@abelxiaoxing/cadence 2.0.44 → 2.0.45
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/docs/conversation-mode.md +12 -3
- package/package.json +2 -1
- package/src/model-preview.mjs +3180 -0
- package/src/native-build.ts +1 -1
- package/src/service/contracts/models.ts +23 -12
- package/src/service-cli.mjs +15 -4
- package/src/service-host.mjs +493 -220
- package/web/dist/assets/cadence.js +18 -18
- package/web/dist/manifest.json +5 -5
package/src/service-host.mjs
CHANGED
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
createServer as createServer2,
|
|
10
10
|
request as request2
|
|
11
11
|
} from "node:http";
|
|
12
|
-
import { homedir as
|
|
12
|
+
import { homedir as homedir9 } from "node:os";
|
|
13
13
|
import { dirname as dirname17 } from "node:path";
|
|
14
|
-
import { fileURLToPath as
|
|
14
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
15
15
|
import { WebSocket, WebSocketServer as WebSocketServer2 } from "ws";
|
|
16
16
|
|
|
17
17
|
// src/history/files.ts
|
|
@@ -3846,16 +3846,9 @@ function decodeModelCandidate(value) {
|
|
|
3846
3846
|
function catalogOffers(entries, selector) {
|
|
3847
3847
|
return entries.some((e) => e.provider === selector.provider && e.model === selector.model && e.api === selector.api && e.thinking.some((t) => t.selectable && t.level === selector.thinking));
|
|
3848
3848
|
}
|
|
3849
|
-
function
|
|
3849
|
+
function decodeModelPreview(value) {
|
|
3850
3850
|
canonicalJson({ kind: "ok", value }, LIMITS.pageBytes);
|
|
3851
|
-
const o = closed(value, [
|
|
3852
|
-
"version",
|
|
3853
|
-
"selected",
|
|
3854
|
-
"status",
|
|
3855
|
-
"entries",
|
|
3856
|
-
"withheld",
|
|
3857
|
-
"remembered"
|
|
3858
|
-
]);
|
|
3851
|
+
const o = closed(value, ["status", "entries", "withheld", "remembered"]);
|
|
3859
3852
|
const entries = list(o.entries, LIMITS.maxPageEntries, decodeModelCandidate);
|
|
3860
3853
|
const remembered = nullable(o.remembered, decodeModelSelector);
|
|
3861
3854
|
const status = oneOf(o.status, ["complete", "capacity"]);
|
|
@@ -3863,14 +3856,29 @@ function decodeModelCatalog(value) {
|
|
|
3863
3856
|
if (status === "capacity" && (entries.length || withheld) || entries.length + withheld > LIMITS.maxPageEntries || new Set(entries.map((e) => canonicalJson([e.provider, e.model]))).size !== entries.length || remembered && !catalogOffers(entries, remembered))
|
|
3864
3857
|
invalid();
|
|
3865
3858
|
return {
|
|
3866
|
-
version: decodeChoiceVersion(o.version),
|
|
3867
|
-
selected: nullable(o.selected, decodeModelSelection),
|
|
3868
3859
|
status,
|
|
3869
3860
|
entries,
|
|
3870
3861
|
withheld,
|
|
3871
3862
|
remembered
|
|
3872
3863
|
};
|
|
3873
3864
|
}
|
|
3865
|
+
function decodeModelCatalog(value) {
|
|
3866
|
+
const o = closed(value, [
|
|
3867
|
+
"version",
|
|
3868
|
+
"selected",
|
|
3869
|
+
"status",
|
|
3870
|
+
"entries",
|
|
3871
|
+
"withheld",
|
|
3872
|
+
"remembered"
|
|
3873
|
+
]);
|
|
3874
|
+
const { version, selected, ...preview } = o;
|
|
3875
|
+
canonicalJson({ kind: "ok", value }, LIMITS.pageBytes);
|
|
3876
|
+
return {
|
|
3877
|
+
...decodeModelPreview(preview),
|
|
3878
|
+
version: decodeChoiceVersion(version),
|
|
3879
|
+
selected: nullable(selected, decodeModelSelection)
|
|
3880
|
+
};
|
|
3881
|
+
}
|
|
3874
3882
|
// src/history/admission.ts
|
|
3875
3883
|
function decodeRunAdmission(value) {
|
|
3876
3884
|
const o = closed(value, ["schema", "runId", "identity", "graph"]);
|
|
@@ -12385,9 +12393,9 @@ async function stopWorkers(ledger, epoch, reboot, inspect) {
|
|
|
12385
12393
|
let stopped = 0, running = 0;
|
|
12386
12394
|
for (const worker of ledger.read(epoch)) {
|
|
12387
12395
|
const holder = holderState({ ...worker, host: hostname7() });
|
|
12388
|
-
if (holder.state
|
|
12396
|
+
if (holder.state === "dead")
|
|
12389
12397
|
continue;
|
|
12390
|
-
if (!worker.started) {
|
|
12398
|
+
if (holder.state !== "live" || !worker.started) {
|
|
12391
12399
|
running++;
|
|
12392
12400
|
continue;
|
|
12393
12401
|
}
|
|
@@ -12935,9 +12943,16 @@ async function healWorkbench(store, options = {}) {
|
|
|
12935
12943
|
}
|
|
12936
12944
|
}
|
|
12937
12945
|
const cause = !activeNow || damaged ? "storage" : holder.reboot ? "reboot" : "crash";
|
|
12946
|
+
const ledger = new ProcessLedger(store.files);
|
|
12947
|
+
const epoch = value?.epoch ?? null;
|
|
12948
|
+
const workers = takenOver ? { stopped: 0, running: 0 } : await stopWorkers(ledger, epoch, holder.reboot, !!options.inspect);
|
|
12949
|
+
if (workers.running)
|
|
12950
|
+
return { status: "blocked", reason: "workers-running", pid };
|
|
12938
12951
|
if (options.inspect)
|
|
12939
|
-
return { status: "reclaimable", cause, workers:
|
|
12952
|
+
return { status: "reclaimable", cause, workers: workers.stopped };
|
|
12940
12953
|
const actions = new Set;
|
|
12954
|
+
if (workers.stopped)
|
|
12955
|
+
actions.add("stopped-workers");
|
|
12941
12956
|
const archive = log.archive();
|
|
12942
12957
|
for (const path of temporaries) {
|
|
12943
12958
|
archive.keep(path);
|
|
@@ -12955,6 +12970,8 @@ async function healWorkbench(store, options = {}) {
|
|
|
12955
12970
|
store.files.remove(lockPath, lock.snapshot);
|
|
12956
12971
|
actions.add("released-locks");
|
|
12957
12972
|
}
|
|
12973
|
+
if (epoch)
|
|
12974
|
+
ledger.remove(epoch);
|
|
12958
12975
|
return {
|
|
12959
12976
|
status: "healed",
|
|
12960
12977
|
event: log.record({
|
|
@@ -12962,7 +12979,7 @@ async function healWorkbench(store, options = {}) {
|
|
|
12962
12979
|
path: null,
|
|
12963
12980
|
cause,
|
|
12964
12981
|
actions: [...actions],
|
|
12965
|
-
workers:
|
|
12982
|
+
workers: workers.stopped,
|
|
12966
12983
|
archive: archive.used() ? archive.name : null
|
|
12967
12984
|
})
|
|
12968
12985
|
};
|
|
@@ -12980,6 +12997,8 @@ function decodeGatewayRegistration(value) {
|
|
|
12980
12997
|
if (!o || typeof o !== "object" || !["alive", "stopping", "stopped", "quarantined"].includes(o.phase))
|
|
12981
12998
|
throw new ContractError("corrupt-selected");
|
|
12982
12999
|
integer(o.pid, 1, 2147483647);
|
|
13000
|
+
if (o.epoch !== undefined)
|
|
13001
|
+
decodeId(o.epoch);
|
|
12983
13002
|
return o;
|
|
12984
13003
|
}
|
|
12985
13004
|
|
|
@@ -14792,6 +14811,40 @@ class GatewayConversations {
|
|
|
14792
14811
|
}
|
|
14793
14812
|
}
|
|
14794
14813
|
|
|
14814
|
+
// src/service/gateway-models.ts
|
|
14815
|
+
import { homedir as homedir7 } from "node:os";
|
|
14816
|
+
async function readGatewayModels(project, input, secrets, read) {
|
|
14817
|
+
const c = project ? new ServiceCoordination(project.path, input.stateHome) : undefined;
|
|
14818
|
+
if (c && c.store.root !== project?.path)
|
|
14819
|
+
throw new ContractError("stale");
|
|
14820
|
+
const file = c?.files.read(c.path("host-config.json"));
|
|
14821
|
+
const config = c ? readHostConfig(c) : undefined;
|
|
14822
|
+
if (file && !config)
|
|
14823
|
+
throw new ContractError("corrupt-selected");
|
|
14824
|
+
const agentDir = config?.agentDir ?? input.agentDir;
|
|
14825
|
+
if (!agentDir)
|
|
14826
|
+
throw new ContractError("unavailable");
|
|
14827
|
+
const home = homedir7(), cwd = project?.path ?? home, environment2 = captureEnvironment(process.env);
|
|
14828
|
+
const source = piSource(agentDir, home, cwd, environment2);
|
|
14829
|
+
const before = readPiSnapshot(source);
|
|
14830
|
+
const catalog = await read({
|
|
14831
|
+
agentDir: source.directory,
|
|
14832
|
+
home,
|
|
14833
|
+
cwd,
|
|
14834
|
+
environment: environment2,
|
|
14835
|
+
secrets: [...secrets]
|
|
14836
|
+
});
|
|
14837
|
+
const after = readPiSnapshot(source);
|
|
14838
|
+
if (!sameModels(before, after) || before.auth.identity !== after.auth.identity || before.auth.stamp !== after.auth.stamp)
|
|
14839
|
+
throw new ContractError("stale");
|
|
14840
|
+
if (c) {
|
|
14841
|
+
c.files.assert(c.path("host-config.json"), file);
|
|
14842
|
+
if (canonicalJson(readHostConfig(c) ?? null) !== canonicalJson(config ?? null))
|
|
14843
|
+
throw new ContractError("stale");
|
|
14844
|
+
}
|
|
14845
|
+
return catalog;
|
|
14846
|
+
}
|
|
14847
|
+
|
|
14795
14848
|
// src/service/http.ts
|
|
14796
14849
|
import { createHash as createHash11, randomUUID as randomUUID12 } from "node:crypto";
|
|
14797
14850
|
import {
|
|
@@ -15676,6 +15729,187 @@ Content-Length: 0\r
|
|
|
15676
15729
|
}
|
|
15677
15730
|
}
|
|
15678
15731
|
|
|
15732
|
+
// src/service/model-preview-process.ts
|
|
15733
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
15734
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
15735
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
15736
|
+
|
|
15737
|
+
// src/service/model-preview-protocol.ts
|
|
15738
|
+
import { isAbsolute as isAbsolute11 } from "node:path";
|
|
15739
|
+
var PREVIEW_INPUT_BYTES = 1024 * 1024;
|
|
15740
|
+
var PREVIEW_TIMEOUT_MS = 15000;
|
|
15741
|
+
var PREVIEW_PROCESSES = 2;
|
|
15742
|
+
function decodeModelPreviewInput(value) {
|
|
15743
|
+
canonicalJson(value, PREVIEW_INPUT_BYTES);
|
|
15744
|
+
const o = closed(value, ["kind", "agentDir", "home", "cwd", "secrets"]);
|
|
15745
|
+
const path = (v) => {
|
|
15746
|
+
const p = text(v, 4096, true);
|
|
15747
|
+
if (!isAbsolute11(p))
|
|
15748
|
+
throw new ContractError("invalid");
|
|
15749
|
+
return p;
|
|
15750
|
+
};
|
|
15751
|
+
return {
|
|
15752
|
+
kind: literal(o.kind, "cadence-model-preview/1"),
|
|
15753
|
+
agentDir: path(o.agentDir),
|
|
15754
|
+
home: path(o.home),
|
|
15755
|
+
cwd: path(o.cwd),
|
|
15756
|
+
secrets: list(o.secrets, 4096, (v) => text(v, PREVIEW_INPUT_BYTES, true))
|
|
15757
|
+
};
|
|
15758
|
+
}
|
|
15759
|
+
|
|
15760
|
+
// src/service/model-preview-process.ts
|
|
15761
|
+
class ModelPreviewProcesses {
|
|
15762
|
+
options;
|
|
15763
|
+
jobs = new Map;
|
|
15764
|
+
stopping = false;
|
|
15765
|
+
poisoned = false;
|
|
15766
|
+
constructor(options) {
|
|
15767
|
+
this.options = options;
|
|
15768
|
+
}
|
|
15769
|
+
get uncertain() {
|
|
15770
|
+
return this.poisoned;
|
|
15771
|
+
}
|
|
15772
|
+
read(source) {
|
|
15773
|
+
try {
|
|
15774
|
+
this.options.assertCurrent();
|
|
15775
|
+
if (this.stopping || this.poisoned)
|
|
15776
|
+
throw new ContractError("quarantine");
|
|
15777
|
+
const { environment: environment2, ...fields2 } = source;
|
|
15778
|
+
const input = decodeModelPreviewInput({
|
|
15779
|
+
kind: "cadence-model-preview/1",
|
|
15780
|
+
...fields2
|
|
15781
|
+
});
|
|
15782
|
+
const body = canonicalJson(input, PREVIEW_INPUT_BYTES);
|
|
15783
|
+
const env = captureEnvironment(hostEnvironment(environment2));
|
|
15784
|
+
const key = createHash12("sha256").update(body).update(JSON.stringify(env)).digest("hex");
|
|
15785
|
+
const previous = this.jobs.get(key);
|
|
15786
|
+
if (previous)
|
|
15787
|
+
return previous.result;
|
|
15788
|
+
if (this.jobs.size >= PREVIEW_PROCESSES)
|
|
15789
|
+
throw new ContractError("capacity");
|
|
15790
|
+
const job2 = this.launch(body, env, key, input.home);
|
|
15791
|
+
this.jobs.set(key, job2);
|
|
15792
|
+
return job2.result;
|
|
15793
|
+
} catch (error) {
|
|
15794
|
+
return Promise.reject(error);
|
|
15795
|
+
}
|
|
15796
|
+
}
|
|
15797
|
+
invalidate() {
|
|
15798
|
+
for (const job2 of this.jobs.values())
|
|
15799
|
+
job2.stop();
|
|
15800
|
+
}
|
|
15801
|
+
async close() {
|
|
15802
|
+
this.stopping = true;
|
|
15803
|
+
this.invalidate();
|
|
15804
|
+
await Promise.all([...this.jobs.values()].map((job2) => job2.settlement));
|
|
15805
|
+
if (this.poisoned)
|
|
15806
|
+
throw new ContractError("quarantine");
|
|
15807
|
+
}
|
|
15808
|
+
launch(body, env, key, cwd) {
|
|
15809
|
+
let resolveResult, rejectResult;
|
|
15810
|
+
let resolveSettlement, rejectSettlement;
|
|
15811
|
+
const result = new Promise((resolve11, reject) => {
|
|
15812
|
+
resolveResult = resolve11;
|
|
15813
|
+
rejectResult = reject;
|
|
15814
|
+
});
|
|
15815
|
+
const settlement = new Promise((resolve11, reject) => {
|
|
15816
|
+
resolveSettlement = resolve11;
|
|
15817
|
+
rejectSettlement = reject;
|
|
15818
|
+
});
|
|
15819
|
+
result.catch(() => {});
|
|
15820
|
+
settlement.catch(() => {});
|
|
15821
|
+
const child2 = spawn4(process.execPath, [fileURLToPath3(this.options.worker)], {
|
|
15822
|
+
cwd,
|
|
15823
|
+
env,
|
|
15824
|
+
windowsHide: true,
|
|
15825
|
+
detached: process.platform !== "win32",
|
|
15826
|
+
stdio: ["pipe", "pipe", "ignore", "ipc"]
|
|
15827
|
+
});
|
|
15828
|
+
const pid = child2.pid, started = pid ? processStart(pid) : null;
|
|
15829
|
+
let closed2 = false, stopping = false, failed;
|
|
15830
|
+
let bytes = 0;
|
|
15831
|
+
const chunks = [];
|
|
15832
|
+
let killTimer;
|
|
15833
|
+
let unknownTimer;
|
|
15834
|
+
const signal = (value) => {
|
|
15835
|
+
if (closed2 || child2.exitCode !== null || child2.signalCode !== null || !pid)
|
|
15836
|
+
return;
|
|
15837
|
+
try {
|
|
15838
|
+
this.options.assertCurrent();
|
|
15839
|
+
} catch {
|
|
15840
|
+
return;
|
|
15841
|
+
}
|
|
15842
|
+
if (started && processStart(pid) !== started)
|
|
15843
|
+
return;
|
|
15844
|
+
try {
|
|
15845
|
+
child2.kill(value);
|
|
15846
|
+
} catch {}
|
|
15847
|
+
};
|
|
15848
|
+
const stop = (error = new ContractError("unavailable")) => {
|
|
15849
|
+
failed ??= error;
|
|
15850
|
+
if (closed2 || stopping)
|
|
15851
|
+
return;
|
|
15852
|
+
stopping = true;
|
|
15853
|
+
signal("SIGTERM");
|
|
15854
|
+
killTimer = setTimeout(() => signal("SIGKILL"), LIMITS.terminateGraceMs);
|
|
15855
|
+
unknownTimer = setTimeout(() => {
|
|
15856
|
+
if (closed2)
|
|
15857
|
+
return;
|
|
15858
|
+
this.poisoned = true;
|
|
15859
|
+
const error2 = new ContractError("quarantine");
|
|
15860
|
+
rejectResult(error2);
|
|
15861
|
+
rejectSettlement(error2);
|
|
15862
|
+
this.options.unconfirmed();
|
|
15863
|
+
}, LIMITS.unconfirmedStopMs);
|
|
15864
|
+
};
|
|
15865
|
+
const deadline = setTimeout(() => stop(), PREVIEW_TIMEOUT_MS);
|
|
15866
|
+
child2.once("error", () => stop());
|
|
15867
|
+
child2.stdin?.on("error", () => stop());
|
|
15868
|
+
child2.stdout?.on("error", () => stop());
|
|
15869
|
+
child2.stdout?.on("data", (chunk) => {
|
|
15870
|
+
if (failed)
|
|
15871
|
+
return;
|
|
15872
|
+
bytes += chunk.length;
|
|
15873
|
+
if (bytes > LIMITS.pageBytes) {
|
|
15874
|
+
chunks.length = 0;
|
|
15875
|
+
stop(new ContractError("oversize"));
|
|
15876
|
+
} else
|
|
15877
|
+
chunks.push(chunk);
|
|
15878
|
+
});
|
|
15879
|
+
child2.once("close", (code2, nativeSignal) => {
|
|
15880
|
+
closed2 = true;
|
|
15881
|
+
clearTimeout(deadline);
|
|
15882
|
+
clearTimeout(killTimer);
|
|
15883
|
+
clearTimeout(unknownTimer);
|
|
15884
|
+
this.jobs.delete(key);
|
|
15885
|
+
if (pid)
|
|
15886
|
+
this.options.closed(pid);
|
|
15887
|
+
resolveSettlement();
|
|
15888
|
+
if (failed || code2 !== 0 || nativeSignal) {
|
|
15889
|
+
rejectResult(failed ?? new ContractError("unavailable"));
|
|
15890
|
+
return;
|
|
15891
|
+
}
|
|
15892
|
+
try {
|
|
15893
|
+
this.options.assertCurrent();
|
|
15894
|
+
const reply = decodeReply(parseWireJson(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks)), LIMITS.pageBytes), decodeModelPreview);
|
|
15895
|
+
if (reply.kind === "error")
|
|
15896
|
+
throw new ContractError(reply.error.code);
|
|
15897
|
+
resolveResult(reply.value);
|
|
15898
|
+
} catch (error) {
|
|
15899
|
+
rejectResult(error instanceof ContractError ? error : new ContractError("unavailable"));
|
|
15900
|
+
}
|
|
15901
|
+
});
|
|
15902
|
+
try {
|
|
15903
|
+
if (pid)
|
|
15904
|
+
this.options.launched(pid);
|
|
15905
|
+
} catch {
|
|
15906
|
+
stop();
|
|
15907
|
+
}
|
|
15908
|
+
child2.stdin?.end(body);
|
|
15909
|
+
return { result, settlement, stop: () => stop() };
|
|
15910
|
+
}
|
|
15911
|
+
}
|
|
15912
|
+
|
|
15679
15913
|
// src/service/workbench-files.ts
|
|
15680
15914
|
import {
|
|
15681
15915
|
closeSync as closeSync7,
|
|
@@ -15687,11 +15921,11 @@ import {
|
|
|
15687
15921
|
readSync as readSync5,
|
|
15688
15922
|
realpathSync as realpathSync9
|
|
15689
15923
|
} from "node:fs";
|
|
15690
|
-
import { homedir as
|
|
15691
|
-
import { dirname as dirname16, isAbsolute as
|
|
15924
|
+
import { homedir as homedir8 } from "node:os";
|
|
15925
|
+
import { dirname as dirname16, isAbsolute as isAbsolute12, join as join27, relative as relative5, resolve as resolve11, sep as sep5 } from "node:path";
|
|
15692
15926
|
function inside(root, path) {
|
|
15693
15927
|
const r = relative5(root, path);
|
|
15694
|
-
return r === "" || !
|
|
15928
|
+
return r === "" || !isAbsolute12(r) && r !== ".." && !r.startsWith(`..${sep5}`);
|
|
15695
15929
|
}
|
|
15696
15930
|
var sensitive2 = (name) => /^\.(?:git|ssh|aws|azure|gnupg|kube|npmrc|pypirc|netrc)$/i.test(name) || /^\.env(?:\.|$)/i.test(name) || /^(?:auth|models|credentials|service-account)\.json$/i.test(name) || /^id_(?:rsa|dsa|ecdsa|ed25519)(?:\.|$)/i.test(name) || /\.(?:pem|key|p12|pfx)$/i.test(name);
|
|
15697
15931
|
|
|
@@ -15715,14 +15949,14 @@ class WorkbenchFiles {
|
|
|
15715
15949
|
throw new ContractError("forbidden");
|
|
15716
15950
|
}
|
|
15717
15951
|
directory(path) {
|
|
15718
|
-
if (!
|
|
15952
|
+
if (!isAbsolute12(path) || !safeDirectory(path))
|
|
15719
15953
|
throw new ContractError("invalid");
|
|
15720
15954
|
const canonical = realpathSync9(path);
|
|
15721
15955
|
this.allowed(canonical);
|
|
15722
15956
|
return canonical;
|
|
15723
15957
|
}
|
|
15724
15958
|
selected(path) {
|
|
15725
|
-
if (
|
|
15959
|
+
if (isAbsolute12(path) || path.split(/[\\/]/).some((part) => part === ".." || sensitive2(part)))
|
|
15726
15960
|
throw new ContractError("forbidden");
|
|
15727
15961
|
const target = resolve11(this.root, path);
|
|
15728
15962
|
if (!inside(this.root, target) || !safeDirectory(dirname16(target)))
|
|
@@ -15733,7 +15967,7 @@ class WorkbenchFiles {
|
|
|
15733
15967
|
return target;
|
|
15734
15968
|
}
|
|
15735
15969
|
browsed(path) {
|
|
15736
|
-
const full = /^~(?:[\\/]|$)/.test(path) ? join27(
|
|
15970
|
+
const full = /^~(?:[\\/]|$)/.test(path) ? join27(homedir8(), path.slice(1)) : path || this.root;
|
|
15737
15971
|
try {
|
|
15738
15972
|
return this.directory(full);
|
|
15739
15973
|
} catch (error) {
|
|
@@ -15844,7 +16078,7 @@ async function createGateway(value, hostUrl, source) {
|
|
|
15844
16078
|
const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
|
|
15845
16079
|
const web = loadWebAssets(source?.webDirectory);
|
|
15846
16080
|
const build2 = {
|
|
15847
|
-
contractHash: "
|
|
16081
|
+
contractHash: "ee8ae17515fd8baf0aba38eb6a78a27e8c574cda265ddc17884c0741a6fb56b1",
|
|
15848
16082
|
assets: {
|
|
15849
16083
|
sourceHash: web.manifest.sourceHash,
|
|
15850
16084
|
contractHash: web.manifest.contractHash,
|
|
@@ -15964,13 +16198,25 @@ Content-Length: 0\r
|
|
|
15964
16198
|
secrets: () => acquired.access.redactionLiterals()
|
|
15965
16199
|
});
|
|
15966
16200
|
acquired.access.onRevoke(() => activity2.invalidate());
|
|
15967
|
-
const files = new WorkbenchFiles(
|
|
16201
|
+
const files = new WorkbenchFiles(homedir9(), [store.files.namespace, input.agentDir], () => acquired.access.redactionLiterals());
|
|
15968
16202
|
const assert = () => {
|
|
15969
16203
|
store.assert();
|
|
15970
16204
|
if (!accepting)
|
|
15971
16205
|
throw new ContractError("quarantine");
|
|
15972
16206
|
};
|
|
15973
|
-
|
|
16207
|
+
let previewLedger;
|
|
16208
|
+
const modelPreviews = new ModelPreviewProcesses({
|
|
16209
|
+
worker: new URL("./model-preview.mjs", hostUrl),
|
|
16210
|
+
assertCurrent: () => store.assert(),
|
|
16211
|
+
launched: (pid) => {
|
|
16212
|
+
previewLedger ??= new ProcessLedger(store.files).open(auth.epoch);
|
|
16213
|
+
previewLedger.add(pid);
|
|
16214
|
+
},
|
|
16215
|
+
closed: (pid) => previewLedger?.remove(pid),
|
|
16216
|
+
unconfirmed: () => stop()
|
|
16217
|
+
});
|
|
16218
|
+
acquired.access.onRevoke(() => modelPreviews.invalidate());
|
|
16219
|
+
const root = dirname17(dirname17(fileURLToPath4(hostUrl))), version = installedVersion(root), record3 = new MaintenanceRecord(store);
|
|
15974
16220
|
const managed = (() => {
|
|
15975
16221
|
const s = supervisingUnit(process.env, (selection) => hostSystem(root, ownerControl, selection));
|
|
15976
16222
|
return s && serviceConfigPath(s) === input.serverConfig ? s : undefined;
|
|
@@ -16216,6 +16462,8 @@ Content-Length: 0\r
|
|
|
16216
16462
|
return;
|
|
16217
16463
|
accepting = false;
|
|
16218
16464
|
activity2.close();
|
|
16465
|
+
const previewsClosed = modelPreviews.close();
|
|
16466
|
+
previewsClosed.catch(() => {});
|
|
16219
16467
|
store.phase("stopping");
|
|
16220
16468
|
stopping = (async () => {
|
|
16221
16469
|
await Promise.allSettled([...preparations.values()].map((o) => o.result));
|
|
@@ -16237,6 +16485,8 @@ Content-Length: 0\r
|
|
|
16237
16485
|
if ((await stopService(c)).status !== "stopped")
|
|
16238
16486
|
throw new ContractError("quarantine");
|
|
16239
16487
|
});
|
|
16488
|
+
await previewsClosed;
|
|
16489
|
+
previewLedger?.close();
|
|
16240
16490
|
conversations.close();
|
|
16241
16491
|
store.release();
|
|
16242
16492
|
for (const close of relays)
|
|
@@ -16252,6 +16502,8 @@ Content-Length: 0\r
|
|
|
16252
16502
|
server.close();
|
|
16253
16503
|
for (const socket of connections)
|
|
16254
16504
|
socket.destroy();
|
|
16505
|
+
if (modelPreviews.uncertain)
|
|
16506
|
+
process.exit(75);
|
|
16255
16507
|
});
|
|
16256
16508
|
}
|
|
16257
16509
|
async function body(req, maximum = 16384) {
|
|
@@ -16530,6 +16782,21 @@ Content-Length: 0\r
|
|
|
16530
16782
|
});
|
|
16531
16783
|
return;
|
|
16532
16784
|
}
|
|
16785
|
+
if (url.pathname === "/workbench/v1/models" && req.method === "GET") {
|
|
16786
|
+
browserBuild(boundary);
|
|
16787
|
+
const keys2 = [...url.searchParams.keys()];
|
|
16788
|
+
if (keys2.length && (keys2.length !== 1 || keys2[0] !== "project"))
|
|
16789
|
+
throw new ContractError("invalid");
|
|
16790
|
+
const id = url.searchParams.get("project");
|
|
16791
|
+
const selected2 = id === null ? undefined : store.projects().find((p) => p.id === decodeHash(id));
|
|
16792
|
+
if (id !== null && !selected2)
|
|
16793
|
+
throw new ContractError("unavailable");
|
|
16794
|
+
const catalog = await readGatewayModels(selected2, input, acquired.access.redactionLiterals(), (source2) => modelPreviews.read(source2));
|
|
16795
|
+
auth.current(caller);
|
|
16796
|
+
assert();
|
|
16797
|
+
reply(res, 200, catalog, LIMITS.pageBytes);
|
|
16798
|
+
return;
|
|
16799
|
+
}
|
|
16533
16800
|
if (raw === "/workbench/v1/activity" && req.method === "GET") {
|
|
16534
16801
|
browserBuild(boundary);
|
|
16535
16802
|
const value2 = await activity2.read();
|
|
@@ -16543,7 +16810,7 @@ Content-Length: 0\r
|
|
|
16543
16810
|
kind: "workbench",
|
|
16544
16811
|
epoch: auth.epoch,
|
|
16545
16812
|
csrf: auth.csrf,
|
|
16546
|
-
home:
|
|
16813
|
+
home: homedir9(),
|
|
16547
16814
|
projects: store.projects(),
|
|
16548
16815
|
recoveries: new RecoveryLog(store.files).notices(),
|
|
16549
16816
|
build: build2
|
|
@@ -16694,14 +16961,14 @@ Content-Length: 0\r
|
|
|
16694
16961
|
}
|
|
16695
16962
|
|
|
16696
16963
|
// src/service/host.ts
|
|
16697
|
-
import { spawn as
|
|
16964
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
16698
16965
|
import { lstatSync as lstatSync25, opendirSync as opendirSync16 } from "node:fs";
|
|
16699
16966
|
import { join as join43 } from "node:path";
|
|
16700
|
-
import { fileURLToPath as
|
|
16967
|
+
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
16701
16968
|
|
|
16702
16969
|
// src/agent-registry.ts
|
|
16703
|
-
import { createHash as
|
|
16704
|
-
import { fileURLToPath as
|
|
16970
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
16971
|
+
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
16705
16972
|
var AGENT_FILES = [
|
|
16706
16973
|
"design-explorer.md",
|
|
16707
16974
|
"implementation-worker.md",
|
|
@@ -16709,7 +16976,7 @@ var AGENT_FILES = [
|
|
|
16709
16976
|
];
|
|
16710
16977
|
function loadAgentDefinitions() {
|
|
16711
16978
|
return AGENT_FILES.map((fileName) => {
|
|
16712
|
-
const path =
|
|
16979
|
+
const path = fileURLToPath5(new URL(`../agents/${fileName}`, import.meta.url));
|
|
16713
16980
|
const data2 = readBounded(path, 32768, true);
|
|
16714
16981
|
if (!data2)
|
|
16715
16982
|
throw new Error("Missing package Agent");
|
|
@@ -16717,7 +16984,7 @@ function loadAgentDefinitions() {
|
|
|
16717
16984
|
role: fileName.replace(/\.md$/, ""),
|
|
16718
16985
|
fileName,
|
|
16719
16986
|
path,
|
|
16720
|
-
sha256:
|
|
16987
|
+
sha256: createHash13("sha256").update(data2).digest("hex"),
|
|
16721
16988
|
bytes: data2.length,
|
|
16722
16989
|
content: data2.toString("utf8")
|
|
16723
16990
|
};
|
|
@@ -16972,7 +17239,7 @@ class HistoryLive {
|
|
|
16972
17239
|
}
|
|
16973
17240
|
|
|
16974
17241
|
// src/history/navigation.ts
|
|
16975
|
-
import { createHash as
|
|
17242
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
16976
17243
|
import { lstatSync as lstatSync18 } from "node:fs";
|
|
16977
17244
|
import { dirname as dirname18, join as join29 } from "node:path";
|
|
16978
17245
|
|
|
@@ -18199,7 +18466,7 @@ class HistoryNavigation {
|
|
|
18199
18466
|
continue;
|
|
18200
18467
|
}
|
|
18201
18468
|
let pending = Buffer.alloc(0), at = offset, bodyBytes = 0;
|
|
18202
|
-
const checksum =
|
|
18469
|
+
const checksum = createHash14("sha256"), rows = [];
|
|
18203
18470
|
while (at < size2) {
|
|
18204
18471
|
const chunk = this.block(path, at, size2, budget);
|
|
18205
18472
|
at += chunk.length;
|
|
@@ -18702,7 +18969,7 @@ function navigationKeys(row) {
|
|
|
18702
18969
|
}
|
|
18703
18970
|
|
|
18704
18971
|
// src/history/projection.ts
|
|
18705
|
-
import { createHash as
|
|
18972
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
18706
18973
|
|
|
18707
18974
|
// src/history/task-folds.ts
|
|
18708
18975
|
var TASKS = 1024;
|
|
@@ -19045,17 +19312,17 @@ function materializeEntity(s, sources) {
|
|
|
19045
19312
|
}
|
|
19046
19313
|
|
|
19047
19314
|
// src/history/export.ts
|
|
19048
|
-
import { createHash as
|
|
19315
|
+
import { createHash as createHash18, randomUUID as randomUUID14 } from "node:crypto";
|
|
19049
19316
|
import { readFileSync as readFileSync5 } from "node:fs";
|
|
19050
19317
|
|
|
19051
19318
|
// src/history/search.ts
|
|
19052
|
-
import { createHash as
|
|
19319
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
19053
19320
|
|
|
19054
19321
|
// src/history/read-proof.ts
|
|
19055
19322
|
import {
|
|
19056
19323
|
createCipheriv,
|
|
19057
19324
|
createDecipheriv,
|
|
19058
|
-
createHash as
|
|
19325
|
+
createHash as createHash15,
|
|
19059
19326
|
randomBytes as randomBytes5
|
|
19060
19327
|
} from "node:crypto";
|
|
19061
19328
|
var PREFIX = "rp1.";
|
|
@@ -19107,7 +19374,7 @@ class HistoryReadProof {
|
|
|
19107
19374
|
root: this.files.format.rootIdentity,
|
|
19108
19375
|
format: material.formatStamp,
|
|
19109
19376
|
key: material.keyStamp,
|
|
19110
|
-
request:
|
|
19377
|
+
request: createHash15("sha256").update(canonicalJson(readIdentity(request3))).digest("hex")
|
|
19111
19378
|
}));
|
|
19112
19379
|
}
|
|
19113
19380
|
seal(context, plaintext, budget) {
|
|
@@ -19879,11 +20146,11 @@ function decodeRetainedProgress(value) {
|
|
|
19879
20146
|
}
|
|
19880
20147
|
|
|
19881
20148
|
// src/history/retained-traversal.ts
|
|
19882
|
-
import { createHash as
|
|
20149
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
19883
20150
|
function bad5() {
|
|
19884
20151
|
throw new ContractError("corrupt-selected");
|
|
19885
20152
|
}
|
|
19886
|
-
var fingerprint = (v) =>
|
|
20153
|
+
var fingerprint = (v) => createHash16("sha256").update(canonicalJson(v)).digest("hex");
|
|
19887
20154
|
var ready = (v) => {
|
|
19888
20155
|
const s = v.state;
|
|
19889
20156
|
if (s.phase !== "ready")
|
|
@@ -20239,11 +20506,11 @@ var digits = (id) => {
|
|
|
20239
20506
|
return s.slice(0, 12) + s.slice(13, 16) + s.slice(17);
|
|
20240
20507
|
};
|
|
20241
20508
|
var publicTextRef = (id, label, text2, field, batch, row, slot) => ({
|
|
20242
|
-
recordId: uuid(address(batch.pointer).toString(16).padStart(14, "0") +
|
|
20509
|
+
recordId: uuid(address(batch.pointer).toString(16).padStart(14, "0") + createHash17("sha256").update(`${id}/${label}`).digest("hex").slice(0, 16)),
|
|
20243
20510
|
version: batch.rows.indexOf(row) * EVENT_SLOTS + slot + 1,
|
|
20244
20511
|
field,
|
|
20245
20512
|
bytes: Buffer.byteLength(text2),
|
|
20246
|
-
sha256:
|
|
20513
|
+
sha256: createHash17("sha256").update(text2).digest("hex")
|
|
20247
20514
|
});
|
|
20248
20515
|
var initial = () => ({
|
|
20249
20516
|
pos: { segment: 1, offset: 0 },
|
|
@@ -20259,7 +20526,7 @@ function scanCursor(base, p) {
|
|
|
20259
20526
|
const snapshot = p.snapshot.toString(16).padStart(14, "0");
|
|
20260
20527
|
if (snapshot.length !== 14)
|
|
20261
20528
|
throw new ContractError("capacity");
|
|
20262
|
-
const binding =
|
|
20529
|
+
const binding = createHash17("sha256").update(canonicalJson({
|
|
20263
20530
|
...readIdentity(base),
|
|
20264
20531
|
recordId: null,
|
|
20265
20532
|
recordVersion: version,
|
|
@@ -20600,7 +20867,7 @@ class RetainedScan {
|
|
|
20600
20867
|
graph: {
|
|
20601
20868
|
recordId: v.intent.operationId,
|
|
20602
20869
|
revision: graph.revision,
|
|
20603
|
-
sha256:
|
|
20870
|
+
sha256: createHash17("sha256").update(canonicalJson(graph)).digest("hex")
|
|
20604
20871
|
}
|
|
20605
20872
|
},
|
|
20606
20873
|
graph
|
|
@@ -20899,7 +21166,7 @@ async function searchQuantum(reader, value, limit = LIMITS.pageEntries) {
|
|
|
20899
21166
|
// src/history/export.ts
|
|
20900
21167
|
var exporterIdentity;
|
|
20901
21168
|
function buildIdentity() {
|
|
20902
|
-
exporterIdentity ??=
|
|
21169
|
+
exporterIdentity ??= createHash18("sha256").update(readFileSync5(new URL(import.meta.url))).digest("hex");
|
|
20903
21170
|
return exporterIdentity;
|
|
20904
21171
|
}
|
|
20905
21172
|
function aborted(signal) {
|
|
@@ -20959,7 +21226,7 @@ Coverage: ${canonicalJson(event.coverage)}
|
|
|
20959
21226
|
}
|
|
20960
21227
|
}
|
|
20961
21228
|
async function* exportHistory(projection, input, signal) {
|
|
20962
|
-
const request3 = decodeExportRequest(input), exportId = randomUUID14(), digest =
|
|
21229
|
+
const request3 = decodeExportRequest(input), exportId = randomUUID14(), digest = createHash18("sha256");
|
|
20963
21230
|
let ordinal = 0, encodedBytes = 0, coverage = { ...COMPLETE, omissions: [] };
|
|
20964
21231
|
const frame = (event) => {
|
|
20965
21232
|
aborted(signal);
|
|
@@ -21028,7 +21295,7 @@ async function* exportHistory(projection, input, signal) {
|
|
|
21028
21295
|
const { detail, owner } = item, original = open2.get(detail.content.recordId);
|
|
21029
21296
|
if (detail.content.bytes ? !original || original.bytes !== detail.content.bytes || original.content !== canonicalJson(detail.content) : original !== undefined)
|
|
21030
21297
|
throw new ContractError("corrupt-selected");
|
|
21031
|
-
if ((original?.hash ??
|
|
21298
|
+
if ((original?.hash ?? createHash18("sha256")).digest("hex") !== detail.content.sha256)
|
|
21032
21299
|
throw new ContractError("corrupt-selected");
|
|
21033
21300
|
open2.delete(detail.content.recordId);
|
|
21034
21301
|
const events = [];
|
|
@@ -21059,7 +21326,7 @@ async function* exportHistory(projection, input, signal) {
|
|
|
21059
21326
|
coverage = combineCoverage(coverage, item.coverage);
|
|
21060
21327
|
const length = Buffer.byteLength(item.text);
|
|
21061
21328
|
if (item.inline) {
|
|
21062
|
-
if (item.start !== 0 || length !== item.content.bytes ||
|
|
21329
|
+
if (item.start !== 0 || length !== item.content.bytes || createHash18("sha256").update(item.text).digest("hex") !== item.content.sha256)
|
|
21063
21330
|
throw new ContractError("corrupt-selected");
|
|
21064
21331
|
} else {
|
|
21065
21332
|
let original = open2.get(item.content.recordId);
|
|
@@ -21069,7 +21336,7 @@ async function* exportHistory(projection, input, signal) {
|
|
|
21069
21336
|
original = {
|
|
21070
21337
|
bytes: 0,
|
|
21071
21338
|
content: canonicalJson(item.content),
|
|
21072
|
-
hash:
|
|
21339
|
+
hash: createHash18("sha256")
|
|
21073
21340
|
};
|
|
21074
21341
|
open2.set(item.content.recordId, original);
|
|
21075
21342
|
}
|
|
@@ -21184,7 +21451,7 @@ async function* exportHistory(projection, input, signal) {
|
|
|
21184
21451
|
}
|
|
21185
21452
|
|
|
21186
21453
|
// src/history/list-progress.ts
|
|
21187
|
-
import { createHash as
|
|
21454
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
21188
21455
|
|
|
21189
21456
|
// src/history/detail-progress.ts
|
|
21190
21457
|
function bad7() {
|
|
@@ -21658,7 +21925,7 @@ function fits(link, scope) {
|
|
|
21658
21925
|
return scope.kind === "workspace" || (scope.kind === "task" ? link.taskId === scope.id : scope.kind === "run" ? link.runId === scope.id : link.childRunId === scope.id);
|
|
21659
21926
|
}
|
|
21660
21927
|
function nextAfter(request3, n) {
|
|
21661
|
-
const h =
|
|
21928
|
+
const h = createHash19("sha256").update(canonicalJson({ ...readIdentity(request3), after: null, ordinal: n })).digest("hex");
|
|
21662
21929
|
return {
|
|
21663
21930
|
recordId: `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`,
|
|
21664
21931
|
version: 1,
|
|
@@ -22042,7 +22309,7 @@ async function read(p, request3, entity) {
|
|
|
22042
22309
|
const tasks = [...p.environment.legacyTasks(budget)].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
22043
22310
|
if (tasks.length > 1000)
|
|
22044
22311
|
throw new ContractError("capacity");
|
|
22045
|
-
const sum =
|
|
22312
|
+
const sum = createHash19("sha256");
|
|
22046
22313
|
for (const task2 of tasks) {
|
|
22047
22314
|
budget.reserve(0);
|
|
22048
22315
|
sum.update(JSON.stringify({
|
|
@@ -22055,7 +22322,7 @@ async function read(p, request3, entity) {
|
|
|
22055
22322
|
if (s.legacy > tasks.length)
|
|
22056
22323
|
bad9();
|
|
22057
22324
|
if (!s.legacyIdentity && request3.after?.version === Number.MAX_SAFE_INTEGER) {
|
|
22058
|
-
const h =
|
|
22325
|
+
const h = createHash19("sha256").update(canonicalJson({
|
|
22059
22326
|
...readIdentity(request3),
|
|
22060
22327
|
after: null,
|
|
22061
22328
|
legacy: s.legacy === 0 ? "begin" : identity,
|
|
@@ -22335,7 +22602,7 @@ class HistoryProjection {
|
|
|
22335
22602
|
};
|
|
22336
22603
|
cursor(request3, pos, row, item) {
|
|
22337
22604
|
const offset = pos.offset * (LIMITS.segmentRecords + 1) * ROW_SLOTS + row * ROW_SLOTS + item;
|
|
22338
|
-
const digest =
|
|
22605
|
+
const digest = createHash20("sha256").update(canonicalJson({
|
|
22339
22606
|
...readIdentity(request3),
|
|
22340
22607
|
after: null,
|
|
22341
22608
|
position: { ...pos, row, item }
|
|
@@ -22526,7 +22793,7 @@ class HistoryProjection {
|
|
|
22526
22793
|
if (legacyPhase)
|
|
22527
22794
|
this.navigation.snapshot(snapshot, budget);
|
|
22528
22795
|
const cursor = (offset2, identity2) => {
|
|
22529
|
-
const digest2 =
|
|
22796
|
+
const digest2 = createHash20("sha256").update(canonicalJson({ ...request3, after: null, legacy: identity2, offset: offset2 })).digest("hex");
|
|
22530
22797
|
return {
|
|
22531
22798
|
recordId: `${digest2.slice(0, 8)}-${digest2.slice(8, 12)}-4${digest2.slice(13, 16)}-8${digest2.slice(17, 20)}-${digest2.slice(20, 32)}`,
|
|
22532
22799
|
version: legacyVersion,
|
|
@@ -22553,7 +22820,7 @@ class HistoryProjection {
|
|
|
22553
22820
|
}
|
|
22554
22821
|
if (legacy.length > 1000)
|
|
22555
22822
|
throw new ContractError("capacity");
|
|
22556
|
-
const items = [...legacy].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0), digest =
|
|
22823
|
+
const items = [...legacy].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0), digest = createHash20("sha256");
|
|
22557
22824
|
for (const item of items) {
|
|
22558
22825
|
budget.reserve(0);
|
|
22559
22826
|
if (Buffer.byteLength(item.goal) > 8192)
|
|
@@ -22743,7 +23010,7 @@ class HistoryProjection {
|
|
|
22743
23010
|
}
|
|
22744
23011
|
|
|
22745
23012
|
// src/history/reader.ts
|
|
22746
|
-
import { createHash as
|
|
23013
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
22747
23014
|
import { existsSync as existsSync3 } from "node:fs";
|
|
22748
23015
|
import { join as join30 } from "node:path";
|
|
22749
23016
|
|
|
@@ -23405,7 +23672,7 @@ class HistoryReader {
|
|
|
23405
23672
|
}
|
|
23406
23673
|
}
|
|
23407
23674
|
const text2 = Buffer.concat(pieces);
|
|
23408
|
-
if (end !== detail.content.bytes ||
|
|
23675
|
+
if (end !== detail.content.bytes || createHash21("sha256").update(text2).digest("hex") !== detail.content.sha256)
|
|
23409
23676
|
return;
|
|
23410
23677
|
return { detail, bytes: text2 };
|
|
23411
23678
|
} catch {
|
|
@@ -23440,7 +23707,7 @@ class HistoryReader {
|
|
|
23440
23707
|
if (!current2 || current2.length < expected.bytes || hash(current2.subarray(0, expected.bytes)) !== expected.identity)
|
|
23441
23708
|
throw new ContractError("corrupt-selected");
|
|
23442
23709
|
}
|
|
23443
|
-
const checksum =
|
|
23710
|
+
const checksum = createHash21("sha256");
|
|
23444
23711
|
let bytes = 0;
|
|
23445
23712
|
let cached;
|
|
23446
23713
|
for (const e of locator.chunks) {
|
|
@@ -23714,16 +23981,16 @@ class HistoryReader {
|
|
|
23714
23981
|
}
|
|
23715
23982
|
|
|
23716
23983
|
// src/history/recovery.ts
|
|
23717
|
-
import { createHash as
|
|
23984
|
+
import { createHash as createHash25, randomUUID as randomUUID18 } from "node:crypto";
|
|
23718
23985
|
import { lstatSync as lstatSync19, opendirSync as opendirSync10 } from "node:fs";
|
|
23719
23986
|
import { join as join34, relative as relative7 } from "node:path";
|
|
23720
23987
|
|
|
23721
23988
|
// src/history/writer.ts
|
|
23722
|
-
import { createHash as
|
|
23989
|
+
import { createHash as createHash24, randomUUID as randomUUID17 } from "node:crypto";
|
|
23723
23990
|
import { join as join33 } from "node:path";
|
|
23724
23991
|
|
|
23725
23992
|
// src/task-store.ts
|
|
23726
|
-
import { createHash as
|
|
23993
|
+
import { createHash as createHash22, randomUUID as randomUUID15 } from "node:crypto";
|
|
23727
23994
|
import {
|
|
23728
23995
|
closeSync as closeSync8,
|
|
23729
23996
|
fsyncSync as fsyncSync4,
|
|
@@ -23811,7 +24078,7 @@ function recordText(record3) {
|
|
|
23811
24078
|
`;
|
|
23812
24079
|
}
|
|
23813
24080
|
function contentIdentity(text2) {
|
|
23814
|
-
return
|
|
24081
|
+
return createHash22("sha256").update(text2).digest("hex");
|
|
23815
24082
|
}
|
|
23816
24083
|
function savedRecordIdentity(record3) {
|
|
23817
24084
|
return contentIdentity(recordText(record3));
|
|
@@ -23956,11 +24223,11 @@ function legacyTaskStore(c) {
|
|
|
23956
24223
|
}
|
|
23957
24224
|
|
|
23958
24225
|
// src/history/plans.ts
|
|
23959
|
-
import { createHash as
|
|
24226
|
+
import { createHash as createHash23, randomUUID as randomUUID16 } from "node:crypto";
|
|
23960
24227
|
function assertPlanContent(plan, reference, secrets) {
|
|
23961
24228
|
text(plan, 32768);
|
|
23962
24229
|
const ref = decodeContentRef(reference);
|
|
23963
|
-
if (ref.field !== "plan" || ref.bytes !== Buffer.byteLength(plan) || ref.sha256 !==
|
|
24230
|
+
if (ref.field !== "plan" || ref.bytes !== Buffer.byteLength(plan) || ref.sha256 !== createHash23("sha256").update(plan).digest("hex") || sanitizeText(plan, secrets) !== plan)
|
|
23964
24231
|
throw new ContractError("invalid");
|
|
23965
24232
|
}
|
|
23966
24233
|
function planRecording(plan, graph, operationId, epoch) {
|
|
@@ -24020,7 +24287,7 @@ import {
|
|
|
24020
24287
|
openSync as openSync9,
|
|
24021
24288
|
realpathSync as realpathSync10
|
|
24022
24289
|
} from "node:fs";
|
|
24023
|
-
import { dirname as dirname19, isAbsolute as
|
|
24290
|
+
import { dirname as dirname19, isAbsolute as isAbsolute13, join as join32, relative as relative6, sep as sep6 } from "node:path";
|
|
24024
24291
|
function summary(text2, maximum, runId) {
|
|
24025
24292
|
const label = `[Cadence summary${runId ? `; run ${runId}` : ""}; retained history is separate]
|
|
24026
24293
|
`;
|
|
@@ -24070,7 +24337,7 @@ function publicationRecord(store, reader, intent, link, run, request3, expected,
|
|
|
24070
24337
|
if (action.kind !== "create" || !request3.cwd || store.list().length >= 1000)
|
|
24071
24338
|
bad11();
|
|
24072
24339
|
const cwd = realpathSync10(request3.cwd), within = relative6(store.root, cwd);
|
|
24073
|
-
if (
|
|
24340
|
+
if (isAbsolute13(within) || within === ".." || within.startsWith(`..${sep6}`))
|
|
24074
24341
|
bad11();
|
|
24075
24342
|
record3 = {
|
|
24076
24343
|
schema: TASK_SCHEMA,
|
|
@@ -25625,7 +25892,7 @@ class HistoryWriter {
|
|
|
25625
25892
|
recordId: randomUUID17(),
|
|
25626
25893
|
version: 1,
|
|
25627
25894
|
bytes: 0,
|
|
25628
|
-
hash:
|
|
25895
|
+
hash: createHash24("sha256"),
|
|
25629
25896
|
parts: 0,
|
|
25630
25897
|
ended: null,
|
|
25631
25898
|
committedSeq: null
|
|
@@ -26003,7 +26270,7 @@ function readOperationStateForPublication(files, operationId) {
|
|
|
26003
26270
|
// src/history/recovery.ts
|
|
26004
26271
|
function digestHistory(files, exclude) {
|
|
26005
26272
|
files.assertFormat();
|
|
26006
|
-
const digest =
|
|
26273
|
+
const digest = createHash25("sha256");
|
|
26007
26274
|
let count2 = 0;
|
|
26008
26275
|
const walk = (path, depth) => {
|
|
26009
26276
|
if (depth > 8 || !files.files.directory(path))
|
|
@@ -26114,13 +26381,13 @@ async function healHistory(lease, log) {
|
|
|
26114
26381
|
}
|
|
26115
26382
|
|
|
26116
26383
|
// src/subagent-process.ts
|
|
26117
|
-
import { spawn as
|
|
26118
|
-
import { createHash as
|
|
26384
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
26385
|
+
import { createHash as createHash27, randomUUID as randomUUID20 } from "node:crypto";
|
|
26119
26386
|
import { join as join35 } from "node:path";
|
|
26120
26387
|
import { StringDecoder } from "node:string_decoder";
|
|
26121
|
-
import { fileURLToPath as
|
|
26388
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
26122
26389
|
// src/worker-capture.mjs
|
|
26123
|
-
import { createHash as
|
|
26390
|
+
import { createHash as createHash26, randomUUID as randomUUID19 } from "node:crypto";
|
|
26124
26391
|
var completeCoverage = () => ({
|
|
26125
26392
|
observed: "complete",
|
|
26126
26393
|
source: "complete",
|
|
@@ -26206,7 +26473,7 @@ class CaptureState {
|
|
|
26206
26473
|
final: null,
|
|
26207
26474
|
stopReason: null,
|
|
26208
26475
|
finalIndices: new Set,
|
|
26209
|
-
finalHash:
|
|
26476
|
+
finalHash: createHash26("sha256"),
|
|
26210
26477
|
finalBytes: 0,
|
|
26211
26478
|
finalIndex: -1
|
|
26212
26479
|
});
|
|
@@ -26233,7 +26500,7 @@ class CaptureState {
|
|
|
26233
26500
|
}
|
|
26234
26501
|
this.details.set(e.detailId, {
|
|
26235
26502
|
descriptor: e.descriptor,
|
|
26236
|
-
hash:
|
|
26503
|
+
hash: createHash26("sha256"),
|
|
26237
26504
|
bytes: 0,
|
|
26238
26505
|
ended: false,
|
|
26239
26506
|
preview: ""
|
|
@@ -26701,7 +26968,7 @@ class WorkerRecording {
|
|
|
26701
26968
|
// src/subagent-process.ts
|
|
26702
26969
|
function terminateWindowsTree(pid, fallback) {
|
|
26703
26970
|
const root = process.env.SystemRoot;
|
|
26704
|
-
const taskkill =
|
|
26971
|
+
const taskkill = spawn5(root ? join35(root, "System32", "taskkill.exe") : "taskkill.exe", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
|
|
26705
26972
|
taskkill.once("error", fallback);
|
|
26706
26973
|
taskkill.once("close", (code2) => {
|
|
26707
26974
|
if (code2 !== 0)
|
|
@@ -26740,7 +27007,7 @@ function runProcess(spec) {
|
|
|
26740
27007
|
if (spec.input !== undefined && Buffer.byteLength(spec.input) > 128 * 1024)
|
|
26741
27008
|
return Promise.resolve(early("failed", "Worker input exceeds bound"));
|
|
26742
27009
|
return new Promise((resolve12) => {
|
|
26743
|
-
const child2 =
|
|
27010
|
+
const child2 = spawn5(spec.command, spec.args, {
|
|
26744
27011
|
cwd: spec.cwd,
|
|
26745
27012
|
env: spec.env ?? safeChildEnv(),
|
|
26746
27013
|
detached: process.platform !== "win32",
|
|
@@ -27153,7 +27420,7 @@ function launchEncoded(encoded2, signal, timeoutMs, extra = {}) {
|
|
|
27153
27420
|
throw new Error("network");
|
|
27154
27421
|
return runProcess({
|
|
27155
27422
|
command: process.execPath,
|
|
27156
|
-
args: [
|
|
27423
|
+
args: [fileURLToPath6(new URL("./sdk-worker.mjs", import.meta.url))],
|
|
27157
27424
|
cwd: encoded2.material.cwd,
|
|
27158
27425
|
input: encoded2.input,
|
|
27159
27426
|
env: encoded2.selected.env,
|
|
@@ -27171,7 +27438,7 @@ function launchConversation(prepared, conversation, signal, options) {
|
|
|
27171
27438
|
const imageInput = options.images?.length ? JSON.stringify(options.images) : undefined;
|
|
27172
27439
|
const imageDescriptor = imageInput === undefined ? undefined : {
|
|
27173
27440
|
bytes: Buffer.byteLength(imageInput),
|
|
27174
|
-
sha256:
|
|
27441
|
+
sha256: createHash27("sha256").update(imageInput).digest("hex")
|
|
27175
27442
|
};
|
|
27176
27443
|
return prepared.consume((material) => {
|
|
27177
27444
|
encoded2 = encodeEnvelope({ ...material, model: { ...material.model } }, options.timeoutMs);
|
|
@@ -27464,6 +27731,123 @@ class OwnerModelChoice {
|
|
|
27464
27731
|
|
|
27465
27732
|
// src/service/model-context.ts
|
|
27466
27733
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
27734
|
+
|
|
27735
|
+
// src/service/model-catalog.ts
|
|
27736
|
+
function publicModelIdentifier(value, literals) {
|
|
27737
|
+
return !/[\p{Cc}\p{Cf}\p{Cs}]/u.test(value) && diagnosticText(value, 512, literals) === value && sanitizeText(value, literals) === value;
|
|
27738
|
+
}
|
|
27739
|
+
function exactEnvironment(launch, selected2, snapshot) {
|
|
27740
|
+
const scoped = snapshot.credentials[selected2.selection.provider]?.env;
|
|
27741
|
+
const local = scoped === undefined ? {} : environment(scoped);
|
|
27742
|
+
for (const [name, value] of Object.entries(selected2.env)) {
|
|
27743
|
+
if (local[name])
|
|
27744
|
+
continue;
|
|
27745
|
+
const d = Object.getOwnPropertyDescriptor(process.env, name);
|
|
27746
|
+
if (!d || !("value" in d) || d.value !== value || launch[name] !== value)
|
|
27747
|
+
throw new ContractError("stale");
|
|
27748
|
+
}
|
|
27749
|
+
}
|
|
27750
|
+
function validateCatalogModel(runtime, thinking, input, current2, launch, literals) {
|
|
27751
|
+
if (!runtime || !thinking)
|
|
27752
|
+
throw new ContractError("unavailable");
|
|
27753
|
+
if (runtime.getError() || runtime.getRegisteredNativeProvider(input.provider) || runtime.getRegisteredProviderConfig(input.provider))
|
|
27754
|
+
throw new ContractError("unsupported-context");
|
|
27755
|
+
const model2 = runtime.getModel(input.provider, input.model);
|
|
27756
|
+
if (!model2 || model2.api !== input.api || model2.provider !== input.provider || model2.id !== input.model || !thinking(model2).includes(input.thinking))
|
|
27757
|
+
throw new ContractError("unsupported-context");
|
|
27758
|
+
if (!publicModelIdentifier(input.provider, literals) || !publicModelIdentifier(input.model, literals))
|
|
27759
|
+
throw new ContractError("unsupported-context");
|
|
27760
|
+
const credential2 = current2.credentials[input.provider];
|
|
27761
|
+
const provider = runtime.getProvider(input.provider);
|
|
27762
|
+
if (credential2?.type === "oauth" ? !provider?.auth.oauth : !provider?.auth.apiKey)
|
|
27763
|
+
throw new ContractError("unsupported-context");
|
|
27764
|
+
if (credential2?.type === "api_key" ? !credential2.key : !credential2 && !current2.providers[input.provider]?.apiKey)
|
|
27765
|
+
throw new ContractError("auth-unavailable");
|
|
27766
|
+
const selected2 = {
|
|
27767
|
+
model: model2,
|
|
27768
|
+
sourceIdentity: sourceIdentity(current2, input.provider),
|
|
27769
|
+
credentialIdentity: stablePrivate(credential2 ?? null),
|
|
27770
|
+
env: selectedEnvironment(current2, input.provider, input.model, launch)
|
|
27771
|
+
};
|
|
27772
|
+
exactEnvironment(launch, { ...selected2, selection: input }, current2);
|
|
27773
|
+
return selected2;
|
|
27774
|
+
}
|
|
27775
|
+
function projectModelCatalog(runtime, supportedThinking, current2, literals, validate) {
|
|
27776
|
+
const providers = [
|
|
27777
|
+
...new Set([
|
|
27778
|
+
...Object.keys(current2.credentials),
|
|
27779
|
+
...Object.keys(current2.providers)
|
|
27780
|
+
])
|
|
27781
|
+
].sort();
|
|
27782
|
+
let count2 = 0;
|
|
27783
|
+
for (const provider of providers) {
|
|
27784
|
+
if (runtime.getRegisteredNativeProvider(provider) || runtime.getRegisteredProviderConfig(provider))
|
|
27785
|
+
throw new ContractError("unsupported-context");
|
|
27786
|
+
count2 += runtime.getModels(provider).length;
|
|
27787
|
+
if (count2 > LIMITS.maxPageEntries)
|
|
27788
|
+
return { status: "capacity", entries: [], withheld: 0 };
|
|
27789
|
+
}
|
|
27790
|
+
const entries2 = [];
|
|
27791
|
+
let withheld = 0;
|
|
27792
|
+
for (const provider of providers) {
|
|
27793
|
+
const models2 = runtime.getModels(provider);
|
|
27794
|
+
if (entries2.length + withheld + models2.length > LIMITS.maxPageEntries)
|
|
27795
|
+
throw new ContractError("capacity");
|
|
27796
|
+
for (const model2 of models2) {
|
|
27797
|
+
if (model2.provider !== provider)
|
|
27798
|
+
throw new ContractError("unsupported-context");
|
|
27799
|
+
if (!publicModelIdentifier(provider, literals) || !publicModelIdentifier(model2.id, literals)) {
|
|
27800
|
+
withheld++;
|
|
27801
|
+
continue;
|
|
27802
|
+
}
|
|
27803
|
+
const api = modelApis.find((api2) => api2 === model2.api) ?? null;
|
|
27804
|
+
const levels2 = supportedThinking(model2);
|
|
27805
|
+
if (levels2.length > 7)
|
|
27806
|
+
throw new ContractError("unsupported-context");
|
|
27807
|
+
let eligibility = "candidate";
|
|
27808
|
+
const thinking = levels2.map((level) => ({
|
|
27809
|
+
level,
|
|
27810
|
+
selectable: api !== null && thinkingLevels.some((t) => t === level)
|
|
27811
|
+
}));
|
|
27812
|
+
const supported = thinking.find((t) => t.selectable);
|
|
27813
|
+
if (!api || !supported)
|
|
27814
|
+
eligibility = "unsupported";
|
|
27815
|
+
else {
|
|
27816
|
+
try {
|
|
27817
|
+
validate(decodeModelSelector({
|
|
27818
|
+
provider,
|
|
27819
|
+
model: model2.id,
|
|
27820
|
+
api,
|
|
27821
|
+
thinking: supported.level
|
|
27822
|
+
}), current2);
|
|
27823
|
+
} catch (error) {
|
|
27824
|
+
if (!(error instanceof ContractError))
|
|
27825
|
+
throw error;
|
|
27826
|
+
if (error.code === "auth-unavailable")
|
|
27827
|
+
eligibility = "auth-unavailable";
|
|
27828
|
+
else if (error.code === "unsupported-context")
|
|
27829
|
+
eligibility = "unsupported";
|
|
27830
|
+
else
|
|
27831
|
+
throw error;
|
|
27832
|
+
}
|
|
27833
|
+
}
|
|
27834
|
+
entries2.push(decodeModelCandidate({
|
|
27835
|
+
provider,
|
|
27836
|
+
model: model2.id,
|
|
27837
|
+
api,
|
|
27838
|
+
thinking: thinking.map((t) => ({
|
|
27839
|
+
...t,
|
|
27840
|
+
selectable: t.selectable && eligibility === "candidate"
|
|
27841
|
+
})),
|
|
27842
|
+
images: model2.input.includes("image"),
|
|
27843
|
+
eligibility
|
|
27844
|
+
}));
|
|
27845
|
+
}
|
|
27846
|
+
}
|
|
27847
|
+
return { status: "complete", entries: entries2, withheld };
|
|
27848
|
+
}
|
|
27849
|
+
|
|
27850
|
+
// src/service/model-context.ts
|
|
27467
27851
|
function committed(result) {
|
|
27468
27852
|
if (result.status !== "committed")
|
|
27469
27853
|
throw new ContractError("recording-exhausted");
|
|
@@ -27481,17 +27865,6 @@ function directAuthRoute(launch, scoped) {
|
|
|
27481
27865
|
throw new ContractError("unsupported-context");
|
|
27482
27866
|
}
|
|
27483
27867
|
}
|
|
27484
|
-
function exactEnvironment(launch, selected2, snapshot) {
|
|
27485
|
-
const scoped = snapshot.credentials[selected2.selection.provider]?.env;
|
|
27486
|
-
const local = scoped === undefined ? {} : environment(scoped);
|
|
27487
|
-
for (const [name, value] of Object.entries(selected2.env)) {
|
|
27488
|
-
if (local[name])
|
|
27489
|
-
continue;
|
|
27490
|
-
const d = Object.getOwnPropertyDescriptor(process.env, name);
|
|
27491
|
-
if (!d || !("value" in d) || d.value !== value || launch[name] !== value)
|
|
27492
|
-
throw new ContractError("stale");
|
|
27493
|
-
}
|
|
27494
|
-
}
|
|
27495
27868
|
function authProjection(value) {
|
|
27496
27869
|
if (!value)
|
|
27497
27870
|
throw new ContractError("auth-unavailable");
|
|
@@ -27598,82 +27971,11 @@ class OwnerModelContext {
|
|
|
27598
27971
|
const runtime = this.#runtime;
|
|
27599
27972
|
if (!runtime || !this.#thinking)
|
|
27600
27973
|
throw new ContractError("unavailable");
|
|
27601
|
-
const
|
|
27602
|
-
...new Set([
|
|
27603
|
-
...Object.keys(current2.credentials),
|
|
27604
|
-
...Object.keys(current2.providers)
|
|
27605
|
-
])
|
|
27606
|
-
].sort();
|
|
27607
|
-
let count2 = 0;
|
|
27608
|
-
for (const provider of providers) {
|
|
27609
|
-
if (runtime.getRegisteredNativeProvider(provider) || runtime.getRegisteredProviderConfig(provider))
|
|
27610
|
-
throw new ContractError("unsupported-context");
|
|
27611
|
-
count2 += runtime.getModels(provider).length;
|
|
27612
|
-
if (count2 > LIMITS.maxPageEntries)
|
|
27613
|
-
return { status: "capacity", entries: [], withheld: 0 };
|
|
27614
|
-
}
|
|
27615
|
-
const literals = this.catalogLiterals(current2);
|
|
27616
|
-
const entries2 = [];
|
|
27617
|
-
let withheld = 0;
|
|
27618
|
-
for (const provider of providers) {
|
|
27619
|
-
const models2 = runtime.getModels(provider);
|
|
27620
|
-
if (entries2.length + withheld + models2.length > LIMITS.maxPageEntries)
|
|
27621
|
-
throw new ContractError("capacity");
|
|
27622
|
-
for (const model2 of models2) {
|
|
27623
|
-
if (model2.provider !== provider)
|
|
27624
|
-
throw new ContractError("unsupported-context");
|
|
27625
|
-
if (!this.isPublicIdentifier(provider, literals) || !this.isPublicIdentifier(model2.id, literals)) {
|
|
27626
|
-
withheld++;
|
|
27627
|
-
continue;
|
|
27628
|
-
}
|
|
27629
|
-
const api = modelApis.find((api2) => api2 === model2.api) ?? null;
|
|
27630
|
-
const levels2 = this.#thinking(model2);
|
|
27631
|
-
if (levels2.length > 7)
|
|
27632
|
-
throw new ContractError("unsupported-context");
|
|
27633
|
-
let eligibility = "candidate";
|
|
27634
|
-
const thinking = levels2.map((level) => ({
|
|
27635
|
-
level,
|
|
27636
|
-
selectable: api !== null && thinkingLevels.some((t) => t === level)
|
|
27637
|
-
}));
|
|
27638
|
-
const supported = thinking.find((t) => t.selectable);
|
|
27639
|
-
if (!api || !supported)
|
|
27640
|
-
eligibility = "unsupported";
|
|
27641
|
-
else {
|
|
27642
|
-
try {
|
|
27643
|
-
this.validateModel(decodeModelSelector({
|
|
27644
|
-
provider,
|
|
27645
|
-
model: model2.id,
|
|
27646
|
-
api,
|
|
27647
|
-
thinking: supported.level
|
|
27648
|
-
}), current2);
|
|
27649
|
-
} catch (error) {
|
|
27650
|
-
if (!(error instanceof ContractError))
|
|
27651
|
-
throw error;
|
|
27652
|
-
if (error.code === "auth-unavailable")
|
|
27653
|
-
eligibility = "auth-unavailable";
|
|
27654
|
-
else if (error.code === "unsupported-context")
|
|
27655
|
-
eligibility = "unsupported";
|
|
27656
|
-
else
|
|
27657
|
-
throw error;
|
|
27658
|
-
}
|
|
27659
|
-
}
|
|
27660
|
-
entries2.push(decodeModelCandidate({
|
|
27661
|
-
provider,
|
|
27662
|
-
model: model2.id,
|
|
27663
|
-
api,
|
|
27664
|
-
thinking: thinking.map((t) => ({
|
|
27665
|
-
...t,
|
|
27666
|
-
selectable: t.selectable && eligibility === "candidate"
|
|
27667
|
-
})),
|
|
27668
|
-
images: model2.input.includes("image"),
|
|
27669
|
-
eligibility
|
|
27670
|
-
}));
|
|
27671
|
-
}
|
|
27672
|
-
}
|
|
27974
|
+
const catalog = projectModelCatalog(runtime, this.#thinking, current2, this.catalogLiterals(current2), (input, snapshot) => this.validateModel(input, snapshot));
|
|
27673
27975
|
const after = this.catalogSource();
|
|
27674
27976
|
if (after.auth.identity !== current2.auth.identity || after.auth.stamp !== current2.auth.stamp)
|
|
27675
27977
|
throw new ContractError("stale");
|
|
27676
|
-
return
|
|
27978
|
+
return catalog;
|
|
27677
27979
|
} catch (error) {
|
|
27678
27980
|
throw new ContractError(error instanceof ContractError ? error.code : "corrupt-selected");
|
|
27679
27981
|
}
|
|
@@ -27692,13 +27994,6 @@ class OwnerModelContext {
|
|
|
27692
27994
|
catalogLiterals(snapshot) {
|
|
27693
27995
|
return snapshotLiterals(snapshot, this.#launch, this.#options.network?.literals ?? []);
|
|
27694
27996
|
}
|
|
27695
|
-
isPublicIdentifier(value, literals) {
|
|
27696
|
-
return !/[\p{Cc}\p{Cf}\p{Cs}]/u.test(value) && diagnosticText(value, 512, literals) === value && sanitizeText(value, literals) === value;
|
|
27697
|
-
}
|
|
27698
|
-
publicIdentifier(value, literals) {
|
|
27699
|
-
if (!this.isPublicIdentifier(value, literals))
|
|
27700
|
-
throw new ContractError("unsupported-context");
|
|
27701
|
-
}
|
|
27702
27997
|
replaceSelection(input, beforeInstall) {
|
|
27703
27998
|
this.#options.owner.assertQuiescent();
|
|
27704
27999
|
if (this.#pending || this.#loading)
|
|
@@ -27835,31 +28130,9 @@ class OwnerModelContext {
|
|
|
27835
28130
|
return { ...selection };
|
|
27836
28131
|
}
|
|
27837
28132
|
validateModel(input, current2) {
|
|
27838
|
-
|
|
27839
|
-
if (!runtime || !this.#thinking)
|
|
28133
|
+
if (!this.#runtime || !this.#thinking)
|
|
27840
28134
|
throw new ContractError("unavailable");
|
|
27841
|
-
|
|
27842
|
-
throw new ContractError("unsupported-context");
|
|
27843
|
-
const model2 = runtime.getModel(input.provider, input.model);
|
|
27844
|
-
if (!model2 || model2.api !== input.api || model2.provider !== input.provider || model2.id !== input.model || !this.#thinking(model2).includes(input.thinking))
|
|
27845
|
-
throw new ContractError("unsupported-context");
|
|
27846
|
-
const literals = this.catalogLiterals(current2);
|
|
27847
|
-
this.publicIdentifier(input.provider, literals);
|
|
27848
|
-
this.publicIdentifier(input.model, literals);
|
|
27849
|
-
const credential2 = current2.credentials[input.provider];
|
|
27850
|
-
const provider = runtime.getProvider(input.provider);
|
|
27851
|
-
if (credential2?.type === "oauth" ? !provider?.auth.oauth : !provider?.auth.apiKey)
|
|
27852
|
-
throw new ContractError("unsupported-context");
|
|
27853
|
-
if (credential2?.type === "api_key" ? !credential2.key : !credential2 && !current2.providers[input.provider]?.apiKey)
|
|
27854
|
-
throw new ContractError("auth-unavailable");
|
|
27855
|
-
const selected2 = {
|
|
27856
|
-
model: model2,
|
|
27857
|
-
sourceIdentity: sourceIdentity(current2, input.provider),
|
|
27858
|
-
credentialIdentity: stablePrivate(credential2 ?? null),
|
|
27859
|
-
env: selectedEnvironment(current2, input.provider, input.model, this.#launch)
|
|
27860
|
-
};
|
|
27861
|
-
exactEnvironment(this.#launch, { ...selected2, selection: input }, current2);
|
|
27862
|
-
return selected2;
|
|
28135
|
+
return validateCatalogModel(this.#runtime, this.#thinking, input, current2, this.#launch, this.catalogLiterals(current2));
|
|
27863
28136
|
}
|
|
27864
28137
|
fresh(selected2, resolvingOAuth = false) {
|
|
27865
28138
|
this.alive();
|
|
@@ -29450,18 +29723,18 @@ CONVERSATION CONTEXT (data): cwd ${live2.execution.cwd}; checkout root ${live2.e
|
|
|
29450
29723
|
import { randomUUID as randomUUID26 } from "node:crypto";
|
|
29451
29724
|
import { opendirSync as opendirSync14, realpathSync as realpathSync12, statfsSync as statfsSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
29452
29725
|
import { basename as basename5, dirname as dirname24, join as join41, resolve as resolve14 } from "node:path";
|
|
29453
|
-
import { fileURLToPath as
|
|
29726
|
+
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
29454
29727
|
|
|
29455
29728
|
// src/task-diff.ts
|
|
29456
29729
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
29457
|
-
import { createHash as
|
|
29730
|
+
import { createHash as createHash28 } from "node:crypto";
|
|
29458
29731
|
import { lstatSync as lstatSync20, readdirSync as readdirSync4, readlinkSync } from "node:fs";
|
|
29459
29732
|
import { join as join38, relative as relative8 } from "node:path";
|
|
29460
29733
|
var admin = (path) => path === ".cadence/assistant/tasks" || path.startsWith(".cadence/assistant/tasks/");
|
|
29461
29734
|
var GIT_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
29462
29735
|
function captureChanges(root, outputBytes = GIT_OUTPUT_BYTES) {
|
|
29463
29736
|
const deadline = Date.now() + 3000;
|
|
29464
|
-
const hash3 =
|
|
29737
|
+
const hash3 = createHash28("sha256");
|
|
29465
29738
|
const parts = [];
|
|
29466
29739
|
let complete = true;
|
|
29467
29740
|
const limits = [];
|
|
@@ -29519,7 +29792,7 @@ function captureChanges(root, outputBytes = GIT_OUTPUT_BYTES) {
|
|
|
29519
29792
|
fileBytes += data2.length;
|
|
29520
29793
|
add(name, data2);
|
|
29521
29794
|
const binary = data2.includes(0);
|
|
29522
|
-
parts.push(`${name} (${binary ? "binary" : "text"}, ${data2.length} bytes, sha256 ${
|
|
29795
|
+
parts.push(`${name} (${binary ? "binary" : "text"}, ${data2.length} bytes, sha256 ${createHash28("sha256").update(data2).digest("hex")})`);
|
|
29523
29796
|
} catch {
|
|
29524
29797
|
complete = false;
|
|
29525
29798
|
limits.push(`Unreadable/changing: ${name}`);
|
|
@@ -29675,13 +29948,13 @@ ${data2.toString("utf8")}`);
|
|
|
29675
29948
|
}
|
|
29676
29949
|
|
|
29677
29950
|
// src/worker-workspace.mjs
|
|
29678
|
-
import { isAbsolute as
|
|
29951
|
+
import { isAbsolute as isAbsolute14, relative as relative9, resolve as resolve12, sep as sep7 } from "node:path";
|
|
29679
29952
|
function withinRoot(root, path) {
|
|
29680
29953
|
const part = relative9(root, path);
|
|
29681
|
-
return part === "" || !
|
|
29954
|
+
return part === "" || !isAbsolute14(part) && part !== ".." && !part.startsWith(`..${sep7}`);
|
|
29682
29955
|
}
|
|
29683
29956
|
var absolute2 = (value) => {
|
|
29684
|
-
if (typeof value !== "string" || !
|
|
29957
|
+
if (typeof value !== "string" || !isAbsolute14(value) || value.includes("\x00"))
|
|
29685
29958
|
throw new Error("Invalid execution directory");
|
|
29686
29959
|
return resolve12(value);
|
|
29687
29960
|
};
|
|
@@ -29696,7 +29969,7 @@ function executionDirectory(execution, tree) {
|
|
|
29696
29969
|
|
|
29697
29970
|
// src/service/project-knowledge.ts
|
|
29698
29971
|
import { isUtf8 } from "node:buffer";
|
|
29699
|
-
import { createHash as
|
|
29972
|
+
import { createHash as createHash30 } from "node:crypto";
|
|
29700
29973
|
import {
|
|
29701
29974
|
closeSync as closeSync11,
|
|
29702
29975
|
constants as constants10,
|
|
@@ -29709,8 +29982,8 @@ import {
|
|
|
29709
29982
|
import { dirname as dirname22, posix } from "node:path";
|
|
29710
29983
|
|
|
29711
29984
|
// src/service/workflow-git.ts
|
|
29712
|
-
import { spawn as
|
|
29713
|
-
import { createHash as
|
|
29985
|
+
import { spawn as spawn6, spawnSync as spawnSync6 } from "node:child_process";
|
|
29986
|
+
import { createHash as createHash29 } from "node:crypto";
|
|
29714
29987
|
import {
|
|
29715
29988
|
closeSync as closeSync10,
|
|
29716
29989
|
constants as constants9,
|
|
@@ -29724,7 +29997,7 @@ import {
|
|
|
29724
29997
|
realpathSync as realpathSync11
|
|
29725
29998
|
} from "node:fs";
|
|
29726
29999
|
import { lstat, open as open2, readdir, readlink } from "node:fs/promises";
|
|
29727
|
-
import { dirname as dirname21, isAbsolute as
|
|
30000
|
+
import { dirname as dirname21, isAbsolute as isAbsolute15, join as join39, relative as relative10, resolve as resolve13, sep as sep8 } from "node:path";
|
|
29728
30001
|
var NAMES_BYTES = 64 * 1024 * 1024;
|
|
29729
30002
|
var SYNC_MS = 30000;
|
|
29730
30003
|
var READ_MS = 120000;
|
|
@@ -29766,7 +30039,7 @@ function gitAnswer(cwd, args) {
|
|
|
29766
30039
|
}
|
|
29767
30040
|
function gitRun(cwd, args, timeoutMs = READ_MS) {
|
|
29768
30041
|
return new Promise((done, fail3) => {
|
|
29769
|
-
const child2 =
|
|
30042
|
+
const child2 = spawn6("git", gitArguments(args), {
|
|
29770
30043
|
cwd,
|
|
29771
30044
|
env: gitEnvironment(),
|
|
29772
30045
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -29809,7 +30082,7 @@ async function gitHead(cwd) {
|
|
|
29809
30082
|
}
|
|
29810
30083
|
function contains2(root, path) {
|
|
29811
30084
|
const within = relative10(root, path);
|
|
29812
|
-
return !within || !within.startsWith(`..${sep8}`) && within !== ".." && !
|
|
30085
|
+
return !within || !within.startsWith(`..${sep8}`) && within !== ".." && !isAbsolute15(within);
|
|
29813
30086
|
}
|
|
29814
30087
|
function nested(a, b) {
|
|
29815
30088
|
return contains2(a, b) || contains2(b, a);
|
|
@@ -29872,7 +30145,7 @@ function fileIdentity(p, st, hashBytes) {
|
|
|
29872
30145
|
try {
|
|
29873
30146
|
if (!fstatSync7(fd).isFile())
|
|
29874
30147
|
throw new ContractError("stale");
|
|
29875
|
-
const digest =
|
|
30148
|
+
const digest = createHash29("sha256"), buffer = Buffer.alloc(CHUNK);
|
|
29876
30149
|
for (let n = readSync6(fd, buffer);n > 0; n = readSync6(fd, buffer))
|
|
29877
30150
|
digest.update(buffer.subarray(0, n));
|
|
29878
30151
|
return `sha256:${digest.digest("hex")}`;
|
|
@@ -29899,7 +30172,7 @@ async function fileIdentityAsync(p, st, hashBytes, signal) {
|
|
|
29899
30172
|
const same2 = (a, b) => a.isFile() && b.isFile() && a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.ctimeMs === b.ctimeMs;
|
|
29900
30173
|
if (!same2(st, before))
|
|
29901
30174
|
throw new ContractError("stale");
|
|
29902
|
-
const digest =
|
|
30175
|
+
const digest = createHash29("sha256"), buffer = Buffer.alloc(CHUNK);
|
|
29903
30176
|
let remaining = before.size;
|
|
29904
30177
|
while (remaining > 0) {
|
|
29905
30178
|
if (signal?.aborted)
|
|
@@ -30261,7 +30534,7 @@ var KNOWLEDGE_LIMITS = {
|
|
|
30261
30534
|
depth: 3
|
|
30262
30535
|
};
|
|
30263
30536
|
var roots = ["engineering", "docs", ".trellis/spec", ".cadence/knowledge"];
|
|
30264
|
-
var digest = (s) =>
|
|
30537
|
+
var digest = (s) => createHash30("sha256").update(s).digest("hex");
|
|
30265
30538
|
var markdown2 = (p) => /\.md$/iu.test(p) && !/^(?:\.cadence\/assistant|\.trellis\/(?:workspace|tasks))(?:\/|$)/u.test(p) && !p.split("/").some((part) => part === ".." || part === ".git" || part === "node_modules" || part.startsWith(".env") || part.startsWith(".") && part !== ".cadence" && part !== ".trellis");
|
|
30266
30539
|
function read2(root, path) {
|
|
30267
30540
|
if (!markdown2(path))
|
|
@@ -30446,7 +30719,7 @@ Read existing documentation first. Update the existing topic owner instead of du
|
|
|
30446
30719
|
}
|
|
30447
30720
|
|
|
30448
30721
|
// src/service/workflow-controller.ts
|
|
30449
|
-
import { createHash as
|
|
30722
|
+
import { createHash as createHash31 } from "node:crypto";
|
|
30450
30723
|
var RECOVERY_BYTES = 32768;
|
|
30451
30724
|
|
|
30452
30725
|
class AttemptFailure extends Error {
|
|
@@ -30529,7 +30802,7 @@ class DeliveryController {
|
|
|
30529
30802
|
if (decision.action === "blocked")
|
|
30530
30803
|
throw new Error(`Delivery blocked: ${decision.cause}
|
|
30531
30804
|
${decision.strategy}`);
|
|
30532
|
-
const fingerprint2 =
|
|
30805
|
+
const fingerprint2 = createHash31("sha256").update(canonicalJson({
|
|
30533
30806
|
stage,
|
|
30534
30807
|
observation,
|
|
30535
30808
|
failure: error.message.replace(/[0-9a-f]{8}-[0-9a-f-]{27,}/gu, "<step>"),
|
|
@@ -31308,9 +31581,9 @@ function workflowResultDetail(value, secrets) {
|
|
|
31308
31581
|
|
|
31309
31582
|
// src/service/workflows.ts
|
|
31310
31583
|
var OWNER_RUNTIME = Object.freeze({
|
|
31311
|
-
version: "2.0.
|
|
31312
|
-
build: "
|
|
31313
|
-
entry:
|
|
31584
|
+
version: "2.0.45",
|
|
31585
|
+
build: "3602a85c51a63f2061163b51d5d50e3dcbe9016c9e22d1353554356f0d9f7ddc",
|
|
31586
|
+
entry: fileURLToPath7(import.meta.url),
|
|
31314
31587
|
pid: process.pid,
|
|
31315
31588
|
node: process.versions.node,
|
|
31316
31589
|
platform: process.platform,
|
|
@@ -33408,9 +33681,9 @@ var processLifetime = {
|
|
|
33408
33681
|
const restarts = process.uptime() > 600 ? 0 : previous;
|
|
33409
33682
|
if (!Number.isSafeInteger(restarts) || restarts >= SELF_RESTARTS)
|
|
33410
33683
|
return;
|
|
33411
|
-
const child2 =
|
|
33684
|
+
const child2 = spawn7(process.execPath, [
|
|
33412
33685
|
...process.execArgv,
|
|
33413
|
-
|
|
33686
|
+
fileURLToPath8(new URL("./service-host.mjs", import.meta.url))
|
|
33414
33687
|
], {
|
|
33415
33688
|
detached: true,
|
|
33416
33689
|
stdio: ["pipe", "ignore", "ignore"],
|
|
@@ -33429,7 +33702,7 @@ var processLifetime = {
|
|
|
33429
33702
|
}
|
|
33430
33703
|
};
|
|
33431
33704
|
async function createServiceHost(value, sourceBuild, lifetime) {
|
|
33432
|
-
const embedded = "
|
|
33705
|
+
const embedded = "ee8ae17515fd8baf0aba38eb6a78a27e8c574cda265ddc17884c0741a6fb56b1";
|
|
33433
33706
|
if (embedded && sourceBuild)
|
|
33434
33707
|
throw new ContractError("unsupported-context");
|
|
33435
33708
|
const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);
|