@allansantos-dev/smart-tool 0.9.79 → 0.9.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/README.md +82 -18
  3. package/browser_control.py +10 -3
  4. package/browser_service_client.py +3 -32
  5. package/chromium_flags.py +30 -0
  6. package/client_hooks.py +10 -8
  7. package/code_health.py +182 -0
  8. package/code_impact.py +14 -2
  9. package/config.py +76 -8
  10. package/credential_check.py +38 -0
  11. package/dependency_notice.py +262 -14
  12. package/document_converter.py +221 -0
  13. package/document_read.py +100 -25
  14. package/document_text.py +194 -6
  15. package/dossier.py +71 -9
  16. package/embedding_cache.py +32 -8
  17. package/freshness.py +3 -2
  18. package/hook_decision.py +289 -18
  19. package/hooks/pretool_router.py +5 -4
  20. package/indexer.py +92 -3
  21. package/install.py +66 -27
  22. package/install_runtime.py +24 -10
  23. package/layer_check.py +57 -0
  24. package/link_check.py +69 -0
  25. package/local_embedder.py +115 -58
  26. package/locales/pt-BR.json +122 -18
  27. package/low_priority.py +41 -0
  28. package/model_client.py +1 -1
  29. package/model_health.py +24 -6
  30. package/notice_action.py +9 -0
  31. package/package.json +1 -1
  32. package/pr_comment.py +94 -0
  33. package/pr_impact.py +292 -8
  34. package/process_limits.py +108 -0
  35. package/project_admission.py +17 -15
  36. package/project_monitor.py +33 -7
  37. package/project_scheduler.py +12 -4
  38. package/removed_callers.py +146 -0
  39. package/scout.py +6 -2
  40. package/setup_audit.py +34 -1
  41. package/setup_ui.py +241 -41
  42. package/smart_tool_daemon.py +403 -91
  43. package/tray.py +29 -9
  44. package/update_check.py +18 -0
  45. package/update_splash.py +2 -2
  46. package/usage_meter.py +78 -0
  47. package/version.py +1 -1
  48. package/web_adapters/browser/crawl4ai_search.py +7 -3
  49. package/web_document_graph.py +12 -1
  50. package/web_fetch.py +24 -0
  51. package/web_search_health.py +31 -0
package/setup_ui.py CHANGED
@@ -32,14 +32,17 @@ import i18n
32
32
  import model_catalog
33
33
  import model_defaults
34
34
  import model_health
35
+ import usage_meter
35
36
  import model_upgrade
36
37
  import local_embedder
37
38
  import project_store
38
39
  import secret_store
39
40
  import setup_audit
41
+ import update_check
40
42
  import integration_metrics
41
43
  import version
42
44
  import web_search_external
45
+ import web_search_health
43
46
 
44
47
  SETUP_TOKEN = secrets.token_urlsafe(24)
45
48
 
@@ -204,6 +207,25 @@ def handle_health_get():
204
207
  return model_health.summary()
205
208
 
206
209
 
210
+ def handle_usage_get():
211
+ """The 30-day use of the model gateway over every project, per purpose, and the hourly volume alerts."""
212
+ return usage_meter.overview(30)
213
+
214
+
215
+ def handle_usage_mute(body):
216
+ """Mutes the volume alert of `body["purpose"]` for 7 days and returns the refreshed overview."""
217
+ try:
218
+ usage_meter.mute_volume(body.get("purpose") if isinstance(body, dict) else None)
219
+ except ValueError as exc:
220
+ raise SetupError(str(exc))
221
+ return handle_usage_get()
222
+
223
+
224
+ def handle_web_requesters_get():
225
+ """Who asked the recent web searches: one row per client and project folder, never the query text."""
226
+ return web_search_health.by_requester()
227
+
228
+
207
229
  def handle_notices():
