@warpgogol/forge 9.4.1 → 9.6.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/CHANGELOG.md +33 -0
- package/README.md +30 -0
- package/README.uk.md +30 -0
- package/bin/cli.ts +163 -53
- package/dist/bin/cli.js +137 -42
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/codebase/codebase.module.d.ts +3 -0
- package/dist/os/codebase/codebase.module.d.ts.map +1 -0
- package/dist/os/codebase/codebase.module.js +53 -0
- package/dist/os/codebase/codebase.module.js.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts +15 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +97 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure.d.ts +22 -0
- package/dist/os/codebase/handlers/codebase-measure.d.ts.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure.js +435 -0
- package/dist/os/codebase/handlers/codebase-measure.js.map +1 -0
- package/dist/os/codebase/index.d.ts +4 -0
- package/dist/os/codebase/index.d.ts.map +1 -0
- package/dist/os/codebase/index.js +13 -0
- package/dist/os/codebase/index.js.map +1 -0
- package/dist/os/codebase/types.d.ts +35 -0
- package/dist/os/codebase/types.d.ts.map +1 -0
- package/dist/os/codebase/types.js +17 -0
- package/dist/os/codebase/types.js.map +1 -0
- package/dist/os/core/handlers/package-health.d.ts +6 -4
- package/dist/os/core/handlers/package-health.d.ts.map +1 -1
- package/dist/os/core/handlers/package-health.js +15 -20
- package/dist/os/core/handlers/package-health.js.map +1 -1
- package/dist/os/correctness/anchors.d.ts +24 -0
- package/dist/os/correctness/anchors.d.ts.map +1 -0
- package/dist/os/correctness/anchors.js +156 -0
- package/dist/os/correctness/anchors.js.map +1 -0
- package/dist/os/correctness/audit/bindings-verify-substance.d.ts +7 -0
- package/dist/os/correctness/audit/bindings-verify-substance.d.ts.map +1 -0
- package/dist/os/correctness/audit/bindings-verify-substance.js +145 -0
- package/dist/os/correctness/audit/bindings-verify-substance.js.map +1 -0
- package/dist/os/correctness/audit/differential.d.ts +7 -0
- package/dist/os/correctness/audit/differential.d.ts.map +1 -0
- package/dist/os/correctness/audit/differential.js +105 -0
- package/dist/os/correctness/audit/differential.js.map +1 -0
- package/dist/os/correctness/audit/ledger-orphans.d.ts +6 -0
- package/dist/os/correctness/audit/ledger-orphans.d.ts.map +1 -0
- package/dist/os/correctness/audit/ledger-orphans.js +71 -0
- package/dist/os/correctness/audit/ledger-orphans.js.map +1 -0
- package/dist/os/correctness/audit/ledger.d.ts +29 -0
- package/dist/os/correctness/audit/ledger.d.ts.map +1 -0
- package/dist/os/correctness/audit/ledger.js +72 -0
- package/dist/os/correctness/audit/ledger.js.map +1 -0
- package/dist/os/correctness/audit/run.d.ts +27 -0
- package/dist/os/correctness/audit/run.d.ts.map +1 -0
- package/dist/os/correctness/audit/run.js +184 -0
- package/dist/os/correctness/audit/run.js.map +1 -0
- package/dist/os/correctness/audit/schema-db.d.ts +32 -0
- package/dist/os/correctness/audit/schema-db.d.ts.map +1 -0
- package/dist/os/correctness/audit/schema-db.js +166 -0
- package/dist/os/correctness/audit/schema-db.js.map +1 -0
- package/dist/os/correctness/audit/snapshot.d.ts +34 -0
- package/dist/os/correctness/audit/snapshot.d.ts.map +1 -0
- package/dist/os/correctness/audit/snapshot.js +190 -0
- package/dist/os/correctness/audit/snapshot.js.map +1 -0
- package/dist/os/correctness/audit/sql-scanner.d.ts +28 -0
- package/dist/os/correctness/audit/sql-scanner.d.ts.map +1 -0
- package/dist/os/correctness/audit/sql-scanner.js +279 -0
- package/dist/os/correctness/audit/sql-scanner.js.map +1 -0
- package/dist/os/correctness/audit/sql-schema-conform.d.ts +17 -0
- package/dist/os/correctness/audit/sql-schema-conform.d.ts.map +1 -0
- package/dist/os/correctness/audit/sql-schema-conform.js +163 -0
- package/dist/os/correctness/audit/sql-schema-conform.js.map +1 -0
- package/dist/os/correctness/audit/state-transitions-coverage.d.ts +19 -0
- package/dist/os/correctness/audit/state-transitions-coverage.d.ts.map +1 -0
- package/dist/os/correctness/audit/state-transitions-coverage.js +263 -0
- package/dist/os/correctness/audit/state-transitions-coverage.js.map +1 -0
- package/dist/os/correctness/audit/tests/git-fixture.d.ts +15 -0
- package/dist/os/correctness/audit/tests/git-fixture.d.ts.map +1 -0
- package/dist/os/correctness/audit/tests/git-fixture.js +85 -0
- package/dist/os/correctness/audit/tests/git-fixture.js.map +1 -0
- package/dist/os/correctness/audit/types.d.ts +58 -0
- package/dist/os/correctness/audit/types.d.ts.map +1 -0
- package/dist/os/correctness/audit/types.js +34 -0
- package/dist/os/correctness/audit/types.js.map +1 -0
- package/dist/os/correctness/correctness.module.d.ts +3 -0
- package/dist/os/correctness/correctness.module.d.ts.map +1 -0
- package/dist/os/correctness/correctness.module.js +173 -0
- package/dist/os/correctness/correctness.module.js.map +1 -0
- package/dist/os/correctness/gate/frozen.d.ts +52 -0
- package/dist/os/correctness/gate/frozen.d.ts.map +1 -0
- package/dist/os/correctness/gate/frozen.js +322 -0
- package/dist/os/correctness/gate/frozen.js.map +1 -0
- package/dist/os/correctness/gate/origin.d.ts +28 -0
- package/dist/os/correctness/gate/origin.d.ts.map +1 -0
- package/dist/os/correctness/gate/origin.js +139 -0
- package/dist/os/correctness/gate/origin.js.map +1 -0
- package/dist/os/correctness/gate/repo.d.ts +25 -0
- package/dist/os/correctness/gate/repo.d.ts.map +1 -0
- package/dist/os/correctness/gate/repo.js +88 -0
- package/dist/os/correctness/gate/repo.js.map +1 -0
- package/dist/os/correctness/gate/run.d.ts +22 -0
- package/dist/os/correctness/gate/run.d.ts.map +1 -0
- package/dist/os/correctness/gate/run.js +430 -0
- package/dist/os/correctness/gate/run.js.map +1 -0
- package/dist/os/correctness/gate/runner.d.ts +18 -0
- package/dist/os/correctness/gate/runner.d.ts.map +1 -0
- package/dist/os/correctness/gate/runner.js +123 -0
- package/dist/os/correctness/gate/runner.js.map +1 -0
- package/dist/os/correctness/gate/tests/gate-fixture.d.ts +36 -0
- package/dist/os/correctness/gate/tests/gate-fixture.d.ts.map +1 -0
- package/dist/os/correctness/gate/tests/gate-fixture.js +153 -0
- package/dist/os/correctness/gate/tests/gate-fixture.js.map +1 -0
- package/dist/os/correctness/gate/types.d.ts +102 -0
- package/dist/os/correctness/gate/types.d.ts.map +1 -0
- package/dist/os/correctness/gate/types.js +64 -0
- package/dist/os/correctness/gate/types.js.map +1 -0
- package/dist/os/correctness/handlers/audit.d.ts +4 -0
- package/dist/os/correctness/handlers/audit.d.ts.map +1 -0
- package/dist/os/correctness/handlers/audit.js +95 -0
- package/dist/os/correctness/handlers/audit.js.map +1 -0
- package/dist/os/correctness/handlers/gate.d.ts +4 -0
- package/dist/os/correctness/handlers/gate.d.ts.map +1 -0
- package/dist/os/correctness/handlers/gate.js +62 -0
- package/dist/os/correctness/handlers/gate.js.map +1 -0
- package/dist/os/correctness/handlers/validate.d.ts +19 -0
- package/dist/os/correctness/handlers/validate.d.ts.map +1 -0
- package/dist/os/correctness/handlers/validate.js +367 -0
- package/dist/os/correctness/handlers/validate.js.map +1 -0
- package/dist/os/correctness/index.d.ts +8 -0
- package/dist/os/correctness/index.d.ts.map +1 -0
- package/dist/os/correctness/index.js +23 -0
- package/dist/os/correctness/index.js.map +1 -0
- package/dist/os/correctness/manifest-schema.d.ts +155 -0
- package/dist/os/correctness/manifest-schema.d.ts.map +1 -0
- package/dist/os/correctness/manifest-schema.js +110 -0
- package/dist/os/correctness/manifest-schema.js.map +1 -0
- package/dist/os/correctness/references.d.ts +22 -0
- package/dist/os/correctness/references.d.ts.map +1 -0
- package/dist/os/correctness/references.js +129 -0
- package/dist/os/correctness/references.js.map +1 -0
- package/dist/os/correctness/tests/fixture-workspace.d.ts +23 -0
- package/dist/os/correctness/tests/fixture-workspace.d.ts.map +1 -0
- package/dist/os/correctness/tests/fixture-workspace.js +104 -0
- package/dist/os/correctness/tests/fixture-workspace.js.map +1 -0
- package/dist/os/correctness/workspace.d.ts +32 -0
- package/dist/os/correctness/workspace.d.ts.map +1 -0
- package/dist/os/correctness/workspace.js +147 -0
- package/dist/os/correctness/workspace.js.map +1 -0
- package/dist/os/flow/correctness-step.d.ts +19 -0
- package/dist/os/flow/correctness-step.d.ts.map +1 -0
- package/dist/os/flow/correctness-step.js +133 -0
- package/dist/os/flow/correctness-step.js.map +1 -0
- package/dist/os/flow/digest.d.ts +18 -0
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +28 -1
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/dirty-classify.d.ts +7 -0
- package/dist/os/flow/dirty-classify.d.ts.map +1 -1
- package/dist/os/flow/dirty-classify.js +11 -0
- package/dist/os/flow/dirty-classify.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +19 -4
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-check.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-check.js +9 -9
- package/dist/os/flow/handlers/flow-check.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +11 -1
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts +11 -0
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +148 -30
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/handlers/flow-open.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-open.js +14 -19
- package/dist/os/flow/handlers/flow-open.js.map +1 -1
- package/dist/os/flow/index.d.ts +1 -0
- package/dist/os/flow/index.d.ts.map +1 -1
- package/dist/os/flow/index.js +5 -3
- package/dist/os/flow/index.js.map +1 -1
- package/dist/os/flow/post-rebase-regen.d.ts +33 -0
- package/dist/os/flow/post-rebase-regen.d.ts.map +1 -0
- package/dist/os/flow/post-rebase-regen.js +120 -0
- package/dist/os/flow/post-rebase-regen.js.map +1 -0
- package/dist/os/flow/preflight.d.ts +24 -0
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +364 -24
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/publish.d.ts.map +1 -1
- package/dist/os/flow/publish.js +23 -4
- package/dist/os/flow/publish.js.map +1 -1
- package/dist/os/flow/registry.d.ts +6 -6
- package/dist/os/flow/tests/helpers.d.ts +9 -1
- package/dist/os/flow/tests/helpers.d.ts.map +1 -1
- package/dist/os/flow/tests/helpers.js +36 -2
- package/dist/os/flow/tests/helpers.js.map +1 -1
- package/dist/os/friction/types.d.ts +2 -2
- package/dist/os/gate-run/detach.d.ts +27 -0
- package/dist/os/gate-run/detach.d.ts.map +1 -0
- package/dist/os/gate-run/detach.js +85 -0
- package/dist/os/gate-run/detach.js.map +1 -0
- package/dist/os/gate-run/gate-run.module.d.ts +3 -0
- package/dist/os/gate-run/gate-run.module.d.ts.map +1 -0
- package/dist/os/gate-run/gate-run.module.js +23 -0
- package/dist/os/gate-run/gate-run.module.js.map +1 -0
- package/dist/os/gate-run/index.d.ts +7 -0
- package/dist/os/gate-run/index.d.ts.map +1 -0
- package/dist/os/gate-run/index.js +5 -0
- package/dist/os/gate-run/index.js.map +1 -0
- package/dist/os/gate-run/record.d.ts +47 -0
- package/dist/os/gate-run/record.d.ts.map +1 -0
- package/dist/os/gate-run/record.js +157 -0
- package/dist/os/gate-run/record.js.map +1 -0
- package/dist/os/gate-run/status.d.ts +53 -0
- package/dist/os/gate-run/status.d.ts.map +1 -0
- package/dist/os/gate-run/status.js +163 -0
- package/dist/os/gate-run/status.js.map +1 -0
- package/dist/os/gate-run/types.d.ts +47 -0
- package/dist/os/gate-run/types.d.ts.map +1 -0
- package/dist/os/gate-run/types.js +24 -0
- package/dist/os/gate-run/types.js.map +1 -0
- package/dist/os/program/schemas.d.ts +3 -3
- package/dist/os/queue/types.d.ts +2 -2
- package/dist/os/rfc/evidence-annotation.d.ts +26 -0
- package/dist/os/rfc/evidence-annotation.d.ts.map +1 -0
- package/dist/os/rfc/evidence-annotation.js +52 -0
- package/dist/os/rfc/evidence-annotation.js.map +1 -0
- package/dist/os/rfc/handlers/fixed-inputs.d.ts.map +1 -1
- package/dist/os/rfc/handlers/fixed-inputs.js +7 -1
- package/dist/os/rfc/handlers/fixed-inputs.js.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts +8 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.js +65 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.js.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +35 -29
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.js +152 -11
- package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
- package/dist/os/rfc/rfc.module.d.ts.map +1 -1
- package/dist/os/rfc/rfc.module.js +20 -7
- package/dist/os/rfc/rfc.module.js.map +1 -1
- package/dist/os/rfc/types.d.ts +12 -3
- package/dist/os/rfc/types.d.ts.map +1 -1
- package/dist/os/rfc/types.js +5 -2
- package/dist/os/rfc/types.js.map +1 -1
- package/dist/os/rfc/verify-workspace.d.ts +12 -0
- package/dist/os/rfc/verify-workspace.d.ts.map +1 -1
- package/dist/os/rfc/verify-workspace.js +155 -0
- package/dist/os/rfc/verify-workspace.js.map +1 -1
- package/dist/os/system/task-schemas.d.ts +1 -1
- package/dist/os/system/tests/helpers.d.ts.map +1 -1
- package/dist/os/system/tests/helpers.js +6 -1
- package/dist/os/system/tests/helpers.js.map +1 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +1 -1
- package/dist/src/cli-flags.d.ts.map +1 -1
- package/dist/src/cli-flags.js +6 -0
- package/dist/src/cli-flags.js.map +1 -1
- package/dist/src/command-modules.d.ts +4 -0
- package/dist/src/command-modules.d.ts.map +1 -0
- package/dist/src/command-modules.js +42 -0
- package/dist/src/command-modules.js.map +1 -0
- package/dist/src/config/forge-config.d.ts +16 -1
- package/dist/src/config/forge-config.d.ts.map +1 -1
- package/dist/src/config/forge-config.js +27 -11
- package/dist/src/config/forge-config.js.map +1 -1
- package/dist/src/correctness/index.d.ts +32 -0
- package/dist/src/correctness/index.d.ts.map +1 -0
- package/dist/src/correctness/index.js +157 -0
- package/dist/src/correctness/index.js.map +1 -0
- package/dist/src/correctness/schema-hash.d.ts +15 -0
- package/dist/src/correctness/schema-hash.d.ts.map +1 -0
- package/dist/src/correctness/schema-hash.js +44 -0
- package/dist/src/correctness/schema-hash.js.map +1 -0
- package/dist/src/knowledge/schema.d.ts +1 -1
- package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
- package/dist/src/onboarding/agents-generate.js +20 -3
- package/dist/src/onboarding/agents-generate.js.map +1 -1
- package/dist/src/onboarding/create.d.ts +7 -0
- package/dist/src/onboarding/create.d.ts.map +1 -1
- package/dist/src/onboarding/create.js +62 -9
- package/dist/src/onboarding/create.js.map +1 -1
- package/dist/src/types.d.ts +7 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +2 -8
- package/dist/src/types.js.map +1 -1
- package/docs/reference/correctness-audit.md +91 -0
- package/docs/reference/correctness-gate.md +102 -0
- package/docs/reference/correctness-manifest.md +142 -0
- package/docs/reference/forge-yaml.md +15 -0
- package/os/codebase/codebase.module.ts +57 -0
- package/os/codebase/handlers/codebase-measure-symbols.ts +131 -0
- package/os/codebase/handlers/codebase-measure.ts +503 -0
- package/os/codebase/index.ts +21 -0
- package/os/codebase/types.ts +55 -0
- package/os/core/handlers/package-health.test.ts +24 -2
- package/os/core/handlers/package-health.ts +16 -19
- package/os/correctness/anchors.ts +182 -0
- package/os/correctness/audit/bindings-verify-substance.test.ts +79 -0
- package/os/correctness/audit/bindings-verify-substance.ts +155 -0
- package/os/correctness/audit/differential.test.ts +113 -0
- package/os/correctness/audit/differential.ts +131 -0
- package/os/correctness/audit/ledger-orphans.test.ts +96 -0
- package/os/correctness/audit/ledger-orphans.ts +84 -0
- package/os/correctness/audit/ledger.test.ts +65 -0
- package/os/correctness/audit/ledger.ts +103 -0
- package/os/correctness/audit/run.ts +220 -0
- package/os/correctness/audit/schema-db.ts +208 -0
- package/os/correctness/audit/snapshot.ts +211 -0
- package/os/correctness/audit/sql-scanner.test.ts +84 -0
- package/os/correctness/audit/sql-scanner.ts +289 -0
- package/os/correctness/audit/sql-schema-conform.test.ts +170 -0
- package/os/correctness/audit/sql-schema-conform.ts +178 -0
- package/os/correctness/audit/state-transitions-coverage.test.ts +141 -0
- package/os/correctness/audit/state-transitions-coverage.ts +271 -0
- package/os/correctness/audit/tests/git-fixture.ts +98 -0
- package/os/correctness/audit/types.ts +91 -0
- package/os/correctness/correctness-capture.test.ts +107 -0
- package/os/correctness/correctness-chain.test.ts +232 -0
- package/os/correctness/correctness-coverage.test.ts +86 -0
- package/os/correctness/correctness-mode.test.ts +108 -0
- package/os/correctness/correctness-substrate.test.ts +64 -0
- package/os/correctness/correctness.module.ts +182 -0
- package/os/correctness/gate/anchor-events.test.ts +77 -0
- package/os/correctness/gate/freeze-coverage.test.ts +218 -0
- package/os/correctness/gate/freeze-diff.test.ts +110 -0
- package/os/correctness/gate/frozen.ts +399 -0
- package/os/correctness/gate/gate-mode.test.ts +76 -0
- package/os/correctness/gate/hardening.test.ts +175 -0
- package/os/correctness/gate/oracle-edit.test.ts +83 -0
- package/os/correctness/gate/oracle-origin.test.ts +142 -0
- package/os/correctness/gate/origin.ts +175 -0
- package/os/correctness/gate/repo.ts +102 -0
- package/os/correctness/gate/run.ts +547 -0
- package/os/correctness/gate/runner.ts +136 -0
- package/os/correctness/gate/substrate-attestation.test.ts +71 -0
- package/os/correctness/gate/tests/gate-fixture.ts +205 -0
- package/os/correctness/gate/tier-high.test.ts +92 -0
- package/os/correctness/gate/types.ts +144 -0
- package/os/correctness/handlers/audit.ts +107 -0
- package/os/correctness/handlers/gate.ts +75 -0
- package/os/correctness/handlers/validate.ts +514 -0
- package/os/correctness/index.ts +24 -0
- package/os/correctness/manifest-schema.ts +174 -0
- package/os/correctness/references.ts +143 -0
- package/os/correctness/tests/fixture-workspace.ts +119 -0
- package/os/correctness/workspace.ts +167 -0
- package/os/flow/correctness-step.ts +166 -0
- package/os/flow/digest.ts +40 -1
- package/os/flow/dirty-classify.ts +13 -0
- package/os/flow/flow.module.ts +20 -4
- package/os/flow/handlers/flow-check.ts +17 -18
- package/os/flow/handlers/flow-digest.ts +11 -1
- package/os/flow/handlers/flow-integrate.ts +191 -39
- package/os/flow/handlers/flow-open.ts +24 -31
- package/os/flow/index.ts +5 -7
- package/os/flow/post-rebase-regen.ts +170 -0
- package/os/flow/preflight.ts +361 -27
- package/os/flow/publish.ts +23 -4
- package/os/flow/tests/flow-detachable.test.ts +31 -0
- package/os/flow/tests/flow-digest-correctness-trail.test.ts +55 -0
- package/os/flow/tests/flow-integrate-correctness-gate.test.ts +275 -0
- package/os/flow/tests/flow-integrate.post-rebase-regen.test.ts +234 -0
- package/os/flow/tests/flow-integrate.preflight.test.ts +26 -5
- package/os/flow/tests/flow-integrate.test.ts +77 -10
- package/os/flow/tests/helpers.ts +45 -24
- package/os/flow/tests/lockfile-induced.test.ts +328 -0
- package/os/gate-run/detach.ts +106 -0
- package/os/gate-run/gate-run.module.ts +25 -0
- package/os/gate-run/index.ts +16 -0
- package/os/gate-run/record.ts +194 -0
- package/os/gate-run/status.ts +201 -0
- package/os/gate-run/tests/gate-run-detach.test.ts +144 -0
- package/os/gate-run/tests/gate-run-record.test.ts +200 -0
- package/os/gate-run/tests/gate-run-status.test.ts +114 -0
- package/os/gate-run/types.ts +73 -0
- package/os/rfc/evidence-annotation.ts +61 -0
- package/os/rfc/handlers/fixed-inputs.test.ts +70 -0
- package/os/rfc/handlers/fixed-inputs.ts +11 -1
- package/os/rfc/handlers/implement-stamp-promotes.test.ts +214 -0
- package/os/rfc/handlers/implement-stamp-promotes.ts +79 -0
- package/os/rfc/handlers/implement-stamp.ts +40 -29
- package/os/rfc/handlers/list-create.test.ts +14 -5
- package/os/rfc/handlers/validate-evidence-shape.test.ts +218 -0
- package/os/rfc/handlers/validate-probe-meta.test.ts +71 -0
- package/os/rfc/handlers/validate-rules.ts +211 -21
- package/os/rfc/handlers/validate-transient-probes.test.ts +222 -0
- package/os/rfc/rfc-0000-template.md +10 -10
- package/os/rfc/rfc.module.ts +21 -7
- package/os/rfc/types.ts +16 -2
- package/os/rfc/verify-workspace-manifest.test.ts +55 -0
- package/os/rfc/verify-workspace.ts +167 -0
- package/os/system/tests/helpers.ts +6 -1
- package/package.json +57 -1
- package/profiles/typescript.yaml +16 -0
- package/skills/_shared/agent-operating-model.md +4 -0
- package/skills/fo/fo-idea-audit/SKILL.md +4 -0
- package/skills/fo/fo-idea-create-rfc/SKILL.md +6 -2
- package/skills/fo/fo-idea-implement/SKILL.md +8 -2
- package/skills/fo/fo-review/SKILL.md +16 -2
- package/skills/fo/fo-session-retro/SKILL.md +4 -2
- package/src/cli-flags.ts +7 -0
- package/src/command-modules.ts +62 -0
- package/src/config/forge-config.ts +37 -11
- package/src/correctness/index.ts +192 -0
- package/src/correctness/schema-hash.ts +59 -0
- package/src/onboarding/agents-generate.ts +20 -3
- package/src/onboarding/create.ts +59 -9
- package/src/tests/agents-generate-detach.test.ts +126 -0
- package/src/tests/codebase-measure-rfc-1581.test.ts +260 -0
- package/src/tests/command-modules.test.ts +34 -0
- package/src/types.ts +9 -8
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579 orchestration of `correctness.audit` — resolve the base
|
|
4
|
+
revision, load the base and judged snapshots (working tree or staged index),
|
|
5
|
+
run the code auditors on both and the configuration auditor on the judged
|
|
6
|
+
tree, attribute findings differentially, apply the allow-list, and derive
|
|
7
|
+
the status (fail only on introduced errors).</purpose>
|
|
8
|
+
<non-goals>
|
|
9
|
+
<item>No writes — the ledger writer lives in the handler behind --write-ledger.</item>
|
|
10
|
+
<item>No manifest validation or oracle freeze — RFC-1578 / RFC-1580.</item>
|
|
11
|
+
</non-goals>
|
|
12
|
+
</MODULE_CONTRACT>
|
|
13
|
+
<CHANGE_SUMMARY>
|
|
14
|
+
<item>RFC-1579: initial orchestration.</item>
|
|
15
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
16
|
+
|
|
17
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
18
|
+
<item>RFC-1579: gate line, ecosystem.commit early run, reference page
|
|
19
|
+
|
|
20
|
+
typescript profile integration-gate.sh runs the primary install's correctness.audit against FLOW_BASE_SHA; werkstatt ecosystem.commit gains EC-34 (correctness.audit --staged, refuses introduced CORR-AUDIT-01..03, warns on CORR-AUDIT-04); in-code CREATE TABLE tables (Durable Object storage) are unverifiable instead of D1 findings; correctness.audit declares generates: []; reference page and agent guides.
|
|
21
|
+
|
|
22
|
+
Measured on werkstatt (rollout step 3): 7 wrangler D1 configs, ~10 s per run, 3 legacy sql.schema.conform findings (packages/warpgogol-billing-cloudflare against schemas outside the repo), 127 unverifiable statements, no state machines; CORR-AUDIT-04 present (verify equals test) — fixed by the werkstatt gate-wiring queue task.</item>
|
|
23
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
24
|
+
|
|
25
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
26
|
+
</CHANGE_SUMMARY>
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { readFileSync } from "node:fs";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
import { parse as parseYaml } from "yaml";
|
|
32
|
+
|
|
33
|
+
import { createOriginGit } from "../../rfc/verification-origin.ts";
|
|
34
|
+
|
|
35
|
+
import { auditVerifySubstance } from "./bindings-verify-substance.ts";
|
|
36
|
+
import { attribute, readAllowList } from "./differential.ts";
|
|
37
|
+
import { auditLedgerOrphans } from "./ledger-orphans.ts";
|
|
38
|
+
import { closeSchemas, discoverSchemas } from "./schema-db.ts";
|
|
39
|
+
import { auditSqlSchemaConform, inCodeTables } from "./sql-schema-conform.ts";
|
|
40
|
+
import { scanLiterals, scanStatements, type SqlStatement } from "./sql-scanner.ts";
|
|
41
|
+
import {
|
|
42
|
+
defaultBase,
|
|
43
|
+
isTestFile,
|
|
44
|
+
loadSnapshot,
|
|
45
|
+
resolveRevision,
|
|
46
|
+
type SnapshotKind,
|
|
47
|
+
type TreeSnapshot,
|
|
48
|
+
} from "./snapshot.ts";
|
|
49
|
+
import { auditStateTransitions, declaredWriters } from "./state-transitions-coverage.ts";
|
|
50
|
+
import { AUDIT_CHECK_IDS, type AuditCheckId, type AuditResult, type RawFinding } from "./types.ts";
|
|
51
|
+
|
|
52
|
+
export interface AuditOptions {
|
|
53
|
+
/** Revision to compare against; default: HEAD with --staged, else merge-base with develop. */
|
|
54
|
+
base?: string;
|
|
55
|
+
/** Judge the staged index instead of the working tree. */
|
|
56
|
+
staged?: boolean;
|
|
57
|
+
/** Run one auditor only. */
|
|
58
|
+
check?: AuditCheckId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type AuditOutcome = { ok: true; result: AuditResult } | { ok: false; usageError: string };
|
|
62
|
+
|
|
63
|
+
interface CodePass {
|
|
64
|
+
findings: RawFinding[];
|
|
65
|
+
unverifiable: number;
|
|
66
|
+
skipped: string[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function statementsOf(snapshot: TreeSnapshot): SqlStatement[] {
|
|
70
|
+
const out: SqlStatement[] = [];
|
|
71
|
+
for (const [file, text] of snapshot.files) {
|
|
72
|
+
if (!/\.(?:ts|mts|tsx)$/.test(file) || isTestFile(file)) continue;
|
|
73
|
+
out.push(...scanStatements(file, text));
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const DDL_RE = /CREATE\s+(?:VIRTUAL\s+)?TABLE/i;
|
|
79
|
+
|
|
80
|
+
/** Literal texts carrying in-code DDL (non-test TypeScript only), with their file. */
|
|
81
|
+
function literalTextsOf(snapshot: TreeSnapshot): { file: string; text: string }[] {
|
|
82
|
+
const out: { file: string; text: string }[] = [];
|
|
83
|
+
for (const [file, text] of snapshot.files) {
|
|
84
|
+
if (!/\.(?:ts|mts|tsx)$/.test(file) || isTestFile(file) || !DDL_RE.test(text)) continue;
|
|
85
|
+
for (const lit of scanLiterals(text))
|
|
86
|
+
if (DDL_RE.test(lit.text)) out.push({ file, text: lit.text });
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Run the code auditors (1–3) over one snapshot. */
|
|
92
|
+
export function runCodeAuditors(snapshot: TreeSnapshot, only?: AuditCheckId): CodePass {
|
|
93
|
+
const wants = (id: AuditCheckId) => !only || only === id;
|
|
94
|
+
const pass: CodePass = { findings: [], unverifiable: 0, skipped: [] };
|
|
95
|
+
if (wants("sql.schema.conform") || wants("ledger.orphans")) {
|
|
96
|
+
const discovery = discoverSchemas(snapshot);
|
|
97
|
+
try {
|
|
98
|
+
for (const u of discovery.unsupported)
|
|
99
|
+
pass.skipped.push(`sql.schema.conform: unsupported-config (${u})`);
|
|
100
|
+
const noD1 = discovery.schemas.length === 0 && discovery.failures.length === 0;
|
|
101
|
+
if (noD1) {
|
|
102
|
+
if (wants("sql.schema.conform")) pass.skipped.push("sql.schema.conform: no-d1");
|
|
103
|
+
if (wants("ledger.orphans")) pass.skipped.push("ledger.orphans: no-d1");
|
|
104
|
+
} else {
|
|
105
|
+
const statements = statementsOf(snapshot);
|
|
106
|
+
if (wants("sql.schema.conform")) {
|
|
107
|
+
const r = auditSqlSchemaConform(
|
|
108
|
+
discovery,
|
|
109
|
+
statements,
|
|
110
|
+
inCodeTables(literalTextsOf(snapshot)),
|
|
111
|
+
);
|
|
112
|
+
pass.findings.push(...r.findings);
|
|
113
|
+
pass.unverifiable += r.unverifiable;
|
|
114
|
+
}
|
|
115
|
+
if (wants("ledger.orphans"))
|
|
116
|
+
pass.findings.push(...auditLedgerOrphans(discovery, statements, snapshot).findings);
|
|
117
|
+
}
|
|
118
|
+
} finally {
|
|
119
|
+
closeSchemas(discovery);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (wants("state.transitions.coverage")) {
|
|
123
|
+
const r = auditStateTransitions(snapshot);
|
|
124
|
+
pass.findings.push(...r.findings);
|
|
125
|
+
pass.skipped.push(...r.skipped);
|
|
126
|
+
}
|
|
127
|
+
return pass;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function forgeDoc(snapshot: TreeSnapshot): unknown {
|
|
131
|
+
try {
|
|
132
|
+
return parseYaml(snapshot.files.get("forge.yaml") ?? "") ?? {};
|
|
133
|
+
} catch {
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function runCorrectnessAudit(
|
|
139
|
+
workspaceRoot: string,
|
|
140
|
+
options: AuditOptions = {},
|
|
141
|
+
): Promise<AuditOutcome> {
|
|
142
|
+
if (options.check && !AUDIT_CHECK_IDS.includes(options.check)) {
|
|
143
|
+
return {
|
|
144
|
+
ok: false,
|
|
145
|
+
usageError: `--check ${options.check} is not an auditor (${AUDIT_CHECK_IDS.join(", ")})`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const baseRef = options.base ?? (options.staged ? "HEAD" : null);
|
|
149
|
+
const base = baseRef
|
|
150
|
+
? await resolveRevision(workspaceRoot, baseRef)
|
|
151
|
+
: await defaultBase(workspaceRoot);
|
|
152
|
+
if (!base) {
|
|
153
|
+
return {
|
|
154
|
+
ok: false,
|
|
155
|
+
usageError: baseRef
|
|
156
|
+
? `--base ${baseRef} does not resolve to a commit`
|
|
157
|
+
: "no merge-base with develop — pass --base <ref>",
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const judgedKind: SnapshotKind = options.staged ? { kind: "index" } : { kind: "worktree" };
|
|
161
|
+
const configOnly = options.check === "bindings.verify.substance";
|
|
162
|
+
const empty = { findings: [] as RawFinding[], unverifiable: 0, skipped: [] as string[] };
|
|
163
|
+
let now: TreeSnapshot | null;
|
|
164
|
+
let then: TreeSnapshot | null;
|
|
165
|
+
try {
|
|
166
|
+
if (configOnly) {
|
|
167
|
+
// The configuration auditor needs only forge.yaml — no base or code reads.
|
|
168
|
+
const forgeYaml = options.staged
|
|
169
|
+
? await createOriginGit(workspaceRoot).run(["show", ":forge.yaml"])
|
|
170
|
+
: (() => {
|
|
171
|
+
try {
|
|
172
|
+
return readFileSync(path.join(workspaceRoot, "forge.yaml"), "utf8");
|
|
173
|
+
} catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
})();
|
|
177
|
+
now = {
|
|
178
|
+
label: judgedKind.kind,
|
|
179
|
+
files: new Map(forgeYaml ? [["forge.yaml", forgeYaml]] : []),
|
|
180
|
+
};
|
|
181
|
+
then = { label: base, files: new Map() };
|
|
182
|
+
} else {
|
|
183
|
+
now = await loadSnapshot(workspaceRoot, judgedKind, declaredWriters);
|
|
184
|
+
then = await loadSnapshot(workspaceRoot, { kind: "rev", sha: base }, declaredWriters);
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
return { ok: false, usageError: `cannot read the trees: ${(err as Error).message}` };
|
|
188
|
+
}
|
|
189
|
+
if (!now || !then)
|
|
190
|
+
return { ok: false, usageError: `cannot read the ${!now ? "judged tree" : `base ${base}`}` };
|
|
191
|
+
|
|
192
|
+
const codeOnly = options.check && !configOnly ? options.check : undefined;
|
|
193
|
+
const nowPass = configOnly ? empty : runCodeAuditors(now, codeOnly);
|
|
194
|
+
const basePass = configOnly ? empty : runCodeAuditors(then, codeOnly);
|
|
195
|
+
|
|
196
|
+
const doc = forgeDoc(now);
|
|
197
|
+
const exempt = (doc as { correctness?: { mode?: unknown } })?.correctness?.mode === "exempt";
|
|
198
|
+
const config =
|
|
199
|
+
!options.check || options.check === "bindings.verify.substance"
|
|
200
|
+
? auditVerifySubstance(now.files.get("forge.yaml"), exempt)
|
|
201
|
+
: { findings: [], unverifiable: 0, skipped: [] };
|
|
202
|
+
|
|
203
|
+
const findings = attribute(
|
|
204
|
+
basePass.findings,
|
|
205
|
+
[...nowPass.findings, ...config.findings],
|
|
206
|
+
readAllowList(doc),
|
|
207
|
+
);
|
|
208
|
+
const blocking = findings.some((f) => f.attribution === "introduced" && f.severity === "error");
|
|
209
|
+
return {
|
|
210
|
+
ok: true,
|
|
211
|
+
result: {
|
|
212
|
+
command: "correctness.audit",
|
|
213
|
+
base,
|
|
214
|
+
status: blocking ? "fail" : "pass",
|
|
215
|
+
findings,
|
|
216
|
+
unverifiable: nowPass.unverifiable,
|
|
217
|
+
skipped: [...nowPass.skipped, ...config.skipped],
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579: D1 schema discovery — every `d1_databases` binding of a
|
|
4
|
+
wrangler.json / wrangler.jsonc in the snapshot yields one schema keyed by
|
|
5
|
+
`database_name`: its `migrations_dir` (default `migrations/`, relative to the
|
|
6
|
+
config's directory) is applied in filename order to its own in-memory
|
|
7
|
+
`node:sqlite` database. Databases are never merged; a migration that fails
|
|
8
|
+
to apply is reported instead of falling back to a partial schema.</purpose>
|
|
9
|
+
<non-goals>
|
|
10
|
+
<item>No wrangler.toml support in v1 — reported as unsupported-config.</item>
|
|
11
|
+
<item>No new runtime dependency — JSONC is stripped by the built-in stripper.</item>
|
|
12
|
+
</non-goals>
|
|
13
|
+
</MODULE_CONTRACT>
|
|
14
|
+
<CHANGE_SUMMARY>
|
|
15
|
+
<item>RFC-1579: initial per-database schema builder.</item>
|
|
16
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
17
|
+
|
|
18
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
19
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
20
|
+
|
|
21
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
22
|
+
</CHANGE_SUMMARY>
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import type { DatabaseSync as DatabaseSyncType } from "node:sqlite";
|
|
27
|
+
import { createRequire } from "node:module";
|
|
28
|
+
|
|
29
|
+
import { stripJsonc } from "./sql-scanner.ts";
|
|
30
|
+
import { isWranglerConfig, type TreeSnapshot } from "./snapshot.ts";
|
|
31
|
+
|
|
32
|
+
const require = createRequire(import.meta.url);
|
|
33
|
+
|
|
34
|
+
/** Load node:sqlite without its one-time ExperimentalWarning reaching stderr. */
|
|
35
|
+
function loadSqlite(): typeof import("node:sqlite") {
|
|
36
|
+
const original = process.emitWarning;
|
|
37
|
+
process.emitWarning = ((warning: string | Error, ...rest: unknown[]) => {
|
|
38
|
+
const text = typeof warning === "string" ? warning : warning.message;
|
|
39
|
+
if (/SQLite/i.test(text)) return;
|
|
40
|
+
return (original as (...a: unknown[]) => void).call(process, warning, ...rest);
|
|
41
|
+
}) as typeof process.emitWarning;
|
|
42
|
+
try {
|
|
43
|
+
return require("node:sqlite") as typeof import("node:sqlite");
|
|
44
|
+
} finally {
|
|
45
|
+
process.emitWarning = original;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface D1Schema {
|
|
50
|
+
/** `database_name` of the binding. */
|
|
51
|
+
name: string;
|
|
52
|
+
/** Workspace-relative POSIX directory of the wrangler config ("" = repo root). */
|
|
53
|
+
packageDir: string;
|
|
54
|
+
configFile: string;
|
|
55
|
+
migrations: string[];
|
|
56
|
+
db: DatabaseSyncType;
|
|
57
|
+
/** Base tables (no sqlite_/_cf_/d1_migrations engine tables, no FTS shadows), lower-cased. */
|
|
58
|
+
tables: Set<string>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface MigrationFailure {
|
|
62
|
+
migration: string;
|
|
63
|
+
message: string;
|
|
64
|
+
/** "config" — the wrangler file itself is unreadable; "migration" — a migration does not apply. */
|
|
65
|
+
kind: "config" | "migration";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface SchemaDiscovery {
|
|
69
|
+
schemas: D1Schema[];
|
|
70
|
+
failures: MigrationFailure[];
|
|
71
|
+
unsupported: string[];
|
|
72
|
+
/** Package dirs whose config or migrations failed — their statements are unverifiable. */
|
|
73
|
+
failedPackages: Set<string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface D1Binding {
|
|
77
|
+
database_name?: unknown;
|
|
78
|
+
migrations_dir?: unknown;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function d1Bindings(config: unknown): D1Binding[] {
|
|
82
|
+
if (!config || typeof config !== "object") return [];
|
|
83
|
+
const out: D1Binding[] = [];
|
|
84
|
+
const top = (config as { d1_databases?: unknown }).d1_databases;
|
|
85
|
+
if (Array.isArray(top)) out.push(...(top as D1Binding[]));
|
|
86
|
+
const envs = (config as { env?: unknown }).env;
|
|
87
|
+
if (envs && typeof envs === "object") {
|
|
88
|
+
for (const env of Object.values(envs as Record<string, unknown>)) {
|
|
89
|
+
const list = (env as { d1_databases?: unknown })?.d1_databases;
|
|
90
|
+
if (Array.isArray(list)) out.push(...(list as D1Binding[]));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const ENGINE_TABLE_RE = /^(?:sqlite_|_cf_)|^d1_migrations$/i;
|
|
97
|
+
|
|
98
|
+
function baseTables(db: DatabaseSyncType): Set<string> {
|
|
99
|
+
const rows = db.prepare("PRAGMA table_list").all() as {
|
|
100
|
+
name: string;
|
|
101
|
+
type: string;
|
|
102
|
+
schema: string;
|
|
103
|
+
}[];
|
|
104
|
+
return new Set(
|
|
105
|
+
rows
|
|
106
|
+
.filter((r) => r.schema === "main" && r.type === "table" && !ENGINE_TABLE_RE.test(r.name))
|
|
107
|
+
.map((r) => r.name.toLowerCase()),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Discover and build every D1 schema of a snapshot. */
|
|
112
|
+
export function discoverSchemas(snapshot: TreeSnapshot): SchemaDiscovery {
|
|
113
|
+
const { DatabaseSync } = loadSqlite();
|
|
114
|
+
const schemas: D1Schema[] = [];
|
|
115
|
+
const failures: MigrationFailure[] = [];
|
|
116
|
+
const unsupported: string[] = [];
|
|
117
|
+
const failedPackages = new Set<string>();
|
|
118
|
+
const configs = [...snapshot.files.keys()].filter(isWranglerConfig).sort();
|
|
119
|
+
for (const configFile of configs) {
|
|
120
|
+
if (configFile.endsWith(".toml")) {
|
|
121
|
+
unsupported.push(configFile);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
let parsed: unknown;
|
|
125
|
+
try {
|
|
126
|
+
parsed = JSON.parse(stripJsonc(snapshot.files.get(configFile)!));
|
|
127
|
+
} catch (err) {
|
|
128
|
+
failures.push({
|
|
129
|
+
migration: configFile,
|
|
130
|
+
kind: "config",
|
|
131
|
+
message: `not valid JSON(C): ${(err as Error).message}`,
|
|
132
|
+
});
|
|
133
|
+
failedPackages.add(
|
|
134
|
+
path.posix.dirname(configFile) === "." ? "" : path.posix.dirname(configFile),
|
|
135
|
+
);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const packageDir = path.posix.dirname(configFile) === "." ? "" : path.posix.dirname(configFile);
|
|
139
|
+
const seen = new Set<string>();
|
|
140
|
+
for (const binding of d1Bindings(parsed)) {
|
|
141
|
+
const name = typeof binding.database_name === "string" ? binding.database_name : null;
|
|
142
|
+
if (!name || seen.has(name)) continue;
|
|
143
|
+
seen.add(name);
|
|
144
|
+
const dirRel =
|
|
145
|
+
typeof binding.migrations_dir === "string" ? binding.migrations_dir : "migrations";
|
|
146
|
+
const migrationsDir = path.posix
|
|
147
|
+
.normalize(path.posix.join(packageDir, dirRel))
|
|
148
|
+
.replace(/^\.\//, "");
|
|
149
|
+
const prefix = migrationsDir === "." ? "" : `${migrationsDir}/`;
|
|
150
|
+
const migrations = [...snapshot.files.keys()]
|
|
151
|
+
.filter(
|
|
152
|
+
(f) =>
|
|
153
|
+
f.endsWith(".sql") && f.startsWith(prefix) && !f.slice(prefix.length).includes("/"),
|
|
154
|
+
)
|
|
155
|
+
.sort((a, b) => path.posix.basename(a).localeCompare(path.posix.basename(b)));
|
|
156
|
+
const db = new DatabaseSync(":memory:");
|
|
157
|
+
let ok = true;
|
|
158
|
+
for (const migration of migrations) {
|
|
159
|
+
try {
|
|
160
|
+
db.exec(snapshot.files.get(migration)!);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
failures.push({ migration, kind: "migration", message: (err as Error).message });
|
|
163
|
+
ok = false;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!ok) {
|
|
168
|
+
db.close();
|
|
169
|
+
failedPackages.add(packageDir);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
schemas.push({ name, packageDir, configFile, migrations, db, tables: baseTables(db) });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// One D1 database bound by several workers: configs without migrations share
|
|
176
|
+
// the schema of the binding that owns them (keyed by database_name).
|
|
177
|
+
for (const schema of schemas) {
|
|
178
|
+
if (schema.migrations.length > 0) continue;
|
|
179
|
+
const owner = schemas.find((o) => o.name === schema.name && o.migrations.length > 0);
|
|
180
|
+
if (!owner) continue;
|
|
181
|
+
schema.db.close();
|
|
182
|
+
schema.db = owner.db;
|
|
183
|
+
schema.tables = owner.tables;
|
|
184
|
+
schema.migrations = owner.migrations;
|
|
185
|
+
}
|
|
186
|
+
return { schemas, failures, unsupported, failedPackages };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Candidate schemas of a statement in `file`: its package's schemas, or every schema outside any. */
|
|
190
|
+
export function candidateSchemas(schemas: D1Schema[], file: string): D1Schema[] {
|
|
191
|
+
const owning = schemas
|
|
192
|
+
.filter((s) => s.packageDir === "" || file.startsWith(`${s.packageDir}/`))
|
|
193
|
+
.sort((a, b) => b.packageDir.length - a.packageDir.length);
|
|
194
|
+
if (owning.length === 0) return schemas;
|
|
195
|
+
const deepest = owning[0]!.packageDir;
|
|
196
|
+
// A root-level config only owns files that no deeper config claims.
|
|
197
|
+
return owning.filter((s) => s.packageDir === deepest);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function closeSchemas(discovery: SchemaDiscovery): void {
|
|
201
|
+
for (const s of discovery.schemas) {
|
|
202
|
+
try {
|
|
203
|
+
s.db.close();
|
|
204
|
+
} catch {
|
|
205
|
+
// already closed
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579: tree snapshots the correctness auditors read — the working
|
|
4
|
+
tree, the staged index, or a base revision. Only audit-relevant files are
|
|
5
|
+
loaded (wrangler configs, migration SQL, non-test TypeScript, forge.yaml);
|
|
6
|
+
index and revision blobs come from one `git cat-file --batch` process
|
|
7
|
+
(RFC-1513 batching path, argv exec per DNA-89).</purpose>
|
|
8
|
+
<non-goals>
|
|
9
|
+
<item>Do not check anything out — base reads never touch the working tree.</item>
|
|
10
|
+
<item>Do not interpret file contents — auditors own semantics.</item>
|
|
11
|
+
</non-goals>
|
|
12
|
+
</MODULE_CONTRACT>
|
|
13
|
+
<CHANGE_SUMMARY>
|
|
14
|
+
<item>RFC-1579: initial snapshot sources.</item>
|
|
15
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
16
|
+
|
|
17
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
18
|
+
<item>RFC-1579: gate line, ecosystem.commit early run, reference page
|
|
19
|
+
|
|
20
|
+
typescript profile integration-gate.sh runs the primary install's correctness.audit against FLOW_BASE_SHA; werkstatt ecosystem.commit gains EC-34 (correctness.audit --staged, refuses introduced CORR-AUDIT-01..03, warns on CORR-AUDIT-04); in-code CREATE TABLE tables (Durable Object storage) are unverifiable instead of D1 findings; correctness.audit declares generates: []; reference page and agent guides.
|
|
21
|
+
|
|
22
|
+
Measured on werkstatt (rollout step 3): 7 wrangler D1 configs, ~10 s per run, 3 legacy sql.schema.conform findings (packages/warpgogol-billing-cloudflare against schemas outside the repo), 127 unverifiable statements, no state machines; CORR-AUDIT-04 present (verify equals test) — fixed by the werkstatt gate-wiring queue task.</item>
|
|
23
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
24
|
+
|
|
25
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
26
|
+
</CHANGE_SUMMARY>
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { readFileSync } from "node:fs";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
|
|
32
|
+
import { execFile } from "node:child_process";
|
|
33
|
+
|
|
34
|
+
import { createOriginGit, gitEnvForCwd } from "../../rfc/verification-origin.ts";
|
|
35
|
+
import { listWorkspaceFiles } from "../workspace.ts";
|
|
36
|
+
|
|
37
|
+
export interface TreeSnapshot {
|
|
38
|
+
/** Human label: "working-tree", "index", or the revision sha. */
|
|
39
|
+
label: string;
|
|
40
|
+
/** Relevant files, POSIX-relative → content. */
|
|
41
|
+
files: Map<string, string>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const TEST_FILE_RE =
|
|
45
|
+
/(?:^|\/)(?:__tests__|tests?|__mocks__|fixtures?|test-fixtures)\/|\.(?:test|spec|pbt\.test)\.[cm]?tsx?$/;
|
|
46
|
+
const SKIP_SEGMENT_RE = /(?:^|\/)(?:node_modules|dist|\.turbo|\.wrangler|coverage|\.astro)\//;
|
|
47
|
+
|
|
48
|
+
export function isTestFile(rel: string): boolean {
|
|
49
|
+
return TEST_FILE_RE.test(rel);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isWranglerConfig(rel: string): boolean {
|
|
53
|
+
return /(?:^|\/)wrangler\.(?:json|jsonc|toml)$/.test(rel);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Whether a path can influence any auditor. */
|
|
57
|
+
export function isAuditRelevant(rel: string): boolean {
|
|
58
|
+
if (SKIP_SEGMENT_RE.test(rel)) return false;
|
|
59
|
+
if (rel === "forge.yaml") return true;
|
|
60
|
+
if (isWranglerConfig(rel)) return true;
|
|
61
|
+
if (rel.endsWith(".sql")) return true;
|
|
62
|
+
if (/\.(?:ts|mts|tsx)$/.test(rel) && !rel.endsWith(".d.ts")) return true;
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Uppercase SQL keywords a statement literal must start with (case-sensitive prefilter). */
|
|
67
|
+
// No `\b`: BSD/macOS ERE lacks it; the prefilter only needs a superset.
|
|
68
|
+
export const SQL_KEYWORD_PREFILTER = "(SELECT|INSERT|UPDATE|DELETE|WITH|REPLACE|CREATE)";
|
|
69
|
+
export const STATE_MACHINE_MARKER = "@state-machine[";
|
|
70
|
+
const SQL_KEYWORD_RE = new RegExp(SQL_KEYWORD_PREFILTER);
|
|
71
|
+
const TS_RE = /\.(?:ts|mts|tsx)$/;
|
|
72
|
+
|
|
73
|
+
export type SnapshotKind = { kind: "worktree" } | { kind: "index" } | { kind: "rev"; sha: string };
|
|
74
|
+
|
|
75
|
+
/** TypeScript files that need scanning: SQL keywords, a machine marker, or a writer name. */
|
|
76
|
+
function tsMatches(text: string, writers: string[]): boolean {
|
|
77
|
+
return (
|
|
78
|
+
SQL_KEYWORD_RE.test(text) ||
|
|
79
|
+
text.includes(STATE_MACHINE_MARKER) ||
|
|
80
|
+
writers.some((w) => text.includes(w))
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Load the audit-relevant files of one tree. Non-TypeScript inputs (forge.yaml,
|
|
86
|
+
* wrangler configs, migration SQL) are always read; TypeScript files only when
|
|
87
|
+
* they can carry a statement, a machine marker, or a call of a declared writer
|
|
88
|
+
* (`writersOf` returns writer names declared by the machines found so far — a
|
|
89
|
+
* second pass picks up files that only call a writer).
|
|
90
|
+
*/
|
|
91
|
+
export async function loadSnapshot(
|
|
92
|
+
workspaceRoot: string,
|
|
93
|
+
which: SnapshotKind,
|
|
94
|
+
writersOf: (files: Map<string, string>) => string[],
|
|
95
|
+
): Promise<TreeSnapshot | null> {
|
|
96
|
+
const files = new Map<string, string>();
|
|
97
|
+
if (which.kind === "worktree") {
|
|
98
|
+
const rels = (await listWorkspaceFiles(workspaceRoot)).filter(isAuditRelevant);
|
|
99
|
+
const ts: [string, string][] = [];
|
|
100
|
+
for (const rel of rels) {
|
|
101
|
+
let text: string;
|
|
102
|
+
try {
|
|
103
|
+
text = readFileSync(path.join(workspaceRoot, rel), "utf8");
|
|
104
|
+
} catch {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (TS_RE.test(rel)) ts.push([rel, text]);
|
|
108
|
+
else files.set(rel, text);
|
|
109
|
+
}
|
|
110
|
+
for (const [rel, text] of ts) if (tsMatches(text, [])) files.set(rel, text);
|
|
111
|
+
const writers = writersOf(files);
|
|
112
|
+
if (writers.length > 0) {
|
|
113
|
+
for (const [rel, text] of ts)
|
|
114
|
+
if (!files.has(rel) && tsMatches(text, writers)) files.set(rel, text);
|
|
115
|
+
}
|
|
116
|
+
return { label: "working-tree", files };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const git = createOriginGit(workspaceRoot);
|
|
120
|
+
const treeArg = which.kind === "rev" ? which.sha : "--cached";
|
|
121
|
+
const listing = await git.run(
|
|
122
|
+
which.kind === "rev"
|
|
123
|
+
? ["ls-tree", "-r", "-z", "--name-only", which.sha]
|
|
124
|
+
: ["ls-files", "-z", "--cached"],
|
|
125
|
+
);
|
|
126
|
+
if (listing === null) return null;
|
|
127
|
+
const all = listing.split("\0").filter((l) => l.length > 0 && isAuditRelevant(l));
|
|
128
|
+
const specOf = (rel: string) => (which.kind === "rev" ? `${which.sha}:${rel}` : `:${rel}`);
|
|
129
|
+
const read = async (rels: string[]) => {
|
|
130
|
+
if (rels.length === 0) return;
|
|
131
|
+
const specs = rels.map(specOf);
|
|
132
|
+
let contents = (await git.showMany?.(specs)) ?? null;
|
|
133
|
+
if (contents === null) {
|
|
134
|
+
contents = [];
|
|
135
|
+
for (const spec of specs) contents.push(await git.run(["show", spec]));
|
|
136
|
+
}
|
|
137
|
+
rels.forEach((rel, i) => {
|
|
138
|
+
const body = contents![i];
|
|
139
|
+
if (typeof body === "string") files.set(rel, body);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
const grep = async (args: string[]): Promise<string[]> => {
|
|
143
|
+
// `git grep` exits 1 on "no match"; any other failure must not read as an
|
|
144
|
+
// empty tree (that would fail open on the judged side).
|
|
145
|
+
const { code, stdout } = await gitGrep(workspaceRoot, [
|
|
146
|
+
"grep",
|
|
147
|
+
"-l",
|
|
148
|
+
"-z",
|
|
149
|
+
...args,
|
|
150
|
+
treeArg,
|
|
151
|
+
"--",
|
|
152
|
+
"*.ts",
|
|
153
|
+
"*.mts",
|
|
154
|
+
"*.tsx",
|
|
155
|
+
]);
|
|
156
|
+
if (code === 1) return [];
|
|
157
|
+
if (code !== 0) throw new Error(`git grep failed with exit ${code}`);
|
|
158
|
+
const prefix = which.kind === "rev" ? `${which.sha}:` : "";
|
|
159
|
+
return stdout
|
|
160
|
+
.split("\0")
|
|
161
|
+
.filter((l) => l.length > 0)
|
|
162
|
+
.map((l) => (prefix && l.startsWith(prefix) ? l.slice(prefix.length) : l))
|
|
163
|
+
.filter(isAuditRelevant);
|
|
164
|
+
};
|
|
165
|
+
await read(all.filter((rel) => !TS_RE.test(rel)));
|
|
166
|
+
const first = await grep(["-E", "-e", SQL_KEYWORD_PREFILTER, "-e", "@state-machine\\["]);
|
|
167
|
+
await read(first);
|
|
168
|
+
const writers = writersOf(files);
|
|
169
|
+
if (writers.length > 0) {
|
|
170
|
+
const more = (await grep(["-F", ...writers.flatMap((w) => ["-e", w])])).filter(
|
|
171
|
+
(rel) => !files.has(rel),
|
|
172
|
+
);
|
|
173
|
+
await read(more);
|
|
174
|
+
}
|
|
175
|
+
return { label: which.kind === "rev" ? which.sha : "index", files };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function gitGrep(cwd: string, args: string[]): Promise<{ code: number | null; stdout: string }> {
|
|
179
|
+
return new Promise((resolve) => {
|
|
180
|
+
execFile(
|
|
181
|
+
"git",
|
|
182
|
+
args,
|
|
183
|
+
{ cwd, timeout: 120_000, maxBuffer: 64 * 1024 * 1024, env: gitEnvForCwd() },
|
|
184
|
+
(err, stdout) => {
|
|
185
|
+
const code = err
|
|
186
|
+
? (((err as { code?: unknown }).code as number | null | undefined) ?? null)
|
|
187
|
+
: 0;
|
|
188
|
+
resolve({ code: typeof code === "number" ? code : null, stdout: String(stdout ?? "") });
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Resolve a revision to a full sha; null when it does not resolve. */
|
|
195
|
+
export async function resolveRevision(workspaceRoot: string, ref: string): Promise<string | null> {
|
|
196
|
+
const out = await createOriginGit(workspaceRoot).run([
|
|
197
|
+
"rev-parse",
|
|
198
|
+
"--verify",
|
|
199
|
+
"--quiet",
|
|
200
|
+
`${ref}^{commit}`,
|
|
201
|
+
]);
|
|
202
|
+
const sha = out?.trim() ?? "";
|
|
203
|
+
return /^[0-9a-f]{40,64}$/.test(sha) ? sha : null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Default base: merge-base of HEAD with develop (DNA-119 fixed branch model). */
|
|
207
|
+
export async function defaultBase(workspaceRoot: string): Promise<string | null> {
|
|
208
|
+
const out = await createOriginGit(workspaceRoot).run(["merge-base", "HEAD", "develop"]);
|
|
209
|
+
const sha = out?.trim() ?? "";
|
|
210
|
+
return /^[0-9a-f]{40,64}$/.test(sha) ? sha : null;
|
|
211
|
+
}
|