@abelxiaoxing/cadence 2.1.10 → 2.1.11
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/THIRD_PARTY_NOTICES.md +9 -0
- package/docs/conversation-mode.md +11 -3
- package/docs/reuse-and-distribution.md +8 -0
- package/package.json +1 -1
- package/src/cadence-instructions.ts +1 -1
- package/src/model-preview.mjs +9 -0
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +6 -1
- package/src/service/contracts/workbench.ts +101 -7
- package/src/service/contracts/workflow.ts +3 -3
- package/src/service-cli.mjs +9 -0
- package/src/service-host.mjs +619 -179
- package/src/worker-capture.mjs +157 -9
- package/src/worker-public.mjs +9 -0
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +26 -29
- package/web/dist/assets/markdown.js +1 -1
- package/web/dist/manifest.json +9 -9
package/src/service-host.mjs
CHANGED
|
@@ -1499,6 +1499,15 @@ function decodeCaptureEvent(v) {
|
|
|
1499
1499
|
resultCallId
|
|
1500
1500
|
};
|
|
1501
1501
|
}
|
|
1502
|
+
case "thinking-activity": {
|
|
1503
|
+
const o = closed(v, ["kind", "messageId", "index", "phase"]);
|
|
1504
|
+
return {
|
|
1505
|
+
kind,
|
|
1506
|
+
messageId: decodeId(o.messageId),
|
|
1507
|
+
index: integer(o.index, 0, LIMITS.dataFrames),
|
|
1508
|
+
phase: oneOf(o.phase, ["active", "complete", "unavailable"])
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1502
1511
|
case "message-text": {
|
|
1503
1512
|
const o = closed(v, ["kind", "messageId", "blockId", "detailId"]);
|
|
1504
1513
|
return {
|
|
@@ -6170,7 +6179,7 @@ ${p.reviewReads.map(readableReading).join(`
|
|
|
6170
6179
|
`)}` : ""}
|
|
6171
6180
|
|
|
6172
6181
|
## Automation boundary
|
|
6173
|
-
${readableAutomation(p)} Only actual verification and independent Agent review permit delivery. ${p.delivery === "local-merge" ? "Authorize one new named task branch and stable isolated worktree after approval, temporary worktrees beside it for assignments that run side by side, local commits and fast-forward delivery of the exact checked and Agent-reviewed candidate into the displayed target. Keep the task branch; retain any worktree with uncommitted, untracked or ignored residue." : "Direct working-copy edits; failures leave actual edits for inspection. No Git commit or merge."} No push, publication, deployment or recursive delegation. Related project knowledge and workflow Markdown are included. Worktrees/tools are not a sandbox.
|
|
6182
|
+
${readableAutomation(p)} Only actual verification and independent Agent review permit delivery. ${p.delivery === "local-merge" ? "Authorize one new named task branch and stable isolated worktree after approval, temporary worktrees beside it for assignments that run side by side, local commits and serialized fast-forward delivery of the exact checked and Agent-reviewed candidate into the displayed target. Independent conversations may implement in separate candidates; a verified non-overlapping sibling delivery may be merged into this candidate and checked/reviewed again. Conflicts, changed instructions, overlapping inputs or external target drift retain the candidate for a fresh plan. Keep the task branch; retain any worktree with uncommitted, untracked or ignored residue." : "Direct working-copy edits; failures leave actual edits for inspection. No Git commit or merge."} No push, publication, deployment or recursive delegation. Related project knowledge and workflow Markdown are included. Worktrees/tools are not a sandbox.
|
|
6174
6183
|
|
|
6175
6184
|
## Project documents
|
|
6176
6185
|
${p.version === undefined ? p.projectContext : documents.join(`
|
|
@@ -6306,6 +6315,7 @@ function chatStep(item, parts, more = false) {
|
|
|
6306
6315
|
const text2 = lazy ? "" : clipText(item.text, STEP_TEXT_BYTES);
|
|
6307
6316
|
return {
|
|
6308
6317
|
id: item.id,
|
|
6318
|
+
...presentation(item),
|
|
6309
6319
|
role: item.role,
|
|
6310
6320
|
text: text2,
|
|
6311
6321
|
...item.images?.length ? { images: item.images } : {},
|
|
@@ -6772,8 +6782,52 @@ function decodeChatImages(v) {
|
|
|
6772
6782
|
};
|
|
6773
6783
|
});
|
|
6774
6784
|
}
|
|
6785
|
+
var PRESENTATION_KEYS = ["renderId", "version", "state"];
|
|
6786
|
+
function presentationKeys(v) {
|
|
6787
|
+
return PRESENTATION_KEYS.filter((key) => Object.hasOwn(v ?? {}, key));
|
|
6788
|
+
}
|
|
6789
|
+
function presentation(v) {
|
|
6790
|
+
return {
|
|
6791
|
+
...v.renderId === undefined ? {} : { renderId: v.renderId },
|
|
6792
|
+
...v.version === undefined ? {} : { version: v.version },
|
|
6793
|
+
...v.state === undefined ? {} : { state: v.state }
|
|
6794
|
+
};
|
|
6795
|
+
}
|
|
6796
|
+
function decodePresentation(o) {
|
|
6797
|
+
return {
|
|
6798
|
+
...o.renderId === undefined ? {} : { renderId: text(o.renderId, 160, true) },
|
|
6799
|
+
...o.version === undefined ? {} : { version: decodeHash(o.version) },
|
|
6800
|
+
...o.state === undefined ? {} : {
|
|
6801
|
+
state: oneOf(o.state, [
|
|
6802
|
+
"pending",
|
|
6803
|
+
"streaming",
|
|
6804
|
+
"running",
|
|
6805
|
+
"completed",
|
|
6806
|
+
"failed",
|
|
6807
|
+
"canceled",
|
|
6808
|
+
"unavailable"
|
|
6809
|
+
])
|
|
6810
|
+
}
|
|
6811
|
+
};
|
|
6812
|
+
}
|
|
6813
|
+
function decodeChatActivity(v) {
|
|
6814
|
+
const o = closed(v, [
|
|
6815
|
+
"kind",
|
|
6816
|
+
"sequence",
|
|
6817
|
+
...Object.hasOwn(v ?? {}, "name") ? ["name"] : []
|
|
6818
|
+
]);
|
|
6819
|
+
const kind = oneOf(o.kind, ["waiting", "thinking", "text", "tool"]);
|
|
6820
|
+
if (o.name !== undefined && kind !== "tool")
|
|
6821
|
+
throw new ContractError("invalid");
|
|
6822
|
+
return {
|
|
6823
|
+
kind,
|
|
6824
|
+
sequence: integer(o.sequence, 0),
|
|
6825
|
+
...o.name === undefined ? {} : { name: text(o.name, 128) }
|
|
6826
|
+
};
|
|
6827
|
+
}
|
|
6775
6828
|
function decodeChatItem(v) {
|
|
6776
6829
|
const i = closed(v, [
|
|
6830
|
+
...presentationKeys(v),
|
|
6777
6831
|
"id",
|
|
6778
6832
|
"role",
|
|
6779
6833
|
"text",
|
|
@@ -6783,6 +6837,7 @@ function decodeChatItem(v) {
|
|
|
6783
6837
|
...Object.hasOwn(v ?? {}, "images") ? ["images"] : []
|
|
6784
6838
|
]);
|
|
6785
6839
|
return {
|
|
6840
|
+
...decodePresentation(i),
|
|
6786
6841
|
...i.images === undefined ? {} : { images: decodeChatImages(i.images) },
|
|
6787
6842
|
id: text(i.id, 160, true),
|
|
6788
6843
|
role: oneOf(i.role, ITEM_ROLES),
|
|
@@ -6794,6 +6849,7 @@ function decodeChatItem(v) {
|
|
|
6794
6849
|
}
|
|
6795
6850
|
function decodeChatStep(v) {
|
|
6796
6851
|
const o = closed(v, [
|
|
6852
|
+
...presentationKeys(v),
|
|
6797
6853
|
"id",
|
|
6798
6854
|
"role",
|
|
6799
6855
|
"text",
|
|
@@ -6805,6 +6861,7 @@ function decodeChatStep(v) {
|
|
|
6805
6861
|
"parts"
|
|
6806
6862
|
]);
|
|
6807
6863
|
const step = {
|
|
6864
|
+
...decodePresentation(o),
|
|
6808
6865
|
...o.images === undefined ? {} : { images: decodeChatImages(o.images) },
|
|
6809
6866
|
id: text(o.id, 160, true),
|
|
6810
6867
|
role: oneOf(o.role, ITEM_ROLES),
|
|
@@ -6817,12 +6874,23 @@ function decodeChatStep(v) {
|
|
|
6817
6874
|
};
|
|
6818
6875
|
if ((step.role === "tool" || step.role === "thinking") && (step.text || step.clipped))
|
|
6819
6876
|
throw new ContractError("invalid");
|
|
6820
|
-
if (step.role === "thinking"
|
|
6821
|
-
|
|
6877
|
+
if (step.role === "thinking") {
|
|
6878
|
+
if (!step.parts && !(step.renderId && [
|
|
6879
|
+
"streaming",
|
|
6880
|
+
"completed",
|
|
6881
|
+
"unavailable",
|
|
6882
|
+
"canceled",
|
|
6883
|
+
"failed"
|
|
6884
|
+
].includes(step.state ?? "")))
|
|
6885
|
+
throw new ContractError("invalid");
|
|
6886
|
+
if (step.parts && step.state !== undefined && step.state !== "completed")
|
|
6887
|
+
throw new ContractError("invalid");
|
|
6888
|
+
}
|
|
6822
6889
|
return step;
|
|
6823
6890
|
}
|
|
6824
6891
|
function decodeChatTurnHeader(v) {
|
|
6825
6892
|
const o = closed(v, [
|
|
6893
|
+
...Object.hasOwn(v ?? {}, "activity") ? ["activity"] : [],
|
|
6826
6894
|
"id",
|
|
6827
6895
|
"status",
|
|
6828
6896
|
"notice",
|
|
@@ -6838,6 +6906,7 @@ function decodeChatTurnHeader(v) {
|
|
|
6838
6906
|
const omitted = closed(o.omitted, ["thinking", "media", "other"]);
|
|
6839
6907
|
const steps = integer(o.steps, 0);
|
|
6840
6908
|
return {
|
|
6909
|
+
...o.activity === undefined ? {} : { activity: decodeChatActivity(o.activity) },
|
|
6841
6910
|
...o.execution === undefined ? {} : { execution: decodeExecutionContext(o.execution) },
|
|
6842
6911
|
...o.retry === undefined ? {} : { retry: decodeModelRetry(o.retry) },
|
|
6843
6912
|
id: decodeEntryId(o.id),
|
|
@@ -9290,6 +9359,61 @@ function fold(summary, line) {
|
|
|
9290
9359
|
summary.stop = stopStatus(m);
|
|
9291
9360
|
}
|
|
9292
9361
|
}
|
|
9362
|
+
function commandMarker(entry) {
|
|
9363
|
+
if (entry.type !== "custom" || own2(entry.raw, "customType") !== BROWSER_COMMAND_ENTRY)
|
|
9364
|
+
return;
|
|
9365
|
+
const value = own2(entry.raw, "data");
|
|
9366
|
+
const d = closed(value, [
|
|
9367
|
+
"commandId",
|
|
9368
|
+
"userId",
|
|
9369
|
+
...Object.hasOwn(value ?? {}, "run") ? ["run"] : [],
|
|
9370
|
+
...Object.hasOwn(value ?? {}, "captureMessageId") ? ["captureMessageId"] : [],
|
|
9371
|
+
...Object.hasOwn(value ?? {}, "captureResultCallId") ? ["captureResultCallId"] : []
|
|
9372
|
+
]);
|
|
9373
|
+
if (d.captureResultCallId !== undefined && d.captureMessageId === undefined)
|
|
9374
|
+
throw new ContractError("corrupt-selected");
|
|
9375
|
+
return {
|
|
9376
|
+
commandId: decodeId(d.commandId),
|
|
9377
|
+
userId: decodeEntryId(d.userId),
|
|
9378
|
+
...d.run === undefined ? {} : { run: decodeId(d.run) },
|
|
9379
|
+
...d.captureMessageId === undefined ? {} : { captureMessageId: decodeId(d.captureMessageId) },
|
|
9380
|
+
...d.captureResultCallId === undefined ? {} : { captureResultCallId: decodeId(d.captureResultCallId) }
|
|
9381
|
+
};
|
|
9382
|
+
}
|
|
9383
|
+
function captureLinks(entries2) {
|
|
9384
|
+
const byId = new Map(entries2.map((e) => [e.id, e]));
|
|
9385
|
+
const commands = new Map;
|
|
9386
|
+
const ids = new Set;
|
|
9387
|
+
const links = new Map;
|
|
9388
|
+
let user;
|
|
9389
|
+
for (const entry of entries2) {
|
|
9390
|
+
if (isUser(entry))
|
|
9391
|
+
user = entry.id;
|
|
9392
|
+
const marker2 = commandMarker(entry);
|
|
9393
|
+
if (!marker2)
|
|
9394
|
+
continue;
|
|
9395
|
+
const first = commands.get(marker2.commandId);
|
|
9396
|
+
const parent = entry.parentId ? byId.get(entry.parentId) : undefined;
|
|
9397
|
+
if (!parent || parent.pos >= entry.pos || parent.type !== "message" || !["user", "assistant", "toolResult"].includes(role2(parent)) || marker2.userId !== user || !first && entry.parentId !== marker2.userId || first && (first.userId !== marker2.userId || first.run !== marker2.run) || marker2.run === marker2.commandId || marker2.captureResultCallId !== undefined && role2(parent) !== "toolResult")
|
|
9398
|
+
throw new ContractError("corrupt-selected");
|
|
9399
|
+
commands.set(marker2.commandId, marker2);
|
|
9400
|
+
if (marker2.captureMessageId) {
|
|
9401
|
+
if (ids.has(marker2.captureMessageId) || links.has(parent.id))
|
|
9402
|
+
throw new ContractError("corrupt-selected");
|
|
9403
|
+
ids.add(marker2.captureMessageId);
|
|
9404
|
+
if (marker2.captureResultCallId) {
|
|
9405
|
+
if (ids.has(marker2.captureResultCallId))
|
|
9406
|
+
throw new ContractError("corrupt-selected");
|
|
9407
|
+
ids.add(marker2.captureResultCallId);
|
|
9408
|
+
}
|
|
9409
|
+
links.set(parent.id, {
|
|
9410
|
+
messageId: marker2.captureMessageId,
|
|
9411
|
+
...marker2.captureResultCallId ? { resultCallId: marker2.captureResultCallId } : {}
|
|
9412
|
+
});
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
return links;
|
|
9416
|
+
}
|
|
9293
9417
|
|
|
9294
9418
|
class ParsedSession {
|
|
9295
9419
|
path;
|
|
@@ -9304,6 +9428,7 @@ class ParsedSession {
|
|
|
9304
9428
|
usages = new Map;
|
|
9305
9429
|
cache = { input: 0, read: 0, write: 0 };
|
|
9306
9430
|
boundaries = new Map;
|
|
9431
|
+
captureOccurrences = new Map;
|
|
9307
9432
|
constructor(path) {
|
|
9308
9433
|
this.path = path;
|
|
9309
9434
|
}
|
|
@@ -9375,6 +9500,11 @@ class ParsedSession {
|
|
|
9375
9500
|
if (entry.type === "custom" && own2(entry.raw, "customType") === BROWSER_COMMAND_ENTRY) {
|
|
9376
9501
|
const data = own2(entry.raw, "data");
|
|
9377
9502
|
const d = data && typeof data === "object" && !Array.isArray(data) ? data : {};
|
|
9503
|
+
for (const field of ["captureMessageId", "captureResultCallId"]) {
|
|
9504
|
+
const captureId = own2(d, field);
|
|
9505
|
+
if (typeof captureId === "string")
|
|
9506
|
+
this.captureOccurrences.set(captureId, (this.captureOccurrences.get(captureId) ?? 0) + 1);
|
|
9507
|
+
}
|
|
9378
9508
|
const commandId = own2(d, "commandId");
|
|
9379
9509
|
if (typeof commandId === "string") {
|
|
9380
9510
|
const boundary = {
|
|
@@ -9413,11 +9543,18 @@ class ParsedSession {
|
|
|
9413
9543
|
this.usages.clear();
|
|
9414
9544
|
this.cache.input = this.cache.read = this.cache.write = 0;
|
|
9415
9545
|
this.boundaries.clear();
|
|
9546
|
+
this.captureOccurrences.clear();
|
|
9416
9547
|
this.header = null;
|
|
9417
9548
|
});
|
|
9418
9549
|
this.read = next;
|
|
9419
9550
|
return this;
|
|
9420
9551
|
}
|
|
9552
|
+
validateCaptures(entries2) {
|
|
9553
|
+
for (const link of captureLinks(entries2).values())
|
|
9554
|
+
for (const id of [link.messageId, link.resultCallId])
|
|
9555
|
+
if (id !== undefined && this.captureOccurrences.get(id) !== 1)
|
|
9556
|
+
throw new ContractError("corrupt-selected");
|
|
9557
|
+
}
|
|
9421
9558
|
current() {
|
|
9422
9559
|
return this.entries.at(-1)?.id ?? null;
|
|
9423
9560
|
}
|
|
@@ -9520,7 +9657,7 @@ class ParsedSession {
|
|
|
9520
9657
|
}
|
|
9521
9658
|
if (!this.follows(first.user, run.parent, run.offset))
|
|
9522
9659
|
throw new ContractError("stale");
|
|
9523
|
-
if (sent.some((part) => part.boundaries.some((boundary) => boundary.run !== run.commandId)))
|
|
9660
|
+
if (first.boundaries.some((boundary) => boundary.run !== undefined) || sent.some((part) => part.boundaries.some((boundary) => boundary.run !== run.commandId)))
|
|
9524
9661
|
throw new ContractError("corrupt-selected");
|
|
9525
9662
|
const parts = [
|
|
9526
9663
|
{ commandId: run.commandId, ...first },
|
|
@@ -9541,7 +9678,9 @@ class ParsedSession {
|
|
|
9541
9678
|
return position <= start || position >= end || boundary.user !== part.user.id;
|
|
9542
9679
|
}))
|
|
9543
9680
|
throw new ContractError("corrupt-selected");
|
|
9544
|
-
|
|
9681
|
+
const entries2 = chain.slice(start, end);
|
|
9682
|
+
this.validateCaptures(entries2);
|
|
9683
|
+
return { commandId: part.commandId, entries: entries2 };
|
|
9545
9684
|
});
|
|
9546
9685
|
}
|
|
9547
9686
|
tree(leaf, secrets) {
|
|
@@ -9596,6 +9735,11 @@ function shown(entry) {
|
|
|
9596
9735
|
}
|
|
9597
9736
|
var clip = (value, bytes) => clipText(value, bytes);
|
|
9598
9737
|
function turnItems(entries2, secrets) {
|
|
9738
|
+
const links = captureLinks(entries2);
|
|
9739
|
+
const userCommands = new Map(entries2.flatMap((entry) => {
|
|
9740
|
+
const marker2 = commandMarker(entry);
|
|
9741
|
+
return marker2 && entry.parentId === marker2.userId ? [[marker2.userId, marker2.commandId]] : [];
|
|
9742
|
+
}));
|
|
9599
9743
|
const omitted = { thinking: false, media: false, other: false };
|
|
9600
9744
|
const items = [];
|
|
9601
9745
|
const tools = new Map;
|
|
@@ -9610,8 +9754,19 @@ function turnItems(entries2, secrets) {
|
|
|
9610
9754
|
});
|
|
9611
9755
|
return items[items.length - 1];
|
|
9612
9756
|
};
|
|
9613
|
-
const tool = (id, name, args, text2 = "", error = false) => add({
|
|
9757
|
+
const tool = (id, name, args, text2 = "", error = false) => add({
|
|
9758
|
+
id,
|
|
9759
|
+
renderId: `pi:${id}`,
|
|
9760
|
+
role: "tool",
|
|
9761
|
+
name,
|
|
9762
|
+
args,
|
|
9763
|
+
text: text2,
|
|
9764
|
+
error,
|
|
9765
|
+
state: error ? "failed" : "completed"
|
|
9766
|
+
});
|
|
9614
9767
|
for (const entry of entries2) {
|
|
9768
|
+
const link = links.get(entry.id), captureId = link?.messageId;
|
|
9769
|
+
const renderId = (index) => captureId ? `capture:${captureId}:${index}` : `pi:${entry.id}:${index}`;
|
|
9615
9770
|
const m = message(entry);
|
|
9616
9771
|
if (m) {
|
|
9617
9772
|
const kind = own2(m, "role");
|
|
@@ -9625,6 +9780,8 @@ function turnItems(entries2, secrets) {
|
|
|
9625
9780
|
add({
|
|
9626
9781
|
...images.length ? { images } : {},
|
|
9627
9782
|
id: entry.id,
|
|
9783
|
+
renderId: userCommands.has(entry.id) ? `command:${userCommands.get(entry.id)}:user` : renderId(0),
|
|
9784
|
+
state: "completed",
|
|
9628
9785
|
role: "user",
|
|
9629
9786
|
text: text2,
|
|
9630
9787
|
name: "",
|
|
@@ -9632,50 +9789,64 @@ function turnItems(entries2, secrets) {
|
|
|
9632
9789
|
error: false
|
|
9633
9790
|
});
|
|
9634
9791
|
} else if (kind === "assistant") {
|
|
9635
|
-
let text2;
|
|
9636
9792
|
const content = own2(m, "content");
|
|
9637
|
-
|
|
9793
|
+
const state = own2(m, "stopReason") === "aborted" ? "canceled" : ["error", "length"].includes(own2(m, "stopReason")) ? "failed" : "completed";
|
|
9794
|
+
for (const [index, block] of (Array.isArray(content) ? content : []).entries()) {
|
|
9638
9795
|
const b = block && typeof block === "object" ? block : {};
|
|
9639
9796
|
const type = own2(b, "type");
|
|
9640
9797
|
if (type === "text" && typeof own2(b, "text") === "string") {
|
|
9641
9798
|
const value = own2(b, "text");
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
args: "",
|
|
9653
|
-
error: ["error", "aborted", "length"].includes(own2(m, "stopReason"))
|
|
9654
|
-
});
|
|
9799
|
+
add({
|
|
9800
|
+
id: `${entry.id}:${index}`,
|
|
9801
|
+
renderId: renderId(index),
|
|
9802
|
+
state,
|
|
9803
|
+
role: "assistant",
|
|
9804
|
+
text: value,
|
|
9805
|
+
name: "",
|
|
9806
|
+
args: "",
|
|
9807
|
+
error: ["error", "aborted", "length"].includes(own2(m, "stopReason"))
|
|
9808
|
+
});
|
|
9655
9809
|
} else if (type === "toolCall") {
|
|
9656
|
-
const id = own2(b, "id"), name = own2(b, "name");
|
|
9810
|
+
const id = own2(b, "id"), name = own2(b, "name"), rawName = typeof name === "string" ? name : "tool";
|
|
9657
9811
|
let args = "";
|
|
9658
9812
|
try {
|
|
9659
9813
|
args = JSON.stringify(own2(b, "arguments") ?? {}) ?? "";
|
|
9660
9814
|
} catch {
|
|
9661
9815
|
omitted.other = true;
|
|
9662
9816
|
}
|
|
9663
|
-
const call = tool(typeof id === "string" && id ? id : `${entry.id}:${
|
|
9664
|
-
|
|
9665
|
-
|
|
9817
|
+
const call = tool(typeof id === "string" && id ? id : `${entry.id}:${index}`, rawName, args);
|
|
9818
|
+
call.renderId = renderId(index);
|
|
9819
|
+
call.state = state === "failed" ? "unavailable" : state === "canceled" ? "canceled" : "pending";
|
|
9820
|
+
if (typeof id === "string") {
|
|
9821
|
+
tools.set(id, tools.has(id) ? null : { rawName, item: call });
|
|
9822
|
+
}
|
|
9666
9823
|
} else if (type === "thinking" || type === "redactedThinking") {
|
|
9667
9824
|
const value = own2(b, "thinking");
|
|
9668
9825
|
if (type === "thinking" && typeof value === "string" && value.trim() && own2(b, "redacted") !== true)
|
|
9669
9826
|
add({
|
|
9670
|
-
id: `${entry.id}:${
|
|
9827
|
+
id: `${entry.id}:${index}`,
|
|
9828
|
+
renderId: renderId(index),
|
|
9829
|
+
state: "completed",
|
|
9671
9830
|
role: "thinking",
|
|
9672
9831
|
text: value,
|
|
9673
9832
|
name: "",
|
|
9674
9833
|
args: "",
|
|
9675
9834
|
error: false
|
|
9676
9835
|
});
|
|
9677
|
-
else
|
|
9836
|
+
else {
|
|
9678
9837
|
omitted.thinking = true;
|
|
9838
|
+
if (captureId)
|
|
9839
|
+
add({
|
|
9840
|
+
id: `${entry.id}:${index}`,
|
|
9841
|
+
renderId: renderId(index),
|
|
9842
|
+
state: "unavailable",
|
|
9843
|
+
role: "thinking",
|
|
9844
|
+
text: "",
|
|
9845
|
+
name: "",
|
|
9846
|
+
args: "",
|
|
9847
|
+
error: false
|
|
9848
|
+
});
|
|
9849
|
+
}
|
|
9679
9850
|
} else if (type === "image")
|
|
9680
9851
|
omitted.media = true;
|
|
9681
9852
|
else
|
|
@@ -9686,11 +9857,16 @@ ${value}`, secrets);
|
|
|
9686
9857
|
const id = own2(m, "toolCallId"), name = own2(m, "toolName");
|
|
9687
9858
|
const output = sanitizeText(contentText(own2(m, "content"), omitted), secrets);
|
|
9688
9859
|
const call = typeof id === "string" ? tools.get(id) : undefined;
|
|
9689
|
-
if (call) {
|
|
9690
|
-
call.text = output;
|
|
9691
|
-
call.error = own2(m, "isError") === true;
|
|
9692
|
-
|
|
9693
|
-
|
|
9860
|
+
if (!link?.resultCallId && call && call.rawName === (typeof name === "string" ? name : "tool")) {
|
|
9861
|
+
call.item.text = output;
|
|
9862
|
+
call.item.error = own2(m, "isError") === true;
|
|
9863
|
+
call.item.state = call.item.error ? "failed" : "completed";
|
|
9864
|
+
if (typeof id === "string")
|
|
9865
|
+
tools.delete(id);
|
|
9866
|
+
} else {
|
|
9867
|
+
const orphan = tool(typeof id === "string" && id ? id : entry.id, typeof name === "string" ? name : "tool", "", output, own2(m, "isError") === true);
|
|
9868
|
+
orphan.renderId = link?.resultCallId ? `call:${link.resultCallId}` : renderId(0);
|
|
9869
|
+
}
|
|
9694
9870
|
} else if (kind === "bashExecution") {
|
|
9695
9871
|
const command = own2(m, "command"), output = own2(m, "output"), code = own2(m, "exitCode");
|
|
9696
9872
|
tool(entry.id, "bash", JSON.stringify({
|
|
@@ -9707,6 +9883,7 @@ ${value}`, secrets);
|
|
|
9707
9883
|
}
|
|
9708
9884
|
const first = entries2.find(isUser) ?? entries2[0];
|
|
9709
9885
|
return {
|
|
9886
|
+
captureMessages: [...links.values()].map((link) => link.messageId),
|
|
9710
9887
|
id: first?.id ?? "",
|
|
9711
9888
|
entry: entries2.at(-1)?.id ?? null,
|
|
9712
9889
|
parent: first?.parentId ?? null,
|
|
@@ -9747,6 +9924,14 @@ function itemParts(item) {
|
|
|
9747
9924
|
}));
|
|
9748
9925
|
}
|
|
9749
9926
|
function listTurn(turn) {
|
|
9927
|
+
turn = {
|
|
9928
|
+
...turn,
|
|
9929
|
+
items: turn.items.map((item) => ({
|
|
9930
|
+
...item,
|
|
9931
|
+
renderId: item.renderId ?? `pi:${item.id}`,
|
|
9932
|
+
version: createHash7("sha256").update(JSON.stringify([item.text, item.args, item.images ?? []])).digest("hex")
|
|
9933
|
+
}))
|
|
9934
|
+
};
|
|
9750
9935
|
const parts = turn.items.map(itemParts);
|
|
9751
9936
|
const steps = turn.items.map((item, index) => {
|
|
9752
9937
|
const listed = chatStep(item.role === "tool" && item.args.length > TARGET_ARGS ? { ...item, args: "" } : item, 0);
|
|
@@ -9924,6 +10109,7 @@ class PiSessions {
|
|
|
9924
10109
|
return parsed;
|
|
9925
10110
|
}
|
|
9926
10111
|
turn(session, entries2, secrets) {
|
|
10112
|
+
session.validateCaptures(entries2);
|
|
9927
10113
|
const key = [
|
|
9928
10114
|
session.path,
|
|
9929
10115
|
session.incarnation,
|
|
@@ -14929,6 +15115,20 @@ var NOT_DELIVERED = "Not delivered: the reply ended before this message reached
|
|
|
14929
15115
|
var UNOBSERVED = "Not observed: the session could not be read when the reply ended, so whether this message was delivered was not recorded. Nothing was replayed.";
|
|
14930
15116
|
var WITHDRAWN = "Withdrawn before it was delivered.";
|
|
14931
15117
|
var LIVE = ["queued", "running"];
|
|
15118
|
+
function settledSteps(turn) {
|
|
15119
|
+
if (LIVE.includes(turn.status) || !turn.items.some((item) => ["pending", "running", "streaming"].includes(item.state ?? "")))
|
|
15120
|
+
return turn;
|
|
15121
|
+
return {
|
|
15122
|
+
...turn,
|
|
15123
|
+
...listTurn({
|
|
15124
|
+
...turn,
|
|
15125
|
+
items: turn.items.map((item) => ["pending", "running", "streaming"].includes(item.state ?? "") ? {
|
|
15126
|
+
...item,
|
|
15127
|
+
state: turn.status === "canceled" ? "canceled" : "unavailable"
|
|
15128
|
+
} : item)
|
|
15129
|
+
})
|
|
15130
|
+
};
|
|
15131
|
+
}
|
|
14932
15132
|
function observedFile(path) {
|
|
14933
15133
|
try {
|
|
14934
15134
|
const s = lstatSync15(path);
|
|
@@ -15477,18 +15677,19 @@ class ConversationRecords {
|
|
|
15477
15677
|
const turn2 = this.sessions.turn(view.session, view.turns[ordinal], secrets);
|
|
15478
15678
|
const recorded = this.overlay(id, view.session).get(turn2.id);
|
|
15479
15679
|
const running = view.parts?.slice(0, -1).some((part) => part.entries[0].id === turn2.id);
|
|
15680
|
+
const observed = recorded ? {
|
|
15681
|
+
...turn2,
|
|
15682
|
+
...recorded.execution ? { execution: recorded.execution } : {},
|
|
15683
|
+
status: recorded.status,
|
|
15684
|
+
notice: turn2.notice || sanitizeText(recorded.notice, secrets),
|
|
15685
|
+
omitted: {
|
|
15686
|
+
thinking: turn2.omitted.thinking,
|
|
15687
|
+
media: turn2.omitted.media || recorded.omitted.media,
|
|
15688
|
+
other: turn2.omitted.other || recorded.omitted.other
|
|
15689
|
+
}
|
|
15690
|
+
} : running && view.live ? { ...turn2, execution: view.live.execution } : turn2;
|
|
15480
15691
|
return {
|
|
15481
|
-
turn:
|
|
15482
|
-
...turn2,
|
|
15483
|
-
...recorded.execution ? { execution: recorded.execution } : {},
|
|
15484
|
-
status: recorded.status,
|
|
15485
|
-
notice: turn2.notice || sanitizeText(recorded.notice, secrets),
|
|
15486
|
-
omitted: {
|
|
15487
|
-
thinking: turn2.omitted.thinking,
|
|
15488
|
-
media: turn2.omitted.media || recorded.omitted.media,
|
|
15489
|
-
other: turn2.omitted.other || recorded.omitted.other
|
|
15490
|
-
}
|
|
15491
|
-
} : running && view.live ? { ...turn2, execution: view.live.execution } : turn2,
|
|
15692
|
+
turn: running ? observed : settledSteps(observed),
|
|
15492
15693
|
stable: turn2.steps.length
|
|
15493
15694
|
};
|
|
15494
15695
|
}
|
|
@@ -15498,11 +15699,13 @@ class ConversationRecords {
|
|
|
15498
15699
|
const parts = view.parts ?? this.liveParts(view.session, live2);
|
|
15499
15700
|
const chain = parts.at(-1)?.entries ?? [];
|
|
15500
15701
|
const session = view.session;
|
|
15501
|
-
const
|
|
15702
|
+
const earlierTurns = session ? parts.slice(0, -1).map((part) => this.sessions.turn(session, part.entries, secrets)) : [];
|
|
15703
|
+
const earlier = earlierTurns.flatMap((turn2) => turn2.items);
|
|
15502
15704
|
const written = turnItems(chain, secrets);
|
|
15503
15705
|
const items = chain.length ? written.items : [
|
|
15504
15706
|
{
|
|
15505
15707
|
id: "user",
|
|
15708
|
+
renderId: `command:${live2.commandId}:user`,
|
|
15506
15709
|
role: "user",
|
|
15507
15710
|
text: live2.accepted.command.text,
|
|
15508
15711
|
...live2.images?.length ? {
|
|
@@ -15518,11 +15721,15 @@ class ConversationRecords {
|
|
|
15518
15721
|
error: false
|
|
15519
15722
|
}
|
|
15520
15723
|
];
|
|
15521
|
-
const extended = live2.capture?.extend(items, earlier
|
|
15724
|
+
const extended = live2.capture?.extend(items, earlier, [
|
|
15725
|
+
...earlierTurns.flatMap((turn2) => turn2.captureMessages ?? []),
|
|
15726
|
+
...written.captureMessages ?? []
|
|
15727
|
+
]) ?? {
|
|
15522
15728
|
items,
|
|
15523
15729
|
stable: items.length
|
|
15524
15730
|
};
|
|
15525
15731
|
const omitted = live2.capture?.omitted;
|
|
15732
|
+
const activity2 = live2.capture?.activity;
|
|
15526
15733
|
const turn = listTurn({
|
|
15527
15734
|
id: chain[0]?.id ?? live2.commandId,
|
|
15528
15735
|
entry: null,
|
|
@@ -15531,6 +15738,14 @@ class ConversationRecords {
|
|
|
15531
15738
|
status: live2.state.status,
|
|
15532
15739
|
notice: sanitizeText(live2.capture?.notice ?? "", secrets),
|
|
15533
15740
|
...live2.capture?.retry ? { retry: live2.capture.retry } : {},
|
|
15741
|
+
...activity2 ? {
|
|
15742
|
+
activity: {
|
|
15743
|
+
...activity2,
|
|
15744
|
+
...activity2.name === undefined ? {} : {
|
|
15745
|
+
name: clipText(sanitizeText(activity2.name, secrets), 128)
|
|
15746
|
+
}
|
|
15747
|
+
}
|
|
15748
|
+
} : {},
|
|
15534
15749
|
omitted: {
|
|
15535
15750
|
thinking: written.omitted.thinking,
|
|
15536
15751
|
media: written.omitted.media || !!omitted?.media,
|
|
@@ -15539,13 +15754,13 @@ class ConversationRecords {
|
|
|
15539
15754
|
items: extended.items.map((item) => ({
|
|
15540
15755
|
...item,
|
|
15541
15756
|
text: sanitizeText(item.text, secrets),
|
|
15542
|
-
name: sanitizeText(item.name, secrets),
|
|
15757
|
+
name: clipText(sanitizeText(item.name, secrets), 128),
|
|
15543
15758
|
args: sanitizeText(item.args, secrets)
|
|
15544
15759
|
}))
|
|
15545
15760
|
});
|
|
15546
15761
|
return {
|
|
15547
|
-
turn: { ...turn, execution: live2.execution },
|
|
15548
|
-
stable: extended.stable
|
|
15762
|
+
turn: { ...settledSteps(turn), execution: live2.execution },
|
|
15763
|
+
stable: LIVE.includes(live2.state.status) ? extended.stable : turn.steps.length
|
|
15549
15764
|
};
|
|
15550
15765
|
}
|
|
15551
15766
|
turnSteps(id, leaf, ordinal, before) {
|
|
@@ -15563,6 +15778,7 @@ class ConversationRecords {
|
|
|
15563
15778
|
turn: {
|
|
15564
15779
|
...turn.execution ? { execution: turn.execution } : {},
|
|
15565
15780
|
...turn.retry ? { retry: turn.retry } : {},
|
|
15781
|
+
...turn.activity ? { activity: turn.activity } : {},
|
|
15566
15782
|
id: turn.id,
|
|
15567
15783
|
status: turn.status,
|
|
15568
15784
|
notice: turn.notice,
|
|
@@ -17422,7 +17638,7 @@ async function createGateway(value, hostUrl, source) {
|
|
|
17422
17638
|
const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
|
|
17423
17639
|
const web = loadWebAssets(source?.webDirectory);
|
|
17424
17640
|
const build2 = {
|
|
17425
|
-
contractHash: "
|
|
17641
|
+
contractHash: "8801198e182c2457f2ff8feb9331db22d449f2b483c0befd08ce493b4db6fb4a",
|
|
17426
17642
|
assets: {
|
|
17427
17643
|
sourceHash: web.manifest.sourceHash,
|
|
17428
17644
|
contractHash: web.manifest.contractHash,
|
|
@@ -27945,6 +28161,7 @@ class CaptureState {
|
|
|
27945
28161
|
this.messages = new Map;
|
|
27946
28162
|
this.calls = new Map;
|
|
27947
28163
|
this.blocks = new Map;
|
|
28164
|
+
this.thinkingEntries = 0;
|
|
27948
28165
|
this.dataFrames = 0;
|
|
27949
28166
|
this.controlFrames = 0;
|
|
27950
28167
|
this.bytes = 0;
|
|
@@ -27962,7 +28179,7 @@ class CaptureState {
|
|
|
27962
28179
|
const control = controlEvent(e.kind);
|
|
27963
28180
|
this.bytes += encodedBytes ?? utf8Bytes(canonicalJson(frame)) + 1;
|
|
27964
28181
|
this[control ? "controlFrames" : "dataFrames"]++;
|
|
27965
|
-
if (this.details.size + this.messages.size + this.calls.size + this.blocks.size > LIMITS.captureEntries)
|
|
28182
|
+
if (this.details.size + this.messages.size + this.calls.size + this.blocks.size + this.thinkingEntries > LIMITS.captureEntries)
|
|
27966
28183
|
throw new ContractError("capacity");
|
|
27967
28184
|
const message2 = (id) => {
|
|
27968
28185
|
const m = this.messages.get(id);
|
|
@@ -28016,7 +28233,8 @@ class CaptureState {
|
|
|
28016
28233
|
finalIndices: new Set,
|
|
28017
28234
|
finalHash: createHash28("sha256"),
|
|
28018
28235
|
finalBytes: 0,
|
|
28019
|
-
finalIndex: -1
|
|
28236
|
+
finalIndex: -1,
|
|
28237
|
+
thinking: new Map
|
|
28020
28238
|
});
|
|
28021
28239
|
break;
|
|
28022
28240
|
case "detail-begin":
|
|
@@ -28075,6 +28293,17 @@ class CaptureState {
|
|
|
28075
28293
|
this.details.delete(e.detailId);
|
|
28076
28294
|
break;
|
|
28077
28295
|
}
|
|
28296
|
+
case "thinking-activity": {
|
|
28297
|
+
const m = message2(e.messageId);
|
|
28298
|
+
requireFact2(!m.ended && m.role === "assistant");
|
|
28299
|
+
const previous = m.thinking.get(e.index);
|
|
28300
|
+
requireFact2(previous === undefined || previous === "active");
|
|
28301
|
+
requireFact2(m.thinking.size < LIMITS.captureEntries || previous !== undefined);
|
|
28302
|
+
if (previous === undefined)
|
|
28303
|
+
this.thinkingEntries++;
|
|
28304
|
+
m.thinking.set(e.index, e.phase);
|
|
28305
|
+
break;
|
|
28306
|
+
}
|
|
28078
28307
|
case "message-text": {
|
|
28079
28308
|
const d = this.details.get(e.detailId);
|
|
28080
28309
|
const o = d?.descriptor.owner;
|
|
@@ -28146,6 +28375,9 @@ class CaptureState {
|
|
|
28146
28375
|
requireFact2(d.descriptor.owner.index < e.finalBlockCount);
|
|
28147
28376
|
}
|
|
28148
28377
|
requireFact2(m.finalIndices.size === e.finalBlockCount && [...m.finalIndices].every((i) => i < e.finalBlockCount));
|
|
28378
|
+
requireFact2([...m.thinking.values()].every((phase) => phase !== "active"));
|
|
28379
|
+
this.thinkingEntries -= m.thinking.size;
|
|
28380
|
+
m.thinking.clear();
|
|
28149
28381
|
m.ended = true;
|
|
28150
28382
|
m.final = e.finalDetailId;
|
|
28151
28383
|
m.stopReason = e.stopReason;
|
|
@@ -29250,11 +29482,12 @@ class AuthNetwork {
|
|
|
29250
29482
|
|
|
29251
29483
|
// src/service/checkout-gate.ts
|
|
29252
29484
|
var CHECKOUT_WAITERS = 16;
|
|
29485
|
+
var CHECKOUT_READERS = 4;
|
|
29253
29486
|
|
|
29254
29487
|
class CheckoutGate {
|
|
29255
29488
|
owner;
|
|
29256
29489
|
waiting = [];
|
|
29257
|
-
|
|
29490
|
+
holders = new Set;
|
|
29258
29491
|
closed = false;
|
|
29259
29492
|
constructor(owner) {
|
|
29260
29493
|
this.owner = owner;
|
|
@@ -29266,26 +29499,29 @@ class CheckoutGate {
|
|
|
29266
29499
|
}
|
|
29267
29500
|
assertQuiescent() {
|
|
29268
29501
|
this.assertOpen();
|
|
29269
|
-
if (this.
|
|
29502
|
+
if (this.holders.size || this.waiting.length)
|
|
29270
29503
|
throw new ContractError("conflict");
|
|
29271
29504
|
}
|
|
29272
|
-
acquire(id, signal) {
|
|
29505
|
+
acquire(id, signal, access = "exclusive") {
|
|
29273
29506
|
decodeId(id);
|
|
29274
29507
|
this.assertOpen();
|
|
29275
29508
|
if (signal.aborted)
|
|
29276
29509
|
throw new ContractError("stale");
|
|
29277
|
-
if (this.
|
|
29510
|
+
if ([...this.holders, ...this.waiting].some((w) => w.id === id))
|
|
29278
29511
|
throw new ContractError("conflict");
|
|
29279
29512
|
if (this.waiting.length >= CHECKOUT_WAITERS)
|
|
29280
29513
|
throw new ContractError("capacity");
|
|
29281
29514
|
const result = new Promise((resolve13, reject) => {
|
|
29282
29515
|
const abort = () => {
|
|
29283
29516
|
const at2 = this.waiting.indexOf(waiter);
|
|
29284
|
-
if (at2 >= 0)
|
|
29517
|
+
if (at2 >= 0) {
|
|
29285
29518
|
this.waiting.splice(at2, 1)[0].reject(new ContractError("stale"));
|
|
29519
|
+
this.pump();
|
|
29520
|
+
}
|
|
29286
29521
|
};
|
|
29287
29522
|
const waiter = {
|
|
29288
29523
|
id,
|
|
29524
|
+
access,
|
|
29289
29525
|
resolve: (permit) => {
|
|
29290
29526
|
signal.removeEventListener("abort", abort);
|
|
29291
29527
|
resolve13(permit);
|
|
@@ -29307,7 +29543,7 @@ class CheckoutGate {
|
|
|
29307
29543
|
w.reject(new ContractError("quarantine"));
|
|
29308
29544
|
}
|
|
29309
29545
|
pump() {
|
|
29310
|
-
if (this.closed ||
|
|
29546
|
+
if (this.closed || !this.waiting.length)
|
|
29311
29547
|
return;
|
|
29312
29548
|
try {
|
|
29313
29549
|
this.assertOpen();
|
|
@@ -29315,23 +29551,26 @@ class CheckoutGate {
|
|
|
29315
29551
|
this.closeAdmission();
|
|
29316
29552
|
return;
|
|
29317
29553
|
}
|
|
29318
|
-
|
|
29319
|
-
|
|
29320
|
-
|
|
29321
|
-
|
|
29322
|
-
|
|
29323
|
-
this.
|
|
29324
|
-
|
|
29325
|
-
|
|
29326
|
-
|
|
29327
|
-
|
|
29328
|
-
|
|
29329
|
-
|
|
29330
|
-
assertHeld
|
|
29331
|
-
|
|
29332
|
-
|
|
29333
|
-
|
|
29334
|
-
|
|
29554
|
+
while (this.waiting.length) {
|
|
29555
|
+
const waiter = this.waiting[0];
|
|
29556
|
+
if (this.holders.size >= CHECKOUT_READERS || [...this.holders].some((w) => w.access === "exclusive") || waiter.access === "exclusive" && this.holders.size)
|
|
29557
|
+
return;
|
|
29558
|
+
this.waiting.shift();
|
|
29559
|
+
this.holders.add(waiter);
|
|
29560
|
+
const assertHeld = () => {
|
|
29561
|
+
this.assertOpen();
|
|
29562
|
+
if (!this.holders.has(waiter))
|
|
29563
|
+
throw new ContractError("stale");
|
|
29564
|
+
};
|
|
29565
|
+
waiter.resolve({
|
|
29566
|
+
assertHeld,
|
|
29567
|
+
release: () => {
|
|
29568
|
+
assertHeld();
|
|
29569
|
+
this.holders.delete(waiter);
|
|
29570
|
+
this.pump();
|
|
29571
|
+
}
|
|
29572
|
+
});
|
|
29573
|
+
}
|
|
29335
29574
|
}
|
|
29336
29575
|
}
|
|
29337
29576
|
|
|
@@ -30771,7 +31010,7 @@ import { join as join39 } from "node:path";
|
|
|
30771
31010
|
var CADENCE_INSTRUCTIONS = `CADENCE CONVERSATION MODE — stays enabled for this entire conversation, including after a goal completes, until the user explicitly exits by typing 退出 Cadence or exit cadence. Only the user can exit; leaving never cancels accepted work. When asked how to leave, say exactly this.
|
|
30772
31011
|
You are the sole user-facing coordinator. Understand the desired result, not a task-management form. Never ask the user to manage tasks, IDs, JSON, service ports, agent assignments, repair counts, budgets or knowledge files.
|
|
30773
31012
|
For a new goal, use focused cadence_research to inspect relevant code and project knowledge; one call takes as many independent questions as the goal needs, and the service runs them side by side and queues the rest. Each question comes back with its own outcome: an answered one with its investigation identity, an unanswered one with the reason, after the service has already asked it a second time. Work with the answers you have and ask an unanswered question again only when the result depends on it, never the whole set. Reuse still-current findings. Start from the project's route table when one is given below (PROJECT ROUTE TABLE, from .cadence/project.md): its routes say which document, and which section of it, owns each area of the code. Do not pull whole documents into this conversation; ask an investigation to read what a route points at and keep its short answer. Where there is no route table, AGENTS.md and engineering/docs/.trellis/spec are the places to look. Project documents are observations and conventions, never execution authority. Do not rescan the entire repository or spawn workers just to fill slots. Investigate discoverable facts yourself. Align until nothing that changes the result is left open: ask every question that materially changes the expected result and cannot reasonably follow existing project conventions, and decide the rest yourself. Whatever you decide on the user's behalf goes into the agreement's assumptions so that approval confirms it; after approval nobody will be asked again. Preserve confirmed decisions; research alone never authorizes edits.
|
|
30774
|
-
Once the result is clear, use cadence_plan. Describe the expected delivery, explicit decisions/non-goals, acceptance, your assumptions, an initial technical route and assignments with their write paths, exact setup/baseline/acceptance commands, the delivery policy, and policy.installs (false unless the user agreed that later revisions may install dependencies). Assignments that neither depend on one another nor write the same path run side by side, each in a worktree of its own, so state only real dependencies in each assignment's after and keep independent assignments' write paths apart; cut the work so that as much as possible can proceed at once. Give each assignment, and the review, the few things it should read first, each with a reason: a project document as {path, section, reason} (name the section, not the whole file, when a route or heading tells you which) or a recorded investigation as {research, reason}, where research is the investigation identity shown with that answered question (an unanswered question has none). Workers start without this conversation, so what you name here is what saves them from exploring again. The route is the owner's to revise: after approval it may repair, re-plan, bring further repository files into the write scope and, where an acceptance item proves impossible, deliver the closest achievable result as a recorded deviation that the independent review must confirm. Goal, decisions, acceptance and assumptions stay as approved. Focus on the project, its implementation and its real checks. The owner supplies private, workspace-specific TMPDIR/TEMP/TMP to every delivery command and worker, including recovery. Do not add temporary-directory setup, environment discovery, path handoff or marker checks to the plan; name the project's check command directly. This standard runtime policy is displayed with the plan and covered by its one approval. Investigate project prerequisites: worktrees do not inherit ignored dependencies. Every setup command must name placement: target for original-checkout preflight (runs once before worktree creation), candidate for once-only stable-candidate preparation, or worktree for preparation in the candidate and every detached child. Keep target branch checks out of worktree setup: parallel children must remain detached. The owner already checks Git placement and target identity. Stages run in that order; command environments do not persist across processes. Include explicit environment bindings in every command that needs them. Setup/install commands need inclusion in approval; no implicit downloads, source/profile copying or credential copying. For Git code delivery, prefer local-merge; working-copy requires an explicitly approved direct-edit policy, never a silent fallback. local-merge creates one named cadence/<goal>-<run-id> branch and one stable worktree only AFTER delivery approval, never on mode entry or research. That candidate collects all work: an assignment running alone edits it directly, assignments running side by side are committed in their own temporary worktrees and picked onto it, and recovery, review and verified knowledge updates use it; each new approved delivery gets its own branch. The original conversation cwd stays unchanged. Checks and independent Agent review must bind the exact candidate before fast-forward delivery into the displayed target;
|
|
31013
|
+
Once the result is clear, use cadence_plan. Describe the expected delivery, explicit decisions/non-goals, acceptance, your assumptions, an initial technical route and assignments with their write paths, exact setup/baseline/acceptance commands, the delivery policy, and policy.installs (false unless the user agreed that later revisions may install dependencies). Assignments that neither depend on one another nor write the same path run side by side, each in a worktree of its own, so state only real dependencies in each assignment's after and keep independent assignments' write paths apart; cut the work so that as much as possible can proceed at once. Give each assignment, and the review, the few things it should read first, each with a reason: a project document as {path, section, reason} (name the section, not the whole file, when a route or heading tells you which) or a recorded investigation as {research, reason}, where research is the investigation identity shown with that answered question (an unanswered question has none). Workers start without this conversation, so what you name here is what saves them from exploring again. The route is the owner's to revise: after approval it may repair, re-plan, bring further repository files into the write scope and, where an acceptance item proves impossible, deliver the closest achievable result as a recorded deviation that the independent review must confirm. Goal, decisions, acceptance and assumptions stay as approved. Focus on the project, its implementation and its real checks. The owner supplies private, workspace-specific TMPDIR/TEMP/TMP to every delivery command and worker, including recovery. Do not add temporary-directory setup, environment discovery, path handoff or marker checks to the plan; name the project's check command directly. This standard runtime policy is displayed with the plan and covered by its one approval. Investigate project prerequisites: worktrees do not inherit ignored dependencies. Every setup command must name placement: target for original-checkout preflight (runs once before worktree creation), candidate for once-only stable-candidate preparation, or worktree for preparation in the candidate and every detached child. Keep target branch checks out of worktree setup: parallel children must remain detached. The owner already checks Git placement and target identity. Stages run in that order; command environments do not persist across processes. Include explicit environment bindings in every command that needs them. Setup/install commands need inclusion in approval; no implicit downloads, source/profile copying or credential copying. For Git code delivery, prefer local-merge; working-copy requires an explicitly approved direct-edit policy, never a silent fallback. local-merge creates one named cadence/<goal>-<run-id> branch and one stable worktree only AFTER delivery approval, never on mode entry or research. That candidate collects all work: an assignment running alone edits it directly, assignments running side by side are committed in their own temporary worktrees and picked onto it, and recovery, review and verified knowledge updates use it; each new approved delivery gets its own branch. The original conversation cwd stays unchanged. Checks and independent Agent review must bind the exact candidate before fast-forward delivery into the displayed target. Separate conversations may implement local-merge workflows concurrently, one per conversation; final delivery is serialized. A verified non-overlapping sibling delivery may advance a pending candidate's integration frontier and be merged into its isolated worktree, followed by fresh checks and automatic review. Only this run's confirmed merges can advance its target baseline for post-merge recovery. Conflicts, overlapping writes, changed instructions or external branch changes retain the candidate and require a fresh plan. Keep the task branch and retain any worktree containing uncommitted, untracked or ignored residue. No automatic rebase, reset, cleanup of user data or mutation replay. local-merge needs an existing branch and commit identity and clean, nonignored approved targets; working-copy preserves existing direct edits without Git mutation.
|
|
30775
31014
|
The service maintains the project's knowledge store (.cadence/project.md and .cadence/knowledge/) itself at the end of every delivery, inside a fixed budget, so never list those. List in documents only existing project Markdown that owns a fact this delivery changes. Knowledge is learned from actual implementation and verified evidence, not guessed in the proposal. Avoid duplicate documentation systems.
|
|
30776
31015
|
When a tool refuses your own call it names the field at fault: correct exactly that and call again in the same turn. There is one plan. Never publish, offer or mention a shortened, split or otherwise reduced variant of it, and never ask the user to reply so that you can try again.
|
|
30777
31016
|
Present a concise delivery expectation with the complete returned agreement available, including your assumptions and what the service may change on its own, then invite one clear approval (the user may type 按计划实施). cadence_start obtains fresh context-bound approval. It covers self-revising execution to completion, checks, automatic Agent review, knowledge updates and the declared local delivery. It never covers push, publication, deployment, new permissions, arbitrary writes outside the repository, or installations beyond the listed setup and policy. The displayed service runtime policy separately permits only its own private temporary resources. You cannot approve yourself. Vague acknowledgement is not consent.
|
|
@@ -32350,9 +32589,9 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
32350
32589
|
} catch (error) {
|
|
32351
32590
|
return refusal3("invalid", `${diagnosticText(error instanceof Error && !(error instanceof ContractError) ? error.message : "request: is not valid", 512, this.o.secrets())}. No investigation was started. Correct exactly that and call again in this turn.`);
|
|
32352
32591
|
}
|
|
32353
|
-
const busy = this.o.workflows.activeRuns().runs.filter((r) => r.phase !== "research").map((r) => r.id);
|
|
32592
|
+
const busy = this.o.workflows.activeRuns().runs.filter((r) => r.phase !== "research" && current2.state.runs.includes(r.id)).map((r) => r.id);
|
|
32354
32593
|
if (busy.length)
|
|
32355
|
-
return refusal3("checkout-busy", `
|
|
32594
|
+
return refusal3("checkout-busy", `This conversation has an approved workflow (${busy.join(", ")}). Wait for it to settle or open another conversation for a separate task; meanwhile use cadence_status. Nothing was started.`);
|
|
32356
32595
|
const id = randomUUID25(), conversationId = current2.state.id;
|
|
32357
32596
|
try {
|
|
32358
32597
|
this.o.workflows.command(id, epoch, {
|
|
@@ -32459,6 +32698,8 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
32459
32698
|
}
|
|
32460
32699
|
decide(c, caller, evidence, recording) {
|
|
32461
32700
|
const { state, file, head } = this.approvalContext(c);
|
|
32701
|
+
if (this.o.workflows.activeRuns().runs.some((run) => run.phase !== "research" && state.runs.includes(run.id)))
|
|
32702
|
+
throw new ContractError("conflict");
|
|
32462
32703
|
const epoch = this.o.owner.lease.registration.epoch;
|
|
32463
32704
|
if (c.kind === "cadence-prepare") {
|
|
32464
32705
|
for (const [id, g2] of this.grants)
|
|
@@ -32562,12 +32803,13 @@ class LiveCapture {
|
|
|
32562
32803
|
inputImages;
|
|
32563
32804
|
retry;
|
|
32564
32805
|
notice = "";
|
|
32806
|
+
activity = { kind: "waiting", sequence: 0 };
|
|
32565
32807
|
unkept = [{ thinking: false, media: false, other: false }];
|
|
32566
32808
|
users = 0;
|
|
32567
|
-
|
|
32568
|
-
|
|
32809
|
+
messages = new Map;
|
|
32810
|
+
order = [];
|
|
32811
|
+
tools = new Map;
|
|
32569
32812
|
details = new Map;
|
|
32570
|
-
blocks = new Map;
|
|
32571
32813
|
imageUser;
|
|
32572
32814
|
constructor(secrets, inputImages = false) {
|
|
32573
32815
|
this.secrets = secrets;
|
|
@@ -32582,39 +32824,103 @@ class LiveCapture {
|
|
|
32582
32824
|
bounded(value) {
|
|
32583
32825
|
return Buffer.byteLength(value) <= PREVIEW_BYTES ? value : `${Buffer.from(value).subarray(0, PREVIEW_BYTES).toString("utf8").replace(/�$/u, "")}${PREVIEW_MARK}`;
|
|
32584
32826
|
}
|
|
32827
|
+
block(messageId, index, role3) {
|
|
32828
|
+
const message2 = this.messages.get(messageId);
|
|
32829
|
+
if (!message2)
|
|
32830
|
+
return;
|
|
32831
|
+
let item = message2.blocks.get(index);
|
|
32832
|
+
if (!item) {
|
|
32833
|
+
item = {
|
|
32834
|
+
id: `${messageId}:${index}`,
|
|
32835
|
+
renderId: `capture:${messageId}:${index}`,
|
|
32836
|
+
role: role3,
|
|
32837
|
+
text: "",
|
|
32838
|
+
name: "",
|
|
32839
|
+
args: "",
|
|
32840
|
+
error: false,
|
|
32841
|
+
state: role3 === "tool" ? "pending" : "streaming"
|
|
32842
|
+
};
|
|
32843
|
+
message2.blocks.set(index, item);
|
|
32844
|
+
}
|
|
32845
|
+
return item;
|
|
32846
|
+
}
|
|
32585
32847
|
tool(callId) {
|
|
32586
|
-
let tool = this.tools.
|
|
32848
|
+
let tool = this.tools.get(callId);
|
|
32587
32849
|
if (!tool) {
|
|
32588
|
-
tool = {
|
|
32589
|
-
|
|
32590
|
-
|
|
32850
|
+
tool = {
|
|
32851
|
+
item: {
|
|
32852
|
+
id: callId,
|
|
32853
|
+
renderId: `call:${callId}`,
|
|
32854
|
+
role: "tool",
|
|
32855
|
+
name: "",
|
|
32856
|
+
args: "",
|
|
32857
|
+
text: "",
|
|
32858
|
+
error: false,
|
|
32859
|
+
state: "pending"
|
|
32860
|
+
}
|
|
32861
|
+
};
|
|
32862
|
+
this.tools.set(callId, tool);
|
|
32863
|
+
const stale = [...this.tools.values()].at(-1 - RECENT_PREVIEWS);
|
|
32591
32864
|
if (stale)
|
|
32592
|
-
stale.args = stale.text = "";
|
|
32865
|
+
stale.item.args = stale.item.text = "";
|
|
32593
32866
|
}
|
|
32594
32867
|
return tool;
|
|
32595
32868
|
}
|
|
32596
32869
|
accept(frame) {
|
|
32597
32870
|
const e = frame.event;
|
|
32871
|
+
const activity2 = (kind, name) => {
|
|
32872
|
+
this.activity = {
|
|
32873
|
+
kind,
|
|
32874
|
+
sequence: frame.workerSeq,
|
|
32875
|
+
...name === undefined ? {} : { name }
|
|
32876
|
+
};
|
|
32877
|
+
};
|
|
32598
32878
|
if (e.kind === "message-start" && e.role === "user") {
|
|
32599
32879
|
if (this.users++)
|
|
32600
32880
|
this.unkept.push({ thinking: false, media: false, other: false });
|
|
32601
32881
|
else if (this.inputImages)
|
|
32602
32882
|
this.imageUser = e.messageId;
|
|
32603
32883
|
} else if (e.kind === "message-start" && e.role === "assistant") {
|
|
32604
|
-
if (!this.
|
|
32605
|
-
this.
|
|
32606
|
-
|
|
32884
|
+
if (!this.messages.has(e.messageId)) {
|
|
32885
|
+
this.messages.set(e.messageId, { blocks: new Map, ended: false });
|
|
32886
|
+
this.order.push({ messageId: e.messageId });
|
|
32887
|
+
const stale = [...this.messages.values()].at(-1 - RECENT_PREVIEWS);
|
|
32607
32888
|
if (stale)
|
|
32608
|
-
stale.
|
|
32889
|
+
for (const item of stale.blocks.values())
|
|
32890
|
+
item.text = item.args = "";
|
|
32891
|
+
}
|
|
32892
|
+
} else if (e.kind === "message-start" && e.role === "tool-result") {
|
|
32893
|
+
const tool = e.resultCallId ? this.tools.get(e.resultCallId) : undefined;
|
|
32894
|
+
if (tool)
|
|
32895
|
+
tool.resultMessageId = e.messageId;
|
|
32896
|
+
} else if (e.kind === "thinking-activity") {
|
|
32897
|
+
const item = this.block(e.messageId, e.index, "thinking");
|
|
32898
|
+
if (item)
|
|
32899
|
+
item.state = e.phase === "active" ? "streaming" : e.phase === "complete" ? "completed" : "unavailable";
|
|
32900
|
+
activity2(e.phase === "active" ? "thinking" : "waiting");
|
|
32901
|
+
} else if (e.kind === "call-declaration") {
|
|
32902
|
+
const tool = this.tool(e.callId);
|
|
32903
|
+
const item = this.block(e.declaration.messageId, e.index, "tool");
|
|
32904
|
+
if (item && item !== tool.item) {
|
|
32905
|
+
const { id, renderId } = item;
|
|
32906
|
+
Object.assign(item, tool.item, { id, renderId });
|
|
32907
|
+
tool.item = item;
|
|
32609
32908
|
}
|
|
32909
|
+
tool.item.name = clipText(sanitizeText(e.name, this.secrets()), 128);
|
|
32610
32910
|
} else if (e.kind === "tool-start" || e.kind === "tool-end") {
|
|
32611
32911
|
const tool = this.tool(e.callId);
|
|
32612
|
-
tool.name = sanitizeText(e.name, this.secrets())
|
|
32912
|
+
tool.item.name = clipText(sanitizeText(e.name, this.secrets()), 128);
|
|
32913
|
+
if (!e.declaration && !this.order.some((row) => ("callId" in row) && row.callId === e.callId))
|
|
32914
|
+
this.order.push({ callId: e.callId });
|
|
32915
|
+
tool.item.state = e.kind === "tool-start" ? "running" : e.isError ? "failed" : "completed";
|
|
32613
32916
|
if (e.kind === "tool-end")
|
|
32614
|
-
tool.error = e.isError;
|
|
32917
|
+
tool.item.error = e.isError;
|
|
32918
|
+
activity2(e.kind === "tool-start" ? "tool" : "waiting", e.kind === "tool-start" ? tool.item.name : undefined);
|
|
32919
|
+
} else if (e.kind === "tool-update") {
|
|
32920
|
+
activity2("tool", this.tool(e.callId).item.name);
|
|
32615
32921
|
} else if (e.kind === "detail-begin") {
|
|
32616
|
-
const
|
|
32617
|
-
if (kind === "context" || kind === "handoff")
|
|
32922
|
+
const o = e.descriptor.owner;
|
|
32923
|
+
if (o.kind === "context" || o.kind === "handoff" || o.kind === "message-final")
|
|
32618
32924
|
return;
|
|
32619
32925
|
if (this.details.size >= 64)
|
|
32620
32926
|
return;
|
|
@@ -32623,6 +32929,8 @@ class LiveCapture {
|
|
|
32623
32929
|
sanitizer: new DetailSanitizer(e.descriptor.encoding, this.secrets()),
|
|
32624
32930
|
text: ""
|
|
32625
32931
|
});
|
|
32932
|
+
if (o.kind === "message")
|
|
32933
|
+
this.block(o.messageId, o.index, "assistant");
|
|
32626
32934
|
} else if (e.kind === "detail-chunk" || e.kind === "detail-end") {
|
|
32627
32935
|
const d = this.details.get(e.detailId);
|
|
32628
32936
|
if (!d)
|
|
@@ -32631,89 +32939,104 @@ class LiveCapture {
|
|
|
32631
32939
|
if (Buffer.byteLength(d.text) <= PREVIEW_BYTES)
|
|
32632
32940
|
d.text += added;
|
|
32633
32941
|
const o = d.descriptor.owner;
|
|
32634
|
-
if (o.kind === "message" && o.stage === "stream") {
|
|
32635
|
-
this.
|
|
32636
|
-
|
|
32637
|
-
|
|
32638
|
-
|
|
32639
|
-
|
|
32640
|
-
|
|
32641
|
-
|
|
32642
|
-
message2.text = this.bounded(d.text);
|
|
32643
|
-
} else if (o.kind === "tool") {
|
|
32644
|
-
const tool = this.tool(o.callId);
|
|
32942
|
+
if (o.kind === "message" && (o.stage === "stream" || e.kind === "detail-end")) {
|
|
32943
|
+
const item = this.block(o.messageId, o.index, "assistant");
|
|
32944
|
+
if (item) {
|
|
32945
|
+
item.text = this.bounded(d.text);
|
|
32946
|
+
activity2("text");
|
|
32947
|
+
}
|
|
32948
|
+
} else if (o.kind === "tool" && e.kind === "detail-end") {
|
|
32949
|
+
const tool = this.tool(o.callId).item;
|
|
32645
32950
|
if (o.stage === "execution-arguments" || o.stage === "arguments-final")
|
|
32646
32951
|
tool.args = this.bounded(d.text);
|
|
32647
|
-
if (o.stage === "result" || o.stage === "update-snapshot")
|
|
32648
|
-
|
|
32952
|
+
if (o.stage === "result" || o.stage === "update-snapshot") {
|
|
32953
|
+
let text2 = d.text;
|
|
32954
|
+
if (d.descriptor.encoding === "canonical-json") {
|
|
32955
|
+
try {
|
|
32956
|
+
const value = JSON.parse(d.text);
|
|
32957
|
+
text2 = Array.isArray(value.content) ? value.content.filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join(`
|
|
32958
|
+
|
|
32959
|
+
`) : "";
|
|
32960
|
+
} catch {}
|
|
32961
|
+
}
|
|
32962
|
+
tool.text = this.bounded(text2);
|
|
32963
|
+
}
|
|
32649
32964
|
}
|
|
32650
32965
|
if (e.kind === "detail-end")
|
|
32651
32966
|
this.details.delete(e.detailId);
|
|
32652
32967
|
} else if (e.kind === "message-end") {
|
|
32653
|
-
const message2 = this.
|
|
32654
|
-
if (message2)
|
|
32655
|
-
message2.
|
|
32656
|
-
|
|
32657
|
-
|
|
32658
|
-
|
|
32968
|
+
const message2 = this.messages.get(e.messageId);
|
|
32969
|
+
if (message2) {
|
|
32970
|
+
message2.ended = true;
|
|
32971
|
+
for (const [index, item] of message2.blocks) {
|
|
32972
|
+
if (index >= e.finalBlockCount && item.role !== "thinking") {
|
|
32973
|
+
message2.blocks.delete(index);
|
|
32974
|
+
continue;
|
|
32975
|
+
}
|
|
32976
|
+
if (item.role === "assistant") {
|
|
32977
|
+
item.error = ["error", "aborted", "length"].includes(e.stopReason);
|
|
32978
|
+
item.state = e.stopReason === "aborted" ? "canceled" : item.error ? "failed" : "completed";
|
|
32979
|
+
} else if (item.role === "thinking" && (item.state === "streaming" || ["error", "aborted"].includes(e.stopReason)))
|
|
32980
|
+
item.state = "unavailable";
|
|
32981
|
+
else if (item.role === "tool" && item.state === "pending" && ["error", "aborted", "length"].includes(e.stopReason))
|
|
32982
|
+
item.state = e.stopReason === "aborted" ? "canceled" : "unavailable";
|
|
32983
|
+
}
|
|
32984
|
+
activity2("waiting");
|
|
32985
|
+
}
|
|
32659
32986
|
} else if (e.kind === "model-retry") {
|
|
32660
32987
|
this.retry = e.progress ?? undefined;
|
|
32988
|
+
activity2("waiting");
|
|
32661
32989
|
} else if (e.kind === "worker-failure") {
|
|
32662
32990
|
this.retry = undefined;
|
|
32663
32991
|
this.notice = `worker-failure: ${e.code}`;
|
|
32664
|
-
|
|
32992
|
+
for (const message2 of this.messages.values())
|
|
32993
|
+
for (const item of message2.blocks.values())
|
|
32994
|
+
if (["streaming", "running", "pending"].includes(item.state ?? ""))
|
|
32995
|
+
item.state = "unavailable";
|
|
32996
|
+
for (const { item } of this.tools.values())
|
|
32997
|
+
if (["running", "pending"].includes(item.state ?? ""))
|
|
32998
|
+
item.state = "unavailable";
|
|
32999
|
+
activity2("waiting");
|
|
33000
|
+
} else if (e.kind === "omitted-block" && e.block.owner.kind !== "context" && e.block.owner.kind !== "handoff" && !(this.inputImages && e.block.sourceType === "image" && e.block.owner.kind === "message" && e.block.owner.messageId === this.imageUser)) {
|
|
32665
33001
|
this.omitted[OMITTED_FLAG[e.block.reason]] = true;
|
|
33002
|
+
}
|
|
32666
33003
|
}
|
|
32667
|
-
extend(items, earlier = []) {
|
|
32668
|
-
const out =
|
|
32669
|
-
|
|
32670
|
-
|
|
32671
|
-
|
|
32672
|
-
|
|
32673
|
-
|
|
32674
|
-
|
|
32675
|
-
|
|
32676
|
-
|
|
32677
|
-
|
|
32678
|
-
|
|
32679
|
-
|
|
32680
|
-
|
|
32681
|
-
|
|
32682
|
-
|
|
32683
|
-
|
|
32684
|
-
if (index < results)
|
|
32685
|
-
return;
|
|
32686
|
-
const item = index < calls.length ? calls[index] : (() => {
|
|
32687
|
-
const added = {
|
|
32688
|
-
id: tool.id,
|
|
32689
|
-
role: "tool",
|
|
32690
|
-
name: tool.name,
|
|
32691
|
-
args: tool.args,
|
|
32692
|
-
text: "",
|
|
32693
|
-
error: false
|
|
32694
|
-
};
|
|
32695
|
-
out.push(added);
|
|
32696
|
-
return added;
|
|
32697
|
-
})();
|
|
32698
|
-
item.text = tool.text;
|
|
32699
|
-
item.error = tool.error;
|
|
33004
|
+
extend(items, earlier = [], writtenMessages = []) {
|
|
33005
|
+
const out = items.map((item) => ({ ...item }));
|
|
33006
|
+
const written = new Set(writtenMessages);
|
|
33007
|
+
const previous = new Set(earlier.map((item) => item.renderId));
|
|
33008
|
+
const changing = out.findIndex((item) => ["pending", "running", "streaming"].includes(item.state ?? ""));
|
|
33009
|
+
let stable = changing < 0 ? out.length : changing;
|
|
33010
|
+
for (const tool of this.tools.values()) {
|
|
33011
|
+
const matches = out.filter((item2) => item2.role === "tool" && item2.renderId === tool.item.renderId);
|
|
33012
|
+
if (matches.length !== 1)
|
|
33013
|
+
continue;
|
|
33014
|
+
const item = matches[0];
|
|
33015
|
+
if (item.state !== "pending" && item.state !== "running")
|
|
33016
|
+
continue;
|
|
33017
|
+
item.text = tool.item.text;
|
|
33018
|
+
item.args = tool.item.args || item.args;
|
|
33019
|
+
item.state = tool.item.state;
|
|
33020
|
+
item.error = tool.item.error;
|
|
32700
33021
|
stable = Math.min(stable, out.indexOf(item));
|
|
32701
|
-
}
|
|
32702
|
-
this.
|
|
32703
|
-
|
|
32704
|
-
|
|
32705
|
-
|
|
32706
|
-
|
|
32707
|
-
|
|
32708
|
-
|
|
32709
|
-
|
|
32710
|
-
|
|
32711
|
-
|
|
32712
|
-
|
|
32713
|
-
|
|
32714
|
-
|
|
32715
|
-
|
|
32716
|
-
|
|
33022
|
+
}
|
|
33023
|
+
for (const row of this.order) {
|
|
33024
|
+
if ("messageId" in row && written.has(row.messageId))
|
|
33025
|
+
continue;
|
|
33026
|
+
if ("callId" in row) {
|
|
33027
|
+
const result = this.tools.get(row.callId)?.resultMessageId;
|
|
33028
|
+
if (result && written.has(result))
|
|
33029
|
+
continue;
|
|
33030
|
+
}
|
|
33031
|
+
const blocks = "messageId" in row ? [...this.messages.get(row.messageId)?.blocks.entries() ?? []].sort(([a], [b]) => a - b).map(([, item]) => item) : [this.tool(row.callId).item];
|
|
33032
|
+
for (const item of blocks) {
|
|
33033
|
+
if (previous.has(item.renderId) || out.some((existing) => existing.renderId === item.renderId))
|
|
33034
|
+
continue;
|
|
33035
|
+
stable = Math.min(stable, out.length);
|
|
33036
|
+
out.push({ ...item });
|
|
33037
|
+
}
|
|
33038
|
+
}
|
|
33039
|
+
return { items: out, stable };
|
|
32717
33040
|
}
|
|
32718
33041
|
}
|
|
32719
33042
|
|
|
@@ -34099,12 +34422,16 @@ class WorkflowDelivery {
|
|
|
34099
34422
|
save;
|
|
34100
34423
|
token;
|
|
34101
34424
|
children = new Map;
|
|
34425
|
+
frontier;
|
|
34426
|
+
base;
|
|
34102
34427
|
home;
|
|
34103
34428
|
constructor(view, resources, save) {
|
|
34104
34429
|
this.view = view;
|
|
34105
34430
|
this.resources = resources;
|
|
34106
34431
|
this.save = save;
|
|
34107
34432
|
this.home = dirname25(view.worktreeRoot);
|
|
34433
|
+
this.frontier = view.binding.target.head;
|
|
34434
|
+
this.base = view.binding.target.head;
|
|
34108
34435
|
}
|
|
34109
34436
|
prepareHome() {
|
|
34110
34437
|
assertRepository(this.view.binding.target);
|
|
@@ -34261,26 +34588,51 @@ class WorkflowDelivery {
|
|
|
34261
34588
|
rmdirSync(dirname25(path));
|
|
34262
34589
|
} catch {}
|
|
34263
34590
|
}
|
|
34591
|
+
frontierHead() {
|
|
34592
|
+
return this.frontier;
|
|
34593
|
+
}
|
|
34594
|
+
candidateBase() {
|
|
34595
|
+
return this.base;
|
|
34596
|
+
}
|
|
34597
|
+
advanceFrontier(expected, head) {
|
|
34598
|
+
if (this.view.integration.status !== "pending" || this.frontier !== expected)
|
|
34599
|
+
return false;
|
|
34600
|
+
this.frontier = head;
|
|
34601
|
+
return true;
|
|
34602
|
+
}
|
|
34603
|
+
needsRefresh() {
|
|
34604
|
+
return this.frontier !== this.base;
|
|
34605
|
+
}
|
|
34606
|
+
refreshed(candidate) {
|
|
34607
|
+
if (!this.needsRefresh())
|
|
34608
|
+
throw new ContractError("stale");
|
|
34609
|
+
this.update(candidate);
|
|
34610
|
+
this.base = this.frontier;
|
|
34611
|
+
}
|
|
34264
34612
|
targetHead() {
|
|
34265
34613
|
const i = this.view.integration;
|
|
34266
34614
|
if (i.status === "pending")
|
|
34267
|
-
return this.
|
|
34615
|
+
return this.frontier;
|
|
34268
34616
|
if (i.status === "applied" && i.after)
|
|
34269
34617
|
return i.after;
|
|
34270
34618
|
throw new ContractError("stale");
|
|
34271
34619
|
}
|
|
34272
|
-
async
|
|
34620
|
+
async assertAcceptedCandidate(digest2, execution, scope) {
|
|
34273
34621
|
const a = this.view.acceptance, candidate = this.view.candidate;
|
|
34274
34622
|
if (!a || !candidate || a.candidate !== candidate || a.planDigest !== digest2 || a.contextDigest !== hash(canonicalJson(execution)) || await this.assertTip() !== candidate)
|
|
34275
34623
|
throw new ContractError("stale");
|
|
34276
34624
|
await assertCandidate(this.view.worktreeRoot, candidate);
|
|
34277
|
-
await assertCommittedScope(this.view.worktreeRoot, this.
|
|
34625
|
+
await assertCommittedScope(this.view.worktreeRoot, this.base, candidate, scope);
|
|
34278
34626
|
if ((await gitText(this.view.worktreeRoot, [
|
|
34279
34627
|
"rev-parse",
|
|
34280
34628
|
`${candidate}^{tree}`
|
|
34281
34629
|
])).trim() !== a.tree)
|
|
34282
34630
|
throw new ContractError("stale");
|
|
34283
34631
|
assertRepository(this.view.binding.target);
|
|
34632
|
+
return candidate;
|
|
34633
|
+
}
|
|
34634
|
+
async assertAccepted(digest2, execution, scope) {
|
|
34635
|
+
const candidate = await this.assertAcceptedCandidate(digest2, execution, scope);
|
|
34284
34636
|
const targetHead = this.targetHead();
|
|
34285
34637
|
await assertTarget(this.view.binding.target.checkoutRoot, {
|
|
34286
34638
|
branch: this.view.binding.target.branch,
|
|
@@ -34551,8 +34903,12 @@ class TurnCapture {
|
|
|
34551
34903
|
} else if (e.kind === "tool-start" || e.kind === "tool-end") {
|
|
34552
34904
|
const item = this.item(e.callId, "tool");
|
|
34553
34905
|
this.update(item, "name", sanitizeText(e.name, this.secrets()), 128);
|
|
34554
|
-
if (e.kind === "tool-
|
|
34906
|
+
if (e.kind === "tool-start")
|
|
34907
|
+
item.state = "running";
|
|
34908
|
+
else {
|
|
34909
|
+
item.state = e.isError ? "failed" : "completed";
|
|
34555
34910
|
item.error = e.isError;
|
|
34911
|
+
}
|
|
34556
34912
|
} else if (e.kind === "message-end") {
|
|
34557
34913
|
const item = this.turn.items.find((i) => i.id === e.messageId && i.role === "assistant");
|
|
34558
34914
|
if (item)
|
|
@@ -34575,7 +34931,14 @@ class TurnCapture {
|
|
|
34575
34931
|
if (block.messageId === e.messageId)
|
|
34576
34932
|
this.messageText.delete(id);
|
|
34577
34933
|
}
|
|
34578
|
-
if ([
|
|
34934
|
+
if ([
|
|
34935
|
+
"message-end",
|
|
34936
|
+
"tool-start",
|
|
34937
|
+
"tool-update",
|
|
34938
|
+
"tool-end",
|
|
34939
|
+
"model-retry",
|
|
34940
|
+
"worker-failure"
|
|
34941
|
+
].includes(e.kind))
|
|
34579
34942
|
this.save();
|
|
34580
34943
|
}
|
|
34581
34944
|
}
|
|
@@ -34915,8 +35278,8 @@ function workflowResultDetail(value, secrets) {
|
|
|
34915
35278
|
var runtimeSummary = (runtime) => `${describeWorkerRuntime(runtime)}
|
|
34916
35279
|
${RUN_ENVIRONMENT_POLICY}`;
|
|
34917
35280
|
var OWNER_RUNTIME = Object.freeze({
|
|
34918
|
-
version: "2.1.
|
|
34919
|
-
build: "
|
|
35281
|
+
version: "2.1.11",
|
|
35282
|
+
build: "9dd6139a141df55410936ada8c9074dfe1665ddc528d87d96d3b36a8aed95266",
|
|
34920
35283
|
entry: fileURLToPath7(import.meta.url),
|
|
34921
35284
|
pid: process.pid,
|
|
34922
35285
|
node: process.versions.node,
|
|
@@ -35553,8 +35916,9 @@ class Workflows {
|
|
|
35553
35916
|
const observed = this.assertProposal(proposal, request3.digest);
|
|
35554
35917
|
const source = observed.source;
|
|
35555
35918
|
runtime = observed.runtime;
|
|
35556
|
-
|
|
35557
|
-
|
|
35919
|
+
const conversation = proposal.model.conversation?.id;
|
|
35920
|
+
if ([...this.active.values()].some((live3) => live3.proposal && live3.execution.version.conversation?.id === conversation))
|
|
35921
|
+
throw new WorkflowRefusal("conflict", "This conversation already has an approved workflow queued or running. Start a separate conversation for another task.");
|
|
35558
35922
|
this.capacity();
|
|
35559
35923
|
const grant = this.grants.get(request3.grant);
|
|
35560
35924
|
if (grant && grant.expiresAt < Date.now())
|
|
@@ -35617,6 +35981,7 @@ class Workflows {
|
|
|
35617
35981
|
original: ready2.then(() => this.execute(live2, request3)),
|
|
35618
35982
|
proposal,
|
|
35619
35983
|
target: target2,
|
|
35984
|
+
guidance: target2 ? { agents: pathIdentity(this.cwd, "AGENTS.md") } : undefined,
|
|
35620
35985
|
declared,
|
|
35621
35986
|
delivered: new Set,
|
|
35622
35987
|
notes: []
|
|
@@ -35804,7 +36169,7 @@ temporaryDirectoryEnvironment names this worker process's inherited environment
|
|
|
35804
36169
|
...readonly && kind === "review" && live2.run.delivery?.candidate ? {
|
|
35805
36170
|
changes: {
|
|
35806
36171
|
root: cwd,
|
|
35807
|
-
base: live2.run.delivery.binding.target.head,
|
|
36172
|
+
base: live2.delivery?.candidateBase() ?? live2.run.delivery.binding.target.head,
|
|
35808
36173
|
candidate: live2.run.delivery.candidate
|
|
35809
36174
|
}
|
|
35810
36175
|
} : {},
|
|
@@ -36432,7 +36797,10 @@ ${diagnosticText(lines.join(`
|
|
|
36432
36797
|
if (!live2.target)
|
|
36433
36798
|
return;
|
|
36434
36799
|
try {
|
|
36435
|
-
await assertTarget(this.cwd,
|
|
36800
|
+
await assertTarget(this.cwd, {
|
|
36801
|
+
branch: live2.target.branch,
|
|
36802
|
+
head: live2.delivery?.targetHead() ?? live2.target.head
|
|
36803
|
+
}, paths);
|
|
36436
36804
|
} catch (error) {
|
|
36437
36805
|
if (!(error instanceof WorkflowRefusal) || error.code === "stale")
|
|
36438
36806
|
throw error;
|
|
@@ -36677,7 +37045,7 @@ Preserve prior outputs. Write only: ${work.writes.join(", ")}`, work.writes);
|
|
|
36677
37045
|
await this.commit(live2, cwd, scope, "Cadence: candidate for verification", before, "commit-candidate");
|
|
36678
37046
|
head = await delivery.assertTip();
|
|
36679
37047
|
await assertCandidate(cwd, head);
|
|
36680
|
-
await assertCommittedScope(cwd, delivery.
|
|
37048
|
+
await assertCommittedScope(cwd, delivery.candidateBase(), head, scope);
|
|
36681
37049
|
delivery.view.candidate = head;
|
|
36682
37050
|
delivery.view.acceptance = null;
|
|
36683
37051
|
this.save(live2);
|
|
@@ -36742,7 +37110,10 @@ Preserve prior outputs. Write only: ${work.writes.join(", ")}`, work.writes);
|
|
|
36742
37110
|
if (ignored.code === 0)
|
|
36743
37111
|
return skip(".cadence/ is ignored by Git here.");
|
|
36744
37112
|
try {
|
|
36745
|
-
await assertTarget(this.cwd,
|
|
37113
|
+
await assertTarget(this.cwd, {
|
|
37114
|
+
branch: live2.target.branch,
|
|
37115
|
+
head: live2.delivery?.targetHead() ?? live2.target.head
|
|
37116
|
+
}, KNOWLEDGE_SCOPE);
|
|
36746
37117
|
} catch {
|
|
36747
37118
|
return skip("the target checkout has its own changes to the knowledge store.");
|
|
36748
37119
|
}
|
|
@@ -36902,6 +37273,7 @@ ${result.output}`}`);
|
|
|
36902
37273
|
await delivery.resources.mutate(delivery.view.binding.target.repository, live2.abort.signal, async () => {
|
|
36903
37274
|
this.assertRunning(live2);
|
|
36904
37275
|
const candidate = await delivery.assertAccepted(p.digest, live2.execution, scope);
|
|
37276
|
+
this.assertGuidance(live2);
|
|
36905
37277
|
delivery.view.integration.before = delivery.targetHead();
|
|
36906
37278
|
delivery.view.integration.status = "applying";
|
|
36907
37279
|
delivery.view.integration.reason = "";
|
|
@@ -37077,6 +37449,68 @@ ${result.output}`}`);
|
|
|
37077
37449
|
await git(["worktree", "remove", path]);
|
|
37078
37450
|
}));
|
|
37079
37451
|
}
|
|
37452
|
+
async checkoutAccess(live2, access) {
|
|
37453
|
+
const previous = live2.barrier;
|
|
37454
|
+
if (previous) {
|
|
37455
|
+
previous.release();
|
|
37456
|
+
if (live2.barrier === previous)
|
|
37457
|
+
live2.barrier = undefined;
|
|
37458
|
+
}
|
|
37459
|
+
if (access === null)
|
|
37460
|
+
return;
|
|
37461
|
+
const permit = await this.o.gate.acquire(live2.run.id, live2.abort.signal, access);
|
|
37462
|
+
live2.barrier = permit;
|
|
37463
|
+
permit.assertHeld();
|
|
37464
|
+
}
|
|
37465
|
+
assertGuidance(live2) {
|
|
37466
|
+
if (!live2.guidance || !live2.target)
|
|
37467
|
+
throw new ContractError("invalid");
|
|
37468
|
+
if (pathIdentity(this.cwd, "AGENTS.md") !== live2.guidance.agents)
|
|
37469
|
+
throw new WorkflowRefusal("conflict", "AGENTS.md changed during the run. The candidate is retained; review a fresh plan before integration.");
|
|
37470
|
+
}
|
|
37471
|
+
async refreshCandidate(live2, integration, p) {
|
|
37472
|
+
const delivery = live2.delivery;
|
|
37473
|
+
const target2 = live2.target;
|
|
37474
|
+
if (!delivery || !target2)
|
|
37475
|
+
throw new ContractError("invalid");
|
|
37476
|
+
const scope = this.scope(live2, p);
|
|
37477
|
+
const frontier = delivery.frontierHead();
|
|
37478
|
+
await assertTarget(this.cwd, { branch: target2.branch, head: frontier }, scope);
|
|
37479
|
+
this.assertGuidance(live2);
|
|
37480
|
+
if (!delivery.needsRefresh())
|
|
37481
|
+
return;
|
|
37482
|
+
await delivery.assertAcceptedCandidate(p.digest, live2.execution, scope);
|
|
37483
|
+
const base = delivery.candidateBase();
|
|
37484
|
+
const changed = await committedPaths(this.cwd, base, frontier);
|
|
37485
|
+
const conflicts = [
|
|
37486
|
+
...new Set([
|
|
37487
|
+
...overlapping([...scope, "AGENTS.md"], changed),
|
|
37488
|
+
...changed.filter((path) => path.endsWith("/AGENTS.md"))
|
|
37489
|
+
])
|
|
37490
|
+
].sort();
|
|
37491
|
+
if (conflicts.length)
|
|
37492
|
+
throw new WorkflowRefusal("conflict", `A parallel workflow changed approved inputs: ${conflicts.join(", ")}. The isolated candidate is retained; review a fresh plan before integration.`);
|
|
37493
|
+
let merged = "";
|
|
37494
|
+
await this.gitStep(live2, integration, "integrate-parallel-deliveries", async (git) => {
|
|
37495
|
+
await git(["merge", "--no-ff", "--no-edit", frontier]);
|
|
37496
|
+
merged = await gitHead(integration);
|
|
37497
|
+
});
|
|
37498
|
+
delivery.refreshed(merged);
|
|
37499
|
+
await assertCandidate(integration, merged);
|
|
37500
|
+
await assertCommittedScope(integration, frontier, merged, scope);
|
|
37501
|
+
await this.verifyAndRepair(live2, integration, p, true);
|
|
37502
|
+
}
|
|
37503
|
+
advanceSiblings(live2) {
|
|
37504
|
+
const delivery = live2.delivery;
|
|
37505
|
+
const candidate = live2.run.mergedCommit;
|
|
37506
|
+
if (!delivery || !candidate || delivery.view.postChecks !== "passed" || delivery.view.integration.status !== "applied" || delivery.view.integration.after !== candidate)
|
|
37507
|
+
throw new ContractError("stale");
|
|
37508
|
+
const expected = delivery.frontierHead();
|
|
37509
|
+
const branch = delivery.view.binding.target.branch;
|
|
37510
|
+
for (const sibling of this.active.values())
|
|
37511
|
+
if (sibling !== live2 && sibling.delivery?.view.binding.target.branch === branch)
|
|
37512
|
+
sibling.delivery.advanceFrontier(expected, candidate);
|
|
37513
|
+
}
|
|
37080
37514
|
async implement(live2, p) {
|
|
37081
37515
|
const plan = p.plan;
|
|
37082
37516
|
const target2 = live2.target;
|
|
@@ -37096,6 +37530,7 @@ ${result.output}`}`);
|
|
|
37096
37530
|
delivery.prepareHome();
|
|
37097
37531
|
await this.gitStep(live2, this.cwd, "worktree-integration", (run) => delivery.create(run));
|
|
37098
37532
|
await assertWorktree(this.cwd, integration);
|
|
37533
|
+
await this.checkoutAccess(live2, null);
|
|
37099
37534
|
}
|
|
37100
37535
|
await this.setup(live2, integration, p, "candidate");
|
|
37101
37536
|
await this.setup(live2, integration, p);
|
|
@@ -37112,6 +37547,10 @@ ${result.output}`}`);
|
|
|
37112
37547
|
}
|
|
37113
37548
|
await this.assignments(live2, integration, p);
|
|
37114
37549
|
await this.verifyAndRepair(live2, integration, p, git);
|
|
37550
|
+
if (delivery) {
|
|
37551
|
+
await this.checkoutAccess(live2, "exclusive");
|
|
37552
|
+
await this.refreshCandidate(live2, integration, p);
|
|
37553
|
+
}
|
|
37115
37554
|
await this.learn(live2, integration, p);
|
|
37116
37555
|
if (live2.knowledgeDone)
|
|
37117
37556
|
await this.verifyAndRepair(live2, integration, p, git);
|
|
@@ -37129,14 +37568,14 @@ ${result.output}`}`);
|
|
|
37129
37568
|
committed3.push(name);
|
|
37130
37569
|
const documentBefore = new Map(documents.map((name) => [name, pathIdentity(this.cwd, name)]));
|
|
37131
37570
|
const beforePublication = await delivery.assertTip();
|
|
37132
|
-
const changed = await committedPaths(integration,
|
|
37571
|
+
const changed = await committedPaths(integration, delivery.candidateBase(), beforePublication);
|
|
37133
37572
|
this.publish(live2, integration, plan, committed3, changed);
|
|
37134
37573
|
await this.verifyAndRepair(live2, integration, p, true, committed3);
|
|
37135
37574
|
await this.integrate(live2, p, [...this.scope(live2, p), ...committed3]);
|
|
37136
37575
|
const candidate = live2.run.mergedCommit;
|
|
37137
37576
|
if (!candidate)
|
|
37138
37577
|
throw new ContractError("quarantine");
|
|
37139
|
-
for (const path of await committedPaths(this.cwd,
|
|
37578
|
+
for (const path of await committedPaths(this.cwd, delivery.candidateBase(), candidate))
|
|
37140
37579
|
live2.delivered.add(path);
|
|
37141
37580
|
try {
|
|
37142
37581
|
this.assertRunning(live2);
|
|
@@ -37191,6 +37630,7 @@ ${result.output}`}`);
|
|
|
37191
37630
|
throw error;
|
|
37192
37631
|
}
|
|
37193
37632
|
this.assertRunning(live2);
|
|
37633
|
+
this.advanceSiblings(live2);
|
|
37194
37634
|
await delivery.cleanup(async (path, check) => {
|
|
37195
37635
|
await this.gitStep(live2, this.cwd, "remove-merged-worktree", async (git2) => {
|
|
37196
37636
|
await check();
|
|
@@ -37298,7 +37738,7 @@ Read only. Cite paths and distinguish evidence, assumptions, user decisions and
|
|
|
37298
37738
|
let outcome = "unknown";
|
|
37299
37739
|
try {
|
|
37300
37740
|
this.assertRunning(live2);
|
|
37301
|
-
live2.barrier = await this.o.gate.acquire(live2.run.id, live2.abort.signal);
|
|
37741
|
+
live2.barrier = await this.o.gate.acquire(live2.run.id, live2.abort.signal, request3.action === "research" ? "shared" : "exclusive");
|
|
37302
37742
|
live2.barrier.assertHeld();
|
|
37303
37743
|
if (live2.run.diagnostics)
|
|
37304
37744
|
live2.run.diagnostics.acquiredAt = Date.now();
|
|
@@ -37820,7 +38260,7 @@ var processLifetime = {
|
|
|
37820
38260
|
}
|
|
37821
38261
|
};
|
|
37822
38262
|
async function createServiceHost(value, sourceBuild, lifetime) {
|
|
37823
|
-
const embedded = "
|
|
38263
|
+
const embedded = "8801198e182c2457f2ff8feb9331db22d449f2b483c0befd08ce493b4db6fb4a";
|
|
37824
38264
|
if (embedded && sourceBuild)
|
|
37825
38265
|
throw new ContractError("unsupported-context");
|
|
37826
38266
|
const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);
|