sidekick-agent-cli 0.2.1__tar.gz → 0.3.0__tar.gz

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.
Files changed (19) hide show
  1. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/PKG-INFO +1 -1
  2. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/pyproject.toml +1 -1
  3. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/auth.py +6 -4
  4. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/chat.py +0 -1
  5. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/chat_display.py +0 -1
  6. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/cli.py +9 -2
  7. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/cli_common.py +8 -4
  8. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/local_tools.py +5 -5
  9. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/runner.py +28 -4
  10. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/runtime.py +71 -60
  11. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/.gitignore +0 -0
  12. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/LICENSE +0 -0
  13. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/README.md +0 -0
  14. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/SECURITY.md +0 -0
  15. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/__init__.py +0 -0
  16. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/__main__.py +0 -0
  17. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/api_client.py +0 -0
  18. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/display.py +0 -0
  19. {sidekick_agent_cli-0.2.1 → sidekick_agent_cli-0.3.0}/src/agent_runtime/run.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sidekick-agent-cli
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: CLI for the Sidekick Agent Orchestrator
5
5
  Project-URL: Homepage, https://github.com/datex-labs/sidekick
6
6
  Project-URL: Repository, https://github.com/datex-labs/sidekick
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sidekick-agent-cli"
7
- version = "0.2.1"
7
+ version = "0.3.0"
8
8
  description = "CLI for the Sidekick Agent Orchestrator"
9
9
  requires-python = ">=3.11"
10
10
  license = "MIT"
@@ -13,6 +13,7 @@ import json
13
13
  import logging
14
14
  import os
15
15
  import pathlib
16
+ import sys
16
17
  import secrets
17
18
  import tempfile
18
19
  import webbrowser
@@ -86,10 +87,11 @@ def _write_credentials(creds: dict[str, Any]) -> None:
86
87
  )
87
88
  try:
88
89
  os.write(fd, json.dumps(creds, indent=2, default=str).encode())
89
- os.fchmod(fd, 0o600)
90
+ if sys.platform != "win32":
91
+ os.fchmod(fd, 0o600)
90
92
  os.close(fd)
91
93
  fd = -1 # mark as closed
92
- os.rename(tmp_path, CREDENTIALS_PATH)
94
+ os.replace(tmp_path, CREDENTIALS_PATH)
93
95
  except BaseException:
94
96
  if fd >= 0:
95
97
  os.close(fd)
@@ -335,7 +337,7 @@ async def browser_auth(url: str) -> dict:
335
337
  try:
336
338
  # Open browser to authorization page
337
339
  auth_url = f"{url.rstrip('/')}/cli/authorize?port={port}&state={state}"
338
- print(f"\nOpening browser for authentication...")
340
+ print("\nOpening browser for authentication...")
339
341
  print(f"If the browser doesn't open, visit:\n {auth_url}\n")
340
342
  webbrowser.open(auth_url)
341
343
 
@@ -446,7 +448,7 @@ def browser_register(url: str) -> dict[str, str]:
446
448
 
447
449
  register_url = f"{url.rstrip('/')}/cli/register?port={port}&state={state}"
448
450
  logger.info("Opening browser for runner registration: %s", register_url)
449
- print(f"\nOpening browser for runner registration...")
451
+ print("\nOpening browser for runner registration...")
450
452
  print(f"If the browser doesn't open, visit:\n {register_url}\n")
451
453
  webbrowser.open(register_url)
452
454
 
@@ -6,7 +6,6 @@ Usage: sidekick chat --url https://sidekick.example.com
6
6
 
7
7
  from __future__ import annotations
8
8
 
9
- import asyncio
10
9
  import logging
11
10
  import os
12
11
  import pathlib
@@ -11,7 +11,6 @@ import sys
11
11
  from typing import Optional
12
12
 
13
13
  from rich.console import Console
14
- from rich.markdown import Markdown
15
14
  from rich.panel import Panel
16
15
  from rich.text import Text
17
16
 
@@ -364,13 +364,20 @@ def _run_serve(args: argparse.Namespace) -> None:
364
364
  )
365
365
  )
366
366
 
367
- for sig in (signal.SIGINT, signal.SIGTERM):
368
- loop.add_signal_handler(sig, task.cancel)
367
+ if sys.platform != "win32":
368
+ for sig in (signal.SIGINT, signal.SIGTERM):
369
+ loop.add_signal_handler(sig, task.cancel)
369
370
 
370
371
  try:
371
372
  loop.run_until_complete(task)
