import { createHash, randomUUID } from "node:crypto";
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Firedrill } from "@firedrill-run/sdk";
const directory = mkdtempSync(join(tmpdir(), "firedrill-capture-"));
const client = Firedrill.fromConfig();
const result = await client.simulate({
name: "Retain a structured observation",
scenarios: [{
id: "message",
name: "Observe supplied message",
input: { message: "Ready for review" },
}],
}, async (input, context) => {
const content = Buffer.from(JSON.stringify({ observedMessage: input.message }));
const path = join(directory, "observation.json");
writeFileSync(path, content, { mode: 0o600, flag: "wx" });
const retained = await context.attach({
path,
artifact: {
id: randomUUID(),
name: "observation.json",
kind: "file",
mediaType: "application/json",
bytes: content.length,
sha256: createHash("sha256").update(content).digest("hex"),
capturedAt: new Date().toISOString(),
metadata: { provenance: "runner_reported" },
},
});
return { message: input.message, artifactId: retained.id };
});
console.log(result.reportUrl);
console.log("Private original capture:", directory);