@graview/tools 0.1.26 → 0.1.27

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/README.md CHANGED
@@ -91,6 +91,20 @@ caller — or the person an agent acts for — comes back as
91
91
  `{ untrusted: true, authoredBy, text }` in `get_node`, `get_graph` and
92
92
  `search_graph`, so a model reads another collaborator's words as data.
93
93
 
94
+ Every read is bounded, for a seat's turn and an MCP client alike, since both
95
+ call the same runtime: no answer is longer than `READ_CHARS` (8,000)
96
+ characters of JSON. `get_graph` answers a page of at most `READ_PAGE` (25)
97
+ records with the edges out of them, `total`, and `more` saying how many are
98
+ left and the `offset` of the next page; `get_node` answers a record's fields
99
+ and its links as `{ kind, id, label }`, `READ_LINKS` (20) each way a page;
100
+ `search_graph` at most `READ_HITS` (20) hits, whatever `limit` asked;
101
+ `get_violations` `{ violations, total, more? }`, `READ_PROBLEMS` (20) a page.
102
+ A text longer than `READ_TEXT` (600) characters is cut and says how long it
103
+ was, and any other read that does not fit answers `{ cut, partial }`. Within
104
+ one turn of a host's model, a call with the same name and input as an
105
+ earlier one is answered `{ already: "Already read: see the answer to call N
106
+ of this turn, which is above." }`, and counts toward the turn's twelve.
107
+
94
108
  ## Drawing a view on the fly, and keeping it as a lens
95
109
 
96
110
  Asked for a way of seeing — "a board of deliverables by status", "a timeline
