@allansantos-dev/smart-tool 0.9.13 → 0.9.14

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.14 - beta
4
+
5
+ - The setup audit runs on its own: the daemon audits every registered project two minutes after it starts and then
6
+ every 30 minutes, one at a time. MCP servers several projects share are contacted once and a successful result is
7
+ reused for 6 hours (a failure never is, so a server fixed meanwhile shows at once; Run now always contacts them
8
+ again). A project's `.mcp.json` servers are only counted and started when Claude Code approved them
9
+ (`enableAllProjectMcpServers`, `enabledMcpjsonServers`, `disabledMcpjsonServers`): registering a cloned repository
10
+ for search never runs the commands it declares. The summary per project is in
11
+ `~/.smart-tool/data/setup-audit/index.json`; projects no longer registered are dropped from it.
12
+ - **Setup audit** panel on the setup screen: pick a registered project (the one with the most errors opens first) and
13
+ see its last report, scheduled or on request: findings by severity with their documentation link, what is new,
14
+ what was resolved, the tokens each MCP server's tools cost and what was not verified; Run now audits it again.
15
+ Everything taken from config files is shown as text.
16
+
3
17
  ## 0.9.13 - beta
4
18
 
5
19
  - Setup audit: `project_manage` with `action=setup_audit` and a `project_root` (or `python setup_audit.py --project
package/README.md CHANGED
@@ -15,7 +15,7 @@ registered as the `playwright` server where this machine lets a browser be drive
15
15
  An optional hook routes the agent's native Grep/Glob/Read/Bash/WebSearch/WebFetch calls to these tools when they
16
16
  are cheaper, or just tells the agent what Smart Tool would do.
17
17
 
18
- **Status:** 0.9.13 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
18
+ **Status:** 0.9.14 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
19
19
 
20
20
  ## How it works
21
21
 
@@ -160,7 +160,11 @@ Open the setup screen from the tray icon ("Open settings") or at `http://127.0.0
160
160
  directly), skills sharing a name or over the description budget, an AGENTS.md only Codex reads, broken `@imports`
161
161
  and a Codex instruction chain over 32 KiB. Each finding links the documentation it relies on; nothing is edited,
162
162
  env and header values never enter the report, and what could not be checked is listed as not verified. A second
163
- run shows what is new and what was resolved.
163
+ run shows what is new and what was resolved. The daemon also runs it on its own for every registered project,
164
+ two minutes after it starts and then every 30 minutes (MCP servers shared by several projects are contacted once
165
+ and their result reused for 6 hours; Run now always contacts them again), and the setup screen's **Setup audit**
166
+ panel shows each project's last report: findings by severity, what is new, what was resolved, the tokens each MCP
167
+ server's tools cost and what was not verified.
164
168
  4. **Local models** (optional): if the mcp-memory embedding sidecar is installed on the machine, its local embedder
165
169
  can serve as a fallback (or preferred) embedding model.
166
170
  5. **Web search providers** work without keys on their free public tiers; add your own key for more volume. Set your
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allansantos-dev/smart-tool",
3
- "version": "0.9.13",
3
+ "version": "0.9.14",
4
4
  "description": "Local MCP server that gives coding agents (Claude Code, Codex) cheaper, sharper tools than their built-in search. Windows.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Allan Santos",
package/setup_audit.py CHANGED
@@ -33,7 +33,11 @@ import endpoint_sync
33
33
  import paths
34
34
 
35
35
  REPORT_DIR = os.path.join(paths.DATA_DIR, "setup-audit")
36
+ INDEX_NAME = "index.json"
36
37
  PROBE_TIMEOUT_S = 15
38
+ SCHEDULE_S = 30 * 60
39
+ FIRST_RUN_DELAY_S = 120
40
+ PROBE_MAX_AGE_S = 6 * 3600
37
41
  SKILL_DESCRIPTION_MAX = 1536
38
42
  SKILL_BUDGET_CHARS = 8000
39
43
  CODEX_PROJECT_DOC_MAX = 32 * 1024
@@ -192,13 +196,21 @@ def _ancestors(project):
192
196
  current = parent
193
197
 
194
198
 
199
+ def _approvals(data, approval):
200
+ """Folds one settings object's .mcp.json approvals (enableAllProjectMcpServers, enabledMcpjsonServers,
201
+ disabledMcpjsonServers) into approval."""
202
+ approval["all"] = approval["all"] or data.get("enableAllProjectMcpServers") is True
203
+ approval["on"].update(data.get("enabledMcpjsonServers") or [])
204
+ approval["off"].update(data.get("disabledMcpjsonServers") or [])
205
+
206
+
195
207
  def collect_claude(project, snapshot):
196
208
  """Claude Code's effective set for project: settings layers, enabled plugins, hooks, MCP, skills, CLAUDE.md."""
197
209
  layers = [(path, "managed") for path in _managed_settings()] + [
198
210
  (os.path.join(endpoint_sync.claude_dir(), "settings.json"), "user"),
199
211
  (os.path.join(project, ".claude", "settings.json"), "project"),
200
212
  (os.path.join(project, ".claude", "settings.local.json"), "local")]
201
- hooks, enabled, overrides, settings = [], {}, {}, []
213
+ hooks, enabled, overrides, settings, approval = [], {}, {}, [], {"all": False, "on": set(), "off": set()}
202
214
  for path, scope in layers:
203
215
  data = snapshot.json(path)
204
216
  if data is None:
@@ -207,14 +219,19 @@ def collect_claude(project, snapshot):
207
219
  hooks += _hooks_from(data, f"settings:{scope}")
208
220
  enabled.update({k: v for k, v in (data.get("enabledPlugins") or {}).items()})
209
221
  overrides.update(data.get("skillOverrides") or {})
222
+ _approvals(data, approval)
210
223
  disabled_skills = {name for name, value in overrides.items() if value == "off"}
211
224
  state = snapshot.json(endpoint_sync.claude_json()) or {}
212
225
  mcp = _mcp_entries(state.get("mcpServers"), "user", endpoint_sync.claude_json())
213
226
  project_state = (state.get("projects") or {}).get(os.path.abspath(project).replace("\\", "/")) or \
214
227
  (state.get("projects") or {}).get(os.path.abspath(project)) or {}
215
228
  mcp += _mcp_entries(project_state.get("mcpServers"), "local", endpoint_sync.claude_json())
229
+ _approvals(project_state, approval)
216
230
  project_mcp = snapshot.json(os.path.join(project, ".mcp.json")) or {}
217
- mcp += _mcp_entries(project_mcp.get("mcpServers"), "project", os.path.join(project, ".mcp.json"))
231
+ shared = _mcp_entries(project_mcp.get("mcpServers"), "project", os.path.join(project, ".mcp.json"))
232
+ unapproved = [e["name"] for e in shared
233
+ if e["name"] in approval["off"] or not (approval["all"] or e["name"] in approval["on"])]
234
+ mcp += [e for e in shared if e["name"] not in unapproved]
218
235
  skills = _skills(snapshot, os.path.join(endpoint_sync.claude_dir(), "skills"), "user", disabled=disabled_skills)
219
236
  skills += _skills(snapshot, os.path.join(project, ".claude", "skills"), "project", disabled=disabled_skills)
220
237
  plugins = []
@@ -245,7 +262,7 @@ def collect_claude(project, snapshot):
245
262
  if text is not None:
246
263
  instructions.append({"path": path, "kind": kind, "bytes": len(text.encode("utf-8")), "_text": text})
247
264
  return {"settings": settings, "plugins": plugins, "hooks": hooks, "mcp": mcp, "skills": skills,
248
- "instructions": instructions}
265
+ "instructions": instructions, "unapproved_mcp": unapproved}
249
266
 
250
267
 
251
268
  def collect_codex(project, snapshot):
@@ -513,16 +530,40 @@ def _rpc_http(entry, timeout):
513
530
  return {"error": str(getattr(exc, "reason", exc)), "kind": "down"}
