Documentation
¶
Overview ¶
Package server is whittle's HTTP front door. It replaces the Python compressor's POST /v1/compress with a content-aware router + structural compressors (and delegates the prose path back to the Python service). The response shape matches the Python service closely enough that the edge-server caller - which reads only `compressed` + `action` - is unchanged.
Index ¶
- func ExtractHookText(toolResponse json.RawMessage, toolOutput string) (string, func(string) any, bool)
- func ExtractToolText(raw json.RawMessage) (string, func(string) any, bool)
- func HookReply(updated any) map[string]any
- func ListenAndServe(addr string) error
- func NewMux(p *compress.Pipeline) http.Handler
- func NewMuxWithStore(p *compress.Pipeline, store *Store) http.Handler
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractHookText ¶ added in v0.3.0
func ExtractHookText(toolResponse json.RawMessage, toolOutput string) (string, func(string) any, bool)
ExtractHookText is the one extraction entry point for both hook paths (HTTP /hook and the `whittle hook` command). It prefers tool_response - the field that carries the tool's output SHAPE, which the replacement must reproduce - and falls back to the legacy string-only tool_output field (real Claude Code 2.1.203 events omit it; kept for SDK/older producers).
func ExtractToolText ¶ added in v0.3.0
ExtractToolText finds the compressible text in a tool_response and returns a rebuild function that produces an updatedToolOutput of the same shape with that text replaced.
Recognized shapes, in order (captured from real PostToolUse events):
- bare non-empty string -> replaced as a bare string
- {"stdout"|"output"|"result": "text"} -> that key swapped (Bash, ...)
- {"file": {"content": "text"}} -> file.content swapped (Read)
MCP content arrays ({"content":[{"type":"text",...}]}) are NOT handled (a pre-existing gap): unknown shapes fail closed - no replacement, original preserved - never a guessed rebuild.
Sibling fields (stderr, interrupted, file.numLines, unknown future fields) are preserved verbatim: they describe the original tool run and keep the replacement schema-valid by construction. (file.numLines/totalLines deliberately keep describing the file on disk, so follow-up Read offset/limit math stays correct against the real file.) The text-carrying entry is nilled as soon as it is decoded so the large original bytes are not pinned in memory across the compress round-trip; rebuild is single-use and mutates the maps decoded here.
func HookReply ¶ added in v0.3.0
HookReply wraps a rebuilt updatedToolOutput in the PostToolUse hook envelope - the single definition of the wire contract for both delivery paths (HTTP body and command-hook stdout).
func ListenAndServe ¶
ListenAndServe builds the pipeline from the environment and serves the HTTP API on addr (":45871" if empty). Env: WHITTLE_MODEL_URL (enables the ML prose path), WHITTLE_MAX_CHARS (global ceiling), WHITTLE_PROSE_MAX_CHARS (prose latency ceiling).