Skip to content

Spec-to-diff: verify repo-grounded specs before generating diffs #21

Open

Description

@angelrdavila

Problem

Models often guess at paths, symbols, and APIs when proposing edits. The result is diffs that look plausible but do not compile or apply against the live tree: phantom files, wrong package boundaries, signatures that do not exist, or changes anchored to stale mental models of the repo.

Repo maps, semantic search, and LSP tools improve discovery, but they do not by themselves guarantee that the edit plan is grounded in what is actually on disk before the harness asks for a patch.

Proposed approach

Spec-to-diff grounding — the provider (or context backend) builds a concrete, verified task spec before diff generation:

  1. Scope on demand — From the user goal (and optional paths), resolve only the relevant slice of the repo (not a whole-repo map dump): candidate files, symbols to touch, call relationships, and expected behavior constraints.
  2. Live resolution — Every claim in the spec is resolved against the live workspace (read/hash/git state): file exists, symbol at line/range, signature/type as reported by parser/LSP or equivalent, imports and callers where needed.
  3. Validated spec artifact — Emit a structured spec (files, edit targets, invariants, test expectations) that fails closed if resolution fails (missing path, ambiguous symbol, drift since last read).
  4. Diff from spec — The model (or a dedicated edit step) generates the diff from the spec, not from free-form imagination of structure. Invalid specs never reach patch application.

This pairs naturally with thee’s session director and optional hosted context path: the client keeps the tool loop; the backend owns resolution, validation, and serving the spec bundle into the generation step.

Open questions

  • vs repo maps (Aider-style): PageRank/tree-sitter maps orient the model but are not a verified edit contract. Where does spec-to-diff sit — replace map, augment map, or post-map validation only?
  • vs LSP-on-demand (OpenCode-style): Tools return definitions/references when the model asks; nothing forces a single validated plan before patch. Do we require an explicit spec phase in the state machine?
  • vs localization pipelines (SWE-agent, Agentless, Loc2Repair): File/symbol localization is often a separate stage; repair is soft-guided. Is our spec a hard gate or soft hints with verifier fallback?
  • vs IDE indexing (Cursor): Semantic + grep indexes improve retrieval; they do not produce a machine-checkable edit spec. Can we reuse index chunks only as inputs to resolution?
  • Latency and cost: Two-phase (resolve → edit) vs interleaved tool loop; cache keys for resolved specs (see semantic caching issue).
  • Portability: Spec validation when the workspace is dirty, shallow clone, or multi-root; behavior when LSP is unavailable (tree-sitter-only?).

Research comparing harnesses on this axis is in flight; this issue should be updated when that lands (repo maps, LSP, pre-diff validation, localization-only patterns).

Success criteria (draft)

  • Measurable drop in apply failures, phantom paths, and compile/test failures on first apply on the eval basket vs baseline.
  • Spec rejection is observable in trace (spec_invalid, symbol_not_found, file_hash_mismatch) without logging full file bodies in strict mode.
  • Spec scope stays within token/caps; resolution time acceptable for interactive thee.

Related

  • Repo map tool spec (docs/harness-architecture/tools/repo-map.md)
  • Context engine / retrieval (docs/harness-architecture/context-engine.md)
  • Patch tool and apply ladder (docs/harness-architecture/tools/patch.md)
  • OSS harness comparison (docs/harness-architecture/oss-comparison.md)
  • Benchmarks / hidden-check eval (docs/benchmarks.md)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions