@abelxiaoxing/cadence 2.0.37 → 2.0.38
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 -2
- package/README.es.md +2 -2
- package/README.fr.md +2 -2
- package/README.ja.md +2 -2
- package/README.ko.md +2 -2
- package/README.md +9 -7
- package/README.pt-BR.md +2 -2
- package/README.ru.md +2 -2
- package/README.zh-CN.md +10 -8
- package/agents/design-explorer.md +4 -2
- package/agents/diagnosis-worker.md +5 -2
- package/agents/implementation-worker.md +19 -12
- package/docs/conversation-mode.md +43 -16
- package/package.json +4 -1
- package/src/agent-browser/session-navigator.ts +33 -6
- package/src/agent-browser/source.ts +23 -19
- package/src/agent-panel-cadence.ts +147 -628
- package/src/agent-panel-model.ts +30 -19
- package/src/agent-panel.ts +12 -16
- package/src/cadence-instructions.ts +8 -7
- package/src/cadence-mode.ts +30 -9
- package/src/change-tools.mjs +268 -0
- package/src/coordinator-tools.mjs +2 -2
- package/src/git-environment.d.mts +2 -0
- package/src/git-environment.mjs +24 -0
- package/src/index.ts +1 -1
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +20 -3
- package/src/operator-cli.mjs +18 -11
- package/src/sdk-worker.mjs +2 -0
- package/src/service/contracts/workbench.ts +11 -3
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +7 -0
- package/src/service-cli.mjs +366 -85
- package/src/service-host.mjs +2450 -983
- package/src/worker-capture.mjs +24 -1
- package/src/worker-public.mjs +18 -0
- package/src/worker-redaction.mjs +11 -0
- package/src/worker-toolkit.mjs +48 -1
- package/src/workspace.ts +4 -24
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +18 -17
- package/web/dist/manifest.json +7 -7
package/src/service-cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { spawn as spawn3 } 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 dirname13, join as
|
|
9
|
+
import { dirname as dirname13, join as join20, resolve as resolve7 } from "node:path";
|
|
10
10
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
11
11
|
|
|
12
12
|
// src/install-config.mjs
|
|
@@ -1770,6 +1770,24 @@ class CaptureBudgetLease {
|
|
|
1770
1770
|
this.forget();
|
|
1771
1771
|
}
|
|
1772
1772
|
}
|
|
1773
|
+
// src/git-environment.mjs
|
|
1774
|
+
function gitEnvironment() {
|
|
1775
|
+
const root = process.getuid?.() === 0;
|
|
1776
|
+
return {
|
|
1777
|
+
...Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith("GIT_") && !(root && name === "SUDO_UID"))),
|
|
1778
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
1779
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
1780
|
+
LC_ALL: "C"
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
function gitArguments(args) {
|
|
1784
|
+
return [
|
|
1785
|
+
"--no-replace-objects",
|
|
1786
|
+
...process.platform !== "win32" && process.getuid?.() === 0 ? ["-c", "safe.directory=", "-c", "core.fsmonitor=false"] : [],
|
|
1787
|
+
...args
|
|
1788
|
+
];
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1773
1791
|
// src/workspace.ts
|
|
1774
1792
|
import { spawnSync } from "node:child_process";
|
|
1775
1793
|
import { createHash } from "node:crypto";
|
|
@@ -1890,17 +1908,6 @@ function readBounded(path2, max, packaged = false) {
|
|
|
1890
1908
|
closeSync2(fd);
|
|
1891
1909
|
}
|
|
1892
1910
|
}
|
|
1893
|
-
function gitEnvironment() {
|
|
1894
|
-
const root = process.getuid?.() === 0;
|
|
1895
|
-
return {
|
|
1896
|
-
...Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith("GIT_") && !(root && name === "SUDO_UID"))),
|
|
1897
|
-
GIT_OPTIONAL_LOCKS: "0",
|
|
1898
|
-
LC_ALL: "C"
|
|
1899
|
-
};
|
|
1900
|
-
}
|
|
1901
|
-
function gitArguments(args) {
|
|
1902
|
-
return process.platform !== "win32" && process.getuid?.() === 0 ? ["-c", "safe.directory=", "-c", "core.fsmonitor=false", ...args] : args;
|
|
1903
|
-
}
|
|
1904
1911
|
function resolveWorkspace(cwd) {
|
|
1905
1912
|
const actual = realpathSync(cwd);
|
|
1906
1913
|
const result = spawnSync("git", gitArguments(["rev-parse", "--show-toplevel"]), {
|
|
@@ -3638,6 +3645,8 @@ class ServiceCoordination {
|
|
|
3638
3645
|
}
|
|
3639
3646
|
acquire(input, resolvedEndpoint = input.endpoint, initializeNew, reselectExisting) {
|
|
3640
3647
|
this.store;
|
|
3648
|
+
if (rootsOverlap(this.store.root, join6(this.stateHome, "cadence-worktrees-v1")))
|
|
3649
|
+
throw new ContractError("forbidden");
|
|
3641
3650
|
const config = decodeOwnerConfig(input);
|
|
3642
3651
|
const bound = endpoint(resolvedEndpoint);
|
|
3643
3652
|
if (!endpointMatches(config.endpoint, bound))
|
|
@@ -4673,10 +4682,10 @@ function strayTemporaries(directory2) {
|
|
|
4673
4682
|
}
|
|
4674
4683
|
|
|
4675
4684
|
// src/service/self-heal.ts
|
|
4676
|
-
import { createHash as createHash4, randomUUID as
|
|
4677
|
-
import { lstatSync as
|
|
4685
|
+
import { createHash as createHash4, randomUUID as randomUUID8 } from "node:crypto";
|
|
4686
|
+
import { lstatSync as lstatSync8, opendirSync as opendirSync5 } from "node:fs";
|
|
4678
4687
|
import { hostname as hostname5 } from "node:os";
|
|
4679
|
-
import { join as
|
|
4688
|
+
import { join as join12 } from "node:path";
|
|
4680
4689
|
|
|
4681
4690
|
// src/service/process-ledger.ts
|
|
4682
4691
|
import { rmSync as rmSync3 } from "node:fs";
|
|
@@ -4796,6 +4805,250 @@ class LiveLedger {
|
|
|
4796
4805
|
}
|
|
4797
4806
|
}
|
|
4798
4807
|
|
|
4808
|
+
// src/service/repository-coordination.ts
|
|
4809
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
4810
|
+
import { lstatSync as lstatSync7, opendirSync as opendirSync4 } from "node:fs";
|
|
4811
|
+
import { isAbsolute as isAbsolute6, join as join11 } from "node:path";
|
|
4812
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4813
|
+
var WAIT_MS = 30000;
|
|
4814
|
+
var POLL_MS = 50;
|
|
4815
|
+
var ACTIVE_RESOURCES = 256;
|
|
4816
|
+
function decode3(value) {
|
|
4817
|
+
const o = closed(value, [
|
|
4818
|
+
"schema",
|
|
4819
|
+
"kind",
|
|
4820
|
+
"resource",
|
|
4821
|
+
"root",
|
|
4822
|
+
"epoch",
|
|
4823
|
+
"run",
|
|
4824
|
+
"token",
|
|
4825
|
+
"identity",
|
|
4826
|
+
"holder"
|
|
4827
|
+
]);
|
|
4828
|
+
if (o.schema !== "cadence-delivery-resource/1" || !["mutation", "workspace"].includes(String(o.kind)))
|
|
4829
|
+
throw new ContractError("corrupt-selected");
|
|
4830
|
+
for (const path2 of [o.resource, o.root])
|
|
4831
|
+
if (typeof path2 !== "string" || !isAbsolute6(path2) || path2.includes("\x00"))
|
|
4832
|
+
throw new ContractError("corrupt-selected");
|
|
4833
|
+
const h = closed(o.holder, ["pid", "host", "boot", "started"]);
|
|
4834
|
+
if (!Number.isSafeInteger(h.pid) || Number(h.pid) < 1 || typeof h.host !== "string" || ![h.boot, h.started].every((x) => x === null || typeof x === "string"))
|
|
4835
|
+
throw new ContractError("corrupt-selected");
|
|
4836
|
+
return {
|
|
4837
|
+
schema: "cadence-delivery-resource/1",
|
|
4838
|
+
kind: o.kind,
|
|
4839
|
+
resource: text(o.resource, 4096, true),
|
|
4840
|
+
root: text(o.root, 4096, true),
|
|
4841
|
+
epoch: decodeId(o.epoch),
|
|
4842
|
+
run: decodeId(o.run),
|
|
4843
|
+
token: decodeId(o.token),
|
|
4844
|
+
identity: o.identity === null ? null : decodeHash(o.identity),
|
|
4845
|
+
holder: h
|
|
4846
|
+
};
|
|
4847
|
+
}
|
|
4848
|
+
var directory2 = (files) => join11(files.namespace, "delivery-resources-v1");
|
|
4849
|
+
var resourcePath = (files, row) => join11(directory2(files), row.kind, `${hash(row.resource)}.json`);
|
|
4850
|
+
var ownerDirectory = (files, root, epoch) => join11(directory2(files), "owners", hash(root), decodeId(epoch));
|
|
4851
|
+
var indexPath = (files, row) => join11(ownerDirectory(files, row.root, row.epoch), `${row.kind}-${hash(row.resource)}.json`);
|
|
4852
|
+
function worktreeIdentity(path2) {
|
|
4853
|
+
const root = lstatSync7(path2), marker = lstatSync7(join11(path2, ".git"));
|
|
4854
|
+
if (!root.isDirectory() || root.isSymbolicLink() || !marker.isFile() || marker.nlink !== 1 || marker.size > 8192)
|
|
4855
|
+
throw new ContractError("stale");
|
|
4856
|
+
const body = readBounded(join11(path2, ".git"), 8192);
|
|
4857
|
+
const after = lstatSync7(join11(path2, ".git")), afterRoot = lstatSync7(path2);
|
|
4858
|
+
if (!body || after.dev !== marker.dev || after.ino !== marker.ino || after.ctimeMs !== marker.ctimeMs || after.size !== marker.size || afterRoot.dev !== root.dev || afterRoot.ino !== root.ino)
|
|
4859
|
+
throw new ContractError("stale");
|
|
4860
|
+
return hash(encoded([
|
|
4861
|
+
root.dev,
|
|
4862
|
+
root.ino,
|
|
4863
|
+
marker.dev,
|
|
4864
|
+
marker.ino,
|
|
4865
|
+
body.toString("utf8")
|
|
4866
|
+
]));
|
|
4867
|
+
}
|
|
4868
|
+
|
|
4869
|
+
class RepositoryCoordination {
|
|
4870
|
+
c;
|
|
4871
|
+
root;
|
|
4872
|
+
epoch;
|
|
4873
|
+
run;
|
|
4874
|
+
assertOwner;
|
|
4875
|
+
fault;
|
|
4876
|
+
owned = new Map;
|
|
4877
|
+
constructor(c, root, epoch, run, assertOwner, fault) {
|
|
4878
|
+
this.c = c;
|
|
4879
|
+
this.root = root;
|
|
4880
|
+
this.epoch = epoch;
|
|
4881
|
+
this.run = run;
|
|
4882
|
+
this.assertOwner = assertOwner;
|
|
4883
|
+
this.fault = fault;
|
|
4884
|
+
}
|
|
4885
|
+
write(operation) {
|
|
4886
|
+
try {
|
|
4887
|
+
return operation();
|
|
4888
|
+
} catch (error) {
|
|
4889
|
+
this.fault();
|
|
4890
|
+
throw error;
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
reserve(kind, resource) {
|
|
4894
|
+
this.assertOwner();
|
|
4895
|
+
const row = {
|
|
4896
|
+
schema: "cadence-delivery-resource/1",
|
|
4897
|
+
kind,
|
|
4898
|
+
resource,
|
|
4899
|
+
root: this.root,
|
|
4900
|
+
epoch: this.epoch,
|
|
4901
|
+
run: this.run,
|
|
4902
|
+
token: randomUUID7(),
|
|
4903
|
+
identity: null,
|
|
4904
|
+
holder: selfMark()
|
|
4905
|
+
};
|
|
4906
|
+
const target = resourcePath(this.c.files, row);
|
|
4907
|
+
if (this.c.files.read(target))
|
|
4908
|
+
return null;
|
|
4909
|
+
const index = this.write(() => this.c.files.create(indexPath(this.c.files, row), encoded(row)));
|
|
4910
|
+
let file;
|
|
4911
|
+
try {
|
|
4912
|
+
file = this.c.files.create(target, encoded(row));
|
|
4913
|
+
} catch (error) {
|
|
4914
|
+
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
4915
|
+
this.write(() => this.c.files.remove(indexPath(this.c.files, row), index));
|
|
4916
|
+
return null;
|
|
4917
|
+
}
|
|
4918
|
+
this.fault();
|
|
4919
|
+
throw error;
|
|
4920
|
+
}
|
|
4921
|
+
const held = { row, file, index };
|
|
4922
|
+
this.owned.set(row.token, held);
|
|
4923
|
+
return held;
|
|
4924
|
+
}
|
|
4925
|
+
async mutate(repository, signal, operation, settled) {
|
|
4926
|
+
const deadline = performance.now() + WAIT_MS;
|
|
4927
|
+
let held;
|
|
4928
|
+
for (;; ) {
|
|
4929
|
+
this.assertOwner();
|
|
4930
|
+
if (signal.aborted)
|
|
4931
|
+
throw new ContractError("stale");
|
|
4932
|
+
held = this.reserve("mutation", repository);
|
|
4933
|
+
if (held)
|
|
4934
|
+
break;
|
|
4935
|
+
if (performance.now() >= deadline)
|
|
4936
|
+
throw new ContractError("conflict");
|
|
4937
|
+
await delay(POLL_MS, undefined, { signal });
|
|
4938
|
+
}
|
|
4939
|
+
try {
|
|
4940
|
+
return await operation();
|
|
4941
|
+
} finally {
|
|
4942
|
+
if (settled())
|
|
4943
|
+
this.release(held.row.token);
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4946
|
+
reserveWorkspace(path2) {
|
|
4947
|
+
const held = this.reserve("workspace", path2);
|
|
4948
|
+
if (!held)
|
|
4949
|
+
throw new ContractError("conflict");
|
|
4950
|
+
return held.row.token;
|
|
4951
|
+
}
|
|
4952
|
+
confirmWorkspace(token) {
|
|
4953
|
+
const held = this.require(token);
|
|
4954
|
+
held.row = { ...held.row, identity: worktreeIdentity(held.row.resource) };
|
|
4955
|
+
this.write(() => this.c.files.create(join11(this.c.directory, "workflows-v1", "runs", this.run, "ownership", `${token}.json`), encoded({ ...held.row, schema: "cadence-workspace-observation/1" })));
|
|
4956
|
+
}
|
|
4957
|
+
assertWorkspace(token) {
|
|
4958
|
+
this.assertOwner();
|
|
4959
|
+
const held = this.require(token);
|
|
4960
|
+
this.c.files.assert(resourcePath(this.c.files, held.row), held.file);
|
|
4961
|
+
if (!held.row.identity || worktreeIdentity(held.row.resource) !== held.row.identity)
|
|
4962
|
+
throw new ContractError("stale");
|
|
4963
|
+
}
|
|
4964
|
+
require(token) {
|
|
4965
|
+
const held = this.owned.get(token);
|
|
4966
|
+
if (!held)
|
|
4967
|
+
throw new ContractError("stale");
|
|
4968
|
+
return held;
|
|
4969
|
+
}
|
|
4970
|
+
release(token) {
|
|
4971
|
+
this.assertOwner();
|
|
4972
|
+
const held = this.require(token);
|
|
4973
|
+
this.write(() => {
|
|
4974
|
+
this.c.files.remove(resourcePath(this.c.files, held.row), held.file);
|
|
4975
|
+
this.c.files.remove(indexPath(this.c.files, held.row), held.index);
|
|
4976
|
+
});
|
|
4977
|
+
this.owned.delete(token);
|
|
4978
|
+
}
|
|
4979
|
+
finish() {
|
|
4980
|
+
for (const held of [...this.owned.values()])
|
|
4981
|
+
if (held.row.kind === "workspace")
|
|
4982
|
+
this.release(held.row.token);
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
function recoverDeliveryResources(files, root, epoch, options = {}) {
|
|
4986
|
+
const home = ownerDirectory(files, root, epoch);
|
|
4987
|
+
if (!files.directory(home))
|
|
4988
|
+
return 0;
|
|
4989
|
+
const dir = opendirSync4(home);
|
|
4990
|
+
const actions = [];
|
|
4991
|
+
let count = 0;
|
|
4992
|
+
const read = (path2) => {
|
|
4993
|
+
try {
|
|
4994
|
+
const snapshot = files.read(path2);
|
|
4995
|
+
if (!snapshot)
|
|
4996
|
+
return { snapshot, row: undefined, broken: false };
|
|
4997
|
+
try {
|
|
4998
|
+
return { snapshot, row: decode3(json(snapshot)), broken: false };
|
|
4999
|
+
} catch {
|
|
5000
|
+
return { snapshot, row: undefined, broken: true };
|
|
5001
|
+
}
|
|
5002
|
+
} catch {
|
|
5003
|
+
return { snapshot: undefined, row: undefined, broken: true };
|
|
5004
|
+
}
|
|
5005
|
+
};
|
|
5006
|
+
const archive = (path2) => {
|
|
5007
|
+
if (!options.archive)
|
|
5008
|
+
throw new ContractError("corrupt-selected");
|
|
5009
|
+
options.archive(path2);
|
|
5010
|
+
};
|
|
5011
|
+
try {
|
|
5012
|
+
for (let entry = dir.readSync();entry; entry = dir.readSync()) {
|
|
5013
|
+
if (++count > ACTIVE_RESOURCES)
|
|
5014
|
+
throw new ContractError("capacity");
|
|
5015
|
+
const match = /^(mutation|workspace)-([a-f0-9]{64})\.json$/u.exec(entry.name);
|
|
5016
|
+
const path2 = join11(home, entry.name);
|
|
5017
|
+
if (!match) {
|
|
5018
|
+
if (!options.takeOver)
|
|
5019
|
+
throw new ContractError("corrupt-selected");
|
|
5020
|
+
actions.push(() => archive(path2));
|
|
5021
|
+
continue;
|
|
5022
|
+
}
|
|
5023
|
+
const [, kind, key] = match;
|
|
5024
|
+
const index = read(path2), target = join11(directory2(files), kind, `${key}.json`), shared = read(target);
|
|
5025
|
+
const matches = (row) => row.kind === kind && hash(row.resource) === key && row.root === root && row.epoch === epoch;
|
|
5026
|
+
const ownerMatches = (row) => !options.expectedOwner || Object.entries(options.expectedOwner).every(([key2, value]) => value == null || row.holder[key2] === value);
|
|
5027
|
+
const badIndex = index.broken || !index.row || !matches(index.row) || !ownerMatches(index.row);
|
|
5028
|
+
const badShared = shared.broken || shared.row && (shared.row.kind !== kind || hash(shared.row.resource) !== key || matches(shared.row) && (!ownerMatches(shared.row) || index.row && !badIndex && index.row.token === shared.row.token && encoded(index.row.holder) !== encoded(shared.row.holder)));
|
|
5029
|
+
if (badShared && !options.takeOver)
|
|
5030
|
+
throw new ContractError("corrupt-selected");
|
|
5031
|
+
actions.push(() => {
|
|
5032
|
+
if (badShared)
|
|
5033
|
+
archive(target);
|
|
5034
|
+
else if (shared.row && shared.snapshot && matches(shared.row) && (!index.row || badIndex || index.row.token === shared.row.token)) {
|
|
5035
|
+
files.remove(target, shared.snapshot);
|
|
5036
|
+
}
|
|
5037
|
+
if (badIndex)
|
|
5038
|
+
archive(path2);
|
|
5039
|
+
else if (index.snapshot)
|
|
5040
|
+
files.remove(path2, index.snapshot);
|
|
5041
|
+
});
|
|
5042
|
+
}
|
|
5043
|
+
} finally {
|
|
5044
|
+
dir.closeSync();
|
|
5045
|
+
}
|
|
5046
|
+
if (!options.inspect)
|
|
5047
|
+
for (const action of actions)
|
|
5048
|
+
action();
|
|
5049
|
+
return count;
|
|
5050
|
+
}
|
|
5051
|
+
|
|
4799
5052
|
// src/service/self-heal.ts
|
|
4800
5053
|
function attempt(read) {
|
|
4801
5054
|
try {
|
|
@@ -4804,7 +5057,7 @@ function attempt(read) {
|
|
|
4804
5057
|
return null;
|
|
4805
5058
|
}
|
|
4806
5059
|
}
|
|
4807
|
-
function readFile(files, path2,
|
|
5060
|
+
function readFile(files, path2, decode4, maximum) {
|
|
4808
5061
|
let snapshot;
|
|
4809
5062
|
try {
|
|
4810
5063
|
snapshot = files.read(path2, maximum);
|
|
@@ -4817,7 +5070,7 @@ function readFile(files, path2, decode3, maximum) {
|
|
|
4817
5070
|
return {
|
|
4818
5071
|
path: path2,
|
|
4819
5072
|
snapshot: bytes,
|
|
4820
|
-
value: attempt(() =>
|
|
5073
|
+
value: attempt(() => decode4(json(bytes, maximum)))
|
|
4821
5074
|
};
|
|
4822
5075
|
}
|
|
4823
5076
|
function decodeOwnerLock(value) {
|
|
@@ -4927,7 +5180,7 @@ class RegistryHealer {
|
|
|
4927
5180
|
this.ledger = new ProcessLedger(c.files);
|
|
4928
5181
|
}
|
|
4929
5182
|
path(name) {
|
|
4930
|
-
return
|
|
5183
|
+
return join12(this.c.registryDirectory, name);
|
|
4931
5184
|
}
|
|
4932
5185
|
async heal(options = {}) {
|
|
4933
5186
|
const lockPath = this.path("registry.lock");
|
|
@@ -4938,7 +5191,7 @@ class RegistryHealer {
|
|
|
4938
5191
|
lock = undefined;
|
|
4939
5192
|
const age = (() => {
|
|
4940
5193
|
try {
|
|
4941
|
-
return Date.now() -
|
|
5194
|
+
return Date.now() - lstatSync8(lockPath).mtimeMs;
|
|
4942
5195
|
} catch {
|
|
4943
5196
|
return 0;
|
|
4944
5197
|
}
|
|
@@ -5044,7 +5297,7 @@ class RegistryHealer {
|
|
|
5044
5297
|
const lockPath = this.path("registry.lock");
|
|
5045
5298
|
const lock = this.c.files.create(lockPath, encoded({
|
|
5046
5299
|
schema: "cadence-service-registry-lock/1",
|
|
5047
|
-
token:
|
|
5300
|
+
token: randomUUID8(),
|
|
5048
5301
|
pid: process.pid,
|
|
5049
5302
|
host: hostname5()
|
|
5050
5303
|
}));
|
|
@@ -5087,19 +5340,19 @@ class RegistryHealer {
|
|
|
5087
5340
|
}
|
|
5088
5341
|
function liveReservations(c) {
|
|
5089
5342
|
const out = [];
|
|
5090
|
-
const dir =
|
|
5343
|
+
const dir = opendirSync5(c.files.namespace);
|
|
5091
5344
|
try {
|
|
5092
5345
|
for (let e = dir.readSync();e; e = dir.readSync()) {
|
|
5093
5346
|
if (!/^[a-f0-9]{64}$/.test(e.name))
|
|
5094
5347
|
continue;
|
|
5095
|
-
const service =
|
|
5096
|
-
const registration2 = readFile(c.files,
|
|
5348
|
+
const service = join12(c.files.namespace, e.name, "service-v1");
|
|
5349
|
+
const registration2 = readFile(c.files, join12(service, "registration.json"), decodeRegistrationLenient);
|
|
5097
5350
|
if (!registration2 || registration2 === "unreadable")
|
|
5098
5351
|
continue;
|
|
5099
5352
|
const r = registration2.value;
|
|
5100
5353
|
if (!r || r.phase === "stopped")
|
|
5101
5354
|
continue;
|
|
5102
|
-
const owner = readFile(c.files,
|
|
5355
|
+
const owner = readFile(c.files, join12(service, "owner.lock"), decodeOwnerLock);
|
|
5103
5356
|
const mark = owner && owner !== "unreadable" && owner.value ? owner.value : r;
|
|
5104
5357
|
if (holderState(mark, stampTime(registration2.snapshot.stamp)).state !== "live")
|
|
5105
5358
|
continue;
|
|
@@ -5120,20 +5373,20 @@ function liveReservations(c) {
|
|
|
5120
5373
|
return out;
|
|
5121
5374
|
}
|
|
5122
5375
|
function projectFiles(c, root) {
|
|
5123
|
-
const privateRoot =
|
|
5376
|
+
const privateRoot = join12(c.files.namespace, createHash4("sha256").update(root).digest("hex"));
|
|
5124
5377
|
return {
|
|
5125
5378
|
root,
|
|
5126
5379
|
privateRoot,
|
|
5127
|
-
service:
|
|
5128
|
-
checkoutPath:
|
|
5380
|
+
service: join12(privateRoot, "service-v1"),
|
|
5381
|
+
checkoutPath: join12(privateRoot, "checkout.lock")
|
|
5129
5382
|
};
|
|
5130
5383
|
}
|
|
5131
5384
|
function snapshotProject(c, p) {
|
|
5132
5385
|
const s = { temporaries: [] };
|
|
5133
|
-
s.registration = readFile(c.files,
|
|
5134
|
-
s.owner = readFile(c.files,
|
|
5386
|
+
s.registration = readFile(c.files, join12(p.service, "registration.json"), decodeRegistrationLenient);
|
|
5387
|
+
s.owner = readFile(c.files, join12(p.service, "owner.lock"), decodeOwnerLock);
|
|
5135
5388
|
try {
|
|
5136
|
-
s.capability = c.files.read(
|
|
5389
|
+
s.capability = c.files.read(join12(p.service, "local-capability.json"));
|
|
5137
5390
|
} catch {
|
|
5138
5391
|
s.capability = "unreadable";
|
|
5139
5392
|
}
|
|
@@ -5148,7 +5401,7 @@ function snapshotProject(c, p) {
|
|
|
5148
5401
|
} catch {}
|
|
5149
5402
|
s.temporaries = [
|
|
5150
5403
|
...strayTemporaries(p.service),
|
|
5151
|
-
...strayTemporaries(
|
|
5404
|
+
...strayTemporaries(join12(p.service, "history-v2"))
|
|
5152
5405
|
];
|
|
5153
5406
|
return s;
|
|
5154
5407
|
}
|
|
@@ -5217,6 +5470,28 @@ async function healProjectAt(c, root, options = {}) {
|
|
|
5217
5470
|
const workers = takenOver ? { stopped: 0, running: 0 } : await stopWorkers(ledger, epoch, holder.reboot, !!options.inspect);
|
|
5218
5471
|
if (workers.running)
|
|
5219
5472
|
return { status: "blocked", reason: "workers-running", pid };
|
|
5473
|
+
const selectedOwner = [
|
|
5474
|
+
s.owner && s.owner !== "unreadable" ? s.owner.value : null,
|
|
5475
|
+
s.registration && s.registration !== "unreadable" ? s.registration.value : null,
|
|
5476
|
+
s.row
|
|
5477
|
+
].find((value) => value?.epoch === epoch);
|
|
5478
|
+
const expectedOwner = selectedOwner ? {
|
|
5479
|
+
pid: selectedOwner.pid,
|
|
5480
|
+
host: selectedOwner.host,
|
|
5481
|
+
..."boot" in selectedOwner ? { boot: selectedOwner.boot ?? null } : {},
|
|
5482
|
+
..."started" in selectedOwner ? { started: selectedOwner.started ?? null } : {}
|
|
5483
|
+
} : undefined;
|
|
5484
|
+
if (epoch) {
|
|
5485
|
+
try {
|
|
5486
|
+
recoverDeliveryResources(c.files, root, epoch, {
|
|
5487
|
+
inspect: true,
|
|
5488
|
+
takeOver: options.takeOver,
|
|
5489
|
+
expectedOwner
|
|
5490
|
+
});
|
|
5491
|
+
} catch {
|
|
5492
|
+
return { status: "blocked", reason: "holder-unknown", pid };
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5220
5495
|
const restarted = epoch ? ledger.restartRequested(epoch) : false;
|
|
5221
5496
|
const cause = !active(s) ? "storage" : holder.reboot ? "reboot" : restarted ? "restart" : "crash";
|
|
5222
5497
|
if (options.inspect)
|
|
@@ -5227,6 +5502,12 @@ async function healProjectAt(c, root, options = {}) {
|
|
|
5227
5502
|
if (workers.stopped)
|
|
5228
5503
|
actions.add("stopped-workers");
|
|
5229
5504
|
const archive = log.archive();
|
|
5505
|
+
if (epoch && recoverDeliveryResources(c.files, root, epoch, {
|
|
5506
|
+
takeOver: options.takeOver,
|
|
5507
|
+
expectedOwner,
|
|
5508
|
+
archive: (path2) => archive.keep(path2)
|
|
5509
|
+
}))
|
|
5510
|
+
actions.add("released-locks");
|
|
5230
5511
|
if (active(s)) {
|
|
5231
5512
|
reclaim(c, p, s, archive);
|
|
5232
5513
|
actions.add("released-locks");
|
|
@@ -5261,8 +5542,8 @@ function metadataDamaged(c, p) {
|
|
|
5261
5542
|
return false;
|
|
5262
5543
|
}
|
|
5263
5544
|
try {
|
|
5264
|
-
const format = c.files.read(
|
|
5265
|
-
const config = c.files.read(
|
|
5545
|
+
const format = c.files.read(join12(p.service, "format.json"));
|
|
5546
|
+
const config = c.files.read(join12(p.service, "config.json"));
|
|
5266
5547
|
if (!format || !config)
|
|
5267
5548
|
return true;
|
|
5268
5549
|
const f = closed(json(format), [
|
|
@@ -5274,10 +5555,10 @@ function metadataDamaged(c, p) {
|
|
|
5274
5555
|
if (f.schema !== "cadence-service-format/1" || f.root !== p.root || f.stateHome !== c.stateHome || f.configIdentity !== config.identity)
|
|
5275
5556
|
return true;
|
|
5276
5557
|
const selected = decodeOwnerConfig(json(config));
|
|
5277
|
-
const host = c.files.read(
|
|
5558
|
+
const host = c.files.read(join12(p.service, "host-config.json"));
|
|
5278
5559
|
if (host && host.identity !== selected.policyIdentity)
|
|
5279
5560
|
return true;
|
|
5280
|
-
const registration2 = c.files.read(
|
|
5561
|
+
const registration2 = c.files.read(join12(p.service, "registration.json"));
|
|
5281
5562
|
if (registration2) {
|
|
5282
5563
|
const r = decodeRegistration(json(registration2));
|
|
5283
5564
|
if (r.root !== p.root || r.stateHome !== c.stateHome || r.configIdentity !== config.identity)
|
|
@@ -5300,7 +5581,7 @@ function reclaim(c, p, expected, archive) {
|
|
|
5300
5581
|
mutate();
|
|
5301
5582
|
const registration2 = s.registration;
|
|
5302
5583
|
if (registration2 === "unreadable")
|
|
5303
|
-
archive.keep(
|
|
5584
|
+
archive.keep(join12(p.service, "registration.json"));
|
|
5304
5585
|
else if (registration2) {
|
|
5305
5586
|
if (!registration2.value)
|
|
5306
5587
|
archive.keep(registration2.path);
|
|
@@ -5308,7 +5589,7 @@ function reclaim(c, p, expected, archive) {
|
|
|
5308
5589
|
c.files.replace(registration2.path, registration2.snapshot, encoded({ ...registration2.value, phase: "stopped" }));
|
|
5309
5590
|
}
|
|
5310
5591
|
if (s.row)
|
|
5311
|
-
c.files.replace(
|
|
5592
|
+
c.files.replace(join12(c.registryDirectory, "roots.json"), view.snapshot, encoded({
|
|
5312
5593
|
...view.value,
|
|
5313
5594
|
entries: view.value.entries.filter((row) => row.root !== p.root)
|
|
5314
5595
|
}), 1024 * 1024);
|
|
@@ -5321,8 +5602,8 @@ function reclaim(c, p, expected, archive) {
|
|
|
5321
5602
|
}
|
|
5322
5603
|
c.files.remove(path2, "snapshot" in value ? value.snapshot : value, maximum);
|
|
5323
5604
|
};
|
|
5324
|
-
drop(
|
|
5325
|
-
drop(
|
|
5605
|
+
drop(join12(p.service, "local-capability.json"), s.capability);
|
|
5606
|
+
drop(join12(p.service, "owner.lock"), s.owner);
|
|
5326
5607
|
drop(p.checkoutPath, s.checkout, 8192);
|
|
5327
5608
|
});
|
|
5328
5609
|
}
|
|
@@ -5660,16 +5941,16 @@ Cadence releases whatever the old project owner left behind automatically.
|
|
|
5660
5941
|
|
|
5661
5942
|
// src/service/gateway-cli.ts
|
|
5662
5943
|
import { homedir as homedir6 } from "node:os";
|
|
5663
|
-
import { dirname as dirname9, join as
|
|
5944
|
+
import { dirname as dirname9, join as join14, resolve as resolve6 } from "node:path";
|
|
5664
5945
|
import { fileURLToPath } from "node:url";
|
|
5665
5946
|
|
|
5666
5947
|
// src/service/runtime.ts
|
|
5667
5948
|
import { homedir as homedir5 } from "node:os";
|
|
5668
|
-
import { dirname as dirname8, isAbsolute as
|
|
5949
|
+
import { dirname as dirname8, isAbsolute as isAbsolute7, join as join13, resolve as resolve5 } from "node:path";
|
|
5669
5950
|
var STARTUP_INPUT_BYTES = 16 * 1024;
|
|
5670
5951
|
function absolute(value) {
|
|
5671
5952
|
const result = text(value, 4096, true);
|
|
5672
|
-
if (!
|
|
5953
|
+
if (!isAbsolute7(result))
|
|
5673
5954
|
throw new ContractError("invalid");
|
|
5674
5955
|
return result;
|
|
5675
5956
|
}
|
|
@@ -5765,7 +6046,7 @@ function selectStart(options, ambient) {
|
|
|
5765
6046
|
port: options.port ?? 17423,
|
|
5766
6047
|
proxy: null
|
|
5767
6048
|
},
|
|
5768
|
-
agentDir: resolve5(options.agentDir ?? ambient.PI_CODING_AGENT_DIR ??
|
|
6049
|
+
agentDir: resolve5(options.agentDir ?? ambient.PI_CODING_AGENT_DIR ?? join13(ambient.HOME ?? ambient.USERPROFILE ?? homedir5(), ".pi", "agent")),
|
|
5769
6050
|
tokenSource: options.tokenFile ? "file" : env ? "environment" : "generated",
|
|
5770
6051
|
tokenFile: options.tokenFile ? resolve5(options.tokenFile) : null
|
|
5771
6052
|
});
|
|
@@ -5897,7 +6178,7 @@ async function gatewayMain(argv, hostUrl) {
|
|
|
5897
6178
|
kind: "workbench",
|
|
5898
6179
|
serverConfig: config,
|
|
5899
6180
|
stateHome: store.stateHome,
|
|
5900
|
-
agentDir: agentDir ?? selected?.agentDir ?? resolve6(process.env.PI_CODING_AGENT_DIR ??
|
|
6181
|
+
agentDir: agentDir ?? selected?.agentDir ?? resolve6(process.env.PI_CODING_AGENT_DIR ?? join14(homedir6(), ".pi", "agent")),
|
|
5901
6182
|
policy: { ...policy, port: server.port }
|
|
5902
6183
|
});
|
|
5903
6184
|
const blocked = await healWorkbenchForStart(store, () => ownerResponsive(store));
|
|
@@ -5944,7 +6225,7 @@ import {
|
|
|
5944
6225
|
accessSync,
|
|
5945
6226
|
constants as constants4,
|
|
5946
6227
|
existsSync as existsSync3,
|
|
5947
|
-
lstatSync as
|
|
6228
|
+
lstatSync as lstatSync9,
|
|
5948
6229
|
mkdtempSync,
|
|
5949
6230
|
readFileSync as readFileSync3,
|
|
5950
6231
|
realpathSync as realpathSync5,
|
|
@@ -5952,7 +6233,7 @@ import {
|
|
|
5952
6233
|
writeFileSync as writeFileSync4
|
|
5953
6234
|
} from "node:fs";
|
|
5954
6235
|
import { tmpdir } from "node:os";
|
|
5955
|
-
import { basename as basename2, dirname as dirname10, isAbsolute as
|
|
6236
|
+
import { basename as basename2, dirname as dirname10, isAbsolute as isAbsolute8, join as join15 } from "node:path";
|
|
5956
6237
|
var PACKAGE = "@abelxiaoxing/cadence";
|
|
5957
6238
|
var VIEW_MS = 30000;
|
|
5958
6239
|
var INSTALL_MS = 15 * 60000;
|
|
@@ -5980,19 +6261,19 @@ var unsupported = () => ({
|
|
|
5980
6261
|
});
|
|
5981
6262
|
function sameCopy(modules, root) {
|
|
5982
6263
|
try {
|
|
5983
|
-
const path2 =
|
|
5984
|
-
return !
|
|
6264
|
+
const path2 = join15(modules, ...PACKAGE.split("/"));
|
|
6265
|
+
return !lstatSync9(path2).isSymbolicLink() && realpathSync5(path2) === realpathSync5(root) && realpathSync5(path2) === join15(realpathSync5(modules), ...PACKAGE.split("/"));
|
|
5985
6266
|
} catch {
|
|
5986
6267
|
return false;
|
|
5987
6268
|
}
|
|
5988
6269
|
}
|
|
5989
6270
|
function prefixManager(prefix) {
|
|
5990
|
-
const npm = existsSync3(
|
|
5991
|
-
const bun = existsSync3(
|
|
6271
|
+
const npm = existsSync3(join15(prefix, "package-lock.json")) || existsSync3(join15(prefix, "npm-shrinkwrap.json"));
|
|
6272
|
+
const bun = existsSync3(join15(prefix, "bun.lock")) || existsSync3(join15(prefix, "bun.lockb"));
|
|
5992
6273
|
return npm === bun ? undefined : bun ? "bun" : "npm";
|
|
5993
6274
|
}
|
|
5994
6275
|
function writable(installation, modules, root) {
|
|
5995
|
-
if (installation.manager === "bun" && [".npmrc", "bunfig.toml", ".bunfig.toml"].some((name) => existsSync3(
|
|
6276
|
+
if (installation.manager === "bun" && [".npmrc", "bunfig.toml", ".bunfig.toml"].some((name) => existsSync3(join15(installation.prefix, name))))
|
|
5996
6277
|
return unsupported();
|
|
5997
6278
|
try {
|
|
5998
6279
|
for (const path2 of [installation.prefix, modules, dirname10(root), root])
|
|
@@ -6004,18 +6285,18 @@ function writable(installation, modules, root) {
|
|
|
6004
6285
|
"bun.lock",
|
|
6005
6286
|
"bun.lockb"
|
|
6006
6287
|
])
|
|
6007
|
-
if (existsSync3(
|
|
6008
|
-
accessSync(
|
|
6288
|
+
if (existsSync3(join15(installation.prefix, name)))
|
|
6289
|
+
accessSync(join15(installation.prefix, name), constants4.W_OK);
|
|
6009
6290
|
return installation;
|
|
6010
6291
|
} catch {
|
|
6011
6292
|
return { route: "not-writable" };
|
|
6012
6293
|
}
|
|
6013
6294
|
}
|
|
6014
6295
|
async function installation(s, commands) {
|
|
6015
|
-
const agent = agentDirectory(s), piPrefix =
|
|
6016
|
-
if (sameCopy(
|
|
6296
|
+
const agent = agentDirectory(s), piPrefix = join15(agent, "npm");
|
|
6297
|
+
if (sameCopy(join15(piPrefix, "node_modules"), s.root)) {
|
|
6017
6298
|
try {
|
|
6018
|
-
const settings2 = JSON.parse(readFileSync3(
|
|
6299
|
+
const settings2 = JSON.parse(readFileSync3(join15(agent, "settings.json"), "utf8"));
|
|
6019
6300
|
if (!settings2 || !Array.isArray(settings2.packages))
|
|
6020
6301
|
return unsupported();
|
|
6021
6302
|
const sources = settings2.packages.map((p) => typeof p === "string" ? p : p && typeof p === "object" && ("source" in p) ? p.source : undefined).filter((source) => typeof source === "string" && (source === `npm:${PACKAGE}` || source.startsWith(`npm:${PACKAGE}@`)));
|
|
@@ -6031,7 +6312,7 @@ async function installation(s, commands) {
|
|
|
6031
6312
|
route: manager === "npm" ? "pi-npm" : "pi-bun",
|
|
6032
6313
|
manager,
|
|
6033
6314
|
prefix: piPrefix
|
|
6034
|
-
},
|
|
6315
|
+
}, join15(piPrefix, "node_modules"), s.root);
|
|
6035
6316
|
} catch {
|
|
6036
6317
|
return unsupported();
|
|
6037
6318
|
}
|
|
@@ -6039,27 +6320,27 @@ async function installation(s, commands) {
|
|
|
6039
6320
|
const localModules = dirname10(dirname10(s.root)), local = dirname10(localModules);
|
|
6040
6321
|
const manifest = (() => {
|
|
6041
6322
|
try {
|
|
6042
|
-
return JSON.parse(readFileSync3(
|
|
6323
|
+
return JSON.parse(readFileSync3(join15(local, "package.json"), "utf8"));
|
|
6043
6324
|
} catch {
|
|
6044
6325
|
return;
|
|
6045
6326
|
}
|
|
6046
6327
|
})();
|
|
6047
|
-
if (manifest?.name === "pi-extensions" || basename2(dirname10(local)) === ".pi" || basename2(local) === "npm" && existsSync3(
|
|
6328
|
+
if (manifest?.name === "pi-extensions" || basename2(dirname10(local)) === ".pi" || basename2(local) === "npm" && existsSync3(join15(dirname10(local), "settings.json")))
|
|
6048
6329
|
return unsupported();
|
|
6049
6330
|
const bun = await commands.bun(["pm", "ls", "--global"]);
|
|
6050
6331
|
const bunPrefix = bun.status === 0 ? /^(\/[^\r\n]+) node_modules(?: \(\d+(?: installed)?\))?\r?$/.exec(bun.stdout.split(`
|
|
6051
6332
|
`)[0])?.[1] : undefined;
|
|
6052
|
-
if (bunPrefix && sameCopy(
|
|
6333
|
+
if (bunPrefix && sameCopy(join15(bunPrefix, "node_modules"), s.root)) {
|
|
6053
6334
|
const manager = prefixManager(bunPrefix);
|
|
6054
6335
|
if (manager === "bun")
|
|
6055
|
-
return writable({ route: "bun", manager: "bun", prefix: bunPrefix },
|
|
6336
|
+
return writable({ route: "bun", manager: "bun", prefix: bunPrefix }, join15(bunPrefix, "node_modules"), s.root);
|
|
6056
6337
|
if (!manager)
|
|
6057
6338
|
return unsupported();
|
|
6058
6339
|
}
|
|
6059
6340
|
const npm = await commands.npm(["root", "--global"]);
|
|
6060
6341
|
const modules = npm.status === 0 ? npm.stdout.trim() : "";
|
|
6061
6342
|
const prefix = dirname10(dirname10(modules));
|
|
6062
|
-
if (
|
|
6343
|
+
if (isAbsolute8(modules) && modules === join15(prefix, "lib", "node_modules") && sameCopy(modules, s.root))
|
|
6063
6344
|
return writable({ route: "npm", manager: "npm", prefix }, modules, s.root);
|
|
6064
6345
|
if (basename2(localModules) !== "node_modules" || !sameCopy(localModules, s.root))
|
|
6065
6346
|
return unsupported();
|
|
@@ -6124,9 +6405,9 @@ async function fetchVersions(i, versions, commands) {
|
|
|
6124
6405
|
})).status !== 0)
|
|
6125
6406
|
return false;
|
|
6126
6407
|
} else {
|
|
6127
|
-
const stage = mkdtempSync(
|
|
6408
|
+
const stage = mkdtempSync(join15(tmpdir(), "cadence-upgrade-"));
|
|
6128
6409
|
try {
|
|
6129
|
-
writeFileSync4(
|
|
6410
|
+
writeFileSync4(join15(stage, "package.json"), JSON.stringify({ private: true }));
|
|
6130
6411
|
if ((await commands.bun([
|
|
6131
6412
|
"add",
|
|
6132
6413
|
"--cwd",
|
|
@@ -6150,12 +6431,12 @@ async function fetchVersions(i, versions, commands) {
|
|
|
6150
6431
|
|
|
6151
6432
|
// src/service/launchd.ts
|
|
6152
6433
|
import { rmSync as rmSync5 } from "node:fs";
|
|
6153
|
-
import { dirname as dirname11, join as
|
|
6434
|
+
import { dirname as dirname11, join as join16 } from "node:path";
|
|
6154
6435
|
var LABEL = "com.abelxiaoxing.cadence";
|
|
6155
6436
|
var MARKER2 = `<?xml version="1.0" encoding="UTF-8"?>
|
|
6156
6437
|
<!-- Generated by @abelxiaoxing/cadence`;
|
|
6157
6438
|
function plistPath(s) {
|
|
6158
|
-
return
|
|
6439
|
+
return join16(s.home, "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
6159
6440
|
}
|
|
6160
6441
|
var xml = (value) => checked(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
6161
6442
|
function buildPlist(u) {
|
|
@@ -6235,11 +6516,11 @@ async function configureLaunchAgent(s, mode, requested) {
|
|
|
6235
6516
|
s.launchctl(["bootout", target(s)]);
|
|
6236
6517
|
write(path2, buildPlist({
|
|
6237
6518
|
node: s.node,
|
|
6238
|
-
cli:
|
|
6519
|
+
cli: join16(s.root, "src", "service-cli.mjs"),
|
|
6239
6520
|
workspace,
|
|
6240
6521
|
serverConfig: serverConfigPath(s.home),
|
|
6241
6522
|
environment: serviceEnvironment(s),
|
|
6242
|
-
log:
|
|
6523
|
+
log: join16(s.home, "Library", "Logs", "cadence.log")
|
|
6243
6524
|
}));
|
|
6244
6525
|
const result = {
|
|
6245
6526
|
unit: path2,
|
|
@@ -6250,7 +6531,7 @@ async function configureLaunchAgent(s, mode, requested) {
|
|
|
6250
6531
|
s.launchctl(["enable", target(s)]);
|
|
6251
6532
|
else if (disabled(s))
|
|
6252
6533
|
return { status: "disabled", ...result };
|
|
6253
|
-
if (workspace !== null && !regularFile(
|
|
6534
|
+
if (workspace !== null && !regularFile(join16(agentDirectory(s), "auth.json")))
|
|
6254
6535
|
return { status: "waiting-for-pi-login", ...result };
|
|
6255
6536
|
const started = s.launchctl(["bootstrap", domain(s), path2]).status === 0;
|
|
6256
6537
|
return { status: started ? "started" : "failed", ...result };
|
|
@@ -6299,14 +6580,14 @@ function launchAgentStatus(s) {
|
|
|
6299
6580
|
|
|
6300
6581
|
// src/service/login-run.ts
|
|
6301
6582
|
import { rmSync as rmSync6 } from "node:fs";
|
|
6302
|
-
import { dirname as dirname12, isAbsolute as
|
|
6583
|
+
import { dirname as dirname12, isAbsolute as isAbsolute9, join as join17 } from "node:path";
|
|
6303
6584
|
var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
6304
6585
|
var APPROVED_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run";
|
|
6305
6586
|
var RUN_VALUE = "Cadence";
|
|
6306
6587
|
var MARKER3 = "' Generated by @abelxiaoxing/cadence";
|
|
6307
6588
|
function launcherPath(s) {
|
|
6308
6589
|
const local = s.env.LOCALAPPDATA;
|
|
6309
|
-
return
|
|
6590
|
+
return join17(local && isAbsolute9(local) ? local : join17(s.home, "AppData", "Local"), "cadence-server", "cadence.vbs");
|
|
6310
6591
|
}
|
|
6311
6592
|
var literal2 = (value) => `"${checked(value).replaceAll('"', '""')}"`;
|
|
6312
6593
|
function argument2(value) {
|
|
@@ -6362,7 +6643,7 @@ async function configureLoginRun(s, mode, requested) {
|
|
|
6362
6643
|
const environment = s.env.PI_CODING_AGENT_DIR ? [["PI_CODING_AGENT_DIR", agentDirectory(s)]] : [];
|
|
6363
6644
|
write(path2, utf16(buildLauncher({
|
|
6364
6645
|
node: s.node,
|
|
6365
|
-
cli:
|
|
6646
|
+
cli: join17(s.root, "src", "service-cli.mjs"),
|
|
6366
6647
|
workspace,
|
|
6367
6648
|
serverConfig: serverConfigPath(s.home),
|
|
6368
6649
|
environment
|
|
@@ -6378,7 +6659,7 @@ async function configureLoginRun(s, mode, requested) {
|
|
|
6378
6659
|
return { status: "failed", ...result };
|
|
6379
6660
|
s.reg(["delete", APPROVED_KEY, "/v", RUN_VALUE, "/f"]);
|
|
6380
6661
|
}
|
|
6381
|
-
if (workspace !== null && !regularFile(
|
|
6662
|
+
if (workspace !== null && !regularFile(join17(agentDirectory(s), "auth.json")))
|
|
6382
6663
|
return { status: "waiting-for-pi-login", ...result };
|
|
6383
6664
|
return { status: s.launch(path2) ? "started" : "failed", ...result };
|
|
6384
6665
|
}
|
|
@@ -6429,7 +6710,7 @@ async function loginRunStatus(s) {
|
|
|
6429
6710
|
// src/service/maintenance.ts
|
|
6430
6711
|
import { spawn as spawn2, spawnSync as spawnSync4 } from "node:child_process";
|
|
6431
6712
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
6432
|
-
import { join as
|
|
6713
|
+
import { join as join18 } from "node:path";
|
|
6433
6714
|
var RESTART_MS = 5 * 60000;
|
|
6434
6715
|
function cgroupPath(text2) {
|
|
6435
6716
|
const lines = text2?.split(`
|
|
@@ -6447,7 +6728,7 @@ function insideUnit(s) {
|
|
|
6447
6728
|
return unit !== "" && (own === unit || own.startsWith(`${unit}/`));
|
|
6448
6729
|
}
|
|
6449
6730
|
function installedVersion(root) {
|
|
6450
|
-
const value = JSON.parse(readFileSync4(
|
|
6731
|
+
const value = JSON.parse(readFileSync4(join18(root, "package.json"), "utf8"));
|
|
6451
6732
|
if (!value || typeof value !== "object" || !("name" in value))
|
|
6452
6733
|
throw new ContractError("invalid");
|
|
6453
6734
|
literal(value.name, PACKAGE);
|
|
@@ -6539,7 +6820,7 @@ function releaseForInstallation(selected, commands, spec) {
|
|
|
6539
6820
|
async function restartInstalled(s) {
|
|
6540
6821
|
const name = serviceName(s);
|
|
6541
6822
|
const result = await run(s.node, [
|
|
6542
|
-
|
|
6823
|
+
join18(s.root, "src", "service-cli.mjs"),
|
|
6543
6824
|
"server",
|
|
6544
6825
|
"restart",
|
|
6545
6826
|
s.scope === "system" ? "--system" : "--user",
|
|
@@ -6625,7 +6906,7 @@ function jobOutcome(action, result) {
|
|
|
6625
6906
|
|
|
6626
6907
|
// src/service/system-service.ts
|
|
6627
6908
|
import { existsSync as existsSync4, realpathSync as realpathSync6, rmSync as rmSync7 } from "node:fs";
|
|
6628
|
-
import { isAbsolute as
|
|
6909
|
+
import { isAbsolute as isAbsolute10, join as join19 } from "node:path";
|
|
6629
6910
|
var MARKER4 = "# Generated by @abelxiaoxing/cadence";
|
|
6630
6911
|
function boundary(s) {
|
|
6631
6912
|
if (s.platform !== "linux" || s.scope !== "system")
|
|
@@ -6639,7 +6920,7 @@ function legacyPath(s) {
|
|
|
6639
6920
|
function observed(s) {
|
|
6640
6921
|
const path2 = unitPath(s);
|
|
6641
6922
|
let previous = readGenerated(path2, MARKER4);
|
|
6642
|
-
if (typeof previous === "string" && (unitWorkspace(previous) !== null && !
|
|
6923
|
+
if (typeof previous === "string" && (unitWorkspace(previous) !== null && !isAbsolute10(unitWorkspace(previous) ?? "") || !previous.includes(`
|
|
6643
6924
|
User=root
|
|
6644
6925
|
`)))
|
|
6645
6926
|
previous = null;
|
|
@@ -6656,7 +6937,7 @@ function sameStateEnvironment(s, previous) {
|
|
|
6656
6937
|
if (values.size !== kept.length)
|
|
6657
6938
|
return false;
|
|
6658
6939
|
const state = s.env.XDG_STATE_HOME;
|
|
6659
|
-
return values.get("HOME") === s.home && values.get("XDG_STATE_HOME") === (state &&
|
|
6940
|
+
return values.get("HOME") === s.home && values.get("XDG_STATE_HOME") === (state && isAbsolute10(state) ? state : undefined);
|
|
6660
6941
|
} catch {
|
|
6661
6942
|
return false;
|
|
6662
6943
|
}
|
|
@@ -6699,7 +6980,7 @@ async function configureSystemService(s, mode, requested) {
|
|
|
6699
6980
|
const content = buildUnit({
|
|
6700
6981
|
system: true,
|
|
6701
6982
|
node: s.node,
|
|
6702
|
-
cli:
|
|
6983
|
+
cli: join19(s.root, "src", "service-cli.mjs"),
|
|
6703
6984
|
workspace: selected.workspace,
|
|
6704
6985
|
serverConfig: serviceConfigPath(s),
|
|
6705
6986
|
agentDir,
|
|
@@ -6748,7 +7029,7 @@ async function configureSystemService(s, mode, requested) {
|
|
|
6748
7029
|
return { status: "failed", ...result, ...selected };
|
|
6749
7030
|
if (mode === "install" && s.systemctl(["enable", s.unit]).status !== 0)
|
|
6750
7031
|
return { status: "failed", ...result, ...selected };
|
|
6751
|
-
if (selected.workspace !== null && !regularFile(
|
|
7032
|
+
if (selected.workspace !== null && !regularFile(join19(agentDir, "auth.json")))
|
|
6752
7033
|
return { status: "waiting-for-pi-login", ...result, ...selected };
|
|
6753
7034
|
s.systemctl(["reset-failed", s.unit]);
|
|
6754
7035
|
return {
|
|
@@ -6988,10 +7269,10 @@ function startupGuidance(result, input) {
|
|
|
6988
7269
|
return `Pi's agent directory ${agent} must be an existing real directory (not a symlink) owned by you.
|
|
6989
7270
|
`;
|
|
6990
7271
|
case "pi-auth":
|
|
6991
|
-
return `${
|
|
7272
|
+
return `${join20(agent, "auth.json")} must be your own single-link regular file holding valid Pi credentials; log in to Pi first.
|
|
6992
7273
|
`;
|
|
6993
7274
|
case "pi-models":
|
|
6994
|
-
return `${
|
|
7275
|
+
return `${join20(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.
|
|
6995
7276
|
`;
|
|
6996
7277
|
case "pi-runtime":
|
|
6997
7278
|
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.
|
|
@@ -7228,7 +7509,7 @@ function upgrade(s, to) {
|
|
|
7228
7509
|
});
|
|
7229
7510
|
}
|
|
7230
7511
|
function serverGuidance(s, action, result, link) {
|
|
7231
|
-
const cli = piUserInstall(s) ? `node ${JSON.stringify(
|
|
7512
|
+
const cli = piUserInstall(s) ? `node ${JSON.stringify(join20(s.root, "src", "service-cli.mjs"))}` : "cadence";
|
|
7232
7513
|
const note = result.redirectedFrom ? `Cadence workspace: ${result.workspace} (${result.redirectedFrom} contains Cadence's private state)
|
|
7233
7514
|
` : "";
|
|
7234
7515
|
return note + serverStatusGuidance(s, action, result, cli, link);
|
|
@@ -7335,7 +7616,7 @@ ${manage}
|
|
|
7335
7616
|
${linger}`;
|
|
7336
7617
|
}
|
|
7337
7618
|
case "waiting-for-pi-login":
|
|
7338
|
-
return `Cadence is registered for ${result.workspace}; it starts once Pi has ${
|
|
7619
|
+
return `Cadence is registered for ${result.workspace}; it starts once Pi has ${join20(agentDirectory(s), "auth.json")}.
|
|
7339
7620
|
Log in to Pi, then: ${cli} server restart${flags}
|
|
7340
7621
|
${config}
|
|
7341
7622
|
${lingerGuidance(result.linger)}`;
|