@ctrl-spc/cli 1.1.5 → 1.1.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/dist/launchd.js CHANGED
@@ -17,7 +17,20 @@ export function getPlistPath(home = homedir()) {
17
17
  export function resolveBinPath(moduleUrl = import.meta.url) {
18
18
  return fileURLToPath(new URL('../bin/ctrl-spc.js', moduleUrl));
19
19
  }
20
- export function buildPlist(nodePath, scriptPath, home = homedir()) {
20
+ export function buildDaemonPath(home = homedir(), envPath = process.env.PATH ?? '') {
21
+ const preferred = [
22
+ join(home, '.local', 'bin'),
23
+ '/opt/homebrew/bin',
24
+ '/usr/local/bin',
25
+ '/usr/bin',
26
+ '/bin',
27
+ '/usr/sbin',
28
+ '/sbin',
29
+ '/Applications/Codex.app/Contents/Resources',
30
+ ];
31
+ return [...new Set([...preferred, ...envPath.split(':').filter(Boolean)])].join(':');
32
+ }
33
+ export function buildPlist(nodePath, scriptPath, home = homedir(), daemonPath = buildDaemonPath(home)) {
21
34
  const { daemonLogPath } = getStatePaths(home);
22
35
  return `<?xml version="1.0" encoding="UTF-8"?>
23
36
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -35,6 +48,11 @@ export function buildPlist(nodePath, scriptPath, home = homedir()) {
35
48
  <true/>
36
49
  <key>KeepAlive</key>
37
50
  <true/>
51
+ <key>EnvironmentVariables</key>
52
+ <dict>
53
+ <key>PATH</key>
54
+ <string>${escapeXml(daemonPath)}</string>
55
+ </dict>
38
56
  <key>StandardErrorPath</key>
39
57
  <string>${escapeXml(daemonLogPath)}</string>
40
58
  <key>StandardOutPath</key>
@@ -42,17 +60,21 @@ export function buildPlist(nodePath, scriptPath, home = homedir()) {
42
60
  </dict>
43
61
  </plist>`;
44
62
  }
45
- export async function installDaemon() {
46
- const home = homedir();
63
+ function writeDaemonPlist(home = homedir()) {
47
64
  const launchAgentsDir = join(home, 'Library', 'LaunchAgents');
48
65
  const plistPath = getPlistPath(home);
66
+ ensureStateDir(home);
67
+ mkdirSync(launchAgentsDir, { recursive: true });
68
+ writeFileSync(plistPath, buildPlist(process.execPath, resolveBinPath(), home), 'utf8');
69
+ return plistPath;
70
+ }
71
+ export async function installDaemon() {
72
+ const home = homedir();
49
73
  const uid = process.getuid?.();
50
74
  if (uid === undefined) {
51
75
  throw new Error(INSTALL_FAILED_MESSAGE);
52
76
  }
53
- ensureStateDir(home);
54
- mkdirSync(launchAgentsDir, { recursive: true });
55
- writeFileSync(plistPath, buildPlist(process.execPath, resolveBinPath(), home), 'utf8');
77
+ const plistPath = writeDaemonPlist(home);
56
78
  const domain = `gui/${uid}`;
57
79
  try {
58
80
  try {
@@ -95,7 +117,7 @@ export async function restartDaemon(home = homedir(), exec = defaultExec) {
95
117
  const uid = process.getuid?.();
96
118
  if (uid === undefined)
97
119
  throw new Error(RESTART_FAILED_MESSAGE);
98
- const plistPath = getPlistPath(home);
120
+ const plistPath = writeDaemonPlist(home);
99
121
  try {
100
122
  exec('launchctl', kickstartArgs(uid));
101
123
  }
package/dist/spawner.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { PassThrough } from 'node:stream';
2
3
  import { assembleCommand, READINESS_REPLY } from './flagAssembler.js';
3
4
  // agent_type -> spawn mode is derived, never stored (spec decision 8).
4
5
  function isRemote(agentType) {
@@ -97,5 +98,8 @@ export function makeSpawner(deps) {
97
98
  // Real spawn handle backed by node:child_process, used by the daemon (not in unit tests).
98
99
  export function nodeSpawnAgent(cmd, args, cwd) {
99
100
  const child = spawn(cmd, args, { cwd, stdio: ['ignore', 'pipe', 'ignore'] });
100
- return { pid: child.pid ?? -1, stdout: child.stdout, kill: () => child.kill() };
101
+ const stdout = new PassThrough();
102
+ child.stdout?.pipe(stdout);
103
+ child.on('error', (err) => stdout.destroy(err));
104
+ return { pid: child.pid ?? -1, stdout, kill: () => child.kill() };
101
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl-spc/cli",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Control Space CLI - machine setup and background daemon",
5
5
  "type": "module",
6
6
  "files": [