@quikit/quikpilot-runner 9.3.0-rc.70 → 9.3.0-rc.72

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.js CHANGED
@@ -29584,8 +29584,8 @@ var isArray = Array.isArray || (function(obj) {
29584
29584
  return toString.call(obj) === "[object Array]";
29585
29585
  });
29586
29586
  var regexpCache = /* @__PURE__ */ Object.create(null);
29587
- function wordsRegexp(words) {
29588
- return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"));
29587
+ function wordsRegexp(words2) {
29588
+ return regexpCache[words2] || (regexpCache[words2] = new RegExp("^(?:" + words2.replace(/ /g, "|") + ")$"));
29589
29589
  }
29590
29590
  function codePointToString(code) {
29591
29591
  if (code <= 65535) {
@@ -42151,7 +42151,11 @@ var REASON_WORDS = {
42151
42151
  out_of_time: "the time allowed for writing the change ran out",
42152
42152
  // QUIKTR-1854: an existing test that QuikPilot cannot read pins the bug. QUIKTR-1855: JavaScript, TypeScript, Python, Go and Java test files can be read.
42153
42153
  test_unsupported_language: "an existing test expects what an approved case calls wrong, but QuikPilot could not read that test file to ask about it (it reads JavaScript, TypeScript, Python, Go and Java test files), so no change to it could be proposed",
42154
- test_conflict_unreportable: "an existing test expects what an approved case calls wrong, and it is written once for many rows, so no change to it could be proposed"
42154
+ test_conflict_unreportable: "an existing test expects what an approved case calls wrong, and it is written once for many rows, so no change to it could be proposed",
42155
+ // QUIKTR-2325 / QUIKTR-2326: the parts check. Only `part_missing` ends an attempt; the other two stop the run before any code.
42156
+ part_missing: "it said it was finished but had not built every part of the feature the design lists",
42157
+ part_not_placed: "the plan chose no file for a part of the feature the design lists",
42158
+ needs_database_change: "the feature needs a stored value (a database change) QuikPilot cannot make here"
42155
42159
  };
42156
42160
  function reasonInWords(reason) {
42157
42161
  return REASON_WORDS[reason] ?? reason;
@@ -42168,8 +42172,8 @@ function failedAttemptRecord(n, failure) {
42168
42172
  };
42169
42173
  }
42170
42174
  function attemptInWords(a, fallback) {
42171
- const words = a?.afterRecovery ? `${reasonInWords(a?.reason ?? fallback)}, a second time in a row, even after the AI was asked to take a smaller step` : reasonInWords(a?.reason ?? fallback);
42172
- return a?.runtimeCode && a.runtimeCode !== "other" ? `${words} (error code ${a.runtimeCode})` : words;
42175
+ const words2 = a?.afterRecovery ? `${reasonInWords(a?.reason ?? fallback)}, a second time in a row, even after the AI was asked to take a smaller step` : reasonInWords(a?.reason ?? fallback);
42176
+ return a?.runtimeCode && a.runtimeCode !== "other" ? `${words2} (error code ${a.runtimeCode})` : words2;
42173
42177
  }
42174
42178
  function exhaustedMessage(attempts, stop2, unreportable) {
42175
42179
  const first = attempts[0];
@@ -42198,8 +42202,14 @@ var CodegenAttemptsExhausted = class extends Error {
42198
42202
  stopReason;
42199
42203
  /** QUIKTR-1823: existing tests written once for many rows that stood in the way (path, line, case), when that is why the step ended. */
42200
42204
  unreportable;
42201
- constructor(attempts, stopReason, unreportable = []) {
42202
- super(exhaustedMessage(attempts, stopReason, unreportable));
42205
+ /**
42206
+ * QUIKTR-2325: `partsMissing` - the runner's own sentence naming the parts of the feature the last attempt did not build (`part_missing`).
42207
+ * It goes FIRST: QuikProjects explains a run's reason by how it starts ("A part of the feature was not built:"), and the attempts follow.
42208
+ * Built from the design's words and the planned paths; never a file's text.
42209
+ */
42210
+ constructor(attempts, stopReason, unreportable = [], partsMissing) {
42211
+ const message = exhaustedMessage(attempts, stopReason, unreportable);
42212
+ super(partsMissing ? `${partsMissing} ${message}` : message);
42203
42213
  this.name = "CodegenAttemptsExhausted";
42204
42214
  this.attempts = attempts;
42205
42215
  this.stopReason = stopReason;
@@ -47357,6 +47367,258 @@ function reviewAnswer(lines) {
47357
47367
  return { rules: ["done_rule"], violations: [...lines.slice(0, MAX_REVIEW_CASES), REVIEW_CLOSING], message: REVIEW_MESSAGE };
47358
47368
  }
47359
47369
 
47370
+ // src/scopeCheck.ts
47371
+ var import_node_fs16 = require("node:fs");
47372
+ var ROUTE_METHOD_RE = /\b(GET|POST|PUT|PATCH|DELETE)\b/i;
47373
+ var ROUTE_PATH_RE = /\/[A-Za-z0-9_\-{}[\]]+(?:\/[A-Za-z0-9_\-:{}[\]]+)+/;
47374
+ var ROUTE_EXPORT_RE = /\bexport\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/;
47375
+ var NO_PATH = "(this file's route)";
47376
+ function detectMentions(text3) {
47377
+ const found = [];
47378
+ for (const line of text3.split("\n")) {
47379
+ const methodMatch = ROUTE_METHOD_RE.exec(line);
47380
+ const pathMatch = ROUTE_PATH_RE.exec(line);
47381
+ if (methodMatch && pathMatch) {
47382
+ found.push({ method: methodMatch[1].toUpperCase(), path: pathMatch[0].replace(/:+$/, "") });
47383
+ }
47384
+ const exportMatch = ROUTE_EXPORT_RE.exec(line);
47385
+ if (exportMatch) {
47386
+ found.push({ method: exportMatch[1].toUpperCase(), path: NO_PATH });
47387
+ }
47388
+ }
47389
+ return found;
47390
+ }
47391
+ function normalizePath(path) {
47392
+ return path.replace(/:[A-Za-z0-9_]+|\{[^}]+\}|\[[^\]]+\]/g, "*");
47393
+ }
47394
+ function surfaceCovers(surface, mention) {
47395
+ if (!new RegExp(`\\b${mention.method}\\b`, "i").test(surface)) return false;
47396
+ if (mention.path === NO_PATH) return true;
47397
+ const declaredPath = normalizePath(surface);
47398
+ const mentionPath = normalizePath(mention.path);
47399
+ return declaredPath.includes(mentionPath) || mentionPath.includes(declaredPath);
47400
+ }
47401
+ function addedLines(before, after) {
47402
+ const beforeLines = new Set(before.split("\n"));
47403
+ return after.split("\n").filter((line) => !beforeLines.has(line)).join("\n");
47404
+ }
47405
+ function checkApiScope(results, targets, apiChanges) {
47406
+ const targetsByPath = new Map(targets.map((t) => [t.path, t]));
47407
+ const violations = [];
47408
+ for (const { targetPath, newContent } of results) {
47409
+ if (isTestFile(targetPath)) continue;
47410
+ const target = targetsByPath.get(targetPath);
47411
+ const isNewFile = target?.kind === "NEW_FILE";
47412
+ let scanned;
47413
+ if (isNewFile) {
47414
+ scanned = newContent;
47415
+ } else {
47416
+ let currentContent;
47417
+ try {
47418
+ currentContent = (0, import_node_fs16.readFileSync)(targetPath, "utf8");
47419
+ } catch {
47420
+ currentContent = "";
47421
+ }
47422
+ scanned = addedLines(currentContent, newContent);
47423
+ }
47424
+ for (const mention of detectMentions(scanned)) {
47425
+ if (!apiChanges.some((c) => surfaceCovers(c.surface, mention))) {
47426
+ violations.push({ file: targetPath, method: mention.method, path: mention.path });
47427
+ }
47428
+ }
47429
+ }
47430
+ return { blocked: violations.length > 0, violations };
47431
+ }
47432
+ function describeScopeViolations(check) {
47433
+ return check.violations.map((v) => `${v.file} adds ${v.method} ${v.path}, not declared in the design's API changes`).join("; ");
47434
+ }
47435
+
47436
+ // src/partsCheck.ts
47437
+ var PARTS_CHECK_ENV = "QUIKPILOT_PARTS_CHECK";
47438
+ function partsCheckOn(env2 = process.env) {
47439
+ return env2[PARTS_CHECK_ENV]?.trim().toLowerCase() === "on";
47440
+ }
47441
+ var PART_KINDS = ["endpoint", "screen", "data", "stored", "logic"];
47442
+ var MAX_PARTS = 8;
47443
+ var MAX_NAME_CHARS3 = 150;
47444
+ var MAX_WHAT_CHARS = 300;
47445
+ var PART_ID_RE = /^P\d+$/;
47446
+ var MARKER_RE = /\[(P\d+)(?:=(exists))?\]/g;
47447
+ function isRecord3(x) {
47448
+ return typeof x === "object" && x !== null && !Array.isArray(x);
47449
+ }
47450
+ function partsFromDesign(design) {
47451
+ if (!isRecord3(design) || !Array.isArray(design.parts)) return [];
47452
+ const raw = design.parts;
47453
+ if (raw.length === 0 || raw.length > MAX_PARTS) return [];
47454
+ const out2 = [];
47455
+ const ids = /* @__PURE__ */ new Set();
47456
+ for (const p of raw) {
47457
+ if (!isRecord3(p)) return [];
47458
+ const { id, kind, name: name2, what } = p;
47459
+ if (typeof id !== "string" || !PART_ID_RE.test(id) || ids.has(id)) return [];
47460
+ if (typeof kind !== "string" || !PART_KINDS.includes(kind)) return [];
47461
+ if (typeof name2 !== "string" || name2.trim() === "" || name2.length > MAX_NAME_CHARS3) return [];
47462
+ if (typeof what !== "string" || what.length > MAX_WHAT_CHARS) return [];
47463
+ ids.add(id);
47464
+ out2.push({ id, kind, name: name2, what });
47465
+ }
47466
+ return out2;
47467
+ }
47468
+ function designForTargeting(design, on) {
47469
+ if (on && partsFromDesign(design).length > 0) return { design, partsCheck: true };
47470
+ if (!design || !Object.prototype.hasOwnProperty.call(design, "parts")) return { design, partsCheck: false };
47471
+ const { parts: _parts, ...rest } = design;
47472
+ void _parts;
47473
+ return { design: rest, partsCheck: false };
47474
+ }
47475
+ function readMarks(targets) {
47476
+ const placed = /* @__PURE__ */ new Map();
47477
+ const exists = /* @__PURE__ */ new Set();
47478
+ for (const t of targets) {
47479
+ for (const step of t.planStepsImplemented ?? []) {
47480
+ if (typeof step !== "string") continue;
47481
+ for (const m of step.matchAll(MARKER_RE)) {
47482
+ if (m[2] === "exists") {
47483
+ exists.add(m[1]);
47484
+ continue;
47485
+ }
47486
+ const paths = placed.get(m[1]) ?? [];
47487
+ if (!paths.includes(t.path)) paths.push(t.path);
47488
+ placed.set(m[1], paths);
47489
+ }
47490
+ }
47491
+ }
47492
+ return { placed, exists };
47493
+ }
47494
+ function takenAsExisting(part, marks) {
47495
+ return part.kind === "stored" && marks.exists.has(part.id) && !marks.placed.has(part.id);
47496
+ }
47497
+ function existsMarked(parts2, targets) {
47498
+ const marks = readMarks(targets);
47499
+ const onlyExists = parts2.filter((p) => marks.exists.has(p.id) && !marks.placed.has(p.id));
47500
+ return {
47501
+ existing: onlyExists.filter((p) => takenAsExisting(p, marks)).map((p) => p.id),
47502
+ ignored: onlyExists.filter((p) => !takenAsExisting(p, marks)).map((p) => p.id)
47503
+ };
47504
+ }
47505
+ function words(text3) {
47506
+ return text3.trim().replace(/\s+/g, " ").replace(/[\s.;:,]+$/, "");
47507
+ }
47508
+ var STORED_STOP_START = "This feature needs a stored value QuikPilot cannot add here:";
47509
+ var NOT_PLACED_START = "No file was planned for a part of the feature:";
47510
+ var PART_MISSING_START = "A part of the feature was not built:";
47511
+ function storedSentence(stored) {
47512
+ const listed = stored.map((p) => `${words(p.name)} \u2014 ${words(p.what)}`).join("; ");
47513
+ return stored.length === 1 ? `${STORED_STOP_START} ${listed}. Add the field and its migration first, or narrow the feature.` : `${STORED_STOP_START} ${listed}. Add each field and its migration first, or narrow the feature.`;
47514
+ }
47515
+ function notPlacedSentence(parts2) {
47516
+ const listed = parts2.map((p) => `${p.id} ${words(p.name)} (${p.kind})`).join("; ");
47517
+ return `${NOT_PLACED_START} ${listed}. Nothing was written. Run it again, or narrow the feature.`;
47518
+ }
47519
+ function afterTargeting(parts2, targets) {
47520
+ if (parts2.length === 0) return null;
47521
+ const marks = readMarks(targets);
47522
+ const unplaced = parts2.filter((p) => !marks.placed.has(p.id) && !takenAsExisting(p, marks));
47523
+ if (unplaced.length === 0) return null;
47524
+ const stored = unplaced.filter((p) => p.kind === "stored");
47525
+ if (stored.length > 0) return { reason: "needs_database_change", ids: stored.map((p) => p.id), sentence: storedSentence(stored) };
47526
+ return { reason: "part_not_placed", ids: unplaced.map((p) => p.id), sentence: notPlacedSentence(unplaced) };
47527
+ }
47528
+ var PartsStopError = class extends Error {
47529
+ reason;
47530
+ ids;
47531
+ constructor(stop2) {
47532
+ super(stop2.sentence);
47533
+ this.name = "PartsStopError";
47534
+ this.reason = stop2.reason;
47535
+ this.ids = [...stop2.ids];
47536
+ }
47537
+ };
47538
+ function partsForCode(parts2, targets) {
47539
+ const marks = readMarks(targets);
47540
+ return parts2.filter((p) => !takenAsExisting(p, marks)).map((p) => ({ id: p.id, kind: p.kind, name: p.name, paths: marks.placed.get(p.id) ?? [] }));
47541
+ }
47542
+ function methodOf(name2) {
47543
+ const m = ROUTE_METHOD_RE.exec(name2);
47544
+ return m && m[1] === m[1].toUpperCase() ? m[1] : void 0;
47545
+ }
47546
+ function routeIsThePart(name2, mention) {
47547
+ const method = methodOf(name2);
47548
+ if (method && mention.method !== method) return false;
47549
+ const path = ROUTE_PATH_RE.exec(name2)?.[0]?.replace(/:+$/, "");
47550
+ if (!path) return true;
47551
+ return surfaceCovers(`${mention.method} ${path}`, mention);
47552
+ }
47553
+ function lastFixedSegment(name2) {
47554
+ const path = ROUTE_PATH_RE.exec(name2)?.[0]?.replace(/:+$/, "");
47555
+ if (!path) return void 0;
47556
+ const fixed = path.split("/").filter((s) => s && !/^[:{[]/.test(s));
47557
+ return fixed.length ? fixed[fixed.length - 1].toLowerCase() : void 0;
47558
+ }
47559
+ var EXPORTED_HANDLER_RE = /\bexport\s+(?:const|let|(?:async\s+)?function)\s+(GET|POST|PUT|PATCH|DELETE)\b/;
47560
+ function looseRouteIsThePart(name2, filePath, added) {
47561
+ const method = methodOf(name2);
47562
+ const segment = lastFixedSegment(name2);
47563
+ const hasSegment = (text3) => segment === void 0 || new RegExp(`(^|[^A-Za-z0-9_])${segment.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&")}([^A-Za-z0-9_]|$)`, "i").test(text3);
47564
+ const exported = EXPORTED_HANDLER_RE.exec(added);
47565
+ if (exported && (!method || exported[1] === method) && hasSegment(filePath.replace(/\\/g, "/"))) return true;
47566
+ if (segment === void 0) return false;
47567
+ const methodSaid = !method || new RegExp(`\\b${method}\\b`, "i").test(added);
47568
+ return methodSaid && hasSegment(added);
47569
+ }
47570
+ function missingAtDone(parts2, changed, addedLinesOf, isTest) {
47571
+ const changedSet = new Set(changed);
47572
+ const missing = [];
47573
+ for (const part of parts2) {
47574
+ const built = part.paths.filter((p) => changedSet.has(p) && !isTest(p));
47575
+ if (built.length === 0) {
47576
+ missing.push({ part, why: "unchanged" });
47577
+ continue;
47578
+ }
47579
+ if (part.kind === "endpoint" && !built.some((p) => {
47580
+ const added = addedLinesOf(p) ?? "";
47581
+ return detectMentions(added).some((m) => routeIsThePart(part.name, m)) || looseRouteIsThePart(part.name, p, added);
47582
+ })) {
47583
+ missing.push({ part, why: "no_route" });
47584
+ }
47585
+ }
47586
+ return missing;
47587
+ }
47588
+ var PARTS_MESSAGE = "Your answer was sent back: the approved design lists parts this feature needs, and your change does not build each one yet. Each sentence names a part and the files the plan chose for it. This check is made once.";
47589
+ function withFiles(build, paths) {
47590
+ for (let k = paths.length; k >= 1; k--) {
47591
+ const files = k === paths.length ? paths.join(", ") : `${paths.slice(0, k).join(", ")} and ${paths.length - k} more`;
47592
+ const sentence = build(files);
47593
+ if (sentence.length <= MAX_REFUSED_SENTENCE_CHARS) return sentence;
47594
+ }
47595
+ return build(paths.length > 0 ? paths[0] : "no file").slice(0, MAX_REFUSED_SENTENCE_CHARS);
47596
+ }
47597
+ function partSentence(m) {
47598
+ const head = `Part ${m.part.id} (${m.part.kind}) "${words(m.part.name)}" is not built: `;
47599
+ return m.why === "no_route" ? withFiles((files) => `${head}no route line for it was added in ${files}. Add the route there.`, m.part.paths) : withFiles((files) => `${head}none of its planned files was changed (${files}). Build it there.`, m.part.paths);
47600
+ }
47601
+ function partsAnswer(missing) {
47602
+ return { rules: ["done_rule"], violations: missing.slice(0, MAX_REFUSED_SENTENCES).map(partSentence), message: PARTS_MESSAGE };
47603
+ }
47604
+ function partMissingSentence(missing) {
47605
+ const item = (m, short) => {
47606
+ const paths = m.part.paths;
47607
+ const files = paths.length === 0 ? "no file" : short && paths.length > 1 ? `${paths[0]} and ${paths.length - 1} more` : paths.join(", ");
47608
+ return `${m.part.id} ${words(m.part.name)} (${m.part.kind}, ${m.why === "no_route" ? "no route added in" : "planned in"} ${files})`;
47609
+ };
47610
+ const fits = (s) => s.length <= MAX_REFUSED_SENTENCE_CHARS;
47611
+ for (const short of [false, true]) {
47612
+ const all = `${PART_MISSING_START} ${missing.map((m) => item(m, short)).join("; ")}.`;
47613
+ if (fits(all)) return all;
47614
+ }
47615
+ for (let k = missing.length - 1; k >= 1; k--) {
47616
+ const some = `${PART_MISSING_START} ${missing.slice(0, k).map((m) => item(m, true)).join("; ")}; and ${missing.length - k} more.`;
47617
+ if (fits(some)) return some;
47618
+ }
47619
+ return `${PART_MISSING_START} ${missing[0] ? item(missing[0], true) : ""}`.slice(0, MAX_REFUSED_SENTENCE_CHARS);
47620
+ }
47621
+
47360
47622
  // src/codegenLoop.ts
47361
47623
  var CODEGEN_LOOP_CONTRACT_VERSION = "codegen-loop-1";
47362
47624
  var CODEGEN_LOOP_2_CONTRACT_VERSION = "codegen-loop-2";
@@ -47601,6 +47863,7 @@ async function runCodegenLoop(args2, deps) {
47601
47863
  const redRuns = [];
47602
47864
  let redRefusals = 0;
47603
47865
  let importRefusals = 0;
47866
+ let partRefusals = 0;
47604
47867
  let proofSendBacks = 0;
47605
47868
  let giveUpRefusals = 0;
47606
47869
  let redUnproven;
@@ -48104,6 +48367,36 @@ async function runCodegenLoop(args2, deps) {
48104
48367
  throw new CodegenLoopFailure("syntax_error", void 0, void 0, sentence, sentence.slice(0, MAX_PREVIOUS_DETAIL_CHARS));
48105
48368
  }
48106
48369
  }
48370
+ if (args2.phase === "code" && args2.parts && args2.parts.length > 0) {
48371
+ const missingParts = missingAtDone(
48372
+ args2.parts,
48373
+ overlay.changedPaths(),
48374
+ (p) => {
48375
+ const entry = overlay.get(p);
48376
+ if (!entry) return null;
48377
+ return entry.created || entry.originalLf === null ? entry.lf : addedLines(entry.originalLf, entry.lf);
48378
+ },
48379
+ looksLikeTest
48380
+ );
48381
+ if (missingParts.length > 0) {
48382
+ const ids = missingParts.map((m) => m.part.id);
48383
+ if (partRefusals < 1 && !isFinal) {
48384
+ partRefusals += 1;
48385
+ const answer = partsAnswer(missingParts);
48386
+ refusedStreak += 1;
48387
+ refusedTurns.push({ turn, rules: answer.rules });
48388
+ log({ event: "codegen.parts_check", turn, outcome: "sent", parts: args2.parts.length, missing: missingParts.length, ids });
48389
+ transcript.push({ turn, toolCalls: [], refused: answer });
48390
+ if (refusedStreak >= REFUSED_STREAK_LIMIT) forced = "refused_repeatedly";
48391
+ forced = settleNextTurn(turn, forced);
48392
+ continue;
48393
+ }
48394
+ log({ event: "codegen.parts_check", turn, outcome: "missing", parts: args2.parts.length, missing: missingParts.length, ids });
48395
+ const sentence = partMissingSentence(missingParts);
48396
+ throw new CodegenLoopFailure("part_missing", void 0, void 0, sentence, sentence.slice(0, MAX_PREVIOUS_DETAIL_CHARS));
48397
+ }
48398
+ log({ event: "codegen.parts_check", turn, outcome: "ok", parts: args2.parts.length });
48399
+ }
48107
48400
  const doneSummary = typeof body2.summary === "string" ? body2.summary.slice(0, MAX_SUMMARY_CHARS) : "";
48108
48401
  const lane = args2.lane;
48109
48402
  if (harness && args2.phase === "code" && lane?.kind === "code" && !lane.amend && args2.keepOnGiveUp === true) {
@@ -48420,6 +48713,7 @@ async function runPhases(i3) {
48420
48713
  lane: { kind: "code", testPaths: i3.testPaths, frozen: tests.frozen },
48421
48714
  seed: tests.results,
48422
48715
  ...tests.proposals ? { seedProposals: tests.proposals } : {},
48716
+ ...i3.parts && i3.parts.length > 0 ? { parts: i3.parts } : {},
48423
48717
  keepOnGiveUp: true,
48424
48718
  previousAttempt: keptChange(i3.attempt, "tests_written", tests.answer, tests.steps)
48425
48719
  });
@@ -48740,7 +49034,7 @@ function buildCodegenLoopRecord(loop) {
48740
49034
  }
48741
49035
 
48742
49036
  // src/codegenLoopContext.ts
48743
- var import_node_fs16 = require("node:fs");
49037
+ var import_node_fs17 = require("node:fs");
48744
49038
 
48745
49039
  // src/langReach.ts
48746
49040
  var import_node_path19 = require("node:path");
@@ -49122,8 +49416,8 @@ function pairedTestPaths(codePath, listing, isTest = isTestTarget) {
49122
49416
  const stem = m[1].toLowerCase();
49123
49417
  const dir = dirOf2(codePath);
49124
49418
  const parent = parentOf(dir);
49125
- const join16 = (d, leaf) => d === "" ? leaf : `${d}/${leaf}`;
49126
- const homes = /* @__PURE__ */ new Set([dir, join16(dir, "__tests__"), join16(parent, "__tests__"), join16(parent, "tests"), join16(parent, "test")]);
49419
+ const join17 = (d, leaf) => d === "" ? leaf : `${d}/${leaf}`;
49420
+ const homes = /* @__PURE__ */ new Set([dir, join17(dir, "__tests__"), join17(parent, "__tests__"), join17(parent, "tests"), join17(parent, "test")]);
49127
49421
  const found = [];
49128
49422
  for (const path of listing) {
49129
49423
  if (!homes.has(dirOf2(path))) continue;
@@ -49136,7 +49430,7 @@ function asLf(text3) {
49136
49430
  return toLf(text3.charCodeAt(0) === 65279 ? text3.slice(1) : text3);
49137
49431
  }
49138
49432
  function collectLoopContext(p) {
49139
- const readFile = p.readFile ?? ((path) => (0, import_node_fs16.readFileSync)(path, "utf8"));
49433
+ const readFile = p.readFile ?? ((path) => (0, import_node_fs17.readFileSync)(path, "utf8"));
49140
49434
  const listing = new Set(p.listing);
49141
49435
  const mapSpecifier = p.mapSpecifier ?? createAliasMapper({
49142
49436
  readText: (path) => {
@@ -49303,7 +49597,7 @@ function mapModeMessage(phase, reason) {
49303
49597
  }
49304
49598
 
49305
49599
  // src/testsToCheck.ts
49306
- var import_node_fs17 = require("node:fs");
49600
+ var import_node_fs18 = require("node:fs");
49307
49601
  var import_node_path20 = require("node:path");
49308
49602
  var MAX_TESTS_TO_CHECK = 10;
49309
49603
  var SECOND_HOP_BELOW = 3;
@@ -49355,7 +49649,7 @@ function testsToCheck(i3) {
49355
49649
  }
49356
49650
  var readFromRoot = (root) => (rel) => {
49357
49651
  try {
49358
- return (0, import_node_fs17.readFileSync)((0, import_node_path20.join)(root, rel), "utf8");
49652
+ return (0, import_node_fs18.readFileSync)((0, import_node_path20.join)(root, rel), "utf8");
49359
49653
  } catch {
49360
49654
  return null;
49361
49655
  }
@@ -49544,9 +49838,10 @@ function keptAttempt(n, summary) {
49544
49838
  }
49545
49839
  var keptWarning = (n) => `The ${n === 1 ? "first" : "second"} attempt said it could not finish, but its change passed every check the AI is held to apart from the project's tests, so QuikPilot kept it and let the checks decide.`;
49546
49840
  var failedAttempt = failedAttemptRecord;
49547
- function lose(p, summary, attempts, stop2, unreportable) {
49841
+ function lose(p, summary, attempts, stop2, unreportable, failures = []) {
49548
49842
  p.out.loop = buildCodegenLoopRecord({ ...summary ?? NO_SUMMARY, stopReason: stop2, attempts });
49549
- return new CodegenAttemptsExhausted(attempts, stop2, unreportable);
49843
+ const partsMissing = [...failures].reverse().find((f) => f.reason === "part_missing")?.detail;
49844
+ return new CodegenAttemptsExhausted(attempts, stop2, unreportable, partsMissing);
49550
49845
  }
49551
49846
  function oldCodeRunner(args2, log, now, wholeSuite = false) {
49552
49847
  return async (files) => {
@@ -49636,6 +49931,7 @@ async function runCodegenStep(p) {
49636
49931
  testPaths: testTargetPaths(p.targets, discoveredTestsOf(p.testDiscovery)),
49637
49932
  redCheckIds: checkableIds(args2.requiredAutomationIds, p.requiredTestTypes),
49638
49933
  ...p.redReview === true ? { redReview: true } : {},
49934
+ ...p.parts && p.parts.length > 0 ? { parts: p.parts } : {},
49639
49935
  run: (a) => runCodegenLoop(a, loopDeps),
49640
49936
  ...args2.tests ? { onOldCode: oldCodeRunner(args2, log, now) } : {},
49641
49937
  log
@@ -49752,14 +50048,14 @@ async function runCodegenStep(p) {
49752
50048
  }
49753
50049
  await guardTree();
49754
50050
  const firstRecord = failedAttempt(1, f1);
49755
- if ("final" in first && first.final) throw lose(p, f1.summary, [firstRecord], "failed");
50051
+ if ("final" in first && first.final) throw lose(p, f1.summary, [firstRecord], "failed", void 0, [f1]);
49756
50052
  if (f1.reason === "test_conflict_unreportable") throw lose(p, f1.summary, [firstRecord], "failed", f1.unreportable);
49757
50053
  const testLimit = p.mode === "loop-tests" && p.tests ? await oneTestRunMs(p.tests) : null;
49758
50054
  const left = hardStopAtMs - now();
49759
50055
  const needed = secondAttemptFloorMs({ firstAttemptMs: firstMs, testLimitMs: testLimit });
49760
50056
  if (f1.reason === "out_of_time" || left < needed) {
49761
50057
  log({ event: "codegen.attempt_skipped", attempt: 2, reason: "out_of_time", leftMs: Math.max(0, left), neededMs: needed });
49762
- throw lose(p, f1.summary, [firstRecord, { n: 2, outcome: "not_started", reason: "out_of_time", turns: 0, toolCalls: 0 }], "out_of_time");
50058
+ throw lose(p, f1.summary, [firstRecord, { n: 2, outcome: "not_started", reason: "out_of_time", turns: 0, toolCalls: 0 }], "out_of_time", void 0, [f1]);
49763
50059
  }
49764
50060
  warn(p, `The first attempt at writing the change ended (${f1.reason}${said}), so QuikPilot is trying once more.`);
49765
50061
  const previous = { ...previousAttemptFrom(f1, 1), ...f1.steps && f1.steps.steps.length > 0 ? f1.steps : {} };
@@ -49785,11 +50081,11 @@ async function runCodegenStep(p) {
49785
50081
  }
49786
50082
  const f2 = second.failure;
49787
50083
  log({ event: "codegen.attempt_end", attempt: 2, outcome: "failed", reason: f2.reason, ...f2.afterRecovery ? { afterRecovery: true } : {}, turns: f2.summary?.turns ?? 0, toolCalls: f2.summary?.toolCalls ?? 0, durationMs: secondMs });
49788
- throw lose(p, f2.summary, [firstRecord, failedAttempt(2, f2)], f2.reason === "out_of_time" ? "out_of_time" : "failed", f2.unreportable);
50084
+ throw lose(p, f2.summary, [firstRecord, failedAttempt(2, f2)], f2.reason === "out_of_time" ? "out_of_time" : "failed", f2.unreportable, [f1, f2]);
49789
50085
  }
49790
50086
 
49791
50087
  // src/codegenHeal.ts
49792
- var import_node_fs18 = require("node:fs");
50088
+ var import_node_fs19 = require("node:fs");
49793
50089
 
49794
50090
  // src/heal.ts
49795
50091
  var MAX_ATTEMPTS_IN_ALL = 3;
@@ -49869,7 +50165,7 @@ async function runHealAttempt(i3) {
49869
50165
  const created = i3.results.map((r) => r.targetPath).filter((path) => !listed.has(path));
49870
50166
  const workspaceListing = [...p.workspaceListing, ...created];
49871
50167
  const targets = p.targets.map((t) => t.kind === "NEW_FILE" && keptText.has(t.path) ? { ...t, kind: "EXISTING" } : t);
49872
- const disk = p.readFile ?? ((path) => (0, import_node_fs18.readFileSync)(path, "utf8"));
50168
+ const disk = p.readFile ?? ((path) => (0, import_node_fs19.readFileSync)(path, "utf8"));
49873
50169
  const readFile = (path) => keptText.get(path) ?? disk(path);
49874
50170
  const discoveredTests = discoveredTestsOf(p.testDiscovery);
49875
50171
  const context = collectLoopContext({ targets, listing: workspaceListing, deniedPaths: p.deniedPaths, writeRoot: p.writeRoot ?? "", ...discoveredTests ? { discoveredTests } : {}, readFile });
@@ -50133,74 +50429,6 @@ async function runVerifyAndFix(p) {
50133
50429
  var import_node_child_process9 = require("node:child_process");
50134
50430
  var import_node_fs20 = require("node:fs");
50135
50431
  var import_node_path21 = require("node:path");
50136
-
50137
- // src/scopeCheck.ts
50138
- var import_node_fs19 = require("node:fs");
50139
- var ROUTE_METHOD_RE = /\b(GET|POST|PUT|PATCH|DELETE)\b/i;
50140
- var ROUTE_PATH_RE = /\/[A-Za-z0-9_\-{}[\]]+(?:\/[A-Za-z0-9_\-:{}[\]]+)+/;
50141
- var ROUTE_EXPORT_RE = /\bexport\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/;
50142
- var NO_PATH = "(this file's route)";
50143
- function detectMentions(text3) {
50144
- const found = [];
50145
- for (const line of text3.split("\n")) {
50146
- const methodMatch = ROUTE_METHOD_RE.exec(line);
50147
- const pathMatch = ROUTE_PATH_RE.exec(line);
50148
- if (methodMatch && pathMatch) {
50149
- found.push({ method: methodMatch[1].toUpperCase(), path: pathMatch[0].replace(/:+$/, "") });
50150
- }
50151
- const exportMatch = ROUTE_EXPORT_RE.exec(line);
50152
- if (exportMatch) {
50153
- found.push({ method: exportMatch[1].toUpperCase(), path: NO_PATH });
50154
- }
50155
- }
50156
- return found;
50157
- }
50158
- function normalizePath(path) {
50159
- return path.replace(/:[A-Za-z0-9_]+|\{[^}]+\}|\[[^\]]+\]/g, "*");
50160
- }
50161
- function surfaceCovers(surface, mention) {
50162
- if (!new RegExp(`\\b${mention.method}\\b`, "i").test(surface)) return false;
50163
- if (mention.path === NO_PATH) return true;
50164
- const declaredPath = normalizePath(surface);
50165
- const mentionPath = normalizePath(mention.path);
50166
- return declaredPath.includes(mentionPath) || mentionPath.includes(declaredPath);
50167
- }
50168
- function addedLines(before, after) {
50169
- const beforeLines = new Set(before.split("\n"));
50170
- return after.split("\n").filter((line) => !beforeLines.has(line)).join("\n");
50171
- }
50172
- function checkApiScope(results, targets, apiChanges) {
50173
- const targetsByPath = new Map(targets.map((t) => [t.path, t]));
50174
- const violations = [];
50175
- for (const { targetPath, newContent } of results) {
50176
- if (isTestFile(targetPath)) continue;
50177
- const target = targetsByPath.get(targetPath);
50178
- const isNewFile = target?.kind === "NEW_FILE";
50179
- let scanned;
50180
- if (isNewFile) {
50181
- scanned = newContent;
50182
- } else {
50183
- let currentContent;
50184
- try {
50185
- currentContent = (0, import_node_fs19.readFileSync)(targetPath, "utf8");
50186
- } catch {
50187
- currentContent = "";
50188
- }
50189
- scanned = addedLines(currentContent, newContent);
50190
- }
50191
- for (const mention of detectMentions(scanned)) {
50192
- if (!apiChanges.some((c) => surfaceCovers(c.surface, mention))) {
50193
- violations.push({ file: targetPath, method: mention.method, path: mention.path });
50194
- }
50195
- }
50196
- }
50197
- return { blocked: violations.length > 0, violations };
50198
- }
50199
- function describeScopeViolations(check) {
50200
- return check.violations.map((v) => `${v.file} adds ${v.method} ${v.path}, not declared in the design's API changes`).join("; ");
50201
- }
50202
-
50203
- // src/hunkCheck.ts
50204
50432
  var MAX_REPORTED_HUNKS = 20;
50205
50433
  function toFinding(r) {
50206
50434
  if (r.unnecessary.length === 0) return void 0;
@@ -50759,7 +50987,7 @@ function describeAutomationCoverageViolations(check) {
50759
50987
  var estraverse5 = __toESM2(require_estraverse());
50760
50988
  var MAX_UNSUPPLIED_ENTRIES = 10;
50761
50989
  var MAX_UNSUPPLIED_NAMES = 5;
50762
- var MAX_NAME_CHARS3 = 80;
50990
+ var MAX_NAME_CHARS4 = 80;
50763
50991
  var MAX_FUNCTION_CHARS = 120;
50764
50992
  var FUNCTION_TYPES = /* @__PURE__ */ new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
50765
50993
  var IDENTIFIER_NAME = /^[A-Za-z_$][\w$]*$/;
@@ -50900,7 +51128,7 @@ function findUnsuppliedInputs(input) {
50900
51128
  if (isCallback(site)) continue;
50901
51129
  const names = [];
50902
51130
  for (const { name: name2 } of readsOf(site)) {
50903
- if (!IDENTIFIER_NAME.test(name2) || name2.length > MAX_NAME_CHARS3) continue;
51131
+ if (!IDENTIFIER_NAME.test(name2) || name2.length > MAX_NAME_CHARS4) continue;
50904
51132
  if (known.has(name2) || supplied.has(name2) || names.includes(name2)) continue;
50905
51133
  names.push(name2);
50906
51134
  }
@@ -51183,6 +51411,7 @@ async function verifyChange(ctx, results, undoable) {
51183
51411
  }
51184
51412
 
51185
51413
  // src/guardrail.ts
51414
+ var MAX_LEFT_OUT_NAMES2 = 10;
51186
51415
  function checkGuardrail(deniedPaths, writeRoot = "") {
51187
51416
  addAll(writeRoot || void 0);
51188
51417
  const violations = deniedPaths.flatMap((pattern) => diffCachedNamesMatching(pattern));
@@ -51190,11 +51419,15 @@ function checkGuardrail(deniedPaths, writeRoot = "") {
51190
51419
  throw new Error(`QuikPilot touched denied paths:
51191
51420
  ${violations.join("\n")}`);
51192
51421
  }
51193
- return { leftOut: writeRoot ? changedOutside(writeRoot).length : 0 };
51422
+ if (!writeRoot) return { leftOut: 0, names: [], hidden: 0 };
51423
+ const outside = changedOutside(writeRoot);
51424
+ const protectedPatterns = readDenied(deniedPaths);
51425
+ const nameable = outside.filter((path) => matchesDeniedPath(path, protectedPatterns) === null);
51426
+ return { leftOut: outside.length, names: nameable.slice(0, MAX_LEFT_OUT_NAMES2), hidden: outside.length - nameable.length };
51194
51427
  }
51195
51428
 
51196
51429
  // src/run.ts
51197
- var import_node_fs26 = require("node:fs");
51430
+ var import_node_fs27 = require("node:fs");
51198
51431
 
51199
51432
  // src/mapMode.ts
51200
51433
  var MAP_ENV = "QUIKPILOT_MAP";
@@ -51768,7 +52001,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
51768
52001
  var REPORT_COPY = "final-test-report.xml";
51769
52002
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
51770
52003
  var MAX_FILES = 200;
51771
- var RUNNER_VERSION = true ? "9.3.0-rc.70" : "dev";
52004
+ var RUNNER_VERSION = true ? "9.3.0-rc.72" : "dev";
51772
52005
  function safeDestination(base, repoPath) {
51773
52006
  if (!repoPath || (0, import_node_path26.isAbsolute)(repoPath)) return null;
51774
52007
  const destination = (0, import_node_path26.resolve)(base, repoPath);
@@ -51849,6 +52082,35 @@ function writeFailureArtifact(input) {
51849
52082
  }
51850
52083
  }
51851
52084
 
52085
+ // src/finalChange.ts
52086
+ var import_node_child_process12 = require("node:child_process");
52087
+ var import_node_fs26 = require("node:fs");
52088
+ var import_node_path27 = require("node:path");
52089
+ function changesAgainstBase(root, wanted) {
52090
+ if (wanted.size === 0) return [];
52091
+ const status = (0, import_node_child_process12.execFileSync)("git", ["status", "--porcelain", "-z", "--untracked-files=all", "--no-renames"], {
52092
+ cwd: root,
52093
+ encoding: "utf8",
52094
+ maxBuffer: 64 * 1024 * 1024
52095
+ });
52096
+ const changed = new Set(
52097
+ status.split("\0").filter((entry) => entry.length > 3).map((entry) => entry.slice(3))
52098
+ );
52099
+ const out2 = [];
52100
+ for (const path of [...wanted].sort()) {
52101
+ if (!changed.has(path)) continue;
52102
+ let current2;
52103
+ try {
52104
+ current2 = (0, import_node_fs26.readFileSync)((0, import_node_path27.join)(root, path), "utf8").replace(/\r\n/g, "\n");
52105
+ } catch {
52106
+ continue;
52107
+ }
52108
+ const base = readCommittedText(root, path);
52109
+ out2.push({ path, added: base === null ? current2 : addedLines(base.replace(/\r\n/g, "\n"), current2) });
52110
+ }
52111
+ return out2;
52112
+ }
52113
+
51852
52114
  // src/testDiscovery.ts
51853
52115
  var ABSENT = { report: "ABSENT" };
51854
52116
  var DRIVE_RE = /^[A-Za-z]:\//;
@@ -51962,12 +52224,12 @@ async function resolveTestDiscovery(i3) {
51962
52224
  }
51963
52225
 
51964
52226
  // src/targetingFindings.ts
51965
- var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
52227
+ var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
51966
52228
  function prepareTargetingFindings(raw, listing, deniedPaths) {
51967
- if (!isRecord3(raw)) return void 0;
52229
+ if (!isRecord4(raw)) return void 0;
51968
52230
  const { verdict, files, callPath, evidence, searches } = raw;
51969
52231
  if (typeof verdict !== "string" || !Array.isArray(files) || !Array.isArray(callPath) || !Array.isArray(evidence)) return void 0;
51970
- const keep = (entry) => isRecord3(entry) && typeof entry.path === "string" && listing.has(entry.path) && matchesDeniedPath(entry.path, deniedPaths) === null;
52232
+ const keep = (entry) => isRecord4(entry) && typeof entry.path === "string" && listing.has(entry.path) && matchesDeniedPath(entry.path, deniedPaths) === null;
51971
52233
  const kept = {
51972
52234
  files: files.filter(keep),
51973
52235
  callPath: callPath.filter(keep),
@@ -52021,7 +52283,7 @@ function validateTarget(target, workspaceRoot, workspaceListing, deniedPaths) {
52021
52283
  );
52022
52284
  }
52023
52285
  }
52024
- function buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings) {
52286
+ function buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck = false) {
52025
52287
  const contextData = {
52026
52288
  // NESTED, NOT FLATTENED — a second vocabulary for the design shape is exactly what
52027
52289
  // QUIKTR-1034 cost.
@@ -52044,6 +52306,9 @@ function buildContextData(design, workspaceListing, requiredTests, deniedPaths,
52044
52306
  if (findings) {
52045
52307
  contextData.findings = findings;
52046
52308
  }
52309
+ if (partsCheck) {
52310
+ contextData.partsCheck = true;
52311
+ }
52047
52312
  return contextData;
52048
52313
  }
52049
52314
  async function postTargeting(gateway, contextData, signal) {
@@ -52093,14 +52358,14 @@ function finalizeTargeting(body2, workspaceRoot, workspaceListing, deniedPaths)
52093
52358
  ...correctedKinds.length > 0 ? { correctedKinds } : {}
52094
52359
  };
52095
52360
  }
52096
- async function runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope = [], findings) {
52097
- const contextData = buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
52361
+ async function runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope = [], findings, partsCheck = false) {
52362
+ const contextData = buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck);
52098
52363
  let envelope = await postTargeting(gateway, contextData);
52099
52364
  let warnings;
52100
52365
  if (findings && envelope?.errorCode === "CONTRACT_REJECTED") {
52101
52366
  envelope = await postTargeting(
52102
52367
  gateway,
52103
- buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope)
52368
+ buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, void 0, partsCheck)
52104
52369
  );
52105
52370
  warnings = ["QuikPilot's targeting ran without the early look's findings (the AI service did not accept them)."];
52106
52371
  }
@@ -52136,15 +52401,18 @@ async function loopWithTools2(args2, tools2, deps) {
52136
52401
  }
52137
52402
  var CODE_LIKE = /^[A-Z0-9_]{1,40}$/;
52138
52403
  async function runTargeting(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope = [], options = {}) {
52404
+ const wired = designForTargeting(design, options.partsCheck === true);
52405
+ design = wired.design;
52406
+ const partsCheck = wired.partsCheck;
52139
52407
  if (options.scope?.view === "map") {
52140
- return runMapTargeting(gateway, design, workspaceRoot, options.scope, requiredTests, deniedPaths, testDiscovery, outOfScope, options);
52408
+ return runMapTargeting(gateway, design, workspaceRoot, options.scope, requiredTests, deniedPaths, testDiscovery, outOfScope, options, partsCheck);
52141
52409
  }
52142
52410
  const mode = options.mode ?? resolveTargetingMode();
52143
52411
  const findings = prepareTargetingFindings(options.findings, new Set(workspaceListing), deniedPaths);
52144
52412
  if (mode !== "loop") {
52145
- return runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
52413
+ return runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck);
52146
52414
  }
52147
- const baseContext = buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
52415
+ const baseContext = buildContextData(design, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck);
52148
52416
  const listingView = repoViewOf(options.scope);
52149
52417
  let summary;
52150
52418
  let runtimeCode;
@@ -52191,7 +52459,7 @@ async function runTargeting(gateway, design, workspaceRoot, workspaceListing, re
52191
52459
  toolCalls: fellBack.toolCalls,
52192
52460
  ...runtimeCode && CODE_LIKE.test(runtimeCode) ? { runtimeCode } : {}
52193
52461
  });
52194
- const single = await runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
52462
+ const single = await runSingleShot(gateway, design, workspaceRoot, workspaceListing, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck);
52195
52463
  return {
52196
52464
  ...single,
52197
52465
  loop: fellBack,
@@ -52204,7 +52472,7 @@ function mapTestDiscovery(testDiscovery) {
52204
52472
  if (estimateTokens(JSON.stringify(testDiscovery.discoveredTestFiles, null, 2)) <= MAP_DISCOVERY_MAX_TOKENS) return testDiscovery;
52205
52473
  return { report: "PRESENT", discoveredTestFiles: [], unmappedEntries: Math.max(1, testDiscovery.unmappedEntries + testDiscovery.discoveredTestFiles.length) };
52206
52474
  }
52207
- function buildMapContextData(repoMap, design, requiredTests, deniedPaths, testDiscovery, outOfScope, findings) {
52475
+ function buildMapContextData(repoMap, design, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck = false) {
52208
52476
  return {
52209
52477
  repoMap,
52210
52478
  design,
@@ -52213,12 +52481,13 @@ function buildMapContextData(repoMap, design, requiredTests, deniedPaths, testDi
52213
52481
  ...deniedPaths.length > 0 ? { deniedPaths } : {},
52214
52482
  ...outOfScope.length > 0 ? { outOfScope } : {},
52215
52483
  testDiscovery: mapTestDiscovery(testDiscovery),
52216
- ...findings ? { findings } : {}
52484
+ ...findings ? { findings } : {},
52485
+ ...partsCheck ? { partsCheck: true } : {}
52217
52486
  };
52218
52487
  }
52219
- async function runMapTargeting(gateway, design, workspaceRoot, scope, requiredTests, deniedPaths, testDiscovery, outOfScope, options) {
52488
+ async function runMapTargeting(gateway, design, workspaceRoot, scope, requiredTests, deniedPaths, testDiscovery, outOfScope, options, partsCheck) {
52220
52489
  const findings = prepareTargetingFindings(options.findings, new Set(scope.readListing), deniedPaths);
52221
- const baseContext = buildMapContextData(scope.repoMap, design, requiredTests, deniedPaths, testDiscovery, outOfScope, findings);
52490
+ const baseContext = buildMapContextData(scope.repoMap, design, requiredTests, deniedPaths, testDiscovery, outOfScope, findings, partsCheck);
52222
52491
  const repoView = repoViewOf(scope);
52223
52492
  const log = options.loopDeps?.log ?? ((e) => console.log(JSON.stringify(e)));
52224
52493
  let reason;
@@ -52409,6 +52678,15 @@ var JOB_RESERVE_MS = 7 * 6e4;
52409
52678
  var HUNK_CHECK_MAX_MS = 6 * 6e4;
52410
52679
  var HUNK_CHECK_MIN_BUDGET_MS = 3 * 6e4;
52411
52680
  var HUNK_CHECK_END_BEFORE_STOP_MS = 2 * 6e4;
52681
+ function leftOutNote(root, out2) {
52682
+ const names = out2.names ?? [];
52683
+ const hidden = out2.hidden ?? 0;
52684
+ const more = Math.max(0, out2.leftOut - names.length - hidden);
52685
+ const protectedFiles = `${hidden} protected file${hidden === 1 ? "" : "s"}`;
52686
+ const listed = names.length > 0 ? `${names.join(", ")}${more > 0 ? ` and ${more} more` : ""}${hidden > 0 ? ` + ${protectedFiles}` : ""}` : hidden > 0 ? `${protectedFiles}, not named${more > 0 ? `, and ${more} more` : ""}` : `${more} not named`;
52687
+ const head = `${out2.leftOut} changed file${out2.leftOut === 1 ? "" : "s"} outside ${root} ${out2.leftOut === 1 ? "was" : "were"} left out of the pull request`;
52688
+ return `${head} (changed while the project's commands ran): ${listed}.`;
52689
+ }
52412
52690
  async function run2(env2) {
52413
52691
  const runStartedAt = Date.now();
52414
52692
  let hardFailure = false;
@@ -52456,7 +52734,7 @@ async function run2(env2) {
52456
52734
  await preloadLanguages(workspaceListing);
52457
52735
  const readCheckoutText2 = (path) => {
52458
52736
  try {
52459
- return (0, import_node_fs26.readFileSync)(path, "utf8");
52737
+ return (0, import_node_fs27.readFileSync)(path, "utf8");
52460
52738
  } catch {
52461
52739
  return null;
52462
52740
  }
@@ -52487,6 +52765,9 @@ async function run2(env2) {
52487
52765
  );
52488
52766
  }
52489
52767
  const outOfScope = (packet.outOfScope ?? []).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
52768
+ const partsOn = partsCheckOn();
52769
+ const designParts = partsOn ? partsFromDesign(packet.design) : [];
52770
+ if (partsOn) console.log(JSON.stringify({ event: "parts_check.on", parts: designParts.length }));
52490
52771
  const setupStartedAt = Date.now();
52491
52772
  runCommand(packet.commands.setup, "Setup");
52492
52773
  if (packet.commands.setup) console.log(JSON.stringify({ event: "timing", phase: "setup", seconds: Math.round((Date.now() - setupStartedAt) / 1e3) }));
@@ -52530,7 +52811,14 @@ async function run2(env2) {
52530
52811
  // QUIKTR-1580 - and the scope: in map mode it is how targeting sees the repository; since QUIKTR-1582 it is also handed over in listing
52531
52812
  // mode, only so the record can say which folder the run could change (listing-mode targeting reads nothing else from it).
52532
52813
  // QUIKTR-1888 - the mode the packet and the environment settle on, so the project's switch reaches the targeting step too.
52533
- { ...packet.findings ? { findings: packet.findings } : {}, scope, ...tools2 ? { tools2 } : {}, mode: resolveTargetingMode(process.env, packet.targetingMode) }
52814
+ // QUIKTR-2325 - and `partsCheck` only when the switch is on and the design has parts.
52815
+ {
52816
+ ...packet.findings ? { findings: packet.findings } : {},
52817
+ scope,
52818
+ ...tools2 ? { tools2 } : {},
52819
+ mode: resolveTargetingMode(process.env, packet.targetingMode),
52820
+ ...designParts.length > 0 ? { partsCheck: true } : {}
52821
+ }
52534
52822
  );
52535
52823
  targetingResult = targeting;
52536
52824
  for (const w of targeting.warnings ?? []) {
@@ -52577,6 +52865,24 @@ async function run2(env2) {
52577
52865
  `QuikPilot's generated plan gives two files identical instructions \u2014 ${describeOverlapWarnings(blockingOverlaps).join("; ")}`
52578
52866
  );
52579
52867
  }
52868
+ if (designParts.length > 0) {
52869
+ const exists = existsMarked(designParts, targeting.targets);
52870
+ if (exists.existing.length > 0 || exists.ignored.length > 0) {
52871
+ console.log(
52872
+ JSON.stringify({
52873
+ event: "parts_check.after_targeting",
52874
+ existing: exists.existing.length,
52875
+ ids: exists.existing,
52876
+ ...exists.ignored.length > 0 ? { ignored: exists.ignored } : {}
52877
+ })
52878
+ );
52879
+ }
52880
+ }
52881
+ const partsStop = afterTargeting(designParts, targeting.targets);
52882
+ if (partsStop) {
52883
+ console.log(JSON.stringify({ event: "parts_check.stop", reason: partsStop.reason, ids: partsStop.ids }));
52884
+ throw new PartsStopError(partsStop);
52885
+ }
52580
52886
  const judgedByPool = buildJudgedByPool(
52581
52887
  packet.requiredTests,
52582
52888
  targeting.targets,
@@ -52597,6 +52903,8 @@ async function run2(env2) {
52597
52903
  const twoPhase = twoPhaseWanted && twoPhaseSkip === null;
52598
52904
  const redReview = twoPhase && redReviewOn();
52599
52905
  if (redReview) console.log(JSON.stringify({ event: "red_review.on" }));
52906
+ const codeParts = twoPhase && designParts.length > 0 ? partsForCode(designParts, targeting.targets) : [];
52907
+ if (designParts.length > 0 && !twoPhase) console.log(JSON.stringify({ event: "parts_check.done_check_off", reason: "one_phase" }));
52600
52908
  if (twoPhaseWanted && twoPhaseSkip !== null) {
52601
52909
  warnings.push(TWO_PHASE_SKIPPED_NOTE);
52602
52910
  console.log(JSON.stringify({ event: "two_phase.off", reason: twoPhaseSkip }));
@@ -52628,6 +52936,7 @@ async function run2(env2) {
52628
52936
  ...runScratch ? { runScratch } : {},
52629
52937
  ...twoPhase ? { twoPhase: true, ...packet.requiredTestTypes ? { requiredTestTypes: packet.requiredTestTypes } : {} } : {},
52630
52938
  ...redReview ? { redReview: true } : {},
52939
+ ...codeParts.length > 0 ? { parts: codeParts } : {},
52631
52940
  tests: {
52632
52941
  root: process.cwd(),
52633
52942
  command: packet.commands.test,
@@ -52789,6 +53098,15 @@ async function run2(env2) {
52789
53098
  const suffix = healFailureSuffix(fixed.heal);
52790
53099
  throw suffix ? new Error(`${final.error.message}${suffix}`) : final.error;
52791
53100
  }
53101
+ if (designParts.length > 0) {
53102
+ const finalParts = partsForCode(designParts, targeting.targets);
53103
+ const changes = changesAgainstBase(process.cwd(), new Set(finalParts.flatMap((p) => p.paths)));
53104
+ const added = new Map(changes.map((c) => [c.path, c.added]));
53105
+ const missing = missingAtDone(finalParts, [...added.keys()], (p) => added.get(p) ?? null, testRule(discoveredTestsOf(codegenDiscovery)));
53106
+ const ids = missing.map((m) => m.part.id);
53107
+ console.log(JSON.stringify({ event: "parts_check.final", outcome: missing.length > 0 ? "missing" : "ok", missing: missing.length, ids }));
53108
+ if (missing.length > 0) throw new PartsStopError({ reason: "part_missing", ids, sentence: partMissingSentence(missing) });
53109
+ }
52792
53110
  if (codegenMode === "loop-tests" && fixed.heal && fixed.heal.made > 0 && process.env.QUIKPILOT_TESTS_CORRECTED?.trim().toLowerCase() !== "off") {
52793
53111
  try {
52794
53112
  const files = correctedOwnTests({ kept: results, final: fixed.results, baselineOf: (path) => readCommittedText(process.cwd(), path) });
@@ -52863,9 +53181,8 @@ async function run2(env2) {
52863
53181
  try {
52864
53182
  const guarded = checkGuardrail(packet.guardrails.deniedPaths, ...scopeRoot ? [scopeRoot] : []);
52865
53183
  if (guarded && guarded.leftOut > 0) {
52866
- const note = `${guarded.leftOut} changed file${guarded.leftOut === 1 ? " was" : "s were"} outside ${scopeRoot} and left out of the pull request.`;
52867
- warnings.push(note);
52868
- console.log(JSON.stringify({ event: "scope.left_out", count: guarded.leftOut }));
53184
+ warnings.push(leftOutNote(scopeRoot, guarded));
53185
+ console.log(JSON.stringify({ event: "scope.left_out", count: guarded.leftOut, ...guarded.hidden > 0 ? { hidden: guarded.hidden } : {} }));
52869
53186
  }
52870
53187
  const installationToken = await exchangeForInstallationToken(
52871
53188
  env2.installationTokenUrl,
@@ -53023,7 +53340,7 @@ var EvidenceLedger = class {
53023
53340
  return seen;
53024
53341
  }
53025
53342
  };
53026
- function isRecord4(x) {
53343
+ function isRecord5(x) {
53027
53344
  return typeof x === "object" && x !== null && !Array.isArray(x);
53028
53345
  }
53029
53346
  function arrayOf(x) {
@@ -53061,7 +53378,7 @@ function capFindingsSize(findings, max = MAX_FINDINGS_CHARS) {
53061
53378
  function verifyFindings(raw, ledger, ctx) {
53062
53379
  const dropped = emptyDropped();
53063
53380
  const redactions = emptyRedactionCounts();
53064
- if (!isRecord4(raw)) return { findings: emptyFindings(), downgraded: false, dropped, redactions };
53381
+ if (!isRecord5(raw)) return { findings: emptyFindings(), downgraded: false, dropped, redactions };
53065
53382
  const pathOk2 = (p) => typeof p === "string" && ctx.listing.has(p) && matchesDeniedPath(p, ctx.deniedPaths) === null;
53066
53383
  const symbolsOf = (path, list2) => {
53067
53384
  const out2 = [];
@@ -53076,7 +53393,7 @@ function verifyFindings(raw, ledger, ctx) {
53076
53393
  };
53077
53394
  const files = [];
53078
53395
  for (const f of arrayOf(raw.files)) {
53079
- if (!isRecord4(f) || !pathOk2(f.path)) {
53396
+ if (!isRecord5(f) || !pathOk2(f.path)) {
53080
53397
  dropped.files += 1;
53081
53398
  continue;
53082
53399
  }
@@ -53086,7 +53403,7 @@ function verifyFindings(raw, ledger, ctx) {
53086
53403
  }
53087
53404
  const callPath = [];
53088
53405
  for (const s of arrayOf(raw.callPath)) {
53089
- const ok = isRecord4(s) && pathOk2(s.path) && typeof s.symbol === "string" && s.symbol.length > 0 && s.symbol.length <= MAX_SYMBOL_CHARS && isLine2(s.line) && ledger.hasLines(s.path, s.line, s.line) && ledger.textContains(s.path, s.symbol);
53406
+ const ok = isRecord5(s) && pathOk2(s.path) && typeof s.symbol === "string" && s.symbol.length > 0 && s.symbol.length <= MAX_SYMBOL_CHARS && isLine2(s.line) && ledger.hasLines(s.path, s.line, s.line) && ledger.textContains(s.path, s.symbol);
53090
53407
  if (!ok) {
53091
53408
  dropped.callPath += 1;
53092
53409
  continue;
@@ -53095,7 +53412,7 @@ function verifyFindings(raw, ledger, ctx) {
53095
53412
  }
53096
53413
  const evidence = [];
53097
53414
  for (const e of arrayOf(raw.evidence)) {
53098
- const ok = isRecord4(e) && pathOk2(e.path) && isLine2(e.startLine) && isLine2(e.endLine) && e.startLine <= e.endLine && e.endLine - e.startLine + 1 <= MAX_EVIDENCE_LINES && ledger.hasLines(e.path, e.startLine, e.endLine);
53415
+ const ok = isRecord5(e) && pathOk2(e.path) && isLine2(e.startLine) && isLine2(e.endLine) && e.startLine <= e.endLine && e.endLine - e.startLine + 1 <= MAX_EVIDENCE_LINES && ledger.hasLines(e.path, e.startLine, e.endLine);
53099
53416
  if (!ok) {
53100
53417
  dropped.evidence += 1;
53101
53418
  continue;