514
531
 
515
532
 
516
- def probe_mcp(entries, cwd, timeout=PROBE_TIMEOUT_S):
517
- """Tools of each MCP server, started or called as a session would (in parallel)."""
533
+ _PROBES = {}
534
+ _PROBES_LOCK = threading.Lock()
535
+
536
+
537
+ def _probe_key(entry, cwd):
538
+ """Identity of a server launch (secrets only as a hash), shared by the projects and harnesses that register it;
539
+ the folder counts for servers a project registers itself and for arguments that may be relative paths."""
540
+ relative = any(not a.startswith("-") and not os.path.isabs(a) and ("/" in a or "\\" in a or "." in a)
541
+ for a in entry["args"])
542
+ per_project = entry["transport"] == "stdio" and (entry["scope"] in ("project", "local") or relative)
543
+ spec = [entry["transport"], entry.get("command"), entry["args"], entry.get("url"), sorted(entry["_env"].items()),
544
+ sorted(entry["_headers"].items()), entry.get("_bearer_env"), cwd if per_project else None]
545
+ return hashlib.sha256(json.dumps(spec, default=str).encode()).hexdigest()
546
+
547
+
548
+ def probe_mcp(entries, cwd, timeout=PROBE_TIMEOUT_S, max_age=0):
549
+ """Tools of each MCP server, started or called as a session would (in parallel). With max_age, a result of the
550
+ same launch younger than that is reused (failures never are: a server fixed meanwhile shows at once): the periodic
551
+ audit does not start every server of every project each time. Each result carries `probed_at`."""
518
552
  def one(entry):
553
+ key = _probe_key(entry, cwd)
554
+ with _PROBES_LOCK:
555
+ cached = _PROBES.get(key)
556
+ if max_age and cached and not cached.get("error") and time.time() - cached["probed_at"] < max_age:
557
+ return cached
519
558
  # A server whose config cannot even be used (a URL with an unexpanded variable, a bad port) is a finding.
520
559
  try:
521
- if entry["transport"] == "http":
522
- return _rpc_http(entry, timeout)
523
- return _rpc_stdio(entry, cwd, timeout)
560
+ result = _rpc_http(entry, timeout) if entry["transport"] == "http" else _rpc_stdio(entry, cwd, timeout)
524
561
  except Exception as exc:
525
- return {"error": f"{type(exc).__name__}: {exc}"[:200], "kind": "down"}
562
+ result = {"error": f"{type(exc).__name__}: {exc}"[:200], "kind": "down"}
563
+ result["probed_at"] = time.time()
564
+ with _PROBES_LOCK:
565
+ _PROBES[key] = result
566
+ return result
526
567
  with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
527
568
  return list(pool.map(one, entries))
528
569
 
@@ -578,9 +619,10 @@ def _public(section):
578
619
  return out
579
620
 
580
621
 
