threecode/types

Shared types and process-level globals.

All types that cross module boundaries live here to avoid import cycles. experimentalEnabled is a global because every module that validates a profile needs it, and threading it through every call site is noise.

Types

Action = object
  kind*: ActionKind
  path*: string
  body*: string
  stdin*: string             ## bash-only: piped to the command's stdin
  timeoutSecs*: int          ## bash-only: model-requested run cap in seconds; 0 = default
  edits*: seq[(string, string)]
  plan*: seq[PlanItem]
  offset*: int
  limit*: int
The parsed, tool-agnostic representation of a single model tool call. runAction in actions.nim consumes this and produces the tool result.
ActionKind = enum
  akBash, akRead, akWrite, akPatch, akApplyPatch, akPlan, akWebSearch,
  akWebFetch, akClear, akError
ApiError = object of CatchableError
InputState = object
  turnActive*: bool
  shutdown*: bool
  autoSend*: bool
  queuedText*: string
  queuedEchoRows*: int
  queuedPrompts*: seq[tuple[text: string, echoRows: int]]
  queuedCommand*: string
  queuedCommandRows*: int
  cmdWasQuit*: bool
Shared between the main thread and the buffered prompt thread during model/tool turns.
ParseIssue = object
  line*: int
  msg*: string
A syntax problem the text-mode parser surfaced on a fenced block (unterminated fence, orphan code-fence, malformed SEARCH/REPLACE). line is 1-indexed into the assistant reply.
PlanItem = object
  text*: string
  status*: string
One item in a model-emitted update_plan / todo list.
Profile = object
  name*, url*, key*, model*: string
  family*, version*, variant*: string
  reasoning*: string         ## reasoning/thinking effort level: "low", "medium",
                             ## "high", or "" when the model has no such knob.
                             ## Mapped to a wire field in `callModel` per family
                             ## (gpt-oss: `reasoning_effort`; glm: `thinking.type`).
model is the full wire value sent in the API model field (e.g. "openai/gpt-oss-120b"). Display code shortens it with shortModel(model) (everything after the last /). family ("glm" / "qwen" / "gpt-oss") drives (prompt, tools) tuple selection. version and variant (e.g. "3", "480b") are informational tags from KnownGoodCombos. In experimental mode family may also come from the per-provider config override.
ReadCache = ref object
  state*: Table[string, (Time, int)]
Session = object
  usage*: Usage
  lastPromptTokens*: int
  toolLog*: seq[ToolRecord]
  savePath*: string
  profileName*: string
  created*: string
  cwd*: string
  plan*: seq[PlanItem]
  readCache*: ReadCache
ToolRecord = object
  banner*: string
  output*: string
  code*: int
  kind*: ActionKind
Usage = object
  promptTokens*, completionTokens*, totalTokens*, cachedTokens*: int

Vars

debugEnabled: bool = false
Set by -D/--debug.
experimentalEnabled: bool = false
Set by -x/--experimental.
streamingEnabled: bool = true
Whether model calls use SSE streaming ("stream": true) or a single request/response. Default on for live output. The non-streaming path is the reliable fallback when a provider's SSE transport is flaky (empty 200 replies, ticker dying mid-response — the streamhttp TLS-read race). Toggled at runtime via :streaming on/off, persisted in [settings].

Consts

DefaultBashTimeout = 120
seconds; used when the model omits timeout
ExitApi = 5
ExitUsage = 2
MaxBashTimeout = 600
seconds; hard ceiling regardless of model request

Procs

proc bashTimeoutSecs(req: int): int {....raises: [], tags: [ReadEnvEffect],
                                      forbids: [].}
Resolve the run cap (seconds) from a model-requested value. Missing/zero/negative → default; any value above MaxBashTimeout is clamped to it. Read at call time so THREECODE_MAX_TIMEOUT can raise the ceiling at runtime without a rebuild.
proc die(msg: string; code = 1) {.noreturn, ...raises: [IOError],
                                  tags: [WriteIOEffect], forbids: [].}