@kodycodes/cli 3.21.0 → 3.22.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/dist/{auth-J5AA2E2W.js → auth-W5RWT6IP.js} +5 -5
- package/dist/bin.js +7 -7
- package/dist/{chunk-LU2BYSFJ.js → chunk-2FU3OO7F.js} +3 -3
- package/dist/{chunk-ZE7DA6IP.js → chunk-5E2HSGBZ.js} +9 -4
- package/dist/{chunk-ZE7DA6IP.js.map → chunk-5E2HSGBZ.js.map} +1 -1
- package/dist/chunk-76OYRT4A.js +144 -0
- package/dist/chunk-76OYRT4A.js.map +6 -0
- package/dist/{chunk-K77ETGIL.js → chunk-BKKWWWCE.js} +43 -42
- package/dist/chunk-BKKWWWCE.js.map +6 -0
- package/dist/{chunk-6IPCLPNQ.js → chunk-CWQVWIAQ.js} +53 -13
- package/dist/chunk-CWQVWIAQ.js.map +6 -0
- package/dist/{chunk-4ZR5HTHC.js → chunk-DBNNDB7I.js} +20 -11
- package/dist/{chunk-4ZR5HTHC.js.map → chunk-DBNNDB7I.js.map} +1 -1
- package/dist/{chunk-7XRBM7AU.js → chunk-DEI4SMFK.js} +3 -3
- package/dist/{chunk-4GIMXYTU.js → chunk-FPYLVYHC.js} +60 -25
- package/dist/{chunk-4GIMXYTU.js.map → chunk-FPYLVYHC.js.map} +1 -1
- package/dist/{chunk-KWAUPCKM.js → chunk-K2G6GYKA.js} +23 -6
- package/dist/chunk-K2G6GYKA.js.map +6 -0
- package/dist/{chunk-EKOYDF24.js → chunk-NPQ2XAK5.js} +3 -3
- package/dist/{chunk-GV5U56NK.js → chunk-OKM2QMOV.js} +3 -3
- package/dist/{chunk-YXGHVHEJ.js → chunk-OXBMXZ6S.js} +106 -17
- package/dist/chunk-OXBMXZ6S.js.map +6 -0
- package/dist/{chunk-FN5KUR6I.js → chunk-RD6ZJU2N.js} +3 -3
- package/dist/{chunk-SCRMD7NW.js → chunk-VRD6DN44.js} +44 -22
- package/dist/chunk-VRD6DN44.js.map +6 -0
- package/dist/{chunk-7RLOLQIT.js → chunk-YBO6HUV3.js} +2 -2
- package/dist/chunk-YBO6HUV3.js.map +6 -0
- package/dist/{chunk-C2WYSCUJ.js → chunk-YQRMKXCC.js} +31 -21
- package/dist/chunk-YQRMKXCC.js.map +6 -0
- package/dist/{chunk-RWERUUUW.js → chunk-ZUROJOJ2.js} +3 -3
- package/dist/{chunk-CWMTTI6P.js → chunk-ZXNYKFSN.js} +3 -3
- package/dist/cli.js +7 -7
- package/dist/{commands-3KZPBDIP.js → commands-XPGR4OT4.js} +274 -26
- package/dist/commands-XPGR4OT4.js.map +6 -0
- package/dist/{dev-command-OMHJWIPL.js → dev-command-67JMY2DZ.js} +16 -14
- package/dist/dev-command-67JMY2DZ.js.map +6 -0
- package/dist/execution-context/client.d.ts +8 -1
- package/dist/execution-context/fs-access.d.ts +16 -1
- package/dist/execution-context/host-commands.d.ts +10 -3
- package/dist/execution-context/runner-lock.d.ts +2 -2
- package/dist/execution-context/service.d.ts +28 -6
- package/dist/execution-context/windows-command.d.ts +34 -0
- package/dist/{git-credential-DPTBUVMO.js → git-credential-BT363OJQ.js} +6 -6
- package/dist/host-fs-shim.d.ts +1 -0
- package/dist/{local-execute-BEH3OVD5.js → local-execute-L6A7FLNN.js} +10 -9
- package/dist/{local-package-graph-4VLBVUTP.js → local-package-graph-WFDNSNOJ.js} +3 -3
- package/dist/{local-package-run-UEGYEUSE.js → local-package-run-RRELUZEM.js} +11 -10
- package/dist/{mock-dep-resolve-76V75ADG.js → mock-dep-resolve-G7TA4CJB.js} +6 -6
- package/dist/{mock-fetch-gateway-HGGKCQYJ.js → mock-fetch-gateway-QNUFNYAH.js} +4 -3
- package/dist/{mock-local-deps-MKLQO7DK.js → mock-local-deps-K2NARQ7F.js} +5 -5
- package/dist/{mock-server-LJB6RFLE.js → mock-server-2FMSQMBT.js} +5 -4
- package/dist/{open-api-client-JEQU23NL.js → open-api-client-DJL2PE7P.js} +4 -4
- package/dist/process-tree.d.ts +13 -0
- package/dist/{remote-execute-KJAK3LW7.js → remote-execute-KUSUI6UT.js} +4 -4
- package/dist/{run-executor-7MV5E5PX.js → run-executor-PJL5KQAY.js} +12 -11
- package/dist/run-executor-PJL5KQAY.js.map +6 -0
- package/dist/{setup-git-EVEFEUCJ.js → setup-git-KBH7GA6E.js} +5 -5
- package/dist/{whoami-E56UFY6Z.js → whoami-SGE7VKGY.js} +3 -3
- package/dist/workerd-binary.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-6IPCLPNQ.js.map +0 -6
- package/dist/chunk-7RLOLQIT.js.map +0 -6
- package/dist/chunk-C2WYSCUJ.js.map +0 -6
- package/dist/chunk-K77ETGIL.js.map +0 -6
- package/dist/chunk-KWAUPCKM.js.map +0 -6
- package/dist/chunk-SCRMD7NW.js.map +0 -6
- package/dist/chunk-YXGHVHEJ.js.map +0 -6
- package/dist/commands-3KZPBDIP.js.map +0 -6
- package/dist/dev-command-OMHJWIPL.js.map +0 -6
- package/dist/run-executor-7MV5E5PX.js.map +0 -6
- /package/dist/{auth-J5AA2E2W.js.map → auth-W5RWT6IP.js.map} +0 -0
- /package/dist/{chunk-LU2BYSFJ.js.map → chunk-2FU3OO7F.js.map} +0 -0
- /package/dist/{chunk-7XRBM7AU.js.map → chunk-DEI4SMFK.js.map} +0 -0
- /package/dist/{chunk-EKOYDF24.js.map → chunk-NPQ2XAK5.js.map} +0 -0
- /package/dist/{chunk-GV5U56NK.js.map → chunk-OKM2QMOV.js.map} +0 -0
- /package/dist/{chunk-FN5KUR6I.js.map → chunk-RD6ZJU2N.js.map} +0 -0
- /package/dist/{chunk-RWERUUUW.js.map → chunk-ZUROJOJ2.js.map} +0 -0
- /package/dist/{chunk-CWMTTI6P.js.map → chunk-ZXNYKFSN.js.map} +0 -0
- /package/dist/{git-credential-DPTBUVMO.js.map → git-credential-BT363OJQ.js.map} +0 -0
- /package/dist/{local-execute-BEH3OVD5.js.map → local-execute-L6A7FLNN.js.map} +0 -0
- /package/dist/{local-package-graph-4VLBVUTP.js.map → local-package-graph-WFDNSNOJ.js.map} +0 -0
- /package/dist/{local-package-run-UEGYEUSE.js.map → local-package-run-RRELUZEM.js.map} +0 -0
- /package/dist/{mock-dep-resolve-76V75ADG.js.map → mock-dep-resolve-G7TA4CJB.js.map} +0 -0
- /package/dist/{mock-fetch-gateway-HGGKCQYJ.js.map → mock-fetch-gateway-QNUFNYAH.js.map} +0 -0
- /package/dist/{mock-local-deps-MKLQO7DK.js.map → mock-local-deps-K2NARQ7F.js.map} +0 -0
- /package/dist/{mock-server-LJB6RFLE.js.map → mock-server-2FMSQMBT.js.map} +0 -0
- /package/dist/{open-api-client-JEQU23NL.js.map → open-api-client-DJL2PE7P.js.map} +0 -0
- /package/dist/{remote-execute-KJAK3LW7.js.map → remote-execute-KUSUI6UT.js.map} +0 -0
- /package/dist/{setup-git-EVEFEUCJ.js.map → setup-git-KBH7GA6E.js.map} +0 -0
- /package/dist/{whoami-E56UFY6Z.js.map → whoami-SGE7VKGY.js.map} +0 -0
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
OpenApiError,
|
|
13
13
|
openApiGet,
|
|
14
14
|
openApiRequest
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-DEI4SMFK.js";
|
|
16
16
|
import {
|
|
17
17
|
isScopedApiToken,
|
|
18
18
|
notAuthenticatedMessage
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-FPYLVYHC.js";
|
|
20
20
|
import {
|
|
21
21
|
fileStorePath,
|
|
22
22
|
loadCredentialStore,
|
|
@@ -2346,4 +2346,4 @@ export {
|
|
|
2346
2346
|
login,
|
|
2347
2347
|
loginWithDevice
|
|
2348
2348
|
};
|
|
2349
|
-
//# sourceMappingURL=chunk-
|
|
2349
|
+
//# sourceMappingURL=chunk-ZXNYKFSN.js.map
|
package/dist/cli.js
CHANGED
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
resolvePackagePublishTarget,
|
|
14
14
|
runCli,
|
|
15
15
|
storedApiTokenAfterLoginNotice
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-BKKWWWCE.js";
|
|
17
17
|
import "./chunk-M7PRSUCC.js";
|
|
18
18
|
import "./chunk-7PRJ36I5.js";
|
|
19
19
|
import "./chunk-SLNAWWQK.js";
|
|
20
20
|
import {
|
|
21
21
|
resolveLocalExecuteBearer
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-RD6ZJU2N.js";
|
|
23
23
|
import "./chunk-2XPH7L2P.js";
|
|
24
24
|
import {
|
|
25
25
|
authBootstrap,
|
|
@@ -32,21 +32,21 @@ import {
|
|
|
32
32
|
parseCliScopesFlag,
|
|
33
33
|
redeemBootstrapCode,
|
|
34
34
|
resolveCliTokenLifetime
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-2FU3OO7F.js";
|
|
36
36
|
import "./chunk-6ZYUGXVW.js";
|
|
37
|
-
import "./chunk-
|
|
37
|
+
import "./chunk-ZXNYKFSN.js";
|
|
38
38
|
import "./chunk-GVSGNTG6.js";
|
|
39
39
|
import "./chunk-CWWHR4FH.js";
|
|
40
40
|
import "./chunk-CASGRYOF.js";
|
|
41
|
-
import "./chunk-
|
|
41
|
+
import "./chunk-DEI4SMFK.js";
|
|
42
42
|
import "./chunk-46IJPEID.js";
|
|
43
43
|
import {
|
|
44
44
|
readApiToken,
|
|
45
45
|
requireApiToken,
|
|
46
46
|
resolveScopedApiToken
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-FPYLVYHC.js";
|
|
48
48
|
import "./chunk-FHLTB67D.js";
|
|
49
|
-
import "./chunk-
|
|
49
|
+
import "./chunk-K2G6GYKA.js";
|
|
50
50
|
import "./chunk-NHRYNRXG.js";
|
|
51
51
|
import "./chunk-D6XME4RY.js";
|
|
52
52
|
import "./chunk-VP2O3HLT.js";
|
|
@@ -8,8 +8,10 @@ import {
|
|
|
8
8
|
ecpMaxConcurrentRunsCap,
|
|
9
9
|
ecpPingFrame,
|
|
10
10
|
ecpProtocolVersion,
|
|
11
|
+
ecpRootPublicKeys,
|
|
11
12
|
ecpRunHeader,
|
|
12
13
|
ecpSignatureHeader,
|
|
14
|
+
ecpTestRootPublicKey,
|
|
13
15
|
ed25519JwkThumbprint,
|
|
14
16
|
formatEcpSignatureHeader,
|
|
15
17
|
importEd25519PrivateKey,
|
|
@@ -19,7 +21,7 @@ import {
|
|
|
19
21
|
signFrame,
|
|
20
22
|
verifyFrame,
|
|
21
23
|
verifyServerKeySet
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-CWQVWIAQ.js";
|
|
23
25
|
import {
|
|
24
26
|
allowLocalPath,
|
|
25
27
|
createLocalWorkerTracker,
|
|
@@ -27,16 +29,19 @@ import {
|
|
|
27
29
|
effectiveFs,
|
|
28
30
|
emptyEffectiveFs,
|
|
29
31
|
fsFeatures,
|
|
32
|
+
killProcessTree,
|
|
30
33
|
localPolicyPath,
|
|
31
34
|
readLocalCommandsEnabled,
|
|
32
35
|
readLocalPolicy,
|
|
33
36
|
reapLeftoverWorkers,
|
|
34
37
|
removeLocalPath,
|
|
35
38
|
setLocalAutoUpdateEnabled,
|
|
36
|
-
setLocalCommandsEnabled
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import "./chunk-
|
|
39
|
+
setLocalCommandsEnabled,
|
|
40
|
+
windowsCommandLine
|
|
41
|
+
} from "./chunk-OXBMXZ6S.js";
|
|
42
|
+
import "./chunk-OKM2QMOV.js";
|
|
43
|
+
import "./chunk-76OYRT4A.js";
|
|
44
|
+
import "./chunk-FPYLVYHC.js";
|
|
40
45
|
import {
|
|
41
46
|
apiTokenFileStorePath
|
|
42
47
|
} from "./chunk-FHLTB67D.js";
|
|
@@ -51,7 +56,13 @@ import {
|
|
|
51
56
|
import "./chunk-UW6AWLXX.js";
|
|
52
57
|
|
|
53
58
|
// src/execution-context/commands.ts
|
|
54
|
-
import {
|
|
59
|
+
import {
|
|
60
|
+
appendFileSync,
|
|
61
|
+
readFileSync as readFileSync6,
|
|
62
|
+
rmSync as rmSync4,
|
|
63
|
+
unwatchFile,
|
|
64
|
+
watchFile
|
|
65
|
+
} from "node:fs";
|
|
55
66
|
import { cpus, platform, totalmem } from "node:os";
|
|
56
67
|
|
|
57
68
|
// src/execution-context/client.ts
|
|
@@ -222,12 +233,22 @@ async function setContextCommands(input) {
|
|
|
222
233
|
if (!response.ok) throw await readError(response);
|
|
223
234
|
return await response.json();
|
|
224
235
|
}
|
|
236
|
+
function serverKeyRootsFor(apiUrl, env = process.env) {
|
|
237
|
+
if (env.KODY_ECP_TRUST_TEST_ROOT !== "1") return ecpRootPublicKeys;
|
|
238
|
+
const { protocol, hostname } = new URL(apiUrl);
|
|
239
|
+
const host = hostname.toLowerCase();
|
|
240
|
+
const testHost = protocol === "https:" && host.endsWith(".workers.dev") || host === "localhost";
|
|
241
|
+
return testHost ? [...ecpRootPublicKeys, ecpTestRootPublicKey] : ecpRootPublicKeys;
|
|
242
|
+
}
|
|
225
243
|
async function fetchServerKeys(input) {
|
|
226
244
|
const response = await (input.fetchFn ?? fetch)(
|
|
227
245
|
new URL(`${executionContextsPath}/server-keys`, input.apiUrl)
|
|
228
246
|
);
|
|
229
247
|
if (!response.ok) throw await readError(response);
|
|
230
|
-
const set = await verifyServerKeySet({
|
|
248
|
+
const set = await verifyServerKeySet({
|
|
249
|
+
document: await response.json(),
|
|
250
|
+
roots: serverKeyRootsFor(input.apiUrl, input.env)
|
|
251
|
+
});
|
|
231
252
|
if (!set) {
|
|
232
253
|
throw new Error(
|
|
233
254
|
"Kody server keys failed root signature verification. Refusing to connect."
|
|
@@ -908,7 +929,8 @@ async function superviseNewerVersion(input) {
|
|
|
908
929
|
);
|
|
909
930
|
const forward = (signal) => () => {
|
|
910
931
|
try {
|
|
911
|
-
child.kill(signal);
|
|
932
|
+
if (process.platform !== "win32") child.kill(signal);
|
|
933
|
+
else if (signal !== "SIGINT" && child.pid) killProcessTree(child.pid);
|
|
912
934
|
} catch {
|
|
913
935
|
}
|
|
914
936
|
};
|
|
@@ -1636,7 +1658,7 @@ function isAlive(pid) {
|
|
|
1636
1658
|
}
|
|
1637
1659
|
}
|
|
1638
1660
|
function commandOf(pid) {
|
|
1639
|
-
if (process.platform === "win32") return
|
|
1661
|
+
if (process.platform === "win32") return windowsCommandLine(pid);
|
|
1640
1662
|
try {
|
|
1641
1663
|
return execFileSync("ps", ["-o", "command=", "-p", String(pid)], {
|
|
1642
1664
|
encoding: "utf8",
|
|
@@ -1764,6 +1786,7 @@ function acquireRunnerLock(path, info, check = {}) {
|
|
|
1764
1786
|
function describeLauncher(launcher) {
|
|
1765
1787
|
if (launcher === "systemd") return "the systemd service";
|
|
1766
1788
|
if (launcher === "launchd") return "the launchd service";
|
|
1789
|
+
if (launcher === "taskscheduler") return "the Task Scheduler task";
|
|
1767
1790
|
if (launcher === "desktop") return "the Kody desktop app";
|
|
1768
1791
|
return "a terminal";
|
|
1769
1792
|
}
|
|
@@ -2021,28 +2044,35 @@ import {
|
|
|
2021
2044
|
writeFileSync as writeFileSync4
|
|
2022
2045
|
} from "node:fs";
|
|
2023
2046
|
import { homedir as homedir2, tmpdir, userInfo } from "node:os";
|
|
2024
|
-
import {
|
|
2047
|
+
import { dirname as dirname4, join as join3, sep as sep2 } from "node:path";
|
|
2025
2048
|
var serviceEnvVar = "KODY_DAEMON_SERVICE";
|
|
2026
2049
|
var stayStoppedExitCode = 0;
|
|
2027
2050
|
function serviceManagerFor(platform2 = process.platform) {
|
|
2028
2051
|
if (platform2 === "linux") return "systemd";
|
|
2029
2052
|
if (platform2 === "darwin") return "launchd";
|
|
2053
|
+
if (platform2 === "win32") return "taskscheduler";
|
|
2030
2054
|
return null;
|
|
2031
2055
|
}
|
|
2032
|
-
|
|
2056
|
+
function isServiceManager(value) {
|
|
2057
|
+
return value === "systemd" || value === "launchd" || value === "taskscheduler";
|
|
2058
|
+
}
|
|
2059
|
+
var unsupportedPlatformMessage = "Running kody daemon as a background service is supported on Linux (systemd), macOS (launchd), and Windows (Task Scheduler). Keep `kody daemon` running in a terminal on this machine instead.";
|
|
2033
2060
|
function serviceName(ecid) {
|
|
2034
2061
|
return `kody-daemon-${ecid}`;
|
|
2035
2062
|
}
|
|
2036
2063
|
function launchdLabel(ecid) {
|
|
2037
2064
|
return `codes.kody.daemon.${ecid}`;
|
|
2038
2065
|
}
|
|
2066
|
+
function scheduledTaskName(ecid) {
|
|
2067
|
+
return `\\Kody\\${serviceName(ecid)}`;
|
|
2068
|
+
}
|
|
2039
2069
|
function servicePaths(input) {
|
|
2040
2070
|
const home = input.home ?? homedir2();
|
|
2041
2071
|
const env = input.env ?? process.env;
|
|
2042
2072
|
const dir = contextDir(input.apiUrl, input.ecid);
|
|
2043
2073
|
return {
|
|
2044
2074
|
manager: input.manager,
|
|
2045
|
-
unitPath: input.manager === "systemd" ? join3(
|
|
2075
|
+
unitPath: input.manager === "taskscheduler" ? join3(dir, "daemon-task.ps1") : input.manager === "systemd" ? join3(
|
|
2046
2076
|
env.XDG_CONFIG_HOME || join3(home, ".config"),
|
|
2047
2077
|
"systemd",
|
|
2048
2078
|
"user",
|
|
@@ -2104,10 +2134,16 @@ function servicePath(input) {
|
|
|
2104
2134
|
"/usr/sbin",
|
|
2105
2135
|
"/sbin"
|
|
2106
2136
|
];
|
|
2107
|
-
return [...new Set(dirs)].join(platform2 === "win32" ? ";" :
|
|
2137
|
+
return [...new Set(dirs)].join(platform2 === "win32" ? ";" : ":");
|
|
2108
2138
|
}
|
|
2109
2139
|
function serviceEnvironment(input) {
|
|
2110
2140
|
const env = input.env ?? process.env;
|
|
2141
|
+
if (input.paths.manager === "taskscheduler") {
|
|
2142
|
+
return {
|
|
2143
|
+
[serviceEnvVar]: input.paths.manager,
|
|
2144
|
+
...env.XDG_CONFIG_HOME ? { XDG_CONFIG_HOME: env.XDG_CONFIG_HOME } : {}
|
|
2145
|
+
};
|
|
2146
|
+
}
|
|
2111
2147
|
return {
|
|
2112
2148
|
PATH: servicePath({
|
|
2113
2149
|
node: input.program.node,
|
|
@@ -2199,10 +2235,96 @@ ${Object.entries(env).map(
|
|
|
2199
2235
|
</plist>
|
|
2200
2236
|
`;
|
|
2201
2237
|
}
|
|
2238
|
+
function powershellQuote(value) {
|
|
2239
|
+
return `'${value.replace(/[\n\r]/g, "").replace(/'/g, "''")}'`;
|
|
2240
|
+
}
|
|
2241
|
+
function taskSchedulerScript(input) {
|
|
2242
|
+
const env = serviceEnvironment(input);
|
|
2243
|
+
return [
|
|
2244
|
+
"\uFEFF# Written by `kody daemon install`. Re-run it to repair; remove with `kody daemon uninstall`.",
|
|
2245
|
+
`# Kody execution context ${input.contextName.replace(/[\n\r]/g, " ")} (${input.ecid})`,
|
|
2246
|
+
...Object.entries(env).map(
|
|
2247
|
+
([key, value]) => `$env:${key} = ${powershellQuote(value)}`
|
|
2248
|
+
),
|
|
2249
|
+
`Set-Location -LiteralPath ${powershellQuote(input.paths.workingDir)}`,
|
|
2250
|
+
"while ($true) {",
|
|
2251
|
+
` & ${[input.program.node, ...daemonArgs(input)].map(powershellQuote).join(" ")}`,
|
|
2252
|
+
` if ($LASTEXITCODE -eq ${stayStoppedExitCode}) { break }`,
|
|
2253
|
+
" Start-Sleep -Seconds 10",
|
|
2254
|
+
"}",
|
|
2255
|
+
""
|
|
2256
|
+
].join("\r\n");
|
|
2257
|
+
}
|
|
2258
|
+
function windowsUser(env = process.env) {
|
|
2259
|
+
const name = env.USERNAME || userInfo().username;
|
|
2260
|
+
return env.USERDOMAIN ? `${env.USERDOMAIN}\\${name}` : name;
|
|
2261
|
+
}
|
|
2262
|
+
function scheduledTaskXml(input) {
|
|
2263
|
+
const user = xml(input.user ?? windowsUser());
|
|
2264
|
+
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
2265
|
+
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
2266
|
+
<RegistrationInfo>
|
|
2267
|
+
<Description>Kody execution context ${xml(input.ecid)}. Written by kody daemon install; remove with kody daemon uninstall.</Description>
|
|
2268
|
+
<URI>${xml(scheduledTaskName(input.ecid))}</URI>
|
|
2269
|
+
</RegistrationInfo>
|
|
2270
|
+
<Triggers>
|
|
2271
|
+
<LogonTrigger>
|
|
2272
|
+
<Enabled>true</Enabled>
|
|
2273
|
+
<UserId>${user}</UserId>
|
|
2274
|
+
</LogonTrigger>
|
|
2275
|
+
</Triggers>
|
|
2276
|
+
<Principals>
|
|
2277
|
+
<Principal id="Author">
|
|
2278
|
+
<UserId>${user}</UserId>
|
|
2279
|
+
<LogonType>InteractiveToken</LogonType>
|
|
2280
|
+
<RunLevel>LeastPrivilege</RunLevel>
|
|
2281
|
+
</Principal>
|
|
2282
|
+
</Principals>
|
|
2283
|
+
<Settings>
|
|
2284
|
+
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
|
|
2285
|
+
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
|
|
2286
|
+
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
|
|
2287
|
+
<AllowHardTerminate>true</AllowHardTerminate>
|
|
2288
|
+
<StartWhenAvailable>true</StartWhenAvailable>
|
|
2289
|
+
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
|
|
2290
|
+
<IdleSettings>
|
|
2291
|
+
<StopOnIdleEnd>false</StopOnIdleEnd>
|
|
2292
|
+
<RestartOnIdle>false</RestartOnIdle>
|
|
2293
|
+
</IdleSettings>
|
|
2294
|
+
<AllowStartOnDemand>true</AllowStartOnDemand>
|
|
2295
|
+
<Enabled>true</Enabled>
|
|
2296
|
+
<Hidden>false</Hidden>
|
|
2297
|
+
<RunOnlyIfIdle>false</RunOnlyIfIdle>
|
|
2298
|
+
<WakeToRun>false</WakeToRun>
|
|
2299
|
+
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
|
|
2300
|
+
<Priority>7</Priority>
|
|
2301
|
+
<RestartOnFailure>
|
|
2302
|
+
<Interval>PT1M</Interval>
|
|
2303
|
+
<Count>3</Count>
|
|
2304
|
+
</RestartOnFailure>
|
|
2305
|
+
</Settings>
|
|
2306
|
+
<Actions Context="Author">
|
|
2307
|
+
<Exec>
|
|
2308
|
+
<Command>powershell.exe</Command>
|
|
2309
|
+
<Arguments>-NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File "${xml(input.scriptPath)}"</Arguments>
|
|
2310
|
+
<WorkingDirectory>${xml(input.workingDir)}</WorkingDirectory>
|
|
2311
|
+
</Exec>
|
|
2312
|
+
</Actions>
|
|
2313
|
+
</Task>
|
|
2314
|
+
`;
|
|
2315
|
+
}
|
|
2202
2316
|
function unitFor(input) {
|
|
2317
|
+
if (input.paths.manager === "taskscheduler") return taskSchedulerScript(input);
|
|
2203
2318
|
return input.paths.manager === "systemd" ? systemdUnit(input) : launchdPlist(input);
|
|
2204
2319
|
}
|
|
2205
2320
|
function programInUnit(text, manager) {
|
|
2321
|
+
if (manager === "taskscheduler") {
|
|
2322
|
+
const line = text.split(/\r?\n/).find((l) => /^\s*& '/.test(l));
|
|
2323
|
+
const quoted = [...(line ?? "").matchAll(/'((?:[^']|'')*)'/g)].map(
|
|
2324
|
+
(match) => match[1].replace(/''/g, "'")
|
|
2325
|
+
);
|
|
2326
|
+
return { node: quoted[0] ?? null, entry: quoted[1] ?? null };
|
|
2327
|
+
}
|
|
2206
2328
|
if (manager === "systemd") {
|
|
2207
2329
|
const line = text.split("\n").find((l) => l.startsWith("ExecStart="));
|
|
2208
2330
|
const quoted = [...(line ?? "").matchAll(/"((?:[^"\\]|\\.)*)"/g)].map(
|
|
@@ -2225,7 +2347,8 @@ var runCommand = (command, args) => {
|
|
|
2225
2347
|
const stdout = execFileSync2(command, args, {
|
|
2226
2348
|
encoding: "utf8",
|
|
2227
2349
|
stdio: ["ignore", "pipe", "pipe"],
|
|
2228
|
-
timeout: 3e4
|
|
2350
|
+
timeout: 3e4,
|
|
2351
|
+
windowsHide: true
|
|
2229
2352
|
});
|
|
2230
2353
|
return { ok: true, stdout, stderr: "" };
|
|
2231
2354
|
} catch (error) {
|
|
@@ -2258,7 +2381,41 @@ function writeJson(path, value) {
|
|
|
2258
2381
|
function lingerCommand(user = userInfo().username) {
|
|
2259
2382
|
return `sudo loginctl enable-linger ${user}`;
|
|
2260
2383
|
}
|
|
2384
|
+
function powershell(run, script) {
|
|
2385
|
+
return run("powershell.exe", [
|
|
2386
|
+
"-NoProfile",
|
|
2387
|
+
"-NonInteractive",
|
|
2388
|
+
"-Command",
|
|
2389
|
+
script
|
|
2390
|
+
]);
|
|
2391
|
+
}
|
|
2392
|
+
function scheduledTaskState(ecid, run) {
|
|
2393
|
+
const name = serviceName(ecid);
|
|
2394
|
+
const shown = powershell(
|
|
2395
|
+
run,
|
|
2396
|
+
`$task = Get-ScheduledTask -TaskPath '\\Kody\\' -TaskName '${name}' -ErrorAction SilentlyContinue; if ($task) { $task.State.ToString() } else { 'Missing' }`
|
|
2397
|
+
);
|
|
2398
|
+
const state = shown.stdout.trim();
|
|
2399
|
+
return { reachable: shown.ok, state: state === "Missing" ? null : state };
|
|
2400
|
+
}
|
|
2401
|
+
function endScheduledTask(ecid, statePath, run) {
|
|
2402
|
+
run("schtasks.exe", ["/End", "/TN", scheduledTaskName(ecid)]);
|
|
2403
|
+
const runtime = readJson(statePath);
|
|
2404
|
+
if (!runtime?.pid || runtime.service !== "taskscheduler") return;
|
|
2405
|
+
const commandLine = windowsCommandLine(runtime.pid);
|
|
2406
|
+
if (commandLine?.includes("daemon") && commandLine.includes(ecid))
|
|
2407
|
+
killProcessTree(runtime.pid, "win32");
|
|
2408
|
+
}
|
|
2261
2409
|
function managerState(input) {
|
|
2410
|
+
if (input.manager === "taskscheduler") {
|
|
2411
|
+
const { reachable, state } = scheduledTaskState(input.ecid, input.run);
|
|
2412
|
+
return {
|
|
2413
|
+
reachable,
|
|
2414
|
+
enabled: state !== null && state !== "Disabled",
|
|
2415
|
+
running: state === "Running",
|
|
2416
|
+
pid: null
|
|
2417
|
+
};
|
|
2418
|
+
}
|
|
2262
2419
|
if (input.manager === "systemd") {
|
|
2263
2420
|
const unit = `${serviceName(input.ecid)}.service`;
|
|
2264
2421
|
const shown = input.run("systemctl", [
|
|
@@ -2401,6 +2558,13 @@ function serviceStatus(input) {
|
|
|
2401
2558
|
});
|
|
2402
2559
|
}
|
|
2403
2560
|
const state = managerState({ manager, ecid: input.ecid, run });
|
|
2561
|
+
if (manager === "taskscheduler" && !state.reachable) {
|
|
2562
|
+
base.problems.push({
|
|
2563
|
+
code: "user-manager-unavailable",
|
|
2564
|
+
message: "Could not read the scheduled task (Get-ScheduledTask failed in Windows PowerShell).",
|
|
2565
|
+
fix: `schtasks /Query /TN ${scheduledTaskName(input.ecid)}`
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2404
2568
|
if (manager === "systemd") {
|
|
2405
2569
|
if (!state.reachable) {
|
|
2406
2570
|
base.problems.push({
|
|
@@ -2523,6 +2687,33 @@ function installService(input) {
|
|
|
2523
2687
|
warnings
|
|
2524
2688
|
};
|
|
2525
2689
|
}
|
|
2690
|
+
if (input.paths.manager === "taskscheduler") {
|
|
2691
|
+
const name = scheduledTaskName(input.ecid);
|
|
2692
|
+
const definition = scheduledTaskXml({
|
|
2693
|
+
ecid: input.ecid,
|
|
2694
|
+
scriptPath: input.paths.unitPath,
|
|
2695
|
+
workingDir: input.paths.workingDir
|
|
2696
|
+
});
|
|
2697
|
+
const xmlPath = input.paths.unitPath.replace(/\.ps1$/, ".xml");
|
|
2698
|
+
writeFileSync4(xmlPath, Buffer.from(`\uFEFF${definition}`, "utf16le"));
|
|
2699
|
+
must(
|
|
2700
|
+
"schtasks.exe",
|
|
2701
|
+
["/Create", "/TN", name, "/XML", xmlPath, "/F"],
|
|
2702
|
+
"register the scheduled task"
|
|
2703
|
+
);
|
|
2704
|
+
rmSync3(xmlPath, { force: true });
|
|
2705
|
+
const running = scheduledTaskState(input.ecid, run).state === "Running";
|
|
2706
|
+
if (running && (changed || input.restart)) {
|
|
2707
|
+
endScheduledTask(input.ecid, input.paths.statePath, run);
|
|
2708
|
+
}
|
|
2709
|
+
if (!running || changed || input.restart)
|
|
2710
|
+
must("schtasks.exe", ["/Run", "/TN", name], "start the scheduled task");
|
|
2711
|
+
return {
|
|
2712
|
+
changed,
|
|
2713
|
+
restarted: running && (changed || input.restart),
|
|
2714
|
+
warnings
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2526
2717
|
const target = launchdTarget(input.ecid);
|
|
2527
2718
|
const loaded = run("launchctl", ["print", target]).ok;
|
|
2528
2719
|
run("launchctl", ["enable", target]);
|
|
@@ -2546,6 +2737,17 @@ function installService(input) {
|
|
|
2546
2737
|
}
|
|
2547
2738
|
function restartService(input) {
|
|
2548
2739
|
const run = input.run ?? runCommand;
|
|
2740
|
+
if (input.manager === "taskscheduler") {
|
|
2741
|
+
if (input.statePath) endScheduledTask(input.ecid, input.statePath, run);
|
|
2742
|
+
const started = run("schtasks.exe", [
|
|
2743
|
+
"/Run",
|
|
2744
|
+
"/TN",
|
|
2745
|
+
scheduledTaskName(input.ecid)
|
|
2746
|
+
]);
|
|
2747
|
+
if (!started.ok)
|
|
2748
|
+
throw new Error(`Could not restart the service: ${started.stderr.trim()}`);
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2549
2751
|
const result = input.manager === "systemd" ? (run("systemctl", [
|
|
2550
2752
|
"--user",
|
|
2551
2753
|
"reset-failed",
|
|
@@ -2561,12 +2763,25 @@ function restartService(input) {
|
|
|
2561
2763
|
function startService(input) {
|
|
2562
2764
|
const run = input.run ?? runCommand;
|
|
2563
2765
|
const unit = `${serviceName(input.ecid)}.service`;
|
|
2766
|
+
if (input.manager === "taskscheduler") {
|
|
2767
|
+
const name = scheduledTaskName(input.ecid);
|
|
2768
|
+
run("schtasks.exe", ["/Change", "/TN", name, "/ENABLE"]);
|
|
2769
|
+
const started = run("schtasks.exe", ["/Run", "/TN", name]);
|
|
2770
|
+
if (!started.ok)
|
|
2771
|
+
throw new Error(`Could not start the service: ${started.stderr.trim()}`);
|
|
2772
|
+
return;
|
|
2773
|
+
}
|
|
2564
2774
|
const result = input.manager === "systemd" ? (run("systemctl", ["--user", "reset-failed", unit]), run("systemctl", ["--user", "start", unit])) : (run("launchctl", ["enable", launchdTarget(input.ecid)]), run("launchctl", ["kickstart", launchdTarget(input.ecid)]));
|
|
2565
2775
|
if (!result.ok)
|
|
2566
2776
|
throw new Error(`Could not start the service: ${result.stderr.trim()}`);
|
|
2567
2777
|
}
|
|
2568
2778
|
function stopService(input) {
|
|
2569
2779
|
const run = input.run ?? runCommand;
|
|
2780
|
+
if (input.manager === "taskscheduler") {
|
|
2781
|
+
if (input.statePath) endScheduledTask(input.ecid, input.statePath, run);
|
|
2782
|
+
else run("schtasks.exe", ["/End", "/TN", scheduledTaskName(input.ecid)]);
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2570
2785
|
const result = input.manager === "systemd" ? run("systemctl", [
|
|
2571
2786
|
"--user",
|
|
2572
2787
|
"stop",
|
|
@@ -2583,6 +2798,10 @@ function uninstallService(input) {
|
|
|
2583
2798
|
rmSync3(input.paths.unitPath, { force: true });
|
|
2584
2799
|
run("systemctl", ["--user", "daemon-reload"]);
|
|
2585
2800
|
run("systemctl", ["--user", "reset-failed", unit]);
|
|
2801
|
+
} else if (input.paths.manager === "taskscheduler") {
|
|
2802
|
+
endScheduledTask(input.ecid, input.paths.statePath, run);
|
|
2803
|
+
run("schtasks.exe", ["/Delete", "/TN", scheduledTaskName(input.ecid), "/F"]);
|
|
2804
|
+
rmSync3(input.paths.unitPath, { force: true });
|
|
2586
2805
|
} else {
|
|
2587
2806
|
run("launchctl", ["bootout", launchdTarget(input.ecid)]);
|
|
2588
2807
|
rmSync3(input.paths.unitPath, { force: true });
|
|
@@ -2596,6 +2815,13 @@ function disableOwnService(input) {
|
|
|
2596
2815
|
"disable",
|
|
2597
2816
|
`${serviceName(input.ecid)}.service`
|
|
2598
2817
|
]);
|
|
2818
|
+
} else if (input.manager === "taskscheduler") {
|
|
2819
|
+
run("schtasks.exe", [
|
|
2820
|
+
"/Change",
|
|
2821
|
+
"/TN",
|
|
2822
|
+
scheduledTaskName(input.ecid),
|
|
2823
|
+
"/DISABLE"
|
|
2824
|
+
]);
|
|
2599
2825
|
} else {
|
|
2600
2826
|
run("launchctl", ["disable", launchdTarget(input.ecid)]);
|
|
2601
2827
|
}
|
|
@@ -2661,7 +2887,7 @@ function isRoot(env) {
|
|
|
2661
2887
|
}
|
|
2662
2888
|
function maxConcurrentInUnit(text) {
|
|
2663
2889
|
const match = text?.match(
|
|
2664
|
-
/--max-concurrent(?:"?\s+"
|
|
2890
|
+
/--max-concurrent(?:"?\s+"?|'\s+'|<\/string>\s*<string>)(\d+)/
|
|
2665
2891
|
);
|
|
2666
2892
|
return match ? Number(match[1]) : void 0;
|
|
2667
2893
|
}
|
|
@@ -2896,10 +3122,15 @@ async function startOrStopRunner(env, input) {
|
|
|
2896
3122
|
stopService({
|
|
2897
3123
|
manager: input.manager,
|
|
2898
3124
|
ecid: input.ecid,
|
|
3125
|
+
statePath: servicePaths({
|
|
3126
|
+
apiUrl: env.apiUrl,
|
|
3127
|
+
ecid: input.ecid,
|
|
3128
|
+
manager: input.manager
|
|
3129
|
+
}).statePath,
|
|
2899
3130
|
...env.run ? { run: env.run } : {}
|
|
2900
3131
|
});
|
|
2901
3132
|
const other = runner && runner.pid > 0 && runner.launcher !== input.manager ? runner : null;
|
|
2902
|
-
if (other)
|
|
3133
|
+
if (other) stopDaemonProcess(other.pid);
|
|
2903
3134
|
say(
|
|
2904
3135
|
`Stopped the kody daemon service after runs in flight finish.${other ? ` Also stopping the kody daemon that held this context (${describeHolder(other)}).` : ""} It starts again at the next login or boot, or with \`kody daemon start\`.`,
|
|
2905
3136
|
{ service: input.manager, ...other ? { runner: other } : {} }
|
|
@@ -2910,13 +3141,17 @@ async function startOrStopRunner(env, input) {
|
|
|
2910
3141
|
say("No kody daemon is running this context.");
|
|
2911
3142
|
return 0;
|
|
2912
3143
|
}
|
|
2913
|
-
|
|
3144
|
+
stopDaemonProcess(runner.pid);
|
|
2914
3145
|
say(
|
|
2915
3146
|
`Stopping the kody daemon (${describeHolder(runner)}) after runs in flight finish.`,
|
|
2916
3147
|
{ runner }
|
|
2917
3148
|
);
|
|
2918
3149
|
return 0;
|
|
2919
3150
|
}
|
|
3151
|
+
function stopDaemonProcess(pid) {
|
|
3152
|
+
if (process.platform === "win32") killProcessTree(pid, "win32");
|
|
3153
|
+
else process.kill(pid, "SIGTERM");
|
|
3154
|
+
}
|
|
2920
3155
|
async function runAutoUpdateCommand(env, action) {
|
|
2921
3156
|
if (action === "on" || action === "off") {
|
|
2922
3157
|
await setLocalAutoUpdateEnabled({ enabled: action === "on" });
|
|
@@ -3051,7 +3286,12 @@ ${runner ? ` Runner: ${describeHolder(runner)}
|
|
|
3051
3286
|
}
|
|
3052
3287
|
if (input.sub === "restart") {
|
|
3053
3288
|
const before = runtimeState(paths.statePath);
|
|
3054
|
-
restartService({
|
|
3289
|
+
restartService({
|
|
3290
|
+
manager,
|
|
3291
|
+
ecid,
|
|
3292
|
+
statePath: paths.statePath,
|
|
3293
|
+
...env.run ? { run: env.run } : {}
|
|
3294
|
+
});
|
|
3055
3295
|
env.write(
|
|
3056
3296
|
"Restarting the kody daemon service. Runs in flight finish first.\n"
|
|
3057
3297
|
);
|
|
@@ -3557,10 +3797,11 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
3557
3797
|
);
|
|
3558
3798
|
}
|
|
3559
3799
|
const asService = process.env[serviceEnvVar];
|
|
3560
|
-
const manager = asService
|
|
3800
|
+
const manager = isServiceManager(asService) ? asService : null;
|
|
3561
3801
|
const paths = manager ? servicePaths({ apiUrl: input.apiUrl, ecid, manager }) : null;
|
|
3562
3802
|
const supervised = process.env[supervisedEnvVar] === "1";
|
|
3563
3803
|
if (paths && !supervised) rotateLog(paths.logPath);
|
|
3804
|
+
if (paths && manager === "taskscheduler") appendOutputTo(paths.logPath);
|
|
3564
3805
|
const readAutoUpdate = async () => autoUpdateSetting(await readLocalPolicy().catch(() => null));
|
|
3565
3806
|
const relaunchArgs = [
|
|
3566
3807
|
"daemon",
|
|
@@ -3605,7 +3846,7 @@ Run \`kody daemon\` in a terminal, or fix that and run: kody daemon install --co
|
|
|
3605
3846
|
}
|
|
3606
3847
|
const { context, privateKey } = started;
|
|
3607
3848
|
let { serverKeys } = started;
|
|
3608
|
-
const { runContextRun } = await import("./run-executor-
|
|
3849
|
+
const { runContextRun } = await import("./run-executor-PJL5KQAY.js");
|
|
3609
3850
|
const hostCommands = new HostCommands({
|
|
3610
3851
|
localEnabled: await readLocalCommandsEnabled().catch(() => false)
|
|
3611
3852
|
});
|
|
@@ -3879,11 +4120,6 @@ async function runCommandsOptInCommand(input, [action = "status", ...extra]) {
|
|
|
3879
4120
|
if (extra.length > 0 || !["status", "on", "off"].includes(action)) {
|
|
3880
4121
|
throw new Error(commandsUsage);
|
|
3881
4122
|
}
|
|
3882
|
-
if (process.platform === "win32" && action === "on") {
|
|
3883
|
-
throw new Error(
|
|
3884
|
-
"Host commands are not supported on Windows yet: the Kody runner supports macOS and Linux. (execution_context_commands_unsupported)"
|
|
3885
|
-
);
|
|
3886
|
-
}
|
|
3887
4123
|
const ecids = input.values.context ? [
|
|
3888
4124
|
localContextId(input.apiUrl, input.values.context) ?? input.values.context
|
|
3889
4125
|
] : storedContextIds(input.apiUrl);
|
|
@@ -4003,6 +4239,18 @@ ${describe(policy.fs)}`
|
|
|
4003
4239
|
}
|
|
4004
4240
|
throw new Error(policyUsage);
|
|
4005
4241
|
}
|
|
4242
|
+
function appendOutputTo(path) {
|
|
4243
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
4244
|
+
const write = stream.write.bind(stream);
|
|
4245
|
+
stream.write = ((chunk, ...rest) => {
|
|
4246
|
+
try {
|
|
4247
|
+
appendFileSync(path, chunk, { mode: 384 });
|
|
4248
|
+
} catch {
|
|
4249
|
+
}
|
|
4250
|
+
return write(chunk, ...rest);
|
|
4251
|
+
});
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4006
4254
|
export {
|
|
4007
4255
|
defaultMaxConcurrentRuns,
|
|
4008
4256
|
localCapabilities,
|
|
@@ -4010,4 +4258,4 @@ export {
|
|
|
4010
4258
|
readCodeFile,
|
|
4011
4259
|
runExecutionContextCommand
|
|
4012
4260
|
};
|
|
4013
|
-
//# sourceMappingURL=commands-
|
|
4261
|
+
//# sourceMappingURL=commands-XPGR4OT4.js.map
|