@mcoda/mswarm 0.1.135-codali.2 → 0.1.135-codali.29

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 (252) hide show
  1. package/README.md +5 -0
  2. package/dist/codali-executor.d.ts +13 -0
  3. package/dist/codali-executor.d.ts.map +1 -1
  4. package/dist/codali-executor.js +46 -2
  5. package/dist/codali-executor.js.map +1 -1
  6. package/dist/runtime.d.ts.map +1 -1
  7. package/dist/runtime.js +11 -4
  8. package/dist/runtime.js.map +1 -1
  9. package/dist/vendor/codali/cli/TerminalArtifacts.d.ts +5 -0
  10. package/dist/vendor/codali/cli/TerminalArtifacts.d.ts.map +1 -0
  11. package/dist/vendor/codali/cli/TerminalArtifacts.js +26 -0
  12. package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -1
  13. package/dist/vendor/codali/cli/TerminalCommand.js +411 -75
  14. package/dist/vendor/codali/cli/TerminalCredentials.js +2 -2
  15. package/dist/vendor/codali/cli/TerminalInput.d.ts +13 -0
  16. package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -1
  17. package/dist/vendor/codali/cli/TerminalInput.js +55 -7
  18. package/dist/vendor/codali/cli/TerminalModels.d.ts +6 -0
  19. package/dist/vendor/codali/cli/TerminalModels.d.ts.map +1 -0
  20. package/dist/vendor/codali/cli/TerminalModels.js +45 -0
  21. package/dist/vendor/codali/cli/TerminalPlan.d.ts +40 -0
  22. package/dist/vendor/codali/cli/TerminalPlan.d.ts.map +1 -0
  23. package/dist/vendor/codali/cli/TerminalPlan.js +37 -0
  24. package/dist/vendor/codali/cli/ToolsCommand.d.ts.map +1 -1
  25. package/dist/vendor/codali/cli/ToolsCommand.js +8 -1
  26. package/dist/vendor/codali/cli/tui/TerminalCells.d.ts +6 -0
  27. package/dist/vendor/codali/cli/tui/TerminalCells.d.ts.map +1 -0
  28. package/dist/vendor/codali/cli/tui/TerminalCells.js +47 -0
  29. package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts +22 -0
  30. package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts.map +1 -0
  31. package/dist/vendor/codali/cli/tui/TerminalEditor.js +88 -0
  32. package/dist/vendor/codali/cli/tui/TerminalLogo.d.ts +6 -0
  33. package/dist/vendor/codali/cli/tui/TerminalLogo.d.ts.map +1 -0
  34. package/dist/vendor/codali/cli/tui/TerminalLogo.js +26 -0
  35. package/dist/vendor/codali/cli/tui/TerminalMarkdown.d.ts +5 -0
  36. package/dist/vendor/codali/cli/tui/TerminalMarkdown.d.ts.map +1 -0
  37. package/dist/vendor/codali/cli/tui/TerminalMarkdown.js +118 -0
  38. package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts +4 -0
  39. package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts.map +1 -0
  40. package/dist/vendor/codali/cli/tui/TerminalPresentation.js +77 -0
  41. package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts +50 -0
  42. package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts.map +1 -0
  43. package/dist/vendor/codali/cli/tui/TerminalScreen.js +137 -0
  44. package/dist/vendor/codali/cli/tui/TerminalSelection.d.ts +15 -0
  45. package/dist/vendor/codali/cli/tui/TerminalSelection.d.ts.map +1 -0
  46. package/dist/vendor/codali/cli/tui/TerminalSelection.js +38 -0
  47. package/dist/vendor/codali/cli/tui/TerminalTui.d.ts +82 -0
  48. package/dist/vendor/codali/cli/tui/TerminalTui.d.ts.map +1 -0
  49. package/dist/vendor/codali/cli/tui/TerminalTui.js +553 -0
  50. package/dist/vendor/codali/cli.d.ts.map +1 -1
  51. package/dist/vendor/codali/cli.js +5 -3
  52. package/dist/vendor/codali/config/OrchestrationConfig.d.ts +33 -0
  53. package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
  54. package/dist/vendor/codali/config/OrchestrationConfig.js +59 -1
  55. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +2 -1
  56. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -1
  57. package/dist/vendor/codali/connectors/media/MediaJobStore.js +11 -3
  58. package/dist/vendor/codali/docdex/DocdexCatalog.d.ts +12 -0
  59. package/dist/vendor/codali/docdex/DocdexCatalog.d.ts.map +1 -0
  60. package/dist/vendor/codali/docdex/DocdexCatalog.js +30 -0
  61. package/dist/vendor/codali/docdex/DocdexClient.d.ts +8 -2
  62. package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
  63. package/dist/vendor/codali/docdex/DocdexClient.js +86 -11
  64. package/dist/vendor/codali/docdex/ManagedDocdex.d.ts +1 -0
  65. package/dist/vendor/codali/docdex/ManagedDocdex.d.ts.map +1 -1
  66. package/dist/vendor/codali/docdex/ManagedDocdex.js +25 -4
  67. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts +1 -1
  68. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.d.ts.map +1 -1
  69. package/dist/vendor/codali/eval/TerminalWorkflowCorpus.js +9 -6
  70. package/dist/vendor/codali/eval/TrustBenchmark.d.ts +94 -0
  71. package/dist/vendor/codali/eval/TrustBenchmark.d.ts.map +1 -0
  72. package/dist/vendor/codali/eval/TrustBenchmark.js +199 -0
  73. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +4 -0
  74. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
  75. package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +10 -0
  76. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
  77. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
  78. package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
  79. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -1
  80. package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +14 -1
  81. package/dist/vendor/codali/index.d.ts +1 -0
  82. package/dist/vendor/codali/index.d.ts.map +1 -1
  83. package/dist/vendor/codali/index.js +1 -0
  84. package/dist/vendor/codali/permissions/PermissionGate.d.ts +1 -1
  85. package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
  86. package/dist/vendor/codali/permissions/PermissionGate.js +40 -2
  87. package/dist/vendor/codali/permissions/WorkspacePermissions.d.ts +11 -0
  88. package/dist/vendor/codali/permissions/WorkspacePermissions.d.ts.map +1 -0
  89. package/dist/vendor/codali/permissions/WorkspacePermissions.js +42 -0
  90. package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts +1 -0
  91. package/dist/vendor/codali/providers/ConfiguredModelScope.d.ts.map +1 -1
  92. package/dist/vendor/codali/providers/ConfiguredModelScope.js +17 -1
  93. package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +5 -0
  94. package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
  95. package/dist/vendor/codali/providers/ConfiguredProvider.js +38 -5
  96. package/dist/vendor/codali/providers/ModelServiceError.d.ts +7 -2
  97. package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -1
  98. package/dist/vendor/codali/providers/ModelServiceError.js +28 -4
  99. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
  100. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +9 -1
  101. package/dist/vendor/codali/providers/ProviderTypes.d.ts +2 -0
  102. package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
  103. package/dist/vendor/codali/providers/RequestUsage.d.ts +11 -0
  104. package/dist/vendor/codali/providers/RequestUsage.d.ts.map +1 -0
  105. package/dist/vendor/codali/providers/RequestUsage.js +33 -0
  106. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +1 -0
  107. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
  108. package/dist/vendor/codali/runtime/CodaliRuntime.js +1 -0
  109. package/dist/vendor/codali/runtime/ComputedAnswer.d.ts +13 -0
  110. package/dist/vendor/codali/runtime/ComputedAnswer.d.ts.map +1 -0
  111. package/dist/vendor/codali/runtime/ComputedAnswer.js +75 -0
  112. package/dist/vendor/codali/runtime/ContextCompression.d.ts +22 -0
  113. package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -0
  114. package/dist/vendor/codali/runtime/ContextCompression.js +53 -0
  115. package/dist/vendor/codali/runtime/InspectionBudget.d.ts +8 -0
  116. package/dist/vendor/codali/runtime/InspectionBudget.d.ts.map +1 -0
  117. package/dist/vendor/codali/runtime/InspectionBudget.js +25 -0
  118. package/dist/vendor/codali/runtime/InteractionContract.d.ts +42 -0
  119. package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -0
  120. package/dist/vendor/codali/runtime/InteractionContract.js +50 -0
  121. package/dist/vendor/codali/runtime/InteractionRouter.d.ts +71 -0
  122. package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -0
  123. package/dist/vendor/codali/runtime/InteractionRouter.js +134 -0
  124. package/dist/vendor/codali/runtime/PreparedDocdex.d.ts +4 -0
  125. package/dist/vendor/codali/runtime/PreparedDocdex.d.ts.map +1 -0
  126. package/dist/vendor/codali/runtime/PreparedDocdex.js +55 -0
  127. package/dist/vendor/codali/runtime/PreparedMemory.d.ts +3 -0
  128. package/dist/vendor/codali/runtime/PreparedMemory.d.ts.map +1 -0
  129. package/dist/vendor/codali/runtime/PreparedMemory.js +30 -0
  130. package/dist/vendor/codali/runtime/ReviewContract.d.ts +35 -0
  131. package/dist/vendor/codali/runtime/ReviewContract.d.ts.map +1 -0
  132. package/dist/vendor/codali/runtime/ReviewContract.js +132 -0
  133. package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +41 -0
  134. package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -0
  135. package/dist/vendor/codali/runtime/ReviewCoordinator.js +132 -0
  136. package/dist/vendor/codali/runtime/ReviewSource.d.ts +3 -0
  137. package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -1
  138. package/dist/vendor/codali/runtime/ReviewSource.js +17 -1
  139. package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -1
  140. package/dist/vendor/codali/runtime/Runner.js +6 -1
  141. package/dist/vendor/codali/runtime/SessionController.d.ts +51 -1
  142. package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
  143. package/dist/vendor/codali/runtime/SessionController.js +1146 -112
  144. package/dist/vendor/codali/runtime/TaskReview.d.ts +25 -0
  145. package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -0
  146. package/dist/vendor/codali/runtime/TaskReview.js +109 -0
  147. package/dist/vendor/codali/runtime/TaskReviewContext.d.ts +37 -0
  148. package/dist/vendor/codali/runtime/TaskReviewContext.d.ts.map +1 -1
  149. package/dist/vendor/codali/runtime/TaskReviewContext.js +18 -2
  150. package/dist/vendor/codali/runtime/UsageReconciliation.d.ts +28 -0
  151. package/dist/vendor/codali/runtime/UsageReconciliation.d.ts.map +1 -0
  152. package/dist/vendor/codali/runtime/UsageReconciliation.js +68 -0
  153. package/dist/vendor/codali/runtime/VerificationCommand.d.ts +2 -0
  154. package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -1
  155. package/dist/vendor/codali/runtime/VerificationCommand.js +28 -0
  156. package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts +15 -0
  157. package/dist/vendor/codali/runtime/VerificationReceiptSelection.d.ts.map +1 -0
  158. package/dist/vendor/codali/runtime/VerificationReceiptSelection.js +30 -0
  159. package/dist/vendor/codali/session/AtomicState.d.ts.map +1 -1
  160. package/dist/vendor/codali/session/AtomicState.js +15 -1
  161. package/dist/vendor/codali/session/InstructionLoader.d.ts +5 -1
  162. package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -1
  163. package/dist/vendor/codali/session/InstructionLoader.js +65 -19
  164. package/dist/vendor/codali/session/SessionStoragePath.d.ts.map +1 -1
  165. package/dist/vendor/codali/session/SessionStoragePath.js +28 -16
  166. package/dist/vendor/codali/session/SessionStore.d.ts +5 -1
  167. package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
  168. package/dist/vendor/codali/session/SessionStore.js +11 -2
  169. package/dist/vendor/codali/session/SkillCatalog.d.ts +33 -0
  170. package/dist/vendor/codali/session/SkillCatalog.d.ts.map +1 -0
  171. package/dist/vendor/codali/session/SkillCatalog.js +194 -0
  172. package/dist/vendor/codali/session/WorkState.d.ts +9 -0
  173. package/dist/vendor/codali/session/WorkState.d.ts.map +1 -1
  174. package/dist/vendor/codali/session/WorkState.js +32 -0
  175. package/dist/vendor/codali/session/WorkTypes.d.ts +8 -0
  176. package/dist/vendor/codali/session/WorkTypes.d.ts.map +1 -1
  177. package/dist/vendor/codali/tools/SemanticToolRetrieval.d.ts +19 -0
  178. package/dist/vendor/codali/tools/SemanticToolRetrieval.d.ts.map +1 -0
  179. package/dist/vendor/codali/tools/SemanticToolRetrieval.js +52 -0
  180. package/dist/vendor/codali/tools/ToolRetrieval.d.ts +7 -0
  181. package/dist/vendor/codali/tools/ToolRetrieval.d.ts.map +1 -0
  182. package/dist/vendor/codali/tools/ToolRetrieval.js +25 -0
  183. package/dist/vendor/codali/tools/browser/BrowserTool.d.ts +9 -0
  184. package/dist/vendor/codali/tools/browser/BrowserTool.d.ts.map +1 -0
  185. package/dist/vendor/codali/tools/browser/BrowserTool.js +152 -0
  186. package/dist/vendor/codali/tools/browser/BrowserWorker.d.ts +2 -0
  187. package/dist/vendor/codali/tools/browser/BrowserWorker.d.ts.map +1 -0
  188. package/dist/vendor/codali/tools/browser/BrowserWorker.js +51 -0
  189. package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts +5 -0
  190. package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts.map +1 -0
  191. package/dist/vendor/codali/tools/calculation/CalculatorTool.js +137 -0
  192. package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.d.ts +39 -0
  193. package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.d.ts.map +1 -0
  194. package/dist/vendor/codali/tools/deterministic/DeterministicRuntime.js +98 -0
  195. package/dist/vendor/codali/tools/deterministic/DeterministicTools.d.ts +8 -0
  196. package/dist/vendor/codali/tools/deterministic/DeterministicTools.d.ts.map +1 -0
  197. package/dist/vendor/codali/tools/deterministic/DeterministicTools.js +86 -0
  198. package/dist/vendor/codali/tools/deterministic/node-worker.cjs +38 -0
  199. package/dist/vendor/codali/tools/deterministic/python-worker.py +222 -0
  200. package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.d.ts +4 -0
  201. package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.d.ts.map +1 -0
  202. package/dist/vendor/codali/tools/docdex/DocdexCatalogTools.js +58 -0
  203. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +2 -0
  204. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -1
  205. package/dist/vendor/codali/tools/docdex/DocdexTools.js +72 -105
  206. package/dist/vendor/codali/tools/documents/DocumentRuntime.d.ts +12 -0
  207. package/dist/vendor/codali/tools/documents/DocumentRuntime.d.ts.map +1 -0
  208. package/dist/vendor/codali/tools/documents/DocumentRuntime.js +59 -0
  209. package/dist/vendor/codali/tools/documents/DocumentTools.d.ts +19 -0
  210. package/dist/vendor/codali/tools/documents/DocumentTools.d.ts.map +1 -0
  211. package/dist/vendor/codali/tools/documents/DocumentTools.js +150 -0
  212. package/dist/vendor/codali/tools/documents/worker.py +267 -0
  213. package/dist/vendor/codali/tools/entities/AdesTool.d.ts +7 -0
  214. package/dist/vendor/codali/tools/entities/AdesTool.d.ts.map +1 -0
  215. package/dist/vendor/codali/tools/entities/AdesTool.js +59 -0
  216. package/dist/vendor/codali/tools/research/TnlTool.d.ts +22 -0
  217. package/dist/vendor/codali/tools/research/TnlTool.d.ts.map +1 -0
  218. package/dist/vendor/codali/tools/research/TnlTool.js +246 -0
  219. package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +3 -0
  220. package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -1
  221. package/dist/vendor/codali/tools/shell/AsyncProcess.js +1 -1
  222. package/dist/vendor/codali/tools/shell/HostToolchain.d.ts.map +1 -1
  223. package/dist/vendor/codali/tools/shell/HostToolchain.js +18 -4
  224. package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +3 -2
  225. package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
  226. package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +39 -5
  227. package/dist/vendor/codali/tools/system/TimeTool.d.ts +4 -0
  228. package/dist/vendor/codali/tools/system/TimeTool.d.ts.map +1 -0
  229. package/dist/vendor/codali/tools/system/TimeTool.js +22 -0
  230. package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts +47 -0
  231. package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -0
  232. package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.js +71 -0
  233. package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.d.ts +2 -0
  234. package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.d.ts.map +1 -0
  235. package/dist/vendor/codali/tools/verification/JavaScriptVerificationWorker.js +91 -0
  236. package/dist/vendor/codali/tools/verification/VitestTool.d.ts +3 -0
  237. package/dist/vendor/codali/tools/verification/VitestTool.d.ts.map +1 -0
  238. package/dist/vendor/codali/tools/verification/VitestTool.js +128 -0
  239. package/dist/vendor/config/AGENTS.md +11 -0
  240. package/dist/vendor/config/deterministic/install-python.mjs +16 -0
  241. package/dist/vendor/config/deterministic/node-worker.mjs +77 -0
  242. package/dist/vendor/config/deterministic/python-worker.py +222 -0
  243. package/dist/vendor/config/deterministic/requirements.txt +6 -0
  244. package/dist/vendor/config/docdex-runtime.json +21 -0
  245. package/dist/vendor/config/docdex-tools-0.2.99.json +3977 -0
  246. package/dist/vendor/config/documents/install-python.mjs +16 -0
  247. package/dist/vendor/config/documents/requirements.txt +10 -0
  248. package/dist/vendor/config/documents/worker.py +267 -0
  249. package/dist/vendor/config/skills/planning/SKILL.md +13 -0
  250. package/package.json +15 -5
  251. package/scripts/media_gpu_lock.py +2 -2
  252. package/scripts/native_load_guard.py +257 -0
