Classification

Content Type Taxonomy

IN THIS DOCUMENT

Crimson marks the heading currently in view; every entry is one of the document's own headings.

The classifier labeled every payload that enters the compression pipeline with a content type so thresholds and previews can adapt per type - errors stay visible in context while Aphrodite compressed verbose build and log output at the base threshold.

Classification is layered: a vendored base classifier assigns one of seven coarse types, an Aphrodite-side semantic detector refines common tool-output shapes, the Hermes bridge unwraps wrapper envelopes before either runs, and an explicit caller-supplied type hint always wins.

Across all stages the pipeline can emit 30 distinct content types.

The preview each type produces is documented in the Enriched Preview Catalog.

Classification Pipeline

StageWhereRole
Base classifierheadroom-core content detectorCoarse type: JSON array, source code, search results, build output, diff, HTML, plain text. Confidence-gated, first match wins
Semantic refinementcrates/aphrodite/src/preview.rsRefines common shapes (test output, git status/log, ls, grep, tables, markdown, YAML, XML, CSV) that the base classifier flattens to text
Proxy heuristicscrates/aphrodite/src/proxy.rsThe standalone proxy path’s own ladder: JSON envelopes, per-language code, errors, build, linter, diff, git, log
Envelope unwrapcrates/aphrodite-hermes/src/tools.rsThe Hermes plugin path: unwraps {output, exit_code}, {diff}, {error}, {total_count, matches}, {content, total_lines} envelopes before classifying the payload

The proxy path classifies raw pushed content; the Hermes plugin path unwraps envelopes first, then runs the same base classifier and semantic detector on the extracted payload.

Both paths share the semantic detector, so the semantic detector tagged a git status or ls -l result the same way whether it arrived through the proxy or through a Hermes tool call.

Base Classifier (7 Types)

The vendored headroom-core content detector is regex-based and confidence-gated: each candidate type must clear a confidence floor, and the first candidate to clear its floor wins.

JSON objects deliberately do not match - only arrays do - so an object falls through to text.

