toolsplice-core 0.0.1 → 0.0.2
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 +26 -17
- package/dist/abortable.d.ts +6 -0
- package/dist/abortable.js +50 -0
- package/dist/adaptive-read.d.ts +50 -0
- package/dist/adaptive-read.js +780 -0
- package/dist/answer-wait.d.ts +7 -0
- package/dist/answer-wait.js +45 -0
- package/dist/cache-reads.d.ts +18 -0
- package/dist/cache-reads.js +89 -0
- package/dist/calibration-ledger.d.ts +37 -0
- package/dist/calibration-ledger.js +148 -0
- package/dist/calibration-marker.d.ts +4 -0
- package/dist/calibration-marker.js +77 -0
- package/dist/catalog-setup.d.ts +33 -0
- package/dist/catalog-setup.js +89 -0
- package/dist/catalog.d.ts +10 -0
- package/dist/catalog.js +42 -0
- package/dist/checkpoint-files.d.ts +15 -0
- package/dist/checkpoint-files.js +99 -0
- package/dist/coalesce-reads.d.ts +6 -0
- package/dist/coalesce-reads.js +33 -0
- package/dist/contract-caller.d.ts +2 -1
- package/dist/contract-caller.js +35 -16
- package/dist/contract-schema.d.ts +3 -1
- package/dist/contract-schema.js +34 -4
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.js +5 -1
- package/dist/core.d.ts +31 -1
- package/dist/core.js +27 -0
- package/dist/db-final-answer.d.ts +9 -0
- package/dist/db-final-answer.js +62 -0
- package/dist/define.d.ts +78 -0
- package/dist/define.js +14 -0
- package/dist/final-answer-stores.d.ts +71 -0
- package/dist/final-answer-stores.js +72 -0
- package/dist/final-answer.d.ts +32 -0
- package/dist/final-answer.js +104 -0
- package/dist/impact.d.ts +48 -0
- package/dist/impact.js +71 -0
- package/dist/local-tool.d.ts +18 -0
- package/dist/local-tool.js +32 -0
- package/dist/mcp-apps.d.ts +53 -0
- package/dist/mcp-apps.js +32 -0
- package/dist/mcp-event-delivery.d.ts +98 -0
- package/dist/mcp-event-delivery.js +211 -0
- package/dist/mcp-extensions.d.ts +46 -0
- package/dist/mcp-extensions.js +200 -0
- package/dist/mcp-peer.d.ts +45 -0
- package/dist/mcp-peer.js +207 -0
- package/dist/mcp-server-card.d.ts +21 -0
- package/dist/mcp-server-card.js +54 -0
- package/dist/page-checkpoint.d.ts +71 -0
- package/dist/page-checkpoint.js +286 -0
- package/dist/page-read-gate.d.ts +15 -0
- package/dist/page-read-gate.js +48 -0
- package/dist/pattern.d.ts +1 -0
- package/dist/pattern.js +27 -5
- package/dist/read-pages.d.ts +25 -0
- package/dist/read-pages.js +85 -0
- package/dist/read-policy.d.ts +6 -0
- package/dist/read-policy.js +16 -0
- package/dist/read-steps.d.ts +12 -0
- package/dist/read-steps.js +36 -0
- package/dist/result-session.d.ts +109 -0
- package/dist/result-session.js +620 -0
- package/dist/route-checkpoint.d.ts +3 -0
- package/dist/route-checkpoint.js +80 -0
- package/dist/route-evaluation.d.ts +141 -0
- package/dist/route-evaluation.js +329 -0
- package/dist/row-groups.d.ts +17 -0
- package/dist/row-groups.js +79 -0
- package/dist/row-query.d.ts +62 -0
- package/dist/row-query.js +172 -0
- package/dist/rules.d.ts +30 -0
- package/dist/rules.js +72 -0
- package/dist/run-diagnostics.d.ts +75 -0
- package/dist/run-diagnostics.js +212 -0
- package/dist/search-fetch.d.ts +50 -0
- package/dist/search-fetch.js +264 -0
- package/dist/skill-files.d.ts +9 -0
- package/dist/skill-files.js +49 -0
- package/dist/splice-diagnostics.d.ts +4 -0
- package/dist/splice-diagnostics.js +24 -16
- package/dist/splice-recording.d.ts +29 -2
- package/dist/splice-recording.js +22 -5
- package/dist/splice.d.ts +98 -1
- package/dist/splice.js +225 -27
- package/dist/sqlite-checkpoint-store.d.ts +5 -0
- package/dist/sqlite-checkpoint-store.js +91 -0
- package/dist/sqlite-checkpoint-worker.js +115 -0
- package/dist/test-difference.d.ts +13 -0
- package/dist/test-difference.js +42 -0
- package/dist/testing.d.ts +122 -0
- package/dist/testing.js +261 -0
- package/dist/text-pages.d.ts +24 -0
- package/dist/text-pages.js +36 -0
- package/dist/tool-discovery.d.ts +59 -0
- package/dist/tool-discovery.js +136 -0
- package/dist/unevaluated.d.ts +7 -0
- package/dist/unevaluated.js +156 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workflow-json.js +1 -1
- package/integrations/ai.d.mts +36 -0
- package/integrations/ai.mjs +178 -0
- package/integrations/call-options.mjs +9 -0
- package/integrations/langchain.d.mts +31 -0
- package/integrations/langchain.mjs +114 -0
- package/integrations/managed.mjs +154 -0
- package/integrations/types.d.mts +13 -0
- package/package.json +30 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { currentDiagnostics, recordReadResult } from "./run-diagnostics.js";
|
|
2
|
+
import { markdownPageFacts } from "./adaptive-read.js";
|
|
3
|
+
import { abortable, withCallDeadline, isReadDeadline } from "./abortable.js";
|
|
4
|
+
import { readSplicePath } from "./splice.js";
|
|
5
|
+
import { copyJson, jsonObject, pointerParts } from "./workflow-json.js";
|
|
6
|
+
function positiveRank(rank) {
|
|
7
|
+
return typeof rank === "number" && Number.isSafeInteger(rank) && rank >= 1;
|
|
8
|
+
}
|
|
9
|
+
function canonicalOrigin(authority) {
|
|
10
|
+
const match = /^(https?):\/\/(\[[a-f0-9:.]+\]|[a-z0-9.-]+)(?::\d{1,5})?$/i.exec(authority);
|
|
11
|
+
if (!match)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(authority);
|
|
15
|
+
// Reject ambiguous legacy IPv4 spellings in a source-provided location.
|
|
16
|
+
if (!match[2].startsWith("[") && url.hostname !== match[2].toLowerCase())
|
|
17
|
+
return;
|
|
18
|
+
return url.origin;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function trustedOrigins(origins) {
|
|
25
|
+
if (!Array.isArray(origins) || !origins.length)
|
|
26
|
+
throw new TypeError("Specify allowed HTTP(S) origins.");
|
|
27
|
+
return new Set(origins.map((s) => {
|
|
28
|
+
const origin = typeof s === "string" && canonicalOrigin(s.replace(/\/$/, ""));
|
|
29
|
+
if (!origin)
|
|
30
|
+
throw new TypeError("Expected an HTTP(S) origin without credentials or a path.");
|
|
31
|
+
return origin;
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
// Local JSON Pointer references keep pointing into the search schema after nesting.
|
|
35
|
+
// Visit only schema positions so example payloads and const values stay literal.
|
|
36
|
+
function nestSearchSchema(root) {
|
|
37
|
+
function visit(value, top = false) {
|
|
38
|
+
if (!jsonObject(value) || (!top && Object.hasOwn(value, "$id")))
|
|
39
|
+
return;
|
|
40
|
+
if (typeof value.$ref === "string" &&
|
|
41
|
+
(value.$ref === "#" || value.$ref.startsWith("#/")))
|
|
42
|
+
value.$ref = "#/properties/search" + value.$ref.slice(1);
|
|
43
|
+
for (const key of [
|
|
44
|
+
"properties",
|
|
45
|
+
"patternProperties",
|
|
46
|
+
"$defs",
|
|
47
|
+
"definitions",
|
|
48
|
+
"dependentSchemas",
|
|
49
|
+
"dependencies",
|
|
50
|
+
]) {
|
|
51
|
+
const schemas = value[key];
|
|
52
|
+
if (jsonObject(schemas))
|
|
53
|
+
Object.values(schemas).forEach((s) => visit(s));
|
|
54
|
+
}
|
|
55
|
+
for (const key of [
|
|
56
|
+
"items",
|
|
57
|
+
"prefixItems",
|
|
58
|
+
"allOf",
|
|
59
|
+
"anyOf",
|
|
60
|
+
"oneOf",
|
|
61
|
+
"not",
|
|
62
|
+
"if",
|
|
63
|
+
"then",
|
|
64
|
+
"else",
|
|
65
|
+
"contains",
|
|
66
|
+
"additionalItems",
|
|
67
|
+
"additionalProperties",
|
|
68
|
+
"propertyNames",
|
|
69
|
+
"unevaluatedProperties",
|
|
70
|
+
"unevaluatedItems",
|
|
71
|
+
"contentSchema",
|
|
72
|
+
]) {
|
|
73
|
+
const sub = value[key];
|
|
74
|
+
if (Array.isArray(sub))
|
|
75
|
+
sub.forEach((s) => visit(s));
|
|
76
|
+
else
|
|
77
|
+
visit(sub);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const metadata = {};
|
|
81
|
+
for (const k of ["$schema", "$id"])
|
|
82
|
+
if (Object.hasOwn(root, k)) {
|
|
83
|
+
metadata[k] = root[k];
|
|
84
|
+
delete root[k];
|
|
85
|
+
}
|
|
86
|
+
visit(root, true);
|
|
87
|
+
return metadata;
|
|
88
|
+
}
|
|
89
|
+
export class SearchFetchTool {
|
|
90
|
+
search;
|
|
91
|
+
fetchPage;
|
|
92
|
+
definition;
|
|
93
|
+
#origins;
|
|
94
|
+
#rank;
|
|
95
|
+
#flat;
|
|
96
|
+
#extras;
|
|
97
|
+
#markdown;
|
|
98
|
+
#headingLevel;
|
|
99
|
+
#results;
|
|
100
|
+
#url;
|
|
101
|
+
#argument;
|
|
102
|
+
#retryFetchIf;
|
|
103
|
+
constructor(search, fetchPage, options) {
|
|
104
|
+
this.search = search;
|
|
105
|
+
this.fetchPage = fetchPage;
|
|
106
|
+
this.#origins = trustedOrigins(options.origins);
|
|
107
|
+
if (options.retryFetchIf !== undefined &&
|
|
108
|
+
typeof options.retryFetchIf !== "function")
|
|
109
|
+
throw new TypeError("retryFetchIf must be a function.");
|
|
110
|
+
this.#retryFetchIf = options.retryFetchIf;
|
|
111
|
+
this.#rank = options.rank ?? 1;
|
|
112
|
+
if (this.#rank !== "input" && !positiveRank(this.#rank))
|
|
113
|
+
throw new RangeError("Expected a positive result rank.");
|
|
114
|
+
this.#results = options.resultsPath ?? "/results";
|
|
115
|
+
this.#url = options.urlPath ?? "/contentUrl";
|
|
116
|
+
this.#argument = options.urlArgument ?? "url";
|
|
117
|
+
if ([this.#results, this.#url].some((p) => pointerParts(p).length > 32))
|
|
118
|
+
throw new Error("Handoff paths allow at most 32 segments.");
|
|
119
|
+
const input = copyJson(search.definition.inputSchema);
|
|
120
|
+
const dynamic = this.#rank === "input";
|
|
121
|
+
const properties = input.properties ?? {};
|
|
122
|
+
this.#markdown = options.pageView === "markdown";
|
|
123
|
+
if (options.headingLevel !== undefined && (!this.#markdown || !Number.isInteger(options.headingLevel) || options.headingLevel < 1 || options.headingLevel > 6))
|
|
124
|
+
throw new RangeError("headingLevel requires a Markdown view and an integer from 1 to 6.");
|
|
125
|
+
this.#headingLevel = options.headingLevel ?? 1;
|
|
126
|
+
if (options.pageView !== undefined &&
|
|
127
|
+
!["page", "markdown"].includes(options.pageView))
|
|
128
|
+
throw new TypeError("Unknown page view.");
|
|
129
|
+
const extras = {};
|
|
130
|
+
if (dynamic)
|
|
131
|
+
extras.rank = {
|
|
132
|
+
type: "integer",
|
|
133
|
+
minimum: 1,
|
|
134
|
+
description: "One-based result position. Use 1 for first, 2 for second.",
|
|
135
|
+
};
|
|
136
|
+
if (this.#markdown)
|
|
137
|
+
extras.countLiteral = {
|
|
138
|
+
type: "string",
|
|
139
|
+
minLength: 1,
|
|
140
|
+
maxLength: 256,
|
|
141
|
+
description: "To count exact case-sensitive occurrences in the full Markdown page, supply the requested literal.",
|
|
142
|
+
};
|
|
143
|
+
this.#extras = new Set(Object.keys(extras));
|
|
144
|
+
this.#flat =
|
|
145
|
+
input.type === "object" &&
|
|
146
|
+
!JSON.stringify(input).includes('"$ref":') &&
|
|
147
|
+
jsonObject(properties) &&
|
|
148
|
+
Object.keys(extras).every((k) => !Object.hasOwn(properties, k)) &&
|
|
149
|
+
Object.keys(input).every((k) => [
|
|
150
|
+
"type",
|
|
151
|
+
"properties",
|
|
152
|
+
"required",
|
|
153
|
+
"additionalProperties",
|
|
154
|
+
"title",
|
|
155
|
+
"description",
|
|
156
|
+
"$comment",
|
|
157
|
+
"$schema",
|
|
158
|
+
"$defs",
|
|
159
|
+
"definitions",
|
|
160
|
+
].includes(k));
|
|
161
|
+
const flat = this.#flat && jsonObject(properties);
|
|
162
|
+
const wrapped = flat
|
|
163
|
+
? { ...input }
|
|
164
|
+
: {
|
|
165
|
+
...(this.#extras.size ? nestSearchSchema(input) : {}),
|
|
166
|
+
type: "object",
|
|
167
|
+
additionalProperties: false,
|
|
168
|
+
};
|
|
169
|
+
wrapped.properties = {
|
|
170
|
+
...(flat ? properties : { search: input }),
|
|
171
|
+
...extras,
|
|
172
|
+
};
|
|
173
|
+
wrapped.required = [
|
|
174
|
+
...(flat
|
|
175
|
+
? Array.isArray(input.required)
|
|
176
|
+
? input.required
|
|
177
|
+
: []
|
|
178
|
+
: ["search"]),
|
|
179
|
+
...(dynamic ? ["rank"] : []),
|
|
180
|
+
];
|
|
181
|
+
const result = this.#markdown
|
|
182
|
+
? `Returns the exact requestedUrl and first Markdown H${this.#headingLevel} heading. Supply countLiteral when the request asks for a literal count. The returned count covers the full page.`
|
|
183
|
+
: "A successful call has already fetched the page. Use the returned page evidence to answer.";
|
|
184
|
+
this.definition = {
|
|
185
|
+
name: options.name ?? "search_then_fetch",
|
|
186
|
+
description: `Search and fetch ${dynamic ? "the selected result (one-based rank)" : "result number " + this.#rank} in one call. Preserve the supplied search arguments exactly. ${result} If the rank is absent it returns no_match.`,
|
|
187
|
+
inputSchema: this.#extras.size ? wrapped : input,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
execute(args, options) {
|
|
191
|
+
const trace = currentDiagnostics();
|
|
192
|
+
const result = withCallDeadline(options, "Search-to-fetch handoff timed out.", (bounded) => this.#run(args, bounded));
|
|
193
|
+
return trace ? result.catch(error => {
|
|
194
|
+
const type = options?.signal?.aborted ? "cancel" : isReadDeadline(error) ? "deadline" : error?.name === "AbortError" ? "cancel" : "handoff-error";
|
|
195
|
+
trace.record({ type });
|
|
196
|
+
throw error;
|
|
197
|
+
}) : result;
|
|
198
|
+
}
|
|
199
|
+
async #run(args, options) {
|
|
200
|
+
options?.signal?.throwIfAborted();
|
|
201
|
+
const dynamic = this.#rank === "input";
|
|
202
|
+
const rank = dynamic ? args.rank : this.#rank;
|
|
203
|
+
const nested = this.#extras.size > 0 && !this.#flat;
|
|
204
|
+
const searchArgs = nested
|
|
205
|
+
? args.search
|
|
206
|
+
: this.#extras.size
|
|
207
|
+
? Object.fromEntries(Object.entries(args).filter(([k]) => !this.#extras.has(k)))
|
|
208
|
+
: args;
|
|
209
|
+
const literal = this.#markdown ? args.countLiteral : undefined;
|
|
210
|
+
if (literal !== undefined &&
|
|
211
|
+
(typeof literal !== "string" ||
|
|
212
|
+
!literal.length ||
|
|
213
|
+
Array.from(literal).length > 256))
|
|
214
|
+
throw new TypeError("countLiteral must contain 1 to 256 characters.");
|
|
215
|
+
if (!positiveRank(rank) ||
|
|
216
|
+
!jsonObject(searchArgs) ||
|
|
217
|
+
(nested &&
|
|
218
|
+
Object.keys(args).some((k) => k !== "search" && !this.#extras.has(k))))
|
|
219
|
+
throw new TypeError("Invalid search arguments or result rank.");
|
|
220
|
+
const trace = currentDiagnostics();
|
|
221
|
+
trace?.record({ type: "read", operation: "search" });
|
|
222
|
+
const hits = readSplicePath(recordReadResult(await this.search.execute(copyJson(searchArgs), options)), this.#results).value;
|
|
223
|
+
options?.signal?.throwIfAborted();
|
|
224
|
+
if (!Array.isArray(hits))
|
|
225
|
+
throw new Error("The search result collection must be an array.");
|
|
226
|
+
if (rank > hits.length)
|
|
227
|
+
return { status: "no_match", rank, totalResults: hits.length };
|
|
228
|
+
const url = readSplicePath(hits[rank - 1], this.#url).value;
|
|
229
|
+
const authority = typeof url === "string" &&
|
|
230
|
+
!/[\s\\\x00-\x1f\x7f]/u.test(url) &&
|
|
231
|
+
/^(https?:\/\/[^/?#]+)(?:[/?#]|$)/i.exec(url)?.[1];
|
|
232
|
+
const origin = authority && canonicalOrigin(authority);
|
|
233
|
+
if (!origin || !this.#origins.has(origin))
|
|
234
|
+
throw new Error("The selected result has no permitted fetch URL.");
|
|
235
|
+
options?.signal?.throwIfAborted();
|
|
236
|
+
const fetch = () => {
|
|
237
|
+
trace?.record({ type: "read", operation: "fetch" });
|
|
238
|
+
return this.fetchPage.execute({ [this.#argument]: url }, options);
|
|
239
|
+
};
|
|
240
|
+
let page;
|
|
241
|
+
try {
|
|
242
|
+
page = await fetch();
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
options?.signal?.throwIfAborted();
|
|
246
|
+
const decide = this.#retryFetchIf;
|
|
247
|
+
if (!decide || (error instanceof Error && error.name === "AbortError"))
|
|
248
|
+
throw error;
|
|
249
|
+
if ((await abortable(() => decide(error), options?.signal)) !== true)
|
|
250
|
+
throw error;
|
|
251
|
+
options?.signal?.throwIfAborted();
|
|
252
|
+
trace?.record({ type: "retry" });
|
|
253
|
+
page = await fetch();
|
|
254
|
+
}
|
|
255
|
+
options?.signal?.throwIfAborted();
|
|
256
|
+
recordReadResult(page);
|
|
257
|
+
return this.#markdown
|
|
258
|
+
? { requestedUrl: url, ...markdownPageFacts(page, literal, this.#headingLevel) }
|
|
259
|
+
: { requestedUrl: url, page };
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
export function searchThenFetch(search, fetchPage, options) {
|
|
263
|
+
return new SearchFetchTool(search, fetchPage, options);
|
|
264
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Identify manifest resources without translating them to host filesystem paths. */
|
|
2
|
+
export declare function skillFile(uri: string, base?: string): {
|
|
3
|
+
path: string[];
|
|
4
|
+
origin: string;
|
|
5
|
+
key: string;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
/** Optional YAML parser is loaded only for an entry file, after verifying its bytes. */
|
|
9
|
+
export declare function defaultSkillFrontmatter(markdown: string): Promise<any>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Identify manifest resources without translating them to host filesystem paths. */
|
|
2
|
+
export function skillFile(uri, base) {
|
|
3
|
+
let url;
|
|
4
|
+
try {
|
|
5
|
+
url = new URL(uri, base);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
throw new Error("Invalid MCP skill resource URI.");
|
|
9
|
+
}
|
|
10
|
+
const path = url.pathname.split("/").map((segment) => {
|
|
11
|
+
const value = decodeURIComponent(segment);
|
|
12
|
+
if (/[\/\\\x00-\x1f\x7f]/u.test(value))
|
|
13
|
+
throw new Error("Invalid MCP skill resource path.");
|
|
14
|
+
return value;
|
|
15
|
+
});
|
|
16
|
+
if (!url.href.includes("://") || !path.at(-1))
|
|
17
|
+
throw new Error("Expected a skill file URI.");
|
|
18
|
+
const origin = url.protocol +
|
|
19
|
+
"//" +
|
|
20
|
+
(url.username || url.password
|
|
21
|
+
? url.username + ":" + url.password + "@"
|
|
22
|
+
: "") +
|
|
23
|
+
url.host;
|
|
24
|
+
return {
|
|
25
|
+
path,
|
|
26
|
+
origin,
|
|
27
|
+
key: JSON.stringify([origin, path, url.search]),
|
|
28
|
+
name: path.at(-2) || decodeURIComponent(url.host),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Optional YAML parser is loaded only for an entry file, after verifying its bytes. */
|
|
32
|
+
export async function defaultSkillFrontmatter(markdown) {
|
|
33
|
+
const normalized = markdown.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
|
|
34
|
+
const match = /^---[ \t]*\n([\s\S]*?)^---[ \t]*(?:\n|$)/m.exec(normalized);
|
|
35
|
+
if (!match || match.index !== 0)
|
|
36
|
+
throw new Error("Expected YAML frontmatter at the start of SKILL.md.");
|
|
37
|
+
const packageName = "yaml";
|
|
38
|
+
const yaml = await import(packageName).catch(() => {
|
|
39
|
+
throw new Error("Install yaml or pass a Markdown frontmatter parser to skills.open().");
|
|
40
|
+
});
|
|
41
|
+
const document = yaml.parseDocument(match[1], {
|
|
42
|
+
version: "1.2",
|
|
43
|
+
schema: "core",
|
|
44
|
+
uniqueKeys: true,
|
|
45
|
+
});
|
|
46
|
+
if (document.errors.length || document.warnings.length)
|
|
47
|
+
throw new Error("Invalid YAML skill frontmatter.");
|
|
48
|
+
return document.toJS({ maxAliasCount: 64 });
|
|
49
|
+
}
|
|
@@ -5,6 +5,7 @@ export interface SpliceFieldOrigin {
|
|
|
5
5
|
origin: "source" | "context" | "literal";
|
|
6
6
|
pointer?: string;
|
|
7
7
|
selectionPointer?: string;
|
|
8
|
+
matchPointer?: string;
|
|
8
9
|
parsedJson?: boolean;
|
|
9
10
|
rowIndex?: number;
|
|
10
11
|
}
|
|
@@ -27,14 +28,17 @@ export interface SpliceExplanation {
|
|
|
27
28
|
pointer: string;
|
|
28
29
|
parsedJson: boolean;
|
|
29
30
|
forEach: boolean;
|
|
31
|
+
matchPointer?: string;
|
|
30
32
|
};
|
|
31
33
|
summary: string;
|
|
32
34
|
issues: {
|
|
33
35
|
code: string;
|
|
34
36
|
path: string;
|
|
35
37
|
fields: SpliceFieldOrigin[];
|
|
38
|
+
ruleId?: string;
|
|
36
39
|
}[];
|
|
37
40
|
sideEffects: "no-destination-calls" | "destination-effects-may-have-occurred";
|
|
38
41
|
}
|
|
42
|
+
export declare function describeBinding(spec: SpliceSpec, bindingIndex: number, rowIndex?: number): SpliceFieldOrigin;
|
|
39
43
|
/** Path-only explanation. Never traverses causes or includes inputs, results or literal values. */
|
|
40
44
|
export declare function explainSpliceError(plan: SpliceSpec, error: SpliceError): SpliceExplanation;
|
|
@@ -4,6 +4,25 @@ const overlaps = (a, b) => {
|
|
|
4
4
|
const x = pointerParts(a), y = pointerParts(b);
|
|
5
5
|
return x.slice(0, Math.min(x.length, y.length)).every((p, i) => p === y[i]);
|
|
6
6
|
};
|
|
7
|
+
export function describeBinding(spec, bindingIndex, rowIndex) {
|
|
8
|
+
const binding = spec.bindings[bindingIndex];
|
|
9
|
+
return {
|
|
10
|
+
bindingIndex,
|
|
11
|
+
targetPointer: binding.to,
|
|
12
|
+
...("from" in binding
|
|
13
|
+
? {
|
|
14
|
+
origin: "source",
|
|
15
|
+
pointer: binding.from,
|
|
16
|
+
selectionPointer: spec.source.path ?? "",
|
|
17
|
+
...(spec.source.matchOne ? { matchPointer: spec.source.matchOne.path } : {}),
|
|
18
|
+
parsedJson: spec.source.parseJson ?? false,
|
|
19
|
+
}
|
|
20
|
+
: "fromContext" in binding
|
|
21
|
+
? { origin: "context", pointer: binding.fromContext }
|
|
22
|
+
: { origin: "literal" }),
|
|
23
|
+
...(rowIndex === undefined ? {} : { rowIndex }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
7
26
|
/** Path-only explanation. Never traverses causes or includes inputs, results or literal values. */
|
|
8
27
|
export function explainSpliceError(plan, error) {
|
|
9
28
|
const spec = parseSpliceSpec(plan);
|
|
@@ -40,23 +59,11 @@ export function explainSpliceError(plan, error) {
|
|
|
40
59
|
overlaps(issue.path.slice(10), binding.to))));
|
|
41
60
|
if (!relevant)
|
|
42
61
|
continue;
|
|
43
|
-
fields.push(
|
|
44
|
-
bindingIndex,
|
|
45
|
-
targetPointer: binding.to,
|
|
46
|
-
...("from" in binding
|
|
47
|
-
? {
|
|
48
|
-
origin: "source",
|
|
49
|
-
pointer: binding.from,
|
|
50
|
-
selectionPointer: spec.source.path ?? "",
|
|
51
|
-
parsedJson: spec.source.parseJson ?? false,
|
|
52
|
-
}
|
|
53
|
-
: "fromContext" in binding
|
|
54
|
-
? { origin: "context", pointer: binding.fromContext }
|
|
55
|
-
: { origin: "literal" }),
|
|
56
|
-
...(rowIndex === undefined ? {} : { rowIndex }),
|
|
57
|
-
});
|
|
62
|
+
fields.push(describeBinding(spec, bindingIndex, rowIndex));
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
const ruleIndex = /^\/rules\/(\d+)$/.exec(path);
|
|
65
|
+
const rule = ruleIndex ? spec.rules?.[Number(ruleIndex[1])] : undefined;
|
|
66
|
+
return { code: issue.code, path: issue.path, fields, ...(rule ? { ruleId: rule.id } : {}) };
|
|
60
67
|
});
|
|
61
68
|
return {
|
|
62
69
|
stage: error.stage,
|
|
@@ -70,6 +77,7 @@ export function explainSpliceError(plan, error) {
|
|
|
70
77
|
pointer: spec.source.path ?? "",
|
|
71
78
|
parsedJson: spec.source.parseJson ?? false,
|
|
72
79
|
forEach: spec.forEach ?? false,
|
|
80
|
+
...(spec.source.matchOne ? { matchPointer: spec.source.matchOne.path } : {}),
|
|
73
81
|
},
|
|
74
82
|
summary: `${error.stage} validation or execution failed; ${error.completedTargets} destination result(s) were acknowledged and collected.`,
|
|
75
83
|
issues,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type ReadPolicy } from "./read-policy.js";
|
|
1
2
|
import type { ToolCaller } from "./execution.js";
|
|
2
3
|
import type { ToolResultLike } from "./extract.js";
|
|
3
4
|
import { type ContractSnapshot } from "./contracts.js";
|
|
4
|
-
import { SpliceError, type SpliceSpec, type SpliceRunOptions } from "./splice.js";
|
|
5
|
+
import { SpliceError, type SpliceSpec, type SpliceRunOptions, type SpliceReadOptions } from "./splice.js";
|
|
5
6
|
interface RecordedCall {
|
|
6
7
|
side: "source" | "target";
|
|
7
8
|
name: string;
|
|
@@ -36,6 +37,7 @@ export interface SpliceRecording {
|
|
|
36
37
|
input?: unknown;
|
|
37
38
|
context?: unknown;
|
|
38
39
|
allowReview: boolean;
|
|
40
|
+
readPolicy?: ReadPolicy;
|
|
39
41
|
cancellationObserved: boolean;
|
|
40
42
|
calls: RecordedCall[];
|
|
41
43
|
outcome: RecordedOutcome;
|
|
@@ -55,7 +57,8 @@ export interface SpliceRecordingOptions {
|
|
|
55
57
|
}
|
|
56
58
|
export declare function createSpliceRecorder(plan: SpliceSpec, source: ContractSnapshot, target: ContractSnapshot, options?: SpliceRecordingOptions): {
|
|
57
59
|
report: import("./splice.js").SpliceReport;
|
|
58
|
-
run: (
|
|
60
|
+
run: (source: ToolCaller, target: ToolCaller, input: unknown, options?: SpliceRunOptions) => Promise<unknown[]>;
|
|
61
|
+
runReads: (source: ToolCaller, target: ToolCaller, input: unknown, options?: SpliceReadOptions) => Promise<unknown[]>;
|
|
59
62
|
snapshot: () => SpliceRecording;
|
|
60
63
|
};
|
|
61
64
|
export declare function parseSpliceRecording(input: unknown): SpliceRecording;
|
|
@@ -102,4 +105,28 @@ export declare function replaySpliceRecording(input: SpliceRecording | string, o
|
|
|
102
105
|
explanation?: import("./splice-diagnostics.js").SpliceExplanation | undefined;
|
|
103
106
|
caveats: string[];
|
|
104
107
|
}>;
|
|
108
|
+
export declare function replayLoadedFixture(fixture: ReturnType<typeof loadReplayFixture>, options: SpliceReplayOptions): Promise<{
|
|
109
|
+
matched: boolean;
|
|
110
|
+
recordedOutcome: RecordedOutcome;
|
|
111
|
+
upgrade?: {
|
|
112
|
+
status: "failed" | "inconclusive" | "passed";
|
|
113
|
+
source: import("./contracts.js").ContractComparison;
|
|
114
|
+
target: import("./contracts.js").ContractComparison;
|
|
115
|
+
fingerprints: {
|
|
116
|
+
recordedSource: string;
|
|
117
|
+
candidateSource: string;
|
|
118
|
+
recordedTarget: string;
|
|
119
|
+
candidateTarget: string;
|
|
120
|
+
};
|
|
121
|
+
note: string;
|
|
122
|
+
} | undefined;
|
|
123
|
+
mode: "restored-fixture" | "saved-fixture";
|
|
124
|
+
networkCalls: 0;
|
|
125
|
+
consumedCalls: number;
|
|
126
|
+
recordedCalls: number;
|
|
127
|
+
outcome: RecordedOutcome;
|
|
128
|
+
result?: unknown[] | undefined;
|
|
129
|
+
explanation?: import("./splice-diagnostics.js").SpliceExplanation | undefined;
|
|
130
|
+
caveats: string[];
|
|
131
|
+
}>;
|
|
105
132
|
export {};
|
package/dist/splice-recording.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Explicit one-run capture and network-free replay. This is not a durable job journal.
|
|
2
|
+
import { parseReadPolicy } from "./read-policy.js";
|
|
1
3
|
import { VERSION } from "./version.js";
|
|
2
4
|
import { parseContractSnapshot, selectContractTools, compareContractSnapshots, } from "./contracts.js";
|
|
3
5
|
import { prepareSplice, parseSpliceSpec, SpliceError, } from "./splice.js";
|
|
@@ -98,10 +100,12 @@ export function createSpliceRecorder(plan, source, target, options = {}) {
|
|
|
98
100
|
entry.durationMs = Math.max(0, Date.now() - started);
|
|
99
101
|
}
|
|
100
102
|
};
|
|
101
|
-
const
|
|
103
|
+
const captureRun = async (sourceCaller, targetCaller, input, runOptions, policy) => {
|
|
102
104
|
if (state !== "new")
|
|
103
105
|
throw new Error("A recorder captures one run; create another recorder for concurrent or subsequent runs.");
|
|
104
106
|
state = "running";
|
|
107
|
+
if (policy)
|
|
108
|
+
recording.readPolicy = policy;
|
|
105
109
|
recording.allowReview = runOptions.allowReview === true;
|
|
106
110
|
if (capture === "payloads") {
|
|
107
111
|
recording.plan = captureValue(spec);
|
|
@@ -117,7 +121,8 @@ export function createSpliceRecorder(plan, source, target, options = {}) {
|
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
123
|
try {
|
|
120
|
-
const
|
|
124
|
+
const execute = policy ? prepared.runReads : prepared.run;
|
|
125
|
+
const result = await execute(wrap("source", sourceCaller), wrap("target", targetCaller), input, { ...runOptions, ...policy });
|
|
121
126
|
let resultFingerprint;
|
|
122
127
|
try {
|
|
123
128
|
resultFingerprint = jsonFingerprint(result);
|
|
@@ -218,7 +223,12 @@ export function createSpliceRecorder(plan, source, target, options = {}) {
|
|
|
218
223
|
detached.fingerprint = hashRecording(detached);
|
|
219
224
|
return copyJson(detached, maxBytes);
|
|
220
225
|
};
|
|
221
|
-
|
|
226
|
+
const run = (source, target, input, options = {}) => captureRun(source, target, input, options);
|
|
227
|
+
const runReads = async (source, target, input, options = {}) => {
|
|
228
|
+
const policy = parseReadPolicy({ concurrency: options.concurrency ?? 4, assumeReadOnly: options.assumeReadOnly ?? false });
|
|
229
|
+
return captureRun(source, target, input, options, policy);
|
|
230
|
+
};
|
|
231
|
+
return { report: prepared.report, run, runReads, snapshot };
|
|
222
232
|
}
|
|
223
233
|
export function parseSpliceRecording(input) {
|
|
224
234
|
const r = parseWorkflowJson(input);
|
|
@@ -248,6 +258,8 @@ export function parseSpliceRecording(input) {
|
|
|
248
258
|
!["succeeded", "failed"].includes(String(r.outcome.status)) ||
|
|
249
259
|
typeof r.fingerprint !== "string")
|
|
250
260
|
return bad();
|
|
261
|
+
if (r.readPolicy !== undefined)
|
|
262
|
+
parseReadPolicy(r.readPolicy);
|
|
251
263
|
for (const c of r.calls) {
|
|
252
264
|
if (!jsonObject(c) ||
|
|
253
265
|
!["source", "target"].includes(String(c.side)) ||
|
|
@@ -329,7 +341,10 @@ export function loadReplayFixture(input, options = {}) {
|
|
|
329
341
|
}
|
|
330
342
|
/** No live caller or connection can be supplied. Saved responses are consumed strictly in order. */
|
|
331
343
|
export async function replaySpliceRecording(input, options = {}) {
|
|
332
|
-
|
|
344
|
+
return replayLoadedFixture(loadReplayFixture(input, options), options);
|
|
345
|
+
}
|
|
346
|
+
export async function replayLoadedFixture(fixture, options) {
|
|
347
|
+
const { recording, restored, spec, source: originalSource, target: originalTarget, } = fixture;
|
|
333
348
|
const candidate = (value, original, tool) => {
|
|
334
349
|
if (value === undefined)
|
|
335
350
|
return original;
|
|
@@ -377,7 +392,9 @@ export async function replaySpliceRecording(input, options = {}) {
|
|
|
377
392
|
},
|
|
378
393
|
]);
|
|
379
394
|
const prepared = prepareSplice(spec, s, t);
|
|
380
|
-
|
|
395
|
+
const execute = recording.readPolicy ? prepared.runReads : prepared.run;
|
|
396
|
+
result = await execute(caller("source"), caller("target"), recording.input, {
|
|
397
|
+
...recording.readPolicy,
|
|
381
398
|
allowReview: options.allowReview ?? recording.allowReview,
|
|
382
399
|
...(Object.hasOwn(recording, "context")
|
|
383
400
|
? { context: recording.context }
|