pi-insomnia 0.1.2 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3 - 2026-07-17
4
+
3
5
  All notable changes to this project will be documented in this file.
4
6
 
5
7
  This project follows the spirit of [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and uses semantic versioning for releases.
6
8
 
7
9
  ## [Unreleased]
8
10
 
11
+ ### Fixed
12
+
13
+ - Keep macOS sleep inhibition active across automatic retries, compaction retries, and queued follow-up work until Pi emits `agent_settled`.
14
+
9
15
  ## [0.1.2] - 2026-07-01
10
16
 
11
17
  ### Changed
package/README.md CHANGED
@@ -8,7 +8,7 @@ A source-distributed [Pi](https://pi.dev) package that prevents macOS idle sleep
8
8
  ## Features
9
9
 
10
10
  - Automatically starts a macOS sleep assertion when a Pi agent run starts.
11
- - Automatically releases the assertion when the agent run ends.
11
+ - Automatically releases the assertion when Pi settles after all retries, compaction, and queued follow-up work.
12
12
  - Cleans up on Pi session shutdown, reloads, and quits.
13
13
  - Uses the macOS built-in `/usr/bin/caffeinate` command; no third-party runtime dependency is required.
14
14
  - Shows a small `☕ sleep inhibited` footer status while active in UI modes.
@@ -24,7 +24,7 @@ On macOS, the extension launches:
24
24
  /usr/bin/caffeinate -i -w <pi-pid>
25
25
  ```
26
26
 
27
- `-i` prevents idle system sleep while the process is running. `-w <pi-pid>` also ties the assertion to the Pi process so the helper exits if Pi exits unexpectedly. The extension still explicitly terminates the helper when the agent becomes idle.
27
+ `-i` prevents idle system sleep while the process is running. `-w <pi-pid>` also ties the assertion to the Pi process so the helper exits if Pi exits unexpectedly. The extension still explicitly terminates the helper when Pi becomes fully idle after any automatic retries, compaction retries, or queued follow-up work.
28
28
 
29
29
  ## Installation
30
30
 
@@ -34,16 +34,17 @@ function stopSpinner(ctx: ExtensionContext): void {
34
34
  setStatus(ctx, undefined);
35
35
  }
36
36
 
37
- export default function piInsomnia(pi: ExtensionAPI) {
37
+ export default function piInsomnia(
38
+ pi: ExtensionAPI,
39
+ inhibitor = new MacSleepInhibitor(),
40
+ ) {
38
41
  reportInstallTelemetry();
39
42
 
40
- const inhibitor = new MacSleepInhibitor();
41
-
42
43
  pi.on("agent_start", async (_event, ctx) => {
43
44
  if (inhibitor.acquire()) startSpinner(ctx);
44
45
  });
45
46
 
46
- pi.on("agent_end", async (_event, ctx) => {
47
+ pi.on("agent_settled", async (_event, ctx) => {
47
48
  inhibitor.release();
48
49
  if (!inhibitor.isInhibiting) stopSpinner(ctx);
49
50
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-insomnia",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Prevent macOS idle sleep while Pi agents are working.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,6 +45,7 @@
45
45
  "scripts": {
46
46
  "check": "tsc --noEmit",
47
47
  "typecheck": "tsc --noEmit",
48
+ "test": "node --import tsx --test tests/*.test.mjs",
48
49
  "pack:dry-run": "npm pack --dry-run"
49
50
  },
50
51
  "peerDependencies": {
@@ -52,7 +53,8 @@
52
53
  },
53
54
  "devDependencies": {
54
55
  "@earendil-works/pi-coding-agent": "^0.80.0",
55
- "@types/node": "^25.9.3",
56
+ "@types/node": "^26.1.0",
57
+ "tsx": "^4.23.0",
56
58
  "typescript": "^6.0.3"
57
59
  },
58
60
  "publishConfig": {
@@ -13,7 +13,7 @@ export class MacSleepInhibitor {
13
13
  private readonly pid: number;
14
14
  private readonly caffeinatePath: string;
15
15
  private child: ChildProcess | undefined;
16
- private activeRequests = 0;
16
+ private active = false;
17
17
 
18
18
  constructor(options: MacSleepInhibitorOptions = {}) {
19
19
  this.platform = options.platform ?? process.platform;
@@ -26,7 +26,7 @@ export class MacSleepInhibitor {
26
26
  }
27
27
 
28
28
  get isActive(): boolean {
29
- return this.activeRequests > 0;
29
+ return this.active;
30
30
  }
31
31
 
32
32
  get isInhibiting(): boolean {
@@ -36,7 +36,7 @@ export class MacSleepInhibitor {
36
36
  acquire(): boolean {
37
37
  if (!this.isSupported) return false;
38
38
 
39
- this.activeRequests += 1;
39
+ this.active = true;
40
40
  this.start();
41
41
  return this.isInhibiting;
42
42
  }
@@ -44,12 +44,12 @@ export class MacSleepInhibitor {
44
44
  release(): void {
45
45
  if (!this.isSupported) return;
46
46
 
47
- if (this.activeRequests > 0) this.activeRequests -= 1;
48
- if (this.activeRequests === 0) this.stop();
47
+ this.active = false;
48
+ this.stop();
49
49
  }
50
50
 
51
51
  forceStop(): void {
52
- this.activeRequests = 0;
52
+ this.active = false;
53
53
  this.stop();
54
54
  }
55
55