gemcode 0.4.28__py3-none-any.whl → 0.4.30__py3-none-any.whl

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.
@@ -157,14 +157,30 @@ def _cleanup_managed_servers() -> None:
157
157
  atexit.register(_cleanup_managed_servers)
158
158
 
159
159
 
160
+ def _http_responds(port: int, request_path: str = "/", *, timeout: float = 1.0) -> bool:
161
+ try:
162
+ conn = HTTPConnection("127.0.0.1", port, timeout=timeout)
163
+ conn.request(
164
+ "GET",
165
+ request_path or "/",
166
+ headers={"User-Agent": "GemCode-Web-Preview/1.0", "Accept": "*/*"},
167
+ )
168
+ resp = conn.getresponse()
169
+ resp.read()
170
+ conn.close()
171
+ return True
172
+ except OSError:
173
+ return False
174
+
175
+
160
176
  def ensure_workspace_static_server(port: int, root: Path) -> tuple[bool, str | None]:
161
177
  """
162
- Ensure something accepts TCP on ``127.0.0.1:port``.
178
+ Ensure something accepts HTTP on ``127.0.0.1:port``.
163
179
 
164
180
  If the port is free and eligible, start ``python -m http.server`` in ``root``.
165
181
  Returns (ok, note).
166
182
  """
167
- if _port_open("127.0.0.1", port, timeout=0.35):
183
+ if _http_responds(port):
168
184
  return True, None
169
185
  if port not in STATIC_AUTOSTART_PORTS:
170
186
  return False, (
@@ -176,16 +192,16 @@ def ensure_workspace_static_server(port: int, root: Path) -> tuple[bool, str | N
176
192
  return False, f"Workspace root is not a directory: {root}"
177
193
 
178
194
  with _server_lock:
179
- if _port_open("127.0.0.1", port, timeout=0.35):
195
+ if _http_responds(port):
180
196
  return True, None
181
197
  existing = _managed_servers.get(port)
182
198
  if existing is not None and existing.poll() is None:
183
- for _ in range(25):
184
- if _port_open("127.0.0.1", port, timeout=0.2):
199
+ for _ in range(40):
200
+ if _http_responds(port):
185
201
  return True, "managed"
186
202
  if existing.poll() is not None:
187
203
  break
188
- time.sleep(0.08)
204
+ time.sleep(0.1)
189
205
  try:
190
206
  proc = subprocess.Popen(
191
207
  [
@@ -204,13 +220,13 @@ def ensure_workspace_static_server(port: int, root: Path) -> tuple[bool, str | N
204
220
  except OSError as exc:
205
221
  return False, f"Could not start static preview server: {exc}"
206
222
  _managed_servers[port] = proc
207
- for _ in range(30):
208
- if _port_open("127.0.0.1", port, timeout=0.2):
223
+ for _ in range(50):
224
+ if _http_responds(port):
209
225
  return True, "started"
210
226
  if proc.poll() is not None:
211
227
  _managed_servers.pop(port, None)
212
228
  return False, "Static preview server exited immediately (port may be busy)."
213
- time.sleep(0.08)
229
+ time.sleep(0.1)
214
230
  return False, "Timed out waiting for static preview server."
215
231
 
216
232
 
@@ -299,13 +315,29 @@ def handle_preview_proxy(
299
315
  if root is not None:
300
316
  ok, note = ensure_workspace_static_server(port, root)
301
317
  if ok:
302
- try:
303
- time.sleep(0.05)
304
- status, body, ctype, headers_list = _fetch()
305
- except OSError as second_exc:
318
+ status = 0
319
+ body = b""
320
+ ctype = ""
321
+ headers_list = []
322
+ last_err: OSError | None = None
323
+ # Retry briefly — TCP can accept before http.server is ready to route paths.
324
+ for attempt in range(12):
325
+ try:
326
+ time.sleep(0.08 if attempt else 0.05)
327
+ status, body, ctype, headers_list = _fetch()
328
+ if status != 404:
329
+ break
330
+ # 404 right after start: file may not be visible yet; retry a few times.
331
+ if attempt < 8:
332
+ continue
333
+ break
334
+ except OSError as second_exc:
335
+ last_err = second_exc
336
+ continue
337
+ if last_err is not None and status == 0:
306
338
  msg = (
307
339
  f'{{"error":"Preview upstream unreachable after starting static server: '
308
- f'{type(second_exc).__name__}: {second_exc}"}}'
340
+ f'{type(last_err).__name__}: {last_err}"}}'
309
341
  )
310
342
  return 502, msg.encode(), {"Content-Type": "application/json; charset=utf-8"}
311
343
  else:
@@ -315,6 +347,25 @@ def handle_preview_proxy(
315
347
  else:
316
348
  msg = f'{{"error":"Preview upstream unreachable: {type(first_exc).__name__}: {first_exc}"}}'
317
349
  return 502, msg.encode(), {"Content-Type": "application/json; charset=utf-8"}
350
+ else:
351
+ # Live server returned 404 — retry once after a short wait (startup race).
352
+ if status == 404 and root is not None:
353
+ for _ in range(6):
354
+ time.sleep(0.12)
355
+ try:
356
+ status, body, ctype, headers_list = _fetch()
357
+ if status != 404:
358
+ break
359
+ except OSError:
360
+ ok, _ = ensure_workspace_static_server(port, root)
361
+ if not ok:
362
+ break
363
+ try:
364
+ status, body, ctype, headers_list = _fetch()
365
+ except OSError:
366
+ break
367
+ if status != 404:
368
+ break
318
369
 
319
370
  headers: dict[str, str] = {}
320
371
  for key, value in headers_list:
@@ -437,6 +437,8 @@ def _inject_web_code_context(cfg: GemCodeConfig, prompt: str, req: dict[str, Any
437
437
  "Use them proactively; never tell the user you cannot access their files.",
438
438
  f"Workspace root: `{root}`",
439
439
  "Tool paths are relative to this workspace root.",
440
+ "When the user asks to analyze the codebase / project / repo, stay **inside this workspace root only** — "
441
+ "do not walk up to parent directories or sibling folders outside this root.",
440
442
  ]
441
443
 
442
444
  active = req.get("active_file")
@@ -1125,15 +1127,21 @@ async def run_adapter(req: dict[str, Any]) -> None:
1125
1127
  raise ValueError(str(exc)) from exc
1126
1128
  if not root_path.is_dir():
1127
1129
  raise ValueError(f"project_root is not a directory: {root_path}")
1128
- project_root = str(root_path)
1130
+ project_root = str(root_path.resolve())
1129
1131
  from gemcode.org import resolve_fleet_root
1130
1132
 
1131
- fleet_root = resolve_fleet_root(root_path.resolve())
1132
- cfg = GemCodeConfig(project_root=fleet_root)
1133
+ # Fleet/org lives at the nearest ancestor with .gemcode/org.json (often the
1134
+ # tenant PVC root). Tooling + "analyze codebase" must stay on the *selected*
1135
+ # project folder the UI sent — do not widen to fleet_root.
1136
+ project_path = root_path.resolve()
1137
+ fleet_root = resolve_fleet_root(project_path)
1138
+ cfg = GemCodeConfig(project_root=project_path)
1133
1139
 
1134
1140
  from gemcode.trust import ensure_hosted_workspace_trust
1135
1141
 
1136
1142
  ensure_hosted_workspace_trust(fleet_root)
1143
+ if project_path != fleet_root:
1144
+ ensure_hosted_workspace_trust(project_path)
1137
1145
 
1138
1146
  if req.get("session_id"):
1139
1147
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gemcode
3
- Version: 0.4.28
3
+ Version: 0.4.30
4
4
  Summary: Local-first coding agent on Google Gemini + ADK
5
5
  Author: GemCode Contributors
6
6
  License: Apache License
@@ -130,23 +130,23 @@ gemcode/web/customize_api.py,sha256=Et1HY49lleZlCBywsBg9n61KFReqTB0wGQrDmhrNEf4,
130
130
  gemcode/web/files_api.py,sha256=sdlSd3gj3TF_qrH2xYy70CTWMXAIzqouWe6uDkMrroo,7724
131
131
  gemcode/web/fleet_api.py,sha256=4lR7lWqpMojaAL7_c6rjjA5hMFnnUgpI1T561RvM-3w,19276
132
132
  gemcode/web/hitl_bridge.py,sha256=08rzUmVDiY6eAsMXZ-oE-XLPK5gk-wAGIFxDY2QlobA,5465
133
- gemcode/web/preview_api.py,sha256=mE6izq2TZfrBmiLAJRaZlyKxWYlv6b6SQfh7HoS_E18,10795
133
+ gemcode/web/preview_api.py,sha256=si8BduQX5VSjJntOQJAf6PIs8NC9qNwfMx4MBYizHbA,12275
134
134
  gemcode/web/project_root.py,sha256=rMKsp2va2z1p9CI-NKzbdJq2hyKXtNzDSLyTk-tV8Ws,1936
135
135
  gemcode/web/runtime_api.py,sha256=BezPpbNnj85aXiL5r7aXGcA3FFubadY7lHtskaNPgMc,12935
136
136
  gemcode/web/serve_bind.py,sha256=Q6odfJuoTw8hIn3Hq8jcLe6EvRB1_wj4klrOBjKdTiE,3097
137
137
  gemcode/web/serve_state.py,sha256=wTHaZ4CGjZYOxRMlKmFUEMpFoBPnci20GLbMjxGdGG0,6265
138
138
  gemcode/web/server.py,sha256=pBQ9MfzGkTbRR-Oz8xtPc7KbFINc4qbycXPUrGoPhj8,28123
139
139
  gemcode/web/sessions_api.py,sha256=4qudnYLiqIbUixon1PsV8yfBf6tu6llWLc_ESTFK61g,2008
140
- gemcode/web/sse_adapter.py,sha256=zZA2-EXz3dmmFe98F4IWQYDYgqz378yrSYiEilKo_dE,44283
140
+ gemcode/web/sse_adapter.py,sha256=_RfPyKbUEnIg7B7_v80fWZ-r6trJG8L7viscV5I798o,44821
141
141
  gemcode/web/terminal_api.py,sha256=2FWU0XQ6CVUFW_JJiVukFPdj_sgsYa_y7IQb9brxCZw,3329
142
142
  gemcode/web/terminal_repl.py,sha256=fQt895g0qcr6VBhXfv_5b_bsC5zHT5-MO0ysBdgi2Fg,3886
143
143
  gemcode/web/ui_chat_store.py,sha256=sThUOcWC-svx-e2pt88ZazPrWelN2JbqeDicU7s5iUg,2377
144
144
  gemcode/web/web_config_api.py,sha256=1kmk1vSu5z63loddTNBHVsisiYy4CfyVIF93TYCgEqs,2264
145
145
  gemcode/web/web_sse_compat.py,sha256=9A2s-GI7El7AotJqhO263FrLwppCXXkdydZ5EiOQbao,504
146
146
  gemcode/web/workspace_panel_api.py,sha256=uZS11ovlZtc1IJDnOA776Z6IndC0WovcBbmPMnZyIHs,14122
147
- gemcode-0.4.28.dist-info/licenses/LICENSE,sha256=TD4524qn-W8Z07GTDnag-9jJPFutFZNB0a1WbMHPC54,8388
148
- gemcode-0.4.28.dist-info/METADATA,sha256=Wv7RNkngc-y6S9c3Vk21Lf1Ve_lgVxeYIrg453iRyBc,27378
149
- gemcode-0.4.28.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
150
- gemcode-0.4.28.dist-info/entry_points.txt,sha256=cZdLTLDiHbks7OSUCuxCh66dCWeQdpLR8BozoqfEjV4,45
151
- gemcode-0.4.28.dist-info/top_level.txt,sha256=UYrjULLBY2bcgK6KI6flomJWmsbDXu7n0rvW2SWFrbo,8
152
- gemcode-0.4.28.dist-info/RECORD,,
147
+ gemcode-0.4.30.dist-info/licenses/LICENSE,sha256=TD4524qn-W8Z07GTDnag-9jJPFutFZNB0a1WbMHPC54,8388
148
+ gemcode-0.4.30.dist-info/METADATA,sha256=nNxBDl1SoNbEYKzLUShn7WTQqmVhjyCXJQEezPR5wpY,27378
149
+ gemcode-0.4.30.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
150
+ gemcode-0.4.30.dist-info/entry_points.txt,sha256=cZdLTLDiHbks7OSUCuxCh66dCWeQdpLR8BozoqfEjV4,45
151
+ gemcode-0.4.30.dist-info/top_level.txt,sha256=UYrjULLBY2bcgK6KI6flomJWmsbDXu7n0rvW2SWFrbo,8
152
+ gemcode-0.4.30.dist-info/RECORD,,