toolsplice 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 +62 -330
- 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/cli.js +545 -14
- 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/index.d.ts +32 -1
- package/dist/index.js +28 -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/probe.js +6 -19
- 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-driver-cli.d.ts +3 -0
- package/dist/route-driver-cli.js +43 -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-measure.d.ts +33 -0
- package/dist/splice-measure.js +55 -0
- package/dist/splice-project.d.ts +12 -6
- package/dist/splice-project.js +72 -20
- 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.d.ts +1 -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/v2.js +25 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workflow-json.js +1 -1
- package/docs/AGENT-FRAMEWORKS.md +431 -0
- package/docs/BENCHMARKS.md +43 -0
- package/docs/INTEGRATION-QUICKSTART.md +859 -0
- package/docs/LEARNING-AND-STORAGE.md +393 -0
- package/docs/MCP.md +204 -0
- package/docs/PROJECTS-AND-UPGRADES.md +67 -9
- package/docs/PYTHON-REFERENCE.md +348 -0
- package/docs/PYTHON.md +120 -0
- package/docs/RECORDING-AND-CORRECTIONS.md +30 -1
- package/docs/TESTING.md +259 -0
- package/examples/mcp-app/build.mjs +11 -0
- package/examples/mcp-app/view.mjs +22 -0
- package/examples/quickstart.mjs +43 -0
- package/examples/route-driver.mjs +67 -0
- 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 +47 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type SpliceRecording } from "./splice-recording.js";
|
|
2
|
+
export interface SpliceMeasurementOptions {
|
|
3
|
+
restorations?: Record<string, unknown>;
|
|
4
|
+
/** Count tokens in compact JSON tool-result text using the application's tokenizer. */
|
|
5
|
+
countTokens?: (text: string) => number;
|
|
6
|
+
}
|
|
7
|
+
export interface SpliceMeasurement {
|
|
8
|
+
format: "toolsplice-measurement";
|
|
9
|
+
formatVersion: 1;
|
|
10
|
+
basis: "compact-json-tool-results";
|
|
11
|
+
networkCalls: 0;
|
|
12
|
+
recordedUpstreamCalls: {
|
|
13
|
+
source: number;
|
|
14
|
+
target: number;
|
|
15
|
+
};
|
|
16
|
+
direct: {
|
|
17
|
+
modelToolCalls: number;
|
|
18
|
+
toolResultBytes: number;
|
|
19
|
+
toolResultTokens?: number;
|
|
20
|
+
};
|
|
21
|
+
composite: {
|
|
22
|
+
modelToolCalls: number;
|
|
23
|
+
toolResultBytes: number;
|
|
24
|
+
toolResultTokens?: number;
|
|
25
|
+
};
|
|
26
|
+
saved: {
|
|
27
|
+
modelToolCalls: number;
|
|
28
|
+
toolResultBytes: number;
|
|
29
|
+
toolResultTokens?: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Compare one decoded result per upstream call with the native composite's structuredContent. */
|
|
33
|
+
export declare function measureSpliceRecording(input: SpliceRecording | string, options?: SpliceMeasurementOptions): Promise<SpliceMeasurement>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { decode } from "./execution.js";
|
|
2
|
+
import { loadReplayFixture, replayLoadedFixture, } from "./splice-recording.js";
|
|
3
|
+
/** Compare one decoded result per upstream call with the native composite's structuredContent. */
|
|
4
|
+
export async function measureSpliceRecording(input, options = {}) {
|
|
5
|
+
const fixture = loadReplayFixture(input, options);
|
|
6
|
+
if (fixture.recording.outcome.status !== "succeeded" ||
|
|
7
|
+
fixture.recording.cancellationObserved)
|
|
8
|
+
throw new Error("Measurement requires a successful, uninterrupted recording.");
|
|
9
|
+
const replay = await replayLoadedFixture(fixture, {});
|
|
10
|
+
if (!replay.matched || !replay.result)
|
|
11
|
+
throw new Error("The saved handoff must reproduce its complete result before measurement.");
|
|
12
|
+
const metric = (modelToolCalls) => ({
|
|
13
|
+
modelToolCalls,
|
|
14
|
+
toolResultBytes: 0,
|
|
15
|
+
...(options.countTokens ? { toolResultTokens: 0 } : {}),
|
|
16
|
+
});
|
|
17
|
+
const add = (total, value) => {
|
|
18
|
+
const json = JSON.stringify(value);
|
|
19
|
+
total.toolResultBytes += Buffer.byteLength(json);
|
|
20
|
+
if (options.countTokens) {
|
|
21
|
+
const tokens = options.countTokens(json);
|
|
22
|
+
if (!Number.isSafeInteger(tokens) ||
|
|
23
|
+
tokens < 0 ||
|
|
24
|
+
!Number.isSafeInteger(total.toolResultTokens + tokens))
|
|
25
|
+
throw new Error("A token count must be a nonnegative safe integer.");
|
|
26
|
+
total.toolResultTokens = total.toolResultTokens + tokens;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const { calls } = fixture.recording;
|
|
30
|
+
const direct = metric(calls.length), composite = metric(1);
|
|
31
|
+
const recordedUpstreamCalls = { source: 0, target: 0 };
|
|
32
|
+
for (const call of calls) {
|
|
33
|
+
add(direct, decode(call.result));
|
|
34
|
+
recordedUpstreamCalls[call.side]++;
|
|
35
|
+
}
|
|
36
|
+
add(composite, { results: replay.result });
|
|
37
|
+
return {
|
|
38
|
+
format: "toolsplice-measurement",
|
|
39
|
+
formatVersion: 1,
|
|
40
|
+
basis: "compact-json-tool-results",
|
|
41
|
+
networkCalls: 0,
|
|
42
|
+
recordedUpstreamCalls,
|
|
43
|
+
direct,
|
|
44
|
+
composite,
|
|
45
|
+
saved: {
|
|
46
|
+
modelToolCalls: direct.modelToolCalls - composite.modelToolCalls,
|
|
47
|
+
toolResultBytes: direct.toolResultBytes - composite.toolResultBytes,
|
|
48
|
+
...(options.countTokens
|
|
49
|
+
? {
|
|
50
|
+
toolResultTokens: direct.toolResultTokens - composite.toolResultTokens,
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
package/dist/splice-project.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type SpliceRecording } from "./splice-recording.js";
|
|
2
|
+
import { type CatalogSetup } from "./catalog-setup.js";
|
|
2
3
|
export interface SpliceProjectOptions {
|
|
4
|
+
catalogs?: CatalogSetup;
|
|
3
5
|
recording?: SpliceRecording | string;
|
|
4
6
|
restorations?: Record<string, unknown>;
|
|
5
7
|
}
|
|
6
8
|
export declare function createSpliceProjectFiles(options?: SpliceProjectOptions): Promise<{
|
|
7
9
|
files: Record<string, string>;
|
|
8
|
-
origin: "recording" | "synthetic";
|
|
10
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
9
11
|
check: {
|
|
10
12
|
source: import("./splice.js").SpliceEndpoint;
|
|
11
13
|
target: import("./splice.js").SpliceEndpoint;
|
|
@@ -20,7 +22,8 @@ export declare function createSpliceProjectFiles(options?: SpliceProjectOptions)
|
|
|
20
22
|
preflightStatus: "blocked" | "ready" | "review";
|
|
21
23
|
status: "blocked" | "ready" | "review";
|
|
22
24
|
issues: import("./splice.js").SpliceIssue[];
|
|
23
|
-
origin: "recording" | "synthetic";
|
|
25
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
26
|
+
hasSourceInput?: boolean | undefined;
|
|
24
27
|
adapter: {
|
|
25
28
|
status: string;
|
|
26
29
|
};
|
|
@@ -48,7 +51,8 @@ export declare function checkSpliceProjectFiles(files: Record<string, string>):
|
|
|
48
51
|
preflightStatus: "blocked" | "ready" | "review";
|
|
49
52
|
status: "blocked" | "ready" | "review";
|
|
50
53
|
issues: import("./splice.js").SpliceIssue[];
|
|
51
|
-
origin: "recording" | "synthetic";
|
|
54
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
55
|
+
hasSourceInput?: boolean | undefined;
|
|
52
56
|
adapter: {
|
|
53
57
|
status: string;
|
|
54
58
|
};
|
|
@@ -63,7 +67,7 @@ export declare function checkSpliceProjectFiles(files: Record<string, string>):
|
|
|
63
67
|
export declare function initializeSpliceProject(directory: string, options?: SpliceProjectOptions): Promise<{
|
|
64
68
|
directory: string;
|
|
65
69
|
files: string[];
|
|
66
|
-
origin: "recording" | "synthetic";
|
|
70
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
67
71
|
check: {
|
|
68
72
|
source: import("./splice.js").SpliceEndpoint;
|
|
69
73
|
target: import("./splice.js").SpliceEndpoint;
|
|
@@ -78,7 +82,8 @@ export declare function initializeSpliceProject(directory: string, options?: Spl
|
|
|
78
82
|
preflightStatus: "blocked" | "ready" | "review";
|
|
79
83
|
status: "blocked" | "ready" | "review";
|
|
80
84
|
issues: import("./splice.js").SpliceIssue[];
|
|
81
|
-
origin: "recording" | "synthetic";
|
|
85
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
86
|
+
hasSourceInput?: boolean | undefined;
|
|
82
87
|
adapter: {
|
|
83
88
|
status: string;
|
|
84
89
|
};
|
|
@@ -105,7 +110,8 @@ export declare function checkSpliceProject(directory: string): Promise<{
|
|
|
105
110
|
preflightStatus: "blocked" | "ready" | "review";
|
|
106
111
|
status: "blocked" | "ready" | "review";
|
|
107
112
|
issues: import("./splice.js").SpliceIssue[];
|
|
108
|
-
origin: "recording" | "synthetic";
|
|
113
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
114
|
+
hasSourceInput?: boolean | undefined;
|
|
109
115
|
adapter: {
|
|
110
116
|
status: string;
|
|
111
117
|
};
|
package/dist/splice-project.js
CHANGED
|
@@ -7,6 +7,8 @@ import { createContractCaller, ContractValidationError, } from "./contract-calle
|
|
|
7
7
|
import { decode } from "./execution.js";
|
|
8
8
|
import { loadReplayFixture, parseSpliceRecording, replaySpliceRecording, } from "./splice-recording.js";
|
|
9
9
|
import { explainSpliceError } from "./splice-diagnostics.js";
|
|
10
|
+
import { catalogFixture, catalogSelection } from "./catalog-setup.js";
|
|
11
|
+
import { parseSpliceSuite, suiteFromRecording } from "./testing.js";
|
|
10
12
|
import { copyJson, parseWorkflowJson, jsonObject, JSON_LIMIT, } from "./workflow-json.js";
|
|
11
13
|
const serialize = (value) => {
|
|
12
14
|
const text = JSON.stringify(copyJson(value), null, 2) + "\n";
|
|
@@ -25,7 +27,24 @@ export async function createSpliceProjectFiles(options = {}) {
|
|
|
25
27
|
hasContext: true,
|
|
26
28
|
restorationRequiredForRecording: false,
|
|
27
29
|
};
|
|
28
|
-
|
|
30
|
+
let mapped;
|
|
31
|
+
if (options.catalogs !== undefined) {
|
|
32
|
+
if (options.recording !== undefined || options.restorations !== undefined)
|
|
33
|
+
throw new Error("Choose either a recording or catalogs.");
|
|
34
|
+
const config = options.catalogs;
|
|
35
|
+
source = createContractFromCatalog({ name: config.source.server }, config.sourceCatalog, { tools: [config.source.tool] });
|
|
36
|
+
target = createContractFromCatalog({ name: config.target.server }, config.targetCatalog, { tools: [config.target.tool] });
|
|
37
|
+
plan = parseSpliceSpec({ format: "toolsplice-splice", formatVersion: 1, ...catalogSelection(config),
|
|
38
|
+
target: config.target, bindings: config.bindings });
|
|
39
|
+
fixture = catalogFixture(config.fixture, config.fixtureFormat);
|
|
40
|
+
mapped = await prepareSplice(plan, source, target).mapOutput(fixture);
|
|
41
|
+
input = config.input;
|
|
42
|
+
manifest.origin = "catalogs";
|
|
43
|
+
manifest.hasContext = false;
|
|
44
|
+
if (input === undefined)
|
|
45
|
+
manifest.hasInput = false;
|
|
46
|
+
}
|
|
47
|
+
else if (options.recording !== undefined) {
|
|
29
48
|
const loaded = loadReplayFixture(options.recording, {
|
|
30
49
|
restorations: options.restorations,
|
|
31
50
|
});
|
|
@@ -124,7 +143,7 @@ export async function createSpliceProjectFiles(options = {}) {
|
|
|
124
143
|
"plan.json": serialize(plan),
|
|
125
144
|
"source.json": serialize(source),
|
|
126
145
|
"target.json": serialize(target),
|
|
127
|
-
"input.json": serialize(input),
|
|
146
|
+
...(manifest.hasInput === false ? {} : { "input.json": serialize(input) }),
|
|
128
147
|
"fixture.json": serialize(fixture),
|
|
129
148
|
"adapter.ts": emitSpliceModule(plan, source, target),
|
|
130
149
|
};
|
|
@@ -132,9 +151,37 @@ export async function createSpliceProjectFiles(options = {}) {
|
|
|
132
151
|
files["context.json"] = serialize(context);
|
|
133
152
|
if (originalRecording)
|
|
134
153
|
files["recording.json"] = serialize(originalRecording);
|
|
154
|
+
const suite = mapped !== undefined ? {
|
|
155
|
+
format: "toolsplice-suite", formatVersion: 1, allowReview: true,
|
|
156
|
+
cases: [{ name: "catalog sample maps to the reviewed arguments", mappingOnly: true,
|
|
157
|
+
input: {}, sourceResult: { structuredContent: fixture },
|
|
158
|
+
expect: { status: "succeeded", targetCalls: 0, arguments: mapped } }],
|
|
159
|
+
} : originalRecording ? suiteFromRecording(originalRecording, { restorations: options.restorations }) : {
|
|
160
|
+
format: "toolsplice-suite", formatVersion: 1, allowReview: true,
|
|
161
|
+
cases: [
|
|
162
|
+
{ name: "saves the complete document", input, context, sourceResult: { structuredContent: fixture },
|
|
163
|
+
targetResults: [{ structuredContent: { saved: true } }], expect: { status: "succeeded", targetCalls: 1,
|
|
164
|
+
arguments: [{ path: "saved.md", content: fixture.markdown }], results: [{ saved: true }] } },
|
|
165
|
+
{ name: "invalid source prevents writes", input, context, sourceResult: { structuredContent: { markdown: null } },
|
|
166
|
+
expect: { status: "failed", stage: "source", code: "validation-type", targetCalls: 0 } },
|
|
167
|
+
],
|
|
168
|
+
};
|
|
169
|
+
if (mapped !== undefined)
|
|
170
|
+
parseSpliceSuite({ ...suite, plan, sourceContract: source, targetContract: target });
|
|
171
|
+
const cases = suite.cases.map(c => {
|
|
172
|
+
if (mapped === undefined)
|
|
173
|
+
return c;
|
|
174
|
+
const { sourceResult, ...rest } = c;
|
|
175
|
+
return { ...rest, sourceFixture: "fixture.json" };
|
|
176
|
+
});
|
|
177
|
+
files["tests.json"] = serialize({ ...suite, cases, plan: "plan.json", sourceContract: "source.json", targetContract: "target.json" });
|
|
135
178
|
files["README.md"] =
|
|
136
|
-
`# Toolsplice handoff project\n\nOrigin: ${manifest.origin}. This folder contains private application artifacts; review before sharing.\n\nCheck the saved source input/output, context and every mapped destination argument offline:\n\n\`\`\`sh\ntoolsplice project . --allow-review --json\n\`\`\`\n\nThe command calls no tools and writes no documents. --allow-review accepts the offline review exit status; it does not disable runtime guards.\n\n${manifest.origin === "synthetic" ? "The catalogs, input and response are synthetic. Connect your own tools, export their contracts and explicitly update the mapping. Toolsplice does not guess ID semantics or establish provider clients.\n" : "The contracts, mapping and source fixture come from the successful saved recording. No provider was contacted to create this folder.\n"}\n\nThe generated adapter.ts uses the full toolsplice package. Call createSplice with your application-owned callers, then pass input and optional context. Review its report and explicitly set allowReview when required. The adapter can perform real destination effects only when your application invokes it with live callers.\n\nFor a smaller dependency tree, use toolsplice-core in your application and regenerate with its emitSpliceModule function; its default runtime import is toolsplice-core. Install toolsplice or toolsplice-core from npm, or the appropriate local tarball when testing this checkout.\n\n${originalRecording ? `Replay all captured responses: \`toolsplice replay recording.json --json\`. ${manifest.restorationRequiredForRecording ? "The retained recording is still redacted and needs your private --restorations file; restored input/context/fixture files in this private project may contain confidential values." : ""}\nCheck a candidate contract: \`toolsplice replay recording.json --target-contract new-target.json --json\`.\n` : ""}`;
|
|
179
|
+
`# Toolsplice handoff project\n\nOrigin: ${manifest.origin}. This folder contains private application artifacts; review before sharing.\n\nCheck the saved source input/output, context and every mapped destination argument offline:\n\n\`\`\`sh\ntoolsplice project . --allow-review --json\n\`\`\`\n\nThe command calls no tools and writes no documents. --allow-review accepts the offline review exit status; it does not disable runtime guards.\n\n${manifest.origin === "synthetic" ? "The catalogs, input and response are synthetic. Connect your own tools, export their contracts and explicitly update the mapping. Toolsplice does not guess ID semantics or establish provider clients.\n" : manifest.origin === "catalogs" ? "The mapping comes from your explicit bindings. Review the generated expected arguments in tests.json before committing the baseline. The mapping test checks the saved sample without calling either tool." : "The contracts, mapping and source fixture come from the successful saved recording. No provider was contacted to create this folder.\n"}\n\nThe generated adapter.ts uses the full toolsplice package. Call createSplice with your application-owned callers, then pass input and optional context. Review its report and explicitly set allowReview when required. The adapter can perform real destination effects only when your application invokes it with live callers.\n\nFor a smaller dependency tree, use toolsplice-core in your application and regenerate with its emitSpliceModule function; its default runtime import is toolsplice-core. Install toolsplice or toolsplice-core from npm, or the appropriate local tarball when testing this checkout.\n\n${originalRecording ? `Replay all captured responses: \`toolsplice replay recording.json --json\`. ${manifest.restorationRequiredForRecording ? "The retained recording is still redacted and needs your private --restorations file; restored input/context/fixture files in this private project may contain confidential values." : ""}\nCheck a candidate contract: \`toolsplice replay recording.json --target-contract new-target.json --json\`.\n` : ""}`;
|
|
137
180
|
files["README.md"] += `
|
|
181
|
+
Run the regression suite with \`toolsplice test .\` (or \`npx toolsplice test .\` after a local npm install).
|
|
182
|
+
The suite loads plan.json, source.json and target.json relative to tests.json, so edits are tested immediately.
|
|
183
|
+
Use \`--junit results.xml\` for a new CI report file. Cases use mock callers and make zero live calls.
|
|
184
|
+
|
|
138
185
|
The project check also verifies that adapter.ts matches the saved plan/contracts and current generator. After editing those artifacts, generate into a new file:
|
|
139
186
|
|
|
140
187
|
\`\`\`sh
|
|
@@ -153,7 +200,8 @@ function projectManifest(input) {
|
|
|
153
200
|
if (!jsonObject(v) ||
|
|
154
201
|
v.format !== "toolsplice-project" ||
|
|
155
202
|
v.formatVersion !== 1 ||
|
|
156
|
-
|
|
203
|
+
(Object.hasOwn(v, "hasInput") && (v.hasInput !== false || v.origin !== "catalogs")) ||
|
|
204
|
+
!["synthetic", "recording", "catalogs"].includes(String(v.origin)) ||
|
|
157
205
|
!["decoded", "mcp"].includes(String(v.fixtureFormat)) ||
|
|
158
206
|
typeof v.hasContext !== "boolean" ||
|
|
159
207
|
typeof v.restorationRequiredForRecording !== "boolean" ||
|
|
@@ -163,6 +211,7 @@ function projectManifest(input) {
|
|
|
163
211
|
"origin",
|
|
164
212
|
"fixtureFormat",
|
|
165
213
|
"hasContext",
|
|
214
|
+
"hasInput",
|
|
166
215
|
"restorationRequiredForRecording",
|
|
167
216
|
].includes(k)))
|
|
168
217
|
throw new Error("Invalid or unsupported Toolsplice project manifest.");
|
|
@@ -186,21 +235,23 @@ export async function checkSpliceProjectFiles(files) {
|
|
|
186
235
|
message: "Generated adapter differs from the current plan/contracts/generator. Generate a new file and review it before replacing the old adapter.",
|
|
187
236
|
},
|
|
188
237
|
]);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
238
|
+
if (manifest.hasInput !== false) {
|
|
239
|
+
const input = parseWorkflowJson(files["input.json"]);
|
|
240
|
+
if (!jsonObject(input))
|
|
241
|
+
throw new SpliceError("source", 0, undefined, [
|
|
242
|
+
{
|
|
243
|
+
severity: "error",
|
|
244
|
+
code: "source-input-object",
|
|
245
|
+
path: "/input",
|
|
246
|
+
message: "Source input must be an object.",
|
|
247
|
+
},
|
|
248
|
+
]);
|
|
249
|
+
try {
|
|
250
|
+
await createContractCaller(async () => ({ content: [] }), selectContractTools(source, [plan.source.tool]), { outputs: false })({ name: plan.source.tool, arguments: input });
|
|
251
|
+
}
|
|
252
|
+
catch (e) {
|
|
253
|
+
throw new SpliceError("source", 0, e instanceof ContractValidationError ? e : undefined);
|
|
254
|
+
}
|
|
204
255
|
}
|
|
205
256
|
let fixture = parseWorkflowJson(files["fixture.json"]);
|
|
206
257
|
if (manifest.fixtureFormat === "mcp") {
|
|
@@ -240,6 +291,7 @@ export async function checkSpliceProjectFiles(files) {
|
|
|
240
291
|
? [...prepared.report.issues, ...failure.issues]
|
|
241
292
|
: prepared.report.issues,
|
|
242
293
|
origin: manifest.origin,
|
|
294
|
+
...(manifest.origin === "catalogs" ? { hasSourceInput: manifest.hasInput !== false } : {}),
|
|
243
295
|
adapter: {
|
|
244
296
|
status: adapterCurrent === undefined
|
|
245
297
|
? "not-checked"
|
|
@@ -287,7 +339,7 @@ export async function checkSpliceProject(directory) {
|
|
|
287
339
|
"plan.json",
|
|
288
340
|
"source.json",
|
|
289
341
|
"target.json",
|
|
290
|
-
"input.json",
|
|
342
|
+
...(manifest.hasInput === false ? [] : ["input.json"]),
|
|
291
343
|
"fixture.json",
|
|
292
344
|
"adapter.ts",
|
|
293
345
|
...(manifest.hasContext ? ["context.json"] : []),
|
|
@@ -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 }
|
package/dist/splice.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ContractSchema, type ContractSnapshot } from "./contracts.js";
|
|
2
2
|
import { type BindingCallOptions, type ToolCaller } from "./execution.js";
|
|
3
|
+
import { type SpliceRule } from "./rules.js";
|
|
4
|
+
import { type McpToolUi } from "./mcp-apps.js";
|
|
3
5
|
export interface SpliceEndpoint {
|
|
4
6
|
server: string;
|
|
5
7
|
tool: string;
|
|
@@ -26,19 +28,44 @@ export interface SpliceSpec {
|
|
|
26
28
|
path: string;
|
|
27
29
|
equals: unknown;
|
|
28
30
|
}[];
|
|
31
|
+
/** Select exactly one candidate by a scalar key after source value validation. */
|
|
32
|
+
matchOne?: {
|
|
33
|
+
path: string;
|
|
34
|
+
} & ({
|
|
35
|
+
equals: string | number | boolean | null;
|
|
36
|
+
} | {
|
|
37
|
+
fromContext: string;
|
|
38
|
+
});
|
|
29
39
|
};
|
|
30
40
|
target: SpliceEndpoint & {
|
|
31
41
|
/** Reject duplicate destination-key tuples within this batch, before any target call. */
|
|
32
42
|
uniqueBy?: string[];
|
|
43
|
+
/** Return this field from each validated destination response. Empty selects the full result. */
|
|
44
|
+
resultPath?: string;
|
|
45
|
+
/** Build an object from named JSON pointers into the validated destination response. */
|
|
46
|
+
resultFields?: Record<string, string>;
|
|
33
47
|
};
|
|
34
48
|
forEach?: boolean;
|
|
35
49
|
maxItems?: number;
|
|
36
50
|
/** UTF-8 JSON bytes of the final result array; default 5 MiB, maximum 64 MiB. */
|
|
37
51
|
maxResultBytes?: number;
|
|
38
52
|
bindings: SpliceBinding[];
|
|
53
|
+
/** Per-row application rules checked before any destination call. */
|
|
54
|
+
rules?: SpliceRule[];
|
|
39
55
|
/** Application-supplied values, validated before any source call. */
|
|
40
56
|
contextSchema?: Record<string, unknown>;
|
|
41
57
|
}
|
|
58
|
+
export interface SpliceToolOptions {
|
|
59
|
+
/** Enable ordered read waves with an application-owned concurrency bound. */
|
|
60
|
+
readConcurrency?: number;
|
|
61
|
+
assumeReadOnly?: boolean;
|
|
62
|
+
/** Link an explicitly registered MCP Apps resource to the outer tool. */
|
|
63
|
+
ui?: McpToolUi;
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
source: ToolCaller;
|
|
67
|
+
target: ToolCaller;
|
|
68
|
+
}
|
|
42
69
|
export interface SpliceIssue {
|
|
43
70
|
severity: "error" | "warning";
|
|
44
71
|
code: string;
|
|
@@ -66,18 +93,88 @@ export interface SpliceRunOptions extends BindingCallOptions, SpliceMappingOptio
|
|
|
66
93
|
/** Explicitly allow uncertain static checks; runtime validation still applies to every row. */
|
|
67
94
|
allowReview?: boolean;
|
|
68
95
|
}
|
|
96
|
+
export interface SpliceReadOptions extends SpliceRunOptions {
|
|
97
|
+
/** Maximum independent destination calls in each ordered wave. Default 4. */
|
|
98
|
+
concurrency?: number;
|
|
99
|
+
/** Application confirmation for read-only tools that omit the MCP readOnlyHint. */
|
|
100
|
+
assumeReadOnly?: boolean;
|
|
101
|
+
}
|
|
69
102
|
export declare class SpliceError extends Error {
|
|
70
103
|
readonly stage: "preflight" | "context" | "source" | "mapping" | "target";
|
|
71
104
|
readonly completedTargets: number;
|
|
105
|
+
/** Rows submitted in read waves, possibly beyond the successful in-order prefix. */
|
|
106
|
+
scheduledTargets?: number;
|
|
72
107
|
readonly issues: SpliceIssue[];
|
|
73
108
|
constructor(stage: "preflight" | "context" | "source" | "mapping" | "target", completedTargets: number, cause?: unknown, details?: SpliceIssue[]);
|
|
74
109
|
}
|
|
110
|
+
export declare function readSplicePath(value: unknown, pointer: string): {
|
|
111
|
+
found: boolean;
|
|
112
|
+
value: unknown;
|
|
113
|
+
};
|
|
75
114
|
export declare function parseSpliceSpec(source: string | unknown): SpliceSpec;
|
|
76
115
|
export declare function preflightSplice(plan: SpliceSpec, source: ContractSnapshot, target: ContractSnapshot): SpliceReport;
|
|
77
116
|
export declare function prepareSplice(plan: SpliceSpec, source: ContractSnapshot, target: ContractSnapshot): {
|
|
78
117
|
report: SpliceReport;
|
|
79
118
|
mapOutput: (output: unknown, options?: SpliceMappingOptions) => Promise<Record<string, unknown>[]>;
|
|
80
|
-
run: (
|
|
119
|
+
run: (source: ToolCaller, target: ToolCaller, args: unknown, options?: SpliceRunOptions) => Promise<unknown[]>;
|
|
120
|
+
runReads: (source: ToolCaller, target: ToolCaller, args: unknown, options?: SpliceReadOptions) => Promise<unknown[]>;
|
|
121
|
+
asTool: ({ name, description, source, target, ui, readConcurrency: requested, assumeReadOnly }: SpliceToolOptions) => {
|
|
122
|
+
definition: {
|
|
123
|
+
name: string;
|
|
124
|
+
description?: string | undefined;
|
|
125
|
+
_meta?: {
|
|
126
|
+
ui: McpToolUi;
|
|
127
|
+
} | undefined;
|
|
128
|
+
inputSchema: {
|
|
129
|
+
type: "object";
|
|
130
|
+
};
|
|
131
|
+
outputSchema: {
|
|
132
|
+
type: "object";
|
|
133
|
+
properties: {
|
|
134
|
+
results: {
|
|
135
|
+
type: string;
|
|
136
|
+
items: {
|
|
137
|
+
type: string;
|
|
138
|
+
properties: {
|
|
139
|
+
[k: string]: {};
|
|
140
|
+
};
|
|
141
|
+
required: string[];
|
|
142
|
+
additionalProperties: boolean;
|
|
143
|
+
} | {
|
|
144
|
+
type?: undefined;
|
|
145
|
+
properties?: undefined;
|
|
146
|
+
required?: undefined;
|
|
147
|
+
additionalProperties?: undefined;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
required: string[];
|
|
152
|
+
additionalProperties: boolean;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
call: (args: Record<string, unknown>, options?: SpliceRunOptions) => Promise<{
|
|
156
|
+
resultType: "complete";
|
|
157
|
+
structuredContent: {
|
|
158
|
+
results: unknown[];
|
|
159
|
+
};
|
|
160
|
+
content: {
|
|
161
|
+
type: "text";
|
|
162
|
+
text: string;
|
|
163
|
+
}[];
|
|
164
|
+
isError?: undefined;
|
|
165
|
+
} | {
|
|
166
|
+
structuredContent?: undefined;
|
|
167
|
+
resultType: "complete";
|
|
168
|
+
isError: true;
|
|
169
|
+
content: {
|
|
170
|
+
type: "text";
|
|
171
|
+
text: string;
|
|
172
|
+
}[];
|
|
173
|
+
}>;
|
|
174
|
+
execute: (args: Record<string, unknown>, options?: SpliceRunOptions) => Promise<{
|
|
175
|
+
results: unknown[];
|
|
176
|
+
}>;
|
|
177
|
+
};
|
|
81
178
|
};
|
|
82
179
|
export declare function emitSpliceModule(plan: SpliceSpec, source: ContractSnapshot, target: ContractSnapshot, options?: {
|
|
83
180
|
runtimeImport?: string;
|