The Go rewrite should be compatibility-first. The existing Python implementation should be treated as the executable specification for public behavior, pipeline semantics, diagnostics, and safety rules.
The rewrite should not begin as a redesign. The first production-capable Go version should be able to stand in for the Python CLI in the surrounding transcript pipeline.
The initial goal is:
```text
same public contract
same pipeline semantics
same safety posture
same diagnostic philosophy
idiomatic Go implementation
reliable subprocess behavior
```
Exact LLM output parity is not required because LLM calls are nondeterministic and may vary by backend, prompt formatting, model, or structured-output implementation. Deterministic framework behavior should be held to a much stricter compatibility standard.
## Core principles
1. Preserve behavior before improving behavior.
2. Port deterministic layers before LLM layers.
3. Test with fake LLMs before testing with real LLMs.
4. Keep module stages sequential until correctness is established.
5. Add bounded concurrency only after the sequential implementation is correct.
6. Keep the CLI contract stable for downstream callers.
7. Keep stdout/stderr behavior clean and predictable.
8. Treat diagnostics and reports as part of the product, not as afterthoughts.
9. Avoid prompt improvements during the port.
10. Prefer explicit Go structs and validation over reflection-heavy abstractions.
## Compatibility targets
The Go implementation should preserve the following public behaviors where practical:
-`audita process` command shape;
- transcript input support for bare segment arrays and `{ "segments": [...] }` objects;
- glossary YAML support;
- default module sequence;
- repeated module instance naming;
- environment variable and CLI flag configuration concepts;
- CLI-over-env precedence;
- output file behavior;
- stdout behavior when `--output` is omitted;
- stderr logging behavior;
- separate `--report-json` machine-readable report behavior;
- work-dir diagnostics behavior;
- retention modes `auto`, `always`, and `never`;
- failed-run diagnostics preservation;
- skipped-change reporting instead of crashing on stale or unsafe proposal application.
- deterministic transcript proposal application in stable proposal-index order;
- applied and skipped change records with stable skip reasons;
- report/diagnostic-oriented chunking summary and chunk metadata hooks;
- minimal framework contracts/interfaces for future modules, validators, and structured LLM clients;
- test-only fake-module composition tests proving chunking and proposal application can work together.
The Go rewrite does **not** yet include end-to-end transcript polishing behavior:
- no real module execution pipeline yet;
- no real `glossary`, `homophones`, `spoken_word`, or `grammar` module implementations;
- no LLM proposal generation;
- no validator-chain execution;
- no concrete structured LLM client implementation;
- no final LLM-driven transcript polishing behavior comparable to Python production runs.
This means the Go binary should not be described as a complete LLM transcript polisher yet.
## Developer quick note
Use these commands while developing deterministic rewrite phases:
```sh
go test ./...
go run ./cmd/audita process internal/cli/testdata/tiny_transcript.json --glossary internal/cli/testdata/tiny_glossary.yaml --output /tmp/audita-go-output.json --report-json /tmp/audita-go-report.json
```
The second command is a representative CLI wiring check only; it is not a real LLM polishing run in the current phase.
The Go rewrite has completed Phase 2 with the following capabilities:
### Implemented Features:
1.**Typed Schema Validation**:
- Transcript validation supports both bare segment arrays and objects with `segments` field
- Glossary validation matches the existing YAML format
- Comprehensive field validation and error reporting
2.**Deterministic Normalization**:
- Chronological sorting of segments
- Same-speaker adjacent segment merging with configurable gap thresholds
- Ellipsis insertion for gaps above the ellipsis threshold
- Configurable maximum segment duration and token limits
- Sequential ID reassignment starting at 1
- Category preservation during merging
3.**Process Output**:
- Output is normalized transcript JSON (not raw passthrough)
- Canonical transcript shape as specified in architecture docs
- Proper stdout/stderr discipline preserved from Phase 1
4.**Enhanced Reporting**:
- Success reports include normalization statistics
- Failure reports include error phase and concise messages
- No secrets leaked to reports
5.**Minimal Diagnostics**:
- Per-run work directories with unique timestamps
- Source transcript artifacts (raw and parsed)
- Normalized transcript artifacts
- Normalization summary artifacts
- Authoritative report.json in run directory
- Error logs on failure
- Basic retention policy implementation
### Not Yet Implemented (Future Phases):
- Chunking and token-bounded section building
- LLM proposal generation and structured output
- Validator chains and decision logging
- Module execution pipeline
- Full diagnostics retention policy
- Skipped correction detection for auto retention
- Real module implementations (glossary, homophones, spoken_word, grammar)
### Compatibility Notes:
The Go implementation maintains the public CLI contract from the Python implementation:
-`audita process transcript.json --glossary glossary.yaml --output corrected.json`
- stdout contains transcript JSON when --output is omitted
- stderr contains logs and errors only
- --report-json writes machine-readable reports
- Nonzero exit codes on failure
The normalization behavior is deterministic and matches the architectural specifications, but may differ from Python-era behavior in edge cases until full module implementation is complete.
An HTTP API should be deferred until the Go CLI is stable.
Consider HTTP later only if one or more of these become true:
- multiple callers need a shared long-running Audita worker;
- process startup time becomes a meaningful bottleneck;
- a job queue is needed;
- remote execution becomes necessary;
- centralized concurrency control is preferable to per-process control;
- operational monitoring of Audita as a service becomes valuable.
Even then, the HTTP API should wrap the same core Go pipeline used by the CLI. The CLI should remain the simplest and most reliable integration surface.