code-context-control 2.159.2__py3-none-any.whl → 2.161.0__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.
- cli/c3.py +16 -5
- cli/hub_server.py +174 -83
- cli/hub_ui/components/modals.js +16 -11
- cli/hub_ui/components/settings_modal.js +9 -2
- {code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/METADATA +1 -1
- {code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/RECORD +14 -14
- oracle/services/mobile_api.py +20 -1
- oracle/services/schedule_api.py +89 -1
- services/schedule_runner.py +253 -10
- services/schedule_store.py +14 -1
- {code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/WHEEL +0 -0
- {code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/entry_points.txt +0 -0
- {code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/licenses/LICENSE +0 -0
- {code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/top_level.txt +0 -0
cli/c3.py
CHANGED
|
@@ -96,7 +96,7 @@ console = Console() if HAS_RICH else None
|
|
|
96
96
|
# Config
|
|
97
97
|
CONFIG_DIR = ".c3"
|
|
98
98
|
CONFIG_FILE = ".c3/config.json"
|
|
99
|
-
__version__ = "2.
|
|
99
|
+
__version__ = "2.161.0"
|
|
100
100
|
|
|
101
101
|
# The PreToolUse matcher for native subagent calls (installer and hub migration).
|
|
102
102
|
AGENT_MATCHER = "Agent|Task"
|
|
@@ -5172,12 +5172,19 @@ def _ensure_global_claude_md() -> None:
|
|
|
5172
5172
|
- Creates the file if it doesn't exist.
|
|
5173
5173
|
- Updates the C3 section if present but outdated.
|
|
5174
5174
|
- Preserves any user-written content outside the C3 section.
|
|
5175
|
+
|
|
5176
|
+
Every install-mcp calls this, and the hub's batch update runs several
|
|
5177
|
+
installs at once. An unchanged file is left alone, and a changed one is
|
|
5178
|
+
replaced atomically: a plain truncate-and-write let a concurrent run read
|
|
5179
|
+
the file empty and write back the C3 block alone, dropping the user's text.
|
|
5175
5180
|
"""
|
|
5181
|
+
from services.atomic_json import write_text_atomic
|
|
5182
|
+
|
|
5176
5183
|
global_md = Path.home() / ".claude" / "CLAUDE.md"
|
|
5177
5184
|
global_md.parent.mkdir(parents=True, exist_ok=True)
|
|
5178
5185
|
|
|
5179
5186
|
if not global_md.exists():
|
|
5180
|
-
global_md
|
|
5187
|
+
write_text_atomic(global_md, _GLOBAL_CLAUDE_MD_CONTENT)
|
|
5181
5188
|
print(f"Wrote {global_md} (global C3 enforcement)")
|
|
5182
5189
|
return
|
|
5183
5190
|
|
|
@@ -5193,7 +5200,11 @@ def _ensure_global_claude_md() -> None:
|
|
|
5193
5200
|
|
|
5194
5201
|
# Markers already present → surgical, marker-bounded replacement.
|
|
5195
5202
|
if C3_BLOCK_BEGIN in existing:
|
|
5196
|
-
|
|
5203
|
+
merged = merge_c3_block(existing, wrapped)
|
|
5204
|
+
if merged == existing:
|
|
5205
|
+
print(f"Kept {global_md} (C3 enforcement up to date)")
|
|
5206
|
+
return
|
|
5207
|
+
write_text_atomic(global_md, merged)
|
|
5197
5208
|
print(f"Updated {global_md} (refreshed C3 enforcement)")
|
|
5198
5209
|
return
|
|
5199
5210
|
|
|
@@ -5217,13 +5228,13 @@ def _ensure_global_claude_md() -> None:
|
|
|
5217
5228
|
before = existing[:start].rstrip()
|
|
5218
5229
|
after = existing[end:].lstrip()
|
|
5219
5230
|
parts = [p for p in (before, wrapped, after) if p]
|
|
5220
|
-
global_md
|
|
5231
|
+
write_text_atomic(global_md, "\n\n".join(parts) + "\n")
|
|
5221
5232
|
print(f"Updated {global_md} (migrated C3 enforcement to markers)")
|
|
5222
5233
|
return
|
|
5223
5234
|
|
|
5224
5235
|
# User has their own CLAUDE.md with no C3 content — append the marked block.
|
|
5225
5236
|
merged = existing.rstrip() + "\n\n" + wrapped + "\n"
|
|
5226
|
-
global_md
|
|
5237
|
+
write_text_atomic(global_md, merged)
|
|
5227
5238
|
print(f"Updated {global_md} (appended C3 enforcement)")
|
|
5228
5239
|
|
|
5229
5240
|
|
cli/hub_server.py
CHANGED
|
@@ -526,6 +526,11 @@ def api_hub_config_set():
|
|
|
526
526
|
cfg["runtime_cache_size"] = max(1, int(data["runtime_cache_size"]))
|
|
527
527
|
except (ValueError, TypeError):
|
|
528
528
|
return jsonify({"error": "runtime_cache_size must be an integer"}), 400
|
|
529
|
+
if "update_workers" in data:
|
|
530
|
+
try:
|
|
531
|
+
cfg["update_workers"] = max(1, min(int(data["update_workers"]), _UPDATE_WORKERS_MAX))
|
|
532
|
+
except (ValueError, TypeError):
|
|
533
|
+
return jsonify({"error": "update_workers must be an integer"}), 400
|
|
529
534
|
_write_hub_config(cfg)
|
|
530
535
|
return jsonify({"saved": True, "config": cfg})
|
|
531
536
|
|
|
@@ -1246,12 +1251,90 @@ def api_run_component():
|
|
|
1246
1251
|
return jsonify({"error": str(e), "success": False}), 500
|
|
1247
1252
|
|
|
1248
1253
|
|
|
1254
|
+
# A first embedding build on a large project takes minutes, far past the
|
|
1255
|
+
# _run_c3 default.
|
|
1256
|
+
_UPDATE_TIMEOUT_S = 600
|
|
1257
|
+
_UPDATE_WORKERS_DEFAULT = 3
|
|
1258
|
+
_UPDATE_WORKERS_MAX = 8
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
def _update_workers() -> int:
|
|
1262
|
+
"""Projects updated at once: hub config ``update_workers``, clamped to 1-8."""
|
|
1263
|
+
try:
|
|
1264
|
+
n = int(_read_hub_config().get("update_workers") or _UPDATE_WORKERS_DEFAULT)
|
|
1265
|
+
except (ValueError, TypeError):
|
|
1266
|
+
n = _UPDATE_WORKERS_DEFAULT
|
|
1267
|
+
return max(1, min(n, _UPDATE_WORKERS_MAX))
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
def _run_pooled(items: list, run_one, state: dict, lock, workers: int) -> None:
|
|
1271
|
+
"""Run ``run_one(item) -> row`` over ``items`` on up to ``workers`` threads.
|
|
1272
|
+
|
|
1273
|
+
Records each row in ``state["results"]`` as it finishes and keeps the
|
|
1274
|
+
paths being worked on in ``state["in_progress"]``. Items not yet started
|
|
1275
|
+
when ``state["cancelled"]`` is set are skipped; running ones finish.
|
|
1276
|
+
``run_one`` must return a row rather than raise.
|
|
1277
|
+
"""
|
|
1278
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
1279
|
+
|
|
1280
|
+
def task(index, item):
|
|
1281
|
+
path = item.get("path")
|
|
1282
|
+
with lock:
|
|
1283
|
+
if state["cancelled"]:
|
|
1284
|
+
return
|
|
1285
|
+
state["in_progress"].append(path)
|
|
1286
|
+
state["current"] = item.get("name") or path
|
|
1287
|
+
state["current_index"] = index
|
|
1288
|
+
t0 = time.time()
|
|
1289
|
+
row = run_one(item)
|
|
1290
|
+
row.setdefault("elapsed_ms", int((time.time() - t0) * 1000))
|
|
1291
|
+
with lock:
|
|
1292
|
+
state["results"].append(row)
|
|
1293
|
+
state["in_progress"].remove(path)
|
|
1294
|
+
if not state["in_progress"]:
|
|
1295
|
+
state["current"] = None
|
|
1296
|
+
|
|
1297
|
+
with ThreadPoolExecutor(max_workers=max(1, workers),
|
|
1298
|
+
thread_name_prefix="c3-hub-update") as pool:
|
|
1299
|
+
list(pool.map(task, range(len(items)), items))
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
def _dedupe_by_path(items: list) -> list:
|
|
1303
|
+
seen, out = set(), []
|
|
1304
|
+
for item in items:
|
|
1305
|
+
key = os.path.normcase(os.path.normpath(str(item.get("path") or "")))
|
|
1306
|
+
if key and key not in seen:
|
|
1307
|
+
seen.add(key)
|
|
1308
|
+
out.append(item)
|
|
1309
|
+
return out
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
def _update_project_row(p: dict) -> dict:
|
|
1313
|
+
"""Run ``c3 init --force`` for one project and return its result row."""
|
|
1314
|
+
path = p["path"]
|
|
1315
|
+
row = {"path": path, "name": p.get("name")}
|
|
1316
|
+
if not Path(path).is_dir():
|
|
1317
|
+
row.update(success=False, skipped=True, output="Project folder not found.",
|
|
1318
|
+
returncode=None)
|
|
1319
|
+
return row
|
|
1320
|
+
args = ["init", path, "--force"]
|
|
1321
|
+
ide = p.get("ide")
|
|
1322
|
+
if ide and ide not in ("unknown", "auto"):
|
|
1323
|
+
args += ["--ide", ide]
|
|
1324
|
+
res = _run_c3(args, timeout=_UPDATE_TIMEOUT_S)
|
|
1325
|
+
row.update(success=res.get("success"), output=res.get("output"),
|
|
1326
|
+
returncode=res.get("returncode"))
|
|
1327
|
+
return row
|
|
1328
|
+
|
|
1329
|
+
|
|
1249
1330
|
_batch_state = {
|
|
1250
1331
|
"running": False,
|
|
1251
1332
|
"cancelled": False,
|
|
1252
1333
|
"results": [],
|
|
1253
1334
|
"current": None,
|
|
1254
1335
|
"current_index": 0,
|
|
1336
|
+
"in_progress": [],
|
|
1337
|
+
"workers": 1,
|
|
1255
1338
|
"total": 0,
|
|
1256
1339
|
"done": False,
|
|
1257
1340
|
"error": None,
|
|
@@ -1259,37 +1342,19 @@ _batch_state = {
|
|
|
1259
1342
|
_batch_lock = threading.Lock()
|
|
1260
1343
|
|
|
1261
1344
|
|
|
1262
|
-
def _batch_worker(projects):
|
|
1345
|
+
def _batch_worker(projects, workers: int = 1):
|
|
1263
1346
|
"""Run batch init in background thread, updating _batch_state."""
|
|
1264
|
-
|
|
1265
|
-
|
|
1347
|
+
try:
|
|
1348
|
+
_run_pooled(projects, _update_project_row, _batch_state, _batch_lock, workers)
|
|
1349
|
+
except Exception as e:
|
|
1266
1350
|
with _batch_lock:
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
_batch_state["current"] = p.get("name") or p["path"]
|
|
1270
|
-
_batch_state["current_index"] = i
|
|
1271
|
-
|
|
1272
|
-
path = p["path"]
|
|
1273
|
-
args = ["init", path, "--force"]
|
|
1274
|
-
ide = p.get("ide")
|
|
1275
|
-
if ide and ide != "unknown":
|
|
1276
|
-
args += ["--ide", ide]
|
|
1277
|
-
|
|
1278
|
-
res = _run_c3(args)
|
|
1279
|
-
result = {
|
|
1280
|
-
"path": path,
|
|
1281
|
-
"name": p.get("name"),
|
|
1282
|
-
"success": res.get("success"),
|
|
1283
|
-
"output": res.get("output"),
|
|
1284
|
-
"returncode": res.get("returncode"),
|
|
1285
|
-
}
|
|
1351
|
+
_batch_state["error"] = str(e)
|
|
1352
|
+
finally:
|
|
1286
1353
|
with _batch_lock:
|
|
1287
|
-
_batch_state["
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
_batch_state["done"] = True
|
|
1292
|
-
_batch_state["current"] = None
|
|
1354
|
+
_batch_state["running"] = False
|
|
1355
|
+
_batch_state["done"] = True
|
|
1356
|
+
_batch_state["current"] = None
|
|
1357
|
+
_batch_state["in_progress"] = []
|
|
1293
1358
|
|
|
1294
1359
|
|
|
1295
1360
|
@app.route("/api/projects/run-init/batch", methods=["POST"])
|
|
@@ -1301,9 +1366,10 @@ def api_run_init_batch():
|
|
|
1301
1366
|
return jsonify({"error": "Batch update already in progress"}), 409
|
|
1302
1367
|
try:
|
|
1303
1368
|
data = request.get_json(force=True) or {}
|
|
1304
|
-
projects = data.get("projects") or _pm().list_projects()
|
|
1369
|
+
projects = _dedupe_by_path(data.get("projects") or _pm().list_projects())
|
|
1305
1370
|
if not projects:
|
|
1306
1371
|
return jsonify({"error": "No projects to update"}), 400
|
|
1372
|
+
workers = _update_workers()
|
|
1307
1373
|
with _batch_lock:
|
|
1308
1374
|
_batch_state = {
|
|
1309
1375
|
"running": True,
|
|
@@ -1311,13 +1377,15 @@ def api_run_init_batch():
|
|
|
1311
1377
|
"results": [],
|
|
1312
1378
|
"current": None,
|
|
1313
1379
|
"current_index": 0,
|
|
1380
|
+
"in_progress": [],
|
|
1381
|
+
"workers": workers,
|
|
1314
1382
|
"total": len(projects),
|
|
1315
1383
|
"done": False,
|
|
1316
1384
|
"error": None,
|
|
1317
1385
|
}
|
|
1318
|
-
t = threading.Thread(target=_batch_worker, args=(projects,), daemon=True)
|
|
1386
|
+
t = threading.Thread(target=_batch_worker, args=(projects, workers), daemon=True)
|
|
1319
1387
|
t.start()
|
|
1320
|
-
return jsonify({"started": True, "total": len(projects)})
|
|
1388
|
+
return jsonify({"started": True, "total": len(projects), "workers": workers})
|
|
1321
1389
|
except Exception as e:
|
|
1322
1390
|
return jsonify({"error": str(e)}), 500
|
|
1323
1391
|
|
|
@@ -1326,7 +1394,10 @@ def api_run_init_batch():
|
|
|
1326
1394
|
def api_batch_status():
|
|
1327
1395
|
"""Return current batch update state for polling."""
|
|
1328
1396
|
with _batch_lock:
|
|
1329
|
-
|
|
1397
|
+
snap = dict(_batch_state)
|
|
1398
|
+
snap["results"] = list(snap.get("results") or [])
|
|
1399
|
+
snap["in_progress"] = list(snap.get("in_progress") or [])
|
|
1400
|
+
return jsonify(snap)
|
|
1330
1401
|
|
|
1331
1402
|
|
|
1332
1403
|
@app.route("/api/projects/run-init/batch/cancel", methods=["POST"])
|
|
@@ -1695,59 +1766,65 @@ def api_subprojects_reconcile():
|
|
|
1695
1766
|
|
|
1696
1767
|
_sub_cascade_state = {
|
|
1697
1768
|
"running": False, "cancelled": False, "results": [],
|
|
1698
|
-
"current": None, "current_index": 0, "
|
|
1699
|
-
"done": False, "error": None, "op": None, "parent": None,
|
|
1769
|
+
"current": None, "current_index": 0, "in_progress": [], "workers": 1,
|
|
1770
|
+
"total": 0, "done": False, "error": None, "op": None, "parent": None,
|
|
1700
1771
|
}
|
|
1701
1772
|
_sub_cascade_lock = threading.Lock()
|
|
1702
1773
|
|
|
1703
1774
|
|
|
1704
|
-
def
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1775
|
+
def _sub_cascade_row(op: str, child: dict) -> dict:
|
|
1776
|
+
path = child.get("path")
|
|
1777
|
+
row = {"path": path, "name": child.get("name"), "success": False, "output": ""}
|
|
1778
|
+
try:
|
|
1779
|
+
if child.get("status") == "missing_folder":
|
|
1780
|
+
row["output"] = "missing_folder"
|
|
1781
|
+
elif child.get("status") == "missing_c3" and op != "update":
|
|
1782
|
+
row["output"] = "missing_c3"
|
|
1783
|
+
elif op == "update":
|
|
1784
|
+
res = _run_c3(["init", path, "--force"], timeout=_UPDATE_TIMEOUT_S)
|
|
1785
|
+
row["success"] = bool(res.get("success"))
|
|
1786
|
+
row["output"] = res.get("output", "")
|
|
1787
|
+
elif op == "reindex":
|
|
1788
|
+
from services.doc_index import DocIndex
|
|
1789
|
+
from services.indexer import CodeIndex
|
|
1790
|
+
r = CodeIndex(path).build_index()
|
|
1791
|
+
try:
|
|
1792
|
+
DocIndex(path).build()
|
|
1793
|
+
except Exception:
|
|
1794
|
+
pass
|
|
1795
|
+
row["success"] = True
|
|
1796
|
+
row["output"] = (f"{r.get('files_indexed', 0)} files, "
|
|
1797
|
+
f"{r.get('chunks_created', 0)} chunks")
|
|
1798
|
+
elif op == "health":
|
|
1799
|
+
from cli.c3 import _check_c3_health
|
|
1800
|
+
info = _check_c3_health(path)
|
|
1801
|
+
row["success"] = bool(info.get("healthy"))
|
|
1802
|
+
row["output"] = "healthy" if row["success"] else "; ".join(info.get("issues", []))
|
|
1803
|
+
except Exception as e:
|
|
1804
|
+
row["output"] = str(e)
|
|
1805
|
+
return row
|
|
1806
|
+
|
|
1807
|
+
|
|
1808
|
+
def _sub_cascade_worker(op: str, targets: list, workers: int = 1):
|
|
1809
|
+
"""Per-child cascade in a background thread (progress + cancel like batch init).
|
|
1810
|
+
|
|
1811
|
+
Only ``update`` runs in subprocesses, so only it uses more than one worker;
|
|
1812
|
+
reindex and health build indexes inside the hub process.
|
|
1813
|
+
"""
|
|
1814
|
+
try:
|
|
1815
|
+
_run_pooled(targets, lambda child: _sub_cascade_row(op, child),
|
|
1816
|
+
_sub_cascade_state, _sub_cascade_lock,
|
|
1817
|
+
workers if op == "update" else 1)
|
|
1818
|
+
except Exception as e:
|
|
1708
1819
|
with _sub_cascade_lock:
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
_sub_cascade_state["current"] = child.get("name") or child.get("path")
|
|
1712
|
-
_sub_cascade_state["current_index"] = i
|
|
1713
|
-
path = child.get("path")
|
|
1714
|
-
t0 = time.time()
|
|
1715
|
-
row = {"path": path, "name": child.get("name"), "success": False, "output": ""}
|
|
1716
|
-
try:
|
|
1717
|
-
if child.get("status") == "missing_folder":
|
|
1718
|
-
row["output"] = "missing_folder"
|
|
1719
|
-
elif child.get("status") == "missing_c3" and op != "update":
|
|
1720
|
-
row["output"] = "missing_c3"
|
|
1721
|
-
elif op == "update":
|
|
1722
|
-
res = _run_c3(["init", path, "--force"], timeout=600)
|
|
1723
|
-
row["success"] = bool(res.get("success"))
|
|
1724
|
-
row["output"] = res.get("output", "")
|
|
1725
|
-
elif op == "reindex":
|
|
1726
|
-
from services.doc_index import DocIndex
|
|
1727
|
-
from services.indexer import CodeIndex
|
|
1728
|
-
r = CodeIndex(path).build_index()
|
|
1729
|
-
try:
|
|
1730
|
-
DocIndex(path).build()
|
|
1731
|
-
except Exception:
|
|
1732
|
-
pass
|
|
1733
|
-
row["success"] = True
|
|
1734
|
-
row["output"] = (f"{r.get('files_indexed', 0)} files, "
|
|
1735
|
-
f"{r.get('chunks_created', 0)} chunks")
|
|
1736
|
-
elif op == "health":
|
|
1737
|
-
from cli.c3 import _check_c3_health
|
|
1738
|
-
info = _check_c3_health(path)
|
|
1739
|
-
row["success"] = bool(info.get("healthy"))
|
|
1740
|
-
row["output"] = "healthy" if row["success"] else "; ".join(info.get("issues", []))
|
|
1741
|
-
except Exception as e:
|
|
1742
|
-
row["output"] = str(e)
|
|
1743
|
-
row["elapsed_ms"] = int((time.time() - t0) * 1000)
|
|
1820
|
+
_sub_cascade_state["error"] = str(e)
|
|
1821
|
+
finally:
|
|
1744
1822
|
with _sub_cascade_lock:
|
|
1745
|
-
_sub_cascade_state["
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
_invalidate_subproject_links()
|
|
1823
|
+
_sub_cascade_state["running"] = False
|
|
1824
|
+
_sub_cascade_state["done"] = True
|
|
1825
|
+
_sub_cascade_state["current"] = None
|
|
1826
|
+
_sub_cascade_state["in_progress"] = []
|
|
1827
|
+
_invalidate_subproject_links()
|
|
1751
1828
|
|
|
1752
1829
|
|
|
1753
1830
|
@app.route("/api/projects/subprojects/cascade", methods=["POST"])
|
|
@@ -1777,19 +1854,23 @@ def api_subprojects_cascade():
|
|
|
1777
1854
|
targets = [t for t in listed if t not in skipped]
|
|
1778
1855
|
if data.get("include_parent"):
|
|
1779
1856
|
targets.append({"name": "(parent)", "path": sm.parent_path, "status": "ok"})
|
|
1857
|
+
targets = _dedupe_by_path(targets)
|
|
1858
|
+
workers = _update_workers() if op == "update" else 1
|
|
1780
1859
|
if not targets:
|
|
1781
1860
|
return jsonify({"error": "No cascade-eligible sub-projects"
|
|
1782
1861
|
+ (f" ({len(skipped)} skipped)" if skipped else "")}), 400
|
|
1783
1862
|
with _sub_cascade_lock:
|
|
1784
1863
|
_sub_cascade_state = {
|
|
1785
1864
|
"running": True, "cancelled": False, "results": [],
|
|
1786
|
-
"current": None, "current_index": 0, "
|
|
1865
|
+
"current": None, "current_index": 0, "in_progress": [],
|
|
1866
|
+
"workers": workers, "total": len(targets),
|
|
1787
1867
|
"done": False, "error": None, "op": op, "parent": sm.parent_path,
|
|
1788
1868
|
}
|
|
1789
|
-
t = threading.Thread(target=_sub_cascade_worker, args=(op, targets
|
|
1869
|
+
t = threading.Thread(target=_sub_cascade_worker, args=(op, targets, workers),
|
|
1870
|
+
daemon=True)
|
|
1790
1871
|
t.start()
|
|
1791
1872
|
return jsonify({"started": True, "total": len(targets), "op": op,
|
|
1792
|
-
"skipped": len(skipped)})
|
|
1873
|
+
"skipped": len(skipped), "workers": workers})
|
|
1793
1874
|
except ValueError as e:
|
|
1794
1875
|
return jsonify({"error": str(e)}), 404
|
|
1795
1876
|
except Exception as e:
|
|
@@ -1799,7 +1880,10 @@ def api_subprojects_cascade():
|
|
|
1799
1880
|
@app.route("/api/projects/subprojects/cascade/status", methods=["GET"])
|
|
1800
1881
|
def api_subprojects_cascade_status():
|
|
1801
1882
|
with _sub_cascade_lock:
|
|
1802
|
-
|
|
1883
|
+
snap = dict(_sub_cascade_state)
|
|
1884
|
+
snap["results"] = list(snap.get("results") or [])
|
|
1885
|
+
snap["in_progress"] = list(snap.get("in_progress") or [])
|
|
1886
|
+
return jsonify(snap)
|
|
1803
1887
|
|
|
1804
1888
|
|
|
1805
1889
|
@app.route("/api/projects/subprojects/cascade/cancel", methods=["POST"])
|
|
@@ -3265,6 +3349,13 @@ def api_hub_schedule_runs():
|
|
|
3265
3349
|
return jsonify({"runs": _sched_with_names(rows), "count": len(rows), "project": project_path})
|
|
3266
3350
|
|
|
3267
3351
|
|
|
3352
|
+
@app.route("/api/hub/schedules/runs/<run_id>/output", methods=["GET"])
|
|
3353
|
+
def api_hub_schedule_run_output(run_id):
|
|
3354
|
+
data, err = _sched_call(_schedule_api().run_output, str(run_id), after=request.args.get("after"),
|
|
3355
|
+
limit=request.args.get("limit"))
|
|
3356
|
+
return err or jsonify(data)
|
|
3357
|
+
|
|
3358
|
+
|
|
3268
3359
|
@app.route("/api/hub/schedules/approvals", methods=["GET"])
|
|
3269
3360
|
def api_hub_schedule_approvals():
|
|
3270
3361
|
project_path, err = _sched_project_arg()
|
cli/hub_ui/components/modals.js
CHANGED
|
@@ -1325,12 +1325,14 @@ function BatchUpdateModal({ projects, onClose, onChanged }) {
|
|
|
1325
1325
|
const total = (state && state.total) || (targets ? targets.length : 0) || 1;
|
|
1326
1326
|
const findResult = (p) => results.find(r => (r.path || '').toLowerCase() === (p.path || '').toLowerCase());
|
|
1327
1327
|
const okCount = results.filter(r => r.success).length;
|
|
1328
|
-
const
|
|
1328
|
+
const skipCount = results.filter(r => r.skipped).length;
|
|
1329
|
+
const failCount = results.filter(r => !r.success && !r.skipped).length;
|
|
1330
|
+
const inProgress = ((state && state.in_progress) || []).map(x => (x || '').toLowerCase());
|
|
1329
1331
|
|
|
1330
|
-
const rowStatus = (p
|
|
1332
|
+
const rowStatus = (p) => {
|
|
1331
1333
|
const r = findResult(p);
|
|
1332
|
-
if (r) return r.success ? 'done' : 'failed';
|
|
1333
|
-
if (phase === 'running' && state && state.running &&
|
|
1334
|
+
if (r) return r.success ? 'done' : r.skipped ? 'skipped' : 'failed';
|
|
1335
|
+
if (phase === 'running' && state && state.running && inProgress.includes((p.path || '').toLowerCase())) return 'running';
|
|
1334
1336
|
return 'pending';
|
|
1335
1337
|
};
|
|
1336
1338
|
|
|
@@ -1353,8 +1355,8 @@ function BatchUpdateModal({ projects, onClose, onChanged }) {
|
|
|
1353
1355
|
{!targets.length && (
|
|
1354
1356
|
<div style={{ padding: 14, fontSize: 12, color: T.textDim }}>No projects registered.</div>
|
|
1355
1357
|
)}
|
|
1356
|
-
{targets.map((p
|
|
1357
|
-
const st = rowStatus(p
|
|
1358
|
+
{targets.map((p) => {
|
|
1359
|
+
const st = rowStatus(p);
|
|
1358
1360
|
const r = findResult(p);
|
|
1359
1361
|
return (
|
|
1360
1362
|
<div key={p.path} style={{ padding: '7px 10px', borderBottom: `1px solid ${T.border}40` }}>
|
|
@@ -1362,7 +1364,7 @@ function BatchUpdateModal({ projects, onClose, onChanged }) {
|
|
|
1362
1364
|
{st === 'done' && <I name="check" size={13} color={T.accent} />}
|
|
1363
1365
|
{st === 'failed' && <I name="xCircle" size={13} color={T.error} />}
|
|
1364
1366
|
{st === 'running' && <GlowDot color={T.warn} />}
|
|
1365
|
-
{st === 'pending' && <GlowDot color={T.textDim} />}
|
|
1367
|
+
{(st === 'pending' || st === 'skipped') && <GlowDot color={T.textDim} />}
|
|
1366
1368
|
<span style={{ fontSize: 13, color: T.text, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
|
1367
1369
|
{p.name || p.path}
|
|
1368
1370
|
</span>
|
|
@@ -1372,8 +1374,8 @@ function BatchUpdateModal({ projects, onClose, onChanged }) {
|
|
|
1372
1374
|
color: st === 'done' ? T.accent : st === 'failed' ? T.error : st === 'running' ? T.warn : T.textDim,
|
|
1373
1375
|
}}>{st === 'running' ? 'running…' : st}</span>
|
|
1374
1376
|
</div>
|
|
1375
|
-
{st === 'failed' && r && r.output && (
|
|
1376
|
-
<div className="mono" style={{ fontSize: 11, color: T.error, marginTop: 3, paddingLeft: 21, whiteSpace: 'pre-wrap' }}>
|
|
1377
|
+
{(st === 'failed' || st === 'skipped') && r && r.output && (
|
|
1378
|
+
<div className="mono" style={{ fontSize: 11, color: st === 'failed' ? T.error : T.textDim, marginTop: 3, paddingLeft: 21, whiteSpace: 'pre-wrap' }}>
|
|
1377
1379
|
{r.output.split('\n').filter(l => l.trim()).slice(-2).join('\n')}
|
|
1378
1380
|
</div>
|
|
1379
1381
|
)}
|
|
@@ -1386,14 +1388,17 @@ function BatchUpdateModal({ projects, onClose, onChanged }) {
|
|
|
1386
1388
|
{(phase === 'running' || phase === 'done') && (
|
|
1387
1389
|
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginTop: 12 }}>
|
|
1388
1390
|
<ProgressBar value={results.length} max={total} />
|
|
1389
|
-
<span className="mono" style={{ fontSize: 11, color: T.textMuted }}>
|
|
1391
|
+
<span className="mono" style={{ fontSize: 11, color: T.textMuted }}>
|
|
1392
|
+
{results.length}/{total}{state && state.workers > 1 ? ` · ${state.workers} at once` : ''}
|
|
1393
|
+
</span>
|
|
1390
1394
|
</div>
|
|
1391
1395
|
)}
|
|
1392
1396
|
|
|
1393
1397
|
{phase === 'done' && (
|
|
1394
1398
|
<div style={{ fontSize: 12, marginTop: 10, color: failCount ? T.error : T.accent }}>
|
|
1395
1399
|
Batch {state && state.cancelled ? 'cancelled' : 'finished'} — {okCount} succeeded, {failCount} failed
|
|
1396
|
-
{
|
|
1400
|
+
{skipCount ? `, ${skipCount} skipped (folder missing)` : ''}
|
|
1401
|
+
{state && state.cancelled ? ` (${Math.max(0, total - results.length)} not started)` : ''}.
|
|
1397
1402
|
</div>
|
|
1398
1403
|
)}
|
|
1399
1404
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// ─── Hub settings modal ─────────────────────────────────────────
|
|
2
2
|
// Config: GET/POST /api/hub/config {port, auto_open_browser, oracle_url,
|
|
3
|
-
// runtime_cache_size}. Hub service: GET /api/hub/service + POST
|
|
3
|
+
// runtime_cache_size, update_workers}. Hub service: GET /api/hub/service + POST
|
|
4
4
|
// /api/hub/service/install|uninstall|start|stop. Restart: POST /api/hub/restart.
|
|
5
5
|
// Oracle service: GET /api/oracle/service + POST
|
|
6
6
|
// /api/oracle/service/install|uninstall|start|stop — runs `c3 oracle serve`
|
|
@@ -16,6 +16,7 @@ function SettingsModal({ onClose, onChanged }) {
|
|
|
16
16
|
const [oracleUrl, setOracleUrl] = useState('');
|
|
17
17
|
const [agentCmd, setAgentCmd] = useState(''); // ide_cmds['claude-code']
|
|
18
18
|
const [cacheSize, setCacheSize] = useState(8);
|
|
19
|
+
const [updateWorkers, setUpdateWorkers] = useState(3);
|
|
19
20
|
const [saving, setSaving] = useState(false);
|
|
20
21
|
const [svc, setSvc] = useState(null); // hub: {installed, running, method, port, log_path} | {error}
|
|
21
22
|
const [svcBusy, setSvcBusy] = useState('');
|
|
@@ -54,6 +55,7 @@ function SettingsModal({ onClose, onChanged }) {
|
|
|
54
55
|
setOracleUrl(d.oracle_url || '');
|
|
55
56
|
setAgentCmd(((d.ide_cmds || {})['claude-code']) || '');
|
|
56
57
|
setCacheSize(d.runtime_cache_size || 8);
|
|
58
|
+
setUpdateWorkers(d.update_workers || 3);
|
|
57
59
|
} catch {
|
|
58
60
|
notify('Could not load hub config', 'err');
|
|
59
61
|
}
|
|
@@ -70,6 +72,7 @@ function SettingsModal({ onClose, onChanged }) {
|
|
|
70
72
|
return;
|
|
71
73
|
}
|
|
72
74
|
const cache = Math.max(1, parseInt(cacheSize, 10) || 8);
|
|
75
|
+
const workers = Math.min(8, Math.max(1, parseInt(updateWorkers, 10) || 3));
|
|
73
76
|
setSaving(true);
|
|
74
77
|
try {
|
|
75
78
|
// Blank restores the stock `claude`; other IDE overrides are left alone.
|
|
@@ -79,7 +82,7 @@ function SettingsModal({ onClose, onChanged }) {
|
|
|
79
82
|
await api.post('/api/hub/config', {
|
|
80
83
|
port: portVal, auto_open_browser: autoBrowser,
|
|
81
84
|
oracle_url: oracleUrl.trim(), runtime_cache_size: cache,
|
|
82
|
-
ide_cmds: ideCmds,
|
|
85
|
+
update_workers: workers, ide_cmds: ideCmds,
|
|
83
86
|
});
|
|
84
87
|
const portChanged = cfg && portVal !== cfg.port;
|
|
85
88
|
notify(portChanged
|
|
@@ -229,6 +232,10 @@ function SettingsModal({ onClose, onChanged }) {
|
|
|
229
232
|
<input type="number" value={cacheSize} onChange={e => setCacheSize(e.target.value)}
|
|
230
233
|
min={1} className="mono" style={inputStyle(110)} />
|
|
231
234
|
), 'Max project runtimes kept warm for drill-in and global search.')}
|
|
235
|
+
{fieldRow('Parallel updates', (
|
|
236
|
+
<input type="number" value={updateWorkers} onChange={e => setUpdateWorkers(e.target.value)}
|
|
237
|
+
min={1} max={8} className="mono" style={inputStyle(110)} />
|
|
238
|
+
), 'Projects "Update all" and sub-project cascades update at once (1-8). Each one is a separate c3 process.')}
|
|
232
239
|
{fieldRow('Agent command', (
|
|
233
240
|
<input value={agentCmd} onChange={e => setAgentCmd(e.target.value)}
|
|
234
241
|
placeholder="claude" className="mono" style={inputStyle(220)} />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-context-control
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.161.0
|
|
4
4
|
Summary: Local MCP code-intelligence for AI coding tools: surgical search/read/edit, agent-config version history, path-level access + masking guards, and a multi-project hub.
|
|
5
5
|
Author-email: Dimitri Tselenchuk <dtselenc@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
cli/__init__.py,sha256=ec66drCZGNMRU4V6ov0zVhYZph1us12Vn8OvG_LJyRY,22
|
|
2
2
|
cli/_hook_utils.py,sha256=tzpdF413jakQKMbTru_GdHxQXxLLQKiZzVkTm4Fo_eU,23258
|
|
3
3
|
cli/_shell_writes.py,sha256=iBbzK0v0d29rhrYgF3zKJIJbb1WSZhQjD_6w8-nOUec,7348
|
|
4
|
-
cli/c3.py,sha256=
|
|
4
|
+
cli/c3.py,sha256=756qSx3772RsjgPOuhRLnDcQGLM3L1zZDp6JT_sQuTg,439974
|
|
5
5
|
cli/docs.html,sha256=pPxcP5ieY0DcfEDvegwIcRxbz1woLZoKLVSF-4JVy0Q,146784
|
|
6
6
|
cli/edits.html,sha256=UjAhoCmBmQ89cklGvJqzC6eyNP2tc8H6T-e01DVkLvE,43418
|
|
7
7
|
cli/hook_access_guard.py,sha256=4UF2YHp5_vISH7Gvolc_Bz3ppSye2lGpGx38egRLj1g,32116
|
|
@@ -23,7 +23,7 @@ cli/hook_session_end.py,sha256=toFEPDKRoutDuVOmuOgHmQ8CM0o7tF7yALhMxJz7VEM,3482
|
|
|
23
23
|
cli/hook_session_open.py,sha256=Bq8zKPkucPYASQDxJcT1bGm975d__RbTvaiWj9yVcDs,11969
|
|
24
24
|
cli/hook_session_stats.py,sha256=I-2NeLlV1NxeqKtTM2JH9haSpFU7r4qG0u8pfCJ80YU,8725
|
|
25
25
|
cli/hook_terse_advisor.py,sha256=W_zaTfX2akgX-ifuUTsLu2H1atM8XmWt6jpPoeU7Pm0,6252
|
|
26
|
-
cli/hub_server.py,sha256=
|
|
26
|
+
cli/hub_server.py,sha256=0bGnpetegI-bs0tCLdsDFDuvEu-OdnEqzxywqdcJkiw,230525
|
|
27
27
|
cli/hub_ui.html,sha256=v41R_JAH4Jwodpy3tbeBUel-80FbNmffBrey-QH5Q64,2963
|
|
28
28
|
cli/mcp_proxy.py,sha256=r-Qhlie7gCtotex8yQUudCyBLRUK-IW6cNIW5RhBW0o,17648
|
|
29
29
|
cli/mcp_server.py,sha256=DisVVExGIbeEABxtDPzdaGJpu7P1okA4l_dzu-VFD3E,84862
|
|
@@ -70,11 +70,11 @@ cli/hub_ui/components/hub_schedules.js,sha256=80TdfYAz0nHk3k3CINtagfkoE2gx_Sm6pd
|
|
|
70
70
|
cli/hub_ui/components/hub_sessions.js,sha256=Uo-U3T9ZIqSgiBkfNIWB3K2c-J-WBJApUU2IPSi5BZk,21401
|
|
71
71
|
cli/hub_ui/components/hub_tokens.js,sha256=oBFTvW5zJShpBaqIqmJPK_g7SpEiulurMRjlfO34T2c,18565
|
|
72
72
|
cli/hub_ui/components/mcp_manager.js,sha256=Bqd74xuHVyADpILJZbFHTlM2gcUpG1nH_ngZhMlobaU,17405
|
|
73
|
-
cli/hub_ui/components/modals.js,sha256
|
|
73
|
+
cli/hub_ui/components/modals.js,sha256=MAdmSYTCCyCBwhjaGqepc9DGntMfdW4QC8cPikdsK3k,67420
|
|
74
74
|
cli/hub_ui/components/project_card.js,sha256=V_g5LUUj99IPdjw5f98ViZ-mbBGTXt_RKqq_0g-tPMs,30722
|
|
75
75
|
cli/hub_ui/components/project_tree.js,sha256=jPgkHZwgBM9iNT4pxXPTMgV4dtZpOX5EQsGvzcL4PP0,3829
|
|
76
76
|
cli/hub_ui/components/session_drawer.js,sha256=OEBvdF3PqRji9CEntolDMVplXF2NTG2xwmXCqkcb0Nw,7553
|
|
77
|
-
cli/hub_ui/components/settings_modal.js,sha256=
|
|
77
|
+
cli/hub_ui/components/settings_modal.js,sha256=jPj81txTsOZqULAB3wTlJgVpeMgdUqTY4qQ67K5TzzM,15055
|
|
78
78
|
cli/hub_ui/components/sidebar.js,sha256=RH0OlqCINFNCIXgns-wgge5gG8vkn5wyfRT87qdmo1I,4585
|
|
79
79
|
cli/hub_ui/components/summary_bar.js,sha256=JnMq01Oum8DwwUOhFnX5mr8K7I-ERdPlbaBOR8QT72o,2993
|
|
80
80
|
cli/hub_ui/components/task_board.js,sha256=QiWKmj1NkhkloGlfzZj_tWd7Sgz3xSxwVLp8I5OfIiM,15952
|
|
@@ -135,7 +135,7 @@ cli/ui/components/sessions.js,sha256=FIKtil76B8tCkAmcFV7hlj6GQ_DCJK2jCzvEmdK7NBE
|
|
|
135
135
|
cli/ui/components/settings.js,sha256=FXcn-UQE2mXC6HFsLeEas-wAUFKt0OJaLySroZQMhGA,84095
|
|
136
136
|
cli/ui/components/sidebar.js,sha256=K2ym2kUgpbyG-EBA_wBIIiqQY8qTatsiBZwzseMWuIQ,9939
|
|
137
137
|
cli/ui/components/tasks.js,sha256=vyKQ3uwoppMwvdEaHlhWXW4oWcAisx4NveqzMhsYqHo,38438
|
|
138
|
-
code_context_control-2.
|
|
138
|
+
code_context_control-2.161.0.dist-info/licenses/LICENSE,sha256=l8Kh5QCNWNvR6kIt8L0BUZvc2LAFiHv2c-FnsGnUZf4,11301
|
|
139
139
|
core/__init__.py,sha256=qiheEC2r3KCd3vscukDVkjCXFcadzGgNhDhs9PbLVPA,2835
|
|
140
140
|
core/blas_threads.py,sha256=Do7pR9YdumshhOmP6TV5oAv65i3gN7Lvt93b5EAO1bo,1256
|
|
141
141
|
core/codex_patch.py,sha256=CxvT_rQIwPNTRJZj9EHJmx0ZdOeSLxjiixuLI3Z7lPc,2107
|
|
@@ -169,11 +169,11 @@ oracle/services/insight_engine.py,sha256=lwcdXtjt3CSZLqHVpXx6SG5gDhZYUKwXt4Z8dGy
|
|
|
169
169
|
oracle/services/local_session.py,sha256=nkawOjDbotUp5wtZQnC1wPDw3HopNYMkoYqWpP5ToCU,9227
|
|
170
170
|
oracle/services/memory_reader.py,sha256=rSEmoIXQu2JkolHJIQWpn0piPJpyuf1KZvW_9liQwkU,3727
|
|
171
171
|
oracle/services/memory_writer.py,sha256=hpvYsxjhl293jEjGcRKfjG5njUaAOXKqbmJaUu1WdUU,6997
|
|
172
|
-
oracle/services/mobile_api.py,sha256=
|
|
172
|
+
oracle/services/mobile_api.py,sha256=SNcu0o_J0ym0H7lyTVccJBD7TTiSqzM7kFSFyucZ8eQ,153291
|
|
173
173
|
oracle/services/mobile_fleet.py,sha256=1M6vN4vOlYdVt1qFDSK97PLPHjvZkus4ZZSRm-ow2Nc,23968
|
|
174
174
|
oracle/services/project_scanner.py,sha256=PkYJtwOLRME1EzwRy3GIkYk6Xw0u1_BzFcaMJ5gJ1_s,6118
|
|
175
175
|
oracle/services/review_agent.py,sha256=m_fzoHowpiibf0_iz3dF72LWSrwB_FbDd1am-SbeWXg,11273
|
|
176
|
-
oracle/services/schedule_api.py,sha256=
|
|
176
|
+
oracle/services/schedule_api.py,sha256=6NgmSYf2h4RSwqChuKvceWvRq3jC_ACdBKcZGi9-Wqs,12798
|
|
177
177
|
oracle/services/scheduler.py,sha256=cz6N1YXv2OdseJ8_XBS5szt_zjkcvd27xYfbF3to2kM,14730
|
|
178
178
|
oracle/services/tool_executor.py,sha256=xtAkBWkclh_FwOgzprjGkyRIV8-A7Lc3bz0UFPShrv0,1113
|
|
179
179
|
oracle/services/tool_registry.py,sha256=mJUZSS99PDH8whkndNxcQXT1uoNxPviE3MotGzj2jtk,26046
|
|
@@ -305,8 +305,8 @@ services/router.py,sha256=Cz10nx2fKTbaGn14mSBePWIDrw5rdcs_1JFYXeik084,15626
|
|
|
305
305
|
services/runtime.py,sha256=W7Og5gmLVEjm6IG3oT-l046-b6pmz5VUaZ1asZu4W-o,13898
|
|
306
306
|
services/scanner.py,sha256=lH0aiDCdCRruKS-VTAD_LsF4zrhMLpMRhFlOZZlw4VM,9613
|
|
307
307
|
services/schedule_approvals.py,sha256=tzf_YTnOoJf-DOx3m83m54EQnNBXE752nv4eE6N0PwU,8516
|
|
308
|
-
services/schedule_runner.py,sha256=
|
|
309
|
-
services/schedule_store.py,sha256=
|
|
308
|
+
services/schedule_runner.py,sha256=Rk05QsGT-lTqDA_FHWdyGCVFRUCnygmpbJtUjdGc6hE,21519
|
|
309
|
+
services/schedule_store.py,sha256=NyweZBYG3E6RS9Rx72aa6vcMk6Brt-tVwdpLUHJ1ok0,25789
|
|
310
310
|
services/session_benchmark.py,sha256=KUcWWC5X088p_ao6DgglUMwj7jCzdecPKxJ7XiGKob0,106255
|
|
311
311
|
services/session_catalog.py,sha256=P57Z4OUnx6hbLKECJ1Xzxz8BCKxxPncAqx1cB7HbXwo,47607
|
|
312
312
|
services/session_live.py,sha256=RPFhxqVh0QmKIDn_PN0OxjpK2wHOOrvJkIgsvogMuwQ,5646
|
|
@@ -354,8 +354,8 @@ tui/screens/search_view.py,sha256=MMHjVdlk3HZSuDBSvq8IGrqv_Mh5Us6YqXQ80bcWSMk,19
|
|
|
354
354
|
tui/screens/session_view.py,sha256=eZ1eDwHTvPOck1wCCviixtOaCxIkBT_95ytNNNriGNA,5991
|
|
355
355
|
tui/screens/stats.py,sha256=p81PjzdaIv7hllb8f45-rlVe4lJZwSdIMqu7e86_u5s,6223
|
|
356
356
|
tui/screens/ui_view.py,sha256=1QJCgLh2YfgWIpvzRG1KOGXYEaOYX6ojN61Azjf2oX0,2125
|
|
357
|
-
code_context_control-2.
|
|
358
|
-
code_context_control-2.
|
|
359
|
-
code_context_control-2.
|
|
360
|
-
code_context_control-2.
|
|
361
|
-
code_context_control-2.
|
|
357
|
+
code_context_control-2.161.0.dist-info/METADATA,sha256=RYTXEHC7XZbgWpo422zZ7iZ5VmXrzDOdRAoKSmZR688,29355
|
|
358
|
+
code_context_control-2.161.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
359
|
+
code_context_control-2.161.0.dist-info/entry_points.txt,sha256=7kX_WUsDCF2hbXzvbNyscyaBb9AeA-DJY5v_5hN0DlU,93
|
|
360
|
+
code_context_control-2.161.0.dist-info/top_level.txt,sha256=wRt41zBybVF3qAiNXHz9BURbkKvUvfhmWWtKMhaw6eE,29
|
|
361
|
+
code_context_control-2.161.0.dist-info/RECORD,,
|
oracle/services/mobile_api.py
CHANGED
|
@@ -87,6 +87,8 @@ from services.atomic_json import write_json_atomic
|
|
|
87
87
|
# and /overrides/policy/clear; built-in guards read + tighten + lease
|
|
88
88
|
# revoke (/access/builtin*); the session catalog (/sessions*, no
|
|
89
89
|
# transcript text by default); and /now.
|
|
90
|
+
# 7 (unchanged, additive): `schedule_output` capability and
|
|
91
|
+
# GET /schedules/runs/<run_id>/output, a run's stdout paged by line.
|
|
90
92
|
API_VERSION = 7
|
|
91
93
|
|
|
92
94
|
CAPABILITIES = [
|
|
@@ -105,7 +107,8 @@ CAPABILITIES = [
|
|
|
105
107
|
"jobs", "ci",
|
|
106
108
|
# Scheduled tasks (/schedules): read the schedules, their runs and pending
|
|
107
109
|
# approvals; write = create/edit/run-now/decide (docs/scheduled-tasks.md).
|
|
108
|
-
|
|
110
|
+
# schedule_output: a run's stdout while it runs and after it ends.
|
|
111
|
+
"schedules", "schedules_write", "schedule_output",
|
|
109
112
|
# Poll-based chat transport, served by services/chat_poll.py under
|
|
110
113
|
# /api/mobile/chat/*. Advertised here because /info is the single place a
|
|
111
114
|
# client probes; the routes themselves live in that blueprint.
|
|
@@ -139,6 +142,7 @@ _CAPABILITY_SWITCHES = {
|
|
|
139
142
|
"suggestions_write": "mobile_suggestions_write",
|
|
140
143
|
"schedules": "mobile_schedules_enabled",
|
|
141
144
|
"schedules_write": "mobile_schedules_write",
|
|
145
|
+
"schedule_output": "mobile_schedules_enabled",
|
|
142
146
|
# v7: each overview goes dark with the subsystem it reads; locks_overview
|
|
143
147
|
# and now are ops reads like /locks and /status, so always on.
|
|
144
148
|
"access_overview": "mobile_access_enabled",
|
|
@@ -1194,6 +1198,21 @@ def mobile_schedule_runs():
|
|
|
1194
1198
|
return jsonify({"runs": rows, "count": len(rows), "project": project_path})
|
|
1195
1199
|
|
|
1196
1200
|
|
|
1201
|
+
@bp.route("/schedules/runs/<run_id>/output", methods=["GET"])
|
|
1202
|
+
def mobile_schedule_run_output(run_id):
|
|
1203
|
+
"""A run's stdout lines after ``after`` (query: after, limit); see schedule_api.run_output."""
|
|
1204
|
+
gate = _feature_or_404("schedule_output")
|
|
1205
|
+
if gate:
|
|
1206
|
+
return gate
|
|
1207
|
+
api = _schedule_api()
|
|
1208
|
+
run = api._get_store().get_run(str(run_id))
|
|
1209
|
+
if run is None or _resolve_registered(str(run.get("project_path") or "")) is None:
|
|
1210
|
+
return jsonify({"error": "unknown run"}), 404
|
|
1211
|
+
data, err = _schedule_call(api.run_output, str(run_id), after=request.args.get("after"),
|
|
1212
|
+
limit=request.args.get("limit"))
|
|
1213
|
+
return err or jsonify(data)
|
|
1214
|
+
|
|
1215
|
+
|
|
1197
1216
|
@bp.route("/schedules/approvals", methods=["GET"])
|
|
1198
1217
|
def mobile_schedule_approvals():
|
|
1199
1218
|
gate = _feature_or_404("schedules")
|
oracle/services/schedule_api.py
CHANGED
|
@@ -13,9 +13,13 @@ from pathlib import Path
|
|
|
13
13
|
|
|
14
14
|
from flask import Blueprint, jsonify, request
|
|
15
15
|
|
|
16
|
+
from services import schedule_runner as runner
|
|
16
17
|
from services.cron_expr import preview, validate_when
|
|
17
18
|
from services.schedule_approvals import ApprovalError
|
|
18
|
-
from services.schedule_store import RUN_STATUSES, RevConflict, ScheduleError
|
|
19
|
+
from services.schedule_store import OPEN_RUN_STATUSES, RUN_STATUSES, RevConflict, ScheduleError
|
|
20
|
+
|
|
21
|
+
OUTPUT_DEFAULT_LIMIT = 500
|
|
22
|
+
OUTPUT_MAX_LIMIT = 2000
|
|
19
23
|
|
|
20
24
|
bp = Blueprint("schedule_api", __name__, url_prefix="/api/schedules")
|
|
21
25
|
|
|
@@ -131,6 +135,85 @@ def preview_when(body: dict) -> dict:
|
|
|
131
135
|
return {"when": when, "next": [f.isoformat() for f in fires]}
|
|
132
136
|
|
|
133
137
|
|
|
138
|
+
def run_output(run_id: str, after=0, limit=OUTPUT_DEFAULT_LIMIT, *, jobstore=None) -> dict:
|
|
139
|
+
"""One page of a run's stdout: the lines numbered ``n > after``.
|
|
140
|
+
|
|
141
|
+
Reads ``schedule_runs/<run_id>.out`` once the run has one; before that the
|
|
142
|
+
job's spool while it runs (``live``, complete lines only) or its kept
|
|
143
|
+
output once it ended (``output_store``). A line keeps its number across
|
|
144
|
+
the three. ``after`` and ``limit`` may be strings from a query;
|
|
145
|
+
``limit`` is clamped to 1..2000. Raises ``ApiError`` 404 for an unknown
|
|
146
|
+
run and 400 for a non-integer ``after``/``limit``.
|
|
147
|
+
"""
|
|
148
|
+
store = _get_store()
|
|
149
|
+
run = store.get_run(str(run_id or ""))
|
|
150
|
+
if run is None:
|
|
151
|
+
raise ApiError(f"no run {run_id}", 404)
|
|
152
|
+
after = _int_arg(after, 0, "after")
|
|
153
|
+
limit = min(max(_int_arg(limit, OUTPUT_DEFAULT_LIMIT, "limit"), 1), OUTPUT_MAX_LIMIT)
|
|
154
|
+
status = run.get("status")
|
|
155
|
+
out = {"run_id": run["run_id"], "status": status, "open": status in OPEN_RUN_STATUSES,
|
|
156
|
+
"job_id": run.get("job_id") or None, "format": _run_format(store, run),
|
|
157
|
+
"source": "none", "lines": [], "next": after, "total": 0, "dropped": 0,
|
|
158
|
+
"stderr_tail": str(run.get("stderr_tail") or "")}
|
|
159
|
+
|
|
160
|
+
def page(path, source: str, first_n: int = 1) -> bool:
|
|
161
|
+
try:
|
|
162
|
+
lines, total = runner.page_lines(path, first_n=first_n, after=after, limit=limit,
|
|
163
|
+
complete_only=source == "live")
|
|
164
|
+
except OSError:
|
|
165
|
+
return False
|
|
166
|
+
out.update(source=source, lines=lines, total=total, next=lines[-1]["n"] if lines else after)
|
|
167
|
+
return True
|
|
168
|
+
|
|
169
|
+
archive = store.runs_dir / f"{run['run_id']}.out"
|
|
170
|
+
if run.get("output_lines") is not None and archive.is_file():
|
|
171
|
+
dropped = int(run.get("output_dropped") or 0)
|
|
172
|
+
if page(archive, "archive", dropped + 1):
|
|
173
|
+
out["dropped"] = dropped
|
|
174
|
+
return out
|
|
175
|
+
job_id = run.get("job_id")
|
|
176
|
+
if not job_id:
|
|
177
|
+
return out
|
|
178
|
+
jobs = jobstore if jobstore is not None else _jobstore()
|
|
179
|
+
job = jobs.find(job_id)
|
|
180
|
+
if job is not None and not job.terminal and job.spool.get("stdout"):
|
|
181
|
+
if page(job.spool["stdout"], "live"):
|
|
182
|
+
return out
|
|
183
|
+
job = jobs.find(job_id) # the spool was promoted between the two reads
|
|
184
|
+
if job is not None and job.terminal:
|
|
185
|
+
path = runner.job_stream_path(jobs, job, "stdout")
|
|
186
|
+
if path is not None:
|
|
187
|
+
page(path, "output_store")
|
|
188
|
+
return out
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _int_arg(value, default: int, name: str) -> int:
|
|
192
|
+
if value is None or value == "":
|
|
193
|
+
return default
|
|
194
|
+
try:
|
|
195
|
+
return max(0, int(value))
|
|
196
|
+
except (TypeError, ValueError) as exc:
|
|
197
|
+
raise ApiError(f"{name} must be an integer", 400) from exc
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _run_format(store, run: dict) -> str:
|
|
201
|
+
if run.get("output_format"):
|
|
202
|
+
return str(run["output_format"])
|
|
203
|
+
if run.get("status") in ("check_running", "check_skipped"):
|
|
204
|
+
return "text"
|
|
205
|
+
schedule = store.get(run.get("schedule_id") or "")
|
|
206
|
+
return runner.output_format(schedule) if schedule else "text"
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _jobstore():
|
|
210
|
+
jobstore = getattr(_get_scheduler(), "jobstore", None)
|
|
211
|
+
if jobstore is not None:
|
|
212
|
+
return jobstore
|
|
213
|
+
from services.shell_jobs import JobStore
|
|
214
|
+
return JobStore()
|
|
215
|
+
|
|
216
|
+
|
|
134
217
|
def _limit(default: int = 50, cap: int = 500) -> int:
|
|
135
218
|
try:
|
|
136
219
|
return max(1, min(int(request.args.get("limit") or default), cap))
|
|
@@ -198,6 +281,11 @@ def one_run(run_id: str):
|
|
|
198
281
|
return jsonify(run)
|
|
199
282
|
|
|
200
283
|
|
|
284
|
+
@bp.route("/runs/<run_id>/output", methods=["GET"])
|
|
285
|
+
def one_run_output(run_id: str):
|
|
286
|
+
return jsonify(run_output(run_id, after=request.args.get("after"), limit=request.args.get("limit")))
|
|
287
|
+
|
|
288
|
+
|
|
201
289
|
@bp.route("/approvals", methods=["GET"])
|
|
202
290
|
def approvals():
|
|
203
291
|
status = (request.args.get("status") or "").strip() or None
|
services/schedule_runner.py
CHANGED
|
@@ -10,10 +10,13 @@ owns the order in which that happens.
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
12
|
import json
|
|
13
|
+
import os
|
|
13
14
|
import shutil
|
|
14
15
|
from dataclasses import dataclass, field
|
|
16
|
+
from pathlib import Path
|
|
15
17
|
|
|
16
18
|
from services.schedule_store import EXECUTED_STATUSES, ScheduleStore, prompt_text
|
|
19
|
+
from services.shell_output import OutputAccessError, _restrict_file
|
|
17
20
|
|
|
18
21
|
SESSION_ID = "scheduler"
|
|
19
22
|
CLAUDE_NESTING_VARS = ("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CLAUDE_CODE_SESSION_ID",
|
|
@@ -23,6 +26,12 @@ CODEX_EFFORTS = {"": "medium", "low": "low", "medium": "medium", "high": "high",
|
|
|
23
26
|
GROK_EFFORTS = {"": "", "low": "low", "medium": "medium", "high": "high", "xhigh": "high", "max": "high"}
|
|
24
27
|
JOB_TO_RUN = {"done": "done", "failed": "failed", "timeout": "timeout",
|
|
25
28
|
"cancelled": "cancelled", "lost": "lost"}
|
|
29
|
+
ARCHIVE_MAX_BYTES = 8 * 1024 * 1024
|
|
30
|
+
STDERR_TAIL_LINES = 60
|
|
31
|
+
STDERR_TAIL_BYTES = 8 * 1024
|
|
32
|
+
OUTPUT_PAGE_BYTES = 1024 * 1024
|
|
33
|
+
OUTPUT_LINE_CLIP = 256 * 1024
|
|
34
|
+
_CHUNK = 1024 * 1024
|
|
26
35
|
|
|
27
36
|
|
|
28
37
|
class PlanError(ValueError):
|
|
@@ -86,7 +95,7 @@ def _exe(name: str) -> str:
|
|
|
86
95
|
|
|
87
96
|
def _plan_claude(schedule: dict, prompt: str, cwd: str, timeout_s: int, _prompt_file: str) -> FirePlan:
|
|
88
97
|
from cli.tools.delegate import _EFFORT_LEVELS, _MODEL_NAME_RE
|
|
89
|
-
argv = [_exe("claude"), "-p", "--output-format", "json", "--no-session-persistence",
|
|
98
|
+
argv = [_exe("claude"), "-p", "--output-format", "stream-json", "--verbose", "--no-session-persistence",
|
|
90
99
|
"--permission-mode", str(schedule.get("permission_mode") or "acceptEdits"),
|
|
91
100
|
"--permission-prompts", "none", "--name", f"sched:{schedule.get('id', '')}"]
|
|
92
101
|
model = str(schedule.get("model") or "").strip()
|
|
@@ -145,6 +154,14 @@ def _plan_grok(schedule: dict, prompt: str, cwd: str, timeout_s: int, prompt_fil
|
|
|
145
154
|
_PROVIDERS = {"claude": _plan_claude, "codex": _plan_codex, "gemini": _plan_gemini, "grok": _plan_grok}
|
|
146
155
|
|
|
147
156
|
|
|
157
|
+
def output_format(schedule: dict) -> str:
|
|
158
|
+
"""How a client reads this schedule's stdout: ``claude-stream``, ``codex-json`` or ``text``."""
|
|
159
|
+
if schedule.get("kind") == "command":
|
|
160
|
+
return "text"
|
|
161
|
+
provider = str(schedule.get("provider") or "claude")
|
|
162
|
+
return {"claude": "claude-stream", "codex": "codex-json"}.get(provider, "text")
|
|
163
|
+
|
|
164
|
+
|
|
148
165
|
def dispatch(store: ScheduleStore, jobstore, schedule: dict, run: dict, *, check: bool = False) -> dict:
|
|
149
166
|
"""Start the job for ``run`` and record it; a spawn failure finishes the run."""
|
|
150
167
|
run_id = run["run_id"]
|
|
@@ -160,22 +177,37 @@ def dispatch(store: ScheduleStore, jobstore, schedule: dict, run: dict, *, check
|
|
|
160
177
|
job = jobstore.start(project_path=schedule["project_path"], session_id=SESSION_ID,
|
|
161
178
|
cmd=fire.display, cwd=fire.cwd, timeout_s=fire.timeout_s,
|
|
162
179
|
payload=fire.payload())
|
|
180
|
+
fmt = "text" if check else output_format(schedule)
|
|
163
181
|
if job.terminal and job.status != "done":
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
status = JOB_TO_RUN.get(job.status, "failed")
|
|
183
|
+
return store.finish_run(run_id, status, job_id=job.id, exit_code=job.exit_code,
|
|
184
|
+
error=job.error or "job ended before it ran", output_format=fmt,
|
|
185
|
+
**_output_fields(store, jobstore, run_id, job, status))
|
|
166
186
|
status = "check_running" if check else "dispatched"
|
|
167
|
-
return store.update_run(run_id, status=status, job_id=job.id, dispatched_at=job.created_at
|
|
187
|
+
return store.update_run(run_id, status=status, job_id=job.id, dispatched_at=job.created_at,
|
|
188
|
+
output_format=fmt)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def job_stream_path(jobstore, job, stream: str = "stdout") -> Path | None:
|
|
192
|
+
"""Where a terminal job's kept ``stream`` lives, or None when it was not kept or has expired."""
|
|
193
|
+
if not getattr(job, "output_id", ""):
|
|
194
|
+
return None
|
|
195
|
+
try:
|
|
196
|
+
meta = jobstore.output_store.resolve(job.output_id, project_path=job.project_path,
|
|
197
|
+
session_id=job.session_id, guard_check=lambda _p: None)
|
|
198
|
+
return Path(meta.stream_path(stream))
|
|
199
|
+
except (OutputAccessError, OSError, ValueError):
|
|
200
|
+
return None
|
|
168
201
|
|
|
169
202
|
|
|
170
203
|
def job_stdout(jobstore, job) -> str:
|
|
171
204
|
"""Raw kept stdout of a terminal job, or empty when it was not kept."""
|
|
172
|
-
|
|
205
|
+
path = job_stream_path(jobstore, job, "stdout")
|
|
206
|
+
if path is None:
|
|
173
207
|
return ""
|
|
174
208
|
try:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return meta.stream_path("stdout").read_bytes().decode("utf-8", "replace")
|
|
178
|
-
except Exception:
|
|
209
|
+
return path.read_bytes().decode("utf-8", "replace")
|
|
210
|
+
except OSError:
|
|
179
211
|
return ""
|
|
180
212
|
|
|
181
213
|
|
|
@@ -183,7 +215,10 @@ def parse_result(parser: str, stdout: str) -> dict:
|
|
|
183
215
|
"""Cost, tokens, turns, model and a result excerpt from a provider's JSON stdout."""
|
|
184
216
|
if parser == "claude":
|
|
185
217
|
from cli.tools.delegate import parse_claude_json
|
|
186
|
-
|
|
218
|
+
result_line, last_text = _claude_stream(stdout)
|
|
219
|
+
if result_line is None and last_text:
|
|
220
|
+
return {"result_excerpt": last_text}
|
|
221
|
+
text, _ok, stats = parse_claude_json(stdout if result_line is None else result_line)
|
|
187
222
|
out = {"result_excerpt": text}
|
|
188
223
|
tokens = {k: stats[k] for k in ("input_tokens", "output_tokens", "cache_read_tokens",
|
|
189
224
|
"cache_write_tokens") if k in stats}
|
|
@@ -214,6 +249,34 @@ def parse_result(parser: str, stdout: str) -> dict:
|
|
|
214
249
|
return {"result_excerpt": stdout.strip()}
|
|
215
250
|
|
|
216
251
|
|
|
252
|
+
def _claude_stream(stdout: str) -> tuple[str | None, str]:
|
|
253
|
+
"""The last ``result`` event line of a stream-json transcript and the last assistant text.
|
|
254
|
+
|
|
255
|
+
``(None, "")`` for a single JSON document without a ``type``; a stream cut
|
|
256
|
+
off before its result (timeout, cancel) gives ``(None, <last text the
|
|
257
|
+
model wrote>)``. Split on newlines only: an event may carry a raw U+2028.
|
|
258
|
+
"""
|
|
259
|
+
result_line, last_text = None, ""
|
|
260
|
+
for line in (stdout or "").split("\n"):
|
|
261
|
+
line = line.strip()
|
|
262
|
+
if not line.startswith("{"):
|
|
263
|
+
continue
|
|
264
|
+
try:
|
|
265
|
+
event = json.loads(line)
|
|
266
|
+
except ValueError:
|
|
267
|
+
continue
|
|
268
|
+
if not isinstance(event, dict):
|
|
269
|
+
continue
|
|
270
|
+
if event.get("type") == "result":
|
|
271
|
+
result_line = line
|
|
272
|
+
elif event.get("type") == "assistant":
|
|
273
|
+
content = (event.get("message") or {}).get("content")
|
|
274
|
+
texts = [str(c.get("text") or "") for c in content or [] if isinstance(c, dict) and c.get("type") == "text"]
|
|
275
|
+
if any(texts):
|
|
276
|
+
last_text = "\n".join(t for t in texts if t).strip()
|
|
277
|
+
return result_line, last_text
|
|
278
|
+
|
|
279
|
+
|
|
217
280
|
def _trailing_json(text: str):
|
|
218
281
|
raw = (text or "").strip()
|
|
219
282
|
start = raw.find("{")
|
|
@@ -256,9 +319,189 @@ def finalize(store: ScheduleStore, jobstore, run: dict, job, parser: str = "comm
|
|
|
256
319
|
stdout = job_stdout(jobstore, job)
|
|
257
320
|
if stdout:
|
|
258
321
|
extra.update(parse_result(parser, stdout))
|
|
322
|
+
extra.update(_output_fields(store, jobstore, run["run_id"], job, status))
|
|
259
323
|
return store.finish_run(run["run_id"], status, **extra)
|
|
260
324
|
|
|
261
325
|
|
|
326
|
+
def _output_fields(store: ScheduleStore, jobstore, run_id: str, job, status: str) -> dict:
|
|
327
|
+
"""The archive's run fields, plus ``stderr_tail`` when the run ended badly."""
|
|
328
|
+
fields = archive_output(store, jobstore, run_id, job)
|
|
329
|
+
if status != "done" or (job.exit_code or 0) != 0:
|
|
330
|
+
tail = stderr_tail(jobstore, job)
|
|
331
|
+
if tail:
|
|
332
|
+
fields["stderr_tail"] = tail
|
|
333
|
+
return fields
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def archive_output(store: ScheduleStore, jobstore, run_id: str, job) -> dict:
|
|
337
|
+
"""Copy the job's kept stdout to ``schedule_runs/<run_id>.out``, keeping its last 8 MiB.
|
|
338
|
+
|
|
339
|
+
Returns ``{"output_lines": lines in the whole stream, "output_dropped":
|
|
340
|
+
lines cut from its head}``, or ``{}`` when the job kept no stdout or the
|
|
341
|
+
copy failed. Line N of the archive is line ``output_dropped + N`` of the
|
|
342
|
+
stream. The archive starts at a line boundary unless the stream's last
|
|
343
|
+
line alone is longer than the cap; then it holds that line's tail.
|
|
344
|
+
"""
|
|
345
|
+
src = job_stream_path(jobstore, job, "stdout")
|
|
346
|
+
if src is None:
|
|
347
|
+
return {}
|
|
348
|
+
dst = store.runs_dir / f"{run_id}.out"
|
|
349
|
+
tmp = dst.with_name(dst.name + ".tmp")
|
|
350
|
+
try:
|
|
351
|
+
with open(src, "rb") as fh:
|
|
352
|
+
size = os.fstat(fh.fileno()).st_size
|
|
353
|
+
start = _archive_start(fh, size)
|
|
354
|
+
fh.seek(0)
|
|
355
|
+
dropped = _count_lines(fh, start, complete_only=True)
|
|
356
|
+
lines = dropped + _count_lines(fh, size, complete_only=False)
|
|
357
|
+
fh.seek(start)
|
|
358
|
+
store.runs_dir.mkdir(parents=True, exist_ok=True)
|
|
359
|
+
with open(tmp, "wb") as out:
|
|
360
|
+
shutil.copyfileobj(fh, out, _CHUNK)
|
|
361
|
+
os.replace(tmp, dst)
|
|
362
|
+
except OSError:
|
|
363
|
+
try:
|
|
364
|
+
tmp.unlink()
|
|
365
|
+
except OSError:
|
|
366
|
+
pass
|
|
367
|
+
return {}
|
|
368
|
+
_restrict_file(dst)
|
|
369
|
+
return {"output_lines": lines, "output_dropped": dropped}
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def _archive_start(fh, size: int) -> int:
|
|
373
|
+
"""Offset the archive copies from: the first line start inside the last ``ARCHIVE_MAX_BYTES``."""
|
|
374
|
+
if size <= ARCHIVE_MAX_BYTES:
|
|
375
|
+
return 0
|
|
376
|
+
cut = size - ARCHIVE_MAX_BYTES
|
|
377
|
+
fh.seek(cut)
|
|
378
|
+
pos = cut
|
|
379
|
+
while pos < size:
|
|
380
|
+
chunk = fh.read(min(_CHUNK, size - pos))
|
|
381
|
+
if not chunk:
|
|
382
|
+
break
|
|
383
|
+
nl = chunk.find(b"\n")
|
|
384
|
+
if nl >= 0:
|
|
385
|
+
start = pos + nl + 1
|
|
386
|
+
return start if start < size else cut
|
|
387
|
+
pos += len(chunk)
|
|
388
|
+
return cut
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def stderr_tail(jobstore, job) -> str:
|
|
392
|
+
"""The last ``STDERR_TAIL_LINES`` lines (at most ``STDERR_TAIL_BYTES``) of the job's stderr."""
|
|
393
|
+
path = job_stream_path(jobstore, job, "stderr")
|
|
394
|
+
if path is None:
|
|
395
|
+
return ""
|
|
396
|
+
try:
|
|
397
|
+
with open(path, "rb") as fh:
|
|
398
|
+
size = os.fstat(fh.fileno()).st_size
|
|
399
|
+
fh.seek(max(0, size - STDERR_TAIL_BYTES))
|
|
400
|
+
data = fh.read(STDERR_TAIL_BYTES)
|
|
401
|
+
except OSError:
|
|
402
|
+
return ""
|
|
403
|
+
lines = [line.rstrip("\r") for line in data.decode("utf-8", "replace").split("\n")]
|
|
404
|
+
if size > STDERR_TAIL_BYTES and len(lines) > 1:
|
|
405
|
+
lines = lines[1:] # the read started inside this line
|
|
406
|
+
while lines and not lines[-1]:
|
|
407
|
+
lines.pop()
|
|
408
|
+
return "\n".join(lines[-STDERR_TAIL_LINES:])
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def page_lines(path, *, first_n: int = 1, after: int = 0, limit: int = 500,
|
|
412
|
+
max_bytes: int = OUTPUT_PAGE_BYTES, clip: int = OUTPUT_LINE_CLIP,
|
|
413
|
+
complete_only: bool = False) -> tuple[list[dict], int]:
|
|
414
|
+
"""The lines of ``path`` numbered from ``first_n`` with ``n > after``, and the last line's number.
|
|
415
|
+
|
|
416
|
+
Returns ``([{"n", "text", "clipped"?}], total)``; ``total`` is
|
|
417
|
+
``first_n - 1`` for an empty file. At most ``limit`` lines and about
|
|
418
|
+
``max_bytes`` of text, but at least one line when one is due. A line
|
|
419
|
+
longer than ``clip`` bytes keeps its first ``clip`` bytes and carries
|
|
420
|
+
``clipped: true``. ``complete_only`` leaves out a last line that has no
|
|
421
|
+
newline yet, for a file another process is still writing; the file is
|
|
422
|
+
read only up to its size at open. Raises ``OSError`` when it cannot be opened.
|
|
423
|
+
"""
|
|
424
|
+
lines: list[dict] = []
|
|
425
|
+
with open(path, "rb") as fh:
|
|
426
|
+
size = os.fstat(fh.fileno()).st_size
|
|
427
|
+
n = first_n - 1
|
|
428
|
+
n += _skip_lines(fh, max(0, after - n), size)
|
|
429
|
+
used = 0
|
|
430
|
+
while len(lines) < limit and fh.tell() < size:
|
|
431
|
+
mark = fh.tell()
|
|
432
|
+
raw, complete, clipped = _read_line(fh, size, clip)
|
|
433
|
+
if not complete and complete_only:
|
|
434
|
+
fh.seek(mark)
|
|
435
|
+
break
|
|
436
|
+
if n + 1 > after:
|
|
437
|
+
cost = len(raw) + 1
|
|
438
|
+
if lines and used + cost > max_bytes:
|
|
439
|
+
fh.seek(mark)
|
|
440
|
+
break
|
|
441
|
+
used += cost
|
|
442
|
+
row = {"n": n + 1, "text": raw.decode("utf-8", "replace").rstrip("\r")}
|
|
443
|
+
if clipped:
|
|
444
|
+
row["clipped"] = True
|
|
445
|
+
lines.append(row)
|
|
446
|
+
n += 1
|
|
447
|
+
n += _count_lines(fh, size, complete_only=complete_only)
|
|
448
|
+
return lines, n
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _skip_lines(fh, count: int, size: int) -> int:
|
|
452
|
+
"""Move past ``count`` newline-terminated lines (fewer at the end); returns how many."""
|
|
453
|
+
passed = 0
|
|
454
|
+
pos = resume = fh.tell()
|
|
455
|
+
while passed < count and pos < size:
|
|
456
|
+
chunk = fh.read(min(_CHUNK, size - pos))
|
|
457
|
+
if not chunk:
|
|
458
|
+
break
|
|
459
|
+
found = chunk.count(b"\n")
|
|
460
|
+
if found and passed + found <= count:
|
|
461
|
+
passed += found
|
|
462
|
+
resume = pos + chunk.rfind(b"\n") + 1
|
|
463
|
+
elif found:
|
|
464
|
+
idx = -1
|
|
465
|
+
for _ in range(count - passed):
|
|
466
|
+
idx = chunk.find(b"\n", idx + 1)
|
|
467
|
+
resume = pos + idx + 1
|
|
468
|
+
passed = count
|
|
469
|
+
pos += len(chunk)
|
|
470
|
+
fh.seek(resume)
|
|
471
|
+
return passed
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def _read_line(fh, size: int, clip: int) -> tuple[bytes, bool, bool]:
|
|
475
|
+
"""``(first clip bytes, complete, clipped)`` of the line at the cursor; consumes the whole line."""
|
|
476
|
+
raw = fh.readline(min(clip + 1, size - fh.tell()))
|
|
477
|
+
if raw.endswith(b"\n"):
|
|
478
|
+
return raw[:-1], True, False
|
|
479
|
+
if len(raw) <= clip:
|
|
480
|
+
return raw, False, False
|
|
481
|
+
while fh.tell() < size:
|
|
482
|
+
more = fh.readline(min(_CHUNK, size - fh.tell()))
|
|
483
|
+
if not more:
|
|
484
|
+
break
|
|
485
|
+
if more.endswith(b"\n"):
|
|
486
|
+
return raw[:clip], True, True
|
|
487
|
+
return raw[:clip], False, True
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def _count_lines(fh, end: int, *, complete_only: bool) -> int:
|
|
491
|
+
"""Lines from the cursor to ``end``; a last one with no newline counts unless ``complete_only``."""
|
|
492
|
+
count, last, pos = 0, b"\n", fh.tell()
|
|
493
|
+
while pos < end:
|
|
494
|
+
chunk = fh.read(min(_CHUNK, end - pos))
|
|
495
|
+
if not chunk:
|
|
496
|
+
break
|
|
497
|
+
count += chunk.count(b"\n")
|
|
498
|
+
last = chunk[-1:]
|
|
499
|
+
pos += len(chunk)
|
|
500
|
+
if last != b"\n" and not complete_only:
|
|
501
|
+
count += 1
|
|
502
|
+
return count
|
|
503
|
+
|
|
504
|
+
|
|
262
505
|
def cli_available(provider: str) -> bool:
|
|
263
506
|
return bool(shutil.which({"claude": "claude", "codex": "codex", "gemini": "gemini",
|
|
264
507
|
"grok": "grok"}.get(provider, provider)))
|
services/schedule_store.py
CHANGED
|
@@ -20,6 +20,7 @@ from __future__ import annotations
|
|
|
20
20
|
|
|
21
21
|
import json
|
|
22
22
|
import os
|
|
23
|
+
import re
|
|
23
24
|
import threading
|
|
24
25
|
import time
|
|
25
26
|
import uuid
|
|
@@ -72,7 +73,12 @@ _RUN_FIELDS = (
|
|
|
72
73
|
"run_id", "schedule_id", "schedule_name", "project_path", "trigger", "due_at", "claimed_at",
|
|
73
74
|
"dispatched_at", "finished_at", "status", "job_id", "approval_id", "exit_code", "duration_ms",
|
|
74
75
|
"output_id", "cost_usd", "tokens", "turns", "model", "result_excerpt", "error",
|
|
76
|
+
"output_format", "output_lines", "output_dropped", "stderr_tail",
|
|
75
77
|
)
|
|
78
|
+
# Files kept beside ``<run_id>.json`` and swept with it: the stdout archive
|
|
79
|
+
# (services/schedule_runner.archive_output) and grok's prompt file.
|
|
80
|
+
RUN_SIDE_FILES = (".out", ".out.tmp", ".prompt.txt")
|
|
81
|
+
_RUN_ID_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$")
|
|
76
82
|
|
|
77
83
|
|
|
78
84
|
class ScheduleError(ValueError):
|
|
@@ -454,6 +460,8 @@ class ScheduleStore:
|
|
|
454
460
|
write_json_atomic(self._run_path(run["run_id"]), run, ensure_ascii=False, fsync=False)
|
|
455
461
|
|
|
456
462
|
def get_run(self, run_id: str) -> dict | None:
|
|
463
|
+
if not _RUN_ID_RE.match(run_id or ""):
|
|
464
|
+
return None
|
|
457
465
|
path = self._run_path(run_id)
|
|
458
466
|
if not path.exists():
|
|
459
467
|
return None
|
|
@@ -555,7 +563,12 @@ class ScheduleStore:
|
|
|
555
563
|
self._run_path(run["run_id"]).unlink()
|
|
556
564
|
removed += 1
|
|
557
565
|
except OSError:
|
|
558
|
-
|
|
566
|
+
continue
|
|
567
|
+
for suffix in RUN_SIDE_FILES:
|
|
568
|
+
try:
|
|
569
|
+
(self.runs_dir / f"{run['run_id']}{suffix}").unlink(missing_ok=True)
|
|
570
|
+
except OSError:
|
|
571
|
+
pass
|
|
559
572
|
return removed
|
|
560
573
|
|
|
561
574
|
|
|
File without changes
|
{code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{code_context_control-2.159.2.dist-info → code_context_control-2.161.0.dist-info}/top_level.txt
RENAMED
|
File without changes
|