rtk

package
v0.5.2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package rtk puts a compressor between a leaf's shell and the work model's context. rtk (github.com/rtk-ai/rtk, Apache-2.0) is a proxy binary that runs an inspection command and prints a far shorter version of what it said: a `ps aux` that cost 254KB of context costs 3.5KB through it, a `git diff` 41% less, a bare `ls -la` a fifth. Every one of those bytes is paid for again on every later turn of the leaf, so the saving compounds the way spilling does.

Two properties are load-bearing, and everything in this package serves them.

codeaf stays the only thing anyone installs. rtk is never a build or install dependency: it is resolved at runtime, and fetched in the background if it is missing. While it is unavailable — offline, unsupported platform, download still in flight — commands run exactly as they did before. Nothing here may block or fail a leaf's work.

A leaf's shell never changes meaning because rtk was in the middle. rtk's own rewriter decides what it can compress, which is the honest source of truth and spares us a table of command syntax; but it is broader than we want — it will turn `git add .` into `rtk git add .` — so the last word on eligibility is here, and a wrapped run that goes wrong is answered by the plain one.

The head's belt deliberately does not use any of this. The head reads deliverables in order to answer the user in their own words; a compressed read would cost answer fidelity to save tokens on the one surface where the bytes are the point.

Index

Constants

View Source
const (
	// Version is the pinned rtk release. Pinned rather than tracking latest so
	// that what a leaf sees does not change under it on someone else's release
	// schedule. To bump: read the notes at
	// https://github.com/rtk-ai/rtk/releases, set the tag here, and re-run the
	// integration test with CODEAF_TEST_RTK=1 — the one test that checks a real
	// binary still preserves exit codes.
	Version = "v0.45.0"

	// EnvBinary is the escape hatch: a path to a chosen rtk, or "off" to run
	// every command plain. It is read on every call so a running resident can
	// be taken out of the loop without a restart.
	EnvBinary = "CODEAF_RTK"

	// Off is the EnvBinary value that disables wrapping everywhere.
	Off = "off"
)

Variables

This section is empty.

Functions

func BinDir

func BinDir() (string, error)

BinDir is where a bootstrapped rtk lives. It is codeaf's own shelf, not the user's ~/.local/bin, because codeaf put it there and codeaf maintains it.

func Bootstrap

func Bootstrap(ctx context.Context)

Bootstrap fetches the pinned rtk if there is none, and is safe to call from a goroutine at startup and to ignore. It never returns an error because there is no caller for whom rtk's absence is a failure: every path through here ends with commands running exactly as they always have.

func Failed

func Failed(exitCode int, output string) bool

Failed reads a wrapped run's result for the one thing that means the wrapping broke rather than the command: rtk could not execute what it was handed. That is exit 127 — either rtk is no longer where we found it, or it fell through to a program that is not installed — and in both cases the plain command is the honest answer, whether it succeeds or reports the same absence itself.

func StripNudge

func StripNudge(output string) string

StripNudge removes rtk's once-a-day hook advertisement from merged output.

Types

type Class

type Class int

Class is how much of a wrapped command's failure we are willing to believe.

A read is cheap to repeat and its failures are the ones a model most needs verbatim — "no such file" has to be the shell's sentence, not a proxy's — so any nonzero exit is answered by running it again plain. A check earns the opposite treatment: a failing test suite is reporting, not malfunctioning, and its compressed failure is the single most valuable thing rtk produces. Running it twice would cost the leaf the whole suite a second time, so a check's exit code is taken at face value unless rtk itself came apart.

const (
	ClassNone Class = iota
	ClassRead
	ClassCheck
)

type Tool

type Tool struct {
	Path string
	// contains filtered or unexported fields
}

Tool is a resolved rtk binary and the memory of what it has been asked.

func Available

func Available() (*Tool, bool)

Available answers where rtk is, and never fetches it. Everything it does is a local lookup, which is nothing beside the fork the caller is about to do.

func (*Tool) Ban

func (t *Tool) Ban(command string)

Ban marks a rewrite that failed on rtk's own terms, so the shape is never wrapped again in this process.

func (*Tool) Wrap

func (t *Tool) Wrap(ctx context.Context, command string) (string, Class)

Wrap answers what a command should actually run as. The returned command is the one to execute and the class says how far its exit code can be trusted; ClassNone means run what was passed in, untouched.

Jump to

Keyboard shortcuts

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