372
373
  except asyncio.CancelledError:
373
374
  pass
375
+ except KeyboardInterrupt:
376
+ task.cancel()
377
+ try:
378
+ loop.run_until_complete(task)
379
+ except asyncio.CancelledError:
380
+ pass
374
381
  finally:
375
382
  loop.close()
376
383
 
@@ -9,7 +9,6 @@ from __future__ import annotations
9
9
 
10
10
  import asyncio
11
11
  import logging
12
- import os
13
12
  import signal
14
13
  import sys
15
14
  from dataclasses import dataclass
@@ -87,14 +86,19 @@ def run_async(coro) -> None:
87
86
  loop = asyncio.new_event_loop()
88
87
  task = loop.create_task(coro)
89
88
 
90
- for sig in (signal.SIGINT, signal.SIGTERM):
91
- loop.add_signal_handler(sig, task.cancel)
89
+ if sys.platform != "win32":
90
+ for sig in (signal.SIGINT, signal.SIGTERM):
91
+ loop.add_signal_handler(sig, task.cancel)
92
92
 
93
93
  try:
94
94
  loop.run_until_complete(task)
95
95
  except asyncio.CancelledError:
96
96
  pass
97
97
  except KeyboardInterrupt:
98
- pass
98
+ task.cancel()
99
+ try:
100
+ loop.run_until_complete(task)
101
+ except asyncio.CancelledError:
102
+ pass
99
103
  finally:
100
104
  loop.close()
@@ -7,12 +7,9 @@ running the runtime inside a VM — zero-hop tool execution.
7
7
  """
8
8
 
9
9
  import asyncio
10
- import json
11
10
  import logging
12
11
  import os
13
12
  from pathlib import Path
14
- from typing import Any, Dict
15
-
16
13
  from .api_client import ToolNode, ToolResult
17
14
 
18
15
  logger = logging.getLogger(__name__)
@@ -40,6 +37,9 @@ SENSITIVE_ENV_VARS = frozenset({
40
37
  "PYTHONPATH", "PATH", "PYTHONSTARTUP", "PYTHONHOME", "NODE_OPTIONS",
41
38
  # Home / config directories (information leakage)
42
39
  "HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME",
40
+ "USERPROFILE", "APPDATA", "LOCALAPPDATA",
41
+ # Windows system paths and shell
42
+ "COMSPEC", "PATHEXT", "SYSTEMROOT", "WINDIR",
43
43
  # Proxy settings (traffic redirection)
44
44
  "HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY",
45
45
  # TLS / certificate overrides
@@ -374,9 +374,9 @@ async def _get_session_info(node: ToolNode, workspace: str | None = None) -> Too
374
374
 
375
375
  cwd = os.getcwd()
376
376
  info_lines = [
377
- f"Status: online",
377
+ "Status: online",
378
378
  f"Working Directory: {cwd}",
379
- f"Backend: self-hosted",
379
+ "Backend: self-hosted",
380
380
  f"Hostname: {socket.gethostname()}",
381
381
  f"OS: {platform.system()} {platform.release()}",
382
382
  ]
@@ -30,13 +30,25 @@ except Exception:
30
30
  __version__ = "0.1.0" # Fallback for editable installs / development
31
31
 
32
32
 
33
+ def _is_wsl() -> bool:
34
+ """Detect if running inside Windows Subsystem for Linux."""
35
+ try:
36
+ with open("/proc/version") as f:
37
+ return "microsoft" in f.read().lower()
38
+ except Exception:
39
+ return False
40
+
41
+
33
42
  def _get_machine_info(name: str | None = None) -> dict:
34
43
  """Collect machine info to send on WebSocket connect."""
35
- import subprocess
44
+ system = platform.system()
45
+ os_label = f"{system} {platform.release()}"
46
+ if system == "Linux" and _is_wsl():
47
+ os_label += " (WSL)"
36
48
 
37
49
  info: dict = {
38
50
  "hostname": socket.gethostname(),
39
- "os": f"{platform.system()} {platform.release()}",
51
+ "os": os_label,
40
52
  "platform": platform.platform(),
41
53
  "python_version": platform.python_version(),
42
54
  "agent_runtime_version": __version__,
@@ -46,17 +58,29 @@ def _get_machine_info(name: str | None = None) -> dict:
46
58
  # CPU info
47
59
  info["cpu_cores"] = os.cpu_count()
48
60
  info["cpu_arch"] = platform.machine()
49
- info["cpu_name"] = _run_quiet(["sysctl", "-n", "machdep.cpu.brand_string"]) if platform.system() == "Darwin" else _read_file_line("/proc/cpuinfo", "model name")
61
+ if system == "Darwin":
62
+ info["cpu_name"] = _run_quiet(["sysctl", "-n", "machdep.cpu.brand_string"])
63
+ elif system == "Windows":
64
+ raw = _run_quiet(["wmic", "cpu", "get", "name", "/value"])
65
+ info["cpu_name"] = raw.split("=", 1)[1].strip() if raw and "=" in raw else None
66
+ else:
67
+ info["cpu_name"] = _read_file_line("/proc/cpuinfo", "model name")
50
68
  if not info["cpu_name"]:
51
69
  info["cpu_name"] = platform.processor() or None
52
70
 
53
71
  # Memory (total physical RAM in bytes)
54
- system = platform.system()
55
72
  mem_bytes: int | None = None
56
73
  if system == "Darwin":
57
74
  raw = _run_quiet(["sysctl", "-n", "hw.memsize"])
58
75
  if raw:
59
76
  mem_bytes = int(raw)
77
+ elif system == "Windows":
78
+ raw = _run_quiet(["wmic", "OS", "get", "TotalVisibleMemorySize", "/value"])
79
+ if raw and "=" in raw:
80
+ try:
81
+ mem_bytes = int(raw.split("=", 1)[1].strip()) * 1024 # KB -> bytes
82
+ except (ValueError, IndexError):
83
+ pass
60
84
  elif system == "Linux":
61
85
  raw = _read_file_line("/proc/meminfo", "MemTotal")
62
86
  if raw:
@@ -13,10 +13,10 @@ It never touches databases, Redis, or LLM providers directly.
13
13
  import asyncio
14
14
  import json
15
15
  import logging
16
+ import os
16
17
  from typing import Dict, List, Optional
17
18
 
18
19
  from .api_client import (
19
- EvaluationContext,
20
20
  LLMResponse,
21
21
  RuntimeAPIClient,
22
22
  ToolNode,
@@ -63,6 +63,12 @@ class AgentRuntime:
63
63
  """
