Skip to content

Add stable machine-parseable receipt schema to top-level CLI (publish / fetch-metrics)#7

Open
AlyciaBHZ wants to merge 2 commits into
mainfrom
feat/stable-receipt-schema
Open

Add stable machine-parseable receipt schema to top-level CLI (publish / fetch-metrics)#7
AlyciaBHZ wants to merge 2 commits into
mainfrom
feat/stable-receipt-schema

Conversation

@AlyciaBHZ

Copy link
Copy Markdown
Collaborator

Why

broadcast-kit is increasingly consumed as the egress executor behind other systems (the FKST reddit package already shells out to it; more FKST marketing packages — social-metrics, douyin/xhs publishers — will follow). Today those consumers must scrape inconsistent JSON: URL fields differ per platform (post_url / note_url / video_url), status values vary (success / ok / failed), and per-publisher CLIs print human text. Every consumer ends up writing brittle parsing.

This PR gives the top-level broadcast-kit publish and broadcast-kit fetch-metrics a stable, versioned receipt contract so any caller can depend on fixed field names/types instead of reverse-engineering output.

What

  • New broadcast_kit/receipts.py normalizes only the top-level command result just before print.
  • Two receipt types:
    • broadcast.publish.receipt.v0 — always-present: platform, status (ok|dry_run|blocked|error), account_label, dry_run, post_uri (unified from post_url/note_url/video_url/url), evidence_path, reason.
    • broadcast.metrics.fetch_receipt.v0 — always-present: platform, status (ok|dry_run|stub|error), account_label, dry_run, metrics_path (incl. legacy source.raw_path fallback), records, preview, reason.
  • Backward compatible: legacy fields preserved; original status kept as raw_status when remapped; for fetch-metrics --platform all the nested records items are left untouched (top-level-only normalization).
  • XHS metrics stays honest status: "stub" (no faked collector).
  • Unknown fetch statuses normalize to error (safe default for a contract).
  • Contract doc: contracts/receipts.md — including the rule that automation should parse only the top-level publish / fetch-metrics JSON, never the per-publisher CLIs (which are non-contract).
  • Tests: tests/test_cli_receipts.py — 28 tests pass, covering key presence, records preservation for --platform all, raw_status retention, URL/evidence normalization, and the source.raw_path fallback.

Non-goals

No changes to publisher/collector behavior, per-publisher CLIs, or any live-publish path. Purely additive output normalization.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant