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, an agent's turn runs a tool its last reply asked for (a build, the tests: up to an hour, aooo_han on X), or a request ended less than Grace ago, 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.
While the gateway is shared with other computers, sleep is held off as long as it is, whether a request is in flight or not: another computer's agent can't wake this one.
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 ¶
var Grace = 10 * time.Minute
Grace is how long after the last request ended sleep is still held off.
Functions ¶
func Keep ¶
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.
func NoNap ¶
func NoNap() func()
NoNap keeps macOS from App Napping the magpie serving the gateway until the release it returns is called (#6261, ChasLui). The menu-bar app serves it in its own process, and with the screen locked macOS naps the app as one in the background: its priority falls to 4 and its timers wait, so the first request after a quiet while spent its 30 seconds before routing and got a 504. An agent waiting on the gateway is the user's work, so the activity says it is user initiated, as Apple's App Nap opt-out does. It lets the system sleep when idle, as it did: holding that off is Keep's, and only while the user asked for it. Nor does it ask for NSActivityLatencyCritical's timer precision, which is for audio and video; a request needs the process run, not run to the millisecond.
Types ¶
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
// on the network, or a gateway listening beyond loopback). Their next
// request can come at any time, and one that meets this computer
// asleep gets nothing until someone touches it (eachg0 on X: with
// the screen locked, a shared Mac's requests timed out now and then
// with keep-awake on, and came right with a key pressed), so sleep is
// held off the whole time it is shared, idle or not.
Shared bool
}
State is what the gateway has in flight, as Keep needs to know it.