@outerlayer/cli 0.40.0-next.20261117031847 → 0.40.0-next.20261117043041

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.
Files changed (187) hide show
  1. package/README.md +5 -1
  2. package/dist/agent-setup-4J2JL5EB.js +41 -0
  3. package/dist/{agent-subcommand-SNGOSV4D.js → agent-subcommand-64YO6FE4.js} +4 -4
  4. package/dist/{artifact-link-cmd-K6VFGMIO.js → artifact-link-cmd-HYEM4X5U.js} +2 -2
  5. package/dist/{bridge-C5FNHUYF.js → bridge-H72K6N7O.js} +7 -7
  6. package/dist/{build-YFKCYJR6.js → build-PBQIJPCC.js} +13 -13
  7. package/dist/{build-disk-ZRWIYYVO.js → build-disk-3COAKTPF.js} +11 -11
  8. package/dist/build-info.json +1 -1
  9. package/dist/{builder-334EUQCE.js → builder-GOJQQOIV.js} +10 -10
  10. package/dist/caller-BZBHMIA2.js +23 -0
  11. package/dist/{check-LGB3BWZ7.js → check-TRV42MHY.js} +55 -55
  12. package/dist/{chunk-O2324X34.js → chunk-2L2LLHQW.js} +1 -1
  13. package/dist/{chunk-XLU5ZOTK.js → chunk-3FZXSMIL.js} +4 -4
  14. package/dist/{chunk-WNQMNFJG.js → chunk-3RG2ZR3J.js} +5 -5
  15. package/dist/{chunk-G3HBBHIK.js → chunk-3TEE7JVW.js} +1 -1
  16. package/dist/{chunk-OF6XMZHO.js → chunk-52CTFVXD.js} +1 -1
  17. package/dist/{chunk-DQQID2EX.js → chunk-6FWHB4TW.js} +8 -8
  18. package/dist/{chunk-MCUI6RHU.js → chunk-6IGOHB3O.js} +12 -3
  19. package/dist/{chunk-GZLNKW2J.js → chunk-7CK4Z6VC.js} +6 -6
  20. package/dist/{chunk-J6WQ6POX.js → chunk-7QDRLTFW.js} +1 -1
  21. package/dist/{chunk-ROMZCAG7.js → chunk-AAGXH2FR.js} +1 -1
  22. package/dist/{chunk-OVF475U5.js → chunk-ATK2MNGU.js} +4 -4
  23. package/dist/{chunk-CVSREZEZ.js → chunk-BIBHD4KJ.js} +4 -4
  24. package/dist/{chunk-QVTGSGQ5.js → chunk-BIXO533I.js} +2 -2
  25. package/dist/{chunk-WZRXXOWB.js → chunk-BVKLR7GA.js} +17 -17
  26. package/dist/{chunk-OCXVMUXA.js → chunk-CKS7B2ZJ.js} +7 -7
  27. package/dist/{chunk-2F3RZT5L.js → chunk-CZYUSXAR.js} +3 -3
  28. package/dist/{chunk-2MSLNM5V.js → chunk-D3PPI7I4.js} +1 -1
  29. package/dist/{chunk-M7RI6IMR.js → chunk-DMW22UQE.js} +3 -3
  30. package/dist/{chunk-F7EYCXY4.js → chunk-EBSN6K35.js} +6 -6
  31. package/dist/{chunk-MJGBRYDH.js → chunk-FBFYIEHC.js} +12 -7
  32. package/dist/{chunk-UNGZ25QF.js → chunk-FRQLJUID.js} +2 -2
  33. package/dist/{chunk-FPUFOQEH.js → chunk-FUNAQRMN.js} +9 -9
  34. package/dist/{chunk-CEHT2FCU.js → chunk-FYL2RFHI.js} +3 -3
  35. package/dist/{chunk-R4IC7BKJ.js → chunk-G2KLJMPR.js} +8 -8
  36. package/dist/{chunk-ONDONSBT.js → chunk-H37HSQGH.js} +1 -1
  37. package/dist/{chunk-GOJ2SPKB.js → chunk-H73CCPAW.js} +1 -1
  38. package/dist/{chunk-6JRDP6O4.js → chunk-H7BNWYIA.js} +5 -5
  39. package/dist/{chunk-HQPB4ZMS.js → chunk-HHOFP647.js} +1 -1
  40. package/dist/{chunk-62EOPMMA.js → chunk-HQEPFG5U.js} +1 -1
  41. package/dist/{chunk-4WRECUUH.js → chunk-I6PDJEYQ.js} +3 -3
  42. package/dist/{chunk-F2I2GQMF.js → chunk-IHMGZWOB.js} +1 -1
  43. package/dist/{chunk-QVQWIKDP.js → chunk-ISTSELPU.js} +6 -6
  44. package/dist/{chunk-OUVDFJ3T.js → chunk-IXHMDBXY.js} +7 -7
  45. package/dist/{chunk-EO7KUUKZ.js → chunk-J4EPJMU6.js} +2 -2
  46. package/dist/{chunk-6RJBLCPV.js → chunk-J7UWKTRV.js} +1 -1
  47. package/dist/{chunk-WYD6XWET.js → chunk-JMQDGBAF.js} +2 -2
  48. package/dist/{chunk-6P23FS2Z.js → chunk-K3IO22FH.js} +1 -1
  49. package/dist/{chunk-YUR7GV5L.js → chunk-KPCGSGZS.js} +5 -5
  50. package/dist/{chunk-DOJGTDZU.js → chunk-KZEZBZ4W.js} +8 -8
  51. package/dist/{chunk-2VVSAKM3.js → chunk-LDTLGJ5F.js} +530 -103
  52. package/dist/{chunk-ZTZFWQBG.js → chunk-MAWSNLSZ.js} +4 -4
  53. package/dist/{chunk-CGYKQEPN.js → chunk-MN73QQDA.js} +4 -4
  54. package/dist/{chunk-IWPU2TDY.js → chunk-O2JKZTP3.js} +2 -2
  55. package/dist/{chunk-ERFVB3TJ.js → chunk-OA2KHMXX.js} +6 -6
  56. package/dist/{chunk-JDAH6YHU.js → chunk-PC6BJDBE.js} +5 -5
  57. package/dist/{chunk-DRF45IQZ.js → chunk-PIP32M2V.js} +3 -3
  58. package/dist/{chunk-3TQVQKQ2.js → chunk-PKYJMXRB.js} +8 -8
  59. package/dist/{chunk-CJCGE7TW.js → chunk-PVDIDOKH.js} +40 -9
  60. package/dist/{chunk-A72OH6K3.js → chunk-QJ3AJNRP.js} +7 -7
  61. package/dist/{chunk-OIAWDKSR.js → chunk-QKMVEQXO.js} +3 -3
  62. package/dist/{chunk-DV44KCM6.js → chunk-QMC2MM2S.js} +1 -1
  63. package/dist/{chunk-NLOUOUZV.js → chunk-QMOE5Y4X.js} +1 -1
  64. package/dist/{chunk-AAOM7S3Z.js → chunk-RC5WWCUS.js} +5 -5
  65. package/dist/{chunk-T3NBGNP5.js → chunk-RZSGNO7S.js} +247 -138
  66. package/dist/{chunk-NWYQ7PKS.js → chunk-SLZSJRLS.js} +10 -10
  67. package/dist/{chunk-6MF44FPF.js → chunk-SS3SQYDS.js} +1 -1
  68. package/dist/{chunk-H7EBNQGW.js → chunk-SSVM6C5N.js} +1 -1
  69. package/dist/{chunk-JGSIVQVE.js → chunk-T4SVE4O4.js} +4 -4
  70. package/dist/{chunk-QIO2NIX2.js → chunk-TPLMLNME.js} +1 -1
  71. package/dist/{chunk-NO3JPGJW.js → chunk-UAGUV74T.js} +1 -1
  72. package/dist/{chunk-Z3IDEUCC.js → chunk-ULI64TQ5.js} +3 -3
  73. package/dist/{chunk-OY4EJVUH.js → chunk-V56S4A34.js} +1 -1
  74. package/dist/{chunk-CWJ26A6W.js → chunk-V65YF5VP.js} +1 -1
  75. package/dist/{chunk-5SAJ23BY.js → chunk-VEW4BPVJ.js} +1 -1
  76. package/dist/{chunk-QAZOUTEM.js → chunk-VH7P6XUP.js} +1 -1
  77. package/dist/{chunk-DHB3M244.js → chunk-VUSPSY6N.js} +1 -1
  78. package/dist/{chunk-YNNTU5IZ.js → chunk-WAI7EGGE.js} +1 -1
  79. package/dist/{chunk-3IHZYNZW.js → chunk-WHIAOWEN.js} +1 -1
  80. package/dist/{chunk-WT74ZSRC.js → chunk-XVE7HD6X.js} +6 -6
  81. package/dist/{chunk-KDKMVWHJ.js → chunk-XVTDFLRQ.js} +3 -3
  82. package/dist/{chunk-PIJWOPSG.js → chunk-Y73IIGAU.js} +7 -7
  83. package/dist/{chunk-5LDYQLE3.js → chunk-YAB2SVSI.js} +2 -2
  84. package/dist/{chunk-IQTMXXKU.js → chunk-YOQ3GBJK.js} +10 -10
  85. package/dist/{chunk-SBSH253O.js → chunk-YVLGGDYK.js} +1 -1
  86. package/dist/{chunk-RO5YUUN2.js → chunk-ZHXBFXG2.js} +1 -1
  87. package/dist/{claude-launcher-3H5XSXVA.js → claude-launcher-43RD6G3Y.js} +7 -7
  88. package/dist/{cli-FRR5Q3IX.js → cli-DRPVOAEG.js} +169 -169
  89. package/dist/{command-Y5FG3FWC.js → command-FMNZSGIX.js} +52 -52
  90. package/dist/{config-V6VQOSHM.js → config-OJTLS62B.js} +12 -12
  91. package/dist/{connect-cmd-AU2IGAYG.js → connect-cmd-L5KO3U67.js} +13 -13
  92. package/dist/{container-start-Z6OCZPUC.js → container-start-OPQZF4LH.js} +49 -49
  93. package/dist/{context-cleanup-SK445SLA.js → context-cleanup-REXSRAU6.js} +4 -4
  94. package/dist/{context-show-cmd-Z6YW2XPG.js → context-show-cmd-DAVFJJHX.js} +14 -14
  95. package/dist/{control-plane-launch-CNGKWYLK.js → control-plane-launch-TARK67QP.js} +14 -14
  96. package/dist/{demo-record-cmd-VEMSRUVR.js → demo-record-cmd-BRBXTCSL.js} +8 -8
  97. package/dist/{demo-voice-cmd-ABNZ6H7V.js → demo-voice-cmd-67ZE46PS.js} +20 -20
  98. package/dist/{dist-775TDFCK.js → dist-3AH72O53.js} +2 -2
  99. package/dist/{docker-UHQ4LAJE.js → docker-FEOTGBDS.js} +10 -10
  100. package/dist/{doctor-B7XTBO53.js → doctor-22YI6EJN.js} +51 -51
  101. package/dist/{emit-artifact-cmd-WLBQOFGX.js → emit-artifact-cmd-ZDQ5PPRN.js} +19 -19
  102. package/dist/{emit-cmd-A6ZGOPLZ.js → emit-cmd-MY3TTOV7.js} +7 -7
  103. package/dist/{emit-criteria-cmd-S533NEY4.js → emit-criteria-cmd-SED3RVYR.js} +16 -16
  104. package/dist/{emit-demo-cmd-K4JY5PDP.js → emit-demo-cmd-VBHIORA3.js} +20 -20
  105. package/dist/{emit-finding-cmd-C7RZGGVJ.js → emit-finding-cmd-NQRNWPFW.js} +16 -16
  106. package/dist/{emit-result-cmd-5NLUDBXM.js → emit-result-cmd-CA3FQUGR.js} +18 -18
  107. package/dist/{emit-step-cmd-Q7VIXGYQ.js → emit-step-cmd-EZQD56H5.js} +16 -16
  108. package/dist/{exec-client-RR6F42IB.js → exec-client-JEOB57LW.js} +8 -8
  109. package/dist/{find-unit-WRHK3H5X.js → find-unit-HJRHPB3Y.js} +13 -13
  110. package/dist/{findings-cmd-74MN2Q7K.js → findings-cmd-4HKGMYM7.js} +16 -16
  111. package/dist/{fleet-readiness-R6B3PYU7.js → fleet-readiness-SPPQPJZI.js} +14 -14
  112. package/dist/{governing-source-M2HYH7ZN.js → governing-source-URY2L5EI.js} +21 -21
  113. package/dist/{guest-init-QEWU2H7W.js → guest-init-KXWFAIS5.js} +9 -9
  114. package/dist/{hook-fast-GPW7D4MD.js → hook-fast-3EMC5BR5.js} +1 -1
  115. package/dist/{hook-install-VF3X2ZXN.js → hook-install-2S7NZOBO.js} +4 -4
  116. package/dist/host-checks-MVOAIBQA.js +82 -0
  117. package/dist/host-key-JGKWDEN7.js +18 -0
  118. package/dist/{image-tag-LKOD5GRQ.js → image-tag-DJ2DYY75.js} +8 -8
  119. package/dist/index.js +4 -4
  120. package/dist/{init-UO4SOY57.js → init-F6XEU4VR.js} +47 -47
  121. package/dist/init-JEXSFOFP.js +82 -0
  122. package/dist/{init-agent-JVMIDIXN.js → init-agent-BLC6ART6.js} +47 -47
  123. package/dist/init-cmd-ISFN4IXL.js +53 -0
  124. package/dist/{init-update-BRUFAWCA.js → init-update-2PHTQUR6.js} +24 -24
  125. package/dist/install-cmd-2SO5XQMZ.js +26 -0
  126. package/dist/launch-agent-ZCE2MKWW.js +26 -0
  127. package/dist/{layout-BG6MFUS3.js → layout-4GFI5FUZ.js} +4 -4
  128. package/dist/{login-browser-OA4R4PEQ.js → login-browser-G3NBTYT6.js} +2 -2
  129. package/dist/{logs-WNZZNFA3.js → logs-IGY3Z45I.js} +7 -7
  130. package/dist/loop-A3LCREAQ.js +92 -0
  131. package/dist/machine-P5OCN6FJ.js +82 -0
  132. package/dist/{machine-skills-B7KO47CH.js → machine-skills-FJPUFZ7N.js} +4 -4
  133. package/dist/{mcp-install-cmd-JXD6Q7NN.js → mcp-install-cmd-DWN6GODI.js} +4 -4
  134. package/dist/{mcp-serve-cmd-4D4P6IA7.js → mcp-serve-cmd-3ACPN3DK.js} +9 -9
  135. package/dist/{paths-I7LDWR3Q.js → paths-KPYCKVEO.js} +7 -7
  136. package/dist/pending-LR3J3B32.js +18 -0
  137. package/dist/{pidfile-SNTRLZ2Z.js → pidfile-2TYTTJAD.js} +8 -8
  138. package/dist/{record-QJPGOWYX.js → record-SXQN3F2G.js} +8 -8
  139. package/dist/{relay-V5GHEWT3.js → relay-XUWU6YJA.js} +5 -5
  140. package/dist/{relay-protocol-2S2EAHYH.js → relay-protocol-2ELEUOSS.js} +5 -5
  141. package/dist/{run-cmd-YY34QRDU.js → run-cmd-ZC6H5JMT.js} +16 -16
  142. package/dist/{runner-agents-CLDURIBZ.js → runner-agents-RKBGYF6D.js} +4 -4
  143. package/dist/runner-env-7AZQ443N.js +24 -0
  144. package/dist/{runner-identity-2374JAQF.js → runner-identity-IA53MENM.js} +10 -10
  145. package/dist/{runner-key-JRZ5N4IM.js → runner-key-K6SJMQ6I.js} +47 -47
  146. package/dist/{session-sender-CUM4SRT7.js → session-sender-HUD6KDQS.js} +19 -19
  147. package/dist/{setup-cmd-5ICCOGTJ.js → setup-cmd-6BBZWFJX.js} +14 -14
  148. package/dist/{setup-wiring-CEGNPVS5.js → setup-wiring-AE2RFMC4.js} +54 -54
  149. package/dist/{spec-cmd-6ACWBET6.js → spec-cmd-VKL4K2QQ.js} +17 -17
  150. package/dist/{starter-pack-WOD4WMUX.js → starter-pack-ETRBBABF.js} +5 -5
  151. package/dist/state-5QGIGKBB.js +18 -0
  152. package/dist/{status-H677WBLM.js → status-TJWQ5EIM.js} +47 -47
  153. package/dist/{sync-cmd-5UMBZRKI.js → sync-cmd-EPN6VJ4R.js} +18 -18
  154. package/dist/update-steps-RDYVUTKN.js +83 -0
  155. package/dist/{watch-34LOYMEQ.js → watch-YSSMGF7F.js} +18 -18
  156. package/dist/{work-claim-cmd-NRHTDJC3.js → work-claim-cmd-TV4TJNBE.js} +23 -23
  157. package/dist/{work-cmd-NBYW3LBP.js → work-cmd-VWXZLMF4.js} +16 -16
  158. package/dist/{work-comment-cmd-J4CG33NA.js → work-comment-cmd-A6OMDNWD.js} +18 -18
  159. package/dist/{work-demo-cmd-APJDOTHV.js → work-demo-cmd-RO2MNERR.js} +16 -16
  160. package/dist/{work-logs-cmd-FL7DOHUU.js → work-logs-cmd-FNVY6PFY.js} +16 -16
  161. package/dist/{work-mock-cmd-4MAYOAQS.js → work-mock-cmd-AC2Z3W7V.js} +16 -16
  162. package/dist/{work-needs-attention-cmd-LG5MFGPW.js → work-needs-attention-cmd-2IEXGHHV.js} +16 -16
  163. package/dist/{work-no-change-cmd-QATDFQ46.js → work-no-change-cmd-VN5YDUZZ.js} +16 -16
  164. package/dist/{work-open-pr-cmd-FV43THW5.js → work-open-pr-cmd-GX3AEJMQ.js} +17 -17
  165. package/dist/{work-pr-cmd-53VAE7HD.js → work-pr-cmd-PU7YFJDD.js} +16 -16
  166. package/dist/{work-proofs-cmd-4SF7WZC3.js → work-proofs-cmd-XOIAKWF2.js} +18 -18
  167. package/dist/{work-proofs-record-IGKVQOLA.js → work-proofs-record-7DEOYNST.js} +24 -24
  168. package/dist/{work-stop-cmd-V5SPVTY4.js → work-stop-cmd-4PKBXINK.js} +16 -16
  169. package/package.json +1 -1
  170. package/skill-pack/maintained/outerlayer-review/SKILL.md +9 -3
  171. package/skill-pack/maintained/outerlayer-review/references/consolidation.md +80 -0
  172. package/skill-pack/shipped.json +3 -0
  173. package/skill-pack/template/review/SKILL.md +14 -0
  174. package/dist/agent-setup-E3NJKG6H.js +0 -41
  175. package/dist/caller-6PMFDU4O.js +0 -23
  176. package/dist/host-checks-PKOVCAGU.js +0 -82
  177. package/dist/host-key-HICYSAZ5.js +0 -18
  178. package/dist/init-DFC5GUE5.js +0 -82
  179. package/dist/init-cmd-WTJ7KOQ5.js +0 -53
  180. package/dist/install-cmd-2H4QK5O7.js +0 -26
  181. package/dist/launch-agent-HPWRSGXZ.js +0 -26
  182. package/dist/loop-WO37TJ5C.js +0 -92
  183. package/dist/machine-ZXCUPCDS.js +0 -82
  184. package/dist/pending-L65HTOAV.js +0 -18
  185. package/dist/runner-env-ACRSRRBW.js +0 -24
  186. package/dist/state-TUO74X72.js +0 -18
  187. package/dist/update-steps-XCDL66FA.js +0 -83
