538143554c
Every stage used to be told to read memory.md, the full output of every earlier turn (19 KB average, 92 KB max), and paid for it on each model call. memory.md is now essential memory, hard-capped at 4 KB and inlined in the prompt: the task, the previous stage's # handoff section (or its truncated output head), a one-line-per-stage outcome ledger and the server-captured changed files. history.md keeps the old full memory on disk; read-capable stages are pointed at it and input.md for on-demand detail, and it is never inlined. The prompt asks each stage for a short # handoff section.
57 lines
1.8 KiB
Go
57 lines
1.8 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
|
|
// HistoryPath is the full accumulated history; MemoryPath is the short,
|
|
// capped essential memory that is inlined into the prompt.
|
|
HistoryPath 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"),
|
|
HistoryPath: filepath.Join(turnDir, "history.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
|
|
}
|