Skip to content

Session command line: land #99 - #146

Open
krishhgg wants to merge 13 commits into
integration/menu-controlsfrom
integration/session-command
Open

krishhgg wants to merge 13 commits into
integration/menu-controlsfrom
integration/session-command

Conversation

@krishhgg

@krishhgg krishhgg commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Scripts and coding agents can start, extend and end the menu bar app's session with Insomnia --session start <seconds> | extend <seconds> | end | status. The session they start is the same one the menu bar counts down, and the command line never runs pmset itself.

This lands #99 by @0xRafie at e738536. The commit is merged here unchanged, so GitHub marks #99 merged when this one merges and its author keeps the credit. It sits on #145 (menu controls), because both add an object to the app's launch code. Review and merge #145 first; this pull request's base then moves to main.

To @0xRafie: please don't push to your branch now. A new commit on it isn't in this pull request, so #99 would stay open instead of showing as merged.

Conflicts resolved

Maintainer fix

  • 0ec2765, an extend the cap leaves in place was reported as done. tryExtend returned true whenever it saved the session. At the 30 day cap the new end equals the old one, and after a lower maxDuration in config.json it is earlier, so Insomnia --session extend 3600 printed success for an extension that never happened. It now reports success only when the end moved later, and the command prints its "not extended" reason otherwise. The menu's extend ignores the result and behaves as before. A new test fails without the fix.

Not changed: after a hand-lowered maxDuration, an extend still moves the end in to the new cap, from the menu or the command line. That is main's existing rule ("never past now + maxDuration"); only the command's answer changes.

Tests

Focused on macOS 26.2 (Xcode 26.4.1): SessionCommandTests, DisplaySleepTests, TimeChangeTests and MenuBarCountdownOptionTests pass. Full suite at 0ec2765: 1,275 tests, 0 failures. Since then the only change is merging #145's pill fixes (54f3c7e, 732de03, 85576e5); hosted CI on macOS 26 and 27 passes at 37f87d5. UIStatusTests, UIStartupTests and KeychainStoreTests are skipped on the maintainer's Mac; hosted CI runs them.

Codex review

Clean at 0ec2765 (gpt-6.1-sol, xhigh, read-only): the whole of #99 combined with #145, the merge resolution and the extend fix. A read-only audit of #99 alone at e738536 found only the extend result, fixed in 0ec2765. The commits merged in since are #145's pill fixes, which Codex reviewed on #145 (clean at 85576e5).

Evidence

A macOS 27.0.1 VM run of the command sequence at the final head comes first, then the owner's report from their own Mac on macOS 26 and 27. It covers start, status, extend, end; an end sent before a start; an end whose restore fails and is retried; two command lines at once; an extend at the cap; and a request while the app isn't running.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Adds Insomnia --session commands that drive the running menu bar app.

  • Scripts can start, extend, end, and check an Insomnia session.
  • Capped extensions tell scripts when the session deadline did not move.

No actionable new issues were found. No previous review threads were supplied.

Diagram

sequenceDiagram
    participant CLI as Command line
    participant Files as Support directory
    participant App as Running app
    participant Manager as SessionManager
    CLI->>Files: Publish a separate request
    App->>Files: Claim request by rename
    App->>Manager: Start, extend, or end
    Manager->>Manager: Use existing recovery queue and lock
    Manager->>Files: Write reply
    CLI->>Files: Read and remove reply
    CLI-->>CLI: Print result and exit
Loading

Reviews (4) · Last reviewed commit: "Merge integration/menu-controls: pin the..." · Reviewed by Greptile

0xRafie and others added 10 commits October 12, 2026 20:16
Insomnia --session start <seconds> | extend <seconds> | end | status lets a
script or an agent start, extend and end the session the menu bar counts
down, with the same battery and heat rules. The command line changes
nothing itself: it links one request into session-command in the support
directory, the app's watcher claims it, runs it like the matching menu
action and answers in session-command.reply.<id>. A request nothing claims
within 2 s is taken back, and one older than 5 s is dropped, so a request
left behind never starts a session later.
A start queued behind another, an end whose restore failed, and an end that
arrived while a start was in flight could all answer done. The manager's
tryStart and tryExtend now say whether this call took effect, an end maps
every EndOutcome other than restored to a reason, and an end or extend with
no session yet waits for queued work first. The watcher starts after the
launch reconcile, a request a killed command line left no longer blocks the
next one, a command line waits on and takes back only its own file (by
inode), old answers are removed, and an app still starting is told apart
from an older build.
…nd every time

Greptile on #99: an end that found no session answered done without ending,
which left a dirty journal or an unadopted session.json behind, and the
take-back of a shared request path could still drop another caller's
request when three command lines raced. An end now always runs end(reason:
.user), which also abandons a start in flight. Each command line writes its
own session-command.<id>.request, so publishing, the app's claim and a
take-back are each one rename of that caller's own file, and the app serves
the requests it finds oldest first.
…st runs first

`end` then `start` each run in their own task. While the end waited on the
lifecycle queue or the recovery lock, the early `session != nil` check in
`run(.start)` still saw the old session and refused the start as already
running; the end then ran and left no session. The check is gone, so the
start queues behind the end and `performStart` decides under the lock. The
check after `tryStart` still gives the refusal message.

The new test holds an extend at the backstop arm, queues `end` and then
`start`, and checks that the start makes a new session.
`tryStart` refuses a start while an end is pending, but only when the
request arrives. An end already in the queue can leave itself to its retry
(`scheduleEndRetry` in `performEnd`), and a start queued behind it went on
to start a session that the retry stopped 30 s later. `performStart` now
checks `pendingEnd` as well, with the same refusal.

Removing the early check in `run(.start)` made this reachable from `end`
then `start`; a start sent with no session running could already reach it.
The new test fails the end's arm, lets the start's succeed, and checks the
start is refused and nothing runs.
Lands #99 at e738536, by 0xRafie.

Conflict with #137 and the maintainer's time change fix, resolved here:
each added an app-lifetime object to InsomniaApp, the display sleep and
time change observers and #99's session command watcher. All three are
kept. The observers start first; the watcher starts after the launch
reconcile, as in #99.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tryExtend reported success whenever it saved the session. At the 30 day
cap the new end equals the old one, and after a lower maxDuration in
config.json it is earlier, so `Insomnia --session extend` printed a
success for an extension that never happened. It now reports success
only when the end moved later, and the command line prints its "not
extended" reason otherwise. The menu's extend ignores the result, so it
behaves as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T01:17:15.168092Z 0ec2765 PR opened
🔒 Security Review ✅ Completed 2026-10-24T01:18:55.263207Z 0ec2765 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

krishhgg and others added 3 commits October 23, 2026 20:13
Brings in 54f3c7e, which keeps the pills open when a pill is clicked
on macOS 27.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in 732de03: one refocus watch per press, and the pills return
focus to the app the user was in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in 85576e5, a test seam for the focus-loss test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants