tokensafe 4.7.12 → 4.7.13
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/.codex-plugin/plugin.json +1 -1
- package/README.md +7 -3
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +2 -0
- package/src/__init__.py +1 -1
- package/src/auto_inject.py +133 -4
- package/src/batch_editor.py +40 -9
- package/src/graph_engine.py +298 -27
- package/src/mcp_server.py +102 -13
- package/src/oumv_gateway.py +149 -6
- package/src/retrofit.py +97 -12
- package/src/scoped_search.py +126 -0
- package/src/telemetry_sync.py +1 -1
- package/src/version_checker.py +1 -1
package/src/scoped_search.py
CHANGED
|
@@ -102,6 +102,73 @@ class ScopedSearch:
|
|
|
102
102
|
return per_file
|
|
103
103
|
return max(4, min(8, max_results // 3))
|
|
104
104
|
|
|
105
|
+
@classmethod
|
|
106
|
+
def _graph_symbol_index(cls, root_dir: str):
|
|
107
|
+
"""Cache-only view of the AST symbol index; never starts a repository crawl."""
|
|
108
|
+
try:
|
|
109
|
+
from src.graph_engine import CodeGraph
|
|
110
|
+
graph = CodeGraph(root_dir, use_disk_cache=True)
|
|
111
|
+
except Exception:
|
|
112
|
+
return None
|
|
113
|
+
return graph if graph.symbols else None
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def _symbol_matches(
|
|
117
|
+
cls,
|
|
118
|
+
query: str,
|
|
119
|
+
root_dir: str,
|
|
120
|
+
scope: str,
|
|
121
|
+
max_results: int,
|
|
122
|
+
per_file: int,
|
|
123
|
+
) -> Optional[List[Dict[str, Any]]]:
|
|
124
|
+
"""Exact declaration lookup across every indexed file.
|
|
125
|
+
|
|
126
|
+
An identifier query is a lookup, not a grep: the disk walk stops at a file
|
|
127
|
+
budget (2,500 by default) and therefore never reaches later packages, which
|
|
128
|
+
is why a symbol declared in `paidz-workers` answered "0 matches" while the
|
|
129
|
+
graph index held it. Returns None when this is not a symbol-shaped query or
|
|
130
|
+
no cache exists — the caller then falls back to the bounded disk scan.
|
|
131
|
+
"""
|
|
132
|
+
if not re.fullmatch(r"[A-Za-z_$][\w$]{2,}", query or ""):
|
|
133
|
+
return None
|
|
134
|
+
graph = cls._graph_symbol_index(root_dir)
|
|
135
|
+
if graph is None:
|
|
136
|
+
return None
|
|
137
|
+
q = query.lower()
|
|
138
|
+
suffix_ok = any(ch.isupper() for ch in query) or "_" in query
|
|
139
|
+
hits = []
|
|
140
|
+
for sym in graph.symbols.values():
|
|
141
|
+
name = sym.name.lower()
|
|
142
|
+
if name == q:
|
|
143
|
+
rank = 0
|
|
144
|
+
elif suffix_ok and name.endswith(q):
|
|
145
|
+
rank = 1
|
|
146
|
+
else:
|
|
147
|
+
continue
|
|
148
|
+
if not cls.is_match_file(os.path.basename(sym.file_path), sym.file_path, scope):
|
|
149
|
+
continue
|
|
150
|
+
hits.append((rank, sym))
|
|
151
|
+
if not hits:
|
|
152
|
+
return None
|
|
153
|
+
hits.sort(key=lambda item: (item[0], item[1].file_path, item[1].line_start))
|
|
154
|
+
per_file_cap = cls._resolve_per_file(per_file, max_results)
|
|
155
|
+
per_file_counts: Dict[str, int] = {}
|
|
156
|
+
matches: List[Dict[str, Any]] = []
|
|
157
|
+
for _, sym in hits:
|
|
158
|
+
if len(matches) >= max_results:
|
|
159
|
+
break
|
|
160
|
+
seen = per_file_counts.get(sym.file_path, 0)
|
|
161
|
+
if seen >= per_file_cap:
|
|
162
|
+
continue
|
|
163
|
+
per_file_counts[sym.file_path] = seen + 1
|
|
164
|
+
text = f"{sym.kind} {sym.name}"
|
|
165
|
+
if sym.signature:
|
|
166
|
+
text += f" — {sym.signature}"
|
|
167
|
+
if len(text) > 100:
|
|
168
|
+
text = text[:97] + "..."
|
|
169
|
+
matches.append({"file": sym.file_path, "line": sym.line_start, "text": text})
|
|
170
|
+
return matches
|
|
171
|
+
|
|
105
172
|
@classmethod
|
|
106
173
|
def search(
|
|
107
174
|
cls,
|
|
@@ -214,12 +281,14 @@ class ScopedSearch:
|
|
|
214
281
|
"success": True,
|
|
215
282
|
"query": query,
|
|
216
283
|
"scope": scope,
|
|
284
|
+
"source": "fts_trigram",
|
|
217
285
|
"files_matched": len(fts_hit_files),
|
|
218
286
|
"scanned_files": len(fts_hit_files),
|
|
219
287
|
"total_matches": len(fts_matches),
|
|
220
288
|
"overflow_matches": sum(overflow.values()),
|
|
221
289
|
"per_file_cap": per_file_cap,
|
|
222
290
|
"timed_out": False,
|
|
291
|
+
"partial": False,
|
|
223
292
|
"matches": fts_matches,
|
|
224
293
|
"markdown": cls._render_markdown(
|
|
225
294
|
query, fts_matches, len(fts_hit_files), False, max_results,
|
|
@@ -230,6 +299,44 @@ class ScopedSearch:
|
|
|
230
299
|
except Exception:
|
|
231
300
|
pass # Seamless fallback to disk scan
|
|
232
301
|
|
|
302
|
+
# Symbol fast path: an identifier is a lookup, and the AST index covers every
|
|
303
|
+
# file while the bounded disk walk below covers only the first 2,500.
|
|
304
|
+
if not regex_mode and not case_sensitive:
|
|
305
|
+
symbol_matches = cls._symbol_matches(query, root_dir, scope, max_results, per_file)
|
|
306
|
+
if symbol_matches is not None:
|
|
307
|
+
hit_files = {m["file"] for m in symbol_matches}
|
|
308
|
+
indexed = 0
|
|
309
|
+
try:
|
|
310
|
+
graph = cls._graph_symbol_index(root_dir)
|
|
311
|
+
indexed = len(graph.file_symbols) if graph else 0
|
|
312
|
+
except Exception:
|
|
313
|
+
indexed = 0
|
|
314
|
+
markdown = cls._render_markdown(
|
|
315
|
+
query, symbol_matches, indexed or len(hit_files), False, max_results,
|
|
316
|
+
hit_files=hit_files, scope=scope, root_dir=root_dir,
|
|
317
|
+
)
|
|
318
|
+
if indexed:
|
|
319
|
+
markdown += (
|
|
320
|
+
f"\n_Answered from the AST symbol index ({indexed} indexed files): "
|
|
321
|
+
f"declarations only, complete across the repository._"
|
|
322
|
+
)
|
|
323
|
+
return {
|
|
324
|
+
"success": True,
|
|
325
|
+
"query": query,
|
|
326
|
+
"scope": scope,
|
|
327
|
+
"source": "graph_symbol_index",
|
|
328
|
+
"files_matched": len(hit_files),
|
|
329
|
+
"scanned_files": indexed or len(hit_files),
|
|
330
|
+
"total_matches": len(symbol_matches),
|
|
331
|
+
"overflow_matches": 0,
|
|
332
|
+
"per_file_cap": cls._resolve_per_file(per_file, max_results),
|
|
333
|
+
"timed_out": False,
|
|
334
|
+
"partial": False,
|
|
335
|
+
"matches": symbol_matches,
|
|
336
|
+
"markdown": markdown,
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
233
340
|
matches: List[Dict[str, Any]] = []
|
|
234
341
|
total_scanned_files = 0
|
|
235
342
|
hit_files = set()
|
|
@@ -330,16 +437,35 @@ class ScopedSearch:
|
|
|
330
437
|
per_file_cap=per_file_cap,
|
|
331
438
|
)
|
|
332
439
|
|
|
440
|
+
partial = bool(timed_out or total_scanned_files >= max_scanned_files)
|
|
441
|
+
if partial and not matches:
|
|
442
|
+
markdown += (
|
|
443
|
+
"\n_Scan stopped at its safety budget, so coverage was partial: the match may live "
|
|
444
|
+
"in a file that was not reached. Narrow 'path'/'project_path' for an exhaustive scan._"
|
|
445
|
+
)
|
|
446
|
+
if re.fullmatch(r"[A-Za-z_$][\w$]{2,}", query or ""):
|
|
447
|
+
markdown += (
|
|
448
|
+
f"\n_Declaration lookup: `oumv(action='index', query='{query}')` searches the complete "
|
|
449
|
+
"AST symbol index instead of the bounded disk walk._"
|
|
450
|
+
)
|
|
451
|
+
|
|
333
452
|
return {
|
|
334
453
|
"success": True,
|
|
335
454
|
"query": query,
|
|
336
455
|
"scope": scope,
|
|
456
|
+
"source": "disk_scan",
|
|
337
457
|
"total_matches": len(matches),
|
|
338
458
|
"overflow_matches": sum(overflow.values()),
|
|
339
459
|
"per_file_cap": per_file_cap,
|
|
340
460
|
"files_matched": len(hit_files),
|
|
341
461
|
"scanned_files": total_scanned_files,
|
|
342
462
|
"timed_out": timed_out,
|
|
463
|
+
"partial": partial,
|
|
464
|
+
"coverage": {
|
|
465
|
+
"file_budget": max_scanned_files,
|
|
466
|
+
"time_budget_seconds": timeout_seconds,
|
|
467
|
+
"stopped_early": partial,
|
|
468
|
+
},
|
|
343
469
|
"matches": matches,
|
|
344
470
|
"markdown": markdown,
|
|
345
471
|
}
|
package/src/telemetry_sync.py
CHANGED
|
@@ -311,7 +311,7 @@ class TelemetrySync:
|
|
|
311
311
|
current_last_id = last_id
|
|
312
312
|
headers = {
|
|
313
313
|
"Content-Type": "application/json",
|
|
314
|
-
"User-Agent": "TokenSafe-Sync/4.7.
|
|
314
|
+
"User-Agent": "TokenSafe-Sync/4.7.13"
|
|
315
315
|
}
|
|
316
316
|
if active_key:
|
|
317
317
|
headers["Authorization"] = f"Bearer {active_key}"
|
package/src/version_checker.py
CHANGED
|
@@ -17,7 +17,7 @@ import urllib.request
|
|
|
17
17
|
import urllib.error
|
|
18
18
|
from typing import Dict, Any, Optional, Tuple
|
|
19
19
|
|
|
20
|
-
CURRENT_VERSION = "4.7.
|
|
20
|
+
CURRENT_VERSION = "4.7.13"
|
|
21
21
|
CACHE_TTL = 86400 # 24 hours
|
|
22
22
|
# When the cloud is unreachable we must NOT cache the synthesized "up to date"
|
|
23
23
|
# answer for a full day — otherwise an update released right after an outage
|