freeai-code 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 (59) hide show
  1. {freeai_code-0.2.1/freeai_code.egg-info → freeai_code-0.3.0}/PKG-INFO +14 -1
  2. {freeai_code-0.2.1 → freeai_code-0.3.0}/README.md +13 -0
  3. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/__init__.py +1 -1
  4. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/agent.py +42 -5
  5. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/cli.py +124 -3
  6. freeai_code-0.3.0/free_code/rc.py +338 -0
  7. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/ui/prompt.py +1 -0
  8. {freeai_code-0.2.1 → freeai_code-0.3.0/freeai_code.egg-info}/PKG-INFO +14 -1
  9. {freeai_code-0.2.1 → freeai_code-0.3.0}/freeai_code.egg-info/SOURCES.txt +2 -0
  10. {freeai_code-0.2.1 → freeai_code-0.3.0}/pyproject.toml +1 -1
  11. freeai_code-0.3.0/tests/test_rc.py +319 -0
  12. {freeai_code-0.2.1 → freeai_code-0.3.0}/LICENSE +0 -0
  13. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/__main__.py +0 -0
  14. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/auth.py +0 -0
  15. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/builtin_manifest.py +0 -0
  16. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/client.py +0 -0
  17. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/cloud.py +0 -0
  18. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/config.py +0 -0
  19. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/context/__init__.py +0 -0
  20. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/context/discovery.py +0 -0
  21. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/context/repo_map.py +0 -0
  22. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/context/window.py +0 -0
  23. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/feedback_ui.py +0 -0
  24. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/manifest.py +0 -0
  25. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/mcp.py +0 -0
  26. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/models.py +0 -0
  27. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/remote_tools.py +0 -0
  28. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/sessions.py +0 -0
  29. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/streaming.py +0 -0
  30. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/telemetry.py +0 -0
  31. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/__init__.py +0 -0
  32. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/file_ops.py +0 -0
  33. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/git_ops.py +0 -0
  34. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/i18n.py +0 -0
  35. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/list_files.py +0 -0
  36. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/search.py +0 -0
  37. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/shell.py +0 -0
  38. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/test_runner.py +0 -0
  39. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/tools/web.py +0 -0
  40. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/toolset.py +0 -0
  41. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/ui/__init__.py +0 -0
  42. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/ui/diff_view.py +0 -0
  43. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/ui/terminal.py +0 -0
  44. {freeai_code-0.2.1 → freeai_code-0.3.0}/free_code/updater.py +0 -0
  45. {freeai_code-0.2.1 → freeai_code-0.3.0}/freeai_code.egg-info/dependency_links.txt +0 -0
  46. {freeai_code-0.2.1 → freeai_code-0.3.0}/freeai_code.egg-info/entry_points.txt +0 -0
  47. {freeai_code-0.2.1 → freeai_code-0.3.0}/freeai_code.egg-info/requires.txt +0 -0
  48. {freeai_code-0.2.1 → freeai_code-0.3.0}/freeai_code.egg-info/top_level.txt +0 -0
  49. {freeai_code-0.2.1 → freeai_code-0.3.0}/setup.cfg +0 -0
  50. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_agent.py +0 -0
  51. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_cli.py +0 -0
  52. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_login.py +0 -0
  53. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_manifest.py +0 -0
  54. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_mcp.py +0 -0
  55. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_remote_tools.py +0 -0
  56. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_telemetry.py +0 -0
  57. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_tools_misc.py +0 -0
  58. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/test_updater.py +0 -0
  59. {freeai_code-0.2.1 → freeai_code-0.3.0}/tests/tests_helpers.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freeai-code
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Free AI coding assistant — open-source Claude Code alternative. pip install freeai-code
5
5
  Author-email: "Free.ai" <hello@free.ai>
6
6
  License: MIT
@@ -99,6 +99,7 @@ free-code init
99
99
  | `free-code models` | Every model Free.ai serves, free tier first (`--free`, `--paid`, `--type image`, a search word) |
100
100
  | `free-code tools` | The tools the agent has (local, platform, MCP) and what needs approval (`--refresh` fetches the server manifest) |
101
101
  | `free-code mcp add/list/remove/tools/trust` | Use MCP servers such as sttai-mcp |