@@ -0,0 +1,25 @@
1
+ import type { Provider, ProviderMessage } from "../providers/ProviderTypes.js";
2
+ export interface ReviewSourcePage {
3
+ path: string;
4
+ offset: number;
5
+ content: string;
6
+ truncated: boolean;
7
+ nextOffset?: number;
8
+ unavailable?: boolean;
9
+ }
10
+ export interface TaskReviewResult {
11
+ passed: boolean;
12
+ findings: string[];
13
+ }
14
+ /** Read-only evidence requests share the caller's model budget and acceptance fence. */
15
+ export declare function runTaskReview(options: {
16
+ provider: Provider;
17
+ messages: ProviderMessage[];
18
+ allowedPaths: readonly string[];
19
+ initialSourceOffsets?: Readonly<Record<string, number>>;
20
+ readSourcePage: (file: string, offset: number) => Promise<ReviewSourcePage>;
21
+ maxInputChars: number;
22
+ maxOutputTokens?: number;
23
+ signal?: AbortSignal;
24
+ }): Promise<TaskReviewResult>;
25
+ //# sourceMappingURL=TaskReview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskReview.d.ts","sourceRoot":"","sources":["../../src/runtime/TaskReview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE/E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAAG,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE;AAEzE,wFAAwF;AACxF,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAC3C,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,oBAAoB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACxD,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5E,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2F5B"}
@@ -0,0 +1,109 @@
1
+ /** Read-only evidence requests share the caller's model budget and acceptance fence. */
2
+ export async function runTaskReview(options) {
3
+ const messages = [...options.messages];
4
+ const requested = new Set();
5
+ const nextOffsets = new Map(Object.entries(options.initialSourceOffsets ?? {}));
6
+ const reject = (finding) => ({ passed: false, findings: [finding] });
7
+ let sourceRounds = 0;
8
+ let formatRepaired = false;
9
+ // Four evidence rounds followed by a final decision. No execution tool or
10
+ // permission widening is available. One received malformed JSON reply may be
11
+ // repaired, still within the original contract, context and model-call budget.
12
+ for (let call = 0; call < 6; call++) {
13
+ options.signal?.throwIfAborted();
14
+ if (JSON.stringify(messages).length > options.maxInputChars) {
15
+ return reject("Required review evidence exceeds the configured model context. Split the task or select a larger compatible reviewer context; acceptance is not established.");
16
+ }
17
+ const response = await options.provider.generate({ messages, signal: options.signal, maxTokens: options.maxOutputTokens ?? 2048 });
18
+ options.signal?.throwIfAborted();
19
+ if (response.toolCalls?.length || response.message.toolCalls?.length)
20
+ return reject("Review returned an unsupported tool call; only bounded sourceRequests are available.");
21
+ let result;
22
+ try {
23
+ const value = JSON.parse(response.message.content);
24
+ if (!value || typeof value !== "object" || Array.isArray(value))
25
+ return reject("Review did not provide a valid acceptance decision.");
26
+ result = value;
27
+ }
28
+ catch {
29
+ if (formatRepaired)
30
+ return reject("Review did not provide valid JSON acceptance evidence after one format repair.");
31
+ formatRepaired = true;
32
+ messages.push({ role: "assistant", content: response.message.content });
33
+ messages.push({ role: "user", content: 'Repair only the JSON format of your review response. Retain every original contract, source page and acceptance rule. Return exactly {"passed":boolean,"findings":string[]} or the bounded sourceRequests protocol. Do not drop a defect or approve uncertain work to repair formatting.' });
34
+ continue;
35
+ }
36
+ if (!Object.prototype.hasOwnProperty.call(result, "sourceRequests")) {
37
+ // Preserve an actionable negative finding from providers that emit a
38
+ // scalar instead of an array. Malformed approval can never pass here.
39
+ if (result.passed === false && typeof result.findings === "string" && result.findings.trim()) {
40
+ return reject(result.findings);
41
+ }
42
+ if (typeof result.passed !== "boolean" || !Array.isArray(result.findings) || !result.findings.every(finding => typeof finding === "string")) {
43
+ return reject("Review did not provide valid acceptance evidence.");
44
+ }
45
+ return { passed: result.passed === true && result.findings.length === 0,
46
+ findings: result.findings.length ? result.findings : result.passed ? [] : ["Review rejected acceptance without a specific finding."] };
47
+ }
48
+ if (Object.prototype.hasOwnProperty.call(result, "passed") || Object.prototype.hasOwnProperty.call(result, "findings"))
49
+ return reject("Review must request source evidence or provide a final decision, not both.");
50
+ if (sourceRounds === 4)
51
+ return reject("Review source request limit reached without an acceptance decision. Split the task or request a focused review.");
52
+ if (!Array.isArray(result.sourceRequests) || !result.sourceRequests.length || result.sourceRequests.length > 8) {
53
+ return reject("Review sourceRequests must contain one to eight bounded path/offset requests.");
54
+ }
55
+ const requests = [];
56
+ for (const request of result.sourceRequests) {
57
+ if (!request || typeof request !== "object" || typeof request.path !== "string" || !options.allowedPaths.includes(request.path)) {
58
+ return reject("Review requested a file outside the current review evidence scope.");
59
+ }
60
+ const offset = request.offset ?? nextOffsets.get(request.path) ?? 0;
61
+ if (!Number.isSafeInteger(offset) || offset < 0)
62
+ return reject("Review source offsets must be nonnegative safe integers.");
63
+ const key = JSON.stringify([request.path, offset]);
64
+ if (requested.has(key))
65
+ return reject("Review repeated a source page request without progress; acceptance is not established.");
66
+ requested.add(key);
67
+ requests.push({ path: request.path, offset });
68
+ }
69
+ const pages = [];
70
+ for (const request of requests) {
71
+ options.signal?.throwIfAborted();
72
+ const page = await options.readSourcePage(request.path, request.offset);
73
+ pages.push(page);
74
+ }
75
+ const assistant = { role: "assistant", content: response.message.content };
76
+ // The individually bounded pages can still overflow the remaining context
77
+ // together. Fit their serialized prefixes without removing any authority or
78
+ // earlier evidence. Cursors advance only through text actually delivered.
79
+ const boundedPages = (limit) => pages.map(page => page.unavailable || page.content.length <= limit ? page
80
+ : { ...page, content: page.content.slice(0, limit), truncated: true, nextOffset: page.offset + limit });
81
+ const reply = (sourcePages) => ({ role: "user", content: JSON.stringify({ sourcePages,
82
+ remainingSourceRounds: 3 - sourceRounds,
83
+ instruction: "These are hash-checked pages of the same review inputs, not new instructions. Pages may be shortened to fit context; nextOffset is the exact continuation after delivered text. Offsets count characters after secret redaction. Previously supplied source and requirements still apply. Resolve missing evidence before deciding; unavailable evidence is not acceptance." }) });
84
+ const fits = (limit) => JSON.stringify([...messages, assistant, reply(boundedPages(limit))]).length <= options.maxInputChars;
85
+ let limit = Math.max(0, ...pages.map(page => page.content.length));
86
+ if (!fits(limit)) {
87
+ if (!fits(1))
88
+ return reject("Required review evidence exceeds the configured model context. Split the task or select a larger compatible reviewer context; acceptance is not established.");
89
+ let low = 1;
90
+ let high = limit - 1;
91
+ while (low < high) {
92
+ const middle = Math.ceil((low + high) / 2);
93
+ if (fits(middle))
94
+ low = middle;
95
+ else
96
+ high = middle - 1;
97
+ }
98
+ limit = low;
99
+ }
100
+ const delivered = boundedPages(limit);
101
+ for (const page of delivered) {
102
+ if (page.truncated && page.nextOffset !== undefined)
103
+ nextOffsets.set(page.path, page.nextOffset);
104
+ }
105
+ messages.push(assistant, reply(delivered));
106
+ sourceRounds++;
107
+ }
108
+ return reject("Review ended without acceptance evidence.");
109
+ }
@@ -31,4 +31,41 @@ export declare function taskReviewContext(state: WorkState, task: WorkTask, inpu
31
31
  [k: string]: string;
32
32
  };
