Skip to content

Add idle_keepawake: idle detection + keep machine awake#427

Merged
JE-Chen merged 1 commit into
devfrom
feat/idle-keepawake-batch
Jun 25, 2026
Merged

Add idle_keepawake: idle detection + keep machine awake#427
JE-Chen merged 1 commit into
devfrom
feat/idle-keepawake-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 25, 2026

Copy link
Copy Markdown
Member

Why

Long unattended automation runs get derailed two ways: the screensaver / power policy sleeps the box mid-run, or the run should hold while a human is actively using the machine. The framework had neither signal. Second feature of the ROUND-15 cross-app OS lane (after shell_open).

What

A headless utils/idle_keepawake/ module behind injectable seams so all logic is testable without touching the OS:

  • idle_seconds / is_idle — seconds since the last user keyboard/mouse input (GetLastInputInfo on Windows) through an injectable probe.
  • plan_keep_awake — pure planner describing which wake flags a request maps to.
  • keep_awake — scoped context manager keeping the machine awake for a with block, restoring prior state on exit.
  • keep_awake_on / allow_sleep — process-global on/off pair for JSON action flows (lock-guarded; a second keep_awake_on replaces and releases the prior request).

All keep-awake entry points apply the plan through an injectable driverSetThreadExecutionState (Windows), caffeinate (macOS), systemd-inhibit (Linux) by default. The live OS paths are platform-specific (untested in Linux CI, like shell_open's opener); the headless tests drive the logic through fake probe/driver.

Five-layer coverage

  • Headless core: je_auto_control/utils/idle_keepawake/ (no PySide6).
  • Facade: re-exported from je_auto_control/__init__.py + __all__.
  • Executor: AC_idle_seconds, AC_is_idle, AC_plan_keep_awake, AC_keep_awake_on, AC_allow_sleep.
  • MCP: matching ac_* tools (reads read-only; keep-awake on/off side-effect-only).
  • Script Builder: commands under Shell.

Docs: EN/Zh v204_features_doc.rst + WHATS_NEW. Headless test test_idle_keepawake_batch.py (14 tests, fake probe/driver). Full headless suite green (3793 passed). Verified the real Win32 probe + SetThreadExecutionState keep-awake path end-to-end on Windows.

Long unattended runs derail two ways: the screensaver/power policy sleeps
the box mid-run, or the run should hold while a human is using the machine.
The framework had neither signal. idle_seconds/is_idle read time since the
last input (GetLastInputInfo on Windows) through an injectable probe;
keep_awake (scoped CM) and keep_awake_on/allow_sleep (process-global on/off
for JSON flows) stop the system and display sleeping through an injectable
driver (SetThreadExecutionState/caffeinate/systemd-inhibit by default),
restored on release. plan_keep_awake is the pure planner. All logic is
unit-testable without touching the OS via the injected probe/driver.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 55 complexity · 0 duplication

Metric Results
Complexity 55
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit c096c05 into dev Jun 25, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/idle-keepawake-batch branch June 25, 2026 00:08
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant