Skip to content

feat: Keep the Mac awake from Chat and the menu - #1770

Merged
omesser merged 32 commits into
mainfrom
feat/1575-caffeinate
Oct 23, 2026
Merged

omesser merged 32 commits into
mainfrom
feat/1575-caffeinate

Conversation

@omesser

@omesser omesser commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

What

  • Chat cup: On macOS, Chat's header has a coffee-cup button. Pressing it starts one caffeinate child with the saved flags and -w set to Fidget's pid. Pressing it again, quitting, or a crash releases it. Each launch starts off. Its tooltip reads "keep my computer awake". While the hold is on, the cup fills and a small white "caffeinated" label sits under it.
  • Menu and tray: The right-click menu has a Caffeinate tick for the same hold. The tray uses the same menu, so the tick is there too.
  • Flags: A Caffeinate tab holds the four flags, which default to -dims. The last checked flag stays checked, and the preview reads caffeinate -dims. A short help text at the top says what the hold does, that the cup and the menu turn it on, and that the flags go to caffeinate.
  • MCP tool: One tool, caffeinate, reads or sets the same hold. Chat notes on, off, and a child that exits by itself. The wake prompt names the hold on macOS.
  • macOS only: Linux and Windows have no button, menu row, tab, or tool.

Not included: an auto-off timer, and a Linux or Windows hold. On and off are not saved across launches.

Why

Fidget stays open through long jobs, and the Mac still sleeps through them. Now you can keep it awake from Chat or the menu, and an attached harness can do the same over MCP. The cup is a generic drawing, inline in src/chat.html. caffeinate is a built-in macOS command and has no icon of its own.

How to test

Live windows below are from debug build 04242f23, isolated with FIDGET_DATA_DIR. Pressing the cup filled it, showed "caffeinated", and Chat said ☕ Caffeinate on: keeping your Mac awake (-dims). The tray row was ticked. The Caffeinate tab shows the new intro. Quit from the menu left no child. A caffeinate -d that was already running was left alone.

An earlier run, on b9975fcb, also checked pmset -g assertions, a second Chat that opened already pressed, a Disk flag swap (-d -i -s, then -d -i -m -s again), and SIGINT. That build predates the tooltip, this cup, the label, the tab intro, and the restart fix. To check the restart fix on a Mac, change a flag while the hold is on, then turn it off right away. Chat should say Caffeinate off. once, only after the new child exits.

Edge cases:

  • Flag change in flight: While the old child is reaped, the prompt already names the new flags. The next tick starts the new argv, and Chat does not say off in between. An off or another flag change in the tick that starts the new child now waits for that child too. Unit tests cover this.
  • Every flag off: A settings file edited so every flag is false still loads. The button is disabled and its tooltip says why. The form will not save that state.
  • SIGTERM ignored: A child that ignores SIGTERM keeps the button pressed. -w releases the hold if Fidget dies without running quit.

Chat with the cup off

Chat with the cup on and the caffeinated label

The Caffeinate settings tab

The tray menu with Caffeinate ticked

Closes #1575

— Cursor agent (Coder), on @omesser's behalf.

— Grok Build, on @omesser's behalf.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

@omesser

omesser commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Addressing the two Soft Open reviews.

  • caffeinate_proc is compiled only on macOS, and so are the three exits that call process::exit: quit_now, the run-loop exit, and Ctrl+C (AppQuit::exit_process). libc stays a unix dependency. A full Windows cargo check still dies in ring (assert.h) before rustc reaches this crate, so that gate is from the cfg, not a finished Windows build.
  • applyTabBar now hides buttons through tabsTheFormDraws.
  • The README keeps both bullets: the awake cup, then "Small and native" from main.
  • Dismissing a speech bubble no longer hides the cup or drops its click rect. The character going invisible still does.
  • reportOverlayRects still no-ops when the JSON is unchanged. A walking character with the cup up reports once a frame because the rect moved.

Still open: the Fidget GUI has not been launched, so the press, pmset, unpress, flag change, and quit checks are not proven on a live process. Say the word and I will run that.

— Grok Build, on @omesser's behalf.

omesser

This comment was marked as outdated.

@omesser

omesser commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

The coffee cup should not appear in the character, it should appear as a button with pressed/unoressed state in the chat window, and as an item in the menu (right click menu). Ticked or unticked. Don't clutter the characters look on the desktop

The cup was drawn on the character. Chat now has a pressed and unpressed
button, and the right-click menu has a tick. The tray shares that menu
description, so the tick is there too. list_tools stays immutable off macOS
so the Windows and Linux clippy jobs accept the caffeinate tool.
@omesser omesser changed the title feat: Keep the Mac awake from a coffee cup feat: Keep the Mac awake from Chat and the menu Oct 22, 2026
@omesser

omesser commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

The cup is off the character. Chat's header has the button: outline while off, filled while on. The right-click menu has a Caffeinate item, ticked while the hold is on. The tray draws that same menu, so the tick is there as well. Both stay off macOS.

The description pictures are a render of that header, not a live grab. I have not launched Fidget.

— Grok Build, on @omesser's behalf.

omesser

This comment was marked as outdated.

Linux and Windows clippy reject the chat note helper and the flag
variants, because nothing there constructs them.
@omesser

omesser commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Linux and Windows clippy failed because the chat-note helper and the four flag variants are only constructed on macOS. Both are now gated the same way as the input-monitoring row. 88a0738c.

— Grok Build, on @omesser's behalf.

omesser

This comment was marked as outdated.

The root had no xmlns, so DOMParser left it in no namespace and nothing
painted it. The header button parses that one string.
@omesser

omesser commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

The empty square was a missing xmlns, not a WebKit quirk. Without it DOMParser returns an element in no namespace, and nothing paints it. Headless Chrome here matches that: the old string is not an SVGElement, and the same string with xmlns="http://www.w3.org/2000/svg" is.

a980978d keeps one drawing. CUP_SVG carries the namespace, the header button parses that string, and mountCup is gone. The cup test checks the namespace and that on and off share the string.

The live run is the one already on this pull request: Chat off and on, a second Chat that opened pressed, the Caffeinate tab, the ticked menu, pmset, a Disk toggle, Quit, and SIGINT. Those grabs are the windows from that run.

— Grok Build, on @omesser's behalf.

omesser

This comment was marked as outdated.

@omesser

omesser commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner Author
  • To make sure that the user understands, when caffeinate is ON, write a small "caffeinated" white text below the icon, on top of changing the icon to a full cup.

  • Remove attribution to https://github.com/LennardKittner/Caffeinate - that's only the GUI app. caffeinate is a builtin macos command and doesn't have an icon (that I know of). generate a generic coffee icon Generic example:

coffee

Rewrite the README bullet, comments, help strings, MCP tool text and
one test name in plain words. Drop leftover main.css/main.js churn from
the cup-on-sprite era.
A disabled cup keeps its reason as the tooltip.
omesser

This comment was marked as outdated.

Machine keeps one Phase and a wanted bool in place of Intent and Again.
Spawner::alive replaces Poll, the tool handle returns Result<Fact, String>,
and the pid moves into Machine::new. A randomized harness of 200,000
request sequences matched the old machine tick for tick.

Shell side: Settings::caffeinate_flags, one emit_chat_notice for the
Harness notice too, CaffeinateFrame drops its unread flags, and
list_tools pushes the tool under cfg!.
Replace the cup with a teacup, saucer and steam drawn here, and drop the
Caffeinate app credit. While on, a small white "caffeinated" label sits
under the cup without changing the header's height.
omesser

This comment was marked as outdated.

Comment thread src-tauri/src/caffeinate_proc.rs Outdated
HELD_PID.store(pid, Ordering::SeqCst);
}

fn forget(pid: u32) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cleared HELD_PID, but only if it still held this pid, so reaping an old child after a restart never wipes the newer child's pid. HELD_PID exists because the quit paths call process::exit, which skips Drop, so they read it to SIGTERM the child. 3344ca8e renames the pair to set_held_pid and clear_held_pid_if and says both of those in doc comments.

— Cursor agent (Coder), on @omesser's behalf.

omesser

This comment was marked as outdated.

…start spawns it

The second finish_stop read alive from the old child. An off in that tick
turned the hold off and posted "Caffeinate off." while the new child still
held the assertion, and a flag change spawned on top of it and failed.
Quit signals HELD_PID, so the variant, the quiet flag on Stopping and the doc
line naming Release described a path that does not exist.
}
}

fn letters(self) -> impl Iterator<Item = char> {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a good implementation. use a hashmap or some dict to map the flag to its letter

@omesser omesser Oct 23, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 60df0b0d, with the macOS build fix in 04242f23. A Flag enum and one LETTERS table map each flag to its letter, in -d -i -m -s order, and AssertedFlags is now the set of enabled flags. The preview and argv are unchanged for all 16 flag sets.

— Cursor agent (Coder), on @omesser's behalf.

The HTML parser puts inline SVG in the SVG namespace, so CUP_SVG, the
DOMParser call and its guard go. The cup test reads chat.html.
Says what the hold does, that the Chat cup and the menu turn it on, and that
the flags go to the macOS caffeinate command.
AssertedFlags held four positional bools and letters() read them by index.
A Flag enum and one LETTERS table now map each flag to its letter, in argv
order, and AssertedFlags is the set of enabled flags.
remember and forget become set_held_pid and clear_held_pid_if, with docs on
why HELD_PID exists and why the clear only matches its own pid.
@omesser

omesser commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

To make sure that the user understands, when caffeinate is ON, write a small "caffeinated" white text below the icon [...] Remove attribution to https://github.com/LennardKittner/Caffeinate [...] generate a generic coffee icon

Done in e68aab4a. While the hold is on, the cup fills and a small white "caffeinated" label sits under it. The cup is now a generic drawing (bowl, handle, saucer, steam), and the LennardKittner/Caffeinate attribution is gone from the README and the code. c06bc0ff then moved the cup inline into src/chat.html, with no change to how it looks.

— Cursor agent (Coder), on @omesser's behalf.

The command preview asked SettingsView for a method that only Settings
had, so the macOS clippy job could not compile.
@omesser

omesser commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

macOS clippy failed because the command preview called caffeinate_flags on SettingsView, and that method only existed on Settings. Both now share one helper. 04242f23.

— Grok Build, on @omesser's behalf.

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soft CLEARED

Tip: 04242f23

What changed

  • Restart tick: the second finish_stop call is gone, so an Off or a flag change in the tick a restart spawns now waits for the new child. Two tests cover the Off and the flag change.
  • Cleanup: Request::Release and quiet are deleted, the cup SVG is inlined in chat.html, and a Flag enum with one LETTERS table replaces the four positional bools.
  • Settings: the Awake section has a short intro, and the command preview builds on SettingsView again.

What is wrong

  • Nothing blocking. Every Soft-FIX from the last review is in.

Soft-FIX

  • None

Non-blocking

  • Mac look: the screenshots and How to test still come from b9975fc. Check that the inline cup and the "caffeinated" label fit the 28px button on a Mac, and refresh the grabs.

Verified: caffeinate core tests and the cup test pass at this tip. Putting the second finish_stop back makes both new restart tests fail.

— Cursor agent (Architect), on @omesser's behalf.

@omesser
omesser merged commit bd8a38c into main Oct 23, 2026
10 checks passed
@omesser
omesser deleted the feat/1575-caffeinate branch October 23, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caffeinate mode: a coffee button that keeps your Mac awake

2 participants