64
64
  turn = await self.api.start_turn(conversation_id, node_id, ref_name, user_id=user_id)
65
65
 
66
+ # Expose agent/conversation context as env vars so local tools
67
+ # (RunCommand, etc.) inherit them in their subprocess environment.
68
+ if turn.agent_id:
69
+ os.environ["SIDEKICK_AGENT_ID"] = turn.agent_id
70
+ os.environ["SIDEKICK_CONVERSATION_ID"] = conversation_id
71
+
66
72
  logger.info(
67
73
  f"Turn started: {turn.turn_id} | "
68
74
  f"conversation={conversation_id} | "
@@ -75,75 +81,80 @@ class AgentRuntime:
75
81
  iteration = 0
76
82
  max_iterations = 25 # Safety limit
77
83
 
78
- while iteration < max_iterations:
79
- iteration += 1
84
+ try:
85
+ while iteration < max_iterations:
86
+ iteration += 1
87
+
88
+ # Check cancellation
89
+ if await self.api.is_cancelled(turn.turn_id):
90
+ logger.info(f"Turn {turn.turn_id} cancelled")
91
+ if self._display:
92
+ self._display.on_turn_cancelled(turn.turn_id)
93
+ break
80
94
 
81
- # Check cancellation
82
- if await self.api.is_cancelled(turn.turn_id):
83
- logger.info(f"Turn {turn.turn_id} cancelled")
95
+ # Call LLM (Sidekick handles frontend streaming as a side effect)
96
+ logger.info(f"LLM call #{iteration} for turn {turn.turn_id}")
84
97
  if self._display:
85
- self._display.on_turn_cancelled(turn.turn_id)
86
- break
87
-
88
- # Call LLM (Sidekick handles frontend streaming as a side effect)
89
- logger.info(f"LLM call #{iteration} for turn {turn.turn_id}")
90
- if self._display:
91
- self._display.on_llm_call(iteration, turn.turn_id)
92
- response = await self.api.stream_llm(turn.turn_id, turn, on_delta=on_delta)
93
-
94
- if not response.tool_calls:
95
- # No tool calls — finalize the turn
96
- await self.api.complete_turn(turn.turn_id, response.parts)
98
+ self._display.on_llm_call(iteration, turn.turn_id)
99
+ response = await self.api.stream_llm(turn.turn_id, turn, on_delta=on_delta)
100
+
101
+ if not response.tool_calls:
102
+ # No tool calls — finalize the turn
103
+ await self.api.complete_turn(turn.turn_id, response.parts)
104
+ logger.info(
105
+ f"Turn {turn.turn_id} completed (no tools) after {iteration} iteration(s)"
106
+ )
107
+ if self._display:
108
+ self._display.on_turn_completed(turn.turn_id, iteration)
109
+ return
110
+
111
+ # Register tool calls with Sidekick (creates pending nodes)
112
+ tool_nodes = await self.api.register_tool_calls(
113
+ turn.turn_id,
114
+ response.parts,
115
+ response.tool_calls,
116
+ turn.tool_definitions,
117
+ )
118
+
119
+ tool_names = [tn.tool_name for tn in tool_nodes]
97
120
  logger.info(
98
- f"Turn {turn.turn_id} completed (no tools) after {iteration} iteration(s)"
121
+ f"Registered {len(tool_nodes)} tool calls: "
122
+ f"{', '.join(tool_names)}"
99
123
  )
100
124
  if self._display:
101
- self._display.on_turn_completed(turn.turn_id, iteration)
102
- return
103
-
104
- # Register tool calls with Sidekick (creates pending nodes)
105
- tool_nodes = await self.api.register_tool_calls(
106
- turn.turn_id,
107
- response.parts,
108
- response.tool_calls,
109
- turn.tool_definitions,
110
- )
125
+ self._display.on_tools_registered(tool_names)
111
126
 
112
- tool_names = [tn.tool_name for tn in tool_nodes]
113
- logger.info(
114
- f"Registered {len(tool_nodes)} tool calls: "
115
- f"{', '.join(tool_names)}"
116
- )
117
- if self._display:
118
- self._display.on_tools_registered(tool_names)
119
-
120
- # Execute tools (local or remote)
121
- results = await self._execute_tools(
122
- tool_nodes, conversation_id, node_id, ref_name,
123
- on_tool_start=on_tool_start, on_tool_complete=on_tool_complete,
124
- )
127
+ # Execute tools (local or remote)
128
+ results = await self._execute_tools(
129
+ tool_nodes, conversation_id, node_id, ref_name,
130
+ on_tool_start=on_tool_start, on_tool_complete=on_tool_complete,
131
+ )
125
132
 
126
- # Submit results to Sidekick
127
- await self.api.submit_tool_results(turn.turn_id, results)
133
+ # Submit results to Sidekick
134
+ await self.api.submit_tool_results(turn.turn_id, results)
128
135
 
129
- # Evaluate oversized tool results via ephemeral branches
130
- eval_config = (turn.agent_config or {}).get("context_evaluation", {})
131
- if eval_config.get("enabled"):
132
- await self._evaluate_tool_results(
133
- turn, results, eval_config, tool_nodes
134
- )
136
+ # Evaluate oversized tool results via ephemeral branches
137
+ eval_config = (turn.agent_config or {}).get("context_evaluation", {})
138
+ if eval_config.get("enabled"):
139
+ await self._evaluate_tool_results(
140
+ turn, results, eval_config, tool_nodes
141
+ )
135
142
 
136
- # Get updated context for next LLM call
137
- continuation = await self.api.continue_turn(turn.turn_id)
138
- turn.messages = continuation.messages
139
- turn.tool_definitions = continuation.tool_definitions
143
+ # Get updated context for next LLM call
144
+ continuation = await self.api.continue_turn(turn.turn_id)
145
+ turn.messages = continuation.messages
146
+ turn.tool_definitions = continuation.tool_definitions
140
147
 
141
- if iteration >= max_iterations:
142
- logger.warning(
143
- f"Turn {turn.turn_id} hit max iterations ({max_iterations})"
144
- )
145
- # Still complete the turn with whatever we have
146
- await self.api.complete_turn(turn.turn_id, [])
148
+ if iteration >= max_iterations:
149
+ logger.warning(
150
+ f"Turn {turn.turn_id} hit max iterations ({max_iterations})"
151
+ )
152
+ # Still complete the turn with whatever we have
153
+ await self.api.complete_turn(turn.turn_id, [])
154
+ finally:
155
+ # Clean up turn-scoped env vars
156
+ os.environ.pop("SIDEKICK_AGENT_ID", None)
157
+ os.environ.pop("SIDEKICK_CONVERSATION_ID", None)
147
158
 
148
159
  async def _execute_single_tool(
149
160
  self,