ollie/tools/process_output

35 lines
1014 B
Bash
Executable File

#!/usr/bin/env bash
# ollie:parallel read
# ollie:prompt
# ## process_output
#
# Read output from a detached background process (last 64KB ring buffer).
#
# **Args**: `[pid]`
#
# ```
# call_tool: calls=[{tool: "process_output", args: ["12345"]}]
# ```
# ollie:end
set -euo pipefail
if [ $# -lt 1 ]; then echo '{"schema": {"type": "array", "items": [{"name": "pid", "type": "string", "description": "Process PID", "required": true}], "examples": [["12345"]]}}'; exit 1; fi
pid="${1}"
session="${OLLIE_SESSION_ID:?OLLIE_SESSION_ID not set}"
# Use gdbus for proper parsing of string with newlines
result=$(gdbus call --session --dest org.ollie.SessionManager \
--object-path /org/ollie/SessionManager \
--method org.ollie.SessionManager.GetDetachedOutput "$session" "$pid" 2>&1)
# gdbus wraps in ('...',) - strip the outer tuple
result=$(echo "$result" | sed "s/^('//;s/',)$//")
if [ -z "$result" ]; then
echo "(no output captured yet)"
else
# Unescape gdbus string escaping
echo -e "$result"
fi