@@ -1,39 +1,39 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from 'node:module';
3
- import { readHousekeepingRecord, writeHousekeepingRecord } from './chunk-ROMZCAG7.js';
3
+ import { readHousekeepingRecord, writeHousekeepingRecord } from './chunk-AAGXH2FR.js';
4
4
  import { fetchVersionMeta, npmVersion, npmSupportsProvenance, fetchTarballDigest, fetchProvenance, installVersion, auditSignatures } from './chunk-E7R2GIAW.js';
5
- import { reportFailedStart, fitImageBuildMemory } from './chunk-A72OH6K3.js';
6
- import { renderUpdateSteps } from './chunk-Z3IDEUCC.js';
5
+ import { reportFailedStart, fitImageBuildMemory } from './chunk-QJ3AJNRP.js';
6
+ import { renderUpdateSteps } from './chunk-ULI64TQ5.js';
7
7
  import { decideInstalledSwitch } from './chunk-TXKHD4Q6.js';
8
- import { writeFleetState } from './chunk-NO3JPGJW.js';
9
- import { writePendingUpdate } from './chunk-5SAJ23BY.js';
10
- import { fleetConfigProblem, realBlockedProbes, checkBlockedWithSlots, askFleetMachine } from './chunk-NWYQ7PKS.js';
11
- import { writeMarker, readMarker, currentVersion, removeMarker, isInLayout, startedThroughCurrent, entryIn, versionDir, switchCurrent, cleanVersions, stagingDir } from './chunk-QIO2NIX2.js';
12
- import { leaseTimeLeftMs, createContainerRuntime, heldSandboxClaimsOf, unfinishedJobs, withTunnelLog, itemTag, releaseLease, runDecision, claimRun, LEASE_SECONDS, isUnfinished, prepareResume, restoreSessionIntoMicroVm, restoreSessionIntoContainer, restoreSessionIntoSandbox, restoreWork, keptSessionDir, workRestoredEnv, sessionGuestOfMicroVm, sessionGuestOfContainer, sessionGuestOfSandbox, recordsProofsOnly, itemScope, attemptNote, fetchManagedClaudeKey, holdManagedClaudeKey, fetchManagedBuildSettings, holdManagedBuildSettings, setStage, jobEnv, runHook, describeHookEnd, needsBuildSkill, provisionContainer, leaseExpiresAtMs, withJobTimeLimit, deliverContainerHooks, provisionSandbox, deliverSandboxHooks, provisionMicroVm, deliverCommitHooks, provisionEnvironment, readProvisionOut, resolveHostBuild, workdirProblem, listenOnBroker, hostEnvironment, deliverExecMaven, runWithSpawn, hostCommandEnvironment, lifecycleSteps, execArgv, lifecycleFailureReason, decideHostBuildSkill, prepareBranch, keptCommitsLine, currentSkillCommand, formerSkillProblem, commandLogOffset, startSandboxCommand, MICROVM_COMMAND_DIR, startMicroVmCommand, microVmCommandLine, runCommand, containerCommandExec, execCommandLine, startSender, startHostServices, finishJob, sampleGuest, foldSample, isSandboxTracked, isContainerTracked, isMicroVmTracked, probeSandboxCommand, probeMicroVmCommand, probeCommand, appendCommandLog, judgeProbe, SandboxGoneError, SandboxContainerStoppedError, EXIT_CODE_FILE, isTracked, isGroupAlive, outcomeFromExitCode, isIsolatedJob, jobTimeLimitMinutes, isTimedOut, readCpuUsec, isIdle, HELPER_ENV, setUpRunnerCgroup, stopOrphanedMicroVms, sweepImageBuilders, listUnreadableJobs, listAdoptableJobs, retryFailedReleases, recoverLostJobs, GUEST_USAGE_INTERVAL_MS, vmAlive, filesAreCopied, inSandbox, listItemDisks, hookLimitsFor, runCommandOf, AttemptLogBook, environmentFor, builtOf, judgeCredential, readWorkItem, makeRecorder, microVmOomKills, needsRenew, renewRun, renewLease, RENEW_INTERVAL_SECONDS, stoppedHelperReason, measureDisk, listTrackedJobs, sweepSandboxes, keptSandboxIds, parseCpuList, ensureTunnel, keepGhConfigCurrent, restartSender, rejoinSandboxBuild, createHousekeepingDocker, housekeepingDockerIfReachable, runHousekeeping, shellQuote, jobRecordsClaim, freeItemDisksUntil, savedStatesDir, readRecords, removeOldestUntil, treeFileText, timeoutAfter, scrubReason, ensureNetworkReady, ADOPTED_FETCH_RETRY_WINDOW_MS, managedBuildSettingsFor, gitRemoteFor, startServicesFor, installTrust, createLeaseChannel, serveLease, writeGuestGhConfig, deliverJobFiles, inTeardown } from './chunk-T3NBGNP5.js';
13
- import { RUNNER_PROTOCOL } from './chunk-HQPB4ZMS.js';
14
- import { criteriaOf, loadCitationFinder, wholeItems, itemsSentence, oneLineReason, wholeEntries, parseJudgeAnswer } from './chunk-MJGBRYDH.js';
15
- import { RepoFilter } from './chunk-FPUFOQEH.js';
8
+ import { writeFleetState } from './chunk-UAGUV74T.js';
9
+ import { writePendingUpdate } from './chunk-VEW4BPVJ.js';
10
+ import { fleetConfigProblem, realBlockedProbes, checkBlockedWithSlots, askFleetMachine } from './chunk-SLZSJRLS.js';
11
+ import { writeMarker, readMarker, currentVersion, removeMarker, isInLayout, startedThroughCurrent, entryIn, versionDir, switchCurrent, cleanVersions, stagingDir } from './chunk-TPLMLNME.js';
12
+ import { leaseTimeLeftMs, createContainerRuntime, heldSandboxClaimsOf, unfinishedJobs, withTunnelLog, itemTag, releaseLease, runDecision, claimRun, LEASE_SECONDS, isUnfinished, prepareResume, restoreSessionIntoMicroVm, restoreSessionIntoContainer, restoreSessionIntoSandbox, restoreWork, keptSessionDir, workRestoredEnv, sessionGuestOfMicroVm, sessionGuestOfContainer, sessionGuestOfSandbox, recordsProofsOnly, itemScope, attemptNote, fetchManagedClaudeKey, holdManagedClaudeKey, fetchManagedBuildSettings, holdManagedBuildSettings, setStage, jobEnv, runHook, describeHookEnd, needsBuildSkill, provisionContainer, leaseExpiresAtMs, withJobTimeLimit, deliverContainerHooks, provisionSandbox, deliverSandboxHooks, provisionMicroVm, deliverCommitHooks, provisionEnvironment, readProvisionOut, resolveHostBuild, workdirProblem, listenOnBroker, hostEnvironment, deliverExecMaven, runWithSpawn, hostCommandEnvironment, lifecycleSteps, execArgv, lifecycleFailureReason, decideHostBuildSkill, prepareBranch, keptCommitsLine, currentSkillCommand, formerSkillProblem, commandLogOffset, startSandboxCommand, MICROVM_COMMAND_DIR, startMicroVmCommand, microVmCommandLine, runCommand, containerCommandExec, execCommandLine, startSender, startHostServices, finishJob, sampleGuest, foldSample, isSandboxTracked, isContainerTracked, isMicroVmTracked, probeSandboxCommand, probeMicroVmCommand, probeCommand, appendCommandLog, judgeProbe, SandboxGoneError, SandboxContainerStoppedError, EXIT_CODE_FILE, isTracked, isGroupAlive, outcomeFromExitCode, isIsolatedJob, jobTimeLimitMinutes, isTimedOut, readCpuUsec, isIdle, HELPER_ENV, setUpRunnerCgroup, stopOrphanedMicroVms, sweepImageBuilders, listUnreadableJobs, listAdoptableJobs, retryFailedReleases, recoverLostJobs, GUEST_USAGE_INTERVAL_MS, vmAlive, filesAreCopied, inSandbox, listItemDisks, hookLimitsFor, runCommandOf, AttemptLogBook, environmentFor, builtOf, judgeCredential, readWorkItem, makeRecorder, microVmOomKills, needsRenew, renewRun, renewLease, RENEW_INTERVAL_SECONDS, stoppedHelperReason, measureDisk, listTrackedJobs, sweepSandboxes, keptSandboxIds, parseCpuList, ensureTunnel, keepGhConfigCurrent, restartSender, rejoinSandboxBuild, createHousekeepingDocker, housekeepingDockerIfReachable, runHousekeeping, shellQuote, jobRecordsClaim, freeItemDisksUntil, savedStatesDir, readRecords, holdsHostDisk, removeOldestUntil, treeFileText, scrubReason, timeoutAfter, ensureNetworkReady, ADOPTED_FETCH_RETRY_WINDOW_MS, managedBuildSettingsFor, gitRemoteFor, startServicesFor, installTrust, createLeaseChannel, serveLease, writeGuestGhConfig, deliverJobFiles, inTeardown } from './chunk-RZSGNO7S.js';
13
+ import { RUNNER_PROTOCOL } from './chunk-HHOFP647.js';
14
+ import { criteriaOf, diffLines, loadCitationFinder, wholeItems, itemsSentence, oneLineReason, parseJudgeAnswer, wholeEntries, treePath, lineInDiff } from './chunk-FBFYIEHC.js';
15
+ import { RepoFilter } from './chunk-FUNAQRMN.js';
16
16
  import { JOB_STATE_FORMAT, readsJobState, jobStateFormatOf } from './chunk-B4XB5QFD.js';
