mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-19 12:49:32 +01:00
88ed3eef37d2c291eba761a27a701e0a557e32d4
11
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
be8b96fa5d |
feat(desktop): keep a closed MacBook awake without the administrator password
Keep This Mac Awake > With the Lid Closed is a plain switch now. 1.50.1 installed a root LaunchDaemon behind the administrator prompt, which set `pmset disablesleep` while the app asked for it. The app now turns off lid sleep in the kernel's power management root itself (`kPMSetClamshellSleepState`, a call any process may make), the method LogoLight ships as Lit with Lid Closed. That switch has no owner (read from Apple's sources of the kernel and of powerd): the kernel keeps it after the process that set it has gone and honours it on battery, macOS's power daemon and LogoLight write the same bit, and clearing it under a closed lid puts the Mac to sleep at once. On an Apple silicon Mac it is also what keeps a docked MacBook awake with its lid closed, set by the power daemon once, when a display comes. So a child process holds it (`src/lid_awake.rs`, this binary with `--keep-awake-lid`): - it sets the switch again every second and holds two assertions with it (system sleep and idle sleep), the three LogoLight measured together; - it reads the power source itself and holds nothing on battery; - it writes nothing at all while an external display is connected: a zero from here would put a docked Mac to sleep, or leave it without its closed-lid mode until the display is plugged in again. What the child set before the display came is cleared once the display has been gone for five seconds, and the child outlives the app for that if it has to; - it lets go when the pipe from the app closes (quit, crash, Force Quit) and when the app has not written for a minute (a hang), the assertions first, then the switch; - it ignores SIGHUP, SIGINT and SIGTERM, so the pipe is its one way out; - it leaves the switch alone at its end while LogoLight holds it for itself (LogoLight sets it once and would not notice it gone). One child at a time holds a lock on `lid-awake` next to `desktop.json`, and the file is non-empty while the switch may be set. A child that was killed leaves it marked and unlocked: the app turns lid sleep back on when it sees a child end and at its next launch, and the next child takes the mark over. The status line says what came of it: the kernel took the call, the lid is left to macOS at a display, on battery, refused, or that the Mac slept under the lid all the same and until when. A display has its own wording so a Mac that sleeps there never reads as covered. The helper of 1.50.1 is no longer installed or used. Its request file is never written and is deleted at launch, so a helper that is still there does nothing. While it is installed the menu has Remove the Old Lid Helper…, the one item left behind the administrator prompt. `macos/keep-awake-lid.sh` and its vitest suite go with the install path. Checked on a Mac mini (macOS 27.2, no lid, no display): 276 tests, clippy and fmt; the kernel takes the call from an unprivileged process; the real child holds its assertions, lets go on a closed pipe and after a minute of silence, ignores SIGTERM, waits for a child before it, writes nothing when told a display is connected, and a SIGKILLed child is replaced by the app and its mark undone. 34 deliberate breaks of these rules each fail a test. Not run yet: the app itself with this change (the mini has no session to open it in), a real closed lid, the menu items, and the removal of the old helper. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> |
||
|
|
5cd8fa049a |
feat(desktop): blink the logo while a LogoLight that steps aside runs
LogoLight drives the lid logo with the same DisplayLogicalState fades,
so Codeman used to leave the logo to it whenever it ran: the owner had
LogoLight open and the release candidate never breathed.
LogoLight steps aside instead since its 1.3.0 ("LogoLight steps aside
while Codeman shows its agents on the logo, and takes the logo back
afterwards"). This is Codeman's side of that contract, which lives in the
marker the blinker already keeps for crash recovery:
- it now holds the blinker's process ID;
- it goes down right before the first write rather than when the blink
starts, so a blink waiting for the display does not pause LogoLight for
nothing; under a closed lid the first write is telling the logo the lid
is open, so the marker and the wait come before that;
- with a LogoLight that says LogoLightStepsAsideForCodeman in its
Info.plist, the blinker waits two seconds after writing it, since
LogoLight looks every second. A blink that starts within a second of
the last one's end (work, then a permission) skips the wait: LogoLight
takes the logo back only after the marker has been gone for 1.5 s.
The key is read from the running LogoLight's bundle by process ID
(proc_pidpath, then the plist file, never NSBundle, which would keep a
stale copy across a LogoLight update). An older LogoLight is still left
the logo, and the warning when the switch is turned on now says to update
it. At launch, a logo a killed child left is put back as before, but with
any LogoLight running the lid state is left to it.
Tests: 229 pass on the Mac mini, and six deliberate breaks of the
handover each fail one. The Info.plist lookup was run against a stand-in
process carrying the Info.plist of the released LogoLight 1.3.1: it reads
"steps aside". Not seen with a real LogoLight on a real logo yet.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
||
|
|
979275af1f |
fix(desktop): blink under a closed lid the way LogoLight 1.3.1 measured it
LogoLight 1.3.1 lights the logo behind a closed lid on a real MacBook kept
awake with no display attached, and its research notes say why the earlier
tries here stayed dark and what must not be written:
- Kept awake like that, the built-in display stays online and
CGDisplayIsAsleep says 0, so the lid path was never taken ("not tried
yet"). The lid sensor decides now (in since the last commit).
- DisplayPowerStateEvent is gone. A client's DidSleep keeps the logo dark,
lid open too, until a DidWake is written; the last commit wrote DidSleep
when a blink ended, and at launch with a marker and the lid closed.
- After ClamshellUpdate 0, each display in CBDisplayList is told the lid
is closed again (setProperty:withKey:andDisplay:), as each keyboard is:
told it is open, True Tone tints an external display warm and dim.
- The logo is told once, when the daemon has handled the lid
(CBClamshellState, bounded to two seconds of waiting), not at every
cycle, which would toggle those display modules with every beat. It is
told again when it is found dark at the start of a beat, or when a rise
did not move it: three times in a row, then every half minute, with
"stayed dark" in the menu line.
- Unplugging under the lid tells the logo the lid is closed again.
- "The Mac went to sleep" is only said while the lid is closed.
The keep-awake side needs nothing new: pmset disablesleep holds the Mac at
full wake, which is the state LogoLight measured; an assertion against
system sleep alone gives a dark wake, where the logo stays dark.
221 tests pass on the Mac mini, and 13 deliberate breaks of the lid rules
each fail one. Not seen from this app on a real lid yet.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
||
|
|
ede99b309c |
fix(desktop): the lid sensor decides, and every lid close leaves a reason
On RC4 the owner closed the lid with LogoLight not running and the menu line still said "not tried yet": the child never wrote anything. Three ways that could happen left no trace: the display list still showing the built-in display awake under the closed lid (the blink then never took the lid path), no blink running because no agent was at work, and the Mac going to sleep at the lid close. The lid sensor now wins: a closed lid counts as closed whatever the display list says. While no blink runs and the lid is closed, the line says why (nothing to show, no agent at work; the logo switched off; LogoLight has the logo; a refused change). The child notices a sleep as wall-clock time that passed while Instant stood still, and the line then says "the Mac went to sleep". With no child at all (switch off, no server open) the app says nothing watches the lid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
c307d63d3b |
fix(desktop): under a closed lid, just keep blinking, and say what happened
RC3's lid path went dark on the real MacBook without a word: it waited for CBClamshellState, gave up after two tries, and wrote ClamshellUpdate 1 back on every failed proof, and none of its silent paths left a trace without a Terminal launch. Now, while the lid sensor (AppleClamshellState) says closed, the built-in display is off and the Mac is on its power adapter, the logo is told the lid is open (and each keyboard that it is closed) at the start of every cycle, with no tries and no give-up: monotone, so nothing is toggled in between. With no other display on the display sleeps, which also keeps the logo dark, so if the first rise does not move it the logo is told the display woke (DisplayPowerStateEvent 2); DidSleep is written back at the end only if that was sent. The end of a blink, and the marker recovery, still put the logo back to dark as a closed lid has it. What the closed lid did last is a line in the View menu, under Apple Logo Blink Styles: "Lid Closed: blinking", "blinking (display told awake)", "stayed dark, macOS keeps the logo off", or why it was not tried (on battery, no keyboard to keep dark, no lid sensor), with the time. The child writes it to logo-lid next to desktop.json, with the readings on a second line; the app reads it every two seconds. The battery and keyboard gates stay: the lid helper only holds on the adapter, and a keyboard told the lid is open would light under it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
4c53d424a7 |
fix(desktop): a firmer proof under the closed lid, and a stderr note that cannot abort
The proof that the logo moves under the closed lid now needs a fade level above 0.01, not just above 0, so no drift of a fade held at 0 passes for a rise; the slowest rise (the breath's) is past it in about 80 ms. The note on stderr is a writeln! whose error is dropped: eprintln! panics on a failed write, and the blink child has panic = "abort". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
39f2e847d8 |
feat(desktop): the lid logo keeps blinking with the lid closed
With the lid closed, corebrightnessd tells every module so and keeps the logo dark, so the blink stopped as soon as the lid came down, which is exactly when the logo on the lid is the one thing in view. While the Mac stays awake with the lid closed on its power adapter (Keep This Mac Awake's lid helper, or an external display), the blink child now does what LogoLight's Lit with Lid Closed measured on the real MacBook: once the daemon has handled the lid (CBClamshellState), it tells the logo the lid is open (ClamshellUpdate 0) and each keyboard alone that it is closed, so the keyboard stays dark and is never relit after a Blank. The first rise after that has to move the logo within 1.5 s. If it does not (with no display on, the daemon may still hold the logo dark), the lid is told closed again, tried once more, then left dark until the lid opens, a display comes on or the agents' state changes. A logo the daemon takes back (it resends the lid state when a display or keyboard comes up) is told again. Ending a blink under the closed lid hands the logo back to normal and then writes ClamshellUpdate 1, since normal there is dark; the marker recovery does the same for a killed child. Never on battery (a dark wake must not light the logo in a bag), never without the keyboard IDs, and nothing is written when the lid opens. Every step is a line on stderr so a real-Mac run shows which one stopped it. Not seen on a real MacBook yet; the README says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
7d96b3dcf6 |
feat(desktop): the lid logo breathes, blinks and flashes on its own fades, behind one switch
The 1.50.0 blink switched LEBacklightMode on and off. Every style was a lit logo with short dark blips that differed only in how many there were, and Working (Heartbeat) looked busier than Waiting for you (Wink), so urgency read backwards. Each change was also a write to a setting corebrightnessd keeps in root's preferences, and new users had to pick a style in three submenus before anything happened. Now one rule: the more the logo moves, the more it needs you. - View > Blink Apple Logo is one switch, off until turned on. It shows Breathe while agents work, Calm for a yellow tab and Alarm for a red one. Each state can take another style under View > Apple Logo Blink Styles. Picking a style turns the switch on, and turning it on with every state off brings back those three. - Breathe is new: a slow fade out and back in, every 6.3 s. - The logo moves on the LED's own hardware fades (LEPWMFactorFadeDuration, then DisplayLogicalState Blank or Unblank), as LogoLight measured them on the real logo (MIT, reimplemented in Rust, not copied). A blink writes no setting and leaves nothing behind a restart. LEBacklightMode is only read, so a logo the user switched off stays off. - The direction of a fade is tracked, because the daemon ignores a write in the direction it already heads and the state can't be read back. When the direction is unknown, the logo is turned round with a 1e9 s fade first. - After every Blank the keyboards alone are told Unblank, and only while the built-in display is awake (CGDisplayIsAsleep). They are told Blank when it sleeps and Unblank when it wakes. When it sleeps, the fade duration also goes back to automatic, as LogoLight does. - A rise from exactly dark waits for a display frame, up to 0.5 s. Short dark beats (up to 0.35 s) turn round before their fall ends, so they never reach 0. Long ones time their light from when the rise starts. - Every end puts the logo back: lit, with the automatic fade duration. A new marker file (logo-fade) covers a killed child. 1.50.0's marker (logo-blink) still switches back on a logo that version left off. - While LogoLight runs, Codeman leaves the logo to it (process-name check), and the app says so when the switch is turned on. - Settings from 1.50.0 keep their styles, with the switch on if any was chosen. All three off was that version's default, so it reads as untouched. The tests run the blink against a fake corebrightnessd that moves in 17.5 ms frames on the measured spring curve. It starts each fade 19 ms after the write, ignores a write in the direction it already heads, and holds a rise from exactly dark back by a configurable delay. They pin these cases: - dips never reach 0 - long dark beats keep their light - no keyboard is told to light while the display sleeps - every end leaves the automatic duration and a lit logo - a logo switched off or driven by LogoLight is left alone - old settings are migrated An ignored probe (what_this_mac_answers) reads a Mac's displays, processes, keyboards and logo without writing anything. Not measured on the real logo, since there was no MacBook to test on: - how the 0.12 to 0.36 s fades of the hard styles look - whether a rise from a dip (about 7%) really skips the frame wait - the keyboard during Alarm - the keyboards through a real display sleep Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
404930d55e |
refactor(desktop): policy, logo and the connect page, simpler and the same
No behavior change: the connect page renders pixel-identical in eight states (Chromium, before and after), posts the same messages, and passes its jsdom and browser tests. - policy.rs: the connect commands' camelCase fields come from serde's rename_all_fields instead of three per-field renames; parse_ipc's length and id checks are match guards like its other arms, with the message cap named (MAX_MESSAGE_LEN); new_window reads its URL through external_url, which is the same parse-and-http(s) check. - logo.rs: the stubs for other platforms are one module, and Logo, Marker and recover are private to the file. - connect.html: answers() is the one test for a server that answers (six copies), the running and needs-login rows of This Mac share their branch, prepareWizard, needsAgent, newWait and openTerminal each replace two or three copies, a finished install and a finished agent share their path, host() is displayAddress(), state.clock is in the state literal, three CSS rules that matched nothing are gone, and the state comments say what wait and gui hold now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
7edf1a1c27 |
feat(desktop): a blink style for each state of the agents
The logo said one thing: agents are working. It now has a style of its own for each state the tabs show: at work, finished and waiting for you (yellow), and stopped on a permission or a question (red), set under View > Blink Apple Logo. The most urgent state with a style wins, red then yellow then work, and a state set to Off falls through to the next instead of silencing the logo. Red and yellow come from `GET /api/approvals`, the list the page rebuilds those tabs from after a reload, read natively for the reason the session list is: WebKit stalls a hidden page's stream. An idle item stops counting once it is acknowledged, so the logo stops when the tab's colour goes. The request is skipped while neither alert has a style, a 404 from an older server reads as no alerts, and a request that fails keeps the last answer. A dialog on screen costs the server one tmux capture per poll. Alarm is new: three sharp flashes and a short rest. It stays under the limit of three flashes in any second, so its urgency comes from its shape. A style saved by the earlier version stays as the one for work, and yellow and red start as Wink and Alarm, since whoever chose one asked for a logo that talks. `SETTLE` goes from 2 s to 3 s, the time the server takes to judge a new dialog, so a prompt answered before its hook landed never flashes red. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
cd4cee15a7 |
feat(desktop): blink the lid Apple logo while agents work
On a MacBook Pro with a PROLED XDR display, the lit Apple logo on the lid can blink while agents work and stop when they finish, so a run can be read from across the room. View > Blink Apple Logo While Agents Work picks a style (Calm, Slow, Wink, Heartbeat, Fast). It is off by default, and the menu exists only on a Mac that has the logo. Apple documents one control for the logo, `sudo defaults write com.apple.CoreBrightness LEBacklightMode -int 0`. The same setting is a property of BrightnessSystemClient in the private CoreBrightness framework, which a process of the logged-in user can set with no administrator, so nothing here needs a helper or a password. The setting is system-wide and survives a reboot, and the release profile has panic = "abort", so the work runs in a child process (this binary with --logo-blink) tied to the app by a pipe. When the pipe closes, however the app ended, the child restores the logo and exits. A marker file covers power loss and a SIGKILL of the child itself. The child asks api/sessions itself: WebKit stalls the event stream of a hidden page, which lost whole turns and ran a blink 39 s past the end. It sends the session cookie of its first answer with every poll, because a good password without a cookie creates a login session each time and Codeman evicts the oldest of 100. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |