{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package input\n\nPackage input routes a raw interactive line — coalesce / steer / queue / interrupt — so the agent collaborates the way people actually type instead of treating every Enter as a new task. Composer text is TEXT: Parse never scans prose for arbitrary file paths (that \"helpfully\" turned words into attachments because they matched repo paths). The ONE Parse-level extraction is a narrow pasted/dragged ABSOLUTE path to an EXISTING supported image file (the macOS \"paste a screenshot\" case); every OTHER attachment comes only from an explicit drag/drop or attach event via Resolve. Routing is deterministic and unit-testable; the timing side (coalescing window) lives in the interactive runner.\n\n## Constants\n\n```go\nconst (\n\tMaxImageB64Bytes   = 10 \u003c\u003c 20 // per-image ceiling, base64-encoded (Anthropic direct; 5MB on Bedrock/Vertex)\n\tMaxPDFB64Bytes     = 24 \u003c\u003c 20 // per-PDF ceiling, base64-encoded — fits the 32MB request envelope with headroom\n\tMaxRequestB64Bytes = 32 \u003c\u003c 20 // whole-request payload ceiling\n\tMaxAttachments     = 20       // claude.ai's per-message limit; ≤20 also avoids the stricter \u003e20-image 2000px dimension rule\n\n)\n```\nAttachment ceilings — the DIRECT Anthropic API limits, verified against the vision + PDF docs at platform.claude.com. These are the binding limits because memcode's gateway talks to the Anthropic API directly AND images always serve on Anthropic (the cheap lane has no vision). On Bedrock/Vertex the per-image cap would be 5MB instead of 10MB — not a path memcode uses, so we don't carry a provider-profile abstraction for it (it would be dead code).\n\nSizes are checked BASE64-ENCODED, because that's how images travel in the request and base64 inflates raw bytes by ~33% — a raw 8MB image is ~10.7MB on the wire. Checking raw bytes would accept bundles the API then rejects.\n\n## Functions\n\n```go\nfunc Base64Len(n int64) int64\n```\nBase64Len returns the base64-encoded byte length of n raw bytes (4 chars per 3 bytes, padded).\n\n```go\nfunc Downscale(data []byte, mime string) ([]byte, string)\n```\nDownscale shrinks an image's long edge to maxImageEdge (re-encoding in the same format) when it's larger, returning the smaller bytes. It's a best-effort optimization: any decode/encode failure, an already-small image, or a result that isn't actually smaller returns the original bytes + mime unchanged. Only PNG and JPEG are resized — the common screenshot/photo formats; GIF/WebP pass through untouched (no extra decoder dependency, and GIF animation is preserved).\n\n```go\nfunc ImageMatches(text, cwd string) []string\n```\nImageMatches returns the substrings of text that are absolute paths to existing supported image/PDF files — the same eligibility criteria used by discoverImagePaths. The TUI uses this to collapse a dragged-in path to a compact \"\\[Image #N]\" chip while keeping the exact substring recoverable on submit.\n\n## Types\n\n```go\ntype Attachment struct {\n\tPath      string `json:\"path\"`\n\tKind      Kind   `json:\"kind\"`\n\tMime      string `json:\"mime,omitempty\"`\n\tSHA256    string `json:\"sha256,omitempty\"`\n\tSizeBytes int64  `json:\"size_bytes,omitempty\"`\n\tSource    string `json:\"source\"` // drag_drop | paste\n}\n```\nAttachment is one file referenced in a turn. Raw bytes are NOT stored here; only metadata (and the path, for the runner to read under policy).\n\n```go\nfunc CapAttachments(atts []Attachment) (kept []Attachment, dropped int)\n```\nCapAttachments enforces the count + aggregate-payload ceilings, measuring each attachment at its BASE64-encoded size (how it travels to the model) so a bundle accepted locally can't blow the request envelope after encoding. Returns the kept attachments (order preserved) and how many were dropped, so the caller can tell the user.\n\n```go\nfunc Resolve(candidate, cwd, source string) (Attachment, bool)\n```\nResolve turns an explicit path (from a drag/drop payload or an attach command, NOT from scanning prose) into an Attachment if it exists. source is recorded for provenance (e.g. \"drag\\_drop\", \"attach\").\n\nPATH POLICY (current behavior, deliberately documented — not yet a hardened gate): a pasted/dragged ABSOLUTE path is honored ANYWHERE on disk (e.g. ~/Desktop, /tmp, /Volumes), because the user explicitly produced the event — but it's narrowed to supported images (imagePathRe) and size-capped. Symlinks are NOT resolved/confined, and an explicit attach of an arbitrary absolute path is not yet confirmation-gated. TODO(attachments): a real policy — workspace-local by default for \\`attach\\`, explicit allow for out-of-cwd absolute paths, and no silent symlink traversal outside cwd. TestResolveOutsideCwdAllowed pins TODAY's behavior so any tightening is intentional.\n\n```go\ntype Bundle struct {\n\tText           string       `json:\"text\"`\n\tAttachments    []Attachment `json:\"attachments\"`\n\tAttachmentOnly bool         `json:\"attachment_only,omitempty\"`\n}\n```\nBundle is one user turn: canonical pasted text plus additive attachments. AttachmentOnly is true only when the routed source consists solely of recognized attachment paths, so callers can distinguish missing chat text from mixed input.\n\n```go\ntype Decision struct {\n\tBundle Bundle\n\tRoute  Route\n\tReason string\n}\n```\nDecision is the full routing result for an input line (inspectable).\n\n```go\nfunc Parse(line, cwd string) Decision\n```\nParse routes a raw input line. It does NOT scan prose for file paths (that turned words into attachments). The ONE narrow exception is a pasted ABSOLUTE path to an EXISTING image file — the macOS \"paste a screenshot\" case — which becomes an image attachment so the model can actually see it. Everything else is text.\n\n```go\ntype Kind string\n```\nKind classifies an attachment.\n\n```go\nconst (\n\tKindImage     Kind = \"image\"\n\tKindPDF       Kind = \"pdf\" // sent as a native document block — the model reads it on the LLM call\n\tKindText      Kind = \"text\"\n\tKindBinary    Kind = \"binary\"\n\tKindDirectory Kind = \"directory\"\n\tKindSecret    Kind = \"secret\" // detected as credential-bearing — never sent raw\n)\n```\n\n```go\ntype Route string\n```\nRoute is how an input is folded into the session.\n\n```go\nconst (\n\tCoalesce  Route = \"coalesce\"  // merge into the current turn (timing-decided by the runner)\n\tSteer     Route = \"steer\"     // refine the active objective (default)\n\tQueue     Route = \"queue\"     // a separate/future task\n\tInterrupt Route = \"interrupt\" // stop and re-plan\n\tShell     Route = \"shell\"     // `$` direct-shell lane: run verbatim, no agent/model\n)\n```\n\n","path":"github.com/memcode-ai/memcode/internal/agent/input","name":"input","synopsis":"Package input routes a raw interactive line — coalesce / steer / queue / interrupt — so the agent collaborates the way people actually type instead of treating every Enter as a new task.","isRedistributable":true}