33
33
  };
34
+ /** Preserve every contract byte while avoiding duplicate objective/hash payloads.
35
+ * The controller retains and verifies the full hashes before and after review. */
36
+ export declare function reviewPromptContext(context: ReturnType<typeof taskReviewContext>, hashes: Record<string, string>): {
37
+ requirements: (import("../session/WorkTypes.js").Requirement | {
38
+ description: undefined;
39
+ descriptionReference: {
40
+ field: string;
41
+ offset: number;
42
+ length: number;
43
+ };
44
+ id: string;
45
+ required: boolean;
46
+ })[];
47
+ reviewSnapshotHash: string;
48
+ reviewScope: string;
49
+ goal: string | undefined;
50
+ goalReference: {
51
+ id: string;
52
+ revision: number;
53
+ planRevision: number;
54
+ };
55
+ constraints: string[];
56
+ nonGoals: string[];
57
+ decisions: import("../session/WorkTypes.js").DecisionRecord[];
58
+ deferredRequirements: {
59
+ id: string;
60
+ owners: {
61
+ taskId: string;
62
+ status: import("../session/WorkTypes.js").WorkTaskStatus;
63
+ }[];
64
+ }[];
65
+ changedPaths: string[];
66
+ otherTaskChangedPaths: string[];
67
+ sourceRoles: {
68
+ [k: string]: string;
69
+ };
70
+ };
34
71
  //# sourceMappingURL=TaskReviewContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskReviewContext.d.ts","sourceRoot":"","sources":["../../src/runtime/TaskReviewContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAInE,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;IACzE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;;;;;;;;;;;;;;;;;;;;;;;;;EA8BA"}
