@kodycodes/cli 3.8.0 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/dist/{auth-SH6OMYRB.js → auth-VDYNOWWW.js} +6 -6
- package/dist/bin.js +8 -8
- package/dist/{chunk-CHTKWLTY.js → chunk-3KFAHJ3X.js} +2 -2
- package/dist/{chunk-UUYLUB6D.js → chunk-5TKCVAGC.js} +4 -4
- package/dist/{chunk-S3KLKZ4C.js → chunk-A7PTGYDE.js} +2 -2
- package/dist/{chunk-2IHEZ5IG.js → chunk-BJYXRGMJ.js} +2 -2
- package/dist/chunk-HJXNQHP2.js +375 -0
- package/dist/chunk-HJXNQHP2.js.map +6 -0
- package/dist/{chunk-UZQGSC5Q.js → chunk-NOEA3TW5.js} +1 -1
- package/dist/{chunk-UZQGSC5Q.js.map → chunk-NOEA3TW5.js.map} +1 -1
- package/dist/{chunk-TZKZOMEA.js → chunk-OF5K2JTC.js} +2 -2
- package/dist/{chunk-EMIW7YJV.js → chunk-OW4X6SKC.js} +42 -39
- package/dist/chunk-OW4X6SKC.js.map +6 -0
- package/dist/{chunk-7CS745HK.js → chunk-P37TRN7V.js} +19 -3
- package/dist/chunk-P37TRN7V.js.map +6 -0
- package/dist/{chunk-2HKTSXCY.js → chunk-R5ULTMY3.js} +3 -3
- package/dist/{chunk-VR5OIYT3.js → chunk-SHZLU4OJ.js} +3 -3
- package/dist/{chunk-BFV3UBTK.js → chunk-SMB76RG2.js} +4 -4
- package/dist/{chunk-MQTJINYJ.js → chunk-UYONQBCZ.js} +6 -6
- package/dist/{chunk-CMIH7XDH.js → chunk-ZDPOWJS3.js} +6 -3
- package/dist/chunk-ZDPOWJS3.js.map +6 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +8 -8
- package/dist/{commands-IRGDWBBN.js → commands-C4O7KIIS.js} +152 -11
- package/dist/commands-C4O7KIIS.js.map +6 -0
- package/dist/{dev-command-BVDS3CGN.js → dev-command-FGRZUFYE.js} +9 -9
- package/dist/execution-context/commands.d.ts +1 -0
- package/dist/execution-context/daemon.d.ts +13 -0
- package/dist/execution-context/fs-access.d.ts +73 -0
- package/dist/execution-context/host-fs-bridge.d.ts +15 -0
- package/dist/execution-context/run-executor.d.ts +2 -0
- package/dist/{git-credential-OCWEHLY5.js → git-credential-V65OCEZZ.js} +7 -7
- package/dist/host-fs-shim.d.ts +18 -0
- package/dist/{local-execute-B7MEJ6T3.js → local-execute-PCTSXEMG.js} +403 -16
- package/dist/local-execute-PCTSXEMG.js.map +6 -0
- package/dist/local-execute.d.ts +7 -0
- package/dist/{local-package-graph-FJGQQIDV.js → local-package-graph-PHUDK35Z.js} +5 -5
- package/dist/{local-package-run-LJJF5DYK.js → local-package-run-26D36PUB.js} +9 -9
- package/dist/local-runtime-bridge.d.ts +3 -0
- package/dist/{mock-dep-resolve-OM6EBPBX.js → mock-dep-resolve-3C7XMXQ5.js} +7 -7
- package/dist/{mock-local-deps-LESBH4TV.js → mock-local-deps-MFYUHSMH.js} +6 -6
- package/dist/{open-api-client-PTUOXP3U.js → open-api-client-RRFJ536X.js} +5 -5
- package/dist/{org-OQQ4CIJC.js → org-HSRJWL37.js} +2 -2
- package/dist/{remote-execute-B5VM4KSV.js → remote-execute-V75DKTWV.js} +5 -5
- package/dist/{run-executor-ZCOLFJCY.js → run-executor-A6IKTPSR.js} +8 -5
- package/dist/run-executor-A6IKTPSR.js.map +6 -0
- package/dist/{setup-git-ND4XYQD6.js → setup-git-WBYEM2Y3.js} +6 -6
- package/dist/{store-6HBMNQKB.js → store-HWK76VF3.js} +4 -2
- package/dist/store.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunk-7CS745HK.js.map +0 -6
- package/dist/chunk-CMIH7XDH.js.map +0 -6
- package/dist/chunk-DTQAU3ML.js +0 -124
- package/dist/chunk-DTQAU3ML.js.map +0 -6
- package/dist/chunk-EMIW7YJV.js.map +0 -6
- package/dist/commands-IRGDWBBN.js.map +0 -6
- package/dist/local-execute-B7MEJ6T3.js.map +0 -6
- package/dist/run-executor-ZCOLFJCY.js.map +0 -6
- /package/dist/{auth-SH6OMYRB.js.map → auth-VDYNOWWW.js.map} +0 -0
- /package/dist/{chunk-CHTKWLTY.js.map → chunk-3KFAHJ3X.js.map} +0 -0
- /package/dist/{chunk-UUYLUB6D.js.map → chunk-5TKCVAGC.js.map} +0 -0
- /package/dist/{chunk-S3KLKZ4C.js.map → chunk-A7PTGYDE.js.map} +0 -0
- /package/dist/{chunk-2IHEZ5IG.js.map → chunk-BJYXRGMJ.js.map} +0 -0
- /package/dist/{chunk-TZKZOMEA.js.map → chunk-OF5K2JTC.js.map} +0 -0
- /package/dist/{chunk-2HKTSXCY.js.map → chunk-R5ULTMY3.js.map} +0 -0
- /package/dist/{chunk-VR5OIYT3.js.map → chunk-SHZLU4OJ.js.map} +0 -0
- /package/dist/{chunk-BFV3UBTK.js.map → chunk-SMB76RG2.js.map} +0 -0
- /package/dist/{chunk-MQTJINYJ.js.map → chunk-UYONQBCZ.js.map} +0 -0
- /package/dist/{dev-command-BVDS3CGN.js.map → dev-command-FGRZUFYE.js.map} +0 -0
- /package/dist/{git-credential-OCWEHLY5.js.map → git-credential-V65OCEZZ.js.map} +0 -0
- /package/dist/{local-package-graph-FJGQQIDV.js.map → local-package-graph-PHUDK35Z.js.map} +0 -0
- /package/dist/{local-package-run-LJJF5DYK.js.map → local-package-run-26D36PUB.js.map} +0 -0
- /package/dist/{mock-dep-resolve-OM6EBPBX.js.map → mock-dep-resolve-3C7XMXQ5.js.map} +0 -0
- /package/dist/{mock-local-deps-LESBH4TV.js.map → mock-local-deps-MFYUHSMH.js.map} +0 -0
- /package/dist/{open-api-client-PTUOXP3U.js.map → open-api-client-RRFJ536X.js.map} +0 -0
- /package/dist/{org-OQQ4CIJC.js.map → org-HSRJWL37.js.map} +0 -0
- /package/dist/{remote-execute-B5VM4KSV.js.map → remote-execute-V75DKTWV.js.map} +0 -0
- /package/dist/{setup-git-ND4XYQD6.js.map → setup-git-WBYEM2Y3.js.map} +0 -0
- /package/dist/{store-6HBMNQKB.js.map → store-HWK76VF3.js.map} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type FsMode = 'ro' | 'rw';
|
|
2
|
+
export type FsRule = {
|
|
3
|
+
path: string;
|
|
4
|
+
mode: FsMode;
|
|
5
|
+
};
|
|
6
|
+
export type FsLayer = 'server_grant' | 'local_policy';
|
|
7
|
+
export type LocalFsPolicy = {
|
|
8
|
+
version: 1;
|
|
9
|
+
fs: Array<FsRule>;
|
|
10
|
+
};
|
|
11
|
+
export type FsMount = {
|
|
12
|
+
path: string;
|
|
13
|
+
mode: FsMode;
|
|
14
|
+
};
|
|
15
|
+
export type FsRefusal = {
|
|
16
|
+
path: string;
|
|
17
|
+
layer: FsLayer;
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Host folders one run may touch: the server grant intersected with this
|
|
22
|
+
* machine's local policy, plus the grant roots so refusals can name the layer.
|
|
23
|
+
*/
|
|
24
|
+
export type EffectiveFs = {
|
|
25
|
+
mounts: Array<FsMount>;
|
|
26
|
+
refused: Array<FsRefusal>;
|
|
27
|
+
grantRoots: Array<string>;
|
|
28
|
+
};
|
|
29
|
+
export declare const emptyEffectiveFs: EffectiveFs;
|
|
30
|
+
export declare function localPolicyPath(configDir?: string): string;
|
|
31
|
+
export declare class FsAccessError extends Error {
|
|
32
|
+
readonly code: 'EACCES' | 'EROFS' | 'EINVAL' | 'ENOTSUP' | 'EFBIG';
|
|
33
|
+
constructor(code: 'EACCES' | 'EROFS' | 'EINVAL' | 'ENOTSUP' | 'EFBIG', message: string);
|
|
34
|
+
}
|
|
35
|
+
export declare function isWithin(child: string, parent: string): boolean;
|
|
36
|
+
export declare function readLocalPolicy(path?: string): Promise<LocalFsPolicy>;
|
|
37
|
+
/** Adds or replaces one rule, stored as its canonical (realpath) form. */
|
|
38
|
+
export declare function allowLocalPath(input: {
|
|
39
|
+
path: string;
|
|
40
|
+
mode: FsMode;
|
|
41
|
+
policyPath?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
policy: LocalFsPolicy;
|
|
44
|
+
added: {
|
|
45
|
+
path: string;
|
|
46
|
+
mode: FsMode;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
export declare function removeLocalPath(input: {
|
|
50
|
+
path: string;
|
|
51
|
+
policyPath?: string;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
policy: LocalFsPolicy;
|
|
54
|
+
removed: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* A folder is mounted only where both layers allow it, at the narrower mode.
|
|
58
|
+
* Both sides are canonicalized, so a symlinked grant path is judged by where
|
|
59
|
+
* it really points.
|
|
60
|
+
*/
|
|
61
|
+
export declare function effectiveFs(grant: ReadonlyArray<{
|
|
62
|
+
path: string;
|
|
63
|
+
mode: string;
|
|
64
|
+
}>, policy: ReadonlyArray<FsRule>): Promise<EffectiveFs>;
|
|
65
|
+
/**
|
|
66
|
+
* Maps a path the run asked for to the host path it may use, or throws an
|
|
67
|
+
* error naming the layer (server grant or local policy) that refused it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function resolveHostPath(effective: EffectiveFs, path: string, access: 'read' | 'write', options?: {
|
|
70
|
+
followFinal?: boolean;
|
|
71
|
+
allowMountRoot?: boolean;
|
|
72
|
+
}): Promise<string>;
|
|
73
|
+
export declare function fsFeatures(effective: EffectiveFs): string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type EffectiveFs } from './fs-access.js';
|
|
2
|
+
/** Largest file one host-folder read or write moves through the bridge. */
|
|
3
|
+
export declare const hostFsMaxBytes: number;
|
|
4
|
+
export type HostFsRequest = {
|
|
5
|
+
op: string;
|
|
6
|
+
path: string;
|
|
7
|
+
dest?: string;
|
|
8
|
+
data?: string;
|
|
9
|
+
recursive?: boolean;
|
|
10
|
+
force?: boolean;
|
|
11
|
+
withFileTypes?: boolean;
|
|
12
|
+
mode?: number;
|
|
13
|
+
};
|
|
14
|
+
/** Runs one fs call from a run's workerd against the effective host mounts. */
|
|
15
|
+
export declare function handleHostFsRequest(effective: EffectiveFs, request: HostFsRequest): Promise<unknown>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type EcpGrant, type EcpRunRequestBody } from '@kody-internal/shared/execution-context-protocol/index.ts';
|
|
2
|
+
import { type EffectiveFs } from './fs-access.js';
|
|
2
3
|
import { type LocalWorkerTracker } from './worker-tracker.js';
|
|
3
4
|
/**
|
|
4
5
|
* Runs a context run in local workerd through the same path as
|
|
@@ -13,6 +14,7 @@ export declare function runContextRun(input: {
|
|
|
13
14
|
workerTracker?: LocalWorkerTracker;
|
|
14
15
|
/** The context grant's egress; absent means the default (public only). */
|
|
15
16
|
egress?: EcpGrant['egress'];
|
|
17
|
+
hostFs?: () => EffectiveFs;
|
|
16
18
|
}): Promise<{
|
|
17
19
|
structuredContent?: Record<string, unknown> | undefined;
|
|
18
20
|
isError: boolean;
|
|
@@ -7,27 +7,27 @@ import {
|
|
|
7
7
|
gitCredentialHostFromMcpUrl,
|
|
8
8
|
resolveCliTokenLifetime,
|
|
9
9
|
setupGitDefaultScopes
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-SMB76RG2.js";
|
|
11
11
|
import "./chunk-6ZYUGXVW.js";
|
|
12
12
|
import {
|
|
13
13
|
ensureOpenApiCredentials
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5TKCVAGC.js";
|
|
15
15
|
import "./chunk-GVSGNTG6.js";
|
|
16
16
|
import "./chunk-CWWHR4FH.js";
|
|
17
17
|
import "./chunk-CASGRYOF.js";
|
|
18
18
|
import {
|
|
19
19
|
callOpenApiOperation
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-BJYXRGMJ.js";
|
|
21
21
|
import "./chunk-46IJPEID.js";
|
|
22
22
|
import "./chunk-BML3W5CO.js";
|
|
23
|
-
import "./chunk-
|
|
23
|
+
import "./chunk-OF5K2JTC.js";
|
|
24
24
|
import {
|
|
25
25
|
loadStoredApiToken
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-A7PTGYDE.js";
|
|
27
27
|
import "./chunk-NHRYNRXG.js";
|
|
28
28
|
import {
|
|
29
29
|
loadCredentials
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-ZDPOWJS3.js";
|
|
31
31
|
import {
|
|
32
32
|
defaultApiUrl,
|
|
33
33
|
defaultMcpUrl
|
|
@@ -168,4 +168,4 @@ export {
|
|
|
168
168
|
parseGitCredentialInput,
|
|
169
169
|
readGitCredentialStdin
|
|
170
170
|
};
|
|
171
|
-
//# sourceMappingURL=git-credential-
|
|
171
|
+
//# sourceMappingURL=git-credential-V65OCEZZ.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workerd has no host filesystem, so execution-context runs reach granted host
|
|
3
|
+
* folders through these `node:fs` / `node:fs/promises` replacements. Paths in
|
|
4
|
+
* a mount (or anywhere outside workerd's own /bundle, /tmp, /dev) go to the
|
|
5
|
+
* kody bridge, which enforces the effective mounts on the Node side; every
|
|
6
|
+
* other call goes to workerd's built-in virtual fs unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export declare const hostFsShimModules: readonly [{
|
|
9
|
+
readonly name: "node:fs";
|
|
10
|
+
readonly file: "host-fs.js";
|
|
11
|
+
}, {
|
|
12
|
+
readonly name: "node:fs/promises";
|
|
13
|
+
readonly file: "host-fs-promises.js";
|
|
14
|
+
}];
|
|
15
|
+
export declare function createHostFsPromisesSource(input: {
|
|
16
|
+
routeRoots: ReadonlyArray<string>;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function createHostFsSource(): string;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
forwardLocalGatewayFetchStream,
|
|
5
5
|
installMockFetchShimModules,
|
|
6
6
|
startLocalRuntimeBridge
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-P37TRN7V.js";
|
|
8
8
|
import {
|
|
9
9
|
resolveMockFetchGateway,
|
|
10
10
|
tryHandleMockGatewayFetchCall
|
|
@@ -28,8 +28,11 @@ import {
|
|
|
28
28
|
runSecretEnvVar,
|
|
29
29
|
runSecretHeader,
|
|
30
30
|
writePackageModuleFiles
|
|
31
|
-
} from "./chunk-
|
|
32
|
-
import
|
|
31
|
+
} from "./chunk-R5ULTMY3.js";
|
|
32
|
+
import {
|
|
33
|
+
FsAccessError,
|
|
34
|
+
resolveHostPath
|
|
35
|
+
} from "./chunk-HJXNQHP2.js";
|
|
33
36
|
import {
|
|
34
37
|
createEgressGateSource,
|
|
35
38
|
egressGateModuleName,
|
|
@@ -53,10 +56,10 @@ import {
|
|
|
53
56
|
missingCredentialCallMapFeatureMessage,
|
|
54
57
|
openCapabilityProxySession,
|
|
55
58
|
sessionSupportsCredentialCallMap
|
|
56
|
-
} from "./chunk-
|
|
57
|
-
import "./chunk-
|
|
59
|
+
} from "./chunk-OF5K2JTC.js";
|
|
60
|
+
import "./chunk-A7PTGYDE.js";
|
|
58
61
|
import "./chunk-NHRYNRXG.js";
|
|
59
|
-
import "./chunk-
|
|
62
|
+
import "./chunk-ZDPOWJS3.js";
|
|
60
63
|
import {
|
|
61
64
|
apiTokenEnvVar
|
|
62
65
|
} from "./chunk-V7P2QDVU.js";
|
|
@@ -66,7 +69,369 @@ import "./chunk-UW6AWLXX.js";
|
|
|
66
69
|
import { spawn } from "node:child_process";
|
|
67
70
|
import { randomBytes } from "node:crypto";
|
|
68
71
|
import { rmSync } from "node:fs";
|
|
69
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
72
|
+
import { mkdtemp, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
73
|
+
|
|
74
|
+
// src/execution-context/host-fs-bridge.ts
|
|
75
|
+
import {
|
|
76
|
+
access,
|
|
77
|
+
appendFile,
|
|
78
|
+
copyFile,
|
|
79
|
+
lstat,
|
|
80
|
+
mkdir,
|
|
81
|
+
readFile,
|
|
82
|
+
readdir,
|
|
83
|
+
rename,
|
|
84
|
+
rm,
|
|
85
|
+
rmdir,
|
|
86
|
+
stat,
|
|
87
|
+
unlink,
|
|
88
|
+
writeFile
|
|
89
|
+
} from "node:fs/promises";
|
|
90
|
+
var hostFsMaxBytes = 32 * 1024 * 1024;
|
|
91
|
+
function statView(stats) {
|
|
92
|
+
return {
|
|
93
|
+
kind: stats.isDirectory() ? "directory" : stats.isSymbolicLink() ? "symlink" : stats.isFile() ? "file" : "other",
|
|
94
|
+
size: stats.size,
|
|
95
|
+
mode: stats.mode,
|
|
96
|
+
mtimeMs: stats.mtimeMs,
|
|
97
|
+
atimeMs: stats.atimeMs,
|
|
98
|
+
ctimeMs: stats.ctimeMs,
|
|
99
|
+
birthtimeMs: stats.birthtimeMs
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function decodeData(data) {
|
|
103
|
+
const bytes = Buffer.from(typeof data === "string" ? data : "", "base64");
|
|
104
|
+
if (bytes.byteLength > hostFsMaxBytes) {
|
|
105
|
+
throw new FsAccessError(
|
|
106
|
+
"EFBIG",
|
|
107
|
+
`Host folder writes are limited to ${hostFsMaxBytes} bytes per call.`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return bytes;
|
|
111
|
+
}
|
|
112
|
+
async function handleHostFsRequest(effective, request) {
|
|
113
|
+
const path = request.path;
|
|
114
|
+
switch (request.op) {
|
|
115
|
+
case "readFile": {
|
|
116
|
+
const real = await resolveHostPath(effective, path, "read");
|
|
117
|
+
const info = await stat(real);
|
|
118
|
+
if (info.size > hostFsMaxBytes) {
|
|
119
|
+
throw new FsAccessError(
|
|
120
|
+
"EFBIG",
|
|
121
|
+
`${path} is larger than the ${hostFsMaxBytes}-byte host folder read limit.`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return (await readFile(real)).toString("base64");
|
|
125
|
+
}
|
|
126
|
+
case "writeFile":
|
|
127
|
+
case "appendFile": {
|
|
128
|
+
const real = await resolveHostPath(effective, path, "write", {
|
|
129
|
+
allowMountRoot: false
|
|
130
|
+
});
|
|
131
|
+
const write = request.op === "writeFile" ? writeFile : appendFile;
|
|
132
|
+
await write(real, decodeData(request.data));
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
case "readdir": {
|
|
136
|
+
const real = await resolveHostPath(effective, path, "read");
|
|
137
|
+
const entries = await readdir(real, { withFileTypes: true });
|
|
138
|
+
return entries.map((entry) => ({
|
|
139
|
+
name: entry.name,
|
|
140
|
+
kind: entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : entry.isFile() ? "file" : "other"
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
case "stat":
|
|
144
|
+
return statView(
|
|
145
|
+
await stat(await resolveHostPath(effective, path, "read"))
|
|
146
|
+
);
|
|
147
|
+
case "lstat":
|
|
148
|
+
return statView(
|
|
149
|
+
await lstat(
|
|
150
|
+
await resolveHostPath(effective, path, "read", {
|
|
151
|
+
followFinal: false
|
|
152
|
+
})
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
case "access": {
|
|
156
|
+
const wantsWrite = typeof request.mode === "number" && (request.mode & 2) !== 0;
|
|
157
|
+
const real = await resolveHostPath(
|
|
158
|
+
effective,
|
|
159
|
+
path,
|
|
160
|
+
wantsWrite ? "write" : "read",
|
|
161
|
+
{ allowMountRoot: true }
|
|
162
|
+
);
|
|
163
|
+
await access(real, request.mode);
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
case "realpath":
|
|
167
|
+
return await resolveHostPath(effective, path, "read");
|
|
168
|
+
case "mkdir": {
|
|
169
|
+
const real = await resolveHostPath(effective, path, "write", {
|
|
170
|
+
followFinal: false,
|
|
171
|
+
allowMountRoot: true
|
|
172
|
+
});
|
|
173
|
+
await mkdir(real, { recursive: request.recursive === true });
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
case "rm":
|
|
177
|
+
case "unlink":
|
|
178
|
+
case "rmdir": {
|
|
179
|
+
const real = await resolveHostPath(effective, path, "write", {
|
|
180
|
+
followFinal: false
|
|
181
|
+
});
|
|
182
|
+
if (request.op === "unlink") await unlink(real);
|
|
183
|
+
else if (request.op === "rmdir") await rmdir(real);
|
|
184
|
+
else
|
|
185
|
+
await rm(real, {
|
|
186
|
+
recursive: request.recursive === true,
|
|
187
|
+
force: request.force === true
|
|
188
|
+
});
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
case "rename":
|
|
192
|
+
case "copyFile": {
|
|
193
|
+
const dest = request.dest ?? "";
|
|
194
|
+
const destReal = await resolveHostPath(effective, dest, "write", {
|
|
195
|
+
followFinal: request.op === "copyFile"
|
|
196
|
+
});
|
|
197
|
+
if (request.op === "rename") {
|
|
198
|
+
const from = await resolveHostPath(effective, path, "write", {
|
|
199
|
+
followFinal: false
|
|
200
|
+
});
|
|
201
|
+
await rename(from, destReal);
|
|
202
|
+
} else {
|
|
203
|
+
await copyFile(await resolveHostPath(effective, path, "read"), destReal);
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
default:
|
|
208
|
+
throw new FsAccessError(
|
|
209
|
+
"ENOTSUP",
|
|
210
|
+
`fs.${request.op} is not supported on execution context host folders. Use fs/promises readFile, writeFile, appendFile, readdir, stat, lstat, mkdir, rm, unlink, rmdir, rename, copyFile, access, or realpath.`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/host-fs-shim.ts
|
|
216
|
+
import * as nodeFs from "node:fs";
|
|
217
|
+
var hostFsShimModules = [
|
|
218
|
+
{ name: "node:fs", file: "host-fs.js" },
|
|
219
|
+
{ name: "node:fs/promises", file: "host-fs-promises.js" }
|
|
220
|
+
];
|
|
221
|
+
var identifier = /^[A-Za-z_$][\w$]*$/;
|
|
222
|
+
function exportNames(value) {
|
|
223
|
+
return Object.keys(value).filter((name) => identifier.test(name) && name !== "default").sort();
|
|
224
|
+
}
|
|
225
|
+
function createHostFsPromisesSource(input) {
|
|
226
|
+
const names = exportNames(nodeFs.promises);
|
|
227
|
+
return `import { env } from 'cloudflare:workers';
|
|
228
|
+
import { Buffer } from 'node:buffer';
|
|
229
|
+
import { posix } from 'node:path';
|
|
230
|
+
|
|
231
|
+
const real = process.getBuiltinModule('node:fs').promises;
|
|
232
|
+
const routeRoots = ${JSON.stringify(input.routeRoots)};
|
|
233
|
+
const virtualRoots = ['/bundle', '/tmp', '/dev'];
|
|
234
|
+
const within = (path, root) => path === root || path.startsWith(root.endsWith('/') ? root : root + '/');
|
|
235
|
+
|
|
236
|
+
export function __kodyHostPath(path) {
|
|
237
|
+
if (path instanceof URL) {
|
|
238
|
+
if (path.protocol !== 'file:') return null;
|
|
239
|
+
path = decodeURIComponent(path.pathname);
|
|
240
|
+
}
|
|
241
|
+
if (typeof path !== 'string' || !path.startsWith('/')) return null;
|
|
242
|
+
const normalized = posix.normalize(path);
|
|
243
|
+
if (routeRoots.some((root) => within(normalized, root))) return normalized;
|
|
244
|
+
if (virtualRoots.some((root) => within(normalized, root))) return null;
|
|
245
|
+
return normalized;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function __kodyHostFsError(code, message, syscall, path) {
|
|
249
|
+
const error = new Error(message);
|
|
250
|
+
error.code = code;
|
|
251
|
+
error.syscall = syscall;
|
|
252
|
+
if (path !== undefined) error.path = path;
|
|
253
|
+
return error;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function call(op, body) {
|
|
257
|
+
const response = await env.KODY_BRIDGE.fetch('http://kody-bridge/fs', {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: { 'content-type': 'application/json', ${JSON.stringify(runSecretHeader)}: env.KODY_RUN_SECRET },
|
|
260
|
+
body: JSON.stringify({ op, ...body }),
|
|
261
|
+
});
|
|
262
|
+
const data = await response.json();
|
|
263
|
+
if (data.error) throw __kodyHostFsError(data.error.code, data.error.message, op, body.path);
|
|
264
|
+
return data.result;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const encodingOf = (options) => (typeof options === 'string' ? options : (options?.encoding ?? null));
|
|
268
|
+
|
|
269
|
+
function toBase64(data, options) {
|
|
270
|
+
if (typeof data === 'string') return Buffer.from(data, encodingOf(options) ?? 'utf8').toString('base64');
|
|
271
|
+
if (ArrayBuffer.isView(data)) return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('base64');
|
|
272
|
+
throw new TypeError('Host folder writes take a string, Buffer, or TypedArray.');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function kindChecks(kind) {
|
|
276
|
+
return {
|
|
277
|
+
isFile: () => kind === 'file',
|
|
278
|
+
isDirectory: () => kind === 'directory',
|
|
279
|
+
isSymbolicLink: () => kind === 'symlink',
|
|
280
|
+
isFIFO: () => false,
|
|
281
|
+
isSocket: () => false,
|
|
282
|
+
isBlockDevice: () => false,
|
|
283
|
+
isCharacterDevice: () => false,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function toStats(view) {
|
|
288
|
+
return {
|
|
289
|
+
...kindChecks(view.kind),
|
|
290
|
+
size: view.size,
|
|
291
|
+
mode: view.mode,
|
|
292
|
+
mtimeMs: view.mtimeMs,
|
|
293
|
+
atimeMs: view.atimeMs,
|
|
294
|
+
ctimeMs: view.ctimeMs,
|
|
295
|
+
birthtimeMs: view.birthtimeMs,
|
|
296
|
+
mtime: new Date(view.mtimeMs),
|
|
297
|
+
atime: new Date(view.atimeMs),
|
|
298
|
+
ctime: new Date(view.ctimeMs),
|
|
299
|
+
birthtime: new Date(view.birthtimeMs),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const hosted = {
|
|
304
|
+
async readFile(path, options) {
|
|
305
|
+
const bytes = Buffer.from(await call('readFile', { path }), 'base64');
|
|
306
|
+
const encoding = encodingOf(options);
|
|
307
|
+
return encoding ? bytes.toString(encoding) : bytes;
|
|
308
|
+
},
|
|
309
|
+
async writeFile(path, data, options) {
|
|
310
|
+
await call('writeFile', { path, data: toBase64(data, options) });
|
|
311
|
+
},
|
|
312
|
+
async appendFile(path, data, options) {
|
|
313
|
+
await call('appendFile', { path, data: toBase64(data, options) });
|
|
314
|
+
},
|
|
315
|
+
async readdir(path, options) {
|
|
316
|
+
const entries = await call('readdir', { path });
|
|
317
|
+
return options?.withFileTypes
|
|
318
|
+
? entries.map((entry) => ({ name: entry.name, parentPath: path, path, ...kindChecks(entry.kind) }))
|
|
319
|
+
: entries.map((entry) => entry.name);
|
|
320
|
+
},
|
|
321
|
+
async stat(path) {
|
|
322
|
+
return toStats(await call('stat', { path }));
|
|
323
|
+
},
|
|
324
|
+
async lstat(path) {
|
|
325
|
+
return toStats(await call('lstat', { path }));
|
|
326
|
+
},
|
|
327
|
+
async mkdir(path, options) {
|
|
328
|
+
await call('mkdir', { path, recursive: typeof options === 'object' && options?.recursive === true });
|
|
329
|
+
},
|
|
330
|
+
async rm(path, options) {
|
|
331
|
+
await call('rm', { path, recursive: options?.recursive === true, force: options?.force === true });
|
|
332
|
+
},
|
|
333
|
+
async unlink(path) {
|
|
334
|
+
await call('unlink', { path });
|
|
335
|
+
},
|
|
336
|
+
async rmdir(path) {
|
|
337
|
+
await call('rmdir', { path });
|
|
338
|
+
},
|
|
339
|
+
async rename(path, dest) {
|
|
340
|
+
await call('rename', { path, dest });
|
|
341
|
+
},
|
|
342
|
+
async copyFile(path, dest) {
|
|
343
|
+
await call('copyFile', { path, dest });
|
|
344
|
+
},
|
|
345
|
+
async access(path, mode) {
|
|
346
|
+
await call('access', { path, ...(typeof mode === 'number' ? { mode } : {}) });
|
|
347
|
+
},
|
|
348
|
+
async realpath(path) {
|
|
349
|
+
return await call('realpath', { path });
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
const twoPath = new Set(['rename', 'copyFile']);
|
|
353
|
+
|
|
354
|
+
function wrapHosted(name) {
|
|
355
|
+
return function (...args) {
|
|
356
|
+
const first = __kodyHostPath(args[0]);
|
|
357
|
+
const second = twoPath.has(name) ? __kodyHostPath(args[1]) : null;
|
|
358
|
+
if (first === null && second === null) return real[name](...args);
|
|
359
|
+
if (twoPath.has(name) && (first === null || second === null)) {
|
|
360
|
+
return Promise.reject(__kodyHostFsError('ENOTSUP', 'fs.' + name + ' cannot move files between a host folder and the run\\'s virtual filesystem.', name, args[0]));
|
|
361
|
+
}
|
|
362
|
+
args[0] = first;
|
|
363
|
+
if (second !== null) args[1] = second;
|
|
364
|
+
return hosted[name](...args);
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function guardUnsupported(name) {
|
|
369
|
+
const fn = real[name];
|
|
370
|
+
return function (...args) {
|
|
371
|
+
if (__kodyHostPath(args[0]) !== null) {
|
|
372
|
+
return Promise.reject(__kodyHostFsError('ENOTSUP', 'fs.promises.' + name + ' is not supported on execution context host folders. Supported: ' + Object.keys(hosted).join(', ') + '.', name, args[0]));
|
|
373
|
+
}
|
|
374
|
+
return fn.apply(real, args);
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const promises = {};
|
|
379
|
+
for (const name of Object.keys(real)) {
|
|
380
|
+
const value = real[name];
|
|
381
|
+
promises[name] = name in hosted ? wrapHosted(name) : typeof value === 'function' ? guardUnsupported(name) : value;
|
|
382
|
+
}
|
|
383
|
+
for (const name of Object.keys(hosted)) promises[name] ??= wrapHosted(name);
|
|
384
|
+
|
|
385
|
+
export default promises;
|
|
386
|
+
${names.map((name) => `export const ${name} = promises[${JSON.stringify(name)}];`).join("\n")}
|
|
387
|
+
`;
|
|
388
|
+
}
|
|
389
|
+
function createHostFsSource() {
|
|
390
|
+
const names = exportNames(nodeFs);
|
|
391
|
+
return `import __kodyPromises, { __kodyHostPath, __kodyHostFsError } from 'node:fs/promises';
|
|
392
|
+
|
|
393
|
+
const real = process.getBuiltinModule('node:fs');
|
|
394
|
+
const hosted = new Set(['readFile', 'writeFile', 'appendFile', 'readdir', 'stat', 'lstat', 'mkdir', 'rm', 'unlink', 'rmdir', 'rename', 'copyFile', 'access', 'realpath']);
|
|
395
|
+
const twoPath = new Set(['rename', 'copyFile']);
|
|
396
|
+
|
|
397
|
+
const routed = (name, args) =>
|
|
398
|
+
__kodyHostPath(args[0]) !== null || (twoPath.has(name) && __kodyHostPath(args[1]) !== null);
|
|
399
|
+
|
|
400
|
+
function wrapCallback(name) {
|
|
401
|
+
const fn = real[name];
|
|
402
|
+
return function (...args) {
|
|
403
|
+
const callback = args[args.length - 1];
|
|
404
|
+
if (typeof callback !== 'function' || !routed(name, args)) return fn.apply(real, args);
|
|
405
|
+
args.pop();
|
|
406
|
+
__kodyPromises[name](...args).then((value) => callback(null, value), (error) => callback(error));
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function guard(name) {
|
|
411
|
+
const fn = real[name];
|
|
412
|
+
const hint = name.endsWith('Sync') && hosted.has(name.slice(0, -4))
|
|
413
|
+
? ' Synchronous fs calls cannot reach host folders; use await fs.promises.' + name.slice(0, -4) + '(...) instead.'
|
|
414
|
+
: ' Use fs.promises ' + [...hosted].join(', ') + '.';
|
|
415
|
+
return function (...args) {
|
|
416
|
+
if (routed(name, args)) {
|
|
417
|
+
throw __kodyHostFsError('ENOTSUP', 'fs.' + name + ' is not supported on execution context host folders.' + hint, name, args[0]);
|
|
418
|
+
}
|
|
419
|
+
return fn.apply(real, args);
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const fs = {};
|
|
424
|
+
for (const name of Object.keys(real)) {
|
|
425
|
+
const value = real[name];
|
|
426
|
+
fs[name] = name === 'promises' ? __kodyPromises : typeof value !== 'function' || /^[A-Z]/.test(name) ? value : hosted.has(name) ? wrapCallback(name) : guard(name);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export default fs;
|
|
430
|
+
${names.map((name) => `export const ${name} = fs[${JSON.stringify(name)}];`).join("\n")}
|
|
431
|
+
`;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// src/local-execute.ts
|
|
70
435
|
import { request as httpRequest } from "node:http";
|
|
71
436
|
import { tmpdir } from "node:os";
|
|
72
437
|
import { join } from "node:path";
|
|
@@ -187,6 +552,8 @@ async function runLocalExecute(input) {
|
|
|
187
552
|
allowPrivateNetwork: input.allowPrivateNetwork,
|
|
188
553
|
onStatus: input.onStatus
|
|
189
554
|
});
|
|
555
|
+
const startFs = input.hostFs?.();
|
|
556
|
+
const hostFs = input.hostFs && startFs && (startFs.mounts.length > 0 || startFs.grantRoots.length > 0) ? input.hostFs : void 0;
|
|
190
557
|
bridge = await startLocalRuntimeBridge({
|
|
191
558
|
runSecret,
|
|
192
559
|
forwardCall: async (call, signal) => {
|
|
@@ -206,6 +573,9 @@ async function runLocalExecute(input) {
|
|
|
206
573
|
signal
|
|
207
574
|
});
|
|
208
575
|
},
|
|
576
|
+
...hostFs ? {
|
|
577
|
+
forwardHostFs: async (body) => await handleHostFsRequest(hostFs(), body)
|
|
578
|
+
} : {},
|
|
209
579
|
forwardGatewayFetchStream: async ({ request, response: response2, signal }) => {
|
|
210
580
|
await forwardLocalGatewayFetchStream({
|
|
211
581
|
request,
|
|
@@ -227,26 +597,43 @@ async function runLocalExecute(input) {
|
|
|
227
597
|
packageModules = installed.packageModules;
|
|
228
598
|
gatewayFetchShimModules = installed.sideEffectModules;
|
|
229
599
|
}
|
|
230
|
-
|
|
600
|
+
if (hostFs) {
|
|
601
|
+
const routeRoots = [
|
|
602
|
+
.../* @__PURE__ */ new Set([
|
|
603
|
+
...startFs.mounts.map((mount) => mount.path),
|
|
604
|
+
...startFs.grantRoots
|
|
605
|
+
])
|
|
606
|
+
];
|
|
607
|
+
await writeFile2(
|
|
608
|
+
join(workDir, hostFsShimModules[0].file),
|
|
609
|
+
createHostFsSource()
|
|
610
|
+
);
|
|
611
|
+
await writeFile2(
|
|
612
|
+
join(workDir, hostFsShimModules[1].file),
|
|
613
|
+
createHostFsPromisesSource({ routeRoots })
|
|
614
|
+
);
|
|
615
|
+
packageModules = [...packageModules, ...hostFsShimModules];
|
|
616
|
+
}
|
|
617
|
+
await writeFile2(
|
|
231
618
|
join(workDir, files.entry),
|
|
232
619
|
createLocalEntrySource({ sideEffectModules: gatewayFetchShimModules })
|
|
233
620
|
);
|
|
234
|
-
await
|
|
235
|
-
await
|
|
621
|
+
await writeFile2(join(workDir, files.user), code);
|
|
622
|
+
await writeFile2(
|
|
236
623
|
join(workDir, files.runtime),
|
|
237
624
|
createLocalRuntimeModuleSource()
|
|
238
625
|
);
|
|
239
|
-
await
|
|
626
|
+
await writeFile2(
|
|
240
627
|
join(workDir, localWorkerModuleNames.runtimeFlatAlias),
|
|
241
628
|
createRuntimeFlatAliasSource()
|
|
242
629
|
);
|
|
243
630
|
const egressPolicy = input.egress ?? localExecuteEgressPolicy(input.allowPrivateNetwork);
|
|
244
|
-
await
|
|
631
|
+
await writeFile2(
|
|
245
632
|
join(workDir, egressGateModuleName),
|
|
246
633
|
createEgressGateSource()
|
|
247
634
|
);
|
|
248
635
|
const configPath = join(workDir, "config.capnp");
|
|
249
|
-
await
|
|
636
|
+
await writeFile2(
|
|
250
637
|
configPath,
|
|
251
638
|
createWorkerdConfig({
|
|
252
639
|
bridgePort: bridge.port,
|
|
@@ -312,11 +699,11 @@ async function runLocalExecute(input) {
|
|
|
312
699
|
releaseSignals();
|
|
313
700
|
stopWorkerd();
|
|
314
701
|
await bridge?.close();
|
|
315
|
-
await
|
|
702
|
+
await rm2(workDir, { recursive: true, force: true });
|
|
316
703
|
}
|
|
317
704
|
}
|
|
318
705
|
async function writePackageModuleFiles2(workDir, graph) {
|
|
319
|
-
return await writePackageModuleFiles(workDir, graph,
|
|
706
|
+
return await writePackageModuleFiles(workDir, graph, writeFile2, join);
|
|
320
707
|
}
|
|
321
708
|
function buildLocalExecuteResult(input) {
|
|
322
709
|
const { sandbox } = input;
|
|
@@ -471,4 +858,4 @@ export {
|
|
|
471
858
|
runLocalExecute,
|
|
472
859
|
savedPackageImportLocalResolveStatus
|
|
473
860
|
};
|
|
474
|
-
//# sourceMappingURL=local-execute-
|
|
861
|
+
//# sourceMappingURL=local-execute-PCTSXEMG.js.map
|