@allansantos-dev/smart-tool 0.9.57 → 0.9.65

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.
@@ -53,6 +53,8 @@
53
53
  "smart_scout: writes a short answer over the lines it read and keeps only the ones that answer. Empty returns the literal lines without a model.": "smart_scout: escreve uma resposta curta sobre as linhas que leu e guarda só as que respondem. Vazio devolve as linhas literais, sem modelo.",
54
54
  "Web research": "Pesquisa na web",
55
55
  "Used by web_search with depth=research. Empty uses the router model.": "Usado por web_search com depth=research. Vazio usa o modelo do roteador.",
56
+ "Docs model": "Modelo da documentação",
57
+ "Writes the prose of the generated documentation (project_manage action=docs write_prose=true); each paragraph is checked against the code before it is written.": "Escreve a prosa da documentação gerada (project_manage action=docs write_prose=true); cada parágrafo é conferido contra o código antes de ser gravado.",
56
58
  "Advanced web research limits": "Limites avançados da pesquisa na web",
57
59
  "Maximum research rounds": "Máximo de rodadas de pesquisa",
58
60
  "How many search rounds a research may run before answering.": "Quantas rodadas de busca uma pesquisa pode fazer antes de responder.",
@@ -185,6 +187,8 @@
185
187
  "Rerank": "Rerank",
186
188
  "Model check": "Verificação de modelos",
187
189
  "Scope": "Escopo",
190
+ "Scout": "Scout",
191
+ "Documentation": "Documentação",
188
192
  "Showing the latest {0} of {1}.": "Mostrando os {0} mais recentes de {1}.",
189
193
  "Role": "Função",
190
194
  "Model": "Modelo",
@@ -226,6 +230,11 @@
226
230
  "The edit runs; the agent is told which touched functions lack a docstring.": "A edição é feita; o agente é avisado de quais funções alteradas estão sem docstring.",
227
231
  "Require": "Exigir",
228
232
  "No documentation checks.": "Nenhuma verificação de documentação.",
233
+ "Comments in the wrong place": "Comentários no lugar errado",
234
+ "Checks the comments an edit adds: commented-out code, ticket or history tags, a loose block above a function instead of its docstring, and a long block inside a function body. A short comment that says why stays allowed.": "Verifica os comentários que uma edição adiciona: código comentado, tags de ticket ou de histórico, um bloco solto acima de uma função em vez da docstring e um bloco longo dentro do corpo da função. Um comentário curto que diz o porquê continua permitido.",
235
+ "An edit that adds a comment in the wrong place is blocked until it is fixed.": "Uma edição que adiciona um comentário no lugar errado é bloqueada até ser corrigida.",
236
+ "The edit runs; the agent is told which comments are misplaced.": "A edição é feita; o agente é avisado de quais comentários estão fora do lugar.",
237
+ "No comment checks.": "Nenhuma verificação de comentários.",
229
238
  "Duplicate functions on edit": "Funções duplicadas ao editar",
230
239
  "Compares the functions an edit writes with the indexed code: identical bodies, and near-identical ones with only local names changed. It never blocks.": "Compara as funções que uma edição escreve com o código indexado: corpos idênticos e quase idênticos, só com nomes locais alterados. Nunca bloqueia.",
231
240
  "Warn": "Avisar",
@@ -564,7 +573,7 @@
564
573
  "Reading the snapshot and analyzing imports and calls…": "Lendo o instantâneo e analisando importações e chamadas…",
565
574
  "Could not load the maps.": "Não foi possível carregar os mapas.",
566
575
  "Use Load maps to try again.": "Use Carregar mapas para tentar de novo.",
567
- "Local analysis of Java, Angular, Python, JavaScript/TypeScript, HTML/CSS and Markdown links. TXT and DOCX show up in coverage and in text search. {0} of {1} files were analyzed. Other languages and incomplete snapshots remain available in coverage.": "Análise local de Java, Angular, Python, JavaScript/TypeScript, HTML/CSS e links de Markdown. TXT e DOCX aparecem na cobertura e na busca de texto. {0} de {1} arquivos foram analisados. Outras linguagens e instantâneos incompletos continuam disponíveis na cobertura.",
576
+ "Local analysis of Java, Angular, Python, JavaScript/TypeScript, Go, HTML/CSS and Markdown links. TXT and DOCX show up in coverage and in text search. {0} of {1} files were analyzed. Other languages and incomplete snapshots remain available in coverage.": "Análise local de Java, Angular, Python, JavaScript/TypeScript, Go, HTML/CSS e links de Markdown. TXT e DOCX aparecem na cobertura e na busca de texto. {0} de {1} arquivos foram analisados. Outras linguagens e instantâneos incompletos continuam disponíveis na cobertura.",
568
577
  "{0} resolved internal references; {1} external references; {2} call relations. Unresolved targets are a limited sample ({3} records in the analysis).": "{0} referências internas resolvidas; {1} referências externas; {2} relações de chamada. Os destinos não resolvidos são uma amostra limitada ({3} registros na análise).",
569
578
  "The analysis limits were reached. Filter by folder to explore the available part.": "Os limites da análise foram atingidos. Filtre por pasta para explorar a parte disponível.",
570
579
  "{0} of {1} files · area by lines": "{0} de {1} arquivos · área por linhas",