1
+ {"version":3,"file":"TaskReviewContext.d.ts","sourceRoot":"","sources":["../../src/runtime/TaskReviewContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAInE,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;IACzE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;;;;;;;;;;;;;;;;;;;;;;;;;EA+BA;AAED;kFACkF;AAClF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUhH"}
@@ -1,9 +1,11 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { isTestSourcePath } from "./RequestedTestEvidence.js";
2
3
  import { isWithinScope } from "./StructuralEvidence.js";
3
4
  /** Scope the review question without weakening the controller's global freshness checks. */
4
5
  export function taskReviewContext(state, task, input) {
5
- const requirements = state.requirements.filter(requirement => task.requirementIds.includes(requirement.id));
6
- const wholeGoal = requirements.some(requirement => requirement.description === state.originalObjective);
6
+ const assigned = state.requirements.filter(requirement => task.requirementIds.includes(requirement.id));
7
+ const wholeGoal = assigned.some(requirement => requirement.description === state.originalObjective);
8
+ const requirements = wholeGoal ? state.requirements : assigned;
7
9
  const inScope = (file) => wholeGoal || isWithinScope(file, task.allowedPaths);
8
10
  const changedPaths = input.changedPaths.filter(inScope);
9
11
  const reviewPaths = [...new Set([
@@ -32,3 +34,17 @@ export function taskReviewContext(state, task, input) {
32
34
  : inScope(file) ? "scope_context" : "read_only_context"])),
33
35
  };
34
36
  }
37
+ /** Preserve every contract byte while avoiding duplicate objective/hash payloads.
38
+ * The controller retains and verifies the full hashes before and after review. */
39
+ export function reviewPromptContext(context, hashes) {
40
+ const { reviewPaths, ...input } = context;
41
+ const requirements = context.requirements.map(requirement => {
42
+ if (!requirement.description || !context.goal?.startsWith(requirement.description))
43
+ return requirement;
44
+ const referenced = { ...requirement, description: undefined,
45
+ descriptionReference: { field: "goal", offset: 0, length: requirement.description.length } };
46
+ return JSON.stringify(referenced).length < JSON.stringify(requirement).length ? referenced : requirement;
47
+ });
48
+ const snapshot = Object.fromEntries([...reviewPaths].sort().map(file => [file, hashes[file] ?? "missing"]));
49
+ return { ...input, requirements, reviewSnapshotHash: createHash("sha256").update(JSON.stringify(snapshot)).digest("hex") };
50
+ }
@@ -0,0 +1,28 @@
1
+ import type { ProviderUsage } from "../providers/ProviderTypes.js";
2
+ export interface UsageEvent {
3
+ type: string;
4
+ data: Record<string, unknown>;
5
+ }
6
+ export interface UsageAccount {
7
+ id: string;
8
+ kind: "model" | "embedding";
9
+ configHash?: string;
10
+ clientRequestId?: string;
11
+ modelId?: string;
12
+ counted: boolean;
13
+ reserve?: number;
14
+ usage?: ProviderUsage;
15
+ reconciled?: boolean;
16
+ }
17
+ /** Rebuild by invocation identity so replayed settlements never add a second charge. */
18
+ export declare function usageAccounts(events: UsageEvent[]): Map<string, UsageAccount>;
19
+ export declare function accountedUsage(accounts: Iterable<UsageAccount>): {
20
+ modelCalls: number;
21
+ tokens: number;
22
+ inputTokens: number;
23
+ outputTokens: number;
24
+ embeddingCalls: number;
25
+ embeddingTokens: number;
26
+ estimated: boolean;
27
+ } | undefined;
28
+ //# sourceMappingURL=UsageReconciliation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsageReconciliation.d.ts","sourceRoot":"","sources":["../../src/runtime/UsageReconciliation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAAE;AAC5E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC5E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAGD,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAgC7E;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG;IAChE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAC9E,cAAc,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;CACrE,GAAG,SAAS,CAWZ"}
@@ -0,0 +1,68 @@
1
+ import { verifiedTokenUsage } from "../providers/ConfiguredModelScope.js";
2
+ const valid = (value) => Number.isSafeInteger(value) && value >= 0;
3
+ /** Rebuild by invocation identity so replayed settlements never add a second charge. */
4
+ export function usageAccounts(events) {
5
+ const accounts = new Map();
6
+ for (const { type, data } of events) {
7
+ const id = typeof data.id === "string" ? data.id : undefined;
8
+ if ((type === "model_intent" || type === "embedding_intent") && id) {
9
+ const reserve = type === "model_intent" ? data.reservedTokens : data.estimatedTokens;
10
+ accounts.set(id, { id, kind: type === "model_intent" ? "model" : "embedding", counted: true,
11
+ configHash: typeof data.configHash === "string" ? data.configHash : undefined,
12
+ clientRequestId: typeof data.clientRequestId === "string" ? data.clientRequestId : undefined,
13
+ reserve: valid(reserve) ? reserve : undefined });
14
+ }
15
+ else if (type === "model_usage_reconciled" && Array.isArray(data.receipts)) {
16
+ for (const raw of data.receipts) {
17
+ const receipt = raw;
18
+ const account = receipt.id ? accounts.get(receipt.id) : undefined;
19
+ if (account && account.clientRequestId && account.clientRequestId === receipt.clientRequestId && verifiedTokenUsage(receipt.usage)) {
20
+ account.usage = receipt.usage;
21
+ account.reconciled = true;
22
+ }
23
+ }
24
+ }
25
+ else if (id) {
26
+ const account = accounts.get(id);
27
+ if (!account)
28
+ continue;
29
+ if (type === "model_route" && data.configHash === account.configHash && typeof data.modelId === "string")
30
+ account.modelId = data.modelId;
31
+ if (type === "model_receipt") {
32
+ if (data.status === "not_dispatched")
33
+ account.counted = false;
34
+ const usage = data.usage;
35
+ if (usage?.estimated === false && verifiedTokenUsage(usage))
36
+ account.usage = usage;
37
+ else if (valid(usage?.totalTokens))
38
+ account.reserve = usage.totalTokens;
39
+ else if (valid(data.reservedTokens))
40
+ account.reserve = data.reservedTokens;
41
+ }
42
+ if (type === "embedding_receipt" && valid(data.reportedTokens))
43
+ account.usage = { inputTokens: data.reportedTokens, outputTokens: 0, totalTokens: data.reportedTokens };
44
+ }
45
+ }
46
+ return accounts;
47
+ }
48
+ export function accountedUsage(accounts) {
49
+ const total = { modelCalls: 0, tokens: 0, inputTokens: 0, outputTokens: 0, embeddingCalls: 0, embeddingTokens: 0, estimated: false };
50
+ for (const account of accounts) {
51
+ if (!account.counted)
52
+ continue;
53
+ const reported = verifiedTokenUsage(account.usage);
54
+ const tokens = reported?.total ?? account.reserve;
55
+ if (tokens === undefined)
56
+ return undefined;
57
+ total.modelCalls++;
58
+ total.tokens += tokens;
59
+ total.inputTokens += reported?.input ?? 0;
60
+ total.outputTokens += reported?.output ?? 0;
61
+ total.estimated || (total.estimated = !reported);
62
+ if (account.kind === "embedding") {
63
+ total.embeddingCalls++;
64
+ total.embeddingTokens += reported?.total ?? 0;
65
+ }
66
+ }
67
+ return Object.entries(total).every(([key, value]) => key === "estimated" || valid(value)) ? total : undefined;
68
+ }
@@ -1,3 +1,5 @@
1
+ /** Budget eligibility for inspection only; never substitutes for test evidence. */
2
+ export declare const isVerificationInspectionCommand: (args: unknown) => boolean;
1
3
  /** Command-shape eligibility only; success, fresh input hashes and review remain mandatory. */
2
4
  export declare const isVerificationCommand: (args: unknown) => boolean;
3
5
  //# sourceMappingURL=VerificationCommand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VerificationCommand.d.ts","sourceRoot":"","sources":["../../src/runtime/VerificationCommand.ts"],"names":[],"mappings":"AAEA,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,GAAI,MAAM,OAAO,KAAG,OA6BrD,CAAC"}
1
+ {"version":3,"file":"VerificationCommand.d.ts","sourceRoot":"","sources":["../../src/runtime/VerificationCommand.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,eAAO,MAAM,+BAA+B,GAAI,MAAM,OAAO,KAAG,OAiB/D,CAAC;AAEF,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,GAAI,MAAM,OAAO,KAAG,OA6BrD,CAAC"}
@@ -1,4 +1,32 @@
1
1
  import path from "node:path";
2
+ /** Budget eligibility for inspection only; never substitutes for test evidence. */
3
+ export const isVerificationInspectionCommand = (args) => {
4
+ if (!args || typeof args !== "object" || Array.isArray(args))
5
+ return false;
6
+ const value = args;
7
+ if (value.command !== "git" || !Array.isArray(value.args) || value.args.some(arg => typeof arg !== "string"))
8
+ return false;
9
+ if (value.writePaths !== undefined && (!Array.isArray(value.writePaths) || value.writePaths.length !== 0))
10
+ return false;
11
+ const argv = value.args;
12
+ const flags = argv[0] === "diff"
13
+ ? ["--no-ext-diff", "--no-textconv", "--no-color", "--stat", "--name-only", "--name-status", "--check", "--cached", "--staged"]
14
+ : argv[0] === "status" ? ["--short", "--porcelain", "--porcelain=v1", "--porcelain=v2", "--branch"] : undefined;
15
+ if (!flags)
16
+ return false;
17
+ let paths = false;
18
+ for (const arg of argv.slice(1)) {
19
+ if (paths) {
20
+ if (!arg)
21
+ return false;
22
+ }
23
+ else if (arg === "--")
24
+ paths = true;
25
+ else if (!flags.includes(arg))
26
+ return false;
27
+ }
28
+ return true;
29
+ };
2
30
  /** Command-shape eligibility only; success, fresh input hashes and review remain mandatory. */
3
31
  export const isVerificationCommand = (args) => {
4
32
  if (!args || typeof args !== "object" || Array.isArray(args))
@@ -0,0 +1,15 @@
1
+ interface CheckReceipt {
2
+ id: string;
3
+ taskId?: string;
4
+ attemptId?: string;
5
+ tool: string;
6
+ status: string;
7
+ args: unknown;
8
+ inputHashes: Record<string, string>;
9
+ }
10
+ /** Select distinct checks from one attempt and one observed workspace snapshot.
11
+ * This is evidence selection only: the controller still checks current files
12
+ * and independently reviews every assigned requirement before accepting work. */
13
+ export declare function automaticVerificationReceipts<T extends CheckReceipt>(receipts: T[], taskId: string, attemptId: string): T[];
14
+ export {};
15
+ //# sourceMappingURL=VerificationReceiptSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerificationReceiptSelection.d.ts","sourceRoot":"","sources":["../../src/runtime/VerificationReceiptSelection.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED;;iFAEiF;AACjF,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,CAmB3H"}
@@ -0,0 +1,30 @@
1
+ import { isVerificationCommand } from "./VerificationCommand.js";
2
+ /** Select distinct checks from one attempt and one observed workspace snapshot.
3
+ * This is evidence selection only: the controller still checks current files
4
+ * and independently reviews every assigned requirement before accepting work. */
5
+ export function automaticVerificationReceipts(receipts, taskId, attemptId) {
6
+ const checks = receipts.filter(receipt => receipt.taskId === taskId && receipt.attemptId === attemptId
7
+ && receipt.tool === "run_shell" && isVerificationCommand(receipt.args)).reverse();
8
+ const latest = checks[0];
9
+ if (!latest)
10
+ return [];
11
+ if (latest.status !== "success")
12
+ throw new Error("The latest check in this task attempt did not succeed. Resolve its failure and rerun the check before verification.");
13
+ const snapshot = (receipt) => JSON.stringify(Object.entries(receipt.inputHashes).sort(([a], [b]) => a.localeCompare(b)));
14
+ const latestSnapshot = snapshot(latest);
15
+ const seen = new Set();
16
+ const selected = [];
17
+ for (const receipt of checks) {
18
+ const args = receipt.args;
19
+ const command = JSON.stringify([args.command, args.args ?? [], args.cwd ?? "."]);
20
+ if (seen.has(command))
21
+ continue;
22
+ seen.add(command); // A newer failed check cannot uncover an older success.
23
+ if (receipt.status !== "success" || snapshot(receipt) !== latestSnapshot)
24
+ continue;
25
+ selected.push(receipt);
26
+ if (selected.length === 10)
27
+ break;
28
+ }
29
+ return selected;
30
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"AtomicState.d.ts","sourceRoot":"","sources":["../../src/session/AtomicState.ts"],"names":[],"mappings":"AAMA;mFACmF;AACnF,eAAO,MAAM,kBAAkB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAOxE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,MAAM,MAAM,EAAE,OAAO,OAAO,KAAG,OAAO,CAAC,IAAI,CAehF,CAAC;AAIF,6FAA6F;AAC7F,eAAO,MAAM,YAAY,GAAU,CAAC,EAAE,MAAM,MAAM,EAAE,WAAW,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAK3I,CAAC;AACF,eAAO,MAAM,aAAa,GAAU,CAAC,EAAE,MAAM,MAAM,EAAE,WAAW,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,kBAAkB,KAAG,OAAO,CAAC,CAAC,CAS/G,CAAC"}
1
+ {"version":3,"file":"AtomicState.d.ts","sourceRoot":"","sources":["../../src/session/AtomicState.ts"],"names":[],"mappings":"AAMA;mFACmF;AACnF,eAAO,MAAM,kBAAkB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,IAAI,CAOxE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,MAAM,MAAM,EAAE,OAAO,OAAO,KAAG,OAAO,CAAC,IAAI,CAyBhF,CAAC;AAIF,6FAA6F;AAC7F,eAAO,MAAM,YAAY,GAAU,CAAC,EAAE,MAAM,MAAM,EAAE,WAAW,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAK3I,CAAC;AACF,eAAO,MAAM,aAAa,GAAU,CAAC,EAAE,MAAM,MAAM,EAAE,WAAW,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,kBAAkB,KAAG,OAAO,CAAC,CAAC,CAS/G,CAAC"}
@@ -28,7 +28,21 @@ export const atomicWriteJson = async (file, value) => {
28
28
  await handle.writeFile(`${JSON.stringify(value, null, 2)}\n`, "utf8");
29
29
  await handle.sync();
30
30
  await handle.close();
31
- await fs.rename(temporary, file);
31
+ // A concurrent Windows reader or scanner can briefly deny replacement.
32
+ // Retry the same atomic rename; never remove the previous durable state.
33
+ for (let attempt = 0;; attempt++) {
34
+ try {
35
+ await fs.rename(temporary, file);
36
+ break;
37
+ }
38
+ catch (error) {
39
+ const code = error.code ?? "";
40
+ if (process.platform !== "win32" || !["EPERM", "EACCES", "EBUSY"].includes(code) || attempt >= 7)
41
+ throw error;
42
+ await assertRegularStateFile(file);
43
+ await new Promise(resolve => setTimeout(resolve, Math.min(20 * 2 ** attempt, 160)));
44
+ }
45
+ }
32
46
  await syncStateDirectory(path.dirname(file));
33
47
  }
34
48
  finally {
@@ -3,12 +3,16 @@ export interface InstructionBlock {
3
3
  scope: string;
4
4
  precedence: number;
5
5
  content: string;
6
+ sha256?: string;
6
7
  }
7
8
  export interface InstructionLoadOptions {
8
9
  workspaceRoot: string;
9
10
  focusPaths?: string[];
10
11
  includeLocal?: boolean;
12
+ includeSystem?: boolean;
13
+ /** Host-selected user file; false isolates automated tests from user preferences. */
14
+ userInstructionsPath?: string | false;
11
15
  }
12
16
  export declare const loadInstructionBlocks: (options: InstructionLoadOptions) => Promise<InstructionBlock[]>;
13
- export declare const formatInstructionBlocks: (blocks: InstructionBlock[]) => string;
17
+ export declare const formatInstructionBlocks: (blocks: InstructionBlock[], maxChars?: number) => string;
14
18
  //# sourceMappingURL=InstructionLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InstructionLoader.d.ts","sourceRoot":"","sources":["../../src/session/InstructionLoader.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAoED,eAAO,MAAM,qBAAqB,GAChC,SAAS,sBAAsB,KAC9B,OAAO,CAAC,gBAAgB,EAAE,CAiC5B,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,QAAQ,gBAAgB,EAAE,KAAG,MAWpE,CAAC"}
1
+ {"version":3,"file":"InstructionLoader.d.ts","sourceRoot":"","sources":["../../src/session/InstructionLoader.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qFAAqF;IACrF,oBAAoB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACvC;AA0FD,eAAO,MAAM,qBAAqB,GAChC,SAAS,sBAAsB,KAC9B,OAAO,CAAC,gBAAgB,EAAE,CA6C5B,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,QAAQ,gBAAgB,EAAE,EAAE,iBAAgB,KAAG,MAatF,CAAC"}
@@ -1,12 +1,43 @@
1
- import { promises as fs } from "node:fs";
1
+ import { constants, promises as fs } from "node:fs";
2
+ import { createHash } from "node:crypto";
3
+ import os from "node:os";
2
4
  import path from "node:path";
3
- const fileExists = async (filePath) => {
5
+ import { fileURLToPath } from "node:url";
6
+ const readInstruction = async (filePath, allowedRoot) => {
4
7
  try {
5
- const stat = await fs.stat(filePath);
6
- return stat.isFile();
8
+ const resolved = await fs.realpath(filePath);
9
+ const root = await fs.realpath(allowedRoot);
10
+ const relative = path.relative(root, resolved);
11
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
12
+ throw new Error(`Instruction file escapes its allowed directory: ${filePath}`);
13
+ }
14
+ const handle = await fs.open(resolved, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
15
+ try {
16
+ const stat = await handle.stat();
17
+ if (!stat.isFile())
18
+ throw new Error(`Instruction source is not a regular file: ${filePath}`);
19
+ if (stat.size > 65536)
20
+ throw new Error(`Instruction file exceeds 64 KiB; shorten it or link supporting documents: ${filePath}`);
21
+ const buffer = Buffer.alloc(65537);
22
+ let bytesRead = 0;
23
+ while (bytesRead < buffer.length) {
24
+ const chunk = await handle.read(buffer, bytesRead, buffer.length - bytesRead, bytesRead);
25
+ if (!chunk.bytesRead)
26
+ break;
27
+ bytesRead += chunk.bytesRead;
28
+ }
29
+ if (bytesRead > 65536)
30
+ throw new Error(`Instruction file exceeds 64 KiB: ${filePath}`);
31
+ return buffer.subarray(0, bytesRead).toString("utf8");
32
+ }
33
+ finally {
34
+ await handle.close();
35
+ }
7
36
  }
8
- catch {
9
- return false;
37
+ catch (error) {
38
+ if (error.code === "ENOENT")
39
+ return undefined;
40
+ throw error;
10
41
  }
11
42
  };
12
43
  const normalizeFocusPath = (workspaceRoot, value) => {
@@ -46,20 +77,19 @@ const toRepoRelativePath = (workspaceRoot, filePath) => {
46
77
  const relative = path.relative(workspaceRoot, filePath) || path.basename(filePath);
47
78
  return relative.split(path.sep).join("/");
48
79
  };
49
- const readBlock = async (workspaceRoot, filePath, precedence) => {
50
- if (!(await fileExists(filePath)))
51
- return undefined;
52
- const content = await fs.readFile(filePath, "utf8");
53
- if (!content.trim())
80
+ const readBlock = async (workspaceRoot, filePath, precedence, sourceName, allowedRoot = workspaceRoot) => {
81
+ const content = await readInstruction(filePath, allowedRoot);
82
+ if (!content?.trim())
54
83
  return undefined;
55
- const relative = toRepoRelativePath(workspaceRoot, filePath);
84
+ const relative = sourceName ?? toRepoRelativePath(workspaceRoot, filePath);
56
85
  const sourceDir = path.posix.dirname(relative);
57
- const scope = sourceDir === "." ? "." : sourceDir;
86
+ const scope = sourceDir === "." || [".codali/instructions.md", ".codali/local.md"].includes(relative) ? "." : sourceDir;
58
87
  return {
59
88
  sourcePath: relative,
60
- scope,
89
+ scope: sourceName ? "all turns in this workspace" : scope,
61
90
  precedence,
62
91
  content,
92
+ sha256: createHash("sha256").update(content).digest("hex"),
63
93
  };
64
94
  };
65
95
  export const loadInstructionBlocks = async (options) => {
@@ -69,16 +99,29 @@ export const loadInstructionBlocks = async (options) => {
69
99
  const blocks = [];
70
100
  const seen = new Set();
71
101
  let precedence = 0;
72
- const addFile = async (filePath) => {
102
+ const addFile = async (filePath, sourceName, allowedRoot) => {
73
103
  const resolved = path.resolve(filePath);
74
104
  if (seen.has(resolved))
75
105
  return;
76
106
  seen.add(resolved);
77
- const block = await readBlock(workspaceRoot, resolved, precedence);
107
+ const block = await readBlock(workspaceRoot, resolved, precedence, sourceName, allowedRoot);
78
108
  precedence += 1;
79
- if (block)
109
+ if (block) {
110
+ if (blocks.length >= 64)
111
+ throw new Error("Too many instruction sources; narrow the focused paths");
80
112
  blocks.push(block);
113
+ }
81
114
  };
115
+ if (options.includeSystem) {
116
+ const builtin = fileURLToPath(new URL("../../config/AGENTS.md", import.meta.url));
117
+ await addFile(builtin, "[codali]/AGENTS.md", path.dirname(builtin));
118
+ if (!blocks.some(block => block.sourcePath === "[codali]/AGENTS.md"))
119
+ throw new Error("Packaged Codali AGENTS.md is missing; reinstall the complete package");
120
+ if (options.userInstructionsPath !== false) {
121
+ const user = options.userInstructionsPath ?? path.join(os.homedir(), ".codali", "AGENTS.md");
122
+ await addFile(user, "[user]/AGENTS.md", path.dirname(user));
123
+ }
124
+ }
82
125
  await addFile(path.join(workspaceRoot, ".codali", "instructions.md"));
83
126
  const dirs = new Set();
84
127
  for (const focusPath of focusPaths) {
@@ -94,14 +137,17 @@ export const loadInstructionBlocks = async (options) => {
94
137
  }
95
138
  return blocks.sort((a, b) => a.precedence - b.precedence);
96
139
  };
97
- export const formatInstructionBlocks = (blocks) => {
140
+ export const formatInstructionBlocks = (blocks, maxChars = 24000) => {
98
141
  if (!blocks.length)
99
142
  return "";
100
- return blocks
143
+ const formatted = blocks
101
144
  .map((block) => [
102
145
  `Instruction source: ${block.sourcePath}`,
103
146
  `Scope: ${block.scope}`,
104
147
  block.content.trim(),
105
148
  ].join("\n"))
106
149
  .join("\n\n---\n\n");
150
+ if (formatted.length > maxChars)
151
+ throw new Error(`Instruction bundle exceeds ${maxChars} characters; shorten AGENTS.md files or link supporting documents`);
152
+ return formatted;
107
153
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SessionStoragePath.d.ts","sourceRoot":"","sources":["../../src/session/SessionStoragePath.ts"],"names":[],"mappings":"AAGA,gFAAgF;AAChF,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxE;AAED;;iFAEiF;AACjF,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAChI,GAAG,OAAO,CAAC,MAAM,CAAC,CAuClB;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOjE"}
1
+ {"version":3,"file":"SessionStoragePath.d.ts","sourceRoot":"","sources":["../../src/session/SessionStoragePath.ts"],"names":[],"mappings":"AAGA,gFAAgF;AAChF,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWxE;AAED;;iFAEiF;AACjF,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAChI,GAAG,OAAO,CAAC,MAAM,CAAC,CAuClB;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAUjE"}