btw

package
v1.5.88 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

This file implements the /btw command (mirrors Claude Code's /btw and the pi agent extension @narumitw/pi-btw): a throwaway "side thread" for asking the model a quick side question that must NOT pollute the main conversation.

/btw is intercepted in the REPL loop rather than routed through a slash Action closure because it must run an agent stream and read the live main context — none of which a pure string→string Action can do, exactly like /compact and /goal. It reaches the session's collaborators and mutable state through the cli.Host contract and reads follow-up lines through cli.Editor, so it need not import the concrete replDeps aggregate that assembles them.

Isolation contract (the whole point of the feature): a side thread runs on a COPY of the main conversation as background, and its question/answer are only ever appended to that copy — never to host.AgentCtx().Messages. Nothing is persisted: no store.Save, no change to the persisted cursor / current leaf / header timestamp. Closing the side thread, switching sessions or restarting golder discards everything.

Scope: /btw is intercepted in the REPL loop and runs a side question against a copy of the main context (#279); it supports multi-turn follow-ups in the same ephemeral thread (#280), bare-/btw reopen of the most recent side thread this process (#281), and an optional model/thinking override config (#282, see btw_config.go) that affects only the side thread.

This file implements the /btw model/thinking override config (US-005, #282): an optional per-command config that lets a side thread use a different model and/or reasoning effort than the main session, without touching the main session's settings (mirrors pi-btw's pi-btw.json).

The config lives at $GOLDER_HOME/btw.json (or ~/.golder/btw.json). It is read fresh on every /btw invocation, so editing it takes effect on the next call with no restart. A missing file, an empty object, or an absent field all mean "inherit the session default" silently — only a malformed file or an unusable model override produces a (non-fatal) warning.

Index

Constants

View Source
const BtwHeader = btwHeader

BtwHeader exposes the side-thread banner text so callers (and tests) can recognize it in output.

Variables

This section is empty.

Functions

func AskSide

func AskSide(setCancel func(context.CancelFunc), out io.Writer, host cli.Host, side *agentcore.AgentContext, settings BtwRunSettings, question string)

AskSide appends the question to the side context and streams one answer, mirroring streamRun's rendering but targeting the side context so nothing is written back to the main conversation or to disk. It reuses the REPL's SIGINT cancel plumbing via setCancel. The model/provider/thinking come from settings (session defaults overlaid with btw.json, #282), never from host.Live(), so a /btw override cannot leak into the main session.

func NewSideContext

func NewSideContext(main *agentcore.AgentContext) *agentcore.AgentContext

NewSideContext builds the side thread's private AgentContext. Its Messages are a fresh slice seeded with a shallow COPY of the main messages (the elements are immutable value/interface messages, so a copied slice header is enough to guarantee appends to the side thread never reach the main context's Messages). The system prompt and tools are shared by value; only Messages diverges.

func RunBtw

func RunBtw(setCancel func(context.CancelFunc), out io.Writer, host cli.Host, editor cli.Editor, line string)

RunBtw handles a /btw invocation. With an argument it starts a fresh side thread, asks that question, then enters a follow-up loop so the user can keep asking in the same ephemeral thread. Bare "/btw" reopens the most recent side thread from this process — replaying its Q&A history — and drops back into the follow-up loop; if none exists yet it guides the user to supply a question (US-004, #281). setCancel publishes the active run's cancel func so the REPL's SIGINT handler can interrupt the side run, reusing the same plumbing as a normal turn.

The main context is never mutated: RunBtw builds a private side AgentContext seeded with a copy of the main messages, runs every turn against that copy, and returns without touching host.AgentCtx() or persisting anything. The side thread is retained in-process (host.LastBtw()) so a later bare /btw can reopen it, but it is never written to disk — restarting golder discards it.

Types

type BtwRunSettings

type BtwRunSettings struct {
	Model         string
	ProviderName  string
	Provider      provider.Provider
	ThinkingLevel agentcore.ThinkingLevel
}

BtwRunSettings is the resolved model/provider/thinking a side run uses. It is computed once per /btw invocation from the session defaults overlaid with btw.json, and passed down to AskSide so every turn of that invocation uses the same settings.

func ResolveBtwSettings

func ResolveBtwSettings(out io.Writer, host cli.Host) BtwRunSettings

ResolveBtwSettings computes the model/provider/thinking a side run should use. It starts from the session defaults (host.Live()) and overlays btw.json:

  • No config / empty object / absent fields → inherit the session values.
  • thinkingLevel set → validate and override (invalid value warns, falls back).
  • model set → resolve its provider (reusing resolveProvider like /model); if the model cannot be resolved/authenticated, warn on one line and fall back to the session model+provider.

A malformed config file warns once and inherits everything. Nothing here mutates the session live config, so the override is confined to the side thread (FR-8).

Jump to

Keyboard shortcuts

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