TypeDetection signalConfidence floor
json_arrayStrict JSON parse of an array ([-prefixed)none (strongest signal)
diffdiff --git, diff --cc, --- a/, @@ -A,B +C,D @@, @@@ hunk headers0.7
html<!DOCTYPE html / <html / structural tags0.7
searchpath:line: prefix on a majority of non-blank lines0.6
buildLog-level markers, timestamps, test verdicts, npm ERR! / cargo error0.5
source_codePer-language pattern votes (python, javascript, typescript, go, rust, java)0.5
textFallback0.5 (0.0 for empty input)

Semantic Refinement (15 Types)

detect_semantic_type runs after the base classifier and before the loose first-line heuristics.

Detection is deliberately conservative - line-prefix patterns and majority votes - so ordinary prose is never mis-tagged.

OrderTypeDetection signal
1jsonStrict parse of an object or array, unless the object is a Hermes wrapper envelope
2testtest result:, === RUN, --- PASS:, N passed / N failed, running N tests
3diffdiff --git, --- + +++ header pair, or @@ hunk with change lines
4codeStrong signature line (fn main(, def x(, struct X, #include, shebang) or two or more statement-line votes
5tableTwo or more |-prefixed lines with a separator row
6markdownTwo or more heading lines plus structure or body prose
7yamlThree or more top-level lowercase key: value lines
8html / xml<!DOCTYPE html / <html open, or < open with </ close
9csvTwo or more rows with an identical comma-field count (no , comma-space)
10buildTwo or more cargo/rustc verb or error lines (Compiling, Finished, error[, warning:)
11gitPorcelain status codes on a majority of lines (M, A, ??, UU)
12gitlogcommit <hash> blocks
13greppath:line:match on a majority of lines
14lsls -l mode strings, or a majority of bare path-like tokens

A JSON object is excluded from json when any of its keys matches the Hermes wrapper envelope guard (output, exit_code, diff, error, success, total_count, matches, matches_text, content, total_lines, result, message, found, preview, name, description): those objects are wrappers whose payload lives inside, and the bridge unwraps them instead of previewing the key list.

Proxy Heuristics

The standalone proxy path classifies raw content with its own ladder, running the semantic detector between the code step and the error step:

  1. JSON: {- or [-prefixed. Invalid JSON → text; contains exit_code or the quoted key "status" → tool_output; otherwise json
  2. Code (more than 3 lines): code_rust (fn/impl/struct/enum plus ->, &, or use), code_python (def plus import/class/from/self.), code_go (func/package plus import (), code_js (function/const/=> plus import/export), generic code
  3. Semantic detector (the 15 refined shapes above)
  4. Error: first line contains error/Error/ERROR/Traceback/panic, or starts with thread ' → error
  5. Build output: first line starts with Compiling, running, or test, or contains Finished → build_output
  6. Linter: first line starts with error[E, error:, warning[, warning:, or contains mypy, clippy, eslint, tsc → linter
  7. Diff: first line starts with diff --git, @@ -, +++, or --- → diff
  8. Git: first line starts with commit or On branch → git
  9. Log: a line starts with [ and contains a log level, or starts with a digit and is ISO/syslog-like → log
  10. Fallback → text

Envelope Unwrap (Hermes Bridge)

Before classification, the Hermes bridge extracts the meaningful payload from wrapper envelopes.

The stored content is always the original bytes - the extracted payload is used only for classification and preview:

EnvelopeExtracted payloadClassified as
{output, exit_code}outputterminal if it contains exit code: or Error:; build_error if it contains error[ or error: could not; build_output if it is cargo/test verb output; otherwise the base classifier’s verdict
{success, diff} / {error}diff / error messageBase classifier on the diff, or text for error messages
{total_count, matches / matches_text}One path:line:content row per real matchsearch
{content, total_lines}contentBase classifier’s verdict

A caller-supplied type hint (from the tool schema) overrides the detected type. For JSON payloads the preview is built from the full stored content, never from an unwrap fragment.

Complete Registry (30 Types)

TypeProduced byThresholdPreview arm
jsonSemantic, proxy×1[json:{keys} {ln}L | {first keys}]
json_arrayBase×1[json:{items} items {ln}L]
source_codeBase×code[code:{fns} fns {first fn} {ln}L]
codeSemantic, proxy×codecode arm
code_rustProxy×codecode arm
code_pythonProxy×codecode arm
code_goProxy×codecode arm
code_jsProxy×codecode arm
testSemantic×1[test:{pass} pass {fail} fail {ignored} ignored]
diffBase, semantic, proxy×2[diff:{files} {ln}L | {file} +more]
buildBase, semantic×1[build:{err}E {warn}W {ln}L]
build_outputProxy, bridgeBASEbuild family
build_errorBridgeBASEbuild family
linterProxyBASE[lint:{ln}L {size}B | {first issue}]
errorProxy×8[error:{ln}L {size}B | {first error line}]
logProxyBASE[log:{ln}L {size}B | {error or tail}]
terminalBridge×1[terminal:{lines} exit={exit}]
searchBase, bridge×1[grep:{files} matches {ln}L | {first loc}]
grepSemantic×1[grep:{files} hits {ln}L | {first loc}]
gitSemantic, proxy×2[git:{mod}M {add}A | {file} +more]
gitlogSemantic×1[gitlog:{commits} commits {first} {last}]
lsSemantic×1[ls:{files} files {dirs} dirs | {extensions}]
tableSemantic×1[table:{items} rows {ln}L]
markdownSemantic×1[markdown:{ln}L {size}B | {first heading}]
yamlSemantic×1[yaml:{keys} keys {ln}L | {first key}]
xmlSemantic×1[xml:{ln}L {size}B | {root}]
csvSemantic×1[csv:{rows} rows {ln}L]
htmlBase, semantic×1[html:{title} {ln}L]
tool_outputProxy×1Proxy-only label (envelope guess)
textEvery stage’s fallback×2[text:{ln}L {size}B | {first line}]

Threshold Groups

The per-type threshold decides how many bytes of a type survive in context before compression. Base is the floor for all types.

GroupTypesMultiplier
Noisy (BASE, excluded from auto-tune)linter, build_output, logbase, immediately - never tuned
Errorerror×8
Codecode_rust, code_python, code_go, code_js, code× code multiplier
Trackeddiff, git, text×2
Defaulttool_output, json, everything else×1

The code multiplier is configurable (compression.code_multiplier or APHRODITE_CODE_MULTIPLIER) and defaults to 3.0.

Auto-tune adjusts the base from the historical compression-ratio EMA: ratio above 20 → ×2.0, ratio below 3 → ×0.5, otherwise ×1.0.

The noisy group is exempt - build, lint, and log output stays fully visible because a coding session needs to read it.

Detection Examples

JSON envelope (proxy path)

{ "output": "Compiling aphrodite v1.6.6", "exit_code": 0 }

→ type=tool_output (contains exit_code), threshold ×1

Rust code (proxy path)

pub fn main() -> Result<()> {
    let app = AppState::new();
}

→ type=code_rust, threshold ×code multiplier

Build output (proxy path)

   Compiling aphrodite v1.6.6
   Compiling headroom-core v1.0.0
    Finished release [optimized] target(s) in 12.34s

→ type=build_output, threshold BASE (fully visible, never auto-tuned)

Linter output (proxy path)

error[E0308]: mismatched types
  --> src/proxy.rs:841:5

→ type=linter (matches error[E before the generic error check), threshold BASE

Test output (semantic detector)

test result: ok. 3 passed; 0 failed; 0 ignored

→ type=test, threshold ×1

Terminal output (Hermes bridge)

{ "output": "error: could not compile `aphrodite`", "exit_code": 101 }

→ unwrapped to the message, type=build_error (contains error: could not), threshold BASE

Marker-shaped preview (the doubling regression, fixed in v1.3.4)

[text:[text:53L 1913B]]

→ an already-self-describing preview re-wrapped in render_marker; the fix emits the preview exactly once (regression-tested).

Shown here as the type catalog’s known failure shape, sourced from CHANGELOG.md v1.3.4.