Files
pipelines/internal/turn/layout.go
T

53 lines
1.6 KiB
Go

// Package turn owns the file layout and markdown contracts for file-based
// stage turns. It deliberately has no dependency on the server, protocol or
// stage packages: callers persist and execute turns, while this package keeps
// their paths and plain-markdown shapes deterministic.
package turn
import (
"fmt"
"os"
"path/filepath"
)
// Paths is the complete on-disk layout for one stage visit.
type Paths struct {
RunDir string
Sequence int
StageKey string
TurnDir string
InputPath string
MemoryPath string
OutputPath string
PrivateDir string
PublicDir string
}
// Layout returns the deterministic paths for a stage turn. The sequence is
// zero-padded to two digits; longer sequences keep all of their digits.
func Layout(runDir string, sequence int, stageKey string) Paths {
turnDir := filepath.Join(runDir, "stages", fmt.Sprintf("%02d-%s", sequence, stageKey))
return Paths{
RunDir: runDir,
Sequence: sequence,
StageKey: stageKey,
TurnDir: turnDir,
InputPath: filepath.Join(turnDir, "input.md"),
MemoryPath: filepath.Join(turnDir, "memory.md"),
OutputPath: filepath.Join(turnDir, "output.md"),
PrivateDir: filepath.Join(turnDir, "private"),
PublicDir: filepath.Join(runDir, "public"),
}
}
// Ensure creates the turn, private and run-level public directories. It is
// idempotent and never removes or rewrites anything already present.
func (p Paths) Ensure() error {
for _, dir := range []string{p.TurnDir, p.PrivateDir, p.PublicDir} {
if err := os.MkdirAll(dir, 0o700); err != nil {
return fmt.Errorf("turn: create %s: %w", dir, err)
}
}
return nil
}