diff --git a/Makefile b/Makefile index 4b4a49c..01f9f41 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,13 @@ clean: rm -rf $(BUILD_DIR) rm -f $(LIB_DIR)/libollie.so $(LIB_DIR)/libollie.h +# Install Dolphin service menus +dolphin-install: + mkdir -p ~/.local/share/kio/servicemenus + cp dolphin/ollie-actions.desktop ~/.local/share/kio/servicemenus/ + sudo cp dolphin/ollie-ask /usr/local/bin/ + @echo "Dolphin menus installed. Restart Dolphin or re-open context menu." + # Install plasmoid to user's local plasma directory plasmoid-install: daemon kpackagetool6 -t Plasma/Applet -u plasmoid/ 2>/dev/null || \ diff --git a/dolphin/ollie-actions.desktop b/dolphin/ollie-actions.desktop new file mode 100644 index 0000000..6cee70c --- /dev/null +++ b/dolphin/ollie-actions.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Type=Service +MimeType=all/allfiles;inode/directory; +Actions=askOllie;sessionHere; +X-KDE-AuthorizeAction=shell_access + +[Desktop Action askOllie] +Name=Ask Ollie about this +Icon=system-run +Exec=ollie-ask %f + +[Desktop Action sessionHere] +Name=Start Ollie session here +Icon=system-run +Exec=ollie-session-here %f diff --git a/dolphin/ollie-ask b/dolphin/ollie-ask new file mode 100755 index 0000000..2bd0c82 --- /dev/null +++ b/dolphin/ollie-ask @@ -0,0 +1,76 @@ +#!/bin/sh +# ollie-ask: one-shot prompt helper for Dolphin service menus +# Usage: ollie-ask [prompt_prefix] + +TARGET="$1" +PREFIX="${2:-Describe and explain this file:}" +CWD="$(dirname "$TARGET")" +PROMPT="$PREFIX $TARGET" + +SERVICE="org.ollie.SessionManager" +OBJ="/org/ollie/SessionManager" +IFACE="org.ollie.SessionManager" + +# Create session +SESSION=$(dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.CreateSession \ + string:"$CWD" string:"" string:"" string:"default" 2>/dev/null | \ + awk -F'"' '/string "/{print $2; exit}') + +if [ -z "$SESSION" ]; then + notify-send "Ollie" "Failed to create session" + exit 1 +fi + +# Submit +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.Submit string:"$SESSION" string:"$PROMPT" > /dev/null 2>&1 + +# Wait for agent to start (state becomes non-idle) +i=0 +while [ $i -lt 20 ]; do + STATE=$(dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.GetState string:"$SESSION" 2>/dev/null | \ + awk -F'"' '/string "/{print $2; exit}') + [ "$STATE" != "idle" ] && break + sleep 0.2 + i=$((i + 1)) +done + +# Wait for agent to finish (state returns to idle, max 60s) +i=0 +while [ $i -lt 120 ]; do + STATE=$(dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.GetState string:"$SESSION" 2>/dev/null | \ + awk -F'"' '/string "/{print $2; exit}') + [ "$STATE" = "idle" ] && break + sleep 0.5 + i=$((i + 1)) +done + +# Get chat via gdbus +RESULT=$(gdbus call --session --dest $SERVICE --object-path $OBJ \ + --method $IFACE.GetChat "$SESSION" 0 2>/dev/null | \ + sed "s/^('//; s/', int64 [0-9]*)$//; s/\\\\n/\n/g") + +# Extract assistant response +ASSISTANT=$(printf '%s\n' "$RESULT" | sed -n '/^\[assistant\]$/,/^\[/{/^\[assistant\]$/d; /^\[/d; p;}') +[ -z "$ASSISTANT" ] && ASSISTANT="$RESULT" + +# Kill session +dbus-send --session --dest=$SERVICE --type=method_call \ + $OBJ $IFACE.KillSession string:"$SESSION" > /dev/null 2>&1 + +# Show result +TMPFILE=$(mktemp /tmp/ollie-ask.XXXXXX) +printf '%s' "$ASSISTANT" > "$TMPFILE" + +if command -v kdialog > /dev/null 2>&1; then + kdialog --title "Ollie — $(basename "$TARGET")" --textbox "$TMPFILE" 600 400 +elif command -v zenity > /dev/null 2>&1; then + zenity --text-info --title="Ollie — $(basename "$TARGET")" --width=600 --height=400 --filename="$TMPFILE" +else + notify-send -t 30000 "Ollie" "$ASSISTANT" +fi + +rm -f "$TMPFILE" diff --git a/dolphin/ollie-session-here b/dolphin/ollie-session-here new file mode 100755 index 0000000..3c1d423 --- /dev/null +++ b/dolphin/ollie-session-here @@ -0,0 +1,11 @@ +#!/bin/sh +# ollie-session-here: start a session in the given directory +TARGET="$1" +[ -f "$TARGET" ] && TARGET="$(dirname "$TARGET")" +[ -z "$TARGET" ] && TARGET="$HOME" + +dbus-send --session --dest=org.ollie.SessionManager --type=method_call \ + /org/ollie/SessionManager org.ollie.SessionManager.CreateSession \ + string:"$TARGET" string:"" string:"" string:"default" + +notify-send -t 3000 "Ollie" "Session started in $TARGET"