@abelxiaoxing/cadence 2.2.1 → 2.2.2

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.
@@ -516,6 +516,13 @@ function decodeId(v) {
516
516
  invalid();
517
517
  return s;
518
518
  }
519
+ var knowledgeFields = Object.freeze({
520
+ checkout: (v) => list(v, 8, (entry) => text(entry, 1024, true)),
521
+ path: (v) => text(v, 1024, true),
522
+ section: (v) => text(v, 512, true),
523
+ match: (v) => text(v, 256, true),
524
+ investigation: decodeId
525
+ });
519
526
  function decodeHash(v) {
520
527
  const s = text(v, 64);
521
528
  if (!/^[0-9a-f]{64}$/.test(s))
@@ -6423,17 +6430,17 @@ function decodeEntryId(v) {
6423
6430
  function decodeKnowledgeLookup(v) {
6424
6431
  if (Object.hasOwn(v ?? {}, "checkout")) {
6425
6432
  const { checkout } = closed(v, ["checkout"]);
6426
- return { checkout: list(checkout, 8, (path) => text(path, 1024, true)) };
6433
+ return { checkout: knowledgeFields.checkout(checkout) };
6427
6434
  }
6428
6435
  if (Object.hasOwn(v ?? {}, "investigation"))
6429
6436
  return {
6430
- investigation: decodeId(closed(v, ["investigation"]).investigation)
6437
+ investigation: knowledgeFields.investigation(closed(v, ["investigation"]).investigation)
6431
6438
  };
6432
6439
  if (Object.hasOwn(v ?? {}, "match")) {
6433
6440
  const raw2 = closed(v, ["path", "match"]);
6434
6441
  return {
6435
- path: text(raw2.path, 1024, true),
6436
- match: text(raw2.match, 256, true)
6442
+ path: knowledgeFields.path(raw2.path),
6443
+ match: knowledgeFields.match(raw2.match)
6437
6444
  };
6438
6445
  }
6439
6446
  const raw = closed(v, [
@@ -6441,8 +6448,8 @@ function decodeKnowledgeLookup(v) {
6441
6448
  ...Object.hasOwn(v ?? {}, "section") ? ["section"] : []
6442
6449
  ]);
6443
6450
  return {
6444
- path: text(raw.path, 1024, true),
6445
- ...raw.section === undefined ? {} : { section: text(raw.section, 512, true) }
6451
+ path: knowledgeFields.path(raw.path),
6452
+ ...raw.section === undefined ? {} : { section: knowledgeFields.section(raw.section) }
6446
6453
  };
6447
6454
  }
6448
6455
  var FILE_PART_BYTES = 192 * 1024;
@@ -17898,7 +17905,7 @@ async function createGateway(value, hostUrl, source) {
17898
17905
  const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
17899
17906
  const web = loadWebAssets(source?.webDirectory);
17900
17907
  const build2 = {
17901
- contractHash: "190a21e723f753a233225a9f4bcf12a99d71b294a58728961846cd110cd60a17",
17908
+ contractHash: "80875479add4b7830419060b7e5018a39de200665edfbdec20fc10d50861bfea",
17902
17909
  assets: {
17903
17910
  sourceHash: web.manifest.sourceHash,
17904
17911
  contractHash: web.manifest.contractHash,
@@ -31463,6 +31470,179 @@ Present a concise delivery expectation with the complete returned agreement avai
31463
31470
  During accepted work the service owns progress, recovery and revision, and finishes without the user. Report actual cadence_status observations; do not start replacement workflows or ask for 'continue' after an individual child fails. Child failure is not delivery failure. Report recorded plan revisions as progress and lead with any recorded deviation when the run completes. Agents have no total runtime deadline; explicit command timeouts and actual closure still apply. A run stops only for a condition outside the repository; then explain that condition and the preserved outcomes, not a generic request to continue.
31464
31471
  For follow-up to a settled or interrupted run, inspect retained outcomes first. Partial outputs are not unexplained user edits. Unknown results must be observed and reconciled, never blindly replayed; a new delivery requires fresh approval. No automatic replay after owner restart. cadence_cancel is explicit cancellation, not navigation or exit. Worker prose is not passing checks; automatic review is never human review. Completion leaves Cadence ON and ready. Tools operate on the host; this is not a sandbox.`;
31465
31472
 
31473
+ // src/coordinator-tools.mjs
31474
+ import { Type } from "typebox";
31475
+ var CHECK = Type.Object({
31476
+ name: Type.String(),
31477
+ command: Type.String(),
31478
+ timeoutMs: Type.Optional(Type.Integer({
31479
+ description: "Milliseconds, from 100. Leave out for no timeout."
31480
+ }))
31481
+ });
31482
+ var READING = Type.Union([
31483
+ Type.Object({
31484
+ path: Type.String({ description: "Project document to read first." }),
31485
+ section: Type.Optional(Type.String({ description: "One heading of that document." })),
31486
+ reason: Type.String()
31487
+ }),
31488
+ Type.Object({
31489
+ research: Type.String({
31490
+ description: 'A recorded investigation: the "investigation" value of a completed research step.'
31491
+ }),
31492
+ reason: Type.String()
31493
+ })
31494
+ ]);
31495
+ var RESEARCH_PARAMETERS = Type.Object({
31496
+ goal: Type.String(),
31497
+ questions: Type.Array(Type.String({
31498
+ description: "One focused, independent question."
31499
+ }), {
31500
+ description: "Split independent questions freely; the service runs as many at once as this machine is configured for and queues the rest."
31501
+ }),
31502
+ roots: Type.Optional(Type.Array(Type.String({
31503
+ description: "Specific investigation directories, relative to this conversation's cwd by default. Avoid filesystem roots and broad parent trees."
31504
+ })))
31505
+ });
31506
+ var lookupExample = 'Use {checkout:["node_modules"]}, {checkout:[]}, {path:"docs.md"} with optional section or match, or {investigation:"<retained UUID>"}.';
31507
+ function knowledgeToolInput(input) {
31508
+ const bad12 = (field, why) => {
31509
+ throw new Error(`${field}: ${why}. ${lookupExample}`);
31510
+ };
31511
+ const keys2 = Object.keys(input ?? {});
31512
+ let raw;
31513
+ try {
31514
+ raw = closed(input, keys2);
31515
+ } catch {
31516
+ bad12("cadence_knowledge", "expected an object with named lookup fields");
31517
+ }
31518
+ const fields3 = Object.create(null);
31519
+ for (const key3 of keys2) {
31520
+ if (!Object.hasOwn(knowledgeFields, key3))
31521
+ bad12(JSON.stringify(key3.slice(0, 80)), "unknown field; omit it");
31522
+ if (key3 !== "checkout" && raw[key3] === "")
31523
+ continue;
31524
+ try {
31525
+ fields3[key3] = knowledgeFields[key3](raw[key3]);
31526
+ } catch {
31527
+ bad12(key3, key3 === "checkout" ? "give an array of up to eight nonempty dependency paths (each at most 1024 bytes)" : key3 === "investigation" ? "give a retained investigation UUID" : "give a nonblank string within the field limit");
31528
+ }
31529
+ }
31530
+ const { checkout, path, section, match, investigation } = fields3;
31531
+ if ((section || match) && !path)
31532
+ bad12(section ? "section/path" : "match/path", "name the source file in path");
31533
+ if (section && match)
31534
+ bad12("section/match", "choose one selector");
31535
+ if (checkout?.length && (path || investigation))
31536
+ bad12("checkout", "cannot combine dependencies with path or investigation");
31537
+ if (investigation && path)
31538
+ bad12("investigation/path", "choose one source");
31539
+ const relative9 = (name) => !/[\\:\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(name) && name.split("/").every((part) => part && part !== "." && part !== ".." && part.toLowerCase() !== ".git");
31540
+ if (path && !relative9(path))
31541
+ bad12("path", "give a plain checkout-relative file path");
31542
+ if (checkout?.some((name) => !relative9(name) || name.split("/").some((part) => part.startsWith("."))))
31543
+ bad12("checkout", "give plain checkout-relative dependency names");
31544
+ if (investigation)
31545
+ return { investigation };
31546
+ if (path)
31547
+ return match ? { path, match } : section ? { path, section } : { path };
31548
+ if (checkout)
31549
+ return { checkout };
31550
+ bad12("path/checkout/investigation", "no lookup selected");
31551
+ }
31552
+ var KNOWLEDGE_PARAMETERS = Type.Object({
31553
+ checkout: Type.Optional(Type.Array(Type.String(), {
31554
+ description: "Instead of other fields, give up to eight checkout-relative dependency directory names (e.g. node_modules and web/node_modules), or [] for Git placement only. Observe the original checkout, Git branch and HEAD, and whether each named entry is a directory, symlink or absent. Never follows a dependency link."
31555
+ })),
31556
+ path: Type.Optional(Type.String({
31557
+ description: "One checkout-relative document, or the exact project source file containing a known fact."
31558
+ })),
31559
+ section: Type.Optional(Type.String({
31560
+ description: "Exact Markdown heading. Use either section or match."
31561
+ })),
31562
+ match: Type.Optional(Type.String({
31563
+ description: "A literal on a line of this source file (such as a token, assertion or build script). Return matching line numbers with short previews and context at the first occurrence, without a research worker."
31564
+ })),
31565
+ investigation: Type.Optional(Type.String({
31566
+ description: "Instead of path/section, supply a retained investigation ID to recheck its sources and reuse the answer."
31567
+ }))
31568
+ });
31569
+ var DESIGN_PARAMETERS = Type.Object({
31570
+ questions: Type.Array(Type.Object({
31571
+ id: Type.String(),
31572
+ question: Type.String(),
31573
+ options: Type.Array(Type.Object({
31574
+ id: Type.String(),
31575
+ label: Type.String(),
31576
+ cost: Type.String()
31577
+ })),
31578
+ recommended: Type.String({ description: "Recommended option ID" }),
31579
+ reason: Type.String(),
31580
+ acceptance: Type.String({
31581
+ description: "Acceptance item this decision affects"
31582
+ }),
31583
+ when: Type.Optional(Type.Union([
31584
+ Type.Null(),
31585
+ Type.Object({ question: Type.String(), option: Type.String() })
31586
+ ], {
31587
+ description: "Omit or use null for an independent question. For a conditional question give an earlier question ID and one of its option IDs."
31588
+ }))
31589
+ }))
31590
+ });
31591
+ var PLAN_PARAMETERS = Type.Object({
31592
+ goal: Type.String(),
31593
+ design: Type.String({ description: "The initial technical route." }),
31594
+ decisions: Type.Optional(Type.String({ description: "Explicit decisions and non-goals." })),
31595
+ acceptance: Type.String(),
31596
+ assumptions: Type.Optional(Type.String({
31597
+ description: "What you decided on the user's behalf without asking; approval confirms it. Leave out when there is none."
31598
+ })),
31599
+ documents: Type.Optional(Type.Array(Type.String({
31600
+ description: "Existing project Markdown this delivery may update."
31601
+ }))),
31602
+ reviewReads: Type.Optional(Type.Array(READING, {
31603
+ description: "What the independent review reads first."
31604
+ })),
31605
+ policy: Type.Optional(Type.Object({
31606
+ installs: Type.Optional(Type.Boolean({
31607
+ description: "Whether a later revision may add dependency-installation commands. False unless the user agreed."
31608
+ }))
31609
+ })),
31610
+ tasks: Type.Array(Type.Object({
31611
+ id: Type.String({
31612
+ description: "Lowercase letters, digits and hyphens, starting with a letter."
31613
+ }),
31614
+ title: Type.String(),
31615
+ instructions: Type.String({ description: "At most 8KiB." }),
31616
+ writes: Type.Array(Type.String()),
31617
+ after: Type.Optional(Type.Array(Type.String(), {
31618
+ description: "Ids of the assignments this one really depends on. Leave out when it depends on none."
31619
+ })),
31620
+ reads: Type.Optional(Type.Array(READING, {
31621
+ description: "The few things this assignment should read first."
31622
+ }))
31623
+ }), { description: "One to 16 assignments." }),
31624
+ checks: Type.Array(CHECK, {
31625
+ description: "The real acceptance commands: at least one, at most 16."
31626
+ }),
31627
+ setup: Type.Optional(Type.Array(Type.Object({
31628
+ ...CHECK.properties,
31629
+ placement: Type.Union([
31630
+ Type.Literal("target"),
31631
+ Type.Literal("candidate"),
31632
+ Type.Literal("worktree")
31633
+ ], {
31634
+ description: "target: preflight once in the original checkout before creating worktrees; candidate: once in the stable candidate; worktree: prepare the candidate and every detached child. Target branch checks belong to target, never worktree. Commands do not export environment into later processes."
31635
+ })
31636
+ }), {
31637
+ description: "Explicit preparation commands with their execution placement, at most four. Run in target, candidate, then worktree stages, preserving order within each stage."
31638
+ })),
31639
+ baselineChecks: Type.Optional(Type.Array(CHECK)),
31640
+ delivery: Type.Union([
31641
+ Type.Literal("local-merge"),
31642
+ Type.Literal("working-copy")
31643
+ ])
31644
+ });
31645
+
31466
31646
  // src/service/project-knowledge.ts
31467
31647
  import { isUtf8 } from "node:buffer";
31468
31648
  import { createHash as createHash31 } from "node:crypto";
@@ -31966,11 +32146,20 @@ function workflowObservation(cwd, plan) {
31966
32146
  identity: hash(JSON.stringify({ head, branch, contents }))
31967
32147
  };
31968
32148
  }
31969
- async function assertTarget(cwd, expected, scope) {
31970
- const head = await gitHead(cwd);
31971
- const branch = (await gitText(cwd, ["symbolic-ref", "HEAD"])).trim();
31972
- if (head !== expected.head || branch !== expected.branch)
31973
- throw new WorkflowRefusal("stale", `The target branch changed during the run (expected ${expected.branch} at ${expected.head.slice(0, 12)}); nothing was integrated.`);
32149
+ async function assertTargetPosition(cwd, expected, stage) {
32150
+ const [ref, oid] = await Promise.all([
32151
+ gitRun(cwd, ["symbolic-ref", "--quiet", "HEAD"]).catch(() => null),
32152
+ gitRun(cwd, ["rev-parse", "--verify", "HEAD"]).catch(() => null)
32153
+ ]);
32154
+ const branch = ref?.code === 0 ? ref.stdout.trim() : ref?.code === 1 ? "(detached HEAD)" : null;
32155
+ const head = oid?.code === 0 ? oid.stdout.trim() : null;
32156
+ if (head === expected.head && branch === expected.branch)
32157
+ return;
32158
+ const unreadable = !head || !branch;
32159
+ throw new WorkflowRefusal(unreadable ? "unavailable" : "stale", `${stage}: target ${unreadable ? "identity could not be verified" : "position changed"}; expected ${expected.branch} at ${expected.head}, observed ${branch || "(unreadable ref)"} at ${head || "(unreadable HEAD)"}. Refused to proceed; this check made no merge.`);
32160
+ }
32161
+ async function assertTarget(cwd, expected, scope, stage) {
32162
+ await assertTargetPosition(cwd, expected, stage);
31974
32163
  assertVisibleIndex(overlapping(scope, indexHidden(await gitText(cwd, INDEX_FLAGS))));
31975
32164
  const dirty = overlapping(scope, await changedPaths(cwd));
31976
32165
  if (dirty.length)
@@ -33094,10 +33283,20 @@ Current design ${design.id}, revision ${design.revision}, ${design.submitted ? "
33094
33283
  if (name === "cadence_knowledge") {
33095
33284
  if (!this.o.cwd)
33096
33285
  return refusal3("unavailable", "Project directory unavailable.");
33286
+ let source;
33097
33287
  try {
33098
- return await this.knowledge(decodeKnowledgeLookup(args));
33099
- } catch {
33100
- return refusal3("invalid", "checkout/path/section/match/investigation: supply checkout with a list of local dependency paths, a Markdown path and optional heading, a file path and literal match, or one retained investigation ID.");
33288
+ source = knowledgeToolInput(args);
33289
+ } catch (error) {
33290
+ return refusal3("invalid", diagnosticText(error instanceof Error ? error.message : "Expected a knowledge lookup.", 512, this.o.secrets()));
33291
+ }
33292
+ try {
33293
+ return await this.knowledge(source);
33294
+ } catch (error) {
33295
+ if (this.o.owner.state !== "idle")
33296
+ throw error;
33297
+ const field = "checkout" in source ? "checkout" : ("investigation" in source) ? "investigation" : "path";
33298
+ const code2 = error instanceof ContractError ? error.code : "unavailable";
33299
+ return refusal3(code2, field === "checkout" ? "checkout: the owner could not observe that entry. Name an allowed dependency directly, not through a linked ancestor." : `${field}: the owner could not read that source; use an allowed project source.`);
33101
33300
  }
33102
33301
  }
33103
33302
  if (name === "cadence_design") {
@@ -35258,7 +35457,7 @@ class WorkflowDelivery {
35258
35457
  await assertTarget(this.view.binding.target.checkoutRoot, {
35259
35458
  branch: this.view.binding.target.branch,
35260
35459
  head: targetHead
35261
- }, scope);
35460
+ }, scope, "integration preflight");
35262
35461
  if ((await gitRun(this.view.worktreeRoot, [
35263
35462
  "merge-base",
35264
35463
  "--is-ancestor",
@@ -35899,8 +36098,8 @@ function workflowResultDetail(value, secrets) {
35899
36098
  var runtimeSummary = (runtime) => `${describeWorkerRuntime(runtime)}
35900
36099
  ${RUN_ENVIRONMENT_POLICY}`;
35901
36100
  var OWNER_RUNTIME = Object.freeze({
35902
- version: "2.2.1",
35903
- build: "a00e54093398520b297b4fa2a520c8519e5f947a49f61dae258493ec2903ab39",
36101
+ version: "2.2.2",
36102
+ build: "9d8538776a8e8f204fa4ccffb749d41eee1ca010f56af92ef5d3e88038eb2910",
35904
36103
  entry: fileURLToPath7(import.meta.url),
35905
36104
  pid: process.pid,
35906
36105
  node: process.versions.node,
@@ -36610,6 +36809,8 @@ class Workflows {
36610
36809
  effect();
36611
36810
  if (request3.action === "execute")
36612
36811
  this.grants.delete(request3.grant);
36812
+ if (live2.run.delivery)
36813
+ live2.delivery = new WorkflowDelivery(live2.run.delivery, new RepositoryCoordination(this.o.coordination, this.cwd, live2.run.epoch, live2.run.id, () => this.o.owner.lease.assert(), () => this.o.owner.quarantine()), () => this.save(live2));
36613
36814
  this.active.set(commandId, live2);
36614
36815
  this.o.owner.trackConversation(live2.original, () => abort.abort({ source: "service", reason: "stop", target: commandId }));
36615
36816
  try {
@@ -37439,9 +37640,9 @@ ${diagnosticText(lines.join(`
37439
37640
  await assertTarget(this.cwd, {
37440
37641
  branch: live2.target.branch,
37441
37642
  head: live2.delivery?.targetHead() ?? live2.target.head
37442
- }, paths);
37643
+ }, paths, "scope revision");
37443
37644
  } catch (error) {
37444
- if (!(error instanceof WorkflowRefusal) || error.code === "stale")
37645
+ if (!(error instanceof WorkflowRefusal) || error.code === "stale" || error.code === "unavailable")
37445
37646
  throw error;
37446
37647
  throw new InvalidDecision(`These paths cannot join the write scope because the target checkout has its own changes to them or hides them: ${paths.join(", ")} (${error.detail})`);
37447
37648
  }
@@ -37752,8 +37953,10 @@ Preserve prior outputs. Write only: ${work.writes.join(", ")}`, work.writes);
37752
37953
  await assertTarget(this.cwd, {
37753
37954
  branch: live2.target.branch,
37754
37955
  head: live2.delivery?.targetHead() ?? live2.target.head
37755
- }, KNOWLEDGE_SCOPE);
37756
- } catch {
37956
+ }, KNOWLEDGE_SCOPE, "knowledge placement");
37957
+ } catch (error) {
37958
+ if (error instanceof WorkflowRefusal && (error.code === "stale" || error.code === "unavailable"))
37959
+ throw error;
37757
37960
  return skip("the target checkout has its own changes to the knowledge store.");
37758
37961
  }
37759
37962
  return true;
@@ -38107,6 +38310,17 @@ ${result.output}`}`);
38107
38310
  if (pathIdentity(this.cwd, "AGENTS.md") !== live2.guidance.agents)
38108
38311
  throw new WorkflowRefusal("conflict", "AGENTS.md changed during the run. The candidate is retained; review a fresh plan before integration.");
38109
38312
  }
38313
+ async assertSiblingScope(branch, base, frontier, scope, stage) {
38314
+ const changed = await committedPaths(this.cwd, base, frontier);
38315
+ const conflicts = [
38316
+ ...new Set([
38317
+ ...overlapping([...scope, "AGENTS.md"], changed),
38318
+ ...changed.filter((path) => path.endsWith("/AGENTS.md"))
38319
+ ])
38320
+ ].sort();
38321
+ if (conflicts.length)
38322
+ throw new WorkflowRefusal("conflict", `${stage}: verified sibling advanced ${branch} from ${base} to ${frontier} and changed approved inputs: ${conflicts.join(", ")}. Refused to integrate overlapping work.`);
38323
+ }
38110
38324
  async refreshCandidate(live2, integration, p) {
38111
38325
  const delivery = live2.delivery;
38112
38326
  const target2 = live2.target;
@@ -38114,21 +38328,13 @@ ${result.output}`}`);
38114
38328
  throw new ContractError("invalid");
38115
38329
  const scope = this.scope(live2, p);
38116
38330
  const frontier = delivery.frontierHead();
38117
- await assertTarget(this.cwd, { branch: target2.branch, head: frontier }, scope);
38331
+ await assertTarget(this.cwd, { branch: target2.branch, head: frontier }, scope, "candidate refresh");
38118
38332
  this.assertGuidance(live2);
38119
38333
  if (!delivery.needsRefresh())
38120
38334
  return;
38121
38335
  await delivery.assertAcceptedCandidate(p.digest, live2.execution, scope);
38122
38336
  const base = delivery.candidateBase();
38123
- const changed = await committedPaths(this.cwd, base, frontier);
38124
- const conflicts = [
38125
- ...new Set([
38126
- ...overlapping([...scope, "AGENTS.md"], changed),
38127
- ...changed.filter((path) => path.endsWith("/AGENTS.md"))
38128
- ])
38129
- ].sort();
38130
- if (conflicts.length)
38131
- throw new WorkflowRefusal("conflict", `A parallel workflow changed approved inputs: ${conflicts.join(", ")}. The isolated candidate is retained; review a fresh plan before integration.`);
38337
+ await this.assertSiblingScope(target2.branch, base, frontier, scope, "candidate refresh");
38132
38338
  let merged = "";
38133
38339
  await this.gitStep(live2, integration, "integrate-parallel-deliveries", async (git) => {
38134
38340
  await git(["merge", "--no-ff", "--no-edit", frontier]);
@@ -38163,7 +38369,7 @@ ${result.output}`}`);
38163
38369
  const integration = delivery?.view.worktreeRoot ?? this.cwd;
38164
38370
  if (plan.setup.some((c) => c.placement === "target")) {
38165
38371
  await this.setup(live2, this.cwd, p, "target");
38166
- await this.assertStartable(live2, p);
38372
+ await this.assertStartable(live2, p, "after target setup");
38167
38373
  }
38168
38374
  if (delivery) {
38169
38375
  delivery.prepareHome();
@@ -38245,7 +38451,7 @@ ${result.output}`}`);
38245
38451
  if (!expected)
38246
38452
  throw new ContractError("quarantine");
38247
38453
  assertRepository(delivery.view.binding.target);
38248
- await assertTarget(this.cwd, { head: expected, branch: target2.branch }, scope);
38454
+ await assertTarget(this.cwd, { head: expected, branch: target2.branch }, scope, "before post-merge checks");
38249
38455
  delivery.view.postChecks = "unknown";
38250
38456
  this.save(live2);
38251
38457
  const beforeSource = await sourceIdentityAsync(this.cwd, scope, live2.abort.signal);
@@ -38257,9 +38463,7 @@ ${result.output}`}`);
38257
38463
  const deliveredHead = live2.run.mergedCommit;
38258
38464
  if (!deliveredHead)
38259
38465
  throw new ContractError("quarantine");
38260
- await this.unchangedHead(this.cwd, deliveredHead);
38261
- if ((await gitText(this.cwd, ["symbolic-ref", "HEAD"])).trim() !== target2.branch)
38262
- throw new ContractError("stale");
38466
+ await assertTargetPosition(this.cwd, { head: deliveredHead, branch: target2.branch }, "after post-merge checks");
38263
38467
  delivery.view.postChecks = checked2 ? "passed" : "failed";
38264
38468
  this.save(live2);
38265
38469
  if (!checked2) {
@@ -38281,7 +38485,7 @@ ${result.output}`}`);
38281
38485
  });
38282
38486
  });
38283
38487
  }
38284
- async assertStartable(live2, p) {
38488
+ async assertStartable(live2, p, stage) {
38285
38489
  this.current();
38286
38490
  if (!live2.execution.model)
38287
38491
  throw new ContractError("stale");
@@ -38289,9 +38493,15 @@ ${result.output}`}`);
38289
38493
  if (p.epoch !== this.o.owner.lease.registration.epoch || p.cwd !== live2.execution.cwd)
38290
38494
  throw new ContractError("stale");
38291
38495
  const writes = workflowWrites(p.plan);
38292
- if (live2.target)
38293
- await assertTarget(this.cwd, live2.target, writes);
38294
- else if (await contentsIdentityAsync(this.cwd, writes) !== live2.declared)
38496
+ if (live2.target) {
38497
+ const { branch, head: base } = live2.target;
38498
+ const head = live2.delivery?.frontierHead() ?? base;
38499
+ await assertTarget(this.cwd, { branch, head }, writes, stage);
38500
+ if (base !== head) {
38501
+ await this.assertSiblingScope(branch, base, head, writes, stage);
38502
+ this.assertGuidance(live2);
38503
+ }
38504
+ } else if (await contentsIdentityAsync(this.cwd, writes) !== live2.declared)
38295
38505
  throw new WorkflowRefusal("stale", "Declared targets changed between approval and start; nothing was edited.");
38296
38506
  }
38297
38507
  async investigate(live2, request3) {
@@ -38386,7 +38596,7 @@ Read only. Cite paths and distinguish evidence, assumptions, user decisions and
38386
38596
  if (live2.run.diagnostics)
38387
38597
  live2.run.diagnostics.acquiredAt = Date.now();
38388
38598
  if (live2.proposal) {
38389
- await this.assertStartable(live2, live2.proposal);
38599
+ await this.assertStartable(live2, live2.proposal, "start preflight");
38390
38600
  let environmentFile;
38391
38601
  live2.environment = new RunEnvironment(this.o.coordination.stateHome, this.cwd, (directories) => {
38392
38602
  environmentFile = this.write(this.path(live2.run.id, "environment.json"), { directories }, environmentFile);
@@ -38396,8 +38606,6 @@ Read only. Cite paths and distinguish evidence, assumptions, user decisions and
38396
38606
  throw new ContractError("unavailable");
38397
38607
  });
38398
38608
  }
38399
- if (live2.run.delivery)
38400
- live2.delivery = new WorkflowDelivery(live2.run.delivery, new RepositoryCoordination(this.o.coordination, this.cwd, live2.run.epoch, live2.run.id, () => this.o.owner.lease.assert(), () => this.o.owner.quarantine()), () => this.save(live2));
38401
38609
  live2.run.status = "running";
38402
38610
  this.save(live2);
38403
38611
  if (request3.action === "research") {
@@ -38414,8 +38622,13 @@ Read only. Cite paths and distinguish evidence, assumptions, user decisions and
38414
38622
  } catch (error) {
38415
38623
  outcome = this.o.owner.state === "quarantined" ? "unknown" : live2.abort.signal.aborted ? "canceled" : error instanceof WorkflowFailure && error.outcome !== "completed" ? error.outcome : "failed";
38416
38624
  failure2 = this.describe(error);
38625
+ const integration = live2.run.delivery?.integration;
38626
+ if (error instanceof WorkflowRefusal && integration?.status === "pending") {
38627
+ integration.status = "blocked";
38628
+ integration.reason = this.notice(failure2);
38629
+ }
38417
38630
  } finally {
38418
- if (live2.delivery && this.o.owner.state === "idle") {
38631
+ if (live2.delivery && live2.environment && this.o.owner.state === "idle") {
38419
38632
  try {
38420
38633
  live2.delivery.finish();
38421
38634
  } catch {
@@ -38925,7 +39138,7 @@ var processLifetime = {
38925
39138
  }
38926
39139
  };
38927
39140
  async function createServiceHost(value, sourceBuild, lifetime) {
38928
- const embedded = "190a21e723f753a233225a9f4bcf12a99d71b294a58728961846cd110cd60a17";
39141
+ const embedded = "80875479add4b7830419060b7e5018a39de200665edfbdec20fc10d50861bfea";
38929
39142
  if (embedded && sourceBuild)
38930
39143
  throw new ContractError("unsupported-context");
38931
39144
  const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);
@@ -39128,7 +39341,7 @@ async function createServiceHost(value, sourceBuild, lifetime) {
39128
39341
  authority: "local",
39129
39342
  csrf: null,
39130
39343
  capabilities: {
39131
- actions: !!workbench && !!choice.snapshot().selected,
39344
+ actions: ready2 && heldOwner.state === "idle" && !!workbench,
39132
39345
  manualChecks: false,
39133
39346
  history: true
39134
39347
  }
@@ -234,6 +234,14 @@ export function decodeId(v) {
234
234
  invalid();
235
235
  return s;
236
236
  }
237
+ /** Scalar bounds shared by model input and the (independently closed) owner read. */
238
+ export const knowledgeFields = Object.freeze({
239
+ checkout: (v) => list(v, 8, (entry) => text(entry, 1024, true)),
240
+ path: (v) => text(v, 1024, true),
241
+ section: (v) => text(v, 512, true),
242
+ match: (v) => text(v, 256, true),
243
+ investigation: decodeId,
244
+ });
237
245
  export function decodeHash(v) {
238
246
  const s = text(v, 64);
239
247
  if (!/^[0-9a-f]{64}$/.test(s)) invalid();