ReadLatest reads the latest handoff artifact if it exists. Returns (nil, nil) when no artifact is present.
(root string)
| 54 | // ReadLatest reads the latest handoff artifact if it exists. |
| 55 | // Returns (nil, nil) when no artifact is present. |
| 56 | func ReadLatest(root string) (*Artifact, error) { |
| 57 | path := LatestPath(root) |
| 58 | data, err := os.ReadFile(path) |
| 59 | if err != nil { |
| 60 | if os.IsNotExist(err) { |
| 61 | return nil, nil |
| 62 | } |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | var artifact Artifact |
| 67 | if err := json.Unmarshal(data, &artifact); err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | normalizeArtifact(&artifact) |
| 71 | |
| 72 | return &artifact, nil |
| 73 | } |
| 74 | |
| 75 | // WriteLatest writes an artifact atomically to .codemap/handoff.latest.json. |
| 76 | func WriteLatest(root string, artifact *Artifact) error { |