@yahyahammad/venastine 0.3.16 → 0.3.18

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.
@@ -21,6 +21,12 @@ SECURITY MODEL (ROADMAP §6, deviated per user decision):
21
21
  resolved via os.path.realpath before any check, so a path that looks
22
22
  inside the workspace but resolves outside it is treated as outside.
23
23
 
24
+ `/workspace/x` IS INSIDE (ROADMAP_v3 §96, batch 263): it is the
25
+ container's name for `<workspace>/x`, and resolve_path maps it there
26
+ while a tool that starts shell commands is enabled. Every other path
27
+ outside the workspace still asks, the owner's choice: a prompt is how
28
+ this layer avoids saying whether a file exists before anyone said yes.
29
+
24
30
  PROTECTED SEGMENTS (security/protected_paths.py) are the one hard
25
31
  deny, and the exception to both rules above: any path -- inside or
26
32
  outside the workspace -- that resolves into `.venastine/` is refused
@@ -84,6 +90,7 @@ from pydantic import BaseModel, Field
84
90
  import config
85
91
  from json_store import write_text_atomic
86
92
  from security.protected_paths import hardlinked_segment, protected_segment
93
+ from security.sandbox import CONTAINER_WORKSPACE
87
94
  from tools.base import invalid_params
88
95
 
89
96
  logger = logging.getLogger(__name__)
@@ -113,15 +120,67 @@ def resolve_path(user_path: str) -> str:
113
120
  ``os.path.join(WORKSPACE_ROOT, ...)`` at the call site is this
114
121
  project's canonical producer/consumer bug, and here it would mean a
115
122
  diff of one file beside an edit to another.
123
+
124
+ THE CONTAINER'S SPELLING (ROADMAP_v3 §96, CW1-CW3). The shell runs
125
+ in a container that mounts the workspace at `/workspace`, so the
126
+ paths the model sees there -- `pwd`, a build's error lines -- name
127
+ workspace files as `/workspace/x`. These tools run on the host, where
128
+ that path is somewhere else or nowhere: until batch 263 such a call
129
+ asked to leave the workspace and then failed on a file that was
130
+ there all along. So `/workspace/x` resolves to `<workspace>/x`, here
131
+ and nowhere else, which is what makes the approval check, the four
132
+ handlers, the protected deny and the TUI's diff agree on it.
133
+
134
+ Only while a tool that starts commands is enabled (CW1), because that
135
+ is where the model learns the spelling. Only when the host's own
136
+ reading of the path lands OUTSIDE the workspace, so a host whose
137
+ workspace really lives under `/workspace` keeps its meaning, and only
138
+ when the mapped path lands INSIDE it, so `..` or a link out of it
139
+ keeps the prompt it had (CW2).
140
+ """
141
+ host = os.path.realpath(os.path.join(WORKSPACE_ROOT, user_path))
142
+ rest = _container_remainder(user_path)
143
+ if rest is None or _inside(host) or not _shell_starts_commands():
144
+ return host
145
+ mapped = os.path.realpath(os.path.join(WORKSPACE_ROOT, rest))
146
+ return mapped if _inside(mapped) else host
147
+
148
+
149
+ def _container_remainder(user_path: str) -> Optional[str]:
150
+ """What follows the container's mount point in *user_path*, or None
151
+ when the path is not spelled from it.
152
+
153
+ The mount point is a whole SEGMENT: `/workspace` and `/workspace/x`
154
+ are the container's spelling and `/workspacefoo` is not. Leading
155
+ slashes are dropped from the remainder because POSIX folds a run of
156
+ them into one -- `/workspace//x` is `/workspace/x` in the container --
157
+ while `os.path.join` would read the second as a new root.
116
158
  """
117
- return os.path.realpath(os.path.join(WORKSPACE_ROOT, user_path))
159
+ if user_path == CONTAINER_WORKSPACE:
160
+ return ""
161
+ if user_path.startswith(CONTAINER_WORKSPACE + "/"):
162
+ return user_path[len(CONTAINER_WORKSPACE):].lstrip("/")
163
+ return None
118
164
 
119
165
 
120
- def _is_within_workspace(user_path: str) -> bool:
121
- resolved = resolve_path(user_path)
166
+ def _shell_starts_commands() -> bool:
167
+ """Whether any tool that runs a command in the container may be
168
+ called (§96 CW1): the same four `shell_approval_mode` governs, asked
169
+ through `is_tool_allowed`, so a hosted deployment that refuses them
170
+ maps nothing either."""
171
+ from security.permissions import APPROVAL_BY_SHELL_MODE, is_tool_allowed
172
+
173
+ return any(is_tool_allowed(name) for name in APPROVAL_BY_SHELL_MODE)
174
+
175
+
176
+ def _inside(resolved: str) -> bool:
122
177
  return resolved == WORKSPACE_ROOT or resolved.startswith(WORKSPACE_ROOT + os.sep)
123
178
 
124
179
 
180
+ def _is_within_workspace(user_path: str) -> bool:
181
+ return _inside(resolve_path(user_path))
182
+
183
+
125
184
  def _file_approval_check(tool_name: str, params: dict) -> bool:
126
185
  """Path-dependent approval policy for read / write / edit.
127
186
 
@@ -414,7 +473,8 @@ def read_run(params: dict) -> dict:
414
473
  with open(resolved, encoding="utf-8", errors="replace") as f:
415
474
  all_lines = f.read().splitlines()
416
475
  except Exception as e:
417
- logger.exception("read tool failed on %s", parsed.path)
476
+ # INFO (batch 266): the result below says this; the file keeps the trace.
477
+ logger.info("read tool failed on %s", parsed.path, exc_info=True)
418
478
  return {"error": f"Could not read file: {e}"}
419
479
 
420
480
  content, lines_returned, truncated, message = _truncate_lines(
@@ -482,7 +542,8 @@ def write_run(params: dict) -> dict:
482
542
  created = not os.path.exists(resolved)
483
543
  write_text_atomic(resolved, parsed.content)
484
544
  except Exception as e:
485
- logger.exception("write tool failed on %s", parsed.path)
545
+ # INFO (batch 266): the result below says this; the file keeps the trace.
546
+ logger.info("write tool failed on %s", parsed.path, exc_info=True)
486
547
  return {"error": f"Could not write file: {e}"}
487
548
 
488
549
  if created:
@@ -551,7 +612,9 @@ def edit_run(params: dict) -> dict:
551
612
  with open(resolved, encoding="utf-8", newline="") as f:
552
613
  content = f.read()
553
614
  except Exception as e:
554
- logger.exception("edit tool read failed on %s", parsed.path)
615
+ # INFO (batch 266): the result below says this; the file keeps the trace.
616
+ logger.info("edit tool read failed on %s", parsed.path,
617
+ exc_info=True)
555
618
  return {"error": f"Could not read file: {e}"}
556
619
 
557
620
  old_text, new_text = parsed.old_text, parsed.new_text
@@ -586,7 +649,9 @@ def edit_run(params: dict) -> dict:
586
649
  try:
587
650
  write_text_atomic(resolved, content)
588
651
  except Exception as e:
589
- logger.exception("edit tool write failed on %s", parsed.path)
652
+ # INFO (batch 266): the result below says this; the file keeps the trace.
653
+ logger.info("edit tool write failed on %s", parsed.path,
654
+ exc_info=True)
590
655
  return {"error": f"Could not write file: {e}"}
591
656
 
592
657
  return {"result": f"Replaced 1 occurrence in {parsed.path}"}
@@ -685,7 +750,8 @@ def view_image_run(params: dict, memory=None, call_id=None,
685
750
  with open(resolved, "rb") as f:
686
751
  raw = f.read(config.MAX_IMAGE_BYTES + 1)
687
752
  except OSError as e:
688
- logger.exception("view_image failed on %s", parsed.path)
753
+ # INFO (batch 266): the result below says this; the file keeps the trace.
754
+ logger.info("view_image failed on %s", parsed.path, exc_info=True)
689
755
  return {"error": f"Could not read file: {e}"}
690
756
  if len(raw) > config.MAX_IMAGE_BYTES:
691
757
  return {"error": (
@@ -311,7 +311,10 @@ def read_run(params: dict) -> dict:
311
311
  chunk = f.read(config.INIT_READ_CHARS)
312
312
  more = f.read(1) != ""
313
313
  except OSError as e:
314
- logger.warning("read_project_doc failed for %s: %s", user_path, e)
314
+ # INFO, not WARNING (batch 266, the owner's choice): the error below
315
+ # is the result, and both shells print a failed result as a line of
316
+ # its own, so a WARNING here drew the one failure twice.
317
+ logger.info("read_project_doc failed for %s: %s", user_path, e)
315
318
  return {"error": f"Could not read {user_path}: {e}"}
316
319
 
317
320
  result = {"path": user_path, "content": chunk, "truncated": more}
@@ -442,8 +445,10 @@ def write_run(params: dict) -> dict:
442
445
  destination = doc_path(root, name)
443
446
  resolved = _resolve_in_project(root, name)
444
447
  if resolved is None:
445
- logger.warning("write_project_doc refused %s: resolves outside the "
446
- "project", destination)
448
+ # INFO (batch 266): the error below is the result, which both shells
449
+ # print as a line of its own. The file keeps the path it resolved to.
450
+ logger.info("write_project_doc refused %s: resolves outside the "
451
+ "project", destination)
447
452
  return {"error": f"write_project_doc: {name!r} resolves outside the "
448
453
  f"project directory, so it is not one of this "
449
454
  f"project's documents."}
@@ -458,7 +463,8 @@ def write_run(params: dict) -> dict:
458
463
  # approval that was shown a diff of the lines that changed.
459
464
  write_text_atomic(resolved, content)
460
465
  except OSError as e:
461
- logger.warning("write_project_doc failed for %s: %s", resolved, e)
466
+ # INFO (batch 266), as `read_project_doc`'s failure: the result says it.
467
+ logger.info("write_project_doc failed for %s: %s", resolved, e)
462
468
  return {"error": f"Could not write {resolved}: {e}"}
463
469
 
464
470
  return {"result": f"Wrote {len(content)} characters to {resolved}"}
@@ -1115,5 +1115,6 @@ def run(params: dict) -> dict:
1115
1115
  except SandboxUnavailable as e:
1116
1116
  return {"error": str(e)}
1117
1117
  except Exception as e:
1118
- logger.exception("shell tool failed")
1118
+ # INFO (batch 266): the result below says this; the file keeps the trace.
1119
+ logger.info("shell tool failed", exc_info=True)
1119
1120
  return {"error": f"Shell execution failed: {e}"}
@@ -75,7 +75,8 @@ def available() -> bool:
75
75
 
76
76
  _TIMEOUT_DESCRIPTION = (
77
77
  "The longest this session may run, in seconds. Pick what the work needs: "
78
- "while it runs the user's prompt is blocked. Above "
78
+ "while it runs the user can still message you but cannot switch thread "
79
+ "or model. Above "
79
80
  f"{config.SHELL_SESSION_TIMEOUT_CAP_S} it is capped at "
80
81
  f"{config.SHELL_SESSION_TIMEOUT_CAP_S} and the result says so. When it is "
81
82
  "reached the command is stopped and you are woken.")
@@ -215,8 +216,10 @@ class KillParams(BaseModel):
215
216
 
216
217
  _SHARED = (
217
218
  f"At most {config.SHELL_SESSION_MAX_LIVE} sessions run at once, shared with "
218
- "any subagents, and the user's prompt is blocked while one of yours runs. "
219
- "Read output with shell_output and stop a session with shell_kill.")
219
+ "any subagents. While one of yours runs the user can still message you: "
220
+ "each message is a turn of its own, and a result that lands meanwhile "
221
+ "wakes you after it. Read output with shell_output and stop a session "
222
+ "with shell_kill.")
220
223
 
221
224
 
222
225
  def _schema(name: str, description: str, model, required) -> dict:
@@ -360,7 +360,11 @@ def run(params: dict) -> dict:
360
360
  "The search provider is rate-limiting this harness. "
361
361
  "Wait a minute before searching again.")}
362
362
  last_exc = e
363
- logger.warning(
363
+ # INFO (batch 266, the owner's choice). The last attempt's
364
+ # error is the result below, which both shells print as a
365
+ # line of its own, and an attempt that a retry recovered from
366
+ # is nothing to show anyone. The file keeps every attempt.
367
+ logger.info(
364
368
  "web_search attempt %s/%s failed for %r: %s",
365
369
  attempt + 1, MAX_RETRIES + 1, parsed.query, e)
366
370
  else:
@@ -233,10 +233,11 @@ def _interpret(tool_name: str, stdout: str, stderr: str, returncode: int,
233
233
  return {"error": _limit_message(tool_name, timeout)}
234
234
 
235
235
  excerpt = (stderr or "").strip().replace("\n", " ")[-_STDERR_EXCERPT:]
236
- # logger.warning, not exception: there is no traceback here to keep,
237
- # and this path is reachable by ordinary input.
238
- logger.warning("%s produced no readable result (exit %s): %s",
239
- tool_name, returncode, excerpt)
236
+ # Not logger.exception: there is no traceback here to keep, and this
237
+ # path is reachable by ordinary input. INFO, not WARNING (batch 266):
238
+ # the result below says the same, and both shells print it.
239
+ logger.info("%s produced no readable result (exit %s): %s",
240
+ tool_name, returncode, excerpt)
240
241
  return {"error": f"{tool_name} did not return a usable result "
241
242
  f"(exit {returncode}). {excerpt}".strip()}
242
243
 
@@ -309,8 +310,10 @@ def run_isolated(handler, params: dict, timeout: float,
309
310
  # case, which shares this wording rather than repeating it.
310
311
  return {"error": _limit_message(tool_name, timeout)}
311
312
  except OSError as e:
312
- logger.warning("Could not start an isolated child for %s: %s",
313
- tool_name, e)
313
+ # INFO (batch 266): the result below says this, and both shells
314
+ # print it; the file keeps the line.
315
+ logger.info("Could not start an isolated child for %s: %s",
316
+ tool_name, e)
314
317
  return {"error": f"{tool_name} could not be run: {e}"}
315
318
  stdout, stdout_bytes = _head(out, MAX_CHILD_OUTPUT_BYTES + 1)
316
319
  stderr = _tail(err, 4 * _STDERR_EXCERPT)