Skip to content

feat(spec-compiler): sin-code compile-spec CLI + YAML→JSON compiler (issue #164, v0 spike)#212

Merged
Delqhi merged 1 commit into
mainfrom
feat/issue-164-spec-compiler
Jun 16, 2026
Merged

feat(spec-compiler): sin-code compile-spec CLI + YAML→JSON compiler (issue #164, v0 spike)#212
Delqhi merged 1 commit into
mainfrom
feat/issue-164-spec-compiler

Conversation

@Delqhi

@Delqhi Delqhi commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Implements the fifth of the 5 issues. Scope-bounded to v0 (Schema + Parser + Validator + 4 Emitters + CLI + round-trip tests). Engine wiring and remote spec inheritance are follow-ups per the issue body.

What ships

  • cmd/sin-code/internal/spec/compiler/ — 4 source files + 24 tests
    • schema.go — Config + Project + Verify + Hooks + Permissions + Loop
    • parse.go — Parse(bytes) + ParseFile + InitTemplate
    • validate.go — field-path validation
    • emit.go — EmitHooks/Verify/Permissions/Loop (4 JSON contracts)
  • cmd/sin-code/compile_spec_cmd.go — cobra subcommand
    • --init (write starter .sin-code.yml)
    • default (compile → 4 derived JSONs)
    • --check (CI: fail if derived files are stale)
    • --out <dir>, --dry-run
  • SPEC-COMPILER.md + CHANGELOG entry
  • main.go: register NewCompileSpecCmd

Mandate compliance

  • M1 (n8n CI): sin-code compile-spec runs locally; --check is intended for CI but the work happens in the operator's checkout, not on the GitHub runner.
  • M2 (single binary): gopkg.in/yaml.v3 is already in go.mod as a transitive dep. No new dependency.
  • M5 (module path): new code in cmd/sin-code/internal/spec/compiler/. No module-path changes.
  • M6 (SIN tools over naive built-ins): the schema is designed so the engines can adopt it without new types — the JSON contract mirrors the existing struct shapes where possible.

Acceptance criteria (from #164)

  • The schema is documented (SPEC-COMPILER.md)
  • sin-code compile-spec round-trips: spec → derived → no diff on re-run (TestRoundTrip is the load-bearing test)
  • The schema validates with clear error messages on invalid input (24 Validate_* tests)
  • Test coverage ≥ 80%

What does NOT ship (deferred per issue body)

  • Engine wiring (v1.1, ~2 weeks): the three engines must learn to read their derived JSON files. They currently read code, not config. This is a refactor of internal/{hooks,verify,permission}.
  • Remote spec inheritance (v2): extends: org/sin-code-base.yml
  • Spec testing (v2): sin spec test that asserts the spec is consistent

Relationship to issue #155 (Pro-Repo-Konfiguration)

Live smoke test

$ sin-code compile-spec --init --out /tmp/test
wrote /tmp/test/.sin-code.yml

$ sin-code compile-spec --out /tmp/test
wrote /tmp/test/.sin/hooks.json (55 bytes)
wrote /tmp/test/internal/verify/config.json (157 bytes)
wrote /tmp/test/internal/permission/policies.json (60 bytes)
wrote /tmp/test/.sin/loop.json (18 bytes)

$ sin-code compile-spec --out /tmp/test --check
all derived files are in sync

Diffstat

 9 files changed, 1086 insertions(+), 1 deletion(-)

Closes

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sin-code Ready Ready Preview, Comment, Open in v0 Jun 16, 2026 6:13pm

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

🏆 CEO Audit — A+ (100.0/100)

Metric Value
Grade A+
Score 100.0/100
Critical findings 0
High findings 0
Profile QUICK
Min grade gate B

📥 Download full report (Markdown)
📊 Download SARIF (for Code Scanning)

Run ~/.config/opencode/skills/ceo-audit/scripts/audit.sh . --profile=QUICK locally to reproduce.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

🏆 CEO Audit — A+ (100.0/100)

Metric Value
Grade A+
Score 100.0/100
Critical findings 0
High findings 0
Medium findings 0
Profile QUICK
Min grade gate B

📥 Download full report (Markdown)

Run ID: 27638350051 · Commit: ${github.sha}

Run ~/.config/opencode/skills/ceo-audit/scripts/audit.sh . --profile=QUICK locally to reproduce.

// Default to a project matching the cwd name, type "go".
name := filepath.Base(outDir)
data := compiler.InitTemplate(name, "go")
if err := os.MkdirAll(outDir, 0o755); err != nil {
if err := os.MkdirAll(outDir, 0o755); err != nil {
return err
}
if err := os.WriteFile(path, data, 0o644); err != nil {
}
// Atomic write: temp file + rename, so a crash mid-write
// never leaves a half-written file behind.
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
return err
}
tmp := dest + ".tmp"
if err := os.WriteFile(tmp, f.Data, 0o644); err != nil {
drift := false
for _, f := range files {
dest := filepath.Join(outDir, f.Path)
existing, err := os.ReadFile(dest)
// config" — the former is a hint to run `sin-code compile-spec
// --init`, the latter is a hard fail).
func ParseFile(path string) (*Config, error) {
b, err := os.ReadFile(path)
…issue #164, v0 spike)

What ships:
  - cmd/sin-code/internal/spec/compiler/ — 4 source files + 24 tests
    - schema.go:  Config + Project + Verify + Hooks + Permissions + Loop
    - parse.go:   Parse(bytes) + ParseFile + InitTemplate
    - validate.go: field-path validation (predicate/hook names unique, etc)
    - emit.go:    EmitHooks/Verify/Permissions/Loop — 4 JSON contracts
  - cmd/sin-code/compile_spec_cmd.go — cobra subcommand
    - --init (write starter .sin-code.yml)
    - default (compile → 4 derived JSONs)
    - --check (CI: fail if derived files are stale)
    - --out <dir>, --dry-run
  - SPEC-COMPILER.md + CHANGELOG entry
  - main.go: register NewCompileSpecCmd

Mandate compliance:
  - M1: compile-spec runs locally; --check is intended for CI
        but the work happens in the operator's checkout, not on
        the GitHub runner.
  - M2: gopkg.in/yaml.v3 is already in go.mod as a transitive dep.
        No new dependency.
  - M5: new code in cmd/sin-code/internal/spec/compiler/. No
        module-path changes.
  - M6: the schema is designed so the engines can adopt it
        without new types — the JSON contract mirrors the
        existing struct shapes where possible.

Acceptance criteria (from #164):
  - [x] The schema is documented (SPEC-COMPILER.md)
  - [x] sin-code compile-spec round-trips: spec → derived → no
        diff on re-run (TestRoundTrip is the load-bearing test)
  - [x] The schema validates with clear error messages on
        invalid input (24 Validate_* tests)
  - [x] Test coverage ≥ 80%

What does NOT ship (deferred per issue body):
  - Engine wiring (v1.1, ~2 weeks): the three engines must
    learn to read their derived JSON files. They currently
    read code, not config. This is a refactor of
    internal/{hooks,verify,permission}.
  - Remote spec inheritance (v2): 'extends: org/sin-code-base.yml'
  - Spec testing (v2): 'sin spec test' that asserts the spec
    is consistent

Relationship to issue #155 (Pro-Repo-Konfiguration):
  - Issue #155 proposes .sin-code.yml for loop parameters only.
  - The v0 schema includes those fields as the 'loop:' block.
  - When #164 v1.1 lands and the loop builder reads .sin/loop.json,
    issue #155 is closed by reference. The two issues describe
    different slices of the same eventual file.

Refs: #164
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