package/model_client.py CHANGED
@@ -131,22 +131,27 @@ def _route(model):
131
131
  return str(model or "").replace("/", ".").replace(":", ".").split(".")[0].lower()
132
132
 
133
133
 
134
+ def _claude(model):
135
+ """Whether the model id names a Claude model, the only family that reads Anthropic's `output_config`."""
136
+ return "claude" in str(model or "").lower()
137
+
138
+
134
139
  def structured(model, system, user, tool, timeout=30):
135
140
  """One chat call whose answer is a JSON object validated against the parameters schema of `tool` (the tool
136
141
  definition is only the carrier of name and schema; `system` may be empty). The request format comes from the `structured_output`
137
- configuration: `output_config` for the routes listed there, `response_format` otherwise; never `temperature`.
142
+ configuration: `output_config` for the Claude models on the routes listed there, `response_format` otherwise; never `temperature`.
138
143
  Raises RuntimeError on a stop other than a normal one, a refusal or an empty answer, and ValueError when the
139
144
  object breaks the schema."""
140
145
  settings = config.structured_output()
141
146
  schema = _strict_schema(tool["function"]["parameters"], set(settings["unsupported_keywords"]))
142
147
  route = _route(model)
143
148
  routes = {item.lower() for item in settings["output_config_routes"]}
144
- if settings["mode"] == "output_config" and route not in routes:
145
- raise ValueError(f"structured_output.mode is output_config but the route {route!r} of {model} is not in "
146
- f"output_config_routes {sorted(routes)}.")
149
+ if settings["mode"] == "output_config" and (route not in routes or not _claude(model)):
150
+ raise ValueError(f"structured_output.mode is output_config but {model} is not a Claude model on a route of "
151
+ f"output_config_routes {sorted(routes)}; use mode auto or response_format.")
147
152
  messages = [{"role": "system", "content": system}] if system else []
148
153
  body = {"model": model, "messages": messages + [{"role": "user", "content": user}]}
149
- if settings["mode"] == "output_config" or (settings["mode"] == "auto" and route in routes):
154
+ if settings["mode"] == "output_config" or (settings["mode"] == "auto" and route in routes and _claude(model)):
150
155
  body["output_config"] = {"format": {"type": "json_schema", "schema": schema}}
151
156
  else:
152
157
  body["response_format"] = {"type": "json_schema", "json_schema": {
package/model_defaults.py CHANGED
@@ -6,16 +6,19 @@ import config
6
6
  import model_catalog
7
7
 
8
8
 
9
- # Matched as the last path/dot segment of the catalog id, so "claude-haiku-5-5" also finds "vertex_ai.anthropic.claude-haiku-5-5"
10
- # (LiteLLM aliases) and "anthropic/claude-haiku-5-5" (OpenRouter). Chosen by measurement, 3 rounds per model, correctness
11
- # first and price second (docs/research/2026-10-24-modelos-do-scout-e-dos-outros-papeis.md): the router answers pages
12
- # and the scout reads code excerpts, where Claude Haiku 5.5 answered every request and led the no-index path; scope and
13
- # research pick the GPT-5.4 nano, as accurate there at about half the price and without the long reasoning of the mini.
9
+ # Matched as the last path/dot segment of the catalog id, so a short name also finds its LiteLLM alias
10
+ # ("vertex_ai.anthropic.<name>") and its OpenRouter id ("anthropic/<name>"). Chosen by measurement, 3 rounds per model,
11
+ # correctness first and price second (docs/research/2026-10-24-modelos-do-scout-e-dos-outros-papeis.md): the router
12
+ # answers pages and the scout reads code excerpts, where Claude Haiku answered every request and led the no-index path;
13
+ # scope and research pick the GPT nano, as accurate there at about half the price and without the long reasoning of the
14
+ # mini. The documentation prose takes Haiku as well: as many paragraphs judged correct as Sonnet within the noise, at a
15
+ # tenth of its price, while the nano invented details (docs/research/2026-11-05-modelo-e-instrucao-da-prosa.md).
14
16
  _CHOICES = {
15
17
  "router_model": ("chat", "claude-haiku-5-5"),
16
18
  "scope_model": ("chat", "gpt-5.4-nano"),
17
19
  "scout_model": ("chat", "claude-haiku-5-5"),
18
20
  "research_model": ("chat", "gpt-5.4-nano"),
21
+ "docs_model": ("chat", "claude-haiku-5-5"),
19
22
  "embedding_model": ("embedding", "text-embedding-3-small"),
20
23
  "rerank_model": ("rerank", "rerank-3-5"),
21
24
  }
@@ -23,7 +26,7 @@ RECOMMENDED_MODELS = {role: _CHOICES[role] for role in config.MODEL_ROLES}
23
26
 
24
27
 
25
28
  def _route_rank(model_id):
26
- """Vertex first (the owner's gateway is stable there), Bedrock only when nothing else serves the model."""
29
+ """Vertex first, Bedrock only when nothing else serves the model."""
27
30
  route = re.split(r"[/.:]", model_id)[0].lower()
28
31
  return 0 if route.startswith("vertex") else 2 if route.startswith("bedrock") else 1
29
32
 
package/model_health.py CHANGED
@@ -29,6 +29,8 @@ SAMPLE_CHARS = 160
29
29
  GROUP_ROWS = 20
30
30
  PURPOSES = ("index_embedding", "query_embedding", "rerank", "embedding_probe", "scope")
31
31
  _PATHS = ("/v1/chat/completions", "/v1/embeddings", "/v1/rerank")
32
+ _PURPOSE_ROLE = {"scope": "scope_model", "scout": "scout_model", "docs": "docs_model", "rerank": "rerank_model",
33
+ "index_embedding": "embedding_model", "query_embedding": "embedding_model"}
32
34
  _TOOL = contextvars.ContextVar("model_health_tool", default=None)
33
35
  _COLLECTED = contextvars.ContextVar("model_health_collected", default=None)
34
36
  _SCHEMA = set()
@@ -81,9 +83,13 @@ def classify(error):
81
83
  return "connection" if _CONNECTION.search(error or "") else "other"
82
84
 
83
85
 
84
- def role_of(model, cfg=None):
85
- """Name of the config field that selects `model` ('other' when none does)."""
86
+ def role_of(model, cfg=None, purpose=None):
87
+ """Name of the config field that selects `model` ('other' when none does). Several roles may hold the same model:
88
+ the role of the running `purpose` (usage_meter.purpose) wins over the first field in MODEL_ROLES order."""
86
89
  cfg = cfg if cfg is not None else config.load_config()
90
+ declared = _PURPOSE_ROLE.get(purpose)
91
+ if declared and cfg.get(declared) == model:
92
+ return declared
87
93
  return next((field for field in config.MODEL_ROLES if cfg.get(field) == model), "other")
88
94
 
89
95
 
@@ -107,7 +113,7 @@ def record(path, body, failure=None):
107
113
  return
108
114
  try:
109
115
  model = str((body or {}).get("model", "")) if isinstance(body, dict) else ""
110
- role = role_of(model)
116
+ role = role_of(model, purpose=usage_meter.purpose())
111
117
  now = time.time()
112
118
  text = error_text(failure) if failure is not None else None
113
119
  with project_store._LOCK, _db() as db:
package/model_upgrade.py CHANGED
@@ -15,7 +15,7 @@ import model_catalog
15
15
  import model_defaults
16
16
 
17
17
  DEFAULTS_VERSION = 2
18
- ROLES = ("router_model", "scope_model", "scout_model", "research_model")
18
+ ROLES = ("router_model", "scope_model", "scout_model", "research_model", "docs_model")
19
19
  REMIND_EVERY_S = 24 * 3600
20
20
 
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allansantos-dev/smart-tool",
3
- "version": "0.9.57",
3
+ "version": "0.9.65",
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",
package/pr_impact.py ADDED
@@ -0,0 +1,84 @@
1
+ """Impact report of a change set, in Markdown, for the description or a comment of a pull request.
2
+
3
+ It joins what Smart Tool already computes: the functions the diff touches and the tests to run (affected_tests), the
4
+ callers of each touched function (code_impact) and the documentation anchors the change leaves out of date (doc_scope).
5
+ Nothing is published: the agent pastes the report where it belongs.
6
+ """
7
+ import os
8
+
9
+ import affected_tests
10
+ import code_impact
11
+ import doc_scope
12
+
13
+ MAX_FUNCTIONS = 15
14
+ MAX_CALLERS = 8
15
+
16
+
17
+ def _callers(root, label, view_id):
18
+ """Callers of one touched function, or None when the function is new and nothing calls it yet."""
19
+ try:
20
+ found = code_impact.impact(root, label, view_id, depth=1, limit=MAX_CALLERS)
21
+ except ValueError:
22
+ return None
23
+ return found["callers"], found["counts"]["callers"]
24
+
25
+
26
+ def _stale(root, view_id, paths):
27
+ """Documentation findings that sit on the changed files, or the reason none could be computed."""
28
+ if not os.path.isdir(os.path.join(root, doc_scope.DOCS_DIR)):
29
+ return [], "docs/scope is not generated in this project; run project_manage action=docs generate=true."
30
+ found = doc_scope.check(root, view_id, limit=200)["findings"]
31
+ return [f for f in found if f["issue"] != "broken_link" and f["id"].rpartition("::")[0] in paths], None
32
+
33
+
34
+ def report(root, base="HEAD", limit=30, view_id=None):
35
+ """Impact of the changes since base.
36
+
37
+ Parameters: root (str) project folder; base (str) git revision; limit (int) rows per list; view_id (str or None).
38
+ Returns: dict with 'markdown' and the data behind it (touched, tests, stale_anchors, commands, run_all).
39
+ """
40
+ changes = affected_tests.affected(root, base, limit, view_id)
41
+ changed_code = set(changes["changed"]["code"])
42
+ touched = changes["touched_functions"][:MAX_FUNCTIONS]
43
+ callers = {label: _callers(root, label, view_id) for label in touched}
44
+ stale, stale_note = _stale(root, view_id, changed_code)
45
+ lines = [f"## Impact of the change against `{base}`", "",
46
+ f"{changes['counts']['changed_files']} changed file(s), {len(changes['touched_functions'])} touched "
47
+ f"function(s), {changes['counts']['tests']} test file(s) to run.", ""]
48
+ if changes["touched_functions"]:
49
+ lines += ["### Touched functions and who calls them", "", "| Function | Callers | Called from |", "|---|---|---|"]
50
+ for label in touched:
51
+ reached = callers[label]
52
+ if reached is None:
53
+ lines.append(f"| `{label}` | 0 | new: nothing calls it yet |")
54
+ continue
55
+ sites, total = reached
56
+ shown = ", ".join(f"`{s['function']}` ({s['path']}:{s['line']})" for s in sites)
57
+ more = f" (+{total - len(sites)} more)" if total > len(sites) else ""
58
+ lines.append(f"| `{label}` | {total} | {shown or '-'}{more} |")
59
+ if len(changes["touched_functions"]) > len(touched):
60
+ lines.append(f"\n{len(changes['touched_functions']) - len(touched)} more touched function(s) not listed.")
61
+ lines.append("")
62
+ lines += ["### Documentation left out of date", ""]
63
+ if stale_note:
64
+ lines += [stale_note, ""]
65
+ elif stale:
66
+ lines += [f"- `{f['id']}`: {f['issue'].replace('_', ' ')} ({f['file']}:{f['line']})" for f in stale]
67
+ lines += ["", "Regenerate with `project_manage action=docs generate=true` and review the prose of these entries.", ""]
68
+ else:
69
+ lines += ["No documented entry in the changed files is out of date.", ""]
70
+ lines += ["### Tests to run", ""]
71
+ if changes["tests"]:
72
+ lines += [f"- `{t['path']}`: {t['why']}" for t in changes["tests"]]
73
+ if changes.get("omitted"):
74
+ lines.append(f"- ... and {changes['omitted']['tests']} more")
75
+ lines += [""] + [f"`{c['command']}` (in `{c['cwd']}`)" if c.get("command") else f"{c['reason']} ({', '.join(c['files'])})"
76
+ for c in changes["commands"]]
77
+ else:
78
+ lines.append("No test reaches the changed code through imports or static calls.")
79
+ if changes["run_all"]:
80
+ lines += ["", "Run the whole suite: " + "; ".join(changes["run_all_reasons"]) + "."]
81
+ return {"base": base, "markdown": "\n".join(lines).rstrip("\n") + "\n", "touched": touched,
82
+ "callers": {label: (reached[1] if reached else 0) for label, reached in callers.items()},
83
+ "stale_anchors": stale, "stale_note": stale_note, "tests": changes["tests"],
84
+ "commands": changes["commands"], "run_all": changes["run_all"], "counts": changes["counts"]}
@@ -13,7 +13,7 @@ SCRIPT=r'''
13
13
  window.SmartInsights=(()=>{
14
14
  const $i=id=>document.getElementById(id);let sequence=0,storage=null,plan=null,comparison=null,compareRequest=0,diffRequest=0;
15
15
  const count=n=>Number(n||0).toLocaleString('en-US'),size=n=>n>=1048576?(n/1048576).toLocaleString('en-US',{maximumFractionDigits:2})+' MiB':(n/1024).toLocaleString('en-US',{maximumFractionDigits:1})+' KiB';
16
- const phaseNames={index_embedding:'Indexing',query_embedding:'Query',embedding_probe:'Model check',scope:'Scope',rerank:'Rerank',other:'Other step'};
16
+ const phaseNames={index_embedding:'Indexing',query_embedding:'Query',embedding_probe:'Model check',scope:'Scope',scout:'Scout',docs:'Documentation',rerank:'Rerank',other:'Other step'};
17
17
  function summary(host,rows){host.innerHTML=rows.map(([title,value,note])=>`<div><small>${esc(title)}</small><strong>${esc(value)}</strong>${note?'<small>'+esc(note)+'</small>':''}</div>`).join('')}
18
18
  function table(headers,rows){return '<table class="insights-table"><thead><tr>'+headers.map(x=>'<th>'+esc(x)+'</th>').join('')+'</tr></thead><tbody>'+rows.map(row=>'<tr>'+row.map(value=>'<td>'+value+'</td>').join('')+'</tr>').join('')+'</tbody></table>'}
19
19
  async function run(button,task){const seq=sequence,key=selected;button.disabled=true;try{await task(key,()=>seq===sequence&&key===selected)}catch(e){if(seq===sequence)message(e.message,true)}finally{if(seq===sequence)button.disabled=false}}
@@ -61,7 +61,7 @@ window.SmartMaps=(()=>{
61
61
  function clearSelection(){byId('maps-selected').textContent='Select an element';for(const id of ['maps-path','maps-state','maps-facts'])byId(id).textContent='';byId('maps-relation-title').textContent=mode==='calls'?'Static calls':'File dependencies';byId('maps-relations').replaceChildren();byId('maps-read').disabled=true}
62
62
  function reset(){++requestId;aborter?.abort();data=null;project=null;selectedNode=null;positions.clear();currentNodes=[];currentEdges=[];shown=[];shownEdges=[];globalLookup.clear();byId('maps-world').replaceChildren();byId('maps-color-legend').replaceChildren();byId('map-files').replaceChildren();byId('map-chunks').replaceChildren();byId('maps-diagnostic-list').replaceChildren();byId('map-view').replaceChildren(new Option('Current view or available legacy',''));byId('maps-folder').replaceChildren(new Option('All',''));byId('maps-symbol-picker').replaceChildren(new Option('Select…',''));byId('maps-search').value='';byId('map-info').textContent='Load the maps of this project. The analysis is local and creates no embeddings.';byId('maps-count').textContent='';byId('maps-empty').hidden=false;byId('maps-empty').textContent='Load a view to explore the three maps.';byId('load-map').disabled=false;byId('maps-popup-link').hidden=true;byId('maps-popup-link').removeAttribute('href');clearSelection()}
63
63
  async function load(view,restore=null){const key=selected,id=++requestId;aborter?.abort();aborter=new AbortController();byId('load-map').disabled=true;byId('map-info').textContent='Reading the snapshot and analyzing imports and calls…';try{const response=await fetch('/setup/projects',{method:'POST',headers:{'Content-Type':'application/json','X-Setup-Token':token},body:JSON.stringify({action:'graph',project_id:key,...(view?{view_id:view}:{})}),signal:aborter.signal});const result=await response.json();if(!response.ok)throw Error(result.error||'Could not load the maps.');if(id!==requestId||key!==selected)return;data=result;project=key;selectedNode=null;focus=false;positions.clear();byId('map-view').replaceChildren(...data.views.map(v=>new Option(v.label+(v.current?' (active)':'')+' · '+v.files+' files',v.view_id)));if(data.selected)byId('map-view').value=data.selected.view_id;byId('map-info').textContent=data.selected?`${data.selected.label} · ${data.counts.files} files · ${data.counts.parsed_files} analyzed. ${data.selected.current?'Indexed content; local changes may be pending.':'Stored snapshot. Current view: '+(data.current_view?.label||'not identified')+'.'}`:data.message;byId('maps-folder').replaceChildren(new Option('All',''),...Array.from(new Set(data.files.map(f=>f.group))).sort().map(f=>new Option(f,f)));byId('map-chunks').replaceChildren();renderDiagnostics();if(restore){byId('maps-search').value=restore.q||'';if([...byId('maps-folder').options].some(o=>o.value===restore.folder))byId('maps-folder').value=restore.folder;if(['60','120','250'].includes(restore.limit))byId('maps-limit').value=restore.limit;if(['module','status'].includes(restore.colors))byId('maps-color-mode').value=restore.colors}refreshGraph(true);if(restore?.node&&globalLookup.has(restore.node)){selectedNode=restore.node;focus=restore.focus==='1';refreshGraph(true)}}catch(e){if(e.name!=='AbortError'&&id===requestId){byId('map-info').textContent=e.message+' Use Load maps to try again.';message(e.message,true)}}finally{if(id===requestId)byId('load-map').disabled=false}}
64
- function renderDiagnostics(){const c=data.counts||{},lines=[`Local analysis of Java, Angular, Python, JavaScript/TypeScript, HTML/CSS and Markdown links. TXT and DOCX show up in coverage and in text search. ${c.parsed_files||0} of ${c.files||0} files were analyzed. Other languages and incomplete snapshots remain available in coverage.`,`${c.resolved_imports||0} resolved internal references; ${c.external_imports||0} external references; ${c.calls||0} call relations. Unresolved targets are a limited sample (${c.unresolved_calls||0} records in the analysis).`];if(data.truncated)lines.push('The analysis limits were reached. Filter by folder to explore the available part.');lines.push(...(data.diagnostics||[]).slice(0,60).map(d=>d.path+': '+d.reason));lines.push(...(data.unresolved||[]).slice(0,40).map(u=>u.path+':'+u.line+' · '+u.expression+' — '+u.reason));plainList(byId('maps-diagnostic-list'),lines)}
64
+ function renderDiagnostics(){const c=data.counts||{},lines=[`Local analysis of Java, Angular, Python, JavaScript/TypeScript, Go, HTML/CSS and Markdown links. TXT and DOCX show up in coverage and in text search. ${c.parsed_files||0} of ${c.files||0} files were analyzed. Other languages and incomplete snapshots remain available in coverage.`,`${c.resolved_imports||0} resolved internal references; ${c.external_imports||0} external references; ${c.calls||0} call relations. Unresolved targets are a limited sample (${c.unresolved_calls||0} records in the analysis).`];if(data.truncated)lines.push('The analysis limits were reached. Filter by folder to explore the available part.');lines.push(...(data.diagnostics||[]).slice(0,60).map(d=>d.path+': '+d.reason));lines.push(...(data.unresolved||[]).slice(0,40).map(u=>u.path+':'+u.line+' · '+u.expression+' — '+u.reason));plainList(byId('maps-diagnostic-list'),lines)}
65
65
  function prepare(){const files=new Map((data?.files||[]).map(f=>[f.path,f]));currentNodes=mode==='calls'?(data?.symbols||[]).map(s=>({...s,file:files.get(s.path),label:s.name==='callback'?'callback :'+s.start_line:s.name})): (data?.files||[]).map(f=>({...f,file:f,label:/^(index|styles|__init__)\./.test(f.path.split('/').pop())?f.path.split('/').slice(-2).join('/'):f.path.split('/').pop()}));globalLookup=new Map(currentNodes.map(n=>[n.id,n]));currentEdges=(mode==='calls'?data?.calls:data?.dependencies)||[];currentEdges=currentEdges.filter(e=>e.target&&globalLookup.has(e.source)&&globalLookup.has(e.target));}
66
66
  function chooseVisible(){const term=byId('maps-search').value.trim().toLocaleLowerCase(),folder=byId('maps-folder').value,limit=Number(byId('maps-limit').value);const degree=new Map();for(const e of currentEdges){degree.set(e.source,(degree.get(e.source)||0)+1);degree.set(e.target,(degree.get(e.target)||0)+1)}let list=currentNodes.filter(n=>(!folder||n.file?.group===folder)&&(!term||(n.path+' '+n.label).toLocaleLowerCase().includes(term)));if(focus&&selectedNode){const near=new Set([selectedNode]);for(const e of currentEdges){if(e.source===selectedNode)near.add(e.target);if(e.target===selectedNode)near.add(e.source)}list=currentNodes.filter(n=>near.has(n.id))}list.sort((a,b)=>mode==='coverage'?(b.lines||0)-(a.lines||0):((degree.get(b.id)||0)-(degree.get(a.id)||0)||a.path.localeCompare(b.path)));if(selectedNode&&globalLookup.has(selectedNode)&&list.some(n=>n.id===selectedNode))list=[globalLookup.get(selectedNode),...list.filter(n=>n.id!==selectedNode)];shown=list.slice(0,limit);const ids=new Set(shown.map(n=>n.id));shownEdges=currentEdges.filter(e=>ids.has(e.source)&&ids.has(e.target)).slice(0,1000);byId('maps-count').textContent=mode==='coverage'?`${shown.length} of ${list.length} files · area by lines`:`${shown.length} of ${list.length} nodes · ${shownEdges.length} visible relations${focus?' · selected neighborhood':''}`;byId('maps-empty').hidden=!!shown.length;byId('maps-empty').textContent=mode==='calls'?'No resolved functions in this selection. Check the diagnostics or choose another folder/view.':'No files match the filter.';byId('maps-symbol-picker').replaceChildren(new Option('Select…',''),...list.slice(0,1000).map(n=>new Option(n.label+' · '+n.path,n.id)));if(selectedNode)byId('maps-symbol-picker').value=selectedNode;}
67
67
  function layout(){const groups=new Map();for(const n of shown){const pathGroup=n.file?.group||'(root)',parts=pathGroup.split('/'),g=parts.slice(0,parts[0]==='src'?2:1).join('/');if(!groups.has(g))groups.set(g,[]);groups.get(g).push(n)}const sorted=[...groups].sort((a,b)=>b[1].length-a[1].length);const cols=Math.max(1,Math.ceil(Math.sqrt(sorted.length*1.4)));let i=0;for(const [group,nodes] of sorted){const step=mode==='calls'?580:440,cx=210+(i%cols)*step,cy=210+Math.floor(i/cols)*step;nodes.forEach((n,j)=>{if(!positions.has(n.id)){const ring=Math.floor(Math.sqrt(j)),angle=j*2.399963,rad=nodes.length===1?0:mode==='calls'?90+ring*105:50+ring*65;positions.set(n.id,{x:cx+Math.cos(angle)*rad,y:cy+Math.sin(angle)*rad})}});i++}}
package/redirect_rule.py CHANGED
@@ -19,6 +19,7 @@ import glob
19
19
  import os
20
20
  import re
21
21
  import shlex
22
+ import tempfile
22
23
  import time
23
24
 
24
25
  import index_scope
@@ -109,13 +110,20 @@ def count_files(path):
109
110
  return files, False
110
111
 
111
112
 
113
+ def system_temp():
114
+ """The system's temporary folder."""
115
+ return tempfile.gettempdir()
116
+
117
+
112
118
  def _in_project(target, cwd):
113
- """A registered project holds target, or target is inside the session's directory."""
119
+ """A registered project holds target, or target is inside the session's directory and not in the system's
120
+ temporary folder: a copy made there for a measurement or a build is gone soon, and the redirected smart_search
121
+ would register and index it."""
114
122
  key = os.path.normcase(os.path.abspath(target)) + os.sep
115
123
  if any(key.startswith(os.path.normcase(os.path.abspath(p["root"])).rstrip(os.sep) + os.sep)
116
124
  for p in project_store.all_projects()):
117
125
  return True
118
- return bool(cwd) and index_scope._within_root(cwd, target)
126
+ return bool(cwd) and index_scope._within_root(cwd, target) and not index_scope._within_root(system_temp(), target)
119
127
 
120
128
 
121
129
  def _has_files(target):
@@ -404,16 +412,20 @@ def _bash(command, cwd, powershell=False):
404
412
 
405
413
 
406
414
  def _shell(command, cwd, state, powershell, depth):
407
- """(decision, target, reason) of one shell script; substitutions and `bash -c`/`powershell -Command` scripts are
408
- decided with the same state (folder, variables, loop variables)."""
415
+ """(decision, target, reason) of one shell script; `bash -c`/`powershell -Command` scripts are decided with the
416
+ same state (folder, variables, loop variables), and each substitution with the state of the segment it sits in,
417
+ as a subshell whose `cd` does not leak out."""
409
418
  verdict = ("allow", None, "No content search over a folder.")
410
419
  text, inner = _substitutions(_strip_heredocs(command), powershell)
411
- for script in inner if depth < MAX_NESTING else ():
412
- found = _shell(script, cwd, state, powershell, depth + 1)
413
- if found[0] == "redirect":
414
- return found
420
+ pending = inner if depth < MAX_NESTING else []
415
421
  variables, lists, listing = state["variables"], state["lists"], None
416
422
  for segment, after_pipe in segments(text):
423
+ count = segment.count(LISTING) + segment.count(SUBSTITUTION)
424
+ for script in pending[:count]:
425
+ found = _shell(script, cwd, {**state}, powershell, depth + 1)
426
+ if found[0] == "redirect":
427
+ return found
428
+ pending = pending[count:]
417
429
  words = _split(segment, powershell)
418
430
  if words[:2] == ["while", "read"]:
419
431
  name = next((t for t in words[2:] if not t.startswith("-")), None)
package/setup_ui.py CHANGED
@@ -85,6 +85,7 @@ def status_payload():
85
85
  "scope_model": cfg.get("scope_model", ""),
86
86
  "scout_model": cfg.get("scout_model", ""),
87
87
  "research_model": cfg.get("research_model", ""),
88
+ "docs_model": cfg.get("docs_model", ""),
88
89
  "research_max_iterations": cfg.get("research_max_iterations", config.DEFAULT_CONFIG["research_max_iterations"]),
89
90
  "quick_search_timeout_s": cfg.get("quick_search_timeout_s", config.DEFAULT_CONFIG["quick_search_timeout_s"]),
90
91
  "site_memory_similarity_threshold": cfg.get("site_memory_similarity_threshold", config.DEFAULT_CONFIG["site_memory_similarity_threshold"]),
@@ -140,6 +141,7 @@ def handle_models_get():
140
141
  "scope_model": cfg.get("scope_model", ""),
141
142
  "scout_model": cfg.get("scout_model", ""),
142
143
  "research_model": cfg.get("research_model", ""),
144
+ "docs_model": cfg.get("docs_model", ""),
143
145
  "research_max_iterations": cfg.get("research_max_iterations", config.DEFAULT_CONFIG["research_max_iterations"]),
144
146
  "quick_search_timeout_s": cfg.get("quick_search_timeout_s", config.DEFAULT_CONFIG["quick_search_timeout_s"]),
145
147
  "site_memory_similarity_threshold": cfg.get("site_memory_similarity_threshold", config.DEFAULT_CONFIG["site_memory_similarity_threshold"]),
@@ -252,6 +254,10 @@ def handle_integration_get():
252
254
  doc_mode, doc_error = config.doc_mode(), ""
253
255
  except ValueError as exc:
254
256
  doc_mode, doc_error = "", str(exc)
257
+ try:
258
+ comment_mode, comment_error = config.comment_mode(), ""
259
+ except ValueError as exc:
260
+ comment_mode, comment_error = "", str(exc)
255
261
  try:
256
262
  duplicate_mode, duplicate_error = config.duplicate_mode(), ""
257
263
  except ValueError as exc:
@@ -270,7 +276,8 @@ def handle_integration_get():
270
276
  stored, patterns_error = block_patterns._empty(), str(exc)
271
277
  return {"daemon_url": setup_origin(), "clients": clients, "hook_mode": mode, "hook_mode_error": mode_error,
272
278
  "hook_modes": list(config.HOOK_MODES), "doc_mode": doc_mode, "doc_mode_error": doc_error,
273
- "doc_modes": list(config.DOC_MODES), "duplicate_mode": duplicate_mode,
279
+ "doc_modes": list(config.DOC_MODES), "comment_mode": comment_mode, "comment_mode_error": comment_error,
280
+ "comment_modes": list(config.COMMENT_MODES), "duplicate_mode": duplicate_mode,
274
281
  "duplicate_mode_error": duplicate_error, "duplicate_modes": list(config.DUPLICATE_MODES),
275
282
  "dependency_mode": dependency_mode, "dependency_mode_error": dependency_error,
276
283
  "dependency_modes": list(config.DEPENDENCY_MODES),
@@ -292,9 +299,9 @@ def handle_integration_save(body):
292
299
  except (OSError, ValueError) as exc:
293
300
  raise SetupError(str(exc))
294
301
  return handle_integration_get()
295
- if isinstance(body, dict) and body.get("action") in ("hook_mode", "doc_mode", "duplicate_mode", "dependency_mode", "pattern_proposals"):
302
+ if isinstance(body, dict) and body.get("action") in ("hook_mode", "doc_mode", "comment_mode", "duplicate_mode", "dependency_mode", "pattern_proposals"):
296
303
  action = body["action"]
297
- allowed = {"hook_mode": config.HOOK_MODES, "doc_mode": config.DOC_MODES,
304
+ allowed = {"hook_mode": config.HOOK_MODES, "doc_mode": config.DOC_MODES, "comment_mode": config.COMMENT_MODES,
298
305
  "duplicate_mode": config.DUPLICATE_MODES, "dependency_mode": config.DEPENDENCY_MODES,
299
306
  "pattern_proposals": config.PATTERN_PROPOSAL_MODES}[action]
300
307
  if body.get("mode") not in allowed:
@@ -451,6 +458,7 @@ _MODEL_FIELDS = {
451
458
  "scope_model": "chat",
452
459
  "scout_model": "chat",
453
460
  "research_model": "chat",
461
+ "docs_model": "chat",
454
462
  "embedding_model": "embedding",
455
463
  "rerank_model": "rerank",
456
464
  }
@@ -783,6 +791,7 @@ __I18N__
783
791
  </div>
784
792
  <div class="field"><label for="sel-scout">Code scout (optional)</label><span class="explain">smart_scout: writes a short answer over the lines it read and keeps only the ones that answer. Empty returns the literal lines without a model.</span><input id="sel-scout" list="dl-scout" autocomplete="off" spellcheck="false"><datalist id="dl-scout"></datalist></div>
785
793
  <div class="field"><label for="sel-research">Web research</label><span class="explain">Used by web_search with depth=research. Empty uses the router model.</span><input id="sel-research" list="dl-research" autocomplete="off" spellcheck="false"><datalist id="dl-research"></datalist></div>
794
+ <div class="field"><label for="sel-docs">Docs model</label><span class="explain">Writes the prose of the generated documentation (project_manage action=docs write_prose=true); each paragraph is checked against the code before it is written.</span><input id="sel-docs" list="dl-docs" autocomplete="off" spellcheck="false"><datalist id="dl-docs"></datalist></div>
786
795
  <details class="more">
787
796
  <summary>Advanced web research limits</summary>
788
797
  <div class="pair" style="margin-top:12px">
@@ -1135,6 +1144,7 @@ async function loadModels() {
1135
1144
  fillSuggestions($("sel-scope"), data.chat, data.current.scope_model);
1136
1145
  fillSuggestions($("sel-scout"), data.chat_lightweight.length ? data.chat_lightweight : data.chat, data.current.scout_model);
1137
1146
  fillSuggestions($("sel-research"), data.chat, data.current.research_model);
1147
+ fillSuggestions($("sel-docs"), data.chat, data.current.docs_model);
1138
1148
  fillSuggestions($("sel-embedding"), data.embedding, data.current.embedding_model);
1139
1149
  fillSuggestions($("sel-rerank"), data.rerank, data.current.rerank_model);
1140
1150
  fillNumber("num-research-iterations", "research-iterations-hint", data.ranges.research_max_iterations, data.current.research_max_iterations, data.recommended.research_max_iterations, "");
@@ -1211,7 +1221,7 @@ $("btn-save-models").addEventListener("click", async () => {
1211
1221
  setMsg("models-msg", "", "Saving…");
1212
1222
  try {
1213
1223
  await post("/setup/models", {
1214
- router_model: $("sel-router").value, scope_model: $("sel-scope").value, scout_model: $("sel-scout").value, research_model: $("sel-research").value,
1224
+ router_model: $("sel-router").value, scope_model: $("sel-scope").value, scout_model: $("sel-scout").value, research_model: $("sel-research").value, docs_model: $("sel-docs").value,
1215
1225
  research_max_iterations: Number($("num-research-iterations").value), quick_search_timeout_s: Number($("num-quick-timeout").value),
1216
1226
  site_memory_similarity_threshold: Number($("num-site-memory-threshold").value),
1217
1227
  embedding_model: $("sel-embedding").value, rerank_model: $("sel-rerank").value,
@@ -1302,9 +1312,14 @@ const RULES = [
1302
1312
  ["off", "Off", "No routing; agents use their native tools as usual."]] },
1303
1313
  { key: "doc_mode", title: "Documentation on edit", applies: "Applies on the next edit.",
1304
1314
  intro: "Checks the public functions an edit touches. Private, nested and override functions are exempt, as in pydocstyle, eslint-plugin-jsdoc and Checkstyle. A documented function comes up again only when its signature changes.",
1305
- options: [["remind", "Remind", "The edit runs; the agent is told which touched functions lack a docstring.", true],
1306
- ["require", "Require", "An edit that leaves a touched function without a docstring is blocked until it adds one."],
1315
+ options: [["require", "Require", "An edit that leaves a touched function without a docstring is blocked until it adds one.", true],
1316
+ ["remind", "Remind", "The edit runs; the agent is told which touched functions lack a docstring."],
1307
1317
  ["off", "Off", "No documentation checks."]] },
1318
+ { key: "comment_mode", title: "Comments in the wrong place", applies: "Applies on the next edit.",
1319
+ intro: "Checks the comments an edit adds: commented-out code, ticket or history tags, a loose block above a function instead of its docstring, and a long block inside a function body. A short comment that says why stays allowed.",
1320
+ options: [["require", "Require", "An edit that adds a comment in the wrong place is blocked until it is fixed.", true],
1321
+ ["remind", "Remind", "The edit runs; the agent is told which comments are misplaced."],
1322
+ ["off", "Off", "No comment checks."]] },
1308
1323
  { key: "duplicate_mode", title: "Duplicate functions on edit", applies: "Applies on the next edit.",
1309
1324
  intro: "Compares the functions an edit writes with the indexed code: identical bodies, and near-identical ones with only local names changed. It never blocks.",
1310
1325
  options: [["warn", "Warn", "The edit runs; the agent is told when a function copies one already in the project.", true],