feat(copilot): stabilize concurrency and enhance terminal context management
- AI Concurrency: - Implemented a dedicated background event loop (ConnpyAILoop) in a separate thread for AI tasks to ensure thread safety and event loop affinity. - Added 'run_ai_async' utility to funnel all LiteLLM calls through the dedicated loop. - Implemented global 'cleanup()' for safe closure of sync/async LiteLLM sessions. - gRPC & Remote Sessions: - Enhanced 'NodeServicer' to identify command blocks within the terminal buffer using prompt regex/byte tracking. - Added support for selective context retrieval via 'context_start_pos' in the gRPC Interact stream. - Synchronized remote Copilot behavior by enriching questions with session history (last 5 queries) in 'NodeStub'. - Optimized token usage by cleaning 'node_info' metadata before AI transmission. - Terminal Context & Core: - Modified 'node.connect' to always initialize 'mylog' (BytesIO) buffer regardless of disk logging configuration, ensuring Copilot context availability. - Integrated 'ai.cleanup()' in CLI (connapp) and Server (api) exit points for graceful shutdowns. - Suppressed LiteLLM internal streaming coroutine warnings during task cancellation.
This commit is contained in:
1 parent
1103393be6
commit
dba7e24dda
7 files changed
+170
-15
No files matched your search
+9
-6
@@ -354,14 +354,17 @@ class node:
|
||||
port_str = f":{self.port}" if self.port and self.protocol not in ["ssm", "kubectl", "docker"] else ""
|
||||
logger("success", f"Connected to {self.unique} at {self.host}{port_str} via: {self.protocol}")
|
||||
|
||||
# Always initialize self.mylog to capture terminal context for the AI Copilot
|
||||
if not hasattr(self, 'mylog'):
|
||||
self.mylog = io.BytesIO()
|
||||
|
||||
if not async_mode:
|
||||
self.child.logfile_read = self.mylog
|
||||
|
||||
# Only start disk-logging tasks if logfile is configured
|
||||
if 'logfile' in dir(self):
|
||||
# Initialize self.mylog
|
||||
if not 'mylog' in dir(self):
|
||||
self.mylog = io.BytesIO()
|
||||
if not async_mode:
|
||||
self.child.logfile_read = self.mylog
|
||||
|
||||
# Start the _savelog thread
|
||||
# Start the _savelog thread (sync mode)
|
||||
log_thread = threading.Thread(target=self._savelog)
|
||||
log_thread.daemon = True
|
||||
log_thread.start()
|
||||
|
||||
Reference in new issue
Block a user