takeover

package
v0.174.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 9 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

Package takeover hands a Claude Code session's permission requests to the person's screen while the screen has taken the session over, and back to the session's own window when it has not.

The state is files in one folder, so the PermissionRequest hook reads it without beekeeper's state lock: a session is taken over while its flag (<session>.json, naming the screen's process) exists and that process runs. Only then does the hook hold a request: it writes it into the session's folder (<session>/<id>.request) and waits for the screen's answer beside it (<id>.answer). Every other request is decided at once with no decision, as before.

Index

Constants

View Source
const (
	Allow = "allow"
	Deny  = "deny"
)

The behaviours a Decision has, as Claude Code's PermissionRequest hook output names them.

View Source
const GiveUp = 290 * time.Second

GiveUp is how long the hook holds a request for the screen: under the hook's own 300 s timeout, so the outcome is the hook's and never depends on Claude Code cancelling it.

View Source
const Poll = 250 * time.Millisecond

Poll is how often a held request looks for its answer and its flag.

Variables

View Source
var ErrHandedBack = errors.New("the request is no longer held: it went back to the session's window")

ErrHandedBack is an answer to a request the hook no longer holds: it gave up, or the session's window answered it.

Functions

func Answer

func Answer(dir, session, id string, d Decision) error

Answer gives the held request id of session the screen's decision; a request no longer held is ErrHandedBack.

func Dir

func Dir(stateDir string) string

Dir is the take-over folder in beekeeper's state folder.

func Release

func Release(dir, session string) error

Release hands session back: its held requests go to its own window at their next look.

func Take

func Take(dir, session string, f Flag) error

Take records that the screen f names took session over.

Types

type Decision

type Decision struct {
	Behavior string `json:"behavior"`
	// Message tells the model why a request was denied.
	Message string `json:"message,omitempty"`
}

Decision is the screen's answer to a request.

func Hold

func Hold(ctx context.Context, dir string, r Request, alive func(pid int) bool, poll time.Duration) (d Decision, ok bool, err error)

Hold holds r for the screen until it answers, its flag goes or its screen stops, or ctx ends (the caller's GiveUp): ok is false for each of the latter, and the request goes to the session's own window. Hold leaves no file behind.

type Flag

type Flag struct {
	// PID is the screen's process: a flag whose process is gone is no
	// take-over.
	PID   int       `json:"pid"`
	By    string    `json:"by"`
	Since time.Time `json:"since"`
}

Flag says a screen has taken a session over.

func Taken

func Taken(dir, session string, alive func(pid int) bool) (Flag, bool)

Taken returns session's flag when one exists and alive says its screen runs. It takes no lock: one file read.

type Request

type Request struct {
	ID      string          `json:"id"`
	Session string          `json:"session"`
	Tool    string          `json:"tool"`
	Input   json.RawMessage `json:"input,omitempty"`
	At      time.Time       `json:"at"`
}

Request is a permission request the hook holds for the screen.

func Pending

func Pending(dir, session string) ([]Request, error)

Pending returns the requests held for session, oldest first.

Jump to

Keyboard shortcuts

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