Metadata-Version: 2.4
Name: bylines
Version: 0.5.0
Summary: Verify that an AI agent's submitted work was really written in its session: replay transcripts, classify every line by first appearance, and check authorship, time-window and revision rules.
Author: kaamura
License: MIT
Project-URL: Homepage, https://github.com/kaamura-ai/bylines
Project-URL: Repository, https://github.com/kaamura-ai/bylines
Keywords: ai-agent,attestation,provenance,transcript,verification
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# bylines

[![CI](https://github.com/kaamura-ai/bylines/actions/workflows/ci.yml/badge.svg)](https://github.com/kaamura-ai/bylines/actions)

**A receipt for agent work.**

An AI agent did the work. Can it prove it? `bylines` replays the agent's
session transcripts, reconstructs the repository exactly as the session
built it, and classifies **every line by first appearance** — so honest
agent work comes with a receipt the author can hand over, and anyone can
check. Not a policing tool: a piece of paper that makes agent labour
legible, and tradeable.

## For authors: prove your work

You steered an agent through a real session — hours of iteration, not a
one-prompt paste. From the outside, the two look identical. bylines lets
you attach the proof:

```
# 1. Verify your own work before you hand it over
bylines verify --repo ./myrepo --sessions ~/.claude/projects/-myrepo \
  --harness claude-code --policy policy.toml \
  --out report.json --md report.md

# 2. Redact the transcripts into a shareable bundle
#    (prompts and tool outputs removed; the verdict survives)
bylines redact --sessions ~/.claude/projects/-myrepo \
  --harness claude-code --anchor myrepo --out ./attestation

# 3. The bundle is hash-chained at redaction time, so nobody can edit
#    it afterwards without breaking verification (see below)

# 4. Render the badge and paste the snippet into your PR or README
bylines badge --report report.json --out badge.svg
```

Commit `attestation/` and `badge.svg` next to the code. A reviewer can
re-run the verification and get the same verdict — deterministically,
offline, with no account and no trust in you required.

## What bylines does not prove

Read this before you rely on a verdict, in either direction.

`bylines` proves **internal consistency**: these transcripts reproduce
this artifact under these rules. It does **not** prove:

- that the transcripts are authentic — a determined forger can fabricate
  a transcript; bylines makes forgery *costly*, not impossible;
- that a human was present, or supervised anything;
- that the timestamps are true — they are self-reported clocks.

The hash chain proves a bundle is unchanged *since redaction*. It does
not prove the redaction itself was honest: a forger can redact a
doctored transcript and chain that. The full threat model is in
`DESIGN.md`. bylines' position: raise the cost of faking from zero to
substantial, and make honest work readable. That is all, and it is
enough to be useful.

## For reviewers: check a receipt

Given a repository and its transcripts (raw, or a redacted bundle),
`bylines`:

1. **Replays** every `write`/`edit` tool call in timestamp order,
   reconstructing each file exactly as the session built it.
2. **Classifies every line by first appearance.** A line counts as
   *agent-authored* only if its first appearance in the transcript is
   inside a `write`/`edit` payload. Lines that first surfaced in a tool
   result, a file read, a shell output, or a pasted blob stay *external*
   forever — later edits cannot launder them into authored lines.
3. **Checks the rules** a reviewer actually cares about:
   - `reproduces` — enough of the final code was agent-authored, little
     enough came from nowhere;
   - `in_window` — the work happened inside the allowed time window;
   - `revised` — files reached their final content through real
     iteration, not a single paste;
   - `coverage` — every file in the repo is accounted for: authored,
     declared (vendored / binary / generated, with hashes), or flagged
     unexplained;
   - `chain` — a redacted bundle's hash chain is intact: no record was
     edited, deleted, inserted, or reordered after redaction.
4. **Emits a deterministic report** (`report.json` + a human-readable
   Markdown summary). Same inputs, same verdict — re-run it yourself.

Exit code: `0` pass, `1` fail, `2` input error.

## Install

```
pipx install bylines
```

(or `pip install bylines`.)

Python 3.11+, standard library only. No network, no API keys, fully
offline.

## Quickstart

```
bylines verify \
  --repo ./my-entry \
  --sessions ./bundle/sessions \
  --harness claude-code \
  --policy policy.toml \
  --out report.json --md report.md
```

`--harness` selects the transcript format: `muse` (Muse session JSONL,
the default), `claude-code` (`~/.claude/projects/**/*.jsonl`, subagent
transcripts included), `codex` (`~/.codex/sessions/**/rollout-*.jsonl`,
including `apply_patch` writes), or `events` (redacted bylines bundles,
below).

## Redacted bundles and hash chains

Raw transcripts contain your prompts and everything your tools printed —
not something you publish. `bylines redact` converts them into a
shareable bylines event file:

```
bylines redact --sessions ~/.claude/projects/-home-dev-myrepo \
  --harness claude-code --anchor myrepo --out ./attestation
bylines verify --repo ./myrepo --sessions ./attestation --harness events
```

Redaction keeps timestamps, tool-call structure and the `write`/`edit`
payloads (those lines are the artifact itself — the repo already
publishes them), and removes all conversation text and tool outputs.
Outputs survive only as per-line SHA-256 hashes, which is exactly what
verification needs: a line first sighted in an output is still
classified *external*, so a pasted file still fails — the verdict on a
redacted bundle is the verdict on the raw transcript.

`bylines redact` also writes a `<stem>.chain.json` sidecar: every record
is hashed together with the hash of the record before it, so any edit,
deletion, insertion or reorder in the bundle breaks the chain.
`bylines verify --harness events` recomputes the chain and fails the
`chain` check on any mismatch, naming the first broken record. Bundles
made before v0.4 have no sidecar and still verify (the chain check
reports `warn`); run `bylines chain --sessions ./attestation` to anchor
them after the fact.

## The badge

`bylines badge --report report.json --out badge.svg` renders a static,
self-contained SVG badge — verdict and authored percentage — and prints
the Markdown snippet to paste next to it:

```
![bylines: verified · authored 77.4%](badge.svg)
```

No badge service, no tracking pixel, no network: the SVG is generated
locally from your report and lives in your repo like any other file.

## GitHub Action

Commit a redacted bundle with your repo and verify it in CI:

```yaml
- uses: actions/checkout@v4
- uses: kaamura-ai/bylines@v0.5.0
  with:
    sessions: ./attestation
    harness: events
    policy: ./policy.toml
```

The action fails the job on a `fail` verdict and uploads `report.json` /
`report.md` as artifacts.

On `pull_request` events it also posts the verdict summary as a PR
comment (updated in place on re-runs, not spammed). That requires the
workflow token to be allowed to comment:

```yaml
permissions:
  pull-requests: write
```

Set `comment: "false"` in the action inputs to disable the comment.

## Policy (TOML)

```toml
[window]
opens  = "2026-12-01T00:00:00Z"
closes = "2026-12-07T00:00:00Z"

[counted]
include = ["**/*.py", "**/*.md"]
exclude = ["vendor/**", "*.min.js"]

[reproduces]
authored_min   = 0.30
unwritten_max  = 0.40

[revised]
min_files = 1
min_ops   = 2

[coverage]
unexplained = "fail"   # or "warn"
```

## Status

v0.5 — Muse, Claude Code and Codex transcript adapters, replay engine,
the five checks (reproduces / in_window / revised / coverage / chain),
JSON/Markdown reports, redacted bundles (`bylines redact`) with
hash-chain anchoring, a verified badge (`bylines badge`), and a GitHub
Action that can join the PR conversation (see `DESIGN.md`, `ROADMAP.md`).

Validated against a production corpus: a real contest submission
verified by a platform's own (closed) checker reproduces the same
verdict under bylines, from both the raw and the redacted transcript.

See `examples/self-verification/` for bylines verifying its own
development session — bundle, policy and report included, warts and all.

## License

MIT
