toolsplice 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +104 -2
- 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.d.ts +2 -0
- package/dist/cli.js +1454 -0
- package/dist/coalesce-reads.d.ts +6 -0
- package/dist/coalesce-reads.js +33 -0
- package/dist/codegen.d.ts +44 -0
- package/dist/codegen.js +479 -0
- package/dist/contract-caller.d.ts +23 -0
- package/dist/contract-caller.js +326 -0
- package/dist/contract-corrections.d.ts +35 -0
- package/dist/contract-corrections.js +159 -0
- package/dist/contract-schema.d.ts +7 -0
- package/dist/contract-schema.js +156 -0
- package/dist/contracts.d.ts +72 -0
- package/dist/contracts.js +370 -0
- package/dist/core.d.ts +44 -0
- package/dist/core.js +43 -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/doctor.d.ts +22 -0
- package/dist/doctor.js +91 -0
- package/dist/drift.d.ts +23 -0
- package/dist/drift.js +111 -0
- package/dist/execution.d.ts +38 -0
- package/dist/execution.js +66 -0
- package/dist/extract.d.ts +34 -0
- package/dist/extract.js +73 -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 +51 -0
- package/dist/index.js +47 -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/ordered-transport.d.ts +12 -0
- package/dist/ordered-transport.js +106 -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 +3 -0
- package/dist/pattern.js +54 -0
- package/dist/postgres.d.ts +41 -0
- package/dist/postgres.js +264 -0
- package/dist/probe.d.ts +29 -0
- package/dist/probe.js +121 -0
- package/dist/proxy.d.ts +40 -0
- package/dist/proxy.js +436 -0
- 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/runtime.d.ts +6 -0
- package/dist/runtime.js +26 -0
- package/dist/schema.d.ts +17 -0
- package/dist/schema.js +299 -0
- package/dist/search-fetch.d.ts +50 -0
- package/dist/search-fetch.js +264 -0
- package/dist/shape.d.ts +91 -0
- package/dist/shape.js +499 -0
- package/dist/skill-files.d.ts +9 -0
- package/dist/skill-files.js +49 -0
- package/dist/splice-diagnostics.d.ts +44 -0
- package/dist/splice-diagnostics.js +88 -0
- package/dist/splice-measure.d.ts +33 -0
- package/dist/splice-measure.js +55 -0
- package/dist/splice-project.d.ts +125 -0
- package/dist/splice-project.js +348 -0
- package/dist/splice-recording.d.ts +132 -0
- package/dist/splice-recording.js +481 -0
- package/dist/splice.d.ts +181 -0
- package/dist/splice.js +1263 -0
- 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/storage.d.ts +17 -0
- package/dist/storage.js +1 -0
- package/dist/store.d.ts +151 -0
- package/dist/store.js +735 -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.d.ts +49 -0
- package/dist/v2.js +413 -0
- package/dist/validate-output.d.ts +3 -0
- package/dist/validate-output.js +73 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/workflow-json.d.ts +8 -0
- package/dist/workflow-json.js +74 -0
- 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 +173 -0
- package/docs/PYTHON-REFERENCE.md +348 -0
- package/docs/PYTHON.md +120 -0
- package/docs/RECORDING-AND-CORRECTIONS.md +205 -0
- 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 +139 -4
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type SpliceRecording } from "./splice-recording.js";
|
|
2
|
+
import { type CatalogSetup } from "./catalog-setup.js";
|
|
3
|
+
export interface SpliceProjectOptions {
|
|
4
|
+
catalogs?: CatalogSetup;
|
|
5
|
+
recording?: SpliceRecording | string;
|
|
6
|
+
restorations?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createSpliceProjectFiles(options?: SpliceProjectOptions): Promise<{
|
|
9
|
+
files: Record<string, string>;
|
|
10
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
11
|
+
check: {
|
|
12
|
+
source: import("./splice.js").SpliceEndpoint;
|
|
13
|
+
target: import("./splice.js").SpliceEndpoint;
|
|
14
|
+
maxTargetCalls: number;
|
|
15
|
+
maxResultBytes: number;
|
|
16
|
+
fingerprints: {
|
|
17
|
+
source: string;
|
|
18
|
+
target: string;
|
|
19
|
+
plan: string;
|
|
20
|
+
};
|
|
21
|
+
note: string;
|
|
22
|
+
preflightStatus: "blocked" | "ready" | "review";
|
|
23
|
+
status: "blocked" | "ready" | "review";
|
|
24
|
+
issues: import("./splice.js").SpliceIssue[];
|
|
25
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
26
|
+
hasSourceInput?: boolean | undefined;
|
|
27
|
+
adapter: {
|
|
28
|
+
status: string;
|
|
29
|
+
};
|
|
30
|
+
networkCalls: number;
|
|
31
|
+
toolCalls: number;
|
|
32
|
+
explanation?: import("./splice-diagnostics.js").SpliceExplanation | undefined;
|
|
33
|
+
mappingSummary?: {
|
|
34
|
+
rows: number;
|
|
35
|
+
argumentBytes: number;
|
|
36
|
+
} | undefined;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
/** Checks fixed artifact filenames only; returns counts/paths, never mapped values. */
|
|
40
|
+
export declare function checkSpliceProjectFiles(files: Record<string, string>): Promise<{
|
|
41
|
+
source: import("./splice.js").SpliceEndpoint;
|
|
42
|
+
target: import("./splice.js").SpliceEndpoint;
|
|
43
|
+
maxTargetCalls: number;
|
|
44
|
+
maxResultBytes: number;
|
|
45
|
+
fingerprints: {
|
|
46
|
+
source: string;
|
|
47
|
+
target: string;
|
|
48
|
+
plan: string;
|
|
49
|
+
};
|
|
50
|
+
note: string;
|
|
51
|
+
preflightStatus: "blocked" | "ready" | "review";
|
|
52
|
+
status: "blocked" | "ready" | "review";
|
|
53
|
+
issues: import("./splice.js").SpliceIssue[];
|
|
54
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
55
|
+
hasSourceInput?: boolean | undefined;
|
|
56
|
+
adapter: {
|
|
57
|
+
status: string;
|
|
58
|
+
};
|
|
59
|
+
networkCalls: number;
|
|
60
|
+
toolCalls: number;
|
|
61
|
+
explanation?: import("./splice-diagnostics.js").SpliceExplanation | undefined;
|
|
62
|
+
mappingSummary?: {
|
|
63
|
+
rows: number;
|
|
64
|
+
argumentBytes: number;
|
|
65
|
+
} | undefined;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function initializeSpliceProject(directory: string, options?: SpliceProjectOptions): Promise<{
|
|
68
|
+
directory: string;
|
|
69
|
+
files: string[];
|
|
70
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
71
|
+
check: {
|
|
72
|
+
source: import("./splice.js").SpliceEndpoint;
|
|
73
|
+
target: import("./splice.js").SpliceEndpoint;
|
|
74
|
+
maxTargetCalls: number;
|
|
75
|
+
maxResultBytes: number;
|
|
76
|
+
fingerprints: {
|
|
77
|
+
source: string;
|
|
78
|
+
target: string;
|
|
79
|
+
plan: string;
|
|
80
|
+
};
|
|
81
|
+
note: string;
|
|
82
|
+
preflightStatus: "blocked" | "ready" | "review";
|
|
83
|
+
status: "blocked" | "ready" | "review";
|
|
84
|
+
issues: import("./splice.js").SpliceIssue[];
|
|
85
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
86
|
+
hasSourceInput?: boolean | undefined;
|
|
87
|
+
adapter: {
|
|
88
|
+
status: string;
|
|
89
|
+
};
|
|
90
|
+
networkCalls: number;
|
|
91
|
+
toolCalls: number;
|
|
92
|
+
explanation?: import("./splice-diagnostics.js").SpliceExplanation | undefined;
|
|
93
|
+
mappingSummary?: {
|
|
94
|
+
rows: number;
|
|
95
|
+
argumentBytes: number;
|
|
96
|
+
} | undefined;
|
|
97
|
+
};
|
|
98
|
+
}>;
|
|
99
|
+
export declare function checkSpliceProject(directory: string): Promise<{
|
|
100
|
+
source: import("./splice.js").SpliceEndpoint;
|
|
101
|
+
target: import("./splice.js").SpliceEndpoint;
|
|
102
|
+
maxTargetCalls: number;
|
|
103
|
+
maxResultBytes: number;
|
|
104
|
+
fingerprints: {
|
|
105
|
+
source: string;
|
|
106
|
+
target: string;
|
|
107
|
+
plan: string;
|
|
108
|
+
};
|
|
109
|
+
note: string;
|
|
110
|
+
preflightStatus: "blocked" | "ready" | "review";
|
|
111
|
+
status: "blocked" | "ready" | "review";
|
|
112
|
+
issues: import("./splice.js").SpliceIssue[];
|
|
113
|
+
origin: "catalogs" | "recording" | "synthetic";
|
|
114
|
+
hasSourceInput?: boolean | undefined;
|
|
115
|
+
adapter: {
|
|
116
|
+
status: string;
|
|
117
|
+
};
|
|
118
|
+
networkCalls: number;
|
|
119
|
+
toolCalls: number;
|
|
120
|
+
explanation?: import("./splice-diagnostics.js").SpliceExplanation | undefined;
|
|
121
|
+
mappingSummary?: {
|
|
122
|
+
rows: number;
|
|
123
|
+
argumentBytes: number;
|
|
124
|
+
} | undefined;
|
|
125
|
+
}>;
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// Fixed-file, offline project scaffolding. No subprocesses, credential discovery or tool connections.
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { createContractFromCatalog, parseContractSnapshot, selectContractTools, } from "./contracts.js";
|
|
5
|
+
import { prepareSplice, parseSpliceSpec, emitSpliceModule, SpliceError, } from "./splice.js";
|
|
6
|
+
import { createContractCaller, ContractValidationError, } from "./contract-caller.js";
|
|
7
|
+
import { decode } from "./execution.js";
|
|
8
|
+
import { loadReplayFixture, parseSpliceRecording, replaySpliceRecording, } from "./splice-recording.js";
|
|
9
|
+
import { explainSpliceError } from "./splice-diagnostics.js";
|
|
10
|
+
import { catalogFixture, catalogSelection } from "./catalog-setup.js";
|
|
11
|
+
import { parseSpliceSuite, suiteFromRecording } from "./testing.js";
|
|
12
|
+
import { copyJson, parseWorkflowJson, jsonObject, JSON_LIMIT, } from "./workflow-json.js";
|
|
13
|
+
const serialize = (value) => {
|
|
14
|
+
const text = JSON.stringify(copyJson(value), null, 2) + "\n";
|
|
15
|
+
if (Buffer.byteLength(text) > JSON_LIMIT)
|
|
16
|
+
throw new Error("Serialized project artifact exceeds 5 MiB.");
|
|
17
|
+
return text;
|
|
18
|
+
};
|
|
19
|
+
export async function createSpliceProjectFiles(options = {}) {
|
|
20
|
+
let plan, source, target, input, fixture, context;
|
|
21
|
+
let originalRecording;
|
|
22
|
+
const manifest = {
|
|
23
|
+
format: "toolsplice-project",
|
|
24
|
+
formatVersion: 1,
|
|
25
|
+
origin: "synthetic",
|
|
26
|
+
fixtureFormat: "decoded",
|
|
27
|
+
hasContext: true,
|
|
28
|
+
restorationRequiredForRecording: false,
|
|
29
|
+
};
|
|
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) {
|
|
48
|
+
const loaded = loadReplayFixture(options.recording, {
|
|
49
|
+
restorations: options.restorations,
|
|
50
|
+
});
|
|
51
|
+
const replay = await replaySpliceRecording(options.recording, {
|
|
52
|
+
restorations: options.restorations,
|
|
53
|
+
});
|
|
54
|
+
if (!replay.matched || replay.outcome.status !== "succeeded")
|
|
55
|
+
throw new Error("A starter needs a successful recording that matches offline replay.");
|
|
56
|
+
const call = loaded.recording.calls.find((c) => c.side === "source");
|
|
57
|
+
if (!call || call.outcome !== "returned" || !Object.hasOwn(call, "result"))
|
|
58
|
+
throw new Error("Recording has no usable source response.");
|
|
59
|
+
plan = loaded.spec;
|
|
60
|
+
source = loaded.source;
|
|
61
|
+
target = loaded.target;
|
|
62
|
+
input = loaded.recording.input;
|
|
63
|
+
fixture = call.result;
|
|
64
|
+
context = loaded.recording.context;
|
|
65
|
+
originalRecording = parseSpliceRecording(options.recording);
|
|
66
|
+
manifest.origin = "recording";
|
|
67
|
+
manifest.fixtureFormat = "mcp";
|
|
68
|
+
manifest.hasContext = Object.hasOwn(loaded.recording, "context");
|
|
69
|
+
manifest.restorationRequiredForRecording = loaded.restored;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (options.restorations !== undefined)
|
|
73
|
+
throw new Error("Restorations require a recording.");
|
|
74
|
+
source = createContractFromCatalog({ name: "documents" }, {
|
|
75
|
+
tools: [
|
|
76
|
+
{
|
|
77
|
+
name: "read_document",
|
|
78
|
+
inputSchema: {
|
|
79
|
+
type: "object",
|
|
80
|
+
properties: { url: { type: "string" } },
|
|
81
|
+
required: ["url"],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
},
|
|
84
|
+
outputSchema: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: { markdown: { type: "string" } },
|
|
87
|
+
required: ["markdown"],
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
target = createContractFromCatalog({ name: "artifacts" }, {
|
|
94
|
+
tools: [
|
|
95
|
+
{
|
|
96
|
+
name: "save_document",
|
|
97
|
+
inputSchema: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
path: { type: "string", minLength: 1 },
|
|
101
|
+
content: { type: "string" },
|
|
102
|
+
},
|
|
103
|
+
required: ["path", "content"],
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
},
|
|
106
|
+
outputSchema: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: { saved: { type: "boolean" } },
|
|
109
|
+
required: ["saved"],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
plan = {
|
|
115
|
+
format: "toolsplice-splice",
|
|
116
|
+
formatVersion: 1,
|
|
117
|
+
source: {
|
|
118
|
+
server: "documents",
|
|
119
|
+
tool: "read_document",
|
|
120
|
+
path: "/markdown",
|
|
121
|
+
valueSchema: { type: "string", minLength: 1 },
|
|
122
|
+
},
|
|
123
|
+
target: { server: "artifacts", tool: "save_document" },
|
|
124
|
+
contextSchema: {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: { path: { type: "string", minLength: 1 } },
|
|
127
|
+
required: ["path"],
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
},
|
|
130
|
+
bindings: [
|
|
131
|
+
{ to: "/content", from: "" },
|
|
132
|
+
{ to: "/path", fromContext: "/path" },
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
input = { url: "https://docs.example.com/intro" };
|
|
136
|
+
context = { path: "saved.md" };
|
|
137
|
+
fixture = {
|
|
138
|
+
markdown: "# Synthetic document\n\nThis is an offline starter fixture. No URL is fetched and no document is written.\n",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const files = {
|
|
142
|
+
"toolsplice.project.json": serialize(manifest),
|
|
143
|
+
"plan.json": serialize(plan),
|
|
144
|
+
"source.json": serialize(source),
|
|
145
|
+
"target.json": serialize(target),
|
|
146
|
+
...(manifest.hasInput === false ? {} : { "input.json": serialize(input) }),
|
|
147
|
+
"fixture.json": serialize(fixture),
|
|
148
|
+
"adapter.ts": emitSpliceModule(plan, source, target),
|
|
149
|
+
};
|
|
150
|
+
if (manifest.hasContext)
|
|
151
|
+
files["context.json"] = serialize(context);
|
|
152
|
+
if (originalRecording)
|
|
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" });
|
|
178
|
+
files["README.md"] =
|
|
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` : ""}`;
|
|
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
|
+
|
|
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:
|
|
186
|
+
|
|
187
|
+
\`\`\`sh
|
|
188
|
+
toolsplice splice plan.json --source-contract source.json --target-contract target.json --fixture fixture.json --fixture-format ${manifest.fixtureFormat}${manifest.hasContext ? " --context context.json" : ""} --allow-review --summary --out adapter.next.ts --json
|
|
189
|
+
\`\`\`
|
|
190
|
+
|
|
191
|
+
Review adapter.next.ts before replacing adapter.ts. Existing files are never overwritten by generation.
|
|
192
|
+
`;
|
|
193
|
+
const check = await checkSpliceProjectFiles(files);
|
|
194
|
+
if (check.status === "blocked")
|
|
195
|
+
throw new Error("Starter artifacts do not pass offline validation.");
|
|
196
|
+
return { files, origin: manifest.origin, check };
|
|
197
|
+
}
|
|
198
|
+
function projectManifest(input) {
|
|
199
|
+
const v = parseWorkflowJson(input);
|
|
200
|
+
if (!jsonObject(v) ||
|
|
201
|
+
v.format !== "toolsplice-project" ||
|
|
202
|
+
v.formatVersion !== 1 ||
|
|
203
|
+
(Object.hasOwn(v, "hasInput") && (v.hasInput !== false || v.origin !== "catalogs")) ||
|
|
204
|
+
!["synthetic", "recording", "catalogs"].includes(String(v.origin)) ||
|
|
205
|
+
!["decoded", "mcp"].includes(String(v.fixtureFormat)) ||
|
|
206
|
+
typeof v.hasContext !== "boolean" ||
|
|
207
|
+
typeof v.restorationRequiredForRecording !== "boolean" ||
|
|
208
|
+
Object.keys(v).some((k) => ![
|
|
209
|
+
"format",
|
|
210
|
+
"formatVersion",
|
|
211
|
+
"origin",
|
|
212
|
+
"fixtureFormat",
|
|
213
|
+
"hasContext",
|
|
214
|
+
"hasInput",
|
|
215
|
+
"restorationRequiredForRecording",
|
|
216
|
+
].includes(k)))
|
|
217
|
+
throw new Error("Invalid or unsupported Toolsplice project manifest.");
|
|
218
|
+
return v;
|
|
219
|
+
}
|
|
220
|
+
/** Checks fixed artifact filenames only; returns counts/paths, never mapped values. */
|
|
221
|
+
export async function checkSpliceProjectFiles(files) {
|
|
222
|
+
const manifest = projectManifest(files["toolsplice.project.json"]), plan = parseSpliceSpec(files["plan.json"]), source = parseContractSnapshot(files["source.json"]), target = parseContractSnapshot(files["target.json"]), prepared = prepareSplice(plan, source, target);
|
|
223
|
+
let failure, rows;
|
|
224
|
+
const adapterCurrent = prepared.report.status === "blocked"
|
|
225
|
+
? undefined
|
|
226
|
+
: files["adapter.ts"] === emitSpliceModule(plan, source, target);
|
|
227
|
+
if (prepared.report.status !== "blocked")
|
|
228
|
+
try {
|
|
229
|
+
if (!adapterCurrent)
|
|
230
|
+
throw new SpliceError("preflight", 0, undefined, [
|
|
231
|
+
{
|
|
232
|
+
severity: "error",
|
|
233
|
+
code: "generated-adapter-stale",
|
|
234
|
+
path: "/adapter.ts",
|
|
235
|
+
message: "Generated adapter differs from the current plan/contracts/generator. Generate a new file and review it before replacing the old adapter.",
|
|
236
|
+
},
|
|
237
|
+
]);
|
|
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
|
+
}
|
|
255
|
+
}
|
|
256
|
+
let fixture = parseWorkflowJson(files["fixture.json"]);
|
|
257
|
+
if (manifest.fixtureFormat === "mcp") {
|
|
258
|
+
if (!jsonObject(fixture))
|
|
259
|
+
throw new Error("MCP fixture must be a result object.");
|
|
260
|
+
try {
|
|
261
|
+
if (fixture.resultType !== undefined &&
|
|
262
|
+
fixture.resultType !== "complete")
|
|
263
|
+
throw new Error("Non-complete result.");
|
|
264
|
+
fixture = decode(fixture);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
throw new SpliceError("source", 0, undefined, [
|
|
268
|
+
{
|
|
269
|
+
severity: "error",
|
|
270
|
+
code: "fixture-tool-error",
|
|
271
|
+
path: "/fixture",
|
|
272
|
+
message: "Saved MCP source reports an error.",
|
|
273
|
+
},
|
|
274
|
+
]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
rows = await prepared.mapOutput(fixture, manifest.hasContext
|
|
278
|
+
? { context: parseWorkflowJson(files["context.json"]) }
|
|
279
|
+
: {});
|
|
280
|
+
}
|
|
281
|
+
catch (e) {
|
|
282
|
+
if (!(e instanceof SpliceError))
|
|
283
|
+
throw e;
|
|
284
|
+
failure = e;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
...prepared.report,
|
|
288
|
+
preflightStatus: prepared.report.status,
|
|
289
|
+
status: failure ? "blocked" : prepared.report.status,
|
|
290
|
+
issues: failure
|
|
291
|
+
? [...prepared.report.issues, ...failure.issues]
|
|
292
|
+
: prepared.report.issues,
|
|
293
|
+
origin: manifest.origin,
|
|
294
|
+
...(manifest.origin === "catalogs" ? { hasSourceInput: manifest.hasInput !== false } : {}),
|
|
295
|
+
adapter: {
|
|
296
|
+
status: adapterCurrent === undefined
|
|
297
|
+
? "not-checked"
|
|
298
|
+
: adapterCurrent
|
|
299
|
+
? "current"
|
|
300
|
+
: "stale",
|
|
301
|
+
},
|
|
302
|
+
networkCalls: 0,
|
|
303
|
+
toolCalls: 0,
|
|
304
|
+
...(failure ? { explanation: explainSpliceError(plan, failure) } : {}),
|
|
305
|
+
...(rows
|
|
306
|
+
? {
|
|
307
|
+
mappingSummary: {
|
|
308
|
+
rows: rows.length,
|
|
309
|
+
argumentBytes: rows.reduce((n, row) => n + Buffer.byteLength(JSON.stringify(row)), 0),
|
|
310
|
+
},
|
|
311
|
+
}
|
|
312
|
+
: {}),
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
export async function initializeSpliceProject(directory, options = {}) {
|
|
316
|
+
const result = await createSpliceProjectFiles(options), path = resolve(directory);
|
|
317
|
+
// Validation precedes this atomic new-directory operation. Existing folders are never modified.
|
|
318
|
+
mkdirSync(path, { mode: 0o700 });
|
|
319
|
+
for (const [name, text] of Object.entries(result.files))
|
|
320
|
+
writeFileSync(join(path, name), text, { mode: 0o600, flag: "wx" });
|
|
321
|
+
return {
|
|
322
|
+
directory: path,
|
|
323
|
+
files: Object.keys(result.files),
|
|
324
|
+
origin: result.origin,
|
|
325
|
+
check: result.check,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
export async function checkSpliceProject(directory) {
|
|
329
|
+
const path = resolve(directory), read = (name) => {
|
|
330
|
+
try {
|
|
331
|
+
return readFileSync(join(path, name), "utf8");
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
throw new Error("Project artifact is missing or unreadable.");
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const text = read("toolsplice.project.json"), manifest = projectManifest(text);
|
|
338
|
+
const files = Object.fromEntries([
|
|
339
|
+
"plan.json",
|
|
340
|
+
"source.json",
|
|
341
|
+
"target.json",
|
|
342
|
+
...(manifest.hasInput === false ? [] : ["input.json"]),
|
|
343
|
+
"fixture.json",
|
|
344
|
+
"adapter.ts",
|
|
345
|
+
...(manifest.hasContext ? ["context.json"] : []),
|
|
346
|
+
].map((name) => [name, read(name)]));
|
|
347
|
+
return checkSpliceProjectFiles({ ...files, "toolsplice.project.json": text });
|
|
348
|
+
}
|