cacli 0.2.2__tar.gz → 0.2.4__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 (55) hide show
  1. {cacli-0.2.2/src/cacli.egg-info → cacli-0.2.4}/PKG-INFO +1 -1
  2. {cacli-0.2.2 → cacli-0.2.4}/pyproject.toml +1 -1
  3. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/cli.py +34 -0
  4. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/SKILL.md +6 -2
  5. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/engine.py +19 -0
  6. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/host.py +25 -0
  7. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/base.py +3 -0
  8. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/claude.py +19 -2
  9. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/pi.py +26 -3
  10. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/runner.py +39 -0
  11. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/spawn.py +3 -0
  12. cacli-0.2.4/src/cacli/tools.py +49 -0
  13. {cacli-0.2.2 → cacli-0.2.4/src/cacli.egg-info}/PKG-INFO +1 -1
  14. {cacli-0.2.2 → cacli-0.2.4}/src/cacli.egg-info/SOURCES.txt +1 -0
  15. {cacli-0.2.2 → cacli-0.2.4}/tests/test_flow.py +42 -0
  16. {cacli-0.2.2 → cacli-0.2.4}/tests/test_launch.py +152 -2
  17. {cacli-0.2.2 → cacli-0.2.4}/tests/test_pi_provider.py +42 -0
  18. {cacli-0.2.2 → cacli-0.2.4}/LICENSE +0 -0
  19. {cacli-0.2.2 → cacli-0.2.4}/README.md +0 -0
  20. {cacli-0.2.2 → cacli-0.2.4}/setup.cfg +0 -0
  21. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/__init__.py +0 -0
  22. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/devin_stream.py +0 -0
  23. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/__init__.py +0 -0
  24. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/aexec.py +0 -0
  25. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/cli.py +0 -0
  26. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/costs.py +0 -0
  27. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/journal.py +0 -0
  28. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/runs.py +0 -0
  29. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/sandbox.py +0 -0
  30. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/schema.py +0 -0
  31. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/flow/shim.py +0 -0
  32. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/__init__.py +0 -0
  33. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/codex.py +0 -0
  34. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/cursor.py +0 -0
  35. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/devin.py +0 -0
  36. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/harnesses/opencode.py +0 -0
  37. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/inference.py +0 -0
  38. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/server.py +0 -0
  39. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/sessions.py +0 -0
  40. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/status.py +0 -0
  41. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/transcript_apply.py +0 -0
  42. {cacli-0.2.2 → cacli-0.2.4}/src/cacli/types.py +0 -0
  43. {cacli-0.2.2 → cacli-0.2.4}/src/cacli.egg-info/dependency_links.txt +0 -0
  44. {cacli-0.2.2 → cacli-0.2.4}/src/cacli.egg-info/entry_points.txt +0 -0
  45. {cacli-0.2.2 → cacli-0.2.4}/src/cacli.egg-info/requires.txt +0 -0
  46. {cacli-0.2.2 → cacli-0.2.4}/src/cacli.egg-info/top_level.txt +0 -0
  47. {cacli-0.2.2 → cacli-0.2.4}/tests/test_claude_provider.py +0 -0
  48. {cacli-0.2.2 → cacli-0.2.4}/tests/test_codex_provider.py +0 -0
  49. {cacli-0.2.2 → cacli-0.2.4}/tests/test_cursor_provider.py +0 -0
  50. {cacli-0.2.2 → cacli-0.2.4}/tests/test_devin_provider.py +0 -0
  51. {cacli-0.2.2 → cacli-0.2.4}/tests/test_devin_stream.py +0 -0
  52. {cacli-0.2.2 → cacli-0.2.4}/tests/test_flow_resume.py +0 -0
  53. {cacli-0.2.2 → cacli-0.2.4}/tests/test_flow_schema.py +0 -0
  54. {cacli-0.2.2 → cacli-0.2.4}/tests/test_opencode_provider.py +0 -0
  55. {cacli-0.2.2 → cacli-0.2.4}/tests/test_transcript_apply.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cacli
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Harness and provider CLI for running coding agents
5
5
  Author: Benjamin Anderson
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cacli"
7
- version = "0.2.2"
7
+ version = "0.2.4"
8
8
  description = "Harness and provider CLI for running coding agents"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -61,6 +61,10 @@ def _normalize_argv(argv: list[str]) -> list[str]:
61
61
  return ["run", *argv]
62
62
 
63
63
 
64
+ def _tool_list(value: str) -> list[str]:
65
+ return [tool.strip() for tool in value.split(",")] if value.strip() else []
66
+
67
+
64
68
  def _add_common_args(parser: argparse.ArgumentParser) -> None:
65
69
  """Add arguments shared between run and spawn."""
66
70
  parser.add_argument("prompt", help="The task prompt")
@@ -105,6 +109,30 @@ def _add_common_args(parser: argparse.ArgumentParser) -> None:
105
109
  "restores unsandboxed execution."
106
110
  ),
107
111
  )
