@abelxiaoxing/cadence 2.1.9 → 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.
@@ -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" && !step.parts)
6821
- throw new ContractError("invalid");
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
- return { commandId: part.commandId, entries: chain.slice(start, end) };
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({ id, role: "tool", name, args, text: text2, error });
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
- for (const block of Array.isArray(content) ? content : []) {
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
- if (text2 && items[items.length - 1] === text2)
9643
- text2.text += sanitizeText(`
9644
-
9645
- ${value}`, secrets);
9646
- else
9647
- text2 = add({
9648
- id: `${entry.id}:${items.length}`,
9649
- role: "assistant",
9650
- text: value,
9651
- name: "",
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}:${items.length}`, typeof name === "string" ? name : "tool", args);
9664
- if (typeof id === "string")
9665
- tools.set(id, call);
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}:${items.length}`,
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
- } else
9693
- tool(typeof id === "string" && id ? id : entry.id, typeof name === "string" ? name : "tool", "", output, own2(m, "isError") === true);
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,
@@ -10875,12 +11061,29 @@ function loginNextPath(url) {
10875
11061
  import { createHash as createHash9 } from "node:crypto";
10876
11062
  var styles = `
10877
11063
  :root {
10878
- color-scheme: dark;
11064
+ color-scheme: light dark;
10879
11065
  font-family:
10880
- Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
10881
- color: #edf4f1;
10882
- background: #0a100f;
11066
+ Inter, Geist, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
10883
11067
  font-synthesis: none;
11068
+ --page: light-dark(#f5f7ff, #020617);
11069
+ --text: light-dark(#0f172a, #e6edf7);
11070
+ --muted: light-dark(#536176, #94a3b8);
11071
+ --glass: light-dark(rgba(255, 255, 255, 0.62), rgba(15, 23, 42, 0.62));
11072
+ --glass-line: light-dark(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.1));
11073
+ --field: light-dark(rgba(255, 255, 255, 0.5), rgba(2, 6, 23, 0.48));
11074
+ --field-line: light-dark(rgba(100, 116, 139, 0.28), rgba(255, 255, 255, 0.12));
11075
+ --primary-a: light-dark(#0e7490, #22d3ee);
11076
+ --primary-b: light-dark(#1d4ed8, #60a5fa);
11077
+ --on-primary: light-dark(#ffffff, #082f49);
11078
+ --focus: light-dark(#2563eb, #22d3ee);
11079
+ --glow: light-dark(rgba(37, 99, 235, 0.22), rgba(34, 211, 238, 0.2));
11080
+ --shadow: light-dark(rgba(30, 64, 175, 0.14), rgba(0, 0, 0, 0.42));
11081
+ --mesh-a: light-dark(rgba(147, 197, 253, 0.64), rgba(34, 211, 238, 0.1));
11082
+ --mesh-b: light-dark(rgba(196, 181, 253, 0.58), rgba(37, 99, 235, 0.16));
11083
+ --mesh-c: light-dark(rgba(165, 243, 252, 0.52), rgba(99, 102, 241, 0.1));
11084
+ --grid: light-dark(rgba(37, 99, 235, 0.04), rgba(56, 189, 248, 0.055));
11085
+ --error: light-dark(#b91c1c, #fda4af);
11086
+ --error-bg: light-dark(rgba(254, 226, 226, 0.7), rgba(159, 18, 57, 0.12));
10884
11087
  }
10885
11088
  * {
10886
11089
  box-sizing: border-box;
@@ -10891,267 +11094,150 @@ body {
10891
11094
  min-height: 100svh;
10892
11095
  display: grid;
10893
11096
  place-items: center;
10894
- padding: 40px 28px;
10895
- background:
10896
- radial-gradient(ellipse at 12% 5%, #183a302e, transparent 55%),
10897
- radial-gradient(ellipse at 90% 95%, #253b492e, transparent 50%), #0a100f;
11097
+ padding: 28px 20px;
11098
+ color: var(--text);
11099
+ background: var(--page);
10898
11100
  }
10899
- body::before {
11101
+ body::before,
11102
+ body::after {
10900
11103
  content: "";
10901
11104
  position: fixed;
10902
11105
  inset: 0;
11106
+ z-index: 0;
10903
11107
  pointer-events: none;
10904
- background-image:
10905
- linear-gradient(#9bc6b605 1px, transparent 1px),
10906
- linear-gradient(90deg, #9bc6b605 1px, transparent 1px);
10907
- background-size: 64px 64px;
10908
- }
10909
- main {
10910
- position: relative;
10911
- display: grid;
10912
- grid-template-columns: 1.1fr 1fr;
10913
- width: min(1080px, 100%);
10914
- min-height: 650px;
10915
- border: 1px solid #b2d6c51c;
10916
- border-radius: 28px;
10917
- overflow: hidden;
10918
- background: #101916;
10919
- box-shadow: 0 40px 100px #0005;
10920
11108
  }
10921
- .story {
10922
- position: relative;
10923
- isolation: isolate;
10924
- overflow: hidden;
10925
- padding: 42px 48px;
10926
- display: flex;
10927
- flex-direction: column;
11109
+ body::before {
10928
11110
  background:
10929
- radial-gradient(ellipse at 25% 80%, #2e6f4d40, transparent 65%),
10930
- linear-gradient(145deg, #172922, #101c19);
11111
+ radial-gradient(circle at 12% 10%, var(--mesh-a), transparent 42%),
11112
+ radial-gradient(circle at 90% 16%, var(--mesh-b), transparent 44%),
11113
+ radial-gradient(circle at 52% 100%, var(--mesh-c), transparent 48%);
10931
11114
  }
10932
- .brand {
10933
- display: flex;
10934
- align-items: center;
10935
- gap: 11px;
10936
- font-size: 20px;
10937
- font-weight: 600;
10938
- letter-spacing: -0.7px;
10939
- }
10940
- .brand svg {
10941
- width: 34px;
10942
- height: 34px;
10943
- color: #b8f3ce;
11115
+ body::after {
11116
+ background-image:
11117
+ linear-gradient(var(--grid) 1px, transparent 1px),
11118
+ linear-gradient(90deg, var(--grid) 1px, transparent 1px);
11119
+ background-size: 48px 48px;
11120
+ mask-image: radial-gradient(ellipse at center, #000, transparent 78%);
10944
11121
  }
10945
- .intro {
11122
+ main {
10946
11123
  position: relative;
10947
11124
  z-index: 1;
10948
- margin-top: 76px;
10949
- }
10950
- .eyebrow {
10951
- font-size: 10px;
10952
- font-weight: 600;
10953
- letter-spacing: 2.3px;
10954
- text-transform: uppercase;
10955
- color: #a4bdb1;
10956
- margin: 0 0 19px;
10957
- }
10958
- .headline {
10959
- font-size: clamp(42px, 4.4vw, 58px);
10960
- font-weight: 450;
10961
- line-height: 1.08;
10962
- letter-spacing: -2.7px;
10963
- margin: 0;
10964
- }
10965
- .headline em {
10966
- font-style: normal;
10967
- color: #bbf4cf;
10968
- }
10969
- .lede {
10970
- max-width: 310px;
10971
- margin: 24px 0 0;
10972
- color: #a8beb2;
10973
- font-size: 14px;
10974
- line-height: 1.75;
10975
- }
10976
- .orbit {
10977
- position: absolute;
10978
- z-index: -1;
10979
- width: 430px;
10980
- height: 430px;
10981
- right: -180px;
10982
- bottom: -175px;
10983
- border: 1px solid #b8f3ce30;
10984
- border-radius: 50%;
11125
+ width: min(400px, 100%);
11126
+ padding: 40px;
11127
+ overflow: hidden;
11128
+ border: 1px solid var(--glass-line);
11129
+ border-radius: 28px;
11130
+ background: var(--glass);
10985
11131
  box-shadow:
10986
- 0 0 80px #8affac09,
10987
- inset 0 0 80px #8affac09;
10988
- }
10989
- .orbit::before,
10990
- .orbit::after {
10991
- content: "";
10992
- position: absolute;
10993
- border-radius: 50%;
10994
- border: 1px solid #b8f3ce1a;
10995
- inset: 44px;
10996
- }
10997
- .orbit::after {
10998
- inset: -48px;
10999
- border-style: dashed;
11000
- border-color: #b8f3ce17;
11001
- }
11002
- .satellite {
11003
- position: absolute;
11004
- inset: 0;
11005
- border-radius: 50%;
11006
- animation: orbit 36s linear infinite;
11132
+ 0 28px 80px var(--shadow),
11133
+ 0 0 48px var(--glow),
11134
+ inset 0 1px 0 var(--glass-line);
11135
+ backdrop-filter: blur(24px) saturate(140%);
11136
+ -webkit-backdrop-filter: blur(24px) saturate(140%);
11137
+ text-align: center;
11138
+ animation: arrive 0.45s ease-out both;
11007
11139
  }
11008
- .satellite::before {
11140
+ main::before {
11009
11141
  content: "";
11010
11142
  position: absolute;
11011
- top: 60px;
11012
- left: 60px;
11013
- width: 8px;
11014
- height: 8px;
11015
- border-radius: 50%;
11016
- background: #c2f6d3;
11017
- box-shadow: 0 0 24px #b6ffcd88;
11018
- }
11019
- .rhythm {
11020
- display: flex;
11021
- align-items: center;
11022
- gap: 14px;
11023
- margin-top: auto;
11024
- padding-top: 72px;
11025
- font-size: 11px;
11026
- color: #b0c4b8;
11027
- letter-spacing: 0.3px;
11028
- }
11029
- .rhythm span {
11030
- color: #638273;
11143
+ inset: 0 18% auto;
11144
+ height: 1px;
11145
+ background: linear-gradient(90deg, transparent, var(--primary-a), transparent);
11146
+ opacity: 0.75;
11031
11147
  }
11032
- .entry {
11033
- display: flex;
11034
- flex-direction: column;
11035
- justify-content: center;
11036
- padding: 64px 56px;
11037
- background: linear-gradient(150deg, #16201b66, transparent 65%);
11148
+ .brand {
11149
+ display: grid;
11150
+ justify-items: center;
11151
+ gap: 16px;
11038
11152
  }
11039
- .access {
11040
- display: inline-flex;
11041
- align-items: center;
11042
- gap: 7px;
11043
- width: fit-content;
11044
- border: 1px solid #d6f3e51a;
11045
- border-radius: 999px;
11046
- padding: 7px 10px;
11047
- font-size: 10px;
11048
- letter-spacing: 1.4px;
11049
- color: #bed2c5;
11050
- text-transform: uppercase;
11051
- margin-bottom: 30px;
11052
- }
11053
- .access svg {
11054
- width: 12px;
11055
- height: 12px;
11056
- color: #b8edc7;
11153
+ .brand-mark {
11154
+ display: grid;
11155
+ place-items: center;
11156
+ width: 52px;
11157
+ height: 52px;
11158
+ border: 1px solid var(--glass-line);
11159
+ border-radius: 16px;
11160
+ color: var(--on-primary);
11161
+ background: linear-gradient(135deg, var(--primary-a), var(--primary-b));
11162
+ box-shadow: 0 10px 32px var(--glow);
11163
+ }
11164
+ .brand-mark svg {
11165
+ width: 30px;
11166
+ height: 30px;
11057
11167
  }
11058
11168
  h1 {
11059
- font-size: 32px;
11169
+ margin: 0;
11170
+ font-size: 24px;
11171
+ font-weight: 600;
11060
11172
  line-height: 1.2;
11061
- font-weight: 500;
11062
- letter-spacing: -1.2px;
11063
- margin: 0 0 12px;
11064
- }
11065
- .description {
11066
- font-size: 14px;
11067
- color: #a5b5ab;
11068
- line-height: 1.65;
11069
- margin: 0 0 32px;
11173
+ letter-spacing: -0.7px;
11070
11174
  }
11071
- label {
11072
- display: block;
11073
- font-size: 12px;
11074
- font-weight: 500;
11075
- color: #d1e0d6;
11076
- margin-bottom: 10px;
11175
+ form {
11176
+ margin-top: 34px;
11077
11177
  }
11078
11178
  .field {
11079
11179
  position: relative;
11180
+ margin-bottom: 14px;
11080
11181
  }
11081
- .field svg {
11182
+ .field > svg {
11082
11183
  position: absolute;
11184
+ top: 17px;
11083
11185
  left: 16px;
11084
- top: 18px;
11085
11186
  width: 18px;
11086
11187
  height: 18px;
11087
- color: #849e8e;
11188
+ color: var(--muted);
11088
11189
  pointer-events: none;
11089
11190
  }
11090
11191
  input[type="password"] {
11091
11192
  display: block;
11092
11193
  width: 100%;
11093
- height: 54px;
11094
- border: 1px solid #c2e7cf26;
11095
- border-radius: 10px;
11096
- background: #0b130f;
11097
- color: #edf4f1;
11194
+ height: 52px;
11098
11195
  padding: 0 16px 0 46px;
11099
- font:
11100
- 16px ui-monospace,
11101
- SFMono-Regular,
11102
- Consolas,
11103
- monospace;
11104
- letter-spacing: 1px;
11196
+ border: 1px solid var(--field-line);
11197
+ border-radius: 14px;
11198
+ outline: none;
11199
+ background: var(--field);
11200
+ color: var(--text);
11201
+ font: 15px ui-monospace, SFMono-Regular, Consolas, monospace;
11202
+ letter-spacing: 0.5px;
11105
11203
  transition:
11106
11204
  border-color 0.2s,
11107
- box-shadow 0.2s;
11205
+ box-shadow 0.2s,
11206
+ background 0.2s;
11108
11207
  }
11109
11208
  input::placeholder {
11110
- font:
11111
- 13px ui-sans-serif,
11112
- system-ui,
11113
- sans-serif;
11209
+ color: var(--muted);
11210
+ font-family: Inter, Geist, ui-sans-serif, system-ui, sans-serif;
11114
11211
  letter-spacing: 0;
11115
- color: #7f9588;
11116
11212
  }
11117
11213
  input:hover {
11118
- border-color: #a9d9b950;
11214
+ border-color: var(--focus);
11119
11215
  }
11120
11216
  input:focus-visible {
11121
- outline: 2px solid #b8f3ce;
11122
- outline-offset: 3px;
11123
- border-color: #b8f3ce;
11217
+ border-color: var(--focus);
11218
+ box-shadow: 0 0 0 4px var(--glow);
11124
11219
  }
11125
11220
  input[aria-invalid="true"] {
11126
- border-color: #e5aa87;
11127
- }
11128
- .hint {
11129
- margin: 10px 0 24px;
11130
- font-size: 12px;
11131
- line-height: 1.6;
11132
- color: #92a99a;
11221
+ border-color: var(--error);
11133
11222
  }
11134
11223
  button {
11135
11224
  width: 100%;
11136
- min-height: 52px;
11225
+ min-height: 50px;
11137
11226
  display: flex;
11138
11227
  align-items: center;
11139
11228
  justify-content: center;
11140
- gap: 12px;
11141
- border: 1px solid #d8ffe0;
11142
- border-radius: 10px;
11143
- background: #c5f5d4;
11144
- color: #14271c;
11145
- font:
11146
- 600 13px ui-sans-serif,
11147
- system-ui,
11148
- sans-serif;
11229
+ gap: 10px;
11230
+ border: 1px solid var(--glass-line);
11231
+ border-radius: 14px;
11232
+ background: linear-gradient(135deg, var(--primary-a), var(--primary-b));
11233
+ color: var(--on-primary);
11234
+ font: 600 14px Inter, Geist, ui-sans-serif, system-ui, sans-serif;
11149
11235
  cursor: pointer;
11150
- box-shadow: 0 4px 24px #9cffbb0a;
11236
+ box-shadow: 0 10px 28px var(--glow);
11151
11237
  transition:
11152
- background 0.2s,
11153
11238
  transform 0.2s,
11154
- box-shadow 0.2s;
11239
+ box-shadow 0.2s,
11240
+ filter 0.2s;
11155
11241
  }
11156
11242
  button svg {
11157
11243
  width: 17px;
@@ -11159,9 +11245,9 @@ button svg {
11159
11245
  transition: transform 0.2s;
11160
11246
  }
11161
11247
  button:hover {
11162
- background: #d8ffe3;
11163
- box-shadow: 0 4px 28px #9cffbb1c;
11248
+ filter: brightness(1.06);
11164
11249
  transform: translateY(-1px);
11250
+ box-shadow: 0 14px 34px var(--glow);
11165
11251
  }
11166
11252
  button:hover svg {
11167
11253
  transform: translateX(3px);
@@ -11170,130 +11256,44 @@ button:active {
11170
11256
  transform: translateY(0);
11171
11257
  }
11172
11258
  button:focus-visible {
11173
- outline: 2px solid #c5f5d4;
11259
+ outline: 2px solid var(--focus);
11174
11260
  outline-offset: 4px;
11175
11261
  }
11176
- .remember {
11177
- margin: 22px auto 0;
11178
- max-width: 270px;
11179
- text-align: center;
11180
- color: #91a799;
11181
- font-size: 11px;
11182
- line-height: 1.8;
11183
- }
11184
11262
  .notice {
11263
+ margin: 0 0 16px;
11264
+ padding: 10px 12px;
11265
+ border: 1px solid var(--error);
11266
+ border-radius: 12px;
11267
+ background: var(--error-bg);
11268
+ color: var(--error);
11185
11269
  font-size: 12px;
11186
- color: #f4c6a9;
11187
- background: #a34a2019;
11188
- border: 1px solid #dca47c40;
11189
- border-radius: 10px;
11190
- padding: 12px 14px;
11191
- margin: 0 0 20px;
11192
- line-height: 1.65;
11193
- }
11194
- footer {
11195
- position: relative;
11196
- grid-column: 1 / -1;
11197
- display: flex;
11198
- justify-content: space-between;
11199
- gap: 16px;
11200
- width: min(1080px, 100%);
11201
- padding: 20px 8px 0;
11202
- color: #829b8b;
11203
- font-size: 10px;
11204
- letter-spacing: 0.3px;
11205
- }
11206
- .shell {
11207
- width: 100%;
11208
- display: grid;
11209
- justify-items: center;
11270
+ line-height: 1.5;
11271
+ text-align: left;
11210
11272
  }
11211
- @keyframes orbit {
11212
- to {
11213
- transform: rotate(360deg);
11214
- }
11273
+ .sr-only {
11274
+ position: absolute;
11275
+ width: 1px;
11276
+ height: 1px;
11277
+ padding: 0;
11278
+ margin: -1px;
11279
+ overflow: hidden;
11280
+ clip-path: inset(50%);
11281
+ white-space: nowrap;
11282
+ border: 0;
11215
11283
  }
11216
- @media (min-width: 1600px) {
11217
- main {
11218
- min-height: 700px;
11219
- }
11220
- .intro {
11221
- margin-top: 100px;
11284
+ @keyframes arrive {
11285
+ from {
11286
+ opacity: 0;
11287
+ transform: translateY(8px);
11222
11288
  }
11223
11289
  }
11224
- @media (max-width: 800px) {
11290
+ @media (max-width: 420px) {
11225
11291
  body {
11226
- padding: 24px 18px;
11292
+ padding: 18px 14px;
11227
11293
  }
11228
11294
  main {
11229
- grid-template-columns: 1fr;
11230
- max-width: 480px;
11231
- min-height: 0;
11232
- border-radius: 22px;
11233
- }
11234
- .story {
11235
- padding: 28px 30px 30px;
11236
- }
11237
- .intro {
11238
- margin-top: 34px;
11239
- }
11240
- .headline {
11241
- font-size: 40px;
11242
- letter-spacing: -1.8px;
11243
- }
11244
- .headline br {
11245
- display: none;
11246
- }
11247
- .lede {
11248
- font-size: 13px;
11249
- margin-top: 14px;
11250
- max-width: 340px;
11251
- }
11252
- .rhythm {
11253
- display: none;
11254
- }
11255
- .orbit {
11256
- width: 320px;
11257
- height: 320px;
11258
- right: -180px;
11259
- bottom: -215px;
11260
- }
11261
- .entry {
11262
- padding: 32px 30px 36px;
11263
- }
11264
- .access {
11265
- margin-bottom: 22px;
11266
- }
11267
- h1 {
11268
- font-size: 28px;
11269
- }
11270
- .description {
11271
- margin-bottom: 26px;
11272
- }
11273
- footer {
11274
- max-width: 480px;
11275
- padding-top: 16px;
11276
- font-size: 9px;
11277
- }
11278
- .eyebrow {
11279
- margin-bottom: 12px;
11280
- }
11281
- }
11282
- @media (max-width: 360px) {
11283
- body {
11284
- padding: 14px 10px;
11285
- }
11286
- .story,
11287
- .entry {
11288
- padding-left: 22px;
11289
- padding-right: 22px;
11290
- }
11291
- .headline {
11292
- font-size: 36px;
11293
- }
11294
- footer {
11295
- flex-wrap: wrap;
11296
- gap: 6px;
11295
+ padding: 32px 24px;
11296
+ border-radius: 24px;
11297
11297
  }
11298
11298
  }
11299
11299
  @media (prefers-reduced-motion: reduce) {
@@ -11305,19 +11305,18 @@ footer {
11305
11305
  }
11306
11306
  }
11307
11307
  @media (forced-colors: active) {
11308
+ body::before,
11309
+ body::after,
11310
+ main::before {
11311
+ display: none;
11312
+ }
11308
11313
  main,
11309
11314
  input[type="password"],
11310
11315
  button,
11311
- .access,
11316
+ .brand-mark,
11312
11317
  .notice {
11313
11318
  border: 1px solid CanvasText;
11314
11319
  }
11315
- .orbit {
11316
- display: none;
11317
- }
11318
- .headline em {
11319
- color: CanvasText;
11320
- }
11321
11320
  }
11322
11321
  `;
11323
11322
  var AUTH_PAGE_CSP = `default-src 'none'; style-src 'sha256-${createHash9("sha256").update(styles).digest("base64")}'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'`;
@@ -11330,43 +11329,28 @@ function renderAuthPage(options) {
11330
11329
  <head>
11331
11330
  <meta charset="utf-8">
11332
11331
  <meta name="viewport" content="width=device-width, initial-scale=1">
11333
- <meta name="color-scheme" content="dark">
11334
- <title>Welcome to Cadence</title>
11332
+ <meta name="color-scheme" content="light dark">
11333
+ <title>Cadence</title>
11335
11334
  <style>${styles}</style>
11336
11335
  </head>
11337
11336
  <body>
11338
- <div class="shell">
11339
- <main>
11340
- <section class="story" aria-label="Cadence">
11341
- <div class="brand"><svg viewBox="0 0 36 36" fill="none" aria-hidden="true"><rect x="1" y="1" width="34" height="34" rx="11" stroke="currentColor" stroke-opacity=".3"/><path d="M25 12a9 9 0 1 0 0 12M12 18h12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>cadence</div>
11342
- <div class="intro">
11343
- <p class="eyebrow">A little focus. A lot of possibility.</p>
11344
- <p class="headline">Find your flow.<br> Build <em>what’s next.</em></p>
11345
- <p class="lede">A space for your ideas to become plans, and your plans to become something real.</p>
11337
+ <main aria-labelledby="welcome">
11338
+ <div class="brand">
11339
+ <span class="brand-mark" aria-hidden="true"><svg viewBox="0 0 36 36" fill="none"><path d="M25 11a9 9 0 1 0 0 14M12 18h12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></span>
11340
+ <h1 id="welcome">Cadence</h1>
11346
11341
  </div>
11347
- <div class="orbit" aria-hidden="true"><div class="satellite"></div></div>
11348
- <div class="rhythm" aria-hidden="true">Think <span>↗</span> Create <span>↗</span> Keep going</div>
11349
- </section>
11350
- <section class="entry" aria-labelledby="welcome">
11351
- <div class="access"><svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><rect x="4" y="9" width="12" height="8" rx="2" stroke="currentColor" stroke-width="1.5"/><path d="M7 9V6a3 3 0 0 1 6 0v3" stroke="currentColor" stroke-width="1.5"/></svg>Private workspace</div>
11352
- <h1 id="welcome">Welcome to Cadence.</h1>
11353
- <p class="description">Your next idea starts here.<br>Enter your access key to step inside.</p>
11354
- ${options.authError ? '<p id="auth-notice" class="notice" role="alert">Access key was not accepted. Check the current key and try again.</p>' : ""}
11342
+ ${options.authError ? '<p id="auth-notice" class="notice" role="alert">Invalid access token.</p>' : ""}
11355
11343
  <form method="post" action="/auth">
11356
11344
  <input type="hidden" name="next" value="${escapeAttr(options.nextPath)}">
11357
- <label for="key">Access key</label>
11345
+ <label class="sr-only" for="key">Access token</label>
11358
11346
  <div class="field">
11359
11347
  <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="8" cy="9" r="4" stroke="currentColor" stroke-width="1.6"/><path d="m11 12 8 8m-3-3 2-2m-5-1 2-2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
11360
- <input id="key" name="password" type="password" placeholder="Enter your access key" autocomplete="current-password" required autofocus aria-describedby="key-hint${options.authError ? " auth-notice" : ""}"${options.authError ? ' aria-invalid="true"' : ""}>
11348
+ <input id="key" name="password" type="password" placeholder="Access token" autocomplete="current-password" required autofocus aria-describedby="key-hint${options.authError ? " auth-notice" : ""}"${options.authError ? ' aria-invalid="true"' : ""}>
11361
11349
  </div>
11362
- <p id="key-hint" class="hint">Use the key provided by your Cadence server.</p>
11363
- <button type="submit">Open workspace<svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 12h15m-6-6 6 6-6 6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
11350
+ <p id="key-hint" class="sr-only">Use the token provided by your Cadence server.</p>
11351
+ <button type="submit">Enter<svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 12h15m-6-6 6 6-6 6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
11364
11352
  </form>
11365
- <p class="remember">Stay signed in on this browser for up to a year.<br>Your access key stays out of the address bar.</p>
11366
- </section>
11367
11353
  </main>
11368
- <footer><span>Cadence · A workspace for what’s next.</span><span>Your space. Your pace.</span></footer>
11369
- </div>
11370
11354
  </body>
11371
11355
  </html>
11372
11356
  `;
@@ -15131,6 +15115,20 @@ var NOT_DELIVERED = "Not delivered: the reply ended before this message reached
15131
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.";
15132
15116
  var WITHDRAWN = "Withdrawn before it was delivered.";
15133
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
+ }
15134
15132
  function observedFile(path) {
15135
15133
  try {
15136
15134
  const s = lstatSync15(path);
@@ -15679,18 +15677,19 @@ class ConversationRecords {
15679
15677
  const turn2 = this.sessions.turn(view.session, view.turns[ordinal], secrets);
15680
15678
  const recorded = this.overlay(id, view.session).get(turn2.id);
15681
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;
15682
15691
  return {
15683
- turn: recorded ? {
15684
- ...turn2,
15685
- ...recorded.execution ? { execution: recorded.execution } : {},
15686
- status: recorded.status,
15687
- notice: turn2.notice || sanitizeText(recorded.notice, secrets),
15688
- omitted: {
15689
- thinking: turn2.omitted.thinking,
15690
- media: turn2.omitted.media || recorded.omitted.media,
15691
- other: turn2.omitted.other || recorded.omitted.other
15692
- }
15693
- } : running && view.live ? { ...turn2, execution: view.live.execution } : turn2,
15692
+ turn: running ? observed : settledSteps(observed),
15694
15693
  stable: turn2.steps.length
15695
15694
  };
15696
15695
  }
@@ -15700,11 +15699,13 @@ class ConversationRecords {
15700
15699
  const parts = view.parts ?? this.liveParts(view.session, live2);
15701
15700
  const chain = parts.at(-1)?.entries ?? [];
15702
15701
  const session = view.session;
15703
- const earlier = session ? parts.slice(0, -1).flatMap((part) => this.sessions.turn(session, part.entries, secrets).items) : [];
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);
15704
15704
  const written = turnItems(chain, secrets);
15705
15705
  const items = chain.length ? written.items : [
15706
15706
  {
15707
15707
  id: "user",
15708
+ renderId: `command:${live2.commandId}:user`,
15708
15709
  role: "user",
15709
15710
  text: live2.accepted.command.text,
15710
15711
  ...live2.images?.length ? {
@@ -15720,11 +15721,15 @@ class ConversationRecords {
15720
15721
  error: false
15721
15722
  }
15722
15723
  ];
15723
- 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
+ ]) ?? {
15724
15728
  items,
15725
15729
  stable: items.length
15726
15730
  };
15727
15731
  const omitted = live2.capture?.omitted;
15732
+ const activity2 = live2.capture?.activity;
15728
15733
  const turn = listTurn({
15729
15734
  id: chain[0]?.id ?? live2.commandId,
15730
15735
  entry: null,
@@ -15733,6 +15738,14 @@ class ConversationRecords {
15733
15738
  status: live2.state.status,
15734
15739
  notice: sanitizeText(live2.capture?.notice ?? "", secrets),
15735
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
+ } : {},
15736
15749
  omitted: {
15737
15750
  thinking: written.omitted.thinking,
15738
15751
  media: written.omitted.media || !!omitted?.media,
@@ -15741,13 +15754,13 @@ class ConversationRecords {
15741
15754
  items: extended.items.map((item) => ({
15742
15755
  ...item,
15743
15756
  text: sanitizeText(item.text, secrets),
15744
- name: sanitizeText(item.name, secrets),
15757
+ name: clipText(sanitizeText(item.name, secrets), 128),
15745
15758
  args: sanitizeText(item.args, secrets)
15746
15759
  }))
15747
15760
  });
15748
15761
  return {
15749
- turn: { ...turn, execution: live2.execution },
15750
- stable: extended.stable
15762
+ turn: { ...settledSteps(turn), execution: live2.execution },
15763
+ stable: LIVE.includes(live2.state.status) ? extended.stable : turn.steps.length
15751
15764
  };
15752
15765
  }
15753
15766
  turnSteps(id, leaf, ordinal, before) {
@@ -15765,6 +15778,7 @@ class ConversationRecords {
15765
15778
  turn: {
15766
15779
  ...turn.execution ? { execution: turn.execution } : {},
15767
15780
  ...turn.retry ? { retry: turn.retry } : {},
15781
+ ...turn.activity ? { activity: turn.activity } : {},
15768
15782
  id: turn.id,
15769
15783
  status: turn.status,
15770
15784
  notice: turn.notice,
@@ -17624,7 +17638,7 @@ async function createGateway(value, hostUrl, source) {
17624
17638
  const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
17625
17639
  const web = loadWebAssets(source?.webDirectory);
17626
17640
  const build2 = {
17627
- contractHash: "d70dd3e63843be7df42ff10943fcdc78bcd27b881b0ac8222526e8dad7b0e6e2",
17641
+ contractHash: "8801198e182c2457f2ff8feb9331db22d449f2b483c0befd08ce493b4db6fb4a",
17628
17642
  assets: {
17629
17643
  sourceHash: web.manifest.sourceHash,
17630
17644
  contractHash: web.manifest.contractHash,
@@ -28147,6 +28161,7 @@ class CaptureState {
28147
28161
  this.messages = new Map;
28148
28162
  this.calls = new Map;
28149
28163
  this.blocks = new Map;
28164
+ this.thinkingEntries = 0;
28150
28165
  this.dataFrames = 0;
28151
28166
  this.controlFrames = 0;
28152
28167
  this.bytes = 0;
@@ -28164,7 +28179,7 @@ class CaptureState {
28164
28179
  const control = controlEvent(e.kind);
28165
28180
  this.bytes += encodedBytes ?? utf8Bytes(canonicalJson(frame)) + 1;
28166
28181
  this[control ? "controlFrames" : "dataFrames"]++;
28167
- 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)
28168
28183
  throw new ContractError("capacity");
28169
28184
  const message2 = (id) => {
28170
28185
  const m = this.messages.get(id);
@@ -28218,7 +28233,8 @@ class CaptureState {
28218
28233
  finalIndices: new Set,
28219
28234
  finalHash: createHash28("sha256"),
28220
28235
  finalBytes: 0,
28221
- finalIndex: -1
28236
+ finalIndex: -1,
28237
+ thinking: new Map
28222
28238
  });
28223
28239
  break;
28224
28240
  case "detail-begin":
@@ -28277,6 +28293,17 @@ class CaptureState {
28277
28293
  this.details.delete(e.detailId);
28278
28294
  break;
28279
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
+ }
28280
28307
  case "message-text": {
28281
28308
  const d = this.details.get(e.detailId);
28282
28309
  const o = d?.descriptor.owner;
@@ -28348,6 +28375,9 @@ class CaptureState {
28348
28375
  requireFact2(d.descriptor.owner.index < e.finalBlockCount);
28349
28376
  }
28350
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();
28351
28381
  m.ended = true;
28352
28382
  m.final = e.finalDetailId;
28353
28383
  m.stopReason = e.stopReason;
@@ -29452,11 +29482,12 @@ class AuthNetwork {
29452
29482
 
29453
29483
  // src/service/checkout-gate.ts
29454
29484
  var CHECKOUT_WAITERS = 16;
29485
+ var CHECKOUT_READERS = 4;
29455
29486
 
29456
29487
  class CheckoutGate {
29457
29488
  owner;
29458
29489
  waiting = [];
29459
- holder = null;
29490
+ holders = new Set;
29460
29491
  closed = false;
29461
29492
  constructor(owner) {
29462
29493
  this.owner = owner;
@@ -29468,26 +29499,29 @@ class CheckoutGate {
29468
29499
  }
29469
29500
  assertQuiescent() {
29470
29501
  this.assertOpen();
29471
- if (this.holder || this.waiting.length)
29502
+ if (this.holders.size || this.waiting.length)
29472
29503
  throw new ContractError("conflict");
29473
29504
  }
29474
- acquire(id, signal) {
29505
+ acquire(id, signal, access = "exclusive") {
29475
29506
  decodeId(id);
29476
29507
  this.assertOpen();
29477
29508
  if (signal.aborted)
29478
29509
  throw new ContractError("stale");
29479
- if (this.holder?.id === id || this.waiting.some((w) => w.id === id))
29510
+ if ([...this.holders, ...this.waiting].some((w) => w.id === id))
29480
29511
  throw new ContractError("conflict");
29481
29512
  if (this.waiting.length >= CHECKOUT_WAITERS)
29482
29513
  throw new ContractError("capacity");
29483
29514
  const result = new Promise((resolve13, reject) => {
29484
29515
  const abort = () => {
29485
29516
  const at2 = this.waiting.indexOf(waiter);
29486
- if (at2 >= 0)
29517
+ if (at2 >= 0) {
29487
29518
  this.waiting.splice(at2, 1)[0].reject(new ContractError("stale"));
29519
+ this.pump();
29520
+ }
29488
29521
  };
29489
29522
  const waiter = {
29490
29523
  id,
29524
+ access,
29491
29525
  resolve: (permit) => {
29492
29526
  signal.removeEventListener("abort", abort);
29493
29527
  resolve13(permit);
@@ -29509,7 +29543,7 @@ class CheckoutGate {
29509
29543
  w.reject(new ContractError("quarantine"));
29510
29544
  }
29511
29545
  pump() {
29512
- if (this.closed || this.holder || !this.waiting.length)
29546
+ if (this.closed || !this.waiting.length)
29513
29547
  return;
29514
29548
  try {
29515
29549
  this.assertOpen();
@@ -29517,23 +29551,26 @@ class CheckoutGate {
29517
29551
  this.closeAdmission();
29518
29552
  return;
29519
29553
  }
29520
- const waiter = this.waiting.shift();
29521
- if (!waiter)
29522
- return;
29523
- this.holder = waiter;
29524
- const assertHeld = () => {
29525
- this.assertOpen();
29526
- if (this.holder !== waiter)
29527
- throw new ContractError("stale");
29528
- };
29529
- waiter.resolve({
29530
- assertHeld,
29531
- release: () => {
29532
- assertHeld();
29533
- this.holder = null;
29534
- this.pump();
29535
- }
29536
- });
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
+ }
29537
29574
  }
29538
29575
  }
29539
29576
 
@@ -30973,7 +31010,7 @@ import { join as join39 } from "node:path";
30973
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.
30974
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.
30975
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.
30976
- 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; only this run's confirmed merges can advance that target baseline for post-merge recovery. 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.
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.
30977
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.
30978
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.
30979
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.
@@ -32552,9 +32589,9 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
32552
32589
  } catch (error) {
32553
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.`);
32554
32591
  }
32555
- 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);
32556
32593
  if (busy.length)
32557
- return refusal3("checkout-busy", `An approved workflow (${busy.join(", ")}) is using this checkout. New investigations start only after it settles; meanwhile discuss recorded evidence or use cadence_status. Nothing was started.`);
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.`);
32558
32595
  const id = randomUUID25(), conversationId = current2.state.id;
32559
32596
  try {
32560
32597
  this.o.workflows.command(id, epoch, {
@@ -32661,6 +32698,8 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
32661
32698
  }
32662
32699
  decide(c, caller, evidence, recording) {
32663
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");
32664
32703
  const epoch = this.o.owner.lease.registration.epoch;
32665
32704
  if (c.kind === "cadence-prepare") {
32666
32705
  for (const [id, g2] of this.grants)
@@ -32764,12 +32803,13 @@ class LiveCapture {
32764
32803
  inputImages;
32765
32804
  retry;
32766
32805
  notice = "";
32806
+ activity = { kind: "waiting", sequence: 0 };
32767
32807
  unkept = [{ thinking: false, media: false, other: false }];
32768
32808
  users = 0;
32769
- assistants = [];
32770
- tools = [];
32809
+ messages = new Map;
32810
+ order = [];
32811
+ tools = new Map;
32771
32812
  details = new Map;
32772
- blocks = new Map;
32773
32813
  imageUser;
32774
32814
  constructor(secrets, inputImages = false) {
32775
32815
  this.secrets = secrets;
@@ -32784,39 +32824,103 @@ class LiveCapture {
32784
32824
  bounded(value) {
32785
32825
  return Buffer.byteLength(value) <= PREVIEW_BYTES ? value : `${Buffer.from(value).subarray(0, PREVIEW_BYTES).toString("utf8").replace(/�$/u, "")}${PREVIEW_MARK}`;
32786
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
+ }
32787
32847
  tool(callId) {
32788
- let tool = this.tools.find((t) => t.id === callId);
32848
+ let tool = this.tools.get(callId);
32789
32849
  if (!tool) {
32790
- tool = { id: callId, name: "", args: "", text: "", error: false };
32791
- this.tools.push(tool);
32792
- const stale = this.tools[this.tools.length - 1 - RECENT_PREVIEWS];
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);
32793
32864
  if (stale)
32794
- stale.args = stale.text = "";
32865
+ stale.item.args = stale.item.text = "";
32795
32866
  }
32796
32867
  return tool;
32797
32868
  }
32798
32869
  accept(frame) {
32799
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
+ };
32800
32878
  if (e.kind === "message-start" && e.role === "user") {
32801
32879
  if (this.users++)
32802
32880
  this.unkept.push({ thinking: false, media: false, other: false });
32803
32881
  else if (this.inputImages)
32804
32882
  this.imageUser = e.messageId;
32805
32883
  } else if (e.kind === "message-start" && e.role === "assistant") {
32806
- if (!this.assistants.some((a) => a.id === e.messageId)) {
32807
- this.assistants.push({ id: e.messageId, text: "", error: false });
32808
- const stale = this.assistants[this.assistants.length - 1 - RECENT_PREVIEWS];
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);
32809
32888
  if (stale)
32810
- stale.text = "";
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;
32811
32908
  }
32909
+ tool.item.name = clipText(sanitizeText(e.name, this.secrets()), 128);
32812
32910
  } else if (e.kind === "tool-start" || e.kind === "tool-end") {
32813
32911
  const tool = this.tool(e.callId);
32814
- tool.name = sanitizeText(e.name, this.secrets()).slice(0, 128);
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";
32815
32916
  if (e.kind === "tool-end")
32816
- 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);
32817
32921
  } else if (e.kind === "detail-begin") {
32818
- const kind = e.descriptor.owner.kind;
32819
- if (kind === "context" || kind === "handoff")
32922
+ const o = e.descriptor.owner;
32923
+ if (o.kind === "context" || o.kind === "handoff" || o.kind === "message-final")
32820
32924
  return;
32821
32925
  if (this.details.size >= 64)
32822
32926
  return;
@@ -32825,6 +32929,8 @@ class LiveCapture {
32825
32929
  sanitizer: new DetailSanitizer(e.descriptor.encoding, this.secrets()),
32826
32930
  text: ""
32827
32931
  });
32932
+ if (o.kind === "message")
32933
+ this.block(o.messageId, o.index, "assistant");
32828
32934
  } else if (e.kind === "detail-chunk" || e.kind === "detail-end") {
32829
32935
  const d = this.details.get(e.detailId);
32830
32936
  if (!d)
@@ -32833,89 +32939,104 @@ class LiveCapture {
32833
32939
  if (Buffer.byteLength(d.text) <= PREVIEW_BYTES)
32834
32940
  d.text += added;
32835
32941
  const o = d.descriptor.owner;
32836
- if (o.kind === "message" && o.stage === "stream") {
32837
- this.blocks.set(o.blockId, { messageId: o.messageId, text: d.text });
32838
- const message2 = this.assistants.find((a) => a.id === o.messageId);
32839
- if (message2)
32840
- message2.text = this.bounded([...this.blocks.values()].filter((b) => b.messageId === o.messageId).map((b) => b.text).join(""));
32841
- } else if (o.kind === "message-final") {
32842
- const message2 = this.assistants.find((a) => a.id === o.messageId);
32843
- if (message2)
32844
- message2.text = this.bounded(d.text);
32845
- } else if (o.kind === "tool") {
32846
- 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;
32847
32950
  if (o.stage === "execution-arguments" || o.stage === "arguments-final")
32848
32951
  tool.args = this.bounded(d.text);
32849
- if (o.stage === "result" || o.stage === "update-snapshot")
32850
- tool.text = this.bounded(d.text);
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
+ }
32851
32964
  }
32852
32965
  if (e.kind === "detail-end")
32853
32966
  this.details.delete(e.detailId);
32854
32967
  } else if (e.kind === "message-end") {
32855
- const message2 = this.assistants.find((a) => a.id === e.messageId);
32856
- if (message2)
32857
- message2.error = ["error", "aborted", "length"].includes(e.stopReason);
32858
- for (const [id, block] of this.blocks)
32859
- if (block.messageId === e.messageId)
32860
- this.blocks.delete(id);
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
+ }
32861
32986
  } else if (e.kind === "model-retry") {
32862
32987
  this.retry = e.progress ?? undefined;
32988
+ activity2("waiting");
32863
32989
  } else if (e.kind === "worker-failure") {
32864
32990
  this.retry = undefined;
32865
32991
  this.notice = `worker-failure: ${e.code}`;
32866
- } 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))
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)) {
32867
33001
  this.omitted[OMITTED_FLAG[e.block.reason]] = true;
33002
+ }
32868
33003
  }
32869
- extend(items, earlier = []) {
32870
- const out = [...earlier, ...items].map((item) => ({ ...item }));
32871
- let written = 0, counted;
32872
- for (const item of out) {
32873
- if (item.role === "assistant") {
32874
- const at2 = item.id.lastIndexOf(":");
32875
- const message2 = at2 < 0 ? item.id : item.id.slice(0, at2);
32876
- if (message2 !== counted)
32877
- written++;
32878
- counted = message2;
32879
- } else if (item.role !== "thinking")
32880
- counted = undefined;
32881
- }
32882
- const calls = out.filter((i) => i.role === "tool");
32883
- const results = calls.filter((i) => i.text || i.error).length;
32884
- let stable = out.length;
32885
- this.tools.forEach((tool, index) => {
32886
- if (index < results)
32887
- return;
32888
- const item = index < calls.length ? calls[index] : (() => {
32889
- const added = {
32890
- id: tool.id,
32891
- role: "tool",
32892
- name: tool.name,
32893
- args: tool.args,
32894
- text: "",
32895
- error: false
32896
- };
32897
- out.push(added);
32898
- return added;
32899
- })();
32900
- item.text = tool.text;
32901
- 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;
32902
33021
  stable = Math.min(stable, out.indexOf(item));
32903
- });
32904
- this.assistants.slice(written).forEach((message2) => {
32905
- stable = Math.min(stable, out.length);
32906
- out.push({
32907
- id: message2.id,
32908
- role: "assistant",
32909
- text: message2.text,
32910
- name: "",
32911
- args: "",
32912
- error: message2.error
32913
- });
32914
- });
32915
- return {
32916
- items: out.slice(earlier.length),
32917
- stable: Math.max(0, stable - earlier.length)
32918
- };
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 };
32919
33040
  }
32920
33041
  }
32921
33042
 
@@ -34301,12 +34422,16 @@ class WorkflowDelivery {
34301
34422
  save;
34302
34423
  token;
34303
34424
  children = new Map;
34425
+ frontier;
34426
+ base;
34304
34427
  home;
34305
34428
  constructor(view, resources, save) {
34306
34429
  this.view = view;
34307
34430
  this.resources = resources;
34308
34431
  this.save = save;
34309
34432
  this.home = dirname25(view.worktreeRoot);
34433
+ this.frontier = view.binding.target.head;
34434
+ this.base = view.binding.target.head;
34310
34435
  }
34311
34436
  prepareHome() {
34312
34437
  assertRepository(this.view.binding.target);
@@ -34463,26 +34588,51 @@ class WorkflowDelivery {
34463
34588
  rmdirSync(dirname25(path));
34464
34589
  } catch {}
34465
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
+ }
34466
34612
  targetHead() {
34467
34613
  const i = this.view.integration;
34468
34614
  if (i.status === "pending")
34469
- return this.view.binding.target.head;
34615
+ return this.frontier;
34470
34616
  if (i.status === "applied" && i.after)
34471
34617
  return i.after;
34472
34618
  throw new ContractError("stale");
34473
34619
  }
34474
- async assertAccepted(digest2, execution, scope) {
34620
+ async assertAcceptedCandidate(digest2, execution, scope) {
34475
34621
  const a = this.view.acceptance, candidate = this.view.candidate;
34476
34622
  if (!a || !candidate || a.candidate !== candidate || a.planDigest !== digest2 || a.contextDigest !== hash(canonicalJson(execution)) || await this.assertTip() !== candidate)
34477
34623
  throw new ContractError("stale");
34478
34624
  await assertCandidate(this.view.worktreeRoot, candidate);
34479
- await assertCommittedScope(this.view.worktreeRoot, this.view.binding.target.head, candidate, scope);
34625
+ await assertCommittedScope(this.view.worktreeRoot, this.base, candidate, scope);
34480
34626
  if ((await gitText(this.view.worktreeRoot, [
34481
34627
  "rev-parse",
34482
34628
  `${candidate}^{tree}`
34483
34629
  ])).trim() !== a.tree)
34484
34630
  throw new ContractError("stale");
34485
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);
34486
34636
  const targetHead = this.targetHead();
34487
34637
  await assertTarget(this.view.binding.target.checkoutRoot, {
34488
34638
  branch: this.view.binding.target.branch,
@@ -34753,8 +34903,12 @@ class TurnCapture {
34753
34903
  } else if (e.kind === "tool-start" || e.kind === "tool-end") {
34754
34904
  const item = this.item(e.callId, "tool");
34755
34905
  this.update(item, "name", sanitizeText(e.name, this.secrets()), 128);
34756
- if (e.kind === "tool-end")
34906
+ if (e.kind === "tool-start")
34907
+ item.state = "running";
34908
+ else {
34909
+ item.state = e.isError ? "failed" : "completed";
34757
34910
  item.error = e.isError;
34911
+ }
34758
34912
  } else if (e.kind === "message-end") {
34759
34913
  const item = this.turn.items.find((i) => i.id === e.messageId && i.role === "assistant");
34760
34914
  if (item)
@@ -34777,7 +34931,14 @@ class TurnCapture {
34777
34931
  if (block.messageId === e.messageId)
34778
34932
  this.messageText.delete(id);
34779
34933
  }
34780
- if (["message-end", "tool-end", "model-retry", "worker-failure"].includes(e.kind))
34934
+ if ([
34935
+ "message-end",
34936
+ "tool-start",
34937
+ "tool-update",
34938
+ "tool-end",
34939
+ "model-retry",
34940
+ "worker-failure"
34941
+ ].includes(e.kind))
34781
34942
  this.save();
34782
34943
  }
34783
34944
  }
@@ -35117,8 +35278,8 @@ function workflowResultDetail(value, secrets) {
35117
35278
  var runtimeSummary = (runtime) => `${describeWorkerRuntime(runtime)}
