@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
package/dist/loop.js ADDED
@@ -0,0 +1,173 @@
1
+ import { labelOf } from "@graview/core";
2
+ import { applyPlan, planFrom } from "./plan.js";
3
+ import { jevCostUsd } from "./providers/jev.js";
4
+ import { questionsForInvariant } from "./questions.js";
5
+ import { offerOf } from "./run.js";
6
+ /** The graph as a string that is the same for the same graph. */
7
+ function stateKey(store) {
8
+ const snapshot = store.graph.snapshot();
9
+ const nodes = [...snapshot.nodes].map((node) => JSON.stringify(node, Object.keys(node).sort())).sort();
10
+ const edges = [...snapshot.edges].map((edge) => JSON.stringify(edge, Object.keys(edge).sort())).sort();
11
+ return `${nodes.join("\n")}\n--\n${edges.join("\n")}`;
12
+ }
13
+ export async function runLoop(store, loop, options) {
14
+ const author = options.author ?? { kind: "agent", id: loop.name, session: `loop-${Date.now().toString(36)}` };
15
+ const batch = options.batch ?? `loop:${loop.name}:${Date.now().toString(36)}`;
16
+ const maxTurns = loop.budget?.turns ?? 20;
17
+ const usage = { questions: 0, calls: 0, inputTokens: 0, usd: 0 };
18
+ const turns = [];
19
+ const seen = new Set([stateKey(store)]);
20
+ const planOptions = { ...(options.app ? { app: options.app } : {}), principal: options.principal ?? author };
21
+ const name = (violation) => {
22
+ const id = violation.subjectId ?? violation.nodeIds[0];
23
+ const node = id ? store.graph.getNode(id) : undefined;
24
+ return node ? labelOf(store.schema.tryDefinition(node.kind), node) : (id ?? violation.invariant);
25
+ };
26
+ const standing = () => store.violations(options.context).filter((v) => !loop.rules || loop.rules.includes(v.invariant));
27
+ const finish = (stopped) => {
28
+ usage.usd = jevCostUsd(usage.inputTokens);
29
+ /* The stop is said on the seat's own path too, so the rail carries the sentence. */
30
+ options.onCall?.({ name: "stop", args: { why: stopped.why, said: stopped.said }, mutating: false, phase: "ok", at: new Date().toISOString() });
31
+ return { name: loop.name, author, batch, turns, stopped, usage, remaining: standing().length };
32
+ };
33
+ const done = (count) => `${turns.length} repair${turns.length === 1 ? "" : "s"} made${count > 0 ? `, ${count} still standing` : ""}.`;
34
+ for (let turn = 0;; turn++) {
35
+ const violations = standing();
36
+ if (violations.length === 0) {
37
+ return finish({ why: "nothing-left", said: turns.length === 0 ? "Nothing is wrong, so there was nothing to repair." : `Nothing left to repair: ${done(0)}` });
38
+ }
39
+ if (turn >= maxTurns) {
40
+ return finish({ why: "budget", said: `Stopped at the budget of ${maxTurns} turn${maxTurns === 1 ? "" : "s"}: ${done(violations.length)}` });
41
+ }
42
+ if (loop.budget?.questions !== undefined && usage.questions >= loop.budget.questions) {
43
+ return finish({ why: "budget", said: `Stopped at the budget of ${loop.budget.questions} question${loop.budget.questions === 1 ? "" : "s"}: ${done(violations.length)}` });
44
+ }
45
+ if (loop.budget?.usd !== undefined && jevCostUsd(usage.inputTokens) >= loop.budget.usd) {
46
+ return finish({ why: "budget", said: `Stopped at the budget of $${loop.budget.usd}: ${done(violations.length)}` });
47
+ }
48
+ /*
49
+ * THE FIRST VIOLATION WITH A REPAIR IT CAN TAKE. A repair still missing
50
+ * an argument is not one the loop can choose — there is nothing typed to
51
+ * choose with — so a violation whose every repair is like that is left
52
+ * standing, and said so if nothing else can be done.
53
+ */
54
+ const workable = violations
55
+ .map((violation) => ({ violation, ready: violation.repairs.filter((repair) => !repair.missing?.length) }))
56
+ .find((candidate) => candidate.ready.length > 0);
57
+ if (!workable) {
58
+ return finish({
59
+ why: "no-repair",
60
+ said: `${violations.length} thing${violations.length === 1 ? " is" : "s are"} still wrong and none of them names a repair I could take without being told more: ${done(violations.length)}`,
61
+ });
62
+ }
63
+ const { violation, ready } = workable;
64
+ const nodeIds = violation.subjectId ? [violation.subjectId] : violation.nodeIds;
65
+ const at = new Date().toISOString();
66
+ const announced = {
67
+ name: "repair",
68
+ args: { turn, rule: violation.invariant, ...(nodeIds[0] ? { node: nodeIds[0] } : {}), about: name(violation) },
69
+ mutating: false,
70
+ at,
71
+ };
72
+ options.onCall?.({ ...announced, phase: "running" });
73
+ const [, repairQuestion] = questionsForInvariant(store, violation.invariant, violation);
74
+ let call;
75
+ let asked;
76
+ let answer;
77
+ let confidence = 1;
78
+ if (repairQuestion && repairQuestion.about === "repair") {
79
+ let decided;
80
+ try {
81
+ decided = await options.decide({ broken: violation.message, about: name(violation), implicated: violation.nodeIds }, { [repairQuestion.id]: repairQuestion.question });
82
+ }
83
+ catch (error) {
84
+ const why = error instanceof Error ? error.message : String(error);
85
+ options.onCall?.({ ...announced, phase: "failed", error: why });
86
+ return finish({ why: "failed", said: `Stopped because the decision provider failed: ${why} ${done(violations.length)}` });
87
+ }
88
+ usage.questions += 1;
89
+ usage.calls += 1;
90
+ usage.inputTokens += decided.usage.inputTokens;
91
+ answer = decided.answers[repairQuestion.id];
92
+ asked = repairQuestion;
93
+ if (!answer || answer.type !== "choice" || !repairQuestion.options[answer.choice]) {
94
+ options.onCall?.({ ...announced, phase: "failed", error: "no usable answer" });
95
+ return finish({ why: "failed", said: `Stopped because the answer about ${name(violation)} was not one of the repairs offered. ${done(violations.length)}` });
96
+ }
97
+ confidence = Math.round(answer.confidence * 1000) / 1000;
98
+ const because = offerOf(answer, {
99
+ ...(options.floor !== undefined ? { floor: options.floor } : {}),
100
+ ...(options.splitWithin !== undefined ? { splitWithin: options.splitWithin } : {}),
101
+ });
102
+ if (because) {
103
+ options.onCall?.({ ...announced, phase: "ok", reads: nodeIds });
104
+ const question = {
105
+ id: repairQuestion.id,
106
+ ...(nodeIds[0] ? { nodeId: nodeIds[0] } : {}),
107
+ nodeLabel: name(violation),
108
+ asks: repairQuestion.question.instructions,
109
+ because,
110
+ confidence,
111
+ options: Object.entries(answer.probabilities)
112
+ .map(([value, probability]) => {
113
+ const option = repairQuestion.options[value];
114
+ return {
115
+ value,
116
+ probability,
117
+ ...(option ? { call: { mutation: option.mutation, args: { ...option.args }, why: repairQuestion.question.type === "choice" ? (repairQuestion.question.criteria[value] ?? value) : value } } : {}),
118
+ };
119
+ })
120
+ .sort((a, b) => b.probability - a.probability),
121
+ };
122
+ return finish({
123
+ why: "unsure",
124
+ said: `Stopped at ${name(violation)}: ${because === "split" ? "it could be more than one repair" : `I am only ${Math.round(confidence * 100)}% sure which repair`}, so I am asking rather than acting. ${done(violations.length)}`,
125
+ question,
126
+ });
127
+ }
128
+ const chosen = repairQuestion.options[answer.choice];
129
+ call = {
130
+ mutation: chosen.mutation,
131
+ args: { ...chosen.args },
132
+ why: `${violation.message} → ${repairQuestion.question.type === "choice" ? (repairQuestion.question.criteria[answer.choice] ?? answer.choice) : answer.choice}`,
133
+ confidence,
134
+ };
135
+ }
136
+ else {
137
+ /* One ready repair: the rule has already answered, and nothing is asked. */
138
+ const only = ready[0];
139
+ call = { mutation: only.mutation, args: { ...(only.args ?? {}) }, why: `${violation.message} → ${only.label}`, confidence: 1 };
140
+ }
141
+ const before = violations.length;
142
+ const plan = planFrom(store, [call], planOptions);
143
+ if (plan.refused.length > 0) {
144
+ options.onCall?.({ ...announced, phase: "failed", error: plan.refused[0].refusal.message });
145
+ return finish({ why: "refused", said: `Stopped at ${name(violation)}: ${plan.refused[0].refusal.message} ${done(before)}` });
146
+ }
147
+ const landed = applyPlan(store, plan, { author, batch, keepWhatRan: true });
148
+ if (landed.stoppedAt) {
149
+ options.onCall?.({ ...announced, phase: "failed", error: landed.stoppedAt.why });
150
+ return finish({ why: "refused", said: `Stopped at ${name(violation)}: ${landed.stoppedAt.why} ${done(before)}` });
151
+ }
152
+ options.onCall?.({ ...announced, phase: "ok", reads: nodeIds });
153
+ const after = standing().length;
154
+ turns.push({ turn, violation, ...(asked ? { asked } : {}), ...(answer ? { answer } : {}), confidence, call, before, after });
155
+ const key = stateKey(store);
156
+ if (seen.has(key)) {
157
+ return finish({
158
+ why: "seen-before",
159
+ said: `Stopped at ${name(violation)}: this repair put the graph back into a state it has already been in, so going on would go in a circle. ${done(after)}`,
160
+ });
161
+ }
162
+ seen.add(key);
163
+ }
164
+ }
165
+ /** A loop, spoken by the seat: the stop sentence, and the question if it stopped to ask. */
166
+ export function replyFromLoop(result) {
167
+ return {
168
+ say: result.stopped.said,
169
+ proposals: [],
170
+ ...(result.stopped.question ? { questions: [result.stopped.question] } : {}),
171
+ };
172
+ }
173
+ //# sourceMappingURL=loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.js","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA8D,MAAM,eAAe,CAAC;AAGpG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsC,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,UAAU,EAA4B,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAA8C,MAAM,gBAAgB,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA0EnC,iEAAiE;AACjE,SAAS,QAAQ,CAAsB,KAAe;IACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACxC,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,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OAAO;QACL,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;QACxB,SAAS,EAAE,EAAE;QACb,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { McpTool, McpToolResult } from "./agent/adapters.js";
2
+ /**
3
+ * MCP OVER STDIO, without a dependency.
4
+ *
5
+ * The protocol an editor's agent speaks to a local tool server is small:
6
+ * JSON-RPC 2.0, one message per line, five methods that matter. Writing
7
+ * them out is shorter than the SDK's install notes, keeps `graview mcp` a
8
+ * command any project already has the dependencies for, and — the point —
9
+ * leaves the adapter as the ONLY thing that decides anything. This file
10
+ * moves bytes; `createMcpAdapter` renames fields; the runtime is where the
11
+ * tools live. Three layers, none of which can disagree about a tool.
12
+ */
13
+ export interface McpAdapterLike {
14
+ listTools(): McpTool[];
15
+ callTool(name: string, args?: Record<string, unknown>): Promise<McpToolResult>;
16
+ }
17
+ export interface StdioMcpOptions {
18
+ readonly adapter: McpAdapterLike;
19
+ readonly name: string;
20
+ readonly version: string;
21
+ /** What a client shows its model on connecting: how to work here, in a paragraph. */
22
+ readonly instructions?: string;
23
+ readonly input: AsyncIterable<string | Uint8Array>;
24
+ readonly output: {
25
+ write(chunk: string): unknown;
26
+ };
27
+ /** Told about each request as it settles — a host's log, on stderr. */
28
+ readonly onRequest?: (method: string, ok: boolean) => void;
29
+ }
30
+ /** The newest protocol revision this speaks; a client asking for an older one gets its own back. */
31
+ export declare const MCP_PROTOCOL_VERSION = "2025-06-18";
32
+ /**
33
+ * Serves until the input ends. Requests are answered IN ORDER, one at a
34
+ * time: a mutation lands before the read that follows it looks, which is
35
+ * the ordering an agent assumes when it acts and then checks.
36
+ */
37
+ export declare function serveMcpStdio(options: StdioMcpOptions): Promise<void>;
38
+ //# sourceMappingURL=mcp-stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-stdio.d.ts","sourceRoot":"","sources":["../src/mcp-stdio.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,cAAc;IAC7B,SAAS,IAAI,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAChF;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qFAAqF;IACrF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACnD,uEAAuE;IACvE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5D;AASD,oGAAoG;AACpG,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAMjD;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAqE3E"}
@@ -0,0 +1,83 @@
1
+ /** The newest protocol revision this speaks; a client asking for an older one gets its own back. */
2
+ export const MCP_PROTOCOL_VERSION = "2025-06-18";
3
+ const METHOD_NOT_FOUND = -32601;
4
+ const INVALID_PARAMS = -32602;
5
+ const PARSE_ERROR = -32700;
6
+ /**
7
+ * Serves until the input ends. Requests are answered IN ORDER, one at a
8
+ * time: a mutation lands before the read that follows it looks, which is
9
+ * the ordering an agent assumes when it acts and then checks.
10
+ */
11
+ export async function serveMcpStdio(options) {
12
+ const send = (message) => options.output.write(`${JSON.stringify(message)}\n`);
13
+ const reply = (id, result) => send({ jsonrpc: "2.0", id: id ?? null, result });
14
+ const fail = (id, code, message) => send({ jsonrpc: "2.0", id: id ?? null, error: { code, message } });
15
+ const handle = async (request) => {
16
+ const { id, method, params = {} } = request;
17
+ const notification = id === undefined;
18
+ const settle = (ok) => options.onRequest?.(method ?? "?", ok);
19
+ switch (method) {
20
+ case "initialize": {
21
+ const asked = typeof params["protocolVersion"] === "string" ? params["protocolVersion"] : MCP_PROTOCOL_VERSION;
22
+ reply(id, {
23
+ protocolVersion: asked <= MCP_PROTOCOL_VERSION ? asked : MCP_PROTOCOL_VERSION,
24
+ capabilities: { tools: { listChanged: false } },
25
+ serverInfo: { name: options.name, version: options.version },
26
+ ...(options.instructions ? { instructions: options.instructions } : {}),
27
+ });
28
+ return settle(true);
29
+ }
30
+ case "notifications/initialized":
31
+ case "notifications/cancelled":
32
+ case "notifications/roots/list_changed":
33
+ return;
34
+ case "ping":
35
+ if (!notification)
36
+ reply(id, {});
37
+ return settle(true);
38
+ case "tools/list":
39
+ reply(id, { tools: options.adapter.listTools() });
40
+ return settle(true);
41
+ case "tools/call": {
42
+ const name = params["name"];
43
+ if (typeof name !== "string") {
44
+ fail(id, INVALID_PARAMS, "tools/call needs a tool name.");
45
+ return settle(false);
46
+ }
47
+ const args = (params["arguments"] ?? {});
48
+ const result = await options.adapter.callTool(name, args);
49
+ reply(id, result);
50
+ return settle(result.isError !== true);
51
+ }
52
+ default:
53
+ if (notification)
54
+ return;
55
+ fail(id, METHOD_NOT_FOUND, `Method not found: ${method ?? "(none)"}`);
56
+ return settle(false);
57
+ }
58
+ };
59
+ let pending = "";
60
+ for await (const chunk of options.input) {
61
+ pending += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
62
+ let newline = pending.indexOf("\n");
63
+ while (newline !== -1) {
64
+ const line = pending.slice(0, newline).trim();
65
+ pending = pending.slice(newline + 1);
66
+ newline = pending.indexOf("\n");
67
+ if (line.length === 0)
68
+ continue;
69
+ let request;
70
+ try {
71
+ request = JSON.parse(line);
72
+ }
73
+ catch {
74
+ fail(null, PARSE_ERROR, "That line was not JSON.");
75
+ continue;
76
+ }
77
+ // A batch is answered message by message, in order.
78
+ for (const one of Array.isArray(request) ? request : [request])
79
+ await handle(one);
80
+ }
81
+ }
82
+ }
83
+ //# sourceMappingURL=mcp-stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-stdio.js","sourceRoot":"","sources":["../src/mcp-stdio.ts"],"names":[],"mappings":"AAsCA,oGAAoG;AACpG,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAEjD,MAAM,gBAAgB,GAAG,CAAC,KAAK,CAAC;AAChC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AAC9B,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAwB;IAC1D,MAAM,IAAI,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxF,MAAM,KAAK,GAAG,CAAC,EAAwB,EAAE,MAAe,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9G,MAAM,IAAI,GAAG,CAAC,EAAwB,EAAE,IAAY,EAAE,OAAe,EAAE,EAAE,CACvE,IAAI,CAAC,EAAE,OAAO,E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AAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnF,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YAC9C,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACrC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YAChC,IAAI,OAAuB,CAAC;YAC5B,IAAI,CAAC;gBACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAmB,CAAC;YAC/C,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,yBAAyB,CAAC,CAAC;gBACnD,SAAS;YACX,CAAC;YACD,oDAAoD;YACpD,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,OAA4B,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;gBAAE,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1G,CAAC;IACH,CAAC;AACH,CAAC"}
package/dist/pins.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A PERSON'S OWN PINS, kept in their browser.
3
+ *
4
+ * The dev pins an act by declaring `pinned: true` on the mutation; a person
5
+ * pins one from the menu itself. Their choices live here — per browser,
6
+ * beside the intelligence config, never in the repo or the graph — and win
7
+ * in BOTH directions: their pin outranks the dev's, and their unpin demotes
8
+ * an act the dev pinned. Without the second half the star on a declared pin
9
+ * was a control that did nothing visible, which teaches people not to press
10
+ * controls.
11
+ */
12
+ export interface PinOverrides {
13
+ /** Acts this person pinned. Outrank the dev's declared pins. */
14
+ readonly pinned: readonly string[];
15
+ /** Declared pins this person turned off. */
16
+ readonly unpinned: readonly string[];
17
+ }
18
+ export declare const NO_PINS: PinOverrides;
19
+ /** The saved overrides, or none — never a throw. Reads the old plain-array shape too. */
20
+ export declare function loadPins(): PinOverrides;
21
+ export declare function savePins(overrides: PinOverrides): void;
22
+ /**
23
+ * One gesture, both directions: pin what is unpinned, unpin what is pinned
24
+ * — including a pin the DEV declared, which the person demotes rather than
25
+ * deletes (the declaration is not theirs to edit). Returns the new
26
+ * overrides, saved.
27
+ */
28
+ export declare function togglePin(overrides: PinOverrides, mutation: string, declaredPinned?: boolean): PinOverrides;
29
+ //# sourceMappingURL=pins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pins.d.ts","sourceRoot":"","sources":["../src/pins.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,eAAO,MAAM,OAAO,EAAE,YAA2C,CAAC;AAKlE,yFAAyF;AACzF,wBAAgB,QAAQ,IAAI,YAAY,CAcvC;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI,CAMtD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,MAAM,EAChB,cAAc,UAAQ,GACrB,YAAY,CAWd"}
package/dist/pins.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * A PERSON'S OWN PINS, kept in their browser.
3
+ *
4
+ * The dev pins an act by declaring `pinned: true` on the mutation; a person
5
+ * pins one from the menu itself. Their choices live here — per browser,
6
+ * beside the intelligence config, never in the repo or the graph — and win
7
+ * in BOTH directions: their pin outranks the dev's, and their unpin demotes
8
+ * an act the dev pinned. Without the second half the star on a declared pin
9
+ * was a control that did nothing visible, which teaches people not to press
10
+ * controls.
11
+ */
12
+ const STORED = "graview:pins";
13
+ export const NO_PINS = { pinned: [], unpinned: [] };
14
+ const names = (value) => Array.isArray(value) ? value.filter((name) => typeof name === "string") : [];
15
+ /** The saved overrides, or none — never a throw. Reads the old plain-array shape too. */
16
+ export function loadPins() {
17
+ try {
18
+ const raw = globalThis.localStorage?.getItem(STORED);
19
+ if (!raw)
20
+ return NO_PINS;
21
+ const parsed = JSON.parse(raw);
22
+ if (Array.isArray(parsed))
23
+ return { pinned: names(parsed), unpinned: [] };
24
+ if (typeof parsed === "object" && parsed !== null) {
25
+ const shaped = parsed;
26
+ return { pinned: names(shaped.pinned), unpinned: names(shaped.unpinned) };
27
+ }
28
+ return NO_PINS;
29
+ }
30
+ catch {
31
+ return NO_PINS;
32
+ }
33
+ }
34
+ export function savePins(overrides) {
35
+ try {
36
+ globalThis.localStorage?.setItem(STORED, JSON.stringify(overrides));
37
+ }
38
+ catch {
39
+ // A pin that cannot be remembered still applies for this visit.
40
+ }
41
+ }
42
+ /**
43
+ * One gesture, both directions: pin what is unpinned, unpin what is pinned
44
+ * — including a pin the DEV declared, which the person demotes rather than
45
+ * deletes (the declaration is not theirs to edit). Returns the new
46
+ * overrides, saved.
47
+ */
48
+ export function togglePin(overrides, mutation, declaredPinned = false) {
49
+ const without = (list) => list.filter((name) => name !== mutation);
50
+ const next = declaredPinned
51
+ ? overrides.unpinned.includes(mutation)
52
+ ? { pinned: without(overrides.pinned), unpinned: without(overrides.unpinned) }
53
+ : { pinned: without(overrides.pinned), unpinned: [...overrides.unpinned, mutation] }
54
+ : overrides.pinned.includes(mutation)
55
+ ? { pinned: without(overrides.pinned), unpinned: without(overrides.unpinned) }
56
+ : { pinned: [...overrides.pinned, mutation], unpinned: without(overrides.unpinned) };
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AAC;IACzF,QAAQ,CAAC,IAAI,CAAC,CAAC;IACf,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/plan.d.ts ADDED
@@ -0,0 +1,150 @@
1
+ import { type AnySchema, type GraviewApp, type Principal, type Refusal, type Store } from "@graview/core";
2
+ import type { ProposedCall } from "./intelligence.js";
3
+ /**
4
+ * A PLAN IS WHAT A MODEL WANTS TO DO, AND IT IS AN OBJECT LIKE ANY OTHER.
5
+ *
6
+ * An act is declared, typed, permissioned, logged and undoable. What a model
7
+ * PROPOSES had none of that: a bare list of calls, applied in the order it
8
+ * happened to write them, by whatever code the app wrote itself. The first
9
+ * product to do this seriously wrote every layer — the ordering, the review,
10
+ * the batch, the allowlist — and any second product would have written the
11
+ * same thing slightly differently.
12
+ *
13
+ * Four things a plan is that a list of calls is not:
14
+ *
15
+ * ORDERED. Seeding a blank graph means making a zone before the feature
16
+ * that stands in it, and a model should not have to sort that — the
17
+ * declaration already says which kinds wait for which (`beginning`). More
18
+ * than that: a plan can refer to what it is about to make. `as: "lawn"` on
19
+ * one call and `{ $plan: "lawn" }` in another's arguments is how forty
20
+ * proposals become one graph, and it is the only way a model can name a
21
+ * node that does not exist yet.
22
+ *
23
+ * JUDGED BEFORE ANY OF IT RUNS. Every call is checked against the policy
24
+ * and against the provider's own `may` — which the store now enforces — so
25
+ * a person reviewing a plan is reading what WILL happen, not what might.
26
+ *
27
+ * REVIEWABLE. The refused entries stay in the plan with their reason,
28
+ * struck through rather than dropped, for the same reason the actions strip
29
+ * withholds rather than hides.
30
+ *
31
+ * ONE TURN. Applied under one batch, so the whole plan is one entry in the
32
+ * activity and one undo — a seeding that put forty nodes in is taken back
33
+ * the way it arrived.
34
+ */
35
+ /** A call a plan may name, so a later call can point at what it makes. */
36
+ export interface PlannedCall extends ProposedCall {
37
+ /** A name for the node this call creates, referred to as { $plan: name }. */
38
+ readonly as?: string;
39
+ /**
40
+ * HOW SURE whoever proposed it was, 0–1. A first-class field rather than
41
+ * a number in `why`, so a review can order the least sure first and a
42
+ * surface can offer rather than apply — the same number wherever the
43
+ * call travels.
44
+ */
45
+ readonly confidence?: number;
46
+ }
47
+ /** A reference to a node an earlier call in this plan will create. */
48
+ export interface PlanReference {
49
+ readonly $plan: string;
50
+ }
51
+ export declare function isPlanReference(value: unknown): value is PlanReference;
52
+ export interface PlanEntry {
53
+ readonly call: PlannedCall;
54
+ /** Where it ended up once the plan was ordered. */
55
+ readonly at: number;
56
+ /** The plan names this call points at — what must be made before it. */
57
+ readonly dependsOn: readonly string[];
58
+ /** Why this cannot run, if it cannot. */
59
+ readonly refusal?: Refusal;
60
+ }
61
+ export interface Plan {
62
+ /** Every entry, in the order they would be applied. */
63
+ readonly entries: readonly PlanEntry[];
64
+ /** The ones that can run, in order. */
65
+ readonly ready: readonly PlanEntry[];
66
+ /** The ones that cannot, with a reason each. */
67
+ readonly refused: readonly PlanEntry[];
68
+ /** What the plan would make, by kind. */
69
+ readonly makes: Readonly<Record<string, number>>;
70
+ }
71
+ export interface PlanOptions<S extends AnySchema> {
72
+ /** The seat the plan is for; its refusals are the ones a person will meet. */
73
+ readonly principal?: Principal;
74
+ /** The declaration, so the plan can be ordered by the chain it states. */
75
+ readonly app?: GraviewApp<S>;
76
+ }
77
+ /**
78
+ * Orders and judges a set of proposals.
79
+ *
80
+ * Ordering is by what each call NEEDS: a call referring to `{ $plan: "lawn" }`
81
+ * comes after the call named `lawn`; beyond that, by the declaration's own
82
+ * chain, so a zone is made before a feature even when nothing in the plan
83
+ * says so. A reference to a name the plan never makes, and a cycle between
84
+ * two of them, are refusals rather than a runtime surprise.
85
+ */
86
+ export declare function planFrom<S extends AnySchema>(store: Store<S>, proposals: readonly PlannedCall[], options?: PlanOptions<S>): Plan;
87
+ export interface AppliedPlan<S extends AnySchema> {
88
+ /** What each named call made, by its plan name. */
89
+ readonly made: Readonly<Record<string, string>>;
90
+ readonly batch: string;
91
+ readonly applied: number;
92
+ /** Set when a call threw, naming which one and why. */
93
+ readonly stoppedAt?: {
94
+ readonly at: number;
95
+ readonly why: string;
96
+ };
97
+ /** Whether what had already been applied was taken back again. */
98
+ readonly undone?: boolean;
99
+ readonly store: Store<S>;
100
+ }
101
+ /**
102
+ * Applies a plan's ready entries as ONE TURN.
103
+ *
104
+ * Sequentially rather than in a single `applyAll`, because a call can refer
105
+ * to what an earlier one made and those ids do not exist until it has run —
106
+ * but under one batch, so the activity shows one entry and `store.undo(batch)`
107
+ * takes the whole seeding back the way it arrived.
108
+ *
109
+ * ALL OR NOTHING, and it says where it stopped. A plan that half-applied
110
+ * leaves a graph nobody meant and an undo nobody trusts, so what the batch
111
+ * has written is taken back before the error reaches the caller — and the
112
+ * result names the call that failed and why, because a plan that silently
113
+ * vanished would be its own kind of wrong. `keepWhatRan` is for a caller who
114
+ * would rather have the half: a long seeding whose last call was a typo.
115
+ */
116
+ export declare function applyPlan<S extends AnySchema>(store: Store<S>, plan: Plan, options?: {
117
+ readonly author?: Principal;
118
+ readonly batch?: string;
119
+ readonly keepWhatRan?: boolean;
120
+ /**
121
+ * Told before each entry lands, with the resolved arguments — so a
122
+ * body can walk to the target before the op does, and the activity
123
+ * mark then lights where it is standing.
124
+ */
125
+ readonly before?: (entry: PlanEntry, args: Readonly<Record<string, unknown>>) => void;
126
+ }): AppliedPlan<S>;
127
+ /**
128
+ * EVERYTHING THAT GOES IF THIS GOES.
129
+ *
130
+ * Declining the area declines the tree standing in it. A review a person
131
+ * cannot disagree with is not a review — a model confident about eleven
132
+ * things and wrong about the twelfth is the normal case — and the twelfth
133
+ * is very often the one the other four point at. Saying so BEFORE the press
134
+ * is the difference between a review and a surprise.
135
+ *
136
+ * Only what POINTS AT it, transitively. A call that merely mentions the same
137
+ * subject is its own business.
138
+ */
139
+ export declare function dependentsOf(plan: Plan, name: string): readonly PlanEntry[];
140
+ /**
141
+ * The plan without those entries, and without anything left pointing at
142
+ * nothing — the same plan a person is left with after declining one thing.
143
+ *
144
+ * Re-planned rather than filtered, so what comes back is ordered, judged and
145
+ * counted exactly like the plan it came from.
146
+ */
147
+ export declare function without<S extends AnySchema>(store: Store<S>, plan: Plan, declined: Iterable<string>, options?: PlanOptions<S>): Plan;
148
+ /** What a plan would do, in the words a person reviewing it needs. */
149
+ export declare function describePlan(plan: Plan): string;
150
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAMtE;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,yCAAyC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,IAAI;IACnB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC;IACvC,uCAAuC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