forgeos 0.1.0-alpha.7 → 0.1.0-alpha.71
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/.agents/skills/forge-agent-fabric/SKILL.md +178 -0
- package/.agents/skills/forge-agent-fabric/references/managed-workflows.md +95 -0
- package/.agents/skills/forge-agent-fabric/references/repository-analysis.md +102 -0
- package/.agents/skills/forge-agent-fabric/scripts/fabric.mjs +46 -0
- package/.agents/skills/forge-agent-fabric/scripts/repository.mjs +44 -0
- package/.npmignore +10 -0
- package/AGENTS.md +142 -90
- package/CHANGELOG.md +870 -9
- package/LICENSE +21 -0
- package/README.md +121 -6
- package/adapters/go/README.md +23 -0
- package/adapters/go/go.mod +3 -0
- package/adapters/go/http.go +149 -0
- package/adapters/go/registry.go +234 -0
- package/adapters/go/types.go +136 -0
- package/adapters/java/README.md +68 -0
- package/adapters/java/pom.xml +47 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Auth.java +20 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Diagnostic.java +16 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Entry.java +38 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/EntryKind.java +16 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ErrorInfo.java +4 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Forge.java +94 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeCall.java +12 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeContext.java +11 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeHandler.java +8 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeHttpHandler.java +179 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeRegistry.java +121 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Json.java +14 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Manifest.java +14 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/RequestEnvelope.java +6 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ResponseEnvelope.java +25 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Risk.java +18 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Schemas.java +36 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Service.java +65 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/TransactionMode.java +18 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/TypedForgeHandler.java +6 -0
- package/adapters/java-spring-boot-starter/README.md +32 -0
- package/adapters/java-spring-boot-starter/pom.xml +49 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeCommand.java +22 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeExternalService.java +15 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeQuery.java +16 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeServiceBeanCondition.java +18 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeSpringAutoConfiguration.java +16 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeSpringRuntime.java +104 -0
- package/adapters/java-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +1 -0
- package/bin/forge.mjs +18 -0
- package/docs/agent-fabric-programs.md +151 -0
- package/docs/agent-fabric.md +582 -0
- package/docs/architecture/agent-fabric/PORTABLE_PROJECTS_PLAN.md +136 -0
- package/docs/architecture/agent-fabric/README.md +180 -0
- package/docs/architecture/agent-fabric/REPOSITORY_MANIFEST_PLAN.md +284 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_ADR.md +81 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_CORRECTIONS.md +39 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_CORRECTIONS_EVIDENCE.md +53 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_EVIDENCE.md +49 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_PLAN.md +590 -0
- package/docs/cair-protocol.md +103 -0
- package/docs/changelog.md +1070 -0
- package/docs/forge-protocol.md +189 -0
- package/docs/repository-agent-benchmark.md +179 -0
- package/docs/repository-analysis.md +139 -0
- package/docs/repository-context-quality.md +179 -0
- package/docs/repository-runtime-observation.md +82 -0
- package/examples/agent-fabric-v2/README.md +70 -0
- package/examples/agent-fabric-v2/item-child.workflow.ts +11 -0
- package/examples/agent-fabric-v2/make-request.mjs +4 -0
- package/examples/agent-fabric-v2/map-child.workflow.ts +10 -0
- package/examples/agent-fabric-v2/migrate.workflow.ts +35 -0
- package/examples/agent-fabric-v2/registry.example.json +256 -0
- package/examples/agent-fabric-v2/run-ui-fixture.ts +48 -0
- package/examples/agent-fabric-v2/ui-audit.workflow.ts +28 -0
- package/examples/agent-fabric-v2/ui-fixture-worker.cjs +36 -0
- package/examples/agent-fabric-v2/visual-population.json +13 -0
- package/examples/agent-fabric-v2/workers/check.mjs +2 -0
- package/examples/agent-fabric-v2/workers/common.mjs +7 -0
- package/examples/agent-fabric-v2/workers/discover.mjs +2 -0
- package/examples/agent-fabric-v2/workers/migrate.mjs +4 -0
- package/examples/agent-fabric-v2/workers/review.mjs +3 -0
- package/examples/go-billing/go.mod +7 -0
- package/examples/go-billing/main.go +120 -0
- package/examples/java-billing/pom.xml +60 -0
- package/examples/java-billing/src/main/java/dev/forgeos/examples/billing/CreateInvoiceInput.java +4 -0
- package/examples/java-billing/src/main/java/dev/forgeos/examples/billing/Invoice.java +11 -0
- package/examples/java-billing/src/main/java/dev/forgeos/examples/billing/Main.java +127 -0
- package/package.json +60 -5
- package/schemas/agent-fabric/v0.1/control-event.schema.json +281 -0
- package/schemas/forge-manifest.schema.json +389 -0
- package/scripts/field-test-forgeos.mjs +1021 -0
- package/scripts/install-agent-fabric-skill.mjs +105 -0
- package/src/forge/_generated/releaseManifest.json +1 -2
- package/src/forge/_generated/releaseManifest.ts +3 -3
- package/src/forge/agent-adapters/index.ts +1592 -125
- package/src/forge/agent-adapters/types.ts +225 -1
- package/src/forge/agent-fabric/adapter.ts +131 -0
- package/src/forge/agent-fabric/attached-snapshot.ts +55 -0
- package/src/forge/agent-fabric/attached-task-contract.ts +105 -0
- package/src/forge/agent-fabric/attached-task-service.ts +127 -0
- package/src/forge/agent-fabric/attached-task-store.ts +109 -0
- package/src/forge/agent-fabric/authority.ts +298 -0
- package/src/forge/agent-fabric/canonical.ts +135 -0
- package/src/forge/agent-fabric/codex-adversarial-review.ts +229 -0
- package/src/forge/agent-fabric/codex-sdk-worker.ts +203 -0
- package/src/forge/agent-fabric/conductor.ts +754 -0
- package/src/forge/agent-fabric/dictionary.ts +12 -0
- package/src/forge/agent-fabric/errors.ts +32 -0
- package/src/forge/agent-fabric/hardened-conductor.ts +485 -0
- package/src/forge/agent-fabric/hardened-reducer.ts +211 -0
- package/src/forge/agent-fabric/index.ts +48 -0
- package/src/forge/agent-fabric/journal.ts +116 -0
- package/src/forge/agent-fabric/local-adaptive-digest-worker.mjs +26 -0
- package/src/forge/agent-fabric/local-adaptive-harness.ts +343 -0
- package/src/forge/agent-fabric/local-adaptive-service.ts +398 -0
- package/src/forge/agent-fabric/local-adaptive-worker.ts +146 -0
- package/src/forge/agent-fabric/local-approval-window.ts +211 -0
- package/src/forge/agent-fabric/local-change-review-service.ts +374 -0
- package/src/forge/agent-fabric/local-coding-worker.ts +285 -0
- package/src/forge/agent-fabric/local-control-store.ts +239 -0
- package/src/forge/agent-fabric/local-effect-broker.ts +348 -0
- package/src/forge/agent-fabric/local-evolution-approval.ts +81 -0
- package/src/forge/agent-fabric/local-evolution-profile.ts +87 -0
- package/src/forge/agent-fabric/local-evolution-registry.ts +427 -0
- package/src/forge/agent-fabric/local-evolution-service.ts +200 -0
- package/src/forge/agent-fabric/local-intelligence.ts +281 -0
- package/src/forge/agent-fabric/local-paths.ts +18 -0
- package/src/forge/agent-fabric/local-task-contract.ts +203 -0
- package/src/forge/agent-fabric/local-task-inbox.ts +543 -0
- package/src/forge/agent-fabric/local-task-server.ts +374 -0
- package/src/forge/agent-fabric/local-task-service.ts +982 -0
- package/src/forge/agent-fabric/local-verification.ts +551 -0
- package/src/forge/agent-fabric/managed-environment.ts +205 -0
- package/src/forge/agent-fabric/managed-run-contract.ts +103 -0
- package/src/forge/agent-fabric/managed-run-service.ts +401 -0
- package/src/forge/agent-fabric/managed-run-store.ts +165 -0
- package/src/forge/agent-fabric/managed-workspace.ts +253 -0
- package/src/forge/agent-fabric/p0a.ts +104 -0
- package/src/forge/agent-fabric/p0b-model-adapter.ts +434 -0
- package/src/forge/agent-fabric/planning.ts +155 -0
- package/src/forge/agent-fabric/program-api.ts +37 -0
- package/src/forge/agent-fabric/program-contract.ts +283 -0
- package/src/forge/agent-fabric/program-dsl.ts +126 -0
- package/src/forge/agent-fabric/program-evidence.ts +22 -0
- package/src/forge/agent-fabric/program-image.ts +15 -0
- package/src/forge/agent-fabric/program-lock.ts +50 -0
- package/src/forge/agent-fabric/program-owner.ts +16 -0
- package/src/forge/agent-fabric/program-scheduler.ts +38 -0
- package/src/forge/agent-fabric/program-service.ts +793 -0
- package/src/forge/agent-fabric/program-store.ts +142 -0
- package/src/forge/agent-fabric/program-structure.ts +65 -0
- package/src/forge/agent-fabric/program-types.ts +110 -0
- package/src/forge/agent-fabric/program-view.ts +12 -0
- package/src/forge/agent-fabric/program-worker.ts +108 -0
- package/src/forge/agent-fabric/project-profile.ts +50 -0
- package/src/forge/agent-fabric/project-registry.ts +120 -0
- package/src/forge/agent-fabric/project-runtime.ts +85 -0
- package/src/forge/agent-fabric/readiness.ts +26 -0
- package/src/forge/agent-fabric/reducer.ts +863 -0
- package/src/forge/agent-fabric/repository-context.ts +83 -0
- package/src/forge/agent-fabric/resource-ledger.ts +266 -0
- package/src/forge/agent-fabric/serialized-local-adapter.ts +60 -0
- package/src/forge/agent-fabric/types.ts +424 -0
- package/src/forge/agent-fabric/validation.ts +500 -0
- package/src/forge/agent-fabric/workflow-engine.ts +218 -0
- package/src/forge/agent-fabric/workflow-task-actions.ts +104 -0
- package/src/forge/agent-fabric/workflow-templates.ts +11 -0
- package/src/forge/agent-memory/bridge.ts +1728 -0
- package/src/forge/agent-memory/context-pack.ts +284 -0
- package/src/forge/agent-memory/hook-runner.ts +331 -0
- package/src/forge/agent-memory/mcp.ts +597 -0
- package/src/forge/agent-memory/normalize.ts +498 -0
- package/src/forge/agent-memory/redaction.ts +103 -0
- package/src/forge/agent-memory/sources/claude-code.ts +51 -0
- package/src/forge/agent-memory/sources/codex-hook-runner.mjs +343 -0
- package/src/forge/agent-memory/sources/codex.ts +161 -0
- package/src/forge/agent-memory/sources/cursor.ts +35 -0
- package/src/forge/agent-memory/types.ts +215 -0
- package/src/forge/bench.ts +248 -0
- package/src/forge/brownfield-import/index.ts +896 -0
- package/src/forge/brownfield-import/types.ts +127 -0
- package/src/forge/cair/action-journal.ts +61 -0
- package/src/forge/cair/action-parser.ts +314 -0
- package/src/forge/cair/action-validator.ts +40 -0
- package/src/forge/cair/actions.ts +1818 -0
- package/src/forge/cair/format.ts +77 -0
- package/src/forge/cair/index.ts +118 -0
- package/src/forge/cair/query.ts +478 -0
- package/src/forge/cair/snapshot.ts +315 -0
- package/src/forge/cair/types.ts +255 -0
- package/src/forge/cli/adaptive.ts +51 -0
- package/src/forge/cli/ai.ts +16 -1
- package/src/forge/cli/auth.ts +459 -15
- package/src/forge/cli/authmd.ts +441 -0
- package/src/forge/cli/baseline.ts +112 -0
- package/src/forge/cli/build.ts +20 -4
- package/src/forge/cli/changed.ts +418 -0
- package/src/forge/cli/codex-app-server.ts +877 -0
- package/src/forge/cli/commands.ts +1859 -20
- package/src/forge/cli/db.ts +209 -2
- package/src/forge/cli/deploy.ts +1339 -0
- package/src/forge/cli/deps.ts +150 -23
- package/src/forge/cli/dev.ts +1137 -53
- package/src/forge/cli/docs.ts +265 -0
- package/src/forge/cli/doctor.ts +297 -0
- package/src/forge/cli/env-placeholders.ts +62 -0
- package/src/forge/cli/evolution.ts +40 -0
- package/src/forge/cli/fabric.ts +253 -0
- package/src/forge/cli/field-test.ts +568 -0
- package/src/forge/cli/golden-path.ts +487 -0
- package/src/forge/cli/handoff.ts +336 -0
- package/src/forge/cli/index.ts +1 -0
- package/src/forge/cli/last-run.ts +84 -0
- package/src/forge/cli/main.ts +196 -3
- package/src/forge/cli/new.ts +169 -17
- package/src/forge/cli/next-actions.ts +23 -0
- package/src/forge/cli/output.ts +398 -6
- package/src/forge/cli/parse.ts +1377 -38
- package/src/forge/cli/progress.ts +51 -0
- package/src/forge/cli/query.ts +32 -0
- package/src/forge/cli/release.ts +35 -11
- package/src/forge/cli/repository.ts +151 -0
- package/src/forge/cli/run.ts +42 -0
- package/src/forge/cli/secrets.ts +137 -1
- package/src/forge/cli/seed.ts +581 -0
- package/src/forge/cli/self-host.ts +56 -14
- package/src/forge/cli/studio.ts +2282 -0
- package/src/forge/cli/verify.ts +1458 -32
- package/src/forge/cli/windows.ts +23 -0
- package/src/forge/cli/workos.ts +3509 -0
- package/src/forge/compiler/agent-contract/build.ts +728 -64
- package/src/forge/compiler/agent-contract/types.ts +45 -2
- package/src/forge/compiler/ai-registry/parse.ts +71 -2
- package/src/forge/compiler/api-surface/build.ts +47 -0
- package/src/forge/compiler/app-graph/build.ts +112 -9
- package/src/forge/compiler/app-graph/extract.ts +107 -0
- package/src/forge/compiler/app-graph/module-graph.ts +73 -78
- package/src/forge/compiler/app-graph/parser.ts +24 -24
- package/src/forge/compiler/app-graph/profile.ts +26 -0
- package/src/forge/compiler/app-graph/tsconfig-hash.ts +41 -4
- package/src/forge/compiler/app-graph/versions.ts +1 -1
- package/src/forge/compiler/classifier/capabilities.ts +3 -2
- package/src/forge/compiler/classifier/classify.ts +32 -8
- package/src/forge/compiler/classifier/secrets.ts +3 -2
- package/src/forge/compiler/classifier/signals.ts +91 -1
- package/src/forge/compiler/client-sdk/build-manifest.ts +59 -0
- package/src/forge/compiler/client-sdk/render-client.ts +295 -13
- package/src/forge/compiler/data-graph/build.ts +29 -1
- package/src/forge/compiler/data-graph/parse.ts +20 -4
- package/src/forge/compiler/data-graph/sql/ddl.ts +144 -31
- package/src/forge/compiler/data-graph/sql/serialize.ts +4 -0
- package/src/forge/compiler/data-graph/sql/types.ts +1 -0
- package/src/forge/compiler/diagnostics/codes.ts +38 -0
- package/src/forge/compiler/diagnostics/create.ts +28 -2
- package/src/forge/compiler/diagnostics/index.ts +2 -0
- package/src/forge/compiler/emitter/barrel.ts +3 -0
- package/src/forge/compiler/emitter/render.ts +9 -0
- package/src/forge/compiler/external-manifest/registry.ts +217 -0
- package/src/forge/compiler/external-manifest/types.ts +91 -0
- package/src/forge/compiler/external-manifest/validate.ts +373 -0
- package/src/forge/compiler/frontend-graph/build.ts +142 -14
- package/src/forge/compiler/integration/add.ts +991 -33
- package/src/forge/compiler/integration/plan.ts +43 -12
- package/src/forge/compiler/integration/render.ts +29 -0
- package/src/forge/compiler/integration/snapshot.ts +2 -0
- package/src/forge/compiler/integration/templates/convex.ts +70 -0
- package/src/forge/compiler/integration/templates/index.ts +1 -0
- package/src/forge/compiler/integration/templates/render.ts +38 -0
- package/src/forge/compiler/integration/templates/types.ts +3 -0
- package/src/forge/compiler/integration/templates/workos.ts +1439 -0
- package/src/forge/compiler/make-registry/build.ts +8 -9
- package/src/forge/compiler/orchestrator/fast-check.ts +4 -0
- package/src/forge/compiler/orchestrator/generate-lock.ts +14 -3
- package/src/forge/compiler/orchestrator/manifest.ts +1 -1
- package/src/forge/compiler/orchestrator/plan-profile.ts +23 -0
- package/src/forge/compiler/orchestrator/plan.ts +249 -10
- package/src/forge/compiler/orchestrator/profile.ts +65 -0
- package/src/forge/compiler/orchestrator/run.ts +101 -33
- package/src/forge/compiler/orchestrator/serialize.ts +33 -8
- package/src/forge/compiler/orchestrator/types.ts +1 -1
- package/src/forge/compiler/package-graph/compiler.ts +3 -1
- package/src/forge/compiler/package-graph/constants.ts +1 -1
- package/src/forge/compiler/package-graph/dts-extractor.ts +14 -1
- package/src/forge/compiler/package-manager/adapter.ts +4 -1
- package/src/forge/compiler/package-manager/commands.ts +4 -0
- package/src/forge/compiler/package-manager/executor.ts +30 -1
- package/src/forge/compiler/package-manager/version.ts +36 -12
- package/src/forge/compiler/package-upgrades/planner.ts +155 -18
- package/src/forge/compiler/package-upgrades/types.ts +2 -0
- package/src/forge/compiler/policy-registry/build.ts +47 -2
- package/src/forge/compiler/policy-registry/parse.ts +32 -2
- package/src/forge/compiler/recipes/definitions.ts +63 -0
- package/src/forge/compiler/recipes/index.ts +2 -0
- package/src/forge/compiler/recipes/profiles.ts +81 -0
- package/src/forge/compiler/recipes/registry.ts +6 -0
- package/src/forge/compiler/test-graph/build.ts +11 -3
- package/src/forge/compiler/types/app-graph.ts +8 -2
- package/src/forge/compiler/types/cli.ts +76 -1
- package/src/forge/compiler/types/dev-manifest.ts +4 -0
- package/src/forge/compiler/types/emit.ts +2 -0
- package/src/forge/compiler/types/frontend-graph.ts +2 -2
- package/src/forge/compiler/types/integration.ts +1 -0
- package/src/forge/compiler/types/package-graph.ts +6 -0
- package/src/forge/compiler/types/policy-registry.ts +3 -1
- package/src/forge/delta/broker-runner.mjs +5 -0
- package/src/forge/delta/broker.ts +429 -0
- package/src/forge/delta/classifier.ts +52 -0
- package/src/forge/delta/explain.ts +238 -0
- package/src/forge/delta/git-observer.ts +67 -0
- package/src/forge/delta/ids.ts +44 -0
- package/src/forge/delta/index.ts +25 -0
- package/src/forge/delta/process-identity.ts +37 -0
- package/src/forge/delta/queue-status.ts +190 -0
- package/src/forge/delta/recorder.ts +540 -0
- package/src/forge/delta/redaction.ts +50 -0
- package/src/forge/delta/schema.ts +240 -0
- package/src/forge/delta/session.ts +142 -0
- package/src/forge/delta/status.ts +1139 -0
- package/src/forge/delta/store.ts +3329 -0
- package/src/forge/delta/timeline.ts +178 -0
- package/src/forge/dev/server.ts +1061 -22
- package/src/forge/dev/types.ts +15 -1
- package/src/forge/dev/watch.ts +17 -7
- package/src/forge/dev-console/cycle.ts +285 -33
- package/src/forge/dev-console/types.ts +47 -1
- package/src/forge/impact/index.ts +222 -30
- package/src/forge/impact/types.ts +33 -1
- package/src/forge/intent/index.ts +35 -16
- package/src/forge/make/fields.ts +26 -0
- package/src/forge/make/index.ts +42 -6
- package/src/forge/make/templates.ts +211 -4
- package/src/forge/make/types.ts +2 -1
- package/src/forge/policy.ts +1 -1
- package/src/forge/react/index.ts +160 -2
- package/src/forge/refactor/index.ts +1 -0
- package/src/forge/repair/rules/index.ts +2 -2
- package/src/forge/repository-analysis/adapters/common.ts +72 -0
- package/src/forge/repository-analysis/adapters/docker.ts +185 -0
- package/src/forge/repository-analysis/adapters/java.ts +133 -0
- package/src/forge/repository-analysis/adapters/typescript.ts +350 -0
- package/src/forge/repository-analysis/adapters/vue.ts +71 -0
- package/src/forge/repository-analysis/analyze.ts +434 -0
- package/src/forge/repository-analysis/benchmark.ts +336 -0
- package/src/forge/repository-analysis/cache-gc.ts +154 -0
- package/src/forge/repository-analysis/check-selection.ts +123 -0
- package/src/forge/repository-analysis/context-node.ts +17 -0
- package/src/forge/repository-analysis/context.ts +456 -0
- package/src/forge/repository-analysis/http-resolution.ts +135 -0
- package/src/forge/repository-analysis/identity.ts +45 -0
- package/src/forge/repository-analysis/index.ts +18 -0
- package/src/forge/repository-analysis/nuxt-resolution.ts +188 -0
- package/src/forge/repository-analysis/quality.ts +60 -0
- package/src/forge/repository-analysis/retrieval.ts +309 -0
- package/src/forge/repository-analysis/runtime-artifacts.ts +195 -0
- package/src/forge/repository-analysis/runtime-observation.ts +325 -0
- package/src/forge/repository-analysis/scanner.ts +174 -0
- package/src/forge/repository-analysis/storage.ts +193 -0
- package/src/forge/repository-analysis/test-associations.ts +59 -0
- package/src/forge/repository-analysis/types.ts +99 -0
- package/src/forge/repository-manifest/index.ts +178 -0
- package/src/forge/repository-manifest/types.ts +63 -0
- package/src/forge/review/index.ts +162 -12
- package/src/forge/review/types.ts +15 -0
- package/src/forge/runtime/ai/providers.ts +19 -4
- package/src/forge/runtime/auth/config.ts +17 -0
- package/src/forge/runtime/auth/evaluate.ts +15 -2
- package/src/forge/runtime/auth/resolve.ts +61 -6
- package/src/forge/runtime/auth/types.ts +1 -0
- package/src/forge/runtime/db/factory.ts +1 -3
- package/src/forge/runtime/db/generated-client.ts +13 -2
- package/src/forge/runtime/db/memory-adapter.ts +139 -32
- package/src/forge/runtime/db/pglite-adapter.ts +285 -2
- package/src/forge/runtime/executor.ts +129 -16
- package/src/forge/runtime/external/bridge.ts +663 -0
- package/src/forge/runtime/runner/run-entry.ts +16 -7
- package/src/forge/runtime/telemetry/buffer.ts +4 -1
- package/src/forge/runtime/telemetry/scrubber.ts +35 -5
- package/src/forge/runtime/webhooks/security.ts +12 -7
- package/src/forge/server.ts +71 -7
- package/src/forge/ui/index.ts +831 -19
- package/src/forge/ui/types.ts +3 -1
- package/src/forge/version.ts +1 -1
- package/src/forge/vue/index.ts +422 -0
- package/src/forge/workspace/baseline.ts +112 -0
- package/src/forge/workspace/change-summary.ts +292 -0
- package/src/forge/workspace/forge-cli.ts +42 -0
- package/src/forge/workspace/git-summary.ts +393 -0
- package/templates/agent-workroom/AGENTS.md +29 -0
- package/templates/agent-workroom/README.md +34 -0
- package/templates/agent-workroom/forge.config.ts +3 -0
- package/templates/agent-workroom/package.json +34 -0
- package/templates/agent-workroom/pnpm-workspace.yaml +2 -0
- package/templates/agent-workroom/src/actions/indexAgentSignal.ts +10 -0
- package/templates/agent-workroom/src/commands/openWorkroom.ts +61 -0
- package/templates/agent-workroom/src/commands/recordAgentSignal.ts +119 -0
- package/templates/agent-workroom/src/commands/recordCheckRun.ts +52 -0
- package/templates/agent-workroom/src/forge/schema.ts +54 -0
- package/templates/agent-workroom/src/policies.ts +6 -0
- package/templates/agent-workroom/src/queries/listWorkrooms.ts +11 -0
- package/templates/agent-workroom/src/queries/liveWorkroom.ts +63 -0
- package/templates/agent-workroom/tsconfig.json +16 -0
- package/templates/agent-workroom/web/index.html +13 -0
- package/templates/agent-workroom/web/package.json +21 -0
- package/templates/agent-workroom/web/src/App.tsx +345 -0
- package/templates/agent-workroom/web/src/lib/forge.ts +20 -0
- package/templates/agent-workroom/web/src/main.tsx +13 -0
- package/templates/agent-workroom/web/src/styles.css +545 -0
- package/templates/agent-workroom/web/tsconfig.json +27 -0
- package/templates/agent-workroom/web/vite.config.ts +36 -0
- package/templates/b2b-support-web/package.json +2 -0
- package/templates/b2b-support-web/pnpm-workspace.yaml +2 -0
- package/templates/b2b-support-web/web/app/page.tsx +2 -2
- package/templates/b2b-support-web/web/lib/forge.ts +9 -2
- package/templates/b2b-support-web/web/next.config.ts +24 -0
- package/templates/b2b-support-web/web/package.json +1 -1
- package/templates/minimal-web/package.json +2 -1
- package/templates/minimal-web/pnpm-workspace.yaml +2 -0
- package/templates/minimal-web/web/index.html +1 -0
- package/templates/minimal-web/web/src/App.tsx +12 -6
- package/templates/minimal-web/web/src/lib/forge.ts +9 -2
- package/templates/minimal-web/web/src/styles.css +34 -0
- package/templates/minimal-web/web/vite.config.ts +36 -0
- package/templates/nuxt-web/.vscode/settings.json +14 -0
- package/templates/nuxt-web/.yarnrc.yml +1 -0
- package/templates/nuxt-web/README.md +30 -0
- package/templates/nuxt-web/forge.config.ts +3 -0
- package/templates/nuxt-web/package.json +37 -0
- package/templates/nuxt-web/pnpm-workspace.yaml +2 -0
- package/templates/nuxt-web/src/actions/logNoteCreated.ts +11 -0
- package/templates/nuxt-web/src/commands/createNote.ts +26 -0
- package/templates/nuxt-web/src/forge/schema.ts +12 -0
- package/templates/nuxt-web/src/policies.ts +6 -0
- package/templates/nuxt-web/src/queries/listNotes.ts +8 -0
- package/templates/nuxt-web/src/queries/liveNotes.ts +8 -0
- package/templates/nuxt-web/tsconfig.json +17 -0
- package/templates/nuxt-web/web/app.vue +67 -0
- package/templates/nuxt-web/web/components/LiveNotes.vue +89 -0
- package/templates/nuxt-web/web/components/NoteComposer.vue +100 -0
- package/templates/nuxt-web/web/composables/forge.ts +13 -0
- package/templates/nuxt-web/web/composables/useNotes.ts +24 -0
- package/templates/nuxt-web/web/nuxt.config.ts +11 -0
- package/templates/nuxt-web/web/package.json +22 -0
- package/templates/nuxt-web/web/plugins/forge.client.ts +10 -0
- package/templates/nuxt-web/web/plugins/forge.server.ts +10 -0
- package/templates/nuxt-web/web/server/api/forge-health.get.ts +7 -0
- package/templates/nuxt-web/web/tsconfig.json +6 -0
- package/templates/vendor-access/.vscode/settings.json +14 -0
- package/templates/vendor-access/README.md +30 -0
- package/templates/vendor-access/forge.config.ts +3 -0
- package/templates/vendor-access/package.json +35 -0
- package/templates/vendor-access/pnpm-workspace.yaml +2 -0
- package/templates/vendor-access/src/commands/addEvidence.ts +42 -0
- package/templates/vendor-access/src/commands/approveAccessRequest.ts +43 -0
- package/templates/vendor-access/src/commands/createAccessRequest.ts +49 -0
- package/templates/vendor-access/src/commands/seedVendorAccessDemo.ts +200 -0
- package/templates/vendor-access/src/forge/schema.ts +74 -0
- package/templates/vendor-access/src/policies.ts +11 -0
- package/templates/vendor-access/src/queries/listVendorAccessDashboard.ts +24 -0
- package/templates/vendor-access/src/queries/liveVendorAccessDashboard.ts +24 -0
- package/templates/vendor-access/tsconfig.json +17 -0
- package/templates/vendor-access/web/index.html +13 -0
- package/templates/vendor-access/web/package.json +21 -0
- package/templates/vendor-access/web/src/App.tsx +573 -0
- package/templates/vendor-access/web/src/lib/forge.ts +20 -0
- package/templates/vendor-access/web/src/main.tsx +205 -0
- package/templates/vendor-access/web/src/styles.css +682 -0
- package/templates/vendor-access/web/tsconfig.json +18 -0
- package/templates/vendor-access/web/vite.config.ts +36 -0
- package/src/forge/_generated/actionSubscriptions.json +0 -2
- package/src/forge/_generated/actionSubscriptions.ts +0 -10
- package/src/forge/_generated/agentAdapterManifest.json +0 -2
- package/src/forge/_generated/agentAdapterManifest.ts +0 -73
- package/src/forge/_generated/agentContract.json +0 -2
- package/src/forge/_generated/agentContract.ts +0 -7829
- package/src/forge/_generated/agentQuickstart.md +0 -34
- package/src/forge/_generated/agentTools.json +0 -2
- package/src/forge/_generated/agentTools.md +0 -16
- package/src/forge/_generated/agentTools.ts +0 -12
- package/src/forge/_generated/aiContext.ts +0 -125
- package/src/forge/_generated/aiModels.json +0 -2
- package/src/forge/_generated/aiModels.ts +0 -51
- package/src/forge/_generated/aiProviders.json +0 -2
- package/src/forge/_generated/aiProviders.ts +0 -23
- package/src/forge/_generated/aiRegistry.json +0 -2
- package/src/forge/_generated/aiRegistry.ts +0 -31
- package/src/forge/_generated/api.json +0 -2
- package/src/forge/_generated/api.ts +0 -8
- package/src/forge/_generated/appGraph.json +0 -2
- package/src/forge/_generated/appGraph.ts +0 -14937
- package/src/forge/_generated/appMap.md +0 -55
- package/src/forge/_generated/artifactManifest.json +0 -2
- package/src/forge/_generated/artifactManifest.ts +0 -7
- package/src/forge/_generated/authClaims.json +0 -2
- package/src/forge/_generated/authClaims.ts +0 -13
- package/src/forge/_generated/authConfig.json +0 -2
- package/src/forge/_generated/authConfig.ts +0 -17
- package/src/forge/_generated/authContext.ts +0 -23
- package/src/forge/_generated/authRegistry.json +0 -2
- package/src/forge/_generated/authRegistry.ts +0 -25
- package/src/forge/_generated/buildInfo.json +0 -2
- package/src/forge/_generated/buildInfo.ts +0 -9
- package/src/forge/_generated/capabilityMap.json +0 -2
- package/src/forge/_generated/capabilityMap.md +0 -15
- package/src/forge/_generated/capabilityMap.ts +0 -17
- package/src/forge/_generated/client.ts +0 -282
- package/src/forge/_generated/clientApi.ts +0 -9
- package/src/forge/_generated/clientManifest.json +0 -2
- package/src/forge/_generated/clientManifest.ts +0 -39
- package/src/forge/_generated/clientTypes.ts +0 -78
- package/src/forge/_generated/configRegistry.json +0 -2
- package/src/forge/_generated/configRegistry.ts +0 -4
- package/src/forge/_generated/dataGraph.json +0 -2
- package/src/forge/_generated/dataGraph.ts +0 -8
- package/src/forge/_generated/db.json +0 -2
- package/src/forge/_generated/db.ts +0 -2
- package/src/forge/_generated/dbSecurityManifest.json +0 -2
- package/src/forge/_generated/dbSecurityManifest.ts +0 -15
- package/src/forge/_generated/dbSessionContext.json +0 -2
- package/src/forge/_generated/dbSessionContext.ts +0 -39
- package/src/forge/_generated/deployManifest.json +0 -2
- package/src/forge/_generated/deployManifest.ts +0 -14
- package/src/forge/_generated/devManifest.json +0 -2
- package/src/forge/_generated/devManifest.ts +0 -62
- package/src/forge/_generated/envSchema.json +0 -2
- package/src/forge/_generated/envSchema.ts +0 -59
- package/src/forge/_generated/frontendGraph.json +0 -2
- package/src/forge/_generated/frontendGraph.ts +0 -27
- package/src/forge/_generated/importGuards.json +0 -2
- package/src/forge/_generated/importGuards.ts +0 -686
- package/src/forge/_generated/index.ts +0 -68
- package/src/forge/_generated/liveProductionManifest.json +0 -2
- package/src/forge/_generated/liveProductionManifest.ts +0 -23
- package/src/forge/_generated/liveProtocol.json +0 -2
- package/src/forge/_generated/liveProtocol.ts +0 -21
- package/src/forge/_generated/liveQueryRegistry.json +0 -2
- package/src/forge/_generated/liveQueryRegistry.ts +0 -9
- package/src/forge/_generated/liveTransportConfig.json +0 -2
- package/src/forge/_generated/liveTransportConfig.ts +0 -19
- package/src/forge/_generated/makeRegistry.json +0 -2
- package/src/forge/_generated/makeRegistry.ts +0 -177
- package/src/forge/_generated/makeTemplates.json +0 -2
- package/src/forge/_generated/makeTemplates.ts +0 -66
- package/src/forge/_generated/mockMap.json +0 -2
- package/src/forge/_generated/mockMap.ts +0 -7
- package/src/forge/_generated/operationPlaybooks.md +0 -167
- package/src/forge/_generated/packageGraph.json +0 -2
- package/src/forge/_generated/packageGraph.ts +0 -249334
- package/src/forge/_generated/packageUpgradeRegistry.json +0 -2
- package/src/forge/_generated/packageUpgradeRegistry.ts +0 -15
- package/src/forge/_generated/permissionMatrix.json +0 -2
- package/src/forge/_generated/permissionMatrix.ts +0 -7
- package/src/forge/_generated/policyRegistry.json +0 -2
- package/src/forge/_generated/policyRegistry.ts +0 -11
- package/src/forge/_generated/queryRegistry.json +0 -2
- package/src/forge/_generated/queryRegistry.ts +0 -9
- package/src/forge/_generated/react.d.ts +0 -22
- package/src/forge/_generated/react.ts +0 -29
- package/src/forge/_generated/reactManifest.json +0 -2
- package/src/forge/_generated/reactManifest.ts +0 -19
- package/src/forge/_generated/rlsPolicies.json +0 -2
- package/src/forge/_generated/rlsPolicies.sql +0 -34
- package/src/forge/_generated/rlsPolicies.ts +0 -6
- package/src/forge/_generated/runtimeGraph.json +0 -2
- package/src/forge/_generated/runtimeGraph.ts +0 -8
- package/src/forge/_generated/runtimeMatrix.json +0 -2
- package/src/forge/_generated/runtimeMatrix.ts +0 -334130
- package/src/forge/_generated/runtimeRegistry.ts +0 -2
- package/src/forge/_generated/runtimeRules.md +0 -91
- package/src/forge/_generated/secretRegistry.json +0 -2
- package/src/forge/_generated/secretRegistry.ts +0 -50
- package/src/forge/_generated/secretsContext.ts +0 -11
- package/src/forge/_generated/serverApi.ts +0 -10
- package/src/forge/_generated/sourceMapManifest.json +0 -2
- package/src/forge/_generated/sourceMapManifest.ts +0 -7
- package/src/forge/_generated/sqlPlan.json +0 -2
- package/src/forge/_generated/sqlPlan.ts +0 -88
- package/src/forge/_generated/subscriptionManifest.json +0 -2
- package/src/forge/_generated/subscriptionManifest.ts +0 -7
- package/src/forge/_generated/symbolicationManifest.json +0 -2
- package/src/forge/_generated/symbolicationManifest.ts +0 -17
- package/src/forge/_generated/telemetryRegistry.json +0 -2
- package/src/forge/_generated/telemetryRegistry.ts +0 -9
- package/src/forge/_generated/telemetrySinks.json +0 -2
- package/src/forge/_generated/telemetrySinks.ts +0 -11
- package/src/forge/_generated/tenantScope.json +0 -2
- package/src/forge/_generated/tenantScope.ts +0 -8
- package/src/forge/_generated/testGraph.json +0 -2
- package/src/forge/_generated/testGraph.ts +0 -3452
- package/src/forge/_generated/testPlanRegistry.json +0 -2
- package/src/forge/_generated/testPlanRegistry.ts +0 -33
- package/src/forge/_generated/uiRoutes.json +0 -2
- package/src/forge/_generated/uiRoutes.ts +0 -16
- package/src/forge/_generated/uiScenarios.json +0 -2
- package/src/forge/_generated/uiScenarios.ts +0 -30
- package/src/forge/_generated/uiTestManifest.json +0 -2
- package/src/forge/_generated/uiTestManifest.ts +0 -27
- package/src/forge/_generated/workflowRegistry.json +0 -2
- package/src/forge/_generated/workflowRegistry.ts +0 -9
- package/src/forge/_generated/workflowSubscriptions.json +0 -2
- package/src/forge/_generated/workflowSubscriptions.ts +0 -10
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { AdapterResult, AnalysisSource, RepositoryNode } from "../types.ts";
|
|
3
|
+
import { emptyResult, evidence, makeEdge, makeNode, staticHttpPath } from "./common.ts";
|
|
4
|
+
|
|
5
|
+
/** Parses JS/TS with the bundled compiler; resolves lexical references without loading libraries/dependencies. */
|
|
6
|
+
export function analyzeTypeScript(source: AnalysisSource, scriptText = source.text, offset = 0, scriptLanguage?: string): AdapterResult {
|
|
7
|
+
const result = emptyResult();
|
|
8
|
+
const filename = source.path.endsWith(".vue") ? `${source.path}.${scriptLanguage ?? "js"}` : source.path;
|
|
9
|
+
const kind = filename.endsWith(".tsx") ? ts.ScriptKind.TSX : filename.endsWith(".jsx") ? ts.ScriptKind.JSX : /\.[cm]?js$/.test(filename) ? ts.ScriptKind.JS : ts.ScriptKind.TS;
|
|
10
|
+
const sourceFile = ts.createSourceFile(filename, scriptText, ts.ScriptTarget.Latest, true, kind);
|
|
11
|
+
const options: ts.CompilerOptions = { noLib: true, noResolve: true, allowJs: true, target: ts.ScriptTarget.Latest, module: ts.ModuleKind.ESNext };
|
|
12
|
+
const host: ts.CompilerHost = {
|
|
13
|
+
getSourceFile: (path) => path === filename ? sourceFile : undefined,
|
|
14
|
+
getDefaultLibFileName: () => "", writeFile: () => undefined,
|
|
15
|
+
getCurrentDirectory: () => "/", getDirectories: () => [],
|
|
16
|
+
fileExists: (path) => path === filename, readFile: (path) => path === filename ? scriptText : undefined,
|
|
17
|
+
getCanonicalFileName: (path) => path, useCaseSensitiveFileNames: () => true, getNewLine: () => "\n",
|
|
18
|
+
};
|
|
19
|
+
const program = ts.createProgram([filename], options, host);
|
|
20
|
+
const checker = program.getTypeChecker();
|
|
21
|
+
for (const diagnostic of program.getSyntacticDiagnostics(sourceFile)) result.diagnostics.push({ code: "REPOSITORY_TS_PARSE", severity: "error", file: source.path, message: ts.flattenDiagnosticMessageText(diagnostic.messageText, " ") });
|
|
22
|
+
const declarations = new Map<ts.Symbol, RepositoryNode>();
|
|
23
|
+
const owners = new Map<ts.Node, RepositoryNode>();
|
|
24
|
+
const importBindings = new Map<string, { node: RepositoryNode; imported: string }>();
|
|
25
|
+
const scopeName = (node: ts.Node): string => {
|
|
26
|
+
const parts: string[] = [];
|
|
27
|
+
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
28
|
+
if ((ts.isClassDeclaration(parent) || ts.isFunctionDeclaration(parent) || ts.isMethodDeclaration(parent)) && parent.name) parts.unshift(parent.name.getText(sourceFile));
|
|
29
|
+
}
|
|
30
|
+
return parts.join(".");
|
|
31
|
+
};
|
|
32
|
+
const addDeclaration = (node: ts.Node, name: ts.Identifier | ts.StringLiteral, kind: string) => {
|
|
33
|
+
const scope = scopeName(node);
|
|
34
|
+
const qualified = scope ? `${scope}.${name.text}` : name.text;
|
|
35
|
+
const symbol = checker.getSymbolAtLocation(name);
|
|
36
|
+
const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
|
|
37
|
+
const repositoryNode = makeNode(source, "symbol", name.text, offset + node.getStart(sourceFile), offset + node.end, { symbolKind: kind, qualifiedName: qualified, exported: modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) || ts.isVariableDeclaration(node) && ts.isVariableDeclarationList(node.parent) && ts.isVariableStatement(node.parent.parent) && ts.getModifiers(node.parent.parent)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) || false, defaultExport: modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) || false }, `${qualified}:${kind}:${offset + node.pos}`);
|
|
38
|
+
// Position is only a disambiguator for repeated declarations; edits never alias a different symbol silently.
|
|
39
|
+
if (symbol) declarations.set(symbol, repositoryNode);
|
|
40
|
+
owners.set(node, repositoryNode);
|
|
41
|
+
result.nodes.push(repositoryNode);
|
|
42
|
+
};
|
|
43
|
+
const visitDeclarations = (node: ts.Node) => {
|
|
44
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
45
|
+
const bindings: { local: string; imported: string }[] = [];
|
|
46
|
+
if (node.importClause?.name) bindings.push({ local: node.importClause.name.text, imported: "default" });
|
|
47
|
+
const named = node.importClause?.namedBindings;
|
|
48
|
+
if (named && ts.isNamedImports(named)) for (const item of named.elements) bindings.push({ local: item.name.text, imported: item.propertyName?.text ?? item.name.text });
|
|
49
|
+
if (named && ts.isNamespaceImport(named)) bindings.push({ local: named.name.text, imported: "*" });
|
|
50
|
+
const repositoryNode = makeNode(source, "import", node.moduleSpecifier.text, offset + node.getStart(sourceFile), offset + node.end, { specifier: node.moduleSpecifier.text, bindings }, `import:${offset + node.pos}:${node.moduleSpecifier.text}`);
|
|
51
|
+
result.nodes.push(repositoryNode);
|
|
52
|
+
for (const binding of bindings) importBindings.set(binding.local, { node: repositoryNode, imported: binding.imported });
|
|
53
|
+
}
|
|
54
|
+
if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isEnumDeclaration(node)) && node.name) addDeclaration(node, node.name, ts.SyntaxKind[node.kind]);
|
|
55
|
+
else if ((ts.isVariableDeclaration(node) || ts.isMethodDeclaration(node)) && node.name && (ts.isIdentifier(node.name) || ts.isStringLiteral(node.name))) addDeclaration(node, node.name, ts.SyntaxKind[node.kind]);
|
|
56
|
+
ts.forEachChild(node, visitDeclarations);
|
|
57
|
+
};
|
|
58
|
+
visitDeclarations(sourceFile);
|
|
59
|
+
const ownerOf = (node: ts.Node): RepositoryNode | undefined => {
|
|
60
|
+
for (let current: ts.Node | undefined = node; current; current = current.parent) if (owners.has(current)) return owners.get(current);
|
|
61
|
+
return undefined;
|
|
62
|
+
};
|
|
63
|
+
// Initializer variables (for example `response = await api.get(...)`) are not callables.
|
|
64
|
+
const callableOwnerOf = (node: ts.Node): RepositoryNode | undefined => {
|
|
65
|
+
for (let current: ts.Node | undefined = node; current; current = current.parent) {
|
|
66
|
+
if (ts.isFunctionDeclaration(current) || ts.isMethodDeclaration(current)) return owners.get(current);
|
|
67
|
+
if (ts.isArrowFunction(current) || ts.isFunctionExpression(current)) {
|
|
68
|
+
let wrapped: ts.Node = current;
|
|
69
|
+
while (wrapped.parent && (ts.isParenthesizedExpression(wrapped.parent) || ts.isAsExpression(wrapped.parent) || ts.isSatisfiesExpression(wrapped.parent))) wrapped = wrapped.parent;
|
|
70
|
+
return ts.isVariableDeclaration(wrapped.parent) && wrapped.parent.initializer === wrapped ? owners.get(wrapped.parent) : undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return ownerOf(node);
|
|
74
|
+
};
|
|
75
|
+
const literal = (node: ts.Node | undefined) => node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : undefined;
|
|
76
|
+
type Scalar = string | number | boolean;
|
|
77
|
+
const mutatedObjects = new Set<ts.Symbol>();
|
|
78
|
+
const collectMutations = (node: ts.Node) => {
|
|
79
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && node.operatorToken.kind <= ts.SyntaxKind.LastAssignment) {
|
|
80
|
+
const target = node.left;
|
|
81
|
+
if (ts.isPropertyAccessExpression(target) || ts.isElementAccessExpression(target)) { const symbol = checker.getSymbolAtLocation(target.expression); if (symbol) mutatedObjects.add(symbol); }
|
|
82
|
+
}
|
|
83
|
+
ts.forEachChild(node, collectMutations);
|
|
84
|
+
};
|
|
85
|
+
collectMutations(sourceFile);
|
|
86
|
+
const unwrapped = (expression: ts.Expression): ts.Expression => {
|
|
87
|
+
while (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isTypeAssertionExpression(expression) || ts.isAwaitExpression(expression)) expression = expression.expression;
|
|
88
|
+
return expression;
|
|
89
|
+
};
|
|
90
|
+
const constant = (expression: ts.Expression | undefined, parameters = new Map<ts.Symbol, Scalar>(), seen = new Set<ts.Symbol>(), depth = 0): Scalar | undefined => {
|
|
91
|
+
if (!expression || depth > 20) return undefined;
|
|
92
|
+
expression = unwrapped(expression);
|
|
93
|
+
if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) return expression.text;
|
|
94
|
+
if (ts.isNumericLiteral(expression)) return Number(expression.text);
|
|
95
|
+
if (expression.kind === ts.SyntaxKind.TrueKeyword || expression.kind === ts.SyntaxKind.FalseKeyword) return expression.kind === ts.SyntaxKind.TrueKeyword;
|
|
96
|
+
if (ts.isIdentifier(expression)) {
|
|
97
|
+
if (/(?:password|secret|credential|authorization|token)/i.test(expression.text)) return undefined;
|
|
98
|
+
const symbol = checker.getSymbolAtLocation(expression);
|
|
99
|
+
if (!symbol || seen.has(symbol)) return undefined;
|
|
100
|
+
if (parameters.has(symbol)) return parameters.get(symbol);
|
|
101
|
+
const declaration = symbol.valueDeclaration;
|
|
102
|
+
if (!declaration || !ts.isVariableDeclaration(declaration) || !ts.isVariableDeclarationList(declaration.parent) || !(declaration.parent.flags & ts.NodeFlags.Const)) return undefined;
|
|
103
|
+
const next = new Set(seen); next.add(symbol);
|
|
104
|
+
return constant(declaration.initializer, parameters, next, depth + 1);
|
|
105
|
+
}
|
|
106
|
+
if (ts.isTemplateExpression(expression)) {
|
|
107
|
+
let value = expression.head.text;
|
|
108
|
+
for (const span of expression.templateSpans) { const part = constant(span.expression, parameters, seen, depth + 1); if (part === undefined) return undefined; value += String(part) + span.literal.text; }
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
if (ts.isBinaryExpression(expression) && expression.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
112
|
+
const left = constant(expression.left, parameters, seen, depth + 1); const right = constant(expression.right, parameters, seen, depth + 1);
|
|
113
|
+
if (left === undefined || right === undefined) return undefined;
|
|
114
|
+
return typeof left === "number" && typeof right === "number" ? left + right : String(left) + String(right);
|
|
115
|
+
}
|
|
116
|
+
if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression) && !/(?:password|secret|credential|authorization|token)/i.test(expression.name.text)) {
|
|
117
|
+
const symbol = checker.getSymbolAtLocation(expression.expression); const declaration = symbol?.valueDeclaration;
|
|
118
|
+
if (symbol && mutatedObjects.has(symbol)) return undefined;
|
|
119
|
+
if (declaration && ts.isVariableDeclaration(declaration) && ts.isVariableDeclarationList(declaration.parent) && declaration.parent.flags & ts.NodeFlags.Const && declaration.initializer && ts.isObjectLiteralExpression(unwrapped(declaration.initializer))) {
|
|
120
|
+
const value = unwrapped(declaration.initializer) as ts.ObjectLiteralExpression;
|
|
121
|
+
const property = value.properties.find((item) => ts.isPropertyAssignment(item) && item.name.getText(sourceFile).replace(/["']/g, "") === expression.name.text);
|
|
122
|
+
if (property && ts.isPropertyAssignment(property)) return constant(property.initializer, parameters, seen, depth + 1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
};
|
|
127
|
+
const staticString = (expression: ts.Expression | undefined, parameters?: Map<ts.Symbol, Scalar>): string | undefined => { const value = constant(expression, parameters); return value === undefined ? undefined : String(value); };
|
|
128
|
+
const segmentPathPattern = (expression: ts.Expression | undefined): { requestPathPattern: string; requestPatternParameters: { name: string; kind: string }[] } | undefined => {
|
|
129
|
+
if (!expression) return undefined;
|
|
130
|
+
expression = unwrapped(expression);
|
|
131
|
+
if (!ts.isTemplateExpression(expression) || !/^\/(?!\/)/.test(expression.head.text) || expression.templateSpans.length > 8) return undefined;
|
|
132
|
+
let path = expression.head.text;
|
|
133
|
+
const parameters: { name: string; kind: string }[] = [];
|
|
134
|
+
for (const span of expression.templateSpans) {
|
|
135
|
+
if (!path.endsWith("/") || span.literal.text && !span.literal.text.startsWith("/")) return undefined;
|
|
136
|
+
const value = constant(span.expression);
|
|
137
|
+
if (value !== undefined) { if (!/^[A-Za-z0-9_~-]+$/.test(String(value))) return undefined; path += String(value) + span.literal.text; continue; }
|
|
138
|
+
let parameter = unwrapped(span.expression); let encoded = false;
|
|
139
|
+
if (ts.isCallExpression(parameter) && ts.isIdentifier(parameter.expression) && parameter.expression.text === "encodeURIComponent" && !checker.getSymbolAtLocation(parameter.expression) && parameter.arguments.length === 1) { parameter = unwrapped(parameter.arguments[0]); encoded = true; }
|
|
140
|
+
if (!ts.isIdentifier(parameter) || /(?:password|secret|credential|authorization|token)/i.test(parameter.text)) return undefined;
|
|
141
|
+
const declaration = checker.getSymbolAtLocation(parameter)?.valueDeclaration;
|
|
142
|
+
if (!declaration || !ts.isParameter(declaration) || declaration.type?.kind !== ts.SyntaxKind.NumberKeyword && !(encoded && declaration.type?.kind === ts.SyntaxKind.StringKeyword)) return undefined;
|
|
143
|
+
parameters.push({ name: parameter.text, kind: declaration.type?.kind === ts.SyntaxKind.NumberKeyword ? "number" : "encoded-string" });
|
|
144
|
+
path += `{${parameter.text}}${span.literal.text}`;
|
|
145
|
+
}
|
|
146
|
+
if (!parameters.length || path.length > 2048 || /[?#\\%]|\/\//.test(path) || path.split("/").some((segment) => segment === "." || segment === ".." || segment && !/^(?:[A-Za-z0-9_.~-]+|\{[A-Za-z_$][\w$]*\})$/.test(segment))) return undefined;
|
|
147
|
+
return { requestPathPattern: path, requestPatternParameters: parameters };
|
|
148
|
+
};
|
|
149
|
+
const staticObject = (expression: ts.Expression | undefined): ts.ObjectLiteralExpression | undefined => {
|
|
150
|
+
if (!expression) return undefined; expression = unwrapped(expression);
|
|
151
|
+
if (ts.isObjectLiteralExpression(expression)) return expression;
|
|
152
|
+
if (ts.isIdentifier(expression)) {
|
|
153
|
+
const symbol = checker.getSymbolAtLocation(expression); const declaration = symbol?.valueDeclaration;
|
|
154
|
+
if (symbol && !mutatedObjects.has(symbol) && declaration && ts.isVariableDeclaration(declaration) && ts.isVariableDeclarationList(declaration.parent) && declaration.parent.flags & ts.NodeFlags.Const && declaration.initializer) { const value = unwrapped(declaration.initializer); if (ts.isObjectLiteralExpression(value)) return value; }
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
};
|
|
158
|
+
const propertyValue = (object: ts.Expression | undefined, name: string): ts.Expression | undefined => {
|
|
159
|
+
const value = staticObject(object); if (!value) return undefined;
|
|
160
|
+
for (const item of [...value.properties].reverse()) {
|
|
161
|
+
if (ts.isSpreadAssignment(item)) return undefined;
|
|
162
|
+
if (ts.isPropertyAssignment(item) && item.name.getText(sourceFile).replace(/["']/g, "") === name) return item.initializer;
|
|
163
|
+
if (ts.isShorthandPropertyAssignment(item) && item.name.text === name) return item.name;
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
};
|
|
167
|
+
const urlMetadata = (url: string | undefined, base?: string) => {
|
|
168
|
+
const absolute = url !== undefined && /^(?:https?:)?\/\//.test(url);
|
|
169
|
+
const combined = url === undefined ? undefined : !absolute && base ? `${base.replace(/\/$/, "")}/${url.replace(/^\//, "")}` : url;
|
|
170
|
+
const path = combined !== undefined ? staticHttpPath(combined) : undefined;
|
|
171
|
+
let origin: string | undefined;
|
|
172
|
+
if (combined && /^https?:\/\//.test(combined)) { try { origin = new URL(combined).origin; } catch { /* unresolved invalid URL */ } }
|
|
173
|
+
return { path, origin, requestPath: url !== undefined ? staticHttpPath(url) : undefined, requestAbsolute: absolute };
|
|
174
|
+
};
|
|
175
|
+
interface Client { node: RepositoryNode; baseURL?: string; baseKnown: boolean }
|
|
176
|
+
const clients = new Map<ts.Symbol, Client>();
|
|
177
|
+
const builtinName = (expression: ts.Expression): string | undefined => {
|
|
178
|
+
if (!ts.isIdentifier(expression)) return undefined;
|
|
179
|
+
const imported = importBindings.get(expression.text);
|
|
180
|
+
if (imported && ["axios", "ofetch"].includes(imported.node.name)) return imported.node.name === "axios" ? "axios" : "$fetch";
|
|
181
|
+
const symbol = checker.getSymbolAtLocation(expression);
|
|
182
|
+
return !symbol && ["fetch", "$fetch", "useFetch", "axios", "ofetch"].includes(expression.text) ? expression.text : undefined;
|
|
183
|
+
};
|
|
184
|
+
const collectClients = (node: ts.Node) => {
|
|
185
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && ts.isCallExpression(unwrapped(node.initializer))) {
|
|
186
|
+
const factory = unwrapped(node.initializer) as ts.CallExpression;
|
|
187
|
+
if (ts.isPropertyAccessExpression(factory.expression) && factory.expression.name.text === "create" && builtinName(factory.expression.expression)) {
|
|
188
|
+
const baseExpression = propertyValue(factory.arguments[0], "baseURL");
|
|
189
|
+
const baseURL = staticString(baseExpression);
|
|
190
|
+
const options = staticObject(factory.arguments[0]);
|
|
191
|
+
const baseKnown = !factory.arguments[0] || !!options && (baseExpression ? baseURL !== undefined : !options.properties.some((property) => ts.isSpreadAssignment(property)));
|
|
192
|
+
const symbol = checker.getSymbolAtLocation(node.name);
|
|
193
|
+
const model = makeNode(source, "http-client", node.name.text, offset + node.getStart(sourceFile), offset + node.end, { clientId: node.name.text, baseKnown, ...urlMetadata("", baseURL), exported: symbol ? declarations.get(symbol)?.metadata.exported : false, factory: builtinName(factory.expression.expression) }, `client:${offset + node.pos}`);
|
|
194
|
+
result.nodes.push(model);
|
|
195
|
+
if (symbol) clients.set(symbol, { node: model, baseURL, baseKnown });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
ts.forEachChild(node, collectClients);
|
|
199
|
+
};
|
|
200
|
+
collectClients(sourceFile);
|
|
201
|
+
interface Request { method: string; url?: string; clientId: string; confidence: string; client?: Client; clientImportId?: string; baseURL?: string; baseKnown: boolean }
|
|
202
|
+
const request = (node: ts.CallExpression, parameters?: Map<ts.Symbol, Scalar>): Request | undefined => {
|
|
203
|
+
const expression = node.expression;
|
|
204
|
+
if (ts.isPropertyAccessExpression(expression) && /^(get|post|put|patch|delete|head|options)$/i.test(expression.name.text) && ts.isIdentifier(expression.expression)) {
|
|
205
|
+
const receiver = expression.expression;
|
|
206
|
+
const symbol = checker.getSymbolAtLocation(receiver); const client = symbol ? clients.get(symbol) : undefined;
|
|
207
|
+
const imported = importBindings.get(receiver.text);
|
|
208
|
+
const builtin = builtinName(receiver);
|
|
209
|
+
const binding = symbol?.valueDeclaration;
|
|
210
|
+
const declaration = binding && ts.isBindingElement(binding) && ts.isObjectBindingPattern(binding.parent) && ts.isVariableDeclaration(binding.parent.parent) ? binding.parent.parent : undefined;
|
|
211
|
+
const initializer = declaration?.initializer && unwrapped(declaration.initializer);
|
|
212
|
+
const nuxtProvided = initializer && ts.isCallExpression(initializer) && ts.isIdentifier(initializer.expression) && initializer.expression.text === "useNuxtApp" && !checker.getSymbolAtLocation(initializer.expression);
|
|
213
|
+
if (!client && !imported && !builtin && !nuxtProvided && !/^(?:\$?api|http|client)$/.test(receiver.text)) return undefined;
|
|
214
|
+
const options = node.arguments[["post", "put", "patch"].includes(expression.name.text.toLowerCase()) ? 2 : 1];
|
|
215
|
+
const baseExpression = propertyValue(options, "baseURL"); const baseURL = staticString(baseExpression, parameters) ?? client?.baseURL;
|
|
216
|
+
return { method: expression.name.text.toUpperCase(), url: staticString(node.arguments[0], parameters), clientId: receiver.text, confidence: client ? "factory" : builtin ? "builtin" : "candidate", client, clientImportId: imported?.node.id, baseURL, baseKnown: baseExpression ? staticString(baseExpression, parameters) !== undefined : client?.baseKnown ?? !!builtin };
|
|
217
|
+
}
|
|
218
|
+
if (ts.isIdentifier(expression)) {
|
|
219
|
+
const symbol = checker.getSymbolAtLocation(expression); const client = symbol ? clients.get(symbol) : undefined;
|
|
220
|
+
const builtin = builtinName(expression);
|
|
221
|
+
if (!client && !builtin) return undefined;
|
|
222
|
+
const options = node.arguments[1];
|
|
223
|
+
const baseExpression = builtin === "fetch" ? undefined : propertyValue(options, "baseURL"); const methodExpression = propertyValue(options, "method");
|
|
224
|
+
const method = methodExpression ? staticString(methodExpression, parameters)?.toUpperCase() ?? "UNKNOWN" : "GET";
|
|
225
|
+
const baseURL = staticString(baseExpression, parameters) ?? client?.baseURL;
|
|
226
|
+
const url = staticString(node.arguments[0], parameters);
|
|
227
|
+
const documentRelative = url !== undefined && !/^(?:\/|https?:\/\/)/.test(url) && !baseURL;
|
|
228
|
+
return { method, url, clientId: expression.text, confidence: client ? "factory" : "builtin", client, baseURL, baseKnown: !documentRelative && (baseExpression ? staticString(baseExpression, parameters) !== undefined : client?.baseKnown ?? true) };
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
};
|
|
232
|
+
const wrappers = new Map<ts.Symbol, { method: string; urlTemplate: string; parameterIndex: number; baseURL?: string; baseKnown: boolean; clientId: string }>();
|
|
233
|
+
const collectWrappers = (node: ts.Node) => {
|
|
234
|
+
let callable: ts.FunctionDeclaration | ts.ArrowFunction | ts.FunctionExpression | undefined; let symbol: ts.Symbol | undefined;
|
|
235
|
+
if (ts.isFunctionDeclaration(node) && node.name) { callable = node; symbol = checker.getSymbolAtLocation(node.name); }
|
|
236
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && (ts.isArrowFunction(unwrapped(node.initializer)) || ts.isFunctionExpression(unwrapped(node.initializer)))) { callable = unwrapped(node.initializer) as ts.ArrowFunction | ts.FunctionExpression; symbol = checker.getSymbolAtLocation(node.name); }
|
|
237
|
+
if (callable && symbol && callable.body) {
|
|
238
|
+
const body = callable.body;
|
|
239
|
+
const returns = ts.isBlock(body) ? body.statements.filter((statement): statement is ts.ReturnStatement => ts.isReturnStatement(statement)) : [];
|
|
240
|
+
const returned = ts.isBlock(body) ? returns.length === 1 && body.statements.every((statement) => ts.isReturnStatement(statement) || ts.isVariableStatement(statement)) ? returns[0].expression : undefined : body;
|
|
241
|
+
const expression = returned && unwrapped(returned);
|
|
242
|
+
if (expression && ts.isCallExpression(expression)) {
|
|
243
|
+
const params = new Map<ts.Symbol, Scalar>();
|
|
244
|
+
callable.parameters.forEach((parameter, index) => { if (ts.isIdentifier(parameter.name)) { const bound = checker.getSymbolAtLocation(parameter.name); if (bound) params.set(bound, `__FORGE_URL_PARAM_${index}__`); } });
|
|
245
|
+
const model = request(expression, params);
|
|
246
|
+
const tokens = model?.url?.match(/__FORGE_URL_PARAM_\d+__/g);
|
|
247
|
+
if (model?.url && tokens?.length === 1 && model.confidence !== "candidate" && model.method !== "UNKNOWN") {
|
|
248
|
+
const wrapper = { method: model.method, urlTemplate: model.url, parameterIndex: Number(/\d+/.exec(tokens[0])![0]), baseURL: model.baseURL, baseKnown: model.baseKnown, clientId: model.clientId };
|
|
249
|
+
wrappers.set(symbol, wrapper);
|
|
250
|
+
const safeTemplate = staticHttpPath(model.url);
|
|
251
|
+
const declaration = declarations.get(symbol); if (declaration && safeTemplate?.includes(tokens[0])) declaration.metadata.httpWrapper = { ...wrapper, urlTemplate: safeTemplate, baseURL: undefined, ...urlMetadata("", model.baseURL), origin: urlMetadata(model.url, model.baseURL).origin };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
ts.forEachChild(node, collectWrappers);
|
|
256
|
+
};
|
|
257
|
+
collectWrappers(sourceFile);
|
|
258
|
+
const visit = (node: ts.Node) => {
|
|
259
|
+
if (ts.isIdentifier(node)) {
|
|
260
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
261
|
+
const target = symbol ? declarations.get(symbol) : undefined;
|
|
262
|
+
const parent = node.parent;
|
|
263
|
+
const declarationName = (ts.isDeclarationStatement(parent) || ts.isVariableDeclaration(parent) || ts.isMethodDeclaration(parent) || ts.isParameter(parent)) && "name" in parent && parent.name === node;
|
|
264
|
+
if (target && !declarationName && !ts.isImportSpecifier(parent) && !ts.isImportClause(parent)) {
|
|
265
|
+
const owner = ts.isCallExpression(parent) && parent.expression === node ? callableOwnerOf(node) : ownerOf(node);
|
|
266
|
+
const edge = makeEdge(owner ?? makeNode(source, "file", source.path), target, ts.isCallExpression(parent) && parent.expression === node ? "calls" : "references", evidence(source, "resolved", "complete"), { binding: "lexical", offset: offset + node.getStart(sourceFile) });
|
|
267
|
+
result.edges.push(edge);
|
|
268
|
+
}
|
|
269
|
+
const imported = importBindings.get(node.text);
|
|
270
|
+
if (imported && symbol?.declarations?.some((declaration) => ts.isImportSpecifier(declaration) || ts.isImportClause(declaration) || ts.isNamespaceImport(declaration)) && !ts.isImportSpecifier(parent) && !ts.isImportClause(parent) && !ts.isNamespaceImport(parent)) {
|
|
271
|
+
const invocation = ts.isCallExpression(parent) && parent.expression === node ? parent : imported.imported === "*" && ts.isPropertyAccessExpression(parent) && parent.expression === node && ts.isCallExpression(parent.parent) && parent.parent.expression === parent ? parent.parent : undefined;
|
|
272
|
+
const call = !!invocation;
|
|
273
|
+
const argument = invocation ? staticString(invocation.arguments[0]) : undefined;
|
|
274
|
+
const argumentPaths = invocation ? invocation.arguments.map((argument) => { const value = staticString(argument); return value && /^(?:\/|https?:\/\/)/.test(value) ? staticHttpPath(value) : undefined; }) : undefined;
|
|
275
|
+
const reference = makeNode(source, "import-reference", node.text, offset + node.getStart(sourceFile), offset + node.end, { importId: imported.node.id, imported: imported.imported === "*" && ts.isPropertyAccessExpression(parent) ? parent.name.text : imported.imported, namespace: imported.imported === "*", owner: (call ? callableOwnerOf(node) : ownerOf(node))?.id, call, argumentPaths, ...(argument ? { argumentPath: staticHttpPath(argument), argumentAbsolute: /^(?:https?:)?\/\//.test(argument) } : {}) }, `import-reference:${offset + node.getStart(sourceFile)}`);
|
|
276
|
+
result.nodes.push(reference);
|
|
277
|
+
}
|
|
278
|
+
if (!symbol && ts.isCallExpression(parent) && parent.expression === node && !builtinName(node)) {
|
|
279
|
+
const argument = staticString(parent.arguments[0]);
|
|
280
|
+
const argumentPaths = parent.arguments.map((argument) => { const value = staticString(argument); return value && /^(?:\/|https?:\/\/)/.test(value) ? staticHttpPath(value) : undefined; });
|
|
281
|
+
result.nodes.push(makeNode(source, "unresolved-reference", node.text, offset + node.getStart(sourceFile), offset + node.end, { owner: callableOwnerOf(node)?.id, call: true, argumentPaths, ...(argument ? { argumentPath: staticHttpPath(argument), argumentAbsolute: /^(?:https?:)?\/\//.test(argument) } : {}) }, `unresolved-reference:${offset + node.getStart(sourceFile)}`));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (ts.isCallExpression(node)) {
|
|
285
|
+
const expression = node.expression;
|
|
286
|
+
const functionName = expression.getText(sourceFile);
|
|
287
|
+
let model = request(node);
|
|
288
|
+
if (!model && ts.isIdentifier(expression)) {
|
|
289
|
+
const symbol = checker.getSymbolAtLocation(expression); const wrapper = symbol && wrappers.get(symbol);
|
|
290
|
+
const argument = wrapper && staticString(node.arguments[wrapper.parameterIndex]);
|
|
291
|
+
if (wrapper && argument !== undefined) model = { method: wrapper.method, url: wrapper.urlTemplate.replace(`__FORGE_URL_PARAM_${wrapper.parameterIndex}__`, argument), clientId: expression.text, confidence: "wrapper", baseURL: wrapper.baseURL, baseKnown: wrapper.baseKnown };
|
|
292
|
+
}
|
|
293
|
+
if (model) {
|
|
294
|
+
const info = urlMetadata(model.url, model.baseURL);
|
|
295
|
+
const pattern = model.url === undefined ? segmentPathPattern(node.arguments[0]) : undefined;
|
|
296
|
+
const call = makeNode(source, "http-call", `${model.method} ${info.path ?? "<dynamic>"}`, offset + node.getStart(sourceFile), offset + node.end, { method: model.method, ...info, ...pattern, ...(pattern ? { origin: urlMetadata("", model.baseURL).origin } : {}), clientId: model.clientId, clientConfidence: model.confidence, clientModelId: model.client?.node.id, clientImportId: model.clientImportId, baseKnown: model.baseKnown, basePath: model.baseURL ? urlMetadata("", model.baseURL).path : undefined }, `http:${offset + node.pos}`);
|
|
297
|
+
result.nodes.push(call);
|
|
298
|
+
const owner = callableOwnerOf(node); if (owner) result.edges.push(makeEdge(owner, call, "calls", evidence(source)));
|
|
299
|
+
if (!info.path || !model.baseKnown) result.diagnostics.push({ code: "REPOSITORY_DYNAMIC_URL", severity: "info", file: source.path, message: "HTTP URL or client base cannot be statically resolved" });
|
|
300
|
+
}
|
|
301
|
+
if (ts.isPropertyAccessExpression(expression) && /^(?:app|router)\.(get|post|put|patch|delete|head|options)$/.test(functionName)) {
|
|
302
|
+
const path = literal(node.arguments[0]);
|
|
303
|
+
if (path) result.nodes.push(makeNode(source, "endpoint", `${expression.name.text.toUpperCase()} ${path}`, offset + node.getStart(sourceFile), offset + node.end, { method: expression.name.text.toUpperCase(), path }, `endpoint:${offset + node.pos}`));
|
|
304
|
+
}
|
|
305
|
+
if (/^(?:test|it|describe)(?:\.(?:only|skip|todo))?$/.test(functionName)) {
|
|
306
|
+
const name = literal(node.arguments[0]);
|
|
307
|
+
const callback = node.arguments.find((argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
|
|
308
|
+
if (name) result.nodes.push(makeNode(source, functionName.startsWith("describe") ? "test-suite" : "test", name, offset + node.getStart(sourceFile), offset + node.end, { framework: "jest-compatible", observedCoverage: false, ...(callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) ? { testBody: { start: offset + callback.body.getStart(sourceFile), end: offset + callback.body.end } } : {}) }, `test:${offset + node.pos}`));
|
|
309
|
+
}
|
|
310
|
+
if (["defineProps", "defineEmits", "defineStore"].includes(functionName)) {
|
|
311
|
+
const names: string[] = [];
|
|
312
|
+
for (const type of node.typeArguments ?? []) if (ts.isTypeLiteralNode(type)) for (const member of type.members) if (member.name && (ts.isIdentifier(member.name) || ts.isStringLiteral(member.name))) names.push(member.name.text);
|
|
313
|
+
const argument = node.arguments[0];
|
|
314
|
+
if (argument && ts.isArrayLiteralExpression(argument)) for (const item of argument.elements) { const name = literal(item); if (name) names.push(name); }
|
|
315
|
+
if (argument && ts.isObjectLiteralExpression(argument)) for (const property of argument.properties) if (property.name && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name))) names.push(property.name.text);
|
|
316
|
+
result.nodes.push(makeNode(source, functionName === "defineStore" ? "store" : "declaration", functionName, offset + node.getStart(sourceFile), offset + node.end, { macro: functionName, names: [...new Set(names)] }, `macro:${offset + node.pos}`));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// Static Vue Router route entries; no evaluation of arbitrary JS configuration.
|
|
320
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
321
|
+
const provide = propertyValue(node, "provide");
|
|
322
|
+
if (provide && ts.isObjectLiteralExpression(provide)) for (const property of provide.properties) {
|
|
323
|
+
const variable = ts.isShorthandPropertyAssignment(property) ? property.name : ts.isPropertyAssignment(property) && ts.isIdentifier(property.initializer) ? property.initializer : undefined;
|
|
324
|
+
if (!variable || !property.name || !(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name))) continue;
|
|
325
|
+
const symbol = ts.isShorthandPropertyAssignment(property) ? checker.getShorthandAssignmentValueSymbol(property) : checker.getSymbolAtLocation(variable);
|
|
326
|
+
const client = symbol && clients.get(symbol);
|
|
327
|
+
if (client) client.node.metadata.providedAs = [...new Set([...(Array.isArray(client.node.metadata.providedAs) ? client.node.metadata.providedAs as string[] : []), `$${property.name.text}`])];
|
|
328
|
+
}
|
|
329
|
+
let route: string | undefined; let componentName: string | undefined;
|
|
330
|
+
for (const property of node.properties) if (ts.isPropertyAssignment(property)) {
|
|
331
|
+
if (property.name.getText(sourceFile) === "path") route = literal(property.initializer);
|
|
332
|
+
if (property.name.getText(sourceFile) === "component" && ts.isIdentifier(property.initializer)) componentName = property.initializer.text;
|
|
333
|
+
}
|
|
334
|
+
if (route && componentName) {
|
|
335
|
+
const page = makeNode(source, "page", route, offset + node.getStart(sourceFile), offset + node.end, { route, componentName }, `route:${offset + node.pos}`);
|
|
336
|
+
result.nodes.push(page);
|
|
337
|
+
const imported = importBindings.get(componentName); if (imported) result.edges.push(makeEdge(page, imported.node, "routes-to", evidence(source)));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (ts.isExportAssignment(node) && ts.isIdentifier(node.expression)) {
|
|
341
|
+
const symbol = checker.getSymbolAtLocation(node.expression); const declaration = symbol && declarations.get(symbol); const client = symbol && clients.get(symbol);
|
|
342
|
+
if (declaration) { declaration.metadata.defaultExport = true; declaration.metadata.exported = true; }
|
|
343
|
+
if (client) { client.node.metadata.defaultExport = true; client.node.metadata.exported = true; }
|
|
344
|
+
}
|
|
345
|
+
ts.forEachChild(node, visit);
|
|
346
|
+
};
|
|
347
|
+
visit(sourceFile);
|
|
348
|
+
result.limitations.push("TypeScript: lexical bindings are resolved; package types, dynamic imports/configuration and full cross-file type semantics are not resolved");
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parse, compileTemplate } from "@vue/compiler-sfc";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
import type { AdapterResult, AnalysisSource } from "../types.ts";
|
|
4
|
+
import { emptyResult, evidence, makeEdge, makeNode } from "./common.ts";
|
|
5
|
+
import { analyzeTypeScript } from "./typescript.ts";
|
|
6
|
+
|
|
7
|
+
interface TemplateNode {
|
|
8
|
+
type: number;
|
|
9
|
+
tag?: string;
|
|
10
|
+
children?: TemplateNode[];
|
|
11
|
+
branches?: TemplateNode[];
|
|
12
|
+
props?: { type: number; name: string; arg?: { content?: string }; exp?: { content?: string }; loc?: { start: { offset: number }; end: { offset: number } } }[];
|
|
13
|
+
loc?: { start: { offset: number }; end: { offset: number } };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function analyzeVue(source: AnalysisSource): AdapterResult {
|
|
17
|
+
const result = emptyResult();
|
|
18
|
+
const parsed = parse(source.text, { filename: source.path });
|
|
19
|
+
for (const error of parsed.errors) result.diagnostics.push({ code: "REPOSITORY_VUE_PARSE", severity: "error", file: source.path, message: typeof error === "string" ? error : error.message });
|
|
20
|
+
const descriptor = parsed.descriptor;
|
|
21
|
+
const ui = makeNode(source, "ui-component", basename(source.path, ".vue"), 0, source.text.length, { framework: "vue" });
|
|
22
|
+
result.nodes.push(ui);
|
|
23
|
+
for (const block of [descriptor.script, descriptor.scriptSetup]) {
|
|
24
|
+
if (!block) continue;
|
|
25
|
+
if (block.src) {
|
|
26
|
+
result.nodes.push(makeNode(source, "import", block.src, block.loc.start.offset, block.loc.end.offset, { specifier: block.src, bindings: [] }, `external-script:${block.src}`));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (block.lang && !["ts", "tsx", "js", "jsx"].includes(block.lang)) {
|
|
30
|
+
result.diagnostics.push({ code: "REPOSITORY_VUE_SCRIPT_LANGUAGE", severity: "warning", file: source.path, message: `Unsupported script language: ${block.lang}` }); continue;
|
|
31
|
+
}
|
|
32
|
+
const analyzed = analyzeTypeScript(source, block.content, block.loc.start.offset, block.lang ?? "js");
|
|
33
|
+
result.nodes.push(...analyzed.nodes); result.edges.push(...analyzed.edges);
|
|
34
|
+
result.diagnostics.push(...analyzed.diagnostics); result.limitations.push(...analyzed.limitations);
|
|
35
|
+
for (const node of analyzed.nodes.filter((node) => ["symbol", "http-call", "store", "declaration"].includes(node.kind))) result.edges.push(makeEdge(ui, node, "contains", evidence(source)));
|
|
36
|
+
}
|
|
37
|
+
if (descriptor.template) {
|
|
38
|
+
const block = descriptor.template;
|
|
39
|
+
if (block.src) result.diagnostics.push({ code: "REPOSITORY_VUE_TEMPLATE_EXTERNAL", severity: "warning", file: source.path, message: "External template src is declared but not loaded or preprocessed by static SFC analysis" });
|
|
40
|
+
else if (block.lang && block.lang !== "html") result.diagnostics.push({ code: "REPOSITORY_VUE_TEMPLATE_LANGUAGE", severity: "warning", file: source.path, message: `Unsupported template preprocessor: ${block.lang}` });
|
|
41
|
+
else {
|
|
42
|
+
const compiled = compileTemplate({ source: block.content, filename: source.path, id: source.hash });
|
|
43
|
+
for (const error of compiled.errors) result.diagnostics.push({ code: "REPOSITORY_VUE_TEMPLATE_PARSE", severity: "error", file: source.path, message: typeof error === "string" ? error : error.message });
|
|
44
|
+
const visit = (node: TemplateNode) => {
|
|
45
|
+
if (node.type === 1 && node.tag && node.loc) {
|
|
46
|
+
const dynamic = node.tag === "component";
|
|
47
|
+
const importedComponent = result.nodes.find((candidate) => candidate.kind === "import" && Array.isArray(candidate.metadata.bindings) && (candidate.metadata.bindings as { local: string }[]).some((binding) => binding.local === node.tag || binding.local.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase() === node.tag));
|
|
48
|
+
if (importedComponent) {
|
|
49
|
+
const edge = makeEdge(ui, importedComponent, "renders", evidence(source));
|
|
50
|
+
result.edges.push(edge);
|
|
51
|
+
} else if (/^[A-Z]/.test(node.tag) || node.tag.includes("-") || dynamic) {
|
|
52
|
+
const unresolved = makeNode(source, "ui-reference", node.tag, block.loc.start.offset + node.loc.start.offset, block.loc.start.offset + node.loc.end.offset, { dynamic, autoimport: !dynamic, resolved: false }, `template:${node.loc.start.offset}`);
|
|
53
|
+
result.nodes.push(unresolved); result.edges.push(makeEdge(ui, unresolved, "renders", evidence(source, "syntactic", "unresolved")));
|
|
54
|
+
result.diagnostics.push({ code: "REPOSITORY_VUE_COMPONENT_UNRESOLVED", severity: "info", file: source.path, message: `Component '${node.tag}' has no explicit resolved import; autoimports/dynamic components remain unresolved` });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const child of node.children ?? []) visit(child);
|
|
58
|
+
for (const branch of node.branches ?? []) visit(branch);
|
|
59
|
+
};
|
|
60
|
+
if (compiled.ast) visit(compiled.ast as unknown as TemplateNode);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const pageMatch = /(?:^|\/)(?:pages|app\/pages)\/(.+)\.vue$/.exec(source.path);
|
|
64
|
+
if (pageMatch) {
|
|
65
|
+
const route = `/${pageMatch[1].replace(/(?:^|\/)index$/, "").replace(/\[([^\]]+)\]/g, ":$1")}`.replace(/\/$/, "") || "/";
|
|
66
|
+
const page = makeNode(source, "page", route, 0, source.text.length, { framework: "nuxt", route, convention: true });
|
|
67
|
+
page.evidence = evidence(source, "inferred"); result.nodes.push(page); result.edges.push(makeEdge(page, ui, "renders", evidence(source, "inferred")));
|
|
68
|
+
}
|
|
69
|
+
result.limitations.push("Vue: explicit imports, SFC blocks and HTML templates parsed; runtime component registration, Nuxt autoimports, template expression type resolution and custom preprocessors remain unresolved");
|
|
70
|
+
return result;
|
|
71
|
+
}
|