@allansantos-dev/smart-tool 0.9.13 → 0.9.15

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,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.15 - beta
4
+
5
+ - The hook redirects the folder searches that slipped past it in a shell: wrapped (`bash -c`, `sh -lc`,
6
+ `powershell -Command`, `cmd /c`, `timeout 60`, `env X=1`, `time`, `nice`, a `( ... )` subshell), looped
7
+ (`for f in src/*.py; do grep x "$f"`), fed by a listing (`find -exec grep|cat`, `find | xargs -0 grep`,
8
+ `grep x $(find src -name '*.py')`, `find | while read f`, `Get-ChildItem -Recurse | Select-String` or
9
+ `| % { Get-Content $_ }`), `git --no-pager grep`, `cat` over more than 20 files, and inline python/node scripts
10
+ (`-c`, `-e`, heredoc) that walk a project folder, read the files and match their text. A listing capped by `head`,
11
+ `find -name` of one exact file and scripts that write files still run. Replayed over 3 days of real transcripts
12
+ (14,580 Grep and shell calls), 37 more calls are redirected, all folder searches; none of the previous redirects
13
+ changed.
14
+ - Claude Code's PowerShell tool goes through the same rule as Bash; it was not in the hook matcher. Reinstall the
15
+ hook from the setup screen (it shows as outdated): the matcher now has `PowerShell` and `smart_search`.
16
+ - Setup screen, Agents: the redirects of the last 7 days by tool and reason, and what the same session did next
17
+ (called `smart_search`, ran an allowed native call, was blocked again, or nothing within 15 minutes). The hook log
18
+ now records the session, and `smart_search` calls pass through the hook only to be counted. Next to it, the
19
+ measured context per call: a native call of the kinds redirected ~510 tokens, a `smart_search` round trip ~2,160
20
+ tokens; a redirect saves context only when one search replaces several native ones, which is not measured yet.
21
+
22
+ ## 0.9.14 - beta
23
+
24
+ - The setup audit runs on its own: the daemon audits every registered project two minutes after it starts and then
25
+ every 30 minutes, one at a time. MCP servers several projects share are contacted once and a successful result is
26
+ reused for 6 hours (a failure never is, so a server fixed meanwhile shows at once; Run now always contacts them
27
+ again). A project's `.mcp.json` servers are only counted and started when Claude Code approved them
28
+ (`enableAllProjectMcpServers`, `enabledMcpjsonServers`, `disabledMcpjsonServers`): registering a cloned repository
29
+ for search never runs the commands it declares. The summary per project is in
30
+ `~/.smart-tool/data/setup-audit/index.json`; projects no longer registered are dropped from it.
31
+ - **Setup audit** panel on the setup screen: pick a registered project (the one with the most errors opens first) and
32
+ see its last report, scheduled or on request: findings by severity with their documentation link, what is new,
33
+ what was resolved, the tokens each MCP server's tools cost and what was not verified; Run now audits it again.
34
+ Everything taken from config files is shown as text.
35
+
3
36
  ## 0.9.13 - beta
4
37
 
5
38
  - 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.15 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
19
19
 
20
20
  ## How it works
21
21
 
@@ -116,8 +116,12 @@ Open the setup screen from the tray icon ("Open settings") or at `http://127.0.0
116
116
  The hook behaviors:
117
117
  - **Redirect** (default): the native tool is denied with the reason and the Smart Tool tool to use. The decision
118
118
  is a fixed rule, under a millisecond and the same every time: a content search over a project folder (`grep -r`,
119
- `rg`, `git grep`, the Grep tool on a folder) or over more than 20 listed files goes to `smart_search`; reading or
120
- searching known files, listings, Glob and commands that change files run. With **Block patterns proposed by a
119
+ `rg`, `git grep`, the Grep tool on a folder) or over more than 20 listed files goes to `smart_search`, in Bash and
120
+ PowerShell alike and also when it is wrapped (`bash -c`, `powershell -Command`, `timeout`, a subshell), looped
121
+ (`for f in src/*.py`), fed by a listing (`find -exec grep`, `xargs`, `Get-ChildItem | Select-String`) or written
122
+ as an inline python/node script that walks a folder and matches text; reading or searching known files,
123
+ listings, Glob and commands that change files run. The setup screen counts the redirects and what each session
124
+ did next. With **Block patterns proposed by a
121
125
  model** on (default), the scope model reviews, in the background, bulk reads the rule could not measure and
122
126
  proposes regex patterns, each checked against the logged calls; a pattern blocks only after you accept it.
123
127
  - **Advise only**: the native tool runs; the agent receives the same advice next to the result and decides.
@@ -160,7 +164,11 @@ Open the setup screen from the tray icon ("Open settings") or at `http://127.0.0
160
164
  directly), skills sharing a name or over the description budget, an AGENTS.md only Codex reads, broken `@imports`
161
165
  and a Codex instruction chain over 32 KiB. Each finding links the documentation it relies on; nothing is edited,
162
166
  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.
167
+ run shows what is new and what was resolved. The daemon also runs it on its own for every registered project,
168
+ two minutes after it starts and then every 30 minutes (MCP servers shared by several projects are contacted once
169
+ and their result reused for 6 hours; Run now always contacts them again), and the setup screen's **Setup audit**
170
+ panel shows each project's last report: findings by severity, what is new, what was resolved, the tokens each MCP
171
+ server's tools cost and what was not verified.
164
172
  4. **Local models** (optional): if the mcp-memory embedding sidecar is installed on the machine, its local embedder
165
173
  can serve as a fallback (or preferred) embedding model.
166
174
  5. **Web search providers** work without keys on their free public tiers; add your own key for more volume. Set your
package/client_hooks.py CHANGED
@@ -16,7 +16,7 @@ HOME = os.path.expanduser("~")
16
16
  PREVIEW_TTL_S = 600
17
17
  CLIENTS = {
18
18
  "claude": {"label": "Claude Code", "names": {"claude-code"}, "files": [os.path.join(endpoint_sync.claude_dir(), "settings.json")],
19
- "docs": "https://code.claude.com/docs/en/hooks", "event": "PreToolUse", "matcher": "Grep|Glob|Read|Bash|WebSearch|WebFetch|Edit|MultiEdit|Write", "http": True},
19
+ "docs": "https://code.claude.com/docs/en/hooks", "event": "PreToolUse", "matcher": "Grep|Glob|Read|Bash|PowerShell|WebSearch|WebFetch|Edit|MultiEdit|Write|mcp__smart-tool__smart_search", "http": True},
20
20
  "codex": {"label": "Codex", "prefix": "codex", "files": [os.path.join(HOME, ".codex", "hooks.json"), os.path.join(HOME, ".codex", "config.toml")],
21
21
  "docs": "https://learn.chatgpt.com/docs/hooks", "event": "PreToolUse", "matcher": "Bash|apply_patch",
22
22
  "after_install": "Codex only runs new hooks after the user approves the definition in /hooks."},
package/hook_decision.py CHANGED
@@ -27,6 +27,7 @@ EDIT_TOOLS = ("Edit", "MultiEdit", "Write", "apply_patch")
27
27
  MAX_DOC_FINDINGS = 5
28
28
  MAX_DUPLICATE_FINDINGS = 3
29
29
  SMART_TOOL_SERVER = "smart-tool"
30
+ SMART_SEARCH_TOOL = f"mcp__{SMART_TOOL_SERVER}__smart_search"
30
31
  REASON_MAX_CHARS = 200
31
32
 
32
33
 
@@ -260,6 +261,12 @@ def decide(payload, client, web_route):
260
261
  if doc_mode == "off" and duplicate_mode == "off":
261
262
  return {}
262
263
  return _edit_review(payload, doc_mode, duplicate_mode)
264
+ if isinstance(payload, dict) and str(payload.get("tool_name")).startswith(f"mcp__{SMART_TOOL_SERVER}__"):
265
+ if payload["tool_name"] == SMART_SEARCH_TOOL:
266
+ router.CLIENT.set(client)
267
+ router.SESSION.set(payload.get("session_id"))
268
+ router._log_decision(SMART_SEARCH_TOOL, {}, "allow", "Smart Tool search, logged to measure followed redirects")
269
+ return {}
263
270
  mode = config.hook_mode(cfg)
264
271
  if mode == "off" or not isinstance(payload, dict):
265
272
  return {}
@@ -288,6 +295,7 @@ def _route(payload, client, web_route, cfg):
288
295
  decision = web_route(tool_name, url)
289
296
  return deny(web_message(client, tool_name, url, clean_reason(decision.get("reason")))) if decision.get("redirect") else {}
290
297
  router.CLIENT.set(client)
298
+ router.SESSION.set(payload.get("session_id"))
291
299
  try:
292
300
  decision, reason, target = router.decide(tool_name, tool_input, cwd=cwd)
293
301
  except Exception as exc:
@@ -2,6 +2,7 @@ import collections
2
2
  import json
3
3
  import os
4
4
  import paths
5
+ import re
5
6
  import threading
6
7
  import time
7
8
 
@@ -11,6 +12,12 @@ import router
11
12
  PATH = os.path.join(paths.DATA_DIR, "integration-metrics.jsonl")
12
13
  MAX_BYTES = 20 * 1024 * 1024
13
14
  _LOCK = threading.Lock()
15
+ FOLLOW_WINDOW_S = 900
16
+ # Measured on 2026-10-12 with docs/spikes/bash_bypass_replay.py over 3 days of Claude Code transcripts (14,580 Grep and
17
+ # shell calls), at ~4 characters per token: the 310 calls the rule redirects put 2,031 characters on average in the
18
+ # context when they ran; a smart_search round trip (pending reply 716 + result 7,924) puts 8,640.
19
+ NATIVE_REDIRECTED_TOKENS = 510
20
+ SMART_SEARCH_TOKENS = 2160
14
21
 
15
22
 
16
23
  def record(event, **fields):
@@ -78,5 +85,48 @@ def summary(days=7):
78
85
  return {"days": days, "events_by_client": {k: dict(v) for k, v in by_client.items()},
79
86
  "rejects_by_kind": dict(rejects), "single_language_reasons": dict(reasons.most_common(20)),
80
87
  "hook_decisions_by_client": {k: dict(v) for k, v in decisions.items()},
88
+ "redirects": redirects(days),
81
89
  "web_search_cache": web_cache,
82
90
  "files": {"integration": PATH, "router": router.METRICS_PATH}}
91
+
92
+
93
+ def _next_in_session(rows, index):
94
+ """The session's next logged call within FOLLOW_WINDOW_S of rows[index], or None."""
95
+ start = rows[index]["ts"]
96
+ return next((row for row in rows[index + 1:] if row["ts"] - start <= FOLLOW_WINDOW_S), None)
97
+
98
+
99
+ def redirects(days=7):
100
+ """Redirects of native searches in the last days and what the same session did next: called smart_search
101
+ (followed), ran an allowed native call such as reading a file it found (native), was blocked again, or made no other
102
+ call within FOLLOW_WINDOW_S. Redirects logged without a session (before 0.9.15, or a client that sends none) count
103
+ as unknown. tokens_per_call holds the measured context of each side, so the panel never claims a saving it did
104
+ not measure."""
105
+ rows = sorted(_read(router.METRICS_PATH, time.time() - days * 86400), key=lambda row: row["ts"])
106
+ sessions = collections.defaultdict(list)
107
+ for row in rows:
108
+ if row.get("session"):
109
+ sessions[row["session"]].append(row)
110
+ by_tool, by_reason, outcomes = collections.Counter(), collections.Counter(), collections.Counter()
111
+ for row in rows:
112
+ if row.get("decision") != "redirect":
113
+ continue
114
+ by_tool[row.get("tool_name") or "?"] += 1
115
+ by_reason[re.sub(r"\d+", "N", str(row.get("reason") or "?"))[:80]] += 1
116
+ own = sessions.get(row.get("session"))
117
+ if not own:
118
+ outcomes["unknown"] += 1
119
+ continue
120
+ after = _next_in_session(own, own.index(row))
121
+ if after is None:
122
+ outcomes["no_other_call"] += 1
123
+ elif str(after.get("tool_name", "")).startswith("mcp__smart-tool__"):
124
+ outcomes["followed"] += 1
125
+ elif after.get("decision") == "redirect":
126
+ outcomes["blocked_again"] += 1
127
+ else:
128
+ outcomes["native"] += 1
129
+ return {"days": days, "total": sum(by_tool.values()), "by_tool": dict(by_tool),
130
+ "by_reason": dict(by_reason.most_common(8)), "outcomes": dict(outcomes),
131
+ "tokens_per_call": {"native_redirected": NATIVE_REDIRECTED_TOKENS, "smart_search": SMART_SEARCH_TOKENS,
132
+ "measured": "2026-10-12, 3 days of Claude Code transcripts"}}
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.15",
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",