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,158 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { copyInertJson } from "./client-output-json.js";
|
|
5
|
-
import { MEMORY_READ_TOOLS } from "./memory-mcp-policy.js";
|
|
6
|
-
import { containsSensitiveData, isCredentialPath } from "./sensitive-data.js";
|
|
7
|
-
|
|
8
|
-
export const MEMORY_CONNECTION_VERSION = "1.0.0";
|
|
9
|
-
export const MEMORY_CONNECTION_LIMITS = Object.freeze({
|
|
10
|
-
inputBytes: 131072,
|
|
11
|
-
reportBytes: 131072,
|
|
12
|
-
pathChars: 4096
|
|
13
|
-
});
|
|
14
|
-
export const MEMORY_CONNECTION_FACTS = Object.freeze({
|
|
15
|
-
evidence: "declared",
|
|
16
|
-
physicalPathsVerified: false,
|
|
17
|
-
localReadVerified: false,
|
|
18
|
-
nativeReadVerified: false,
|
|
19
|
-
runtimeVerified: false,
|
|
20
|
-
authorizationGranted: false,
|
|
21
|
-
executable: false,
|
|
22
|
-
applied: false,
|
|
23
|
-
wrote: false,
|
|
24
|
-
sent: false,
|
|
25
|
-
executed: false,
|
|
26
|
-
humanReviewRequired: true
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const INPUT_KEYS = [
|
|
30
|
-
"agent", "mcpName", "skillName", "nodePath", "toolkitRoot",
|
|
31
|
-
"manifestPath", "vaultPath", "sourcePath", "homeDirectory"
|
|
32
|
-
];
|
|
33
|
-
const ROOT_KEYS = ["toolkitRoot", "vaultPath", "sourcePath", "homeDirectory"];
|
|
34
|
-
const CONTROL = /[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/u;
|
|
35
|
-
const PRIVATE_PATH = /(?:^|\/)(?:\.git|\.obsidian|\.codex|\.claude|\.gemini|\.agents|\.secrets|\.credentials|\.npmrc|\.netrc|\.envrc)(?:\/|$)/i;
|
|
36
|
-
const RESERVED_NAMES = new Set(["__proto__", "constructor", "prototype"]);
|
|
37
|
-
|
|
38
|
-
export class MemoryConnectionInputError extends Error {
|
|
39
|
-
constructor(code) {
|
|
40
|
-
super(code);
|
|
41
|
-
this.name = "MemoryConnectionInputError";
|
|
42
|
-
this.code = code;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const reject = (code) => { throw new MemoryConnectionInputError(code); };
|
|
47
|
-
|
|
48
|
-
/** Reject conversion hooks before interpreting caller-supplied declarations. */
|
|
49
|
-
export function copyMemoryConnectionData(input) {
|
|
50
|
-
let data;
|
|
51
|
-
try { data = copyInertJson(input); }
|
|
52
|
-
catch { reject("MC_DATA_INVALID"); }
|
|
53
|
-
if (Buffer.byteLength(JSON.stringify(data)) > MEMORY_CONNECTION_LIMITS.inputBytes) {
|
|
54
|
-
reject("MC_INPUT_LIMIT");
|
|
55
|
-
}
|
|
56
|
-
return data;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function freezeMemoryConnectionData(data) {
|
|
60
|
-
const owned = copyMemoryConnectionData(data);
|
|
61
|
-
function freeze(value) {
|
|
62
|
-
if (value !== null && typeof value === "object") {
|
|
63
|
-
for (const child of Object.values(value)) freeze(child);
|
|
64
|
-
Object.freeze(value);
|
|
65
|
-
}
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
return freeze(owned);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Stable pin over inert declarations only; this does not verify their truth. */
|
|
72
|
-
export function memoryConnectionHash(input) {
|
|
73
|
-
const data = copyMemoryConnectionData(input);
|
|
74
|
-
const canonical = (value) => {
|
|
75
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
76
|
-
if (Array.isArray(value)) return "[" + value.map(canonical).join(",") + "]";
|
|
77
|
-
return "{" + Object.keys(value).sort().map((key) =>
|
|
78
|
-
JSON.stringify(key) + ":" + canonical(value[key])).join(",") + "}";
|
|
79
|
-
};
|
|
80
|
-
return createHash("sha256").update(canonical(data)).digest("hex");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function hasMemoryConnectionKeys(value, required, optional = []) {
|
|
84
|
-
let data, keys;
|
|
85
|
-
try {
|
|
86
|
-
data = copyMemoryConnectionData(value);
|
|
87
|
-
keys = copyMemoryConnectionData({ required, optional });
|
|
88
|
-
} catch { return false; }
|
|
89
|
-
return data !== null && typeof data === "object" && !Array.isArray(data) &&
|
|
90
|
-
Array.isArray(keys.required) && Array.isArray(keys.optional) &&
|
|
91
|
-
[...keys.required, ...keys.optional].every((key) => typeof key === "string") &&
|
|
92
|
-
keys.required.every((key) => Object.hasOwn(data, key)) &&
|
|
93
|
-
Object.keys(data).every((key) => keys.required.includes(key) || keys.optional.includes(key));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function isPath(value, allowClientDirectory = false) {
|
|
97
|
-
return typeof value === "string" && value.length > 0 &&
|
|
98
|
-
value.length <= MEMORY_CONNECTION_LIMITS.pathChars && value === value.trim() &&
|
|
99
|
-
Buffer.from(value, "utf8").toString("utf8") === value &&
|
|
100
|
-
!CONTROL.test(value) && !value.includes("\\") &&
|
|
101
|
-
path.posix.isAbsolute(value) && path.posix.normalize(value) === value &&
|
|
102
|
-
value.split("/").slice(1).every((part) => part && part !== "." && part !== "..") &&
|
|
103
|
-
!containsSensitiveData(value) && !isCredentialPath(value) &&
|
|
104
|
-
(allowClientDirectory || !PRIVATE_PATH.test(value));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function isName(value) {
|
|
108
|
-
return typeof value === "string" && /^[a-z][a-z0-9-]{0,63}$/.test(value) &&
|
|
109
|
-
!RESERVED_NAMES.has(value);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const within = (parent, child) => child === parent || child.startsWith(parent + "/");
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Builds a disabled protected invocation from explicit POSIX path declarations.
|
|
116
|
-
* No discovery, realpath, file inspection, runtime admission or execution occurs.
|
|
117
|
-
* A collector must independently verify paths and bytes before operational use.
|
|
118
|
-
*/
|
|
119
|
-
export function createMemoryConnectionDescriptor(input) {
|
|
120
|
-
const data = copyMemoryConnectionData(input);
|
|
121
|
-
if (!hasMemoryConnectionKeys(data, INPUT_KEYS)) reject("MC_DESCRIPTOR_INVALID");
|
|
122
|
-
if (data.agent !== "codex") reject("MC_AGENT_UNSUPPORTED");
|
|
123
|
-
if (!isName(data.mcpName) || !isName(data.skillName)) reject("MC_NAME_INVALID");
|
|
124
|
-
for (const key of ["nodePath", "manifestPath", ...ROOT_KEYS]) {
|
|
125
|
-
if (!isPath(data[key])) reject("MC_PATH_INVALID");
|
|
126
|
-
}
|
|
127
|
-
if (data.vaultPath === data.homeDirectory ||
|
|
128
|
-
within(data.sourcePath, data.vaultPath) || within(data.vaultPath, data.sourcePath)) {
|
|
129
|
-
reject("MC_PATH_OVERLAP");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const binPath = path.posix.join(data.toolkitRoot, "bin", "project-memory-mcp.js");
|
|
133
|
-
const source = path.posix.join(data.vaultPath, "07-AGENTES", "skills", data.skillName);
|
|
134
|
-
const target = path.posix.join(data.homeDirectory, ".agents", "skills", data.skillName);
|
|
135
|
-
const configurationPath = path.posix.join(data.homeDirectory, ".codex", "config.toml");
|
|
136
|
-
if (!isPath(binPath) || !isPath(source) ||
|
|
137
|
-
!isPath(target, true) || !isPath(configurationPath, true)) {
|
|
138
|
-
reject("MC_PATH_INVALID");
|
|
139
|
-
}
|
|
140
|
-
const descriptor = {
|
|
141
|
-
schemaVersion: MEMORY_CONNECTION_VERSION,
|
|
142
|
-
identity: data,
|
|
143
|
-
server: {
|
|
144
|
-
command: data.nodePath,
|
|
145
|
-
args: [binPath, "--manifest", data.manifestPath],
|
|
146
|
-
cwd: data.toolkitRoot,
|
|
147
|
-
enabled_tools: [...MEMORY_READ_TOOLS],
|
|
148
|
-
enabled: false
|
|
149
|
-
},
|
|
150
|
-
skill: { source, target },
|
|
151
|
-
configurationPath,
|
|
152
|
-
facts: { ...MEMORY_CONNECTION_FACTS }
|
|
153
|
-
};
|
|
154
|
-
if (Buffer.byteLength(JSON.stringify(descriptor)) > MEMORY_CONNECTION_LIMITS.reportBytes) {
|
|
155
|
-
reject("MC_REPORT_LIMIT");
|
|
156
|
-
}
|
|
157
|
-
return freezeMemoryConnectionData(descriptor);
|
|
158
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { copyInertJson } from "./client-output-json.js";
|
|
2
|
-
import {
|
|
3
|
-
createMemoryConnectionDescriptor, freezeMemoryConnectionData, memoryConnectionHash,
|
|
4
|
-
MEMORY_CONNECTION_FACTS, MEMORY_CONNECTION_VERSION
|
|
5
|
-
} from "./memory-connection-descriptor.js";
|
|
6
|
-
import { containsSensitiveData } from "./sensitive-data.js";
|
|
7
|
-
|
|
8
|
-
export const MEMORY_CONNECTION_DIAGNOSTIC_LIMITS = Object.freeze({
|
|
9
|
-
inputBytes: 128 * 1024, reportBytes: 128 * 1024,
|
|
10
|
-
depth: 64, nodes: 30000, arrayItems: 256, stringChars: 4096, serverItems: 16
|
|
11
|
-
});
|
|
12
|
-
const ROLES = ["configuration", "skill", "artifacts", "manifest", "package"];
|
|
13
|
-
const ARTIFACT_KEYS = ["nodeSha256", "binSha256", "manifestSha256", "packageJsonSha256", "packageLockSha256"];
|
|
14
|
-
const PIN_KEYS = ["configurationSha256", "skillSha256", ...ARTIFACT_KEYS];
|
|
15
|
-
const FIELDS = {
|
|
16
|
-
configuration: ["state", "mcpName", "fileState", "entryState", "configurationSha256", "metadataSha256", "server"],
|
|
17
|
-
skill: ["state", "skillName", "sourceSha256", "metadataSha256", "resolvedSource"],
|
|
18
|
-
artifacts: ["state", "hashes", "metadataSha256"],
|
|
19
|
-
manifest: ["state", "descriptorSha256", "manifestSha256"],
|
|
20
|
-
package: ["state", "descriptorSha256", "packageJsonSha256", "packageLockSha256"]
|
|
21
|
-
};
|
|
22
|
-
const STATES = {
|
|
23
|
-
configuration: ["observed", "absent", "blocked", "invalid"],
|
|
24
|
-
skill: ["matched", "absent", "conflict", "blocked", "invalid"],
|
|
25
|
-
artifacts: ["matched", "blocked", "invalid"],
|
|
26
|
-
manifest: ["validated", "blocked", "invalid"], package: ["consistent", "blocked", "invalid"]
|
|
27
|
-
};
|
|
28
|
-
const HASH = /^[a-f0-9]{64}$/;
|
|
29
|
-
const CONTROL = /[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/u;
|
|
30
|
-
const code = name => "MC_DIAGNOSTIC_" + name;
|
|
31
|
-
const object = value => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32
|
-
const hash = value => typeof value === "string" && HASH.test(value);
|
|
33
|
-
const exact = (value, keys) => object(value) && Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
34
|
-
const within = (root, full) => full === root || full.startsWith(root + "/");
|
|
35
|
-
class Rejected extends Error {
|
|
36
|
-
constructor(reason, state = "invalid") { super(reason); this.reason = reason; this.state = state; }
|
|
37
|
-
}
|
|
38
|
-
const requireInput = condition => { if (!condition) throw new Rejected(code("INPUT")); };
|
|
39
|
-
|
|
40
|
-
function captured(input) {
|
|
41
|
-
let data;
|
|
42
|
-
try { data = copyInertJson(input); }
|
|
43
|
-
catch (error) {
|
|
44
|
-
if (error?.code === "metadata-limit") throw new Rejected(code("LIMIT"), "blocked");
|
|
45
|
-
throw new Rejected(code("INPUT"));
|
|
46
|
-
}
|
|
47
|
-
if (Buffer.byteLength(JSON.stringify(data)) > MEMORY_CONNECTION_DIAGNOSTIC_LIMITS.inputBytes) {
|
|
48
|
-
throw new Rejected(code("LIMIT"), "blocked");
|
|
49
|
-
}
|
|
50
|
-
requireInput(exact(data, ["schemaVersion", "descriptor", "reviewedPins", "components"]));
|
|
51
|
-
requireInput(data.schemaVersion === MEMORY_CONNECTION_VERSION);
|
|
52
|
-
let descriptor;
|
|
53
|
-
try {
|
|
54
|
-
descriptor = createMemoryConnectionDescriptor(data.descriptor?.identity);
|
|
55
|
-
requireInput(memoryConnectionHash(descriptor) === memoryConnectionHash(data.descriptor));
|
|
56
|
-
const { toolkitRoot, vaultPath, manifestPath } = descriptor.identity;
|
|
57
|
-
requireInput(!within(toolkitRoot, vaultPath) && !within(vaultPath, toolkitRoot) && manifestPath.startsWith(vaultPath + "/"));
|
|
58
|
-
} catch { throw new Rejected(code("INPUT")); }
|
|
59
|
-
requireInput(exact(data.reviewedPins, PIN_KEYS));
|
|
60
|
-
for (const key of PIN_KEYS) requireInput(hash(data.reviewedPins[key]) || key === "configurationSha256" && data.reviewedPins[key] === null);
|
|
61
|
-
requireInput(exact(data.components, ROLES));
|
|
62
|
-
// Every projection is checked before any partial classification is published.
|
|
63
|
-
for (const role of ROLES) projection(role, data.components[role], descriptor);
|
|
64
|
-
return { data, descriptor };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function strings(value) {
|
|
68
|
-
if (typeof value === "string") {
|
|
69
|
-
requireInput(value.length <= MEMORY_CONNECTION_DIAGNOSTIC_LIMITS.stringChars && value === value.trim() &&
|
|
70
|
-
!CONTROL.test(value) && Buffer.from(value, "utf8").toString("utf8") === value);
|
|
71
|
-
} else if (value !== null && typeof value === "object") {
|
|
72
|
-
for (const child of Object.values(value)) strings(child);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function projection(role, item, descriptor) {
|
|
77
|
-
if (item === null) return;
|
|
78
|
-
requireInput(exact(item, ["bindingSha256", ...FIELDS[role]]) && hash(item.bindingSha256) && STATES[role].includes(item.state));
|
|
79
|
-
const negative = ["blocked", "invalid"].includes(item.state);
|
|
80
|
-
if (role === "configuration") {
|
|
81
|
-
requireInput(typeof item.mcpName === "string" || negative && item.mcpName === null);
|
|
82
|
-
if (negative) requireInput(item.mcpName === null || item.mcpName === descriptor.identity.mcpName);
|
|
83
|
-
if (item.state === "observed") {
|
|
84
|
-
requireInput(item.fileState === "present" && hash(item.configurationSha256) && hash(item.metadataSha256));
|
|
85
|
-
requireInput(item.entryState === "observed" && object(item.server) || item.entryState === "absent" && item.server === null);
|
|
86
|
-
strings(item.server);
|
|
87
|
-
} else if (item.state === "absent") {
|
|
88
|
-
requireInput(item.fileState === "absent" && item.entryState === null && item.server === null && item.configurationSha256 === null && hash(item.metadataSha256));
|
|
89
|
-
} else {
|
|
90
|
-
requireInput(item.fileState === "unknown" && item.entryState === null && item.server === null && item.configurationSha256 === null && item.metadataSha256 === null);
|
|
91
|
-
}
|
|
92
|
-
} else if (role === "skill") {
|
|
93
|
-
requireInput(typeof item.skillName === "string" || negative && item.skillName === null);
|
|
94
|
-
if (negative) requireInput(item.skillName === null || item.skillName === descriptor.identity.skillName);
|
|
95
|
-
if (["matched", "absent"].includes(item.state)) {
|
|
96
|
-
requireInput(hash(item.sourceSha256) && hash(item.metadataSha256));
|
|
97
|
-
requireInput(item.state === "matched" ? typeof item.resolvedSource === "string" : item.resolvedSource === null);
|
|
98
|
-
strings(item.resolvedSource);
|
|
99
|
-
} else requireInput(item.sourceSha256 === null && item.metadataSha256 === null && item.resolvedSource === null);
|
|
100
|
-
} else if (role === "artifacts") {
|
|
101
|
-
requireInput(item.state === "matched" ? exact(item.hashes, ARTIFACT_KEYS) && ARTIFACT_KEYS.every(key => hash(item.hashes[key])) && hash(item.metadataSha256) :
|
|
102
|
-
item.hashes === null && item.metadataSha256 === null);
|
|
103
|
-
} else {
|
|
104
|
-
const hashes = role === "manifest" ? ["descriptorSha256", "manifestSha256"] : ["descriptorSha256", "packageJsonSha256", "packageLockSha256"];
|
|
105
|
-
requireInput(hashes.every(key => negative ? item[key] === null : hash(item[key])));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function serverMatches(server, expected) {
|
|
110
|
-
if (!exact(server, ["command", "args", "cwd", "enabled_tools", "enabled"]) ||
|
|
111
|
-
typeof server.command !== "string" || typeof server.cwd !== "string" || typeof server.enabled !== "boolean" ||
|
|
112
|
-
!Array.isArray(server.args) || !Array.isArray(server.enabled_tools) ||
|
|
113
|
-
server.args.length > MEMORY_CONNECTION_DIAGNOSTIC_LIMITS.serverItems || server.enabled_tools.length > MEMORY_CONNECTION_DIAGNOSTIC_LIMITS.serverItems ||
|
|
114
|
-
!server.args.every(arg => typeof arg === "string") || !server.enabled_tools.every(tool => typeof tool === "string")) return false;
|
|
115
|
-
return server.command === expected.command && server.cwd === expected.cwd &&
|
|
116
|
-
server.args.length === expected.args.length && server.args.every((arg, i) => arg === expected.args[i]) &&
|
|
117
|
-
server.enabled_tools.length === expected.enabled_tools.length && new Set(server.enabled_tools).size === server.enabled_tools.length &&
|
|
118
|
-
expected.enabled_tools.every(tool => server.enabled_tools.includes(tool));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function component(role, item, descriptor, binding, pins) {
|
|
122
|
-
const output = (status, reason) => ({ id: role, status, code: code(reason) });
|
|
123
|
-
if (item === null) return output("not-provided", "MISSING");
|
|
124
|
-
if (item.bindingSha256 !== binding || ["manifest", "package"].includes(role) && item.descriptorSha256 !== null && item.descriptorSha256 !== binding) {
|
|
125
|
-
return output("blocked", "BINDING");
|
|
126
|
-
}
|
|
127
|
-
if (role === "configuration" && ["observed", "absent"].includes(item.state) && item.configurationSha256 !== pins.configurationSha256 ||
|
|
128
|
-
role === "skill" && ["matched", "absent"].includes(item.state) && item.sourceSha256 !== pins.skillSha256 ||
|
|
129
|
-
role === "artifacts" && item.state === "matched" && ARTIFACT_KEYS.some(key => item.hashes[key] !== pins[key]) ||
|
|
130
|
-
role === "manifest" && item.state === "validated" && item.manifestSha256 !== pins.manifestSha256 ||
|
|
131
|
-
role === "package" && item.state === "consistent" && ["packageJsonSha256", "packageLockSha256"].some(key => item[key] !== pins[key])) {
|
|
132
|
-
return output("blocked", "PINS");
|
|
133
|
-
}
|
|
134
|
-
if (["blocked", "invalid"].includes(item.state)) return output("blocked", role.toUpperCase());
|
|
135
|
-
if (role === "configuration") {
|
|
136
|
-
if (item.mcpName !== descriptor.identity.mcpName) return output("conflict", "CONFIGURATION");
|
|
137
|
-
if (item.state === "absent" || item.entryState === "absent") return output("missing", "MISSING");
|
|
138
|
-
if (!serverMatches(item.server, descriptor.server)) return output("conflict", "CONFIGURATION");
|
|
139
|
-
if (!item.server.enabled) return output("disabled", "DISABLED");
|
|
140
|
-
}
|
|
141
|
-
if (role === "skill") {
|
|
142
|
-
if (item.skillName !== descriptor.identity.skillName || item.state === "conflict" ||
|
|
143
|
-
item.state === "matched" && item.resolvedSource !== descriptor.skill.source) return output("conflict", "SKILL");
|
|
144
|
-
if (item.state === "absent") return output("missing", "MISSING");
|
|
145
|
-
}
|
|
146
|
-
return output("declared-matched", "MATCH");
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function report(state, reasons, components = [], hashes = {}) {
|
|
150
|
-
const result = {
|
|
151
|
-
schemaVersion: MEMORY_CONNECTION_VERSION, state, components, reasons: [...new Set(reasons)].sort(),
|
|
152
|
-
descriptorSha256: null, bundleHash: null, ...hashes,
|
|
153
|
-
facts: {
|
|
154
|
-
...MEMORY_CONNECTION_FACTS, evidence: "declared-reports", verificationScope: "cross-report-declarations-only",
|
|
155
|
-
declarationsLinked: state === "coherent", provenanceVerified: false, snapshotAtomicVerified: false, freshnessVerified: false,
|
|
156
|
-
skillLoadedVerified: false, runtimeVersionVerified: false, runtimeCompatibilityVerified: false, installedDependenciesVerified: false
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
if (Buffer.byteLength(JSON.stringify(result)) > MEMORY_CONNECTION_DIAGNOSTIC_LIMITS.reportBytes) throw new Rejected(code("LIMIT"), "blocked");
|
|
160
|
-
return freezeMemoryConnectionData(result);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Compare caller-declared projections, never authenticate origin or admit a runtime. */
|
|
164
|
-
export function summarizeMemoryConnectionEvidence(input) {
|
|
165
|
-
try {
|
|
166
|
-
const { data, descriptor } = captured(input);
|
|
167
|
-
if (containsSensitiveData(JSON.stringify(data))) return report("blocked", [code("SENSITIVE")]);
|
|
168
|
-
const binding = memoryConnectionHash(descriptor);
|
|
169
|
-
const components = ROLES.map(role => component(role, data.components[role], descriptor, binding, data.reviewedPins));
|
|
170
|
-
const state = components.some(c => ["blocked", "conflict"].includes(c.status)) ? "blocked" :
|
|
171
|
-
components.some(c => ["missing", "disabled", "not-provided"].includes(c.status)) ? "incomplete" : "coherent";
|
|
172
|
-
if (state !== "coherent") return report(state, components.filter(c => c.status !== "declared-matched").map(c => c.code), components);
|
|
173
|
-
return report("coherent", [code("COHERENT")], components, { descriptorSha256: binding, bundleHash: memoryConnectionHash(data) });
|
|
174
|
-
} catch (error) {
|
|
175
|
-
return report(error instanceof Rejected ? error.state : "blocked", [error instanceof Rejected ? error.reason : code("VALIDATION")]);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { constants } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
copyMemoryConnectionData, freezeMemoryConnectionData,
|
|
8
|
-
MEMORY_CONNECTION_FACTS, MEMORY_CONNECTION_VERSION
|
|
9
|
-
} from "./memory-connection-descriptor.js";
|
|
10
|
-
import { readMemoryConnectionToml, MEMORY_CONNECTION_TOML_LIMITS } from "./memory-connection-toml.js";
|
|
11
|
-
import { containsSensitiveData, isCredentialPath } from "./sensitive-data.js";
|
|
12
|
-
|
|
13
|
-
export const MEMORY_CONNECTION_FILE_LIMITS = Object.freeze({
|
|
14
|
-
fileBytes: MEMORY_CONNECTION_TOML_LIMITS.inputBytes, chunkBytes: 65536,
|
|
15
|
-
pathChars: 4096, components: 64, reportBytes: 131072
|
|
16
|
-
});
|
|
17
|
-
export const MEMORY_CONNECTION_OPEN_FLAGS = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
|
|
18
|
-
const CONTROL = /[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/u;
|
|
19
|
-
const PRIVATE_ROOT = /(?:^|\/)(?:\.git|\.obsidian|\.codex|\.claude|\.gemini|\.agents|\.credentials|\.secrets)(?:\/|$)/i;
|
|
20
|
-
class Rejected extends Error {
|
|
21
|
-
constructor(code, state = "blocked") { super(code); this.code = code; this.state = state; }
|
|
22
|
-
}
|
|
23
|
-
const reject = (code, state) => { throw new Rejected(code, state); };
|
|
24
|
-
const errno = (error) => error instanceof Error && typeof error.code === "string" ? error.code : "";
|
|
25
|
-
const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
26
|
-
const directorySignature = (s) => JSON.stringify([s.dev, s.ino, s.uid, s.gid, s.mode]);
|
|
27
|
-
const fileSignature = (s) => JSON.stringify([s.dev, s.ino, s.uid, s.gid, s.mode, s.nlink, s.size, s.mtimeMs, s.ctimeMs]);
|
|
28
|
-
|
|
29
|
-
function validPath(value) {
|
|
30
|
-
return typeof value === "string" && value.length > 1 && value.length <= MEMORY_CONNECTION_FILE_LIMITS.pathChars &&
|
|
31
|
-
value === value.trim() && Buffer.from(value, "utf8").toString("utf8") === value &&
|
|
32
|
-
!CONTROL.test(value) && !value.includes("\\") && path.posix.isAbsolute(value) &&
|
|
33
|
-
path.posix.normalize(value) === value && !value.endsWith("/") &&
|
|
34
|
-
value.split("/").slice(1).every((part) => part && part !== "." && part !== "..") &&
|
|
35
|
-
value.split("/").length - 1 <= MEMORY_CONNECTION_FILE_LIMITS.components &&
|
|
36
|
-
!containsSensitiveData(value) && !isCredentialPath(value);
|
|
37
|
-
}
|
|
38
|
-
function inputData(input) {
|
|
39
|
-
let data;
|
|
40
|
-
try { data = copyMemoryConnectionData(input); } catch { reject("MC_FILES_INPUT", "invalid"); }
|
|
41
|
-
const required = ["homeDirectory", "configurationPath", "mcpName"];
|
|
42
|
-
if (!data || Array.isArray(data) || Object.keys(data).length !== required.length ||
|
|
43
|
-
!required.every((key) => Object.hasOwn(data, key)) ||
|
|
44
|
-
!validPath(data.homeDirectory) || PRIVATE_ROOT.test(data.homeDirectory) ||
|
|
45
|
-
!validPath(data.configurationPath) || data.configurationPath !== data.homeDirectory + "/.codex/config.toml" ||
|
|
46
|
-
typeof data.mcpName !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(data.mcpName) ||
|
|
47
|
-
["constructor", "prototype", "__proto__"].includes(data.mcpName)) reject("MC_FILES_INPUT", "invalid");
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function safeDirectory(s, uid, insideHome) {
|
|
52
|
-
if (!s.isDirectory() || s.isSymbolicLink() || !(s.mode & 0o100)) reject("MC_FILES_PARENT_UNSAFE");
|
|
53
|
-
if (insideHome) {
|
|
54
|
-
if (s.uid !== uid || s.mode & 0o7022) reject("MC_FILES_PARENT_UNSAFE");
|
|
55
|
-
} else {
|
|
56
|
-
// Root-owned sticky temporary ancestors are allowed ONLY before the owned home.
|
|
57
|
-
const sharedTemporary = s.uid === 0 && (s.mode & 0o7777) === 0o1777;
|
|
58
|
-
if (![0, uid].includes(s.uid) || !sharedTemporary && s.mode & 0o7022) reject("MC_FILES_PARENT_UNSAFE");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function safeFile(s, uid) {
|
|
62
|
-
if (!s.isFile() || s.isSymbolicLink() || s.uid !== uid || s.nlink !== 1 || (s.mode & 0o7777) !== 0o600) {
|
|
63
|
-
reject("MC_FILES_FILE_UNSAFE");
|
|
64
|
-
}
|
|
65
|
-
if (!Number.isSafeInteger(s.size) || s.size < 0 || s.size > MEMORY_CONNECTION_FILE_LIMITS.fileBytes) {
|
|
66
|
-
reject("MC_FILES_LIMIT");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function inspect(io, data, uid) {
|
|
70
|
-
const parents = [];
|
|
71
|
-
let current = "/";
|
|
72
|
-
const root = await io.lstat(current); safeDirectory(root, uid, false);
|
|
73
|
-
parents.push({ path: current, signature: directorySignature(root) });
|
|
74
|
-
const parts = data.configurationPath.slice(1).split("/");
|
|
75
|
-
for (let index = 0; index < parts.length; index++) {
|
|
76
|
-
current = path.posix.join(current, parts[index]);
|
|
77
|
-
let s;
|
|
78
|
-
try { s = await io.lstat(current); }
|
|
79
|
-
catch (error) {
|
|
80
|
-
if (errno(error) === "ENOENT" && [data.homeDirectory + "/.codex", data.configurationPath].includes(current)) {
|
|
81
|
-
return { parents, file: null, missing: current };
|
|
82
|
-
}
|
|
83
|
-
reject("MC_FILES_UNREADABLE");
|
|
84
|
-
}
|
|
85
|
-
if (index === parts.length - 1) { safeFile(s, uid); return { parents, file: s, missing: null }; }
|
|
86
|
-
safeDirectory(s, uid, current === data.homeDirectory || current.startsWith(data.homeDirectory + "/"));
|
|
87
|
-
parents.push({ path: current, signature: directorySignature(s) });
|
|
88
|
-
}
|
|
89
|
-
reject("MC_FILES_INPUT", "invalid");
|
|
90
|
-
}
|
|
91
|
-
async function recheck(io, data, snapshot, uid) {
|
|
92
|
-
for (const parent of snapshot.parents) {
|
|
93
|
-
let s;
|
|
94
|
-
try { s = await io.lstat(parent.path); } catch { reject("MC_FILES_CHANGED"); }
|
|
95
|
-
safeDirectory(s, uid, parent.path === data.homeDirectory || parent.path.startsWith(data.homeDirectory + "/"));
|
|
96
|
-
if (directorySignature(s) !== parent.signature) reject("MC_FILES_CHANGED");
|
|
97
|
-
}
|
|
98
|
-
if (snapshot.missing) {
|
|
99
|
-
try { await io.lstat(snapshot.missing); }
|
|
100
|
-
catch (error) { if (errno(error) === "ENOENT") return; reject("MC_FILES_CHANGED"); }
|
|
101
|
-
reject("MC_FILES_CHANGED");
|
|
102
|
-
}
|
|
103
|
-
let named;
|
|
104
|
-
try { named = await io.lstat(data.configurationPath); } catch { reject("MC_FILES_CHANGED"); }
|
|
105
|
-
safeFile(named, uid);
|
|
106
|
-
if (fileSignature(named) !== fileSignature(snapshot.file)) reject("MC_FILES_CHANGED");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Reads one explicit configuration in a verified POSIX path; never discovers,
|
|
111
|
-
* writes, repairs or launches anything. IO overrides are TRUSTED test doubles,
|
|
112
|
-
* not an authorization/sandbox boundary and never evidence of native local IO.
|
|
113
|
-
* Name/descriptor checks detect observable races, not atomic openat/ABA isolation.
|
|
114
|
-
*/
|
|
115
|
-
export async function collectMemoryConnectionConfiguration(input, dependencies = {}) {
|
|
116
|
-
let data = null;
|
|
117
|
-
let nativeIO = false, io;
|
|
118
|
-
const result = (state, details = {}) => {
|
|
119
|
-
const success = state === "observed" || state === "absent";
|
|
120
|
-
const read = state === "observed";
|
|
121
|
-
const report = {
|
|
122
|
-
schemaVersion: MEMORY_CONNECTION_VERSION, state, mcpName: data?.mcpName ?? null,
|
|
123
|
-
fileState: read ? "present" : state === "absent" ? "absent" : "unknown",
|
|
124
|
-
entryState: null, configurationSha256: null, metadataSha256: null,
|
|
125
|
-
server: null, ranges: null, reasons: [], ...details,
|
|
126
|
-
facts: {
|
|
127
|
-
...MEMORY_CONNECTION_FACTS, verificationScope: "configuration-only",
|
|
128
|
-
evidence: success ? nativeIO ? read ? "local-file" : "local-metadata" : "simulated-local-file" : "none",
|
|
129
|
-
configurationPathVerified: success && nativeIO,
|
|
130
|
-
configurationSourceVerified: read && nativeIO,
|
|
131
|
-
localReadVerified: read && nativeIO,
|
|
132
|
-
byteSyntaxVerified: read
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
if (Buffer.byteLength(JSON.stringify(report)) > MEMORY_CONNECTION_FILE_LIMITS.reportBytes) reject("MC_FILES_REPORT_LIMIT");
|
|
136
|
-
return freezeMemoryConnectionData(report);
|
|
137
|
-
};
|
|
138
|
-
try {
|
|
139
|
-
data = inputData(input);
|
|
140
|
-
nativeIO = dependencies.io === undefined;
|
|
141
|
-
io = dependencies.io ?? fs;
|
|
142
|
-
const uid = process.getuid?.();
|
|
143
|
-
if (!["darwin", "linux"].includes(process.platform) || !Number.isSafeInteger(uid) || constants.O_NOFOLLOW === undefined) {
|
|
144
|
-
reject("MC_FILES_PLATFORM");
|
|
145
|
-
}
|
|
146
|
-
const snapshot = await inspect(io, data, uid);
|
|
147
|
-
const metadataHash = () => digest(JSON.stringify({
|
|
148
|
-
parents: snapshot.parents, path: data.configurationPath,
|
|
149
|
-
file: snapshot.file ? fileSignature(snapshot.file) : null, missing: snapshot.missing
|
|
150
|
-
}));
|
|
151
|
-
await recheck(io, data, snapshot, uid);
|
|
152
|
-
if (snapshot.missing) return result("absent", { metadataSha256: metadataHash(), reasons: ["MC_FILES_MISSING"] });
|
|
153
|
-
let handle;
|
|
154
|
-
try { handle = await io.open(data.configurationPath, MEMORY_CONNECTION_OPEN_FLAGS); }
|
|
155
|
-
catch (error) { reject(errno(error) === "ELOOP" ? "MC_FILES_FILE_UNSAFE" : "MC_FILES_UNREADABLE"); }
|
|
156
|
-
let bytes;
|
|
157
|
-
try {
|
|
158
|
-
const opened = await handle.stat(); safeFile(opened, uid);
|
|
159
|
-
if (fileSignature(opened) !== fileSignature(snapshot.file)) reject("MC_FILES_CHANGED");
|
|
160
|
-
// Recheck the whole named chain BEFORE the first content read, too.
|
|
161
|
-
await recheck(io, data, snapshot, uid);
|
|
162
|
-
bytes = Buffer.alloc(snapshot.file.size);
|
|
163
|
-
let offset = 0;
|
|
164
|
-
while (offset < bytes.length) {
|
|
165
|
-
const request = Math.min(MEMORY_CONNECTION_FILE_LIMITS.chunkBytes, bytes.length - offset);
|
|
166
|
-
const { bytesRead } = await handle.read(bytes, offset, request, offset);
|
|
167
|
-
if (!Number.isSafeInteger(bytesRead) || bytesRead < 0 || bytesRead > request) reject("MC_FILES_READ");
|
|
168
|
-
if (bytesRead === 0) reject("MC_FILES_CHANGED");
|
|
169
|
-
offset += bytesRead;
|
|
170
|
-
}
|
|
171
|
-
const after = await handle.stat(); safeFile(after, uid);
|
|
172
|
-
if (fileSignature(after) !== fileSignature(snapshot.file)) reject("MC_FILES_CHANGED");
|
|
173
|
-
await recheck(io, data, snapshot, uid);
|
|
174
|
-
} finally {
|
|
175
|
-
try { await handle.close(); } catch { reject("MC_FILES_CLOSE"); }
|
|
176
|
-
}
|
|
177
|
-
await recheck(io, data, snapshot, uid);
|
|
178
|
-
const parsed = readMemoryConnectionToml(bytes, { mcpName: data.mcpName });
|
|
179
|
-
if (!["observed", "absent"].includes(parsed.state)) {
|
|
180
|
-
return result("blocked", { reasons: ["MC_FILES_TOML", ...parsed.reasons] });
|
|
181
|
-
}
|
|
182
|
-
return result("observed", {
|
|
183
|
-
entryState: parsed.state, configurationSha256: parsed.configurationSha256,
|
|
184
|
-
metadataSha256: metadataHash(), server: parsed.server, ranges: parsed.ranges
|
|
185
|
-
});
|
|
186
|
-
} catch (error) {
|
|
187
|
-
return result(error instanceof Rejected ? error.state : "blocked", {
|
|
188
|
-
reasons: [error instanceof Rejected ? error.code : "MC_FILES_IO"]
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { types } from "node:util";
|
|
4
|
-
import Ajv2020 from "ajv/dist/2020.js";
|
|
5
|
-
import ownSchema from "../schemas/project-memory.schema.json" with { type: "json" };
|
|
6
|
-
import { copyBytes, copyInertJson, decode, parseEventJson } from "./client-output-json.js";
|
|
7
|
-
import {
|
|
8
|
-
createMemoryConnectionDescriptor, copyMemoryConnectionData, freezeMemoryConnectionData,
|
|
9
|
-
memoryConnectionHash, MEMORY_CONNECTION_FACTS, MEMORY_CONNECTION_VERSION
|
|
10
|
-
} from "./memory-connection-descriptor.js";
|
|
11
|
-
import { containsSensitiveData, isCredentialPath } from "./sensitive-data.js";
|
|
12
|
-
|
|
13
|
-
export const MEMORY_CONNECTION_MANIFEST_LIMITS = Object.freeze({
|
|
14
|
-
manifestBytes: 512 * 1024, reportBytes: 128 * 1024,
|
|
15
|
-
depth: 64, nodes: 30000, arrayItems: 256, pathChars: 4096, components: 64
|
|
16
|
-
});
|
|
17
|
-
// Trusted module/schema loading is distinct from evaluating caller-supplied bytes.
|
|
18
|
-
const trustedSchema = freezeMemoryConnectionData(ownSchema);
|
|
19
|
-
const validateSchema = new Ajv2020({
|
|
20
|
-
strict: true, allErrors: false, ownProperties: true,
|
|
21
|
-
coerceTypes: false, useDefaults: false, removeAdditional: false
|
|
22
|
-
}).compile(trustedSchema);
|
|
23
|
-
const KEYS = ["descriptor", "manifestBytes", "expectedManifestSha256"];
|
|
24
|
-
const CONTROL = /[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/u;
|
|
25
|
-
const PRIVATE_PATH = /(?:^|\/)(?:\.git|\.obsidian|\.codex|\.claude|\.gemini|\.agents|\.secrets|\.credentials|\.npmrc|\.netrc|\.envrc)(?:\/|$)/i;
|
|
26
|
-
const within = (root, full) => full === root || full.startsWith(root + "/");
|
|
27
|
-
class Rejected extends Error {
|
|
28
|
-
constructor(code, state = "blocked") { super(code); this.code = code; this.state = state; }
|
|
29
|
-
}
|
|
30
|
-
const reject = (code, state) => { throw new Rejected(code, state); };
|
|
31
|
-
|
|
32
|
-
function inputs(input) {
|
|
33
|
-
try {
|
|
34
|
-
if (!input || typeof input !== "object" || types.isProxy(input) ||
|
|
35
|
-
![Object.prototype, null].includes(Object.getPrototypeOf(input)) || Object.getOwnPropertySymbols(input).length) reject("MC_MANIFEST_INPUT", "invalid");
|
|
36
|
-
const fields = Object.getOwnPropertyDescriptors(input), names = Object.keys(fields);
|
|
37
|
-
if (names.length !== KEYS.length || !KEYS.every(k => Object.hasOwn(fields, k) && fields[k].enumerable && Object.hasOwn(fields[k], "value"))) reject("MC_MANIFEST_INPUT", "invalid");
|
|
38
|
-
const data = copyMemoryConnectionData({ descriptor: fields.descriptor.value, expectedManifestSha256: fields.expectedManifestSha256.value });
|
|
39
|
-
if (typeof data.expectedManifestSha256 !== "string" || !/^[a-f0-9]{64}$/.test(data.expectedManifestSha256)) reject("MC_MANIFEST_INPUT", "invalid");
|
|
40
|
-
const descriptor = createMemoryConnectionDescriptor(data.descriptor?.identity);
|
|
41
|
-
if (memoryConnectionHash(descriptor) !== memoryConnectionHash(data.descriptor)) reject("MC_MANIFEST_INPUT", "invalid");
|
|
42
|
-
const { toolkitRoot, vaultPath, manifestPath } = descriptor.identity;
|
|
43
|
-
if (within(toolkitRoot, vaultPath) || within(vaultPath, toolkitRoot) || !manifestPath.startsWith(vaultPath + "/")) reject("MC_MANIFEST_INPUT", "invalid");
|
|
44
|
-
return { descriptor, pin: data.expectedManifestSha256, bytes: fields.manifestBytes.value };
|
|
45
|
-
} catch { reject("MC_MANIFEST_INPUT", "invalid"); }
|
|
46
|
-
}
|
|
47
|
-
function capturedBytes(value) {
|
|
48
|
-
try {
|
|
49
|
-
if (value && typeof value === "object" && !types.isProxy(value) && types.isUint8Array(value)) {
|
|
50
|
-
const typed = Object.getPrototypeOf(Uint8Array.prototype);
|
|
51
|
-
const backing = Object.getOwnPropertyDescriptor(typed, "buffer").get.call(value);
|
|
52
|
-
if (types.isSharedArrayBuffer(backing)) reject("MC_MANIFEST_INPUT", "invalid");
|
|
53
|
-
}
|
|
54
|
-
return copyBytes(value, MEMORY_CONNECTION_MANIFEST_LIMITS.manifestBytes);
|
|
55
|
-
} catch (e) {
|
|
56
|
-
if (e instanceof Rejected) throw e;
|
|
57
|
-
if (e?.code === "byte-limit") reject("MC_MANIFEST_LIMIT");
|
|
58
|
-
if (["invalid-unicode", "invalid-utf8"].includes(e?.code)) reject("MC_MANIFEST_FORMAT");
|
|
59
|
-
reject("MC_MANIFEST_INPUT", "invalid");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function resolveDeclaration(base, value) {
|
|
63
|
-
if (typeof value !== "string" || !value || value !== value.trim() || value.length > MEMORY_CONNECTION_MANIFEST_LIMITS.pathChars ||
|
|
64
|
-
CONTROL.test(value) || value.includes("\\") || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(value) || value.includes("//") || value.endsWith("/") ||
|
|
65
|
-
PRIVATE_PATH.test(value) || isCredentialPath(value) || containsSensitiveData(value)) reject("MC_MANIFEST_IDENTITY");
|
|
66
|
-
if (path.posix.isAbsolute(value) && path.posix.normalize(value) !== value) reject("MC_MANIFEST_IDENTITY");
|
|
67
|
-
const full = path.posix.resolve(base, value);
|
|
68
|
-
if (full === "/" || full.length > MEMORY_CONNECTION_MANIFEST_LIMITS.pathChars || full.split("/").length - 1 > MEMORY_CONNECTION_MANIFEST_LIMITS.components ||
|
|
69
|
-
PRIVATE_PATH.test(full) || isCredentialPath(full)) reject("MC_MANIFEST_IDENTITY");
|
|
70
|
-
return full;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Validate a captured, reviewed byte pin and declarations only. No target IO,
|
|
75
|
-
* discovery, runtime/dependency admission, client launch or plan application.
|
|
76
|
-
* Schema loading is trusted startup; $schema in the input never selects a schema.
|
|
77
|
-
*/
|
|
78
|
-
export function validateMemoryConnectionManifest(input) {
|
|
79
|
-
const report = (state, details = {}) => {
|
|
80
|
-
const validated = state === "validated";
|
|
81
|
-
const result = {
|
|
82
|
-
schemaVersion: MEMORY_CONNECTION_VERSION, state,
|
|
83
|
-
manifestSha256: null, descriptorSha256: null, reasons: [], ...details,
|
|
84
|
-
facts: {
|
|
85
|
-
...MEMORY_CONNECTION_FACTS, evidence: "provided-bytes",
|
|
86
|
-
verificationScope: "manifest-declarations-only",
|
|
87
|
-
manifestSchemaValidated: validated, manifestSecurityValidated: validated,
|
|
88
|
-
manifestDescriptorMatched: validated, manifestSemanticsVerified: false,
|
|
89
|
-
installedDependenciesVerified: false, runtimeVersionVerified: false,
|
|
90
|
-
runtimeCompatibilityVerified: false
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
if (Buffer.byteLength(JSON.stringify(result)) > MEMORY_CONNECTION_MANIFEST_LIMITS.reportBytes) reject("MC_MANIFEST_REPORT_LIMIT");
|
|
94
|
-
return freezeMemoryConnectionData(result);
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
const { descriptor, pin, bytes: value } = inputs(input), bytes = capturedBytes(value);
|
|
98
|
-
if (!bytes.length) reject("MC_MANIFEST_FORMAT");
|
|
99
|
-
if (createHash("sha256").update(bytes).digest("hex") !== pin) reject("MC_MANIFEST_PIN_MISMATCH");
|
|
100
|
-
let manifest;
|
|
101
|
-
try { manifest = copyInertJson(parseEventJson(decode(bytes))); }
|
|
102
|
-
catch (e) { reject(["event-json-limit", "metadata-limit"].includes(e?.code) ? "MC_MANIFEST_LIMIT" : "MC_MANIFEST_FORMAT"); }
|
|
103
|
-
if (containsSensitiveData(JSON.stringify(manifest))) reject("MC_MANIFEST_SENSITIVE");
|
|
104
|
-
if (!validateSchema(manifest)) reject("MC_MANIFEST_SCHEMA");
|
|
105
|
-
const identity = descriptor.identity, base = path.posix.dirname(identity.manifestPath);
|
|
106
|
-
if (resolveDeclaration(base, manifest.source.repositoryPath) !== identity.sourcePath ||
|
|
107
|
-
resolveDeclaration(base, manifest.memory.vaultPath) !== identity.vaultPath ||
|
|
108
|
-
manifest.memory.mcpServerName !== identity.mcpName) reject("MC_MANIFEST_IDENTITY");
|
|
109
|
-
if (new Set(manifest.agents.map(a => a.id)).size !== manifest.agents.length) reject("MC_MANIFEST_AGENTS");
|
|
110
|
-
const codex = manifest.agents.filter(a => a.id === "codex");
|
|
111
|
-
if (codex.length !== 1 || codex[0].enabled !== true || codex[0].skillName !== identity.skillName) reject("MC_MANIFEST_AGENTS");
|
|
112
|
-
return report("validated", {
|
|
113
|
-
manifestSha256: pin, descriptorSha256: memoryConnectionHash(descriptor), reasons: ["MC_MANIFEST_VALIDATED"]
|
|
114
|
-
});
|
|
115
|
-
} catch (e) {
|
|
116
|
-
return report(e instanceof Rejected ? e.state : "blocked", { reasons: [e instanceof Rejected ? e.code : "MC_MANIFEST_VALIDATION"] });
|
|
117
|
-
}
|
|
118
|
-
}
|