@warpgogol/forge 7.0.0 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/bin/cli.js +6 -12
- package/bin/resolve-entry.js +24 -0
- package/dist/os/compass/comment-safety.d.ts +83 -0
- package/dist/os/compass/comment-safety.d.ts.map +1 -0
- package/dist/os/compass/comment-safety.js +305 -0
- package/dist/os/compass/comment-safety.js.map +1 -0
- package/dist/os/compass/compass.module.d.ts.map +1 -1
- package/dist/os/compass/compass.module.js +47 -4
- package/dist/os/compass/compass.module.js.map +1 -1
- package/dist/os/compass/handlers/compass-change-summary-handler.d.ts +2 -1
- package/dist/os/compass/handlers/compass-change-summary-handler.d.ts.map +1 -1
- package/dist/os/compass/handlers/compass-change-summary-handler.js +34 -10
- package/dist/os/compass/handlers/compass-change-summary-handler.js.map +1 -1
- package/dist/os/compass/handlers/compass-docs-scaffold.d.ts.map +1 -1
- package/dist/os/compass/handlers/compass-docs-scaffold.js +54 -17
- package/dist/os/compass/handlers/compass-docs-scaffold.js.map +1 -1
- package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts +14 -0
- package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts.map +1 -0
- package/dist/os/compass/handlers/compass-header-scaffold-handler.js +261 -0
- package/dist/os/compass/handlers/compass-header-scaffold-handler.js.map +1 -0
- package/dist/os/compass/handlers/compass-header-scaffold.d.ts +31 -0
- package/dist/os/compass/handlers/compass-header-scaffold.d.ts.map +1 -0
- package/dist/os/compass/handlers/compass-header-scaffold.js +739 -0
- package/dist/os/compass/handlers/compass-header-scaffold.js.map +1 -0
- package/dist/os/compass/handlers/compass-inventory-handler.d.ts.map +1 -1
- package/dist/os/compass/handlers/compass-inventory-handler.js +8 -4
- package/dist/os/compass/handlers/compass-inventory-handler.js.map +1 -1
- package/dist/os/compass/handlers/compass-inventory.d.ts +6 -0
- package/dist/os/compass/handlers/compass-inventory.d.ts.map +1 -1
- package/dist/os/compass/handlers/compass-inventory.js +28 -13
- package/dist/os/compass/handlers/compass-inventory.js.map +1 -1
- package/dist/os/compass/handlers/compass-migrate-handler.d.ts.map +1 -1
- package/dist/os/compass/handlers/compass-migrate-handler.js +12 -26
- package/dist/os/compass/handlers/compass-migrate-handler.js.map +1 -1
- package/dist/os/compass/handlers/compass-migrate.d.ts +15 -2
- package/dist/os/compass/handlers/compass-migrate.d.ts.map +1 -1
- package/dist/os/compass/handlers/compass-migrate.js +58 -20
- package/dist/os/compass/handlers/compass-migrate.js.map +1 -1
- package/dist/os/compass/handlers/git-revision.d.ts +10 -0
- package/dist/os/compass/handlers/git-revision.d.ts.map +1 -1
- package/dist/os/compass/handlers/git-revision.js +58 -4
- package/dist/os/compass/handlers/git-revision.js.map +1 -1
- package/dist/os/compass/handlers/summary-record.d.ts +20 -5
- package/dist/os/compass/handlers/summary-record.d.ts.map +1 -1
- package/dist/os/compass/handlers/summary-record.js +175 -44
- package/dist/os/compass/handlers/summary-record.js.map +1 -1
- package/dist/os/compass/index.d.ts +1 -0
- package/dist/os/compass/index.d.ts.map +1 -1
- package/dist/os/compass/index.js +2 -0
- package/dist/os/compass/index.js.map +1 -1
- package/dist/os/compass/policy.d.ts +9 -0
- package/dist/os/compass/policy.d.ts.map +1 -1
- package/dist/os/compass/policy.js +11 -2
- package/dist/os/compass/policy.js.map +1 -1
- package/dist/os/core/core.module.js +1 -1
- package/dist/os/core/handlers/package-health.d.ts.map +1 -1
- package/dist/os/core/handlers/package-health.js +1 -6
- package/dist/os/core/handlers/package-health.js.map +1 -1
- package/dist/os/queue/types.d.ts +2 -0
- package/dist/os/queue/types.d.ts.map +1 -1
- package/dist/os/queue/types.js +3 -1
- package/dist/os/queue/types.js.map +1 -1
- package/dist/os/rfc/acceptance.d.ts.map +1 -1
- package/dist/os/rfc/acceptance.js +51 -1
- package/dist/os/rfc/acceptance.js.map +1 -1
- package/dist/os/rfc/decision-log.d.ts.map +1 -1
- package/dist/os/rfc/decision-log.js +21 -3
- package/dist/os/rfc/decision-log.js.map +1 -1
- package/dist/os/rfc/dna-trace.d.ts +2 -0
- package/dist/os/rfc/dna-trace.d.ts.map +1 -1
- package/dist/os/rfc/dna-trace.js +13 -4
- package/dist/os/rfc/dna-trace.js.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp-origin.d.ts +37 -0
- package/dist/os/rfc/handlers/implement-stamp-origin.d.ts.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp-origin.js +118 -0
- package/dist/os/rfc/handlers/implement-stamp-origin.js.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts +41 -1
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +594 -81
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts +42 -0
- package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts.map +1 -0
- package/dist/os/rfc/handlers/rfc-evidence-sync.js +147 -0
- package/dist/os/rfc/handlers/rfc-evidence-sync.js.map +1 -0
- package/dist/os/rfc/handlers/validate-rules.d.ts +9 -1
- package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.js +60 -8
- package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
- package/dist/os/rfc/reachable-symbol.d.ts +17 -0
- package/dist/os/rfc/reachable-symbol.d.ts.map +1 -0
- package/dist/os/rfc/reachable-symbol.js +376 -0
- package/dist/os/rfc/reachable-symbol.js.map +1 -0
- package/dist/os/rfc/rfc.module.d.ts.map +1 -1
- package/dist/os/rfc/rfc.module.js +89 -5
- package/dist/os/rfc/rfc.module.js.map +1 -1
- package/dist/os/rfc/types.d.ts +81 -12
- package/dist/os/rfc/types.d.ts.map +1 -1
- package/dist/os/rfc/types.js +15 -10
- package/dist/os/rfc/types.js.map +1 -1
- package/dist/os/rfc/verification-evidence.d.ts +10 -1
- package/dist/os/rfc/verification-evidence.d.ts.map +1 -1
- package/dist/os/rfc/verification-evidence.js +175 -10
- package/dist/os/rfc/verification-evidence.js.map +1 -1
- package/dist/os/rfc/verification-origin.d.ts +58 -0
- package/dist/os/rfc/verification-origin.d.ts.map +1 -0
- package/dist/os/rfc/verification-origin.js +346 -0
- package/dist/os/rfc/verification-origin.js.map +1 -0
- package/dist/os/rfc/verification-refresh.d.ts.map +1 -1
- package/dist/os/rfc/verification-refresh.js +11 -1
- package/dist/os/rfc/verification-refresh.js.map +1 -1
- package/dist/os/rfc/verify-workspace.d.ts +23 -0
- package/dist/os/rfc/verify-workspace.d.ts.map +1 -0
- package/dist/os/rfc/verify-workspace.js +278 -0
- package/dist/os/rfc/verify-workspace.js.map +1 -0
- package/dist/os/session/handlers/metrics-rfc.d.ts.map +1 -1
- package/dist/os/session/handlers/metrics-rfc.js +3 -0
- package/dist/os/session/handlers/metrics-rfc.js.map +1 -1
- package/dist/os/spec/spec-status.d.ts.map +1 -1
- package/dist/os/spec/spec-status.js +5 -23
- package/dist/os/spec/spec-status.js.map +1 -1
- package/dist/os/spec/spec-validate.d.ts.map +1 -1
- package/dist/os/spec/spec-validate.js +30 -9
- package/dist/os/spec/spec-validate.js.map +1 -1
- package/dist/os/workflow/handlers.d.ts +0 -4
- package/dist/os/workflow/handlers.d.ts.map +1 -1
- package/dist/os/workflow/handlers.js +9 -36
- package/dist/os/workflow/handlers.js.map +1 -1
- package/dist/os/workflow/index.d.ts +2 -2
- package/dist/os/workflow/index.d.ts.map +1 -1
- package/dist/os/workflow/index.js +1 -1
- package/dist/os/workflow/index.js.map +1 -1
- package/dist/os/workflow/types.d.ts +0 -19
- package/dist/os/workflow/types.d.ts.map +1 -1
- package/dist/os/workflow/types.js +0 -2
- package/dist/os/workflow/types.js.map +1 -1
- package/dist/os/workflow/workflow.module.d.ts.map +1 -1
- package/dist/os/workflow/workflow.module.js +6 -15
- package/dist/os/workflow/workflow.module.js.map +1 -1
- package/dist/src/config/forge-config.d.ts +5 -0
- package/dist/src/config/forge-config.d.ts.map +1 -1
- package/dist/src/config/forge-config.js +5 -2
- package/dist/src/config/forge-config.js.map +1 -1
- package/dist/src/onboarding/agents-generate.js +1 -1
- package/dist/src/onboarding/doctor.js +3 -3
- package/dist/src/onboarding/doctor.js.map +1 -1
- package/dist/src/onboarding/init.js +2 -2
- package/dist/src/onboarding/nested-agents-templates.js +1 -1
- package/dist/src/onboarding/prettierignore.js +1 -1
- package/dist/src/onboarding/upgrade.js +2 -2
- package/dist/src/onboarding/workspace-discovery.js +1 -1
- package/dist/src/profiles/profile-schema.d.ts +2 -0
- package/dist/src/profiles/profile-schema.d.ts.map +1 -1
- package/dist/src/profiles/profile-schema.js +1 -0
- package/dist/src/profiles/profile-schema.js.map +1 -1
- package/dist/src/profiles/stack-profile.d.ts +1 -0
- package/dist/src/profiles/stack-profile.d.ts.map +1 -1
- package/dist/src/types.d.ts +23 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +2 -1
- package/dist/src/types.js.map +1 -1
- package/docs/reference/cli.md +0 -1
- package/docs/reference/programmatic-api.md +1 -1
- package/os/adr/handlers/validate.test.ts +14 -0
- package/os/compass/comment-safety.ts +331 -0
- package/os/compass/compass.module.ts +50 -4
- package/os/compass/handlers/compass-change-summary-handler.ts +41 -11
- package/os/compass/handlers/compass-docs-scaffold.ts +59 -17
- package/os/compass/handlers/compass-game-extensions.test.ts +3 -7
- package/os/compass/handlers/compass-header-scaffold-handler.ts +352 -0
- package/os/compass/handlers/compass-header-scaffold.ts +847 -0
- package/os/compass/handlers/compass-inventory-handler.ts +9 -4
- package/os/compass/handlers/compass-inventory.ts +29 -13
- package/os/compass/handlers/compass-migrate-handler.ts +13 -27
- package/os/compass/handlers/compass-migrate.ts +77 -21
- package/os/compass/handlers/git-revision.ts +59 -4
- package/os/compass/handlers/resolve-scan-root-package.test.ts +14 -0
- package/os/compass/handlers/resolve-scan-root-workpiece.test.ts +14 -0
- package/os/compass/handlers/summary-record.ts +194 -41
- package/os/compass/handlers/tests/compass-audit-plan.test.ts +6 -0
- package/os/compass/handlers/tests/compass-audit-record.test.ts +6 -0
- package/os/compass/handlers/tests/compass-audit-validate.test.ts +6 -0
- package/os/compass/handlers/tests/compass-change-summary-handler.test.ts +131 -0
- package/os/compass/handlers/tests/compass-docs-validate.test.ts +6 -0
- package/os/compass/handlers/tests/compass-header-scaffold.test.ts +896 -0
- package/os/compass/handlers/tests/compass-ledger-scope.test.ts +6 -0
- package/os/compass/handlers/tests/compass-migrate.test.ts +87 -9
- package/os/compass/handlers/tests/compass-policy.test.ts +1 -1
- package/os/compass/handlers/tests/compass-text-safety.test.ts +271 -0
- package/os/compass/handlers/tests/compass-v2-contract.test.ts +52 -3
- package/os/compass/handlers/tests/summary-record.test.ts +324 -3
- package/os/compass/index.ts +15 -0
- package/os/compass/policy.ts +27 -2
- package/os/core/core.module.ts +1 -1
- package/os/core/handlers/invariant-engine.test.ts +3 -1
- package/os/core/handlers/note-frontmatter-validate.test.ts +6 -1
- package/os/core/handlers/note-link-validate.test.ts +6 -1
- package/os/core/handlers/note-orphan-detect.test.ts +6 -1
- package/os/core/handlers/package-health.test.ts +6 -0
- package/os/core/handlers/package-health.ts +1 -6
- package/os/mission/handlers/archive.test.ts +14 -0
- package/os/naming/naming-convention.test.ts +14 -0
- package/os/queue/decision-ledger.test.ts +27 -4
- package/os/queue/queue-validate.test.ts +14 -0
- package/os/queue/types.ts +3 -1
- package/os/rfc/acceptance-reachable.test.ts +146 -0
- package/os/rfc/acceptance.test.ts +25 -0
- package/os/rfc/acceptance.ts +51 -1
- package/os/rfc/decision-log.ts +22 -4
- package/os/rfc/dna-trace.ts +17 -5
- package/os/rfc/frontmatter-io.test.ts +14 -0
- package/os/rfc/handlers/implement-stamp-acceptance-verification.test.ts +81 -0
- package/os/rfc/handlers/implement-stamp-binding.test.ts +79 -0
- package/os/rfc/handlers/implement-stamp-origin.test.ts +132 -0
- package/os/rfc/handlers/implement-stamp-origin.ts +154 -0
- package/os/rfc/handlers/implement-stamp-stale.test.ts +20 -2
- package/os/rfc/handlers/implement-stamp.ts +714 -87
- package/os/rfc/handlers/lifecycle.test.ts +14 -0
- package/os/rfc/handlers/rfc-evidence-sync.ts +221 -0
- package/os/rfc/handlers/validate-rules-rfc0997.test.ts +14 -0
- package/os/rfc/handlers/validate-rules-rfc1006.test.ts +14 -0
- package/os/rfc/handlers/validate-rules-rfc1330.test.ts +120 -0
- package/os/rfc/handlers/validate-rules-rfc1334.test.ts +65 -0
- package/os/rfc/handlers/validate-rules.test.ts +14 -0
- package/os/rfc/handlers/validate-rules.ts +80 -7
- package/os/rfc/handlers/validate.test.ts +4 -3
- package/os/rfc/reachable-symbol.ts +441 -0
- package/os/rfc/rfc-0000-template.md +3 -0
- package/os/rfc/rfc-create-concurrent.test.ts +6 -0
- package/os/rfc/rfc-create-hint.test.ts +6 -0
- package/os/rfc/rfc-read-only-no-side-effects.test.ts +6 -0
- package/os/rfc/rfc.module.ts +95 -5
- package/os/rfc/types.ts +106 -12
- package/os/rfc/verification-emit-check.test.ts +14 -0
- package/os/rfc/verification-emit-freshness.test.ts +415 -0
- package/os/rfc/verification-emit.test.ts +14 -0
- package/os/rfc/verification-evidence.ts +230 -10
- package/os/rfc/verification-normalize.test.ts +14 -0
- package/os/rfc/verification-origin.test.ts +236 -0
- package/os/rfc/verification-origin.ts +417 -0
- package/os/rfc/verification-refresh.test.ts +14 -0
- package/os/rfc/verification-refresh.ts +12 -1
- package/os/rfc/verifier/rfc-1333/imp12-binding.acceptance.test.ts +78 -0
- package/os/rfc/verifier/rfc-1333/imp12-gate.acceptance.test.ts +81 -0
- package/os/rfc/verifier/rfc-1333/skills-and-types.acceptance.test.ts +50 -0
- package/os/rfc/verifier/rfc-1333/verify-workspace.acceptance.test.ts +103 -0
- package/os/rfc/verify-workspace.test.ts +122 -0
- package/os/rfc/verify-workspace.ts +342 -0
- package/os/session/handlers/metrics-rfc.ts +3 -0
- package/os/spec/spec-status.test.ts +130 -0
- package/os/spec/spec-status.ts +5 -18
- package/os/spec/spec-validate.test.ts +76 -1
- package/os/spec/spec-validate.ts +26 -7
- package/os/workflow/handlers.ts +8 -42
- package/os/workflow/index.ts +1 -4
- package/os/workflow/types.ts +0 -22
- package/os/workflow/workflow.module.ts +6 -16
- package/package.json +1 -1
- package/skills/_shared/agent-operating-model.md +1 -1
- package/skills/_shared/fo-pipeline-conventions.md +1 -0
- package/skills/fo/fo-add-tests/SKILL.md +14 -0
- package/skills/fo/fo-fix/SKILL.md +2 -1
- package/skills/fo/fo-handoff/SKILL.md +1 -1
- package/skills/fo/fo-idea-create-rfc/acceptance-criteria-standard.md +8 -0
- package/skills/fo/fo-idea-i-just-want-to-see-the-result/SKILL.md +4 -2
- package/skills/fo/fo-idea-implement/SKILL.md +68 -53
- package/skills/fo/fo-idea-plan/SKILL.md +3 -1
- package/skills/fo/fo-review/SKILL.md +12 -0
- package/skills/fo/fo-session-save/learned-principles.md +13 -0
- package/skills/fo/fo-step-commit/SKILL.md +1 -1
- package/src/bin-entry.test.ts +37 -0
- package/src/compass/contract-registry.test.ts +14 -0
- package/src/compass/types.test.ts +14 -0
- package/src/config/__tests__/resolve-terminology.test.ts +14 -0
- package/src/config/forge-config.test.ts +14 -0
- package/src/config/forge-config.ts +7 -2
- package/src/forge-module.test.ts +14 -0
- package/src/knowledge/__tests__/promote.test.ts +14 -0
- package/src/knowledge/__tests__/serialize.test.ts +14 -0
- package/src/knowledge/__tests__/sync.test.ts +4 -1
- package/src/knowledge/budgets.test.ts +14 -0
- package/src/knowledge/compact.test.ts +14 -0
- package/src/knowledge/parse.test.ts +14 -0
- package/src/knowledge/schema.test.ts +14 -0
- package/src/migration-adapters/__tests__/ignored-files.test.ts +14 -0
- package/src/migration-adapters/__tests__/registry.test.ts +14 -0
- package/src/migration-adapters/__tests__/types.test.ts +14 -0
- package/src/onboarding/__tests__/workspace-discovery.test.ts +14 -0
- package/src/onboarding/agents-generate.ts +1 -1
- package/src/onboarding/compass-docs/semantic-layer-block.test.ts +6 -0
- package/src/onboarding/create.test.ts +14 -0
- package/src/onboarding/doctor-token-check.test.ts +3 -0
- package/src/onboarding/doctor.test.ts +14 -0
- package/src/onboarding/doctor.ts +3 -3
- package/src/onboarding/init.test.ts +14 -0
- package/src/onboarding/init.ts +2 -2
- package/src/onboarding/nested-agents-templates.ts +1 -1
- package/src/onboarding/prettierignore.ts +1 -1
- package/src/onboarding/scaffold.test.ts +14 -0
- package/src/onboarding/site-workshop-profile.test.ts +3 -0
- package/src/onboarding/upgrade.test.ts +14 -0
- package/src/onboarding/upgrade.ts +2 -2
- package/src/onboarding/workspace-discovery.ts +1 -1
- package/src/pipeline-status.test.ts +14 -0
- package/src/plugin/forge-plugin-manifest.test.ts +14 -0
- package/src/profiles/__tests__/profile-schema.test.ts +14 -0
- package/src/profiles/__tests__/stack-profile.test.ts +14 -0
- package/src/profiles/__tests__/terminology-utils.test.ts +14 -0
- package/src/profiles/profile-schema.ts +1 -0
- package/src/tests/acceptance-criteria.test.ts +14 -0
- package/src/tests/acceptance-probe-kinds.test.ts +14 -0
- package/src/tests/adr-implement-stamp.test.ts +14 -0
- package/src/tests/agents-generate-domain.test.ts +3 -0
- package/src/tests/agents-generate.test.ts +3 -0
- package/src/tests/bindings-schema.test.ts +2 -0
- package/src/tests/budgets.test.ts +14 -0
- package/src/tests/compact.test.ts +14 -0
- package/src/tests/compass-docs-flag.test.ts +6 -0
- package/src/tests/compass-docs-scaffold.test.ts +6 -0
- package/src/tests/compass-docs-validate-scope.test.ts +6 -0
- package/src/tests/contract-registry.test.ts +14 -0
- package/src/tests/create.test.ts +3 -0
- package/src/tests/discover-pack-skills.test.ts +14 -0
- package/src/tests/doctor-autonomy.test.ts +3 -0
- package/src/tests/doctor-bindings.test.ts +6 -1
- package/src/tests/doctor-dist-freshness.test.ts +26 -2
- package/src/tests/doctor-domain.test.ts +6 -1
- package/src/tests/doctor-fix.test.ts +3 -0
- package/src/tests/doctor-nested-agents.test.ts +3 -0
- package/src/tests/doctor-profile-id-known.test.ts +3 -0
- package/src/tests/doctor-skills-unmanaged.test.ts +3 -0
- package/src/tests/doctor-version-sync.test.ts +4 -1
- package/src/tests/editable-generated-region.test.ts +6 -3
- package/src/tests/exploration-handlers.test.ts +14 -0
- package/src/tests/file-size-lint.test.ts +6 -1
- package/src/tests/forge-autonomy-validate.test.ts +3 -1
- package/src/tests/forge-config.test.ts +6 -1
- package/src/tests/forge-validate-compass-docs.test.ts +6 -0
- package/src/tests/fs-atomic.test.ts +14 -0
- package/src/tests/fs.test.ts +14 -0
- package/src/tests/generated-marker.test.ts +14 -0
- package/src/tests/hash.test.ts +14 -0
- package/src/tests/implement-stamp.test.ts +476 -10
- package/src/tests/init-bindings.test.ts +6 -1
- package/src/tests/knowledge-parse.test.ts +14 -0
- package/src/tests/knowledge-pbt.test.ts +14 -0
- package/src/tests/markdown-table.test.ts +6 -3
- package/src/tests/memory-compact.test.ts +3 -0
- package/src/tests/memory-scaffold.test.ts +6 -1
- package/src/tests/metrics-rfc-1053.test.ts +14 -0
- package/src/tests/migration-adapters.test.ts +3 -0
- package/src/tests/package-files.test.ts +4 -1
- package/src/tests/package-health-lint-surface.test.ts +3 -0
- package/src/tests/pinned-check.test.ts +14 -0
- package/src/tests/pinned-init.test.ts +14 -0
- package/src/tests/pinned-validate.test.ts +14 -0
- package/src/tests/plugin-manifest.test.ts +14 -0
- package/src/tests/prettierignore-manage.test.ts +3 -0
- package/src/tests/profile-schema.test.ts +6 -1
- package/src/tests/profile-validate.test.ts +6 -1
- package/src/tests/program-lease.test.ts +3 -0
- package/src/tests/program-paths-extended.test.ts +3 -0
- package/src/tests/program-paths.test.ts +3 -0
- package/src/tests/program-property.test.ts +3 -0
- package/src/tests/program-schemas.test.ts +3 -0
- package/src/tests/program-spec-node.test.ts +3 -0
- package/src/tests/promote.test.ts +14 -0
- package/src/tests/public-surface.test.ts +6 -1
- package/src/tests/registry.test.ts +14 -0
- package/src/tests/rfc-evidence-sync.test.ts +347 -0
- package/src/tests/rfc-implement-stamp-governance.test.ts +403 -0
- package/src/tests/scaffold-project.test.ts +3 -0
- package/src/tests/session-handlers.test.ts +14 -0
- package/src/tests/session-pbt.test.ts +14 -0
- package/src/tests/skill-agents-sync.test.ts +3 -4
- package/src/tests/skill-schema.test.ts +14 -0
- package/src/tests/skill-sync-marker.test.ts +3 -0
- package/src/tests/skill-validate-knowledge.test.ts +14 -0
- package/src/tests/skill-validate.test.ts +14 -0
- package/src/tests/stack-profile.test.ts +6 -1
- package/src/tests/string-utils.test.ts +14 -0
- package/src/tests/upgrade.test.ts +6 -1
- package/src/tests/werkstatt-lock.test.ts +14 -0
- package/src/tests/workspace-discovery-domain.test.ts +6 -1
- package/src/tests/workspace-discovery.test.ts +6 -1
- package/src/types.test.ts +14 -0
- package/src/types.ts +30 -1
- package/src/utils/__tests__/fs-idempotent.test.ts +17 -0
- package/src/utils/__tests__/fs-trash.test.ts +17 -0
- package/src/utils/fs-atomic.test.ts +17 -0
- package/src/utils/fs-trash-sync.test.ts +17 -0
- package/src/utils/fs.test.ts +17 -0
- package/src/utils/generated-marker.test.ts +17 -0
- package/src/utils/hash.test.ts +17 -0
- package/src/utils/string-utils.test.ts +17 -0
- package/src/validators/__tests__/note-orphan-detect.test.ts +14 -0
|
@@ -0,0 +1,847 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
compass.header.scaffold — pure codemod core (RFC-1318). Authors and repairs
|
|
5
|
+
Compass v2 headers under machine-enforced invariants: append-only merge of
|
|
6
|
+
existing content, closed-block guarantee on every emission, derived-or-sentinel
|
|
7
|
+
purposes, fixture-string safety, header-scoped comment anchors, high-risk
|
|
8
|
+
deference, deterministic repair of known malformation shapes.
|
|
9
|
+
</purpose>
|
|
10
|
+
<non-goals>
|
|
11
|
+
<item>Do not walk the filesystem or write — the handler owns discovery, dirty-target checks, and writes.</item>
|
|
12
|
+
<item>Do not rewrite surviving authored content — the merge only inserts missing blocks/items; weak prose stays for agents.</item>
|
|
13
|
+
<item>Do not strip forbidden v1 blocks or reorder blocks — compass.migrate owns the transformer role.</item>
|
|
14
|
+
</non-goals>
|
|
15
|
+
</MODULE_CONTRACT>
|
|
16
|
+
<CHANGE_SUMMARY>
|
|
17
|
+
<item>RFC-1318: add compass.header.scaffold codemod for mechanical header sweeps</item>
|
|
18
|
+
<item>RFC-1318</item>
|
|
19
|
+
<item>RFC-1323: write-time comment-terminator safety — shared comment-safety seam, authored CS-08 reject, injected neutralization, header-region scan</item>
|
|
20
|
+
<item>RFC-1323: review pass — still-open enclosing-style detection, per-file pre-pass parity, scaffold never-throws, docs.scaffold raw-leaf assert, trim per-file skip, CS-08 always-error severity</item>
|
|
21
|
+
</CHANGE_SUMMARY>
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { CompassPolicy, CompassRiskClass } from "../policy.ts";
|
|
25
|
+
import {
|
|
26
|
+
COMPASS_TAGS,
|
|
27
|
+
TODO_ITEM,
|
|
28
|
+
blockSpan,
|
|
29
|
+
collectAiInvariants,
|
|
30
|
+
hasUnclosedTag,
|
|
31
|
+
inHeaderRegion,
|
|
32
|
+
} from "./compass-migrate.ts";
|
|
33
|
+
import {
|
|
34
|
+
EXPORTED_SYMBOL_RE,
|
|
35
|
+
deriveFileTokens,
|
|
36
|
+
getRelativeSegments,
|
|
37
|
+
getWorkspaceRelativeSegments,
|
|
38
|
+
} from "./compass-inventory.ts";
|
|
39
|
+
import {
|
|
40
|
+
type CommentStyle,
|
|
41
|
+
commentStyleCandidates,
|
|
42
|
+
commentStyleFor,
|
|
43
|
+
getLineCommentPrefix,
|
|
44
|
+
assertCompassCommentSafe,
|
|
45
|
+
CompassCommentSafetyError,
|
|
46
|
+
} from "../comment-safety.ts";
|
|
47
|
+
|
|
48
|
+
export type ScaffoldDisposition = "inserted" | "repaired" | "sentinel" | "unchanged" | "skipped";
|
|
49
|
+
|
|
50
|
+
export interface ScaffoldDiagnostic {
|
|
51
|
+
ruleId: "SCAFFOLD-01" | "SCAFFOLD-02" | "COMPASS-CS-08";
|
|
52
|
+
message: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ScaffoldFileResult {
|
|
56
|
+
disposition: ScaffoldDisposition;
|
|
57
|
+
source: string;
|
|
58
|
+
repairs: string[];
|
|
59
|
+
diagnostic?: ScaffoldDiagnostic;
|
|
60
|
+
skipReason?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ScaffoldFileInput {
|
|
64
|
+
pathFromRoot: string;
|
|
65
|
+
workspaceRelativePath: string;
|
|
66
|
+
source: string;
|
|
67
|
+
riskClass: CompassRiskClass;
|
|
68
|
+
keyDecisionsRequired: boolean;
|
|
69
|
+
isTest: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const SENTINEL_PURPOSE =
|
|
73
|
+
"TODO(compass): describe this file's role — automatic derivation found no usable signal.";
|
|
74
|
+
const SENTINEL_NONGOAL = "TODO(compass): record the boundary this file must not take on.";
|
|
75
|
+
const TAG_LINE_CAP = 10;
|
|
76
|
+
|
|
77
|
+
// CommentStyle / commentStyleCandidates / commentStyleFor live in
|
|
78
|
+
// ../comment-safety.ts (RFC-1323) — imported above; no private copy remains.
|
|
79
|
+
|
|
80
|
+
interface HeaderSpan {
|
|
81
|
+
start: number;
|
|
82
|
+
/** Offset just past the comment terminator. */
|
|
83
|
+
end: number;
|
|
84
|
+
/** Offset of the comment terminator itself (where insertions anchor). */
|
|
85
|
+
closeStart: number;
|
|
86
|
+
style: CommentStyle;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function firstTagIndex(source: string): number {
|
|
90
|
+
let best = -1;
|
|
91
|
+
for (const tag of COMPASS_TAGS) {
|
|
92
|
+
const i = source.indexOf(`<${tag}>`);
|
|
93
|
+
if (i >= 0 && (best < 0 || i < best)) best = i;
|
|
94
|
+
}
|
|
95
|
+
return best;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Locate the comment that carries the Compass header — the comment whose open
|
|
100
|
+
* precedes the first compass tag in the header region without a close between
|
|
101
|
+
* them. Repair anchors at the header comment's own terminator, never a close
|
|
102
|
+
* marker below it (fixture blocks or later comments must not absorb the boundary).
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* A comment opener counts as a header carrier only when nothing but
|
|
106
|
+
* whitespace precedes it on its line — an opener inside a string literal or
|
|
107
|
+
* mid-expression is fixture material, not a comment (SCAFFOLD-01).
|
|
108
|
+
*/
|
|
109
|
+
function atLineStart(source: string, index: number): boolean {
|
|
110
|
+
const lineStart = source.lastIndexOf("\n", index - 1) + 1;
|
|
111
|
+
return source.slice(lineStart, index).trim() === "";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Line-start openers still sit inside fixtures when they live inside a
|
|
116
|
+
* multi-line template literal (odd unescaped-backtick count) or a fenced
|
|
117
|
+
* code block (odd ```-fence count) — neither is a real comment.
|
|
118
|
+
*/
|
|
119
|
+
function insideLiteral(source: string, open: number, style: CommentStyle): boolean {
|
|
120
|
+
const before = source.slice(0, open);
|
|
121
|
+
if (style === "block") {
|
|
122
|
+
return (before.match(/(?<!\\)`/g) ?? []).length % 2 === 1;
|
|
123
|
+
}
|
|
124
|
+
if (style === "html") {
|
|
125
|
+
const fences = before
|
|
126
|
+
.split("\n")
|
|
127
|
+
.filter((l) => l.trimStart().startsWith("```") || l.trimStart().startsWith("~~~")).length;
|
|
128
|
+
return fences % 2 === 1;
|
|
129
|
+
}
|
|
130
|
+
if (style === "line") {
|
|
131
|
+
// GDScript/tres docstrings: an odd triple-quote count puts the run inside
|
|
132
|
+
// a string literal, not a comment block.
|
|
133
|
+
return (before.match(/"""/g) ?? []).length % 2 === 1;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function findHeaderSpanInStyle(
|
|
139
|
+
source: string,
|
|
140
|
+
tagIdx: number,
|
|
141
|
+
style: CommentStyle,
|
|
142
|
+
path: string,
|
|
143
|
+
): HeaderSpan | null {
|
|
144
|
+
if (style === "block") {
|
|
145
|
+
const open = source.lastIndexOf("/*", tagIdx);
|
|
146
|
+
if (open < 0 || !atLineStart(source, open) || insideLiteral(source, open, style)) return null;
|
|
147
|
+
if (source.slice(open, tagIdx).includes("*/")) return null;
|
|
148
|
+
const close = source.indexOf("*/", tagIdx);
|
|
149
|
+
if (close < 0) return null;
|
|
150
|
+
return { start: open, end: close + 2, closeStart: close, style };
|
|
151
|
+
}
|
|
152
|
+
if (style === "html") {
|
|
153
|
+
const open = source.lastIndexOf("<!--", tagIdx);
|
|
154
|
+
if (open < 0 || !atLineStart(source, open) || insideLiteral(source, open, style)) return null;
|
|
155
|
+
if (source.slice(open, tagIdx).includes("-->")) return null;
|
|
156
|
+
const close = source.indexOf("-->", tagIdx);
|
|
157
|
+
if (close < 0) return null;
|
|
158
|
+
return { start: open, end: close + 3, closeStart: close, style };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// line style — a contiguous run of prefixed lines around the tag's line.
|
|
162
|
+
const prefix = (getLineCommentPrefix(path) ?? "# ").trimEnd();
|
|
163
|
+
const lines = source.split("\n");
|
|
164
|
+
const offsets: number[] = [];
|
|
165
|
+
let off = 0;
|
|
166
|
+
for (const line of lines) {
|
|
167
|
+
offsets.push(off);
|
|
168
|
+
off += line.length + 1;
|
|
169
|
+
}
|
|
170
|
+
let tagLine = -1;
|
|
171
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
172
|
+
if (offsets[i]! <= tagIdx && tagIdx < offsets[i]! + lines[i]!.length + 1) {
|
|
173
|
+
tagLine = i;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (tagLine < 0 || !lines[tagLine]!.trimStart().startsWith(prefix)) return null;
|
|
178
|
+
let first = tagLine;
|
|
179
|
+
while (first > 0 && lines[first - 1]!.trimStart().startsWith(prefix)) first -= 1;
|
|
180
|
+
if (insideLiteral(source, offsets[first]!, style)) return null;
|
|
181
|
+
let last = tagLine;
|
|
182
|
+
while (last + 1 < lines.length && lines[last + 1]!.trimStart().startsWith(prefix)) last += 1;
|
|
183
|
+
const end = offsets[last]! + lines[last]!.length;
|
|
184
|
+
return { start: offsets[first]!, end, closeStart: end, style };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function findHeaderSpan(source: string, path: string): HeaderSpan | null {
|
|
188
|
+
const tagIdx = firstTagIndex(source);
|
|
189
|
+
if (tagIdx < 0 || !inHeaderRegion(source, tagIdx)) return null;
|
|
190
|
+
for (const style of commentStyleCandidates(path)) {
|
|
191
|
+
const span = findHeaderSpanInStyle(source, tagIdx, style, path);
|
|
192
|
+
if (span) return span;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Lines carrying literal compass tags — the SCAFFOLD-01 evidence list. */
|
|
198
|
+
function tagLines(source: string): string[] {
|
|
199
|
+
const out: string[] = [];
|
|
200
|
+
for (const [index, line] of source.split("\n").entries()) {
|
|
201
|
+
if (/<\/?(?:MODULE_CONTRACT|KEY_DECISIONS|CHANGE_SUMMARY|non-goals|purpose)\b/.test(line)) {
|
|
202
|
+
out.push(`L${index + 1}: ${line.trim().slice(0, 120)}`);
|
|
203
|
+
if (out.length >= TAG_LINE_CAP) break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function firstDescribeTitle(source: string): string | undefined {
|
|
210
|
+
return /\bdescribe(?:\.(?:skip|only|todo|each|concurrent|runIf|skipIf))?\s*\(\s*["'`]([^"'`]+)["'`]/.exec(
|
|
211
|
+
source,
|
|
212
|
+
)?.[1];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function exportedSymbols(source: string): string[] {
|
|
216
|
+
const names: string[] = [];
|
|
217
|
+
for (const m of source.matchAll(EXPORTED_SYMBOL_RE)) names.push(m[1]!);
|
|
218
|
+
return names;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function stemPhrase(path: string): string {
|
|
222
|
+
const filename = path.split("/").filter(Boolean).pop() ?? "";
|
|
223
|
+
const dot = filename.lastIndexOf(".");
|
|
224
|
+
const raw = dot > 0 ? filename.slice(0, dot) : filename;
|
|
225
|
+
return raw
|
|
226
|
+
.replace(/\.(test|spec)$/i, "")
|
|
227
|
+
.replace(/[[\]]/g, " ")
|
|
228
|
+
.replace(/[-_.]+/g, " ")
|
|
229
|
+
.trim();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The PURPOSE-02 bar: ≥10 words and ≥1 file-derived token in the text. */
|
|
233
|
+
function purposeMeetsBar(text: string, tokens: Set<string>): boolean {
|
|
234
|
+
const words = text
|
|
235
|
+
.toLowerCase()
|
|
236
|
+
.split(/[^a-z0-9]+/)
|
|
237
|
+
.filter(Boolean);
|
|
238
|
+
if (words.length < 10) return false;
|
|
239
|
+
const wordSet = new Set(words);
|
|
240
|
+
return [...tokens].some((t) => wordSet.has(t));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function derivePurpose(input: ScaffoldFileInput): { text: string; sentinel: boolean } {
|
|
244
|
+
const { pathFromRoot, source, isTest } = input;
|
|
245
|
+
const tokens = deriveFileTokens(pathFromRoot, source);
|
|
246
|
+
const stem = stemPhrase(pathFromRoot);
|
|
247
|
+
|
|
248
|
+
if (isTest) {
|
|
249
|
+
const title = firstDescribeTitle(source);
|
|
250
|
+
if (title) {
|
|
251
|
+
const clean = title.replace(/[<>]/g, "");
|
|
252
|
+
const text = `Unit tests for ${clean} — covers the ${stem} suite surface and its observable contract.`;
|
|
253
|
+
if (purposeMeetsBar(text, tokens)) return { text, sentinel: false };
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
const symbols = exportedSymbols(source)
|
|
257
|
+
.slice(0, 3)
|
|
258
|
+
.map((s) => s.replace(/[<>]/g, ""));
|
|
259
|
+
if (symbols.length > 0) {
|
|
260
|
+
const text = `Provides ${symbols.join(", ")} for the ${stem} module surface consumed by callers of this layer.`;
|
|
261
|
+
if (purposeMeetsBar(text, tokens)) return { text, sentinel: false };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return { text: SENTINEL_PURPOSE, sentinel: true };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function contractBlock(purposeText: string, nonGoalItems: string[]): string {
|
|
268
|
+
const goals = nonGoalItems.map((item) => ` <item>${item}</item>`).join("\n");
|
|
269
|
+
return [
|
|
270
|
+
"<MODULE_CONTRACT>",
|
|
271
|
+
`<purpose>${purposeText}</purpose>`,
|
|
272
|
+
"<non-goals>",
|
|
273
|
+
goals,
|
|
274
|
+
"</non-goals>",
|
|
275
|
+
"</MODULE_CONTRACT>",
|
|
276
|
+
].join("\n");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function keyDecisionsBlock(items: string[]): string {
|
|
280
|
+
return ["<KEY_DECISIONS>", ...items.map((i) => ` <item>${i}</item>`), "</KEY_DECISIONS>"].join(
|
|
281
|
+
"\n",
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function wrapHeader(blocks: string[], style: CommentStyle, path: string): string {
|
|
286
|
+
const body = blocks.join("\n");
|
|
287
|
+
// RFC-1323: authored/derived text must not carry the style's comment
|
|
288
|
+
// terminator — a terminator-bearing derived purpose is a scaffold bug and
|
|
289
|
+
// fails closed (COMPASS-CS-08) rather than writing a corrupted header.
|
|
290
|
+
assertCompassCommentSafe(body, style, { file: path, block: "header" });
|
|
291
|
+
if (style === "html") return `<!--\n${body}\n-->`;
|
|
292
|
+
if (style === "line") {
|
|
293
|
+
const prefix = getLineCommentPrefix(path) ?? "# ";
|
|
294
|
+
return body
|
|
295
|
+
.split("\n")
|
|
296
|
+
.map((l) => prefix + l)
|
|
297
|
+
.join("\n");
|
|
298
|
+
}
|
|
299
|
+
return `/*\n${body}\n*/`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Comment style for a NEW header. .astro gets `/* *\u002f` inside a `---`
|
|
304
|
+
* frontmatter fence but `<!-- -->` when the file has none — literal block
|
|
305
|
+
* markers in the template region would render as text.
|
|
306
|
+
*/
|
|
307
|
+
function insertStyleFor(path: string, source: string): CommentStyle {
|
|
308
|
+
const start = source.charCodeAt(0) === 0xfeff ? 1 : 0;
|
|
309
|
+
if (path.endsWith(".astro") && !source.startsWith("---", start)) return "html";
|
|
310
|
+
return commentStyleFor(path);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Offset where a new header lands — after BOM, shebang, astro frontmatter,
|
|
315
|
+
* markdown YAML frontmatter, and directive prologue. For .astro the offset is
|
|
316
|
+
* INSIDE the frontmatter fence (block comment); for .md it is after the fence
|
|
317
|
+
* (frontmatter stays first, then the `<!-- -->` header).
|
|
318
|
+
*/
|
|
319
|
+
function insertionOffset(source: string, path: string): number {
|
|
320
|
+
let i = 0;
|
|
321
|
+
if (source.charCodeAt(0) === 0xfeff) i = 1;
|
|
322
|
+
if (source.startsWith("#!", i)) {
|
|
323
|
+
const nl = source.indexOf("\n", i);
|
|
324
|
+
i = nl < 0 ? source.length : nl + 1;
|
|
325
|
+
}
|
|
326
|
+
if (path.endsWith(".astro") && source.startsWith("---", i)) {
|
|
327
|
+
const openEnd = source.indexOf("\n", i);
|
|
328
|
+
if (openEnd >= 0) return openEnd + 1;
|
|
329
|
+
}
|
|
330
|
+
if (path.endsWith(".md") && source.startsWith("---", i)) {
|
|
331
|
+
// The closing fence must be a --- only line — `----` rules or body
|
|
332
|
+
// horizontal rules are not frontmatter terminators.
|
|
333
|
+
const close = source.slice(i + 3).search(/\r?\n---[^\S\r\n]*(?:\r?\n|$)/);
|
|
334
|
+
if (close >= 0) {
|
|
335
|
+
const nlLen = source[i + 3 + close] === "\r" ? 2 : 1;
|
|
336
|
+
const fenceStart = i + 3 + close + nlLen;
|
|
337
|
+
const afterClose = source.indexOf("\n", fenceStart);
|
|
338
|
+
i = afterClose < 0 ? source.length : afterClose + 1;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (;;) {
|
|
342
|
+
const m = /^[^\S\r\n]*["']use [\w-]+["'][^\S\r\n]*;?[^\S\r\n]*(?:\r?\n|$)/.exec(
|
|
343
|
+
source.slice(i),
|
|
344
|
+
);
|
|
345
|
+
if (!m) break;
|
|
346
|
+
i += m[0].length;
|
|
347
|
+
}
|
|
348
|
+
while (source[i] === "\n" || source[i] === "\r") i += 1;
|
|
349
|
+
return i;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Offset of the start of the line containing `index`. */
|
|
353
|
+
function lineStartOf(source: string, index: number): number {
|
|
354
|
+
return source.lastIndexOf("\n", index - 1) + 1;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
interface Edit {
|
|
358
|
+
start: number;
|
|
359
|
+
end: number;
|
|
360
|
+
text: string;
|
|
361
|
+
/**
|
|
362
|
+
* Emission rank for same-position inserts — higher applies first so the
|
|
363
|
+
* final text order follows ascending rank (inner closes before new blocks
|
|
364
|
+
* before outer closes at a shared anchor).
|
|
365
|
+
*/
|
|
366
|
+
order?: number;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function applyEdits(
|
|
370
|
+
source: string,
|
|
371
|
+
edits: Edit[],
|
|
372
|
+
guard?: { style: CommentStyle; file: string },
|
|
373
|
+
): string {
|
|
374
|
+
const sorted = [...edits].sort((a, b) => b.start - a.start || (b.order ?? 0) - (a.order ?? 0));
|
|
375
|
+
// RFC-1323: every inserted payload is asserted against the header's own
|
|
376
|
+
// style — seeded/re-emitted item text (e.g. @ai-invariant lines captured
|
|
377
|
+
// from // comments) can carry a terminator that means nothing there but
|
|
378
|
+
// truncates the block/html header it lands in.
|
|
379
|
+
if (guard) {
|
|
380
|
+
for (const e of sorted) {
|
|
381
|
+
assertCompassCommentSafe(e.text, guard.style, { file: guard.file, block: "header" });
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
let out = source;
|
|
385
|
+
for (const e of sorted) out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
386
|
+
return out;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function skipped(
|
|
390
|
+
reason: string,
|
|
391
|
+
source: string,
|
|
392
|
+
diagnostic?: ScaffoldDiagnostic,
|
|
393
|
+
): ScaffoldFileResult {
|
|
394
|
+
return {
|
|
395
|
+
disposition: "skipped",
|
|
396
|
+
source,
|
|
397
|
+
repairs: [],
|
|
398
|
+
skipReason: reason,
|
|
399
|
+
...(diagnostic ? { diagnostic } : {}),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Pure per-file transform. Returns the (possibly) rewritten source plus a
|
|
405
|
+
* disposition — never throws; unrepairable shapes report SCAFFOLD-02, and
|
|
406
|
+
* authored text carrying a comment terminator reports COMPASS-CS-08 — both
|
|
407
|
+
* with the original source.
|
|
408
|
+
*/
|
|
409
|
+
export function scaffoldFile(input: ScaffoldFileInput, policy: CompassPolicy): ScaffoldFileResult {
|
|
410
|
+
try {
|
|
411
|
+
return scaffoldFileImpl(input, policy);
|
|
412
|
+
} catch (err) {
|
|
413
|
+
if (err instanceof CompassCommentSafetyError) {
|
|
414
|
+
return skipped("unsafe text", input.source, {
|
|
415
|
+
ruleId: "COMPASS-CS-08",
|
|
416
|
+
message: `${err.message} — file left untouched`,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
throw err;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function scaffoldFileImpl(input: ScaffoldFileInput, policy: CompassPolicy): ScaffoldFileResult {
|
|
424
|
+
const { source, pathFromRoot, riskClass, keyDecisionsRequired } = input;
|
|
425
|
+
const tagIdx = firstTagIndex(source);
|
|
426
|
+
const span = findHeaderSpan(source, pathFromRoot);
|
|
427
|
+
|
|
428
|
+
// Fixture-string safety — markup candidates outside a header comment are
|
|
429
|
+
// string-literal/code-borne tags; dynamic tag construction is agent work.
|
|
430
|
+
// An unterminated comment opener swallowing the tags is a malformation
|
|
431
|
+
// (SCAFFOLD-02), not a fixture.
|
|
432
|
+
if (!span && tagIdx >= 0) {
|
|
433
|
+
const unterminated = (
|
|
434
|
+
[
|
|
435
|
+
["/*", "*/"],
|
|
436
|
+
["<!--", "-->"],
|
|
437
|
+
] as const
|
|
438
|
+
).some(([opener, closer]) => {
|
|
439
|
+
const open = source.lastIndexOf(opener, tagIdx);
|
|
440
|
+
return (
|
|
441
|
+
open >= 0 &&
|
|
442
|
+
atLineStart(source, open) &&
|
|
443
|
+
!insideLiteral(source, open, opener === "/*" ? "block" : "html") &&
|
|
444
|
+
!source.slice(open, tagIdx).includes(closer) &&
|
|
445
|
+
source.indexOf(closer, tagIdx) < 0
|
|
446
|
+
);
|
|
447
|
+
});
|
|
448
|
+
if (unterminated) {
|
|
449
|
+
return skipped("unrepairable malformation", source, {
|
|
450
|
+
ruleId: "SCAFFOLD-02",
|
|
451
|
+
message: "unterminated comment carries compass tags — file left untouched",
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const lines = tagLines(source);
|
|
455
|
+
return skipped("fixture-string markup", source, {
|
|
456
|
+
ruleId: "SCAFFOLD-01",
|
|
457
|
+
message: `markup candidates outside a header comment — literal lines: ${lines.join(" | ")}`,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// High-risk deference — a new header on a high-risk file requires an
|
|
462
|
+
// @ai-invariant the codemod cannot invent; authorship stays agent work.
|
|
463
|
+
const aiInvariants = collectAiInvariants(source, policy);
|
|
464
|
+
if (!span && riskClass === "high" && aiInvariants.length === 0) {
|
|
465
|
+
return skipped(
|
|
466
|
+
"high-risk file requires an @ai-invariant — header authorship stays agent work",
|
|
467
|
+
source,
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// ── Insert path: no header anywhere ───────────────────────────────────────
|
|
472
|
+
if (!span) {
|
|
473
|
+
const purpose = derivePurpose(input);
|
|
474
|
+
const blocks = [
|
|
475
|
+
contractBlock(purpose.text, [SENTINEL_NONGOAL]),
|
|
476
|
+
...(keyDecisionsRequired
|
|
477
|
+
? [keyDecisionsBlock(aiInvariants.length > 0 ? aiInvariants : [TODO_ITEM])]
|
|
478
|
+
: []),
|
|
479
|
+
"<CHANGE_SUMMARY>\n</CHANGE_SUMMARY>",
|
|
480
|
+
];
|
|
481
|
+
const style = insertStyleFor(pathFromRoot, source);
|
|
482
|
+
const header = wrapHeader(blocks, style, pathFromRoot);
|
|
483
|
+
const at = insertionOffset(source, pathFromRoot);
|
|
484
|
+
// Never glue the header onto a partial last line (EOF shebang, frontmatter
|
|
485
|
+
// fence without trailing newline, terminal 'use client').
|
|
486
|
+
const pad = at > 0 && source[at - 1] !== "\n" ? "\n" : "";
|
|
487
|
+
const next = `${source.slice(0, at)}${pad}${header}\n\n${source.slice(at)}`;
|
|
488
|
+
if (!closesCleanly(next, pathFromRoot)) {
|
|
489
|
+
return skipped("unrepairable malformation", source, {
|
|
490
|
+
ruleId: "SCAFFOLD-02",
|
|
491
|
+
message: "composed header failed the closed-block parse-back — file left untouched",
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
disposition: purpose.sentinel ? "sentinel" : "inserted",
|
|
496
|
+
source: next,
|
|
497
|
+
repairs: ["inserted-header", ...(purpose.sentinel ? ["sentinel-purpose"] : [])],
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// ── Repair path: append-only merge inside the header comment ──────────────
|
|
502
|
+
// Staged edits: every stage recomputes positions against the post-edit text
|
|
503
|
+
// so coordinates never mix bases.
|
|
504
|
+
let next = source;
|
|
505
|
+
const repairs: string[] = [];
|
|
506
|
+
let usedSentinel = false;
|
|
507
|
+
const prefixFor = (s: HeaderSpan) =>
|
|
508
|
+
s.style === "line" ? (getLineCommentPrefix(pathFromRoot) ?? "# ") : "";
|
|
509
|
+
const reheader = () => {
|
|
510
|
+
const s = findHeaderSpan(next, pathFromRoot);
|
|
511
|
+
return s ? { span: s, text: next.slice(s.start, s.end) } : null;
|
|
512
|
+
};
|
|
513
|
+
const lineWrap = (block: string, s: HeaderSpan) => {
|
|
514
|
+
const prefix = prefixFor(s);
|
|
515
|
+
return prefix === ""
|
|
516
|
+
? block
|
|
517
|
+
: block
|
|
518
|
+
.split("\n")
|
|
519
|
+
.map((l) => prefix + l)
|
|
520
|
+
.join("\n");
|
|
521
|
+
};
|
|
522
|
+
// Line-style spans may only be edited at line boundaries — a mid-line
|
|
523
|
+
// insert either splits the prefix run or glues text onto a comment line.
|
|
524
|
+
// insertAt: before the line containing absPos. appendAt: past the run's
|
|
525
|
+
// end for line style (closeStart === end there), before the comment
|
|
526
|
+
// terminator otherwise. Line-style text needs a leading "\n".
|
|
527
|
+
const insertAt = (absPos: number, h: { span: HeaderSpan }) =>
|
|
528
|
+
prefixFor(h.span) !== "" ? lineStartOf(next, absPos) : absPos;
|
|
529
|
+
const appendAt = (h: { span: HeaderSpan }) =>
|
|
530
|
+
prefixFor(h.span) !== "" ? h.span.end : h.span.closeStart;
|
|
531
|
+
const appendText = (block: string, s: HeaderSpan) =>
|
|
532
|
+
prefixFor(s) !== "" ? `\n${block}` : `${block}\n`;
|
|
533
|
+
const stageGuard = (): ScaffoldFileResult => ({
|
|
534
|
+
disposition: "skipped",
|
|
535
|
+
source,
|
|
536
|
+
repairs: [],
|
|
537
|
+
skipReason: "unrepairable malformation",
|
|
538
|
+
diagnostic: {
|
|
539
|
+
ruleId: "SCAFFOLD-02",
|
|
540
|
+
message: "header comment lost between repair stages — file left untouched",
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// Stage 1 — close any compass tag left open inside the header. The close
|
|
545
|
+
// anchors before the next sibling tag's open (a swallowed sibling) or
|
|
546
|
+
// before the header comment's own terminator. All anchor positions are
|
|
547
|
+
// header-relative and shift by h.span.start exactly once.
|
|
548
|
+
{
|
|
549
|
+
const h = reheader();
|
|
550
|
+
if (!h) return stageGuard();
|
|
551
|
+
const prefix = prefixFor(h.span);
|
|
552
|
+
const closeEdits: Edit[] = [];
|
|
553
|
+
for (const tag of COMPASS_TAGS) {
|
|
554
|
+
if (!hasUnclosedTag(h.text, tag)) continue;
|
|
555
|
+
const openAt = h.text.indexOf(`<${tag}>`);
|
|
556
|
+
const later = COMPASS_TAGS.slice(COMPASS_TAGS.indexOf(tag) + 1)
|
|
557
|
+
.map((t) => h.text.indexOf(`<${t}>`, openAt + 1))
|
|
558
|
+
.filter((i) => i >= 0)
|
|
559
|
+
.sort((a, b) => a - b);
|
|
560
|
+
let at: number;
|
|
561
|
+
let closeLine: string;
|
|
562
|
+
if (later.length > 0 && prefix !== "") {
|
|
563
|
+
// Anchor at the sibling tag's line start — a mid-line insert would
|
|
564
|
+
// split the contiguous prefix run line comments depend on.
|
|
565
|
+
at = h.text.lastIndexOf("\n", later[0]! - 1) + 1;
|
|
566
|
+
closeLine = `${prefix}</${tag}>\n`;
|
|
567
|
+
} else if (later.length > 0) {
|
|
568
|
+
at = later[0]!;
|
|
569
|
+
closeLine = `</${tag}>\n`;
|
|
570
|
+
} else if (prefix !== "") {
|
|
571
|
+
// End of the prefix run — open a fresh line rather than gluing onto
|
|
572
|
+
// the last comment line's tail.
|
|
573
|
+
at = h.span.end - h.span.start;
|
|
574
|
+
closeLine = `\n${prefix}</${tag}>`;
|
|
575
|
+
} else {
|
|
576
|
+
at = h.span.closeStart - h.span.start;
|
|
577
|
+
closeLine = `</${tag}>\n`;
|
|
578
|
+
}
|
|
579
|
+
closeEdits.push({ start: h.span.start + at, end: h.span.start + at, text: closeLine });
|
|
580
|
+
repairs.push(`closed-${tag.toLowerCase().replace(/_/g, "-")}`);
|
|
581
|
+
}
|
|
582
|
+
next = applyEdits(next, closeEdits, { style: h.span.style, file: pathFromRoot });
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Stage 2 — contract-level repairs: missing contract, missing/unclosed
|
|
586
|
+
// purpose, missing/unclosed/item-less non-goals.
|
|
587
|
+
{
|
|
588
|
+
const h = reheader();
|
|
589
|
+
if (!h) return stageGuard();
|
|
590
|
+
const edits: Edit[] = [];
|
|
591
|
+
const contract = blockSpan(h.text, "MODULE_CONTRACT");
|
|
592
|
+
if (!contract) {
|
|
593
|
+
// The header comment carries stray tags but no contract — compose one
|
|
594
|
+
// inside the comment. Canonical order puts MODULE_CONTRACT first, so it
|
|
595
|
+
// anchors before the earliest stray block (or at the run's end).
|
|
596
|
+
const purpose = derivePurpose(input);
|
|
597
|
+
usedSentinel = purpose.sentinel;
|
|
598
|
+
const insertion = lineWrap(contractBlock(purpose.text, [SENTINEL_NONGOAL]), h.span);
|
|
599
|
+
const strayIdx = ["<KEY_DECISIONS>", "<CHANGE_SUMMARY>"]
|
|
600
|
+
.map((t) => h.text.indexOf(t))
|
|
601
|
+
.filter((i) => i >= 0)
|
|
602
|
+
.sort((a, b) => a - b)[0];
|
|
603
|
+
if (strayIdx !== undefined) {
|
|
604
|
+
const at = insertAt(h.span.start + strayIdx, h);
|
|
605
|
+
edits.push({ start: at, end: at, text: `${insertion}\n` });
|
|
606
|
+
} else {
|
|
607
|
+
const at = appendAt(h);
|
|
608
|
+
edits.push({ start: at, end: at, text: appendText(insertion, h.span) });
|
|
609
|
+
}
|
|
610
|
+
repairs.push("inserted-module-contract");
|
|
611
|
+
} else {
|
|
612
|
+
const contractText = h.text.slice(contract.start, contract.end);
|
|
613
|
+
const base = h.span.start + contract.start;
|
|
614
|
+
|
|
615
|
+
if (!contractText.includes("<purpose>")) {
|
|
616
|
+
const purpose = derivePurpose(input);
|
|
617
|
+
usedSentinel = purpose.sentinel;
|
|
618
|
+
const openEnd = base + "<MODULE_CONTRACT>".length;
|
|
619
|
+
edits.push({
|
|
620
|
+
start: openEnd,
|
|
621
|
+
end: openEnd,
|
|
622
|
+
text: `\n${lineWrap(`<purpose>${purpose.text}</purpose>`, h.span)}`,
|
|
623
|
+
order: 20,
|
|
624
|
+
});
|
|
625
|
+
repairs.push(purpose.sentinel ? "sentinel-purpose" : "inserted-purpose");
|
|
626
|
+
} else if (!contractText.includes("</purpose>")) {
|
|
627
|
+
// An unclosed <purpose> swallows its siblings — close it before the
|
|
628
|
+
// next inner tag or the contract close, whichever comes first.
|
|
629
|
+
const purposeOpen = contractText.indexOf("<purpose>");
|
|
630
|
+
const following = ["<non-goals>", "</MODULE_CONTRACT>"]
|
|
631
|
+
.map((t) => contractText.indexOf(t, purposeOpen + 1))
|
|
632
|
+
.filter((i) => i >= 0)
|
|
633
|
+
.sort((a, b) => a - b);
|
|
634
|
+
// `following` is contractText-relative; contract.end is h.text-relative.
|
|
635
|
+
const absAt = following.length > 0 ? base + following[0]! : h.span.start + contract.end;
|
|
636
|
+
// Same-line siblings (`# <purpose>t <non-goals>`) close inline —
|
|
637
|
+
// a line-start insert would emit the close before its own open and
|
|
638
|
+
// a prefixed insert would split the line leaving a bare tag tail.
|
|
639
|
+
const purposeAbs = base + purposeOpen;
|
|
640
|
+
const sameLine =
|
|
641
|
+
prefixFor(h.span) !== "" && lineStartOf(next, absAt) === lineStartOf(next, purposeAbs);
|
|
642
|
+
const anchor = sameLine ? absAt : insertAt(absAt, h);
|
|
643
|
+
edits.push({
|
|
644
|
+
start: anchor,
|
|
645
|
+
end: anchor,
|
|
646
|
+
text: sameLine ? `</purpose> ` : `${lineWrap("</purpose>", h.span)}\n`,
|
|
647
|
+
order: 10,
|
|
648
|
+
});
|
|
649
|
+
repairs.push("closed-purpose");
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const ng = contractText.indexOf("<non-goals>");
|
|
653
|
+
if (ng < 0) {
|
|
654
|
+
const anchor = insertAt(base + contractText.indexOf("</MODULE_CONTRACT>"), h);
|
|
655
|
+
edits.push({
|
|
656
|
+
start: anchor,
|
|
657
|
+
end: anchor,
|
|
658
|
+
text: `${lineWrap(`<non-goals>\n <item>${SENTINEL_NONGOAL}</item>\n</non-goals>`, h.span)}\n`,
|
|
659
|
+
order: 30,
|
|
660
|
+
});
|
|
661
|
+
repairs.push("inserted-non-goals");
|
|
662
|
+
} else {
|
|
663
|
+
let ngEnd = contractText.indexOf("</non-goals>", ng);
|
|
664
|
+
if (ngEnd < 0) {
|
|
665
|
+
const anchor = insertAt(base + contractText.indexOf("</MODULE_CONTRACT>"), h);
|
|
666
|
+
edits.push({
|
|
667
|
+
start: anchor,
|
|
668
|
+
end: anchor,
|
|
669
|
+
text: `${lineWrap("</non-goals>", h.span)}\n`,
|
|
670
|
+
order: 40,
|
|
671
|
+
});
|
|
672
|
+
repairs.push("closed-non-goals");
|
|
673
|
+
ngEnd = contractText.indexOf("</MODULE_CONTRACT>");
|
|
674
|
+
}
|
|
675
|
+
const inner = contractText.slice(ng + "<non-goals>".length, ngEnd);
|
|
676
|
+
const itemOpens = (inner.match(/<item>/g) ?? []).length;
|
|
677
|
+
const itemCloses = (inner.match(/<\/item>/g) ?? []).length;
|
|
678
|
+
if (itemOpens === 0) {
|
|
679
|
+
const bareLines = inner
|
|
680
|
+
.split("\n")
|
|
681
|
+
.map((l) => l.trim().replace(/^[#;]+\s?/, ""))
|
|
682
|
+
.filter((l) => l.length > 0 && !l.startsWith("*") && !l.startsWith("//"));
|
|
683
|
+
const items = bareLines.length > 0 ? bareLines : [SENTINEL_NONGOAL];
|
|
684
|
+
const ngPrefix = prefixFor(h.span);
|
|
685
|
+
if (ngPrefix !== "") {
|
|
686
|
+
// Line style: replace whole prefixed lines — the line after
|
|
687
|
+
// <non-goals> through the line before </non-goals>.
|
|
688
|
+
const innerStart = next.indexOf("\n", base + ng) + 1;
|
|
689
|
+
const innerEnd = lineStartOf(next, base + ngEnd);
|
|
690
|
+
if (innerStart > 0 && innerStart <= innerEnd) {
|
|
691
|
+
edits.push({
|
|
692
|
+
start: innerStart,
|
|
693
|
+
end: innerEnd,
|
|
694
|
+
text: items.map((i) => `${ngPrefix} <item>${i}</item>\n`).join(""),
|
|
695
|
+
});
|
|
696
|
+
repairs.push("non-goals-items");
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
edits.push({
|
|
700
|
+
start: base + ng + "<non-goals>".length,
|
|
701
|
+
end: base + ngEnd,
|
|
702
|
+
text: `\n${items.map((i) => ` <item>${i}</item>`).join("\n")}\n`,
|
|
703
|
+
});
|
|
704
|
+
repairs.push("non-goals-items");
|
|
705
|
+
}
|
|
706
|
+
} else if (itemOpens !== itemCloses) {
|
|
707
|
+
// Same-line `<item>…</non-goals>` closes inline — a line-start
|
|
708
|
+
// insert would emit the close before its own open.
|
|
709
|
+
const itemOpenAbs = base + ng + "<non-goals>".length + inner.lastIndexOf("<item>");
|
|
710
|
+
const itemAbsEnd = base + ngEnd;
|
|
711
|
+
const sameLine =
|
|
712
|
+
prefixFor(h.span) !== "" &&
|
|
713
|
+
lineStartOf(next, itemAbsEnd) === lineStartOf(next, itemOpenAbs);
|
|
714
|
+
const anchor = sameLine ? itemAbsEnd : insertAt(itemAbsEnd, h);
|
|
715
|
+
edits.push({
|
|
716
|
+
start: anchor,
|
|
717
|
+
end: anchor,
|
|
718
|
+
text: sameLine ? `</item> ` : `${lineWrap("</item>", h.span)}\n`,
|
|
719
|
+
order: 10,
|
|
720
|
+
});
|
|
721
|
+
repairs.push("closed-item");
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
next = applyEdits(next, edits, { style: h.span.style, file: pathFromRoot });
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// Stage 3 — KEY_DECISIONS required by layer/risk but absent.
|
|
729
|
+
{
|
|
730
|
+
const h = reheader();
|
|
731
|
+
if (!h) return stageGuard();
|
|
732
|
+
if (keyDecisionsRequired && !h.text.includes("<KEY_DECISIONS>")) {
|
|
733
|
+
if (riskClass === "high" && aiInvariants.length === 0) {
|
|
734
|
+
return skipped(
|
|
735
|
+
"high-risk file requires an @ai-invariant — header authorship stays agent work",
|
|
736
|
+
source,
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
const kd = lineWrap(
|
|
740
|
+
keyDecisionsBlock(aiInvariants.length > 0 ? aiInvariants : [TODO_ITEM]),
|
|
741
|
+
h.span,
|
|
742
|
+
);
|
|
743
|
+
const mc = blockSpan(h.text, "MODULE_CONTRACT");
|
|
744
|
+
if (mc) {
|
|
745
|
+
next = applyEdits(
|
|
746
|
+
next,
|
|
747
|
+
[
|
|
748
|
+
{
|
|
749
|
+
start: h.span.start + mc.end,
|
|
750
|
+
end: h.span.start + mc.end,
|
|
751
|
+
text: `\n${kd}`,
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
{ style: h.span.style, file: pathFromRoot },
|
|
755
|
+
);
|
|
756
|
+
} else {
|
|
757
|
+
const at = appendAt(h);
|
|
758
|
+
next = applyEdits(next, [{ start: at, end: at, text: appendText(kd, h.span) }], {
|
|
759
|
+
style: h.span.style,
|
|
760
|
+
file: pathFromRoot,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
repairs.push("inserted-key-decisions");
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Stage 4 — CHANGE_SUMMARY absent entirely (unclosed was repaired in stage 1).
|
|
768
|
+
{
|
|
769
|
+
const h = reheader();
|
|
770
|
+
if (!h) return stageGuard();
|
|
771
|
+
if (!h.text.includes("<CHANGE_SUMMARY>")) {
|
|
772
|
+
const cs = lineWrap("<CHANGE_SUMMARY>\n</CHANGE_SUMMARY>", h.span);
|
|
773
|
+
const anchor =
|
|
774
|
+
blockSpan(h.text, "KEY_DECISIONS")?.end ?? blockSpan(h.text, "MODULE_CONTRACT")?.end;
|
|
775
|
+
if (anchor !== undefined) {
|
|
776
|
+
next = applyEdits(
|
|
777
|
+
next,
|
|
778
|
+
[
|
|
779
|
+
{
|
|
780
|
+
start: h.span.start + anchor,
|
|
781
|
+
end: h.span.start + anchor,
|
|
782
|
+
text: `\n${cs}`,
|
|
783
|
+
},
|
|
784
|
+
],
|
|
785
|
+
{ style: h.span.style, file: pathFromRoot },
|
|
786
|
+
);
|
|
787
|
+
} else {
|
|
788
|
+
const at = appendAt(h);
|
|
789
|
+
next = applyEdits(next, [{ start: at, end: at, text: appendText(cs, h.span) }], {
|
|
790
|
+
style: h.span.style,
|
|
791
|
+
file: pathFromRoot,
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
repairs.push("inserted-change-summary");
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (next === source) {
|
|
799
|
+
return { disposition: "unchanged", source, repairs: [] };
|
|
800
|
+
}
|
|
801
|
+
if (!closesCleanly(next, pathFromRoot)) {
|
|
802
|
+
return skipped("unrepairable malformation", source, {
|
|
803
|
+
ruleId: "SCAFFOLD-02",
|
|
804
|
+
message: "repaired header failed the closed-block parse-back — file left untouched",
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
return {
|
|
808
|
+
disposition: usedSentinel ? "sentinel" : "repaired",
|
|
809
|
+
source: next,
|
|
810
|
+
repairs: [...new Set(repairs)],
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Every compass tag present in the header comment closes inside it — inner
|
|
816
|
+
* tags included, so "unchanged" stays aligned with what compass.validate
|
|
817
|
+
* reports (its extractor requires close tags too).
|
|
818
|
+
*/
|
|
819
|
+
function closesCleanly(source: string, path: string): boolean {
|
|
820
|
+
const span = findHeaderSpan(source, path);
|
|
821
|
+
if (!span) return false;
|
|
822
|
+
const header = source.slice(span.start, span.end);
|
|
823
|
+
for (const tag of COMPASS_TAGS) {
|
|
824
|
+
if (hasUnclosedTag(header, tag)) return false;
|
|
825
|
+
}
|
|
826
|
+
const contract = blockSpan(header, "MODULE_CONTRACT");
|
|
827
|
+
if (!contract) return false;
|
|
828
|
+
const contractText = header.slice(contract.start, contract.end);
|
|
829
|
+
if (!contractText.includes("<purpose>") || !contractText.includes("</purpose>")) return false;
|
|
830
|
+
const ng = blockSpan(contractText, "non-goals");
|
|
831
|
+
if (!ng) return false;
|
|
832
|
+
const ngText = contractText.slice(ng.start, ng.end);
|
|
833
|
+
const itemOpens = (ngText.match(/<item>/g) ?? []).length;
|
|
834
|
+
const itemCloses = (ngText.match(/<\/item>/g) ?? []).length;
|
|
835
|
+
if (itemOpens === 0 || itemOpens !== itemCloses) return false;
|
|
836
|
+
return header.includes("<CHANGE_SUMMARY>");
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** Workspace-relative path for an explicit --files target (mirrors migrate's toTarget). */
|
|
840
|
+
export function explicitWorkspaceRelativePath(
|
|
841
|
+
absPath: string,
|
|
842
|
+
workspaceRoot: string,
|
|
843
|
+
policy: CompassPolicy,
|
|
844
|
+
): string {
|
|
845
|
+
const segments = getRelativeSegments(absPath, workspaceRoot);
|
|
846
|
+
return getWorkspaceRelativeSegments(segments, policy).join("/");
|
|
847
|
+
}
|