112
+ parser.add_argument(
113
+ "--extension",
114
+ dest="extensions",
115
+ action="append",
116
+ default=[],
117
+ help="Pi extension path, passed as -e (repeatable; pi only)",
118
+ )
119
+ parser.add_argument(
120
+ "--tools",
121
+ type=_tool_list,
122
+ default=None,
123
+ help=(
124
+ "Comma-separated tool names: an exact set (read,grep), or "
125
+ "-name removals from the defaults (--tools=-write); "
126
+ '"" disables all tools (pi and claude only)'
127
+ ),
128
+ )
129
+ parser.add_argument(
130
+ "--no-trust-project",
131
+ dest="trust_project",
132
+ action="store_false",
133
+ default=True,
134
+ help="Ignore project-local Pi settings and extensions (--no-approve; pi only)",
135
+ )
108
136
  parser.add_argument("--cwd", default=".", help="Working directory")
109
137
  parser.add_argument(
110
138
  "--timeout", "-t", type=int, default=3600, help="Timeout in seconds"
@@ -123,6 +151,9 @@ def _run_command(args) -> None:
123
151
  web_search=args.web_search,
124
152
  settings=args.settings,
125
153
  sandbox=args.sandbox,
154
+ extensions=args.extensions,
155
+ trust_project=args.trust_project,
156
+ tools=args.tools,
126
157
  )
127
158
  if args.command_only:
128
159
  print(launch.command)
@@ -142,6 +173,9 @@ def _run_command(args) -> None:
142
173
  sandbox=args.sandbox,
143
174
  cwd=args.cwd,
144
175
  timeout=args.timeout,
176
+ extensions=args.extensions,
177
+ trust_project=args.trust_project,
178
+ tools=args.tools,
145
179
  )
146
180
 
147
181
  if args.raw:
@@ -108,6 +108,9 @@ All arguments after `prompt` are keyword-only.
108
108
  | `sandbox` | None | `True` = force OS sandbox, `False` = force off, `None` = harness default (codex/devin default sandboxed; claude/cursor use their own CLI defaults) |
109
109
  | `web_search` | True | allow the agent to search the web |
110
110
  | `env` | None | extra env vars (dict of str→str) |
111
+ | `extensions` | None | pi only: list of extension paths, each passed as `-e` |
112
+ | `trust_project` | True | pi only: `False` passes `--no-approve`, ignoring project-local `.pi/` settings and extensions |
113
+ | `tools` | None | pi and claude: the harness's tool names, either an exact set (`["read", "bash", "codemode"]`, `[]` for none) or `-name` removals from its defaults (`["-write"]`) |
111
114
 
112
115
  **Returns `None` on terminal failure** (after retries) — never raises for
113
116
  agent failure. Fan-outs degrade instead of exploding; filter with
@@ -207,8 +210,9 @@ the previous run's journal (instant, no re-execution — though replayed costs
207
210
  still count against the resumed run's budget), then goes live at the first
208
211
  call whose identity differs. Identity includes prompt/harness/provider/model/effort/
209
212
  schema/cwd plus the execution options `web_search`, `settings`, `sandbox`,
210
- `env`, `retries`, `schema_retries`, `timeout`, and `stall_timeout`. `label` and
211
- `phase` are display-only and deliberately excluded from resume identity.
213
+ `env`, `retries`, `schema_retries`, `timeout`, and `stall_timeout` (and
214
+ `extensions`/`trust_project`/`tools` when set). `label` and `phase` are
215
+ display-only and deliberately excluded from resume identity.
212
216
  Resuming with an edited script or different `--args` is the intended
213
217
  iteration workflow: fix a later stage, keep earlier results cached. Cached
214
218
  terminal failures (`None`) replay as `None`. Budget-exceeded runs resume with
@@ -210,6 +210,9 @@ class FlowEngine:
210
210
  settings: str | None,
211
211
  sandbox: bool | None,
212
212
  env: dict[str, str] | None,
213
+ extensions: tuple[str, ...] = (),
214
+ trust_project: bool = True,
215
+ tools: tuple[str, ...] | None = None,
213
216
  ) -> Any | None:
214
217
  if self.cancel_event.is_set():
215
218
  raise RuntimeError("FlowCancelled: workflow cancelled")
@@ -219,14 +222,27 @@ class FlowEngine:
219
222
  provider=provider_name,
220
223
  model=model,
221
224
  params=provider_params(env),
225
+ extensions=extensions,
226
+ trust_project=trust_project,
227
+ tools=tools,
222
228
  )
223
229
  adapter = get_harness(harness_name)
224
230
  if self.exec_fn is aexec:
225
231
  check_credentials(launch, env)
226
232
  provider_name = launch.provider
227
233
  resolved_model = launch.model
