@abelxiaoxing/cadence 2.1.5 → 2.1.7
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 +23 -4
- package/docs/service-management.md +2 -1
- package/package.json +1 -1
- package/src/agent-panel-cadence.ts +0 -2
- package/src/cadence-mode.ts +2 -15
- package/src/history-shell.ts +0 -1
- package/src/native-build.ts +1 -1
- package/src/native-client.ts +2 -9
- package/src/service/contracts/build.ts +1 -17
- package/src/service/contracts/workbench.ts +55 -0
- package/src/service/contracts/workflow.ts +6 -0
- package/src/service-host.mjs +185 -117
- package/src/service-http-client.ts +38 -11
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +28 -28
- package/web/dist/manifest.json +7 -7
package/src/service-host.mjs
CHANGED
|
@@ -2244,18 +2244,6 @@ function decodeBrowserBuild(value) {
|
|
|
2244
2244
|
buildId: decodeHash(o.buildId)
|
|
2245
2245
|
};
|
|
2246
2246
|
}
|
|
2247
|
-
function decodeClientBuild(value) {
|
|
2248
|
-
const kind = oneOf(Object.getOwnPropertyDescriptor(value ?? {}, "kind")?.value, ["native", "browser"]);
|
|
2249
|
-
const o = closed(value, kind === "native" ? ["kind", "contractHash"] : ["kind", "contractHash", "sourceHash", "buildId"]);
|
|
2250
|
-
return kind === "native" ? { kind, contractHash: decodeHash(o.contractHash) } : {
|
|
2251
|
-
kind,
|
|
2252
|
-
...decodeBrowserBuild({
|
|
2253
|
-
contractHash: o.contractHash,
|
|
2254
|
-
sourceHash: o.sourceHash,
|
|
2255
|
-
buildId: o.buildId
|
|
2256
|
-
})
|
|
2257
|
-
};
|
|
2258
|
-
}
|
|
2259
2247
|
function decodeServiceBuild(value) {
|
|
2260
2248
|
const o = closed(value, ["contractHash", "assets"]);
|
|
2261
2249
|
return {
|
|
@@ -2263,9 +2251,6 @@ function decodeServiceBuild(value) {
|
|
|
2263
2251
|
assets: decodeBrowserBuild(o.assets)
|
|
2264
2252
|
};
|
|
2265
2253
|
}
|
|
2266
|
-
function compatibleBuild(server, client, safety = false) {
|
|
2267
|
-
return !!server && !!client && client.contractHash === server.contractHash && (safety || server.assets.contractHash === server.contractHash && (client.kind === "native" || client.buildId === server.assets.buildId && client.sourceHash === server.assets.sourceHash));
|
|
2268
|
-
}
|
|
2269
2254
|
// src/service/contracts/history.ts
|
|
2270
2255
|
function decodeReceipt(v) {
|
|
2271
2256
|
canonicalJson(v);
|
|
@@ -5895,9 +5880,11 @@ function decodeWorkflowProposal(v) {
|
|
|
5895
5880
|
"cwd",
|
|
5896
5881
|
...Object.hasOwn(v ?? {}, "checkoutRoot") ? ["checkoutRoot"] : [],
|
|
5897
5882
|
...Object.hasOwn(v ?? {}, "delivery") ? ["delivery"] : [],
|
|
5883
|
+
...Object.hasOwn(v ?? {}, "revalidatedFrom") ? ["revalidatedFrom"] : [],
|
|
5898
5884
|
...modern ? ["display"] : []
|
|
5899
5885
|
]);
|
|
5900
5886
|
return {
|
|
5887
|
+
...o.revalidatedFrom === undefined ? {} : { revalidatedFrom: decodeId(o.revalidatedFrom) },
|
|
5901
5888
|
...o.delivery === undefined ? {} : { delivery: decodeDeliveryBinding(o.delivery) },
|
|
5902
5889
|
id: decodeId(o.id),
|
|
5903
5890
|
epoch: decodeId(o.epoch),
|
|
@@ -6608,6 +6595,36 @@ function decodeWorkbenchCommand(v) {
|
|
|
6608
6595
|
intent: oneOf(o2.intent, ["message", "enter", "exit"])
|
|
6609
6596
|
};
|
|
6610
6597
|
}
|
|
6598
|
+
if (kind === "cadence-revalidate") {
|
|
6599
|
+
const o2 = closed(v, [
|
|
6600
|
+
"kind",
|
|
6601
|
+
"commandId",
|
|
6602
|
+
"conversationId",
|
|
6603
|
+
"revision",
|
|
6604
|
+
"proposalId",
|
|
6605
|
+
"digest",
|
|
6606
|
+
"head",
|
|
6607
|
+
"context",
|
|
6608
|
+
"expected",
|
|
6609
|
+
"model"
|
|
6610
|
+
]);
|
|
6611
|
+
const conversationId = decodeSessionId(o2.conversationId);
|
|
6612
|
+
const context = decodeConversationContext(o2.context);
|
|
6613
|
+
if (context.id !== conversationId)
|
|
6614
|
+
throw new ContractError("invalid");
|
|
6615
|
+
return {
|
|
6616
|
+
kind,
|
|
6617
|
+
commandId: decodeId(o2.commandId),
|
|
6618
|
+
conversationId,
|
|
6619
|
+
revision: integer(o2.revision, 0),
|
|
6620
|
+
proposalId: decodeId(o2.proposalId),
|
|
6621
|
+
digest: decodeHash(o2.digest),
|
|
6622
|
+
head: nullable(o2.head, decodeEntryId),
|
|
6623
|
+
context,
|
|
6624
|
+
expected: decodeChoiceVersion(o2.expected),
|
|
6625
|
+
model: decodeModelSelector(o2.model)
|
|
6626
|
+
};
|
|
6627
|
+
}
|
|
6611
6628
|
if (kind === "cadence-prepare" || kind === "cadence-approve") {
|
|
6612
6629
|
const keys2 = [
|
|
6613
6630
|
"kind",
|
|
@@ -7001,6 +7018,14 @@ function decodeWorkbenchResult(v) {
|
|
|
7001
7018
|
throw new ContractError("invalid");
|
|
7002
7019
|
return { kind: k, runs, links };
|
|
7003
7020
|
}
|
|
7021
|
+
if (k === "cadence-revalidated") {
|
|
7022
|
+
const o2 = closed(v, ["kind", "commandId", "state"]);
|
|
7023
|
+
return {
|
|
7024
|
+
kind: k,
|
|
7025
|
+
commandId: decodeId(o2.commandId),
|
|
7026
|
+
state: decodeCadenceConversation(o2.state)
|
|
7027
|
+
};
|
|
7028
|
+
}
|
|
7004
7029
|
if (k === "cadence-grant") {
|
|
7005
7030
|
const o2 = closed(v, [
|
|
7006
7031
|
"kind",
|
|
@@ -10090,10 +10115,7 @@ class ActivityDiscoveryReader {
|
|
|
10090
10115
|
const summary = decodeOwnerActivity(await o.readOwner(c, signal));
|
|
10091
10116
|
if (signal.aborted)
|
|
10092
10117
|
return;
|
|
10093
|
-
if (summary.epoch !== row.epoch || c.localAccess().epoch !== row.epoch
|
|
10094
|
-
kind: "native",
|
|
10095
|
-
contractHash: o.build.contractHash
|
|
10096
|
-
}))
|
|
10118
|
+
if (summary.epoch !== row.epoch || c.localAccess().epoch !== row.epoch)
|
|
10097
10119
|
throw new Error;
|
|
10098
10120
|
if (summary.activities.some((activity2) => activity2.epoch !== row.epoch || activity2.source === "terminal"))
|
|
10099
10121
|
throw new Error("invalid-attribution");
|
|
@@ -16267,7 +16289,7 @@ Content-Length: 0\r
|
|
|
16267
16289
|
this.attachments.set(attachmentId, attachment);
|
|
16268
16290
|
}
|
|
16269
16291
|
res.setHeader("X-Cadence-Attachment", attachmentId);
|
|
16270
|
-
} else if (route.source === "body")
|
|
16292
|
+
} else if (route.source === "body" && (route.operation !== "detach" || this.attachments.has(attachmentId)))
|
|
16271
16293
|
attachment = this.attachment(caller);
|
|
16272
16294
|
const input = route.source === "body" ? await this.body(req, abort.signal) : route.input === null ? null : parseWireJson(route.input);
|
|
16273
16295
|
if (route.source !== "body" && (req.headers["content-encoding"] !== undefined || req.headers["transfer-encoding"] || req.headers["content-length"] && req.headers["content-length"] !== "0"))
|
|
@@ -16276,26 +16298,14 @@ Content-Length: 0\r
|
|
|
16276
16298
|
this.options.auth.current(caller);
|
|
16277
16299
|
if (abort.signal.aborted || !this.accepting)
|
|
16278
16300
|
unavailable();
|
|
16279
|
-
if (attachment && this.attachment(caller) !== attachment)
|
|
16301
|
+
if (attachment && route.operation !== "detach" && this.attachment(caller) !== attachment)
|
|
16280
16302
|
throw new ContractError("stale");
|
|
16281
16303
|
if (route.operation === "export" || route.operation === "download") {
|
|
16282
16304
|
await this.export(route.operation, input, caller, abort.signal, res, resetIdle);
|
|
16283
16305
|
return;
|
|
16284
16306
|
}
|
|
16285
|
-
const rawBuild = boundary.headers.get("x-cadence-build");
|
|
16286
|
-
const clientBuild = rawBuild === undefined ? null : decodeClientBuild(parseWireJson(rawBuild, 1024));
|
|
16287
|
-
if (caller.authority === "browser" && clientBuild?.kind === "native")
|
|
16288
|
-
throw new ContractError("forbidden");
|
|
16289
|
-
if ([
|
|
16290
|
-
"preflight",
|
|
16291
|
-
"command",
|
|
16292
|
-
"chooseModel",
|
|
16293
|
-
"cancel",
|
|
16294
|
-
"workbenchCommand"
|
|
16295
|
-
].includes(route.operation) && !compatibleBuild(this.options.build, clientBuild, route.operation === "cancel" || route.operation === "workbenchCommand" && decodeWorkbenchCommand(input).kind === "interrupt"))
|
|
16296
|
-
throw new ContractError("unsupported-context");
|
|
16297
16307
|
dispatched = route.operation === "command" || route.operation === "cancel" || route.operation === "chooseModel" || route.operation === "workbenchCommand";
|
|
16298
|
-
const value = await this.dispatch(route.operation, input, caller, abort.signal
|
|
16308
|
+
const value = await this.dispatch(route.operation, input, caller, abort.signal);
|
|
16299
16309
|
this.options.auth.current(caller);
|
|
16300
16310
|
if (abort.signal.aborted)
|
|
16301
16311
|
unavailable();
|
|
@@ -16373,7 +16383,7 @@ Content-Length: 0\r
|
|
|
16373
16383
|
const value = this.options.management.invoke(operation);
|
|
16374
16384
|
send(res, 200, { kind: "ok", value });
|
|
16375
16385
|
}
|
|
16376
|
-
async dispatch(operation, input, caller, signal
|
|
16386
|
+
async dispatch(operation, input, caller, signal) {
|
|
16377
16387
|
const a = this.options.adapters, p = a.projection;
|
|
16378
16388
|
switch (operation) {
|
|
16379
16389
|
case "workbenchRead":
|
|
@@ -16424,7 +16434,8 @@ Content-Length: 0\r
|
|
|
16424
16434
|
value: a.modelChoice.choose(decodeChooseModelRequest(input))
|
|
16425
16435
|
};
|
|
16426
16436
|
case "detach":
|
|
16427
|
-
|
|
16437
|
+
if (this.attachments.has(caller.attachmentId))
|
|
16438
|
+
this.detach(this.attachment(caller));
|
|
16428
16439
|
return { kind: "ok", value: null };
|
|
16429
16440
|
case "preflight":
|
|
16430
16441
|
case "command":
|
|
@@ -16451,7 +16462,7 @@ Content-Length: 0\r
|
|
|
16451
16462
|
authority: caller.authority,
|
|
16452
16463
|
csrf: caller.authority === "browser" ? this.options.auth.csrf : null,
|
|
16453
16464
|
capabilities: {
|
|
16454
|
-
actions: original.capabilities.actions && !!a.workbench
|
|
16465
|
+
actions: original.capabilities.actions && !!a.workbench,
|
|
16455
16466
|
manualChecks: false,
|
|
16456
16467
|
history: original.capabilities.history
|
|
16457
16468
|
}
|
|
@@ -16960,7 +16971,7 @@ async function createGateway(value, hostUrl, source) {
|
|
|
16960
16971
|
const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
|
|
16961
16972
|
const web = loadWebAssets(source?.webDirectory);
|
|
16962
16973
|
const build2 = {
|
|
16963
|
-
contractHash: "
|
|
16974
|
+
contractHash: "6aa819700494584b707a8e1b44428c532cd7ac7b1c8a28126e401b43f527543b",
|
|
16964
16975
|
assets: {
|
|
16965
16976
|
sourceHash: web.manifest.sourceHash,
|
|
16966
16977
|
contractHash: web.manifest.contractHash,
|
|
@@ -17075,7 +17086,6 @@ Content-Length: 0\r
|
|
|
17075
17086
|
stateHome: input.stateHome,
|
|
17076
17087
|
agentDir: input.agentDir,
|
|
17077
17088
|
epoch: auth.epoch,
|
|
17078
|
-
build: build2,
|
|
17079
17089
|
readOwner: (c, signal) => nativeCall(c, "activity", false, undefined, signal),
|
|
17080
17090
|
secrets: () => acquired.access.redactionLiterals()
|
|
17081
17091
|
});
|
|
@@ -17175,11 +17185,6 @@ Content-Length: 0\r
|
|
|
17175
17185
|
requesting = false;
|
|
17176
17186
|
}
|
|
17177
17187
|
}
|
|
17178
|
-
function browserBuild(boundary) {
|
|
17179
|
-
const clientBuild = decodeClientBuild(parseWireJson(boundary.headers.get("x-cadence-build") ?? "null", 1024));
|
|
17180
|
-
if (clientBuild.kind !== "browser" || !compatibleBuild(build2, clientBuild))
|
|
17181
|
-
throw new ContractError("unsupported-context");
|
|
17182
|
-
}
|
|
17183
17188
|
function select(path, epoch) {
|
|
17184
17189
|
assert();
|
|
17185
17190
|
if (epoch !== auth.epoch)
|
|
@@ -17198,7 +17203,7 @@ Content-Length: 0\r
|
|
|
17198
17203
|
store.saveProject(project);
|
|
17199
17204
|
return project;
|
|
17200
17205
|
}
|
|
17201
|
-
async function
|
|
17206
|
+
async function prepareExecution(purpose, projectId, id, epoch, current, location) {
|
|
17202
17207
|
assert();
|
|
17203
17208
|
if (epoch !== auth.epoch)
|
|
17204
17209
|
throw new ContractError("stale");
|
|
@@ -17214,7 +17219,7 @@ Content-Length: 0\r
|
|
|
17214
17219
|
if (observed.store.root !== selected2.path)
|
|
17215
17220
|
throw new ContractError("stale");
|
|
17216
17221
|
const identity = canonicalJson({
|
|
17217
|
-
kind: "prepare-send",
|
|
17222
|
+
kind: purpose === "send" ? "prepare-send" : "prepare-plan",
|
|
17218
17223
|
projectId,
|
|
17219
17224
|
epoch,
|
|
17220
17225
|
...location ? { location } : {}
|
|
@@ -17336,7 +17341,12 @@ Content-Length: 0\r
|
|
|
17336
17341
|
throw new ContractError("stale");
|
|
17337
17342
|
return { project, endpoint: local.endpoint, cookie };
|
|
17338
17343
|
})();
|
|
17339
|
-
|
|
17344
|
+
const pending2 = { epoch: local.epoch, result };
|
|
17345
|
+
bindings.set(id, pending2);
|
|
17346
|
+
result.catch(() => {
|
|
17347
|
+
if (bindings.get(id) === pending2)
|
|
17348
|
+
bindings.delete(id);
|
|
17349
|
+
});
|
|
17340
17350
|
return result;
|
|
17341
17351
|
}
|
|
17342
17352
|
function stop() {
|
|
@@ -17523,9 +17533,9 @@ Content-Length: 0\r
|
|
|
17523
17533
|
if (route2.operation === "session" && !store.associatedProjects().some((p) => p.id === project.id))
|
|
17524
17534
|
throw new ContractError("unavailable");
|
|
17525
17535
|
const attachment = boundary.headers.get("x-cadence-attachment");
|
|
17526
|
-
if (attachment && attachments.get(attachment)?.projectId !== project.id || req.method === "POST" && !attachment)
|
|
17536
|
+
if (attachment && (attachments.has(attachment) ? attachments.get(attachment)?.projectId !== project.id : route2.operation !== "session") || req.method === "POST" && !attachment)
|
|
17527
17537
|
throw new ContractError("stale");
|
|
17528
|
-
if (route2.operation === "session" && !attachment && attachments.size >= 2048)
|
|
17538
|
+
if (route2.operation === "session" && (!attachment || !attachments.has(attachment)) && attachments.size >= 2048)
|
|
17529
17539
|
throw new ContractError("capacity");
|
|
17530
17540
|
if (req.method === "POST" && boundary.headers.get("origin") !== boundary.origin)
|
|
17531
17541
|
throw new ContractError("forbidden");
|
|
@@ -17665,7 +17675,6 @@ Content-Length: 0\r
|
|
|
17665
17675
|
return;
|
|
17666
17676
|
}
|
|
17667
17677
|
if (url.pathname === "/workbench/v1/models" && req.method === "GET") {
|
|
17668
|
-
browserBuild(boundary);
|
|
17669
17678
|
const keys2 = [...url.searchParams.keys()];
|
|
17670
17679
|
if (keys2.length && (keys2.length !== 1 || keys2[0] !== "project"))
|
|
17671
17680
|
throw new ContractError("invalid");
|
|
@@ -17680,7 +17689,6 @@ Content-Length: 0\r
|
|
|
17680
17689
|
return;
|
|
17681
17690
|
}
|
|
17682
17691
|
if (raw === "/workbench/v1/activity" && req.method === "GET") {
|
|
17683
|
-
browserBuild(boundary);
|
|
17684
17692
|
const value2 = await activity2.read();
|
|
17685
17693
|
auth.current(caller);
|
|
17686
17694
|
assert();
|
|
@@ -17717,7 +17725,6 @@ Content-Length: 0\r
|
|
|
17717
17725
|
return;
|
|
17718
17726
|
}
|
|
17719
17727
|
if (raw === "/workbench/v1/service" && req.method === "POST") {
|
|
17720
|
-
browserBuild(boundary);
|
|
17721
17728
|
const value2 = await body(req);
|
|
17722
17729
|
auth.current(caller);
|
|
17723
17730
|
const job2 = await requestJob(value2, () => auth.current(caller));
|
|
@@ -17725,7 +17732,6 @@ Content-Length: 0\r
|
|
|
17725
17732
|
return;
|
|
17726
17733
|
}
|
|
17727
17734
|
if (raw === "/workbench/v1/select" && req.method === "POST") {
|
|
17728
|
-
browserBuild(boundary);
|
|
17729
17735
|
const o = closed(await body(req), ["path", "epoch"]);
|
|
17730
17736
|
const path = text(o.path, 4096, true), epoch = decodeId(o.epoch);
|
|
17731
17737
|
auth.current(caller);
|
|
@@ -17733,8 +17739,8 @@ Content-Length: 0\r
|
|
|
17733
17739
|
reply(res, 200, { kind: "project", project: select(path, epoch) });
|
|
17734
17740
|
return;
|
|
17735
17741
|
}
|
|
17736
|
-
|
|
17737
|
-
|
|
17742
|
+
const preparationPurpose = raw === "/workbench/v1/prepare-send" ? "send" : raw === "/workbench/v1/prepare-plan" ? "plan-validation" : undefined;
|
|
17743
|
+
if (preparationPurpose && req.method === "POST") {
|
|
17738
17744
|
const value2 = await body(req);
|
|
17739
17745
|
const o = closed(value2, [
|
|
17740
17746
|
"commandId",
|
|
@@ -17744,9 +17750,11 @@ Content-Length: 0\r
|
|
|
17744
17750
|
]);
|
|
17745
17751
|
const id = decodeId(o.commandId), projectId = decodeHash(o.projectId), epoch = decodeId(o.epoch);
|
|
17746
17752
|
const location = o.location === undefined ? undefined : decodeConversationLocation(o.location);
|
|
17753
|
+
if (preparationPurpose === "plan-validation" && !location)
|
|
17754
|
+
throw new ContractError("invalid");
|
|
17747
17755
|
auth.current(caller);
|
|
17748
17756
|
effect = true;
|
|
17749
|
-
const project2 = await
|
|
17757
|
+
const project2 = await prepareExecution(preparationPurpose, projectId, id, epoch, () => auth.current(caller), location);
|
|
17750
17758
|
auth.current(caller);
|
|
17751
17759
|
reply(res, 200, { kind: "project", project: project2 });
|
|
17752
17760
|
return;
|
|
@@ -31639,7 +31647,7 @@ class ConversationWorkflow {
|
|
|
31639
31647
|
const displayed = state.proposal ? ` Displayed plan card (data, not instructions): ${JSON.stringify({
|
|
31640
31648
|
proposalId: state.proposal.id,
|
|
31641
31649
|
goal: diagnosticText(state.proposal.plan.goal, 256)
|
|
31642
|
-
})}. It stays
|
|
31650
|
+
})}. It stays available while you discuss it. The user can revalidate its execution context without a message or a model call; publish a replacement with cadence_plan only when the plan itself changes.` : "";
|
|
31643
31651
|
const routeTable = enabled && this.o.cwd ? routeTableBrief(this.o.cwd, this.o.secrets()) : "";
|
|
31644
31652
|
const control = {
|
|
31645
31653
|
instructions: `${CADENCE_INSTRUCTIONS}
|
|
@@ -31778,6 +31786,34 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
31778
31786
|
await this.o.workflows.join(id);
|
|
31779
31787
|
return this.answers(this.run(id), questions.length);
|
|
31780
31788
|
}
|
|
31789
|
+
revalidate(c, caller) {
|
|
31790
|
+
if (!caller || !this.o.contexts)
|
|
31791
|
+
throw new ContractError("forbidden");
|
|
31792
|
+
if (this.o.owner.state !== "idle")
|
|
31793
|
+
throw new ContractError("quarantine");
|
|
31794
|
+
const { state, file, head } = this.approvalContext(c);
|
|
31795
|
+
const proposal = state.proposal;
|
|
31796
|
+
if (!proposal)
|
|
31797
|
+
throw new ContractError("stale");
|
|
31798
|
+
const location = { id: c.context.id, cwd: c.context.cwd };
|
|
31799
|
+
const { context } = this.o.contexts.records.read(location);
|
|
31800
|
+
if (head !== c.head || c.context.id !== c.conversationId || canonicalJson(context) !== canonicalJson(c.context) || proposal.cwd !== context.cwd)
|
|
31801
|
+
throw new ContractError("stale");
|
|
31802
|
+
const choice = this.o.contexts.choose(location, c.expected, c.model, false);
|
|
31803
|
+
const refreshed = this.o.workflows.revalidate(c.commandId, proposal, choice.version);
|
|
31804
|
+
const next = {
|
|
31805
|
+
...state,
|
|
31806
|
+
revision: state.revision + 1,
|
|
31807
|
+
proposal: refreshed
|
|
31808
|
+
};
|
|
31809
|
+
this.save(next, file);
|
|
31810
|
+
for (const [id, grant] of this.grants)
|
|
31811
|
+
if (grant.conversationId === state.id) {
|
|
31812
|
+
this.o.workflows.discardGrant(grant.nativeGrant);
|
|
31813
|
+
this.grants.delete(id);
|
|
31814
|
+
}
|
|
31815
|
+
return { kind: "cadence-revalidated", commandId: c.commandId, state: next };
|
|
31816
|
+
}
|
|
31781
31817
|
approval(c, caller) {
|
|
31782
31818
|
if (!caller)
|
|
31783
31819
|
throw new ContractError("forbidden");
|
|
@@ -31821,12 +31857,16 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
31821
31857
|
commandId: c.commandId
|
|
31822
31858
|
};
|
|
31823
31859
|
}
|
|
31824
|
-
|
|
31860
|
+
approvalContext(c) {
|
|
31825
31861
|
const { state, file } = this.records.usable(c.conversationId);
|
|
31826
31862
|
const latest = this.o.conversations.records.latestRun(c.conversationId);
|
|
31827
31863
|
if (!state.enabled || c.revision !== state.revision || !state.proposal || state.proposal.id !== c.proposalId || state.proposal.digest !== c.digest || !latest || latest.commandId !== state.head || !latest.settled || this.active.has(c.conversationId))
|
|
31828
31864
|
throw new ContractError("stale");
|
|
31829
31865
|
const head = this.o.conversations.records.approvalHead(c.conversationId, latest.commandId);
|
|
31866
|
+
return { state, file, head };
|
|
31867
|
+
}
|
|
31868
|
+
decide(c, caller, evidence, recording) {
|
|
31869
|
+
const { state, file, head } = this.approvalContext(c);
|
|
31830
31870
|
const epoch = this.o.owner.lease.registration.epoch;
|
|
31831
31871
|
if (c.kind === "cadence-prepare") {
|
|
31832
31872
|
for (const [id, g2] of this.grants)
|
|
@@ -31866,23 +31906,25 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
31866
31906
|
this.grants.delete(c.grant);
|
|
31867
31907
|
if (!grant || grant.caller !== canonicalJson(caller) || grant.expiresAt < Date.now() || grant.revision !== c.revision || grant.conversationId !== c.conversationId || grant.proposalId !== c.proposalId || grant.digest !== c.digest || grant.head !== head)
|
|
31868
31908
|
throw new ContractError("expired-grant");
|
|
31869
|
-
|
|
31870
|
-
|
|
31871
|
-
|
|
31872
|
-
|
|
31873
|
-
|
|
31874
|
-
|
|
31875
|
-
|
|
31876
|
-
|
|
31877
|
-
|
|
31878
|
-
|
|
31879
|
-
|
|
31880
|
-
|
|
31881
|
-
|
|
31882
|
-
|
|
31883
|
-
|
|
31884
|
-
|
|
31885
|
-
|
|
31909
|
+
const beforeAdmission = () => {
|
|
31910
|
+
recording();
|
|
31911
|
+
this.grants.delete(c.grant);
|
|
31912
|
+
try {
|
|
31913
|
+
this.o.coordination.files.create(evidence, canonicalJson({
|
|
31914
|
+
commandId: c.commandId,
|
|
31915
|
+
conversationId: state.id,
|
|
31916
|
+
revision: c.revision,
|
|
31917
|
+
proposalId: c.proposalId,
|
|
31918
|
+
digest: c.digest,
|
|
31919
|
+
caller,
|
|
31920
|
+
epoch,
|
|
31921
|
+
at: Date.now()
|
|
31922
|
+
}, EVIDENCE_BYTES), EVIDENCE_BYTES);
|
|
31923
|
+
} catch (e) {
|
|
31924
|
+
this.o.owner.quarantine();
|
|
31925
|
+
throw e;
|
|
31926
|
+
}
|
|
31927
|
+
};
|
|
31886
31928
|
let result;
|
|
31887
31929
|
try {
|
|
31888
31930
|
result = this.o.workflows.command(c.commandId, epoch, {
|
|
@@ -31890,7 +31932,7 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
31890
31932
|
proposalId: c.proposalId,
|
|
31891
31933
|
digest: c.digest,
|
|
31892
31934
|
grant: grant.nativeGrant
|
|
31893
|
-
});
|
|
31935
|
+
}, { beforeAdmission });
|
|
31894
31936
|
} catch (error) {
|
|
31895
31937
|
if (this.o.owner.state !== "idle" || this.exists(c.commandId))
|
|
31896
31938
|
this.attach(state.id, c.commandId, true);
|
|
@@ -34218,8 +34260,8 @@ function workflowResultDetail(value, secrets) {
|
|
|
34218
34260
|
var runtimeSummary = (runtime) => `${describeWorkerRuntime(runtime)}
|
|
34219
34261
|
${RUN_ENVIRONMENT_POLICY}`;
|
|
34220
34262
|
var OWNER_RUNTIME = Object.freeze({
|
|
34221
|
-
version: "2.1.
|
|
34222
|
-
build: "
|
|
34263
|
+
version: "2.1.7",
|
|
34264
|
+
build: "71f1c6144e536050f63d0cbc74944e0cd3acbbe4dc012ad8c99f8ca4a600a5bc",
|
|
34223
34265
|
entry: fileURLToPath7(import.meta.url),
|
|
34224
34266
|
pid: process.pid,
|
|
34225
34267
|
node: process.versions.node,
|
|
@@ -34503,6 +34545,62 @@ class Workflows {
|
|
|
34503
34545
|
throw new ContractError("unavailable");
|
|
34504
34546
|
return decodeWorkflowProposal(parseWireJson(file.bytes.toString("utf8"), RECORD_BYTES3));
|
|
34505
34547
|
}
|
|
34548
|
+
revalidate(commandId, previous, model2) {
|
|
34549
|
+
this.current();
|
|
34550
|
+
const kept = this.proposal(previous.id);
|
|
34551
|
+
if (canonicalJson(kept) !== canonicalJson(previous))
|
|
34552
|
+
throw new ContractError("stale");
|
|
34553
|
+
if (previous.digest !== hash(canonicalJson(previous.delivery ? { plan: previous.plan, delivery: previous.delivery } : previous.plan)) || previous.cwd !== this.contexts.capture(model2).cwd || previous.checkoutRoot !== undefined && previous.checkoutRoot !== this.cwd)
|
|
34554
|
+
throw new ContractError("stale");
|
|
34555
|
+
if (sanitizeData(previous.plan, this.o.secrets()) !== canonicalJson(previous.plan))
|
|
34556
|
+
throw new ContractError("forbidden");
|
|
34557
|
+
return this.publishProposal(commandId, previous.plan, model2, () => {}, previous.id);
|
|
34558
|
+
}
|
|
34559
|
+
publishProposal(commandId, input, model2, effect, revalidatedFrom) {
|
|
34560
|
+
this.floor();
|
|
34561
|
+
const secrets = this.o.secrets();
|
|
34562
|
+
const plan = decodeWorkflowPlan(JSON.parse(sanitizeData(input, secrets)), {
|
|
34563
|
+
strict: true
|
|
34564
|
+
});
|
|
34565
|
+
const selected2 = this.model(model2);
|
|
34566
|
+
const cwd = this.contexts.capture(model2).cwd;
|
|
34567
|
+
const runtime = unattendedRuntime(this.o.models.workerSettings(cwd, selected2));
|
|
34568
|
+
const { source, digest: digest2, delivery } = this.observation(plan, runtime);
|
|
34569
|
+
const p = {
|
|
34570
|
+
...revalidatedFrom ? { revalidatedFrom } : {},
|
|
34571
|
+
...delivery ? { delivery } : {},
|
|
34572
|
+
id: commandId,
|
|
34573
|
+
epoch: this.o.owner.lease.registration.epoch,
|
|
34574
|
+
model: model2,
|
|
34575
|
+
plan,
|
|
34576
|
+
cwd,
|
|
34577
|
+
checkoutRoot: this.cwd,
|
|
34578
|
+
observation: digest2,
|
|
34579
|
+
display: {
|
|
34580
|
+
runtime: runtimeSummary(runtime),
|
|
34581
|
+
model: `${selected2.provider}/${selected2.model} · ${selected2.thinking}`,
|
|
34582
|
+
branch: source.branch,
|
|
34583
|
+
baseCommit: source.head
|
|
34584
|
+
},
|
|
34585
|
+
digest: hash(canonicalJson(delivery ? { plan, delivery } : plan))
|
|
34586
|
+
};
|
|
34587
|
+
if (sanitizeData(p, secrets) !== canonicalJson(p))
|
|
34588
|
+
throw new ContractError("forbidden");
|
|
34589
|
+
const target2 = join43(this.root, "proposals", `${decodeId(commandId)}.json`);
|
|
34590
|
+
const previous = this.files.read(target2, RECORD_BYTES3);
|
|
34591
|
+
if (previous) {
|
|
34592
|
+
if (previous.bytes.toString("utf8") !== canonicalJson(p))
|
|
34593
|
+
throw new ContractError("conflict");
|
|
34594
|
+
} else {
|
|
34595
|
+
effect();
|
|
34596
|
+
this.write(target2, p);
|
|
34597
|
+
}
|
|
34598
|
+
return p;
|
|
34599
|
+
}
|
|
34600
|
+
discardGrant(grant) {
|
|
34601
|
+
this.o.owner.lease.assert();
|
|
34602
|
+
this.grants.delete(grant);
|
|
34603
|
+
}
|
|
34506
34604
|
assertProposal(p, digest2) {
|
|
34507
34605
|
this.current();
|
|
34508
34606
|
try {
|
|
@@ -34704,12 +34802,13 @@ class Workflows {
|
|
|
34704
34802
|
if (r.action === "cancel")
|
|
34705
34803
|
return this.cancel(commandId, epoch, r.runId);
|
|
34706
34804
|
if (!options.definite)
|
|
34707
|
-
return this.admit(commandId, epoch, r, () => {});
|
|
34805
|
+
return this.admit(commandId, epoch, r, options.beforeAdmission ?? (() => {}));
|
|
34708
34806
|
let effects = true;
|
|
34709
34807
|
try {
|
|
34710
34808
|
effects = this.o.owner.state !== "idle" || this.attempted(commandId, r.action);
|
|
34711
34809
|
return this.admit(commandId, epoch, r, () => {
|
|
34712
34810
|
effects = true;
|
|
34811
|
+
options.beforeAdmission?.();
|
|
34713
34812
|
});
|
|
34714
34813
|
} catch (error) {
|
|
34715
34814
|
if (!effects && error instanceof ContractError && !(error instanceof UnacceptedConversationCommand) && this.o.owner.state === "idle")
|
|
@@ -34733,44 +34832,11 @@ class Workflows {
|
|
|
34733
34832
|
throw new ContractError("stale");
|
|
34734
34833
|
const secrets = this.o.secrets();
|
|
34735
34834
|
if (r.action === "propose") {
|
|
34736
|
-
this.
|
|
34737
|
-
this.floor();
|
|
34738
|
-
const plan = decodeWorkflowPlan(JSON.parse(sanitizeData(r.plan, secrets)), { strict: true });
|
|
34739
|
-
const selected2 = this.model(r.model);
|
|
34740
|
-
const runtime2 = unattendedRuntime(this.o.models.workerSettings(this.contexts.capture(r.model).cwd, selected2));
|
|
34741
|
-
const { source, digest: digest2, delivery: delivery2 } = this.observation(plan, runtime2);
|
|
34742
|
-
const p = {
|
|
34743
|
-
...delivery2 ? { delivery: delivery2 } : {},
|
|
34744
|
-
id: commandId,
|
|
34745
|
-
epoch,
|
|
34746
|
-
model: r.model,
|
|
34747
|
-
plan,
|
|
34748
|
-
cwd: this.contexts.capture(r.model).cwd,
|
|
34749
|
-
checkoutRoot: this.cwd,
|
|
34750
|
-
observation: digest2,
|
|
34751
|
-
display: {
|
|
34752
|
-
runtime: runtimeSummary(runtime2),
|
|
34753
|
-
model: `${selected2.provider}/${selected2.model} · ${selected2.thinking}`,
|
|
34754
|
-
branch: source.branch,
|
|
34755
|
-
baseCommit: source.head
|
|
34756
|
-
},
|
|
34757
|
-
digest: hash(canonicalJson(delivery2 ? { plan, delivery: delivery2 } : plan))
|
|
34758
|
-
};
|
|
34759
|
-
if (sanitizeData(p, secrets) !== canonicalJson(p))
|
|
34760
|
-
throw new ContractError("forbidden");
|
|
34761
|
-
const target3 = join43(this.root, "proposals", `${commandId}.json`);
|
|
34762
|
-
const previous = this.files.read(target3, RECORD_BYTES3);
|
|
34763
|
-
if (previous) {
|
|
34764
|
-
if (previous.bytes.toString("utf8") !== canonicalJson(p))
|
|
34765
|
-
throw new ContractError("conflict");
|
|
34766
|
-
} else {
|
|
34767
|
-
effect();
|
|
34768
|
-
this.write(target3, p);
|
|
34769
|
-
}
|
|
34835
|
+
const proposal2 = this.publishProposal(commandId, r.plan, r.model, effect);
|
|
34770
34836
|
return {
|
|
34771
34837
|
kind: "workflow",
|
|
34772
34838
|
commandId,
|
|
34773
|
-
response: { type: "proposal", proposal:
|
|
34839
|
+
response: { type: "proposal", proposal: proposal2 }
|
|
34774
34840
|
};
|
|
34775
34841
|
}
|
|
34776
34842
|
if (r.action === "prepare") {
|
|
@@ -34835,8 +34901,6 @@ class Workflows {
|
|
|
34835
34901
|
if (sanitizeData(delivery, secrets) !== canonicalJson(delivery))
|
|
34836
34902
|
throw new ContractError("forbidden");
|
|
34837
34903
|
}
|
|
34838
|
-
effect();
|
|
34839
|
-
this.grants.delete(request3.grant);
|
|
34840
34904
|
if (proposal.plan.delivery === "local-merge")
|
|
34841
34905
|
target2 = { head: source.head, branch: source.branch };
|
|
34842
34906
|
else
|
|
@@ -34892,6 +34956,8 @@ class Workflows {
|
|
|
34892
34956
|
notes: []
|
|
34893
34957
|
};
|
|
34894
34958
|
effect();
|
|
34959
|
+
if (request3.action === "execute")
|
|
34960
|
+
this.grants.delete(request3.grant);
|
|
34895
34961
|
this.active.set(commandId, live2);
|
|
34896
34962
|
this.o.owner.trackConversation(live2.original, () => abort.abort({ source: "service", reason: "stop", target: commandId }));
|
|
34897
34963
|
try {
|
|
@@ -36883,6 +36949,8 @@ class Workbench {
|
|
|
36883
36949
|
}
|
|
36884
36950
|
if (request3.kind === "send" || request3.kind === "cadence-send" || request3.kind === "cadence-exit")
|
|
36885
36951
|
return this.send(request3, caller);
|
|
36952
|
+
if (request3.kind === "cadence-revalidate")
|
|
36953
|
+
return this.cadence.revalidate(request3, caller);
|
|
36886
36954
|
if (request3.kind === "cadence-prepare" || request3.kind === "cadence-approve")
|
|
36887
36955
|
return this.cadence.approval(request3, caller);
|
|
36888
36956
|
if (request3.kind === "workflow-cancel") {
|
|
@@ -37063,7 +37131,7 @@ var processLifetime = {
|
|
|
37063
37131
|
}
|
|
37064
37132
|
};
|
|
37065
37133
|
async function createServiceHost(value, sourceBuild, lifetime) {
|
|
37066
|
-
const embedded = "
|
|
37134
|
+
const embedded = "6aa819700494584b707a8e1b44428c532cd7ac7b1c8a28126e401b43f527543b";
|
|
37067
37135
|
if (embedded && sourceBuild)
|
|
37068
37136
|
throw new ContractError("unsupported-context");
|
|
37069
37137
|
const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);
|