Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions agents/skills/zmx/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: zmx
description: Manage ZMX sessions.
---

# ZMX

## Kill named sessions

```console
zmx kill <name>... --force
```

## Kill the current session and its containing shell

Run `scripts/kill-current.sh` relative to this skill directory.
47 changes: 47 additions & 0 deletions agents/skills/zmx/scripts/kill-current.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ ${1:-} == "--finish" ]]; then
session=$2
containing_shell=$3
zmx=$4

sleep 1
"$zmx" kill "$session" --force
kill -TERM "$containing_shell"
exit
fi

session=${ZMX_SESSION:-}

if [[ -z $session ]]; then
echo "Not inside a ZMX session." >&2
exit 1
fi

pid=$$
containing_shell=

while [[ $pid =~ ^[0-9]+$ ]] && ((pid > 1)); do
command_line=$(ps -p "$pid" -o command=)
parent=$(ps -p "$pid" -o ppid= | xargs)

if [[ $command_line == *"zmx attach $session"* ]]; then
containing_shell=$parent
fi

pid=$parent
done

if [[ -z $containing_shell ]]; then
echo "Could not identify the containing shell." >&2
exit 1
fi

script_dir=$(cd -- "$(dirname -- "$0")" && pwd)
script="$script_dir/$(basename -- "$0")"
zmx=$(command -v zmx)

nohup "$script" \
--finish "$session" "$containing_shell" "$zmx" \
>"/tmp/zmx-murder-$session.log" 2>&1 </dev/null &
3 changes: 3 additions & 0 deletions nix/modules/pi-agent.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ let
cfg.paths.root + "/agents/skills/agent-browser/SKILL.md";
".pi/agent/skills/issue-ticket-pr-writing/SKILL.md".source =
cfg.paths.root + "/agents/skills/issue-ticket-pr-writing/SKILL.md";
".pi/agent/skills/zmx/SKILL.md".source = cfg.paths.root + "/agents/skills/zmx/SKILL.md";
".pi/agent/skills/zmx/scripts/kill-current.sh".source =
cfg.paths.root + "/agents/skills/zmx/scripts/kill-current.sh";
};
}
];
Expand Down
Loading