102
+ | `free-code rc` | Start a session you can watch and drive from the app (`rc status`, `rc off`) |
102
103
  | `free-code sessions` | Saved sessions you can resume |
103
104
  | `free-code login` / `logout` | Sign in through the browser / forget the key |
104
105
  | `free-code update` | Upgrade through whatever installed it (`--check`, `--version X`, `--dry-run`) |
@@ -157,6 +158,18 @@ free-code # its tools appear as mcp__stt_ai__<tool>
157
158
 
158
159
  `${NAME}` in `--env` values is read from your own environment, so no secret is written to disk. Servers live in `~/.free-code/mcp.json` (same `mcpServers` shape as Claude Desktop; `--url https://...` adds an HTTP server). A project can ship `.free-code/mcp.json`, but opening a repository must not start programs, so it is ignored until you run `free-code mcp trust` and it re-prompts if the file changes. MCP tools ask for approval in safe mode.
159
160
 
161
+ ## Remote Control
162
+
163
+ Watch and drive a session from the Free.ai app or https://free.ai/code/sessions/ (works on a phone).
164
+
165
+ ```bash
166
+ free-code rc # start a session with Remote Control on (or type /rc inside a running one)
167
+ free-code rc status # this account's remote sessions
168
+ free-code rc off # end it (also /rc off)
169
+ ```
170
+
171
+ It is opt-in per session and needs `free-code login`. From the app you can see the live transcript and tool calls, send prompts, approve or deny tool calls, interrupt, and end the session. Approvals that safe mode requires stay required: the terminal and the app both get the request and the first answer wins, and every remote prompt is also printed in the terminal. The CLI only makes outbound HTTPS calls to free.ai; messages are relayed between your terminal and devices signed in to your own account, kept as a rolling buffer of the newest 300 events and deleted an hour after the session ends. If the connection drops the session keeps running locally and reconnects. Session text can include code the model read, and tokens and keys are redacted from previews, so treat it like the terminal itself. API for the apps: [docs/remote-control.md](docs/remote-control.md).
172
+
160
173
  ## Scripts and CI
161
174
 
162
175
  ```bash
@@ -66,6 +66,7 @@ free-code init
66
66
  | `free-code models` | Every model Free.ai serves, free tier first (`--free`, `--paid`, `--type image`, a search word) |
67
67
  | `free-code tools` | The tools the agent has (local, platform, MCP) and what needs approval (`--refresh` fetches the server manifest) |
68
68
  | `free-code mcp add/list/remove/tools/trust` | Use MCP servers such as sttai-mcp |
69
+ | `free-code rc` | Start a session you can watch and drive from the app (`rc status`, `rc off`) |
69
70
  | `free-code sessions` | Saved sessions you can resume |
70
71
  | `free-code login` / `logout` | Sign in through the browser / forget the key |
71
72
  | `free-code update` | Upgrade through whatever installed it (`--check`, `--version X`, `--dry-run`) |
@@ -124,6 +125,18 @@ free-code # its tools appear as mcp__stt_ai__<tool>
124
125
 
125
126
  `${NAME}` in `--env` values is read from your own environment, so no secret is written to disk. Servers live in `~/.free-code/mcp.json` (same `mcpServers` shape as Claude Desktop; `--url https://...` adds an HTTP server). A project can ship `.free-code/mcp.json`, but opening a repository must not start programs, so it is ignored until you run `free-code mcp trust` and it re-prompts if the file changes. MCP tools ask for approval in safe mode.
126
127
 
128
+ ## Remote Control
129
+
130
+ Watch and drive a session from the Free.ai app or https://free.ai/code/sessions/ (works on a phone).
131
+
132
+ ```bash
133
+ free-code rc # start a session with Remote Control on (or type /rc inside a running one)
134
+ free-code rc status # this account's remote sessions
135
+ free-code rc off # end it (also /rc off)
136
+ ```
137
+
138
+ It is opt-in per session and needs `free-code login`. From the app you can see the live transcript and tool calls, send prompts, approve or deny tool calls, interrupt, and end the session. Approvals that safe mode requires stay required: the terminal and the app both get the request and the first answer wins, and every remote prompt is also printed in the terminal. The CLI only makes outbound HTTPS calls to free.ai; messages are relayed between your terminal and devices signed in to your own account, kept as a rolling buffer of the newest 300 events and deleted an hour after the session ends. If the connection drops the session keeps running locally and reconnects. Session text can include code the model read, and tokens and keys are redacted from previews, so treat it like the terminal itself. API for the apps: [docs/remote-control.md](docs/remote-control.md).
139
+
127
140
  ## Scripts and CI
