devduck 0.4.1__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of devduck might be problematic. Click here for more details.

devduck/tools/tray.py ADDED
@@ -0,0 +1,246 @@
1
+ """
2
+ Tray app control tool - integrated with devduck
3
+ """
4
+
5
+ from strands import tool
6
+ from typing import Dict, Any, List
7
+ import subprocess
8
+ import socket
9
+ import json
10
+ import tempfile
11
+ import os
12
+ import time
13
+ import signal
14
+ from pathlib import Path
15
+
16
+ # Global state
17
+ _tray_process = None
18
+
19
+
20
+ def _send_ipc_command(socket_path: str, command: Dict) -> Dict:
21
+ """Send IPC command to tray app"""
22
+ try:
23
+ client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
24
+ client.settimeout(10.0)
25
+ client.connect(socket_path)
26
+
27
+ # Send command
28
+ message = json.dumps(command).encode("utf-8")
29
+ client.sendall(message)
30
+
31
+ # Receive response
32
+ response_data = b""
33
+ while True:
34
+ chunk = client.recv(4096)
35
+ if not chunk:
36
+ break
37
+ response_data += chunk
38
+ # Check if we have complete JSON
39
+ try:
40
+ json.loads(response_data.decode("utf-8"))
41
+ break
42
+ except:
43
+ continue
44
+
45
+ client.close()
46
+
47
+ if not response_data:
48
+ return {"status": "error", "message": "Empty response"}
49
+
50
+ return json.loads(response_data.decode("utf-8"))
51
+ except socket.timeout:
52
+ return {"status": "error", "message": "Timeout"}
53
+ except Exception as e:
54
+ return {"status": "error", "message": str(e)}
55
+
56
+
57
+ @tool
58
+ def tray(
59
+ action: str,
60
+ items: List[Dict[str, Any]] = None,
61
+ title: str = None,
62
+ message: Dict[str, Any] = None,
63
+ text: str = None,
64
+ ) -> Dict[str, Any]:
65
+ """Control system tray app with devduck integration.
66
+
67
+ Returns:
68
+ Dict with status and content
69
+ """
70
+ global _tray_process
71
+
72
+ socket_path = os.path.join(tempfile.gettempdir(), "devduck_tray.sock")
73
+
74
+ if action == "start":
75
+ if _tray_process and _tray_process.poll() is None:
76
+ return {"status": "success", "content": [{"text": "✓ Already running"}]}
77
+
78
+ # Get tray script path
79
+ tools_dir = Path(__file__).parent
80
+ tray_script = tools_dir / "_tray_app.py"
81
+
82
+ if not tray_script.exists():
83
+ return {
84
+ "status": "error",
85
+ "content": [{"text": f"❌ Tray app not found: {tray_script}"}],
86
+ }
87
+
88
+ _tray_process = subprocess.Popen(
89
+ ["python3", str(tray_script)],
90
+ stdout=subprocess.DEVNULL,
91
+ stderr=subprocess.DEVNULL,
92
+ )
93
+
94
+ time.sleep(1.5)
95
+
96
+ return {
97
+ "status": "success",
98
+ "content": [{"text": f"✓ Tray app started (PID: {_tray_process.pid})"}],
99
+ }
100
+
101
+ elif action == "stop":
102
+ if _tray_process:
103
+ try:
104
+ os.kill(_tray_process.pid, signal.SIGTERM)
105
+ _tray_process.wait(timeout=3)
106
+ except:
107
+ pass
108
+ _tray_process = None
109
+
110
+ return {"status": "success", "content": [{"text": "✓ Stopped"}]}
111
+
112
+ elif action == "status":
113
+ is_running = _tray_process and _tray_process.poll() is None
114
+ return {"status": "success", "content": [{"text": f"Running: {is_running}"}]}
115
+
116
+ elif action == "update_menu":
117
+ if not items:
118
+ return {
119
+ "status": "error",
120
+ "content": [{"text": "items parameter required"}],
121
+ }
122
+
123
+ result = _send_ipc_command(
124
+ socket_path, {"action": "update_menu", "items": items}
125
+ )
126
+
127
+ if result.get("status") == "success":
128
+ return {
129
+ "status": "success",
130
+ "content": [{"text": f"✓ Menu updated ({len(items)} items)"}],
131
+ }
132
+ else:
133
+ return {
134
+ "status": "error",
135
+ "content": [
136
+ {"text": f"Failed: {result.get('message', 'Unknown error')}"}
137
+ ],
138
+ }
139
+
140
+ elif action == "update_title":
141
+ if not title:
142
+ return {
143
+ "status": "error",
144
+ "content": [{"text": "title parameter required"}],
145
+ }
146
+
147
+ result = _send_ipc_command(
148
+ socket_path, {"action": "update_title", "title": title}
149
+ )
150
+
151
+ if result.get("status") == "success":
152
+ return {"status": "success", "content": [{"text": f"✓ Title: {title}"}]}
153
+ else:
154
+ return {
155
+ "status": "error",
156
+ "content": [{"text": f"Failed: {result.get('message')}"}],
157
+ }
158
+
159
+ elif action == "set_progress":
160
+ """Set progress indicator: idle, thinking, processing, complete, error"""
161
+ if not text:
162
+ return {
163
+ "status": "error",
164
+ "content": [
165
+ {
166
+ "text": "text parameter required (idle/thinking/processing/complete/error)"
167
+ }
168
+ ],
169
+ }
170
+
171
+ result = _send_ipc_command(
172
+ socket_path, {"action": "set_progress", "progress": text}
173
+ )
174
+
175
+ if result.get("status") == "success":
176
+ return {"status": "success", "content": [{"text": f"✓ Progress: {text}"}]}
177
+ else:
178
+ return {
179
+ "status": "error",
180
+ "content": [{"text": f"Failed: {result.get('message')}"}],
181
+ }
182
+
183
+ elif action == "notify":
184
+ if not message:
185
+ return {
186
+ "status": "error",
187
+ "content": [{"text": "message parameter required"}],
188
+ }
189
+
190
+ result = _send_ipc_command(
191
+ socket_path, {"action": "notify", "message": message}
192
+ )
193
+
194
+ if result.get("status") == "success":
195
+ return {"status": "success", "content": [{"text": "✓ Notification sent"}]}
196
+ else:
197
+ return {
198
+ "status": "error",
199
+ "content": [{"text": f"Failed: {result.get('message')}"}],
200
+ }
201
+
202
+ elif action == "show_input":
203
+ result = _send_ipc_command(socket_path, {"action": "show_input"})
204
+
205
+ if result.get("status") == "success":
206
+ return {"status": "success", "content": [{"text": "✓ Input shown"}]}
207
+ else:
208
+ return {
209
+ "status": "error",
210
+ "content": [{"text": f"Failed: {result.get('message')}"}],
211
+ }
212
+
213
+ elif action == "stream_text":
214
+ if not text:
215
+ return {"status": "error", "content": [{"text": "text parameter required"}]}
216
+
217
+ result = _send_ipc_command(socket_path, {"action": "stream_text", "text": text})
218
+
219
+ if result.get("status") == "success":
220
+ return {"status": "success", "content": [{"text": "✓ Text streamed"}]}
221
+ else:
222
+ return {
223
+ "status": "error",
224
+ "content": [{"text": f"Failed: {result.get('message')}"}],
225
+ }
226
+
227
+ elif action in ["toggle_tcp", "toggle_ws", "toggle_mcp"]:
228
+ result = _send_ipc_command(socket_path, {"action": action})
229
+
230
+ if result.get("status") == "success":
231
+ return {"status": "success", "content": [{"text": f"✓ {action} executed"}]}
232
+ else:
233
+ return {
234
+ "status": "error",
235
+ "content": [{"text": f"Failed: {result.get('message')}"}],
236
+ }
237
+
238
+ else:
239
+ return {
240
+ "status": "error",
241
+ "content": [
242
+ {
243
+ "text": f"Unknown action: {action}. Available: start, stop, status, update_menu, update_title, set_progress, notify, show_input, stream_text, toggle_tcp, toggle_ws, toggle_mcp"
244
+ }
245
+ ],
246
+ }