35118
35279
  ${RUN_ENVIRONMENT_POLICY}`;
35119
35280
  var OWNER_RUNTIME = Object.freeze({
35120
- version: "2.1.9",
35121
- build: "90395624f4308e49e37f4c427661bb878871b9d2b80eacff894eb1d897f153c4",
35281
+ version: "2.1.11",
35282
+ build: "9dd6139a141df55410936ada8c9074dfe1665ddc528d87d96d3b36a8aed95266",
35122
35283
  entry: fileURLToPath7(import.meta.url),
35123
35284
  pid: process.pid,
35124
35285
  node: process.versions.node,
@@ -35755,8 +35916,9 @@ class Workflows {
35755
35916
  const observed = this.assertProposal(proposal, request3.digest);
35756
35917
  const source = observed.source;
35757
35918
  runtime = observed.runtime;
35758
- if ([...this.active.values()].some((live3) => live3.proposal))
35759
- throw new WorkflowRefusal("conflict", "Another approved workflow is queued or running in this checkout. Approve this plan again after it settles.");
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.");
35760
35922
  this.capacity();
35761
35923
  const grant = this.grants.get(request3.grant);
35762
35924
  if (grant && grant.expiresAt < Date.now())
@@ -35819,6 +35981,7 @@ class Workflows {
35819
35981
  original: ready2.then(() => this.execute(live2, request3)),
35820
35982
  proposal,
35821
35983
  target: target2,
35984
+ guidance: target2 ? { agents: pathIdentity(this.cwd, "AGENTS.md") } : undefined,
35822
35985
  declared,
35823
35986
  delivered: new Set,
35824
35987
  notes: []
@@ -36006,7 +36169,7 @@ temporaryDirectoryEnvironment names this worker process's inherited environment
36006
36169
  ...readonly && kind === "review" && live2.run.delivery?.candidate ? {
36007
36170
  changes: {
36008
36171
  root: cwd,
36009
- base: live2.run.delivery.binding.target.head,
36172
+ base: live2.delivery?.candidateBase() ?? live2.run.delivery.binding.target.head,
36010
36173
  candidate: live2.run.delivery.candidate
36011
36174
  }
36012
36175
  } : {},
@@ -36634,7 +36797,10 @@ ${diagnosticText(lines.join(`
36634
36797
  if (!live2.target)
