@kitman-sh/cli 0.10.71 → 0.10.72

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.
Files changed (29) hide show
  1. package/dist/{chunk-9e452fhe.js → chunk-030xsst1.js} +266 -111
  2. package/dist/{chunk-hr9vd6dj.js → chunk-290se4bt.js} +3 -3
  3. package/dist/{chunk-h89p59p6.js → chunk-2es1djpn.js} +8 -8
  4. package/dist/{chunk-y7p921rs.js → chunk-61by5f18.js} +17 -17
  5. package/dist/{chunk-dk0ftqwg.js → chunk-7672g0fj.js} +28 -177
  6. package/dist/{chunk-g4xsa9ks.js → chunk-7g4e5fsj.js} +177 -52
  7. package/dist/{chunk-csbf77zs.js → chunk-7sm45hhc.js} +6 -6
  8. package/dist/{chunk-x1zqfxve.js → chunk-7wenq6ew.js} +4 -4
  9. package/dist/{chunk-q3c7vmby.js → chunk-b63rssdn.js} +1 -1
  10. package/dist/{chunk-5n121vsj.js → chunk-cefprsjj.js} +4 -4
  11. package/dist/{chunk-cmatdpfy.js → chunk-cj3ef3pv.js} +6 -6
  12. package/dist/{chunk-zwec6t49.js → chunk-d2fxfv0j.js} +7 -7
  13. package/dist/{chunk-tkmp48ha.js → chunk-g8b2z9jn.js} +4 -4
  14. package/dist/chunk-gngg8j56.js +202 -0
  15. package/dist/{chunk-4wqjxfbv.js → chunk-hxm3bvpn.js} +5 -5
  16. package/dist/{chunk-v01c0k6j.js → chunk-nhd7dh79.js} +1 -1
  17. package/dist/{chunk-gxnpdpjz.js → chunk-pnsqttt3.js} +7 -7
  18. package/dist/{chunk-1rry0tsn.js → chunk-pyt2zrwc.js} +2 -2
  19. package/dist/{chunk-rrnee9mk.js → chunk-se79jbha.js} +1 -1
  20. package/dist/{chunk-60333x3q.js → chunk-tv94e132.js} +5 -5
  21. package/dist/{chunk-vs10kwdr.js → chunk-vd8f9brg.js} +10 -10
  22. package/dist/{chunk-d3ksv8y1.js → chunk-vrt08dk9.js} +60 -60
  23. package/dist/{chunk-rm83dbpv.js → chunk-w6qjh6q5.js} +2 -2
  24. package/dist/chunk-wssfts9s.js +16 -0
  25. package/dist/egress-proxy.ts +51 -4
  26. package/dist/index.js +4 -4
  27. package/package.json +1 -1
  28. package/dist/chunk-1w81w56v.js +0 -109
  29. package/dist/chunk-wtpwkjws.js +0 -100
