@allansantos-dev/smart-tool 0.9.15 → 0.9.17
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 +25 -0
- package/README.md +17 -3
- package/client_hooks.py +167 -15
- package/hooks/session_audit.py +39 -0
- package/install.py +5 -4
- package/package.json +1 -1
- package/setup_audit.py +29 -0
- package/setup_ui.py +1056 -727
- package/smart_tool_daemon.py +54 -5
- package/version.py +1 -1
package/smart_tool_daemon.py
CHANGED
|
@@ -327,7 +327,7 @@ SERVER_INSTRUCTIONS = (
|
|
|
327
327
|
TOOLS = [
|
|
328
328
|
{
|
|
329
329
|
"name": "project_manage",
|
|
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.",
|
|
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; mode=last returns the stored report instead of auditing again. Jobs via smart_search_result.",
|
|
331
331
|
"inputSchema": {
|
|
332
332
|
"type": "object", "properties": {
|
|
333
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"]},
|
|
@@ -349,6 +349,7 @@ TOOLS = [
|
|
|
349
349
|
"left_view":{"type":"string"},"right_view":{"type":"string"},"relations":{"type":"boolean"},
|
|
350
350
|
"update_mode": {"type": "string", "enum": ["on_search", "eager"]},
|
|
351
351
|
"view_id": {"type": "string"}, "file_path": {"type": "string"},
|
|
352
|
+
"mode": {"type": "string", "enum": ["run", "last"], "default": "run", "description": "setup_audit: run audits now; last reads the stored report (the service audits registered projects every 30 minutes) without running anything, and fails when none is stored"},
|
|
352
353
|
"probe": {"type": "boolean", "default": True, "description": "setup_audit: start/call each MCP server (initialize + tools/list); false reads configs only"},
|
|
353
354
|
"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)"},
|
|
354
355
|
"symbol": {"type": "string", "description": "graph: function, Class.method, class name or path::name to get its callers, calls, tests and importers"},
|
|
@@ -1299,8 +1300,25 @@ def _mark_notice_delivered(job_id):
|
|
|
1299
1300
|
session, _client = _session_client()
|
|
1300
1301
|
with _JOBS_LOCK:
|
|
1301
1302
|
job = _jobs.get(job_id) or {}
|
|
1302
|
-
|
|
1303
|
-
|
|
1303
|
+
keys = (job.get("arguments") or {}).get("setup_notice_keys")
|
|
1304
|
+
if session and job.get("status") == "done" and keys:
|
|
1305
|
+
session.setdefault("notices_delivered", set()).update(keys)
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
def _pending_notices(session, client, project_root):
|
|
1309
|
+
"""[(key, text)] the session has not been told yet: the hook state (once) and the stored setup audit of the
|
|
1310
|
+
searched folder (once per folder, only with errors or warnings, and not when the SessionStart audit hook already
|
|
1311
|
+
reports it at the start of the session)."""
|
|
1312
|
+
delivered = session.get("notices_delivered") or set()
|
|
1313
|
+
pending = []
|
|
1314
|
+
if session["hook_notice"] and "hook" not in delivered:
|
|
1315
|
+
pending.append(("hook", session["hook_notice"]))
|
|
1316
|
+
key = "audit:" + setup_audit.index_key(project_root)
|
|
1317
|
+
if key not in delivered and not client_hooks.audit_hook_installed(client):
|
|
1318
|
+
text = setup_audit.session_notice(project_root)
|
|
1319
|
+
if text:
|
|
1320
|
+
pending.append((key, text))
|
|
1321
|
+
return pending
|
|
1304
1322
|
|
|
1305
1323
|
|
|
1306
1324
|
def _smart_search_arguments(arguments):
|
|
@@ -1348,8 +1366,11 @@ def _smart_search_arguments(arguments):
|
|
|
1348
1366
|
state = client_hooks.status(client)
|
|
1349
1367
|
_metric("hook_status", installed=state["installed"], client_name=state["name"], error=state["error"])
|
|
1350
1368
|
session["hook_notice"] = client_hooks.notice(state) or ""
|
|
1351
|
-
if session is not None
|
|
1352
|
-
|
|
1369
|
+
if session is not None:
|
|
1370
|
+
notices = _pending_notices(session, client, project_root)
|
|
1371
|
+
if notices:
|
|
1372
|
+
arguments["setup_notice"] = " ".join(text for _key, text in notices)
|
|
1373
|
+
arguments["setup_notice_keys"] = [key for key, _text in notices]
|
|
1353
1374
|
_metric("search", group=group, top_k=limits, query_comments=bool(comments), single_language_reason=reason)
|
|
1354
1375
|
return arguments
|
|
1355
1376
|
|
|
@@ -1493,6 +1514,16 @@ def _project_action(arguments):
|
|
|
1493
1514
|
root = arguments.get("project_root")
|
|
1494
1515
|
if not isinstance(root, str) or not os.path.isdir(root):
|
|
1495
1516
|
raise ValueError("setup_audit needs project_root: the folder whose Claude Code and Codex setup to audit.")
|
|
1517
|
+
mode = arguments.get("mode", "run")
|
|
1518
|
+
if mode not in ("run", "last"):
|
|
1519
|
+
raise ValueError("setup_audit mode must be run (audit now) or last (read the stored report).")
|
|
1520
|
+
if mode == "last":
|
|
1521
|
+
report = setup_audit.stored_for(root)
|
|
1522
|
+
if report is None:
|
|
1523
|
+
raise ValueError(f"No stored setup audit covers {root}: call setup_audit with mode=run once "
|
|
1524
|
+
"(the service also audits registered projects every 30 minutes).")
|
|
1525
|
+
return {"summary": report["summary"], "snapshot_key": report["snapshot_key"],
|
|
1526
|
+
"checked_at": report["checked_at"], "stored": True, "report": setup_audit.markdown(report)}
|
|
1496
1527
|
report = setup_audit.run(root, probe=arguments.get("probe", True) is not False)
|
|
1497
1528
|
return {"summary": report["summary"], "snapshot_key": report["snapshot_key"],
|
|
1498
1529
|
"report": setup_audit.markdown(report)}
|
|
@@ -3355,6 +3386,21 @@ def _pretool_hook(handler):
|
|
|
3355
3386
|
return output
|
|
3356
3387
|
|
|
3357
3388
|
|
|
3389
|
+
def _session_audit_hook(handler):
|
|
3390
|
+
"""SessionStart output for the audit report hook: the stored audit notice of the session's folder as
|
|
3391
|
+
additionalContext, or `{}` when nothing is stored or it holds no error or warning. Never runs an audit."""
|
|
3392
|
+
try:
|
|
3393
|
+
payload = json.loads(handler._read_body(HOOK_MAX_BODY_BYTES) or b"{}")
|
|
3394
|
+
cwd = payload.get("cwd")
|
|
3395
|
+
text = setup_audit.session_notice(cwd) if isinstance(cwd, str) and os.path.isdir(cwd) else ""
|
|
3396
|
+
except Exception as exc:
|
|
3397
|
+
_log(f"SessionStart audit hook without a report: {type(exc).__name__}: {exc}")
|
|
3398
|
+
return {}
|
|
3399
|
+
if not text:
|
|
3400
|
+
return {}
|
|
3401
|
+
return {"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": text}}
|
|
3402
|
+
|
|
3403
|
+
|
|
3358
3404
|
_TOOL_HANDLERS = {
|
|
3359
3405
|
"web_fetch": _handle_web_fetch,
|
|
3360
3406
|
"project_manage": _handle_project_manage,
|
|
@@ -3663,6 +3709,9 @@ class MCPHandler(BaseHTTPRequestHandler):
|
|
|
3663
3709
|
if urllib.parse.urlsplit(self.path).path == "/hooks/pretool":
|
|
3664
3710
|
self._write_json(200, _pretool_hook(self))
|
|
3665
3711
|
return
|
|
3712
|
+
if urllib.parse.urlsplit(self.path).path == "/hooks/session-audit":
|
|
3713
|
+
self._write_json(200, _session_audit_hook(self))
|
|
3714
|
+
return
|
|
3666
3715
|
save = _SETUP_SAVES.get(self.path)
|
|
3667
3716
|
if save:
|
|
3668
3717
|
self._post_setup(save)
|
package/version.py
CHANGED