| 227 | |
| 228 | /** Read a specific version's content (defaults to current). */ |
| 229 | export async function getArtifact(cwd: string, id: string, version?: number): Promise<{ manifest: ArtifactManifest; version: number; content: string; absFile: string }> { |
| 230 | const manifest = await readManifest(cwd, id); |
| 231 | if (!manifest) throw new Error(`Artifact "${id}" not found.`); |
| 232 | const v = version ?? manifest.current; |
| 233 | const entry = manifest.versions.find(x => x.v === v); |
| 234 | if (!entry) throw new Error(`Artifact "${id}" has no version ${v}.`); |
| 235 | const absFile = path.join(artifactDir(cwd, id), entry.file); |
| 236 | const content = await fs.readFile(absFile, 'utf-8'); |
| 237 | return { manifest, version: v, content, absFile }; |
| 238 | } |
| 239 | |
| 240 | /** Roll the "current" pointer back to an earlier (existing) version — no new file. */ |
| 241 | export async function rollbackArtifact(cwd: string, id: string, toVersion: number, write: WriteFn, now = new Date().toISOString()): Promise<ArtifactManifest> { |