@@ -0,0 +1,202 @@
1
+ // @bun
2
+ import {
3
+ getOrUndefined,
4
+ flatMap,
5
+ toArray,
6
+ decodeUnknownOption,
7
+ optionalKey,
8
+ String4,
9
+ Struct,
10
+ Record,
11
+ ArraySchema,
12
+ decodeJsonStringOption,
13
+ encodeUnknownJsonStringSync
14
+ } from "./chunk-vrt08dk9.js";
15
+ import {
16
+ replaceSecretReferences,
17
+ secretReferencesIn
18
+ } from "./chunk-se79jbha.js";
19
+
20
+ // packages/agent-runtime/src/srt-step.ts
21
+ import { SandboxRuntimeConfigSchema } from "@anthropic-ai/sandbox-runtime";
22
+ import { spawn } from "child_process";
23
+ import { readFileSync as readFileSync2 } from "fs";
24
+
25
+ // packages/agent-runtime/src/secret-proxy.ts
26
+ import { appendFileSync, readFileSync, renameSync, writeFileSync } from "fs";
27
+
28
+ // packages/agent-runtime/src/egress-proxy.ts
29
+ var egressAllowed = (hosts, host, port) => {
30
+ const target = host.toLowerCase();
31
+ return hosts.some((entry) => {
32
+ const [name = "", entryPort] = entry.toLowerCase().split(":");
33
+ if (entryPort !== undefined && Number(entryPort) !== port)
34
+ return false;
35
+ return name.startsWith("*.") ? target.endsWith(name.slice(1)) : target === name;
36
+ });
37
+ };
38
+ if (false)
39
+ ;
40
+
41
+ // packages/agent-runtime/src/secret-proxy.ts
42
+ var basicPrefix = /^basic\s+/i;
43
+ var basicCredential = (value) => {
44
+ if (!basicPrefix.test(value))
45
+ return;
46
+ const decoded = Buffer.from(value.replace(basicPrefix, ""), "base64").toString("utf8");
47
+ return secretReferencesIn(decoded).length === 0 ? undefined : decoded;
48
+ };
49
+ var referencesInHeader = (value) => [
50
+ ...new Set([...secretReferencesIn(value), ...secretReferencesIn(basicCredential(value) ?? "")])
51
+ ];
52
+ var swapped = (value, registry) => {
53
+ const swap = (reference) => registry[reference]?.value ?? reference;
54
+ const basic = basicCredential(value);
55
+ return basic === undefined ? replaceSecretReferences(value, swap) : `Basic ${Buffer.from(replaceSecretReferences(basic, swap)).toString("base64")}`;
56
+ };
57
+ var decideSecretRequest = (request, readRegistry) => {
58
+ const carrying = request.headers.flatMap(([name, value]) => {
59
+ const references = referencesInHeader(value);
60
+ return references.length === 0 ? [] : [{ name, value, references }];
61
+ });
62
+ const inTarget = secretReferencesIn(request.target);
63
+ if (carrying.length === 0 && inTarget.length === 0)
64
+ return { action: "allow" };
65
+ const registry = readRegistry();
66
+ const refusals = [
67
+ ...inTarget.map((reference) => ({
68
+ reference,
69
+ host: request.host,
70
+ reason: "A reference is swapped only in a header, never in a URL."
71
+ })),
72
+ ...[...new Set(carrying.flatMap((header) => header.references))].flatMap((reference) => {
73
+ const entry = registry?.[reference];
74
+ const reason = entry === undefined ? "The reference is unknown or revoked." : request.scheme !== "https" ? "A reference is swapped only over HTTPS." : !egressAllowed(entry.hosts, request.host, request.port) ? `The Secret may be sent only to ${entry.hosts.join(", ")}.` : undefined;
75
+ return reason === undefined ? [] : [{ reference, host: request.host, reason }];
76
+ })
77
+ ];
78
+ if (refusals.length > 0)
79
+ return {
80
+ action: "deny",
81
+ reason: `Kitman refused this request: ${refusals.map((refusal) => `${refusal.reference}: ${refusal.reason}`).join(" ")}`,
82
+ refusals
83
+ };
84
+ const names = new Set(carrying.map((header) => header.name.toLowerCase()));
85
+ return {
86
+ action: "allow",
87
+ setHeaders: request.headers.filter(([name]) => names.has(name.toLowerCase())).map(([name, value]) => [name, registry === undefined ? value : swapped(value, registry)])
88
+ };
89
+ };
90
+ var Registry = Record(String4, Struct({ value: String4, hosts: ArraySchema(String4) }));
91
+ var Refusal = Struct({
92
+ reference: optionalKey(String4),
93
+ host: String4,
94
+ reason: String4
95
+ });
96
+ var readSecretRegistry = (file) => {
97
+ try {
98
+ return getOrUndefined(flatMap(decodeJsonStringOption(readFileSync(file, "utf8")), decodeUnknownOption(Registry)));
99
+ } catch {
100
+ return;
101
+ }
102
+ };
103
+ var writeSecretRegistry = (file, registry) => {
104
+ const next = `${file}.next`;
105
+ writeFileSync(next, encodeUnknownJsonStringSync(registry), { mode: 384 });
106
+ renameSync(next, file);
107
+ };
108
+ var secretRefusalLog = (registryFile) => `${registryFile}.refused`;
109
+ var appendSecretRefusals = (registryFile, refusals) => appendFileSync(secretRefusalLog(registryFile), refusals.map((refusal) => `${encodeUnknownJsonStringSync(refusal)}
110
+ `).join(""), { mode: 384 });
111
+ var parseSecretRefusals = (text) => text.split(`
112
+ `).flatMap((line) => toArray(flatMap(decodeJsonStringOption(line), decodeUnknownOption(Refusal))));
113
+
114
+ // packages/agent-runtime/src/srt-step.ts
115
+ var secretFilter2 = (registryFile) => (request, info) => {
116
+ const url = new URL(request.url);
117
+ const decision = decideSecretRequest({
118
+ headers: [...request.headers.entries()],
119
+ host: info?.target?.host ?? url.hostname,
120
+ port: info?.target?.port ?? (url.port === "" ? url.protocol === "https:" ? 443 : 80 : Number(url.port)),
121
+ target: info?.requestTarget ?? `${url.pathname}${url.search}`,
122
+ scheme: info?.scheme ?? (url.protocol === "https:" ? "https" : "http")
123
+ }, () => readSecretRegistry(registryFile));
124
+ if (decision.action === "allow")
125
+ return Promise.resolve(decision.setHeaders === undefined ? { action: "allow" } : { action: "allow", setHeaders: decision.setHeaders.map(([name, value]) => [name, value]) });
126
+ try {
127
+ appendSecretRefusals(registryFile, decision.refusals);
128
+ } catch {}
129
+ return Promise.resolve({ action: "deny", status: 403, mark: "secret-refused", reason: decision.reason });
130
+ };
131
+ var stepSandboxConfig = (settings, registryFile) => {
132
+ const parsed = SandboxRuntimeConfigSchema.safeParse({
133
+ ...settings,
134
+ network: { ...settings.network, tlsTerminate: {}, refuseOpaqueTunnels: true }
135
+ });
136
+ return parsed.success ? {
137
+ success: true,
138
+ data: { ...parsed.data, network: { ...parsed.data.network, filterRequest: secretFilter2(registryFile) } }
139
+ } : parsed;
140
+ };
141
+ var opaqueTunnelRefusal2 = "A tunnel Kitman cannot see into, such as SOCKS or a CONNECT without TLS, is refused.";
142
+ var opaqueConnectReasons = "tunnel carries no TLS|this proxy does not tunnel CONNECTs";
143
+ var isOpaqueConnectReason2 = (reason) => new RegExp(`^(?:${opaqueConnectReasons})`).test(reason);
144
+ var opaqueTunnel = new RegExp(`^deny (?:socks-tunnel (\\S+) \\(refuseOpaqueTunnels\\)|http-request CONNECT (\\S+) \\((?:${opaqueConnectReasons})[^)]*\\))`);
145
+ var refusedTunnelHost = (line) => {
146
+ const match = opaqueTunnel.exec(line);
147
+ return match === null ? undefined : match[1] ?? match[2];
148
+ };
149
+ var shellQuoted = (arg) => `'${arg.replaceAll("'", "'\\''")}'`;
150
+ var argument = (args, flag) => {
151
+ const at = args.indexOf(flag);
152
+ return at === -1 ? undefined : args[at + 1];
153
+ };
154
+ var runSrtStep2 = async (args) => {
155
+ const separator = args.indexOf("--");
156
+ const settingsFile = argument(args, "--settings");
157
+ const registryFile = argument(args, "--secrets");
158
+ const command = separator === -1 ? [] : args.slice(separator + 1);
159
+ if (settingsFile === undefined || registryFile === undefined || command.length === 0) {
160
+ console.error("Usage: srt-step --settings <file> --secrets <registry> -- <command>");
161
+ process.exit(2);
162
+ }
163
+ delete process.env.SRT_DEBUG;
164
+ const { SandboxManager } = await import("@anthropic-ai/sandbox-runtime");
165
+ const config = stepSandboxConfig(JSON.parse(readFileSync2(settingsFile, "utf8")), registryFile);
166
+ if (!config.success) {
167
+ console.error(`srt-step: ${settingsFile} does not hold a valid srt config: ${config.error.message}`);
168
+ process.exit(2);
169
+ }
170
+ await SandboxManager.initialize(config.data);
171
+ const recorded = new WeakSet;
172
+ SandboxManager.getSandboxViolationStore().subscribe((violations) => {
173
+ const refusals = violations.flatMap((violation) => {
174
+ if (recorded.has(violation))
175
+ return [];
176
+ recorded.add(violation);
177
+ const host = refusedTunnelHost(violation.line);
178
+ return host === undefined ? [] : [{ host, reason: opaqueTunnelRefusal2 }];
179
+ });
180
+ if (refusals.length === 0)
181
+ return;
182
+ try {
183
+ appendSecretRefusals(registryFile, refusals);
184
+ } catch {}
185
+ });
186
+ const child = spawn(await SandboxManager.wrapWithSandbox(command.map(shellQuoted).join(" ")), {
187
+ shell: true,
188
+ stdio: "inherit"
189
+ });
190
+ child.on("exit", (code, signal) => {
191
+ SandboxManager.cleanupAfterCommand();
192
+ process.exit(signal === null ? code ?? 0 : signal === "SIGINT" || signal === "SIGTERM" ? 0 : 1);
193
+ });
194
+ child.on("error", (error) => {
195
+ console.error(`Failed to execute command: ${error.message}`);
196
+ process.exit(1);
197
+ });
198
+ for (const signal of ["SIGINT", "SIGTERM"])
199
+ process.on(signal, () => child.kill(signal));
200
+ };
201
+
202
+ export { egressAllowed, writeSecretRegistry, secretRefusalLog, appendSecretRefusals, parseSecretRefusals, secretFilter2, opaqueTunnelRefusal2, isOpaqueConnectReason2, runSrtStep2 };
@@ -23,24 +23,24 @@ import {
23
23
  fnUntraced,
24
24
  encodePrettyJsonString,
25
25
  decodeJsonStringSync
26
- } from "./chunk-d3ksv8y1.js";
26
+ } from "./chunk-vrt08dk9.js";
27
27
  import {
28
28
  isJsonObject,
29
29
  isString
30
- } from "./chunk-v01c0k6j.js";
30
+ } from "./chunk-nhd7dh79.js";
31
31
  import {
32
32
  FileSystem,
33
33
  Path,
34
34
  optionalEnv
35
- } from "./chunk-dk0ftqwg.js";
35
+ } from "./chunk-7672g0fj.js";
36
36
  import {
37
37
  AgentHarnessIds,
38
38
  sha2562,
39
39
  runCommand2
40
- } from "./chunk-9e452fhe.js";
40
+ } from "./chunk-030xsst1.js";
41
41
  import {
42
42
  NpmRegistry
43
- } from "./chunk-hr9vd6dj.js";
43
+ } from "./chunk-290se4bt.js";
44
44
 
