nexakit 0.0.0-stage → 0.2.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/.claude-plugin/marketplace.json +28 -0
- package/LICENSE +26 -0
- package/README.md +79 -2
- package/agents/claude/docs-researcher.md +9 -0
- package/agents/claude/implementation-tutor.md +9 -0
- package/agents/claude/project-explorer.md +9 -0
- package/agents/claude/quality-reviewer.md +9 -0
- package/agents/claude/requirements-analyst.md +9 -0
- package/agents/claude/solution-architect.md +9 -0
- package/agents/codex/docs-researcher.toml +10 -0
- package/agents/codex/implementation-tutor.toml +10 -0
- package/agents/codex/project-explorer.toml +10 -0
- package/agents/codex/quality-reviewer.toml +10 -0
- package/agents/codex/requirements-analyst.toml +11 -0
- package/agents/codex/solution-architect.toml +10 -0
- package/assets/brand/README.md +38 -0
- package/assets/brand/agent-toolkit-mark.png +0 -0
- package/assets/brand/agent-toolkit-mark.svg +13 -0
- package/assets/brand/agent-toolkit-tui-hero.png +0 -0
- package/assets/brand/nexakit-readme-hero.png +0 -0
- package/assets/brand/nexakit-readme-hero.svg +21 -0
- package/assets/runtime/package-lock.json +1425 -0
- package/bin/agent-task.js +14 -0
- package/bin/agent-toolkit-gemini.js +13 -0
- package/bin/agent-toolkit-inbox.js +14 -0
- package/bin/agent-toolkit-mcp.js +17 -0
- package/bin/agent-toolkit.js +13 -0
- package/bin/nexakit.js +13 -0
- package/bin/project-memory-mcp.js +22 -0
- package/bin/project-memory.js +7 -0
- package/catalogs/skills/api-design-principles/LICENSE.txt +21 -0
- package/catalogs/skills/api-design-principles/SKILL.md +110 -0
- package/catalogs/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/catalogs/skills/api-design-principles/assets/rest-api-template.py +185 -0
- package/catalogs/skills/api-design-principles/references/details.md +413 -0
- package/catalogs/skills/api-design-principles/references/graphql-schema-design.md +589 -0
- package/catalogs/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/catalogs/skills/nodejs-backend-patterns/LICENSE.txt +21 -0
- package/catalogs/skills/nodejs-backend-patterns/SKILL.md +45 -0
- package/catalogs/skills/nodejs-backend-patterns/references/advanced-patterns.md +430 -0
- package/catalogs/skills/nodejs-backend-patterns/references/details.md +599 -0
- package/catalogs/skills/supabase-postgres-best-practices/CHANGELOG.md +73 -0
- package/catalogs/skills/supabase-postgres-best-practices/LICENSE.txt +21 -0
- package/catalogs/skills/supabase-postgres-best-practices/SKILL.md +64 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/_sections.md +39 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/_template.md +34 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/catalogs/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
- package/catalogs/skills/vercel-composition-patterns/AGENTS.md +946 -0
- package/catalogs/skills/vercel-composition-patterns/LICENSE.txt +27 -0
- package/catalogs/skills/vercel-composition-patterns/README.md +60 -0
- package/catalogs/skills/vercel-composition-patterns/SKILL.md +89 -0
- package/catalogs/skills/vercel-composition-patterns/metadata.json +11 -0
- package/catalogs/skills/vercel-composition-patterns/rules/_sections.md +29 -0
- package/catalogs/skills/vercel-composition-patterns/rules/_template.md +24 -0
- package/catalogs/skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
- package/catalogs/skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
- package/catalogs/skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
- package/catalogs/skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
- package/catalogs/skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
- package/catalogs/skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
- package/catalogs/skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
- package/catalogs/skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
- package/catalogs/skills/vercel-react-best-practices/AGENTS.md +3810 -0
- package/catalogs/skills/vercel-react-best-practices/LICENSE.txt +27 -0
- package/catalogs/skills/vercel-react-best-practices/README.md +123 -0
- package/catalogs/skills/vercel-react-best-practices/SKILL.md +149 -0
- package/catalogs/skills/vercel-react-best-practices/metadata.json +15 -0
- package/catalogs/skills/vercel-react-best-practices/rules/_sections.md +46 -0
- package/catalogs/skills/vercel-react-best-practices/rules/_template.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-effect-event-deps.md +56 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
- package/catalogs/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-defer-await.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-analyzable-paths.md +63 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +60 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/catalogs/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/catalogs/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-flatmap-filter.md +60 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-request-idle-callback.md +105 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/catalogs/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-resource-hints.md +85 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-script-defer-async.md +68 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-no-inline-components.md +82 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-use-deferred-value.md +59 -0
- package/catalogs/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-hoist-static-io.md +149 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-no-shared-module-state.md +50 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +34 -0
- package/catalogs/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
- package/catalogs/skills/webapp-testing/LICENSE.txt +202 -0
- package/catalogs/skills/webapp-testing/SKILL.md +96 -0
- package/catalogs/skills/webapp-testing/examples/console_logging.py +35 -0
- package/catalogs/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/catalogs/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/catalogs/skills/webapp-testing/scripts/with_server.py +106 -0
- package/catalogs/skills.json +1115 -0
- package/docs/skills/evidencias/2026-10-28-evaluacion-inicial-mcp-seguridad.md +118 -0
- package/docs/skills/evidencias/2026-10-28-incorporacion-mcp-seguridad.json +152 -0
- package/docs/skills/evidencias/2026-10-28-recomendador-preparacion.md +50 -0
- package/package.json +73 -4
- package/plugins/nexakit-modelo/.claude-plugin/plugin.json +1 -0
- package/plugins/nexakit-modelo/hooks/hooks.json +1 -0
- package/plugins/nexakit-modelo/hooks/register.js +48 -0
- package/plugins/nexakit-modelo/hooks/status.js +8 -0
- package/plugins/nexakit-modelo/tests/register.test.ts +21 -0
- package/plugins/nexakit-panel/.claude-plugin/plugin.json +1 -0
- package/plugins/nexakit-panel/README.md +20 -0
- package/plugins/nexakit-panel/hooks/hooks.json +1 -0
- package/plugins/nexakit-panel/hooks/lienzo.js +382 -0
- package/plugins/nexakit-panel/hooks/panel.js +279 -0
- package/plugins/nexakit-panel/hooks/register.tsx +248 -0
- package/plugins/nexakit-panel/tests/lienzo.test.ts +142 -0
- package/plugins/nexakit-panel/tests/panel.test.ts +240 -0
- package/plugins/nexakit-panel/tests/register.test.ts +167 -0
- package/plugins/nexakit-panel/types/index.d.ts +41 -0
- package/plugins/nexakit-sesion/.claude-plugin/plugin.json +1 -0
- package/plugins/nexakit-sesion/README.md +12 -0
- package/plugins/nexakit-sesion/hooks/aviso.js +38 -0
- package/plugins/nexakit-sesion/hooks/hooks.json +1 -0
- package/plugins/nexakit-sesion/hooks/register.js +28 -0
- package/plugins/nexakit-sesion/tests/register.test.ts +96 -0
- package/plugins/niveles/.claude-plugin/plugin.json +5 -0
- package/plugins/niveles/agents/nivel-alto.md +13 -0
- package/plugins/niveles/agents/nivel-exigente.md +13 -0
- package/plugins/niveles/agents/nivel-ligero.md +13 -0
- package/plugins/niveles/agents/nivel-normal.md +13 -0
- package/schemas/agent-client-adapter.schema.json +786 -0
- package/schemas/agent-client-auth-diagnostic.schema.json +801 -0
- package/schemas/agent-client-isolated-variant.schema.json +105 -0
- package/schemas/agent-client-isolated-verification.schema.json +99 -0
- package/schemas/agent-client-managed-preferences-invocation.schema.json +67 -0
- package/schemas/agent-client-managed-preferences.schema.json +63 -0
- package/schemas/agent-client-native-diagnostics.schema.json +85 -0
- package/schemas/agent-client-native-evaluation.schema.json +171 -0
- package/schemas/agent-client-native-preflight.schema.json +90 -0
- package/schemas/agent-client-output.schema.json +551 -0
- package/schemas/agent-client-runtime-fixture.schema.json +90 -0
- package/schemas/agent-client-runtime-local.schema.json +95 -0
- package/schemas/agent-client-runtime.schema.json +1288 -0
- package/schemas/agent-client-selective-config.schema.json +77 -0
- package/schemas/agent-client-supervised-local.schema.json +135 -0
- package/schemas/agent-client-supervised.schema.json +186 -0
- package/schemas/agent-model-preference.schema.json +573 -0
- package/schemas/agent-model-selection.schema.json +311 -0
- package/schemas/agent-task-approvals.schema.json +362 -0
- package/schemas/agent-task-prepare.schema.json +1324 -0
- package/schemas/agent-task-verify.schema.json +198 -0
- package/schemas/project-memory-update.schema.json +33 -0
- package/schemas/project-memory.schema.json +298 -0
- package/schemas/skill-catalog.schema.json +246 -0
- package/schemas/task-workflow-plan-output.schema.json +35 -0
- package/scripts/prepare-package.js +6 -0
- package/scripts/validate-skill-catalog.js +41 -0
- package/skills/cerrar-avisens/SKILL.md +12 -0
- package/skills/cerrar-memoria/SKILL.md +96 -0
- package/skills/cerrar-memoria/references/cierre.md +76 -0
- package/skills/decision-records/SKILL.md +27 -0
- package/skills/decision-records/agents/openai.yaml +7 -0
- package/skills/decision-records/references/adr-template.md +35 -0
- package/skills/differential-review/LICENSE.txt +427 -0
- package/skills/differential-review/SKILL.md +225 -0
- package/skills/differential-review/adversarial.md +203 -0
- package/skills/differential-review/agents/openai.yaml +6 -0
- package/skills/differential-review/assets/trail-of-bits-mark.svg +1 -0
- package/skills/differential-review/methodology.md +234 -0
- package/skills/differential-review/patterns.md +300 -0
- package/skills/differential-review/reporting.md +369 -0
- package/skills/elegir-modelo/SKILL.md +68 -0
- package/skills/elegir-modelo/modelos.mjs +108 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +71 -0
- package/skills/gemini/SKILL.md +52 -0
- package/skills/imagen/SKILL.md +12 -0
- package/skills/investigar/SKILL.md +11 -0
- package/skills/mcp-builder/LICENSE.txt +202 -0
- package/skills/mcp-builder/SKILL.md +236 -0
- package/skills/mcp-builder/reference/evaluation.md +602 -0
- package/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/skills/mcp-builder/scripts/connections.py +151 -0
- package/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/skills/ordenar-proyecto/SKILL.md +56 -0
- package/skills/project-handoff/SKILL.md +53 -0
- package/skills/project-handoff/agents/openai.yaml +7 -0
- package/skills/project-handoff/references/handoff-template.md +35 -0
- package/skills/quality-gate/LICENSE.txt +26 -0
- package/skills/quality-gate/SKILL.md +44 -0
- package/skills/quality-gate/agents/openai.yaml +7 -0
- package/skills/quality-gate/references/review-checklist.md +42 -0
- package/skills/revisar/SKILL.md +11 -0
- package/skills/revisar-skill/LICENSE-find-skills.txt +26 -0
- package/skills/revisar-skill/SKILL.md +94 -0
- package/skills/revision-cruzada/SKILL.md +59 -0
- package/skills/web-design-guidelines/AGENTS.md +156 -0
- package/skills/web-design-guidelines/LICENSE.txt +21 -0
- package/skills/web-design-guidelines/SKILL.md +29 -0
- package/src/agent-models.js +131 -0
- package/src/brand.js +117 -0
- package/src/claude-code-runner.js +642 -0
- package/src/cli-executable.js +88 -0
- package/src/cli.js +778 -0
- package/src/client-adapter-plan.js +271 -0
- package/src/client-auth-diagnostic-parser.js +211 -0
- package/src/client-auth-diagnostic.js +257 -0
- package/src/client-isolated-variant.js +106 -0
- package/src/client-isolated-verification.js +130 -0
- package/src/client-local-platform.js +14 -0
- package/src/client-managed-preferences-invocation.js +209 -0
- package/src/client-managed-preferences.js +78 -0
- package/src/client-native-access.js +134 -0
- package/src/client-native-diagnostics.js +253 -0
- package/src/client-native-evaluation.js +106 -0
- package/src/client-native-preflight-files.js +68 -0
- package/src/client-native-preflight.js +95 -0
- package/src/client-output-json.js +118 -0
- package/src/client-output-parser.js +278 -0
- package/src/client-runtime-admission.js +80 -0
- package/src/client-runtime-coordinator.js +70 -0
- package/src/client-runtime-core.js +92 -0
- package/src/client-runtime-fixture-permit.js +20 -0
- package/src/client-runtime-fixture-protocol.js +39 -0
- package/src/client-runtime-state.js +67 -0
- package/src/client-runtime-store-files.js +91 -0
- package/src/client-runtime-store.js +239 -0
- package/src/client-runtime-supervisor.js +146 -0
- package/src/client-selective-config.js +195 -0
- package/src/client-selective-files.js +126 -0
- package/src/client-supervised-codes.js +32 -0
- package/src/client-supervised-contract.js +52 -0
- package/src/client-supervised-coordinator.js +36 -0
- package/src/client-supervised-permit.js +20 -0
- package/src/client-supervised-protocol.js +37 -0
- package/src/client-supervised-store.js +167 -0
- package/src/client-supervised-supervisor.js +167 -0
- package/src/client-supervised.js +160 -0
- package/src/codex-cli-runner.js +358 -0
- package/src/codex-delivery.js +101 -0
- package/src/connect.js +703 -0
- package/src/doctor.js +795 -0
- package/src/gemini-cli.js +76 -0
- package/src/gemini-files.js +45 -0
- package/src/gemini-tools.js +249 -0
- package/src/init.js +473 -0
- package/src/install-lock.js +127 -0
- package/src/install-registry.js +61 -0
- package/src/legacy-repair.js +71 -0
- package/src/level-agents.js +111 -0
- package/src/link-states.js +172 -0
- package/src/memory-connection-artifacts.js +192 -0
- package/src/memory-connection-descriptor.js +158 -0
- package/src/memory-connection-diagnostic.js +177 -0
- package/src/memory-connection-files.js +191 -0
- package/src/memory-connection-manifest.js +118 -0
- package/src/memory-connection-package.js +176 -0
- package/src/memory-connection-plan.js +211 -0
- package/src/memory-connection-skill.js +211 -0
- package/src/memory-connection-toml.js +153 -0
- package/src/memory-locator.js +118 -0
- package/src/memory-mcp-policy.js +181 -0
- package/src/memory-mcp-server.js +166 -0
- package/src/memory-mcp-transport.js +59 -0
- package/src/missing-dependencies.js +21 -0
- package/src/model-command.js +147 -0
- package/src/model-preference.js +235 -0
- package/src/model-selection.js +368 -0
- package/src/native/managed-preferences.c +100 -0
- package/src/native/managed-preferences.h +17 -0
- package/src/package-lock-path.js +13 -0
- package/src/panel-cli.js +182 -0
- package/src/peer-handoff.js +27 -0
- package/src/peer-inbox-cli.js +211 -0
- package/src/peer-review-mcp.js +210 -0
- package/src/peer-review-store.js +532 -0
- package/src/platform.js +24 -0
- package/src/project-root.js +41 -0
- package/src/project-signals.js +339 -0
- package/src/recommend-report.js +77 -0
- package/src/review-instructions.js +211 -0
- package/src/review-policy.js +35 -0
- package/src/revision-adapters.js +157 -0
- package/src/revision-context.js +86 -0
- package/src/revision-isolation.js +222 -0
- package/src/revision-process.js +103 -0
- package/src/revision-provenance.js +89 -0
- package/src/revision-snapshot.js +120 -0
- package/src/revision.js +242 -0
- package/src/runtime-fixtures/runtime-supervisor/child.cjs +3 -0
- package/src/runtime-fixtures/runtime-supervisor/fixture.cjs +49 -0
- package/src/runtime-fixtures/supervised/child.cjs +3 -0
- package/src/runtime-fixtures/supervised/fixture.cjs +47 -0
- package/src/sensitive-data.js +21 -0
- package/src/setup-apply.js +231 -0
- package/src/setup-plan.js +231 -0
- package/src/setup-state.js +277 -0
- package/src/setup-tui.js +555 -0
- package/src/skill-catalog-add.js +91 -0
- package/src/skill-catalog-audit.js +68 -0
- package/src/skill-catalog.js +170 -0
- package/src/skill-files.js +39 -0
- package/src/skill-recommendations.js +1673 -0
- package/src/skill-scan-report.js +14 -0
- package/src/skill-scan.js +178 -0
- package/src/stable-command.js +53 -0
- package/src/stable-install.js +222 -0
- package/src/status.js +200 -0
- package/src/superpowers.js +133 -0
- package/src/sync-apply.js +227 -0
- package/src/sync-files.js +109 -0
- package/src/sync-inspect.js +394 -0
- package/src/sync-ledger.js +94 -0
- package/src/sync-markdown.js +151 -0
- package/src/sync-proposal.js +84 -0
- package/src/sync-record.js +459 -0
- package/src/sync.js +360 -0
- package/src/task-approvals.js +367 -0
- package/src/task-cli.js +79 -0
- package/src/task-external-verifier.js +584 -0
- package/src/task-prepare-files.js +115 -0
- package/src/task-prepare.js +180 -0
- package/src/task-verify-cli.js +67 -0
- package/src/task-verify-files.js +188 -0
- package/src/task-verify.js +118 -0
- package/src/task-workflow-mcp.js +544 -0
- package/src/task-workflow-store.js +254 -0
- package/src/terminal-text.js +68 -0
- package/src/toolkit-cli.js +543 -0
- package/src/toolkit-commands-guide.js +107 -0
- package/src/toolkit-setup.js +614 -0
- package/src/usage-metrics.js +43 -0
- package/templates/agent-team/01-encargo.md +158 -0
- package/templates/agent-team/02-propuesta.md +132 -0
- package/templates/agent-team/03-revision.md +150 -0
- package/templates/agent-team/README.md +213 -0
- package/templates/model-inventory/01-inventario.md +154 -0
- package/templates/model-inventory/README.md +115 -0
- package/templates/project-memory/README.md +67 -0
- package/templates/project-memory/project-memory.example.json +53 -0
- package/templates/project-memory/skill/project-id/SKILL.md +37 -0
- package/templates/project-memory/skill/project-id/references/project-profile.md +44 -0
- package/templates/project-memory/vault/00-INICIO/Estado actual.md +44 -0
- package/templates/project-memory/vault/00-INICIO/Fuentes de verdad.md +30 -0
- package/templates/project-memory/vault/00-INICIO/Inicio del proyecto.md +44 -0
- package/templates/project-memory/vault/00-INICIO/Mantenimiento de la memoria.md +26 -0
- package/templates/project-memory/vault/00-INICIO/Mapa de la memoria.md +33 -0
- package/templates/project-memory/vault/00-INICIO/Registro de sincronizaci/303/263n.md" +28 -0
- package/templates/project-memory/vault/01-PRODUCTO/Producto.md +16 -0
- package/templates/project-memory/vault/02-ARQUITECTURA/Arquitectura.md +16 -0
- package/templates/project-memory/vault/03-IMPLEMENTACION/Implementaci/303/263n.md +15 -0
- package/templates/project-memory/vault/04-DECISIONES/Decisiones.md +19 -0
- package/templates/project-memory/vault/05-ENTREGAS/Entregas.md +12 -0
- package/templates/project-memory/vault/06-OPERACION/Operaci/303/263n.md +15 -0
- package/templates/project-memory/vault/07-AGENTES/Protocolo de agentes.md +33 -0
- package/templates/project-memory/vault/08-RECURSOS/Recursos.md +12 -0
- package/templates/project-memory/vault/09-ARCHIVO/README.md +5 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { types } from "node:util";
|
|
3
|
+
import { copyBytes, copyInertJson, decode, parseEventJson } from "./client-output-json.js";
|
|
4
|
+
import {
|
|
5
|
+
createMemoryConnectionDescriptor, copyMemoryConnectionData, freezeMemoryConnectionData,
|
|
6
|
+
memoryConnectionHash, MEMORY_CONNECTION_FACTS, MEMORY_CONNECTION_VERSION
|
|
7
|
+
} from "./memory-connection-descriptor.js";
|
|
8
|
+
import { containsSensitiveData } from "./sensitive-data.js";
|
|
9
|
+
|
|
10
|
+
export const MEMORY_CONNECTION_PACKAGE_LIMITS = Object.freeze({
|
|
11
|
+
packageJsonBytes: 512 * 1024, packageLockBytes: 2 * 1024 * 1024,
|
|
12
|
+
totalBytes: 2560 * 1024, reportBytes: 128 * 1024,
|
|
13
|
+
depth: 64, nodes: 30000, arrayItems: 256, metadataBytes: 2000000,
|
|
14
|
+
dependencies: 256, nameChars: 256, specifierChars: 1024
|
|
15
|
+
});
|
|
16
|
+
const KEYS = ["descriptor", "packageJsonBytes", "packageLockBytes", "expectedPackageJsonSha256", "expectedPackageLockSha256"];
|
|
17
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
18
|
+
const CONTROL = /[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/u;
|
|
19
|
+
const object = value => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
const within = (root, full) => full === root || full.startsWith(root + "/");
|
|
21
|
+
const sha256 = bytes => createHash("sha256").update(bytes).digest("hex");
|
|
22
|
+
class Rejected extends Error {
|
|
23
|
+
constructor(code, state = "blocked") { super(code); this.code = code; this.state = state; }
|
|
24
|
+
}
|
|
25
|
+
const reject = (code, state) => { throw new Rejected(code, state); };
|
|
26
|
+
|
|
27
|
+
function inputs(input) {
|
|
28
|
+
try {
|
|
29
|
+
if (!object(input) || types.isProxy(input) ||
|
|
30
|
+
![Object.prototype, null].includes(Object.getPrototypeOf(input)) || Object.getOwnPropertySymbols(input).length) {
|
|
31
|
+
reject("MC_PACKAGE_INPUT", "invalid");
|
|
32
|
+
}
|
|
33
|
+
const fields = Object.getOwnPropertyDescriptors(input);
|
|
34
|
+
if (Object.keys(fields).length !== KEYS.length || !KEYS.every(key =>
|
|
35
|
+
Object.hasOwn(fields, key) && fields[key].enumerable && Object.hasOwn(fields[key], "value"))) reject("MC_PACKAGE_INPUT", "invalid");
|
|
36
|
+
// Copy only small metadata here: file bytes have their own larger budgets.
|
|
37
|
+
const data = copyMemoryConnectionData({
|
|
38
|
+
descriptor: fields.descriptor.value,
|
|
39
|
+
packagePin: fields.expectedPackageJsonSha256.value,
|
|
40
|
+
lockPin: fields.expectedPackageLockSha256.value
|
|
41
|
+
});
|
|
42
|
+
if (typeof data.packagePin !== "string" || !HASH.test(data.packagePin) ||
|
|
43
|
+
typeof data.lockPin !== "string" || !HASH.test(data.lockPin)) reject("MC_PACKAGE_INPUT", "invalid");
|
|
44
|
+
const descriptor = createMemoryConnectionDescriptor(data.descriptor?.identity);
|
|
45
|
+
if (memoryConnectionHash(descriptor) !== memoryConnectionHash(data.descriptor)) reject("MC_PACKAGE_INPUT", "invalid");
|
|
46
|
+
const { toolkitRoot, vaultPath, manifestPath } = descriptor.identity;
|
|
47
|
+
if (within(toolkitRoot, vaultPath) || within(vaultPath, toolkitRoot) || !manifestPath.startsWith(vaultPath + "/")) {
|
|
48
|
+
reject("MC_PACKAGE_INPUT", "invalid");
|
|
49
|
+
}
|
|
50
|
+
return { descriptor, packagePin: data.packagePin, lockPin: data.lockPin,
|
|
51
|
+
packageValue: fields.packageJsonBytes.value, lockValue: fields.packageLockBytes.value };
|
|
52
|
+
} catch { reject("MC_PACKAGE_INPUT", "invalid"); }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function capture(value, limit) {
|
|
56
|
+
try {
|
|
57
|
+
if (value && typeof value === "object" && !types.isProxy(value) && types.isUint8Array(value)) {
|
|
58
|
+
const typed = Object.getPrototypeOf(Uint8Array.prototype);
|
|
59
|
+
const backing = Object.getOwnPropertyDescriptor(typed, "buffer").get.call(value);
|
|
60
|
+
if (types.isSharedArrayBuffer(backing)) reject("MC_PACKAGE_INPUT", "invalid");
|
|
61
|
+
}
|
|
62
|
+
return copyBytes(value, limit);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof Rejected) throw error;
|
|
65
|
+
if (error?.code === "byte-limit") reject("MC_PACKAGE_LIMIT");
|
|
66
|
+
if (["invalid-unicode", "invalid-utf8"].includes(error?.code)) reject("MC_PACKAGE_FORMAT");
|
|
67
|
+
reject("MC_PACKAGE_INPUT", "invalid");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parse(bytes) {
|
|
72
|
+
try { return copyInertJson(parseEventJson(decode(bytes))); }
|
|
73
|
+
catch (error) { reject(["event-json-limit", "metadata-limit"].includes(error?.code) ? "MC_PACKAGE_LIMIT" : "MC_PACKAGE_FORMAT"); }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function profile(pkg, lock) {
|
|
77
|
+
if (lock.lockfileVersion !== 3 || !object(lock.packages) || !Object.hasOwn(lock.packages, "") || !object(lock.packages[""])) {
|
|
78
|
+
reject("MC_PACKAGE_PROFILE");
|
|
79
|
+
}
|
|
80
|
+
const root = lock.packages[""];
|
|
81
|
+
for (const item of [pkg, root]) {
|
|
82
|
+
for (const field of ["devDependencies", "optionalDependencies", "peerDependencies"]) {
|
|
83
|
+
if (Object.hasOwn(item, field) && (!object(item[field]) || Object.keys(item[field]).length)) reject("MC_PACKAGE_PROFILE");
|
|
84
|
+
}
|
|
85
|
+
for (const field of ["workspaces", "overrides", "bundleDependencies", "bundledDependencies"]) {
|
|
86
|
+
if (Object.hasOwn(item, field)) reject("MC_PACKAGE_PROFILE");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return root;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function literal(value, limit, reason) {
|
|
93
|
+
if (typeof value === "string" && value.length > limit) reject("MC_PACKAGE_LIMIT");
|
|
94
|
+
if (typeof value !== "string" || !value || value !== value.trim() || CONTROL.test(value)) reject(reason);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function identity(pkg, lock, root) {
|
|
99
|
+
for (const field of ["name", "version"]) {
|
|
100
|
+
const values = [pkg, lock, root].map(item => literal(item[field], MEMORY_CONNECTION_PACKAGE_LIMITS.nameChars, "MC_PACKAGE_IDENTITY"));
|
|
101
|
+
if (values.some(value => value !== values[0])) reject("MC_PACKAGE_IDENTITY");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function dependencies(item) {
|
|
106
|
+
if (!Object.hasOwn(item, "dependencies")) return {};
|
|
107
|
+
const value = item.dependencies;
|
|
108
|
+
if (!object(value)) reject("MC_PACKAGE_DEPENDENCIES");
|
|
109
|
+
const keys = Object.keys(value);
|
|
110
|
+
if (keys.length > MEMORY_CONNECTION_PACKAGE_LIMITS.dependencies) reject("MC_PACKAGE_LIMIT");
|
|
111
|
+
for (const key of keys) {
|
|
112
|
+
literal(key, MEMORY_CONNECTION_PACKAGE_LIMITS.nameChars, "MC_PACKAGE_DEPENDENCIES");
|
|
113
|
+
literal(value[key], MEMORY_CONNECTION_PACKAGE_LIMITS.specifierChars, "MC_PACKAGE_DEPENDENCIES");
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function engines(pkg, root) {
|
|
119
|
+
for (const item of [pkg, root]) {
|
|
120
|
+
if (Object.hasOwn(item, "engines") && !object(item.engines)) reject("MC_PACKAGE_ENGINES");
|
|
121
|
+
}
|
|
122
|
+
const has = item => Object.hasOwn(item, "engines") && Object.hasOwn(item.engines, "node");
|
|
123
|
+
const a = has(pkg), b = has(root);
|
|
124
|
+
if (!a && !b) return false;
|
|
125
|
+
if (!a || !b) reject("MC_PACKAGE_ENGINES");
|
|
126
|
+
const left = literal(pkg.engines.node, MEMORY_CONNECTION_PACKAGE_LIMITS.specifierChars, "MC_PACKAGE_ENGINES");
|
|
127
|
+
const right = literal(root.engines.node, MEMORY_CONNECTION_PACKAGE_LIMITS.specifierChars, "MC_PACKAGE_ENGINES");
|
|
128
|
+
if (left !== right) reject("MC_PACKAGE_ENGINES");
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function report(state, reason, hashes = {}, engineMatched = false) {
|
|
133
|
+
const matched = state === "consistent";
|
|
134
|
+
const result = {
|
|
135
|
+
schemaVersion: MEMORY_CONNECTION_VERSION, state, reasons: [reason],
|
|
136
|
+
descriptorSha256: null, packageJsonSha256: null, packageLockSha256: null, ...hashes,
|
|
137
|
+
facts: {
|
|
138
|
+
...MEMORY_CONNECTION_FACTS, evidence: "provided-bytes", verificationScope: "package-root-declarations-only",
|
|
139
|
+
packageIdentityMatched: matched, directDependencyDeclarationsMatched: matched,
|
|
140
|
+
engineDeclarationMatched: matched && engineMatched,
|
|
141
|
+
rangeSatisfactionVerified: false, dependencyGraphVerified: false, installedDependenciesVerified: false,
|
|
142
|
+
runtimeVersionVerified: false, runtimeCompatibilityVerified: false
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
if (Buffer.byteLength(JSON.stringify(result)) > MEMORY_CONNECTION_PACKAGE_LIMITS.reportBytes) reject("MC_PACKAGE_LIMIT");
|
|
146
|
+
return freezeMemoryConnectionData(result);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Compare two reviewed byte captures and root declarations only. No candidate IO,
|
|
151
|
+
* npm/Node execution, range solving, installed-tree inspection or plan integration.
|
|
152
|
+
*/
|
|
153
|
+
export function validateMemoryConnectionPackage(input) {
|
|
154
|
+
try {
|
|
155
|
+
const data = inputs(input);
|
|
156
|
+
const packageBytes = capture(data.packageValue, MEMORY_CONNECTION_PACKAGE_LIMITS.packageJsonBytes);
|
|
157
|
+
const lockBytes = capture(data.lockValue, MEMORY_CONNECTION_PACKAGE_LIMITS.packageLockBytes);
|
|
158
|
+
if (packageBytes.length + lockBytes.length > MEMORY_CONNECTION_PACKAGE_LIMITS.totalBytes) reject("MC_PACKAGE_LIMIT");
|
|
159
|
+
const packageHash = sha256(packageBytes), lockHash = sha256(lockBytes);
|
|
160
|
+
if (packageHash !== data.packagePin || lockHash !== data.lockPin) reject("MC_PACKAGE_PIN_MISMATCH");
|
|
161
|
+
const pkg = parse(packageBytes), lock = parse(lockBytes);
|
|
162
|
+
if (containsSensitiveData(JSON.stringify(pkg)) || containsSensitiveData(JSON.stringify(lock))) reject("MC_PACKAGE_SENSITIVE");
|
|
163
|
+
const root = profile(pkg, lock);
|
|
164
|
+
identity(pkg, lock, root);
|
|
165
|
+
const left = dependencies(pkg), right = dependencies(root), keys = Object.keys(left);
|
|
166
|
+
if (keys.length !== Object.keys(right).length || keys.some(key => !Object.hasOwn(right, key) || left[key] !== right[key])) {
|
|
167
|
+
reject("MC_PACKAGE_DEPENDENCIES");
|
|
168
|
+
}
|
|
169
|
+
const engineMatched = engines(pkg, root);
|
|
170
|
+
return report("consistent", "MC_PACKAGE_CONSISTENT", {
|
|
171
|
+
descriptorSha256: memoryConnectionHash(data.descriptor), packageJsonSha256: data.packagePin, packageLockSha256: data.lockPin
|
|
172
|
+
}, engineMatched);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return report(error instanceof Rejected ? error.state : "blocked", error instanceof Rejected ? error.code : "MC_PACKAGE_VALIDATION");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMemoryConnectionDescriptor,
|
|
3
|
+
copyMemoryConnectionData,
|
|
4
|
+
freezeMemoryConnectionData,
|
|
5
|
+
hasMemoryConnectionKeys,
|
|
6
|
+
memoryConnectionHash,
|
|
7
|
+
MEMORY_CONNECTION_FACTS,
|
|
8
|
+
MEMORY_CONNECTION_LIMITS,
|
|
9
|
+
MEMORY_CONNECTION_VERSION,
|
|
10
|
+
MemoryConnectionInputError
|
|
11
|
+
} from "./memory-connection-descriptor.js";
|
|
12
|
+
import { containsSensitiveData } from "./sensitive-data.js";
|
|
13
|
+
|
|
14
|
+
const PIN_KEYS = [
|
|
15
|
+
"manifestSha256", "binSha256", "nodeSha256", "dependenciesSha256",
|
|
16
|
+
"pathMetadataSha256", "skillMetadataSha256"
|
|
17
|
+
];
|
|
18
|
+
const SERVER_KEYS = ["command", "args", "enabled"];
|
|
19
|
+
const SERVER_OPTIONAL = ["cwd", "enabled_tools"];
|
|
20
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
21
|
+
const states = (value, allowed) => typeof value === "string" && allowed.includes(value);
|
|
22
|
+
const component = (id, action, code) => ({ id, action, code });
|
|
23
|
+
const reject = (code) => { throw new MemoryConnectionInputError(code); };
|
|
24
|
+
const equal = (a, b) => memoryConnectionHash(a) === memoryConnectionHash(b);
|
|
25
|
+
|
|
26
|
+
function blank() {
|
|
27
|
+
return {
|
|
28
|
+
command: "project-memory connect plan",
|
|
29
|
+
schemaVersion: MEMORY_CONNECTION_VERSION,
|
|
30
|
+
state: "invalid",
|
|
31
|
+
connectionClass: "unknown",
|
|
32
|
+
identity: null,
|
|
33
|
+
candidateServer: null,
|
|
34
|
+
components: [],
|
|
35
|
+
summary: { create: 0, update: 0, migrate: 0, unchanged: 0, conflicts: 0, blocked: 0 },
|
|
36
|
+
reasons: [],
|
|
37
|
+
planHash: null,
|
|
38
|
+
facts: { ...MEMORY_CONNECTION_FACTS }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function finish(report, state, reasons) {
|
|
43
|
+
report.state = state;
|
|
44
|
+
report.reasons = [...new Set(reasons)].sort();
|
|
45
|
+
report.summary = {
|
|
46
|
+
create: report.components.filter((item) => item.action === "create").length,
|
|
47
|
+
update: report.components.filter((item) => item.action === "update").length,
|
|
48
|
+
migrate: report.components.filter((item) => item.action === "migrate").length,
|
|
49
|
+
unchanged: report.components.filter((item) => item.action === "unchanged").length,
|
|
50
|
+
conflicts: report.components.filter((item) => item.action === "conflict").length,
|
|
51
|
+
blocked: report.components.filter((item) => item.action === "blocked").length
|
|
52
|
+
};
|
|
53
|
+
if (!["preview", "unchanged"].includes(state)) {
|
|
54
|
+
report.candidateServer = null;
|
|
55
|
+
report.planHash = null;
|
|
56
|
+
}
|
|
57
|
+
if (Buffer.byteLength(JSON.stringify(report)) > MEMORY_CONNECTION_LIMITS.reportBytes) {
|
|
58
|
+
const limited = blank();
|
|
59
|
+
limited.reasons = ["MC_REPORT_LIMIT"];
|
|
60
|
+
return freezeMemoryConnectionData(limited);
|
|
61
|
+
}
|
|
62
|
+
return freezeMemoryConnectionData(report);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function checkObservations(observations) {
|
|
66
|
+
if (!hasMemoryConnectionKeys(observations, ["configuration", "skill"])) {
|
|
67
|
+
reject("MC_OBSERVATIONS_INVALID");
|
|
68
|
+
}
|
|
69
|
+
const config = observations.configuration;
|
|
70
|
+
if (!hasMemoryConnectionKeys(config, ["state", "sha256", "server"]) ||
|
|
71
|
+
!states(config.state, ["absent", "present", "unsafe"])) {
|
|
72
|
+
reject("MC_OBSERVATIONS_INVALID");
|
|
73
|
+
}
|
|
74
|
+
if (config.state === "present") {
|
|
75
|
+
if (typeof config.sha256 !== "string" || !HASH.test(config.sha256) ||
|
|
76
|
+
config.server !== null && (typeof config.server !== "object" || Array.isArray(config.server))) {
|
|
77
|
+
reject("MC_OBSERVATIONS_INVALID");
|
|
78
|
+
}
|
|
79
|
+
} else if (config.sha256 !== null || config.server !== null) {
|
|
80
|
+
reject("MC_OBSERVATIONS_INVALID");
|
|
81
|
+
}
|
|
82
|
+
const skill = observations.skill;
|
|
83
|
+
if (!hasMemoryConnectionKeys(skill, ["state", "resolvedSource"]) ||
|
|
84
|
+
!states(skill.state, ["absent", "matched", "conflict", "unsafe"]) ||
|
|
85
|
+
["absent", "unsafe"].includes(skill.state) && skill.resolvedSource !== null ||
|
|
86
|
+
skill.state === "matched" && typeof skill.resolvedSource !== "string" ||
|
|
87
|
+
skill.state === "conflict" && skill.resolvedSource !== null && typeof skill.resolvedSource !== "string") {
|
|
88
|
+
reject("MC_OBSERVATIONS_INVALID");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function sensitive(value) {
|
|
93
|
+
if (typeof value === "string") return containsSensitiveData(value);
|
|
94
|
+
return value !== null && typeof value === "object" &&
|
|
95
|
+
Object.values(value).some(sensitive);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function serverShape(server) {
|
|
99
|
+
return hasMemoryConnectionKeys(server, SERVER_KEYS, SERVER_OPTIONAL) &&
|
|
100
|
+
typeof server.command === "string" && Array.isArray(server.args) &&
|
|
101
|
+
server.args.length <= 16 && server.args.every((arg) => typeof arg === "string") &&
|
|
102
|
+
typeof server.enabled === "boolean" &&
|
|
103
|
+
(server.cwd === undefined || typeof server.cwd === "string") &&
|
|
104
|
+
(server.enabled_tools === undefined || Array.isArray(server.enabled_tools) &&
|
|
105
|
+
server.enabled_tools.every((tool) => typeof tool === "string"));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function policyMatches(tools, expected) {
|
|
109
|
+
return Array.isArray(tools) && tools.length === expected.length &&
|
|
110
|
+
new Set(tools).size === tools.length && expected.every((tool) => tools.includes(tool));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Classifies explicit declarations and creates an intent pin, never a permission.
|
|
115
|
+
* Only these two modules and their tests are part of RG3-A1a: no TOML collector,
|
|
116
|
+
* writer, public CLI dispatch, native MCP test or actual client configuration.
|
|
117
|
+
*/
|
|
118
|
+
export function createMemoryConnectionPlan(input) {
|
|
119
|
+
const report = blank();
|
|
120
|
+
let data, descriptor;
|
|
121
|
+
try {
|
|
122
|
+
data = copyMemoryConnectionData(input);
|
|
123
|
+
if (!hasMemoryConnectionKeys(data, ["schemaVersion", "descriptor", "observations", "pins", "migrateLegacy"]) ||
|
|
124
|
+
data.schemaVersion !== MEMORY_CONNECTION_VERSION || typeof data.migrateLegacy !== "boolean") {
|
|
125
|
+
reject("MC_PLAN_INVALID");
|
|
126
|
+
}
|
|
127
|
+
if (sensitive(data)) reject("MC_SENSITIVE_INPUT");
|
|
128
|
+
descriptor = createMemoryConnectionDescriptor(data.descriptor?.identity);
|
|
129
|
+
if (!equal(descriptor, data.descriptor)) reject("MC_DESCRIPTOR_MISMATCH");
|
|
130
|
+
if (!hasMemoryConnectionKeys(data.pins, PIN_KEYS) ||
|
|
131
|
+
Object.values(data.pins).some((hash) => typeof hash !== "string" || !HASH.test(hash))) {
|
|
132
|
+
reject("MC_PINS_INVALID");
|
|
133
|
+
}
|
|
134
|
+
checkObservations(data.observations);
|
|
135
|
+
if (data.observations.skill.state === "matched" &&
|
|
136
|
+
data.observations.skill.resolvedSource !== descriptor.skill.source) {
|
|
137
|
+
reject("MC_SKILL_DECLARATION_MISMATCH");
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return finish(report, "invalid", [error instanceof MemoryConnectionInputError ? error.code : "MC_PLAN_INVALID"]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
report.identity = { ...descriptor.identity };
|
|
144
|
+
const { configuration, skill } = data.observations;
|
|
145
|
+
report.components.push(component("skill", {
|
|
146
|
+
absent: "create", matched: "unchanged", conflict: "conflict", unsafe: "blocked"
|
|
147
|
+
}[skill.state], {
|
|
148
|
+
absent: "MC_SKILL_MISSING", matched: "MC_SKILL_MATCH_DECLARED",
|
|
149
|
+
conflict: "MC_SKILL_CONFLICT", unsafe: "MC_SKILL_UNSAFE"
|
|
150
|
+
}[skill.state]));
|
|
151
|
+
|
|
152
|
+
if (configuration.state === "unsafe") {
|
|
153
|
+
report.connectionClass = "unsafe";
|
|
154
|
+
report.components.push(component("mcp", "blocked", "MC_CONFIG_UNSAFE"));
|
|
155
|
+
} else if (configuration.server === null) {
|
|
156
|
+
report.connectionClass = "absent";
|
|
157
|
+
report.components.push(component("mcp", "create", "MC_SERVER_MISSING"),
|
|
158
|
+
component("policy", "create", "MC_POLICY_PROPOSED"));
|
|
159
|
+
report.candidateServer = structuredClone(descriptor.server);
|
|
160
|
+
} else {
|
|
161
|
+
const current = configuration.server;
|
|
162
|
+
if (!serverShape(current)) {
|
|
163
|
+
report.components.push(component("mcp", "conflict", "MC_SERVER_UNKNOWN"));
|
|
164
|
+
} else if (current.command === descriptor.server.command &&
|
|
165
|
+
equal(current.args, descriptor.server.args) && current.cwd === descriptor.server.cwd) {
|
|
166
|
+
report.connectionClass = "protected";
|
|
167
|
+
report.components.push(component("mcp", "unchanged", "MC_SERVER_MATCH_DECLARED"));
|
|
168
|
+
if (policyMatches(current.enabled_tools, descriptor.server.enabled_tools)) {
|
|
169
|
+
report.components.push(component("policy", "unchanged", "MC_POLICY_MATCH_DECLARED"));
|
|
170
|
+
report.candidateServer = { ...structuredClone(descriptor.server), enabled: current.enabled };
|
|
171
|
+
} else {
|
|
172
|
+
report.components.push(component("policy", "conflict", "MC_POLICY_MISMATCH"));
|
|
173
|
+
}
|
|
174
|
+
} else if (current.command === "npx" && equal(current.args, [
|
|
175
|
+
"-y", "@modelcontextprotocol/server-filesystem@2026.8.31", descriptor.identity.vaultPath
|
|
176
|
+
]) && (current.cwd === undefined || current.cwd === descriptor.server.cwd)) {
|
|
177
|
+
report.connectionClass = "legacy-direct";
|
|
178
|
+
if (data.migrateLegacy) {
|
|
179
|
+
report.components.push(component("mcp", "migrate", "MC_LEGACY_MIGRATION_PROPOSED"),
|
|
180
|
+
component("policy", "migrate", "MC_POLICY_PROPOSED"));
|
|
181
|
+
report.candidateServer = structuredClone(descriptor.server);
|
|
182
|
+
} else {
|
|
183
|
+
report.components.push(component("mcp", "conflict", "MC_LEGACY_OPT_IN_REQUIRED"));
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
report.components.push(component("mcp", "conflict", "MC_SERVER_IDENTITY_MISMATCH"));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const reasons = report.components.filter((item) => ["conflict", "blocked"].includes(item.action))
|
|
191
|
+
.map((item) => item.code);
|
|
192
|
+
if (report.components.some((item) => item.action === "blocked")) return finish(report, "blocked", reasons);
|
|
193
|
+
if (report.components.some((item) => item.action === "conflict")) return finish(report, "conflict", reasons);
|
|
194
|
+
try {
|
|
195
|
+
report.planHash = memoryConnectionHash({
|
|
196
|
+
schemaVersion: MEMORY_CONNECTION_VERSION,
|
|
197
|
+
descriptor,
|
|
198
|
+
observations: data.observations,
|
|
199
|
+
pins: data.pins,
|
|
200
|
+
migrateLegacy: data.migrateLegacy,
|
|
201
|
+
components: report.components,
|
|
202
|
+
candidateServer: report.candidateServer
|
|
203
|
+
});
|
|
204
|
+
} catch {
|
|
205
|
+
return finish(report, "invalid", ["MC_PLAN_LIMIT"]);
|
|
206
|
+
}
|
|
207
|
+
const unchanged = report.components.every((item) => item.action === "unchanged");
|
|
208
|
+
const notes = [unchanged ? "MC_MATCH_DECLARED" : "MC_PREVIEW_ONLY"];
|
|
209
|
+
if (report.candidateServer.enabled === false) notes.push("MC_SERVER_DISABLED");
|
|
210
|
+
return finish(report, unchanged ? "unchanged" : "preview", notes);
|
|
211
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
import { copyBytes, decode } from "./client-output-json.js";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
createMemoryConnectionDescriptor, copyMemoryConnectionData,
|
|
9
|
+
freezeMemoryConnectionData, memoryConnectionHash,
|
|
10
|
+
MEMORY_CONNECTION_FACTS, MEMORY_CONNECTION_VERSION
|
|
11
|
+
} from "./memory-connection-descriptor.js";
|
|
12
|
+
|
|
13
|
+
export const MEMORY_CONNECTION_SKILL_LIMITS = Object.freeze({
|
|
14
|
+
fileBytes: 131072, chunkBytes: 65536, pathChars: 4096,
|
|
15
|
+
components: 64, reportBytes: 131072
|
|
16
|
+
});
|
|
17
|
+
export const MEMORY_CONNECTION_SKILL_OPEN_FLAGS = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
|
|
18
|
+
class Rejected extends Error {
|
|
19
|
+
constructor(code, state = "blocked") { super(code); this.code = code; this.state = state; }
|
|
20
|
+
}
|
|
21
|
+
const reject = (code, state) => { throw new Rejected(code, state); };
|
|
22
|
+
const errno = (e) => e instanceof Error && typeof e.code === "string" ? e.code : "";
|
|
23
|
+
const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
24
|
+
const dirSignature = (s) => JSON.stringify([s.dev, s.ino, s.uid, s.gid, s.mode]);
|
|
25
|
+
const fileSignature = (s) => JSON.stringify([s.dev, s.ino, s.uid, s.gid, s.mode, s.nlink, s.size, s.mtimeMs, s.ctimeMs]);
|
|
26
|
+
|
|
27
|
+
function inputs(input) {
|
|
28
|
+
try {
|
|
29
|
+
const data = copyMemoryConnectionData(input);
|
|
30
|
+
if (!data || Array.isArray(data) || Object.keys(data).length !== 2 ||
|
|
31
|
+
!Object.hasOwn(data, "descriptor") || !Object.hasOwn(data, "expectedSkillSha256") ||
|
|
32
|
+
typeof data.expectedSkillSha256 !== "string" || !/^[a-f0-9]{64}$/.test(data.expectedSkillSha256)) {
|
|
33
|
+
reject("MC_SKILL_INPUT", "invalid");
|
|
34
|
+
}
|
|
35
|
+
const descriptor = createMemoryConnectionDescriptor(data.descriptor?.identity);
|
|
36
|
+
if (memoryConnectionHash(descriptor) !== memoryConnectionHash(data.descriptor)) reject("MC_SKILL_INPUT", "invalid");
|
|
37
|
+
const sourceFile = descriptor.skill.source + "/SKILL.md";
|
|
38
|
+
for (const full of [descriptor.skill.target, sourceFile]) {
|
|
39
|
+
if (full.length > MEMORY_CONNECTION_SKILL_LIMITS.pathChars ||
|
|
40
|
+
full.split("/").length - 1 > MEMORY_CONNECTION_SKILL_LIMITS.components) reject("MC_SKILL_INPUT", "invalid");
|
|
41
|
+
}
|
|
42
|
+
return { descriptor, expected: data.expectedSkillSha256, sourceFile };
|
|
43
|
+
} catch { reject("MC_SKILL_INPUT", "invalid"); }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function safeDir(s, uid, owned) {
|
|
47
|
+
if (!s.isDirectory() || s.isSymbolicLink() || !(s.mode & 0o100)) reject("MC_SKILL_PARENT_UNSAFE");
|
|
48
|
+
if (owned) {
|
|
49
|
+
if (s.uid !== uid || s.mode & 0o7022) reject("MC_SKILL_PARENT_UNSAFE");
|
|
50
|
+
} else {
|
|
51
|
+
const sharedSticky = s.uid === 0 && (s.mode & 0o7777) === 0o1777;
|
|
52
|
+
if (![0, uid].includes(s.uid) || !sharedSticky && s.mode & 0o7022) reject("MC_SKILL_PARENT_UNSAFE");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function safeSourceFile(s, uid) {
|
|
56
|
+
if (!s.isFile() || s.isSymbolicLink() || s.uid !== uid || s.nlink !== 1 || (s.mode & 0o7777) !== 0o600) {
|
|
57
|
+
reject("MC_SKILL_FILE_UNSAFE");
|
|
58
|
+
}
|
|
59
|
+
if (!Number.isSafeInteger(s.size) || s.size < 0 || s.size > MEMORY_CONNECTION_SKILL_LIMITS.fileBytes) reject("MC_SKILL_FILE_LIMIT");
|
|
60
|
+
}
|
|
61
|
+
async function parents(io, full, ownedRoot, uid, missingAllowed = []) {
|
|
62
|
+
const chain = []; let current = "/";
|
|
63
|
+
const root = await io.lstat(current); safeDir(root, uid, false);
|
|
64
|
+
chain.push({ path: current, signature: dirSignature(root) });
|
|
65
|
+
const parts = full.slice(1).split("/");
|
|
66
|
+
for (const part of parts.slice(0, -1)) {
|
|
67
|
+
current = path.posix.join(current, part); let s;
|
|
68
|
+
try { s = await io.lstat(current); }
|
|
69
|
+
catch (e) {
|
|
70
|
+
if (errno(e) === "ENOENT" && missingAllowed.includes(current)) return { chain, missing: current };
|
|
71
|
+
reject(errno(e) === "ENOENT" ? "MC_SKILL_PATH_MISSING" : "MC_SKILL_UNREADABLE");
|
|
72
|
+
}
|
|
73
|
+
safeDir(s, uid, current === ownedRoot || current.startsWith(ownedRoot + "/"));
|
|
74
|
+
chain.push({ path: current, signature: dirSignature(s) });
|
|
75
|
+
}
|
|
76
|
+
return { chain, missing: null };
|
|
77
|
+
}
|
|
78
|
+
async function recheckParents(io, snapshot, ownedRoot, uid) {
|
|
79
|
+
for (const parent of snapshot.chain) {
|
|
80
|
+
let s; try { s = await io.lstat(parent.path); } catch { reject("MC_SKILL_CHANGED"); }
|
|
81
|
+
safeDir(s, uid, parent.path === ownedRoot || parent.path.startsWith(ownedRoot + "/"));
|
|
82
|
+
if (dirSignature(s) !== parent.signature) reject("MC_SKILL_CHANGED");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function targetSnapshot(io, descriptor, uid) {
|
|
86
|
+
const home = descriptor.identity.homeDirectory, target = descriptor.skill.target;
|
|
87
|
+
const snapshot = await parents(io, target, home, uid, [home + "/.agents", home + "/.agents/skills"]);
|
|
88
|
+
snapshot.stat = null; snapshot.link = null;
|
|
89
|
+
if (snapshot.missing) return snapshot;
|
|
90
|
+
let s;
|
|
91
|
+
try { s = await io.lstat(target); }
|
|
92
|
+
catch (e) { if (errno(e) === "ENOENT") { snapshot.missing = target; return snapshot; } reject("MC_SKILL_UNREADABLE"); }
|
|
93
|
+
if (s.uid !== uid) reject("MC_SKILL_TARGET_UNSAFE");
|
|
94
|
+
snapshot.stat = s;
|
|
95
|
+
if (s.isSymbolicLink()) {
|
|
96
|
+
if (s.nlink !== 1 || s.mode & 0o7000) reject("MC_SKILL_TARGET_UNSAFE");
|
|
97
|
+
snapshot.link = await linkText(io, target);
|
|
98
|
+
} else if (!s.isFile() && !s.isDirectory()) reject("MC_SKILL_TARGET_UNSAFE");
|
|
99
|
+
return snapshot;
|
|
100
|
+
}
|
|
101
|
+
async function linkText(io, target) {
|
|
102
|
+
// Native readlink must not silently replace invalid path bytes with U+FFFD.
|
|
103
|
+
const raw = await io.readlink(target, { encoding: "buffer" });
|
|
104
|
+
try {
|
|
105
|
+
const text = decode(copyBytes(raw, MEMORY_CONNECTION_SKILL_LIMITS.pathChars * 4));
|
|
106
|
+
if (text.length > MEMORY_CONNECTION_SKILL_LIMITS.pathChars) reject("MC_SKILL_TARGET_UNSAFE");
|
|
107
|
+
return text;
|
|
108
|
+
} catch { reject("MC_SKILL_TARGET_UNSAFE"); }
|
|
109
|
+
}
|
|
110
|
+
async function recheckTarget(io, descriptor, snapshot, uid) {
|
|
111
|
+
await recheckParents(io, snapshot, descriptor.identity.homeDirectory, uid);
|
|
112
|
+
if (snapshot.missing) {
|
|
113
|
+
try { await io.lstat(snapshot.missing); }
|
|
114
|
+
catch (e) { if (errno(e) === "ENOENT") return; reject("MC_SKILL_CHANGED"); }
|
|
115
|
+
reject("MC_SKILL_CHANGED");
|
|
116
|
+
}
|
|
117
|
+
let s;
|
|
118
|
+
try { s = await io.lstat(descriptor.skill.target); } catch { reject("MC_SKILL_CHANGED"); }
|
|
119
|
+
if (fileSignature(s) !== fileSignature(snapshot.stat)) reject("MC_SKILL_CHANGED");
|
|
120
|
+
if (snapshot.link !== null && await linkText(io, descriptor.skill.target) !== snapshot.link) reject("MC_SKILL_CHANGED");
|
|
121
|
+
}
|
|
122
|
+
async function sourceSnapshot(io, data, uid) {
|
|
123
|
+
const snapshot = await parents(io, data.sourceFile, data.descriptor.identity.vaultPath, uid);
|
|
124
|
+
let s;
|
|
125
|
+
try { s = await io.lstat(data.sourceFile); }
|
|
126
|
+
catch (e) { reject(errno(e) === "ENOENT" ? "MC_SKILL_SOURCE_MISSING" : "MC_SKILL_UNREADABLE"); }
|
|
127
|
+
safeSourceFile(s, uid); snapshot.stat = s; return snapshot;
|
|
128
|
+
}
|
|
129
|
+
async function recheckSource(io, data, snapshot, uid) {
|
|
130
|
+
await recheckParents(io, snapshot, data.descriptor.identity.vaultPath, uid);
|
|
131
|
+
let s;
|
|
132
|
+
try { s = await io.lstat(data.sourceFile); } catch { reject("MC_SKILL_CHANGED"); }
|
|
133
|
+
safeSourceFile(s, uid);
|
|
134
|
+
if (fileSignature(s) !== fileSignature(snapshot.stat)) reject("MC_SKILL_CHANGED");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Check only the exact own link and reviewed SKILL.md bytes. Never enumerate,
|
|
139
|
+
* interpret Skill text, follow foreign destinations, install, repair or execute.
|
|
140
|
+
* IO overrides are trusted simulations, not a sandbox or native-read evidence.
|
|
141
|
+
* Rechecks detect observable races; they are not atomic openat/ABA protection.
|
|
142
|
+
*/
|
|
143
|
+
export async function inspectMemoryConnectionSkill(input, dependencies = {}) {
|
|
144
|
+
let data = null, nativeIO = false;
|
|
145
|
+
const report = (state, details = {}) => {
|
|
146
|
+
const read = ["matched", "absent"].includes(state), observed = read || state === "conflict";
|
|
147
|
+
const result = {
|
|
148
|
+
schemaVersion: MEMORY_CONNECTION_VERSION, state, skillName: data?.descriptor.identity.skillName ?? null,
|
|
149
|
+
sourceSha256: null, metadataSha256: null, resolvedSource: null, reasons: [], ...details,
|
|
150
|
+
facts: {
|
|
151
|
+
...MEMORY_CONNECTION_FACTS, verificationScope: "skill-installation-only",
|
|
152
|
+
evidence: observed ? nativeIO ? read ? "local-skill-file" : "local-skill-metadata" : "simulated-local-skill" : "none",
|
|
153
|
+
targetObservationVerified: observed && nativeIO, skillSourceVerified: read && nativeIO,
|
|
154
|
+
localReadVerified: read && nativeIO, bytePinMatched: read,
|
|
155
|
+
skillFormatVerified: false, skillLoadedVerified: false
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
if (Buffer.byteLength(JSON.stringify(result)) > MEMORY_CONNECTION_SKILL_LIMITS.reportBytes) reject("MC_SKILL_REPORT_LIMIT");
|
|
159
|
+
return freezeMemoryConnectionData(result);
|
|
160
|
+
};
|
|
161
|
+
try {
|
|
162
|
+
data = inputs(input);
|
|
163
|
+
nativeIO = dependencies.io === undefined;
|
|
164
|
+
const io = dependencies.io ?? fs, uid = process.getuid?.();
|
|
165
|
+
if (!["darwin", "linux"].includes(process.platform) || !Number.isSafeInteger(uid) || constants.O_NOFOLLOW === undefined) reject("MC_SKILL_PLATFORM");
|
|
166
|
+
const descriptor = data.descriptor, target = await targetSnapshot(io, descriptor, uid);
|
|
167
|
+
await recheckTarget(io, descriptor, target, uid);
|
|
168
|
+
if (target.stat && target.link !== descriptor.skill.source) {
|
|
169
|
+
return report("conflict", { reasons: ["MC_SKILL_TARGET_CONFLICT"] });
|
|
170
|
+
}
|
|
171
|
+
const source = await sourceSnapshot(io, data, uid);
|
|
172
|
+
await recheckSource(io, data, source, uid); await recheckTarget(io, descriptor, target, uid);
|
|
173
|
+
let handle;
|
|
174
|
+
try { handle = await io.open(data.sourceFile, MEMORY_CONNECTION_SKILL_OPEN_FLAGS); }
|
|
175
|
+
catch (e) { reject(errno(e) === "ELOOP" ? "MC_SKILL_FILE_UNSAFE" : "MC_SKILL_UNREADABLE"); }
|
|
176
|
+
let bytes;
|
|
177
|
+
try {
|
|
178
|
+
const start = await handle.stat(); safeSourceFile(start, uid);
|
|
179
|
+
if (fileSignature(start) !== fileSignature(source.stat)) reject("MC_SKILL_CHANGED");
|
|
180
|
+
await recheckSource(io, data, source, uid); await recheckTarget(io, descriptor, target, uid);
|
|
181
|
+
bytes = Buffer.alloc(source.stat.size); let offset = 0;
|
|
182
|
+
while (offset < bytes.length) {
|
|
183
|
+
const request = Math.min(MEMORY_CONNECTION_SKILL_LIMITS.chunkBytes, bytes.length - offset);
|
|
184
|
+
const { bytesRead } = await handle.read(bytes, offset, request, offset);
|
|
185
|
+
if (!Number.isSafeInteger(bytesRead) || bytesRead < 0 || bytesRead > request) reject("MC_SKILL_READ");
|
|
186
|
+
if (!bytesRead) reject("MC_SKILL_CHANGED");
|
|
187
|
+
offset += bytesRead;
|
|
188
|
+
}
|
|
189
|
+
const after = await handle.stat(); safeSourceFile(after, uid);
|
|
190
|
+
if (fileSignature(after) !== fileSignature(source.stat)) reject("MC_SKILL_CHANGED");
|
|
191
|
+
await recheckSource(io, data, source, uid); await recheckTarget(io, descriptor, target, uid);
|
|
192
|
+
} finally {
|
|
193
|
+
try { await handle.close(); } catch { reject("MC_SKILL_CLOSE"); }
|
|
194
|
+
}
|
|
195
|
+
await recheckSource(io, data, source, uid); await recheckTarget(io, descriptor, target, uid);
|
|
196
|
+
const sha256 = digest(bytes);
|
|
197
|
+
if (sha256 !== data.expected) reject("MC_SKILL_PIN_MISMATCH");
|
|
198
|
+
const metadataSha256 = digest(JSON.stringify({
|
|
199
|
+
source: { path: data.sourceFile, parents: source.chain, signature: fileSignature(source.stat) },
|
|
200
|
+
target: { path: descriptor.skill.target, parents: target.chain, missing: target.missing,
|
|
201
|
+
signature: target.stat ? fileSignature(target.stat) : null, link: target.link }
|
|
202
|
+
}));
|
|
203
|
+
return report(target.missing ? "absent" : "matched", {
|
|
204
|
+
sourceSha256: sha256, metadataSha256,
|
|
205
|
+
resolvedSource: target.missing ? null : descriptor.skill.source,
|
|
206
|
+
reasons: [target.missing ? "MC_SKILL_TARGET_MISSING" : "MC_SKILL_MATCH"]
|
|
207
|
+
});
|
|
208
|
+
} catch (e) {
|
|
209
|
+
return report(e instanceof Rejected ? e.state : "blocked", { reasons: [e instanceof Rejected ? e.code : "MC_SKILL_IO"] });
|
|
210
|
+
}
|
|
211
|
+
}
|