@narumitw/pi-caffeinate 0.49.3 → 0.49.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,23 +1,16 @@
1
- # ☕ pi-caffeinate — Keep Your Computer Awake While Pi Works
1
+ # ☕ pi-caffeinate — Keep Your Computer Awake While Pi Runs
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-caffeinate)](https://www.npmjs.com/package/@narumitw/pi-caffeinate) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- `@narumitw/pi-caffeinate` is a cross-platform [Pi coding agent](https://pi.dev) extension that prevents your computer from sleeping while the Pi agent is processing a prompt.
6
-
7
- It is designed for long-running coding, refactoring, debugging, web research, and autonomous agent workflows where a suspended laptop or desktop would interrupt progress.
5
+ Prevent system or display sleep while Pi is processing a prompt, then release the inhibitor as soon as the run ends.
8
6
 
9
7
  ## ✨ Features
10
8
 
11
- - Starts an OS sleep inhibitor when Pi begins processing (`agent_start`).
12
- - Releases the inhibitor when processing ends (`agent_end`) or the session shuts down.
13
- - Publishes the active keep-awake mode as status while an inhibitor is active, unless quiet mode is enabled.
14
- - Supports macOS, Windows, WSL, and Linux.
15
- - Defaults to display-awake mode on every supported OS: prevent system sleep and keep the screen/display awake.
16
- - Provides a single `/caffeinate` command with menu-based controls and direct subcommands.
17
- - Persists the selected keep-awake mode and optional quiet mode in a small JSON settings file.
18
- - Allows a custom inhibitor command through environment configuration.
19
- - Emits plain status text; `@narumitw/pi-statusline` can add or suppress the status icon from JSON config.
20
- - Fails safely when no supported inhibitor is available.
9
+ - Starts an OS sleep inhibitor when a Pi run begins and releases it when the run or session ends.
10
+ - Supports macOS, Windows, WSL, and Linux with a display-awake default.
11
+ - Provides `/caffeinate` controls for the keep-awake mode, current status, and quiet mode.
12
+ - Persists preferences locally and accepts an optional custom inhibitor command.
13
+ - Shows activity only while the inhibitor is active and fails safely when no supported mechanism is available.
21
14
 
22
15
  ## 📦 Install
23
16
 
@@ -34,12 +27,22 @@ pi -e npm:@narumitw/pi-caffeinate
34
27
  Try this package locally from the repository root:
35
28
 
36
29
  ```bash
37
- pi -e ./extensions/pi-caffeinate
30
+ npm --workspace @narumitw/pi-caffeinate run build
31
+ pi -e ./packages/pi-caffeinate
38
32
  ```
39
33
 
34
+ The package declares `dist/index.ts`, so an unbuilt local checkout must be built before Pi loads the package directory.
35
+
36
+ ## 🚀 Quick start
37
+
38
+ Load the extension and use Pi normally.
39
+ During an agent run, pi-caffeinate uses the saved keep-awake mode and defaults to keeping both the system and display awake.
40
+ Run `/caffeinate` to open the controls or `/caffeinate status` to inspect the current state.
41
+
40
42
  ## 🖥️ Supported platforms
41
43
 
42
- The default mode is `display` on every supported OS. That means pi-caffeinate prevents system sleep, suspend, or hibernate and keeps the screen/display awake.
44
+ The default mode is `display` on every supported OS.
45
+ That means pi-caffeinate prevents system sleep, suspend, or hibernate and keeps the screen/display awake.
43
46
 
44
47
  Use `/caffeinate sleep` if you want to prevent system sleep while allowing normal display idle behavior such as screen blanking or monitor power-off.
45
48
 
@@ -48,43 +51,55 @@ Use `/caffeinate sleep` if you want to prevent system sleep while allowing norma
48
51
  | macOS | `caffeinate -ims` | `caffeinate -dimsu` |
49
52
  | Windows | PowerShell `SetThreadExecutionState(0x80000001)` | PowerShell `SetThreadExecutionState(0x80000003)` |
50
53
  | WSL | Windows `powershell.exe` with `SetThreadExecutionState(0x80000001)` | Windows `powershell.exe` with `SetThreadExecutionState(0x80000003)` |
51
- | Linux with systemd | `systemd-inhibit --what=sleep ... sleep infinity` | `systemd-inhibit --what=idle:sleep ... sleep infinity` |
52
- | Linux fallback | `caffeinate -ims` when available | `caffeinate -dimsu` when available |
54
+ | Linux with systemd | `systemd-inhibit --what=sleep ... sleep infinity` | D-Bus `org.freedesktop.ScreenSaver.Inhibit` + `systemd-inhibit --what=idle:sleep ... sleep infinity` |
55
+ | Linux without systemd | `caffeinate -ims` when available | D-Bus `org.freedesktop.ScreenSaver.Inhibit` + `caffeinate -dimsu` when available; D-Bus only otherwise |
56
+
57
+ On Linux, `display` mode requests idle inhibition through the standard `org.freedesktop.ScreenSaver` D-Bus service, trying both `/org/freedesktop/ScreenSaver` and `/ScreenSaver` for desktop compatibility.
58
+ The session-bus connection stays open for the whole agent turn.
59
+ The inhibition ends when `UnInhibit` is called or the connection closes.
60
+ `systemd-inhibit --what=idle:sleep` runs alongside it to preserve logind idle and sleep inhibition.
61
+ If no ScreenSaver service is available, pi-caffeinate keeps the systemd blocker or `caffeinate` fallback and reports a partial-activation warning.
62
+ If only D-Bus is available, pi-caffeinate reports partial activation because desktop idle is inhibited but direct system suspend may remain possible.
63
+ D-Bus method calls use short deadlines, and stop or shutdown aborts an in-flight acquisition before closing its session-bus connection.
53
64
 
54
65
  If no supported inhibitor is available, the extension stays loaded and reports that caffeinate is unavailable.
55
66
 
56
- ## 🚀 Commands
67
+ ## 💬 Commands
57
68
 
58
69
  ```text
59
70
  /caffeinate
60
71
  ```
61
72
 
62
- Opens standard keep-awake controls in TUI or RPC mode. Print and JSON modes reject the interactive
63
- menu observably; use the direct `status`, `sleep`, `display`, `stop`, or `help` routes instead.
73
+ Opens standard keep-awake controls in TUI or RPC mode.
74
+ Print and JSON modes reject the interactive menu observably; use the direct `status`, `sleep`, `display`, `stop`, or `help` routes instead.
64
75
 
65
76
  ```text
66
77
  /caffeinate display
67
78
  ```
68
79
 
69
- Keeps the system and screen/display awake. If an inhibitor is currently active, it is restarted so the new mode applies immediately.
80
+ Keeps the system and screen/display awake.
81
+ If an inhibitor is currently active, it is restarted so the new mode applies immediately.
70
82
 
71
83
  ```text
72
84
  /caffeinate sleep
73
85
  ```
74
86
 
75
- Keeps the system awake while allowing normal display sleep. If an inhibitor is currently active, it is restarted so the new mode applies immediately.
87
+ Keeps the system awake while allowing normal display sleep.
88
+ If an inhibitor is currently active, it is restarted so the new mode applies immediately.
76
89
 
77
90
  ```text
78
91
  /caffeinate status
79
92
  ```
80
93
 
81
- Shows whether an inhibitor is active, unavailable, disabled, or idle. The status includes the current mode, quiet mode, and settings file path.
94
+ Shows whether an inhibitor is active, unavailable, disabled, or idle.
95
+ The status includes the current mode, quiet mode, and settings file path.
82
96
 
83
97
  ```text
84
98
  /caffeinate mode
85
99
  ```
86
100
 
87
- Opens the standard keep-awake mode selector in TUI or RPC mode. Escape closes the selector.
101
+ Opens the standard keep-awake mode selector in TUI or RPC mode.
102
+ Escape closes the selector.
88
103
 
89
104
  ```text
90
105
  /caffeinate stop
@@ -92,7 +107,7 @@ Opens the standard keep-awake mode selector in TUI or RPC mode. Escape closes th
92
107
 
93
108
  Releases any active inhibitor until Pi starts another agent run.
94
109
 
95
- ## ⚙️ Configuration
110
+ ## ⚙️ Settings
96
111
 
97
112
  ### Persisted settings
98
113
 
@@ -112,25 +127,22 @@ Example:
112
127
  }
113
128
  ```
114
129
 
115
- Set `"quiet": true` to hide the routine `Keeping computer awake (...)` and
116
- `Released pi-caffeinate (agent finished)` lifecycle notifications and keep the `caffeinate` status
117
- item clear while active or unavailable. Quiet mode does not hide warnings or explicit feedback from
118
- `/caffeinate` commands such as `status`, mode changes, help, and manual stop. It defaults to `false`
119
- when omitted. The file is read at startup and on `/reload`; run `/reload` after editing it in a
120
- running Pi session before using mode commands.
121
-
122
- Missing, invalid, or deleted settings default back to `display` mode with quiet mode disabled on
123
- every supported OS. A missing file stays absent until the first successful mode change. Within one Pi process, mode saves run in invocation order, reread the latest valid document, and preserve unknown fields. Malformed
124
- JSON or an invalid recognized field blocks mode saves until repaired instead of being overwritten.
125
- A failed save keeps the prior runtime mode; if restarting an active inhibitor fails after publication,
126
- the extension restores the prior saved mode and inhibitor behavior or reports an explicit rollback
127
- failure.
128
-
129
- Compatibility: older versions used `pi-caffeinate-settings.json`. A legacy-only file remains
130
- readable with a warning and is never modified automatically; rename it to `pi-caffeinate.json`.
131
- The first subsequent settings save writes the canonical file. If both files exist,
132
- `pi-caffeinate.json` wins and the legacy file is ignored. The legacy filename is deprecated
133
- and will be removed in a future major release.
130
+ Set `"quiet": true` to hide the routine `Keeping computer awake (...)` and `Released pi-caffeinate (agent finished)` lifecycle notifications and keep the `caffeinate` status item clear while active or unavailable.
131
+ Quiet mode does not hide warnings or explicit feedback from `/caffeinate` commands such as `status`, mode changes, help, and manual stop.
132
+ It defaults to `false` when omitted.
133
+ The file is read at startup and on `/reload`; run `/reload` after editing it in a running Pi session before using mode commands.
134
+
135
+ Missing, invalid, or deleted settings default back to `display` mode with quiet mode disabled on every supported OS.
136
+ A missing file stays absent until the first successful mode change.
137
+ Within one Pi process, mode saves run in invocation order, reread the latest valid document, and preserve unknown fields.
138
+ Malformed JSON or an invalid recognized field blocks mode saves until repaired instead of being overwritten.
139
+ A failed save keeps the prior runtime mode; if restarting an active inhibitor fails after publication, the extension restores the prior saved mode and inhibitor behavior or reports an explicit rollback failure.
140
+
141
+ Compatibility: older versions used `pi-caffeinate-settings.json`.
142
+ A legacy-only file remains readable with a warning and is never modified automatically; rename it to `pi-caffeinate.json`.
143
+ The first subsequent settings save writes the canonical file.
144
+ If both files exist, `pi-caffeinate.json` wins and the legacy file is ignored.
145
+ The legacy filename is deprecated and will be removed in a future major release.
134
146
 
135
147
  ### Environment variables
136
148
 
@@ -146,9 +158,11 @@ Use a custom inhibitor command:
146
158
  PI_CAFFEINATE_COMMAND='systemd-inhibit --what=idle:sleep --why="pi running" --mode=block sleep infinity' pi
147
159
  ```
148
160
 
149
- The custom command is parsed with shell-like quoting and is run directly without a shell. `PI_CAFFEINATE_COMMAND` takes precedence over the saved mode; `/caffeinate status` reports when a custom command is active.
161
+ The custom command is parsed with shell-like quoting and is run directly without a shell.
162
+ `PI_CAFFEINATE_COMMAND` takes precedence over the saved mode; `/caffeinate status` reports when a custom command is active.
150
163
 
151
- Deprecated: `PI_CAFFEINATE_ICON` still works for now. If you use `@narumitw/pi-statusline`, move the icon to `${PI_CODING_AGENT_DIR:-~/.pi/agent}/pi-statusline.json`:
164
+ Deprecated: `PI_CAFFEINATE_ICON` still works for now.
165
+ If you use `@narumitw/pi-statusline`, move the icon to `${PI_CODING_AGENT_DIR:-~/.pi/agent}/pi-statusline.json`:
152
166
 
153
167
  ```json
154
168
  {
@@ -158,29 +172,43 @@ Deprecated: `PI_CAFFEINATE_ICON` still works for now. If you use `@narumitw/pi-s
158
172
  }
159
173
  ```
160
174
 
161
- Without `@narumitw/pi-statusline`, keep using `PI_CAFFEINATE_ICON` during the compatibility window. In `pi-statusline.json`, use an empty string to show the caffeinate status without an icon.
175
+ Without `@narumitw/pi-statusline`, keep using `PI_CAFFEINATE_ICON` during the compatibility window.
176
+ In `pi-statusline.json`, use an empty string to show the caffeinate status without an icon.
162
177
 
163
178
  ## 🧠 Why use pi-caffeinate?
164
179
 
165
- AI coding agents often run tool-heavy tasks that take several minutes. `pi-caffeinate` keeps your machine awake during active Pi work, helping browser automation, local builds, test runs, code generation, and long prompts finish reliably.
180
+ AI coding agents often run tool-heavy tasks that take several minutes.
181
+ `pi-caffeinate` keeps your machine awake during active Pi work, helping browser automation, local builds, test runs, code generation, and long prompts finish reliably.
182
+
183
+ The default display-awake mode prioritizes uninterrupted long-running Pi work across platforms, including Linux desktops that require idle inhibition to prevent automatic suspend.
184
+ Use `/caffeinate sleep` (shown as `system-awake` in status output) when you prefer normal screen power saving and your system does not need idle inhibition to keep Pi running.
185
+
186
+ ## 📦 Dependencies
166
187
 
167
- The default display-awake mode prioritizes uninterrupted long-running Pi work across platforms, including Linux desktops that require idle inhibition to prevent automatic suspend. Use `/caffeinate sleep` (shown as `system-awake` in status output) when you prefer normal screen power saving and your system does not need idle inhibition to keep Pi running.
188
+ On Linux, `display` mode uses the `dbus-native` package (pure JavaScript, no native build step) to call `org.freedesktop.ScreenSaver` on the session bus.
168
189
 
169
190
  ## 🗂️ Package layout
170
191
 
171
192
  ```txt
172
- extensions/pi-caffeinate/
193
+ packages/pi-caffeinate/
173
194
  ├── src/
174
195
  │ ├── index.ts # Pi package entrypoint
175
196
  │ ├── caffeinate.ts # Extension registration and lifecycle orchestration
176
197
  │ └── *.ts # Package-local inhibitor and settings modules
198
+ ├── dist/ # Generated source-mapped Jiti runtime
199
+ ├── scripts/
200
+ │ └── build-runtime.mjs
201
+ ├── test/
202
+ │ ├── build-runtime.test.ts
203
+ │ └── caffeinate.test.ts
177
204
  ├── README.md
178
205
  ├── LICENSE
179
206
  ├── tsconfig.json
180
207
  └── package.json
181
208
  ```
182
209
 
183
- `index.ts` is the Pi entrypoint and forwards to `caffeinate.ts`; the other source modules are internal.
210
+ `src/index.ts` remains the thin authoritative forwarder, while Pi loads the generated `dist/index.ts` runtime.
211
+ The other source modules are internal.
184
212
 
185
213
  ## 🔎 Keywords
186
214
 
@@ -188,4 +216,5 @@ Pi extension, Pi coding agent, caffeinate, prevent sleep, keep awake, sleep inhi
188
216
 
189
217
  ## 📄 License
190
218
 
191
- MIT. See [`LICENSE`](./LICENSE).
219
+ MIT.
220
+ See [`LICENSE`](./LICENSE).