devops-bot-sdk 1.6.6__tar.gz → 1.6.8__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 (111) hide show
  1. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/PKG-INFO +1 -1
  2. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/devops_bot_sdk.egg-info/PKG-INFO +1 -1
  3. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/devops_bot_sdk.egg-info/SOURCES.txt +2 -0
  4. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/__init__.py +2 -2
  5. devops_bot_sdk-1.6.8/sdk/agents/engines/claude_code.py +122 -0
  6. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/config.py +64 -6
  7. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/design_verify/loop.py +5 -4
  8. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/local_exec.py +23 -11
  9. devops_bot_sdk-1.6.8/tests/test_agent_workspace_settings.py +140 -0
  10. devops_bot_sdk-1.6.8/tests/test_allowed_tools_config.py +102 -0
  11. devops_bot_sdk-1.6.6/sdk/agents/engines/claude_code.py +0 -61
  12. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/README.md +0 -0
  13. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/devops_bot_sdk.egg-info/dependency_links.txt +0 -0
  14. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/devops_bot_sdk.egg-info/entry_points.txt +0 -0
  15. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/devops_bot_sdk.egg-info/requires.txt +0 -0
  16. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/devops_bot_sdk.egg-info/top_level.txt +0 -0
  17. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/pyproject.toml +0 -0
  18. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agentd.py +0 -0
  19. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/__init__.py +0 -0
  20. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/activity.py +0 -0
  21. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/builder.py +0 -0
  22. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/chat.py +0 -0
  23. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/connectors.py +0 -0
  24. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/engines/__init__.py +0 -0
  25. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/engines/http.py +0 -0
  26. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/engines/mcp.py +0 -0
  27. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/engines/n8n.py +0 -0
  28. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/engines/shell.py +0 -0
  29. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/integrations.py +0 -0
  30. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/inventory.py +0 -0
  31. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/library/__init__.py +0 -0
  32. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/manifest.py +0 -0
  33. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/prompt_studio.py +0 -0
  34. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/prompt_template.py +0 -0
  35. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/prompt_vars.py +0 -0
  36. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/run_log.py +0 -0
  37. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/secrets.py +0 -0
  38. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/ticket_run.py +0 -0
  39. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/usage.py +0 -0
  40. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/agents/varstore.py +0 -0
  41. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/cli.py +0 -0
  42. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/client.py +0 -0
  43. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/collectors/__init__.py +0 -0
  44. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/collectors/files.py +0 -0
  45. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/collectors/process.py +0 -0
  46. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/collectors/screenshot.py +0 -0
  47. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/crucial.py +0 -0
  48. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/design_verify/__init__.py +0 -0
  49. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/design_verify/assets.py +0 -0
  50. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/design_verify/bootstrap.py +0 -0
  51. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/design_verify/browser.py +0 -0
  52. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/design_verify/compare.py +0 -0
  53. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/exceptions.py +0 -0
  54. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/git_ops.py +0 -0
  55. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/github_ingest.py +0 -0
  56. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/graphify.py +0 -0
  57. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/hooks/__init__.py +0 -0
  58. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/hooks/crucial_guard.py +0 -0
  59. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ipc/__init__.py +0 -0
  60. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ipc/electron_bridge.py +0 -0
  61. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ipc/handlers.py +0 -0
  62. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/models/__init__.py +0 -0
  63. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/models/envelope.py +0 -0
  64. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/models/requests.py +0 -0
  65. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/models/responses.py +0 -0
  66. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/models/snapshots.py +0 -0
  67. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/platform_compat.py +0 -0
  68. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/py.typed +0 -0
  69. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/run_auto.py +0 -0
  70. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/sse.py +0 -0
  71. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/test.py +0 -0
  72. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/test_pipeline.py +0 -0
  73. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/__init__.py +0 -0
  74. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/api.py +0 -0
  75. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/dashboard.py +0 -0
  76. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/health.py +0 -0
  77. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/ip_allowlist.py +0 -0
  78. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/jobs.py +0 -0
  79. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/models.py +0 -0
  80. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/runner.py +0 -0
  81. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/security.py +0 -0
  82. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/server.py +0 -0
  83. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/service.py +0 -0
  84. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/session.py +0 -0
  85. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/setup_manager.py +0 -0
  86. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/agents.html +0 -0
  87. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/app.js +0 -0
  88. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/custom-agents.html +0 -0
  89. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/default-agents.html +0 -0
  90. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/index.html +0 -0
  91. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/login.html +0 -0
  92. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/runs.html +0 -0
  93. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/setup.html +0 -0
  94. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/styles.css +0 -0
  95. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/ui/static/tickets.html +0 -0
  96. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/updater.py +0 -0
  97. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/sdk/vps_health.py +0 -0
  98. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/setup.cfg +0 -0
  99. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agent_activity.py +0 -0
  100. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agent_chat_features.py +0 -0
  101. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agent_listing.py +0 -0
  102. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agent_prompt_async.py +0 -0
  103. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agent_prompt_models.py +0 -0
  104. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agent_run_ticket.py +0 -0
  105. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_agents_connectors_builder.py +0 -0
  106. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_git_action.py +0 -0
  107. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_github_ingest.py +0 -0
  108. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_health.py +0 -0
  109. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_otp_login.py +0 -0
  110. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_updater_extras.py +0 -0
  111. {devops_bot_sdk-1.6.6 → devops_bot_sdk-1.6.8}/tests/test_vps_health.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: devops-bot-sdk