128
141
 
129
142
  ```bash
@@ -1,3 +1,3 @@
1
1
  """Free.ai Coder CLI — Free AI coding assistant."""
2
2
 
3
- __version__ = "0.2.1"
3
+ __version__ = "0.3.0"
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import asyncio
6
6
  import json
7
7
  import sys
8
+ import uuid
8
9
  from pathlib import Path
9
10
  from typing import Any, Dict, List, Optional
10
11
 
@@ -18,6 +19,7 @@ from free_code.config import load_config
18
19
  from free_code.context.repo_map import generate_repo_map
19
20
  from free_code.context.window import build_context
20
21
  from free_code import sessions as sessions_mod
22
+ from free_code import rc as rc_mod
21
23
  from free_code import telemetry
22
24
  from free_code.toolset import ToolSet
23
25
  from free_code.tools.shell import is_dangerous
@@ -92,9 +94,27 @@ class Agent:
92
94
  self.tool_log: List[Dict[str, Any]] = []
93
95
  self.denied_for_approval = False
94
96
  self.tasks_done = 0
97
+ self.rc: Optional[rc_mod.RemoteControl] = None
98
+ self.reader: Optional[rc_mod.TerminalReader] = None
99
+
100
+ # ---- Remote Control (no-ops unless `free-code rc` is on for this session)
101
+ def _emit(self, type_: str, data: Optional[Dict[str, Any]] = None) -> None:
102
+ if self.rc is not None and self.rc.active:
103
+ self.rc.emit(type_, data)
104
+
105
+ def _cancelled(self) -> bool:
106
+ if self.rc is not None and self.rc.cancel.is_set():
107
+ self.rc.cancel.clear()
108
+ self._emit("notice", {"text": "Interrupted from the app."})
109
+ self.last_error = "interrupted"
110
+ if self.output == "rich":
111
+ console.print("[dim]Interrupted from the app.[/dim]")
112
+ return True
113
+ return False
95
114
 
96
115
  # ---- output helpers (rich in the terminal, quiet for --print / --json)
97
116
  def _say(self, text: str) -> None:
117
+ self._emit("assistant", {"text": rc_mod.redact(text, 4000)})
98
118
  if self.output == "rich":
99
119
  print_markdown(text)
100
120
 
@@ -103,9 +123,11 @@ class Agent:
103
123
  return
104
124
  print_error(text)
105
125
 
106
- def _confirm(self, message: str) -> bool:
126
+ def _confirm(self, message: str, tool: str = "", preview: str = "") -> bool:
107
127
  if self.auto_approve:
108
128
  return True
129
+ if self.rc is not None and self.rc.active and self.output == "rich":
130
+ return self.rc.confirm(message, tool, preview, self.reader, lambda m: console.print(f"[warning]{m}[/warning]"))
109
131
  if self.output != "rich" or not sys.stdin.isatty():
110
132
  self.denied_for_approval = True
111
133
  return False
@@ -136,9 +158,16 @@ class Agent:
136
158
  system = self.system
137
159
 
138
160
  self.messages.append({"role": "user", "content": user_message})
161
+ self._emit("status", {"state": "working"})
162
+ if self.rc is not None:
163
+ self.rc.cancel.clear()
139
164
 
140
165
  for step in range(self.max_steps):
166
+ if self._cancelled():
167
+ break
141
168
  response_text = await self._get_response(system)
169
+ if self._cancelled():
170
+ break
142
171
 
143
172
  if not response_text:
144
173
  break
@@ -183,6 +212,7 @@ class Agent:
183
212
  self._err(self.last_error)
184
213
  self.tasks_done += 1
185
214
  self.save_session()
215
+ self._emit("status", {"state": "idle"})
186
216
 
187
217
  async def _get_response(self, system: Optional[str] = None) -> str:
188
218
  """Get a streaming response from the LLM."""
@@ -194,6 +224,8 @@ class Agent:
194
224
  first_chunk = True
195
225
  async for event in self.client.chat_stream(self.messages, system=system):
196
226
  event_type = event.get("type", "")
227
+ if self.rc is not None and self.rc.cancel.is_set():
228
+ return ""
197
229
 
198
230
  if event_type == "text":
199
231
  content = event.get("content", "")
@@ -261,25 +293,25 @@ class Agent:
261
293
  if self.safe_mode:
262
294
  if level == "write":
263
295
  show(); shown = True
264
- if not self._confirm("Apply this change?"):
296
+ if not self._confirm("Apply this change?", tool_name, rc_mod.args_preview(tool_name, tool_args)):
265
297
  return None
266
298
  elif level == "shell":
267
299
  cmd = tool_args.get("command", "")
268
300
  show(); shown = True
269
301
  if is_dangerous(cmd) and self.output == "rich":
270
302
  console.print("[warning]This command could be dangerous.[/warning]")
271
- if not self._confirm(f"Run: {cmd}"):
303
+ if not self._confirm(f"Run: {cmd}", tool_name, rc_mod.redact(str(cmd), 400)):
272
304
  return None
273
305
  elif level in ("upload", "mcp"):
274
306
  show(); shown = True
275
307
  what = ("Upload this file to Free.ai?" if level == "upload"
276
308
  else f"Run MCP tool {tool_name}?")
277
- if not self._confirm(what):
309
+ if not self._confirm(what, tool_name, rc_mod.args_preview(tool_name, tool_args)):
278
310
  return None
279
311
  else:
280
312
  if level == "shell" and is_dangerous(tool_args.get("command", "")):
281
313
  show(); shown = True
282
- if not self._confirm("This command could be dangerous. Run anyway?"):
314
+ if not self._confirm("This command could be dangerous. Run anyway?", tool_name, rc_mod.redact(str(tool_args.get("command", "")), 400)):
283
315
  return None
284
316
  # An auto-approved run still never executes a dangerous command silently.
285
317
  if level == "shell" and self.auto_approve and is_dangerous(tool_args.get("command", "")) \
@@ -291,6 +323,9 @@ class Agent:
291
323
  if not shown:
292
324
  show()
293
325
 
326
+ call_id = uuid.uuid4().hex[:12]
327
+ self._emit("tool_call", {"id": call_id, "tool": tool_name if kind != "mcp" else tool_name,
328
+ "preview": rc_mod.args_preview(tool_name, tool_args)})
294
329
  try:
295
330
  result, source = ts.execute(tool_name, dict(tool_args))
296
331
  except TypeError:
@@ -303,6 +338,8 @@ class Agent:
303
338
  result, source = f"Error executing {tool_name}: {e}", "builtin"
304
339
 
305
340
  self._record(tool_name, tool_args, result, source)
341
+ self._emit("tool_result", {"id": call_id, "ok": not str(result).lstrip().startswith("Error"),
342
+ "preview": rc_mod.redact(str(result), 800)})
306
343
  if self.output == "rich":
307
344
  print_tool_result(result, collapsed=len(str(result)) > 1000)
308
345
  return str(result)
@@ -163,15 +163,16 @@ def main(ctx: click.Context, print_prompt: Optional[str], cont: bool, resume_id:
163
163
  resume=resume_id, cont=cont)
164
164
  _run_noninteractive(agent, prompt, as_json=as_json, print_mode=True)
165
165
  return
166
- ctx.invoke(chat, cont=cont, resume_id=resume_id, auto_yes=auto_yes, model_override=model_override,
166
+ ctx.invoke(chat, cont=cont, resume_id=resume_id, rc_on=False, auto_yes=auto_yes, model_override=model_override,
167
167
  max_steps=max_steps, no_mcp=no_mcp, as_json=False)
168
168
 
169
169
 
170
170
  @main.command()
171
171
  @click.option("--continue", "-c", "cont", is_flag=True, help="Resume the latest session for this project.")
172
172
  @click.option("--resume", "resume_id", default=None, metavar="ID", help="Resume a saved session.")
173
+ @click.option("--rc", "rc_on", is_flag=True, help="Turn on Remote Control for this session (same as free-code rc).")
173
174
  @agent_options
174
- def chat(cont: bool = False, resume_id: Optional[str] = None, auto_yes: bool = False,
175
+ def chat(cont: bool = False, resume_id: Optional[str] = None, rc_on: bool = False, auto_yes: bool = False,
175
176
  as_json: bool = False, model_override: Optional[str] = None,
176
177
  max_steps: Optional[int] = None, no_mcp: bool = False) -> None:
177
178
  """Start an interactive coding session."""
@@ -192,6 +193,8 @@ def chat(cont: bool = False, resume_id: Optional[str] = None, auto_yes: bool = F
192
193
  agent = _make_agent(project_root, auto_yes=auto_yes, model_override=model_override,
193
194
  max_steps=max_steps, no_mcp=no_mcp, resume=resume_id, cont=cont)
194
195
  config = agent.config
196
+ if rc_on:
197
+ _start_rc(agent, project_root)
195
198
 
196
199
  print_welcome()
197
200
  print_model_info(config.get("provider", "free.ai"), get_model(config))
@@ -208,7 +211,7 @@ def chat(cont: bool = False, resume_id: Optional[str] = None, auto_yes: bool = F
208
211
 
209
212
  while True:
210
213
  try:
211
- user_input = get_input("you> ")
214
+ user_input, from_app = _next_input(agent, get_input)
212
215
  except KeyboardInterrupt:
213
216
  console.print("\n[dim]Goodbye![/dim]")
214
217
  break
@@ -264,6 +267,16 @@ def chat(cont: bool = False, resume_id: Optional[str] = None, auto_yes: bool = F
264
267
  else:
265
268
  print_error("No matching session. Try /sessions.")
266
269
  continue
270
+ elif cmd == "/rc":
271
+ if rest.strip() == "off":
272
+ _rc_off(agent)
273
+ elif rest.strip() == "status":
274
+ console.print(f"Remote Control: {'on, ' + agent.rc.url if agent.rc and agent.rc.active else 'off'}")
275
+ elif agent.rc and agent.rc.active:
276
+ console.print(f"Remote Control is already on: {agent.rc.url}")
277
+ else:
278
+ _start_rc(agent, project_root)
279
+ continue
267
280
  elif cmd == "/feedback":
268
281
  feedback_ui.feedback_command(rest, agent.messages, agent.client.model)
269
282
  continue
@@ -305,6 +318,7 @@ def chat(cont: bool = False, resume_id: Optional[str] = None, auto_yes: bool = F
305
318
  continue
306
319
 
307
320
  try:
321
+ agent._emit("prompt", {"text": user_input[:2000], "source": "app" if from_app else "terminal"})
308
322
  asyncio.run(agent.chat(user_input))
309
323
  if agent.last_error:
310
324
  _hint_login_on_limit(agent.last_error)
@@ -317,6 +331,65 @@ def chat(cont: bool = False, resume_id: Optional[str] = None, auto_yes: bool = F
317
331
  print_error(f"Agent error: {e}")
318
332
 
319
333
 
334
+ def _next_input(agent, get_input):
335
+ """Next line from the terminal, or a prompt sent from the app when Remote Control is on."""
336
+ from free_code.rc import TerminalReader
337
+
338
+ rc = agent.rc
339
+ if agent.reader is None and not (rc and rc.active):
340
+ return get_input("you> "), False
341
+ reader = agent.reader or TerminalReader()
342
+ agent.reader = reader
343
+ if reader._busy:
344
+ console.print("[bold cyan]you> [/bold cyan]", end="")
345
+ reader.request("you> ")
346
+ while True:
347
+ if rc and rc.active:
348
+ text = rc.next_remote_prompt()
349
+ if text:
350
+ console.print(f"\n[cyan][from the app][/cyan] {text}")
351
+ return text, True
352
+ got, line = reader.get(0.3 if (rc and rc.active) else None)
353
+ if got:
354
+ return (line.strip() if line is not None else None), False
355
+
356
+
357
+ def _start_rc(agent, project_root: Path) -> bool:
358
+ import atexit
359
+
360
+ from free_code.rc import RCError, RemoteControl, TerminalReader
361
+
362
+ token = agent.config.get("token")
363
+ if not token:
364
+ console.print("[yellow]Remote Control needs a Free.ai sign-in. Run: free-code login[/yellow]")
365
+ return False
366
+ rc = RemoteControl(token, project=project_root.name, model=agent.client.model,
367
+ notify=lambda m: console.print(f"\n[dim]{m}[/dim]"))
368
+ try:
369
+ rc.start()
370
+ except RCError as e:
371
+ console.print(f"[red]{e}[/red]")
372
+ return False
373
+ agent.rc = rc
374
+ agent.reader = agent.reader or TerminalReader()
375
+ atexit.register(rc.stop)
376
+ console.print(f"[green]Remote Control is on.[/green] Open the Free.ai app, or {rc.url}")
377
+ console.print("[dim]Prompts and approvals also appear here; file writes and commands still need approval. "
378
+ "Only your account can see this session. End it with /rc off or free-code rc off.[/dim]")
379
+ if agent.auto_approve or not agent.safe_mode:
380
+ console.print("[yellow]Approvals are off in this session (--yes or safe_mode false), so a prompt sent "
381
+ "from the app can edit files and run commands without asking.[/yellow]")
382
+ return True
383
+
384
+
385
+ def _rc_off(agent) -> None:
386
+ if agent.rc and agent.rc.active:
387
+ agent.rc.stop()
388
+ console.print("[green]Remote Control ended.[/green]")
389
+ else:
390
+ console.print("[dim]Remote Control is not on in this session.[/dim]")
391
+
392
+
320
393
  def _hint_login_on_limit(error: str) -> None:
321
394
  """When the anonymous limit or a missing key stops a request, offer the browser login."""
322
395
  if "free-code login" not in error or not sys.stdin.isatty():
@@ -948,3 +1021,51 @@ def mcp_trust() -> None:
948
1021
  if click.confirm("Allow these in this project?", default=False):
949
1022
  trust(root)
950
1023
  console.print("[green]Trusted.[/green]")
1024
+
1025
+
1026
+ @main.group("rc", invoke_without_command=True)
1027
+ @click.option("--continue", "-c", "cont", is_flag=True, help="Resume the latest session for this project.")
1028
+ @click.option("--resume", "resume_id", default=None, metavar="ID", help="Resume a saved session.")
1029
+ @click.option("--model", "model_override", default=None, help="Model id for this session.")
1030
+ @click.pass_context
1031
+ def rc(ctx: click.Context, cont: bool, resume_id: Optional[str], model_override: Optional[str]) -> None:
1032
+ """Remote Control: start a session you can watch and drive from the Free.ai app."""
1033
+ if ctx.invoked_subcommand is not None:
1034
+ return
1035
+ ctx.invoke(chat, cont=cont, resume_id=resume_id, rc_on=True, auto_yes=False,
1036
+ as_json=False, model_override=model_override, max_steps=None, no_mcp=False)
1037
+
1038
+
1039
+ @rc.command("off")
1040
+ def rc_off() -> None:
1041
+ """End the Remote Control session started from this machine."""
1042
+ from free_code import rc as rc_mod
1043
+
1044
+ token = load_config().get("token")
1045
+ if not token:
1046
+ raise click.ClickException("Not signed in. Run: free-code login")
1047
+ console.print(rc_mod.stop_from_state(token))
1048
+
1049
+
1050
+ @rc.command("status")
1051
+ def rc_status() -> None:
1052
+ """Show this account's Remote Control sessions."""
1053
+ import httpx
1054
+
1055
+ from free_code import rc as rc_mod
1056
+
1057
+ token = load_config().get("token")
1058
+ if not token:
1059
+ raise click.ClickException("Not signed in. Run: free-code login")
1060
+ try:
1061
+ r = httpx.get(f"{rc_mod.RELAY_BASE}/api/v1/code/rc/sessions/", headers={"Authorization": f"Bearer {token}"}, timeout=10)
1062
+ rows = r.json().get("sessions", []) if r.status_code == 200 else []
1063
+ except (httpx.HTTPError, ValueError):
1064
+ raise click.ClickException("Could not reach free.ai.")
1065
+ mine = rc_mod.read_state()
1066
+ if not rows:
1067
+ console.print("[dim]No remote sessions.[/dim]")
1068
+ for row in rows:
1069
+ mark = " (this machine)" if mine and mine.get("session_id") == row["id"] else ""
1070
+ console.print(f" {row['id'][:8]} {row['status']:5s} {row['project']} on {row['host']}{mark}")
1071
+ console.print("[dim]Web: https://free.ai/code/sessions/[/dim]")