The launchd service runs with PATH=/usr/bin:/bin:/usr/sbin:/sbin; tmux split-window gives the new pane the caller's PATH, so 'exec lf' failed and the pane closed at once. install.sh now records its own PATH in the plist EnvironmentVariables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
||
"""Пишет описание службы launchd для сервера панели: запуск при входе, перезапуск при падении.
|
||
|
||
launchagent.py write <plist> <python> <claude_agents.py> <log> <PATH>
|
||
"""
|
||
import os
|
||
import plistlib
|
||
import sys
|
||
|
||
LABEL = "com.andrey.claude-agents" # то же, что SERVICE_LABEL в claude_agents.py
|
||
|
||
|
||
def plist(python, script, log, path):
|
||
return {
|
||
"Label": LABEL,
|
||
"ProgramArguments": [python, script, "--headless"],
|
||
# у launchd PATH без Homebrew, а панели tmux, открытые службой (lf), получают её PATH
|
||
"EnvironmentVariables": {"PATH": path},
|
||
"RunAtLoad": True,
|
||
"KeepAlive": True,
|
||
"StandardOutPath": log,
|
||
"StandardErrorPath": log,
|
||
}
|
||
|
||
|
||
def main():
|
||
if len(sys.argv) != 7 or sys.argv[1] != "write":
|
||
print(__doc__.strip(), file=sys.stderr)
|
||
sys.exit(2)
|
||
path, python, script, log = (os.path.expanduser(a) for a in sys.argv[2:6])
|
||
env_path = sys.argv[6]
|
||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||
os.makedirs(os.path.dirname(log), exist_ok=True)
|
||
tmp = path + ".tmp"
|
||
with open(tmp, "wb") as f:
|
||
plistlib.dump(plist(python, script, log, env_path), f, fmt=plistlib.FMT_XML)
|
||
os.replace(tmp, path)
|
||
print(path)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|