@allansantos-dev/smart-tool 0.9.82 → 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 +51 -0
- package/README.md +35 -4
- package/affected_tests.py +9 -8
- package/client_hooks.py +1 -1
- package/code_graph.py +10 -6
- package/commit_check.py +184 -0
- package/document_converter.py +4 -4
- package/document_read.py +15 -9
- package/document_url.py +107 -0
- package/hook_call.py +3 -2
- package/hook_decision.py +42 -1
- package/hooks/pre_commit.py +45 -0
- package/package.json +1 -1
- package/release_notes.py +125 -0
- package/rename_preview.py +95 -0
- package/requester.py +1 -1
- package/smart_tool_daemon.py +105 -15
- package/version.py +1 -1
- package/web_fetch_many.py +61 -0
package/smart_tool_daemon.py
CHANGED
|
@@ -57,6 +57,7 @@ import index_inventory
|
|
|
57
57
|
import usage_meter
|
|
58
58
|
import document_read
|
|
59
59
|
import document_text
|
|
60
|
+
import document_url
|
|
60
61
|
import dependency_notice
|
|
61
62
|
import dossier
|
|
62
63
|
import scout
|
|
@@ -84,6 +85,7 @@ import local_embedder
|
|
|
84
85
|
import low_priority
|
|
85
86
|
import web_search_health
|
|
86
87
|
import web_fetch
|
|
88
|
+
import web_fetch_many
|
|
87
89
|
import version
|
|
88
90
|
import update_check
|
|
89
91
|
import gateway
|
|
@@ -388,10 +390,10 @@ SERVER_INSTRUCTIONS = (
|
|
|
388
390
|
TOOLS = [
|
|
389
391
|
{
|
|
390
392
|
"name": "project_manage",
|
|
391
|
-
"description": "Manages folders and indexing. Every action takes project_root (the folder) or project_id. list gives a short line per project (a project whose folder is gone shows as unavailable with the reason); status shows storage, scope and jobs, and with a path inside a registered project answers for the deepest one that holds it (resolved_from). deps lists the known OSV advisories of every dependency the manifests of the project declare (package.json, requirements*.txt, pyproject.toml, go.mod), not only the ones an edit changed, at the version a package-lock.json beside a package.json resolved when it satisfies the range; only package names and versions leave the machine. 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. pr_impact (base, default HEAD; main or origin/main for a branch) returns a Markdown report of the change for a pull request: the functions the diff touches with their callers and the tests that reach them (those no test reaches are listed apart), the documentation entries it leaves out of date, the notes the edit hook would have added to the whole diff (comments, copies, dependency advisories) and the tests to run with their command; it publishes nothing. pr_impact_comment (pr, base required) posts that report as a comment on pull request pr through the gh CLI, from the project folder, and returns the comment URL; a rerun replaces the previous Smart Tool comment (marked by a hidden HTML marker) instead of stacking another, and the body carries no local path; it is a write to GitHub, so it refuses unless the user turned pr_comment on in the setup screen (Agent rules, off by default), and when gh is missing or not logged in; never call it without the user asking for the comment. hotspots (limit) ranks the code files by commits times lines, the riskiest to change; dead_code lists the functions no code calls and those only tests call (static call graph, candidates); import_cycles lists the groups of files that import each other; comments lists comments in the wrong place (commented-out code, history tags, loose docs, long inline blocks) across the code files, not only in an edit; credentials lists, per git-tracked text file (read from disk, so .env files and old commits count), the file and line of each credential shape (provider tokens, AWS keys, private-key headers), never the value, and skips lines that say they are an example; links lists the relative links of the tracked HTML and Markdown files that point to a missing file, plus the links it could not decide (root-relative, template expressions, pages with a base element), reported as unchecked, not broken. graph without symbol reads the indexed view: coverage, references and static calls in Java, Angular, Python, Go 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, Go doc comment starting with the name; private, nested and override functions excluded) with coverage percent, excluding tests unless include_tests=true, for documenting a project that started without it; docs generate=true writes the documentation scope to docs/scope in the project in three levels tied to the code: technical pages by folder (an entry per public function anchored on path::name with signature, first doc line, layer, callers, calls and tests, plus a Mermaid flow by layer), functional.md (each entry point and the functions its flow reaches, by layer) and simple.md; the prose between the prose markers is kept by regeneration; docs write_prose=true writes the empty prose blocks with the Docs model of the setup (each paragraph checked against the code first) within about 40 s and says how many are left, call it again until none is; docs check=true reports anchors whose function changed signature or is gone and broken links; docs validate=true checks every claim of docs/scope against the code (anchors, links, line numbers, callers and tests, coverage, entry points, command-line options, prose names, counts, glossary, navigation, versions) and writes docs/scope/validation.md with pass/fail per check, the evidence, a score and the verdict (generate runs it too); docs with symbol lists where that function is documented; layers declares the project's layers (ordered highest first, each with path globs and annotations): without layers it returns the saved rule or a suggestion read from folder names and annotations, with files, symbols and calls between layers (direction down or up); pass layers to preview a rule and the same layers with confirm=true to save it in the project (.smart-tool/layers.json); 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; each view carries stale (not updated for 30 days, the test of the daily cleanup that removes them) and stale_bytes sums them; 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; each finding carries its fix (the file to edit or the command to run), applied by the agent when the user agrees, never by Smart Tool; mode=last returns the stored report instead of auditing again. redirect_proposals (no project_root) lists the redirect patterns proposed from allowed searches, most matched first, with a guide; redirect_decide decides them by ids: accept, instruct (tip without blocking), reject, or remove an accepted one. junk (no project_root) lists the registered projects that were never projects: a personal, system, application-data or build folder, a subfolder of a repository or of another project, a folder of projects, or a folder that no longer exists (on a drive or share that is mounted); with confirm=true it unregisters them and deletes only their index files, and the manifest says what went. A project is the folder where the session started, so smart_search and register refuse a folder that is not a project and index a new one only from the session that started in it. Jobs via smart_search_result.",
|
|
393
|
+
"description": "Manages folders and indexing. Every action takes project_root (the folder) or project_id. list gives a short line per project (a project whose folder is gone shows as unavailable with the reason); status shows storage, scope and jobs, and with a path inside a registered project answers for the deepest one that holds it (resolved_from). deps lists the known OSV advisories of every dependency the manifests of the project declare (package.json, requirements*.txt, pyproject.toml, go.mod), not only the ones an edit changed, at the version a package-lock.json beside a package.json resolved when it satisfies the range; only package names and versions leave the machine. 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. pr_impact (base, default HEAD; main or origin/main for a branch) returns a Markdown report of the change for a pull request: the functions the diff touches with their callers and the tests that reach them (those no test reaches are listed apart), the documentation entries it leaves out of date, the notes the edit hook would have added to the whole diff (comments, copies, dependency advisories) and the tests to run with their command; it publishes nothing. pr_impact_comment (pr, base required) posts that report as a comment on pull request pr through the gh CLI, from the project folder, and returns the comment URL; a rerun replaces the previous Smart Tool comment (marked by a hidden HTML marker) instead of stacking another, and the body carries no local path; it is a write to GitHub, so it refuses unless the user turned pr_comment on in the setup screen (Agent rules, off by default), and when gh is missing or not logged in; never call it without the user asking for the comment. hotspots (limit) ranks the code files by commits times lines, the riskiest to change; dead_code lists the functions no code calls and those only tests call (static call graph, candidates); import_cycles lists the groups of files that import each other; comments lists comments in the wrong place (commented-out code, history tags, loose docs, long inline blocks) across the code files, not only in an edit; credentials lists, per git-tracked text file (read from disk, so .env files and old commits count), the file and line of each credential shape (provider tokens, AWS keys, private-key headers), never the value, and skips lines that say they are an example; links lists the relative links of the tracked HTML and Markdown files that point to a missing file, plus the links it could not decide (root-relative, template expressions, pages with a base element), reported as unchecked, not broken. rename_preview lists, before a rename of the function in symbol, its definitions with file and lines, its callers with line (also the calls the graph left unresolved under that name), the tests that reach it, the files importing its module, the anchors of docs/scope and the lines of the README and docs text that name it, each list capped by limit with the totals in counts; it fails when the symbol is not found and writes nothing. release_notes drafts the notes of the next release in Markdown under a `## Draft since <base>` heading without a model: the commit subjects since base (default the latest tag), the public functions the diff touches with their caller and test counts, the decision notes that name them and the documentation entries the diff leaves out of date; it writes nothing and fails when there is no tag and no base. commit_check reviews the staged change (git diff --cached, not the working tree) with the notes the edit hook gives a finished diff (credentials, commented-out code, missing docstrings, duplicates, dependency advisories, link and edit notes), for edits the agent hook never saw (an IDE, hand edits, another agent); it writes nothing. commit_hook_install writes a git pre-commit hook in the project that prints that review to stderr at every commit and never blocks it (exit 0 always; a daemon that is down is one line, a check that fails is printed); it is opt-in, and refuses, naming what it found and changing nothing, when core.hooksPath is set, husky is used or a pre-commit that is not Smart Tool's exists; commit_hook_uninstall removes only that hook and puts back a backed-up hook that is not ours. graph without symbol reads the indexed view: coverage, references and static calls in Java, Angular, Python, Go 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, Go doc comment starting with the name; private, nested and override functions excluded) with coverage percent, excluding tests unless include_tests=true, for documenting a project that started without it; docs generate=true writes the documentation scope to docs/scope in the project in three levels tied to the code: technical pages by folder (an entry per public function anchored on path::name with signature, first doc line, layer, callers, calls and tests, plus a Mermaid flow by layer), functional.md (each entry point and the functions its flow reaches, by layer) and simple.md; the prose between the prose markers is kept by regeneration; docs write_prose=true writes the empty prose blocks with the Docs model of the setup (each paragraph checked against the code first) within about 40 s and says how many are left, call it again until none is; docs check=true reports anchors whose function changed signature or is gone and broken links; docs validate=true checks every claim of docs/scope against the code (anchors, links, line numbers, callers and tests, coverage, entry points, command-line options, prose names, counts, glossary, navigation, versions) and writes docs/scope/validation.md with pass/fail per check, the evidence, a score and the verdict (generate runs it too); docs with symbol lists where that function is documented; layers declares the project's layers (ordered highest first, each with path globs and annotations): without layers it returns the saved rule or a suggestion read from folder names and annotations, with files, symbols and calls between layers (direction down or up); pass layers to preview a rule and the same layers with confirm=true to save it in the project (.smart-tool/layers.json); 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; each view carries stale (not updated for 30 days, the test of the daily cleanup that removes them) and stale_bytes sums them; 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; each finding carries its fix (the file to edit or the command to run), applied by the agent when the user agrees, never by Smart Tool; mode=last returns the stored report instead of auditing again. redirect_proposals (no project_root) lists the redirect patterns proposed from allowed searches, most matched first, with a guide; redirect_decide decides them by ids: accept, instruct (tip without blocking), reject, or remove an accepted one. junk (no project_root) lists the registered projects that were never projects: a personal, system, application-data or build folder, a subfolder of a repository or of another project, a folder of projects, or a folder that no longer exists (on a drive or share that is mounted); with confirm=true it unregisters them and deletes only their index files, and the manifest says what went. A project is the folder where the session started, so smart_search and register refuse a folder that is not a project and index a new one only from the session that started in it. Jobs via smart_search_result.",
|
|
392
394
|
"inputSchema": {
|
|
393
395
|
"type": "object", "properties": {
|
|
394
|
-
"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", "layers", "affected_tests", "pr_impact", "pr_impact_comment", "hotspots", "dead_code", "import_cycles", "comments", "credentials", "links", "setup_audit", "redirect_proposals", "redirect_decide", "junk", "deps"]},
|
|
396
|
+
"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", "layers", "affected_tests", "pr_impact", "pr_impact_comment", "hotspots", "dead_code", "import_cycles", "comments", "credentials", "links", "rename_preview", "release_notes", "commit_check", "commit_hook_install", "commit_hook_uninstall", "setup_audit", "redirect_proposals", "redirect_decide", "junk", "deps"]},
|
|
395
397
|
"ids": {"type": "array", "items": {"type": "string"}, "description": "redirect_decide: proposal ids from redirect_proposals (accepted ids for remove)"},
|
|
396
398
|
"decision": {"type": "string", "enum": ["accept", "instruct", "reject", "remove"], "description": "redirect_decide: accept redirects matching calls to smart_search; instruct lets them run with a tip naming smart_search; reject discards; remove deletes an accepted pattern"},
|
|
397
399
|
"finding_id": {"type": "string"},
|
|
@@ -423,9 +425,9 @@ TOOLS = [
|
|
|
423
425
|
"view_id": {"type": "string"}, "file_path": {"type": "string"},
|
|
424
426
|
"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"},
|
|
425
427
|
"probe": {"type": "boolean", "default": True, "description": "setup_audit: start/call each MCP server (initialize + tools/list); false reads configs only"},
|
|
426
|
-
"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)"},
|
|
428
|
+
"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); release_notes: tag, branch or commit the draft starts from (default: the latest tag, and it fails when there is none)"},
|
|
427
429
|
"pr": {"type": "integer", "minimum": 1, "description": "pr_impact_comment: number of the pull request to comment on"},
|
|
428
|
-
"symbol": {"type": "string", "description": "graph: function, Class.method, class name or path::name to get its callers, calls, tests and importers; docs: where that function is documented"},
|
|
430
|
+
"symbol": {"type": "string", "description": "graph: function, Class.method, class name or path::name to get its callers, calls, tests and importers; docs: where that function is documented; rename_preview: the function to rename"},
|
|
429
431
|
"depth": {"type": "integer", "minimum": 1, "maximum": 4, "default": 3, "description": "graph with symbol: call hops searched for tests"},
|
|
430
432
|
"project_root": {"type": "string"}, "project_id": {"type": "string"},
|
|
431
433
|
"job_id": {"type": "string"}, "watch": {"type": "boolean"},
|
|
@@ -583,7 +585,8 @@ TOOLS = [
|
|
|
583
585
|
"description": (
|
|
584
586
|
"Reads a known URL and returns only the answer to the prompt, written by the gateway's mini model - use instead of "
|
|
585
587
|
"the native WebFetch. The page is cached for 24 h: another prompt on the same URL does not download it again. "
|
|
586
|
-
"JavaScript-built pages are rendered in the browser. Reads PDFs as text, page by page; does not read localhost or internal networks."
|
|
588
|
+
"JavaScript-built pages are rendered in the browser. Reads PDFs as text, page by page; does not read localhost or internal networks. "
|
|
589
|
+
"For several URLs with the same prompt, use web_fetch_many."
|
|
587
590
|
),
|
|
588
591
|
"inputSchema": {
|
|
589
592
|
"type": "object",
|
|
@@ -594,6 +597,26 @@ TOOLS = [
|
|
|
594
597
|
"required": ["url", "prompt"],
|
|
595
598
|
},
|
|
596
599
|
},
|
|
600
|
+
{
|
|
601
|
+
"name": "web_fetch_many",
|
|
602
|
+
"description": (
|
|
603
|
+
"Reads up to 8 known URLs in one call with the same prompt and returns one block per URL, in the order given: the "
|
|
604
|
+
"answer, or an ERROR line with the reason. Each URL is read exactly as web_fetch reads it (24 h cache, browser for "
|
|
605
|
+
"JavaScript-built pages, PDFs as text, no localhost or internal networks), 4 at a time, and a URL that fails never "
|
|
606
|
+
"hides the others; the call fails as a whole only when every URL failed. A URL repeated is read once. Use it "
|
|
607
|
+
"instead of several web_fetch calls when the same question applies to every page; use web_fetch for one URL or "
|
|
608
|
+
"a different prompt per page."
|
|
609
|
+
),
|
|
610
|
+
"inputSchema": {
|
|
611
|
+
"type": "object",
|
|
612
|
+
"properties": {
|
|
613
|
+
"urls": {"type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": web_fetch_many.MAX_URLS,
|
|
614
|
+
"description": "Full http(s) URLs of the pages"},
|
|
615
|
+
"prompt": {"type": "string", "description": "What to extract or answer from each page"},
|
|
616
|
+
},
|
|
617
|
+
"required": ["urls", "prompt"],
|
|
618
|
+
},
|
|
619
|
+
},
|
|
597
620
|
{
|
|
598
621
|
"name": "read_document",
|
|
599
622
|
"description": (
|
|
@@ -605,13 +628,16 @@ TOOLS = [
|
|
|
605
628
|
"as markdown (headings, lists, tables) in parts of about 6,000 characters because a docx has no fixed "
|
|
606
629
|
"pages; pptx per slide with the speaker notes; xlsx per sheet, one tab-separated line per row with the "
|
|
607
630
|
"cached formula values; html as markdown in parts like a docx; csv as one sheet, one tab-separated line per row; "
|
|
608
|
-
"epub per chapter in reading order. Use info_only first to size a large file and pick the pages you need.
|
|
631
|
+
"epub per chapter in reading order. Use info_only first to size a large file and pick the pages you need. The path "
|
|
632
|
+
"may also be an http(s) URL of a PDF, docx, pptx, xlsx, csv or epub file: it is downloaded the way web_fetch "
|
|
633
|
+
"downloads (public addresses only, 5 MB cap), kept for 24 h and read the same way, with the same ranges; a URL "
|
|
634
|
+
"of a web page fails, read it with web_fetch. A scanned "
|
|
609
635
|
"PDF (no text layer) fails with that reason; there is no OCR. Not for plain text or code: use Read."
|
|
610
636
|
),
|
|
611
637
|
"inputSchema": {
|
|
612
638
|
"type": "object",
|
|
613
639
|
"properties": {
|
|
614
|
-
"path": {"type": "string", "description": "Absolute path of the .pdf, .docx, .pptx, .xlsx, .html, .htm, .csv or .epub file"},
|
|
640
|
+
"path": {"type": "string", "description": "Absolute path of the .pdf, .docx, .pptx, .xlsx, .html, .htm, .csv or .epub file, or the http(s) URL of a PDF, docx, pptx, xlsx, csv or epub file"},
|
|
615
641
|
"range": {"type": "string", "description": "Pages, slides, parts, chapters or sheets to read: `3`, `3-5`, `7-` (to the end), `-4` (the first four) or a comma list like `1,4-6`; a sheet name also works for a workbook. Default: from the first one"},
|
|
616
642
|
"max_chars": {"type": "integer", "minimum": 1000, "maximum": document_read.MAX_CHARS_LIMIT, "default": document_read.DEFAULT_MAX_CHARS, "description": "Cap of the text returned (about four characters per token)"},
|
|
617
643
|
"info_only": {"type": "boolean", "default": False, "description": "Return only the facts (type, size, counts, estimated tokens), no text"},
|
|
@@ -2533,7 +2559,7 @@ def _project_action(arguments):
|
|
|
2533
2559
|
action = arguments.get("action", "list")
|
|
2534
2560
|
if action == "probe":
|
|
2535
2561
|
return _probe_index_models()
|
|
2536
|
-
if action in ('graph','compare','duplicates','duplicates_dismiss','duplicates_restore','docs','layers','affected_tests','pr_impact','pr_impact_comment','hotspots','dead_code','import_cycles','comments','credentials','links'):
|
|
2562
|
+
if action in ('graph','compare','duplicates','duplicates_dismiss','duplicates_restore','docs','layers','affected_tests','pr_impact','pr_impact_comment','hotspots','dead_code','import_cycles','comments','credentials','links','rename_preview','release_notes','commit_check'):
|
|
2537
2563
|
# Análise somente leitura pode demorar; não prende o lock global de ações.
|
|
2538
2564
|
key=arguments.get('project_id')
|
|
2539
2565
|
if not isinstance(key,str) or not re.fullmatch(r'[a-f0-9]{16}',key):
|
|
@@ -2581,6 +2607,17 @@ def _project_action(arguments):
|
|
|
2581
2607
|
if action in ('credentials','links'):
|
|
2582
2608
|
return getattr(project_scan,action)(project['root'],limit)
|
|
2583
2609
|
return getattr(code_health,action)(project['root'],arguments.get('view_id'),limit)
|
|
2610
|
+
if action=='rename_preview':
|
|
2611
|
+
import rename_preview
|
|
2612
|
+
limit=_parse_bounded_int(arguments.get('limit'),default=30,min_v=1,max_v=200,field_name='limit')
|
|
2613
|
+
return rename_preview.preview(project['root'],arguments.get('symbol'),arguments.get('view_id'),limit)
|
|
2614
|
+
if action=='commit_check':
|
|
2615
|
+
import commit_check
|
|
2616
|
+
return commit_check.review(project['root'])
|
|
2617
|
+
if action=='release_notes':
|
|
2618
|
+
import release_notes
|
|
2619
|
+
limit=_parse_bounded_int(arguments.get('limit'),default=30,min_v=1,max_v=200,field_name='limit')
|
|
2620
|
+
return release_notes.draft(project['root'],arguments.get('base'),limit,arguments.get('view_id'))
|
|
2584
2621
|
if action=='pr_impact':
|
|
2585
2622
|
import pr_impact
|
|
2586
2623
|
limit=_parse_bounded_int(arguments.get('limit'),default=30,min_v=1,max_v=200,field_name='limit')
|
|
@@ -2619,7 +2656,7 @@ def _project_action(arguments):
|
|
|
2619
2656
|
root = project['root'] if project else arguments.get('project_root')
|
|
2620
2657
|
with index_views.pin(root) if isinstance(root, str) and os.path.isdir(root) else contextlib.nullcontext():
|
|
2621
2658
|
result = _project_action_locked(arguments)
|
|
2622
|
-
if _PROJECT_MONITOR and arguments.get("action") not in (None, "list", "status", "inspect", "usage", "storage", "pin_view", "cleanup_preview", "cleanup_commit", "search_limits", "integration", "install_hook_preview", "install_hook"):
|
|
2659
|
+
if _PROJECT_MONITOR and arguments.get("action") not in (None, "list", "status", "inspect", "usage", "storage", "pin_view", "cleanup_preview", "cleanup_commit", "search_limits", "integration", "install_hook_preview", "install_hook", "commit_hook_install", "commit_hook_uninstall"):
|
|
2623
2660
|
_PROJECT_MONITOR.refresh()
|
|
2624
2661
|
return result
|
|
2625
2662
|
|
|
@@ -2712,6 +2749,9 @@ def _project_action_locked(arguments):
|
|
|
2712
2749
|
project = project_store.get(key)
|
|
2713
2750
|
if not project:
|
|
2714
2751
|
raise ValueError("Project not registered.")
|
|
2752
|
+
if action in ("commit_hook_install", "commit_hook_uninstall"):
|
|
2753
|
+
import commit_check
|
|
2754
|
+
return (commit_check.install_hook if action == "commit_hook_install" else commit_check.uninstall_hook)(project["root"])
|
|
2715
2755
|
if action == "status":
|
|
2716
2756
|
if arguments.get("resolved_from"):
|
|
2717
2757
|
return {"project": _project_payload(project), "resolved_from": arguments["resolved_from"],
|
|
@@ -4380,6 +4420,26 @@ def _handle_web_fetch(arguments):
|
|
|
4380
4420
|
return _sanitize_text(f"Source: {page['final_url']} (read at {read_at}, {origin}{cut})\n\n{text}")
|
|
4381
4421
|
|
|
4382
4422
|
|
|
4423
|
+
def _handle_web_fetch_many(arguments):
|
|
4424
|
+
"""Several URLs with one prompt, each through `_handle_web_fetch`: the per-URL report of web_fetch_many.render, and an
|
|
4425
|
+
error carrying that report when no URL could be read."""
|
|
4426
|
+
urls, prompt = arguments.get("urls"), arguments.get("prompt")
|
|
4427
|
+
started = time.monotonic()
|
|
4428
|
+
try:
|
|
4429
|
+
web_fetch_many.check(urls, prompt)
|
|
4430
|
+
except ValueError as exc:
|
|
4431
|
+
_metric("web_fetch_many", error=type(exc).__name__, elapsed_s=round(time.monotonic() - started, 2))
|
|
4432
|
+
raise
|
|
4433
|
+
results = web_fetch_many.read_many(urls, prompt, lambda url, text: _handle_web_fetch({"url": url, "prompt": text}))
|
|
4434
|
+
failed = sum(not result["ok"] for result in results)
|
|
4435
|
+
_metric("web_fetch_many", urls=len(results), distinct=len({web_fetch.normalize(url) for url in urls}), failed=failed,
|
|
4436
|
+
elapsed_s=round(time.monotonic() - started, 2))
|
|
4437
|
+
report = _sanitize_text(web_fetch_many.render(results))
|
|
4438
|
+
if failed == len(results):
|
|
4439
|
+
raise RuntimeError(report)
|
|
4440
|
+
return report
|
|
4441
|
+
|
|
4442
|
+
|
|
4383
4443
|
def _web_route(tool, url):
|
|
4384
4444
|
"""Hook decision for native WebSearch/WebFetch: redirect to the Smart Tool only while it can answer."""
|
|
4385
4445
|
if tool not in ("WebSearch", "WebFetch"):
|
|
@@ -4591,6 +4651,23 @@ def _stop_hook(handler):
|
|
|
4591
4651
|
f"{type(exc).__name__}: {_sanitize_text(str(exc))}"}
|
|
4592
4652
|
|
|
4593
4653
|
|
|
4654
|
+
def _commit_check_hook(handler):
|
|
4655
|
+
"""Answer of the git pre-commit hook (hooks/pre_commit.py): `{ok: True, files, notes}` with the review of the staged
|
|
4656
|
+
change of the registered project whose folder the hook sent, or `{ok: False, error}` naming why it could not run
|
|
4657
|
+
(an unregistered folder included); always 200, the hook prints the failure and lets the commit go."""
|
|
4658
|
+
try:
|
|
4659
|
+
import commit_check
|
|
4660
|
+
payload = json.loads(handler._read_body(HOOK_MAX_BODY_BYTES) or b"{}")
|
|
4661
|
+
root = payload.get("root") if isinstance(payload, dict) else None
|
|
4662
|
+
if not isinstance(root, str) or not os.path.isabs(root):
|
|
4663
|
+
raise ValueError("the hook sent no project folder")
|
|
4664
|
+
project = project_store.get(_with_project_id({"project_root": root})["project_id"])
|
|
4665
|
+
return {"ok": True, **commit_check.review(project["root"])}
|
|
4666
|
+
except Exception as exc:
|
|
4667
|
+
_log(f"Commit check failed: {type(exc).__name__}: {exc}")
|
|
4668
|
+
return {"ok": False, "error": f"{type(exc).__name__}: {_sanitize_text(str(exc))}"}
|
|
4669
|
+
|
|
4670
|
+
|
|
4594
4671
|
def _session_audit_hook(handler):
|
|
4595
4672
|
"""SessionStart output of the session-start hook: the update notices both as systemMessage (shown to the user) and
|
|
4596
4673
|
as additionalContext, plus the redirect proposals waiting for a decision as context; `{}` when there is nothing to
|
|
@@ -4616,19 +4693,28 @@ def _handle_read_document(arguments):
|
|
|
4616
4693
|
"""read_document: facts and a page, slide, sheet, part or chapter range of a PDF, docx, pptx, xlsx, html, csv or epub as compact text (see
|
|
4617
4694
|
document_read). Fails loudly, with the reason, for a path that is not absolute or readable, an unsupported or
|
|
4618
4695
|
oversized file, a password, a scanned PDF, a corrupt or hostile package and a range outside the document; one metric
|
|
4619
|
-
row records the kind, the estimated tokens of the whole text and of the answer.
|
|
4696
|
+
row records the kind, the estimated tokens of the whole text and of the answer. A `path` that starts with http:// or
|
|
4697
|
+
https:// is downloaded and read by document_url instead (the kind comes from the URL path: no query or credentials
|
|
4698
|
+
reach the metric); every other value takes the file path above."""
|
|
4620
4699
|
started = time.monotonic()
|
|
4621
4700
|
unknown = sorted(set(arguments) - {"path", "range", "max_chars", "info_only"})
|
|
4622
4701
|
if unknown:
|
|
4623
4702
|
raise ValueError(f"read_document does not take {', '.join(unknown)}")
|
|
4703
|
+
path = arguments.get("path")
|
|
4704
|
+
from_url = document_url.is_url(path)
|
|
4624
4705
|
try:
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4706
|
+
if from_url:
|
|
4707
|
+
text = document_url.read(path, arguments.get("range") or None,
|
|
4708
|
+
arguments.get("max_chars", document_read.DEFAULT_MAX_CHARS),
|
|
4709
|
+
bool(arguments.get("info_only")), started + WEB_FETCH_TIMEOUT_S)
|
|
4710
|
+
else:
|
|
4711
|
+
text = document_read.read(path, arguments.get("range") or None,
|
|
4712
|
+
arguments.get("max_chars", document_read.DEFAULT_MAX_CHARS),
|
|
4713
|
+
bool(arguments.get("info_only")))
|
|
4628
4714
|
except Exception as exc:
|
|
4629
4715
|
_metric("read_document", error=type(exc).__name__, elapsed_s=round(time.monotonic() - started, 2))
|
|
4630
4716
|
raise
|
|
4631
|
-
_metric("read_document", kind=os.path.splitext(str(
|
|
4717
|
+
_metric("read_document", kind=document_url.extension(path) if from_url else os.path.splitext(str(path))[1].lower(),
|
|
4632
4718
|
answer_tokens=document_read.estimate_tokens(text), elapsed_s=round(time.monotonic() - started, 2))
|
|
4633
4719
|
return _sanitize_text(text)
|
|
4634
4720
|
|
|
@@ -4636,6 +4722,7 @@ def _handle_read_document(arguments):
|
|
|
4636
4722
|
_TOOL_HANDLERS = {
|
|
4637
4723
|
"read_document": _handle_read_document,
|
|
4638
4724
|
"web_fetch": _handle_web_fetch,
|
|
4725
|
+
"web_fetch_many": _handle_web_fetch_many,
|
|
4639
4726
|
"project_manage": _handle_project_manage,
|
|
4640
4727
|
"smart_search": _handle_smart_search,
|
|
4641
4728
|
"smart_search_result": _handle_smart_search_result,
|
|
@@ -5036,7 +5123,7 @@ class MCPHandler(BaseHTTPRequestHandler):
|
|
|
5036
5123
|
|
|
5037
5124
|
def do_POST(self):
|
|
5038
5125
|
"""Routes a POST: the Playwright bridge, setup actions, the hook routes (/hooks/pretool, /hooks/posttool,
|
|
5039
|
-
/hooks/session-audit) and the MCP endpoint (/mcp); anything else is 404."""
|
|
5126
|
+
/hooks/session-audit, /hooks/commit-check) and the MCP endpoint (/mcp); anything else is 404."""
|
|
5040
5127
|
if self._reject_foreign_origin():
|
|
5041
5128
|
return
|
|
5042
5129
|
if self.path == browser_bridge.PATH:
|
|
@@ -5077,6 +5164,9 @@ class MCPHandler(BaseHTTPRequestHandler):
|
|
|
5077
5164
|
if urllib.parse.urlsplit(self.path).path == "/hooks/stop":
|
|
5078
5165
|
self._write_json(200, _stop_hook(self))
|
|
5079
5166
|
return
|
|
5167
|
+
if urllib.parse.urlsplit(self.path).path == "/hooks/commit-check":
|
|
5168
|
+
self._write_json(200, _commit_check_hook(self))
|
|
5169
|
+
return
|
|
5080
5170
|
if self.path == "/setup/notices":
|
|
5081
5171
|
try:
|
|
5082
5172
|
self._write_json(200, setup_ui.handle_notices())
|
package/version.py
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""web_fetch_many: several URLs with one prompt in one call, each read through the single-URL path of web_fetch.
|
|
2
|
+
|
|
3
|
+
The caller passes that path as `fetch_one(url, prompt)`: it returns the text of one URL or raises. Every URL is read on
|
|
4
|
+
its own (cache, failure memory, browser fallback, address guard and answer of web_fetch), so one URL that fails is
|
|
5
|
+
reported with its reason next to the others instead of failing or answering for them. A small pool keeps the number of
|
|
6
|
+
pages read at once, and so of browsers started, low.
|
|
7
|
+
"""
|
|
8
|
+
import concurrent.futures
|
|
9
|
+
import contextvars
|
|
10
|
+
|
|
11
|
+
import web_fetch
|
|
12
|
+
|
|
13
|
+
MAX_URLS = 8
|
|
14
|
+
WORKERS = 4
|
|
15
|
+
MAX_URL_CHARS = 2000
|
|
16
|
+
MAX_PROMPT_CHARS = 4000
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def check(urls, prompt):
|
|
20
|
+
"""Raises ValueError unless `urls` is a list of 1 to MAX_URLS non-empty strings and `prompt` a non-empty string, so
|
|
21
|
+
nothing is read for a malformed call."""
|
|
22
|
+
if not isinstance(urls, list) or not urls:
|
|
23
|
+
raise ValueError(f"web_fetch_many requires 'urls' (a list of 1 to {MAX_URLS} URLs)")
|
|
24
|
+
if len(urls) > MAX_URLS:
|
|
25
|
+
raise ValueError(f"web_fetch_many reads at most {MAX_URLS} URLs per call, got {len(urls)}: split them in calls "
|
|
26
|
+
f"of {MAX_URLS} or fewer")
|
|
27
|
+
if not all(isinstance(url, str) and url.strip() and len(url) <= MAX_URL_CHARS for url in urls):
|
|
28
|
+
raise ValueError(f"web_fetch_many requires every URL to be a non-empty string of at most {MAX_URL_CHARS} "
|
|
29
|
+
"characters")
|
|
30
|
+
if not isinstance(prompt, str) or not prompt.strip() or len(prompt) > MAX_PROMPT_CHARS:
|
|
31
|
+
raise ValueError(f"web_fetch_many requires 'prompt' (at most {MAX_PROMPT_CHARS} characters)")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def read_many(urls, prompt, fetch_one):
|
|
35
|
+
"""One result per entry of `urls`, in the same order: `{"url", "ok": True, "text"}` or `{"url", "ok": False,
|
|
36
|
+
"error"}`. A URL repeated (same address once the fragment and the outer spaces are dropped) is read once and
|
|
37
|
+
every position gets its result. Each read runs in a copy of the caller's context, so the request attribution and
|
|
38
|
+
the model-failure collection of the tool call follow it into the pool."""
|
|
39
|
+
keys = [web_fetch.normalize(url) for url in urls]
|
|
40
|
+
distinct = list(dict.fromkeys(keys))
|
|
41
|
+
with concurrent.futures.ThreadPoolExecutor(min(WORKERS, len(distinct)), thread_name_prefix="web-fetch-many") as pool:
|
|
42
|
+
futures = {key: pool.submit(contextvars.copy_context().run, fetch_one, key, prompt) for key in distinct}
|
|
43
|
+
outcomes = {key: _outcome(future) for key, future in futures.items()}
|
|
44
|
+
return [{"url": url, **outcomes[key]} for url, key in zip(urls, keys)]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _outcome(future):
|
|
48
|
+
try:
|
|
49
|
+
return {"ok": True, "text": future.result()}
|
|
50
|
+
except Exception as exc:
|
|
51
|
+
return {"ok": False, "error": str(exc) or type(exc).__name__}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def render(results):
|
|
55
|
+
"""The text the agent reads: a count line, then one numbered block per URL with its answer or `ERROR: reason`."""
|
|
56
|
+
failed = sum(not result["ok"] for result in results)
|
|
57
|
+
blocks = [f"web_fetch_many: {len(results)} URLs, {len(results) - failed} read, {failed} failed."]
|
|
58
|
+
for number, result in enumerate(results, 1):
|
|
59
|
+
body = result["text"] if result["ok"] else f"ERROR: {result['error']}"
|
|
60
|
+
blocks.append(f"[{number}/{len(results)}] {result['url']}\n{body}")
|
|
61
|
+
return "\n\n".join(blocks)
|