stitchkit 0.113.1 → 0.113.3
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/CHANGELOG.md +14 -0
- package/dist/contract/errors.d.ts +2 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +2 -2
- package/dist/entrypoints/agent-runtime/coding-tools.js +4 -4
- package/dist/entrypoints/agent-runtime/harness.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +2 -2
- package/dist/entrypoints/agent-runtime/sandbox.js +4 -4
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +6 -6
- package/dist/entrypoints/agent-runtime.js +11 -11
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application.js +2 -2
- package/dist/entrypoints/cli.js +8 -8
- package/dist/entrypoints/contract.js +2 -2
- package/dist/entrypoints/files.js +1 -1
- package/dist/entrypoints/index.js +5 -5
- package/dist/entrypoints/node.js +7 -7
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +1 -1
- package/dist/entrypoints/server.js +8 -8
- package/dist/entrypoints/testing.js +3 -3
- package/dist/entrypoints/tools/connections.js +5 -5
- package/dist/entrypoints/tools/invoker.js +5 -5
- package/dist/entrypoints/tools/mcp.js +7 -7
- package/dist/entrypoints/tools.js +13 -13
- package/dist/{index-8jjzfts8.js → index-095ya5hm.js} +5 -5
- package/dist/{index-sjww6myv.js → index-1csp1hwm.js} +4 -4
- package/dist/{index-xmgjtkvr.js → index-2bqf0a74.js} +1 -1
- package/dist/{index-ykdcnq1f.js → index-3za04re9.js} +1 -1
- package/dist/{index-yjnmac9b.js → index-523tq7y4.js} +1 -1
- package/dist/{index-mhrtwttb.js → index-7fc0c2np.js} +1 -1
- package/dist/{index-emrmgq3s.js → index-86nbfysb.js} +3 -3
- package/dist/{index-556g5hsh.js → index-98hv3sba.js} +1 -1
- package/dist/{index-h1spd9kv.js → index-9dyd8xzf.js} +1 -1
- package/dist/{index-gz9jf461.js → index-aykhzcnf.js} +1 -1
- package/dist/{index-86sxnvpr.js → index-bjcjqj46.js} +1 -1
- package/dist/{index-pzw0fpek.js → index-cqmqyjax.js} +1 -1
- package/dist/{index-nk1mh535.js → index-ega3yz4c.js} +1 -1
- package/dist/{index-k8fbzggr.js → index-fy4av0hq.js} +1 -1
- package/dist/{index-v6mzw27b.js → index-htxh46ej.js} +3 -3
- package/dist/{index-pvh3z03x.js → index-jk29rwkr.js} +1 -1
- package/dist/{index-fynr93w4.js → index-k42ckyzx.js} +1 -1
- package/dist/{index-fytsnhzj.js → index-k7z3j3hr.js} +211 -125
- package/dist/{index-j9gxbztg.js → index-qcn84byh.js} +2 -0
- package/dist/{index-jgwqc38k.js → index-rhzkndr5.js} +2 -2
- package/dist/{index-k0zfcxf5.js → index-tpwbct8j.js} +1 -1
- package/dist/{index-8asb62xn.js → index-v1tswj0z.js} +1 -1
- package/dist/{index-tg2q89ps.js → index-v6vb5qx8.js} +4 -4
- package/dist/{index-2qymcsq2.js → index-vtann8bz.js} +3 -3
- package/dist/{index-nn6607y3.js → index-vwhrnp67.js} +4 -4
- package/dist/{index-dsxrcseb.js → index-zktz242w.js} +2 -2
- package/dist/tools/cli/command-shape.d.ts +4 -0
- package/dist/tools/cli/command-shape.d.ts.map +1 -0
- package/dist/tools/cli/command.d.ts +2 -1
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts +5 -1
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/help.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +1 -1
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/managed-surface.d.ts +3 -2
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/policy.d.ts +2 -0
- package/dist/tools/cli/policy.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-native.d.ts.map +1 -1
- package/dist/tools/cli/session.d.ts +0 -1
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/unavailable.d.ts +10 -0
- package/dist/tools/cli/unavailable.d.ts.map +1 -0
- package/llms/cli.2.txt +282 -1
- package/llms/cli.txt +49 -287
- package/llms/server.4.txt +1 -1
- package/llms-full.txt +51 -8
- package/llms.txt +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateDeclaredOutput
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-k42ckyzx.js";
|
|
4
4
|
import {
|
|
5
5
|
jsonSchemaObjectCoercionMembers
|
|
6
6
|
} from "./index-dsa676h8.js";
|
|
@@ -14,15 +14,15 @@ import {
|
|
|
14
14
|
objectShapeKeys,
|
|
15
15
|
assertUniqueToolName,
|
|
16
16
|
buildToolPresentationSchema
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-rhzkndr5.js";
|
|
18
18
|
import {
|
|
19
19
|
toolResultFromError,
|
|
20
20
|
toolErrorFromResult
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-v6vb5qx8.js";
|
|
22
22
|
import {
|
|
23
23
|
createToolRunner,
|
|
24
24
|
formatToolError
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-htxh46ej.js";
|
|
26
26
|
import {
|
|
27
27
|
fetchGuarded,
|
|
28
28
|
readCapped
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
} from "./index-eemvahkc.js";
|
|
36
36
|
import {
|
|
37
37
|
collectToolSurface
|
|
38
|
-
} from "./index-
|
|
38
|
+
} from "./index-86nbfysb.js";
|
|
39
39
|
import {
|
|
40
40
|
isUnsafeKey,
|
|
41
41
|
safeJsonParse
|
|
@@ -43,6 +43,10 @@ import {
|
|
|
43
43
|
import {
|
|
44
44
|
formatZodError2
|
|
45
45
|
} from "./index-1eeqpadm.js";
|
|
46
|
+
import {
|
|
47
|
+
AppError2,
|
|
48
|
+
STITCH_ERROR_STATUS2
|
|
49
|
+
} from "./index-qcn84byh.js";
|
|
46
50
|
import {
|
|
47
51
|
isRecord
|
|
48
52
|
} from "./index-9jfdm5tg.js";
|
|
@@ -65,17 +69,28 @@ function prepareCliCommandEmission(definition, result, options) {
|
|
|
65
69
|
if (!result.ok || definition.output === undefined) {
|
|
66
70
|
return { result, successExitCode: 0 };
|
|
67
71
|
}
|
|
72
|
+
let successExitCode;
|
|
73
|
+
try {
|
|
74
|
+
successExitCode = cliCommandSuccessExitCode(definition, result.data);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return {
|
|
77
|
+
result: toolResultFromError(new Error("CLI result policy failed", { cause: error })),
|
|
78
|
+
successExitCode: 0
|
|
79
|
+
};
|
|
80
|
+
}
|
|
68
81
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
if (definition.present === undefined)
|
|
83
|
+
return { result, successExitCode };
|
|
84
|
+
const presentation = definition.present({ result: result.data, options });
|
|
85
|
+
if (typeof presentation !== "string") {
|
|
72
86
|
throw new Error("CLI result presenter must return a string");
|
|
73
87
|
}
|
|
74
88
|
return { result, presentation, successExitCode };
|
|
75
89
|
} catch (error) {
|
|
76
90
|
return {
|
|
77
|
-
result
|
|
78
|
-
|
|
91
|
+
result,
|
|
92
|
+
presentationFailure: toolResultFromError(new Error("CLI result presentation failed", { cause: error })),
|
|
93
|
+
successExitCode
|
|
79
94
|
};
|
|
80
95
|
}
|
|
81
96
|
}
|
|
@@ -137,6 +152,8 @@ var DEFAULT_EXIT_CODES2 = {
|
|
|
137
152
|
CONNECTION_REQUEST_FAILED: 1,
|
|
138
153
|
UPSTREAM_TOOL_ERROR: 1,
|
|
139
154
|
WAIT_FAILED: 1,
|
|
155
|
+
CLI_COMMAND_UNAVAILABLE: 1,
|
|
156
|
+
CLI_PRESENTATION_FAILED: 8,
|
|
140
157
|
INTERNAL_SERVER_ERROR: 1
|
|
141
158
|
};
|
|
142
159
|
function cliExitCode2(result, exitCodes) {
|
|
@@ -160,6 +177,21 @@ function emitResult2(result, writers, opts) {
|
|
|
160
177
|
`);
|
|
161
178
|
return cliExitCode2(result, opts.exitCodes);
|
|
162
179
|
}
|
|
180
|
+
function emitPresentationFailure(result, failure, writers, opts) {
|
|
181
|
+
emitResult2(result, writers, opts);
|
|
182
|
+
return emitResult2({
|
|
183
|
+
ok: false,
|
|
184
|
+
code: "CLI_PRESENTATION_FAILED",
|
|
185
|
+
retryable: false,
|
|
186
|
+
details: {
|
|
187
|
+
message: "The command completed successfully, but its result presentation failed.",
|
|
188
|
+
command: opts.toolName,
|
|
189
|
+
operationSucceeded: true,
|
|
190
|
+
cause: formatToolError(failure)
|
|
191
|
+
},
|
|
192
|
+
hint: "The complete, unformatted result is on stdout. Do not repeat the command to recover its result."
|
|
193
|
+
}, writers, { json: opts.json, toolName: opts.toolName, exitCodes: opts.exitCodes });
|
|
194
|
+
}
|
|
163
195
|
|
|
164
196
|
// src/tools/cli/argument-error.ts
|
|
165
197
|
class CliArgumentError2 extends Error {
|
|
@@ -653,19 +685,25 @@ async function runNativeCommand(definition, args, config, globals) {
|
|
|
653
685
|
written: { ...out !== "" && { stdout: out }, ...err !== "" && { stderr: err } }
|
|
654
686
|
};
|
|
655
687
|
}
|
|
656
|
-
function buildCliSurface(config, auth, nativeHelp, applicationGlobalNames,
|
|
688
|
+
function buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, shapeIssue) {
|
|
657
689
|
const services = typeof config.services === "function" ? config.services(auth) : config.services ?? [];
|
|
658
690
|
const runtimeTools = typeof config.runtimeTools === "function" ? config.runtimeTools(auth) : config.runtimeTools ?? [];
|
|
659
691
|
const tools = new Map;
|
|
660
692
|
const help = new Map(nativeHelp);
|
|
661
|
-
for (const { mountable } of collectToolSurface({
|
|
693
|
+
for (const { kind, mountable } of collectToolSurface({
|
|
662
694
|
surface: { services, runtimeTools },
|
|
663
695
|
transport: "CLI"
|
|
664
696
|
})) {
|
|
665
697
|
const descriptor = applyCliPresentationPolicy(mountable.name, managedCliDescriptor(mountable), config);
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
698
|
+
const issue = shapeIssue?.(mountable.name, descriptor, help.has(mountable.name), config.passthrough?.[mountable.name], applicationGlobalNames);
|
|
699
|
+
if (issue !== undefined) {
|
|
700
|
+
if (kind !== "runtime")
|
|
701
|
+
throw new Error(issue);
|
|
702
|
+
help.set(mountable.name, { ...descriptor, unavailableReason: issue });
|
|
703
|
+
} else {
|
|
704
|
+
tools.set(mountable.name, mountable);
|
|
705
|
+
help.set(mountable.name, descriptor);
|
|
706
|
+
}
|
|
669
707
|
}
|
|
670
708
|
assertCliPoliciesResolved(help, config);
|
|
671
709
|
return { tools, help };
|
|
@@ -1765,7 +1803,10 @@ function renderTopHelp(input) {
|
|
|
1765
1803
|
];
|
|
1766
1804
|
const width = Math.max(0, ...[...commands.keys()].map((key) => key.length));
|
|
1767
1805
|
for (const [command, descriptor] of commands) {
|
|
1768
|
-
lines.push(` ${padRight(command, width)} ${summarize(descriptor.description)}${command === defaultCommand ? " (default)" : ""}`);
|
|
1806
|
+
lines.push(` ${padRight(command, width)} ${summarize(descriptor.description)}${command === defaultCommand ? " (default)" : ""}${descriptor.unavailableReason !== undefined ? " [unavailable]" : ""}`);
|
|
1807
|
+
if (descriptor.unavailableReason !== undefined) {
|
|
1808
|
+
lines.push(` Unavailable: ${descriptor.unavailableReason}`);
|
|
1809
|
+
}
|
|
1769
1810
|
}
|
|
1770
1811
|
if (input.unavailable !== undefined) {
|
|
1771
1812
|
lines.push("", `Managed commands are unavailable: ${input.unavailable}`);
|
|
@@ -1809,6 +1850,9 @@ function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
|
|
|
1809
1850
|
"[--flags]"
|
|
1810
1851
|
].join(" ");
|
|
1811
1852
|
const lines = [descriptor.description, "", usage, ""];
|
|
1853
|
+
if (descriptor.unavailableReason !== undefined) {
|
|
1854
|
+
lines.push(`Unavailable: ${descriptor.unavailableReason}`, "");
|
|
1855
|
+
}
|
|
1812
1856
|
if (fields.length > 0) {
|
|
1813
1857
|
lines.push("Arguments:");
|
|
1814
1858
|
const labels = new Map(fields.map((field) => {
|
|
@@ -1845,114 +1889,24 @@ function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
|
|
|
1845
1889
|
`;
|
|
1846
1890
|
}
|
|
1847
1891
|
|
|
1848
|
-
// src/tools/cli/
|
|
1849
|
-
function
|
|
1850
|
-
return {
|
|
1851
|
-
description: definition.description,
|
|
1852
|
-
argumentSchema: definition.input,
|
|
1853
|
-
presentationSchema: cliCommandPresentationSchema(definition)
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
function assertCommandShape(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
|
|
1892
|
+
// src/tools/cli/command-shape.ts
|
|
1893
|
+
function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
|
|
1857
1894
|
assertUniqueToolName(name, exists, "CLI command");
|
|
1858
1895
|
if (name === "help" || name === "version") {
|
|
1859
1896
|
throw new Error(`[stitchkit] CLI command "${name}" is reserved`);
|
|
1860
1897
|
}
|
|
1898
|
+
if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
|
|
1899
|
+
throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
|
|
1900
|
+
}
|
|
1861
1901
|
const fieldNames = jsonSchemaFields(descriptor.presentationSchema).map((field) => field.name);
|
|
1862
1902
|
const conflicting = fieldNames.filter((field) => RESERVED_CLI_OPTIONS.has(field));
|
|
1863
1903
|
if (conflicting.length > 0) {
|
|
1864
|
-
|
|
1904
|
+
return `[stitchkit] CLI command "${name}" declares reserved option field(s): ${conflicting.join(", ")}`;
|
|
1865
1905
|
}
|
|
1866
1906
|
const shadowed = fieldNames.filter((field) => applicationGlobals.has(field));
|
|
1867
1907
|
if (shadowed.length > 0) {
|
|
1868
|
-
|
|
1908
|
+
return `[stitchkit] CLI command "${name}" declares field(s) shadowed by application global options: ${shadowed.join(", ")}`;
|
|
1869
1909
|
}
|
|
1870
|
-
if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
|
|
1871
|
-
throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
function createCliSession(config, io) {
|
|
1875
|
-
if (config.auth !== undefined && config.resolveAuth !== undefined) {
|
|
1876
|
-
throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
|
|
1877
|
-
}
|
|
1878
|
-
const applicationOptions = config.globalOptions ? jsonSchemaFields(buildToolPresentationSchema({
|
|
1879
|
-
inputSchema: config.globalOptions,
|
|
1880
|
-
unrepresentable: "any"
|
|
1881
|
-
})) : [];
|
|
1882
|
-
const applicationGlobalNames = new Set(applicationOptions.map((field) => field.name));
|
|
1883
|
-
for (const name of applicationGlobalNames) {
|
|
1884
|
-
if (RESERVED_CLI_OPTIONS.has(name)) {
|
|
1885
|
-
throw new Error(`[stitchkit] CLI global option "--${name}" is reserved by the framework`);
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
const nativeCommands = new Map;
|
|
1889
|
-
const nativeHelp = new Map;
|
|
1890
|
-
for (const definition of config.commands ?? []) {
|
|
1891
|
-
const descriptor = applyCliPresentationPolicy(definition.name, nativeDescriptor(definition), config);
|
|
1892
|
-
assertCommandShape(definition.name, descriptor, nativeCommands.has(definition.name), config.passthrough?.[definition.name], applicationGlobalNames);
|
|
1893
|
-
nativeCommands.set(definition.name, definition);
|
|
1894
|
-
nativeHelp.set(definition.name, descriptor);
|
|
1895
|
-
}
|
|
1896
|
-
return {
|
|
1897
|
-
config,
|
|
1898
|
-
io,
|
|
1899
|
-
applicationOptions,
|
|
1900
|
-
applicationGlobalNames,
|
|
1901
|
-
nativeCommands,
|
|
1902
|
-
nativeHelp
|
|
1903
|
-
};
|
|
1904
|
-
}
|
|
1905
|
-
function resolveCliRoute(session, argv) {
|
|
1906
|
-
const { config } = session;
|
|
1907
|
-
const { stdout, stderr, exit } = session.io;
|
|
1908
|
-
let globals;
|
|
1909
|
-
let routableArgv;
|
|
1910
|
-
try {
|
|
1911
|
-
const lifted = extractCliGlobalOptions2(argv, config.globalOptions);
|
|
1912
|
-
globals = lifted.globals;
|
|
1913
|
-
routableArgv = lifted.argv;
|
|
1914
|
-
} catch (error) {
|
|
1915
|
-
if (!(error instanceof CliArgumentError2))
|
|
1916
|
-
throw error;
|
|
1917
|
-
stderr(`${error.message}
|
|
1918
|
-
`);
|
|
1919
|
-
exit(2);
|
|
1920
|
-
return;
|
|
1921
|
-
}
|
|
1922
|
-
const typedGlobals = globals;
|
|
1923
|
-
const route = routeCliArgv2(routableArgv, config.defaultCommand);
|
|
1924
|
-
if (route.error) {
|
|
1925
|
-
stderr(`${route.error}
|
|
1926
|
-
`);
|
|
1927
|
-
exit(2);
|
|
1928
|
-
return;
|
|
1929
|
-
}
|
|
1930
|
-
const { command, commandArgv } = route;
|
|
1931
|
-
if (route.version || command === "--version" || command === "version") {
|
|
1932
|
-
stdout(`${config.name} ${config.version}
|
|
1933
|
-
`);
|
|
1934
|
-
exit(0);
|
|
1935
|
-
return;
|
|
1936
|
-
}
|
|
1937
|
-
const beforeSeparator = commandArgv.indexOf("--") === -1 ? commandArgv : commandArgv.slice(0, commandArgv.indexOf("--"));
|
|
1938
|
-
const helpRequested = beforeSeparator.includes("--help") || beforeSeparator.includes("-h");
|
|
1939
|
-
return {
|
|
1940
|
-
globals,
|
|
1941
|
-
typedGlobals,
|
|
1942
|
-
route,
|
|
1943
|
-
command,
|
|
1944
|
-
commandArgv,
|
|
1945
|
-
beforeSeparator,
|
|
1946
|
-
helpRequested
|
|
1947
|
-
};
|
|
1948
|
-
}
|
|
1949
|
-
function emitOptionsFor(config, json, toolName) {
|
|
1950
|
-
return {
|
|
1951
|
-
json,
|
|
1952
|
-
toolName,
|
|
1953
|
-
errorHint: config.errorHint,
|
|
1954
|
-
exitCodes: { ...DEFAULT_EXIT_CODES2, ...config.exitCodes }
|
|
1955
|
-
};
|
|
1956
1910
|
}
|
|
1957
1911
|
|
|
1958
1912
|
// src/tools/cli/managed-surface.ts
|
|
@@ -1979,7 +1933,7 @@ async function buildManagedSurface(session, typedGlobals, forExecution) {
|
|
|
1979
1933
|
};
|
|
1980
1934
|
}
|
|
1981
1935
|
}
|
|
1982
|
-
const { tools, help } = buildCliSurface(config, auth, nativeHelp, applicationGlobalNames,
|
|
1936
|
+
const { tools, help } = buildCliSurface(config, auth, nativeHelp, applicationGlobalNames, commandShapeIssue);
|
|
1983
1937
|
return { resolved: true, auth, help, tools };
|
|
1984
1938
|
}
|
|
1985
1939
|
|
|
@@ -2056,6 +2010,128 @@ async function prepareInvocation(command, commandArgv, descriptor, config, readS
|
|
|
2056
2010
|
return { ok: true, toolArgs, options };
|
|
2057
2011
|
}
|
|
2058
2012
|
|
|
2013
|
+
// src/tools/cli/session.ts
|
|
2014
|
+
function nativeDescriptor(definition) {
|
|
2015
|
+
return {
|
|
2016
|
+
description: definition.description,
|
|
2017
|
+
argumentSchema: definition.input,
|
|
2018
|
+
presentationSchema: cliCommandPresentationSchema(definition)
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
function createCliSession(config, io) {
|
|
2022
|
+
if (config.auth !== undefined && config.resolveAuth !== undefined) {
|
|
2023
|
+
throw new Error("[stitchkit] createCli: use either auth or resolveAuth, not both");
|
|
2024
|
+
}
|
|
2025
|
+
const applicationOptions = config.globalOptions ? jsonSchemaFields(buildToolPresentationSchema({
|
|
2026
|
+
inputSchema: config.globalOptions,
|
|
2027
|
+
unrepresentable: "any"
|
|
2028
|
+
})) : [];
|
|
2029
|
+
const applicationGlobalNames = new Set(applicationOptions.map((field) => field.name));
|
|
2030
|
+
for (const name of applicationGlobalNames) {
|
|
2031
|
+
if (RESERVED_CLI_OPTIONS.has(name)) {
|
|
2032
|
+
throw new Error(`[stitchkit] CLI global option "--${name}" is reserved by the framework`);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
const nativeCommands = new Map;
|
|
2036
|
+
const nativeHelp = new Map;
|
|
2037
|
+
for (const definition of config.commands ?? []) {
|
|
2038
|
+
const descriptor = applyCliPresentationPolicy(definition.name, nativeDescriptor(definition), config);
|
|
2039
|
+
const issue = commandShapeIssue(definition.name, descriptor, nativeCommands.has(definition.name), config.passthrough?.[definition.name], applicationGlobalNames);
|
|
2040
|
+
if (issue !== undefined)
|
|
2041
|
+
throw new Error(issue);
|
|
2042
|
+
nativeCommands.set(definition.name, definition);
|
|
2043
|
+
nativeHelp.set(definition.name, descriptor);
|
|
2044
|
+
}
|
|
2045
|
+
return {
|
|
2046
|
+
config,
|
|
2047
|
+
io,
|
|
2048
|
+
applicationOptions,
|
|
2049
|
+
applicationGlobalNames,
|
|
2050
|
+
nativeCommands,
|
|
2051
|
+
nativeHelp
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
function resolveCliRoute(session, argv) {
|
|
2055
|
+
const { config } = session;
|
|
2056
|
+
const { stdout, stderr, exit } = session.io;
|
|
2057
|
+
let globals;
|
|
2058
|
+
let routableArgv;
|
|
2059
|
+
try {
|
|
2060
|
+
const lifted = extractCliGlobalOptions2(argv, config.globalOptions);
|
|
2061
|
+
globals = lifted.globals;
|
|
2062
|
+
routableArgv = lifted.argv;
|
|
2063
|
+
} catch (error) {
|
|
2064
|
+
if (!(error instanceof CliArgumentError2))
|
|
2065
|
+
throw error;
|
|
2066
|
+
stderr(`${error.message}
|
|
2067
|
+
`);
|
|
2068
|
+
exit(2);
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
const typedGlobals = globals;
|
|
2072
|
+
const route = routeCliArgv2(routableArgv, config.defaultCommand);
|
|
2073
|
+
if (route.error) {
|
|
2074
|
+
stderr(`${route.error}
|
|
2075
|
+
`);
|
|
2076
|
+
exit(2);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
const { command, commandArgv } = route;
|
|
2080
|
+
if (route.version || command === "--version" || command === "version") {
|
|
2081
|
+
stdout(`${config.name} ${config.version}
|
|
2082
|
+
`);
|
|
2083
|
+
exit(0);
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
const beforeSeparator = commandArgv.indexOf("--") === -1 ? commandArgv : commandArgv.slice(0, commandArgv.indexOf("--"));
|
|
2087
|
+
const helpRequested = beforeSeparator.some((token) => {
|
|
2088
|
+
if (token === "--help" || token === "-h")
|
|
2089
|
+
return true;
|
|
2090
|
+
const option = classifyLongOptionToken(token);
|
|
2091
|
+
return option?.name === "help" && option.value !== undefined && isReservedBoolWord(option.value) && parseReservedBool("help", option.value);
|
|
2092
|
+
});
|
|
2093
|
+
return {
|
|
2094
|
+
globals,
|
|
2095
|
+
typedGlobals,
|
|
2096
|
+
route,
|
|
2097
|
+
command,
|
|
2098
|
+
commandArgv,
|
|
2099
|
+
beforeSeparator,
|
|
2100
|
+
helpRequested
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
function emitOptionsFor(config, json, toolName) {
|
|
2104
|
+
return {
|
|
2105
|
+
json,
|
|
2106
|
+
toolName,
|
|
2107
|
+
errorHint: config.errorHint,
|
|
2108
|
+
exitCodes: { ...DEFAULT_EXIT_CODES2, ...config.exitCodes }
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// src/tools/cli/unavailable.ts
|
|
2113
|
+
function unavailableCommand(reason) {
|
|
2114
|
+
return toolResultFromError(new AppError2("CLI_COMMAND_UNAVAILABLE", {
|
|
2115
|
+
message: reason,
|
|
2116
|
+
status: STITCH_ERROR_STATUS2.CLI_COMMAND_UNAVAILABLE,
|
|
2117
|
+
retryable: false
|
|
2118
|
+
}));
|
|
2119
|
+
}
|
|
2120
|
+
function unavailableCommandJson(argv) {
|
|
2121
|
+
for (let i = 0;i < argv.length; i++) {
|
|
2122
|
+
const token = argv[i];
|
|
2123
|
+
if (token === "--")
|
|
2124
|
+
break;
|
|
2125
|
+
if (token === undefined)
|
|
2126
|
+
continue;
|
|
2127
|
+
const option = classifyLongOptionToken(token);
|
|
2128
|
+
if (option?.name !== "json")
|
|
2129
|
+
continue;
|
|
2130
|
+
return option.value === undefined ? separateBoolValue(argv[i + 1]) ?? true : isReservedBoolWord(option.value) && parseReservedBool("json", option.value);
|
|
2131
|
+
}
|
|
2132
|
+
return false;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2059
2135
|
// src/tools/cli/run-managed.ts
|
|
2060
2136
|
async function runManagedInvocation(session, route) {
|
|
2061
2137
|
const { config } = session;
|
|
@@ -2077,7 +2153,7 @@ function respondTopLevelHelp(session, route, managed) {
|
|
|
2077
2153
|
const helpFilter = route.route.helpFilter ?? (command !== undefined ? commandArgv[0] : undefined);
|
|
2078
2154
|
const filter = helpFilter !== undefined && !helpFilter.startsWith("-") ? helpFilter : undefined;
|
|
2079
2155
|
if (filter !== undefined && filterCommands(managed.help, filter).size === 0) {
|
|
2080
|
-
stderr(`no command matches "${filter}" (${managed.help.
|
|
2156
|
+
stderr(`no command matches "${filter}" (${[...managed.help.values()].filter((entry) => entry.unavailableReason === undefined).length} available)
|
|
2081
2157
|
` + (managed.resolved ? "" : `Managed commands are unavailable: ${managed.reason}
|
|
2082
2158
|
`));
|
|
2083
2159
|
const codes = { ...DEFAULT_EXIT_CODES2, ...config.exitCodes };
|
|
@@ -2098,19 +2174,22 @@ function respondTopLevelHelp(session, route, managed) {
|
|
|
2098
2174
|
async function runManagedCommand(session, route, command, managed) {
|
|
2099
2175
|
const { config, applicationOptions } = session;
|
|
2100
2176
|
const { stdout, stderr, exit, readStdin } = session.io;
|
|
2101
|
-
const
|
|
2102
|
-
if (!
|
|
2177
|
+
const descriptor = managed.help.get(command);
|
|
2178
|
+
if (!descriptor) {
|
|
2103
2179
|
stderr(`Unknown command "${command}". Run "${config.name} --help" for the command list.
|
|
2104
2180
|
`);
|
|
2105
2181
|
return exit(1);
|
|
2106
2182
|
}
|
|
2107
|
-
const descriptor = managed.help.get(command);
|
|
2108
|
-
if (!descriptor)
|
|
2109
|
-
throw new Error("[stitchkit] managed CLI descriptor invariant failed");
|
|
2110
2183
|
if (route.helpRequested) {
|
|
2111
2184
|
stdout(renderCommandHelp(config.name, command, descriptor, applicationOptions));
|
|
2112
2185
|
return exit(0);
|
|
2113
2186
|
}
|
|
2187
|
+
if (descriptor.unavailableReason !== undefined) {
|
|
2188
|
+
return exit(emitResult2(unavailableCommand(descriptor.unavailableReason), { stdout, stderr }, emitOptionsFor(config, unavailableCommandJson(route.commandArgv), command)));
|
|
2189
|
+
}
|
|
2190
|
+
const tool = managed.tools.get(command);
|
|
2191
|
+
if (!tool)
|
|
2192
|
+
throw new Error("[stitchkit] managed CLI executable invariant failed");
|
|
2114
2193
|
const prepared = await prepareInvocation(command, route.commandArgv, descriptor, config, readStdin);
|
|
2115
2194
|
if (!prepared.ok) {
|
|
2116
2195
|
stderr(`${prepared.message}
|
|
@@ -2171,6 +2250,9 @@ async function executeManagedTool(session, route, command, managed, tool, { tool
|
|
|
2171
2250
|
initial: result,
|
|
2172
2251
|
wait: waitConfig,
|
|
2173
2252
|
call: async (toolName, args) => {
|
|
2253
|
+
const unavailable = managed.help.get(toolName)?.unavailableReason;
|
|
2254
|
+
if (unavailable !== undefined)
|
|
2255
|
+
return unavailableCommand(unavailable);
|
|
2174
2256
|
const pollTool = managed.tools.get(toolName);
|
|
2175
2257
|
if (!pollTool) {
|
|
2176
2258
|
return {
|
|
@@ -2202,11 +2284,12 @@ async function emitManagedResult(session, command, initial, options) {
|
|
|
2202
2284
|
try {
|
|
2203
2285
|
viewed = renderCliView2(result.data, options.view);
|
|
2204
2286
|
} catch (error) {
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2287
|
+
const failure = error instanceof CliArgumentError2 ? {
|
|
2288
|
+
ok: false,
|
|
2289
|
+
code: "BAD_REQUEST",
|
|
2290
|
+
details: { message: error.message }
|
|
2291
|
+
} : toolResultFromError(error);
|
|
2292
|
+
return exit(emitPresentationFailure(result, failure, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
|
|
2210
2293
|
}
|
|
2211
2294
|
if (viewed.kind === "text") {
|
|
2212
2295
|
stdout(viewed.text);
|
|
@@ -2263,6 +2346,9 @@ async function runNativeCommand2(session, route, command, native) {
|
|
|
2263
2346
|
}
|
|
2264
2347
|
const result = await executeCliCommand(native, toolArgs, options, { stdout, stderr }, config.coerceJsonArgs ?? true, globals);
|
|
2265
2348
|
const emission = prepareCliCommandEmission(native, result, options);
|
|
2349
|
+
if (emission.result.ok && emission.presentationFailure !== undefined) {
|
|
2350
|
+
return exit(emitPresentationFailure(emission.result, emission.presentationFailure, { stdout, stderr }, emitOptionsFor(config, options.json, command)));
|
|
2351
|
+
}
|
|
2266
2352
|
let emittedExitCode;
|
|
2267
2353
|
if (emission.result.ok && emission.presentation !== undefined) {
|
|
2268
2354
|
stdout(emission.presentation);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateDeclaredOutput
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-k42ckyzx.js";
|
|
4
4
|
import {
|
|
5
5
|
toJsonSchema
|
|
6
6
|
} from "./index-ct75c3at.js";
|
|
7
7
|
import {
|
|
8
8
|
AppError2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-qcn84byh.js";
|
|
10
10
|
import {
|
|
11
11
|
serializeCanonicalJson
|
|
12
12
|
} from "./index-zsvzhjtk.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
normalizeError2,
|
|
3
3
|
validateDeclaredOutput
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-k42ckyzx.js";
|
|
5
5
|
import {
|
|
6
6
|
localVerdict
|
|
7
7
|
} from "./index-dsa676h8.js";
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
applyToolViewDefaults,
|
|
13
13
|
projectToolView,
|
|
14
14
|
objectShapeKeys
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-rhzkndr5.js";
|
|
16
16
|
import {
|
|
17
17
|
runWithRequestContext2,
|
|
18
18
|
getRequestContext2
|
|
19
19
|
} from "./index-r6v4mc67.js";
|
|
20
20
|
import {
|
|
21
21
|
projectedToolError
|
|
22
|
-
} from "./index-
|
|
22
|
+
} from "./index-98hv3sba.js";
|
|
23
23
|
import {
|
|
24
24
|
isUnsafeKey
|
|
25
25
|
} from "./index-zsarb5xp.js";
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
STITCH_ERROR_STATUS2,
|
|
32
32
|
isRetryableStatus2,
|
|
33
33
|
isStitchErrorCode2
|
|
34
|
-
} from "./index-
|
|
34
|
+
} from "./index-qcn84byh.js";
|
|
35
35
|
import {
|
|
36
36
|
isRecord
|
|
37
37
|
} from "./index-9jfdm5tg.js";
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
recordedErrorMessage,
|
|
4
4
|
normalizeError2,
|
|
5
5
|
validateDeclaredOutput
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-k42ckyzx.js";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_CONTRACT_STREAM_FRAME_BYTES2
|
|
9
9
|
} from "./index-h2fhjqy7.js";
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
bindContract,
|
|
28
28
|
mediaTypeEssence
|
|
29
|
-
} from "./index-
|
|
29
|
+
} from "./index-cqmqyjax.js";
|
|
30
30
|
import {
|
|
31
31
|
readBoundedChunks,
|
|
32
32
|
concatChunks,
|
|
@@ -71,7 +71,7 @@ import {
|
|
|
71
71
|
AppError2,
|
|
72
72
|
badRequest2,
|
|
73
73
|
forbidden2
|
|
74
|
-
} from "./index-
|
|
74
|
+
} from "./index-qcn84byh.js";
|
|
75
75
|
import {
|
|
76
76
|
resolveTraceContext2
|
|
77
77
|
} from "./index-yex7eg1v.js";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertUniqueToolName
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-rhzkndr5.js";
|
|
4
4
|
import {
|
|
5
5
|
toolErrorFromResult
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-v6vb5qx8.js";
|
|
7
7
|
import {
|
|
8
8
|
collectTools2,
|
|
9
9
|
createToolRunner
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-htxh46ej.js";
|
|
11
11
|
import {
|
|
12
12
|
AppError2
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-qcn84byh.js";
|
|
14
14
|
|
|
15
15
|
// src/tools/invoker.ts
|
|
16
16
|
function createToolInvoker2(services, config) {
|
|
@@ -27,13 +27,13 @@ import {
|
|
|
27
27
|
} from "./index-j4zh647a.js";
|
|
28
28
|
import {
|
|
29
29
|
defineRuntimeTool2
|
|
30
|
-
} from "./index-
|
|
30
|
+
} from "./index-ega3yz4c.js";
|
|
31
31
|
import {
|
|
32
32
|
AppError2,
|
|
33
33
|
forbidden2,
|
|
34
34
|
conflict2,
|
|
35
35
|
STITCH_ERROR_STATUS2
|
|
36
|
-
} from "./index-
|
|
36
|
+
} from "./index-qcn84byh.js";
|
|
37
37
|
|
|
38
38
|
// src/agent-runtime/coding-tool-contract.ts
|
|
39
39
|
import { z } from "zod";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CliCommandPresentation } from './policy.js';
|
|
2
|
+
/** Local configuration faults throw; only argv field conflicts become unavailable. */
|
|
3
|
+
export declare function commandShapeIssue(name: string, descriptor: CliCommandPresentation, exists: boolean, passthroughField?: string, applicationGlobals?: ReadonlySet<string>): string | undefined;
|
|
4
|
+
//# sourceMappingURL=command-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-shape.d.ts","sourceRoot":"","sources":["../../../src/tools/cli/command-shape.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,sFAAsF;AACtF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,sBAAsB,EAClC,MAAM,EAAE,OAAO,EACf,gBAAgB,CAAC,EAAE,MAAM,EACzB,kBAAkB,GAAE,WAAW,CAAC,MAAM,CAAa,GAClD,MAAM,GAAG,SAAS,CAwBpB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ZodObject, ZodType, z } from 'zod';
|
|
2
|
-
import { type ToolResult } from '../execute-result.js';
|
|
2
|
+
import { type ToolFailure, type ToolResult } from '../execute-result.js';
|
|
3
3
|
import type { CliRunOptions } from './args.js';
|
|
4
4
|
import type { CliWriters } from './format.js';
|
|
5
5
|
export interface CliCommandContext<TInput extends ZodObject> extends CliWriters {
|
|
@@ -42,6 +42,7 @@ export declare function defineCliCommand<TInput extends ZodObject>(definition: C
|
|
|
42
42
|
export interface PreparedCliCommandEmission {
|
|
43
43
|
result: ToolResult;
|
|
44
44
|
presentation?: string;
|
|
45
|
+
presentationFailure?: ToolFailure;
|
|
45
46
|
successExitCode: number;
|
|
46
47
|
}
|
|
47
48
|
/**
|