@allansantos-dev/smart-tool 0.9.81 → 0.9.83
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 +115 -0
- package/NOTICE +1 -1
- package/README.md +73 -14
- package/affected_tests.py +9 -8
- package/agent_redirect.py +32 -0
- package/autostart.py +32 -25
- package/browser_bridge.py +320 -0
- package/browser_control.py +76 -39
- package/browser_service_client.py +1 -7
- package/client_hooks.py +41 -42
- package/code_graph.py +66 -21
- package/code_graph_java.mjs +21 -12
- package/code_health.py +14 -9
- package/codex_config.py +3 -0
- package/commit_check.py +184 -0
- package/daemon_launcher.py +37 -5
- package/doc_candidates.py +63 -0
- package/doc_check.py +9 -3
- package/doc_extras.py +2 -3
- package/doc_insights.py +26 -2
- package/doc_prose.py +59 -11
- package/doc_registry.py +241 -0
- package/doc_scope.py +205 -39
- package/doc_turn.py +205 -0
- package/doc_validate.py +52 -9
- package/document_converter.py +4 -4
- package/document_read.py +19 -11
- package/document_url.py +107 -0
- package/edit_shape.py +119 -0
- package/endpoint_sync.py +3 -21
- package/engine_home.py +95 -0
- package/hook_call.py +133 -0
- package/hook_decision.py +142 -7
- package/hooks/pre_commit.py +45 -0
- package/hooks/pretool_router.py +36 -30
- package/hooks/turn_end.py +40 -0
- package/index_views.py +5 -0
- package/install.py +24 -9
- package/lazy_mcp_proxy.py +10 -9
- package/local_embedder.py +8 -1
- package/locales/pt-BR.json +1 -2
- package/model_breaker.py +6 -5
- package/package.json +2 -2
- package/process_limits.py +17 -3
- package/project_identity.py +19 -1
- package/project_scan.py +98 -0
- package/release_notes.py +125 -0
- package/rename_preview.py +95 -0
- package/requester.py +1 -1
- package/scout_access.py +48 -0
- package/shell_reads.py +67 -0
- package/smart_tool_daemon.py +245 -50
- package/tray.py +31 -0
- package/venv_launch.py +67 -0
- package/version.py +1 -1
- package/web_adapters/node/engine-home.mjs +42 -0
- package/web_adapters/node/package-lock.json +13 -0
- package/web_adapters/node/package.json +1 -0
- package/web_fetch_many.py +61 -0
package/scout_access.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Whether `smart_scout` can be called in a Claude Code session without stopping for a permission decision.
|
|
2
|
+
|
|
3
|
+
The hook payload carries the permission mode but not the session's allow rules, so the rules are read from the same
|
|
4
|
+
settings files Claude Code merges: user, project and project-local. Where the answer cannot be shown to be yes, it is no:
|
|
5
|
+
a hook that sends an agent to a tool it may not call leaves the work waiting on a prompt nobody answers."""
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
import endpoint_sync
|
|
10
|
+
|
|
11
|
+
TOOL = "mcp__smart-tool__smart_scout"
|
|
12
|
+
SERVER_RULES = frozenset({TOOL, "mcp__smart-tool__*", "mcp__smart-tool"})
|
|
13
|
+
OPEN_MODES = frozenset({"bypassPermissions"})
|
|
14
|
+
SETTINGS_FILES = ("settings.json", "settings.local.json")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _settings(cwd):
|
|
18
|
+
"""The parsed permission blocks of the settings files that exist; an unreadable or malformed file is skipped as
|
|
19
|
+
Claude Code skips it, and counts as no allow rule."""
|
|
20
|
+
folders = [endpoint_sync.claude_dir(), os.path.join(cwd or "", ".claude")] if cwd else [endpoint_sync.claude_dir()]
|
|
21
|
+
found = []
|
|
22
|
+
for folder in folders:
|
|
23
|
+
for name in SETTINGS_FILES:
|
|
24
|
+
try:
|
|
25
|
+
with open(os.path.join(folder, name), encoding="utf-8") as stream:
|
|
26
|
+
data = json.load(stream)
|
|
27
|
+
except (OSError, ValueError):
|
|
28
|
+
continue
|
|
29
|
+
if isinstance(data, dict) and isinstance(data.get("permissions"), dict):
|
|
30
|
+
found.append(data["permissions"])
|
|
31
|
+
return found
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def callable_in(payload):
|
|
35
|
+
"""True when the session runs in a mode that allows every tool or an allow rule names `smart_scout` (the tool, its
|
|
36
|
+
server or the server wildcard) and no deny rule does."""
|
|
37
|
+
if not isinstance(payload, dict):
|
|
38
|
+
return False
|
|
39
|
+
permissions = _settings(payload.get("cwd"))
|
|
40
|
+
|
|
41
|
+
def rules(key):
|
|
42
|
+
return {rule for block in permissions for rule in (block.get(key) or []) if isinstance(rule, str)}
|
|
43
|
+
|
|
44
|
+
if rules("deny") & SERVER_RULES:
|
|
45
|
+
return False
|
|
46
|
+
if payload.get("permission_mode") in OPEN_MODES or any(block.get("defaultMode") in OPEN_MODES for block in permissions):
|
|
47
|
+
return True
|
|
48
|
+
return bool(rules("allow") & SERVER_RULES)
|
package/shell_reads.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Source files read through the shell (`cat`, `head`, `sed -n`), counted per session so a run of them can be answered
|
|
2
|
+
with a tip.
|
|
3
|
+
|
|
4
|
+
One read of a known file is what the shell is for, and `smart_search` cannot return its exact lines, so no single read
|
|
5
|
+
is touched. A burst of them is an investigation done by reading, which `smart_scout` answers with only the lines that
|
|
6
|
+
matter: the third read inside the window carries the tip, then the tip waits before it repeats."""
|
|
7
|
+
import collections
|
|
8
|
+
import os
|
|
9
|
+
import threading
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
import redirect_rule
|
|
13
|
+
|
|
14
|
+
READERS = frozenset({"cat", "head", "sed"})
|
|
15
|
+
SOURCE_SUFFIXES = frozenset({
|
|
16
|
+
".py", ".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".java", ".kt", ".go", ".rs", ".c", ".cc", ".cpp", ".h", ".hpp",
|
|
17
|
+
".cs", ".rb", ".php", ".swift", ".scala", ".vue", ".svelte", ".sh", ".ps1", ".sql", ".lua", ".dart"})
|
|
18
|
+
BURST_READS = 3
|
|
19
|
+
WINDOW_S = 600
|
|
20
|
+
TIP_EVERY_S = 600
|
|
21
|
+
MAX_SESSIONS = 256
|
|
22
|
+
TIP = ("You have read {count} source files through the shell in the last minutes. For a question that spans several "
|
|
23
|
+
"files call mcp__smart-tool__smart_scout(project_root, question) (it returns only the lines that answer); keep "
|
|
24
|
+
"cat, head and sed -n for a file you already know and need verbatim.")
|
|
25
|
+
|
|
26
|
+
_LOCK = threading.Lock()
|
|
27
|
+
_READS = collections.OrderedDict()
|
|
28
|
+
_TIPPED = {}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def source_files(command, cwd):
|
|
32
|
+
"""The existing source files, inside the session's reach, that the reading commands of a shell command print: `cat`,
|
|
33
|
+
`head` and `sed -n` at the start of a command, not a filter after a pipe."""
|
|
34
|
+
found = []
|
|
35
|
+
for segment, after_pipe in redirect_rule.segments(command or ""):
|
|
36
|
+
if after_pipe:
|
|
37
|
+
continue
|
|
38
|
+
tokens = redirect_rule._unwrap(redirect_rule._split(segment, False), {})
|
|
39
|
+
if not tokens or tokens[0].lower() not in READERS or (tokens[0].lower() == "sed" and "-n" not in tokens):
|
|
40
|
+
continue
|
|
41
|
+
for raw in redirect_rule._reader_files(tokens[0].lower(), tokens[1:]):
|
|
42
|
+
path = redirect_rule.resolve_path(os.path.expanduser(raw), cwd)
|
|
43
|
+
if path and os.path.splitext(path)[1].lower() in SOURCE_SUFFIXES and os.path.isfile(path) \
|
|
44
|
+
and redirect_rule._in_project(path, cwd):
|
|
45
|
+
found.append(path)
|
|
46
|
+
return found
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def note(session_id, command, cwd, now=None):
|
|
50
|
+
"""Counts the source reads of one shell call for the session and returns the tip when this call is the third inside
|
|
51
|
+
the window and no tip went out in the last TIP_EVERY_S; None otherwise."""
|
|
52
|
+
files = source_files(command, cwd)
|
|
53
|
+
if not files or not session_id:
|
|
54
|
+
return None
|
|
55
|
+
now = time.time() if now is None else now
|
|
56
|
+
with _LOCK:
|
|
57
|
+
reads = _READS.setdefault(session_id, collections.deque())
|
|
58
|
+
_READS.move_to_end(session_id)
|
|
59
|
+
while len(_READS) > MAX_SESSIONS:
|
|
60
|
+
_TIPPED.pop(_READS.popitem(last=False)[0], None)
|
|
61
|
+
reads.extend([now] * len(files))
|
|
62
|
+
while reads and now - reads[0] > WINDOW_S:
|
|
63
|
+
reads.popleft()
|
|
64
|
+
if len(reads) < BURST_READS or now - _TIPPED.get(session_id, -TIP_EVERY_S) < TIP_EVERY_S:
|
|
65
|
+
return None
|
|
66
|
+
_TIPPED[session_id] = now
|
|
67
|
+
return TIP.format(count=len(reads))
|