3
- Version: 1.6.6
3
+ Version: 1.6.8
4
4
  Summary: DevOps Bot Desktop SDK — thin client for the AgentOS Electron desktop app
5
5
  Author: noumanaziz2128
6
6
  License-Expression: LicenseRef-Proprietary
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: devops-bot-sdk
3
- Version: 1.6.6
3
+ Version: 1.6.8
4
4
  Summary: DevOps Bot Desktop SDK — thin client for the AgentOS Electron desktop app
5
5
  Author: noumanaziz2128
6
6
  License-Expression: LicenseRef-Proprietary
@@ -97,7 +97,9 @@ tests/test_agent_listing.py
97
97
  tests/test_agent_prompt_async.py
98
98
  tests/test_agent_prompt_models.py
99
99
  tests/test_agent_run_ticket.py
100
+ tests/test_agent_workspace_settings.py
100
101
  tests/test_agents_connectors_builder.py
102
+ tests/test_allowed_tools_config.py
101
103
  tests/test_git_action.py
102
104
  tests/test_github_ingest.py
103
105
  tests/test_health.py
@@ -1,6 +1,6 @@
1
1
  """AgentOS Desktop SDK — thin HTTPS/SSE client for the Electron app.
2
2
 
3
- Version: 1.6.6
3
+ Version: 1.6.8
4
4
 
5
5
  Public surface:
6
6
  BackendClient.from_config() — create client from ~/.agentos/config.toml
@@ -30,7 +30,7 @@ Rules:
30
30
  - All data egress through submit_webhook only
31
31
  """
32
32
 
33
- __version__ = "1.6.6" # SINGLE SOURCE OF TRUTH — bump on every change; pyproject,
33
+ __version__ = "1.6.8" # SINGLE SOURCE OF TRUTH — bump on every change; pyproject,
34
34
  __author__ = "AgentOS" # sdk.client.SDK_VERSION and the UI server version all read this.
35
35
 
36
36
  from sdk.client import BackendClient
@@ -0,0 +1,122 @@
1
+ """claude_code engine -- a thin adapter from an agent manifest onto ``sdk.local_exec.run_claude_local``."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import logging
6
+ from pathlib import Path
7
+ from typing import TYPE_CHECKING, Any, Awaitable, Callable
8
+
9
+ from sdk import config
10
+ from sdk.local_exec import run_claude_local
11
+
12
+ if TYPE_CHECKING:
13
+ from sdk.agents.manifest import AgentManifest
14
+
15
+ logger = logging.getLogger("sdk.agents.engines.claude_code")
16
+
17
+ # Same shape as sdk.local_exec.EventHandler -- kept local so this module doesn't
18
+ # need to reach into local_exec for a type alias.
19
+ EventHandler = Callable[[dict], Awaitable[None]]
20
+
21
+ # Directory every agent without a real code workspace runs in.
22
+ AGENT_RUNS_DIR = Path.home() / ".agentos" / "runs"
23
+
24
+
25
+ def ensure_agent_workspace(agent_name: str) -> Path:
26
+ """The working directory for ``agent_name``, with its Claude settings in place.
27
+
28
+ Returns ``~/.agentos/runs/<agent>`` and makes sure
29
+ ``<that>/.claude/settings.json`` grants the configured tools
30
+ (``config.get_allowed_tools()``) under ``permissions.allow``.
31
+
32
+ Why write it at all when ``run_claude_local`` already passes
33
+ ``--allowedTools``: that flag covers the headless run, but the run directory IS
34
+ a Claude Code project, so anything reading project settings — a resumed
35
+ session, a nested/interactive invocation, a hook — sees the same grants instead
36
+ of falling back to prompting in a place where nobody can answer.
37
+
38
+ MERGES rather than overwrites: existing keys and any extra entries already in
39
+ ``permissions.allow`` are preserved, so a hand-added rule survives, and a tool
40
+ added to the configured list later shows up on the next run. Best-effort — a
41
+ write failure is logged and the run proceeds on ``--allowedTools`` alone.
42
+
43
+ Applies to CUSTOM and DEPARTMENT agents alike: both arrive as prompt-based
44
+ backend rows and both run through here.
45
+ """
46
+ workspace = AGENT_RUNS_DIR / agent_name
47
+ workspace.mkdir(parents=True, exist_ok=True)
48
+
49
+ settings_path = workspace / ".claude" / "settings.json"
50
+ try:
51
+ settings: dict = {}
52
+ if settings_path.exists():
53
+ try:
54
+ loaded = json.loads(settings_path.read_text(encoding="utf-8"))
55
+ if isinstance(loaded, dict):
56
+ settings = loaded
57
+ except (OSError, json.JSONDecodeError) as exc:
58
+ # A corrupt file silently disables ALL settings from it, so replace
59
+ # it rather than leave the agent running with none.
60
+ logger.warning("rewriting unparseable %s: %s", settings_path, exc)
61
+
62
+ permissions = settings.get("permissions")
63
+ if not isinstance(permissions, dict):
64
+ permissions = {}
65
+ allow = [t for t in (permissions.get("allow") or []) if isinstance(t, str)]
66
+ for tool in config.get_allowed_tools():
67
+ if tool not in allow:
68
+ allow.append(tool)
69
+ permissions["allow"] = allow
70
+ settings["permissions"] = permissions
71
+
72
+ settings_path.parent.mkdir(parents=True, exist_ok=True)
73
+ settings_path.write_text(json.dumps(settings, indent=2) + "\n", encoding="utf-8")
74
+ except OSError as exc:
75
+ logger.warning("could not write %s: %s", settings_path, exc)
76
+
77
+ return workspace
78
+
79
+
80
+ async def run(
81
+ manifest: "AgentManifest",
82
+ skill_text: str,
83
+ mcp_config: dict[str, Any] | None,
84
+ project_path: str | None = None,
85
+ on_event: EventHandler | None = None,
86
+ extra_env: dict[str, str] | None = None,
87
+ ) -> dict[str, Any]:
88
+ """Run a custom agent's manifest through the local ``claude`` CLI.
89
+
90
+ This does not reimplement any of ``run_claude_local``'s subprocess handling,
91
+ stream-json parsing, or crucial-hook logic -- it only assembles the prompt
92
+ and a working directory, then delegates.
93
+
94
+ ``skill_text`` is expected to already be the resolved skill body (see
95
+ ``sdk.agents.manifest.resolve_skill_text``), concatenated by the caller
96
+ where needed. To be safe, the final prompt is (re-)assembled here from
97
+ ``manifest.prompt`` plus, when ``skill_text`` is truthy, two newlines and
98
+ the skill body.
99
+ """
100
+ full_prompt = manifest.prompt
101
+ if skill_text:
102
+ full_prompt = f"{full_prompt}\n\n{skill_text}"
103
+
104
+ if project_path is None:
105
+ # Most custom agents (e.g. "summarise my PRs daily") have no real code
106
+ # workspace -- Claude Code still needs a valid current-working-directory
107
+ # to run in, so fall back to a per-agent scratch directory.
108
+ project_path = str(ensure_agent_workspace(manifest.name))
109
+
110
+ # mcp_config: accepted here for forward compatibility only. Wiring an
111
+ # --mcp-config flag into run_claude_local's subprocess command is a later
112
+ # follow-up, once run_claude_local itself grows an mcp_config parameter --
113
+ # this module does not attempt to work around that in the meantime, so the
114
+ # argument is currently unused.
115
+
116
+ return await run_claude_local(
117
+ prompt=full_prompt,
118
+ project_path=project_path,
119
+ allowed_tools=manifest.allowed_tools or None,
120
+ on_event=on_event,
121
+ extra_env=extra_env,
122
+ )
@@ -156,20 +156,29 @@ def _dotenv_value(key: str) -> str:
156
156
  _DEFAULT_ALLOWED_IPS: list[str] = ["20.12.201.148"]
157
157
 
158
158
 
159
- def _parse_ip_list(raw: str) -> list[str]:
160
- """Split an IP allowlist string, tolerant of JSON-ish list syntax.
159
+ def _parse_token_list(raw: str) -> list[str]:
160
+ """Split a comma/space-separated list, tolerant of JSON-ish syntax.
161
161
 
162
- Accepts ``"1.2.3.4, 5.6.7.8"``, ``1.2.3.4 5.6.7.8``, or ``["1.2.3.4","5.6.7.8"]``.
162
+ Accepts ``"a, b"``, ``a b``, or ``["a","b"]``. De-duplicates, order-preserving.
163
+ Used for every list-shaped setting (IP allowlist, tool allowlist).
163
164
  """
164
165
  raw = (raw or "").strip().strip("[]")
165
166
  out: list[str] = []
166
167
  for token in re.split(r"[,\s]+", raw):
167
- ip = token.strip().strip('"').strip("'")
168
- if ip and ip not in out:
169
- out.append(ip)
168
+ item = token.strip().strip('"').strip("'")
169
+ if item and item not in out:
170
+ out.append(item)
170
171
  return out
171
172
 
172
173
 
