Skip to content

Conversation

Copy link

Copilot AI commented Dec 19, 2025

Build a Go CLI tool that compares configuration files (YAML, JSON, TOML, INI) by semantic meaning rather than text diff. Handles nested structures, ignores key ordering, and outputs colored diffs or machine-readable JSON.

Architecture

  • Unified AST (pkg/ast): Normalizes all formats into a common tree representation with typed nodes (Map, Array, String, Number, Bool, Null)
  • Format parsers (pkg/parser): Auto-detects and parses each format into the AST using established libraries (yaml.v3, BurntSushi/toml, ini.v1)
  • Comparison engine (pkg/diff): Traverses ASTs recursively, tracking paths with dot notation (e.g., server.host[0]), classifying changes as Added/Removed/Modified
  • Output formatters (pkg/output): Renders diffs as colored terminal output, plain text, or JSON

Usage

# Colored diff with path tracking
$ go-config-diff config1.yaml config2.yaml
~ database.credentials.password
  - "secret123"
  + "newsecret456"
+ server.timeout
  + 60

# Machine-readable for CI/CD
$ go-config-diff -format=json old.toml new.toml
{
  "has_changes": true,
  "changes": [
    {
      "type": "modified",
      "path": "database.name",
      "old_value": "myapp",
      "new_value": "myapp_prod"
    }
  ]
}

Exit code 0 when identical, 1 when different. Order-independent map comparison ensures {"a": 1, "b": 2} equals {"b": 2, "a": 1}.

Implementation notes

  • Parser outputs interface{} converted to AST via reflection for type safety
  • INI sections mapped to nested objects (section name as key)
  • Array comparison by index; future optimization could add content-based matching for reordered arrays
  • Test coverage includes format detection, parsing, semantic equality, and nested structure comparison
Original prompt

Build a Go utility that compares configuration files (YAML, JSON, TOML, INI) semantically rather than line-by-line. Normalize structures, detect meaningful differences, and ignore ordering or formatting. Provide colored diffs and machine-readable output. Use Go parsers for each format and a unified internal AST model.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 19, 2025 19:40
Co-authored-by: BaseMax <2658040+BaseMax@users.noreply.github.com>
Co-authored-by: BaseMax <2658040+BaseMax@users.noreply.github.com>
Co-authored-by: BaseMax <2658040+BaseMax@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Go utility for comparing configuration files semantically Implement semantic configuration file comparison utility Dec 19, 2025
Copilot AI requested a review from BaseMax December 19, 2025 19:47
@BaseMax BaseMax marked this pull request as ready for review December 19, 2025 21:39
@BaseMax
Copy link
Owner

BaseMax commented Dec 19, 2025

@copilot Build a Go utility that compares configuration files (YAML, JSON, TOML, INI) semantically rather than line-by-line. Normalize structures, detect meaningful differences, and ignore ordering or formatting. Provide colored diffs and machine-readable output. Use Go parsers for each format and a unified internal AST model.

@BaseMax BaseMax merged commit ec3f4de into main Dec 19, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants