@allansantos-dev/smart-tool 0.9.11 → 0.9.13

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/setup_ui.py CHANGED
@@ -938,6 +938,7 @@ function browserText(item) {
938
938
  const state = item.browser_control || {};
939
939
  if (state.state === "registered") return "Browser control on: Playwright MCP drives an isolated, headless Chromium";
940
940
  if (state.state === "kept") return "Browser control: your own playwright MCP server is kept";
941
+ if (state.state === "undenied") return "Browser control is registered without its safety rule: " + state.reason;
941
942
  if (state.state === "unavailable") return "Browser control unavailable on this machine (" + state.reason + "); pages are still read by web_fetch";
942
943
  return "Browser control is set up when the MCP is registered";
943
944
  }
@@ -35,6 +35,7 @@ import uuid
35
35
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
36
36
 
37
37
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
38
+ import browser_control
38
39
  import capabilities
39
40
  import client_hooks
40
41
  import install_runtime
@@ -58,6 +59,7 @@ import project_monitor
58
59
  import research_metrics
59
60
  import research_cache
60
61
  import router
62
+ import setup_audit
61
63
  import setup_ui
62
64
  import site_memory
63
65
  import web_search_adapters
@@ -309,7 +311,10 @@ def _smart_search_job_payload(job_id):
309
311
  # upfront, so a blocked agent already has the replacement in its tool list.
310
312
  ALWAYS_LOAD = {"anthropic/alwaysLoad": True}
311
313
  SERVER_INSTRUCTIONS = (
312
- "Smart Tool serves an indexed semantic search over the user's projects and a cheaper web reader. The user installed "
314
+ "Smart Tool serves an indexed semantic search over the user's projects and a cheaper web reader. Use smart_search "
315
+ "FIRST to explore code in the user's projects (where something is implemented, how a flow works, what already "
316
+ "exists to reuse) before reading files one by one; Grep/Read are for an exact string or a file you already know. "
317
+ "Use web_search/web_fetch for any web research. The user also installed "
313
318
  "a PreToolUse hook that blocks content searches over a project folder (grep -r, rg, git grep, Grep on a folder) "
314
319
  "and native WebFetch/WebSearch. A call blocked by Smart Tool is a routing rule, not a failure: make the call the block "
315
320
  "message names (smart_search with project_root and query_identifiers, web_fetch with url and prompt, web_search "
@@ -322,10 +327,10 @@ SERVER_INSTRUCTIONS = (
322
327
  TOOLS = [
323
328
  {
324
329
  "name": "project_manage",
325
- "description": "Manages folders and indexing. Every action takes project_root (the folder) or project_id. list gives a short line per project; status shows storage, scope and jobs. graph with symbol (function, Class.method, class name, or path::name when the name repeats) answers what an edit touches: definition, callers with line, calls, tests that reach it through static calls (depth hops, default 3) and files importing it; use it before changing a function to know what to update. affected_tests answers which tests to run after editing: every test file importing a changed file (git diff against base, default HEAD, untracked included) plus changed tests, likeliest failures first, with the command to run them and run_all when config or unanalyzed code changed. graph without symbol reads the indexed view: coverage, references and static calls in Java, Angular, Python and JS/TS/JSX/TSX; includes HTML/CSS/Markdown references and TXT/DOCX coverage; with file_path, narrows to that file's symbols, imports and calls (lists capped by limit). inspect lists the files of a view_id; with file_path, returns only that file's chunks. usage shows consumption and reuse; docs lists public functions without a docstring (Python docstring, JSDoc, Javadoc; private, nested and override functions excluded) with coverage percent, excluding tests unless include_tests=true, for documenting a project that started without it; duplicates lists duplicated functions (identical, near-identical and semantic bodies, min_similarity default 0.90; below that most pairs measured were false positives), excluding tests unless include_tests=true; fix real duplicates; only dismiss with duplicates_dismiss (finding_id, reason=false_positive|intentional, note) what is not a duplicate or is a copy kept on purpose: the finding stays hidden until the code changes, and duplicates_restore reopens it; integration shows the MCP client, hook and tool usage metrics; install_hook_preview shows the change that would install the hook redirecting Grep/Read to smart_search and WebSearch/WebFetch to web_search/web_fetch in this session's client and returns a plan_id; install_hook writes it with that plan_id and confirm=true, with a backup, only after the user approves the change; search_limits saves the project's default top_k per block ({code, test, doc}, each 1-20, total at most 20); storage shows disk usage and views; pin_view protects a view; cleanup_preview and cleanup_commit remove selected views after confirmation; compare compares two stored views, without checkout or embeddings. register adds a folder; preview checks the scope; index/rebuild update; pause/cancel keep checkpoints; resume continues; policy picks on_search/eager; scope adjusts the scope; remove deletes only the local index. Jobs via smart_search_result.",
330
+ "description": "Manages folders and indexing. Every action takes project_root (the folder) or project_id. list gives a short line per project; status shows storage, scope and jobs. graph with symbol (function, Class.method, class name, or path::name when the name repeats) answers what an edit touches: definition, callers with line, calls, tests that reach it through static calls (depth hops, default 3) and files importing it; use it before changing a function to know what to update. affected_tests answers which tests to run after editing: every test file importing a changed file (git diff against base, default HEAD, untracked included) plus changed tests, likeliest failures first, with the command to run them and run_all when config or unanalyzed code changed. graph without symbol reads the indexed view: coverage, references and static calls in Java, Angular, Python and JS/TS/JSX/TSX; includes HTML/CSS/Markdown references and TXT/DOCX coverage; with file_path, narrows to that file's symbols, imports and calls (lists capped by limit). inspect lists the files of a view_id; with file_path, returns only that file's chunks. usage shows consumption and reuse; docs lists public functions without a docstring (Python docstring, JSDoc, Javadoc; private, nested and override functions excluded) with coverage percent, excluding tests unless include_tests=true, for documenting a project that started without it; duplicates lists duplicated functions (identical, near-identical and semantic bodies, min_similarity default 0.90; below that most pairs measured were false positives), excluding tests unless include_tests=true; fix real duplicates; only dismiss with duplicates_dismiss (finding_id, reason=false_positive|intentional, note) what is not a duplicate or is a copy kept on purpose: the finding stays hidden until the code changes, and duplicates_restore reopens it; integration shows the MCP client, hook and tool usage metrics; install_hook_preview shows the change that would install the hook redirecting Grep/Read to smart_search and WebSearch/WebFetch to web_search/web_fetch in this session's client and returns a plan_id; install_hook writes it with that plan_id and confirm=true, with a backup, only after the user approves the change; search_limits saves the project's default top_k per block ({code, test, doc}, each 1-20, total at most 20); storage shows disk usage and views; pin_view protects a view; cleanup_preview and cleanup_commit remove selected views after confirmation; compare compares two stored views, without checkout or embeddings. register adds a folder; preview checks the scope; index/rebuild update; pause/cancel keep checkpoints; resume continues; policy picks on_search/eager; scope adjusts the scope; remove deletes only the local index. setup_audit (project_root) reports what Claude Code and Codex actually load for that folder (settings layers, plugins, hooks, MCP servers, skills, CLAUDE.md/AGENTS.md) and where they collide: hooks deciding on the same tool in parallel, missing hook scripts, silenced hooks, MCP servers down or offering duplicate tools, skill name and budget problems, AGENTS.md that only Codex reads, broken @imports; what could not be checked is listed as not verified. Jobs via smart_search_result.",
326
331
  "inputSchema": {
327
332
  "type": "object", "properties": {
328
- "action": {"type": "string", "enum": ["list", "status", "register", "preview", "index", "rebuild", "pause", "cancel", "resume", "watch", "scope", "remove", "relocate", "probe", "policy", "inspect", "graph", "usage", "storage", "pin_view", "cleanup_preview", "cleanup_commit", "compare", "search_limits", "integration", "install_hook_preview", "install_hook", "duplicates", "duplicates_dismiss", "duplicates_restore", "docs", "affected_tests"]},
333
+ "action": {"type": "string", "enum": ["list", "status", "register", "preview", "index", "rebuild", "pause", "cancel", "resume", "watch", "scope", "remove", "relocate", "probe", "policy", "inspect", "graph", "usage", "storage", "pin_view", "cleanup_preview", "cleanup_commit", "compare", "search_limits", "integration", "install_hook_preview", "install_hook", "duplicates", "duplicates_dismiss", "duplicates_restore", "docs", "affected_tests", "setup_audit"]},
329
334
  "finding_id": {"type": "string"},
330
335
  "reason": {"type": "string", "enum": ["false_positive", "intentional"]},
331
336
  "note": {"type": "string"},
@@ -344,6 +349,7 @@ TOOLS = [
344
349
  "left_view":{"type":"string"},"right_view":{"type":"string"},"relations":{"type":"boolean"},
345
350
  "update_mode": {"type": "string", "enum": ["on_search", "eager"]},
346
351
  "view_id": {"type": "string"}, "file_path": {"type": "string"},
352
+ "probe": {"type": "boolean", "default": True, "description": "setup_audit: start/call each MCP server (initialize + tools/list); false reads configs only"},
347
353
  "base": {"type": "string", "default": "HEAD", "description": "affected_tests: git revision the changes are compared with (HEAD = uncommitted work; main or origin/main for a branch)"},
348
354
  "symbol": {"type": "string", "description": "graph: function, Class.method, class name or path::name to get its callers, calls, tests and importers"},
349
355
  "depth": {"type": "integer", "minimum": 1, "maximum": 4, "default": 3, "description": "graph with symbol: call hops searched for tests"},
@@ -360,8 +366,9 @@ TOOLS = [
360
366
  "name": "smart_search",
361
367
  "_meta": ALWAYS_LOAD,
362
368
  "description": (
363
- "Semantic search (embed+rerank) over the project's index. Use instead of "
364
- "raw grep/read when the search has no clear scope (e.g. a folder with node_modules). "
369
+ "Semantic search (embed+rerank) over the project's index: the first step to understand code in a "
370
+ "project, finding functions, flows and reusable code by meaning, ranked, with name:line. Use it before "
371
+ "a series of Grep/Read; use Grep only for an exact literal or inside a known file. "
365
372
  "Results come in three blocks, code, test and doc, plus the project profile with the natural "
366
373
  "languages of identifiers, comments and docs (also in project_manage list/status as search_profile). "
367
374
  "Fill query_identifiers with identifier and function-name terms in the identifiers' language and "
@@ -1482,6 +1489,13 @@ def _project_summary(project):
1482
1489
  def _project_action(arguments):
1483
1490
  if not isinstance(arguments, dict):
1484
1491
  raise ValueError("Pass the action in a JSON object.")
1492
+ if arguments.get("action") == "setup_audit":
1493
+ root = arguments.get("project_root")
1494
+ if not isinstance(root, str) or not os.path.isdir(root):
1495
+ raise ValueError("setup_audit needs project_root: the folder whose Claude Code and Codex setup to audit.")
1496
+ report = setup_audit.run(root, probe=arguments.get("probe", True) is not False)
1497
+ return {"summary": report["summary"], "snapshot_key": report["snapshot_key"],
1498
+ "report": setup_audit.markdown(report)}
1485
1499
  arguments = _with_project_id(arguments)
1486
1500
  action = arguments.get("action", "list")
1487
1501
  if action == "probe":
@@ -3195,10 +3209,13 @@ WEB_FETCH_VECTOR_ROOT = os.path.join(paths.DATA_DIR, "web-fetch")
3195
3209
 
3196
3210
 
3197
3211
  def _moli_markdown(url, timeout):
3198
- """Markdown of a JavaScript page rendered by Moli (layout and paint only when the page needs them)."""
3212
+ """Markdown of a JavaScript page rendered by Moli (layout and paint only when the page needs them). Every request
3213
+ Moli makes (redirects, scripts, frames, fetch) refuses private, loopback, link-local and CGNAT addresses, as the
3214
+ HTTP reader and the Crawl4AI route guard do: a public page cannot read this machine or its network through it."""
3199
3215
  if not install_runtime.MOLI_EXE.is_file():
3200
3216
  raise RuntimeError(f"Moli is not installed ({install_runtime.MOLI_EXE}); reinstall Smart Tool.")
3201
- done = subprocess.run([str(install_runtime.MOLI_EXE), "fetch", "--dump", "markdown", url], capture_output=True,
3217
+ done = subprocess.run([str(install_runtime.MOLI_EXE), "fetch", "--block-private-networks", "--dump", "markdown",
3218
+ url], capture_output=True,
3202
3219
  timeout=timeout, creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
3203
3220
  if done.returncode:
3204
3221
  raise RuntimeError(f"moli exited {done.returncode}: {done.stderr.decode('utf-8', 'replace').strip()[-300:]}")
@@ -3475,6 +3492,11 @@ class MCPHandler(BaseHTTPRequestHandler):
3475
3492
  return origin is None or _loopback_host(origin, require_port=True)
3476
3493
 
3477
3494
  def _reject_foreign_origin(self):
3495
+ """The agent's browser (Playwright MCP marks every request with AGENT_HEADER) never reaches the daemon: a page
3496
+ it opens could otherwise steer the agent into /setup, whose token unlocks every setting."""
3497
+ if self.headers.get(browser_control.AGENT_HEADER):
3498
+ self._write_json(403, {"error": "Smart Tool's pages are not available to the agent's browser"})
3499
+ return True
3478
3500
  if self._origin_allowed():
3479
3501
  return False
3480
3502
  self._write_json(403, {"error": "origin not allowed"})
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.11"
4
+ VERSION = "0.9.13"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7
 
package/web_fetch.py CHANGED
@@ -20,6 +20,8 @@ import ipaddress
20
20
  import json
21
21
  import socket
22
22
  import ssl
23
+ import subprocess
24
+ import sys
23
25
  import threading
24
26
  import time
25
27
  import urllib.parse
@@ -37,6 +39,8 @@ SELECT_BUDGET_CHARS = 15_000
37
39
  CHUNK_CHARS = 2_000
38
40
  PAGE_FORMAT = 2
39
41
  MAX_DOWNLOAD_BYTES = 5 * 1024 * 1024
42
+ PDF_MAX_PAGES = 300
43
+ PDF_TIMEOUT_S = 30
40
44
  MAX_REDIRECTS = 5
41
45
  HTTP_TIMEOUT_S = 20
42
46
  READ_CHUNK = 64 * 1024
@@ -208,6 +212,48 @@ def thin(text):
208
212
  return len(stripped) < PLACEHOLDER_SCAN_CHARS and any(p in stripped[:600].lower() for p in PLACEHOLDERS)
209
213
 
210
214
 
215
+ PDF_SCRIPT = """
216
+ import io, json, sys
217
+ import pypdf
218
+ reader = pypdf.PdfReader(io.BytesIO(sys.stdin.buffer.read()))
219
+ if reader.is_encrypted and reader.decrypt("") == pypdf.PasswordType.NOT_DECRYPTED:
220
+ print(json.dumps({"encrypted": True}))
221
+ sys.exit()
222
+ limit, budget = int(sys.argv[1]), int(sys.argv[2])
223
+ pages, size = [], 0
224
+ for page in reader.pages[:limit]:
225
+ pages.append((page.extract_text() or "").strip()[:budget - size])
226
+ size += len(pages[-1])
227
+ if size >= budget:
228
+ break
229
+ print(json.dumps({"pages": pages, "count": len(reader.pages)}))
230
+ """
231
+
232
+
233
+ def pdf_text(body, url, deadline):
234
+ """Text of a PDF (pypdf, pure Python), page by page up to PDF_MAX_PAGES. The native WebFetch reads PDFs and the hook
235
+ sends it here, so a PDF used to be a dead end (9 times in 10 days of transcripts). A hostile PDF can make pypdf
236
+ parse for minutes, so it runs in a subprocess killed at the request's deadline (at most PDF_TIMEOUT_S)."""
237
+ timeout = min(PDF_TIMEOUT_S, _left(deadline))
238
+ try:
239
+ done = subprocess.run([sys.executable, "-I", "-c", PDF_SCRIPT, str(PDF_MAX_PAGES), str(PAGE_STORE_MAX_CHARS)],
240
+ input=body, capture_output=True, timeout=timeout,
241
+ creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
242
+ except subprocess.TimeoutExpired:
243
+ raise FetchError(f"PDF not read in {timeout:.0f}s ({url}).") from None
244
+ if done.returncode:
245
+ detail = (done.stderr.decode("utf-8", "replace").strip().splitlines() or ["no output"])[-1]
246
+ raise FetchError(f"PDF could not be read ({url}): {detail}"[:300])
247
+ result = json.loads(done.stdout)
248
+ if result.get("encrypted"):
249
+ raise FetchError(f"PDF protected by a password is not read by web_fetch ({url}).")
250
+ pages = result["pages"]
251
+ text = "\n\n".join(f"[page {number}]\n{page}" for number, page in enumerate(pages, 1) if page)
252
+ if result["count"] > len(pages):
253
+ text += f"\n\n[pages {len(pages) + 1}-{result['count']} not read]"
254
+ return text
255
+
256
+
211
257
  def read_page(url, deadline, render):
212
258
  """Page text (Markdown) from the 24 h cache, HTTP + trafilatura, or `render(url, deadline)` when HTTP comes thin."""
213
259
  url = normalize(url)
@@ -230,6 +276,8 @@ def read_page(url, deadline, render):
230
276
  text, rendered = markdown, True
231
277
  elif kind in TEXT_TYPES:
232
278
  text = _decode(body, charset)
279
+ elif kind == "application/pdf":
280
+ text = pdf_text(body, final_url, deadline)
233
281
  else:
234
282
  raise FetchError(f"Content type {kind} is not read by web_fetch ({final_url}).")
235
283
  if len(text.strip()) < MIN_CHARS: