@abelxiaoxing/cadence 2.0.27 → 2.0.29
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.de.md +2 -1
- package/README.es.md +2 -1
- package/README.fr.md +2 -1
- package/README.ja.md +3 -1
- package/README.ko.md +5 -1
- package/README.md +2 -1
- package/README.pt-BR.md +2 -1
- package/README.ru.md +2 -1
- package/README.zh-CN.md +2 -1
- package/docs/service-management.md +23 -1
- package/package.json +1 -1
- package/src/conversation-context.mjs +84 -19
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +5 -4
- package/src/service/contracts/workbench.ts +89 -6
- package/src/service-cli.mjs +390 -64
- package/src/service-host.mjs +1632 -706
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +16 -16
- package/web/dist/manifest.json +7 -7
package/src/service-cli.mjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Generated by scripts/build-service.mjs; edit the entry and source modules.
|
|
3
3
|
|
|
4
4
|
// src/service/cli.ts
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
5
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
6
6
|
import { mkdirSync as mkdirSync6 } from "node:fs";
|
|
7
7
|
import { request } from "node:http";
|
|
8
8
|
import { homedir as homedir7 } from "node:os";
|
|
9
|
-
import { dirname as
|
|
9
|
+
import { dirname as dirname13, join as join18, resolve as resolve7 } from "node:path";
|
|
10
10
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
11
11
|
|
|
12
12
|
// src/install-config.mjs
|
|
@@ -2526,6 +2526,13 @@ function hostSystem(root, owner, selection = {}) {
|
|
|
2526
2526
|
unit,
|
|
2527
2527
|
scope,
|
|
2528
2528
|
uid: process.getuid?.(),
|
|
2529
|
+
cgroup: () => {
|
|
2530
|
+
try {
|
|
2531
|
+
return readFileSync("/proc/self/cgroup", "utf8");
|
|
2532
|
+
} catch {
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2535
|
+
},
|
|
2529
2536
|
systemctl: (args) => run("systemctl", [scope === "system" ? "--system" : "--user", ...args]),
|
|
2530
2537
|
linger: () => {
|
|
2531
2538
|
const r = run("loginctl", [
|
|
@@ -2709,6 +2716,20 @@ function unitWorkspace(text2) {
|
|
|
2709
2716
|
return null;
|
|
2710
2717
|
return text2?.match(/^WorkingDirectory=(.+)$/m)?.[1].replaceAll("%%", "%");
|
|
2711
2718
|
}
|
|
2719
|
+
function unitEnvironment(text2) {
|
|
2720
|
+
const out = [];
|
|
2721
|
+
for (const line of text2.split(`
|
|
2722
|
+
`)) {
|
|
2723
|
+
if (!line.startsWith("Environment="))
|
|
2724
|
+
continue;
|
|
2725
|
+
const value = JSON.parse(line.slice("Environment=".length));
|
|
2726
|
+
if (typeof value !== "string" || value.indexOf("=") < 1)
|
|
2727
|
+
throw new ContractError("invalid");
|
|
2728
|
+
const at = value.indexOf("=");
|
|
2729
|
+
out.push([value.slice(0, at), value.slice(at + 1).replaceAll("%%", "%")]);
|
|
2730
|
+
}
|
|
2731
|
+
return out;
|
|
2732
|
+
}
|
|
2712
2733
|
function directory(path2) {
|
|
2713
2734
|
try {
|
|
2714
2735
|
return isAbsolute3(path2) && statSync2(path2).isDirectory();
|
|
@@ -2874,6 +2895,80 @@ function autostartStatus(s) {
|
|
|
2874
2895
|
};
|
|
2875
2896
|
}
|
|
2876
2897
|
|
|
2898
|
+
// src/service/contracts/gateway.ts
|
|
2899
|
+
function decodeProjectEntry(value) {
|
|
2900
|
+
const o = closed(value, ["id", "path", "cwd", "epoch"]);
|
|
2901
|
+
return {
|
|
2902
|
+
id: decodeHash(o.id),
|
|
2903
|
+
path: text(o.path, 4096, true),
|
|
2904
|
+
cwd: text(o.cwd, 4096, true),
|
|
2905
|
+
epoch: decodeId(o.epoch)
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
var RECOVERY_SCOPES = ["registry", "workbench", "project"];
|
|
2909
|
+
var RECOVERY_CAUSES = [
|
|
2910
|
+
"reboot",
|
|
2911
|
+
"crash",
|
|
2912
|
+
"restart",
|
|
2913
|
+
"storage"
|
|
2914
|
+
];
|
|
2915
|
+
var RECOVERY_ACTIONS = [
|
|
2916
|
+
"released-locks",
|
|
2917
|
+
"stopped-workers",
|
|
2918
|
+
"stopped-owner",
|
|
2919
|
+
"continued-history",
|
|
2920
|
+
"archived-history",
|
|
2921
|
+
"archived-state",
|
|
2922
|
+
"rebuilt-registry",
|
|
2923
|
+
"removed-temporaries"
|
|
2924
|
+
];
|
|
2925
|
+
var MAINTENANCE_ACTIONS = ["restart", "upgrade"];
|
|
2926
|
+
var MAINTENANCE_STATES = [
|
|
2927
|
+
"running",
|
|
2928
|
+
"ready",
|
|
2929
|
+
"failed",
|
|
2930
|
+
"rolled-back"
|
|
2931
|
+
];
|
|
2932
|
+
var MAINTENANCE_REASONS = [
|
|
2933
|
+
"fetch-failed",
|
|
2934
|
+
"stop-unconfirmed",
|
|
2935
|
+
"install-failed",
|
|
2936
|
+
"not-ready",
|
|
2937
|
+
"refused",
|
|
2938
|
+
"interrupted"
|
|
2939
|
+
];
|
|
2940
|
+
var VERSION = /^(?:0|[1-9][0-9]{0,8})\.(?:0|[1-9][0-9]{0,8})\.(?:0|[1-9][0-9]{0,8})(?:-[0-9A-Za-z.-]{1,64})?$/;
|
|
2941
|
+
function decodeVersion(value) {
|
|
2942
|
+
const version = text(value, 96, true);
|
|
2943
|
+
if (!VERSION.test(version))
|
|
2944
|
+
throw new ContractError("invalid");
|
|
2945
|
+
return version;
|
|
2946
|
+
}
|
|
2947
|
+
function decodeMaintenanceJob(value) {
|
|
2948
|
+
const o = closed(value, [
|
|
2949
|
+
"id",
|
|
2950
|
+
"action",
|
|
2951
|
+
"from",
|
|
2952
|
+
"to",
|
|
2953
|
+
"state",
|
|
2954
|
+
"reason",
|
|
2955
|
+
"version",
|
|
2956
|
+
"at",
|
|
2957
|
+
"endedAt"
|
|
2958
|
+
]);
|
|
2959
|
+
return {
|
|
2960
|
+
id: decodeId(o.id),
|
|
2961
|
+
action: oneOf(o.action, MAINTENANCE_ACTIONS),
|
|
2962
|
+
from: decodeVersion(o.from),
|
|
2963
|
+
to: o.to === null ? null : decodeVersion(o.to),
|
|
2964
|
+
state: oneOf(o.state, MAINTENANCE_STATES),
|
|
2965
|
+
reason: o.reason === null ? null : oneOf(o.reason, MAINTENANCE_REASONS),
|
|
2966
|
+
version: o.version === null ? null : decodeVersion(o.version),
|
|
2967
|
+
at: integer(o.at, 0),
|
|
2968
|
+
endedAt: o.endedAt === null ? null : integer(o.endedAt, 0)
|
|
2969
|
+
};
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2877
2972
|
// src/service/coordination.ts
|
|
2878
2973
|
import { randomBytes as randomBytes2, randomUUID as randomUUID3 } from "node:crypto";
|
|
2879
2974
|
import { opendirSync } from "node:fs";
|
|
@@ -4109,34 +4204,6 @@ class HttpAuthentication {
|
|
|
4109
4204
|
}
|
|
4110
4205
|
}
|
|
4111
4206
|
|
|
4112
|
-
// src/service/contracts/gateway.ts
|
|
4113
|
-
function decodeProjectEntry(value) {
|
|
4114
|
-
const o = closed(value, ["id", "path", "cwd", "epoch"]);
|
|
4115
|
-
return {
|
|
4116
|
-
id: decodeHash(o.id),
|
|
4117
|
-
path: text(o.path, 4096, true),
|
|
4118
|
-
cwd: text(o.cwd, 4096, true),
|
|
4119
|
-
epoch: decodeId(o.epoch)
|
|
4120
|
-
};
|
|
4121
|
-
}
|
|
4122
|
-
var RECOVERY_SCOPES = ["registry", "workbench", "project"];
|
|
4123
|
-
var RECOVERY_CAUSES = [
|
|
4124
|
-
"reboot",
|
|
4125
|
-
"crash",
|
|
4126
|
-
"restart",
|
|
4127
|
-
"storage"
|
|
4128
|
-
];
|
|
4129
|
-
var RECOVERY_ACTIONS = [
|
|
4130
|
-
"released-locks",
|
|
4131
|
-
"stopped-workers",
|
|
4132
|
-
"stopped-owner",
|
|
4133
|
-
"continued-history",
|
|
4134
|
-
"archived-history",
|
|
4135
|
-
"archived-state",
|
|
4136
|
-
"rebuilt-registry",
|
|
4137
|
-
"removed-temporaries"
|
|
4138
|
-
];
|
|
4139
|
-
|
|
4140
4207
|
// src/service/gateway-store.ts
|
|
4141
4208
|
function decodeGatewayInput(value) {
|
|
4142
4209
|
const o = closed(value, [
|
|
@@ -6120,9 +6187,207 @@ async function loginRunStatus(s) {
|
|
|
6120
6187
|
};
|
|
6121
6188
|
}
|
|
6122
6189
|
|
|
6190
|
+
// src/service/maintenance.ts
|
|
6191
|
+
import { spawn, spawnSync as spawnSync4 } from "node:child_process";
|
|
6192
|
+
import { accessSync, constants as constants4, readFileSync as readFileSync3, realpathSync as realpathSync5 } from "node:fs";
|
|
6193
|
+
import { dirname as dirname12, join as join16 } from "node:path";
|
|
6194
|
+
var PACKAGE = "@abelxiaoxing/cadence";
|
|
6195
|
+
var VIEW_MS = 30000;
|
|
6196
|
+
var INSTALL_MS = 15 * 60000;
|
|
6197
|
+
var RESTART_MS = 5 * 60000;
|
|
6198
|
+
function cgroupPath(text2) {
|
|
6199
|
+
const lines = text2?.split(`
|
|
6200
|
+
`) ?? [];
|
|
6201
|
+
const find = (pattern) => lines.map((line) => pattern.exec(line)?.[1]).find(Boolean);
|
|
6202
|
+
return find(/^\d+:name=systemd:(\/.*)$/) ?? find(/^0::(\/.*)$/);
|
|
6203
|
+
}
|
|
6204
|
+
function insideUnit(s) {
|
|
6205
|
+
if (s.platform !== "linux")
|
|
6206
|
+
return false;
|
|
6207
|
+
const own = cgroupPath(s.cgroup());
|
|
6208
|
+
if (!own)
|
|
6209
|
+
return false;
|
|
6210
|
+
const unit = s.systemctl(["show", "--property=ControlGroup", "--value", s.unit]).stdout.trim();
|
|
6211
|
+
return unit !== "" && (own === unit || own.startsWith(`${unit}/`));
|
|
6212
|
+
}
|
|
6213
|
+
function installedVersion(root) {
|
|
6214
|
+
const value = JSON.parse(readFileSync3(join16(root, "package.json"), "utf8"));
|
|
6215
|
+
if (!value || typeof value !== "object" || !("name" in value))
|
|
6216
|
+
throw new ContractError("invalid");
|
|
6217
|
+
literal(value.name, PACKAGE);
|
|
6218
|
+
return decodeVersion("version" in value ? value.version : undefined);
|
|
6219
|
+
}
|
|
6220
|
+
|
|
6221
|
+
class MaintenanceRecord {
|
|
6222
|
+
store;
|
|
6223
|
+
constructor(store) {
|
|
6224
|
+
this.store = store;
|
|
6225
|
+
}
|
|
6226
|
+
get path() {
|
|
6227
|
+
return this.store.path("maintenance.json");
|
|
6228
|
+
}
|
|
6229
|
+
read() {
|
|
6230
|
+
const file = this.store.files.read(this.path);
|
|
6231
|
+
if (!file)
|
|
6232
|
+
return null;
|
|
6233
|
+
const o = closed(json(file), ["schema", "job"]);
|
|
6234
|
+
literal(o.schema, "cadence-maintenance-job/1");
|
|
6235
|
+
return decodeMaintenanceJob(o.job);
|
|
6236
|
+
}
|
|
6237
|
+
write(job2) {
|
|
6238
|
+
const bytes = encoded({ schema: "cadence-maintenance-job/1", job: job2 });
|
|
6239
|
+
const current = this.store.files.read(this.path);
|
|
6240
|
+
if (current)
|
|
6241
|
+
this.store.files.replace(this.path, current, bytes);
|
|
6242
|
+
else
|
|
6243
|
+
this.store.files.create(this.path, bytes);
|
|
6244
|
+
}
|
|
6245
|
+
finish(id, state, reason, version) {
|
|
6246
|
+
const job2 = this.read();
|
|
6247
|
+
if (job2?.id !== id || job2.state !== "running")
|
|
6248
|
+
return;
|
|
6249
|
+
this.write({ ...job2, state, reason, version, endedAt: Date.now() });
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
var npm = (args, show = false) => run("npm", args, show ? INSTALL_MS : VIEW_MS, show);
|
|
6253
|
+
function run(command, args, timeout, show = false) {
|
|
6254
|
+
return new Promise((resolve7) => {
|
|
6255
|
+
const child = spawn(command, args, {
|
|
6256
|
+
stdio: ["ignore", show ? 2 : "pipe", show ? 2 : "ignore"],
|
|
6257
|
+
timeout,
|
|
6258
|
+
windowsHide: true
|
|
6259
|
+
});
|
|
6260
|
+
let stdout = "";
|
|
6261
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => {
|
|
6262
|
+
if (stdout.length < 1 << 20)
|
|
6263
|
+
stdout += chunk;
|
|
6264
|
+
});
|
|
6265
|
+
child.once("error", () => resolve7({ status: null, stdout: "" }));
|
|
6266
|
+
child.once("close", (status) => resolve7({ status, stdout }));
|
|
6267
|
+
});
|
|
6268
|
+
}
|
|
6269
|
+
async function upgradeRoute(root, npmRun = npm) {
|
|
6270
|
+
const result = await npmRun(["root", "--global"]);
|
|
6271
|
+
const global = result.status === 0 ? result.stdout.trim() : "";
|
|
6272
|
+
let installed;
|
|
6273
|
+
try {
|
|
6274
|
+
installed = realpathSync5(join16(global, ...PACKAGE.split("/")));
|
|
6275
|
+
if (!global || installed !== realpathSync5(root))
|
|
6276
|
+
return "not-npm-global";
|
|
6277
|
+
} catch {
|
|
6278
|
+
return "not-npm-global";
|
|
6279
|
+
}
|
|
6280
|
+
try {
|
|
6281
|
+
accessSync(dirname12(installed), constants4.W_OK);
|
|
6282
|
+
accessSync(global, constants4.W_OK);
|
|
6283
|
+
} catch {
|
|
6284
|
+
return "not-writable";
|
|
6285
|
+
}
|
|
6286
|
+
return "npm";
|
|
6287
|
+
}
|
|
6288
|
+
async function release(spec = "latest", npmRun = npm) {
|
|
6289
|
+
const result = await npmRun([
|
|
6290
|
+
"view",
|
|
6291
|
+
`${PACKAGE}@${spec}`,
|
|
6292
|
+
"version",
|
|
6293
|
+
"deprecated",
|
|
6294
|
+
"--json"
|
|
6295
|
+
]);
|
|
6296
|
+
if (result.status !== 0)
|
|
6297
|
+
return;
|
|
6298
|
+
try {
|
|
6299
|
+
const value = JSON.parse(result.stdout);
|
|
6300
|
+
if (typeof value === "string")
|
|
6301
|
+
return { version: decodeVersion(value), deprecated: false };
|
|
6302
|
+
const o = closed(value, ["version", "deprecated"]);
|
|
6303
|
+
return {
|
|
6304
|
+
version: decodeVersion(o.version),
|
|
6305
|
+
deprecated: typeof o.deprecated === "string"
|
|
6306
|
+
};
|
|
6307
|
+
} catch {
|
|
6308
|
+
return;
|
|
6309
|
+
}
|
|
6310
|
+
}
|
|
6311
|
+
async function restartInstalled(s) {
|
|
6312
|
+
const name = serviceName(s);
|
|
6313
|
+
const result = await run(s.node, [
|
|
6314
|
+
join16(s.root, "src", "service-cli.mjs"),
|
|
6315
|
+
"server",
|
|
6316
|
+
"restart",
|
|
6317
|
+
s.scope === "system" ? "--system" : "--user",
|
|
6318
|
+
...name ? ["--name", name] : []
|
|
6319
|
+
], RESTART_MS);
|
|
6320
|
+
try {
|
|
6321
|
+
const value = JSON.parse(result.stdout.trim().split(`
|
|
6322
|
+
`).at(-1) ?? "");
|
|
6323
|
+
return !!value && typeof value === "object" && "status" in value && value.status === "started" && "service" in value && value.service === "alive";
|
|
6324
|
+
} catch {
|
|
6325
|
+
return false;
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6328
|
+
async function upgradeService(s, to, ports) {
|
|
6329
|
+
const route = await upgradeRoute(s.root, ports.npm);
|
|
6330
|
+
if (route !== "npm")
|
|
6331
|
+
return { status: route };
|
|
6332
|
+
const from = installedVersion(s.root);
|
|
6333
|
+
const target2 = await release(to, ports.npm);
|
|
6334
|
+
if (!target2)
|
|
6335
|
+
return { status: "failed", reason: "fetch-failed", from };
|
|
6336
|
+
const versions = { from, to: target2.version };
|
|
6337
|
+
if (target2.version === from)
|
|
6338
|
+
return { status: "current", version: from, ...versions };
|
|
6339
|
+
if (target2.deprecated)
|
|
6340
|
+
return { status: "deprecated", ...versions };
|
|
6341
|
+
const spec = `${PACKAGE}@${target2.version}`;
|
|
6342
|
+
if ((await ports.npm(["cache", "add", spec], true)).status !== 0)
|
|
6343
|
+
return { status: "failed", reason: "fetch-failed", ...versions };
|
|
6344
|
+
const stopped = await ports.stop();
|
|
6345
|
+
if (stopped.status !== "stopped")
|
|
6346
|
+
return { ...stopped, reason: "stop-unconfirmed", ...versions };
|
|
6347
|
+
const install = (version) => ports.npm([
|
|
6348
|
+
"install",
|
|
6349
|
+
"--global",
|
|
6350
|
+
"--no-audit",
|
|
6351
|
+
"--no-fund",
|
|
6352
|
+
`${PACKAGE}@${version}`
|
|
6353
|
+
], true);
|
|
6354
|
+
const settled = (status, reason) => ({
|
|
6355
|
+
status,
|
|
6356
|
+
...reason ? { reason } : {},
|
|
6357
|
+
...versions,
|
|
6358
|
+
version: installedVersion(s.root)
|
|
6359
|
+
});
|
|
6360
|
+
if ((await install(target2.version)).status !== 0) {
|
|
6361
|
+
await ports.restart();
|
|
6362
|
+
return settled("failed", "install-failed");
|
|
6363
|
+
}
|
|
6364
|
+
if (await ports.restart())
|
|
6365
|
+
return settled("upgraded");
|
|
6366
|
+
if ((await install(from)).status === 0 && await ports.restart())
|
|
6367
|
+
return settled("rolled-back", "not-ready");
|
|
6368
|
+
return settled("failed", "not-ready");
|
|
6369
|
+
}
|
|
6370
|
+
function jobOutcome(action, result) {
|
|
6371
|
+
if (action === "upgrade") {
|
|
6372
|
+
if (result.status === "upgraded" || result.status === "current")
|
|
6373
|
+
return { state: "ready", reason: null };
|
|
6374
|
+
if (result.status === "rolled-back")
|
|
6375
|
+
return { state: "rolled-back", reason: "not-ready" };
|
|
6376
|
+
return { state: "failed", reason: result.reason ?? "refused" };
|
|
6377
|
+
}
|
|
6378
|
+
if (result.status === "started")
|
|
6379
|
+
return result.service === "alive" ? { state: "ready", reason: null } : { state: "failed", reason: "not-ready" };
|
|
6380
|
+
if (result.status === "failed")
|
|
6381
|
+
return { state: "failed", reason: "not-ready" };
|
|
6382
|
+
return {
|
|
6383
|
+
state: "failed",
|
|
6384
|
+
reason: ["unconfirmed", "quarantined", "unavailable"].includes(result.status) ? "stop-unconfirmed" : "refused"
|
|
6385
|
+
};
|
|
6386
|
+
}
|
|
6387
|
+
|
|
6123
6388
|
// src/service/system-service.ts
|
|
6124
|
-
import { existsSync as existsSync3, realpathSync as
|
|
6125
|
-
import { isAbsolute as isAbsolute8, join as
|
|
6389
|
+
import { existsSync as existsSync3, realpathSync as realpathSync6, rmSync as rmSync6 } from "node:fs";
|
|
6390
|
+
import { isAbsolute as isAbsolute8, join as join17 } from "node:path";
|
|
6126
6391
|
var MARKER4 = "# Generated by @abelxiaoxing/cadence";
|
|
6127
6392
|
function boundary(s) {
|
|
6128
6393
|
if (s.platform !== "linux" || s.scope !== "system")
|
|
@@ -6148,22 +6413,10 @@ function masked(s) {
|
|
|
6148
6413
|
}
|
|
6149
6414
|
function sameStateEnvironment(s, previous) {
|
|
6150
6415
|
try {
|
|
6151
|
-
const
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
continue;
|
|
6156
|
-
const value = JSON.parse(line.slice("Environment=".length));
|
|
6157
|
-
if (typeof value !== "string")
|
|
6158
|
-
return false;
|
|
6159
|
-
const at = value.indexOf("=");
|
|
6160
|
-
const key = value.slice(0, at);
|
|
6161
|
-
if (key !== "HOME" && key !== "XDG_STATE_HOME")
|
|
6162
|
-
continue;
|
|
6163
|
-
if (values.has(key))
|
|
6164
|
-
return false;
|
|
6165
|
-
values.set(key, value.slice(at + 1).replaceAll("%%", "%"));
|
|
6166
|
-
}
|
|
6416
|
+
const kept = unitEnvironment(previous).filter(([key]) => key === "HOME" || key === "XDG_STATE_HOME");
|
|
6417
|
+
const values = new Map(kept);
|
|
6418
|
+
if (values.size !== kept.length)
|
|
6419
|
+
return false;
|
|
6167
6420
|
const state = s.env.XDG_STATE_HOME;
|
|
6168
6421
|
return values.get("HOME") === s.home && values.get("XDG_STATE_HOME") === (state && isAbsolute8(state) ? state : undefined);
|
|
6169
6422
|
} catch {
|
|
@@ -6203,12 +6456,12 @@ async function configureSystemService(s, mode, requested) {
|
|
|
6203
6456
|
const selected = selectWorkspace(s, requested, mode === "install" && requested === undefined ? null : unitWorkspace(previous), false);
|
|
6204
6457
|
if (selected.workspace !== null && !sdk)
|
|
6205
6458
|
return { status: "missing-pi-sdk", scope: "system" };
|
|
6206
|
-
const selectedReal = selected.workspace && existsSync3(selected.workspace) ?
|
|
6459
|
+
const selectedReal = selected.workspace && existsSync3(selected.workspace) ? realpathSync6(selected.workspace) : undefined;
|
|
6207
6460
|
const agentDir = agentDirectory(s);
|
|
6208
6461
|
const content = buildUnit({
|
|
6209
6462
|
system: true,
|
|
6210
6463
|
node: s.node,
|
|
6211
|
-
cli:
|
|
6464
|
+
cli: join17(s.root, "src", "service-cli.mjs"),
|
|
6212
6465
|
workspace: selected.workspace,
|
|
6213
6466
|
serverConfig: serviceConfigPath(s),
|
|
6214
6467
|
agentDir,
|
|
@@ -6240,7 +6493,7 @@ async function configureSystemService(s, mode, requested) {
|
|
|
6240
6493
|
return { status: "foreign", ...result };
|
|
6241
6494
|
if (selectedReal && selected.workspace) {
|
|
6242
6495
|
try {
|
|
6243
|
-
if (
|
|
6496
|
+
if (realpathSync6(selected.workspace) !== selectedReal)
|
|
6244
6497
|
return { status: "workspace-changed", ...result };
|
|
6245
6498
|
} catch {
|
|
6246
6499
|
return { status: "workspace-changed", ...result };
|
|
@@ -6257,7 +6510,7 @@ async function configureSystemService(s, mode, requested) {
|
|
|
6257
6510
|
return { status: "failed", ...result, ...selected };
|
|
6258
6511
|
if (mode === "install" && s.systemctl(["enable", s.unit]).status !== 0)
|
|
6259
6512
|
return { status: "failed", ...result, ...selected };
|
|
6260
|
-
if (selected.workspace !== null && !regularFile(
|
|
6513
|
+
if (selected.workspace !== null && !regularFile(join17(agentDir, "auth.json")))
|
|
6261
6514
|
return { status: "waiting-for-pi-login", ...result, ...selected };
|
|
6262
6515
|
s.systemctl(["reset-failed", s.unit]);
|
|
6263
6516
|
return {
|
|
@@ -6497,10 +6750,10 @@ function startupGuidance(result, input) {
|
|
|
6497
6750
|
return `Pi's agent directory ${agent} must be an existing real directory (not a symlink) owned by you.
|
|
6498
6751
|
`;
|
|
6499
6752
|
case "pi-auth":
|
|
6500
|
-
return `${
|
|
6753
|
+
return `${join18(agent, "auth.json")} must be your own single-link regular file holding valid Pi credentials; log in to Pi first.
|
|
6501
6754
|
`;
|
|
6502
6755
|
case "pi-models":
|
|
6503
|
-
return `${
|
|
6756
|
+
return `${join18(agent, "models.json")} must be your own single-link regular file using only fields Cadence's pinned Pi SDK supports; a field only newer Pi understands is refused.
|
|
6504
6757
|
`;
|
|
6505
6758
|
case "pi-runtime":
|
|
6506
6759
|
return `Loading Pi's SDK model runtime failed (optional SDK packages missing, or sources the SDK refuses). Fix that and start again; the next start recovers the owner's registration automatically.
|
|
@@ -6560,7 +6813,7 @@ async function launchHost(input, c, foreground, hostUrl, cwd, env, network) {
|
|
|
6560
6813
|
throw new ContractError("oversize");
|
|
6561
6814
|
if (!sameNetwork(network, networkSnapshot(process.env)))
|
|
6562
6815
|
throw new ContractError("stale");
|
|
6563
|
-
const child =
|
|
6816
|
+
const child = spawn2(process.execPath, [
|
|
6564
6817
|
...env.NODE_USE_ENV_PROXY === "1" ? ["--use-env-proxy"] : [],
|
|
6565
6818
|
fileURLToPath2(hostUrl)
|
|
6566
6819
|
], {
|
|
@@ -6727,8 +6980,17 @@ async function serverAction(s, action, requested, linger) {
|
|
|
6727
6980
|
return { status: "unsupported" };
|
|
6728
6981
|
}
|
|
6729
6982
|
}
|
|
6983
|
+
function upgrade(s, to) {
|
|
6984
|
+
if (s.platform !== "linux")
|
|
6985
|
+
return Promise.resolve({ status: "unsupported" });
|
|
6986
|
+
return upgradeService(s, to, {
|
|
6987
|
+
npm,
|
|
6988
|
+
stop: () => serverAction(s, "stop", undefined, false),
|
|
6989
|
+
restart: () => restartInstalled(s)
|
|
6990
|
+
});
|
|
6991
|
+
}
|
|
6730
6992
|
function serverGuidance(s, action, result, link) {
|
|
6731
|
-
const cli = piUserInstall(s) ? `node ${JSON.stringify(
|
|
6993
|
+
const cli = piUserInstall(s) ? `node ${JSON.stringify(join18(s.root, "src", "service-cli.mjs"))}` : "cadence";
|
|
6732
6994
|
const note = result.redirectedFrom ? `Cadence workspace: ${result.workspace} (${result.redirectedFrom} contains Cadence's private state)
|
|
6733
6995
|
` : "";
|
|
6734
6996
|
return note + serverStatusGuidance(s, action, result, cli, link);
|
|
@@ -6758,8 +7020,46 @@ function managerDetail(s) {
|
|
|
6758
7020
|
return `run its launcher to see why: wscript ${JSON.stringify(launcherPath(s))}`;
|
|
6759
7021
|
}
|
|
6760
7022
|
}
|
|
7023
|
+
var REASONS = {
|
|
7024
|
+
"fetch-failed": "the release could not be fetched; the service kept running",
|
|
7025
|
+
"stop-unconfirmed": "the running service did not confirm its orderly Stop",
|
|
7026
|
+
"install-failed": "npm could not install it",
|
|
7027
|
+
"not-ready": "the new version did not become ready"
|
|
7028
|
+
};
|
|
6761
7029
|
function serverStatusGuidance(s, action, result, cli, link) {
|
|
6762
7030
|
const workspace = JSON.stringify(result.workspace ?? "");
|
|
7031
|
+
if (result.status === "inside-service")
|
|
7032
|
+
return `This command runs inside ${s.unit}: stopping the service would also end this command before it starts Cadence again. Restart or upgrade from the WebUI (Cadence service), or run the command in a terminal outside the service.
|
|
7033
|
+
`;
|
|
7034
|
+
if (action === "upgrade") {
|
|
7035
|
+
const terminal = `Upgrade it the way you installed it, then: ${cli} server restart`;
|
|
7036
|
+
switch (result.status) {
|
|
7037
|
+
case "upgraded":
|
|
7038
|
+
return `Cadence ${result.version} is running (upgraded from ${result.from}).
|
|
7039
|
+
`;
|
|
7040
|
+
case "current":
|
|
7041
|
+
return `Cadence ${result.version} is already the latest version.
|
|
7042
|
+
`;
|
|
7043
|
+
case "deprecated":
|
|
7044
|
+
return `Cadence ${result.to} is deprecated on npm; nothing changed.
|
|
7045
|
+
`;
|
|
7046
|
+
case "rolled-back":
|
|
7047
|
+
return `Cadence ${result.to} did not become ready, so ${result.from} was reinstalled and is running; ${managerDetail(s)}.
|
|
7048
|
+
`;
|
|
7049
|
+
case "not-npm-global":
|
|
7050
|
+
return `This copy of Cadence (${s.root}) was not installed with npm install -g, so it cannot upgrade itself. ${terminal}
|
|
7051
|
+
`;
|
|
7052
|
+
case "not-writable":
|
|
7053
|
+
return `npm cannot write ${s.root} as this account. ${terminal}
|
|
7054
|
+
`;
|
|
7055
|
+
case "unsupported":
|
|
7056
|
+
return `Cadence upgrades itself only on Linux. Run npm install -g ${PACKAGE}@latest, then: ${cli} server restart
|
|
7057
|
+
`;
|
|
7058
|
+
case "failed":
|
|
7059
|
+
return `Cadence was not upgraded: ${REASONS[result.reason ?? ""] ?? result.reason}. Running now: ${result.version ?? result.from}; ${managerDetail(s)}.
|
|
7060
|
+
`;
|
|
7061
|
+
}
|
|
7062
|
+
}
|
|
6763
7063
|
if (result.workspace === null && ["quarantined", "unconfirmed", "unavailable"].includes(result.status))
|
|
6764
7064
|
return `Cadence workbench is not ready (${result.status}).
|
|
6765
7065
|
Details and repair: ${cli} doctor${s.platform === "linux" ? "" : ""} --fix
|
|
@@ -6794,7 +7094,7 @@ ${manage}
|
|
|
6794
7094
|
${linger}`;
|
|
6795
7095
|
}
|
|
6796
7096
|
case "waiting-for-pi-login":
|
|
6797
|
-
return `Cadence is registered for ${result.workspace}; it starts once Pi has ${
|
|
7097
|
+
return `Cadence is registered for ${result.workspace}; it starts once Pi has ${join18(agentDirectory(s), "auth.json")}.
|
|
6798
7098
|
Log in to Pi, then: ${cli} server restart${flags}
|
|
6799
7099
|
${config}
|
|
6800
7100
|
${lingerGuidance(result.linger)}`;
|
|
@@ -6865,7 +7165,8 @@ var SERVER_ACTIONS = [
|
|
|
6865
7165
|
"status",
|
|
6866
7166
|
"restart",
|
|
6867
7167
|
"stop",
|
|
6868
|
-
"uninstall"
|
|
7168
|
+
"uninstall",
|
|
7169
|
+
"upgrade"
|
|
6869
7170
|
];
|
|
6870
7171
|
async function serverMain(argv, hostUrl) {
|
|
6871
7172
|
const action = SERVER_ACTIONS.find((a) => a === argv[0]);
|
|
@@ -6876,6 +7177,7 @@ async function serverMain(argv, hostUrl) {
|
|
|
6876
7177
|
let linger = process.env.CADENCE_LINGER !== "0";
|
|
6877
7178
|
let scope;
|
|
6878
7179
|
let name, port;
|
|
7180
|
+
let to, job2;
|
|
6879
7181
|
const seen = new Set;
|
|
6880
7182
|
while (argv.length) {
|
|
6881
7183
|
const flag = argv.shift();
|
|
@@ -6896,10 +7198,14 @@ async function serverMain(argv, hostUrl) {
|
|
|
6896
7198
|
port = portValue(argv.shift());
|
|
6897
7199
|
if (!port)
|
|
6898
7200
|
throw new ContractError("invalid");
|
|
6899
|
-
} else
|
|
7201
|
+
} else if (flag === "--to" && action === "upgrade" && argv[0])
|
|
7202
|
+
to = decodeVersion(argv.shift());
|
|
7203
|
+
else if (flag === "--job" && (action === "restart" || action === "upgrade") && argv[0])
|
|
7204
|
+
job2 = decodeId(argv.shift());
|
|
7205
|
+
else
|
|
6900
7206
|
throw new ContractError("invalid");
|
|
6901
7207
|
}
|
|
6902
|
-
const s = hostSystem(
|
|
7208
|
+
const s = hostSystem(dirname13(dirname13(fileURLToPath2(hostUrl))), ownerControl, {
|
|
6903
7209
|
scope,
|
|
6904
7210
|
name
|
|
6905
7211
|
});
|
|
@@ -6909,6 +7215,14 @@ async function serverMain(argv, hostUrl) {
|
|
|
6909
7215
|
const result2 = { status: "root-required", scope: "system" };
|
|
6910
7216
|
process.stderr.write(serverGuidance(s, action, result2, undefined));
|
|
6911
7217
|
process.stdout.write(`${JSON.stringify(result2)}
|
|
7218
|
+
`);
|
|
7219
|
+
process.exitCode = 1;
|
|
7220
|
+
return;
|
|
7221
|
+
}
|
|
7222
|
+
if (action !== "status" && insideUnit(s)) {
|
|
7223
|
+
const result2 = { status: "inside-service", unit: s.unit };
|
|
7224
|
+
process.stderr.write(serverGuidance(s, action, result2, undefined));
|
|
7225
|
+
process.stdout.write(`${JSON.stringify(result2)}
|
|
6912
7226
|
`);
|
|
6913
7227
|
process.exitCode = 1;
|
|
6914
7228
|
return;
|
|
@@ -6936,7 +7250,7 @@ async function serverMain(argv, hostUrl) {
|
|
|
6936
7250
|
}
|
|
6937
7251
|
let result;
|
|
6938
7252
|
try {
|
|
6939
|
-
result = await serverAction(s, action, requested, linger);
|
|
7253
|
+
result = action === "upgrade" ? await upgrade(s, to) : await serverAction(s, action, requested, linger);
|
|
6940
7254
|
} catch (error) {
|
|
6941
7255
|
if (error instanceof ContractError && error.code === "invalid")
|
|
6942
7256
|
process.stderr.write(`Cadence server install needs an existing absolute --workspace directory.
|
|
@@ -6952,7 +7266,7 @@ async function serverMain(argv, hostUrl) {
|
|
|
6952
7266
|
...observedServerResult(result, observation.service),
|
|
6953
7267
|
...observation
|
|
6954
7268
|
};
|
|
6955
|
-
if (result.service === "alive")
|
|
7269
|
+
if (result.service === "alive" && !job2)
|
|
6956
7270
|
link = await privateLink(workspace, undefined, serviceConfigPath(s));
|
|
6957
7271
|
}
|
|
6958
7272
|
if (action === "status" && result.workspace !== undefined && !vanished && ["active", "activating", "failed"].includes(result.status)) {
|
|
@@ -6969,6 +7283,12 @@ async function serverMain(argv, hostUrl) {
|
|
|
6969
7283
|
}
|
|
6970
7284
|
if (vanished)
|
|
6971
7285
|
result = { ...result, service: "workspace-missing" };
|
|
7286
|
+
if (job2 && (action === "restart" || action === "upgrade")) {
|
|
7287
|
+
const { state, reason } = jobOutcome(action, result);
|
|
7288
|
+
try {
|
|
7289
|
+
new MaintenanceRecord(new GatewayStore(serviceConfigPath(s))).finish(job2, state, reason, installedVersion(s.root));
|
|
7290
|
+
} catch {}
|
|
7291
|
+
}
|
|
6972
7292
|
process.stderr.write(vanished ?? serverGuidance(s, action, result, link));
|
|
6973
7293
|
process.stdout.write(`${JSON.stringify(result)}
|
|
6974
7294
|
`);
|
|
@@ -6984,7 +7304,12 @@ async function serverMain(argv, hostUrl) {
|
|
|
6984
7304
|
"scope-conflict",
|
|
6985
7305
|
"workspace-changed",
|
|
6986
7306
|
"project-running",
|
|
6987
|
-
"environment-changed"
|
|
7307
|
+
"environment-changed",
|
|
7308
|
+
"inside-service",
|
|
7309
|
+
"not-npm-global",
|
|
7310
|
+
"not-writable",
|
|
7311
|
+
"deprecated",
|
|
7312
|
+
"rolled-back"
|
|
6988
7313
|
].includes(result.status) || result.status === "absent" && (action === "restart" || action === "stop"))
|
|
6989
7314
|
process.exitCode = 1;
|
|
6990
7315
|
}
|
|
@@ -7148,7 +7473,8 @@ Without --workspace these commands address the unified workbench, never cwd; no
|
|
|
7148
7473
|
cadence workbench start|status|diagnose|stop|token-link --reveal|token-rotate [--server-config PATH] [--state-home PATH]
|
|
7149
7474
|
cadence doctor [--fix] [--yes] [--workspace PATH] [--state-home PATH] [--server-config PATH]
|
|
7150
7475
|
Start recovers automatically from an unclean shutdown or crash. Doctor shows the state readonly; --fix also stops an unresponsive Cadence or takes over state it cannot observe, after one confirmation (--yes skips it). recover inspect|resolve are aliases of doctor and doctor --fix.
|
|
7151
|
-
cadence server install [--workspace PATH] [--no-linger]|status|restart|stop|uninstall
|
|
7476
|
+
cadence server install [--workspace PATH] [--no-linger]|status|restart|stop|uninstall|upgrade [--to VERSION]
|
|
7477
|
+
Upgrade (Linux, npm global installs) fetches the release while the service runs, then stops it, installs the release and restarts; a release that does not become ready is replaced by the previous version. Server commands that change the service refuse to run inside it; use the WebUI or a terminal.
|
|
7152
7478
|
Linux server options: --system (root, no linger) or --user; --name NAME selects an independent service; install also accepts --port PORT (required for a new named service). Root defaults to --system. No automatic sudo or profile migration.
|
|
7153
7479
|
cadence project open [PATH] [--create] [--agent-dir PATH] [--state-home PATH]
|
|
7154
7480
|
Project open explicitly starts/reuses that checkout owner, selecting a private free port for a new project. It never creates or starts a task.
|