45
45
  // packages/agent-runtime/src/config-convergence.ts
46
46
  var writeAgentEnvironmentConfigFile2 = fnUntraced(function* (file, content, keep = {}) {
@@ -8,7 +8,7 @@ import {
8
8
  isFunction2,
9
9
  isUndefined2,
10
10
  isObjectOrArray
11
- } from "./chunk-d3ksv8y1.js";
11
+ } from "./chunk-vrt08dk9.js";
12
12
 
13
13
  // packages/core/src/runtime-type.ts
14
14
  var UnsafeJsonObjectKeys = new Set(["__proto__", "constructor", "prototype"]);
@@ -4,13 +4,13 @@ import {
4
4
  runnerRpcUrl2,
5
5
  makeRunnerRpcClient2,
6
6
  makeProgramRpcClient2
7
- } from "./chunk-5n121vsj.js";
8
- import"./chunk-cmatdpfy.js";
9
- import"./chunk-9e452fhe.js";
10
- import"./chunk-rrnee9mk.js";
11
- import"./chunk-v01c0k6j.js";
12
- import"./chunk-dk0ftqwg.js";
13
- import"./chunk-d3ksv8y1.js";
7
+ } from "./chunk-cefprsjj.js";
8
+ import"./chunk-cj3ef3pv.js";
9
+ import"./chunk-030xsst1.js";
10
+ import"./chunk-se79jbha.js";
11
+ import"./chunk-nhd7dh79.js";
12
+ import"./chunk-7672g0fj.js";
13
+ import"./chunk-vrt08dk9.js";
14
14
  export {
15
15
  makeProgramRpcClient2 as makeProgramRpcClient,
16
16
  makeRunnerRpcClient2 as makeRunnerRpcClient,
@@ -22,7 +22,7 @@ import {
22
22
  map8,
23
23
  raceFirst,
24
24
  scoped
25
- } from "./chunk-d3ksv8y1.js";
25
+ } from "./chunk-vrt08dk9.js";
26
26
  import {
27
27
  unwrap,
28
28
  drainFork,
@@ -31,7 +31,7 @@ import {
31
31
  runCollect,
32
32
  runDrain,
33
33
  mkString
34
- } from "./chunk-dk0ftqwg.js";
34
+ } from "./chunk-7672g0fj.js";
35
35
 
