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,253 +0,0 @@
|
|
|
1
|
-
import { supportsDiagnosticHost } 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 { createHash } from "node:crypto";
|
|
6
|
-
import { types } from "node:util";
|
|
7
|
-
import { spawn as nativeSpawn } from "node:child_process";
|
|
8
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
9
|
-
import { copyInertJson } from "./client-output-json.js";
|
|
10
|
-
import { hash } from "./client-runtime-core.js";
|
|
11
|
-
import { createStoreFiles } from "./client-runtime-store-files.js";
|
|
12
|
-
|
|
13
|
-
const ID = "https://agent-toolkit.local/schemas/agent-client-native-diagnostics.schema.json";
|
|
14
|
-
const permits = new WeakMap();
|
|
15
|
-
const monoMs = () => Number(process.hrtime.bigint() / 1_000_000n);
|
|
16
|
-
class DiagnosticFailure extends Error { constructor(code) { super(code); this.code = code; } }
|
|
17
|
-
const fail = code => { throw new DiagnosticFailure(code); };
|
|
18
|
-
const metadata = s => [s.dev, s.ino, s.uid, s.gid, s.mode, s.size, s.mtimeMs, s.ctimeMs];
|
|
19
|
-
const sameStat = (a, b) => JSON.stringify(metadata(a)) === JSON.stringify(metadata(b));
|
|
20
|
-
const safePath = p => typeof p === "string" && path.isAbsolute(p) && path.normalize(p) === p && !/[\x00-\x1f\x7f]/.test(p);
|
|
21
|
-
|
|
22
|
-
/** The caller is trusted orchestration code holding the human's scoped approval. */
|
|
23
|
-
export function createDiagnosticPermit(configuration) {
|
|
24
|
-
const h = Object.freeze(Object.create(null));
|
|
25
|
-
permits.set(h, { binding: hash(copyInertJson(configuration)), live: true, used: false });
|
|
26
|
-
return h;
|
|
27
|
-
}
|
|
28
|
-
export function revokeDiagnosticPermit(h) { const p = permits.get(h); if (p) p.live = false; }
|
|
29
|
-
|
|
30
|
-
/** Strip terminal controls before extracting closed metadata, never return raw output. */
|
|
31
|
-
export function extractDiagnosticMetadata(recipe, text, options) {
|
|
32
|
-
if (!["version", "help"].includes(recipe) || typeof text !== "string" || Buffer.byteLength(text) > 131072 ||
|
|
33
|
-
types.isProxy(options) || !Array.isArray(options)) fail("diagnostic-output-unexpected");
|
|
34
|
-
const clean = text.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "")
|
|
35
|
-
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "");
|
|
36
|
-
if (/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(clean)) fail("diagnostic-output-unexpected");
|
|
37
|
-
if (recipe === "version") {
|
|
38
|
-
const m = /^\s*(\d{1,4}\.\d{1,4}\.\d{1,4}(?:-[a-z0-9][a-z0-9.-]{0,31})?)(?: \(Claude Code\))?\s*$/.exec(clean);
|
|
39
|
-
if (!m) fail("diagnostic-output-unexpected");
|
|
40
|
-
return { declaredVersion: m[1], optionsPresent: [] };
|
|
41
|
-
}
|
|
42
|
-
if (recipe !== "help" || !/^Usage:\s*claude\b/m.test(clean) || /\b(?:api[_-]?key|token)\s*[:=]\s*\S+/i.test(clean)) fail("diagnostic-output-unexpected");
|
|
43
|
-
const found = new Set();
|
|
44
|
-
for (const line of clean.split(/\r?\n/)) {
|
|
45
|
-
if (line.length > 8192) fail("diagnostic-output-unexpected");
|
|
46
|
-
const m = /^\s{0,8}(?:-[A-Za-z],?\s*)?(--[A-Za-z][A-Za-z-]*)(?=[, \t=]|$)/.exec(line);
|
|
47
|
-
if (m && options.includes(m[1])) found.add(m[1]);
|
|
48
|
-
}
|
|
49
|
-
if (!found.has("--print")) fail("diagnostic-output-unexpected");
|
|
50
|
-
return { declaredVersion: null, optionsPresent: [...found].sort() };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** No request JSON, no prompts, no model selection, no account or inference commands. */
|
|
54
|
-
export function createNativeDiagnostics(schema, configuration, authorization, dependencies = {}) {
|
|
55
|
-
const platformAdmitted = supportsDiagnosticHost(process.platform, process.arch, dependencies);
|
|
56
|
-
const s = copyInertJson(schema), cfg = copyInertJson(configuration);
|
|
57
|
-
if (s.$id !== ID) throw Error("Unsupported diagnostic schema");
|
|
58
|
-
const ajv = new Ajv2020({ strict: true, allErrors: true }); ajv.addSchema(s);
|
|
59
|
-
const valid = Object.fromEntries(["configuration", "report", "observation"].map(k => [k, ajv.compile({ $ref: `${ID}#/$defs/${k}` })]));
|
|
60
|
-
if (!valid.configuration(cfg) || ![cfg.candidate.entryPath, cfg.candidate.artifactPath, cfg.workspaceParent].every(safePath) ||
|
|
61
|
-
cfg.limits.graceMs + cfg.limits.confirmationMs >= cfg.limits.processTimeoutMs || cfg.limits.processTimeoutMs > cfg.limits.totalTimeoutMs) throw Error("Invalid diagnostic configuration");
|
|
62
|
-
const options = s.$defs.observation.properties.optionsPresent.items.enum;
|
|
63
|
-
const reasons = s.$defs.reason.enum;
|
|
64
|
-
const io = { ...fs, ...dependencies.io }, spawn = dependencies.spawn ?? nativeSpawn;
|
|
65
|
-
const kill = dependencies.kill ?? process.kill.bind(process), mono = dependencies.monotonic ?? monoMs;
|
|
66
|
-
const files = createStoreFiles(dependencies.io), c = cfg.candidate, l = cfg.limits;
|
|
67
|
-
const clock = () => { const n = mono(); if (!Number.isFinite(n) || n < 0) fail("diagnostic-local-error"); return n; };
|
|
68
|
-
const code = e => e instanceof DiagnosticFailure && reasons.includes(e.code) ? e.code : "diagnostic-local-error";
|
|
69
|
-
let invoked = false;
|
|
70
|
-
|
|
71
|
-
async function physical(p) {
|
|
72
|
-
let curr = path.parse(p).root;
|
|
73
|
-
const parts = p.slice(curr.length).split(path.sep).filter(Boolean);
|
|
74
|
-
if (parts.length > 64) fail("diagnostic-path-unsafe");
|
|
75
|
-
for (let i = 0; i < parts.length; i++) {
|
|
76
|
-
curr = path.join(curr, parts[i]); const stat = await io.lstat(curr);
|
|
77
|
-
if (stat.isSymbolicLink() || i < parts.length - 1 && !stat.isDirectory()) fail("diagnostic-path-unsafe");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async function artifact(deadline) {
|
|
81
|
-
await physical(path.dirname(c.entryPath)); await physical(c.artifactPath);
|
|
82
|
-
const link = await io.lstat(c.entryPath);
|
|
83
|
-
if (!link.isSymbolicLink() || link.dev !== c.expectedDev || link.ino !== c.expectedLinkIno || link.uid !== c.expectedUid ||
|
|
84
|
-
path.resolve(path.dirname(c.entryPath), await io.readlink(c.entryPath)) !== c.artifactPath) fail("diagnostic-artifact-changed");
|
|
85
|
-
const before = await io.lstat(c.artifactPath);
|
|
86
|
-
if (!before.isFile() || before.isSymbolicLink() || before.uid !== c.expectedUid || before.nlink !== 1 ||
|
|
87
|
-
(before.mode & 0o7777) !== c.expectedMode || (before.mode & 0o022) || !(before.mode & 0o111) ||
|
|
88
|
-
before.size !== c.expectedSize || before.dev !== c.expectedDev || before.ino !== c.expectedIno) fail("diagnostic-artifact-changed");
|
|
89
|
-
const h = await io.open(c.artifactPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
90
|
-
let total = 0; const digest = createHash("sha256"), buffer = Buffer.alloc(1048576);
|
|
91
|
-
try {
|
|
92
|
-
if (!sameStat(before, await h.stat())) fail("diagnostic-artifact-changed");
|
|
93
|
-
for (;;) {
|
|
94
|
-
if (clock() >= deadline) fail("diagnostic-deadline");
|
|
95
|
-
const { bytesRead } = await h.read(buffer, 0, buffer.length, null); if (!bytesRead) break;
|
|
96
|
-
total += bytesRead; if (total > 536870912 || total > c.expectedSize) fail("diagnostic-artifact-limit");
|
|
97
|
-
digest.update(buffer.subarray(0, bytesRead));
|
|
98
|
-
}
|
|
99
|
-
if (total !== c.expectedSize || digest.digest("hex") !== c.expectedSha256 || !sameStat(before, await h.stat()) ||
|
|
100
|
-
!sameStat(before, await io.lstat(c.artifactPath)) || !sameStat(link, await io.lstat(c.entryPath)) ||
|
|
101
|
-
path.resolve(path.dirname(c.entryPath), await io.readlink(c.entryPath)) !== c.artifactPath) fail("diagnostic-artifact-changed");
|
|
102
|
-
await physical(c.artifactPath); await physical(path.dirname(c.entryPath));
|
|
103
|
-
} finally { await h.close(); }
|
|
104
|
-
}
|
|
105
|
-
async function privateParent() {
|
|
106
|
-
if (/(?:CloudStorage|Mobile Documents|Dropbox|OneDrive|iCloud)/i.test(cfg.workspaceParent)) fail("diagnostic-private-parent-unsafe");
|
|
107
|
-
await physical(cfg.workspaceParent);
|
|
108
|
-
const stat = await files.directory(cfg.workspaceParent);
|
|
109
|
-
if (stat.dev !== c.expectedDev || stat.uid !== c.expectedUid) fail("diagnostic-private-parent-unsafe");
|
|
110
|
-
for (let p = cfg.workspaceParent; p !== path.parse(p).root; p = path.dirname(p)) {
|
|
111
|
-
try { await io.lstat(path.join(p, ".git")); fail("diagnostic-private-parent-unsafe"); }
|
|
112
|
-
catch (e) { if (e?.code !== "ENOENT") throw e; }
|
|
113
|
-
}
|
|
114
|
-
return stat;
|
|
115
|
-
}
|
|
116
|
-
function runOperation(recipe, workspace, environment, deadline, signal) {
|
|
117
|
-
const r = { recipe, state: "not-started", spawnAttempts: 1, startObserved: false, elapsedMs: 0,
|
|
118
|
-
stdoutBytes: 0, stderrBytes: 0, terminationConfirmed: false, reasons: [] };
|
|
119
|
-
const start = clock(); const end = Math.min(deadline, start + l.processTimeoutMs);
|
|
120
|
-
const chunks = [], stdoutDecoder = new TextDecoder("utf-8", { fatal: true }), stderrDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
121
|
-
let text = "";
|
|
122
|
-
return new Promise(resolve => {
|
|
123
|
-
let child, done = false, canceled = false, cancelAt = null, forced = false, groupGone = false;
|
|
124
|
-
let spawned = false, spawnFailed = false, exited = false, closed = false, outClosed = false, errClosed = false, exitCode = null;
|
|
125
|
-
let timer, hardTimer;
|
|
126
|
-
const add = v => { if (!r.reasons.includes(v)) r.reasons.push(v); };
|
|
127
|
-
const elapsed = () => Math.max(0, Math.ceil(clock() - start));
|
|
128
|
-
const send = sig => {
|
|
129
|
-
if (!spawned || groupGone) return;
|
|
130
|
-
try { kill(-child.pid, sig); }
|
|
131
|
-
catch (e) { if (e?.code === "ESRCH") groupGone = true; else add("diagnostic-signal-unconfirmed"); }
|
|
132
|
-
};
|
|
133
|
-
const alive = () => {
|
|
134
|
-
if (spawnFailed || groupGone) return false; if (!spawned) return true;
|
|
135
|
-
try { kill(-child.pid, 0); return true; }
|
|
136
|
-
catch (e) { if (e?.code === "ESRCH") { groupGone = true; return false; } add("diagnostic-group-unconfirmed"); return true; }
|
|
137
|
-
};
|
|
138
|
-
const cancel = (why, state = "failed") => {
|
|
139
|
-
if (done) return; add(why); if (canceled) return;
|
|
140
|
-
canceled = true; cancelAt = clock(); r.state = state; send("SIGTERM");
|
|
141
|
-
};
|
|
142
|
-
const finish = uncertain => {
|
|
143
|
-
if (done) return; done = true; clearInterval(timer); clearTimeout(hardTimer); signal?.removeEventListener("abort", abort);
|
|
144
|
-
r.elapsedMs = elapsed(); r.terminationConfirmed = spawnFailed || exited && closed && outClosed && errClosed && groupGone;
|
|
145
|
-
if (uncertain || !r.terminationConfirmed || clock() > end) { r.state = "indeterminate"; add("diagnostic-termination-unconfirmed"); }
|
|
146
|
-
else if (spawnFailed) r.state = "failed";
|
|
147
|
-
else if (!canceled) {
|
|
148
|
-
try {
|
|
149
|
-
if (exitCode !== 0) fail("diagnostic-exit-failed");
|
|
150
|
-
chunks.push(stdoutDecoder.decode()); stderrDecoder.decode(); text = chunks.join("");
|
|
151
|
-
r.state = "completed";
|
|
152
|
-
} catch (e) { r.state = "failed"; add(e instanceof DiagnosticFailure ? code(e) : "diagnostic-invalid-utf8"); }
|
|
153
|
-
}
|
|
154
|
-
chunks.length = 0;
|
|
155
|
-
child?.stdout?.destroy(); child?.stderr?.destroy();
|
|
156
|
-
if (!r.reasons.length) add("diagnostic-completed");
|
|
157
|
-
resolve({ operation: r, text: r.state === "completed" ? text : "" });
|
|
158
|
-
};
|
|
159
|
-
const poll = () => {
|
|
160
|
-
if (done) return;
|
|
161
|
-
if (clock() >= end - l.graceMs - l.confirmationMs && !canceled) cancel("diagnostic-deadline", "timed-out");
|
|
162
|
-
if (canceled && !forced && clock() - cancelAt >= l.graceMs) { forced = true; send("SIGKILL"); }
|
|
163
|
-
const live = alive();
|
|
164
|
-
if (exited && closed && outClosed && errClosed && !live) finish(false);
|
|
165
|
-
else if (exited && live && !canceled) cancel("diagnostic-group-unconfirmed");
|
|
166
|
-
if (spawnFailed && closed) finish(false);
|
|
167
|
-
};
|
|
168
|
-
const abort = () => cancel("diagnostic-canceled", "canceled");
|
|
169
|
-
try {
|
|
170
|
-
child = spawn(c.artifactPath, [recipe === "version" ? "--version" : "--help"], {
|
|
171
|
-
shell: false, detached: true, cwd: workspace, env: environment, stdio: ["ignore", "pipe", "pipe"]
|
|
172
|
-
});
|
|
173
|
-
} catch { spawnFailed = true; r.state = "failed"; r.terminationConfirmed = true; r.elapsedMs = elapsed(); add("diagnostic-spawn-failed"); resolve({ operation: r, text: "" }); return; }
|
|
174
|
-
// No awaits before handlers; no diagnostic text is ever sent to stdin.
|
|
175
|
-
child.on("spawn", () => { spawned = true; r.startObserved = true; if (done) send("SIGKILL"); else if (canceled) send("SIGTERM"); });
|
|
176
|
-
child.on("error", () => { if (done) return; if (!spawned) { spawnFailed = true; add("diagnostic-spawn-failed"); } else cancel("diagnostic-process-error"); });
|
|
177
|
-
child.on("exit", n => { exited = true; exitCode = n; poll(); });
|
|
178
|
-
child.on("close", () => { closed = true; poll(); });
|
|
179
|
-
child.stdout.on("close", () => { outClosed = true; poll(); });
|
|
180
|
-
child.stderr.on("close", () => { errClosed = true; poll(); });
|
|
181
|
-
child.stdout.on("error", () => cancel("diagnostic-process-error"));
|
|
182
|
-
child.stderr.on("error", () => cancel("diagnostic-process-error"));
|
|
183
|
-
child.stdout.on("data", b => {
|
|
184
|
-
if (done || canceled) return; r.stdoutBytes += b.length;
|
|
185
|
-
if (r.stdoutBytes > l.maxStdoutBytes) cancel("diagnostic-output-limit");
|
|
186
|
-
else try { chunks.push(stdoutDecoder.decode(b, { stream: true })); } catch { cancel("diagnostic-invalid-utf8"); }
|
|
187
|
-
});
|
|
188
|
-
child.stderr.on("data", b => {
|
|
189
|
-
if (done || canceled) return; r.stderrBytes += b.length;
|
|
190
|
-
if (r.stderrBytes > l.maxStderrBytes) cancel("diagnostic-stderr-limit");
|
|
191
|
-
else try { stderrDecoder.decode(b, { stream: true }); } catch { cancel("diagnostic-invalid-utf8"); }
|
|
192
|
-
});
|
|
193
|
-
signal?.addEventListener("abort", abort, { once: true }); if (signal?.aborted) abort();
|
|
194
|
-
timer = setInterval(poll, 10);
|
|
195
|
-
hardTimer = setTimeout(() => { send("SIGKILL"); poll(); if (!done) finish(true); }, Math.max(1, end - clock()));
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
return Object.freeze({ async run(...args) {
|
|
199
|
-
const r = { scope: "native-diagnostics-only", state: "blocked", nativeExecuted: false, inferenceRequested: false,
|
|
200
|
-
actualModelCalls: null, runtimeReady: false, verifiedAdmission: false, externalBillingVerified: false,
|
|
201
|
-
remoteCancellationVerified: false, spawnAttempts: 0, startsObserved: 0, elapsedMs: 0, operations: [], reasons: [] };
|
|
202
|
-
const observation = { declaredVersion: null, optionsPresent: [] };
|
|
203
|
-
let began, workspace, ownWorkspace, parentIdentity, claimed = false;
|
|
204
|
-
try {
|
|
205
|
-
began = clock(); const deadline = began + l.totalTimeoutMs;
|
|
206
|
-
if (invoked) fail("diagnostic-permit-unavailable"); invoked = true;
|
|
207
|
-
if (types.isProxy(authorization)) fail("diagnostic-permit-unavailable");
|
|
208
|
-
const permit = permits.get(authorization);
|
|
209
|
-
if (!permit || !permit.live || permit.used || permit.binding !== hash(cfg)) fail("diagnostic-permit-unavailable");
|
|
210
|
-
permit.used = true; claimed = true;
|
|
211
|
-
if (args.length) fail("diagnostic-input-forbidden");
|
|
212
|
-
if (!platformAdmitted) fail("diagnostic-platform-not-admitted");
|
|
213
|
-
if (dependencies.signal?.aborted) fail("diagnostic-canceled");
|
|
214
|
-
const home = process.env.HOME;
|
|
215
|
-
if (!safePath(home)) fail("diagnostic-path-unsafe");
|
|
216
|
-
parentIdentity = await privateParent(); await artifact(deadline);
|
|
217
|
-
workspace = await io.mkdtemp(path.join(cfg.workspaceParent, "diagnostic-work-"));
|
|
218
|
-
await io.chmod(workspace, 0o700); ownWorkspace = await files.directory(workspace);
|
|
219
|
-
const environment = { HOME: home, TMPDIR: workspace, PATH: "/usr/bin:/bin:/usr/sbin:/sbin", LANG: "C", LC_ALL: "C",
|
|
220
|
-
DISABLE_AUTOUPDATER: "1", DISABLE_UPDATES: "1", CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1", ENABLE_CLAUDEAI_MCP_SERVERS: "false" };
|
|
221
|
-
for (const recipe of ["version", "help"]) {
|
|
222
|
-
await files.directory(cfg.workspaceParent, parentIdentity); await files.directory(workspace, ownWorkspace);
|
|
223
|
-
if (!permit.live || dependencies.signal?.aborted) fail("diagnostic-canceled");
|
|
224
|
-
if (clock() >= deadline - l.graceMs - l.confirmationMs) fail("diagnostic-deadline");
|
|
225
|
-
const result = await runOperation(recipe, workspace, environment, deadline, dependencies.signal);
|
|
226
|
-
r.operations.push(result.operation); r.spawnAttempts += result.operation.spawnAttempts;
|
|
227
|
-
r.startsObserved += result.operation.startObserved ? 1 : 0; r.nativeExecuted = r.startsObserved > 0;
|
|
228
|
-
if (result.operation.state !== "completed") { r.state = result.operation.state; r.reasons = result.operation.reasons; break; }
|
|
229
|
-
await artifact(deadline);
|
|
230
|
-
const extracted = extractDiagnosticMetadata(recipe, result.text, options);
|
|
231
|
-
if (recipe === "version") observation.declaredVersion = extracted.declaredVersion;
|
|
232
|
-
else observation.optionsPresent = extracted.optionsPresent;
|
|
233
|
-
}
|
|
234
|
-
if (r.operations.length === 2 && r.operations.every(o => o.state === "completed")) { r.state = "completed"; r.reasons = ["diagnostic-completed"]; }
|
|
235
|
-
} catch (e) { r.reasons = [code(e)]; r.state = r.nativeExecuted ? "failed" : "blocked"; }
|
|
236
|
-
finally {
|
|
237
|
-
if (workspace && r.operations.every(o => o.terminationConfirmed)) {
|
|
238
|
-
try {
|
|
239
|
-
await files.directory(cfg.workspaceParent, parentIdentity); await files.directory(workspace, ownWorkspace);
|
|
240
|
-
await io.rmdir(workspace);
|
|
241
|
-
} catch { r.state = "indeterminate"; r.reasons = [...new Set([...r.reasons, "diagnostic-workspace-cleanup-required"])]; }
|
|
242
|
-
}
|
|
243
|
-
if (claimed) revokeDiagnosticPermit(authorization);
|
|
244
|
-
if (began !== undefined) {
|
|
245
|
-
r.elapsedMs = Math.max(0, Math.ceil(clock() - began));
|
|
246
|
-
if (r.elapsedMs > l.totalTimeoutMs) { r.state = "indeterminate"; r.reasons = [...new Set([...r.reasons, "diagnostic-deadline"])]; }
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
r.reasons.sort();
|
|
250
|
-
if (!valid.report(r) || !valid.observation(observation)) throw Error("Diagnostic report invariant failed");
|
|
251
|
-
return { report: r, observation }; // Observation is private; no raw streams or paths.
|
|
252
|
-
} });
|
|
253
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
2
|
-
import { CONTROLS, EFFECTS, hash, same, fresh, unique } from "./client-runtime-core.js";
|
|
3
|
-
import { copyInertJson, copyBytes, decode, parseEventJson, ParseFailure, fail } from "./client-output-json.js";
|
|
4
|
-
|
|
5
|
-
const SCHEMA_ID = "https://agent-toolkit.local/schemas/agent-client-native-evaluation.schema.json";
|
|
6
|
-
const MAX_INPUT_BYTES = 131072;
|
|
7
|
-
const SECTIONS = ["installation", "controls", "effects", "access", "accounting", "observations"];
|
|
8
|
-
|
|
9
|
-
// Trusted construction only. The caller supplies a schema and policy, never paths or callbacks.
|
|
10
|
-
export function createClientNativeEvaluator(schema, trustedPolicy) {
|
|
11
|
-
let contract; let policy;
|
|
12
|
-
try { contract = copyInertJson(schema); policy = copyInertJson(trustedPolicy); }
|
|
13
|
-
catch { throw Error("Invalid native evaluation configuration"); }
|
|
14
|
-
if (contract?.$id !== SCHEMA_ID) throw Error("Unsupported native evaluation schema");
|
|
15
|
-
const ajv = new Ajv2020({ strict: true, allErrors: true });
|
|
16
|
-
ajv.addFormat("date-time", { type: "string", validate: value => {
|
|
17
|
-
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(value)) return false;
|
|
18
|
-
const t = Date.parse(value);
|
|
19
|
-
return Number.isFinite(t) && new Date(t).toISOString() === value.replace(/Z$/, ".000Z");
|
|
20
|
-
} });
|
|
21
|
-
ajv.addSchema(contract);
|
|
22
|
-
const validator = name => ajv.compile({ $ref: `${SCHEMA_ID}#/$defs/${name}` });
|
|
23
|
-
const validInput = validator("input"); const validPolicy = validator("policy"); const validReport = validator("report");
|
|
24
|
-
if (!validPolicy(policy)) throw Error("Invalid native evaluation policy");
|
|
25
|
-
const revoked = new Set(policy.revokedEvidenceRefs); const policySha256 = hash(policy);
|
|
26
|
-
|
|
27
|
-
return function evaluateClientNativeEvidence(input) {
|
|
28
|
-
const r = { schemaVersion: "1.0.0", state: "invalid", evaluationId: null,
|
|
29
|
-
executed: false, runtimeReady: false, verifiedAdmission: false, reasons: [], missing: [],
|
|
30
|
-
audit: { inputSha256: null, bindingSha256: null, policySha256 } };
|
|
31
|
-
const blockers = new Set(); const missing = new Set();
|
|
32
|
-
const block = reason => blockers.add(reason);
|
|
33
|
-
function finish(state, reasons = []) {
|
|
34
|
-
r.state = state; r.reasons = [...new Set(reasons)].sort(); r.missing = [...missing].sort();
|
|
35
|
-
if (!validReport(r)) throw Error("Native evaluation report invariant failed");
|
|
36
|
-
return r;
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
// Strings/bytes use duplicate-aware decoding; objects never invoke conversion hooks.
|
|
40
|
-
const parsed = typeof input === "string" || (input && typeof input === "object" && ArrayBuffer.isView(input))
|
|
41
|
-
? parseEventJson(decode(copyBytes(input, MAX_INPUT_BYTES))) : input;
|
|
42
|
-
const d = copyInertJson(parsed);
|
|
43
|
-
if (Buffer.byteLength(JSON.stringify(d)) > MAX_INPUT_BYTES) fail("native-input-limit");
|
|
44
|
-
if (!validInput(d)) fail("invalid-native-evaluation-input");
|
|
45
|
-
if (d.controls && !unique(d.controls.map(c => c.controlId))) fail("duplicate-native-control");
|
|
46
|
-
if (d.effects && !unique(d.effects.map(e => e.effectId))) fail("duplicate-native-effect");
|
|
47
|
-
if (d.installation && !unique(d.installation.artifacts.map(a => a.artifactId))) fail("duplicate-native-artifact");
|
|
48
|
-
r.evaluationId = d.evaluationId; r.audit.inputSha256 = hash(d); r.audit.bindingSha256 = hash(d.binding);
|
|
49
|
-
if (!same(d.expectedBinding, d.binding)) block("native-binding-mismatch");
|
|
50
|
-
const scope = r.audit.bindingSha256;
|
|
51
|
-
const ref = (id, label) => { if (id !== null && revoked.has(id)) block(`native-evidence-revoked:${label}`); };
|
|
52
|
-
function assess(a, label) {
|
|
53
|
-
ref(a.evidenceRef, label);
|
|
54
|
-
if (a.scopeSha256 !== scope) block(`native-evidence-scope-mismatch:${label}`);
|
|
55
|
-
if (!fresh(a, d.now, policy.maxEvidenceAgeSeconds)) block(`native-evidence-not-fresh:${label}`);
|
|
56
|
-
if (a.status === "rejected") block(`native-evidence-rejected:${label}`);
|
|
57
|
-
else if (a.status !== "locally-tested") missing.add(`${label}.installation-test`);
|
|
58
|
-
else if (a.source !== "installation-test") block(`native-evidence-source-conflict:${label}`);
|
|
59
|
-
}
|
|
60
|
-
for (const section of SECTIONS) if (d[section] === undefined) missing.add(section);
|
|
61
|
-
if (d.installation) {
|
|
62
|
-
assess(d.installation.assessment, "installation");
|
|
63
|
-
const artifacts = [...d.installation.artifacts].sort((a, b) => a.artifactId < b.artifactId ? -1 : a.artifactId > b.artifactId ? 1 : 0);
|
|
64
|
-
if (hash(artifacts) !== d.binding.artifactSha256) block("native-artifact-set-mismatch");
|
|
65
|
-
const kinds = new Set(artifacts.map(a => a.kind));
|
|
66
|
-
if (kinds.has("wrapper") && (!kinds.has("interpreter") || !kinds.has("package"))) block("native-wrapper-dependencies-incomplete");
|
|
67
|
-
if (!kinds.has("binary") && !kinds.has("wrapper")) block("native-entry-artifact-missing");
|
|
68
|
-
}
|
|
69
|
-
for (const id of CONTROLS) {
|
|
70
|
-
const c = d.controls?.find(c => c.controlId === id); const label = `controls.${id}`;
|
|
71
|
-
if (!c) { missing.add(label); continue; }
|
|
72
|
-
assess(c.assessment, label);
|
|
73
|
-
for (const [key, suffix] of [["mechanismId", "mechanism"], ["positiveEvidenceRef", "positive-proof"], ["negativeEvidenceRef", "negative-proof"]]) {
|
|
74
|
-
if (c[key] === null) missing.add(`${label}.${suffix}`);
|
|
75
|
-
else if (key !== "mechanismId") ref(c[key], `${label}.${suffix}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
for (const id of EFFECTS) {
|
|
79
|
-
const e = d.effects?.find(e => e.effectId === id); const label = `effects.${id}`;
|
|
80
|
-
if (!e) { missing.add(label); continue; }
|
|
81
|
-
assess(e.assessment, label);
|
|
82
|
-
if (e.disposition !== "allowed" || e.presence === "unknown") block(`native-effect-unconfirmed:${id}`);
|
|
83
|
-
if (["native-auth", "provider-inference"].includes(id) && e.presence === "absent") block(`native-required-effect-absent:${id}`);
|
|
84
|
-
const a = e.authorization;
|
|
85
|
-
if (a.status !== "approved" || a.evidenceRef === null) block(`native-effect-not-authorized:${id}`);
|
|
86
|
-
if (a.scopeSha256 !== scope) block(`native-authorization-scope-mismatch:${id}`);
|
|
87
|
-
ref(a.evidenceRef, `${label}.authorization`);
|
|
88
|
-
}
|
|
89
|
-
if (d.access) {
|
|
90
|
-
assess(d.access.assessment, "access"); assess(d.access.billingAssessment, "billing");
|
|
91
|
-
if (d.access.access !== "subscription-session" || d.access.externalBilling !== "disabled") block("native-subscription-or-billing-unconfirmed");
|
|
92
|
-
}
|
|
93
|
-
if (d.accounting) {
|
|
94
|
-
assess(d.accounting.assessment, "accounting");
|
|
95
|
-
if (d.accounting.maxCallsPerStart === null || !d.accounting.limitEnforced) block("native-internal-call-ceiling-unconfirmed");
|
|
96
|
-
}
|
|
97
|
-
for (const observation of d.observations ?? []) block(`native-unresolved:${observation}`);
|
|
98
|
-
if (blockers.size) return finish("blocked", [...blockers]);
|
|
99
|
-
if (missing.size) return finish("incomplete", ["native-evidence-incomplete"]);
|
|
100
|
-
return finish("ready-for-installation-review", ["declared-evidence-only"]);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
if (!(error instanceof ParseFailure)) throw error;
|
|
103
|
-
return finish("invalid", [error.code]);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { constants } from "node:fs";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
import { copyInertJson } from "./client-output-json.js";
|
|
6
|
-
|
|
7
|
-
const changed = () => { throw Error("Pinned candidate unavailable"); };
|
|
8
|
-
const sig = s => JSON.stringify([s.dev, s.ino, s.uid, s.mode, s.size, s.mtimeMs, s.ctimeMs]);
|
|
9
|
-
export const absolutePhysicalName = p => typeof p === "string" && path.isAbsolute(p) && path.normalize(p) === p && !/[\x00-\x1f\x7f]/.test(p);
|
|
10
|
-
|
|
11
|
-
async function physical(name, io) {
|
|
12
|
-
if (!absolutePhysicalName(name) || name.split(path.sep).length > 64) changed();
|
|
13
|
-
let p = path.parse(name).root;
|
|
14
|
-
for (const part of name.slice(p.length).split(path.sep).filter(Boolean)) {
|
|
15
|
-
p = path.join(p, part); const s = await io.lstat(p);
|
|
16
|
-
if (s.isSymbolicLink()) changed();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Reads only the approved executable, never settings or credential files. */
|
|
21
|
-
export async function verifyPreflightCandidate(input, { io: overrides = {}, deadline = Infinity, monotonic = () => Number(process.hrtime.bigint() / 1000000n) } = {}) {
|
|
22
|
-
const c = copyInertJson(input), io = { ...fs, ...overrides };
|
|
23
|
-
await physical(path.dirname(c.entryPath), io); await physical(c.artifactPath, io);
|
|
24
|
-
const link = await io.lstat(c.entryPath), s = await io.lstat(c.artifactPath);
|
|
25
|
-
if (!link.isSymbolicLink() || link.ino !== c.expectedLinkIno || link.uid !== c.expectedUid || link.dev !== c.expectedDev ||
|
|
26
|
-
path.resolve(path.dirname(c.entryPath), await io.readlink(c.entryPath)) !== c.artifactPath ||
|
|
27
|
-
!s.isFile() || s.isSymbolicLink() || s.nlink !== 1 || s.size !== c.expectedSize || s.size > 536870912 ||
|
|
28
|
-
s.uid !== c.expectedUid || s.dev !== c.expectedDev || s.ino !== c.expectedIno || (s.mode & 4095) !== c.expectedMode ||
|
|
29
|
-
(s.mode & 0o022) || !(s.mode & 0o111)) changed();
|
|
30
|
-
const h = await io.open(c.artifactPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
31
|
-
const digest = createHash("sha256"), b = Buffer.alloc(1048576); let n = 0;
|
|
32
|
-
try {
|
|
33
|
-
if (sig(s) !== sig(await h.stat())) changed();
|
|
34
|
-
for (;;) {
|
|
35
|
-
if (monotonic() >= deadline) changed();
|
|
36
|
-
const r = await h.read(b, 0, b.length, null); if (!r.bytesRead) break;
|
|
37
|
-
n += r.bytesRead; if (n > c.expectedSize || n > 536870912) changed(); digest.update(b.subarray(0, r.bytesRead));
|
|
38
|
-
}
|
|
39
|
-
if (n !== c.expectedSize || digest.digest("hex") !== c.expectedSha256 || sig(s) !== sig(await h.stat()) ||
|
|
40
|
-
sig(s) !== sig(await io.lstat(c.artifactPath)) || sig(link) !== sig(await io.lstat(c.entryPath)) ||
|
|
41
|
-
path.resolve(path.dirname(c.entryPath), await io.readlink(c.entryPath)) !== c.artifactPath) changed();
|
|
42
|
-
await physical(c.artifactPath, io); await physical(path.dirname(c.entryPath), io);
|
|
43
|
-
} finally { await h.close(); }
|
|
44
|
-
return { unchanged: true };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Caller-specified, approved paths: lstat only, no contents, glob or recursion. */
|
|
48
|
-
export async function inspectPreflightMetadata(input, { lstat = fs.lstat } = {}) {
|
|
49
|
-
const entries = copyInertJson(input);
|
|
50
|
-
if (!Array.isArray(entries) || entries.length > 16 || new Set(entries.map(v => v.id)).size !== entries.length ||
|
|
51
|
-
entries.some(e => Object.keys(e).sort().join() !== "id,path" || typeof e.id !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(e.id) || !absolutePhysicalName(e.path) || e.path === path.parse(e.path).root)) throw Error("Invalid metadata inventory");
|
|
52
|
-
const output = [];
|
|
53
|
-
for (const e of entries) {
|
|
54
|
-
let p = path.parse(e.path).root, result = "missing";
|
|
55
|
-
try {
|
|
56
|
-
const parts = e.path.slice(p.length).split(path.sep).filter(Boolean);
|
|
57
|
-
if (parts.length > 64) throw Error("depth");
|
|
58
|
-
for (const [i, part] of parts.entries()) {
|
|
59
|
-
p = path.join(p, part); const s = await lstat(p);
|
|
60
|
-
if (s.isSymbolicLink()) { result = "unsafe"; break; }
|
|
61
|
-
if (i === parts.length - 1) result = s.isFile() ? "file" : s.isDirectory() ? "directory" : "unsafe";
|
|
62
|
-
else if (!s.isDirectory()) { result = "unsafe"; break; }
|
|
63
|
-
}
|
|
64
|
-
} catch (e2) { result = e2?.code === "ENOENT" ? "missing" : "unknown"; }
|
|
65
|
-
output.push({ id: e.id, kind: result });
|
|
66
|
-
}
|
|
67
|
-
return output;
|
|
68
|
-
}
|
|
@@ -1,95 +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
|
-
import { hash } from "./client-runtime-core.js";
|
|
5
|
-
|
|
6
|
-
export const PREFLIGHT_ID = "https://agent-toolkit.local/schemas/agent-client-native-preflight.schema.json";
|
|
7
|
-
export const PROJECTION_FIELDS = Object.freeze(["policy", "hooks", "commands", "mcp", "connectors", "api-helper", "third-party", "fallback", "delegation"]);
|
|
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
|
-
export function strictPreflightJson(input) {
|
|
11
|
-
if (types.isProxy(input)) fail("preflight-invalid-input");
|
|
12
|
-
const obj = typeof input === "string" || types.isUint8Array(input)
|
|
13
|
-
? parseEventJson(decode(copyBytes(input, 32768))) : copyInertJson(input);
|
|
14
|
-
return copyInertJson(parseEventJson(decode(copyBytes(JSON.stringify(obj), 32768))));
|
|
15
|
-
}
|
|
16
|
-
function validators(schema) {
|
|
17
|
-
const s = copyInertJson(schema);
|
|
18
|
-
if (s.$id !== PREFLIGHT_ID || JSON.stringify(s.$defs.field.properties.name.enum) !== JSON.stringify(PROJECTION_FIELDS)) throw Error("Unsupported preflight schema");
|
|
19
|
-
const ajv = new Ajv2020({ strict: true, allErrors: true }); ajv.addFormat("date-time", { type: "string", validate: stamp }); ajv.addSchema(s);
|
|
20
|
-
return Object.fromEntries(["input", "report", "auth"].map(n => [n, ajv.compile({ $ref: `${PREFLIGHT_ID}#/$defs/${n}` })]));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Extract only non-personal access fields; never echo unknown names or values. */
|
|
24
|
-
export function createNativeAccessExtractor(schema) {
|
|
25
|
-
const valid = validators(schema);
|
|
26
|
-
return input => {
|
|
27
|
-
const d = strictPreflightJson(input);
|
|
28
|
-
const auth = { loggedIn: d.loggedIn, authMethod: d.authMethod, subscriptionType: d.subscriptionType ?? null };
|
|
29
|
-
if (!valid.auth(auth) || !auth.loggedIn && auth.authMethod !== "none" || auth.loggedIn && auth.authMethod === "none") fail("preflight-invalid-access");
|
|
30
|
-
return auth;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Pure consistency review, not an authentication or capability factory. */
|
|
35
|
-
export function createNativePreflightEvaluator(schema, trustedPolicy) {
|
|
36
|
-
const valid = validators(schema), policy = copyInertJson(trustedPolicy);
|
|
37
|
-
if (Object.keys(policy).sort().join() !== "expectedScopeSha256,maxEvidenceAgeSeconds,revokedReferences" ||
|
|
38
|
-
!/^[a-f0-9]{64}$/.test(policy.expectedScopeSha256) || !Number.isSafeInteger(policy.maxEvidenceAgeSeconds) ||
|
|
39
|
-
policy.maxEvidenceAgeSeconds < 1 || policy.maxEvidenceAgeSeconds > 3600 || !Array.isArray(policy.revokedReferences) ||
|
|
40
|
-
policy.revokedReferences.length > 256 || policy.revokedReferences.some(v => typeof v !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(v))) throw Error("Invalid preflight policy");
|
|
41
|
-
const revoked = new Set(policy.revokedReferences);
|
|
42
|
-
return input => {
|
|
43
|
-
const r = { scope: "native-preflight-only", state: "invalid", queryEligible: false, nativeExecuted: false,
|
|
44
|
-
inferenceRequested: false, actualModelCalls: null, runtimeReady: false, verifiedAdmission: false,
|
|
45
|
-
externalBillingVerified: false, remoteCancellationVerified: false, reasons: [], unresolvedFields: [], audit: { inputSha256: null } };
|
|
46
|
-
try {
|
|
47
|
-
const d = strictPreflightJson(input);
|
|
48
|
-
if (!valid.input(d)) fail("preflight-invalid-input");
|
|
49
|
-
r.audit.inputSha256 = hash(d);
|
|
50
|
-
const blocked = new Set(), missing = new Set();
|
|
51
|
-
if (d.candidateScopeSha256 !== policy.expectedScopeSha256) blocked.add("preflight-binding-mismatch");
|
|
52
|
-
const fresh = (time, ref, scope) => {
|
|
53
|
-
if (scope !== null && scope !== policy.expectedScopeSha256 || ref !== null && revoked.has(ref) || time !== null && Date.parse(time) > Date.parse(d.now)) {
|
|
54
|
-
blocked.add("preflight-evidence-rejected"); return false;
|
|
55
|
-
}
|
|
56
|
-
return scope === policy.expectedScopeSha256 && time !== null && ref !== null && Date.parse(d.now) - Date.parse(time) <= policy.maxEvidenceAgeSeconds * 1000;
|
|
57
|
-
};
|
|
58
|
-
const fields = d.projection.fields;
|
|
59
|
-
if (new Set(fields.map(f => f.name)).size !== fields.length) blocked.add("preflight-duplicate-field");
|
|
60
|
-
if (!d.projection.safeSource) missing.add("safe-projection-unavailable");
|
|
61
|
-
for (const name of PROJECTION_FIELDS) {
|
|
62
|
-
const f = fields.find(v => v.name === name);
|
|
63
|
-
if (!f) { r.unresolvedFields.push(name); continue; }
|
|
64
|
-
if (f.state === "present") blocked.add("preflight-critical-control-present");
|
|
65
|
-
const a = f.assessment, current = fresh(a.checkedAt, a.referenceId, a.scopeSha256);
|
|
66
|
-
if (!["absent", "disabled"].includes(f.state) || a.source !== "locally-observed" || !current) r.unresolvedFields.push(name);
|
|
67
|
-
}
|
|
68
|
-
if (r.unresolvedFields.length) missing.add("preflight-controls-unresolved");
|
|
69
|
-
r.queryEligible = d.projection.safeSource && !r.unresolvedFields.length && !blocked.size;
|
|
70
|
-
if (!d.access) missing.add("preflight-access-unresolved");
|
|
71
|
-
else {
|
|
72
|
-
const a = d.access;
|
|
73
|
-
const current = fresh(a.assessment.checkedAt, a.assessment.referenceId, a.assessment.scopeSha256);
|
|
74
|
-
if (a.assessment.source !== "locally-observed" || !current) missing.add("preflight-access-unresolved");
|
|
75
|
-
if (!a.data.loggedIn || a.data.authMethod !== "claude.ai" || a.data.subscriptionType === "free") blocked.add("preflight-access-incompatible");
|
|
76
|
-
if (a.data.subscriptionType === null) missing.add("preflight-subscription-unresolved");
|
|
77
|
-
}
|
|
78
|
-
if (!d.economy) missing.add("preflight-economy-unresolved");
|
|
79
|
-
else {
|
|
80
|
-
const e = d.economy;
|
|
81
|
-
if (e.state === "enabled") blocked.add("preflight-economy-enabled");
|
|
82
|
-
if (e.state !== "disabled" || e.source !== "operator-attested" || !fresh(e.receivedAt, e.referenceId, e.scopeSha256)) missing.add("preflight-economy-unresolved");
|
|
83
|
-
if (e.sessionContinuity !== true) missing.add("preflight-session-unresolved");
|
|
84
|
-
}
|
|
85
|
-
r.state = blocked.size ? "blocked" : missing.size ? "incomplete" : "review-complete";
|
|
86
|
-
// Billing/access findings never authorize a diagnostic query by themselves.
|
|
87
|
-
if (blocked.size) r.queryEligible = false;
|
|
88
|
-
r.reasons = [...new Set([...blocked, ...missing])].sort();
|
|
89
|
-
if (!r.reasons.length) r.reasons = ["preflight-review-complete"];
|
|
90
|
-
r.unresolvedFields.sort();
|
|
91
|
-
} catch { r.reasons = ["preflight-invalid-input"]; r.queryEligible = false; r.audit.inputSha256 = null; }
|
|
92
|
-
if (!valid.report(r)) throw Error("Preflight report invariant failed");
|
|
93
|
-
return r;
|
|
94
|
-
};
|
|
95
|
-
}
|