agent-office-cli 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-office-cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Run and manage AI agent sessions locally, with optional relay to agentoffice.top",
5
5
  "license": "MIT",
6
6
  "engines": {
package/src/index.js CHANGED
@@ -19,6 +19,7 @@ const {
19
19
  createPtyManager,
20
20
  defaultTransportForProvider,
21
21
  ensureNodePtySpawnHelper,
22
+ startSleepInhibitor,
22
23
  listSessionRecords,
23
24
  removeSessionRecord,
24
25
  applyClaudeHookConfig,
@@ -172,6 +173,13 @@ async function main() {
172
173
  throw new Error("tmux is required for AgentOffice local sessions. Install it first, for example with `brew install tmux`.");
173
174
  }
174
175
 
176
+ const sleepInhibitor = startSleepInhibitor({ commandExists });
177
+ if (sleepInhibitor.started) {
178
+ console.log("- sleep guard: caffeinate active");
179
+ } else if (process.platform === "darwin") {
180
+ console.log("- sleep guard: skipped (caffeinate unavailable)");
181
+ }
182
+
175
183
  const store = createSessionStore();
176
184
  const ptyManager = createPtyManager({ store });
177
185
  const restored = ptyManager.restoreManagedSessions();
@@ -18,6 +18,7 @@ const {
18
18
  removeSessionRecord
19
19
  } = require("./session-registry");
20
20
  const { ensureNodePtySpawnHelper } = require("./ensure-node-pty");
21
+ const { startSleepInhibitor } = require("./sleep-inhibitor");
21
22
  const {
22
23
  applyClaudeHookConfig,
23
24
  claudeSettingsPath,
@@ -45,6 +46,7 @@ module.exports = {
45
46
  persistSessionRecord,
46
47
  removeSessionRecord,
47
48
  ensureNodePtySpawnHelper,
49
+ startSleepInhibitor,
48
50
  applyClaudeHookConfig,
49
51
  claudeSettingsPath,
50
52
  commandExists,
@@ -0,0 +1,31 @@
1
+ const { spawn } = require("node:child_process");
2
+
3
+ function startSleepInhibitor({
4
+ pid = process.pid,
5
+ platform = process.platform,
6
+ commandExists = () => true,
7
+ spawn: spawnProcess = spawn
8
+ } = {}) {
9
+ if (platform !== "darwin") {
10
+ return { started: false, reason: "unsupported_platform" };
11
+ }
12
+
13
+ if (!commandExists("caffeinate")) {
14
+ return { started: false, reason: "missing_command" };
15
+ }
16
+
17
+ const child = spawnProcess("caffeinate", ["-dimsu", "-w", String(pid)], {
18
+ stdio: "ignore"
19
+ });
20
+ child.unref?.();
21
+
22
+ return {
23
+ started: true,
24
+ reason: "started",
25
+ child
26
+ };
27
+ }
28
+
29
+ module.exports = {
30
+ startSleepInhibitor
31
+ };
@@ -0,0 +1,63 @@
1
+ const test = require("node:test");
2
+ const assert = require("node:assert/strict");
3
+
4
+ const { startSleepInhibitor } = require("./sleep-inhibitor");
5
+
6
+ test("startSleepInhibitor starts caffeinate by default on macOS", () => {
7
+ const calls = [];
8
+ const child = {
9
+ unrefCalled: false,
10
+ unref() {
11
+ this.unrefCalled = true;
12
+ }
13
+ };
14
+
15
+ const result = startSleepInhibitor({
16
+ pid: 4321,
17
+ platform: "darwin",
18
+ commandExists: (command) => command === "caffeinate",
19
+ spawn: (command, args, options) => {
20
+ calls.push({ command, args, options });
21
+ return child;
22
+ }
23
+ });
24
+
25
+ assert.deepEqual(calls, [
26
+ {
27
+ command: "caffeinate",
28
+ args: ["-dimsu", "-w", "4321"],
29
+ options: { stdio: "ignore" }
30
+ }
31
+ ]);
32
+ assert.equal(child.unrefCalled, true);
33
+ assert.equal(result.started, true);
34
+ assert.equal(result.reason, "started");
35
+ });
36
+
37
+ test("startSleepInhibitor skips non-macOS platforms", () => {
38
+ const result = startSleepInhibitor({
39
+ pid: 4321,
40
+ platform: "linux",
41
+ commandExists: () => true,
42
+ spawn: () => {
43
+ throw new Error("spawn should not be called");
44
+ }
45
+ });
46
+
47
+ assert.equal(result.started, false);
48
+ assert.equal(result.reason, "unsupported_platform");
49
+ });
50
+
51
+ test("startSleepInhibitor skips when caffeinate is unavailable", () => {
52
+ const result = startSleepInhibitor({
53
+ pid: 4321,
54
+ platform: "darwin",
55
+ commandExists: () => false,
56
+ spawn: () => {
57
+ throw new Error("spawn should not be called");
58
+ }
59
+ });
60
+
61
+ assert.equal(result.started, false);
62
+ assert.equal(result.reason, "missing_command");
63
+ });