forgeos 0.1.0-alpha.0 → 0.1.0-alpha.2
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/.npmignore +9 -1
- package/AGENTS.md +6 -1
- package/CHANGELOG.md +30 -0
- package/CONTRIBUTING.md +22 -1
- package/README.md +30 -3
- package/bin/forge.mjs +4 -3
- package/package.json +3 -1
- package/packages/eslint-plugin-forge/index.ts +15 -15
- package/packages/eslint-plugin-forge/package.json +10 -10
- package/packages/eslint-plugin-forge/src/check-source.ts +95 -95
- package/packages/eslint-plugin-forge/src/load-artifacts.ts +24 -24
- package/packages/eslint-plugin-forge/src/rule-no-forge-guard-violation.ts +93 -93
- package/src/forge/_generated/actionSubscriptions.json +2 -2
- package/src/forge/_generated/actionSubscriptions.ts +3 -3
- package/src/forge/_generated/agentAdapterManifest.json +2 -2
- package/src/forge/_generated/agentAdapterManifest.ts +3 -3
- package/src/forge/_generated/agentContract.json +2 -2
- package/src/forge/_generated/agentContract.ts +6786 -2
- package/src/forge/_generated/agentQuickstart.md +1 -1
- package/src/forge/_generated/aiContext.ts +1 -1
- package/src/forge/_generated/aiModels.json +1 -1
- package/src/forge/_generated/aiModels.ts +1 -1
- package/src/forge/_generated/aiProviders.json +1 -1
- package/src/forge/_generated/aiProviders.ts +1 -1
- package/src/forge/_generated/aiRegistry.json +2 -2
- package/src/forge/_generated/aiRegistry.ts +3 -3
- package/src/forge/_generated/api.json +2 -2
- package/src/forge/_generated/api.ts +1 -1
- package/src/forge/_generated/appGraph.json +2 -2
- package/src/forge/_generated/appGraph.ts +1297 -1141
- package/src/forge/_generated/appMap.md +1 -1
- package/src/forge/_generated/artifactManifest.json +2 -2
- package/src/forge/_generated/artifactManifest.ts +2 -2
- package/src/forge/_generated/authClaims.json +1 -1
- package/src/forge/_generated/authClaims.ts +1 -1
- package/src/forge/_generated/authConfig.json +1 -1
- package/src/forge/_generated/authConfig.ts +1 -1
- package/src/forge/_generated/authContext.ts +1 -1
- package/src/forge/_generated/authRegistry.json +1 -1
- package/src/forge/_generated/authRegistry.ts +1 -1
- package/src/forge/_generated/buildInfo.json +2 -2
- package/src/forge/_generated/buildInfo.ts +4 -4
- package/src/forge/_generated/capabilityMap.json +2 -2
- package/src/forge/_generated/capabilityMap.md +1 -1
- package/src/forge/_generated/capabilityMap.ts +2 -2
- package/src/forge/_generated/client.ts +1 -1
- package/src/forge/_generated/clientApi.ts +1 -1
- package/src/forge/_generated/clientManifest.json +2 -2
- package/src/forge/_generated/clientManifest.ts +3 -3
- package/src/forge/_generated/clientTypes.ts +1 -1
- package/src/forge/_generated/configRegistry.json +1 -1
- package/src/forge/_generated/configRegistry.ts +1 -1
- package/src/forge/_generated/dataGraph.json +2 -2
- package/src/forge/_generated/dataGraph.ts +3 -3
- package/src/forge/_generated/db.json +1 -1
- package/src/forge/_generated/db.ts +1 -1
- package/src/forge/_generated/dbSecurityManifest.json +1 -1
- package/src/forge/_generated/dbSecurityManifest.ts +1 -1
- package/src/forge/_generated/dbSessionContext.json +1 -1
- package/src/forge/_generated/dbSessionContext.ts +1 -1
- package/src/forge/_generated/deployManifest.json +2 -2
- package/src/forge/_generated/deployManifest.ts +7 -7
- package/src/forge/_generated/devManifest.json +2 -2
- package/src/forge/_generated/devManifest.ts +3 -3
- package/src/forge/_generated/envSchema.json +1 -1
- package/src/forge/_generated/envSchema.ts +1 -1
- package/src/forge/_generated/frontendGraph.json +1 -1
- package/src/forge/_generated/frontendGraph.ts +1 -1
- package/src/forge/_generated/importGuards.json +2 -2
- package/src/forge/_generated/importGuards.ts +35 -1
- package/src/forge/_generated/index.ts +1 -1
- package/src/forge/_generated/liveProductionManifest.json +1 -1
- package/src/forge/_generated/liveProductionManifest.ts +1 -1
- package/src/forge/_generated/liveProtocol.json +1 -1
- package/src/forge/_generated/liveProtocol.ts +1 -1
- package/src/forge/_generated/liveQueryRegistry.json +2 -2
- package/src/forge/_generated/liveQueryRegistry.ts +3 -3
- package/src/forge/_generated/liveTransportConfig.json +1 -1
- package/src/forge/_generated/liveTransportConfig.ts +1 -1
- package/src/forge/_generated/makeRegistry.json +2 -2
- package/src/forge/_generated/makeRegistry.ts +2 -2
- package/src/forge/_generated/makeTemplates.json +1 -1
- package/src/forge/_generated/makeTemplates.ts +1 -1
- package/src/forge/_generated/mockMap.json +1 -1
- package/src/forge/_generated/mockMap.ts +1 -1
- package/src/forge/_generated/operationPlaybooks.md +7 -5
- package/src/forge/_generated/packageGraph.json +2 -2
- package/src/forge/_generated/packageGraph.ts +90964 -14284
- package/src/forge/_generated/packageUpgradeRegistry.json +2 -2
- package/src/forge/_generated/packageUpgradeRegistry.ts +2 -2
- package/src/forge/_generated/permissionMatrix.json +2 -2
- package/src/forge/_generated/permissionMatrix.ts +3 -3
- package/src/forge/_generated/policyRegistry.json +2 -2
- package/src/forge/_generated/policyRegistry.ts +3 -3
- package/src/forge/_generated/queryRegistry.json +2 -2
- package/src/forge/_generated/queryRegistry.ts +3 -3
- package/src/forge/_generated/react.d.ts +1 -1
- package/src/forge/_generated/react.ts +1 -1
- package/src/forge/_generated/reactManifest.json +2 -2
- package/src/forge/_generated/reactManifest.ts +3 -3
- package/src/forge/_generated/releaseManifest.json +2 -2
- package/src/forge/_generated/releaseManifest.ts +3 -3
- package/src/forge/_generated/rlsPolicies.json +1 -1
- package/src/forge/_generated/rlsPolicies.sql +1 -1
- package/src/forge/_generated/rlsPolicies.ts +1 -1
- package/src/forge/_generated/runtimeGraph.json +2 -2
- package/src/forge/_generated/runtimeGraph.ts +3 -3
- package/src/forge/_generated/runtimeMatrix.json +2 -2
- package/src/forge/_generated/runtimeMatrix.ts +106177 -7917
- package/src/forge/_generated/runtimeRegistry.ts +1 -1
- package/src/forge/_generated/runtimeRules.md +1 -1
- package/src/forge/_generated/secretRegistry.json +1 -1
- package/src/forge/_generated/secretRegistry.ts +1 -1
- package/src/forge/_generated/secretsContext.ts +1 -1
- package/src/forge/_generated/serverApi.ts +1 -1
- package/src/forge/_generated/sourceMapManifest.json +2 -2
- package/src/forge/_generated/sourceMapManifest.ts +2 -2
- package/src/forge/_generated/sqlPlan.json +1 -1
- package/src/forge/_generated/sqlPlan.ts +1 -1
- package/src/forge/_generated/subscriptionManifest.json +2 -2
- package/src/forge/_generated/subscriptionManifest.ts +3 -3
- package/src/forge/_generated/symbolicationManifest.json +2 -2
- package/src/forge/_generated/symbolicationManifest.ts +2 -2
- package/src/forge/_generated/telemetryRegistry.json +2 -2
- package/src/forge/_generated/telemetryRegistry.ts +3 -3
- package/src/forge/_generated/telemetrySinks.json +2 -2
- package/src/forge/_generated/telemetrySinks.ts +2 -2
- package/src/forge/_generated/tenantScope.json +2 -2
- package/src/forge/_generated/tenantScope.ts +3 -3
- package/src/forge/_generated/testGraph.json +2 -2
- package/src/forge/_generated/testGraph.ts +129 -75
- package/src/forge/_generated/testPlanRegistry.json +2 -2
- package/src/forge/_generated/testPlanRegistry.ts +2 -2
- package/src/forge/_generated/uiRoutes.json +1 -1
- package/src/forge/_generated/uiRoutes.ts +1 -1
- package/src/forge/_generated/uiScenarios.json +1 -1
- package/src/forge/_generated/uiScenarios.ts +1 -1
- package/src/forge/_generated/uiTestManifest.json +2 -2
- package/src/forge/_generated/uiTestManifest.ts +2 -2
- package/src/forge/_generated/workflowRegistry.json +2 -2
- package/src/forge/_generated/workflowRegistry.ts +3 -3
- package/src/forge/_generated/workflowSubscriptions.json +2 -2
- package/src/forge/_generated/workflowSubscriptions.ts +3 -3
- package/src/forge/cli/commands.ts +861 -861
- package/src/forge/cli/deps.ts +178 -11
- package/src/forge/cli/dev.ts +32 -5
- package/src/forge/cli/index.ts +7 -7
- package/src/forge/cli/main.ts +54 -54
- package/src/forge/cli/new.ts +29 -1
- package/src/forge/cli/output.ts +97 -97
- package/src/forge/cli/parse.ts +679 -673
- package/src/forge/cli/version.ts +1 -1
- package/src/forge/compiler/agent-contract/build.ts +28 -0
- package/src/forge/compiler/agent-contract/types.ts +16 -0
- package/src/forge/compiler/app-graph/build.ts +112 -112
- package/src/forge/compiler/app-graph/classify.ts +10 -10
- package/src/forge/compiler/app-graph/dup-symbol.ts +29 -29
- package/src/forge/compiler/app-graph/extract.ts +123 -123
- package/src/forge/compiler/app-graph/forge-apis.ts +29 -29
- package/src/forge/compiler/app-graph/index.ts +11 -11
- package/src/forge/compiler/app-graph/module-graph.ts +316 -316
- package/src/forge/compiler/app-graph/parser.ts +119 -119
- package/src/forge/compiler/app-graph/symbols.ts +48 -48
- package/src/forge/compiler/app-graph/tsconfig-hash.ts +62 -62
- package/src/forge/compiler/app-graph/types.ts +43 -43
- package/src/forge/compiler/app-graph/versions.ts +14 -14
- package/src/forge/compiler/cache/index.ts +17 -17
- package/src/forge/compiler/cache/key.ts +46 -46
- package/src/forge/compiler/cache/scheduler.ts +72 -72
- package/src/forge/compiler/cache/store.ts +78 -78
- package/src/forge/compiler/classifier/capabilities.ts +78 -78
- package/src/forge/compiler/classifier/classify.ts +113 -113
- package/src/forge/compiler/classifier/contexts.ts +188 -188
- package/src/forge/compiler/classifier/index.ts +18 -18
- package/src/forge/compiler/classifier/runtime-matrix.ts +45 -45
- package/src/forge/compiler/classifier/secrets.ts +41 -41
- package/src/forge/compiler/classifier/signals.ts +129 -129
- package/src/forge/compiler/diagnostics/codes.ts +125 -120
- package/src/forge/compiler/diagnostics/create.ts +87 -87
- package/src/forge/compiler/diagnostics/index.ts +41 -41
- package/src/forge/compiler/emitter/artifact-kind.ts +14 -14
- package/src/forge/compiler/emitter/barrel.ts +38 -38
- package/src/forge/compiler/emitter/constants.ts +7 -7
- package/src/forge/compiler/emitter/emit.ts +234 -237
- package/src/forge/compiler/emitter/index.ts +24 -24
- package/src/forge/compiler/emitter/lock.ts +61 -61
- package/src/forge/compiler/emitter/render.ts +73 -73
- package/src/forge/compiler/guards/artifacts.ts +96 -96
- package/src/forge/compiler/guards/check-import-guards.ts +106 -106
- package/src/forge/compiler/guards/index.ts +11 -11
- package/src/forge/compiler/guards/propagate-contexts.ts +57 -57
- package/src/forge/compiler/index.ts +17 -17
- package/src/forge/compiler/integration/add.ts +493 -493
- package/src/forge/compiler/integration/index.ts +17 -17
- package/src/forge/compiler/integration/plan.ts +279 -279
- package/src/forge/compiler/integration/render.ts +189 -189
- package/src/forge/compiler/integration/snapshot.ts +52 -52
- package/src/forge/compiler/orchestrator/discover.ts +214 -214
- package/src/forge/compiler/orchestrator/guards.ts +5 -5
- package/src/forge/compiler/orchestrator/index.ts +27 -27
- package/src/forge/compiler/orchestrator/manifest.ts +69 -69
- package/src/forge/compiler/orchestrator/orphans.ts +51 -51
- package/src/forge/compiler/orchestrator/plan.ts +804 -804
- package/src/forge/compiler/orchestrator/run.ts +178 -178
- package/src/forge/compiler/orchestrator/serialize.ts +859 -859
- package/src/forge/compiler/orchestrator/types.ts +23 -23
- package/src/forge/compiler/orchestrator/verify.ts +35 -35
- package/src/forge/compiler/package-graph/capabilities-stub.ts +33 -33
- package/src/forge/compiler/package-graph/checksum.ts +107 -97
- package/src/forge/compiler/package-graph/compiler.ts +444 -363
- package/src/forge/compiler/package-graph/constants.ts +4 -4
- package/src/forge/compiler/package-graph/exports-discovery.ts +91 -84
- package/src/forge/compiler/package-graph/extract-dts.ts +32 -32
- package/src/forge/compiler/package-graph/index.ts +24 -24
- package/src/forge/compiler/package-graph/jsdoc.ts +50 -50
- package/src/forge/compiler/package-graph/oracle.ts +326 -0
- package/src/forge/compiler/package-graph/read-file.ts +21 -21
- package/src/forge/compiler/package-graph/resolve.ts +131 -127
- package/src/forge/compiler/package-manager/adapter.ts +232 -232
- package/src/forge/compiler/package-manager/commands.ts +47 -47
- package/src/forge/compiler/package-manager/detect.ts +65 -65
- package/src/forge/compiler/package-manager/executor.ts +29 -29
- package/src/forge/compiler/package-manager/index.ts +22 -22
- package/src/forge/compiler/package-manager/parse-spec.ts +16 -16
- package/src/forge/compiler/package-manager/version.ts +20 -20
- package/src/forge/compiler/primitives/compare.ts +26 -26
- package/src/forge/compiler/primitives/hash.ts +42 -33
- package/src/forge/compiler/primitives/header.ts +43 -43
- package/src/forge/compiler/primitives/index.ts +45 -45
- package/src/forge/compiler/primitives/paths.ts +24 -24
- package/src/forge/compiler/primitives/serialize.ts +66 -66
- package/src/forge/compiler/primitives/sort.ts +87 -87
- package/src/forge/compiler/recipes/definitions.ts +269 -269
- package/src/forge/compiler/recipes/helpers.ts +37 -37
- package/src/forge/compiler/recipes/index.ts +21 -21
- package/src/forge/compiler/recipes/registry.ts +87 -87
- package/src/forge/compiler/sandbox/artifact-sanitize.ts +26 -26
- package/src/forge/compiler/sandbox/backends/child.ts +123 -123
- package/src/forge/compiler/sandbox/backends/docker.ts +173 -173
- package/src/forge/compiler/sandbox/index.ts +51 -51
- package/src/forge/compiler/sandbox/inspect.ts +143 -143
- package/src/forge/compiler/sandbox/inspector-entry.ts +115 -115
- package/src/forge/compiler/sandbox/limits.ts +31 -31
- package/src/forge/compiler/sandbox/scrub-env.ts +60 -60
- package/src/forge/compiler/sandbox/secret-scan.ts +54 -54
- package/src/forge/compiler/sandbox/serialize.ts +106 -106
- package/src/forge/compiler/sandbox/types.ts +7 -7
- package/src/forge/compiler/types/app-graph.ts +71 -71
- package/src/forge/compiler/types/capability.ts +29 -29
- package/src/forge/compiler/types/classification.ts +9 -9
- package/src/forge/compiler/types/cli.ts +85 -85
- package/src/forge/compiler/types/diagnostic.ts +2 -2
- package/src/forge/compiler/types/emit.ts +25 -25
- package/src/forge/compiler/types/import-guards.ts +19 -19
- package/src/forge/compiler/types/index.ts +98 -98
- package/src/forge/compiler/types/integration.ts +25 -25
- package/src/forge/compiler/types/json.ts +3 -3
- package/src/forge/compiler/types/lock.ts +37 -37
- package/src/forge/compiler/types/package-graph.ts +122 -77
- package/src/forge/compiler/types/runtime-matrix.ts +16 -16
- package/src/forge/compiler/types/runtime.ts +30 -30
- package/src/forge/compiler/types/sandbox.ts +24 -24
- package/src/forge/dev/server.ts +16 -2
- package/src/forge/refactor/index.ts +10 -2
- package/src/forge/refactor/runtime-rename.ts +598 -0
- package/src/forge/runtime/executor.ts +3 -2
- package/src/forge/runtime/live/live-query-runner.ts +2 -1
- package/src/forge/runtime/outbox/process.ts +2 -1
- package/src/forge/runtime/query/run-query.ts +2 -1
- package/src/forge/runtime/runner/run-entry.ts +2 -1
- package/src/forge/runtime/telemetry/sinks/posthog.ts +4 -5
- package/src/forge/runtime/telemetry/sinks/sentry.ts +4 -5
- package/src/forge/runtime/workflows/resolve-step.ts +2 -1
- package/src/forge/version.ts +3 -0
- package/templates/b2b-support-web/src/actions/captureTicketCreated.ts +7 -2
- package/templates/b2b-support-web/src/commands/closeTicket.ts +6 -1
- package/templates/b2b-support-web/src/commands/createTicket.ts +8 -2
- package/templates/b2b-support-web/src/queries/getTicket.ts +8 -1
- package/templates/b2b-support-web/web/components/CreateTicketForm.tsx +1 -2
- package/templates/b2b-support-web/web/components/PolicyDeniedDemo.tsx +1 -2
- package/templates/b2b-support-web/web/components/TicketList.tsx +1 -2
- package/templates/b2b-support-web/web/components/TraceDetails.tsx +1 -1
- package/templates/b2b-support-web/web/lib/forge.ts +1 -0
package/src/forge/cli/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { CLI_VERSION } from "../version.ts";
|
|
@@ -8,6 +8,9 @@ import { GENERATOR_VERSION } from "../emitter/constants.ts";
|
|
|
8
8
|
import { stripDeterministicHeader } from "../primitives/header.ts";
|
|
9
9
|
import { canonicalJson, normalizeNewlines, serializeCanonical } from "../primitives/serialize.ts";
|
|
10
10
|
import { resolveByPackageName } from "../recipes/registry.ts";
|
|
11
|
+
import {
|
|
12
|
+
defaultRuntimeCompatibility,
|
|
13
|
+
} from "../package-graph/oracle.ts";
|
|
11
14
|
import { secretLeakScan } from "../sandbox/secret-scan.ts";
|
|
12
15
|
import type { AiRegistry } from "../types/ai-registry.ts";
|
|
13
16
|
import type { AppGraph } from "../types/app-graph.ts";
|
|
@@ -37,6 +40,7 @@ import type {
|
|
|
37
40
|
AgentCapabilityMap,
|
|
38
41
|
AgentCapabilityMapEntry,
|
|
39
42
|
AgentContract,
|
|
43
|
+
AgentDependencyApiInfo,
|
|
40
44
|
AgentFrontendRuntimeBindingInfo,
|
|
41
45
|
AgentFrontendUsageInfo,
|
|
42
46
|
AgentHttpEndpointInfo,
|
|
@@ -220,6 +224,22 @@ function buildIntegrations(classified: ClassifiedPackage[]): AgentIntegrationInf
|
|
|
220
224
|
return sorted([...byAlias.values()], (entry) => entry.alias);
|
|
221
225
|
}
|
|
222
226
|
|
|
227
|
+
function buildDependencyApis(packageGraph: PackageGraph): AgentDependencyApiInfo[] {
|
|
228
|
+
return sorted(packageGraph.packages, (pkg) => pkg.name).map((pkg) => ({
|
|
229
|
+
package: pkg.name,
|
|
230
|
+
version: pkg.version,
|
|
231
|
+
source: pkg.source,
|
|
232
|
+
entrypoints: sorted(pkg.entrypoints, (entrypoint) => entrypoint.subpath).map((entrypoint) => ({
|
|
233
|
+
subpath: entrypoint.subpath,
|
|
234
|
+
dtsPath: entrypoint.dtsPath,
|
|
235
|
+
exportCount: entrypoint.exports.length,
|
|
236
|
+
exports: uniqueSorted(entrypoint.exports.map((exported) => exported.name)),
|
|
237
|
+
})),
|
|
238
|
+
runtimeCompatibility: pkg.runtimeCompatibility ?? defaultRuntimeCompatibility(),
|
|
239
|
+
runtimeTypeMismatches: pkg.runtimeTypeMismatches ?? [],
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
|
|
223
243
|
function runtimeRules(): AgentRuntimeRule[] {
|
|
224
244
|
return [
|
|
225
245
|
{
|
|
@@ -378,6 +398,8 @@ function playbooks(): AgentPlaybook[] {
|
|
|
378
398
|
title: "Upgrade a package",
|
|
379
399
|
steps: [
|
|
380
400
|
"Run forge deps upgrade-plan <package> --to latest.",
|
|
401
|
+
"Use forge deps inspect <package> --json and forge deps api <package> <symbol> --json before relying on changed external APIs.",
|
|
402
|
+
"Use forge deps trace <package> --json when exports or type resolution are ambiguous.",
|
|
381
403
|
"Read .forge/upgrades/.../plan.md.",
|
|
382
404
|
"If risk is high, inspect affected files and generated adapters before applying.",
|
|
383
405
|
"Apply with forge deps upgrade-apply <plan>.",
|
|
@@ -905,6 +927,7 @@ export function buildAgentContractArtifacts(
|
|
|
905
927
|
deniedContexts: classified?.classification.incompatible ?? [],
|
|
906
928
|
};
|
|
907
929
|
}),
|
|
930
|
+
dependencyApis: buildDependencyApis(input.packageGraph),
|
|
908
931
|
integrations: buildIntegrations(input.classified),
|
|
909
932
|
secrets: sorted(input.secretRegistry.secrets, (secret) => secret.name).map((secret) => ({
|
|
910
933
|
name: secret.name,
|
|
@@ -1155,6 +1178,9 @@ forge inspect app --json
|
|
|
1155
1178
|
forge inspect all --json
|
|
1156
1179
|
forge inspect frontend --json
|
|
1157
1180
|
forge inspect capabilities --json
|
|
1181
|
+
forge deps inspect <package> --json
|
|
1182
|
+
forge deps api <package> <symbol> --json
|
|
1183
|
+
forge deps trace <package> --json
|
|
1158
1184
|
forge auth check --json
|
|
1159
1185
|
forge inspect runtime-matrix --json
|
|
1160
1186
|
forge inspect policies --json
|
|
@@ -1337,6 +1363,8 @@ Use:
|
|
|
1337
1363
|
|
|
1338
1364
|
\`\`\`bash
|
|
1339
1365
|
forge deps upgrade-plan <package> --to latest
|
|
1366
|
+
forge deps inspect <package> --json
|
|
1367
|
+
forge deps api <package> <symbol> --json
|
|
1340
1368
|
forge deps upgrade-apply <plan>
|
|
1341
1369
|
forge verify --strict
|
|
1342
1370
|
\`\`\`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Diagnostic } from "../types/diagnostic.ts";
|
|
2
|
+
import type { PackageRuntimeCompatibility, RuntimeTypeMismatch } from "../types/package-graph.ts";
|
|
2
3
|
import type { RuntimeContext } from "../types/runtime.ts";
|
|
3
4
|
|
|
4
5
|
export interface AgentProjectInfo {
|
|
@@ -100,6 +101,20 @@ export interface AgentPackageInfo {
|
|
|
100
101
|
deniedContexts: RuntimeContext[];
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
export interface AgentDependencyApiInfo {
|
|
105
|
+
package: string;
|
|
106
|
+
version: string;
|
|
107
|
+
source: "static" | "static+runtime";
|
|
108
|
+
entrypoints: Array<{
|
|
109
|
+
subpath: string;
|
|
110
|
+
dtsPath: string | null;
|
|
111
|
+
exportCount: number;
|
|
112
|
+
exports: string[];
|
|
113
|
+
}>;
|
|
114
|
+
runtimeCompatibility: PackageRuntimeCompatibility;
|
|
115
|
+
runtimeTypeMismatches: RuntimeTypeMismatch[];
|
|
116
|
+
}
|
|
117
|
+
|
|
103
118
|
export interface AgentIntegrationInfo {
|
|
104
119
|
alias: string;
|
|
105
120
|
packages: string[];
|
|
@@ -308,6 +323,7 @@ export interface AgentContract {
|
|
|
308
323
|
data: AgentDataInfo;
|
|
309
324
|
policies: AgentPolicyInfo[];
|
|
310
325
|
packages: AgentPackageInfo[];
|
|
326
|
+
dependencyApis: AgentDependencyApiInfo[];
|
|
311
327
|
integrations: AgentIntegrationInfo[];
|
|
312
328
|
secrets: AgentSecretInfo[];
|
|
313
329
|
telemetry: AgentTelemetryInfo;
|
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import { canonicalJson } from "../primitives/serialize.ts";
|
|
2
|
-
import { hashStable } from "../primitives/hash.ts";
|
|
3
|
-
import { normalizePath } from "../primitives/paths.ts";
|
|
4
|
-
import { stableSortEdges, stableSortSymbols } from "../primitives/sort.ts";
|
|
5
|
-
import type { AppGraph, SourceFile } from "../types/app-graph.ts";
|
|
6
|
-
import { detectDuplicateSymbols } from "./dup-symbol.ts";
|
|
7
|
-
import { buildModuleGraph } from "./module-graph.ts";
|
|
8
|
-
import { incrementalParse } from "./parser.ts";
|
|
9
|
-
import { buildForgeSymbols } from "./symbols.ts";
|
|
10
|
-
import { hashTsconfigForWorkspace } from "./tsconfig-hash.ts";
|
|
11
|
-
import type { ParseInvalidationKey } from "./types.ts";
|
|
12
|
-
import { buildAnalyzerVersion } from "./types.ts";
|
|
13
|
-
import {
|
|
14
|
-
APP_GRAPH_SCHEMA_VERSION,
|
|
15
|
-
FORGE_CLASSIFIER_VERSION,
|
|
16
|
-
GENERATOR_VERSION,
|
|
17
|
-
TREE_SITTER_GRAMMAR_VERSION,
|
|
18
|
-
} from "./versions.ts";
|
|
19
|
-
|
|
20
|
-
export interface AppGraphBuildOptions {
|
|
21
|
-
workspaceRoot: string;
|
|
22
|
-
sources: SourceFile[];
|
|
23
|
-
prior?: AppGraph;
|
|
24
|
-
tsconfigPath?: string;
|
|
25
|
-
/** When provided, skips re-reading and hashing tsconfig.json. */
|
|
26
|
-
tsconfigHash?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function normalizeSources(sources: SourceFile[]): SourceFile[] {
|
|
30
|
-
return sources.map((source) => ({
|
|
31
|
-
...source,
|
|
32
|
-
path: normalizePath(source.path),
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function computeInputHash(
|
|
37
|
-
sources: SourceFile[],
|
|
38
|
-
invalidation: ParseInvalidationKey,
|
|
39
|
-
): string {
|
|
40
|
-
const payload = {
|
|
41
|
-
files: [...sources]
|
|
42
|
-
.map((source) => ({ path: source.path, contentHash: source.contentHash }))
|
|
43
|
-
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0)),
|
|
44
|
-
invalidation,
|
|
45
|
-
};
|
|
46
|
-
return hashStable(canonicalJson(payload));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function parseInvalidationFromPrior(prior: AppGraph): ParseInvalidationKey | undefined {
|
|
50
|
-
const analyzer = prior.analyzerVersion;
|
|
51
|
-
const schemaMatch = /schema:([^+]+)/.exec(analyzer);
|
|
52
|
-
const grammarMatch = /grammar:([^+]+)/.exec(analyzer);
|
|
53
|
-
const classifierMatch = /classifier:([^+]+)/.exec(analyzer);
|
|
54
|
-
const tsconfigMatch = /tsconfig:([^+]+)/.exec(analyzer);
|
|
55
|
-
|
|
56
|
-
if (!schemaMatch || !grammarMatch || !classifierMatch || !tsconfigMatch) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
schemaVersion: schemaMatch[1] ?? APP_GRAPH_SCHEMA_VERSION,
|
|
62
|
-
grammarVersion: grammarMatch[1] ?? TREE_SITTER_GRAMMAR_VERSION,
|
|
63
|
-
classifierVersion: classifierMatch[1] ?? FORGE_CLASSIFIER_VERSION,
|
|
64
|
-
tsconfigHash: tsconfigMatch[1] ?? "",
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function buildAppGraph(
|
|
69
|
-
options: AppGraphBuildOptions,
|
|
70
|
-
): Promise<AppGraph> {
|
|
71
|
-
const sources = normalizeSources(options.sources);
|
|
72
|
-
const tsconfigHash =
|
|
73
|
-
options.tsconfigHash ??
|
|
74
|
-
hashTsconfigForWorkspace(
|
|
75
|
-
options.workspaceRoot,
|
|
76
|
-
options.tsconfigPath,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const invalidation: ParseInvalidationKey = {
|
|
80
|
-
schemaVersion: APP_GRAPH_SCHEMA_VERSION,
|
|
81
|
-
grammarVersion: TREE_SITTER_GRAMMAR_VERSION,
|
|
82
|
-
classifierVersion: FORGE_CLASSIFIER_VERSION,
|
|
83
|
-
tsconfigHash,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const priorInvalidation = options.prior
|
|
87
|
-
? parseInvalidationFromPrior(options.prior)
|
|
88
|
-
: undefined;
|
|
89
|
-
|
|
90
|
-
const { symbols: rawSymbols, diagnostics: parseDiagnostics } =
|
|
91
|
-
incrementalParse(
|
|
92
|
-
sources,
|
|
93
|
-
options.prior?.symbols,
|
|
94
|
-
priorInvalidation,
|
|
95
|
-
invalidation,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const forgeSymbols = buildForgeSymbols(rawSymbols, sources);
|
|
99
|
-
const dupDiagnostics = detectDuplicateSymbols(forgeSymbols);
|
|
100
|
-
const moduleGraph = buildModuleGraph(
|
|
101
|
-
sources,
|
|
102
|
-
rawSymbols,
|
|
103
|
-
options.workspaceRoot,
|
|
104
|
-
options.tsconfigPath,
|
|
105
|
-
options.prior,
|
|
106
|
-
);
|
|
107
|
-
|
|
1
|
+
import { canonicalJson } from "../primitives/serialize.ts";
|
|
2
|
+
import { hashStable } from "../primitives/hash.ts";
|
|
3
|
+
import { normalizePath } from "../primitives/paths.ts";
|
|
4
|
+
import { stableSortEdges, stableSortSymbols } from "../primitives/sort.ts";
|
|
5
|
+
import type { AppGraph, SourceFile } from "../types/app-graph.ts";
|
|
6
|
+
import { detectDuplicateSymbols } from "./dup-symbol.ts";
|
|
7
|
+
import { buildModuleGraph } from "./module-graph.ts";
|
|
8
|
+
import { incrementalParse } from "./parser.ts";
|
|
9
|
+
import { buildForgeSymbols } from "./symbols.ts";
|
|
10
|
+
import { hashTsconfigForWorkspace } from "./tsconfig-hash.ts";
|
|
11
|
+
import type { ParseInvalidationKey } from "./types.ts";
|
|
12
|
+
import { buildAnalyzerVersion } from "./types.ts";
|
|
13
|
+
import {
|
|
14
|
+
APP_GRAPH_SCHEMA_VERSION,
|
|
15
|
+
FORGE_CLASSIFIER_VERSION,
|
|
16
|
+
GENERATOR_VERSION,
|
|
17
|
+
TREE_SITTER_GRAMMAR_VERSION,
|
|
18
|
+
} from "./versions.ts";
|
|
19
|
+
|
|
20
|
+
export interface AppGraphBuildOptions {
|
|
21
|
+
workspaceRoot: string;
|
|
22
|
+
sources: SourceFile[];
|
|
23
|
+
prior?: AppGraph;
|
|
24
|
+
tsconfigPath?: string;
|
|
25
|
+
/** When provided, skips re-reading and hashing tsconfig.json. */
|
|
26
|
+
tsconfigHash?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeSources(sources: SourceFile[]): SourceFile[] {
|
|
30
|
+
return sources.map((source) => ({
|
|
31
|
+
...source,
|
|
32
|
+
path: normalizePath(source.path),
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function computeInputHash(
|
|
37
|
+
sources: SourceFile[],
|
|
38
|
+
invalidation: ParseInvalidationKey,
|
|
39
|
+
): string {
|
|
40
|
+
const payload = {
|
|
41
|
+
files: [...sources]
|
|
42
|
+
.map((source) => ({ path: source.path, contentHash: source.contentHash }))
|
|
43
|
+
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0)),
|
|
44
|
+
invalidation,
|
|
45
|
+
};
|
|
46
|
+
return hashStable(canonicalJson(payload));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseInvalidationFromPrior(prior: AppGraph): ParseInvalidationKey | undefined {
|
|
50
|
+
const analyzer = prior.analyzerVersion;
|
|
51
|
+
const schemaMatch = /schema:([^+]+)/.exec(analyzer);
|
|
52
|
+
const grammarMatch = /grammar:([^+]+)/.exec(analyzer);
|
|
53
|
+
const classifierMatch = /classifier:([^+]+)/.exec(analyzer);
|
|
54
|
+
const tsconfigMatch = /tsconfig:([^+]+)/.exec(analyzer);
|
|
55
|
+
|
|
56
|
+
if (!schemaMatch || !grammarMatch || !classifierMatch || !tsconfigMatch) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
schemaVersion: schemaMatch[1] ?? APP_GRAPH_SCHEMA_VERSION,
|
|
62
|
+
grammarVersion: grammarMatch[1] ?? TREE_SITTER_GRAMMAR_VERSION,
|
|
63
|
+
classifierVersion: classifierMatch[1] ?? FORGE_CLASSIFIER_VERSION,
|
|
64
|
+
tsconfigHash: tsconfigMatch[1] ?? "",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function buildAppGraph(
|
|
69
|
+
options: AppGraphBuildOptions,
|
|
70
|
+
): Promise<AppGraph> {
|
|
71
|
+
const sources = normalizeSources(options.sources);
|
|
72
|
+
const tsconfigHash =
|
|
73
|
+
options.tsconfigHash ??
|
|
74
|
+
hashTsconfigForWorkspace(
|
|
75
|
+
options.workspaceRoot,
|
|
76
|
+
options.tsconfigPath,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const invalidation: ParseInvalidationKey = {
|
|
80
|
+
schemaVersion: APP_GRAPH_SCHEMA_VERSION,
|
|
81
|
+
grammarVersion: TREE_SITTER_GRAMMAR_VERSION,
|
|
82
|
+
classifierVersion: FORGE_CLASSIFIER_VERSION,
|
|
83
|
+
tsconfigHash,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const priorInvalidation = options.prior
|
|
87
|
+
? parseInvalidationFromPrior(options.prior)
|
|
88
|
+
: undefined;
|
|
89
|
+
|
|
90
|
+
const { symbols: rawSymbols, diagnostics: parseDiagnostics } =
|
|
91
|
+
incrementalParse(
|
|
92
|
+
sources,
|
|
93
|
+
options.prior?.symbols,
|
|
94
|
+
priorInvalidation,
|
|
95
|
+
invalidation,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const forgeSymbols = buildForgeSymbols(rawSymbols, sources);
|
|
99
|
+
const dupDiagnostics = detectDuplicateSymbols(forgeSymbols);
|
|
100
|
+
const moduleGraph = buildModuleGraph(
|
|
101
|
+
sources,
|
|
102
|
+
rawSymbols,
|
|
103
|
+
options.workspaceRoot,
|
|
104
|
+
options.tsconfigPath,
|
|
105
|
+
options.prior,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
108
|
return {
|
|
109
109
|
schemaVersion: APP_GRAPH_SCHEMA_VERSION,
|
|
110
110
|
generatorVersion: GENERATOR_VERSION,
|
|
@@ -114,8 +114,8 @@ export async function buildAppGraph(
|
|
|
114
114
|
sources.map((source) => [source.path, source.contentHash]),
|
|
115
115
|
),
|
|
116
116
|
symbols: stableSortSymbols(forgeSymbols),
|
|
117
|
-
edges: stableSortEdges([]),
|
|
118
|
-
moduleGraph,
|
|
119
|
-
diagnostics: [...parseDiagnostics, ...dupDiagnostics],
|
|
120
|
-
};
|
|
121
|
-
}
|
|
117
|
+
edges: stableSortEdges([]),
|
|
118
|
+
moduleGraph,
|
|
119
|
+
diagnostics: [...parseDiagnostics, ...dupDiagnostics],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ForgeKind } from "../types/app-graph.ts";
|
|
2
|
-
import { FORGE_BUILDER_APIS } from "./forge-apis.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Classify a Forge builder callee into exactly one ForgeKind, or null when
|
|
6
|
-
* the callee is not a known Forge builder API.
|
|
7
|
-
*/
|
|
8
|
-
export function classifyForgeCallee(callee: string): ForgeKind | null {
|
|
9
|
-
return FORGE_BUILDER_APIS[callee] ?? null;
|
|
10
|
-
}
|
|
1
|
+
import type { ForgeKind } from "../types/app-graph.ts";
|
|
2
|
+
import { FORGE_BUILDER_APIS } from "./forge-apis.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Classify a Forge builder callee into exactly one ForgeKind, or null when
|
|
6
|
+
* the callee is not a known Forge builder API.
|
|
7
|
+
*/
|
|
8
|
+
export function classifyForgeCallee(callee: string): ForgeKind | null {
|
|
9
|
+
return FORGE_BUILDER_APIS[callee] ?? null;
|
|
10
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { forgeDupSymbol } from "../diagnostics/create.ts";
|
|
2
|
-
import type { Diagnostic } from "../types/diagnostic.ts";
|
|
3
|
-
import type { ForgeSymbol } from "../types/app-graph.ts";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Emit FORGE_DUP_SYMBOL warnings for stable-id collisions without discarding symbols.
|
|
7
|
-
*/
|
|
8
|
-
export function detectDuplicateSymbols(symbols: ForgeSymbol[]): Diagnostic[] {
|
|
9
|
-
const groups = new Map<string, ForgeSymbol[]>();
|
|
10
|
-
|
|
11
|
-
for (const symbol of symbols) {
|
|
12
|
-
const list = groups.get(symbol.id) ?? [];
|
|
13
|
-
list.push(symbol);
|
|
14
|
-
groups.set(symbol.id, list);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const diagnostics: Diagnostic[] = [];
|
|
18
|
-
|
|
19
|
-
for (const group of groups.values()) {
|
|
20
|
-
if (group.length <= 1) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
for (const symbol of group) {
|
|
24
|
-
diagnostics.push(forgeDupSymbol(symbol.qualifiedName, symbol.file));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return diagnostics;
|
|
29
|
-
}
|
|
1
|
+
import { forgeDupSymbol } from "../diagnostics/create.ts";
|
|
2
|
+
import type { Diagnostic } from "../types/diagnostic.ts";
|
|
3
|
+
import type { ForgeSymbol } from "../types/app-graph.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Emit FORGE_DUP_SYMBOL warnings for stable-id collisions without discarding symbols.
|
|
7
|
+
*/
|
|
8
|
+
export function detectDuplicateSymbols(symbols: ForgeSymbol[]): Diagnostic[] {
|
|
9
|
+
const groups = new Map<string, ForgeSymbol[]>();
|
|
10
|
+
|
|
11
|
+
for (const symbol of symbols) {
|
|
12
|
+
const list = groups.get(symbol.id) ?? [];
|
|
13
|
+
list.push(symbol);
|
|
14
|
+
groups.set(symbol.id, list);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const diagnostics: Diagnostic[] = [];
|
|
18
|
+
|
|
19
|
+
for (const group of groups.values()) {
|
|
20
|
+
if (group.length <= 1) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
for (const symbol of group) {
|
|
24
|
+
diagnostics.push(forgeDupSymbol(symbol.qualifiedName, symbol.file));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return diagnostics;
|
|
29
|
+
}
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import type { SyntaxNode } from "tree-sitter";
|
|
2
|
-
import { classifyForgeCallee } from "./classify.ts";
|
|
3
|
-
import type { RawSymbol } from "./types.ts";
|
|
4
|
-
|
|
5
|
-
export interface SymbolNameInfo {
|
|
6
|
-
name: string;
|
|
7
|
-
qualifiedName: string;
|
|
8
|
-
exportPath: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function resolveCalleeName(functionNode: SyntaxNode): string | null {
|
|
12
|
-
if (functionNode.type === "identifier") {
|
|
13
|
-
return functionNode.text;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (functionNode.type === "member_expression") {
|
|
17
|
-
const property = functionNode.childForFieldName("property");
|
|
18
|
-
if (property && (property.type === "property_identifier" || property.type === "identifier")) {
|
|
19
|
-
return property.text;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function inferSymbolName(callNode: SyntaxNode): SymbolNameInfo {
|
|
27
|
-
let exportPath = "";
|
|
28
|
-
let parent: SyntaxNode | null = callNode.parent;
|
|
29
|
-
|
|
30
|
-
while (parent) {
|
|
31
|
-
if (parent.type === "variable_declarator") {
|
|
32
|
-
const nameNode = parent.childForFieldName("name");
|
|
33
|
-
if (nameNode) {
|
|
34
|
-
const name = nameNode.text;
|
|
35
|
-
return { name, qualifiedName: name, exportPath };
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (parent.type === "lexical_declaration" || parent.type === "variable_declaration") {
|
|
40
|
-
const declarator = parent.namedChildren.find(
|
|
41
|
-
(child) => child.type === "variable_declarator",
|
|
42
|
-
);
|
|
43
|
-
if (declarator) {
|
|
44
|
-
const nameNode = declarator.childForFieldName("name");
|
|
45
|
-
if (nameNode) {
|
|
46
|
-
const name = nameNode.text;
|
|
47
|
-
return { name, qualifiedName: name, exportPath };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (parent.type === "export_statement") {
|
|
53
|
-
const declaration = parent.childForFieldName("declaration");
|
|
54
|
-
if (declaration?.type === "lexical_declaration" || declaration?.type === "variable_declaration") {
|
|
55
|
-
const declarator = declaration.namedChildren.find(
|
|
56
|
-
(child) => child.type === "variable_declarator",
|
|
57
|
-
);
|
|
58
|
-
if (declarator) {
|
|
59
|
-
const nameNode = declarator.childForFieldName("name");
|
|
60
|
-
if (nameNode) {
|
|
61
|
-
const name = nameNode.text;
|
|
62
|
-
return { name, qualifiedName: name, exportPath: "" };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const value = parent.childForFieldName("value");
|
|
68
|
-
if (value === callNode || value?.descendantsOfType("call_expression").includes(callNode)) {
|
|
69
|
-
exportPath = "default";
|
|
70
|
-
const fallback = "__default_export__";
|
|
71
|
-
return { name: fallback, qualifiedName: fallback, exportPath };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
parent = parent.parent;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const fallback = `__forge_${callNode.startPosition.row}_${callNode.startPosition.column}`;
|
|
79
|
-
return { name: fallback, qualifiedName: fallback, exportPath };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function extractSymbolsFromTree(
|
|
83
|
-
root: SyntaxNode,
|
|
84
|
-
file: string,
|
|
85
|
-
source: string,
|
|
86
|
-
): RawSymbol[] {
|
|
87
|
-
const symbols: RawSymbol[] = [];
|
|
88
|
-
const visited = new Set<string>();
|
|
89
|
-
|
|
90
|
-
function visit(node: SyntaxNode): void {
|
|
91
|
-
if (node.type === "call_expression") {
|
|
92
|
-
const functionNode = node.childForFieldName("function");
|
|
1
|
+
import type { SyntaxNode } from "tree-sitter";
|
|
2
|
+
import { classifyForgeCallee } from "./classify.ts";
|
|
3
|
+
import type { RawSymbol } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
export interface SymbolNameInfo {
|
|
6
|
+
name: string;
|
|
7
|
+
qualifiedName: string;
|
|
8
|
+
exportPath: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function resolveCalleeName(functionNode: SyntaxNode): string | null {
|
|
12
|
+
if (functionNode.type === "identifier") {
|
|
13
|
+
return functionNode.text;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (functionNode.type === "member_expression") {
|
|
17
|
+
const property = functionNode.childForFieldName("property");
|
|
18
|
+
if (property && (property.type === "property_identifier" || property.type === "identifier")) {
|
|
19
|
+
return property.text;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function inferSymbolName(callNode: SyntaxNode): SymbolNameInfo {
|
|
27
|
+
let exportPath = "";
|
|
28
|
+
let parent: SyntaxNode | null = callNode.parent;
|
|
29
|
+
|
|
30
|
+
while (parent) {
|
|
31
|
+
if (parent.type === "variable_declarator") {
|
|
32
|
+
const nameNode = parent.childForFieldName("name");
|
|
33
|
+
if (nameNode) {
|
|
34
|
+
const name = nameNode.text;
|
|
35
|
+
return { name, qualifiedName: name, exportPath };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (parent.type === "lexical_declaration" || parent.type === "variable_declaration") {
|
|
40
|
+
const declarator = parent.namedChildren.find(
|
|
41
|
+
(child) => child.type === "variable_declarator",
|
|
42
|
+
);
|
|
43
|
+
if (declarator) {
|
|
44
|
+
const nameNode = declarator.childForFieldName("name");
|
|
45
|
+
if (nameNode) {
|
|
46
|
+
const name = nameNode.text;
|
|
47
|
+
return { name, qualifiedName: name, exportPath };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (parent.type === "export_statement") {
|
|
53
|
+
const declaration = parent.childForFieldName("declaration");
|
|
54
|
+
if (declaration?.type === "lexical_declaration" || declaration?.type === "variable_declaration") {
|
|
55
|
+
const declarator = declaration.namedChildren.find(
|
|
56
|
+
(child) => child.type === "variable_declarator",
|
|
57
|
+
);
|
|
58
|
+
if (declarator) {
|
|
59
|
+
const nameNode = declarator.childForFieldName("name");
|
|
60
|
+
if (nameNode) {
|
|
61
|
+
const name = nameNode.text;
|
|
62
|
+
return { name, qualifiedName: name, exportPath: "" };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const value = parent.childForFieldName("value");
|
|
68
|
+
if (value === callNode || value?.descendantsOfType("call_expression").includes(callNode)) {
|
|
69
|
+
exportPath = "default";
|
|
70
|
+
const fallback = "__default_export__";
|
|
71
|
+
return { name: fallback, qualifiedName: fallback, exportPath };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
parent = parent.parent;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const fallback = `__forge_${callNode.startPosition.row}_${callNode.startPosition.column}`;
|
|
79
|
+
return { name: fallback, qualifiedName: fallback, exportPath };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function extractSymbolsFromTree(
|
|
83
|
+
root: SyntaxNode,
|
|
84
|
+
file: string,
|
|
85
|
+
source: string,
|
|
86
|
+
): RawSymbol[] {
|
|
87
|
+
const symbols: RawSymbol[] = [];
|
|
88
|
+
const visited = new Set<string>();
|
|
89
|
+
|
|
90
|
+
function visit(node: SyntaxNode): void {
|
|
91
|
+
if (node.type === "call_expression") {
|
|
92
|
+
const functionNode = node.childForFieldName("function");
|
|
93
93
|
if (functionNode && functionNode.type === "identifier") {
|
|
94
|
-
const callee = resolveCalleeName(functionNode);
|
|
95
|
-
if (callee) {
|
|
96
|
-
const kind = classifyForgeCallee(callee);
|
|
97
|
-
if (kind) {
|
|
98
|
-
const key = `${kind}:${node.startIndex}:${node.endIndex}`;
|
|
99
|
-
if (!visited.has(key)) {
|
|
100
|
-
visited.add(key);
|
|
101
|
-
const { name, qualifiedName, exportPath } = inferSymbolName(node);
|
|
102
|
-
symbols.push({
|
|
103
|
-
kind,
|
|
104
|
-
name,
|
|
105
|
-
qualifiedName,
|
|
106
|
-
file,
|
|
107
|
-
span: { start: node.startIndex, end: node.endIndex },
|
|
108
|
-
exportPath,
|
|
109
|
-
sourceSlice: source.slice(node.startIndex, node.endIndex),
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
for (const child of node.namedChildren) {
|
|
118
|
-
visit(child);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
visit(root);
|
|
123
|
-
return symbols;
|
|
124
|
-
}
|
|
94
|
+
const callee = resolveCalleeName(functionNode);
|
|
95
|
+
if (callee) {
|
|
96
|
+
const kind = classifyForgeCallee(callee);
|
|
97
|
+
if (kind) {
|
|
98
|
+
const key = `${kind}:${node.startIndex}:${node.endIndex}`;
|
|
99
|
+
if (!visited.has(key)) {
|
|
100
|
+
visited.add(key);
|
|
101
|
+
const { name, qualifiedName, exportPath } = inferSymbolName(node);
|
|
102
|
+
symbols.push({
|
|
103
|
+
kind,
|
|
104
|
+
name,
|
|
105
|
+
qualifiedName,
|
|
106
|
+
file,
|
|
107
|
+
span: { start: node.startIndex, end: node.endIndex },
|
|
108
|
+
exportPath,
|
|
109
|
+
sourceSlice: source.slice(node.startIndex, node.endIndex),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const child of node.namedChildren) {
|
|
118
|
+
visit(child);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
visit(root);
|
|
123
|
+
return symbols;
|
|
124
|
+
}
|