@allansantos-dev/smart-tool 0.9.78 → 0.9.79
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 +12 -0
- package/README.md +3 -3
- package/affected_tests.py +4 -0
- package/code_graph.py +39 -17
- package/code_graph_go.py +6 -6
- package/code_graph_java.mjs +10 -9
- package/code_graph_js.cjs +8 -8
- package/code_impact.py +3 -1
- package/doc_scope.py +1 -1
- package/duplicates.py +1 -1
- package/layers.py +3 -3
- package/package.json +1 -1
- package/pr_impact.py +2 -0
- package/version.py +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.79 - beta
|
|
4
|
+
|
|
5
|
+
- A graph cut by its limits says what it left out: `left_out` with the files, symbols and call or import relations
|
|
6
|
+
dropped, and a sentence in the note, in the graph answers (`project_manage action=graph`), `layers`, `docs generate`,
|
|
7
|
+
`duplicates`, the affected tests and the PR impact. Files skipped by the 24 MB analysis text limit count with the
|
|
8
|
+
files over the file limit. The graph cache is rebuilt once. The limits stay as they are: doubling them took the
|
|
9
|
+
build of a 6,133-file project from 23 s to 57 s and its memory from 0.7 GB to 1.4 GB
|
|
10
|
+
(`docs/research/2026-11-15-tetos-do-grafo-medidos.md`). The gateway rerank gain over the hybrid order was measured on
|
|
11
|
+
the gold set (first place 35 to 39 of 43, MRR@5 0.868 to 0.919, 1.4 s median per search), so rerank stays optional
|
|
12
|
+
(`docs/research/2026-11-15-ganho-do-rerank-medido.md`). Tests: `tests/test_code_graph_limits.py`,
|
|
13
|
+
`tests/test_affected_tests.py`, `tests/test_pr_impact.py`.
|
|
14
|
+
|
|
3
15
|
## 0.9.78 - beta
|
|
4
16
|
|
|
5
17
|
- A registered project whose folder no longer exists is junk: `project_manage action=junk` lists it and the junk
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ registered as the `playwright` server where this machine lets a browser be drive
|
|
|
17
17
|
An optional hook routes the agent's native Grep/Glob/Read/Bash/WebSearch/WebFetch calls to these tools when they
|
|
18
18
|
are cheaper, or just tells the agent what Smart Tool would do.
|
|
19
19
|
|
|
20
|
-
**Status:** 0.9.
|
|
20
|
+
**Status:** 0.9.79 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
|
|
21
21
|
|
|
22
22
|
## How it works
|
|
23
23
|
|
|
@@ -83,7 +83,7 @@ gateway such as Ollama, nothing about your code leaves the machine.
|
|
|
83
83
|
## Install
|
|
84
84
|
|
|
85
85
|
```powershell
|
|
86
|
-
npx @allansantos-dev/smart-tool@0.9.
|
|
86
|
+
npx @allansantos-dev/smart-tool@0.9.79 install
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Updates install themselves, on by default: the tray checks npm when it starts (at logon) and every 24 h, and when there
|
|
@@ -390,7 +390,7 @@ fails to load is listed in the setup screen with its error and does not affect t
|
|
|
390
390
|
## Uninstall
|
|
391
391
|
|
|
392
392
|
```powershell
|
|
393
|
-
npx @allansantos-dev/smart-tool@0.9.
|
|
393
|
+
npx @allansantos-dev/smart-tool@0.9.79 uninstall [--target DIR] [--keep-data]
|
|
394
394
|
```
|
|
395
395
|
|
|
396
396
|
It asks nothing and opens no window. It stops the tray and the daemon, removes the logon task, the hook entries of Smart
|
package/affected_tests.py
CHANGED
|
@@ -413,6 +413,10 @@ def affected(root, base="HEAD", limit=30, view_id=None):
|
|
|
413
413
|
"view": (data.get("selected") or {}).get("label"),
|
|
414
414
|
"note": NOTE,
|
|
415
415
|
}
|
|
416
|
+
if data.get("truncated"):
|
|
417
|
+
result["truncated"] = True
|
|
418
|
+
result["left_out"] = data["left_out"]
|
|
419
|
+
result["note"] += " " + code_graph.left_out_sentence(data) + " Tests beyond the cut are not listed."
|
|
416
420
|
if len(ordered) > limit:
|
|
417
421
|
result["omitted"] = {"tests": len(ordered) - limit}
|
|
418
422
|
if not changes:
|
package/code_graph.py
CHANGED
|
@@ -23,7 +23,7 @@ import web_document_graph
|
|
|
23
23
|
import code_graph_go
|
|
24
24
|
import document_text
|
|
25
25
|
|
|
26
|
-
VERSION =
|
|
26
|
+
VERSION = 6
|
|
27
27
|
SOURCE_EXTENSIONS = ('.py','.go','.mod','.java','.js','.jsx','.ts','.tsx','.mjs','.cjs','.mts','.cts','.json','.html','.htm','.css','.scss','.sass','.less','.md','.markdown')
|
|
28
28
|
MAX_OVERLAY_BYTES = 5 * 1024 * 1024
|
|
29
29
|
MAX_FILES = 3000
|
|
@@ -71,9 +71,10 @@ def _snapshot(path):
|
|
|
71
71
|
columns = {row[1] for row in conn.execute('PRAGMA table_info(manifest)')}
|
|
72
72
|
size = 'm.size' if 'size' in columns else 'NULL'
|
|
73
73
|
mtime = 'm.mtime_ns' if 'mtime_ns' in columns else 'NULL'
|
|
74
|
-
records = conn.execute(f'SELECT m.path,m.hash,{size},{mtime},count(c.id),max(c.end_line) FROM manifest m LEFT JOIN chunks c ON c.path=m.path GROUP BY m.path ORDER BY m.path LIMIT ?', (MAX_FILES
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
records = conn.execute(f'SELECT m.path,m.hash,{size},{mtime},count(c.id),max(c.end_line) FROM manifest m LEFT JOIN chunks c ON c.path=m.path GROUP BY m.path ORDER BY m.path LIMIT ?', (MAX_FILES,)).fetchall()
|
|
75
|
+
total = conn.execute('SELECT count(*) FROM manifest').fetchone()[0]
|
|
76
|
+
files, sources, diagnostics, used, over_text = [], {}, [], 0, 0
|
|
77
|
+
for original, digest, byte_size, stamp, chunks, line_count in records:
|
|
77
78
|
file_path = original.replace('\\','/')
|
|
78
79
|
record = {'id':file_path,'path':file_path,'hash':digest,'size':byte_size,'mtime_ns':stamp,
|
|
79
80
|
'chunks':chunks,'lines':line_count or 0,'group':posixpath.dirname(file_path) or '(root)',
|
|
@@ -87,10 +88,11 @@ def _snapshot(path):
|
|
|
87
88
|
diagnostics.append({'path':file_path,'reason':error})
|
|
88
89
|
elif used+len(text) > MAX_TEXT:
|
|
89
90
|
diagnostics.append({'path':file_path,'reason':'Content limit for this analysis reached.'})
|
|
91
|
+
over_text += 1
|
|
90
92
|
else:
|
|
91
93
|
used += len(text)
|
|
92
94
|
sources[file_path] = text
|
|
93
|
-
return files, sources, diagnostics,
|
|
95
|
+
return files, sources, diagnostics, max(total-MAX_FILES, 0) + over_text
|
|
94
96
|
finally:
|
|
95
97
|
conn.close()
|
|
96
98
|
|
|
@@ -247,7 +249,8 @@ def _python_graph(sources):
|
|
|
247
249
|
visit_scope(tree)
|
|
248
250
|
if used_module:symbols.append(module)
|
|
249
251
|
return {'symbols':symbols,'dependencies':dependencies[:MAX_EDGES],'calls':calls,'unresolved':unresolved,
|
|
250
|
-
'diagnostics':diagnostics,'parsed':list(trees),
|
|
252
|
+
'diagnostics':diagnostics,'parsed':list(trees),
|
|
253
|
+
'left_out':{'symbols':dropped['symbols'],'edges':dropped['calls']+max(len(dependencies)-MAX_EDGES,0)}}
|
|
251
254
|
|
|
252
255
|
|
|
253
256
|
NODE_HEAP_MB = (1024, 4096)
|
|
@@ -298,15 +301,22 @@ def _analyze(path):
|
|
|
298
301
|
return _analyze_sources(*_snapshot(path))
|
|
299
302
|
|
|
300
303
|
|
|
301
|
-
def _analyze_sources(files,sources,diagnostics,
|
|
304
|
+
def _analyze_sources(files,sources,diagnostics,files_left_out):
|
|
305
|
+
"""Analyzes the sources of one snapshot. `left_out` counts what the limits cut: files the snapshot never read
|
|
306
|
+
(files_left_out), symbols and call or import occurrences each analyzer dropped at its own cap, and what the merged
|
|
307
|
+
graph drops at the global caps (symbols past MAX_SYMBOLS, calls whose endpoint was dropped, relations past MAX_EDGES).
|
|
308
|
+
The counts are lower bounds: what lies inside left-out files, and the calls made inside functions an analyzer
|
|
309
|
+
dropped, are never seen and not counted."""
|
|
302
310
|
merged={'symbols':[],'dependencies':[],'calls':[],'unresolved':[],'diagnostics':diagnostics,'parsed':[]}
|
|
311
|
+
left_out={'files':files_left_out,'symbols':0,'edges':0}
|
|
303
312
|
retryable=False
|
|
304
313
|
for output in (_python_graph(sources),_javascript_graph(sources,[f['path'] for f in files]),_java_graph(sources),code_graph_go.analyze(sources,ANALYZER_LIMITS),web_document_graph.analyze(sources,[f['path'] for f in files])):
|
|
305
314
|
for key in merged:merged[key].extend(output.get(key,[]))
|
|
306
|
-
|
|
315
|
+
for kind,count in output.get('left_out',{}).items():left_out[kind]+=count
|
|
307
316
|
retryable |= output.get('retryable',False)
|
|
308
|
-
|
|
309
|
-
|
|
317
|
+
kept_symbols=merged['symbols'][:MAX_SYMBOLS]
|
|
318
|
+
left_out['symbols']+=len(merged['symbols'])-len(kept_symbols)
|
|
319
|
+
by_id={sym['id']:sym for sym in kept_symbols}
|
|
310
320
|
# Relações repetidas preservam contagem e locais de chamada sem poluir o desenho.
|
|
311
321
|
def collapse(rows,fields):
|
|
312
322
|
result={}
|
|
@@ -316,14 +326,17 @@ def _analyze_sources(files,sources,diagnostics,truncated):
|
|
|
316
326
|
result[key]['count']+=1
|
|
317
327
|
if len(result[key]['lines'])<20:result[key]['lines'].append(row.get('line'))
|
|
318
328
|
return list(result.values())
|
|
329
|
+
linked=[r for r in merged['calls'] if r['source'] in by_id and r['target'] in by_id]
|
|
330
|
+
left_out['edges']+=len(merged['calls'])-len(linked)
|
|
319
331
|
deps=collapse(merged['dependencies'],('source','target','specifier','kind'))
|
|
320
|
-
calls=collapse(
|
|
332
|
+
calls=collapse(linked,('source','target','kind'))
|
|
333
|
+
left_out['edges']+=sum(r['count'] for r in deps[MAX_EDGES:])+sum(r['count'] for r in calls[MAX_EDGES:])
|
|
321
334
|
supported=set(merged['parsed'])
|
|
322
335
|
for file in files:file['analysis']='parsed' if file['path'] in supported else 'not_analyzed'
|
|
323
|
-
return {'files':files,'symbols':
|
|
336
|
+
return {'files':files,'symbols':kept_symbols,
|
|
324
337
|
'dependencies':deps[:MAX_EDGES],'calls':calls[:MAX_EDGES],
|
|
325
338
|
'unresolved':merged['unresolved'][:1000],'diagnostics':merged['diagnostics'],
|
|
326
|
-
'truncated':
|
|
339
|
+
'truncated':any(left_out.values()),'left_out':left_out,'retryable':retryable,
|
|
327
340
|
'counts':{'files':len(files),'parsed_files':len(supported),'symbols':len(merged['symbols']),
|
|
328
341
|
'resolved_imports':sum(bool(r['target']) for r in deps),
|
|
329
342
|
'external_imports':sum(r['resolution']=='external' for r in deps),
|
|
@@ -353,13 +366,21 @@ def _focus(data,file_path):
|
|
|
353
366
|
return data
|
|
354
367
|
|
|
355
368
|
|
|
369
|
+
def left_out_sentence(data):
|
|
370
|
+
"""One sentence with how much the analysis limits cut from the graph, or None when nothing was left out."""
|
|
371
|
+
if not data.get('truncated'):
|
|
372
|
+
return None
|
|
373
|
+
left=data['left_out']
|
|
374
|
+
return (f"Graph cut by analysis limits: {left['files']:,} files, {left['symbols']:,} symbols and {left['edges']:,} call and import relations left out"
|
|
375
|
+
+' (lower bounds: what lies inside left-out files and functions is not counted).')
|
|
376
|
+
|
|
377
|
+
|
|
356
378
|
def _by_file(data):
|
|
357
379
|
by_file={}
|
|
358
380
|
for symbol in data['symbols']:
|
|
359
381
|
by_file.setdefault(symbol['path'],[]).append(symbol)
|
|
360
382
|
parsed={f['path'] for f in data['files'] if f.get('analysis')=='parsed'}
|
|
361
|
-
|
|
362
|
-
return {'symbols':by_file,'parsed':parsed,'note':note}
|
|
383
|
+
return {'symbols':by_file,'parsed':parsed,'note':left_out_sentence(data)}
|
|
363
384
|
|
|
364
385
|
|
|
365
386
|
def _disk_path(view_path):
|
|
@@ -493,6 +514,7 @@ def build(root,view_id=None,storage_id=None,file_path=None,background=False):
|
|
|
493
514
|
file['status']='indexed' if (current.st_mtime_ns,current.st_size)==(file['mtime_ns'],file['size']) else 'pending'
|
|
494
515
|
except OSError:file['status']='missing'
|
|
495
516
|
file.pop('mtime_ns',None)
|
|
517
|
+
if data['truncated']:data['note']=left_out_sentence(data)
|
|
496
518
|
data.update(views=inventory['views'],selected=inventory['selected'],current_view=inventory['current_view'],
|
|
497
519
|
message=inventory['message'],read_only=True,source='indexed_snapshot',generated_at=time.time(),
|
|
498
520
|
limits={'files':MAX_FILES,'symbols':MAX_SYMBOLS,'edges':MAX_EDGES,'display_nodes_default':120},
|
|
@@ -601,7 +623,7 @@ def build_overlay(root,changes,view_id=None,shared=False):
|
|
|
601
623
|
if not inventory['selected']:
|
|
602
624
|
return {**inventory,'symbols':[],'dependencies':[],'calls':[],'diagnostics':[],'counts':{},'files':[]}
|
|
603
625
|
path=inventory['selected']['path'];stat=os.stat(path)
|
|
604
|
-
files,sources,diagnostics,
|
|
626
|
+
files,sources,diagnostics,files_left_out=_snapshot(path)
|
|
605
627
|
by_path={f['path']:f for f in files};overlaid=[]
|
|
606
628
|
for rel,status in sorted(changes.items()):
|
|
607
629
|
full=os.path.join(root,rel)
|
|
@@ -624,7 +646,7 @@ def build_overlay(root,changes,view_id=None,shared=False):
|
|
|
624
646
|
if not _ANALYSIS_SLOTS.acquire(timeout=3):
|
|
625
647
|
raise RuntimeError('Two map analyses are in progress. Wait for them to finish and retry.')
|
|
626
648
|
try:
|
|
627
|
-
cached=_analyze_sources(list(by_path.values()),sources,diagnostics,
|
|
649
|
+
cached=_analyze_sources(list(by_path.values()),sources,diagnostics,files_left_out)
|
|
628
650
|
finally:
|
|
629
651
|
_ANALYSIS_SLOTS.release()
|
|
630
652
|
if not cached['retryable']:
|
package/code_graph_go.py
CHANGED
|
@@ -352,7 +352,7 @@ def _default_alias(spec):
|
|
|
352
352
|
|
|
353
353
|
def analyze(sources, limits=None):
|
|
354
354
|
"""Imports, symbols (functions, methods, types) and resolved calls of the Go files in sources (path -> text).
|
|
355
|
-
limits caps symbols and edges ({'symbols': n, 'edges': n});
|
|
355
|
+
limits caps symbols and edges ({'symbols': n, 'edges': n}); 'left_out' counts the symbols and calls dropped at the caps."""
|
|
356
356
|
limits = limits or {}
|
|
357
357
|
max_symbols, max_edges = limits.get("symbols", float("inf")), limits.get("edges", float("inf"))
|
|
358
358
|
go_files = {path: text for path, text in sources.items() if path.endswith(".go")}
|
|
@@ -428,7 +428,7 @@ def _symbols_and_calls(files, max_symbols, max_edges):
|
|
|
428
428
|
target = imports_of[path].get(alias)
|
|
429
429
|
return (target, name) if target else None
|
|
430
430
|
|
|
431
|
-
index, results, symbols, calls, unresolved,
|
|
431
|
+
index, results, symbols, calls, unresolved, left_out = {}, {}, [], [], [], {"symbols": 0, "edges": 0}
|
|
432
432
|
for path, info in files.items():
|
|
433
433
|
tables = index.setdefault(key_of(path), {"funcs": {}, "methods": {}, "types": {}, "fields": {},
|
|
434
434
|
"embedded": {}})
|
|
@@ -449,7 +449,7 @@ def _symbols_and_calls(files, max_symbols, max_edges):
|
|
|
449
449
|
symbol_id = f"{symbol_id}@{decl['start']}"
|
|
450
450
|
seen.add(symbol_id)
|
|
451
451
|
if len(symbols) >= max_symbols:
|
|
452
|
-
|
|
452
|
+
left_out["symbols"] += 1
|
|
453
453
|
continue
|
|
454
454
|
symbol = {"id": symbol_id, "path": path, "name": name, "kind": decl["kind"], "language": "go",
|
|
455
455
|
"start_line": decl["start"], "end_line": decl["end"]}
|
|
@@ -484,7 +484,7 @@ def _symbols_and_calls(files, max_symbols, max_edges):
|
|
|
484
484
|
calls.append({"source": decl["symbol"]["id"], "target": call["target"]["id"],
|
|
485
485
|
"line": call["line"], "kind": "reference", "resolution": "static"})
|
|
486
486
|
else:
|
|
487
|
-
|
|
487
|
+
left_out["edges"] += 1
|
|
488
488
|
continue
|
|
489
489
|
if call["target"] is None:
|
|
490
490
|
if len(unresolved) < 1000:
|
|
@@ -494,8 +494,8 @@ def _symbols_and_calls(files, max_symbols, max_edges):
|
|
|
494
494
|
calls.append({"source": decl["symbol"]["id"], "target": call["target"]["id"],
|
|
495
495
|
"line": call["line"], "kind": "call", "resolution": "static"})
|
|
496
496
|
else:
|
|
497
|
-
|
|
498
|
-
return {"symbols": symbols, "calls": calls, "unresolved": unresolved, "
|
|
497
|
+
left_out["edges"] += 1
|
|
498
|
+
return {"symbols": symbols, "calls": calls, "unresolved": unresolved, "left_out": left_out}
|
|
499
499
|
|
|
500
500
|
|
|
501
501
|
def _body_calls(path, tokens, decl, index, imported, own, results, resolve_type, member):
|
package/code_graph_java.mjs
CHANGED
|
@@ -10,15 +10,15 @@ if(nodeModule.registerHooks){const bundle=new URL('chevrotain/lib/chevrotain.mjs
|
|
|
10
10
|
const {parse}=await import(new URL('java-parser/src/index.js',modules).href);
|
|
11
11
|
const input=JSON.parse(fs.readFileSync(0,'utf8'));
|
|
12
12
|
const symbols=[],dependencies=[],calls=[],unresolved=[],diagnostics=[],units=[],classes=new Map(),methodNodes=new Map(),kids=new WeakMap();
|
|
13
|
-
const {symbols:MAX_SYMBOLS,edges:MAX_EDGES}=input.limits;
|
|
14
|
-
function room(list,max){if(list.length<max)return true;
|
|
13
|
+
const {symbols:MAX_SYMBOLS,edges:MAX_EDGES}=input.limits;const leftOut={symbols:0,edges:0};
|
|
14
|
+
function room(list,max,kind){if(list.length<max)return true;leftOut[kind]++;return false}
|
|
15
15
|
const NO_CHILDREN=Object.freeze([]);
|
|
16
16
|
function children(n){const groups=n?.children;if(!groups)return NO_CHILDREN;let list=kids.get(n);if(list)return list;list=[];for(const key in groups)for(const child of groups[key])if(child.children)list.push(child);kids.set(n,list);return list}
|
|
17
17
|
function all(n,name,stop=false){const result=[];function visit(node){if(node?.name===name){result.push(node);if(stop)return}for(const child of children(node))visit(child)}visit(n);return result}
|
|
18
18
|
function first(n,name){return all(n,name,true)[0]}
|
|
19
19
|
function identifiers(n){const out=[];function visit(node){if(node?.children)for(const [key,items] of Object.entries(node.children))for(const child of items){if(child.children)visit(child);else if(key==='Identifier')out.push(child)}}visit(n);return out.sort((a,b)=>a.startOffset-b.startOffset)}
|
|
20
20
|
function text(u,n){return n?.location?u.text.slice(n.location.startOffset,n.location.endOffset+1):''}
|
|
21
|
-
function addSymbol(u,n,name,kind){if(!room(symbols,MAX_SYMBOLS))return null;const s={id:u.path+'::'+name+'@'+n.location.startLine+':'+n.location.startOffset,path:u.path,name,kind,language:'java',start_line:n.location.startLine,end_line:n.location.endLine};symbols.push(s);return s}
|
|
21
|
+
function addSymbol(u,n,name,kind){if(!room(symbols,MAX_SYMBOLS,'symbols'))return null;const s={id:u.path+'::'+name+'@'+n.location.startLine+':'+n.location.startOffset,path:u.path,name,kind,language:'java',start_line:n.location.startLine,end_line:n.location.endLine};symbols.push(s);return s}
|
|
22
22
|
const classKinds=new Set(['normalClassDeclaration','normalInterfaceDeclaration','enumDeclaration','recordDeclaration']);
|
|
23
23
|
for(const file of input.files){try{const tree=parse(file.text),pkg=first(tree,'packageDeclaration'),unit={...file,tree,package:pkg?identifiers(pkg).map(t=>t.image).join('.'): '',imports:[],classes:[]};
|
|
24
24
|
for(const n of all(tree,'importDeclaration')){const raw=text(unit,n).replace(/^import\s+/,'').replace(/;\s*$/,'').trim(),stat=raw.startsWith('static '),spec=(stat?raw.slice(7):raw).replace(/\s+/g,'');unit.imports.push({spec,static:stat,line:n.location.startLine})}
|
|
@@ -38,18 +38,18 @@ for(const unit of units){
|
|
|
38
38
|
function walk(n,cls=null,method=null,vars=new Map(),owner=null){if(classKinds.has(n.name))cls=unit.classes.find(c=>c.node===n)||cls;if(cls&&n.name==='classBody'&&n!==cls.body)return;
|
|
39
39
|
if(methodNodes.has(n)){method=methodNodes.get(n);vars=new Map(cls.fields);collectVariables(unit,n,vars);owner=method.symbol}
|
|
40
40
|
if(n.name==='lambdaExpression'){vars=new Map(vars);for(const param of identifiers(n.children.lambdaParameters?.[0]))vars.set(param.image,null);owner=addSymbol(unit,n,(cls?.local||'')+'.lambda@'+n.location.startLine,'function')||owner}
|
|
41
|
-
if(cls&&['unannType','classType','interfaceType'].includes(n.name)){const type=resolveType(unit,text(unit,n),cls);if(type&&type.unit.path!==unit.path&&room(dependencies,MAX_EDGES))dependencies.push({source:unit.path,target:type.unit.path,specifier:type.fqn,line:n.location.startLine,kind:'java_type',resolution:'resolved'})}
|
|
41
|
+
if(cls&&['unannType','classType','interfaceType'].includes(n.name)){const type=resolveType(unit,text(unit,n),cls);if(type&&type.unit.path!==unit.path&&room(dependencies,MAX_EDGES,'edges'))dependencies.push({source:unit.path,target:type.unit.path,specifier:type.fqn,line:n.location.startLine,kind:'java_type',resolution:'resolved'})}
|
|
42
42
|
if(cls&&n.name==='primary'){
|
|
43
43
|
const prefix=n.children.primaryPrefix?.[0],prefixText=text(unit,prefix).trim(),suffixes=n.children.primarySuffix||[];let chain=prefixText,fluent=false;
|
|
44
44
|
const newMatch=/^new\s+([\w.$]+)/.exec(prefixText);let constructed=newMatch?resolveType(unit,newMatch[1],cls):null;
|
|
45
|
-
const link=(type,line)=>{if(type&&type.unit.path!==unit.path&&room(dependencies,MAX_EDGES))dependencies.push({source:unit.path,target:type.unit.path,specifier:type.fqn,line,kind:'java_type',resolution:'resolved'})};
|
|
46
|
-
if(constructed&&room(calls,MAX_EDGES))calls.push({source:(owner||cls.symbol).id,target:constructed.symbol.id,line:n.location.startLine,kind:'construct',resolution:'static'});
|
|
45
|
+
const link=(type,line)=>{if(type&&type.unit.path!==unit.path&&room(dependencies,MAX_EDGES,'edges'))dependencies.push({source:unit.path,target:type.unit.path,specifier:type.fqn,line,kind:'java_type',resolution:'resolved'})};
|
|
46
|
+
if(constructed&&room(calls,MAX_EDGES,'edges'))calls.push({source:(owner||cls.symbol).id,target:constructed.symbol.id,line:n.location.startLine,kind:'construct',resolution:'static'});
|
|
47
47
|
link(constructed,n.location.startLine);
|
|
48
48
|
const staticHead=/^([A-Z][\w$]*)\./.exec(prefixText);if(staticHead&&!vars.has(staticHead[1]))link(resolveType(unit,staticHead[1],cls),n.location.startLine);
|
|
49
49
|
for(const suffix of suffixes){const invoke=suffix.children.methodInvocationSuffix?.[0];if(!invoke){chain+=text(unit,suffix);continue}const args=invoke.children.argumentList?.[0],arity=args?(args.children.expression||[]).length:0;const match=/^(?:([\w.$]+)\.)?([\w$]+)$/.exec(chain);let target=null;
|
|
50
50
|
if(match&&!fluent){const receiver=match[1],name=match[2];let type=null;if(!receiver||receiver==='this')type=cls;else if(receiver==='super')type=resolveType(unit,cls.extends,cls);else if(receiver.startsWith('this.'))type=resolveType(unit,cls.fields.get(receiver.slice(5))||'',cls);else if(vars.has(receiver))type=resolveType(unit,vars.get(receiver)||'',cls);else{type=resolveType(unit,receiver,cls);link(type,invoke.location.startLine)}target=lookupMethod(type,name,arity);if(!target&&!receiver){const candidates=unit.imports.filter(i=>i.static&&(i.spec.endsWith('.'+name)||i.spec.endsWith('.*'))).map(i=>lookupMethod(classes.get(i.spec.split('.').slice(0,-1).join('.')),name,arity)).filter(Boolean);if(candidates.length===1)target=candidates[0]}}
|
|
51
51
|
if(constructed&&!fluent){const methodName=/\.([\w$]+)$/.exec(chain)?.[1];if(methodName)target=lookupMethod(constructed,methodName,arity)}
|
|
52
|
-
if(target&&room(calls,MAX_EDGES))calls.push({source:(owner||cls.symbol).id,target:target.id,line:invoke.location.startLine,kind:'call',resolution:'static'});
|
|
52
|
+
if(target&&room(calls,MAX_EDGES,'edges'))calls.push({source:(owner||cls.symbol).id,target:target.id,line:invoke.location.startLine,kind:'call',resolution:'static'});
|
|
53
53
|
else if(unresolved.length<1000)unresolved.push({path:unit.path,line:invoke.location.startLine,expression:chain.slice(0,140),reason:'External/dynamic type, interface without implementation, or ambiguous overload in the Java snapshot.'});
|
|
54
54
|
fluent=true;chain+='<result>';
|
|
55
55
|
}
|
|
@@ -57,5 +57,6 @@ for(const unit of units){
|
|
|
57
57
|
for(const child of children(n))walk(child,cls,method,vars,owner)
|
|
58
58
|
}walk(unit.tree)
|
|
59
59
|
}
|
|
60
|
-
const ids=new Set(symbols.map(s=>s.id));
|
|
61
|
-
|
|
60
|
+
const ids=new Set(symbols.map(s=>s.id)),linked=calls.filter(c=>ids.has(c.source)&&ids.has(c.target));
|
|
61
|
+
leftOut.edges+=calls.length-linked.length;
|
|
62
|
+
process.stdout.write(JSON.stringify({symbols,dependencies,calls:linked,unresolved,diagnostics,parsed:units.map(u=>u.path),left_out:leftOut}));
|
package/code_graph_js.cjs
CHANGED
|
@@ -66,8 +66,8 @@ const host={
|
|
|
66
66
|
const program=ts.createProgram(names,options,host),checker=program.getTypeChecker();
|
|
67
67
|
const symbols=[],dependencies=[],calls=[],unresolved=[],diagnostics=[],declarations=new Map(),moduleNodes=new Map();
|
|
68
68
|
const {symbols:maxSymbols,edges:maxEdges}=input.limits;
|
|
69
|
-
|
|
70
|
-
function room(list,max){if(list.length<max)return true;
|
|
69
|
+
const leftOut={symbols:0,edges:0};
|
|
70
|
+
function room(list,max,kind){if(list.length<max)return true;leftOut[kind]++;return false;}
|
|
71
71
|
function filePath(source){return source.fileName.replace('/snapshot/','');}
|
|
72
72
|
function line(source,pos){return source.getLineAndCharacterOfPosition(pos).line+1;}
|
|
73
73
|
function displayName(node) {
|
|
@@ -81,7 +81,7 @@ function displayName(node) {
|
|
|
81
81
|
}
|
|
82
82
|
function isFunction(node){return !!node.body && (ts.isFunctionDeclaration(node)||ts.isMethodDeclaration(node)||ts.isFunctionExpression(node)||ts.isArrowFunction(node)||ts.isConstructorDeclaration(node)||ts.isGetAccessor(node)||ts.isSetAccessor(node));}
|
|
83
83
|
function addSymbol(node,source,owner){
|
|
84
|
-
if(!room(symbols,maxSymbols))return null;
|
|
84
|
+
if(!room(symbols,maxSymbols,'symbols'))return null;
|
|
85
85
|
let name=displayName(node),parent=node.parent;
|
|
86
86
|
const classParent=parent&&ts.isPropertyDeclaration(parent)?parent.parent:parent;
|
|
87
87
|
const cls=classParent && (ts.isClassDeclaration(classParent)||ts.isClassExpression(classParent)) ? classParent.name?.getText() : null;
|
|
@@ -116,16 +116,16 @@ for(const source of parsed){
|
|
|
116
116
|
const active=declarations.get(node)||owner;
|
|
117
117
|
if((ts.isImportDeclaration(node)||ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
118
118
|
const spec=node.moduleSpecifier.text,target=resolve(spec,source.fileName);
|
|
119
|
-
if(room(dependencies,maxEdges))dependencies.push({source:filePath(source),target:target?.replace('/snapshot/','')||null,specifier:spec,line:line(source,node.getStart(source)),kind:node.importClause?.isTypeOnly||node.isTypeOnly?'type_import':'import',resolution:target?'resolved':spec.startsWith('.')?'unresolved':'external'});
|
|
119
|
+
if(room(dependencies,maxEdges,'edges'))dependencies.push({source:filePath(source),target:target?.replace('/snapshot/','')||null,specifier:spec,line:line(source,node.getStart(source)),kind:node.importClause?.isTypeOnly||node.isTypeOnly?'type_import':'import',resolution:target?'resolved':spec.startsWith('.')?'unresolved':'external'});
|
|
120
120
|
}
|
|
121
121
|
if(ts.isCallExpression(node)||ts.isNewExpression(node)){
|
|
122
122
|
const expression=node.expression,at=line(source,node.getStart(source));
|
|
123
123
|
if(ts.isCallExpression(node) && (expression.kind===ts.SyntaxKind.ImportKeyword || ts.isIdentifier(expression)&&expression.text==='require') && node.arguments?.length && ts.isStringLiteral(node.arguments[0])){
|
|
124
124
|
const spec=node.arguments[0].text,target=resolve(spec,source.fileName);
|
|
125
|
-
if(room(dependencies,maxEdges))dependencies.push({source:filePath(source),target:target?.replace('/snapshot/','')||null,specifier:spec,line:at,kind:'dynamic_import',resolution:target?'resolved':spec.startsWith('.')?'unresolved':'external'});
|
|
125
|
+
if(room(dependencies,maxEdges,'edges'))dependencies.push({source:filePath(source),target:target?.replace('/snapshot/','')||null,specifier:spec,line:at,kind:'dynamic_import',resolution:target?'resolved':spec.startsWith('.')?'unresolved':'external'});
|
|
126
126
|
}else{
|
|
127
127
|
const target=targetFor(node);
|
|
128
|
-
if(target && room(calls,maxEdges))calls.push({source:(active||moduleSymbol(source)).id,target:target.id,line:at,kind:ts.isNewExpression(node)?'construct':'call',resolution:'static'});
|
|
128
|
+
if(target && room(calls,maxEdges,'edges'))calls.push({source:(active||moduleSymbol(source)).id,target:target.id,line:at,kind:ts.isNewExpression(node)?'construct':'call',resolution:'static'});
|
|
129
129
|
else if(unresolved.length<1000)unresolved.push({path:filePath(source),line:at,expression:expression.getText(source).slice(0,120),reason:'External or dynamic target, or no resolved implementation in the snapshot.'});
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -144,8 +144,8 @@ for(const source of parsed){
|
|
|
144
144
|
if(components.some(c=>c.template!=null)){
|
|
145
145
|
try{
|
|
146
146
|
const {parseTemplate}=require('./web_adapters/node/node_modules/@angular/compiler/fesm2022/compiler.mjs');
|
|
147
|
-
for(const component of components){if(component.template==null||!component.templatePath)continue;const pathName=component.templatePath.replace('/snapshot/',''),tree=parseTemplate(component.template,pathName);if(tree.errors?.length){diagnostics.push({path:pathName,reason:'Invalid Angular template or syntax not supported in this version.'});continue}templatePaths.add(pathName);const owner={id:pathName+'::'+filePath(component.source)+'::'+component.name+'.template@'+component.inlineLine,path:pathName,name:component.name+'.template',kind:'template',language:'angular',start_line:component.inlineLine,end_line:component.inlineLine+component.template.split('\n').length-1,location_kind:component.templatePath===component.source.fileName?'inline_template':'source_line'};if(!room(symbols,maxSymbols))break;symbols.push(owner);const shadow=new Set(),seen=new WeakSet();function walk(n,fn){if(!n||typeof n!=='object'||seen.has(n))return;seen.add(n);fn(n);for(const [key,value] of Object.entries(n)){if(['sourceSpan','span','startSourceSpan','endSourceSpan','keySpan','valueSpan','parent'].includes(key))continue;if(Array.isArray(value))value.forEach(x=>walk(x,fn));else if(value&&typeof value==='object')walk(value,fn)}}walk(tree.nodes,n=>{if(['Variable','Reference','LetDeclaration'].includes(n.constructor.name)&&n.name)shadow.add(n.name);if(n.constructor.name==='ForLoopBlock'&&n.item?.name)shadow.add(n.item.name)});const seen2=new WeakSet();function inspect(n){if(!n||typeof n!=='object'||seen2.has(n))return;seen2.add(n);const start=n.sourceSpan?.start,at=(typeof start==='number'?component.template.slice(0,start).split('\n').length-1:(start?.line??0))+component.inlineLine;if(n.constructor.name==='Call'||n.constructor.name==='SafeCall'){const receiver=n.receiver;if(receiver?.constructor.name==='PropertyRead'&&['ImplicitReceiver','ThisReceiver'].includes(receiver.receiver?.constructor.name)){const target=shadow.has(receiver.name)?null:component.methods.get(receiver.name);if(target&&room(calls,maxEdges))calls.push({source:owner.id,target:target.id,line:at,kind:'template_call',resolution:'static'});else if(unresolved.length<1000)unresolved.push({path:pathName,line:at,expression:receiver.name+'()',reason:'Unresolved template method, or a local variable that shadows the component.'})}}if(n.constructor.name==='Element'){const matches=components.filter(c=>c.selector===n.name);if(matches.length===1&&filePath(matches[0].source)!==pathName)dependencies.push({source:pathName,target:filePath(matches[0].source),specifier:n.name,line:at,kind:'angular_component',resolution:'resolved'})}if(n.constructor.name==='BindingPipe'){const matches=pipes.filter(p=>p.pipeName===n.name&&p.methods.has('transform'));if(matches.length===1){const pipe=matches[0];dependencies.push({source:pathName,target:filePath(pipe.source),specifier:n.name,line:at,kind:'angular_pipe',resolution:'resolved'});calls.push({source:owner.id,target:pipe.methods.get('transform').id,line:at,kind:'template_pipe',resolution:'static'})}}for(const [key,value] of Object.entries(n)){if(['sourceSpan','span','startSourceSpan','endSourceSpan','keySpan','valueSpan','parent'].includes(key))continue;if(Array.isArray(value))value.forEach(inspect);else if(value&&typeof value==='object')inspect(value)}}inspect(tree.nodes)
|
|
147
|
+
for(const component of components){if(component.template==null||!component.templatePath)continue;const pathName=component.templatePath.replace('/snapshot/',''),tree=parseTemplate(component.template,pathName);if(tree.errors?.length){diagnostics.push({path:pathName,reason:'Invalid Angular template or syntax not supported in this version.'});continue}templatePaths.add(pathName);const owner={id:pathName+'::'+filePath(component.source)+'::'+component.name+'.template@'+component.inlineLine,path:pathName,name:component.name+'.template',kind:'template',language:'angular',start_line:component.inlineLine,end_line:component.inlineLine+component.template.split('\n').length-1,location_kind:component.templatePath===component.source.fileName?'inline_template':'source_line'};if(!room(symbols,maxSymbols,'symbols'))break;symbols.push(owner);const shadow=new Set(),seen=new WeakSet();function walk(n,fn){if(!n||typeof n!=='object'||seen.has(n))return;seen.add(n);fn(n);for(const [key,value] of Object.entries(n)){if(['sourceSpan','span','startSourceSpan','endSourceSpan','keySpan','valueSpan','parent'].includes(key))continue;if(Array.isArray(value))value.forEach(x=>walk(x,fn));else if(value&&typeof value==='object')walk(value,fn)}}walk(tree.nodes,n=>{if(['Variable','Reference','LetDeclaration'].includes(n.constructor.name)&&n.name)shadow.add(n.name);if(n.constructor.name==='ForLoopBlock'&&n.item?.name)shadow.add(n.item.name)});const seen2=new WeakSet();function inspect(n){if(!n||typeof n!=='object'||seen2.has(n))return;seen2.add(n);const start=n.sourceSpan?.start,at=(typeof start==='number'?component.template.slice(0,start).split('\n').length-1:(start?.line??0))+component.inlineLine;if(n.constructor.name==='Call'||n.constructor.name==='SafeCall'){const receiver=n.receiver;if(receiver?.constructor.name==='PropertyRead'&&['ImplicitReceiver','ThisReceiver'].includes(receiver.receiver?.constructor.name)){const target=shadow.has(receiver.name)?null:component.methods.get(receiver.name);if(target&&room(calls,maxEdges,'edges'))calls.push({source:owner.id,target:target.id,line:at,kind:'template_call',resolution:'static'});else if(unresolved.length<1000)unresolved.push({path:pathName,line:at,expression:receiver.name+'()',reason:'Unresolved template method, or a local variable that shadows the component.'})}}if(n.constructor.name==='Element'){const matches=components.filter(c=>c.selector===n.name);if(matches.length===1&&filePath(matches[0].source)!==pathName)dependencies.push({source:pathName,target:filePath(matches[0].source),specifier:n.name,line:at,kind:'angular_component',resolution:'resolved'})}if(n.constructor.name==='BindingPipe'){const matches=pipes.filter(p=>p.pipeName===n.name&&p.methods.has('transform'));if(matches.length===1){const pipe=matches[0];dependencies.push({source:pathName,target:filePath(pipe.source),specifier:n.name,line:at,kind:'angular_pipe',resolution:'resolved'});calls.push({source:owner.id,target:pipe.methods.get('transform').id,line:at,kind:'template_pipe',resolution:'static'})}}for(const [key,value] of Object.entries(n)){if(['sourceSpan','span','startSourceSpan','endSourceSpan','keySpan','valueSpan','parent'].includes(key))continue;if(Array.isArray(value))value.forEach(inspect);else if(value&&typeof value==='object')inspect(value)}}inspect(tree.nodes)
|
|
148
148
|
}
|
|
149
149
|
}catch{diagnostics.push({path:'Angular',reason:'The Angular template analyzer did not finish. Check the local runtime.'})}
|
|
150
150
|
}
|
|
151
|
-
process.stdout.write(JSON.stringify({symbols,dependencies
|
|
151
|
+
process.stdout.write(JSON.stringify({symbols,dependencies,calls,unresolved,diagnostics,parsed:[...parsed.map(filePath),...templatePaths],left_out:leftOut}));
|
package/code_impact.py
CHANGED
|
@@ -143,7 +143,9 @@ def impact(root, symbol, view_id=None, depth=3, limit=30):
|
|
|
143
143
|
"diagnostics": diagnostics,
|
|
144
144
|
"view": (data.get("selected") or {}).get("label"),
|
|
145
145
|
"note": NOTE + (f" {len(found)} definitions share this name; each entry says which one ('of'); pass "
|
|
146
|
-
"path::name to keep one." if label else "")
|
|
146
|
+
"path::name to keep one." if label else "")
|
|
147
|
+
+ (f" {code_graph.left_out_sentence(data)} Callers and tests beyond the cut are not listed." if data["truncated"] else ""),
|
|
148
|
+
**({"left_out": data["left_out"]} if data["truncated"] else {}),
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
|
package/doc_scope.py
CHANGED
|
@@ -690,7 +690,7 @@ def generate(root, view_id=None, limit=30, model=None):
|
|
|
690
690
|
summary["failed_checks"] = [c for c in validation["checks"] if c["status"] == "fail"]
|
|
691
691
|
return {"validation": summary, "folder": folder, "written": len(files), "removed": [f"{DOCS_DIR}/{r}" for r in removed], **counts,
|
|
692
692
|
"prose_pending_total": len(pending), "prose_pending": pending[:limit], "prose_dropped": dropped[:limit],
|
|
693
|
-
"truncated": bool(model.graph.get("truncated")),
|
|
693
|
+
"truncated": bool(model.graph.get("truncated")), "left_out": model.graph["left_out"],
|
|
694
694
|
"extras": sorted(f"{DOCS_DIR}/{rel}" for rel in extras), "index_file": index_file if block is not None else None,
|
|
695
695
|
"guidance": (f"Validation FAILED: {summary['claims_failed']} claim(s) do not hold; read {validation['report']} "
|
|
696
696
|
"and fix the generator or the code before trusting these pages. " if summary["verdict"] == "fail"
|
package/duplicates.py
CHANGED
|
@@ -184,7 +184,7 @@ def _functions(root, include_tests):
|
|
|
184
184
|
if inventory.get("message"):
|
|
185
185
|
notes.append(inventory["message"])
|
|
186
186
|
if graph.get("truncated"):
|
|
187
|
-
notes.append(
|
|
187
|
+
notes.append(code_graph.left_out_sentence(graph))
|
|
188
188
|
if graph.get("retryable"):
|
|
189
189
|
notes.append("Partial analysis: " + "; ".join(d.get("reason", "") for d in graph.get("diagnostics", [])[:2]))
|
|
190
190
|
return functions, notes, view
|
package/layers.py
CHANGED
|
@@ -165,7 +165,7 @@ def summary(rule, graph, read):
|
|
|
165
165
|
the declared order, 'up' goes against it) and the folders no layer covers.
|
|
166
166
|
|
|
167
167
|
Parameters: rule (Rule); graph (dict) code graph with 'symbols' and 'calls'; read (callable path -> str or None).
|
|
168
|
-
Returns: dict with 'layers', 'calls_between', 'unassigned' and '
|
|
168
|
+
Returns: dict with 'layers', 'calls_between', 'unassigned', 'truncated' and 'left_out' (what the graph limits cut).
|
|
169
169
|
"""
|
|
170
170
|
order = {layer["name"]: index for index, layer in enumerate(rule.layers)}
|
|
171
171
|
paths = sorted({s["path"] for s in graph.get("symbols") or []})
|
|
@@ -185,7 +185,7 @@ def summary(rule, graph, read):
|
|
|
185
185
|
for (a, b), n in sorted(between.items(), key=lambda item: (order[item[0][0]],
|
|
186
186
|
order[item[0][1]]))],
|
|
187
187
|
"unassigned": [{"folder": folder, "files": n} for folder, n in unassigned.most_common(MAX_UNASSIGNED)],
|
|
188
|
-
"unassigned_files": files[None], "truncated": bool(graph.get("truncated"))}
|
|
188
|
+
"unassigned_files": files[None], "truncated": bool(graph.get("truncated")), "left_out": graph["left_out"]}
|
|
189
189
|
|
|
190
190
|
|
|
191
191
|
def report(root, layers=None, confirm=False, view_id=None):
|
|
@@ -229,7 +229,7 @@ def report(root, layers=None, confirm=False, view_id=None):
|
|
|
229
229
|
proposed = suggest(sorted({s["path"] for s in symbols}), read)
|
|
230
230
|
if not proposed:
|
|
231
231
|
return {"saved": False, "rule_path": path, "layers": [], "calls_between": [], "unassigned": [],
|
|
232
|
-
"truncated": bool(graph.get("truncated")),
|
|
232
|
+
"truncated": bool(graph.get("truncated")), "left_out": graph["left_out"],
|
|
233
233
|
"guidance": "No folder or annotation follows a known layer convention; declare the layers yourself "
|
|
234
234
|
"(name, paths, annotations, highest first) and confirm them."}
|
|
235
235
|
return {"saved": False, "rule_path": path, **summary(Rule(proposed), code, read),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allansantos-dev/smart-tool",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.79",
|
|
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": "Smart Tool contributors",
|
package/pr_impact.py
CHANGED
|
@@ -78,6 +78,8 @@ def report(root, base="HEAD", limit=30, view_id=None):
|
|
|
78
78
|
lines.append("No test reaches the changed code through imports or static calls.")
|
|
79
79
|
if changes["run_all"]:
|
|
80
80
|
lines += ["", "Run the whole suite: " + "; ".join(changes["run_all_reasons"]) + "."]
|
|
81
|
+
if changes.get("truncated"):
|
|
82
|
+
lines += ["", changes["note"]]
|
|
81
83
|
return {"base": base, "markdown": "\n".join(lines).rstrip("\n") + "\n", "touched": touched,
|
|
82
84
|
"callers": {label: (reached[1] if reached else 0) for label, reached in callers.items()},
|
|
83
85
|
"stale_anchors": stale, "stale_note": stale_note, "tests": changes["tests"],
|
package/version.py
CHANGED