@@ -0,0 +1,13 @@
1
+ /** The most characters of JSON one read answers: about 2,000 tokens. */
2
+ export declare const READ_CHARS = 8000;
3
+ /** The most records one page of `get_graph` lists, before `READ_CHARS` asks for fewer. */
4
+ export declare const READ_PAGE = 25;
5
+ /** The most links each way `get_node` names (id, kind and label), a page at a time. */
6
+ export declare const READ_LINKS = 20;
7
+ /** The most hits `search_graph` answers, whatever `limit` asked for. */
8
+ export declare const READ_HITS = 20;
9
+ /** The most problems one page of `get_violations` lists. */
10
+ export declare const READ_PROBLEMS = 20;
11
+ /** The most characters of one field's text a read carries; the rest is said as cut. */
12
+ export declare const READ_TEXT = 600;
13
+ //# sourceMappingURL=bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../src/agent/bounds.ts"],"names":[],"mappings":"AAWA,wEAAwE;AACxE,eAAO,MAAM,UAAU,OAAQ,CAAC;AAChC,0FAA0F;AAC1F,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,uFAAuF;AACvF,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,wEAAwE;AACxE,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,4DAA4D;AAC5D,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,uFAAuF;AACvF,eAAO,MAAM,SAAS,MAAM,CAAC"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * HOW MUCH ONE READ ANSWERS (FR-167). A seat's turn in an app of 30
3
+ * components, 28 skills and 84 strengths read the whole graph in one
4
+ * answer of about 28,000 tokens, and every step after it resent all of it:
5
+ * seven steps, 91k tokens of input at the end, $0.60 for one question. A
6
+ * read now answers a page, says how many more there are and how to ask for
7
+ * them, and never more than `READ_CHARS` characters of JSON — for a seat's
8
+ * turn and an MCP client alike, since both call the same runtime. The
9
+ * reads themselves are `./reads.ts`, fetched with the first read.
10
+ */
11
+ /** The most characters of JSON one read answers: about 2,000 tokens. */
12
+ export const READ_CHARS = 8_000;
13
+ /** The most records one page of `get_graph` lists, before `READ_CHARS` asks for fewer. */
14
+ export const READ_PAGE = 25;
15
+ /** The most links each way `get_node` names (id, kind and label), a page at a time. */
16
+ export const READ_LINKS = 20;
17
+ /** The most hits `search_graph` answers, whatever `limit` asked for. */
18
+ export const READ_HITS = 20;
19
+ /** The most problems one page of `get_violations` lists. */
20
+ export const READ_PROBLEMS = 20;
21
+ /** The most characters of one field's text a read carries; the rest is said as cut. */
22
+ export const READ_TEXT = 600;
23
+ //# sourceMappingURL=bounds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bounds.js","sourceRoot":"","sources":["../../src/agent/bounds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAChC,0FAA0F;AAC1F,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAC5B,uFAAuF;AACvF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAC7B,wEAAwE;AACxE,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAC5B,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,uFAAuF;AACvF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type AnySchema, type SearchResult, type Store, type Violation } from "@graview/core";
2
+ import type { Authorship } from "./untrusted.js";
3
+ /**
4
+ * ANY READ, HELD TO `READ_CHARS`. An answer that fits is handed back as it
5
+ * is; one that does not — a place described in full, a long preview — is
6
+ * its first characters with a sentence saying it was cut and how to ask for
7
+ * less, so no read hands a model more than a read may.
8
+ */
9
+ export declare function withinReadChars(tool: string, data: unknown): unknown;
10
+ /** `search_graph`: the hits without every match's id — what a picture lights, not what a model reads — and how many more. */
11
+ export declare function searchRead(found: SearchResult, marked: SearchResult): unknown;
12
+ /** `get_graph`: a page of records, the edges out of them, the total and how to read the next page. */
13
+ export declare function graphRead<S extends AnySchema>(seen: Store<S>, by: Authorship, args: Record<string, unknown>): {
14
+ readonly data: unknown;
15
+ readonly reads: readonly string[];
16
+ };
17
+ /** `get_node`: the record's fields, its links as ids, kinds and labels a page each way, its problems and computed values. */
18
+ export declare function nodeRead<S extends AnySchema>(seen: Store<S>, by: Authorship, id: string, args: Record<string, unknown>): {
19
+ readonly data: Record<string, unknown>;
20
+ readonly reads: readonly string[];
21
+ };
22
+ /** `get_violations`: a page of problems, the total and how to read the next page. */
23
+ export declare function violationsRead(every: readonly Violation[], args: Record<string, unknown>): {
24
+ readonly data: unknown;
25
+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EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAOxJ"}
@@ -0,0 +1,182 @@
1
+ import { labelOf } from "@graview/core";
2
+ import { computedValues } from "@graview/core/blocks";
3
+ import { READ_CHARS, READ_LINKS, READ_PAGE, READ_PROBLEMS, READ_TEXT } from "./bounds.js";
4
+ /*
5
+ * THE BOUNDED READS (FR-167), fetched with a seat's first read: a page of
6
+ * records with how many more, a record without its neighborhood, the hits
7
+ * and no more, and any answer held to `READ_CHARS`. The bounds are
8
+ * `./bounds.ts`; the runtime that calls these is `./tools.ts`.
9
+ */
10
+ /*
11
+ * OTHER PEOPLE'S WORDS ARE DATA (FR-10), in what a record read answers:
12
+ * marked here rather than in `./untrusted.ts`, which the runtime carries up
13
+ * front, since only these reads hand a record over.
14
+ */
15
+ const wrap = (text, author, by) => ({ untrusted: true, authoredBy: by.say(author), text });
16
+ /** A record with each field somebody else wrote as their words. */
17
+ function markNode(node, by) {
18
+ let out;
19
+ for (const [field, value] of Object.entries(node)) {
20
+ if (typeof value !== "string" || field === "id" || field === "kind")
21
+ continue;
22
+ const author = by.fieldBy(node.id, field);
23
+ if (!author)
24
+ continue;
25
+ out ??= { ...node };
26
+ out[field] = wrap(value, author, by);
27
+ }
28
+ return (out ?? node);
29
+ }
30
+ /**
31
+ * A record's computed values (FR-83), with the words in them marked as
32
+ * somebody's: a record named by a value is named in its author's words, and
33
+ * words worked out from the record's own prose are that prose's author's.
34
+ */
35
+ function markComputed(id, values, by) {
36
+ const mark = (value) => {
37
+ if (Array.isArray(value))
38
+ return value.map(mark);
39
+ if (value !== null && typeof value === "object" && "id" in value && "label" in value) {
40
+ const record = value;
41
+ const author = by.recordBy(record.id);
42
+ return author ? { ...record, label: wrap(record.label, author, by) } : record;
43
+ }
44
+ if (typeof value === "string") {
45
+ const author = by.recordBy(id);
46
+ return author ? wrap(value, author, by) : value;
47
+ }
48
+ return value;
49
+ };
50
+ return Object.fromEntries(Object.entries(values).map(([name, value]) => [name, mark(value)]));
51
+ }
52
+ /** A record's links, each named in the linked record's author's words when somebody else wrote them. */
53
+ function markLinks(links, by) {
54
+ return links.map((link) => {
55
+ const author = by.recordBy(link.id);
56
+ return author ? { ...link, label: wrap(link.label, author, by) } : link;
57
+ });
58
+ }
59
+ function markGraph(snapshot, by) {
60
+ return { ...snapshot, nodes: snapshot.nodes.map((node) => markNode(node, by)) };
61
+ }
62
+ /** An answer's length, as a model is handed it. */
63
+ const charsOf = (value) => (JSON.stringify(value) ?? "null").length;
64
+ /** Where a page starts: a whole number at or past 0, else 0. */
65
+ const offsetOf = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0);
66
+ /** "and 117 more nodes: call get_graph with offset 25 for the next page." — or nothing, when the page was the last. */
67
+ function moreSaid(total, offset, shown, tool, what, extra = "") {
68
+ const rest = total - offset - shown;
69
+ return rest > 0 ? `and ${rest} more ${what}: call ${tool} with ${extra}offset ${offset + shown} for the next page.` : undefined;
70
+ }
71
+ /** A violation as a tool answers it, without the parts a page draws its line with. */
72
+ const spoken = ({ line: _line, ...rest }) => rest;
73
+ /** A record with each long text cut at `READ_TEXT` characters, saying how long it was. */
74
+ function clipped(node) {
75
+ let out;
76
+ for (const [field, value] of Object.entries(node)) {
77
+ if (typeof value !== "string" || value.length <= READ_TEXT)
78
+ continue;
79
+ out ??= { ...node };
80
+ out[field] = `${value.slice(0, READ_TEXT)}… (cut at ${READ_TEXT} of ${value.length} characters)`;
81
+ }
82
+ return (out ?? node);
83
+ }
84
+ /**
85
+ * The longest page of `items` from `offset` whose answer fits `READ_CHARS`:
86
+ * at most `most`, and fewer while the answer is longer than a read may be.
87
+ * At least one, so a page always moves on; a single record too long to fit
88
+ * is cut whole by `withinReadChars`.
89
+ */
90
+ function fittedPage(items, offset, most, answer) {
91
+ let count = Math.min(most, Math.max(0, items.length - offset));
92
+ let page = items.slice(offset, offset + count);
93
+ let said = answer(page);
94
+ while (count > 1 && charsOf(said) > READ_CHARS) {
95
+ count = Math.max(1, Math.floor(count * 0.75));
96
+ page = items.slice(offset, offset + count);
97
+ said = answer(page);
98
+ }
99
+ return { page, answer: said };
100
+ }
101
+ /**
102
+ * ANY READ, HELD TO `READ_CHARS`. An answer that fits is handed back as it
103
+ * is; one that does not — a place described in full, a long preview — is
104
+ * its first characters with a sentence saying it was cut and how to ask for
105
+ * less, so no read hands a model more than a read may.
106
+ */
107
+ export function withinReadChars(tool, data) {
108
+ const json = JSON.stringify(data) ?? "null";
109
+ if (json.length <= READ_CHARS)
110
+ return data;
111
+ const cut = `This answer was ${json.length} characters, more than the ${READ_CHARS} one read answers, so it is cut. Ask ${tool} for less, or use search_graph and get_node to read one thing.`;
112
+ // Quoted again inside the answer, the partial grows by its escapes: shortened until the whole fits.
113
+ for (let at = READ_CHARS - cut.length - 40;;) {
114
+ const out = { cut, partial: json.slice(0, at) };
115
+ const over = charsOf(out) - READ_CHARS;
116
+ if (over <= 0)
117
+ return out;
118
+ at = Math.max(0, at - over - 8);
119
+ }
120
+ }
121
+ /** `search_graph`: the hits without every match's id — what a picture lights, not what a model reads — and how many more. */
122
+ export function searchRead(found, marked) {
123
+ const { matched: _matched, ...answer } = marked;
124
+ const shown = found.hits.filter((hit) => hit.about === "node").length;
125
+ return found.total > shown ? { ...answer, more: `and ${found.total - shown} more records match: narrow the words, or add kind:<kind>.` } : answer;
126
+ }
127
+ /** `get_graph`: a page of records, the edges out of them, the total and how to read the next page. */
128
+ export function graphRead(seen, by, args) {
129
+ const snapshot = seen.graph.snapshot();
130
+ const offset = offsetOf(args["offset"]);
131
+ const total = snapshot.nodes.length;
132
+ const { page, answer } = fittedPage(snapshot.nodes, offset, READ_PAGE, (nodes) => {
133
+ const on = new Set(nodes.map((node) => node.id));
134
+ const more = moreSaid(total, offset, nodes.length, "get_graph", "nodes");
135
+ return { ...markGraph({ nodes: nodes.map(clipped), edges: snapshot.edges.filter((edge) => on.has(edge.from)) }, by), total, ...(more ? { more } : {}) };
136
+ });
137
+ return { data: answer, reads: page.map((node) => node.id) };
138
+ }
139
+ /** `get_node`: the record's fields, its links as ids, kinds and labels a page each way, its problems and computed values. */
140
+ export function nodeRead(seen, by, id, args) {
141
+ const node = seen.graph.getNode(id);
142
+ const offset = offsetOf(args["offset"]);
143
+ const outAll = seen.graph.outEdges(id);
144
+ const inAll = seen.graph.inEdges(id);
145
+ const out = outAll.slice(offset, offset + READ_LINKS);
146
+ const inbound = inAll.slice(offset, offset + READ_LINKS);
147
+ const link = (kind, other) => {
148
+ const at = seen.graph.getNode(other);
149
+ return { kind, id: other, label: at ? labelOf(seen.schema.tryDefinition(at.kind), at) : other };
150
+ };
151
+ // Worked out over what this seat sees, never the store's whole graph (FR-83, FR-55).
152
+ const worked = computedValues(seen.schema, seen.graph, node);
153
+ const problems = seen.violations().filter((violation) => violation.nodeIds.includes(id));
154
+ const more = [
155
+ moreSaid(outAll.length, offset, out.length, "get_node", "links out", `id "${id}" and `),
156
+ moreSaid(inAll.length, offset, inbound.length, "get_node", "links in", `id "${id}" and `),
157
+ problems.length > READ_PROBLEMS ? `and ${problems.length - READ_PROBLEMS} more problems: get_violations lists them.` : undefined,
158
+ ].filter(Boolean);
159
+ return {
160
+ data: {
161
+ node: markNode(clipped(node), by),
162
+ ...(Object.keys(worked.values).length > 0 ? { computed: markComputed(id, worked.values, by) } : {}),
163
+ ...(Object.keys(worked.refused).length > 0 ? { uncomputed: worked.refused } : {}),
164
+ out: markLinks(out.map((edge) => link(edge.kind, edge.to)), by),
165
+ in: markLinks(inbound.map((edge) => link(edge.kind, edge.from)), by),
166
+ violations: problems.slice(0, READ_PROBLEMS).map(spoken),
167
+ ...(more.length > 0 ? { more: more.join(" ") } : {}),
168
+ },
169
+ // Asking about a node is asking about its neighborhood: the answer names them, so looking at it looked at them.
170
+ reads: [id, ...out.map((edge) => edge.to), ...inbound.map((edge) => edge.from)],
171
+ };
172
+ }
173
+ /** `get_violations`: a page of problems, the total and how to read the next page. */
174
+ export function violationsRead(every, args) {
175
+ const offset = offsetOf(args["offset"]);
176
+ const { page, answer } = fittedPage(every, offset, READ_PROBLEMS, (shown) => {
177
+ const more = moreSaid(every.length, offset, shown.length, "get_violations", "problems");
178
+ return { violations: shown.map(spoken), total: every.length, ...(more ? { more } : {}) };
179
+ });
180
+ return { data: answer, reads: [...new Set(page.flatMap((violation) => violation.nodeIds))] };
181
+ }
182
+ //# sourceMappingURL=reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.js","sourceRoot":"","sources":["../../src/agent/reads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG1F;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAAuD,EAAE,EAAc,EAAiB,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAE/K,mEAAmE;AACnE,SAAS,QAAQ,CAAyC,IAAO,EAAE,EAAc;IAC/E,IAAI,GAAwC,CAAC;IAC7C,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,MAAM;YAAE,SAAS;QAC9E,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,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,CAAC,CAAC;IACxC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;QAC1E,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;QACxF,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC3F,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/F,CAAC"}
@@ -187,6 +187,8 @@ export interface ToolRuntime<S extends AnySchema> {
187
187
  }