208
230
  """What the tray should show now: the model offer (once a day until answered) and models over the failure limit
209
231
  (once a day each). Fetching marks them announced, so each toast is shown once per reminder period. A project's
@@ -213,23 +235,40 @@ def handle_notices():
213
235
  return {"upgrade": offer, "failing": model_health.alerts_due(), "check_error": upgrade["check_error"]}
214
236
 
215
237
 
216
- def handle_local_models_get():
217
- available = local_embedder.info() if local_embedder.configured() else None
218
- return {"mode": config.local_models_mode(), "modes": list(config.LOCAL_MODEL_MODES),
219
- "sidecar": {"configured": local_embedder.configured(), "url": local_embedder.url(),
220
- "embedding_model": (available or {}).get("model")}}
238
+ def handle_embedder_get():
239
+ """The chosen embedder and what the embeddings home answers: its model identity, whether a rerank host is
240
+ configured in it, or why it cannot be used."""
241
+ available, problem, base = None, "", None
242
+ try:
243
+ base = local_embedder.url()
244
+ available = local_embedder.info()
245
+ except local_embedder.IdentityError as exc:
246
+ problem = str(exc)
247
+ try:
248
+ choice = config.embedder()
249
+ except ValueError as exc:
250
+ choice, problem = None, str(exc)
251
+ return {"embedder": choice, "embedders": list(config.EMBEDDERS),
252
+ "home": {"announced": local_embedder.configured(), "announce": local_embedder.ANNOUNCE, "url": base,
253
+ "embedding_model": (available or {}).get("model"),
254
+ "rerank": bool((available or {}).get("rerank")), "error": problem}}
221
255
 
222
256
 
223
- def handle_local_models_save(body):
224
- if not isinstance(body, dict) or body.get("mode") not in config.LOCAL_MODEL_MODES:
225
- raise SetupError("Invalid mode: use fallback, off or prefer.")
257
+ def handle_embedder_save(body):
258
+ if not isinstance(body, dict) or body.get("embedder") not in config.EMBEDDERS:
259
+ raise SetupError("Invalid embedder: use home or gateway.")
260
+
261
+ def choose(cfg):
262
+ cfg.pop("local_models", None)
263
+ cfg["embedder"] = body["embedder"]
264
+
226
265
  try:
227
- config.update_config(lambda cfg: cfg.update(local_models=body["mode"]))
266
+ config.update_config(choose)
228
267
  except config.ConfigCorruptedError as exc:
229
268
  raise SetupError(str(exc))
230
269
  except OSError as exc:
231
270
  raise SetupError(f"Disk error while saving the configuration ({exc}); try again.")
232
- return {"ok": True, **handle_local_models_get()}
271
+ return {"ok": True, **handle_embedder_get()}
233
272
 
234
273
 
235
274
  def handle_integration_get():
@@ -266,6 +305,22 @@ def handle_integration_get():
266
305
  dependency_mode, dependency_error = config.dependency_mode(), ""
267
306
  except ValueError as exc:
268
307
  dependency_mode, dependency_error = "", str(exc)
308
+ try:
309
+ layer_mode, layer_error = config.layer_mode(), ""
310
+ except ValueError as exc:
311
+ layer_mode, layer_error = "", str(exc)
312
+ try:
313
+ link_mode, link_error = config.link_mode(), ""
314
+ except ValueError as exc:
315
+ link_mode, link_error = "", str(exc)
316
+ try:
317
+ pr_comment, pr_comment_error = config.pr_comment(), ""
318
+ except ValueError as exc:
319
+ pr_comment, pr_comment_error = "", str(exc)
320
+ try:
321
+ decision_mode, decision_error = config.decision_mode(), ""
322
+ except ValueError as exc:
323
+ decision_mode, decision_error = "", str(exc)
269
324
  try:
270
325
  proposals_mode, proposals_error = config.pattern_proposals(), ""
271
326
  except ValueError as exc:
@@ -281,6 +336,11 @@ def handle_integration_get():
281
336
  "duplicate_mode_error": duplicate_error, "duplicate_modes": list(config.DUPLICATE_MODES),
282
337
  "dependency_mode": dependency_mode, "dependency_mode_error": dependency_error,
283
338
  "dependency_modes": list(config.DEPENDENCY_MODES),
339
+ "layer_mode": layer_mode, "layer_mode_error": layer_error, "layer_modes": list(config.LAYER_MODES),
340
+ "link_mode": link_mode, "link_mode_error": link_error, "link_modes": list(config.LINK_MODES),
341
+ "pr_comment": pr_comment, "pr_comment_error": pr_comment_error, "pr_comment_modes": list(config.PR_COMMENT_MODES),
342
+ "decision_mode": decision_mode, "decision_mode_error": decision_error,
343
+ "decision_modes": list(config.DECISION_MODES),
284
344
  "pattern_proposals": proposals_mode, "pattern_proposals_error": proposals_error,
285
345
  "block_patterns": {"proposals": stored["proposals"], "accepted": stored["accepted"],
286
346
  "rejected": len(stored["rejected"]), "error": patterns_error},
@@ -299,10 +359,12 @@ def handle_integration_save(body):
299
359
  except (OSError, ValueError) as exc:
300
360
  raise SetupError(str(exc))
301
361
  return handle_integration_get()
302
- if isinstance(body, dict) and body.get("action") in ("hook_mode", "doc_mode", "comment_mode", "duplicate_mode", "dependency_mode", "pattern_proposals"):
362
+ if isinstance(body, dict) and body.get("action") in ("hook_mode", "doc_mode", "comment_mode", "duplicate_mode", "dependency_mode", "layer_mode", "link_mode", "pr_comment", "decision_mode", "pattern_proposals"):
303
363
  action = body["action"]
304
364
  allowed = {"hook_mode": config.HOOK_MODES, "doc_mode": config.DOC_MODES, "comment_mode": config.COMMENT_MODES,
305
365
  "duplicate_mode": config.DUPLICATE_MODES, "dependency_mode": config.DEPENDENCY_MODES,
366
+ "layer_mode": config.LAYER_MODES, "link_mode": config.LINK_MODES, "pr_comment": config.PR_COMMENT_MODES,
367
+ "decision_mode": config.DECISION_MODES,
306
368
  "pattern_proposals": config.PATTERN_PROPOSAL_MODES}[action]
307
369
  if body.get("mode") not in allowed:
308
370
  raise SetupError(f"Invalid mode: use {', '.join(allowed)}.")
@@ -442,6 +504,25 @@ def handle_autostart_get():
442
504
  return autostart.status()
443
505
 
444
506
 
507
+ def handle_updates_get():
508
+ """The update state for the Startup page: versions, last check, last update, a failed automatic try and the switch."""
509
+ return update_check.status()
510
+
511
+
512
+ def handle_updates_save(body):
513
+ """{"enabled": bool}: the automatic update switch, the same `auto_update` key as the tray menu. Refused while the
514
+ environment opt-out is set, as the tray does, because the choice would have no effect."""
515
+ if not isinstance(body, dict) or not isinstance(body.get("enabled"), bool):
516
+ raise SetupError("Send {\"enabled\": true or false}.")
517
+ if update_check.env_opted_out():
518
+ raise SetupError(f"{update_check.ENV_OPT_OUT}=off is set: automatic updates stay off until it is removed.")
519
+ try:
520
+ config.update_config(lambda cfg: cfg.__setitem__("auto_update", body["enabled"]))
521
+ except (OSError, config.ConfigCorruptedError) as exc:
522
+ raise SetupError(str(exc))
523
+ return update_check.status()
524
+
525
+
445
526
  def handle_autostart_action(body):
446
527
  if not isinstance(body, dict):
447
528
  raise SetupError("Request body must be a JSON object with 'action'.")
@@ -772,10 +853,17 @@ __I18N__
772
853
 
773
854
  <div class="card" id="health-card">
774
855
  <div class="card-head"><h3>Model failures (last 24 h)</h3><span class="pill" id="health-pill" data-tone="busy">Checking</span></div>
775
- <p class="lede">Failed calls to a gateway model, grouped by type (429, 503, timeout, ...) and role, with the latest lines of each group. A model that fails half of its calls (5 or more) also raises a Windows notification.</p>
856
+ <p class="lede">Failed calls to a gateway model, grouped by type (429, 503, timeout, ...) and role, with the latest lines of each group. A model that fails half of its calls (5 or more) also raises a Windows notification. Calls refused while a model is paused show as Circuit open and do not count toward that limit.</p>
776
857
  <div id="health-table"></div>
777
858
  </div>
778
859
 
860
+ <div class="card" id="usage-card">
861
+ <div class="card-head"><h3>Model use (last 30 days)</h3><span class="pill" id="usage-pill" data-tone="busy">Checking</span></div>
862
+ <p class="lede">Calls, failures and, when the gateway reports them, tokens and cost, per purpose and over every project. A purpose whose calls in one hour pass twice its own busiest hour of the previous week (and at least 100) is flagged here; it never raises a notification.</p>
863
+ <div id="usage-table"></div>
864
+ <div class="msg" id="usage-msg" role="status"></div>
865
+ </div>
866
+
779
867
  <div class="card" id="models-card">
780
868
  <div class="card-head"><h3>2. Models</h3><span class="pill" id="models-pill" data-tone="busy">Checking</span></div>
781
869
  <p class="lede">Any model id your gateway accepts. The gateway's catalog shows up as suggestions while you type.</p>
@@ -798,17 +886,17 @@ __I18N__
798
886
  <div class="field"><label for="num-research-iterations">Maximum research rounds</label><span class="explain">How many search rounds a research may run before answering.</span><input type="number" id="num-research-iterations" step="1"><span class="hint" id="research-iterations-hint"></span></div>
799
887
  <div class="field"><label for="num-quick-timeout">Quick search time limit (s)</label><span class="explain">How long a quick web search waits for its sources.</span><input type="number" id="num-quick-timeout" step="1"><span class="hint" id="quick-timeout-hint"></span></div>
800
888
  </div>
801
- <div class="field"><label for="num-site-memory-threshold">Per-site memory similarity</label><span class="explain">How close a new question must be to a remembered page of the same site to reuse it.</span><input type="number" id="num-site-memory-threshold" step="0.01"><span class="hint" id="site-memory-threshold-hint"></span></div>
889
+ <div class="field"><label for="num-site-memory-threshold">Per-site memory similarity</label><span class="explain">How close a new question must be to a remembered page of the same site to reuse it, with the gateway embedder; the embeddings home uses 0.62, measured on its model.</span><input type="number" id="num-site-memory-threshold" step="0.01"><span class="hint" id="site-memory-threshold-hint"></span></div>
802
890
  </details>
803
891
  <div class="actions"><button type="button" class="primary" id="btn-save-models">Save models</button></div>
804
892
  <div class="msg" id="models-msg" role="status"></div>
805
893
  </div>
806
894
  </div>
807
895
 
808
- <div class="card" id="local-models-card">
809
- <div class="card-head"><h3>3. Local models</h3><span class="pill" id="local-pill" data-tone="busy">Checking</span></div>
810
- <p class="lede">Embedding from the mcp-memory sidecar on this machine. Switching between gateway and local rebuilds the project indexes; going back to a model used before reuses its vector cache.</p>
811
- <fieldset class="choice" id="local-models-choice"><legend>When to use the local model</legend></fieldset>
896
+ <div class="card" id="embedder-card">
897
+ <div class="card-head"><h3>3. Embedder</h3><span class="pill" id="embedder-pill" data-tone="busy">Checking</span></div>
898
+ <p class="lede">The embeddings home (casa-de-embeddings) is the embedding service of this machine, shared with other tools; its rerank connector forwards to the rerank host configured in it. Switching the embedder re-embeds each project in the background: the old index keeps answering until the new one is complete, then the old vectors are deleted.</p>
899
+ <fieldset class="choice" id="embedder-choice"><legend>Embedder for the project indexes</legend></fieldset>
812
900
  </div>
813
901
  </section>
814
902
 
@@ -820,6 +908,11 @@ __I18N__
820
908
  <p class="lede">A key is tested with a real search before it is saved, and is protected by DPAPI in this Windows profile.</p>
821
909
  <div id="provider-list"><p class="lede">Loading…</p></div>
822
910
  </div>
911
+ <div class="card" id="requesters-card">
912
+ <h3>Who asked the searches</h3>
913
+ <p class="lede">The recent web search calls grouped by the client and project folder that made them. The text of a search is never recorded.</p>
914
+ <div id="requesters-table"></div>
915
+ </div>
823
916
  <div class="card">
824
917
  <h3>Your contact (optional)</h3>
825
918
  <p class="lede">Wikimedia asks tools to name a contact in their User-Agent. It stays on this machine and is sent only to the search APIs.</p>
@@ -865,6 +958,13 @@ __I18N__
865
958
  <div class="actions"><button type="button" id="btn-autostart-toggle" disabled>Checking</button></div>
866
959
  <div class="msg" id="autostart-msg" role="status"></div>
867
960
  </div>
961
+ <div class="card" id="updates-card">
962
+ <div class="card-head"><h3>Automatic updates</h3><span class="pill" id="updates-pill" data-tone="busy">Checking</span></div>
963
+ <p class="lede">Smart Tool checks npm at start and every 24 hours and, when this is on, installs a newer version by itself. The switch is the same as in the tray menu.</p>
964
+ <div id="updates-body"></div>
965
+ <div class="actions"><button type="button" id="btn-updates-toggle" disabled>Checking</button></div>
966
+ <div class="msg" id="updates-msg" role="status"></div>
967
+ </div>
868
968
  <div class="card">
869
969
  <h3>This installation</h3>
870
970
  <dl class="facts">
@@ -880,7 +980,7 @@ __I18N__
880
980
  const TOKEN = __SETUP_TOKEN__;
881
981
  let status = __STATUS_JSON__;
882
982
  const $ = (id) => document.getElementById(id);
883
- const loaded = { integration: null, autostart: null, providers: null, audit: null };
983
+ const loaded = { integration: null, autostart: null, updates: null, providers: null, audit: null };
884
984
  const failed = {};
885
985
  let serviceDown = false;
886
986
 
@@ -1193,7 +1293,7 @@ for (const [id, action] of [["btn-upgrade-apply", "apply"], ["btn-upgrade-declin
1193
1293
  });
1194
1294
  }
1195
1295
  const FAILURE_TYPES = { "429": "429 Too Many Requests", "503": "503 Service Unavailable", "5xx": "Other 5xx", timeout: "Timeout",
1196
- connection: "Connection", auth: "Authentication (401/403)", other: "Other" };
1296
+ connection: "Connection", circuit_open: "Circuit open", auth: "Authentication (401/403)", other: "Other" };
1197
1297
  const PURPOSE_LABELS = { index_embedding: "Indexing", query_embedding: "Query", rerank: "Rerank", embedding_probe: "Model check", scope: "Scope" };
1198
1298
  function healthHtml(data) {
1199
1299
  const when = (at) => esc(new Date(at * 1000).toLocaleString());
@@ -1220,6 +1320,50 @@ async function loadHealth() {
1220
1320
  $("health-table").textContent = "Could not read the failure log: " + error.message;
1221
1321
  }
1222
1322
  }
1323
+ function usageHtml(data) {
1324
+ const num = (value) => (value === null ? "-" : Number(value).toLocaleString());
1325
+ const cost = (value) => (value === null ? "-" : "$" + Number(value).toFixed(4));
1326
+ const rows = data.by_purpose.map((row) => `<tr><td>${esc(PURPOSE_LABELS[row.purpose] || row.purpose)}</td><td>${num(row.attempts)}</td><td>${num(row.errors)}</td><td>${num(row.prompt_tokens)}</td><td>${num(row.output_tokens)}</td><td>${cost(row.reported_usd)}</td></tr>`).join("");
1327
+ const alerts = data.volume.map((row) => `<li><strong>${esc(PURPOSE_LABELS[row.purpose] || row.purpose)}</strong>: ${row.attempts} calls this hour, limit ${row.threshold}`
1328
+ + (row.muted ? " (muted)" : ` <button type="button" class="mute-volume" data-purpose="${esc(row.purpose)}">Mute for 7 days</button>`) + "</li>").join("");
1329
+ return (alerts ? `<h4>Volume alert</h4><ul>${alerts}</ul>` : "")
1330
+ + (rows ? `<table><tr><th>Purpose</th><th>Calls</th><th>Failed</th><th>Prompt tokens</th><th>Output tokens</th><th>Reported cost</th></tr>${rows}</table>` : "<p>No model call in the last 30 days.</p>")
1331
+ + data.notes.map((note) => `<p class="mono">${esc(note)}</p>`).join("");
1332
+ }
1333
+ async function loadUsage() {
1334
+ try {
1335
+ const data = await getJSON("/setup/usage");
1336
+ const active = data.volume.filter((row) => !row.muted).length;
1337
+ setPill("usage-pill", active ? "bad" : "ok", active ? plural(active, "volume alert") : plural(data.totals.attempts, "call"));
1338
+ $("usage-table").innerHTML = usageHtml(data);
1339
+ } catch (error) {
1340
+ setPill("usage-pill", "bad", "Unavailable");
1341
+ $("usage-table").textContent = "Could not read the usage meter: " + error.message;
1342
+ }
1343
+ }
1344
+ function requestersHtml(data) {
1345
+ const rows = data.rows.map((row) => `<tr><td>${esc(row.client)}</td><td class="mono">${esc(row.project || "-")}</td><td>${row.sessions}</td><td>${row.calls}</td><td>${row.failed}</td><td>${esc(new Date(row.last_at * 1000).toLocaleString())}</td><td>${esc(row.sources.join(", "))}</td></tr>`).join("");
1346
+ return (rows ? `<table><tr><th>Client</th><th>Project</th><th>Sessions</th><th>Calls</th><th>Failed</th><th>Last</th><th>Attributed by</th></tr>${rows}</table>` : "<p>No web search recorded yet.</p>")
1347
+ + (data.unattributed ? `<p class="mono">${plural(data.unattributed, "call")} came without a requester (a client that sent only its name).</p>` : "");
1348
+ }
1349
+ async function loadRequesters() {
1350
+ try {
1351
+ $("requesters-table").innerHTML = requestersHtml(await getJSON("/setup/web-search/requesters"));
1352
+ } catch (error) {
1353
+ $("requesters-table").textContent = "Could not read the search log: " + error.message;
1354
+ }
1355
+ }
1356
+ $("usage-table").addEventListener("click", async (event) => {
1357
+ const button = event.target.closest(".mute-volume");
1358
+ if (!button) return;
1359
+ try {
1360
+ await post("/setup/usage/mute", { purpose: button.dataset.purpose });
1361
+ await loadUsage();
1362
+ setMsg("usage-msg", "ok", "Volume alert muted for 7 days.");
1363
+ } catch (error) {
1364
+ setMsg("usage-msg", "error", error.message);
1365
+ }
1366
+ });
1223
1367
  $("btn-save-models").addEventListener("click", async () => {
1224
1368
  if (!modelsLoaded) { setMsg("models-msg", "error", "The catalog has not loaded yet; nothing was saved."); return; }
1225
1369
  setMsg("models-msg", "", "Saving…");
@@ -1277,34 +1421,34 @@ function checkRadio(name, value) {
1277
1421
  for (const radio of document.querySelectorAll(`input[name="${name}"]`)) radio.checked = radio.value === value;
1278
1422
  }
1279
1423
 
1280
- const LOCAL_OPTIONS = [
1281
- ["fallback", "Only as a fallback", "Use the local model only when the gateway does not have the embedding model.", true],
1282
- ["prefer", "Prefer local", "Use the local model even when the gateway has it; your code vectors stay on this machine."],
1283
- ["off", "Never", "Always use the gateway."],
1424
+ const EMBEDDER_OPTIONS = [
1425
+ ["home", "Embeddings home", "The embedding service of this machine; your code goes to the address it announces, not to the gateway.", true],
1426
+ ["gateway", "Gateway", "The gateway's embedding_model and rerank_model; your code goes to the gateway."],
1284
1427
  ];
1285
- let localMode = null;
1286
- const localSaved = choiceGroup($("local-models-choice"), "local_models", LOCAL_OPTIONS, null, async (mode) => {
1287
- setMsg(localSaved, "", "Saving…");
1428
+ let embedderChoice = null;
1429
+ const embedderSaved = choiceGroup($("embedder-choice"), "embedder", EMBEDDER_OPTIONS, null, async (embedder) => {
1430
+ setMsg(embedderSaved, "", "Saving…");
1288
1431
  try {
1289
- await post("/setup/local-models", { mode });
1290
- localMode = mode;
1291
- setMsg(localSaved, "ok", "Saved. The indexes adjust on the next search or check.");
1432
+ await post("/setup/embedder", { embedder });
1433
+ embedderChoice = embedder;
1434
+ setMsg(embedderSaved, "ok", "Saved. Each project is re-embedded in the background; its old index answers meanwhile.");
1292
1435
  } catch (error) {
1293
- checkRadio("local_models", localMode);
1294
- setMsg(localSaved, "error", error.message);
1436
+ checkRadio("embedder", embedderChoice);
1437
+ setMsg(embedderSaved, "error", error.message);
1295
1438
  }
1296
1439
  });
1297
- async function loadLocalModels() {
1440
+ async function loadEmbedder() {
1298
1441
  try {
1299
- const data = await getJSON("/setup/local-models");
1300
- localMode = data.mode;
1301
- checkRadio("local_models", data.mode);
1302
- if (!data.sidecar.configured) setPill("local-pill", "idle", "No sidecar on this machine");
1303
- else if (data.sidecar.embedding_model) setPill("local-pill", "ok", "Sidecar answering: " + data.sidecar.embedding_model);
1304
- else setPill("local-pill", "warn", "Sidecar not answering (" + data.sidecar.url + ")");
1442
+ const data = await getJSON("/setup/embedder");
1443
+ embedderChoice = data.embedder;
1444
+ checkRadio("embedder", data.embedder);
1445
+ if (data.home.error) setPill("embedder-pill", "warn", data.home.error);
1446
+ else if (!data.home.announced) setPill("embedder-pill", "idle", "Embeddings home not running");
1447
+ else if (data.home.embedding_model) setPill("embedder-pill", "ok", "Embeddings home answering: " + data.home.embedding_model + (data.home.rerank ? " · rerank host configured" : ""));
1448
+ else setPill("embedder-pill", "warn", "Embeddings home not answering (" + data.home.url + ")");
1305
1449
  } catch (error) {
1306
- setPill("local-pill", "bad", "Status unavailable");
1307
- setMsg(localSaved, "error", error.message);
1450
+ setPill("embedder-pill", "bad", "Status unavailable");
1451
+ setMsg(embedderSaved, "error", error.message);
1308
1452
  }
1309
1453
  }
1310
1454
 
@@ -1332,6 +1476,22 @@ const RULES = [
1332
1476
  intro: "Looks up the dependencies an edit of a dependency manifest adds or changes in the OSV advisory database. It never blocks.",
1333
1477
  options: [["warn", "Warn", "The edit runs; the agent is told which added or changed dependencies have known advisories.", true],
1334
1478
  ["off", "Off", "No dependency checks and no network call."]] },
1479
+ { key: "layer_mode", title: "Calls that go up the layers on edit", applies: "Applies on the next edit.",
1480
+ intro: "When the project has confirmed layers (.smart-tool/layers.json), warns about a call an edit adds from a lower layer to a function of a higher one. A project without layers is never checked. It never blocks.",
1481
+ options: [["warn", "Warn", "The edit runs; the agent is told which new calls go up the layers.", true],
1482
+ ["off", "Off", "No layer checks."]] },
1483
+ { key: "link_mode", title: "Broken local links on edit", applies: "Applies on the next edit.",
1484
+ intro: "Checks the relative links (href, src, Markdown link targets) an edit of an HTML or Markdown file adds or changes against the files on disk, and says which ones it could not check. Links that were already broken are left alone. It never blocks.",
1485
+ options: [["warn", "Warn", "The edit runs; the agent is told which new links point to a file that does not exist.", true],
1486
+ ["off", "Off", "No link checks."]] },
1487
+ { key: "pr_comment", title: "Impact report as a pull request comment", applies: "Applies on the next request of an agent.",
1488
+ intro: "Lets Smart Tool post the impact report as a comment on a pull request through the gh CLI, with your own gh login. This writes to GitHub: nothing is ever posted while this is off, and each post is one agent request (project_manage action=pr_impact_comment). A rerun replaces the previous Smart Tool comment instead of adding another.",
1489
+ options: [["off", "Off", "Nothing is posted to GitHub.", true],
1490
+ ["on", "On", "Agents may post the impact report as a comment on a pull request through the gh CLI."]] },
1491
+ { key: "decision_mode", title: "Recorded decisions on edit", applies: "Applies on the next edit.",
1492
+ intro: "Looks up the notes of the project (docs/research, the backlog, CLAUDE.md and AGENTS.md) and its commit messages for the functions an edit touches, and names the ones that record a decision about them. A single-word function name counts only when a note qualifies it with its module or class. It never blocks.",
1493
+ options: [["warn", "Warn", "The edit runs; the agent is told which notes and commits record a decision about a touched function.", true],
1494
+ ["off", "Off", "No decision lookup."]] },
1335
1495
  { key: "pattern_proposals", title: "Block patterns proposed by a model", applies: "Applies to the next review.",
1336
1496
  intro: "Afterwards, never delaying a call, the scope model (else the router model) reviews searches the fixed rule let through and may propose block patterns. Nothing blocks until you accept it on the Redirects page.",
1337
1497
  options: [["on", "On", "Review in the background and list proposals for you.", true],
@@ -1747,6 +1907,43 @@ $("btn-autostart-toggle").addEventListener("click", async () => {
1747
1907
  }
1748
1908
  });
1749
1909
 
1910
+ function updatesHtml(data) {
1911
+ const when = (at) => esc(new Date(at * 1000).toLocaleString());
1912
+ const lines = [`<p>Installed: ${esc(data.installed)}.</p>`, data.checked_at ? `<p>Last check: ${when(data.checked_at)}.</p>` : "<p>Not checked yet.</p>"];
1913
+ if (data.available) lines.push(`<p>Version ${esc(data.latest)} is available. To update by hand, run <span class="mono">${esc(data.command)}</span></p>`);
1914
+ else if (data.checked_at) lines.push("<p>Smart Tool is up to date.</p>");
1915
+ if (data.updated) lines.push(`<p>Updated from ${esc(data.updated.from)} to ${esc(data.updated.to)} on ${when(data.updated.at)}.</p>`);
1916
+ if (data.failed) lines.push(`<p class="msg error">The last automatic update to ${esc(data.failed)} failed; ${esc(data.installed)} is still installed.</p>`);
1917
+ if (data.env_opt_out) lines.push('<p class="hint">SMART_TOOL_AUTO_UPDATE=off is set in the environment: automatic updates stay off until it is removed.</p>');
1918
+ return lines.join("");
1919
+ }
1920
+ async function loadUpdates() {
1921
+ try {
1922
+ loaded.updates = await getJSON("/setup/updates");
1923
+ const data = loaded.updates;
1924
+ setPill("updates-pill", data.automatic ? "ok" : "idle", data.automatic ? "On" : "Off");
1925
+ $("updates-body").innerHTML = updatesHtml(data);
1926
+ const toggle = $("btn-updates-toggle");
1927
+ toggle.disabled = data.env_opt_out;
1928
+ toggle.className = data.enabled ? "" : "primary";
1929
+ toggle.textContent = data.enabled ? "Turn off" : "Turn on";
1930
+ } catch (error) {
1931
+ setPill("updates-pill", "bad", "Status unavailable");
1932
+ setMsg("updates-msg", "error", error.message);
1933
+ }
1934
+ }
1935
+ $("btn-updates-toggle").addEventListener("click", async () => {
1936
+ $("btn-updates-toggle").disabled = true;
1937
+ try {
1938
+ await post("/setup/updates", { enabled: !loaded.updates.enabled });
1939
+ await loadUpdates();
1940
+ setMsg("updates-msg", "ok", loaded.updates.enabled ? "Automatic updates turned on." : "Automatic updates turned off.");
1941
+ } catch (error) {
1942
+ setMsg("updates-msg", "error", error.message);
1943
+ $("btn-updates-toggle").disabled = false;
1944
+ }
1945
+ });
1946
+
1750
1947
  const PROVIDER_STATES = { keyless: ["ok", "Free tier, no key"], configured: ["ok", "Your key"], unreadable: ["bad", "Key unreadable"] };
1751
1948
  function providerRow(name, info) {
1752
1949
  const entry = node("div", "provider-row");
@@ -1998,7 +2195,10 @@ renderGateway();
1998
2195
  renderOverview();
1999
2196
  if (status.gateway.status === "ready") { loadModels(); loadUpgrade(); }
2000
2197
  loadHealth();
2001
- loadLocalModels();
2198
+ loadUsage();
2199
+ loadRequesters();
2200
+ loadUpdates();
2201
+ loadEmbedder();
2002
2202
  loadIntegration();
2003
2203
  loadAutostart();
2004
2204
  loadProviders();