581
- def run(project, probe=True, save=True):
622
+ def run(project, probe=True, save=True, probe_max_age=0, trigger="manual"):
582
623
  """Collects both harnesses for project, runs every check and returns the report; with save, stores it and
583
- marks findings new or resolved against the previous report of the same project."""
624
+ marks findings new or resolved against the previous report of the same project. probe_max_age reuses recent
625
+ MCP probes (periodic runs); trigger records who asked (manual or schedule)."""
584
626
  project = os.path.abspath(project)
585
627
  snapshot = _Snapshot()
586
628
  claude, codex = collect_claude(project, snapshot), collect_codex(project, snapshot)
@@ -590,12 +632,16 @@ def run(project, probe=True, save=True):
590
632
  findings += check_hook_overlap(harness, data["hooks"], tools)
591
633
  findings += check_hook_targets(harness, data["hooks"], names, probe)
592
634
  findings += check_skills(harness, data["skills"])
593
- results = probe_mcp(data["mcp"], project) if probe else [None] * len(data["mcp"])
635
+ results = (probe_mcp(data["mcp"], project, max_age=probe_max_age) if probe
636
+ else [None] * len(data["mcp"]))
594
637
  findings += check_mcp(harness, data["mcp"], results)
595
638
  findings += check_instructions(project, claude, codex)
596
639
  unverified = list(snapshot.unverified)
597
640
  if not probe:
598
641
  unverified.append("MCP servers and HTTP hook endpoints were not contacted (probe off)")
642
+ for name in claude["unapproved_mcp"]:
643
+ unverified.append(f".mcp.json server '{name}' is not approved in Claude Code, so it is neither loaded nor "
644
+ "started here")
599
645
  if codex.get("plugins_unverified"):
600
646
  unverified.append("Codex plugins (their skills and hooks) are not collected yet")
601
647
  unverified += ["skill trigger overlap and contradictions between instructions need a model (not run)",
@@ -603,7 +649,7 @@ def run(project, probe=True, save=True):
603
649
  key = hashlib.sha256(json.dumps(sorted(snapshot.files.items())).encode()).hexdigest()[:16]
604
650
  order = {"error": 0, "warn": 1, "info": 2}
605
651
  findings.sort(key=lambda f: (order[f["severity"]], f["harness"], f["check"], f["subject"]))
606
- report = {"project": project, "checked_at": time.time(), "snapshot_key": key, "probe": probe,
652
+ report = {"project": project, "checked_at": time.time(), "snapshot_key": key, "probe": probe, "trigger": trigger,
607
653
  "summary": {s: sum(f["severity"] == s for f in findings) for s in order},
608
654
  "findings": findings, "unverified": unverified,
609
655
  "claude": _public(claude), "codex": _public(codex), "files": len(snapshot.files)}
@@ -612,9 +658,70 @@ def run(project, probe=True, save=True):
612
658
  return report
613
659
 
614
660
 
661
+ def _report_path(project):
662
+ return os.path.join(REPORT_DIR, hashlib.sha1(os.path.abspath(project).lower().encode()).hexdigest()[:12] + ".json")
663
+
664
+
665
+ def last_report(project):
666
+ """The last stored report of project, or None when it was never audited."""
667
+ try:
668
+ with open(_report_path(project), encoding="utf-8") as stream:
669
+ return json.load(stream)
670
+ except FileNotFoundError:
671
+ return None
672
+
673
+
674
+ def index():
675
+ """{project: {summary, new, resolved, checked_at, trigger}} of every audited project (the periodic summary)."""
676
+ try:
677
+ with open(os.path.join(REPORT_DIR, INDEX_NAME), encoding="utf-8") as stream:
678
+ data = json.load(stream)
679
+ except FileNotFoundError:
680
+ return {}
681
+ if not isinstance(data, dict):
682
+ raise ValueError(f"{os.path.join(REPORT_DIR, INDEX_NAME)} is not a setup audit index: fix or delete it.")
683
+ return data
684
+
685
+
686
+ _INDEX_LOCK = threading.Lock()
687
+
688
+
689
+ def index_key(project):
690
+ """The index key of a folder: the same for any spelling of it on this OS."""
691
+ return os.path.normcase(os.path.abspath(project))
692
+
693
+
694
+ def _write_index(data):
695
+ atomic_io.write_secret_text(os.path.join(REPORT_DIR, INDEX_NAME), json.dumps(data, indent=1, ensure_ascii=False))
696
+
697
+
698
+ def prune_index(projects):
699
+ """Drops the index entries and reports of folders no longer registered."""
700
+ keep = {index_key(p) for p in projects}
701
+ with _INDEX_LOCK:
702
+ data = index()
703
+ gone = [key for key in data if key not in keep]
704
+ for key in gone:
705
+ data.pop(key)
706
+ try:
707
+ os.remove(_report_path(key))
708
+ except FileNotFoundError:
709
+ pass
710
+ if gone:
711
+ _write_index(data)
712
+ return gone
713
+
714
+
615
715
  def _save_with_diff(report):
716
+ """Stores the report, marks findings new or resolved against the previous one and updates the index, all under
717
+ one lock: the scheduler, Run now and project_manage may audit the same folder at once."""
718
+ with _INDEX_LOCK:
719
+ _save_locked(report)
720
+
721
+
722
+ def _save_locked(report):
616
723
  os.makedirs(REPORT_DIR, exist_ok=True)
617
- last_path = os.path.join(REPORT_DIR, hashlib.sha1(report["project"].lower().encode()).hexdigest()[:12] + ".json")
724
+ last_path = _report_path(report["project"])
618
725
  try:
619
726
  with open(last_path, encoding="utf-8") as stream:
620
727
  previous = json.load(stream)
@@ -629,6 +736,58 @@ def _save_with_diff(report):
629
736
  for finding in report["findings"]:
630
737
  finding["new"] = finding["id"] not in before
631
738
  atomic_io.write_secret_text(last_path, json.dumps(report, indent=1, ensure_ascii=False))
739
+ changes = report.get("changes") or {}
740
+ data = index()
741
+ data[index_key(report["project"])] = {"summary": report["summary"], "new": len(changes.get("new", [])),
742
+ "resolved": len(changes.get("resolved", [])),
743
+ "checked_at": report["checked_at"], "trigger": report["trigger"],
744
+ "snapshot_key": report["snapshot_key"]}
745
+ _write_index(data)
746
+
747
+
748
+ class Scheduler:
749
+ """Periodic mode: audits every registered project whose folder exists, FIRST_RUN_DELAY_S after start and then
750
+ every SCHEDULE_S, one project at a time, reusing MCP probes younger than PROBE_MAX_AGE_S. projects() returns the
751
+ folders; log gets one line per run and every failure (a failing project never stops the others)."""
752
+
753
+ def __init__(self, projects, log, interval=SCHEDULE_S, first_delay=FIRST_RUN_DELAY_S):
754
+ self._projects, self._log, self._interval, self._first_delay = projects, log, interval, first_delay
755
+ self._stop = threading.Event()
756
+ self._thread = None
757
+
758
+ def start(self):
759
+ self._thread = threading.Thread(target=self._loop, name="setup-audit", daemon=True)
760
+ self._thread.start()
761
+
762
+ def stop(self):
763
+ self._stop.set()
764
+
765
+ def run_once(self):
766
+ """Audits each project once; returns {project: summary or error text}."""
767
+ outcome, projects = {}, list(self._projects())
768
+ prune_index(projects)
769
+ for root in projects:
770
+ if self._stop.is_set():
771
+ break
772
+ if not os.path.isdir(root):
773
+ continue
774
+ try:
775
+ report = run(root, probe_max_age=PROBE_MAX_AGE_S, trigger="schedule")
776
+ outcome[root] = report["summary"]
777
+ except Exception as exc:
778
+ outcome[root] = f"{type(exc).__name__}: {exc}"[:200]
779
+ self._log(f"setup audit failed for {root}: {outcome[root]}")
780
+ errors = sum(v["error"] for v in outcome.values() if isinstance(v, dict))
781
+ self._log(f"setup audit: {len(outcome)} project(s), {errors} error finding(s)")
782
+ return outcome
783
+
784
+ def _loop(self):
785
+ if self._stop.wait(self._first_delay):
786
+ return
787
+ while True:
788
+ self.run_once()
789
+ if self._stop.wait(self._interval):
790
+ return
632
791
 
633
792
 
634
793
  def markdown(report):
package/setup_ui.py CHANGED
@@ -29,7 +29,9 @@ import gateway
29
29
  import model_catalog
30
30
  import model_defaults
31
31
  import local_embedder
32
+ import project_store
32
33
  import secret_store
34
+ import setup_audit
33
35
  import version
34
36
  import web_search_external
35
37
 
@@ -251,6 +253,30 @@ def handle_integration_save(body):
251
253
  raise SetupError("Invalid action: use hook_mode, register_mcp, browser_control, preview or install.")
252
254
 
253
255
 
256
+ def handle_audit(body):
257
+ """Setup audit panel: `index` lists the registered projects with their last audit summary; `report` returns the
258
+ last stored report of one of them; `run` audits it now (MCP servers contacted unless probe is false). Only
259
+ registered project folders are accepted."""
260
+ if not isinstance(body, dict):
261
+ raise SetupError("Invalid request.")
262
+ roots = sorted({p["root"] for p in project_store.all_projects() if p.get("root")}, key=str.casefold)
263
+ try:
264
+ if body.get("action") == "index":
265
+ stored = setup_audit.index()
266
+ found = {root: stored[setup_audit.index_key(root)] for root in roots if setup_audit.index_key(root) in stored}
267
+ return {"projects": roots, "index": found, "schedule_s": setup_audit.SCHEDULE_S}
268
+ root = body.get("project_root")
269
+ if root not in roots:
270
+ raise SetupError("Choose one of the registered projects.")
271
+ if body.get("action") == "report":
272
+ return {"report": setup_audit.last_report(root)}
273
+ if body.get("action") == "run":
274
+ return {"report": setup_audit.run(root, probe=body.get("probe") is not False)}
275
+ except (OSError, ValueError) as exc:
276
+ raise SetupError(str(exc))
277
+ raise SetupError("Invalid action: use index, report or run.")
278
+
279
+
254
280
  def handle_providers_get():
255
281
  return {"providers": {
256
282
  name: {**web_search_external.PROVIDERS[name], "status": config.provider_key_status(name)}
@@ -498,6 +524,15 @@ _PAGE_TEMPLATE = """<!doctype html>
498
524
  .pattern-actions button { padding: 4px 10px; font-size: .78rem; }
499
525
  .pattern-pager { justify-content: space-between; }
500
526
  .pattern-blocking > summary { cursor: pointer; font: 600 .9rem var(--display); }
527
+ .audit-list { list-style: none; padding: 0; margin: 10px 0; }
528
+ .audit-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
529
+ .audit-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
530
+ .audit-sev { font: 600 .72rem var(--display); letter-spacing: .06em; text-transform: uppercase; }
531
+ .audit-error { color: var(--bad); }
532
+ .audit-warn { color: var(--warn); }
533
+ .audit-info { color: var(--muted); }
534
+ .audit-new { font: 600 .72rem var(--display); color: var(--signal); }
535
+ .audit-detail { font-size: .84rem; margin: 4px 0 0; overflow-wrap: anywhere; }
501
536
 
502
537
  body:not(.ready) .station[data-live="1"] .wire::after { transform: scaleX(0); }
503
538
  @media (max-width: 900px) { .panels { grid-template-columns: minmax(0, 1fr); } }
@@ -659,6 +694,17 @@ _PAGE_TEMPLATE = """<!doctype html>
659
694
  <div id="agents-list"></div>
660
695
  </section>
661
696
 
697
+ <section id="audit-section">
698
+ <h2>Setup audit</h2>
699
+ <p class="lede">What Claude Code and Codex load for a project, and where they collide: hooks deciding on the same tool at once, hooks or MCP servers that do not work, tools offered twice, skills and instructions one agent never sees. It runs on its own every 30 minutes for the registered projects; nothing is changed.</p>
700
+ <div class="field"><label for="sel-audit-project">Project</label>
701
+ <select id="sel-audit-project"></select>
702
+ <span class="hint" id="audit-hint"></span></div>
703
+ <div class="actions"><button type="button" id="btn-audit-run">Run now</button></div>
704
+ <div class="msg" id="audit-msg" role="status"></div>
705
+ <div id="audit-report"></div>
706
+ </section>
707
+
662
708
  <section id="providers-section">
663
709
  <h2>Web search providers</h2>
664
710
  <p class="lede">All of them work without a key, on each provider's public free tier. Add your own key only if you need more volume: it is tested with a real search before being saved and is protected by DPAPI on this Windows machine.</p>
@@ -1226,6 +1272,114 @@ $("btn-save-hook-mode").addEventListener("click", async () => {
1226
1272
  }
1227
1273
  });
1228
1274
 
1275
+ const AUDIT_SEVERITY = { error: "Error", warn: "Warning", info: "Note" };
1276
+ let auditProjects = [];
1277
+ function auditWhen(seconds) {
1278
+ return seconds ? new Date(seconds * 1000).toLocaleString() : "never";
1279
+ }
1280
+ function renderAudit(report) {
1281
+ const box = $("audit-report");
1282
+ box.replaceChildren();
1283
+ if (!report) {
1284
+ box.appendChild(patternEl("p", "hint", "Not audited yet: the next scheduled run covers it, or press Run now."));
1285
+ return;
1286
+ }
1287
+ const s = report.summary;
1288
+ box.appendChild(patternEl("p", "", s.error + " error(s), " + s.warn + " warning(s), " + s.info + " note(s) · "
1289
+ + (report.trigger === "schedule" ? "scheduled run" : "run on request") + " at " + auditWhen(report.checked_at)));
1290
+ const changes = report.changes;
1291
+ if (changes) box.appendChild(patternEl("p", "hint", "Since the previous run: " + changes.new.length + " new, "
1292
+ + changes.resolved.length + " resolved" + (changes.snapshot_changed ? " (configuration changed)." : ".")));
1293
+ const list = patternEl("ul", "audit-list");
1294
+ for (const finding of report.findings) {
1295
+ const row = patternEl("li", "audit-row");
1296
+ const head = patternEl("div", "audit-head");
1297
+ head.append(patternEl("span", "audit-sev audit-" + finding.severity, AUDIT_SEVERITY[finding.severity] || finding.severity),
1298
+ patternEl("span", "pattern-tool", finding.harness), patternEl("strong", "", finding.subject));
1299
+ if (finding.new) head.appendChild(patternEl("span", "audit-new", "new"));
1300
+ const detail = patternEl("p", "audit-detail", finding.detail + " ");
1301
+ if ((finding.source || "").startsWith("https://")) {
1302
+ const link = patternEl("a", "", "documentation");
1303
+ link.setAttribute("href", finding.source);
1304
+ link.setAttribute("target", "_blank");
1305
+ link.setAttribute("rel", "noopener noreferrer");
1306
+ detail.appendChild(link);
1307
+ }
1308
+ row.append(head, detail);
1309
+ list.appendChild(row);
1310
+ }
1311
+ if (report.findings.length) box.appendChild(list);
1312
+ else box.appendChild(patternEl("p", "msg ok", "No collision or broken piece found."));
1313
+ if (changes && changes.resolved.length) {
1314
+ const resolved = patternEl("details", "");
1315
+ resolved.appendChild(patternEl("summary", "", "Resolved since the previous run (" + changes.resolved.length + ")"));
1316
+ const items = patternEl("ul", "audit-list");
1317
+ for (const finding of changes.resolved) items.appendChild(patternEl("li", "audit-detail", finding.subject + ": " + finding.detail));
1318
+ resolved.appendChild(items);
1319
+ box.appendChild(resolved);
1320
+ }
1321
+ const costs = [];
1322
+ for (const side of ["claude", "codex"]) {
1323
+ const servers = ((report[side] || {}).mcp || []).filter((m) => m.tools !== undefined);
1324
+ if (servers.length) costs.push(side + ": " + servers.map((m) => m.name + " " + m.tools + " tools (~"
1325
+ + Math.round(m.tool_chars / 4).toLocaleString() + " tokens)").join(", "));
1326
+ }
1327
+ if (costs.length) box.appendChild(patternEl("p", "hint", "MCP tools offered — " + costs.join(" · ")));
1328
+ const unverified = patternEl("details", "");
1329
+ unverified.appendChild(patternEl("summary", "", "Not verified (" + report.unverified.length + ")"));
1330
+ const items = patternEl("ul", "audit-list");
1331
+ for (const item of report.unverified) items.appendChild(patternEl("li", "audit-detail", item));
1332
+ unverified.appendChild(items);
1333
+ box.appendChild(unverified);
1334
+ }
1335
+ async function showAudit(root) {
1336
+ try {
1337
+ renderAudit((await post("/setup/audit", { action: "report", project_root: root })).report);
1338
+ } catch (error) {
1339
+ setMsg("audit-msg", "error", error.message);
1340
+ }
1341
+ }
1342
+ async function loadAudit() {
1343
+ try {
1344
+ const data = await post("/setup/audit", { action: "index" });
1345
+ auditProjects = data.projects;
1346
+ const select = $("sel-audit-project");
1347
+ select.replaceChildren();
1348
+ for (const root of data.projects) {
1349
+ const entry = data.index[root];
1350
+ const label = root + (entry ? " — " + entry.summary.error + " error(s), " + entry.summary.warn + " warning(s)" : " — not audited yet");
1351
+ const option = patternEl("option", "", label);
1352
+ option.value = root;
1353
+ select.appendChild(option);
1354
+ }
1355
+ $("audit-hint").textContent = data.projects.length ? "Runs every " + Math.round(data.schedule_s / 60) + " minutes." : "Register a project to audit it.";
1356
+ $("btn-audit-run").disabled = !data.projects.length;
1357
+ if (data.projects.length) {
1358
+ const worst = data.projects.slice().sort((a, b) => ((data.index[b] || {summary: {error: -1}}).summary.error)
1359
+ - ((data.index[a] || {summary: {error: -1}}).summary.error))[0];
1360
+ select.value = worst;
1361
+ await showAudit(worst);
1362
+ }
1363
+ } catch (error) {
1364
+ setMsg("audit-msg", "error", "Setup audit unavailable: " + error.message);
1365
+ }
1366
+ }
1367
+ $("sel-audit-project").addEventListener("change", () => showAudit($("sel-audit-project").value));
1368
+ $("btn-audit-run").addEventListener("click", async () => {
1369
+ const button = $("btn-audit-run");
1370
+ button.disabled = true;
1371
+ setMsg("audit-msg", "", "Auditing; MCP servers are being contacted…");
1372
+ try {
1373
+ renderAudit((await post("/setup/audit", { action: "run", project_root: $("sel-audit-project").value })).report);
1374
+ setMsg("audit-msg", "ok", "Audit finished.");
1375
+ } catch (error) {
1376
+ setMsg("audit-msg", "error", error.message);
1377
+ } finally {
1378
+ button.disabled = false;
1379
+ }
1380
+ });
1381
+ loadAudit();
1382
+
1229
1383
  const providerLabels = { keyless: ["warn", "No key · free tier"], configured: ["ok", "Key configured"], unreadable: ["bad", "Key unreadable in this Windows profile"] };
1230
1384
  function providerCard(name, info) {
1231
1385
  const card = document.createElement("div");
@@ -3473,6 +3473,7 @@ _SETUP_SAVES = {
3473
3473
  "/setup/gateway": setup_ui.handle_gateway_save,
3474
3474
  "/setup/autostart": setup_ui.handle_autostart_action,
3475
3475
  "/setup/contact": setup_ui.handle_contact_save,
3476
+ "/setup/audit": setup_ui.handle_audit,
3476
3477
  }
3477
3478
 
3478
3479
 
@@ -3789,9 +3790,12 @@ def main():
3789
3790
  _log(f"project monitor started; {recovered} interrupted job(s) recovered")
3790
3791
  except Exception as exc:
3791
3792
  _log(f"project monitor unavailable: {_project_error(exc)}")
3793
+ audit = setup_audit.Scheduler(lambda: [p["root"] for p in project_store.all_projects() if p.get("root")], _log)
3794
+ audit.start()
3792
3795
  try:
3793
3796
  server.serve_forever()
3794
3797
  finally:
3798
+ audit.stop()
3795
3799
  if _PROJECT_MONITOR:
3796
3800
  _PROJECT_MONITOR.stop()
3797
3801
  with _JOBS_LOCK:
package/version.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Single source of the Smart Tool version and of the User-Agent sent to public APIs."""
2
2
  import re
3
3
 
4
- VERSION = "0.9.13"
4
+ VERSION = "0.9.14"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7