@allansantos-dev/smart-tool 0.9.80 → 0.9.81
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 +65 -0
- package/README.md +21 -4
- package/client_hooks.py +10 -8
- package/code_health.py +5 -3
- package/code_impact.py +1 -1
- package/config.py +35 -0
- package/dossier.py +40 -5
- package/hook_decision.py +240 -20
- package/hooks/pretool_router.py +5 -4
- package/install.py +66 -27
- package/install_runtime.py +24 -10
- package/link_check.py +69 -0
- package/local_embedder.py +1 -1
- package/locales/pt-BR.json +71 -2
- package/model_client.py +1 -1
- package/model_health.py +24 -6
- package/notice_action.py +9 -0
- package/package.json +1 -1
- package/pr_comment.py +94 -0
- package/pr_impact.py +216 -35
- package/project_admission.py +17 -15
- package/removed_callers.py +146 -0
- package/setup_ui.py +33 -4
- package/smart_tool_daemon.py +8 -3
- package/tray.py +29 -9
- package/update_splash.py +2 -2
- package/version.py +1 -1
- package/web_document_graph.py +12 -1
package/setup_ui.py
CHANGED
|
@@ -309,6 +309,18 @@ def handle_integration_get():
|
|
|
309
309
|
layer_mode, layer_error = config.layer_mode(), ""
|
|
310
310
|
except ValueError as exc:
|
|
311
311
|
layer_mode, layer_error = "", str(exc)
|
|
312
|
+
try:
|
|
313
|
+
link_mode, link_error = config.link_mode(), ""
|
|
314
|
+
except ValueError as exc:
|
|
315
|
+
link_mode, link_error = "", str(exc)
|
|
316
|
+
try:
|
|
317
|
+
pr_comment, pr_comment_error = config.pr_comment(), ""
|
|
318
|
+
except ValueError as exc:
|
|
319
|
+
pr_comment, pr_comment_error = "", str(exc)
|
|
320
|
+
try:
|
|
321
|
+
decision_mode, decision_error = config.decision_mode(), ""
|
|
322
|
+
except ValueError as exc:
|
|
323
|
+
decision_mode, decision_error = "", str(exc)
|
|
312
324
|
try:
|
|
313
325
|
proposals_mode, proposals_error = config.pattern_proposals(), ""
|
|
314
326
|
except ValueError as exc:
|
|
@@ -325,6 +337,10 @@ def handle_integration_get():
|
|
|
325
337
|
"dependency_mode": dependency_mode, "dependency_mode_error": dependency_error,
|
|
326
338
|
"dependency_modes": list(config.DEPENDENCY_MODES),
|
|
327
339
|
"layer_mode": layer_mode, "layer_mode_error": layer_error, "layer_modes": list(config.LAYER_MODES),
|
|
340
|
+
"link_mode": link_mode, "link_mode_error": link_error, "link_modes": list(config.LINK_MODES),
|
|
341
|
+
"pr_comment": pr_comment, "pr_comment_error": pr_comment_error, "pr_comment_modes": list(config.PR_COMMENT_MODES),
|
|
342
|
+
"decision_mode": decision_mode, "decision_mode_error": decision_error,
|
|
343
|
+
"decision_modes": list(config.DECISION_MODES),
|
|
328
344
|
"pattern_proposals": proposals_mode, "pattern_proposals_error": proposals_error,
|
|
329
345
|
"block_patterns": {"proposals": stored["proposals"], "accepted": stored["accepted"],
|
|
330
346
|
"rejected": len(stored["rejected"]), "error": patterns_error},
|
|
@@ -343,11 +359,12 @@ def handle_integration_save(body):
|
|
|
343
359
|
except (OSError, ValueError) as exc:
|
|
344
360
|
raise SetupError(str(exc))
|
|
345
361
|
return handle_integration_get()
|
|
346
|
-
if isinstance(body, dict) and body.get("action") in ("hook_mode", "doc_mode", "comment_mode", "duplicate_mode", "dependency_mode", "layer_mode", "pattern_proposals"):
|
|
362
|
+
if isinstance(body, dict) and body.get("action") in ("hook_mode", "doc_mode", "comment_mode", "duplicate_mode", "dependency_mode", "layer_mode", "link_mode", "pr_comment", "decision_mode", "pattern_proposals"):
|
|
347
363
|
action = body["action"]
|
|
348
364
|
allowed = {"hook_mode": config.HOOK_MODES, "doc_mode": config.DOC_MODES, "comment_mode": config.COMMENT_MODES,
|
|
349
365
|
"duplicate_mode": config.DUPLICATE_MODES, "dependency_mode": config.DEPENDENCY_MODES,
|
|
350
|
-
"layer_mode": config.LAYER_MODES,
|
|
366
|
+
"layer_mode": config.LAYER_MODES, "link_mode": config.LINK_MODES, "pr_comment": config.PR_COMMENT_MODES,
|
|
367
|
+
"decision_mode": config.DECISION_MODES,
|
|
351
368
|
"pattern_proposals": config.PATTERN_PROPOSAL_MODES}[action]
|
|
352
369
|
if body.get("mode") not in allowed:
|
|
353
370
|
raise SetupError(f"Invalid mode: use {', '.join(allowed)}.")
|
|
@@ -836,7 +853,7 @@ __I18N__
|
|
|
836
853
|
|
|
837
854
|
<div class="card" id="health-card">
|
|
838
855
|
<div class="card-head"><h3>Model failures (last 24 h)</h3><span class="pill" id="health-pill" data-tone="busy">Checking</span></div>
|
|
839
|
-
<p class="lede">Failed calls to a gateway model, grouped by type (429, 503, timeout, ...) and role, with the latest lines of each group. A model that fails half of its calls (5 or more) also raises a Windows notification.</p>
|
|
856
|
+
<p class="lede">Failed calls to a gateway model, grouped by type (429, 503, timeout, ...) and role, with the latest lines of each group. A model that fails half of its calls (5 or more) also raises a Windows notification. Calls refused while a model is paused show as Circuit open and do not count toward that limit.</p>
|
|
840
857
|
<div id="health-table"></div>
|
|
841
858
|
</div>
|
|
842
859
|
|
|
@@ -1276,7 +1293,7 @@ for (const [id, action] of [["btn-upgrade-apply", "apply"], ["btn-upgrade-declin
|
|
|
1276
1293
|
});
|
|
1277
1294
|
}
|
|
1278
1295
|
const FAILURE_TYPES = { "429": "429 Too Many Requests", "503": "503 Service Unavailable", "5xx": "Other 5xx", timeout: "Timeout",
|
|
1279
|
-
connection: "Connection", auth: "Authentication (401/403)", other: "Other" };
|
|
1296
|
+
connection: "Connection", circuit_open: "Circuit open", auth: "Authentication (401/403)", other: "Other" };
|
|
1280
1297
|
const PURPOSE_LABELS = { index_embedding: "Indexing", query_embedding: "Query", rerank: "Rerank", embedding_probe: "Model check", scope: "Scope" };
|
|
1281
1298
|
function healthHtml(data) {
|
|
1282
1299
|
const when = (at) => esc(new Date(at * 1000).toLocaleString());
|
|
@@ -1463,6 +1480,18 @@ const RULES = [
|
|
|
1463
1480
|
intro: "When the project has confirmed layers (.smart-tool/layers.json), warns about a call an edit adds from a lower layer to a function of a higher one. A project without layers is never checked. It never blocks.",
|
|
1464
1481
|
options: [["warn", "Warn", "The edit runs; the agent is told which new calls go up the layers.", true],
|
|
1465
1482
|
["off", "Off", "No layer checks."]] },
|
|
1483
|
+
{ key: "link_mode", title: "Broken local links on edit", applies: "Applies on the next edit.",
|
|
1484
|
+
intro: "Checks the relative links (href, src, Markdown link targets) an edit of an HTML or Markdown file adds or changes against the files on disk, and says which ones it could not check. Links that were already broken are left alone. It never blocks.",
|
|
1485
|
+
options: [["warn", "Warn", "The edit runs; the agent is told which new links point to a file that does not exist.", true],
|
|
1486
|
+
["off", "Off", "No link checks."]] },
|
|
1487
|
+
{ key: "pr_comment", title: "Impact report as a pull request comment", applies: "Applies on the next request of an agent.",
|
|
1488
|
+
intro: "Lets Smart Tool post the impact report as a comment on a pull request through the gh CLI, with your own gh login. This writes to GitHub: nothing is ever posted while this is off, and each post is one agent request (project_manage action=pr_impact_comment). A rerun replaces the previous Smart Tool comment instead of adding another.",
|
|
1489
|
+
options: [["off", "Off", "Nothing is posted to GitHub.", true],
|
|
1490
|
+
["on", "On", "Agents may post the impact report as a comment on a pull request through the gh CLI."]] },
|
|
1491
|
+
{ key: "decision_mode", title: "Recorded decisions on edit", applies: "Applies on the next edit.",
|
|
1492
|
+
intro: "Looks up the notes of the project (docs/research, the backlog, CLAUDE.md and AGENTS.md) and its commit messages for the functions an edit touches, and names the ones that record a decision about them. A single-word function name counts only when a note qualifies it with its module or class. It never blocks.",
|
|
1493
|
+
options: [["warn", "Warn", "The edit runs; the agent is told which notes and commits record a decision about a touched function.", true],
|
|
1494
|
+
["off", "Off", "No decision lookup."]] },
|
|
1466
1495
|
{ key: "pattern_proposals", title: "Block patterns proposed by a model", applies: "Applies to the next review.",
|
|
1467
1496
|
intro: "Afterwards, never delaying a call, the scope model (else the router model) reviews searches the fixed rule let through and may propose block patterns. Nothing blocks until you accept it on the Redirects page.",
|
|
1468
1497
|
options: [["on", "On", "Review in the background and list proposals for you.", true],
|
package/smart_tool_daemon.py
CHANGED
|
@@ -384,10 +384,10 @@ SERVER_INSTRUCTIONS = (
|
|
|
384
384
|
TOOLS = [
|
|
385
385
|
{
|
|
386
386
|
"name": "project_manage",
|
|
387
|
-
"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. 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. 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.",
|
|
387
|
+
"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. 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.",
|
|
388
388
|
"inputSchema": {
|
|
389
389
|
"type": "object", "properties": {
|
|
390
|
-
"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", "hotspots", "dead_code", "import_cycles", "comments", "setup_audit", "redirect_proposals", "redirect_decide", "junk", "deps"]},
|
|
390
|
+
"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", "setup_audit", "redirect_proposals", "redirect_decide", "junk", "deps"]},
|
|
391
391
|
"ids": {"type": "array", "items": {"type": "string"}, "description": "redirect_decide: proposal ids from redirect_proposals (accepted ids for remove)"},
|
|
392
392
|
"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"},
|
|
393
393
|
"finding_id": {"type": "string"},
|
|
@@ -420,6 +420,7 @@ TOOLS = [
|
|
|
420
420
|
"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"},
|
|
421
421
|
"probe": {"type": "boolean", "default": True, "description": "setup_audit: start/call each MCP server (initialize + tools/list); false reads configs only"},
|
|
422
422
|
"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)"},
|
|
423
|
+
"pr": {"type": "integer", "minimum": 1, "description": "pr_impact_comment: number of the pull request to comment on"},
|
|
423
424
|
"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"},
|
|
424
425
|
"depth": {"type": "integer", "minimum": 1, "maximum": 4, "default": 3, "description": "graph with symbol: call hops searched for tests"},
|
|
425
426
|
"project_root": {"type": "string"}, "project_id": {"type": "string"},
|
|
@@ -2507,7 +2508,7 @@ def _project_action(arguments):
|
|
|
2507
2508
|
action = arguments.get("action", "list")
|
|
2508
2509
|
if action == "probe":
|
|
2509
2510
|
return _probe_index_models()
|
|
2510
|
-
if action in ('graph','compare','duplicates','duplicates_dismiss','duplicates_restore','docs','layers','affected_tests','pr_impact','hotspots','dead_code','import_cycles','comments'):
|
|
2511
|
+
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'):
|
|
2511
2512
|
# Análise somente leitura pode demorar; não prende o lock global de ações.
|
|
2512
2513
|
key=arguments.get('project_id')
|
|
2513
2514
|
if not isinstance(key,str) or not re.fullmatch(r'[a-f0-9]{16}',key):
|
|
@@ -2556,6 +2557,10 @@ def _project_action(arguments):
|
|
|
2556
2557
|
import pr_impact
|
|
2557
2558
|
limit=_parse_bounded_int(arguments.get('limit'),default=30,min_v=1,max_v=200,field_name='limit')
|
|
2558
2559
|
return pr_impact.report(project['root'],arguments.get('base','HEAD'),limit,arguments.get('view_id'))
|
|
2560
|
+
if action=='pr_impact_comment':
|
|
2561
|
+
import pr_comment
|
|
2562
|
+
limit=_parse_bounded_int(arguments.get('limit'),default=30,min_v=1,max_v=200,field_name='limit')
|
|
2563
|
+
return pr_comment.publish(project['root'],arguments.get('pr'),arguments.get('base'),limit,arguments.get('view_id'))
|
|
2559
2564
|
if action=='affected_tests':
|
|
2560
2565
|
import affected_tests
|
|
2561
2566
|
limit=_parse_bounded_int(arguments.get('limit'),default=30,min_v=1,max_v=200,field_name='limit')
|
package/tray.py
CHANGED
|
@@ -36,6 +36,8 @@ NOTICE_INTERVAL_S = 600
|
|
|
36
36
|
NOTICE_RETRY_S = 15
|
|
37
37
|
UPDATE_RETRY_S = 300
|
|
38
38
|
NOTICE_UNREACHABLE_LOG_S = 600
|
|
39
|
+
BALLOON_TEXT_MAX = 255
|
|
40
|
+
BALLOON_TITLE_MAX = 63
|
|
39
41
|
LOG_PATH = os.path.join(paths.DATA_DIR, "tray.log")
|
|
40
42
|
LOG_MAX_BYTES = 256 * 1024
|
|
41
43
|
SETUP_URL = "http://127.0.0.1:8765/setup"
|
|
@@ -89,13 +91,13 @@ def _set_state(health, icon=None):
|
|
|
89
91
|
icon.title = i18n.t(_TITLES[health])
|
|
90
92
|
|
|
91
93
|
|
|
92
|
-
def _notify(icon, text, buttons=(), **values):
|
|
94
|
+
def _notify(icon, text, buttons=(), tag=None, **values):
|
|
93
95
|
"""Windows notification, translated (text is an English catalog key; buttons are (catalog key, protocol link)). A
|
|
94
96
|
toast under Smart Tool's own app id, since the tray balloon is shown as "Python"; when Windows refuses the toast,
|
|
95
|
-
the balloon carries the text and the refusal."""
|
|
97
|
+
the balloon carries the text and the refusal. A toast with a tag replaces the earlier one with the same tag."""
|
|
96
98
|
message = i18n.t(text, **values)
|
|
97
99
|
try:
|
|
98
|
-
toast_notice.show("Smart Tool", [message], [(i18n.t(label), uri) for label, uri in buttons])
|
|
100
|
+
toast_notice.show("Smart Tool", [message], [(i18n.t(label), uri) for label, uri in buttons], tag=tag)
|
|
99
101
|
except Exception as exc:
|
|
100
102
|
icon.notify(f"{message} ({exc})", "Smart Tool")
|
|
101
103
|
|
|
@@ -146,12 +148,17 @@ def _poll_loop(icon):
|
|
|
146
148
|
time.sleep(POLL_INTERVAL_S)
|
|
147
149
|
|
|
148
150
|
|
|
149
|
-
def _toast(title, lines, buttons, tag):
|
|
150
|
-
"""One notice: a toast Windows refuses goes to `tray.log` and
|
|
151
|
+
def _toast(icon, title, lines, buttons, tag):
|
|
152
|
+
"""One notice: a toast Windows refuses goes to `tray.log` and, cut to what a balloon holds, to the tray balloon; a
|
|
153
|
+
balloon that fails is logged too, and neither keeps the next notices from being shown."""
|
|
151
154
|
try:
|
|
152
155
|
toast_notice.show(title, lines, buttons, tag=tag)
|
|
153
156
|
except Exception as exc:
|
|
154
157
|
_log(f"notice {tag}: {type(exc).__name__}: {exc}")
|
|
158
|
+
try:
|
|
159
|
+
icon.notify(f"{' '.join(lines)} ({exc})"[:BALLOON_TEXT_MAX], title[:BALLOON_TITLE_MAX])
|
|
160
|
+
except Exception as balloon_exc:
|
|
161
|
+
_log(f"notice {tag}: balloon failed: {type(balloon_exc).__name__}: {balloon_exc}")
|
|
155
162
|
|
|
156
163
|
|
|
157
164
|
def _show_notices(icon, notices):
|
|
@@ -160,14 +167,14 @@ def _show_notices(icon, notices):
|
|
|
160
167
|
if offer:
|
|
161
168
|
lines = [f"{role}: {change['current']} -> {change['new']}" for role, change in offer["changes"].items()]
|
|
162
169
|
nonce = offer["nonce"]
|
|
163
|
-
_toast(i18n.t("Smart Tool has new recommended models"), lines, [
|
|
170
|
+
_toast(icon, i18n.t("Smart Tool has new recommended models"), lines, [
|
|
164
171
|
(i18n.t("Apply now"), toast_notice.action_uri("models-apply", n=nonce)),
|
|
165
172
|
(i18n.t("Don't show again"), toast_notice.action_uri("models-decline", n=nonce)),
|
|
166
173
|
], "models-upgrade")
|
|
167
174
|
for row in notices.get("failing") or []:
|
|
168
175
|
last = row.get("last_error") or i18n.t("see the failure log in the settings")
|
|
169
176
|
_toast(
|
|
170
|
-
i18n.t("{model} is failing", model=row["model"]),
|
|
177
|
+
icon, i18n.t("{model} is failing", model=row["model"]),
|
|
171
178
|
[i18n.t("{errors} of {calls} calls failed in 24 h as {role}.", errors=row["errors"], calls=row["calls"],
|
|
172
179
|
role=row["role"]), last[:160]],
|
|
173
180
|
[(i18n.t("Switch model"), toast_notice.action_uri("open-setup", section="models")),
|
|
@@ -238,7 +245,7 @@ def _announce_start(icon):
|
|
|
238
245
|
if failed:
|
|
239
246
|
log = (i18n.N_("View log"), toast_notice.action_uri("open-update-log"))
|
|
240
247
|
_notify(icon, "The update to {target} failed; Smart Tool {version} is still installed. It is tried again in "
|
|
241
|
-
"24 h, or now from this menu.", [log], target=failed, version=version.VERSION)
|
|
248
|
+
"24 h, or now from this menu.", [log], tag="update-failed", target=failed, version=version.VERSION)
|
|
242
249
|
|
|
243
250
|
|
|
244
251
|
def _update_loop(icon):
|
|
@@ -274,8 +281,9 @@ def _update_loop(icon):
|
|
|
274
281
|
_notify(icon, "Updating Smart Tool from {old} to {new}...", old=version.VERSION, new=latest)
|
|
275
282
|
update_check.run_update(latest, automatic=True)
|
|
276
283
|
elif not known:
|
|
284
|
+
update_now = (i18n.N_("Update now"), toast_notice.action_uri("update-now", v=latest))
|
|
277
285
|
_notify(icon, "Smart Tool {version} is available: use \"Update to {version}\" in this menu.",
|
|
278
|
-
version=latest)
|
|
286
|
+
[update_now], version=latest)
|
|
279
287
|
time.sleep(UPDATE_RETRY_S if unreachable else UPDATE_CHECK_INTERVAL_S)
|
|
280
288
|
|
|
281
289
|
|
|
@@ -348,6 +356,17 @@ def _choose_language(lang):
|
|
|
348
356
|
return choose
|
|
349
357
|
|
|
350
358
|
|
|
359
|
+
def _open_log(icon, item):
|
|
360
|
+
"""Menu action: opens `tray.log` with the program Windows associates with it, or says there is none yet."""
|
|
361
|
+
if not os.path.exists(LOG_PATH):
|
|
362
|
+
_notify(icon, "There is no tray log yet.")
|
|
363
|
+
return
|
|
364
|
+
try:
|
|
365
|
+
os.startfile(LOG_PATH)
|
|
366
|
+
except OSError as exc:
|
|
367
|
+
_notify(icon, "Could not open the log: {error}", error=exc)
|
|
368
|
+
|
|
369
|
+
|
|
351
370
|
def _open_setup(icon, item):
|
|
352
371
|
registry = daemon_launcher.read_registry()
|
|
353
372
|
webbrowser.open((registry["url"].rstrip("/") + "/setup") if registry else SETUP_URL)
|
|
@@ -440,6 +459,7 @@ def main():
|
|
|
440
459
|
pystray.MenuItem(lambda item: i18n.t("Projects and indexing…"), _open_projects, default=True),
|
|
441
460
|
pystray.MenuItem(lambda item: i18n.t("Index a folder…"), _add_project),
|
|
442
461
|
pystray.MenuItem(lambda item: i18n.t("Open settings"), _open_setup),
|
|
462
|
+
pystray.MenuItem(lambda item: i18n.t("Open tray log"), _open_log),
|
|
443
463
|
pystray.MenuItem(lambda item: i18n.t("Start with Windows"), _toggle_autostart, checked=_autostart_checked),
|
|
444
464
|
pystray.MenuItem(_update_label, _update_now),
|
|
445
465
|
pystray.MenuItem(lambda item: i18n.t("Update automatically"), _toggle_auto_update,
|
package/update_splash.py
CHANGED
|
@@ -54,12 +54,12 @@ def install_command(target):
|
|
|
54
54
|
the tray announced. `@latest` would let npx reuse an older package from its cache and install that instead;
|
|
55
55
|
--prefer-online makes npm ask the registry for the package's version list, which in the first minutes after a
|
|
56
56
|
publication its cache does not yet have (ETARGET); --expect-version makes the installer refuse a package that is
|
|
57
|
-
not that version."""
|
|
57
|
+
not that version. The installer is asked for English: STEPS and the log are read from its English lines."""
|
|
58
58
|
npx = node_locator.which("npx.cmd")
|
|
59
59
|
if not npx:
|
|
60
60
|
raise RuntimeError(i18n.t("Node.js (npx) was not found; install Node.js and try again."))
|
|
61
61
|
return ["cmd.exe", "/d", "/c", npx, "--yes", "--prefer-online", f"{update_check.PACKAGE}@{target}", "install",
|
|
62
|
-
"--expect-version", target], npx
|
|
62
|
+
"--language", "en", "--expect-version", target], npx
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
def installed_version(folder=os.path.dirname(os.path.abspath(__file__))):
|
package/version.py
CHANGED
package/web_document_graph.py
CHANGED
|
@@ -5,14 +5,25 @@ from html.parser import HTMLParser
|
|
|
5
5
|
from urllib.parse import unquote,urlsplit
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
def local_target(origin,value):
|
|
9
|
+
"""Caminho do alvo de uma referência local: relativo à pasta de `origin` (ou à raiz, se começar com '/')."""
|
|
10
|
+
path=urlsplit(value).path
|
|
11
|
+
return posixpath.normpath(posixpath.join(posixpath.dirname(origin),unquote(path))) if not path.startswith('/') else unquote(path).lstrip('/')
|
|
12
|
+
|
|
13
|
+
|
|
8
14
|
def analyze(sources,all_paths):
|
|
15
|
+
"""Referências locais e externas de HTML, CSS e Markdown.
|
|
16
|
+
|
|
17
|
+
Parâmetros: sources (dict caminho -> texto); all_paths (caminhos existentes, para resolver os alvos).
|
|
18
|
+
Retorna: dict com `dependencies` (source, target, specifier, line, kind, resolution), `diagnostics` e `parsed`.
|
|
19
|
+
"""
|
|
9
20
|
paths=set(all_paths);dependencies=[];diagnostics=[];parsed=[]
|
|
10
21
|
def reference(origin,value,line,kind):
|
|
11
22
|
if not value or value.startswith(('#','data:','javascript:','mailto:','tel:')):return
|
|
12
23
|
url=urlsplit(value)
|
|
13
24
|
if url.scheme or url.netloc:
|
|
14
25
|
dependencies.append({'source':origin,'target':None,'specifier':value[:300],'line':line,'kind':kind,'resolution':'external'});return
|
|
15
|
-
target=
|
|
26
|
+
target=local_target(origin,value)
|
|
16
27
|
if target.startswith('../') or target==origin:return
|
|
17
28
|
found=target if target in paths else None
|
|
18
29
|
dependencies.append({'source':origin,'target':found,'specifier':value[:300],'line':line,'kind':kind,'resolution':'resolved' if found else 'unresolved'})
|