stitchkit 0.124.5 → 0.126.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +99 -1
- package/dist/agent-runtime/branch-contract.d.ts +5 -0
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +18 -0
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +9 -2
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-source.d.ts +1 -1
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- package/dist/agent-runtime/store-conformance-branch.d.ts.map +1 -1
- package/dist/application/watch-hub-core.d.ts +2 -1
- package/dist/application/watch-hub-core.d.ts.map +1 -1
- package/dist/application/watch-hub-source.d.ts +2 -0
- package/dist/application/watch-hub-source.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts +20 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/coding-tools.js +4 -4
- package/dist/entrypoints/agent-runtime/harness.js +4 -4
- 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 +33 -9
- package/dist/entrypoints/agent-runtime.js +12 -12
- package/dist/entrypoints/application.d.ts +1 -1
- package/dist/entrypoints/application.d.ts.map +1 -1
- package/dist/entrypoints/application.js +55 -8
- package/dist/entrypoints/bin/upgrade-cli.js +2 -0
- package/dist/entrypoints/cli.js +6 -6
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/node.js +2 -1
- package/dist/entrypoints/process.js +2 -2
- package/dist/entrypoints/server.d.ts +1 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +7 -7
- package/dist/entrypoints/testing.js +1 -1
- package/dist/entrypoints/tools/agent.js +6 -6
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +4 -4
- package/dist/entrypoints/tools/mcp.js +8 -6
- package/dist/entrypoints/tools/toolkit.js +10 -8
- package/dist/entrypoints/tools.js +11 -11
- package/dist/{index-gbj964dt.js → index-103dp7fz.js} +54 -31
- package/dist/{index-cm07qz01.js → index-1v3k5zgx.js} +1 -1
- package/dist/{index-3n8k175r.js → index-48acz7z0.js} +5 -5
- package/dist/{index-6fmg17bg.js → index-4efxzrht.js} +2 -2
- package/dist/{index-en2xqhty.js → index-57ppvpw0.js} +1 -1
- package/dist/{index-x68eyh6y.js → index-7cn66qdk.js} +2 -2
- package/dist/{index-7q05ag0z.js → index-7zksb1ty.js} +1 -1
- package/dist/{index-xaem29dc.js → index-a3z56mtn.js} +1 -1
- package/dist/{index-568w258r.js → index-a6w6mwda.js} +1 -1
- package/dist/{index-z2z67tnv.js → index-cvjddnvd.js} +3 -3
- package/dist/{index-afc3mtah.js → index-ft2wvst5.js} +101 -32
- package/dist/{index-gdqawggb.js → index-jjvr9f15.js} +14 -0
- package/dist/{index-q7s1yr9g.js → index-kxff9e9w.js} +3 -3
- package/dist/{index-r7v5xz0g.js → index-m0wsfmrc.js} +1 -1
- package/dist/{index-pq7rkwkk.js → index-m200b8hs.js} +65 -12
- package/dist/{index-2ds89z96.js → index-n6hvd1r2.js} +4 -4
- package/dist/{index-p9saezh1.js → index-pa9bhefy.js} +1 -1
- package/dist/{index-p1mwqkgh.js → index-v7rbjatr.js} +122 -113
- package/dist/{index-rk7m4j7r.js → index-x2d51zay.js} +9 -10
- package/dist/{index-1wz4y15d.js → index-x2rvpbtj.js} +1 -1
- package/dist/internal/coalesced-task.d.ts +14 -2
- package/dist/internal/coalesced-task.d.ts.map +1 -1
- package/dist/internal/upgrade-affects.d.ts.map +1 -1
- package/dist/process/group-settlement.d.ts +2 -0
- package/dist/process/group-settlement.d.ts.map +1 -1
- package/dist/server/context.d.ts +2 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/error-dispatch.d.ts +2 -0
- package/dist/server/error-dispatch.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +3 -0
- package/dist/server/handler-state.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +48 -3
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/types.d.ts +8 -2
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts +10 -1
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/command-shape.d.ts +4 -0
- package/dist/tools/cli/command-shape.d.ts.map +1 -1
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/session.d.ts +1 -1
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts +6 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/internal/surface-projector.d.ts +2 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/llms/agent-runtime.2.txt +30 -0
- package/llms/agent-runtime.4.txt +1 -1
- package/llms/application.3.txt +9 -3
- package/llms/cli.2.txt +1 -1
- package/llms/cli.txt +27 -0
- package/llms/live.txt +28 -1
- package/llms/server.3.txt +2 -1
- package/llms/server.5.txt +3 -1
- package/llms/server.txt +44 -1
- package/llms/stitchkit.txt +3 -3
- package/llms/{upgrading-0.106.0-0.124.0.txt → upgrading-0.106.0-0.126.0.txt} +65 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +210 -12
- package/llms.txt +6 -6
- package/package.json +4 -4
|
@@ -129,6 +129,18 @@ function observationFailureReason(cause) {
|
|
|
129
129
|
const signal = "signal" in cause && typeof cause.signal === "string" ? cause.signal : undefined;
|
|
130
130
|
return (errnoOf(cause) ?? signal ?? cause.name).slice(0, 32);
|
|
131
131
|
}
|
|
132
|
+
var GROUP_EXIT_QUICK_LOOKS = 8;
|
|
133
|
+
async function groupLeavesShortly(pid, deadline) {
|
|
134
|
+
for (let look = 0;look < GROUP_EXIT_QUICK_LOOKS; look += 1) {
|
|
135
|
+
const remaining = deadline - performance.now();
|
|
136
|
+
if (remaining <= 0)
|
|
137
|
+
return false;
|
|
138
|
+
await sleep(Math.min(1, remaining));
|
|
139
|
+
if (!processGroupExists(pid))
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
132
144
|
async function waitForProcessGroupExit(pid, deadline, killLiveMembers) {
|
|
133
145
|
if (pid === undefined)
|
|
134
146
|
return;
|
|
@@ -148,6 +160,8 @@ async function waitForProcessGroupExit(pid, deadline, killLiveMembers) {
|
|
|
148
160
|
throw new GroupSettlementError("Command process group settlement was not confirmed after SIGKILL", { ...observation(), failure: "deadline" });
|
|
149
161
|
if (!processGroupExists(pid))
|
|
150
162
|
return;
|
|
163
|
+
if (observations === 0 && await groupLeavesShortly(pid, deadline))
|
|
164
|
+
return;
|
|
151
165
|
const table = await processGroups(remaining);
|
|
152
166
|
observations++;
|
|
153
167
|
if (!hasLiveGroupMember(table, pid))
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
projectToolSurface
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-x2d51zay.js";
|
|
4
4
|
import {
|
|
5
5
|
contractToolMountable
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-7cn66qdk.js";
|
|
7
7
|
import {
|
|
8
8
|
runtimeToolMountable
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-m0wsfmrc.js";
|
|
10
10
|
|
|
11
11
|
// src/tools/surface.ts
|
|
12
12
|
function collectToolSurface({
|
|
@@ -1,7 +1,59 @@
|
|
|
1
1
|
// src/server/middleware/cors.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var CorsOriginDecisionSchema = z.union([
|
|
4
|
+
z.literal(false),
|
|
5
|
+
z.object({ credentials: z.boolean() }).strict()
|
|
6
|
+
]);
|
|
7
|
+
function isOriginPolicy(config) {
|
|
8
|
+
return typeof config.origin === "function";
|
|
9
|
+
}
|
|
10
|
+
function isSerializedOrigin(origin) {
|
|
11
|
+
if (!URL.canParse(origin))
|
|
12
|
+
return false;
|
|
13
|
+
const url = new URL(origin);
|
|
14
|
+
return url.host !== "" && origin === `${url.protocol}//${url.host}`;
|
|
15
|
+
}
|
|
16
|
+
function resolveRequestCors(config, origin) {
|
|
17
|
+
if (!isOriginPolicy(config)) {
|
|
18
|
+
return {
|
|
19
|
+
headers: corsHeaders2(config, origin),
|
|
20
|
+
safelistedBody: config.origin === undefined || config.origin === "*" ? "no-allow-list" : isOriginAllowed(config, origin) ? "allowed" : "refused"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (!origin || !isSerializedOrigin(origin))
|
|
24
|
+
return deniedRequestCors(config);
|
|
25
|
+
return askPolicy(config, origin);
|
|
26
|
+
}
|
|
27
|
+
async function askPolicy(config, origin) {
|
|
28
|
+
const parsed = CorsOriginDecisionSchema.safeParse(await config.origin(origin));
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
throw new TypeError("[stitchkit] cors: an origin resolver must answer false or { credentials: boolean }");
|
|
31
|
+
}
|
|
32
|
+
if (parsed.data === false)
|
|
33
|
+
return deniedRequestCors(config);
|
|
34
|
+
return {
|
|
35
|
+
headers: {
|
|
36
|
+
...permissionHeaders(config, origin, parsed.data.credentials),
|
|
37
|
+
Vary: "Origin"
|
|
38
|
+
},
|
|
39
|
+
safelistedBody: parsed.data.credentials ? "allowed" : "refused"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function deniedRequestCors(config) {
|
|
43
|
+
return {
|
|
44
|
+
headers: { ...permissionHeaders(config, undefined, false), Vary: "Origin" },
|
|
45
|
+
safelistedBody: "refused"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
2
48
|
var DEFAULT_CORS_ALLOW_HEADERS2 = "Content-Type, Authorization, X-Trace-Id, traceparent, tracestate";
|
|
3
49
|
var DEFAULT_CORS_EXPOSE_HEADERS2 = "Content-Disposition, Content-Length, Content-Range, Accept-Ranges, ETag, Last-Modified, X-Request-Id, X-Build-Id";
|
|
4
50
|
function assertCorsConfig(config) {
|
|
51
|
+
if (isOriginPolicy(config)) {
|
|
52
|
+
if (config.credentials !== undefined) {
|
|
53
|
+
throw new Error("[stitchkit] cors: an origin resolver decides credentials per origin; remove `credentials`.");
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
5
57
|
if (config.credentials && (config.origin === undefined || config.origin === "*")) {
|
|
6
58
|
throw new Error("[stitchkit] cors: `credentials: true` cannot be combined with a wildcard origin. " + "Set `origin` to an explicit string or list.");
|
|
7
59
|
}
|
|
@@ -36,7 +88,13 @@ function isOriginAllowed(config, requestOrigin) {
|
|
|
36
88
|
return allowed.some((origin) => origin.toLowerCase() === lower);
|
|
37
89
|
}
|
|
38
90
|
function corsHeaders2(config, requestOrigin) {
|
|
39
|
-
const
|
|
91
|
+
const headers = permissionHeaders(config, resolveOrigin(config, requestOrigin), config.credentials === true);
|
|
92
|
+
if (Array.isArray(config.origin)) {
|
|
93
|
+
headers.Vary = "Origin";
|
|
94
|
+
}
|
|
95
|
+
return headers;
|
|
96
|
+
}
|
|
97
|
+
function permissionHeaders(config, allowOrigin, credentials) {
|
|
40
98
|
const headers = {
|
|
41
99
|
"Access-Control-Allow-Methods": config.methods ?? "GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS",
|
|
42
100
|
"Access-Control-Allow-Headers": config.headers ?? DEFAULT_CORS_ALLOW_HEADERS2
|
|
@@ -47,13 +105,10 @@ function corsHeaders2(config, requestOrigin) {
|
|
|
47
105
|
}
|
|
48
106
|
if (allowOrigin !== undefined) {
|
|
49
107
|
headers["Access-Control-Allow-Origin"] = allowOrigin;
|
|
50
|
-
if (
|
|
108
|
+
if (credentials) {
|
|
51
109
|
headers["Access-Control-Allow-Credentials"] = "true";
|
|
52
110
|
}
|
|
53
111
|
}
|
|
54
|
-
if (Array.isArray(config.origin)) {
|
|
55
|
-
headers.Vary = "Origin";
|
|
56
|
-
}
|
|
57
112
|
return headers;
|
|
58
113
|
}
|
|
59
114
|
function corsPreflightResponse2(config, req) {
|
|
@@ -62,13 +117,11 @@ function corsPreflightResponse2(config, req) {
|
|
|
62
117
|
headers: corsHeaders2(config, req.headers.get("origin"))
|
|
63
118
|
});
|
|
64
119
|
}
|
|
65
|
-
function requestCorsHeaders(cors
|
|
66
|
-
|
|
67
|
-
return {};
|
|
68
|
-
return corsHeaders2(cors, req.headers.get("origin"));
|
|
120
|
+
function requestCorsHeaders(cors) {
|
|
121
|
+
return cors ? { ...cors.headers } : {};
|
|
69
122
|
}
|
|
70
|
-
function applyCors(res, cors
|
|
71
|
-
const extra = requestCorsHeaders(cors
|
|
123
|
+
function applyCors(res, cors) {
|
|
124
|
+
const extra = requestCorsHeaders(cors);
|
|
72
125
|
if (Object.keys(extra).length === 0)
|
|
73
126
|
return res;
|
|
74
127
|
try {
|
|
@@ -101,4 +154,4 @@ function setCorsHeader(headers, key, value) {
|
|
|
101
154
|
headers.set("Vary", `${existing}, ${value}`);
|
|
102
155
|
}
|
|
103
156
|
|
|
104
|
-
export { DEFAULT_CORS_ALLOW_HEADERS2, DEFAULT_CORS_EXPOSE_HEADERS2, assertCorsConfig,
|
|
157
|
+
export { resolveRequestCors, deniedRequestCors, DEFAULT_CORS_ALLOW_HEADERS2, DEFAULT_CORS_EXPOSE_HEADERS2, assertCorsConfig, corsHeaders2, corsPreflightResponse2, requestCorsHeaders, applyCors };
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
toolResultFromError,
|
|
3
3
|
toolCauseFromResult,
|
|
4
4
|
isToolExecutionControlError2
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-x2rvpbtj.js";
|
|
6
6
|
import {
|
|
7
7
|
createToolRunner,
|
|
8
8
|
formatToolError
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-7cn66qdk.js";
|
|
10
10
|
import {
|
|
11
11
|
resolveRuntimeToolCall
|
|
12
12
|
} from "./index-eh71zr32.js";
|
|
@@ -15,10 +15,10 @@ import {
|
|
|
15
15
|
} from "./index-1psbyyhj.js";
|
|
16
16
|
import {
|
|
17
17
|
collectToolSurface
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-kxff9e9w.js";
|
|
19
19
|
import {
|
|
20
20
|
agentPresenterOf
|
|
21
|
-
} from "./index-
|
|
21
|
+
} from "./index-m0wsfmrc.js";
|
|
22
22
|
import {
|
|
23
23
|
isRecord
|
|
24
24
|
} from "./index-hkxgennw.js";
|
|
@@ -18,16 +18,17 @@ import {
|
|
|
18
18
|
mergeSchemas,
|
|
19
19
|
toToolName,
|
|
20
20
|
assertUniqueToolName,
|
|
21
|
-
buildToolPresentationSchema
|
|
22
|
-
|
|
21
|
+
buildToolPresentationSchema,
|
|
22
|
+
projectedContractToolName
|
|
23
|
+
} from "./index-x2d51zay.js";
|
|
23
24
|
import {
|
|
24
25
|
toolResultFromError,
|
|
25
26
|
toolErrorFromResult
|
|
26
|
-
} from "./index-
|
|
27
|
+
} from "./index-x2rvpbtj.js";
|
|
27
28
|
import {
|
|
28
29
|
createToolRunner,
|
|
29
30
|
formatToolError
|
|
30
|
-
} from "./index-
|
|
31
|
+
} from "./index-7cn66qdk.js";
|
|
31
32
|
import {
|
|
32
33
|
isRepeatableRead
|
|
33
34
|
} from "./index-332d0m9g.js";
|
|
@@ -54,7 +55,7 @@ import {
|
|
|
54
55
|
} from "./index-9cxxfkhb.js";
|
|
55
56
|
import {
|
|
56
57
|
collectToolSurface
|
|
57
|
-
} from "./index-
|
|
58
|
+
} from "./index-kxff9e9w.js";
|
|
58
59
|
import {
|
|
59
60
|
fetchGuarded,
|
|
60
61
|
readCapped
|
|
@@ -646,15 +647,21 @@ function assertCliPoliciesResolved(commands, config) {
|
|
|
646
647
|
}
|
|
647
648
|
|
|
648
649
|
// src/tools/cli/stream-surface.ts
|
|
650
|
+
function cliStreamIdentity(serviceName, methodName, method) {
|
|
651
|
+
if (!method.stream || !method.expose?.includes("CLI"))
|
|
652
|
+
return;
|
|
653
|
+
return { name: toToolName(serviceName, methodName), descriptor: method.stream };
|
|
654
|
+
}
|
|
649
655
|
function collectCliStreams(services) {
|
|
650
656
|
const streams = new Map;
|
|
651
657
|
for (const service of services) {
|
|
652
658
|
for (const [methodName, method] of Object.entries(service.methods)) {
|
|
653
|
-
|
|
659
|
+
const identity = cliStreamIdentity(service.name, methodName, method);
|
|
660
|
+
if (identity === undefined)
|
|
654
661
|
continue;
|
|
655
|
-
const name =
|
|
662
|
+
const { name, descriptor } = identity;
|
|
656
663
|
streams.set(name, {
|
|
657
|
-
descriptor
|
|
664
|
+
descriptor,
|
|
658
665
|
tool: {
|
|
659
666
|
method,
|
|
660
667
|
name,
|
|
@@ -978,19 +985,39 @@ function classifyLongOptionToken(token) {
|
|
|
978
985
|
};
|
|
979
986
|
}
|
|
980
987
|
function readCliBooleanFlag(argv, name) {
|
|
988
|
+
const request = name === "help" || name === "schema";
|
|
981
989
|
for (const [index, token] of argv.entries()) {
|
|
982
990
|
if (token === "--")
|
|
983
991
|
break;
|
|
984
992
|
if (token === undefined)
|
|
985
993
|
continue;
|
|
994
|
+
if (name === "help" && token === "-h")
|
|
995
|
+
return true;
|
|
986
996
|
const option = classifyLongOptionToken(token);
|
|
987
997
|
if (option?.name !== name || option.globalKind !== "boolean")
|
|
988
998
|
continue;
|
|
989
|
-
|
|
999
|
+
const enabled = option.value === undefined ? separateBoolValue(argv[index + 1]) ?? true : isReservedBoolWord(option.value) && parseReservedBool(name, option.value);
|
|
1000
|
+
if (enabled || !request)
|
|
1001
|
+
return enabled;
|
|
990
1002
|
}
|
|
991
1003
|
return false;
|
|
992
1004
|
}
|
|
1005
|
+
function preserveCliBooleanBoundary(prefix, next) {
|
|
1006
|
+
if (separateBoolValue(next) === undefined)
|
|
1007
|
+
return;
|
|
1008
|
+
const last = prefix.at(-1);
|
|
1009
|
+
const option = last === undefined ? undefined : classifyLongOptionToken(last);
|
|
1010
|
+
if (option?.globalKind === "boolean" && !option.inline) {
|
|
1011
|
+
prefix[prefix.length - 1] = last === "--help" ? "-h" : `${last}=true`;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
993
1014
|
var HELP_TOKENS = new Set(["--help", "-h", "help"]);
|
|
1015
|
+
function isCliVersionToken(token) {
|
|
1016
|
+
return token === "--version" || token === "version";
|
|
1017
|
+
}
|
|
1018
|
+
function isReservedCliCommandName(name) {
|
|
1019
|
+
return name === "--" || HELP_TOKENS.has(name) || isCliVersionToken(name) || classifyLongOptionToken(name)?.globalKind !== undefined;
|
|
1020
|
+
}
|
|
994
1021
|
function helpFilterFrom(token, rest) {
|
|
995
1022
|
if (token?.startsWith("--help=")) {
|
|
996
1023
|
const value = token.slice("--help=".length).trim();
|
|
@@ -1003,34 +1030,50 @@ function helpFilterFrom(token, rest) {
|
|
|
1003
1030
|
const next = rest[0];
|
|
1004
1031
|
return next !== undefined && !next.startsWith("-") ? next : undefined;
|
|
1005
1032
|
}
|
|
1033
|
+
function isTopHelpOption(token) {
|
|
1034
|
+
return token === "--help" || token === "-h" || token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
|
|
1035
|
+
}
|
|
1036
|
+
function leadingGlobalCount(argv, hasDefault) {
|
|
1037
|
+
let index = 0;
|
|
1038
|
+
while (index < argv.length) {
|
|
1039
|
+
const token = argv[index];
|
|
1040
|
+
if (token === undefined || isTopHelpOption(token))
|
|
1041
|
+
break;
|
|
1042
|
+
const option = classifyLongOptionToken(token);
|
|
1043
|
+
if (!option?.globalKind)
|
|
1044
|
+
break;
|
|
1045
|
+
index++;
|
|
1046
|
+
if (option.inline)
|
|
1047
|
+
continue;
|
|
1048
|
+
const value = argv[index];
|
|
1049
|
+
if (value === undefined)
|
|
1050
|
+
break;
|
|
1051
|
+
if (option.globalKind === "boolean") {
|
|
1052
|
+
if (separateBoolValue(value) !== undefined)
|
|
1053
|
+
index++;
|
|
1054
|
+
} else {
|
|
1055
|
+
if (value === "--" || value === "--help" || value === "-h" || value === "--version" || hasDefault && value === "version") {
|
|
1056
|
+
break;
|
|
1057
|
+
}
|
|
1058
|
+
if (hasDefault || !classifyLongOptionToken(value)?.globalKind)
|
|
1059
|
+
index++;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
return index;
|
|
1063
|
+
}
|
|
1006
1064
|
function routeCliArgv2(argv, defaultCommand) {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1065
|
+
const index = leadingGlobalCount(argv, defaultCommand !== undefined);
|
|
1066
|
+
const token = argv[index];
|
|
1067
|
+
if (token === "--" && (index > 0 || defaultCommand !== undefined)) {
|
|
1010
1068
|
return {
|
|
1011
|
-
|
|
1012
|
-
commandArgv,
|
|
1069
|
+
commandArgv: [],
|
|
1013
1070
|
topLevelHelp: false,
|
|
1014
1071
|
version: false,
|
|
1015
|
-
|
|
1072
|
+
error: 'A command is required before "--"'
|
|
1016
1073
|
};
|
|
1017
1074
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
while (index < argv.length) {
|
|
1021
|
-
const token = argv[index];
|
|
1022
|
-
if (token === undefined)
|
|
1023
|
-
break;
|
|
1024
|
-
if (token === "--") {
|
|
1025
|
-
return {
|
|
1026
|
-
commandArgv: [],
|
|
1027
|
-
topLevelHelp: false,
|
|
1028
|
-
version: false,
|
|
1029
|
-
error: 'A command is required before "--"'
|
|
1030
|
-
};
|
|
1031
|
-
}
|
|
1032
|
-
const inlineHelpFilter = token.startsWith("--help=") && !isReservedBoolWord(token.slice("--help=".length));
|
|
1033
|
-
if (token === "--help" || token === "-h" || inlineHelpFilter) {
|
|
1075
|
+
if (defaultCommand !== undefined) {
|
|
1076
|
+
if (token !== undefined && isTopHelpOption(token)) {
|
|
1034
1077
|
const helpFilter = helpFilterFrom(token, argv.slice(index + 1));
|
|
1035
1078
|
return {
|
|
1036
1079
|
commandArgv: [],
|
|
@@ -1039,80 +1082,30 @@ function routeCliArgv2(argv, defaultCommand) {
|
|
|
1039
1082
|
...helpFilter !== undefined && { helpFilter }
|
|
1040
1083
|
};
|
|
1041
1084
|
}
|
|
1042
|
-
if (token
|
|
1085
|
+
if (isCliVersionToken(token)) {
|
|
1043
1086
|
return { commandArgv: [], topLevelHelp: false, version: true };
|
|
1044
1087
|
}
|
|
1045
|
-
if (
|
|
1046
|
-
return {
|
|
1047
|
-
command: token,
|
|
1048
|
-
commandArgv: [...globals, ...argv.slice(index + 1)],
|
|
1049
|
-
topLevelHelp: false,
|
|
1050
|
-
version: false
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
if (!token.startsWith("--")) {
|
|
1088
|
+
if (token === undefined || token.startsWith("-") && token !== "-") {
|
|
1054
1089
|
return {
|
|
1055
1090
|
command: defaultCommand,
|
|
1056
|
-
commandArgv:
|
|
1091
|
+
commandArgv: argv.slice(),
|
|
1057
1092
|
topLevelHelp: false,
|
|
1058
1093
|
version: false
|
|
1059
1094
|
};
|
|
1060
1095
|
}
|
|
1061
|
-
const option = classifyLongOptionToken(token);
|
|
1062
|
-
if (!option) {
|
|
1063
|
-
return {
|
|
1064
|
-
command: defaultCommand,
|
|
1065
|
-
commandArgv: [...globals, ...argv.slice(index)],
|
|
1066
|
-
topLevelHelp: false,
|
|
1067
|
-
version: false
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
if (option.globalKind === "boolean") {
|
|
1071
|
-
globals.push(token);
|
|
1072
|
-
index += 1;
|
|
1073
|
-
const next = argv[index];
|
|
1074
|
-
if (option.value === undefined && next !== undefined && separateBoolValue(next) !== undefined) {
|
|
1075
|
-
globals.push(next);
|
|
1076
|
-
index += 1;
|
|
1077
|
-
}
|
|
1078
|
-
continue;
|
|
1079
|
-
}
|
|
1080
|
-
if (option.globalKind === "value") {
|
|
1081
|
-
globals.push(token);
|
|
1082
|
-
if (!option.inline) {
|
|
1083
|
-
const value = argv[index + 1];
|
|
1084
|
-
if (value === "--help" || value === "-h") {
|
|
1085
|
-
const helpFilter = helpFilterFrom(value, argv.slice(index + 2));
|
|
1086
|
-
return {
|
|
1087
|
-
commandArgv: [],
|
|
1088
|
-
topLevelHelp: true,
|
|
1089
|
-
version: false,
|
|
1090
|
-
...helpFilter !== undefined && { helpFilter }
|
|
1091
|
-
};
|
|
1092
|
-
}
|
|
1093
|
-
if (value === "--version" || value === "version") {
|
|
1094
|
-
return { commandArgv: [], topLevelHelp: false, version: true };
|
|
1095
|
-
}
|
|
1096
|
-
if (value !== undefined)
|
|
1097
|
-
globals.push(value);
|
|
1098
|
-
index += value === undefined ? 1 : 2;
|
|
1099
|
-
} else {
|
|
1100
|
-
index += 1;
|
|
1101
|
-
}
|
|
1102
|
-
continue;
|
|
1103
|
-
}
|
|
1104
|
-
return {
|
|
1105
|
-
command: defaultCommand,
|
|
1106
|
-
commandArgv: [...globals, ...argv.slice(index)],
|
|
1107
|
-
topLevelHelp: false,
|
|
1108
|
-
version: false
|
|
1109
|
-
};
|
|
1110
1096
|
}
|
|
1097
|
+
const commandIndex = token === undefined ? 0 : index;
|
|
1098
|
+
const command = argv[commandIndex];
|
|
1099
|
+
const rest = argv.slice(commandIndex + 1);
|
|
1100
|
+
const prefix = argv.slice(0, commandIndex);
|
|
1101
|
+
preserveCliBooleanBoundary(prefix, rest[0]);
|
|
1102
|
+
const helpFilter = commandIndex > 0 || defaultCommand === undefined ? helpFilterFrom(command, rest) : undefined;
|
|
1111
1103
|
return {
|
|
1112
|
-
command
|
|
1113
|
-
commandArgv:
|
|
1104
|
+
command,
|
|
1105
|
+
commandArgv: prefix.concat(rest),
|
|
1114
1106
|
topLevelHelp: false,
|
|
1115
|
-
version: false
|
|
1107
|
+
version: false,
|
|
1108
|
+
...helpFilter !== undefined && { helpFilter }
|
|
1116
1109
|
};
|
|
1117
1110
|
}
|
|
1118
1111
|
|
|
@@ -1539,11 +1532,27 @@ function renderCommandHelp(name, command, descriptor, applicationOptions = []) {
|
|
|
1539
1532
|
}
|
|
1540
1533
|
|
|
1541
1534
|
// src/tools/cli/command-shape.ts
|
|
1535
|
+
function assertCliCommandName(name) {
|
|
1536
|
+
if (isReservedCliCommandName(name)) {
|
|
1537
|
+
throw new Error(`[stitchkit] CLI command "${name}" is reserved. Rename the command to a word outside the framework option syntax.`);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
function assertStaticCliCommandNames(services, runtimeTools) {
|
|
1541
|
+
for (const tool of runtimeTools) {
|
|
1542
|
+
if (tool.transports?.includes("CLI"))
|
|
1543
|
+
assertCliCommandName(tool.name);
|
|
1544
|
+
}
|
|
1545
|
+
for (const service of services) {
|
|
1546
|
+
for (const [key, method] of Object.entries(service.methods)) {
|
|
1547
|
+
const name = projectedContractToolName(service.name, key, method, "CLI") ?? cliStreamIdentity(service.name, key, method)?.name;
|
|
1548
|
+
if (name !== undefined)
|
|
1549
|
+
assertCliCommandName(name);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1542
1553
|
function commandShapeIssue(name, descriptor, exists, passthroughField, applicationGlobals = new Set) {
|
|
1543
1554
|
assertUniqueToolName(name, exists, "CLI command");
|
|
1544
|
-
|
|
1545
|
-
throw new Error(`[stitchkit] CLI command "${name}" is reserved`);
|
|
1546
|
-
}
|
|
1555
|
+
assertCliCommandName(name);
|
|
1547
1556
|
if (passthroughField !== undefined && descriptor.aliases.has(passthroughField)) {
|
|
1548
1557
|
throw new Error(`[stitchkit] CLI command "${name}" cannot alias passthrough field "${passthroughField}"`);
|
|
1549
1558
|
}
|
|
@@ -1566,9 +1575,8 @@ async function buildManagedSurface(session, typedGlobals, forExecution) {
|
|
|
1566
1575
|
authPromise ??= (async () => config.resolveAuth ? await config.resolveAuth(typedGlobals) : await config.auth)();
|
|
1567
1576
|
return authPromise;
|
|
1568
1577
|
};
|
|
1569
|
-
const dynamicSurface = typeof config.services === "function" || typeof config.runtimeTools === "function";
|
|
1570
1578
|
let auth;
|
|
1571
|
-
if (
|
|
1579
|
+
if (session.hasManagedFactory || forExecution) {
|
|
1572
1580
|
try {
|
|
1573
1581
|
auth = await resolveIdentity();
|
|
1574
1582
|
} catch (error) {
|
|
@@ -1986,6 +1994,7 @@ function extractCliGlobalOptions2(argv, schema) {
|
|
|
1986
1994
|
}
|
|
1987
1995
|
}
|
|
1988
1996
|
appendCliFieldValue(raw, jsonFields, field.name, value, info, field.json);
|
|
1997
|
+
preserveCliBooleanBoundary(rest, argv[i + 1]);
|
|
1989
1998
|
}
|
|
1990
1999
|
const args = {};
|
|
1991
2000
|
for (const [name, values] of raw) {
|
|
@@ -2104,6 +2113,7 @@ function createCliSession(config, io) {
|
|
|
2104
2113
|
}
|
|
2105
2114
|
const nativeCommands = new Map;
|
|
2106
2115
|
const nativeHelp = new Map;
|
|
2116
|
+
assertStaticCliCommandNames(typeof config.services === "function" ? [] : config.services ?? [], typeof config.runtimeTools === "function" ? [] : config.runtimeTools ?? []);
|
|
2107
2117
|
for (const definition of config.commands ?? []) {
|
|
2108
2118
|
const descriptor = applyCliPresentationPolicy(definition.name, nativeDescriptor(definition), config);
|
|
2109
2119
|
const issue = commandShapeIssue(definition.name, descriptor, nativeCommands.has(definition.name), config.passthrough?.[definition.name], applicationGlobalNames);
|
|
@@ -2118,7 +2128,8 @@ function createCliSession(config, io) {
|
|
|
2118
2128
|
applicationOptions,
|
|
2119
2129
|
applicationGlobalNames,
|
|
2120
2130
|
nativeCommands,
|
|
2121
|
-
nativeHelp
|
|
2131
|
+
nativeHelp,
|
|
2132
|
+
hasManagedFactory: typeof config.services === "function" || typeof config.runtimeTools === "function"
|
|
2122
2133
|
};
|
|
2123
2134
|
}
|
|
2124
2135
|
function resolveCliRoute(session, argv) {
|
|
@@ -2147,28 +2158,26 @@ function resolveCliRoute(session, argv) {
|
|
|
2147
2158
|
return;
|
|
2148
2159
|
}
|
|
2149
2160
|
const { command, commandArgv } = route;
|
|
2150
|
-
if (
|
|
2161
|
+
if (config.defaultCommand === undefined && session.hasManagedFactory && command !== undefined && command !== routableArgv[0] && session.nativeCommands.has(command)) {
|
|
2162
|
+
stderr(`Managed command names are unknown before native dispatch. Put "${config.name} ${command}" first and keep options with their values. ` + `If moving a bare boolean flag next to positional true or false, spell the flag explicitly (for example, --dry-run=true).
|
|
2163
|
+
`);
|
|
2164
|
+
exit(2);
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
if (route.version || isCliVersionToken(command)) {
|
|
2151
2168
|
stdout(`${config.name} ${config.version}
|
|
2152
2169
|
`);
|
|
2153
2170
|
exit(0);
|
|
2154
2171
|
return;
|
|
2155
2172
|
}
|
|
2156
|
-
const
|
|
2157
|
-
const
|
|
2158
|
-
if (token === `--${name}` || name === "help" && token === "-h")
|
|
2159
|
-
return true;
|
|
2160
|
-
const option = classifyLongOptionToken(token);
|
|
2161
|
-
return option?.name === name && option.value !== undefined && isReservedBoolWord(option.value) && parseReservedBool(name, option.value);
|
|
2162
|
-
});
|
|
2163
|
-
const helpRequested = asked("help");
|
|
2164
|
-
const schemaRequested = !helpRequested && asked("schema");
|
|
2173
|
+
const helpRequested = readCliBooleanFlag(commandArgv, "help");
|
|
2174
|
+
const schemaRequested = !helpRequested && readCliBooleanFlag(commandArgv, "schema");
|
|
2165
2175
|
return {
|
|
2166
2176
|
globals,
|
|
2167
2177
|
typedGlobals,
|
|
2168
2178
|
route,
|
|
2169
2179
|
command,
|
|
2170
2180
|
commandArgv,
|
|
2171
|
-
beforeSeparator,
|
|
2172
2181
|
quiet: readCliBooleanFlag(route.topLevelHelp ? routableArgv : commandArgv, "quiet"),
|
|
2173
2182
|
helpRequested,
|
|
2174
2183
|
schemaRequested
|
|
@@ -2543,13 +2552,13 @@ async function pollUntilDone2(params) {
|
|
|
2543
2552
|
async function runManagedInvocation(session, route) {
|
|
2544
2553
|
const { config } = session;
|
|
2545
2554
|
const { stdout, stderr, exit } = session.io;
|
|
2546
|
-
const { command, helpRequested, schemaRequested
|
|
2555
|
+
const { command, helpRequested, schemaRequested } = route;
|
|
2547
2556
|
const topLevelHelp = route.route.topLevelHelp || command === undefined || command === "help" || command === "--help" || command === "-h" || command.startsWith("--help=") && !isReservedBoolWord(command.slice("--help=".length));
|
|
2548
2557
|
const managed = await buildManagedSurface(session, route.typedGlobals, !topLevelHelp && !helpRequested && !schemaRequested);
|
|
2549
2558
|
if (topLevelHelp)
|
|
2550
2559
|
return respondTopLevelHelp(session, route, managed);
|
|
2551
2560
|
if (!managed.resolved) {
|
|
2552
|
-
return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config,
|
|
2561
|
+
return exit(emitResult2(managed.failure, { stdout, stderr }, emitOptionsFor(config, readCliBooleanFlag(route.commandArgv, "json"), command ?? config.name)));
|
|
2553
2562
|
}
|
|
2554
2563
|
return runManagedCommand(session, route, command, managed);
|
|
2555
2564
|
}
|
|
@@ -1039,6 +1039,12 @@ function assertProjectedName(name, serviceName, action, transport, derived) {
|
|
|
1039
1039
|
}
|
|
1040
1040
|
assertToolName(name, serviceName, action);
|
|
1041
1041
|
}
|
|
1042
|
+
function projectedContractToolName(serviceName, methodName, method, transport) {
|
|
1043
|
+
const exposed = method.expose?.includes(transport) ?? transport !== "CLI";
|
|
1044
|
+
if (!exposed || isHttpOnlyEndpoint(method))
|
|
1045
|
+
return;
|
|
1046
|
+
return method.toolName ?? toToolName(serviceName, methodName);
|
|
1047
|
+
}
|
|
1042
1048
|
function projectToolSurface(surface, transport, config = {}) {
|
|
1043
1049
|
const projected = [];
|
|
1044
1050
|
const names = new Set;
|
|
@@ -1058,16 +1064,9 @@ function projectToolSurface(surface, transport, config = {}) {
|
|
|
1058
1064
|
};
|
|
1059
1065
|
for (const service of surface.services ?? []) {
|
|
1060
1066
|
for (const [methodName, method] of Object.entries(service.methods)) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
continue;
|
|
1064
|
-
} else if (method.expose && !method.expose.includes(transport)) {
|
|
1067
|
+
const name = projectedContractToolName(service.name, methodName, method, transport);
|
|
1068
|
+
if (name === undefined)
|
|
1065
1069
|
continue;
|
|
1066
|
-
}
|
|
1067
|
-
if (isHttpOnlyEndpoint(method)) {
|
|
1068
|
-
continue;
|
|
1069
|
-
}
|
|
1070
|
-
const name = method.toolName ?? toToolName(service.name, methodName);
|
|
1071
1070
|
if (config.assertNames ?? true) {
|
|
1072
1071
|
assertProjectedName(name, service.name, methodName, transport, !method.toolName);
|
|
1073
1072
|
}
|
|
@@ -1216,4 +1215,4 @@ function prepareProjectedMcpTools(tools, config = {}) {
|
|
|
1216
1215
|
return prepared;
|
|
1217
1216
|
}
|
|
1218
1217
|
|
|
1219
|
-
export { toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, objectShapeKeys, rebuildObject, mergeSchemas, staticInputRounds, validateMcpRoundPolicy, validateResolvedInputRounds, assertToolName, toToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS2, findNonPortableFormats2, flattenToolJsonSchema2, buildToolPresentationSchema, presentationMetadata, findUntypedProperties2, assertToolExtensionCompatible, projectRuntimeTool, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
|
|
1218
|
+
export { toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, objectShapeKeys, rebuildObject, mergeSchemas, staticInputRounds, validateMcpRoundPolicy, validateResolvedInputRounds, assertToolName, toToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS2, findNonPortableFormats2, flattenToolJsonSchema2, buildToolPresentationSchema, presentationMetadata, findUntypedProperties2, assertToolExtensionCompatible, projectRuntimeTool, projectedContractToolName, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
|
|
@@ -3,13 +3,25 @@ export interface CoalescedTask {
|
|
|
3
3
|
readonly running: boolean;
|
|
4
4
|
/** A trigger arrived that no pass has served yet. */
|
|
5
5
|
readonly pending: boolean;
|
|
6
|
+
/** Milliseconds until the pass after a failure may start; `0` when nothing holds it. */
|
|
7
|
+
readonly retryInMs: number;
|
|
6
8
|
trigger(): void;
|
|
7
9
|
pauseRetry(): void;
|
|
8
10
|
close(): void;
|
|
9
11
|
}
|
|
10
|
-
/**
|
|
12
|
+
/** What a pass that neither succeeded nor failed returns: its work was abandoned. */
|
|
13
|
+
export declare const ABANDONED_PASS: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* One job per key; hints during work become one trailing pass, failures retain retry.
|
|
16
|
+
*
|
|
17
|
+
* The pause after a failure belongs to the job, not to whoever is asking: a
|
|
18
|
+
* paused retry keeps the moment it is due, and a trigger before that moment
|
|
19
|
+
* waits for it instead of running at once. A pass that returns
|
|
20
|
+
* {@link ABANDONED_PASS} stays dirty and leaves the failure count alone.
|
|
21
|
+
*/
|
|
11
22
|
export declare function createCoalescedTask(config: {
|
|
12
|
-
|
|
23
|
+
/** Resolves with {@link ABANDONED_PASS} for abandoned work; any other value is a completed pass. */
|
|
24
|
+
run(): Promise<unknown>;
|
|
13
25
|
active(): boolean;
|
|
14
26
|
onError(error: unknown): void;
|
|
15
27
|
backoff: BackoffPolicy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coalesced-task.d.ts","sourceRoot":"","sources":["../../src/internal/coalesced-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAC;AAE9D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,IAAI,IAAI,CAAC;IACnB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,
|
|
1
|
+
{"version":3,"file":"coalesced-task.d.ts","sourceRoot":"","sources":["../../src/internal/coalesced-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAC;AAE9D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,wFAAwF;IACxF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,IAAI,IAAI,CAAC;IACnB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,qFAAqF;AACrF,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,oGAAoG;IACpG,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,MAAM,IAAI,OAAO,CAAC;IAClB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;CACxB,GAAG,aAAa,CAyEhB"}
|