188
188
  /** Said on every act whose arguments name records: a name is resolved as well as an id (FR-33). */
189
189
  export declare const BY_NAME = "An argument that names a record takes its id or its name.";
190
+ /** JSON with every object's keys sorted — the form two equal surfaces share, and two equal calls (FR-167). */
191
+ export declare function canonical(value: unknown): string;
190
192
  /** The surface's fingerprint. */
191
193
  export declare function surfaceHash(definitions: readonly ToolDefinition[]): string;
192
194
  export interface ToolDefinitionsOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agent/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAaL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,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,SAAS,SAAS,EACnD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,OAAO,GAAE,kBAAkB,CAAC,CAAC,CAAM,GAClC,WAAW,CAAC,CAAC,CAAC,CAwShB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,19 +1,22 @@
1
1
  import { actTitle, answerSeenBy, deriveMutations, derivedVia, nodeRefArgs, permits, permittedMutations, refusalOf, resolveModules, search, sha256Hex, } from "@graview/core";
2
2
  import { mutationToolSchema } from "@graview/core/json-schema";
3
- import { computedValues } from "@graview/core/blocks";
4
- import { authorship, markComputed, markGraph, markHits, markNode } from "./untrusted.js";
3
+ import { authorship, markHits } from "./untrusted.js";
4
+ import { READ_HITS } from "./bounds.js";
5
5
  import { deriveAffordances, applyAffordance, } from "../derive.js";
6
+ /** A part fetched once when first asked for, and asked for again on the next ask when it did not arrive (FR-139). */
7
+ const lazily = (load) => {
8
+ let held;
9
+ return () => (held ??= load().catch((error) => {
10
+ held = undefined;
11
+ throw error;
12
+ }));
13
+ };
6
14
  /*
7
- * The describer, fetched when a place is first asked about, and asked for
8
- * again on the next ask when it did not arrive (FR-139). A literal
15
+ * The describer, fetched when a place is first asked about. A literal
9
16
  * specifier and nothing more: tools runs in workerd, which refuses an
10
17
  * `import()` whose specifier is computed at run time.
11
18
  */
12
- let describing;
13
- const describer = () => (describing ??= import("@graview/core/describe").catch((error) => {
14
- describing = undefined;
15
- throw error;
16
- }));
19
+ const describer = lazily(() => import("@graview/core/describe"));
17
20
  /*
18
21
  * The words a broken rule's line is said in (FR-159), fetched and waited
19
22
  * for by the calls that answer problems (get_violations, get_node): once
@@ -35,17 +38,20 @@ const lines = () => import("@graview/core/lines").catch(() => undefined);
35
38
  const judgingWithLines = async () => {
36
39
  (await lines())?.judgeWithLines();
37
40
  };
41
+ /*
42
+ * The bounded reads (FR-167), fetched with the first read: a seat that is
43
+ * never asked carries none of them. A literal specifier, as above.
44
+ */
45
+ const reads = lazily(() => import("./reads.js"));
38
46
  /*
39
47
  * The drafting engine, fetched when a view is first asked for (draft_view,
40
48
  * keep_lens): a seat that never asks carries none of it. A literal
41
49
  * specifier, as above.
42
50
  */
