@open-mercato/cli 0.6.7 → 0.6.8-canary.320.1.bf889f49e4
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/.turbo/turbo-build.log +77 -4
- package/AGENTS.md +6 -1
- package/build.mjs +68 -11
- package/dist/agentic/claude-code/hooks/entity-migration-check.ts +32 -88
- package/dist/agentic/codex/enforcement-rules.md +2 -16
- package/dist/agentic/cursor/hooks/entity-migration-check.mjs +19 -50
- package/dist/agentic/cursor/rules/entity-guard.mdc +9 -21
- package/dist/agentic/cursor/rules/generated-guard.mdc +3 -5
- package/dist/agentic/cursor/rules/open-mercato.mdc +3 -29
- package/dist/agentic/guides/ai-workflows.md +76 -0
- package/dist/agentic/guides/architecture.md +107 -0
- package/dist/agentic/guides/backend-ui.md +86 -0
- package/dist/agentic/guides/contracts.md +92 -0
- package/dist/agentic/guides/extensions.md +121 -0
- package/dist/agentic/guides/framework-extension-points.md +36 -0
- package/dist/agentic/guides/integrations.md +81 -0
- package/dist/agentic/guides/module-facts.json +116757 -3951
- package/dist/agentic/guides/module-system.md +12 -127
- package/dist/agentic/guides/modules/ai_assistant.md +227 -28
- package/dist/agentic/guides/modules/api_docs.md +58 -2
- package/dist/agentic/guides/modules/api_keys.md +92 -7
- package/dist/agentic/guides/modules/attachments.md +119 -14
- package/dist/agentic/guides/modules/audit_logs.md +131 -10
- package/dist/agentic/guides/modules/auth.md +276 -33
- package/dist/agentic/guides/modules/business_rules.md +149 -14
- package/dist/agentic/guides/modules/catalog.md +482 -43
- package/dist/agentic/guides/modules/channel_gmail.md +82 -3
- package/dist/agentic/guides/modules/channel_imap.md +82 -3
- package/dist/agentic/guides/modules/checkout.md +305 -27
- package/dist/agentic/guides/modules/communication_channels.md +315 -33
- package/dist/agentic/guides/modules/configs.md +104 -8
- package/dist/agentic/guides/modules/content.md +57 -2
- package/dist/agentic/guides/modules/currencies.md +152 -17
- package/dist/agentic/guides/modules/customer_accounts.md +387 -45
- package/dist/agentic/guides/modules/customers.md +746 -85
- package/dist/agentic/guides/modules/dashboards.md +155 -10
- package/dist/agentic/guides/modules/data_sync.md +149 -16
- package/dist/agentic/guides/modules/design_system.md +102 -0
- package/dist/agentic/guides/modules/dictionaries.md +107 -12
- package/dist/agentic/guides/modules/directory.md +148 -15
- package/dist/agentic/guides/modules/entities.md +145 -13
- package/dist/agentic/guides/modules/events.md +59 -2
- package/dist/agentic/guides/modules/feature_toggles.md +119 -9
- package/dist/agentic/guides/modules/gateway_stripe.md +92 -4
- package/dist/agentic/guides/modules/generators.md +45 -2
- package/dist/agentic/guides/modules/inbox_ops.md +207 -27
- package/dist/agentic/guides/modules/integrations.md +149 -16
- package/dist/agentic/guides/modules/messages.md +223 -24
- package/dist/agentic/guides/modules/notifications.md +96 -8
- package/dist/agentic/guides/modules/onboarding.md +77 -6
- package/dist/agentic/guides/modules/payment_gateways.md +168 -21
- package/dist/agentic/guides/modules/perspectives.md +77 -7
- package/dist/agentic/guides/modules/planner.md +136 -18
- package/dist/agentic/guides/modules/portal.md +93 -2
- package/dist/agentic/guides/modules/progress.md +104 -14
- package/dist/agentic/guides/modules/query_index.md +154 -15
- package/dist/agentic/guides/modules/record_locks.md +206 -21
- package/dist/agentic/guides/modules/resources.md +197 -30
- package/dist/agentic/guides/modules/sales.md +687 -84
- package/dist/agentic/guides/modules/scheduler.md +133 -14
- package/dist/agentic/guides/modules/search.md +170 -6
- package/dist/agentic/guides/modules/security.md +294 -35
- package/dist/agentic/guides/modules/shipping_carriers.md +134 -18
- package/dist/agentic/guides/modules/sso.md +151 -26
- package/dist/agentic/guides/modules/staff.md +372 -57
- package/dist/agentic/guides/modules/storage_s3.md +95 -5
- package/dist/agentic/guides/modules/sync_akeneo.md +85 -3
- package/dist/agentic/guides/modules/sync_excel.md +75 -6
- package/dist/agentic/guides/modules/system_status_overlays.md +60 -2
- package/dist/agentic/guides/modules/translations.md +104 -10
- package/dist/agentic/guides/modules/webhooks.md +203 -24
- package/dist/agentic/guides/modules/wms.md +469 -47
- package/dist/agentic/guides/modules/workflows.md +302 -43
- package/dist/agentic/guides/reference-module-facts.json +6942 -0
- package/dist/agentic/guides/reference-modules/example.md +462 -0
- package/dist/agentic/guides/spec-delivery.md +56 -0
- package/dist/agentic/guides/testing-debugging.md +80 -0
- package/dist/agentic/guides/upstream/AGENTS.md +300 -0
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +334 -0
- package/dist/agentic/guides/upstream/manifest.json +8 -0
- package/dist/agentic/shared/AGENTS.md.template +120 -311
- package/dist/agentic/shared/ai/agentic.config.json +2 -0
- package/dist/agentic/shared/ai/harness/README.md +50 -0
- package/dist/agentic/shared/ai/harness/RELEASE.md +59 -0
- package/dist/agentic/shared/ai/harness/cases.json +20596 -0
- package/dist/agentic/shared/ai/harness/cases.schema.json +196 -0
- package/dist/agentic/shared/ai/harness/design-system-inventory.json +6326 -0
- package/dist/agentic/shared/ai/harness/fixtures/index.json +51 -0
- package/dist/agentic/shared/ai/harness/fixtures/seeds.json +166 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-policy.md +21 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-response.schema.json +96 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-result.schema.json +172 -0
- package/dist/agentic/shared/ai/harness/knowledge-change.schema.json +228 -0
- package/dist/agentic/shared/ai/harness/release-matrix.json +163 -0
- package/dist/agentic/shared/ai/harness/release-result.schema.json +219 -0
- package/dist/agentic/shared/ai/harness/result.schema.json +136 -0
- package/dist/agentic/shared/ai/harness/routing-response.schema.json +22 -0
- package/dist/agentic/shared/ai/harness/source-link-inventory.json +1706 -0
- package/dist/agentic/shared/ai/harness/target-validation-result.schema.json +73 -0
- package/dist/agentic/shared/ai/harness/validators.json +82 -0
- package/dist/agentic/shared/ai/harness/writable-ast-oracles.mjs +2121 -0
- package/dist/agentic/shared/ai/harness/writable-behavior-oracles.mjs +1096 -0
- package/dist/agentic/shared/ai/harness/writable-spec-oracles.mjs +602 -0
- package/dist/agentic/shared/ai/lessons/_template.md +16 -0
- package/dist/agentic/shared/ai/lessons.md +26 -3
- package/dist/agentic/shared/ai/review-checklist.md +36 -0
- package/dist/agentic/shared/ai/skills/om-auto-implement-spec/SKILL.md +21 -0
- package/dist/agentic/shared/ai/skills/om-auto-review-pr/SKILL.md +4 -0
- package/dist/agentic/shared/ai/skills/om-auto-upgrade-0.6.6-to-0.6.7/SKILL.md +98 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/SKILL.md +21 -241
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/crud-surfaces.md +31 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/frontend-and-design-system.md +53 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/page-and-navigation.md +15 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/quality-states.md +11 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/SKILL.md +30 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/activity-contracts.md +12 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/durability-and-progress.md +13 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/workflow-design.md +14 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/SKILL.md +28 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/attachments-and-overrides.md +12 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/module-agents-and-tools.md +22 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/orchestrator-agents.md +12 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/surface-selector.md +19 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/SKILL.md +17 -601
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/integrity-and-concurrency.md +21 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/migration-workflow.md +15 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/schema-design.md +16 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/sensitive-data.md +10 -0
- package/dist/agentic/shared/ai/skills/om-eject-and-customize/SKILL.md +15 -310
- package/dist/agentic/shared/ai/skills/om-eject-and-customize/references/decision-and-procedure.md +19 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +31 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-template.md +100 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-workflow.md +16 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/knowledge-change.md +133 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/owner-selection.md +17 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/SKILL.md +25 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/references/resolver-procedure.md +11 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/references/skew-and-escalation.md +13 -0
- package/dist/agentic/shared/ai/skills/om-help/SKILL.md +15 -97
- package/dist/agentic/shared/ai/skills/om-help/references/delivery-workflows.md +18 -0
- package/dist/agentic/shared/ai/skills/om-help/references/task-families.md +20 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/SKILL.md +33 -152
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/phases-and-gates.md +33 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/planning-and-progress.md +40 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/report-templates.md +27 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/spec-resolution.md +24 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/SKILL.md +25 -708
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/package-and-activation.md +16 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +25 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/security-and-reliability.md +15 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/sync-and-files.md +12 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/SKILL.md +34 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/agents/openai.yaml +4 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/agentic-setup.md +11 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/input-normalization.md +31 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/judge-workflow.md +39 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/report-template.md +43 -0
- package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/rules.md +11 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +20 -820
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/api-and-domain.md +32 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/business-one-shot-blueprints.md +172 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/data-and-migrations.md +14 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/discovery-surface-catalog.md +83 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/module-surfaces.md +40 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/planning.md +11 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/runtime-cache-and-queues.md +22 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/verification.md +13 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/SKILL.md +41 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/agentic-setup.md +19 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/bundle-preparation.md +44 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/consent-and-review.md +39 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/publication.md +20 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/report-templates.md +57 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/references/rules.md +11 -0
- package/dist/agentic/shared/ai/skills/om-share-this-session/scripts/prepare-share-bundle.mjs +486 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +20 -843
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +42 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +27 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/read-write-roundtrip.md +13 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +43 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/verification.md +11 -0
- package/dist/agentic/shared/ai/skills/om-trim-unused-modules/SKILL.md +15 -63
- package/dist/agentic/shared/ai/skills/om-trim-unused-modules/references/dependency-and-redirect.md +15 -0
- package/dist/agentic/shared/ai/skills/om-troubleshooter/SKILL.md +17 -467
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnosis-map.md +29 -0
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/regression-oracles.md +14 -0
- package/dist/agentic/shared/ai/skills/tiers.json +143 -21
- package/dist/agentic/shared/ai/skills/tiers.schema.json +52 -40
- package/dist/agentic/shared/ai/specs/2026-08-06-reference-module-activation.md +248 -0
- package/dist/agentic/shared/ai/specs/README.md +4 -3
- package/dist/agentic/shared/ai/specs/SPEC-000-template.md +226 -10
- package/dist/agentic/shared/ai/trackers/github.md +108 -4
- package/dist/agentic/shared/scripts/agent-harness-tool-server.mjs +224 -0
- package/dist/agentic/shared/scripts/check-lessons.mjs +178 -0
- package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +3812 -0
- package/dist/agentic/shared/scripts/execution-sandbox.mjs +329 -0
- package/dist/agentic/shared/scripts/framework-context.mjs +888 -0
- package/dist/agentic/shared/scripts/install-skills.mjs +1029 -0
- package/dist/agentic/shared/scripts/install-skills.sh +4 -694
- package/dist/agentic/shared/scripts/prepare-agent-harness-fixture.mjs +222 -0
- package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +1774 -0
- package/dist/agentic/shared/scripts/validate-knowledge-change.mjs +1172 -0
- package/dist/bin.js +32 -34
- package/dist/bin.js.map +2 -2
- package/dist/lib/__integration__/TC-INT-008.spec.js +88 -8
- package/dist/lib/__integration__/TC-INT-008.spec.js.map +2 -2
- package/dist/lib/agentic-init.js +13 -3
- package/dist/lib/agentic-init.js.map +2 -2
- package/dist/lib/agentic-setup.js +434 -186
- package/dist/lib/agentic-setup.js.map +2 -2
- package/dist/lib/cli-bootstrap-mode.js +32 -0
- package/dist/lib/cli-bootstrap-mode.js.map +7 -0
- package/dist/lib/dev-supervisor-manifest.js +105 -0
- package/dist/lib/dev-supervisor-manifest.js.map +7 -0
- package/dist/lib/generate-watch-events.js +15 -0
- package/dist/lib/generate-watch-events.js.map +2 -2
- package/dist/lib/generators/entity-ids.js +11 -24
- package/dist/lib/generators/entity-ids.js.map +2 -2
- package/dist/lib/generators/extensions/injection-widgets.js +20 -0
- package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
- package/dist/lib/generators/module-di.js +10 -23
- package/dist/lib/generators/module-di.js.map +2 -2
- package/dist/lib/generators/module-entities.js +10 -23
- package/dist/lib/generators/module-entities.js.map +2 -2
- package/dist/lib/generators/module-extension-facts.js +1882 -0
- package/dist/lib/generators/module-extension-facts.js.map +7 -0
- package/dist/lib/generators/module-fact-sources.js +70 -0
- package/dist/lib/generators/module-fact-sources.js.map +7 -0
- package/dist/lib/generators/module-facts-discovery.js +64 -7
- package/dist/lib/generators/module-facts-discovery.js.map +2 -2
- package/dist/lib/generators/module-facts.js +1913 -52
- package/dist/lib/generators/module-facts.js.map +3 -3
- package/dist/lib/generators/module-override-targets.js +712 -0
- package/dist/lib/generators/module-override-targets.js.map +7 -0
- package/dist/lib/generators/module-registry.js +405 -36
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/generators/route-manifest-shards.js +170 -0
- package/dist/lib/generators/route-manifest-shards.js.map +7 -0
- package/dist/lib/in-process-generate-watcher.js +12 -3
- package/dist/lib/in-process-generate-watcher.js.map +2 -2
- package/dist/lib/load-env.js +24 -0
- package/dist/lib/load-env.js.map +7 -0
- package/dist/lib/queue-worker-supervisor.js.map +2 -2
- package/dist/lib/resolver.js +28 -3
- package/dist/lib/resolver.js.map +2 -2
- package/dist/lib/telemetry-init.js +358 -0
- package/dist/lib/telemetry-init.js.map +7 -0
- package/dist/lib/testing/integration.js +5 -2
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/lib/utils.js +15 -8
- package/dist/lib/utils.js.map +2 -2
- package/dist/mercato.js +35 -9
- package/dist/mercato.js.map +2 -2
- package/package.json +13 -11
- package/src/__tests__/mercato.test.ts +144 -0
- package/src/bin.ts +60 -42
- package/src/lib/__integration__/TC-INT-008.spec.ts +107 -9
- package/src/lib/__tests__/agentic-init.test.ts +41 -5
- package/src/lib/__tests__/agentic-setup.ownership.test.ts +386 -0
- package/src/lib/__tests__/cli-bootstrap-mode.test.ts +22 -0
- package/src/lib/__tests__/content-stable-writes.test.ts +74 -0
- package/src/lib/__tests__/dev-supervisor-manifest.test.ts +131 -0
- package/src/lib/__tests__/generate-watch-events.test.ts +76 -0
- package/src/lib/__tests__/in-process-generate-watcher.test.ts +52 -1
- package/src/lib/__tests__/injection-widget-id-validation.test.ts +184 -0
- package/src/lib/__tests__/load-env.test.ts +65 -0
- package/src/lib/__tests__/queue-worker-supervisor.test.ts +33 -0
- package/src/lib/__tests__/resolver.enterprise.test.ts +50 -0
- package/src/lib/__tests__/telemetry-init.test.ts +298 -0
- package/src/lib/agentic-init.ts +15 -3
- package/src/lib/agentic-setup.ts +573 -222
- package/src/lib/cli-bootstrap-mode.ts +31 -0
- package/src/lib/dev-supervisor-manifest.ts +142 -0
- package/src/lib/generate-watch-events.ts +14 -0
- package/src/lib/generators/__tests__/activation-adapter-coverage.test.ts +92 -0
- package/src/lib/generators/__tests__/entity-ids.test.ts +32 -0
- package/src/lib/generators/__tests__/helpers/override-target-diagnostic-fixtures.ts +150 -0
- package/src/lib/generators/__tests__/module-extension-activations.test.ts +762 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +603 -0
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +139 -2
- package/src/lib/generators/__tests__/module-facts.computed-di-token.test.ts +88 -0
- package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.discovery.test.ts +54 -10
- package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +414 -0
- package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +108 -0
- package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +393 -0
- package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +561 -0
- package/src/lib/generators/__tests__/module-facts.search-entity-id.test.ts +151 -0
- package/src/lib/generators/__tests__/module-facts.source-links.test.ts +160 -0
- package/src/lib/generators/__tests__/module-override-targets.diagnostic-wiring.test.ts +92 -0
- package/src/lib/generators/__tests__/module-override-targets.roundtrip.test.ts +149 -0
- package/src/lib/generators/__tests__/module-override-targets.test.ts +328 -0
- package/src/lib/generators/__tests__/module-override-targets.unknown-mode.test.ts +117 -0
- package/src/lib/generators/__tests__/module-subset.test.ts +266 -0
- package/src/lib/generators/__tests__/output-snapshots.test.ts +3 -3
- package/src/lib/generators/__tests__/route-manifest-shards.test.ts +62 -0
- package/src/lib/generators/entity-ids.ts +10 -26
- package/src/lib/generators/extensions/injection-widgets.ts +51 -0
- package/src/lib/generators/module-di.ts +9 -25
- package/src/lib/generators/module-entities.ts +9 -25
- package/src/lib/generators/module-extension-facts.ts +2472 -0
- package/src/lib/generators/module-fact-sources.ts +108 -0
- package/src/lib/generators/module-facts-discovery.ts +104 -7
- package/src/lib/generators/module-facts.ts +2747 -138
- package/src/lib/generators/module-override-targets.ts +907 -0
- package/src/lib/generators/module-registry.ts +448 -35
- package/src/lib/generators/route-manifest-shards.ts +146 -0
- package/src/lib/in-process-generate-watcher.ts +13 -4
- package/src/lib/load-env.ts +30 -0
- package/src/lib/queue-worker-supervisor.ts +7 -2
- package/src/lib/resolver.ts +34 -3
- package/src/lib/telemetry-init.ts +461 -0
- package/src/lib/testing/__tests__/integration.test.ts +4 -0
- package/src/lib/testing/integration.ts +5 -2
- package/src/lib/utils.ts +24 -16
- package/src/mercato.ts +46 -9
- package/dist/agentic/guides/cache.md +0 -45
- package/dist/agentic/guides/core.md +0 -453
- package/dist/agentic/guides/events.md +0 -117
- package/dist/agentic/guides/queue.md +0 -53
- package/dist/agentic/guides/search.md +0 -115
- package/dist/agentic/guides/shared.md +0 -108
- package/dist/agentic/guides/ui.md +0 -347
- package/dist/agentic/shared/ai/skills/om-auto-continue-pr-loop/SKILL.md +0 -27
- package/dist/agentic/shared/ai/skills/om-auto-create-pr-loop/SKILL.md +0 -27
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/ui-components.md +0 -260
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/mikro-orm-cheatsheet.md +0 -146
- package/dist/agentic/shared/ai/skills/om-help/references/skills-catalog.md +0 -84
- package/dist/agentic/shared/ai/skills/om-help/references/workflow-sequences.md +0 -193
- package/dist/agentic/shared/ai/skills/om-integration-builder/STANDALONE.md +0 -34
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/adapter-contracts.md +0 -762
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/naming-conventions.md +0 -50
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/navigation-patterns.md +0 -97
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-contracts.md +0 -271
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnostic-commands.md +0 -101
package/dist/lib/resolver.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/resolver.ts"],
|
|
4
|
-
"sourcesContent": ["import path from 'node:path'\nimport fs from 'node:fs'\nimport ts from 'typescript-js'\nimport { parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'\n\n/**\n * Resolved execution environment for the CLI.\n * Produced once by resolveEnvironment() and consumed by all subsystems.\n * Eliminates per-subsystem isMonorepo() branching and hardcoded path segments.\n */\nexport type CliEnvironment = {\n /** Whether the CLI is running inside a Yarn/npm workspace monorepo. */\n mode: 'monorepo' | 'standalone'\n /** Workspace or project root (where package.json / node_modules live). */\n rootDir: string\n /** Next.js application directory (contains src/, package.json, next.config.*). */\n appDir: string\n /**\n * Resolve the root directory of an installed @open-mercato package.\n * Monorepo: packages/<pkg>/ Standalone: node_modules/<pkg>/\n */\n packageRoot: (packageName: string) => string\n}\n\nexport type ModuleEntry = {\n id: string\n from?: '@open-mercato/core' | '@app' | string\n}\n\nexport type PackageInfo = {\n name: string\n path: string\n modulesPath: string\n}\n\nexport interface PackageResolver {\n isMonorepo(): boolean\n getRootDir(): string\n getAppDir(): string\n getOutputDir(): string\n getModulesConfigPath(): string\n discoverPackages(): PackageInfo[]\n loadEnabledModules(): ModuleEntry[]\n getModulePaths(entry: ModuleEntry): { appBase: string; pkgBase: string }\n getModuleImportBase(entry: ModuleEntry): { appBase: string; pkgBase: string }\n getPackageOutputDir(packageName: string): string\n getPackageRoot(from?: string): string\n}\n\nfunction pkgDirFor(rootDir: string, from?: string, isMonorepo = true): string {\n if (!isMonorepo) {\n const pkgName = from || '@open-mercato/core'\n const pkgRoot = path.join(rootDir, 'node_modules', pkgName)\n const distModules = path.join(pkgRoot, 'dist', 'modules')\n if (fs.existsSync(distModules)) return distModules\n return path.join(pkgRoot, 'src', 'modules')\n }\n\n // Monorepo mode - read from src/modules (TypeScript source)\n if (!from || from === '@open-mercato/core') {\n return path.resolve(rootDir, 'packages/core/src/modules')\n }\n // Support other local packages like '@open-mercato/onboarding' => packages/onboarding/src/modules\n const m = from.match(/^@open-mercato\\/(.+)$/)\n if (m) {\n return path.resolve(rootDir, `packages/${m[1]}/src/modules`)\n }\n // Fallback to core modules path\n return path.resolve(rootDir, 'packages/core/src/modules')\n}\n\nfunction pkgRootFor(rootDir: string, from?: string, isMonorepo = true): string {\n if (!isMonorepo) {\n const pkgName = from || '@open-mercato/core'\n return path.join(rootDir, 'node_modules', pkgName)\n }\n\n if (!from || from === '@open-mercato/core') {\n return path.resolve(rootDir, 'packages/core')\n }\n const m = from.match(/^@open-mercato\\/(.+)$/)\n if (m) {\n return path.resolve(rootDir, `packages/${m[1]}`)\n }\n return path.resolve(rootDir, 'packages/core')\n}\n\nfunction parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): ModuleEntry | null {\n let id: string | null = null\n let from: string | null = null\n for (const property of node.properties) {\n if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) continue\n const key = property.name.text\n if (key === 'id' && ts.isStringLiteralLike(property.initializer)) {\n id = property.initializer.text\n }\n if (key === 'from' && ts.isStringLiteralLike(property.initializer)) {\n from = property.initializer.text\n }\n }\n if (!id) return null\n return { id, from: from ?? '@open-mercato/core' }\n}\n\nfunction parseProcessEnvAccess(\n node: ts.Expression,\n env: NodeJS.ProcessEnv,\n): { matched: boolean; value: string | undefined } {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const target = node.expression\n if (\n ts.isPropertyAccessExpression(target)\n && ts.isIdentifier(target.expression)\n && target.expression.text === 'process'\n && target.name.text === 'env'\n ) {\n return { matched: true, value: env[node.name.text] }\n }\n }\n if (\n ts.isElementAccessExpression(node)\n && ts.isPropertyAccessExpression(node.expression)\n && ts.isIdentifier(node.expression.expression)\n && node.expression.expression.text === 'process'\n && node.expression.name.text === 'env'\n && ts.isStringLiteralLike(node.argumentExpression)\n ) {\n return { matched: true, value: env[node.argumentExpression.text] }\n }\n return { matched: false, value: undefined }\n}\n\nfunction evaluateStaticExpression(node: ts.Expression, env: NodeJS.ProcessEnv): unknown {\n return evaluateStaticExpressionWithScope(node, env, new Map())\n}\n\nfunction evaluateStaticExpressionWithScope(\n node: ts.Expression,\n env: NodeJS.ProcessEnv,\n scope: Map<string, unknown>,\n): unknown {\n if (ts.isParenthesizedExpression(node)) return evaluateStaticExpressionWithScope(node.expression, env, scope)\n if (ts.isIdentifier(node)) {\n return scope.get(node.text)\n }\n if (ts.isStringLiteralLike(node) || ts.isNoSubstitutionTemplateLiteral(node)) return node.text\n if (ts.isNumericLiteral(node)) return Number(node.text)\n if (node.kind === ts.SyntaxKind.TrueKeyword) return true\n if (node.kind === ts.SyntaxKind.FalseKeyword) return false\n if (node.kind === ts.SyntaxKind.NullKeyword) return null\n\n const envAccess = parseProcessEnvAccess(node, env)\n if (envAccess.matched) return envAccess.value\n\n if (ts.isPropertyAccessExpression(node)) {\n const target = evaluateStaticExpressionWithScope(node.expression, env, scope)\n if (target && typeof target === 'object' && node.name.text in target) {\n return (target as Record<string, unknown>)[node.name.text]\n }\n return undefined\n }\n\n if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {\n return !Boolean(evaluateStaticExpressionWithScope(node.operand, env, scope))\n }\n\n if (ts.isBinaryExpression(node)) {\n if (node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {\n return Boolean(evaluateStaticExpressionWithScope(node.left, env, scope))\n && Boolean(evaluateStaticExpressionWithScope(node.right, env, scope))\n }\n if (node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {\n return Boolean(evaluateStaticExpressionWithScope(node.left, env, scope))\n || Boolean(evaluateStaticExpressionWithScope(node.right, env, scope))\n }\n if (node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken) {\n return evaluateStaticExpressionWithScope(node.left, env, scope) === evaluateStaticExpressionWithScope(node.right, env, scope)\n }\n if (node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken) {\n return evaluateStaticExpressionWithScope(node.left, env, scope) !== evaluateStaticExpressionWithScope(node.right, env, scope)\n }\n }\n\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'parseBooleanWithDefault') {\n const rawValueNode = node.arguments[0]\n const fallbackNode = node.arguments[1]\n const rawValue = rawValueNode ? evaluateStaticExpressionWithScope(rawValueNode, env, scope) : undefined\n const fallbackValue = fallbackNode ? evaluateStaticExpressionWithScope(fallbackNode, env, scope) : false\n return parseBooleanWithDefault(typeof rawValue === 'string' ? rawValue : undefined, Boolean(fallbackValue))\n }\n\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'some') {\n const target = evaluateStaticExpressionWithScope(node.expression.expression, env, scope)\n const predicate = node.arguments[0]\n if (!Array.isArray(target) || !predicate) return undefined\n\n return target.some((entry) => {\n if (!ts.isArrowFunction(predicate) && !ts.isFunctionExpression(predicate)) return false\n\n const localScope = new Map(scope)\n const parameter = predicate.parameters[0]\n if (parameter && ts.isIdentifier(parameter.name)) {\n localScope.set(parameter.name.text, entry)\n }\n\n if (ts.isBlock(predicate.body)) {\n const returnStatement = predicate.body.statements.find((statement): statement is ts.ReturnStatement =>\n ts.isReturnStatement(statement),\n )\n if (!returnStatement?.expression) return false\n return Boolean(evaluateStaticExpressionWithScope(returnStatement.expression, env, localScope))\n }\n\n return Boolean(evaluateStaticExpressionWithScope(predicate.body, env, localScope))\n })\n }\n\n return undefined\n}\n\nfunction evaluateStaticCondition(\n node: ts.Expression,\n env: NodeJS.ProcessEnv,\n scope: Map<string, unknown>,\n): boolean {\n const evaluated = evaluateStaticExpressionWithScope(node, env, scope)\n return Boolean(evaluated)\n}\n\nfunction collectPushEntriesFromStatement(\n statement: ts.Statement,\n env: NodeJS.ProcessEnv,\n targetVariableName: string,\n scope: Map<string, unknown>,\n): ModuleEntry[] {\n if (ts.isBlock(statement)) {\n return statement.statements.flatMap((child) => collectPushEntriesFromStatement(child, env, targetVariableName, scope))\n }\n\n if (ts.isIfStatement(statement)) {\n if (evaluateStaticCondition(statement.expression, env, scope)) {\n return collectPushEntriesFromStatement(statement.thenStatement, env, targetVariableName, scope)\n }\n if (statement.elseStatement) {\n return collectPushEntriesFromStatement(statement.elseStatement, env, targetVariableName, scope)\n }\n return []\n }\n\n if (!ts.isExpressionStatement(statement)) return []\n const expression = statement.expression\n if (!ts.isCallExpression(expression)) return []\n if (!ts.isPropertyAccessExpression(expression.expression)) return []\n const pushTarget = expression.expression.expression\n const pushMethod = expression.expression.name\n if (!ts.isIdentifier(pushTarget) || pushTarget.text !== targetVariableName) return []\n if (pushMethod.text !== 'push') return []\n\n return expression.arguments.flatMap((argument) => {\n if (!ts.isObjectLiteralExpression(argument)) return []\n const entry = parseModuleEntryFromObjectLiteral(argument)\n return entry ? [entry] : []\n })\n}\n\nfunction parseModulesFromSource(source: string, env: NodeJS.ProcessEnv = process.env): ModuleEntry[] {\n const sourceFile = ts.createSourceFile('modules.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)\n const modules: ModuleEntry[] = []\n const variableName = 'enabledModules'\n const scope = new Map<string, unknown>()\n let foundDeclaration = false\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name)) continue\n if (declaration.name.text === variableName) {\n if (!declaration.initializer || !ts.isArrayLiteralExpression(declaration.initializer)) continue\n const fromArray = declaration.initializer.elements.flatMap((element) => {\n if (!ts.isObjectLiteralExpression(element)) return []\n const entry = parseModuleEntryFromObjectLiteral(element)\n return entry ? [entry] : []\n })\n modules.push(...fromArray)\n scope.set(variableName, [...modules])\n foundDeclaration = true\n continue\n }\n if (!declaration.initializer) continue\n scope.set(\n declaration.name.text,\n evaluateStaticExpressionWithScope(declaration.initializer, env, scope),\n )\n }\n continue\n }\n if (!foundDeclaration) continue\n const pushedEntries = collectPushEntriesFromStatement(statement, env, variableName, scope)\n if (pushedEntries.length > 0) {\n modules.push(...pushedEntries)\n scope.set(variableName, [...modules])\n }\n }\n\n return modules\n}\n\nfunction readEnabledModulesFromConfig(cfgPath: string): ModuleEntry[] {\n const source = fs.readFileSync(cfgPath, 'utf8')\n return parseModulesFromSource(source)\n}\n\nfunction loadEnabledModulesFromConfig(appDir: string): ModuleEntry[] {\n const cfgPath = path.resolve(appDir, 'src/modules.ts')\n if (fs.existsSync(cfgPath)) {\n try {\n const loadedModules = readEnabledModulesFromConfig(cfgPath)\n if (loadedModules.length > 0) return loadedModules\n } catch (error) {\n console.warn(\n '[resolver] Failed to read enabled modules from src/modules.ts, falling back to src/modules scan:',\n error,\n )\n }\n }\n // Fallback: scan src/modules/* to keep backward compatibility\n const modulesRoot = path.resolve(appDir, 'src/modules')\n if (!fs.existsSync(modulesRoot)) return []\n const scannedModules = fs\n .readdirSync(modulesRoot, { withFileTypes: true })\n .filter((e) => e.isDirectory() && !e.name.startsWith('.'))\n .map((e) => ({ id: e.name, from: '@app' as const }))\n\n return scannedModules\n}\n\nfunction discoverPackagesInMonorepo(rootDir: string): PackageInfo[] {\n const packagesDir = path.join(rootDir, 'packages')\n if (!fs.existsSync(packagesDir)) return []\n\n const packages: PackageInfo[] = []\n const entries = fs.readdirSync(packagesDir, { withFileTypes: true })\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue\n const pkgPath = path.join(packagesDir, entry.name)\n const pkgJsonPath = path.join(pkgPath, 'package.json')\n\n if (!fs.existsSync(pkgJsonPath)) continue\n\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))\n // Read from src/modules (TypeScript source)\n const modulesPath = path.join(pkgPath, 'src', 'modules')\n\n if (fs.existsSync(modulesPath)) {\n packages.push({\n name: pkgJson.name || `@open-mercato/${entry.name}`,\n path: pkgPath,\n modulesPath,\n })\n }\n } catch {\n // Skip invalid packages\n }\n }\n\n return packages\n}\n\nfunction discoverPackagesInNodeModules(rootDir: string): PackageInfo[] {\n const nodeModulesPath = path.join(rootDir, 'node_modules', '@open-mercato')\n if (!fs.existsSync(nodeModulesPath)) return []\n\n const packages: PackageInfo[] = []\n const entries = fs.readdirSync(nodeModulesPath, { withFileTypes: true })\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue\n const pkgPath = path.join(nodeModulesPath, entry.name)\n const pkgJsonPath = path.join(pkgPath, 'package.json')\n\n if (!fs.existsSync(pkgJsonPath)) continue\n\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))\n const distModulesPath = path.join(pkgPath, 'dist', 'modules')\n const srcModulesPath = path.join(pkgPath, 'src', 'modules')\n const modulesPath = fs.existsSync(distModulesPath) ? distModulesPath : srcModulesPath\n\n if (fs.existsSync(modulesPath)) {\n packages.push({\n name: pkgJson.name || `@open-mercato/${entry.name}`,\n path: pkgPath,\n modulesPath,\n })\n }\n } catch {\n // Skip invalid packages\n }\n }\n\n return packages\n}\n\nfunction detectAppDir(rootDir: string, isMonorepo: boolean): string {\n if (!isMonorepo) {\n // Production mode: app is at root\n return rootDir\n }\n\n // Monorepo mode: look for app in apps/mercato/ or apps/app/\n const mercatoApp = path.join(rootDir, 'apps', 'mercato')\n if (fs.existsSync(mercatoApp)) {\n return mercatoApp\n }\n\n const defaultApp = path.join(rootDir, 'apps', 'app')\n if (fs.existsSync(defaultApp)) {\n return defaultApp\n }\n\n // Fallback: check if apps directory exists and has any app\n const appsDir = path.join(rootDir, 'apps')\n if (fs.existsSync(appsDir)) {\n const entries = fs.readdirSync(appsDir, { withFileTypes: true })\n const appEntry = entries.find(\n (e) => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'docs'\n )\n if (appEntry) {\n return path.join(appsDir, appEntry.name)\n }\n }\n\n // Final fallback for legacy structure: root is the app\n return rootDir\n}\n\nfunction findNodeModulesRoot(startDir: string): string | null {\n // Walk up to find node_modules/@open-mercato/core\n let dir = startDir\n while (dir !== path.dirname(dir)) {\n const corePkgPath = path.join(dir, 'node_modules', '@open-mercato', 'core')\n if (fs.existsSync(corePkgPath)) {\n return dir\n }\n dir = path.dirname(dir)\n }\n return null\n}\n\nfunction detectMonorepoFromNodeModules(appDir: string): { isMonorepo: boolean; monorepoRoot: string | null; nodeModulesRoot: string | null } {\n // Find where node_modules/@open-mercato/core is located (may be hoisted)\n const nodeModulesRoot = findNodeModulesRoot(appDir)\n if (!nodeModulesRoot) {\n return { isMonorepo: false, monorepoRoot: null, nodeModulesRoot: null }\n }\n\n const corePkgPath = path.join(nodeModulesRoot, 'node_modules', '@open-mercato', 'core')\n\n try {\n const stat = fs.lstatSync(corePkgPath)\n if (stat.isSymbolicLink()) {\n // It's a symlink - we're in monorepo dev mode\n // Resolve the symlink to find the monorepo root\n const realPath = fs.realpathSync(corePkgPath)\n // realPath is something like /path/to/monorepo/packages/core\n // monorepo root is 2 levels up\n const monorepoRoot = path.dirname(path.dirname(realPath))\n return { isMonorepo: true, monorepoRoot, nodeModulesRoot }\n }\n // It's a real directory - production mode\n return { isMonorepo: false, monorepoRoot: null, nodeModulesRoot }\n } catch {\n // Package doesn't exist yet or error reading - assume production mode\n return { isMonorepo: false, monorepoRoot: null, nodeModulesRoot }\n }\n}\n\nexport function createResolver(cwd: string = process.cwd()): PackageResolver {\n // First detect if we're in a monorepo by checking if node_modules packages are symlinks\n const { isMonorepo: _isMonorepo, monorepoRoot, nodeModulesRoot } = detectMonorepoFromNodeModules(cwd)\n // In workspaces with hoisted real directories, package sources live under the discovered node_modules root.\n const rootDir = monorepoRoot ?? nodeModulesRoot ?? cwd\n\n // shouldResolveAppFromRoot: true when we have a workspace/install root that differs from cwd\n // (monorepo symlinks detected, or node_modules root found above cwd)\n const shouldResolveAppFromRoot =\n _isMonorepo || (nodeModulesRoot !== null && path.resolve(nodeModulesRoot) !== path.resolve(cwd))\n\n // The app directory depends on context:\n // - In monorepo: use detectAppDir to find apps/mercato or similar\n // - When symlinks not detected (e.g. Docker volume node_modules): still use apps/mercato if present at rootDir\n // - Otherwise: app is at cwd\n const candidateAppDir = shouldResolveAppFromRoot ? detectAppDir(rootDir, true) : rootDir\n const appDir =\n _isMonorepo\n ? candidateAppDir\n : shouldResolveAppFromRoot && candidateAppDir !== rootDir && fs.existsSync(candidateAppDir)\n ? candidateAppDir\n : cwd\n\n return {\n isMonorepo: () => _isMonorepo,\n\n getRootDir: () => rootDir,\n\n getAppDir: () => appDir,\n\n getOutputDir: () => {\n // Output is ALWAYS .mercato/generated relative to app directory\n return path.join(appDir, '.mercato', 'generated')\n },\n\n getModulesConfigPath: () => path.join(appDir, 'src', 'modules.ts'),\n\n discoverPackages: () => {\n return _isMonorepo\n ? discoverPackagesInMonorepo(rootDir)\n : discoverPackagesInNodeModules(rootDir)\n },\n\n loadEnabledModules: () => loadEnabledModulesFromConfig(appDir),\n\n getModulePaths: (entry: ModuleEntry) => {\n const appBase = path.resolve(appDir, 'src/modules', entry.id)\n const pkgModulesRoot = pkgDirFor(rootDir, entry.from, _isMonorepo)\n const pkgBase = path.join(pkgModulesRoot, entry.id)\n return { appBase, pkgBase }\n },\n\n getModuleImportBase: (entry: ModuleEntry) => {\n // Prefer @app overrides at import-time; fall back to provided package alias\n const from = entry.from || '@open-mercato/core'\n return {\n appBase: `@/modules/${entry.id}`,\n pkgBase: `${from}/modules/${entry.id}`,\n }\n },\n\n getPackageOutputDir: (packageName: string) => {\n if (packageName === '@app') {\n // App output goes to .mercato/generated\n return path.join(appDir, '.mercato', 'generated')\n }\n const pkgRoot = pkgRootFor(rootDir, packageName, _isMonorepo)\n return path.join(pkgRoot, 'generated')\n },\n\n getPackageRoot: (from?: string) => {\n return pkgRootFor(rootDir, from, _isMonorepo)\n },\n }\n}\n\n/**\n * Resolve the CLI execution environment as a plain value-object.\n * Call once at subsystem init; use the returned object for all path decisions.\n */\nexport function resolveEnvironment(cwd: string = process.cwd()): CliEnvironment {\n const resolver = createResolver(cwd)\n const _isMonorepo = resolver.isMonorepo()\n const rootDir = resolver.getRootDir()\n const appDir = resolver.getAppDir()\n return {\n mode: _isMonorepo ? 'monorepo' : 'standalone',\n rootDir,\n appDir,\n packageRoot: (packageName: string) => pkgRootFor(rootDir, packageName, _isMonorepo),\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,SAAS,+BAA+B;AA8CxC,SAAS,UAAU,SAAiB,MAAe,aAAa,MAAc;AAC5E,MAAI,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AAM,EAAE;AAAA,QAC9B,SAAS,GAAG,IAAI,YAAY,MAAM,EAAE;AAAA,MACtC;AAAA,IACF;AAAA,IAEA,qBAAqB,CAAC,gBAAwB;AAC5C,UAAI,gBAAgB,QAAQ;AAE1B,eAAO,KAAK,KAAK,QAAQ,YAAY,WAAW;AAAA,MAClD;AACA,YAAM,UAAU,WAAW,SAAS,aAAa,WAAW;AAC5D,aAAO,KAAK,KAAK,SAAS,WAAW;AAAA,IACvC;AAAA,IAEA,gBAAgB,CAAC,SAAkB;AACjC,aAAO,WAAW,SAAS,MAAM,WAAW;AAAA,IAC9C;AAAA,EACF;AACF;AAMO,SAAS,mBAAmB,MAAc,QAAQ,IAAI,GAAmB;AAC9E,QAAM,WAAW,eAAe,GAAG;AACnC,QAAM,cAAc,SAAS,WAAW;AACxC,QAAM,UAAU,SAAS,WAAW;AACpC,QAAM,SAAS,SAAS,UAAU;AAClC,SAAO;AAAA,IACL,MAAM,cAAc,aAAa;AAAA,IACjC;AAAA,IACA;AAAA,IACA,aAAa,CAAC,gBAAwB,WAAW,SAAS,aAAa,WAAW;AAAA,EACpF;AACF;",
|
|
4
|
+
"sourcesContent": ["import path from 'node:path'\nimport fs from 'node:fs'\nimport ts from 'typescript-js'\nimport { parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'\n\n/**\n * Resolved execution environment for the CLI.\n * Produced once by resolveEnvironment() and consumed by all subsystems.\n * Eliminates per-subsystem isMonorepo() branching and hardcoded path segments.\n */\nexport type CliEnvironment = {\n /** Whether the CLI is running inside a Yarn/npm workspace monorepo. */\n mode: 'monorepo' | 'standalone'\n /** Workspace or project root (where package.json / node_modules live). */\n rootDir: string\n /** Next.js application directory (contains src/, package.json, next.config.*). */\n appDir: string\n /**\n * Resolve the root directory of an installed @open-mercato package.\n * Monorepo: packages/<pkg>/ Standalone: node_modules/<pkg>/\n */\n packageRoot: (packageName: string) => string\n}\n\nexport type ModuleEntry = {\n id: string\n from?: '@open-mercato/core' | '@app' | string\n devSupervisorRequiresFullBootstrap?: boolean\n}\n\nexport type PackageInfo = {\n name: string\n version?: string | null\n path: string\n modulesPath: string\n}\n\nexport interface PackageResolver {\n isMonorepo(): boolean\n getRootDir(): string\n getAppDir(): string\n getOutputDir(): string\n getModulesConfigPath(): string\n discoverPackages(): PackageInfo[]\n loadEnabledModules(): ModuleEntry[]\n getModulePaths(entry: ModuleEntry): { appBase: string; pkgBase: string }\n getModuleImportBase(entry: ModuleEntry): { appBase: string; pkgBase: string }\n getPackageOutputDir(packageName: string): string\n getPackageRoot(from?: string): string\n}\n\nfunction pkgDirFor(rootDir: string, from?: string, isMonorepo = true): string {\n if (!isMonorepo) {\n const pkgName = from || '@open-mercato/core'\n const pkgRoot = path.join(rootDir, 'node_modules', pkgName)\n const distModules = path.join(pkgRoot, 'dist', 'modules')\n if (fs.existsSync(distModules)) return distModules\n return path.join(pkgRoot, 'src', 'modules')\n }\n\n // Monorepo mode - read from src/modules (TypeScript source)\n if (!from || from === '@open-mercato/core') {\n return path.resolve(rootDir, 'packages/core/src/modules')\n }\n // Support other local packages like '@open-mercato/onboarding' => packages/onboarding/src/modules\n const m = from.match(/^@open-mercato\\/(.+)$/)\n if (m) {\n return path.resolve(rootDir, `packages/${m[1]}/src/modules`)\n }\n // Fallback to core modules path\n return path.resolve(rootDir, 'packages/core/src/modules')\n}\n\nfunction pkgRootFor(rootDir: string, from?: string, isMonorepo = true): string {\n if (!isMonorepo) {\n const pkgName = from || '@open-mercato/core'\n return path.join(rootDir, 'node_modules', pkgName)\n }\n\n if (!from || from === '@open-mercato/core') {\n return path.resolve(rootDir, 'packages/core')\n }\n const m = from.match(/^@open-mercato\\/(.+)$/)\n if (m) {\n return path.resolve(rootDir, `packages/${m[1]}`)\n }\n return path.resolve(rootDir, 'packages/core')\n}\n\nfunction parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): ModuleEntry | null {\n let id: string | null = null\n let from: string | null = null\n let devSupervisorRequiresFullBootstrap = false\n for (const property of node.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n const key = ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)\n ? property.name.text\n : null\n if (key === 'id' && ts.isStringLiteralLike(property.initializer)) {\n id = property.initializer.text\n }\n if (key === 'from' && ts.isStringLiteralLike(property.initializer)) {\n from = property.initializer.text\n }\n if (key === 'overrides') {\n if (!ts.isObjectLiteralExpression(property.initializer)) {\n devSupervisorRequiresFullBootstrap = true\n continue\n }\n for (const overrideProperty of property.initializer.properties) {\n if (ts.isSpreadAssignment(overrideProperty)) {\n devSupervisorRequiresFullBootstrap = true\n break\n }\n if (!ts.isPropertyAssignment(overrideProperty)) continue\n const overrideKey = ts.isIdentifier(overrideProperty.name) || ts.isStringLiteralLike(overrideProperty.name)\n ? overrideProperty.name.text\n : null\n if (overrideKey === 'workers' || overrideKey === 'cli') {\n devSupervisorRequiresFullBootstrap = true\n break\n }\n }\n }\n }\n if (!id) return null\n return {\n id,\n from: from ?? '@open-mercato/core',\n ...(devSupervisorRequiresFullBootstrap ? { devSupervisorRequiresFullBootstrap: true } : {}),\n }\n}\n\nfunction parseProcessEnvAccess(\n node: ts.Expression,\n env: NodeJS.ProcessEnv,\n): { matched: boolean; value: string | undefined } {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {\n const target = node.expression\n if (\n ts.isPropertyAccessExpression(target)\n && ts.isIdentifier(target.expression)\n && target.expression.text === 'process'\n && target.name.text === 'env'\n ) {\n return { matched: true, value: env[node.name.text] }\n }\n }\n if (\n ts.isElementAccessExpression(node)\n && ts.isPropertyAccessExpression(node.expression)\n && ts.isIdentifier(node.expression.expression)\n && node.expression.expression.text === 'process'\n && node.expression.name.text === 'env'\n && ts.isStringLiteralLike(node.argumentExpression)\n ) {\n return { matched: true, value: env[node.argumentExpression.text] }\n }\n return { matched: false, value: undefined }\n}\n\nfunction evaluateStaticExpression(node: ts.Expression, env: NodeJS.ProcessEnv): unknown {\n return evaluateStaticExpressionWithScope(node, env, new Map())\n}\n\nfunction evaluateStaticExpressionWithScope(\n node: ts.Expression,\n env: NodeJS.ProcessEnv,\n scope: Map<string, unknown>,\n): unknown {\n if (ts.isParenthesizedExpression(node)) return evaluateStaticExpressionWithScope(node.expression, env, scope)\n if (ts.isIdentifier(node)) {\n return scope.get(node.text)\n }\n if (ts.isStringLiteralLike(node) || ts.isNoSubstitutionTemplateLiteral(node)) return node.text\n if (ts.isNumericLiteral(node)) return Number(node.text)\n if (node.kind === ts.SyntaxKind.TrueKeyword) return true\n if (node.kind === ts.SyntaxKind.FalseKeyword) return false\n if (node.kind === ts.SyntaxKind.NullKeyword) return null\n\n const envAccess = parseProcessEnvAccess(node, env)\n if (envAccess.matched) return envAccess.value\n\n if (ts.isPropertyAccessExpression(node)) {\n const target = evaluateStaticExpressionWithScope(node.expression, env, scope)\n if (target && typeof target === 'object' && node.name.text in target) {\n return (target as Record<string, unknown>)[node.name.text]\n }\n return undefined\n }\n\n if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken) {\n return !Boolean(evaluateStaticExpressionWithScope(node.operand, env, scope))\n }\n\n if (ts.isBinaryExpression(node)) {\n if (node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {\n return Boolean(evaluateStaticExpressionWithScope(node.left, env, scope))\n && Boolean(evaluateStaticExpressionWithScope(node.right, env, scope))\n }\n if (node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {\n return Boolean(evaluateStaticExpressionWithScope(node.left, env, scope))\n || Boolean(evaluateStaticExpressionWithScope(node.right, env, scope))\n }\n if (node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken) {\n return evaluateStaticExpressionWithScope(node.left, env, scope) === evaluateStaticExpressionWithScope(node.right, env, scope)\n }\n if (node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken) {\n return evaluateStaticExpressionWithScope(node.left, env, scope) !== evaluateStaticExpressionWithScope(node.right, env, scope)\n }\n }\n\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'parseBooleanWithDefault') {\n const rawValueNode = node.arguments[0]\n const fallbackNode = node.arguments[1]\n const rawValue = rawValueNode ? evaluateStaticExpressionWithScope(rawValueNode, env, scope) : undefined\n const fallbackValue = fallbackNode ? evaluateStaticExpressionWithScope(fallbackNode, env, scope) : false\n return parseBooleanWithDefault(typeof rawValue === 'string' ? rawValue : undefined, Boolean(fallbackValue))\n }\n\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'some') {\n const target = evaluateStaticExpressionWithScope(node.expression.expression, env, scope)\n const predicate = node.arguments[0]\n if (!Array.isArray(target) || !predicate) return undefined\n\n return target.some((entry) => {\n if (!ts.isArrowFunction(predicate) && !ts.isFunctionExpression(predicate)) return false\n\n const localScope = new Map(scope)\n const parameter = predicate.parameters[0]\n if (parameter && ts.isIdentifier(parameter.name)) {\n localScope.set(parameter.name.text, entry)\n }\n\n if (ts.isBlock(predicate.body)) {\n const returnStatement = predicate.body.statements.find((statement): statement is ts.ReturnStatement =>\n ts.isReturnStatement(statement),\n )\n if (!returnStatement?.expression) return false\n return Boolean(evaluateStaticExpressionWithScope(returnStatement.expression, env, localScope))\n }\n\n return Boolean(evaluateStaticExpressionWithScope(predicate.body, env, localScope))\n })\n }\n\n return undefined\n}\n\nfunction evaluateStaticCondition(\n node: ts.Expression,\n env: NodeJS.ProcessEnv,\n scope: Map<string, unknown>,\n): boolean {\n const evaluated = evaluateStaticExpressionWithScope(node, env, scope)\n return Boolean(evaluated)\n}\n\nfunction collectPushEntriesFromStatement(\n statement: ts.Statement,\n env: NodeJS.ProcessEnv,\n targetVariableName: string,\n scope: Map<string, unknown>,\n): ModuleEntry[] {\n if (ts.isBlock(statement)) {\n return statement.statements.flatMap((child) => collectPushEntriesFromStatement(child, env, targetVariableName, scope))\n }\n\n if (ts.isIfStatement(statement)) {\n if (evaluateStaticCondition(statement.expression, env, scope)) {\n return collectPushEntriesFromStatement(statement.thenStatement, env, targetVariableName, scope)\n }\n if (statement.elseStatement) {\n return collectPushEntriesFromStatement(statement.elseStatement, env, targetVariableName, scope)\n }\n return []\n }\n\n if (!ts.isExpressionStatement(statement)) return []\n const expression = statement.expression\n if (!ts.isCallExpression(expression)) return []\n if (!ts.isPropertyAccessExpression(expression.expression)) return []\n const pushTarget = expression.expression.expression\n const pushMethod = expression.expression.name\n if (!ts.isIdentifier(pushTarget) || pushTarget.text !== targetVariableName) return []\n if (pushMethod.text !== 'push') return []\n\n return expression.arguments.flatMap((argument) => {\n if (!ts.isObjectLiteralExpression(argument)) return []\n const entry = parseModuleEntryFromObjectLiteral(argument)\n return entry ? [entry] : []\n })\n}\n\nfunction parseModulesFromSource(source: string, env: NodeJS.ProcessEnv = process.env): ModuleEntry[] {\n const sourceFile = ts.createSourceFile('modules.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)\n const modules: ModuleEntry[] = []\n const variableName = 'enabledModules'\n const scope = new Map<string, unknown>()\n let foundDeclaration = false\n\n for (const statement of sourceFile.statements) {\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name)) continue\n if (declaration.name.text === variableName) {\n if (!declaration.initializer || !ts.isArrayLiteralExpression(declaration.initializer)) continue\n const fromArray = declaration.initializer.elements.flatMap((element) => {\n if (!ts.isObjectLiteralExpression(element)) return []\n const entry = parseModuleEntryFromObjectLiteral(element)\n return entry ? [entry] : []\n })\n modules.push(...fromArray)\n scope.set(variableName, [...modules])\n foundDeclaration = true\n continue\n }\n if (!declaration.initializer) continue\n scope.set(\n declaration.name.text,\n evaluateStaticExpressionWithScope(declaration.initializer, env, scope),\n )\n }\n continue\n }\n if (!foundDeclaration) continue\n const pushedEntries = collectPushEntriesFromStatement(statement, env, variableName, scope)\n if (pushedEntries.length > 0) {\n modules.push(...pushedEntries)\n scope.set(variableName, [...modules])\n }\n }\n\n return modules\n}\n\nfunction readEnabledModulesFromConfig(cfgPath: string): ModuleEntry[] {\n const source = fs.readFileSync(cfgPath, 'utf8')\n return parseModulesFromSource(source)\n}\n\nfunction loadEnabledModulesFromConfig(appDir: string): ModuleEntry[] {\n const cfgPath = path.resolve(appDir, 'src/modules.ts')\n if (fs.existsSync(cfgPath)) {\n try {\n const loadedModules = readEnabledModulesFromConfig(cfgPath)\n if (loadedModules.length > 0) return loadedModules\n } catch (error) {\n console.warn(\n '[resolver] Failed to read enabled modules from src/modules.ts, falling back to src/modules scan:',\n error,\n )\n }\n }\n // Fallback: scan src/modules/* to keep backward compatibility\n const modulesRoot = path.resolve(appDir, 'src/modules')\n if (!fs.existsSync(modulesRoot)) return []\n const scannedModules = fs\n .readdirSync(modulesRoot, { withFileTypes: true })\n .filter((e) => e.isDirectory() && !e.name.startsWith('.'))\n .map((e) => ({ id: e.name, from: '@app' as const }))\n\n return scannedModules\n}\n\nfunction discoverPackagesInMonorepo(rootDir: string): PackageInfo[] {\n const packagesDir = path.join(rootDir, 'packages')\n if (!fs.existsSync(packagesDir)) return []\n\n const packages: PackageInfo[] = []\n const entries = fs.readdirSync(packagesDir, { withFileTypes: true })\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue\n const pkgPath = path.join(packagesDir, entry.name)\n const pkgJsonPath = path.join(pkgPath, 'package.json')\n\n if (!fs.existsSync(pkgJsonPath)) continue\n\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))\n // Read from src/modules (TypeScript source)\n const modulesPath = path.join(pkgPath, 'src', 'modules')\n\n if (fs.existsSync(modulesPath)) {\n packages.push({\n name: pkgJson.name || `@open-mercato/${entry.name}`,\n version: typeof pkgJson.version === 'string' ? pkgJson.version : null,\n path: pkgPath,\n modulesPath,\n })\n }\n } catch {\n // Skip invalid packages\n }\n }\n\n return packages\n}\n\nfunction discoverPackagesInNodeModules(rootDir: string): PackageInfo[] {\n const nodeModulesPath = path.join(rootDir, 'node_modules', '@open-mercato')\n if (!fs.existsSync(nodeModulesPath)) return []\n\n const packages: PackageInfo[] = []\n const entries = fs.readdirSync(nodeModulesPath, { withFileTypes: true })\n\n for (const entry of entries) {\n if (!entry.isDirectory()) continue\n const pkgPath = path.join(nodeModulesPath, entry.name)\n const pkgJsonPath = path.join(pkgPath, 'package.json')\n\n if (!fs.existsSync(pkgJsonPath)) continue\n\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))\n const distModulesPath = path.join(pkgPath, 'dist', 'modules')\n const srcModulesPath = path.join(pkgPath, 'src', 'modules')\n const modulesPath = fs.existsSync(distModulesPath) ? distModulesPath : srcModulesPath\n\n if (fs.existsSync(modulesPath)) {\n packages.push({\n name: pkgJson.name || `@open-mercato/${entry.name}`,\n version: typeof pkgJson.version === 'string' ? pkgJson.version : null,\n path: pkgPath,\n modulesPath,\n })\n }\n } catch {\n // Skip invalid packages\n }\n }\n\n return packages\n}\n\nfunction detectAppDir(rootDir: string, isMonorepo: boolean): string {\n if (!isMonorepo) {\n // Production mode: app is at root\n return rootDir\n }\n\n // Monorepo mode: look for app in apps/mercato/ or apps/app/\n const mercatoApp = path.join(rootDir, 'apps', 'mercato')\n if (fs.existsSync(mercatoApp)) {\n return mercatoApp\n }\n\n const defaultApp = path.join(rootDir, 'apps', 'app')\n if (fs.existsSync(defaultApp)) {\n return defaultApp\n }\n\n // Fallback: check if apps directory exists and has any app\n const appsDir = path.join(rootDir, 'apps')\n if (fs.existsSync(appsDir)) {\n const entries = fs.readdirSync(appsDir, { withFileTypes: true })\n const appEntry = entries.find(\n (e) => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'docs'\n )\n if (appEntry) {\n return path.join(appsDir, appEntry.name)\n }\n }\n\n // Final fallback for legacy structure: root is the app\n return rootDir\n}\n\nfunction findNodeModulesRoot(startDir: string): string | null {\n // Walk up to find node_modules/@open-mercato/core\n let dir = startDir\n while (dir !== path.dirname(dir)) {\n const corePkgPath = path.join(dir, 'node_modules', '@open-mercato', 'core')\n if (fs.existsSync(corePkgPath)) {\n return dir\n }\n dir = path.dirname(dir)\n }\n return null\n}\n\nfunction detectMonorepoFromNodeModules(appDir: string): { isMonorepo: boolean; monorepoRoot: string | null; nodeModulesRoot: string | null } {\n // Find where node_modules/@open-mercato/core is located (may be hoisted)\n const nodeModulesRoot = findNodeModulesRoot(appDir)\n if (!nodeModulesRoot) {\n return { isMonorepo: false, monorepoRoot: null, nodeModulesRoot: null }\n }\n\n const corePkgPath = path.join(nodeModulesRoot, 'node_modules', '@open-mercato', 'core')\n\n try {\n const stat = fs.lstatSync(corePkgPath)\n if (stat.isSymbolicLink()) {\n // It's a symlink - we're in monorepo dev mode\n // Resolve the symlink to find the monorepo root\n const realPath = fs.realpathSync(corePkgPath)\n // realPath is something like /path/to/monorepo/packages/core\n // monorepo root is 2 levels up\n const monorepoRoot = path.dirname(path.dirname(realPath))\n return { isMonorepo: true, monorepoRoot, nodeModulesRoot }\n }\n // It's a real directory - production mode\n return { isMonorepo: false, monorepoRoot: null, nodeModulesRoot }\n } catch {\n // Package doesn't exist yet or error reading - assume production mode\n return { isMonorepo: false, monorepoRoot: null, nodeModulesRoot }\n }\n}\n\nexport function createResolver(cwd: string = process.cwd()): PackageResolver {\n // First detect if we're in a monorepo by checking if node_modules packages are symlinks\n const { isMonorepo: _isMonorepo, monorepoRoot, nodeModulesRoot } = detectMonorepoFromNodeModules(cwd)\n // In workspaces with hoisted real directories, package sources live under the discovered node_modules root.\n const rootDir = monorepoRoot ?? nodeModulesRoot ?? cwd\n\n // shouldResolveAppFromRoot: true when we have a workspace/install root that differs from cwd\n // (monorepo symlinks detected, or node_modules root found above cwd)\n const shouldResolveAppFromRoot =\n _isMonorepo || (nodeModulesRoot !== null && path.resolve(nodeModulesRoot) !== path.resolve(cwd))\n\n // The app directory depends on context:\n // - In monorepo: use detectAppDir to find apps/mercato or similar\n // - When symlinks not detected (e.g. Docker volume node_modules): still use apps/mercato if present at rootDir\n // - Otherwise: app is at cwd\n const candidateAppDir = shouldResolveAppFromRoot ? detectAppDir(rootDir, true) : rootDir\n const appDir =\n _isMonorepo\n ? candidateAppDir\n : shouldResolveAppFromRoot && candidateAppDir !== rootDir && fs.existsSync(candidateAppDir)\n ? candidateAppDir\n : cwd\n\n return {\n isMonorepo: () => _isMonorepo,\n\n getRootDir: () => rootDir,\n\n getAppDir: () => appDir,\n\n getOutputDir: () => {\n // Output is ALWAYS .mercato/generated relative to app directory\n return path.join(appDir, '.mercato', 'generated')\n },\n\n getModulesConfigPath: () => path.join(appDir, 'src', 'modules.ts'),\n\n discoverPackages: () => {\n return _isMonorepo\n ? discoverPackagesInMonorepo(rootDir)\n : discoverPackagesInNodeModules(rootDir)\n },\n\n loadEnabledModules: () => loadEnabledModulesFromConfig(appDir),\n\n getModulePaths: (entry: ModuleEntry) => {\n const appBase = path.resolve(appDir, 'src/modules', entry.id)\n const pkgModulesRoot = pkgDirFor(rootDir, entry.from, _isMonorepo)\n const pkgBase = path.join(pkgModulesRoot, entry.id)\n return { appBase, pkgBase }\n },\n\n getModuleImportBase: (entry: ModuleEntry) => {\n // Prefer @app overrides at import-time; fall back to provided package alias\n const from = entry.from || '@open-mercato/core'\n return {\n appBase: `@/modules/${entry.id}`,\n pkgBase: `${from}/modules/${entry.id}`,\n }\n },\n\n getPackageOutputDir: (packageName: string) => {\n if (packageName === '@app') {\n // App output goes to .mercato/generated\n return path.join(appDir, '.mercato', 'generated')\n }\n const pkgRoot = pkgRootFor(rootDir, packageName, _isMonorepo)\n return path.join(pkgRoot, 'generated')\n },\n\n getPackageRoot: (from?: string) => {\n return pkgRootFor(rootDir, from, _isMonorepo)\n },\n }\n}\n\n/**\n * Resolve the CLI execution environment as a plain value-object.\n * Call once at subsystem init; use the returned object for all path decisions.\n */\nexport function resolveEnvironment(cwd: string = process.cwd()): CliEnvironment {\n const resolver = createResolver(cwd)\n const _isMonorepo = resolver.isMonorepo()\n const rootDir = resolver.getRootDir()\n const appDir = resolver.getAppDir()\n return {\n mode: _isMonorepo ? 'monorepo' : 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AA,IAEA,gBAAgB,CAAC,SAAkB;AACjC,aAAO,WAAW,SAAS,MAAM,WAAW;AAAA,IAC9C;AAAA,EACF;AACF;AAMO,SAAS,mBAAmB,MAAc,QAAQ,IAAI,GAAmB;AAC9E,QAAM,WAAW,eAAe,GAAG;AACnC,QAAM,cAAc,SAAS,WAAW;AACxC,QAAM,UAAU,SAAS,WAAW;AACpC,QAAM,SAAS,SAAS,UAAU;AAClC,SAAO;AAAA,IACL,MAAM,cAAc,aAAa;AAAA,IACjC;AAAA,IACA;AAAA,IACA,aAAa,CAAC,gBAAwB,WAAW,SAAS,aAAa,WAAW;AAAA,EACpF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
const BULLMQ_OTEL_VERSION = "^1.3.1";
|
|
4
|
+
const ENV_BLOCK = `
|
|
5
|
+
# --- Telemetry & Observability (vendor-neutral OTLP: traces, logs, metrics, errors) ---
|
|
6
|
+
# Off by default: leave TELEMETRY_BACKEND unset (or =noop) for a hard no-op
|
|
7
|
+
# (the OpenTelemetry SDK is never loaded). Set to 'console' for local span/metric
|
|
8
|
+
# output, or an OTLP backend to export: 'signoz' | 'newrelic' | 'otlp' (generic).
|
|
9
|
+
# All three OTLP names use the same exporter \u2014 they differ only by the endpoint +
|
|
10
|
+
# headers below. Any OTLP backend is a one-line swap; no code change.
|
|
11
|
+
# TELEMETRY_BACKEND=otlp
|
|
12
|
+
# Logs use the shared logger facade and its OM_LOG_LEVEL / OM_LOG_PRETTY /
|
|
13
|
+
# OM_LOG_DESTINATION controls. Telemetry adds remote export; it does not create
|
|
14
|
+
# a second local output path.
|
|
15
|
+
# TELEMETRY_SAMPLING_RATIO=1.0 # 0.0\u20131.0 (default 1.0 dev / 0.1 prod)
|
|
16
|
+
# TELEMETRY_TRUST_INBOUND_TRACE=false # default false: root-per-request (ignore an
|
|
17
|
+
# # inbound traceparent from a proxy/LB). Set true
|
|
18
|
+
# # only behind a trusted upstream whose trace continues.
|
|
19
|
+
# # This also enables richer bullmq-otel spans;
|
|
20
|
+
# # otherwise async queues use metadata._trace.
|
|
21
|
+
#
|
|
22
|
+
# OTLP endpoint + auth \u2014 pick ONE vendor (use your region's host):
|
|
23
|
+
# SigNoz Cloud:
|
|
24
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.signoz.cloud:443
|
|
25
|
+
# OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-ingestion-key>
|
|
26
|
+
# New Relic (OTLP-native; EU host shown, US is https://otlp.nr-data.net):
|
|
27
|
+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.eu01.nr-data.net
|
|
28
|
+
# OTEL_EXPORTER_OTLP_HEADERS=api-key=<your-ingest-license-key>
|
|
29
|
+
#
|
|
30
|
+
# Resource identity: keep one stable service name across environments and
|
|
31
|
+
# separate envs via the deployment.environment resource attribute.
|
|
32
|
+
# OTEL_SERVICE_NAME=open-mercato
|
|
33
|
+
# OTEL_RESOURCE_ATTRIBUTES=deployment.environment=local
|
|
34
|
+
`;
|
|
35
|
+
const INSTRUMENTATION_TS = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
36
|
+
|
|
37
|
+
export async function register(): Promise<void> {
|
|
38
|
+
// Initialize telemetry (no-op unless TELEMETRY_BACKEND is set). OTEL's NodeSDK
|
|
39
|
+
// is Node-only and incompatible with the edge runtime, so the telemetry
|
|
40
|
+
// bootstrap \u2014 which can pull in the SDK \u2014 is imported only on the Node.js
|
|
41
|
+
// runtime. The helper owns init + graceful degrade + shutdown flush.
|
|
42
|
+
if (
|
|
43
|
+
process.env.NEXT_RUNTIME === 'nodejs'
|
|
44
|
+
&& isTelemetryBackendEnabled()
|
|
45
|
+
) {
|
|
46
|
+
const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')
|
|
47
|
+
await registerTelemetryForNextjs()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
const DISPATCHER_SNIPPET = ` // add near the other imports:
|
|
52
|
+
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
53
|
+
|
|
54
|
+
// in the dispatcher's success path, just before returning the response:
|
|
55
|
+
getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)
|
|
56
|
+
|
|
57
|
+
// in the dispatcher's catch (error) block, before re-throwing:
|
|
58
|
+
getTelemetryRuntime()?.reportError(error, {
|
|
59
|
+
attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },
|
|
60
|
+
})
|
|
61
|
+
getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`;
|
|
62
|
+
function parseArgs(args) {
|
|
63
|
+
return {
|
|
64
|
+
dryRun: args.includes("--dry-run") || args.includes("-n")
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function resolveOpenMercatoVersion(pkg) {
|
|
68
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
69
|
+
const deps = pkg[field];
|
|
70
|
+
if (deps && typeof deps === "object") {
|
|
71
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
72
|
+
if (name.startsWith("@open-mercato/") && typeof version === "string") return version;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return "*";
|
|
77
|
+
}
|
|
78
|
+
function patchPackageJson(appDir, options) {
|
|
79
|
+
const file = "package.json";
|
|
80
|
+
const path = join(appDir, file);
|
|
81
|
+
const raw = readFileSync(path, "utf8");
|
|
82
|
+
const pkg = JSON.parse(raw);
|
|
83
|
+
const version = resolveOpenMercatoVersion(pkg);
|
|
84
|
+
const hasTelemetry = Boolean(pkg.dependencies?.["@open-mercato/telemetry"]);
|
|
85
|
+
const hasBullmqOtel = Boolean(pkg.optionalDependencies?.["bullmq-otel"]);
|
|
86
|
+
if (hasTelemetry && hasBullmqOtel) {
|
|
87
|
+
return { file, status: "skipped", detail: "@open-mercato/telemetry already installed" };
|
|
88
|
+
}
|
|
89
|
+
const deps = { ...pkg.dependencies ?? {} };
|
|
90
|
+
if (!hasTelemetry) deps["@open-mercato/telemetry"] = version;
|
|
91
|
+
const optDeps = { ...pkg.optionalDependencies ?? {} };
|
|
92
|
+
if (!hasBullmqOtel) optDeps["bullmq-otel"] = BULLMQ_OTEL_VERSION;
|
|
93
|
+
const next = {
|
|
94
|
+
...pkg,
|
|
95
|
+
dependencies: sortRecord(deps),
|
|
96
|
+
optionalDependencies: sortRecord(optDeps)
|
|
97
|
+
};
|
|
98
|
+
if (!options.dryRun) writeFileSync(path, `${JSON.stringify(next, null, 2)}
|
|
99
|
+
`);
|
|
100
|
+
return {
|
|
101
|
+
file,
|
|
102
|
+
status: "patched",
|
|
103
|
+
detail: `+@open-mercato/telemetry@${version}${hasBullmqOtel ? "" : ` +bullmq-otel@${BULLMQ_OTEL_VERSION} (optional)`} \u2014 run \`yarn install\``
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function sortRecord(record) {
|
|
107
|
+
return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)));
|
|
108
|
+
}
|
|
109
|
+
function patchEnvFile(appDir, relativePath, options) {
|
|
110
|
+
const path = join(appDir, relativePath);
|
|
111
|
+
if (!existsSync(path)) return null;
|
|
112
|
+
const content = readFileSync(path, "utf8");
|
|
113
|
+
if (content.includes("TELEMETRY_BACKEND")) {
|
|
114
|
+
return { file: relativePath, status: "skipped", detail: "TELEMETRY_* block already present" };
|
|
115
|
+
}
|
|
116
|
+
const next = `${content.replace(/\s*$/, "")}
|
|
117
|
+
${ENV_BLOCK}`;
|
|
118
|
+
if (!options.dryRun) writeFileSync(path, next);
|
|
119
|
+
return { file: relativePath, status: "patched", detail: "appended commented TELEMETRY_* / OTEL_* block" };
|
|
120
|
+
}
|
|
121
|
+
function patchInstrumentation(appDir, options) {
|
|
122
|
+
const file = "src/instrumentation.ts";
|
|
123
|
+
const path = join(appDir, file);
|
|
124
|
+
if (!existsSync(path)) {
|
|
125
|
+
if (!options.dryRun) {
|
|
126
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
127
|
+
writeFileSync(path, INSTRUMENTATION_TS);
|
|
128
|
+
}
|
|
129
|
+
return { file, status: "created", detail: "Node-runtime-guarded registerTelemetryForNextjs() bootstrap" };
|
|
130
|
+
}
|
|
131
|
+
const content = readFileSync(path, "utf8");
|
|
132
|
+
if (content.includes("registerTelemetryForNextjs")) {
|
|
133
|
+
if (content.includes("isTelemetryBackendEnabled")) {
|
|
134
|
+
return { file, status: "skipped", detail: "telemetry already wired" };
|
|
135
|
+
}
|
|
136
|
+
const migrated = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
137
|
+
` + content.replace(
|
|
138
|
+
`if (process.env.NEXT_RUNTIME === 'nodejs') {`,
|
|
139
|
+
`if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {`
|
|
140
|
+
);
|
|
141
|
+
if (!options.dryRun) writeFileSync(path, migrated);
|
|
142
|
+
return { file, status: "patched", detail: "added the explicit backend import guard" };
|
|
143
|
+
}
|
|
144
|
+
const anchor = content.match(/export\s+async\s+function\s+register\s*\([^)]*\)\s*:\s*Promise<void>\s*\{/);
|
|
145
|
+
if (!anchor || anchor.index === void 0) {
|
|
146
|
+
return {
|
|
147
|
+
file,
|
|
148
|
+
status: "manual",
|
|
149
|
+
detail: "register() not found \u2014 add the telemetry bootstrap manually",
|
|
150
|
+
manualSnippet: INSTRUMENTATION_TS
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const insertAt = anchor.index + anchor[0].length;
|
|
154
|
+
const block = `
|
|
155
|
+
// Initialize telemetry (no-op unless TELEMETRY_BACKEND is set); Node-only.
|
|
156
|
+
if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {
|
|
157
|
+
const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')
|
|
158
|
+
await registerTelemetryForNextjs()
|
|
159
|
+
}`;
|
|
160
|
+
const importLine = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
161
|
+
`;
|
|
162
|
+
const withImport = content.includes("isTelemetryBackendEnabled") ? content : importLine + content;
|
|
163
|
+
const shiftedInsertAt = insertAt + (withImport.length - content.length);
|
|
164
|
+
const next = withImport.slice(0, shiftedInsertAt) + block + withImport.slice(shiftedInsertAt);
|
|
165
|
+
if (!options.dryRun) writeFileSync(path, next);
|
|
166
|
+
return { file, status: "patched", detail: "inserted registerTelemetryForNextjs() into register()" };
|
|
167
|
+
}
|
|
168
|
+
async function patchNextConfig(appDir, options) {
|
|
169
|
+
const file = "next.config.ts";
|
|
170
|
+
const path = join(appDir, file);
|
|
171
|
+
if (!existsSync(path)) {
|
|
172
|
+
return { file, status: "manual", detail: "next.config.ts not found", manualSnippet: nextConfigSnippet() };
|
|
173
|
+
}
|
|
174
|
+
const { Project, SyntaxKind } = await import("ts-morph");
|
|
175
|
+
const project = new Project({ skipAddingFilesFromTsConfig: true, skipFileDependencyResolution: true });
|
|
176
|
+
const sf = project.addSourceFileAtPath(path);
|
|
177
|
+
const telemetryConfigImport = sf.getImportDeclarations().find((decl) => [
|
|
178
|
+
"@open-mercato/telemetry/nextjs",
|
|
179
|
+
"@open-mercato/telemetry/nextjs-config"
|
|
180
|
+
].includes(decl.getModuleSpecifierValue()));
|
|
181
|
+
const hasImport = Boolean(telemetryConfigImport);
|
|
182
|
+
const hasCanonicalImport = telemetryConfigImport?.getModuleSpecifierValue() === "@open-mercato/telemetry/nextjs-config";
|
|
183
|
+
const arrayProp = sf.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find((prop) => prop.getName() === "serverExternalPackages");
|
|
184
|
+
const arrayInit = arrayProp?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression);
|
|
185
|
+
if (!arrayInit) {
|
|
186
|
+
return {
|
|
187
|
+
file,
|
|
188
|
+
status: "manual",
|
|
189
|
+
detail: "serverExternalPackages array not found",
|
|
190
|
+
manualSnippet: nextConfigSnippet()
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const hasSpread = arrayInit.getElements().some((el) => el.getText().includes("telemetryServerExternalPackages"));
|
|
194
|
+
if (hasCanonicalImport && hasSpread) {
|
|
195
|
+
return { file, status: "skipped", detail: "telemetryServerExternalPackages already wired" };
|
|
196
|
+
}
|
|
197
|
+
let text = readFileSync(path, "utf8");
|
|
198
|
+
if (!hasSpread) {
|
|
199
|
+
const start = arrayInit.getStart();
|
|
200
|
+
const end = arrayInit.getEnd();
|
|
201
|
+
text = text.slice(0, start) + insertSpread(text.slice(start, end)) + text.slice(end);
|
|
202
|
+
}
|
|
203
|
+
text = text.replace(
|
|
204
|
+
"from '@open-mercato/telemetry/nextjs'",
|
|
205
|
+
"from '@open-mercato/telemetry/nextjs-config'"
|
|
206
|
+
);
|
|
207
|
+
if (!hasImport) {
|
|
208
|
+
const importRegex = /^import[^\n]*$/gm;
|
|
209
|
+
let lastImport = null;
|
|
210
|
+
let match;
|
|
211
|
+
while ((match = importRegex.exec(text)) !== null) lastImport = match;
|
|
212
|
+
const insertAt = lastImport ? lastImport.index + lastImport[0].length : 0;
|
|
213
|
+
text = text.slice(0, insertAt) + `
|
|
214
|
+
import { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'` + text.slice(insertAt);
|
|
215
|
+
}
|
|
216
|
+
if (!options.dryRun) writeFileSync(path, text);
|
|
217
|
+
return { file, status: "patched", detail: "spread telemetryServerExternalPackages into serverExternalPackages" };
|
|
218
|
+
}
|
|
219
|
+
function insertSpread(arrayText) {
|
|
220
|
+
const inner = arrayText.slice(1, -1);
|
|
221
|
+
if (inner.includes("\n")) {
|
|
222
|
+
const elementIndent = inner.match(/\n([ \t]+)\S/)?.[1] ?? " ";
|
|
223
|
+
const closeIndent = arrayText.match(/\n([ \t]*)\]$/)?.[1] ?? "";
|
|
224
|
+
const trimmed = inner.replace(/\s*$/, "");
|
|
225
|
+
const separator = trimmed === "" || trimmed.endsWith(",") ? "" : ",";
|
|
226
|
+
return `[${trimmed}${separator}
|
|
227
|
+
${elementIndent}...telemetryServerExternalPackages,
|
|
228
|
+
${closeIndent}]`;
|
|
229
|
+
}
|
|
230
|
+
const flat = inner.trim();
|
|
231
|
+
return flat === "" ? "[...telemetryServerExternalPackages]" : `[${flat}, ...telemetryServerExternalPackages]`;
|
|
232
|
+
}
|
|
233
|
+
function nextConfigSnippet() {
|
|
234
|
+
return `import { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'
|
|
235
|
+
// serverExternalPackages: [ ...existing, ...telemetryServerExternalPackages ]`;
|
|
236
|
+
}
|
|
237
|
+
function patchDispatcher(appDir, options) {
|
|
238
|
+
const file = "src/app/api/[...slug]/route.ts";
|
|
239
|
+
const path = join(appDir, file);
|
|
240
|
+
if (!existsSync(path)) {
|
|
241
|
+
return { file, status: "manual", detail: "dispatcher not found", manualSnippet: DISPATCHER_SNIPPET };
|
|
242
|
+
}
|
|
243
|
+
let content = readFileSync(path, "utf8");
|
|
244
|
+
if (content.includes("from '@open-mercato/shared/lib/telemetry/runtime'") && content.includes("getTelemetryRuntime()?.recordHttpDuration")) {
|
|
245
|
+
return { file, status: "skipped", detail: "telemetry already wired" };
|
|
246
|
+
}
|
|
247
|
+
if (content.includes("import { reportError } from '@open-mercato/telemetry'") && content.includes("import { recordHttpDuration } from '@open-mercato/telemetry/nextjs'")) {
|
|
248
|
+
content = content.replace(
|
|
249
|
+
"import { reportError } from '@open-mercato/telemetry'\nimport { recordHttpDuration } from '@open-mercato/telemetry/nextjs'",
|
|
250
|
+
"import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'"
|
|
251
|
+
).replace(/\brecordHttpDuration\(/g, "getTelemetryRuntime()?.recordHttpDuration(").replace(/\breportError\(/g, "getTelemetryRuntime()?.reportError(");
|
|
252
|
+
if (!options.dryRun) writeFileSync(path, content);
|
|
253
|
+
return { file, status: "patched", detail: "migrated dispatcher to the default-off runtime bridge" };
|
|
254
|
+
}
|
|
255
|
+
const importAnchor = "import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'";
|
|
256
|
+
const returnMatch = content.match(/^([ \t]*)return finalResponse\s*$/m);
|
|
257
|
+
const catchRegex = /^([ \t]*)\}\s*catch\s*\(error\)\s*\{[ \t]*$/gm;
|
|
258
|
+
const catchMatch = findCatchAfter(content, catchRegex, returnMatch?.index ?? -1);
|
|
259
|
+
if (!content.includes(importAnchor) || !returnMatch || returnMatch.index === void 0 || !catchMatch) {
|
|
260
|
+
return {
|
|
261
|
+
file,
|
|
262
|
+
status: "manual",
|
|
263
|
+
detail: "dispatcher shape not recognized \u2014 apply the snippet by hand",
|
|
264
|
+
manualSnippet: DISPATCHER_SNIPPET
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
content = content.replace(
|
|
268
|
+
importAnchor,
|
|
269
|
+
`${importAnchor}
|
|
270
|
+
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'`
|
|
271
|
+
);
|
|
272
|
+
const ret = content.match(/^([ \t]*)return finalResponse\s*$/m);
|
|
273
|
+
if (!ret || ret.index === void 0) {
|
|
274
|
+
return { file, status: "manual", detail: "success-path anchor lost", manualSnippet: DISPATCHER_SNIPPET };
|
|
275
|
+
}
|
|
276
|
+
const retIndent = ret[1];
|
|
277
|
+
content = content.slice(0, ret.index) + `${retIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)
|
|
278
|
+
` + content.slice(ret.index);
|
|
279
|
+
const catch2 = findCatchAfter(content, /^([ \t]*)\}\s*catch\s*\(error\)\s*\{[ \t]*$/gm, content.indexOf("return finalResponse"));
|
|
280
|
+
if (!catch2) {
|
|
281
|
+
return { file, status: "manual", detail: "catch anchor lost", manualSnippet: DISPATCHER_SNIPPET };
|
|
282
|
+
}
|
|
283
|
+
const bodyIndent = `${catch2.indent} `;
|
|
284
|
+
const insertAt = catch2.index + catch2.length;
|
|
285
|
+
const block = `
|
|
286
|
+
${bodyIndent}getTelemetryRuntime()?.reportError(error, {
|
|
287
|
+
${bodyIndent} attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },
|
|
288
|
+
${bodyIndent}})
|
|
289
|
+
${bodyIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`;
|
|
290
|
+
content = content.slice(0, insertAt) + block + content.slice(insertAt);
|
|
291
|
+
if (!options.dryRun) writeFileSync(path, content);
|
|
292
|
+
return { file, status: "patched", detail: "wired reportError (5xx) + http.server.request.duration metric" };
|
|
293
|
+
}
|
|
294
|
+
function findCatchAfter(content, regex, afterIndex) {
|
|
295
|
+
regex.lastIndex = 0;
|
|
296
|
+
let match;
|
|
297
|
+
while ((match = regex.exec(content)) !== null) {
|
|
298
|
+
if (match.index > afterIndex) {
|
|
299
|
+
return { index: match.index, length: match[0].length, indent: match[1] };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
async function runTelemetryInit(args) {
|
|
305
|
+
const appDir = resolve(".");
|
|
306
|
+
const options = parseArgs(args);
|
|
307
|
+
if (!existsSync(join(appDir, "src", "modules.ts"))) {
|
|
308
|
+
console.error("\u274C Not an Open Mercato app directory (src/modules.ts not found)");
|
|
309
|
+
return 1;
|
|
310
|
+
}
|
|
311
|
+
if (!existsSync(join(appDir, "package.json"))) {
|
|
312
|
+
console.error("\u274C package.json not found");
|
|
313
|
+
return 1;
|
|
314
|
+
}
|
|
315
|
+
console.log("");
|
|
316
|
+
console.log(options.dryRun ? "\u{1F52D} Telemetry init (dry run \u2014 no files written)\n" : "\u{1F52D} Wiring @open-mercato/telemetry into this app\n");
|
|
317
|
+
const results = [];
|
|
318
|
+
results.push(patchPackageJson(appDir, options));
|
|
319
|
+
const envExample = patchEnvFile(appDir, ".env.example", options);
|
|
320
|
+
if (envExample) results.push(envExample);
|
|
321
|
+
const env = patchEnvFile(appDir, ".env", options);
|
|
322
|
+
if (env) results.push(env);
|
|
323
|
+
results.push(patchInstrumentation(appDir, options));
|
|
324
|
+
results.push(await patchNextConfig(appDir, options));
|
|
325
|
+
results.push(patchDispatcher(appDir, options));
|
|
326
|
+
const icon = { created: "\u270D\uFE0F ", patched: "\u2705", skipped: "\u23ED\uFE0F ", manual: "\u26A0\uFE0F " };
|
|
327
|
+
for (const result of results) {
|
|
328
|
+
console.log(`${icon[result.status]} ${result.file} \u2014 ${result.detail}`);
|
|
329
|
+
}
|
|
330
|
+
const manual = results.filter((result) => result.status === "manual");
|
|
331
|
+
for (const result of manual) {
|
|
332
|
+
if (!result.manualSnippet) continue;
|
|
333
|
+
console.log("");
|
|
334
|
+
console.log(`\u2500\u2500 manual step for ${result.file} \u2500\u2500`);
|
|
335
|
+
console.log(result.manualSnippet);
|
|
336
|
+
}
|
|
337
|
+
console.log("");
|
|
338
|
+
const changed = results.some((result) => result.status === "patched" || result.status === "created");
|
|
339
|
+
if (options.dryRun) {
|
|
340
|
+
console.log("Dry run complete \u2014 re-run without --dry-run to apply.");
|
|
341
|
+
} else if (changed) {
|
|
342
|
+
console.log("Next steps:");
|
|
343
|
+
console.log(" 1. yarn install (resolve @open-mercato/telemetry + the OTEL SDK)");
|
|
344
|
+
console.log(" 2. set TELEMETRY_BACKEND + OTEL_EXPORTER_OTLP_* in .env");
|
|
345
|
+
console.log(" 3. yarn typecheck && yarn build (verify the wiring)");
|
|
346
|
+
} else {
|
|
347
|
+
console.log("Nothing to do \u2014 telemetry is already wired.");
|
|
348
|
+
}
|
|
349
|
+
if (manual.length > 0) {
|
|
350
|
+
console.log("");
|
|
351
|
+
console.log(`\u26A0\uFE0F ${manual.length} file(s) need a manual edit (shown above) \u2014 the rest were applied automatically.`);
|
|
352
|
+
}
|
|
353
|
+
return 0;
|
|
354
|
+
}
|
|
355
|
+
export {
|
|
356
|
+
runTelemetryInit
|
|
357
|
+
};
|
|
358
|
+
//# sourceMappingURL=telemetry-init.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/telemetry-init.ts"],
|
|
4
|
+
"sourcesContent": ["import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\n\n/**\n * `mercato telemetry init` \u2014 wire `@open-mercato/telemetry` into an app that was\n * scaffolded before telemetry existed. Deterministic, idempotent, and safe to\n * re-run: each step detects whether it is already applied and skips.\n *\n * The web-tier wiring lives in app-owned source files (a dependency bump cannot\n * touch them), so this patches them in place using the same idioms the rest of\n * the CLI uses: JSON edits, detect-before-append for `.env`, a ts-morph edit for\n * `next.config.ts`, and anchored insertion for `instrumentation.ts` + the API\n * dispatcher. When a file's shape is not recognized (a customized dispatcher, an\n * unusual next.config), the step degrades to printing the exact snippet and\n * flags it as a manual step rather than editing code it does not understand.\n *\n * Worker/scheduler telemetry is not handled here \u2014 it ships transitively via\n * `@open-mercato/cli`'s telemetry dependency once the app updates its packages.\n */\n\nconst BULLMQ_OTEL_VERSION = '^1.3.1'\n\ntype StepStatus = 'created' | 'patched' | 'skipped' | 'manual'\n\ntype StepResult = {\n file: string\n status: StepStatus\n detail: string\n /** Snippet to show when the step needs manual work. */\n manualSnippet?: string\n}\n\ntype TelemetryInitOptions = {\n dryRun: boolean\n}\n\nconst ENV_BLOCK = `\n# --- Telemetry & Observability (vendor-neutral OTLP: traces, logs, metrics, errors) ---\n# Off by default: leave TELEMETRY_BACKEND unset (or =noop) for a hard no-op\n# (the OpenTelemetry SDK is never loaded). Set to 'console' for local span/metric\n# output, or an OTLP backend to export: 'signoz' | 'newrelic' | 'otlp' (generic).\n# All three OTLP names use the same exporter \u2014 they differ only by the endpoint +\n# headers below. Any OTLP backend is a one-line swap; no code change.\n# TELEMETRY_BACKEND=otlp\n# Logs use the shared logger facade and its OM_LOG_LEVEL / OM_LOG_PRETTY /\n# OM_LOG_DESTINATION controls. Telemetry adds remote export; it does not create\n# a second local output path.\n# TELEMETRY_SAMPLING_RATIO=1.0 # 0.0\u20131.0 (default 1.0 dev / 0.1 prod)\n# TELEMETRY_TRUST_INBOUND_TRACE=false # default false: root-per-request (ignore an\n# # inbound traceparent from a proxy/LB). Set true\n# # only behind a trusted upstream whose trace continues.\n# # This also enables richer bullmq-otel spans;\n# # otherwise async queues use metadata._trace.\n#\n# OTLP endpoint + auth \u2014 pick ONE vendor (use your region's host):\n# SigNoz Cloud:\n# OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.signoz.cloud:443\n# OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-ingestion-key>\n# New Relic (OTLP-native; EU host shown, US is https://otlp.nr-data.net):\n# OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.eu01.nr-data.net\n# OTEL_EXPORTER_OTLP_HEADERS=api-key=<your-ingest-license-key>\n#\n# Resource identity: keep one stable service name across environments and\n# separate envs via the deployment.environment resource attribute.\n# OTEL_SERVICE_NAME=open-mercato\n# OTEL_RESOURCE_ATTRIBUTES=deployment.environment=local\n`\n\nconst INSTRUMENTATION_TS = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\n\nexport async function register(): Promise<void> {\n // Initialize telemetry (no-op unless TELEMETRY_BACKEND is set). OTEL's NodeSDK\n // is Node-only and incompatible with the edge runtime, so the telemetry\n // bootstrap \u2014 which can pull in the SDK \u2014 is imported only on the Node.js\n // runtime. The helper owns init + graceful degrade + shutdown flush.\n if (\n process.env.NEXT_RUNTIME === 'nodejs'\n && isTelemetryBackendEnabled()\n ) {\n const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')\n await registerTelemetryForNextjs()\n }\n}\n`\n\nconst DISPATCHER_SNIPPET = ` // add near the other imports:\n import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\n\n // in the dispatcher's success path, just before returning the response:\n getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)\n\n // in the dispatcher's catch (error) block, before re-throwing:\n getTelemetryRuntime()?.reportError(error, {\n attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },\n })\n getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`\n\nfunction parseArgs(args: string[]): TelemetryInitOptions {\n return {\n dryRun: args.includes('--dry-run') || args.includes('-n'),\n }\n}\n\n/** Read the version an app already pins its `@open-mercato/*` deps to (lockstep). */\nfunction resolveOpenMercatoVersion(pkg: Record<string, unknown>): string {\n for (const field of ['dependencies', 'devDependencies'] as const) {\n const deps = pkg[field]\n if (deps && typeof deps === 'object') {\n for (const [name, version] of Object.entries(deps as Record<string, string>)) {\n if (name.startsWith('@open-mercato/') && typeof version === 'string') return version\n }\n }\n }\n return '*'\n}\n\nfunction patchPackageJson(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'package.json'\n const path = join(appDir, file)\n const raw = readFileSync(path, 'utf8')\n const pkg = JSON.parse(raw) as {\n dependencies?: Record<string, string>\n optionalDependencies?: Record<string, string>\n }\n const version = resolveOpenMercatoVersion(pkg)\n const hasTelemetry = Boolean(pkg.dependencies?.['@open-mercato/telemetry'])\n const hasBullmqOtel = Boolean(pkg.optionalDependencies?.['bullmq-otel'])\n if (hasTelemetry && hasBullmqOtel) {\n return { file, status: 'skipped', detail: '@open-mercato/telemetry already installed' }\n }\n\n const deps = { ...(pkg.dependencies ?? {}) }\n if (!hasTelemetry) deps['@open-mercato/telemetry'] = version\n const optDeps = { ...(pkg.optionalDependencies ?? {}) }\n if (!hasBullmqOtel) optDeps['bullmq-otel'] = BULLMQ_OTEL_VERSION\n\n const next = {\n ...pkg,\n dependencies: sortRecord(deps),\n optionalDependencies: sortRecord(optDeps),\n }\n if (!options.dryRun) writeFileSync(path, `${JSON.stringify(next, null, 2)}\\n`)\n return {\n file,\n status: 'patched',\n detail: `+@open-mercato/telemetry@${version}${hasBullmqOtel ? '' : ` +bullmq-otel@${BULLMQ_OTEL_VERSION} (optional)`} \u2014 run \\`yarn install\\``,\n }\n}\n\nfunction sortRecord(record: Record<string, string>): Record<string, string> {\n return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)))\n}\n\nfunction patchEnvFile(appDir: string, relativePath: string, options: TelemetryInitOptions): StepResult | null {\n const path = join(appDir, relativePath)\n if (!existsSync(path)) return null\n const content = readFileSync(path, 'utf8')\n if (content.includes('TELEMETRY_BACKEND')) {\n return { file: relativePath, status: 'skipped', detail: 'TELEMETRY_* block already present' }\n }\n const next = `${content.replace(/\\s*$/, '')}\\n${ENV_BLOCK}`\n if (!options.dryRun) writeFileSync(path, next)\n return { file: relativePath, status: 'patched', detail: 'appended commented TELEMETRY_* / OTEL_* block' }\n}\n\nfunction patchInstrumentation(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/instrumentation.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n if (!options.dryRun) {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, INSTRUMENTATION_TS)\n }\n return { file, status: 'created', detail: 'Node-runtime-guarded registerTelemetryForNextjs() bootstrap' }\n }\n const content = readFileSync(path, 'utf8')\n if (content.includes('registerTelemetryForNextjs')) {\n if (content.includes('isTelemetryBackendEnabled')) {\n return { file, status: 'skipped', detail: 'telemetry already wired' }\n }\n const migrated =\n `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\\n` +\n content.replace(\n `if (process.env.NEXT_RUNTIME === 'nodejs') {`,\n `if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {`,\n )\n if (!options.dryRun) writeFileSync(path, migrated)\n return { file, status: 'patched', detail: 'added the explicit backend import guard' }\n }\n const anchor = content.match(/export\\s+async\\s+function\\s+register\\s*\\([^)]*\\)\\s*:\\s*Promise<void>\\s*\\{/)\n if (!anchor || anchor.index === undefined) {\n return {\n file,\n status: 'manual',\n detail: 'register() not found \u2014 add the telemetry bootstrap manually',\n manualSnippet: INSTRUMENTATION_TS,\n }\n }\n const insertAt = anchor.index + anchor[0].length\n const block =\n `\\n // Initialize telemetry (no-op unless TELEMETRY_BACKEND is set); Node-only.` +\n `\\n if (process.env.NEXT_RUNTIME === 'nodejs' && isTelemetryBackendEnabled()) {` +\n `\\n const { registerTelemetryForNextjs } = await import('@open-mercato/telemetry/nextjs')` +\n `\\n await registerTelemetryForNextjs()` +\n `\\n }`\n const importLine = `import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'\\n`\n const withImport = content.includes('isTelemetryBackendEnabled')\n ? content\n : importLine + content\n const shiftedInsertAt = insertAt + (withImport.length - content.length)\n const next = withImport.slice(0, shiftedInsertAt) + block + withImport.slice(shiftedInsertAt)\n if (!options.dryRun) writeFileSync(path, next)\n return { file, status: 'patched', detail: 'inserted registerTelemetryForNextjs() into register()' }\n}\n\nasync function patchNextConfig(appDir: string, options: TelemetryInitOptions): Promise<StepResult> {\n const file = 'next.config.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n return { file, status: 'manual', detail: 'next.config.ts not found', manualSnippet: nextConfigSnippet() }\n }\n // Use ts-morph to *detect* the real `serverExternalPackages` array literal\n // (robust against a match inside a comment/string), then do the *insertion*\n // via a formatting-preserving text splice so the user's config stays tidy.\n const { Project, SyntaxKind } = await import('ts-morph')\n const project = new Project({ skipAddingFilesFromTsConfig: true, skipFileDependencyResolution: true })\n const sf = project.addSourceFileAtPath(path)\n\n const telemetryConfigImport = sf\n .getImportDeclarations()\n .find((decl) => [\n '@open-mercato/telemetry/nextjs',\n '@open-mercato/telemetry/nextjs-config',\n ].includes(decl.getModuleSpecifierValue()))\n const hasImport = Boolean(telemetryConfigImport)\n const hasCanonicalImport =\n telemetryConfigImport?.getModuleSpecifierValue() === '@open-mercato/telemetry/nextjs-config'\n\n const arrayProp = sf\n .getDescendantsOfKind(SyntaxKind.PropertyAssignment)\n .find((prop) => prop.getName() === 'serverExternalPackages')\n const arrayInit = arrayProp?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)\n if (!arrayInit) {\n return {\n file,\n status: 'manual',\n detail: 'serverExternalPackages array not found',\n manualSnippet: nextConfigSnippet(),\n }\n }\n const hasSpread = arrayInit.getElements().some((el) => el.getText().includes('telemetryServerExternalPackages'))\n if (hasCanonicalImport && hasSpread) {\n return { file, status: 'skipped', detail: 'telemetryServerExternalPackages already wired' }\n }\n\n let text = readFileSync(path, 'utf8')\n // Splice the array first, using the AST node's byte offsets (formatting-agnostic:\n // handles both single-line and multi-line arrays). Do this before modifying\n // imports, because either an inserted import or the legacy import migration\n // shifts the array offsets captured from the original source.\n if (!hasSpread) {\n const start = arrayInit.getStart()\n const end = arrayInit.getEnd()\n text = text.slice(0, start) + insertSpread(text.slice(start, end)) + text.slice(end)\n }\n text = text.replace(\n \"from '@open-mercato/telemetry/nextjs'\",\n \"from '@open-mercato/telemetry/nextjs-config'\",\n )\n if (!hasImport) {\n const importRegex = /^import[^\\n]*$/gm\n let lastImport: RegExpExecArray | null = null\n let match: RegExpExecArray | null\n while ((match = importRegex.exec(text)) !== null) lastImport = match\n const insertAt = lastImport ? lastImport.index + lastImport[0].length : 0\n text =\n text.slice(0, insertAt) +\n `\\nimport { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'` +\n text.slice(insertAt)\n }\n if (!options.dryRun) writeFileSync(path, text)\n return { file, status: 'patched', detail: 'spread telemetryServerExternalPackages into serverExternalPackages' }\n}\n\n/** Add `...telemetryServerExternalPackages` as the last element of an array literal, preserving its style. */\nfunction insertSpread(arrayText: string): string {\n const inner = arrayText.slice(1, -1)\n if (inner.includes('\\n')) {\n const elementIndent = inner.match(/\\n([ \\t]+)\\S/)?.[1] ?? ' '\n const closeIndent = arrayText.match(/\\n([ \\t]*)\\]$/)?.[1] ?? ''\n const trimmed = inner.replace(/\\s*$/, '')\n const separator = trimmed === '' || trimmed.endsWith(',') ? '' : ','\n return `[${trimmed}${separator}\\n${elementIndent}...telemetryServerExternalPackages,\\n${closeIndent}]`\n }\n const flat = inner.trim()\n return flat === '' ? '[...telemetryServerExternalPackages]' : `[${flat}, ...telemetryServerExternalPackages]`\n}\n\nfunction nextConfigSnippet(): string {\n return (\n `import { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs-config'\\n` +\n `// serverExternalPackages: [ ...existing, ...telemetryServerExternalPackages ]`\n )\n}\n\n/**\n * Auto-patch the catch-all API dispatcher \u2014 but only when it still matches the\n * known scaffold shape (all anchors present, telemetry not yet wired). On any\n * mismatch, print the snippet and mark it manual rather than editing an\n * unrecognized (customized) handler.\n */\nfunction patchDispatcher(appDir: string, options: TelemetryInitOptions): StepResult {\n const file = 'src/app/api/[...slug]/route.ts'\n const path = join(appDir, file)\n if (!existsSync(path)) {\n return { file, status: 'manual', detail: 'dispatcher not found', manualSnippet: DISPATCHER_SNIPPET }\n }\n let content = readFileSync(path, 'utf8')\n if (\n content.includes(\"from '@open-mercato/shared/lib/telemetry/runtime'\")\n && content.includes('getTelemetryRuntime()?.recordHttpDuration')\n ) {\n return { file, status: 'skipped', detail: 'telemetry already wired' }\n }\n if (\n content.includes(\"import { reportError } from '@open-mercato/telemetry'\")\n && content.includes(\"import { recordHttpDuration } from '@open-mercato/telemetry/nextjs'\")\n ) {\n content = content\n .replace(\n \"import { reportError } from '@open-mercato/telemetry'\\nimport { recordHttpDuration } from '@open-mercato/telemetry/nextjs'\",\n \"import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\",\n )\n .replace(/\\brecordHttpDuration\\(/g, 'getTelemetryRuntime()?.recordHttpDuration(')\n .replace(/\\breportError\\(/g, 'getTelemetryRuntime()?.reportError(')\n if (!options.dryRun) writeFileSync(path, content)\n return { file, status: 'patched', detail: 'migrated dispatcher to the default-off runtime bridge' }\n }\n\n const importAnchor = \"import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\"\n const returnMatch = content.match(/^([ \\t]*)return finalResponse\\s*$/m)\n // The handleRequest catch is the first `} catch (error) {` after the success return.\n const catchRegex = /^([ \\t]*)\\}\\s*catch\\s*\\(error\\)\\s*\\{[ \\t]*$/gm\n const catchMatch = findCatchAfter(content, catchRegex, returnMatch?.index ?? -1)\n\n if (!content.includes(importAnchor) || !returnMatch || returnMatch.index === undefined || !catchMatch) {\n return {\n file,\n status: 'manual',\n detail: 'dispatcher shape not recognized \u2014 apply the snippet by hand',\n manualSnippet: DISPATCHER_SNIPPET,\n }\n }\n\n // 1) imports\n content = content.replace(\n importAnchor,\n `${importAnchor}\\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'`,\n )\n\n // 2) success-path metric (re-match after the import edit shifted offsets)\n const ret = content.match(/^([ \\t]*)return finalResponse\\s*$/m)\n if (!ret || ret.index === undefined) {\n return { file, status: 'manual', detail: 'success-path anchor lost', manualSnippet: DISPATCHER_SNIPPET }\n }\n const retIndent = ret[1]\n content =\n content.slice(0, ret.index) +\n `${retIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)\\n` +\n content.slice(ret.index)\n\n // 3) catch-block error funnel + 500 metric\n const catch2 = findCatchAfter(content, /^([ \\t]*)\\}\\s*catch\\s*\\(error\\)\\s*\\{[ \\t]*$/gm, content.indexOf('return finalResponse'))\n if (!catch2) {\n return { file, status: 'manual', detail: 'catch anchor lost', manualSnippet: DISPATCHER_SNIPPET }\n }\n const bodyIndent = `${catch2.indent} `\n const insertAt = catch2.index + catch2.length\n const block =\n `\\n${bodyIndent}getTelemetryRuntime()?.reportError(error, {` +\n `\\n${bodyIndent} attributes: { 'http.request.method': method, 'http.route': match.route.path, 'http.response.status_code': 500 },` +\n `\\n${bodyIndent}})` +\n `\\n${bodyIndent}getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)`\n content = content.slice(0, insertAt) + block + content.slice(insertAt)\n\n if (!options.dryRun) writeFileSync(path, content)\n return { file, status: 'patched', detail: 'wired reportError (5xx) + http.server.request.duration metric' }\n}\n\nfunction findCatchAfter(\n content: string,\n regex: RegExp,\n afterIndex: number,\n): { index: number; length: number; indent: string } | null {\n regex.lastIndex = 0\n let match: RegExpExecArray | null\n while ((match = regex.exec(content)) !== null) {\n if (match.index > afterIndex) {\n return { index: match.index, length: match[0].length, indent: match[1] }\n }\n }\n return null\n}\n\nexport async function runTelemetryInit(args: string[]): Promise<number> {\n const appDir = resolve('.')\n const options = parseArgs(args)\n\n if (!existsSync(join(appDir, 'src', 'modules.ts'))) {\n console.error('\u274C Not an Open Mercato app directory (src/modules.ts not found)')\n return 1\n }\n if (!existsSync(join(appDir, 'package.json'))) {\n console.error('\u274C package.json not found')\n return 1\n }\n\n console.log('')\n console.log(options.dryRun ? '\uD83D\uDD2D Telemetry init (dry run \u2014 no files written)\\n' : '\uD83D\uDD2D Wiring @open-mercato/telemetry into this app\\n')\n\n const results: StepResult[] = []\n results.push(patchPackageJson(appDir, options))\n const envExample = patchEnvFile(appDir, '.env.example', options)\n if (envExample) results.push(envExample)\n const env = patchEnvFile(appDir, '.env', options)\n if (env) results.push(env)\n results.push(patchInstrumentation(appDir, options))\n results.push(await patchNextConfig(appDir, options))\n results.push(patchDispatcher(appDir, options))\n\n const icon: Record<StepStatus, string> = { created: '\u270D\uFE0F ', patched: '\u2705', skipped: '\u23ED\uFE0F ', manual: '\u26A0\uFE0F ' }\n for (const result of results) {\n console.log(`${icon[result.status]} ${result.file} \u2014 ${result.detail}`)\n }\n\n const manual = results.filter((result) => result.status === 'manual')\n for (const result of manual) {\n if (!result.manualSnippet) continue\n console.log('')\n console.log(`\u2500\u2500 manual step for ${result.file} \u2500\u2500`)\n console.log(result.manualSnippet)\n }\n\n console.log('')\n const changed = results.some((result) => result.status === 'patched' || result.status === 'created')\n if (options.dryRun) {\n console.log('Dry run complete \u2014 re-run without --dry-run to apply.')\n } else if (changed) {\n console.log('Next steps:')\n console.log(' 1. yarn install (resolve @open-mercato/telemetry + the OTEL SDK)')\n console.log(' 2. set TELEMETRY_BACKEND + OTEL_EXPORTER_OTLP_* in .env')\n console.log(' 3. yarn typecheck && yarn build (verify the wiring)')\n } else {\n console.log('Nothing to do \u2014 telemetry is already wired.')\n }\n if (manual.length > 0) {\n console.log('')\n console.log(`\u26A0\uFE0F ${manual.length} file(s) need a manual edit (shown above) \u2014 the rest were applied automatically.`)\n }\n return 0\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY,cAAc,eAAe,iBAAiB;AACnE,SAAS,SAAS,MAAM,eAAe;AAmBvC,MAAM,sBAAsB;AAgB5B,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgClB,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB3B,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAY3B,SAAS,UAAU,MAAsC;AACvD,SAAO;AAAA,IACL,QAAQ,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,IAAI;AAAA,EAC1D;AACF;AAGA,SAAS,0BAA0B,KAAsC;AACvE,aAAW,SAAS,CAAC,gBAAgB,iBAAiB,GAAY;AAChE,UAAM,OAAO,IAAI,KAAK;AACtB,QAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,iBAAW,CAAC,MAAM,OAAO,KAAK,OAAO,QAAQ,IAA8B,GAAG;AAC5E,YAAI,KAAK,WAAW,gBAAgB,KAAK,OAAO,YAAY,SAAU,QAAO;AAAA,MAC/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