server

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

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

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

func ExtractToolText(raw json.RawMessage) (string, func(string) any, bool)

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

func HookReply(updated any) map[string]any

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

func ListenAndServe(addr string) error

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).

func NewMux

func NewMux(p *compress.Pipeline) http.Handler

func NewMuxWithStore added in v0.2.0

func NewMuxWithStore(p *compress.Pipeline, store *Store) http.Handler

Types

type Store added in v0.2.0

type Store struct {
	// contains filtered or unexported fields
}

func OpenStore added in v0.2.0

func OpenStore(dir string, maxBytes int64, ttl time.Duration) (*Store, error)

func (*Store) Get added in v0.2.0

func (s *Store) Get(id int64) (string, bool)

Get returns the original content for an alias, or ok=false (expired/unknown).

func (*Store) Put added in v0.2.0

func (s *Store) Put(content string) int64

Put stores content and returns its alias id (deduped by content hash).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL