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
package/src/init.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const SOURCE_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const TEMPLATE_ROOT = path.resolve(SOURCE_DIRECTORY, "../templates/project-memory");
|
|
9
|
+
const PROJECT_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
10
|
+
const KNOWN_AGENTS = ["codex", "claude", "antigravity"];
|
|
11
|
+
const BRANCH_PATTERN = /^(?!.*(?:\.\.|\/\/|@\{|\\))[A-Za-z0-9][A-Za-z0-9._/-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
|
|
12
|
+
const SYNC_MODES = new Set(["none", "git-manual", "git-automated"]);
|
|
13
|
+
|
|
14
|
+
export function initializeMemory(options, context = {}) {
|
|
15
|
+
const config = normalizeOptions(options, context);
|
|
16
|
+
validateConfig(config);
|
|
17
|
+
|
|
18
|
+
const generatedFiles = buildGeneratedFiles(config);
|
|
19
|
+
const files = generatedFiles.map((file) => inspectTarget(config.destination, file));
|
|
20
|
+
const conflicts = files.filter((file) => file.action === "conflict");
|
|
21
|
+
const report = createReport(config, files, options.apply === true);
|
|
22
|
+
|
|
23
|
+
if (conflicts.length > 0) {
|
|
24
|
+
report.status = "conflict";
|
|
25
|
+
return report;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!options.apply) {
|
|
29
|
+
report.status = "preview";
|
|
30
|
+
return report;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
if (file.action !== "create") {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fs.mkdirSync(path.dirname(file.absolutePath), { recursive: true });
|
|
39
|
+
fs.writeFileSync(file.absolutePath, file.content, {
|
|
40
|
+
encoding: "utf8",
|
|
41
|
+
flag: "wx"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
report.status = files.some((file) => file.action === "create")
|
|
46
|
+
? "created"
|
|
47
|
+
: "unchanged";
|
|
48
|
+
return report;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeOptions(options, context) {
|
|
52
|
+
const destination = resolvePhysicalPath(path.resolve(options.destination ?? ""));
|
|
53
|
+
const sourcePath = resolvePhysicalPath(path.resolve(options.sourcePath ?? ""));
|
|
54
|
+
const defaultBranch = options.defaultBranch ?? "main";
|
|
55
|
+
const integrationBranch = options.integrationBranch ?? defaultBranch;
|
|
56
|
+
const syncMode =
|
|
57
|
+
options.syncMode ?? (options.memoryRemote ? "git-manual" : "none");
|
|
58
|
+
const now = context.now ?? new Date();
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
destinationProvided: Boolean(options.destination),
|
|
62
|
+
sourceProvided: Boolean(options.sourcePath),
|
|
63
|
+
projectId: options.projectId?.trim(),
|
|
64
|
+
projectName: options.projectName?.trim(),
|
|
65
|
+
description:
|
|
66
|
+
options.description?.trim() ||
|
|
67
|
+
`Memoria organizada y privada de ${options.projectName?.trim() ?? ""}.`,
|
|
68
|
+
destination,
|
|
69
|
+
sourcePath,
|
|
70
|
+
sourceRemote: options.sourceRemote?.trim(),
|
|
71
|
+
memoryRemote: options.memoryRemote?.trim(),
|
|
72
|
+
defaultBranch,
|
|
73
|
+
integrationBranch,
|
|
74
|
+
memoryBranch: "main",
|
|
75
|
+
mcpName: options.mcpName?.trim() || `${options.projectId?.trim()}-memory`,
|
|
76
|
+
syncMode,
|
|
77
|
+
agents: options.agents ?? ["codex", "claude"],
|
|
78
|
+
date: formatDate(now),
|
|
79
|
+
templateRoot: path.resolve(context.templateRoot ?? TEMPLATE_ROOT)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function validateConfig(config) {
|
|
84
|
+
const errors = [];
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
!PROJECT_ID_PATTERN.test(config.projectId ?? "") ||
|
|
88
|
+
config.projectId?.length < 2 ||
|
|
89
|
+
config.projectId?.length > 64
|
|
90
|
+
) {
|
|
91
|
+
errors.push("--project-id debe usar minúsculas, números y guiones.");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!Array.isArray(config.agents) || config.agents.length === 0 ||
|
|
95
|
+
config.agents.some((agent) => !KNOWN_AGENTS.includes(agent)) ||
|
|
96
|
+
new Set(config.agents).size !== config.agents.length) {
|
|
97
|
+
errors.push("Los agentes deben ser codex, claude o antigravity, sin repetir.");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!config.projectName || config.projectName.length > 100) {
|
|
101
|
+
errors.push("--project-name es obligatorio y admite máximo 100 caracteres.");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!config.destinationProvided) {
|
|
105
|
+
errors.push("Debes indicar la ruta de destino.");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!config.sourceProvided) {
|
|
109
|
+
errors.push("--source es obligatorio.");
|
|
110
|
+
} else if (!isDirectory(config.sourcePath)) {
|
|
111
|
+
errors.push("--source debe apuntar a un directorio existente.");
|
|
112
|
+
} else if (!isGitRepository(config.sourcePath)) {
|
|
113
|
+
errors.push("--source debe pertenecer a un repositorio Git.");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
!BRANCH_PATTERN.test(config.defaultBranch) ||
|
|
118
|
+
config.defaultBranch.length > 255
|
|
119
|
+
) {
|
|
120
|
+
errors.push("--default-branch no es un nombre de rama válido.");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (
|
|
124
|
+
!BRANCH_PATTERN.test(config.integrationBranch) ||
|
|
125
|
+
config.integrationBranch.length > 255
|
|
126
|
+
) {
|
|
127
|
+
errors.push("--integration-branch no es un nombre de rama válido.");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!PROJECT_ID_PATTERN.test(config.mcpName) || config.mcpName.length > 80) {
|
|
131
|
+
errors.push("--mcp-name debe usar minúsculas, números y guiones.");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (config.description.length > 500) {
|
|
135
|
+
errors.push("--description no puede superar 500 caracteres.");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!SYNC_MODES.has(config.syncMode)) {
|
|
139
|
+
errors.push("--sync-mode debe ser none, git-manual o git-automated.");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (config.sourceRemote && hasEmbeddedCredentials(config.sourceRemote)) {
|
|
143
|
+
errors.push("--source-remote no puede contener credenciales.");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (config.memoryRemote && hasEmbeddedCredentials(config.memoryRemote)) {
|
|
147
|
+
errors.push("--memory-remote no puede contener credenciales.");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (config.destination === path.parse(config.destination).root) {
|
|
151
|
+
errors.push("El destino no puede ser la raíz del sistema de archivos.");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (config.destination === path.resolve(os.homedir())) {
|
|
155
|
+
errors.push("El destino no puede ser directamente el directorio personal.");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (fs.existsSync(config.destination) && !isDirectory(config.destination)) {
|
|
159
|
+
errors.push("El destino existente debe ser un directorio.");
|
|
160
|
+
} else if (
|
|
161
|
+
fs.existsSync(config.destination) &&
|
|
162
|
+
fs.lstatSync(config.destination).isSymbolicLink()
|
|
163
|
+
) {
|
|
164
|
+
errors.push("El destino no puede ser un enlace simbólico.");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
isSameOrInside(config.sourcePath, config.destination) ||
|
|
169
|
+
isSameOrInside(config.destination, config.sourcePath)
|
|
170
|
+
) {
|
|
171
|
+
errors.push("El repositorio fuente y la memoria deben estar separados.");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!isDirectory(config.templateRoot)) {
|
|
175
|
+
errors.push("No se encontró la plantilla canónica instalada.");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (errors.length > 0) {
|
|
179
|
+
throw new InitializationError(errors);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function buildGeneratedFiles(config) {
|
|
184
|
+
const replacements = {
|
|
185
|
+
PROJECT_ID: config.projectId,
|
|
186
|
+
PROJECT_NAME: config.projectName,
|
|
187
|
+
SOURCE_REPOSITORY: path.basename(config.sourcePath),
|
|
188
|
+
MEMORY_REPOSITORY: path.basename(config.destination),
|
|
189
|
+
MCP_SERVER_NAME: config.mcpName,
|
|
190
|
+
DEFAULT_BRANCH: config.defaultBranch,
|
|
191
|
+
INTEGRATION_BRANCH: config.integrationBranch,
|
|
192
|
+
DATE: config.date
|
|
193
|
+
};
|
|
194
|
+
const files = [];
|
|
195
|
+
|
|
196
|
+
files.push({
|
|
197
|
+
relativePath: "project-memory.json",
|
|
198
|
+
content: `${JSON.stringify(createManifest(config), null, 2)}\n`
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const vaultRoot = path.join(config.templateRoot, "vault");
|
|
202
|
+
for (const sourcePath of collectFiles(vaultRoot)) {
|
|
203
|
+
files.push({
|
|
204
|
+
relativePath: normalizeRelativePath(path.relative(vaultRoot, sourcePath)),
|
|
205
|
+
content: renderTemplate(fs.readFileSync(sourcePath, "utf8"), replacements)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const skillRoot = path.join(config.templateRoot, "skill/project-id");
|
|
210
|
+
for (const sourcePath of collectFiles(skillRoot)) {
|
|
211
|
+
const rendered = renderTemplate(
|
|
212
|
+
fs.readFileSync(sourcePath, "utf8"),
|
|
213
|
+
replacements
|
|
214
|
+
)
|
|
215
|
+
.replaceAll("project-id", config.projectId)
|
|
216
|
+
.replaceAll("Project Name", config.projectName);
|
|
217
|
+
files.push({
|
|
218
|
+
relativePath: normalizeRelativePath(
|
|
219
|
+
path.join(
|
|
220
|
+
"07-AGENTES/skills",
|
|
221
|
+
config.projectId,
|
|
222
|
+
path.relative(skillRoot, sourcePath)
|
|
223
|
+
)
|
|
224
|
+
),
|
|
225
|
+
content: rendered
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return files.sort((left, right) =>
|
|
230
|
+
left.relativePath.localeCompare(right.relativePath)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function createManifest(config) {
|
|
235
|
+
const documentationPaths = ["README.md", "docs"].filter((candidate) =>
|
|
236
|
+
fs.existsSync(path.join(config.sourcePath, candidate))
|
|
237
|
+
);
|
|
238
|
+
const source = {
|
|
239
|
+
repositoryPath: config.sourcePath,
|
|
240
|
+
defaultBranch: config.defaultBranch,
|
|
241
|
+
integrationBranch: config.integrationBranch
|
|
242
|
+
};
|
|
243
|
+
const memory = {
|
|
244
|
+
vaultPath: ".",
|
|
245
|
+
repositoryBranch: config.memoryBranch,
|
|
246
|
+
mcpServerName: config.mcpName,
|
|
247
|
+
syncMode: config.syncMode,
|
|
248
|
+
layout: {
|
|
249
|
+
profile: "canonical-v1"
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
if (config.sourceRemote) {
|
|
254
|
+
source.remoteUrl = config.sourceRemote;
|
|
255
|
+
}
|
|
256
|
+
if (documentationPaths.length > 0) {
|
|
257
|
+
source.documentationPaths = documentationPaths;
|
|
258
|
+
}
|
|
259
|
+
if (config.memoryRemote) {
|
|
260
|
+
memory.repositoryRemote = config.memoryRemote;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
schemaVersion: "1.0.0",
|
|
265
|
+
project: {
|
|
266
|
+
id: config.projectId,
|
|
267
|
+
name: config.projectName,
|
|
268
|
+
description: config.description
|
|
269
|
+
},
|
|
270
|
+
source,
|
|
271
|
+
memory,
|
|
272
|
+
agents: config.agents.map((id) => ({
|
|
273
|
+
id,
|
|
274
|
+
enabled: true,
|
|
275
|
+
skillName: config.projectId
|
|
276
|
+
})),
|
|
277
|
+
security: {
|
|
278
|
+
mcpAccess: "read-only",
|
|
279
|
+
sensitiveDataPolicy: "forbidden",
|
|
280
|
+
writeRequiresExplicitAuthorization: true,
|
|
281
|
+
allowCredentialsInMemory: false
|
|
282
|
+
},
|
|
283
|
+
automation: {
|
|
284
|
+
enabled: false,
|
|
285
|
+
reviewBranch: config.integrationBranch,
|
|
286
|
+
requiresMergedChange: true,
|
|
287
|
+
schedule: "Not configured"
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function inspectTarget(destination, generatedFile) {
|
|
293
|
+
const absolutePath = path.join(destination, generatedFile.relativePath);
|
|
294
|
+
const parentConflict = findParentConflict(destination, absolutePath);
|
|
295
|
+
|
|
296
|
+
if (parentConflict) {
|
|
297
|
+
return {
|
|
298
|
+
...generatedFile,
|
|
299
|
+
absolutePath,
|
|
300
|
+
action: "conflict",
|
|
301
|
+
reason: `Un componente de la ruta no es un directorio: ${parentConflict}`
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (!fs.existsSync(absolutePath)) {
|
|
306
|
+
return { ...generatedFile, absolutePath, action: "create" };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const stats = fs.lstatSync(absolutePath);
|
|
310
|
+
if (!stats.isFile() || stats.isSymbolicLink()) {
|
|
311
|
+
return {
|
|
312
|
+
...generatedFile,
|
|
313
|
+
absolutePath,
|
|
314
|
+
action: "conflict",
|
|
315
|
+
reason: "La ruta existente no es un archivo regular."
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const current = fs.readFileSync(absolutePath, "utf8");
|
|
320
|
+
if (current === generatedFile.content) {
|
|
321
|
+
return { ...generatedFile, absolutePath, action: "unchanged" };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
...generatedFile,
|
|
326
|
+
absolutePath,
|
|
327
|
+
action: "conflict",
|
|
328
|
+
reason: "El archivo existente tiene contenido diferente."
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function createReport(config, files, apply) {
|
|
333
|
+
return {
|
|
334
|
+
command: "init",
|
|
335
|
+
status: "preview",
|
|
336
|
+
mode: apply ? "apply" : "preview",
|
|
337
|
+
destination: config.destination,
|
|
338
|
+
project: {
|
|
339
|
+
id: config.projectId,
|
|
340
|
+
name: config.projectName
|
|
341
|
+
},
|
|
342
|
+
summary: {
|
|
343
|
+
create: files.filter((file) => file.action === "create").length,
|
|
344
|
+
unchanged: files.filter((file) => file.action === "unchanged").length,
|
|
345
|
+
conflicts: files.filter((file) => file.action === "conflict").length
|
|
346
|
+
},
|
|
347
|
+
files: files.map(({ relativePath, action, reason }) => ({
|
|
348
|
+
path: relativePath,
|
|
349
|
+
action,
|
|
350
|
+
...(reason ? { reason } : {})
|
|
351
|
+
}))
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function collectFiles(rootDirectory) {
|
|
356
|
+
const files = [];
|
|
357
|
+
const pending = [rootDirectory];
|
|
358
|
+
|
|
359
|
+
while (pending.length > 0) {
|
|
360
|
+
const current = pending.pop();
|
|
361
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
362
|
+
const fullPath = path.join(current, entry.name);
|
|
363
|
+
if (entry.isDirectory()) {
|
|
364
|
+
pending.push(fullPath);
|
|
365
|
+
} else if (entry.isFile()) {
|
|
366
|
+
files.push(fullPath);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return files.sort();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function renderTemplate(content, replacements) {
|
|
375
|
+
let rendered = content;
|
|
376
|
+
for (const [name, value] of Object.entries(replacements)) {
|
|
377
|
+
rendered = rendered.replaceAll(`{{${name}}}`, value);
|
|
378
|
+
}
|
|
379
|
+
return rendered;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function findParentConflict(destination, targetPath) {
|
|
383
|
+
let current = path.dirname(targetPath);
|
|
384
|
+
const root = path.resolve(destination);
|
|
385
|
+
|
|
386
|
+
while (current.startsWith(root) && current !== path.dirname(current)) {
|
|
387
|
+
if (fs.existsSync(current) && !isDirectory(current)) {
|
|
388
|
+
return current;
|
|
389
|
+
}
|
|
390
|
+
if (current === root) {
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
current = path.dirname(current);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function resolvePhysicalPath(candidate) {
|
|
400
|
+
let current = path.resolve(candidate);
|
|
401
|
+
const missingSegments = [];
|
|
402
|
+
|
|
403
|
+
while (!fs.existsSync(current) && current !== path.dirname(current)) {
|
|
404
|
+
missingSegments.unshift(path.basename(current));
|
|
405
|
+
current = path.dirname(current);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const physicalParent = fs.existsSync(current)
|
|
409
|
+
? fs.realpathSync(current)
|
|
410
|
+
: current;
|
|
411
|
+
return path.join(physicalParent, ...missingSegments);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function isSameOrInside(parentPath, candidatePath) {
|
|
415
|
+
const relative = path.relative(parentPath, candidatePath);
|
|
416
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function hasEmbeddedCredentials(value) {
|
|
420
|
+
try {
|
|
421
|
+
const url = new URL(value);
|
|
422
|
+
const sensitiveQueryKeys = [
|
|
423
|
+
"access_token",
|
|
424
|
+
"api_key",
|
|
425
|
+
"apikey",
|
|
426
|
+
"auth",
|
|
427
|
+
"password",
|
|
428
|
+
"secret",
|
|
429
|
+
"token"
|
|
430
|
+
];
|
|
431
|
+
return (
|
|
432
|
+
Boolean(url.username || url.password) ||
|
|
433
|
+
sensitiveQueryKeys.some((key) => url.searchParams.has(key))
|
|
434
|
+
);
|
|
435
|
+
} catch {
|
|
436
|
+
return /(?:access_token|api_key|password|secret|token)=/i.test(value);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function isGitRepository(directory) {
|
|
441
|
+
try {
|
|
442
|
+
execFileSync("git", ["-C", directory, "rev-parse", "--show-toplevel"], {
|
|
443
|
+
stdio: "ignore"
|
|
444
|
+
});
|
|
445
|
+
return true;
|
|
446
|
+
} catch {
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function isDirectory(candidate) {
|
|
452
|
+
try {
|
|
453
|
+
return fs.statSync(candidate).isDirectory();
|
|
454
|
+
} catch {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function normalizeRelativePath(value) {
|
|
460
|
+
return value.split(path.sep).join("/");
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function formatDate(date) {
|
|
464
|
+
return date.toISOString().slice(0, 10);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export class InitializationError extends Error {
|
|
468
|
+
constructor(details) {
|
|
469
|
+
super(details.join(" "));
|
|
470
|
+
this.name = "InitializationError";
|
|
471
|
+
this.details = details;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
const LOCK_FILE = 'bloqueo';
|
|
7
|
+
const MAX_RECOVERIES = 10;
|
|
8
|
+
|
|
9
|
+
export class LockError extends Error {
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'LockError';
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function defaultIsAlive(pid) {
|
|
18
|
+
try { process.kill(pid, 0); return true; } catch (error) { return error.code === 'EPERM'; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
22
|
+
const ignoreMissing = error => { if (error.code !== 'ENOENT') throw error; };
|
|
23
|
+
|
|
24
|
+
// The state is `missing`, `unreadable` (not valid JSON, wrong shape or not a regular file) or `ok`.
|
|
25
|
+
async function readOwner(file) {
|
|
26
|
+
let text;
|
|
27
|
+
try { text = await fs.readFile(file, 'utf8'); } catch (error) {
|
|
28
|
+
return error.code === 'ENOENT' ? { state: 'missing' } : { state: 'unreadable' };
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const data = JSON.parse(text);
|
|
32
|
+
if (Number.isInteger(data?.pid) && data.pid > 0 && typeof data.equipo === 'string' && typeof data.marca === 'string') {
|
|
33
|
+
return { state: 'ok', owner: data };
|
|
34
|
+
}
|
|
35
|
+
} catch { /* falls through */ }
|
|
36
|
+
return { state: 'unreadable' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Writes the record to a private file and hard-links it into place: the lock never exists half written.
|
|
40
|
+
async function createExclusive(file, record) {
|
|
41
|
+
const temporary = `${file}.nuevo-${crypto.randomUUID()}`;
|
|
42
|
+
await fs.writeFile(temporary, JSON.stringify(record), { mode: 0o600, flag: 'wx' });
|
|
43
|
+
try {
|
|
44
|
+
await fs.link(temporary, file);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error.code === 'EEXIST') return false;
|
|
48
|
+
throw error;
|
|
49
|
+
} finally {
|
|
50
|
+
await fs.unlink(temporary).catch(() => {});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Called only for an owner judged dead. The removal happens under a second guard, so two recoverers can never
|
|
55
|
+
// act at once. Under the guard only the dead lock can be at `file`: acquirers create it only when it is absent,
|
|
56
|
+
// and its dead owner will not release it. The guard itself is never removed by anyone but its holder: a guard
|
|
57
|
+
// left by a process that died in the middle of a recovery (a few milliseconds) must be removed by hand, because
|
|
58
|
+
// removing it by reading and deleting would reopen the same race. Returns 'recuperado' or 'ocupado'.
|
|
59
|
+
async function recover(file, judgedMark, { record }) {
|
|
60
|
+
const guard = `${file}.recuperando`;
|
|
61
|
+
if (!(await createExclusive(guard, record))) return 'ocupado';
|
|
62
|
+
try {
|
|
63
|
+
const again = await readOwner(file);
|
|
64
|
+
if (again.state === 'ok' && again.owner.marca === judgedMark) await fs.unlink(file).catch(ignoreMissing);
|
|
65
|
+
return 'recuperado';
|
|
66
|
+
} finally {
|
|
67
|
+
const current = await readOwner(guard);
|
|
68
|
+
if (current.state === 'ok' && current.owner.marca === record.marca) await fs.unlink(guard).catch(ignoreMissing);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const busy = (file, unreadable) => new LockError('ocupado', unreadable
|
|
73
|
+
? `No se puede leer el bloqueo de nexakit. Si no hay ninguna instalación en curso, bórralo a mano: ${file}`
|
|
74
|
+
: 'Otra instalación de nexakit está en curso; vuelve a intentarlo cuando termine.');
|
|
75
|
+
|
|
76
|
+
export async function acquireLock(nexakitDir, {
|
|
77
|
+
waitMs = 30_000, pollMs = 250, hostname = os.hostname(), pid = process.pid, isAlive = defaultIsAlive
|
|
78
|
+
} = {}) {
|
|
79
|
+
await fs.mkdir(nexakitDir, { recursive: true, mode: 0o700 });
|
|
80
|
+
const file = path.join(nexakitDir, LOCK_FILE);
|
|
81
|
+
const token = crypto.randomUUID();
|
|
82
|
+
const record = { pid, equipo: hostname, hora: new Date().toISOString(), marca: token };
|
|
83
|
+
const deadline = Date.now() + waitMs;
|
|
84
|
+
let recoveries = 0;
|
|
85
|
+
|
|
86
|
+
while (true) {
|
|
87
|
+
if (await createExclusive(file, record)) return heldLock(file, token);
|
|
88
|
+
|
|
89
|
+
const current = await readOwner(file);
|
|
90
|
+
if (current.state === 'missing') continue;
|
|
91
|
+
if (current.state === 'ok') {
|
|
92
|
+
const { owner } = current;
|
|
93
|
+
if (owner.equipo !== hostname) {
|
|
94
|
+
throw new LockError('otro-equipo', `El bloqueo de nexakit lo creó otro equipo (${owner.equipo}). Si no hay ninguna instalación en curso, bórralo a mano: ${file}`);
|
|
95
|
+
}
|
|
96
|
+
// Age never decides: a live owner keeps the lock however long it takes.
|
|
97
|
+
if (!isAlive(owner.pid) && await recover(file, owner.marca, { record }) === 'recuperado') {
|
|
98
|
+
if (++recoveries > MAX_RECOVERIES) throw busy(file, false);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (Date.now() >= deadline) {
|
|
103
|
+
const guard = await readOwner(`${file}.recuperando`);
|
|
104
|
+
if (guard.state === 'ok' && guard.owner.equipo === hostname && !isAlive(guard.owner.pid)) {
|
|
105
|
+
throw new LockError('ocupado', `Se interrumpió una recuperación anterior del bloqueo de nexakit. Si no hay ninguna instalación en curso, borra a mano: ${file}.recuperando`);
|
|
106
|
+
}
|
|
107
|
+
throw busy(file, current.state === 'unreadable');
|
|
108
|
+
}
|
|
109
|
+
await sleep(Math.max(1, Math.min(pollMs, deadline - Date.now())));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function heldLock(file, token) {
|
|
114
|
+
return {
|
|
115
|
+
token,
|
|
116
|
+
async assertHeld() {
|
|
117
|
+
const current = await readOwner(file);
|
|
118
|
+
if (!(current.state === 'ok' && current.owner.marca === token)) {
|
|
119
|
+
throw new LockError('perdido', 'Se perdió el bloqueo de nexakit; no se escribió nada más.');
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
async release() {
|
|
123
|
+
const current = await readOwner(file);
|
|
124
|
+
if (current.state === 'ok' && current.owner.marca === token) await fs.unlink(file).catch(ignoreMissing);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
const REGISTRY_FILE = 'instalaciones.json';
|
|
6
|
+
const MAX_REGISTRY_BYTES = 4 * 1024 * 1024;
|
|
7
|
+
const FIELDS = ['destino', 'apunta', 'raiz', 'fecha'];
|
|
8
|
+
|
|
9
|
+
const damaged = file => new Error(`El registro de instalaciones de nexakit está dañado: ${file}`);
|
|
10
|
+
const isText = value => typeof value === 'string' && value.length > 0;
|
|
11
|
+
const empty = () => ({ version: 1, entradas: [] });
|
|
12
|
+
|
|
13
|
+
// The registry is the only proof that a broken link belongs to nexakit. `apunta` must be what `readlink`
|
|
14
|
+
// returns for the link, since that is the value compared later.
|
|
15
|
+
export async function readRegistry(nexakitDir) {
|
|
16
|
+
const file = path.join(nexakitDir, REGISTRY_FILE);
|
|
17
|
+
let info;
|
|
18
|
+
try { info = await fs.lstat(file); } catch (error) {
|
|
19
|
+
if (error.code === 'ENOENT') return empty();
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
if (!info.isFile() || info.size > MAX_REGISTRY_BYTES) throw damaged(file);
|
|
23
|
+
let data;
|
|
24
|
+
try { data = JSON.parse(await fs.readFile(file, 'utf8')); } catch { throw damaged(file); }
|
|
25
|
+
const valid = data?.version === 1 && Array.isArray(data.entradas) &&
|
|
26
|
+
data.entradas.every(entry => entry && typeof entry === 'object' && FIELDS.every(field => isText(entry[field])));
|
|
27
|
+
if (!valid) throw damaged(file);
|
|
28
|
+
return {
|
|
29
|
+
version: 1,
|
|
30
|
+
entradas: data.entradas.map(({ destino, apunta, raiz, fecha }) => ({ destino, apunta, raiz, fecha }))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const isRegistered = (registry, target, literal) =>
|
|
35
|
+
registry.entradas.some(entry => entry.destino === target && entry.apunta === literal);
|
|
36
|
+
|
|
37
|
+
// Must run under the install lock: the lock is checked on entry and again right before the file is replaced.
|
|
38
|
+
export async function recordEntries(nexakitDir, entries, lock) {
|
|
39
|
+
if (!Array.isArray(entries) || !entries.every(entry => isText(entry?.destino) && isText(entry?.apunta) && isText(entry?.raiz))) {
|
|
40
|
+
throw new Error('Entrada del registro de instalaciones no válida.');
|
|
41
|
+
}
|
|
42
|
+
if (entries.length === 0) return;
|
|
43
|
+
await lock.assertHeld();
|
|
44
|
+
|
|
45
|
+
const registry = await readRegistry(nexakitDir);
|
|
46
|
+
const fecha = new Date().toISOString();
|
|
47
|
+
// A Map keeps the position of an entry that is replaced.
|
|
48
|
+
const byTarget = new Map(registry.entradas.map(entry => [entry.destino, entry]));
|
|
49
|
+
for (const { destino, apunta, raiz } of entries) byTarget.set(destino, { destino, apunta, raiz, fecha });
|
|
50
|
+
|
|
51
|
+
const file = path.join(nexakitDir, REGISTRY_FILE);
|
|
52
|
+
const temporary = `${file}.${crypto.randomUUID()}.tmp`;
|
|
53
|
+
try {
|
|
54
|
+
await fs.writeFile(temporary, `${JSON.stringify({ version: 1, entradas: [...byTarget.values()] }, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
55
|
+
await lock.assertHeld();
|
|
56
|
+
await fs.rename(temporary, file);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
await fs.unlink(temporary).catch(() => {});
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|