nexakit 0.10.0 → 0.13.0

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 (479) hide show
  1. package/README.md +13 -6
  2. package/assets/runtime/package-lock.json +415 -6
  3. package/bench/casos/arquitectura/alta-usuarios/base/controladores/usuarios.js +16 -0
  4. package/bench/casos/arquitectura/alta-usuarios/base/db.js +14 -0
  5. package/bench/casos/arquitectura/alta-usuarios/base/docs/adr/0003-capas.md +15 -0
  6. package/bench/casos/arquitectura/alta-usuarios/base/errores.js +3 -0
  7. package/bench/casos/arquitectura/alta-usuarios/base/repositorios/usuarios.js +14 -0
  8. package/bench/casos/arquitectura/alta-usuarios/base/servicios/usuarios.js +20 -0
  9. package/bench/casos/arquitectura/alta-usuarios/cambio/controladores/usuarios.js +47 -0
  10. package/bench/casos/arquitectura/alta-usuarios/cambio/repositorios/usuarios.js +21 -0
  11. package/bench/casos/arquitectura/alta-usuarios/cambio/servicios/perfil.js +14 -0
  12. package/bench/casos/arquitectura/alta-usuarios/esperado.json +53 -0
  13. package/bench/casos/arquitectura/pedidos-facturacion/base/docs/adr/0001-capas.md +18 -0
  14. package/bench/casos/arquitectura/pedidos-facturacion/base/src/aplicacion/confirmar.ts +8 -0
  15. package/bench/casos/arquitectura/pedidos-facturacion/base/src/dominio/pedido.ts +15 -0
  16. package/bench/casos/arquitectura/pedidos-facturacion/base/src/dominio/puertos.ts +6 -0
  17. package/bench/casos/arquitectura/pedidos-facturacion/base/src/infra/db.ts +14 -0
  18. package/bench/casos/arquitectura/pedidos-facturacion/base/src/main.ts +9 -0
  19. package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/aplicacion/facturar.ts +19 -0
  20. package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/dominio/informe.ts +7 -0
  21. package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/dominio/pedido.ts +21 -0
  22. package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/infra/db.ts +22 -0
  23. package/bench/casos/arquitectura/pedidos-facturacion/esperado.json +53 -0
  24. package/bench/casos/arquitectura/resumen-cliente/base/docs/adr/0001-capas.md +18 -0
  25. package/bench/casos/arquitectura/resumen-cliente/base/src/aplicacion/confirmar.ts +8 -0
  26. package/bench/casos/arquitectura/resumen-cliente/base/src/dominio/pedido.ts +15 -0
  27. package/bench/casos/arquitectura/resumen-cliente/base/src/dominio/puertos.ts +6 -0
  28. package/bench/casos/arquitectura/resumen-cliente/base/src/infra/db.ts +14 -0
  29. package/bench/casos/arquitectura/resumen-cliente/base/src/main.ts +9 -0
  30. package/bench/casos/arquitectura/resumen-cliente/cambio/src/aplicacion/resumen.ts +6 -0
  31. package/bench/casos/arquitectura/resumen-cliente/cambio/src/dominio/pedido.ts +33 -0
  32. package/bench/casos/arquitectura/resumen-cliente/cambio/src/dominio/puertos.ts +7 -0
  33. package/bench/casos/arquitectura/resumen-cliente/cambio/src/infra/db.ts +18 -0
  34. package/bench/casos/arquitectura/resumen-cliente/cambio/src/main.ts +14 -0
  35. package/bench/casos/arquitectura/resumen-cliente/esperado.json +23 -0
  36. package/bench/casos/documentacion/comentario-obsoleto/base/README.md +18 -0
  37. package/bench/casos/documentacion/comentario-obsoleto/base/src/usuarios.ts +35 -0
  38. package/bench/casos/documentacion/comentario-obsoleto/cambio/src/copia.ts +8 -0
  39. package/bench/casos/documentacion/comentario-obsoleto/cambio/src/usuarios.ts +43 -0
  40. package/bench/casos/documentacion/comentario-obsoleto/esperado.json +42 -0
  41. package/bench/casos/documentacion/reportes-config/base/README.md +23 -0
  42. package/bench/casos/documentacion/reportes-config/base/src/cli.js +33 -0
  43. package/bench/casos/documentacion/reportes-config/base/src/config.js +15 -0
  44. package/bench/casos/documentacion/reportes-config/base/src/envio.js +23 -0
  45. package/bench/casos/documentacion/reportes-config/cambio/src/cli.js +35 -0
  46. package/bench/casos/documentacion/reportes-config/cambio/src/config.js +15 -0
  47. package/bench/casos/documentacion/reportes-config/esperado.json +42 -0
  48. package/bench/casos/documentacion/tiempo-espera/base/README.md +10 -0
  49. package/bench/casos/documentacion/tiempo-espera/base/src/config.js +8 -0
  50. package/bench/casos/documentacion/tiempo-espera/cambio/README.md +10 -0
  51. package/bench/casos/documentacion/tiempo-espera/cambio/src/config.js +8 -0
  52. package/bench/casos/documentacion/tiempo-espera/esperado.json +16 -0
  53. package/bench/casos/pruebas/calendario-laboral/base/src/fechas.js +3 -0
  54. package/bench/casos/pruebas/calendario-laboral/base/test/fechas.test.js +7 -0
  55. package/bench/casos/pruebas/calendario-laboral/cambio/src/fechas.js +37 -0
  56. package/bench/casos/pruebas/calendario-laboral/cambio/test/calendario.test.js +31 -0
  57. package/bench/casos/pruebas/calendario-laboral/esperado.json +49 -0
  58. package/bench/casos/pruebas/fin-de-semana/base/src/fechas.js +3 -0
  59. package/bench/casos/pruebas/fin-de-semana/base/test/fechas.test.js +7 -0
  60. package/bench/casos/pruebas/fin-de-semana/cambio/src/fechas.js +8 -0
  61. package/bench/casos/pruebas/fin-de-semana/cambio/test/fines-de-semana.test.js +13 -0
  62. package/bench/casos/pruebas/fin-de-semana/esperado.json +16 -0
  63. package/bench/casos/pruebas/precios-carrito/base/src/precio.ts +3 -0
  64. package/bench/casos/pruebas/precios-carrito/base/test/precio.test.js +11 -0
  65. package/bench/casos/pruebas/precios-carrito/cambio/src/precio.ts +34 -0
  66. package/bench/casos/pruebas/precios-carrito/cambio/test/precio.test.js +42 -0
  67. package/bench/casos/pruebas/precios-carrito/esperado.json +42 -0
  68. package/bench/casos/rendimiento/boletin-correo/base/src/correo.html +1 -0
  69. package/bench/casos/rendimiento/boletin-correo/base/src/plantilla.ts +11 -0
  70. package/bench/casos/rendimiento/boletin-correo/cambio/src/envios.ts +44 -0
  71. package/bench/casos/rendimiento/boletin-correo/cambio/src/plantilla.ts +10 -0
  72. package/bench/casos/rendimiento/boletin-correo/esperado.json +42 -0
  73. package/bench/casos/rendimiento/clientes-por-lote/base/src/informe.js +8 -0
  74. package/bench/casos/rendimiento/clientes-por-lote/cambio/src/informe.js +6 -0
  75. package/bench/casos/rendimiento/clientes-por-lote/esperado.json +14 -0
  76. package/bench/casos/rendimiento/informe-ventas/base/src/informe.js +6 -0
  77. package/bench/casos/rendimiento/informe-ventas/base/src/tasas.json +1 -0
  78. package/bench/casos/rendimiento/informe-ventas/cambio/src/informe.js +33 -0
  79. package/bench/casos/rendimiento/informe-ventas/cambio/src/tasas.js +7 -0
  80. package/bench/casos/rendimiento/informe-ventas/esperado.json +42 -0
  81. package/bench/casos/seguridad/inyeccion-orden/base/src/respaldo.ts +13 -0
  82. package/bench/casos/seguridad/inyeccion-orden/cambio/src/respaldo.ts +69 -0
  83. package/bench/casos/seguridad/inyeccion-orden/esperado.json +42 -0
  84. package/bench/casos/seguridad/limpio-validacion/base/servidor.js +11 -0
  85. package/bench/casos/seguridad/limpio-validacion/cambio/servidor.js +39 -0
  86. package/bench/casos/seguridad/limpio-validacion/esperado.json +14 -0
  87. package/bench/casos/seguridad/servidor-archivos/base/servidor.js +21 -0
  88. package/bench/casos/seguridad/servidor-archivos/cambio/servidor.js +79 -0
  89. package/bench/casos/seguridad/servidor-archivos/esperado.json +42 -0
  90. package/bin/nexakit-fabrica-mcp.js +12 -0
  91. package/dist/fabrica/banco/casos.js +304 -0
  92. package/dist/fabrica/banco/ejecutar.js +483 -0
  93. package/dist/fabrica/banco/medir.js +120 -0
  94. package/dist/fabrica/cli.js +737 -0
  95. package/dist/fabrica/conectores/antigravity.js +1040 -0
  96. package/dist/fabrica/conectores/codex.js +967 -0
  97. package/dist/fabrica/conectores/tipos.js +8 -0
  98. package/dist/fabrica/config.js +44 -0
  99. package/dist/fabrica/consolidar.js +218 -0
  100. package/dist/fabrica/decision.js +210 -0
  101. package/dist/fabrica/diff.js +247 -0
  102. package/dist/fabrica/disco.js +356 -0
  103. package/dist/fabrica/ejecutor.js +597 -0
  104. package/dist/fabrica/encargo/candado.js +274 -0
  105. package/dist/fabrica/encargo/ejecutar.js +827 -0
  106. package/dist/fabrica/encargo/evidencia.js +308 -0
  107. package/dist/fabrica/encargo/parche.js +146 -0
  108. package/dist/fabrica/encargo/worktree.js +394 -0
  109. package/dist/fabrica/enrutador.js +425 -0
  110. package/dist/fabrica/errores.js +14 -0
  111. package/dist/fabrica/esquemas.js +57 -0
  112. package/dist/fabrica/estaciones.js +75 -0
  113. package/dist/fabrica/evidencia.js +406 -0
  114. package/dist/fabrica/indice.js +1 -0
  115. package/dist/fabrica/jsonrpc.js +274 -0
  116. package/dist/fabrica/lecciones.js +363 -0
  117. package/dist/fabrica/mcp.js +376 -0
  118. package/dist/fabrica/preferencias.js +56 -0
  119. package/dist/fabrica/protocolos/codex/AbsolutePathBuf.js +2 -0
  120. package/dist/fabrica/protocolos/codex/ApplyPatchApprovalResponse.js +2 -0
  121. package/dist/fabrica/protocolos/codex/ClientInfo.js +2 -0
  122. package/dist/fabrica/protocolos/codex/ExecCommandApprovalParams.js +2 -0
  123. package/dist/fabrica/protocolos/codex/ExecCommandApprovalResponse.js +2 -0
  124. package/dist/fabrica/protocolos/codex/ExecPolicyAmendment.js +2 -0
  125. package/dist/fabrica/protocolos/codex/FunctionCallOutputBody.js +2 -0
  126. package/dist/fabrica/protocolos/codex/FunctionCallOutputContentItem.js +2 -0
  127. package/dist/fabrica/protocolos/codex/ImageDetail.js +2 -0
  128. package/dist/fabrica/protocolos/codex/InitializeCapabilities.js +2 -0
  129. package/dist/fabrica/protocolos/codex/InitializeParams.js +2 -0
  130. package/dist/fabrica/protocolos/codex/InitializeResponse.js +2 -0
  131. package/dist/fabrica/protocolos/codex/InputModality.js +2 -0
  132. package/dist/fabrica/protocolos/codex/LegacyAppPathString.js +2 -0
  133. package/dist/fabrica/protocolos/codex/NetworkPolicyAmendment.js +2 -0
  134. package/dist/fabrica/protocolos/codex/NetworkPolicyRuleAction.js +2 -0
  135. package/dist/fabrica/protocolos/codex/ParsedCommand.js +2 -0
  136. package/dist/fabrica/protocolos/codex/Personality.js +2 -0
  137. package/dist/fabrica/protocolos/codex/ReasoningEffort.js +2 -0
  138. package/dist/fabrica/protocolos/codex/ReasoningSummary.js +2 -0
  139. package/dist/fabrica/protocolos/codex/ReviewDecision.js +2 -0
  140. package/dist/fabrica/protocolos/codex/ThreadId.js +2 -0
  141. package/dist/fabrica/protocolos/codex/serde_json/JsonValue.js +2 -0
  142. package/dist/fabrica/protocolos/codex/v2/AdditionalFileSystemPermissions.js +2 -0
  143. package/dist/fabrica/protocolos/codex/v2/AdditionalNetworkPermissions.js +2 -0
  144. package/dist/fabrica/protocolos/codex/v2/ApprovalsReviewer.js +2 -0
  145. package/dist/fabrica/protocolos/codex/v2/AskForApproval.js +2 -0
  146. package/dist/fabrica/protocolos/codex/v2/ByteRange.js +2 -0
  147. package/dist/fabrica/protocolos/codex/v2/CommandAction.js +2 -0
  148. package/dist/fabrica/protocolos/codex/v2/CommandExecutionApprovalDecision.js +2 -0
  149. package/dist/fabrica/protocolos/codex/v2/CommandExecutionApprovalKind.js +2 -0
  150. package/dist/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalParams.js +2 -0
  151. package/dist/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalResponse.js +2 -0
  152. package/dist/fabrica/protocolos/codex/v2/ConfigReadParams.js +2 -0
  153. package/dist/fabrica/protocolos/codex/v2/CyberAccessProgram.js +2 -0
  154. package/dist/fabrica/protocolos/codex/v2/ExecPolicyAmendment.js +2 -0
  155. package/dist/fabrica/protocolos/codex/v2/FileChangeApprovalDecision.js +2 -0
  156. package/dist/fabrica/protocolos/codex/v2/FileChangeRequestApprovalResponse.js +2 -0
  157. package/dist/fabrica/protocolos/codex/v2/FileSystemAccessMode.js +2 -0
  158. package/dist/fabrica/protocolos/codex/v2/FileSystemPath.js +2 -0
  159. package/dist/fabrica/protocolos/codex/v2/FileSystemSandboxEntry.js +2 -0
  160. package/dist/fabrica/protocolos/codex/v2/FileSystemSpecialPath.js +2 -0
  161. package/dist/fabrica/protocolos/codex/v2/GrantedPermissionProfile.js +2 -0
  162. package/dist/fabrica/protocolos/codex/v2/ListMcpServerStatusParams.js +2 -0
  163. package/dist/fabrica/protocolos/codex/v2/McpServerElicitationAction.js +2 -0
  164. package/dist/fabrica/protocolos/codex/v2/McpServerElicitationRequestResponse.js +2 -0
  165. package/dist/fabrica/protocolos/codex/v2/McpServerStatusDetail.js +2 -0
  166. package/dist/fabrica/protocolos/codex/v2/Model.js +2 -0
  167. package/dist/fabrica/protocolos/codex/v2/ModelAccessPrograms.js +2 -0
  168. package/dist/fabrica/protocolos/codex/v2/ModelAvailabilityNux.js +2 -0
  169. package/dist/fabrica/protocolos/codex/v2/ModelListParams.js +2 -0
  170. package/dist/fabrica/protocolos/codex/v2/ModelListResponse.js +2 -0
  171. package/dist/fabrica/protocolos/codex/v2/ModelServiceTier.js +2 -0
  172. package/dist/fabrica/protocolos/codex/v2/ModelUpgradeInfo.js +2 -0
  173. package/dist/fabrica/protocolos/codex/v2/MultiAgentVersion.js +2 -0
  174. package/dist/fabrica/protocolos/codex/v2/NetworkAccess.js +2 -0
  175. package/dist/fabrica/protocolos/codex/v2/NetworkApprovalContext.js +2 -0
  176. package/dist/fabrica/protocolos/codex/v2/NetworkApprovalProtocol.js +2 -0
  177. package/dist/fabrica/protocolos/codex/v2/NetworkPolicyAmendment.js +2 -0
  178. package/dist/fabrica/protocolos/codex/v2/NetworkPolicyRuleAction.js +2 -0
  179. package/dist/fabrica/protocolos/codex/v2/PermissionGrantScope.js +2 -0
  180. package/dist/fabrica/protocolos/codex/v2/PermissionsRequestApprovalResponse.js +2 -0
  181. package/dist/fabrica/protocolos/codex/v2/ReasoningEffortOption.js +2 -0
  182. package/dist/fabrica/protocolos/codex/v2/SandboxMode.js +2 -0
  183. package/dist/fabrica/protocolos/codex/v2/SandboxPolicy.js +2 -0
  184. package/dist/fabrica/protocolos/codex/v2/TextElement.js +2 -0
  185. package/dist/fabrica/protocolos/codex/v2/ThreadSource.js +2 -0
  186. package/dist/fabrica/protocolos/codex/v2/ThreadStartParams.js +2 -0
  187. package/dist/fabrica/protocolos/codex/v2/ThreadStartSource.js +2 -0
  188. package/dist/fabrica/protocolos/codex/v2/ThreadTokenUsage.js +2 -0
  189. package/dist/fabrica/protocolos/codex/v2/ThreadTokenUsageUpdatedNotification.js +2 -0
  190. package/dist/fabrica/protocolos/codex/v2/TokenUsageBreakdown.js +2 -0
  191. package/dist/fabrica/protocolos/codex/v2/ToolRequestUserInputAnswer.js +2 -0
  192. package/dist/fabrica/protocolos/codex/v2/ToolRequestUserInputResponse.js +2 -0
  193. package/dist/fabrica/protocolos/codex/v2/TurnInterruptParams.js +2 -0
  194. package/dist/fabrica/protocolos/codex/v2/TurnStartParams.js +2 -0
  195. package/dist/fabrica/protocolos/codex/v2/TurnToolOutput.js +2 -0
  196. package/dist/fabrica/protocolos/codex/v2/UserInput.js +2 -0
  197. package/dist/fabrica/rastro.js +487 -0
  198. package/dist/fabrica/sesion.js +230 -0
  199. package/dist/fabrica/tabla-modelos.json +29 -0
  200. package/dist/fabrica/veredictos.js +327 -0
  201. package/package.json +16 -8
  202. package/plugins/huellas.json +6 -6
  203. package/plugins/nexakit-lecciones/.claude-plugin/plugin.json +1 -1
  204. package/plugins/nexakit-lecciones/README.md +6 -5
  205. package/plugins/nexakit-lecciones/hooks/lecciones.js +29 -5
  206. package/plugins/nexakit-lecciones/hooks/register.js +7 -3
  207. package/plugins/nexakit-modelo/.claude-plugin/plugin.json +1 -1
  208. package/plugins/nexakit-modelo/hooks/barra.js +100 -4
  209. package/plugins/nexakit-modelo/hooks/decidir.js +2 -2
  210. package/plugins/nexakit-modelo/hooks/recomendar.js +1 -1
  211. package/plugins/nexakit-modelo/hooks/register.js +122 -7
  212. package/plugins/nexakit-modelo/tests/register.test.ts +301 -0
  213. package/plugins/niveles/.claude-plugin/plugin.json +1 -1
  214. package/plugins/niveles/agents/cazador-de-flakes.md +1 -0
  215. package/plugins/niveles/agents/cierre-de-memoria.md +1 -0
  216. package/plugins/niveles/agents/investigador.md +1 -0
  217. package/plugins/niveles/agents/nivel-alto.md +1 -0
  218. package/plugins/niveles/agents/nivel-exigente.md +1 -0
  219. package/plugins/niveles/agents/nivel-ligero.md +1 -0
  220. package/plugins/niveles/agents/nivel-normal.md +1 -0
  221. package/plugins/niveles/agents/revisor-de-calidad.md +1 -0
  222. package/plugins/niveles/agents/sincronizador-docs.md +1 -0
  223. package/plugins/niveles/agents/subir-al-repo.md +1 -0
  224. package/skills/elegir-modelo/SKILL.md +4 -3
  225. package/skills/elegir-modelo/modelos.mjs +100 -1
  226. package/skills/fabrica/SKILL.md +55 -0
  227. package/skills/gemini/SKILL.md +2 -3
  228. package/skills/quality-gate/SKILL.md +2 -2
  229. package/src/agent-models.js +6 -4
  230. package/src/antigravity-barra.js +64 -12
  231. package/src/antigravity-command.js +4 -2
  232. package/src/antigravity-models.js +61 -0
  233. package/src/antigravity-pre-tool.js +11 -3
  234. package/src/antigravity-recommendation.js +15 -9
  235. package/src/antigravity-setup.js +4 -31
  236. package/src/cli-executable.d.ts +11 -0
  237. package/src/codex-pre-tool.js +3 -3
  238. package/src/codex-recommendation.js +1 -2
  239. package/src/codex-setup.js +3 -20
  240. package/src/codex-team.js +31 -4
  241. package/src/fabrica/banco/casos.ts +315 -0
  242. package/src/fabrica/banco/ejecutar.ts +587 -0
  243. package/src/fabrica/banco/medir.ts +160 -0
  244. package/src/fabrica/cli.ts +781 -0
  245. package/src/fabrica/conectores/antigravity.ts +1090 -0
  246. package/src/fabrica/conectores/codex.ts +1013 -0
  247. package/src/fabrica/conectores/tipos.ts +54 -0
  248. package/src/fabrica/config.ts +43 -0
  249. package/src/fabrica/consolidar.ts +277 -0
  250. package/src/fabrica/decision.ts +285 -0
  251. package/src/fabrica/diff.ts +294 -0
  252. package/src/fabrica/disco.ts +380 -0
  253. package/src/fabrica/ejecutor.ts +716 -0
  254. package/src/fabrica/encargo/candado.ts +287 -0
  255. package/src/fabrica/encargo/ejecutar.ts +953 -0
  256. package/src/fabrica/encargo/evidencia.ts +301 -0
  257. package/src/fabrica/encargo/parche.ts +151 -0
  258. package/src/fabrica/encargo/worktree.ts +427 -0
  259. package/src/fabrica/enrutador.ts +494 -0
  260. package/src/fabrica/errores.ts +15 -0
  261. package/src/fabrica/esquemas.ts +92 -0
  262. package/src/fabrica/estaciones.ts +83 -0
  263. package/src/fabrica/evidencia.ts +445 -0
  264. package/src/fabrica/indice.ts +1 -0
  265. package/src/fabrica/jsonrpc.ts +314 -0
  266. package/src/fabrica/lecciones.ts +411 -0
  267. package/src/fabrica/mcp.ts +450 -0
  268. package/src/fabrica/preferencias.ts +66 -0
  269. package/src/fabrica/protocolos/codex/AbsolutePathBuf.ts +14 -0
  270. package/src/fabrica/protocolos/codex/ApplyPatchApprovalResponse.ts +6 -0
  271. package/src/fabrica/protocolos/codex/ClientInfo.ts +5 -0
  272. package/src/fabrica/protocolos/codex/ExecCommandApprovalParams.ts +16 -0
  273. package/src/fabrica/protocolos/codex/ExecCommandApprovalResponse.ts +6 -0
  274. package/src/fabrica/protocolos/codex/ExecPolicyAmendment.ts +12 -0
  275. package/src/fabrica/protocolos/codex/FunctionCallOutputBody.ts +6 -0
  276. package/src/fabrica/protocolos/codex/FunctionCallOutputContentItem.ts +10 -0
  277. package/src/fabrica/protocolos/codex/ImageDetail.ts +5 -0
  278. package/src/fabrica/protocolos/codex/InitializeCapabilities.ts +42 -0
  279. package/src/fabrica/protocolos/codex/InitializeParams.ts +7 -0
  280. package/src/fabrica/protocolos/codex/InitializeResponse.ts +20 -0
  281. package/src/fabrica/protocolos/codex/InputModality.ts +8 -0
  282. package/src/fabrica/protocolos/codex/LegacyAppPathString.ts +27 -0
  283. package/src/fabrica/protocolos/codex/NetworkPolicyAmendment.ts +6 -0
  284. package/src/fabrica/protocolos/codex/NetworkPolicyRuleAction.ts +5 -0
  285. package/src/fabrica/protocolos/codex/ParsedCommand.ts +12 -0
  286. package/src/fabrica/protocolos/codex/Personality.ts +8 -0
  287. package/src/fabrica/protocolos/codex/ReasoningEffort.ts +8 -0
  288. package/src/fabrica/protocolos/codex/ReasoningSummary.ts +10 -0
  289. package/src/fabrica/protocolos/codex/ReviewDecision.ts +10 -0
  290. package/src/fabrica/protocolos/codex/ThreadId.ts +10 -0
  291. package/src/fabrica/protocolos/codex/VERSION +1 -0
  292. package/src/fabrica/protocolos/codex/serde_json/JsonValue.ts +5 -0
  293. package/src/fabrica/protocolos/codex/v2/AdditionalFileSystemPermissions.ts +15 -0
  294. package/src/fabrica/protocolos/codex/v2/AdditionalNetworkPermissions.ts +5 -0
  295. package/src/fabrica/protocolos/codex/v2/ApprovalsReviewer.ts +12 -0
  296. package/src/fabrica/protocolos/codex/v2/AskForApproval.ts +5 -0
  297. package/src/fabrica/protocolos/codex/v2/ByteRange.ts +5 -0
  298. package/src/fabrica/protocolos/codex/v2/CommandAction.ts +6 -0
  299. package/src/fabrica/protocolos/codex/v2/CommandExecutionApprovalDecision.ts +7 -0
  300. package/src/fabrica/protocolos/codex/v2/CommandExecutionApprovalKind.ts +8 -0
  301. package/src/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalParams.ts +51 -0
  302. package/src/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalResponse.ts +6 -0
  303. package/src/fabrica/protocolos/codex/v2/ConfigReadParams.ts +11 -0
  304. package/src/fabrica/protocolos/codex/v2/CyberAccessProgram.ts +9 -0
  305. package/src/fabrica/protocolos/codex/v2/ExecPolicyAmendment.ts +5 -0
  306. package/src/fabrica/protocolos/codex/v2/FileChangeApprovalDecision.ts +5 -0
  307. package/src/fabrica/protocolos/codex/v2/FileChangeRequestApprovalResponse.ts +6 -0
  308. package/src/fabrica/protocolos/codex/v2/FileSystemAccessMode.ts +5 -0
  309. package/src/fabrica/protocolos/codex/v2/FileSystemPath.ts +7 -0
  310. package/src/fabrica/protocolos/codex/v2/FileSystemSandboxEntry.ts +7 -0
  311. package/src/fabrica/protocolos/codex/v2/FileSystemSpecialPath.ts +6 -0
  312. package/src/fabrica/protocolos/codex/v2/GrantedPermissionProfile.ts +7 -0
  313. package/src/fabrica/protocolos/codex/v2/ListMcpServerStatusParams.ts +23 -0
  314. package/src/fabrica/protocolos/codex/v2/McpServerElicitationAction.ts +5 -0
  315. package/src/fabrica/protocolos/codex/v2/McpServerElicitationRequestResponse.ts +17 -0
  316. package/src/fabrica/protocolos/codex/v2/McpServerStatusDetail.ts +5 -0
  317. package/src/fabrica/protocolos/codex/v2/Model.ts +33 -0
  318. package/src/fabrica/protocolos/codex/v2/ModelAccessPrograms.ts +13 -0
  319. package/src/fabrica/protocolos/codex/v2/ModelAvailabilityNux.ts +5 -0
  320. package/src/fabrica/protocolos/codex/v2/ModelListParams.ts +17 -0
  321. package/src/fabrica/protocolos/codex/v2/ModelListResponse.ts +11 -0
  322. package/src/fabrica/protocolos/codex/v2/ModelServiceTier.ts +5 -0
  323. package/src/fabrica/protocolos/codex/v2/ModelUpgradeInfo.ts +9 -0
  324. package/src/fabrica/protocolos/codex/v2/MultiAgentVersion.ts +8 -0
  325. package/src/fabrica/protocolos/codex/v2/NetworkAccess.ts +5 -0
  326. package/src/fabrica/protocolos/codex/v2/NetworkApprovalContext.ts +6 -0
  327. package/src/fabrica/protocolos/codex/v2/NetworkApprovalProtocol.ts +5 -0
  328. package/src/fabrica/protocolos/codex/v2/NetworkPolicyAmendment.ts +6 -0
  329. package/src/fabrica/protocolos/codex/v2/NetworkPolicyRuleAction.ts +5 -0
  330. package/src/fabrica/protocolos/codex/v2/PermissionGrantScope.ts +5 -0
  331. package/src/fabrica/protocolos/codex/v2/PermissionsRequestApprovalResponse.ts +11 -0
  332. package/src/fabrica/protocolos/codex/v2/ReasoningEffortOption.ts +6 -0
  333. package/src/fabrica/protocolos/codex/v2/SandboxMode.ts +5 -0
  334. package/src/fabrica/protocolos/codex/v2/SandboxPolicy.ts +7 -0
  335. package/src/fabrica/protocolos/codex/v2/TextElement.ts +14 -0
  336. package/src/fabrica/protocolos/codex/v2/ThreadSource.ts +5 -0
  337. package/src/fabrica/protocolos/codex/v2/ThreadStartParams.ts +22 -0
  338. package/src/fabrica/protocolos/codex/v2/ThreadStartSource.ts +5 -0
  339. package/src/fabrica/protocolos/codex/v2/ThreadTokenUsage.ts +6 -0
  340. package/src/fabrica/protocolos/codex/v2/ThreadTokenUsageUpdatedNotification.ts +6 -0
  341. package/src/fabrica/protocolos/codex/v2/TokenUsageBreakdown.ts +5 -0
  342. package/src/fabrica/protocolos/codex/v2/ToolRequestUserInputAnswer.ts +8 -0
  343. package/src/fabrica/protocolos/codex/v2/ToolRequestUserInputResponse.ts +9 -0
  344. package/src/fabrica/protocolos/codex/v2/TurnInterruptParams.ts +5 -0
  345. package/src/fabrica/protocolos/codex/v2/TurnStartParams.ts +75 -0
  346. package/src/fabrica/protocolos/codex/v2/TurnToolOutput.ts +10 -0
  347. package/src/fabrica/protocolos/codex/v2/UserInput.ts +11 -0
  348. package/src/fabrica/rastro.ts +508 -0
  349. package/src/fabrica/sesion.ts +280 -0
  350. package/src/fabrica/tabla-modelos.json +29 -0
  351. package/src/fabrica/veredictos.ts +365 -0
  352. package/src/gemini-cli.js +15 -12
  353. package/src/gemini-tools.js +1 -1
  354. package/src/gemini-usage-store.js +32 -0
  355. package/src/instructions-block.js +69 -0
  356. package/src/lecciones-command.js +105 -4
  357. package/src/lecciones-instructions.js +178 -0
  358. package/src/legacy-repair.js +1 -1
  359. package/src/level-agents.js +5 -3
  360. package/src/memory-mcp-policy.js +1 -1
  361. package/src/missing-dependencies.js +5 -0
  362. package/src/model-command.d.ts +29 -0
  363. package/src/model-command.js +4 -27
  364. package/src/regla-ordenes-simples.d.ts +2 -0
  365. package/src/regla-ordenes-simples.js +4 -0
  366. package/src/review-instructions.js +69 -81
  367. package/src/safe-paths.js +38 -0
  368. package/src/setup-apply.js +24 -2
  369. package/src/setup-plan.js +57 -1
  370. package/src/setup-state.js +14 -0
  371. package/src/shell-quote.js +2 -0
  372. package/src/skill-recommendations.js +101 -28
  373. package/src/stable-command.js +2 -2
  374. package/src/stable-install.js +4 -2
  375. package/src/superpowers.js +0 -7
  376. package/src/task-document.js +59 -0
  377. package/src/terminal-text.js +2 -19
  378. package/src/toolkit-cli.js +63 -8
  379. package/src/toolkit-setup.js +192 -37
  380. package/templates/agent-team/README.md +7 -19
  381. package/bin/agent-task.js +0 -14
  382. package/bin/agent-toolkit-inbox.js +0 -14
  383. package/bin/agent-toolkit-mcp.js +0 -17
  384. package/schemas/agent-client-adapter.schema.json +0 -786
  385. package/schemas/agent-client-auth-diagnostic.schema.json +0 -801
  386. package/schemas/agent-client-isolated-variant.schema.json +0 -105
  387. package/schemas/agent-client-isolated-verification.schema.json +0 -99
  388. package/schemas/agent-client-managed-preferences-invocation.schema.json +0 -67
  389. package/schemas/agent-client-managed-preferences.schema.json +0 -63
  390. package/schemas/agent-client-native-diagnostics.schema.json +0 -85
  391. package/schemas/agent-client-native-evaluation.schema.json +0 -171
  392. package/schemas/agent-client-native-preflight.schema.json +0 -90
  393. package/schemas/agent-client-output.schema.json +0 -551
  394. package/schemas/agent-client-runtime-fixture.schema.json +0 -90
  395. package/schemas/agent-client-runtime-local.schema.json +0 -95
  396. package/schemas/agent-client-runtime.schema.json +0 -1288
  397. package/schemas/agent-client-selective-config.schema.json +0 -77
  398. package/schemas/agent-client-supervised-local.schema.json +0 -135
  399. package/schemas/agent-client-supervised.schema.json +0 -186
  400. package/schemas/agent-task-approvals.schema.json +0 -362
  401. package/schemas/agent-task-prepare.schema.json +0 -1324
  402. package/schemas/agent-task-verify.schema.json +0 -198
  403. package/schemas/task-workflow-plan-output.schema.json +0 -35
  404. package/skills/revisar/SKILL.md +0 -51
  405. package/src/claude-code-runner.js +0 -642
  406. package/src/client-adapter-plan.js +0 -271
  407. package/src/client-auth-diagnostic-parser.js +0 -211
  408. package/src/client-auth-diagnostic.js +0 -257
  409. package/src/client-isolated-variant.js +0 -106
  410. package/src/client-isolated-verification.js +0 -130
  411. package/src/client-local-platform.js +0 -14
  412. package/src/client-managed-preferences-invocation.js +0 -209
  413. package/src/client-managed-preferences.js +0 -78
  414. package/src/client-native-access.js +0 -134
  415. package/src/client-native-diagnostics.js +0 -253
  416. package/src/client-native-evaluation.js +0 -106
  417. package/src/client-native-preflight-files.js +0 -68
  418. package/src/client-native-preflight.js +0 -95
  419. package/src/client-output-parser.js +0 -278
  420. package/src/client-runtime-admission.js +0 -80
  421. package/src/client-runtime-coordinator.js +0 -70
  422. package/src/client-runtime-core.js +0 -92
  423. package/src/client-runtime-fixture-permit.js +0 -20
  424. package/src/client-runtime-fixture-protocol.js +0 -39
  425. package/src/client-runtime-state.js +0 -67
  426. package/src/client-runtime-store-files.js +0 -91
  427. package/src/client-runtime-store.js +0 -239
  428. package/src/client-runtime-supervisor.js +0 -146
  429. package/src/client-selective-config.js +0 -195
  430. package/src/client-selective-files.js +0 -126
  431. package/src/client-supervised-codes.js +0 -32
  432. package/src/client-supervised-contract.js +0 -52
  433. package/src/client-supervised-coordinator.js +0 -36
  434. package/src/client-supervised-permit.js +0 -20
  435. package/src/client-supervised-protocol.js +0 -37
  436. package/src/client-supervised-store.js +0 -167
  437. package/src/client-supervised-supervisor.js +0 -167
  438. package/src/client-supervised.js +0 -160
  439. package/src/codex-cli-runner.js +0 -358
  440. package/src/codex-delivery.js +0 -101
  441. package/src/memory-connection-artifacts.js +0 -192
  442. package/src/memory-connection-descriptor.js +0 -158
  443. package/src/memory-connection-diagnostic.js +0 -177
  444. package/src/memory-connection-files.js +0 -191
  445. package/src/memory-connection-manifest.js +0 -118
  446. package/src/memory-connection-package.js +0 -176
  447. package/src/memory-connection-plan.js +0 -217
  448. package/src/memory-connection-skill.js +0 -211
  449. package/src/memory-connection-toml.js +0 -153
  450. package/src/native/managed-preferences.c +0 -100
  451. package/src/native/managed-preferences.h +0 -17
  452. package/src/package-lock-path.js +0 -13
  453. package/src/peer-handoff.js +0 -27
  454. package/src/peer-inbox-cli.js +0 -211
  455. package/src/peer-review-mcp.js +0 -210
  456. package/src/peer-review-store.js +0 -532
  457. package/src/review-policy.js +0 -35
  458. package/src/revision-adapters.js +0 -158
  459. package/src/revision-context.js +0 -86
  460. package/src/revision-isolation.js +0 -222
  461. package/src/revision-process.js +0 -103
  462. package/src/revision-provenance.js +0 -89
  463. package/src/revision-snapshot.js +0 -120
  464. package/src/revision.js +0 -242
  465. package/src/runtime-fixtures/runtime-supervisor/child.cjs +0 -3
  466. package/src/runtime-fixtures/runtime-supervisor/fixture.cjs +0 -49
  467. package/src/runtime-fixtures/supervised/child.cjs +0 -3
  468. package/src/runtime-fixtures/supervised/fixture.cjs +0 -47
  469. package/src/task-approvals.js +0 -367
  470. package/src/task-cli.js +0 -79
  471. package/src/task-external-verifier.js +0 -584
  472. package/src/task-prepare-files.js +0 -115
  473. package/src/task-prepare.js +0 -180
  474. package/src/task-verify-cli.js +0 -67
  475. package/src/task-verify-files.js +0 -188
  476. package/src/task-verify.js +0 -118
  477. package/src/task-workflow-mcp.js +0 -544
  478. package/src/task-workflow-store.js +0 -254
  479. package/src/toolkit-commands-guide.js +0 -115
@@ -1,209 +0,0 @@
1
- import { supportsPreferenceHost } from "./client-local-platform.js";
2
- import fs from "node:fs/promises";
3
- import { constants } from "node:fs";
4
- import path from "node:path";
5
- import { spawn as systemSpawn } from "node:child_process";
6
- import { createHash } from "node:crypto";
7
- import { types } from "node:util";
8
- import Ajv2020 from "ajv/dist/2020.js";
9
- import { copyInertJson, copyBytes } from "./client-output-json.js";
10
- import { hash } from "./client-runtime-core.js";
11
- import { createStoreFiles } from "./client-runtime-store-files.js";
12
- import { createManagedPreferencesStreamReader } from "./client-managed-preferences.js";
13
-
14
- export const INVOCATION_SCHEMA_ID = "https://agent-toolkit.local/schemas/agent-client-managed-preferences-invocation.schema.json";
15
- const permits = new WeakMap(), monotonic = () => Number(process.hrtime.bigint() / 1000000n);
16
- const environmentIdentity = () => hash({ home: process.env.HOME, uid: process.getuid?.() ?? null, profile: "preferences-minimal-v1" });
17
- const physicalName = p => typeof p === "string" && path.isAbsolute(p) && path.normalize(p) === p &&
18
- !/[\x00-\x1f\x7f]/.test(p) && Buffer.from(p, "utf8").toString("utf8") === p;
19
- const signature = s => JSON.stringify([s.dev, s.ino, s.uid, s.mode, s.nlink, s.size, s.mtimeMs, s.ctimeMs]);
20
- const chunkLength = b => {
21
- if (types.isProxy(b) || !types.isUint8Array(b)) throw Error("chunk");
22
- return Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), "length").get.call(b);
23
- };
24
-
25
- /** Trusted orchestration must obtain human approval first. JSON/hash is not consent. */
26
- export function createManagedPreferencesInvocationPermit(configuration) {
27
- let cfg;
28
- try {
29
- cfg = copyInertJson(configuration);
30
- if (!Number.isSafeInteger(cfg.limits.permitLifetimeMs) || cfg.limits.permitLifetimeMs < 1 || cfg.limits.permitLifetimeMs > 3600000) throw Error();
31
- } catch { throw Error("Invalid helper permission configuration"); }
32
- const handle = Object.freeze(Object.create(null)), issuedAt = monotonic();
33
- permits.set(handle, { binding: hash(cfg), environment: environmentIdentity(), issuedAt, expiresAt: issuedAt + cfg.limits.permitLifetimeMs, live: true, used: false });
34
- return handle;
35
- }
36
- export function revokeManagedPreferencesInvocationPermit(handle) {
37
- if (types.isProxy(handle)) return;
38
- const p = permits.get(handle); if (p) p.live = false;
39
- }
40
-
41
- async function verifyArtifact(pin, io, files, deadline, now) {
42
- await files.physical(pin.path);
43
- const before = await io.lstat(pin.path);
44
- if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1 || before.dev !== pin.dev || before.ino !== pin.ino ||
45
- before.uid !== pin.uid || (before.mode & 4095) !== pin.mode || !(pin.mode & 0o100) || pin.mode & 0o022 || before.size !== pin.size ||
46
- before.mtimeMs !== pin.mtimeMs || before.ctimeMs !== pin.ctimeMs) throw Error("artifact");
47
- const handle = await io.open(pin.path, constants.O_RDONLY | constants.O_NOFOLLOW), digest = createHash("sha256");
48
- try {
49
- if (signature(before) !== signature(await handle.stat())) throw Error("artifact");
50
- const buffer = Buffer.alloc(65536); let offset = 0;
51
- while (offset < pin.size) {
52
- if (now() >= deadline) throw Error("deadline");
53
- const length = Math.min(buffer.length, pin.size - offset, 8388608 - offset);
54
- const { bytesRead } = await handle.read(buffer, 0, length, offset); if (!bytesRead) throw Error("artifact");
55
- offset += bytesRead; if (offset > pin.size || offset > 8388608) throw Error("artifact"); digest.update(buffer.subarray(0, bytesRead));
56
- }
57
- if (offset !== pin.size || digest.digest("hex") !== pin.sha256 || signature(before) !== signature(await handle.stat()) ||
58
- signature(before) !== signature(await io.lstat(pin.path))) throw Error("artifact");
59
- await files.physical(pin.path);
60
- } finally { await handle.close(); }
61
- }
62
-
63
- /** A single approved helper, not an AI client launcher or an isolation certificate. */
64
- export function createManagedPreferencesInvocation(schema, preferencesSchema, configuration, authorization, dependencies = {}) {
65
- let cfg, validReport, prefSchema;
66
- try {
67
- cfg = copyInertJson(configuration);
68
- const s = copyInertJson(schema), ps = copyInertJson(preferencesSchema); prefSchema = ps;
69
- if (s.$id !== INVOCATION_SCHEMA_ID || ps.$id !== "https://agent-toolkit.local/schemas/agent-client-managed-preferences.schema.json") throw Error();
70
- const ajv = new Ajv2020({ strict: true, allErrors: true }); ajv.addSchema(ps); ajv.addSchema(s);
71
- const valid = ajv.compile({ $ref: `${INVOCATION_SCHEMA_ID}#/$defs/configuration` });
72
- if (!valid(cfg) || !physicalName(cfg.artifact.path) || !physicalName(cfg.workspaceParent.path) ||
73
- cfg.limits.graceMs + cfg.limits.confirmationMs + 20 >= cfg.limits.totalTimeoutMs) throw Error();
74
- createManagedPreferencesStreamReader(ps, cfg.expectedSource); // Validate the decoder contract before IO.
75
- validReport = ajv.compile({ $ref: `${INVOCATION_SCHEMA_ID}#/$defs/report` });
76
- } catch { throw Error("Invalid managed-preferences invocation configuration"); }
77
- const limits = cfg.limits, io = { ...fs, ...dependencies.io }, files = createStoreFiles(dependencies.io);
78
- const spawn = dependencies.spawn ?? systemSpawn, kill = dependencies.kill ?? process.kill.bind(process), now = dependencies.monotonic ?? monotonic;
79
- let invoked = false;
80
- return Object.freeze({ async run(...args) {
81
- const began = now(), deadline = began + limits.totalTimeoutMs;
82
- const r = { scope: "managed-preferences-helper-only", state: "blocked", decision: "no-client-start", spawnAttempts: 0,
83
- helperStarted: false, helperExecutionVerified: false, artifactMatchedBefore: false, artifactMatchedAfter: false,
84
- terminationConfirmed: true, cleanupRequired: false, stdoutBytes: 0, stderrBytes: 0, elapsedMs: 0, projection: null, reasons: [],
85
- nativeClientStarted: false, inferenceRequested: false, runtimeReady: false, verifiedAdmission: false,
86
- effectiveIsolationVerified: false, externalBillingVerified: false, preferencesQueriedVerified: false };
87
- let workspace, owned, parent, permission, claimed = false;
88
- const add = code => { if (!r.reasons.includes(code)) r.reasons.push(code); };
89
- try {
90
- if (invoked) throw Error("permission"); invoked = true;
91
- permission = !types.isProxy(authorization) && permits.get(authorization);
92
- if (!permission || !permission.live || permission.used || permission.binding !== hash(cfg) ||
93
- permission.environment !== environmentIdentity() ||
94
- began < permission.issuedAt || began >= permission.expiresAt) { add("helper-permission-rejected"); return r; }
95
- permission.used = true; claimed = true;
96
- if (args.length) { add("helper-input-forbidden"); return r; }
97
- if (!supportsPreferenceHost(process.platform, cfg.expectedSource) || cfg.artifact.uid !== process.getuid() || cfg.workspaceParent.uid !== process.getuid()) throw Error("identity");
98
- if (dependencies.signal?.aborted) { r.state = "canceled"; add("helper-canceled"); return r; }
99
- const home = process.env.HOME;
100
- if (!physicalName(home) || /(CloudStorage|Mobile Documents|Dropbox|OneDrive|iCloud)/i.test(cfg.workspaceParent.path)) throw Error("parent");
101
- parent = await files.directory(cfg.workspaceParent.path);
102
- if (parent.dev !== cfg.workspaceParent.dev || parent.ino !== cfg.workspaceParent.ino || parent.uid !== cfg.workspaceParent.uid ||
103
- (parent.mode & 4095) !== cfg.workspaceParent.mode) throw Error("parent");
104
- for (let dir = cfg.workspaceParent.path; ; dir = path.dirname(dir)) {
105
- try { await io.lstat(path.join(dir, ".git")); throw Error("git"); } catch (e) { if (e.code !== "ENOENT") throw e; }
106
- if (dir === path.parse(dir).root) break;
107
- }
108
- await verifyArtifact(cfg.artifact, io, files, deadline, now); r.artifactMatchedBefore = true;
109
- workspace = await io.mkdtemp(path.join(cfg.workspaceParent.path, "preferences-work-")); await io.chmod(workspace, 0o700); owned = await files.directory(workspace);
110
- if (!permission.live || dependencies.signal?.aborted || now() >= Math.min(deadline, permission.expiresAt) - limits.graceMs - limits.confirmationMs) throw Error("pre-start");
111
- const stream = createManagedPreferencesStreamReader(prefSchema, cfg.expectedSource);
112
- const env = { HOME: home, TMPDIR: workspace, PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C" };
113
- r.spawnAttempts = 1; r.terminationConfirmed = false;
114
- let child;
115
- try { child = spawn(cfg.artifact.path, [], { shell: false, detached: true, cwd: workspace, env, stdio: ["ignore", "pipe", "pipe"] }); }
116
- catch { r.terminationConfirmed = true; add("helper-spawn-failed"); throw Error("spawn"); }
117
- await new Promise(resolve => {
118
- let done = false, stopped = false, stoppedAt = null, forced = false, gone = false, failedSpawn = false, pid = null;
119
- let exited = false, closed = false, outClosed = false, errClosed = false, exitCode = null, timer, hard;
120
- const send = signal => {
121
- if (pid === null || gone) return;
122
- try { kill(-pid, signal); } catch (e) { if (e.code === "ESRCH") gone = true; else add("helper-signal-unconfirmed"); }
123
- };
124
- const alive = () => {
125
- if (gone || failedSpawn) return false;
126
- if (pid === null) return true;
127
- try { kill(-pid, 0); return true; } catch (e) { if (e.code === "ESRCH") { gone = true; return false; } add("helper-group-unconfirmed"); return true; }
128
- };
129
- const stop = (code, state = "failed", decoderCode = "preferences-transport-error") => {
130
- if (done) return; add(code);
131
- if (stopped) return;
132
- stopped = true; stoppedAt = now(); r.state = state; stream.abort(decoderCode); send("SIGTERM");
133
- };
134
- const finish = uncertain => {
135
- if (done) return; done = true; clearInterval(timer); clearTimeout(hard); dependencies.signal?.removeEventListener("abort", abort);
136
- r.terminationConfirmed = failedSpawn || exited && closed && outClosed && errClosed && gone;
137
- if (uncertain || !r.terminationConfirmed || now() > deadline) { r.state = "indeterminate"; add("helper-termination-unconfirmed"); stream.abort("preferences-transport-unconfirmed"); }
138
- else if (failedSpawn) r.state = "failed";
139
- else if (!stopped) {
140
- const projection = stream.finish(exitCode);
141
- if (projection.state === "invalid") { r.state = "failed"; add("helper-protocol-invalid"); }
142
- else { r.projection = projection; r.state = projection.state === "helper-failed" ? "helper-failed" : "completed"; }
143
- }
144
- if (stopped || uncertain || failedSpawn) stream.finish(null);
145
- child.stdout.destroy(); child.stderr.destroy(); resolve();
146
- };
147
- const poll = () => {
148
- if (done) return;
149
- if (!permission.live || now() >= permission.expiresAt) stop("helper-permission-revoked", "canceled");
150
- if (now() >= deadline - limits.graceMs - limits.confirmationMs && !stopped) stop("helper-deadline", "timed-out", "preferences-transport-timeout");
151
- if (stopped && !forced && now() - stoppedAt >= limits.graceMs) { forced = true; send("SIGKILL"); }
152
- const live = alive();
153
- if (exited && closed && outClosed && errClosed && !live) finish(false);
154
- else if (exited && live && !stopped) stop("helper-descendants-unconfirmed");
155
- if (failedSpawn && closed) finish(false);
156
- if (!done && stopped && forced && now() - stoppedAt >= limits.graceMs + limits.confirmationMs) finish(true);
157
- };
158
- const abort = () => stop("helper-canceled", "canceled");
159
- child.on("spawn", () => {
160
- if (!Number.isSafeInteger(child.pid) || child.pid <= 1) { stop("helper-pid-unavailable"); return; }
161
- pid = child.pid;
162
- if (done) { send("SIGKILL"); return; }
163
- r.helperStarted = true; if (stopped) send("SIGTERM");
164
- });
165
- child.on("error", () => { if (done) return; if (!r.helperStarted) { failedSpawn = true; add("helper-spawn-failed"); } else stop("helper-process-error"); });
166
- child.on("exit", code => { exited = true; exitCode = code; poll(); }); child.on("close", () => { closed = true; poll(); });
167
- child.stdout.on("close", () => { outClosed = true; poll(); }); child.stderr.on("close", () => { errClosed = true; poll(); });
168
- child.stdout.on("error", () => stop("helper-stream-error")); child.stderr.on("error", () => stop("helper-stream-error"));
169
- child.stdout.on("data", chunk => {
170
- if (done || stopped) return;
171
- try {
172
- r.stdoutBytes += chunkLength(chunk);
173
- if (r.stdoutBytes > limits.maxOutputBytes) stop("helper-output-limit", "failed", "preferences-transport-overflow");
174
- else if (!stream.push(copyBytes(chunk, limits.maxOutputBytes))) stop("helper-output-invalid");
175
- } catch { stop("helper-output-invalid"); }
176
- });
177
- child.stderr.on("data", chunk => {
178
- if (done || stopped) return;
179
- try { const size = chunkLength(chunk); r.stderrBytes += size; if (size) stop(r.stderrBytes > limits.maxErrorBytes ? "helper-stderr-limit" : "helper-stderr-not-empty"); }
180
- catch { stop("helper-stderr-invalid"); }
181
- });
182
- dependencies.signal?.addEventListener("abort", abort, { once: true }); if (dependencies.signal?.aborted) abort();
183
- timer = setInterval(poll, 10);
184
- hard = setTimeout(() => { send("SIGKILL"); poll(); if (!done) finish(true); }, Math.max(1, deadline - now()));
185
- });
186
- if (r.state === "completed" || r.state === "helper-failed") {
187
- await verifyArtifact(cfg.artifact, io, files, deadline, now); r.artifactMatchedAfter = true;
188
- if (!permission.live || now() >= permission.expiresAt) throw Error("revoked");
189
- r.helperExecutionVerified = true;
190
- }
191
- } catch {
192
- r.state = r.helperStarted ? "indeterminate" : r.spawnAttempts ? "failed" : "blocked";
193
- r.projection = null; r.helperExecutionVerified = false; add("helper-local-check-failed");
194
- } finally {
195
- if (claimed) revokeManagedPreferencesInvocationPermit(authorization);
196
- if (workspace) {
197
- if (r.terminationConfirmed) try { await files.directory(cfg.workspaceParent.path, parent); await files.directory(workspace, owned); await io.rmdir(workspace); }
198
- catch { r.state = "indeterminate"; r.cleanupRequired = true; add("helper-workspace-cleanup-required"); }
199
- else { r.cleanupRequired = true; add("helper-workspace-retained"); }
200
- }
201
- r.elapsedMs = Math.max(0, Math.ceil(now() - began));
202
- if (r.elapsedMs > limits.totalTimeoutMs) { r.state = "indeterminate"; add("helper-deadline"); }
203
- if (!["completed", "helper-failed"].includes(r.state)) { r.projection = null; r.helperExecutionVerified = false; }
204
- if (!r.reasons.length) add(r.state === "completed" ? "helper-completed" : "helper-failed");
205
- r.reasons.sort(); if (!validReport(r)) throw Error("Managed-preferences invocation report invariant failed");
206
- }
207
- return r;
208
- } });
209
- }
@@ -1,78 +0,0 @@
1
- import Ajv2020 from "ajv/dist/2020.js";
2
- import { types } from "node:util";
3
- import { copyInertJson, copyBytes, decode, parseEventJson, fail } from "./client-output-json.js";
4
-
5
- export const PREFERENCES_SCHEMA_ID = "https://agent-toolkit.local/schemas/agent-client-managed-preferences.schema.json";
6
- export const PREFERENCE_KEYS = Object.freeze(["hooks", "policyHelper", "apiKeyHelper", "env", "managedMcpServers", "disableAllHooks"]);
7
- const transportReasons = Object.freeze(["preferences-transport-timeout", "preferences-transport-overflow", "preferences-transport-unconfirmed", "preferences-transport-changed-artifact", "preferences-transport-error"]);
8
- function strictJson(input) {
9
- if (types.isProxy(input)) fail("preferences-invalid-output");
10
- const d = typeof input === "string" || types.isUint8Array(input)
11
- ? parseEventJson(decode(copyBytes(input, 32768))) : copyInertJson(input);
12
- return copyInertJson(parseEventJson(decode(copyBytes(JSON.stringify(d), 32768))));
13
- }
14
- const report = reason => ({ scope: "partial-preference-observation", state: "invalid", decision: "no-native-start",
15
- sourceClaim: null, fields: [], reasons: [reason], helperExecutionVerified: false, preferencesQueriedVerified: false,
16
- runtimeReady: false, verifiedAdmission: false, effectiveIsolationVerified: false, externalBillingVerified: false });
17
-
18
- /** This decoder validates protocol claims; it does not launch or authenticate a helper. */
19
- export function createManagedPreferencesReader(schema, expectedSource) {
20
- let valid;
21
- try {
22
- const s = copyInertJson(schema);
23
- if (s.$id !== PREFERENCES_SCHEMA_ID || JSON.stringify(s.$defs.field.properties.name.enum) !== JSON.stringify(PREFERENCE_KEYS) ||
24
- typeof expectedSource !== "string" || !["synthetic", "core-foundation-claim"].includes(expectedSource)) throw Error();
25
- const ajv = new Ajv2020({ strict: true, allErrors: true }); ajv.addSchema(s);
26
- valid = Object.fromEntries(["wire", "report"].map(n => [n, ajv.compile({ $ref: `${PREFERENCES_SCHEMA_ID}#/$defs/${n}` })]));
27
- } catch { throw Error("Invalid managed-preferences schema or source"); }
28
- const checked = r => { if (!valid.report(r)) throw Error("Managed-preferences report invariant failed"); return r; };
29
- return (input, exitCode) => {
30
- let r = report("preferences-invalid-output");
31
- try {
32
- const d = strictJson(input); if (!valid.wire(d)) fail("preferences-invalid-output");
33
- if (d.source !== expectedSource) return checked(report("preferences-source-mismatch"));
34
- if (!Number.isSafeInteger(exitCode) || exitCode !== (d.status === "complete" ? 0 : 1)) return checked(report("preferences-exit-mismatch"));
35
- if (d.status === "failed") { r.state = "helper-failed"; r.sourceClaim = d.source; r.reasons = [d.code]; }
36
- else {
37
- if (new Set(d.fields.map(f => f.name)).size !== 6) fail("preferences-invalid-output");
38
- r.state = "partial-observation"; r.sourceClaim = d.source;
39
- r.fields = PREFERENCE_KEYS.map(name => ({ ...d.fields.find(f => f.name === name) }));
40
- r.reasons = ["preferences-observation-partial"];
41
- if (r.fields.some(f => f.forced === "unknown")) r.reasons.push("preferences-force-unknown");
42
- if (r.fields.some(f => f.type === "not-found-by-api" && f.forced === "forced")) r.reasons.push("preferences-nonatomic-observation");
43
- r.reasons.sort();
44
- }
45
- } catch { r = report("preferences-invalid-output"); }
46
- return checked(r);
47
- };
48
- }
49
-
50
- /** Closed, bounded stdout accumulator. No provisional fields, native IO, or timers. */
51
- export function createManagedPreferencesStreamReader(schema, expectedSource) {
52
- const read = createManagedPreferencesReader(schema, expectedSource);
53
- let buffer = Buffer.alloc(32768), bytes = 0, closed = false, error = null;
54
- const discard = reason => { buffer = null; bytes = 0; error = reason; };
55
- return Object.freeze({
56
- push(chunk) {
57
- if (closed) { discard("preferences-stream-closed"); return false; }
58
- if (error) return false;
59
- try {
60
- const b = copyBytes(chunk, 32768);
61
- if (bytes + b.length > 32768) { discard("preferences-transport-overflow"); return false; }
62
- Uint8Array.prototype.set.call(buffer, b, bytes); bytes += b.length; return true;
63
- } catch { discard("preferences-invalid-output"); return false; }
64
- },
65
- abort(reason) {
66
- if (closed) { discard("preferences-stream-closed"); return false; }
67
- discard(typeof reason === "string" && transportReasons.includes(reason) ? reason : "preferences-transport-error");
68
- return false;
69
- },
70
- finish(exitCode) {
71
- if (closed) return report("preferences-stream-closed");
72
- closed = true;
73
- if (error) { buffer = null; return report(error); }
74
- const result = read(buffer.subarray(0, bytes), exitCode); buffer = null; bytes = 0;
75
- return result;
76
- }
77
- });
78
- }
@@ -1,134 +0,0 @@
1
- import { supportsDiagnosticHost } from "./client-local-platform.js";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import { spawn as nativeSpawn } from "node:child_process";
5
- import { types } from "node:util";
6
- import Ajv2020 from "ajv/dist/2020.js";
7
- import { hash } from "./client-runtime-core.js";
8
- import { createStoreFiles } from "./client-runtime-store-files.js";
9
- import { copyInertJson } from "./client-output-json.js";
10
- import { createNativePreflightEvaluator, createNativeAccessExtractor, strictPreflightJson } from "./client-native-preflight.js";
11
- import { verifyPreflightCandidate, absolutePhysicalName } from "./client-native-preflight-files.js";
12
-
13
- const permits = new WeakMap(), monoMs = () => Number(process.hrtime.bigint() / 1000000n);
14
- export const nativeAccessScope = cfg => hash({ candidate: cfg.candidate, recipe: ["auth", "status"], limits: cfg.limits, environmentProfile: "native-access-minimal-v1" });
15
- // Trusted orchestration only; hashes/JSON never create human approval themselves.
16
- export function createNativeAccessPermit(cfg, input) {
17
- const h = Object.freeze(Object.create(null)); permits.set(h, { binding: hash({ cfg: copyInertJson(cfg), input: strictPreflightJson(input) }), used: false, live: true }); return h;
18
- }
19
- export function revokeNativeAccessPermit(h) { const p = permits.get(h); if (p) p.live = false; }
20
-
21
- export function createNativeAccessCollector(schema, candidateSchema, configuration, authorization, dependencies = {}) {
22
- const platformAdmitted = supportsDiagnosticHost(process.platform, process.arch, dependencies);
23
- const cfg = copyInertJson(configuration), cs = copyInertJson(candidateSchema);
24
- if (cs.$id !== "https://agent-toolkit.local/schemas/agent-client-native-diagnostics.schema.json") throw Error("Invalid candidate schema");
25
- const ajv = new Ajv2020({ strict: true }); ajv.addSchema(cs);
26
- ajv.addFormat("date-time", { type: "string", validate: v => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(v) && Number.isFinite(Date.parse(v)) && new Date(v).toISOString() === v.replace(/Z$/, ".000Z") });
27
- const ps = copyInertJson(schema); ajv.addSchema(ps);
28
- const reportValid = ajv.compile({ $ref: ps.$id + "#/$defs/accessReport" });
29
- const pinValid = ajv.compile({ $ref: cs.$id + "#/$defs/pin" });
30
- const l = cfg.limits;
31
- if (Object.keys(cfg).sort().join() !== "candidate,limits,workspaceParent" || !pinValid(cfg.candidate) ||
32
- ![cfg.workspaceParent, cfg.candidate.entryPath, cfg.candidate.artifactPath].every(absolutePhysicalName) ||
33
- Object.keys(l).sort().join() !== "confirmationMs,graceMs,maxErrorBytes,maxOutputBytes,timeoutMs,totalTimeoutMs" ||
34
- Object.values(l).some(v => !Number.isSafeInteger(v) || v < 1) || l.timeoutMs > 15000 || l.totalTimeoutMs > 90000 ||
35
- l.timeoutMs > l.totalTimeoutMs || l.graceMs > 1000 || l.confirmationMs > 1000 || l.graceMs + l.confirmationMs >= l.timeoutMs ||
36
- l.maxOutputBytes > 32768 || l.maxErrorBytes > 32768) throw Error("Invalid access configuration");
37
- const policy = { expectedScopeSha256: nativeAccessScope(cfg), maxEvidenceAgeSeconds: 3600, revokedReferences: dependencies.revokedReferences ?? [] };
38
- const evaluate = createNativePreflightEvaluator(schema, policy), extract = createNativeAccessExtractor(schema);
39
- const spawn = dependencies.spawn ?? nativeSpawn, kill = dependencies.kill ?? process.kill.bind(process);
40
- const mono = dependencies.monotonic ?? monoMs, clock = dependencies.clock ?? Date.now;
41
- const io = { ...fs, ...dependencies.io }, files = createStoreFiles(dependencies.io); let invoked = false;
42
- return Object.freeze({ async run(input) {
43
- const began = mono(), deadline = began + l.totalTimeoutMs;
44
- const r = { scope: "native-access-only", state: "blocked", nativeExecuted: false, spawnAttempts: 0,
45
- inferenceRequested: false, actualModelCalls: null, runtimeReady: false, verifiedAdmission: false,
46
- externalBillingVerified: false, remoteCancellationVerified: false, terminationConfirmed: true,
47
- stdoutBytes: 0, stderrBytes: 0, elapsedMs: 0, preflight: null, reasons: [] };
48
- let workspace, owned, parent, claimed = false, auth = null;
49
- try {
50
- if (invoked) throw Error("permission"); invoked = true;
51
- const d = strictPreflightJson(input), p = !types.isProxy(authorization) && permits.get(authorization);
52
- if (!p || !p.live || p.used || p.binding !== hash({ cfg, input: d })) throw Error("permission");
53
- p.used = true; claimed = true;
54
- if (!platformAdmitted) throw Error("platform");
55
- const current = new Date(clock()).toISOString().replace(/\.\d{3}Z$/, "Z");
56
- r.preflight = evaluate({ ...d, now: current });
57
- if (!r.preflight.queryEligible) { r.reasons = ["access-controls-insufficient"]; return { report: r, auth }; }
58
- await verifyPreflightCandidate(cfg.candidate, { io: dependencies.io, deadline, monotonic: mono });
59
- if (/(CloudStorage|Mobile Documents|Dropbox|OneDrive|iCloud)/i.test(cfg.workspaceParent)) throw Error("parent");
60
- parent = await files.directory(cfg.workspaceParent);
61
- if (parent.dev !== cfg.candidate.expectedDev || parent.uid !== cfg.candidate.expectedUid) throw Error("parent");
62
- for (let dir = cfg.workspaceParent; dir !== path.parse(dir).root; dir = path.dirname(dir)) {
63
- try { await io.lstat(path.join(dir, ".git")); throw Error("git"); } catch (e) { if (e.code !== "ENOENT") throw e; }
64
- }
65
- workspace = await io.mkdtemp(path.join(cfg.workspaceParent, "access-work-")); await io.chmod(workspace, 0o700); owned = await files.directory(workspace);
66
- if (!p.live || dependencies.signal?.aborted || mono() >= deadline - l.graceMs - l.confirmationMs) throw Error("deadline");
67
- const env = { HOME: process.env.HOME, TMPDIR: workspace, PATH: "/usr/bin:/bin:/usr/sbin:/sbin", LANG: "C", LC_ALL: "C",
68
- DISABLE_UPDATES: "1", DISABLE_AUTOUPDATER: "1", CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1", ENABLE_CLAUDEAI_MCP_SERVERS: "false" };
69
- if (!absolutePhysicalName(env.HOME)) throw Error("home");
70
- const end = Math.min(deadline, mono() + l.timeoutMs); r.spawnAttempts = 1; r.terminationConfirmed = false;
71
- let child;
72
- try { child = spawn(cfg.candidate.artifactPath, ["auth", "status"], { shell: false, detached: true, cwd: workspace, env, stdio: ["ignore", "pipe", "pipe"] }); }
73
- catch { r.terminationConfirmed = true; throw Error("spawn-failed"); }
74
- let decoded = "";
75
- await new Promise(resolve => {
76
- const out = new TextDecoder("utf-8", { fatal: true }), err = new TextDecoder("utf-8", { fatal: true });
77
- let done = false, canceled = false, at = null, forced = false, gone = false, failedSpawn = false;
78
- let exited = false, closed = false, outClosed = false, errClosed = false, exitCode = null, timer, hard;
79
- const add = c => { if (!r.reasons.includes(c)) r.reasons.push(c); };
80
- const send = sig => { if (!r.nativeExecuted || gone) return; try { kill(-child.pid, sig); } catch (e) { if (e.code === "ESRCH") gone = true; else add("access-signal-unconfirmed"); } };
81
- const alive = () => { if (gone || failedSpawn) return false; if (!r.nativeExecuted) return true; try { kill(-child.pid, 0); return true; } catch (e) { if (e.code === "ESRCH") { gone = true; return false; } add("access-group-unconfirmed"); return true; } };
82
- const stop = (c, state = "failed") => { if (done) return; add(c); if (canceled) return; canceled = true; at = mono(); r.state = state; send("SIGTERM"); };
83
- const finish = uncertain => {
84
- if (done) return; done = true; clearInterval(timer); clearTimeout(hard); dependencies.signal?.removeEventListener("abort", abort);
85
- r.terminationConfirmed = failedSpawn || exited && closed && outClosed && errClosed && gone;
86
- if (uncertain || !r.terminationConfirmed || mono() > end) { r.state = "indeterminate"; add("access-termination-unconfirmed"); }
87
- else if (failedSpawn) r.state = "failed";
88
- else if (!canceled) {
89
- try { if (exitCode !== 0) throw Error("exit"); decoded += out.decode(); err.decode(); auth = extract(decoded); r.state = "completed"; }
90
- catch { r.state = "failed"; add("access-response-invalid"); auth = null; }
91
- }
92
- decoded = ""; child.stdout.destroy(); child.stderr.destroy(); resolve();
93
- };
94
- const poll = () => {
95
- if (done) return;
96
- if (mono() >= end - l.graceMs - l.confirmationMs && !canceled) stop("access-deadline", "timed-out");
97
- if (canceled && !forced && mono() - at >= l.graceMs) { forced = true; send("SIGKILL"); }
98
- const live = alive();
99
- if (exited && closed && outClosed && errClosed && !live) finish(false);
100
- else if (exited && live && !canceled) stop("access-descendants-unconfirmed");
101
- if (failedSpawn && closed) finish(false);
102
- };
103
- const abort = () => stop("access-canceled", "canceled");
104
- child.on("spawn", () => { r.nativeExecuted = true; if (done) send("SIGKILL"); else if (canceled) send("SIGTERM"); });
105
- child.on("error", () => { if (!r.nativeExecuted) { failedSpawn = true; add("access-spawn-failed"); } else stop("access-process-error"); });
106
- child.on("exit", code => { exited = true; exitCode = code; poll(); }); child.on("close", () => { closed = true; poll(); });
107
- child.stdout.on("close", () => { outClosed = true; poll(); }); child.stderr.on("close", () => { errClosed = true; poll(); });
108
- child.stdout.on("error", () => stop("access-process-error")); child.stderr.on("error", () => stop("access-process-error"));
109
- child.stdout.on("data", b => { if (done || canceled) return; r.stdoutBytes += b.length; if (r.stdoutBytes > l.maxOutputBytes) stop("access-output-limit"); else try { decoded += out.decode(b, { stream: true }); } catch { stop("access-utf8-invalid"); } });
110
- child.stderr.on("data", b => { if (done || canceled) return; r.stderrBytes += b.length; if (r.stderrBytes > l.maxErrorBytes) stop("access-stderr-limit"); else try { err.decode(b, { stream: true }); } catch { stop("access-utf8-invalid"); } });
111
- dependencies.signal?.addEventListener("abort", abort, { once: true }); if (dependencies.signal?.aborted) abort();
112
- timer = setInterval(poll, 10); hard = setTimeout(() => { send("SIGKILL"); poll(); if (!done) finish(true); }, Math.max(1, end - mono()));
113
- });
114
- if (r.state === "completed") {
115
- await verifyPreflightCandidate(cfg.candidate, { io: dependencies.io, deadline, monotonic: mono });
116
- const observedAt = new Date(clock()).toISOString().replace(/\.\d{3}Z$/, "Z");
117
- r.preflight = evaluate({ ...d, now: observedAt, access: { data: auth,
118
- assessment: { source: "locally-observed", referenceId: "native-access-observation", checkedAt: observedAt, scopeSha256: policy.expectedScopeSha256 } } });
119
- if (r.preflight.state === "blocked") { r.state = "blocked"; r.reasons.push("access-preflight-incompatible"); }
120
- }
121
- if (!r.reasons.length) r.reasons = ["access-completed"];
122
- } catch { auth = null; r.state = r.nativeExecuted ? "indeterminate" : "blocked"; r.reasons = ["access-local-check-failed"]; }
123
- finally {
124
- if (claimed) revokeNativeAccessPermit(authorization);
125
- if (workspace && r.terminationConfirmed) try { await files.directory(cfg.workspaceParent, parent); await files.directory(workspace, owned); await io.rmdir(workspace); }
126
- catch { r.state = "indeterminate"; r.reasons.push("access-workspace-cleanup-required"); }
127
- r.elapsedMs = Math.max(0, Math.ceil(mono() - began));
128
- if (r.elapsedMs > l.totalTimeoutMs) { r.state = "indeterminate"; r.reasons.push("access-deadline"); }
129
- r.reasons = [...new Set(r.reasons)].sort();
130
- if (!reportValid(r)) throw Error("Access report invariant failed");
131
- }
132
- return { report: r, auth }; // auth is a private projection, never raw stdout.
133
- } });
134
- }