devduck 0.1.1766644714__py3-none-any.whl → 0.3.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/__init__.py +700 -1027
- devduck/_version.py +2 -2
- devduck/test_redduck.py +1 -0
- devduck/tools/__init__.py +4 -44
- devduck/tools/install_tools.py +2 -103
- devduck/tools/mcp_server.py +6 -34
- devduck/tools/tcp.py +4 -6
- devduck/tools/websocket.py +1 -7
- devduck-0.3.0.dist-info/METADATA +152 -0
- devduck-0.3.0.dist-info/RECORD +18 -0
- {devduck-0.1.1766644714.dist-info → devduck-0.3.0.dist-info}/entry_points.txt +0 -1
- devduck-0.3.0.dist-info/licenses/LICENSE +21 -0
- devduck/agentcore_handler.py +0 -76
- devduck/tools/_ambient_input.py +0 -423
- devduck/tools/_tray_app.py +0 -530
- devduck/tools/agentcore_agents.py +0 -197
- devduck/tools/agentcore_config.py +0 -441
- devduck/tools/agentcore_invoke.py +0 -423
- devduck/tools/agentcore_logs.py +0 -320
- devduck/tools/ambient.py +0 -157
- devduck/tools/fetch_github_tool.py +0 -201
- devduck/tools/ipc.py +0 -546
- devduck/tools/scraper.py +0 -935
- devduck/tools/speech_to_speech.py +0 -850
- devduck/tools/state_manager.py +0 -292
- devduck/tools/system_prompt.py +0 -608
- devduck/tools/tray.py +0 -247
- devduck-0.1.1766644714.dist-info/METADATA +0 -717
- devduck-0.1.1766644714.dist-info/RECORD +0 -33
- devduck-0.1.1766644714.dist-info/licenses/LICENSE +0 -201
- {devduck-0.1.1766644714.dist-info → devduck-0.3.0.dist-info}/WHEEL +0 -0
- {devduck-0.1.1766644714.dist-info → devduck-0.3.0.dist-info}/top_level.txt +0 -0
devduck/tools/state_manager.py
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
"""DevDuck State Manager - Time-travel for agent conversations"""
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import tempfile
|
|
5
|
-
import dill
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from datetime import datetime
|
|
8
|
-
from typing import Dict, Any
|
|
9
|
-
from strands import tool
|
|
10
|
-
|
|
11
|
-
base_dir = Path(os.getenv("DEVDUCK_HOME", tempfile.gettempdir()))
|
|
12
|
-
states_dir = base_dir / ".devduck" / "states"
|
|
13
|
-
states_dir.mkdir(parents=True, exist_ok=True)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@tool
|
|
17
|
-
def state_manager(
|
|
18
|
-
action: str,
|
|
19
|
-
state_file: str = None,
|
|
20
|
-
query: str = None,
|
|
21
|
-
metadata: dict = None,
|
|
22
|
-
agent=None, # Parent agent injection
|
|
23
|
-
) -> Dict[str, Any]:
|
|
24
|
-
"""Agent state management with time-travel capabilities.
|
|
25
|
-
|
|
26
|
-
Inspired by cagataycali/research-agent state export pattern.
|
|
27
|
-
|
|
28
|
-
Actions:
|
|
29
|
-
- export: Save current agent state to pkl
|
|
30
|
-
- load: Load and display state from pkl
|
|
31
|
-
- list: List available saved states
|
|
32
|
-
- resume: Load state and continue with new query (ephemeral)
|
|
33
|
-
- modify: Update pkl file metadata
|
|
34
|
-
- delete: Remove saved state
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
action: Operation to perform
|
|
38
|
-
state_file: Path to pkl file (auto-generated for export)
|
|
39
|
-
query: New query for resume action
|
|
40
|
-
metadata: Additional metadata for export/modify
|
|
41
|
-
agent: Parent agent (auto-injected by Strands)
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
Dict with status and content
|
|
45
|
-
|
|
46
|
-
Examples:
|
|
47
|
-
# Save current state
|
|
48
|
-
state_manager(action="export", metadata={"note": "before refactor"})
|
|
49
|
-
|
|
50
|
-
# List saved states
|
|
51
|
-
state_manager(action="list")
|
|
52
|
-
|
|
53
|
-
# Resume from previous state (ephemeral, no mutation)
|
|
54
|
-
state_manager(action="resume", state_file="~/.devduck/states/devduck_20250116_032000.pkl", query="continue analysis")
|
|
55
|
-
|
|
56
|
-
# Modify state metadata
|
|
57
|
-
state_manager(action="modify", state_file="path/to/state.pkl", metadata={"tags": ["important", "refactor"]})
|
|
58
|
-
"""
|
|
59
|
-
try:
|
|
60
|
-
if action == "export":
|
|
61
|
-
# Capture current agent state
|
|
62
|
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
63
|
-
state_file = states_dir / f"devduck_{timestamp}.pkl"
|
|
64
|
-
|
|
65
|
-
# Safe state extraction (avoid complex objects)
|
|
66
|
-
state_data = {
|
|
67
|
-
"version": "1.0",
|
|
68
|
-
"timestamp": datetime.now().isoformat(),
|
|
69
|
-
"system_prompt": agent.system_prompt,
|
|
70
|
-
"tools": list(agent.tool_names),
|
|
71
|
-
"model": {
|
|
72
|
-
"model_id": getattr(agent.model, "model_id", "unknown"),
|
|
73
|
-
"temperature": getattr(agent.model, "temperature", None),
|
|
74
|
-
"provider": getattr(agent.model, "provider", "unknown"),
|
|
75
|
-
},
|
|
76
|
-
"metadata": metadata or {},
|
|
77
|
-
"environment": {
|
|
78
|
-
"cwd": str(Path.cwd()),
|
|
79
|
-
"devduck_version": "0.6.0",
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
# Try to capture conversation history if available
|
|
84
|
-
if hasattr(agent, "conversation_history"):
|
|
85
|
-
state_data["conversation_history"] = agent.conversation_history
|
|
86
|
-
elif hasattr(agent, "messages"):
|
|
87
|
-
state_data["conversation_history"] = agent.messages
|
|
88
|
-
|
|
89
|
-
# Save with dill
|
|
90
|
-
with open(state_file, "wb") as f:
|
|
91
|
-
dill.dump(state_data, f)
|
|
92
|
-
|
|
93
|
-
size = state_file.stat().st_size
|
|
94
|
-
return {
|
|
95
|
-
"status": "success",
|
|
96
|
-
"content": [
|
|
97
|
-
{
|
|
98
|
-
"text": f"✅ State exported: {state_file}\n"
|
|
99
|
-
f"📦 Size: {size} bytes\n"
|
|
100
|
-
f"🔧 Tools: {len(state_data['tools'])}\n"
|
|
101
|
-
f"📝 Metadata: {metadata or 'none'}"
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
elif action == "list":
|
|
107
|
-
# List all saved states
|
|
108
|
-
states = sorted(
|
|
109
|
-
states_dir.glob("devduck_*.pkl"),
|
|
110
|
-
key=lambda p: p.stat().st_mtime,
|
|
111
|
-
reverse=True,
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
if not states:
|
|
115
|
-
return {
|
|
116
|
-
"status": "success",
|
|
117
|
-
"content": [{"text": "No saved states found"}],
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
output = f"📚 Found {len(states)} saved states:\n\n"
|
|
121
|
-
for i, state_path in enumerate(states[:10], 1): # Show last 10
|
|
122
|
-
try:
|
|
123
|
-
with open(state_path, "rb") as f:
|
|
124
|
-
state_data = dill.load(f)
|
|
125
|
-
|
|
126
|
-
timestamp = state_data.get("timestamp", "unknown")
|
|
127
|
-
tools_count = len(state_data.get("tools", []))
|
|
128
|
-
meta = state_data.get("metadata", {})
|
|
129
|
-
|
|
130
|
-
output += f"{i}. {state_path.name}\n"
|
|
131
|
-
output += f" 📅 {timestamp}\n"
|
|
132
|
-
output += f" 🔧 {tools_count} tools\n"
|
|
133
|
-
if meta:
|
|
134
|
-
output += f" 📝 {meta}\n"
|
|
135
|
-
output += "\n"
|
|
136
|
-
except:
|
|
137
|
-
output += f"{i}. {state_path.name} (corrupted)\n\n"
|
|
138
|
-
|
|
139
|
-
return {"status": "success", "content": [{"text": output}]}
|
|
140
|
-
|
|
141
|
-
elif action == "load":
|
|
142
|
-
# Load and display state
|
|
143
|
-
if not state_file:
|
|
144
|
-
return {
|
|
145
|
-
"status": "error",
|
|
146
|
-
"content": [{"text": "state_file required for load"}],
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
state_path = Path(state_file).expanduser()
|
|
150
|
-
if not state_path.exists():
|
|
151
|
-
return {
|
|
152
|
-
"status": "error",
|
|
153
|
-
"content": [{"text": f"State file not found: {state_path}"}],
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
with open(state_path, "rb") as f:
|
|
157
|
-
state_data = dill.load(f)
|
|
158
|
-
|
|
159
|
-
# Pretty format
|
|
160
|
-
output = f"📦 State: {state_path.name}\n\n"
|
|
161
|
-
output += f"📅 Timestamp: {state_data.get('timestamp')}\n"
|
|
162
|
-
output += f"🤖 Model: {state_data.get('model', {}).get('model_id')}\n"
|
|
163
|
-
output += f"🔧 Tools ({len(state_data.get('tools', []))}): {', '.join(state_data.get('tools', []))}\n"
|
|
164
|
-
output += f"📝 Metadata: {state_data.get('metadata', {})}\n"
|
|
165
|
-
|
|
166
|
-
if "conversation_history" in state_data:
|
|
167
|
-
history = state_data["conversation_history"]
|
|
168
|
-
output += f"\n💬 Conversation: {len(history)} messages\n"
|
|
169
|
-
|
|
170
|
-
return {"status": "success", "content": [{"text": output}]}
|
|
171
|
-
|
|
172
|
-
elif action == "resume":
|
|
173
|
-
# Time-travel: Load state and continue with ephemeral agent
|
|
174
|
-
if not state_file or not query:
|
|
175
|
-
return {
|
|
176
|
-
"status": "error",
|
|
177
|
-
"content": [{"text": "state_file and query required for resume"}],
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
state_path = Path(state_file).expanduser()
|
|
181
|
-
if not state_path.exists():
|
|
182
|
-
return {
|
|
183
|
-
"status": "error",
|
|
184
|
-
"content": [{"text": f"State file not found: {state_path}"}],
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
with open(state_path, "rb") as f:
|
|
188
|
-
state_data = dill.load(f)
|
|
189
|
-
|
|
190
|
-
# ✅ Create ephemeral DevDuck instance (no mutation!)
|
|
191
|
-
try:
|
|
192
|
-
from devduck import DevDuck
|
|
193
|
-
|
|
194
|
-
ephemeral_duck = DevDuck(auto_start_servers=False)
|
|
195
|
-
ephemeral_agent = ephemeral_duck.agent
|
|
196
|
-
except Exception as e:
|
|
197
|
-
return {
|
|
198
|
-
"status": "error",
|
|
199
|
-
"content": [{"text": f"Failed to create ephemeral DevDuck: {e}"}],
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
# Load saved state into ephemeral agent
|
|
203
|
-
ephemeral_agent.system_prompt = state_data["system_prompt"]
|
|
204
|
-
|
|
205
|
-
# Restore conversation history
|
|
206
|
-
if "conversation_history" in state_data:
|
|
207
|
-
saved_history = state_data["conversation_history"]
|
|
208
|
-
|
|
209
|
-
if hasattr(ephemeral_agent, "conversation_history"):
|
|
210
|
-
ephemeral_agent.conversation_history = saved_history
|
|
211
|
-
elif hasattr(ephemeral_agent, "messages"):
|
|
212
|
-
ephemeral_agent.messages = saved_history
|
|
213
|
-
|
|
214
|
-
# Build continuation prompt with context
|
|
215
|
-
continuation_context = f"""
|
|
216
|
-
[Resumed from state: {state_path.name}]
|
|
217
|
-
[Original timestamp: {state_data.get('timestamp')}]
|
|
218
|
-
|
|
219
|
-
{query}
|
|
220
|
-
"""
|
|
221
|
-
# Run ephemeral agent (parent agent unchanged!)
|
|
222
|
-
result = ephemeral_agent(continuation_context)
|
|
223
|
-
|
|
224
|
-
return {
|
|
225
|
-
"status": "success",
|
|
226
|
-
"content": [{"text": f"🔄 Resumed from {state_path.name}\n\n{result}"}],
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
elif action == "modify":
|
|
230
|
-
# Modify state metadata
|
|
231
|
-
if not state_file:
|
|
232
|
-
return {
|
|
233
|
-
"status": "error",
|
|
234
|
-
"content": [{"text": "state_file required for modify"}],
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
state_path = Path(state_file).expanduser()
|
|
238
|
-
if not state_path.exists():
|
|
239
|
-
return {
|
|
240
|
-
"status": "error",
|
|
241
|
-
"content": [{"text": f"State file not found: {state_path}"}],
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
with open(state_path, "rb") as f:
|
|
245
|
-
state_data = dill.load(f)
|
|
246
|
-
|
|
247
|
-
# Update metadata
|
|
248
|
-
if metadata:
|
|
249
|
-
state_data["metadata"].update(metadata)
|
|
250
|
-
|
|
251
|
-
# Save back
|
|
252
|
-
with open(state_path, "wb") as f:
|
|
253
|
-
dill.dump(state_data, f)
|
|
254
|
-
|
|
255
|
-
return {
|
|
256
|
-
"status": "success",
|
|
257
|
-
"content": [
|
|
258
|
-
{
|
|
259
|
-
"text": f"✅ Modified {state_path.name}\n📝 New metadata: {state_data['metadata']}"
|
|
260
|
-
}
|
|
261
|
-
],
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
elif action == "delete":
|
|
265
|
-
# Delete saved state
|
|
266
|
-
if not state_file:
|
|
267
|
-
return {
|
|
268
|
-
"status": "error",
|
|
269
|
-
"content": [{"text": "state_file required for delete"}],
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
state_path = Path(state_file).expanduser()
|
|
273
|
-
if not state_path.exists():
|
|
274
|
-
return {
|
|
275
|
-
"status": "error",
|
|
276
|
-
"content": [{"text": f"State file not found: {state_path}"}],
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
state_path.unlink()
|
|
280
|
-
return {
|
|
281
|
-
"status": "success",
|
|
282
|
-
"content": [{"text": f"🗑️ Deleted {state_path.name}"}],
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
else:
|
|
286
|
-
return {
|
|
287
|
-
"status": "error",
|
|
288
|
-
"content": [{"text": f"Unknown action: {action}"}],
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
except Exception as e:
|
|
292
|
-
return {"status": "error", "content": [{"text": f"Error: {e}"}]}
|