36
36
  // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/internal/redacted.js
37
37
  var redactedRegistry = /* @__PURE__ */ new WeakMap;
@@ -18,7 +18,7 @@ import {
18
18
  isMinLength,
19
19
  isMaxLength,
20
20
  FiniteFromString
21
- } from "./chunk-d3ksv8y1.js";
21
+ } from "./chunk-vrt08dk9.js";
22
22
 
23
23
  // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/JsonSchema.js
24
24
  var PRE_2020_TO_2020_COLLISIONS = ["$anchor", "$defs", "$dynamicAnchor", "$dynamicRef", "$vocabulary", "contentSchema", "dependentRequired", "dependentSchemas", "maxContains", "minContains", "prefixItems", "unevaluatedItems", "unevaluatedProperties"];
@@ -7,11 +7,11 @@ import {
7
7
  decoded2,
8
8
  readOpencode2,
9
9
  runOpencodeReader2
10
- } from "./chunk-csbf77zs.js";
11
- import"./chunk-1rry0tsn.js";
12
- import"./chunk-v01c0k6j.js";
13
- import"./chunk-dk0ftqwg.js";
14
- import"./chunk-d3ksv8y1.js";
10
+ } from "./chunk-7sm45hhc.js";
11
+ import"./chunk-pyt2zrwc.js";
12
+ import"./chunk-nhd7dh79.js";
13
+ import"./chunk-7672g0fj.js";
14
+ import"./chunk-vrt08dk9.js";
15
15
  export {
16
16
  decoded2 as decoded,
17
17
  decodedOption2 as decodedOption,
@@ -32,9 +32,9 @@ import {
32
32
  toCodecJson,
33
33
  Json,
34
34
  encodePrettyJsonString
35
- } from "./chunk-d3ksv8y1.js";
36
- import"./chunk-rrnee9mk.js";
37
- import"./chunk-v01c0k6j.js";
35
+ } from "./chunk-vrt08dk9.js";
36
+ import"./chunk-se79jbha.js";
37
+ import"./chunk-nhd7dh79.js";
38
38
  import {
39
39
  SecureRandom,
40
40
  layerWebCrypto,
@@ -46,7 +46,7 @@ import {
46
46
  layer4,
47
47
  kitmanMcpServer,
48
48
  RunnerRpcProtocolVersion
49
- } from "./chunk-9e452fhe.js";
49
+ } from "./chunk-030xsst1.js";
50
50
  import {
51
51
  decodeText,
52
52
  mkString,
@@ -54,23 +54,23 @@ import {
54
54
  Path,
55
55
  withDefault,
56
56
  String2
57
- } from "./chunk-dk0ftqwg.js";
57
+ } from "./chunk-7672g0fj.js";
58
58
  import {
59
59
  Packument,
60
60
  tarballMatches
61
- } from "./chunk-hr9vd6dj.js";
62
- import"./chunk-5n121vsj.js";
61
+ } from "./chunk-290se4bt.js";
62
+ import"./chunk-cefprsjj.js";
63
63
  import {
64
64
  AgentDeclaration,
65
65
  KitDeclarations,
66
66
  describeFlag,
67
67
  Described
68
- } from "./chunk-x1zqfxve.js";
68
+ } from "./chunk-7wenq6ew.js";
69
69
  import {
70
70
  ChildProcessSpawner,
71
71
  make3
72
- } from "./chunk-1rry0tsn.js";
73
- import"./chunk-cmatdpfy.js";
72
+ } from "./chunk-pyt2zrwc.js";
73
+ import"./chunk-cj3ef3pv.js";
74
74
 
75
75
  // packages/sdk/src/build/index.ts
76
76
  class DependencyInstallFailed extends TaggedError2()("DependencyInstallFailed", {