feat: add demo evidence bundle
Browse filesCo-authored-by: Codex <noreply@openai.com>
Files changed (7)
95 unmodified lines9697989910010195 unmodified linesadvisor engine as a normal user session, so the demo state can be used immediately with JSONL, Notes, Chapter, LoRA,Packet, and PNG exports.## Prize Ledger`/api/prize-ledger` and the in-app Prize Ledger panel expose submission evidence: the documented model stack, total95 unmodified lines9697989910010110210310410510610710895 unmodified linesadvisor engine as a normal user session, so the demo state can be used immediately with JSONL, Notes, Chapter, LoRA,Packet, and PNG exports.## Demo Evidence Bundle`/api/demo-bundle.zip` and the `Bundle` button download a server-built ZIP for the deterministic demo session. Thebundle includes a manifest, demo session JSON, Prize Ledger JSON, trace JSONL, Field Notes, Almanac chapter, LoRA SFTJSONL, Submission Packet, and a PNG export note. This gives judges or collaborators one auditable package withoutdepending on browser `localStorage`.## Prize Ledger`/api/prize-ledger` and the in-app Prize Ledger panel expose submission evidence: the documented model stack, total
4 unmodified lines56789101112131483 unmodified lines98991001011021034 unmodified linesfrom pathlib import Pathfrom typing import Iteratorfrom fastapi.responses import FileResponse, HTMLResponse, JSONResponsefrom gradio import Serverfrom hackathon_advisor.agent import AdvisorEnginefrom hackathon_advisor.chapter import build_chapter_markdownfrom hackathon_advisor.data import ProjectIndexfrom hackathon_advisor.demo_rehearsal import build_demo_rehearsal83 unmodified linesreturn build_demo_rehearsal(engine)@app.api(name="tool_contract_check", concurrency_limit=8)def tool_contract_check(model_output: str, fallback_query: str = "") -> dict:return resolve_tool_call(model_output, fallback_query=fallback_query).to_dict()4 unmodified lines5678910111213141583 unmodified lines991001011021031041051061071081091101111121131141151161171181191204 unmodified linesfrom pathlib import Pathfrom typing import Iteratorfrom fastapi.responses import FileResponse, HTMLResponse, JSONResponse, Responsefrom gradio import Serverfrom hackathon_advisor.agent import AdvisorEnginefrom hackathon_advisor.artifact_bundle import BUNDLE_FILENAME, build_demo_bundle_zipfrom hackathon_advisor.chapter import build_chapter_markdownfrom hackathon_advisor.data import ProjectIndexfrom hackathon_advisor.demo_rehearsal import build_demo_rehearsal83 unmodified linesreturn build_demo_rehearsal(engine)@app.get("/api/demo-bundle.zip")def demo_bundle() -> Response:runtime_status = engine.runtime_status()ledger = prize_ledger(runtime_status)metadata = {**trace_metadata(index),"project_count": len(index.projects),}content = build_demo_bundle_zip(build_demo_rehearsal(engine), metadata, ledger)return Response(content=content,media_type="application/zip",headers={"Content-Disposition": f'attachment; filename="{BUNDLE_FILENAME}"'},)@app.api(name="tool_contract_check", concurrency_limit=8)def tool_contract_check(model_output: str, fallback_query: str = "") -> dict:return resolve_tool_call(model_output, fallback_query=fallback_query).to_dict()
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899from __future__ import annotations
from datetime import datetime, timezonefrom io import BytesIOimport jsonfrom typing import Anyfrom zipfile import ZIP_DEFLATED, ZipFile
from hackathon_advisor.chapter import build_chapter_markdownfrom hackathon_advisor.field_notes import build_field_notes_markdownfrom hackathon_advisor.lora_dataset import build_lora_dataset_jsonlfrom hackathon_advisor.submission_packet import build_submission_packet_markdownfrom hackathon_advisor.trace_export import build_trace_jsonl
BUNDLE_SCHEMA_VERSION = 1BUNDLE_FILENAME = "hackathon-advisor-demo-bundle.zip"
def build_demo_bundle_zip( demo: dict[str, Any], metadata: dict[str, Any], ledger: dict[str, Any],) -> bytes: session = demo.get("session") if isinstance(demo.get("session"), dict) else {} files = _bundle_files(session, metadata, ledger, demo) manifest = _manifest(files, metadata, ledger, demo)
buffer = BytesIO() with ZipFile(buffer, "w", compression=ZIP_DEFLATED) as archive: archive.writestr("manifest.json", json.dumps(manifest, ensure_ascii=False, indent=2, sort_keys=True) + "\n") for filename, content in files.items(): archive.writestr(filename, content) return buffer.getvalue()
def _bundle_files( session: dict[str, Any], metadata: dict[str, Any], ledger: dict[str, Any], demo: dict[str, Any],) -> dict[str, str]: return { "demo-session.json": json.dumps(demo, ensure_ascii=False, indent=2, sort_keys=True) + "\n", "prize-ledger.json": json.dumps(ledger, ensure_ascii=False, indent=2, sort_keys=True) + "\n", "trace.jsonl": build_trace_jsonl(session, metadata), "field-notes.md": build_field_notes_markdown(session, metadata), "almanac-chapter.md": build_chapter_markdown(session, metadata), "lora-sft.jsonl": build_lora_dataset_jsonl(session, metadata), "submission-packet.md": build_submission_packet_markdown(session, metadata, ledger), "png-export-note.md": _png_note(demo), }
def _manifest( files: dict[str, str], metadata: dict[str, Any], ledger: dict[str, Any], demo: dict[str, Any],) -> dict[str, Any]: badges = ledger.get("badges") if isinstance(ledger.get("badges"), list) else [] return { "type": "demo_bundle_manifest", "schema_version": BUNDLE_SCHEMA_VERSION, "generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"), "app": "hackathon-advisor", "turn_count": int(demo.get("turn_count") or 0), "file_count": len(files), "files": list(files), "runtime": ledger.get("runtime") if isinstance(ledger.get("runtime"), dict) else {}, "badge_status": { str(badge.get("name")): str(badge.get("status")) for badge in badges if isinstance(badge, dict) }, "index": { "algorithm": _clean(metadata.get("index_algorithm")), "snapshot_generated_at": _clean(metadata.get("snapshot_generated_at")), "index_generated_at": _clean(metadata.get("index_generated_at")), "snapshot_digest": _clean(metadata.get("snapshot_digest")), }, }
def _png_note(demo: dict[str, Any]) -> str: artifact = demo.get("artifact") if isinstance(demo.get("artifact"), dict) else {} title = _clean(artifact.get("title")) or "current fate page" return ( "# PNG Export Note\n\n" "The visual fate-page PNG is rendered client-side from the same session artifact so the browser can draw the " "canvas with the deployed CSS and fonts. Load the Demo session in the Space, then press `PNG` to export it.\n\n" f"Demo artifact title: {title}\n" )
def _clean(value: Any) -> str: if value is None: return "" return " ".join(str(value).split())24 unmodified lines25262728293050 unmodified lines818283848586526 unmodified lines61361461561661761824 unmodified linesconst exportChapterButton = document.querySelector("#export-chapter");const exportLoraButton = document.querySelector("#export-lora");const exportPacketButton = document.querySelector("#export-packet");const resetButton = document.querySelector("#reset-session");const SESSION_STORAGE_KEY = "hackathon-advisor-session-v1";50 unmodified linesawait exportSubmissionPacket();});resetButton.addEventListener("click", () => {clearSavedSession();window.location.reload();526 unmodified linesfunction setCommandDisabled(disabled) {document.querySelectorAll(".command-row button").forEach((button) => {const isArtifact = button.id === "export-artifact";const isTrace = button.id === "export-trace";const isNotes = button.id === "export-notes";24 unmodified lines2526272829303150 unmodified lines82838485868788899091526 unmodified lines61861962062162262362424 unmodified linesconst exportChapterButton = document.querySelector("#export-chapter");const exportLoraButton = document.querySelector("#export-lora");const exportPacketButton = document.querySelector("#export-packet");const exportBundleButton = document.querySelector("#export-bundle");const resetButton = document.querySelector("#reset-session");const SESSION_STORAGE_KEY = "hackathon-advisor-session-v1";50 unmodified linesawait exportSubmissionPacket();});exportBundleButton.addEventListener("click", () => {window.location.assign("/api/demo-bundle.zip");});resetButton.addEventListener("click", () => {clearSavedSession();window.location.reload();526 unmodified linesfunction setCommandDisabled(disabled) {document.querySelectorAll(".command-row button").forEach((button) => {if (button.id === "export-bundle") return;const isArtifact = button.id === "export-artifact";const isTrace = button.id === "export-trace";const isNotes = button.id === "export-notes";
37 unmodified lines38394041424337 unmodified lines<button type="button" id="export-chapter" title="Export the Almanac chapter" disabled>Chapter</button><button type="button" id="export-lora" title="Export the LoRA SFT dataset" disabled>LoRA</button><button type="button" id="export-packet" title="Export the submission packet" disabled>Packet</button><button type="button" id="export-artifact" title="Export the current fate page" disabled>PNG</button><button type="button" id="reset-session" title="Clear the saved session">Reset</button></div>37 unmodified lines3839404142434437 unmodified lines<button type="button" id="export-chapter" title="Export the Almanac chapter" disabled>Chapter</button><button type="button" id="export-lora" title="Export the LoRA SFT dataset" disabled>LoRA</button><button type="button" id="export-packet" title="Export the submission packet" disabled>Packet</button><button type="button" id="export-bundle" title="Download the demo evidence bundle">Bundle</button><button type="button" id="export-artifact" title="Export the current fate page" disabled>PNG</button><button type="button" id="reset-session" title="Clear the saved session">Reset</button></div>
12345678120 unmodified lines129130131132133134import jsonfrom app import (bootstrap,chapter_artifact,demo_session,engine,field_notes_artifact,120 unmodified linesassert payload["export_ready"]["submission_packet"] is Truedef test_tool_contract_check_endpoint_defaults_safely() -> None:payload = tool_contract_check("broken", "family archive")1234567891011120 unmodified lines132133134135136137138139140141142143144145146147148149150151import jsonfrom io import BytesIOfrom zipfile import ZipFilefrom app import (bootstrap,chapter_artifact,demo_bundle,demo_session,engine,field_notes_artifact,120 unmodified linesassert payload["export_ready"]["submission_packet"] is Truedef test_demo_bundle_endpoint_returns_zip_attachment() -> None:response = demo_bundle()assert response.media_type == "application/zip"assert "hackathon-advisor-demo-bundle.zip" in response.headers["content-disposition"]with ZipFile(BytesIO(response.body)) as archive:names = set(archive.namelist())manifest = json.loads(archive.read("manifest.json"))assert "submission-packet.md" in namesassert "lora-sft.jsonl" in namesassert manifest["turn_count"] == 2def test_tool_contract_check_endpoint_defaults_safely() -> None:payload = tool_contract_check("broken", "family archive")
1234567891011121314151617181920212223242526272829303132333435363738394041424344import jsonfrom io import BytesIOfrom pathlib import Pathfrom zipfile import ZipFile
from hackathon_advisor.agent import AdvisorEnginefrom hackathon_advisor.artifact_bundle import build_demo_bundle_zipfrom hackathon_advisor.data import ProjectIndexfrom hackathon_advisor.demo_rehearsal import build_demo_rehearsalfrom hackathon_advisor.prize_ledger import prize_ledgerfrom hackathon_advisor.trace_export import trace_metadata
def test_demo_bundle_contains_submission_evidence_files() -> None: index = ProjectIndex.from_files(Path("data/projects.json"), Path("data/project_index.json")) engine = AdvisorEngine(index) metadata = { **trace_metadata(index), "project_count": len(index.projects), } content = build_demo_bundle_zip(build_demo_rehearsal(engine), metadata, prize_ledger(engine.runtime_status()))
with ZipFile(BytesIO(content)) as archive: names = set(archive.namelist()) manifest = json.loads(archive.read("manifest.json")) trace = archive.read("trace.jsonl").decode("utf-8") packet = archive.read("submission-packet.md").decode("utf-8")
assert names == { "manifest.json", "demo-session.json", "prize-ledger.json", "trace.jsonl", "field-notes.md", "almanac-chapter.md", "lora-sft.jsonl", "submission-packet.md", "png-export-note.md", } assert manifest["type"] == "demo_bundle_manifest" assert manifest["turn_count"] == 2 assert manifest["badge_status"]["Well-Tuned"] == "dataset-ready" assert "agent_turn" in trace assert "## Prize Evidence" in packetREADME.md+7
app.py+18-1
hackathon_advisor/artifact_bundle.pyAdded+99
static/app.js+6
static/index.html+1
tests/test_app.py+17
tests/test_artifact_bundle.pyAdded+44