@kodycodes/cli 3.28.2 → 3.28.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/dist/bin.js +1 -1
- package/dist/{chunk-NINSI6RV.js → chunk-4NMUNDYR.js} +14 -6
- package/dist/{chunk-NINSI6RV.js.map → chunk-4NMUNDYR.js.map} +1 -1
- package/dist/{chunk-AUY7E5W4.js → chunk-A3EJ5CXG.js} +4 -4
- package/dist/{chunk-4SE2AT5A.js → chunk-AO7JQ7QO.js} +2 -2
- package/dist/{chunk-CPOQG27Q.js → chunk-FEVH7L22.js} +3 -3
- package/dist/{chunk-HYDKOHOG.js → chunk-GOBGKXEU.js} +2 -2
- package/dist/{chunk-6YL6C3LL.js → chunk-PMRDVBMB.js} +13 -8
- package/dist/chunk-PMRDVBMB.js.map +6 -0
- package/dist/{chunk-SLHFID52.js → chunk-TJKEADTR.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{commands-KJ2LKZPN.js → commands-KSLL3FBI.js} +305 -24
- package/dist/commands-KSLL3FBI.js.map +6 -0
- package/dist/{dev-command-AD3RRODH.js → dev-command-SAN55YUO.js} +6 -6
- package/dist/execution-context/fs-access.d.ts +2 -0
- package/dist/execution-context/host-access.d.ts +80 -0
- package/dist/{local-execute-DESLSJIM.js → local-execute-YWYSSSX4.js} +5 -5
- package/dist/{local-package-graph-T2PWPQDN.js → local-package-graph-BOT5WG6P.js} +3 -3
- package/dist/{local-package-run-PUB3K7FH.js → local-package-run-TWSCJ5OP.js} +6 -6
- package/dist/{mock-local-deps-5G7GBK7X.js → mock-local-deps-BSIIIPOE.js} +4 -4
- package/dist/{run-executor-MJXLTKYY.js → run-executor-RY226HUI.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-6YL6C3LL.js.map +0 -6
- package/dist/commands-KJ2LKZPN.js.map +0 -6
- /package/dist/{chunk-AUY7E5W4.js.map → chunk-A3EJ5CXG.js.map} +0 -0
- /package/dist/{chunk-4SE2AT5A.js.map → chunk-AO7JQ7QO.js.map} +0 -0
- /package/dist/{chunk-CPOQG27Q.js.map → chunk-FEVH7L22.js.map} +0 -0
- /package/dist/{chunk-HYDKOHOG.js.map → chunk-GOBGKXEU.js.map} +0 -0
- /package/dist/{chunk-SLHFID52.js.map → chunk-TJKEADTR.js.map} +0 -0
- /package/dist/{dev-command-AD3RRODH.js.map → dev-command-SAN55YUO.js.map} +0 -0
- /package/dist/{local-execute-DESLSJIM.js.map → local-execute-YWYSSSX4.js.map} +0 -0
- /package/dist/{local-package-graph-T2PWPQDN.js.map → local-package-graph-BOT5WG6P.js.map} +0 -0
- /package/dist/{local-package-run-PUB3K7FH.js.map → local-package-run-TWSCJ5OP.js.map} +0 -0
- /package/dist/{mock-local-deps-5G7GBK7X.js.map → mock-local-deps-BSIIIPOE.js.map} +0 -0
- /package/dist/{run-executor-MJXLTKYY.js.map → run-executor-RY226HUI.js.map} +0 -0
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
allowLocalPath,
|
|
4
|
+
canonicalHostPath,
|
|
4
5
|
credentialDenylist,
|
|
5
6
|
effectiveFs,
|
|
6
7
|
emptyEffectiveFs,
|
|
7
8
|
fsFeatures,
|
|
9
|
+
isAbsolute,
|
|
8
10
|
isDeniedPath,
|
|
11
|
+
isWithin,
|
|
9
12
|
killProcessTree,
|
|
10
13
|
localPolicyPath,
|
|
14
|
+
plainPath,
|
|
11
15
|
readLocalCommandsEnabled,
|
|
12
16
|
readLocalPolicy,
|
|
13
17
|
removeLocalPath,
|
|
18
|
+
samePath,
|
|
14
19
|
setLocalAutoUpdateEnabled,
|
|
15
20
|
setLocalCommandsEnabled,
|
|
16
21
|
windowsCommandLine
|
|
17
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-4NMUNDYR.js";
|
|
18
23
|
import {
|
|
19
24
|
killWindowsTree,
|
|
20
25
|
windowsFileLaunch,
|
|
@@ -617,7 +622,7 @@ import {
|
|
|
617
622
|
} from "node:fs";
|
|
618
623
|
import { createRequire } from "node:module";
|
|
619
624
|
import { homedir } from "node:os";
|
|
620
|
-
import { delimiter, dirname, isAbsolute, join, normalize, sep } from "node:path";
|
|
625
|
+
import { delimiter, dirname, isAbsolute as isAbsolute2, join, normalize, sep } from "node:path";
|
|
621
626
|
import { gunzipSync } from "node:zlib";
|
|
622
627
|
var packageName = "@kodycodes/cli";
|
|
623
628
|
var registryUrl = "https://registry.npmjs.org";
|
|
@@ -701,7 +706,7 @@ function writeJsonAtomic(path, value) {
|
|
|
701
706
|
}
|
|
702
707
|
function readCurrent(store = cliStoreDir()) {
|
|
703
708
|
const current = readJsonFile(join(store, "current.json"));
|
|
704
|
-
if (!current || typeof current.version !== "string" || typeof current.entry !== "string" || !parseVersion(current.version) || !
|
|
709
|
+
if (!current || typeof current.version !== "string" || typeof current.entry !== "string" || !parseVersion(current.version) || !isAbsolute2(current.entry) || !isWithinDir(current.entry, join(store, "versions"))) {
|
|
705
710
|
return null;
|
|
706
711
|
}
|
|
707
712
|
return current;
|
|
@@ -858,7 +863,7 @@ function extractPackage(gzipped, dest) {
|
|
|
858
863
|
const relative = path.replace(/^package\//, "");
|
|
859
864
|
if (relative === path && path !== "package") continue;
|
|
860
865
|
const parts = relative.split("/").filter(Boolean);
|
|
861
|
-
if (parts.some((part) => part === ".." || part === ".") ||
|
|
866
|
+
if (parts.some((part) => part === ".." || part === ".") || isAbsolute2(relative)) {
|
|
862
867
|
throw new Error(`tarball has an unsafe path: ${path}`);
|
|
863
868
|
}
|
|
864
869
|
if (parts.length === 0) continue;
|
|
@@ -2151,7 +2156,7 @@ import { spawn as spawn2 } from "node:child_process";
|
|
|
2151
2156
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
2152
2157
|
import { realpath, stat } from "node:fs/promises";
|
|
2153
2158
|
import { homedir as homedir2 } from "node:os";
|
|
2154
|
-
import { isAbsolute as
|
|
2159
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
2155
2160
|
var HostCommandError = class extends Error {
|
|
2156
2161
|
constructor(code, message) {
|
|
2157
2162
|
super(`${message} (${code})`);
|
|
@@ -2248,7 +2253,7 @@ function isUtf8Continuation(byte) {
|
|
|
2248
2253
|
}
|
|
2249
2254
|
function shellFor(env) {
|
|
2250
2255
|
const shell = env.SHELL;
|
|
2251
|
-
return shell &&
|
|
2256
|
+
return shell && isAbsolute3(shell) ? shell : "/bin/sh";
|
|
2252
2257
|
}
|
|
2253
2258
|
function killTree(child, signal) {
|
|
2254
2259
|
if (child.pid === void 0) return;
|
|
@@ -2375,7 +2380,7 @@ var HostCommands = class {
|
|
|
2375
2380
|
);
|
|
2376
2381
|
}
|
|
2377
2382
|
const args = spec.args ?? [];
|
|
2378
|
-
if (!Array.isArray(args) || !args.every((
|
|
2383
|
+
if (!Array.isArray(args) || !args.every((arg2) => typeof arg2 === "string")) {
|
|
2379
2384
|
throw new HostCommandError(
|
|
2380
2385
|
"invalid_request",
|
|
2381
2386
|
"`args` must be an array of strings."
|
|
@@ -2392,7 +2397,7 @@ var HostCommands = class {
|
|
|
2392
2397
|
throw new HostCommandError("invalid_request", "The command is too long.");
|
|
2393
2398
|
}
|
|
2394
2399
|
const cwd = spec.cwd ?? homedir2();
|
|
2395
|
-
if (typeof cwd !== "string" || !
|
|
2400
|
+
if (typeof cwd !== "string" || !isAbsolute3(cwd)) {
|
|
2396
2401
|
throw new HostCommandError(
|
|
2397
2402
|
"invalid_request",
|
|
2398
2403
|
"`cwd` must be an absolute path on the machine."
|
|
@@ -2829,6 +2834,12 @@ function createPackageGraphCache(options = {}) {
|
|
|
2829
2834
|
};
|
|
2830
2835
|
}
|
|
2831
2836
|
|
|
2837
|
+
// src/execution-context/service-commands.ts
|
|
2838
|
+
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
2839
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5, readdirSync as readdirSync2 } from "node:fs";
|
|
2840
|
+
import { createInterface } from "node:readline";
|
|
2841
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2842
|
+
|
|
2832
2843
|
// src/execution-context/keystore.ts
|
|
2833
2844
|
import {
|
|
2834
2845
|
createCipheriv,
|
|
@@ -3044,12 +3055,6 @@ function loadContext(input) {
|
|
|
3044
3055
|
return { context, privateJwk: decryptPrivateKey(file, input.wrapping) };
|
|
3045
3056
|
}
|
|
3046
3057
|
|
|
3047
|
-
// src/execution-context/service-commands.ts
|
|
3048
|
-
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
3049
|
-
import { existsSync as existsSync4, readFileSync as readFileSync5, readdirSync as readdirSync2 } from "node:fs";
|
|
3050
|
-
import { createInterface } from "node:readline";
|
|
3051
|
-
import { setTimeout as sleep } from "node:timers/promises";
|
|
3052
|
-
|
|
3053
3058
|
// src/execution-context/service.ts
|
|
3054
3059
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
3055
3060
|
import {
|
|
@@ -4466,6 +4471,242 @@ async function runUpdate(env) {
|
|
|
4466
4471
|
return restarted === services.length ? 0 : 1;
|
|
4467
4472
|
}
|
|
4468
4473
|
|
|
4474
|
+
// src/execution-context/host-access.ts
|
|
4475
|
+
var grantUsage = "Usage: kody context grant [show] [--context <name>] | kody context grant allow <path> [--mode ro|rw] [--context <name>] | kody context grant remove <path> [--context <name>] | kody context grant lan on|off [--context <name>]";
|
|
4476
|
+
function arg(value) {
|
|
4477
|
+
return /^[\w@%+=:,./\\-]+$/.test(value) ? value : JSON.stringify(value);
|
|
4478
|
+
}
|
|
4479
|
+
function overlaps(a, b) {
|
|
4480
|
+
return isWithin(a, b) || isWithin(b, a);
|
|
4481
|
+
}
|
|
4482
|
+
function contextPageUrl(apiUrl, context) {
|
|
4483
|
+
const slug = context.ownerOrg?.slug;
|
|
4484
|
+
return slug ? `${apiUrl.replace(/\/+$/, "")}/@${slug}/-/execution-contexts/${context.id}` : null;
|
|
4485
|
+
}
|
|
4486
|
+
function lanState(mode) {
|
|
4487
|
+
return mode === "public-and-lan" ? "on" : mode === "allowlist" ? "allowlist only" : "off";
|
|
4488
|
+
}
|
|
4489
|
+
function hostAccessNotes(context, policyFs) {
|
|
4490
|
+
const name = arg(context.name);
|
|
4491
|
+
const grantFs = context.hostAccess?.fs;
|
|
4492
|
+
if (!grantFs) {
|
|
4493
|
+
const count = context.grantSummary?.fs;
|
|
4494
|
+
if (count === void 0) return [];
|
|
4495
|
+
if (policyFs.length > 0 && count === 0) {
|
|
4496
|
+
return [
|
|
4497
|
+
`This machine's local policy allows host folders, but ${context.name}'s server grant lists none (grant.fs: 0), so runs cannot use them. Someone with Contribute or Manage on ${context.name} can turn it on with: kody context grant allow <folder> --mode ro|rw --context ${name}`
|
|
4498
|
+
];
|
|
4499
|
+
}
|
|
4500
|
+
if (policyFs.length === 0 && count > 0) {
|
|
4501
|
+
return [
|
|
4502
|
+
`${context.name}'s server grant lists host folders, but this machine's local policy allows none, so runs cannot use them. The machine owner can allow one with: kody context policy allow <folder> --mode ro|rw`
|
|
4503
|
+
];
|
|
4504
|
+
}
|
|
4505
|
+
return [];
|
|
4506
|
+
}
|
|
4507
|
+
const notes = [];
|
|
4508
|
+
for (const rule of policyFs) {
|
|
4509
|
+
if (grantFs.some((entry) => overlaps(entry.path, rule.path))) continue;
|
|
4510
|
+
notes.push(
|
|
4511
|
+
`${rule.path} (local policy ${rule.mode}) is not in ${context.name}'s server grant, so runs cannot use it. Turn it on with: kody context grant allow ${arg(rule.path)} --mode ${rule.mode} --context ${name}`
|
|
4512
|
+
);
|
|
4513
|
+
}
|
|
4514
|
+
for (const entry of grantFs) {
|
|
4515
|
+
if (policyFs.some((rule) => overlaps(entry.path, rule.path))) continue;
|
|
4516
|
+
notes.push(
|
|
4517
|
+
`${entry.path} (server grant ${entry.mode}) is not allowed by this machine's local policy, so runs cannot use it. The machine owner can allow it with: kody context policy allow ${arg(entry.path)} --mode ${entry.mode}`
|
|
4518
|
+
);
|
|
4519
|
+
}
|
|
4520
|
+
return notes;
|
|
4521
|
+
}
|
|
4522
|
+
function describeServerGrant(apiUrl, context) {
|
|
4523
|
+
const fs = context.hostAccess?.fs;
|
|
4524
|
+
const egress = context.hostAccess?.egress.mode ?? context.grantSummary?.egress.mode;
|
|
4525
|
+
const page = contextPageUrl(apiUrl, context);
|
|
4526
|
+
return [
|
|
4527
|
+
`Server grant for ${context.name} (Kody's side; changing it needs Contribute or Manage on the context):`,
|
|
4528
|
+
fs ? fs.length === 0 ? " Host folders (grant.fs): none" : [
|
|
4529
|
+
" Host folders (grant.fs):",
|
|
4530
|
+
...fs.map((entry) => ` ${entry.mode} ${entry.path}`)
|
|
4531
|
+
].join("\n") : ` Host folders (grant.fs): ${context.grantSummary?.fs ?? 0}`,
|
|
4532
|
+
...egress ? [` Local network (grant.egress ${egress}): ${lanState(egress)}`] : [],
|
|
4533
|
+
...page ? [` Page: ${page}`] : []
|
|
4534
|
+
].join("\n");
|
|
4535
|
+
}
|
|
4536
|
+
async function getContext(api, id) {
|
|
4537
|
+
const body = await apiJson({
|
|
4538
|
+
...api,
|
|
4539
|
+
method: "GET",
|
|
4540
|
+
path: `/v1/execution-contexts/${encodeURIComponent(id)}`
|
|
4541
|
+
});
|
|
4542
|
+
return body.context;
|
|
4543
|
+
}
|
|
4544
|
+
async function resolveId(api, ref) {
|
|
4545
|
+
if (ref.startsWith("ec_")) return ref;
|
|
4546
|
+
const body = await apiJson({
|
|
4547
|
+
...api,
|
|
4548
|
+
method: "GET",
|
|
4549
|
+
path: "/v1/execution-contexts"
|
|
4550
|
+
});
|
|
4551
|
+
const match = (body.contexts ?? []).find((c) => c.name === ref);
|
|
4552
|
+
if (!match) throw new Error(`No execution context named ${ref} in this org.`);
|
|
4553
|
+
return match.id;
|
|
4554
|
+
}
|
|
4555
|
+
async function machineGrantNotes(input) {
|
|
4556
|
+
const ids = storedContextIds(input.apiUrl);
|
|
4557
|
+
if (ids.length === 0) return [];
|
|
4558
|
+
let token;
|
|
4559
|
+
try {
|
|
4560
|
+
token = await input.token();
|
|
4561
|
+
} catch (error) {
|
|
4562
|
+
return [
|
|
4563
|
+
{
|
|
4564
|
+
id: null,
|
|
4565
|
+
name: null,
|
|
4566
|
+
notes: [],
|
|
4567
|
+
error: `Could not check the server grant (grant.fs) for this machine's contexts: ${firstLine(error)}`
|
|
4568
|
+
}
|
|
4569
|
+
];
|
|
4570
|
+
}
|
|
4571
|
+
return await Promise.all(
|
|
4572
|
+
ids.map(async (id) => {
|
|
4573
|
+
try {
|
|
4574
|
+
const context = await getContext({ ...input, token }, id);
|
|
4575
|
+
return {
|
|
4576
|
+
id,
|
|
4577
|
+
name: context.name,
|
|
4578
|
+
notes: hostAccessNotes(context, input.policyFs)
|
|
4579
|
+
};
|
|
4580
|
+
} catch (error) {
|
|
4581
|
+
return {
|
|
4582
|
+
id,
|
|
4583
|
+
name: null,
|
|
4584
|
+
notes: [],
|
|
4585
|
+
error: `Could not check the server grant for ${id}: ${firstLine(error)}`
|
|
4586
|
+
};
|
|
4587
|
+
}
|
|
4588
|
+
})
|
|
4589
|
+
);
|
|
4590
|
+
}
|
|
4591
|
+
function describeMachineGrantNotes(results) {
|
|
4592
|
+
if (results.length === 0) return "";
|
|
4593
|
+
const lines = results.flatMap(
|
|
4594
|
+
(result) => "error" in result && result.error ? [` ${result.error}`] : result.notes.length === 0 ? [` ${result.name}: server grant and local policy agree.`] : result.notes.map((note) => ` ${note}`)
|
|
4595
|
+
);
|
|
4596
|
+
return `
|
|
4597
|
+
Server grant check (a run can use a folder only if both layers allow it):
|
|
4598
|
+
${lines.join("\n")}`;
|
|
4599
|
+
}
|
|
4600
|
+
function firstLine(error) {
|
|
4601
|
+
return (error instanceof Error ? error.message : String(error)).split("\n")[0];
|
|
4602
|
+
}
|
|
4603
|
+
async function runGrantCommand(input) {
|
|
4604
|
+
const [action = "show", target, ...extra] = input.positionals;
|
|
4605
|
+
const valid = action === "show" && target === void 0 || (action === "allow" || action === "remove") && target !== void 0 || action === "lan" && (target === "on" || target === "off");
|
|
4606
|
+
if (!valid || extra.length > 0) throw new Error(grantUsage);
|
|
4607
|
+
const ref = input.values.context ?? localContextId(input.apiUrl);
|
|
4608
|
+
if (!ref) {
|
|
4609
|
+
throw new Error(
|
|
4610
|
+
`No execution context is registered on this machine; pass --context <name>.
|
|
4611
|
+
${grantUsage}`
|
|
4612
|
+
);
|
|
4613
|
+
}
|
|
4614
|
+
const api = {
|
|
4615
|
+
apiUrl: input.apiUrl,
|
|
4616
|
+
...input.org ? { org: input.org } : {},
|
|
4617
|
+
...input.fetchFn ? { fetchFn: input.fetchFn } : {},
|
|
4618
|
+
token: await input.token()
|
|
4619
|
+
};
|
|
4620
|
+
const onThisMachine = localContextId(input.apiUrl, ref);
|
|
4621
|
+
const id = onThisMachine ?? await resolveId(api, ref);
|
|
4622
|
+
let context = await getContext(api, id);
|
|
4623
|
+
const emit = async (summary) => {
|
|
4624
|
+
const policy = onThisMachine ? await readLocalPolicy() : null;
|
|
4625
|
+
const notes = policy ? hostAccessNotes(context, policy.fs) : [];
|
|
4626
|
+
const text = [
|
|
4627
|
+
...summary ? [summary] : [],
|
|
4628
|
+
describeServerGrant(input.apiUrl, context),
|
|
4629
|
+
...notes.length > 0 ? [
|
|
4630
|
+
"This machine (a run can use a folder only if both layers allow it):",
|
|
4631
|
+
...notes.map((note) => ` ${note}`)
|
|
4632
|
+
] : []
|
|
4633
|
+
].join("\n");
|
|
4634
|
+
input.write(
|
|
4635
|
+
input.values.json ? `${JSON.stringify({ context, ...policy ? { localPolicy: policy.fs, notes } : {} }, null, 2)}
|
|
4636
|
+
` : `${text}
|
|
4637
|
+
`
|
|
4638
|
+
);
|
|
4639
|
+
return 0;
|
|
4640
|
+
};
|
|
4641
|
+
if (action === "show") return await emit(null);
|
|
4642
|
+
const access = context.hostAccess;
|
|
4643
|
+
if (!access) {
|
|
4644
|
+
throw new Error(
|
|
4645
|
+
`Changing ${context.name}'s server grant needs Contribute or Manage on it (the same check as executionContextUpdate). Ask its operator or someone who manages it${contextPageUrl(input.apiUrl, context) ? `: ${contextPageUrl(input.apiUrl, context)}` : "."}`
|
|
4646
|
+
);
|
|
4647
|
+
}
|
|
4648
|
+
const patch = async (grant) => {
|
|
4649
|
+
const body = await apiJson({
|
|
4650
|
+
...api,
|
|
4651
|
+
method: "PATCH",
|
|
4652
|
+
path: `/v1/execution-contexts/${encodeURIComponent(id)}`,
|
|
4653
|
+
body: { grant }
|
|
4654
|
+
});
|
|
4655
|
+
context = body.context ?? context;
|
|
4656
|
+
};
|
|
4657
|
+
if (action === "lan") {
|
|
4658
|
+
const mode2 = access.egress.mode;
|
|
4659
|
+
if (target === "on") {
|
|
4660
|
+
if (mode2 === "public-and-lan") {
|
|
4661
|
+
return await emit(
|
|
4662
|
+
`The local network is already on for ${context.name}.`
|
|
4663
|
+
);
|
|
4664
|
+
}
|
|
4665
|
+
if (mode2 !== "public") {
|
|
4666
|
+
throw new Error(
|
|
4667
|
+
`${context.name}'s egress is ${mode2}, not public. \`kody context grant lan on\` only switches public to public-and-lan; change a ${mode2} egress with executionContextUpdate grant.egress or on the context page.`
|
|
4668
|
+
);
|
|
4669
|
+
}
|
|
4670
|
+
await patch({ egress: { mode: "public-and-lan" } });
|
|
4671
|
+
return await emit(
|
|
4672
|
+
`Turned the local network on in ${context.name}'s server grant (grant.egress public-and-lan).`
|
|
4673
|
+
);
|
|
4674
|
+
}
|
|
4675
|
+
if (mode2 !== "public-and-lan") {
|
|
4676
|
+
return await emit(`The local network is already off for ${context.name}.`);
|
|
4677
|
+
}
|
|
4678
|
+
await patch({ egress: { mode: "public" } });
|
|
4679
|
+
return await emit(
|
|
4680
|
+
`Turned the local network off in ${context.name}'s server grant (grant.egress public).`
|
|
4681
|
+
);
|
|
4682
|
+
}
|
|
4683
|
+
const raw = plainPath(target);
|
|
4684
|
+
if (!isAbsolute(raw)) throw new Error(`${target} is not an absolute path.`);
|
|
4685
|
+
const path = onThisMachine ? await canonicalHostPath(raw).catch((error) => {
|
|
4686
|
+
if (action === "remove") return raw;
|
|
4687
|
+
throw error;
|
|
4688
|
+
}) : raw;
|
|
4689
|
+
const rest = access.fs.filter((entry) => !samePath(entry.path, path));
|
|
4690
|
+
if (action === "remove") {
|
|
4691
|
+
if (rest.length === access.fs.length) {
|
|
4692
|
+
return await emit(`${path} was not in ${context.name}'s server grant.`);
|
|
4693
|
+
}
|
|
4694
|
+
await patch({ fs: rest });
|
|
4695
|
+
return await emit(`Removed ${path} from ${context.name}'s server grant.`);
|
|
4696
|
+
}
|
|
4697
|
+
const mode = input.values.mode ?? "ro";
|
|
4698
|
+
if (mode !== "ro" && mode !== "rw") {
|
|
4699
|
+
throw new Error("--mode must be ro (read-only) or rw (read-write).");
|
|
4700
|
+
}
|
|
4701
|
+
const fs = [...rest, { path, mode }].sort(
|
|
4702
|
+
(a, b) => a.path.localeCompare(b.path)
|
|
4703
|
+
);
|
|
4704
|
+
await patch({ fs });
|
|
4705
|
+
return await emit(
|
|
4706
|
+
`Added ${path} (${mode}) to ${context.name}'s server grant. Running daemons pick this up right away.`
|
|
4707
|
+
);
|
|
4708
|
+
}
|
|
4709
|
+
|
|
4469
4710
|
// src/execution-context/worker-tracker.ts
|
|
4470
4711
|
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
4471
4712
|
import {
|
|
@@ -4635,6 +4876,9 @@ async function runCommand2(input) {
|
|
|
4635
4876
|
if (input.command === "context" && sub === "policy") {
|
|
4636
4877
|
return await runPolicyCommand(input, rest);
|
|
4637
4878
|
}
|
|
4879
|
+
if (input.command === "context" && sub === "grant") {
|
|
4880
|
+
return await runGrantCommand({ ...input, ...base, positionals: rest });
|
|
4881
|
+
}
|
|
4638
4882
|
const serviceEnv = {
|
|
4639
4883
|
apiUrl: input.apiUrl,
|
|
4640
4884
|
clientVersion: input.clientVersion,
|
|
@@ -4798,11 +5042,27 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
4798
5042
|
path: "/v1/execution-contexts"
|
|
4799
5043
|
});
|
|
4800
5044
|
const contexts = body.contexts ?? [];
|
|
5045
|
+
const local = new Set(storedContextIds(input.apiUrl));
|
|
5046
|
+
const policyFs = contexts.some((c) => local.has(c.id)) ? (await readLocalPolicy()).fs : [];
|
|
5047
|
+
const notesFor = (c) => local.has(c.id) ? hostAccessNotes(c, policyFs) : [];
|
|
4801
5048
|
out(
|
|
4802
5049
|
input,
|
|
4803
|
-
|
|
5050
|
+
{
|
|
5051
|
+
...body,
|
|
5052
|
+
...local.size > 0 ? {
|
|
5053
|
+
thisMachine: {
|
|
5054
|
+
localPolicy: policyFs,
|
|
5055
|
+
notes: Object.fromEntries(
|
|
5056
|
+
contexts.filter((c) => local.has(c.id)).map((c) => [c.name, notesFor(c)])
|
|
5057
|
+
)
|
|
5058
|
+
}
|
|
5059
|
+
} : {}
|
|
5060
|
+
},
|
|
4804
5061
|
contexts.length === 0 ? "No execution contexts yet. Register this machine with `kody context register --name <name>`." : contexts.map(
|
|
4805
|
-
(c) =>
|
|
5062
|
+
(c) => [
|
|
5063
|
+
`${c.name} (${c.id}) ${c.status}${c.usable ? "" : `, not usable: ${c.unusableReason}`}${c.grantSummary ? `; server grant: ${c.grantSummary.fs} host folder${c.grantSummary.fs === 1 ? "" : "s"}, LAN ${lanState(c.grantSummary.egress.mode)}` : ""}${local.has(c.id) ? " (this machine)" : ""}`,
|
|
5064
|
+
...notesFor(c).map((note) => ` ${note}`)
|
|
5065
|
+
].join("\n")
|
|
4806
5066
|
).join("\n")
|
|
4807
5067
|
);
|
|
4808
5068
|
return 0;
|
|
@@ -4979,7 +5239,7 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
4979
5239
|
}
|
|
4980
5240
|
const { context, privateKey } = started;
|
|
4981
5241
|
let { serverKeys } = started;
|
|
4982
|
-
const { runContextRun } = await import("./run-executor-
|
|
5242
|
+
const { runContextRun } = await import("./run-executor-RY226HUI.js");
|
|
4983
5243
|
const hostCommands = new HostCommands({
|
|
4984
5244
|
localEnabled: await readLocalCommandsEnabled().catch(() => false)
|
|
4985
5245
|
});
|
|
@@ -5095,6 +5355,7 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
5095
5355
|
const packageGraphCache = createPackageGraphCache();
|
|
5096
5356
|
let stop = "shutdown";
|
|
5097
5357
|
let autoUpdateEnabled = (await readAutoUpdate()).enabled;
|
|
5358
|
+
let reportedServerFsOff = false;
|
|
5098
5359
|
const activity = { runs: 0 };
|
|
5099
5360
|
const updater = startDaemonUpdater({
|
|
5100
5361
|
selfVersion: input.clientVersion,
|
|
@@ -5171,6 +5432,13 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
5171
5432
|
effective: async (grantFs) => {
|
|
5172
5433
|
const policy = await readLocalPolicy();
|
|
5173
5434
|
autoUpdateEnabled = autoUpdateSetting(policy).enabled;
|
|
5435
|
+
const serverOff = grantFs.length === 0 && policy.fs.length > 0;
|
|
5436
|
+
if (serverOff && !reportedServerFsOff) {
|
|
5437
|
+
log(
|
|
5438
|
+
"This machine's local policy allows host folders, but this context's server grant (grant.fs) lists none, so runs get no host folders. Someone with Contribute or Manage on the context can turn it on with: kody context grant allow <folder> --mode ro|rw"
|
|
5439
|
+
);
|
|
5440
|
+
}
|
|
5441
|
+
reportedServerFsOff = serverOff;
|
|
5174
5442
|
return await effectiveFs(grantFs, policy.fs);
|
|
5175
5443
|
},
|
|
5176
5444
|
onChange: (listener) => {
|
|
@@ -5236,7 +5504,7 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
5236
5504
|
return stayStoppedExitCode;
|
|
5237
5505
|
}
|
|
5238
5506
|
throw new Error(
|
|
5239
|
-
"Usage: kody context register --name <name> [--org <slug>] | kody context list | kody context revoke <name> | kody context delete <name> | kody context cancel-run <name> <run id> | kody context policy [show | allow <path> [--mode ro|rw] | remove <path>] | kody context commands [status | on | off] [--context <name>] | kody chain show | add <name> | remove <name> | kody connect --name <name> | kody daemon [--context <ec id>] [--max-concurrent <n>] | kody daemon install | status | logs | restart | start | stop | uninstall | auto-update [on | off | status] | kody update"
|
|
5507
|
+
"Usage: kody context register --name <name> [--org <slug>] | kody context list | kody context revoke <name> | kody context delete <name> | kody context cancel-run <name> <run id> | kody context policy [show | allow <path> [--mode ro|rw] | remove <path>] | kody context grant [show | allow <path> [--mode ro|rw] | remove <path> | lan on|off] [--context <name>] | kody context commands [status | on | off] [--context <name>] | kody chain show | add <name> | remove <name> | kody connect --name <name> | kody daemon [--context <ec id>] [--max-concurrent <n>] | kody daemon install | status | logs | restart | start | stop | uninstall | auto-update [on | off | status] | kody update"
|
|
5240
5508
|
);
|
|
5241
5509
|
}
|
|
5242
5510
|
async function resolveContextId(input) {
|
|
@@ -5356,11 +5624,23 @@ async function runPolicyCommand(input, [action, path, ...extra]) {
|
|
|
5356
5624
|
const describe = (rules) => rules.length === 0 ? `No host folders are allowed on this machine (${file}). Execution-context runs only see their virtual filesystem.` : [
|
|
5357
5625
|
`Host folders this machine allows (${file}):`,
|
|
5358
5626
|
...rules.map((rule) => ` ${rule.mode} ${rule.path}`),
|
|
5359
|
-
"A run can use a folder only if its context grant (grant.fs) also lists it; the narrower mode wins."
|
|
5627
|
+
"This is the local policy. A run can use a folder only if its context server grant (grant.fs) also lists it; the narrower mode wins."
|
|
5360
5628
|
].join("\n");
|
|
5629
|
+
const grantNotes = (fs) => machineGrantNotes({
|
|
5630
|
+
apiUrl: input.apiUrl,
|
|
5631
|
+
...input.org ? { org: input.org } : {},
|
|
5632
|
+
...input.fetchFn ? { fetchFn: input.fetchFn } : {},
|
|
5633
|
+
token: input.token,
|
|
5634
|
+
policyFs: fs
|
|
5635
|
+
});
|
|
5361
5636
|
if (action === void 0 || action === "show") {
|
|
5362
5637
|
const policy = await readLocalPolicy(file);
|
|
5363
|
-
|
|
5638
|
+
const serverGrant = await grantNotes(policy.fs);
|
|
5639
|
+
out(
|
|
5640
|
+
input,
|
|
5641
|
+
{ path: file, ...policy, serverGrant },
|
|
5642
|
+
`${describe(policy.fs)}${describeMachineGrantNotes(serverGrant)}`
|
|
5643
|
+
);
|
|
5364
5644
|
return 0;
|
|
5365
5645
|
}
|
|
5366
5646
|
if (!path || extra.length > 0) throw new Error(policyUsage);
|
|
@@ -5374,11 +5654,12 @@ async function runPolicyCommand(input, [action, path, ...extra]) {
|
|
|
5374
5654
|
mode,
|
|
5375
5655
|
policyPath: file
|
|
5376
5656
|
});
|
|
5657
|
+
const serverGrant = await grantNotes(policy.fs);
|
|
5377
5658
|
out(
|
|
5378
5659
|
input,
|
|
5379
|
-
{ path: file, ...policy },
|
|
5380
|
-
`Allowed ${added.path} (${added.mode}). Running daemons pick this up within a few seconds.
|
|
5381
|
-
${describe(policy.fs)}`
|
|
5660
|
+
{ path: file, ...policy, serverGrant },
|
|
5661
|
+
`Allowed ${added.path} (${added.mode}) in this machine's local policy. Running daemons pick this up within a few seconds. This does not change the context's server grant.
|
|
5662
|
+
${describe(policy.fs)}${describeMachineGrantNotes(serverGrant)}`
|
|
5382
5663
|
);
|
|
5383
5664
|
return 0;
|
|
5384
5665
|
}
|
|
@@ -5413,4 +5694,4 @@ export {
|
|
|
5413
5694
|
maxConcurrentRuns,
|
|
5414
5695
|
runExecutionContextCommand
|
|
5415
5696
|
};
|
|
5416
|
-
//# sourceMappingURL=commands-
|
|
5697
|
+
//# sourceMappingURL=commands-KSLL3FBI.js.map
|