forgeos 0.1.0-alpha.7 → 0.1.0-alpha.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/forge-agent-fabric/SKILL.md +169 -0
- package/.agents/skills/forge-agent-fabric/references/managed-workflows.md +95 -0
- package/.agents/skills/forge-agent-fabric/references/repository-analysis.md +102 -0
- package/.agents/skills/forge-agent-fabric/scripts/fabric.mjs +46 -0
- package/.agents/skills/forge-agent-fabric/scripts/repository.mjs +44 -0
- package/.npmignore +10 -0
- package/AGENTS.md +142 -90
- package/CHANGELOG.md +864 -9
- package/LICENSE +21 -0
- package/README.md +121 -6
- package/adapters/go/README.md +23 -0
- package/adapters/go/go.mod +3 -0
- package/adapters/go/http.go +149 -0
- package/adapters/go/registry.go +234 -0
- package/adapters/go/types.go +136 -0
- package/adapters/java/README.md +68 -0
- package/adapters/java/pom.xml +47 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Auth.java +20 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Diagnostic.java +16 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Entry.java +38 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/EntryKind.java +16 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ErrorInfo.java +4 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Forge.java +94 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeCall.java +12 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeContext.java +11 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeHandler.java +8 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeHttpHandler.java +179 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ForgeRegistry.java +121 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Json.java +14 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Manifest.java +14 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/RequestEnvelope.java +6 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/ResponseEnvelope.java +25 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Risk.java +18 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Schemas.java +36 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/Service.java +65 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/TransactionMode.java +18 -0
- package/adapters/java/src/main/java/dev/forgeos/adapter/TypedForgeHandler.java +6 -0
- package/adapters/java-spring-boot-starter/README.md +32 -0
- package/adapters/java-spring-boot-starter/pom.xml +49 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeCommand.java +22 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeExternalService.java +15 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeQuery.java +16 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeServiceBeanCondition.java +18 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeSpringAutoConfiguration.java +16 -0
- package/adapters/java-spring-boot-starter/src/main/java/dev/forgeos/adapter/spring/ForgeSpringRuntime.java +104 -0
- package/adapters/java-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +1 -0
- package/bin/forge.mjs +18 -0
- package/docs/agent-fabric-programs.md +168 -0
- package/docs/agent-fabric.md +584 -0
- package/docs/architecture/agent-fabric/PORTABLE_PROJECTS_PLAN.md +136 -0
- package/docs/architecture/agent-fabric/README.md +180 -0
- package/docs/architecture/agent-fabric/REPOSITORY_MANIFEST_PLAN.md +284 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_ADR.md +41 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_EVIDENCE.md +109 -0
- package/docs/architecture/agent-fabric/WORKFLOW_PROGRAM_V2_PLAN.md +550 -0
- package/docs/cair-protocol.md +103 -0
- package/docs/changelog.md +1070 -0
- package/docs/forge-protocol.md +189 -0
- package/docs/repository-agent-benchmark.md +179 -0
- package/docs/repository-analysis.md +139 -0
- package/docs/repository-context-quality.md +179 -0
- package/docs/repository-runtime-observation.md +82 -0
- package/examples/agent-fabric-v2/README.md +54 -0
- package/examples/agent-fabric-v2/make-request.mjs +4 -0
- package/examples/agent-fabric-v2/migrate.workflow.ts +35 -0
- package/examples/agent-fabric-v2/registry.example.json +256 -0
- package/examples/agent-fabric-v2/workers/check.mjs +2 -0
- package/examples/agent-fabric-v2/workers/common.mjs +7 -0
- package/examples/agent-fabric-v2/workers/discover.mjs +2 -0
- package/examples/agent-fabric-v2/workers/migrate.mjs +4 -0
- package/examples/agent-fabric-v2/workers/review.mjs +3 -0
- package/examples/go-billing/go.mod +7 -0
- package/examples/go-billing/main.go +120 -0
- package/examples/java-billing/pom.xml +60 -0
- package/examples/java-billing/src/main/java/dev/forgeos/examples/billing/CreateInvoiceInput.java +4 -0
- package/examples/java-billing/src/main/java/dev/forgeos/examples/billing/Invoice.java +11 -0
- package/examples/java-billing/src/main/java/dev/forgeos/examples/billing/Main.java +127 -0
- package/package.json +58 -5
- package/schemas/agent-fabric/v0.1/control-event.schema.json +281 -0
- package/schemas/forge-manifest.schema.json +389 -0
- package/scripts/field-test-forgeos.mjs +1021 -0
- package/scripts/install-agent-fabric-skill.mjs +105 -0
- package/src/forge/_generated/releaseManifest.json +1 -2
- package/src/forge/_generated/releaseManifest.ts +3 -3
- package/src/forge/agent-adapters/index.ts +1592 -125
- package/src/forge/agent-adapters/types.ts +225 -1
- package/src/forge/agent-fabric/adapter.ts +131 -0
- package/src/forge/agent-fabric/attached-snapshot.ts +55 -0
- package/src/forge/agent-fabric/attached-task-contract.ts +105 -0
- package/src/forge/agent-fabric/attached-task-service.ts +127 -0
- package/src/forge/agent-fabric/attached-task-store.ts +109 -0
- package/src/forge/agent-fabric/authority.ts +298 -0
- package/src/forge/agent-fabric/canonical.ts +135 -0
- package/src/forge/agent-fabric/codex-adversarial-review.ts +229 -0
- package/src/forge/agent-fabric/codex-sdk-worker.ts +201 -0
- package/src/forge/agent-fabric/conductor.ts +754 -0
- package/src/forge/agent-fabric/dictionary.ts +12 -0
- package/src/forge/agent-fabric/errors.ts +32 -0
- package/src/forge/agent-fabric/hardened-conductor.ts +485 -0
- package/src/forge/agent-fabric/hardened-reducer.ts +211 -0
- package/src/forge/agent-fabric/index.ts +48 -0
- package/src/forge/agent-fabric/journal.ts +116 -0
- package/src/forge/agent-fabric/local-adaptive-digest-worker.mjs +26 -0
- package/src/forge/agent-fabric/local-adaptive-harness.ts +343 -0
- package/src/forge/agent-fabric/local-adaptive-service.ts +398 -0
- package/src/forge/agent-fabric/local-adaptive-worker.ts +146 -0
- package/src/forge/agent-fabric/local-approval-window.ts +211 -0
- package/src/forge/agent-fabric/local-change-review-service.ts +374 -0
- package/src/forge/agent-fabric/local-coding-worker.ts +285 -0
- package/src/forge/agent-fabric/local-control-store.ts +239 -0
- package/src/forge/agent-fabric/local-effect-broker.ts +348 -0
- package/src/forge/agent-fabric/local-evolution-approval.ts +81 -0
- package/src/forge/agent-fabric/local-evolution-profile.ts +87 -0
- package/src/forge/agent-fabric/local-evolution-registry.ts +427 -0
- package/src/forge/agent-fabric/local-evolution-service.ts +200 -0
- package/src/forge/agent-fabric/local-intelligence.ts +281 -0
- package/src/forge/agent-fabric/local-paths.ts +18 -0
- package/src/forge/agent-fabric/local-task-contract.ts +203 -0
- package/src/forge/agent-fabric/local-task-inbox.ts +543 -0
- package/src/forge/agent-fabric/local-task-server.ts +374 -0
- package/src/forge/agent-fabric/local-task-service.ts +982 -0
- package/src/forge/agent-fabric/local-verification.ts +551 -0
- package/src/forge/agent-fabric/managed-environment.ts +205 -0
- package/src/forge/agent-fabric/managed-run-contract.ts +103 -0
- package/src/forge/agent-fabric/managed-run-service.ts +401 -0
- package/src/forge/agent-fabric/managed-run-store.ts +165 -0
- package/src/forge/agent-fabric/managed-workspace.ts +253 -0
- package/src/forge/agent-fabric/p0a.ts +104 -0
- package/src/forge/agent-fabric/p0b-model-adapter.ts +434 -0
- package/src/forge/agent-fabric/planning.ts +155 -0
- package/src/forge/agent-fabric/program-contract.ts +229 -0
- package/src/forge/agent-fabric/program-dsl.ts +112 -0
- package/src/forge/agent-fabric/program-service.ts +619 -0
- package/src/forge/agent-fabric/program-store.ts +117 -0
- package/src/forge/agent-fabric/program-types.ts +98 -0
- package/src/forge/agent-fabric/program-worker.ts +91 -0
- package/src/forge/agent-fabric/project-profile.ts +50 -0
- package/src/forge/agent-fabric/project-registry.ts +120 -0
- package/src/forge/agent-fabric/project-runtime.ts +85 -0
- package/src/forge/agent-fabric/readiness.ts +26 -0
- package/src/forge/agent-fabric/reducer.ts +863 -0
- package/src/forge/agent-fabric/repository-context.ts +83 -0
- package/src/forge/agent-fabric/resource-ledger.ts +266 -0
- package/src/forge/agent-fabric/serialized-local-adapter.ts +60 -0
- package/src/forge/agent-fabric/types.ts +424 -0
- package/src/forge/agent-fabric/validation.ts +500 -0
- package/src/forge/agent-fabric/workflow-engine.ts +218 -0
- package/src/forge/agent-fabric/workflow-task-actions.ts +104 -0
- package/src/forge/agent-fabric/workflow-templates.ts +11 -0
- package/src/forge/agent-memory/bridge.ts +1728 -0
- package/src/forge/agent-memory/context-pack.ts +284 -0
- package/src/forge/agent-memory/hook-runner.ts +331 -0
- package/src/forge/agent-memory/mcp.ts +597 -0
- package/src/forge/agent-memory/normalize.ts +498 -0
- package/src/forge/agent-memory/redaction.ts +103 -0
- package/src/forge/agent-memory/sources/claude-code.ts +51 -0
- package/src/forge/agent-memory/sources/codex-hook-runner.mjs +343 -0
- package/src/forge/agent-memory/sources/codex.ts +161 -0
- package/src/forge/agent-memory/sources/cursor.ts +35 -0
- package/src/forge/agent-memory/types.ts +215 -0
- package/src/forge/bench.ts +248 -0
- package/src/forge/brownfield-import/index.ts +896 -0
- package/src/forge/brownfield-import/types.ts +127 -0
- package/src/forge/cair/action-journal.ts +61 -0
- package/src/forge/cair/action-parser.ts +314 -0
- package/src/forge/cair/action-validator.ts +40 -0
- package/src/forge/cair/actions.ts +1818 -0
- package/src/forge/cair/format.ts +77 -0
- package/src/forge/cair/index.ts +118 -0
- package/src/forge/cair/query.ts +478 -0
- package/src/forge/cair/snapshot.ts +315 -0
- package/src/forge/cair/types.ts +255 -0
- package/src/forge/cli/adaptive.ts +51 -0
- package/src/forge/cli/ai.ts +16 -1
- package/src/forge/cli/auth.ts +459 -15
- package/src/forge/cli/authmd.ts +441 -0
- package/src/forge/cli/baseline.ts +112 -0
- package/src/forge/cli/build.ts +20 -4
- package/src/forge/cli/changed.ts +418 -0
- package/src/forge/cli/codex-app-server.ts +877 -0
- package/src/forge/cli/commands.ts +1859 -20
- package/src/forge/cli/db.ts +209 -2
- package/src/forge/cli/deploy.ts +1339 -0
- package/src/forge/cli/deps.ts +150 -23
- package/src/forge/cli/dev.ts +1137 -53
- package/src/forge/cli/docs.ts +265 -0
- package/src/forge/cli/doctor.ts +297 -0
- package/src/forge/cli/env-placeholders.ts +62 -0
- package/src/forge/cli/evolution.ts +40 -0
- package/src/forge/cli/fabric.ts +253 -0
- package/src/forge/cli/field-test.ts +568 -0
- package/src/forge/cli/golden-path.ts +487 -0
- package/src/forge/cli/handoff.ts +336 -0
- package/src/forge/cli/index.ts +1 -0
- package/src/forge/cli/last-run.ts +84 -0
- package/src/forge/cli/main.ts +194 -3
- package/src/forge/cli/new.ts +169 -17
- package/src/forge/cli/next-actions.ts +23 -0
- package/src/forge/cli/output.ts +398 -6
- package/src/forge/cli/parse.ts +1377 -38
- package/src/forge/cli/progress.ts +51 -0
- package/src/forge/cli/query.ts +32 -0
- package/src/forge/cli/release.ts +35 -11
- package/src/forge/cli/repository.ts +151 -0
- package/src/forge/cli/run.ts +42 -0
- package/src/forge/cli/secrets.ts +137 -1
- package/src/forge/cli/seed.ts +581 -0
- package/src/forge/cli/self-host.ts +56 -14
- package/src/forge/cli/studio.ts +2282 -0
- package/src/forge/cli/verify.ts +1458 -32
- package/src/forge/cli/windows.ts +23 -0
- package/src/forge/cli/workos.ts +3509 -0
- package/src/forge/compiler/agent-contract/build.ts +728 -64
- package/src/forge/compiler/agent-contract/types.ts +45 -2
- package/src/forge/compiler/ai-registry/parse.ts +71 -2
- package/src/forge/compiler/api-surface/build.ts +47 -0
- package/src/forge/compiler/app-graph/build.ts +112 -9
- package/src/forge/compiler/app-graph/extract.ts +107 -0
- package/src/forge/compiler/app-graph/module-graph.ts +73 -78
- package/src/forge/compiler/app-graph/parser.ts +24 -24
- package/src/forge/compiler/app-graph/profile.ts +26 -0
- package/src/forge/compiler/app-graph/tsconfig-hash.ts +41 -4
- package/src/forge/compiler/app-graph/versions.ts +1 -1
- package/src/forge/compiler/classifier/capabilities.ts +3 -2
- package/src/forge/compiler/classifier/classify.ts +32 -8
- package/src/forge/compiler/classifier/secrets.ts +3 -2
- package/src/forge/compiler/classifier/signals.ts +91 -1
- package/src/forge/compiler/client-sdk/build-manifest.ts +59 -0
- package/src/forge/compiler/client-sdk/render-client.ts +295 -13
- package/src/forge/compiler/data-graph/build.ts +29 -1
- package/src/forge/compiler/data-graph/parse.ts +20 -4
- package/src/forge/compiler/data-graph/sql/ddl.ts +144 -31
- package/src/forge/compiler/data-graph/sql/serialize.ts +4 -0
- package/src/forge/compiler/data-graph/sql/types.ts +1 -0
- package/src/forge/compiler/diagnostics/codes.ts +38 -0
- package/src/forge/compiler/diagnostics/create.ts +28 -2
- package/src/forge/compiler/diagnostics/index.ts +2 -0
- package/src/forge/compiler/emitter/barrel.ts +3 -0
- package/src/forge/compiler/emitter/render.ts +9 -0
- package/src/forge/compiler/external-manifest/registry.ts +217 -0
- package/src/forge/compiler/external-manifest/types.ts +91 -0
- package/src/forge/compiler/external-manifest/validate.ts +373 -0
- package/src/forge/compiler/frontend-graph/build.ts +142 -14
- package/src/forge/compiler/integration/add.ts +991 -33
- package/src/forge/compiler/integration/plan.ts +43 -12
- package/src/forge/compiler/integration/render.ts +29 -0
- package/src/forge/compiler/integration/snapshot.ts +2 -0
- package/src/forge/compiler/integration/templates/convex.ts +70 -0
- package/src/forge/compiler/integration/templates/index.ts +1 -0
- package/src/forge/compiler/integration/templates/render.ts +38 -0
- package/src/forge/compiler/integration/templates/types.ts +3 -0
- package/src/forge/compiler/integration/templates/workos.ts +1439 -0
- package/src/forge/compiler/make-registry/build.ts +8 -9
- package/src/forge/compiler/orchestrator/fast-check.ts +4 -0
- package/src/forge/compiler/orchestrator/generate-lock.ts +14 -3
- package/src/forge/compiler/orchestrator/manifest.ts +1 -1
- package/src/forge/compiler/orchestrator/plan-profile.ts +23 -0
- package/src/forge/compiler/orchestrator/plan.ts +249 -10
- package/src/forge/compiler/orchestrator/profile.ts +65 -0
- package/src/forge/compiler/orchestrator/run.ts +101 -33
- package/src/forge/compiler/orchestrator/serialize.ts +33 -8
- package/src/forge/compiler/orchestrator/types.ts +1 -1
- package/src/forge/compiler/package-graph/compiler.ts +3 -1
- package/src/forge/compiler/package-graph/constants.ts +1 -1
- package/src/forge/compiler/package-graph/dts-extractor.ts +14 -1
- package/src/forge/compiler/package-manager/adapter.ts +4 -1
- package/src/forge/compiler/package-manager/commands.ts +4 -0
- package/src/forge/compiler/package-manager/executor.ts +30 -1
- package/src/forge/compiler/package-manager/version.ts +36 -12
- package/src/forge/compiler/package-upgrades/planner.ts +155 -18
- package/src/forge/compiler/package-upgrades/types.ts +2 -0
- package/src/forge/compiler/policy-registry/build.ts +47 -2
- package/src/forge/compiler/policy-registry/parse.ts +32 -2
- package/src/forge/compiler/recipes/definitions.ts +63 -0
- package/src/forge/compiler/recipes/index.ts +2 -0
- package/src/forge/compiler/recipes/profiles.ts +81 -0
- package/src/forge/compiler/recipes/registry.ts +6 -0
- package/src/forge/compiler/test-graph/build.ts +11 -3
- package/src/forge/compiler/types/app-graph.ts +8 -2
- package/src/forge/compiler/types/cli.ts +76 -1
- package/src/forge/compiler/types/dev-manifest.ts +4 -0
- package/src/forge/compiler/types/emit.ts +2 -0
- package/src/forge/compiler/types/frontend-graph.ts +2 -2
- package/src/forge/compiler/types/integration.ts +1 -0
- package/src/forge/compiler/types/package-graph.ts +6 -0
- package/src/forge/compiler/types/policy-registry.ts +3 -1
- package/src/forge/delta/broker-runner.mjs +5 -0
- package/src/forge/delta/broker.ts +429 -0
- package/src/forge/delta/classifier.ts +52 -0
- package/src/forge/delta/explain.ts +238 -0
- package/src/forge/delta/git-observer.ts +67 -0
- package/src/forge/delta/ids.ts +44 -0
- package/src/forge/delta/index.ts +25 -0
- package/src/forge/delta/process-identity.ts +37 -0
- package/src/forge/delta/queue-status.ts +190 -0
- package/src/forge/delta/recorder.ts +540 -0
- package/src/forge/delta/redaction.ts +50 -0
- package/src/forge/delta/schema.ts +240 -0
- package/src/forge/delta/session.ts +142 -0
- package/src/forge/delta/status.ts +1139 -0
- package/src/forge/delta/store.ts +3329 -0
- package/src/forge/delta/timeline.ts +178 -0
- package/src/forge/dev/server.ts +1061 -22
- package/src/forge/dev/types.ts +15 -1
- package/src/forge/dev/watch.ts +17 -7
- package/src/forge/dev-console/cycle.ts +285 -33
- package/src/forge/dev-console/types.ts +47 -1
- package/src/forge/impact/index.ts +222 -30
- package/src/forge/impact/types.ts +33 -1
- package/src/forge/intent/index.ts +35 -16
- package/src/forge/make/fields.ts +26 -0
- package/src/forge/make/index.ts +42 -6
- package/src/forge/make/templates.ts +211 -4
- package/src/forge/make/types.ts +2 -1
- package/src/forge/policy.ts +1 -1
- package/src/forge/react/index.ts +160 -2
- package/src/forge/refactor/index.ts +1 -0
- package/src/forge/repair/rules/index.ts +2 -2
- package/src/forge/repository-analysis/adapters/common.ts +72 -0
- package/src/forge/repository-analysis/adapters/docker.ts +185 -0
- package/src/forge/repository-analysis/adapters/java.ts +133 -0
- package/src/forge/repository-analysis/adapters/typescript.ts +350 -0
- package/src/forge/repository-analysis/adapters/vue.ts +71 -0
- package/src/forge/repository-analysis/analyze.ts +434 -0
- package/src/forge/repository-analysis/benchmark.ts +336 -0
- package/src/forge/repository-analysis/cache-gc.ts +154 -0
- package/src/forge/repository-analysis/check-selection.ts +123 -0
- package/src/forge/repository-analysis/context-node.ts +17 -0
- package/src/forge/repository-analysis/context.ts +456 -0
- package/src/forge/repository-analysis/http-resolution.ts +135 -0
- package/src/forge/repository-analysis/identity.ts +45 -0
- package/src/forge/repository-analysis/index.ts +18 -0
- package/src/forge/repository-analysis/nuxt-resolution.ts +188 -0
- package/src/forge/repository-analysis/quality.ts +60 -0
- package/src/forge/repository-analysis/retrieval.ts +309 -0
- package/src/forge/repository-analysis/runtime-artifacts.ts +195 -0
- package/src/forge/repository-analysis/runtime-observation.ts +325 -0
- package/src/forge/repository-analysis/scanner.ts +174 -0
- package/src/forge/repository-analysis/storage.ts +193 -0
- package/src/forge/repository-analysis/test-associations.ts +59 -0
- package/src/forge/repository-analysis/types.ts +99 -0
- package/src/forge/repository-manifest/index.ts +178 -0
- package/src/forge/repository-manifest/types.ts +63 -0
- package/src/forge/review/index.ts +162 -12
- package/src/forge/review/types.ts +15 -0
- package/src/forge/runtime/ai/providers.ts +19 -4
- package/src/forge/runtime/auth/config.ts +17 -0
- package/src/forge/runtime/auth/evaluate.ts +15 -2
- package/src/forge/runtime/auth/resolve.ts +61 -6
- package/src/forge/runtime/auth/types.ts +1 -0
- package/src/forge/runtime/db/factory.ts +1 -3
- package/src/forge/runtime/db/generated-client.ts +13 -2
- package/src/forge/runtime/db/memory-adapter.ts +139 -32
- package/src/forge/runtime/db/pglite-adapter.ts +285 -2
- package/src/forge/runtime/executor.ts +129 -16
- package/src/forge/runtime/external/bridge.ts +663 -0
- package/src/forge/runtime/runner/run-entry.ts +16 -7
- package/src/forge/runtime/telemetry/buffer.ts +4 -1
- package/src/forge/runtime/telemetry/scrubber.ts +35 -5
- package/src/forge/runtime/webhooks/security.ts +12 -7
- package/src/forge/server.ts +71 -7
- package/src/forge/ui/index.ts +831 -19
- package/src/forge/ui/types.ts +3 -1
- package/src/forge/version.ts +1 -1
- package/src/forge/vue/index.ts +422 -0
- package/src/forge/workspace/baseline.ts +112 -0
- package/src/forge/workspace/change-summary.ts +292 -0
- package/src/forge/workspace/forge-cli.ts +42 -0
- package/src/forge/workspace/git-summary.ts +393 -0
- package/templates/agent-workroom/AGENTS.md +29 -0
- package/templates/agent-workroom/README.md +34 -0
- package/templates/agent-workroom/forge.config.ts +3 -0
- package/templates/agent-workroom/package.json +34 -0
- package/templates/agent-workroom/pnpm-workspace.yaml +2 -0
- package/templates/agent-workroom/src/actions/indexAgentSignal.ts +10 -0
- package/templates/agent-workroom/src/commands/openWorkroom.ts +61 -0
- package/templates/agent-workroom/src/commands/recordAgentSignal.ts +119 -0
- package/templates/agent-workroom/src/commands/recordCheckRun.ts +52 -0
- package/templates/agent-workroom/src/forge/schema.ts +54 -0
- package/templates/agent-workroom/src/policies.ts +6 -0
- package/templates/agent-workroom/src/queries/listWorkrooms.ts +11 -0
- package/templates/agent-workroom/src/queries/liveWorkroom.ts +63 -0
- package/templates/agent-workroom/tsconfig.json +16 -0
- package/templates/agent-workroom/web/index.html +13 -0
- package/templates/agent-workroom/web/package.json +21 -0
- package/templates/agent-workroom/web/src/App.tsx +345 -0
- package/templates/agent-workroom/web/src/lib/forge.ts +20 -0
- package/templates/agent-workroom/web/src/main.tsx +13 -0
- package/templates/agent-workroom/web/src/styles.css +545 -0
- package/templates/agent-workroom/web/tsconfig.json +27 -0
- package/templates/agent-workroom/web/vite.config.ts +36 -0
- package/templates/b2b-support-web/package.json +2 -0
- package/templates/b2b-support-web/pnpm-workspace.yaml +2 -0
- package/templates/b2b-support-web/web/app/page.tsx +2 -2
- package/templates/b2b-support-web/web/lib/forge.ts +9 -2
- package/templates/b2b-support-web/web/next.config.ts +24 -0
- package/templates/b2b-support-web/web/package.json +1 -1
- package/templates/minimal-web/package.json +2 -1
- package/templates/minimal-web/pnpm-workspace.yaml +2 -0
- package/templates/minimal-web/web/index.html +1 -0
- package/templates/minimal-web/web/src/App.tsx +12 -6
- package/templates/minimal-web/web/src/lib/forge.ts +9 -2
- package/templates/minimal-web/web/src/styles.css +34 -0
- package/templates/minimal-web/web/vite.config.ts +36 -0
- package/templates/nuxt-web/.vscode/settings.json +14 -0
- package/templates/nuxt-web/.yarnrc.yml +1 -0
- package/templates/nuxt-web/README.md +30 -0
- package/templates/nuxt-web/forge.config.ts +3 -0
- package/templates/nuxt-web/package.json +37 -0
- package/templates/nuxt-web/pnpm-workspace.yaml +2 -0
- package/templates/nuxt-web/src/actions/logNoteCreated.ts +11 -0
- package/templates/nuxt-web/src/commands/createNote.ts +26 -0
- package/templates/nuxt-web/src/forge/schema.ts +12 -0
- package/templates/nuxt-web/src/policies.ts +6 -0
- package/templates/nuxt-web/src/queries/listNotes.ts +8 -0
- package/templates/nuxt-web/src/queries/liveNotes.ts +8 -0
- package/templates/nuxt-web/tsconfig.json +17 -0
- package/templates/nuxt-web/web/app.vue +67 -0
- package/templates/nuxt-web/web/components/LiveNotes.vue +89 -0
- package/templates/nuxt-web/web/components/NoteComposer.vue +100 -0
- package/templates/nuxt-web/web/composables/forge.ts +13 -0
- package/templates/nuxt-web/web/composables/useNotes.ts +24 -0
- package/templates/nuxt-web/web/nuxt.config.ts +11 -0
- package/templates/nuxt-web/web/package.json +22 -0
- package/templates/nuxt-web/web/plugins/forge.client.ts +10 -0
- package/templates/nuxt-web/web/plugins/forge.server.ts +10 -0
- package/templates/nuxt-web/web/server/api/forge-health.get.ts +7 -0
- package/templates/nuxt-web/web/tsconfig.json +6 -0
- package/templates/vendor-access/.vscode/settings.json +14 -0
- package/templates/vendor-access/README.md +30 -0
- package/templates/vendor-access/forge.config.ts +3 -0
- package/templates/vendor-access/package.json +35 -0
- package/templates/vendor-access/pnpm-workspace.yaml +2 -0
- package/templates/vendor-access/src/commands/addEvidence.ts +42 -0
- package/templates/vendor-access/src/commands/approveAccessRequest.ts +43 -0
- package/templates/vendor-access/src/commands/createAccessRequest.ts +49 -0
- package/templates/vendor-access/src/commands/seedVendorAccessDemo.ts +200 -0
- package/templates/vendor-access/src/forge/schema.ts +74 -0
- package/templates/vendor-access/src/policies.ts +11 -0
- package/templates/vendor-access/src/queries/listVendorAccessDashboard.ts +24 -0
- package/templates/vendor-access/src/queries/liveVendorAccessDashboard.ts +24 -0
- package/templates/vendor-access/tsconfig.json +17 -0
- package/templates/vendor-access/web/index.html +13 -0
- package/templates/vendor-access/web/package.json +21 -0
- package/templates/vendor-access/web/src/App.tsx +573 -0
- package/templates/vendor-access/web/src/lib/forge.ts +20 -0
- package/templates/vendor-access/web/src/main.tsx +205 -0
- package/templates/vendor-access/web/src/styles.css +682 -0
- package/templates/vendor-access/web/tsconfig.json +18 -0
- package/templates/vendor-access/web/vite.config.ts +36 -0
- package/src/forge/_generated/actionSubscriptions.json +0 -2
- package/src/forge/_generated/actionSubscriptions.ts +0 -10
- package/src/forge/_generated/agentAdapterManifest.json +0 -2
- package/src/forge/_generated/agentAdapterManifest.ts +0 -73
- package/src/forge/_generated/agentContract.json +0 -2
- package/src/forge/_generated/agentContract.ts +0 -7829
- package/src/forge/_generated/agentQuickstart.md +0 -34
- package/src/forge/_generated/agentTools.json +0 -2
- package/src/forge/_generated/agentTools.md +0 -16
- package/src/forge/_generated/agentTools.ts +0 -12
- package/src/forge/_generated/aiContext.ts +0 -125
- package/src/forge/_generated/aiModels.json +0 -2
- package/src/forge/_generated/aiModels.ts +0 -51
- package/src/forge/_generated/aiProviders.json +0 -2
- package/src/forge/_generated/aiProviders.ts +0 -23
- package/src/forge/_generated/aiRegistry.json +0 -2
- package/src/forge/_generated/aiRegistry.ts +0 -31
- package/src/forge/_generated/api.json +0 -2
- package/src/forge/_generated/api.ts +0 -8
- package/src/forge/_generated/appGraph.json +0 -2
- package/src/forge/_generated/appGraph.ts +0 -14937
- package/src/forge/_generated/appMap.md +0 -55
- package/src/forge/_generated/artifactManifest.json +0 -2
- package/src/forge/_generated/artifactManifest.ts +0 -7
- package/src/forge/_generated/authClaims.json +0 -2
- package/src/forge/_generated/authClaims.ts +0 -13
- package/src/forge/_generated/authConfig.json +0 -2
- package/src/forge/_generated/authConfig.ts +0 -17
- package/src/forge/_generated/authContext.ts +0 -23
- package/src/forge/_generated/authRegistry.json +0 -2
- package/src/forge/_generated/authRegistry.ts +0 -25
- package/src/forge/_generated/buildInfo.json +0 -2
- package/src/forge/_generated/buildInfo.ts +0 -9
- package/src/forge/_generated/capabilityMap.json +0 -2
- package/src/forge/_generated/capabilityMap.md +0 -15
- package/src/forge/_generated/capabilityMap.ts +0 -17
- package/src/forge/_generated/client.ts +0 -282
- package/src/forge/_generated/clientApi.ts +0 -9
- package/src/forge/_generated/clientManifest.json +0 -2
- package/src/forge/_generated/clientManifest.ts +0 -39
- package/src/forge/_generated/clientTypes.ts +0 -78
- package/src/forge/_generated/configRegistry.json +0 -2
- package/src/forge/_generated/configRegistry.ts +0 -4
- package/src/forge/_generated/dataGraph.json +0 -2
- package/src/forge/_generated/dataGraph.ts +0 -8
- package/src/forge/_generated/db.json +0 -2
- package/src/forge/_generated/db.ts +0 -2
- package/src/forge/_generated/dbSecurityManifest.json +0 -2
- package/src/forge/_generated/dbSecurityManifest.ts +0 -15
- package/src/forge/_generated/dbSessionContext.json +0 -2
- package/src/forge/_generated/dbSessionContext.ts +0 -39
- package/src/forge/_generated/deployManifest.json +0 -2
- package/src/forge/_generated/deployManifest.ts +0 -14
- package/src/forge/_generated/devManifest.json +0 -2
- package/src/forge/_generated/devManifest.ts +0 -62
- package/src/forge/_generated/envSchema.json +0 -2
- package/src/forge/_generated/envSchema.ts +0 -59
- package/src/forge/_generated/frontendGraph.json +0 -2
- package/src/forge/_generated/frontendGraph.ts +0 -27
- package/src/forge/_generated/importGuards.json +0 -2
- package/src/forge/_generated/importGuards.ts +0 -686
- package/src/forge/_generated/index.ts +0 -68
- package/src/forge/_generated/liveProductionManifest.json +0 -2
- package/src/forge/_generated/liveProductionManifest.ts +0 -23
- package/src/forge/_generated/liveProtocol.json +0 -2
- package/src/forge/_generated/liveProtocol.ts +0 -21
- package/src/forge/_generated/liveQueryRegistry.json +0 -2
- package/src/forge/_generated/liveQueryRegistry.ts +0 -9
- package/src/forge/_generated/liveTransportConfig.json +0 -2
- package/src/forge/_generated/liveTransportConfig.ts +0 -19
- package/src/forge/_generated/makeRegistry.json +0 -2
- package/src/forge/_generated/makeRegistry.ts +0 -177
- package/src/forge/_generated/makeTemplates.json +0 -2
- package/src/forge/_generated/makeTemplates.ts +0 -66
- package/src/forge/_generated/mockMap.json +0 -2
- package/src/forge/_generated/mockMap.ts +0 -7
- package/src/forge/_generated/operationPlaybooks.md +0 -167
- package/src/forge/_generated/packageGraph.json +0 -2
- package/src/forge/_generated/packageGraph.ts +0 -249334
- package/src/forge/_generated/packageUpgradeRegistry.json +0 -2
- package/src/forge/_generated/packageUpgradeRegistry.ts +0 -15
- package/src/forge/_generated/permissionMatrix.json +0 -2
- package/src/forge/_generated/permissionMatrix.ts +0 -7
- package/src/forge/_generated/policyRegistry.json +0 -2
- package/src/forge/_generated/policyRegistry.ts +0 -11
- package/src/forge/_generated/queryRegistry.json +0 -2
- package/src/forge/_generated/queryRegistry.ts +0 -9
- package/src/forge/_generated/react.d.ts +0 -22
- package/src/forge/_generated/react.ts +0 -29
- package/src/forge/_generated/reactManifest.json +0 -2
- package/src/forge/_generated/reactManifest.ts +0 -19
- package/src/forge/_generated/rlsPolicies.json +0 -2
- package/src/forge/_generated/rlsPolicies.sql +0 -34
- package/src/forge/_generated/rlsPolicies.ts +0 -6
- package/src/forge/_generated/runtimeGraph.json +0 -2
- package/src/forge/_generated/runtimeGraph.ts +0 -8
- package/src/forge/_generated/runtimeMatrix.json +0 -2
- package/src/forge/_generated/runtimeMatrix.ts +0 -334130
- package/src/forge/_generated/runtimeRegistry.ts +0 -2
- package/src/forge/_generated/runtimeRules.md +0 -91
- package/src/forge/_generated/secretRegistry.json +0 -2
- package/src/forge/_generated/secretRegistry.ts +0 -50
- package/src/forge/_generated/secretsContext.ts +0 -11
- package/src/forge/_generated/serverApi.ts +0 -10
- package/src/forge/_generated/sourceMapManifest.json +0 -2
- package/src/forge/_generated/sourceMapManifest.ts +0 -7
- package/src/forge/_generated/sqlPlan.json +0 -2
- package/src/forge/_generated/sqlPlan.ts +0 -88
- package/src/forge/_generated/subscriptionManifest.json +0 -2
- package/src/forge/_generated/subscriptionManifest.ts +0 -7
- package/src/forge/_generated/symbolicationManifest.json +0 -2
- package/src/forge/_generated/symbolicationManifest.ts +0 -17
- package/src/forge/_generated/telemetryRegistry.json +0 -2
- package/src/forge/_generated/telemetryRegistry.ts +0 -9
- package/src/forge/_generated/telemetrySinks.json +0 -2
- package/src/forge/_generated/telemetrySinks.ts +0 -11
- package/src/forge/_generated/tenantScope.json +0 -2
- package/src/forge/_generated/tenantScope.ts +0 -8
- package/src/forge/_generated/testGraph.json +0 -2
- package/src/forge/_generated/testGraph.ts +0 -3452
- package/src/forge/_generated/testPlanRegistry.json +0 -2
- package/src/forge/_generated/testPlanRegistry.ts +0 -33
- package/src/forge/_generated/uiRoutes.json +0 -2
- package/src/forge/_generated/uiRoutes.ts +0 -16
- package/src/forge/_generated/uiScenarios.json +0 -2
- package/src/forge/_generated/uiScenarios.ts +0 -30
- package/src/forge/_generated/uiTestManifest.json +0 -2
- package/src/forge/_generated/uiTestManifest.ts +0 -27
- package/src/forge/_generated/workflowRegistry.json +0 -2
- package/src/forge/_generated/workflowRegistry.ts +0 -9
- package/src/forge/_generated/workflowSubscriptions.json +0 -2
- package/src/forge/_generated/workflowSubscriptions.ts +0 -10
|
@@ -0,0 +1,1139 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
3
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
4
|
+
import { createDiagnostic } from "../compiler/diagnostics/create.ts";
|
|
5
|
+
import { normalizePath } from "../compiler/primitives/paths.ts";
|
|
6
|
+
import {
|
|
7
|
+
DeltaStore,
|
|
8
|
+
DeltaStoreBusyError,
|
|
9
|
+
describeDeltaStoreBusy,
|
|
10
|
+
getDeltaStorePath,
|
|
11
|
+
probeDeltaStoreBusy,
|
|
12
|
+
summarizeDeltaStoreBusy,
|
|
13
|
+
type DeltaStatus,
|
|
14
|
+
type DeltaStatusDetails,
|
|
15
|
+
type DeltaStoreBusyInfo,
|
|
16
|
+
} from "./store.ts";
|
|
17
|
+
import { redactDeltaPayload } from "./redaction.ts";
|
|
18
|
+
import { normalizeForgeCliCommandsInValue } from "../workspace/forge-cli.ts";
|
|
19
|
+
import { inspectDeltaAgentQueue, type DeltaAgentQueueSnapshot } from "./queue-status.ts";
|
|
20
|
+
import { probeDeltaBroker } from "./broker.ts";
|
|
21
|
+
|
|
22
|
+
export type DeltaStatusResult =
|
|
23
|
+
| (DeltaStatus & { queue: DeltaAgentQueueSnapshot; details?: DeltaStatusDetails; exitCode: 0 })
|
|
24
|
+
| {
|
|
25
|
+
ok: false;
|
|
26
|
+
recording: false;
|
|
27
|
+
store: string;
|
|
28
|
+
busy?: DeltaStoreBusyInfo;
|
|
29
|
+
queue: DeltaAgentQueueSnapshot;
|
|
30
|
+
broker: { active: boolean; pid?: number; error?: string };
|
|
31
|
+
diagnostics: ReturnType<typeof createDiagnostic>[];
|
|
32
|
+
nextActions: string[];
|
|
33
|
+
exitCode: 1;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export interface DeltaStatusOptions {
|
|
37
|
+
verbose?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface DeltaRepairOptions {
|
|
41
|
+
workspaceRoot: string;
|
|
42
|
+
dryRun: boolean;
|
|
43
|
+
yes: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DeltaRepairResult {
|
|
47
|
+
ok: boolean;
|
|
48
|
+
applied: boolean;
|
|
49
|
+
needsConfirmation: boolean;
|
|
50
|
+
store: string;
|
|
51
|
+
backupPath?: string;
|
|
52
|
+
busy?: DeltaStoreBusyInfo;
|
|
53
|
+
actions: Array<{ kind: "backup" | "remove" | "initialize" | "restore"; from?: string; to?: string; skipped?: boolean }>;
|
|
54
|
+
diagnostics: ReturnType<typeof createDiagnostic>[];
|
|
55
|
+
nextActions: string[];
|
|
56
|
+
exitCode: 0 | 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DeltaCompactOptions {
|
|
60
|
+
workspaceRoot: string;
|
|
61
|
+
dryRun?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface DeltaPruneOptions {
|
|
65
|
+
workspaceRoot: string;
|
|
66
|
+
olderThan?: string;
|
|
67
|
+
dryRun?: boolean;
|
|
68
|
+
yes?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface DeltaExportOptions {
|
|
72
|
+
workspaceRoot: string;
|
|
73
|
+
redacted?: boolean;
|
|
74
|
+
output?: string;
|
|
75
|
+
limit?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DeltaMaintenanceFileResult {
|
|
79
|
+
path: string;
|
|
80
|
+
exists: boolean;
|
|
81
|
+
beforeBytes: number;
|
|
82
|
+
afterBytes: number;
|
|
83
|
+
linesBefore: number;
|
|
84
|
+
linesAfter: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface DeltaCompactResult {
|
|
88
|
+
ok: boolean;
|
|
89
|
+
subcommand: "compact";
|
|
90
|
+
applied: boolean;
|
|
91
|
+
dryRun: boolean;
|
|
92
|
+
files: DeltaMaintenanceFileResult[];
|
|
93
|
+
diagnostics: ReturnType<typeof createDiagnostic>[];
|
|
94
|
+
nextActions: string[];
|
|
95
|
+
exitCode: 0 | 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface DeltaPruneResult {
|
|
99
|
+
ok: boolean;
|
|
100
|
+
subcommand: "prune";
|
|
101
|
+
applied: boolean;
|
|
102
|
+
needsConfirmation: boolean;
|
|
103
|
+
olderThan?: string;
|
|
104
|
+
cutoff?: string;
|
|
105
|
+
files: Array<DeltaMaintenanceFileResult & { prunedLines: number }>;
|
|
106
|
+
diagnostics: ReturnType<typeof createDiagnostic>[];
|
|
107
|
+
nextActions: string[];
|
|
108
|
+
exitCode: 0 | 1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface DeltaExportResult {
|
|
112
|
+
ok: boolean;
|
|
113
|
+
subcommand: "export";
|
|
114
|
+
redacted: boolean;
|
|
115
|
+
output?: string;
|
|
116
|
+
written: boolean;
|
|
117
|
+
data?: Record<string, unknown>;
|
|
118
|
+
busy?: DeltaStoreBusyInfo;
|
|
119
|
+
diagnostics: ReturnType<typeof createDiagnostic>[];
|
|
120
|
+
nextActions: string[];
|
|
121
|
+
exitCode: 0 | 1;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface DeltaDoctorCheck {
|
|
125
|
+
name: string;
|
|
126
|
+
ok: boolean;
|
|
127
|
+
severity: "error" | "warning";
|
|
128
|
+
message: string;
|
|
129
|
+
evidence?: Record<string, unknown>;
|
|
130
|
+
suggestedCommands?: string[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface DeltaDoctorResult {
|
|
134
|
+
ok: boolean;
|
|
135
|
+
checks: DeltaDoctorCheck[];
|
|
136
|
+
status?: DeltaStatusResult;
|
|
137
|
+
nextActions: string[];
|
|
138
|
+
exitCode: 0 | 1;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function normalizeDeltaCliCommandHints<T>(workspaceRoot: string, result: T): T {
|
|
142
|
+
if (!result || typeof result !== "object") {
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
const value = result as Record<string, unknown>;
|
|
146
|
+
const normalized: Record<string, unknown> = { ...value };
|
|
147
|
+
for (const key of ["nextActions", "diagnostics", "checks"]) {
|
|
148
|
+
if (key in normalized) {
|
|
149
|
+
normalized[key] = normalizeForgeCliCommandsInValue(workspaceRoot, normalized[key], key);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if ("status" in normalized) {
|
|
153
|
+
normalized.status = normalizeDeltaCliCommandHints(workspaceRoot, normalized.status);
|
|
154
|
+
}
|
|
155
|
+
return normalized as T;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function openDeltaStoreForStatus(
|
|
159
|
+
workspaceRoot: string,
|
|
160
|
+
): Promise<{ store: DeltaStore | null; openError?: unknown }> {
|
|
161
|
+
let openError: unknown;
|
|
162
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
163
|
+
openError = undefined;
|
|
164
|
+
const store = await DeltaStore.open(workspaceRoot, { access: "read" }).catch((error: unknown) => {
|
|
165
|
+
openError = error;
|
|
166
|
+
return null;
|
|
167
|
+
});
|
|
168
|
+
if (store) {
|
|
169
|
+
return { store };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!(openError instanceof DeltaStoreBusyError)) {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
const busyInfo = describeDeltaStoreBusy(openError, workspaceRoot);
|
|
176
|
+
const orphanedPgliteLock =
|
|
177
|
+
busyInfo.relativeLockPath.endsWith("postmaster.pid") &&
|
|
178
|
+
busyInfo.processAlive === false;
|
|
179
|
+
const transientPgliteLock =
|
|
180
|
+
orphanedPgliteLock &&
|
|
181
|
+
typeof busyInfo.ageMs === "number" &&
|
|
182
|
+
busyInfo.ageMs < 2_000;
|
|
183
|
+
if (!transientPgliteLock) {
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
await sleep(150 * (attempt + 1));
|
|
187
|
+
}
|
|
188
|
+
return { store: null, openError };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function unavailableDeltaStatus(workspaceRoot: string, storePath: string, openError: unknown): Promise<DeltaStatusResult> {
|
|
192
|
+
const errorMessage = openError instanceof Error ? openError.message : "unknown open error";
|
|
193
|
+
const busyError = openError instanceof DeltaStoreBusyError ? openError : undefined;
|
|
194
|
+
const busy = Boolean(busyError);
|
|
195
|
+
const busyInfo = busyError ? describeDeltaStoreBusy(busyError, workspaceRoot) : undefined;
|
|
196
|
+
const busySummary = busyInfo ? summarizeDeltaStoreBusy(busyInfo) : undefined;
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
recording: false,
|
|
200
|
+
store: storePath,
|
|
201
|
+
...(busyInfo ? { busy: busyInfo } : {}),
|
|
202
|
+
queue: inspectDeltaAgentQueue(workspaceRoot),
|
|
203
|
+
broker: await probeDeltaBroker(workspaceRoot).catch((error: unknown) => ({
|
|
204
|
+
active: false,
|
|
205
|
+
error: error instanceof Error ? error.message : "Delta broker could not be probed",
|
|
206
|
+
})),
|
|
207
|
+
diagnostics: [
|
|
208
|
+
createDiagnostic({
|
|
209
|
+
severity: "error",
|
|
210
|
+
code: busy ? "FORGE_DELTA_BUSY" : "FORGE_DELTA_STORE_UNAVAILABLE",
|
|
211
|
+
message: busy
|
|
212
|
+
? `Forge Delta local store is busy: ${errorMessage}${busySummary ? ` (${busySummary})` : ""}`
|
|
213
|
+
: `Forge Delta local store is unavailable: ${errorMessage}`,
|
|
214
|
+
file: storePath,
|
|
215
|
+
fixHint: busy
|
|
216
|
+
? busyInfo?.processAlive
|
|
217
|
+
? `Wait for pid ${busyInfo.pid ?? "shown in the lock file"} to finish, then retry.`
|
|
218
|
+
: `If no Forge/agent process is still running, inspect ${busyInfo?.relativeLockPath ?? ".forge/delta/delta.lock"} and retry.`
|
|
219
|
+
: "Inspect the original open error and preserve the Delta store before considering a repair.",
|
|
220
|
+
suggestedCommands: [
|
|
221
|
+
"forge delta status --json",
|
|
222
|
+
"forge agent timeline --json",
|
|
223
|
+
"forge delta repair --dry-run --json",
|
|
224
|
+
],
|
|
225
|
+
}),
|
|
226
|
+
],
|
|
227
|
+
nextActions: [
|
|
228
|
+
busy
|
|
229
|
+
? busyInfo?.processAlive
|
|
230
|
+
? `Wait for pid ${busyInfo.pid ?? "shown in .forge/delta/delta.lock"} to release ${busyInfo.relativeLockPath}`
|
|
231
|
+
: `Inspect ${busyInfo?.relativeLockPath ?? ".forge/delta/delta.lock"}; it may belong to an exited process`
|
|
232
|
+
: "Close any running forge dev or external agent process using .forge/delta/delta.db",
|
|
233
|
+
"forge agent timeline --json",
|
|
234
|
+
"forge delta repair --dry-run --json",
|
|
235
|
+
"forge delta status --json",
|
|
236
|
+
],
|
|
237
|
+
exitCode: 1,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function runDeltaStatusRaw(workspaceRoot: string, options: DeltaStatusOptions = {}): Promise<DeltaStatusResult> {
|
|
242
|
+
const storePath = normalizePath(relative(workspaceRoot, getDeltaStorePath(workspaceRoot)));
|
|
243
|
+
const { store, openError } = await openDeltaStoreForStatus(workspaceRoot);
|
|
244
|
+
if (!store) {
|
|
245
|
+
return unavailableDeltaStatus(workspaceRoot, storePath, openError);
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
const status = await store.status();
|
|
249
|
+
const details = options.verbose ? await store.statusDetails() : undefined;
|
|
250
|
+
return {
|
|
251
|
+
...status,
|
|
252
|
+
queue: inspectDeltaAgentQueue(workspaceRoot),
|
|
253
|
+
...(details ? { details } : {}),
|
|
254
|
+
exitCode: 0,
|
|
255
|
+
};
|
|
256
|
+
} catch (error) {
|
|
257
|
+
return unavailableDeltaStatus(workspaceRoot, storePath, error);
|
|
258
|
+
} finally {
|
|
259
|
+
await store.close().catch(() => undefined);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function runDeltaStatus(workspaceRoot: string, options: DeltaStatusOptions = {}): Promise<DeltaStatusResult> {
|
|
264
|
+
return normalizeDeltaCliCommandHints(workspaceRoot, await runDeltaStatusRaw(workspaceRoot, options));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function timestampForPath(date = new Date()): string {
|
|
268
|
+
return date.toISOString().replace(/[:.]/g, "-");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function deltaBackupPath(workspaceRoot: string, storePath: string): string {
|
|
272
|
+
return join(workspaceRoot, ".forge", "delta", "backups", `${basename(storePath)}.${timestampForPath()}`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function runDeltaRepairRaw(options: DeltaRepairOptions): Promise<DeltaRepairResult> {
|
|
276
|
+
const absoluteStorePath = getDeltaStorePath(options.workspaceRoot);
|
|
277
|
+
const store = normalizePath(relative(options.workspaceRoot, absoluteStorePath));
|
|
278
|
+
const backupAbsolute = deltaBackupPath(options.workspaceRoot, absoluteStorePath);
|
|
279
|
+
const backupPath = normalizePath(relative(options.workspaceRoot, backupAbsolute));
|
|
280
|
+
const storeExists = existsSync(absoluteStorePath);
|
|
281
|
+
const actions: DeltaRepairResult["actions"] = [
|
|
282
|
+
...(storeExists ? [{ kind: "backup" as const, from: store, to: backupPath }] : [{ kind: "backup" as const, from: store, to: backupPath, skipped: true }]),
|
|
283
|
+
{ kind: "initialize", to: store },
|
|
284
|
+
];
|
|
285
|
+
|
|
286
|
+
if (options.dryRun || !options.yes) {
|
|
287
|
+
return {
|
|
288
|
+
ok: true,
|
|
289
|
+
applied: false,
|
|
290
|
+
needsConfirmation: !options.yes,
|
|
291
|
+
store,
|
|
292
|
+
...(storeExists ? { backupPath } : {}),
|
|
293
|
+
actions,
|
|
294
|
+
diagnostics: [],
|
|
295
|
+
nextActions: [
|
|
296
|
+
"forge delta repair --yes --json",
|
|
297
|
+
"forge delta status --json",
|
|
298
|
+
],
|
|
299
|
+
exitCode: 0,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const busy = probeDeltaStoreBusy(options.workspaceRoot);
|
|
304
|
+
if (busy) {
|
|
305
|
+
const busyInfo = describeDeltaStoreBusy(busy, options.workspaceRoot);
|
|
306
|
+
const busySummary = summarizeDeltaStoreBusy(busyInfo);
|
|
307
|
+
return {
|
|
308
|
+
ok: false,
|
|
309
|
+
applied: false,
|
|
310
|
+
needsConfirmation: false,
|
|
311
|
+
store,
|
|
312
|
+
...(storeExists ? { backupPath } : {}),
|
|
313
|
+
busy: busyInfo,
|
|
314
|
+
actions,
|
|
315
|
+
diagnostics: [
|
|
316
|
+
createDiagnostic({
|
|
317
|
+
severity: "error",
|
|
318
|
+
code: "FORGE_DELTA_BUSY",
|
|
319
|
+
message: `Forge Delta repair cannot run while the local store is busy: ${busy.message} (${busySummary})`,
|
|
320
|
+
file: store,
|
|
321
|
+
fixHint: busyInfo.processAlive
|
|
322
|
+
? `Wait for pid ${busyInfo.pid ?? "shown in the lock file"} to finish before repairing local Delta memory.`
|
|
323
|
+
: `If no Forge/agent process is still running, inspect ${busyInfo.relativeLockPath} before repairing local Delta memory.`,
|
|
324
|
+
suggestedCommands: [
|
|
325
|
+
"forge delta status --json",
|
|
326
|
+
"forge agent timeline --json",
|
|
327
|
+
"forge delta repair --dry-run --json",
|
|
328
|
+
],
|
|
329
|
+
}),
|
|
330
|
+
],
|
|
331
|
+
nextActions: [
|
|
332
|
+
busyInfo.processAlive
|
|
333
|
+
? `Wait for pid ${busyInfo.pid ?? "shown in .forge/delta/delta.lock"} to release ${busyInfo.relativeLockPath}`
|
|
334
|
+
: `Inspect ${busyInfo.relativeLockPath}; it may belong to an exited process`,
|
|
335
|
+
"forge agent timeline --json",
|
|
336
|
+
"forge delta status --json",
|
|
337
|
+
"forge delta repair --dry-run --json",
|
|
338
|
+
],
|
|
339
|
+
exitCode: 1,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
let moved = false;
|
|
344
|
+
try {
|
|
345
|
+
if (storeExists) {
|
|
346
|
+
mkdirSync(dirname(backupAbsolute), { recursive: true });
|
|
347
|
+
renameSync(absoluteStorePath, backupAbsolute);
|
|
348
|
+
moved = true;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const fresh = await DeltaStore.open(options.workspaceRoot, { access: "write" });
|
|
352
|
+
await fresh.close();
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
ok: true,
|
|
356
|
+
applied: true,
|
|
357
|
+
needsConfirmation: false,
|
|
358
|
+
store,
|
|
359
|
+
...(moved ? { backupPath } : {}),
|
|
360
|
+
actions,
|
|
361
|
+
diagnostics: [],
|
|
362
|
+
nextActions: [
|
|
363
|
+
"forge delta status --json",
|
|
364
|
+
"forge agent hooks smoke --target codex --json",
|
|
365
|
+
"forge agent doctor --target codex --json",
|
|
366
|
+
],
|
|
367
|
+
exitCode: 0,
|
|
368
|
+
};
|
|
369
|
+
} catch (error) {
|
|
370
|
+
const diagnostics = [
|
|
371
|
+
createDiagnostic({
|
|
372
|
+
severity: "error",
|
|
373
|
+
code: "FORGE_DELTA_REPAIR_FAILED",
|
|
374
|
+
message: error instanceof Error ? error.message : "Forge Delta repair failed",
|
|
375
|
+
file: store,
|
|
376
|
+
}),
|
|
377
|
+
];
|
|
378
|
+
if (moved) {
|
|
379
|
+
try {
|
|
380
|
+
rmSync(absoluteStorePath, { recursive: true, force: true });
|
|
381
|
+
renameSync(backupAbsolute, absoluteStorePath);
|
|
382
|
+
actions.push({ kind: "restore", from: backupPath, to: store });
|
|
383
|
+
} catch (restoreError) {
|
|
384
|
+
diagnostics.push(createDiagnostic({
|
|
385
|
+
severity: "error",
|
|
386
|
+
code: "FORGE_DELTA_REPAIR_RESTORE_FAILED",
|
|
387
|
+
message: restoreError instanceof Error ? restoreError.message : "failed to restore Delta backup after repair failure",
|
|
388
|
+
file: backupPath,
|
|
389
|
+
}));
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
ok: false,
|
|
394
|
+
applied: false,
|
|
395
|
+
needsConfirmation: false,
|
|
396
|
+
store,
|
|
397
|
+
...(moved ? { backupPath } : {}),
|
|
398
|
+
actions,
|
|
399
|
+
diagnostics,
|
|
400
|
+
nextActions: [
|
|
401
|
+
"Close any running forge dev or external agent process using .forge/delta/delta.db",
|
|
402
|
+
"forge delta repair --dry-run --json",
|
|
403
|
+
],
|
|
404
|
+
exitCode: 1,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export async function runDeltaRepair(options: DeltaRepairOptions): Promise<DeltaRepairResult> {
|
|
410
|
+
return normalizeDeltaCliCommandHints(options.workspaceRoot, await runDeltaRepairRaw(options));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export function deltaQueueDrainCheck(queue: DeltaAgentQueueSnapshot): DeltaDoctorCheck {
|
|
414
|
+
const pendingEvents = queue.pendingEvents;
|
|
415
|
+
const hasPartialTail = typeof queue.incompleteLineBytes === "number" && queue.incompleteLineBytes > 0;
|
|
416
|
+
const agedPending = typeof queue.oldestPendingAgeMs === "number" && queue.oldestPendingAgeMs >= 5 * 60_000 &&
|
|
417
|
+
((pendingEvents !== null && pendingEvents > 0) || hasPartialTail);
|
|
418
|
+
const age = typeof queue.oldestPendingAgeMs === "number"
|
|
419
|
+
? `; pending for at least ${Math.floor(queue.oldestPendingAgeMs / 1_000)}s (${queue.ageSource})`
|
|
420
|
+
: "";
|
|
421
|
+
return {
|
|
422
|
+
name: "queue-drain",
|
|
423
|
+
ok: queue.freshness === "fresh",
|
|
424
|
+
severity: queue.error || agedPending || (queue.freshness === "unknown" && !hasPartialTail) ? "error" : "warning",
|
|
425
|
+
message: hasPartialTail && pendingEvents === 0
|
|
426
|
+
? `agent queue has ${queue.incompleteLineBytes} incomplete trailing byte${queue.incompleteLineBytes === 1 ? "" : "s"}${age}`
|
|
427
|
+
: queue.freshness === "unknown"
|
|
428
|
+
? `agent queue backlog is unknown${queue.generationMismatch ? ": checkpoint belongs to a different queue generation" : queue.error ? `: ${queue.error}` : ""}`
|
|
429
|
+
: pendingEvents === 0
|
|
430
|
+
? "agent queue has no complete pending events"
|
|
431
|
+
: `agent queue has ${pendingEvents} pending event${pendingEvents === 1 ? "" : "s"}${
|
|
432
|
+
hasPartialTail ? ` and ${queue.incompleteLineBytes} incomplete trailing bytes` : ""
|
|
433
|
+
}${age}`,
|
|
434
|
+
evidence: {
|
|
435
|
+
queuePath: queue.queuePath,
|
|
436
|
+
pendingEvents,
|
|
437
|
+
pendingBytes: queue.pendingBytes,
|
|
438
|
+
incompleteLineBytes: queue.incompleteLineBytes,
|
|
439
|
+
queueSizeBytes: queue.queueSizeBytes,
|
|
440
|
+
checkpointPath: queue.checkpointPath,
|
|
441
|
+
checkpointOffset: queue.checkpointOffset,
|
|
442
|
+
effectiveOffset: queue.effectiveOffset,
|
|
443
|
+
checkpointUpdatedAt: queue.checkpointUpdatedAt,
|
|
444
|
+
checkpointGeneration: queue.checkpointGeneration,
|
|
445
|
+
queueGeneration: queue.queueGeneration,
|
|
446
|
+
generationMismatch: queue.generationMismatch,
|
|
447
|
+
freshness: queue.freshness,
|
|
448
|
+
oldestPendingAt: queue.oldestPendingAt,
|
|
449
|
+
oldestPendingAgeMs: queue.oldestPendingAgeMs,
|
|
450
|
+
ageSource: queue.ageSource,
|
|
451
|
+
},
|
|
452
|
+
suggestedCommands: queue.freshness !== "fresh"
|
|
453
|
+
? ["forge agent ingest codex --file .forge/agent/events.ndjson --json"]
|
|
454
|
+
: undefined,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async function runDeltaDoctorRaw(workspaceRoot: string): Promise<DeltaDoctorResult> {
|
|
459
|
+
const status = await runDeltaStatus(workspaceRoot, { verbose: true });
|
|
460
|
+
const details = status.exitCode === 0 ? status.details : undefined;
|
|
461
|
+
const checks: DeltaDoctorCheck[] = [
|
|
462
|
+
{
|
|
463
|
+
name: "delta-status",
|
|
464
|
+
ok: status.exitCode === 0,
|
|
465
|
+
severity: "error",
|
|
466
|
+
message: status.exitCode === 0 ? "DeltaDB status is readable" : "DeltaDB status is unavailable",
|
|
467
|
+
evidence: {
|
|
468
|
+
store: status.store,
|
|
469
|
+
...(status.exitCode === 1 ? { broker: status.broker } : {}),
|
|
470
|
+
},
|
|
471
|
+
suggestedCommands: status.exitCode === 0 ? undefined : status.nextActions,
|
|
472
|
+
},
|
|
473
|
+
];
|
|
474
|
+
|
|
475
|
+
const busy = probeDeltaStoreBusy(workspaceRoot);
|
|
476
|
+
if (busy) {
|
|
477
|
+
const busyInfo = describeDeltaStoreBusy(busy, workspaceRoot);
|
|
478
|
+
checks.push({
|
|
479
|
+
name: "delta-writable",
|
|
480
|
+
ok: false,
|
|
481
|
+
severity: "warning",
|
|
482
|
+
message: busyInfo.processAlive
|
|
483
|
+
? `Delta writer lock is held by pid ${busyInfo.pid ?? "unknown"}`
|
|
484
|
+
: `Delta writer lock is present at ${busyInfo.relativeLockPath}`,
|
|
485
|
+
evidence: { busy: busyInfo },
|
|
486
|
+
suggestedCommands: ["forge delta status --verbose --json"],
|
|
487
|
+
});
|
|
488
|
+
} else {
|
|
489
|
+
let writer: DeltaStore | null = null;
|
|
490
|
+
try {
|
|
491
|
+
writer = await DeltaStore.open(workspaceRoot, { access: "write" });
|
|
492
|
+
checks.push({
|
|
493
|
+
name: "delta-writable",
|
|
494
|
+
ok: true,
|
|
495
|
+
severity: "error",
|
|
496
|
+
message: "DeltaDB writer lock can be acquired",
|
|
497
|
+
});
|
|
498
|
+
} catch (error) {
|
|
499
|
+
if (error instanceof DeltaStoreBusyError) {
|
|
500
|
+
const busyInfo = describeDeltaStoreBusy(error, workspaceRoot);
|
|
501
|
+
checks.push({
|
|
502
|
+
name: "delta-writable",
|
|
503
|
+
ok: false,
|
|
504
|
+
severity: "warning",
|
|
505
|
+
message: busyInfo.relativeLockPath.endsWith("postmaster.pid")
|
|
506
|
+
? "Delta writer is currently held by an active local PGlite runtime"
|
|
507
|
+
: busyInfo.processAlive
|
|
508
|
+
? `Delta writer lock is held by pid ${busyInfo.pid ?? "unknown"}`
|
|
509
|
+
: `Delta writer lock is present at ${busyInfo.relativeLockPath}`,
|
|
510
|
+
evidence: { busy: busyInfo },
|
|
511
|
+
suggestedCommands: ["forge delta status --verbose --json"],
|
|
512
|
+
});
|
|
513
|
+
} else {
|
|
514
|
+
checks.push({
|
|
515
|
+
name: "delta-writable",
|
|
516
|
+
ok: false,
|
|
517
|
+
severity: "error",
|
|
518
|
+
message: error instanceof Error ? error.message : "DeltaDB writer lock cannot be acquired",
|
|
519
|
+
suggestedCommands: ["forge delta repair --dry-run --json"],
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
} finally {
|
|
523
|
+
await writer?.close().catch(() => undefined);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const schemaOk = !details?.schema.storedVersion || details.schema.storedVersion === details.schema.expectedVersion;
|
|
528
|
+
checks.push({
|
|
529
|
+
name: "schema-current",
|
|
530
|
+
ok: Boolean(details) && schemaOk,
|
|
531
|
+
severity: "error",
|
|
532
|
+
message: details
|
|
533
|
+
? `schema ${details.schema.storedVersion ?? "not initialized"}; expected ${details.schema.expectedVersion}`
|
|
534
|
+
: "schema details unavailable",
|
|
535
|
+
evidence: details?.schema,
|
|
536
|
+
suggestedCommands: schemaOk ? undefined : ["forge delta repair --dry-run --json"],
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
checks.push(deltaQueueDrainCheck(status.queue));
|
|
540
|
+
|
|
541
|
+
const redaction = details?.operational.queueRedaction ?? "unknown";
|
|
542
|
+
checks.push({
|
|
543
|
+
name: "queue-redaction",
|
|
544
|
+
ok: redaction === "none" || redaction === "redacted",
|
|
545
|
+
severity: "warning",
|
|
546
|
+
message: redaction === "none"
|
|
547
|
+
? "agent queue is empty or absent"
|
|
548
|
+
: redaction === "redacted"
|
|
549
|
+
? "agent queue contains redacted payloads"
|
|
550
|
+
: `agent queue redaction status is ${redaction}`,
|
|
551
|
+
evidence: details
|
|
552
|
+
? {
|
|
553
|
+
queuePath: details.operational.queuePath,
|
|
554
|
+
queueRedaction: redaction,
|
|
555
|
+
queueHistoryPath: details.operational.queueHistoryPath,
|
|
556
|
+
queueHistoryLines: details.operational.queueHistoryLines,
|
|
557
|
+
lastCompactionAt: details.operational.lastCompactionAt,
|
|
558
|
+
}
|
|
559
|
+
: undefined,
|
|
560
|
+
suggestedCommands: redaction === "legacy-raw-present" || redaction === "mixed"
|
|
561
|
+
? ["forge agent ingest codex --file .forge/agent/events.ndjson --json", "forge delta compact --json"]
|
|
562
|
+
: undefined,
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
const gitignore = readGitignore(workspaceRoot);
|
|
566
|
+
const requiredGitignore = [
|
|
567
|
+
".codex/",
|
|
568
|
+
".forge/delta/",
|
|
569
|
+
".forge/agent/",
|
|
570
|
+
".forge/agent/*.ndjson",
|
|
571
|
+
".forge/agent/*.history",
|
|
572
|
+
".forge/last-run.json",
|
|
573
|
+
".forge/runtime-cache/",
|
|
574
|
+
".forge/studio",
|
|
575
|
+
];
|
|
576
|
+
const missingGitignore = requiredGitignore.filter((entry) => !gitignore.includes(entry));
|
|
577
|
+
checks.push({
|
|
578
|
+
name: "gitignore-operational-state",
|
|
579
|
+
ok: missingGitignore.length === 0,
|
|
580
|
+
severity: "warning",
|
|
581
|
+
message: missingGitignore.length === 0
|
|
582
|
+
? "local Delta, agent queue, and Studio state are ignored"
|
|
583
|
+
: `missing gitignore coverage: ${missingGitignore.join(", ")}`,
|
|
584
|
+
evidence: { required: requiredGitignore, missing: missingGitignore },
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
const ok = checks.every((check) => check.ok || check.severity === "warning");
|
|
588
|
+
return {
|
|
589
|
+
ok,
|
|
590
|
+
checks,
|
|
591
|
+
status,
|
|
592
|
+
nextActions: uniqueDeltaDoctorNextActions(checks),
|
|
593
|
+
exitCode: ok ? 0 : 1,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
export async function runDeltaDoctor(workspaceRoot: string): Promise<DeltaDoctorResult> {
|
|
598
|
+
return normalizeDeltaCliCommandHints(workspaceRoot, await runDeltaDoctorRaw(workspaceRoot));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function readGitignore(workspaceRoot: string): string {
|
|
602
|
+
try {
|
|
603
|
+
return readFileSync(join(workspaceRoot, ".gitignore"), "utf8");
|
|
604
|
+
} catch {
|
|
605
|
+
return "";
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function uniqueDeltaDoctorNextActions(checks: DeltaDoctorCheck[]): string[] {
|
|
610
|
+
const actions = checks.flatMap((check) => check.suggestedCommands ?? []);
|
|
611
|
+
return [...new Set(actions.length > 0 ? actions : ["forge delta status --verbose --json"])];
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function agentQueueHistoryPath(workspaceRoot: string): string {
|
|
615
|
+
return join(workspaceRoot, ".forge", "agent", "events.ndjson.history");
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function lineTimestamp(line: string): string | undefined {
|
|
619
|
+
try {
|
|
620
|
+
const parsed = JSON.parse(line) as Record<string, unknown>;
|
|
621
|
+
for (const key of ["enqueuedAt", "capturedAt", "timestamp"]) {
|
|
622
|
+
if (typeof parsed[key] === "string") {
|
|
623
|
+
return parsed[key] as string;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const payload = parsed.payload;
|
|
627
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
628
|
+
const event = (payload as Record<string, unknown>).event;
|
|
629
|
+
if (event && typeof event === "object" && !Array.isArray(event) && typeof (event as Record<string, unknown>).timestamp === "string") {
|
|
630
|
+
return (event as Record<string, string>).timestamp;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
} catch {
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
return undefined;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function redactedJsonLine(line: string): string | undefined {
|
|
640
|
+
try {
|
|
641
|
+
const parsed = JSON.parse(line) as Record<string, unknown>;
|
|
642
|
+
return JSON.stringify(redactDeltaPayload(parsed).value);
|
|
643
|
+
} catch {
|
|
644
|
+
return undefined;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function compactLines(text: string, maxBytes = 256_000): { text: string; linesBefore: number; linesAfter: number } {
|
|
649
|
+
const redactedLines = text
|
|
650
|
+
.split(/\r?\n/u)
|
|
651
|
+
.filter((line) => line.trim().length > 0)
|
|
652
|
+
.map(redactedJsonLine)
|
|
653
|
+
.filter((line): line is string => typeof line === "string");
|
|
654
|
+
const kept: string[] = [];
|
|
655
|
+
let bytes = 0;
|
|
656
|
+
for (const line of [...redactedLines].reverse()) {
|
|
657
|
+
const lineBytes = Buffer.byteLength(`${line}\n`);
|
|
658
|
+
if (kept.length > 0 && bytes + lineBytes > maxBytes) {
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
kept.push(line);
|
|
662
|
+
bytes += lineBytes;
|
|
663
|
+
}
|
|
664
|
+
const lines = kept.reverse();
|
|
665
|
+
return {
|
|
666
|
+
text: lines.length > 0 ? `${lines.join("\n")}\n` : "",
|
|
667
|
+
linesBefore: redactedLines.length,
|
|
668
|
+
linesAfter: lines.length,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
async function runDeltaCompactRaw(options: DeltaCompactOptions): Promise<DeltaCompactResult> {
|
|
673
|
+
const historyPath = agentQueueHistoryPath(options.workspaceRoot);
|
|
674
|
+
const relativeHistoryPath = normalizePath(relative(options.workspaceRoot, historyPath));
|
|
675
|
+
if (!existsSync(historyPath)) {
|
|
676
|
+
return {
|
|
677
|
+
ok: true,
|
|
678
|
+
subcommand: "compact",
|
|
679
|
+
applied: false,
|
|
680
|
+
dryRun: Boolean(options.dryRun),
|
|
681
|
+
files: [{
|
|
682
|
+
path: relativeHistoryPath,
|
|
683
|
+
exists: false,
|
|
684
|
+
beforeBytes: 0,
|
|
685
|
+
afterBytes: 0,
|
|
686
|
+
linesBefore: 0,
|
|
687
|
+
linesAfter: 0,
|
|
688
|
+
}],
|
|
689
|
+
diagnostics: [],
|
|
690
|
+
nextActions: ["forge delta status --verbose --json"],
|
|
691
|
+
exitCode: 0,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
const before = readFileSync(historyPath, "utf8");
|
|
695
|
+
const compacted = compactLines(before);
|
|
696
|
+
const beforeBytes = Buffer.byteLength(before);
|
|
697
|
+
const afterBytes = Buffer.byteLength(compacted.text);
|
|
698
|
+
if (!options.dryRun && compacted.text !== before) {
|
|
699
|
+
writeFileSync(historyPath, compacted.text, "utf8");
|
|
700
|
+
}
|
|
701
|
+
return {
|
|
702
|
+
ok: true,
|
|
703
|
+
subcommand: "compact",
|
|
704
|
+
applied: !options.dryRun && compacted.text !== before,
|
|
705
|
+
dryRun: Boolean(options.dryRun),
|
|
706
|
+
files: [{
|
|
707
|
+
path: relativeHistoryPath,
|
|
708
|
+
exists: true,
|
|
709
|
+
beforeBytes,
|
|
710
|
+
afterBytes,
|
|
711
|
+
linesBefore: compacted.linesBefore,
|
|
712
|
+
linesAfter: compacted.linesAfter,
|
|
713
|
+
}],
|
|
714
|
+
diagnostics: [],
|
|
715
|
+
nextActions: ["forge delta status --verbose --json"],
|
|
716
|
+
exitCode: 0,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export async function runDeltaCompact(options: DeltaCompactOptions): Promise<DeltaCompactResult> {
|
|
721
|
+
return normalizeDeltaCliCommandHints(options.workspaceRoot, await runDeltaCompactRaw(options));
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function parseOlderThan(value: string | undefined): { cutoff?: Date; error?: string } {
|
|
725
|
+
if (!value) {
|
|
726
|
+
return { error: "forge delta prune requires --older-than <duration>, for example 30d" };
|
|
727
|
+
}
|
|
728
|
+
const match = value.match(/^(\d+)(m|h|d|w)$/u);
|
|
729
|
+
if (!match) {
|
|
730
|
+
return { error: "--older-than supports minutes, hours, days, or weeks, for example 30d" };
|
|
731
|
+
}
|
|
732
|
+
const amount = Number(match[1]);
|
|
733
|
+
const unit = match[2];
|
|
734
|
+
const multiplier = unit === "m" ? 60_000 : unit === "h" ? 3_600_000 : unit === "d" ? 86_400_000 : 604_800_000;
|
|
735
|
+
return { cutoff: new Date(Date.now() - amount * multiplier) };
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
async function runDeltaPruneRaw(options: DeltaPruneOptions): Promise<DeltaPruneResult> {
|
|
739
|
+
const parsed = parseOlderThan(options.olderThan);
|
|
740
|
+
if (!parsed.cutoff) {
|
|
741
|
+
return {
|
|
742
|
+
ok: false,
|
|
743
|
+
subcommand: "prune",
|
|
744
|
+
applied: false,
|
|
745
|
+
needsConfirmation: false,
|
|
746
|
+
olderThan: options.olderThan,
|
|
747
|
+
files: [],
|
|
748
|
+
diagnostics: [createDiagnostic({
|
|
749
|
+
severity: "error",
|
|
750
|
+
code: "FORGE_DELTA_PRUNE_USAGE",
|
|
751
|
+
message: parsed.error ?? "invalid prune duration",
|
|
752
|
+
suggestedCommands: ["forge delta prune --older-than 30d --dry-run --json"],
|
|
753
|
+
})],
|
|
754
|
+
nextActions: ["forge delta prune --older-than 30d --dry-run --json"],
|
|
755
|
+
exitCode: 1,
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
const cutoffIso = parsed.cutoff.toISOString();
|
|
759
|
+
const historyPath = agentQueueHistoryPath(options.workspaceRoot);
|
|
760
|
+
const relativeHistoryPath = normalizePath(relative(options.workspaceRoot, historyPath));
|
|
761
|
+
if (!existsSync(historyPath)) {
|
|
762
|
+
return {
|
|
763
|
+
ok: true,
|
|
764
|
+
subcommand: "prune",
|
|
765
|
+
applied: false,
|
|
766
|
+
needsConfirmation: false,
|
|
767
|
+
olderThan: options.olderThan,
|
|
768
|
+
cutoff: cutoffIso,
|
|
769
|
+
files: [{
|
|
770
|
+
path: relativeHistoryPath,
|
|
771
|
+
exists: false,
|
|
772
|
+
beforeBytes: 0,
|
|
773
|
+
afterBytes: 0,
|
|
774
|
+
linesBefore: 0,
|
|
775
|
+
linesAfter: 0,
|
|
776
|
+
prunedLines: 0,
|
|
777
|
+
}],
|
|
778
|
+
diagnostics: [],
|
|
779
|
+
nextActions: ["forge delta status --verbose --json"],
|
|
780
|
+
exitCode: 0,
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
const before = readFileSync(historyPath, "utf8");
|
|
784
|
+
const lines = before.split(/\r?\n/u).filter((line) => line.trim().length > 0);
|
|
785
|
+
const kept = lines.filter((line) => {
|
|
786
|
+
const timestamp = lineTimestamp(line);
|
|
787
|
+
return !timestamp || Date.parse(timestamp) >= parsed.cutoff!.getTime();
|
|
788
|
+
});
|
|
789
|
+
const nextText = kept.length > 0 ? `${kept.join("\n")}\n` : "";
|
|
790
|
+
const needsConfirmation = !options.dryRun && !options.yes && kept.length !== lines.length;
|
|
791
|
+
if (!options.dryRun && !needsConfirmation && nextText !== before) {
|
|
792
|
+
writeFileSync(historyPath, nextText, "utf8");
|
|
793
|
+
}
|
|
794
|
+
return {
|
|
795
|
+
ok: true,
|
|
796
|
+
subcommand: "prune",
|
|
797
|
+
applied: !options.dryRun && !needsConfirmation && nextText !== before,
|
|
798
|
+
needsConfirmation,
|
|
799
|
+
olderThan: options.olderThan,
|
|
800
|
+
cutoff: cutoffIso,
|
|
801
|
+
files: [{
|
|
802
|
+
path: relativeHistoryPath,
|
|
803
|
+
exists: true,
|
|
804
|
+
beforeBytes: Buffer.byteLength(before),
|
|
805
|
+
afterBytes: Buffer.byteLength(nextText),
|
|
806
|
+
linesBefore: lines.length,
|
|
807
|
+
linesAfter: kept.length,
|
|
808
|
+
prunedLines: lines.length - kept.length,
|
|
809
|
+
}],
|
|
810
|
+
diagnostics: [],
|
|
811
|
+
nextActions: needsConfirmation
|
|
812
|
+
? [`forge delta prune --older-than ${options.olderThan} --yes --json`, "forge delta status --verbose --json"]
|
|
813
|
+
: ["forge delta status --verbose --json"],
|
|
814
|
+
exitCode: 0,
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
export async function runDeltaPrune(options: DeltaPruneOptions): Promise<DeltaPruneResult> {
|
|
819
|
+
return normalizeDeltaCliCommandHints(options.workspaceRoot, await runDeltaPruneRaw(options));
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function resolveExportPath(workspaceRoot: string, output: string): string {
|
|
823
|
+
const absolute = resolve(workspaceRoot, output);
|
|
824
|
+
const rel = relative(resolve(workspaceRoot), absolute);
|
|
825
|
+
if (rel.startsWith("..") || resolve(rel) === rel) {
|
|
826
|
+
throw new Error(`refusing to write Delta export outside workspace: ${output}`);
|
|
827
|
+
}
|
|
828
|
+
return absolute;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
async function runDeltaExportRaw(options: DeltaExportOptions): Promise<DeltaExportResult> {
|
|
832
|
+
if (!options.redacted) {
|
|
833
|
+
return {
|
|
834
|
+
ok: false,
|
|
835
|
+
subcommand: "export",
|
|
836
|
+
redacted: false,
|
|
837
|
+
written: false,
|
|
838
|
+
diagnostics: [createDiagnostic({
|
|
839
|
+
severity: "error",
|
|
840
|
+
code: "FORGE_DELTA_EXPORT_REDACTED_REQUIRED",
|
|
841
|
+
message: "Delta export only supports redacted output; pass --redacted.",
|
|
842
|
+
suggestedCommands: ["forge delta export --redacted --json"],
|
|
843
|
+
})],
|
|
844
|
+
nextActions: ["forge delta export --redacted --json"],
|
|
845
|
+
exitCode: 1,
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
const limit = Math.max(1, Math.min(Math.floor(options.limit ?? 100), 500));
|
|
849
|
+
const store: DeltaStore | DeltaStoreBusyError | Error = await DeltaStore.open(options.workspaceRoot, { access: "read" }).catch((error: unknown) =>
|
|
850
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
851
|
+
);
|
|
852
|
+
if (store instanceof DeltaStoreBusyError) {
|
|
853
|
+
const busy = describeDeltaStoreBusy(store, options.workspaceRoot);
|
|
854
|
+
return {
|
|
855
|
+
ok: false,
|
|
856
|
+
subcommand: "export",
|
|
857
|
+
redacted: true,
|
|
858
|
+
written: false,
|
|
859
|
+
busy,
|
|
860
|
+
diagnostics: [createDiagnostic({
|
|
861
|
+
severity: "error",
|
|
862
|
+
code: "FORGE_DELTA_BUSY",
|
|
863
|
+
message: `Forge Delta export cannot run while the local store is busy: ${summarizeDeltaStoreBusy(busy)}`,
|
|
864
|
+
suggestedCommands: ["forge delta status --json"],
|
|
865
|
+
})],
|
|
866
|
+
nextActions: ["forge delta status --json"],
|
|
867
|
+
exitCode: 1,
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
if (store instanceof Error) {
|
|
871
|
+
const message = store.message || "unknown Delta store open failure";
|
|
872
|
+
const pgliteAbort = /Aborted\(\)|postmaster|pglite/iu.test(message);
|
|
873
|
+
return {
|
|
874
|
+
ok: false,
|
|
875
|
+
subcommand: "export",
|
|
876
|
+
redacted: true,
|
|
877
|
+
written: false,
|
|
878
|
+
diagnostics: [createDiagnostic({
|
|
879
|
+
severity: "error",
|
|
880
|
+
code: "FORGE_DELTA_EXPORT_FAILED",
|
|
881
|
+
message: `Forge Delta export could not open the local store: ${message}`,
|
|
882
|
+
fixHint: pgliteAbort
|
|
883
|
+
? "The local PGlite Delta store may be stale or corrupt. Inspect status first; if no Forge process is active, run a dry-run repair before removing local memory."
|
|
884
|
+
: "Inspect Delta status before retrying the export.",
|
|
885
|
+
suggestedCommands: [
|
|
886
|
+
"forge delta status --verbose --json",
|
|
887
|
+
"forge delta repair --dry-run --json",
|
|
888
|
+
"forge doctor windows --json",
|
|
889
|
+
],
|
|
890
|
+
})],
|
|
891
|
+
nextActions: [
|
|
892
|
+
"forge delta status --verbose --json",
|
|
893
|
+
"forge delta repair --dry-run --json",
|
|
894
|
+
],
|
|
895
|
+
exitCode: 1,
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
try {
|
|
899
|
+
const status = await store.status();
|
|
900
|
+
const details = await store.statusDetails();
|
|
901
|
+
const timeline = await store.timeline({ limit });
|
|
902
|
+
const semanticTimeline = await store.semanticTimeline({ limit }, { refresh: false });
|
|
903
|
+
const agentMemory = await store.listAgentMemoryEvents({ limit });
|
|
904
|
+
const data = {
|
|
905
|
+
schemaVersion: "0.1.0",
|
|
906
|
+
redacted: true,
|
|
907
|
+
exportedAt: new Date().toISOString(),
|
|
908
|
+
status: { ...status, details },
|
|
909
|
+
timeline,
|
|
910
|
+
semanticTimeline,
|
|
911
|
+
agentMemory,
|
|
912
|
+
};
|
|
913
|
+
let output: string | undefined;
|
|
914
|
+
if (options.output) {
|
|
915
|
+
const absolute = resolveExportPath(options.workspaceRoot, options.output);
|
|
916
|
+
mkdirSync(dirname(absolute), { recursive: true });
|
|
917
|
+
writeFileSync(absolute, `${JSON.stringify(data, null, 2)}\n`, "utf8");
|
|
918
|
+
output = normalizePath(relative(options.workspaceRoot, absolute));
|
|
919
|
+
}
|
|
920
|
+
return {
|
|
921
|
+
ok: true,
|
|
922
|
+
subcommand: "export",
|
|
923
|
+
redacted: true,
|
|
924
|
+
...(output ? { output } : {}),
|
|
925
|
+
written: Boolean(output),
|
|
926
|
+
data,
|
|
927
|
+
diagnostics: [],
|
|
928
|
+
nextActions: ["forge delta status --verbose --json"],
|
|
929
|
+
exitCode: 0,
|
|
930
|
+
};
|
|
931
|
+
} finally {
|
|
932
|
+
await store.close();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
export async function runDeltaExport(options: DeltaExportOptions): Promise<DeltaExportResult> {
|
|
937
|
+
return normalizeDeltaCliCommandHints(options.workspaceRoot, await runDeltaExportRaw(options));
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
export function formatDeltaStatusHuman(result: DeltaStatusResult): string {
|
|
941
|
+
const lines = ["Forge Delta", ""];
|
|
942
|
+
if (!result.ok) {
|
|
943
|
+
lines.push("Status:");
|
|
944
|
+
lines.push(" unavailable");
|
|
945
|
+
lines.push(` local store: ${result.store}`);
|
|
946
|
+
lines.push(` local broker: ${result.broker.active ? `responding (pid ${result.broker.pid ?? "unknown"})` : "not responding"}`);
|
|
947
|
+
lines.push(` agent queue: ${result.queue.freshness} (${result.queue.pendingEvents ?? "unknown"} complete pending events, ${result.queue.pendingBytes ?? "unknown"} pending bytes)`);
|
|
948
|
+
lines.push(` checkpoint: ${result.queue.checkpointOffset ?? "unknown"} at ${result.queue.checkpointPath}`);
|
|
949
|
+
if (result.queue.generationMismatch) lines.push(" checkpoint generation differs from the current queue; backlog is inspected from the new queue start");
|
|
950
|
+
lines.push("");
|
|
951
|
+
lines.push("Diagnostics:");
|
|
952
|
+
for (const diagnostic of result.diagnostics) {
|
|
953
|
+
lines.push(` ${diagnostic.code}: ${diagnostic.message}`);
|
|
954
|
+
if (diagnostic.fixHint) {
|
|
955
|
+
lines.push(` fix: ${diagnostic.fixHint}`);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
lines.push("");
|
|
959
|
+
lines.push("Next:");
|
|
960
|
+
for (const action of result.nextActions) {
|
|
961
|
+
lines.push(` ${action}`);
|
|
962
|
+
}
|
|
963
|
+
return `${lines.join("\n")}\n`;
|
|
964
|
+
}
|
|
965
|
+
lines.push("Status:");
|
|
966
|
+
lines.push(` ${result.recording ? "recording enabled" : "recording disabled"}`);
|
|
967
|
+
lines.push(` local store: ${result.store}`);
|
|
968
|
+
lines.push("");
|
|
969
|
+
lines.push("Current work session:");
|
|
970
|
+
if (result.workSession) {
|
|
971
|
+
lines.push(` ${result.workSession.id}`);
|
|
972
|
+
lines.push(` title: ${result.workSession.title}`);
|
|
973
|
+
lines.push(` status: ${result.workSession.status}`);
|
|
974
|
+
lines.push(` confidence: ${result.workSession.confidence.toFixed(2)}`);
|
|
975
|
+
lines.push(` operations: ${result.workSession.operationCount}`);
|
|
976
|
+
if (result.workSession.gitBranch) {
|
|
977
|
+
lines.push(` branch: ${result.workSession.gitBranch}`);
|
|
978
|
+
}
|
|
979
|
+
if (result.workSession.reasons.length > 0) {
|
|
980
|
+
lines.push("");
|
|
981
|
+
lines.push("Why this session:");
|
|
982
|
+
for (const reason of result.workSession.reasons.slice(0, 5)) {
|
|
983
|
+
lines.push(` - ${reason.signal}${reason.value ? `: ${reason.value}` : ""}`);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
} else {
|
|
987
|
+
lines.push(" none");
|
|
988
|
+
}
|
|
989
|
+
lines.push("");
|
|
990
|
+
lines.push("Latest recorder session:");
|
|
991
|
+
if (result.session) {
|
|
992
|
+
lines.push(` ${result.session.id}`);
|
|
993
|
+
lines.push(` started: ${result.session.startedAt}`);
|
|
994
|
+
lines.push(` operations: ${result.session.operationCount}`);
|
|
995
|
+
} else {
|
|
996
|
+
lines.push(" none");
|
|
997
|
+
}
|
|
998
|
+
lines.push("");
|
|
999
|
+
lines.push("Recent operations:");
|
|
1000
|
+
if (result.recentOperations.length === 0) {
|
|
1001
|
+
lines.push(" none");
|
|
1002
|
+
} else {
|
|
1003
|
+
for (const operation of result.recentOperations) {
|
|
1004
|
+
lines.push(` ${operation.timestamp.slice(11, 16)} ${operation.kind}${operation.summary ? ` ${operation.summary}` : ""}`);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
if (result.details) {
|
|
1008
|
+
lines.push("");
|
|
1009
|
+
lines.push("Details:");
|
|
1010
|
+
lines.push(` schema: ${result.details.schema.storedVersion ?? "unknown"} (expected ${result.details.schema.expectedVersion})`);
|
|
1011
|
+
lines.push(` lock: ${result.details.locks.forgeLockPresent ? "present" : "absent"} at ${result.details.paths.lock}`);
|
|
1012
|
+
lines.push(` postmaster: ${result.details.locks.postmasterPresent ? "present" : "absent"} at ${result.details.paths.postmaster}`);
|
|
1013
|
+
lines.push(` health: ${result.details.health.status}`);
|
|
1014
|
+
for (const check of result.details.health.checks) {
|
|
1015
|
+
lines.push(` ${check.status}: ${check.name} - ${check.message}`);
|
|
1016
|
+
}
|
|
1017
|
+
lines.push(" operational:");
|
|
1018
|
+
lines.push(` queue: ${result.details.operational.queueExists ? `${result.details.operational.queueSizeBytes} bytes` : "absent"} at ${result.details.operational.queuePath}`);
|
|
1019
|
+
lines.push(` pending events: ${result.details.operational.queuePendingEvents}`);
|
|
1020
|
+
lines.push(` queue freshness: ${result.queue.freshness}; incomplete trailing bytes: ${result.queue.incompleteLineBytes ?? "unknown"}`);
|
|
1021
|
+
if (result.queue.generationMismatch) lines.push(" checkpoint generation differs from the current queue");
|
|
1022
|
+
lines.push(` queue redaction: ${result.details.operational.queueRedaction}`);
|
|
1023
|
+
lines.push(` queue history: ${result.details.operational.queueHistoryExists ? `${result.details.operational.queueHistorySizeBytes} bytes, ${result.details.operational.queueHistoryLines} lines` : "absent"} at ${result.details.operational.queueHistoryPath}`);
|
|
1024
|
+
if (result.details.operational.lastCompactionAt) {
|
|
1025
|
+
lines.push(` last compaction: ${result.details.operational.lastCompactionAt}`);
|
|
1026
|
+
}
|
|
1027
|
+
lines.push(` overhead: ${result.details.operational.estimatedOverhead}`);
|
|
1028
|
+
if (result.details.operational.oldestOperationAt) {
|
|
1029
|
+
lines.push(` oldest operation: ${result.details.operational.oldestOperationAt}`);
|
|
1030
|
+
}
|
|
1031
|
+
if (result.details.operational.newestOperationAt) {
|
|
1032
|
+
lines.push(` newest operation: ${result.details.operational.newestOperationAt}`);
|
|
1033
|
+
}
|
|
1034
|
+
lines.push(" counts:");
|
|
1035
|
+
for (const [name, count] of Object.entries(result.details.counts)) {
|
|
1036
|
+
lines.push(` ${name}: ${count}`);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return `${lines.join("\n")}\n`;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
export function formatDeltaStatusJson(result: DeltaStatusResult): string {
|
|
1043
|
+
return `${JSON.stringify(result, null, 2)}\n`;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
export function formatDeltaRepairHuman(result: DeltaRepairResult): string {
|
|
1047
|
+
const lines = [
|
|
1048
|
+
`Forge Delta repair ${result.ok ? (result.applied ? "applied" : "planned") : "failed"}`,
|
|
1049
|
+
"",
|
|
1050
|
+
`Store: ${result.store}`,
|
|
1051
|
+
];
|
|
1052
|
+
if (result.backupPath) {
|
|
1053
|
+
lines.push(`Backup: ${result.backupPath}`);
|
|
1054
|
+
}
|
|
1055
|
+
lines.push("", "Actions:");
|
|
1056
|
+
for (const action of result.actions) {
|
|
1057
|
+
lines.push(` ${action.kind}${action.from ? ` ${action.from}` : ""}${action.to ? ` -> ${action.to}` : ""}${action.skipped ? " (skipped)" : ""}`);
|
|
1058
|
+
}
|
|
1059
|
+
if (result.diagnostics.length > 0) {
|
|
1060
|
+
lines.push("", "Diagnostics:");
|
|
1061
|
+
for (const diagnostic of result.diagnostics) {
|
|
1062
|
+
lines.push(` ${diagnostic.code}: ${diagnostic.message}`);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (result.nextActions.length > 0) {
|
|
1066
|
+
lines.push("", "Next:");
|
|
1067
|
+
for (const action of result.nextActions) {
|
|
1068
|
+
lines.push(` ${action}`);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
return `${lines.join("\n")}\n`;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
export function formatDeltaRepairJson(result: DeltaRepairResult): string {
|
|
1075
|
+
return `${JSON.stringify(result, null, 2)}\n`;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
export function formatDeltaDoctorHuman(result: DeltaDoctorResult): string {
|
|
1079
|
+
const lines = ["Forge Delta doctor", ""];
|
|
1080
|
+
for (const check of result.checks) {
|
|
1081
|
+
const marker = check.ok ? "OK" : check.severity === "warning" ? "WARN" : "FAIL";
|
|
1082
|
+
lines.push(`${marker} ${check.name} - ${check.message}`);
|
|
1083
|
+
}
|
|
1084
|
+
if (result.nextActions.length > 0) {
|
|
1085
|
+
lines.push("", "Next:");
|
|
1086
|
+
for (const action of result.nextActions) {
|
|
1087
|
+
lines.push(` ${action}`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
lines.push("", result.ok ? "Delta operational state is usable." : "Delta operational state needs attention.");
|
|
1091
|
+
return `${lines.join("\n")}\n`;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
export function formatDeltaDoctorJson(result: DeltaDoctorResult): string {
|
|
1095
|
+
return `${JSON.stringify(result, null, 2)}\n`;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
export function formatDeltaCompactHuman(result: DeltaCompactResult): string {
|
|
1099
|
+
const lines = [`Forge Delta compact ${result.applied ? "applied" : "planned"}`, ""];
|
|
1100
|
+
for (const file of result.files) {
|
|
1101
|
+
lines.push(`${file.path}: ${file.beforeBytes} -> ${file.afterBytes} bytes (${file.linesBefore} -> ${file.linesAfter} lines)`);
|
|
1102
|
+
}
|
|
1103
|
+
return `${lines.join("\n")}\n`;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
export function formatDeltaCompactJson(result: DeltaCompactResult): string {
|
|
1107
|
+
return `${JSON.stringify(result, null, 2)}\n`;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
export function formatDeltaPruneHuman(result: DeltaPruneResult): string {
|
|
1111
|
+
const lines = [`Forge Delta prune ${result.applied ? "applied" : "planned"}`, ""];
|
|
1112
|
+
if (result.cutoff) {
|
|
1113
|
+
lines.push(`Cutoff: ${result.cutoff}`);
|
|
1114
|
+
}
|
|
1115
|
+
for (const file of result.files) {
|
|
1116
|
+
lines.push(`${file.path}: pruned ${file.prunedLines} lines`);
|
|
1117
|
+
}
|
|
1118
|
+
if (result.needsConfirmation) {
|
|
1119
|
+
lines.push("", "Next:", ...result.nextActions.map((action) => ` ${action}`));
|
|
1120
|
+
}
|
|
1121
|
+
return `${lines.join("\n")}\n`;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
export function formatDeltaPruneJson(result: DeltaPruneResult): string {
|
|
1125
|
+
return `${JSON.stringify(result, null, 2)}\n`;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
export function formatDeltaExportHuman(result: DeltaExportResult): string {
|
|
1129
|
+
if (!result.ok) {
|
|
1130
|
+
return `Forge Delta export failed\n${result.diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("\n")}\n`;
|
|
1131
|
+
}
|
|
1132
|
+
return result.output
|
|
1133
|
+
? `Forge Delta export wrote ${result.output}\n`
|
|
1134
|
+
: `${JSON.stringify(result.data, null, 2)}\n`;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
export function formatDeltaExportJson(result: DeltaExportResult): string {
|
|
1138
|
+
return `${JSON.stringify(result, null, 2)}\n`;
|
|
1139
|
+
}
|