diff --git a/workspace/skills/self-debug/SKILL.md b/workspace/skills/self-debug/SKILL.md new file mode 100644 index 000000000..c5b979d0e --- /dev/null +++ b/workspace/skills/self-debug/SKILL.md @@ -0,0 +1,47 @@ +# self-debug + +Tools for picoclaw to inspect its own health, logs, and configuration. + +## Tools + +- `get_agent_logs`: Fetches the last 50 lines of the agent's systemd logs. + - Usage: `exec "journalctl --user-unit ${PICOCLAW_SERVICE_NAME} --no-pager -n 50"` +- `get_agent_status`: Checks the current status of the picoclaw systemd service. + - Usage: `exec "systemctl --user status ${PICOCLAW_SERVICE_NAME}"` +- `check_config`: Validates the picoclaw configuration and shows the workspace path. + - Usage: `exec "picoclaw --config "${PICOCLAW_CONFIG}" status"` + +## Installation - Linux + +The agent can be installed as a systemd service using: + +```bash +./scripts/install-service-systemd.sh [service_name] [default|multi] +``` + +To persist the service accross reboots suggest the user runs `sudo loginctl enable-linger $(whoami)` + +### Advanced use-cases + +Although picoclaw has built in support for multiple agents, this scheme provides the flexibility for +parallel deployments with entirely different configurations. + +- Fixer - a second stable instance whose role is to be available to debug/monitor/fix the first. +- Blue/Green Stable/Canary pairings. +- Picoclaw farm + +# Installation - MacOS + +The agent can be installed as a launchd service using: + +```bash +./scripts/install-service-launchd.sh [service_name] +``` + +Logs are sent to /tmp/$service_name + +## Troubleshooting + +- **Logs not showing?** Ensure the user is in the `systemd-journal` group: `sudo usermod -a -G systemd-journal $(whoami)` +- **Service inactive?** Use `systemctl --user start picoclaw`. +- **Workspace issues?** Use `picoclaw status` to verify the current workspace path. diff --git a/workspace/skills/self-debug/scripts/install-service-launchd.sh b/workspace/skills/self-debug/scripts/install-service-launchd.sh new file mode 100755 index 000000000..8dc001aaa --- /dev/null +++ b/workspace/skills/self-debug/scripts/install-service-launchd.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +create_plist_file() { + cat < + + + + Label + ${service_name} + ProgramArguments + + ${exec_path} + agent + --config + ${picoclaw_config} + + EnvironmentVariables + + PICOCLAW_HOME + ${picoclaw_home} + PICOCLAW_CONFIG + ${picoclaw_config} + PICOCLAW_SERVICE_NAME + ${service_name} + + RunAtLoad + + KeepAlive + + WorkingDirectory + ${picoclaw_home} + StandardOutPath + /tmp/${service_name}.log + StandardErrorPath + /tmp/${service_name}.err.log + + +EOF +} + +# Variable setup to match your Linux logic +service_name=${1:-picoclaw} + +# macOS specific absolute paths +exec_path=$(which picoclaw) +picoclaw_home="$HOME/.${service_name}" +picoclaw_config="${picoclaw_home}/config.json" +plist_path="$HOME/Library/LaunchAgents/${service_name}.plist" + +# Ensure directory exists +mkdir -p "${picoclaw_home}" + +# Use the heredoc function to write the file +create_plist_file > "${plist_path}" + +# Load it (macOS equivalent of systemctl enable --now) +launchctl bootstrap gui/$(id -u) "${plist_path}" + +echo "Service ${service_name} installed at ${plist_path}" \ No newline at end of file diff --git a/workspace/skills/self-debug/scripts/install-service-systemd.sh b/workspace/skills/self-debug/scripts/install-service-systemd.sh new file mode 100755 index 000000000..6aa45d04a --- /dev/null +++ b/workspace/skills/self-debug/scripts/install-service-systemd.sh @@ -0,0 +1,166 @@ +#!/bin/bash + +SERVICE_NAME=${1:-picoclaw} +TEMPLATE=${2:-default} + +# Get the directory of the script and the repository root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# 1. Detect picoclaw installation +echo "Detecting picoclaw installation..." +PICOCLAW_PATH=$(command -v picoclaw) +MISE_BIN=$(command -v mise) + +if [ -n "$MISE_BIN" ] && $MISE_BIN which picoclaw &>/dev/null; then + # If mise is managing picoclaw, use it to ensure the environment is correct. + # This works whether picoclaw is installed via a tool spec or locally. + EXEC_START="$MISE_BIN exec -- picoclaw gateway" + echo " - Detected mise-managed picoclaw, using: $EXEC_START" +elif [ -n "$PICOCLAW_PATH" ]; then + # Use the absolute path if it's not managed by mise + EXEC_START="$PICOCLAW_PATH gateway" + echo " - Using binary path: $EXEC_START" +else + echo "Error: picoclaw not found. Please install it first." + exit 1 +fi + +service_template__default() { + local service_name="$1" + local exec_start="$2" + cat < /dev/null; then + echo "Error: Template '$TEMPLATE' not found." + exit 1 +fi + +"service_template__$TEMPLATE" "$SERVICE_NAME" "$EXEC_START" > "$OUTPUT_FILE" + +# 4. Reload +echo " $ systemctl --user daemon-reload" +systemctl --user daemon-reload + +"show_usage__$TEMPLATE" "${SERVICE_NAME%@}" "$OUTPUT_FILE"