@adhdev/mesh-shared 1.0.82-rc.46 → 1.0.82-rc.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -755,9 +755,12 @@ var CANONICAL_MESH_TOOL_NAMES = [
755
755
  "mesh_enqueue_task",
756
756
  "mesh_view_queue",
757
757
  "mesh_queue_cancel",
758
+ "mesh_task_stage_decide",
758
759
  "mesh_direct_cancel",
759
760
  "mesh_queue_requeue",
760
761
  "mesh_queue_revise",
762
+ "mesh_light_land",
763
+ "mesh_light_discard",
761
764
  "mesh_send_task",
762
765
  "mesh_read_chat",
763
766
  "mesh_read_debug",
@@ -1717,6 +1720,16 @@ function isWorkerTool(value) {
1717
1720
  return typeof value === "string" && WORKER_TOOL_SET.has(value);
1718
1721
  }
1719
1722
  var WORKER_PROTOCOL_FOOTER_MARKER = "--- adhdev worker protocol ---";
1723
+ function renderLightWorkspaceRules(light) {
1724
+ const base = light.ossBaseSha ? `${light.baseSha} (oss ${light.ossBaseSha})` : light.baseSha;
1725
+ return [
1726
+ `You are working in a temporary light workspace at \`${light.workspace}\` based on \`${base}\`. Work only inside it. Commit your change there (the branch is already set up); do not push.`,
1727
+ "Do not run `npm install`/`npm ci`/`npm rebuild`/`node-gyp`, do not change package.json or lockfiles \u2014 if the fix needs a dependency change, stop and report `blocked`.",
1728
+ "Do not start long-running servers on fixed ports. Run the narrowest tests that cover your change and list them in `report_completion.testsRun`.",
1729
+ light.ownedPaths.length ? `Stay inside \`owned_paths\` (${light.ownedPaths.join(", ")}); if you must touch more, say why in the summary.` : "Stay inside the paths the task names; if you must touch more, say why in the summary."
1730
+ ];
1731
+ }
1732
+ var WORKER_CURRENT_BRANCH_RULE = "Commit your change on the branch that is currently checked out in this workspace. Do not create or switch branches (no `git checkout -b` / `git switch`) unless the task explicitly says to; report the branch you committed on.";
1720
1733
  function hasWorkerProtocolFooter(body) {
1721
1734
  return typeof body === "string" && body.includes(WORKER_PROTOCOL_FOOTER_MARKER);
1722
1735
  }
@@ -1738,6 +1751,8 @@ function renderWorkerProtocolFooter(input = {}) {
1738
1751
  if (input.readonly) scope.push("read-only");
1739
1752
  if (scope.length) lines.push(`You are a delegated worker (${scope.join(", ")}).`);
1740
1753
  else lines.push("You are a delegated worker.");
1754
+ if (input.light) lines.push(...renderLightWorkspaceRules(input.light));
1755
+ else if (input.commitOnCurrentBranch && input.stage?.role !== "review") lines.push(WORKER_CURRENT_BRANCH_RULE);
1741
1756
  if (input.workerMcp === false) {
1742
1757
  lines.push(
1743
1758
  "This session has NO adhdev worker tools (`report_completion`, `progress_update`, `peer_context_pull`, `git_*`) \u2014 do not look for them. When your work is finished, blocked, or has failed, end your turn with a plain final summary: what you did, what you found, which files you changed, and where you left the branch. That final message is what the coordinator receives.",
@@ -1765,8 +1780,21 @@ function renderWorkerProtocolFooter(input = {}) {
1765
1780
  `The ${input.enclosedHandoffNotes} handoff note(s) above were written by agents who touched this code before you; honour their conflict guidance and add your own in \`handoff_notes\` when you report.`
1766
1781
  );
1767
1782
  }
1783
+ if (input.stage) lines.push(...renderStageProtocolLines(input.stage));
1768
1784
  return lines.join("\n");
1769
1785
  }
1786
+ function renderStageProtocolLines(stage) {
1787
+ if (stage.role === "review") {
1788
+ return [
1789
+ `STAGE: you are the independent reviewer (round ${stage.round} of at most ${stage.maxRevisions + 1}). Read the input artifacts first (diff, self-check log, previous verdict).` + (stage.workspace ? ` Your workspace ${stage.workspace} is pinned to the round head \u2014 you may run tests, but nothing you change lands; do not fix, record findings instead.` : " Do not modify the workspace: read it, and record findings instead of fixing."),
1790
+ "Your `report_completion` MUST carry `review`: {verdict: approve | approve_with_nits | changes_requested | reject_approach, findings[{id, severity, category, claim, evidence, suggested_fix?}], checked[], not_checked[], tests_run?[]}. `changes_requested` needs at least one blocking/major finding; `approve` allows none. From round 2 also give `prior_findings[{id, status}]` for every earlier blocking/major finding. `reject_approach` is only for a wrong approach, not for fixable defects."
1791
+ ];
1792
+ }
1793
+ return [
1794
+ `STAGE: your \`report_completion\` is a stage report (${stage.role}, round ${stage.round}). An independent reviewer reads your diff next, so commit your work and leave the workspace clean before you report. You may receive review findings as a follow-up memo in this same session.`,
1795
+ ...stage.role === "revise" ? ["For every open blocking/major finding in the memo, fill `finding_responses[{id, response: fixed | disputed, note}]` \u2014 `disputed` needs your reasoning; the reviewer judges it next round."] : []
1796
+ ];
1797
+ }
1770
1798
  function stripWorkerProtocolFooter(body) {
1771
1799
  if (typeof body !== "string") return body;
1772
1800
  const at = body.indexOf(WORKER_PROTOCOL_FOOTER_MARKER);
@@ -2029,6 +2057,17 @@ function sanitizeRefusalCode(value) {
2029
2057
  if (!normalized) return void 0;
2030
2058
  return normalized.slice(0, 64);
2031
2059
  }
2060
+ var DISPATCH_REFUSAL_DETAIL_MAX = 200;
2061
+ function sanitizeDispatchRefusalDetail(code, message) {
2062
+ const cleanCode = sanitizeRefusalCode(code);
2063
+ let cleanMessage;
2064
+ if (typeof message === "string") {
2065
+ const line = message.replace(/(?:[A-Za-z]:)?[\\/](?:Users|home)[\\/][^\s\\/]+/g, "~").replace(/[\u0000-\u001f\u007f]+/g, " ").replace(/\s+/g, " ").trim();
2066
+ if (line) cleanMessage = line.length > DISPATCH_REFUSAL_DETAIL_MAX ? `${line.slice(0, DISPATCH_REFUSAL_DETAIL_MAX - 1)}\u2026` : line;
2067
+ }
2068
+ if (!cleanCode && !cleanMessage) return void 0;
2069
+ return { ...cleanCode ? { code: cleanCode } : {}, ...cleanMessage ? { message: cleanMessage } : {} };
2070
+ }
2032
2071
  var CONSUME_PROFILES = ["default", "native_source"];
2033
2072
  var SESSION_REBOUND_REASONS = ["restart", "live_holder"];
2034
2073
  var SUSPENSION_MODALS = ["approval", "choice"];
@@ -2103,6 +2142,8 @@ var TURN_REASONS = [
2103
2142
  "reclaim_budget_exhausted",
2104
2143
  "hollow_max_retries",
2105
2144
  "migration_orphan",
2145
+ // a stopping attempt whose writer node stayed unreachable (or was removed) past the bound
2146
+ "writer_unreachable",
2106
2147
  // reclaims (generation + 1)
2107
2148
  "dispatch_refused_session_exited",
2108
2149
  "dispatch_refused_no_target",
@@ -3076,13 +3117,14 @@ function isLedgerQueryEntryWire(value) {
3076
3117
  return true;
3077
3118
  }
3078
3119
  function isLedgerQuerySummaryWire(value) {
3079
- const keys = ["meshId", "totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskBlocked", "taskStalled", "sessionLaunched", "checkpointCreated", "lastActivityAt", "recentFailures"];
3120
+ const keys = ["meshId", "totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskBlocked", "taskStalled", "sessionLaunched", "checkpointCreated", "lastActivityAt", "recentFailures", "taskBlocked", "refineFailed"];
3080
3121
  if (!isRecord(value) || !hasOnlyKeys2(value, keys)) return false;
3081
3122
  if (!isEvidenceIdentifier(value.meshId)) return false;
3082
3123
  for (const k of ["totalEntries", "taskDispatched", "taskCompleted", "taskFailed", "taskStalled", "sessionLaunched", "checkpointCreated", "recentFailures"]) {
3083
3124
  if (!isNonNegativeInt(value[k])) return false;
3084
3125
  }
3085
3126
  if (value.taskBlocked !== void 0 && !isNonNegativeInt(value.taskBlocked)) return false;
3127
+ if (value.refineFailed !== void 0 && !isNonNegativeInt(value.refineFailed)) return false;
3086
3128
  if (value.lastActivityAt !== null && typeof value.lastActivityAt !== "string") return false;
3087
3129
  return true;
3088
3130
  }
@@ -4214,6 +4256,40 @@ function isProviderQuestionBinding(value) {
4214
4256
  return b.transport === "codex_async" ? b.requestId === void 0 : typeof b.requestId === "string" && !!b.requestId.trim() || typeof b.requestId === "number" && Number.isFinite(b.requestId);
4215
4257
  }
4216
4258
 
4259
+ // src/task-source-phase.ts
4260
+ function reviewIndependenceOf(review) {
4261
+ return review.independence ?? "different_provider";
4262
+ }
4263
+
4264
+ // src/light-task.ts
4265
+ var LIGHT_REJECT = {
4266
+ REQUIRES_LOCAL_BASE: "light_requires_local_base",
4267
+ NOT_CONFIGURED: "light_workspace_not_configured",
4268
+ REQUIRES_OWNED_PATHS: "light_requires_owned_paths",
4269
+ MODE_CONFLICT: "light_mode_conflict"
4270
+ };
4271
+ var LIGHT_HOLD = {
4272
+ PREPARE_FAILED: "light_workspace_prepare_failed",
4273
+ LIMIT: "light_workspace_limit",
4274
+ DISK_LOW: "light_workspace_disk_low",
4275
+ CAP: "max_light_parallel_tasks_reached"
4276
+ };
4277
+ var LIGHT_BLOCK_REASONS = [
4278
+ "light_uncommitted_changes",
4279
+ "light_dependency_change",
4280
+ "light_lineage_unproven",
4281
+ "shared_checkout_mutated"
4282
+ ];
4283
+ var LIGHT_WARNINGS = ["shared_checkout_changed_during_task", "light_base_dirty_overlap"];
4284
+ var LIGHT_LAND_MODES = ["refine", "apply_to_checkout"];
4285
+ var LIGHT_TESTS_RUN_MAX = 20;
4286
+ function isLightWorkerSession(session) {
4287
+ const s = session;
4288
+ if (!s || typeof s !== "object") return false;
4289
+ const has = (o) => !!o && typeof o === "object" && typeof o.lightWorkspaceId === "string" && o.lightWorkspaceId.trim() !== "";
4290
+ return has(s.settings) || has(s.launchRecord?.settings) || has(s);
4291
+ }
4292
+
4217
4293
  // src/relay-reprobe.ts
4218
4294
  var RELAY_REPROBE_BASE_DELAY_MS = 6e4;
4219
4295
  var RELAY_REPROBE_MAX_DELAY_MS = 5 * 6e4;
@@ -4293,6 +4369,289 @@ var RelayReprobeScheduler = class {
4293
4369
  this.schedule();
4294
4370
  }
4295
4371
  };
4372
+
4373
+ // src/task-stages.ts
4374
+ var REVIEW_VERDICTS = ["approve", "approve_with_nits", "changes_requested", "reject_approach"];
4375
+ var FINDING_SEVERITIES = ["blocking", "major", "minor", "nit"];
4376
+ var FINDING_CATEGORIES = ["correctness", "regression", "test_gap", "scope", "security", "performance", "maintainability"];
4377
+ var PRIOR_FINDING_STATUSES = ["resolved", "unresolved", "dispute_accepted", "dispute_rejected"];
4378
+ var FINDING_RESPONSE_KINDS = ["fixed", "disputed"];
4379
+ var STAGE_PHASES = ["implementing", "self_checking", "awaiting_review", "reviewing", "revising", "done"];
4380
+ var STAGE_PARKED_PHASES = ["self_checking", "awaiting_review", "reviewing"];
4381
+ var STAGE_INDEPENDENCE_MODES = ["different_provider", "fresh_session_ok"];
4382
+ var STAGE_ROLES = ["implement", "revise", "review"];
4383
+ var STAGE_BLOCKED_REASONS = [
4384
+ "review_unresolved",
4385
+ "review_rejected_approach",
4386
+ "review_unavailable",
4387
+ "self_check_failed",
4388
+ "stage_pipeline_ceiling",
4389
+ "reviewer_mutated_source",
4390
+ // The read-lease checkout could not be fingerprinted (start or end): the review's integrity cannot be verified.
4391
+ "reviewer_integrity_unverifiable"
4392
+ ];
4393
+ var STAGE_DECIDE_ACTIONS = ["accept", "revise_once", "rereview", "abandon"];
4394
+ var STAGE_MAX_REVISIONS_LIMIT = 3;
4395
+ var STAGE_DEFAULT_MAX_REVISIONS = 2;
4396
+ var STAGE_SELF_CHECK_MAX_BOUNCES = 2;
4397
+ var STAGE_INDEPENDENCE_FALLBACK_MS = 10 * 60 * 1e3;
4398
+ var STAGE_PIPELINE_CEILING_DEFAULT_MS = 4 * 60 * 60 * 1e3;
4399
+ var REVIEW_FINDINGS_MAX = 30;
4400
+ var REVIEW_CLAIM_MAX_CHARS = 500;
4401
+ var REVIEW_EVIDENCE_MAX_CHARS = 1e3;
4402
+ var REVIEW_FIX_MAX_CHARS = 500;
4403
+ var REVIEW_FINDING_ID_MAX_CHARS = 40;
4404
+ var REVIEW_CHECKED_MAX = 20;
4405
+ var REVIEW_NOTE_MAX_CHARS = 500;
4406
+ var REVIEW_TESTS_RUN_MAX = 20;
4407
+ var FINDING_RESPONSES_MAX = 30;
4408
+ function makeGuard4(values) {
4409
+ const set = new Set(values);
4410
+ return (value) => typeof value === "string" && set.has(value);
4411
+ }
4412
+ var isReviewVerdict = makeGuard4(REVIEW_VERDICTS);
4413
+ var isFindingSeverity = makeGuard4(FINDING_SEVERITIES);
4414
+ var isFindingCategory = makeGuard4(FINDING_CATEGORIES);
4415
+ var isPriorFindingStatus = makeGuard4(PRIOR_FINDING_STATUSES);
4416
+ var isFindingResponseKind = makeGuard4(FINDING_RESPONSE_KINDS);
4417
+ var isStageBlockedReason = makeGuard4(STAGE_BLOCKED_REASONS);
4418
+ var isRecord4 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
4419
+ function isBlockingSeverity(severity) {
4420
+ return severity === "blocking" || severity === "major";
4421
+ }
4422
+ function resolveStagePlan(raw, task, opts = {}) {
4423
+ const eligible = isStageEligibleTask(task);
4424
+ if (raw === void 0 || raw === null) return (opts.defaultOn ?? true) && defaultsOnFor(task) ? defaultStagePlan() : null;
4425
+ if (raw === false) return null;
4426
+ if (raw === true) {
4427
+ if (!eligible) throw new Error(`invalid_review_option: review requires a non-readonly code_change task (got taskMode=${task.taskMode ?? "unset"}${task.readonly ? ", readonly" : ""})`);
4428
+ return defaultStagePlan();
4429
+ }
4430
+ if (!isRecord4(raw)) throw new Error("invalid_review_option: review must be true, false or {max_revisions?, independence?}");
4431
+ const allowed = /* @__PURE__ */ new Set(["max_revisions", "maxRevisions", "independence"]);
4432
+ for (const key of Object.keys(raw)) {
4433
+ if (!allowed.has(key)) throw new Error(`invalid_review_option: unknown review key '${key}' (expected max_revisions, independence)`);
4434
+ }
4435
+ if (!eligible) throw new Error(`invalid_review_option: review requires a non-readonly code_change task (got taskMode=${task.taskMode ?? "unset"}${task.readonly ? ", readonly" : ""})`);
4436
+ const rawMax = raw.max_revisions ?? raw.maxRevisions;
4437
+ let maxRevisions = STAGE_DEFAULT_MAX_REVISIONS;
4438
+ if (rawMax !== void 0) {
4439
+ if (typeof rawMax !== "number" || !Number.isInteger(rawMax) || rawMax < 0 || rawMax > STAGE_MAX_REVISIONS_LIMIT) {
4440
+ throw new Error(`invalid_review_option: max_revisions must be an integer 0..${STAGE_MAX_REVISIONS_LIMIT}`);
4441
+ }
4442
+ maxRevisions = rawMax;
4443
+ }
4444
+ let independence = "fresh_session_ok";
4445
+ if (raw.independence !== void 0) {
4446
+ if (!STAGE_INDEPENDENCE_MODES.includes(raw.independence)) {
4447
+ throw new Error(`invalid_review_option: independence must be one of ${STAGE_INDEPENDENCE_MODES.join(" | ")}`);
4448
+ }
4449
+ independence = raw.independence;
4450
+ }
4451
+ return { review: true, maxRevisions, independence };
4452
+ }
4453
+ function defaultStagePlan() {
4454
+ return { review: true, maxRevisions: STAGE_DEFAULT_MAX_REVISIONS, independence: "fresh_session_ok" };
4455
+ }
4456
+ function isStageEligibleTask(task) {
4457
+ if (task.readonly) return false;
4458
+ return (task.taskMode ?? "code_change") === "code_change";
4459
+ }
4460
+ function defaultsOnFor(task) {
4461
+ return isStageEligibleTask(task) && (task.difficulty === "medium" || task.difficulty === "difficult");
4462
+ }
4463
+ function str2(value) {
4464
+ return typeof value === "string" ? value.trim() : "";
4465
+ }
4466
+ function validateStringList(value, field, max, maxChars, errors, minItems = 0) {
4467
+ if (!Array.isArray(value)) {
4468
+ errors.push({ field, message: `${field} must be an array of strings` });
4469
+ return [];
4470
+ }
4471
+ if (value.length > max) errors.push({ field, message: `${field} has ${value.length} entries, over the ${max} limit` });
4472
+ const out = [];
4473
+ for (const item of value) {
4474
+ const text = str2(item);
4475
+ if (!text) continue;
4476
+ if (text.length > maxChars) {
4477
+ errors.push({ field, message: `${field} contains an entry over ${maxChars} chars` });
4478
+ continue;
4479
+ }
4480
+ out.push(text);
4481
+ }
4482
+ if (out.length < minItems) errors.push({ field, message: `${field} needs at least ${minItems} entry \u2014 an empty ${field} list is a review with no recorded scope` });
4483
+ return out;
4484
+ }
4485
+ function validateReviewReport(raw, ctx) {
4486
+ const errors = [];
4487
+ if (!isRecord4(raw)) return { errors: [{ field: "review", message: "review must be an object {verdict, findings, checked, notChecked, ...}" }] };
4488
+ const KNOWN = /* @__PURE__ */ new Set(["verdict", "findings", "priorFindings", "checked", "notChecked", "testsRun"]);
4489
+ for (const key of Object.keys(raw)) if (!KNOWN.has(key)) errors.push({ field: `review.${key}`, message: `unknown field '${key}' (expected one of: ${[...KNOWN].join(", ")})` });
4490
+ const verdict = raw.verdict;
4491
+ if (!isReviewVerdict(verdict)) errors.push({ field: "review.verdict", message: `verdict must be one of ${REVIEW_VERDICTS.join(" | ")}` });
4492
+ const findings = [];
4493
+ if (!Array.isArray(raw.findings)) errors.push({ field: "review.findings", message: "findings must be an array (use [] when there are none)" });
4494
+ else {
4495
+ if (raw.findings.length > REVIEW_FINDINGS_MAX) errors.push({ field: "review.findings", message: `findings has ${raw.findings.length} entries, over the ${REVIEW_FINDINGS_MAX} limit \u2014 keep the most important` });
4496
+ const seen = /* @__PURE__ */ new Set();
4497
+ raw.findings.forEach((f, i) => {
4498
+ const at = `review.findings[${i}]`;
4499
+ if (!isRecord4(f)) {
4500
+ errors.push({ field: at, message: "each finding must be an object" });
4501
+ return;
4502
+ }
4503
+ const FK = /* @__PURE__ */ new Set(["id", "severity", "category", "file", "line", "claim", "evidence", "suggestedFix"]);
4504
+ for (const key of Object.keys(f)) if (!FK.has(key)) errors.push({ field: `${at}.${key}`, message: `unknown field '${key}'` });
4505
+ const id2 = str2(f.id);
4506
+ if (!id2 || id2.length > REVIEW_FINDING_ID_MAX_CHARS) errors.push({ field: `${at}.id`, message: `id is required (\u2264 ${REVIEW_FINDING_ID_MAX_CHARS} chars)` });
4507
+ else if (seen.has(id2)) errors.push({ field: `${at}.id`, message: `duplicate finding id '${id2}'` });
4508
+ else seen.add(id2);
4509
+ if (!isFindingSeverity(f.severity)) errors.push({ field: `${at}.severity`, message: `severity must be one of ${FINDING_SEVERITIES.join(" | ")}` });
4510
+ if (!isFindingCategory(f.category)) errors.push({ field: `${at}.category`, message: `category must be one of ${FINDING_CATEGORIES.join(" | ")}` });
4511
+ const claim = str2(f.claim);
4512
+ if (!claim) errors.push({ field: `${at}.claim`, message: "claim is required" });
4513
+ else if (claim.length > REVIEW_CLAIM_MAX_CHARS) errors.push({ field: `${at}.claim`, message: `claim is over ${REVIEW_CLAIM_MAX_CHARS} chars` });
4514
+ const evidence = str2(f.evidence);
4515
+ if (!evidence) errors.push({ field: `${at}.evidence`, message: "evidence is required \u2014 what did you read or run to know this" });
4516
+ else if (evidence.length > REVIEW_EVIDENCE_MAX_CHARS) errors.push({ field: `${at}.evidence`, message: `evidence is over ${REVIEW_EVIDENCE_MAX_CHARS} chars` });
4517
+ const fix = f.suggestedFix === void 0 ? void 0 : str2(f.suggestedFix);
4518
+ if (fix !== void 0 && fix.length > REVIEW_FIX_MAX_CHARS) errors.push({ field: `${at}.suggestedFix`, message: `suggestedFix is over ${REVIEW_FIX_MAX_CHARS} chars` });
4519
+ if (f.file !== void 0 && typeof f.file !== "string") errors.push({ field: `${at}.file`, message: "file must be a string" });
4520
+ if (f.line !== void 0 && (typeof f.line !== "number" || !Number.isInteger(f.line) || f.line < 1)) errors.push({ field: `${at}.line`, message: "line must be a positive integer" });
4521
+ if (id2 && isFindingSeverity(f.severity) && isFindingCategory(f.category) && claim && evidence) {
4522
+ findings.push({
4523
+ id: id2,
4524
+ severity: f.severity,
4525
+ category: f.category,
4526
+ ...typeof f.file === "string" && f.file.trim() ? { file: f.file.trim() } : {},
4527
+ ...typeof f.line === "number" ? { line: f.line } : {},
4528
+ claim,
4529
+ evidence,
4530
+ ...fix ? { suggestedFix: fix } : {}
4531
+ });
4532
+ }
4533
+ });
4534
+ }
4535
+ const checked = validateStringList(raw.checked, "review.checked", REVIEW_CHECKED_MAX, REVIEW_CLAIM_MAX_CHARS, errors, 1);
4536
+ const notChecked = validateStringList(raw.notChecked, "review.notChecked", REVIEW_CHECKED_MAX, REVIEW_CLAIM_MAX_CHARS, errors, 1);
4537
+ let priorFindings;
4538
+ if (raw.priorFindings !== void 0) {
4539
+ if (!Array.isArray(raw.priorFindings)) errors.push({ field: "review.priorFindings", message: "priorFindings must be an array" });
4540
+ else {
4541
+ priorFindings = [];
4542
+ raw.priorFindings.forEach((p, i) => {
4543
+ const at = `review.priorFindings[${i}]`;
4544
+ if (!isRecord4(p)) {
4545
+ errors.push({ field: at, message: "each entry must be an object {id, status, note?}" });
4546
+ return;
4547
+ }
4548
+ for (const key of Object.keys(p)) if (!["id", "status", "note"].includes(key)) errors.push({ field: `${at}.${key}`, message: `unknown field '${key}'` });
4549
+ const id2 = str2(p.id);
4550
+ if (!id2) errors.push({ field: `${at}.id`, message: "id is required" });
4551
+ if (!isPriorFindingStatus(p.status)) errors.push({ field: `${at}.status`, message: `status must be one of ${PRIOR_FINDING_STATUSES.join(" | ")}` });
4552
+ const note = p.note === void 0 ? void 0 : str2(p.note);
4553
+ if (note !== void 0 && note.length > REVIEW_NOTE_MAX_CHARS) errors.push({ field: `${at}.note`, message: `note is over ${REVIEW_NOTE_MAX_CHARS} chars` });
4554
+ if (id2 && isPriorFindingStatus(p.status)) priorFindings.push({ id: id2, status: p.status, ...note ? { note } : {} });
4555
+ });
4556
+ }
4557
+ }
4558
+ const testsRun = raw.testsRun === void 0 ? void 0 : validateTestsRun(raw.testsRun, "review.testsRun", errors);
4559
+ if (isReviewVerdict(verdict)) {
4560
+ const blocking = findings.filter((f) => isBlockingSeverity(f.severity));
4561
+ if (verdict === "changes_requested" && blocking.length === 0 && Array.isArray(raw.findings) && errors.length === 0) {
4562
+ errors.push({ field: "review.verdict", message: "changes_requested needs at least one blocking or major finding \u2014 nits alone are approve_with_nits" });
4563
+ }
4564
+ if (verdict === "approve" && blocking.length > 0) {
4565
+ errors.push({ field: "review.verdict", message: "approve cannot carry blocking or major findings" });
4566
+ }
4567
+ if (verdict === "approve_with_nits" && blocking.length > 0) {
4568
+ errors.push({ field: "review.verdict", message: "approve_with_nits cannot carry blocking or major findings \u2014 use changes_requested" });
4569
+ }
4570
+ }
4571
+ if (ctx.round >= 2 && ctx.priorOpenBlockingIds?.length) {
4572
+ const answered = new Set((priorFindings ?? []).map((p) => p.id));
4573
+ const missing = ctx.priorOpenBlockingIds.filter((id2) => !answered.has(id2));
4574
+ if (missing.length) errors.push({ field: "review.priorFindings", message: `round ${ctx.round} must give a status for every prior blocking/major finding; missing: ${missing.join(", ")}` });
4575
+ }
4576
+ if (errors.length) return { errors };
4577
+ return {
4578
+ report: {
4579
+ verdict,
4580
+ findings,
4581
+ ...priorFindings?.length ? { priorFindings } : {},
4582
+ checked,
4583
+ notChecked,
4584
+ ...testsRun?.length ? { testsRun } : {}
4585
+ },
4586
+ errors: []
4587
+ };
4588
+ }
4589
+ function validateTestsRun(raw, field, errors) {
4590
+ if (!Array.isArray(raw)) {
4591
+ errors.push({ field, message: `${field} must be an array of {command, exit, passed?, failed?, note?}` });
4592
+ return [];
4593
+ }
4594
+ if (raw.length > REVIEW_TESTS_RUN_MAX) errors.push({ field, message: `${field} has ${raw.length} entries, over the ${REVIEW_TESTS_RUN_MAX} limit` });
4595
+ const out = [];
4596
+ raw.forEach((t, i) => {
4597
+ const at = `${field}[${i}]`;
4598
+ if (!isRecord4(t)) {
4599
+ errors.push({ field: at, message: "each entry must be an object" });
4600
+ return;
4601
+ }
4602
+ for (const key of Object.keys(t)) if (!["command", "exit", "passed", "failed", "note"].includes(key)) errors.push({ field: `${at}.${key}`, message: `unknown field '${key}'` });
4603
+ const command = str2(t.command);
4604
+ if (!command || command.length > REVIEW_CLAIM_MAX_CHARS) errors.push({ field: `${at}.command`, message: `command is required (\u2264 ${REVIEW_CLAIM_MAX_CHARS} chars)` });
4605
+ if (typeof t.exit !== "number" || !Number.isInteger(t.exit)) errors.push({ field: `${at}.exit`, message: "exit must be an integer" });
4606
+ for (const k of ["passed", "failed"]) {
4607
+ if (t[k] !== void 0 && (typeof t[k] !== "number" || !Number.isInteger(t[k]) || t[k] < 0)) errors.push({ field: `${at}.${k}`, message: `${k} must be a non-negative integer` });
4608
+ }
4609
+ const note = t.note === void 0 ? void 0 : str2(t.note);
4610
+ if (note !== void 0 && note.length > REVIEW_NOTE_MAX_CHARS) errors.push({ field: `${at}.note`, message: `note is over ${REVIEW_NOTE_MAX_CHARS} chars` });
4611
+ if (command && typeof t.exit === "number") {
4612
+ out.push({
4613
+ command,
4614
+ exit: t.exit,
4615
+ ...typeof t.passed === "number" ? { passed: t.passed } : {},
4616
+ ...typeof t.failed === "number" ? { failed: t.failed } : {},
4617
+ ...note ? { note } : {}
4618
+ });
4619
+ }
4620
+ });
4621
+ return out;
4622
+ }
4623
+ function validateFindingResponses(raw, field = "findingResponses") {
4624
+ const errors = [];
4625
+ if (!Array.isArray(raw)) return { errors: [{ field, message: `${field} must be an array of {id, response, note}` }] };
4626
+ if (raw.length > FINDING_RESPONSES_MAX) errors.push({ field, message: `${field} has ${raw.length} entries, over the ${FINDING_RESPONSES_MAX} limit` });
4627
+ const out = [];
4628
+ raw.forEach((r, i) => {
4629
+ const at = `${field}[${i}]`;
4630
+ if (!isRecord4(r)) {
4631
+ errors.push({ field: at, message: "each entry must be an object {id, response, note}" });
4632
+ return;
4633
+ }
4634
+ for (const key of Object.keys(r)) if (!["id", "response", "note"].includes(key)) errors.push({ field: `${at}.${key}`, message: `unknown field '${key}'` });
4635
+ const id2 = str2(r.id);
4636
+ if (!id2) errors.push({ field: `${at}.id`, message: "id is required" });
4637
+ if (!isFindingResponseKind(r.response)) errors.push({ field: `${at}.response`, message: `response must be one of ${FINDING_RESPONSE_KINDS.join(" | ")}` });
4638
+ const note = str2(r.note);
4639
+ if (!note) errors.push({ field: `${at}.note`, message: "note is required \u2014 say what changed, or why you dispute it" });
4640
+ else if (note.length > REVIEW_NOTE_MAX_CHARS) errors.push({ field: `${at}.note`, message: `note is over ${REVIEW_NOTE_MAX_CHARS} chars` });
4641
+ if (id2 && isFindingResponseKind(r.response) && note && note.length <= REVIEW_NOTE_MAX_CHARS) out.push({ id: id2, response: r.response, note });
4642
+ });
4643
+ return errors.length ? { errors } : { responses: out, errors: [] };
4644
+ }
4645
+ function formatStageVerdictLine(input) {
4646
+ const parts = [`review: ${input.verdict}`];
4647
+ if (input.verdict === "skipped_no_diff") return parts[0];
4648
+ parts.push(`${input.rounds} round${input.rounds === 1 ? "" : "s"}`);
4649
+ if (input.reviewerProvider) parts.push(`reviewer ${input.reviewerProvider} (${input.independenceUsed ?? "different_provider"})`);
4650
+ const tail = [];
4651
+ if (input.fixed) tail.push(`${input.fixed} finding${input.fixed === 1 ? "" : "s"} fixed`);
4652
+ if (input.openNits) tail.push(`${input.openNits} nit${input.openNits === 1 ? "" : "s"} open`);
4653
+ return tail.length ? `${parts.join(" \xB7 ")} \xB7 ${tail.join(", ")}` : parts.join(" \xB7 ");
4654
+ }
4296
4655
  export {
4297
4656
  ASSISTANT_ACCOUNT_SLOT,
4298
4657
  ASSISTANT_FOLLOWER_ALLOWED_OPS,
@@ -4343,14 +4702,25 @@ export {
4343
4702
  DELIVERY_OUTCOMES,
4344
4703
  DELIVERY_VIAS,
4345
4704
  DISPATCH_FAILURE_REASONS,
4705
+ DISPATCH_REFUSAL_DETAIL_MAX,
4346
4706
  EVIDENCE_ENVELOPE_FIELD_SPECS,
4347
4707
  EVIDENCE_SOURCE_IDS,
4708
+ FINDING_CATEGORIES,
4709
+ FINDING_RESPONSES_MAX,
4710
+ FINDING_RESPONSE_KINDS,
4711
+ FINDING_SEVERITIES,
4348
4712
  HOLD_REASONS,
4349
4713
  LAUNCH_DEFAULTS_NEXT_LAUNCH_NOTE,
4350
4714
  LAUNCH_DEFAULT_ERROR_CODES,
4351
4715
  LAUNCH_DEFAULT_ROLES,
4352
4716
  LAUNCH_DEFAULT_SOURCES,
4353
4717
  LEGACY_CARRY_OVER_MISSION_TITLE,
4718
+ LIGHT_BLOCK_REASONS,
4719
+ LIGHT_HOLD,
4720
+ LIGHT_LAND_MODES,
4721
+ LIGHT_REJECT,
4722
+ LIGHT_TESTS_RUN_MAX,
4723
+ LIGHT_WARNINGS,
4354
4724
  LIVENESS_RESULTS,
4355
4725
  MAX_MESH_RECORD_STRING,
4356
4726
  MAX_OWNED_PATHS,
@@ -4408,6 +4778,7 @@ export {
4408
4778
  OWNER_ABANDON_CONFIRM_OPTIONS,
4409
4779
  OWNER_ABANDON_CONFIRM_QUESTION,
4410
4780
  P2P_SIGNAL_TYPES,
4781
+ PRIOR_FINDING_STATUSES,
4411
4782
  PROVIDER_FAILURES,
4412
4783
  QUOTA_BACKFILL_HORIZON_MS,
4413
4784
  QUOTA_RETRY_INFLIGHT_GRACE_MS,
@@ -4424,6 +4795,15 @@ export {
4424
4795
  RELEASE_MEMBER_STATES,
4425
4796
  REMOVED_MESH_TOOLS,
4426
4797
  RETIRED_MESH_TOOLS,
4798
+ REVIEW_CHECKED_MAX,
4799
+ REVIEW_CLAIM_MAX_CHARS,
4800
+ REVIEW_EVIDENCE_MAX_CHARS,
4801
+ REVIEW_FINDINGS_MAX,
4802
+ REVIEW_FINDING_ID_MAX_CHARS,
4803
+ REVIEW_FIX_MAX_CHARS,
4804
+ REVIEW_NOTE_MAX_CHARS,
4805
+ REVIEW_TESTS_RUN_MAX,
4806
+ REVIEW_VERDICTS,
4427
4807
  RelayReprobeScheduler,
4428
4808
  SEND_POLICY_MODES,
4429
4809
  SEND_REFUSAL_REASONS,
@@ -4437,6 +4817,17 @@ export {
4437
4817
  SESSION_STATUS_ALIASES,
4438
4818
  SESSION_STATUS_CLASS,
4439
4819
  SHARED_SESSION_TO_VIEWER_TYPES,
4820
+ STAGE_BLOCKED_REASONS,
4821
+ STAGE_DECIDE_ACTIONS,
4822
+ STAGE_DEFAULT_MAX_REVISIONS,
4823
+ STAGE_INDEPENDENCE_FALLBACK_MS,
4824
+ STAGE_INDEPENDENCE_MODES,
4825
+ STAGE_MAX_REVISIONS_LIMIT,
4826
+ STAGE_PARKED_PHASES,
4827
+ STAGE_PHASES,
4828
+ STAGE_PIPELINE_CEILING_DEFAULT_MS,
4829
+ STAGE_ROLES,
4830
+ STAGE_SELF_CHECK_MAX_BOUNCES,
4440
4831
  STATUS_PROBE_ARG_KEY,
4441
4832
  SUSPENSION_MODALS,
4442
4833
  SUSPENSION_RESOLUTIONS,
@@ -4463,6 +4854,7 @@ export {
4463
4854
  VIEWER_TO_SHARED_SESSION_TYPES,
4464
4855
  WORKER_BRANCH_STATES,
4465
4856
  WORKER_COMMITS_MAX,
4857
+ WORKER_CURRENT_BRANCH_RULE,
4466
4858
  WORKER_DECISIONS_NEEDED_MAX,
4467
4859
  WORKER_PROTOCOL_FOOTER_MARKER,
4468
4860
  WORKER_REPORT_OUTCOMES,
@@ -4544,6 +4936,7 @@ export {
4544
4936
  decodeUserSessionToDashboard,
4545
4937
  decodeViewerToSharedSession,
4546
4938
  defaultProviderPriorityFromNodeFacts,
4939
+ defaultStagePlan,
4547
4940
  deriveItemDedupeKey,
4548
4941
  deriveProviderPriorityFromSlots,
4549
4942
  deriveSlotsFromLegacy,
@@ -4558,6 +4951,7 @@ export {
4558
4951
  followedRemoteProjectKey,
4559
4952
  followerOpPermitted,
4560
4953
  formatQuotaAccount,
4954
+ formatStageVerdictLine,
4561
4955
  hasGitStatusEvidence,
4562
4956
  hasWorkerProtocolFooter,
4563
4957
  interpolateString,
@@ -4565,6 +4959,7 @@ export {
4565
4959
  isAssistantFollowerAllowedOp,
4566
4960
  isAssistantTool,
4567
4961
  isBlockedStatus,
4962
+ isBlockingSeverity,
4568
4963
  isBusyStatus,
4569
4964
  isCarryOverMissionRecord,
4570
4965
  isCarryOverMissionTitle,
@@ -4583,11 +4978,15 @@ export {
4583
4978
  isDeadStatus,
4584
4979
  isDowngrade,
4585
4980
  isEvidenceIdentifier,
4981
+ isFindingCategory,
4982
+ isFindingResponseKind,
4983
+ isFindingSeverity,
4586
4984
  isFiniteNumber,
4587
4985
  isIdleSessionState,
4588
4986
  isInputEnvelopeWire,
4589
4987
  isLaunchDefaultRole,
4590
4988
  isLaunchDefaultSource,
4989
+ isLightWorkerSession,
4591
4990
  isMeshDeliveryMode,
4592
4991
  isMeshIndexQueryResponse,
4593
4992
  isMeshMissionStatusValue,
@@ -4612,11 +5011,13 @@ export {
4612
5011
  isOutboundMessageOrigin,
4613
5012
  isP2PSignalType,
4614
5013
  isPhantomDaemonEntry,
5014
+ isPriorFindingStatus,
4615
5015
  isProviderQuestionBinding,
4616
5016
  isRawDaemonDoId,
4617
5017
  isReadyStatus,
4618
5018
  isRecord,
4619
5019
  isReleaseStatus,
5020
+ isReviewVerdict,
4620
5021
  isSendPolicy,
4621
5022
  isSendPolicyMode,
4622
5023
  isSendRefusal,
@@ -4625,6 +5026,8 @@ export {
4625
5026
  isSessionLaunchedBy,
4626
5027
  isSessionStatus,
4627
5028
  isSharedSessionToViewerType,
5029
+ isStageBlockedReason,
5030
+ isStageEligibleTask,
4628
5031
  isSubmitOutcome,
4629
5032
  isSummaryRef,
4630
5033
  isTerminalSessionRecordStatus,
@@ -4696,9 +5099,14 @@ export {
4696
5099
  readStringArray,
4697
5100
  readText,
4698
5101
  renderCoordinatorWorkerSection,
5102
+ renderLightWorkspaceRules,
4699
5103
  renderMissionBriefBlock,
5104
+ renderStageProtocolLines,
4700
5105
  renderWorkerProtocolFooter,
5106
+ resolveStagePlan,
4701
5107
  retiredMeshToolError,
5108
+ reviewIndependenceOf,
5109
+ sanitizeDispatchRefusalDetail,
4702
5110
  sanitizeModelIdentifier,
4703
5111
  sanitizeRefusalCode,
4704
5112
  sanitizeRemoteRepoIdentity,
@@ -4714,6 +5122,9 @@ export {
4714
5122
  touchedFilesOutsideOwnership,
4715
5123
  truncateMissionText,
4716
5124
  unwrapPastedContent,
5125
+ validateFindingResponses,
5126
+ validateReviewReport,
5127
+ validateTestsRun,
4717
5128
  withStatusProbeMarker
4718
5129
  };
4719
5130
  //# sourceMappingURL=index.mjs.map