Files
Tabish Bidiwale d73705736f feat: make apply instructions schema-aware (#444)
* feat: make apply instructions schema-aware

The `generateApplyInstructions` function was hardcoded to check for
`spec-driven` artifacts. This change makes it read artifact definitions
from the schema's new `apply` block, enabling support for different
workflows like TDD.

Changes:
- Add `ApplyPhaseSchema` Zod schema with `requires`, `tracks`, and
  `instruction` fields to types.ts
- Update `SchemaYamlSchema` to include optional `apply` field
- Add `apply` block to spec-driven and tdd schemas
- Refactor `generateApplyInstructions` to:
  - Load schema via `resolveSchema()`
  - Read `apply.requires` for required artifacts
  - Check artifact existence dynamically (supports glob patterns)
  - Use `apply.tracks` for progress tracking (or skip if null)
  - Use `apply.instruction` for custom guidance
  - Build `contextFiles` from all existing artifacts in schema
- Handle fallback when schema has no `apply` block (require all artifacts)
- Add 8 new tests for schema-aware apply behavior

* fix: improve apply instructions robustness and consistency

- Fix artifactOutputExists to properly handle glob patterns cross-platform
  by using path.sep and verifying actual file matches
- Remove redundant if/else in contextFiles loop
- Distinguish between missing tracks file vs empty tracks file
- Use consistent { error: } key in ApplyPhaseSchema validation
- Rename fallback test to accurately describe what it tests

* test: add fallback behavior tests for schemas without apply block

Add two tests that verify the fallback logic when a schema lacks an
apply block:
- Blocks when not all artifacts exist (requires ALL artifacts)
- Ready state with default instruction when all artifacts exist

Uses XDG_DATA_HOME to create temporary user schemas for testing.
2026-01-05 22:45:27 -08:00

1.3 KiB

Prerequisites

  • 0.1 Implement add-per-change-schema-metadata first (to auto-detect schema)

1. Schema Format

  • 1.1 Add ApplyPhaseSchema Zod schema to src/core/artifact-graph/types.ts
  • 1.2 Update SchemaYamlSchema to include optional apply field
  • 1.3 Export ApplyPhase type

2. Update Existing Schemas

  • 2.1 Add apply block to schemas/spec-driven/schema.yaml
  • 2.2 Add apply block to schemas/tdd/schema.yaml

3. Refactor generateApplyInstructions

  • 3.1 Load schema via resolveSchema(schemaName)
  • 3.2 Read apply.requires to determine required artifacts
  • 3.3 Check artifact existence dynamically (not hardcoded paths)
  • 3.4 Use apply.tracks for progress tracking (or skip if null)
  • 3.5 Use apply.instruction for the instruction text
  • 3.6 Build contextFiles from all existing artifacts in schema

4. Handle Fallback

  • 4.1 If schema has no apply block, require all artifacts to exist
  • 4.2 Default instruction: "All artifacts complete. Proceed with implementation."

5. Tests

  • 5.1 Test apply instructions with spec-driven schema
  • 5.2 Test apply instructions with tdd schema
  • 5.3 Test fallback when schema has no apply block
  • 5.4 Test blocked state when required artifacts missing