36635
36798
  return;
36636
36799
  try {
36637
- await assertTarget(this.cwd, live2.target, paths);
36800
+ await assertTarget(this.cwd, {
36801
+ branch: live2.target.branch,
36802
+ head: live2.delivery?.targetHead() ?? live2.target.head
36803
+ }, paths);
36638
36804
  } catch (error) {
36639
36805
  if (!(error instanceof WorkflowRefusal) || error.code === "stale")
36640
36806
  throw error;
@@ -36879,7 +37045,7 @@ Preserve prior outputs. Write only: ${work.writes.join(", ")}`, work.writes);
36879
37045
  await this.commit(live2, cwd, scope, "Cadence: candidate for verification", before, "commit-candidate");
36880
37046
  head = await delivery.assertTip();
36881
37047
  await assertCandidate(cwd, head);
36882
- await assertCommittedScope(cwd, delivery.view.binding.target.head, head, scope);
37048
+ await assertCommittedScope(cwd, delivery.candidateBase(), head, scope);
36883
37049
  delivery.view.candidate = head;
36884
37050
  delivery.view.acceptance = null;
36885
37051
  this.save(live2);
@@ -36944,7 +37110,10 @@ Preserve prior outputs. Write only: ${work.writes.join(", ")}`, work.writes);
36944
37110
  if (ignored.code === 0)
