forgeos 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +1 -0
- package/AGENTS.md +277 -0
- package/CHANGELOG.md +8 -0
- package/CONTRIBUTING.md +58 -0
- package/README.md +377 -0
- package/bin/forge-bun.mjs +110 -0
- package/bin/forge.mjs +19 -0
- package/package.json +96 -0
- package/packages/eslint-plugin-forge/index.ts +15 -0
- package/packages/eslint-plugin-forge/package.json +10 -0
- package/packages/eslint-plugin-forge/src/check-source.ts +95 -0
- package/packages/eslint-plugin-forge/src/load-artifacts.ts +24 -0
- package/packages/eslint-plugin-forge/src/rule-no-forge-guard-violation.ts +93 -0
- package/src/forge/_generated/actionSubscriptions.json +2 -0
- package/src/forge/_generated/actionSubscriptions.ts +10 -0
- package/src/forge/_generated/agentAdapterManifest.json +2 -0
- package/src/forge/_generated/agentAdapterManifest.ts +73 -0
- package/src/forge/_generated/agentContract.json +2 -0
- package/src/forge/_generated/agentContract.ts +912 -0
- package/src/forge/_generated/agentQuickstart.md +32 -0
- package/src/forge/_generated/aiContext.ts +59 -0
- package/src/forge/_generated/aiModels.json +2 -0
- package/src/forge/_generated/aiModels.ts +35 -0
- package/src/forge/_generated/aiProviders.json +2 -0
- package/src/forge/_generated/aiProviders.ts +23 -0
- package/src/forge/_generated/aiRegistry.json +2 -0
- package/src/forge/_generated/aiRegistry.ts +29 -0
- package/src/forge/_generated/api.json +2 -0
- package/src/forge/_generated/api.ts +8 -0
- package/src/forge/_generated/appGraph.json +2 -0
- package/src/forge/_generated/appGraph.ts +14511 -0
- package/src/forge/_generated/appMap.md +35 -0
- package/src/forge/_generated/artifactManifest.json +2 -0
- package/src/forge/_generated/artifactManifest.ts +7 -0
- package/src/forge/_generated/authClaims.json +2 -0
- package/src/forge/_generated/authClaims.ts +13 -0
- package/src/forge/_generated/authConfig.json +2 -0
- package/src/forge/_generated/authConfig.ts +17 -0
- package/src/forge/_generated/authContext.ts +23 -0
- package/src/forge/_generated/authRegistry.json +2 -0
- package/src/forge/_generated/authRegistry.ts +25 -0
- package/src/forge/_generated/buildInfo.json +2 -0
- package/src/forge/_generated/buildInfo.ts +9 -0
- package/src/forge/_generated/capabilityMap.json +2 -0
- package/src/forge/_generated/capabilityMap.md +15 -0
- package/src/forge/_generated/capabilityMap.ts +17 -0
- package/src/forge/_generated/client.ts +282 -0
- package/src/forge/_generated/clientApi.ts +9 -0
- package/src/forge/_generated/clientManifest.json +2 -0
- package/src/forge/_generated/clientManifest.ts +39 -0
- package/src/forge/_generated/clientTypes.ts +78 -0
- package/src/forge/_generated/configRegistry.json +2 -0
- package/src/forge/_generated/configRegistry.ts +4 -0
- package/src/forge/_generated/dataGraph.json +2 -0
- package/src/forge/_generated/dataGraph.ts +8 -0
- package/src/forge/_generated/db.json +2 -0
- package/src/forge/_generated/db.ts +2 -0
- package/src/forge/_generated/dbSecurityManifest.json +2 -0
- package/src/forge/_generated/dbSecurityManifest.ts +15 -0
- package/src/forge/_generated/dbSessionContext.json +2 -0
- package/src/forge/_generated/dbSessionContext.ts +39 -0
- package/src/forge/_generated/deployManifest.json +2 -0
- package/src/forge/_generated/deployManifest.ts +14 -0
- package/src/forge/_generated/devManifest.json +2 -0
- package/src/forge/_generated/devManifest.ts +47 -0
- package/src/forge/_generated/envSchema.json +2 -0
- package/src/forge/_generated/envSchema.ts +59 -0
- package/src/forge/_generated/frontendGraph.json +2 -0
- package/src/forge/_generated/frontendGraph.ts +27 -0
- package/src/forge/_generated/importGuards.json +2 -0
- package/src/forge/_generated/importGuards.ts +652 -0
- package/src/forge/_generated/index.ts +67 -0
- package/src/forge/_generated/liveProductionManifest.json +2 -0
- package/src/forge/_generated/liveProductionManifest.ts +23 -0
- package/src/forge/_generated/liveProtocol.json +2 -0
- package/src/forge/_generated/liveProtocol.ts +21 -0
- package/src/forge/_generated/liveQueryRegistry.json +2 -0
- package/src/forge/_generated/liveQueryRegistry.ts +9 -0
- package/src/forge/_generated/liveTransportConfig.json +2 -0
- package/src/forge/_generated/liveTransportConfig.ts +19 -0
- package/src/forge/_generated/makeRegistry.json +2 -0
- package/src/forge/_generated/makeRegistry.ts +163 -0
- package/src/forge/_generated/makeTemplates.json +2 -0
- package/src/forge/_generated/makeTemplates.ts +61 -0
- package/src/forge/_generated/mockMap.json +2 -0
- package/src/forge/_generated/mockMap.ts +7 -0
- package/src/forge/_generated/operationPlaybooks.md +145 -0
- package/src/forge/_generated/packageGraph.json +2 -0
- package/src/forge/_generated/packageGraph.ts +168569 -0
- package/src/forge/_generated/packageUpgradeRegistry.json +2 -0
- package/src/forge/_generated/packageUpgradeRegistry.ts +15 -0
- package/src/forge/_generated/permissionMatrix.json +2 -0
- package/src/forge/_generated/permissionMatrix.ts +7 -0
- package/src/forge/_generated/policyRegistry.json +2 -0
- package/src/forge/_generated/policyRegistry.ts +11 -0
- package/src/forge/_generated/queryRegistry.json +2 -0
- package/src/forge/_generated/queryRegistry.ts +9 -0
- package/src/forge/_generated/react.d.ts +22 -0
- package/src/forge/_generated/react.ts +29 -0
- package/src/forge/_generated/reactManifest.json +2 -0
- package/src/forge/_generated/reactManifest.ts +19 -0
- package/src/forge/_generated/releaseManifest.json +2 -0
- package/src/forge/_generated/releaseManifest.ts +25 -0
- package/src/forge/_generated/rlsPolicies.json +2 -0
- package/src/forge/_generated/rlsPolicies.sql +34 -0
- package/src/forge/_generated/rlsPolicies.ts +6 -0
- package/src/forge/_generated/runtimeGraph.json +2 -0
- package/src/forge/_generated/runtimeGraph.ts +8 -0
- package/src/forge/_generated/runtimeMatrix.json +2 -0
- package/src/forge/_generated/runtimeMatrix.ts +229125 -0
- package/src/forge/_generated/runtimeRegistry.ts +2 -0
- package/src/forge/_generated/runtimeRules.md +79 -0
- package/src/forge/_generated/secretRegistry.json +2 -0
- package/src/forge/_generated/secretRegistry.ts +50 -0
- package/src/forge/_generated/secretsContext.ts +11 -0
- package/src/forge/_generated/serverApi.ts +10 -0
- package/src/forge/_generated/sourceMapManifest.json +2 -0
- package/src/forge/_generated/sourceMapManifest.ts +7 -0
- package/src/forge/_generated/sqlPlan.json +2 -0
- package/src/forge/_generated/sqlPlan.ts +88 -0
- package/src/forge/_generated/subscriptionManifest.json +2 -0
- package/src/forge/_generated/subscriptionManifest.ts +7 -0
- package/src/forge/_generated/symbolicationManifest.json +2 -0
- package/src/forge/_generated/symbolicationManifest.ts +17 -0
- package/src/forge/_generated/telemetryRegistry.json +2 -0
- package/src/forge/_generated/telemetryRegistry.ts +9 -0
- package/src/forge/_generated/telemetrySinks.json +2 -0
- package/src/forge/_generated/telemetrySinks.ts +11 -0
- package/src/forge/_generated/tenantScope.json +2 -0
- package/src/forge/_generated/tenantScope.ts +8 -0
- package/src/forge/_generated/testGraph.json +2 -0
- package/src/forge/_generated/testGraph.ts +3054 -0
- package/src/forge/_generated/testPlanRegistry.json +2 -0
- package/src/forge/_generated/testPlanRegistry.ts +33 -0
- package/src/forge/_generated/uiRoutes.json +2 -0
- package/src/forge/_generated/uiRoutes.ts +16 -0
- package/src/forge/_generated/uiScenarios.json +2 -0
- package/src/forge/_generated/uiScenarios.ts +30 -0
- package/src/forge/_generated/uiTestManifest.json +2 -0
- package/src/forge/_generated/uiTestManifest.ts +27 -0
- package/src/forge/_generated/workflowRegistry.json +2 -0
- package/src/forge/_generated/workflowRegistry.ts +9 -0
- package/src/forge/_generated/workflowSubscriptions.json +2 -0
- package/src/forge/_generated/workflowSubscriptions.ts +10 -0
- package/src/forge/agent-adapters/index.ts +1002 -0
- package/src/forge/agent-adapters/types.ts +135 -0
- package/src/forge/cli/agent-contract.ts +50 -0
- package/src/forge/cli/ai.ts +148 -0
- package/src/forge/cli/auth.ts +198 -0
- package/src/forge/cli/build.ts +105 -0
- package/src/forge/cli/bun-exec.ts +4 -0
- package/src/forge/cli/commands.ts +1130 -0
- package/src/forge/cli/db.ts +316 -0
- package/src/forge/cli/deps.ts +277 -0
- package/src/forge/cli/dev.ts +529 -0
- package/src/forge/cli/doctor.ts +209 -0
- package/src/forge/cli/feature.ts +485 -0
- package/src/forge/cli/index.ts +25 -0
- package/src/forge/cli/lint-forge.ts +119 -0
- package/src/forge/cli/live.ts +179 -0
- package/src/forge/cli/main.ts +92 -0
- package/src/forge/cli/make.ts +133 -0
- package/src/forge/cli/new.ts +505 -0
- package/src/forge/cli/outbox.ts +297 -0
- package/src/forge/cli/output.ts +114 -0
- package/src/forge/cli/parse.ts +2211 -0
- package/src/forge/cli/policy.ts +204 -0
- package/src/forge/cli/query.ts +91 -0
- package/src/forge/cli/refactor.ts +221 -0
- package/src/forge/cli/release.ts +285 -0
- package/src/forge/cli/rls.ts +322 -0
- package/src/forge/cli/run.ts +76 -0
- package/src/forge/cli/secrets.ts +274 -0
- package/src/forge/cli/self-host.ts +468 -0
- package/src/forge/cli/serve.ts +93 -0
- package/src/forge/cli/telemetry.ts +219 -0
- package/src/forge/cli/verify.ts +587 -0
- package/src/forge/cli/version.ts +1 -0
- package/src/forge/cli/windows.ts +413 -0
- package/src/forge/cli/worker.ts +87 -0
- package/src/forge/cli/workflow.ts +424 -0
- package/src/forge/compiler/action-subscriptions/build.ts +116 -0
- package/src/forge/compiler/action-subscriptions/constants.ts +2 -0
- package/src/forge/compiler/action-subscriptions/index.ts +6 -0
- package/src/forge/compiler/action-subscriptions/parse.ts +6 -0
- package/src/forge/compiler/agent-contract/build.ts +1651 -0
- package/src/forge/compiler/agent-contract/types.ts +326 -0
- package/src/forge/compiler/ai-registry/build.ts +165 -0
- package/src/forge/compiler/ai-registry/constants.ts +2 -0
- package/src/forge/compiler/ai-registry/parse.ts +56 -0
- package/src/forge/compiler/api-surface/build.ts +107 -0
- package/src/forge/compiler/app-graph/build.ts +121 -0
- package/src/forge/compiler/app-graph/classify.ts +10 -0
- package/src/forge/compiler/app-graph/dup-symbol.ts +29 -0
- package/src/forge/compiler/app-graph/extract.ts +124 -0
- package/src/forge/compiler/app-graph/forge-apis.ts +29 -0
- package/src/forge/compiler/app-graph/index.ts +15 -0
- package/src/forge/compiler/app-graph/module-graph.ts +320 -0
- package/src/forge/compiler/app-graph/parser.ts +119 -0
- package/src/forge/compiler/app-graph/symbols.ts +48 -0
- package/src/forge/compiler/app-graph/tsconfig-hash.ts +62 -0
- package/src/forge/compiler/app-graph/types.ts +43 -0
- package/src/forge/compiler/app-graph/versions.ts +14 -0
- package/src/forge/compiler/cache/index.ts +17 -0
- package/src/forge/compiler/cache/key.ts +46 -0
- package/src/forge/compiler/cache/scheduler.ts +72 -0
- package/src/forge/compiler/cache/store.ts +78 -0
- package/src/forge/compiler/classifier/capabilities.ts +78 -0
- package/src/forge/compiler/classifier/classify.ts +113 -0
- package/src/forge/compiler/classifier/contexts.ts +188 -0
- package/src/forge/compiler/classifier/index.ts +18 -0
- package/src/forge/compiler/classifier/runtime-matrix.ts +45 -0
- package/src/forge/compiler/classifier/secrets.ts +41 -0
- package/src/forge/compiler/classifier/signals.ts +129 -0
- package/src/forge/compiler/client-sdk/build-manifest.ts +151 -0
- package/src/forge/compiler/client-sdk/render-client.ts +432 -0
- package/src/forge/compiler/data-graph/build.ts +131 -0
- package/src/forge/compiler/data-graph/constants.ts +5 -0
- package/src/forge/compiler/data-graph/index.ts +6 -0
- package/src/forge/compiler/data-graph/parse.ts +176 -0
- package/src/forge/compiler/data-graph/rls/build.ts +222 -0
- package/src/forge/compiler/data-graph/rls/types.ts +62 -0
- package/src/forge/compiler/data-graph/sql/ddl.ts +390 -0
- package/src/forge/compiler/data-graph/sql/naming.ts +10 -0
- package/src/forge/compiler/data-graph/sql/serialize.ts +85 -0
- package/src/forge/compiler/data-graph/sql/types.ts +37 -0
- package/src/forge/compiler/dev-manifest/build.ts +170 -0
- package/src/forge/compiler/dev-manifest/constants.ts +5 -0
- package/src/forge/compiler/diagnostics/codes.ts +611 -0
- package/src/forge/compiler/diagnostics/create.ts +245 -0
- package/src/forge/compiler/diagnostics/index.ts +55 -0
- package/src/forge/compiler/emitter/artifact-kind.ts +14 -0
- package/src/forge/compiler/emitter/barrel.ts +44 -0
- package/src/forge/compiler/emitter/constants.ts +7 -0
- package/src/forge/compiler/emitter/emit.ts +237 -0
- package/src/forge/compiler/emitter/index.ts +24 -0
- package/src/forge/compiler/emitter/lock.ts +62 -0
- package/src/forge/compiler/emitter/render.ts +73 -0
- package/src/forge/compiler/emitter/write.ts +35 -0
- package/src/forge/compiler/frontend-graph/build.ts +495 -0
- package/src/forge/compiler/fs/index.ts +23 -0
- package/src/forge/compiler/fs/memory.ts +233 -0
- package/src/forge/compiler/fs/node.ts +139 -0
- package/src/forge/compiler/fs/profile.ts +108 -0
- package/src/forge/compiler/fs/types.ts +52 -0
- package/src/forge/compiler/guards/artifacts.ts +96 -0
- package/src/forge/compiler/guards/check-ai-usage.ts +98 -0
- package/src/forge/compiler/guards/check-import-guards.ts +106 -0
- package/src/forge/compiler/guards/check-process-env.ts +98 -0
- package/src/forge/compiler/guards/check-query-usage.ts +76 -0
- package/src/forge/compiler/guards/index.ts +11 -0
- package/src/forge/compiler/guards/propagate-contexts.ts +57 -0
- package/src/forge/compiler/index.ts +17 -0
- package/src/forge/compiler/integration/add.ts +496 -0
- package/src/forge/compiler/integration/index.ts +17 -0
- package/src/forge/compiler/integration/plan.ts +283 -0
- package/src/forge/compiler/integration/render.ts +189 -0
- package/src/forge/compiler/integration/snapshot.ts +52 -0
- package/src/forge/compiler/integration/templates/ai.ts +131 -0
- package/src/forge/compiler/integration/templates/index.ts +8 -0
- package/src/forge/compiler/integration/templates/posthog.ts +145 -0
- package/src/forge/compiler/integration/templates/render.ts +113 -0
- package/src/forge/compiler/integration/templates/sentry.ts +151 -0
- package/src/forge/compiler/integration/templates/stripe.ts +109 -0
- package/src/forge/compiler/integration/templates/types.ts +14 -0
- package/src/forge/compiler/integration/templates/zod.ts +55 -0
- package/src/forge/compiler/live-production/types.ts +122 -0
- package/src/forge/compiler/live-query-registry/build.ts +150 -0
- package/src/forge/compiler/live-query-registry/constants.ts +2 -0
- package/src/forge/compiler/make-registry/build.ts +179 -0
- package/src/forge/compiler/orchestrator/discover.ts +214 -0
- package/src/forge/compiler/orchestrator/fast-check.ts +117 -0
- package/src/forge/compiler/orchestrator/generate-lock.ts +138 -0
- package/src/forge/compiler/orchestrator/guards.ts +5 -0
- package/src/forge/compiler/orchestrator/index.ts +27 -0
- package/src/forge/compiler/orchestrator/manifest-hashes.ts +21 -0
- package/src/forge/compiler/orchestrator/manifest.ts +92 -0
- package/src/forge/compiler/orchestrator/orphans.ts +51 -0
- package/src/forge/compiler/orchestrator/plan.ts +876 -0
- package/src/forge/compiler/orchestrator/profile.ts +36 -0
- package/src/forge/compiler/orchestrator/run.ts +277 -0
- package/src/forge/compiler/orchestrator/serialize.ts +886 -0
- package/src/forge/compiler/orchestrator/session.ts +96 -0
- package/src/forge/compiler/orchestrator/types.ts +31 -0
- package/src/forge/compiler/orchestrator/verify.ts +38 -0
- package/src/forge/compiler/orchestrator/workspace-index.ts +154 -0
- package/src/forge/compiler/package-graph/capabilities-stub.ts +33 -0
- package/src/forge/compiler/package-graph/checksum.ts +97 -0
- package/src/forge/compiler/package-graph/compiler.ts +392 -0
- package/src/forge/compiler/package-graph/constants.ts +4 -0
- package/src/forge/compiler/package-graph/dts-extractor.ts +142 -0
- package/src/forge/compiler/package-graph/exports-discovery.ts +84 -0
- package/src/forge/compiler/package-graph/extract-dts.ts +32 -0
- package/src/forge/compiler/package-graph/index.ts +33 -0
- package/src/forge/compiler/package-graph/jsdoc.ts +62 -0
- package/src/forge/compiler/package-graph/read-file.ts +21 -0
- package/src/forge/compiler/package-graph/resolve.ts +127 -0
- package/src/forge/compiler/package-manager/adapter.ts +237 -0
- package/src/forge/compiler/package-manager/bun-executable.ts +92 -0
- package/src/forge/compiler/package-manager/commands.ts +47 -0
- package/src/forge/compiler/package-manager/detect.ts +79 -0
- package/src/forge/compiler/package-manager/executor.ts +117 -0
- package/src/forge/compiler/package-manager/index.ts +22 -0
- package/src/forge/compiler/package-manager/parse-spec.ts +16 -0
- package/src/forge/compiler/package-manager/version.ts +27 -0
- package/src/forge/compiler/package-upgrades/apply.ts +195 -0
- package/src/forge/compiler/package-upgrades/comparator.ts +181 -0
- package/src/forge/compiler/package-upgrades/impact.ts +139 -0
- package/src/forge/compiler/package-upgrades/markdown.ts +97 -0
- package/src/forge/compiler/package-upgrades/planner.ts +532 -0
- package/src/forge/compiler/package-upgrades/risk.ts +208 -0
- package/src/forge/compiler/package-upgrades/types.ts +174 -0
- package/src/forge/compiler/policy-registry/build.ts +266 -0
- package/src/forge/compiler/policy-registry/constants.ts +2 -0
- package/src/forge/compiler/policy-registry/parse.ts +81 -0
- package/src/forge/compiler/primitives/compare.ts +26 -0
- package/src/forge/compiler/primitives/hash.ts +40 -0
- package/src/forge/compiler/primitives/header.ts +45 -0
- package/src/forge/compiler/primitives/index.ts +45 -0
- package/src/forge/compiler/primitives/paths.ts +24 -0
- package/src/forge/compiler/primitives/result.ts +164 -0
- package/src/forge/compiler/primitives/serialize.ts +66 -0
- package/src/forge/compiler/primitives/sort.ts +87 -0
- package/src/forge/compiler/query-registry/build.ts +114 -0
- package/src/forge/compiler/query-registry/constants.ts +2 -0
- package/src/forge/compiler/recipes/definitions.ts +289 -0
- package/src/forge/compiler/recipes/helpers.ts +37 -0
- package/src/forge/compiler/recipes/index.ts +21 -0
- package/src/forge/compiler/recipes/registry.ts +102 -0
- package/src/forge/compiler/release/build.ts +100 -0
- package/src/forge/compiler/release/types.ts +119 -0
- package/src/forge/compiler/runtime-graph/build.ts +137 -0
- package/src/forge/compiler/runtime-graph/constants.ts +5 -0
- package/src/forge/compiler/runtime-graph/index.ts +5 -0
- package/src/forge/compiler/sandbox/artifact-sanitize.ts +26 -0
- package/src/forge/compiler/sandbox/backends/child.ts +123 -0
- package/src/forge/compiler/sandbox/backends/docker.ts +173 -0
- package/src/forge/compiler/sandbox/index.ts +51 -0
- package/src/forge/compiler/sandbox/inspect.ts +143 -0
- package/src/forge/compiler/sandbox/inspector-entry.ts +115 -0
- package/src/forge/compiler/sandbox/limits.ts +31 -0
- package/src/forge/compiler/sandbox/scrub-env.ts +60 -0
- package/src/forge/compiler/sandbox/secret-scan.ts +54 -0
- package/src/forge/compiler/sandbox/serialize.ts +106 -0
- package/src/forge/compiler/sandbox/types.ts +7 -0
- package/src/forge/compiler/secret-registry/build.ts +123 -0
- package/src/forge/compiler/telemetry-registry/build.ts +89 -0
- package/src/forge/compiler/telemetry-registry/constants.ts +2 -0
- package/src/forge/compiler/telemetry-registry/parse.ts +13 -0
- package/src/forge/compiler/test-graph/build.ts +277 -0
- package/src/forge/compiler/types/action-subscriptions.ts +19 -0
- package/src/forge/compiler/types/ai-registry.ts +33 -0
- package/src/forge/compiler/types/app-graph.ts +80 -0
- package/src/forge/compiler/types/capability.ts +29 -0
- package/src/forge/compiler/types/classification.ts +9 -0
- package/src/forge/compiler/types/cli.ts +159 -0
- package/src/forge/compiler/types/data-graph.ts +24 -0
- package/src/forge/compiler/types/dev-manifest.ts +41 -0
- package/src/forge/compiler/types/diagnostic.ts +12 -0
- package/src/forge/compiler/types/emit.ts +25 -0
- package/src/forge/compiler/types/frontend-graph.ts +81 -0
- package/src/forge/compiler/types/import-guards.ts +19 -0
- package/src/forge/compiler/types/index.ts +98 -0
- package/src/forge/compiler/types/integration.ts +25 -0
- package/src/forge/compiler/types/json.ts +3 -0
- package/src/forge/compiler/types/live-query-registry.ts +32 -0
- package/src/forge/compiler/types/lock.ts +37 -0
- package/src/forge/compiler/types/package-graph.ts +84 -0
- package/src/forge/compiler/types/policy-registry.ts +69 -0
- package/src/forge/compiler/types/query-registry.ts +18 -0
- package/src/forge/compiler/types/runtime-graph.ts +30 -0
- package/src/forge/compiler/types/runtime-matrix.ts +16 -0
- package/src/forge/compiler/types/runtime.ts +30 -0
- package/src/forge/compiler/types/sandbox.ts +24 -0
- package/src/forge/compiler/types/secret-registry.ts +38 -0
- package/src/forge/compiler/types/telemetry-registry.ts +26 -0
- package/src/forge/compiler/types/test-graph.ts +45 -0
- package/src/forge/compiler/types/workflow-registry.ts +42 -0
- package/src/forge/compiler/workflow-registry/build.ts +180 -0
- package/src/forge/compiler/workflow-registry/constants.ts +2 -0
- package/src/forge/compiler/workflow-registry/index.ts +5 -0
- package/src/forge/compiler/workflow-registry/parse.ts +19 -0
- package/src/forge/dev/server.ts +1379 -0
- package/src/forge/dev/types.ts +49 -0
- package/src/forge/dev/watch.ts +109 -0
- package/src/forge/dev-console/cycle.ts +652 -0
- package/src/forge/dev-console/types.ts +99 -0
- package/src/forge/feature/compiler.ts +656 -0
- package/src/forge/feature/examples.ts +125 -0
- package/src/forge/feature/types.ts +177 -0
- package/src/forge/impact/index.ts +1160 -0
- package/src/forge/impact/types.ts +151 -0
- package/src/forge/intent/index.ts +490 -0
- package/src/forge/intent/types.ts +73 -0
- package/src/forge/make/fields.ts +146 -0
- package/src/forge/make/index.ts +1101 -0
- package/src/forge/make/naming.ts +42 -0
- package/src/forge/make/templates.ts +525 -0
- package/src/forge/make/types.ts +151 -0
- package/src/forge/platform/module.ts +20 -0
- package/src/forge/policy.ts +1 -0
- package/src/forge/react/index.ts +418 -0
- package/src/forge/refactor/index.ts +1936 -0
- package/src/forge/refactor/text-utils.ts +34 -0
- package/src/forge/refactor/types.ts +191 -0
- package/src/forge/refactor/workspace-fs.ts +171 -0
- package/src/forge/repair/index.ts +656 -0
- package/src/forge/repair/rules/index.ts +476 -0
- package/src/forge/repair/types.ts +175 -0
- package/src/forge/review/index.ts +992 -0
- package/src/forge/review/types.ts +196 -0
- package/src/forge/runtime/ai/check.ts +86 -0
- package/src/forge/runtime/ai/context.ts +394 -0
- package/src/forge/runtime/ai/cost-estimator.ts +41 -0
- package/src/forge/runtime/ai/mock.ts +49 -0
- package/src/forge/runtime/ai/providers.ts +78 -0
- package/src/forge/runtime/ai/state.ts +17 -0
- package/src/forge/runtime/ai/types.ts +67 -0
- package/src/forge/runtime/auth/authenticate.ts +58 -0
- package/src/forge/runtime/auth/claims.ts +119 -0
- package/src/forge/runtime/auth/config.ts +148 -0
- package/src/forge/runtime/auth/errors.ts +45 -0
- package/src/forge/runtime/auth/evaluate.ts +126 -0
- package/src/forge/runtime/auth/resolve.ts +74 -0
- package/src/forge/runtime/auth/types.ts +87 -0
- package/src/forge/runtime/auth/verifier.ts +138 -0
- package/src/forge/runtime/context/create-context.ts +204 -0
- package/src/forge/runtime/context/create-query-context.ts +34 -0
- package/src/forge/runtime/db/adapter.ts +31 -0
- package/src/forge/runtime/db/factory.ts +83 -0
- package/src/forge/runtime/db/generated-client.ts +294 -0
- package/src/forge/runtime/db/memory-adapter.ts +706 -0
- package/src/forge/runtime/db/migrate.ts +132 -0
- package/src/forge/runtime/db/outbox.ts +54 -0
- package/src/forge/runtime/db/pglite-adapter.ts +51 -0
- package/src/forge/runtime/db/postgres-adapter.ts +112 -0
- package/src/forge/runtime/db/read-only-client.ts +97 -0
- package/src/forge/runtime/db/session-context.ts +62 -0
- package/src/forge/runtime/executor.ts +446 -0
- package/src/forge/runtime/live/dependency-tracker.ts +57 -0
- package/src/forge/runtime/live/invalidation-log.ts +189 -0
- package/src/forge/runtime/live/live-query-runner.ts +267 -0
- package/src/forge/runtime/live/registry.ts +28 -0
- package/src/forge/runtime/live/sse.ts +75 -0
- package/src/forge/runtime/live/subscription-manager.ts +443 -0
- package/src/forge/runtime/live/types.ts +143 -0
- package/src/forge/runtime/outbox/claim.ts +153 -0
- package/src/forge/runtime/outbox/process.ts +298 -0
- package/src/forge/runtime/outbox/retry.ts +8 -0
- package/src/forge/runtime/outbox/subscriptions.ts +33 -0
- package/src/forge/runtime/outbox/types.ts +69 -0
- package/src/forge/runtime/policy/check.ts +157 -0
- package/src/forge/runtime/policy/load.ts +55 -0
- package/src/forge/runtime/query/registry.ts +19 -0
- package/src/forge/runtime/query/run-query.ts +347 -0
- package/src/forge/runtime/release/runtime.ts +322 -0
- package/src/forge/runtime/release/symbolicate.ts +175 -0
- package/src/forge/runtime/runner/command-transaction.ts +193 -0
- package/src/forge/runtime/runner/run-entry.ts +226 -0
- package/src/forge/runtime/secrets/check.ts +78 -0
- package/src/forge/runtime/secrets/create-context.ts +138 -0
- package/src/forge/runtime/secrets/env-loader.ts +94 -0
- package/src/forge/runtime/secrets/runtime-bundle.ts +47 -0
- package/src/forge/runtime/secrets/types.ts +31 -0
- package/src/forge/runtime/telemetry/buffer.ts +87 -0
- package/src/forge/runtime/telemetry/context.ts +192 -0
- package/src/forge/runtime/telemetry/correlation.ts +13 -0
- package/src/forge/runtime/telemetry/flush.ts +190 -0
- package/src/forge/runtime/telemetry/process.ts +20 -0
- package/src/forge/runtime/telemetry/scrubber.ts +115 -0
- package/src/forge/runtime/telemetry/sinks/local-jsonl.ts +39 -0
- package/src/forge/runtime/telemetry/sinks/posthog.ts +64 -0
- package/src/forge/runtime/telemetry/sinks/sentry.ts +60 -0
- package/src/forge/runtime/telemetry/spans.ts +58 -0
- package/src/forge/runtime/telemetry/types.ts +64 -0
- package/src/forge/runtime/workflows/cancel.ts +26 -0
- package/src/forge/runtime/workflows/create-run.ts +98 -0
- package/src/forge/runtime/workflows/process-run.ts +182 -0
- package/src/forge/runtime/workflows/process-step.ts +190 -0
- package/src/forge/runtime/workflows/process.ts +260 -0
- package/src/forge/runtime/workflows/registry.ts +51 -0
- package/src/forge/runtime/workflows/resolve-step.ts +46 -0
- package/src/forge/runtime/workflows/retry-run.ts +44 -0
- package/src/forge/runtime/workflows/retry.ts +8 -0
- package/src/forge/runtime/workflows/sanitize.ts +19 -0
- package/src/forge/runtime/workflows/start-from-outbox.ts +71 -0
- package/src/forge/runtime/workflows/types.ts +77 -0
- package/src/forge/server.ts +96 -0
- package/src/forge/ui/index.ts +770 -0
- package/src/forge/ui/types.ts +191 -0
- package/templates/b2b-support-web/.env.example +22 -0
- package/templates/b2b-support-web/.vscode/settings.json +14 -0
- package/templates/b2b-support-web/AGENTS.md +108 -0
- package/templates/b2b-support-web/README.md +48 -0
- package/templates/b2b-support-web/forge.config.ts +3 -0
- package/templates/b2b-support-web/package.json +34 -0
- package/templates/b2b-support-web/src/actions/captureTicketCreated.ts +14 -0
- package/templates/b2b-support-web/src/commands/closeTicket.ts +20 -0
- package/templates/b2b-support-web/src/commands/createTicket.ts +47 -0
- package/templates/b2b-support-web/src/commands/manageBilling.ts +9 -0
- package/templates/b2b-support-web/src/forge/schema.ts +35 -0
- package/templates/b2b-support-web/src/policies.ts +9 -0
- package/templates/b2b-support-web/src/queries/getTicket.ts +6 -0
- package/templates/b2b-support-web/src/queries/listTickets.ts +6 -0
- package/templates/b2b-support-web/src/queries/liveTickets.ts +9 -0
- package/templates/b2b-support-web/src/workflows/triageTicketWorkflow.ts +64 -0
- package/templates/b2b-support-web/tsconfig.json +14 -0
- package/templates/b2b-support-web/web/app/globals.css +77 -0
- package/templates/b2b-support-web/web/app/layout.tsx +13 -0
- package/templates/b2b-support-web/web/app/page.tsx +13 -0
- package/templates/b2b-support-web/web/app/providers.tsx +21 -0
- package/templates/b2b-support-web/web/app/tickets/page.tsx +21 -0
- package/templates/b2b-support-web/web/components/CreateTicketForm.tsx +43 -0
- package/templates/b2b-support-web/web/components/PolicyDeniedDemo.tsx +31 -0
- package/templates/b2b-support-web/web/components/TicketList.tsx +52 -0
- package/templates/b2b-support-web/web/components/TraceDetails.tsx +18 -0
- package/templates/b2b-support-web/web/components/TriageStatus.tsx +13 -0
- package/templates/b2b-support-web/web/lib/forge.ts +13 -0
- package/templates/b2b-support-web/web/next-env.d.ts +5 -0
- package/templates/b2b-support-web/web/next.config.ts +8 -0
- package/templates/b2b-support-web/web/package.json +21 -0
- package/templates/b2b-support-web/web/tsconfig.json +30 -0
- package/templates/minimal-web/.vscode/settings.json +14 -0
- package/templates/minimal-web/README.md +21 -0
- package/templates/minimal-web/forge.config.ts +3 -0
- package/templates/minimal-web/package.json +32 -0
- package/templates/minimal-web/src/actions/logNoteCreated.ts +11 -0
- package/templates/minimal-web/src/commands/createNote.ts +26 -0
- package/templates/minimal-web/src/forge/schema.ts +12 -0
- package/templates/minimal-web/src/policies.ts +6 -0
- package/templates/minimal-web/src/queries/listNotes.ts +8 -0
- package/templates/minimal-web/src/queries/liveNotes.ts +8 -0
- package/templates/minimal-web/tsconfig.json +15 -0
- package/templates/minimal-web/web/index.html +12 -0
- package/templates/minimal-web/web/package.json +21 -0
- package/templates/minimal-web/web/src/App.tsx +89 -0
- package/templates/minimal-web/web/src/lib/forge.ts +13 -0
- package/templates/minimal-web/web/src/main.tsx +13 -0
- package/templates/minimal-web/web/src/styles.css +156 -0
- package/templates/minimal-web/web/tsconfig.json +18 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InMemoryFileSystem — a test/double {@link FileSystem} with no disk access.
|
|
3
|
+
*
|
|
4
|
+
* Paths are normalised to forward slashes and stored flat. Directories are
|
|
5
|
+
* tracked both explicitly (via {@link InMemoryFileSystem.mkdirp}) and implicitly
|
|
6
|
+
* (any ancestor of a written file). This mirrors the observable behaviour of
|
|
7
|
+
* {@link NodeFileSystem} closely enough for compiler/authoring unit tests.
|
|
8
|
+
*/
|
|
9
|
+
import type { DirEntry, FileStat, FileSystem } from "./types.ts";
|
|
10
|
+
|
|
11
|
+
function normalize(path: string): string {
|
|
12
|
+
const slashed = path.replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
13
|
+
if (slashed.length > 1 && slashed.endsWith("/")) {
|
|
14
|
+
return slashed.slice(0, -1);
|
|
15
|
+
}
|
|
16
|
+
return slashed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parentOf(path: string): string | null {
|
|
20
|
+
const idx = path.lastIndexOf("/");
|
|
21
|
+
if (idx <= 0) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return path.slice(0, idx);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class InMemoryFileSystem implements FileSystem {
|
|
28
|
+
private readonly files = new Map<string, string>();
|
|
29
|
+
private readonly dirs = new Set<string>();
|
|
30
|
+
private tempCounter = 0;
|
|
31
|
+
|
|
32
|
+
constructor(initial?: Record<string, string>) {
|
|
33
|
+
if (initial) {
|
|
34
|
+
for (const [path, content] of Object.entries(initial)) {
|
|
35
|
+
this.writeText(path, content);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Snapshot of all stored files keyed by normalised path. */
|
|
41
|
+
snapshot(): Record<string, string> {
|
|
42
|
+
return Object.fromEntries(this.files);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private addAncestors(path: string): void {
|
|
46
|
+
let parent = parentOf(path);
|
|
47
|
+
while (parent !== null) {
|
|
48
|
+
this.dirs.add(parent);
|
|
49
|
+
parent = parentOf(parent);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
readText(path: string): string | null {
|
|
54
|
+
const key = normalize(path);
|
|
55
|
+
return this.files.has(key) ? (this.files.get(key) as string) : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
writeText(path: string, content: string): void {
|
|
59
|
+
const key = normalize(path);
|
|
60
|
+
this.files.set(key, content);
|
|
61
|
+
this.addAncestors(key);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exists(path: string): boolean {
|
|
65
|
+
const key = normalize(path);
|
|
66
|
+
return this.files.has(key) || this.isDirectory(key);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
isDirectory(path: string): boolean {
|
|
70
|
+
const key = normalize(path);
|
|
71
|
+
if (this.dirs.has(key)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
const prefix = `${key}/`;
|
|
75
|
+
for (const file of this.files.keys()) {
|
|
76
|
+
if (file.startsWith(prefix)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
readDir(path: string): DirEntry[] {
|
|
84
|
+
const key = normalize(path);
|
|
85
|
+
const prefix = key === "" ? "" : `${key}/`;
|
|
86
|
+
const childDirs = new Set<string>();
|
|
87
|
+
const childFiles = new Set<string>();
|
|
88
|
+
|
|
89
|
+
const consider = (entry: string, isFile: boolean): void => {
|
|
90
|
+
if (!entry.startsWith(prefix) || entry === key) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const rest = entry.slice(prefix.length);
|
|
94
|
+
if (rest === "") {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const slash = rest.indexOf("/");
|
|
98
|
+
if (slash === -1) {
|
|
99
|
+
if (isFile) {
|
|
100
|
+
childFiles.add(rest);
|
|
101
|
+
} else {
|
|
102
|
+
childDirs.add(rest);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
childDirs.add(rest.slice(0, slash));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
for (const file of this.files.keys()) {
|
|
110
|
+
consider(file, true);
|
|
111
|
+
}
|
|
112
|
+
for (const dir of this.dirs) {
|
|
113
|
+
consider(dir, false);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const entries: DirEntry[] = [];
|
|
117
|
+
for (const name of childDirs) {
|
|
118
|
+
entries.push({ name, isDirectory: true, isFile: false });
|
|
119
|
+
}
|
|
120
|
+
for (const name of childFiles) {
|
|
121
|
+
if (!childDirs.has(name)) {
|
|
122
|
+
entries.push({ name, isDirectory: false, isFile: true });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
mkdirp(path: string): void {
|
|
129
|
+
const key = normalize(path);
|
|
130
|
+
this.dirs.add(key);
|
|
131
|
+
this.addAncestors(key);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
rename(from: string, to: string): void {
|
|
135
|
+
const fromKey = normalize(from);
|
|
136
|
+
const toKey = normalize(to);
|
|
137
|
+
|
|
138
|
+
if (this.files.has(fromKey)) {
|
|
139
|
+
this.files.set(toKey, this.files.get(fromKey) as string);
|
|
140
|
+
this.files.delete(fromKey);
|
|
141
|
+
this.addAncestors(toKey);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Directory move: relocate every descendant file and dir.
|
|
146
|
+
const prefix = `${fromKey}/`;
|
|
147
|
+
for (const file of [...this.files.keys()]) {
|
|
148
|
+
if (file.startsWith(prefix)) {
|
|
149
|
+
const moved = `${toKey}/${file.slice(prefix.length)}`;
|
|
150
|
+
this.files.set(moved, this.files.get(file) as string);
|
|
151
|
+
this.files.delete(file);
|
|
152
|
+
this.addAncestors(moved);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const dir of [...this.dirs]) {
|
|
156
|
+
if (dir === fromKey || dir.startsWith(prefix)) {
|
|
157
|
+
this.dirs.delete(dir);
|
|
158
|
+
const moved = dir === fromKey ? toKey : `${toKey}/${dir.slice(prefix.length)}`;
|
|
159
|
+
this.dirs.add(moved);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
remove(path: string): void {
|
|
165
|
+
const key = normalize(path);
|
|
166
|
+
this.files.delete(key);
|
|
167
|
+
this.dirs.delete(key);
|
|
168
|
+
const prefix = `${key}/`;
|
|
169
|
+
for (const file of [...this.files.keys()]) {
|
|
170
|
+
if (file.startsWith(prefix)) {
|
|
171
|
+
this.files.delete(file);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const dir of [...this.dirs]) {
|
|
175
|
+
if (dir.startsWith(prefix)) {
|
|
176
|
+
this.dirs.delete(dir);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
copy(from: string, to: string): void {
|
|
182
|
+
const fromKey = normalize(from);
|
|
183
|
+
const toKey = normalize(to);
|
|
184
|
+
|
|
185
|
+
if (this.files.has(fromKey)) {
|
|
186
|
+
this.writeText(toKey, this.files.get(fromKey) as string);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const prefix = `${fromKey}/`;
|
|
191
|
+
for (const file of [...this.files.keys()]) {
|
|
192
|
+
if (file.startsWith(prefix)) {
|
|
193
|
+
const copied = `${toKey}/${file.slice(prefix.length)}`;
|
|
194
|
+
this.writeText(copied, this.files.get(file) as string);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
this.mkdirp(toKey);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
appendText(path: string, content: string): void {
|
|
201
|
+
const existing = this.readText(path) ?? "";
|
|
202
|
+
this.writeText(path, existing + content);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
makeTempDir(prefix: string): string {
|
|
206
|
+
this.tempCounter += 1;
|
|
207
|
+
const dir = `${normalize(prefix)}${this.tempCounter.toString(36)}${Date.now().toString(36)}`;
|
|
208
|
+
this.mkdirp(dir);
|
|
209
|
+
return dir;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
stat(path: string): FileStat | null {
|
|
213
|
+
const key = normalize(path);
|
|
214
|
+
if (this.files.has(key)) {
|
|
215
|
+
const content = this.files.get(key) as string;
|
|
216
|
+
return {
|
|
217
|
+
size: content.length,
|
|
218
|
+
mtimeMs: 0,
|
|
219
|
+
isDirectory: false,
|
|
220
|
+
isFile: true,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (this.isDirectory(key)) {
|
|
224
|
+
return {
|
|
225
|
+
size: 0,
|
|
226
|
+
mtimeMs: 0,
|
|
227
|
+
isDirectory: true,
|
|
228
|
+
isFile: false,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeFileSystem — the production {@link FileSystem} backed by `node:fs`.
|
|
3
|
+
*
|
|
4
|
+
* This is the single place in the codebase that should reach for synchronous
|
|
5
|
+
* `node:fs` primitives. Everything else depends on the {@link FileSystem}
|
|
6
|
+
* interface so it can be unit-tested against {@link InMemoryFileSystem}.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
appendFileSync,
|
|
10
|
+
cpSync,
|
|
11
|
+
existsSync,
|
|
12
|
+
mkdirSync,
|
|
13
|
+
mkdtempSync,
|
|
14
|
+
readFileSync,
|
|
15
|
+
readdirSync,
|
|
16
|
+
renameSync,
|
|
17
|
+
rmSync,
|
|
18
|
+
statSync,
|
|
19
|
+
writeFileSync,
|
|
20
|
+
} from "node:fs";
|
|
21
|
+
import { basename, dirname, join } from "node:path";
|
|
22
|
+
import type { DirEntry, FileStat, FileSystem } from "./types.ts";
|
|
23
|
+
|
|
24
|
+
export class NodeFileSystem implements FileSystem {
|
|
25
|
+
readText(path: string): string | null {
|
|
26
|
+
try {
|
|
27
|
+
return readFileSync(path, "utf8");
|
|
28
|
+
} catch (error) {
|
|
29
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
30
|
+
if (code === "ENOENT" || code === "EISDIR") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Atomic write: stages content in a sibling temp file and renames it into
|
|
39
|
+
* place, so a crash mid-write never leaves a partially written artifact.
|
|
40
|
+
*/
|
|
41
|
+
writeText(path: string, content: string): void {
|
|
42
|
+
const directory = dirname(path);
|
|
43
|
+
mkdirSync(directory, { recursive: true });
|
|
44
|
+
const temporaryPath = join(
|
|
45
|
+
directory,
|
|
46
|
+
`.${basename(path)}.${process.pid}.tmp`,
|
|
47
|
+
);
|
|
48
|
+
try {
|
|
49
|
+
writeFileSync(temporaryPath, content, "utf8");
|
|
50
|
+
try {
|
|
51
|
+
renameSync(temporaryPath, path);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
54
|
+
if (process.platform !== "win32" || (code !== "EEXIST" && code !== "EPERM")) {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
rmSync(path, { force: true });
|
|
58
|
+
renameSync(temporaryPath, path);
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
try {
|
|
62
|
+
rmSync(temporaryPath, { force: true });
|
|
63
|
+
} catch {
|
|
64
|
+
// Ignore cleanup failures while surfacing the original write error.
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exists(path: string): boolean {
|
|
71
|
+
return existsSync(path);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
readDir(path: string): DirEntry[] {
|
|
75
|
+
if (!existsSync(path)) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return readdirSync(path, { withFileTypes: true }).map((entry) => ({
|
|
79
|
+
name: entry.name,
|
|
80
|
+
isDirectory: entry.isDirectory(),
|
|
81
|
+
isFile: entry.isFile(),
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
mkdirp(path: string): void {
|
|
86
|
+
mkdirSync(path, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
rename(from: string, to: string): void {
|
|
90
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
91
|
+
renameSync(from, to);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
copy(from: string, to: string): void {
|
|
95
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
96
|
+
cpSync(from, to, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
appendText(path: string, content: string): void {
|
|
100
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
101
|
+
appendFileSync(path, content, "utf8");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
makeTempDir(prefix: string): string {
|
|
105
|
+
mkdirSync(dirname(prefix), { recursive: true });
|
|
106
|
+
return mkdtempSync(prefix);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
remove(path: string): void {
|
|
110
|
+
if (existsSync(path)) {
|
|
111
|
+
rmSync(path, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
isDirectory(path: string): boolean {
|
|
116
|
+
return existsSync(path) && statSync(path).isDirectory();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
stat(path: string): FileStat | null {
|
|
120
|
+
try {
|
|
121
|
+
const entry = statSync(path);
|
|
122
|
+
return {
|
|
123
|
+
size: entry.size,
|
|
124
|
+
mtimeMs: entry.mtimeMs,
|
|
125
|
+
isDirectory: entry.isDirectory(),
|
|
126
|
+
isFile: entry.isFile(),
|
|
127
|
+
};
|
|
128
|
+
} catch (error) {
|
|
129
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
130
|
+
if (code === "ENOENT") {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Shared singleton for production call sites that want a default backend. */
|
|
139
|
+
export const nodeFileSystem = new NodeFileSystem();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { DirEntry, FileStat, FileSystem } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
export interface FileSystemProfile {
|
|
4
|
+
readText: number;
|
|
5
|
+
readTextBytes: number;
|
|
6
|
+
writeText: number;
|
|
7
|
+
writeTextBytes: number;
|
|
8
|
+
readDir: number;
|
|
9
|
+
stat: number;
|
|
10
|
+
exists: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function emptyProfile(): FileSystemProfile {
|
|
14
|
+
return {
|
|
15
|
+
readText: 0,
|
|
16
|
+
readTextBytes: 0,
|
|
17
|
+
writeText: 0,
|
|
18
|
+
writeTextBytes: 0,
|
|
19
|
+
readDir: 0,
|
|
20
|
+
stat: 0,
|
|
21
|
+
exists: 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let activeProfile: FileSystemProfile | null = null;
|
|
26
|
+
|
|
27
|
+
export function isForgeProfileEnabled(): boolean {
|
|
28
|
+
return process.env.FORGE_PROFILE === "1" || process.env.FORGE_PROFILE === "true";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getFileSystemProfile(): FileSystemProfile | null {
|
|
32
|
+
return activeProfile;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function resetFileSystemProfile(): void {
|
|
36
|
+
activeProfile = isForgeProfileEnabled() ? emptyProfile() : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function formatFileSystemProfile(profile: FileSystemProfile): string {
|
|
40
|
+
return [
|
|
41
|
+
"forge fs profile:",
|
|
42
|
+
` readText: ${profile.readText} (${profile.readTextBytes} bytes)`,
|
|
43
|
+
` writeText: ${profile.writeText} (${profile.writeTextBytes} bytes)`,
|
|
44
|
+
` readDir: ${profile.readDir}`,
|
|
45
|
+
` stat: ${profile.stat}`,
|
|
46
|
+
` exists: ${profile.exists}`,
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createProfiledFileSystem(inner: FileSystem): FileSystem {
|
|
51
|
+
if (!activeProfile) {
|
|
52
|
+
activeProfile = emptyProfile();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const profile = activeProfile;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
readText(path: string): string | null {
|
|
59
|
+
const content = inner.readText(path);
|
|
60
|
+
profile.readText += 1;
|
|
61
|
+
if (content !== null) {
|
|
62
|
+
profile.readTextBytes += content.length;
|
|
63
|
+
}
|
|
64
|
+
return content;
|
|
65
|
+
},
|
|
66
|
+
writeText(path: string, content: string): void {
|
|
67
|
+
profile.writeText += 1;
|
|
68
|
+
profile.writeTextBytes += content.length;
|
|
69
|
+
inner.writeText(path, content);
|
|
70
|
+
},
|
|
71
|
+
exists(path: string): boolean {
|
|
72
|
+
profile.exists += 1;
|
|
73
|
+
return inner.exists(path);
|
|
74
|
+
},
|
|
75
|
+
readDir(path: string): DirEntry[] {
|
|
76
|
+
profile.readDir += 1;
|
|
77
|
+
return inner.readDir(path);
|
|
78
|
+
},
|
|
79
|
+
mkdirp(path: string): void {
|
|
80
|
+
inner.mkdirp(path);
|
|
81
|
+
},
|
|
82
|
+
rename(from: string, to: string): void {
|
|
83
|
+
inner.rename(from, to);
|
|
84
|
+
},
|
|
85
|
+
copy(from: string, to: string): void {
|
|
86
|
+
inner.copy(from, to);
|
|
87
|
+
},
|
|
88
|
+
appendText(path: string, content: string): void {
|
|
89
|
+
profile.writeText += 1;
|
|
90
|
+
profile.writeTextBytes += content.length;
|
|
91
|
+
inner.appendText(path, content);
|
|
92
|
+
},
|
|
93
|
+
makeTempDir(prefix: string): string {
|
|
94
|
+
return inner.makeTempDir(prefix);
|
|
95
|
+
},
|
|
96
|
+
remove(path: string): void {
|
|
97
|
+
inner.remove(path);
|
|
98
|
+
},
|
|
99
|
+
isDirectory(path: string): boolean {
|
|
100
|
+
profile.exists += 1;
|
|
101
|
+
return inner.isDirectory(path);
|
|
102
|
+
},
|
|
103
|
+
stat(path: string): FileStat | null {
|
|
104
|
+
profile.stat += 1;
|
|
105
|
+
return inner.stat(path);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileSystem — a minimal, injectable I/O abstraction.
|
|
3
|
+
*
|
|
4
|
+
* ForgeOS leaf code calls `node:fs` synchronous APIs directly, which makes pure
|
|
5
|
+
* unit testing impossible without touching the real disk or monkey-patching
|
|
6
|
+
* modules. This interface captures exactly the operations the compiler and
|
|
7
|
+
* authoring tools need, so production code can run on {@link NodeFileSystem}
|
|
8
|
+
* while tests run on an in-memory backend.
|
|
9
|
+
*
|
|
10
|
+
* The surface is intentionally synchronous to match the existing call sites and
|
|
11
|
+
* the deterministic, single-shot nature of the generators.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface DirEntry {
|
|
15
|
+
name: string;
|
|
16
|
+
isDirectory: boolean;
|
|
17
|
+
isFile: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FileStat {
|
|
21
|
+
size: number;
|
|
22
|
+
mtimeMs: number;
|
|
23
|
+
isDirectory: boolean;
|
|
24
|
+
isFile: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface FileSystem {
|
|
28
|
+
/** Return file contents as UTF-8, or `null` when the path does not exist. */
|
|
29
|
+
readText(path: string): string | null;
|
|
30
|
+
/** Write UTF-8 contents, creating parent directories as needed. */
|
|
31
|
+
writeText(path: string, content: string): void;
|
|
32
|
+
/** Whether a file or directory exists at the path. */
|
|
33
|
+
exists(path: string): boolean;
|
|
34
|
+
/** List immediate entries of a directory. Returns `[]` for a missing dir. */
|
|
35
|
+
readDir(path: string): DirEntry[];
|
|
36
|
+
/** Create a directory (and parents). No-op if it already exists. */
|
|
37
|
+
mkdirp(path: string): void;
|
|
38
|
+
/** Rename/move a file or directory. */
|
|
39
|
+
rename(from: string, to: string): void;
|
|
40
|
+
/** Recursively copy a file or directory tree (overwrites the target). */
|
|
41
|
+
copy(from: string, to: string): void;
|
|
42
|
+
/** Append UTF-8 text, creating the file and parent directories as needed. */
|
|
43
|
+
appendText(path: string, content: string): void;
|
|
44
|
+
/** Create a unique temporary directory for `prefix`; returns its path. */
|
|
45
|
+
makeTempDir(prefix: string): string;
|
|
46
|
+
/** Remove a file or directory tree. No-op if the path is absent. */
|
|
47
|
+
remove(path: string): void;
|
|
48
|
+
/** Whether the path exists and is a directory. */
|
|
49
|
+
isDirectory(path: string): boolean;
|
|
50
|
+
/** Metadata for an existing path, or `null` when absent. */
|
|
51
|
+
stat(path: string): FileStat | null;
|
|
52
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { GENERATED_DIR } from "../emitter/constants.ts";
|
|
2
|
+
import { hashStable, serializeCanonical } from "../primitives/index.ts";
|
|
3
|
+
import type { EmitFile } from "../types/emit.ts";
|
|
4
|
+
import type { ModuleGraph } from "../types/app-graph.ts";
|
|
5
|
+
import type { ImportGuardsArtifact } from "../types/import-guards.ts";
|
|
6
|
+
import type { RuntimeMatrix } from "../types/runtime-matrix.ts";
|
|
7
|
+
import { propagateContexts } from "./propagate-contexts.ts";
|
|
8
|
+
|
|
9
|
+
export function buildImportGuardsArtifact(
|
|
10
|
+
matrix: RuntimeMatrix,
|
|
11
|
+
moduleGraph?: ModuleGraph,
|
|
12
|
+
): ImportGuardsArtifact {
|
|
13
|
+
const entries = matrix.entries.map((entry) => ({
|
|
14
|
+
packageName: entry.packageName,
|
|
15
|
+
alias: entry.alias,
|
|
16
|
+
compatible: [...entry.compatible],
|
|
17
|
+
incompatible: [...entry.incompatible],
|
|
18
|
+
rationale: { ...entry.rationale },
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
let moduleContexts: ImportGuardsArtifact["moduleContexts"] = [];
|
|
22
|
+
if (moduleGraph) {
|
|
23
|
+
propagateContexts(moduleGraph);
|
|
24
|
+
moduleContexts = moduleGraph.nodes
|
|
25
|
+
.filter((node) => node.effectiveContexts.length > 0)
|
|
26
|
+
.map((node) => ({
|
|
27
|
+
file: node.file,
|
|
28
|
+
effectiveContexts: [...node.effectiveContexts],
|
|
29
|
+
}))
|
|
30
|
+
.sort((a, b) => (a.file < b.file ? -1 : a.file > b.file ? 1 : 0));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
schemaVersion: matrix.schemaVersion,
|
|
35
|
+
entries,
|
|
36
|
+
moduleContexts,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function renderRuntimeMatrixTs(matrix: RuntimeMatrix): string {
|
|
41
|
+
return `export const runtimeMatrix = ${serializeCanonical(matrix).trim()} as const;\n`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function renderImportGuardsTs(artifact: ImportGuardsArtifact): string {
|
|
45
|
+
return `export const importGuards = ${serializeCanonical(artifact).trim()} as const;\n`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function buildRuntimeMatrixEmitFiles(matrix: RuntimeMatrix): EmitFile[] {
|
|
49
|
+
const jsonBody = serializeCanonical(matrix);
|
|
50
|
+
const tsBody = renderRuntimeMatrixTs(matrix);
|
|
51
|
+
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
path: `${GENERATED_DIR}/runtimeMatrix.json`,
|
|
55
|
+
content: jsonBody,
|
|
56
|
+
contentHash: hashStable(jsonBody),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
path: `${GENERATED_DIR}/runtimeMatrix.ts`,
|
|
60
|
+
content: tsBody,
|
|
61
|
+
contentHash: hashStable(tsBody),
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function buildImportGuardsEmitFiles(
|
|
67
|
+
matrix: RuntimeMatrix,
|
|
68
|
+
moduleGraph?: ModuleGraph,
|
|
69
|
+
): EmitFile[] {
|
|
70
|
+
const artifact = buildImportGuardsArtifact(matrix, moduleGraph);
|
|
71
|
+
const jsonBody = serializeCanonical(artifact);
|
|
72
|
+
const tsBody = renderImportGuardsTs(artifact);
|
|
73
|
+
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
path: `${GENERATED_DIR}/importGuards.json`,
|
|
77
|
+
content: jsonBody,
|
|
78
|
+
contentHash: hashStable(jsonBody),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
path: `${GENERATED_DIR}/importGuards.ts`,
|
|
82
|
+
content: tsBody,
|
|
83
|
+
contentHash: hashStable(tsBody),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function buildGuardArtifactEmitFiles(
|
|
89
|
+
matrix: RuntimeMatrix,
|
|
90
|
+
moduleGraph?: ModuleGraph,
|
|
91
|
+
): EmitFile[] {
|
|
92
|
+
return [
|
|
93
|
+
...buildRuntimeMatrixEmitFiles(matrix),
|
|
94
|
+
...buildImportGuardsEmitFiles(matrix, moduleGraph),
|
|
95
|
+
];
|
|
96
|
+
}
|