@narumitw/pi-caffeinate 0.49.5 → 0.49.7
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 +50 -46
- package/dist/index.ts +1 -1
- package/dist/index.ts.map +2 -2
- package/package.json +5 -8
- package/src/dbus-inhibit.ts +2 -1
package/README.md
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-caffeinate) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
Prevent system or display sleep while Pi is
|
|
5
|
+
Prevent system or display sleep while Pi is running an agent task, then release the inhibitor when the run ends.
|
|
6
6
|
|
|
7
7
|
## ✨ Features
|
|
8
8
|
|
|
9
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
|
|
11
|
-
- Provides `/caffeinate` controls for
|
|
10
|
+
- Supports macOS, Windows, WSL, and Linux, with display-awake as the default.
|
|
11
|
+
- Provides `/caffeinate` controls for keep-awake mode and status.
|
|
12
12
|
- Persists preferences locally and accepts an optional custom inhibitor command.
|
|
13
|
-
-
|
|
13
|
+
- Falls back when possible, warns on partial activation, and reports when no inhibitor is available.
|
|
14
14
|
|
|
15
15
|
## 📦 Install
|
|
16
16
|
|
|
@@ -32,19 +32,18 @@ pi -e ./packages/pi-caffeinate
|
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
The package declares `dist/index.ts`, so an unbuilt local checkout must be built before Pi loads the package directory.
|
|
35
|
+
Pi extensions run with the Pi process's user permissions, so install only trusted packages.
|
|
35
36
|
|
|
36
37
|
## 🚀 Quick start
|
|
37
38
|
|
|
38
39
|
Load the extension and use Pi normally.
|
|
39
|
-
During
|
|
40
|
-
Run `/caffeinate`
|
|
40
|
+
During each agent run, pi-caffeinate uses the saved mode and defaults to keeping the system and display awake.
|
|
41
|
+
Run `/caffeinate` for controls or `/caffeinate status` for the current state.
|
|
41
42
|
|
|
42
43
|
## 🖥️ Supported platforms
|
|
43
44
|
|
|
44
|
-
The default
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
The default `display` mode prevents system sleep, suspend, or hibernate and keeps the display awake.
|
|
46
|
+
Use `/caffeinate sleep` to prevent system sleep while allowing normal screen blanking or monitor power-off.
|
|
48
47
|
|
|
49
48
|
| Platform | `sleep` mode | `display` mode, default |
|
|
50
49
|
| --- | --- | --- |
|
|
@@ -54,13 +53,13 @@ Use `/caffeinate sleep` if you want to prevent system sleep while allowing norma
|
|
|
54
53
|
| Linux with systemd | `systemd-inhibit --what=sleep ... sleep infinity` | D-Bus `org.freedesktop.ScreenSaver.Inhibit` + `systemd-inhibit --what=idle:sleep ... sleep infinity` |
|
|
55
54
|
| Linux without systemd | `caffeinate -ims` when available | D-Bus `org.freedesktop.ScreenSaver.Inhibit` + `caffeinate -dimsu` when available; D-Bus only otherwise |
|
|
56
55
|
|
|
57
|
-
On Linux, `display` mode requests idle inhibition
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
`systemd-inhibit --what=idle:sleep` runs alongside
|
|
61
|
-
If
|
|
62
|
-
If only D-Bus is available,
|
|
63
|
-
D-Bus
|
|
56
|
+
On Linux, `display` mode requests idle inhibition from `org.freedesktop.ScreenSaver` over D-Bus.
|
|
57
|
+
It tries `/org/freedesktop/ScreenSaver` and `/ScreenSaver` for desktop compatibility and keeps the session-bus connection open for the agent turn.
|
|
58
|
+
Calling `UnInhibit` or closing the connection releases the request.
|
|
59
|
+
`systemd-inhibit --what=idle:sleep` runs alongside D-Bus to preserve logind idle and sleep inhibition.
|
|
60
|
+
If the ScreenSaver service is unavailable, pi-caffeinate keeps the systemd or `caffeinate` blocker and warns that activation is partial.
|
|
61
|
+
If only D-Bus is available, it warns that direct system suspend may remain possible.
|
|
62
|
+
D-Bus calls have 2-second deadlines, and stop or shutdown aborts an in-progress acquisition before closing the connection.
|
|
64
63
|
|
|
65
64
|
If no supported inhibitor is available, the extension stays loaded and reports that caffeinate is unavailable.
|
|
66
65
|
|
|
@@ -70,8 +69,9 @@ If no supported inhibitor is available, the extension stays loaded and reports t
|
|
|
70
69
|
/caffeinate
|
|
71
70
|
```
|
|
72
71
|
|
|
73
|
-
Opens
|
|
74
|
-
Print and JSON modes reject the interactive menu
|
|
72
|
+
Opens keep-awake controls in TUI or RPC mode.
|
|
73
|
+
Print and JSON modes reject the interactive menu.
|
|
74
|
+
Direct routes avoid interactive UI, but Pi's print and JSON modes do not display their notification feedback.
|
|
75
75
|
|
|
76
76
|
```text
|
|
77
77
|
/caffeinate display
|
|
@@ -91,21 +91,29 @@ If an inhibitor is currently active, it is restarted so the new mode applies imm
|
|
|
91
91
|
/caffeinate status
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
Shows whether
|
|
95
|
-
The
|
|
94
|
+
Shows whether the inhibitor is active, unavailable, disabled, or idle.
|
|
95
|
+
The result includes the mode, quiet-mode state, and settings path.
|
|
96
96
|
|
|
97
97
|
```text
|
|
98
98
|
/caffeinate mode
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
Opens the
|
|
102
|
-
Escape closes
|
|
101
|
+
Opens the keep-awake mode selector in TUI or RPC mode.
|
|
102
|
+
Escape closes it.
|
|
103
103
|
|
|
104
104
|
```text
|
|
105
105
|
/caffeinate stop
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
Releases
|
|
108
|
+
Releases the active inhibitor until Pi starts another agent run.
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
/caffeinate help
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Shows the canonical command routes.
|
|
115
|
+
In TUI and RPC mode, unknown commands and trailing text show a rejection with the command guide.
|
|
116
|
+
Compatibility aliases are `screen` for `display`, `system` for `sleep`, `off` for `stop`, and `config` or `settings` for `mode`.
|
|
109
117
|
|
|
110
118
|
## ⚙️ Settings
|
|
111
119
|
|
|
@@ -127,21 +135,23 @@ Example:
|
|
|
127
135
|
}
|
|
128
136
|
```
|
|
129
137
|
|
|
130
|
-
Set `"quiet": true` to hide
|
|
131
|
-
Quiet mode does not hide warnings or explicit feedback
|
|
138
|
+
Set `"quiet": true` to hide routine start and release notifications and clear the `caffeinate` status item while active or unavailable.
|
|
139
|
+
Quiet mode does not hide warnings or explicit command feedback.
|
|
132
140
|
It defaults to `false` when omitted.
|
|
133
|
-
The file is read at startup and on `/reload
|
|
141
|
+
The file is read at startup and on `/reload`.
|
|
142
|
+
After editing it in a running session, run `/reload` before using mode commands.
|
|
134
143
|
|
|
135
|
-
Missing, invalid, or deleted settings
|
|
144
|
+
Missing, invalid, or deleted settings use `display` mode with quiet mode off.
|
|
136
145
|
A missing file stays absent until the first successful mode change.
|
|
137
146
|
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
|
|
139
|
-
A failed save keeps the
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
Malformed JSON or an invalid recognized field blocks saves until repaired.
|
|
148
|
+
A failed save keeps the previous runtime mode.
|
|
149
|
+
If applying a published mode fails while an inhibitor is active, the extension restores the previous saved mode and inhibitor or reports a rollback failure.
|
|
150
|
+
|
|
151
|
+
Older versions used `pi-caffeinate-settings.json`.
|
|
152
|
+
A legacy-only file remains readable with a warning and is not modified automatically; rename it to `pi-caffeinate.json`.
|
|
153
|
+
The next settings save writes the canonical file.
|
|
154
|
+
If both files exist, `pi-caffeinate.json` takes precedence.
|
|
145
155
|
The legacy filename is deprecated and will be removed in a future major release.
|
|
146
156
|
|
|
147
157
|
### Environment variables
|
|
@@ -158,8 +168,8 @@ Use a custom inhibitor command:
|
|
|
158
168
|
PI_CAFFEINATE_COMMAND='systemd-inhibit --what=idle:sleep --why="pi running" --mode=block sleep infinity' pi
|
|
159
169
|
```
|
|
160
170
|
|
|
161
|
-
The custom command
|
|
162
|
-
`PI_CAFFEINATE_COMMAND`
|
|
171
|
+
The custom command uses shell-like argument parsing but runs directly without a shell.
|
|
172
|
+
`PI_CAFFEINATE_COMMAND` overrides the saved mode, and `/caffeinate status` reports the override.
|
|
163
173
|
|
|
164
174
|
Deprecated: `PI_CAFFEINATE_ICON` still works for now.
|
|
165
175
|
If you use `@narumitw/pi-statusline`, move the icon to `${PI_CODING_AGENT_DIR:-~/.pi/agent}/pi-statusline.json`:
|
|
@@ -173,19 +183,13 @@ If you use `@narumitw/pi-statusline`, move the icon to `${PI_CODING_AGENT_DIR:-~
|
|
|
173
183
|
```
|
|
174
184
|
|
|
175
185
|
Without `@narumitw/pi-statusline`, keep using `PI_CAFFEINATE_ICON` during the compatibility window.
|
|
176
|
-
In `pi-statusline.json`, use an empty string to show
|
|
177
|
-
|
|
178
|
-
## 🧠 Why use pi-caffeinate?
|
|
179
|
-
|
|
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.
|
|
186
|
+
In `pi-statusline.json`, use an empty string to show caffeinate status without an icon.
|
|
182
187
|
|
|
183
|
-
|
|
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.
|
|
188
|
+
Status output calls `display` mode `display-awake` and `sleep` mode `system-awake`.
|
|
185
189
|
|
|
186
190
|
## 📦 Dependencies
|
|
187
191
|
|
|
188
|
-
On Linux, `display` mode uses the `dbus-native` package
|
|
192
|
+
On Linux, `display` mode uses the pure-JavaScript `dbus-native` package to call `org.freedesktop.ScreenSaver` on the session bus.
|
|
189
193
|
|
|
190
194
|
## 🗂️ Package layout
|
|
191
195
|
|
package/dist/index.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import process4 from "node:process";
|
|
6
6
|
|
|
7
7
|
// src/dbus-inhibit.ts
|
|
8
|
-
import { sessionBus } from "dbus-native";
|
|
9
8
|
var SCREENSAVER_BUS_NAME = "org.freedesktop.ScreenSaver";
|
|
10
9
|
var SCREENSAVER_INTERFACE = "org.freedesktop.ScreenSaver";
|
|
11
10
|
var INHIBIT_REASON = "Pi agent is running";
|
|
@@ -13,6 +12,7 @@ var INHIBIT_APPLICATION_NAME = "pi-caffeinate";
|
|
|
13
12
|
var SCREENSAVER_OBJECT_PATHS = ["/org/freedesktop/ScreenSaver", "/ScreenSaver"];
|
|
14
13
|
var DBUS_CALL_TIMEOUT_MS = 2e3;
|
|
15
14
|
async function defaultDbusScreenSaverFactory() {
|
|
15
|
+
const { sessionBus } = await import("dbus-native");
|
|
16
16
|
return new NativeScreenSaverClient(sessionBus());
|
|
17
17
|
}
|
|
18
18
|
var NativeScreenSaverClient = class {
|
package/dist/index.ts.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/caffeinate.ts", "../src/dbus-inhibit.ts", "../src/inhibitor-process.ts", "../src/inhibitors.ts", "../src/settings.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ChildProcess } from \"node:child_process\";\nimport process from \"node:process\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"@earendil-works/pi-coding-agent\";\nimport {\n\ttype DbusScreenSaverClient,\n\ttype DbusScreenSaverFactory,\n\tdefaultDbusScreenSaverFactory,\n\tINHIBIT_REASON,\n\tSCREENSAVER_BUS_NAME,\n} from \"./dbus-inhibit.js\";\nimport { startInhibitorProcess, stopInhibitorProcess } from \"./inhibitor-process.js\";\nimport { formatMode, getInhibitorCommand, type InhibitorCommand } from \"./inhibitors.js\";\nimport {\n\ttype CaffeinateMode,\n\ttype CaffeinateSettings,\n\tloadSettings,\n\tsaveSettings,\n\tsettingsFilePath,\n} from \"./settings.js\";\n\nconst STATUS_KEY = \"caffeinate\";\nconst DISABLED_VALUES = new Set([\"1\", \"true\", \"yes\", \"on\"]);\nconst DEFAULT_MODE = \"display\" satisfies CaffeinateMode;\nconst COMMAND_COMPLETIONS = [\n\t{ value: \"display\", label: \"display\", description: \"Keep system and display awake\" },\n\t{ value: \"sleep\", label: \"sleep\", description: \"Keep system awake; allow display sleep\" },\n\t{ value: \"status\", label: \"status\", description: \"Show current status\" },\n\t{ value: \"mode\", label: \"mode\", description: \"Choose keep-awake mode\" },\n\t{ value: \"stop\", label: \"stop\", description: \"Release inhibitor for now\" },\n\t{ value: \"help\", label: \"help\", description: \"Show command help\" },\n];\nconst MENU_OPTIONS = {\n\tdisplay: \"Keep system and display awake\",\n\tsleep: \"Keep system awake; allow display sleep\",\n\tstatus: \"Show current status\",\n\tstop: \"Release inhibitor for now\",\n\thelp: \"Show command help\",\n} as const;\nconst MODE_OPTIONS = {\n\tdisplay: \"Keep system and display awake\",\n\tsleep: \"Keep system awake; allow display sleep\",\n} as const;\n\ntype CommandAction = \"menu\" | \"help\" | \"status\" | \"mode\" | \"sleep\" | \"display\" | \"stop\";\ntype CommandContext = ExtensionCommandContext;\n\ninterface CaffeinateOptions {\n\tdbusFactory?: DbusScreenSaverFactory;\n}\n\ninterface PendingDbusStart {\n\ttoken: number;\n\tcontroller: AbortController;\n\tclient?: DbusScreenSaverClient;\n}\n\ninterface CaffeinateState {\n\tprocess?: ChildProcess;\n\tdbus?: DbusScreenSaverClient;\n\tcurrentSession?: { generation: number; ctx: ExtensionContext };\n\tdbusCleanup?: Promise<void>;\n\tpendingDbus?: PendingDbusStart;\n\tstartedAt?: number;\n\tcommand?: InhibitorCommand;\n\tlastError?: string;\n\tinhibitWarning?: string;\n\tinhibitorStarting: boolean;\n\tactiveTurns: number;\n\tavailable: boolean;\n\tdisabled: boolean;\n\tmode: CaffeinateMode;\n\tquiet: boolean;\n\tsettingsLoaded: boolean;\n\tsettingsError?: string;\n\tsettingsNotice?: string;\n\ticonWarningShown: boolean;\n\tsessionGeneration: number;\n\tmenuController: AbortController;\n}\n\nconst state: CaffeinateState = {\n\tactiveTurns: 0,\n\tavailable: true,\n\tinhibitorStarting: false,\n\tdisabled: isDisabled(),\n\tmode: DEFAULT_MODE,\n\tquiet: false,\n\tsettingsLoaded: false,\n\ticonWarningShown: false,\n\tsessionGeneration: 0,\n\tmenuController: new AbortController(),\n};\n\nlet dbusFactory = defaultDbusScreenSaverFactory;\nlet inhibitSequence = 0;\n\nexport default function caffeinate(pi: ExtensionAPI, options: CaffeinateOptions = {}) {\n\tdbusFactory = options.dbusFactory ?? defaultDbusScreenSaverFactory;\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tconst generation = ++state.sessionGeneration;\n\t\tstate.currentSession = { generation, ctx };\n\t\treplaceMenuController(\"Caffeinate session replaced\");\n\t\tstate.iconWarningShown = false;\n\t\tstate.settingsNotice = undefined;\n\t\twarnDeprecatedIcon(ctx);\n\t\tawait loadSettingsIntoState(ctx, generation);\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tupdateStatus(ctx);\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tconst generation = state.sessionGeneration;\n\t\tawait ensureSettingsLoaded(ctx, generation);\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tstate.activeTurns += 1;\n\t\tawait startInhibitor(ctx, generation, { notify: !state.quiet });\n\t});\n\n\tpi.on(\"agent_end\", async (_event, ctx) => {\n\t\tconst generation = state.sessionGeneration;\n\t\tstate.activeTurns = Math.max(0, state.activeTurns - 1);\n\t\tif (state.activeTurns === 0) {\n\t\t\tawait stopInhibitor(ctx, \"agent finished\", { notify: !state.quiet });\n\t\t}\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tupdateStatus(ctx);\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tconst generation = ++state.sessionGeneration;\n\t\tstate.currentSession = undefined;\n\t\tstate.menuController.abort(new DOMException(\"Caffeinate session shut down\", \"AbortError\"));\n\t\tstate.activeTurns = 0;\n\t\tawait stopInhibitor(ctx, \"session shutdown\", { notify: false });\n\t\tawait modeOperationQueue;\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t});\n\n\tpi.registerCommand(\"caffeinate\", {\n\t\tdescription: \"Open pi-caffeinate keep-awake controls\",\n\t\tgetArgumentCompletions: (prefix) => commandCompletions(prefix),\n\t\thandler: async (args, ctx) => {\n\t\t\tconst generation = state.sessionGeneration;\n\t\t\tconst command = parseCommand(args);\n\t\t\tif (command === \"sleep\" || command === \"display\") {\n\t\t\t\tawait setModeAfterSettingsLoad(ctx, command, generation);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait ensureSettingsLoaded(ctx, generation);\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tawait handleCaffeinateCommand(args, ctx, generation);\n\t\t},\n\t});\n}\n\nasync function handleCaffeinateCommand(args: string, ctx: CommandContext, generation: number) {\n\tconst command = parseCommand(args);\n\tswitch (command) {\n\t\tcase \"menu\":\n\t\t\tawait showMenu(ctx, generation);\n\t\t\treturn;\n\t\tcase \"help\":\n\t\t\tctx.ui.notify(buildCommandGuide(), \"info\");\n\t\t\treturn;\n\t\tcase \"status\":\n\t\t\tshowStatus(ctx);\n\t\t\treturn;\n\t\tcase \"mode\":\n\t\t\tawait showModeSelector(ctx, generation);\n\t\t\treturn;\n\t\tcase \"sleep\":\n\t\t\tawait setMode(ctx, \"sleep\", generation);\n\t\t\treturn;\n\t\tcase \"display\":\n\t\t\tawait setMode(ctx, \"display\", generation);\n\t\t\treturn;\n\t\tcase \"stop\":\n\t\t\tawait stopCaffeinate(ctx, \"manual stop\", generation);\n\t\t\treturn;\n\t}\n\n\tctx.ui.notify(`Unknown /caffeinate command: ${args.trim()}\\n\\n${buildCommandGuide()}`, \"warning\");\n}\n\nasync function showMenu(ctx: CommandContext, generation: number) {\n\tawait runCaffeinateMenu(ctx, generation, \"main\");\n}\n\nasync function showModeSelector(ctx: CommandContext, generation: number) {\n\tawait runCaffeinateMenu(ctx, generation, \"mode\");\n}\n\nasync function runCaffeinateMenu(ctx: CommandContext, generation: number, start: \"main\" | \"mode\") {\n\tif (!ctx.hasUI) {\n\t\tthrow new Error(\n\t\t\tstart === \"mode\"\n\t\t\t\t? \"Mode selection requires TUI or RPC mode. Use /caffeinate sleep or /caffeinate display.\"\n\t\t\t\t: `The pi-caffeinate menu requires TUI or RPC mode.\\n\\n${buildCommandGuide()}\\n\\n${describeState()}`,\n\t\t);\n\t}\n\tconst menuSignal = state.menuController.signal;\n\tconst isCurrent = () => generation === state.sessionGeneration && !menuSignal.aborted;\n\tconst { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!isCurrent()) return;\n\ttype Screen = \"main\" | \"mode\";\n\ttype Action = \"display\" | \"sleep\" | \"status\" | \"stop\" | \"help\";\n\tconst menu = defineMenu<undefined, Screen, Action>({\n\t\tstart,\n\t\tscreens: {\n\t\t\tmain: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"pi-caffeinate controls\",\n\t\t\t\tlines: describeState().split(\"\\n\"),\n\t\t\t\titems: Object.entries(MENU_OPTIONS).map(([id, label]) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tlabel,\n\t\t\t\t\taction: id as Action,\n\t\t\t\t})),\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\tmode: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: `pi-caffeinate mode (current: ${formatMode(state.mode)})`,\n\t\t\t\titems: Object.entries(MODE_OPTIONS).map(([id, label]) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tlabel,\n\t\t\t\t\taction: id as Action,\n\t\t\t\t})),\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tdisplay: async () => {\n\t\t\t\tawait setMode(ctx, \"display\", generation);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tsleep: async () => {\n\t\t\t\tawait setMode(ctx, \"sleep\", generation);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tstatus: async () => {\n\t\t\t\tshowStatus(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tstop: async () => {\n\t\t\t\tawait stopCaffeinate(ctx, \"manual stop\", generation);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\thelp: async () => {\n\t\t\t\tctx.ui.notify(buildCommandGuide(), \"info\");\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: menuSignal,\n\t\tisCurrent,\n\t});\n}\n\nfunction replaceMenuController(reason: string) {\n\tstate.menuController.abort(new DOMException(reason, \"AbortError\"));\n\tstate.menuController = new AbortController();\n}\n\nlet modeOperationQueue = Promise.resolve();\n\nfunction setModeAfterSettingsLoad(\n\tctx: ExtensionContext,\n\tmode: CaffeinateMode,\n\tgeneration: number,\n): Promise<void> {\n\treturn enqueueModeOperation(async () => {\n\t\tawait ensureSettingsLoaded(ctx, generation);\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tawait setModeNow(ctx, mode, generation);\n\t});\n}\n\nfunction setMode(ctx: ExtensionContext, mode: CaffeinateMode, generation: number): Promise<void> {\n\treturn enqueueModeOperation(() => setModeNow(ctx, mode, generation));\n}\n\nfunction enqueueModeOperation(operation: () => Promise<void>): Promise<void> {\n\tconst queued = modeOperationQueue.then(operation);\n\tmodeOperationQueue = queued.catch(() => undefined);\n\treturn queued;\n}\n\nasync function setModeNow(ctx: ExtensionContext, mode: CaffeinateMode, generation: number) {\n\tif (generation !== state.sessionGeneration) return;\n\tconst previousMode = state.mode;\n\tconst previousQuiet = state.quiet;\n\tconst restartRequired = Boolean(\n\t\thasActiveInhibitor() && previousMode !== mode && !state.command?.custom,\n\t);\n\tstate.settingsError = undefined;\n\n\tif (restartRequired) {\n\t\tstate.mode = mode;\n\t\tawait stopInhibitor(ctx, \"mode changed\", { notify: false });\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tawait startInhibitor(ctx, generation, { notify: false });\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tif (!hasActiveInhibitor()) {\n\t\t\tconst applicationError = state.lastError ?? \"the inhibitor could not be restarted\";\n\t\t\tstate.mode = previousMode;\n\t\t\tawait startInhibitor(ctx, generation, { notify: false });\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tconst rollbackError = hasActiveInhibitor()\n\t\t\t\t? undefined\n\t\t\t\t: (state.lastError ?? \"the previous inhibitor could not be restored\");\n\t\t\tstate.settingsError = rollbackError\n\t\t\t\t? `mode application failed (${applicationError}); runtime rollback failed: ${rollbackError}`\n\t\t\t\t: `mode application failed and was rolled back: ${applicationError}`;\n\t\t\tctx.ui.notify(`pi-caffeinate ${state.settingsError}`, \"warning\");\n\t\t\tupdateStatus(ctx);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tlet savedSettings: CaffeinateSettings;\n\ttry {\n\t\tsavedSettings = await saveSettings({ mode, updatedAt: Date.now() });\n\t} catch (error) {\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tlet rollbackError: string | undefined;\n\t\tif (restartRequired) {\n\t\t\tstate.mode = previousMode;\n\t\t\tstate.quiet = previousQuiet;\n\t\t\tawait stopInhibitor(ctx, \"settings save failed\", { notify: false });\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tawait startInhibitor(ctx, generation, { notify: false });\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tif (!hasActiveInhibitor()) {\n\t\t\t\trollbackError = state.lastError ?? \"the prior inhibitor was not restored\";\n\t\t\t}\n\t\t}\n\t\tstate.settingsError = rollbackError\n\t\t\t? `settings save failed (${formatError(error)}); runtime rollback failed: ${rollbackError}`\n\t\t\t: `settings save failed: ${formatError(error)}`;\n\t\tctx.ui.notify(\n\t\t\t`pi-caffeinate mode remains ${formatMode(previousMode)}; settings were not saved: ${state.settingsError}`,\n\t\t\t\"warning\",\n\t\t);\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tif (generation !== state.sessionGeneration) return;\n\tstate.mode = mode;\n\tstate.quiet = savedSettings.quiet;\n\tctx.ui.notify(`pi-caffeinate mode set to ${formatMode(mode)} and saved.`, \"info\");\n\tupdateStatus(ctx);\n}\n\nfunction showStatus(ctx: ExtensionContext) {\n\tctx.ui.notify(describeState(), statusLevel());\n\tupdateStatus(ctx);\n}\n\nasync function stopCaffeinate(ctx: ExtensionContext, reason: string, sessionGeneration: number) {\n\tstate.activeTurns = 0;\n\tawait stopInhibitor(ctx, reason);\n\tif (sessionGeneration !== state.sessionGeneration) return;\n\tupdateStatus(ctx);\n}\n\nexport function parseCommand(args: string): CommandAction | \"unknown\" {\n\tconst command = args.trim().toLowerCase();\n\tif (!command) return \"menu\";\n\tif (command === \"help\") return \"help\";\n\tif (command === \"status\") return \"status\";\n\tif (command === \"mode\" || command === \"config\" || command === \"settings\") return \"mode\";\n\tif (command === \"sleep\" || command === \"system\") return \"sleep\";\n\tif (command === \"display\" || command === \"screen\") return \"display\";\n\tif (command === \"stop\" || command === \"off\") return \"stop\";\n\treturn \"unknown\";\n}\n\nexport function commandCompletions(prefix: string) {\n\tconst normalized = prefix.trimStart().toLowerCase();\n\tif (/\\s/.test(normalized)) return null;\n\n\tconst matches = COMMAND_COMPLETIONS.filter((completion) =>\n\t\tcompletion.value.startsWith(normalized),\n\t);\n\treturn matches.length > 0 ? matches : null;\n}\n\nfunction buildCommandGuide() {\n\treturn [\n\t\t\"pi-caffeinate commands:\",\n\t\t\"/caffeinate \u2014 open keep-awake controls\",\n\t\t\"/caffeinate display \u2014 keep the system and display awake\",\n\t\t\"/caffeinate sleep \u2014 keep the system awake while allowing display sleep\",\n\t\t\"/caffeinate status \u2014 show current mode, settings, and inhibitor state\",\n\t\t\"/caffeinate mode \u2014 choose a keep-awake mode\",\n\t\t\"/caffeinate stop \u2014 release the active inhibitor until the next agent run\",\n\t].join(\"\\n\");\n}\n\nasync function startInhibitor(\n\tctx: ExtensionContext,\n\tsessionGeneration: number,\n\toptions: { notify?: boolean } = {},\n) {\n\tif (state.disabled || hasActiveInhibitor() || state.inhibitorStarting) {\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tconst token = ++inhibitSequence;\n\tconst command = getInhibitorCommand(state.mode);\n\tconst wantsDbus =\n\t\t!command?.custom &&\n\t\tstate.mode === \"display\" &&\n\t\tprocess.platform === \"linux\" &&\n\t\t(command === undefined || command.addDbusIdleInhibit === true);\n\tif (!command && !wantsDbus) {\n\t\tstate.available = false;\n\t\tstate.lastError = `No supported sleep inhibitor found for ${process.platform}.`;\n\t\tctx.ui.notify(state.lastError, \"warning\");\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tstate.inhibitorStarting = true;\n\tstate.inhibitWarning = undefined;\n\tlet child: ChildProcess | undefined;\n\tlet childError =\n\t\t!command && wantsDbus\n\t\t\t? \"No supported system sleep inhibitor is available; direct system suspend may remain possible.\"\n\t\t\t: undefined;\n\tlet assembling = true;\n\tconst handleChildFailure = (message: string) => {\n\t\tif (!child || token !== inhibitSequence || state.process !== child) return;\n\t\tstate.process = undefined;\n\t\tstate.command = undefined;\n\t\tif (assembling) {\n\t\t\tchildError = message;\n\t\t\treturn;\n\t\t}\n\t\tapplyChildFailure(message);\n\t};\n\n\tif (command) {\n\t\ttry {\n\t\t\tchild = startInhibitorProcess(\n\t\t\t\tcommand,\n\t\t\t\t(error) => handleChildFailure(`${command.description} failed: ${error.message}`),\n\t\t\t\t(exit) => handleChildFailure(`${command.description} exited unexpectedly (${exit}).`),\n\t\t\t);\n\t\t\tstate.process = child;\n\t\t\tstate.command = command;\n\t\t\tstate.startedAt = Date.now();\n\t\t} catch (error) {\n\t\t\tchildError = `${command.description}: ${formatError(error)}`;\n\t\t}\n\t}\n\n\tlet dbus: DbusScreenSaverClient | undefined;\n\tlet dbusError: string | undefined;\n\tif (wantsDbus) {\n\t\tconst pending: PendingDbusStart = { token, controller: new AbortController() };\n\t\tstate.pendingDbus = pending;\n\t\ttry {\n\t\t\tconst client = await dbusFactory();\n\t\t\tif (!pendingStartIsCurrent(pending, sessionGeneration)) {\n\t\t\t\tawait client.close().catch(() => undefined);\n\t\t\t\tawait cancelPendingStart(token, child, command);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpending.client = client;\n\t\t\tawait client.inhibit(INHIBIT_REASON, pending.controller.signal);\n\t\t\tif (!pendingStartIsCurrent(pending, sessionGeneration)) {\n\t\t\t\tawait cancelPendingStart(token, child, command);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpending.client = undefined;\n\t\t\tstate.pendingDbus = undefined;\n\t\t\tdbus = client;\n\t\t} catch (error) {\n\t\t\tconst stale =\n\t\t\t\t!pendingStartIsCurrent(pending, sessionGeneration) || pending.controller.signal.aborted;\n\t\t\tconst pendingClient = takePendingDbusClient(pending);\n\t\t\tawait pendingClient?.close().catch(() => undefined);\n\t\t\tif (stale) {\n\t\t\t\tawait cancelPendingStart(token, child, command);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdbusError = `D-Bus idle inhibit (${SCREENSAVER_BUS_NAME}): ${formatError(error)}`;\n\t\t}\n\t}\n\n\tassembling = false;\n\tif (startIsStale(token, sessionGeneration)) {\n\t\tawait cancelPendingStart(token, child, command);\n\t\tawait dbus?.close().catch(() => undefined);\n\t\treturn;\n\t}\n\n\tstate.inhibitorStarting = false;\n\tstate.dbus = dbus;\n\tif (dbus) {\n\t\tdbus.setFailureHandler((error) => applyDbusFailure(token, dbus, error));\n\t\tif (state.dbus !== dbus) return;\n\t}\n\tconst failures = [childError, dbusError].filter((failure): failure is string => Boolean(failure));\n\tif (!hasActiveInhibitor()) {\n\t\tstate.startedAt = undefined;\n\t\tstate.command = undefined;\n\t\tstate.available = false;\n\t\tstate.lastError =\n\t\t\tfailures.join(\"; \") || `No supported sleep inhibitor found for ${process.platform}.`;\n\t\tctx.ui.notify(state.lastError, \"warning\");\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tstate.startedAt ??= Date.now();\n\tstate.available = true;\n\tstate.lastError = undefined;\n\tstate.inhibitWarning = failures.length > 0 ? failures.join(\"; \") : undefined;\n\tif (state.inhibitWarning) {\n\t\tctx.ui.notify(`pi-caffeinate is partially active: ${state.inhibitWarning}`, \"warning\");\n\t} else if (options.notify !== false) {\n\t\tctx.ui.notify(`Keeping computer awake (${statusModeLabel()}).`, \"info\");\n\t}\n\tupdateStatus(ctx);\n}\n\nasync function stopInhibitor(\n\tctx: ExtensionContext,\n\treason: string,\n\toptions: { notify?: boolean } = {},\n) {\n\tinhibitSequence += 1;\n\tconst child = state.process;\n\tconst dbus = state.dbus;\n\tconst dbusCleanup = state.dbusCleanup;\n\tconst pending = state.pendingDbus;\n\tconst command = state.command;\n\tconst wasStarting = state.inhibitorStarting;\n\tstate.process = undefined;\n\tstate.dbus = undefined;\n\tstate.dbusCleanup = undefined;\n\tstate.pendingDbus = undefined;\n\tstate.command = undefined;\n\tstate.startedAt = undefined;\n\tstate.inhibitWarning = undefined;\n\tstate.inhibitorStarting = false;\n\tdbus?.setFailureHandler(undefined);\n\tpending?.controller.abort(new DOMException(`Caffeinate stopped: ${reason}`, \"AbortError\"));\n\tconst pendingClient = pending ? takePendingDbusClient(pending) : undefined;\n\tif (child) stopInhibitorProcess(child, command);\n\tif (!child && !dbus && !pendingClient && !wasStarting) {\n\t\tawait dbusCleanup;\n\t\treturn;\n\t}\n\tif (options.notify !== false) ctx.ui.notify(`Released pi-caffeinate (${reason}).`, \"info\");\n\tawait Promise.all([dbusCleanup, pendingClient?.close().catch(() => undefined)]);\n\tif (!dbus) return;\n\ttry {\n\t\tawait dbus.uninhibit();\n\t} catch {\n\t\t// Closing the session-bus connection also releases its inhibition cookie.\n\t}\n\tawait dbus.close().catch(() => undefined);\n}\n\nfunction applyChildFailure(message: string) {\n\tif (state.dbus) {\n\t\tstate.available = true;\n\t\tstate.lastError = undefined;\n\t\tstate.inhibitWarning = message;\n\t} else {\n\t\tstate.startedAt = undefined;\n\t\tstate.available = false;\n\t\tstate.lastError = message;\n\t\tstate.inhibitWarning = undefined;\n\t}\n\tconst ctx = currentSessionContext();\n\tif (!ctx) return;\n\tctx.ui.notify(message, \"warning\");\n\tupdateStatus(ctx);\n}\n\nfunction applyDbusFailure(token: number, client: DbusScreenSaverClient, error: Error) {\n\tif (token !== inhibitSequence || state.dbus !== client) return;\n\tclient.setFailureHandler(undefined);\n\tstate.dbus = undefined;\n\tconst message = `D-Bus idle inhibit (${SCREENSAVER_BUS_NAME}) failed: ${formatError(error)}`;\n\tconst notification = state.process ? `pi-caffeinate is partially active: ${message}` : message;\n\tif (state.process) {\n\t\tstate.available = true;\n\t\tstate.lastError = undefined;\n\t\tstate.inhibitWarning = message;\n\t} else {\n\t\tstate.startedAt = undefined;\n\t\tstate.command = undefined;\n\t\tstate.available = false;\n\t\tstate.lastError = [state.inhibitWarning, message].filter(Boolean).join(\"; \");\n\t\tstate.inhibitWarning = undefined;\n\t}\n\tconst cleanup = client.close().catch(() => undefined);\n\tstate.dbusCleanup = cleanup;\n\tvoid cleanup.then(() => {\n\t\tif (state.dbusCleanup === cleanup) state.dbusCleanup = undefined;\n\t});\n\tconst ctx = currentSessionContext();\n\tif (!ctx) return;\n\tctx.ui.notify(notification, \"warning\");\n\tupdateStatus(ctx);\n}\n\nfunction currentSessionContext() {\n\tconst session = state.currentSession;\n\treturn session?.generation === state.sessionGeneration ? session.ctx : undefined;\n}\n\nfunction hasActiveInhibitor() {\n\treturn Boolean(state.process || state.dbus);\n}\n\nfunction startIsStale(token: number, sessionGeneration: number) {\n\treturn token !== inhibitSequence || sessionGeneration !== state.sessionGeneration;\n}\n\nfunction pendingStartIsCurrent(pending: PendingDbusStart, sessionGeneration: number) {\n\treturn (\n\t\tstate.pendingDbus === pending &&\n\t\t!pending.controller.signal.aborted &&\n\t\t!startIsStale(pending.token, sessionGeneration)\n\t);\n}\n\nfunction takePendingDbusClient(pending: PendingDbusStart) {\n\tif (state.pendingDbus === pending) state.pendingDbus = undefined;\n\tconst client = pending.client;\n\tpending.client = undefined;\n\treturn client;\n}\n\nasync function cancelPendingStart(\n\ttoken: number,\n\tchild: ChildProcess | undefined,\n\tcommand: InhibitorCommand | undefined,\n) {\n\tif (token !== inhibitSequence) return;\n\tinhibitSequence += 1;\n\tstate.inhibitorStarting = false;\n\tconst pending = state.pendingDbus?.token === token ? state.pendingDbus : undefined;\n\tstate.pendingDbus = undefined;\n\tpending?.controller.abort(new DOMException(\"Caffeinate start cancelled\", \"AbortError\"));\n\tconst pendingClient = pending ? takePendingDbusClient(pending) : undefined;\n\tif (child && state.process === child) {\n\t\tstate.process = undefined;\n\t\tstate.command = undefined;\n\t\tstate.startedAt = undefined;\n\t\tstopInhibitorProcess(child, command);\n\t}\n\tawait pendingClient?.close().catch(() => undefined);\n}\n\nfunction updateStatus(ctx: ExtensionContext) {\n\tif (state.disabled || state.quiet) {\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\treturn;\n\t}\n\n\tif (hasActiveInhibitor()) {\n\t\tctx.ui.setStatus(STATUS_KEY, withDeprecatedIcon(statusModeLabel()));\n\t\treturn;\n\t}\n\n\tif (!state.available) {\n\t\tctx.ui.setStatus(STATUS_KEY, withDeprecatedIcon(\"unavailable\"));\n\t\treturn;\n\t}\n\n\tctx.ui.setStatus(STATUS_KEY, undefined);\n}\n\nfunction describeState() {\n\tconst customCommand = hasCustomCommand();\n\tconst lines = [\n\t\t`Mode: ${formatMode(state.mode)}${customCommand ? \" (overridden by custom command)\" : \"\"}`,\n\t\t`Quiet mode: ${state.quiet ? \"enabled\" : \"disabled\"}`,\n\t\t`Settings: ${settingsFilePath()}`,\n\t];\n\n\tif (customCommand) lines.push(\"Custom command: PI_CAFFEINATE_COMMAND overrides the saved mode.\");\n\tif (state.settingsNotice) lines.push(`Settings note: ${state.settingsNotice}`);\n\tif (state.settingsError) lines.push(`Settings warning: ${state.settingsError}`);\n\tif (state.disabled) {\n\t\tlines.unshift(\"pi-caffeinate is disabled by PI_CAFFEINATE_DISABLED.\");\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tif (hasActiveInhibitor()) {\n\t\tconst seconds = state.startedAt ? Math.round((Date.now() - state.startedAt) / 1000) : 0;\n\t\tconst activeParts: string[] = [];\n\t\tif (state.dbus) activeParts.push(`D-Bus idle inhibit (${SCREENSAVER_BUS_NAME})`);\n\t\tif (state.process && state.command) activeParts.push(state.command.description);\n\t\tlines.unshift(\n\t\t\t`pi-caffeinate is active using ${activeParts.join(\" + \") || \"an inhibitor\"} for ${seconds}s.`,\n\t\t);\n\t\tif (state.inhibitWarning) lines.push(`Inhibitor warning: ${state.inhibitWarning}`);\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tif (!state.available) {\n\t\tlines.unshift(`pi-caffeinate is unavailable: ${state.lastError ?? \"unknown reason\"}`);\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tlines.unshift(\n\t\t\"pi-caffeinate is idle and will keep the computer awake during the next agent run.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\nfunction statusLevel() {\n\treturn state.available && !state.settingsError && !state.inhibitWarning ? \"info\" : \"warning\";\n}\n\nfunction statusModeLabel() {\n\tif (state.command?.custom) return \"custom\";\n\treturn formatMode(state.mode);\n}\n\nasync function ensureSettingsLoaded(ctx: ExtensionContext, generation: number) {\n\tif (state.disabled || state.settingsLoaded) return;\n\tawait loadSettingsIntoState(ctx, generation);\n}\n\nasync function loadSettingsIntoState(ctx: ExtensionContext, generation: number) {\n\tif (state.disabled) {\n\t\tstate.settingsLoaded = true;\n\t\tstate.settingsError = undefined;\n\t\tstate.quiet = false;\n\t\treturn;\n\t}\n\n\tconst settings = await loadSettings();\n\tif (generation !== state.sessionGeneration) return;\n\tstate.settingsLoaded = true;\n\tstate.settingsError = undefined;\n\tif (settings.notice) {\n\t\tstate.settingsNotice = settings.notice;\n\t\tctx.ui.notify(settings.notice, \"warning\");\n\t}\n\n\tif (settings.kind === \"loaded\") {\n\t\tstate.mode = settings.settings.mode;\n\t\tstate.quiet = settings.settings.quiet;\n\t\treturn;\n\t}\n\n\tstate.mode = DEFAULT_MODE;\n\tstate.quiet = false;\n\tif (settings.kind === \"invalid\") {\n\t\tstate.settingsError = settings.reason;\n\t\tctx.ui.notify(\n\t\t\t`pi-caffeinate settings ignored: ${settings.reason}; using ${formatMode(DEFAULT_MODE)} mode.`,\n\t\t\t\"warning\",\n\t\t);\n\t}\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction isDisabled() {\n\tconst value = process.env.PI_CAFFEINATE_DISABLED?.trim().toLowerCase();\n\treturn value ? DISABLED_VALUES.has(value) : false;\n}\n\nfunction hasCustomCommand() {\n\treturn Boolean(process.env.PI_CAFFEINATE_COMMAND?.trim());\n}\n\nfunction withDeprecatedIcon(text: string) {\n\tconst icon = process.env.PI_CAFFEINATE_ICON?.trim();\n\treturn icon ? `${icon} ${text}` : text;\n}\n\nfunction warnDeprecatedIcon(ctx: ExtensionContext) {\n\tif (state.iconWarningShown || !process.env.PI_CAFFEINATE_ICON?.trim()) return;\n\tstate.iconWarningShown = true;\n\tctx.ui.notify(\n\t\t\"PI_CAFFEINATE_ICON is deprecated but still works for now. If you use @narumitw/pi-statusline, move it to pi-statusline.json (extensionStatusIcons.caffeinate).\",\n\t\t\"warning\",\n\t);\n}\n\nexport {\n\tformatMode,\n\tgetInhibitorCommand,\n\tsplitCommand,\n\twindowsInhibitorScript,\n} from \"./inhibitors.js\";\nexport { normalizeCaffeinateSettings } from \"./settings.js\";\n", "import { type Message, type MessageBus, sessionBus } from \"dbus-native\";\n\nexport const SCREENSAVER_BUS_NAME = \"org.freedesktop.ScreenSaver\";\nexport const SCREENSAVER_INTERFACE = \"org.freedesktop.ScreenSaver\";\nexport const INHIBIT_REASON = \"Pi agent is running\";\n\nconst INHIBIT_APPLICATION_NAME = \"pi-caffeinate\";\nconst SCREENSAVER_OBJECT_PATHS = [\"/org/freedesktop/ScreenSaver\", \"/ScreenSaver\"];\nconst DBUS_CALL_TIMEOUT_MS = 2_000;\n\ntype DbusFailureHandler = (error: Error) => void;\n\nexport interface DbusScreenSaverClient {\n\tsetFailureHandler(handler: DbusFailureHandler | undefined): void;\n\tinhibit(reason: string, signal?: AbortSignal): Promise<void>;\n\tuninhibit(): Promise<void>;\n\tclose(): Promise<void>;\n}\n\nexport type DbusScreenSaverFactory = () => Promise<DbusScreenSaverClient>;\n\nexport async function defaultDbusScreenSaverFactory(): Promise<DbusScreenSaverClient> {\n\treturn new NativeScreenSaverClient(sessionBus());\n}\n\nclass NativeScreenSaverClient implements DbusScreenSaverClient {\n\tprivate cookie?: number;\n\tprivate objectPath?: string;\n\tprivate failureHandler?: DbusFailureHandler;\n\tprivate pendingFailure?: Error;\n\tprivate lastConnectionError?: Error;\n\tprivate closing = false;\n\n\tprivate readonly handleConnectionError = (error: unknown) => {\n\t\tthis.lastConnectionError = toError(error, \"D-Bus session connection failed\");\n\t\tif (this.cookie !== undefined) this.reportFailure(this.lastConnectionError);\n\t};\n\n\tprivate readonly handleConnectionClose = (error?: unknown) => {\n\t\tif (this.closing || this.cookie === undefined) return;\n\t\tthis.reportFailure(\n\t\t\ttoError(error, this.lastConnectionError?.message ?? \"D-Bus session connection closed\"),\n\t\t);\n\t};\n\n\tconstructor(private readonly bus: MessageBus) {\n\t\tthis.bus.connection.on(\"error\", this.handleConnectionError);\n\t\tthis.bus.connection.on(\"close\", this.handleConnectionClose);\n\t}\n\n\tsetFailureHandler(handler: DbusFailureHandler | undefined): void {\n\t\tthis.failureHandler = handler;\n\t\tif (!handler || !this.pendingFailure) return;\n\t\tconst failure = this.pendingFailure;\n\t\tthis.pendingFailure = undefined;\n\t\thandler(failure);\n\t}\n\n\tasync inhibit(reason: string, signal?: AbortSignal): Promise<void> {\n\t\tlet lastError: unknown;\n\t\tfor (const objectPath of SCREENSAVER_OBJECT_PATHS) {\n\t\t\tif (signal?.aborted) throw abortReason(signal);\n\t\t\ttry {\n\t\t\t\tthis.cookie = await invoke<number>(\n\t\t\t\t\tthis.bus,\n\t\t\t\t\t{\n\t\t\t\t\t\tdestination: SCREENSAVER_BUS_NAME,\n\t\t\t\t\t\tpath: objectPath,\n\t\t\t\t\t\tinterface: SCREENSAVER_INTERFACE,\n\t\t\t\t\t\tmember: \"Inhibit\",\n\t\t\t\t\t\tsignature: \"ss\",\n\t\t\t\t\t\tbody: [INHIBIT_APPLICATION_NAME, reason],\n\t\t\t\t\t},\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tthis.objectPath = objectPath;\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tif (signal?.aborted) throw abortReason(signal);\n\t\t\t\tlastError = error;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`D-Bus idle inhibit failed: ${formatError(lastError)}`, {\n\t\t\tcause: lastError,\n\t\t});\n\t}\n\n\tasync uninhibit(): Promise<void> {\n\t\tif (this.cookie === undefined || !this.objectPath) return;\n\t\tconst cookie = this.cookie;\n\t\tthis.cookie = undefined;\n\t\tconst objectPath = this.objectPath;\n\t\tthis.objectPath = undefined;\n\t\tawait invoke<void>(this.bus, {\n\t\t\tdestination: SCREENSAVER_BUS_NAME,\n\t\t\tpath: objectPath,\n\t\t\tinterface: SCREENSAVER_INTERFACE,\n\t\t\tmember: \"UnInhibit\",\n\t\t\tsignature: \"u\",\n\t\t\tbody: [cookie],\n\t\t});\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.closing = true;\n\t\tthis.cookie = undefined;\n\t\tthis.objectPath = undefined;\n\t\tthis.failureHandler = undefined;\n\t\ttry {\n\t\t\tawait this.bus.close();\n\t\t} finally {\n\t\t\tthis.bus.connection.off(\"error\", this.handleConnectionError);\n\t\t\tthis.bus.connection.off(\"close\", this.handleConnectionClose);\n\t\t}\n\t}\n\n\tprivate reportFailure(error: Error): void {\n\t\tif (this.cookie === undefined) return;\n\t\tthis.cookie = undefined;\n\t\tthis.objectPath = undefined;\n\t\tif (this.failureHandler) this.failureHandler(error);\n\t\telse this.pendingFailure = error;\n\t}\n}\n\nfunction invoke<TResult>(\n\tbus: MessageBus,\n\tmessage: Message,\n\tsignal?: AbortSignal,\n): Promise<TResult> {\n\treturn new Promise<TResult>((resolve, reject) => {\n\t\tbus.invoke(message, { signal, timeout: DBUS_CALL_TIMEOUT_MS }, (error, ...values) => {\n\t\t\tif (error) reject(error);\n\t\t\telse resolve(values[0] as TResult);\n\t\t});\n\t});\n}\n\nfunction abortReason(signal: AbortSignal): unknown {\n\treturn signal.reason ?? new DOMException(\"D-Bus idle inhibit cancelled\", \"AbortError\");\n}\n\nfunction toError(error: unknown, fallback: string): Error {\n\treturn error instanceof Error ? error : new Error(fallback);\n}\n\nfunction formatError(error: unknown) {\n\tif (error instanceof Error) {\n\t\treturn error.name === \"Error\" ? error.message : `${error.name}: ${error.message}`;\n\t}\n\treturn String(error);\n}\n", "import { type ChildProcess, spawn } from \"node:child_process\";\nimport process from \"node:process\";\nimport type { InhibitorCommand } from \"./inhibitors.js\";\n\nexport function startInhibitorProcess(\n\tcommand: InhibitorCommand,\n\tonError: (error: Error) => void,\n\tonUnexpectedExit: (description: string) => void,\n): ChildProcess {\n\tconst child = spawn(command.command, command.args, {\n\t\tdetached: false,\n\t\tstdio: [command.releaseOnStdinClose ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t});\n\tchild.once(\"error\", onError);\n\tchild.once(\"exit\", (code, signal) => onUnexpectedExit(formatExit(code, signal)));\n\treturn child;\n}\n\nexport function stopInhibitorProcess(child: ChildProcess, command: InhibitorCommand | undefined) {\n\tchild.removeAllListeners(\"exit\");\n\tchild.removeAllListeners(\"error\");\n\tif (child.killed) return;\n\n\tif (command?.releaseOnStdinClose && child.stdin && !child.stdin.destroyed) {\n\t\tchild.stdin.end();\n\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\tconst killTimer = setTimeout(() => {\n\t\t\t\tif (child.exitCode === null && child.signalCode === null && !child.killed) child.kill();\n\t\t\t}, 2000);\n\t\t\tkillTimer.unref();\n\t\t\tchild.once(\"exit\", () => clearTimeout(killTimer));\n\t\t}\n\t} else if (process.platform === \"win32\") {\n\t\tchild.kill();\n\t} else {\n\t\tchild.kill(\"SIGTERM\");\n\t}\n}\n\nfunction formatExit(code: number | null, signal: NodeJS.Signals | null) {\n\tif (signal) return `signal ${signal}`;\n\treturn `code ${code ?? \"unknown\"}`;\n}\n", "import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport type { CaffeinateMode } from \"./settings.js\";\n\nexport interface InhibitorCommand {\n\tcommand: string;\n\targs: string[];\n\tdescription: string;\n\treleaseOnStdinClose?: boolean;\n\tcustom?: boolean;\n\t/** Display mode also needs D-Bus because logind idle inhibition misses some compositors. */\n\taddDbusIdleInhibit?: boolean;\n}\n\nexport function getInhibitorCommand(mode: CaffeinateMode): InhibitorCommand | undefined {\n\tconst customCommand = process.env.PI_CAFFEINATE_COMMAND?.trim();\n\tif (customCommand) {\n\t\tconst [command, ...args] = splitCommand(customCommand);\n\t\tif (command) return { command, args, description: `custom command (${command})`, custom: true };\n\t}\n\tif (process.platform === \"darwin\") {\n\t\treturn parentBoundUnixCommand(\n\t\t\t\"caffeinate\",\n\t\t\tmacCaffeinateArgs(mode),\n\t\t\tcaffeinateDescription(mode),\n\t\t);\n\t}\n\tif (process.platform === \"linux\") {\n\t\tif (isWsl() && commandExists(\"powershell.exe\")) {\n\t\t\treturn windowsPowerInhibitorCommand(\"powershell.exe\", mode);\n\t\t}\n\t\tif (commandExists(\"systemd-inhibit\")) {\n\t\t\tconst what = mode === \"display\" ? \"idle:sleep\" : \"sleep\";\n\t\t\treturn parentBoundUnixCommand(\n\t\t\t\t\"systemd-inhibit\",\n\t\t\t\t[\n\t\t\t\t\t`--what=${what}`,\n\t\t\t\t\t\"--who=pi-caffeinate\",\n\t\t\t\t\t\"--why=Pi agent is running\",\n\t\t\t\t\t\"--mode=block\",\n\t\t\t\t\t\"sleep\",\n\t\t\t\t\t\"infinity\",\n\t\t\t\t],\n\t\t\t\t`systemd-inhibit (${formatMode(mode)})`,\n\t\t\t\tmode === \"display\",\n\t\t\t);\n\t\t}\n\t\tif (commandExists(\"caffeinate\")) {\n\t\t\treturn parentBoundUnixCommand(\n\t\t\t\t\"caffeinate\",\n\t\t\t\tmacCaffeinateArgs(mode),\n\t\t\t\tcaffeinateDescription(mode),\n\t\t\t\tmode === \"display\",\n\t\t\t);\n\t\t}\n\t}\n\tif (process.platform === \"win32\") return windowsPowerInhibitorCommand(\"powershell.exe\", mode);\n\treturn undefined;\n}\n\nfunction macCaffeinateArgs(mode: CaffeinateMode) {\n\treturn mode === \"sleep\" ? [\"-ims\"] : [\"-dimsu\"];\n}\n\nfunction caffeinateDescription(mode: CaffeinateMode) {\n\treturn `caffeinate (${formatMode(mode)})`;\n}\n\nfunction parentBoundUnixCommand(\n\tcommand: string,\n\targs: string[],\n\tdescription: string,\n\taddDbusIdleInhibit = false,\n): InhibitorCommand {\n\treturn {\n\t\tcommand: \"sh\",\n\t\targs: [\n\t\t\t\"-c\",\n\t\t\tunixParentBoundScript(),\n\t\t\t\"pi-caffeinate-watch\",\n\t\t\tString(process.pid),\n\t\t\tcommand,\n\t\t\t...args,\n\t\t],\n\t\tdescription,\n\t\t...(addDbusIdleInhibit ? { addDbusIdleInhibit: true } : {}),\n\t};\n}\n\nfunction unixParentBoundScript() {\n\treturn `parent=$1; shift; \"$@\" & child=$!; ( while kill -0 \"$parent\" 2>/dev/null; do sleep 5; done; kill \"$child\" 2>/dev/null ) & watcher=$!; cleanup() { kill \"$watcher\" 2>/dev/null; kill \"$child\" 2>/dev/null; wait \"$child\" 2>/dev/null; }; trap 'cleanup; exit 0' INT TERM HUP EXIT; wait \"$child\"; status=$?; kill \"$watcher\" 2>/dev/null; trap - EXIT; exit \"$status\"`;\n}\n\nfunction commandExists(command: string) {\n\tconst searchPath = process.env.PATH ?? \"\";\n\tconst extensions = process.platform === \"win32\" ? [\"\", \".exe\", \".cmd\", \".bat\"] : [\"\"];\n\tfor (const directory of searchPath.split(process.platform === \"win32\" ? \";\" : \":\")) {\n\t\tif (!directory) continue;\n\t\tfor (const extension of extensions) {\n\t\t\tif (existsSync(path.join(directory, `${command}${extension}`))) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\nexport function splitCommand(input: string) {\n\tconst parts: string[] = [];\n\tlet current = \"\";\n\tlet quote: '\"' | \"'\" | undefined;\n\tlet escaping = false;\n\tfor (const char of input) {\n\t\tif (escaping) {\n\t\t\tcurrent += char;\n\t\t\tescaping = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"\\\\\") {\n\t\t\tescaping = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif ((char === '\"' || char === \"'\") && !quote) {\n\t\t\tquote = char;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === quote) {\n\t\t\tquote = undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (/\\s/.test(char) && !quote) {\n\t\t\tif (current) {\n\t\t\t\tparts.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tcurrent += char;\n\t}\n\tif (current) parts.push(current);\n\treturn parts;\n}\n\nfunction windowsPowerInhibitorCommand(command: string, mode: CaffeinateMode): InhibitorCommand {\n\treturn {\n\t\tcommand,\n\t\targs: [\"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\", windowsInhibitorScript(mode)],\n\t\tdescription: `PowerShell SetThreadExecutionState (${formatMode(mode)})`,\n\t\treleaseOnStdinClose: true,\n\t};\n}\n\nexport function windowsInhibitorScript(mode: CaffeinateMode) {\n\tconst flags = mode === \"sleep\" ? \"0x80000001\" : \"0x80000003\";\n\treturn `$ErrorActionPreference = 'Stop'; Add-Type -Namespace Native -Name Power -MemberDefinition '[DllImport(\"kernel32.dll\")] public static extern uint SetThreadExecutionState(uint esFlags);'; $flags = [uint32]'${flags}'; $release = [uint32]'0x80000000'; $stdin = [Console]::OpenStandardInput(); $buffer = New-Object byte[] 1; $readTask = $stdin.ReadAsync($buffer, 0, 1); try { while ($true) { [Native.Power]::SetThreadExecutionState($flags) | Out-Null; if ($readTask.Wait(30000)) { break } } } finally { [Native.Power]::SetThreadExecutionState($release) | Out-Null }`;\n}\n\nfunction isWsl() {\n\ttry {\n\t\treturn existsSync(\"/proc/sys/fs/binfmt_misc/WSLInterop\");\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function formatMode(mode: CaffeinateMode) {\n\treturn mode === \"sleep\" ? \"system-awake\" : \"display-awake\";\n}\n", "import { randomUUID } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { access, lstat, mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport process from \"node:process\";\nimport { getAgentDir } from \"@earendil-works/pi-coding-agent\";\n\nconst NEW_SETTINGS_FILE = \"pi-caffeinate.json\";\nconst LEGACY_SETTINGS_FILE = \"pi-caffeinate-settings.json\";\n\nexport type CaffeinateMode = \"sleep\" | \"display\";\n\nexport interface CaffeinateSettings {\n\tmode: CaffeinateMode;\n\tquiet: boolean;\n\tupdatedAt: number;\n}\n\nexport interface SettingsFileOperations {\n\twrite(path: string, data: string): Promise<void>;\n\trename(source: string, destination: string): Promise<void>;\n}\n\nconst DEFAULT_FILE_OPERATIONS: SettingsFileOperations = {\n\twrite: (path, data) => writeFile(path, data, \"utf8\").then(() => undefined),\n\trename,\n};\n\nexport type SettingsLoadResult =\n\t| { kind: \"missing\"; notice?: string }\n\t| { kind: \"invalid\"; reason: string; notice?: string }\n\t| { kind: \"loaded\"; settings: CaffeinateSettings; notice?: string };\n\nexport async function loadSettings(): Promise<SettingsLoadResult> {\n\tawait settingsSaveQueue;\n\tconst newPath = settingsFilePath();\n\tconst newSettings = await readSettingsFile(newPath);\n\tif (newSettings.kind !== \"missing\") return withLegacyIgnoredNotice(newSettings);\n\n\tconst legacyPath = legacySettingsFilePath();\n\tconst legacySettings = await readSettingsFile(legacyPath);\n\tconst concurrentlyCreatedSettings = await readSettingsFile(newPath);\n\tif (concurrentlyCreatedSettings.kind !== \"missing\") {\n\t\treturn withLegacyIgnoredNotice(concurrentlyCreatedSettings);\n\t}\n\tif (legacySettings.kind === \"missing\") return { kind: \"missing\" };\n\tif (legacySettings.kind === \"invalid\") return legacySettings;\n\n\treturn {\n\t\t...legacySettings,\n\t\tnotice: `Using legacy ${LEGACY_SETTINGS_FILE}; rename it to ${NEW_SETTINGS_FILE}. Future saves write ${NEW_SETTINGS_FILE} without modifying the legacy file.`,\n\t};\n}\n\ninterface SettingsDocumentResult {\n\tresult: SettingsLoadResult;\n\tdocument?: Record<string, unknown>;\n}\n\nasync function readSettingsDocument(filePath: string): Promise<SettingsDocumentResult> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(filePath, \"utf8\");\n\t} catch (error) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return { result: { kind: \"missing\" } };\n\t\treturn { result: { kind: \"invalid\", reason: `${filePath}: ${formatError(error)}` } };\n\t}\n\ttry {\n\t\tconst document = JSON.parse(text) as unknown;\n\t\tconst settings = normalizeCaffeinateSettings(document);\n\t\tif (settings) {\n\t\t\treturn {\n\t\t\t\tresult: { kind: \"loaded\", settings },\n\t\t\t\tdocument: { ...(document as Record<string, unknown>) },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tresult: {\n\t\t\t\tkind: \"invalid\",\n\t\t\t\treason: `${filePath}: expected { \"mode\": \"sleep\" | \"display\", optional \"quiet\": boolean }`,\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\treturn { result: { kind: \"invalid\", reason: `${filePath}: ${formatError(error)}` } };\n\t}\n}\n\nasync function readSettingsFile(filePath: string): Promise<SettingsLoadResult> {\n\treturn (await readSettingsDocument(filePath)).result;\n}\n\nasync function withLegacyIgnoredNotice(settings: SettingsLoadResult): Promise<SettingsLoadResult> {\n\tif (!(await fileExists(legacySettingsFilePath()))) return settings;\n\treturn {\n\t\t...settings,\n\t\tnotice: `pi-caffeinate legacy settings ignored: ${legacySettingsFilePath()} exists, but ${settingsFilePath()} takes precedence. Delete ${LEGACY_SETTINGS_FILE} after confirming your settings.`,\n\t};\n}\n\nasync function fileExists(filePath: string) {\n\ttry {\n\t\tawait access(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function pathEntryExists(filePath: string) {\n\ttry {\n\t\tawait lstat(filePath);\n\t\treturn true;\n\t} catch (error) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return false;\n\t\tthrow error;\n\t}\n}\n\nexport function normalizeCaffeinateSettings(value: unknown): CaffeinateSettings | undefined {\n\tif (!value || typeof value !== \"object\") return undefined;\n\tconst settings = value as { mode?: unknown; quiet?: unknown; updatedAt?: unknown };\n\tif (!isCaffeinateMode(settings.mode)) return undefined;\n\tif (settings.quiet !== undefined && typeof settings.quiet !== \"boolean\") return undefined;\n\tif (settings.updatedAt !== undefined && typeof settings.updatedAt !== \"number\") return undefined;\n\treturn {\n\t\tmode: settings.mode,\n\t\tquiet: settings.quiet ?? false,\n\t\tupdatedAt: settings.updatedAt ?? 0,\n\t};\n}\n\nfunction isCaffeinateMode(value: unknown): value is CaffeinateMode {\n\treturn value === \"sleep\" || value === \"display\";\n}\n\nlet settingsSaveQueue: Promise<unknown> = Promise.resolve();\n\nexport function saveSettings(\n\tsettings: Omit<CaffeinateSettings, \"quiet\"> & { quiet?: boolean },\n\toperations: Partial<SettingsFileOperations> = {},\n): Promise<CaffeinateSettings> {\n\tconst operation = settingsSaveQueue.then(() => saveSettingsNow(settings, operations));\n\tsettingsSaveQueue = operation.catch(() => undefined);\n\treturn operation;\n}\n\nasync function saveSettingsNow(\n\tsettings: Omit<CaffeinateSettings, \"quiet\"> & { quiet?: boolean },\n\toperations: Partial<SettingsFileOperations>,\n): Promise<CaffeinateSettings> {\n\tconst filePath = settingsFilePath();\n\tlet current = await readSettingsDocument(filePath);\n\tconst replaceCanonical = current.result.kind !== \"missing\";\n\tif (!replaceCanonical) current = await readSettingsDocument(legacySettingsFilePath());\n\tif (current.result.kind === \"invalid\") {\n\t\tthrow new Error(`Cannot save pi-caffeinate settings until you repair ${current.result.reason}`);\n\t}\n\tconst document = current.document ?? {};\n\tconst quiet =\n\t\tsettings.quiet ?? (current.result.kind === \"loaded\" ? current.result.settings.quiet : false);\n\tconst nextSettings = { mode: settings.mode, quiet, updatedAt: settings.updatedAt };\n\tconst nextDocument = {\n\t\t...document,\n\t\t...nextSettings,\n\t};\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tconst tempFile = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n\ttry {\n\t\tawait (operations.write ?? DEFAULT_FILE_OPERATIONS.write)(\n\t\t\ttempFile,\n\t\t\t`${JSON.stringify(nextDocument, null, 2)}\\n`,\n\t\t);\n\t\tif (!replaceCanonical && (await pathEntryExists(filePath))) {\n\t\t\tthrow new Error(`${NEW_SETTINGS_FILE} was created concurrently; reopen settings and retry.`);\n\t\t}\n\t\tawait (operations.rename ?? DEFAULT_FILE_OPERATIONS.rename)(tempFile, filePath);\n\t\treturn nextSettings;\n\t} catch (error) {\n\t\tawait rm(tempFile, { force: true }).catch(() => undefined);\n\t\tthrow error;\n\t}\n}\n\nexport function settingsFilePath() {\n\treturn join(agentDir(), NEW_SETTINGS_FILE);\n}\n\nfunction legacySettingsFilePath() {\n\treturn join(agentDir(), LEGACY_SETTINGS_FILE);\n}\n\nfunction agentDir() {\n\treturn getAgentDir();\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
-
"mappings": ";;;;AACA,OA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AAmB;AAC3B,SAAO,QAAQA,SAAQ,IAAI,uBAAuB,KAAK,CAAC;AACzD;AAEA,SAAS,mBAAmB,MAAc;AACzC,QAAM,OAAOA,SAAQ,IAAI,oBAAoB,KAAK;AAClD,SAAO,OAAO,GAAG,IAAI,IAAI,IAAI,KAAK;AACnC;AAEA,SAAS,mBAAmB,KAAuB;AAClD,MAAI,MAAM,oBAAoB,CAACA,SAAQ,IAAI,oBAAoB,KAAK,EAAG;AACvE,QAAM,mBAAmB;AACzB,MAAI,GAAG;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
4
|
+
"sourcesContent": ["import type { ChildProcess } from \"node:child_process\";\nimport process from \"node:process\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"@earendil-works/pi-coding-agent\";\nimport {\n\ttype DbusScreenSaverClient,\n\ttype DbusScreenSaverFactory,\n\tdefaultDbusScreenSaverFactory,\n\tINHIBIT_REASON,\n\tSCREENSAVER_BUS_NAME,\n} from \"./dbus-inhibit.js\";\nimport { startInhibitorProcess, stopInhibitorProcess } from \"./inhibitor-process.js\";\nimport { formatMode, getInhibitorCommand, type InhibitorCommand } from \"./inhibitors.js\";\nimport {\n\ttype CaffeinateMode,\n\ttype CaffeinateSettings,\n\tloadSettings,\n\tsaveSettings,\n\tsettingsFilePath,\n} from \"./settings.js\";\n\nconst STATUS_KEY = \"caffeinate\";\nconst DISABLED_VALUES = new Set([\"1\", \"true\", \"yes\", \"on\"]);\nconst DEFAULT_MODE = \"display\" satisfies CaffeinateMode;\nconst COMMAND_COMPLETIONS = [\n\t{ value: \"display\", label: \"display\", description: \"Keep system and display awake\" },\n\t{ value: \"sleep\", label: \"sleep\", description: \"Keep system awake; allow display sleep\" },\n\t{ value: \"status\", label: \"status\", description: \"Show current status\" },\n\t{ value: \"mode\", label: \"mode\", description: \"Choose keep-awake mode\" },\n\t{ value: \"stop\", label: \"stop\", description: \"Release inhibitor for now\" },\n\t{ value: \"help\", label: \"help\", description: \"Show command help\" },\n];\nconst MENU_OPTIONS = {\n\tdisplay: \"Keep system and display awake\",\n\tsleep: \"Keep system awake; allow display sleep\",\n\tstatus: \"Show current status\",\n\tstop: \"Release inhibitor for now\",\n\thelp: \"Show command help\",\n} as const;\nconst MODE_OPTIONS = {\n\tdisplay: \"Keep system and display awake\",\n\tsleep: \"Keep system awake; allow display sleep\",\n} as const;\n\ntype CommandAction = \"menu\" | \"help\" | \"status\" | \"mode\" | \"sleep\" | \"display\" | \"stop\";\ntype CommandContext = ExtensionCommandContext;\n\ninterface CaffeinateOptions {\n\tdbusFactory?: DbusScreenSaverFactory;\n}\n\ninterface PendingDbusStart {\n\ttoken: number;\n\tcontroller: AbortController;\n\tclient?: DbusScreenSaverClient;\n}\n\ninterface CaffeinateState {\n\tprocess?: ChildProcess;\n\tdbus?: DbusScreenSaverClient;\n\tcurrentSession?: { generation: number; ctx: ExtensionContext };\n\tdbusCleanup?: Promise<void>;\n\tpendingDbus?: PendingDbusStart;\n\tstartedAt?: number;\n\tcommand?: InhibitorCommand;\n\tlastError?: string;\n\tinhibitWarning?: string;\n\tinhibitorStarting: boolean;\n\tactiveTurns: number;\n\tavailable: boolean;\n\tdisabled: boolean;\n\tmode: CaffeinateMode;\n\tquiet: boolean;\n\tsettingsLoaded: boolean;\n\tsettingsError?: string;\n\tsettingsNotice?: string;\n\ticonWarningShown: boolean;\n\tsessionGeneration: number;\n\tmenuController: AbortController;\n}\n\nconst state: CaffeinateState = {\n\tactiveTurns: 0,\n\tavailable: true,\n\tinhibitorStarting: false,\n\tdisabled: isDisabled(),\n\tmode: DEFAULT_MODE,\n\tquiet: false,\n\tsettingsLoaded: false,\n\ticonWarningShown: false,\n\tsessionGeneration: 0,\n\tmenuController: new AbortController(),\n};\n\nlet dbusFactory = defaultDbusScreenSaverFactory;\nlet inhibitSequence = 0;\n\nexport default function caffeinate(pi: ExtensionAPI, options: CaffeinateOptions = {}) {\n\tdbusFactory = options.dbusFactory ?? defaultDbusScreenSaverFactory;\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tconst generation = ++state.sessionGeneration;\n\t\tstate.currentSession = { generation, ctx };\n\t\treplaceMenuController(\"Caffeinate session replaced\");\n\t\tstate.iconWarningShown = false;\n\t\tstate.settingsNotice = undefined;\n\t\twarnDeprecatedIcon(ctx);\n\t\tawait loadSettingsIntoState(ctx, generation);\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tupdateStatus(ctx);\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tconst generation = state.sessionGeneration;\n\t\tawait ensureSettingsLoaded(ctx, generation);\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tstate.activeTurns += 1;\n\t\tawait startInhibitor(ctx, generation, { notify: !state.quiet });\n\t});\n\n\tpi.on(\"agent_end\", async (_event, ctx) => {\n\t\tconst generation = state.sessionGeneration;\n\t\tstate.activeTurns = Math.max(0, state.activeTurns - 1);\n\t\tif (state.activeTurns === 0) {\n\t\t\tawait stopInhibitor(ctx, \"agent finished\", { notify: !state.quiet });\n\t\t}\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tupdateStatus(ctx);\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tconst generation = ++state.sessionGeneration;\n\t\tstate.currentSession = undefined;\n\t\tstate.menuController.abort(new DOMException(\"Caffeinate session shut down\", \"AbortError\"));\n\t\tstate.activeTurns = 0;\n\t\tawait stopInhibitor(ctx, \"session shutdown\", { notify: false });\n\t\tawait modeOperationQueue;\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t});\n\n\tpi.registerCommand(\"caffeinate\", {\n\t\tdescription: \"Open pi-caffeinate keep-awake controls\",\n\t\tgetArgumentCompletions: (prefix) => commandCompletions(prefix),\n\t\thandler: async (args, ctx) => {\n\t\t\tconst generation = state.sessionGeneration;\n\t\t\tconst command = parseCommand(args);\n\t\t\tif (command === \"sleep\" || command === \"display\") {\n\t\t\t\tawait setModeAfterSettingsLoad(ctx, command, generation);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait ensureSettingsLoaded(ctx, generation);\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tawait handleCaffeinateCommand(args, ctx, generation);\n\t\t},\n\t});\n}\n\nasync function handleCaffeinateCommand(args: string, ctx: CommandContext, generation: number) {\n\tconst command = parseCommand(args);\n\tswitch (command) {\n\t\tcase \"menu\":\n\t\t\tawait showMenu(ctx, generation);\n\t\t\treturn;\n\t\tcase \"help\":\n\t\t\tctx.ui.notify(buildCommandGuide(), \"info\");\n\t\t\treturn;\n\t\tcase \"status\":\n\t\t\tshowStatus(ctx);\n\t\t\treturn;\n\t\tcase \"mode\":\n\t\t\tawait showModeSelector(ctx, generation);\n\t\t\treturn;\n\t\tcase \"sleep\":\n\t\t\tawait setMode(ctx, \"sleep\", generation);\n\t\t\treturn;\n\t\tcase \"display\":\n\t\t\tawait setMode(ctx, \"display\", generation);\n\t\t\treturn;\n\t\tcase \"stop\":\n\t\t\tawait stopCaffeinate(ctx, \"manual stop\", generation);\n\t\t\treturn;\n\t}\n\n\tctx.ui.notify(`Unknown /caffeinate command: ${args.trim()}\\n\\n${buildCommandGuide()}`, \"warning\");\n}\n\nasync function showMenu(ctx: CommandContext, generation: number) {\n\tawait runCaffeinateMenu(ctx, generation, \"main\");\n}\n\nasync function showModeSelector(ctx: CommandContext, generation: number) {\n\tawait runCaffeinateMenu(ctx, generation, \"mode\");\n}\n\nasync function runCaffeinateMenu(ctx: CommandContext, generation: number, start: \"main\" | \"mode\") {\n\tif (!ctx.hasUI) {\n\t\tthrow new Error(\n\t\t\tstart === \"mode\"\n\t\t\t\t? \"Mode selection requires TUI or RPC mode. Use /caffeinate sleep or /caffeinate display.\"\n\t\t\t\t: `The pi-caffeinate menu requires TUI or RPC mode.\\n\\n${buildCommandGuide()}\\n\\n${describeState()}`,\n\t\t);\n\t}\n\tconst menuSignal = state.menuController.signal;\n\tconst isCurrent = () => generation === state.sessionGeneration && !menuSignal.aborted;\n\tconst { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (!isCurrent()) return;\n\ttype Screen = \"main\" | \"mode\";\n\ttype Action = \"display\" | \"sleep\" | \"status\" | \"stop\" | \"help\";\n\tconst menu = defineMenu<undefined, Screen, Action>({\n\t\tstart,\n\t\tscreens: {\n\t\t\tmain: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"pi-caffeinate controls\",\n\t\t\t\tlines: describeState().split(\"\\n\"),\n\t\t\t\titems: Object.entries(MENU_OPTIONS).map(([id, label]) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tlabel,\n\t\t\t\t\taction: id as Action,\n\t\t\t\t})),\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\tmode: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: `pi-caffeinate mode (current: ${formatMode(state.mode)})`,\n\t\t\t\titems: Object.entries(MODE_OPTIONS).map(([id, label]) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tlabel,\n\t\t\t\t\taction: id as Action,\n\t\t\t\t})),\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tdisplay: async () => {\n\t\t\t\tawait setMode(ctx, \"display\", generation);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tsleep: async () => {\n\t\t\t\tawait setMode(ctx, \"sleep\", generation);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tstatus: async () => {\n\t\t\t\tshowStatus(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tstop: async () => {\n\t\t\t\tawait stopCaffeinate(ctx, \"manual stop\", generation);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\thelp: async () => {\n\t\t\t\tctx.ui.notify(buildCommandGuide(), \"info\");\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t},\n\t});\n\tawait runMenu(ctx, menu, {\n\t\tgetState: () => undefined,\n\t\tsignal: menuSignal,\n\t\tisCurrent,\n\t});\n}\n\nfunction replaceMenuController(reason: string) {\n\tstate.menuController.abort(new DOMException(reason, \"AbortError\"));\n\tstate.menuController = new AbortController();\n}\n\nlet modeOperationQueue = Promise.resolve();\n\nfunction setModeAfterSettingsLoad(\n\tctx: ExtensionContext,\n\tmode: CaffeinateMode,\n\tgeneration: number,\n): Promise<void> {\n\treturn enqueueModeOperation(async () => {\n\t\tawait ensureSettingsLoaded(ctx, generation);\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tawait setModeNow(ctx, mode, generation);\n\t});\n}\n\nfunction setMode(ctx: ExtensionContext, mode: CaffeinateMode, generation: number): Promise<void> {\n\treturn enqueueModeOperation(() => setModeNow(ctx, mode, generation));\n}\n\nfunction enqueueModeOperation(operation: () => Promise<void>): Promise<void> {\n\tconst queued = modeOperationQueue.then(operation);\n\tmodeOperationQueue = queued.catch(() => undefined);\n\treturn queued;\n}\n\nasync function setModeNow(ctx: ExtensionContext, mode: CaffeinateMode, generation: number) {\n\tif (generation !== state.sessionGeneration) return;\n\tconst previousMode = state.mode;\n\tconst previousQuiet = state.quiet;\n\tconst restartRequired = Boolean(\n\t\thasActiveInhibitor() && previousMode !== mode && !state.command?.custom,\n\t);\n\tstate.settingsError = undefined;\n\n\tif (restartRequired) {\n\t\tstate.mode = mode;\n\t\tawait stopInhibitor(ctx, \"mode changed\", { notify: false });\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tawait startInhibitor(ctx, generation, { notify: false });\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tif (!hasActiveInhibitor()) {\n\t\t\tconst applicationError = state.lastError ?? \"the inhibitor could not be restarted\";\n\t\t\tstate.mode = previousMode;\n\t\t\tawait startInhibitor(ctx, generation, { notify: false });\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tconst rollbackError = hasActiveInhibitor()\n\t\t\t\t? undefined\n\t\t\t\t: (state.lastError ?? \"the previous inhibitor could not be restored\");\n\t\t\tstate.settingsError = rollbackError\n\t\t\t\t? `mode application failed (${applicationError}); runtime rollback failed: ${rollbackError}`\n\t\t\t\t: `mode application failed and was rolled back: ${applicationError}`;\n\t\t\tctx.ui.notify(`pi-caffeinate ${state.settingsError}`, \"warning\");\n\t\t\tupdateStatus(ctx);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tlet savedSettings: CaffeinateSettings;\n\ttry {\n\t\tsavedSettings = await saveSettings({ mode, updatedAt: Date.now() });\n\t} catch (error) {\n\t\tif (generation !== state.sessionGeneration) return;\n\t\tlet rollbackError: string | undefined;\n\t\tif (restartRequired) {\n\t\t\tstate.mode = previousMode;\n\t\t\tstate.quiet = previousQuiet;\n\t\t\tawait stopInhibitor(ctx, \"settings save failed\", { notify: false });\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tawait startInhibitor(ctx, generation, { notify: false });\n\t\t\tif (generation !== state.sessionGeneration) return;\n\t\t\tif (!hasActiveInhibitor()) {\n\t\t\t\trollbackError = state.lastError ?? \"the prior inhibitor was not restored\";\n\t\t\t}\n\t\t}\n\t\tstate.settingsError = rollbackError\n\t\t\t? `settings save failed (${formatError(error)}); runtime rollback failed: ${rollbackError}`\n\t\t\t: `settings save failed: ${formatError(error)}`;\n\t\tctx.ui.notify(\n\t\t\t`pi-caffeinate mode remains ${formatMode(previousMode)}; settings were not saved: ${state.settingsError}`,\n\t\t\t\"warning\",\n\t\t);\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tif (generation !== state.sessionGeneration) return;\n\tstate.mode = mode;\n\tstate.quiet = savedSettings.quiet;\n\tctx.ui.notify(`pi-caffeinate mode set to ${formatMode(mode)} and saved.`, \"info\");\n\tupdateStatus(ctx);\n}\n\nfunction showStatus(ctx: ExtensionContext) {\n\tctx.ui.notify(describeState(), statusLevel());\n\tupdateStatus(ctx);\n}\n\nasync function stopCaffeinate(ctx: ExtensionContext, reason: string, sessionGeneration: number) {\n\tstate.activeTurns = 0;\n\tawait stopInhibitor(ctx, reason);\n\tif (sessionGeneration !== state.sessionGeneration) return;\n\tupdateStatus(ctx);\n}\n\nexport function parseCommand(args: string): CommandAction | \"unknown\" {\n\tconst command = args.trim().toLowerCase();\n\tif (!command) return \"menu\";\n\tif (command === \"help\") return \"help\";\n\tif (command === \"status\") return \"status\";\n\tif (command === \"mode\" || command === \"config\" || command === \"settings\") return \"mode\";\n\tif (command === \"sleep\" || command === \"system\") return \"sleep\";\n\tif (command === \"display\" || command === \"screen\") return \"display\";\n\tif (command === \"stop\" || command === \"off\") return \"stop\";\n\treturn \"unknown\";\n}\n\nexport function commandCompletions(prefix: string) {\n\tconst normalized = prefix.trimStart().toLowerCase();\n\tif (/\\s/.test(normalized)) return null;\n\n\tconst matches = COMMAND_COMPLETIONS.filter((completion) =>\n\t\tcompletion.value.startsWith(normalized),\n\t);\n\treturn matches.length > 0 ? matches : null;\n}\n\nfunction buildCommandGuide() {\n\treturn [\n\t\t\"pi-caffeinate commands:\",\n\t\t\"/caffeinate \u2014 open keep-awake controls\",\n\t\t\"/caffeinate display \u2014 keep the system and display awake\",\n\t\t\"/caffeinate sleep \u2014 keep the system awake while allowing display sleep\",\n\t\t\"/caffeinate status \u2014 show current mode, settings, and inhibitor state\",\n\t\t\"/caffeinate mode \u2014 choose a keep-awake mode\",\n\t\t\"/caffeinate stop \u2014 release the active inhibitor until the next agent run\",\n\t].join(\"\\n\");\n}\n\nasync function startInhibitor(\n\tctx: ExtensionContext,\n\tsessionGeneration: number,\n\toptions: { notify?: boolean } = {},\n) {\n\tif (state.disabled || hasActiveInhibitor() || state.inhibitorStarting) {\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tconst token = ++inhibitSequence;\n\tconst command = getInhibitorCommand(state.mode);\n\tconst wantsDbus =\n\t\t!command?.custom &&\n\t\tstate.mode === \"display\" &&\n\t\tprocess.platform === \"linux\" &&\n\t\t(command === undefined || command.addDbusIdleInhibit === true);\n\tif (!command && !wantsDbus) {\n\t\tstate.available = false;\n\t\tstate.lastError = `No supported sleep inhibitor found for ${process.platform}.`;\n\t\tctx.ui.notify(state.lastError, \"warning\");\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tstate.inhibitorStarting = true;\n\tstate.inhibitWarning = undefined;\n\tlet child: ChildProcess | undefined;\n\tlet childError =\n\t\t!command && wantsDbus\n\t\t\t? \"No supported system sleep inhibitor is available; direct system suspend may remain possible.\"\n\t\t\t: undefined;\n\tlet assembling = true;\n\tconst handleChildFailure = (message: string) => {\n\t\tif (!child || token !== inhibitSequence || state.process !== child) return;\n\t\tstate.process = undefined;\n\t\tstate.command = undefined;\n\t\tif (assembling) {\n\t\t\tchildError = message;\n\t\t\treturn;\n\t\t}\n\t\tapplyChildFailure(message);\n\t};\n\n\tif (command) {\n\t\ttry {\n\t\t\tchild = startInhibitorProcess(\n\t\t\t\tcommand,\n\t\t\t\t(error) => handleChildFailure(`${command.description} failed: ${error.message}`),\n\t\t\t\t(exit) => handleChildFailure(`${command.description} exited unexpectedly (${exit}).`),\n\t\t\t);\n\t\t\tstate.process = child;\n\t\t\tstate.command = command;\n\t\t\tstate.startedAt = Date.now();\n\t\t} catch (error) {\n\t\t\tchildError = `${command.description}: ${formatError(error)}`;\n\t\t}\n\t}\n\n\tlet dbus: DbusScreenSaverClient | undefined;\n\tlet dbusError: string | undefined;\n\tif (wantsDbus) {\n\t\tconst pending: PendingDbusStart = { token, controller: new AbortController() };\n\t\tstate.pendingDbus = pending;\n\t\ttry {\n\t\t\tconst client = await dbusFactory();\n\t\t\tif (!pendingStartIsCurrent(pending, sessionGeneration)) {\n\t\t\t\tawait client.close().catch(() => undefined);\n\t\t\t\tawait cancelPendingStart(token, child, command);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpending.client = client;\n\t\t\tawait client.inhibit(INHIBIT_REASON, pending.controller.signal);\n\t\t\tif (!pendingStartIsCurrent(pending, sessionGeneration)) {\n\t\t\t\tawait cancelPendingStart(token, child, command);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpending.client = undefined;\n\t\t\tstate.pendingDbus = undefined;\n\t\t\tdbus = client;\n\t\t} catch (error) {\n\t\t\tconst stale =\n\t\t\t\t!pendingStartIsCurrent(pending, sessionGeneration) || pending.controller.signal.aborted;\n\t\t\tconst pendingClient = takePendingDbusClient(pending);\n\t\t\tawait pendingClient?.close().catch(() => undefined);\n\t\t\tif (stale) {\n\t\t\t\tawait cancelPendingStart(token, child, command);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdbusError = `D-Bus idle inhibit (${SCREENSAVER_BUS_NAME}): ${formatError(error)}`;\n\t\t}\n\t}\n\n\tassembling = false;\n\tif (startIsStale(token, sessionGeneration)) {\n\t\tawait cancelPendingStart(token, child, command);\n\t\tawait dbus?.close().catch(() => undefined);\n\t\treturn;\n\t}\n\n\tstate.inhibitorStarting = false;\n\tstate.dbus = dbus;\n\tif (dbus) {\n\t\tdbus.setFailureHandler((error) => applyDbusFailure(token, dbus, error));\n\t\tif (state.dbus !== dbus) return;\n\t}\n\tconst failures = [childError, dbusError].filter((failure): failure is string => Boolean(failure));\n\tif (!hasActiveInhibitor()) {\n\t\tstate.startedAt = undefined;\n\t\tstate.command = undefined;\n\t\tstate.available = false;\n\t\tstate.lastError =\n\t\t\tfailures.join(\"; \") || `No supported sleep inhibitor found for ${process.platform}.`;\n\t\tctx.ui.notify(state.lastError, \"warning\");\n\t\tupdateStatus(ctx);\n\t\treturn;\n\t}\n\n\tstate.startedAt ??= Date.now();\n\tstate.available = true;\n\tstate.lastError = undefined;\n\tstate.inhibitWarning = failures.length > 0 ? failures.join(\"; \") : undefined;\n\tif (state.inhibitWarning) {\n\t\tctx.ui.notify(`pi-caffeinate is partially active: ${state.inhibitWarning}`, \"warning\");\n\t} else if (options.notify !== false) {\n\t\tctx.ui.notify(`Keeping computer awake (${statusModeLabel()}).`, \"info\");\n\t}\n\tupdateStatus(ctx);\n}\n\nasync function stopInhibitor(\n\tctx: ExtensionContext,\n\treason: string,\n\toptions: { notify?: boolean } = {},\n) {\n\tinhibitSequence += 1;\n\tconst child = state.process;\n\tconst dbus = state.dbus;\n\tconst dbusCleanup = state.dbusCleanup;\n\tconst pending = state.pendingDbus;\n\tconst command = state.command;\n\tconst wasStarting = state.inhibitorStarting;\n\tstate.process = undefined;\n\tstate.dbus = undefined;\n\tstate.dbusCleanup = undefined;\n\tstate.pendingDbus = undefined;\n\tstate.command = undefined;\n\tstate.startedAt = undefined;\n\tstate.inhibitWarning = undefined;\n\tstate.inhibitorStarting = false;\n\tdbus?.setFailureHandler(undefined);\n\tpending?.controller.abort(new DOMException(`Caffeinate stopped: ${reason}`, \"AbortError\"));\n\tconst pendingClient = pending ? takePendingDbusClient(pending) : undefined;\n\tif (child) stopInhibitorProcess(child, command);\n\tif (!child && !dbus && !pendingClient && !wasStarting) {\n\t\tawait dbusCleanup;\n\t\treturn;\n\t}\n\tif (options.notify !== false) ctx.ui.notify(`Released pi-caffeinate (${reason}).`, \"info\");\n\tawait Promise.all([dbusCleanup, pendingClient?.close().catch(() => undefined)]);\n\tif (!dbus) return;\n\ttry {\n\t\tawait dbus.uninhibit();\n\t} catch {\n\t\t// Closing the session-bus connection also releases its inhibition cookie.\n\t}\n\tawait dbus.close().catch(() => undefined);\n}\n\nfunction applyChildFailure(message: string) {\n\tif (state.dbus) {\n\t\tstate.available = true;\n\t\tstate.lastError = undefined;\n\t\tstate.inhibitWarning = message;\n\t} else {\n\t\tstate.startedAt = undefined;\n\t\tstate.available = false;\n\t\tstate.lastError = message;\n\t\tstate.inhibitWarning = undefined;\n\t}\n\tconst ctx = currentSessionContext();\n\tif (!ctx) return;\n\tctx.ui.notify(message, \"warning\");\n\tupdateStatus(ctx);\n}\n\nfunction applyDbusFailure(token: number, client: DbusScreenSaverClient, error: Error) {\n\tif (token !== inhibitSequence || state.dbus !== client) return;\n\tclient.setFailureHandler(undefined);\n\tstate.dbus = undefined;\n\tconst message = `D-Bus idle inhibit (${SCREENSAVER_BUS_NAME}) failed: ${formatError(error)}`;\n\tconst notification = state.process ? `pi-caffeinate is partially active: ${message}` : message;\n\tif (state.process) {\n\t\tstate.available = true;\n\t\tstate.lastError = undefined;\n\t\tstate.inhibitWarning = message;\n\t} else {\n\t\tstate.startedAt = undefined;\n\t\tstate.command = undefined;\n\t\tstate.available = false;\n\t\tstate.lastError = [state.inhibitWarning, message].filter(Boolean).join(\"; \");\n\t\tstate.inhibitWarning = undefined;\n\t}\n\tconst cleanup = client.close().catch(() => undefined);\n\tstate.dbusCleanup = cleanup;\n\tvoid cleanup.then(() => {\n\t\tif (state.dbusCleanup === cleanup) state.dbusCleanup = undefined;\n\t});\n\tconst ctx = currentSessionContext();\n\tif (!ctx) return;\n\tctx.ui.notify(notification, \"warning\");\n\tupdateStatus(ctx);\n}\n\nfunction currentSessionContext() {\n\tconst session = state.currentSession;\n\treturn session?.generation === state.sessionGeneration ? session.ctx : undefined;\n}\n\nfunction hasActiveInhibitor() {\n\treturn Boolean(state.process || state.dbus);\n}\n\nfunction startIsStale(token: number, sessionGeneration: number) {\n\treturn token !== inhibitSequence || sessionGeneration !== state.sessionGeneration;\n}\n\nfunction pendingStartIsCurrent(pending: PendingDbusStart, sessionGeneration: number) {\n\treturn (\n\t\tstate.pendingDbus === pending &&\n\t\t!pending.controller.signal.aborted &&\n\t\t!startIsStale(pending.token, sessionGeneration)\n\t);\n}\n\nfunction takePendingDbusClient(pending: PendingDbusStart) {\n\tif (state.pendingDbus === pending) state.pendingDbus = undefined;\n\tconst client = pending.client;\n\tpending.client = undefined;\n\treturn client;\n}\n\nasync function cancelPendingStart(\n\ttoken: number,\n\tchild: ChildProcess | undefined,\n\tcommand: InhibitorCommand | undefined,\n) {\n\tif (token !== inhibitSequence) return;\n\tinhibitSequence += 1;\n\tstate.inhibitorStarting = false;\n\tconst pending = state.pendingDbus?.token === token ? state.pendingDbus : undefined;\n\tstate.pendingDbus = undefined;\n\tpending?.controller.abort(new DOMException(\"Caffeinate start cancelled\", \"AbortError\"));\n\tconst pendingClient = pending ? takePendingDbusClient(pending) : undefined;\n\tif (child && state.process === child) {\n\t\tstate.process = undefined;\n\t\tstate.command = undefined;\n\t\tstate.startedAt = undefined;\n\t\tstopInhibitorProcess(child, command);\n\t}\n\tawait pendingClient?.close().catch(() => undefined);\n}\n\nfunction updateStatus(ctx: ExtensionContext) {\n\tif (state.disabled || state.quiet) {\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\treturn;\n\t}\n\n\tif (hasActiveInhibitor()) {\n\t\tctx.ui.setStatus(STATUS_KEY, withDeprecatedIcon(statusModeLabel()));\n\t\treturn;\n\t}\n\n\tif (!state.available) {\n\t\tctx.ui.setStatus(STATUS_KEY, withDeprecatedIcon(\"unavailable\"));\n\t\treturn;\n\t}\n\n\tctx.ui.setStatus(STATUS_KEY, undefined);\n}\n\nfunction describeState() {\n\tconst customCommand = hasCustomCommand();\n\tconst lines = [\n\t\t`Mode: ${formatMode(state.mode)}${customCommand ? \" (overridden by custom command)\" : \"\"}`,\n\t\t`Quiet mode: ${state.quiet ? \"enabled\" : \"disabled\"}`,\n\t\t`Settings: ${settingsFilePath()}`,\n\t];\n\n\tif (customCommand) lines.push(\"Custom command: PI_CAFFEINATE_COMMAND overrides the saved mode.\");\n\tif (state.settingsNotice) lines.push(`Settings note: ${state.settingsNotice}`);\n\tif (state.settingsError) lines.push(`Settings warning: ${state.settingsError}`);\n\tif (state.disabled) {\n\t\tlines.unshift(\"pi-caffeinate is disabled by PI_CAFFEINATE_DISABLED.\");\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tif (hasActiveInhibitor()) {\n\t\tconst seconds = state.startedAt ? Math.round((Date.now() - state.startedAt) / 1000) : 0;\n\t\tconst activeParts: string[] = [];\n\t\tif (state.dbus) activeParts.push(`D-Bus idle inhibit (${SCREENSAVER_BUS_NAME})`);\n\t\tif (state.process && state.command) activeParts.push(state.command.description);\n\t\tlines.unshift(\n\t\t\t`pi-caffeinate is active using ${activeParts.join(\" + \") || \"an inhibitor\"} for ${seconds}s.`,\n\t\t);\n\t\tif (state.inhibitWarning) lines.push(`Inhibitor warning: ${state.inhibitWarning}`);\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tif (!state.available) {\n\t\tlines.unshift(`pi-caffeinate is unavailable: ${state.lastError ?? \"unknown reason\"}`);\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\tlines.unshift(\n\t\t\"pi-caffeinate is idle and will keep the computer awake during the next agent run.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\nfunction statusLevel() {\n\treturn state.available && !state.settingsError && !state.inhibitWarning ? \"info\" : \"warning\";\n}\n\nfunction statusModeLabel() {\n\tif (state.command?.custom) return \"custom\";\n\treturn formatMode(state.mode);\n}\n\nasync function ensureSettingsLoaded(ctx: ExtensionContext, generation: number) {\n\tif (state.disabled || state.settingsLoaded) return;\n\tawait loadSettingsIntoState(ctx, generation);\n}\n\nasync function loadSettingsIntoState(ctx: ExtensionContext, generation: number) {\n\tif (state.disabled) {\n\t\tstate.settingsLoaded = true;\n\t\tstate.settingsError = undefined;\n\t\tstate.quiet = false;\n\t\treturn;\n\t}\n\n\tconst settings = await loadSettings();\n\tif (generation !== state.sessionGeneration) return;\n\tstate.settingsLoaded = true;\n\tstate.settingsError = undefined;\n\tif (settings.notice) {\n\t\tstate.settingsNotice = settings.notice;\n\t\tctx.ui.notify(settings.notice, \"warning\");\n\t}\n\n\tif (settings.kind === \"loaded\") {\n\t\tstate.mode = settings.settings.mode;\n\t\tstate.quiet = settings.settings.quiet;\n\t\treturn;\n\t}\n\n\tstate.mode = DEFAULT_MODE;\n\tstate.quiet = false;\n\tif (settings.kind === \"invalid\") {\n\t\tstate.settingsError = settings.reason;\n\t\tctx.ui.notify(\n\t\t\t`pi-caffeinate settings ignored: ${settings.reason}; using ${formatMode(DEFAULT_MODE)} mode.`,\n\t\t\t\"warning\",\n\t\t);\n\t}\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction isDisabled() {\n\tconst value = process.env.PI_CAFFEINATE_DISABLED?.trim().toLowerCase();\n\treturn value ? DISABLED_VALUES.has(value) : false;\n}\n\nfunction hasCustomCommand() {\n\treturn Boolean(process.env.PI_CAFFEINATE_COMMAND?.trim());\n}\n\nfunction withDeprecatedIcon(text: string) {\n\tconst icon = process.env.PI_CAFFEINATE_ICON?.trim();\n\treturn icon ? `${icon} ${text}` : text;\n}\n\nfunction warnDeprecatedIcon(ctx: ExtensionContext) {\n\tif (state.iconWarningShown || !process.env.PI_CAFFEINATE_ICON?.trim()) return;\n\tstate.iconWarningShown = true;\n\tctx.ui.notify(\n\t\t\"PI_CAFFEINATE_ICON is deprecated but still works for now. If you use @narumitw/pi-statusline, move it to pi-statusline.json (extensionStatusIcons.caffeinate).\",\n\t\t\"warning\",\n\t);\n}\n\nexport {\n\tformatMode,\n\tgetInhibitorCommand,\n\tsplitCommand,\n\twindowsInhibitorScript,\n} from \"./inhibitors.js\";\nexport { normalizeCaffeinateSettings } from \"./settings.js\";\n", "import type { Message, MessageBus } from \"dbus-native\";\n\nexport const SCREENSAVER_BUS_NAME = \"org.freedesktop.ScreenSaver\";\nexport const SCREENSAVER_INTERFACE = \"org.freedesktop.ScreenSaver\";\nexport const INHIBIT_REASON = \"Pi agent is running\";\n\nconst INHIBIT_APPLICATION_NAME = \"pi-caffeinate\";\nconst SCREENSAVER_OBJECT_PATHS = [\"/org/freedesktop/ScreenSaver\", \"/ScreenSaver\"];\nconst DBUS_CALL_TIMEOUT_MS = 2_000;\n\ntype DbusFailureHandler = (error: Error) => void;\n\nexport interface DbusScreenSaverClient {\n\tsetFailureHandler(handler: DbusFailureHandler | undefined): void;\n\tinhibit(reason: string, signal?: AbortSignal): Promise<void>;\n\tuninhibit(): Promise<void>;\n\tclose(): Promise<void>;\n}\n\nexport type DbusScreenSaverFactory = () => Promise<DbusScreenSaverClient>;\n\nexport async function defaultDbusScreenSaverFactory(): Promise<DbusScreenSaverClient> {\n\tconst { sessionBus } = await import(\"dbus-native\");\n\treturn new NativeScreenSaverClient(sessionBus());\n}\n\nclass NativeScreenSaverClient implements DbusScreenSaverClient {\n\tprivate cookie?: number;\n\tprivate objectPath?: string;\n\tprivate failureHandler?: DbusFailureHandler;\n\tprivate pendingFailure?: Error;\n\tprivate lastConnectionError?: Error;\n\tprivate closing = false;\n\n\tprivate readonly handleConnectionError = (error: unknown) => {\n\t\tthis.lastConnectionError = toError(error, \"D-Bus session connection failed\");\n\t\tif (this.cookie !== undefined) this.reportFailure(this.lastConnectionError);\n\t};\n\n\tprivate readonly handleConnectionClose = (error?: unknown) => {\n\t\tif (this.closing || this.cookie === undefined) return;\n\t\tthis.reportFailure(\n\t\t\ttoError(error, this.lastConnectionError?.message ?? \"D-Bus session connection closed\"),\n\t\t);\n\t};\n\n\tconstructor(private readonly bus: MessageBus) {\n\t\tthis.bus.connection.on(\"error\", this.handleConnectionError);\n\t\tthis.bus.connection.on(\"close\", this.handleConnectionClose);\n\t}\n\n\tsetFailureHandler(handler: DbusFailureHandler | undefined): void {\n\t\tthis.failureHandler = handler;\n\t\tif (!handler || !this.pendingFailure) return;\n\t\tconst failure = this.pendingFailure;\n\t\tthis.pendingFailure = undefined;\n\t\thandler(failure);\n\t}\n\n\tasync inhibit(reason: string, signal?: AbortSignal): Promise<void> {\n\t\tlet lastError: unknown;\n\t\tfor (const objectPath of SCREENSAVER_OBJECT_PATHS) {\n\t\t\tif (signal?.aborted) throw abortReason(signal);\n\t\t\ttry {\n\t\t\t\tthis.cookie = await invoke<number>(\n\t\t\t\t\tthis.bus,\n\t\t\t\t\t{\n\t\t\t\t\t\tdestination: SCREENSAVER_BUS_NAME,\n\t\t\t\t\t\tpath: objectPath,\n\t\t\t\t\t\tinterface: SCREENSAVER_INTERFACE,\n\t\t\t\t\t\tmember: \"Inhibit\",\n\t\t\t\t\t\tsignature: \"ss\",\n\t\t\t\t\t\tbody: [INHIBIT_APPLICATION_NAME, reason],\n\t\t\t\t\t},\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t\tthis.objectPath = objectPath;\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tif (signal?.aborted) throw abortReason(signal);\n\t\t\t\tlastError = error;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`D-Bus idle inhibit failed: ${formatError(lastError)}`, {\n\t\t\tcause: lastError,\n\t\t});\n\t}\n\n\tasync uninhibit(): Promise<void> {\n\t\tif (this.cookie === undefined || !this.objectPath) return;\n\t\tconst cookie = this.cookie;\n\t\tthis.cookie = undefined;\n\t\tconst objectPath = this.objectPath;\n\t\tthis.objectPath = undefined;\n\t\tawait invoke<void>(this.bus, {\n\t\t\tdestination: SCREENSAVER_BUS_NAME,\n\t\t\tpath: objectPath,\n\t\t\tinterface: SCREENSAVER_INTERFACE,\n\t\t\tmember: \"UnInhibit\",\n\t\t\tsignature: \"u\",\n\t\t\tbody: [cookie],\n\t\t});\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.closing = true;\n\t\tthis.cookie = undefined;\n\t\tthis.objectPath = undefined;\n\t\tthis.failureHandler = undefined;\n\t\ttry {\n\t\t\tawait this.bus.close();\n\t\t} finally {\n\t\t\tthis.bus.connection.off(\"error\", this.handleConnectionError);\n\t\t\tthis.bus.connection.off(\"close\", this.handleConnectionClose);\n\t\t}\n\t}\n\n\tprivate reportFailure(error: Error): void {\n\t\tif (this.cookie === undefined) return;\n\t\tthis.cookie = undefined;\n\t\tthis.objectPath = undefined;\n\t\tif (this.failureHandler) this.failureHandler(error);\n\t\telse this.pendingFailure = error;\n\t}\n}\n\nfunction invoke<TResult>(\n\tbus: MessageBus,\n\tmessage: Message,\n\tsignal?: AbortSignal,\n): Promise<TResult> {\n\treturn new Promise<TResult>((resolve, reject) => {\n\t\tbus.invoke(message, { signal, timeout: DBUS_CALL_TIMEOUT_MS }, (error, ...values) => {\n\t\t\tif (error) reject(error);\n\t\t\telse resolve(values[0] as TResult);\n\t\t});\n\t});\n}\n\nfunction abortReason(signal: AbortSignal): unknown {\n\treturn signal.reason ?? new DOMException(\"D-Bus idle inhibit cancelled\", \"AbortError\");\n}\n\nfunction toError(error: unknown, fallback: string): Error {\n\treturn error instanceof Error ? error : new Error(fallback);\n}\n\nfunction formatError(error: unknown) {\n\tif (error instanceof Error) {\n\t\treturn error.name === \"Error\" ? error.message : `${error.name}: ${error.message}`;\n\t}\n\treturn String(error);\n}\n", "import { type ChildProcess, spawn } from \"node:child_process\";\nimport process from \"node:process\";\nimport type { InhibitorCommand } from \"./inhibitors.js\";\n\nexport function startInhibitorProcess(\n\tcommand: InhibitorCommand,\n\tonError: (error: Error) => void,\n\tonUnexpectedExit: (description: string) => void,\n): ChildProcess {\n\tconst child = spawn(command.command, command.args, {\n\t\tdetached: false,\n\t\tstdio: [command.releaseOnStdinClose ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t});\n\tchild.once(\"error\", onError);\n\tchild.once(\"exit\", (code, signal) => onUnexpectedExit(formatExit(code, signal)));\n\treturn child;\n}\n\nexport function stopInhibitorProcess(child: ChildProcess, command: InhibitorCommand | undefined) {\n\tchild.removeAllListeners(\"exit\");\n\tchild.removeAllListeners(\"error\");\n\tif (child.killed) return;\n\n\tif (command?.releaseOnStdinClose && child.stdin && !child.stdin.destroyed) {\n\t\tchild.stdin.end();\n\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\tconst killTimer = setTimeout(() => {\n\t\t\t\tif (child.exitCode === null && child.signalCode === null && !child.killed) child.kill();\n\t\t\t}, 2000);\n\t\t\tkillTimer.unref();\n\t\t\tchild.once(\"exit\", () => clearTimeout(killTimer));\n\t\t}\n\t} else if (process.platform === \"win32\") {\n\t\tchild.kill();\n\t} else {\n\t\tchild.kill(\"SIGTERM\");\n\t}\n}\n\nfunction formatExit(code: number | null, signal: NodeJS.Signals | null) {\n\tif (signal) return `signal ${signal}`;\n\treturn `code ${code ?? \"unknown\"}`;\n}\n", "import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport type { CaffeinateMode } from \"./settings.js\";\n\nexport interface InhibitorCommand {\n\tcommand: string;\n\targs: string[];\n\tdescription: string;\n\treleaseOnStdinClose?: boolean;\n\tcustom?: boolean;\n\t/** Display mode also needs D-Bus because logind idle inhibition misses some compositors. */\n\taddDbusIdleInhibit?: boolean;\n}\n\nexport function getInhibitorCommand(mode: CaffeinateMode): InhibitorCommand | undefined {\n\tconst customCommand = process.env.PI_CAFFEINATE_COMMAND?.trim();\n\tif (customCommand) {\n\t\tconst [command, ...args] = splitCommand(customCommand);\n\t\tif (command) return { command, args, description: `custom command (${command})`, custom: true };\n\t}\n\tif (process.platform === \"darwin\") {\n\t\treturn parentBoundUnixCommand(\n\t\t\t\"caffeinate\",\n\t\t\tmacCaffeinateArgs(mode),\n\t\t\tcaffeinateDescription(mode),\n\t\t);\n\t}\n\tif (process.platform === \"linux\") {\n\t\tif (isWsl() && commandExists(\"powershell.exe\")) {\n\t\t\treturn windowsPowerInhibitorCommand(\"powershell.exe\", mode);\n\t\t}\n\t\tif (commandExists(\"systemd-inhibit\")) {\n\t\t\tconst what = mode === \"display\" ? \"idle:sleep\" : \"sleep\";\n\t\t\treturn parentBoundUnixCommand(\n\t\t\t\t\"systemd-inhibit\",\n\t\t\t\t[\n\t\t\t\t\t`--what=${what}`,\n\t\t\t\t\t\"--who=pi-caffeinate\",\n\t\t\t\t\t\"--why=Pi agent is running\",\n\t\t\t\t\t\"--mode=block\",\n\t\t\t\t\t\"sleep\",\n\t\t\t\t\t\"infinity\",\n\t\t\t\t],\n\t\t\t\t`systemd-inhibit (${formatMode(mode)})`,\n\t\t\t\tmode === \"display\",\n\t\t\t);\n\t\t}\n\t\tif (commandExists(\"caffeinate\")) {\n\t\t\treturn parentBoundUnixCommand(\n\t\t\t\t\"caffeinate\",\n\t\t\t\tmacCaffeinateArgs(mode),\n\t\t\t\tcaffeinateDescription(mode),\n\t\t\t\tmode === \"display\",\n\t\t\t);\n\t\t}\n\t}\n\tif (process.platform === \"win32\") return windowsPowerInhibitorCommand(\"powershell.exe\", mode);\n\treturn undefined;\n}\n\nfunction macCaffeinateArgs(mode: CaffeinateMode) {\n\treturn mode === \"sleep\" ? [\"-ims\"] : [\"-dimsu\"];\n}\n\nfunction caffeinateDescription(mode: CaffeinateMode) {\n\treturn `caffeinate (${formatMode(mode)})`;\n}\n\nfunction parentBoundUnixCommand(\n\tcommand: string,\n\targs: string[],\n\tdescription: string,\n\taddDbusIdleInhibit = false,\n): InhibitorCommand {\n\treturn {\n\t\tcommand: \"sh\",\n\t\targs: [\n\t\t\t\"-c\",\n\t\t\tunixParentBoundScript(),\n\t\t\t\"pi-caffeinate-watch\",\n\t\t\tString(process.pid),\n\t\t\tcommand,\n\t\t\t...args,\n\t\t],\n\t\tdescription,\n\t\t...(addDbusIdleInhibit ? { addDbusIdleInhibit: true } : {}),\n\t};\n}\n\nfunction unixParentBoundScript() {\n\treturn `parent=$1; shift; \"$@\" & child=$!; ( while kill -0 \"$parent\" 2>/dev/null; do sleep 5; done; kill \"$child\" 2>/dev/null ) & watcher=$!; cleanup() { kill \"$watcher\" 2>/dev/null; kill \"$child\" 2>/dev/null; wait \"$child\" 2>/dev/null; }; trap 'cleanup; exit 0' INT TERM HUP EXIT; wait \"$child\"; status=$?; kill \"$watcher\" 2>/dev/null; trap - EXIT; exit \"$status\"`;\n}\n\nfunction commandExists(command: string) {\n\tconst searchPath = process.env.PATH ?? \"\";\n\tconst extensions = process.platform === \"win32\" ? [\"\", \".exe\", \".cmd\", \".bat\"] : [\"\"];\n\tfor (const directory of searchPath.split(process.platform === \"win32\" ? \";\" : \":\")) {\n\t\tif (!directory) continue;\n\t\tfor (const extension of extensions) {\n\t\t\tif (existsSync(path.join(directory, `${command}${extension}`))) return true;\n\t\t}\n\t}\n\treturn false;\n}\n\nexport function splitCommand(input: string) {\n\tconst parts: string[] = [];\n\tlet current = \"\";\n\tlet quote: '\"' | \"'\" | undefined;\n\tlet escaping = false;\n\tfor (const char of input) {\n\t\tif (escaping) {\n\t\t\tcurrent += char;\n\t\t\tescaping = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === \"\\\\\") {\n\t\t\tescaping = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif ((char === '\"' || char === \"'\") && !quote) {\n\t\t\tquote = char;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === quote) {\n\t\t\tquote = undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (/\\s/.test(char) && !quote) {\n\t\t\tif (current) {\n\t\t\t\tparts.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tcurrent += char;\n\t}\n\tif (current) parts.push(current);\n\treturn parts;\n}\n\nfunction windowsPowerInhibitorCommand(command: string, mode: CaffeinateMode): InhibitorCommand {\n\treturn {\n\t\tcommand,\n\t\targs: [\"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\", windowsInhibitorScript(mode)],\n\t\tdescription: `PowerShell SetThreadExecutionState (${formatMode(mode)})`,\n\t\treleaseOnStdinClose: true,\n\t};\n}\n\nexport function windowsInhibitorScript(mode: CaffeinateMode) {\n\tconst flags = mode === \"sleep\" ? \"0x80000001\" : \"0x80000003\";\n\treturn `$ErrorActionPreference = 'Stop'; Add-Type -Namespace Native -Name Power -MemberDefinition '[DllImport(\"kernel32.dll\")] public static extern uint SetThreadExecutionState(uint esFlags);'; $flags = [uint32]'${flags}'; $release = [uint32]'0x80000000'; $stdin = [Console]::OpenStandardInput(); $buffer = New-Object byte[] 1; $readTask = $stdin.ReadAsync($buffer, 0, 1); try { while ($true) { [Native.Power]::SetThreadExecutionState($flags) | Out-Null; if ($readTask.Wait(30000)) { break } } } finally { [Native.Power]::SetThreadExecutionState($release) | Out-Null }`;\n}\n\nfunction isWsl() {\n\ttry {\n\t\treturn existsSync(\"/proc/sys/fs/binfmt_misc/WSLInterop\");\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function formatMode(mode: CaffeinateMode) {\n\treturn mode === \"sleep\" ? \"system-awake\" : \"display-awake\";\n}\n", "import { randomUUID } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { access, lstat, mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport process from \"node:process\";\nimport { getAgentDir } from \"@earendil-works/pi-coding-agent\";\n\nconst NEW_SETTINGS_FILE = \"pi-caffeinate.json\";\nconst LEGACY_SETTINGS_FILE = \"pi-caffeinate-settings.json\";\n\nexport type CaffeinateMode = \"sleep\" | \"display\";\n\nexport interface CaffeinateSettings {\n\tmode: CaffeinateMode;\n\tquiet: boolean;\n\tupdatedAt: number;\n}\n\nexport interface SettingsFileOperations {\n\twrite(path: string, data: string): Promise<void>;\n\trename(source: string, destination: string): Promise<void>;\n}\n\nconst DEFAULT_FILE_OPERATIONS: SettingsFileOperations = {\n\twrite: (path, data) => writeFile(path, data, \"utf8\").then(() => undefined),\n\trename,\n};\n\nexport type SettingsLoadResult =\n\t| { kind: \"missing\"; notice?: string }\n\t| { kind: \"invalid\"; reason: string; notice?: string }\n\t| { kind: \"loaded\"; settings: CaffeinateSettings; notice?: string };\n\nexport async function loadSettings(): Promise<SettingsLoadResult> {\n\tawait settingsSaveQueue;\n\tconst newPath = settingsFilePath();\n\tconst newSettings = await readSettingsFile(newPath);\n\tif (newSettings.kind !== \"missing\") return withLegacyIgnoredNotice(newSettings);\n\n\tconst legacyPath = legacySettingsFilePath();\n\tconst legacySettings = await readSettingsFile(legacyPath);\n\tconst concurrentlyCreatedSettings = await readSettingsFile(newPath);\n\tif (concurrentlyCreatedSettings.kind !== \"missing\") {\n\t\treturn withLegacyIgnoredNotice(concurrentlyCreatedSettings);\n\t}\n\tif (legacySettings.kind === \"missing\") return { kind: \"missing\" };\n\tif (legacySettings.kind === \"invalid\") return legacySettings;\n\n\treturn {\n\t\t...legacySettings,\n\t\tnotice: `Using legacy ${LEGACY_SETTINGS_FILE}; rename it to ${NEW_SETTINGS_FILE}. Future saves write ${NEW_SETTINGS_FILE} without modifying the legacy file.`,\n\t};\n}\n\ninterface SettingsDocumentResult {\n\tresult: SettingsLoadResult;\n\tdocument?: Record<string, unknown>;\n}\n\nasync function readSettingsDocument(filePath: string): Promise<SettingsDocumentResult> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(filePath, \"utf8\");\n\t} catch (error) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return { result: { kind: \"missing\" } };\n\t\treturn { result: { kind: \"invalid\", reason: `${filePath}: ${formatError(error)}` } };\n\t}\n\ttry {\n\t\tconst document = JSON.parse(text) as unknown;\n\t\tconst settings = normalizeCaffeinateSettings(document);\n\t\tif (settings) {\n\t\t\treturn {\n\t\t\t\tresult: { kind: \"loaded\", settings },\n\t\t\t\tdocument: { ...(document as Record<string, unknown>) },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tresult: {\n\t\t\t\tkind: \"invalid\",\n\t\t\t\treason: `${filePath}: expected { \"mode\": \"sleep\" | \"display\", optional \"quiet\": boolean }`,\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\treturn { result: { kind: \"invalid\", reason: `${filePath}: ${formatError(error)}` } };\n\t}\n}\n\nasync function readSettingsFile(filePath: string): Promise<SettingsLoadResult> {\n\treturn (await readSettingsDocument(filePath)).result;\n}\n\nasync function withLegacyIgnoredNotice(settings: SettingsLoadResult): Promise<SettingsLoadResult> {\n\tif (!(await fileExists(legacySettingsFilePath()))) return settings;\n\treturn {\n\t\t...settings,\n\t\tnotice: `pi-caffeinate legacy settings ignored: ${legacySettingsFilePath()} exists, but ${settingsFilePath()} takes precedence. Delete ${LEGACY_SETTINGS_FILE} after confirming your settings.`,\n\t};\n}\n\nasync function fileExists(filePath: string) {\n\ttry {\n\t\tawait access(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function pathEntryExists(filePath: string) {\n\ttry {\n\t\tawait lstat(filePath);\n\t\treturn true;\n\t} catch (error) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return false;\n\t\tthrow error;\n\t}\n}\n\nexport function normalizeCaffeinateSettings(value: unknown): CaffeinateSettings | undefined {\n\tif (!value || typeof value !== \"object\") return undefined;\n\tconst settings = value as { mode?: unknown; quiet?: unknown; updatedAt?: unknown };\n\tif (!isCaffeinateMode(settings.mode)) return undefined;\n\tif (settings.quiet !== undefined && typeof settings.quiet !== \"boolean\") return undefined;\n\tif (settings.updatedAt !== undefined && typeof settings.updatedAt !== \"number\") return undefined;\n\treturn {\n\t\tmode: settings.mode,\n\t\tquiet: settings.quiet ?? false,\n\t\tupdatedAt: settings.updatedAt ?? 0,\n\t};\n}\n\nfunction isCaffeinateMode(value: unknown): value is CaffeinateMode {\n\treturn value === \"sleep\" || value === \"display\";\n}\n\nlet settingsSaveQueue: Promise<unknown> = Promise.resolve();\n\nexport function saveSettings(\n\tsettings: Omit<CaffeinateSettings, \"quiet\"> & { quiet?: boolean },\n\toperations: Partial<SettingsFileOperations> = {},\n): Promise<CaffeinateSettings> {\n\tconst operation = settingsSaveQueue.then(() => saveSettingsNow(settings, operations));\n\tsettingsSaveQueue = operation.catch(() => undefined);\n\treturn operation;\n}\n\nasync function saveSettingsNow(\n\tsettings: Omit<CaffeinateSettings, \"quiet\"> & { quiet?: boolean },\n\toperations: Partial<SettingsFileOperations>,\n): Promise<CaffeinateSettings> {\n\tconst filePath = settingsFilePath();\n\tlet current = await readSettingsDocument(filePath);\n\tconst replaceCanonical = current.result.kind !== \"missing\";\n\tif (!replaceCanonical) current = await readSettingsDocument(legacySettingsFilePath());\n\tif (current.result.kind === \"invalid\") {\n\t\tthrow new Error(`Cannot save pi-caffeinate settings until you repair ${current.result.reason}`);\n\t}\n\tconst document = current.document ?? {};\n\tconst quiet =\n\t\tsettings.quiet ?? (current.result.kind === \"loaded\" ? current.result.settings.quiet : false);\n\tconst nextSettings = { mode: settings.mode, quiet, updatedAt: settings.updatedAt };\n\tconst nextDocument = {\n\t\t...document,\n\t\t...nextSettings,\n\t};\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tconst tempFile = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n\ttry {\n\t\tawait (operations.write ?? DEFAULT_FILE_OPERATIONS.write)(\n\t\t\ttempFile,\n\t\t\t`${JSON.stringify(nextDocument, null, 2)}\\n`,\n\t\t);\n\t\tif (!replaceCanonical && (await pathEntryExists(filePath))) {\n\t\t\tthrow new Error(`${NEW_SETTINGS_FILE} was created concurrently; reopen settings and retry.`);\n\t\t}\n\t\tawait (operations.rename ?? DEFAULT_FILE_OPERATIONS.rename)(tempFile, filePath);\n\t\treturn nextSettings;\n\t} catch (error) {\n\t\tawait rm(tempFile, { force: true }).catch(() => undefined);\n\t\tthrow error;\n\t}\n}\n\nexport function settingsFilePath() {\n\treturn join(agentDir(), NEW_SETTINGS_FILE);\n}\n\nfunction legacySettingsFilePath() {\n\treturn join(agentDir(), LEGACY_SETTINGS_FILE);\n}\n\nfunction agentDir() {\n\treturn getAgentDir();\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n\nfunction formatError(error: unknown) {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
+
"mappings": ";;;;AACA,OAAOA,cAAa;;;ACCb,IAAM,uBAAuB;AAC7B,IAAM,wBAAwB;AAC9B,IAAM,iBAAiB;AAE9B,IAAM,2BAA2B;AACjC,IAAM,2BAA2B,CAAC,gCAAgC,cAAc;AAChF,IAAM,uBAAuB;AAa7B,eAAsB,gCAAgE;AACrF,QAAM,EAAE,WAAW,IAAI,MAAM,OAAO,aAAa;AACjD,SAAO,IAAI,wBAAwB,WAAW,CAAC;AAChD;AAEA,IAAM,0BAAN,MAA+D;AAAA,EAoB9D,YAA6B,KAAiB;AAAjB;AAC5B,SAAK,IAAI,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ACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["process", "process", "process", "path", "formatError", "formatError", "process"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-caffeinate",
|
|
3
|
-
"version": "0.49.
|
|
3
|
+
"version": "0.49.7",
|
|
4
4
|
"description": "Pi extension that keeps the computer awake while the agent is running.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,9 +24,6 @@
|
|
|
24
24
|
"./dist/index.ts"
|
|
25
25
|
]
|
|
26
26
|
},
|
|
27
|
-
"piExtension": {
|
|
28
|
-
"lifecycle": "stable"
|
|
29
|
-
},
|
|
30
27
|
"scripts": {
|
|
31
28
|
"build": "node scripts/build-runtime.mjs",
|
|
32
29
|
"check": "npm run build && biome check . && npm run typecheck",
|
|
@@ -38,9 +35,9 @@
|
|
|
38
35
|
"@earendil-works/pi-coding-agent": "*"
|
|
39
36
|
},
|
|
40
37
|
"devDependencies": {
|
|
41
|
-
"@biomejs/biome": "2.5.
|
|
42
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
43
|
-
"@types/node": "26.
|
|
38
|
+
"@biomejs/biome": "2.5.11",
|
|
39
|
+
"@earendil-works/pi-coding-agent": "0.84.4",
|
|
40
|
+
"@types/node": "26.4.0",
|
|
44
41
|
"esbuild": "0.28.2",
|
|
45
42
|
"typescript": "7.0.2"
|
|
46
43
|
},
|
|
@@ -50,7 +47,7 @@
|
|
|
50
47
|
"directory": "packages/pi-caffeinate"
|
|
51
48
|
},
|
|
52
49
|
"dependencies": {
|
|
53
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
50
|
+
"@narumitw/pi-tui-kit": "^0.59.0",
|
|
54
51
|
"dbus-native": "^0.15.2"
|
|
55
52
|
}
|
|
56
53
|
}
|
package/src/dbus-inhibit.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Message, MessageBus } from "dbus-native";
|
|
2
2
|
|
|
3
3
|
export const SCREENSAVER_BUS_NAME = "org.freedesktop.ScreenSaver";
|
|
4
4
|
export const SCREENSAVER_INTERFACE = "org.freedesktop.ScreenSaver";
|
|
@@ -20,6 +20,7 @@ export interface DbusScreenSaverClient {
|
|
|
20
20
|
export type DbusScreenSaverFactory = () => Promise<DbusScreenSaverClient>;
|
|
21
21
|
|
|
22
22
|
export async function defaultDbusScreenSaverFactory(): Promise<DbusScreenSaverClient> {
|
|
23
|
+
const { sessionBus } = await import("dbus-native");
|
|
23
24
|
return new NativeScreenSaverClient(sessionBus());
|
|
24
25
|
}
|
|
25
26
|
|