36945
37111
  return skip(".cadence/ is ignored by Git here.");
36946
37112
  try {
36947
- await assertTarget(this.cwd, live2.target, KNOWLEDGE_SCOPE);
37113
+ await assertTarget(this.cwd, {
37114
+ branch: live2.target.branch,
37115
+ head: live2.delivery?.targetHead() ?? live2.target.head
37116
+ }, KNOWLEDGE_SCOPE);
36948
37117
  } catch {
36949
37118
  return skip("the target checkout has its own changes to the knowledge store.");
36950
37119
  }
@@ -37104,6 +37273,7 @@ ${result.output}`}`);
37104
37273
  await delivery.resources.mutate(delivery.view.binding.target.repository, live2.abort.signal, async () => {
37105
37274
  this.assertRunning(live2);
37106
37275
  const candidate = await delivery.assertAccepted(p.digest, live2.execution, scope);
37276
+ this.assertGuidance(live2);
37107
37277
  delivery.view.integration.before = delivery.targetHead();
37108
37278
  delivery.view.integration.status = "applying";
37109
37279
  delivery.view.integration.reason = "";
@@ -37279,6 +37449,68 @@ ${result.output}`}`);
37279
37449
  await git(["worktree", "remove", path]);
37280
37450
  }));
37281
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
+ }
37282
37514
  async implement(live2, p) {
37283
37515
  const plan = p.plan;
37284
37516
  const target2 = live2.target;
@@ -37298,6 +37530,7 @@ ${result.output}`}`);
37298
37530
  delivery.prepareHome();
37299
37531
  await this.gitStep(live2, this.cwd, "worktree-integration", (run) => delivery.create(run));
37300
37532
  await assertWorktree(this.cwd, integration);
37533
+ await this.checkoutAccess(live2, null);
37301
37534
  }
37302
37535
  await this.setup(live2, integration, p, "candidate");
37303
37536
  await this.setup(live2, integration, p);
@@ -37314,6 +37547,10 @@ ${result.output}`}`);
37314
37547
  }
37315
37548
  await this.assignments(live2, integration, p);
37316
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
+ }
37317
37554
  await this.learn(live2, integration, p);
37318
37555
  if (live2.knowledgeDone)
37319
37556
  await this.verifyAndRepair(live2, integration, p, git);
@@ -37331,14 +37568,14 @@ ${result.output}`}`);
37331
37568
  committed3.push(name);
37332
37569
  const documentBefore = new Map(documents.map((name) => [name, pathIdentity(this.cwd, name)]));
37333
37570
  const beforePublication = await delivery.assertTip();
37334
- const changed = await committedPaths(integration, base, beforePublication);
37571
+ const changed = await committedPaths(integration, delivery.candidateBase(), beforePublication);
37335
37572
  this.publish(live2, integration, plan, committed3, changed);
37336
37573
  await this.verifyAndRepair(live2, integration, p, true, committed3);
37337
37574
  await this.integrate(live2, p, [...this.scope(live2, p), ...committed3]);
37338
37575
  const candidate = live2.run.mergedCommit;
37339
37576
  if (!candidate)
37340
37577
  throw new ContractError("quarantine");
37341
- for (const path of await committedPaths(this.cwd, base, candidate))
37578
+ for (const path of await committedPaths(this.cwd, delivery.candidateBase(), candidate))
37342
37579
  live2.delivered.add(path);
37343
37580
  try {
37344
37581
  this.assertRunning(live2);
@@ -37393,6 +37630,7 @@ ${result.output}`}`);
37393
37630
  throw error;
37394
37631
  }
37395
37632
  this.assertRunning(live2);
37633
+ this.advanceSiblings(live2);
37396
37634
  await delivery.cleanup(async (path, check) => {
37397
37635
  await this.gitStep(live2, this.cwd, "remove-merged-worktree", async (git2) => {
37398
37636
  await check();
@@ -37500,7 +37738,7 @@ Read only. Cite paths and distinguish evidence, assumptions, user decisions and
37500
37738
  let outcome = "unknown";
37501
37739
  try {
37502
37740
  this.assertRunning(live2);
37503
- 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");
37504
37742
  live2.barrier.assertHeld();
37505
37743
  if (live2.run.diagnostics)
37506
37744
  live2.run.diagnostics.acquiredAt = Date.now();
@@ -38022,7 +38260,7 @@ var processLifetime = {
38022
38260
  }
38023
38261
  };
38024
38262
  async function createServiceHost(value, sourceBuild, lifetime) {
38025
- const embedded = "d70dd3e63843be7df42ff10943fcdc78bcd27b881b0ac8222526e8dad7b0e6e2";
38263
+ const embedded = "8801198e182c2457f2ff8feb9331db22d449f2b483c0befd08ce493b4db6fb4a";
38026
38264
  if (embedded && sourceBuild)
38027
38265
  throw new ContractError("unsupported-context");
38028
38266
  const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);