43
- let drafting;
44
- const drafter = () => (drafting ??= import("../draft.js").catch((error) => {
45
- drafting = undefined;
46
- throw error;
47
- }));
51
+ const drafter = lazily(() => import("../draft.js"));
48
52
  const read = (title) => ({ title, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false });
53
+ /** Where a page of a read starts (FR-167). */
54
+ const OFFSET = { type: "number", description: "Where the page starts; 0 when unsaid." };
49
55
  const READ_TOOLS = [
50
56
  {
51
57
  name: "search_graph",
@@ -55,7 +61,7 @@ const READ_TOOLS = [
55
61
  type: "object",
56
62
  properties: {
57
63
  query: { type: "string", description: "Words, with optional key:value conditions." },
58
- limit: { type: "number", description: "Most hits to return; 20 when unsaid." },
64
+ limit: { type: "number", description: "Most hits to return; at most 20." },
59
65
  subject: { type: "string", description: "A node id whose acts to include." },
60
66
  },
61
67
  required: ["query"],
@@ -66,23 +72,26 @@ const READ_TOOLS = [
66
72
  },
67
73
  {
68
74
  name: "get_graph",
69
- title: "Read the whole graph",
70
- description: "Read the whole graph: every node with its fields, and every edge. Start here when you need the shape of the domain rather than one thing in it.",
75
+ title: "Read the graph",
76
+ description: "Read the graph, 25 nodes a page: their fields, the edges out of them, and how many more. Start here when you need the shape of the domain rather than one thing in it.",
71
77
  inputSchema: {
72
78
  type: "object",
73
- properties: {},
79
+ properties: { offset: OFFSET },
74
80
  additionalProperties: false,
75
81
  },
76
82
  mutating: false,
77
- annotations: read("Read the whole graph"),
83
+ annotations: read("Read the graph"),
78
84
  },
79
85
  {
80
86
  name: "get_node",
81
87
  title: "Read one node",
82
- description: "Read one node, its edges, and the violations that implicate it, with its computed values: read-only fields worked out from what you can see, which no act sets. Use this to check a thing before you change it.",
88
+ description: "Read one node: its fields, its links (id, kind and label, 20 each way a page), the violations that implicate it, and its computed values: read-only fields worked out from what you can see, which no act sets. Use this to check a thing before you change it.",
83
89
  inputSchema: {
84
90
  type: "object",
85
- properties: { id: { type: "string", description: "A node's id, or its name." } },
91
+ properties: {
92
+ id: { type: "string", description: "A node's id, or its name." },
93
+ offset: OFFSET,
94
+ },
86
95
  required: ["id"],
87
96
  additionalProperties: false,
88
97
  },
@@ -92,10 +101,11 @@ const READ_TOOLS = [
92
101
  {
93
102
  name: "get_violations",
94
103
  title: "List the problems",
95
- description: "List every invariant violation the graph currently has, with the repairs that would resolve each one. Read this before proposing work: a rule that is already broken is more urgent than anything you could add.",
104
+ description: "List the invariant violations the graph currently has, 20 a page, with the repairs that would resolve each one. Read this before proposing work: a rule that is already broken is more urgent than anything you could add.",
96
105
  inputSchema: {
97
106
  type: "object",
98
107
  properties: {
108
+ offset: OFFSET,
99
109
  context: {
100
110
  type: "object",
101
111
  description: "Evaluation context, e.g. { weekStart }.",
@@ -301,8 +311,8 @@ function actTool(mutation, name) {
301
311
  act: mutation.name,
302
312
  };
303
313
  }
304
- /** JSON with every object's keys sorted — the form two equal surfaces share. */
305
- function canonical(value) {
314
+ /** JSON with every object's keys sorted — the form two equal surfaces share, and two equal calls (FR-167). */
315
+ export function canonical(value) {
306
316
  if (value === null || typeof value !== "object")
307
317
  return JSON.stringify(value) ?? "null";
308
318
  if (Array.isArray(value))
@@ -473,24 +483,20 @@ export function createToolRuntime(store, options = {}) {
473
483
  const subject = typeof args["subject"] === "string" ? args["subject"] : undefined;
474
484
  const found = search(seen, String(args["query"] ?? ""), {
475
485
  principal,
476
- limit: typeof args["limit"] === "number" ? args["limit"] : 20,
486
+ limit: typeof args["limit"] === "number" && args["limit"] > 0 ? Math.min(args["limit"], READ_HITS) : READ_HITS,
477
487
  ...(places ? { places } : {}),
478
488
  ...(subject ? { subject, from: [subject] } : {}),
479
489
  });
480
490
  return {
481
491
  ok: true,
482
- data: markHits(found, authorship(seen, principal)),
492
+ data: (await reads()).searchRead(found, markHits(found, authorship(seen, principal))),
483
493
  // What came back was looked at: the records named, and nothing else.
484
494
  reads: found.hits.flatMap((hit) => (hit.about === "node" ? [hit.id] : [])),
485
495
  };
486
496
  }
487
497
  case "get_graph": {
488
- const snapshot = seen.graph.snapshot();
489
- return {
490
- ok: true,
491
- data: markGraph(snapshot, authorship(seen, principal)),
492
- reads: snapshot.nodes.map((node) => node.id),
493
- };
498
+ /* A page of records, the edges out of them, and how many more (FR-167): the whole graph was one answer of 28,000 tokens. */
499
+ return { ok: true, ...(await reads()).graphRead(seen, authorship(seen, principal), args) };
494
500
  }
495
501
  case "get_node": {
496
502
  const asked = String(args["id"] ?? "");
@@ -508,30 +514,9 @@ export function createToolRuntime(store, options = {}) {
508
514
  else
509
515
  return { ok: false, error: `No node "${asked}".` };
510
516
  }
511
- const node = seen.graph.getNode(id);
512
- const out = seen.graph.outEdges(id);
513
- const inbound = seen.graph.inEdges(id);
514
- const by = authorship(seen, principal);
515
- // Worked out over what this seat sees, never the store's whole graph (FR-83, FR-55).
516
- const worked = computedValues(seen.schema, seen.graph, node);
517
- return {
518
- ok: true,
519
- data: {
520
- node: markNode(node, by),
521
- ...(Object.keys(worked.values).length > 0 ? { computed: markComputed(id, worked.values, by) } : {}),
522
- ...(Object.keys(worked.refused).length > 0 ? { uncomputed: worked.refused } : {}),
523
- out,
524
- in: inbound,
525
- violations: seen
526
- .violations()
527
- .filter((violation) => violation.nodeIds.includes(id))
528
- .map(withoutLine),
529
- ...(resolved ? { resolved: [resolved] } : {}),
530
- },
531
- // Asking about a node is asking about its neighborhood: the
532
- // answer names them, so looking at it looked at them.
533
- reads: [id, ...out.map((edge) => edge.to), ...inbound.map((edge) => edge.from)],
534
- };
517
+ /* Its fields and its links as ids, kinds and labels, a page each way (FR-167): never the neighborhood's own fields. */
518
+ const answer = (await reads()).nodeRead(seen, authorship(seen, principal), id, args);
519
+ return { ok: true, data: resolved ? { ...answer.data, resolved: [resolved] } : answer.data, reads: answer.reads };
535
520
  }
536
521
  case "describe_place": {
537
522
  const app = options.app ?? { name: "", schema: store.schema };
@@ -566,12 +551,9 @@ export function createToolRuntime(store, options = {}) {
566
551
  return (await drafter()).runDraftTool(definition.name, args, { app, principal, ...(options.drafts ? { drafts: options.drafts } : {}) });
567
552
  }
568
553
  case "get_violations": {
569
- const violations = seen.violations(args["context"]);
570
- return {
571
- ok: true,
572
- data: violations.map(withoutLine),
573
- reads: [...new Set(violations.flatMap((violation) => violation.nodeIds))],
574
- };
554
+ const every = seen.violations(args["context"]);
555
+ /* A page of problems, and how many more (FR-167). */
556
+ return { ok: true, ...(await reads()).violationsRead(every, args) };
575
557
  }
576
558
  case "get_affordances": {
577
559
  const selection = args["selection"] ?? [];
@@ -657,7 +639,9 @@ export function createToolRuntime(store, options = {}) {
657
639
  : { ...started, phase: "failed", error: result.error });
658
640
  return result;
659
641
  };
660
- return settle(await run(name, args));
642
+ const result = await run(name, args);
643
+ // No read hands a model more than a read may (FR-167): what does not fit is cut, and says so.
644
+ return settle(result.ok && !mutating ? { ...result, data: (await reads()).withinReadChars(name, result.data) } : result);
661
645
  },
662
646
  };
663
647
  }