17
- import { imageTag, writeUpdateStatus, pullInstruction, tagToPull } from './chunk-6MF44FPF.js';
17
+ import { imageTag, writeUpdateStatus, pullInstruction, tagToPull } from './chunk-SS3SQYDS.js';
18
18
  import { isVersion, compareVersions, satisfiesRange } from './chunk-TQMI335S.js';
19
- import { claimCalls, claimItem, spoolHomeFor, leftByRunnerKey, runnerCalls, itemCalls, configForJob } from './chunk-WYD6XWET.js';
20
- import { fetchCommit, readBranchHead, diffBetween } from './chunk-3TQVQKQ2.js';
21
- import { claimPidFile, releasePidFile, writePidFile, readPidFile } from './chunk-QAZOUTEM.js';
19
+ import { claimCalls, claimItem, spoolHomeFor, leftByRunnerKey, runnerCalls, itemCalls, configForJob } from './chunk-JMQDGBAF.js';
20
+ import { fetchCommit, readBranchHead, diffBetween, readDefaultBranchFiles } from './chunk-PKYJMXRB.js';
21
+ import { claimPidFile, releasePidFile, writePidFile, readPidFile } from './chunk-VH7P6XUP.js';
22
22
  import { startTimeOf, isSameProcess } from './chunk-JBJTC3UU.js';
23
- import { describeCallFailure, retrySend, shortClaim, relativeToRunner, formatDuration, resolveGoverningSource, BuildTokens, classifyRefusal, refusalCode, createRunnerLog, formatClock } from './chunk-CJCGE7TW.js';
24
- import { WorkCommandError, isSignatureRefusal, getJson, postJson, getBytes } from './chunk-DOJGTDZU.js';
25
- import { keyRunnerFactory, readsOnly, isBuiltinSandbox, isBuiltinContainer, isBuiltinVm, loadRunnerConfig, checkHooks, builtinKind, keepsHostBuilder, runnerDeliversComments, DEFAULT_CHECK_TIME_LIMIT_MINUTES, readOnlyRemoteOf, DEFAULT_SAVED_STATE_MAX_BYTES, DEFAULT_UPDATE_MAX_WAIT_HOURS, readOnlyOption } from './chunk-ZTZFWQBG.js';
26
- import { formatBytes, freeBytes } from './chunk-5LDYQLE3.js';
27
- import { writeJobFile, ensureRunnerIdentity, identityDockerFor, readJobFile, JUDGE_TREE, exceedsDisk, runnerLabelValue, builderName, ensureFailureCount, builderSpec, ensureBuilder, spawnRun, judgeCommand, JUDGE_DIR, JUDGE_MAX_TURNS } from './chunk-R4IC7BKJ.js';
28
- import { loadHostKey, ensureHostKey, signerFor } from './chunk-NLOUOUZV.js';
29
- import { jobsDir, RUNNER_DIR_MODE, runnerDir, RUNNER_FILE_MODE, buildDir, attemptStamp, jobDir, pidFilePath, storeScopes } from './chunk-3IHZYNZW.js';
30
- import { parseClaimIdentity, parseBranchlessRepositories, parseClaimedRepositories, parseUnreachable, repositoriesOf, primaryOf, JOB_MOUNT, WORK_DIR } from './chunk-JDAH6YHU.js';
31
- import { jobCredentialProblem, COMMAND_LOST_REASON, takeAgentCredentials, heldAgentCredential, CONTAINER_STOPPED_REASON, currentAgentCredential, fdName } from './chunk-QVTGSGQ5.js';
32
- import { cleanAttachmentName } from './chunk-DRF45IQZ.js';
33
- import { jobAgent, jobCommandEnv, runnerAgents, judgeAgent } from './chunk-OF6XMZHO.js';
34
- import { defaultAgents, resolvePackRoot } from './chunk-CEHT2FCU.js';
23
+ import { describeCallFailure, retrySend, shortClaim, relativeToRunner, formatDuration, resolveGoverningSource, BuildTokens, classifyRefusal, refusalCode, createRunnerLog, formatClock, readGovernedFiles } from './chunk-PVDIDOKH.js';
24
+ import { WorkCommandError, isSignatureRefusal, getJson, postJson, getBytes } from './chunk-KZEZBZ4W.js';
25
+ import { keyRunnerFactory, readsOnly, isBuiltinSandbox, isBuiltinContainer, isBuiltinVm, loadRunnerConfig, checkHooks, builtinKind, keepsHostBuilder, runnerDeliversComments, DEFAULT_CHECK_TIME_LIMIT_MINUTES, readOnlyRemoteOf, DEFAULT_SAVED_STATE_MAX_BYTES, DEFAULT_UPDATE_MAX_WAIT_HOURS, readOnlyOption } from './chunk-MAWSNLSZ.js';
26
+ import { formatBytes, freeBytes } from './chunk-YAB2SVSI.js';
27
+ import { writeJobFile, ensureRunnerIdentity, identityDockerFor, readJobFile, JUDGE_TREE, exceedsDisk, runnerLabelValue, builderName, ensureFailureCount, builderSpec, ensureBuilder, spawnRun, JUDGE_DIR, judgeCommand, JUDGE_MAX_TURNS } from './chunk-G2KLJMPR.js';
28
+ import { loadHostKey, ensureHostKey, signerFor } from './chunk-QMOE5Y4X.js';
29
+ import { jobsDir, RUNNER_DIR_MODE, runnerDir, RUNNER_FILE_MODE, buildDir, attemptStamp, jobDir, pidFilePath, storeScopes } from './chunk-WHIAOWEN.js';
30
+ import { parseClaimIdentity, parseBranchlessRepositories, parseClaimedRepositories, parseUnreachable, repositoriesOf, primaryOf, JOB_MOUNT, WORK_DIR } from './chunk-PC6BJDBE.js';
31
+ import { jobCredentialProblem, COMMAND_LOST_REASON, takeAgentCredentials, heldAgentCredential, CONTAINER_STOPPED_REASON, currentAgentCredential, fdName } from './chunk-BIXO533I.js';
32
+ import { cleanAttachmentName } from './chunk-PIP32M2V.js';
33
+ import { jobAgent, jobCommandEnv, runnerAgents, judgeAgent } from './chunk-52CTFVXD.js';
34
+ import { defaultAgents, resolvePackRoot } from './chunk-FYL2RFHI.js';
35
35
  import { resolveVersion } from './chunk-RA3O54FC.js';
36
- import { CheckItemsSchema, CODE_REVIEW_NAME, CHECK_ITEM_HREF_MAX_LENGTH, CHECK_ITEM_REASON_MAX_LENGTH, UNREVIEWED_FILES_ITEM_ID, problemKind, CODE_REVIEW_PROBLEMS_MAX, REVIEWED_COMMIT_ITEM_ID } from './chunk-MCUI6RHU.js';
36
+ import { CheckItemsSchema, CODE_REVIEW_NAME, CHECK_ITEM_HREF_MAX_LENGTH, CHECK_ITEM_REASON_MAX_LENGTH, UNREVIEWED_FILES_ITEM_ID, problemKind, CODE_REVIEW_PROBLEMS_MAX, TEAM_RULES_ITEM_ID, REVIEWED_COMMIT_ITEM_ID, PROBLEM_KINDS, problemSeverity } from './chunk-6IGOHB3O.js';
37
37
  import { randomBytes, createHash } from 'crypto';
38
38
  import { mkdirSync, existsSync, writeFileSync, chmodSync, renameSync, statSync, readdirSync, rmSync, readFileSync, lstatSync, closeSync } from 'fs';
39
39
  import { totalmem, userInfo, constants } from 'os';
@@ -393,11 +393,11 @@ function commentsOf(data) {
393
393
  for (const entry of raw) {
394
394
  const comment = entry;
395
395
  if (comment === null || typeof comment !== "object") continue;
396
- const { claimId, workItemId, commentId, thread, authorName, text, summary, at } = comment;
396
+ const { claimId, workItemId, commentId, thread, authorName, text: text2, summary, at } = comment;
397
397
  if (typeof claimId !== "string" || typeof workItemId !== "string" || typeof commentId !== "string" || commentId === "") continue;
398
- if (typeof thread !== "string" || typeof authorName !== "string" || typeof text !== "string" || typeof at !== "string") continue;
398
+ if (typeof thread !== "string" || typeof authorName !== "string" || typeof text2 !== "string" || typeof at !== "string") continue;
399
399
  const attachments = attachmentsOf(comment.attachments);
400
- comments.push({ claimId, workItemId, commentId, thread, authorName, text, summary: typeof summary === "string" ? summary : null, at, ...attachments.length === 0 ? {} : { attachments } });
400
+ comments.push({ claimId, workItemId, commentId, thread, authorName, text: text2, summary: typeof summary === "string" ? summary : null, at, ...attachments.length === 0 ? {} : { attachments } });
401
401
  }
402
402
  return comments;
403
403
  }
@@ -664,8 +664,8 @@ function readLastUpdate(configPath) {
664
664
  return void 0;
665
665
  }
666
666
  }
667
- function isoTime(text) {
668
- const ms = Date.parse(text);
667
+ function isoTime(text2) {
668
+ const ms = Date.parse(text2);
669
669
  if (!Number.isFinite(ms)) return void 0;
670
670
  const iso = new Date(ms).toISOString();
671
671
  return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(iso) ? iso : void 0;
@@ -1276,8 +1276,8 @@ var SMALL_CHANGE_LINES = 40;
1276
1276
  var LARGE_CHANGE_LINES = 800;
1277
1277
  var GENERATED = /(^|\/)(openapi\.ya?ml|gateway-types\.ts|yarn\.lock|package-lock\.json|pnpm-lock\.yaml)$|\.golden$|\.snap$|(^|\/)generated\/|(^|\/)db-types\//;
1278
1278
  var FLOOR = /\.sql$|(^|\/)migrations\/|auth|secret|permission|webhook|token|(^|\/)rls/i;
1279
- function markdownSection(text, heading) {
1280
- const lines = text.split("\n");
1279
+ function markdownSection(text2, heading) {
1280
+ const lines = text2.split("\n");
1281
1281
  const start2 = lines.findIndex((line) => line.trim() === `## ${heading}`);
1282
1282
  if (start2 === -1) return void 0;
1283
1283
  const end = lines.findIndex((line, index) => index > start2 && line.startsWith("## "));
@@ -1288,15 +1288,15 @@ function splitDiff(patch) {
1288
1288
  const parts = [];
1289
1289
  const starts = [...patch.matchAll(/^diff --git /gm)].map((match) => match.index);
1290
1290
  for (const [index, start2] of starts.entries()) {
1291
- const text = patch.slice(start2, starts[index + 1] ?? patch.length);
1292
- const path = /^diff --git a\/\S+ b\/(\S+)/.exec(text)?.[1] ?? "?";
1291
+ const text2 = patch.slice(start2, starts[index + 1] ?? patch.length);
1292
+ const path = /^diff --git a\/\S+ b\/(\S+)/.exec(text2)?.[1] ?? "?";
1293
1293
  let added = 0;
1294
1294
  let removed = 0;
1295
- for (const line of text.split("\n")) {
1295
+ for (const line of text2.split("\n")) {
1296
1296
  if (line.startsWith("+") && !line.startsWith("+++")) added += 1;
1297
1297
  else if (line.startsWith("-") && !line.startsWith("---")) removed += 1;
1298
1298
  }
1299
- parts.push({ path, text, added, removed });
1299
+ parts.push({ path, text: text2, added, removed });
1300
1300
  }
1301
1301
  return parts;
1302
1302
  }
@@ -1326,8 +1326,8 @@ function territories(changed, briefs) {
1326
1326
  ];
1327
1327
  if (full) names.push(["security", "Security reviewer"], ["failure-path", "Failure-path reviewer"]);
1328
1328
  const focused = names.flatMap(([name, heading]) => {
1329
- const text = briefs === void 0 ? void 0 : markdownSection(briefs, heading);
1330
- return text === void 0 ? [] : [{ name, text }];
1329
+ const text2 = briefs === void 0 ? void 0 : markdownSection(briefs, heading);
1330
+ return text2 === void 0 ? [] : [{ name, text: text2 }];
1331
1331
  });
1332
1332
  return [generalist, ...focused];
1333
1333
  }
@@ -1364,15 +1364,24 @@ function storedProblemsText(problems) {
1364
1364
  }
1365
1365
  function mergeAnswers(answers) {
1366
1366
  const items = [];
1367
- const earlier = /* @__PURE__ */ new Set();
1367
+ const earlier = /* @__PURE__ */ new Map();
1368
1368
  const keyOf = (entry) => {
1369
1369
  const place = entry.refs?.[0];
1370
1370
  return [entry.id, entry.result, place?.path ?? ""].join("\0");
1371
1371
  };
1372
1372
  for (const answer of answers) {
1373
- const kept = answer.items.filter((entry) => !earlier.has(keyOf(entry)));
1374
- for (const entry of kept) earlier.add(keyOf(entry));
1375
- items.push(...kept);
1373
+ const own = [];
1374
+ for (const entry of answer.items) {
1375
+ const held = earlier.get(keyOf(entry));
1376
+ if (held === void 0) {
1377
+ const kept = { ...entry, ...entry.reviewer === void 0 ? {} : { foundBy: [entry.reviewer] } };
1378
+ own.push([keyOf(entry), kept]);
1379
+ items.push(kept);
1380
+ continue;
1381
+ }
1382
+ if (entry.reviewer !== void 0 && !held.foundBy?.includes(entry.reviewer)) held.foundBy = [...held.foundBy ?? [], entry.reviewer];
1383
+ }
1384
+ for (const [key, entry] of own) if (!earlier.has(key)) earlier.set(key, entry);
1376
1385
  }
1377
1386
  const lists = answers.flatMap((answer) => answer.reviewed === void 0 ? [] : [answer.reviewed]);
1378
1387
  const reviewed = lists.length === 0 ? void 0 : [...new Set(lists.flat())];
@@ -1390,7 +1399,7 @@ function mergeAnswers(answers) {
1390
1399
  const result = failed2 ? "fail" : said.length > 0 && said.every((answer) => answer.result === "pass") ? "pass" : void 0;
1391
1400
  return { ...result === void 0 ? {} : { result }, items, ...reviewed === void 0 ? {} : { reviewed }, ...previous === void 0 ? {} : { previous } };
1392
1401
  }
1393
- function carryProblems(merged, stored) {
1402
+ function carriedProblems(merged, stored) {
1394
1403
  const verdicts = new Map((merged.previous ?? []).map((entry) => [entry.id, entry]));
1395
1404
  const kept = [];
1396
1405
  const decided = /* @__PURE__ */ new Set();
@@ -1406,10 +1415,20 @@ function carryProblems(merged, stored) {
1406
1415
  kind: problem.kind,
1407
1416
  ...problem.title === "" ? {} : { title: problem.title },
1408
1417
  ...problem.reason === "" ? {} : { reason: problem.reason },
1409
- ...problem.path === "" ? {} : { refs: [{ path: problem.path, ...line === void 0 ? {} : { line } }] }
1418
+ ...problem.path === "" ? {} : { refs: [{ path: problem.path, ...line === void 0 ? {} : { line } }] },
1419
+ ...problem.severity === null ? {} : { severity: problem.severity }
1410
1420
  });
1411
1421
  }
1412
- return { ...merged, items: [...kept, ...merged.items.filter((entry) => !decided.has(entry.id))] };
1422
+ return { kept, fresh: merged.items.filter((entry) => !decided.has(entry.id)) };
1423
+ }
1424
+ function dropNonProblems(answer, known) {
1425
+ const dropped = [];
1426
+ const items = answer.items.filter((entry) => {
1427
+ const why = (entry.refs ?? []).length === 0 ? "no place" : (entry.reason ?? "").trim() === "" ? "no reason" : entry.refs.some((ref) => known(ref.path)) ? void 0 : "unknown file";
1428
+ if (why !== void 0) dropped.push({ id: entry.id, why });
1429
+ return why === void 0;
1430
+ });
1431
+ return { answer: { ...answer, items }, dropped };
1413
1432
  }
1414
1433
  function unreviewedFiles(changed, reviewed) {
1415
1434
  if (reviewed === void 0) return void 0;
@@ -1435,18 +1454,179 @@ function unreviewedItem(changed, reviewed, commit) {
1435
1454
  return { id: UNREVIEWED_FILES_ITEM_ID, result: "skipped", commit, reason: `${reason}.` };
1436
1455
  }
1437
1456
 
1457
+ // src/runner/code-review-consolidate.ts
1458
+ var CONSOLIDATION_INPUT = "problems.json";
1459
+ var CONSOLIDATION_ANSWER = "items-consolidator.json";
1460
+ var CONSOLIDATOR = "consolidator";
1461
+ var DROP_REASONS = ["duplicate", "out-of-scope", "not-shown", "wrong"];
1462
+ function shouldConsolidate(reviewers, fresh) {
1463
+ if (fresh === 0) return false;
1464
+ return reviewers > 1 || fresh > 1;
1465
+ }
1466
+ function keyAt(index) {
1467
+ return `p${index + 1}`;
1468
+ }
1469
+ function finders(entry) {
1470
+ return entry.foundBy ?? (entry.reviewer === void 0 ? [] : [entry.reviewer]);
1471
+ }
1472
+ function consolidationInput(fresh, reviewers) {
1473
+ const problems = fresh.map((entry, index) => ({
1474
+ key: keyAt(index),
1475
+ reviewers: finders(entry),
1476
+ id: entry.id,
1477
+ kind: entry.kind ?? "bug",
1478
+ title: entry.title,
1479
+ reason: entry.reason,
1480
+ refs: entry.refs ?? []
1481
+ }));
1482
+ return `${JSON.stringify({ reviewers, problems }, null, 2)}
1483
+ `;
1484
+ }
1485
+ function consolidationBrief(consolidation, brief) {
1486
+ const rules = ["What the review covers", "What is a problem", "What is never a problem", "Repository text"].flatMap((heading) => {
1487
+ const body = markdownSection(brief, heading);
1488
+ return body === void 0 ? [] : [`## ${heading}
1489
+
1490
+ ${body}`];
1491
+ });
1492
+ return [consolidation.trimEnd(), ...rules.length === 0 ? [] : ["# The rules of the review", ...rules]].join("\n\n");
1493
+ }
1494
+ function consolidationProtocol(instructions, answer, teamRules = false) {
1495
+ const kinds = `"bug"|"security"|"data"|"test"|"docs"|"comment"${teamRules ? '|"rule"' : ""}`;
1496
+ const ruleKind = teamRules ? " A problem that only one of this repository's rules makes a problem keeps the kind `rule`. It is in scope, so never drop it as `out-of-scope`. Its `trigger` is what the change does, and its `result` names the rule that the change breaks." : "";
1497
+ return `${instructions.trimEnd()}
1498
+
1499
+ ## How to answer
1500
+
1501
+ This section comes from the factory host and overrides any other answer format above. \`${JUDGE_DIR}/${CONSOLIDATION_INPUT}\` lists the new problems, each under a \`key\`. \`${JUDGE_DIR}/files.md\` lists the changed files, the \`diff-<n>.patch\` files hold the change and \`${JUDGE_TREE}/\` the files of the commit under review.
1502
+
1503
+ Write your answer as JSON to \`${answer}\`: \`{"problems":[{"from":["<key>"],"id":"<a short name>","kind":${kinds},"severity":"blocking"|"advisory","title":"<a short name>","reason":"<one to three sentences>","trigger":"<the input or state that triggers it>","result":"<the wrong result>","changed":{"path":"<changed file>","line":<the changed line that adds or causes it>},"refs":[{"path":"<path relative to ${JUDGE_TREE}/>","line":<the line in the commit>}]}],"dropped":[{"key":"<key>","why":"duplicate"|"out-of-scope"|"not-shown"|"wrong","of":"<key it repeats, for a duplicate>","reason":"<one sentence>"}]}\`. \`from\` lists every key the kept problem joins. Give each key once: in the \`from\` of one kept problem, or in \`dropped\`. Never keep a problem that no key names. The host drops a kept problem with no \`trigger\`, \`result\` or \`changed\` line of the change.${ruleKind}
1504
+ `;
1505
+ }
1506
+ function knownPlaces(raw, known) {
1507
+ if (!Array.isArray(raw)) return [];
1508
+ return raw.flatMap((entry) => {
1509
+ const { path, line } = typeof entry === "object" && entry !== null ? entry : {};
1510
+ if (typeof path !== "string" || path === "" || path.length > 1024 || !known(path)) return [];
1511
+ return [{ path, ...Number.isInteger(line) && line > 0 ? { line } : {} }];
1512
+ });
1513
+ }
1514
+ function text(raw, max) {
1515
+ return typeof raw === "string" && raw.trim() !== "" && raw.length <= max ? raw : void 0;
1516
+ }
1517
+ function severityOf(kind, lowered) {
1518
+ if (kind === "test" || kind === "docs" || kind === "comment") return "advisory";
1519
+ if (kind === "security" || kind === "data") return "blocking";
1520
+ return lowered === "advisory" ? "advisory" : "blocking";
1521
+ }
1522
+ function shown(said, inChange) {
1523
+ const changed = Object(said.changed);
1524
+ const placed = typeof changed.path === "string" && Number.isInteger(changed.line) && changed.line > 0 && inChange(changed.path, changed.line);
1525
+ return placed && text(said.trigger, 2e3) !== void 0 && text(said.result, 2e3) !== void 0;
1526
+ }
1527
+ var UNSHOWN_REASON = "The consolidator kept it without naming the trigger, the wrong result and a changed line.";
1528
+ function readConsolidation(raw, fresh, known, inChange) {
1529
+ if (raw === void 0 || raw.trim() === "") return { ok: false, reason: "the consolidator wrote no answer file" };
1530
+ let parsed;
1531
+ try {
1532
+ parsed = JSON.parse(raw);
1533
+ } catch {
1534
+ return { ok: false, reason: "the consolidator's answer is not JSON" };
1535
+ }
1536
+ const answer = Object(parsed);
1537
+ if (!Array.isArray(answer.problems)) return { ok: false, reason: "the consolidator's answer lists no problems" };
1538
+ const sources = new Map(fresh.map((entry, index) => [keyAt(index), entry]));
1539
+ const used = /* @__PURE__ */ new Set();
1540
+ const notes = [];
1541
+ const kept = [];
1542
+ const dropped = [];
1543
+ const droppedKeys = /* @__PURE__ */ new Set();
1544
+ for (const [index, item] of answer.problems.entries()) {
1545
+ const said = Object(item);
1546
+ const keys = Array.isArray(said.from) ? said.from.map(String).filter((key) => sources.has(key) && !used.has(key)) : [];
1547
+ if (keys.length === 0) {
1548
+ notes.push(`problem ${index + 1} of the answer names no reported problem, so it is ignored`);
1549
+ continue;
1550
+ }
1551
+ for (const key of keys) used.add(key);
1552
+ if (!shown(said, inChange)) {
1553
+ for (const key of keys) {
1554
+ droppedKeys.add(key);
1555
+ dropped.push({ key, id: sources.get(key).id, reviewers: finders(sources.get(key)), why: "not-shown", reason: UNSHOWN_REASON });
1556
+ }
1557
+ continue;
1558
+ }
1559
+ const first = sources.get(keys[0]);
1560
+ const refs = knownPlaces(said.refs, known);
1561
+ const kind = PROBLEM_KINDS.includes(said.kind) ? said.kind : first.kind ?? "bug";
1562
+ const title = text(said.title, 300) ?? first.title;
1563
+ const reason = text(said.reason, 4e3) ?? first.reason;
1564
+ kept.push({
1565
+ keys,
1566
+ entry: {
1567
+ id: text(said.id, 200) ?? first.id,
1568
+ result: "fail",
1569
+ kind,
1570
+ ...title === void 0 ? {} : { title },
1571
+ ...reason === void 0 ? {} : { reason },
1572
+ refs: refs.length > 0 ? refs : first.refs ?? [],
1573
+ severity: severityOf(kind, problemSeverity(said.severity)),
1574
+ ...first.reviewer === void 0 ? {} : { reviewer: first.reviewer }
1575
+ }
1576
+ });
1577
+ }
1578
+ const keptKey = (key) => kept.find((problem) => problem.keys.some((held) => held === key));
1579
+ const drops = Array.isArray(answer.dropped) ? answer.dropped : [];
1580
+ const ordered = [...drops.filter((drop) => Object(drop).why !== "duplicate"), ...drops.filter((drop) => Object(drop).why === "duplicate")];
1581
+ for (const drop of ordered) {
1582
+ const said = Object(drop);
1583
+ const key = String(said.key);
1584
+ if (!sources.has(key) || used.has(key)) continue;
1585
+ if (!DROP_REASONS.includes(said.why)) {
1586
+ notes.push(`the drop of ${key} gives no known reason, so ${key} is kept`);
1587
+ continue;
1588
+ }
1589
+ const why = said.why;
1590
+ const of = typeof said.of === "string" ? said.of : void 0;
1591
+ if (why === "duplicate") {
1592
+ const target = keptKey(of);
1593
+ if (target === void 0 && !droppedKeys.has(of)) {
1594
+ notes.push(`${key} is called a duplicate of ${of ?? "nothing"}, which is no kept or dropped problem, so ${key} is kept`);
1595
+ continue;
1596
+ }
1597
+ if (target !== void 0) target.keys.push(key);
1598
+ }
1599
+ used.add(key);
1600
+ droppedKeys.add(key);
1601
+ const source = sources.get(key);
1602
+ const reason = text(said.reason, 1e3);
1603
+ dropped.push({ key, id: source.id, reviewers: finders(source), why, ...of === void 0 ? {} : { of }, ...reason === void 0 ? {} : { reason } });
1604
+ }
1605
+ const items = kept.map(({ entry, keys }) => {
1606
+ const reviewers = [...new Set(keys.flatMap((key) => finders(sources.get(key))))];
1607
+ return reviewers.length === 0 ? entry : { ...entry, foundBy: reviewers };
1608
+ });
1609
+ for (const [key, entry] of sources) {
1610
+ if (used.has(key)) continue;
1611
+ notes.push(`the answer neither keeps nor drops ${key} (${entry.id}), so it is kept as reported`);
1612
+ items.push({ ...entry, severity: severityOf(entry.kind) });
1613
+ }
1614
+ return { ok: true, items, dropped, notes };
1615
+ }
1616
+
1438
1617
  // src/runner/code-review-problems.ts
1439
1618
  var EXCERPT_CONTEXT_LINES = 5;
1440
1619
  var EXCERPT_LINE_MAX = 300;
1441
1620
  var PROBLEMS_MAX = CODE_REVIEW_PROBLEMS_MAX;
1442
1621
  var FILES_MAX = 2e3;
1443
1622
  var TITLE_MAX = 300;
1444
- function storable(text) {
1445
- return text.replace(/\u0000/g, "").replace(/\p{Cs}/gu, "");
1623
+ var CONSOLIDATION_REASON_MAX = 200;
1624
+ function storable(text2) {
1625
+ return text2.replace(/\u0000/g, "").replace(/\p{Cs}/gu, "");
1446
1626
  }
1447
- function problemExcerpt(text, line) {
1448
- if (text === void 0 || line === void 0 || !Number.isInteger(line) || line < 1) return null;
1449
- const lines = storable(text).split(/\r\n|\r|\n/);
1627
+ function problemExcerpt(text2, line) {
1628
+ if (text2 === void 0 || line === void 0 || !Number.isInteger(line) || line < 1) return null;
1629
+ const lines = storable(text2).split(/\r\n|\r|\n/);
1450
1630
  if (lines.at(-1) === "") lines.pop();
1451
1631
  if (line > lines.length) return null;
1452
1632
  const startLine = Math.max(1, line - EXCERPT_CONTEXT_LINES);
@@ -1469,13 +1649,14 @@ function reviewRecord(input) {
1469
1649
  problems.push({
1470
1650
  id: item.id,
1471
1651
  kind: problemKind(entry.kind),
1472
- title: titleOf(entry.title, item.id, input.clean ?? ((text) => text)),
1652
+ title: titleOf(entry.title, item.id, input.clean ?? ((text2) => text2)),
1473
1653
  reason: item.reason ?? "",
1474
1654
  path: place?.path ?? "",
1475
1655
  line: place?.line ?? null,
1476
1656
  inDiff: place?.inDiff === true,
1477
1657
  excerpt: place === void 0 ? null : input.excerptOf(place.path, place.line),
1478
- reviewer: entry.reviewer ?? ""
1658
+ reviewer: entry.reviewer ?? "",
1659
+ severity: entry.severity ?? null
1479
1660
  });
1480
1661
  }
1481
1662
  const files = unreviewedFiles(input.changed, input.merged.reviewed);
@@ -1491,6 +1672,11 @@ function reviewRecord(input) {
1491
1672
  // src/runner/code-review-report.ts
1492
1673
  var REPORT_RETRY_WINDOW_MS = 2e4;
1493
1674
  var MAX_REASON_LENGTH = 2e3;
1675
+ function withoutRuleKind(report) {
1676
+ if (report.result !== "reviewed" || report.review === void 0) return void 0;
1677
+ if (!report.review.problems.some((problem) => problem.kind === "rule")) return void 0;
1678
+ return { ...report, review: { ...report.review, problems: report.review.problems.map((problem) => problem.kind === "rule" ? { ...problem, kind: "bug" } : problem) } };
1679
+ }
1494
1680
  async function reportCodeReview(config, job, report, deps) {
1495
1681
  if (job.queue !== "review") return;
1496
1682
  const tag = itemTag(job);
@@ -1499,12 +1685,22 @@ async function reportCodeReview(config, job, report, deps) {
1499
1685
  const item = claimItem(config, job);
1500
1686
  const body = report.result === "failed" ? { ...report, runnerReason: report.runnerReason.slice(0, MAX_REASON_LENGTH) } : report;
1501
1687
  const signer = await signerFor(calls.configPath);
1502
- const sent = await retrySend(() => postJson(calls.url, `/v1/work-items/${item}/claim/code-review`, calls.apiKey, calls.appId, body, deps.fetchImpl, void 0, signer), {
1688
+ const send = (payload) => retrySend(() => postJson(calls.url, `/v1/work-items/${item}/claim/code-review`, calls.apiKey, calls.appId, payload, deps.fetchImpl, void 0, signer), {
1503
1689
  now: deps.now,
1504
1690
  sleep: deps.sleep,
1505
1691
  windowMs: REPORT_RETRY_WINDOW_MS
1506
1692
  });
1507
- if (!sent.ok) deps.log.line(`${tag} the code review's report was not recorded: ${sent.reason}`);
1693
+ const sent = await send(body);
1694
+ if (sent.ok) return;
1695
+ const older = sent.retryable ? void 0 : withoutRuleKind(body);
1696
+ if (older !== void 0) {
1697
+ const again = await send(older);
1698
+ if (again.ok) {
1699
+ deps.log.line(`${tag} the gateway refused the code review's report, and took it with each team rule problem as a bug: ${sent.reason}`);
1700
+ return;
1701
+ }
1702
+ }
1703
+ deps.log.line(`${tag} the code review's report was not recorded: ${sent.reason}`);
1508
1704
  } catch (err) {
1509
1705
  deps.log.line(`${tag} the code review's report was not sent: ${describeCallFailure(err)}`);
1510
1706
  }
@@ -1520,13 +1716,15 @@ function readStoredProblems(data) {
1520
1716
  {
1521
1717
  id: row.id,
1522
1718
  status: row.status,
1523
- kind: problemKind(row.kind),
1719
+ // A gateway gives a problem of kind `rule` as a bug with `teamRule` set, for a runner that predates the kind.
1720
+ kind: row.teamRule === true ? "rule" : problemKind(row.kind),
1524
1721
  title: typeof row.title === "string" ? row.title : "",
1525
1722
  reason: typeof row.reason === "string" ? row.reason : "",
1526
1723
  path: typeof row.path === "string" ? row.path : "",
1527
1724
  line: typeof row.line === "number" && Number.isInteger(row.line) ? row.line : null,
1528
1725
  commit: typeof row.commit === "string" ? row.commit : "",
1529
- dismissalReason: typeof row.dismissalReason === "string" ? row.dismissalReason : null
1726
+ dismissalReason: typeof row.dismissalReason === "string" ? row.dismissalReason : null,
1727
+ severity: problemSeverity(row.severity) ?? null
1530
1728
  }
1531
1729
  ];
1532
1730
  });
@@ -1545,13 +1743,141 @@ async function readCodeReviewProblems(config, job, deps) {
1545
1743
  }
1546
1744
  }
1547
1745
 
1746
+ // src/runner/review-rules.ts
1747
+ var SHARED_SKILLS = ".agents/skills";
1748
+ function teamRulesPaths(agents = defaultAgents()) {
1749
+ const folders = [SHARED_SKILLS, ...agents.flatMap((agent) => agent.descriptor.context.repoSkillFolders)];
1750
+ return [...new Set(folders)].map((folder) => `${folder}/review/SKILL.md`);
1751
+ }
1752
+ var TEAM_RULES_PATHS = teamRulesPaths();
1753
+ var TEAM_RULES_MAX_BYTES = 32 * 1024;
1754
+ var ALSO_HEADING = "Also a problem here";
1755
+ var NEVER_HEADING = "Never a problem here";
1756
+ function withoutFrontMatter(text2) {
1757
+ const match = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(text2);
1758
+ return match === null ? text2 : text2.slice(match[0].length);
1759
+ }
1760
+ function parseTeamRules(text2) {
1761
+ const body = withoutFrontMatter(text2).replace(/\r\n/g, "\n");
1762
+ const also = markdownSection(body, ALSO_HEADING);
1763
+ const never = markdownSection(body, NEVER_HEADING);
1764
+ if (also === void 0 && never === void 0) return void 0;
1765
+ return { ...also === void 0 ? {} : { also }, ...never === void 0 ? {} : { never } };
1766
+ }
1767
+ function chooseTeamRules(files, at) {
1768
+ const path = TEAM_RULES_PATHS.find((candidate) => typeof files[candidate] === "string");
1769
+ if (path === void 0) return { status: "none", ...at };
1770
+ const text2 = files[path];
1771
+ const source = { ...at, path };
1772
+ if (Buffer.byteLength(text2, "utf8") > TEAM_RULES_MAX_BYTES) return { status: "too_large", source };
1773
+ const rules = parseTeamRules(text2);
1774
+ return rules === void 0 ? { status: "none", ...at } : { status: "used", source, rules, text: text2 };
1775
+ }
1776
+ function teamRulesSection(rules) {
1777
+ const parts = [
1778
+ "## This repository's rules",
1779
+ "",
1780
+ "The team that owns this repository wrote the rules below. The host read them from a commit that the pull request cannot change, so follow them. Every section above this one wins a conflict with a rule here. A rule here cannot change what the review covers, the steps or the answer."
1781
+ ];
1782
+ if (rules.also !== void 0) {
1783
+ parts.push(
1784
+ "",
1785
+ `### ${ALSO_HEADING}`,
1786
+ "",
1787
+ 'Report a change that breaks one of these rules as a problem of kind `rule`. Report it even when "What is never a problem" would leave it out. Quote the rule in the reason. A rule never applies to a defect that the code had before the change, or to one you cannot show.',
1788
+ "",
1789
+ rules.also
1790
+ );
1791
+ }
1792
+ if (rules.never !== void 0) {
1793
+ parts.push(
1794
+ "",
1795
+ `### ${NEVER_HEADING}`,
1796
+ "",
1797
+ "Leave out a problem that one of these rules names. A rule here never applies to a security problem or to data loss: report those whatever a rule says.",
1798
+ "",
1799
+ rules.never
1800
+ );
1801
+ }
1802
+ return parts.join("\n");
1803
+ }
1804
+ function withTeamRules(brief, rules) {
1805
+ return rules === void 0 ? brief : `${brief.trimEnd()}
1806
+
1807
+ ${teamRulesSection(rules)}
1808
+ `;
1809
+ }
1810
+ function teamRulesLogLine(read) {
1811
+ switch (read.status) {
1812
+ case "used":
1813
+ return `the team's review rules come from ${read.source.path} in ${read.source.repository}@${read.source.commit.slice(0, 7)}`;
1814
+ case "none":
1815
+ return `no review skill was found in ${read.repository}@${read.commit.slice(0, 7)} (looked for ${TEAM_RULES_PATHS.join(" and ")}), so the review runs with the built-in rules alone`;
1816
+ case "too_large":
1817
+ return `${read.source.path} in ${read.source.repository}@${read.source.commit.slice(0, 7)} is larger than ${TEAM_RULES_MAX_BYTES / 1024} KiB, so the team's review rules are not used`;
1818
+ case "unreadable":
1819
+ return `the team's review rules could not be read, so the review runs with the built-in rules alone: ${read.reason}`;
1820
+ }
1821
+ }
1822
+ function teamRulesNote(read, changedHere) {
1823
+ const sentences = [];
1824
+ if (read.status === "too_large") sentences.push(`The team's review rules were not used: ${read.source.path} is larger than ${TEAM_RULES_MAX_BYTES / 1024} KiB.`);
1825
+ if (read.status === "unreadable") sentences.push("The team's review rules were not used: the runner could not read them.");
1826
+ if (changedHere) sentences.push("This pull request changes the team's review rules. The change applies to reviews after it merges.");
1827
+ return sentences.length === 0 ? void 0 : sentences.join(" ");
1828
+ }
1829
+ function teamRulesItem(note, commit) {
1830
+ return { id: TEAM_RULES_ITEM_ID, result: "skipped", commit, reason: note };
1831
+ }
1832
+ function changesTeamRules(paths) {
1833
+ return paths.some((path) => TEAM_RULES_PATHS.includes(path));
1834
+ }
1835
+
1836
+ // src/runner/review-rules-read.ts
1837
+ async function readTeamRules(input) {
1838
+ const { config, job, repository } = input;
1839
+ const paths = [...TEAM_RULES_PATHS];
1840
+ try {
1841
+ const governing = await (input.resolve ?? ((name) => resolveGoverningSource({ config: claimCalls(config, job), repository: name, fetchImpl: input.fetchImpl })))(repository);
1842
+ if (!governing.ok) return { status: "unreadable", reason: governing.reason };
1843
+ if (governing.source.kind === "governed") {
1844
+ const source = governing.source;
1845
+ const organizationId = config.fleet === true ? job.organizationId : void 0;
1846
+ const read2 = await (input.readGoverned ?? readGovernedFiles)({
1847
+ configPath: config.configPath,
1848
+ ...organizationId === void 0 ? {} : { organizationId },
1849
+ repository,
1850
+ source,
1851
+ paths,
1852
+ controlPlaneUrl: input.controlPlaneUrl,
1853
+ ...input.controlPlaneToken === void 0 ? {} : { controlPlaneToken: input.controlPlaneToken },
1854
+ log: input.log,
1855
+ tag: input.tag
1856
+ });
1857
+ if (!read2.ok) return { status: "unreadable", reason: read2.reason };
1858
+ return chooseTeamRules(read2.files, { repository: source.repository, commit: source.sha });
1859
+ }
1860
+ const read = await (input.readBranch ?? readDefaultBranchFiles)({
1861
+ remote: input.remote,
1862
+ dir: input.dir,
1863
+ paths,
1864
+ ...input.readToken === void 0 ? {} : { token: input.readToken },
1865
+ ...input.baseBranch === void 0 ? {} : { branch: input.baseBranch }
1866
+ });
1867
+ if (!read.ok) return { status: "unreadable", reason: read.reason };
1868
+ return chooseTeamRules(read.files, { repository, commit: read.commit });
1869
+ } catch (err) {
1870
+ return { status: "unreadable", reason: err instanceof Error ? err.message : String(err) };
1871
+ }
1872
+ }
1873
+
1548
1874
  // src/runner/review-job.ts
1549
1875
  var REVIEW_SKILL = "outerlayer-review";
1550
1876
  var REVIEW_EFFORT = "high";
1551
1877
  var MAX_DIFF_BYTES = 4 * 1024 * 1024;
1552
- function withoutFrontMatter(text) {
1553
- const match = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(text);
1554
- return match === null ? text : text.slice(match[0].length).trimStart();
1878
+ function withoutFrontMatter2(text2) {
1879
+ const match = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(text2);
1880
+ return match === null ? text2 : text2.slice(match[0].length).trimStart();
1555
1881
  }
1556
1882
  function readReviewInstructions(root = resolvePackRoot()) {
1557
1883
  const dir = join(root, "maintained", REVIEW_SKILL);
@@ -1561,14 +1887,17 @@ function readReviewInstructions(root = resolvePackRoot()) {
1561
1887
  } catch {
1562
1888
  return void 0;
1563
1889
  }
1564
- let briefs;
1565
- try {
1566
- briefs = readFileSync(join(dir, "references", "territories.md"), "utf8");
1567
- } catch {
1568
- briefs = void 0;
1569
- }
1570
- const sha256 = createHash("sha256").update(skill).update("\0").update(briefs ?? "").digest("hex");
1571
- return { brief: withoutFrontMatter(skill), territories: briefs, sha256 };
1890
+ const reference = (name) => {
1891
+ try {
1892
+ return readFileSync(join(dir, "references", name), "utf8");
1893
+ } catch {
1894
+ return void 0;
1895
+ }
1896
+ };
1897
+ const briefs = reference("territories.md");
1898
+ const consolidation = reference("consolidation.md");
1899
+ const sha256 = createHash("sha256").update(skill).update("\0").update(briefs ?? "").update("\0").update(consolidation ?? "").digest("hex");
1900
+ return { brief: withoutFrontMatter2(skill), territories: briefs, consolidation, sha256 };
1572
1901
  }
1573
1902
  function reviewIsolation(config) {
1574
1903
  const kind = builtinKind(config.hooks.provision);
@@ -1580,21 +1909,23 @@ function takesReview(config, agents = defaultAgents()) {
1580
1909
  const agent = judgeAgent(agents);
1581
1910
  return agent?.adapter.headless !== void 0 && agent.adapter.image?.program !== void 0;
1582
1911
  }
1583
- function reviewAnswerProtocol(brief, answer) {
1912
+ function reviewAnswerProtocol(brief, answer, teamRules = false) {
1913
+ const kinds = `"bug"|"security"|"data"|"test"|"docs"|"comment"${teamRules ? '|"rule"' : ""}`;
1914
+ const ruleKind = teamRules ? " Use `rule` for a problem that only one of this repository's rules makes a problem." : "";
1584
1915
  return `${brief.trimEnd()}
1585
1916
 
1586
1917
  ## How to answer
1587
1918
 
1588
1919
  This section comes from the factory host and overrides any other answer format above. \`${JUDGE_DIR}/files.md\` lists the changed files, \`${JUDGE_DIR}/diff.patch\` holds the change and \`${JUDGE_TREE}/\` the files of the commit under review.
1589
1920
 
1590
- Write your answer as JSON to \`${answer}\`: \`{"reviewed":["<changed file path>"],"previous":[{"id":"<id in previous.json>","verdict":"fixed"|"open","line":<its line in the commit, when open>}],"problems":[{"id":"<a short name>","kind":"bug"|"security"|"data"|"test"|"docs"|"comment","title":"<a short name>","reason":"<one to three sentences>","refs":[{"path":"<path relative to ${JUDGE_TREE}/>","line":<the line in the commit>}]}]}\`. Each problem is unique by its id in the answer, and names in \`refs\` the file and line it is about. \`reviewed\` lists each changed file you read in full, by its path in the repository. \`previous\` gives a verdict on each defect in \`previous.json\`, when the file exists. Never list a defect of \`previous.json\` in \`problems\`: the host keeps each one that is still open. \`kind\` is what the problem is about, and \`bug\` when none fits. A reason quotes the decisive line or names what is missing. An answer with no problems lists none.
1921
+ Write your answer as JSON to \`${answer}\`: \`{"reviewed":["<changed file path>"],"previous":[{"id":"<id in previous.json>","verdict":"fixed"|"open","line":<its line in the commit, when open>}],"problems":[{"id":"<a short name>","kind":${kinds},"title":"<a short name>","reason":"<one to three sentences>","refs":[{"path":"<path relative to ${JUDGE_TREE}/>","line":<the line in the commit>}]}]}\`. Each problem is unique by its id in the answer, and names in \`refs\` the file and line it is about. \`reviewed\` lists each changed file you read in full, by its path in the repository. \`previous\` gives a verdict on each defect in \`previous.json\`, when the file exists. Never list a defect of \`previous.json\` in \`problems\`: the host keeps each one that is still open. \`kind\` is what the problem is about, and \`bug\` when none fits.${ruleKind} A reason quotes the decisive line or names what is missing. An answer with no problems lists none.
1591
1922
  `;
1592
1923
  }
1593
- function parseReviewAnswer(text) {
1594
- if (text === void 0 || text.trim() === "") return void 0;
1924
+ function parseReviewAnswer(text2) {
1925
+ if (text2 === void 0 || text2.trim() === "") return void 0;
1595
1926
  let raw;
1596
1927
  try {
1597
- raw = JSON.parse(text);
1928
+ raw = JSON.parse(text2);
1598
1929
  } catch {
1599
1930
  return { ok: false, reason: "the reviewer's answer is not JSON" };
1600
1931
  }
@@ -1615,12 +1946,15 @@ function readReviewerEnd(run, minutes, agents = defaultAgents()) {
1615
1946
  if (output.kind === "turn-limit") return { finished: false, reason: `the review reached the turn limit of ${JUDGE_MAX_TURNS} turns`, ...usage };
1616
1947
  return { finished: true, ...usage };
1617
1948
  }
1949
+ function instructionsHash(shipped, teamRulesText) {
1950
+ return teamRulesText === void 0 ? shipped : createHash("sha256").update(shipped).update("\0").update(teamRulesText).digest("hex");
1951
+ }
1618
1952
  async function runReviewJob(input) {
1619
1953
  const { config, job, jobDir: jobDir2, deps } = input;
1620
1954
  const { runtime, log } = deps;
1621
1955
  const tag = itemTag(job);
1622
1956
  const scratch = join(jobDir2, "review-scratch");
1623
- const cleanReason = (text) => scrubReason(text, config, void 0, jobDir2, CHECK_ITEM_REASON_MAX_LENGTH) ?? "";
1957
+ const cleanReason = (text2) => scrubReason(text2, config, void 0, jobDir2, CHECK_ITEM_REASON_MAX_LENGTH) ?? "";
1624
1958
  const notRun = async (reason) => {
1625
1959
  if (input.ending()) return { kind: "ended" };
1626
1960
  const said = oneLineReason(cleanReason(reason)) ?? "the code review did not run";
@@ -1674,6 +2008,26 @@ async function runReviewJob(input) {
1674
2008
  [the diff was cut at ${MAX_DIFF_BYTES} bytes]
1675
2009
  ` : bytes.toString("utf8");
1676
2010
  const { files, changed } = reviewFiles(diff);
2011
+ const controlPlaneUrl = (controlPlane) => runtime.remoteFor?.(controlPlane) ?? `${runtime.github.gitUrl}/${controlPlane}.git`;
2012
+ const teamRules = await (input.readRules ?? readTeamRules)({
2013
+ config,
2014
+ job,
2015
+ repository,
2016
+ remote,
2017
+ baseBranch: base === void 0 ? void 0 : job.reviewBase,
2018
+ dir: join(scratch, "rules"),
2019
+ readToken,
2020
+ controlPlaneUrl,
2021
+ controlPlaneToken: () => tokens.controlPlane(),
2022
+ fetchImpl: deps.fetchImpl,
2023
+ log,
2024
+ tag
2025
+ });
2026
+ log.line(`${tag} ${cleanReason(teamRulesLogLine(teamRules))}`);
2027
+ const rules = teamRules.status === "used" ? teamRules.rules : void 0;
2028
+ const rulesRepository = teamRules.status === "none" ? teamRules.repository : teamRules.status === "unreadable" ? void 0 : teamRules.source.repository;
2029
+ const changedHere = rulesRepository?.toLowerCase() === repository.toLowerCase() && changesTeamRules(changed.map((file) => file.path));
2030
+ const note = teamRulesNote(teamRules, changedHere);
1677
2031
  const workItem = await readWorkItem(itemCalls(config, job), job.item, deps.fetchImpl);
1678
2032
  const issue = issueText(workItem, criteriaOf(workItem));
1679
2033
  if (issue !== void 0) files["issue.md"] = issue;
@@ -1684,34 +2038,59 @@ async function runReviewJob(input) {
1684
2038
  log.line(`${tag} code review of ${head.slice(0, 8)}: ${changed.length} changed ${changed.length === 1 ? "file" : "files"}, reviewers ${runs.map((run) => run.name).join(", ")}`);
1685
2039
  const limitMinutes = config.checks?.timeLimitMinutes ?? DEFAULT_CHECK_TIME_LIMIT_MINUTES;
1686
2040
  const minutes = `${limitMinutes} ${limitMinutes === 1 ? "minute" : "minutes"}`;
1687
- const reviewed = await reviewSideBySide({ environment, files, tree: treeDir, runs, brief: instructions.brief, credential, limitMinutes, minutes, jobDir: jobDir2, deps, tag });
2041
+ const reviewerRuns = runs.map((territory, index) => {
2042
+ const answerName = index === 0 ? "items.json" : `items-${territory.name}.json`;
2043
+ return { territory, answerName, logName: index === 0 ? "review.log" : `review-${territory.name}.log`, prompt: reviewAnswerProtocol(withTeamRules(territoryBrief(instructions.brief, territory), rules), `${JUDGE_DIR}/${answerName}`, rules !== void 0) };
2044
+ });
2045
+ const reviewed = await reviewSideBySide({ environment, files, tree: treeDir, runs: reviewerRuns, credential, limitMinutes, minutes, jobDir: jobDir2, deps, tag });
1688
2046
  if (!reviewed.ok) return await notRun(reviewed.reason);
1689
2047
  if (input.ending()) return { kind: "ended" };
2048
+ let ownTree = false;
2049
+ try {
2050
+ lstatSync(join(treeDir, "tree"));
2051
+ ownTree = true;
2052
+ } catch {
2053
+ }
2054
+ const changedPaths = new Set(changed.map((file) => file.path));
2055
+ const known = (raw) => {
2056
+ const written = treePath(raw, JUDGE_TREE);
2057
+ if (written === void 0) return false;
2058
+ const path = written.startsWith("tree/") && !ownTree ? written.slice("tree/".length) : written;
2059
+ return changedPaths.has(path) || treeFileText(treeDir, path) !== void 0;
2060
+ };
2061
+ const shownLines = diffLines(diff);
2062
+ const inChange = (raw, line) => {
2063
+ const written = treePath(raw, JUDGE_TREE);
2064
+ const path = written !== void 0 && written.startsWith("tree/") && !ownTree ? written.slice("tree/".length) : written;
2065
+ if (path === void 0 || !changedPaths.has(path)) return false;
2066
+ return shownLines.has(path) ? lineInDiff(shownLines, path, line) : true;
2067
+ };
1690
2068
  const answers = [];
1691
- for (const { territory, end, answer } of reviewed.runs) {
2069
+ for (const { territory, end, answer } of reviewed.runs.map((run) => ({ ...run, answer: parseReviewAnswer(run.text) }))) {
1692
2070
  if (answer?.ok === true) {
1693
- answers.push({ ...answer.answer, items: answer.answer.items.map((entry) => ({ ...entry, reviewer: territory.name })) });
2071
+ const guarded = dropNonProblems(answer.answer, known);
2072
+ for (const { id, why } of guarded.dropped) log.line(`${tag} the ${territory.name} review's entry ${JSON.stringify(id)} is no problem (${why}), so it is left out`);
2073
+ answers.push({ ...guarded.answer, items: guarded.answer.items.map((entry) => ({ ...entry, reviewer: territory.name })) });
1694
2074
  if (!end.finished) log.line(`${tag} the ${territory.name} review stopped before it ended, so only what it found is kept: ${end.reason}`);
1695
2075
  } else log.line(`${tag} the ${territory.name} review gave no answer: ${answer?.ok === false ? answer.reason : end.finished ? "it wrote no answer file" : end.reason}`);
1696
2076
  }
1697
2077
  if (answers.length === 0) {
1698
2078
  const first = reviewed.runs[0];
1699
- return await notRun(first.answer?.ok === false ? first.answer.reason : first.end.finished ? "the review wrote no answer file" : first.end.reason);
2079
+ const answer = parseReviewAnswer(first.text);
2080
+ return await notRun(answer?.ok === false ? answer.reason : first.end.finished ? "the review wrote no answer file" : first.end.reason);
1700
2081
  }
1701
- const merged = carryProblems(mergeAnswers(answers), stored ?? []);
2082
+ const joined = mergeAnswers(answers);
2083
+ const { kept, fresh } = carriedProblems(joined, stored ?? []);
2084
+ const consolidated = await consolidate({ fresh, reviewers: answers.length, names: runs.map((run) => run.name) });
2085
+ if (input.ending()) return { kind: "ended" };
2086
+ const merged = { ...joined, items: [...kept, ...consolidated.items] };
1702
2087
  const finder = await loadCitationFinder();
1703
- let ownTree = false;
1704
- try {
1705
- lstatSync(join(treeDir, "tree"));
1706
- ownTree = true;
1707
- } catch {
1708
- }
1709
2088
  const place = (path, line) => {
1710
2089
  if (treeFileText(treeDir, path) === void 0) return {};
1711
2090
  const href = finder.testHref(repository, head, path, line ?? 1);
1712
2091
  return href !== null && href.length <= CHECK_ITEM_HREF_MAX_LENGTH && /^https:\/\/\S+$/.test(href) ? { href } : {};
1713
2092
  };
1714
- const items = wholeItems({ answer: merged, commit: head, treeRoot: JUDGE_TREE, place, ownTree, patch: diff, clean: cleanReason });
2093
+ const items = wholeItems({ answer: merged, commit: head, treeRoot: JUDGE_TREE, place, ownTree, patch: diff, clean: cleanReason, reviewers: answers.length });
1715
2094
  const unreviewed = unreviewedItem(changed, merged.reviewed, head);
1716
2095
  const record2 = {
1717
2096
  ...reviewRecord({
@@ -1724,15 +2103,20 @@ async function runReviewJob(input) {
1724
2103
  seconds: run.end.usage?.durationMs === void 0 ? run.seconds : run.end.usage.durationMs / 1e3,
1725
2104
  ...run.end.usage?.costUsd === void 0 ? {} : { costUsd: run.end.usage.costUsd },
1726
2105
  // A reviewer that stopped early or wrote no answer proves nothing about a problem that it did not report.
1727
- answered: run.answer?.ok === true && run.end.finished
2106
+ answered: parseReviewAnswer(run.text)?.ok === true && run.end.finished
1728
2107
  })),
1729
2108
  excerptOf: (path, line) => problemExcerpt(treeFileText(treeDir, path), line),
1730
2109
  clean: cleanReason
1731
2110
  }),
1732
- instructions: { cliVersion: deps.cliVersion, sha256: instructions.sha256 }
2111
+ instructions: {
2112
+ cliVersion: deps.cliVersion,
2113
+ sha256: instructionsHash(instructions.sha256, teamRules.status === "used" ? teamRules.text : void 0),
2114
+ ...teamRules.status === "used" ? { rulesRepository: teamRules.source.repository, rulesCommit: teamRules.source.commit } : {}
2115
+ },
2116
+ consolidation: consolidated.record
1733
2117
  };
1734
2118
  if (input.ending()) return { kind: "ended" };
1735
- const listed = unreviewed === void 0 ? items : [...items, unreviewed];
2119
+ const listed = [...items, ...unreviewed === void 0 ? [] : [unreviewed], ...note === void 0 ? [] : [teamRulesItem(note, head)]];
1736
2120
  const failing = itemsSentence(listed, { one: "problem", many: "problems" });
1737
2121
  const result = failing === void 0 ? "pass" : "fail";
1738
2122
  const recordResult = makeRecorder({ config, job, jobDir: jobDir2, deps });
@@ -1743,6 +2127,50 @@ async function runReviewJob(input) {
1743
2127
  await reportCodeReview(config, job, { result: "reviewed", reason: "reviewed", commit: head, problems, review: record2 }, deps);
1744
2128
  log.line(`${tag} code review done: ${problems} ${problems === 1 ? "problem" : "problems"}`);
1745
2129
  return { kind: "reviewed", problems };
2130
+ async function consolidate(input2) {
2131
+ const unchanged = (result2, reason) => {
2132
+ log.line(`${tag} the problems were not consolidated: ${reason}`);
2133
+ const items2 = input2.fresh.map((entry) => ({ ...entry, severity: severityOf(entry.kind) }));
2134
+ return { items: items2, record: { result: result2, reason: oneLineReason(cleanReason(reason))?.slice(0, CONSOLIDATION_REASON_MAX) ?? result2 } };
2135
+ };
2136
+ if (!shouldConsolidate(input2.reviewers, input2.fresh.length)) return unchanged("skipped", input2.fresh.length === 0 ? "no reviewer reported a new problem" : "one reviewer reported one problem");
2137
+ if (instructions.consolidation === void 0) return unchanged("skipped", `this CLI's ${REVIEW_SKILL} skill holds no consolidation instructions`);
2138
+ try {
2139
+ return await runPass(instructions.consolidation);
2140
+ } catch (err) {
2141
+ return unchanged("failed", `the consolidator could not be run: ${describeCallFailure(err)}`);
2142
+ }
2143
+ async function runPass(text2) {
2144
+ const answer = `${JUDGE_DIR}/${CONSOLIDATION_ANSWER}`;
2145
+ const run = await reviewSideBySide({
2146
+ environment,
2147
+ files: { ...files, [CONSOLIDATION_INPUT]: consolidationInput(input2.fresh, input2.names) },
2148
+ tree: treeDir,
2149
+ runs: [{
2150
+ territory: { name: CONSOLIDATOR, text: "" },
2151
+ answerName: CONSOLIDATION_ANSWER,
2152
+ logName: `review-${CONSOLIDATOR}.log`,
2153
+ // The pass holds problems to the team's rules too, or it would drop each problem that only such a rule makes one.
2154
+ prompt: consolidationProtocol(withTeamRules(consolidationBrief(text2, instructions.brief), rules), answer, rules !== void 0)
2155
+ }],
2156
+ credential,
2157
+ limitMinutes,
2158
+ minutes,
2159
+ jobDir: jobDir2,
2160
+ deps,
2161
+ tag
2162
+ });
2163
+ if (!run.ok) return unchanged("failed", run.reason);
2164
+ const { end, text: written } = run.runs[0];
2165
+ if (!end.finished) return unchanged("failed", end.reason);
2166
+ const read = readConsolidation(written, input2.fresh, known, inChange);
2167
+ if (!read.ok) return unchanged("failed", read.reason);
2168
+ for (const note2 of read.notes) log.line(`${tag} consolidation: ${note2}`);
2169
+ for (const drop of read.dropped) log.line(`${tag} consolidation dropped ${JSON.stringify(drop.id)} (${drop.reviewers.join(", ") || "no reviewer"}): ${drop.why}${drop.of === void 0 ? "" : ` of ${drop.of}`}${drop.reason === void 0 ? "" : `: ${oneLineReason(cleanReason(drop.reason)) ?? ""}`}`);
2170
+ log.line(`${tag} consolidation kept ${read.items.length} of ${input2.fresh.length} new ${input2.fresh.length === 1 ? "problem" : "problems"}`);
2171
+ return { items: read.items, record: { result: "consolidated" } };
2172
+ }
2173
+ }
1746
2174
  }
1747
2175
  }
1748
2176
  function withCommit(items, commit, result) {
@@ -1756,13 +2184,12 @@ async function reviewSideBySide(input) {
1756
2184
  } catch (err) {
1757
2185
  return { ok: false, reason: `the review could not be prepared: ${describeCallFailure(err)}` };
1758
2186
  }
1759
- const started = input.runs.map((territory, index) => {
1760
- const answerName = index === 0 ? "items.json" : `items-${territory.name}.json`;
2187
+ const started = input.runs.map(({ territory, prompt, answerName, logName }) => {
1761
2188
  const answer = `${JUDGE_DIR}/${answerName}`;
1762
- const command = judgeCommand({ brief: reviewAnswerProtocol(territoryBrief(input.brief, territory), answer), credential: input.credential, effort: REVIEW_EFFORT, answer }, deps.runtime.agents);
2189
+ const command = judgeCommand({ brief: prompt, credential: input.credential, effort: REVIEW_EFFORT, answer }, deps.runtime.agents);
1763
2190
  const began = now().getTime();
1764
2191
  const run = { territory, answerName, began, seconds: void 0, outcome: void 0 };
1765
- const settled = environment.run(command, { logPath: join(input.jobDir, index === 0 ? "review.log" : `review-${territory.name}.log`) }).then(
2192
+ const settled = environment.run(command, { logPath: join(input.jobDir, logName) }).then(
1766
2193
  (result) => result,
1767
2194
  (err) => err instanceof Error ? err : new Error(String(err))
1768
2195
  );
@@ -1782,7 +2209,7 @@ async function reviewSideBySide(input) {
1782
2209
  const answers = await Promise.all(
1783
2210
  started.map(async ({ run }) => {
1784
2211
  try {
1785
- return parseReviewAnswer(await environment.readItems(run.answerName));
2212
+ return await environment.readItems(run.answerName);
1786
2213
  } catch (err) {
1787
2214
  deps.log.error(`${tag} the ${run.territory.name} review's answer could not be read: ${describeCallFailure(err)}`);
1788
2215
  return void 0;
@@ -1799,7 +2226,7 @@ async function reviewSideBySide(input) {
1799
2226
  const outcome = run.outcome;
1800
2227
  if (outcome instanceof Error) deps.log.error(`${tag} the ${run.territory.name} review could not be run: ${describeCallFailure(outcome)}`);
1801
2228
  const ran = outcome === void 0 ? { kind: "timeout" } : outcome instanceof Error ? { kind: "exited", status: 1, stdout: "", stderr: outcome.message } : { kind: "exited", status: outcome.status, stdout: outcome.stdout, stderr: outcome.stderr };
1802
- return { territory: run.territory, end: readReviewerEnd(ran, input.minutes, deps.runtime.agents), answer: answers[index], seconds: run.seconds ?? (now().getTime() - run.began) / 1e3 };
2229
+ return { territory: run.territory, end: readReviewerEnd(ran, input.minutes, deps.runtime.agents), text: answers[index], seconds: run.seconds ?? (now().getTime() - run.began) / 1e3 };
1803
2230
  })
1804
2231
  };
1805
2232
  }
@@ -2434,7 +2861,7 @@ async function freeDiskFromItemDisks(state, readFree) {
2434
2861
  }
2435
2862
  async function freeDiskFromSavedStates(state, root, readFree) {
2436
2863
  const dir = savedStatesDir(root);
2437
- const records = readRecords(dir).filter((record2) => record2.complete);
2864
+ const records = readRecords(dir).filter((record2) => record2.complete && holdsHostDisk(record2));
2438
2865
  if (records.length === 0) return readFree();
2439
2866
  const log = logOf(state);
2440
2867
  const minimum = state.config.housekeeping?.minFreeDisk ?? 0;
@@ -2461,11 +2888,11 @@ async function freeDiskFromSavedStates(state, root, readFree) {
2461
2888
  return readFree();
2462
2889
  }
2463
2890
  function recordPendingUpdate(state, record2) {
2464
- const text = record2 === void 0 ? "none" : JSON.stringify(record2);
2465
- if (state.updateRecord === text) return;
2891
+ const text2 = record2 === void 0 ? "none" : JSON.stringify(record2);
2892
+ if (state.updateRecord === text2) return;
2466
2893
  try {
2467
2894
  writePendingUpdate(runnerDir(state.config.configPath), record2);
2468
- state.updateRecord = text;
2895
+ state.updateRecord = text2;
2469
2896
  reportRepeating(state, "the update-pending.json record", void 0);
2470
2897
  } catch (err) {
2471
2898
  const code = err.code;
@@ -3120,7 +3547,7 @@ var CLAIM_REFUSAL_CODES = new Set(
3120
3547
  "pull_request_from_fork pull_request_on_default_branch pull_request_ambiguous pull_request_repository_not_connected repository_not_reachable branch_claimed_elsewhere".split(" ")
3121
3548
  );
3122
3549
  async function tryClaimAndStart(state, item, queue) {
3123
- const { postJson: postJson2 } = await import('./work-cmd-NBYW3LBP.js');
3550
+ const { postJson: postJson2 } = await import('./work-cmd-VWXZLMF4.js');
3124
3551
  const log = logOf(state);
3125
3552
  const hostKey = await loadHostKey(state.config.configPath);
3126
3553
  const claim = await retrySend(
@@ -4751,7 +5178,7 @@ async function startRunner(configPath, deps, startup) {
4751
5178
  check: update.check ? () => update.check(configPath) : async () => {
4752
5179
  const held = runnerAgents(deps.agents).flatMap((agent) => heldAgentCredential(agent.descriptor.id) ?? []);
4753
5180
  const env = { ...process.env, ...Object.fromEntries(held.map((credential) => [credential.variable, credential.value])) };
4754
- return (await import('./check-LGB3BWZ7.js')).runRunnerCheck(configPath, { fetchImpl: deps.fetchImpl, env });
5181
+ return (await import('./check-TRV42MHY.js')).runRunnerCheck(configPath, { fetchImpl: deps.fetchImpl, env });
4755
5182
  },
4756
5183
  now: () => (deps.now ?? (() => /* @__PURE__ */ new Date()))().getTime(),
4757
5184
  log