@ncoderz/awa 1.7.2 → 1.8.1
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/LICENSE +23 -16
- package/README.md +25 -27
- package/dist/chunk-EL7ZWFXO.js +875 -0
- package/dist/chunk-EL7ZWFXO.js.map +1 -0
- package/dist/{chunk-OQZTQ5ZI.js → chunk-LRQWZCYL.js} +1 -4
- package/dist/chunk-LRQWZCYL.js.map +1 -0
- package/dist/{config-WL3SLSP6.js → config-EJIXC7D7.js} +2 -2
- package/dist/index.js +1257 -452
- package/dist/index.js.map +1 -1
- package/dist/renumber-TLBGOWZM.js +9 -0
- package/dist/renumber-TLBGOWZM.js.map +1 -0
- package/package.json +13 -6
- package/templates/awa/.agent/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.agent/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.agent/workflows/spec-merge.md +3 -0
- package/templates/awa/.agent/workflows/spec-tidy.md +3 -0
- package/templates/awa/.agents/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.agents/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.awa/.agent/schemas/ALIGN_REPORT.schema.yaml +1 -1
- package/templates/awa/.awa/.agent/schemas/API.schema.yaml +1 -1
- package/templates/awa/.awa/.agent/schemas/ARCHITECTURE.schema.yaml +7 -0
- package/templates/awa/.awa/.agent/schemas/DESIGN.schema.yaml +1 -1
- package/templates/awa/.awa/.agent/schemas/{EXAMPLES.schema.yaml → EXAMPLE.schema.yaml} +4 -4
- package/templates/awa/.awa/.agent/schemas/FEAT.schema.yaml +8 -1
- package/templates/awa/.awa/.agent/schemas/PLAN.schema.yaml +1 -1
- package/templates/awa/.awa/.agent/schemas/README.schema.yaml +1 -1
- package/templates/awa/.awa/.agent/schemas/REQ.schema.yaml +1 -1
- package/templates/awa/.awa/.agent/schemas/TASK.schema.yaml +1 -1
- package/templates/awa/.claude/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.claude/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.gemini/commands/spec-merge.md +3 -0
- package/templates/awa/.gemini/commands/spec-tidy.md +3 -0
- package/templates/awa/.gemini/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.gemini/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.github/prompts/awa.spec-merge.prompt.md +8 -0
- package/templates/awa/.github/prompts/awa.spec-tidy.prompt.md +7 -0
- package/templates/awa/.github/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.github/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.kilocode/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.kilocode/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.kilocode/workflows/spec-merge.md +3 -0
- package/templates/awa/.kilocode/workflows/spec-tidy.md +3 -0
- package/templates/awa/.opencode/commands/spec-merge.md +3 -0
- package/templates/awa/.opencode/commands/spec-tidy.md +3 -0
- package/templates/awa/.opencode/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.opencode/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.qwen/commands/spec-merge.md +3 -0
- package/templates/awa/.qwen/commands/spec-tidy.md +3 -0
- package/templates/awa/.qwen/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.qwen/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.roo/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.roo/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/.windsurf/skills/spec-merge/SKILL.md +3 -0
- package/templates/awa/.windsurf/skills/spec-tidy/SKILL.md +3 -0
- package/templates/awa/_delete.txt +4 -0
- package/templates/awa/_partials/_cmd.spec-merge.md +6 -0
- package/templates/awa/_partials/_cmd.spec-tidy.md +5 -0
- package/templates/awa/_partials/_skill.spec-merge.md +6 -0
- package/templates/awa/_partials/_skill.spec-tidy.md +6 -0
- package/templates/awa/_partials/awa.align.md +1 -1
- package/templates/awa/_partials/awa.brainstorm.md +1 -1
- package/templates/awa/_partials/awa.code.md +1 -1
- package/templates/awa/_partials/awa.core.md +9 -4
- package/templates/awa/_partials/awa.design.md +3 -2
- package/templates/awa/_partials/awa.documentation.md +1 -1
- package/templates/awa/_partials/awa.examples.md +4 -4
- package/templates/awa/_partials/awa.feature.md +2 -1
- package/templates/awa/_partials/awa.plan.md +2 -2
- package/templates/awa/_partials/awa.requirements.md +4 -2
- package/templates/awa/_partials/awa.spec-merge.md +97 -0
- package/templates/awa/_partials/awa.spec.tidy.md +92 -0
- package/templates/awa/_partials/awa.tasks.md +1 -1
- package/templates/awa/_partials/awa.upgrade.md +3 -3
- package/templates/awa/_partials/awa.usage.md +77 -6
- package/templates/awa/_partials/awa.vibe.md +1 -1
- package/templates/awa/_tests/claude/.awa/.agent/awa.core.md +126 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/ALIGN_REPORT.schema.yaml +83 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/API.schema.yaml +7 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/ARCHITECTURE.schema.yaml +257 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/DESIGN.schema.yaml +351 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/EXAMPLE.schema.yaml +89 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/FEAT.schema.yaml +142 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/PLAN.schema.yaml +146 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/README.schema.yaml +137 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/REQ.schema.yaml +160 -0
- package/templates/awa/_tests/claude/.awa/.agent/schemas/TASK.schema.yaml +204 -0
- package/templates/awa/_tests/claude/.claude/agents/awa.md +137 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-align/SKILL.md +67 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-architecture/SKILL.md +50 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-brainstorm/SKILL.md +57 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-check/SKILL.md +79 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-code/SKILL.md +179 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-design/SKILL.md +62 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-documentation/SKILL.md +91 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-examples/SKILL.md +58 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-feature/SKILL.md +56 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-plan/SKILL.md +53 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-refactor/SKILL.md +53 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-requirements/SKILL.md +58 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-tasks/SKILL.md +158 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-upgrade/SKILL.md +68 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-usage/SKILL.md +368 -0
- package/templates/awa/_tests/claude/.claude/skills/awa-vibe/SKILL.md +72 -0
- package/templates/awa/_tests/claude/.claude/skills/spec-merge/SKILL.md +102 -0
- package/templates/awa/_tests/claude/.claude/skills/spec-tidy/SKILL.md +97 -0
- package/templates/awa/_tests/claude/CLAUDE.md +132 -0
- package/templates/awa/_tests/copilot/.awa/.agent/awa.core.md +126 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/ALIGN_REPORT.schema.yaml +83 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/API.schema.yaml +7 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/ARCHITECTURE.schema.yaml +257 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/DESIGN.schema.yaml +351 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/EXAMPLE.schema.yaml +89 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/FEAT.schema.yaml +142 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/PLAN.schema.yaml +146 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/README.schema.yaml +137 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/REQ.schema.yaml +160 -0
- package/templates/awa/_tests/copilot/.awa/.agent/schemas/TASK.schema.yaml +204 -0
- package/templates/awa/_tests/copilot/.github/agents/awa.agent.md +137 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.align.prompt.md +67 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.architecture.prompt.md +50 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.brainstorm.prompt.md +57 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.check.prompt.md +79 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.code.prompt.md +179 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.design.prompt.md +62 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.documentation.prompt.md +91 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.examples.prompt.md +58 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.feature.prompt.md +56 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.plan.prompt.md +53 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.refactor.prompt.md +53 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.requirements.prompt.md +58 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.spec-merge.prompt.md +102 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.spec-tidy.prompt.md +96 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.tasks.prompt.md +158 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.upgrade.prompt.md +68 -0
- package/templates/awa/_tests/copilot/.github/prompts/awa.vibe.prompt.md +72 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-align/SKILL.md +67 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-architecture/SKILL.md +50 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-brainstorm/SKILL.md +57 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-check/SKILL.md +79 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-code/SKILL.md +179 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-design/SKILL.md +62 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-documentation/SKILL.md +91 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-examples/SKILL.md +58 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-feature/SKILL.md +56 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-plan/SKILL.md +53 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-refactor/SKILL.md +53 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-requirements/SKILL.md +58 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-tasks/SKILL.md +158 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-upgrade/SKILL.md +68 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-usage/SKILL.md +368 -0
- package/templates/awa/_tests/copilot/.github/skills/awa-vibe/SKILL.md +72 -0
- package/templates/awa/_tests/copilot/.github/skills/spec-merge/SKILL.md +102 -0
- package/templates/awa/_tests/copilot/.github/skills/spec-tidy/SKILL.md +97 -0
- package/dist/chunk-OQZTQ5ZI.js.map +0 -1
- /package/dist/{config-WL3SLSP6.js.map → config-EJIXC7D7.js.map} +0 -0
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/index.ts","../src/_generated/package_info.ts","../src/core/check/code-spec-checker.ts","../src/core/check/marker-scanner.ts","../src/core/check/glob.ts","../src/core/check/matrix-fixer.ts","../src/core/check/reporter.ts","../src/core/check/rule-loader.ts","../src/core/check/schema-checker.ts","../src/core/check/spec-parser.ts","../src/core/check/spec-spec-checker.ts","../src/core/check/types.ts","../src/commands/check.ts","../src/commands/diff.ts","../src/core/batch-runner.ts","../src/core/differ.ts","../src/core/delete-list.ts","../src/core/generator.ts","../src/core/resolver.ts","../src/core/template.ts","../src/core/feature-resolver.ts","../src/core/json-output.ts","../src/core/overlay.ts","../src/core/template-resolver.ts","../src/utils/file-watcher.ts","../src/utils/debouncer.ts","../src/commands/features.ts","../src/core/features/reporter.ts","../src/core/features/scanner.ts","../src/commands/generate.ts","../src/commands/test.ts","../src/core/template-test/fixture-loader.ts","../src/core/template-test/reporter.ts","../src/core/template-test/runner.ts","../src/core/template-test/snapshot.ts","../src/core/trace/content-assembler.ts","../src/core/trace/content-formatter.ts","../src/core/trace/formatter.ts","../src/core/trace/index-builder.ts","../src/core/trace/input-resolver.ts","../src/core/trace/resolver.ts","../src/core/trace/scanner.ts","../src/core/trace/token-estimator.ts","../src/commands/trace.ts","../src/utils/update-check.ts","../src/utils/update-check-cache.ts"],"sourcesContent":["// @awa-component: CLI-ArgumentParser\n// @awa-component: TCLI-TemplateGroup\n// @awa-component: TCLI-RootProgram\n// @awa-impl: CLI-1_AC-1\n// @awa-impl: CLI-1_AC-2\n// @awa-impl: CLI-1_AC-3\n// @awa-impl: CLI-1_AC-4\n// @awa-impl: CLI-1_AC-5\n// @awa-impl: CLI-2_AC-1\n// @awa-impl: CLI-2_AC-2\n// @awa-impl: CLI-2_AC-3\n// @awa-impl: CLI-2_AC-5\n// @awa-impl: CLI-2_AC-6\n// @awa-impl: CLI-3_AC-1\n// @awa-impl: CLI-4_AC-1\n// @awa-impl: CLI-4_AC-2\n// @awa-impl: CLI-5_AC-1\n// @awa-impl: CLI-6_AC-1\n// @awa-impl: CLI-7_AC-1\n// @awa-impl: CLI-8_AC-1\n// @awa-impl: CLI-9_AC-1\n// @awa-impl: CLI-9_AC-2\n// @awa-impl: CLI-9_AC-3\n// @awa-impl: CLI-10_AC-1\n// @awa-impl: CLI-10_AC-2\n// @awa-impl: CLI-11_AC-1\n// @awa-impl: CLI-11_AC-2\n// @awa-impl: CLI-11_AC-3\n// @awa-impl: CLI-12_AC-1\n// @awa-impl: CLI-13_AC-1\n// @awa-impl: CLI-13_AC-2\n// @awa-impl: CLI-14_AC-1\n// @awa-impl: CLI-14_AC-2\n// @awa-impl: CLI-6_AC-2\n// @awa-impl: CFG-5_AC-2\n// @awa-impl: DIFF-7_AC-1\n// @awa-impl: DIFF-7_AC-2\n// @awa-impl: DIFF-7_AC-3\n// @awa-impl: DIFF-7_AC-4\n// @awa-impl: DIFF-7_AC-5\n// @awa-impl: DIFF-7_AC-6\n// @awa-impl: DIFF-7_AC-7\n// @awa-impl: DIFF-7_AC-8\n// @awa-impl: DIFF-7_AC-9\n// @awa-impl: DIFF-7_AC-10\n// @awa-impl: DIFF-7_AC-11\n// @awa-impl: DIFF-7_AC-12\n// @awa-impl: DIFF-7_AC-13\n// @awa-impl: FP-2_AC-1\n// @awa-impl: FP-2_AC-2\n// @awa-impl: FP-2_AC-4\n// @awa-impl: FP-4_AC-1\n// @awa-impl: FP-4_AC-2\n// @awa-impl: FP-4_AC-3\n// @awa-impl: FP-4_AC-5\n// @awa-impl: GEN-10_AC-1\n// @awa-impl: GEN-10_AC-2\n// @awa-impl: INIT-1_AC-1\n// @awa-impl: INIT-2_AC-1\n// @awa-impl: INIT-3_AC-1\n// @awa-impl: INIT-4_AC-1\n// @awa-impl: TCLI-1_AC-1\n// @awa-impl: TCLI-1_AC-2\n// @awa-impl: TCLI-1_AC-3\n// @awa-impl: TCLI-1_AC-4\n// @awa-impl: TCLI-1_AC-5\n// @awa-impl: TCLI-1_AC-6\n// @awa-impl: TCLI-1_AC-7\n// @awa-impl: TCLI-2_AC-1\n// @awa-impl: TCLI-2_AC-2\n// @awa-impl: TCLI-3_AC-1\n// @awa-impl: TCLI-3_AC-2\n// @awa-impl: TCLI-3_AC-3\n// @awa-impl: TCLI-3_AC-4\n// @awa-impl: TCLI-4_AC-1\n// @awa-impl: TCLI-4_AC-2\n// @awa-impl: TCLI-5_AC-1\n// @awa-impl: TCLI-5_AC-2\n// @awa-impl: TCLI-5_AC-3\n// @awa-impl: TCLI-5_AC-4\n\nimport { Command, Option } from 'commander';\nimport { PACKAGE_INFO } from '../_generated/package_info.js';\nimport { checkCommand } from '../commands/check.js';\nimport { diffCommand } from '../commands/diff.js';\nimport { featuresCommand } from '../commands/features.js';\nimport { generateCommand } from '../commands/generate.js';\nimport { testCommand } from '../commands/test.js';\nimport { traceCommand } from '../commands/trace.js';\nimport type { RawCheckOptions } from '../core/check/types.js';\nimport type { RawTestOptions } from '../core/template-test/types.js';\nimport type { TraceCommandOptions } from '../core/trace/types.js';\nimport type { RawCliOptions } from '../types/index.js';\nimport { logger } from '../utils/logger.js';\nimport {\n checkForUpdate,\n printUpdateWarning,\n type UpdateCheckResult,\n} from '../utils/update-check.js';\nimport { shouldCheck, writeCache } from '../utils/update-check-cache.js';\n\nconst version = PACKAGE_INFO.version;\n\n// @awa-impl: CLI-1_AC-2, CLI-9_AC-1, CLI-9_AC-2, CLI-9_AC-3, CLI-10_AC-1, CLI-10_AC-2\n// @awa-impl: TCLI-4_AC-1\nconst program = new Command();\n\nprogram\n .name('awa')\n .description('awa - tool for generating AI coding agent configuration files')\n .version(version, '-v, --version', 'Display version number');\n\n// @awa-impl: TCLI-1_AC-1, TCLI-1_AC-2, TCLI-1_AC-3, TCLI-4_AC-2\n// @awa-impl: TCLI-5_AC-1, TCLI-5_AC-2, TCLI-5_AC-3, TCLI-5_AC-4\nconst template = new Command('template').description(\n 'Template operations (generate, diff, features, test)'\n);\n\n// @awa-impl: CLI-1_AC-1, CLI-1_AC-2, CLI-1_AC-3, CLI-1_AC-4, CLI-1_AC-5\n// @awa-impl: INIT-1_AC-1, INIT-2_AC-1, INIT-3_AC-1, INIT-4_AC-1\n// @awa-impl: TCLI-1_AC-4, TCLI-2_AC-1, TCLI-2_AC-2\n\n/** Configure a generate/init command with shared options and action handler. */\nfunction configureGenerateCommand(cmd: Command): Command {\n return (\n cmd\n .description('Generate AI agent configuration files from templates')\n // @awa-impl: CLI-2_AC-1, CLI-2_AC-5, CLI-2_AC-6\n .argument('[output]', 'Output directory (optional if specified in config)')\n // @awa-impl: CLI-3_AC-1\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n // @awa-impl: CLI-4_AC-1, CLI-4_AC-2\n .option('-f, --features <flag...>', 'Feature flags (can be specified multiple times)')\n .option('--preset <name...>', 'Preset names to enable (can be specified multiple times)')\n .option(\n '--remove-features <flag...>',\n 'Feature flags to remove (can be specified multiple times)'\n )\n // @awa-impl: CLI-5_AC-1\n .option('--force', 'Force overwrite existing files without prompting', false)\n // @awa-impl: CLI-6_AC-1\n .option('--dry-run', 'Preview changes without modifying files', false)\n .option(\n '--delete',\n 'Enable deletion of files listed in the delete list (default: warn only)',\n false\n )\n // @awa-impl: CLI-7_AC-1\n .option('-c, --config <path>', 'Path to configuration file')\n // @awa-impl: CLI-8_AC-1\n .option('--refresh', 'Force refresh of cached Git templates', false)\n // @awa-impl: CLI-15_AC-1\n .option('--all-targets', 'Process all named targets from config', false)\n // @awa-impl: CLI-15_AC-2\n .option('--target <name>', 'Process a specific named target from config')\n // @awa-impl: OVL-1_AC-1\n .option(\n '--overlay <path...>',\n 'Overlay directory paths applied over base template (repeatable)'\n )\n // @awa-impl: JSON-1_AC-1\n .option('--json', 'Output results as JSON (implies --dry-run)', false)\n // @awa-impl: JSON-5_AC-1\n .option('--summary', 'Output compact one-line summary', false)\n .action(async (output: string | undefined, options) => {\n // @awa-impl: CLI-11_AC-1, CLI-11_AC-2, CLI-11_AC-3\n const cliOptions: RawCliOptions = {\n output,\n template: options.template,\n features: options.features,\n preset: options.preset,\n removeFeatures: options.removeFeatures,\n force: options.force,\n dryRun: options.dryRun,\n delete: options.delete,\n config: options.config,\n refresh: options.refresh,\n all: options.allTargets,\n allTargets: options.allTargets,\n target: options.target,\n overlay: options.overlay || [],\n json: options.json,\n summary: options.summary,\n };\n\n await generateCommand(cliOptions);\n })\n );\n}\n\nconfigureGenerateCommand(template.command('generate'));\n\n// @awa-impl: TCLI-2_AC-1, TCLI-2_AC-2\n// Top-level init convenience command (delegates to same handler as template generate)\nconfigureGenerateCommand(program.command('init'));\n\n// @awa-impl: DIFF-7_AC-1, DIFF-7_AC-2, DIFF-7_AC-3, DIFF-7_AC-4, DIFF-7_AC-5, DIFF-7_AC-6, DIFF-7_AC-7, DIFF-7_AC-8, DIFF-7_AC-9, DIFF-7_AC-10\n// @awa-impl: TCLI-1_AC-5\ntemplate\n .command('diff')\n .description('Compare template output with existing target directory')\n // @awa-impl: DIFF-7_AC-1, DIFF-7_AC-2, DIFF-7_AC-3, DIFF-7_AC-4, DIFF-7_AC-5\n .argument('[target]', 'Target directory to compare against (optional if specified in config)')\n // @awa-impl: DIFF-7_AC-6\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n // @awa-impl: DIFF-7_AC-7\n .option('-f, --features <flag...>', 'Feature flags (can be specified multiple times)')\n .option('--preset <name...>', 'Preset names to enable (can be specified multiple times)')\n .option(\n '--remove-features <flag...>',\n 'Feature flags to remove (can be specified multiple times)'\n )\n // @awa-impl: DIFF-7_AC-8\n .option('-c, --config <path>', 'Path to configuration file')\n // @awa-impl: DIFF-7_AC-9\n .option('--refresh', 'Force refresh of cached Git templates', false)\n // @awa-impl: DIFF-7_AC-11\n .option('--list-unknown', 'Include target-only files in diff results', false)\n // @awa-impl: CLI-15_AC-1\n .option('--all-targets', 'Process all named targets from config', false)\n // @awa-impl: CLI-15_AC-2\n .option('--target <name>', 'Process a specific named target from config')\n .option('-w, --watch', 'Watch template directory for changes and re-run diff', false)\n // @awa-impl: OVL-7_AC-1\n .option('--overlay <path...>', 'Overlay directory paths applied over base template (repeatable)')\n // @awa-impl: JSON-2_AC-1\n .option('--json', 'Output results as JSON', false)\n // @awa-impl: JSON-5_AC-1\n .option('--summary', 'Output compact one-line summary', false)\n // @awa-impl: DIFF-7_AC-10\n // Note: --force and --dry-run are intentionally NOT accepted for diff command\n .action(async (target: string | undefined, options) => {\n const cliOptions: RawCliOptions = {\n output: target, // Use target as output for consistency\n template: options.template,\n features: options.features,\n preset: options.preset,\n removeFeatures: options.removeFeatures,\n config: options.config,\n refresh: options.refresh,\n listUnknown: options.listUnknown,\n all: options.allTargets,\n allTargets: options.allTargets,\n target: options.target,\n watch: options.watch,\n overlay: options.overlay || [],\n json: options.json,\n summary: options.summary,\n };\n\n const exitCode = await diffCommand(cliOptions);\n process.exit(exitCode);\n });\n\n// @awa-impl: CHK-8_AC-1, CHK-9_AC-1, CHK-10_AC-1\n// @awa-impl: TCLI-3_AC-1, TCLI-3_AC-3\nprogram\n .command('check')\n .description(\n 'Validate spec files against schemas and check traceability between code markers and specs'\n )\n .option('-c, --config <path>', 'Path to configuration file')\n // @awa-impl: CHK-10_AC-1\n .option('--spec-ignore <pattern...>', 'Glob patterns to exclude from spec file scanning')\n .option('--code-ignore <pattern...>', 'Glob patterns to exclude from code file scanning')\n // @awa-impl: CHK-9_AC-1\n .option('--json', 'Output results as JSON', false)\n .addOption(\n new Option('--format <format>', 'Output format (text or json)').default('text').hideHelp()\n )\n .option('--summary', 'Output compact one-line summary', false)\n .option(\n '--allow-warnings',\n 'Allow warnings without failing (default: warnings are errors)',\n false\n )\n .option(\n '--spec-only',\n 'Run only spec-level checks (schema and cross-refs); skip code-to-spec traceability',\n false\n )\n .option(\n '--no-fix',\n 'Skip regeneration of Requirements Traceability sections in DESIGN and TASK files'\n )\n .action(async (options) => {\n const cliOptions: RawCheckOptions = {\n config: options.config,\n specIgnore: options.specIgnore,\n codeIgnore: options.codeIgnore,\n format: options.format,\n json: options.json,\n summary: options.summary,\n allowWarnings: options.allowWarnings,\n specOnly: options.specOnly,\n fix: options.fix,\n };\n\n const exitCode = await checkCommand(cliOptions);\n process.exit(exitCode);\n });\n\n// @awa-impl: DISC-4_AC-1, DISC-5_AC-1\n// @awa-impl: TCLI-1_AC-6\ntemplate\n .command('features')\n .description('Discover feature flags available in a template')\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n .option('-c, --config <path>', 'Path to configuration file')\n .option('--refresh', 'Force refresh of cached Git templates', false)\n .option('--overlay <path...>', 'Overlay directory paths applied over base template (repeatable)')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .action(async (options) => {\n const exitCode = await featuresCommand({\n template: options.template,\n config: options.config,\n refresh: options.refresh,\n json: options.json,\n summary: options.summary,\n overlay: options.overlay || [],\n });\n process.exit(exitCode);\n });\n\n// @awa-impl: TTST-7_AC-1, TTST-5_AC-1\n// @awa-impl: TCLI-1_AC-7\ntemplate\n .command('test')\n .description('Run template test fixtures to verify expected output')\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n .option('-c, --config <path>', 'Path to configuration file')\n .option('--update-snapshots', 'Update stored snapshots with current rendered output', false)\n .option('--refresh', 'Force refresh of cached Git templates', false)\n .option('--overlay <path...>', 'Overlay directory paths applied over base template (repeatable)')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .action(async (options) => {\n const testOptions: RawTestOptions = {\n template: options.template,\n config: options.config,\n updateSnapshots: options.updateSnapshots,\n refresh: options.refresh,\n json: options.json,\n summary: options.summary,\n overlay: options.overlay || [],\n };\n\n const exitCode = await testCommand(testOptions);\n process.exit(exitCode);\n });\n\n// Add template group to root program\nprogram.addCommand(template);\n\n// @awa-impl: TRC-8_AC-1\n// @awa-impl: TCLI-3_AC-2, TCLI-3_AC-4\nprogram\n .command('trace')\n .description('Explore traceability chains and assemble context from specs, code, and tests')\n .argument('[ids...]', 'Traceability ID(s) to trace')\n .option('--all', 'Trace all known IDs in the project', false)\n .option('--task <path>', 'Resolve IDs from a task file')\n .option('--file <path>', \"Resolve IDs from a source file's markers\")\n .option('--content', 'Output actual file sections instead of locations', false)\n .option('--list', 'Output file paths only (no content or tree)', false)\n .option('--max-tokens <n>', 'Cap content output size (implies --content)')\n .option('--depth <n>', 'Maximum traversal depth')\n .option('--scope <code>', 'Limit results to a feature code')\n .option('--direction <dir>', 'Traversal direction: both, forward, reverse', 'both')\n .option('--no-code', 'Exclude source code (spec-only context)')\n .option('--no-tests', 'Exclude test files')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .option('-A <n>', 'Lines of context after a code marker (--content only; default: 20)')\n .option('-B <n>', 'Lines of context before a code marker (--content only; default: 5)')\n .option('-C <n>', 'Lines of context before and after (--content only; overrides -A and -B)')\n .option('-c, --config <path>', 'Path to configuration file')\n .action(async (ids: string[], options) => {\n const traceOptions: TraceCommandOptions = {\n ids,\n all: options.all,\n task: options.task,\n file: options.file,\n content: options.content,\n list: options.list,\n json: options.json,\n summary: options.summary,\n maxTokens: options.maxTokens !== undefined ? Number(options.maxTokens) : undefined,\n depth: options.depth !== undefined ? Number(options.depth) : undefined,\n scope: options.scope,\n direction: options.direction,\n noCode: options.code === false,\n noTests: options.tests === false,\n beforeContext:\n options.C !== undefined\n ? Number(options.C)\n : options.B !== undefined\n ? Number(options.B)\n : undefined,\n afterContext:\n options.C !== undefined\n ? Number(options.C)\n : options.A !== undefined\n ? Number(options.A)\n : undefined,\n config: options.config,\n };\n\n const exitCode = await traceCommand(traceOptions);\n process.exit(exitCode);\n });\n\n// Fire update check asynchronously (non-blocking) before parse\nlet updateCheckPromise: Promise<UpdateCheckResult | null> | null = null;\n\nconst isJsonOrSummary = process.argv.includes('--json') || process.argv.includes('--summary');\nconst isTTY = process.stdout.isTTY === true;\nconst isDisabledByEnv = !!process.env.NO_UPDATE_NOTIFIER;\n\nif (!isJsonOrSummary && isTTY && !isDisabledByEnv) {\n updateCheckPromise = (async () => {\n try {\n // Load config to check update-check settings\n const { configLoader } = await import('../core/config.js');\n const configPath =\n process.argv.indexOf('-c') !== -1\n ? process.argv[process.argv.indexOf('-c') + 1]\n : process.argv.indexOf('--config') !== -1\n ? process.argv[process.argv.indexOf('--config') + 1]\n : undefined;\n const fileConfig = await configLoader.load(configPath ?? null);\n\n const updateCheckConfig = fileConfig?.['update-check'];\n if (updateCheckConfig?.enabled === false) return null;\n\n const intervalSeconds = updateCheckConfig?.interval ?? 86400;\n const intervalMs = intervalSeconds * 1000;\n\n const needsCheck = await shouldCheck(intervalMs);\n if (!needsCheck) return null;\n\n const result = await checkForUpdate();\n if (result) {\n await writeCache(result.latest);\n }\n return result;\n } catch {\n return null;\n }\n })();\n}\n\n// Print update warning after command completes\nprogram.hook('postAction', async () => {\n if (!updateCheckPromise) return;\n try {\n const result = await updateCheckPromise;\n if (result?.isOutdated) {\n printUpdateWarning(logger, result);\n }\n } catch {\n // Silently ignore\n }\n});\n\n// @awa-impl: GEN-10_AC-1, GEN-10_AC-2\nprogram.parseAsync();\n","// This file is automatically generated. DO NOT EDIT.\n\n/* eslint-disable */\n\nexport const PACKAGE_INFO = {\n \"name\": \"@ncoderz/awa\",\n \"version\": \"1.7.2\",\n \"author\": \"Richard Sewell <richard.sewell@ncoderz.com>\",\n \"license\": \"MIT\",\n \"description\": \"awa is an Agent Workflow for AIs. It is also a CLI tool to powerfully manage agent workflow files using templates.\"\n};\n","// @awa-component: CHK-CodeSpecChecker\n// @awa-impl: CHK-3_AC-1\n// @awa-impl: CHK-4_AC-1\n// @awa-impl: CHK-6_AC-1\n// @awa-impl: CHK-14_AC-1\n// @awa-impl: CHK-18_AC-1\n// @awa-impl: CHK-19_AC-1\n// @awa-impl: CHK-20_AC-1\n// @awa-impl: CHK-21_AC-1\n// @awa-impl: CHK-22_AC-1\n\nimport type {\n CheckConfig,\n CheckResult,\n Finding,\n MarkerScanResult,\n SpecParseResult,\n} from './types.js';\n\n// @awa-impl: CHK-3_AC-1, CHK-4_AC-1, CHK-6_AC-1, CHK-18_AC-1, CHK-19_AC-1, CHK-20_AC-1, CHK-21_AC-1, CHK-22_AC-1\nexport function checkCodeAgainstSpec(\n markers: MarkerScanResult,\n specs: SpecParseResult,\n config: CheckConfig\n): CheckResult {\n const findings: Finding[] = [];\n\n // @awa-impl: CHK-6_AC-1, CHK-14_AC-1\n // Validate ID format for all markers\n const idRegex = new RegExp(`^${config.idPattern}$`);\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n // Component names have different format — skip ID pattern check\n continue;\n }\n if (!idRegex.test(marker.id)) {\n findings.push({\n severity: 'error',\n code: 'invalid-id-format',\n message: `Marker ID '${marker.id}' does not match expected pattern: ${config.idPattern}`,\n filePath: marker.filePath,\n line: marker.line,\n id: marker.id,\n });\n }\n }\n\n // @awa-impl: CHK-3_AC-1\n // Check for orphaned markers (code references non-existent spec ID)\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n // Component markers reference component names\n if (!specs.componentNames.has(marker.id)) {\n findings.push({\n severity: 'error',\n code: 'orphaned-marker',\n message: `Component marker '${marker.id}' not found in any spec file`,\n filePath: marker.filePath,\n line: marker.line,\n id: marker.id,\n });\n }\n } else {\n // impl and test markers reference IDs (ACs, properties, requirement IDs)\n if (!specs.allIds.has(marker.id)) {\n findings.push({\n severity: 'error',\n code: 'orphaned-marker',\n message: `Marker '${marker.id}' not found in any spec file`,\n filePath: marker.filePath,\n line: marker.line,\n id: marker.id,\n });\n }\n }\n }\n\n // @awa-impl: CHK-4_AC-1\n // Check for uncovered ACs (spec ACs with no @awa-test reference)\n const testedIds = new Set(markers.markers.filter((m) => m.type === 'test').map((m) => m.id));\n\n for (const acId of specs.acIds) {\n if (!testedIds.has(acId)) {\n // Look up location from idLocations map, fall back to spec file path\n const loc = specs.idLocations.get(acId);\n const specFile = loc ? undefined : specs.specFiles.find((sf) => sf.acIds.includes(acId));\n findings.push({\n severity: 'warning',\n code: 'uncovered-ac',\n message: `Acceptance criterion '${acId}' has no @awa-test reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: acId,\n });\n }\n }\n\n // @awa-impl: CHK-18_AC-1\n // Check for uncovered components (DESIGN components with no @awa-component marker)\n const implementedComponents = new Set(\n markers.markers.filter((m) => m.type === 'component').map((m) => m.id)\n );\n\n for (const componentName of specs.componentNames) {\n if (!implementedComponents.has(componentName)) {\n const loc = specs.idLocations.get(componentName);\n const specFile = loc\n ? undefined\n : specs.specFiles.find((sf) => sf.componentNames.includes(componentName));\n findings.push({\n severity: 'warning',\n code: 'uncovered-component',\n message: `Component '${componentName}' has no @awa-component reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: componentName,\n });\n }\n }\n\n // @awa-impl: CHK-19_AC-1\n // Check for unimplemented ACs (spec ACs with no @awa-impl marker)\n const implementedIds = new Set(markers.markers.filter((m) => m.type === 'impl').map((m) => m.id));\n\n for (const acId of specs.acIds) {\n if (!implementedIds.has(acId)) {\n const loc = specs.idLocations.get(acId);\n const specFile = loc ? undefined : specs.specFiles.find((sf) => sf.acIds.includes(acId));\n findings.push({\n severity: 'warning',\n code: 'unimplemented-ac',\n message: `Acceptance criterion '${acId}' has no @awa-impl reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: acId,\n });\n }\n }\n\n // @awa-impl: CHK-20_AC-1\n // G5: Check for uncovered properties (spec properties with no @awa-test marker)\n for (const propId of specs.propertyIds) {\n if (!testedIds.has(propId)) {\n const loc = specs.idLocations.get(propId);\n const specFile = loc\n ? undefined\n : specs.specFiles.find((sf) => sf.propertyIds.includes(propId));\n findings.push({\n severity: 'warning',\n code: 'uncovered-property',\n message: `Property '${propId}' has no @awa-test reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: propId,\n });\n }\n }\n\n // @awa-impl: CHK-22_AC-1\n // G1: Check IMPLEMENTS ↔ @awa-impl consistency\n // For each @awa-component marker in code, compare the set of @awa-impl IDs\n // in the same file against the DESIGN component's IMPLEMENTS list\n const componentFiles = new Map<string, Set<string>>();\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n if (!componentFiles.has(marker.id)) {\n componentFiles.set(marker.id, new Set());\n }\n }\n }\n // Collect all @awa-impl IDs per component (by file co-location)\n // A file's component is determined by @awa-component markers in that file\n const fileToComponents = new Map<string, string[]>();\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n const existing = fileToComponents.get(marker.filePath) ?? [];\n existing.push(marker.id);\n fileToComponents.set(marker.filePath, existing);\n }\n }\n for (const marker of markers.markers) {\n if (marker.type === 'impl') {\n const components = fileToComponents.get(marker.filePath);\n if (components) {\n for (const comp of components) {\n componentFiles.get(comp)?.add(marker.id);\n }\n }\n }\n }\n\n // Build the IMPLEMENTS set per component from all DESIGN spec files\n const designImplements = new Map<string, Set<string>>();\n for (const specFile of specs.specFiles) {\n if (specFile.componentImplements) {\n for (const [comp, ids] of specFile.componentImplements) {\n const existing = designImplements.get(comp) ?? new Set();\n for (const id of ids) existing.add(id);\n designImplements.set(comp, existing);\n }\n }\n }\n\n for (const [compName, codeImplIds] of componentFiles) {\n const designImplIds = designImplements.get(compName);\n if (!designImplIds) continue; // No DESIGN component found (already caught by orphaned-marker)\n\n // impl-not-in-implements: @awa-impl in code but not in DESIGN IMPLEMENTS\n for (const implId of codeImplIds) {\n if (!designImplIds.has(implId)) {\n findings.push({\n severity: 'warning',\n code: 'impl-not-in-implements',\n message: `@awa-impl '${implId}' in component '${compName}' is not listed in its IMPLEMENTS`,\n id: implId,\n });\n }\n }\n\n // implements-not-in-impl: DESIGN IMPLEMENTS but no @awa-impl in any file tagged with that component\n for (const implId of designImplIds) {\n if (!codeImplIds.has(implId)) {\n const loc = specs.idLocations.get(compName);\n findings.push({\n severity: 'warning',\n code: 'implements-not-in-impl',\n message: `IMPLEMENTS '${implId}' in component '${compName}' has no @awa-impl in code`,\n filePath: loc?.filePath,\n line: loc?.line,\n id: implId,\n });\n }\n }\n }\n\n return { findings };\n}\n","// @awa-component: CHK-MarkerScanner\n// @awa-impl: CHK-1_AC-1\n// @awa-impl: CHK-11_AC-1\n// @awa-impl: CHK-13_AC-1\n\nimport { readFile } from 'node:fs/promises';\nimport { collectFiles, matchSimpleGlob } from './glob.js';\nimport type { CheckConfig, CodeMarker, Finding, MarkerScanResult, MarkerType } from './types.js';\n\nconst MARKER_TYPE_MAP: Record<string, MarkerType> = {\n '@awa-impl': 'impl',\n '@awa-test': 'test',\n '@awa-component': 'component',\n};\n\n/** Ignore directive patterns (similar to eslint-disable comments). */\n// Use RegExp constructor so the literal token does not appear in this source file,\n// preventing the marker scanner from self-ignoring when it scans its own code.\nconst IGNORE_FILE_RE = new RegExp('@awa-ignore' + '-file\\\\b');\nconst IGNORE_NEXT_LINE_RE = /@awa-ignore-next-line\\b/;\nconst IGNORE_LINE_RE = /@awa-ignore\\b/;\nconst IGNORE_START_RE = /@awa-ignore-start\\b/;\nconst IGNORE_END_RE = /@awa-ignore-end\\b/;\n\n// @awa-impl: CHK-1_AC-1\nexport async function scanMarkers(config: CheckConfig): Promise<MarkerScanResult> {\n const files = await collectCodeFiles(config.codeGlobs, config.codeIgnore);\n const markers: CodeMarker[] = [];\n const findings: Finding[] = [];\n\n for (const filePath of files) {\n // Skip files matching ignoreMarkers globs\n if (config.ignoreMarkers.some((ig) => matchSimpleGlob(filePath, ig))) {\n continue;\n }\n\n const result = await scanFile(filePath, config.markers);\n markers.push(...result.markers);\n findings.push(...result.findings);\n }\n\n return { markers, findings };\n}\n\n// @awa-impl: CHK-11_AC-1\nfunction buildMarkerRegex(markerNames: readonly string[]): RegExp {\n const escaped = markerNames.map((m) => m.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'));\n // Match marker followed by colon, then capture the rest of the line (IDs)\n return new RegExp(`(${escaped.join('|')}):\\\\s*(.+)`, 'g');\n}\n\n/** Pattern matching valid impl/test IDs and component names. */\nconst ID_TOKEN_RE = /^([A-Z][A-Z0-9]*(?:[-_][A-Za-z0-9]+)*(?:\\.\\d+)?(?:[-_][A-Za-z0-9]+)*)/;\n\nasync function scanFile(\n filePath: string,\n markerNames: readonly string[]\n): Promise<{ markers: CodeMarker[]; findings: Finding[] }> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return { markers: [], findings: [] };\n }\n\n // Check for file-level ignore directive anywhere in the file\n if (IGNORE_FILE_RE.test(content)) {\n return { markers: [], findings: [] };\n }\n\n const regex = buildMarkerRegex(markerNames);\n const lines = content.split('\\n');\n const markers: CodeMarker[] = [];\n const findings: Finding[] = [];\n let ignoreNextLine = false;\n let ignoreBlock = false;\n\n for (const [i, line] of lines.entries()) {\n // Check for block ignore boundaries\n if (IGNORE_START_RE.test(line)) {\n ignoreBlock = true;\n continue;\n }\n if (IGNORE_END_RE.test(line)) {\n ignoreBlock = false;\n continue;\n }\n if (ignoreBlock) {\n continue;\n }\n\n // Check if previous line had @awa-ignore-next-line\n if (ignoreNextLine) {\n ignoreNextLine = false;\n continue;\n }\n\n // Check if this line is an @awa-ignore-next-line directive\n if (IGNORE_NEXT_LINE_RE.test(line)) {\n ignoreNextLine = true;\n continue;\n }\n\n // Check for inline @awa-ignore on this line (ignores markers on this line)\n if (IGNORE_LINE_RE.test(line)) {\n continue;\n }\n\n regex.lastIndex = 0;\n let match = regex.exec(line);\n\n while (match !== null) {\n const markerName = match[1] ?? '';\n const idsRaw = match[2] ?? '';\n const type = resolveMarkerType(markerName, markerNames);\n\n // Split by comma to support multiple IDs per marker line\n const ids = idsRaw\n .split(',')\n .map((id) => id.trim())\n .filter(Boolean);\n\n for (const id of ids) {\n // Extract only the leading ID token\n const tokenMatch = ID_TOKEN_RE.exec(id);\n const cleanId = tokenMatch?.[1]?.trim() ?? '';\n if (cleanId && tokenMatch) {\n // Check for trailing text after the ID (only whitespace allowed)\n const remainder = id.slice(tokenMatch[0].length).trim();\n if (remainder) {\n findings.push({\n severity: 'error',\n code: 'marker-trailing-text',\n message: `Marker has trailing text after ID '${cleanId}': '${remainder}' — use comma-separated IDs only`,\n filePath,\n line: i + 1,\n id: cleanId,\n });\n }\n markers.push({ type, id: cleanId, filePath, line: i + 1 });\n }\n }\n\n match = regex.exec(line);\n }\n }\n\n return { markers, findings };\n}\n\nfunction resolveMarkerType(markerName: string, configuredMarkers: readonly string[]): MarkerType {\n // Check default mapping first\n const mapped = MARKER_TYPE_MAP[markerName];\n if (mapped) return mapped;\n // For custom markers, infer type by position in configured array\n // Default order: [impl, test, component]\n const idx = configuredMarkers.indexOf(markerName);\n if (idx === 1) return 'test';\n if (idx === 2) return 'component';\n return 'impl';\n}\n\n// @awa-impl: CHK-13_AC-1\nasync function collectCodeFiles(\n codeGlobs: readonly string[],\n ignore: readonly string[]\n): Promise<string[]> {\n return collectFiles(codeGlobs, ignore);\n}\n","// @awa-component: CHK-MarkerScanner\n// @awa-impl: CHK-13_AC-1\n\nimport { glob } from 'node:fs/promises';\n\n/**\n * Matches a path against a simple glob pattern supporting * and **.\n * Also matches a directory prefix against `dir/**` patterns (e.g. \"src\" matches \"src/**\").\n */\nexport function matchSimpleGlob(path: string, pattern: string): boolean {\n const regex = pattern\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\*\\*/g, '<<GLOBSTAR>>')\n .replace(/\\*/g, '[^/]*')\n .replace(/<<GLOBSTAR>>/g, '.*');\n return new RegExp(`(^|/)${regex}($|/)`).test(path);\n}\n\n/**\n * Collect files matching globs while applying ignore patterns.\n * Uses fs.glob exclude callback for directory-level skipping (perf optimization)\n * and post-filters results for file-level ignore matching.\n */\nexport async function collectFiles(\n globs: readonly string[],\n ignore: readonly string[]\n): Promise<string[]> {\n const files: string[] = [];\n\n // For exclude callback, also match directory prefixes (e.g. \"src\" for \"src/**\")\n const dirPrefixes = ignore.filter((ig) => ig.endsWith('/**')).map((ig) => ig.slice(0, -3));\n\n for (const pattern of globs) {\n for await (const filePath of glob(pattern, {\n exclude: (p) => dirPrefixes.includes(p) || ignore.some((ig) => matchSimpleGlob(p, ig)),\n })) {\n // Post-filter: fs.glob exclude only receives directory names,\n // so we must also filter the yielded file paths\n if (!ignore.some((ig) => matchSimpleGlob(filePath, ig))) {\n files.push(filePath);\n }\n }\n }\n\n return [...new Set(files)];\n}\n","// @awa-component: CHK-MatrixFixer\n// @awa-impl: CHK-23_AC-1\n// @awa-impl: CHK-23_AC-2\n\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport type { SpecFile, SpecParseResult } from './types.js';\n\n// --- Public API ---\n\nexport interface FixResult {\n readonly filesFixed: number;\n readonly fileResults: readonly FileFixResult[];\n}\n\nexport interface FileFixResult {\n readonly filePath: string;\n readonly changed: boolean;\n}\n\n/**\n * Regenerate \"Requirements Traceability\" sections in all DESIGN and TASK files.\n * Returns the number of files that were actually modified.\n */\nexport async function fixMatrices(\n specs: SpecParseResult,\n crossRefPatterns: readonly string[]\n): Promise<FixResult> {\n const reqFileMaps = buildReqFileMaps(specs.specFiles);\n const fileResults: FileFixResult[] = [];\n\n for (const specFile of specs.specFiles) {\n const fileName = basename(specFile.filePath);\n\n if (fileName.startsWith('DESIGN-')) {\n const changed = await fixDesignMatrix(specFile.filePath, reqFileMaps, crossRefPatterns);\n fileResults.push({ filePath: specFile.filePath, changed });\n } else if (fileName.startsWith('TASK-')) {\n const changed = await fixTaskMatrix(specFile.filePath, reqFileMaps, specs, crossRefPatterns);\n fileResults.push({ filePath: specFile.filePath, changed });\n }\n }\n\n return {\n filesFixed: fileResults.filter((r) => r.changed).length,\n fileResults,\n };\n}\n\n// --- ID → REQ filename maps ---\n\ninterface ReqFileMaps {\n /** Maps each requirement ID and AC ID to the REQ file that defines it. */\n readonly idToReqFile: Map<string, string>;\n /** Maps code prefix to sorted list of REQ filenames (fallback for property IDs). */\n readonly codeToReqFiles: Map<string, string[]>;\n}\n\n/**\n * Build maps from requirement/AC IDs and code prefixes to REQ filenames.\n * The per-ID map correctly handles multiple REQ files sharing the same code\n * prefix (e.g. REQ-ARC-flows.md and REQ-ARC-security.md both using ARC-* IDs).\n */\nfunction buildReqFileMaps(specFiles: readonly SpecFile[]): ReqFileMaps {\n const idToReqFile = new Map<string, string>();\n const codeToReqFilesSet = new Map<string, Set<string>>();\n\n for (const sf of specFiles) {\n const fileName = basename(sf.filePath);\n if (!/\\bREQ-/.test(fileName)) continue;\n\n // Map each requirement ID and AC ID to this REQ file\n for (const reqId of sf.requirementIds) {\n idToReqFile.set(reqId, fileName);\n }\n for (const acId of sf.acIds) {\n idToReqFile.set(acId, fileName);\n }\n\n // Build code → REQ files multimap for property ID fallback\n if (sf.code) {\n const existing = codeToReqFilesSet.get(sf.code) ?? new Set<string>();\n existing.add(fileName);\n codeToReqFilesSet.set(sf.code, existing);\n }\n }\n\n // Convert sets to sorted arrays for deterministic output\n const codeToReqFiles = new Map<string, string[]>();\n for (const [code, files] of codeToReqFilesSet) {\n codeToReqFiles.set(code, [...files].sort());\n }\n\n return { idToReqFile, codeToReqFiles };\n}\n\n/**\n * Resolve an ID to its REQ file.\n * - Requirement IDs and AC IDs: direct lookup via idToReqFile\n * - AC IDs not found directly: strip _AC-N suffix and look up parent requirement\n * - Property IDs (CODE_P-N): code prefix fallback via codeToReqFiles\n * (when one REQ file for the code, it's unambiguous; with multiple, uses first sorted)\n */\nfunction resolveReqFile(id: string, maps: ReqFileMaps): string | undefined {\n // Direct lookup (works for both requirement IDs and AC IDs)\n const direct = maps.idToReqFile.get(id);\n if (direct) return direct;\n\n // For AC IDs, try parent requirement: strip _AC-N suffix\n const acMatch = /^(.+)_AC-\\d+$/.exec(id);\n if (acMatch?.[1]) {\n return maps.idToReqFile.get(acMatch[1]);\n }\n\n // For property IDs (CODE_P-N), fall back to code prefix\n const propMatch = /^([A-Z][A-Z0-9]*)_P-\\d+$/.exec(id);\n if (propMatch?.[1]) {\n const files = maps.codeToReqFiles.get(propMatch[1]);\n return files?.[0];\n }\n\n return undefined;\n}\n\n// --- DESIGN matrix ---\n\ninterface ComponentInfo {\n readonly name: string;\n readonly implements: string[];\n}\n\ninterface PropertyInfo {\n readonly id: string;\n readonly validates: string[];\n}\n\nasync function fixDesignMatrix(\n filePath: string,\n reqFileMaps: ReqFileMaps,\n crossRefPatterns: readonly string[]\n): Promise<boolean> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return false;\n }\n\n const { components, properties } = parseDesignFileData(content, crossRefPatterns);\n\n // AC → component names\n const acToComponents = new Map<string, string[]>();\n for (const comp of components) {\n for (const acId of comp.implements) {\n const existing = acToComponents.get(acId) ?? [];\n existing.push(comp.name);\n acToComponents.set(acId, existing);\n }\n }\n\n // AC → property IDs (from VALIDATES)\n const acToProperties = new Map<string, string[]>();\n for (const prop of properties) {\n for (const acId of prop.validates) {\n const existing = acToProperties.get(acId) ?? [];\n existing.push(prop.id);\n acToProperties.set(acId, existing);\n }\n }\n\n // Group ACs by REQ file\n const allAcIds = [...acToComponents.keys()];\n const grouped = groupByReqFile(allAcIds, reqFileMaps);\n\n const newSection = generateDesignSection(grouped, acToComponents, acToProperties);\n const newContent = replaceTraceabilitySection(content, newSection);\n if (newContent === content) return false;\n\n await writeFile(filePath, newContent, 'utf-8');\n return true;\n}\n\nfunction parseDesignFileData(\n content: string,\n crossRefPatterns: readonly string[]\n): { components: ComponentInfo[]; properties: PropertyInfo[] } {\n const lines = content.split('\\n');\n const components: ComponentInfo[] = [];\n const properties: PropertyInfo[] = [];\n\n const componentRegex = /^###\\s+([A-Z][A-Z0-9]*-[A-Za-z][A-Za-z0-9]*(?:[A-Z][a-z0-9]*)*)\\s*$/;\n const reqIdRegex = /^###\\s+([A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?)\\s*:/;\n const propIdRegex = /^-\\s+([A-Z][A-Z0-9]*_P-\\d+)\\s/;\n\n let currentComponent: string | null = null;\n let lastPropertyId: string | null = null;\n\n for (const line of lines) {\n // Component heading\n const compMatch = componentRegex.exec(line);\n if (compMatch?.[1] && !reqIdRegex.test(line)) {\n currentComponent = compMatch[1];\n lastPropertyId = null;\n components.push({ name: currentComponent, implements: [] });\n continue;\n }\n\n // H1/H2 heading resets context\n if (/^#{1,2}\\s/.test(line) && !compMatch) {\n currentComponent = null;\n lastPropertyId = null;\n continue;\n }\n\n // Property ID\n const propMatch = propIdRegex.exec(line);\n if (propMatch?.[1]) {\n lastPropertyId = propMatch[1];\n properties.push({ id: lastPropertyId, validates: [] });\n continue;\n }\n\n // Cross-references\n for (const pattern of crossRefPatterns) {\n const patIdx = line.indexOf(pattern);\n if (patIdx !== -1) {\n const afterPattern = line.slice(patIdx + pattern.length);\n const ids = extractIdsFromText(afterPattern);\n if (ids.length > 0) {\n const isImplements = pattern.toLowerCase().includes('implements');\n if (isImplements && currentComponent) {\n const comp = components.find((c) => c.name === currentComponent);\n if (comp) comp.implements.push(...ids);\n } else if (!isImplements && lastPropertyId) {\n const prop = properties.find((p) => p.id === lastPropertyId);\n if (prop) prop.validates.push(...ids);\n }\n }\n }\n }\n }\n\n return { components, properties };\n}\n\nfunction generateDesignSection(\n grouped: Map<string, string[]>,\n acToComponents: Map<string, string[]>,\n acToProperties: Map<string, string[]>\n): string {\n const lines: string[] = [];\n const reqFiles = [...grouped.keys()].sort();\n\n for (const reqFile of reqFiles) {\n lines.push(`### ${reqFile}`);\n lines.push('');\n\n const acIds = grouped.get(reqFile) ?? [];\n acIds.sort(compareIds);\n\n for (const acId of acIds) {\n const components = acToComponents.get(acId) ?? [];\n const props = acToProperties.get(acId) ?? [];\n\n for (const comp of components) {\n const propStr = props.length > 0 ? ` (${props.join(', ')})` : '';\n lines.push(`- ${acId} → ${comp}${propStr}`);\n }\n }\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n\n// --- TASK matrix ---\n\ninterface TaskInfo {\n readonly id: string;\n readonly implements: string[];\n readonly tests: string[];\n}\n\nasync function fixTaskMatrix(\n filePath: string,\n reqFileMaps: ReqFileMaps,\n specs: SpecParseResult,\n crossRefPatterns: readonly string[]\n): Promise<boolean> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return false;\n }\n\n const { tasks, sourceDesigns } = parseTaskFileData(content, crossRefPatterns);\n\n // AC → implementing task(s)\n const acToTasks = new Map<string, string[]>();\n for (const task of tasks) {\n for (const acId of task.implements) {\n const existing = acToTasks.get(acId) ?? [];\n existing.push(task.id);\n acToTasks.set(acId, existing);\n }\n }\n\n // AC/property → testing task(s)\n const idToTestTasks = new Map<string, string[]>();\n for (const task of tasks) {\n for (const testId of task.tests) {\n const existing = idToTestTasks.get(testId) ?? [];\n existing.push(task.id);\n idToTestTasks.set(testId, existing);\n }\n }\n\n // Collect property IDs from source DESIGN files (to distinguish from ACs in output)\n const sourcePropertyIds = new Set<string>();\n for (const designName of sourceDesigns) {\n const designCode = extractCodeFromFileName(designName);\n for (const sf of specs.specFiles) {\n if (sf.code === designCode && /\\bDESIGN-/.test(basename(sf.filePath))) {\n for (const propId of sf.propertyIds) sourcePropertyIds.add(propId);\n }\n }\n }\n\n // Group ACs and properties by REQ file\n const allIdsForMatrix = [...new Set([...acToTasks.keys(), ...idToTestTasks.keys()])];\n const grouped = groupByReqFile(allIdsForMatrix, reqFileMaps);\n\n const newSection = generateTaskSection(grouped, acToTasks, idToTestTasks, sourcePropertyIds);\n const newContent = replaceTraceabilitySection(content, newSection);\n if (newContent === content) return false;\n\n await writeFile(filePath, newContent, 'utf-8');\n return true;\n}\n\ninterface TaskFileParseResult {\n tasks: TaskInfo[];\n sourceReqs: string[];\n sourceDesigns: string[];\n}\n\nfunction parseTaskFileData(\n content: string,\n crossRefPatterns: readonly string[]\n): TaskFileParseResult {\n const lines = content.split('\\n');\n const tasks: TaskInfo[] = [];\n const sourceReqs: string[] = [];\n const sourceDesigns: string[] = [];\n\n // Parse SOURCE line\n const sourceRegex = /^SOURCE:\\s*(.+)/;\n const taskIdRegex = /^-\\s+\\[[ x]\\]\\s+(T-[A-Z][A-Z0-9]*-\\d+)/;\n\n let currentTaskId: string | null = null;\n\n for (const line of lines) {\n // SOURCE line\n const sourceMatch = sourceRegex.exec(line);\n if (sourceMatch?.[1]) {\n const parts = sourceMatch[1].split(',').map((s) => s.trim());\n for (const part of parts) {\n if (part.startsWith('REQ-')) sourceReqs.push(part);\n else if (part.startsWith('DESIGN-')) sourceDesigns.push(part);\n }\n continue;\n }\n\n // Task checkbox item\n const taskMatch = taskIdRegex.exec(line);\n if (taskMatch?.[1]) {\n currentTaskId = taskMatch[1];\n tasks.push({ id: currentTaskId, implements: [], tests: [] });\n continue;\n }\n\n // H2 heading resets task context (new phase)\n if (/^##\\s/.test(line)) {\n currentTaskId = null;\n continue;\n }\n\n // --- or horizontal rule also resets\n if (/^---/.test(line)) {\n currentTaskId = null;\n continue;\n }\n\n // IMPLEMENTS / TESTS lines (indented under a task)\n if (currentTaskId) {\n const task = tasks.find((t) => t.id === currentTaskId);\n if (task) {\n for (const pattern of crossRefPatterns) {\n const patIdx = line.indexOf(pattern);\n if (patIdx !== -1) {\n const afterPattern = line.slice(patIdx + pattern.length);\n const ids = extractIdsFromText(afterPattern);\n if (ids.length > 0) {\n const isImplements = pattern.toLowerCase().includes('implements');\n if (isImplements) {\n task.implements.push(...ids);\n }\n }\n }\n }\n // TESTS: is not in crossRefPatterns, parse it directly\n const testsIdx = line.indexOf('TESTS:');\n if (testsIdx !== -1) {\n const afterTests = line.slice(testsIdx + 'TESTS:'.length);\n const ids = extractIdsFromText(afterTests);\n if (ids.length > 0) {\n task.tests.push(...ids);\n }\n }\n }\n }\n }\n\n return { tasks, sourceReqs, sourceDesigns };\n}\n\nfunction generateTaskSection(\n grouped: Map<string, string[]>,\n acToTasks: Map<string, string[]>,\n idToTestTasks: Map<string, string[]>,\n propertyIds: Set<string>\n): string {\n const lines: string[] = [];\n const reqFiles = [...grouped.keys()].sort();\n\n for (const reqFile of reqFiles) {\n lines.push(`### ${reqFile}`);\n lines.push('');\n\n const ids = grouped.get(reqFile) ?? [];\n // Separate ACs from properties\n const acIds = ids.filter((id) => !propertyIds.has(id));\n const propIds = ids.filter((id) => propertyIds.has(id));\n\n acIds.sort(compareIds);\n propIds.sort(compareIds);\n\n // AC entries: - {AC-ID} → {Task} ({TestTask})\n for (const acId of acIds) {\n const tasks = acToTasks.get(acId) ?? [];\n const testTasks = idToTestTasks.get(acId) ?? [];\n const taskStr = tasks.length > 0 ? tasks.join(', ') : '(none)';\n const testStr = testTasks.length > 0 ? ` (${testTasks.join(', ')})` : '';\n lines.push(`- ${acId} → ${taskStr}${testStr}`);\n }\n\n // Property entries: - {Prop-ID} → {TestTask}\n for (const propId of propIds) {\n const testTasks = idToTestTasks.get(propId) ?? [];\n const testStr = testTasks.length > 0 ? testTasks.join(', ') : '(none)';\n lines.push(`- ${propId} → ${testStr}`);\n }\n\n lines.push('');\n }\n\n return lines.join('\\n').trimEnd();\n}\n\n// --- Shared utilities ---\n\nfunction groupByReqFile(ids: string[], maps: ReqFileMaps): Map<string, string[]> {\n const groups = new Map<string, string[]>();\n for (const id of ids) {\n const reqFile = resolveReqFile(id, maps);\n if (!reqFile) continue; // Skip IDs we can't resolve to a REQ file\n const existing = groups.get(reqFile) ?? [];\n existing.push(id);\n groups.set(reqFile, existing);\n }\n return groups;\n}\n\nfunction replaceTraceabilitySection(content: string, newSection: string): string {\n const lines = content.split('\\n');\n const sectionStart = lines.findIndex((l) => /^##\\s+Requirements Traceability\\s*$/.test(l));\n\n if (sectionStart === -1) return content;\n\n // Find the next ## heading after the section start\n let sectionEnd = lines.length;\n for (let i = sectionStart + 1; i < lines.length; i++) {\n const line = lines[i];\n if (line !== undefined && /^##\\s/.test(line)) {\n sectionEnd = i;\n break;\n }\n }\n\n const before = lines.slice(0, sectionStart + 1);\n const after = lines.slice(sectionEnd);\n\n const result = [...before, '', newSection.trimEnd(), '', ...after];\n return result.join('\\n');\n}\n\nfunction extractIdsFromText(text: string): string[] {\n const idRegex = /[A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|[A-Z][A-Z0-9]*_P-\\d+/g;\n const ids: string[] = [];\n let match = idRegex.exec(text);\n while (match !== null) {\n ids.push(match[0]);\n match = idRegex.exec(text);\n }\n return ids;\n}\n\nfunction extractCodeFromFileName(fileName: string): string {\n // Extract CODE from REQ-CODE-feature.md or DESIGN-CODE-feature.md\n const match = /^(?:REQ|DESIGN|FEAT|EXAMPLES|API|TASK)-([A-Z][A-Z0-9]*)-/.exec(fileName);\n return match?.[1] ?? '';\n}\n\nfunction compareIds(a: string, b: string): number {\n return a.localeCompare(b, undefined, { numeric: true });\n}\n","// @awa-component: CHK-Reporter\n// @awa-impl: CHK-9_AC-1\n// @awa-impl: CHK-9_AC-2\n// @awa-impl: CHK-9_AC-3\n\nimport chalk from 'chalk';\nimport type { Finding } from './types.js';\n\n// @awa-impl: CHK-9_AC-1\nexport function report(findings: readonly Finding[], format: 'text' | 'json'): void {\n if (format === 'json') {\n reportJson(findings);\n } else {\n reportText(findings);\n }\n}\n\nfunction reportJson(findings: readonly Finding[]): void {\n const errors = findings.filter((f) => f.severity === 'error');\n const warnings = findings.filter((f) => f.severity === 'warning');\n\n const output = {\n valid: errors.length === 0,\n errors: errors.length,\n warnings: warnings.length,\n findings: findings.map((f) => ({\n severity: f.severity,\n code: f.code,\n message: f.message,\n ...(f.filePath ? { filePath: f.filePath } : {}),\n ...(f.line ? { line: f.line } : {}),\n ...(f.id ? { id: f.id } : {}),\n ...(f.ruleSource ? { ruleSource: f.ruleSource } : {}),\n ...(f.rule ? { rule: f.rule } : {}),\n })),\n };\n\n console.log(JSON.stringify(output, null, 2));\n}\n\nfunction reportText(findings: readonly Finding[]): void {\n const errors = findings.filter((f) => f.severity === 'error');\n const warnings = findings.filter((f) => f.severity === 'warning');\n\n if (errors.length > 0) {\n console.log(chalk.red(`\\n${errors.length} error(s):\\n`));\n for (const f of errors) {\n const location = formatLocation(f.filePath, f.line);\n console.log(chalk.red(' ✖'), f.message, location ? chalk.dim(location) : '');\n printRuleContext(f);\n }\n }\n\n if (warnings.length > 0) {\n console.log(chalk.yellow(`\\n${warnings.length} warning(s):\\n`));\n for (const f of warnings) {\n const location = formatLocation(f.filePath, f.line);\n console.log(chalk.yellow(' ⚠'), f.message, location ? chalk.dim(location) : '');\n printRuleContext(f);\n }\n }\n\n if (errors.length === 0 && warnings.length === 0) {\n console.log(chalk.green('\\n✔ Validation passed — no issues found'));\n } else {\n console.log('');\n const parts: string[] = [];\n if (errors.length > 0) parts.push(chalk.red(`${errors.length} error(s)`));\n if (warnings.length > 0) parts.push(chalk.yellow(`${warnings.length} warning(s)`));\n console.log(`Summary: ${parts.join(', ')}`);\n }\n}\n\nfunction formatLocation(filePath?: string, line?: number): string {\n if (!filePath) return '';\n return line ? `(${filePath}:${line})` : `(${filePath})`;\n}\n\nfunction printRuleContext(f: Finding): void {\n if (!f.ruleSource && !f.rule) return;\n const parts: string[] = [];\n if (f.ruleSource) parts.push(f.ruleSource);\n if (f.rule) parts.push(f.rule);\n console.log(chalk.dim(` rule: ${parts.join(' — ')}`));\n}\n","// @awa-component: CHK-RuleLoader\n// @awa-impl: CHK-16_AC-1\n\nimport { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { parse as parseYaml } from 'yaml';\nimport { collectFiles, matchSimpleGlob } from './glob.js';\nimport type {\n CodeBlockContainsRule,\n ContainsRule,\n HeadingOrTextContainsRule,\n ListContainsRule,\n LoadedRuleSet,\n PatternContainsRule,\n RuleFile,\n SectionRule,\n TableContainsRule,\n WhenCondition,\n} from './rule-types.js';\n\n/**\n * Discover and load all *.schema.yaml files from the given schema directory.\n * Parses YAML, validates rule structure, and returns typed rule sets.\n */\nexport async function loadRules(schemaDir: string): Promise<LoadedRuleSet[]> {\n const pattern = join(schemaDir, '*.schema.yaml');\n const files = await collectFiles([pattern], []);\n const results: LoadedRuleSet[] = [];\n\n for (const filePath of files) {\n const ruleSet = await loadRuleFile(filePath);\n if (ruleSet) {\n results.push(ruleSet);\n }\n }\n\n return results;\n}\n\n/**\n * Match spec file paths against a loaded rule set's target-files glob.\n */\nexport function matchesTargetGlob(filePath: string, targetGlob: string): boolean {\n return matchSimpleGlob(filePath, targetGlob);\n}\n\nasync function loadRuleFile(filePath: string): Promise<LoadedRuleSet | null> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return null;\n }\n\n const parsed = parseYaml(content) as unknown;\n if (!parsed || typeof parsed !== 'object') {\n throw new RuleValidationError(`Rule file is not a valid YAML object: ${filePath}`);\n }\n\n const raw = parsed as Record<string, unknown>;\n const ruleFile = validateRuleFile(raw, filePath);\n\n return {\n ruleFile,\n sourcePath: filePath,\n targetGlob: ruleFile['target-files'],\n };\n}\n\nfunction validateRuleFile(raw: Record<string, unknown>, filePath: string): RuleFile {\n // target-files is required\n if (typeof raw['target-files'] !== 'string' || raw['target-files'].length === 0) {\n throw new RuleValidationError(`Missing or empty 'target-files' in ${filePath}`);\n }\n\n // sections is optional (e.g., API rules target non-markdown files)\n let sections: SectionRule[] | undefined;\n if (raw.sections !== undefined) {\n if (!Array.isArray(raw.sections) || raw.sections.length === 0) {\n throw new RuleValidationError(\n `'sections' must be a non-empty array if present in ${filePath}`\n );\n }\n sections = raw.sections.map((s: unknown, i: number) =>\n validateSectionRule(s, `sections[${i}]`, filePath)\n );\n }\n\n // sections-prohibited is optional\n let sectionsProhibited: string[] | undefined;\n if (raw['sections-prohibited'] !== undefined) {\n if (\n !Array.isArray(raw['sections-prohibited']) ||\n !raw['sections-prohibited'].every((v: unknown) => typeof v === 'string')\n ) {\n throw new RuleValidationError(`'sections-prohibited' must be a string array in ${filePath}`);\n }\n sectionsProhibited = raw['sections-prohibited'] as string[];\n }\n\n return {\n 'target-files': raw['target-files'] as string,\n ...(typeof raw.description === 'string' ? { description: raw.description } : {}),\n ...(typeof raw['line-limit'] === 'number' && raw['line-limit'] > 0\n ? { 'line-limit': raw['line-limit'] }\n : {}),\n sections: sections ?? [],\n ...(sectionsProhibited ? { 'sections-prohibited': sectionsProhibited } : {}),\n ...(typeof raw.example === 'string' ? { example: raw.example } : {}),\n };\n}\n\nfunction validateSectionRule(raw: unknown, path: string, filePath: string): SectionRule {\n if (!raw || typeof raw !== 'object') {\n throw new RuleValidationError(`${path} must be an object in ${filePath}`);\n }\n\n const section = raw as Record<string, unknown>;\n\n if (typeof section.heading !== 'string' || section.heading.length === 0) {\n throw new RuleValidationError(`${path}.heading must be a non-empty string in ${filePath}`);\n }\n\n if (typeof section.level !== 'number' || section.level < 1 || section.level > 6) {\n throw new RuleValidationError(`${path}.level must be 1-6 in ${filePath}`);\n }\n\n // Validate heading as regex if it looks like a pattern\n validatePattern(section.heading as string, `${path}.heading`, filePath);\n\n // Validate optional contains rules\n let contains: ContainsRule[] | undefined;\n if (section.contains !== undefined) {\n if (!Array.isArray(section.contains)) {\n throw new RuleValidationError(`${path}.contains must be an array in ${filePath}`);\n }\n contains = section.contains.map((c: unknown, i: number) =>\n validateContainsRule(c, `${path}.contains[${i}]`, filePath)\n );\n }\n\n // Validate optional children rules\n let children: SectionRule[] | undefined;\n if (section.children !== undefined) {\n if (!Array.isArray(section.children)) {\n throw new RuleValidationError(`${path}.children must be an array in ${filePath}`);\n }\n children = section.children.map((c: unknown, i: number) =>\n validateSectionRule(c, `${path}.children[${i}]`, filePath)\n );\n }\n\n return {\n heading: section.heading as string,\n level: section.level as number,\n ...(typeof section.required === 'boolean' ? { required: section.required } : {}),\n ...(typeof section.repeatable === 'boolean' ? { repeatable: section.repeatable } : {}),\n ...(typeof section.description === 'string' ? { description: section.description } : {}),\n ...(contains ? { contains } : {}),\n ...(children ? { children } : {}),\n };\n}\n\nfunction validateContainsRule(raw: unknown, path: string, filePath: string): ContainsRule {\n if (!raw || typeof raw !== 'object') {\n throw new RuleValidationError(`${path} must be an object in ${filePath}`);\n }\n\n const rule = raw as Record<string, unknown>;\n\n // Parse optional 'when' condition (applicable to all rule types)\n const when =\n rule.when !== undefined\n ? validateWhenCondition(rule.when, `${path}.when`, filePath)\n : undefined;\n\n // Pattern rule\n if (typeof rule.pattern === 'string') {\n validatePattern(rule.pattern, `${path}.pattern`, filePath);\n return {\n pattern: rule.pattern,\n ...(typeof rule.label === 'string' ? { label: rule.label } : {}),\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(typeof rule.required === 'boolean' ? { required: rule.required } : {}),\n ...(typeof rule.prohibited === 'boolean' ? { prohibited: rule.prohibited } : {}),\n ...(when ? { when } : {}),\n } satisfies PatternContainsRule;\n }\n\n // List rule\n if (rule.list && typeof rule.list === 'object') {\n const list = rule.list as Record<string, unknown>;\n if (typeof list.pattern !== 'string') {\n throw new RuleValidationError(`${path}.list.pattern must be a string in ${filePath}`);\n }\n validatePattern(list.pattern, `${path}.list.pattern`, filePath);\n return {\n list: {\n pattern: list.pattern,\n ...(typeof list.min === 'number' ? { min: list.min } : {}),\n ...(typeof list.label === 'string' ? { label: list.label } : {}),\n },\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies ListContainsRule;\n }\n\n // Table rule\n if (rule.table && typeof rule.table === 'object') {\n const table = rule.table as Record<string, unknown>;\n if (\n !Array.isArray(table.columns) ||\n !table.columns.every((c: unknown) => typeof c === 'string')\n ) {\n throw new RuleValidationError(`${path}.table.columns must be a string array in ${filePath}`);\n }\n return {\n table: {\n ...(typeof table.heading === 'string' ? { heading: table.heading } : {}),\n columns: table.columns as string[],\n ...(typeof table['min-rows'] === 'number' ? { 'min-rows': table['min-rows'] } : {}),\n },\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies TableContainsRule;\n }\n\n // Code block rule\n if (rule['code-block'] === true) {\n return {\n 'code-block': true,\n ...(typeof rule.label === 'string' ? { label: rule.label } : {}),\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies CodeBlockContainsRule;\n }\n\n // Heading-or-text rule\n if (typeof rule['heading-or-text'] === 'string') {\n return {\n 'heading-or-text': rule['heading-or-text'],\n ...(typeof rule.required === 'boolean' ? { required: rule.required } : {}),\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies HeadingOrTextContainsRule;\n }\n\n throw new RuleValidationError(`${path} has no recognized rule type in ${filePath}`);\n}\n\nfunction validateWhenCondition(raw: unknown, path: string, filePath: string): WhenCondition {\n if (!raw || typeof raw !== 'object') {\n throw new RuleValidationError(`${path} must be an object in ${filePath}`);\n }\n\n const condition = raw as Record<string, unknown>;\n const result: Record<string, string> = {};\n\n if (typeof condition['heading-matches'] === 'string') {\n validatePattern(condition['heading-matches'], `${path}.heading-matches`, filePath);\n result['heading-matches'] = condition['heading-matches'];\n }\n\n if (typeof condition['heading-not-matches'] === 'string') {\n validatePattern(condition['heading-not-matches'], `${path}.heading-not-matches`, filePath);\n result['heading-not-matches'] = condition['heading-not-matches'];\n }\n\n if (!result['heading-matches'] && !result['heading-not-matches']) {\n throw new RuleValidationError(\n `${path} must have 'heading-matches' or 'heading-not-matches' in ${filePath}`\n );\n }\n\n return result as unknown as WhenCondition;\n}\n\nfunction validatePattern(pattern: string, path: string, filePath: string): void {\n // Only validate if it looks like a regex (contains regex special chars)\n if (/[.+*?^${}()|[\\]\\\\]/.test(pattern)) {\n try {\n new RegExp(pattern);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new RuleValidationError(`Invalid regex in ${path}: ${msg} (${filePath})`);\n }\n }\n}\n\nexport class RuleValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'RuleValidationError';\n }\n}\n","// @awa-component: CHK-SchemaChecker\n// @awa-impl: CHK-2_AC-1\n\nimport { readFile } from 'node:fs/promises';\nimport type { Code, Heading, List, PhrasingContent, Root, Table, TableRow } from 'mdast';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport { unified } from 'unified';\nimport { matchesTargetGlob } from './rule-loader.js';\nimport type {\n CodeBlockContainsRule,\n ContainsRule,\n HeadingOrTextContainsRule,\n ListContainsRule,\n LoadedRuleSet,\n PatternContainsRule,\n SectionRule,\n TableContainsRule,\n WhenCondition,\n} from './rule-types.js';\nimport type { CheckResult, Finding, SpecFile } from './types.js';\n\n// --- Rule formatting helpers ---\n\nfunction formatSectionRule(rule: SectionRule): string {\n const parts = [`section: heading=\"${rule.heading}\" level=${rule.level}`];\n if (rule.required) parts.push('required');\n if (rule.repeatable) parts.push('repeatable');\n return parts.join(' ');\n}\n\nfunction formatContainsRule(rule: ContainsRule): string {\n if ('pattern' in rule && typeof rule.pattern === 'string') {\n const r = rule as PatternContainsRule;\n if (r.prohibited) return `contains: prohibited pattern=\"${r.pattern}\"`;\n return `contains: pattern=\"${r.pattern}\"${r.required === false ? '' : ' required'}`;\n }\n if ('list' in rule) {\n const r = rule as ListContainsRule;\n return `contains: list pattern=\"${r.list.pattern}\"${r.list.min !== undefined ? ` min=${r.list.min}` : ''}`;\n }\n if ('table' in rule) {\n const r = rule as TableContainsRule;\n return `contains: table columns=[${r.table.columns.join(', ')}]${r.table['min-rows'] !== undefined ? ` min-rows=${r.table['min-rows']}` : ''}`;\n }\n if ('code-block' in rule) {\n return 'contains: code-block';\n }\n if ('heading-or-text' in rule) {\n const r = rule as HeadingOrTextContainsRule;\n return `contains: heading-or-text=\"${r['heading-or-text']}\"`;\n }\n return 'contains: (unknown rule)';\n}\n\nfunction formatLineLimitRule(limit: number): string {\n return `line-limit: ${limit}`;\n}\n\nfunction formatProhibitedRule(pattern: string): string {\n return `sections-prohibited: \"${pattern}\"`;\n}\n\n/** A section with heading info and all AST nodes belonging to it. */\ninterface SectionNode {\n readonly heading: Heading;\n readonly headingText: string;\n readonly level: number;\n readonly children: SectionNode[];\n readonly contentNodes: Root['children'];\n}\n\n/**\n * Check all spec files against loaded rule sets.\n * Reads file content, parses to mdast, walks AST checking rules.\n */\nexport async function checkSchemasAsync(\n specFiles: readonly SpecFile[],\n ruleSets: readonly LoadedRuleSet[]\n): Promise<CheckResult> {\n const findings: Finding[] = [];\n const parser = unified().use(remarkParse).use(remarkGfm);\n\n for (const spec of specFiles) {\n const matchingRules = ruleSets.filter((rs) => matchesTargetGlob(spec.filePath, rs.targetGlob));\n if (matchingRules.length === 0) continue;\n\n let content: string;\n try {\n content = await readFile(spec.filePath, 'utf-8');\n } catch {\n continue;\n }\n\n const tree = parser.parse(content);\n const sectionTree = buildSectionTree(tree);\n const allSections = flattenSections(sectionTree);\n\n for (const ruleSet of matchingRules) {\n const ruleSource = ruleSet.sourcePath;\n\n // Check line limit if defined\n if (ruleSet.ruleFile['line-limit'] !== undefined) {\n const lineCount = content.split('\\n').length;\n if (lineCount > ruleSet.ruleFile['line-limit']) {\n findings.push({\n severity: 'warning',\n code: 'schema-line-limit',\n message: `File has ${lineCount} lines, exceeds limit of ${ruleSet.ruleFile['line-limit']}`,\n filePath: spec.filePath,\n ruleSource,\n rule: formatLineLimitRule(ruleSet.ruleFile['line-limit']),\n });\n }\n }\n\n findings.push(\n ...checkRulesAgainstSections(\n allSections,\n ruleSet.ruleFile.sections,\n spec.filePath,\n ruleSource\n )\n );\n\n if (ruleSet.ruleFile['sections-prohibited']) {\n findings.push(\n ...checkProhibited(\n content,\n ruleSet.ruleFile['sections-prohibited'],\n spec.filePath,\n ruleSource\n )\n );\n }\n }\n }\n\n return { findings };\n}\n\n// --- Section tree building ---\n\nfunction buildSectionTree(tree: Root): SectionNode[] {\n return buildSectionsFromNodes(tree.children, 0, 0).sections;\n}\n\nfunction buildSectionsFromNodes(\n nodes: Root['children'],\n start: number,\n parentLevel: number\n): { sections: SectionNode[]; nextIndex: number } {\n const sections: SectionNode[] = [];\n let i = start;\n\n while (i < nodes.length) {\n const node = nodes[i];\n if (!node) break;\n if (node.type === 'heading') {\n const h = node as Heading;\n if (parentLevel > 0 && h.depth <= parentLevel) break;\n\n const headingText = extractText(h.children);\n const contentNodes: Root['children'] = [];\n i++;\n\n // Collect content until next heading of same-or-higher level\n while (i < nodes.length) {\n const next = nodes[i];\n if (!next || next.type === 'heading') break;\n contentNodes.push(next);\n i++;\n }\n\n // Collect child headings (deeper level)\n const childResult = buildSectionsFromNodes(nodes, i, h.depth);\n i = childResult.nextIndex;\n\n sections.push({\n heading: h,\n headingText,\n level: h.depth,\n children: childResult.sections,\n contentNodes,\n });\n } else {\n i++;\n }\n }\n\n return { sections, nextIndex: i };\n}\n\nfunction flattenSections(sections: SectionNode[]): SectionNode[] {\n const result: SectionNode[] = [];\n for (const s of sections) {\n result.push(s);\n result.push(...flattenSections(s.children));\n }\n return result;\n}\n\nfunction extractText(children: PhrasingContent[]): string {\n return children\n .map((c) => {\n if ('value' in c) return c.value;\n if ('children' in c) return extractText(c.children as PhrasingContent[]);\n return '';\n })\n .join('');\n}\n\n// --- Rule checking ---\n\n/**\n * Top-level rules match against the flattened view of all sections.\n * `children` sub-rules match only within the matched section's children.\n */\nfunction checkRulesAgainstSections(\n allSections: SectionNode[],\n rules: readonly SectionRule[],\n filePath: string,\n ruleSource: string\n): Finding[] {\n const findings: Finding[] = [];\n\n for (const rule of rules) {\n const matches = findMatchingSections(allSections, rule);\n\n if (matches.length === 0 && rule.required) {\n findings.push({\n severity: 'error',\n code: 'schema-missing-section',\n message: `Missing required section: '${rule.heading}' (level ${rule.level})`,\n filePath,\n ruleSource,\n rule: formatSectionRule(rule),\n });\n continue;\n }\n\n for (const match of matches) {\n if (match.level !== rule.level) {\n findings.push({\n severity: 'warning',\n code: 'schema-wrong-level',\n message: `Section '${match.headingText}' is level ${match.level}, expected ${rule.level}`,\n filePath,\n line: match.heading.position?.start.line,\n ruleSource,\n rule: formatSectionRule(rule),\n });\n }\n\n if (rule.contains) {\n for (const cr of rule.contains) {\n findings.push(...checkContainsRule(match, cr, filePath, ruleSource));\n }\n }\n\n if (rule.children) {\n const childFlat = flattenSections(match.children);\n findings.push(...checkRulesAgainstSections(childFlat, rule.children, filePath, ruleSource));\n }\n }\n }\n\n return findings;\n}\n\nfunction findMatchingSections(allSections: SectionNode[], rule: SectionRule): SectionNode[] {\n const regex = createHeadingRegex(rule.heading);\n const matches = allSections.filter((s) => s.level === rule.level && regex.test(s.headingText));\n\n if (!rule.repeatable && matches.length > 1) {\n return [matches[0] as SectionNode];\n }\n return matches;\n}\n\nfunction createHeadingRegex(pattern: string): RegExp {\n if (/[.+*?^${}()|[\\]\\\\]/.test(pattern)) {\n try {\n return new RegExp(`^${pattern}$`);\n } catch {\n return new RegExp(`^${escapeRegex(pattern)}$`);\n }\n }\n return new RegExp(`^${escapeRegex(pattern)}$`, 'i');\n}\n\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n// --- Contains rule dispatching ---\n\nfunction checkContainsRule(\n section: SectionNode,\n rule: ContainsRule,\n filePath: string,\n ruleSource: string\n): Finding[] {\n // Evaluate 'when' condition gate — skip rule if condition not met\n const when = 'when' in rule ? (rule as { when?: WhenCondition }).when : undefined;\n if (when && !evaluateWhenCondition(when, section.headingText)) {\n return [];\n }\n\n const formattedRule = formatContainsRule(rule);\n\n if ('pattern' in rule && typeof rule.pattern === 'string') {\n return checkPatternContains(\n section,\n rule as PatternContainsRule,\n filePath,\n ruleSource,\n formattedRule\n );\n }\n if ('list' in rule) {\n return checkListContains(\n section,\n rule as ListContainsRule,\n filePath,\n ruleSource,\n formattedRule\n );\n }\n if ('table' in rule) {\n return checkTableContains(\n section,\n rule as TableContainsRule,\n filePath,\n ruleSource,\n formattedRule\n );\n }\n if ('code-block' in rule) {\n return checkCodeBlockContains(\n section,\n rule as CodeBlockContainsRule,\n filePath,\n ruleSource,\n formattedRule\n );\n }\n if ('heading-or-text' in rule) {\n return checkHeadingOrText(\n section,\n rule as HeadingOrTextContainsRule,\n filePath,\n ruleSource,\n formattedRule\n );\n }\n return [];\n}\n\nfunction checkPatternContains(\n section: SectionNode,\n rule: PatternContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string\n): Finding[] {\n const text = getFullSectionText(section);\n const found = new RegExp(rule.pattern, 'm').test(text);\n\n // Prohibited mode: pattern must NOT appear\n if (rule.prohibited) {\n if (found) {\n return [\n {\n severity: 'warning',\n code: 'schema-prohibited',\n message: `Section '${section.headingText}' contains prohibited content: ${rule.label ?? rule.pattern}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n }\n\n // Normal mode: pattern must appear\n if (found) return [];\n\n if (rule.required !== false) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required content: ${rule.label ?? rule.pattern}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n}\n\nfunction checkListContains(\n section: SectionNode,\n rule: ListContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string\n): Finding[] {\n const items = collectAllListItems(section);\n const regex = new RegExp(rule.list.pattern);\n const count = items.filter((item) => regex.test(item)).length;\n\n if (rule.list.min !== undefined && count < rule.list.min) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' has ${count} matching ${rule.list.label ?? 'list items'}, expected at least ${rule.list.min}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n}\n\nfunction checkTableContains(\n section: SectionNode,\n rule: TableContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string\n): Finding[] {\n const tables = collectAllTables(section);\n\n if (tables.length === 0) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required table${rule.table.heading ? ` (${rule.table.heading})` : ''}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n\n // Find the first table whose columns match the rule. If none match, report\n // the column mismatch for the first table. This avoids false positives when a\n // section contains multiple tables with different column sets.\n let matched: Table | undefined;\n let firstMismatch: { table: Table; headers: string[] } | undefined;\n\n for (const table of tables) {\n const headerRow = table.children[0] as TableRow | undefined;\n if (!headerRow) continue;\n\n const headers = headerRow.children.map((cell) =>\n extractText(cell.children as PhrasingContent[]).trim()\n );\n\n if (rule.table.columns.every((col) => headers.includes(col))) {\n matched = table;\n break;\n }\n if (!firstMismatch) {\n firstMismatch = { table, headers };\n }\n }\n\n if (!matched) {\n const mm = firstMismatch;\n return [\n {\n severity: 'error',\n code: 'schema-table-columns',\n message: `No table in '${section.headingText}' has columns [${rule.table.columns.join(', ')}]${mm ? `, found [${mm.headers.join(', ')}]` : ''}`,\n filePath,\n line: mm?.table.position?.start.line ?? section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n\n const findings: Finding[] = [];\n const dataRows = matched.children.length - 1;\n if (rule.table['min-rows'] !== undefined && dataRows < rule.table['min-rows']) {\n findings.push({\n severity: 'error',\n code: 'schema-missing-content',\n message: `Table in '${section.headingText}' has ${dataRows} data rows, expected at least ${rule.table['min-rows']}`,\n filePath,\n line: matched.position?.start.line,\n ruleSource,\n rule: formattedRule,\n });\n }\n return findings;\n}\n\nfunction checkCodeBlockContains(\n section: SectionNode,\n rule: CodeBlockContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string\n): Finding[] {\n if (collectAllCodeBlocks(section).length > 0) return [];\n\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required ${rule.label ?? 'code block'}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n}\n\nfunction checkHeadingOrText(\n section: SectionNode,\n rule: HeadingOrTextContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string\n): Finding[] {\n const needle = rule['heading-or-text'].toUpperCase();\n\n if (section.children.some((c) => c.headingText.toUpperCase().includes(needle))) return [];\n if (getFullSectionText(section).toUpperCase().includes(needle)) return [];\n\n if (rule.required !== false) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required heading or text: '${rule['heading-or-text']}'`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n}\n\n// --- When condition evaluation ---\n\nfunction evaluateWhenCondition(when: WhenCondition, headingText: string): boolean {\n if (when['heading-matches']) {\n if (!new RegExp(when['heading-matches']).test(headingText)) return false;\n }\n if (when['heading-not-matches']) {\n if (new RegExp(when['heading-not-matches']).test(headingText)) return false;\n }\n return true;\n}\n\n// --- Prohibited patterns ---\n\nfunction checkProhibited(\n content: string,\n prohibited: readonly string[],\n filePath: string,\n ruleSource: string\n): Finding[] {\n const findings: Finding[] = [];\n const lines = content.split('\\n');\n\n for (const pattern of prohibited) {\n const regex = new RegExp(escapeRegex(pattern));\n let inCodeBlock = false;\n\n for (const [i, line] of lines.entries()) {\n if (line.startsWith('```')) {\n inCodeBlock = !inCodeBlock;\n continue;\n }\n if (inCodeBlock) continue;\n\n if (regex.test(line)) {\n findings.push({\n severity: 'warning',\n code: 'schema-prohibited',\n message: `Prohibited formatting '${pattern}' found`,\n filePath,\n line: i + 1,\n ruleSource,\n rule: formatProhibitedRule(pattern),\n });\n break;\n }\n }\n }\n return findings;\n}\n\n// --- Content extraction helpers ---\n\nfunction getFullSectionText(section: SectionNode): string {\n let text = section.contentNodes.map(nodeToText).join('\\n');\n for (const child of section.children) {\n text += `\\n${child.headingText}\\n${getFullSectionText(child)}`;\n }\n return text;\n}\n\nfunction nodeToText(node: Root['children'][number]): string {\n if ('value' in node) return node.value as string;\n if ('children' in node) {\n return (node.children as Root['children'])\n .map((c) => nodeToText(c as Root['children'][number]))\n .join('');\n }\n return '';\n}\n\nfunction extractListItems(nodes: Root['children']): string[] {\n const items: string[] = [];\n for (const node of nodes) {\n if (node.type === 'list') {\n for (const item of (node as List).children) {\n const raw = nodeToText(item as unknown as Root['children'][number]);\n // remark-gfm stores checkbox state as a `checked` property on the listItem\n // rather than preserving the literal [ ] / [x] text. Reconstruct it for\n // rules that match checkbox syntax (e.g. \\[ \\] T-CODE-nnn).\n const li = item as { checked?: boolean | null };\n if (li.checked === true) {\n items.push(`[x] ${raw}`);\n } else if (li.checked === false) {\n items.push(`[ ] ${raw}`);\n } else {\n items.push(raw);\n }\n }\n }\n }\n return items;\n}\n\nfunction collectAllListItems(section: SectionNode): string[] {\n const items = extractListItems(section.contentNodes);\n for (const child of section.children) items.push(...collectAllListItems(child));\n return items;\n}\n\nfunction collectAllTables(section: SectionNode): Table[] {\n const tables = section.contentNodes.filter((n) => n.type === 'table') as Table[];\n for (const child of section.children) tables.push(...collectAllTables(child));\n return tables;\n}\n\nfunction collectAllCodeBlocks(section: SectionNode): Code[] {\n const blocks = section.contentNodes.filter((n) => n.type === 'code') as Code[];\n for (const child of section.children) blocks.push(...collectAllCodeBlocks(child));\n return blocks;\n}\n","// @awa-component: CHK-SpecParser\n// @awa-impl: CHK-2_AC-1\n// @awa-impl: CHK-12_AC-1\n\nimport { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport { collectFiles } from './glob.js';\nimport type { CheckConfig, CrossReference, SpecFile, SpecParseResult } from './types.js';\n\n// @awa-impl: CHK-2_AC-1\nexport async function parseSpecs(config: CheckConfig): Promise<SpecParseResult> {\n const files = await collectSpecFiles(config.specGlobs, config.specIgnore);\n const specFiles: SpecFile[] = [];\n\n const requirementIds = new Set<string>();\n const acIds = new Set<string>();\n const propertyIds = new Set<string>();\n const componentNames = new Set<string>();\n const idLocations = new Map<string, { filePath: string; line: number }>();\n\n for (const filePath of files) {\n const specFile = await parseSpecFile(filePath, config.crossRefPatterns);\n if (specFile) {\n specFiles.push(specFile);\n for (const id of specFile.requirementIds) requirementIds.add(id);\n for (const id of specFile.acIds) acIds.add(id);\n for (const id of specFile.propertyIds) propertyIds.add(id);\n for (const name of specFile.componentNames) componentNames.add(name);\n // Merge id locations from parsed spec file\n for (const [id, loc] of specFile.idLocations ?? []) {\n idLocations.set(id, loc);\n }\n }\n }\n\n const allIds = new Set<string>([...requirementIds, ...acIds, ...propertyIds, ...componentNames]);\n\n return { requirementIds, acIds, propertyIds, componentNames, allIds, specFiles, idLocations };\n}\n\nasync function parseSpecFile(\n filePath: string,\n crossRefPatterns: readonly string[]\n): Promise<SpecFile | null> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return null;\n }\n\n const code = extractCodePrefix(filePath);\n const lines = content.split('\\n');\n\n const requirementIds: string[] = [];\n const acIds: string[] = [];\n const propertyIds: string[] = [];\n const componentNames: string[] = [];\n const crossRefs: CrossReference[] = [];\n const idLocations = new Map<string, { filePath: string; line: number }>();\n const componentImplements = new Map<string, string[]>();\n\n // Requirement ID: ### CODE-N: Title or ### CODE-N.P: Title\n const reqIdRegex = /^###\\s+([A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?)\\s*:/;\n // AC ID: - CODE-N_AC-M or - [ ] CODE-N_AC-M or - [x] CODE-N.P_AC-M\n const acIdRegex = /^-\\s+(?:\\[[ x]\\]\\s+)?([A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?_AC-\\d+)\\s/;\n // Property ID: - CODE_P-N [Name]\n const propIdRegex = /^-\\s+([A-Z][A-Z0-9]*_P-\\d+)\\s/;\n // Component name: ### CODE-ComponentName\n const componentRegex = /^###\\s+([A-Z][A-Z0-9]*-[A-Za-z][A-Za-z0-9]*(?:[A-Z][a-z0-9]*)*)\\s*$/;\n\n // Track current component for building componentImplements map\n let currentComponent: string | null = null;\n\n for (const [i, line] of lines.entries()) {\n const lineNum = i + 1;\n\n // Requirement IDs\n const reqMatch = reqIdRegex.exec(line);\n if (reqMatch?.[1]) {\n requirementIds.push(reqMatch[1]);\n idLocations.set(reqMatch[1], { filePath, line: lineNum });\n }\n\n // AC IDs\n const acMatch = acIdRegex.exec(line);\n if (acMatch?.[1]) {\n acIds.push(acMatch[1]);\n idLocations.set(acMatch[1], { filePath, line: lineNum });\n }\n\n // Property IDs\n const propMatch = propIdRegex.exec(line);\n if (propMatch?.[1]) {\n propertyIds.push(propMatch[1]);\n idLocations.set(propMatch[1], { filePath, line: lineNum });\n }\n\n // Component names (from DESIGN files)\n const compMatch = componentRegex.exec(line);\n if (compMatch?.[1]) {\n // Only count as component if it doesn't match requirement pattern\n if (!reqIdRegex.test(line)) {\n componentNames.push(compMatch[1]);\n idLocations.set(compMatch[1], { filePath, line: lineNum });\n currentComponent = compMatch[1];\n }\n }\n\n // Any H2 or H1 heading resets the current component context\n if (/^#{1,2}\\s/.test(line) && !compMatch) {\n currentComponent = null;\n }\n\n // Cross-references (IMPLEMENTS:, VALIDATES:)\n for (const pattern of crossRefPatterns) {\n const patIdx = line.indexOf(pattern);\n if (patIdx !== -1) {\n const afterPattern = line.slice(patIdx + pattern.length);\n const ids = extractIdsFromText(afterPattern);\n if (ids.length > 0) {\n const type = pattern.toLowerCase().includes('implements') ? 'implements' : 'validates';\n crossRefs.push({ type, ids, filePath, line: i + 1 });\n\n // Build componentImplements map for IMPLEMENTS lines\n if (type === 'implements' && currentComponent) {\n const existing = componentImplements.get(currentComponent) ?? [];\n existing.push(...ids);\n componentImplements.set(currentComponent, existing);\n }\n }\n }\n }\n }\n\n return {\n filePath,\n code,\n requirementIds,\n acIds,\n propertyIds,\n componentNames,\n crossRefs,\n idLocations,\n componentImplements,\n };\n}\n\nfunction extractCodePrefix(filePath: string): string {\n const name = basename(filePath, '.md');\n // Extract CODE from patterns like REQ-CODE-feature, DESIGN-CODE-feature, FEAT-CODE-feature\n const match = /^(?:REQ|DESIGN|FEAT|EXAMPLES|API)-([A-Z][A-Z0-9]*)-/.exec(name);\n if (match?.[1]) return match[1];\n // Fallback: ARCHITECTURE.md has no code prefix\n return '';\n}\n\nfunction extractIdsFromText(text: string): string[] {\n const idRegex = /[A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|[A-Z][A-Z0-9]*_P-\\d+/g;\n const ids: string[] = [];\n let match = idRegex.exec(text);\n while (match !== null) {\n ids.push(match[0]);\n match = idRegex.exec(text);\n }\n return ids;\n}\n\n// @awa-impl: CHK-12_AC-1\nasync function collectSpecFiles(\n specGlobs: readonly string[],\n ignore: readonly string[]\n): Promise<string[]> {\n return collectFiles(specGlobs, ignore);\n}\n","// @awa-component: CHK-SpecSpecChecker\n// @awa-impl: CHK-5_AC-1\n// @awa-impl: CHK-7_AC-1\n// @awa-impl: CHK-15_AC-1\n// @awa-impl: CHK-21_AC-1\n\nimport type {\n CheckConfig,\n CheckResult,\n Finding,\n MarkerScanResult,\n SpecParseResult,\n} from './types.js';\n\n// @awa-impl: CHK-5_AC-1, CHK-7_AC-1, CHK-21_AC-1\nexport function checkSpecAgainstSpec(\n specs: SpecParseResult,\n markers: MarkerScanResult,\n config: CheckConfig\n): CheckResult {\n const findings: Finding[] = [];\n\n // @awa-impl: CHK-5_AC-1\n // Check cross-references resolve to real IDs\n for (const specFile of specs.specFiles) {\n for (const crossRef of specFile.crossRefs) {\n for (const refId of crossRef.ids) {\n if (!specs.allIds.has(refId)) {\n findings.push({\n severity: 'error',\n code: 'broken-cross-ref',\n message: `Cross-reference '${refId}' (${crossRef.type}) not found in any spec file`,\n filePath: crossRef.filePath,\n line: crossRef.line,\n id: refId,\n });\n }\n }\n }\n }\n\n // @awa-impl: CHK-21_AC-1\n // G3: Check that every REQ AC is claimed by at least one DESIGN IMPLEMENTS\n const implementedAcIds = new Set<string>();\n for (const specFile of specs.specFiles) {\n for (const crossRef of specFile.crossRefs) {\n if (crossRef.type === 'implements') {\n for (const id of crossRef.ids) {\n implementedAcIds.add(id);\n }\n }\n }\n }\n\n // Only check ACs that come from REQ files (not DESIGN/TASK/etc.)\n const reqAcIds = new Set<string>();\n for (const specFile of specs.specFiles) {\n if (/\\bREQ-/.test(specFile.filePath)) {\n for (const acId of specFile.acIds) {\n reqAcIds.add(acId);\n }\n }\n }\n\n for (const acId of reqAcIds) {\n if (!implementedAcIds.has(acId)) {\n const loc = specs.idLocations.get(acId);\n findings.push({\n severity: 'error',\n code: 'unlinked-ac',\n message: `Acceptance criterion '${acId}' is not claimed by any DESIGN IMPLEMENTS`,\n filePath: loc?.filePath,\n line: loc?.line,\n id: acId,\n });\n }\n }\n\n // @awa-impl: CHK-7_AC-1\n // Check for orphaned spec files (CODE not referenced by any other spec or code)\n // Skip when specOnly — orphaned-spec detection depends on code markers to be meaningful\n if (!config.specOnly) {\n const referencedCodes = new Set<string>();\n\n // Collect codes referenced in code markers\n for (const marker of markers.markers) {\n const codeMatch = /^([A-Z][A-Z0-9]*)[-_]/.exec(marker.id);\n if (codeMatch?.[1]) {\n referencedCodes.add(codeMatch[1]);\n }\n }\n\n // Collect codes referenced in cross-references\n for (const specFile of specs.specFiles) {\n for (const crossRef of specFile.crossRefs) {\n for (const refId of crossRef.ids) {\n const codeMatch = /^([A-Z][A-Z0-9]*)[-_]/.exec(refId);\n if (codeMatch?.[1]) {\n referencedCodes.add(codeMatch[1]);\n }\n }\n }\n }\n\n for (const specFile of specs.specFiles) {\n if (!specFile.code) continue; // Skip ARCHITECTURE.md etc.\n if (!referencedCodes.has(specFile.code)) {\n findings.push({\n severity: 'warning',\n code: 'orphaned-spec',\n message: `Spec file code '${specFile.code}' is not referenced by any other spec or code marker`,\n filePath: specFile.filePath,\n id: specFile.code,\n });\n }\n }\n }\n\n return { findings };\n}\n","// @awa-component: CHK-CheckCommand\n\n// @awa-impl: CHK-16_AC-1\nexport interface CheckConfig {\n readonly specGlobs: readonly string[];\n readonly codeGlobs: readonly string[];\n readonly specIgnore: readonly string[];\n readonly codeIgnore: readonly string[];\n readonly ignoreMarkers: readonly string[];\n readonly markers: readonly string[];\n readonly idPattern: string;\n readonly crossRefPatterns: readonly string[];\n readonly format: 'text' | 'json';\n readonly schemaDir: string;\n readonly schemaEnabled: boolean;\n readonly allowWarnings: boolean;\n readonly specOnly: boolean;\n readonly fix: boolean;\n}\n\nexport const DEFAULT_CHECK_CONFIG: CheckConfig = {\n specGlobs: [\n '.awa/specs/ARCHITECTURE.md',\n '.awa/specs/FEAT-*.md',\n '.awa/specs/REQ-*.md',\n '.awa/specs/DESIGN-*.md',\n '.awa/specs/EXAMPLES-*.md',\n '.awa/specs/API-*.tsp',\n '.awa/tasks/TASK-*.md',\n '.awa/plans/PLAN-*.md',\n '.awa/align/ALIGN-*.md',\n ],\n codeGlobs: [\n '**/*.{ts,js,tsx,jsx,mts,mjs,cjs,py,go,rs,java,kt,kts,cs,c,h,cpp,cc,cxx,hpp,hxx,swift,rb,php,scala,ex,exs,dart,lua,zig}',\n ],\n specIgnore: [],\n codeIgnore: [\n 'node_modules/**',\n 'dist/**',\n 'vendor/**',\n 'target/**',\n 'build/**',\n 'out/**',\n '.awa/**',\n ],\n ignoreMarkers: [],\n markers: ['@awa-impl', '@awa-test', '@awa-component'],\n idPattern: '([A-Z][A-Z0-9]*-\\\\d+(?:\\\\.\\\\d+)?(?:_AC-\\\\d+)?|[A-Z][A-Z0-9]*_P-\\\\d+)',\n crossRefPatterns: ['IMPLEMENTS:', 'VALIDATES:'],\n format: 'text',\n schemaDir: '.awa/.agent/schemas',\n schemaEnabled: true,\n allowWarnings: false,\n specOnly: false,\n fix: true,\n};\n\nexport type FindingSeverity = 'error' | 'warning';\n\nexport type FindingCode =\n | 'orphaned-marker'\n | 'uncovered-ac'\n | 'uncovered-component'\n | 'uncovered-property'\n | 'unimplemented-ac'\n | 'unlinked-ac'\n | 'impl-not-in-implements'\n | 'implements-not-in-impl'\n | 'broken-cross-ref'\n | 'invalid-id-format'\n | 'marker-trailing-text'\n | 'orphaned-spec'\n | 'schema-missing-section'\n | 'schema-wrong-level'\n | 'schema-missing-content'\n | 'schema-table-columns'\n | 'schema-prohibited'\n | 'schema-no-rule'\n | 'schema-line-limit';\n\nexport interface Finding {\n readonly severity: FindingSeverity;\n readonly code: FindingCode;\n readonly message: string;\n readonly filePath?: string;\n readonly line?: number;\n readonly id?: string;\n /** Path to the .schema.yaml file that defines the violated rule. */\n readonly ruleSource?: string;\n /** Concise representation of the violated rule. */\n readonly rule?: string;\n}\n\nexport type MarkerType = 'impl' | 'test' | 'component';\n\nexport interface CodeMarker {\n readonly type: MarkerType;\n readonly id: string;\n readonly filePath: string;\n readonly line: number;\n}\n\nexport interface MarkerScanResult {\n readonly markers: readonly CodeMarker[];\n readonly findings: readonly Finding[];\n}\n\nexport interface CrossReference {\n readonly type: 'implements' | 'validates';\n readonly ids: readonly string[];\n readonly filePath: string;\n readonly line: number;\n}\n\nexport interface SpecFile {\n readonly filePath: string;\n readonly code: string;\n readonly requirementIds: readonly string[];\n readonly acIds: readonly string[];\n readonly propertyIds: readonly string[];\n readonly componentNames: readonly string[];\n readonly crossRefs: readonly CrossReference[];\n /** Maps IDs parsed from this file to their line number. Populated by spec-parser. */\n readonly idLocations?: ReadonlyMap<string, { filePath: string; line: number }>;\n /** Maps component names to their IMPLEMENTS AC IDs. Populated for DESIGN files. */\n readonly componentImplements?: ReadonlyMap<string, readonly string[]>;\n}\n\nexport interface SpecParseResult {\n readonly requirementIds: Set<string>;\n readonly acIds: Set<string>;\n readonly propertyIds: Set<string>;\n readonly componentNames: Set<string>;\n readonly allIds: Set<string>;\n readonly specFiles: readonly SpecFile[];\n /** Maps spec IDs (requirements, ACs, properties, components) to their source location. */\n readonly idLocations: ReadonlyMap<string, { filePath: string; line: number }>;\n}\n\nexport interface CheckResult {\n readonly findings: readonly Finding[];\n}\n\nexport interface RawCheckOptions {\n readonly specIgnore?: string[];\n readonly codeIgnore?: string[];\n readonly format?: string;\n readonly json?: boolean;\n readonly summary?: boolean;\n readonly config?: string;\n readonly allowWarnings?: boolean;\n readonly specOnly?: boolean;\n readonly fix?: boolean;\n}\n","// @awa-component: CHK-CheckCommand\n// @awa-impl: CHK-8_AC-1\n// @awa-impl: CHK-10_AC-1\n// @awa-impl: CHK-17_AC-1\n// @awa-impl: CHK-17_AC-2\n// @awa-impl: CHK-17_AC-3\n// @awa-impl: CHK-24_AC-1\n\nimport { checkCodeAgainstSpec } from '../core/check/code-spec-checker.js';\nimport { scanMarkers } from '../core/check/marker-scanner.js';\nimport { fixMatrices } from '../core/check/matrix-fixer.js';\nimport { report } from '../core/check/reporter.js';\nimport { loadRules } from '../core/check/rule-loader.js';\nimport { checkSchemasAsync } from '../core/check/schema-checker.js';\nimport { parseSpecs } from '../core/check/spec-parser.js';\nimport { checkSpecAgainstSpec } from '../core/check/spec-spec-checker.js';\nimport type { CheckConfig, RawCheckOptions } from '../core/check/types.js';\nimport { DEFAULT_CHECK_CONFIG } from '../core/check/types.js';\nimport { configLoader } from '../core/config.js';\nimport type { FileConfig } from '../types/index.js';\nimport { logger } from '../utils/logger.js';\n\n// @awa-impl: CHK-8_AC-1\nexport async function checkCommand(cliOptions: RawCheckOptions): Promise<number> {\n try {\n // Load config from file\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // Build check config from file [check] section + CLI overrides\n const config = buildCheckConfig(fileConfig, cliOptions);\n\n // Scan code markers (skip when --spec-only), parse specs, and load schema rules in parallel\n const emptyMarkers: import('../core/check/types.js').MarkerScanResult = {\n markers: [],\n findings: [],\n };\n const [markers, specs, ruleSets] = await Promise.all([\n config.specOnly ? Promise.resolve(emptyMarkers) : scanMarkers(config),\n parseSpecs(config),\n config.schemaEnabled ? loadRules(config.schemaDir) : Promise.resolve([]),\n ]);\n\n // Run checkers (code-spec and spec-spec are synchronous; schema is async)\n // When --spec-only, skip code-to-spec traceability checks entirely\n const codeSpecResult = config.specOnly\n ? { findings: [] as const }\n : checkCodeAgainstSpec(markers, specs, config);\n const specSpecResult = checkSpecAgainstSpec(specs, markers, config);\n const schemaResult =\n config.schemaEnabled && ruleSets.length > 0\n ? await checkSchemasAsync(specs.specFiles, ruleSets)\n : { findings: [] as const };\n\n // Combine findings\n const combinedFindings = [\n ...markers.findings,\n ...codeSpecResult.findings,\n ...specSpecResult.findings,\n ...schemaResult.findings,\n ];\n\n // Unless --allow-warnings, promote warnings to errors\n const allFindings = config.allowWarnings\n ? combinedFindings\n : combinedFindings.map((f) =>\n f.severity === 'warning' ? { ...f, severity: 'error' as const } : f\n );\n\n // Report results\n const isSummary = cliOptions.summary === true;\n if (isSummary) {\n const errors = allFindings.filter((f) => f.severity === 'error').length;\n const warnings = allFindings.filter((f) => f.severity === 'warning').length;\n console.log(`errors: ${errors}, warnings: ${warnings}`);\n } else {\n report(allFindings, config.format);\n }\n\n // Run fix: regenerate traceability matrices in DESIGN and TASK files (default; skip with --no-fix)\n if (config.fix) {\n const fixResult = await fixMatrices(specs, config.crossRefPatterns);\n if (fixResult.filesFixed > 0) {\n logger.info(`Fixed traceability matrices in ${fixResult.filesFixed} file(s)`);\n }\n }\n\n // Exit code: 0 = clean, 1 = any errors present\n const hasErrors = allFindings.some((f) => f.severity === 'error');\n return hasErrors ? 1 : 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 2;\n }\n}\n\n// @awa-impl: CHK-10_AC-1, CHK-16_AC-1\nfunction buildCheckConfig(fileConfig: FileConfig | null, cliOptions: RawCheckOptions): CheckConfig {\n const section = fileConfig?.check;\n\n const specGlobs = toStringArray(section?.['spec-globs']) ?? [...DEFAULT_CHECK_CONFIG.specGlobs];\n const codeGlobs = toStringArray(section?.['code-globs']) ?? [...DEFAULT_CHECK_CONFIG.codeGlobs];\n const markers = toStringArray(section?.markers) ?? [...DEFAULT_CHECK_CONFIG.markers];\n const crossRefPatterns = toStringArray(section?.['cross-ref-patterns']) ?? [\n ...DEFAULT_CHECK_CONFIG.crossRefPatterns,\n ];\n const idPattern =\n typeof section?.['id-pattern'] === 'string'\n ? section['id-pattern']\n : DEFAULT_CHECK_CONFIG.idPattern;\n\n // CLI --spec-ignore / --code-ignore append to their respective config lists\n const configSpecIgnore = toStringArray(section?.['spec-ignore']) ?? [\n ...DEFAULT_CHECK_CONFIG.specIgnore,\n ];\n const configCodeIgnore = toStringArray(section?.['code-ignore']) ?? [\n ...DEFAULT_CHECK_CONFIG.codeIgnore,\n ];\n const specIgnore = [...configSpecIgnore, ...(cliOptions.specIgnore ?? [])];\n const codeIgnore = [...configCodeIgnore, ...(cliOptions.codeIgnore ?? [])];\n\n const ignoreMarkers = toStringArray(section?.['ignore-markers']) ?? [\n ...DEFAULT_CHECK_CONFIG.ignoreMarkers,\n ];\n\n const format: 'text' | 'json' =\n cliOptions.json === true\n ? 'json'\n : cliOptions.format === 'json'\n ? 'json'\n : section?.format === 'json'\n ? 'json'\n : DEFAULT_CHECK_CONFIG.format;\n\n const schemaDir =\n typeof section?.['schema-dir'] === 'string'\n ? section['schema-dir']\n : DEFAULT_CHECK_CONFIG.schemaDir;\n\n const schemaEnabled =\n typeof section?.['schema-enabled'] === 'boolean'\n ? section['schema-enabled']\n : DEFAULT_CHECK_CONFIG.schemaEnabled;\n\n const allowWarnings =\n cliOptions.allowWarnings === true\n ? true\n : typeof section?.['allow-warnings'] === 'boolean'\n ? section['allow-warnings']\n : DEFAULT_CHECK_CONFIG.allowWarnings;\n\n const specOnly =\n cliOptions.specOnly === true\n ? true\n : typeof section?.['spec-only'] === 'boolean'\n ? section['spec-only']\n : DEFAULT_CHECK_CONFIG.specOnly;\n\n const fix = cliOptions.fix === false ? false : DEFAULT_CHECK_CONFIG.fix;\n\n return {\n specGlobs,\n codeGlobs,\n specIgnore,\n codeIgnore,\n ignoreMarkers,\n markers,\n idPattern,\n crossRefPatterns,\n format,\n schemaDir,\n schemaEnabled,\n allowWarnings,\n specOnly,\n fix,\n };\n}\n\nfunction toStringArray(value: unknown): string[] | null {\n if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {\n return value as string[];\n }\n return null;\n}\n","// @awa-component: DIFF-DiffCommand\n// @awa-component: JSON-DiffCommand\n// @awa-component: MULTI-DiffCommand\n// @awa-impl: DIFF-5_AC-1\n// @awa-impl: DIFF-5_AC-2\n// @awa-impl: DIFF-5_AC-3\n// @awa-impl: MULTI-6_AC-1\n// @awa-impl: MULTI-7_AC-1\n// @awa-impl: MULTI-12_AC-1\n\nimport { intro, outro } from '@clack/prompts';\nimport { batchRunner } from '../core/batch-runner.js';\nimport { configLoader } from '../core/config.js';\nimport { diffEngine } from '../core/differ.js';\nimport { featureResolver } from '../core/feature-resolver.js';\nimport { formatDiffSummary, serializeDiffResult, writeJsonOutput } from '../core/json-output.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport { DiffError, type RawCliOptions, type ResolvedOptions } from '../types/index.js';\nimport { FileWatcher } from '../utils/file-watcher.js';\nimport { pathExists, rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\nasync function runDiff(\n diffOptions: {\n templatePath: string;\n targetPath: string;\n features: string[];\n listUnknown: boolean;\n },\n options: { json: boolean; summary: boolean },\n mergedDir: string | null\n): Promise<number> {\n try {\n // Perform diff\n const result = await diffEngine.diff(diffOptions);\n\n // @awa-impl: JSON-2_AC-1, JSON-8_AC-1\n if (options.json) {\n writeJsonOutput(serializeDiffResult(result));\n // @awa-impl: DIFF-5_AC-1, DIFF-5_AC-2\n return result.hasDifferences ? 1 : 0;\n }\n\n // @awa-impl: JSON-5_AC-1\n if (options.summary) {\n console.log(formatDiffSummary(result));\n return result.hasDifferences ? 1 : 0;\n }\n\n // Display diff output\n for (const file of result.files) {\n switch (file.status) {\n case 'modified':\n logger.info(`Modified: ${file.relativePath}`);\n if (file.unifiedDiff) {\n // Parse and display unified diff with colors\n const lines = file.unifiedDiff.split('\\n');\n for (const line of lines) {\n if (\n line.startsWith('diff --git') ||\n line.startsWith('index ') ||\n line.startsWith('--- ') ||\n line.startsWith('+++ ')\n ) {\n logger.diffLine(line, 'context');\n } else if (line.startsWith('+')) {\n logger.diffLine(line, 'add');\n } else if (line.startsWith('-')) {\n logger.diffLine(line, 'remove');\n } else if (line.startsWith('@@')) {\n logger.diffLine(line, 'context');\n } else {\n logger.diffLine(line, 'context');\n }\n }\n }\n break;\n case 'new':\n logger.info(`New file: ${file.relativePath}`);\n break;\n case 'extra':\n logger.warn(`Extra file (not in template): ${file.relativePath}`);\n break;\n case 'binary-differs':\n logger.warn(`binary files differ: ${file.relativePath}`);\n break;\n case 'delete-listed':\n logger.warn(`Delete listed: ${file.relativePath}`);\n break;\n case 'identical':\n // Skip identical files from output\n break;\n }\n }\n\n // Display summary\n logger.diffSummary(result);\n\n // @awa-impl: DIFF-5_AC-1, DIFF-5_AC-2\n return result.hasDifferences ? 1 : 0;\n } finally {\n // Clean up merged overlay temp directory\n if (mergedDir) {\n try {\n await rmDir(mergedDir);\n } catch {\n // Swallow cleanup errors — temp dir will be cleaned by OS eventually\n }\n }\n }\n}\n\nasync function prepareDiff(options: ResolvedOptions): Promise<{\n diffOptions: {\n templatePath: string;\n targetPath: string;\n features: string[];\n listUnknown: boolean;\n };\n template: { type: string; localPath: string; source: string };\n mergedDir: string | null;\n}> {\n // Validate target directory exists (now from options.output)\n if (!(await pathExists(options.output))) {\n throw new DiffError(`Target directory does not exist: ${options.output}`);\n }\n\n const targetPath = options.output;\n\n // Resolve template source\n const template = await templateResolver.resolve(options.template, options.refresh);\n\n const features = featureResolver.resolve({\n baseFeatures: [...options.features],\n presetNames: [...options.preset],\n removeFeatures: [...options.removeFeatures],\n presetDefinitions: options.presets,\n });\n\n // @awa-impl: OVL-7_AC-1\n // Build merged template dir if overlays are specified\n let mergedDir: string | null = null;\n let templatePath = template.localPath;\n if (options.overlay.length > 0) {\n const overlayDirs = await resolveOverlays([...options.overlay], options.refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n return {\n diffOptions: {\n templatePath,\n targetPath,\n features,\n listUnknown: options.listUnknown,\n },\n template,\n mergedDir,\n };\n}\n\nexport async function diffCommand(cliOptions: RawCliOptions): Promise<number> {\n try {\n // Load configuration file\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // Batch mode: --all or --target\n if (cliOptions.allTargets || cliOptions.target) {\n const mode = cliOptions.allTargets ? 'all' : 'single';\n const targets = batchRunner.resolveTargets(cliOptions, fileConfig, mode, cliOptions.target);\n\n // @awa-impl: MULTI-12_AC-1\n // Exit code aggregation: 0 if all identical, 1 if any differ, 2 on error (first error short-circuits)\n let hasDifferences = false;\n for (const { targetName, options } of targets) {\n batchRunner.logForTarget(targetName, 'Starting diff...');\n const { diffOptions, mergedDir } = await prepareDiff(options);\n const exitCode = await runDiff(diffOptions, options, mergedDir);\n if (exitCode === 1) {\n hasDifferences = true;\n }\n batchRunner.logForTarget(targetName, 'Diff complete.');\n }\n\n outro('All targets diffed!');\n return hasDifferences ? 1 : 0;\n }\n\n // Standard single-target mode (backward compatible)\n const options = configLoader.merge(cliOptions, fileConfig);\n\n const silent = options.json || options.summary;\n\n // @awa-impl: JSON-6_AC-1\n // Suppress interactive output when --json or --summary is active\n if (!silent) {\n intro('awa CLI - Template Diff');\n }\n\n const { diffOptions, template, mergedDir } = await prepareDiff(options);\n\n // Validate watch mode: only local templates are supported\n if (cliOptions.watch && template.type !== 'local' && template.type !== 'bundled') {\n throw new DiffError('--watch is only supported with local template sources');\n }\n\n // Run diff once\n const result = await runDiff(diffOptions, options, mergedDir);\n\n if (!cliOptions.watch) {\n if (!silent) {\n outro('Diff complete!');\n }\n return result;\n }\n\n // Watch mode: re-run diff on template changes\n // Resolves only on SIGINT (Ctrl+C) — this is intentional for watch mode\n logger.info(`Watching for changes in ${template.localPath}...`);\n\n return new Promise<number>((resolve) => {\n let running = false;\n const watcher = new FileWatcher({\n directory: template.localPath,\n onChange: async () => {\n if (running) return;\n running = true;\n try {\n console.clear();\n logger.info(`[${new Date().toLocaleTimeString()}] Change detected, re-running diff...`);\n logger.info('---');\n await runDiff(diffOptions, options, null);\n } finally {\n running = false;\n }\n },\n });\n\n watcher.start();\n\n process.once('SIGINT', () => {\n watcher.stop();\n logger.info('\\nWatch mode stopped.');\n resolve(0);\n });\n });\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n\n // @awa-impl: DIFF-5_AC-3\n return 2;\n }\n}\n","// @awa-component: MULTI-BatchRunner\n// @awa-component: MULTI-Reporter\n// @awa-impl: MULTI-4_AC-1\n// @awa-impl: MULTI-4_AC-2\n// @awa-impl: MULTI-5_AC-1\n// @awa-impl: MULTI-8_AC-1\n// @awa-impl: MULTI-9_AC-1\n// @awa-impl: MULTI-11_AC-1\n\nimport {\n ConfigError,\n type FileConfig,\n type RawCliOptions,\n type ResolvedOptions,\n} from '../types/index.js';\nimport { logger } from '../utils/logger.js';\nimport { configLoader } from './config.js';\n\nexport interface BatchTargetResult {\n targetName: string;\n options: ResolvedOptions;\n}\n\nexport class BatchRunner {\n // Resolve all targets or a single named target from config\n resolveTargets(\n cli: RawCliOptions,\n fileConfig: FileConfig | null,\n mode: 'all' | 'single',\n targetName?: string\n ): BatchTargetResult[] {\n if (!fileConfig) {\n throw new ConfigError(\n 'No configuration file found. --all and --target require a config file with [targets.*] sections.',\n 'NO_TARGETS',\n null\n );\n }\n\n const targetNames = configLoader.getTargetNames(fileConfig);\n\n if (targetNames.length === 0) {\n throw new ConfigError(\n 'No targets defined in configuration. Add [targets.<name>] sections to .awa.toml.',\n 'NO_TARGETS',\n null\n );\n }\n\n const namesToProcess = mode === 'all' ? targetNames : [targetName as string];\n\n const results: BatchTargetResult[] = [];\n\n for (const name of namesToProcess) {\n const resolved = configLoader.resolveTarget(name, fileConfig);\n\n // Build CLI options for this target:\n // - When --all, ignore CLI positional output\n // - When --target, CLI positional overrides target output\n const targetCli: RawCliOptions = {\n ...cli,\n output: mode === 'all' ? undefined : cli.output,\n };\n\n let options: ResolvedOptions;\n try {\n options = configLoader.merge(targetCli, resolved);\n } catch (error) {\n // Re-throw MISSING_OUTPUT with target-specific message\n if (error instanceof ConfigError && error.code === 'MISSING_OUTPUT') {\n throw new ConfigError(\n `Target '${name}' has no output directory. Specify 'output' in [targets.${name}] or in the root config.`,\n 'MISSING_OUTPUT',\n null\n );\n }\n throw error;\n }\n\n results.push({ targetName: name, options });\n }\n\n return results;\n }\n\n // Log a message prefixed with target name\n logForTarget(targetName: string, message: string): void {\n logger.info(`[${targetName}] ${message}`);\n }\n\n warnForTarget(targetName: string, message: string): void {\n logger.warn(`[${targetName}] ${message}`);\n }\n\n errorForTarget(targetName: string, message: string): void {\n logger.error(`[${targetName}] ${message}`);\n }\n}\n\nexport const batchRunner = new BatchRunner();\n","// @awa-component: DIFF-DiffEngine\n// @awa-impl: DIFF-1_AC-1\n// @awa-impl: DIFF-1_AC-2\n// @awa-impl: DIFF-1_AC-3\n// @awa-impl: DIFF-2_AC-1\n// @awa-impl: DIFF-2_AC-2\n// @awa-impl: DIFF-2_AC-3\n// @awa-impl: DIFF-2_AC-4\n// @awa-impl: DIFF-2_AC-5\n// @awa-impl: DIFF-3_AC-1\n// @awa-impl: DIFF-3_AC-2\n// @awa-impl: DIFF-3_AC-3\n// @awa-impl: DIFF-4_AC-1\n// @awa-impl: DIFF-4_AC-2\n// @awa-impl: DIFF-5_AC-1\n// @awa-impl: DIFF-5_AC-2\n// @awa-impl: DIFF-5_AC-3\n// @awa-impl: DIFF-6_AC-1\n// @awa-impl: DIFF-6_AC-2\n// @awa-impl: DIFF-6_AC-3\n// @awa-impl: DIFF-8_AC-1\n// @awa-impl: DIFF-8_AC-2\n// @awa-impl: DIFF-8_AC-3\n// @awa-impl: DIFF-8_AC-4\n\nimport { tmpdir } from 'node:os';\nimport { join, relative } from 'node:path';\nimport { structuredPatch } from 'diff';\nimport { isBinaryFile as detectBinaryFile } from 'isbinaryfile';\nimport type { DiffOptions, DiffResult, FileDiff, GenerateOptions } from '../types/index.js';\nimport { ensureDir, pathExists, readBinaryFile, rmDir, walkDirectory } from '../utils/fs.js';\nimport { loadDeleteList, resolveDeleteList } from './delete-list.js';\nimport { fileGenerator } from './generator.js';\n\nexport class DiffEngine {\n // @awa-impl: DIFF-1_AC-1, DIFF-1_AC-2, DIFF-1_AC-3\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-2, DIFF-2_AC-3, DIFF-2_AC-4, DIFF-2_AC-5\n // @awa-impl: DIFF-3_AC-1, DIFF-3_AC-2, DIFF-3_AC-3\n // @awa-impl: DIFF-4_AC-1, DIFF-4_AC-2\n // @awa-impl: DIFF-5_AC-1, DIFF-5_AC-2, DIFF-5_AC-3\n // @awa-impl: DIFF-6_AC-1, DIFF-6_AC-2, DIFF-6_AC-3\n async diff(options: DiffOptions): Promise<DiffResult> {\n const { templatePath, targetPath, features, listUnknown } = options;\n\n // @awa-impl: DIFF-1_AC-1, DIFF-1_AC-2\n const tempPath = await this.createTempDir();\n\n try {\n // Generate templates to temp directory\n const generateOptions: GenerateOptions = {\n templatePath,\n outputPath: tempPath,\n features,\n force: true,\n dryRun: false,\n delete: false,\n };\n\n await fileGenerator.generate(generateOptions);\n\n // Collect all files from both directories\n const generatedFiles = new Set<string>();\n const targetFiles = new Set<string>();\n\n // Walk generated directory (if exists - may be empty if template generates nothing)\n if (await pathExists(tempPath)) {\n for await (const file of walkDirectory(tempPath)) {\n const relPath = relative(tempPath, file);\n generatedFiles.add(relPath);\n }\n }\n\n // Walk target directory (if exists)\n if (await pathExists(targetPath)) {\n for await (const file of walkDirectory(targetPath)) {\n const relPath = relative(targetPath, file);\n targetFiles.add(relPath);\n }\n }\n\n // Compare files: iterate generated files first; optionally include target-only files when requested\n const files: FileDiff[] = [];\n\n for (const relPath of generatedFiles) {\n const generatedFilePath = join(tempPath, relPath);\n const targetFilePath = join(targetPath, relPath);\n\n if (targetFiles.has(relPath)) {\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-2, DIFF-2_AC-3, DIFF-2_AC-4, DIFF-2_AC-5\n const fileDiff = await this.compareFiles(generatedFilePath, targetFilePath, relPath);\n files.push(fileDiff);\n } else {\n // @awa-impl: DIFF-3_AC-1\n files.push({\n relativePath: relPath,\n status: 'new',\n });\n }\n }\n\n if (listUnknown) {\n for (const relPath of targetFiles) {\n if (generatedFiles.has(relPath)) {\n continue;\n }\n\n // @awa-impl: DIFF-3_AC-2, DIFF-3_AC-3, DIFF-3_AC-4\n files.push({\n relativePath: relPath,\n status: 'extra',\n });\n }\n }\n\n // Check delete list for files that exist in target\n const deleteEntries = await loadDeleteList(templatePath);\n const deleteList = resolveDeleteList(deleteEntries, features ?? []);\n for (const relPath of deleteList) {\n if (targetFiles.has(relPath) && !generatedFiles.has(relPath)) {\n // Remove any existing 'extra' entry for this path (to avoid double-reporting)\n const existingIdx = files.findIndex(\n (f) => f.relativePath === relPath && f.status === 'extra'\n );\n if (existingIdx !== -1) {\n files.splice(existingIdx, 1);\n }\n files.push({\n relativePath: relPath,\n status: 'delete-listed',\n });\n }\n }\n\n // Calculate summary\n const identical = files.filter((f) => f.status === 'identical').length;\n const modified = files.filter((f) => f.status === 'modified').length;\n const newFiles = files.filter((f) => f.status === 'new').length;\n const extraFiles = files.filter((f) => f.status === 'extra').length;\n const binaryDiffers = files.filter((f) => f.status === 'binary-differs').length;\n const deleteListed = files.filter((f) => f.status === 'delete-listed').length;\n\n const hasDifferences =\n modified > 0 || newFiles > 0 || extraFiles > 0 || binaryDiffers > 0 || deleteListed > 0;\n\n return {\n files,\n identical,\n modified,\n newFiles,\n extraFiles,\n binaryDiffers,\n deleteListed,\n hasDifferences,\n };\n } finally {\n // @awa-impl: DIFF-6_AC-1, DIFF-6_AC-2, DIFF-6_AC-3\n await this.cleanupTempDir(tempPath);\n }\n }\n\n // @awa-impl: DIFF-1_AC-1, DIFF-1_AC-2\n async createTempDir(): Promise<string> {\n const systemTemp = tmpdir();\n const timestamp = Date.now();\n const random = Math.random().toString(36).substring(2, 8);\n const tempPath = join(systemTemp, `awa-diff-${timestamp}-${random}`);\n\n await ensureDir(tempPath);\n return tempPath;\n }\n\n // @awa-impl: DIFF-6_AC-1, DIFF-6_AC-2, DIFF-6_AC-3\n async cleanupTempDir(tempPath: string): Promise<void> {\n try {\n if (await pathExists(tempPath)) {\n await rmDir(tempPath);\n }\n } catch (_error) {\n // Swallow cleanup errors - temp directory will be cleaned by OS eventually\n // This ensures cleanup errors don't mask the actual diff results\n }\n }\n\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-2, DIFF-2_AC-3, DIFF-2_AC-4, DIFF-2_AC-5\n async compareFiles(\n generatedPath: string,\n targetPath: string,\n relativePath: string\n ): Promise<FileDiff> {\n // Read raw bytes for byte-for-byte comparison.\n const generatedBytes = await readBinaryFile(generatedPath);\n const targetBytes = await readBinaryFile(targetPath);\n\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-3\n if (generatedBytes.equals(targetBytes)) {\n return {\n relativePath,\n status: 'identical',\n };\n }\n\n // @awa-impl: DIFF-2_AC-5\n // If either side is binary, do not attempt a text diff.\n const isBinaryGenerated = await this.isBinaryFile(generatedPath);\n const isBinaryTarget = await this.isBinaryFile(targetPath);\n\n if (isBinaryGenerated || isBinaryTarget) {\n return {\n relativePath,\n status: 'binary-differs',\n };\n }\n\n // Text files: unified diff (diff library is text-based)\n const generatedContent = generatedBytes.toString('utf-8');\n const targetContent = targetBytes.toString('utf-8');\n\n // @awa-impl: DIFF-2_AC-4\n // Generate unified diff\n const patch = structuredPatch(\n `a/${relativePath}`,\n `b/${relativePath}`,\n targetContent,\n generatedContent,\n 'target',\n 'generated',\n {\n context: 3,\n }\n );\n\n // Format as git-style unified diff string (with file headers)\n const headerLines = [\n `diff --git a/${relativePath} b/${relativePath}`,\n `--- a/${relativePath}`,\n `+++ b/${relativePath}`,\n ];\n\n const hunkLines = patch.hunks.flatMap((hunk) => {\n const lines = [`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`];\n lines.push(...hunk.lines);\n return lines;\n });\n\n const unifiedDiff = [...headerLines, ...hunkLines].join('\\n');\n\n return {\n relativePath,\n status: 'modified',\n unifiedDiff,\n };\n }\n\n // @awa-impl: DIFF-2_AC-5\n async isBinaryFile(filePath: string): Promise<boolean> {\n try {\n return await detectBinaryFile(filePath);\n } catch {\n // If detection fails, assume text file\n return false;\n }\n }\n}\n\nexport const diffEngine = new DiffEngine();\n","// @awa-component: GEN-DeleteList\n// @awa-impl: GEN-12_AC-1\n// @awa-impl: GEN-12_AC-8\n\nimport { join } from 'node:path';\nimport { pathExists, readTextFile } from '../utils/fs.js';\n\nconst DELETE_LIST_FILENAME = '_delete.txt';\n\n/**\n * A delete list entry. When `features` is set, the path is only deleted\n * when NONE of those features are present in the active feature set\n * (stale tool cleanup). When `features` is absent, the path is always\n * deleted (legacy removal).\n */\nexport interface DeleteEntry {\n path: string;\n /** One or more feature names — keep (don't delete) if any is active. */\n features?: string[];\n}\n\n/**\n * Parse `_delete.txt` content into structured entries.\n *\n * Format:\n * - Blank lines and `#` comments are ignored.\n * - `# @feature <name> [<name2> ...]` starts a feature-gated section: subsequent\n * paths are deleted only when NONE of the listed features are active.\n * - Any other comment line clears the current feature section (returns to\n * always-delete behaviour).\n * - Path lines inherit the current section's feature tag (if any).\n */\nexport function parseDeleteList(content: string): DeleteEntry[] {\n const entries: DeleteEntry[] = [];\n let currentFeatures: string[] | undefined;\n\n for (const raw of content.split('\\n')) {\n const line = raw.trim();\n if (line.length === 0) continue;\n\n if (line.startsWith('#')) {\n const featureMatch = line.match(/^#\\s*@feature\\s+(.+)$/);\n if (featureMatch) {\n const featureSection = featureMatch[1];\n currentFeatures = featureSection ? featureSection.trim().split(/\\s+/) : undefined;\n } else {\n // Any other comment resets the feature section\n currentFeatures = undefined;\n }\n continue;\n }\n\n entries.push({ path: line, features: currentFeatures });\n }\n\n return entries;\n}\n\n/**\n * Resolve which paths from the delete list should actually be deleted,\n * given the currently active feature flags.\n *\n * - Entries without a feature tag are always included (legacy removals).\n * - Entries with feature tags are included only when NONE of those features are active\n * (stale tool output cleanup).\n */\nexport function resolveDeleteList(entries: DeleteEntry[], activeFeatures: string[]): string[] {\n const activeSet = new Set(activeFeatures);\n return entries\n .filter((e) => e.features === undefined || !e.features.some((f) => activeSet.has(f)))\n .map((e) => e.path);\n}\n\n/**\n * Load and parse `_delete.txt` from the template directory.\n * Returns empty array if the file does not exist.\n */\nexport async function loadDeleteList(templatePath: string): Promise<DeleteEntry[]> {\n const deleteListPath = join(templatePath, DELETE_LIST_FILENAME);\n\n if (!(await pathExists(deleteListPath))) {\n return [];\n }\n\n const content = await readTextFile(deleteListPath);\n return parseDeleteList(content);\n}\n","// @awa-component: GEN-FileGenerator\n// @awa-impl: GEN-1_AC-1\n// @awa-impl: GEN-1_AC-2\n// @awa-impl: GEN-1_AC-3\n// @awa-impl: GEN-2_AC-1\n// @awa-impl: GEN-2_AC-2\n// @awa-impl: GEN-2_AC-3\n// @awa-impl: GEN-3_AC-1\n// @awa-impl: GEN-3_AC-2\n// @awa-impl: GEN-3_AC-3\n// @awa-impl: GEN-8_AC-1\n// @awa-impl: GEN-8_AC-2\n// @awa-impl: GEN-8_AC-3\n// @awa-impl: GEN-11_AC-3\n// @awa-impl: GEN-6_AC-1\n// @awa-impl: GEN-6_AC-2\n// @awa-impl: GEN-12_AC-2\n// @awa-impl: GEN-12_AC-4\n// @awa-impl: GEN-12_AC-5\n// @awa-impl: GEN-12_AC-6\n// @awa-impl: GEN-12_AC-7\n// @awa-impl: CLI-6_AC-2\n// @awa-impl: CLI-12_AC-2\n// @awa-impl: TPL-9_AC-1\n// @awa-impl: TPL-9_AC-2\n\nimport { join, relative } from 'node:path';\nimport { PACKAGE_INFO } from '../_generated/package_info.js';\nimport {\n type ConflictItem,\n type FileAction,\n type GenerateOptions,\n GenerationError,\n type GenerationResult,\n} from '../types/index.js';\nimport { deleteFile, pathExists, readTextFile, walkDirectory, writeTextFile } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\nimport { loadDeleteList, resolveDeleteList } from './delete-list.js';\nimport { conflictResolver, deleteResolver } from './resolver.js';\nimport { templateEngine } from './template.js';\n\nexport class FileGenerator {\n // @awa-impl: GEN-1_AC-1, GEN-1_AC-2, GEN-1_AC-3\n // @awa-impl: GEN-2_AC-1, GEN-2_AC-2, GEN-2_AC-3\n // @awa-impl: GEN-3_AC-1, GEN-3_AC-2, GEN-3_AC-3\n async generate(options: GenerateOptions): Promise<GenerationResult> {\n const { templatePath, outputPath, features, force, dryRun } = options;\n const enableDelete = options.delete;\n\n // Configure template engine\n templateEngine.configure(templatePath);\n\n const actions: FileAction[] = [];\n let created = 0;\n let overwritten = 0;\n let deleted = 0;\n let skippedEmpty = 0;\n let skippedUser = 0;\n let skippedEqual = 0;\n\n // Collect files to process\n interface FileToProcess {\n templateFile: string;\n outputFile: string;\n content: string;\n isNew: boolean;\n }\n\n const filesToProcess: FileToProcess[] = [];\n const conflicts: ConflictItem[] = [];\n\n try {\n // First pass: render all templates and categorize files\n for await (const templateFile of this.walkTemplates(templatePath)) {\n // Compute output path\n const outputFile = this.computeOutputPath(templateFile, templatePath, outputPath);\n\n // Render template\n const result = await templateEngine.render(templateFile, {\n features,\n version: PACKAGE_INFO.version,\n });\n\n // Handle empty output\n if (result.isEmpty && !result.isEmptyFileMarker) {\n // Skip empty files\n actions.push({\n type: 'skip-empty',\n sourcePath: templateFile,\n outputPath: outputFile,\n });\n skippedEmpty++;\n continue;\n }\n\n // Get final content (empty string if marker)\n const content = result.isEmptyFileMarker ? '' : result.content;\n\n // Check for conflicts\n const fileExists = await pathExists(outputFile);\n\n if (fileExists) {\n // Read existing content for comparison\n const existingContent = await readTextFile(outputFile);\n conflicts.push({\n outputPath: outputFile,\n sourcePath: templateFile,\n newContent: content,\n existingContent,\n });\n }\n\n filesToProcess.push({\n templateFile,\n outputFile,\n content,\n isNew: !fileExists,\n });\n }\n\n // Resolve all conflicts at once if there are any\n let resolution: { overwrite: string[]; skip: string[]; equal: string[] } = {\n overwrite: [],\n skip: [],\n equal: [],\n };\n if (conflicts.length > 0) {\n resolution = await conflictResolver.resolveBatch(conflicts, force, dryRun);\n }\n\n // Second pass: process files based on resolution\n for (const file of filesToProcess) {\n if (file.isNew) {\n // Create new file\n if (!dryRun) {\n await writeTextFile(file.outputFile, file.content);\n }\n actions.push({\n type: 'create',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n created++;\n logger.fileAction({\n type: 'create',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n } else if (resolution.overwrite.includes(file.outputFile)) {\n // Overwrite existing file\n if (!dryRun) {\n await writeTextFile(file.outputFile, file.content);\n }\n actions.push({\n type: 'overwrite',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n overwritten++;\n logger.fileAction({\n type: 'overwrite',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n } else if (resolution.equal.includes(file.outputFile)) {\n // Skip file — content is identical\n actions.push({\n type: 'skip-equal',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n skippedEqual++;\n logger.fileAction({\n type: 'skip-equal',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n } else if (resolution.skip.includes(file.outputFile)) {\n // Skip file — user declined overwrite\n actions.push({\n type: 'skip-user',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n skippedUser++;\n logger.fileAction({\n type: 'skip-user',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n }\n }\n\n // Process delete list (after file generation)\n const deleteEntries = await loadDeleteList(templatePath);\n if (deleteEntries.length > 0) {\n const deleteList = resolveDeleteList(deleteEntries, features);\n\n // Collect generated output paths to detect conflicts\n const generatedOutputPaths = new Set(filesToProcess.map((f) => f.outputFile));\n\n // Filter: only files that exist and aren't being generated\n const deleteCandidates: string[] = [];\n for (const relPath of deleteList) {\n const absPath = join(outputPath, relPath);\n if (generatedOutputPaths.has(absPath)) {\n logger.warn(\n `Delete list entry '${relPath}' conflicts with generated file — skipping deletion`\n );\n continue;\n }\n if (await pathExists(absPath)) {\n deleteCandidates.push(absPath);\n }\n }\n\n if (deleteCandidates.length > 0) {\n if (!enableDelete) {\n // --delete not passed: warn but do nothing\n for (const absPath of deleteCandidates) {\n logger.warn(\n `Would delete (pass --delete to enable): ${relative(outputPath, absPath)}`\n );\n }\n } else {\n const confirmed = await deleteResolver.resolveDeletes(deleteCandidates, force, dryRun);\n\n for (const absPath of confirmed) {\n if (!dryRun) {\n await deleteFile(absPath);\n }\n actions.push({ type: 'delete', outputPath: absPath });\n deleted++;\n logger.fileAction({ type: 'delete', outputPath: absPath });\n }\n }\n }\n }\n\n return {\n actions,\n created,\n overwritten,\n deleted,\n skipped: skippedEmpty + skippedUser + skippedEqual,\n skippedEmpty,\n skippedUser,\n skippedEqual,\n };\n } catch (error) {\n // @awa-impl: GEN-2_AC-3, GEN-11_AC-3\n if (error instanceof Error && 'code' in error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'EACCES' || code === 'EPERM') {\n throw new GenerationError(`Permission denied: ${error.message}`, 'PERMISSION_DENIED');\n }\n if (code === 'ENOSPC') {\n throw new GenerationError(`Disk full: ${error.message}`, 'DISK_FULL');\n }\n }\n throw error;\n }\n }\n\n // @awa-impl: GEN-8_AC-1, GEN-8_AC-2, GEN-8_AC-3\n // @awa-impl: TPL-9_AC-1, TPL-9_AC-2\n async *walkTemplates(dir: string): AsyncIterable<string> {\n // Use utility function that already handles underscore exclusion\n yield* walkDirectory(dir);\n }\n\n // @awa-impl: GEN-1_AC-1, GEN-1_AC-2, GEN-1_AC-3\n computeOutputPath(templatePath: string, templateRoot: string, outputRoot: string): string {\n // Get relative path from template root\n const relativePath = relative(templateRoot, templatePath);\n\n // Join with output root to mirror structure\n return join(outputRoot, relativePath);\n }\n}\n\nexport const fileGenerator = new FileGenerator();\n","// @awa-component: GEN-ConflictResolver\n// @awa-component: GEN-DeleteResolver\n// @awa-impl: CLI-5_AC-2\n// @awa-impl: CLI-5_AC-3\n// @awa-impl: GEN-4_AC-1\n// @awa-impl: GEN-4_AC-2\n// @awa-impl: GEN-4_AC-3\n// @awa-impl: GEN-5_AC-1\n// @awa-impl: GEN-5_AC-2\n// @awa-impl: GEN-5_AC-3\n// @awa-impl: GEN-5_AC-4\n// @awa-impl: GEN-5_AC-5\n// @awa-impl: GEN-5_AC-6\n// @awa-impl: GEN-5_AC-7\n// @awa-impl: GEN-6_AC-3\n// @awa-impl: GEN-10_AC-3\n// @awa-impl: GEN-12_AC-3\n// @awa-impl: GEN-12_AC-4\n// @awa-impl: GEN-12_AC-5\n// @awa-impl: CLI-12_AC-3\n\nimport { MultiSelectPrompt } from '@clack/core';\nimport { isCancel, multiselect } from '@clack/prompts';\nimport chalk from 'chalk';\nimport type { BatchConflictResolution, ConflictItem } from '../types/index.js';\n\n// Unicode symbols (mirrors @clack/prompts internals)\nconst _unicode = process.platform !== 'win32';\nconst _s = (c: string, fb: string) => (_unicode ? c : fb);\nconst _CHECKED = _s('\\u25FC', '[+]'); // ◼\nconst _UNCHECKED_A = _s('\\u25FB', '[·]'); // ◻ active\nconst _UNCHECKED = _s('\\u25FB', '[ ]'); // ◻ inactive\nconst _BAR = _s('\\u2502', '|'); // │\nconst _BAR_END = _s('\\u2514', '-'); // └\n\ntype SelectOption = { value: string; label?: string; hint?: string };\n\nfunction _renderDeleteItem(opt: SelectOption, state: string): string {\n const label = opt.label ?? opt.value;\n const hint = opt.hint ? ` ${chalk.dim(`(${opt.hint})`)}` : '';\n switch (state) {\n case 'active':\n return `${chalk.cyan(_UNCHECKED_A)} ${label}${hint}`;\n case 'selected':\n return `${chalk.red(_CHECKED)} ${chalk.dim(label)}${hint}`;\n case 'active-selected':\n return `${chalk.red(_CHECKED)} ${label}${hint}`;\n case 'cancelled':\n return chalk.strikethrough(chalk.dim(label));\n case 'submitted':\n return chalk.dim(label);\n default:\n return `${chalk.dim(_UNCHECKED)} ${chalk.dim(label)}`;\n }\n}\n\n/** Like @clack/prompts `multiselect` but with red checkboxes for destructive operations. */\nasync function deleteMultiselect(opts: {\n message: string;\n options: SelectOption[];\n initialValues?: string[];\n required?: boolean;\n}): Promise<string[] | symbol> {\n const { message, options, initialValues, required = false } = opts;\n return new MultiSelectPrompt({\n options,\n initialValues,\n required,\n render() {\n const self = this as unknown as {\n state: string;\n options: SelectOption[];\n cursor: number;\n value: string[];\n };\n const header = `${chalk.gray(_BAR)}\\n${chalk.cyan(_BAR)} ${message}\\n`;\n const getState = (opt: SelectOption, idx: number): string => {\n const active = idx === self.cursor;\n const sel = self.value.includes(opt.value);\n if (active && sel) return 'active-selected';\n if (sel) return 'selected';\n if (active) return 'active';\n return 'inactive';\n };\n switch (self.state) {\n case 'submit':\n return (\n `${header}${chalk.gray(_BAR)} ` +\n (self.options\n .filter((o) => self.value.includes(o.value))\n .map((o) => _renderDeleteItem(o, 'submitted'))\n .join(chalk.dim(', ')) || chalk.dim('none'))\n );\n case 'cancel': {\n const cancelled = self.options\n .filter((o) => self.value.includes(o.value))\n .map((o) => _renderDeleteItem(o, 'cancelled'))\n .join(chalk.dim(', '));\n return `${header}${chalk.gray(_BAR)} ${cancelled.trim() ? `${cancelled}\\n${chalk.gray(_BAR)}` : chalk.dim('none')}`;\n }\n default:\n return (\n `${header}${chalk.cyan(_BAR)} ` +\n self.options\n .map((o, i) => _renderDeleteItem(o, getState(o, i)))\n .join(`\\n${chalk.cyan(_BAR)} `) +\n `\\n${chalk.cyan(_BAR_END)}\\n`\n );\n }\n },\n }).prompt() as Promise<string[] | symbol>;\n}\n\nexport class ConflictResolver {\n // @awa-impl: GEN-4_AC-1, GEN-4_AC-2, GEN-4_AC-3\n // @awa-impl: GEN-5_AC-1, GEN-5_AC-2, GEN-5_AC-3, GEN-5_AC-4, GEN-5_AC-5, GEN-5_AC-6, GEN-5_AC-7\n // @awa-impl: CLI-5_AC-2, CLI-5_AC-3\n // @awa-impl: GEN-6_AC-3\n async resolveBatch(\n conflicts: ConflictItem[],\n force: boolean,\n dryRun: boolean\n ): Promise<BatchConflictResolution> {\n // Separate identical-content files from different files\n const identicalPaths = conflicts\n .filter((c) => c.newContent === c.existingContent)\n .map((c) => c.outputPath);\n const differentFiles = conflicts.filter((c) => c.newContent !== c.existingContent);\n\n // In dry-run mode, never modify files (P7: Dry Run Immutable)\n if (dryRun) {\n return {\n overwrite: [],\n skip: differentFiles.map((c) => c.outputPath),\n equal: identicalPaths,\n };\n }\n\n // In force mode, always overwrite without prompting (P8: Force No Prompt)\n if (force) {\n return {\n overwrite: differentFiles.map((c) => c.outputPath),\n skip: [],\n equal: identicalPaths,\n };\n }\n\n // If all files are identical, skip them all\n if (differentFiles.length === 0) {\n return {\n overwrite: [],\n skip: [],\n equal: identicalPaths,\n };\n }\n\n // @awa-impl: GEN-5_AC-1, GEN-5_AC-2, GEN-5_AC-5, GEN-5_AC-6\n // Prompt user with multi-select (all selected by default)\n const selected = await multiselect({\n message: 'The following files already exist. Select files to overwrite:',\n options: differentFiles.map((c) => ({\n value: c.outputPath,\n label: c.outputPath,\n })),\n initialValues: differentFiles.map((c) => c.outputPath), // All selected by default (AC-5.6)\n required: false,\n });\n\n // @awa-impl: GEN-10_AC-3\n // Handle user cancellation (Ctrl+C)\n if (isCancel(selected)) {\n process.exit(1);\n }\n\n const selectedPaths = selected as string[];\n const allPaths = differentFiles.map((c) => c.outputPath);\n\n return {\n overwrite: selectedPaths,\n skip: allPaths.filter((p) => !selectedPaths.includes(p)),\n equal: identicalPaths,\n };\n }\n}\n\nexport const conflictResolver = new ConflictResolver();\n\nexport class DeleteResolver {\n /**\n * Prompt user to confirm which files to delete.\n * Returns the list of absolute paths confirmed for deletion.\n */\n async resolveDeletes(candidates: string[], force: boolean, dryRun: boolean): Promise<string[]> {\n if (candidates.length === 0) {\n return [];\n }\n\n // In dry-run mode, return all candidates (caller logs but won't delete)\n if (dryRun) {\n return candidates;\n }\n\n // In force mode, delete without prompting\n if (force) {\n return candidates;\n }\n\n // Prompt user with multi-select (all selected by default, red checkboxes)\n const selected = await deleteMultiselect({\n message:\n '⚠ WARNING: The selected files will be PERMANENTLY DELETED from disk.\\n' +\n ' Deselect any files you want to keep. Press Enter to confirm deletion:',\n options: candidates.map((p) => ({\n value: p,\n label: p,\n })),\n initialValues: candidates,\n required: false,\n });\n\n // Handle user cancellation (Ctrl+C)\n if (isCancel(selected)) {\n process.exit(1);\n }\n\n return selected as string[];\n }\n}\n\nexport const deleteResolver = new DeleteResolver();\n","// @awa-component: TPL-TemplateEngine\n// @awa-impl: TPL-4_AC-1\n// @awa-impl: TPL-4_AC-2\n// @awa-impl: TPL-4_AC-3\n// @awa-impl: TPL-4_AC-4\n// @awa-impl: TPL-5_AC-1\n// @awa-impl: TPL-5_AC-2\n// @awa-impl: TPL-5_AC-3\n// @awa-impl: TPL-6_AC-1\n// @awa-impl: TPL-6_AC-2\n// @awa-impl: TPL-7_AC-1\n// @awa-impl: TPL-7_AC-2\n// @awa-impl: TPL-8_AC-1\n// @awa-impl: TPL-8_AC-2\n// @awa-impl: TPL-8_AC-3\n// @awa-impl: TPL-8_AC-4\n// @awa-impl: TPL-11_AC-1\n// @awa-impl: TPL-11_AC-2\n\nimport { Eta } from 'eta';\nimport { type RenderResult, type TemplateContext, TemplateError } from '../types/index.js';\nimport { readTextFile } from '../utils/fs.js';\n\nconst EMPTY_FILE_MARKER = '<!-- AWA:EMPTY_FILE -->';\n\nexport class TemplateEngine {\n private eta: Eta | null = null;\n private templateDir: string | null = null;\n private compiledCache = new Map<string, unknown>();\n\n // @awa-impl: TPL-8_AC-1, TPL-8_AC-2, TPL-8_AC-3, TPL-8_AC-4\n configure(templateDir: string): void {\n this.templateDir = templateDir;\n this.compiledCache.clear();\n\n // @awa-impl: TPL-4_AC-1, TPL-4_AC-2, TPL-4_AC-3, TPL-4_AC-4\n // Configure Eta with partials support\n this.eta = new Eta({\n views: templateDir,\n cache: true, // Enable compilation caching\n autoEscape: false, // Don't escape HTML by default\n defaultExtension: '', // No automatic extension - use exact path as specified (AC-8.2)\n });\n }\n\n // @awa-impl: TPL-5_AC-1, TPL-5_AC-2, TPL-5_AC-3\n // @awa-impl: TPL-6_AC-1, TPL-6_AC-2\n // @awa-impl: TPL-7_AC-1, TPL-7_AC-2\n // @awa-impl: TPL-11_AC-1, TPL-11_AC-2\n async render(templatePath: string, context: TemplateContext): Promise<RenderResult> {\n if (!this.eta || !this.templateDir) {\n throw new TemplateError(\n 'Template engine not configured. Call configure() first.',\n 'RENDER_ERROR'\n );\n }\n\n try {\n // Read template content\n const templateContent = await readTextFile(templatePath);\n\n // Render with features context\n // The context is available as 'it' in templates\n const rendered = await this.eta.renderStringAsync(templateContent, {\n features: context.features,\n version: context.version ?? '',\n });\n\n // Check if output is empty or only whitespace\n const trimmed = rendered.trim();\n const isEmpty = trimmed.length === 0;\n\n // Check for empty file marker\n const isEmptyFileMarker = trimmed === EMPTY_FILE_MARKER;\n\n return {\n content: rendered,\n isEmpty,\n isEmptyFileMarker,\n };\n } catch (error) {\n throw new TemplateError(\n `Failed to render template ${templatePath}: ${error instanceof Error ? error.message : String(error)}`,\n 'RENDER_ERROR',\n templatePath\n );\n }\n }\n}\n\nexport const templateEngine = new TemplateEngine();\n","// @awa-component: FP-FeatureResolver\n// @awa-impl: FP-2_AC-3\n// @awa-impl: FP-4_AC-4\n// @awa-impl: FP-6_AC-1\n// @awa-impl: FP-6_AC-2\n// @awa-impl: FP-6_AC-3\n// @awa-impl: FP-6_AC-4\n// @awa-impl: FP-6_AC-5\n// @awa-impl: FP-7_AC-1\n// @awa-impl: FP-7_AC-2\n\nimport { ConfigError, type PresetDefinitions } from '../types/index.js';\n\nexport interface FeatureResolutionInput {\n baseFeatures: string[];\n presetNames: string[];\n removeFeatures: string[];\n presetDefinitions: PresetDefinitions;\n}\n\nexport class FeatureResolver {\n validatePresets(presetNames: string[], definitions: PresetDefinitions): void {\n for (const name of presetNames) {\n if (!definitions[name]) {\n throw new ConfigError(`Unknown preset: ${name}`, 'UNKNOWN_PRESET');\n }\n }\n }\n\n resolve(input: FeatureResolutionInput): string[] {\n const { baseFeatures, presetNames, removeFeatures, presetDefinitions } = input;\n\n this.validatePresets(presetNames, presetDefinitions);\n\n const finalFeatures: string[] = [];\n const seen = new Set<string>();\n\n const add = (feature: string) => {\n if (seen.has(feature)) return;\n seen.add(feature);\n finalFeatures.push(feature);\n };\n\n for (const feature of baseFeatures) add(feature);\n\n for (const presetName of presetNames) {\n for (const feature of presetDefinitions[presetName] ?? []) add(feature);\n }\n\n if (removeFeatures.length === 0) return finalFeatures;\n\n const removeSet = new Set(removeFeatures);\n return finalFeatures.filter((f) => !removeSet.has(f));\n }\n}\n\nexport const featureResolver = new FeatureResolver();\n","// @awa-component: JSON-JsonSerializer\n// @awa-impl: JSON-1_AC-1\n// @awa-impl: JSON-2_AC-1\n// @awa-impl: JSON-3_AC-1\n// @awa-impl: JSON-4_AC-1\n// @awa-impl: JSON-5_AC-1\n// @awa-impl: JSON-8_AC-1\n\nimport type {\n DiffFileJSON,\n DiffJSON,\n DiffResult,\n GenerationActionJSON,\n GenerationJSON,\n GenerationResult,\n} from '../types/index.js';\n\n// @awa-impl: JSON-1_AC-1, JSON-3_AC-1\nexport function serializeGenerationResult(result: GenerationResult): GenerationJSON {\n const actions: GenerationActionJSON[] = result.actions.map((action) => ({\n type: action.type,\n path: action.outputPath,\n }));\n\n return {\n actions,\n counts: {\n created: result.created,\n overwritten: result.overwritten,\n skipped: result.skipped,\n deleted: result.deleted,\n },\n };\n}\n\n// @awa-impl: JSON-2_AC-1, JSON-4_AC-1\nexport function serializeDiffResult(result: DiffResult): DiffJSON {\n const diffs: DiffFileJSON[] = result.files.map((file) => {\n const entry: DiffFileJSON = {\n path: file.relativePath,\n status: file.status,\n };\n if (file.unifiedDiff) {\n entry.diff = file.unifiedDiff;\n }\n return entry;\n });\n\n return {\n diffs,\n counts: {\n changed: result.modified,\n new: result.newFiles,\n matching: result.identical,\n deleted: result.deleteListed,\n },\n };\n}\n\n// @awa-impl: JSON-5_AC-1\nexport function formatGenerationSummary(result: GenerationResult): string {\n return `created: ${result.created}, overwritten: ${result.overwritten}, skipped: ${result.skipped}, deleted: ${result.deleted}`;\n}\n\n// @awa-impl: JSON-5_AC-1\nexport function formatDiffSummary(result: DiffResult): string {\n return `changed: ${result.modified}, new: ${result.newFiles}, matching: ${result.identical}, deleted: ${result.deleteListed}`;\n}\n\n// @awa-impl: JSON-8_AC-1\nexport function writeJsonOutput(data: GenerationJSON | DiffJSON): void {\n process.stdout.write(`${JSON.stringify(data, null, 2)}\\n`);\n}\n","// @awa-component: OVL-OverlayResolver\n// @awa-component: OVL-MergedTemplateView\n// @awa-impl: OVL-1_AC-1\n// @awa-impl: OVL-2_AC-1\n// @awa-impl: OVL-3_AC-1\n// @awa-impl: OVL-4_AC-1\n// @awa-impl: OVL-5_AC-1\n// @awa-impl: OVL-6_AC-1\n\nimport { cp } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { ensureDir } from '../utils/fs.js';\nimport { templateResolver } from './template-resolver.js';\n\n/**\n * Resolve each overlay source string to a local directory path.\n * Delegates to TemplateResolver so local paths and Git sources are both handled.\n *\n * @awa-impl: OVL-1_AC-1, OVL-6_AC-1\n */\nexport async function resolveOverlays(overlays: string[], refresh: boolean): Promise<string[]> {\n const dirs: string[] = [];\n for (const source of overlays) {\n const resolved = await templateResolver.resolve(source, refresh);\n dirs.push(resolved.localPath);\n }\n return dirs;\n}\n\n/**\n * Build a temporary merged directory by copying baseDir then applying each\n * overlay in order. Later overlay files overwrite earlier ones at the same\n * relative path; base-only files are left intact; overlay-only files are added.\n *\n * Caller is responsible for cleaning up the returned temp directory.\n *\n * @awa-impl: OVL-2_AC-1, OVL-3_AC-1, OVL-4_AC-1, OVL-5_AC-1\n */\nexport async function buildMergedDir(baseDir: string, overlayDirs: string[]): Promise<string> {\n const timestamp = Date.now();\n const random = Math.random().toString(36).substring(2, 8);\n const tempPath = join(tmpdir(), `awa-overlay-${timestamp}-${random}`);\n\n await ensureDir(tempPath);\n\n // Copy base template files into the temp directory\n await cp(baseDir, tempPath, { recursive: true });\n\n // Apply overlays in order — later overlays win (force: true is the default for fs.cp)\n for (const overlayDir of overlayDirs) {\n await cp(overlayDir, tempPath, { recursive: true });\n }\n\n return tempPath;\n}\n","// @awa-component: TPL-TemplateResolver\n// @awa-impl: CLI-3_AC-2\n// @awa-impl: CLI-3_AC-3\n// @awa-impl: CLI-8_AC-2\n// @awa-impl: TPL-1_AC-1\n// @awa-impl: TPL-1_AC-2\n// @awa-impl: TPL-1_AC-3\n// @awa-impl: TPL-1_AC-4\n// @awa-impl: TPL-2_AC-1\n// @awa-impl: TPL-2_AC-2\n// @awa-impl: TPL-2_AC-3\n// @awa-impl: TPL-2_AC-4\n// @awa-impl: TPL-2_AC-5\n// @awa-impl: TPL-2_AC-6\n// @awa-impl: TPL-3_AC-1\n// @awa-impl: TPL-3_AC-2\n// @awa-impl: TPL-3_AC-3\n// @awa-impl: TPL-3_AC-4\n// @awa-impl: TPL-10_AC-1\n// @awa-impl: TPL-10_AC-2\n// @awa-impl: TPL-10_AC-3\n\nimport { createHash } from 'node:crypto';\nimport { rm } from 'node:fs/promises';\nimport { isAbsolute, join, resolve } from 'node:path';\nimport degit from 'degit';\nimport { type ResolvedTemplate, TemplateError, type TemplateSourceType } from '../types/index.js';\nimport { ensureDir, getCacheDir, getTemplateDir, pathExists } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\nexport class TemplateResolver {\n // @awa-impl: CLI-3_AC-2, TPL-10_AC-1\n async resolve(source: string | null, refresh: boolean): Promise<ResolvedTemplate> {\n // If no source provided, use bundled templates\n if (!source) {\n const bundledPath = join(getTemplateDir(), 'awa');\n return {\n type: 'bundled',\n localPath: bundledPath,\n source: 'bundled',\n };\n }\n\n const type = this.detectType(source);\n\n // @awa-impl: TPL-1_AC-1, TPL-1_AC-2, TPL-1_AC-3, TPL-1_AC-4\n if (type === 'local') {\n // Resolve relative/absolute paths\n const localPath = isAbsolute(source) ? source : resolve(process.cwd(), source);\n\n // Check if path exists\n if (!(await pathExists(localPath))) {\n throw new TemplateError(\n `Template source not found: ${localPath}`,\n 'SOURCE_NOT_FOUND',\n source\n );\n }\n\n // Local templates are not cached\n return {\n type: 'local',\n localPath,\n source,\n };\n }\n\n // @awa-impl: TPL-2_AC-1, TPL-2_AC-2, TPL-2_AC-3, TPL-2_AC-4, TPL-2_AC-5, TPL-2_AC-6, TPL-3_AC-1, TPL-3_AC-2, TPL-3_AC-3, TPL-3_AC-4\n if (type === 'git') {\n const cachePath = this.getCachePath(source);\n\n // @awa-impl: CLI-8_AC-2, TPL-3_AC-2\n // Check if cached version exists\n const cacheExists = await pathExists(cachePath);\n\n if (cacheExists && !refresh) {\n // Use cached version\n logger.info(`Using cached template: ${source}`);\n return {\n type: 'git',\n localPath: cachePath,\n source,\n };\n }\n\n // Fetch from Git\n try {\n // Remove existing cache if refresh\n if (cacheExists && refresh) {\n logger.info(`Refreshing template: ${source}`);\n await rm(cachePath, { recursive: true, force: true });\n } else {\n logger.info(`Fetching template: ${source}`);\n }\n\n await ensureDir(cachePath);\n\n // Use degit for shallow fetch\n const emitter = degit(source, { cache: false, force: true });\n await emitter.clone(cachePath);\n\n return {\n type: 'git',\n localPath: cachePath,\n source,\n };\n } catch (error) {\n throw new TemplateError(\n `Failed to fetch Git template: ${error instanceof Error ? error.message : String(error)}`,\n 'FETCH_FAILED',\n source\n );\n }\n }\n\n throw new TemplateError(\n `Unable to resolve template source: ${source}`,\n 'SOURCE_NOT_FOUND',\n source\n );\n }\n\n // @awa-impl: TPL-2_AC-1, TPL-2_AC-2, TPL-2_AC-3, TPL-2_AC-4, TPL-2_AC-5, TPL-2_AC-6\n detectType(source: string): TemplateSourceType {\n // Check for local path indicators\n if (source.startsWith('.') || source.startsWith('/') || source.startsWith('~')) {\n return 'local';\n }\n\n // Check for Windows absolute paths\n if (/^[a-zA-Z]:/.test(source)) {\n return 'local';\n }\n\n // All other formats are treated as Git sources:\n // - GitHub shorthand: owner/repo\n // - Prefixed: github:owner/repo, gitlab:owner/repo, bitbucket:owner/repo\n // - HTTPS: https://github.com/owner/repo\n // - SSH: git@github.com:owner/repo\n // - With subdirs: owner/repo/path/to/templates\n // - With refs: owner/repo#branch\n return 'git';\n }\n\n // @awa-impl: TPL-3_AC-1\n getCachePath(source: string): string {\n // Create a stable cache path based on source hash\n const hash = createHash('sha256').update(source).digest('hex').substring(0, 16);\n const cacheDir = getCacheDir();\n return join(cacheDir, hash);\n }\n}\n\nexport const templateResolver = new TemplateResolver();\n","// @awa-component: DIFF-FileWatcher\n// @awa-impl: DIFF-7_AC-10\n\nimport { type FSWatcher, watch } from 'node:fs';\nimport { Debouncer } from './debouncer.js';\n\nexport interface FileWatcherOptions {\n directory: string;\n debounceMs?: number;\n onChange: () => void;\n}\n\nexport class FileWatcher {\n private watcher: FSWatcher | null = null;\n private debouncer: Debouncer;\n private readonly directory: string;\n private readonly onChange: () => void;\n\n constructor(options: FileWatcherOptions) {\n this.directory = options.directory;\n this.debouncer = new Debouncer(options.debounceMs ?? 300);\n this.onChange = options.onChange;\n }\n\n start(): void {\n this.watcher = watch(this.directory, { recursive: true }, () => {\n this.debouncer.trigger(this.onChange);\n });\n }\n\n stop(): void {\n this.debouncer.cancel();\n if (this.watcher) {\n this.watcher.close();\n this.watcher = null;\n }\n }\n}\n","// @awa-component: DIFF-Debouncer\n// @awa-impl: DIFF-7_AC-10\n\nexport class Debouncer {\n private timer: ReturnType<typeof setTimeout> | null = null;\n\n constructor(private readonly delayMs: number) {}\n\n trigger(callback: () => void): void {\n if (this.timer) {\n clearTimeout(this.timer);\n }\n this.timer = setTimeout(() => {\n this.timer = null;\n callback();\n }, this.delayMs);\n }\n\n cancel(): void {\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n }\n}\n","// @awa-component: DISC-FeaturesCommand\n// @awa-impl: DISC-4_AC-1\n// @awa-impl: DISC-5_AC-1\n// @awa-impl: DISC-8_AC-1\n\nimport { intro, outro } from '@clack/prompts';\nimport { configLoader } from '../core/config.js';\nimport { featuresReporter } from '../core/features/reporter.js';\nimport { featureScanner } from '../core/features/scanner.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport { rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\nexport interface FeaturesCommandOptions {\n template?: string;\n config?: string;\n refresh?: boolean;\n json?: boolean;\n summary?: boolean;\n overlay?: string[];\n}\n\n// @awa-impl: DISC-4_AC-1, DISC-5_AC-1\nexport async function featuresCommand(cliOptions: FeaturesCommandOptions): Promise<number> {\n let mergedDir: string | null = null;\n\n try {\n const silent = cliOptions.json || cliOptions.summary;\n\n if (!silent) {\n intro('awa CLI - Feature Discovery');\n }\n\n // Load configuration file (for presets and default template)\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // Resolve template source — reuse same resolver as generate/diff\n const templateSource = cliOptions.template ?? fileConfig?.template ?? null;\n const refresh = cliOptions.refresh ?? fileConfig?.refresh ?? false;\n const template = await templateResolver.resolve(templateSource, refresh);\n\n // Build merged dir if overlays are specified\n const overlays = cliOptions.overlay ?? fileConfig?.overlay ?? [];\n let templatePath = template.localPath;\n if (overlays.length > 0) {\n const overlayDirs = await resolveOverlays(overlays, refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n // Scan template for feature flags\n const scanResult = await featureScanner.scan(templatePath);\n\n // Retrieve preset definitions from config if available\n const presets = fileConfig?.presets;\n\n // Report results\n if (cliOptions.summary) {\n console.log(\n `features: ${scanResult.features.length}, files-scanned: ${scanResult.filesScanned}`\n );\n } else {\n featuresReporter.report({\n scanResult,\n json: cliOptions.json ?? false,\n presets,\n });\n }\n\n if (!silent) {\n outro('Feature discovery complete!');\n }\n\n return 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 1;\n } finally {\n if (mergedDir) {\n await rmDir(mergedDir);\n }\n }\n}\n","// @awa-component: DISC-Reporter\n// @awa-impl: DISC-6_AC-1\n// @awa-impl: DISC-7_AC-1\n// @awa-impl: DISC-9_AC-1\n\nimport chalk from 'chalk';\nimport type { PresetDefinitions } from '../../types/index.js';\nimport type { ScanResult } from './scanner.js';\n\n/** Options for rendering the features report. */\nexport interface ReportOptions {\n /** Scan results from the feature scanner. */\n scanResult: ScanResult;\n /** Whether to output JSON instead of a human-readable table. */\n json: boolean;\n /** Preset definitions from the user's .awa.toml, if available. */\n presets?: PresetDefinitions;\n}\n\n/** JSON output structure for --json mode. */\nexport interface FeaturesJsonOutput {\n features: Array<{\n name: string;\n files: string[];\n }>;\n presets?: Record<string, string[]>;\n filesScanned: number;\n}\n\nexport class FeaturesReporter {\n // @awa-impl: DISC-6_AC-1, DISC-7_AC-1\n /** Render the features report to stdout. */\n report(options: ReportOptions): void {\n const { scanResult, json, presets } = options;\n\n if (json) {\n this.reportJson(scanResult, presets);\n } else {\n this.reportTable(scanResult, presets);\n }\n }\n\n // @awa-impl: DISC-6_AC-1\n /** Build the JSON output object (also used by tests). */\n buildJsonOutput(scanResult: ScanResult, presets?: PresetDefinitions): FeaturesJsonOutput {\n const output: FeaturesJsonOutput = {\n features: scanResult.features.map((f) => ({\n name: f.name,\n files: f.files,\n })),\n filesScanned: scanResult.filesScanned,\n };\n\n if (presets && Object.keys(presets).length > 0) {\n output.presets = presets;\n }\n\n return output;\n }\n\n private reportJson(scanResult: ScanResult, presets?: PresetDefinitions): void {\n const output = this.buildJsonOutput(scanResult, presets);\n console.log(JSON.stringify(output, null, 2));\n }\n\n // @awa-impl: DISC-7_AC-1\n private reportTable(scanResult: ScanResult, presets?: PresetDefinitions): void {\n const { features, filesScanned } = scanResult;\n\n if (features.length === 0) {\n console.log(chalk.yellow('No feature flags found.'));\n console.log(chalk.dim(`(${filesScanned} files scanned)`));\n return;\n }\n\n console.log(chalk.bold(`Feature flags (${features.length} found):\\n`));\n\n for (const feature of features) {\n console.log(` ${chalk.cyan(feature.name)}`);\n for (const file of feature.files) {\n console.log(` ${chalk.dim(file)}`);\n }\n }\n\n console.log('');\n console.log(chalk.dim(`${filesScanned} files scanned`));\n\n // Show presets if available\n if (presets && Object.keys(presets).length > 0) {\n console.log('');\n console.log(chalk.bold('Presets (from .awa.toml):\\n'));\n for (const [name, flags] of Object.entries(presets)) {\n console.log(` ${chalk.green(name)}: ${flags.join(', ')}`);\n }\n }\n }\n}\n\nexport const featuresReporter = new FeaturesReporter();\n","// @awa-component: DISC-FeatureScanner\n// @awa-impl: DISC-1_AC-1\n// @awa-impl: DISC-2_AC-1\n// @awa-impl: DISC-3_AC-1\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\n\n/** A single feature flag discovered in a template. */\nexport interface DiscoveredFeature {\n /** The flag name (e.g. \"copilot\"). */\n name: string;\n /** Relative paths of template files that reference this flag. */\n files: string[];\n}\n\n/** Result of scanning a template directory for feature flags. */\nexport interface ScanResult {\n /** All discovered feature flags, sorted by name. */\n features: DiscoveredFeature[];\n /** Total number of template files scanned. */\n filesScanned: number;\n}\n\n// Matches: it.features.includes('name') or it.features.includes(\"name\")\n// Also matches: it.features.indexOf('name') or it.features.indexOf(\"name\")\nconst FEATURE_PATTERN = /it\\.features\\.(?:includes|indexOf)\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g;\n\n/**\n * Recursively walk a directory yielding all file paths (including those\n * starting with underscore, since partials may reference feature flags).\n */\nasync function* walkAllFiles(dir: string): AsyncGenerator<string> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n yield* walkAllFiles(fullPath);\n } else if (entry.isFile()) {\n yield fullPath;\n }\n }\n}\n\nexport class FeatureScanner {\n // @awa-impl: DISC-1_AC-1, DISC-2_AC-1\n /** Extract feature flag names from a single file's content. */\n extractFlags(content: string): string[] {\n const flags = new Set<string>();\n for (const match of content.matchAll(FEATURE_PATTERN)) {\n if (match[1]) {\n flags.add(match[1]);\n }\n }\n return [...flags];\n }\n\n // @awa-impl: DISC-1_AC-1, DISC-2_AC-1, DISC-3_AC-1\n /** Scan a template directory and return all discovered feature flags. */\n async scan(templatePath: string): Promise<ScanResult> {\n const flagToFiles = new Map<string, Set<string>>();\n let filesScanned = 0;\n\n for await (const filePath of walkAllFiles(templatePath)) {\n filesScanned++;\n try {\n const content = await readFile(filePath, 'utf-8');\n const flags = this.extractFlags(content);\n const relPath = relative(templatePath, filePath);\n for (const flag of flags) {\n const existing = flagToFiles.get(flag);\n if (existing) {\n existing.add(relPath);\n } else {\n flagToFiles.set(flag, new Set([relPath]));\n }\n }\n } catch {\n // Skip binary files or files that can't be read as UTF-8\n }\n }\n\n const features: DiscoveredFeature[] = [...flagToFiles.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, files]) => ({\n name,\n files: [...files].sort(),\n }));\n\n return { features, filesScanned };\n }\n}\n\nexport const featureScanner = new FeatureScanner();\n","// @awa-component: GEN-GenerateCommand\n// @awa-component: JSON-GenerateCommand\n// @awa-component: INIT-ConfigHint\n// @awa-component: MULTI-GenerateCommand\n// @awa-impl: INIT-5_AC-1\n// @awa-impl: MULTI-6_AC-1\n// @awa-impl: MULTI-10_AC-1\n// @awa-impl: CHK-1_AC-2\n// @awa-impl: CHK-1_AC-3\n// @awa-impl: CHK-5_AC-2\n// @awa-impl: CHK-5_AC-3\n\nimport { intro, isCancel, multiselect, outro } from '@clack/prompts';\nimport { batchRunner } from '../core/batch-runner.js';\nimport { configLoader } from '../core/config.js';\nimport { featureResolver } from '../core/feature-resolver.js';\nimport { fileGenerator } from '../core/generator.js';\nimport {\n formatGenerationSummary,\n serializeGenerationResult,\n writeJsonOutput,\n} from '../core/json-output.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport type { RawCliOptions, ResolvedOptions } from '../types/index.js';\nimport { rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\n/** Known AI tool feature flags for interactive selection. */\nconst TOOL_FEATURES = [\n { value: 'copilot', label: 'GitHub Copilot' },\n { value: 'claude', label: 'Claude Code' },\n { value: 'cursor', label: 'Cursor' },\n { value: 'windsurf', label: 'Windsurf' },\n { value: 'kilocode', label: 'Kilocode' },\n { value: 'opencode', label: 'OpenCode' },\n { value: 'gemini', label: 'Gemini CLI' },\n { value: 'roo', label: 'Roo Code' },\n { value: 'qwen', label: 'Qwen Code' },\n { value: 'codex', label: 'Codex CLI' },\n { value: 'agy', label: 'Antigravity (agy)' },\n { value: 'agents-md', label: 'AGENTS.md (cross-tool)' },\n] as const;\n\nconst TOOL_FEATURE_VALUES = new Set<string>(TOOL_FEATURES.map((t) => t.value));\n\nasync function runGenerate(options: ResolvedOptions, batchMode: boolean): Promise<void> {\n const silent = options.json || options.summary;\n\n // Resolve template source\n const template = await templateResolver.resolve(options.template, options.refresh);\n\n const features = featureResolver.resolve({\n baseFeatures: [...options.features],\n presetNames: [...options.preset],\n removeFeatures: [...options.removeFeatures],\n presetDefinitions: options.presets,\n });\n\n // @awa-impl: MTT-1_AC-1 // @awa-ignore\n // If no tool feature flag is present, prompt the user to select tools interactively\n // In batch mode (--all / --target), skip prompting\n // @awa-impl: JSON-6_AC-1\n if (!batchMode) {\n const hasToolFlag = features.some((f) => TOOL_FEATURE_VALUES.has(f));\n if (!hasToolFlag && !silent) {\n const selected = await multiselect({\n message: 'Select AI tools to generate for (space to toggle, enter to confirm):',\n options: TOOL_FEATURES.map((t) => ({ value: t.value, label: t.label })),\n required: true,\n });\n if (isCancel(selected)) {\n logger.info('Generation cancelled.');\n process.exit(0);\n }\n features.push(...(selected as string[]));\n }\n }\n\n // @awa-impl: JSON-7_AC-1\n // --json implies --dry-run for generate\n const effectiveDryRun = options.json || options.dryRun;\n\n // Display mode indicators\n if (!silent) {\n if (effectiveDryRun) {\n logger.info('Running in dry-run mode (no files will be modified)');\n }\n if (options.force) {\n logger.info('Force mode enabled (existing files will be overwritten)');\n }\n }\n\n // @awa-impl: OVL-2_AC-1\n // Build merged template dir if overlays are specified\n let mergedDir: string | null = null;\n let templatePath = template.localPath;\n if (options.overlay.length > 0) {\n const overlayDirs = await resolveOverlays([...options.overlay], options.refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n try {\n // Generate files\n const result = await fileGenerator.generate({\n templatePath,\n outputPath: options.output,\n features,\n force: options.force,\n dryRun: effectiveDryRun,\n delete: options.delete,\n });\n\n // @awa-impl: JSON-1_AC-1, JSON-8_AC-1\n if (options.json) {\n writeJsonOutput(serializeGenerationResult(result));\n } else if (options.summary) {\n // @awa-impl: JSON-5_AC-1\n console.log(formatGenerationSummary(result));\n } else {\n // Display summary\n logger.summary(result);\n }\n } finally {\n // Clean up merged overlay temp directory\n if (mergedDir) {\n try {\n await rmDir(mergedDir);\n } catch {\n // Swallow cleanup errors — temp dir will be cleaned by OS eventually\n }\n }\n }\n}\n\nexport async function generateCommand(cliOptions: RawCliOptions): Promise<void> {\n try {\n // Load configuration file\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // @awa-impl: INIT-5_AC-1\n // Non-blocking hint when no config file is present and --config was not provided\n if (!cliOptions.config && fileConfig === null) {\n logger.info('Tip: create .awa.toml to save your options for next time.');\n }\n\n // Batch mode: --all or --target\n if (cliOptions.allTargets || cliOptions.target) {\n const mode = cliOptions.allTargets ? 'all' : 'single';\n const targets = batchRunner.resolveTargets(cliOptions, fileConfig, mode, cliOptions.target);\n\n for (const { targetName, options } of targets) {\n batchRunner.logForTarget(targetName, 'Starting generation...');\n await runGenerate(options, true);\n batchRunner.logForTarget(targetName, 'Generation complete.');\n }\n\n outro('All targets generated!');\n return;\n }\n\n // Standard single-target mode (backward compatible)\n const options = configLoader.merge(cliOptions, fileConfig);\n\n const silent = options.json || options.summary;\n\n // @awa-impl: JSON-6_AC-1\n // Suppress interactive output when --json or --summary is active\n if (!silent) {\n intro('awa CLI - Template Generator');\n }\n\n await runGenerate(options, false);\n\n if (!silent) {\n outro('Generation complete!');\n }\n } catch (error) {\n // @awa-impl: JSON-8_AC-1\n // Error handling with proper exit codes — errors always go to stderr\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n process.exit(1);\n }\n}\n","// @awa-component: TTST-TestCommand\n// @awa-impl: TTST-7_AC-1\n// @awa-impl: TTST-9_AC-1\n// @awa-impl: TTST-11_AC-1\n// @awa-impl: TTST-12_AC-1\n\nimport { intro, outro } from '@clack/prompts';\nimport { configLoader } from '../core/config.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport { discoverFixtures } from '../core/template-test/fixture-loader.js';\nimport { report } from '../core/template-test/reporter.js';\nimport { runAll } from '../core/template-test/runner.js';\nimport type { RawTestOptions } from '../core/template-test/types.js';\nimport { rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\n// @awa-impl: TTST-7_AC-1\nexport async function testCommand(options: RawTestOptions): Promise<number> {\n let mergedDir: string | null = null;\n\n try {\n const isJson = options.json === true;\n const isSummary = options.summary === true;\n const silent = isJson || isSummary;\n\n if (!silent) {\n intro('awa CLI - Template Test');\n }\n\n // Load configuration file\n const fileConfig = await configLoader.load(options.config ?? null);\n const templateSource = options.template ?? fileConfig?.template ?? null;\n\n // Resolve template source\n const refresh = options.refresh ?? false;\n const template = await templateResolver.resolve(templateSource, refresh);\n\n // Build merged dir if overlays are specified\n const overlays = options.overlay ?? fileConfig?.overlay ?? [];\n let templatePath = template.localPath;\n if (overlays.length > 0) {\n const overlayDirs = await resolveOverlays(overlays, refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n // Discover fixtures\n const fixtures = await discoverFixtures(templatePath);\n\n if (fixtures.length === 0) {\n if (isSummary) {\n console.log('passed: 0, failed: 0, total: 0');\n } else if (isJson) {\n console.log(JSON.stringify({ total: 0, passed: 0, failed: 0, results: [] }, null, 2));\n } else {\n logger.warn('No test fixtures found in _tests/ directory');\n outro('No tests to run.');\n }\n return 0;\n }\n\n if (!silent) {\n logger.info(`Found ${fixtures.length} fixture(s)`);\n }\n\n // Extract preset definitions from config\n const presetDefinitions = fileConfig?.presets ?? {};\n\n // Run all fixtures\n const result = await runAll(\n fixtures,\n templatePath,\n { updateSnapshots: options.updateSnapshots },\n presetDefinitions\n );\n\n // Report results\n if (isSummary) {\n console.log(`passed: ${result.passed}, failed: ${result.failed}, total: ${result.total}`);\n } else {\n report(result, { json: isJson });\n }\n\n if (result.failed > 0) {\n if (!silent) {\n outro(`${result.failed} fixture(s) failed.`);\n }\n return 1;\n }\n\n if (!silent) {\n outro('All tests passed!');\n }\n return 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 2;\n } finally {\n if (mergedDir) {\n await rmDir(mergedDir);\n }\n }\n}\n","// @awa-component: TTST-FixtureLoader\n// @awa-impl: TTST-1_AC-1\n// @awa-impl: TTST-2_AC-1\n\nimport { readdir } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\nimport { parse } from 'smol-toml';\nimport { readTextFile } from '../../utils/fs.js';\nimport type { TestFixture } from './types.js';\n\n// @awa-impl: TTST-1_AC-1\nexport async function discoverFixtures(templatePath: string): Promise<TestFixture[]> {\n const testsDir = join(templatePath, '_tests');\n\n let entries: string[];\n try {\n const dirEntries = await readdir(testsDir, { withFileTypes: true });\n entries = dirEntries\n .filter((e) => e.isFile() && extname(e.name) === '.toml')\n .map((e) => e.name)\n .sort();\n } catch {\n // _tests/ directory doesn't exist — no fixtures\n return [];\n }\n\n const fixtures: TestFixture[] = [];\n for (const filename of entries) {\n const filePath = join(testsDir, filename);\n const fixture = await parseFixture(filePath);\n fixtures.push(fixture);\n }\n\n return fixtures;\n}\n\n// @awa-impl: TTST-2_AC-1\nexport async function parseFixture(filePath: string): Promise<TestFixture> {\n const content = await readTextFile(filePath);\n const parsed = parse(content) as Record<string, unknown>;\n\n const name = basename(filePath, extname(filePath));\n\n const features = toStringArray(parsed.features) ?? [];\n const preset = toStringArray(parsed.preset) ?? [];\n const removeFeatures = toStringArray(parsed['remove-features']) ?? [];\n const expectedFiles = toStringArray(parsed['expected-files']) ?? [];\n\n return {\n name,\n features,\n preset,\n removeFeatures,\n expectedFiles,\n filePath,\n };\n}\n\nfunction toStringArray(value: unknown): string[] | null {\n if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {\n return value as string[];\n }\n return null;\n}\n","// @awa-component: TTST-Reporter\n// @awa-impl: TTST-6_AC-1\n// @awa-impl: TTST-10_AC-1\n\nimport chalk from 'chalk';\nimport type { FixtureResult, TestSuiteResult } from './types.js';\n\n// @awa-impl: TTST-6_AC-1\nexport function report(result: TestSuiteResult, options?: { json?: boolean }): void {\n if (options?.json) {\n reportJson(result);\n return;\n }\n\n console.log('');\n\n for (const fixture of result.results) {\n reportFixture(fixture);\n }\n\n // Summary\n console.log('');\n console.log(chalk.bold('Test Summary:'));\n console.log(` Total: ${result.total}`);\n console.log(chalk.green(` Passed: ${result.passed}`));\n if (result.failed > 0) {\n console.log(chalk.red(` Failed: ${result.failed}`));\n }\n console.log('');\n}\n\nfunction reportJson(result: TestSuiteResult): void {\n const output = {\n total: result.total,\n passed: result.passed,\n failed: result.failed,\n results: result.results.map((r) => ({\n name: r.name,\n passed: r.passed,\n ...(r.error ? { error: r.error } : {}),\n fileResults: r.fileResults.map((f) => ({\n path: f.path,\n found: f.found,\n })),\n snapshotResults: r.snapshotResults.map((s) => ({\n path: s.path,\n status: s.status,\n })),\n })),\n };\n console.log(JSON.stringify(output, null, 2));\n}\n\nfunction reportFixture(fixture: FixtureResult): void {\n const icon = fixture.passed ? chalk.green('✔') : chalk.red('✖');\n console.log(`${icon} ${fixture.name}`);\n\n if (fixture.error) {\n console.log(chalk.red(` Error: ${fixture.error}`));\n return;\n }\n\n // Report missing files\n const missingFiles = fixture.fileResults.filter((r) => !r.found);\n for (const missing of missingFiles) {\n console.log(chalk.red(` Missing file: ${missing.path}`));\n }\n\n // Report snapshot mismatches\n const snapshotFailures = fixture.snapshotResults.filter((r) => r.status !== 'match');\n for (const failure of snapshotFailures) {\n switch (failure.status) {\n case 'mismatch':\n console.log(chalk.yellow(` Snapshot mismatch: ${failure.path}`));\n break;\n case 'missing-snapshot':\n console.log(chalk.yellow(` Missing snapshot: ${failure.path}`));\n break;\n case 'extra-snapshot':\n console.log(chalk.yellow(` Extra snapshot (not in output): ${failure.path}`));\n break;\n }\n }\n}\n","// @awa-component: TTST-TestRunner\n// @awa-impl: TTST-3_AC-1\n// @awa-impl: TTST-4_AC-1\n// @awa-impl: TTST-5_AC-1\n// @awa-impl: TTST-8_AC-1\n\nimport { mkdir, rm } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathExists } from '../../utils/fs.js';\nimport { featureResolver } from '../feature-resolver.js';\nimport { fileGenerator } from '../generator.js';\nimport { compareSnapshots, updateSnapshots } from './snapshot.js';\nimport type {\n FileAssertionResult,\n FixtureResult,\n SnapshotFileResult,\n TestFixture,\n TestRunOptions,\n TestSuiteResult,\n} from './types.js';\n\n// @awa-impl: TTST-3_AC-1\nexport async function runFixture(\n fixture: TestFixture,\n templatePath: string,\n options: TestRunOptions,\n presetDefinitions: Record<string, string[]> = {}\n): Promise<FixtureResult> {\n const tempDir = join(tmpdir(), `awa-test-${fixture.name}-${Date.now()}`);\n\n try {\n await mkdir(tempDir, { recursive: true });\n\n // Resolve features using presets and remove-features\n const features = featureResolver.resolve({\n baseFeatures: [...fixture.features],\n presetNames: [...fixture.preset],\n removeFeatures: [...fixture.removeFeatures],\n presetDefinitions,\n });\n\n // Render templates to temp dir\n await fileGenerator.generate({\n templatePath,\n outputPath: tempDir,\n features,\n force: true,\n dryRun: false,\n delete: false,\n });\n\n // @awa-impl: TTST-4_AC-1\n // Check expected files\n const fileResults: FileAssertionResult[] = [];\n for (const expectedFile of fixture.expectedFiles) {\n const fullPath = join(tempDir, expectedFile);\n const found = await pathExists(fullPath);\n fileResults.push({ path: expectedFile, found });\n }\n\n const missingFiles = fileResults.filter((r) => !r.found);\n\n // @awa-impl: TTST-5_AC-1\n // Snapshot comparison\n const snapshotDir = join(templatePath, '_tests', fixture.name);\n let snapshotResults: SnapshotFileResult[] = [];\n if (options.updateSnapshots) {\n await updateSnapshots(tempDir, snapshotDir);\n } else if (await pathExists(snapshotDir)) {\n snapshotResults = await compareSnapshots(tempDir, snapshotDir);\n }\n\n const snapshotFailures = snapshotResults.filter((r) => r.status !== 'match');\n\n const passed = missingFiles.length === 0 && snapshotFailures.length === 0;\n\n return {\n name: fixture.name,\n passed,\n fileResults,\n snapshotResults,\n };\n } catch (error) {\n return {\n name: fixture.name,\n passed: false,\n fileResults: [],\n snapshotResults: [],\n error: error instanceof Error ? error.message : String(error),\n };\n } finally {\n // Clean up temp dir\n await rm(tempDir, { recursive: true, force: true }).catch(() => {});\n }\n}\n\nexport async function runAll(\n fixtures: TestFixture[],\n templatePath: string,\n options: TestRunOptions,\n presetDefinitions: Record<string, string[]> = {}\n): Promise<TestSuiteResult> {\n const results: FixtureResult[] = [];\n\n for (const fixture of fixtures) {\n const result = await runFixture(fixture, templatePath, options, presetDefinitions);\n results.push(result);\n }\n\n const passed = results.filter((r) => r.passed).length;\n const failed = results.filter((r) => !r.passed).length;\n\n return {\n results,\n total: results.length,\n passed,\n failed,\n };\n}\n","// @awa-component: TTST-TestRunner\n// @awa-impl: TTST-5_AC-1\n\nimport { mkdir, readdir, rm } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { pathExists, readTextFile, writeTextFile } from '../../utils/fs.js';\nimport type { SnapshotFileResult } from './types.js';\n\n/** Walk a directory recursively and yield relative file paths. */\nasync function walkRelative(dir: string, base: string): Promise<string[]> {\n const results: string[] = [];\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n const sub = await walkRelative(fullPath, base);\n results.push(...sub);\n } else if (entry.isFile()) {\n results.push(relative(base, fullPath));\n }\n }\n\n return results;\n}\n\n// @awa-impl: TTST-5_AC-1\nexport async function compareSnapshots(\n renderedDir: string,\n snapshotDir: string\n): Promise<SnapshotFileResult[]> {\n const results: SnapshotFileResult[] = [];\n\n const renderedFiles = await walkRelative(renderedDir, renderedDir);\n const snapshotFiles = await walkRelative(snapshotDir, snapshotDir);\n\n const snapshotSet = new Set(snapshotFiles);\n const renderedSet = new Set(renderedFiles);\n\n // Check rendered files against snapshots\n for (const file of renderedFiles) {\n const renderedPath = join(renderedDir, file);\n const snapshotPath = join(snapshotDir, file);\n\n if (!snapshotSet.has(file)) {\n results.push({ path: file, status: 'missing-snapshot' });\n continue;\n }\n\n const renderedContent = await readTextFile(renderedPath);\n const snapshotContent = await readTextFile(snapshotPath);\n\n results.push({\n path: file,\n status: renderedContent === snapshotContent ? 'match' : 'mismatch',\n });\n }\n\n // Check for extra snapshot files not in rendered output\n for (const file of snapshotFiles) {\n if (!renderedSet.has(file)) {\n results.push({ path: file, status: 'extra-snapshot' });\n }\n }\n\n return results;\n}\n\n// @awa-impl: TTST-5_AC-1\nexport async function updateSnapshots(renderedDir: string, snapshotDir: string): Promise<void> {\n // Remove existing snapshot directory\n if (await pathExists(snapshotDir)) {\n await rm(snapshotDir, { recursive: true, force: true });\n }\n\n await mkdir(snapshotDir, { recursive: true });\n\n // Copy rendered files to snapshot directory\n const files = await walkRelative(renderedDir, renderedDir);\n for (const file of files) {\n const srcPath = join(renderedDir, file);\n const destPath = join(snapshotDir, file);\n const content = await readTextFile(srcPath);\n await writeTextFile(destPath, content);\n }\n}\n","// @awa-component: TRC-ContentAssembler\n// @awa-impl: TRC-5_AC-1, TRC-5_AC-2, TRC-5_AC-3, TRC-5_AC-4, TRC-5_AC-5\n\nimport { readFile } from 'node:fs/promises';\nimport type { ContentSection, TraceResult } from './types.js';\n\n/** Default lines of context before a code marker. */\nconst DEFAULT_BEFORE_CONTEXT = 5;\n/** Default lines of context after a code marker. */\nconst DEFAULT_AFTER_CONTEXT = 20;\n\n/** Options for controlling code context extraction. */\ninterface ContextLineOptions {\n readonly beforeContext?: number;\n readonly afterContext?: number;\n}\n\n/**\n * Assemble content sections from a trace result by reading the actual files.\n * Returns ContentSections sorted by priority (lowest number = highest priority).\n */\nexport async function assembleContent(\n result: TraceResult,\n taskPath?: string,\n contextOptions?: ContextLineOptions\n): Promise<ContentSection[]> {\n const beforeCtx = contextOptions?.beforeContext ?? DEFAULT_BEFORE_CONTEXT;\n const afterCtx = contextOptions?.afterContext ?? DEFAULT_AFTER_CONTEXT;\n const sections: ContentSection[] = [];\n const seen = new Set<string>();\n\n // Priority 1: Task file — full content\n if (taskPath) {\n const content = await safeReadFile(taskPath);\n if (content) {\n const lineCount = content.split('\\n').length;\n sections.push({\n type: 'task',\n filePath: taskPath,\n startLine: 1,\n endLine: lineCount,\n content,\n priority: 1,\n });\n }\n }\n\n for (const chain of result.chains) {\n // Priority 2: Requirement\n if (chain.requirement) {\n const key = `req:${chain.requirement.location.filePath}:${chain.requirement.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractSpecSection(\n chain.requirement.location.filePath,\n chain.requirement.id,\n chain.requirement.location.line,\n 'requirement',\n 2\n );\n if (section) sections.push(section);\n }\n }\n\n // Also include ACs under requirement (they're typically in the same section)\n for (const ac of chain.acs) {\n const key = `ac:${ac.location.filePath}:${ac.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n // ACs are part of the requirement section — only add if different from requirement\n if (!chain.requirement || ac.location.filePath !== chain.requirement.location.filePath) {\n const section = await extractSpecSection(\n ac.location.filePath,\n ac.id,\n ac.location.line,\n 'requirement',\n 2\n );\n if (section) sections.push(section);\n }\n }\n }\n\n // Priority 3: Design components\n for (const comp of chain.designComponents) {\n const key = `design:${comp.location.filePath}:${comp.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractSpecSection(\n comp.location.filePath,\n comp.id,\n comp.location.line,\n 'design',\n 3\n );\n if (section) sections.push(section);\n }\n }\n\n // Priority 5: Implementation code\n for (const impl of chain.implementations) {\n const key = `impl:${impl.location.filePath}:${impl.location.line}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractCodeSection(\n impl.location.filePath,\n impl.location.line,\n 'implementation',\n 5,\n beforeCtx,\n afterCtx\n );\n if (section) sections.push(section);\n }\n }\n\n // Priority 6: Test code\n for (const t of chain.tests) {\n const key = `test:${t.location.filePath}:${t.location.line}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractCodeSection(\n t.location.filePath,\n t.location.line,\n 'test',\n 6,\n beforeCtx,\n afterCtx\n );\n if (section) sections.push(section);\n }\n }\n\n // Priority 5 (properties are also design-level) → tests already covered\n for (const prop of chain.properties) {\n const key = `prop:${prop.location.filePath}:${prop.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractSpecSection(\n prop.location.filePath,\n prop.id,\n prop.location.line,\n 'design',\n 3\n );\n if (section) sections.push(section);\n }\n }\n }\n\n // Sort by priority\n sections.sort((a, b) => a.priority - b.priority);\n\n return sections;\n}\n\n/**\n * Extract an H3 section from a spec file starting at or near the given line.\n * Reads from the H3 heading to the next H3 or H2 heading.\n */\nasync function extractSpecSection(\n filePath: string,\n _id: string,\n line: number,\n type: ContentSection['type'],\n priority: number\n): Promise<ContentSection | null> {\n const content = await safeReadFile(filePath);\n if (!content) return null;\n\n const lines = content.split('\\n');\n\n // Find the H3 heading at or before the given line\n let startIdx = line - 1;\n while (startIdx >= 0 && !/^###\\s/.test(lines[startIdx] ?? '')) {\n startIdx--;\n }\n if (startIdx < 0) startIdx = Math.max(0, line - 1);\n\n // Find the end: next H2 or H3 heading\n let endIdx = startIdx + 1;\n while (endIdx < lines.length) {\n const l = lines[endIdx] ?? '';\n if (/^#{2,3}\\s/.test(l) && endIdx > startIdx) break;\n endIdx++;\n }\n\n const sectionContent = lines.slice(startIdx, endIdx).join('\\n').trimEnd();\n\n return {\n type,\n filePath,\n startLine: startIdx + 1,\n endLine: endIdx,\n content: sectionContent,\n priority,\n };\n}\n\n/**\n * Extract a code section around a marker line.\n * Tries to find the enclosing function/block; falls back to +/- DEFAULT_CONTEXT_LINES.\n */\nasync function extractCodeSection(\n filePath: string,\n line: number,\n type: ContentSection['type'],\n priority: number,\n beforeContext: number = DEFAULT_BEFORE_CONTEXT,\n afterContext: number = DEFAULT_AFTER_CONTEXT\n): Promise<ContentSection | null> {\n const content = await safeReadFile(filePath);\n if (!content) return null;\n\n const lines = content.split('\\n');\n const lineIdx = line - 1;\n\n // Try to find enclosing function/block\n const range = findEnclosingBlock(lines, lineIdx, beforeContext, afterContext);\n\n const sectionContent = lines\n .slice(range.start, range.end + 1)\n .join('\\n')\n .trimEnd();\n\n return {\n type,\n filePath,\n startLine: range.start + 1,\n endLine: range.end + 1,\n content: sectionContent,\n priority,\n };\n}\n\n/**\n * Find the enclosing function or block around a given line index.\n * Uses simple brace-counting heuristic. Falls back to context window.\n */\nfunction findEnclosingBlock(\n lines: string[],\n lineIdx: number,\n beforeContext: number = DEFAULT_BEFORE_CONTEXT,\n afterContext: number = DEFAULT_AFTER_CONTEXT\n): { start: number; end: number } {\n // Search upward for a function-like declaration\n let start = lineIdx;\n for (let i = lineIdx; i >= 0; i--) {\n const l = lines[i] ?? '';\n // Detect function/method declarations, class declarations, test blocks\n if (\n /^\\s*(export\\s+)?(async\\s+)?function\\s/.test(l) ||\n /^\\s*(export\\s+)?(const|let|var)\\s+\\w+\\s*=\\s*(async\\s+)?\\(/.test(l) ||\n /^\\s*(describe|test|it)\\s*\\(/.test(l) ||\n /^\\s*(export\\s+)?class\\s/.test(l) ||\n /^\\s*(export\\s+)?(const|let|var)\\s+\\w+\\s*=\\s*(async\\s+)?function/.test(l)\n ) {\n start = i;\n break;\n }\n // Don't search too far up\n if (lineIdx - i > 50) {\n start = Math.max(0, lineIdx - beforeContext);\n break;\n }\n }\n\n // Search downward for the closing brace at the same level\n let braceCount = 0;\n let foundOpen = false;\n let end = lineIdx;\n\n for (let i = start; i < lines.length; i++) {\n const l = lines[i] ?? '';\n for (const ch of l) {\n if (ch === '{') {\n braceCount++;\n foundOpen = true;\n } else if (ch === '}') {\n braceCount--;\n }\n }\n if (foundOpen && braceCount <= 0) {\n end = i;\n break;\n }\n // Don't search too far down\n if (i - start > 100) {\n end = Math.min(lines.length - 1, lineIdx + afterContext);\n break;\n }\n }\n\n if (!foundOpen) {\n // Fallback: context window\n start = Math.max(0, lineIdx - beforeContext);\n end = Math.min(lines.length - 1, lineIdx + afterContext);\n }\n\n return { start, end };\n}\n\nasync function safeReadFile(filePath: string): Promise<string | null> {\n try {\n return await readFile(filePath, 'utf-8');\n } catch {\n return null;\n }\n}\n","// @awa-component: TRC-ContentFormatter\n\nimport type { ContentSection } from './types.js';\n\n/** File extension to Markdown language identifier. */\nfunction langId(filePath: string): string {\n if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) return 'typescript';\n if (filePath.endsWith('.js') || filePath.endsWith('.jsx')) return 'javascript';\n if (filePath.endsWith('.md')) return 'markdown';\n if (filePath.endsWith('.yaml') || filePath.endsWith('.yml')) return 'yaml';\n if (filePath.endsWith('.json')) return 'json';\n if (filePath.endsWith('.tsp')) return 'typespec';\n return '';\n}\n\n/** Map section type to a human-readable heading. */\nfunction sectionHeading(type: ContentSection['type']): string {\n switch (type) {\n case 'task':\n return 'Task';\n case 'requirement':\n return 'Requirement';\n case 'design':\n return 'Design';\n case 'implementation':\n return 'Implementation';\n case 'test':\n return 'Test';\n default:\n return 'Other';\n }\n}\n\n/**\n * Format content sections as Markdown with headings, provenance, and code blocks.\n * @awa-impl: TRC-7_AC-1\n */\nexport function formatContentMarkdown(\n sections: ContentSection[],\n queryLabel: string,\n footer: string | null\n): string {\n const lines: string[] = [];\n lines.push(`# Context: ${queryLabel}`);\n lines.push('');\n\n let lastType: string | null = null;\n\n for (const section of sections) {\n // Group by type — add H2 when type changes\n if (section.type !== lastType) {\n lines.push(`## ${sectionHeading(section.type)}`);\n lines.push('');\n lastType = section.type;\n }\n\n lines.push(`> From: ${section.filePath} (lines ${section.startLine}-${section.endLine})`);\n lines.push('');\n\n const isCode = section.type === 'implementation' || section.type === 'test';\n if (isCode) {\n const lang = langId(section.filePath);\n lines.push(`\\`\\`\\`${lang}`);\n lines.push(section.content);\n lines.push('```');\n } else {\n lines.push(section.content);\n }\n lines.push('');\n }\n\n if (footer) {\n lines.push(`---`);\n lines.push(footer);\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Format content sections as JSON structure.\n * @awa-impl: TRC-7_AC-1\n */\nexport function formatContentJson(\n sections: ContentSection[],\n queryLabel: string,\n footer: string | null\n): string {\n const result = {\n query: queryLabel,\n sections: sections.map((s) => ({\n type: s.type,\n filePath: s.filePath,\n startLine: s.startLine,\n endLine: s.endLine,\n content: s.content,\n priority: s.priority,\n })),\n estimatedTokens: Math.ceil(sections.reduce((sum, s) => sum + s.content.length, 0) / 4),\n filesIncluded: new Set(sections.map((s) => s.filePath)).size,\n ...(footer ? { truncated: true, truncationMessage: footer } : {}),\n };\n return JSON.stringify(result, null, 2);\n}\n","// @awa-component: TRC-Formatter\n// @awa-impl: TRC-4_AC-1, TRC-9_AC-1, TRC-10_AC-1\n\nimport type { TraceChain, TraceResult } from './types.js';\n\n/**\n * Format trace result as a text location tree.\n */\nexport function formatTree(result: TraceResult): string {\n const lines: string[] = [];\n\n for (const chain of result.chains) {\n lines.push(...formatChainTree(chain));\n lines.push('');\n }\n\n for (const id of result.notFound) {\n lines.push(`✗ ${id}: not found`);\n }\n\n return lines.join('\\n').trimEnd();\n}\n\nfunction formatChainTree(chain: TraceChain): string[] {\n const lines: string[] = [];\n const queryId = chain.queryId;\n\n // Header line — show AC description if available, otherwise just the ID\n lines.push(`${queryId}`);\n\n // Requirement (reverse)\n if (chain.requirement) {\n lines.push('');\n lines.push(' ▲ Requirement');\n const r = chain.requirement;\n lines.push(` │ ${r.id} (${r.location.filePath}:${r.location.line})`);\n }\n\n // ACs\n if (chain.acs.length > 0) {\n lines.push('');\n lines.push(' ▼ Acceptance Criteria');\n for (const ac of chain.acs) {\n lines.push(` │ ${ac.id} (${ac.location.filePath}:${ac.location.line})`);\n }\n }\n\n // Design components\n if (chain.designComponents.length > 0) {\n lines.push('');\n lines.push(' ▼ Design');\n for (const comp of chain.designComponents) {\n lines.push(` │ ${comp.id} (${comp.location.filePath}:${comp.location.line})`);\n }\n }\n\n // Properties\n if (chain.properties.length > 0) {\n lines.push('');\n lines.push(' ▼ Properties');\n for (const prop of chain.properties) {\n lines.push(` │ ${prop.id} (${prop.location.filePath}:${prop.location.line})`);\n }\n }\n\n // Implementations\n if (chain.implementations.length > 0) {\n lines.push('');\n lines.push(' ▼ Implementation');\n for (const impl of chain.implementations) {\n lines.push(\n ` │ ${impl.location.filePath}:${impl.location.line} (@awa-${impl.type === 'implementation' ? 'impl' : 'component'}: ${impl.id})`\n );\n }\n }\n\n // Tests\n if (chain.tests.length > 0) {\n lines.push('');\n lines.push(' ▼ Tests');\n for (const t of chain.tests) {\n lines.push(` │ ${t.location.filePath}:${t.location.line} (@awa-test: ${t.id})`);\n }\n }\n\n return lines;\n}\n\n/**\n * Format trace result as a file path list.\n */\nexport function formatList(result: TraceResult): string {\n const paths = new Set<string>();\n\n for (const chain of result.chains) {\n if (chain.requirement) {\n paths.add(`${chain.requirement.location.filePath}:${chain.requirement.location.line}`);\n }\n for (const ac of chain.acs) {\n paths.add(`${ac.location.filePath}:${ac.location.line}`);\n }\n for (const comp of chain.designComponents) {\n paths.add(`${comp.location.filePath}:${comp.location.line}`);\n }\n for (const prop of chain.properties) {\n paths.add(`${prop.location.filePath}:${prop.location.line}`);\n }\n for (const impl of chain.implementations) {\n paths.add(`${impl.location.filePath}:${impl.location.line}`);\n }\n for (const t of chain.tests) {\n paths.add(`${t.location.filePath}:${t.location.line}`);\n }\n }\n\n return [...paths].join('\\n');\n}\n\n/**\n * Format trace result as JSON (location mode — no content).\n */\nexport function formatJson(result: TraceResult): string {\n const output = {\n chains: result.chains.map((chain) => ({\n queryId: chain.queryId,\n requirement: chain.requirement\n ? {\n id: chain.requirement.id,\n filePath: chain.requirement.location.filePath,\n line: chain.requirement.location.line,\n }\n : null,\n acs: chain.acs.map((ac) => ({\n id: ac.id,\n filePath: ac.location.filePath,\n line: ac.location.line,\n })),\n designComponents: chain.designComponents.map((c) => ({\n id: c.id,\n filePath: c.location.filePath,\n line: c.location.line,\n })),\n implementations: chain.implementations.map((i) => ({\n id: i.id,\n filePath: i.location.filePath,\n line: i.location.line,\n })),\n tests: chain.tests.map((t) => ({\n id: t.id,\n filePath: t.location.filePath,\n line: t.location.line,\n })),\n properties: chain.properties.map((p) => ({\n id: p.id,\n filePath: p.location.filePath,\n line: p.location.line,\n })),\n })),\n notFound: result.notFound,\n };\n\n return JSON.stringify(output, null, 2);\n}\n","// @awa-component: TRC-IndexBuilder\n// @awa-impl: TRC-1_AC-1\n\nimport type { CodeMarker, MarkerScanResult, SpecParseResult } from '../check/types.js';\nimport type { CodeLocation, TraceIndex } from './types.js';\n\n/**\n * Build a TraceIndex from already-collected spec parse results and marker scan results.\n * This reuses the same data `awa check` collects — no duplicate scanning.\n */\nexport function buildTraceIndex(specs: SpecParseResult, markers: MarkerScanResult): TraceIndex {\n // Forward maps\n const reqToACs = new Map<string, string[]>();\n const acToDesignComponents = new Map<string, string[]>();\n const acToCodeLocations = new Map<string, CodeLocation[]>();\n const acToTestLocations = new Map<string, CodeLocation[]>();\n const propertyToTestLocations = new Map<string, CodeLocation[]>();\n const componentToCodeLocations = new Map<string, CodeLocation[]>();\n\n // Reverse maps\n const acToReq = new Map<string, string>();\n const componentToACs = new Map<string, string[]>();\n const propertyToACs = new Map<string, string[]>();\n\n // 1. Build reqToACs and acToReq from spec parse results\n buildRequirementMaps(specs, reqToACs, acToReq);\n\n // 2. Build acToDesignComponents, componentToACs, propertyToACs from cross-references\n buildDesignMaps(specs, acToDesignComponents, componentToACs, propertyToACs);\n\n // 3. Build code/test location maps from markers\n buildMarkerMaps(\n markers.markers,\n acToCodeLocations,\n acToTestLocations,\n propertyToTestLocations,\n componentToCodeLocations\n );\n\n // 4. Collect all known IDs\n const allIds = new Set<string>([\n ...specs.requirementIds,\n ...specs.acIds,\n ...specs.propertyIds,\n ...specs.componentNames,\n ]);\n\n // 5. Copy idLocations from specs (already a ReadonlyMap<string, {filePath, line}>)\n const idLocations = new Map<string, CodeLocation>();\n for (const [id, loc] of specs.idLocations) {\n idLocations.set(id, loc);\n }\n\n return {\n reqToACs,\n acToDesignComponents,\n acToCodeLocations,\n acToTestLocations,\n propertyToTestLocations,\n componentToCodeLocations,\n acToReq,\n componentToACs,\n propertyToACs,\n idLocations,\n allIds,\n };\n}\n\n/** Build requirement → AC forward map and AC → requirement reverse map. */\nfunction buildRequirementMaps(\n specs: SpecParseResult,\n reqToACs: Map<string, string[]>,\n acToReq: Map<string, string>\n): void {\n // AC IDs embed their parent requirement: e.g. DIFF-1_AC-1 → parent is DIFF-1\n // Sub-requirement ACs: DIFF-1.1_AC-2 → parent is DIFF-1.1\n for (const acId of specs.acIds) {\n const parentReq = extractParentRequirement(acId);\n if (parentReq && specs.requirementIds.has(parentReq)) {\n pushToMap(reqToACs, parentReq, acId);\n acToReq.set(acId, parentReq);\n }\n }\n\n // Also build sub-requirement → parent links: DIFF-1.1 has parent DIFF-1\n for (const reqId of specs.requirementIds) {\n const dotIdx = reqId.lastIndexOf('.');\n if (dotIdx !== -1) {\n const parentReq = reqId.slice(0, dotIdx);\n if (specs.requirementIds.has(parentReq)) {\n // Sub-requirements are not ACs, but we can store in reqToACs for traversal\n // Actually, sub-requirements are requirements themselves — they appear in reqToACs\n // when their own ACs are found. No extra work needed.\n }\n }\n }\n}\n\n/** Build design cross-reference maps from IMPLEMENTS and VALIDATES. */\nfunction buildDesignMaps(\n specs: SpecParseResult,\n acToDesignComponents: Map<string, string[]>,\n componentToACs: Map<string, string[]>,\n propertyToACs: Map<string, string[]>\n): void {\n for (const specFile of specs.specFiles) {\n // Only process DESIGN files (they have components and cross-refs)\n if (specFile.componentNames.length === 0 && specFile.crossRefs.length === 0) {\n continue;\n }\n\n // Map cross-refs to the component they belong to.\n // Cross-refs appear after a component heading (### CODE-ComponentName).\n // We associate each cross-ref with the most recent component heading above it.\n const componentsByLine = specFile.componentNames\n .map((name) => ({\n name,\n line: specFile.idLocations?.get(name)?.line ?? 0,\n }))\n .sort((a, b) => a.line - b.line);\n\n for (const crossRef of specFile.crossRefs) {\n const ownerComponent = findOwnerComponent(componentsByLine, crossRef.line);\n\n if (crossRef.type === 'implements' && ownerComponent) {\n for (const acId of crossRef.ids) {\n pushToMap(acToDesignComponents, acId, ownerComponent);\n pushToMap(componentToACs, ownerComponent, acId);\n }\n }\n\n if (crossRef.type === 'validates') {\n // VALIDATES links a property to the ACs/requirements it validates.\n // We need to find the property this VALIDATES belongs to.\n // Properties appear as list items above the VALIDATES line in the same component.\n const ownerProperty = findOwnerProperty(specFile, crossRef.line);\n if (ownerProperty) {\n for (const acId of crossRef.ids) {\n pushToMap(propertyToACs, ownerProperty, acId);\n }\n }\n }\n }\n }\n}\n\n/** Build marker location maps. */\nfunction buildMarkerMaps(\n markers: readonly CodeMarker[],\n acToCodeLocations: Map<string, CodeLocation[]>,\n acToTestLocations: Map<string, CodeLocation[]>,\n propertyToTestLocations: Map<string, CodeLocation[]>,\n componentToCodeLocations: Map<string, CodeLocation[]>\n): void {\n for (const marker of markers) {\n const loc: CodeLocation = { filePath: marker.filePath, line: marker.line };\n\n switch (marker.type) {\n case 'impl':\n pushToMap(acToCodeLocations, marker.id, loc);\n break;\n case 'test':\n // Test markers can reference ACs or properties\n if (marker.id.includes('_P-')) {\n pushToMap(propertyToTestLocations, marker.id, loc);\n } else {\n pushToMap(acToTestLocations, marker.id, loc);\n }\n break;\n case 'component':\n pushToMap(componentToCodeLocations, marker.id, loc);\n break;\n }\n }\n}\n\n/** Extract parent requirement ID from an AC ID. e.g. DIFF-1_AC-1 → DIFF-1 */\nfunction extractParentRequirement(acId: string): string | null {\n const idx = acId.indexOf('_AC-');\n return idx !== -1 ? acId.slice(0, idx) : null;\n}\n\n/** Find the component name that owns a given line (the most recent component heading above it). */\nfunction findOwnerComponent(\n componentsByLine: readonly { name: string; line: number }[],\n line: number\n): string | null {\n let owner: string | null = null;\n for (const comp of componentsByLine) {\n if (comp.line <= line) {\n owner = comp.name;\n } else {\n break;\n }\n }\n return owner;\n}\n\n/** Find the property ID that owns a VALIDATES cross-ref line. */\nfunction findOwnerProperty(\n specFile: {\n readonly propertyIds: readonly string[];\n readonly idLocations?: ReadonlyMap<string, { filePath: string; line: number }>;\n },\n validateLine: number\n): string | null {\n let owner: string | null = null;\n let closestLine = 0;\n for (const propId of specFile.propertyIds) {\n const loc = specFile.idLocations?.get(propId);\n if (loc && loc.line <= validateLine && loc.line > closestLine) {\n closestLine = loc.line;\n owner = propId;\n }\n }\n return owner;\n}\n\n/** Push a value into a map of arrays. */\nfunction pushToMap<K, V>(map: Map<K, V[]>, key: K, value: V): void {\n const existing = map.get(key);\n if (existing) {\n existing.push(value);\n } else {\n map.set(key, [value]);\n }\n}\n","// @awa-component: TRC-InputResolver\n// @awa-impl: TRC-2_AC-1, TRC-2_AC-2, TRC-2_AC-3\n\nimport { readFile } from 'node:fs/promises';\nimport type { TraceIndex } from './types.js';\n\n/** Result of resolving input to a list of trace IDs. */\nexport interface InputResolution {\n readonly ids: readonly string[];\n readonly warnings: readonly string[];\n}\n\n/**\n * Resolve direct ID arguments: validate each ID exists in the index.\n * Returns the IDs that exist and warnings for those that don't.\n */\nexport function resolveIds(ids: readonly string[], index: TraceIndex): InputResolution {\n const resolved: string[] = [];\n const warnings: string[] = [];\n\n for (const id of ids) {\n if (index.allIds.has(id)) {\n resolved.push(id);\n } else {\n warnings.push(`ID '${id}' not found in any spec or code`);\n }\n }\n\n return { ids: resolved, warnings };\n}\n\n/**\n * Resolve IDs from a task file by scanning for IMPLEMENTS: and TESTS: lines.\n */\nexport async function resolveTaskFile(\n taskPath: string,\n index: TraceIndex\n): Promise<InputResolution> {\n let content: string;\n try {\n content = await readFile(taskPath, 'utf-8');\n } catch {\n return { ids: [], warnings: [`Task file not found: ${taskPath}`] };\n }\n\n const ids = new Set<string>();\n const warnings: string[] = [];\n\n const lines = content.split('\\n');\n const idRegex = /[A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|[A-Z][A-Z0-9]*_P-\\d+/g;\n\n for (const line of lines) {\n // Look for IMPLEMENTS: and TESTS: lines\n if (/^\\s*IMPLEMENTS:/.test(line) || /^\\s*TESTS:/.test(line)) {\n let match = idRegex.exec(line);\n while (match !== null) {\n ids.add(match[0]);\n match = idRegex.exec(line);\n }\n }\n }\n\n // Also extract IDs from the Requirements Traceability section\n // Format: - {AC-ID} → {Task} ({Test}) or - {Property-ID} → {Test}\n // Only extract the first ID on each line (the AC/property before →), skip task refs\n const traceLineRegex = /^- ([A-Z][A-Z0-9]*(?:-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|_P-\\d+))/;\n let inTraceSection = false;\n for (const line of lines) {\n if (/^## Requirements Traceability/.test(line)) {\n inTraceSection = true;\n continue;\n }\n if (inTraceSection && /^## /.test(line)) {\n inTraceSection = false;\n continue;\n }\n if (inTraceSection) {\n const traceMatch = traceLineRegex.exec(line);\n if (traceMatch?.[1]) {\n ids.add(traceMatch[1]);\n }\n }\n }\n\n // Validate resolved IDs\n const resolved: string[] = [];\n for (const id of ids) {\n if (index.allIds.has(id)) {\n resolved.push(id);\n } else {\n warnings.push(`ID '${id}' from task file not found in specs`);\n }\n }\n\n if (resolved.length === 0 && warnings.length === 0) {\n warnings.push(`No traceability IDs found in task file: ${taskPath}`);\n }\n\n return { ids: resolved, warnings };\n}\n\n/**\n * Resolve IDs from a source file by scanning for @awa-* markers.\n */\nexport async function resolveSourceFile(\n filePath: string,\n index: TraceIndex\n): Promise<InputResolution> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return { ids: [], warnings: [`Source file not found: ${filePath}`] };\n }\n\n const ids = new Set<string>();\n const warnings: string[] = [];\n\n const markerRegex = /@awa-(?:impl|test|component):\\s*(.+)/g;\n const idTokenRegex = /[A-Z][A-Z0-9]*(?:[-_][A-Za-z0-9]+)*(?:\\.\\d+)?/g;\n\n const lines = content.split('\\n');\n for (const line of lines) {\n let markerMatch = markerRegex.exec(line);\n while (markerMatch !== null) {\n const idsText = markerMatch[1] ?? '';\n let idMatch = idTokenRegex.exec(idsText);\n while (idMatch !== null) {\n ids.add(idMatch[0]);\n idMatch = idTokenRegex.exec(idsText);\n }\n markerMatch = markerRegex.exec(line);\n }\n }\n\n // Validate resolved IDs\n const resolved: string[] = [];\n for (const id of ids) {\n if (index.allIds.has(id)) {\n resolved.push(id);\n } else {\n warnings.push(`Marker ID '${id}' not found in specs`);\n }\n }\n\n if (resolved.length === 0 && warnings.length === 0) {\n warnings.push(`No traceability markers found in file: ${filePath}`);\n }\n\n return { ids: resolved, warnings };\n}\n","// @awa-component: TRC-TraceResolver\n// @awa-impl: TRC-3_AC-1, TRC-3_AC-2, TRC-3_AC-3, TRC-3_AC-4, TRC-3_AC-5, TRC-11_AC-1, TRC-11_AC-2\n\nimport type { TraceChain, TraceIndex, TraceNode, TraceOptions, TraceResult } from './types.js';\n\n/**\n * Resolve trace chains for a set of IDs against the TraceIndex.\n * Returns a TraceResult with chains for found IDs and a list of not-found IDs.\n */\nexport function resolveTrace(\n index: TraceIndex,\n ids: readonly string[],\n options: TraceOptions\n): TraceResult {\n const chains: TraceChain[] = [];\n const notFound: string[] = [];\n\n for (const id of ids) {\n if (!index.allIds.has(id)) {\n notFound.push(id);\n continue;\n }\n\n const chain = resolveChain(index, id, options);\n if (chain) {\n chains.push(chain);\n }\n }\n\n return { chains, notFound };\n}\n\n/** Resolve a single trace chain for one ID. */\nfunction resolveChain(index: TraceIndex, id: string, options: TraceOptions): TraceChain | null {\n const idType = detectIdType(id);\n const scope = options.scope;\n\n let requirement: TraceNode | undefined;\n let acs: TraceNode[] = [];\n let designComponents: TraceNode[] = [];\n let implementations: TraceNode[] = [];\n let tests: TraceNode[] = [];\n let properties: TraceNode[] = [];\n\n switch (idType) {\n case 'requirement':\n resolveFromRequirement(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n case 'ac':\n resolveFromAC(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n case 'property':\n resolveFromProperty(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n case 'component':\n resolveFromComponent(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n }\n\n // Apply scope filtering\n if (scope) {\n acs = acs.filter((n) => n.id.startsWith(scope));\n designComponents = designComponents.filter((n) => n.id.startsWith(scope));\n implementations = implementations.filter((n) => matchesScope(n, scope, index));\n tests = tests.filter((n) => matchesScope(n, scope, index));\n properties = properties.filter((n) => n.id.startsWith(scope));\n if (requirement && !requirement.id.startsWith(scope)) {\n requirement = undefined;\n }\n }\n\n // Apply layer filtering\n if (options.noCode) {\n implementations = [];\n }\n if (options.noTests) {\n tests = [];\n properties = [];\n }\n\n return {\n queryId: id,\n requirement,\n acs: deduplicateNodes(acs),\n designComponents: deduplicateNodes(designComponents),\n implementations: deduplicateNodes(implementations),\n tests: deduplicateNodes(tests),\n properties: deduplicateNodes(properties),\n };\n}\n\n/** Collectors for building a chain incrementally. */\ninterface ChainCollectors {\n requirement: (node: TraceNode) => void;\n acs: TraceNode[];\n designComponents: TraceNode[];\n implementations: TraceNode[];\n tests: TraceNode[];\n properties: TraceNode[];\n}\n\n/** Resolve starting from a requirement ID. */\nfunction resolveFromRequirement(\n index: TraceIndex,\n reqId: string,\n options: TraceOptions,\n collectors: ChainCollectors\n): void {\n const loc = index.idLocations.get(reqId);\n if (loc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: loc });\n }\n\n if (options.direction === 'reverse') return;\n\n // Forward: requirement → ACs → design → code → tests\n const acIds = index.reqToACs.get(reqId) ?? [];\n for (const acId of acIds) {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n if (withinDepth(options.depth, 1)) {\n resolveACDownstream(index, acId, options, collectors, 1);\n }\n }\n}\n\n/** Resolve starting from an AC ID. */\nfunction resolveFromAC(\n index: TraceIndex,\n acId: string,\n options: TraceOptions,\n collectors: ChainCollectors\n): void {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n\n // Reverse: AC → requirement\n if (options.direction !== 'forward') {\n const reqId = index.acToReq.get(acId);\n if (reqId) {\n const reqLoc = index.idLocations.get(reqId);\n if (reqLoc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: reqLoc });\n }\n }\n }\n\n // Forward: AC → design → code → tests\n if (options.direction !== 'reverse') {\n resolveACDownstream(index, acId, options, collectors, 0);\n }\n}\n\n/** Resolve starting from a property ID. */\nfunction resolveFromProperty(\n index: TraceIndex,\n propId: string,\n options: TraceOptions,\n collectors: ChainCollectors\n): void {\n const propLoc = index.idLocations.get(propId);\n if (propLoc) {\n collectors.properties.push({ id: propId, type: 'property', location: propLoc });\n }\n\n // Forward: property → test locations\n if (options.direction !== 'reverse') {\n const testLocs = index.propertyToTestLocations.get(propId) ?? [];\n for (const loc of testLocs) {\n collectors.tests.push({ id: propId, type: 'test', location: loc });\n }\n }\n\n // Reverse: property → ACs it validates → requirements\n if (options.direction !== 'forward') {\n const acIds = index.propertyToACs.get(propId) ?? [];\n for (const acId of acIds) {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n if (withinDepth(options.depth, 1)) {\n const reqId = index.acToReq.get(acId);\n if (reqId) {\n const reqLoc = index.idLocations.get(reqId);\n if (reqLoc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: reqLoc });\n }\n }\n }\n }\n }\n}\n\n/** Resolve starting from a component name. */\nfunction resolveFromComponent(\n index: TraceIndex,\n componentId: string,\n options: TraceOptions,\n collectors: ChainCollectors\n): void {\n const compLoc = index.idLocations.get(componentId);\n if (compLoc) {\n collectors.designComponents.push({ id: componentId, type: 'component', location: compLoc });\n }\n\n // Forward: component → code locations\n if (options.direction !== 'reverse') {\n const codeLocs = index.componentToCodeLocations.get(componentId) ?? [];\n for (const loc of codeLocs) {\n collectors.implementations.push({\n id: componentId,\n type: 'implementation',\n location: loc,\n });\n }\n }\n\n // Reverse: component → ACs → requirements\n if (options.direction !== 'forward') {\n const acIds = index.componentToACs.get(componentId) ?? [];\n for (const acId of acIds) {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n if (withinDepth(options.depth, 1)) {\n const reqId = index.acToReq.get(acId);\n if (reqId) {\n const reqLoc = index.idLocations.get(reqId);\n if (reqLoc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: reqLoc });\n }\n }\n }\n }\n }\n}\n\n/** Resolve the downstream portion of an AC: design components → code → tests. */\nfunction resolveACDownstream(\n index: TraceIndex,\n acId: string,\n options: TraceOptions,\n collectors: ChainCollectors,\n currentDepth: number\n): void {\n // AC → design components\n const components = index.acToDesignComponents.get(acId) ?? [];\n for (const comp of components) {\n const compLoc = index.idLocations.get(comp);\n if (compLoc) {\n collectors.designComponents.push({ id: comp, type: 'component', location: compLoc });\n }\n }\n\n if (!withinDepth(options.depth, currentDepth + 1)) return;\n\n // AC → code locations (@awa-impl)\n const codeLocs = index.acToCodeLocations.get(acId) ?? [];\n for (const loc of codeLocs) {\n collectors.implementations.push({ id: acId, type: 'implementation', location: loc });\n }\n\n // AC → test locations (@awa-test)\n const testLocs = index.acToTestLocations.get(acId) ?? [];\n for (const loc of testLocs) {\n collectors.tests.push({ id: acId, type: 'test', location: loc });\n }\n}\n\n/** Detect the type of a traceability ID. */\nexport function detectIdType(id: string): 'requirement' | 'ac' | 'property' | 'component' {\n if (id.includes('_AC-')) return 'ac';\n if (id.includes('_P-')) return 'property';\n // Requirements: CODE-N or CODE-N.P (contain a digit after the dash)\n if (/^[A-Z][A-Z0-9]*-\\d+/.test(id)) return 'requirement';\n // Component names: CODE-PascalCaseName\n return 'component';\n}\n\n/** Check if we're within depth limit. */\nfunction withinDepth(maxDepth: number | undefined, current: number): boolean {\n if (maxDepth === undefined) return true;\n return current < maxDepth;\n}\n\n/** Check if a node's associated IDs match the scope code. */\nfunction matchesScope(node: TraceNode, scope: string, _index: TraceIndex): boolean {\n return node.id.startsWith(scope);\n}\n\n/** Deduplicate nodes by id + location. */\nfunction deduplicateNodes(nodes: readonly TraceNode[]): TraceNode[] {\n const seen = new Set<string>();\n const result: TraceNode[] = [];\n for (const node of nodes) {\n const key = `${node.id}:${node.location.filePath}:${node.location.line}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(node);\n }\n }\n return result;\n}\n","// @awa-component: TRC-SharedScanner\n// @awa-impl: TRC-1_AC-1\n\nimport type { FileConfig } from '../../types/index.js';\nimport { scanMarkers } from '../check/marker-scanner.js';\nimport { parseSpecs } from '../check/spec-parser.js';\nimport type { CheckConfig, MarkerScanResult, SpecParseResult } from '../check/types.js';\nimport { DEFAULT_CHECK_CONFIG } from '../check/types.js';\nimport { configLoader } from '../config.js';\n\n/** Results from scanning markers and specs in parallel. */\nexport interface ScanResults {\n readonly markers: MarkerScanResult;\n readonly specs: SpecParseResult;\n readonly config: CheckConfig;\n}\n\n/**\n * Build a CheckConfig from file config + optional overrides.\n * Shared by trace, coverage, impact, and graph commands.\n */\nexport function buildScanConfig(\n fileConfig: FileConfig | null,\n overrides?: Partial<CheckConfig>\n): CheckConfig {\n const section = fileConfig?.check;\n\n return {\n specGlobs: toStringArray(section?.['spec-globs']) ?? [...DEFAULT_CHECK_CONFIG.specGlobs],\n codeGlobs: toStringArray(section?.['code-globs']) ?? [...DEFAULT_CHECK_CONFIG.codeGlobs],\n specIgnore: toStringArray(section?.['spec-ignore']) ?? [...DEFAULT_CHECK_CONFIG.specIgnore],\n codeIgnore: toStringArray(section?.['code-ignore']) ?? [...DEFAULT_CHECK_CONFIG.codeIgnore],\n ignoreMarkers: toStringArray(section?.['ignore-markers']) ?? [\n ...DEFAULT_CHECK_CONFIG.ignoreMarkers,\n ],\n markers: toStringArray(section?.markers) ?? [...DEFAULT_CHECK_CONFIG.markers],\n idPattern:\n typeof section?.['id-pattern'] === 'string'\n ? section['id-pattern']\n : DEFAULT_CHECK_CONFIG.idPattern,\n crossRefPatterns: toStringArray(section?.['cross-ref-patterns']) ?? [\n ...DEFAULT_CHECK_CONFIG.crossRefPatterns,\n ],\n format: DEFAULT_CHECK_CONFIG.format,\n schemaDir: DEFAULT_CHECK_CONFIG.schemaDir,\n schemaEnabled: false,\n allowWarnings: true,\n specOnly: false,\n fix: true,\n ...overrides,\n };\n}\n\n/**\n * Load config, scan markers and parse specs in parallel.\n * Shared by trace, coverage, impact, and graph commands.\n */\nexport async function scan(configPath?: string): Promise<ScanResults> {\n const fileConfig = await configLoader.load(configPath ?? null);\n const config = buildScanConfig(fileConfig);\n\n const [markers, specs] = await Promise.all([scanMarkers(config), parseSpecs(config)]);\n\n return { markers, specs, config };\n}\n\nfunction toStringArray(value: unknown): string[] | null {\n if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {\n return value as string[];\n }\n return null;\n}\n","// @awa-component: TRC-TokenEstimator\n// @awa-impl: TRC-6_AC-1\n\nimport type { ContentSection } from './types.js';\n\n/**\n * Estimate token count using a simple chars/4 heuristic.\n */\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Apply a token budget to content sections.\n * Sections must already be sorted by priority (ascending = highest priority first).\n * Returns the sections that fit within the budget, plus a footer message if truncated.\n */\nexport function applyTokenBudget(\n sections: ContentSection[],\n maxTokens: number\n): { sections: ContentSection[]; truncated: boolean; footer: string | null } {\n if (maxTokens <= 0) {\n return { sections: [], truncated: sections.length > 0, footer: null };\n }\n\n const result: ContentSection[] = [];\n let usedTokens = 0;\n let omittedCount = 0;\n\n for (const section of sections) {\n const sectionTokens = estimateTokens(section.content);\n\n if (usedTokens + sectionTokens <= maxTokens) {\n result.push(section);\n usedTokens += sectionTokens;\n } else if (result.length === 0) {\n // Always include at least the first section (highest priority), even if over budget.\n // Truncate its content to fit.\n const availableChars = maxTokens * 4;\n const truncatedContent = section.content.slice(0, availableChars);\n result.push({ ...section, content: truncatedContent });\n usedTokens = maxTokens;\n // Remaining sections are omitted\n omittedCount = sections.length - 1;\n break;\n } else {\n omittedCount++;\n }\n }\n\n // Count remaining unprocessed sections\n if (omittedCount === 0) {\n omittedCount = sections.length - result.length;\n }\n\n const truncated = omittedCount > 0;\n const footer = truncated\n ? `... ${omittedCount} more section${omittedCount === 1 ? '' : 's'} omitted (use --max-tokens to increase)`\n : null;\n\n return { sections: result, truncated, footer };\n}\n","// @awa-component: TRC-TraceCommand\n// @awa-impl: TRC-8_AC-1, TRC-8_AC-2, TRC-2_AC-4\n// @awa-impl: TRC-12_AC-1\n\nimport { assembleContent } from '../core/trace/content-assembler.js';\nimport { formatContentJson, formatContentMarkdown } from '../core/trace/content-formatter.js';\nimport { formatJson, formatList, formatTree } from '../core/trace/formatter.js';\nimport { buildTraceIndex } from '../core/trace/index-builder.js';\nimport { resolveIds, resolveSourceFile, resolveTaskFile } from '../core/trace/input-resolver.js';\nimport { resolveTrace } from '../core/trace/resolver.js';\nimport { scan } from '../core/trace/scanner.js';\nimport { applyTokenBudget } from '../core/trace/token-estimator.js';\nimport type { TraceCommandOptions, TraceOptions } from '../core/trace/types.js';\nimport { logger } from '../utils/logger.js';\n\n/**\n * Execute the `awa trace` command.\n * Returns exit code: 0 = chain found, 1 = ID not found / no context, 2 = internal error.\n */\nexport async function traceCommand(options: TraceCommandOptions): Promise<number> {\n try {\n // Scan markers and parse specs using shared scanner\n const { markers, specs } = await scan(options.config);\n\n // Build the traceability index\n const index = buildTraceIndex(specs, markers);\n\n // Resolve input to IDs\n let ids: readonly string[];\n let warnings: readonly string[] = [];\n if (options.all) {\n ids = [...index.allIds];\n } else if (options.task) {\n const resolved = await resolveTaskFile(options.task, index);\n ids = resolved.ids;\n warnings = resolved.warnings;\n } else if (options.file) {\n const resolved = await resolveSourceFile(options.file, index);\n ids = resolved.ids;\n warnings = resolved.warnings;\n } else if (options.ids.length > 0) {\n const resolved = resolveIds([...options.ids], index);\n ids = resolved.ids;\n warnings = resolved.warnings;\n } else {\n logger.error('No IDs, --all, --task, or --file specified');\n return 1;\n }\n\n // Log warnings for unresolved IDs\n for (const w of warnings) {\n logger.warn(w);\n }\n\n if (ids.length === 0) {\n if (options.file) {\n logger.error('No traceability markers found in file');\n } else if (options.task) {\n logger.error('No traceability IDs found in task file');\n } else {\n logger.error('No valid IDs found');\n }\n return 1;\n }\n\n // Resolve trace chains\n const traceOptions: TraceOptions = {\n direction: options.direction,\n depth: options.depth,\n scope: options.scope,\n noCode: options.noCode,\n noTests: options.noTests,\n };\n const result = resolveTrace(index, ids, traceOptions);\n\n if (result.chains.length === 0 && result.notFound.length > 0) {\n for (const id of result.notFound) {\n logger.error(`ID not found: ${id}`);\n }\n return 1;\n }\n\n // Format output\n if (options.summary) {\n const chainCount = result.chains.length;\n const notFoundCount = result.notFound.length;\n process.stdout.write(`chains: ${chainCount}, not-found: ${notFoundCount}\\n`);\n return result.notFound.length > 0 && result.chains.length === 0 ? 1 : 0;\n }\n\n let output: string;\n const isContentMode = options.content || options.maxTokens !== undefined;\n const queryLabel = ids.join(', ');\n\n if (isContentMode) {\n // Content mode: assemble actual file sections\n const sections = await assembleContent(result, options.task, {\n beforeContext: options.beforeContext,\n afterContext: options.afterContext,\n });\n let finalSections = sections;\n let footer: string | null = null;\n\n if (options.maxTokens !== undefined) {\n const budgeted = applyTokenBudget(sections, options.maxTokens);\n finalSections = budgeted.sections;\n footer = budgeted.footer;\n }\n\n if (options.json) {\n output = formatContentJson(finalSections, queryLabel, footer);\n } else {\n output = formatContentMarkdown(finalSections, queryLabel, footer);\n }\n } else if (options.list) {\n output = formatList(result);\n } else if (options.json) {\n output = formatJson(result);\n } else {\n output = formatTree(result);\n }\n\n // Output\n process.stdout.write(output);\n\n // Warn about not-found IDs if some chains were found\n if (result.notFound.length > 0) {\n for (const id of result.notFound) {\n logger.warn(`ID not found: ${id}`);\n }\n }\n\n return 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 2;\n }\n}\n","import chalk from 'chalk';\nimport { PACKAGE_INFO } from '../_generated/package_info.js';\nimport type { Logger } from './logger.js';\n\nexport interface UpdateCheckResult {\n current: string;\n latest: string;\n isOutdated: boolean;\n isMajorBump: boolean;\n}\n\n/**\n * Compare two semver version strings numerically (major.minor.patch only).\n * Returns a negative number if a < b, 0 if equal, positive if a > b.\n */\nexport function compareSemver(a: string, b: string): number {\n const partsA = a.split('.').map((s) => Number.parseInt(s, 10));\n const partsB = b.split('.').map((s) => Number.parseInt(s, 10));\n\n for (let i = 0; i < 3; i++) {\n const diff = (partsA[i] ?? 0) - (partsB[i] ?? 0);\n if (diff !== 0) return diff;\n }\n return 0;\n}\n\n/**\n * Check if a version bump is a major version bump.\n */\nexport function isMajorVersionBump(current: string, latest: string): boolean {\n const currentMajor = Number.parseInt(current.split('.')[0] ?? '0', 10);\n const latestMajor = Number.parseInt(latest.split('.')[0] ?? '0', 10);\n return latestMajor > currentMajor;\n}\n\n/**\n * Fetch the latest version from the npm registry.\n * Returns the update check result or null on any error.\n */\nexport async function checkForUpdate(): Promise<UpdateCheckResult | null> {\n try {\n const response = await fetch('https://registry.npmjs.org/@ncoderz/awa/latest', {\n signal: AbortSignal.timeout(5000),\n });\n\n if (!response.ok) return null;\n\n const data = (await response.json()) as { version?: string };\n const latest = data.version;\n if (!latest || typeof latest !== 'string') return null;\n\n const current = PACKAGE_INFO.version;\n const isOutdated = compareSemver(current, latest) < 0;\n\n return {\n current,\n latest,\n isOutdated,\n isMajorBump: isOutdated && isMajorVersionBump(current, latest),\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Print an update warning to the console using the logger.\n */\nexport function printUpdateWarning(log: Logger, result: UpdateCheckResult): void {\n if (!result.isOutdated) return;\n\n console.log('');\n if (result.isMajorBump) {\n log.warn(\n chalk.yellow(\n `New major version available: ${result.current} → ${result.latest} (breaking changes)`\n )\n );\n log.warn(chalk.dim(' See https://github.com/ncoderz/awa/releases for details'));\n } else {\n log.warn(chalk.yellow(`Update available: ${result.current} → ${result.latest}`));\n }\n log.warn(chalk.dim(' Run `npm install -g @ncoderz/awa` to update'));\n console.log('');\n}\n","import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join } from 'node:path';\n\nconst CACHE_DIR = join(homedir(), '.cache', 'awa');\nconst CACHE_FILE = join(CACHE_DIR, 'update-check.json');\nconst DEFAULT_INTERVAL_MS = 86_400_000; // 1 day\n\ninterface CacheData {\n timestamp: number;\n latestVersion: string;\n}\n\n/**\n * Determine whether a new update check should be performed.\n * Returns true if the cache is missing, corrupt, or stale.\n */\nexport async function shouldCheck(intervalMs: number = DEFAULT_INTERVAL_MS): Promise<boolean> {\n try {\n const raw = await readFile(CACHE_FILE, 'utf-8');\n const data = JSON.parse(raw) as CacheData;\n\n if (typeof data.timestamp !== 'number' || typeof data.latestVersion !== 'string') {\n return true;\n }\n\n return Date.now() - data.timestamp >= intervalMs;\n } catch {\n return true;\n }\n}\n\n/**\n * Write the latest version and current timestamp to the cache file.\n */\nexport async function writeCache(latestVersion: string): Promise<void> {\n try {\n await mkdir(dirname(CACHE_FILE), { recursive: true });\n\n const data: CacheData = {\n timestamp: Date.now(),\n latestVersion,\n };\n\n await writeFile(CACHE_FILE, JSON.stringify(data), 'utf-8');\n } catch {\n // Silently ignore write failures\n }\n}\n\n/**\n * Read the cached latest version. Returns null if cache is missing or corrupt.\n */\nexport async function readCachedVersion(): Promise<string | null> {\n try {\n const raw = await readFile(CACHE_FILE, 'utf-8');\n const data = JSON.parse(raw) as CacheData;\n if (typeof data.latestVersion === 'string') {\n return data.latestVersion;\n }\n return null;\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiFA,SAAS,SAAS,cAAc;;;AC7EzB,IAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,eAAe;AACjB;;;ACUO,SAAS,qBACd,SACA,OACA,QACa;AACb,QAAM,WAAsB,CAAC;AAI7B,QAAM,UAAU,IAAI,OAAO,IAAI,OAAO,SAAS,GAAG;AAClD,aAAW,UAAU,QAAQ,SAAS;AACpC,QAAI,OAAO,SAAS,aAAa;AAE/B;AAAA,IACF;AACA,QAAI,CAAC,QAAQ,KAAK,OAAO,EA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BAAkB;AAErC,YAAM,aAAa,MAAM,YAAY,UAAU;AAC/C,UAAI,CAAC,WAAY,QAAO;AAExB,YAAM,SAAS,MAAM,eAAe;AACpC,UAAI,QAAQ;AACV,cAAM,WAAW,OAAO,MAAM;AAAA,MAChC;AACA,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AACL;AAGA,QAAQ,KAAK,cAAc,YAAY;AACrC,MAAI,CAAC,mBAAoB;AACzB,MAAI;AACF,UAAM,SAAS,MAAM;AACrB,QAAI,QAAQ,YAAY;AACtB,yBAAmB,QAAQ,MAAM;AAAA,IACnC;AAAA,EACF,QAAQ;AAAA,EAER;AACF,CAAC;AAGD,QAAQ,WAAW;","names":["readFile","readFile","readFile","readFile","readFile","readFile","basename","readFile","extractIdsFromText","basename","join","relative","join","join","join","chalk","join","relative","join","tmpdir","join","join","join","join","tmpdir","template","options","diffOptions","mergedDir","resolve","intro","outro","chalk","readFile","join","relative","intro","template","outro","intro","isCancel","multiselect","outro","template","multiselect","isCancel","options","outro","intro","intro","outro","readdir","basename","join","join","readdir","basename","toStringArray","chalk","report","reportJson","mkdir","rm","tmpdir","join","readdir","rm","join","relative","readdir","join","relative","rm","join","tmpdir","mkdir","rm","intro","template","outro","report","readFile","readFile","toStringArray","chalk","chalk","mkdir","readFile","writeFile","join","configLoader"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli/index.ts","../src/_generated/package_info.ts","../src/core/check/code-spec-checker.ts","../src/core/check/codes-fixer.ts","../src/core/codes/scanner.ts","../src/core/check/matrix-fixer.ts","../src/core/check/reporter.ts","../src/core/check/rule-loader.ts","../src/core/check/schema-checker.ts","../src/core/check/spec-spec-checker.ts","../src/commands/check.ts","../src/core/codes/reporter.ts","../src/commands/codes.ts","../src/commands/diff.ts","../src/core/batch-runner.ts","../src/core/differ.ts","../src/core/delete-list.ts","../src/core/generator.ts","../src/core/resolver.ts","../src/core/template.ts","../src/core/feature-resolver.ts","../src/core/json-output.ts","../src/core/overlay.ts","../src/core/template-resolver.ts","../src/utils/file-watcher.ts","../src/utils/debouncer.ts","../src/commands/features.ts","../src/core/features/reporter.ts","../src/core/features/scanner.ts","../src/commands/generate.ts","../src/core/merge/content-merger.ts","../src/core/merge/reporter.ts","../src/core/merge/spec-mover.ts","../src/core/merge/types.ts","../src/core/recode/types.ts","../src/core/recode/map-builder.ts","../src/commands/merge.ts","../src/core/recode/reporter.ts","../src/commands/recode.ts","../src/commands/test.ts","../src/core/template-test/fixture-loader.ts","../src/core/template-test/reporter.ts","../src/core/template-test/runner.ts","../src/core/template-test/snapshot.ts","../src/core/trace/content-assembler.ts","../src/core/trace/content-formatter.ts","../src/core/trace/formatter.ts","../src/core/trace/index-builder.ts","../src/core/trace/input-resolver.ts","../src/core/trace/resolver.ts","../src/core/trace/token-estimator.ts","../src/commands/trace.ts","../src/utils/update-check.ts","../src/utils/update-check-cache.ts"],"sourcesContent":["// @awa-component: CLI-ArgumentParser\n// @awa-component: CLI-TemplateGroup\n// @awa-component: CLI-RootProgram\n// @awa-impl: CLI-1_AC-1\n// @awa-impl: CLI-1_AC-2\n// @awa-impl: CLI-1_AC-3\n// @awa-impl: CLI-1_AC-4\n// @awa-impl: CLI-1_AC-5\n// @awa-impl: CLI-2_AC-1\n// @awa-impl: CLI-2_AC-2\n// @awa-impl: CLI-2_AC-3\n// @awa-impl: CLI-2_AC-5\n// @awa-impl: CLI-2_AC-6\n// @awa-impl: CLI-3_AC-1\n// @awa-impl: CLI-4_AC-1\n// @awa-impl: CLI-4_AC-2\n// @awa-impl: CLI-5_AC-1\n// @awa-impl: CLI-6_AC-1\n// @awa-impl: CLI-7_AC-1\n// @awa-impl: CLI-8_AC-1\n// @awa-impl: CLI-9_AC-1\n// @awa-impl: CLI-9_AC-2\n// @awa-impl: CLI-9_AC-3\n// @awa-impl: CLI-10_AC-1\n// @awa-impl: CLI-10_AC-2\n// @awa-impl: CLI-11_AC-1\n// @awa-impl: CLI-11_AC-2\n// @awa-impl: CLI-11_AC-3\n// @awa-impl: CLI-12_AC-1\n// @awa-impl: CLI-13_AC-1\n// @awa-impl: CLI-13_AC-2\n// @awa-impl: CLI-14_AC-1\n// @awa-impl: CLI-14_AC-2\n// @awa-impl: CLI-6_AC-2\n// @awa-impl: CFG-5_AC-2\n// @awa-impl: DIFF-7_AC-1\n// @awa-impl: DIFF-7_AC-2\n// @awa-impl: DIFF-7_AC-3\n// @awa-impl: DIFF-7_AC-4\n// @awa-impl: DIFF-7_AC-5\n// @awa-impl: DIFF-7_AC-6\n// @awa-impl: DIFF-7_AC-7\n// @awa-impl: DIFF-7_AC-8\n// @awa-impl: DIFF-7_AC-9\n// @awa-impl: DIFF-7_AC-10\n// @awa-impl: DIFF-7_AC-11\n// @awa-impl: DIFF-7_AC-12\n// @awa-impl: DIFF-7_AC-13\n// @awa-impl: CFG-8_AC-1\n// @awa-impl: CFG-8_AC-2\n// @awa-impl: CFG-8_AC-4\n// @awa-impl: CFG-10_AC-1\n// @awa-impl: CFG-10_AC-2\n// @awa-impl: CFG-10_AC-3\n// @awa-impl: CFG-10_AC-5\n// @awa-impl: GEN-10_AC-1\n// @awa-impl: GEN-10_AC-2\n// @awa-impl: GEN-13_AC-1\n// @awa-impl: GEN-14_AC-1\n// @awa-impl: GEN-15_AC-1\n// @awa-impl: GEN-16_AC-1\n// @awa-impl: CLI-41_AC-1\n// @awa-impl: CLI-41_AC-2\n// @awa-impl: CLI-41_AC-3\n// @awa-impl: CLI-41_AC-4\n// @awa-impl: CLI-41_AC-5\n// @awa-impl: CLI-41_AC-6\n// @awa-impl: CLI-41_AC-7\n// @awa-impl: CLI-42_AC-1\n// @awa-impl: CLI-42_AC-2\n// @awa-impl: CLI-43_AC-1\n// @awa-impl: CLI-43_AC-2\n// @awa-impl: CLI-43_AC-3\n// @awa-impl: CLI-43_AC-4\n// @awa-impl: CLI-44_AC-1\n// @awa-impl: CLI-44_AC-2\n// @awa-impl: CLI-45_AC-1\n// @awa-impl: CLI-45_AC-2\n// @awa-impl: CLI-45_AC-3\n// @awa-impl: CLI-45_AC-4\n\nimport { Command, Option } from 'commander';\n\nimport { PACKAGE_INFO } from '../_generated/package_info.js';\nimport { checkCommand } from '../commands/check.js';\nimport { codesCommand } from '../commands/codes.js';\nimport { diffCommand } from '../commands/diff.js';\nimport { featuresCommand } from '../commands/features.js';\nimport { generateCommand } from '../commands/generate.js';\nimport { mergeCommand } from '../commands/merge.js';\nimport { recodeCommand } from '../commands/recode.js';\nimport { renumberCommand } from '../commands/renumber.js';\nimport { testCommand } from '../commands/test.js';\nimport { traceCommand } from '../commands/trace.js';\nimport type { RawCheckOptions } from '../core/check/types.js';\nimport type { CodesCommandOptions } from '../core/codes/types.js';\nimport type { MergeCommandOptions } from '../core/merge/types.js';\nimport type { RecodeCommandOptions } from '../core/recode/types.js';\nimport type { RenumberCommandOptions } from '../core/renumber/types.js';\nimport type { RawTestOptions } from '../core/template-test/types.js';\nimport type { TraceCommandOptions } from '../core/trace/types.js';\nimport type { RawCliOptions } from '../types/index.js';\nimport { logger } from '../utils/logger.js';\nimport {\n checkForUpdate,\n printUpdateWarning,\n type UpdateCheckResult,\n} from '../utils/update-check.js';\nimport { shouldCheck, writeCache } from '../utils/update-check-cache.js';\n\nconst version = PACKAGE_INFO.version;\n\n// @awa-impl: CLI-1_AC-2, CLI-9_AC-1, CLI-9_AC-2, CLI-9_AC-3, CLI-10_AC-1, CLI-10_AC-2\n// @awa-impl: CLI-44_AC-1\nconst program = new Command();\n\nprogram\n .name('awa')\n .description('awa - tool for generating AI coding agent configuration files')\n .version(version, '-v, --version', 'Display version number');\n\n// @awa-impl: CLI-41_AC-1, CLI-41_AC-2, CLI-41_AC-3, CLI-44_AC-2\n// @awa-impl: CLI-45_AC-1, CLI-45_AC-2, CLI-45_AC-3, CLI-45_AC-4\nconst template = new Command('template').description(\n 'Template operations (generate, diff, features, test)',\n);\n\n// @awa-impl: CLI-1_AC-1, CLI-1_AC-2, CLI-1_AC-3, CLI-1_AC-4, CLI-1_AC-5\n// @awa-impl: GEN-13_AC-1, GEN-14_AC-1, GEN-15_AC-1, GEN-16_AC-1\n// @awa-impl: CLI-41_AC-4, CLI-42_AC-1, CLI-42_AC-2\n\n/** Configure a generate/init command with shared options and action handler. */\nfunction configureGenerateCommand(cmd: Command): Command {\n return (\n cmd\n .description('Generate AI agent configuration files from templates')\n // @awa-impl: CLI-2_AC-1, CLI-2_AC-5, CLI-2_AC-6\n .argument('[output]', 'Output directory (optional if specified in config)')\n // @awa-impl: CLI-3_AC-1\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n // @awa-impl: CLI-4_AC-1, CLI-4_AC-2\n .option('-f, --features <flag...>', 'Feature flags (can be specified multiple times)')\n .option('--preset <name...>', 'Preset names to enable (can be specified multiple times)')\n .option(\n '--remove-features <flag...>',\n 'Feature flags to remove (can be specified multiple times)',\n )\n // @awa-impl: CLI-5_AC-1\n .option('--force', 'Force overwrite existing files without prompting', false)\n // @awa-impl: CLI-6_AC-1\n .option('--dry-run', 'Preview changes without modifying files', false)\n .option(\n '--delete',\n 'Enable deletion of files listed in the delete list (default: warn only)',\n false,\n )\n // @awa-impl: CLI-7_AC-1\n .option('-c, --config <path>', 'Path to configuration file')\n // @awa-impl: CLI-8_AC-1\n .option('--refresh', 'Force refresh of cached Git templates', false)\n // @awa-impl: CLI-15_AC-1\n .option('--all-targets', 'Process all named targets from config', false)\n // @awa-impl: CLI-15_AC-2\n .option('--target <name>', 'Process a specific named target from config')\n // @awa-impl: OVL-1_AC-1\n .option(\n '--overlay <path...>',\n 'Overlay directory paths applied over base template (repeatable)',\n )\n // @awa-impl: JSON-1_AC-1\n .option('--json', 'Output results as JSON (implies --dry-run)', false)\n // @awa-impl: JSON-5_AC-1\n .option('--summary', 'Output compact one-line summary', false)\n .action(async (output: string | undefined, options) => {\n // @awa-impl: CLI-11_AC-1, CLI-11_AC-2, CLI-11_AC-3\n const cliOptions: RawCliOptions = {\n output,\n template: options.template,\n features: options.features,\n preset: options.preset,\n removeFeatures: options.removeFeatures,\n force: options.force,\n dryRun: options.dryRun,\n delete: options.delete,\n config: options.config,\n refresh: options.refresh,\n all: options.allTargets,\n allTargets: options.allTargets,\n target: options.target,\n overlay: options.overlay || [],\n json: options.json,\n summary: options.summary,\n };\n\n await generateCommand(cliOptions);\n })\n );\n}\n\nconfigureGenerateCommand(template.command('generate'));\n\n// @awa-impl: CLI-42_AC-1, CLI-42_AC-2\n// Top-level init convenience command (delegates to same handler as template generate)\nconfigureGenerateCommand(program.command('init'));\n\n// @awa-impl: DIFF-7_AC-1, DIFF-7_AC-2, DIFF-7_AC-3, DIFF-7_AC-4, DIFF-7_AC-5, DIFF-7_AC-6, DIFF-7_AC-7, DIFF-7_AC-8, DIFF-7_AC-9, DIFF-7_AC-10\n// @awa-impl: CLI-41_AC-5\ntemplate\n .command('diff')\n .description('Compare template output with existing target directory')\n // @awa-impl: DIFF-7_AC-1, DIFF-7_AC-2, DIFF-7_AC-3, DIFF-7_AC-4, DIFF-7_AC-5\n .argument('[target]', 'Target directory to compare against (optional if specified in config)')\n // @awa-impl: DIFF-7_AC-6\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n // @awa-impl: DIFF-7_AC-7\n .option('-f, --features <flag...>', 'Feature flags (can be specified multiple times)')\n .option('--preset <name...>', 'Preset names to enable (can be specified multiple times)')\n .option(\n '--remove-features <flag...>',\n 'Feature flags to remove (can be specified multiple times)',\n )\n // @awa-impl: DIFF-7_AC-8\n .option('-c, --config <path>', 'Path to configuration file')\n // @awa-impl: DIFF-7_AC-9\n .option('--refresh', 'Force refresh of cached Git templates', false)\n // @awa-impl: DIFF-7_AC-11\n .option('--list-unknown', 'Include target-only files in diff results', false)\n // @awa-impl: CLI-15_AC-1\n .option('--all-targets', 'Process all named targets from config', false)\n // @awa-impl: CLI-15_AC-2\n .option('--target <name>', 'Process a specific named target from config')\n .option('-w, --watch', 'Watch template directory for changes and re-run diff', false)\n // @awa-impl: OVL-7_AC-1\n .option('--overlay <path...>', 'Overlay directory paths applied over base template (repeatable)')\n // @awa-impl: JSON-2_AC-1\n .option('--json', 'Output results as JSON', false)\n // @awa-impl: JSON-5_AC-1\n .option('--summary', 'Output compact one-line summary', false)\n // @awa-impl: DIFF-7_AC-10\n // Note: --force and --dry-run are intentionally NOT accepted for diff command\n .action(async (target: string | undefined, options) => {\n const cliOptions: RawCliOptions = {\n output: target, // Use target as output for consistency\n template: options.template,\n features: options.features,\n preset: options.preset,\n removeFeatures: options.removeFeatures,\n config: options.config,\n refresh: options.refresh,\n listUnknown: options.listUnknown,\n all: options.allTargets,\n allTargets: options.allTargets,\n target: options.target,\n watch: options.watch,\n overlay: options.overlay || [],\n json: options.json,\n summary: options.summary,\n };\n\n const exitCode = await diffCommand(cliOptions);\n process.exit(exitCode);\n });\n\n// @awa-impl: CLI-23_AC-1, CLI-24_AC-1, CLI-25_AC-1\n// @awa-impl: CLI-43_AC-1, CLI-43_AC-3\nprogram\n .command('check')\n .description(\n 'Validate spec files against schemas and check traceability between code markers and specs',\n )\n .option('-c, --config <path>', 'Path to configuration file')\n // @awa-impl: CLI-25_AC-1\n .option('--spec-ignore <pattern...>', 'Glob patterns to exclude from spec file scanning')\n .option('--code-ignore <pattern...>', 'Glob patterns to exclude from code file scanning')\n // @awa-impl: CLI-24_AC-1\n .option('--json', 'Output results as JSON', false)\n .addOption(\n new Option('--format <format>', 'Output format (text or json)').default('text').hideHelp(),\n )\n .option('--summary', 'Output compact one-line summary', false)\n .option(\n '--allow-warnings',\n 'Allow warnings without failing (default: warnings are errors)',\n false,\n )\n .option(\n '--spec-only',\n 'Run only spec-level checks (schema and cross-refs); skip code-to-spec traceability',\n false,\n )\n .option(\n '--no-fix',\n 'Skip regeneration of Requirements Traceability sections in DESIGN and TASK files',\n )\n .action(async (options) => {\n const cliOptions: RawCheckOptions = {\n config: options.config,\n specIgnore: options.specIgnore,\n codeIgnore: options.codeIgnore,\n format: options.format,\n json: options.json,\n summary: options.summary,\n allowWarnings: options.allowWarnings,\n specOnly: options.specOnly,\n fix: options.fix,\n };\n\n const exitCode = await checkCommand(cliOptions);\n process.exit(exitCode);\n });\n\n// @awa-impl: DISC-4_AC-1, DISC-5_AC-1\n// @awa-impl: CLI-41_AC-6\ntemplate\n .command('features')\n .description('Discover feature flags available in a template')\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n .option('-c, --config <path>', 'Path to configuration file')\n .option('--refresh', 'Force refresh of cached Git templates', false)\n .option('--overlay <path...>', 'Overlay directory paths applied over base template (repeatable)')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .action(async (options) => {\n const exitCode = await featuresCommand({\n template: options.template,\n config: options.config,\n refresh: options.refresh,\n json: options.json,\n summary: options.summary,\n overlay: options.overlay || [],\n });\n process.exit(exitCode);\n });\n\n// @awa-impl: TTST-7_AC-1, TTST-5_AC-1\n// @awa-impl: CLI-41_AC-7\ntemplate\n .command('test')\n .description('Run template test fixtures to verify expected output')\n .option('-t, --template <source>', 'Template source (local path or Git repository)')\n .option('-c, --config <path>', 'Path to configuration file')\n .option('--update-snapshots', 'Update stored snapshots with current rendered output', false)\n .option('--refresh', 'Force refresh of cached Git templates', false)\n .option('--overlay <path...>', 'Overlay directory paths applied over base template (repeatable)')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .action(async (options) => {\n const testOptions: RawTestOptions = {\n template: options.template,\n config: options.config,\n updateSnapshots: options.updateSnapshots,\n refresh: options.refresh,\n json: options.json,\n summary: options.summary,\n overlay: options.overlay || [],\n };\n\n const exitCode = await testCommand(testOptions);\n process.exit(exitCode);\n });\n\n// Add template group to root program\nprogram.addCommand(template);\n\n// ── spec subcommand group ──\nconst spec = new Command('spec').description(\n 'Spec operations (trace, renumber, recode, merge, codes)',\n);\n\n// @awa-impl: TRC-8_AC-1\n// @awa-impl: CLI-43_AC-2, CLI-43_AC-4\n\n/** Configure a trace command with shared options and action handler. */\nfunction configureTraceCommand(cmd: Command): Command {\n return cmd\n .description('Explore traceability chains and assemble context from specs, code, and tests')\n .argument('[ids...]', 'Traceability ID(s) to trace')\n .option('--all', 'Trace all known IDs in the project', false)\n .option('--task <path>', 'Resolve IDs from a task file')\n .option('--file <path>', \"Resolve IDs from a source file's markers\")\n .option('--content', 'Output actual file sections instead of locations', false)\n .option('--list', 'Output file paths only (no content or tree)', false)\n .option('--max-tokens <n>', 'Cap content output size (implies --content)')\n .option('--depth <n>', 'Maximum traversal depth')\n .option('--scope <code>', 'Limit results to a feature code')\n .option('--direction <dir>', 'Traversal direction: both, forward, reverse', 'both')\n .option('--no-code', 'Exclude source code (spec-only context)')\n .option('--no-tests', 'Exclude test files')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .option('-A <n>', 'Lines of context after a code marker (--content only; default: 20)')\n .option('-B <n>', 'Lines of context before a code marker (--content only; default: 5)')\n .option('-C <n>', 'Lines of context before and after (--content only; overrides -A and -B)')\n .option('-c, --config <path>', 'Path to configuration file')\n .action(async (ids: string[], options) => {\n const traceOptions: TraceCommandOptions = {\n ids,\n all: options.all,\n task: options.task,\n file: options.file,\n content: options.content,\n list: options.list,\n json: options.json,\n summary: options.summary,\n maxTokens: options.maxTokens !== undefined ? Number(options.maxTokens) : undefined,\n depth: options.depth !== undefined ? Number(options.depth) : undefined,\n scope: options.scope,\n direction: options.direction,\n noCode: options.code === false,\n noTests: options.tests === false,\n beforeContext:\n options.C !== undefined\n ? Number(options.C)\n : options.B !== undefined\n ? Number(options.B)\n : undefined,\n afterContext:\n options.C !== undefined\n ? Number(options.C)\n : options.A !== undefined\n ? Number(options.A)\n : undefined,\n config: options.config,\n };\n\n const exitCode = await traceCommand(traceOptions);\n process.exit(exitCode);\n });\n}\n\nconfigureTraceCommand(spec.command('trace'));\n\n/** Configure a renumber command with shared options and action handler. */\nfunction configureRenumberCommand(cmd: Command): Command {\n return cmd\n .description('Renumber traceability IDs to match document order')\n .argument('[code]', 'Feature code to renumber (e.g. CHK, TRC)')\n .option('--all', 'Renumber all feature codes', false)\n .option('--dry-run', 'Preview changes without modifying files', false)\n .option('--json', 'Output results as JSON', false)\n .option(\n '--expand-unambiguous-ids',\n 'Expand unambiguous malformed ID shorthand (slash ranges, dot-dot ranges) before renumbering',\n false,\n )\n .option('-c, --config <path>', 'Path to configuration file')\n .action(async (code: string | undefined, options) => {\n const renumberOptions: RenumberCommandOptions = {\n code,\n all: options.all,\n dryRun: options.dryRun,\n json: options.json,\n config: options.config,\n expandUnambiguousIds: options.expandUnambiguousIds,\n };\n\n const exitCode = await renumberCommand(renumberOptions);\n process.exit(exitCode);\n });\n}\n\nconfigureRenumberCommand(spec.command('renumber'));\n\nspec\n .command('recode')\n .description('Recode traceability IDs from one feature code to another and rename spec files')\n .argument('<source>', 'Source feature code to recode from (e.g. CHK)')\n .argument('<target>', 'Target feature code to recode into (e.g. CLI)')\n .option('--dry-run', 'Preview changes without modifying files', false)\n .option('--json', 'Output results as JSON', false)\n .option('--renumber', 'Renumber target code after recode', false)\n .option('-c, --config <path>', 'Path to configuration file')\n .action(async (source: string, target: string, options) => {\n const recodeOptions: RecodeCommandOptions = {\n sourceCode: source,\n targetCode: target,\n dryRun: options.dryRun,\n json: options.json,\n renumber: options.renumber,\n config: options.config,\n };\n\n const exitCode = await recodeCommand(recodeOptions);\n process.exit(exitCode);\n });\n\nspec\n .command('merge')\n .description('Merge one feature code into another (recode + content merge + cleanup)')\n .argument('<source>', 'Source feature code to merge from (e.g. CHK)')\n .argument('<target>', 'Target feature code to merge into (e.g. CLI)')\n .option('--dry-run', 'Preview changes without modifying files', false)\n .option('--json', 'Output results as JSON', false)\n .option('--renumber', 'Renumber target code after merge', false)\n .option('-c, --config <path>', 'Path to configuration file')\n .action(async (source: string, target: string, options) => {\n const mergeOptions: MergeCommandOptions = {\n sourceCode: source,\n targetCode: target,\n dryRun: options.dryRun,\n json: options.json,\n renumber: options.renumber,\n config: options.config,\n };\n\n const exitCode = await mergeCommand(mergeOptions);\n process.exit(exitCode);\n });\n\nspec\n .command('codes')\n .description('List all feature codes with requirement counts and scope summaries')\n .option('--json', 'Output results as JSON', false)\n .option('--summary', 'Output compact one-line summary', false)\n .option('-c, --config <path>', 'Path to configuration file')\n .action(async (options) => {\n const codesOptions: CodesCommandOptions = {\n json: options.json,\n summary: options.summary,\n config: options.config,\n };\n\n const exitCode = await codesCommand(codesOptions);\n process.exit(exitCode);\n });\n\n// Add spec group to root program\nprogram.addCommand(spec);\n\n// Backward-compat aliases: `awa trace` → `awa spec trace`, `awa renumber` → `awa spec renumber`\nconfigureTraceCommand(program.command('trace'));\nconfigureRenumberCommand(program.command('renumber', { hidden: true }));\n\n// Fire update check asynchronously (non-blocking) before parse\nlet updateCheckPromise: Promise<UpdateCheckResult | null> | null = null;\n\nconst isJsonOrSummary = process.argv.includes('--json') || process.argv.includes('--summary');\nconst isTTY = process.stdout.isTTY === true;\nconst isDisabledByEnv = !!process.env.NO_UPDATE_NOTIFIER;\n\nif (!isJsonOrSummary && isTTY && !isDisabledByEnv) {\n updateCheckPromise = (async () => {\n try {\n // Load config to check update-check settings\n const { configLoader } = await import('../core/config.js');\n const configPath =\n process.argv.indexOf('-c') !== -1\n ? process.argv[process.argv.indexOf('-c') + 1]\n : process.argv.indexOf('--config') !== -1\n ? process.argv[process.argv.indexOf('--config') + 1]\n : undefined;\n const fileConfig = await configLoader.load(configPath ?? null);\n\n const updateCheckConfig = fileConfig?.['update-check'];\n if (updateCheckConfig?.enabled === false) return null;\n\n const intervalSeconds = updateCheckConfig?.interval ?? 86400;\n const intervalMs = intervalSeconds * 1000;\n\n const needsCheck = await shouldCheck(intervalMs);\n if (!needsCheck) return null;\n\n const result = await checkForUpdate();\n if (result) {\n await writeCache(result.latest);\n }\n return result;\n } catch {\n return null;\n }\n })();\n}\n\n// Print update warning after command completes\nprogram.hook('postAction', async () => {\n if (!updateCheckPromise) return;\n try {\n const result = await updateCheckPromise;\n if (result?.isOutdated) {\n printUpdateWarning(logger, result);\n }\n } catch {\n // Silently ignore\n }\n});\n\n// @awa-impl: GEN-10_AC-1, GEN-10_AC-2\nvoid program.parseAsync();\n","// This file is automatically generated. DO NOT EDIT.\n\n/* eslint-disable */\n\nexport const PACKAGE_INFO = {\n \"name\": \"@ncoderz/awa\",\n \"version\": \"1.8.1\",\n \"author\": \"Richard Sewell <richard.sewell@ncoderz.com>\",\n \"license\": \"BSD-3-Clause\",\n \"description\": \"awa is an Agent Workflow for AIs. It is also a CLI tool to powerfully manage agent workflow files using templates.\"\n};\n","// @awa-component: CLI-CodeSpecChecker\n// @awa-impl: CLI-18_AC-1\n// @awa-impl: CLI-19_AC-1\n// @awa-impl: CLI-21_AC-1\n// @awa-impl: CLI-29_AC-1\n// @awa-impl: CLI-33_AC-1\n// @awa-impl: CLI-34_AC-1\n// @awa-impl: CLI-35_AC-1\n// @awa-impl: CLI-36_AC-1\n// @awa-impl: CLI-37_AC-1\n\nimport type {\n CheckConfig,\n CheckResult,\n Finding,\n MarkerScanResult,\n SpecParseResult,\n} from './types.js';\n\n// @awa-impl: CLI-18_AC-1, CLI-19_AC-1, CLI-21_AC-1, CLI-33_AC-1, CLI-34_AC-1, CLI-35_AC-1, CLI-36_AC-1, CLI-37_AC-1\nexport function checkCodeAgainstSpec(\n markers: MarkerScanResult,\n specs: SpecParseResult,\n config: CheckConfig,\n): CheckResult {\n const findings: Finding[] = [];\n\n // @awa-impl: CLI-21_AC-1, CLI-29_AC-1\n // Validate ID format for all markers\n const idRegex = new RegExp(`^${config.idPattern}$`);\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n // Component names have different format — skip ID pattern check\n continue;\n }\n if (!idRegex.test(marker.id)) {\n findings.push({\n severity: 'error',\n code: 'invalid-id-format',\n message: `Marker ID '${marker.id}' does not match expected pattern: ${config.idPattern}`,\n filePath: marker.filePath,\n line: marker.line,\n id: marker.id,\n });\n }\n }\n\n // @awa-impl: CLI-18_AC-1\n // Check for orphaned markers (code references non-existent spec ID)\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n // Component markers reference component names\n if (!specs.componentNames.has(marker.id)) {\n findings.push({\n severity: 'error',\n code: 'orphaned-marker',\n message: `Component marker '${marker.id}' not found in any spec file`,\n filePath: marker.filePath,\n line: marker.line,\n id: marker.id,\n });\n }\n } else {\n // impl and test markers reference IDs (ACs, properties, requirement IDs)\n if (!specs.allIds.has(marker.id)) {\n findings.push({\n severity: 'error',\n code: 'orphaned-marker',\n message: `Marker '${marker.id}' not found in any spec file`,\n filePath: marker.filePath,\n line: marker.line,\n id: marker.id,\n });\n }\n }\n }\n\n // @awa-impl: CLI-19_AC-1\n // Check for uncovered ACs (spec ACs with no @awa-test reference)\n const testedIds = new Set(markers.markers.filter((m) => m.type === 'test').map((m) => m.id));\n\n for (const acId of specs.acIds) {\n if (!testedIds.has(acId)) {\n // Look up location from idLocations map, fall back to spec file path\n const loc = specs.idLocations.get(acId);\n const specFile = loc ? undefined : specs.specFiles.find((sf) => sf.acIds.includes(acId));\n findings.push({\n severity: 'warning',\n code: 'uncovered-ac',\n message: `Acceptance criterion '${acId}' has no @awa-test reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: acId,\n });\n }\n }\n\n // @awa-impl: CLI-33_AC-1\n // Check for uncovered components (DESIGN components with no @awa-component marker)\n const implementedComponents = new Set(\n markers.markers.filter((m) => m.type === 'component').map((m) => m.id),\n );\n\n for (const componentName of specs.componentNames) {\n if (!implementedComponents.has(componentName)) {\n const loc = specs.idLocations.get(componentName);\n const specFile = loc\n ? undefined\n : specs.specFiles.find((sf) => sf.componentNames.includes(componentName));\n findings.push({\n severity: 'warning',\n code: 'uncovered-component',\n message: `Component '${componentName}' has no @awa-component reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: componentName,\n });\n }\n }\n\n // @awa-impl: CLI-34_AC-1\n // Check for unimplemented ACs (spec ACs with no @awa-impl marker)\n const implementedIds = new Set(markers.markers.filter((m) => m.type === 'impl').map((m) => m.id));\n\n for (const acId of specs.acIds) {\n if (!implementedIds.has(acId)) {\n const loc = specs.idLocations.get(acId);\n const specFile = loc ? undefined : specs.specFiles.find((sf) => sf.acIds.includes(acId));\n findings.push({\n severity: 'warning',\n code: 'unimplemented-ac',\n message: `Acceptance criterion '${acId}' has no @awa-impl reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: acId,\n });\n }\n }\n\n // @awa-impl: CLI-35_AC-1\n // G5: Check for uncovered properties (spec properties with no @awa-test marker)\n for (const propId of specs.propertyIds) {\n if (!testedIds.has(propId)) {\n const loc = specs.idLocations.get(propId);\n const specFile = loc\n ? undefined\n : specs.specFiles.find((sf) => sf.propertyIds.includes(propId));\n findings.push({\n severity: 'warning',\n code: 'uncovered-property',\n message: `Property '${propId}' has no @awa-test reference`,\n filePath: loc?.filePath ?? specFile?.filePath,\n line: loc?.line,\n id: propId,\n });\n }\n }\n\n // @awa-impl: CLI-37_AC-1\n // G1: Check IMPLEMENTS ↔ @awa-impl consistency\n // For each @awa-component marker in code, compare the set of @awa-impl IDs\n // in the same file against the DESIGN component's IMPLEMENTS list\n const componentFiles = new Map<string, Set<string>>();\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n if (!componentFiles.has(marker.id)) {\n componentFiles.set(marker.id, new Set());\n }\n }\n }\n // Collect all @awa-impl IDs per component (by file co-location)\n // A file's component is determined by @awa-component markers in that file\n const fileToComponents = new Map<string, string[]>();\n for (const marker of markers.markers) {\n if (marker.type === 'component') {\n const existing = fileToComponents.get(marker.filePath) ?? [];\n existing.push(marker.id);\n fileToComponents.set(marker.filePath, existing);\n }\n }\n for (const marker of markers.markers) {\n if (marker.type === 'impl') {\n const components = fileToComponents.get(marker.filePath);\n if (components) {\n for (const comp of components) {\n componentFiles.get(comp)?.add(marker.id);\n }\n }\n }\n }\n\n // Build the IMPLEMENTS set per component from all DESIGN spec files\n const designImplements = new Map<string, Set<string>>();\n for (const specFile of specs.specFiles) {\n if (specFile.componentImplements) {\n for (const [comp, ids] of specFile.componentImplements) {\n const existing = designImplements.get(comp) ?? new Set();\n for (const id of ids) existing.add(id);\n designImplements.set(comp, existing);\n }\n }\n }\n\n for (const [compName, codeImplIds] of componentFiles) {\n const designImplIds = designImplements.get(compName);\n if (!designImplIds) continue; // No DESIGN component found (already caught by orphaned-marker)\n\n // impl-not-in-implements: @awa-impl in code but not in DESIGN IMPLEMENTS\n for (const implId of codeImplIds) {\n if (!designImplIds.has(implId)) {\n findings.push({\n severity: 'warning',\n code: 'impl-not-in-implements',\n message: `@awa-impl '${implId}' in component '${compName}' is not listed in its IMPLEMENTS`,\n id: implId,\n });\n }\n }\n\n // implements-not-in-impl: DESIGN IMPLEMENTS but no @awa-impl in any file tagged with that component\n for (const implId of designImplIds) {\n if (!codeImplIds.has(implId)) {\n const loc = specs.idLocations.get(compName);\n findings.push({\n severity: 'warning',\n code: 'implements-not-in-impl',\n message: `IMPLEMENTS '${implId}' in component '${compName}' has no @awa-impl in code`,\n filePath: loc?.filePath,\n line: loc?.line,\n id: implId,\n });\n }\n }\n }\n\n return { findings };\n}\n","// @awa-component: CLI-CodesFixer\n// @awa-impl: CLI-40_AC-1\n// @awa-impl: CLI-40_AC-2\n\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\n\nimport { scanCodes } from '../codes/scanner.js';\nimport type { FixResult } from './matrix-fixer.js';\nimport type { CheckConfig, SpecParseResult } from './types.js';\n\n/** Escape characters that would break a Markdown table cell. */\nfunction sanitizeCell(value: string): string {\n return value\n .replace(/\\|/g, '\\\\|')\n .replace(/[\\r\\n]+/g, ' ')\n .trim();\n}\n\nexport interface CodesFixResult extends FixResult {\n /** Codes that have no scope boundary text. */\n readonly emptyScopeCodes: readonly string[];\n}\n\n/**\n * Regenerate the \"Feature Codes\" table in ARCHITECTURE.md from spec data.\n * Returns whether the file was modified and any codes missing scope text.\n */\nexport async function fixCodesTable(\n specs: SpecParseResult,\n config: Pick<CheckConfig, 'specGlobs' | 'specIgnore'>,\n): Promise<CodesFixResult> {\n // Find ARCHITECTURE.md in spec files\n const archFile = specs.specFiles.find((sf) => basename(sf.filePath) === 'ARCHITECTURE.md');\n\n if (!archFile) {\n return { filesFixed: 0, fileResults: [], emptyScopeCodes: [] };\n }\n\n let content: string;\n if (archFile.content != null) {\n content = archFile.content;\n } else {\n try {\n content = await readFile(archFile.filePath, 'utf-8');\n } catch {\n return { filesFixed: 0, fileResults: [], emptyScopeCodes: [] };\n }\n }\n\n // Check if ## Feature Codes section exists\n const lines = content.split('\\n');\n const sectionStart = lines.findIndex((l) => /^##\\s+Feature Codes\\s*$/.test(l));\n if (sectionStart === -1) {\n return { filesFixed: 0, fileResults: [], emptyScopeCodes: [] };\n }\n\n // Scan codes from spec data\n const codesResult = await scanCodes(specs.specFiles, config.specGlobs, config.specIgnore);\n\n // Generate new table\n const tableLines: string[] = [];\n tableLines.push('');\n tableLines.push(\n 'Run `awa spec codes` for the live inventory. The table below defines scope boundaries.',\n );\n tableLines.push('');\n tableLines.push('| Code | Feature | Scope Boundary |');\n tableLines.push('|------|---------|----------------|');\n\n const emptyScopeCodes: string[] = [];\n\n for (const code of codesResult.codes) {\n const scope = sanitizeCell(code.scope || '');\n if (!scope) {\n emptyScopeCodes.push(code.code);\n }\n tableLines.push(`| ${sanitizeCell(code.code)} | ${sanitizeCell(code.feature)} | ${scope} |`);\n }\n\n const newSection = tableLines.join('\\n');\n\n // Replace section content\n const newContent = replaceFeatureCodesSection(content, sectionStart, newSection);\n if (newContent === content) {\n return {\n filesFixed: 0,\n fileResults: [{ filePath: archFile.filePath, changed: false }],\n emptyScopeCodes,\n };\n }\n\n await writeFile(archFile.filePath, newContent, 'utf-8');\n return {\n filesFixed: 1,\n fileResults: [{ filePath: archFile.filePath, changed: true }],\n emptyScopeCodes,\n };\n}\n\n/**\n * Replace the content of the Feature Codes section (between ## Feature Codes and the next ## heading).\n */\nfunction replaceFeatureCodesSection(\n content: string,\n sectionStart: number,\n newSection: string,\n): string {\n const lines = content.split('\\n');\n\n // Find the next ## heading after the section start\n let sectionEnd = lines.length;\n for (let i = sectionStart + 1; i < lines.length; i++) {\n const line = lines[i];\n if (line !== undefined && /^##\\s/.test(line)) {\n sectionEnd = i;\n break;\n }\n }\n\n const before = lines.slice(0, sectionStart + 1);\n const after = lines.slice(sectionEnd);\n\n const result = [...before, newSection.trimEnd(), '', ...after];\n return result.join('\\n');\n}\n","import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\n\nimport { collectFiles } from '../check/glob.js';\nimport type { SpecFile } from '../check/types.js';\nimport type { CodesResult, DocTypes, FeatureCode } from './types.js';\n\ninterface FileRef {\n readonly filePath: string;\n readonly content?: string;\n}\n\n/**\n * Scan spec files to discover all feature codes with metadata.\n * Reuses the check engine's glob infrastructure for file discovery.\n */\nexport async function scanCodes(\n specFiles: readonly SpecFile[],\n specGlobs: readonly string[],\n specIgnore: readonly string[],\n): Promise<CodesResult> {\n // Discover codes from all spec file types (FEAT, REQ, DESIGN, API)\n const codeMap = new Map<\n string,\n {\n feature: string;\n reqCount: number;\n feat: boolean;\n req: boolean;\n design: boolean;\n api: boolean;\n example: boolean;\n }\n >();\n\n // Also collect FEAT files from glob (they aren't always in specFiles)\n const featFiles = await collectFiles(\n specGlobs.filter((g) => g.includes('FEAT-')),\n specIgnore,\n );\n for (const fp of featFiles) {\n const fileName = basename(fp);\n const match = /^FEAT-([A-Z][A-Z0-9]*)-(.+)\\.md$/.exec(fileName);\n if (!match?.[1]) continue;\n const code = match[1];\n const existing = codeMap.get(code);\n if (existing) {\n existing.feat = true;\n } else {\n codeMap.set(code, {\n feature: match[2] ?? code,\n reqCount: 0,\n feat: true,\n req: false,\n design: false,\n api: false,\n example: false,\n });\n }\n }\n\n for (const sf of specFiles) {\n if (!sf.code) continue;\n const fileName = basename(sf.filePath);\n const prefix = fileName.split('-')[0];\n\n const existing = codeMap.get(sf.code);\n if (existing) {\n if (prefix === 'REQ') {\n existing.req = true;\n existing.reqCount += sf.requirementIds.length;\n // Prefer feature name from REQ file over FEAT-derived name\n if (existing.feature === sf.code || !existing.feature) {\n existing.feature = extractFeatureName(fileName);\n }\n } else if (prefix === 'DESIGN') {\n existing.design = true;\n } else if (prefix === 'API') {\n existing.api = true;\n } else if (prefix === 'EXAMPLE') {\n existing.example = true;\n } else if (prefix === 'FEAT') {\n existing.feat = true;\n }\n } else {\n const feature =\n prefix === 'REQ' ? extractFeatureName(fileName) : extractFeatureNameGeneric(fileName);\n codeMap.set(sf.code, {\n feature,\n reqCount: prefix === 'REQ' ? sf.requirementIds.length : 0,\n feat: prefix === 'FEAT',\n req: prefix === 'REQ',\n design: prefix === 'DESIGN',\n api: prefix === 'API',\n example: prefix === 'EXAMPLE',\n });\n }\n }\n\n // Extract scope summaries with fallback chain\n const scopeMap = await extractScopeSummaries(specFiles, specGlobs, specIgnore);\n\n // Build result\n const codes: FeatureCode[] = [];\n for (const [code, meta] of codeMap) {\n const docs: DocTypes = {\n feat: meta.feat,\n req: meta.req,\n design: meta.design,\n api: meta.api,\n example: meta.example,\n };\n codes.push({\n code,\n feature: meta.feature,\n reqCount: meta.reqCount,\n scope: scopeMap.get(code) ?? '',\n docs,\n });\n }\n\n // Sort alphabetically by code\n codes.sort((a, b) => a.code.localeCompare(b.code));\n\n return { codes };\n}\n\n/**\n * Extract feature name from a REQ filename.\n * e.g. \"REQ-CHK-check.md\" → \"check\"\n */\nfunction extractFeatureName(fileName: string): string {\n const name = basename(fileName, '.md');\n // REQ-CODE-feature-name → feature-name\n const match = /^REQ-[A-Z][A-Z0-9]*-(.+)$/.exec(name);\n return match?.[1] ?? name;\n}\n\n/**\n * Extract feature name from any spec filename (FEAT, DESIGN, API).\n * e.g. \"DESIGN-CHK-check.md\" → \"check\", \"API-CHK-rest-api.tsp\" → \"rest-api\"\n */\nfunction extractFeatureNameGeneric(fileName: string): string {\n const name = basename(fileName).replace(/\\.[^.]+$/, '');\n // PREFIX-CODE-feature-name → feature-name\n const match = /^[A-Z]+-[A-Z][A-Z0-9]*-(.+)$/.exec(name);\n return match?.[1] ?? name;\n}\n\n/**\n * Extract scope summaries using fallback chain:\n * 1. FEAT `## Scope Boundary` section\n * 2. FEAT first paragraph after first `##`\n * 3. REQ first paragraph after first `##`\n * 4. DESIGN first paragraph after first `##`\n *\n * Reuses SpecFile.content when available to avoid redundant disk reads.\n */\nasync function extractScopeSummaries(\n specFiles: readonly SpecFile[],\n specGlobs: readonly string[],\n specIgnore: readonly string[],\n): Promise<Map<string, string>> {\n const scopeMap = new Map<string, string>();\n\n // Build code → FileRef maps from already-parsed specFiles first\n const featByCode = buildFileRefMapFromSpecFiles(specFiles, 'FEAT');\n const reqByCode = buildFileRefMapFromSpecFiles(specFiles, 'REQ');\n const designByCode = buildFileRefMapFromSpecFiles(specFiles, 'DESIGN');\n\n // Also discover FEAT files via glob that might not be in specFiles\n const scopeFeatFiles = await collectFiles(\n specGlobs.filter((g) => g.includes('FEAT-')),\n specIgnore,\n );\n for (const fp of scopeFeatFiles) {\n const name = basename(fp, '.md');\n const match = /^FEAT-([A-Z][A-Z0-9]*)-/.exec(name);\n if (match?.[1] && !featByCode.has(match[1])) {\n featByCode.set(match[1], { filePath: fp });\n }\n }\n\n // Collect all codes that need scope\n const allCodes = new Set<string>();\n for (const code of featByCode.keys()) allCodes.add(code);\n for (const sf of specFiles) {\n if (sf.code) {\n allCodes.add(sf.code);\n }\n }\n\n for (const code of allCodes) {\n const scope = await resolveScope(code, featByCode, reqByCode, designByCode);\n if (scope) {\n scopeMap.set(code, scope);\n }\n }\n\n return scopeMap;\n}\n\n/**\n * Resolve scope text for a code using the fallback chain.\n * Uses cached content from SpecFile when available; falls back to readFile.\n */\nasync function resolveScope(\n code: string,\n featByCode: Map<string, FileRef>,\n reqByCode: Map<string, FileRef>,\n designByCode: Map<string, FileRef>,\n): Promise<string> {\n // 1. Try FEAT ## Scope Boundary\n const featRef = featByCode.get(code);\n if (featRef) {\n const content = await readContent(featRef);\n if (content) {\n const scopeBoundary = extractScopeBoundary(content);\n if (scopeBoundary) return scopeBoundary;\n\n // 2. Fall back to FEAT first paragraph\n const firstParagraph = extractFirstParagraph(content);\n if (firstParagraph) return firstParagraph;\n }\n }\n\n // 3. Fall back to REQ first paragraph\n const reqRef = reqByCode.get(code);\n if (reqRef) {\n const content = await readContent(reqRef);\n if (content) {\n const firstParagraph = extractFirstParagraph(content);\n if (firstParagraph) return firstParagraph;\n }\n }\n\n // 4. Fall back to DESIGN first paragraph\n const designRef = designByCode.get(code);\n if (designRef) {\n const content = await readContent(designRef);\n if (content) {\n const firstParagraph = extractFirstParagraph(content);\n if (firstParagraph) return firstParagraph;\n }\n }\n\n return '';\n}\n\n/**\n * Read content from a FileRef, using cached content if available.\n */\nasync function readContent(ref: FileRef): Promise<string | undefined> {\n if (ref.content != null) return ref.content;\n try {\n return await readFile(ref.filePath, 'utf-8');\n } catch {\n return undefined;\n }\n}\n\n/**\n * Build code → FileRef map from SpecFile entries for a given prefix,\n * preserving cached content to avoid re-reads.\n */\nfunction buildFileRefMapFromSpecFiles(\n specFiles: readonly SpecFile[],\n prefix: string,\n): Map<string, FileRef> {\n const map = new Map<string, FileRef>();\n for (const sf of specFiles) {\n if (sf.code && basename(sf.filePath).startsWith(`${prefix}-`) && !map.has(sf.code)) {\n map.set(sf.code, { filePath: sf.filePath, content: sf.content });\n }\n }\n return map;\n}\n\n/**\n * Extract text from the `## Scope Boundary` section in a FEAT file.\n * Returns the first paragraph after the heading, or empty string if not found.\n */\nexport function extractScopeBoundary(content: string): string {\n const lines = content.split('\\n');\n let inSection = false;\n const paragraphLines: string[] = [];\n\n for (const line of lines) {\n if (!inSection) {\n if (/^##\\s+Scope Boundary\\s*$/.test(line)) {\n inSection = true;\n }\n continue;\n }\n\n const trimmed = line.trim();\n\n // Skip blank lines before the paragraph starts\n if (paragraphLines.length === 0 && trimmed === '') {\n continue;\n }\n\n // Stop at the next heading or blank line after we've started collecting\n if (paragraphLines.length > 0 && (trimmed === '' || /^#/.test(trimmed))) {\n break;\n }\n\n paragraphLines.push(trimmed);\n }\n\n const paragraph = paragraphLines.join(' ').trim();\n if (paragraph.length > 120) {\n return `${paragraph.slice(0, 117)}...`;\n }\n return paragraph;\n}\n\n/**\n * Extract the first paragraph after the first ## heading.\n * Returns the first non-empty paragraph text, truncated to a single line.\n */\nexport function extractFirstParagraph(content: string): string {\n const lines = content.split('\\n');\n let foundHeading = false;\n const paragraphLines: string[] = [];\n\n for (const line of lines) {\n // Look for the first ## heading\n if (!foundHeading) {\n if (/^##\\s/.test(line)) {\n foundHeading = true;\n }\n continue;\n }\n\n const trimmed = line.trim();\n\n // Skip blank lines before the paragraph starts\n if (paragraphLines.length === 0 && trimmed === '') {\n continue;\n }\n\n // Stop at the next heading or blank line after we've started collecting\n if (paragraphLines.length > 0 && (trimmed === '' || /^#/.test(trimmed))) {\n break;\n }\n\n paragraphLines.push(trimmed);\n }\n\n const paragraph = paragraphLines.join(' ').trim();\n // Truncate to ~120 chars for table display\n if (paragraph.length > 120) {\n return `${paragraph.slice(0, 117)}...`;\n }\n return paragraph;\n}\n","// @awa-component: CLI-MatrixFixer\n// @awa-impl: CLI-38_AC-1\n// @awa-impl: CLI-38_AC-2\n\nimport { readFile, writeFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\n\nimport type { SpecFile, SpecParseResult } from './types.js';\n\n// --- Public API ---\n\nexport interface FixResult {\n readonly filesFixed: number;\n readonly fileResults: readonly FileFixResult[];\n}\n\nexport interface FileFixResult {\n readonly filePath: string;\n readonly changed: boolean;\n}\n\n/**\n * Regenerate \"Requirements Traceability\" sections in all DESIGN and TASK files.\n * Returns the number of files that were actually modified.\n */\nexport async function fixMatrices(\n specs: SpecParseResult,\n crossRefPatterns: readonly string[],\n): Promise<FixResult> {\n const reqFileMaps = buildReqFileMaps(specs.specFiles);\n const fileResults: FileFixResult[] = [];\n\n for (const specFile of specs.specFiles) {\n const fileName = basename(specFile.filePath);\n\n if (fileName.startsWith('DESIGN-')) {\n const changed = await fixDesignMatrix(\n specFile.filePath,\n reqFileMaps,\n crossRefPatterns,\n specFile.content,\n );\n fileResults.push({ filePath: specFile.filePath, changed });\n } else if (fileName.startsWith('TASK-')) {\n const changed = await fixTaskMatrix(\n specFile.filePath,\n reqFileMaps,\n specs,\n crossRefPatterns,\n specFile.content,\n );\n fileResults.push({ filePath: specFile.filePath, changed });\n }\n }\n\n return {\n filesFixed: fileResults.filter((r) => r.changed).length,\n fileResults,\n };\n}\n\n// --- ID → REQ filename maps ---\n\ninterface ReqFileMaps {\n /** Maps each requirement ID and AC ID to the REQ file that defines it. */\n readonly idToReqFile: Map<string, string>;\n /** Maps code prefix to sorted list of REQ filenames (fallback for property IDs). */\n readonly codeToReqFiles: Map<string, string[]>;\n}\n\n/**\n * Build maps from requirement/AC IDs and code prefixes to REQ filenames.\n * The per-ID map correctly handles multiple REQ files sharing the same code\n * prefix (e.g. REQ-ARC-flows.md and REQ-ARC-security.md both using ARC-* IDs).\n */\nfunction buildReqFileMaps(specFiles: readonly SpecFile[]): ReqFileMaps {\n const idToReqFile = new Map<string, string>();\n const codeToReqFilesSet = new Map<string, Set<string>>();\n\n for (const sf of specFiles) {\n const fileName = basename(sf.filePath);\n if (!/\\bREQ-/.test(fileName)) continue;\n\n // Map each requirement ID and AC ID to this REQ file\n for (const reqId of sf.requirementIds) {\n idToReqFile.set(reqId, fileName);\n }\n for (const acId of sf.acIds) {\n idToReqFile.set(acId, fileName);\n }\n\n // Build code → REQ files multimap for property ID fallback\n if (sf.code) {\n const existing = codeToReqFilesSet.get(sf.code) ?? new Set<string>();\n existing.add(fileName);\n codeToReqFilesSet.set(sf.code, existing);\n }\n }\n\n // Convert sets to sorted arrays for deterministic output\n const codeToReqFiles = new Map<string, string[]>();\n for (const [code, files] of codeToReqFilesSet) {\n codeToReqFiles.set(code, [...files].sort());\n }\n\n return { idToReqFile, codeToReqFiles };\n}\n\n/**\n * Resolve an ID to its REQ file.\n * - Requirement IDs and AC IDs: direct lookup via idToReqFile\n * - AC IDs not found directly: strip _AC-N suffix and look up parent requirement\n * - Property IDs (CODE_P-N): code prefix fallback via codeToReqFiles\n * (when one REQ file for the code, it's unambiguous; with multiple, uses first sorted)\n */\nfunction resolveReqFile(id: string, maps: ReqFileMaps): string | undefined {\n // Direct lookup (works for both requirement IDs and AC IDs)\n const direct = maps.idToReqFile.get(id);\n if (direct) return direct;\n\n // For AC IDs, try parent requirement: strip _AC-N suffix\n const acMatch = /^(.+)_AC-\\d+$/.exec(id);\n if (acMatch?.[1]) {\n return maps.idToReqFile.get(acMatch[1]);\n }\n\n // For property IDs (CODE_P-N), fall back to code prefix\n const propMatch = /^([A-Z][A-Z0-9]*)_P-\\d+$/.exec(id);\n if (propMatch?.[1]) {\n const files = maps.codeToReqFiles.get(propMatch[1]);\n return files?.[0];\n }\n\n return undefined;\n}\n\n// --- DESIGN matrix ---\n\ninterface ComponentInfo {\n readonly name: string;\n readonly implements: string[];\n}\n\ninterface PropertyInfo {\n readonly id: string;\n readonly validates: string[];\n}\n\nasync function fixDesignMatrix(\n filePath: string,\n reqFileMaps: ReqFileMaps,\n crossRefPatterns: readonly string[],\n cachedContent?: string,\n): Promise<boolean> {\n let content: string;\n if (cachedContent != null) {\n content = cachedContent;\n } else {\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return false;\n }\n }\n\n const { components, properties } = parseDesignFileData(content, crossRefPatterns);\n\n // AC → component names\n const acToComponents = new Map<string, string[]>();\n for (const comp of components) {\n for (const acId of comp.implements) {\n const existing = acToComponents.get(acId) ?? [];\n existing.push(comp.name);\n acToComponents.set(acId, existing);\n }\n }\n\n // AC → property IDs (from VALIDATES)\n const acToProperties = new Map<string, string[]>();\n for (const prop of properties) {\n for (const acId of prop.validates) {\n const existing = acToProperties.get(acId) ?? [];\n existing.push(prop.id);\n acToProperties.set(acId, existing);\n }\n }\n\n // Group ACs by REQ file\n const allAcIds = [...acToComponents.keys()];\n const grouped = groupByReqFile(allAcIds, reqFileMaps);\n\n const newSection = generateDesignSection(grouped, acToComponents, acToProperties);\n const newContent = replaceTraceabilitySection(content, newSection);\n if (newContent === content) return false;\n\n await writeFile(filePath, newContent, 'utf-8');\n return true;\n}\n\nfunction parseDesignFileData(\n content: string,\n crossRefPatterns: readonly string[],\n): { components: ComponentInfo[]; properties: PropertyInfo[] } {\n const lines = content.split('\\n');\n const components: ComponentInfo[] = [];\n const properties: PropertyInfo[] = [];\n\n const componentRegex = /^###\\s+([A-Z][A-Z0-9]*-[A-Za-z][A-Za-z0-9]*(?:[A-Z][a-z0-9]*)*)\\s*$/;\n const reqIdRegex = /^###\\s+([A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?)\\s*:/;\n const propIdRegex = /^-\\s+([A-Z][A-Z0-9]*_P-\\d+)\\s/;\n\n let currentComponent: string | null = null;\n let lastPropertyId: string | null = null;\n\n for (const line of lines) {\n // Component heading\n const compMatch = componentRegex.exec(line);\n if (compMatch?.[1] && !reqIdRegex.test(line)) {\n currentComponent = compMatch[1];\n lastPropertyId = null;\n components.push({ name: currentComponent, implements: [] });\n continue;\n }\n\n // H1/H2 heading resets context\n if (/^#{1,2}\\s/.test(line) && !compMatch) {\n currentComponent = null;\n lastPropertyId = null;\n continue;\n }\n\n // Property ID\n const propMatch = propIdRegex.exec(line);\n if (propMatch?.[1]) {\n lastPropertyId = propMatch[1];\n properties.push({ id: lastPropertyId, validates: [] });\n continue;\n }\n\n // Cross-references\n for (const pattern of crossRefPatterns) {\n const patIdx = line.indexOf(pattern);\n if (patIdx !== -1) {\n const afterPattern = line.slice(patIdx + pattern.length);\n const ids = extractIdsFromText(afterPattern);\n if (ids.length > 0) {\n const isImplements = pattern.toLowerCase().includes('implements');\n if (isImplements && currentComponent) {\n const comp = components.find((c) => c.name === currentComponent);\n if (comp) comp.implements.push(...ids);\n } else if (!isImplements && lastPropertyId) {\n const prop = properties.find((p) => p.id === lastPropertyId);\n if (prop) prop.validates.push(...ids);\n }\n }\n }\n }\n }\n\n return { components, properties };\n}\n\nfunction generateDesignSection(\n grouped: Map<string, string[]>,\n acToComponents: Map<string, string[]>,\n acToProperties: Map<string, string[]>,\n): string {\n const lines: string[] = [];\n const reqFiles = [...grouped.keys()].sort();\n\n for (const reqFile of reqFiles) {\n lines.push(`### ${reqFile}`);\n lines.push('');\n\n const acIds = grouped.get(reqFile) ?? [];\n acIds.sort(compareIds);\n\n for (const acId of acIds) {\n const components = acToComponents.get(acId) ?? [];\n const props = acToProperties.get(acId) ?? [];\n\n for (const comp of components) {\n const propStr = props.length > 0 ? ` (${props.join(', ')})` : '';\n lines.push(`- ${acId} → ${comp}${propStr}`);\n }\n }\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n\n// --- TASK matrix ---\n\ninterface TaskInfo {\n readonly id: string;\n readonly implements: string[];\n readonly tests: string[];\n}\n\nasync function fixTaskMatrix(\n filePath: string,\n reqFileMaps: ReqFileMaps,\n specs: SpecParseResult,\n crossRefPatterns: readonly string[],\n cachedContent?: string,\n): Promise<boolean> {\n let content: string;\n if (cachedContent != null) {\n content = cachedContent;\n } else {\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return false;\n }\n }\n\n const { tasks, sourceDesigns } = parseTaskFileData(content, crossRefPatterns);\n\n // AC → implementing task(s)\n const acToTasks = new Map<string, string[]>();\n for (const task of tasks) {\n for (const acId of task.implements) {\n const existing = acToTasks.get(acId) ?? [];\n existing.push(task.id);\n acToTasks.set(acId, existing);\n }\n }\n\n // AC/property → testing task(s)\n const idToTestTasks = new Map<string, string[]>();\n for (const task of tasks) {\n for (const testId of task.tests) {\n const existing = idToTestTasks.get(testId) ?? [];\n existing.push(task.id);\n idToTestTasks.set(testId, existing);\n }\n }\n\n // Collect property IDs from source DESIGN files (to distinguish from ACs in output)\n const sourcePropertyIds = new Set<string>();\n for (const designName of sourceDesigns) {\n const designCode = extractCodeFromFileName(designName);\n for (const sf of specs.specFiles) {\n if (sf.code === designCode && /\\bDESIGN-/.test(basename(sf.filePath))) {\n for (const propId of sf.propertyIds) sourcePropertyIds.add(propId);\n }\n }\n }\n\n // Group ACs and properties by REQ file\n const allIdsForMatrix = [...new Set([...acToTasks.keys(), ...idToTestTasks.keys()])];\n const grouped = groupByReqFile(allIdsForMatrix, reqFileMaps);\n\n const newSection = generateTaskSection(grouped, acToTasks, idToTestTasks, sourcePropertyIds);\n const newContent = replaceTraceabilitySection(content, newSection);\n if (newContent === content) return false;\n\n await writeFile(filePath, newContent, 'utf-8');\n return true;\n}\n\ninterface TaskFileParseResult {\n tasks: TaskInfo[];\n sourceReqs: string[];\n sourceDesigns: string[];\n}\n\nfunction parseTaskFileData(\n content: string,\n crossRefPatterns: readonly string[],\n): TaskFileParseResult {\n const lines = content.split('\\n');\n const tasks: TaskInfo[] = [];\n const sourceReqs: string[] = [];\n const sourceDesigns: string[] = [];\n\n // Parse SOURCE line\n const sourceRegex = /^SOURCE:\\s*(.+)/;\n const taskIdRegex = /^-\\s+\\[[ x]\\]\\s+(T-[A-Z][A-Z0-9]*-\\d+)/;\n\n let currentTaskId: string | null = null;\n\n for (const line of lines) {\n // SOURCE line\n const sourceMatch = sourceRegex.exec(line);\n if (sourceMatch?.[1]) {\n const parts = sourceMatch[1].split(',').map((s) => s.trim());\n for (const part of parts) {\n if (part.startsWith('REQ-')) sourceReqs.push(part);\n else if (part.startsWith('DESIGN-')) sourceDesigns.push(part);\n }\n continue;\n }\n\n // Task checkbox item\n const taskMatch = taskIdRegex.exec(line);\n if (taskMatch?.[1]) {\n currentTaskId = taskMatch[1];\n tasks.push({ id: currentTaskId, implements: [], tests: [] });\n continue;\n }\n\n // H2 heading resets task context (new phase)\n if (/^##\\s/.test(line)) {\n currentTaskId = null;\n continue;\n }\n\n // --- or horizontal rule also resets\n if (/^---/.test(line)) {\n currentTaskId = null;\n continue;\n }\n\n // IMPLEMENTS / TESTS lines (indented under a task)\n if (currentTaskId) {\n const task = tasks.find((t) => t.id === currentTaskId);\n if (task) {\n for (const pattern of crossRefPatterns) {\n const patIdx = line.indexOf(pattern);\n if (patIdx !== -1) {\n const afterPattern = line.slice(patIdx + pattern.length);\n const ids = extractIdsFromText(afterPattern);\n if (ids.length > 0) {\n const isImplements = pattern.toLowerCase().includes('implements');\n if (isImplements) {\n task.implements.push(...ids);\n }\n }\n }\n }\n // TESTS: is not in crossRefPatterns, parse it directly\n const testsIdx = line.indexOf('TESTS:');\n if (testsIdx !== -1) {\n const afterTests = line.slice(testsIdx + 'TESTS:'.length);\n const ids = extractIdsFromText(afterTests);\n if (ids.length > 0) {\n task.tests.push(...ids);\n }\n }\n }\n }\n }\n\n return { tasks, sourceReqs, sourceDesigns };\n}\n\nfunction generateTaskSection(\n grouped: Map<string, string[]>,\n acToTasks: Map<string, string[]>,\n idToTestTasks: Map<string, string[]>,\n propertyIds: Set<string>,\n): string {\n const lines: string[] = [];\n const reqFiles = [...grouped.keys()].sort();\n\n for (const reqFile of reqFiles) {\n lines.push(`### ${reqFile}`);\n lines.push('');\n\n const ids = grouped.get(reqFile) ?? [];\n // Separate ACs from properties\n const acIds = ids.filter((id) => !propertyIds.has(id));\n const propIds = ids.filter((id) => propertyIds.has(id));\n\n acIds.sort(compareIds);\n propIds.sort(compareIds);\n\n // AC entries: - {AC-ID} → {Task} ({TestTask})\n for (const acId of acIds) {\n const tasks = acToTasks.get(acId) ?? [];\n const testTasks = idToTestTasks.get(acId) ?? [];\n const taskStr = tasks.length > 0 ? tasks.join(', ') : '(none)';\n const testStr = testTasks.length > 0 ? ` (${testTasks.join(', ')})` : '';\n lines.push(`- ${acId} → ${taskStr}${testStr}`);\n }\n\n // Property entries: - {Prop-ID} → {TestTask}\n for (const propId of propIds) {\n const testTasks = idToTestTasks.get(propId) ?? [];\n const testStr = testTasks.length > 0 ? testTasks.join(', ') : '(none)';\n lines.push(`- ${propId} → ${testStr}`);\n }\n\n lines.push('');\n }\n\n return lines.join('\\n').trimEnd();\n}\n\n// --- Shared utilities ---\n\nfunction groupByReqFile(ids: string[], maps: ReqFileMaps): Map<string, string[]> {\n const groups = new Map<string, string[]>();\n for (const id of ids) {\n const reqFile = resolveReqFile(id, maps);\n if (!reqFile) continue; // Skip IDs we can't resolve to a REQ file\n const existing = groups.get(reqFile) ?? [];\n existing.push(id);\n groups.set(reqFile, existing);\n }\n return groups;\n}\n\nfunction replaceTraceabilitySection(content: string, newSection: string): string {\n const lines = content.split('\\n');\n const sectionStart = lines.findIndex((l) => /^##\\s+Requirements Traceability\\s*$/.test(l));\n\n if (sectionStart === -1) return content;\n\n // Find the next ## heading after the section start\n let sectionEnd = lines.length;\n for (let i = sectionStart + 1; i < lines.length; i++) {\n const line = lines[i];\n if (line !== undefined && /^##\\s/.test(line)) {\n sectionEnd = i;\n break;\n }\n }\n\n const before = lines.slice(0, sectionStart + 1);\n const after = lines.slice(sectionEnd);\n\n const result = [...before, '', newSection.trimEnd(), '', ...after];\n return result.join('\\n');\n}\n\nfunction extractIdsFromText(text: string): string[] {\n const idRegex = /[A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|[A-Z][A-Z0-9]*_P-\\d+/g;\n const ids: string[] = [];\n let match = idRegex.exec(text);\n while (match !== null) {\n ids.push(match[0]);\n match = idRegex.exec(text);\n }\n return ids;\n}\n\nfunction extractCodeFromFileName(fileName: string): string {\n // Extract CODE from REQ-CODE-feature.md or DESIGN-CODE-feature.md\n const match = /^(?:REQ|DESIGN|FEAT|EXAMPLE|API|TASK)-([A-Z][A-Z0-9]*)-/.exec(fileName);\n return match?.[1] ?? '';\n}\n\nfunction compareIds(a: string, b: string): number {\n return a.localeCompare(b, undefined, { numeric: true });\n}\n","// @awa-component: CLI-Reporter\n// @awa-impl: CLI-24_AC-1\n// @awa-impl: CLI-24_AC-2\n// @awa-impl: CLI-24_AC-3\n\nimport chalk from 'chalk';\n\nimport type { Finding } from './types.js';\n\n// @awa-impl: CLI-24_AC-1\nexport function report(findings: readonly Finding[], format: 'text' | 'json'): void {\n if (format === 'json') {\n reportJson(findings);\n } else {\n reportText(findings);\n }\n}\n\nfunction reportJson(findings: readonly Finding[]): void {\n const errors = findings.filter((f) => f.severity === 'error');\n const warnings = findings.filter((f) => f.severity === 'warning');\n\n const output = {\n valid: errors.length === 0,\n errors: errors.length,\n warnings: warnings.length,\n findings: findings.map((f) => ({\n severity: f.severity,\n code: f.code,\n message: f.message,\n ...(f.filePath ? { filePath: f.filePath } : {}),\n ...(f.line ? { line: f.line } : {}),\n ...(f.id ? { id: f.id } : {}),\n ...(f.ruleSource ? { ruleSource: f.ruleSource } : {}),\n ...(f.rule ? { rule: f.rule } : {}),\n })),\n };\n\n console.log(JSON.stringify(output, null, 2));\n}\n\nfunction reportText(findings: readonly Finding[]): void {\n const errors = findings.filter((f) => f.severity === 'error');\n const warnings = findings.filter((f) => f.severity === 'warning');\n\n if (errors.length > 0) {\n console.log(chalk.red(`\\n${errors.length} error(s):\\n`));\n for (const f of errors) {\n const location = formatLocation(f.filePath, f.line);\n console.log(chalk.red(' ✖'), f.message, location ? chalk.dim(location) : '');\n printRuleContext(f);\n }\n }\n\n if (warnings.length > 0) {\n console.log(chalk.yellow(`\\n${warnings.length} warning(s):\\n`));\n for (const f of warnings) {\n const location = formatLocation(f.filePath, f.line);\n console.log(chalk.yellow(' ⚠'), f.message, location ? chalk.dim(location) : '');\n printRuleContext(f);\n }\n }\n\n if (errors.length === 0 && warnings.length === 0) {\n console.log(chalk.green('\\n✔ Validation passed — no issues found'));\n } else {\n console.log('');\n const parts: string[] = [];\n if (errors.length > 0) parts.push(chalk.red(`${errors.length} error(s)`));\n if (warnings.length > 0) parts.push(chalk.yellow(`${warnings.length} warning(s)`));\n console.log(`Summary: ${parts.join(', ')}`);\n }\n}\n\nfunction formatLocation(filePath?: string, line?: number): string {\n if (!filePath) return '';\n return line ? `(${filePath}:${line})` : `(${filePath})`;\n}\n\nfunction printRuleContext(f: Finding): void {\n if (!f.ruleSource && !f.rule) return;\n const parts: string[] = [];\n if (f.ruleSource) parts.push(f.ruleSource);\n if (f.rule) parts.push(f.rule);\n console.log(chalk.dim(` rule: ${parts.join(' — ')}`));\n}\n","// @awa-component: CLI-RuleLoader\n// @awa-impl: CLI-31_AC-1\n\nimport { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nimport { parse as parseYaml } from 'yaml';\n\nimport { collectFiles, matchSimpleGlob } from './glob.js';\nimport type {\n CodeBlockContainsRule,\n ContainsRule,\n HeadingOrTextContainsRule,\n ListContainsRule,\n LoadedRuleSet,\n PatternContainsRule,\n RuleFile,\n SectionRule,\n TableContainsRule,\n WhenCondition,\n} from './rule-types.js';\n\n/**\n * Discover and load all *.schema.yaml files from the given schema directory.\n * Parses YAML, validates rule structure, and returns typed rule sets.\n */\nexport async function loadRules(schemaDir: string): Promise<LoadedRuleSet[]> {\n const pattern = join(schemaDir, '*.schema.yaml');\n const files = await collectFiles([pattern], []);\n const results: LoadedRuleSet[] = [];\n\n for (const filePath of files) {\n const ruleSet = await loadRuleFile(filePath);\n if (ruleSet) {\n results.push(ruleSet);\n }\n }\n\n return results;\n}\n\n/**\n * Match spec file paths against a loaded rule set's target-files glob.\n */\nexport function matchesTargetGlob(filePath: string, targetGlob: string): boolean {\n return matchSimpleGlob(filePath, targetGlob);\n}\n\nasync function loadRuleFile(filePath: string): Promise<LoadedRuleSet | null> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return null;\n }\n\n const parsed = parseYaml(content) as unknown;\n if (!parsed || typeof parsed !== 'object') {\n throw new RuleValidationError(`Rule file is not a valid YAML object: ${filePath}`);\n }\n\n const raw = parsed as Record<string, unknown>;\n const ruleFile = validateRuleFile(raw, filePath);\n\n return {\n ruleFile,\n sourcePath: filePath,\n targetGlob: ruleFile['target-files'],\n };\n}\n\nfunction validateRuleFile(raw: Record<string, unknown>, filePath: string): RuleFile {\n // target-files is required\n if (typeof raw['target-files'] !== 'string' || raw['target-files'].length === 0) {\n throw new RuleValidationError(`Missing or empty 'target-files' in ${filePath}`);\n }\n\n // sections is optional (e.g., API rules target non-markdown files)\n let sections: SectionRule[] | undefined;\n if (raw.sections !== undefined) {\n if (!Array.isArray(raw.sections) || raw.sections.length === 0) {\n throw new RuleValidationError(\n `'sections' must be a non-empty array if present in ${filePath}`,\n );\n }\n sections = raw.sections.map((s: unknown, i: number) =>\n validateSectionRule(s, `sections[${i}]`, filePath),\n );\n }\n\n // sections-prohibited is optional\n let sectionsProhibited: string[] | undefined;\n if (raw['sections-prohibited'] !== undefined) {\n if (\n !Array.isArray(raw['sections-prohibited']) ||\n !raw['sections-prohibited'].every((v: unknown) => typeof v === 'string')\n ) {\n throw new RuleValidationError(`'sections-prohibited' must be a string array in ${filePath}`);\n }\n sectionsProhibited = raw['sections-prohibited'] as string[];\n }\n\n return {\n 'target-files': raw['target-files'] as string,\n ...(typeof raw.description === 'string' ? { description: raw.description } : {}),\n ...(typeof raw['line-limit'] === 'number' && raw['line-limit'] > 0\n ? { 'line-limit': raw['line-limit'] }\n : {}),\n sections: sections ?? [],\n ...(sectionsProhibited ? { 'sections-prohibited': sectionsProhibited } : {}),\n ...(typeof raw.example === 'string' ? { example: raw.example } : {}),\n };\n}\n\nfunction validateSectionRule(raw: unknown, path: string, filePath: string): SectionRule {\n if (!raw || typeof raw !== 'object') {\n throw new RuleValidationError(`${path} must be an object in ${filePath}`);\n }\n\n const section = raw as Record<string, unknown>;\n\n if (typeof section.heading !== 'string' || section.heading.length === 0) {\n throw new RuleValidationError(`${path}.heading must be a non-empty string in ${filePath}`);\n }\n\n if (typeof section.level !== 'number' || section.level < 1 || section.level > 6) {\n throw new RuleValidationError(`${path}.level must be 1-6 in ${filePath}`);\n }\n\n // Validate heading as regex if it looks like a pattern\n validatePattern(section.heading as string, `${path}.heading`, filePath);\n\n // Validate optional contains rules\n let contains: ContainsRule[] | undefined;\n if (section.contains !== undefined) {\n if (!Array.isArray(section.contains)) {\n throw new RuleValidationError(`${path}.contains must be an array in ${filePath}`);\n }\n contains = section.contains.map((c: unknown, i: number) =>\n validateContainsRule(c, `${path}.contains[${i}]`, filePath),\n );\n }\n\n // Validate optional children rules\n let children: SectionRule[] | undefined;\n if (section.children !== undefined) {\n if (!Array.isArray(section.children)) {\n throw new RuleValidationError(`${path}.children must be an array in ${filePath}`);\n }\n children = section.children.map((c: unknown, i: number) =>\n validateSectionRule(c, `${path}.children[${i}]`, filePath),\n );\n }\n\n return {\n heading: section.heading as string,\n level: section.level as number,\n ...(typeof section.required === 'boolean' ? { required: section.required } : {}),\n ...(typeof section.repeatable === 'boolean' ? { repeatable: section.repeatable } : {}),\n ...(typeof section.description === 'string' ? { description: section.description } : {}),\n ...(contains ? { contains } : {}),\n ...(children ? { children } : {}),\n };\n}\n\nfunction validateContainsRule(raw: unknown, path: string, filePath: string): ContainsRule {\n if (!raw || typeof raw !== 'object') {\n throw new RuleValidationError(`${path} must be an object in ${filePath}`);\n }\n\n const rule = raw as Record<string, unknown>;\n\n // Parse optional 'when' condition (applicable to all rule types)\n const when =\n rule.when !== undefined\n ? validateWhenCondition(rule.when, `${path}.when`, filePath)\n : undefined;\n\n // Pattern rule\n if (typeof rule.pattern === 'string') {\n validatePattern(rule.pattern, `${path}.pattern`, filePath);\n return {\n pattern: rule.pattern,\n ...(typeof rule.label === 'string' ? { label: rule.label } : {}),\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(typeof rule.required === 'boolean' ? { required: rule.required } : {}),\n ...(typeof rule.prohibited === 'boolean' ? { prohibited: rule.prohibited } : {}),\n ...(when ? { when } : {}),\n } satisfies PatternContainsRule;\n }\n\n // List rule\n if (rule.list && typeof rule.list === 'object') {\n const list = rule.list as Record<string, unknown>;\n if (typeof list.pattern !== 'string') {\n throw new RuleValidationError(`${path}.list.pattern must be a string in ${filePath}`);\n }\n validatePattern(list.pattern, `${path}.list.pattern`, filePath);\n return {\n list: {\n pattern: list.pattern,\n ...(typeof list.min === 'number' ? { min: list.min } : {}),\n ...(typeof list.label === 'string' ? { label: list.label } : {}),\n },\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies ListContainsRule;\n }\n\n // Table rule\n if (rule.table && typeof rule.table === 'object') {\n const table = rule.table as Record<string, unknown>;\n if (\n !Array.isArray(table.columns) ||\n !table.columns.every((c: unknown) => typeof c === 'string')\n ) {\n throw new RuleValidationError(`${path}.table.columns must be a string array in ${filePath}`);\n }\n return {\n table: {\n ...(typeof table.heading === 'string' ? { heading: table.heading } : {}),\n columns: table.columns as string[],\n ...(typeof table['min-rows'] === 'number' ? { 'min-rows': table['min-rows'] } : {}),\n },\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies TableContainsRule;\n }\n\n // Code block rule\n if (rule['code-block'] === true) {\n return {\n 'code-block': true,\n ...(typeof rule.label === 'string' ? { label: rule.label } : {}),\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies CodeBlockContainsRule;\n }\n\n // Heading-or-text rule\n if (typeof rule['heading-or-text'] === 'string') {\n return {\n 'heading-or-text': rule['heading-or-text'],\n ...(typeof rule.required === 'boolean' ? { required: rule.required } : {}),\n ...(typeof rule.description === 'string' ? { description: rule.description } : {}),\n ...(when ? { when } : {}),\n } satisfies HeadingOrTextContainsRule;\n }\n\n throw new RuleValidationError(`${path} has no recognized rule type in ${filePath}`);\n}\n\nfunction validateWhenCondition(raw: unknown, path: string, filePath: string): WhenCondition {\n if (!raw || typeof raw !== 'object') {\n throw new RuleValidationError(`${path} must be an object in ${filePath}`);\n }\n\n const condition = raw as Record<string, unknown>;\n const result: Record<string, string> = {};\n\n if (typeof condition['heading-matches'] === 'string') {\n validatePattern(condition['heading-matches'], `${path}.heading-matches`, filePath);\n result['heading-matches'] = condition['heading-matches'];\n }\n\n if (typeof condition['heading-not-matches'] === 'string') {\n validatePattern(condition['heading-not-matches'], `${path}.heading-not-matches`, filePath);\n result['heading-not-matches'] = condition['heading-not-matches'];\n }\n\n if (!result['heading-matches'] && !result['heading-not-matches']) {\n throw new RuleValidationError(\n `${path} must have 'heading-matches' or 'heading-not-matches' in ${filePath}`,\n );\n }\n\n return result as unknown as WhenCondition;\n}\n\nfunction validatePattern(pattern: string, path: string, filePath: string): void {\n // Only validate if it looks like a regex (contains regex special chars)\n if (/[.+*?^${}()|[\\]\\\\]/.test(pattern)) {\n try {\n new RegExp(pattern);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new RuleValidationError(`Invalid regex in ${path}: ${msg} (${filePath})`);\n }\n }\n}\n\nexport class RuleValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'RuleValidationError';\n }\n}\n","// @awa-component: CLI-SchemaChecker\n// @awa-impl: CLI-17_AC-1\n\nimport { readFile } from 'node:fs/promises';\n\nimport type { Code, Heading, List, PhrasingContent, Root, Table, TableRow } from 'mdast';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport { unified } from 'unified';\n\nimport { matchesTargetGlob } from './rule-loader.js';\nimport type {\n CodeBlockContainsRule,\n ContainsRule,\n HeadingOrTextContainsRule,\n ListContainsRule,\n LoadedRuleSet,\n PatternContainsRule,\n SectionRule,\n TableContainsRule,\n WhenCondition,\n} from './rule-types.js';\nimport type { CheckResult, Finding, SpecFile } from './types.js';\n\n// --- Rule formatting helpers ---\n\nfunction formatSectionRule(rule: SectionRule): string {\n const parts = [`section: heading=\"${rule.heading}\" level=${rule.level}`];\n if (rule.required) parts.push('required');\n if (rule.repeatable) parts.push('repeatable');\n return parts.join(' ');\n}\n\nfunction formatContainsRule(rule: ContainsRule): string {\n if ('pattern' in rule && typeof rule.pattern === 'string') {\n const r = rule as PatternContainsRule;\n if (r.prohibited) return `contains: prohibited pattern=\"${r.pattern}\"`;\n return `contains: pattern=\"${r.pattern}\"${r.required === false ? '' : ' required'}`;\n }\n if ('list' in rule) {\n const r = rule as ListContainsRule;\n return `contains: list pattern=\"${r.list.pattern}\"${r.list.min !== undefined ? ` min=${r.list.min}` : ''}`;\n }\n if ('table' in rule) {\n const r = rule as TableContainsRule;\n return `contains: table columns=[${r.table.columns.join(', ')}]${r.table['min-rows'] !== undefined ? ` min-rows=${r.table['min-rows']}` : ''}`;\n }\n if ('code-block' in rule) {\n return 'contains: code-block';\n }\n if ('heading-or-text' in rule) {\n const r = rule as HeadingOrTextContainsRule;\n return `contains: heading-or-text=\"${r['heading-or-text']}\"`;\n }\n return 'contains: (unknown rule)';\n}\n\nfunction formatLineLimitRule(limit: number): string {\n return `line-limit: ${limit}`;\n}\n\nfunction formatProhibitedRule(pattern: string): string {\n return `sections-prohibited: \"${pattern}\"`;\n}\n\n/** A section with heading info and all AST nodes belonging to it. */\ninterface SectionNode {\n readonly heading: Heading;\n readonly headingText: string;\n readonly level: number;\n readonly children: SectionNode[];\n readonly contentNodes: Root['children'];\n}\n\n/**\n * Check all spec files against loaded rule sets.\n * Reads file content, parses to mdast, walks AST checking rules.\n */\nexport async function checkSchemasAsync(\n specFiles: readonly SpecFile[],\n ruleSets: readonly LoadedRuleSet[],\n): Promise<CheckResult> {\n const findings: Finding[] = [];\n const parser = unified().use(remarkParse).use(remarkGfm);\n\n for (const spec of specFiles) {\n const matchingRules = ruleSets.filter((rs) => matchesTargetGlob(spec.filePath, rs.targetGlob));\n if (matchingRules.length === 0) continue;\n\n let content: string;\n if (spec.content != null) {\n content = spec.content;\n } else {\n try {\n content = await readFile(spec.filePath, 'utf-8');\n } catch {\n continue;\n }\n }\n\n const tree = parser.parse(content);\n const sectionTree = buildSectionTree(tree);\n const allSections = flattenSections(sectionTree);\n\n for (const ruleSet of matchingRules) {\n const ruleSource = ruleSet.sourcePath;\n\n // Check line limit if defined\n if (ruleSet.ruleFile['line-limit'] !== undefined) {\n const lineCount = content.split('\\n').length;\n if (lineCount > ruleSet.ruleFile['line-limit']) {\n findings.push({\n severity: 'warning',\n code: 'schema-line-limit',\n message: `File has ${lineCount} lines, exceeds limit of ${ruleSet.ruleFile['line-limit']}`,\n filePath: spec.filePath,\n ruleSource,\n rule: formatLineLimitRule(ruleSet.ruleFile['line-limit']),\n });\n }\n }\n\n findings.push(\n ...checkRulesAgainstSections(\n allSections,\n ruleSet.ruleFile.sections,\n spec.filePath,\n ruleSource,\n ),\n );\n\n if (ruleSet.ruleFile['sections-prohibited']) {\n findings.push(\n ...checkProhibited(\n content,\n ruleSet.ruleFile['sections-prohibited'],\n spec.filePath,\n ruleSource,\n ),\n );\n }\n }\n }\n\n return { findings };\n}\n\n// --- Section tree building ---\n\nfunction buildSectionTree(tree: Root): SectionNode[] {\n return buildSectionsFromNodes(tree.children, 0, 0).sections;\n}\n\nfunction buildSectionsFromNodes(\n nodes: Root['children'],\n start: number,\n parentLevel: number,\n): { sections: SectionNode[]; nextIndex: number } {\n const sections: SectionNode[] = [];\n let i = start;\n\n while (i < nodes.length) {\n const node = nodes[i];\n if (!node) break;\n if (node.type === 'heading') {\n const h = node as Heading;\n if (parentLevel > 0 && h.depth <= parentLevel) break;\n\n const headingText = extractText(h.children);\n const contentNodes: Root['children'] = [];\n i++;\n\n // Collect content until next heading of same-or-higher level\n while (i < nodes.length) {\n const next = nodes[i];\n if (!next || next.type === 'heading') break;\n contentNodes.push(next);\n i++;\n }\n\n // Collect child headings (deeper level)\n const childResult = buildSectionsFromNodes(nodes, i, h.depth);\n i = childResult.nextIndex;\n\n sections.push({\n heading: h,\n headingText,\n level: h.depth,\n children: childResult.sections,\n contentNodes,\n });\n } else {\n i++;\n }\n }\n\n return { sections, nextIndex: i };\n}\n\nfunction flattenSections(sections: SectionNode[]): SectionNode[] {\n const result: SectionNode[] = [];\n for (const s of sections) {\n result.push(s);\n result.push(...flattenSections(s.children));\n }\n return result;\n}\n\nfunction extractText(children: PhrasingContent[]): string {\n return children\n .map((c) => {\n if ('value' in c) return c.value;\n if ('children' in c) return extractText(c.children as PhrasingContent[]);\n return '';\n })\n .join('');\n}\n\n// --- Rule checking ---\n\n/**\n * Top-level rules match against the flattened view of all sections.\n * `children` sub-rules match only within the matched section's children.\n */\nfunction checkRulesAgainstSections(\n allSections: SectionNode[],\n rules: readonly SectionRule[],\n filePath: string,\n ruleSource: string,\n): Finding[] {\n const findings: Finding[] = [];\n\n for (const rule of rules) {\n const matches = findMatchingSections(allSections, rule);\n\n if (matches.length === 0 && rule.required) {\n findings.push({\n severity: 'error',\n code: 'schema-missing-section',\n message: `Missing required section: '${rule.heading}' (level ${rule.level})`,\n filePath,\n ruleSource,\n rule: formatSectionRule(rule),\n });\n continue;\n }\n\n for (const match of matches) {\n if (match.level !== rule.level) {\n findings.push({\n severity: 'warning',\n code: 'schema-wrong-level',\n message: `Section '${match.headingText}' is level ${match.level}, expected ${rule.level}`,\n filePath,\n line: match.heading.position?.start.line,\n ruleSource,\n rule: formatSectionRule(rule),\n });\n }\n\n if (rule.contains) {\n for (const cr of rule.contains) {\n findings.push(...checkContainsRule(match, cr, filePath, ruleSource));\n }\n }\n\n if (rule.children) {\n const childFlat = flattenSections(match.children);\n findings.push(...checkRulesAgainstSections(childFlat, rule.children, filePath, ruleSource));\n }\n }\n }\n\n return findings;\n}\n\nfunction findMatchingSections(allSections: SectionNode[], rule: SectionRule): SectionNode[] {\n const regex = createHeadingRegex(rule.heading);\n const matches = allSections.filter((s) => s.level === rule.level && regex.test(s.headingText));\n\n if (!rule.repeatable && matches.length > 1) {\n return [matches[0] as SectionNode];\n }\n return matches;\n}\n\nfunction createHeadingRegex(pattern: string): RegExp {\n if (/[.+*?^${}()|[\\]\\\\]/.test(pattern)) {\n try {\n return new RegExp(`^${pattern}$`);\n } catch {\n return new RegExp(`^${escapeRegex(pattern)}$`);\n }\n }\n return new RegExp(`^${escapeRegex(pattern)}$`, 'i');\n}\n\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n// --- Contains rule dispatching ---\n\nfunction checkContainsRule(\n section: SectionNode,\n rule: ContainsRule,\n filePath: string,\n ruleSource: string,\n): Finding[] {\n // Evaluate 'when' condition gate — skip rule if condition not met\n const when = 'when' in rule ? (rule as { when?: WhenCondition }).when : undefined;\n if (when && !evaluateWhenCondition(when, section.headingText)) {\n return [];\n }\n\n const formattedRule = formatContainsRule(rule);\n\n if ('pattern' in rule && typeof rule.pattern === 'string') {\n return checkPatternContains(\n section,\n rule as PatternContainsRule,\n filePath,\n ruleSource,\n formattedRule,\n );\n }\n if ('list' in rule) {\n return checkListContains(\n section,\n rule as ListContainsRule,\n filePath,\n ruleSource,\n formattedRule,\n );\n }\n if ('table' in rule) {\n return checkTableContains(\n section,\n rule as TableContainsRule,\n filePath,\n ruleSource,\n formattedRule,\n );\n }\n if ('code-block' in rule) {\n return checkCodeBlockContains(\n section,\n rule as CodeBlockContainsRule,\n filePath,\n ruleSource,\n formattedRule,\n );\n }\n if ('heading-or-text' in rule) {\n return checkHeadingOrText(\n section,\n rule as HeadingOrTextContainsRule,\n filePath,\n ruleSource,\n formattedRule,\n );\n }\n return [];\n}\n\nfunction checkPatternContains(\n section: SectionNode,\n rule: PatternContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string,\n): Finding[] {\n const text = getFullSectionText(section);\n const found = new RegExp(rule.pattern, 'm').test(text);\n\n // Prohibited mode: pattern must NOT appear\n if (rule.prohibited) {\n if (found) {\n return [\n {\n severity: 'warning',\n code: 'schema-prohibited',\n message: `Section '${section.headingText}' contains prohibited content: ${rule.label ?? rule.pattern}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n }\n\n // Normal mode: pattern must appear\n if (found) return [];\n\n if (rule.required !== false) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required content: ${rule.label ?? rule.pattern}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n}\n\nfunction checkListContains(\n section: SectionNode,\n rule: ListContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string,\n): Finding[] {\n const items = collectAllListItems(section);\n const regex = new RegExp(rule.list.pattern);\n const count = items.filter((item) => regex.test(item)).length;\n\n if (rule.list.min !== undefined && count < rule.list.min) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' has ${count} matching ${rule.list.label ?? 'list items'}, expected at least ${rule.list.min}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n}\n\nfunction checkTableContains(\n section: SectionNode,\n rule: TableContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string,\n): Finding[] {\n const tables = collectAllTables(section);\n\n if (tables.length === 0) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required table${rule.table.heading ? ` (${rule.table.heading})` : ''}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n\n // Find the first table whose columns match the rule. If none match, report\n // the column mismatch for the first table. This avoids false positives when a\n // section contains multiple tables with different column sets.\n let matched: Table | undefined;\n let firstMismatch: { table: Table; headers: string[] } | undefined;\n\n for (const table of tables) {\n const headerRow = table.children[0] as TableRow | undefined;\n if (!headerRow) continue;\n\n const headers = headerRow.children.map((cell) =>\n extractText(cell.children as PhrasingContent[]).trim(),\n );\n\n if (rule.table.columns.every((col) => headers.includes(col))) {\n matched = table;\n break;\n }\n if (!firstMismatch) {\n firstMismatch = { table, headers };\n }\n }\n\n if (!matched) {\n const mm = firstMismatch;\n return [\n {\n severity: 'error',\n code: 'schema-table-columns',\n message: `No table in '${section.headingText}' has columns [${rule.table.columns.join(', ')}]${mm ? `, found [${mm.headers.join(', ')}]` : ''}`,\n filePath,\n line: mm?.table.position?.start.line ?? section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n\n const findings: Finding[] = [];\n const dataRows = matched.children.length - 1;\n if (rule.table['min-rows'] !== undefined && dataRows < rule.table['min-rows']) {\n findings.push({\n severity: 'error',\n code: 'schema-missing-content',\n message: `Table in '${section.headingText}' has ${dataRows} data rows, expected at least ${rule.table['min-rows']}`,\n filePath,\n line: matched.position?.start.line,\n ruleSource,\n rule: formattedRule,\n });\n }\n return findings;\n}\n\nfunction checkCodeBlockContains(\n section: SectionNode,\n rule: CodeBlockContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string,\n): Finding[] {\n if (collectAllCodeBlocks(section).length > 0) return [];\n\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required ${rule.label ?? 'code block'}`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n}\n\nfunction checkHeadingOrText(\n section: SectionNode,\n rule: HeadingOrTextContainsRule,\n filePath: string,\n ruleSource: string,\n formattedRule: string,\n): Finding[] {\n const needle = rule['heading-or-text'].toUpperCase();\n\n if (section.children.some((c) => c.headingText.toUpperCase().includes(needle))) return [];\n if (getFullSectionText(section).toUpperCase().includes(needle)) return [];\n\n if (rule.required !== false) {\n return [\n {\n severity: 'error',\n code: 'schema-missing-content',\n message: `Section '${section.headingText}' missing required heading or text: '${rule['heading-or-text']}'`,\n filePath,\n line: section.heading.position?.start.line,\n ruleSource,\n rule: formattedRule,\n },\n ];\n }\n return [];\n}\n\n// --- When condition evaluation ---\n\nfunction evaluateWhenCondition(when: WhenCondition, headingText: string): boolean {\n if (when['heading-matches']) {\n if (!new RegExp(when['heading-matches']).test(headingText)) return false;\n }\n if (when['heading-not-matches']) {\n if (new RegExp(when['heading-not-matches']).test(headingText)) return false;\n }\n return true;\n}\n\n// --- Prohibited patterns ---\n\nfunction checkProhibited(\n content: string,\n prohibited: readonly string[],\n filePath: string,\n ruleSource: string,\n): Finding[] {\n const findings: Finding[] = [];\n const lines = content.split('\\n');\n\n for (const pattern of prohibited) {\n const regex = new RegExp(escapeRegex(pattern));\n let inCodeBlock = false;\n\n for (const [i, line] of lines.entries()) {\n if (line.startsWith('```')) {\n inCodeBlock = !inCodeBlock;\n continue;\n }\n if (inCodeBlock) continue;\n\n if (regex.test(line)) {\n findings.push({\n severity: 'warning',\n code: 'schema-prohibited',\n message: `Prohibited formatting '${pattern}' found`,\n filePath,\n line: i + 1,\n ruleSource,\n rule: formatProhibitedRule(pattern),\n });\n break;\n }\n }\n }\n return findings;\n}\n\n// --- Content extraction helpers ---\n\nfunction getFullSectionText(section: SectionNode): string {\n let text = section.contentNodes.map(nodeToText).join('\\n');\n for (const child of section.children) {\n text += `\\n${child.headingText}\\n${getFullSectionText(child)}`;\n }\n return text;\n}\n\nfunction nodeToText(node: Root['children'][number]): string {\n if ('value' in node) return node.value as string;\n if ('children' in node) {\n return (node.children as Root['children'])\n .map((c) => nodeToText(c as Root['children'][number]))\n .join('');\n }\n return '';\n}\n\nfunction extractListItems(nodes: Root['children']): string[] {\n const items: string[] = [];\n for (const node of nodes) {\n if (node.type === 'list') {\n for (const item of (node as List).children) {\n const raw = nodeToText(item as unknown as Root['children'][number]);\n // remark-gfm stores checkbox state as a `checked` property on the listItem\n // rather than preserving the literal [ ] / [x] text. Reconstruct it for\n // rules that match checkbox syntax (e.g. \\[ \\] T-CODE-nnn).\n const li = item as { checked?: boolean | null };\n if (li.checked === true) {\n items.push(`[x] ${raw}`);\n } else if (li.checked === false) {\n items.push(`[ ] ${raw}`);\n } else {\n items.push(raw);\n }\n }\n }\n }\n return items;\n}\n\nfunction collectAllListItems(section: SectionNode): string[] {\n const items = extractListItems(section.contentNodes);\n for (const child of section.children) items.push(...collectAllListItems(child));\n return items;\n}\n\nfunction collectAllTables(section: SectionNode): Table[] {\n const tables = section.contentNodes.filter((n) => n.type === 'table') as Table[];\n for (const child of section.children) tables.push(...collectAllTables(child));\n return tables;\n}\n\nfunction collectAllCodeBlocks(section: SectionNode): Code[] {\n const blocks = section.contentNodes.filter((n) => n.type === 'code') as Code[];\n for (const child of section.children) blocks.push(...collectAllCodeBlocks(child));\n return blocks;\n}\n","// @awa-component: CLI-SpecSpecChecker\n// @awa-impl: CLI-20_AC-1\n// @awa-impl: CLI-22_AC-1\n// @awa-impl: CLI-30_AC-1\n// @awa-impl: CLI-36_AC-1\n\nimport type {\n CheckConfig,\n CheckResult,\n Finding,\n MarkerScanResult,\n SpecParseResult,\n} from './types.js';\n\n// @awa-impl: CLI-20_AC-1, CLI-22_AC-1, CLI-36_AC-1\nexport function checkSpecAgainstSpec(\n specs: SpecParseResult,\n markers: MarkerScanResult,\n config: CheckConfig,\n): CheckResult {\n const findings: Finding[] = [];\n\n // @awa-impl: CLI-20_AC-1\n // Check cross-references resolve to real IDs\n for (const specFile of specs.specFiles) {\n for (const crossRef of specFile.crossRefs) {\n for (const refId of crossRef.ids) {\n if (!specs.allIds.has(refId)) {\n findings.push({\n severity: 'error',\n code: 'broken-cross-ref',\n message: `Cross-reference '${refId}' (${crossRef.type}) not found in any spec file`,\n filePath: crossRef.filePath,\n line: crossRef.line,\n id: refId,\n });\n }\n }\n }\n }\n\n // @awa-impl: CLI-36_AC-1\n // G3: Check that every REQ AC is claimed by at least one DESIGN IMPLEMENTS\n const implementedAcIds = new Set<string>();\n for (const specFile of specs.specFiles) {\n for (const crossRef of specFile.crossRefs) {\n if (crossRef.type === 'implements') {\n for (const id of crossRef.ids) {\n implementedAcIds.add(id);\n }\n }\n }\n }\n\n // Only check ACs that come from REQ files (not DESIGN/TASK/etc.)\n const reqAcIds = new Set<string>();\n for (const specFile of specs.specFiles) {\n if (/\\bREQ-/.test(specFile.filePath)) {\n for (const acId of specFile.acIds) {\n reqAcIds.add(acId);\n }\n }\n }\n\n for (const acId of reqAcIds) {\n if (!implementedAcIds.has(acId)) {\n const loc = specs.idLocations.get(acId);\n findings.push({\n severity: 'error',\n code: 'unlinked-ac',\n message: `Acceptance criterion '${acId}' is not claimed by any DESIGN IMPLEMENTS`,\n filePath: loc?.filePath,\n line: loc?.line,\n id: acId,\n });\n }\n }\n\n // @awa-impl: CLI-22_AC-1\n // Check for orphaned spec files (CODE not referenced by any other spec or code)\n // Skip when specOnly — orphaned-spec detection depends on code markers to be meaningful\n if (!config.specOnly) {\n const referencedCodes = new Set<string>();\n\n // Collect codes referenced in code markers\n for (const marker of markers.markers) {\n const codeMatch = /^([A-Z][A-Z0-9]*)[-_]/.exec(marker.id);\n if (codeMatch?.[1]) {\n referencedCodes.add(codeMatch[1]);\n }\n }\n\n // Collect codes referenced in cross-references\n for (const specFile of specs.specFiles) {\n for (const crossRef of specFile.crossRefs) {\n for (const refId of crossRef.ids) {\n const codeMatch = /^([A-Z][A-Z0-9]*)[-_]/.exec(refId);\n if (codeMatch?.[1]) {\n referencedCodes.add(codeMatch[1]);\n }\n }\n }\n }\n\n for (const specFile of specs.specFiles) {\n if (!specFile.code) continue; // Skip ARCHITECTURE.md etc.\n if (!referencedCodes.has(specFile.code)) {\n findings.push({\n severity: 'warning',\n code: 'orphaned-spec',\n message: `Spec file code '${specFile.code}' is not referenced by any other spec or code marker`,\n filePath: specFile.filePath,\n id: specFile.code,\n });\n }\n }\n }\n\n return { findings };\n}\n","// @awa-component: CLI-CheckCommand\n// @awa-impl: CLI-23_AC-1\n// @awa-impl: CLI-25_AC-1\n// @awa-impl: CLI-32_AC-1\n// @awa-impl: CLI-32_AC-2\n// @awa-impl: CLI-32_AC-3\n// @awa-impl: CLI-39_AC-1\n\nimport { checkCodeAgainstSpec } from '../core/check/code-spec-checker.js';\nimport { fixCodesTable } from '../core/check/codes-fixer.js';\nimport { scanMarkers } from '../core/check/marker-scanner.js';\nimport { fixMatrices } from '../core/check/matrix-fixer.js';\nimport { report } from '../core/check/reporter.js';\nimport { loadRules } from '../core/check/rule-loader.js';\nimport { checkSchemasAsync } from '../core/check/schema-checker.js';\nimport { parseSpecs } from '../core/check/spec-parser.js';\nimport { checkSpecAgainstSpec } from '../core/check/spec-spec-checker.js';\nimport type { CheckConfig, RawCheckOptions } from '../core/check/types.js';\nimport { DEFAULT_CHECK_CONFIG } from '../core/check/types.js';\nimport { configLoader } from '../core/config.js';\nimport type { FileConfig } from '../types/index.js';\nimport { logger } from '../utils/logger.js';\n\n// @awa-impl: CLI-23_AC-1\nexport async function checkCommand(cliOptions: RawCheckOptions): Promise<number> {\n try {\n // Load config from file\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // Build check config from file [check] section + CLI overrides\n const config = buildCheckConfig(fileConfig, cliOptions);\n\n // Scan code markers (skip when --spec-only), parse specs, and load schema rules in parallel\n const emptyMarkers: import('../core/check/types.js').MarkerScanResult = {\n markers: [],\n findings: [],\n };\n const [markers, specs, ruleSets] = await Promise.all([\n config.specOnly ? Promise.resolve(emptyMarkers) : scanMarkers(config),\n parseSpecs(config),\n config.schemaEnabled ? loadRules(config.schemaDir) : Promise.resolve([]),\n ]);\n\n // Run checkers (code-spec and spec-spec are synchronous; schema is async)\n // When --spec-only, skip code-to-spec traceability checks entirely\n const codeSpecResult = config.specOnly\n ? { findings: [] as const }\n : checkCodeAgainstSpec(markers, specs, config);\n const specSpecResult = checkSpecAgainstSpec(specs, markers, config);\n\n // Run fix BEFORE schema check: regenerate traceability matrices and Feature Codes table\n // so that schema line-limit validation sees the post-generation content (default; skip with --no-fix)\n if (config.fix) {\n const fixResult = await fixMatrices(specs, config.crossRefPatterns);\n if (fixResult.filesFixed > 0) {\n logger.info(`Fixed traceability matrices in ${fixResult.filesFixed} file(s)`);\n }\n\n const codesFixResult = await fixCodesTable(specs, config);\n if (codesFixResult.filesFixed > 0) {\n logger.info('Fixed Feature Codes table in ARCHITECTURE.md');\n }\n if (codesFixResult.emptyScopeCodes.length > 0) {\n logger.warn(\n `Feature codes missing Scope Boundary: ${codesFixResult.emptyScopeCodes.join(', ')}`,\n );\n }\n }\n\n // Schema check runs after fix so line-limit sees generated tables\n const schemaResult =\n config.schemaEnabled && ruleSets.length > 0\n ? await checkSchemasAsync(specs.specFiles, ruleSets)\n : { findings: [] as const };\n\n // Combine findings\n const combinedFindings = [\n ...markers.findings,\n ...codeSpecResult.findings,\n ...specSpecResult.findings,\n ...schemaResult.findings,\n ];\n\n // Unless --allow-warnings, promote warnings to errors\n const allFindings = config.allowWarnings\n ? combinedFindings\n : combinedFindings.map((f) =>\n f.severity === 'warning' ? { ...f, severity: 'error' as const } : f,\n );\n\n // Report results\n const isSummary = cliOptions.summary === true;\n if (isSummary) {\n const errors = allFindings.filter((f) => f.severity === 'error').length;\n const warnings = allFindings.filter((f) => f.severity === 'warning').length;\n console.log(`errors: ${errors}, warnings: ${warnings}`);\n } else {\n report(allFindings, config.format);\n }\n\n // Exit code: 0 = clean, 1 = any errors present\n const hasErrors = allFindings.some((f) => f.severity === 'error');\n return hasErrors ? 1 : 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 2;\n }\n}\n\n// @awa-impl: CLI-25_AC-1, CLI-31_AC-1\nfunction buildCheckConfig(fileConfig: FileConfig | null, cliOptions: RawCheckOptions): CheckConfig {\n const section = fileConfig?.check;\n\n const specGlobs = toStringArray(section?.['spec-globs']) ?? [...DEFAULT_CHECK_CONFIG.specGlobs];\n const codeGlobs = toStringArray(section?.['code-globs']) ?? [...DEFAULT_CHECK_CONFIG.codeGlobs];\n const markers = toStringArray(section?.markers) ?? [...DEFAULT_CHECK_CONFIG.markers];\n const crossRefPatterns = toStringArray(section?.['cross-ref-patterns']) ?? [\n ...DEFAULT_CHECK_CONFIG.crossRefPatterns,\n ];\n const idPattern =\n typeof section?.['id-pattern'] === 'string'\n ? section['id-pattern']\n : DEFAULT_CHECK_CONFIG.idPattern;\n\n // CLI --spec-ignore / --code-ignore append to their respective config lists\n const configSpecIgnore = toStringArray(section?.['spec-ignore']) ?? [\n ...DEFAULT_CHECK_CONFIG.specIgnore,\n ];\n const configCodeIgnore = toStringArray(section?.['code-ignore']) ?? [\n ...DEFAULT_CHECK_CONFIG.codeIgnore,\n ];\n const specIgnore = [...configSpecIgnore, ...(cliOptions.specIgnore ?? [])];\n const codeIgnore = [...configCodeIgnore, ...(cliOptions.codeIgnore ?? [])];\n\n const ignoreMarkers = toStringArray(section?.['ignore-markers']) ?? [\n ...DEFAULT_CHECK_CONFIG.ignoreMarkers,\n ];\n\n const format: 'text' | 'json' =\n cliOptions.json === true\n ? 'json'\n : cliOptions.format === 'json'\n ? 'json'\n : section?.format === 'json'\n ? 'json'\n : DEFAULT_CHECK_CONFIG.format;\n\n const schemaDir =\n typeof section?.['schema-dir'] === 'string'\n ? section['schema-dir']\n : DEFAULT_CHECK_CONFIG.schemaDir;\n\n const schemaEnabled =\n typeof section?.['schema-enabled'] === 'boolean'\n ? section['schema-enabled']\n : DEFAULT_CHECK_CONFIG.schemaEnabled;\n\n const allowWarnings =\n cliOptions.allowWarnings === true\n ? true\n : typeof section?.['allow-warnings'] === 'boolean'\n ? section['allow-warnings']\n : DEFAULT_CHECK_CONFIG.allowWarnings;\n\n const specOnly =\n cliOptions.specOnly === true\n ? true\n : typeof section?.['spec-only'] === 'boolean'\n ? section['spec-only']\n : DEFAULT_CHECK_CONFIG.specOnly;\n\n const fix = cliOptions.fix === false ? false : DEFAULT_CHECK_CONFIG.fix;\n\n return {\n specGlobs,\n codeGlobs,\n specIgnore,\n codeIgnore,\n ignoreMarkers,\n markers,\n idPattern,\n crossRefPatterns,\n format,\n schemaDir,\n schemaEnabled,\n allowWarnings,\n specOnly,\n fix,\n };\n}\n\nfunction toStringArray(value: unknown): string[] | null {\n if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {\n return value as string[];\n }\n return null;\n}\n","import chalk from 'chalk';\n\nimport type { CodesResult } from './types.js';\n\n/** JSON output structure for --json mode. */\nexport interface CodesJsonOutput {\n codes: Array<{\n code: string;\n feature: string;\n reqCount: number;\n docs: string;\n scope: string;\n }>;\n totalCodes: number;\n}\n\n/** Format doc types as a compact F·R·D·A·E string. */\nfunction formatDocs(docs: {\n feat: boolean;\n req: boolean;\n design: boolean;\n api: boolean;\n example: boolean;\n}): string {\n return [\n docs.feat ? 'F' : '·',\n docs.req ? 'R' : '·',\n docs.design ? 'D' : '·',\n docs.api ? 'A' : '·',\n docs.example ? 'E' : '·',\n ].join('');\n}\n\n/** Build the JSON output object. */\nexport function buildJsonOutput(result: CodesResult): CodesJsonOutput {\n return {\n codes: result.codes.map((c) => ({\n code: c.code,\n feature: c.feature,\n reqCount: c.reqCount,\n docs: formatDocs(c.docs),\n scope: c.scope,\n })),\n totalCodes: result.codes.length,\n };\n}\n\n/** Format result as JSON string. */\nexport function formatJson(result: CodesResult): string {\n return JSON.stringify(buildJsonOutput(result), null, 2);\n}\n\n/** Format result as a human-readable table. */\nexport function formatTable(result: CodesResult): string {\n const { codes } = result;\n\n if (codes.length === 0) {\n return chalk.yellow('No feature codes found.');\n }\n\n // Calculate column widths\n const codeWidth = Math.max(4, ...codes.map((c) => c.code.length));\n const featureWidth = Math.max(7, ...codes.map((c) => c.feature.length));\n const reqWidth = 4;\n const docsWidth = 5; // FRDAE is always 5 chars\n\n // Header\n const header = [\n 'CODE'.padEnd(codeWidth),\n 'Feature'.padEnd(featureWidth),\n 'Reqs'.padStart(reqWidth),\n 'Docs'.padEnd(docsWidth),\n 'Scope',\n ].join(' ');\n\n const separator = [\n '─'.repeat(codeWidth),\n '─'.repeat(featureWidth),\n '─'.repeat(reqWidth),\n '─'.repeat(docsWidth),\n '─'.repeat(40),\n ].join(' ');\n\n // Rows\n const rows = codes.map((c) => {\n const docs = formatDocs(c.docs);\n return [\n chalk.cyan(c.code.padEnd(codeWidth)),\n c.feature.padEnd(featureWidth),\n String(c.reqCount).padStart(reqWidth),\n docs,\n chalk.dim(c.scope),\n ].join(' ');\n });\n\n return [chalk.bold(`Feature codes (${codes.length}):\\n`), header, separator, ...rows].join('\\n');\n}\n\n/** Format result as a compact one-line summary. */\nexport function formatSummary(result: CodesResult): string {\n return `codes: ${result.codes.length}`;\n}\n","import { formatJson, formatSummary, formatTable } from '../core/codes/reporter.js';\nimport { scanCodes } from '../core/codes/scanner.js';\nimport type { CodesCommandOptions } from '../core/codes/types.js';\nimport { scan } from '../core/trace/scanner.js';\nimport { logger } from '../utils/logger.js';\n\n/**\n * Execute the `awa spec codes` command.\n * Returns exit code: 0 = success, 2 = internal error.\n */\nexport async function codesCommand(options: CodesCommandOptions): Promise<number> {\n try {\n const { specs, config } = await scan(options.config);\n\n const result = await scanCodes(specs.specFiles, config.specGlobs, config.specIgnore);\n\n if (options.summary) {\n process.stdout.write(`${formatSummary(result)}\\n`);\n } else if (options.json) {\n process.stdout.write(`${formatJson(result)}\\n`);\n } else {\n process.stdout.write(`${formatTable(result)}\\n`);\n }\n\n return 0;\n } catch (err) {\n if (err instanceof Error) {\n logger.error(err.message);\n } else {\n logger.error(String(err));\n }\n return 2;\n }\n}\n","// @awa-component: DIFF-DiffCommand\n// @awa-component: JSON-DiffCommand\n// @awa-component: MULTI-DiffCommand\n// @awa-impl: DIFF-5_AC-1\n// @awa-impl: DIFF-5_AC-2\n// @awa-impl: DIFF-5_AC-3\n// @awa-impl: MULTI-6_AC-1\n// @awa-impl: MULTI-7_AC-1\n// @awa-impl: MULTI-12_AC-1\n\nimport { intro, outro } from '@clack/prompts';\n\nimport { batchRunner } from '../core/batch-runner.js';\nimport { configLoader } from '../core/config.js';\nimport { diffEngine } from '../core/differ.js';\nimport { featureResolver } from '../core/feature-resolver.js';\nimport { formatDiffSummary, serializeDiffResult, writeJsonOutput } from '../core/json-output.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport { DiffError, type RawCliOptions, type ResolvedOptions } from '../types/index.js';\nimport { FileWatcher } from '../utils/file-watcher.js';\nimport { pathExists, rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\nasync function runDiff(\n diffOptions: {\n templatePath: string;\n targetPath: string;\n features: string[];\n listUnknown: boolean;\n },\n options: { json: boolean; summary: boolean },\n mergedDir: string | null,\n): Promise<number> {\n try {\n // Perform diff\n const result = await diffEngine.diff(diffOptions);\n\n // @awa-impl: JSON-2_AC-1, JSON-8_AC-1\n if (options.json) {\n writeJsonOutput(serializeDiffResult(result));\n // @awa-impl: DIFF-5_AC-1, DIFF-5_AC-2\n return result.hasDifferences ? 1 : 0;\n }\n\n // @awa-impl: JSON-5_AC-1\n if (options.summary) {\n console.log(formatDiffSummary(result));\n return result.hasDifferences ? 1 : 0;\n }\n\n // Display diff output\n for (const file of result.files) {\n switch (file.status) {\n case 'modified':\n logger.info(`Modified: ${file.relativePath}`);\n if (file.unifiedDiff) {\n // Parse and display unified diff with colors\n const lines = file.unifiedDiff.split('\\n');\n for (const line of lines) {\n if (\n line.startsWith('diff --git') ||\n line.startsWith('index ') ||\n line.startsWith('--- ') ||\n line.startsWith('+++ ')\n ) {\n logger.diffLine(line, 'context');\n } else if (line.startsWith('+')) {\n logger.diffLine(line, 'add');\n } else if (line.startsWith('-')) {\n logger.diffLine(line, 'remove');\n } else if (line.startsWith('@@')) {\n logger.diffLine(line, 'context');\n } else {\n logger.diffLine(line, 'context');\n }\n }\n }\n break;\n case 'new':\n logger.info(`New file: ${file.relativePath}`);\n break;\n case 'extra':\n logger.warn(`Extra file (not in template): ${file.relativePath}`);\n break;\n case 'binary-differs':\n logger.warn(`binary files differ: ${file.relativePath}`);\n break;\n case 'delete-listed':\n logger.warn(`Delete listed: ${file.relativePath}`);\n break;\n case 'identical':\n // Skip identical files from output\n break;\n }\n }\n\n // Display summary\n logger.diffSummary(result);\n\n // @awa-impl: DIFF-5_AC-1, DIFF-5_AC-2\n return result.hasDifferences ? 1 : 0;\n } finally {\n // Clean up merged overlay temp directory\n if (mergedDir) {\n try {\n await rmDir(mergedDir);\n } catch {\n // Swallow cleanup errors — temp dir will be cleaned by OS eventually\n }\n }\n }\n}\n\nasync function prepareDiff(options: ResolvedOptions): Promise<{\n diffOptions: {\n templatePath: string;\n targetPath: string;\n features: string[];\n listUnknown: boolean;\n };\n template: { type: string; localPath: string; source: string };\n mergedDir: string | null;\n}> {\n // Validate target directory exists (now from options.output)\n if (!(await pathExists(options.output))) {\n throw new DiffError(`Target directory does not exist: ${options.output}`);\n }\n\n const targetPath = options.output;\n\n // Resolve template source\n const template = await templateResolver.resolve(options.template, options.refresh);\n\n const features = featureResolver.resolve({\n baseFeatures: [...options.features],\n presetNames: [...options.preset],\n removeFeatures: [...options.removeFeatures],\n presetDefinitions: options.presets,\n });\n\n // @awa-impl: OVL-7_AC-1\n // Build merged template dir if overlays are specified\n let mergedDir: string | null = null;\n let templatePath = template.localPath;\n if (options.overlay.length > 0) {\n const overlayDirs = await resolveOverlays([...options.overlay], options.refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n return {\n diffOptions: {\n templatePath,\n targetPath,\n features,\n listUnknown: options.listUnknown,\n },\n template,\n mergedDir,\n };\n}\n\nexport async function diffCommand(cliOptions: RawCliOptions): Promise<number> {\n try {\n // Load configuration file\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // Batch mode: --all or --target\n if (cliOptions.allTargets || cliOptions.target) {\n const mode = cliOptions.allTargets ? 'all' : 'single';\n const targets = batchRunner.resolveTargets(cliOptions, fileConfig, mode, cliOptions.target);\n\n // @awa-impl: MULTI-12_AC-1\n // Exit code aggregation: 0 if all identical, 1 if any differ, 2 on error (first error short-circuits)\n let hasDifferences = false;\n for (const { targetName, options } of targets) {\n batchRunner.logForTarget(targetName, 'Starting diff...');\n const { diffOptions, mergedDir } = await prepareDiff(options);\n const exitCode = await runDiff(diffOptions, options, mergedDir);\n if (exitCode === 1) {\n hasDifferences = true;\n }\n batchRunner.logForTarget(targetName, 'Diff complete.');\n }\n\n outro('All targets diffed!');\n return hasDifferences ? 1 : 0;\n }\n\n // Standard single-target mode (backward compatible)\n const options = configLoader.merge(cliOptions, fileConfig);\n\n const silent = options.json || options.summary;\n\n // @awa-impl: JSON-6_AC-1\n // Suppress interactive output when --json or --summary is active\n if (!silent) {\n intro('awa CLI - Template Diff');\n }\n\n const { diffOptions, template, mergedDir } = await prepareDiff(options);\n\n // Validate watch mode: only local templates are supported\n if (cliOptions.watch && template.type !== 'local' && template.type !== 'bundled') {\n throw new DiffError('--watch is only supported with local template sources');\n }\n\n // Run diff once\n const result = await runDiff(diffOptions, options, mergedDir);\n\n if (!cliOptions.watch) {\n if (!silent) {\n outro('Diff complete!');\n }\n return result;\n }\n\n // Watch mode: re-run diff on template changes\n // Resolves only on SIGINT (Ctrl+C) — this is intentional for watch mode\n logger.info(`Watching for changes in ${template.localPath}...`);\n\n return new Promise<number>((resolve) => {\n let running = false;\n const watcher = new FileWatcher({\n directory: template.localPath,\n onChange: async () => {\n if (running) return;\n running = true;\n try {\n console.clear();\n logger.info(`[${new Date().toLocaleTimeString()}] Change detected, re-running diff...`);\n logger.info('---');\n await runDiff(diffOptions, options, null);\n } finally {\n running = false;\n }\n },\n });\n\n watcher.start();\n\n process.once('SIGINT', () => {\n watcher.stop();\n logger.info('\\nWatch mode stopped.');\n resolve(0);\n });\n });\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n\n // @awa-impl: DIFF-5_AC-3\n return 2;\n }\n}\n","// @awa-component: MULTI-BatchRunner\n// @awa-component: MULTI-Reporter\n// @awa-impl: MULTI-4_AC-1\n// @awa-impl: MULTI-4_AC-2\n// @awa-impl: MULTI-5_AC-1\n// @awa-impl: MULTI-8_AC-1\n// @awa-impl: MULTI-9_AC-1\n// @awa-impl: MULTI-11_AC-1\n\nimport {\n ConfigError,\n type FileConfig,\n type RawCliOptions,\n type ResolvedOptions,\n} from '../types/index.js';\nimport { logger } from '../utils/logger.js';\nimport { configLoader } from './config.js';\n\nexport interface BatchTargetResult {\n targetName: string;\n options: ResolvedOptions;\n}\n\nexport class BatchRunner {\n // Resolve all targets or a single named target from config\n resolveTargets(\n cli: RawCliOptions,\n fileConfig: FileConfig | null,\n mode: 'all' | 'single',\n targetName?: string,\n ): BatchTargetResult[] {\n if (!fileConfig) {\n throw new ConfigError(\n 'No configuration file found. --all and --target require a config file with [targets.*] sections.',\n 'NO_TARGETS',\n null,\n );\n }\n\n const targetNames = configLoader.getTargetNames(fileConfig);\n\n if (targetNames.length === 0) {\n throw new ConfigError(\n 'No targets defined in configuration. Add [targets.<name>] sections to .awa.toml.',\n 'NO_TARGETS',\n null,\n );\n }\n\n const namesToProcess = mode === 'all' ? targetNames : [targetName as string];\n\n const results: BatchTargetResult[] = [];\n\n for (const name of namesToProcess) {\n const resolved = configLoader.resolveTarget(name, fileConfig);\n\n // Build CLI options for this target:\n // - When --all, ignore CLI positional output\n // - When --target, CLI positional overrides target output\n const targetCli: RawCliOptions = {\n ...cli,\n output: mode === 'all' ? undefined : cli.output,\n };\n\n let options: ResolvedOptions;\n try {\n options = configLoader.merge(targetCli, resolved);\n } catch (error) {\n // Re-throw MISSING_OUTPUT with target-specific message\n if (error instanceof ConfigError && error.code === 'MISSING_OUTPUT') {\n throw new ConfigError(\n `Target '${name}' has no output directory. Specify 'output' in [targets.${name}] or in the root config.`,\n 'MISSING_OUTPUT',\n null,\n );\n }\n throw error;\n }\n\n results.push({ targetName: name, options });\n }\n\n return results;\n }\n\n // Log a message prefixed with target name\n logForTarget(targetName: string, message: string): void {\n logger.info(`[${targetName}] ${message}`);\n }\n\n warnForTarget(targetName: string, message: string): void {\n logger.warn(`[${targetName}] ${message}`);\n }\n\n errorForTarget(targetName: string, message: string): void {\n logger.error(`[${targetName}] ${message}`);\n }\n}\n\nexport const batchRunner = new BatchRunner();\n","// @awa-component: DIFF-DiffEngine\n// @awa-impl: DIFF-1_AC-1\n// @awa-impl: DIFF-1_AC-2\n// @awa-impl: DIFF-1_AC-3\n// @awa-impl: DIFF-2_AC-1\n// @awa-impl: DIFF-2_AC-2\n// @awa-impl: DIFF-2_AC-3\n// @awa-impl: DIFF-2_AC-4\n// @awa-impl: DIFF-2_AC-5\n// @awa-impl: DIFF-3_AC-1\n// @awa-impl: DIFF-3_AC-2\n// @awa-impl: DIFF-3_AC-3\n// @awa-impl: DIFF-4_AC-1\n// @awa-impl: DIFF-4_AC-2\n// @awa-impl: DIFF-5_AC-1\n// @awa-impl: DIFF-5_AC-2\n// @awa-impl: DIFF-5_AC-3\n// @awa-impl: DIFF-6_AC-1\n// @awa-impl: DIFF-6_AC-2\n// @awa-impl: DIFF-6_AC-3\n// @awa-impl: DIFF-8_AC-1\n// @awa-impl: DIFF-8_AC-2\n// @awa-impl: DIFF-8_AC-3\n// @awa-impl: DIFF-8_AC-4\n\nimport { tmpdir } from 'node:os';\nimport { join, relative } from 'node:path';\n\nimport { structuredPatch } from 'diff';\nimport { isBinaryFile as detectBinaryFile } from 'isbinaryfile';\n\nimport type { DiffOptions, DiffResult, FileDiff, GenerateOptions } from '../types/index.js';\nimport { ensureDir, pathExists, readBinaryFile, rmDir, walkDirectory } from '../utils/fs.js';\nimport { loadDeleteList, resolveDeleteList } from './delete-list.js';\nimport { fileGenerator } from './generator.js';\n\nexport class DiffEngine {\n // @awa-impl: DIFF-1_AC-1, DIFF-1_AC-2, DIFF-1_AC-3\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-2, DIFF-2_AC-3, DIFF-2_AC-4, DIFF-2_AC-5\n // @awa-impl: DIFF-3_AC-1, DIFF-3_AC-2, DIFF-3_AC-3\n // @awa-impl: DIFF-4_AC-1, DIFF-4_AC-2\n // @awa-impl: DIFF-5_AC-1, DIFF-5_AC-2, DIFF-5_AC-3\n // @awa-impl: DIFF-6_AC-1, DIFF-6_AC-2, DIFF-6_AC-3\n async diff(options: DiffOptions): Promise<DiffResult> {\n const { templatePath, targetPath, features, listUnknown } = options;\n\n // @awa-impl: DIFF-1_AC-1, DIFF-1_AC-2\n const tempPath = await this.createTempDir();\n\n try {\n // Generate templates to temp directory\n const generateOptions: GenerateOptions = {\n templatePath,\n outputPath: tempPath,\n features,\n force: true,\n dryRun: false,\n delete: false,\n };\n\n await fileGenerator.generate(generateOptions);\n\n // Collect all files from both directories\n const generatedFiles = new Set<string>();\n const targetFiles = new Set<string>();\n\n // Walk generated directory (if exists - may be empty if template generates nothing)\n if (await pathExists(tempPath)) {\n for await (const file of walkDirectory(tempPath)) {\n const relPath = relative(tempPath, file);\n generatedFiles.add(relPath);\n }\n }\n\n // Walk target directory (if exists)\n if (await pathExists(targetPath)) {\n for await (const file of walkDirectory(targetPath)) {\n const relPath = relative(targetPath, file);\n targetFiles.add(relPath);\n }\n }\n\n // Compare files: iterate generated files first; optionally include target-only files when requested\n const files: FileDiff[] = [];\n\n for (const relPath of generatedFiles) {\n const generatedFilePath = join(tempPath, relPath);\n const targetFilePath = join(targetPath, relPath);\n\n if (targetFiles.has(relPath)) {\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-2, DIFF-2_AC-3, DIFF-2_AC-4, DIFF-2_AC-5\n const fileDiff = await this.compareFiles(generatedFilePath, targetFilePath, relPath);\n files.push(fileDiff);\n } else {\n // @awa-impl: DIFF-3_AC-1\n files.push({\n relativePath: relPath,\n status: 'new',\n });\n }\n }\n\n if (listUnknown) {\n for (const relPath of targetFiles) {\n if (generatedFiles.has(relPath)) {\n continue;\n }\n\n // @awa-impl: DIFF-3_AC-2, DIFF-3_AC-3, DIFF-3_AC-4\n files.push({\n relativePath: relPath,\n status: 'extra',\n });\n }\n }\n\n // Check delete list for files that exist in target\n const deleteEntries = await loadDeleteList(templatePath);\n const deleteList = resolveDeleteList(deleteEntries, features ?? []);\n for (const relPath of deleteList) {\n if (targetFiles.has(relPath) && !generatedFiles.has(relPath)) {\n // Remove any existing 'extra' entry for this path (to avoid double-reporting)\n const existingIdx = files.findIndex(\n (f) => f.relativePath === relPath && f.status === 'extra',\n );\n if (existingIdx !== -1) {\n files.splice(existingIdx, 1);\n }\n files.push({\n relativePath: relPath,\n status: 'delete-listed',\n });\n }\n }\n\n // Calculate summary\n const identical = files.filter((f) => f.status === 'identical').length;\n const modified = files.filter((f) => f.status === 'modified').length;\n const newFiles = files.filter((f) => f.status === 'new').length;\n const extraFiles = files.filter((f) => f.status === 'extra').length;\n const binaryDiffers = files.filter((f) => f.status === 'binary-differs').length;\n const deleteListed = files.filter((f) => f.status === 'delete-listed').length;\n\n const hasDifferences =\n modified > 0 || newFiles > 0 || extraFiles > 0 || binaryDiffers > 0 || deleteListed > 0;\n\n return {\n files,\n identical,\n modified,\n newFiles,\n extraFiles,\n binaryDiffers,\n deleteListed,\n hasDifferences,\n };\n } finally {\n // @awa-impl: DIFF-6_AC-1, DIFF-6_AC-2, DIFF-6_AC-3\n await this.cleanupTempDir(tempPath);\n }\n }\n\n // @awa-impl: DIFF-1_AC-1, DIFF-1_AC-2\n async createTempDir(): Promise<string> {\n const systemTemp = tmpdir();\n const timestamp = Date.now();\n const random = Math.random().toString(36).substring(2, 8);\n const tempPath = join(systemTemp, `awa-diff-${timestamp}-${random}`);\n\n await ensureDir(tempPath);\n return tempPath;\n }\n\n // @awa-impl: DIFF-6_AC-1, DIFF-6_AC-2, DIFF-6_AC-3\n async cleanupTempDir(tempPath: string): Promise<void> {\n try {\n if (await pathExists(tempPath)) {\n await rmDir(tempPath);\n }\n } catch (_error) {\n // Swallow cleanup errors - temp directory will be cleaned by OS eventually\n // This ensures cleanup errors don't mask the actual diff results\n }\n }\n\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-2, DIFF-2_AC-3, DIFF-2_AC-4, DIFF-2_AC-5\n async compareFiles(\n generatedPath: string,\n targetPath: string,\n relativePath: string,\n ): Promise<FileDiff> {\n // Read raw bytes for byte-for-byte comparison.\n const generatedBytes = await readBinaryFile(generatedPath);\n const targetBytes = await readBinaryFile(targetPath);\n\n // @awa-impl: DIFF-2_AC-1, DIFF-2_AC-3\n if (generatedBytes.equals(targetBytes)) {\n return {\n relativePath,\n status: 'identical',\n };\n }\n\n // @awa-impl: DIFF-2_AC-5\n // If either side is binary, do not attempt a text diff.\n const isBinaryGenerated = await this.isBinaryFile(generatedPath);\n const isBinaryTarget = await this.isBinaryFile(targetPath);\n\n if (isBinaryGenerated || isBinaryTarget) {\n return {\n relativePath,\n status: 'binary-differs',\n };\n }\n\n // Text files: unified diff (diff library is text-based)\n const generatedContent = generatedBytes.toString('utf-8');\n const targetContent = targetBytes.toString('utf-8');\n\n // @awa-impl: DIFF-2_AC-4\n // Generate unified diff\n const patch = structuredPatch(\n `a/${relativePath}`,\n `b/${relativePath}`,\n targetContent,\n generatedContent,\n 'target',\n 'generated',\n {\n context: 3,\n },\n );\n\n // Format as git-style unified diff string (with file headers)\n const headerLines = [\n `diff --git a/${relativePath} b/${relativePath}`,\n `--- a/${relativePath}`,\n `+++ b/${relativePath}`,\n ];\n\n const hunkLines = patch.hunks.flatMap((hunk) => {\n const lines = [`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`];\n lines.push(...hunk.lines);\n return lines;\n });\n\n const unifiedDiff = [...headerLines, ...hunkLines].join('\\n');\n\n return {\n relativePath,\n status: 'modified',\n unifiedDiff,\n };\n }\n\n // @awa-impl: DIFF-2_AC-5\n async isBinaryFile(filePath: string): Promise<boolean> {\n try {\n return await detectBinaryFile(filePath);\n } catch {\n // If detection fails, assume text file\n return false;\n }\n }\n}\n\nexport const diffEngine = new DiffEngine();\n","// @awa-component: GEN-DeleteList\n// @awa-impl: GEN-12_AC-1\n// @awa-impl: GEN-12_AC-8\n\nimport { join } from 'node:path';\n\nimport { pathExists, readTextFile } from '../utils/fs.js';\n\nconst DELETE_LIST_FILENAME = '_delete.txt';\n\n/**\n * A delete list entry. When `features` is set, the path is only deleted\n * when NONE of those features are present in the active feature set\n * (stale tool cleanup). When `features` is absent, the path is always\n * deleted (legacy removal).\n */\nexport interface DeleteEntry {\n path: string;\n /** One or more feature names — keep (don't delete) if any is active. */\n features?: string[];\n}\n\n/**\n * Parse `_delete.txt` content into structured entries.\n *\n * Format:\n * - Blank lines and `#` comments are ignored.\n * - `# @feature <name> [<name2> ...]` starts a feature-gated section: subsequent\n * paths are deleted only when NONE of the listed features are active.\n * - Any other comment line clears the current feature section (returns to\n * always-delete behaviour).\n * - Path lines inherit the current section's feature tag (if any).\n */\nexport function parseDeleteList(content: string): DeleteEntry[] {\n const entries: DeleteEntry[] = [];\n let currentFeatures: string[] | undefined;\n\n for (const raw of content.split('\\n')) {\n const line = raw.trim();\n if (line.length === 0) continue;\n\n if (line.startsWith('#')) {\n const featureMatch = line.match(/^#\\s*@feature\\s+(.+)$/);\n if (featureMatch) {\n const featureSection = featureMatch[1];\n currentFeatures = featureSection ? featureSection.trim().split(/\\s+/) : undefined;\n } else {\n // Any other comment resets the feature section\n currentFeatures = undefined;\n }\n continue;\n }\n\n entries.push({ path: line, features: currentFeatures });\n }\n\n return entries;\n}\n\n/**\n * Resolve which paths from the delete list should actually be deleted,\n * given the currently active feature flags.\n *\n * - Entries without a feature tag are always included (legacy removals).\n * - Entries with feature tags are included only when NONE of those features are active\n * (stale tool output cleanup).\n */\nexport function resolveDeleteList(entries: DeleteEntry[], activeFeatures: string[]): string[] {\n const activeSet = new Set(activeFeatures);\n return entries\n .filter((e) => e.features === undefined || !e.features.some((f) => activeSet.has(f)))\n .map((e) => e.path);\n}\n\n/**\n * Load and parse `_delete.txt` from the template directory.\n * Returns empty array if the file does not exist.\n */\nexport async function loadDeleteList(templatePath: string): Promise<DeleteEntry[]> {\n const deleteListPath = join(templatePath, DELETE_LIST_FILENAME);\n\n if (!(await pathExists(deleteListPath))) {\n return [];\n }\n\n const content = await readTextFile(deleteListPath);\n return parseDeleteList(content);\n}\n","// @awa-component: GEN-FileGenerator\n// @awa-impl: GEN-1_AC-1\n// @awa-impl: GEN-1_AC-2\n// @awa-impl: GEN-1_AC-3\n// @awa-impl: GEN-2_AC-1\n// @awa-impl: GEN-2_AC-2\n// @awa-impl: GEN-2_AC-3\n// @awa-impl: GEN-3_AC-1\n// @awa-impl: GEN-3_AC-2\n// @awa-impl: GEN-3_AC-3\n// @awa-impl: GEN-8_AC-1\n// @awa-impl: GEN-8_AC-2\n// @awa-impl: GEN-8_AC-3\n// @awa-impl: GEN-11_AC-3\n// @awa-impl: GEN-6_AC-1\n// @awa-impl: GEN-6_AC-2\n// @awa-impl: GEN-12_AC-2\n// @awa-impl: GEN-12_AC-4\n// @awa-impl: GEN-12_AC-5\n// @awa-impl: GEN-12_AC-6\n// @awa-impl: GEN-12_AC-7\n// @awa-impl: CLI-6_AC-2\n// @awa-impl: CLI-12_AC-2\n// @awa-impl: TPL-9_AC-1\n// @awa-impl: TPL-9_AC-2\n\nimport { join, relative } from 'node:path';\n\nimport { PACKAGE_INFO } from '../_generated/package_info.js';\nimport {\n type ConflictItem,\n type FileAction,\n type GenerateOptions,\n GenerationError,\n type GenerationResult,\n} from '../types/index.js';\nimport { deleteFile, pathExists, readTextFile, walkDirectory, writeTextFile } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\nimport { loadDeleteList, resolveDeleteList } from './delete-list.js';\nimport { conflictResolver, deleteResolver } from './resolver.js';\nimport { templateEngine } from './template.js';\n\nexport class FileGenerator {\n // @awa-impl: GEN-1_AC-1, GEN-1_AC-2, GEN-1_AC-3\n // @awa-impl: GEN-2_AC-1, GEN-2_AC-2, GEN-2_AC-3\n // @awa-impl: GEN-3_AC-1, GEN-3_AC-2, GEN-3_AC-3\n async generate(options: GenerateOptions): Promise<GenerationResult> {\n const { templatePath, outputPath, features, force, dryRun } = options;\n const enableDelete = options.delete;\n\n // Configure template engine\n templateEngine.configure(templatePath);\n\n const actions: FileAction[] = [];\n let created = 0;\n let overwritten = 0;\n let deleted = 0;\n let skippedEmpty = 0;\n let skippedUser = 0;\n let skippedEqual = 0;\n\n // Collect files to process\n interface FileToProcess {\n templateFile: string;\n outputFile: string;\n content: string;\n isNew: boolean;\n }\n\n const filesToProcess: FileToProcess[] = [];\n const conflicts: ConflictItem[] = [];\n\n try {\n // First pass: render all templates and categorize files\n for await (const templateFile of this.walkTemplates(templatePath)) {\n // Compute output path\n const outputFile = this.computeOutputPath(templateFile, templatePath, outputPath);\n\n // Render template\n const result = await templateEngine.render(templateFile, {\n features,\n version: PACKAGE_INFO.version,\n });\n\n // Handle empty output\n if (result.isEmpty && !result.isEmptyFileMarker) {\n // Skip empty files\n actions.push({\n type: 'skip-empty',\n sourcePath: templateFile,\n outputPath: outputFile,\n });\n skippedEmpty++;\n continue;\n }\n\n // Get final content (empty string if marker)\n const content = result.isEmptyFileMarker ? '' : result.content;\n\n // Check for conflicts\n const fileExists = await pathExists(outputFile);\n\n if (fileExists) {\n // Read existing content for comparison\n const existingContent = await readTextFile(outputFile);\n conflicts.push({\n outputPath: outputFile,\n sourcePath: templateFile,\n newContent: content,\n existingContent,\n });\n }\n\n filesToProcess.push({\n templateFile,\n outputFile,\n content,\n isNew: !fileExists,\n });\n }\n\n // Resolve all conflicts at once if there are any\n let resolution: { overwrite: string[]; skip: string[]; equal: string[] } = {\n overwrite: [],\n skip: [],\n equal: [],\n };\n if (conflicts.length > 0) {\n resolution = await conflictResolver.resolveBatch(conflicts, force, dryRun);\n }\n\n // Second pass: process files based on resolution\n for (const file of filesToProcess) {\n if (file.isNew) {\n // Create new file\n if (!dryRun) {\n await writeTextFile(file.outputFile, file.content);\n }\n actions.push({\n type: 'create',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n created++;\n logger.fileAction({\n type: 'create',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n } else if (resolution.overwrite.includes(file.outputFile)) {\n // Overwrite existing file\n if (!dryRun) {\n await writeTextFile(file.outputFile, file.content);\n }\n actions.push({\n type: 'overwrite',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n overwritten++;\n logger.fileAction({\n type: 'overwrite',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n } else if (resolution.equal.includes(file.outputFile)) {\n // Skip file — content is identical\n actions.push({\n type: 'skip-equal',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n skippedEqual++;\n logger.fileAction({\n type: 'skip-equal',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n } else if (resolution.skip.includes(file.outputFile)) {\n // Skip file — user declined overwrite\n actions.push({\n type: 'skip-user',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n skippedUser++;\n logger.fileAction({\n type: 'skip-user',\n sourcePath: file.templateFile,\n outputPath: file.outputFile,\n });\n }\n }\n\n // Process delete list (after file generation)\n const deleteEntries = await loadDeleteList(templatePath);\n if (deleteEntries.length > 0) {\n const deleteList = resolveDeleteList(deleteEntries, features);\n\n // Collect generated output paths to detect conflicts\n const generatedOutputPaths = new Set(filesToProcess.map((f) => f.outputFile));\n\n // Filter: only files that exist and aren't being generated\n const deleteCandidates: string[] = [];\n for (const relPath of deleteList) {\n const absPath = join(outputPath, relPath);\n if (generatedOutputPaths.has(absPath)) {\n logger.warn(\n `Delete list entry '${relPath}' conflicts with generated file — skipping deletion`,\n );\n continue;\n }\n if (await pathExists(absPath)) {\n deleteCandidates.push(absPath);\n }\n }\n\n if (deleteCandidates.length > 0) {\n if (!enableDelete) {\n // --delete not passed: warn but do nothing\n for (const absPath of deleteCandidates) {\n logger.warn(\n `Would delete (pass --delete to enable): ${relative(outputPath, absPath)}`,\n );\n }\n } else {\n const confirmed = await deleteResolver.resolveDeletes(deleteCandidates, force, dryRun);\n\n for (const absPath of confirmed) {\n if (!dryRun) {\n await deleteFile(absPath);\n }\n actions.push({ type: 'delete', outputPath: absPath });\n deleted++;\n logger.fileAction({ type: 'delete', outputPath: absPath });\n }\n }\n }\n }\n\n return {\n actions,\n created,\n overwritten,\n deleted,\n skipped: skippedEmpty + skippedUser + skippedEqual,\n skippedEmpty,\n skippedUser,\n skippedEqual,\n };\n } catch (error) {\n // @awa-impl: GEN-2_AC-3, GEN-11_AC-3\n if (error instanceof Error && 'code' in error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'EACCES' || code === 'EPERM') {\n throw new GenerationError(`Permission denied: ${error.message}`, 'PERMISSION_DENIED');\n }\n if (code === 'ENOSPC') {\n throw new GenerationError(`Disk full: ${error.message}`, 'DISK_FULL');\n }\n }\n throw error;\n }\n }\n\n // @awa-impl: GEN-8_AC-1, GEN-8_AC-2, GEN-8_AC-3\n // @awa-impl: TPL-9_AC-1, TPL-9_AC-2\n async *walkTemplates(dir: string): AsyncIterable<string> {\n // Use utility function that already handles underscore exclusion\n yield* walkDirectory(dir);\n }\n\n // @awa-impl: GEN-1_AC-1, GEN-1_AC-2, GEN-1_AC-3\n computeOutputPath(templatePath: string, templateRoot: string, outputRoot: string): string {\n // Get relative path from template root\n const relativePath = relative(templateRoot, templatePath);\n\n // Join with output root to mirror structure\n return join(outputRoot, relativePath);\n }\n}\n\nexport const fileGenerator = new FileGenerator();\n","// @awa-component: GEN-ConflictResolver\n// @awa-component: GEN-DeleteResolver\n// @awa-impl: CLI-5_AC-2\n// @awa-impl: CLI-5_AC-3\n// @awa-impl: GEN-4_AC-1\n// @awa-impl: GEN-4_AC-2\n// @awa-impl: GEN-4_AC-3\n// @awa-impl: GEN-5_AC-1\n// @awa-impl: GEN-5_AC-2\n// @awa-impl: GEN-5_AC-3\n// @awa-impl: GEN-5_AC-4\n// @awa-impl: GEN-5_AC-5\n// @awa-impl: GEN-5_AC-6\n// @awa-impl: GEN-5_AC-7\n// @awa-impl: GEN-6_AC-3\n// @awa-impl: GEN-10_AC-3\n// @awa-impl: GEN-12_AC-3\n// @awa-impl: GEN-12_AC-4\n// @awa-impl: GEN-12_AC-5\n// @awa-impl: CLI-12_AC-3\n\nimport { MultiSelectPrompt } from '@clack/core';\nimport { isCancel, multiselect } from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport type { BatchConflictResolution, ConflictItem } from '../types/index.js';\n\n// Unicode symbols (mirrors @clack/prompts internals)\nconst _unicode = process.platform !== 'win32';\nconst _s = (c: string, fb: string) => (_unicode ? c : fb);\nconst _CHECKED = _s('\\u25FC', '[+]'); // ◼\nconst _UNCHECKED_A = _s('\\u25FB', '[·]'); // ◻ active\nconst _UNCHECKED = _s('\\u25FB', '[ ]'); // ◻ inactive\nconst _BAR = _s('\\u2502', '|'); // │\nconst _BAR_END = _s('\\u2514', '-'); // └\n\ntype SelectOption = { value: string; label?: string; hint?: string };\n\nfunction _renderDeleteItem(opt: SelectOption, state: string): string {\n const label = opt.label ?? opt.value;\n const hint = opt.hint ? ` ${chalk.dim(`(${opt.hint})`)}` : '';\n switch (state) {\n case 'active':\n return `${chalk.cyan(_UNCHECKED_A)} ${label}${hint}`;\n case 'selected':\n return `${chalk.red(_CHECKED)} ${chalk.dim(label)}${hint}`;\n case 'active-selected':\n return `${chalk.red(_CHECKED)} ${label}${hint}`;\n case 'cancelled':\n return chalk.strikethrough(chalk.dim(label));\n case 'submitted':\n return chalk.dim(label);\n default:\n return `${chalk.dim(_UNCHECKED)} ${chalk.dim(label)}`;\n }\n}\n\n/** Like @clack/prompts `multiselect` but with red checkboxes for destructive operations. */\nasync function deleteMultiselect(opts: {\n message: string;\n options: SelectOption[];\n initialValues?: string[];\n required?: boolean;\n}): Promise<string[] | symbol> {\n const { message, options, initialValues, required = false } = opts;\n return new MultiSelectPrompt({\n options,\n initialValues,\n required,\n render() {\n const self = this as unknown as {\n state: string;\n options: SelectOption[];\n cursor: number;\n value: string[];\n };\n const header = `${chalk.gray(_BAR)}\\n${chalk.cyan(_BAR)} ${message}\\n`;\n const getState = (opt: SelectOption, idx: number): string => {\n const active = idx === self.cursor;\n const sel = self.value.includes(opt.value);\n if (active && sel) return 'active-selected';\n if (sel) return 'selected';\n if (active) return 'active';\n return 'inactive';\n };\n switch (self.state) {\n case 'submit':\n return (\n `${header}${chalk.gray(_BAR)} ` +\n (self.options\n .filter((o) => self.value.includes(o.value))\n .map((o) => _renderDeleteItem(o, 'submitted'))\n .join(chalk.dim(', ')) || chalk.dim('none'))\n );\n case 'cancel': {\n const cancelled = self.options\n .filter((o) => self.value.includes(o.value))\n .map((o) => _renderDeleteItem(o, 'cancelled'))\n .join(chalk.dim(', '));\n return `${header}${chalk.gray(_BAR)} ${cancelled.trim() ? `${cancelled}\\n${chalk.gray(_BAR)}` : chalk.dim('none')}`;\n }\n default:\n return (\n `${header}${chalk.cyan(_BAR)} ` +\n self.options\n .map((o, i) => _renderDeleteItem(o, getState(o, i)))\n .join(`\\n${chalk.cyan(_BAR)} `) +\n `\\n${chalk.cyan(_BAR_END)}\\n`\n );\n }\n },\n }).prompt() as Promise<string[] | symbol>;\n}\n\nexport class ConflictResolver {\n // @awa-impl: GEN-4_AC-1, GEN-4_AC-2, GEN-4_AC-3\n // @awa-impl: GEN-5_AC-1, GEN-5_AC-2, GEN-5_AC-3, GEN-5_AC-4, GEN-5_AC-5, GEN-5_AC-6, GEN-5_AC-7\n // @awa-impl: CLI-5_AC-2, CLI-5_AC-3\n // @awa-impl: GEN-6_AC-3\n async resolveBatch(\n conflicts: ConflictItem[],\n force: boolean,\n dryRun: boolean,\n ): Promise<BatchConflictResolution> {\n // Separate identical-content files from different files\n const identicalPaths = conflicts\n .filter((c) => c.newContent === c.existingContent)\n .map((c) => c.outputPath);\n const differentFiles = conflicts.filter((c) => c.newContent !== c.existingContent);\n\n // In dry-run mode, never modify files (P7: Dry Run Immutable)\n if (dryRun) {\n return {\n overwrite: [],\n skip: differentFiles.map((c) => c.outputPath),\n equal: identicalPaths,\n };\n }\n\n // In force mode, always overwrite without prompting (P8: Force No Prompt)\n if (force) {\n return {\n overwrite: differentFiles.map((c) => c.outputPath),\n skip: [],\n equal: identicalPaths,\n };\n }\n\n // If all files are identical, skip them all\n if (differentFiles.length === 0) {\n return {\n overwrite: [],\n skip: [],\n equal: identicalPaths,\n };\n }\n\n // @awa-impl: GEN-5_AC-1, GEN-5_AC-2, GEN-5_AC-5, GEN-5_AC-6\n // Prompt user with multi-select (all selected by default)\n const selected = await multiselect({\n message: 'The following files already exist. Select files to overwrite:',\n options: differentFiles.map((c) => ({\n value: c.outputPath,\n label: c.outputPath,\n })),\n initialValues: differentFiles.map((c) => c.outputPath), // All selected by default (AC-5.6)\n required: false,\n });\n\n // @awa-impl: GEN-10_AC-3\n // Handle user cancellation (Ctrl+C)\n if (isCancel(selected)) {\n process.exit(1);\n }\n\n const selectedPaths = selected as string[];\n const allPaths = differentFiles.map((c) => c.outputPath);\n\n return {\n overwrite: selectedPaths,\n skip: allPaths.filter((p) => !selectedPaths.includes(p)),\n equal: identicalPaths,\n };\n }\n}\n\nexport const conflictResolver = new ConflictResolver();\n\nexport class DeleteResolver {\n /**\n * Prompt user to confirm which files to delete.\n * Returns the list of absolute paths confirmed for deletion.\n */\n async resolveDeletes(candidates: string[], force: boolean, dryRun: boolean): Promise<string[]> {\n if (candidates.length === 0) {\n return [];\n }\n\n // In dry-run mode, return all candidates (caller logs but won't delete)\n if (dryRun) {\n return candidates;\n }\n\n // In force mode, delete without prompting\n if (force) {\n return candidates;\n }\n\n // Prompt user with multi-select (all selected by default, red checkboxes)\n const selected = await deleteMultiselect({\n message:\n '⚠ WARNING: The selected files will be PERMANENTLY DELETED from disk.\\n' +\n ' Deselect any files you want to keep. Press Enter to confirm deletion:',\n options: candidates.map((p) => ({\n value: p,\n label: p,\n })),\n initialValues: candidates,\n required: false,\n });\n\n // Handle user cancellation (Ctrl+C)\n if (isCancel(selected)) {\n process.exit(1);\n }\n\n return selected as string[];\n }\n}\n\nexport const deleteResolver = new DeleteResolver();\n","// @awa-component: TPL-TemplateEngine\n// @awa-impl: TPL-4_AC-1\n// @awa-impl: TPL-4_AC-2\n// @awa-impl: TPL-4_AC-3\n// @awa-impl: TPL-4_AC-4\n// @awa-impl: TPL-5_AC-1\n// @awa-impl: TPL-5_AC-2\n// @awa-impl: TPL-5_AC-3\n// @awa-impl: TPL-6_AC-1\n// @awa-impl: TPL-6_AC-2\n// @awa-impl: TPL-7_AC-1\n// @awa-impl: TPL-7_AC-2\n// @awa-impl: TPL-8_AC-1\n// @awa-impl: TPL-8_AC-2\n// @awa-impl: TPL-8_AC-3\n// @awa-impl: TPL-8_AC-4\n// @awa-impl: TPL-11_AC-1\n// @awa-impl: TPL-11_AC-2\n\nimport { Eta } from 'eta';\n\nimport { type RenderResult, type TemplateContext, TemplateError } from '../types/index.js';\nimport { readTextFile } from '../utils/fs.js';\n\nconst EMPTY_FILE_MARKER = '<!-- AWA:EMPTY_FILE -->';\n\nexport class TemplateEngine {\n private eta: Eta | null = null;\n private templateDir: string | null = null;\n\n // @awa-impl: TPL-8_AC-1, TPL-8_AC-2, TPL-8_AC-3, TPL-8_AC-4\n configure(templateDir: string): void {\n this.templateDir = templateDir;\n\n // @awa-impl: TPL-4_AC-1, TPL-4_AC-2, TPL-4_AC-3, TPL-4_AC-4\n // Configure Eta with partials support\n this.eta = new Eta({\n views: templateDir,\n cache: true, // Enable compilation caching\n autoEscape: false, // Don't escape HTML by default\n defaultExtension: '', // No automatic extension - use exact path as specified (AC-8.2)\n });\n }\n\n // @awa-impl: TPL-5_AC-1, TPL-5_AC-2, TPL-5_AC-3\n // @awa-impl: TPL-6_AC-1, TPL-6_AC-2\n // @awa-impl: TPL-7_AC-1, TPL-7_AC-2\n // @awa-impl: TPL-11_AC-1, TPL-11_AC-2\n async render(templatePath: string, context: TemplateContext): Promise<RenderResult> {\n if (!this.eta || !this.templateDir) {\n throw new TemplateError(\n 'Template engine not configured. Call configure() first.',\n 'RENDER_ERROR',\n );\n }\n\n try {\n // Read template content\n const templateContent = await readTextFile(templatePath);\n\n // Render with features context\n // The context is available as 'it' in templates\n const rendered = await this.eta.renderStringAsync(templateContent, {\n features: context.features,\n version: context.version ?? '',\n });\n\n // Check if output is empty or only whitespace\n const trimmed = rendered.trim();\n const isEmpty = trimmed.length === 0;\n\n // Check for empty file marker\n const isEmptyFileMarker = trimmed === EMPTY_FILE_MARKER;\n\n return {\n content: rendered,\n isEmpty,\n isEmptyFileMarker,\n };\n } catch (error) {\n throw new TemplateError(\n `Failed to render template ${templatePath}: ${error instanceof Error ? error.message : String(error)}`,\n 'RENDER_ERROR',\n templatePath,\n );\n }\n }\n}\n\nexport const templateEngine = new TemplateEngine();\n","// @awa-component: FP-FeatureResolver\n// @awa-impl: CFG-8_AC-3\n// @awa-impl: CFG-10_AC-4\n// @awa-impl: CFG-12_AC-1\n// @awa-impl: CFG-12_AC-2\n// @awa-impl: CFG-12_AC-3\n// @awa-impl: CFG-12_AC-4\n// @awa-impl: CFG-12_AC-5\n// @awa-impl: CFG-13_AC-1\n// @awa-impl: CFG-13_AC-2\n\nimport { ConfigError, type PresetDefinitions } from '../types/index.js';\n\nexport interface FeatureResolutionInput {\n baseFeatures: string[];\n presetNames: string[];\n removeFeatures: string[];\n presetDefinitions: PresetDefinitions;\n}\n\nexport class FeatureResolver {\n validatePresets(presetNames: string[], definitions: PresetDefinitions): void {\n for (const name of presetNames) {\n if (!definitions[name]) {\n throw new ConfigError(`Unknown preset: ${name}`, 'UNKNOWN_PRESET');\n }\n }\n }\n\n resolve(input: FeatureResolutionInput): string[] {\n const { baseFeatures, presetNames, removeFeatures, presetDefinitions } = input;\n\n this.validatePresets(presetNames, presetDefinitions);\n\n const finalFeatures: string[] = [];\n const seen = new Set<string>();\n\n const add = (feature: string) => {\n if (seen.has(feature)) return;\n seen.add(feature);\n finalFeatures.push(feature);\n };\n\n for (const feature of baseFeatures) add(feature);\n\n for (const presetName of presetNames) {\n for (const feature of presetDefinitions[presetName] ?? []) add(feature);\n }\n\n if (removeFeatures.length === 0) return finalFeatures;\n\n const removeSet = new Set(removeFeatures);\n return finalFeatures.filter((f) => !removeSet.has(f));\n }\n}\n\nexport const featureResolver = new FeatureResolver();\n","// @awa-component: JSON-JsonSerializer\n// @awa-impl: JSON-1_AC-1\n// @awa-impl: JSON-2_AC-1\n// @awa-impl: JSON-3_AC-1\n// @awa-impl: JSON-4_AC-1\n// @awa-impl: JSON-5_AC-1\n// @awa-impl: JSON-8_AC-1\n\nimport type {\n DiffFileJSON,\n DiffJSON,\n DiffResult,\n GenerationActionJSON,\n GenerationJSON,\n GenerationResult,\n} from '../types/index.js';\n\n// @awa-impl: JSON-1_AC-1, JSON-3_AC-1\nexport function serializeGenerationResult(result: GenerationResult): GenerationJSON {\n const actions: GenerationActionJSON[] = result.actions.map((action) => ({\n type: action.type,\n path: action.outputPath,\n }));\n\n return {\n actions,\n counts: {\n created: result.created,\n overwritten: result.overwritten,\n skipped: result.skipped,\n deleted: result.deleted,\n },\n };\n}\n\n// @awa-impl: JSON-2_AC-1, JSON-4_AC-1\nexport function serializeDiffResult(result: DiffResult): DiffJSON {\n const diffs: DiffFileJSON[] = result.files.map((file) => {\n const entry: DiffFileJSON = {\n path: file.relativePath,\n status: file.status,\n };\n if (file.unifiedDiff) {\n entry.diff = file.unifiedDiff;\n }\n return entry;\n });\n\n return {\n diffs,\n counts: {\n changed: result.modified,\n new: result.newFiles,\n matching: result.identical,\n deleted: result.deleteListed,\n },\n };\n}\n\n// @awa-impl: JSON-5_AC-1\nexport function formatGenerationSummary(result: GenerationResult): string {\n return `created: ${result.created}, overwritten: ${result.overwritten}, skipped: ${result.skipped}, deleted: ${result.deleted}`;\n}\n\n// @awa-impl: JSON-5_AC-1\nexport function formatDiffSummary(result: DiffResult): string {\n return `changed: ${result.modified}, new: ${result.newFiles}, matching: ${result.identical}, deleted: ${result.deleteListed}`;\n}\n\n// @awa-impl: JSON-8_AC-1\nexport function writeJsonOutput(data: GenerationJSON | DiffJSON): void {\n process.stdout.write(`${JSON.stringify(data, null, 2)}\\n`);\n}\n","// @awa-component: OVL-OverlayResolver\n// @awa-component: OVL-MergedTemplateView\n// @awa-impl: OVL-1_AC-1\n// @awa-impl: OVL-2_AC-1\n// @awa-impl: OVL-3_AC-1\n// @awa-impl: OVL-4_AC-1\n// @awa-impl: OVL-5_AC-1\n// @awa-impl: OVL-6_AC-1\n\nimport { cp } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\n\nimport { ensureDir } from '../utils/fs.js';\nimport { templateResolver } from './template-resolver.js';\n\n/**\n * Resolve each overlay source string to a local directory path.\n * Delegates to TemplateResolver so local paths and Git sources are both handled.\n *\n * @awa-impl: OVL-1_AC-1, OVL-6_AC-1\n */\nexport async function resolveOverlays(overlays: string[], refresh: boolean): Promise<string[]> {\n const dirs: string[] = [];\n for (const source of overlays) {\n const resolved = await templateResolver.resolve(source, refresh);\n dirs.push(resolved.localPath);\n }\n return dirs;\n}\n\n/**\n * Build a temporary merged directory by copying baseDir then applying each\n * overlay in order. Later overlay files overwrite earlier ones at the same\n * relative path; base-only files are left intact; overlay-only files are added.\n *\n * Caller is responsible for cleaning up the returned temp directory.\n *\n * @awa-impl: OVL-2_AC-1, OVL-3_AC-1, OVL-4_AC-1, OVL-5_AC-1\n */\nexport async function buildMergedDir(baseDir: string, overlayDirs: string[]): Promise<string> {\n const timestamp = Date.now();\n const random = Math.random().toString(36).substring(2, 8);\n const tempPath = join(tmpdir(), `awa-overlay-${timestamp}-${random}`);\n\n await ensureDir(tempPath);\n\n // Copy base template files into the temp directory\n await cp(baseDir, tempPath, { recursive: true });\n\n // Apply overlays in order — later overlays win (force: true is the default for fs.cp)\n for (const overlayDir of overlayDirs) {\n await cp(overlayDir, tempPath, { recursive: true });\n }\n\n return tempPath;\n}\n","// @awa-component: TPL-TemplateResolver\n// @awa-impl: CLI-3_AC-2\n// @awa-impl: CLI-3_AC-3\n// @awa-impl: CLI-8_AC-2\n// @awa-impl: TPL-1_AC-1\n// @awa-impl: TPL-1_AC-2\n// @awa-impl: TPL-1_AC-3\n// @awa-impl: TPL-1_AC-4\n// @awa-impl: TPL-2_AC-1\n// @awa-impl: TPL-2_AC-2\n// @awa-impl: TPL-2_AC-3\n// @awa-impl: TPL-2_AC-4\n// @awa-impl: TPL-2_AC-5\n// @awa-impl: TPL-2_AC-6\n// @awa-impl: TPL-3_AC-1\n// @awa-impl: TPL-3_AC-2\n// @awa-impl: TPL-3_AC-3\n// @awa-impl: TPL-3_AC-4\n// @awa-impl: TPL-10_AC-1\n// @awa-impl: TPL-10_AC-2\n// @awa-impl: TPL-10_AC-3\n\nimport { createHash } from 'node:crypto';\nimport { rm } from 'node:fs/promises';\nimport { isAbsolute, join, resolve } from 'node:path';\n\nimport degit from 'degit';\n\nimport { type ResolvedTemplate, TemplateError, type TemplateSourceType } from '../types/index.js';\nimport { ensureDir, getCacheDir, getTemplateDir, pathExists } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\nexport class TemplateResolver {\n // @awa-impl: CLI-3_AC-2, TPL-10_AC-1\n async resolve(source: string | null, refresh: boolean): Promise<ResolvedTemplate> {\n // If no source provided, use bundled templates\n if (!source) {\n const bundledPath = join(getTemplateDir(), 'awa');\n return {\n type: 'bundled',\n localPath: bundledPath,\n source: 'bundled',\n };\n }\n\n const type = this.detectType(source);\n\n // @awa-impl: TPL-1_AC-1, TPL-1_AC-2, TPL-1_AC-3, TPL-1_AC-4\n if (type === 'local') {\n // Resolve relative/absolute paths\n const localPath = isAbsolute(source) ? source : resolve(process.cwd(), source);\n\n // Check if path exists\n if (!(await pathExists(localPath))) {\n throw new TemplateError(\n `Template source not found: ${localPath}`,\n 'SOURCE_NOT_FOUND',\n source,\n );\n }\n\n // Local templates are not cached\n return {\n type: 'local',\n localPath,\n source,\n };\n }\n\n // @awa-impl: TPL-2_AC-1, TPL-2_AC-2, TPL-2_AC-3, TPL-2_AC-4, TPL-2_AC-5, TPL-2_AC-6, TPL-3_AC-1, TPL-3_AC-2, TPL-3_AC-3, TPL-3_AC-4\n if (type === 'git') {\n const cachePath = this.getCachePath(source);\n\n // @awa-impl: CLI-8_AC-2, TPL-3_AC-2\n // Check if cached version exists\n const cacheExists = await pathExists(cachePath);\n\n if (cacheExists && !refresh) {\n // Use cached version\n logger.info(`Using cached template: ${source}`);\n return {\n type: 'git',\n localPath: cachePath,\n source,\n };\n }\n\n // Fetch from Git\n try {\n // Remove existing cache if refresh\n if (cacheExists && refresh) {\n logger.info(`Refreshing template: ${source}`);\n await rm(cachePath, { recursive: true, force: true });\n } else {\n logger.info(`Fetching template: ${source}`);\n }\n\n await ensureDir(cachePath);\n\n // Use degit for shallow fetch\n const emitter = degit(source, { cache: false, force: true });\n await emitter.clone(cachePath);\n\n return {\n type: 'git',\n localPath: cachePath,\n source,\n };\n } catch (error) {\n throw new TemplateError(\n `Failed to fetch Git template: ${error instanceof Error ? error.message : String(error)}`,\n 'FETCH_FAILED',\n source,\n );\n }\n }\n\n throw new TemplateError(\n `Unable to resolve template source: ${source}`,\n 'SOURCE_NOT_FOUND',\n source,\n );\n }\n\n // @awa-impl: TPL-2_AC-1, TPL-2_AC-2, TPL-2_AC-3, TPL-2_AC-4, TPL-2_AC-5, TPL-2_AC-6\n detectType(source: string): TemplateSourceType {\n // Check for local path indicators\n if (source.startsWith('.') || source.startsWith('/') || source.startsWith('~')) {\n return 'local';\n }\n\n // Check for Windows absolute paths\n if (/^[a-zA-Z]:/.test(source)) {\n return 'local';\n }\n\n // All other formats are treated as Git sources:\n // - GitHub shorthand: owner/repo\n // - Prefixed: github:owner/repo, gitlab:owner/repo, bitbucket:owner/repo\n // - HTTPS: https://github.com/owner/repo\n // - SSH: git@github.com:owner/repo\n // - With subdirs: owner/repo/path/to/templates\n // - With refs: owner/repo#branch\n return 'git';\n }\n\n // @awa-impl: TPL-3_AC-1\n getCachePath(source: string): string {\n // Create a stable cache path based on source hash\n const hash = createHash('sha256').update(source).digest('hex').substring(0, 16);\n const cacheDir = getCacheDir();\n return join(cacheDir, hash);\n }\n}\n\nexport const templateResolver = new TemplateResolver();\n","// @awa-component: DIFF-FileWatcher\n// @awa-impl: DIFF-7_AC-10\n\nimport { type FSWatcher, watch } from 'node:fs';\n\nimport { Debouncer } from './debouncer.js';\n\nexport interface FileWatcherOptions {\n directory: string;\n debounceMs?: number;\n onChange: () => void;\n}\n\nexport class FileWatcher {\n private watcher: FSWatcher | null = null;\n private debouncer: Debouncer;\n private readonly directory: string;\n private readonly onChange: () => void;\n\n constructor(options: FileWatcherOptions) {\n this.directory = options.directory;\n this.debouncer = new Debouncer(options.debounceMs ?? 300);\n this.onChange = options.onChange;\n }\n\n start(): void {\n this.watcher = watch(this.directory, { recursive: true }, () => {\n this.debouncer.trigger(this.onChange);\n });\n }\n\n stop(): void {\n this.debouncer.cancel();\n if (this.watcher) {\n this.watcher.close();\n this.watcher = null;\n }\n }\n}\n","// @awa-component: DIFF-Debouncer\n// @awa-impl: DIFF-7_AC-10\n\nexport class Debouncer {\n private timer: ReturnType<typeof setTimeout> | null = null;\n\n constructor(private readonly delayMs: number) {}\n\n trigger(callback: () => void): void {\n if (this.timer) {\n clearTimeout(this.timer);\n }\n this.timer = setTimeout(() => {\n this.timer = null;\n callback();\n }, this.delayMs);\n }\n\n cancel(): void {\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n }\n}\n","// @awa-component: DISC-FeaturesCommand\n// @awa-impl: DISC-4_AC-1\n// @awa-impl: DISC-5_AC-1\n// @awa-impl: DISC-8_AC-1\n\nimport { intro, outro } from '@clack/prompts';\n\nimport { configLoader } from '../core/config.js';\nimport { featuresReporter } from '../core/features/reporter.js';\nimport { featureScanner } from '../core/features/scanner.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport { rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\nexport interface FeaturesCommandOptions {\n template?: string;\n config?: string;\n refresh?: boolean;\n json?: boolean;\n summary?: boolean;\n overlay?: string[];\n}\n\n// @awa-impl: DISC-4_AC-1, DISC-5_AC-1\nexport async function featuresCommand(cliOptions: FeaturesCommandOptions): Promise<number> {\n let mergedDir: string | null = null;\n\n try {\n const silent = cliOptions.json || cliOptions.summary;\n\n if (!silent) {\n intro('awa CLI - Feature Discovery');\n }\n\n // Load configuration file (for presets and default template)\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // Resolve template source — reuse same resolver as generate/diff\n const templateSource = cliOptions.template ?? fileConfig?.template ?? null;\n const refresh = cliOptions.refresh ?? fileConfig?.refresh ?? false;\n const template = await templateResolver.resolve(templateSource, refresh);\n\n // Build merged dir if overlays are specified\n const overlays = cliOptions.overlay ?? fileConfig?.overlay ?? [];\n let templatePath = template.localPath;\n if (overlays.length > 0) {\n const overlayDirs = await resolveOverlays(overlays, refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n // Scan template for feature flags\n const scanResult = await featureScanner.scan(templatePath);\n\n // Retrieve preset definitions from config if available\n const presets = fileConfig?.presets;\n\n // Report results\n if (cliOptions.summary) {\n console.log(\n `features: ${scanResult.features.length}, files-scanned: ${scanResult.filesScanned}`,\n );\n } else {\n featuresReporter.report({\n scanResult,\n json: cliOptions.json ?? false,\n presets,\n });\n }\n\n if (!silent) {\n outro('Feature discovery complete!');\n }\n\n return 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 1;\n } finally {\n if (mergedDir) {\n await rmDir(mergedDir);\n }\n }\n}\n","// @awa-component: DISC-Reporter\n// @awa-impl: DISC-6_AC-1\n// @awa-impl: DISC-7_AC-1\n// @awa-impl: DISC-9_AC-1\n\nimport chalk from 'chalk';\n\nimport type { PresetDefinitions } from '../../types/index.js';\nimport type { ScanResult } from './scanner.js';\n\n/** Options for rendering the features report. */\nexport interface ReportOptions {\n /** Scan results from the feature scanner. */\n scanResult: ScanResult;\n /** Whether to output JSON instead of a human-readable table. */\n json: boolean;\n /** Preset definitions from the user's .awa.toml, if available. */\n presets?: PresetDefinitions;\n}\n\n/** JSON output structure for --json mode. */\nexport interface FeaturesJsonOutput {\n features: Array<{\n name: string;\n files: string[];\n }>;\n presets?: Record<string, string[]>;\n filesScanned: number;\n}\n\nexport class FeaturesReporter {\n // @awa-impl: DISC-6_AC-1, DISC-7_AC-1\n /** Render the features report to stdout. */\n report(options: ReportOptions): void {\n const { scanResult, json, presets } = options;\n\n if (json) {\n this.reportJson(scanResult, presets);\n } else {\n this.reportTable(scanResult, presets);\n }\n }\n\n // @awa-impl: DISC-6_AC-1\n /** Build the JSON output object (also used by tests). */\n buildJsonOutput(scanResult: ScanResult, presets?: PresetDefinitions): FeaturesJsonOutput {\n const output: FeaturesJsonOutput = {\n features: scanResult.features.map((f) => ({\n name: f.name,\n files: f.files,\n })),\n filesScanned: scanResult.filesScanned,\n };\n\n if (presets && Object.keys(presets).length > 0) {\n output.presets = presets;\n }\n\n return output;\n }\n\n private reportJson(scanResult: ScanResult, presets?: PresetDefinitions): void {\n const output = this.buildJsonOutput(scanResult, presets);\n console.log(JSON.stringify(output, null, 2));\n }\n\n // @awa-impl: DISC-7_AC-1\n private reportTable(scanResult: ScanResult, presets?: PresetDefinitions): void {\n const { features, filesScanned } = scanResult;\n\n if (features.length === 0) {\n console.log(chalk.yellow('No feature flags found.'));\n console.log(chalk.dim(`(${filesScanned} files scanned)`));\n return;\n }\n\n console.log(chalk.bold(`Feature flags (${features.length} found):\\n`));\n\n for (const feature of features) {\n console.log(` ${chalk.cyan(feature.name)}`);\n for (const file of feature.files) {\n console.log(` ${chalk.dim(file)}`);\n }\n }\n\n console.log('');\n console.log(chalk.dim(`${filesScanned} files scanned`));\n\n // Show presets if available\n if (presets && Object.keys(presets).length > 0) {\n console.log('');\n console.log(chalk.bold('Presets (from .awa.toml):\\n'));\n for (const [name, flags] of Object.entries(presets)) {\n console.log(` ${chalk.green(name)}: ${flags.join(', ')}`);\n }\n }\n }\n}\n\nexport const featuresReporter = new FeaturesReporter();\n","// @awa-component: DISC-FeatureScanner\n// @awa-impl: DISC-1_AC-1\n// @awa-impl: DISC-2_AC-1\n// @awa-impl: DISC-3_AC-1\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\n\n/** A single feature flag discovered in a template. */\nexport interface DiscoveredFeature {\n /** The flag name (e.g. \"copilot\"). */\n name: string;\n /** Relative paths of template files that reference this flag. */\n files: string[];\n}\n\n/** Result of scanning a template directory for feature flags. */\nexport interface ScanResult {\n /** All discovered feature flags, sorted by name. */\n features: DiscoveredFeature[];\n /** Total number of template files scanned. */\n filesScanned: number;\n}\n\n// Matches: it.features.includes('name') or it.features.includes(\"name\")\n// Also matches: it.features.indexOf('name') or it.features.indexOf(\"name\")\nconst FEATURE_PATTERN = /it\\.features\\.(?:includes|indexOf)\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g;\n\n/**\n * Recursively walk a directory yielding all file paths (including those\n * starting with underscore, since partials may reference feature flags).\n */\nasync function* walkAllFiles(dir: string): AsyncGenerator<string> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n yield* walkAllFiles(fullPath);\n } else if (entry.isFile()) {\n yield fullPath;\n }\n }\n}\n\nexport class FeatureScanner {\n // @awa-impl: DISC-1_AC-1, DISC-2_AC-1\n /** Extract feature flag names from a single file's content. */\n extractFlags(content: string): string[] {\n const flags = new Set<string>();\n for (const match of content.matchAll(FEATURE_PATTERN)) {\n if (match[1]) {\n flags.add(match[1]);\n }\n }\n return [...flags];\n }\n\n // @awa-impl: DISC-1_AC-1, DISC-2_AC-1, DISC-3_AC-1\n /** Scan a template directory and return all discovered feature flags. */\n async scan(templatePath: string): Promise<ScanResult> {\n const flagToFiles = new Map<string, Set<string>>();\n let filesScanned = 0;\n\n for await (const filePath of walkAllFiles(templatePath)) {\n filesScanned++;\n try {\n const content = await readFile(filePath, 'utf-8');\n const flags = this.extractFlags(content);\n const relPath = relative(templatePath, filePath);\n for (const flag of flags) {\n const existing = flagToFiles.get(flag);\n if (existing) {\n existing.add(relPath);\n } else {\n flagToFiles.set(flag, new Set([relPath]));\n }\n }\n } catch {\n // Skip binary files or files that can't be read as UTF-8\n }\n }\n\n const features: DiscoveredFeature[] = [...flagToFiles.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, files]) => ({\n name,\n files: [...files].sort(),\n }));\n\n return { features, filesScanned };\n }\n}\n\nexport const featureScanner = new FeatureScanner();\n","// @awa-component: GEN-GenerateCommand\n// @awa-component: JSON-GenerateCommand\n// @awa-component: GEN-ConfigHint\n// @awa-component: MULTI-GenerateCommand\n// @awa-impl: GEN-17_AC-1\n// @awa-impl: MULTI-6_AC-1\n// @awa-impl: MULTI-10_AC-1\n// @awa-impl: CLI-16_AC-2\n// @awa-impl: CLI-16_AC-3\n// @awa-impl: CLI-20_AC-2\n// @awa-impl: CLI-20_AC-3\n\nimport { intro, isCancel, multiselect, outro } from '@clack/prompts';\n\nimport { batchRunner } from '../core/batch-runner.js';\nimport { configLoader } from '../core/config.js';\nimport { featureResolver } from '../core/feature-resolver.js';\nimport { fileGenerator } from '../core/generator.js';\nimport {\n formatGenerationSummary,\n serializeGenerationResult,\n writeJsonOutput,\n} from '../core/json-output.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport type { RawCliOptions, ResolvedOptions } from '../types/index.js';\nimport { rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\n/** Known AI tool feature flags for interactive selection. */\nconst TOOL_FEATURES = [\n { value: 'copilot', label: 'GitHub Copilot' },\n { value: 'claude', label: 'Claude Code' },\n { value: 'cursor', label: 'Cursor' },\n { value: 'windsurf', label: 'Windsurf' },\n { value: 'kilocode', label: 'Kilocode' },\n { value: 'opencode', label: 'OpenCode' },\n { value: 'gemini', label: 'Gemini CLI' },\n { value: 'roo', label: 'Roo Code' },\n { value: 'qwen', label: 'Qwen Code' },\n { value: 'codex', label: 'Codex CLI' },\n { value: 'agy', label: 'Antigravity (agy)' },\n { value: 'agents-md', label: 'AGENTS.md (cross-tool)' },\n] as const;\n\nconst TOOL_FEATURE_VALUES = new Set<string>(TOOL_FEATURES.map((t) => t.value));\n\nasync function runGenerate(options: ResolvedOptions, batchMode: boolean): Promise<void> {\n const silent = options.json || options.summary;\n\n // Resolve template source\n const template = await templateResolver.resolve(options.template, options.refresh);\n\n const features = featureResolver.resolve({\n baseFeatures: [...options.features],\n presetNames: [...options.preset],\n removeFeatures: [...options.removeFeatures],\n presetDefinitions: options.presets,\n });\n\n // @awa-impl: MTT-1_AC-1 // @awa-ignore\n // If no tool feature flag is present, prompt the user to select tools interactively\n // In batch mode (--all / --target), skip prompting\n // @awa-impl: JSON-6_AC-1\n if (!batchMode) {\n const hasToolFlag = features.some((f) => TOOL_FEATURE_VALUES.has(f));\n if (!hasToolFlag && !silent) {\n const selected = await multiselect({\n message: 'Select AI tools to generate for (space to toggle, enter to confirm):',\n options: TOOL_FEATURES.map((t) => ({ value: t.value, label: t.label })),\n required: true,\n });\n if (isCancel(selected)) {\n logger.info('Generation cancelled.');\n process.exit(0);\n }\n features.push(...(selected as string[]));\n }\n }\n\n // @awa-impl: JSON-7_AC-1\n // --json implies --dry-run for generate\n const effectiveDryRun = options.json || options.dryRun;\n\n // Display mode indicators\n if (!silent) {\n if (effectiveDryRun) {\n logger.info('Running in dry-run mode (no files will be modified)');\n }\n if (options.force) {\n logger.info('Force mode enabled (existing files will be overwritten)');\n }\n }\n\n // @awa-impl: OVL-2_AC-1\n // Build merged template dir if overlays are specified\n let mergedDir: string | null = null;\n let templatePath = template.localPath;\n if (options.overlay.length > 0) {\n const overlayDirs = await resolveOverlays([...options.overlay], options.refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n try {\n // Generate files\n const result = await fileGenerator.generate({\n templatePath,\n outputPath: options.output,\n features,\n force: options.force,\n dryRun: effectiveDryRun,\n delete: options.delete,\n });\n\n // @awa-impl: JSON-1_AC-1, JSON-8_AC-1\n if (options.json) {\n writeJsonOutput(serializeGenerationResult(result));\n } else if (options.summary) {\n // @awa-impl: JSON-5_AC-1\n console.log(formatGenerationSummary(result));\n } else {\n // Display summary\n logger.summary(result);\n }\n } finally {\n // Clean up merged overlay temp directory\n if (mergedDir) {\n try {\n await rmDir(mergedDir);\n } catch {\n // Swallow cleanup errors — temp dir will be cleaned by OS eventually\n }\n }\n }\n}\n\nexport async function generateCommand(cliOptions: RawCliOptions): Promise<void> {\n try {\n // Load configuration file\n const fileConfig = await configLoader.load(cliOptions.config ?? null);\n\n // @awa-impl: GEN-17_AC-1\n // Non-blocking hint when no config file is present and --config was not provided\n if (!cliOptions.config && fileConfig === null) {\n logger.info('Tip: create .awa.toml to save your options for next time.');\n }\n\n // Batch mode: --all or --target\n if (cliOptions.allTargets || cliOptions.target) {\n const mode = cliOptions.allTargets ? 'all' : 'single';\n const targets = batchRunner.resolveTargets(cliOptions, fileConfig, mode, cliOptions.target);\n\n for (const { targetName, options } of targets) {\n batchRunner.logForTarget(targetName, 'Starting generation...');\n await runGenerate(options, true);\n batchRunner.logForTarget(targetName, 'Generation complete.');\n }\n\n outro('All targets generated!');\n return;\n }\n\n // Standard single-target mode (backward compatible)\n const options = configLoader.merge(cliOptions, fileConfig);\n\n const silent = options.json || options.summary;\n\n // @awa-impl: JSON-6_AC-1\n // Suppress interactive output when --json or --summary is active\n if (!silent) {\n intro('awa CLI - Template Generator');\n }\n\n await runGenerate(options, false);\n\n if (!silent) {\n outro('Generation complete!');\n }\n } catch (error) {\n // @awa-impl: JSON-8_AC-1\n // Error handling with proper exit codes — errors always go to stderr\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n process.exit(1);\n }\n}\n","import { readFile, rename, writeFile } from 'node:fs/promises';\nimport { basename, dirname, extname, join } from 'node:path';\n\nimport type { SpecFile } from '../check/types.js';\nimport type { FileMove } from './types.js';\n\n/** File type prefixes handled by merge. */\nconst MERGE_PREFIXES = ['FEAT', 'REQ', 'DESIGN', 'API', 'EXAMPLE', 'TASK'] as const;\n\n/**\n * Compute a conflict-free target path by replacing only the code in the filename.\n * If the resulting path collides with an existing file or an already-planned move,\n * appends an incrementing index (`-001`, `-002`, …) before the extension.\n */\nexport function resolveMovePath(\n sourceFilePath: string,\n prefix: string,\n sourceCode: string,\n targetCode: string,\n existingPaths: ReadonlySet<string>,\n plannedPaths: ReadonlySet<string>,\n): string {\n const dir = dirname(sourceFilePath);\n const name = basename(sourceFilePath);\n const newName = name.replace(`${prefix}-${sourceCode}-`, `${prefix}-${targetCode}-`);\n const newPath = join(dir, newName);\n\n if (!existingPaths.has(newPath) && !plannedPaths.has(newPath)) {\n return newPath;\n }\n\n // Conflict — add incrementing numeric suffix before the extension\n const ext = extname(newName);\n const stem = newName.slice(0, -ext.length);\n\n for (let i = 1; i < 1000; i++) {\n const indexed = join(dir, `${stem}-${String(i).padStart(3, '0')}${ext}`);\n if (!existingPaths.has(indexed) && !plannedPaths.has(indexed)) {\n return indexed;\n }\n }\n\n // Should never happen in practice\n throw new Error(`Cannot resolve conflict for ${sourceFilePath}`);\n}\n\n/**\n * Update the H1 heading in a spec file, replacing the source code with the target code.\n * Only the first H1 heading is modified; body content is left unchanged.\n */\nexport function updateHeading(content: string, sourceCode: string, targetCode: string): string {\n const lines = content.split('\\n');\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] as string;\n if (/^#\\s/.test(line)) {\n lines[i] = line.replaceAll(sourceCode, targetCode);\n break;\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Execute all file moves: for each source file matching MERGE_PREFIXES,\n * rename it by replacing only the code portion of the filename.\n * If a conflict exists, an incrementing index suffix is added.\n * The H1 heading is also updated to reflect the new code.\n *\n * At this point, source file content has already been recoded by the propagator.\n */\nexport async function executeMoves(\n sourceCode: string,\n targetCode: string,\n specFiles: readonly SpecFile[],\n dryRun: boolean,\n): Promise<FileMove[]> {\n const moves: FileMove[] = [];\n\n // Build set of all existing paths (excluding source files that will be moved)\n const sourceFilePaths = new Set<string>();\n for (const sf of specFiles) {\n const name = basename(sf.filePath);\n for (const prefix of MERGE_PREFIXES) {\n if (name.startsWith(`${prefix}-${sourceCode}-`)) {\n sourceFilePaths.add(sf.filePath);\n break;\n }\n }\n }\n\n const existingPaths = new Set(\n specFiles.map((sf) => sf.filePath).filter((p) => !sourceFilePaths.has(p)),\n );\n const plannedPaths = new Set<string>();\n\n for (const sf of specFiles) {\n const name = basename(sf.filePath);\n let matchedPrefix = '';\n for (const prefix of MERGE_PREFIXES) {\n if (name.startsWith(`${prefix}-${sourceCode}-`)) {\n matchedPrefix = prefix;\n break;\n }\n }\n if (!matchedPrefix) continue;\n\n const targetPath = resolveMovePath(\n sf.filePath,\n matchedPrefix,\n sourceCode,\n targetCode,\n existingPaths,\n plannedPaths,\n );\n\n plannedPaths.add(targetPath);\n\n moves.push({\n sourceFile: sf.filePath,\n targetFile: targetPath,\n docType: matchedPrefix,\n });\n\n if (!dryRun) {\n // Read, update heading, rename\n const content = await readFile(sf.filePath, 'utf-8');\n const updated = updateHeading(content, sourceCode, targetCode);\n\n await rename(sf.filePath, targetPath);\n\n // If heading was updated, write the new content back\n if (updated !== content) {\n await writeFile(targetPath, updated, 'utf-8');\n }\n }\n }\n\n return moves;\n}\n","import type { MergeResult } from './types.js';\n\n/**\n * Format merge results as human-readable text.\n * Shows sections: ID remap table, file appends, affected files, stale refs.\n */\nexport function formatText(result: MergeResult, dryRun: boolean): string {\n const lines: string[] = [];\n\n if (dryRun) {\n lines.push('DRY RUN — no files were modified\\n');\n }\n\n if (result.noChange) {\n lines.push(`${result.sourceCode} → ${result.targetCode}: nothing to merge`);\n return lines.join('\\n');\n }\n\n // Section 1: ID remap table\n lines.push(\n `${result.sourceCode} → ${result.targetCode}: ${result.map.entries.size} ID(s) recoded\\n`,\n );\n if (result.map.entries.size > 0) {\n lines.push(' Old ID → New ID');\n lines.push(` ${'─'.repeat(40)}`);\n for (const [oldId, newId] of result.map.entries) {\n lines.push(` ${oldId} → ${newId}`);\n }\n }\n\n // Section 2: File moves\n if (result.moves.length > 0) {\n lines.push('');\n lines.push(` ${result.moves.length} file(s) moved:`);\n for (const m of result.moves) {\n lines.push(` ${m.sourceFile} → ${m.targetFile} (${m.docType})`);\n }\n }\n\n // Affected files from recode propagation\n if (result.affectedFiles.length > 0) {\n lines.push('');\n lines.push(\n ` ${result.totalReplacements} replacement(s) in ${result.affectedFiles.length} file(s):`,\n );\n for (const file of result.affectedFiles) {\n lines.push(` ${file.filePath} (${file.replacements.length})`);\n }\n }\n\n // Stale references (errors)\n if (result.staleRefs.length > 0) {\n lines.push('');\n lines.push(` ✖ ${result.staleRefs.length} file(s) still reference ${result.sourceCode}:`);\n for (const ref of result.staleRefs) {\n lines.push(` ${ref}`);\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Format merge results as JSON for CI consumption.\n */\nexport function formatJson(result: MergeResult): string {\n const output = {\n sourceCode: result.sourceCode,\n targetCode: result.targetCode,\n noChange: result.noChange,\n map: Object.fromEntries(result.map.entries),\n moves: result.moves.map((m) => ({\n sourceFile: m.sourceFile,\n targetFile: m.targetFile,\n docType: m.docType,\n })),\n staleRefs: result.staleRefs,\n affectedFiles: result.affectedFiles.map((f) => ({\n filePath: f.filePath,\n replacements: f.replacements.map((r) => ({\n line: r.line,\n oldId: r.oldId,\n newId: r.newId,\n })),\n })),\n totalReplacements: result.totalReplacements,\n };\n\n return JSON.stringify(output, null, 2);\n}\n","import { readFile, rename } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\n\nimport type { SpecFile } from '../check/types.js';\nimport type { FileRename } from '../recode/types.js';\nimport { MergeError } from './types.js';\n\n/** Spec file prefixes that include the feature code in their filename. */\nconst CODE_PREFIXES = ['REQ', 'DESIGN', 'FEAT', 'TASK', 'EXAMPLE'] as const;\n\n/**\n * Resolve the feature-name slug for a code from its first REQ file.\n * e.g. code CLI with file REQ-CLI-cli.md → \"cli\"\n */\nexport function resolveFeatureName(\n code: string,\n specFiles: readonly SpecFile[],\n): string | undefined {\n for (const sf of specFiles) {\n const name = basename(sf.filePath, '.md');\n const match = new RegExp(`^REQ-${code}-(.+)$`).exec(name);\n if (match?.[1]) return match[1];\n }\n return undefined;\n}\n\n/**\n * Compute file renames for all spec files belonging to sourceCode.\n * Uses the target code's feature name for the renamed files.\n * Returns the list of planned renames without executing them.\n */\nexport function planRenames(\n sourceCode: string,\n targetCode: string,\n specFiles: readonly SpecFile[],\n): FileRename[] {\n const targetFeature = resolveFeatureName(targetCode, specFiles);\n const renames: FileRename[] = [];\n\n for (const sf of specFiles) {\n const name = basename(sf.filePath);\n for (const prefix of CODE_PREFIXES) {\n const oldPrefix = `${prefix}-${sourceCode}-`;\n if (name.startsWith(oldPrefix)) {\n const oldSuffix = name.slice(oldPrefix.length);\n // Replace the feature-name part with the target's feature name\n const newSuffix = targetFeature ? replaceFeaturePart(oldSuffix, targetFeature) : oldSuffix;\n const newName = `${prefix}-${targetCode}-${newSuffix}`;\n const newPath = join(dirname(sf.filePath), newName);\n renames.push({ oldPath: sf.filePath, newPath });\n break;\n }\n }\n }\n\n return renames;\n}\n\n/**\n * Replace the feature-name part of a suffix with a new feature name.\n * e.g. \"check.md\" → \"cli.md\", \"check-001.md\" → \"cli-001.md\"\n */\nfunction replaceFeaturePart(suffix: string, targetFeature: string): string {\n // Suffix patterns: \"feature-name.md\" or \"feature-name-NNN.md\"\n const numericMatch = /^(.+)-(\\d+\\.md)$/.exec(suffix);\n if (numericMatch) {\n return `${targetFeature}-${numericMatch[2]}`;\n }\n // Simple case: \"feature-name.md\"\n if (suffix.endsWith('.md')) {\n return `${targetFeature}.md`;\n }\n return suffix;\n}\n\n/**\n * Check for rename conflicts — target filenames that already exist.\n * Returns paths that would collide.\n */\nexport function detectConflicts(\n renames: readonly FileRename[],\n specFiles: readonly SpecFile[],\n): string[] {\n const existingPaths = new Set(specFiles.map((sf) => sf.filePath));\n const conflicts: string[] = [];\n\n for (const r of renames) {\n if (existingPaths.has(r.newPath)) {\n conflicts.push(r.newPath);\n }\n }\n\n return conflicts;\n}\n\n/**\n * Update the H1 heading in a spec file if it contains the old code name.\n * Returns the updated content.\n */\nexport function updateHeading(content: string, sourceCode: string, targetCode: string): string {\n const lines = content.split('\\n');\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] as string;\n // Match H1 heading: # Some Title\n if (/^#\\s/.test(line)) {\n // Replace occurrences of source code in the heading\n lines[i] = line.replaceAll(sourceCode, targetCode);\n break; // Only update the first H1\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Execute all planned renames: update headings and rename files.\n * In dry-run mode, returns the list without modifying the filesystem.\n */\nexport async function executeRenames(\n renames: readonly FileRename[],\n sourceCode: string,\n targetCode: string,\n dryRun: boolean,\n): Promise<readonly FileRename[]> {\n if (dryRun) return renames;\n\n for (const r of renames) {\n // Read and update heading\n const content = await readFile(r.oldPath, 'utf-8');\n const updated = updateHeading(content, sourceCode, targetCode);\n\n // Write updated content to new path via rename + write\n // Use fs.rename for atomic move on same filesystem\n await rename(r.oldPath, r.newPath);\n\n // If heading was updated, write the new content\n if (updated !== content) {\n const { writeFile } = await import('node:fs/promises');\n await writeFile(r.newPath, updated, 'utf-8');\n }\n }\n\n return renames;\n}\n\n/**\n * Delete the original source spec files (called after successful renames).\n * In dry-run mode, returns the planned deletions without executing.\n */\nexport async function deleteSourceFiles(\n _renames: readonly FileRename[],\n _dryRun: boolean,\n): Promise<readonly string[]> {\n // After rename, old files no longer exist — they were moved.\n // This function handles any remaining source files not covered by renames.\n // In practice, renames cover all source files, so this is a no-op.\n // Retained for extensibility.\n return [];\n}\n\n/**\n * Scan for stale references to the source code that weren't covered by recode.\n * Checks all spec files for any remaining `sourceCode-` prefixed IDs.\n */\nexport async function findStaleRefs(\n sourceCode: string,\n specFiles: readonly SpecFile[],\n): Promise<string[]> {\n const stale: string[] = [];\n const pattern = new RegExp(`\\\\b${sourceCode}-\\\\d`, 'g');\n\n for (const sf of specFiles) {\n let content: string;\n try {\n content = await readFile(sf.filePath, 'utf-8');\n } catch {\n continue;\n }\n if (pattern.test(content)) {\n stale.push(sf.filePath);\n }\n // Reset regex lastIndex for next iteration\n pattern.lastIndex = 0;\n }\n\n return stale;\n}\n\n/**\n * Validate merge preconditions.\n */\nexport function validateMerge(sourceCode: string, targetCode: string): void {\n if (sourceCode === targetCode) {\n throw new MergeError('SELF_MERGE', `Cannot merge a code into itself: ${sourceCode}`);\n }\n}\n","// Types shared across the merge module.\n\nimport type { AffectedFile, RenumberMap } from '../renumber/types.js';\n\n/**\n * A file move operation: source file renamed to target path (code changed).\n */\nexport interface FileMove {\n readonly sourceFile: string;\n readonly targetFile: string;\n readonly docType: string;\n}\n\n/**\n * Aggregated output of the merge pipeline.\n */\nexport interface MergeResult {\n readonly sourceCode: string;\n readonly targetCode: string;\n readonly map: RenumberMap;\n readonly affectedFiles: readonly AffectedFile[];\n readonly totalReplacements: number;\n readonly moves: readonly FileMove[];\n readonly staleRefs: readonly string[];\n readonly noChange: boolean;\n}\n\n/**\n * CLI options passed to the merge command.\n */\nexport interface MergeCommandOptions {\n readonly sourceCode: string;\n readonly targetCode: string;\n readonly dryRun?: boolean;\n readonly json?: boolean;\n readonly renumber?: boolean;\n readonly config?: string;\n}\n\n// --- Error types ---\n\nexport type MergeErrorCode = 'SOURCE_NOT_FOUND' | 'TARGET_NOT_FOUND' | 'SELF_MERGE';\n\nexport class MergeError extends Error {\n readonly errorCode: MergeErrorCode;\n\n constructor(errorCode: MergeErrorCode, message: string) {\n super(message);\n this.name = 'MergeError';\n this.errorCode = errorCode;\n }\n}\n","// Types shared across the recode module.\n// Components are declared in their respective implementation files.\n\nimport type { AffectedFile, RenumberMap } from '../renumber/types.js';\n\n/**\n * A file rename operation: old path → new path.\n */\nexport interface FileRename {\n readonly oldPath: string;\n readonly newPath: string;\n}\n\n/**\n * Aggregated output of the recode pipeline.\n */\nexport interface RecodeResult {\n readonly sourceCode: string;\n readonly targetCode: string;\n readonly map: RenumberMap;\n readonly affectedFiles: readonly AffectedFile[];\n readonly totalReplacements: number;\n readonly renames: readonly FileRename[];\n readonly staleRefs: readonly string[];\n readonly noChange: boolean;\n}\n\n/**\n * CLI options passed to the recode command.\n */\nexport interface RecodeCommandOptions {\n readonly sourceCode: string;\n readonly targetCode: string;\n readonly dryRun?: boolean;\n readonly json?: boolean;\n readonly renumber?: boolean;\n readonly config?: string;\n}\n\n// --- Error types ---\n\nexport type RecodeErrorCode = 'SOURCE_NOT_FOUND' | 'TARGET_NOT_FOUND' | 'RENAME_CONFLICT';\n\nexport class RecodeError extends Error {\n readonly errorCode: RecodeErrorCode;\n\n constructor(errorCode: RecodeErrorCode, message: string) {\n super(message);\n this.name = 'RecodeError';\n this.errorCode = errorCode;\n }\n}\n","// @awa-component: RCOD-RecodeMapBuilder\n// @awa-impl: RCOD-1_AC-1, RCOD-1_AC-2, RCOD-1_AC-3, RCOD-1_AC-4, RCOD-1_AC-5\n\nimport type { SpecFile, SpecParseResult } from '../check/types.js';\nimport type { RenumberMap } from '../renumber/types.js';\nimport { findSpecFiles, hasAnySpecFile } from '../spec-file-utils.js';\nimport { RecodeError } from './types.js';\n\n/**\n * Result of building a recode map.\n */\nexport interface RecodeMapBuildResult {\n readonly map: RenumberMap;\n readonly noChange: boolean;\n}\n\n/**\n * Build a recode map that translates IDs from sourceCode to targetCode,\n * with numbers offset past the highest existing target numbers.\n * Iterates ALL matching files for each code+prefix pair.\n */\n// @awa-impl: RCOD-1_AC-1\nexport function buildRecodeMap(\n sourceCode: string,\n targetCode: string,\n specs: SpecParseResult,\n): RecodeMapBuildResult {\n // Validate that at least one spec file exists for the source code\n if (!hasAnySpecFile(specs.specFiles, sourceCode)) {\n throw new RecodeError('SOURCE_NOT_FOUND', `No spec files found for source code: ${sourceCode}`);\n }\n\n const entries = new Map<string, string>();\n\n // Walk ALL source REQ files in document order, mapping IDs with offset\n const sourceReqs = findSpecFiles(specs.specFiles, sourceCode, 'REQ');\n if (sourceReqs.length > 0) {\n const targetReqs = findSpecFiles(specs.specFiles, targetCode, 'REQ');\n const reqOffset = findHighestReqNumber(targetReqs);\n buildRequirementEntries(sourceCode, targetCode, sourceReqs, reqOffset, entries);\n }\n\n // Handle properties: find highest target property number across ALL target DESIGN files\n // @awa-impl: RCOD-1_AC-4\n const sourceDesigns = findSpecFiles(specs.specFiles, sourceCode, 'DESIGN');\n const targetDesigns = findSpecFiles(specs.specFiles, targetCode, 'DESIGN');\n if (sourceDesigns.length > 0) {\n const propOffset = findHighestPropertyNumber(targetDesigns);\n buildPropertyEntries(sourceCode, targetCode, sourceDesigns, propOffset, entries);\n }\n\n // Handle component name prefix rewriting across ALL source DESIGN files\n // @awa-impl: RCOD-1_AC-5\n if (sourceDesigns.length > 0) {\n buildComponentEntries(sourceCode, targetCode, sourceDesigns, entries);\n }\n\n const noChange = entries.size === 0;\n const map: RenumberMap = { code: sourceCode, entries };\n return { map, noChange };\n}\n\n/**\n * Build recode entries for requirements, subrequirements, and ACs from all source REQ files.\n */\n// @awa-impl: RCOD-1_AC-1, RCOD-1_AC-2, RCOD-1_AC-3\nfunction buildRequirementEntries(\n _sourceCode: string,\n targetCode: string,\n sourceReqs: readonly SpecFile[],\n reqOffset: number,\n entries: Map<string, string>,\n): void {\n // Collect all requirements and ACs across files in order\n const topLevelReqs: string[] = [];\n const subReqsByParent = new Map<string, string[]>();\n const allAcIds: string[] = [];\n\n for (const sourceReq of sourceReqs) {\n for (const id of sourceReq.requirementIds) {\n if (id.includes('.')) {\n const dotIdx = id.lastIndexOf('.');\n const parent = id.slice(0, dotIdx);\n const subs = subReqsByParent.get(parent) ?? [];\n subs.push(id);\n subReqsByParent.set(parent, subs);\n } else {\n topLevelReqs.push(id);\n }\n }\n for (const acId of sourceReq.acIds) {\n allAcIds.push(acId);\n }\n }\n\n // Map top-level requirements with offset\n const reqNumberMap = new Map<string, number>(); // old source req ID → new target number\n for (let i = 0; i < topLevelReqs.length; i++) {\n const oldId = topLevelReqs[i] as string;\n const newNum = reqOffset + i + 1;\n const newId = `${targetCode}-${newNum}`;\n entries.set(oldId, newId);\n reqNumberMap.set(oldId, newNum);\n }\n\n // Map subrequirements: preserve subreq numbering, update parent prefix\n // @awa-impl: RCOD-1_AC-2\n for (const oldParentId of topLevelReqs) {\n const subs = subReqsByParent.get(oldParentId);\n if (!subs) continue;\n\n const newParentNum = reqNumberMap.get(oldParentId);\n if (newParentNum === undefined) continue;\n\n for (let j = 0; j < subs.length; j++) {\n const oldSubId = subs[j] as string;\n const newSubNum = j + 1;\n const newSubId = `${targetCode}-${newParentNum}.${newSubNum}`;\n entries.set(oldSubId, newSubId);\n }\n }\n\n // Map ACs: group by parent, update parent prefix\n // @awa-impl: RCOD-1_AC-3\n const acsByParent = new Map<string, string[]>();\n for (const acId of allAcIds) {\n const parent = acId.split('_AC-')[0] as string;\n const acs = acsByParent.get(parent) ?? [];\n acs.push(acId);\n acsByParent.set(parent, acs);\n }\n\n for (const [oldParentId, acs] of acsByParent) {\n const newParentId = entries.get(oldParentId) ?? oldParentId;\n for (let k = 0; k < acs.length; k++) {\n const oldAcId = acs[k] as string;\n const newAcNum = k + 1;\n const newAcId = `${newParentId}_AC-${newAcNum}`;\n entries.set(oldAcId, newAcId);\n }\n }\n}\n\n/**\n * Build recode entries for properties with offset from all source DESIGN files.\n */\nfunction buildPropertyEntries(\n _sourceCode: string,\n targetCode: string,\n sourceDesigns: readonly SpecFile[],\n propOffset: number,\n entries: Map<string, string>,\n): void {\n let counter = 0;\n for (const sourceDesign of sourceDesigns) {\n for (const oldId of sourceDesign.propertyIds) {\n counter++;\n const newId = `${targetCode}_P-${propOffset + counter}`;\n entries.set(oldId, newId);\n }\n }\n}\n\n/**\n * Build recode entries for component name prefixes from all source DESIGN files.\n */\nfunction buildComponentEntries(\n sourceCode: string,\n targetCode: string,\n sourceDesigns: readonly SpecFile[],\n entries: Map<string, string>,\n): void {\n for (const sourceDesign of sourceDesigns) {\n for (const compName of sourceDesign.componentNames) {\n const prefix = `${sourceCode}-`;\n if (compName.startsWith(prefix)) {\n const suffix = compName.slice(prefix.length);\n entries.set(compName, `${targetCode}-${suffix}`);\n }\n }\n }\n}\n\n/**\n * Find the highest top-level requirement number across all given REQ files.\n * Returns 0 if no requirements exist.\n */\nfunction findHighestReqNumber(reqFiles: readonly SpecFile[]): number {\n let max = 0;\n for (const reqFile of reqFiles) {\n for (const id of reqFile.requirementIds) {\n if (id.includes('.')) continue; // skip subrequirements\n const match = id.match(/-(\\d+)$/);\n if (match) {\n const num = Number.parseInt(match[1] as string, 10);\n if (num > max) max = num;\n }\n }\n }\n return max;\n}\n\n/**\n * Find the highest property number across all given DESIGN files.\n * Returns 0 if no properties exist.\n */\nfunction findHighestPropertyNumber(designFiles: readonly SpecFile[]): number {\n let max = 0;\n for (const designFile of designFiles) {\n for (const id of designFile.propertyIds) {\n const match = id.match(/_P-(\\d+)$/);\n if (match) {\n const num = Number.parseInt(match[1] as string, 10);\n if (num > max) max = num;\n }\n }\n }\n return max;\n}\n","import { fixCodesTable } from '../core/check/codes-fixer.js';\nimport { executeMoves } from '../core/merge/content-merger.js';\nimport { formatJson, formatText } from '../core/merge/reporter.js';\nimport { findStaleRefs, validateMerge } from '../core/merge/spec-mover.js';\nimport type { MergeCommandOptions, MergeResult } from '../core/merge/types.js';\nimport { MergeError } from '../core/merge/types.js';\nimport { buildRecodeMap } from '../core/recode/map-builder.js';\nimport { RecodeError } from '../core/recode/types.js';\nimport { propagate } from '../core/renumber/propagator.js';\nimport { hasAnySpecFile } from '../core/spec-file-utils.js';\nimport { scan } from '../core/trace/scanner.js';\nimport { logger } from '../utils/logger.js';\n\n/**\n * Execute the `awa spec merge` command.\n *\n * Pipeline:\n * 1. Recode: build offset map (renumber source past target's highest IDs) + propagate.\n * 2. Move: for each source spec file, rename it by changing only the code prefix.\n * When a filename clash occurs, an incrementing index suffix is appended.\n * 3. Stale-ref check: warn about leftover source-code references.\n * 4. Post-processing: optional renumber + ARCHITECTURE.md codes table fix.\n *\n * Returns exit code: 0 = no changes needed, 1 = changes applied/previewed, 2 = error.\n */\nexport async function mergeCommand(options: MergeCommandOptions): Promise<number> {\n try {\n // Validate preconditions\n validateMerge(options.sourceCode, options.targetCode);\n\n const { markers, specs } = await scan(options.config);\n const dryRun = options.dryRun === true;\n\n // Merge requires the target code to already exist\n if (!hasAnySpecFile(specs.specFiles, options.targetCode)) {\n throw new MergeError(\n 'TARGET_NOT_FOUND',\n `No spec files found for target code: ${options.targetCode}. Use \\`awa spec recode\\` to rename a code to a new one.`,\n );\n }\n\n // Phase 1: Recode — build offset map and propagate ID changes across all files.\n // buildRecodeMap finds the highest target IDs and offsets source IDs past them,\n // then recodes source code → target code in one pass.\n const { map, noChange: recodeNoChange } = buildRecodeMap(\n options.sourceCode,\n options.targetCode,\n specs,\n );\n\n let affectedFiles: readonly import('../core/renumber/types.js').AffectedFile[] = [];\n let totalReplacements = 0;\n\n if (!recodeNoChange) {\n const result = await propagate(map, specs, markers, dryRun);\n affectedFiles = result.affectedFiles;\n totalReplacements = result.totalReplacements;\n }\n\n // Phase 2: Move source files to target code namespace (rename only).\n // Source files already contain recoded IDs after Phase 1.\n const moves = await executeMoves(\n options.sourceCode,\n options.targetCode,\n specs.specFiles,\n dryRun,\n );\n\n // Phase 3: Find stale references — exclude moved source files\n // and files the propagator already handled (or would handle in dry-run)\n const movedSourcePaths = new Set(moves.map((m) => m.sourceFile));\n const propagatedPaths = new Set(affectedFiles.map((af) => af.filePath));\n const nonSourceFiles = specs.specFiles.filter(\n (sf) => !movedSourcePaths.has(sf.filePath) && !propagatedPaths.has(sf.filePath),\n );\n const staleRefs = await findStaleRefs(options.sourceCode, nonSourceFiles);\n\n const noChange = recodeNoChange && moves.length === 0;\n\n const result: MergeResult = {\n sourceCode: options.sourceCode,\n targetCode: options.targetCode,\n map,\n affectedFiles,\n totalReplacements,\n moves,\n staleRefs,\n noChange,\n };\n\n outputResult(result, dryRun, options.json === true);\n\n // Stale references are errors — abort with exit code 2\n if (staleRefs.length > 0) {\n return 2;\n }\n\n // Phase 4: Optional renumber\n if (options.renumber && !dryRun && !noChange) {\n const { renumberCommand } = await import('./renumber.js');\n await renumberCommand({\n code: options.targetCode,\n dryRun: false,\n json: options.json,\n config: options.config,\n });\n }\n\n // Update Feature Codes table in ARCHITECTURE.md\n if (!dryRun && !noChange) {\n const { specs: freshSpecs, config: scanConfig } = await scan(options.config);\n await fixCodesTable(freshSpecs, scanConfig);\n }\n\n return noChange ? 0 : 1;\n } catch (err) {\n if (err instanceof MergeError) {\n logger.error(err.message);\n return 2;\n }\n if (err instanceof RecodeError) {\n logger.error(err.message);\n return 2;\n }\n if (err instanceof Error) {\n logger.error(err.message);\n } else {\n logger.error(String(err));\n }\n return 2;\n }\n}\n\n/**\n * Output the merge result in the requested format.\n */\nfunction outputResult(result: MergeResult, dryRun: boolean, json: boolean): void {\n if (json) {\n process.stdout.write(`${formatJson(result)}\\n`);\n } else {\n const text = formatText(result, dryRun);\n logger.info(text);\n }\n}\n","// @awa-component: RCOD-RecodeReporter\n// @awa-impl: RCOD-4_AC-2, RCOD-4_AC-3\n\nimport type { RecodeResult } from './types.js';\n\n/**\n * Format recode results as human-readable text.\n * In dry-run mode, prefixes output with a banner.\n */\n// @awa-impl: RCOD-4_AC-2\nexport function formatText(result: RecodeResult, dryRun: boolean): string {\n const lines: string[] = [];\n\n if (dryRun) {\n lines.push('DRY RUN — no files were modified\\n');\n }\n\n if (result.noChange) {\n lines.push(`${result.sourceCode} → ${result.targetCode}: no IDs to recode`);\n return lines.join('\\n');\n }\n\n lines.push(\n `${result.sourceCode} → ${result.targetCode}: ${result.map.entries.size} ID(s) recoded\\n`,\n );\n lines.push(' Old ID → New ID');\n lines.push(` ${'─'.repeat(40)}`);\n for (const [oldId, newId] of result.map.entries) {\n lines.push(` ${oldId} → ${newId}`);\n }\n\n if (result.affectedFiles.length > 0) {\n lines.push('');\n lines.push(\n ` ${result.totalReplacements} replacement(s) in ${result.affectedFiles.length} file(s):`,\n );\n for (const file of result.affectedFiles) {\n lines.push(` ${file.filePath} (${file.replacements.length})`);\n }\n }\n\n // File renames section\n if (result.renames.length > 0) {\n lines.push('');\n lines.push(` ${result.renames.length} file(s) renamed:`);\n for (const r of result.renames) {\n lines.push(` ${r.oldPath} → ${r.newPath}`);\n }\n }\n\n // Stale references (errors)\n if (result.staleRefs.length > 0) {\n lines.push('');\n lines.push(` ✖ ${result.staleRefs.length} file(s) still reference ${result.sourceCode}:`);\n for (const ref of result.staleRefs) {\n lines.push(` ${ref}`);\n }\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Format recode results as JSON for CI consumption.\n */\n// @awa-impl: RCOD-4_AC-3\nexport function formatJson(result: RecodeResult): string {\n const output = {\n sourceCode: result.sourceCode,\n targetCode: result.targetCode,\n noChange: result.noChange,\n map: Object.fromEntries(result.map.entries),\n affectedFiles: result.affectedFiles.map((f) => ({\n filePath: f.filePath,\n replacements: f.replacements.map((r) => ({\n line: r.line,\n oldId: r.oldId,\n newId: r.newId,\n })),\n })),\n totalReplacements: result.totalReplacements,\n renames: result.renames.map((r) => ({ oldPath: r.oldPath, newPath: r.newPath })),\n staleRefs: result.staleRefs,\n };\n\n return JSON.stringify(output, null, 2);\n}\n","// @awa-component: RCOD-RecodeCommand\n// @awa-impl: RCOD-2_AC-1, RCOD-2_AC-2\n// @awa-impl: RCOD-3_AC-1, RCOD-3_AC-2\n// @awa-impl: RCOD-4_AC-1, RCOD-4_AC-4\n\nimport { fixCodesTable } from '../core/check/codes-fixer.js';\nimport {\n detectConflicts,\n executeRenames,\n findStaleRefs,\n planRenames,\n} from '../core/merge/spec-mover.js';\nimport { buildRecodeMap } from '../core/recode/map-builder.js';\nimport { formatJson, formatText } from '../core/recode/reporter.js';\nimport type { RecodeCommandOptions, RecodeResult } from '../core/recode/types.js';\nimport { RecodeError } from '../core/recode/types.js';\nimport { propagate } from '../core/renumber/propagator.js';\nimport { scan } from '../core/trace/scanner.js';\nimport { logger } from '../utils/logger.js';\n\n/**\n * Execute the `awa spec recode` command.\n * Returns exit code: 0 = no changes needed, 1 = changes applied/previewed, 2 = error.\n */\n// @awa-impl: RCOD-4_AC-1, RCOD-4_AC-4\nexport async function recodeCommand(options: RecodeCommandOptions): Promise<number> {\n try {\n const { markers, specs } = await scan(options.config);\n const dryRun = options.dryRun === true;\n\n // Phase 1: Build recode map (validates both codes exist)\n // @awa-impl: RCOD-3_AC-1, RCOD-3_AC-2\n const { map, noChange: recodeNoChange } = buildRecodeMap(\n options.sourceCode,\n options.targetCode,\n specs,\n );\n\n // Phase 2: Propagate changes using RENUM propagator\n let affectedFiles: readonly import('../core/renumber/types.js').AffectedFile[] = [];\n let totalReplacements = 0;\n\n if (!recodeNoChange) {\n // @awa-impl: RCOD-2_AC-1, RCOD-2_AC-2\n const result = await propagate(map, specs, markers, dryRun);\n affectedFiles = result.affectedFiles;\n totalReplacements = result.totalReplacements;\n }\n\n // Phase 3: Spec file restructuring — rename source files to target code\n const renames = planRenames(options.sourceCode, options.targetCode, specs.specFiles);\n\n // Check for conflicts (target filenames already exist → use merge instead)\n const conflicts = detectConflicts(renames, specs.specFiles);\n if (conflicts.length > 0) {\n throw new RecodeError(\n 'RENAME_CONFLICT',\n `File rename conflict(s): ${conflicts.join(', ')}. Use \\`awa spec merge\\` to combine codes with overlapping files.`,\n );\n }\n\n // Execute renames (move files + update headings)\n await executeRenames(renames, options.sourceCode, options.targetCode, dryRun);\n\n // Phase 4: Find stale references — exclude renamed source files\n // and files the propagator already handled (or would handle in dry-run)\n const propagatedPaths = new Set(affectedFiles.map((af) => af.filePath));\n const nonSourceFiles = specs.specFiles.filter(\n (sf) => !renames.some((r) => r.oldPath === sf.filePath) && !propagatedPaths.has(sf.filePath),\n );\n const staleRefs = await findStaleRefs(options.sourceCode, nonSourceFiles);\n\n const noChange = recodeNoChange && renames.length === 0;\n\n const result: RecodeResult = {\n sourceCode: options.sourceCode,\n targetCode: options.targetCode,\n map,\n affectedFiles,\n totalReplacements,\n renames,\n staleRefs,\n noChange,\n };\n\n outputResult(result, dryRun, options.json === true);\n\n // Stale references are errors — exit code 2\n if (staleRefs.length > 0) {\n return 2;\n }\n\n // Phase 5: Update ARCHITECTURE.md Feature Codes table\n if (!dryRun && !noChange) {\n const { specs: freshSpecs, config: scanConfig } = await scan(options.config);\n await fixCodesTable(freshSpecs, scanConfig);\n }\n\n return noChange ? 0 : 1;\n } catch (err) {\n if (err instanceof RecodeError) {\n logger.error(err.message);\n return 2;\n }\n if (err instanceof Error) {\n logger.error(err.message);\n } else {\n logger.error(String(err));\n }\n return 2;\n }\n}\n\n/**\n * Output the recode result in the requested format.\n */\nfunction outputResult(result: RecodeResult, dryRun: boolean, json: boolean): void {\n if (json) {\n process.stdout.write(`${formatJson(result)}\\n`);\n } else {\n const text = formatText(result, dryRun);\n logger.info(text);\n }\n}\n","// @awa-component: TTST-TestCommand\n// @awa-impl: TTST-7_AC-1\n// @awa-impl: TTST-9_AC-1\n// @awa-impl: TTST-11_AC-1\n// @awa-impl: TTST-12_AC-1\n\nimport { intro, outro } from '@clack/prompts';\n\nimport { configLoader } from '../core/config.js';\nimport { buildMergedDir, resolveOverlays } from '../core/overlay.js';\nimport { templateResolver } from '../core/template-resolver.js';\nimport { discoverFixtures } from '../core/template-test/fixture-loader.js';\nimport { report } from '../core/template-test/reporter.js';\nimport { runAll } from '../core/template-test/runner.js';\nimport type { RawTestOptions } from '../core/template-test/types.js';\nimport { rmDir } from '../utils/fs.js';\nimport { logger } from '../utils/logger.js';\n\n// @awa-impl: TTST-7_AC-1\nexport async function testCommand(options: RawTestOptions): Promise<number> {\n let mergedDir: string | null = null;\n\n try {\n const isJson = options.json === true;\n const isSummary = options.summary === true;\n const silent = isJson || isSummary;\n\n if (!silent) {\n intro('awa CLI - Template Test');\n }\n\n // Load configuration file\n const fileConfig = await configLoader.load(options.config ?? null);\n const templateSource = options.template ?? fileConfig?.template ?? null;\n\n // Resolve template source\n const refresh = options.refresh ?? false;\n const template = await templateResolver.resolve(templateSource, refresh);\n\n // Build merged dir if overlays are specified\n const overlays = options.overlay ?? fileConfig?.overlay ?? [];\n let templatePath = template.localPath;\n if (overlays.length > 0) {\n const overlayDirs = await resolveOverlays(overlays, refresh);\n mergedDir = await buildMergedDir(template.localPath, overlayDirs);\n templatePath = mergedDir;\n }\n\n // Discover fixtures\n const fixtures = await discoverFixtures(templatePath);\n\n if (fixtures.length === 0) {\n if (isSummary) {\n console.log('passed: 0, failed: 0, total: 0');\n } else if (isJson) {\n console.log(JSON.stringify({ total: 0, passed: 0, failed: 0, results: [] }, null, 2));\n } else {\n logger.warn('No test fixtures found in _tests/ directory');\n outro('No tests to run.');\n }\n return 0;\n }\n\n if (!silent) {\n logger.info(`Found ${fixtures.length} fixture(s)`);\n }\n\n // Extract preset definitions from config\n const presetDefinitions = fileConfig?.presets ?? {};\n\n // Run all fixtures\n const result = await runAll(\n fixtures,\n templatePath,\n { updateSnapshots: options.updateSnapshots },\n presetDefinitions,\n );\n\n // Report results\n if (isSummary) {\n console.log(`passed: ${result.passed}, failed: ${result.failed}, total: ${result.total}`);\n } else {\n report(result, { json: isJson });\n }\n\n if (result.failed > 0) {\n if (!silent) {\n outro(`${result.failed} fixture(s) failed.`);\n }\n return 1;\n }\n\n if (!silent) {\n outro('All tests passed!');\n }\n return 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 2;\n } finally {\n if (mergedDir) {\n await rmDir(mergedDir);\n }\n }\n}\n","// @awa-component: TTST-FixtureLoader\n// @awa-impl: TTST-1_AC-1\n// @awa-impl: TTST-2_AC-1\n\nimport { readdir } from 'node:fs/promises';\nimport { basename, extname, join } from 'node:path';\n\nimport { parse } from 'smol-toml';\n\nimport { readTextFile } from '../../utils/fs.js';\nimport type { TestFixture } from './types.js';\n\n// @awa-impl: TTST-1_AC-1\nexport async function discoverFixtures(templatePath: string): Promise<TestFixture[]> {\n const testsDir = join(templatePath, '_tests');\n\n let entries: string[];\n try {\n const dirEntries = await readdir(testsDir, { withFileTypes: true });\n entries = dirEntries\n .filter((e) => e.isFile() && extname(e.name) === '.toml')\n .map((e) => e.name)\n .sort();\n } catch {\n // _tests/ directory doesn't exist — no fixtures\n return [];\n }\n\n const fixtures: TestFixture[] = [];\n for (const filename of entries) {\n const filePath = join(testsDir, filename);\n const fixture = await parseFixture(filePath);\n fixtures.push(fixture);\n }\n\n return fixtures;\n}\n\n// @awa-impl: TTST-2_AC-1\nexport async function parseFixture(filePath: string): Promise<TestFixture> {\n const content = await readTextFile(filePath);\n const parsed = parse(content) as Record<string, unknown>;\n\n const name = basename(filePath, extname(filePath));\n\n const features = toStringArray(parsed.features) ?? [];\n const preset = toStringArray(parsed.preset) ?? [];\n const removeFeatures = toStringArray(parsed['remove-features']) ?? [];\n const expectedFiles = toStringArray(parsed['expected-files']) ?? [];\n\n return {\n name,\n features,\n preset,\n removeFeatures,\n expectedFiles,\n filePath,\n };\n}\n\nfunction toStringArray(value: unknown): string[] | null {\n if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {\n return value as string[];\n }\n return null;\n}\n","// @awa-component: TTST-Reporter\n// @awa-impl: TTST-6_AC-1\n// @awa-impl: TTST-10_AC-1\n\nimport chalk from 'chalk';\n\nimport type { FixtureResult, TestSuiteResult } from './types.js';\n\n// @awa-impl: TTST-6_AC-1\nexport function report(result: TestSuiteResult, options?: { json?: boolean }): void {\n if (options?.json) {\n reportJson(result);\n return;\n }\n\n console.log('');\n\n for (const fixture of result.results) {\n reportFixture(fixture);\n }\n\n // Summary\n console.log('');\n console.log(chalk.bold('Test Summary:'));\n console.log(` Total: ${result.total}`);\n console.log(chalk.green(` Passed: ${result.passed}`));\n if (result.failed > 0) {\n console.log(chalk.red(` Failed: ${result.failed}`));\n }\n console.log('');\n}\n\nfunction reportJson(result: TestSuiteResult): void {\n const output = {\n total: result.total,\n passed: result.passed,\n failed: result.failed,\n results: result.results.map((r) => ({\n name: r.name,\n passed: r.passed,\n ...(r.error ? { error: r.error } : {}),\n fileResults: r.fileResults.map((f) => ({\n path: f.path,\n found: f.found,\n })),\n snapshotResults: r.snapshotResults.map((s) => ({\n path: s.path,\n status: s.status,\n })),\n })),\n };\n console.log(JSON.stringify(output, null, 2));\n}\n\nfunction reportFixture(fixture: FixtureResult): void {\n const icon = fixture.passed ? chalk.green('✔') : chalk.red('✖');\n console.log(`${icon} ${fixture.name}`);\n\n if (fixture.error) {\n console.log(chalk.red(` Error: ${fixture.error}`));\n return;\n }\n\n // Report missing files\n const missingFiles = fixture.fileResults.filter((r) => !r.found);\n for (const missing of missingFiles) {\n console.log(chalk.red(` Missing file: ${missing.path}`));\n }\n\n // Report snapshot mismatches\n const snapshotFailures = fixture.snapshotResults.filter((r) => r.status !== 'match');\n for (const failure of snapshotFailures) {\n switch (failure.status) {\n case 'mismatch':\n console.log(chalk.yellow(` Snapshot mismatch: ${failure.path}`));\n break;\n case 'missing-snapshot':\n console.log(chalk.yellow(` Missing snapshot: ${failure.path}`));\n break;\n case 'extra-snapshot':\n console.log(chalk.yellow(` Extra snapshot (not in output): ${failure.path}`));\n break;\n }\n }\n}\n","// @awa-component: TTST-TestRunner\n// @awa-impl: TTST-3_AC-1\n// @awa-impl: TTST-4_AC-1\n// @awa-impl: TTST-5_AC-1\n// @awa-impl: TTST-8_AC-1\n\nimport { mkdir, rm } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\n\nimport { pathExists } from '../../utils/fs.js';\nimport { featureResolver } from '../feature-resolver.js';\nimport { fileGenerator } from '../generator.js';\nimport { compareSnapshots, updateSnapshots } from './snapshot.js';\nimport type {\n FileAssertionResult,\n FixtureResult,\n SnapshotFileResult,\n TestFixture,\n TestRunOptions,\n TestSuiteResult,\n} from './types.js';\n\n// @awa-impl: TTST-3_AC-1\nexport async function runFixture(\n fixture: TestFixture,\n templatePath: string,\n options: TestRunOptions,\n presetDefinitions: Record<string, string[]> = {},\n): Promise<FixtureResult> {\n const tempDir = join(tmpdir(), `awa-test-${fixture.name}-${Date.now()}`);\n\n try {\n await mkdir(tempDir, { recursive: true });\n\n // Resolve features using presets and remove-features\n const features = featureResolver.resolve({\n baseFeatures: [...fixture.features],\n presetNames: [...fixture.preset],\n removeFeatures: [...fixture.removeFeatures],\n presetDefinitions,\n });\n\n // Render templates to temp dir\n await fileGenerator.generate({\n templatePath,\n outputPath: tempDir,\n features,\n force: true,\n dryRun: false,\n delete: false,\n });\n\n // @awa-impl: TTST-4_AC-1\n // Check expected files\n const fileResults: FileAssertionResult[] = [];\n for (const expectedFile of fixture.expectedFiles) {\n const fullPath = join(tempDir, expectedFile);\n const found = await pathExists(fullPath);\n fileResults.push({ path: expectedFile, found });\n }\n\n const missingFiles = fileResults.filter((r) => !r.found);\n\n // @awa-impl: TTST-5_AC-1\n // Snapshot comparison\n const snapshotDir = join(templatePath, '_tests', fixture.name);\n let snapshotResults: SnapshotFileResult[] = [];\n if (options.updateSnapshots) {\n await updateSnapshots(tempDir, snapshotDir);\n } else if (await pathExists(snapshotDir)) {\n snapshotResults = await compareSnapshots(tempDir, snapshotDir);\n }\n\n const snapshotFailures = snapshotResults.filter((r) => r.status !== 'match');\n\n const passed = missingFiles.length === 0 && snapshotFailures.length === 0;\n\n return {\n name: fixture.name,\n passed,\n fileResults,\n snapshotResults,\n };\n } catch (error) {\n return {\n name: fixture.name,\n passed: false,\n fileResults: [],\n snapshotResults: [],\n error: error instanceof Error ? error.message : String(error),\n };\n } finally {\n // Clean up temp dir\n await rm(tempDir, { recursive: true, force: true }).catch(() => {});\n }\n}\n\nexport async function runAll(\n fixtures: TestFixture[],\n templatePath: string,\n options: TestRunOptions,\n presetDefinitions: Record<string, string[]> = {},\n): Promise<TestSuiteResult> {\n const results: FixtureResult[] = [];\n\n for (const fixture of fixtures) {\n const result = await runFixture(fixture, templatePath, options, presetDefinitions);\n results.push(result);\n }\n\n const passed = results.filter((r) => r.passed).length;\n const failed = results.filter((r) => !r.passed).length;\n\n return {\n results,\n total: results.length,\n passed,\n failed,\n };\n}\n","// @awa-component: TTST-TestRunner\n// @awa-impl: TTST-5_AC-1\n\nimport { mkdir, readdir, rm } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\n\nimport { pathExists, readTextFile, writeTextFile } from '../../utils/fs.js';\nimport type { SnapshotFileResult } from './types.js';\n\n/** Walk a directory recursively and yield relative file paths. */\nasync function walkRelative(dir: string, base: string): Promise<string[]> {\n const results: string[] = [];\n const entries = await readdir(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n const sub = await walkRelative(fullPath, base);\n results.push(...sub);\n } else if (entry.isFile()) {\n results.push(relative(base, fullPath));\n }\n }\n\n return results;\n}\n\n// @awa-impl: TTST-5_AC-1\nexport async function compareSnapshots(\n renderedDir: string,\n snapshotDir: string,\n): Promise<SnapshotFileResult[]> {\n const results: SnapshotFileResult[] = [];\n\n const renderedFiles = await walkRelative(renderedDir, renderedDir);\n const snapshotFiles = await walkRelative(snapshotDir, snapshotDir);\n\n const snapshotSet = new Set(snapshotFiles);\n const renderedSet = new Set(renderedFiles);\n\n // Check rendered files against snapshots\n for (const file of renderedFiles) {\n const renderedPath = join(renderedDir, file);\n const snapshotPath = join(snapshotDir, file);\n\n if (!snapshotSet.has(file)) {\n results.push({ path: file, status: 'missing-snapshot' });\n continue;\n }\n\n const renderedContent = await readTextFile(renderedPath);\n const snapshotContent = await readTextFile(snapshotPath);\n\n results.push({\n path: file,\n status: renderedContent === snapshotContent ? 'match' : 'mismatch',\n });\n }\n\n // Check for extra snapshot files not in rendered output\n for (const file of snapshotFiles) {\n if (!renderedSet.has(file)) {\n results.push({ path: file, status: 'extra-snapshot' });\n }\n }\n\n return results;\n}\n\n// @awa-impl: TTST-5_AC-1\nexport async function updateSnapshots(renderedDir: string, snapshotDir: string): Promise<void> {\n // Remove existing snapshot directory\n if (await pathExists(snapshotDir)) {\n await rm(snapshotDir, { recursive: true, force: true });\n }\n\n await mkdir(snapshotDir, { recursive: true });\n\n // Copy rendered files to snapshot directory\n const files = await walkRelative(renderedDir, renderedDir);\n for (const file of files) {\n const srcPath = join(renderedDir, file);\n const destPath = join(snapshotDir, file);\n const content = await readTextFile(srcPath);\n await writeTextFile(destPath, content);\n }\n}\n","// @awa-component: TRC-ContentAssembler\n// @awa-impl: TRC-5_AC-1, TRC-5_AC-2, TRC-5_AC-3, TRC-5_AC-4, TRC-5_AC-5\n\nimport { readFile } from 'node:fs/promises';\n\nimport type { ContentSection, TraceResult } from './types.js';\n\n/** Default lines of context before a code marker. */\nconst DEFAULT_BEFORE_CONTEXT = 5;\n/** Default lines of context after a code marker. */\nconst DEFAULT_AFTER_CONTEXT = 20;\n\n/** Options for controlling code context extraction. */\ninterface ContextLineOptions {\n readonly beforeContext?: number;\n readonly afterContext?: number;\n}\n\n/**\n * Assemble content sections from a trace result by reading the actual files.\n * Returns ContentSections sorted by priority (lowest number = highest priority).\n */\nexport async function assembleContent(\n result: TraceResult,\n taskPath?: string,\n contextOptions?: ContextLineOptions,\n): Promise<ContentSection[]> {\n const beforeCtx = contextOptions?.beforeContext ?? DEFAULT_BEFORE_CONTEXT;\n const afterCtx = contextOptions?.afterContext ?? DEFAULT_AFTER_CONTEXT;\n const sections: ContentSection[] = [];\n const seen = new Set<string>();\n // File content cache scoped to this invocation — avoids re-reading the same\n // file when multiple trace IDs reference it.\n const fileCache = new Map<string, string | null>();\n\n // Priority 1: Task file — full content\n if (taskPath) {\n const content = await cachedReadFile(fileCache, taskPath);\n if (content) {\n const lineCount = content.split('\\n').length;\n sections.push({\n type: 'task',\n filePath: taskPath,\n startLine: 1,\n endLine: lineCount,\n content,\n priority: 1,\n });\n }\n }\n\n for (const chain of result.chains) {\n // Priority 2: Requirement\n if (chain.requirement) {\n const key = `req:${chain.requirement.location.filePath}:${chain.requirement.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractSpecSection(\n fileCache,\n chain.requirement.location.filePath,\n chain.requirement.id,\n chain.requirement.location.line,\n 'requirement',\n 2,\n );\n if (section) sections.push(section);\n }\n }\n\n // Also include ACs under requirement (they're typically in the same section)\n for (const ac of chain.acs) {\n const key = `ac:${ac.location.filePath}:${ac.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n // ACs are part of the requirement section — only add if different from requirement\n if (!chain.requirement || ac.location.filePath !== chain.requirement.location.filePath) {\n const section = await extractSpecSection(\n fileCache,\n ac.location.filePath,\n ac.id,\n ac.location.line,\n 'requirement',\n 2,\n );\n if (section) sections.push(section);\n }\n }\n }\n\n // Priority 3: Design components\n for (const comp of chain.designComponents) {\n const key = `design:${comp.location.filePath}:${comp.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractSpecSection(\n fileCache,\n comp.location.filePath,\n comp.id,\n comp.location.line,\n 'design',\n 3,\n );\n if (section) sections.push(section);\n }\n }\n\n // Priority 5: Implementation code\n for (const impl of chain.implementations) {\n const key = `impl:${impl.location.filePath}:${impl.location.line}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractCodeSection(\n fileCache,\n impl.location.filePath,\n impl.location.line,\n 'implementation',\n 5,\n beforeCtx,\n afterCtx,\n );\n if (section) sections.push(section);\n }\n }\n\n // Priority 6: Test code\n for (const t of chain.tests) {\n const key = `test:${t.location.filePath}:${t.location.line}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractCodeSection(\n fileCache,\n t.location.filePath,\n t.location.line,\n 'test',\n 6,\n beforeCtx,\n afterCtx,\n );\n if (section) sections.push(section);\n }\n }\n\n // Priority 5 (properties are also design-level) → tests already covered\n for (const prop of chain.properties) {\n const key = `prop:${prop.location.filePath}:${prop.id}`;\n if (!seen.has(key)) {\n seen.add(key);\n const section = await extractSpecSection(\n fileCache,\n prop.location.filePath,\n prop.id,\n prop.location.line,\n 'design',\n 3,\n );\n if (section) sections.push(section);\n }\n }\n }\n\n // Sort by priority\n sections.sort((a, b) => a.priority - b.priority);\n\n return sections;\n}\n\n/**\n * Extract an H3 section from a spec file starting at or near the given line.\n * Reads from the H3 heading to the next H3 or H2 heading.\n */\nasync function extractSpecSection(\n fileCache: Map<string, string | null>,\n filePath: string,\n _id: string,\n line: number,\n type: ContentSection['type'],\n priority: number,\n): Promise<ContentSection | null> {\n const content = await cachedReadFile(fileCache, filePath);\n if (!content) return null;\n\n const lines = content.split('\\n');\n\n // Find the H3 heading at or before the given line\n let startIdx = line - 1;\n while (startIdx >= 0 && !/^###\\s/.test(lines[startIdx] ?? '')) {\n startIdx--;\n }\n if (startIdx < 0) startIdx = Math.max(0, line - 1);\n\n // Find the end: next H2 or H3 heading\n let endIdx = startIdx + 1;\n while (endIdx < lines.length) {\n const l = lines[endIdx] ?? '';\n if (/^#{2,3}\\s/.test(l) && endIdx > startIdx) break;\n endIdx++;\n }\n\n const sectionContent = lines.slice(startIdx, endIdx).join('\\n').trimEnd();\n\n return {\n type,\n filePath,\n startLine: startIdx + 1,\n endLine: endIdx,\n content: sectionContent,\n priority,\n };\n}\n\n/**\n * Extract a code section around a marker line.\n * Tries to find the enclosing function/block; falls back to +/- DEFAULT_CONTEXT_LINES.\n */\nasync function extractCodeSection(\n fileCache: Map<string, string | null>,\n filePath: string,\n line: number,\n type: ContentSection['type'],\n priority: number,\n beforeContext: number = DEFAULT_BEFORE_CONTEXT,\n afterContext: number = DEFAULT_AFTER_CONTEXT,\n): Promise<ContentSection | null> {\n const content = await cachedReadFile(fileCache, filePath);\n if (!content) return null;\n\n const lines = content.split('\\n');\n const lineIdx = line - 1;\n\n // Try to find enclosing function/block\n const range = findEnclosingBlock(lines, lineIdx, beforeContext, afterContext);\n\n const sectionContent = lines\n .slice(range.start, range.end + 1)\n .join('\\n')\n .trimEnd();\n\n return {\n type,\n filePath,\n startLine: range.start + 1,\n endLine: range.end + 1,\n content: sectionContent,\n priority,\n };\n}\n\n/**\n * Find the enclosing function or block around a given line index.\n * Uses simple brace-counting heuristic. Falls back to context window.\n */\nfunction findEnclosingBlock(\n lines: string[],\n lineIdx: number,\n beforeContext: number = DEFAULT_BEFORE_CONTEXT,\n afterContext: number = DEFAULT_AFTER_CONTEXT,\n): { start: number; end: number } {\n // Search upward for a function-like declaration\n let start = lineIdx;\n for (let i = lineIdx; i >= 0; i--) {\n const l = lines[i] ?? '';\n // Detect function/method declarations, class declarations, test blocks\n if (\n /^\\s*(export\\s+)?(async\\s+)?function\\s/.test(l) ||\n /^\\s*(export\\s+)?(const|let|var)\\s+\\w+\\s*=\\s*(async\\s+)?\\(/.test(l) ||\n /^\\s*(describe|test|it)\\s*\\(/.test(l) ||\n /^\\s*(export\\s+)?class\\s/.test(l) ||\n /^\\s*(export\\s+)?(const|let|var)\\s+\\w+\\s*=\\s*(async\\s+)?function/.test(l)\n ) {\n start = i;\n break;\n }\n // Don't search too far up\n if (lineIdx - i > 50) {\n start = Math.max(0, lineIdx - beforeContext);\n break;\n }\n }\n\n // Search downward for the closing brace at the same level\n let braceCount = 0;\n let foundOpen = false;\n let end = lineIdx;\n\n for (let i = start; i < lines.length; i++) {\n const l = lines[i] ?? '';\n for (const ch of l) {\n if (ch === '{') {\n braceCount++;\n foundOpen = true;\n } else if (ch === '}') {\n braceCount--;\n }\n }\n if (foundOpen && braceCount <= 0) {\n end = i;\n break;\n }\n // Don't search too far down\n if (i - start > 100) {\n end = Math.min(lines.length - 1, lineIdx + afterContext);\n break;\n }\n }\n\n if (!foundOpen) {\n // Fallback: context window\n start = Math.max(0, lineIdx - beforeContext);\n end = Math.min(lines.length - 1, lineIdx + afterContext);\n }\n\n return { start, end };\n}\n\nasync function cachedReadFile(\n cache: Map<string, string | null>,\n filePath: string,\n): Promise<string | null> {\n if (cache.has(filePath)) return cache.get(filePath) ?? null;\n let content: string | null;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n content = null;\n }\n cache.set(filePath, content);\n return content;\n}\n","// @awa-component: TRC-ContentFormatter\n\nimport type { ContentSection } from './types.js';\n\n/** File extension to Markdown language identifier. */\nfunction langId(filePath: string): string {\n if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) return 'typescript';\n if (filePath.endsWith('.js') || filePath.endsWith('.jsx')) return 'javascript';\n if (filePath.endsWith('.md')) return 'markdown';\n if (filePath.endsWith('.yaml') || filePath.endsWith('.yml')) return 'yaml';\n if (filePath.endsWith('.json')) return 'json';\n if (filePath.endsWith('.tsp')) return 'typespec';\n return '';\n}\n\n/** Map section type to a human-readable heading. */\nfunction sectionHeading(type: ContentSection['type']): string {\n switch (type) {\n case 'task':\n return 'Task';\n case 'requirement':\n return 'Requirement';\n case 'design':\n return 'Design';\n case 'implementation':\n return 'Implementation';\n case 'test':\n return 'Test';\n default:\n return 'Other';\n }\n}\n\n/**\n * Format content sections as Markdown with headings, provenance, and code blocks.\n * @awa-impl: TRC-7_AC-1\n */\nexport function formatContentMarkdown(\n sections: ContentSection[],\n queryLabel: string,\n footer: string | null,\n): string {\n const lines: string[] = [];\n lines.push(`# Context: ${queryLabel}`);\n lines.push('');\n\n let lastType: string | null = null;\n\n for (const section of sections) {\n // Group by type — add H2 when type changes\n if (section.type !== lastType) {\n lines.push(`## ${sectionHeading(section.type)}`);\n lines.push('');\n lastType = section.type;\n }\n\n lines.push(`> From: ${section.filePath} (lines ${section.startLine}-${section.endLine})`);\n lines.push('');\n\n const isCode = section.type === 'implementation' || section.type === 'test';\n if (isCode) {\n const lang = langId(section.filePath);\n lines.push(`\\`\\`\\`${lang}`);\n lines.push(section.content);\n lines.push('```');\n } else {\n lines.push(section.content);\n }\n lines.push('');\n }\n\n if (footer) {\n lines.push(`---`);\n lines.push(footer);\n lines.push('');\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Format content sections as JSON structure.\n * @awa-impl: TRC-7_AC-1\n */\nexport function formatContentJson(\n sections: ContentSection[],\n queryLabel: string,\n footer: string | null,\n): string {\n const result = {\n query: queryLabel,\n sections: sections.map((s) => ({\n type: s.type,\n filePath: s.filePath,\n startLine: s.startLine,\n endLine: s.endLine,\n content: s.content,\n priority: s.priority,\n })),\n estimatedTokens: Math.ceil(sections.reduce((sum, s) => sum + s.content.length, 0) / 4),\n filesIncluded: new Set(sections.map((s) => s.filePath)).size,\n ...(footer ? { truncated: true, truncationMessage: footer } : {}),\n };\n return JSON.stringify(result, null, 2);\n}\n","// @awa-component: TRC-Formatter\n// @awa-impl: TRC-4_AC-1, TRC-9_AC-1, TRC-10_AC-1\n\nimport type { TraceChain, TraceResult } from './types.js';\n\n/**\n * Format trace result as a text location tree.\n */\nexport function formatTree(result: TraceResult): string {\n const lines: string[] = [];\n\n for (const chain of result.chains) {\n lines.push(...formatChainTree(chain));\n lines.push('');\n }\n\n for (const id of result.notFound) {\n lines.push(`✗ ${id}: not found`);\n }\n\n return lines.join('\\n').trimEnd();\n}\n\nfunction formatChainTree(chain: TraceChain): string[] {\n const lines: string[] = [];\n const queryId = chain.queryId;\n\n // Header line — show AC description if available, otherwise just the ID\n lines.push(`${queryId}`);\n\n // Requirement (reverse)\n if (chain.requirement) {\n lines.push('');\n lines.push(' ▲ Requirement');\n const r = chain.requirement;\n lines.push(` │ ${r.id} (${r.location.filePath}:${r.location.line})`);\n }\n\n // ACs\n if (chain.acs.length > 0) {\n lines.push('');\n lines.push(' ▼ Acceptance Criteria');\n for (const ac of chain.acs) {\n lines.push(` │ ${ac.id} (${ac.location.filePath}:${ac.location.line})`);\n }\n }\n\n // Design components\n if (chain.designComponents.length > 0) {\n lines.push('');\n lines.push(' ▼ Design');\n for (const comp of chain.designComponents) {\n lines.push(` │ ${comp.id} (${comp.location.filePath}:${comp.location.line})`);\n }\n }\n\n // Properties\n if (chain.properties.length > 0) {\n lines.push('');\n lines.push(' ▼ Properties');\n for (const prop of chain.properties) {\n lines.push(` │ ${prop.id} (${prop.location.filePath}:${prop.location.line})`);\n }\n }\n\n // Implementations\n if (chain.implementations.length > 0) {\n lines.push('');\n lines.push(' ▼ Implementation');\n for (const impl of chain.implementations) {\n lines.push(\n ` │ ${impl.location.filePath}:${impl.location.line} (@awa-${impl.type === 'implementation' ? 'impl' : 'component'}: ${impl.id})`,\n );\n }\n }\n\n // Tests\n if (chain.tests.length > 0) {\n lines.push('');\n lines.push(' ▼ Tests');\n for (const t of chain.tests) {\n lines.push(` │ ${t.location.filePath}:${t.location.line} (@awa-test: ${t.id})`);\n }\n }\n\n return lines;\n}\n\n/**\n * Format trace result as a file path list.\n */\nexport function formatList(result: TraceResult): string {\n const paths = new Set<string>();\n\n for (const chain of result.chains) {\n if (chain.requirement) {\n paths.add(`${chain.requirement.location.filePath}:${chain.requirement.location.line}`);\n }\n for (const ac of chain.acs) {\n paths.add(`${ac.location.filePath}:${ac.location.line}`);\n }\n for (const comp of chain.designComponents) {\n paths.add(`${comp.location.filePath}:${comp.location.line}`);\n }\n for (const prop of chain.properties) {\n paths.add(`${prop.location.filePath}:${prop.location.line}`);\n }\n for (const impl of chain.implementations) {\n paths.add(`${impl.location.filePath}:${impl.location.line}`);\n }\n for (const t of chain.tests) {\n paths.add(`${t.location.filePath}:${t.location.line}`);\n }\n }\n\n return [...paths].join('\\n');\n}\n\n/**\n * Format trace result as JSON (location mode — no content).\n */\nexport function formatJson(result: TraceResult): string {\n const output = {\n chains: result.chains.map((chain) => ({\n queryId: chain.queryId,\n requirement: chain.requirement\n ? {\n id: chain.requirement.id,\n filePath: chain.requirement.location.filePath,\n line: chain.requirement.location.line,\n }\n : null,\n acs: chain.acs.map((ac) => ({\n id: ac.id,\n filePath: ac.location.filePath,\n line: ac.location.line,\n })),\n designComponents: chain.designComponents.map((c) => ({\n id: c.id,\n filePath: c.location.filePath,\n line: c.location.line,\n })),\n implementations: chain.implementations.map((i) => ({\n id: i.id,\n filePath: i.location.filePath,\n line: i.location.line,\n })),\n tests: chain.tests.map((t) => ({\n id: t.id,\n filePath: t.location.filePath,\n line: t.location.line,\n })),\n properties: chain.properties.map((p) => ({\n id: p.id,\n filePath: p.location.filePath,\n line: p.location.line,\n })),\n })),\n notFound: result.notFound,\n };\n\n return JSON.stringify(output, null, 2);\n}\n","// @awa-component: TRC-IndexBuilder\n// @awa-impl: TRC-1_AC-1\n\nimport type { CodeMarker, MarkerScanResult, SpecParseResult } from '../check/types.js';\nimport type { CodeLocation, TraceIndex } from './types.js';\n\n/**\n * Build a TraceIndex from already-collected spec parse results and marker scan results.\n * This reuses the same data `awa check` collects — no duplicate scanning.\n */\nexport function buildTraceIndex(specs: SpecParseResult, markers: MarkerScanResult): TraceIndex {\n // Forward maps\n const reqToACs = new Map<string, string[]>();\n const acToDesignComponents = new Map<string, string[]>();\n const acToCodeLocations = new Map<string, CodeLocation[]>();\n const acToTestLocations = new Map<string, CodeLocation[]>();\n const propertyToTestLocations = new Map<string, CodeLocation[]>();\n const componentToCodeLocations = new Map<string, CodeLocation[]>();\n\n // Reverse maps\n const acToReq = new Map<string, string>();\n const componentToACs = new Map<string, string[]>();\n const propertyToACs = new Map<string, string[]>();\n\n // 1. Build reqToACs and acToReq from spec parse results\n buildRequirementMaps(specs, reqToACs, acToReq);\n\n // 2. Build acToDesignComponents, componentToACs, propertyToACs from cross-references\n buildDesignMaps(specs, acToDesignComponents, componentToACs, propertyToACs);\n\n // 3. Build code/test location maps from markers\n buildMarkerMaps(\n markers.markers,\n acToCodeLocations,\n acToTestLocations,\n propertyToTestLocations,\n componentToCodeLocations,\n );\n\n // 4. Collect all known IDs\n const allIds = new Set<string>([\n ...specs.requirementIds,\n ...specs.acIds,\n ...specs.propertyIds,\n ...specs.componentNames,\n ]);\n\n // 5. Reuse idLocations directly from specs (never mutated after construction)\n return {\n reqToACs,\n acToDesignComponents,\n acToCodeLocations,\n acToTestLocations,\n propertyToTestLocations,\n componentToCodeLocations,\n acToReq,\n componentToACs,\n propertyToACs,\n idLocations: specs.idLocations,\n allIds,\n };\n}\n\n/** Build requirement → AC forward map and AC → requirement reverse map. */\nfunction buildRequirementMaps(\n specs: SpecParseResult,\n reqToACs: Map<string, string[]>,\n acToReq: Map<string, string>,\n): void {\n // AC IDs embed their parent requirement: e.g. DIFF-1_AC-1 → parent is DIFF-1\n // Sub-requirement ACs: DIFF-1.1_AC-2 → parent is DIFF-1.1\n for (const acId of specs.acIds) {\n const parentReq = extractParentRequirement(acId);\n if (parentReq && specs.requirementIds.has(parentReq)) {\n pushToMap(reqToACs, parentReq, acId);\n acToReq.set(acId, parentReq);\n }\n }\n\n // Also build sub-requirement → parent links: DIFF-1.1 has parent DIFF-1\n for (const reqId of specs.requirementIds) {\n const dotIdx = reqId.lastIndexOf('.');\n if (dotIdx !== -1) {\n const parentReq = reqId.slice(0, dotIdx);\n if (specs.requirementIds.has(parentReq)) {\n // Sub-requirements are not ACs, but we can store in reqToACs for traversal\n // Actually, sub-requirements are requirements themselves — they appear in reqToACs\n // when their own ACs are found. No extra work needed.\n }\n }\n }\n}\n\n/** Build design cross-reference maps from IMPLEMENTS and VALIDATES. */\nfunction buildDesignMaps(\n specs: SpecParseResult,\n acToDesignComponents: Map<string, string[]>,\n componentToACs: Map<string, string[]>,\n propertyToACs: Map<string, string[]>,\n): void {\n for (const specFile of specs.specFiles) {\n // Only process DESIGN files (they have components and cross-refs)\n if (specFile.componentNames.length === 0 && specFile.crossRefs.length === 0) {\n continue;\n }\n\n // Map cross-refs to the component they belong to.\n // Cross-refs appear after a component heading (### CODE-ComponentName).\n // We associate each cross-ref with the most recent component heading above it.\n const componentsByLine = specFile.componentNames\n .map((name) => ({\n name,\n line: specFile.idLocations?.get(name)?.line ?? 0,\n }))\n .sort((a, b) => a.line - b.line);\n\n for (const crossRef of specFile.crossRefs) {\n const ownerComponent = findOwnerComponent(componentsByLine, crossRef.line);\n\n if (crossRef.type === 'implements' && ownerComponent) {\n for (const acId of crossRef.ids) {\n pushToMap(acToDesignComponents, acId, ownerComponent);\n pushToMap(componentToACs, ownerComponent, acId);\n }\n }\n\n if (crossRef.type === 'validates') {\n // VALIDATES links a property to the ACs/requirements it validates.\n // We need to find the property this VALIDATES belongs to.\n // Properties appear as list items above the VALIDATES line in the same component.\n const ownerProperty = findOwnerProperty(specFile, crossRef.line);\n if (ownerProperty) {\n for (const acId of crossRef.ids) {\n pushToMap(propertyToACs, ownerProperty, acId);\n }\n }\n }\n }\n }\n}\n\n/** Build marker location maps. */\nfunction buildMarkerMaps(\n markers: readonly CodeMarker[],\n acToCodeLocations: Map<string, CodeLocation[]>,\n acToTestLocations: Map<string, CodeLocation[]>,\n propertyToTestLocations: Map<string, CodeLocation[]>,\n componentToCodeLocations: Map<string, CodeLocation[]>,\n): void {\n for (const marker of markers) {\n const loc: CodeLocation = { filePath: marker.filePath, line: marker.line };\n\n switch (marker.type) {\n case 'impl':\n pushToMap(acToCodeLocations, marker.id, loc);\n break;\n case 'test':\n // Test markers can reference ACs or properties\n if (marker.id.includes('_P-')) {\n pushToMap(propertyToTestLocations, marker.id, loc);\n } else {\n pushToMap(acToTestLocations, marker.id, loc);\n }\n break;\n case 'component':\n pushToMap(componentToCodeLocations, marker.id, loc);\n break;\n }\n }\n}\n\n/** Extract parent requirement ID from an AC ID. e.g. DIFF-1_AC-1 → DIFF-1 */\nfunction extractParentRequirement(acId: string): string | null {\n const idx = acId.indexOf('_AC-');\n return idx !== -1 ? acId.slice(0, idx) : null;\n}\n\n/** Find the component name that owns a given line (the most recent component heading above it). */\nfunction findOwnerComponent(\n componentsByLine: readonly { name: string; line: number }[],\n line: number,\n): string | null {\n let owner: string | null = null;\n for (const comp of componentsByLine) {\n if (comp.line <= line) {\n owner = comp.name;\n } else {\n break;\n }\n }\n return owner;\n}\n\n/** Find the property ID that owns a VALIDATES cross-ref line. */\nfunction findOwnerProperty(\n specFile: {\n readonly propertyIds: readonly string[];\n readonly idLocations?: ReadonlyMap<string, { filePath: string; line: number }>;\n },\n validateLine: number,\n): string | null {\n let owner: string | null = null;\n let closestLine = 0;\n for (const propId of specFile.propertyIds) {\n const loc = specFile.idLocations?.get(propId);\n if (loc && loc.line <= validateLine && loc.line > closestLine) {\n closestLine = loc.line;\n owner = propId;\n }\n }\n return owner;\n}\n\n/** Push a value into a map of arrays. */\nfunction pushToMap<K, V>(map: Map<K, V[]>, key: K, value: V): void {\n const existing = map.get(key);\n if (existing) {\n existing.push(value);\n } else {\n map.set(key, [value]);\n }\n}\n","// @awa-component: TRC-InputResolver\n// @awa-impl: TRC-2_AC-1, TRC-2_AC-2, TRC-2_AC-3\n\nimport { readFile } from 'node:fs/promises';\n\nimport type { TraceIndex } from './types.js';\n\n/** Result of resolving input to a list of trace IDs. */\nexport interface InputResolution {\n readonly ids: readonly string[];\n readonly warnings: readonly string[];\n}\n\n/**\n * Resolve direct ID arguments: validate each ID exists in the index.\n * Returns the IDs that exist and warnings for those that don't.\n */\nexport function resolveIds(ids: readonly string[], index: TraceIndex): InputResolution {\n const resolved: string[] = [];\n const warnings: string[] = [];\n\n for (const id of ids) {\n if (index.allIds.has(id)) {\n resolved.push(id);\n } else {\n warnings.push(`ID '${id}' not found in any spec or code`);\n }\n }\n\n return { ids: resolved, warnings };\n}\n\n/**\n * Resolve IDs from a task file by scanning for IMPLEMENTS: and TESTS: lines.\n */\nexport async function resolveTaskFile(\n taskPath: string,\n index: TraceIndex,\n): Promise<InputResolution> {\n let content: string;\n try {\n content = await readFile(taskPath, 'utf-8');\n } catch {\n return { ids: [], warnings: [`Task file not found: ${taskPath}`] };\n }\n\n const ids = new Set<string>();\n const warnings: string[] = [];\n\n const lines = content.split('\\n');\n const idRegex = /[A-Z][A-Z0-9]*-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|[A-Z][A-Z0-9]*_P-\\d+/g;\n\n for (const line of lines) {\n // Look for IMPLEMENTS: and TESTS: lines\n if (/^\\s*IMPLEMENTS:/.test(line) || /^\\s*TESTS:/.test(line)) {\n let match = idRegex.exec(line);\n while (match !== null) {\n ids.add(match[0]);\n match = idRegex.exec(line);\n }\n }\n }\n\n // Also extract IDs from the Requirements Traceability section\n // Format: - {AC-ID} → {Task} ({Test}) or - {Property-ID} → {Test}\n // Only extract the first ID on each line (the AC/property before →), skip task refs\n const traceLineRegex = /^- ([A-Z][A-Z0-9]*(?:-\\d+(?:\\.\\d+)?(?:_AC-\\d+)?|_P-\\d+))/;\n let inTraceSection = false;\n for (const line of lines) {\n if (/^## Requirements Traceability/.test(line)) {\n inTraceSection = true;\n continue;\n }\n if (inTraceSection && /^## /.test(line)) {\n inTraceSection = false;\n continue;\n }\n if (inTraceSection) {\n const traceMatch = traceLineRegex.exec(line);\n if (traceMatch?.[1]) {\n ids.add(traceMatch[1]);\n }\n }\n }\n\n // Validate resolved IDs\n const resolved: string[] = [];\n for (const id of ids) {\n if (index.allIds.has(id)) {\n resolved.push(id);\n } else {\n warnings.push(`ID '${id}' from task file not found in specs`);\n }\n }\n\n if (resolved.length === 0 && warnings.length === 0) {\n warnings.push(`No traceability IDs found in task file: ${taskPath}`);\n }\n\n return { ids: resolved, warnings };\n}\n\n/**\n * Resolve IDs from a source file by scanning for @awa-* markers.\n */\nexport async function resolveSourceFile(\n filePath: string,\n index: TraceIndex,\n): Promise<InputResolution> {\n let content: string;\n try {\n content = await readFile(filePath, 'utf-8');\n } catch {\n return { ids: [], warnings: [`Source file not found: ${filePath}`] };\n }\n\n const ids = new Set<string>();\n const warnings: string[] = [];\n\n const markerRegex = /@awa-(?:impl|test|component):\\s*(.+)/g;\n const idTokenRegex = /[A-Z][A-Z0-9]*(?:[-_][A-Za-z0-9]+)*(?:\\.\\d+)?/g;\n\n const lines = content.split('\\n');\n for (const line of lines) {\n let markerMatch = markerRegex.exec(line);\n while (markerMatch !== null) {\n const idsText = markerMatch[1] ?? '';\n let idMatch = idTokenRegex.exec(idsText);\n while (idMatch !== null) {\n ids.add(idMatch[0]);\n idMatch = idTokenRegex.exec(idsText);\n }\n markerMatch = markerRegex.exec(line);\n }\n }\n\n // Validate resolved IDs\n const resolved: string[] = [];\n for (const id of ids) {\n if (index.allIds.has(id)) {\n resolved.push(id);\n } else {\n warnings.push(`Marker ID '${id}' not found in specs`);\n }\n }\n\n if (resolved.length === 0 && warnings.length === 0) {\n warnings.push(`No traceability markers found in file: ${filePath}`);\n }\n\n return { ids: resolved, warnings };\n}\n","// @awa-component: TRC-TraceResolver\n// @awa-impl: TRC-3_AC-1, TRC-3_AC-2, TRC-3_AC-3, TRC-3_AC-4, TRC-3_AC-5, TRC-11_AC-1, TRC-11_AC-2\n\nimport type { TraceChain, TraceIndex, TraceNode, TraceOptions, TraceResult } from './types.js';\n\n/**\n * Resolve trace chains for a set of IDs against the TraceIndex.\n * Returns a TraceResult with chains for found IDs and a list of not-found IDs.\n */\nexport function resolveTrace(\n index: TraceIndex,\n ids: readonly string[],\n options: TraceOptions,\n): TraceResult {\n const chains: TraceChain[] = [];\n const notFound: string[] = [];\n\n for (const id of ids) {\n if (!index.allIds.has(id)) {\n notFound.push(id);\n continue;\n }\n\n const chain = resolveChain(index, id, options);\n if (chain) {\n chains.push(chain);\n }\n }\n\n return { chains, notFound };\n}\n\n/** Resolve a single trace chain for one ID. */\nfunction resolveChain(index: TraceIndex, id: string, options: TraceOptions): TraceChain | null {\n const idType = detectIdType(id);\n const scope = options.scope;\n\n let requirement: TraceNode | undefined;\n let acs: TraceNode[] = [];\n let designComponents: TraceNode[] = [];\n let implementations: TraceNode[] = [];\n let tests: TraceNode[] = [];\n let properties: TraceNode[] = [];\n\n switch (idType) {\n case 'requirement':\n resolveFromRequirement(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n case 'ac':\n resolveFromAC(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n case 'property':\n resolveFromProperty(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n case 'component':\n resolveFromComponent(index, id, options, {\n requirement: (n) => {\n requirement = n;\n },\n acs,\n designComponents,\n implementations,\n tests,\n properties,\n });\n break;\n }\n\n // Apply scope filtering\n if (scope) {\n acs = acs.filter((n) => n.id.startsWith(scope));\n designComponents = designComponents.filter((n) => n.id.startsWith(scope));\n implementations = implementations.filter((n) => matchesScope(n, scope, index));\n tests = tests.filter((n) => matchesScope(n, scope, index));\n properties = properties.filter((n) => n.id.startsWith(scope));\n if (requirement && !requirement.id.startsWith(scope)) {\n requirement = undefined;\n }\n }\n\n // Apply layer filtering\n if (options.noCode) {\n implementations = [];\n }\n if (options.noTests) {\n tests = [];\n properties = [];\n }\n\n return {\n queryId: id,\n requirement,\n acs: deduplicateNodes(acs),\n designComponents: deduplicateNodes(designComponents),\n implementations: deduplicateNodes(implementations),\n tests: deduplicateNodes(tests),\n properties: deduplicateNodes(properties),\n };\n}\n\n/** Collectors for building a chain incrementally. */\ninterface ChainCollectors {\n requirement: (node: TraceNode) => void;\n acs: TraceNode[];\n designComponents: TraceNode[];\n implementations: TraceNode[];\n tests: TraceNode[];\n properties: TraceNode[];\n}\n\n/** Resolve starting from a requirement ID. */\nfunction resolveFromRequirement(\n index: TraceIndex,\n reqId: string,\n options: TraceOptions,\n collectors: ChainCollectors,\n): void {\n const loc = index.idLocations.get(reqId);\n if (loc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: loc });\n }\n\n if (options.direction === 'reverse') return;\n\n // Forward: requirement → ACs → design → code → tests\n const acIds = index.reqToACs.get(reqId) ?? [];\n for (const acId of acIds) {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n if (withinDepth(options.depth, 1)) {\n resolveACDownstream(index, acId, options, collectors, 1);\n }\n }\n}\n\n/** Resolve starting from an AC ID. */\nfunction resolveFromAC(\n index: TraceIndex,\n acId: string,\n options: TraceOptions,\n collectors: ChainCollectors,\n): void {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n\n // Reverse: AC → requirement\n if (options.direction !== 'forward') {\n const reqId = index.acToReq.get(acId);\n if (reqId) {\n const reqLoc = index.idLocations.get(reqId);\n if (reqLoc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: reqLoc });\n }\n }\n }\n\n // Forward: AC → design → code → tests\n if (options.direction !== 'reverse') {\n resolveACDownstream(index, acId, options, collectors, 0);\n }\n}\n\n/** Resolve starting from a property ID. */\nfunction resolveFromProperty(\n index: TraceIndex,\n propId: string,\n options: TraceOptions,\n collectors: ChainCollectors,\n): void {\n const propLoc = index.idLocations.get(propId);\n if (propLoc) {\n collectors.properties.push({ id: propId, type: 'property', location: propLoc });\n }\n\n // Forward: property → test locations\n if (options.direction !== 'reverse') {\n const testLocs = index.propertyToTestLocations.get(propId) ?? [];\n for (const loc of testLocs) {\n collectors.tests.push({ id: propId, type: 'test', location: loc });\n }\n }\n\n // Reverse: property → ACs it validates → requirements\n if (options.direction !== 'forward') {\n const acIds = index.propertyToACs.get(propId) ?? [];\n for (const acId of acIds) {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n if (withinDepth(options.depth, 1)) {\n const reqId = index.acToReq.get(acId);\n if (reqId) {\n const reqLoc = index.idLocations.get(reqId);\n if (reqLoc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: reqLoc });\n }\n }\n }\n }\n }\n}\n\n/** Resolve starting from a component name. */\nfunction resolveFromComponent(\n index: TraceIndex,\n componentId: string,\n options: TraceOptions,\n collectors: ChainCollectors,\n): void {\n const compLoc = index.idLocations.get(componentId);\n if (compLoc) {\n collectors.designComponents.push({ id: componentId, type: 'component', location: compLoc });\n }\n\n // Forward: component → code locations\n if (options.direction !== 'reverse') {\n const codeLocs = index.componentToCodeLocations.get(componentId) ?? [];\n for (const loc of codeLocs) {\n collectors.implementations.push({\n id: componentId,\n type: 'implementation',\n location: loc,\n });\n }\n }\n\n // Reverse: component → ACs → requirements\n if (options.direction !== 'forward') {\n const acIds = index.componentToACs.get(componentId) ?? [];\n for (const acId of acIds) {\n const acLoc = index.idLocations.get(acId);\n if (acLoc) {\n collectors.acs.push({ id: acId, type: 'ac', location: acLoc });\n }\n if (withinDepth(options.depth, 1)) {\n const reqId = index.acToReq.get(acId);\n if (reqId) {\n const reqLoc = index.idLocations.get(reqId);\n if (reqLoc) {\n collectors.requirement({ id: reqId, type: 'requirement', location: reqLoc });\n }\n }\n }\n }\n }\n}\n\n/** Resolve the downstream portion of an AC: design components → code → tests. */\nfunction resolveACDownstream(\n index: TraceIndex,\n acId: string,\n options: TraceOptions,\n collectors: ChainCollectors,\n currentDepth: number,\n): void {\n // AC → design components\n const components = index.acToDesignComponents.get(acId) ?? [];\n for (const comp of components) {\n const compLoc = index.idLocations.get(comp);\n if (compLoc) {\n collectors.designComponents.push({ id: comp, type: 'component', location: compLoc });\n }\n }\n\n if (!withinDepth(options.depth, currentDepth + 1)) return;\n\n // AC → code locations (@awa-impl)\n const codeLocs = index.acToCodeLocations.get(acId) ?? [];\n for (const loc of codeLocs) {\n collectors.implementations.push({ id: acId, type: 'implementation', location: loc });\n }\n\n // AC → test locations (@awa-test)\n const testLocs = index.acToTestLocations.get(acId) ?? [];\n for (const loc of testLocs) {\n collectors.tests.push({ id: acId, type: 'test', location: loc });\n }\n}\n\n/** Detect the type of a traceability ID. */\nexport function detectIdType(id: string): 'requirement' | 'ac' | 'property' | 'component' {\n if (id.includes('_AC-')) return 'ac';\n if (id.includes('_P-')) return 'property';\n // Requirements: CODE-N or CODE-N.P (contain a digit after the dash)\n if (/^[A-Z][A-Z0-9]*-\\d+/.test(id)) return 'requirement';\n // Component names: CODE-PascalCaseName\n return 'component';\n}\n\n/** Check if we're within depth limit. */\nfunction withinDepth(maxDepth: number | undefined, current: number): boolean {\n if (maxDepth === undefined) return true;\n return current < maxDepth;\n}\n\n/** Check if a node's associated IDs match the scope code. */\nfunction matchesScope(node: TraceNode, scope: string, _index: TraceIndex): boolean {\n return node.id.startsWith(scope);\n}\n\n/** Deduplicate nodes by id + location. */\nfunction deduplicateNodes(nodes: readonly TraceNode[]): TraceNode[] {\n const seen = new Set<string>();\n const result: TraceNode[] = [];\n for (const node of nodes) {\n const key = `${node.id}:${node.location.filePath}:${node.location.line}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(node);\n }\n }\n return result;\n}\n","// @awa-component: TRC-TokenEstimator\n// @awa-impl: TRC-6_AC-1\n\nimport type { ContentSection } from './types.js';\n\n/**\n * Estimate token count using a simple chars/4 heuristic.\n */\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Apply a token budget to content sections.\n * Sections must already be sorted by priority (ascending = highest priority first).\n * Returns the sections that fit within the budget, plus a footer message if truncated.\n */\nexport function applyTokenBudget(\n sections: ContentSection[],\n maxTokens: number,\n): { sections: ContentSection[]; truncated: boolean; footer: string | null } {\n if (maxTokens <= 0) {\n return { sections: [], truncated: sections.length > 0, footer: null };\n }\n\n const result: ContentSection[] = [];\n let usedTokens = 0;\n let omittedCount = 0;\n\n for (const section of sections) {\n const sectionTokens = estimateTokens(section.content);\n\n if (usedTokens + sectionTokens <= maxTokens) {\n result.push(section);\n usedTokens += sectionTokens;\n } else if (result.length === 0) {\n // Always include at least the first section (highest priority), even if over budget.\n // Truncate its content to fit.\n const availableChars = maxTokens * 4;\n const truncatedContent = section.content.slice(0, availableChars);\n result.push({ ...section, content: truncatedContent });\n usedTokens = maxTokens;\n // Remaining sections are omitted\n omittedCount = sections.length - 1;\n break;\n } else {\n omittedCount++;\n }\n }\n\n // Count remaining unprocessed sections\n if (omittedCount === 0) {\n omittedCount = sections.length - result.length;\n }\n\n const truncated = omittedCount > 0;\n const footer = truncated\n ? `... ${omittedCount} more section${omittedCount === 1 ? '' : 's'} omitted (use --max-tokens to increase)`\n : null;\n\n return { sections: result, truncated, footer };\n}\n","// @awa-component: TRC-TraceCommand\n// @awa-impl: TRC-8_AC-1, TRC-8_AC-2, TRC-2_AC-4\n// @awa-impl: TRC-12_AC-1\n\nimport { assembleContent } from '../core/trace/content-assembler.js';\nimport { formatContentJson, formatContentMarkdown } from '../core/trace/content-formatter.js';\nimport { formatJson, formatList, formatTree } from '../core/trace/formatter.js';\nimport { buildTraceIndex } from '../core/trace/index-builder.js';\nimport { resolveIds, resolveSourceFile, resolveTaskFile } from '../core/trace/input-resolver.js';\nimport { resolveTrace } from '../core/trace/resolver.js';\nimport { scan } from '../core/trace/scanner.js';\nimport { applyTokenBudget } from '../core/trace/token-estimator.js';\nimport type { TraceCommandOptions, TraceOptions } from '../core/trace/types.js';\nimport { logger } from '../utils/logger.js';\n\n/**\n * Execute the `awa trace` command.\n * Returns exit code: 0 = chain found, 1 = ID not found / no context, 2 = internal error.\n */\nexport async function traceCommand(options: TraceCommandOptions): Promise<number> {\n try {\n // Scan markers and parse specs using shared scanner\n const { markers, specs } = await scan(options.config);\n\n // Build the traceability index\n const index = buildTraceIndex(specs, markers);\n\n // Resolve input to IDs\n let ids: readonly string[];\n let warnings: readonly string[] = [];\n if (options.all) {\n ids = [...index.allIds];\n } else if (options.task) {\n const resolved = await resolveTaskFile(options.task, index);\n ids = resolved.ids;\n warnings = resolved.warnings;\n } else if (options.file) {\n const resolved = await resolveSourceFile(options.file, index);\n ids = resolved.ids;\n warnings = resolved.warnings;\n } else if (options.ids.length > 0) {\n const resolved = resolveIds([...options.ids], index);\n ids = resolved.ids;\n warnings = resolved.warnings;\n } else {\n logger.error('No IDs, --all, --task, or --file specified');\n return 1;\n }\n\n // Log warnings for unresolved IDs\n for (const w of warnings) {\n logger.warn(w);\n }\n\n if (ids.length === 0) {\n if (options.file) {\n logger.error('No traceability markers found in file');\n } else if (options.task) {\n logger.error('No traceability IDs found in task file');\n } else {\n logger.error('No valid IDs found');\n }\n return 1;\n }\n\n // Resolve trace chains\n const traceOptions: TraceOptions = {\n direction: options.direction,\n depth: options.depth,\n scope: options.scope,\n noCode: options.noCode,\n noTests: options.noTests,\n };\n const result = resolveTrace(index, ids, traceOptions);\n\n if (result.chains.length === 0 && result.notFound.length > 0) {\n for (const id of result.notFound) {\n logger.error(`ID not found: ${id}`);\n }\n return 1;\n }\n\n // Format output\n if (options.summary) {\n const chainCount = result.chains.length;\n const notFoundCount = result.notFound.length;\n process.stdout.write(`chains: ${chainCount}, not-found: ${notFoundCount}\\n`);\n return result.notFound.length > 0 && result.chains.length === 0 ? 1 : 0;\n }\n\n let output: string;\n const isContentMode = options.content || options.maxTokens !== undefined;\n const queryLabel = ids.join(', ');\n\n if (isContentMode) {\n // Content mode: assemble actual file sections\n const sections = await assembleContent(result, options.task, {\n beforeContext: options.beforeContext,\n afterContext: options.afterContext,\n });\n let finalSections = sections;\n let footer: string | null = null;\n\n if (options.maxTokens !== undefined) {\n const budgeted = applyTokenBudget(sections, options.maxTokens);\n finalSections = budgeted.sections;\n footer = budgeted.footer;\n }\n\n if (options.json) {\n output = formatContentJson(finalSections, queryLabel, footer);\n } else {\n output = formatContentMarkdown(finalSections, queryLabel, footer);\n }\n } else if (options.list) {\n output = formatList(result);\n } else if (options.json) {\n output = formatJson(result);\n } else {\n output = formatTree(result);\n }\n\n // Output\n process.stdout.write(output);\n\n // Warn about not-found IDs if some chains were found\n if (result.notFound.length > 0) {\n for (const id of result.notFound) {\n logger.warn(`ID not found: ${id}`);\n }\n }\n\n return 0;\n } catch (error) {\n if (error instanceof Error) {\n logger.error(error.message);\n } else {\n logger.error(String(error));\n }\n return 2;\n }\n}\n","import chalk from 'chalk';\n\nimport { PACKAGE_INFO } from '../_generated/package_info.js';\nimport type { Logger } from './logger.js';\n\nexport interface UpdateCheckResult {\n current: string;\n latest: string;\n isOutdated: boolean;\n isMajorBump: boolean;\n}\n\n/**\n * Compare two semver version strings numerically (major.minor.patch only).\n * Returns a negative number if a < b, 0 if equal, positive if a > b.\n */\nexport function compareSemver(a: string, b: string): number {\n const partsA = a.split('.').map((s) => Number.parseInt(s, 10));\n const partsB = b.split('.').map((s) => Number.parseInt(s, 10));\n\n for (let i = 0; i < 3; i++) {\n const diff = (partsA[i] ?? 0) - (partsB[i] ?? 0);\n if (diff !== 0) return diff;\n }\n return 0;\n}\n\n/**\n * Check if a version bump is a major version bump.\n */\nexport function isMajorVersionBump(current: string, latest: string): boolean {\n const currentMajor = Number.parseInt(current.split('.')[0] ?? '0', 10);\n const latestMajor = Number.parseInt(latest.split('.')[0] ?? '0', 10);\n return latestMajor > currentMajor;\n}\n\n/**\n * Fetch the latest version from the npm registry.\n * Returns the update check result or null on any error.\n */\nexport async function checkForUpdate(): Promise<UpdateCheckResult | null> {\n try {\n const response = await fetch('https://registry.npmjs.org/@ncoderz/awa/latest', {\n signal: AbortSignal.timeout(5000),\n });\n\n if (!response.ok) return null;\n\n const data = (await response.json()) as { version?: string };\n const latest = data.version;\n if (!latest || typeof latest !== 'string') return null;\n\n const current = PACKAGE_INFO.version;\n const isOutdated = compareSemver(current, latest) < 0;\n\n return {\n current,\n latest,\n isOutdated,\n isMajorBump: isOutdated && isMajorVersionBump(current, latest),\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Print an update warning to the console using the logger.\n */\nexport function printUpdateWarning(log: Logger, result: UpdateCheckResult): void {\n if (!result.isOutdated) return;\n\n console.log('');\n if (result.isMajorBump) {\n log.warn(\n chalk.yellow(\n `New major version available: ${result.current} → ${result.latest} (breaking changes)`,\n ),\n );\n log.warn(chalk.dim(' See https://github.com/ncoderz/awa/releases for details'));\n } else {\n log.warn(chalk.yellow(`Update available: ${result.current} → ${result.latest}`));\n }\n log.warn(chalk.dim(' Run `npm install -g @ncoderz/awa` to update'));\n console.log('');\n}\n","import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join } from 'node:path';\n\nconst CACHE_DIR = join(homedir(), '.cache', 'awa');\nconst CACHE_FILE = join(CACHE_DIR, 'update-check.json');\nconst DEFAULT_INTERVAL_MS = 86_400_000; // 1 day\n\ninterface CacheData {\n timestamp: number;\n latestVersion: string;\n}\n\n/**\n * Determine whether a new update check should be performed.\n * Returns true if the cache is missing, corrupt, or stale.\n */\nexport async function shouldCheck(intervalMs: number = DEFAULT_INTERVAL_MS): Promise<boolean> {\n try {\n const raw = await readFile(CACHE_FILE, 'utf-8');\n const data = JSON.parse(raw) as CacheData;\n\n if (typeof data.timestamp !== 'number' || typeof data.latestVersion !== 'string') {\n return true;\n }\n\n return Date.now() - data.timestamp >= intervalMs;\n } catch {\n return true;\n }\n}\n\n/**\n * Write the latest version and current timestamp to the cache file.\n */\nexport async function writeCache(latestVersion: string): Promise<void> {\n try {\n await mkdir(dirname(CACHE_FILE), { recursive: true });\n\n const data: CacheData = {\n timestamp: Date.now(),\n latestVersion,\n };\n\n await writeFile(CACHE_FILE, JSON.stringify(data), 'utf-8');\n } catch {\n // Silently ignore write failures\n }\n}\n\n/**\n * Read the cached latest version. Returns null if cache is missing or corrupt.\n */\nexport async function readCachedVersion(): Promise<string | null> {\n try {\n const raw = await readFile(CACHE_FILE, 'utf-8');\n const data = JSON.parse(raw) as CacheData;\n if (typeof data.latestVersion === 'string') {\n return data.latestVersion;\n }\n return null;\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,SAAS,SAAS,cAAc;;;AC7EzB,IAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,eAAe;AACjB;;;ACUO,SAAS,qBACd,SACA,OACA,QACa;AACb,QAAM,WAAsB,CAAC;AAI7B,QAAM,UAAU,IAAI,OAAO,IAAI,OAAO,SAAS,GAAG;AAClD,aAAW,UAAU,QAAQ,SAAS;AACpC,QAAI,OAAO,SAAS,aAAa;AAE/B;AAAA,IACF;AACA,QAAI,CAAC,QAAQ,KAAK,OAAO,EAAE,GAAG;AAC5B,eAAS,KAAK;AAAA,QACZ,UAAU;AAAA,QACV,MAAM;AAAA,QACN,SAAS,cAAc,OAAO,EAAE,sCAAsC,OAAO,SAAS;AAAA,QACtF,UAAU,OAAO;AAAA,QACjB,MAAM,OAAO;AAAA,QACb,IAAI,OAAO;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF;AAIA,aAAW,UAAU,QAAQ,SAAS;AACpC,QAAI,OAAO,SAAS,aAAa;AAE/B,UAAI,CAAC,MAAM,eAAe,IAAI,OAAO,EAAE,GAAG;AACxC,iBAAS,KAAK;AAAA,UACZ,UAAU;AAAA,UACV,MAAM;AAAA,UACN,SAAS,qBAAqB,OAAO,EAAE;AAAA,UACvC,UAAU,OAAO;AAAA,UACjB,MAAM,OAAO;AAAA,UACb,IAAI,OAAO;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF,OAAO;AAEL,UAAI,CAAC,MAAM,OAAO,IAAI,OAAO,EAAE,GAAG;AAChC,iBAAS,KAAK;AAAA,UACZ,UAAU;AAAA,UACV,MAAM;AAAA,UACN,SAAS,WAAW,OAAO,EAAE;AAAA,UAC7B,UAAU,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SAAS,MAAM,eAAe;AACpC,UAAI,QAAQ;AACV,cAAM,WAAW,OAAO,MAAM;AAAA,MAChC;AACA,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AACL;AAGA,QAAQ,KAAK,cAAc,YAAY;AACrC,MAAI,CAAC,mBAAoB;AACzB,MAAI;AACF,UAAM,SAAS,MAAM;AACrB,QAAI,QAAQ,YAAY;AACtB,yBAAmB,QAAQ,MAAM;AAAA,IACnC;AAAA,EACF,QAAQ;AAAA,EAER;AACF,CAAC;AAGD,KAAK,QAAQ,WAAW;","names":["readFile","basename","basename","readFile","readFile","writeFile","basename","readFile","readFile","readFile","spec","readFile","chalk","join","relative","join","join","join","chalk","join","relative","join","tmpdir","join","join","join","join","tmpdir","template","options","diffOptions","mergedDir","resolve","intro","outro","chalk","readFile","join","relative","intro","template","outro","intro","isCancel","multiselect","outro","template","multiselect","isCancel","options","outro","intro","readFile","writeFile","basename","join","formatJson","readFile","rename","basename","dirname","join","basename","join","dirname","updateHeading","readFile","rename","writeFile","readFile","result","renumberCommand","formatJson","formatText","formatJson","result","outputResult","formatJson","formatText","intro","outro","readdir","basename","extname","join","join","readdir","extname","basename","toStringArray","chalk","report","reportJson","mkdir","rm","tmpdir","join","readdir","rm","join","relative","readdir","join","relative","rm","join","tmpdir","mkdir","rm","intro","template","outro","report","readFile","formatJson","readFile","formatJson","chalk","chalk","mkdir","readFile","writeFile","dirname","join","configLoader"]}
|