awake

package
v0.1.1166 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package awake keeps the computer from going to sleep by itself while agents work through magpie's gateway (xiao_wang24004 on X: the computer went to sleep in the middle of an agent's task). With settings.KeepAwake on, the magpie serving the gateway holds the system's sleep off while a request is in flight, a Claude Code turn waits on its tool results, or a request ended less than Grace ago — an agent running a build or the tests between one request and the next — and lets go once it is idle. Only the system's sleep of its own is held off: the display still turns off, unless settings.KeepAwakeDisplay asks for it to stay on too (#975, Hu9956: an agent recording the screen to check its work found it locked), and closing a laptop's lid or choosing Sleep still sleeps.

On a Mac it is `caffeinate -i` (-d with the display), on Windows SetThreadExecutionState with ES_SYSTEM_REQUIRED (and ES_DISPLAY_REQUIRED), on Linux `systemd-inhibit --what=idle:sleep`, whose idle inhibitor the desktop may or may not take for the screen too; where none is there it does nothing.

Index

Constants

This section is empty.

Variables

View Source
var Grace = 10 * time.Minute

Grace is how long after the last request ended sleep is still held off.

Functions

func Keep

func Keep(ctx context.Context, level func() Level, state func() State)

Keep holds sleep off as far as level says while state says the agents are at work, until ctx ends. A level changed while held is taken anew.

Types

type Level added in v0.1.1081

type Level int

Level is how much Keep holds off.

const (
	Off     Level = iota // nothing
	System               // the system's sleep
	Display              // the system's sleep and the display's
)

type State

type State struct {
	Busy bool      // a request in flight or a turn waiting on tools
	Last time.Time // when the last request ended
}

State is what the gateway has in flight, as Keep needs to know it.

Jump to

Keyboard shortcuts

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