Complete Phase 2 Go normalization foundation

This commit is contained in:
2026-05-11 00:41:29 +00:00
parent d847168ecd
commit 10377876e4
11 changed files with 480 additions and 1241 deletions

View File

@@ -14,10 +14,9 @@ import (
// RunDirectory represents a per-run diagnostics directory
type RunDirectory struct {
path string
retention string
createdAt time.Time
sourceSaved bool
path string
retention string
createdAt time.Time
}
// NewRunDirectory creates a new run directory under the configured work dir
@@ -31,9 +30,8 @@ func NewRunDirectory(workDir, retention string) (*RunDirectory, error) {
return nil, fmt.Errorf("failed to create work directory %q: %w", workDir, err)
}
// Create unique run directory with timestamp
timestamp := time.Now().UTC().Format("2006-01-02T15-04-05Z")
runID := fmt.Sprintf("run-%s", timestamp)
// Create a unique run directory identifier.
runID := fmt.Sprintf("run-%d", time.Now().UTC().UnixNano())
runPath := filepath.Join(workDir, runID)
if err := os.Mkdir(runPath, 0o755); err != nil {
@@ -71,7 +69,6 @@ func (r *RunDirectory) WriteSourceTranscript(transcript *schema.SourceTranscript
return fmt.Errorf("failed to write parsed source transcript: %w", err)
}
r.sourceSaved = true
return nil
}
@@ -122,24 +119,21 @@ func (r *RunDirectory) WriteErrorLog(errorMessage string) error {
return os.WriteFile(errorPath, []byte(errorMessage+"\n"), 0o644)
}
// ApplyRetention applies the retention policy
// TODO: In later phases, implement full retention logic including:
// - auto mode should keep runs with skipped corrections
// - Add proper cleanup of old runs
// - Consider disk space limits
func (r *RunDirectory) ApplyRetention() error {
// For Phase 2, implement minimal retention:
// - always: keep everything (do nothing)
// - never: remove successful runs
// - auto: remove successful runs (same as never for now)
// - failed runs are always kept (handled by caller)
if r.retention == "never" || r.retention == "auto" {
// Remove successful runs
if r.sourceSaved { // Simple heuristic: if we saved source, it was successful
return os.RemoveAll(r.path)
}
// ApplyRetention applies a minimal phase-2 retention policy.
// TODO: In later phases, implement full "auto" semantics based on skip/report outcomes.
func (r *RunDirectory) ApplyRetention(runSucceeded bool) error {
if !runSucceeded {
// Failed runs are always retained.
return nil
}
switch r.retention {
case "always":
return nil
case "never", "auto":
return os.RemoveAll(r.path)
default:
// Retain by default for unknown modes; config validation should prevent this.
return nil
}
// always: keep everything, or failed runs: keep everything
return nil
}