evalstate HF Staff commited on
Commit
496b510
·
verified ·
1 Parent(s): 70c959f

Deploy OpenClaw PR API

Browse files
src/slop_farmer/app/pr_search.py CHANGED
@@ -41,17 +41,16 @@ def format_pr_search_status(result: Mapping[str, Any]) -> str:
41
 
42
 
43
  def format_pr_search_similar(result: Mapping[str, Any]) -> str:
 
 
 
44
  lines = [
45
  f"PR #{result['pr']['pr_number']}: {result['pr']['title']}",
46
  "",
47
  f"Active snapshot: {result['snapshot_id']}",
 
48
  "",
49
  ]
50
- query = result.get("query") or {}
51
- if query.get("mode_used") == "live":
52
- source = query.get("source") or "live"
53
- lines.insert(3, f"Lookup mode: live via {source}")
54
- lines.insert(4, "")
55
  if not result["similar_prs"]:
56
  lines.append("No similar PRs found in the active run.")
57
  return "\n".join(lines)
@@ -96,16 +95,17 @@ def format_pr_search_candidate_clusters(result: Mapping[str, Any]) -> str:
96
 
97
 
98
  def format_pr_search_clusters(result: Mapping[str, Any]) -> str:
 
 
 
99
  lines = [
100
  f"PR #{result['pr']['pr_number']}: cluster context",
101
  "",
 
 
 
102
  ]
103
- query = result.get("query") or {}
104
- if query.get("mode_used") == "live":
105
- source = query.get("source") or "live"
106
- lines.extend([f"Lookup mode: live via {source}", ""])
107
  assigned_clusters = result.get("assigned_clusters") or []
108
- lines.append("Assigned clusters:")
109
  if not assigned_clusters:
110
  lines.append("- none")
111
  else:
 
41
 
42
 
43
  def format_pr_search_similar(result: Mapping[str, Any]) -> str:
44
+ query = result.get("query") or {}
45
+ mode_used = str(query.get("mode_used") or "indexed")
46
+ source = str(query.get("source") or "active_index")
47
  lines = [
48
  f"PR #{result['pr']['pr_number']}: {result['pr']['title']}",
49
  "",
50
  f"Active snapshot: {result['snapshot_id']}",
51
+ f"Lookup: {mode_used} via {source}",
52
  "",
53
  ]
 
 
 
 
 
54
  if not result["similar_prs"]:
55
  lines.append("No similar PRs found in the active run.")
56
  return "\n".join(lines)
 
95
 
96
 
97
  def format_pr_search_clusters(result: Mapping[str, Any]) -> str:
98
+ query = result.get("query") or {}
99
+ mode_used = str(query.get("mode_used") or "indexed")
100
+ source = str(query.get("source") or "active_index")
101
  lines = [
102
  f"PR #{result['pr']['pr_number']}: cluster context",
103
  "",
104
+ f"Lookup: {mode_used} via {source}",
105
+ "",
106
+ "Assigned clusters:",
107
  ]
 
 
 
 
108
  assigned_clusters = result.get("assigned_clusters") or []
 
109
  if not assigned_clusters:
110
  lines.append("- none")
111
  else:
src/slop_farmer/reports/pr_search_service.py CHANGED
@@ -1,7 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import json
4
- from collections.abc import Iterable
5
  from contextlib import suppress
6
  from pathlib import Path
7
  from typing import Any, Protocol
@@ -195,7 +195,8 @@ def get_pr_search_status(db_path: Path, *, repo: str | None = None) -> dict[str,
195
  try:
196
  active_run = resolve_active_run(connection, repo=repo)
197
  return {
198
- **active_run,
 
199
  "row_counts": get_run_counts(connection, run_id=str(active_run["id"])),
200
  }
201
  finally:
@@ -226,7 +227,7 @@ def get_pr_search_similar(
226
  for row in similar_rows:
227
  results.append(
228
  {
229
- **row,
230
  "neighbor_title": _require_document(
231
  connection,
232
  run_id=run_id,
@@ -268,7 +269,7 @@ def get_pr_search_candidate_clusters(
268
  evidence = _json_dict(row.get("evidence_json"))
269
  candidates.append(
270
  {
271
- **row,
272
  "shared_filenames": _json_list(row.get("shared_filenames_json")),
273
  "shared_directories": _json_list(row.get("shared_directories_json")),
274
  "evidence": evidence,
@@ -407,11 +408,7 @@ def get_pr_search_cluster(
407
  "repo": active_run["repo"],
408
  "snapshot_id": active_run["snapshot_id"],
409
  "run_id": run_id,
410
- "cluster": {
411
- **cluster,
412
- "shared_filenames": _json_list(cluster.get("shared_filenames_json")),
413
- "shared_directories": _json_list(cluster.get("shared_directories_json")),
414
- },
415
  "members": members,
416
  }
417
  finally:
@@ -758,7 +755,7 @@ def _get_pr_search_clusters_indexed(
758
  evidence = _json_dict(row.get("evidence_json"))
759
  candidates.append(
760
  {
761
- **row,
762
  "shared_filenames": _json_list(row.get("shared_filenames_json")),
763
  "shared_directories": _json_list(row.get("shared_directories_json")),
764
  "evidence": evidence,
@@ -819,12 +816,16 @@ def _json_float_dict(raw: Any) -> dict[str, float]:
819
 
820
  def _cluster_summary(cluster: dict[str, Any]) -> dict[str, Any]:
821
  return {
822
- **cluster,
823
  "shared_filenames": _json_list(cluster.get("shared_filenames_json")),
824
  "shared_directories": _json_list(cluster.get("shared_directories_json")),
825
  }
826
 
827
 
 
 
 
 
828
  def _normalize_lookup_mode(mode: str) -> str:
829
  normalized = mode.strip().lower()
830
  if normalized not in {"auto", "indexed", "live"}:
 
1
  from __future__ import annotations
2
 
3
  import json
4
+ from collections.abc import Iterable, Mapping
5
  from contextlib import suppress
6
  from pathlib import Path
7
  from typing import Any, Protocol
 
195
  try:
196
  active_run = resolve_active_run(connection, repo=repo)
197
  return {
198
+ **_without_json_fields(active_run),
199
+ "settings": _json_dict(active_run.get("settings_json")),
200
  "row_counts": get_run_counts(connection, run_id=str(active_run["id"])),
201
  }
202
  finally:
 
227
  for row in similar_rows:
228
  results.append(
229
  {
230
+ **_without_json_fields(row),
231
  "neighbor_title": _require_document(
232
  connection,
233
  run_id=run_id,
 
269
  evidence = _json_dict(row.get("evidence_json"))
270
  candidates.append(
271
  {
272
+ **_without_json_fields(row),
273
  "shared_filenames": _json_list(row.get("shared_filenames_json")),
274
  "shared_directories": _json_list(row.get("shared_directories_json")),
275
  "evidence": evidence,
 
408
  "repo": active_run["repo"],
409
  "snapshot_id": active_run["snapshot_id"],
410
  "run_id": run_id,
411
+ "cluster": _cluster_summary(cluster),
 
 
 
 
412
  "members": members,
413
  }
414
  finally:
 
755
  evidence = _json_dict(row.get("evidence_json"))
756
  candidates.append(
757
  {
758
+ **_without_json_fields(row),
759
  "shared_filenames": _json_list(row.get("shared_filenames_json")),
760
  "shared_directories": _json_list(row.get("shared_directories_json")),
761
  "evidence": evidence,
 
816
 
817
  def _cluster_summary(cluster: dict[str, Any]) -> dict[str, Any]:
818
  return {
819
+ **_without_json_fields(cluster),
820
  "shared_filenames": _json_list(cluster.get("shared_filenames_json")),
821
  "shared_directories": _json_list(cluster.get("shared_directories_json")),
822
  }
823
 
824
 
825
+ def _without_json_fields(row: Mapping[str, Any]) -> dict[str, Any]:
826
+ return {str(key): value for key, value in row.items() if not str(key).endswith("_json")}
827
+
828
+
829
  def _normalize_lookup_mode(mode: str) -> str:
830
  normalized = mode.strip().lower()
831
  if normalized not in {"auto", "indexed", "live"}: