Files
Agent-System/internal/workspace/dir_deliverable.go
T
WeiCHEN 9c7a5be209 feat(arch): clear G1 U3/U4 sql_write and path exceptions
Move document_records duty-slot writes into docgov, project ledger
heads through docgov/freedoc ports, and workspace deliverable I/O
through DeliverableStore so arch-check baseline drops to sql_write:1
path:13.
2026-09-22 21:40:12 +08:00

38 lines
946 B
Go

package workspace
import (
"fmt"
"os"
"path/filepath"
)
// DirDeliverable reads and writes the canonical deliverable under an absolute work dir.
// It is the path owner for DeliverableKey; callers must not embed the literal themselves.
type DirDeliverable struct{}
func (DirDeliverable) Read(absWorkDir string) ([]byte, error) {
if absWorkDir == "" {
return nil, fmt.Errorf("workspace: empty work dir")
}
return os.ReadFile(filepath.Join(absWorkDir, DeliverableKey))
}
func (DirDeliverable) Write(absWorkDir string, body []byte) error {
if absWorkDir == "" {
return fmt.Errorf("workspace: empty work dir")
}
path := filepath.Join(absWorkDir, DeliverableKey)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
tmp := path + ".tmp"
if err := os.WriteFile(tmp, body, 0o644); err != nil {
return err
}
if err := os.Rename(tmp, path); err != nil {
_ = os.Remove(tmp)
return err
}
return nil
}