234
+ # Optional launch options join the identity only when set, so resume
235
+ # keys of runs recorded before these options existed stay valid.
236
+ launch_options: dict[str, Any] = {}
237
+ if extensions:
238
+ launch_options["extensions"] = list(extensions)
239
+ if not trust_project:
240
+ launch_options["trust_project"] = False
241
+ if tools is not None:
242
+ launch_options["tools"] = list(tools)
228
243
  index, key, cached, respawning = await self._assign_call(
229
244
  {
245
+ **launch_options,
230
246
  "prompt": prompt,
231
247
  "harness": harness_name,
232
248
  "provider": provider_name,
@@ -377,6 +393,9 @@ class FlowEngine:
377
393
  settings=settings,
378
394
  sandbox=sandbox,
379
395
  output_schema=output_schema,
396
+ extensions=extensions,
397
+ trust_project=trust_project,
398
+ tools=tools,
380
399
  )
381
400
  exec_result = await self.exec_fn(
382
401
  attempt_launch.command,
@@ -120,6 +120,9 @@ class FlowHost:
120
120
  settings: Any = None,
121
121
  sandbox: Any = None,
122
122
  env: Any = None,
123
+ extensions: Any = None,
124
+ trust_project: Any = True,
125
+ tools: Any = None,
123
126
  ) -> Any | None:
124
127
  if self.engine.cancel_event.is_set():
125
128
  raise RuntimeError("FlowCancelled: workflow cancelled")
@@ -184,6 +187,25 @@ class FlowHost:
184
187
  raise TypeError("web_search must be a boolean")
185
188
  if sandbox is not None and not isinstance(sandbox, bool):
186
189
  raise TypeError("sandbox must be a boolean or null")
190
+ if extensions is None:
191
+ extensions = []
192
+ if not isinstance(extensions, list) or not all(
193
+ isinstance(extension, str) and extension for extension in extensions
194
+ ):
195
+ raise TypeError("extensions must be a list of non-empty strings")
196
+ if len(extensions) > 20 or any(
197
+ len(extension) > 4096 for extension in extensions
198
+ ):
199
+ raise ValueError("extensions has too many or too long entries")
200
+ if not isinstance(trust_project, bool):
201
+ raise TypeError("trust_project must be a boolean")
202
+ if tools is not None:
203
+ if not isinstance(tools, list) or not all(
204
+ isinstance(tool, str) for tool in tools
205
+ ):
206
+ raise TypeError("tools must be a list of tool names or null")
207
+ if len(tools) > 100 or any(len(tool) > 200 for tool in tools):
208
+ raise ValueError("tools has too many or too long entries")
187
209
  if env is not None:
188
210
  if not isinstance(env, dict) or not all(
189
211
  isinstance(key, str) and isinstance(value, str)
@@ -222,4 +244,7 @@ class FlowHost:
222
244
  settings=settings,
223
245
  sandbox=sandbox,
224
246
  env=env,
247
+ extensions=tuple(extensions),
248
+ trust_project=trust_project,
249
+ tools=None if tools is None else tuple(tools),
225
250
  )
@@ -26,6 +26,9 @@ class Pairing:
26
26
  class BaseHarness(ABC):
27
27
  name: str
28
28
  pairings: tuple[Pairing, ...]
29
+ # Optional launch options (beyond the common ones) this harness accepts as
30
+ # keyword arguments to build_command and build_pr_description_command.
31
+ launch_options: frozenset[str] = frozenset()
29
32
 
30
33
  def pairing(self, provider: str | None) -> Pairing:
31
34
  selected = provider or self.pairings[0].provider
@@ -6,6 +6,7 @@ import shlex
6
6
  from pathlib import Path
7
7
  from typing import Sequence
8
8
 
9
+ from cacli.tools import ToolSelection
9
10
  from cacli.harnesses.base import BaseHarness, Pairing
10
11
  from cacli.types import AgentRunResult
11
12
 
@@ -62,10 +63,24 @@ def _settings_args(settings: str | None, sandbox: bool | None) -> str:
62
63
  return f" --settings {shlex.quote(encoded)}"
63
64
 
64
65
 
66
+ def _tool_args(tools: ToolSelection | None, *, web_search: bool = True) -> str:
67
+ """`--tools` selects among Claude's built-in tools; MCP and plugin tools stay on."""
68
+ args = ""
69
+ if tools is not None and tools.only is not None:
70
+ args += f" --tools {shlex.quote(','.join(tools.only))}"
71
+ disallowed = [*(tools.remove if tools else ())]
72
+ if not web_search:
73
+ disallowed += ["WebFetch", "WebSearch"]
74
+ for tool in dict.fromkeys(disallowed):
75
+ args += f" --disallowedTools {shlex.quote(tool)}"
76
+ return args
77
+
78
+
65
79
  class ClaudeHarness(BaseHarness):
66
80
  """Harness for the Claude Code CLI."""
67
81
 
68
82
  name = "claude"
83
+ launch_options = frozenset({"tools"})
69
84
  pairings = (
70
85
  Pairing(
71
86
  "claude-sub",
@@ -113,6 +128,7 @@ class ClaudeHarness(BaseHarness):
113
128
  sandbox: bool | None = None,
114
129
  output_schema: dict | Path | None = None,
115
130
  exec_prefix: Sequence[str] = (),
131
+ tools: ToolSelection | None = None,
116
132
  ) -> str:
117
133
  safe_prompt = shlex.quote(prompt)
118
134
  cmd = f"{self.command_head('claude', exec_prefix)} -p {safe_prompt} --verbose --output-format=stream-json"
@@ -126,8 +142,7 @@ class ClaudeHarness(BaseHarness):
126
142
  cmd += _settings_args(settings, sandbox)
127
143
  if output_schema is not None:
128
144
  cmd += f" --json-schema {shlex.quote(json.dumps(output_schema, sort_keys=True, separators=(',', ':')))}"
129
- if not web_search:
130
- cmd += " --disallowedTools WebFetch --disallowedTools WebSearch"
145
+ cmd += _tool_args(tools, web_search=web_search)
131
146
  return cmd
132
147
 
133
148
  def parse_output(self, raw_output: str) -> AgentRunResult:
@@ -181,12 +196,14 @@ class ClaudeHarness(BaseHarness):
181
196
  settings: str | None = None,
182
197
  sandbox: bool | None = None,
183
198
  exec_prefix: Sequence[str] = (),
199
+ tools: ToolSelection | None = None,
184
200
  ) -> str:
185
201
  safe_prompt = shlex.quote(prompt)
186
202
  cmd = f"{self.command_head('claude', exec_prefix)} -p {safe_prompt} --verbose --output-format json"
187
203
  if model:
188
204
  cmd += f" --model {shlex.quote(model)}"
189
205
  cmd += _settings_args(settings, sandbox)
206
+ cmd += _tool_args(tools)
190
207
  return cmd
191
208
 
192
209
  def extract_result_from_json(self, raw_output: str) -> str:
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
  from typing import Any, Sequence
7
7
 
8
8
  from cacli.harnesses.base import BaseHarness, Pairing
9
+ from cacli.tools import ToolSelection
9
10
  from cacli.types import AgentRunResult
10
11
 
11
12
 
@@ -42,10 +43,20 @@ def _message_cost(message: object) -> float | None:
42
43
  return float(total)
43
44
 
44
45
 
46
+ def _tool_args(tools: ToolSelection | None) -> list[str]:
47
+ # `--tools` is an allowlist over every tool, extension tools included.
48
+ if tools is None:
49
+ return []
50
+ if tools.only is None:
51
+ return ["--exclude-tools", ",".join(tools.remove)]
52
+ return ["--tools", ",".join(tools.only)] if tools.only else ["--no-tools"]
53
+
54
+
45
55
  class PiHarness(BaseHarness):
46
56
  """Harness for the Pi coding-agent CLI."""
47
57
 
48
58
  name = "pi"
59
+ launch_options = frozenset({"extensions", "trust_project", "tools"})
49
60
  pairings = (
50
61
  Pairing(
51
62
  "workers-ai",
@@ -70,6 +81,9 @@ class PiHarness(BaseHarness):
70
81
  sandbox: bool | None = None,
71
82
  output_schema: dict | Path | None = None,
72
83
  exec_prefix: Sequence[str] = (),
84
+ extensions: Sequence[str] = (),
85
+ trust_project: bool = True,
86
+ tools: ToolSelection | None = None,
73
87
  ) -> str:
74
88
  if sandbox:
75
89
  raise NotImplementedError(
@@ -79,8 +93,6 @@ class PiHarness(BaseHarness):
79
93
  if settings is not None:
80
94
  raise ValueError("harness 'pi' does not support a settings argument")
81
95
 
82
- # cacli runs Pi in externally isolated environments. Trust the project
83
- # so Pi loads repository-local instructions, settings, and resources.
84
96
  parts = [
85
97
  *exec_prefix,
86
98
  "pi",
@@ -88,8 +100,13 @@ class PiHarness(BaseHarness):
88
100
  "json",
89
101
  "--print",
90
102
  "--no-session",
91
- "--approve",
92
103
  ]
104
+ # cacli runs Pi in externally isolated environments, so by default it
105
+ # trusts the project and loads repository-local settings and resources.
106
+ parts.append("--approve" if trust_project else "--no-approve")
107
+ for extension in extensions:
108
+ parts.extend(["-e", extension])
109
+ parts.extend(_tool_args(tools))
93
110
  if model:
94
111
  parts.extend(["--model", model])
95
112
  if reasoning_effort and reasoning_effort != "auto":
@@ -158,6 +175,9 @@ class PiHarness(BaseHarness):
158
175
  settings: str | None = None,
159
176
  sandbox: bool | None = None,
160
177
  exec_prefix: Sequence[str] = (),
178
+ extensions: Sequence[str] = (),
179
+ trust_project: bool = True,
180
+ tools: ToolSelection | None = None,
161
181
  ) -> str:
162
182
  return self.build_command(
163
183
  prompt=prompt,
@@ -165,6 +185,9 @@ class PiHarness(BaseHarness):
165
185
  settings=settings,
166
186
  sandbox=sandbox,
167
187
  exec_prefix=exec_prefix,
188
+ extensions=extensions,
189
+ trust_project=trust_project,
190
+ tools=tools,
168
191
  )
169
192
 
170
193
  def extract_result_from_json(self, raw_output: str) -> str:
@@ -3,9 +3,11 @@
3
3
  import os
4
4
  from dataclasses import dataclass
5
5
  from pathlib import Path
6
+ from typing import Sequence
6
7
 
7
8
  from cacli.harnesses import get_harness
8
9
  from cacli.inference import Credential, PROVIDERS
10
+ from cacli.tools import parse_tools
9
11
  from cacli.types import AgentRunResult, ExecResult, ShellExecFn
10
12
 
11
13
 
@@ -33,8 +35,25 @@ def _build_launch(
33
35
  sandbox: bool | None = None,
34
36
  output_schema: dict | Path | None = None,
35
37
  pr_description: bool = False,
38
+ extensions: Sequence[str] = (),
39
+ trust_project: bool = True,
40
+ tools: Sequence[str] | None = None,
36
41
  ) -> LaunchSpec:
37
42
  adapter = get_harness(harness)
43
+ # Only options that differ from their defaults reach the harness, so a
44
+ # harness that lacks one still accepts launches that don't use it.
45
+ options: dict = {}
46
+ if extensions:
47
+ options["extensions"] = tuple(extensions)
48
+ if not trust_project:
49
+ options["trust_project"] = False
50
+ if tools is not None:
51
+ options["tools"] = parse_tools(tools)
52
+ unsupported = sorted(set(options) - adapter.launch_options)
53
+ if unsupported:
54
+ raise ValueError(
55
+ f"Harness {harness!r} does not support launch option(s): {', '.join(unsupported)}"
56
+ )
38
57
  pair = adapter.pairing(provider)
39
58
  catalog = PROVIDERS[pair.provider]
40
59
  supplied = dict(params or {})
@@ -67,6 +86,7 @@ def _build_launch(
67
86
  settings=settings,
68
87
  sandbox=sandbox,
69
88
  exec_prefix=exec_prefix,
89
+ **options,
70
90
  )
71
91
  else:
72
92
  command = adapter.build_command(
@@ -78,6 +98,7 @@ def _build_launch(
78
98
  sandbox=sandbox,
79
99
  output_schema=output_schema,
80
100
  exec_prefix=exec_prefix,
101
+ **options,
81
102
  )
82
103
  command = adapter.configure_command(pair, command, supplied)
83
104
  credentials = tuple(
@@ -108,6 +129,9 @@ def build_launch(
108
129
  settings: str | None = None,
109
130
  sandbox: bool | None = None,
110
131
  output_schema: dict | Path | None = None,
132
+ extensions: Sequence[str] = (),
133
+ trust_project: bool = True,
134
+ tools: Sequence[str] | None = None,
111
135
  ) -> LaunchSpec:
112
136
  return _build_launch(
113
137
  harness,
@@ -120,6 +144,9 @@ def build_launch(
120
144
  settings=settings,
121
145
  sandbox=sandbox,
122
146
  output_schema=output_schema,
147
+ extensions=extensions,
148
+ trust_project=trust_project,
149
+ tools=tools,
123
150
  )
124
151
 
125
152
 
@@ -132,6 +159,9 @@ def build_pr_description_command(
132
159
  params: dict[str, str] | None = None,
133
160
  settings: str | None = None,
134
161
  sandbox: bool | None = None,
162
+ extensions: Sequence[str] = (),
163
+ trust_project: bool = True,
164
+ tools: Sequence[str] | None = None,
135
165
  ) -> str:
136
166
  """Build a PR description invocation with the same provider selection."""
137
167
  launch = _build_launch(
@@ -142,6 +172,9 @@ def build_pr_description_command(
142
172
  params=params,
143
173
  settings=settings,
144
174
  sandbox=sandbox,
175
+ extensions=extensions,
176
+ trust_project=trust_project,
177
+ tools=tools,
145
178
  pr_description=True,
146
179
  )
147
180
  return launch.command
@@ -184,6 +217,9 @@ def run_agent(
184
217
  cwd: str = ".",
185
218
  timeout: int = 3600,
186
219
  env: dict[str, str] | None = None,
220
+ extensions: Sequence[str] = (),
221
+ trust_project: bool = True,
222
+ tools: Sequence[str] | None = None,
187
223
  ) -> AgentRunResult:
188
224
  launch = build_launch(
189
225
  harness,
@@ -196,6 +232,9 @@ def run_agent(
196
232
  settings=settings,
197
233
  sandbox=sandbox,
198
234
  output_schema=output_schema,
235
+ extensions=extensions,
236
+ trust_project=trust_project,
237
+ tools=tools,
199
238
  )
200
239
  exec_result: ExecResult = exec_fn(launch.command, cwd, timeout, env)
201
240
  result = get_harness(harness).parse_output(exec_result.stdout)
@@ -47,6 +47,9 @@ def spawn_agent(args) -> None:
47
47
  web_search=getattr(args, "web_search", True),
48
48
  settings=getattr(args, "settings", None),
49
49
  sandbox=getattr(args, "sandbox", None),
50
+ extensions=getattr(args, "extensions", ()),
51
+ trust_project=getattr(args, "trust_project", True),
52
+ tools=getattr(args, "tools", None),
50
53
  )
51
54
 
52
55
  check_credentials(launch)
@@ -0,0 +1,49 @@
1
+ """Harness-neutral tool selection for agent launches.
2
+
3
+ ``tools`` is a list of the harness's own tool names, in one of two forms:
4
+
5
+ - plain names (``["read", "grep"]``): exactly these tools. On Pi every other
6
+ tool is off, extension tools included; on Claude this selects from its
7
+ built-in tools, and MCP and plugin tools stay available. An empty list turns
8
+ all tools off on Pi and all built-in tools off on Claude.
9
+ - ``-name`` entries (``["-write"]``): the harness's defaults minus these.
10
+
11
+ The forms can't be mixed. ``None`` keeps the harness defaults. There is no
12
+ ``+name``: Pi can only add a tool by restating the whole selection, which
13
+ silently drops extension tools and ignores its ``defaultTools`` setting, and
14
+ Claude already starts with every built-in tool. List the exact set instead.
15
+ """
16
+
17
+ from dataclasses import dataclass
18
+ from typing import Sequence
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class ToolSelection:
23
+ # The exact tool set, or None when removing from the defaults.
24
+ only: tuple[str, ...] | None
25
+ remove: tuple[str, ...] = ()
26
+
27
+
28
+ def parse_tools(entries: Sequence[str]) -> ToolSelection:
29
+ if isinstance(entries, str):
30
+ raise TypeError("tools must be a list of tool names, not a string")
31
+ names = [entry.strip() for entry in entries]
32
+ if any(not name or name in ("+", "-") or "," in name for name in names):
33
+ raise ValueError(f"Invalid tools entry in {list(entries)!r}")
34
+ if any(name.startswith("+") for name in names):
35
+ raise ValueError(
36
+ "tools can't add to the defaults with +name; list the exact set of "
37
+ "tools instead (for Pi, e.g. read,bash,edit,write,codemode)"
38
+ )
39
+ removals = [name for name in names if name.startswith("-")]
40
+ if removals and len(removals) != len(names):
41
+ raise ValueError(
42
+ "tools entries must be all plain names (an exact set) or all "
43
+ "-name removals from the defaults, not a mix"
44
+ )
45
+ if not removals:
46
+ return ToolSelection(only=tuple(dict.fromkeys(names)))
47
+ return ToolSelection(
48
+ only=None, remove=tuple(dict.fromkeys(name[1:] for name in removals))
49
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cacli
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Harness and provider CLI for running coding agents
5
5
  Author: Benjamin Anderson
6
6
  License-Expression: MIT
@@ -10,6 +10,7 @@ src/cacli/server.py
10
10
  src/cacli/sessions.py
11
11
  src/cacli/spawn.py
12
12
  src/cacli/status.py
13
+ src/cacli/tools.py
13
14
  src/cacli/transcript_apply.py
14
15
  src/cacli/types.py
15
16
  src/cacli.egg-info/PKG-INFO
@@ -690,3 +690,45 @@ def test_flow_journal_records_harness_and_provider(tmp_path, fake_provider):
690
690
  entry["harness"] == "fake" and entry["provider"] == "openai-api"
691
691
  for entry in entries
692
692
  )
693
+
694
+
695
+ def test_pi_flow_agent_passes_extensions_and_project_trust(tmp_path):
696
+ commands = []
697
+
698
+ async def pi_exec(command, *args, **kwargs):
699
+ commands.append(command)
700
+ message = {
701
+ "role": "assistant",
702
+ "content": [{"type": "text", "text": "done"}],
703
+ "stopReason": "stop",
704
+ }
705
+ return AsyncExecResult(
706
+ 0, json.dumps({"type": "message_end", "message": message})
707
+ )
708
+
709
+ source = (
710
+ "async def main():\n"
711
+ ' return await agent("test", harness="pi", provider="claude-api",\n'
712
+ ' extensions=["/opt/guardian.ts"], trust_project=False, tools=["read", "codemode"])\n'
713
+ )
714
+ outcome = run(
715
+ run_flow(
716
+ write_flow(tmp_path, source),
717
+ runs_root=tmp_path / "runs",
718
+ engine_options={"exec_fn": pi_exec},
719
+ )
720
+ )
721
+ assert outcome.result == "done"
722
+ parts = shlex.split(commands[0])
723
+ assert "--no-approve" in parts and "--approve" not in parts
724
+ assert parts[parts.index("-e") + 1] == "/opt/guardian.ts"
725
+ assert parts[parts.index("--tools") + 1] == "read,codemode"
726
+
727
+
728
+ def test_flow_agent_rejects_invalid_extensions(tmp_path):
729
+ source = (
730
+ "async def main():\n"
731
+ ' return await agent("test", harness="pi", extensions="/opt/guardian.ts")\n'
732
+ )
733
+ with pytest.raises(Exception, match="extensions must be a list"):
734
+ run(run_flow(write_flow(tmp_path, source), runs_root=tmp_path / "runs"))
@@ -1,12 +1,13 @@
1
1
  """Harness/provider pairings and non-secret launch plans."""
2
2
 
3
3
  import shlex
4
+ import sys
4
5
  from dataclasses import asdict
5
6
 
6
7
  import pytest
7
8
 
8
- from cacli import build_launch, get_harness, list_harnesses
9
- from cacli.cli import check_credentials
9
+ from cacli import ExecResult, build_launch, get_harness, list_harnesses, run_agent
10
+ from cacli.cli import check_credentials, main
10
11
  from cacli.inference import PROVIDERS, provider_params
11
12
 
12
13
 
@@ -153,6 +154,88 @@ def test_pr_description_uses_pairing_and_env_prefix():
153
154
  assert "model_providers.openai_api.wire_api=responses" in codex
154
155
 
155
156
 
157
+ def test_pi_launch_options_and_non_pi_rejection():
158
+ from cacli import build_launch
159
+
160
+ launch = build_launch(
161
+ "pi",
162
+ "hello",
163
+ params={"account_id": "account"},
164
+ extensions=("/tmp/guardian extension.ts", "/tmp/extra.ts"),
165
+ trust_project=False,
166
+ )
167
+ assert "--no-approve -e '" in launch.command
168
+ assert "-e '/tmp/guardian extension.ts' -e /tmp/extra.ts" in launch.command
169
+ with pytest.raises(ValueError, match="does not support launch option.*extensions"):
170
+ build_launch("codex", "hello", extensions=("extension.ts",))
171
+ with pytest.raises(
172
+ ValueError, match="does not support launch option.*trust_project"
173
+ ):
174
+ build_launch("codex", "hello", trust_project=False)
175
+ with pytest.raises(ValueError, match="does not support launch option.*extensions"):
176
+ build_launch("claude", "hello", provider="claude-api", extensions=("x.ts",))
177
+
178
+
179
+ @pytest.mark.parametrize(
180
+ ("tools", "expected"),
181
+ [
182
+ (["read", "grep"], ["--tools", "read,grep"]),
183
+ ([], ["--no-tools"]),
184
+ (["read", "bash", "codemode"], ["--tools", "read,bash,codemode"]),
185
+ (["-bash"], ["--exclude-tools", "bash"]),
186
+ ],
187
+ )
188
+ def test_pi_tool_selection(tools, expected):
189
+ command = build_launch(
190
+ "pi", "hello", params={"account_id": "account"}, tools=tools
191
+ ).command
192
+ parts = shlex.split(command)
193
+ flag = expected[0]
194
+ assert parts[parts.index(flag) : parts.index(flag) + len(expected)] == expected
195
+
196
+
197
+ @pytest.mark.parametrize(
198
+ ("tools", "web_search", "fragment", "absent"),
199
+ [
200
+ (["Read", "Bash"], True, "--tools Read,Bash", "--disallowedTools"),
201
+ ([], True, "--tools ''", "--disallowedTools"),
202
+ (
203
+ ["-Bash"],
204
+ False,
205
+ "--disallowedTools Bash --disallowedTools WebFetch --disallowedTools WebSearch",
206
+ "--tools",
207
+ ),
208
+ ],
209
+ )
210
+ def test_claude_tool_selection(tools, web_search, fragment, absent):
211
+ command = build_launch(
212
+ "claude", "hello", provider="claude-api", tools=tools, web_search=web_search
213
+ ).command
214
+ assert fragment in command
215
+ assert absent not in command
216
+
217
+
218
+ def test_tool_selection_defaults_and_errors():
219
+ assert build_launch("claude", "hi", provider="claude-api").command == (
220
+ build_launch("claude", "hi", provider="claude-api", tools=None).command
221
+ )
222
+ assert "--disallowedTools WebFetch --disallowedTools WebSearch" in (
223
+ build_launch("claude", "hi", provider="claude-api", web_search=False).command
224
+ )
225
+ with pytest.raises(ValueError, match="not a mix"):
226
+ build_launch("pi", "hi", params={"account_id": "a"}, tools=["read", "-bash"])
227
+ with pytest.raises(ValueError, match="list the exact set"):
228
+ build_launch("pi", "hi", params={"account_id": "a"}, tools=["+codemode"])
229
+ with pytest.raises(ValueError, match="list the exact set"):
230
+ build_launch("claude", "hi", provider="claude-api", tools=["+Foo"])
231
+ with pytest.raises(ValueError, match="Invalid tools entry"):
232
+ build_launch("pi", "hi", params={"account_id": "a"}, tools=["read,grep"])
233
+ with pytest.raises(TypeError, match="not a string"):
234
+ build_launch("pi", "hi", params={"account_id": "a"}, tools="read")
235
+ with pytest.raises(ValueError, match="does not support launch option.*tools"):
236
+ build_launch("codex", "hi", tools=["shell"])
237
+
238
+
156
239
  def test_cli_rejects_missing_credential_without_printing_value(monkeypatch, capsys):
157
240
  import sys
158
241
  from cacli.cli import main
@@ -282,3 +365,70 @@ def test_provider_params_reads_every_param(monkeypatch):
282
365
  "account_id": "",
283
366
  "azure_host": "https://res.openai.azure.com/",
284
367
  }
368
+
369
+
370
+ def test_cli_and_run_agent_pass_pi_launch_options(monkeypatch, capsys):
371
+ monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", "account")
372
+ monkeypatch.setattr(
373
+ sys,
374
+ "argv",
375
+ [
376
+ "cacli",
377
+ "run",
378
+ "hello",
379
+ "--harness",
380
+ "pi",
381
+ "--extension",
382
+ "/opt/a.ts",
383
+ "--extension",
384
+ "/opt/b.ts",
385
+ "--no-trust-project",
386
+ "--command-only",
387
+ ],
388
+ )
389
+ main()
390
+ parts = shlex.split(capsys.readouterr().out)
391
+ assert "--no-approve" in parts and "--approve" not in parts
392
+ assert [parts[i + 1] for i, part in enumerate(parts) if part == "-e"] == [
393
+ "/opt/a.ts",
394
+ "/opt/b.ts",
395
+ ]
396
+
397
+ seen = []
398
+
399
+ def fake_exec(command, cwd, timeout, env):
400
+ seen.append(command)
401
+ return ExecResult(0, "", "")
402
+
403
+ run_agent(
404
+ "pi",
405
+ "hello",
406
+ fake_exec,
407
+ params={"account_id": "account"},
408
+ extensions=("/opt/a.ts",),
409
+ trust_project=False,
410
+ )
411
+ assert "--no-approve -e /opt/a.ts" in seen[0]
412
+
413
+ monkeypatch.setattr(
414
+ sys,
415
+ "argv",
416
+ [
417
+ "cacli",
418
+ "run",
419
+ "hello",
420
+ "--harness",
421
+ "pi",
422
+ "--tools=read,bash,codemode",
423
+ "--command-only",
424
+ ],
425
+ )
426
+ main()
427
+ assert "--tools read,bash,codemode" in capsys.readouterr().out
428
+ monkeypatch.setattr(
429
+ sys,
430
+ "argv",
431
+ ["cacli", "run", "hello", "--harness", "pi", "--tools", "", "--command-only"],
432
+ )
433
+ main()
434
+ assert "--no-tools" in capsys.readouterr().out
@@ -78,6 +78,48 @@ def test_build_command_omits_optional_model_and_auto_thinking():
78
78
  assert "--thinking" not in parts
79
79
 
80
80
 
81
+ def test_build_command_loads_extensions_in_order_and_can_disable_project_trust():
82
+ command = PiHarness().build_command(
83
+ "hello",
84
+ extensions=("/tmp/first extension.ts", "/tmp/second.ts"),
85
+ trust_project=False,
86
+ )
87
+ parts = shlex.split(command)
88
+
89
+ assert parts[parts.index("--no-approve")] == "--no-approve"
90
+ assert "--approve" not in parts
91
+ assert parts[parts.index("--no-approve") + 1 :] == [
92
+ "-e",
93
+ "/tmp/first extension.ts",
94
+ "-e",
95
+ "/tmp/second.ts",
96
+ ]
97
+
98
+
99
+ def test_build_command_defaults_match_approved_command():
100
+ assert PiHarness().build_command("hello") == (
101
+ "printf '%s' hello | pi --mode json --print --no-session --approve"
102
+ )
103
+
104
+
105
+ def test_pr_description_command_honors_extensions_and_project_trust():
106
+ from cacli import build_pr_description_command
107
+
108
+ command = build_pr_description_command(
109
+ "pi",
110
+ "hello",
111
+ params={"account_id": "account"},
112
+ extensions=("/tmp/guardian extension.ts", "/tmp/other.ts"),
113
+ trust_project=False,
114
+ )
115
+ parts = shlex.split(command)
116
+
117
+ assert "--no-approve" in parts
118
+ assert "--approve" not in parts
119
+ assert parts[parts.index("-e") + 1] == "/tmp/guardian extension.ts"
120
+ assert parts[parts.index("-e", parts.index("-e") + 1) + 1] == "/tmp/other.ts"
121
+
122
+
81
123
  def test_build_command_rejects_internal_sandbox_and_settings():
82
124
  provider = PiHarness()
83
125
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes