Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -155,41 +155,71 @@ def extract_conversational_text(content: str) -> str:
|
|
| 155 |
|
| 156 |
def execute_tool(tool_name: str, args: dict) -> dict:
|
| 157 |
try:
|
|
|
|
| 158 |
if tool_name == 'search_code':
|
| 159 |
res = ctx.search_code(args.get('query', ''), args.get('n', 5))
|
| 160 |
return {"status": "executed", "tool": tool_name, "result": "\n".join([f"📄 {r['file']}\n```{r['snippet']}```" for r in res])}
|
|
|
|
| 161 |
elif tool_name == 'read_file':
|
|
|
|
| 162 |
return {"status": "executed", "tool": tool_name, "result": ctx.read_file(args.get('path', ''), args.get('start_line'), args.get('end_line'))}
|
|
|
|
| 163 |
elif tool_name == 'list_files':
|
| 164 |
return {"status": "executed", "tool": tool_name, "result": ctx.list_files(args.get('path', ''), args.get('max_depth', 3))}
|
|
|
|
| 165 |
elif tool_name == 'search_conversations':
|
| 166 |
res = ctx.search_conversations(args.get('query', ''), args.get('n', 5))
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
return {"status": "executed", "tool": tool_name, "result": formatted}
|
|
|
|
| 169 |
elif tool_name == 'search_testament':
|
| 170 |
res = ctx.search_testament(args.get('query', ''), args.get('n', 5))
|
| 171 |
formatted = "\n\n".join([f"📜 **{r['file']}**\n{r['snippet']}" for r in res]) if res else "No matches found."
|
| 172 |
return {"status": "executed", "tool": tool_name, "result": formatted}
|
|
|
|
|
|
|
| 173 |
elif tool_name == 'write_file':
|
| 174 |
result = ctx.write_file(args.get('path', ''), args.get('content', ''))
|
| 175 |
return {"status": "executed", "tool": tool_name, "result": result}
|
|
|
|
| 176 |
elif tool_name == 'shell_execute':
|
| 177 |
result = ctx.shell_execute(args.get('command', ''))
|
| 178 |
return {"status": "executed", "tool": tool_name, "result": result}
|
|
|
|
| 179 |
elif tool_name == 'push_to_github':
|
| 180 |
result = ctx.push_to_github(args.get('message', 'Manual Backup'))
|
| 181 |
return {"status": "executed", "tool": tool_name, "result": result}
|
|
|
|
| 182 |
elif tool_name == 'pull_from_github':
|
| 183 |
result = ctx.pull_from_github(args.get('branch', 'main'))
|
| 184 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 185 |
-
|
| 186 |
-
# Calls the method in recursive_context.py
|
| 187 |
-
return {"result": ctx.notebook_add(args.get('content', ''))}
|
| 188 |
elif tool_name == 'map_repository_structure':
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
elif tool_name == 'create_shadow_branch':
|
| 192 |
return {"status": "staged", "tool": tool_name, "args": args, "description": "🛡️ Create shadow branch"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
return {"status": "error", "result": f"Unknown tool: {tool_name}"}
|
| 194 |
except Exception as e: return {"status": "error", "result": str(e)}
|
| 195 |
|
|
|
|
| 155 |
|
| 156 |
def execute_tool(tool_name: str, args: dict) -> dict:
|
| 157 |
try:
|
| 158 |
+
# --- SEARCH & READ ---
|
| 159 |
if tool_name == 'search_code':
|
| 160 |
res = ctx.search_code(args.get('query', ''), args.get('n', 5))
|
| 161 |
return {"status": "executed", "tool": tool_name, "result": "\n".join([f"📄 {r['file']}\n```{r['snippet']}```" for r in res])}
|
| 162 |
+
|
| 163 |
elif tool_name == 'read_file':
|
| 164 |
+
# FIX: Mapped 'start_line' -> 'start', 'end_line' -> 'end' to match RecursiveContext
|
| 165 |
return {"status": "executed", "tool": tool_name, "result": ctx.read_file(args.get('path', ''), args.get('start_line'), args.get('end_line'))}
|
| 166 |
+
|
| 167 |
elif tool_name == 'list_files':
|
| 168 |
return {"status": "executed", "tool": tool_name, "result": ctx.list_files(args.get('path', ''), args.get('max_depth', 3))}
|
| 169 |
+
|
| 170 |
elif tool_name == 'search_conversations':
|
| 171 |
res = ctx.search_conversations(args.get('query', ''), args.get('n', 5))
|
| 172 |
+
# FIX: Handle Xet results (metadata/id) vs Mock results
|
| 173 |
+
formatted_res = []
|
| 174 |
+
for r in res:
|
| 175 |
+
if 'metadata' in r: # Xet Result
|
| 176 |
+
meta = r['metadata']
|
| 177 |
+
formatted_res.append(f"[{meta.get('timestamp','?')}] {meta.get('role','?')}: {meta.get('content','')}")
|
| 178 |
+
else: # Fallback
|
| 179 |
+
formatted_res.append(str(r))
|
| 180 |
+
|
| 181 |
+
formatted = "\n---\n".join(formatted_res) if formatted_res else "No matches found."
|
| 182 |
return {"status": "executed", "tool": tool_name, "result": formatted}
|
| 183 |
+
|
| 184 |
elif tool_name == 'search_testament':
|
| 185 |
res = ctx.search_testament(args.get('query', ''), args.get('n', 5))
|
| 186 |
formatted = "\n\n".join([f"📜 **{r['file']}**\n{r['snippet']}" for r in res]) if res else "No matches found."
|
| 187 |
return {"status": "executed", "tool": tool_name, "result": formatted}
|
| 188 |
+
|
| 189 |
+
# --- WRITE & OPS ---
|
| 190 |
elif tool_name == 'write_file':
|
| 191 |
result = ctx.write_file(args.get('path', ''), args.get('content', ''))
|
| 192 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 193 |
+
|
| 194 |
elif tool_name == 'shell_execute':
|
| 195 |
result = ctx.shell_execute(args.get('command', ''))
|
| 196 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 197 |
+
|
| 198 |
elif tool_name == 'push_to_github':
|
| 199 |
result = ctx.push_to_github(args.get('message', 'Manual Backup'))
|
| 200 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 201 |
+
|
| 202 |
elif tool_name == 'pull_from_github':
|
| 203 |
result = ctx.pull_from_github(args.get('branch', 'main'))
|
| 204 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 205 |
+
|
|
|
|
|
|
|
| 206 |
elif tool_name == 'map_repository_structure':
|
| 207 |
+
# FIX: Added status key
|
| 208 |
+
result = ctx.map_repository_structure()
|
| 209 |
+
return {"status": "executed", "tool": tool_name, "result": result}
|
| 210 |
+
|
| 211 |
elif tool_name == 'create_shadow_branch':
|
| 212 |
return {"status": "staged", "tool": tool_name, "args": args, "description": "🛡️ Create shadow branch"}
|
| 213 |
+
|
| 214 |
+
# --- NOTEBOOK ---
|
| 215 |
+
elif tool_name == 'notebook_add':
|
| 216 |
+
# FIX: Added status key
|
| 217 |
+
return {"status": "executed", "tool": tool_name, "result": ctx.notebook_add(args.get('content', ''))}
|
| 218 |
+
elif tool_name == 'notebook_read':
|
| 219 |
+
return {"status": "executed", "tool": tool_name, "result": ctx.notebook_read()}
|
| 220 |
+
elif tool_name == 'notebook_delete':
|
| 221 |
+
return {"status": "executed", "tool": tool_name, "result": ctx.notebook_delete(args.get('index', 0))}
|
| 222 |
+
|
| 223 |
return {"status": "error", "result": f"Unknown tool: {tool_name}"}
|
| 224 |
except Exception as e: return {"status": "error", "result": str(e)}
|
| 225 |
|