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.
- package/README.md +13 -6
- package/assets/runtime/package-lock.json +415 -6
- package/bench/casos/arquitectura/alta-usuarios/base/controladores/usuarios.js +16 -0
- package/bench/casos/arquitectura/alta-usuarios/base/db.js +14 -0
- package/bench/casos/arquitectura/alta-usuarios/base/docs/adr/0003-capas.md +15 -0
- package/bench/casos/arquitectura/alta-usuarios/base/errores.js +3 -0
- package/bench/casos/arquitectura/alta-usuarios/base/repositorios/usuarios.js +14 -0
- package/bench/casos/arquitectura/alta-usuarios/base/servicios/usuarios.js +20 -0
- package/bench/casos/arquitectura/alta-usuarios/cambio/controladores/usuarios.js +47 -0
- package/bench/casos/arquitectura/alta-usuarios/cambio/repositorios/usuarios.js +21 -0
- package/bench/casos/arquitectura/alta-usuarios/cambio/servicios/perfil.js +14 -0
- package/bench/casos/arquitectura/alta-usuarios/esperado.json +53 -0
- package/bench/casos/arquitectura/pedidos-facturacion/base/docs/adr/0001-capas.md +18 -0
- package/bench/casos/arquitectura/pedidos-facturacion/base/src/aplicacion/confirmar.ts +8 -0
- package/bench/casos/arquitectura/pedidos-facturacion/base/src/dominio/pedido.ts +15 -0
- package/bench/casos/arquitectura/pedidos-facturacion/base/src/dominio/puertos.ts +6 -0
- package/bench/casos/arquitectura/pedidos-facturacion/base/src/infra/db.ts +14 -0
- package/bench/casos/arquitectura/pedidos-facturacion/base/src/main.ts +9 -0
- package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/aplicacion/facturar.ts +19 -0
- package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/dominio/informe.ts +7 -0
- package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/dominio/pedido.ts +21 -0
- package/bench/casos/arquitectura/pedidos-facturacion/cambio/src/infra/db.ts +22 -0
- package/bench/casos/arquitectura/pedidos-facturacion/esperado.json +53 -0
- package/bench/casos/arquitectura/resumen-cliente/base/docs/adr/0001-capas.md +18 -0
- package/bench/casos/arquitectura/resumen-cliente/base/src/aplicacion/confirmar.ts +8 -0
- package/bench/casos/arquitectura/resumen-cliente/base/src/dominio/pedido.ts +15 -0
- package/bench/casos/arquitectura/resumen-cliente/base/src/dominio/puertos.ts +6 -0
- package/bench/casos/arquitectura/resumen-cliente/base/src/infra/db.ts +14 -0
- package/bench/casos/arquitectura/resumen-cliente/base/src/main.ts +9 -0
- package/bench/casos/arquitectura/resumen-cliente/cambio/src/aplicacion/resumen.ts +6 -0
- package/bench/casos/arquitectura/resumen-cliente/cambio/src/dominio/pedido.ts +33 -0
- package/bench/casos/arquitectura/resumen-cliente/cambio/src/dominio/puertos.ts +7 -0
- package/bench/casos/arquitectura/resumen-cliente/cambio/src/infra/db.ts +18 -0
- package/bench/casos/arquitectura/resumen-cliente/cambio/src/main.ts +14 -0
- package/bench/casos/arquitectura/resumen-cliente/esperado.json +23 -0
- package/bench/casos/documentacion/comentario-obsoleto/base/README.md +18 -0
- package/bench/casos/documentacion/comentario-obsoleto/base/src/usuarios.ts +35 -0
- package/bench/casos/documentacion/comentario-obsoleto/cambio/src/copia.ts +8 -0
- package/bench/casos/documentacion/comentario-obsoleto/cambio/src/usuarios.ts +43 -0
- package/bench/casos/documentacion/comentario-obsoleto/esperado.json +42 -0
- package/bench/casos/documentacion/reportes-config/base/README.md +23 -0
- package/bench/casos/documentacion/reportes-config/base/src/cli.js +33 -0
- package/bench/casos/documentacion/reportes-config/base/src/config.js +15 -0
- package/bench/casos/documentacion/reportes-config/base/src/envio.js +23 -0
- package/bench/casos/documentacion/reportes-config/cambio/src/cli.js +35 -0
- package/bench/casos/documentacion/reportes-config/cambio/src/config.js +15 -0
- package/bench/casos/documentacion/reportes-config/esperado.json +42 -0
- package/bench/casos/documentacion/tiempo-espera/base/README.md +10 -0
- package/bench/casos/documentacion/tiempo-espera/base/src/config.js +8 -0
- package/bench/casos/documentacion/tiempo-espera/cambio/README.md +10 -0
- package/bench/casos/documentacion/tiempo-espera/cambio/src/config.js +8 -0
- package/bench/casos/documentacion/tiempo-espera/esperado.json +16 -0
- package/bench/casos/pruebas/calendario-laboral/base/src/fechas.js +3 -0
- package/bench/casos/pruebas/calendario-laboral/base/test/fechas.test.js +7 -0
- package/bench/casos/pruebas/calendario-laboral/cambio/src/fechas.js +37 -0
- package/bench/casos/pruebas/calendario-laboral/cambio/test/calendario.test.js +31 -0
- package/bench/casos/pruebas/calendario-laboral/esperado.json +49 -0
- package/bench/casos/pruebas/fin-de-semana/base/src/fechas.js +3 -0
- package/bench/casos/pruebas/fin-de-semana/base/test/fechas.test.js +7 -0
- package/bench/casos/pruebas/fin-de-semana/cambio/src/fechas.js +8 -0
- package/bench/casos/pruebas/fin-de-semana/cambio/test/fines-de-semana.test.js +13 -0
- package/bench/casos/pruebas/fin-de-semana/esperado.json +16 -0
- package/bench/casos/pruebas/precios-carrito/base/src/precio.ts +3 -0
- package/bench/casos/pruebas/precios-carrito/base/test/precio.test.js +11 -0
- package/bench/casos/pruebas/precios-carrito/cambio/src/precio.ts +34 -0
- package/bench/casos/pruebas/precios-carrito/cambio/test/precio.test.js +42 -0
- package/bench/casos/pruebas/precios-carrito/esperado.json +42 -0
- package/bench/casos/rendimiento/boletin-correo/base/src/correo.html +1 -0
- package/bench/casos/rendimiento/boletin-correo/base/src/plantilla.ts +11 -0
- package/bench/casos/rendimiento/boletin-correo/cambio/src/envios.ts +44 -0
- package/bench/casos/rendimiento/boletin-correo/cambio/src/plantilla.ts +10 -0
- package/bench/casos/rendimiento/boletin-correo/esperado.json +42 -0
- package/bench/casos/rendimiento/clientes-por-lote/base/src/informe.js +8 -0
- package/bench/casos/rendimiento/clientes-por-lote/cambio/src/informe.js +6 -0
- package/bench/casos/rendimiento/clientes-por-lote/esperado.json +14 -0
- package/bench/casos/rendimiento/informe-ventas/base/src/informe.js +6 -0
- package/bench/casos/rendimiento/informe-ventas/base/src/tasas.json +1 -0
- package/bench/casos/rendimiento/informe-ventas/cambio/src/informe.js +33 -0
- package/bench/casos/rendimiento/informe-ventas/cambio/src/tasas.js +7 -0
- package/bench/casos/rendimiento/informe-ventas/esperado.json +42 -0
- package/bench/casos/seguridad/inyeccion-orden/base/src/respaldo.ts +13 -0
- package/bench/casos/seguridad/inyeccion-orden/cambio/src/respaldo.ts +69 -0
- package/bench/casos/seguridad/inyeccion-orden/esperado.json +42 -0
- package/bench/casos/seguridad/limpio-validacion/base/servidor.js +11 -0
- package/bench/casos/seguridad/limpio-validacion/cambio/servidor.js +39 -0
- package/bench/casos/seguridad/limpio-validacion/esperado.json +14 -0
- package/bench/casos/seguridad/servidor-archivos/base/servidor.js +21 -0
- package/bench/casos/seguridad/servidor-archivos/cambio/servidor.js +79 -0
- package/bench/casos/seguridad/servidor-archivos/esperado.json +42 -0
- package/bin/nexakit-fabrica-mcp.js +12 -0
- package/dist/fabrica/banco/casos.js +304 -0
- package/dist/fabrica/banco/ejecutar.js +483 -0
- package/dist/fabrica/banco/medir.js +120 -0
- package/dist/fabrica/cli.js +737 -0
- package/dist/fabrica/conectores/antigravity.js +1040 -0
- package/dist/fabrica/conectores/codex.js +967 -0
- package/dist/fabrica/conectores/tipos.js +8 -0
- package/dist/fabrica/config.js +44 -0
- package/dist/fabrica/consolidar.js +218 -0
- package/dist/fabrica/decision.js +210 -0
- package/dist/fabrica/diff.js +247 -0
- package/dist/fabrica/disco.js +356 -0
- package/dist/fabrica/ejecutor.js +597 -0
- package/dist/fabrica/encargo/candado.js +274 -0
- package/dist/fabrica/encargo/ejecutar.js +827 -0
- package/dist/fabrica/encargo/evidencia.js +308 -0
- package/dist/fabrica/encargo/parche.js +146 -0
- package/dist/fabrica/encargo/worktree.js +394 -0
- package/dist/fabrica/enrutador.js +425 -0
- package/dist/fabrica/errores.js +14 -0
- package/dist/fabrica/esquemas.js +57 -0
- package/dist/fabrica/estaciones.js +75 -0
- package/dist/fabrica/evidencia.js +406 -0
- package/dist/fabrica/indice.js +1 -0
- package/dist/fabrica/jsonrpc.js +274 -0
- package/dist/fabrica/lecciones.js +363 -0
- package/dist/fabrica/mcp.js +376 -0
- package/dist/fabrica/preferencias.js +56 -0
- package/dist/fabrica/protocolos/codex/AbsolutePathBuf.js +2 -0
- package/dist/fabrica/protocolos/codex/ApplyPatchApprovalResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/ClientInfo.js +2 -0
- package/dist/fabrica/protocolos/codex/ExecCommandApprovalParams.js +2 -0
- package/dist/fabrica/protocolos/codex/ExecCommandApprovalResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/ExecPolicyAmendment.js +2 -0
- package/dist/fabrica/protocolos/codex/FunctionCallOutputBody.js +2 -0
- package/dist/fabrica/protocolos/codex/FunctionCallOutputContentItem.js +2 -0
- package/dist/fabrica/protocolos/codex/ImageDetail.js +2 -0
- package/dist/fabrica/protocolos/codex/InitializeCapabilities.js +2 -0
- package/dist/fabrica/protocolos/codex/InitializeParams.js +2 -0
- package/dist/fabrica/protocolos/codex/InitializeResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/InputModality.js +2 -0
- package/dist/fabrica/protocolos/codex/LegacyAppPathString.js +2 -0
- package/dist/fabrica/protocolos/codex/NetworkPolicyAmendment.js +2 -0
- package/dist/fabrica/protocolos/codex/NetworkPolicyRuleAction.js +2 -0
- package/dist/fabrica/protocolos/codex/ParsedCommand.js +2 -0
- package/dist/fabrica/protocolos/codex/Personality.js +2 -0
- package/dist/fabrica/protocolos/codex/ReasoningEffort.js +2 -0
- package/dist/fabrica/protocolos/codex/ReasoningSummary.js +2 -0
- package/dist/fabrica/protocolos/codex/ReviewDecision.js +2 -0
- package/dist/fabrica/protocolos/codex/ThreadId.js +2 -0
- package/dist/fabrica/protocolos/codex/serde_json/JsonValue.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/AdditionalFileSystemPermissions.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/AdditionalNetworkPermissions.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ApprovalsReviewer.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/AskForApproval.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ByteRange.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/CommandAction.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/CommandExecutionApprovalDecision.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/CommandExecutionApprovalKind.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ConfigReadParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/CyberAccessProgram.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ExecPolicyAmendment.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/FileChangeApprovalDecision.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/FileChangeRequestApprovalResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/FileSystemAccessMode.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/FileSystemPath.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/FileSystemSandboxEntry.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/FileSystemSpecialPath.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/GrantedPermissionProfile.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ListMcpServerStatusParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/McpServerElicitationAction.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/McpServerElicitationRequestResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/McpServerStatusDetail.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/Model.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ModelAccessPrograms.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ModelAvailabilityNux.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ModelListParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ModelListResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ModelServiceTier.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ModelUpgradeInfo.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/MultiAgentVersion.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/NetworkAccess.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/NetworkApprovalContext.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/NetworkApprovalProtocol.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/NetworkPolicyAmendment.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/NetworkPolicyRuleAction.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/PermissionGrantScope.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/PermissionsRequestApprovalResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ReasoningEffortOption.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/SandboxMode.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/SandboxPolicy.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/TextElement.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ThreadSource.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ThreadStartParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ThreadStartSource.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ThreadTokenUsage.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ThreadTokenUsageUpdatedNotification.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/TokenUsageBreakdown.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ToolRequestUserInputAnswer.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/ToolRequestUserInputResponse.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/TurnInterruptParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/TurnStartParams.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/TurnToolOutput.js +2 -0
- package/dist/fabrica/protocolos/codex/v2/UserInput.js +2 -0
- package/dist/fabrica/rastro.js +487 -0
- package/dist/fabrica/sesion.js +230 -0
- package/dist/fabrica/tabla-modelos.json +29 -0
- package/dist/fabrica/veredictos.js +327 -0
- package/package.json +16 -8
- package/plugins/huellas.json +6 -6
- package/plugins/nexakit-lecciones/.claude-plugin/plugin.json +1 -1
- package/plugins/nexakit-lecciones/README.md +6 -5
- package/plugins/nexakit-lecciones/hooks/lecciones.js +29 -5
- package/plugins/nexakit-lecciones/hooks/register.js +7 -3
- package/plugins/nexakit-modelo/.claude-plugin/plugin.json +1 -1
- package/plugins/nexakit-modelo/hooks/barra.js +100 -4
- package/plugins/nexakit-modelo/hooks/decidir.js +2 -2
- package/plugins/nexakit-modelo/hooks/recomendar.js +1 -1
- package/plugins/nexakit-modelo/hooks/register.js +122 -7
- package/plugins/nexakit-modelo/tests/register.test.ts +301 -0
- package/plugins/niveles/.claude-plugin/plugin.json +1 -1
- package/plugins/niveles/agents/cazador-de-flakes.md +1 -0
- package/plugins/niveles/agents/cierre-de-memoria.md +1 -0
- package/plugins/niveles/agents/investigador.md +1 -0
- package/plugins/niveles/agents/nivel-alto.md +1 -0
- package/plugins/niveles/agents/nivel-exigente.md +1 -0
- package/plugins/niveles/agents/nivel-ligero.md +1 -0
- package/plugins/niveles/agents/nivel-normal.md +1 -0
- package/plugins/niveles/agents/revisor-de-calidad.md +1 -0
- package/plugins/niveles/agents/sincronizador-docs.md +1 -0
- package/plugins/niveles/agents/subir-al-repo.md +1 -0
- package/skills/elegir-modelo/SKILL.md +4 -3
- package/skills/elegir-modelo/modelos.mjs +100 -1
- package/skills/fabrica/SKILL.md +55 -0
- package/skills/gemini/SKILL.md +2 -3
- package/skills/quality-gate/SKILL.md +2 -2
- package/src/agent-models.js +6 -4
- package/src/antigravity-barra.js +64 -12
- package/src/antigravity-command.js +4 -2
- package/src/antigravity-models.js +61 -0
- package/src/antigravity-pre-tool.js +11 -3
- package/src/antigravity-recommendation.js +15 -9
- package/src/antigravity-setup.js +4 -31
- package/src/cli-executable.d.ts +11 -0
- package/src/codex-pre-tool.js +3 -3
- package/src/codex-recommendation.js +1 -2
- package/src/codex-setup.js +3 -20
- package/src/codex-team.js +31 -4
- package/src/fabrica/banco/casos.ts +315 -0
- package/src/fabrica/banco/ejecutar.ts +587 -0
- package/src/fabrica/banco/medir.ts +160 -0
- package/src/fabrica/cli.ts +781 -0
- package/src/fabrica/conectores/antigravity.ts +1090 -0
- package/src/fabrica/conectores/codex.ts +1013 -0
- package/src/fabrica/conectores/tipos.ts +54 -0
- package/src/fabrica/config.ts +43 -0
- package/src/fabrica/consolidar.ts +277 -0
- package/src/fabrica/decision.ts +285 -0
- package/src/fabrica/diff.ts +294 -0
- package/src/fabrica/disco.ts +380 -0
- package/src/fabrica/ejecutor.ts +716 -0
- package/src/fabrica/encargo/candado.ts +287 -0
- package/src/fabrica/encargo/ejecutar.ts +953 -0
- package/src/fabrica/encargo/evidencia.ts +301 -0
- package/src/fabrica/encargo/parche.ts +151 -0
- package/src/fabrica/encargo/worktree.ts +427 -0
- package/src/fabrica/enrutador.ts +494 -0
- package/src/fabrica/errores.ts +15 -0
- package/src/fabrica/esquemas.ts +92 -0
- package/src/fabrica/estaciones.ts +83 -0
- package/src/fabrica/evidencia.ts +445 -0
- package/src/fabrica/indice.ts +1 -0
- package/src/fabrica/jsonrpc.ts +314 -0
- package/src/fabrica/lecciones.ts +411 -0
- package/src/fabrica/mcp.ts +450 -0
- package/src/fabrica/preferencias.ts +66 -0
- package/src/fabrica/protocolos/codex/AbsolutePathBuf.ts +14 -0
- package/src/fabrica/protocolos/codex/ApplyPatchApprovalResponse.ts +6 -0
- package/src/fabrica/protocolos/codex/ClientInfo.ts +5 -0
- package/src/fabrica/protocolos/codex/ExecCommandApprovalParams.ts +16 -0
- package/src/fabrica/protocolos/codex/ExecCommandApprovalResponse.ts +6 -0
- package/src/fabrica/protocolos/codex/ExecPolicyAmendment.ts +12 -0
- package/src/fabrica/protocolos/codex/FunctionCallOutputBody.ts +6 -0
- package/src/fabrica/protocolos/codex/FunctionCallOutputContentItem.ts +10 -0
- package/src/fabrica/protocolos/codex/ImageDetail.ts +5 -0
- package/src/fabrica/protocolos/codex/InitializeCapabilities.ts +42 -0
- package/src/fabrica/protocolos/codex/InitializeParams.ts +7 -0
- package/src/fabrica/protocolos/codex/InitializeResponse.ts +20 -0
- package/src/fabrica/protocolos/codex/InputModality.ts +8 -0
- package/src/fabrica/protocolos/codex/LegacyAppPathString.ts +27 -0
- package/src/fabrica/protocolos/codex/NetworkPolicyAmendment.ts +6 -0
- package/src/fabrica/protocolos/codex/NetworkPolicyRuleAction.ts +5 -0
- package/src/fabrica/protocolos/codex/ParsedCommand.ts +12 -0
- package/src/fabrica/protocolos/codex/Personality.ts +8 -0
- package/src/fabrica/protocolos/codex/ReasoningEffort.ts +8 -0
- package/src/fabrica/protocolos/codex/ReasoningSummary.ts +10 -0
- package/src/fabrica/protocolos/codex/ReviewDecision.ts +10 -0
- package/src/fabrica/protocolos/codex/ThreadId.ts +10 -0
- package/src/fabrica/protocolos/codex/VERSION +1 -0
- package/src/fabrica/protocolos/codex/serde_json/JsonValue.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/AdditionalFileSystemPermissions.ts +15 -0
- package/src/fabrica/protocolos/codex/v2/AdditionalNetworkPermissions.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ApprovalsReviewer.ts +12 -0
- package/src/fabrica/protocolos/codex/v2/AskForApproval.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ByteRange.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/CommandAction.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/CommandExecutionApprovalDecision.ts +7 -0
- package/src/fabrica/protocolos/codex/v2/CommandExecutionApprovalKind.ts +8 -0
- package/src/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalParams.ts +51 -0
- package/src/fabrica/protocolos/codex/v2/CommandExecutionRequestApprovalResponse.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/ConfigReadParams.ts +11 -0
- package/src/fabrica/protocolos/codex/v2/CyberAccessProgram.ts +9 -0
- package/src/fabrica/protocolos/codex/v2/ExecPolicyAmendment.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/FileChangeApprovalDecision.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/FileChangeRequestApprovalResponse.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/FileSystemAccessMode.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/FileSystemPath.ts +7 -0
- package/src/fabrica/protocolos/codex/v2/FileSystemSandboxEntry.ts +7 -0
- package/src/fabrica/protocolos/codex/v2/FileSystemSpecialPath.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/GrantedPermissionProfile.ts +7 -0
- package/src/fabrica/protocolos/codex/v2/ListMcpServerStatusParams.ts +23 -0
- package/src/fabrica/protocolos/codex/v2/McpServerElicitationAction.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/McpServerElicitationRequestResponse.ts +17 -0
- package/src/fabrica/protocolos/codex/v2/McpServerStatusDetail.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/Model.ts +33 -0
- package/src/fabrica/protocolos/codex/v2/ModelAccessPrograms.ts +13 -0
- package/src/fabrica/protocolos/codex/v2/ModelAvailabilityNux.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ModelListParams.ts +17 -0
- package/src/fabrica/protocolos/codex/v2/ModelListResponse.ts +11 -0
- package/src/fabrica/protocolos/codex/v2/ModelServiceTier.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ModelUpgradeInfo.ts +9 -0
- package/src/fabrica/protocolos/codex/v2/MultiAgentVersion.ts +8 -0
- package/src/fabrica/protocolos/codex/v2/NetworkAccess.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/NetworkApprovalContext.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/NetworkApprovalProtocol.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/NetworkPolicyAmendment.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/NetworkPolicyRuleAction.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/PermissionGrantScope.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/PermissionsRequestApprovalResponse.ts +11 -0
- package/src/fabrica/protocolos/codex/v2/ReasoningEffortOption.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/SandboxMode.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/SandboxPolicy.ts +7 -0
- package/src/fabrica/protocolos/codex/v2/TextElement.ts +14 -0
- package/src/fabrica/protocolos/codex/v2/ThreadSource.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ThreadStartParams.ts +22 -0
- package/src/fabrica/protocolos/codex/v2/ThreadStartSource.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ThreadTokenUsage.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/ThreadTokenUsageUpdatedNotification.ts +6 -0
- package/src/fabrica/protocolos/codex/v2/TokenUsageBreakdown.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/ToolRequestUserInputAnswer.ts +8 -0
- package/src/fabrica/protocolos/codex/v2/ToolRequestUserInputResponse.ts +9 -0
- package/src/fabrica/protocolos/codex/v2/TurnInterruptParams.ts +5 -0
- package/src/fabrica/protocolos/codex/v2/TurnStartParams.ts +75 -0
- package/src/fabrica/protocolos/codex/v2/TurnToolOutput.ts +10 -0
- package/src/fabrica/protocolos/codex/v2/UserInput.ts +11 -0
- package/src/fabrica/rastro.ts +508 -0
- package/src/fabrica/sesion.ts +280 -0
- package/src/fabrica/tabla-modelos.json +29 -0
- package/src/fabrica/veredictos.ts +365 -0
- package/src/gemini-cli.js +15 -12
- package/src/gemini-tools.js +1 -1
- package/src/gemini-usage-store.js +32 -0
- package/src/instructions-block.js +69 -0
- package/src/lecciones-command.js +105 -4
- package/src/lecciones-instructions.js +178 -0
- package/src/legacy-repair.js +1 -1
- package/src/level-agents.js +5 -3
- package/src/memory-mcp-policy.js +1 -1
- package/src/missing-dependencies.js +5 -0
- package/src/model-command.d.ts +29 -0
- package/src/model-command.js +4 -27
- package/src/regla-ordenes-simples.d.ts +2 -0
- package/src/regla-ordenes-simples.js +4 -0
- package/src/review-instructions.js +69 -81
- package/src/safe-paths.js +38 -0
- package/src/setup-apply.js +24 -2
- package/src/setup-plan.js +57 -1
- package/src/setup-state.js +14 -0
- package/src/shell-quote.js +2 -0
- package/src/skill-recommendations.js +101 -28
- package/src/stable-command.js +2 -2
- package/src/stable-install.js +4 -2
- package/src/superpowers.js +0 -7
- package/src/task-document.js +59 -0
- package/src/terminal-text.js +2 -19
- package/src/toolkit-cli.js +63 -8
- package/src/toolkit-setup.js +192 -37
- package/templates/agent-team/README.md +7 -19
- package/bin/agent-task.js +0 -14
- package/bin/agent-toolkit-inbox.js +0 -14
- package/bin/agent-toolkit-mcp.js +0 -17
- package/schemas/agent-client-adapter.schema.json +0 -786
- package/schemas/agent-client-auth-diagnostic.schema.json +0 -801
- package/schemas/agent-client-isolated-variant.schema.json +0 -105
- package/schemas/agent-client-isolated-verification.schema.json +0 -99
- package/schemas/agent-client-managed-preferences-invocation.schema.json +0 -67
- package/schemas/agent-client-managed-preferences.schema.json +0 -63
- package/schemas/agent-client-native-diagnostics.schema.json +0 -85
- package/schemas/agent-client-native-evaluation.schema.json +0 -171
- package/schemas/agent-client-native-preflight.schema.json +0 -90
- package/schemas/agent-client-output.schema.json +0 -551
- package/schemas/agent-client-runtime-fixture.schema.json +0 -90
- package/schemas/agent-client-runtime-local.schema.json +0 -95
- package/schemas/agent-client-runtime.schema.json +0 -1288
- package/schemas/agent-client-selective-config.schema.json +0 -77
- package/schemas/agent-client-supervised-local.schema.json +0 -135
- package/schemas/agent-client-supervised.schema.json +0 -186
- package/schemas/agent-task-approvals.schema.json +0 -362
- package/schemas/agent-task-prepare.schema.json +0 -1324
- package/schemas/agent-task-verify.schema.json +0 -198
- package/schemas/task-workflow-plan-output.schema.json +0 -35
- package/skills/revisar/SKILL.md +0 -51
- package/src/claude-code-runner.js +0 -642
- package/src/client-adapter-plan.js +0 -271
- package/src/client-auth-diagnostic-parser.js +0 -211
- package/src/client-auth-diagnostic.js +0 -257
- package/src/client-isolated-variant.js +0 -106
- package/src/client-isolated-verification.js +0 -130
- package/src/client-local-platform.js +0 -14
- package/src/client-managed-preferences-invocation.js +0 -209
- package/src/client-managed-preferences.js +0 -78
- package/src/client-native-access.js +0 -134
- package/src/client-native-diagnostics.js +0 -253
- package/src/client-native-evaluation.js +0 -106
- package/src/client-native-preflight-files.js +0 -68
- package/src/client-native-preflight.js +0 -95
- package/src/client-output-parser.js +0 -278
- package/src/client-runtime-admission.js +0 -80
- package/src/client-runtime-coordinator.js +0 -70
- package/src/client-runtime-core.js +0 -92
- package/src/client-runtime-fixture-permit.js +0 -20
- package/src/client-runtime-fixture-protocol.js +0 -39
- package/src/client-runtime-state.js +0 -67
- package/src/client-runtime-store-files.js +0 -91
- package/src/client-runtime-store.js +0 -239
- package/src/client-runtime-supervisor.js +0 -146
- package/src/client-selective-config.js +0 -195
- package/src/client-selective-files.js +0 -126
- package/src/client-supervised-codes.js +0 -32
- package/src/client-supervised-contract.js +0 -52
- package/src/client-supervised-coordinator.js +0 -36
- package/src/client-supervised-permit.js +0 -20
- package/src/client-supervised-protocol.js +0 -37
- package/src/client-supervised-store.js +0 -167
- package/src/client-supervised-supervisor.js +0 -167
- package/src/client-supervised.js +0 -160
- package/src/codex-cli-runner.js +0 -358
- package/src/codex-delivery.js +0 -101
- package/src/memory-connection-artifacts.js +0 -192
- package/src/memory-connection-descriptor.js +0 -158
- package/src/memory-connection-diagnostic.js +0 -177
- package/src/memory-connection-files.js +0 -191
- package/src/memory-connection-manifest.js +0 -118
- package/src/memory-connection-package.js +0 -176
- package/src/memory-connection-plan.js +0 -217
- package/src/memory-connection-skill.js +0 -211
- package/src/memory-connection-toml.js +0 -153
- package/src/native/managed-preferences.c +0 -100
- package/src/native/managed-preferences.h +0 -17
- package/src/package-lock-path.js +0 -13
- package/src/peer-handoff.js +0 -27
- package/src/peer-inbox-cli.js +0 -211
- package/src/peer-review-mcp.js +0 -210
- package/src/peer-review-store.js +0 -532
- package/src/review-policy.js +0 -35
- package/src/revision-adapters.js +0 -158
- package/src/revision-context.js +0 -86
- package/src/revision-isolation.js +0 -222
- package/src/revision-process.js +0 -103
- package/src/revision-provenance.js +0 -89
- package/src/revision-snapshot.js +0 -120
- package/src/revision.js +0 -242
- package/src/runtime-fixtures/runtime-supervisor/child.cjs +0 -3
- package/src/runtime-fixtures/runtime-supervisor/fixture.cjs +0 -49
- package/src/runtime-fixtures/supervised/child.cjs +0 -3
- package/src/runtime-fixtures/supervised/fixture.cjs +0 -47
- package/src/task-approvals.js +0 -367
- package/src/task-cli.js +0 -79
- package/src/task-external-verifier.js +0 -584
- package/src/task-prepare-files.js +0 -115
- package/src/task-prepare.js +0 -180
- package/src/task-verify-cli.js +0 -67
- package/src/task-verify-files.js +0 -188
- package/src/task-verify.js +0 -118
- package/src/task-workflow-mcp.js +0 -544
- package/src/task-workflow-store.js +0 -254
- package/src/toolkit-commands-guide.js +0 -115
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
4
|
-
|
|
5
|
-
import { copyInertJson, copyBytes, decode, parseEventJson, ParseFailure, fail } from "./client-output-json.js";
|
|
6
|
-
|
|
7
|
-
const OUTPUT_ID = "https://agent-toolkit.local/schemas/agent-client-output.schema.json";
|
|
8
|
-
const FORMAT_ROUTES = {
|
|
9
|
-
"codex-jsonl-text-v1": ["openai", "codex-cli", "codex-native"],
|
|
10
|
-
"claude-jsonl-text-v1": ["anthropic", "claude-code", "claude-native"]
|
|
11
|
-
};
|
|
12
|
-
const emptyObservation = () => ({ value: null, verification: "unknown", match: "unknown", source: null, scope: null });
|
|
13
|
-
const emptyUsage = () => Object.fromEntries(["inputTokens", "outputTokens", "cacheReadTokens", "reasoningTokens", "totalTokens"].map(k => [k, null]));
|
|
14
|
-
class BlockedOutput extends ParseFailure {}
|
|
15
|
-
const block = (code) => { throw new BlockedOutput(code); };
|
|
16
|
-
|
|
17
|
-
/** Offline only. All records/capture metadata are caller-supplied declarations. */
|
|
18
|
-
export function createClientOutputParser(baseSchema, preferenceSchema, adapterSchema, outputSchema, config) {
|
|
19
|
-
const schemas = [baseSchema, preferenceSchema, adapterSchema, outputSchema].map(copyInertJson);
|
|
20
|
-
if (schemas[3].$id !== OUTPUT_ID) throw new Error("Unsupported output schema");
|
|
21
|
-
const ajv = new Ajv2020({ strict: true, allErrors: true });
|
|
22
|
-
ajv.addFormat("date-time", { type: "string", validate: isTimestamp });
|
|
23
|
-
schemas.forEach(s => ajv.addSchema(s));
|
|
24
|
-
const validateConfig = ajv.compile({ $ref: `${OUTPUT_ID}#/$defs/config` });
|
|
25
|
-
const validateMetadata = ajv.compile({ $ref: `${OUTPUT_ID}#/$defs/metadata` });
|
|
26
|
-
const validateReport = ajv.compile({ $ref: `${OUTPUT_ID}#/$defs/report` });
|
|
27
|
-
const configuration = copyInertJson(config);
|
|
28
|
-
if (!validateConfig(configuration)) throw new Error("Invalid output parser registry");
|
|
29
|
-
const keys = configuration.supportedClients.map(r => descriptorKey(r.descriptor));
|
|
30
|
-
if (new Set(keys).size !== keys.length || configuration.supportedClients.some(r => {
|
|
31
|
-
const [provider, client, variant] = FORMAT_ROUTES[r.formatId];
|
|
32
|
-
return r.descriptor.provider !== provider || r.descriptor.client !== client || r.descriptor.variant !== variant;
|
|
33
|
-
})) throw new Error("Inconsistent output parser registry");
|
|
34
|
-
|
|
35
|
-
function finish(report, state, reasons = []) {
|
|
36
|
-
report.state = state;
|
|
37
|
-
report.reasons = [...new Set([...report.reasons, ...reasons])].sort();
|
|
38
|
-
if (state !== "accepted") report.response = null;
|
|
39
|
-
if (!validateReport(report)) throw new Error("Output parser invariant failed");
|
|
40
|
-
return report;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return function parseClientOutput(metadata, stdout, stderr = "") {
|
|
44
|
-
const report = {
|
|
45
|
-
schemaVersion: "1.0.0", parserVersion: "1.0.0", state: "invalid", nativeState: "unknown",
|
|
46
|
-
executed: false, verifiedExecution: false, reviewRequired: true, client: null,
|
|
47
|
-
captureRef: null, identity: null, requested: null, response: null,
|
|
48
|
-
model: emptyObservation(), configuredModel: emptyObservation(), configuredEffort: emptyObservation(), effort: emptyObservation(),
|
|
49
|
-
usage: emptyUsage(), usageScope: null, durationSeconds: null, processObservation: null,
|
|
50
|
-
eventCount: 0, stderrBytes: 0, reasons: [],
|
|
51
|
-
audit: { planSha256: null, stdoutSha256: null, stderrSha256: null }
|
|
52
|
-
};
|
|
53
|
-
try {
|
|
54
|
-
const data = copyInertJson(metadata);
|
|
55
|
-
if (!validateMetadata(data)) fail("invalid-capture-metadata");
|
|
56
|
-
if (data.plan.state !== "prepared") block("plan-not-prepared");
|
|
57
|
-
const { plan } = data; const { intent } = plan; const { limits } = intent;
|
|
58
|
-
report.client = intent.client; report.identity = plan.identity; report.captureRef = data.captureRef;
|
|
59
|
-
report.requested = { model: intent.requestedModel, effort: intent.requestedEffort };
|
|
60
|
-
report.processObservation = data.processObservation ?? null;
|
|
61
|
-
if (data.processObservation?.exitCode !== null && data.processObservation?.exitCode !== undefined &&
|
|
62
|
-
data.processObservation?.signal !== null && data.processObservation?.signal !== undefined) fail("contradictory-process-observation");
|
|
63
|
-
report.audit.planSha256 = hash(canonicalJson(plan));
|
|
64
|
-
const registration = configuration.supportedClients.find(r => descriptorKey(r.descriptor) === descriptorKey(intent.client));
|
|
65
|
-
if (!registration) block("parser-client-version-not-admitted");
|
|
66
|
-
const bytes = copyBytes(stdout, limits.maxOutputBytes);
|
|
67
|
-
const errorBytes = copyBytes(stderr, limits.maxStderrBytes);
|
|
68
|
-
report.stderrBytes = errorBytes.length;
|
|
69
|
-
report.audit.stdoutSha256 = hash(bytes); report.audit.stderrSha256 = hash(errorBytes);
|
|
70
|
-
const text = decode(bytes); decode(errorBytes);
|
|
71
|
-
const stream = createStream(registration.formatId, report, limits);
|
|
72
|
-
let start = 0;
|
|
73
|
-
while (start < text.length) {
|
|
74
|
-
const newline = text.indexOf("\n", start); const end = newline === -1 ? text.length : newline;
|
|
75
|
-
let line = text.slice(start, end); if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
76
|
-
if (!line.trim()) fail("empty-event-line");
|
|
77
|
-
if (Buffer.byteLength(text.slice(start, end)) > limits.maxLineBytes) fail("event-line-byte-limit");
|
|
78
|
-
if (report.eventCount >= limits.maxEvents) fail("event-count-limit");
|
|
79
|
-
report.eventCount++;
|
|
80
|
-
stream.consume(parseEventJson(line)); start = end + 1;
|
|
81
|
-
}
|
|
82
|
-
if (!stream.terminal) return finish(report, "incomplete", ["missing-terminal"]);
|
|
83
|
-
if (!stream.settled()) return finish(report, "incomplete", ["unfinished-native-step"]);
|
|
84
|
-
if (report.nativeState !== "completed") return finish(report, "blocked", ["native-not-completed"]);
|
|
85
|
-
if (typeof stream.final !== "string" || !stream.final.trim()) block("missing-final-response");
|
|
86
|
-
if (Buffer.byteLength(stream.final) > limits.maxOutputBytes) block("response-byte-limit");
|
|
87
|
-
if (report.durationSeconds !== null && report.durationSeconds > limits.timeoutSeconds) block("native-duration-exceeds-plan");
|
|
88
|
-
const process = report.processObservation;
|
|
89
|
-
if (process?.signal) block("process-signaled");
|
|
90
|
-
if (process?.exitCode !== undefined && process.exitCode !== null && process.exitCode !== 0) block("process-nonzero-exit");
|
|
91
|
-
if (process?.elapsedSeconds !== undefined && process.elapsedSeconds !== null && process.elapsedSeconds > limits.timeoutSeconds) block("process-duration-exceeds-plan");
|
|
92
|
-
if (!process || process.exitCode === null) return finish(report, "incomplete", ["process-exit-unconfirmed"]);
|
|
93
|
-
report.response = stream.final;
|
|
94
|
-
return finish(report, "accepted", ["capture-only-review-required"]);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (!(error instanceof ParseFailure)) throw error;
|
|
97
|
-
return finish(report, error instanceof BlockedOutput ? "blocked" : "invalid", [error.code]);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function createStream(format, report, limits) {
|
|
103
|
-
let initialized = false; let terminal = false; let session = null; let final = null;
|
|
104
|
-
let turnStarted = false; let assistantId = null; let assistantText = null;
|
|
105
|
-
const items = new Map();
|
|
106
|
-
|
|
107
|
-
const bindSession = (id) => {
|
|
108
|
-
if (typeof id !== "string" || !id || id.length > 256) fail("invalid-native-session");
|
|
109
|
-
if (session !== null && session !== id) block("native-session-mismatch"); session = id;
|
|
110
|
-
};
|
|
111
|
-
const init = () => { if (initialized) fail("duplicate-native-init"); initialized = true; };
|
|
112
|
-
const ready = () => { if (!initialized) fail("native-event-before-init"); };
|
|
113
|
-
const ending = (state) => { ready(); terminal = true; report.nativeState = state; };
|
|
114
|
-
const configure = (e) => {
|
|
115
|
-
if (e.model !== undefined) observe(report.configuredModel, e.model, report.requested.model, "client-init", "configuration");
|
|
116
|
-
if (e.effort !== undefined && e.effort !== null) observe(report.configuredEffort, e.effort, report.requested.effort, "client-init", "configuration");
|
|
117
|
-
};
|
|
118
|
-
function consume(e) {
|
|
119
|
-
if (terminal) fail("event-after-terminal");
|
|
120
|
-
if (format === "codex-jsonl-text-v1") codex(e);
|
|
121
|
-
else claude(e);
|
|
122
|
-
}
|
|
123
|
-
function codex(e) {
|
|
124
|
-
if (e.type === "thread.started") { fields(e, ["type", "thread_id"]); init(); bindSession(e.thread_id); return; }
|
|
125
|
-
ready();
|
|
126
|
-
if (e.type === "turn.started") {
|
|
127
|
-
fields(e, ["type"]); if (turnStarted) block("multiple-native-turns"); turnStarted = true; return;
|
|
128
|
-
}
|
|
129
|
-
if (["turn.completed", "turn.failed", "error"].includes(e.type)) {
|
|
130
|
-
fields(e, ["type", "usage", "error", "message"]);
|
|
131
|
-
if (!turnStarted && e.type !== "error") fail("terminal-before-turn");
|
|
132
|
-
if (e.type === "turn.completed" && (e.error !== undefined || e.message !== undefined)) block("contradictory-terminal");
|
|
133
|
-
ending(e.type === "turn.completed" ? "completed" : "failed");
|
|
134
|
-
terminalUsage(report, e.usage, "codex"); return;
|
|
135
|
-
}
|
|
136
|
-
if (!["item.started", "item.updated", "item.completed"].includes(e.type)) block("unknown-native-event");
|
|
137
|
-
if (!turnStarted) fail("item-before-turn"); fields(e, ["type", "item"]);
|
|
138
|
-
const item = object(e.item); fields(item, ["id", "type", "text"]);
|
|
139
|
-
if (!["agent_message", "reasoning"].includes(item.type)) block("forbidden-native-item");
|
|
140
|
-
const id = nativeId(item.id); let prior = items.get(id);
|
|
141
|
-
if (prior?.done || (prior && e.type === "item.started")) fail("duplicate-native-item");
|
|
142
|
-
if (prior && prior.type !== item.type) fail("native-item-type-mismatch");
|
|
143
|
-
if (!prior) { prior = { type: item.type, text: "", done: false }; items.set(id, prior); }
|
|
144
|
-
if (item.text !== undefined && typeof item.text !== "string") fail("invalid-native-text");
|
|
145
|
-
if (item.type === "agent_message") {
|
|
146
|
-
if (item.text !== undefined) {
|
|
147
|
-
if (!item.text.startsWith(prior.text)) block("native-snapshot-conflict"); prior.text = item.text;
|
|
148
|
-
}
|
|
149
|
-
if (e.type === "item.completed") {
|
|
150
|
-
if (final !== null) block("multiple-final-messages");
|
|
151
|
-
if (typeof item.text !== "string") fail("missing-native-text"); final = item.text;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Reasoning is validated structurally but never retained in the report.
|
|
155
|
-
prior.done = e.type === "item.completed";
|
|
156
|
-
}
|
|
157
|
-
function claude(e) {
|
|
158
|
-
if (e.parent_tool_use_id !== undefined && e.parent_tool_use_id !== null) block("subagent-output-forbidden");
|
|
159
|
-
if (e.type === "system") {
|
|
160
|
-
if (e.subtype !== "init") block("native-customization-or-retry-forbidden");
|
|
161
|
-
fields(e, ["type", "subtype", "session_id", "uuid", "model", "effort", "tools", "mcp_servers", "plugins", "skills", "agents", "cwd", "claude_code_version", "permissionMode", "apiKeySource", "slash_commands", "terminal_slash_commands", "output_style", "capabilities", "betas", "plugin_errors", "mcp_server_errors"]);
|
|
162
|
-
init(); bindSession(e.session_id); configure(e);
|
|
163
|
-
for (const key of ["tools", "mcp_servers", "plugins", "skills", "agents", "plugin_errors", "mcp_server_errors"]) emptyNativeArray(e, key, ["tools", "mcp_servers", "plugins", "skills"].includes(key));
|
|
164
|
-
if (e.claude_code_version !== undefined && e.claude_code_version !== report.client.clientVersion) block("native-client-version-mismatch");
|
|
165
|
-
if (e.permissionMode === "bypassPermissions") block("native-permission-bypass");
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
ready(); bindSession(e.session_id);
|
|
169
|
-
if (e.type === "assistant") {
|
|
170
|
-
fields(e, ["type", "session_id", "uuid", "parent_tool_use_id", "message", "error", "aborted", "timestamp"]);
|
|
171
|
-
if (e.aborted !== undefined && typeof e.aborted !== "boolean") fail("invalid-native-aborted-status");
|
|
172
|
-
if (e.error !== undefined || e.aborted === true) block("assistant-error-or-aborted");
|
|
173
|
-
const m = object(e.message); fields(m, ["id", "type", "role", "content", "model", "stop_reason", "stop_sequence", "usage"]);
|
|
174
|
-
if ((m.role !== undefined && m.role !== "assistant") || (m.type !== undefined && m.type !== "message")) fail("invalid-assistant-role");
|
|
175
|
-
const id = nativeId(m.id); if (assistantId !== null && assistantId !== id) block("multiple-response-identities"); assistantId = id;
|
|
176
|
-
if (m.model !== undefined) {
|
|
177
|
-
if (report.model.value !== null && report.model.value !== m.model) block("multiple-response-models");
|
|
178
|
-
observe(report.model, m.model, report.requested.model, "claude-assistant-message", "response");
|
|
179
|
-
}
|
|
180
|
-
if (!Array.isArray(m.content)) fail("invalid-assistant-content"); let text = ""; let hasText = false;
|
|
181
|
-
for (const b of m.content) {
|
|
182
|
-
object(b);
|
|
183
|
-
if (b.type === "text") { fields(b, ["type", "text"]); if (typeof b.text !== "string") fail("invalid-native-text"); text += b.text; hasText = true; }
|
|
184
|
-
else if (b.type === "thinking") {
|
|
185
|
-
fields(b, ["type", "thinking", "signature"]);
|
|
186
|
-
if (typeof b.thinking !== "string" || (b.signature !== undefined && typeof b.signature !== "string")) fail("invalid-native-thinking");
|
|
187
|
-
}
|
|
188
|
-
else if (b.type === "redacted_thinking") {
|
|
189
|
-
fields(b, ["type", "data"]); if (typeof b.data !== "string") fail("invalid-native-thinking");
|
|
190
|
-
}
|
|
191
|
-
else block("non-text-assistant-block");
|
|
192
|
-
}
|
|
193
|
-
if (hasText) { if (assistantText !== null) block("duplicate-assistant-text"); assistantText = text; }
|
|
194
|
-
if (m.usage !== undefined) validateUsage(m.usage, "claude");
|
|
195
|
-
if (m.stop_reason !== undefined && m.stop_reason !== null && m.stop_reason !== "end_turn") block("assistant-not-finished");
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (e.type !== "result") block("unknown-native-event");
|
|
199
|
-
fields(e, ["type", "subtype", "session_id", "uuid", "is_error", "num_turns", "result", "duration_ms", "duration_api_ms", "total_cost_usd", "usage", "modelUsage", "permission_denials", "errors", "api_error_status", "terminal_reason", "stop_reason"]);
|
|
200
|
-
if (typeof e.is_error !== "boolean") fail("missing-native-error-status");
|
|
201
|
-
turns(e.num_turns, limits); emptyNativeArray(e, "permission_denials", false);
|
|
202
|
-
if (e.modelUsage !== undefined) {
|
|
203
|
-
const names = Object.keys(object(e.modelUsage));
|
|
204
|
-
if (names.length > 1) block("auxiliary-model-usage-forbidden");
|
|
205
|
-
if (names.length && report.model.value !== null && names[0] !== report.model.value) block("model-usage-identity-conflict");
|
|
206
|
-
}
|
|
207
|
-
const known = ["success", "error_during_execution", "error_max_turns", "error_max_budget_usd", "error_max_structured_output_retries"];
|
|
208
|
-
if (!known.includes(e.subtype)) block("unknown-native-terminal");
|
|
209
|
-
const successful = e.subtype === "success" && !e.is_error && (e.api_error_status === undefined || e.api_error_status === null);
|
|
210
|
-
if (e.errors !== undefined && !Array.isArray(e.errors)) fail("invalid-native-error-list");
|
|
211
|
-
if (successful && e.errors?.length) block("contradictory-terminal");
|
|
212
|
-
if (e.terminal_reason !== undefined && e.terminal_reason !== null && e.terminal_reason !== "completed") {
|
|
213
|
-
ending(["aborted_streaming", "aborted_tools"].includes(e.terminal_reason) ? "interrupted" : "failed");
|
|
214
|
-
} else ending(successful ? "completed" : "failed");
|
|
215
|
-
if (e.duration_ms !== undefined) report.durationSeconds = nonnegative(e.duration_ms) / 1000;
|
|
216
|
-
terminalUsage(report, e.usage, "claude");
|
|
217
|
-
if (report.nativeState === "completed") {
|
|
218
|
-
if (typeof e.result !== "string") fail("missing-native-text"); final = e.result;
|
|
219
|
-
if (assistantText !== null && assistantText !== final) block("native-final-text-conflict");
|
|
220
|
-
if (e.stop_reason !== undefined && e.stop_reason !== null && e.stop_reason !== "end_turn") block("result-not-finished");
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
consume, get terminal() { return terminal; }, get final() { return final; },
|
|
225
|
-
settled() { return [...items.values()].every(s => s.done); }
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function fields(value, allowed) { object(value); if (Object.keys(value).some(k => !allowed.includes(k))) block("unknown-native-field"); }
|
|
230
|
-
function object(v) { if (!v || typeof v !== "object" || Array.isArray(v)) fail("invalid-native-object"); return v; }
|
|
231
|
-
function nativeId(v) { if (typeof v !== "string" || !v || v.length > 256) fail("invalid-native-identifier"); return v; }
|
|
232
|
-
function emptyNativeArray(e, key, required) {
|
|
233
|
-
if (e[key] === undefined && !required) return;
|
|
234
|
-
if (!Array.isArray(e[key])) fail("missing-native-control-list");
|
|
235
|
-
if (e[key].length) block("native-tools-or-customizations-present");
|
|
236
|
-
}
|
|
237
|
-
function nonnegative(v) { if (typeof v !== "number" || !Number.isFinite(v) || v < 0 || v > 86_400_000) fail("invalid-native-number"); return v; }
|
|
238
|
-
function integer(v) { if (!Number.isSafeInteger(v) || v < 0) fail("invalid-native-counter"); return v; }
|
|
239
|
-
function turns(v, limits) { integer(v); if (v < 1 || v > limits.maxTurns) block("native-turn-count-exceeded"); }
|
|
240
|
-
function observe(target, value, requested, source, scope) {
|
|
241
|
-
if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value)) fail("invalid-native-model-metadata");
|
|
242
|
-
Object.assign(target, { value, verification: "reported", match: value === requested ? "matched" : "mismatched", source, scope });
|
|
243
|
-
if (target.match === "mismatched") block("reported-model-or-effort-mismatch");
|
|
244
|
-
}
|
|
245
|
-
function validateUsage(usage, client) {
|
|
246
|
-
object(usage);
|
|
247
|
-
const allowed = {
|
|
248
|
-
codex: ["input_tokens", "output_tokens", "cached_input_tokens", "reasoning_output_tokens"],
|
|
249
|
-
claude: ["input_tokens", "output_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "service_tier", "inference_geo", "server_tool_use", "iterations", "speed"]
|
|
250
|
-
}[client];
|
|
251
|
-
fields(usage, allowed);
|
|
252
|
-
for (const [k, v] of Object.entries(usage)) {
|
|
253
|
-
if (k.endsWith("tokens")) integer(v);
|
|
254
|
-
else if (k === "server_tool_use" && Object.values(object(v)).some(n => integer(n) > 0)) block("native-server-tool-usage-forbidden");
|
|
255
|
-
else if (k === "iterations") block("native-usage-iterations-not-admitted");
|
|
256
|
-
}
|
|
257
|
-
return usage;
|
|
258
|
-
}
|
|
259
|
-
function terminalUsage(report, value, client) {
|
|
260
|
-
if (value === undefined || value === null) return;
|
|
261
|
-
const usage = validateUsage(value, client);
|
|
262
|
-
const map = { inputTokens: "input_tokens", outputTokens: "output_tokens",
|
|
263
|
-
cacheReadTokens: client === "codex" ? "cached_input_tokens" : "cache_read_input_tokens",
|
|
264
|
-
reasoningTokens: client === "codex" ? "reasoning_output_tokens" : "thinking_tokens", totalTokens: "total_tokens" };
|
|
265
|
-
for (const [out, key] of Object.entries(map)) report.usage[out] = usage[key] ?? null;
|
|
266
|
-
report.usageScope = "terminal-native-report";
|
|
267
|
-
}
|
|
268
|
-
function descriptorKey(d) { return JSON.stringify([d.provider, d.client, d.variant, d.clientVersion]); }
|
|
269
|
-
function hash(value) { return createHash("sha256").update(value).digest("hex"); }
|
|
270
|
-
function canonicalJson(v) {
|
|
271
|
-
if (v === null || typeof v !== "object") return JSON.stringify(v);
|
|
272
|
-
if (Array.isArray(v)) return `[${v.map(canonicalJson).join(",")}]`;
|
|
273
|
-
return `{${Object.keys(v).sort().map(k => `${JSON.stringify(k)}:${canonicalJson(v[k])}`).join(",")}}`;
|
|
274
|
-
}
|
|
275
|
-
function isTimestamp(v) {
|
|
276
|
-
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(v)) return false;
|
|
277
|
-
const t = Date.parse(v); return Number.isFinite(t) && new Date(t).toISOString() === v.replace(/Z$/, ".000Z");
|
|
278
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { createClientAdapterPlanner } from "./client-adapter-plan.js";
|
|
2
|
-
import { validators, copyInertJson, ParseFailure, fail, same, hash, unique, fresh, tested, ledgerFacts, CONTROLS, EFFECTS } from "./client-runtime-core.js";
|
|
3
|
-
|
|
4
|
-
const GATES = ["trusted-authorization", "native-installation-and-controls", "subscription-and-billing", "atomic-durable-reservation", "private-context-resolution", "supervised-process-and-cancellation"];
|
|
5
|
-
|
|
6
|
-
/** Pure eligibility of declarations. Never issues an execution capability. */
|
|
7
|
-
export function createClientRuntimeAdmission(base, preference, adapter, runtime) {
|
|
8
|
-
const validate = validators(base, preference, adapter, runtime);
|
|
9
|
-
const plan = createClientAdapterPlanner(base, preference, adapter);
|
|
10
|
-
return function admit(input) {
|
|
11
|
-
const r = { schemaVersion: "1.0.0", engineVersion: "1.0.0", state: "invalid", executed: false, runtimeReady: false,
|
|
12
|
-
verifiedAdmission: false, identity: null, reservation: null, missing: [], reasons: [], externalGates: [...GATES],
|
|
13
|
-
audit: { inputSha256: null, planSha256: null, ledgerSha256: null } };
|
|
14
|
-
function finish(state, reasons = []) {
|
|
15
|
-
r.state = state; r.reasons = [...new Set(reasons)].sort(); r.missing.sort();
|
|
16
|
-
if (state !== "eligible-for-reservation") r.reservation = null;
|
|
17
|
-
if (!validate.admissionReport(r)) throw Error("Runtime admission invariant failed");
|
|
18
|
-
return r;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
const d = copyInertJson(input);
|
|
22
|
-
if (!validate.admissionInput(d)) fail("invalid-admission-input");
|
|
23
|
-
const recomputed = plan(d.planningInput);
|
|
24
|
-
r.identity = recomputed.identity; r.audit.inputSha256 = hash(d);
|
|
25
|
-
if (!same(recomputed, d.plan)) fail("runtime-plan-mismatch");
|
|
26
|
-
if (recomputed.state !== "prepared") return finish("blocked", ["runtime-plan-not-prepared"]);
|
|
27
|
-
r.audit.planSha256 = hash(recomputed);
|
|
28
|
-
r.missing = ["expectedInstallation", "evidence", "ledger"].filter(k => d[k] === undefined);
|
|
29
|
-
if (r.missing.length) return finish("needs-info", ["runtime-evidence-missing"]);
|
|
30
|
-
const { ledger, evidence: e, planningInput: p, now } = d; const intent = recomputed.intent;
|
|
31
|
-
r.audit.ledgerSha256 = hash(ledger);
|
|
32
|
-
const facts = ledgerFacts(ledger, now); const blocks = [];
|
|
33
|
-
const block = c => blocks.push(c); const maxAge = p.selection.policy.availabilityMaxAgeSeconds;
|
|
34
|
-
const current = Date.parse(now); const evaluation = Date.parse(p.selection.request.evaluationTime);
|
|
35
|
-
if (current < evaluation || current - evaluation > maxAge * 1000) block("runtime-evaluation-stale-or-future");
|
|
36
|
-
const ageValid = time => current >= Date.parse(time) && current - Date.parse(time) <= maxAge * 1000;
|
|
37
|
-
const selectedAvailability = p.selection.request.availability.find(a => a.profileId === intent.profileId);
|
|
38
|
-
const registryRecord = p.registry.records.find(a => a.recordId === intent.compatibilityRecordId);
|
|
39
|
-
if (![selectedAvailability?.checkedAt, registryRecord?.evaluatedAt, p.context.provenance.checkedAt,
|
|
40
|
-
p.context.authorization.checkedAt, p.environment.checkedAt, p.historyEvidence.checkedAt].every(ageValid)) block("runtime-plan-evidence-stale-or-future");
|
|
41
|
-
const { identity, planSha256, ...installation } = e.binding;
|
|
42
|
-
if (!same(identity, recomputed.identity) || planSha256 !== r.audit.planSha256) block("runtime-evidence-binding-mismatch");
|
|
43
|
-
if (!same(installation, d.expectedInstallation) || !same(installation.client, intent.client)) block("runtime-installation-mismatch");
|
|
44
|
-
if (!tested(e.installation, now, maxAge)) block("runtime-installation-not-tested-or-fresh");
|
|
45
|
-
if (e.authorization.status !== "approved" || e.authorization.revoked || !fresh(e.authorization, now, maxAge) ||
|
|
46
|
-
e.authorization.referenceId !== intent.authorizationRef) block("runtime-authorization-not-current");
|
|
47
|
-
if (!EFFECTS.every(v => e.authorization.effectsApproved.includes(v))) block("runtime-effects-not-authorized");
|
|
48
|
-
if (!same(e.authorization.limits, ledger.limits)) block("runtime-budget-authorization-mismatch");
|
|
49
|
-
if (!tested(e.access.assessment, now, maxAge) || e.access.access !== "subscription-session" || e.access.externalBilling !== "disabled") block("runtime-access-or-billing-unconfirmed");
|
|
50
|
-
if (!tested(e.context.assessment, now, maxAge) || e.context.promptRef !== intent.input.promptRef) block("runtime-context-mismatch-or-stale");
|
|
51
|
-
if (!unique(e.controls.map(c => c.controlId)) || !unique(e.effects.map(c => c.effectId))) fail("duplicate-runtime-evidence");
|
|
52
|
-
for (const control of CONTROLS) {
|
|
53
|
-
const record = e.controls.find(c => c.controlId === control);
|
|
54
|
-
if (!record || !tested(record.assessment, now, maxAge)) block("runtime-controls-not-tested-or-fresh");
|
|
55
|
-
}
|
|
56
|
-
for (const effect of EFFECTS) {
|
|
57
|
-
const record = e.effects.find(c => c.effectId === effect);
|
|
58
|
-
if (!record || record.disposition !== "allowed" || !tested(record.assessment, now, maxAge)) block("runtime-native-effects-unconfirmed");
|
|
59
|
-
}
|
|
60
|
-
if (!tested(e.accounting.assessment, now, maxAge) || e.accounting.maxCallsPerStart === null || !e.accounting.limitEnforced) block("runtime-call-ceiling-unconfirmed");
|
|
61
|
-
if (ledger.projectId !== recomputed.identity.projectId || ledger.taskId !== recomputed.identity.taskId) block("runtime-ledger-identity-mismatch");
|
|
62
|
-
if (!same(ledger.history, p.selection.request.history)) block("runtime-history-mismatch");
|
|
63
|
-
if (ledger.status !== "reconciled" || facts.uncertain || facts.overrun) block("runtime-reconciliation-required");
|
|
64
|
-
if (facts.active) block("runtime-active-reservation");
|
|
65
|
-
if (ledger.attempts.length >= 128) block("runtime-ledger-capacity");
|
|
66
|
-
if (ledger.limits.maxModelCalls > p.selection.policy.maxFutureExecutions ||
|
|
67
|
-
ledger.limits.maxDurationSeconds > p.selection.policy.maxFutureDurationSeconds) block("runtime-budget-exceeds-policy");
|
|
68
|
-
if (ledger.limits.maxMainStarts <= ledger.mainStartsUsed ||
|
|
69
|
-
ledger.limits.maxModelCalls - ledger.history.executionsUsed < (e.accounting.maxCallsPerStart ?? Infinity) ||
|
|
70
|
-
ledger.limits.maxDurationSeconds - ledger.history.durationUsedSeconds < intent.limits.timeoutSeconds) block("runtime-budget-insufficient");
|
|
71
|
-
if (blocks.length) return finish("blocked", blocks);
|
|
72
|
-
r.reservation = { identity: recomputed.identity, planSha256: r.audit.planSha256, client: intent.client, profileId: intent.profileId,
|
|
73
|
-
model: intent.requestedModel, effort: intent.requestedEffort, calls: e.accounting.maxCallsPerStart, seconds: intent.limits.timeoutSeconds };
|
|
74
|
-
return finish("eligible-for-reservation", ["declared-eligibility-only"]);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (!(error instanceof ParseFailure)) throw error;
|
|
77
|
-
return finish("invalid", [error.code]);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
2
|
-
import { createClientRuntimeStore } from "./client-runtime-store.js";
|
|
3
|
-
import { copyInertJson, hash, same, fresh, fail, ParseFailure } from "./client-runtime-core.js";
|
|
4
|
-
import { copyBytes } from "./client-output-json.js";
|
|
5
|
-
import { superviseFixture, monotonicMs } from "./client-runtime-supervisor.js";
|
|
6
|
-
|
|
7
|
-
export const FIXTURE_SCHEMA_ID = "https://agent-toolkit.local/schemas/agent-client-runtime-fixture.schema.json";
|
|
8
|
-
const stamp = v => typeof v === "string" && /^\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");
|
|
9
|
-
|
|
10
|
-
/** No CLI or native client: configured and called only by a trusted local harness. */
|
|
11
|
-
export function createFixtureCoordinator(base, preference, adapter, runtime, local, fixture, configuration, dependencies = {}) {
|
|
12
|
-
const schemas = [base, preference, adapter, runtime, local, fixture].map(copyInertJson);
|
|
13
|
-
if (schemas[5].$id !== FIXTURE_SCHEMA_ID) throw Error("Unsupported fixture runtime schema");
|
|
14
|
-
const ajv = new Ajv2020({ strict: true, allErrors: true }); ajv.addFormat("date-time", { type: "string", validate: stamp });
|
|
15
|
-
schemas.forEach(s => ajv.addSchema(s)); const valid = ajv.compile({ $ref: `${FIXTURE_SCHEMA_ID}#/$defs/request` });
|
|
16
|
-
const validReport = ajv.compile({ $ref: `${FIXTURE_SCHEMA_ID}#/$defs/report` });
|
|
17
|
-
const cfg = copyInertJson(configuration);
|
|
18
|
-
const runStore = createClientRuntimeStore(...schemas.slice(0, 5), cfg, dependencies.store);
|
|
19
|
-
const clock = dependencies.store?.clock ?? Date.now;
|
|
20
|
-
return async function coordinate(input, { signal } = {}) {
|
|
21
|
-
const r = { schemaVersion: "1.0.0", scope: "fixture-only", state: "not-started", identity: null, attemptId: null,
|
|
22
|
-
fixtureExecuted: false, nativeExecuted: false, runtimeReady: false, verifiedAdmission: false, modelCalls: 0,
|
|
23
|
-
process: null, storage: null, reasons: [] };
|
|
24
|
-
try {
|
|
25
|
-
const d = copyInertJson(input); if (!valid(d)) fail("fixture-invalid-request");
|
|
26
|
-
if (d.reservation.operation !== "apply" || d.reservation.transition.operation !== "reserve") fail("fixture-reservation-required");
|
|
27
|
-
const t = d.reservation.transition, a = d.authorization;
|
|
28
|
-
r.identity = copyInertJson(d.reservation.identity); r.attemptId = t.attemptId;
|
|
29
|
-
copyBytes(d.inputText, d.limits.maxInputBytes);
|
|
30
|
-
if (d.limits.graceMs + d.limits.confirmationMs >= d.limits.timeoutMs ||
|
|
31
|
-
d.limits.maxLineBytes > d.limits.maxOutputBytes || d.limits.timeoutMs > t.admissionInput.planningInput.limits.timeoutSeconds * 1000) fail("fixture-incompatible-limits");
|
|
32
|
-
const gate = time => {
|
|
33
|
-
if (a.status !== "approved" || a.revoked || !a.reconciliationApproved || !fresh(a, time, 3600) ||
|
|
34
|
-
a.fixtureId !== d.fixtureId || a.attemptId !== t.attemptId || !same(a.identity, r.identity) ||
|
|
35
|
-
a.rootSha256 !== hash(cfg.root) || a.limitsSha256 !== hash(d.limits)) fail("fixture-not-authorized");
|
|
36
|
-
return hash(d);
|
|
37
|
-
};
|
|
38
|
-
const ms = clock(); if (typeof ms !== "number" || !Number.isFinite(ms)) fail("fixture-clock-unavailable");
|
|
39
|
-
gate(new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z"));
|
|
40
|
-
if (signal?.aborted) fail("fixture-canceled-before-reservation");
|
|
41
|
-
const beganAt = monotonicMs();
|
|
42
|
-
r.storage = await runStore.withFixtureSession(d.reservation, async session => {
|
|
43
|
-
r.process = await superviseFixture(session.handle, d, { ...dependencies.supervisor, signal, beganAt });
|
|
44
|
-
r.fixtureExecuted = r.process.fixtureExecuted; r.state = r.process.state;
|
|
45
|
-
if (r.process.state === "indeterminate" || !r.process.terminationConfirmed) return; // Retain lock and reservation.
|
|
46
|
-
const ledger = session.snapshot();
|
|
47
|
-
const time = new Date(clock()).toISOString().replace(/\.\d{3}Z$/, "Z"); gate(time);
|
|
48
|
-
const started = r.process.started;
|
|
49
|
-
await session.apply({ schemaVersion: "1.0.0", operation: "settle", now: time, ledger, expectedRevision: ledger.revision,
|
|
50
|
-
expectedLedgerSha256: hash(ledger), attemptId: t.attemptId, startObservation: started ? "started" : "not-started",
|
|
51
|
-
actualCalls: 0, actualSeconds: started ? Math.ceil(r.process.elapsedMs / 1000) : 0,
|
|
52
|
-
outcome: started ? r.process.state : "not-started", terminationConfirmed: true,
|
|
53
|
-
reconciliation: { status: "approved", revoked: false, referenceId: a.referenceId, source: "operator-attestation",
|
|
54
|
-
checkedAt: a.checkedAt, expiresAt: a.expiresAt, evidenceRef: a.evidenceRef,
|
|
55
|
-
projectId: ledger.projectId, taskId: ledger.taskId, attemptId: t.attemptId, ledgerSha256: hash(ledger) } });
|
|
56
|
-
}, gate);
|
|
57
|
-
r.reasons = [...new Set([...(r.process?.reasons ?? []), ...r.storage.reasons])];
|
|
58
|
-
if (r.storage.state === "indeterminate") r.state = "indeterminate";
|
|
59
|
-
if (r.storage.state === "blocked") r.state = "not-started";
|
|
60
|
-
// Public summary deliberately omits snapshots, private paths, process IDs and raw streams.
|
|
61
|
-
r.storage = { state: r.storage.state, writeObservation: r.storage.writeObservation, durability: r.storage.durability,
|
|
62
|
-
cleanup: r.storage.cleanup, revision: r.storage.snapshot?.revision ?? null, reasons: r.storage.reasons };
|
|
63
|
-
} catch (e) {
|
|
64
|
-
r.reasons = [e instanceof ParseFailure ? e.code : "fixture-coordinator-blocked"];
|
|
65
|
-
if (r.fixtureExecuted) r.state = "indeterminate";
|
|
66
|
-
}
|
|
67
|
-
if (!validReport(r)) throw Error("Fixture runtime report invariant failed");
|
|
68
|
-
return r;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
3
|
-
import { copyInertJson, ParseFailure, fail } from "./client-output-json.js";
|
|
4
|
-
|
|
5
|
-
export { copyInertJson, ParseFailure, fail };
|
|
6
|
-
export const RUNTIME_ID = "https://agent-toolkit.local/schemas/agent-client-runtime.schema.json";
|
|
7
|
-
export const CONTROLS = ["no-tools", "no-subagents", "no-mcp", "no-hooks", "no-personalizations", "no-updates", "stdin-text", "no-fallback", "no-resume", "no-permission-bypass", "internal-call-limit"];
|
|
8
|
-
export const EFFECTS = ["native-auth", "provider-inference", "client-state", "telemetry", "descendants"];
|
|
9
|
-
|
|
10
|
-
export function validators(base, preference, adapter, runtime) {
|
|
11
|
-
const schemas = [base, preference, adapter, runtime].map(copyInertJson);
|
|
12
|
-
if (schemas[3].$id !== RUNTIME_ID) throw Error("Unsupported runtime schema");
|
|
13
|
-
const ajv = new Ajv2020({ strict: true, allErrors: true });
|
|
14
|
-
ajv.addFormat("date-time", { type: "string", validate: timestamp });
|
|
15
|
-
schemas.forEach(s => ajv.addSchema(s));
|
|
16
|
-
return Object.fromEntries(["admissionInput", "admissionReport", "stateInput", "stateReport", "ledger"]
|
|
17
|
-
.map(name => [name, ajv.compile({ $ref: `${RUNTIME_ID}#/$defs/${name}` })]));
|
|
18
|
-
}
|
|
19
|
-
export function canonical(v) {
|
|
20
|
-
if (v === null || typeof v !== "object") return JSON.stringify(v);
|
|
21
|
-
if (Array.isArray(v)) return `[${v.map(canonical).join(",")}]`;
|
|
22
|
-
return `{${Object.keys(v).sort().map(k => `${JSON.stringify(k)}:${canonical(v[k])}`).join(",")}}`;
|
|
23
|
-
}
|
|
24
|
-
export const same = (a, b) => canonical(a) === canonical(b);
|
|
25
|
-
export const hash = v => createHash("sha256").update(canonical(v)).digest("hex");
|
|
26
|
-
export const unique = v => new Set(v).size === v.length;
|
|
27
|
-
export function fresh(stamp, now, maxAge = Infinity) {
|
|
28
|
-
const checked = Date.parse(stamp.checkedAt); const expires = Date.parse(stamp.expiresAt); const current = Date.parse(now);
|
|
29
|
-
return checked < expires && checked <= current && current < expires && current - checked <= maxAge * 1000;
|
|
30
|
-
}
|
|
31
|
-
export function tested(stamp, now, maxAge) {
|
|
32
|
-
return stamp.status === "locally-tested" && stamp.source === "installation-test" && fresh(stamp, now, maxAge);
|
|
33
|
-
}
|
|
34
|
-
function timestamp(v) {
|
|
35
|
-
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(v)) return false;
|
|
36
|
-
const t = Date.parse(v); return Number.isFinite(t) && new Date(t).toISOString() === v.replace(/Z$/, ".000Z");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Validate accounting relations, not authenticity. Called only after schema validation.
|
|
40
|
-
export function ledgerFacts(ledger, now) {
|
|
41
|
-
if (!unique(ledger.attempts.map(a => a.attemptId))) fail("duplicate-ledger-attempt");
|
|
42
|
-
const history = copyInertJson(ledger.importedHistory);
|
|
43
|
-
let starts = ledger.importedMainStartsUsed; let active = 0; let previousTime = -Infinity; let uncertain = false; let overrun = false;
|
|
44
|
-
for (const [index, a] of ledger.attempts.entries()) {
|
|
45
|
-
if (a.identity.projectId !== ledger.projectId || a.identity.taskId !== ledger.taskId) fail("foreign-ledger-attempt");
|
|
46
|
-
const reserved = Date.parse(a.reservedAt); const updated = Date.parse(a.updatedAt);
|
|
47
|
-
if (reserved < previousTime || updated < reserved || updated > Date.parse(now)) fail("ledger-chronology-conflict");
|
|
48
|
-
previousTime = updated;
|
|
49
|
-
if (a.state !== "settled") {
|
|
50
|
-
active++;
|
|
51
|
-
if (index !== ledger.attempts.length - 1 || active > 1) fail("multiple-active-attempts");
|
|
52
|
-
if (a.actualCalls !== null || a.actualSeconds !== null || a.evidenceRef !== null) fail("unsettled-consumption-present");
|
|
53
|
-
if (a.state === "reserved" && (a.startObservation !== "not-reported" || a.outcome !== null)) fail("invalid-reserved-attempt");
|
|
54
|
-
if (a.state === "started" && (a.startObservation !== "started" || a.outcome !== null)) fail("invalid-started-attempt");
|
|
55
|
-
if (a.state === "reconciliation-required" && (!["started", "unknown"].includes(a.startObservation) || a.outcome !== "indeterminate")) fail("invalid-interrupted-attempt");
|
|
56
|
-
if (a.state !== "reserved") uncertain = true;
|
|
57
|
-
} else {
|
|
58
|
-
if (a.actualCalls === null || a.actualSeconds === null || a.evidenceRef === null || a.outcome === null || a.outcome === "indeterminate") fail("unproven-settlement");
|
|
59
|
-
if (!["started", "not-started"].includes(a.startObservation)) fail("invalid-settlement-observation");
|
|
60
|
-
if (a.startObservation === "not-started" && (a.actualCalls !== 0 || a.actualSeconds !== 0 || a.outcome !== "not-started")) fail("not-started-consumption-conflict");
|
|
61
|
-
if (a.startObservation === "started" && a.outcome === "not-started") fail("started-outcome-conflict");
|
|
62
|
-
history.executionsUsed += a.actualCalls; history.durationUsedSeconds += a.actualSeconds;
|
|
63
|
-
if (a.startObservation === "started" && a.actualCalls > 0) {
|
|
64
|
-
history.previousProfileId = a.profileId; history.previousEffort = a.effort;
|
|
65
|
-
}
|
|
66
|
-
if (a.actualCalls > a.reservedCalls || a.actualSeconds > a.reservedSeconds) overrun = true;
|
|
67
|
-
}
|
|
68
|
-
if (a.startObservation === "started") starts++;
|
|
69
|
-
}
|
|
70
|
-
if (starts > 1_000_000 || history.executionsUsed > 1_000_000 || history.durationUsedSeconds > 1_000_000) fail("ledger-counter-limit");
|
|
71
|
-
if (!same(ledger.history, history) || ledger.mainStartsUsed !== starts) fail("ledger-total-mismatch");
|
|
72
|
-
if ((uncertain || overrun) && ledger.status !== "reconciliation-required") fail("ledger-uncertainty-hidden");
|
|
73
|
-
return { active, uncertain, overrun, history, starts };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function recalculate(ledger) {
|
|
77
|
-
const history = copyInertJson(ledger.importedHistory); let starts = ledger.importedMainStartsUsed; let pending = false;
|
|
78
|
-
for (const a of ledger.attempts) {
|
|
79
|
-
if (a.startObservation === "started") starts++;
|
|
80
|
-
if (a.state !== "settled" && a.state !== "reserved") pending = true;
|
|
81
|
-
if (a.state === "settled") {
|
|
82
|
-
history.executionsUsed += a.actualCalls; history.durationUsedSeconds += a.actualSeconds;
|
|
83
|
-
if (a.startObservation === "started" && a.actualCalls > 0) { history.previousProfileId = a.profileId; history.previousEffort = a.effort; }
|
|
84
|
-
if (a.actualCalls > a.reservedCalls || a.actualSeconds > a.reservedSeconds) pending = true;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (starts > 1_000_000 || history.executionsUsed > 1_000_000 || history.durationUsedSeconds > 1_000_000) fail("ledger-counter-limit");
|
|
88
|
-
ledger.history = history; ledger.mainStartsUsed = starts;
|
|
89
|
-
if (pending) ledger.status = "reconciliation-required";
|
|
90
|
-
else if (ledger.attempts.every(a => a.state === "settled")) ledger.status = "reconciled";
|
|
91
|
-
return ledger;
|
|
92
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Internal trusted-coordinator interface, never populated from model JSON.
|
|
2
|
-
// Handles are process-local, nontransferable and consumed before asynchronous checks.
|
|
3
|
-
const permits = new WeakMap();
|
|
4
|
-
export function createFixturePermit(check, started, bindingSha256 = null) {
|
|
5
|
-
const handle = Object.freeze(Object.create(null));
|
|
6
|
-
permits.set(handle, { check, started, bindingSha256, used: false, live: true });
|
|
7
|
-
return handle;
|
|
8
|
-
}
|
|
9
|
-
export function revokeFixturePermit(handle) {
|
|
10
|
-
const entry = permits.get(handle); if (entry) entry.live = false;
|
|
11
|
-
}
|
|
12
|
-
export async function claimFixturePermit(handle, bindingSha256 = null) {
|
|
13
|
-
const entry = permits.get(handle);
|
|
14
|
-
if (!entry || !entry.live || entry.used) throw Error("fixture-permit-unavailable");
|
|
15
|
-
entry.used = true;
|
|
16
|
-
if (entry.bindingSha256 !== bindingSha256) throw Error("fixture-permit-binding-mismatch");
|
|
17
|
-
await entry.check();
|
|
18
|
-
if (!entry.live) throw Error("fixture-permit-unavailable");
|
|
19
|
-
return Object.freeze({ started: entry.started });
|
|
20
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { decode, parseEventJson, fail } from "./client-output-json.js";
|
|
2
|
-
|
|
3
|
-
/** Bounded byte-framed fixture protocol, not a parser for any AI client. */
|
|
4
|
-
export function createFixtureProtocol(limits) {
|
|
5
|
-
let bytes = 0, events = 0, pending = Buffer.alloc(0), state = "initial";
|
|
6
|
-
const line = input => {
|
|
7
|
-
if (state === "terminal") fail("fixture-after-terminal");
|
|
8
|
-
if (++events > limits.maxEvents) fail("fixture-event-limit");
|
|
9
|
-
const text = decode(input.at(-1) === 13 ? input.subarray(0, -1) : input);
|
|
10
|
-
const event = parseEventJson(text);
|
|
11
|
-
if (event.v !== 1 || typeof event.type !== "string") fail("fixture-invalid-event");
|
|
12
|
-
const keys = Object.keys(event).sort().join(",");
|
|
13
|
-
if (event.type === "start" && state === "initial" && keys === "type,v") state = "running";
|
|
14
|
-
else if (event.type === "data" && state === "running" && keys === "text,type,v" && typeof event.text === "string") { /* Discard private payload. */ }
|
|
15
|
-
else if (event.type === "end" && state === "running" && keys === "ok,type,v" && event.ok === true) state = "terminal";
|
|
16
|
-
else fail("fixture-forbidden-event");
|
|
17
|
-
};
|
|
18
|
-
return {
|
|
19
|
-
push(chunk) {
|
|
20
|
-
bytes += chunk.length;
|
|
21
|
-
if (bytes > limits.maxOutputBytes) fail("fixture-output-limit");
|
|
22
|
-
let start = 0;
|
|
23
|
-
for (let i = 0; i < chunk.length; i++) if (chunk[i] === 10) {
|
|
24
|
-
const size = pending.length + i - start;
|
|
25
|
-
if (size > limits.maxLineBytes) fail("fixture-line-limit");
|
|
26
|
-
line(Buffer.concat([pending, chunk.subarray(start, i)], size));
|
|
27
|
-
pending = Buffer.alloc(0); start = i + 1;
|
|
28
|
-
}
|
|
29
|
-
const tail = chunk.subarray(start);
|
|
30
|
-
if (pending.length + tail.length > limits.maxLineBytes) fail("fixture-line-limit");
|
|
31
|
-
pending = Buffer.concat([pending, tail]);
|
|
32
|
-
},
|
|
33
|
-
finish() {
|
|
34
|
-
if (pending.length) fail("fixture-unterminated-line");
|
|
35
|
-
if (state !== "terminal") fail("fixture-incomplete-protocol");
|
|
36
|
-
},
|
|
37
|
-
counts: () => ({ stdoutBytes: bytes, events, retainedLineBytes: pending.length })
|
|
38
|
-
};
|
|
39
|
-
}
|