174
+ def _parse_ip_list(raw: str) -> list[str]:
175
+ """Split an IP allowlist string, tolerant of JSON-ish list syntax.
176
+
177
+ Accepts ``"1.2.3.4, 5.6.7.8"``, ``1.2.3.4 5.6.7.8``, or ``["1.2.3.4","5.6.7.8"]``.
178
+ """
179
+ return _parse_token_list(raw)
180
+
181
+
173
182
  def get_allowed_ips() -> list[str]:
174
183
  """Client IPs permitted to reach the ``agentos-ui`` API (``/api/ui/*``).
175
184
 
@@ -201,6 +210,55 @@ def get_allowed_ips() -> list[str]:
201
210
  return out
202
211
 
203
212
 
213
+ # Built-in baseline of tools a headless agent run may use. Kept here (not in
214
+ # local_exec) so it is one configurable setting rather than a literal buried in the
215
+ # spawn code: the set WILL grow, and a new tool must be addable without editing
216
+ # and re-releasing the SDK — see get_allowed_tools().
217
+ _DEFAULT_ALLOWED_TOOLS: list[str] = [
218
+ "Read", "Write", "Edit", "Glob", "Grep", "Bash", "Skill", "WebSearch", "WebFetch",
219
+ ]
220
+
221
+
222
+ def get_allowed_tools() -> list[str]:
223
+ """Tools a headless ``claude -p`` agent run is allowed to use.
224
+
225
+ A headless run cannot answer a permission prompt, so anything missing from
226
+ this list is silently UNAVAILABLE to the agent — which is how a research agent
227
+ ended up reporting it could not search the web. The baseline therefore covers
228
+ the file, shell, skill, and web tools, and everything else is configuration.
229
+
230
+ Sources, merged additively (all optional), each accepting a comma/space-separated
231
+ or bracketed list:
232
+ - the built-in baseline ``_DEFAULT_ALLOWED_TOOLS``
233
+ - ``.env`` key ``AGENTOS_ALLOWED_TOOLS`` (``~/.agentos/.env`` or CWD ``.env``)
234
+ - process env ``AGENTOS_ALLOWED_TOOLS``
235
+ - config.toml key ``allowed_tools``
236
+
237
+ Additive, like ``get_allowed_ips``: naming a tool ANYWHERE adds it, so granting
238
+ a newly-shipped Claude Code tool is a config line on the box, not a code change
239
+ and a release. Read at spawn time, so an edit applies to the next run without
240
+ restarting the daemon or the UI server. MCP/plugin tools are NOT listed here —
241
+ they are discovered per-machine at spawn time (see
242
+ ``local_exec._discover_mcp_allow_entries``).
243
+
244
+ To run with a REDUCED set, pass ``allowed_tools`` explicitly to
245
+ ``local_exec.run_claude_local`` (an agent manifest's ``allowed_tools`` does
246
+ exactly that) — that overrides this list rather than extending it.
247
+ """
248
+ sources = [
249
+ ",".join(_DEFAULT_ALLOWED_TOOLS),
250
+ _dotenv_value("AGENTOS_ALLOWED_TOOLS"),
251
+ os.environ.get("AGENTOS_ALLOWED_TOOLS", ""),
252
+ _load_raw().get("allowed_tools", ""),
253
+ ]
254
+ out: list[str] = []
255
+ for src in sources:
256
+ for tool in _parse_token_list(src):
257
+ if tool not in out:
258
+ out.append(tool)
259
+ return out
260
+
261
+
204
262
  class PermanentAllowlistEntry(ValueError):
205
263
  """Raised when trying to disable an IP that is permanently whitelisted via ``.env``."""
206
264
 
@@ -24,7 +24,7 @@ from dataclasses import dataclass, field
24
24
  from pathlib import Path
25
25
  from typing import Awaitable, Callable
26
26
 
27
- from sdk.local_exec import DEFAULT_ALLOWED_TOOLS, run_claude_local
27
+ from sdk.local_exec import run_claude_local
28
28
 
29
29
  from .bootstrap import ensure_agent_browser
30
30
  from .browser import BrowserError, diff_baseline, render_screenshot
@@ -67,9 +67,10 @@ async def _default_coder(project_path: str, correction_prompt: str) -> None:
67
67
  "unrelated code.\n\n"
68
68
  f"{correction_prompt}"
69
69
  )
70
- result = await run_claude_local(
71
- prompt, project_path, allowed_tools=DEFAULT_ALLOWED_TOOLS
72
- )
70
+ # allowed_tools omitted on purpose: run_claude_local then uses the configured
71
+ # allowlist (config.get_allowed_tools), so this run picks up any tool the box
72
+ # grants instead of a snapshot taken at import.
73
+ result = await run_claude_local(prompt, project_path)
73
74
  if not result.get("ok"):
74
75
  raise RuntimeError(f"correction run failed: {result.get('error')}")
75
76
 
@@ -28,15 +28,22 @@ from datetime import datetime, timedelta
28
28
  from pathlib import Path
29
29
  from typing import Any, Awaitable, Callable
30
30
 
31
- # Default tool allowlist. Bash is included so the agent runs ALL its commands
32
- # locally — git clone, install, build, test, and `gh pr create` for PRs — on the
33
- # user's machine, not the server. ``Skill`` lets the agent invoke installed
34
- # plugin/user Skills (e.g. the Figma skills), which DO load in headless ``-p`` runs
35
- # even when a plugin's MCP server can't authenticate there. MCP/plugin *tools* are
36
- # NOT hard-coded here — they are discovered per-machine and appended at spawn time;
37
- # see ``_discover_mcp_allow_entries`` / ``_local_mcp_servers`` and their use in
38
- # ``run_claude_local``.
39
- DEFAULT_ALLOWED_TOOLS = ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "Skill"]
31
+ from sdk import config # tool allowlist lives there (config.get_allowed_tools)
32
+
33
+ # The tool allowlist is a SETTING, not a literal here: see
34
+ # ``sdk.config.get_allowed_tools`` for the baseline and the ways to extend it
35
+ # (.env / process env ``AGENTOS_ALLOWED_TOOLS`` / config.toml ``allowed_tools``).
36
+ # It is read at spawn time inside ``run_claude_local`` so a change applies to the
37
+ # next run without a restart, and so granting a newly-shipped Claude Code tool
38
+ # never needs an SDK edit and release.
39
+ #
40
+ # Bash is in the baseline so the agent runs ALL its commands locally — git clone,
41
+ # install, build, test, and `gh pr create` for PRs — on the user's machine, not the
42
+ # server. ``Skill`` lets it invoke installed plugin/user Skills (e.g. the Figma
43
+ # skills), which DO load in headless ``-p`` runs even when a plugin's MCP server
44
+ # can't authenticate there. MCP/plugin *tools* are not configured there either —
45
+ # they are discovered per-machine and appended at spawn time; see
46
+ # ``_discover_mcp_allow_entries`` / ``_local_mcp_servers`` below.
40
47
 
41
48
  # Run limits. The OLD design capped TOTAL runtime at 30 min, which killed long
42
49
  # but healthy runs (big builds, many steps) mid-work. Instead we use an IDLE
@@ -445,7 +452,8 @@ async def run_claude_local(
445
452
  Spawns ``claude -p <prompt> --output-format stream-json …`` with the working
446
453
  directory set to the project so all edits land on the real local files.
447
454
  ``--permission-mode acceptEdits`` lets file edits apply unattended (no
448
- interactive prompt); read/write/edit are the only tools enabled by default.
455
+ interactive prompt). The tools enabled come from ``config.get_allowed_tools()``
456
+ unless ``allowed_tools`` is given, which replaces that list.
449
457
 
450
458
  ``on_event`` (optional, async) is called for each streamed JSON event — used
451
459
  by the sidecar to forward live progress (tool calls, assistant text) to the
@@ -477,7 +485,11 @@ async def run_claude_local(
477
485
  path = Path(project_path).expanduser()
478
486
  path.mkdir(parents=True, exist_ok=True)
479
487
 
480
- tools = list(allowed_tools or DEFAULT_ALLOWED_TOOLS)
488
+ # Read the allowlist per spawn (not at import) so a config/.env change takes
489
+ # effect on the next run — the UI server and agentd are long-lived processes.
490
+ # An explicit `allowed_tools` (e.g. a manifest's) REPLACES it, so an agent can
491
+ # still be restricted to fewer tools than the configured set.
492
+ tools = list(allowed_tools or config.get_allowed_tools())
481
493
  # Append per-server MCP allow-entries so installed+authenticated plugins/MCP
482
494
  # servers are usable in this headless run. Discovered once and cached; no-ops
483
495
  # (adds nothing) when no servers are configured or discovery fails, so a machine
@@ -0,0 +1,140 @@
1
+ """Every agent's run directory carries its own ``.claude/settings.json``.
2
+
3
+ ``~/.agentos/runs/<agent>`` IS a Claude Code project, so anything that reads
4
+ project settings there — a resumed session, a nested invocation, a hook — must see
5
+ the same tool grants the headless ``--allowedTools`` flag provides. Otherwise it
6
+ falls back to prompting in a place where nobody can answer, which is how a
7
+ research agent came to report that web access was "not granted".
8
+
9
+ Applies to custom and department agents alike: both are prompt-based backend rows
10
+ that run through the same engine.
11
+ """
12
+ from __future__ import annotations
13
+
14
+ import json
15
+
16
+ import pytest
17
+
18
+ from sdk import config
19
+ from sdk.agents.engines import claude_code
20
+
21
+
22
+ @pytest.fixture
23
+ def runs_dir(tmp_path, monkeypatch):
24
+ """Point AGENT_RUNS_DIR at a temp dir — never touch the real ~/.agentos."""
25
+ d = tmp_path / "runs"
26
+ monkeypatch.setattr(claude_code, "AGENT_RUNS_DIR", d)
27
+ return d
28
+
29
+
30
+ def _allow(path) -> list[str]:
31
+ return json.loads(path.read_text())["permissions"]["allow"]
32
+
33
+
34
+ class TestEnsureAgentWorkspace:
35
+ def test_creates_the_workspace_and_grants_configured_tools(self, runs_dir):
36
+ ws = claude_code.ensure_agent_workspace("AI Research Agent")
37
+ assert ws.is_dir()
38
+ settings = ws / ".claude" / "settings.json"
39
+ assert settings.exists()
40
+ allow = _allow(settings)
41
+ for tool in config.get_allowed_tools():
42
+ assert tool in allow
43
+ # The pair whose absence made research agents report "permission not granted".
44
+ assert "WebSearch" in allow and "WebFetch" in allow
45
+
46
+ def test_free_text_agent_names_are_handled(self, runs_dir):
47
+ """Web-app names carry spaces and '&' — the dir is named after the agent."""
48
+ ws = claude_code.ensure_agent_workspace("Jira & Confluence Project Management Agent")
49
+ assert (ws / ".claude" / "settings.json").exists()
50
+
51
+ def test_department_agent_gets_the_same_treatment(self, runs_dir):
52
+ ws = claude_code.ensure_agent_workspace("Model QA Specialist")
53
+ assert "WebSearch" in _allow(ws / ".claude" / "settings.json")
54
+
55
+ def test_rerun_preserves_hand_added_rules_and_other_keys(self, runs_dir):
56
+ ws = claude_code.ensure_agent_workspace("Agent One")
57
+ settings = ws / ".claude" / "settings.json"
58
+
59
+ data = json.loads(settings.read_text())
60
+ data["permissions"]["allow"].append("Bash(git *)")
61
+ data["env"] = {"MY_FLAG": "1"}
62
+ settings.write_text(json.dumps(data))
63
+
64
+ claude_code.ensure_agent_workspace("Agent One")
65
+ after = json.loads(settings.read_text())
66
+ assert "Bash(git *)" in after["permissions"]["allow"], "hand-added rule dropped"
67
+ assert after["env"] == {"MY_FLAG": "1"}, "unrelated key dropped"
68
+
69
+ def test_a_newly_configured_tool_appears_on_the_next_run(self, runs_dir, monkeypatch):
70
+ ws = claude_code.ensure_agent_workspace("Agent Two")
71
+ settings = ws / ".claude" / "settings.json"
72
+ assert "BrandNewTool" not in _allow(settings)
73
+
74
+ monkeypatch.setenv("AGENTOS_ALLOWED_TOOLS", "BrandNewTool")
75
+ claude_code.ensure_agent_workspace("Agent Two")
76
+ assert "BrandNewTool" in _allow(settings), "config change must reach the workspace"
77
+
78
+ def test_no_duplicate_entries_across_runs(self, runs_dir):
79
+ claude_code.ensure_agent_workspace("Agent Three")
80
+ ws = claude_code.ensure_agent_workspace("Agent Three")
81
+ allow = _allow(ws / ".claude" / "settings.json")
82
+ assert len(allow) == len(set(allow))
83
+
84
+ def test_corrupt_settings_file_is_replaced_not_inherited(self, runs_dir):
85
+ """Invalid JSON silently disables every setting in the file — rewrite it."""
86
+ ws = claude_code.ensure_agent_workspace("Agent Four")
87
+ settings = ws / ".claude" / "settings.json"
88
+ settings.write_text("{ not json at all")
89
+
90
+ claude_code.ensure_agent_workspace("Agent Four")
91
+ assert "WebSearch" in _allow(settings)
92
+
93
+ def test_unwritable_workspace_does_not_break_the_run(self, runs_dir, monkeypatch):
94
+ """The flag still grants the tools, so a settings write failure is survivable."""
95
+ def boom(*a, **kw):
96
+ raise OSError("read-only file system")
97
+
98
+ ws = claude_code.ensure_agent_workspace("Agent Five")
99
+ monkeypatch.setattr("pathlib.Path.write_text", boom)
100
+ assert claude_code.ensure_agent_workspace("Agent Five") == ws
101
+
102
+
103
+ class TestEngineUsesTheWorkspace:
104
+ @pytest.mark.asyncio
105
+ async def test_run_without_project_path_runs_in_the_prepared_workspace(
106
+ self, runs_dir, monkeypatch
107
+ ):
108
+ from types import SimpleNamespace
109
+
110
+ captured: dict = {}
111
+
112
+ async def fake_run(**kwargs):
113
+ captured.update(kwargs)
114
+ return {"ok": True}
115
+
116
+ monkeypatch.setattr(claude_code, "run_claude_local", fake_run)
117
+ manifest = SimpleNamespace(
118
+ name="AI Research Agent", prompt="do the thing", allowed_tools=[],
119
+ )
120
+ await claude_code.run(manifest, "", None)
121
+
122
+ assert captured["project_path"] == str(runs_dir / "AI Research Agent")
123
+ settings = runs_dir / "AI Research Agent" / ".claude" / "settings.json"
124
+ assert settings.exists(), "the engine must prepare the workspace before running"
125
+
126
+ @pytest.mark.asyncio
127
+ async def test_an_explicit_project_path_is_left_alone(self, runs_dir, monkeypatch, tmp_path):
128
+ """A real code checkout must NOT have a .claude/settings.json written into it."""
129
+ from types import SimpleNamespace
130
+
131
+ async def fake_run(**kwargs):
132
+ return {"ok": True}
133
+
134
+ monkeypatch.setattr(claude_code, "run_claude_local", fake_run)
135
+ repo = tmp_path / "some-repo"
136
+ repo.mkdir()
137
+ manifest = SimpleNamespace(name="Coder", prompt="fix it", allowed_tools=[])
138
+ await claude_code.run(manifest, "", None, project_path=str(repo))
139
+
140
+ assert not (repo / ".claude").exists(), "must not write into the user's repo"
@@ -0,0 +1,102 @@
1
+ """The headless-run tool allowlist is CONFIGURATION, not a literal in the spawn code.
2
+
3
+ A headless ``claude -p`` run cannot answer a permission prompt, so a tool absent
4
+ from ``--allowedTools`` is silently unavailable to the agent — that is how a
5
+ research agent came to report it could not search the web. The set will keep
6
+ growing as Claude Code ships tools, so granting one must be a config line on the
7
+ box, never an SDK edit and release.
8
+
9
+ Covers ``config.get_allowed_tools`` (baseline + the three additive sources) and
10
+ that ``local_exec.run_claude_local`` reads it AT SPAWN TIME, while an explicit
11
+ ``allowed_tools`` still narrows a single run.
12
+ """
13
+ from __future__ import annotations
14
+
15
+ from unittest.mock import AsyncMock, patch
16
+
17
+ import pytest
18
+
19
+ from sdk import config
20
+
21
+
22
+ class TestGetAllowedTools:
23
+ def test_baseline_covers_file_shell_skill_and_web_tools(self, monkeypatch):
24
+ monkeypatch.delenv("AGENTOS_ALLOWED_TOOLS", raising=False)
25
+ with patch.object(config, "_dotenv_value", return_value=""), \
26
+ patch.object(config, "_load_raw", return_value={}):
27
+ tools = config.get_allowed_tools()
28
+ for expected in ("Read", "Write", "Edit", "Glob", "Grep", "Bash", "Skill"):
29
+ assert expected in tools
30
+ # The pair whose absence broke every research-shaped agent.
31
+ assert "WebSearch" in tools and "WebFetch" in tools
32
+
33
+ def test_process_env_adds_without_restating_the_baseline(self, monkeypatch):
34
+ monkeypatch.setenv("AGENTOS_ALLOWED_TOOLS", "FutureTool, OtherTool")
35
+ with patch.object(config, "_dotenv_value", return_value=""), \
36
+ patch.object(config, "_load_raw", return_value={}):
37
+ tools = config.get_allowed_tools()
38
+ assert "FutureTool" in tools and "OtherTool" in tools
39
+ assert "Read" in tools, "extending must not drop the baseline"
40
+
41
+ def test_dotenv_and_config_toml_are_also_sources(self, monkeypatch):
42
+ monkeypatch.delenv("AGENTOS_ALLOWED_TOOLS", raising=False)
43
+ with patch.object(config, "_dotenv_value", return_value="DotEnvTool"), \
44
+ patch.object(config, "_load_raw", return_value={"allowed_tools": "TomlTool"}):
45
+ tools = config.get_allowed_tools()
46
+ assert "DotEnvTool" in tools and "TomlTool" in tools
47
+
48
+ def test_json_ish_and_space_separated_forms_parse(self, monkeypatch):
49
+ monkeypatch.setenv("AGENTOS_ALLOWED_TOOLS", '["A", "B"]')
50
+ with patch.object(config, "_dotenv_value", return_value="C D"), \
51
+ patch.object(config, "_load_raw", return_value={}):
52
+ tools = config.get_allowed_tools()
53
+ for t in ("A", "B", "C", "D"):
54
+ assert t in tools
55
+
56
+ def test_no_duplicates_when_a_source_repeats_the_baseline(self, monkeypatch):
57
+ monkeypatch.setenv("AGENTOS_ALLOWED_TOOLS", "Bash, Read")
58
+ with patch.object(config, "_dotenv_value", return_value=""), \
59
+ patch.object(config, "_load_raw", return_value={}):
60
+ tools = config.get_allowed_tools()
61
+ assert len(tools) == len(set(tools))
62
+
63
+
64
+ class TestRunClaudeLocalUsesTheSetting:
65
+ """The flags handed to the CLI must come from the setting, read per spawn."""
66
+
67
+ async def _spawned_cmd(self, **kwargs) -> list[str]:
68
+ from sdk import local_exec
69
+
70
+ proc = AsyncMock()
71
+ proc.returncode = 0
72
+ proc.stdout = None
73
+ proc.stderr = None
74
+ captured: dict = {}
75
+
76
+ async def fake_exec(*cmd, **kw):
77
+ captured["cmd"] = list(cmd)
78
+ raise RuntimeError("stop after spawn")
79
+
80
+ with patch.object(local_exec, "claude_cli_path", return_value="/usr/bin/claude"), \
81
+ patch("asyncio.create_subprocess_exec", new=fake_exec):
82
+ try:
83
+ await local_exec.run_claude_local(
84
+ prompt="hi", project_path="/tmp/agentos-test-run", **kwargs)
85
+ except Exception:
86
+ pass
87
+ return captured.get("cmd", [])
88
+
89
+ @pytest.mark.asyncio
90
+ async def test_configured_tools_reach_the_cli(self, monkeypatch):
91
+ monkeypatch.setenv("AGENTOS_ALLOWED_TOOLS", "BrandNewTool")
92
+ cmd = await self._spawned_cmd()
93
+ assert "--allowedTools" in cmd
94
+ assert "BrandNewTool" in cmd, "a configured tool must be granted with no code change"
95
+ assert "WebSearch" in cmd
96
+
97
+ @pytest.mark.asyncio
98
+ async def test_explicit_allowed_tools_narrows_a_single_run(self, monkeypatch):
99
+ monkeypatch.delenv("AGENTOS_ALLOWED_TOOLS", raising=False)
100
+ cmd = await self._spawned_cmd(allowed_tools=["Read"])
101
+ assert "Read" in cmd
102
+ assert "Bash" not in cmd, "an explicit list replaces the setting, not extends it"
@@ -1,61 +0,0 @@
1
- """claude_code engine -- a thin adapter from an agent manifest onto ``sdk.local_exec.run_claude_local``."""
2
- from __future__ import annotations
3
-
4
- from pathlib import Path
5
- from typing import TYPE_CHECKING, Any, Awaitable, Callable
6
-
7
- from sdk.local_exec import run_claude_local
8
-
9
- if TYPE_CHECKING:
10
- from sdk.agents.manifest import AgentManifest
11
-
12
- # Same shape as sdk.local_exec.EventHandler -- kept local so this module doesn't
13
- # need to reach into local_exec for a type alias.
14
- EventHandler = Callable[[dict], Awaitable[None]]
15
-
16
-
17
- async def run(
18
- manifest: "AgentManifest",
19
- skill_text: str,
20
- mcp_config: dict[str, Any] | None,
21
- project_path: str | None = None,
22
- on_event: EventHandler | None = None,
23
- extra_env: dict[str, str] | None = None,
24
- ) -> dict[str, Any]:
25
- """Run a custom agent's manifest through the local ``claude`` CLI.
26
-
27
- This does not reimplement any of ``run_claude_local``'s subprocess handling,
28
- stream-json parsing, or crucial-hook logic -- it only assembles the prompt
29
- and a working directory, then delegates.
30
-
31
- ``skill_text`` is expected to already be the resolved skill body (see
32
- ``sdk.agents.manifest.resolve_skill_text``), concatenated by the caller
33
- where needed. To be safe, the final prompt is (re-)assembled here from
34
- ``manifest.prompt`` plus, when ``skill_text`` is truthy, two newlines and
35
- the skill body.
36
- """
37
- full_prompt = manifest.prompt
38
- if skill_text:
39
- full_prompt = f"{full_prompt}\n\n{skill_text}"
40
-
41
- if project_path is None:
42
- # Most custom agents (e.g. "summarise my PRs daily") have no real code
43
- # workspace -- Claude Code still needs a valid current-working-directory
44
- # to run in, so fall back to a per-agent scratch directory.
45
- scratch = Path.home() / ".agentos" / "runs" / manifest.name
46
- scratch.mkdir(parents=True, exist_ok=True)
47
- project_path = str(scratch)
48
-
49
- # mcp_config: accepted here for forward compatibility only. Wiring an
50
- # --mcp-config flag into run_claude_local's subprocess command is a later
51
- # follow-up, once run_claude_local itself grows an mcp_config parameter --
52
- # this module does not attempt to work around that in the meantime, so the
53
- # argument is currently unused.
54
-
55
- return await run_claude_local(
56
- prompt=full_prompt,
57
- project_path=project_path,
58
- allowed_tools=manifest.allowed_tools or None,
59
- on_event=on_event,
60
- extra_env=extra_env,
61
- )
File without changes
File without changes