@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,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
RFC-1581: forge-codebase module — registers codebase.measure, the
|
|
5
|
+
project-scale measurement command. Autonomous runtime; no new dependencies.
|
|
6
|
+
</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>No fleet aggregation — rollup lives at the registry-owning layer.</item>
|
|
9
|
+
</non-goals>
|
|
10
|
+
</MODULE_CONTRACT>
|
|
11
|
+
<CHANGE_SUMMARY>
|
|
12
|
+
<item>RFC-1581: initial forge-codebase module.</item>
|
|
13
|
+
<item>RFC-1581: add codebase.measure project-scale measurement command</item>
|
|
14
|
+
<item>RFC-1581: apply REVIEW-CODE-2026-11-13-01 — contract alignment, repo-root anchor, publishConfig exports</item>
|
|
15
|
+
</CHANGE_SUMMARY>
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { ForgeModule } from "../../src/forge-module.ts";
|
|
19
|
+
|
|
20
|
+
export async function createForgeCodebaseModule(): Promise<ForgeModule> {
|
|
21
|
+
const { runCodebaseMeasure } = await import("./handlers/codebase-measure.ts");
|
|
22
|
+
return {
|
|
23
|
+
name: "forge-codebase",
|
|
24
|
+
version: "0.1.0",
|
|
25
|
+
runtime: "autonomous",
|
|
26
|
+
declarations: [],
|
|
27
|
+
commands: [
|
|
28
|
+
{
|
|
29
|
+
name: "codebase.measure",
|
|
30
|
+
description:
|
|
31
|
+
"Measure project scale over git-tracked files: categorized line counts " +
|
|
32
|
+
"(code/tests/docs/generated), per-language code/comment/blank lines, " +
|
|
33
|
+
"AST-derived class/function/method counts for the TS/JS family, and " +
|
|
34
|
+
"top-10 directories by code lines. Read-only; --out <path> writes an " +
|
|
35
|
+
"explicit YAML snapshot. --json returns the full structured measure.",
|
|
36
|
+
scope: "workspace",
|
|
37
|
+
mutatesState: false,
|
|
38
|
+
// Read-only `git ls-files` probe on the read-only adapter (RFC-1176).
|
|
39
|
+
execOnReadOnly: true,
|
|
40
|
+
// `--out` upgrades this invocation to the real adapter — the only write.
|
|
41
|
+
mutatingFlags: ["out"],
|
|
42
|
+
coverage: "operator",
|
|
43
|
+
coverageNote:
|
|
44
|
+
"Operator-invoked measurement — never wired into build.check, gates, or commit paths.",
|
|
45
|
+
flags: {
|
|
46
|
+
out: {
|
|
47
|
+
kind: "string",
|
|
48
|
+
description: "Write a dated YAML snapshot of the measurement to this explicit path.",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
writes: [],
|
|
52
|
+
execute: runCodebaseMeasure,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
pipelines: [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
RFC-1581: symbol pass for codebase.measure — counts classes / functions /
|
|
5
|
+
methods in the TS/JS family (and .astro frontmatter) via a lazily imported
|
|
6
|
+
TypeScript parser. When `typescript` is not importable the pass returns an
|
|
7
|
+
empty result with a `typescript-unavailable` skip marker — never a regex
|
|
8
|
+
estimate, never a crash.
|
|
9
|
+
</purpose>
|
|
10
|
+
<non-goals>
|
|
11
|
+
<item>Does not count symbols in non-TS languages — they stay line-only.</item>
|
|
12
|
+
</non-goals>
|
|
13
|
+
</MODULE_CONTRACT>
|
|
14
|
+
<CHANGE_SUMMARY>
|
|
15
|
+
<item>RFC-1581: initial lazy-AST symbol pass.</item>
|
|
16
|
+
<item>RFC-1581: add codebase.measure project-scale measurement command</item>
|
|
17
|
+
</CHANGE_SUMMARY>
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { createRequire } from "node:module";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { pathToFileURL } from "node:url";
|
|
23
|
+
|
|
24
|
+
export interface FileSymbols {
|
|
25
|
+
classes: number;
|
|
26
|
+
functions: number;
|
|
27
|
+
methods: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SymbolPassResult {
|
|
31
|
+
byFile: Map<string, FileSymbols>;
|
|
32
|
+
skipped: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface TsApi {
|
|
36
|
+
createSourceFile(
|
|
37
|
+
fileName: string,
|
|
38
|
+
sourceText: string,
|
|
39
|
+
languageVersion: unknown,
|
|
40
|
+
setParentNodes?: boolean,
|
|
41
|
+
scriptKind?: unknown,
|
|
42
|
+
): unknown;
|
|
43
|
+
ScriptTarget: { Latest: unknown };
|
|
44
|
+
ScriptKind: { TS: unknown; TSX: unknown; JS: unknown; JSX: unknown };
|
|
45
|
+
SyntaxKind: Record<string, number>;
|
|
46
|
+
isClassDeclaration(node: unknown): boolean;
|
|
47
|
+
isClassExpression(node: unknown): boolean;
|
|
48
|
+
isFunctionDeclaration(node: unknown): boolean;
|
|
49
|
+
isFunctionExpression(node: unknown): boolean;
|
|
50
|
+
isArrowFunction(node: unknown): boolean;
|
|
51
|
+
isMethodDeclaration(node: unknown): boolean;
|
|
52
|
+
forEachChild(node: unknown, cb: (n: unknown) => void): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** .astro: extract the frontmatter script (between the first two `---` fences). */
|
|
56
|
+
function astroFrontmatter(content: string): string | null {
|
|
57
|
+
const lines = content.split("\n");
|
|
58
|
+
if (lines[0]?.trim() !== "---") return null;
|
|
59
|
+
for (let i = 1; i < lines.length; i++) {
|
|
60
|
+
if (lines[i]?.trim() === "---") return lines.slice(1, i).join("\n");
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function scriptKindFor(ts: TsApi, path: string): unknown {
|
|
66
|
+
if (path.endsWith(".tsx")) return ts.ScriptKind.TSX;
|
|
67
|
+
if (
|
|
68
|
+
path.endsWith(".jsx") ||
|
|
69
|
+
path.endsWith(".mjs") ||
|
|
70
|
+
path.endsWith(".cjs") ||
|
|
71
|
+
path.endsWith(".js")
|
|
72
|
+
) {
|
|
73
|
+
return ts.ScriptKind.JSX;
|
|
74
|
+
}
|
|
75
|
+
return ts.ScriptKind.TS;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function measureSymbols(
|
|
79
|
+
files: Array<{ path: string; language: string; content: string }>,
|
|
80
|
+
workspaceRoot: string,
|
|
81
|
+
): Promise<SymbolPassResult> {
|
|
82
|
+
const byFile = new Map<string, FileSymbols>();
|
|
83
|
+
const skipped: string[] = [];
|
|
84
|
+
|
|
85
|
+
if (files.length === 0) return { byFile, skipped };
|
|
86
|
+
|
|
87
|
+
let ts: TsApi;
|
|
88
|
+
try {
|
|
89
|
+
// Resolve against the measured workspace, not this package — forge carries
|
|
90
|
+
// no typescript dependency of its own, so a bare import would never find it.
|
|
91
|
+
const requireFromRoot = createRequire(join(workspaceRoot, "package.json"));
|
|
92
|
+
const tsPath = requireFromRoot.resolve("typescript");
|
|
93
|
+
ts = (await import(pathToFileURL(tsPath).href)) as unknown as TsApi;
|
|
94
|
+
} catch {
|
|
95
|
+
skipped.push("typescript-unavailable");
|
|
96
|
+
return { byFile, skipped };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const file of files) {
|
|
100
|
+
const source = file.language === "Astro" ? astroFrontmatter(file.content) : file.content;
|
|
101
|
+
if (source == null || source.trim().length === 0) continue;
|
|
102
|
+
try {
|
|
103
|
+
const sf = ts.createSourceFile(
|
|
104
|
+
file.path,
|
|
105
|
+
source,
|
|
106
|
+
ts.ScriptTarget.Latest,
|
|
107
|
+
true,
|
|
108
|
+
scriptKindFor(ts, file.path),
|
|
109
|
+
);
|
|
110
|
+
const counts: FileSymbols = { classes: 0, functions: 0, methods: 0 };
|
|
111
|
+
const visit = (node: unknown): void => {
|
|
112
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) counts.classes++;
|
|
113
|
+
else if (ts.isMethodDeclaration(node)) counts.methods++;
|
|
114
|
+
else if (
|
|
115
|
+
ts.isFunctionDeclaration(node) ||
|
|
116
|
+
ts.isFunctionExpression(node) ||
|
|
117
|
+
ts.isArrowFunction(node)
|
|
118
|
+
) {
|
|
119
|
+
counts.functions++;
|
|
120
|
+
}
|
|
121
|
+
ts.forEachChild(node, visit);
|
|
122
|
+
};
|
|
123
|
+
visit(sf);
|
|
124
|
+
byFile.set(file.path, counts);
|
|
125
|
+
} catch {
|
|
126
|
+
skipped.push(`parse-failure:${file.path}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { byFile, skipped };
|
|
131
|
+
}
|
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
RFC-1581: codebase.measure handler — measures project scale over the
|
|
5
|
+
git-tracked file set. Anchors on `git rev-parse --show-toplevel`, enumerates
|
|
6
|
+
`git ls-files`, applies the hardcoded exclusion contour, classifies
|
|
7
|
+
categories, counts code/comment/blank lines per language, and returns
|
|
8
|
+
totals + per-language + top-dir measures. Read-only by default;
|
|
9
|
+
`--out <path>` writes an explicit dated snapshot.
|
|
10
|
+
</purpose>
|
|
11
|
+
<non-goals>
|
|
12
|
+
<item>Does not count untracked files — the contour is the tracked tree.</item>
|
|
13
|
+
<item>Does not estimate symbols with regexes — AST pass lives in
|
|
14
|
+
codebase-measure-symbols.ts and degrades honestly.</item>
|
|
15
|
+
</non-goals>
|
|
16
|
+
</MODULE_CONTRACT>
|
|
17
|
+
<CHANGE_SUMMARY>
|
|
18
|
+
<item>RFC-1581: initial codebase.measure handler.</item>
|
|
19
|
+
<item>RFC-1581 review: repo-root anchor via rev-parse, contract-aligned
|
|
20
|
+
measure shape (repo/exclusions/measuredAt, symbols nested, topDirs path),
|
|
21
|
+
name-driven category for binary/unreadable files, single-read I/O.</item>
|
|
22
|
+
</CHANGE_SUMMARY>
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
26
|
+
import { stringify as yamlStringify } from "yaml";
|
|
27
|
+
|
|
28
|
+
import { resolveIo } from "../../../src/utils/io.ts";
|
|
29
|
+
import { hasGeneratedMarker } from "../../../src/utils/generated-marker.ts";
|
|
30
|
+
import type {
|
|
31
|
+
ForgeCommandInput,
|
|
32
|
+
ForgeCommandResult,
|
|
33
|
+
ForgeRuntimeContext,
|
|
34
|
+
} from "../../../src/types.ts";
|
|
35
|
+
import type {
|
|
36
|
+
CodebaseCategory,
|
|
37
|
+
CodebaseMeasure,
|
|
38
|
+
LanguageMeasure,
|
|
39
|
+
TopDirMeasure,
|
|
40
|
+
} from "../types.ts";
|
|
41
|
+
import { measureSymbols } from "./codebase-measure-symbols.ts";
|
|
42
|
+
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Exclusion contour — paths dropped from the measurement entirely.
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
interface ExclusionRule {
|
|
48
|
+
label: string;
|
|
49
|
+
re: RegExp;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const EXCLUSION_RULES: ExclusionRule[] = [
|
|
53
|
+
{ label: "dir:dist/", re: /(^|\/)dist\// },
|
|
54
|
+
{ label: "dir:.turbo/", re: /(^|\/)\.turbo\// },
|
|
55
|
+
{ label: "dir:.cache/", re: /(^|\/)\.cache\// },
|
|
56
|
+
{ label: "dir:.coverage/", re: /(^|\/)\.coverage\// },
|
|
57
|
+
{ label: "dir:.astro/", re: /(^|\/)\.astro\// },
|
|
58
|
+
{ label: "dir:.agents/skills/", re: /^\.agents\/skills\// },
|
|
59
|
+
{ label: "dir:missions/", re: /^missions\// },
|
|
60
|
+
{ label: "dir:docs/specs/", re: /^docs\/specs\// },
|
|
61
|
+
{ label: "dir:docs/metrics/", re: /^docs\/metrics\// },
|
|
62
|
+
{ label: "dir:docs/rfcs/archive/", re: /^docs\/rfcs\/archive\// },
|
|
63
|
+
{ label: "dir:docs/plans/archive/", re: /^docs\/plans\/archive\// },
|
|
64
|
+
{ label: "dir:docs/audits/", re: /^docs\/audits\// },
|
|
65
|
+
{ label: "dir:node_modules/", re: /(^|\/)node_modules\// },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const GENERATED_NAME = /\.generated\./;
|
|
69
|
+
const GENERATED_TOKEN = "@generated";
|
|
70
|
+
|
|
71
|
+
/** Machine bookkeeping mass — counted under `generated`, never under `code`. */
|
|
72
|
+
const LOCKFILE_NAMES = new Set([
|
|
73
|
+
"pnpm-lock.yaml",
|
|
74
|
+
"package-lock.json",
|
|
75
|
+
"npm-shrinkwrap.json",
|
|
76
|
+
"yarn.lock",
|
|
77
|
+
"bun.lockb",
|
|
78
|
+
"bun.lock",
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
const TEST_PATH = /(^|\/)(__tests__|tests|e2e)\//;
|
|
82
|
+
const TEST_NAME = /\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Language + comment syntax
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
interface CommentSpec {
|
|
89
|
+
line: string[];
|
|
90
|
+
block: Array<[string, string]>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const LANGUAGES: Record<string, { language: string; comments: CommentSpec }> = {
|
|
94
|
+
".ts": { language: "TypeScript", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
95
|
+
".tsx": { language: "TSX", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
96
|
+
".mts": { language: "TypeScript", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
97
|
+
".cts": { language: "TypeScript", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
98
|
+
".js": { language: "JavaScript", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
99
|
+
".mjs": { language: "JavaScript", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
100
|
+
".cjs": { language: "JavaScript", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
101
|
+
".jsx": { language: "JSX", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
102
|
+
".astro": {
|
|
103
|
+
language: "Astro",
|
|
104
|
+
comments: {
|
|
105
|
+
line: ["//"],
|
|
106
|
+
block: [
|
|
107
|
+
["<!--", "-->"],
|
|
108
|
+
["/*", "*/"],
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
".md": { language: "Markdown", comments: { line: [], block: [["<!--", "-->"]] } },
|
|
113
|
+
".mdx": {
|
|
114
|
+
language: "MDX",
|
|
115
|
+
comments: {
|
|
116
|
+
line: ["//"],
|
|
117
|
+
block: [
|
|
118
|
+
["<!--", "-->"],
|
|
119
|
+
["/*", "*/"],
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
".yaml": { language: "YAML", comments: { line: ["#"], block: [] } },
|
|
124
|
+
".yml": { language: "YAML", comments: { line: ["#"], block: [] } },
|
|
125
|
+
".json": { language: "JSON", comments: { line: [], block: [] } },
|
|
126
|
+
".jsonc": { language: "JSONC", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
127
|
+
".css": { language: "CSS", comments: { line: [], block: [["/*", "*/"]] } },
|
|
128
|
+
".scss": { language: "SCSS", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
129
|
+
".html": { language: "HTML", comments: { line: [], block: [["<!--", "-->"]] } },
|
|
130
|
+
".xml": { language: "XML", comments: { line: [], block: [["<!--", "-->"]] } },
|
|
131
|
+
".svg": { language: "SVG", comments: { line: [], block: [["<!--", "-->"]] } },
|
|
132
|
+
".py": { language: "Python", comments: { line: ["#"], block: [] } },
|
|
133
|
+
".rs": { language: "Rust", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
134
|
+
".go": { language: "Go", comments: { line: ["//"], block: [["/*", "*/"]] } },
|
|
135
|
+
".sh": { language: "Shell", comments: { line: ["#"], block: [] } },
|
|
136
|
+
".bash": { language: "Shell", comments: { line: ["#"], block: [] } },
|
|
137
|
+
".toml": { language: "TOML", comments: { line: ["#"], block: [] } },
|
|
138
|
+
".sql": { language: "SQL", comments: { line: ["--"], block: [["/*", "*/"]] } },
|
|
139
|
+
".vue": {
|
|
140
|
+
language: "Vue",
|
|
141
|
+
comments: {
|
|
142
|
+
line: ["//"],
|
|
143
|
+
block: [
|
|
144
|
+
["<!--", "-->"],
|
|
145
|
+
["/*", "*/"],
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
".svelte": {
|
|
150
|
+
language: "Svelte",
|
|
151
|
+
comments: {
|
|
152
|
+
line: ["//"],
|
|
153
|
+
block: [
|
|
154
|
+
["<!--", "-->"],
|
|
155
|
+
["/*", "*/"],
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
".txt": { language: "Text", comments: { line: [], block: [] } },
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const TS_FAMILY = new Set(["TypeScript", "TSX", "JavaScript", "JSX"]);
|
|
163
|
+
|
|
164
|
+
const BINARY_EXTS = new Set([
|
|
165
|
+
".png",
|
|
166
|
+
".jpg",
|
|
167
|
+
".jpeg",
|
|
168
|
+
".gif",
|
|
169
|
+
".webp",
|
|
170
|
+
".avif",
|
|
171
|
+
".ico",
|
|
172
|
+
".pdf",
|
|
173
|
+
".zip",
|
|
174
|
+
".gz",
|
|
175
|
+
".tar",
|
|
176
|
+
".woff",
|
|
177
|
+
".woff2",
|
|
178
|
+
".ttf",
|
|
179
|
+
".otf",
|
|
180
|
+
".eot",
|
|
181
|
+
".mp4",
|
|
182
|
+
".webm",
|
|
183
|
+
".mp3",
|
|
184
|
+
".wav",
|
|
185
|
+
".mov",
|
|
186
|
+
".wasm",
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// Pure helpers (exported for tests)
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
|
|
193
|
+
export function exclusionFor(path: string): string | null {
|
|
194
|
+
return EXCLUSION_RULES.find((rule) => rule.re.test(path))?.label ?? null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function languageFor(path: string): { language: string; comments: CommentSpec } {
|
|
198
|
+
const base = basename(path);
|
|
199
|
+
if (base === "Dockerfile" || base.startsWith("Dockerfile.")) {
|
|
200
|
+
return { language: "Dockerfile", comments: { line: ["#"], block: [] } };
|
|
201
|
+
}
|
|
202
|
+
const spec = LANGUAGES[extname(base).toLowerCase()];
|
|
203
|
+
return spec ?? { language: "Other", comments: { line: [], block: [] } };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// First-match-wins order: generated → tests → docs → code.
|
|
207
|
+
export function categoryFor(
|
|
208
|
+
path: string,
|
|
209
|
+
generated: boolean,
|
|
210
|
+
): "code" | "tests" | "docs" | "generated" {
|
|
211
|
+
const base = basename(path);
|
|
212
|
+
const ext = extname(base).toLowerCase();
|
|
213
|
+
if (generated || LOCKFILE_NAMES.has(base)) return "generated";
|
|
214
|
+
if (TEST_NAME.test(base) || TEST_PATH.test(path)) return "tests";
|
|
215
|
+
if (ext === ".md" || ((ext === ".yaml" || ext === ".yml") && path.startsWith("docs/"))) {
|
|
216
|
+
return "docs";
|
|
217
|
+
}
|
|
218
|
+
if (base === "LICENSE" || base.startsWith("LICENSE.")) return "docs";
|
|
219
|
+
return "code";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function isBinaryName(path: string): boolean {
|
|
223
|
+
return BINARY_EXTS.has(extname(path).toLowerCase());
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Count code / comment / blank lines. A line with code + comment counts as code. */
|
|
227
|
+
export function countLines(
|
|
228
|
+
content: string,
|
|
229
|
+
comments: CommentSpec,
|
|
230
|
+
): { code: number; comments: number; blanks: number } {
|
|
231
|
+
let code = 0;
|
|
232
|
+
let commentLines = 0;
|
|
233
|
+
let blanks = 0;
|
|
234
|
+
let inBlock: string | null = null;
|
|
235
|
+
const lines = content.split("\n");
|
|
236
|
+
// A terminal newline produces a phantom empty tail element — not a real line.
|
|
237
|
+
if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
|
|
238
|
+
if (lines.length === 1 && lines[0] === "") return { code: 0, comments: 0, blanks: 0 };
|
|
239
|
+
for (const raw of lines) {
|
|
240
|
+
const line = raw.trim();
|
|
241
|
+
if (inBlock) {
|
|
242
|
+
commentLines++;
|
|
243
|
+
if (line.includes(inBlock)) inBlock = null;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (line.length === 0) {
|
|
247
|
+
blanks++;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const lineHit = comments.line.some((p) => line.startsWith(p));
|
|
251
|
+
if (lineHit) {
|
|
252
|
+
commentLines++;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const blockHit = comments.block.find(([open]) => line.startsWith(open));
|
|
256
|
+
if (blockHit) {
|
|
257
|
+
commentLines++;
|
|
258
|
+
if (!line.slice(blockHit[0].length).includes(blockHit[1])) inBlock = blockHit[1];
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
code++;
|
|
262
|
+
}
|
|
263
|
+
return { code, comments: commentLines, blanks };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function topDirOf(path: string): string {
|
|
267
|
+
const dir = dirname(path);
|
|
268
|
+
if (dir === ".") return ".";
|
|
269
|
+
const segs = dir.split("/");
|
|
270
|
+
return segs.length >= 2 ? `${segs[0]}/${segs[1]}` : segs[0]!;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
// Handler
|
|
275
|
+
// ---------------------------------------------------------------------------
|
|
276
|
+
|
|
277
|
+
export async function runCodebaseMeasure(
|
|
278
|
+
input: ForgeCommandInput,
|
|
279
|
+
context: ForgeRuntimeContext,
|
|
280
|
+
): Promise<ForgeCommandResult<CodebaseMeasure>> {
|
|
281
|
+
const io = resolveIo(context.io);
|
|
282
|
+
const { workspaceRoot } = context;
|
|
283
|
+
// `outPath` stays an ident bound directly to input.flags["out"] — the
|
|
284
|
+
// mutation scan recognises `if (outPath)` as the declared mutatingFlags gate.
|
|
285
|
+
const outPath = input.flags["out"];
|
|
286
|
+
if (outPath !== undefined && (typeof outPath !== "string" || outPath.length === 0)) {
|
|
287
|
+
return {
|
|
288
|
+
exitCode: 1,
|
|
289
|
+
summary: "[codebase.measure] failed — --out expects a file path",
|
|
290
|
+
nextSteps: [
|
|
291
|
+
{
|
|
292
|
+
action: "Pass --out <path> with a non-empty relative or absolute file path.",
|
|
293
|
+
kind: "required",
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (typeof io.exec !== "function") {
|
|
300
|
+
return {
|
|
301
|
+
exitCode: 1,
|
|
302
|
+
summary: "[codebase.measure] failed — exec capability unavailable",
|
|
303
|
+
nextSteps: [
|
|
304
|
+
{
|
|
305
|
+
action:
|
|
306
|
+
"Run codebase.measure through an io adapter that provides exec (ambient CLI or kernel io).",
|
|
307
|
+
kind: "required",
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Repo-root anchor — identical measurement from any subdirectory.
|
|
314
|
+
const rootProbe = await io.exec("git", ["rev-parse", "--show-toplevel"], {
|
|
315
|
+
cwd: workspaceRoot,
|
|
316
|
+
});
|
|
317
|
+
const repoRoot = rootProbe.exitCode === 0 ? rootProbe.stdout.trim() : null;
|
|
318
|
+
if (!repoRoot) {
|
|
319
|
+
return {
|
|
320
|
+
exitCode: 1,
|
|
321
|
+
summary: "[codebase.measure] failed — not inside a git repository",
|
|
322
|
+
nextSteps: [
|
|
323
|
+
{
|
|
324
|
+
action: "Run inside a forge repository checkout (git rev-parse --show-toplevel failed).",
|
|
325
|
+
kind: "required",
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const listed = await io.exec("git", ["ls-files", "-z"], { cwd: repoRoot });
|
|
332
|
+
if (listed.exitCode !== 0) {
|
|
333
|
+
return {
|
|
334
|
+
exitCode: 1,
|
|
335
|
+
summary: `[codebase.measure] failed — git ls-files exited ${listed.exitCode}`,
|
|
336
|
+
nextSteps: [
|
|
337
|
+
{
|
|
338
|
+
action: `Run inside a Git repository with tracked files (${listed.stderr.trim() || "git ls-files failed"}).`,
|
|
339
|
+
kind: "required",
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const appliedExclusions = new Set<string>();
|
|
346
|
+
const tracked = listed.stdout.split("\0").filter((p) => {
|
|
347
|
+
if (p.length === 0) return false;
|
|
348
|
+
const label = exclusionFor(p);
|
|
349
|
+
if (label) appliedExclusions.add(label);
|
|
350
|
+
return label === null;
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const totals: Record<CodebaseCategory, { files: number; code: number }> = {
|
|
354
|
+
code: { files: 0, code: 0 },
|
|
355
|
+
tests: { files: 0, code: 0 },
|
|
356
|
+
docs: { files: 0, code: 0 },
|
|
357
|
+
generated: { files: 0, code: 0 },
|
|
358
|
+
};
|
|
359
|
+
const languages = new Map<string, LanguageMeasure>();
|
|
360
|
+
const dirCode = new Map<string, number>();
|
|
361
|
+
const symbolsSkipped: string[] = [];
|
|
362
|
+
const tsFiles: Array<{ path: string; language: string; content: string }> = [];
|
|
363
|
+
let binaryFiles = 0;
|
|
364
|
+
let totalFiles = 0;
|
|
365
|
+
let totalCode = 0;
|
|
366
|
+
|
|
367
|
+
for (const rel of tracked) {
|
|
368
|
+
const abs = join(repoRoot, rel);
|
|
369
|
+
const base = basename(rel);
|
|
370
|
+
|
|
371
|
+
let content: string;
|
|
372
|
+
try {
|
|
373
|
+
const bytes = await io.readFileBytes(abs);
|
|
374
|
+
// Binary: known extension or NUL byte in the first 8 KB — counts as a
|
|
375
|
+
// file, contributes zero lines (classified by name rules only).
|
|
376
|
+
if (isBinaryName(rel) || bytes.subarray(0, 8192).includes(0)) {
|
|
377
|
+
binaryFiles++;
|
|
378
|
+
totalFiles++;
|
|
379
|
+
totals[categoryFor(rel, GENERATED_NAME.test(base))].files++;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
content = new TextDecoder().decode(bytes);
|
|
383
|
+
} catch {
|
|
384
|
+
totalFiles++;
|
|
385
|
+
totals[categoryFor(rel, GENERATED_NAME.test(base))].files++;
|
|
386
|
+
symbolsSkipped.push(`unreadable:${rel}`);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const head = content.slice(0, 4096);
|
|
391
|
+
const generated =
|
|
392
|
+
GENERATED_NAME.test(base) || hasGeneratedMarker(head) || head.includes(GENERATED_TOKEN);
|
|
393
|
+
const category = categoryFor(rel, generated);
|
|
394
|
+
const { language, comments } = languageFor(rel);
|
|
395
|
+
const counts = countLines(content, comments);
|
|
396
|
+
|
|
397
|
+
totalFiles++;
|
|
398
|
+
totalCode += counts.code;
|
|
399
|
+
totals[category].files++;
|
|
400
|
+
totals[category].code += counts.code;
|
|
401
|
+
|
|
402
|
+
let lm = languages.get(language);
|
|
403
|
+
if (!lm) {
|
|
404
|
+
lm = { language, files: 0, code: 0, comments: 0, blanks: 0 };
|
|
405
|
+
languages.set(language, lm);
|
|
406
|
+
}
|
|
407
|
+
lm.files++;
|
|
408
|
+
lm.code += counts.code;
|
|
409
|
+
lm.comments += counts.comments;
|
|
410
|
+
lm.blanks += counts.blanks;
|
|
411
|
+
|
|
412
|
+
const dir = topDirOf(rel);
|
|
413
|
+
dirCode.set(dir, (dirCode.get(dir) ?? 0) + counts.code);
|
|
414
|
+
|
|
415
|
+
if (TS_FAMILY.has(language) || language === "Astro") {
|
|
416
|
+
tsFiles.push({ path: rel, language, content });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const symbols = await measureSymbols(tsFiles, repoRoot);
|
|
421
|
+
symbolsSkipped.push(...symbols.skipped);
|
|
422
|
+
for (const [path, s] of symbols.byFile) {
|
|
423
|
+
const lm = languages.get(languageFor(path).language);
|
|
424
|
+
if (!lm) continue;
|
|
425
|
+
lm.symbols ??= { classes: 0, functions: 0, methods: 0 };
|
|
426
|
+
lm.symbols.classes += s.classes;
|
|
427
|
+
lm.symbols.functions += s.functions;
|
|
428
|
+
lm.symbols.methods += s.methods;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const languageRows = [...languages.values()].sort(
|
|
432
|
+
(a, b) => b.code - a.code || (a.language < b.language ? -1 : 1),
|
|
433
|
+
);
|
|
434
|
+
const topDirs: TopDirMeasure[] = [...dirCode.entries()]
|
|
435
|
+
.map(([path, code]) => ({ path, code }))
|
|
436
|
+
.sort((a, b) => b.code - a.code || (a.path < b.path ? -1 : 1))
|
|
437
|
+
.slice(0, 10);
|
|
438
|
+
|
|
439
|
+
const measuredAt = new Date().toISOString();
|
|
440
|
+
const data: CodebaseMeasure = {
|
|
441
|
+
command: "codebase.measure",
|
|
442
|
+
status: "ok",
|
|
443
|
+
repo: basename(repoRoot),
|
|
444
|
+
totals,
|
|
445
|
+
languages: languageRows,
|
|
446
|
+
topDirs,
|
|
447
|
+
symbolsSkipped,
|
|
448
|
+
binaryFiles,
|
|
449
|
+
exclusions: [...appliedExclusions].sort(),
|
|
450
|
+
measuredAt,
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
if (outPath) {
|
|
454
|
+
const target = resolve(repoRoot, outPath);
|
|
455
|
+
try {
|
|
456
|
+
await io.writeFile(target, yamlStringify(data));
|
|
457
|
+
} catch (error) {
|
|
458
|
+
return {
|
|
459
|
+
exitCode: 1,
|
|
460
|
+
data,
|
|
461
|
+
summary: `[codebase.measure] measured but failed to write --out ${outPath}`,
|
|
462
|
+
nextSteps: [
|
|
463
|
+
{
|
|
464
|
+
action: `Ensure the --out path is writable (${error instanceof Error ? error.message : String(error)}).`,
|
|
465
|
+
kind: "required",
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (context.outputFormat === "pretty") {
|
|
473
|
+
context.logger.info(`[codebase.measure] ${totalFiles} files, ${totalCode} code lines`);
|
|
474
|
+
for (const cat of ["code", "tests", "docs", "generated"] as const) {
|
|
475
|
+
context.logger.info(
|
|
476
|
+
` ${cat.padEnd(10)} ${totals[cat].files} files, ${totals[cat].code} code`,
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
for (const row of languageRows) {
|
|
480
|
+
const sym = row.symbols
|
|
481
|
+
? ` | ${row.symbols.classes} classes, ${row.symbols.functions + row.symbols.methods} functions`
|
|
482
|
+
: "";
|
|
483
|
+
context.logger.info(
|
|
484
|
+
` ${row.language.padEnd(12)} ${row.files} files, ${row.code} code, ${row.comments} comments, ${row.blanks} blanks${sym}`,
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
if (topDirs.length > 0) {
|
|
488
|
+
context.logger.info(" top dirs:");
|
|
489
|
+
for (const d of topDirs) context.logger.info(` ${d.code} ${d.path}`);
|
|
490
|
+
}
|
|
491
|
+
if (symbolsSkipped.length > 0) {
|
|
492
|
+
context.logger.info(` symbolsSkipped: ${symbolsSkipped.join(", ")}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
data,
|
|
498
|
+
exitCode: 0,
|
|
499
|
+
summary:
|
|
500
|
+
`[codebase.measure] ${totalFiles} files, ${totalCode} code lines ` +
|
|
501
|
+
`(code ${totals.code.code}, tests ${totals.tests.code}, docs ${totals.docs.code}, generated ${totals.generated.code})`,
|
|
502
|
+
};
|
|
503
|
+
}
|