tokensafe 4.12.4 → 4.13.2
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 +8 -6
- package/hooks/pre_invocation.py +8 -4
- package/kimi.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +4 -3
- package/server.json +3 -3
- package/src/auto_inject.py +1070 -283
- package/src/backend_release.py +10 -0
- package/src/batch_editor.py +18 -8
- package/src/batch_search.py +39 -16
- package/src/bundle_probe.py +205 -0
- package/src/cli.py +76 -7
- package/src/fts_index.py +9 -0
- package/src/globmatch.py +124 -0
- package/src/governor.py +120 -44
- package/src/graph_engine.py +292 -14
- package/src/installer.py +3 -3
- package/src/mcp_server.py +153 -35
- package/src/metrics.py +7 -0
- package/src/oumv_brief.py +346 -0
- package/src/oumv_gateway.py +132 -43
- package/src/quality_score.py +46 -24
- package/src/retrofit.py +35 -11
- package/src/savings.py +1 -0
- package/src/scoped_search.py +238 -9
- package/src/session_brief.py +6 -1
- package/src/telemetry_sync.py +1 -1
- package/src/treesitter_backend.py +26 -1
- package/src/version_checker.py +1 -1
- package/src/web_reader.py +42 -0
- package/src/workspace_roots.py +246 -0
package/src/installer.py
CHANGED
|
@@ -48,14 +48,14 @@ UNIFIED_TOKENSAFE_RULE = (
|
|
|
48
48
|
"## TOKENSAFE GRAPH-FIRST OPTIMIZATION PROTOCOL\n"
|
|
49
49
|
"Always use `tokensafe` MCP tools (`smart_read_file`, `scoped_search`, `apply_edits`, `repo_map`, `session_context`, `oumv`, `run_helper`) over default raw file reads or high-output terminal executions.\n\n"
|
|
50
50
|
"1. **Zero Raw Grep/Find (Blocked & Replaced by `scoped_search`)**: Strictly NEVER execute terminal `grep`, `egrep`, `ripgrep`, or `find` on source code files or directories (`src/`, `views/`, `components/`, `.ts`, `.tsx`, `.py`, `.js`). Use `tokensafe:scoped_search(query, path='.', scope='code')` for single searches (`mode='auto'|'text'|'regex'|'glob'|'fuzzy'|'git'`) or `queries=[...]` for up to 20 concurrent queries in one call.\n"
|
|
51
|
-
"2. **
|
|
51
|
+
"2. **Single-Call Brief, Symbol, Endpoint, Bundle & External Type Inspection (`smart_read_file`)**: On an OUMV-supported stack call `tokensafe:oumv(action='brief', target='<file-or-symbol>')` first: one call returns the skeleton, every call site (graph edges plus `confidence: probable` text-level references), public props and mutable module state, so `observe` then `smart_read_file` then `understand` chains are obsolete. Then call `tokensafe:smart_read_file(path, symbol)` (default `dep_mode='signature'` folds inert code -95%+ tokens; pass `dep_mode='full'` only when needed, or `force_full=true` if a pointer hit references missing context). When the bug names a route, call `smart_read_file(endpoint='POST /api/orders')` FIRST: one call resolves the route registration across the repo → handler body + file path + line range + whole-file version (and names the handler's cross-file callees). `symbol` accepts an identifier, a qualified member (`Type.Method`) or an endpoint target (`'POST /api/orders'`): when the target is not a declaration in that file you get the enclosing handler body (or a tight ±window around the hit) with line numbers, plus the declaration itself when it lives in another file — that is the slice you edit, never a folded skeleton you have to re-read, and it is exact file text so it needs no confirming re-read. Pass `targets=[{path, symbol}]` to bundle 2-8 symbols across files in one call, or `package_name`+`symbol` for 3rd-party `.d.ts` interfaces. OpenAPI/Prisma/GraphQL/SQL schemas auto-slice via `symbol`.\n"
|
|
52
52
|
"3. **Repeat Read Deduplication**: Never re-read unchanged files or symbols within the same session. Reuse the earlier skeleton or pointer hit (`// [TokenSafe: Pointer Hit ...]`).\n"
|
|
53
53
|
"4. **Zero-Fluff Egress & Surgical Diffs**: Omit conversational filler. Reference line ranges (`file.ts#L10-L25`) and use `tokensafe:apply_edits` for multi-hunk/multi-file edits with optional inline `verify`. Take `start_line`/`end_line` from the slice header (`// --- Lx-Ly`): a target that occurs more than once is rejected with its occurrence lines and a ready scoped retry, and the tool auto-scopes to the window just read when exactly one occurrence is inside it. For a failing test, one hunk + `verify='auto'` (the project's own declared test command) per attempt: the edit and the verdict come back in one call, so read the reported line and apply the next hunk instead of rewriting whole files.\n"
|
|
54
54
|
"5. **Architecture Graph, API Surface & Directory Tree (`repo_map`)**: For an unfamiliar repository or a broad refactor, FIRST call `tokensafe:repo_map(view='graph', project_path=...)` for God Nodes (<250 tokens). Use `view='api'` for exported types/interfaces and `view='tree'` instead of `ls -la`. Skip the map when the task already names the failing endpoint, symbol or file — go straight to `scoped_search` + `smart_read_file`.\n"
|
|
55
|
-
"6. **Utilities (`run_helper`)**: Use `tokensafe:run_helper(action=...)` for rare/auxiliary operations: `'sanitize'` (rewrite shell/test commands), `'guard'` (pre-flight secret/safety audit), `'diff'` (slice diff), `'deps'` (lockfile point lookup), `'web'` (fetch clean Markdown), `'expand'` (restore `#hash`), `'image'` (downscale >1024px),
|
|
55
|
+
"6. **Utilities (`run_helper`)**: Use `tokensafe:run_helper(action=...)` for rare/auxiliary operations: `'sanitize'` (rewrite shell/test commands), `'guard'` (pre-flight secret/safety audit), `'diff'` (slice diff), `'deps'` (lockfile point lookup), `'web'` (fetch clean Markdown), `'expand'` (restore `#hash`), `'image'` (downscale >1024px), `'compress'` (TOCP prompt), and `'bundle-probe'` (url + expect/reject/chunks: live entry and hashed chunks checked in one call).\n"
|
|
56
56
|
"7. **Compact Tests & Build Output**: Run noisy commands, builds, and test suites via `tokensafe wrap '<cmd>'` or `tokensafe tests [cmd]` (clean 1-line summary on pass, full trace on failure; never leave `vitest`/`jest`/`bun` in watch mode).\n"
|
|
57
57
|
"8. **Styles & Design Tokens**: When inspecting CSS/SCSS/LESS/Tailwind, `smart_read_file` preserves design tokens (`:root`, `@theme`, CSS variables) in full.\n"
|
|
58
|
-
"9. **Session & Context Hygiene (`session_context`)**: Call `tokensafe:session_context(action='budget', model=...)` before large tasks. On `warning`/`critical
|
|
58
|
+
"9. **Session & Context Hygiene (`session_context`)**: Call `tokensafe:session_context(action='budget', model=...)` before large tasks. Act only on `measurement: 'measured'`: `estimated` is a cumulative floor and `unknown` (`used_pct: null`) means pass `transcript_path`; neither justifies a compaction. On a measured `warning`/`critical`, call `action='compact'` (with `transcript_path`). Use `action='prune'` for superseded reads, `action='mistakes'` for anti-stuck memory, and `action='metrics'` for savings analytics (`total_saved_tokens_basis`).\n"
|
|
59
59
|
"10. **Secret Leak Prevention (Zero Hardcoded Fallbacks)**: Never hardcode real private keys, API secrets, or webhook secrets as fallback arguments in `os.environ.get()`, `os.getenv()`, or `process.env`. Whenever blocked, state:\n"
|
|
60
60
|
"`🛡️ **TokenSafe Security Guard**: Prevented secret / private key leak into git (<target_file>: <details>)`\n"
|
|
61
61
|
"11. **Proof-of-Savings Turn Footer (strictly English)**: Append on tool-using turns:\n"
|
package/src/mcp_server.py
CHANGED
|
@@ -41,11 +41,12 @@ from src import route_index
|
|
|
41
41
|
from src import oumv_policy
|
|
42
42
|
from src.license_manager import LicenseManager
|
|
43
43
|
from src.paths import get_active_workspace, is_plugin_or_system_dir
|
|
44
|
+
from src.workspace_roots import known_roots, rebase_edits, register_roots, resolve_input_path
|
|
44
45
|
from src.session_context import current_root, current_session_id
|
|
45
46
|
|
|
46
47
|
SERVER_INFO = {
|
|
47
48
|
"name": "tokensafe-mcp",
|
|
48
|
-
"version": "4.
|
|
49
|
+
"version": "4.13.2"
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
# MCP client attribution: the initialize handshake carries clientInfo, which
|
|
@@ -786,8 +787,11 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
786
787
|
'properties': {'path': {'type': 'string'},
|
|
787
788
|
'symbol': {'type': 'string'}},
|
|
788
789
|
'required': ['path']}},
|
|
789
|
-
'package_name': {'type': 'string', 'description': '.d.ts npm package'}
|
|
790
|
-
|
|
790
|
+
'package_name': {'type': 'string', 'description': '.d.ts npm package'},
|
|
791
|
+
'root': {'type': 'string',
|
|
792
|
+
'description': 'Workspace root for relative paths (default: session root)'}},
|
|
793
|
+
'anyOf': [{'required': ['path']}, {'required': ['endpoint']}, {'required': ['package_name']},
|
|
794
|
+
{'required': ['targets']}]}},
|
|
791
795
|
{'name': 'scoped_search',
|
|
792
796
|
'annotations': {'readOnlyHint': True},
|
|
793
797
|
'description': 'Search replacing grep/find: query+scope, or queries=[{query|pattern,type,path,glob}] batch (max 20).',
|
|
@@ -799,6 +803,8 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
799
803
|
'description': "code|config|all|ext|subfolder"},
|
|
800
804
|
'path': {'type': 'string'},
|
|
801
805
|
'cwd': {'type': 'string'},
|
|
806
|
+
'root': {'type': 'string',
|
|
807
|
+
'description': 'Workspace root for relative paths (default: session root)'},
|
|
802
808
|
'max_results': {'type': 'integer', 'description': 'default 25'},
|
|
803
809
|
'per_file': {'type': 'integer'},
|
|
804
810
|
'queries': {'type': 'array',
|
|
@@ -828,6 +834,10 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
828
834
|
'required': ['path']}},
|
|
829
835
|
'dry_run': {'type': 'boolean'},
|
|
830
836
|
'best_effort': {'type': 'boolean'},
|
|
837
|
+
'cwd': {'type': 'string',
|
|
838
|
+
'description': 'Repo root for relative edit paths; absolute paths '
|
|
839
|
+
'inside a known root are rebased automatically'},
|
|
840
|
+
'root': {'type': 'string', 'description': 'Alias of cwd'},
|
|
831
841
|
'verify': {'type': 'string',
|
|
832
842
|
'description': "Command run after the edit; 'auto' = the "
|
|
833
843
|
"project's declared test command"}},
|
|
@@ -841,6 +851,8 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
841
851
|
'project_path': {'type': 'string',
|
|
842
852
|
'description': 'Absolute path in multi-repo setups'},
|
|
843
853
|
'path': {'type': 'string'},
|
|
854
|
+
'root': {'type': 'string',
|
|
855
|
+
'description': 'Workspace root for relative paths (default: session root)'},
|
|
844
856
|
'depth': {'type': 'integer'}}}},
|
|
845
857
|
{'name': 'session_context',
|
|
846
858
|
'annotations': {'readOnlyHint': False},
|
|
@@ -853,7 +865,8 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
853
865
|
'transcript_path': {'type': 'string'}}}},
|
|
854
866
|
{'name': 'oumv',
|
|
855
867
|
'annotations': {'readOnlyHint': False},
|
|
856
|
-
'description': "OUMV runtime: 'status'|'observe' L0-L4|'
|
|
868
|
+
'description': "OUMV runtime: 'status'|'observe' L0-L4|'brief' (skeleton + call sites + props + module "
|
|
869
|
+
"state in one call)|'understand'|'verify'|'mutate' (OCC edit)|'graph'|'index' "
|
|
857
870
|
"(repo-wide symbol search: query, kinds?, limit?)|'preview' (dry-run diff, no write)|'build' "
|
|
858
871
|
"(run the runtime's build/test command, §14.3)|'cancel' (cooperative, by requestId). "
|
|
859
872
|
"Observation is free on every plan; the write actions (verify, mutate, preview, build) "
|
|
@@ -862,6 +875,7 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
862
875
|
'properties': {'action': {'type': 'string',
|
|
863
876
|
'enum': ['status',
|
|
864
877
|
'observe',
|
|
878
|
+
'brief',
|
|
865
879
|
'understand',
|
|
866
880
|
'verify',
|
|
867
881
|
'mutate',
|
|
@@ -900,7 +914,8 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
900
914
|
'also accepted as path'}}}},
|
|
901
915
|
{'name': 'run_helper',
|
|
902
916
|
'annotations': {'readOnlyHint': False},
|
|
903
|
-
'description': "Utilities: 'sanitize','guard','diff','deps','web','expand','image','compress','dict'
|
|
917
|
+
'description': "Utilities: 'sanitize','guard','diff','deps','web','expand','image','compress','dict','bundle-probe' "
|
|
918
|
+
"(live entry + hashed chunks + expect/reject table).",
|
|
904
919
|
'inputSchema': {'type': 'object',
|
|
905
920
|
'properties': {'action': {'type': 'string',
|
|
906
921
|
'enum': ['sanitize',
|
|
@@ -911,7 +926,8 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
911
926
|
'expand',
|
|
912
927
|
'image',
|
|
913
928
|
'compress',
|
|
914
|
-
'dict'
|
|
929
|
+
'dict',
|
|
930
|
+
'bundle-probe']},
|
|
915
931
|
'command': {'type': 'string'},
|
|
916
932
|
'code': {'type': 'string'},
|
|
917
933
|
'file_path': {'type': 'string'},
|
|
@@ -922,7 +938,18 @@ TOOLS = [{'name': 'smart_read_file',
|
|
|
922
938
|
'hash': {'type': 'string'},
|
|
923
939
|
'image_path': {'type': 'string'},
|
|
924
940
|
'max_edge': {'type': 'integer'},
|
|
925
|
-
'prompt': {'type': 'string'}
|
|
941
|
+
'prompt': {'type': 'string'},
|
|
942
|
+
'expect': {'type': 'array',
|
|
943
|
+
'items': {'type': 'string'},
|
|
944
|
+
'description': 'bundle-probe: strings that must be present'},
|
|
945
|
+
'reject': {'type': 'array',
|
|
946
|
+
'items': {'type': 'string'},
|
|
947
|
+
'description': 'bundle-probe: strings that must be absent'},
|
|
948
|
+
'chunks': {'type': 'array',
|
|
949
|
+
'items': {'type': 'string'},
|
|
950
|
+
'description': 'bundle-probe: explicit chunk URLs (default: auto-discover from the entry)'},
|
|
951
|
+
'timeout_ms': {'type': 'integer',
|
|
952
|
+
'description': 'bundle-probe: total budget (default 6000, max 15000)'}}}}]
|
|
926
953
|
|
|
927
954
|
|
|
928
955
|
def _tighten_apply_edits_schema() -> None:
|
|
@@ -1073,7 +1100,7 @@ def _resolve_project_root(args: dict) -> Tuple[Optional[str], Optional[str]]:
|
|
|
1073
1100
|
"""
|
|
1074
1101
|
Safely resolves the target project root without falling back to system root dirs or plugin dirs.
|
|
1075
1102
|
"""
|
|
1076
|
-
target = args.get("project_path") or args.get("root_dir") or args.get("path") or args.get("directory")
|
|
1103
|
+
target = args.get("root") or args.get("project_path") or args.get("root_dir") or args.get("path") or args.get("directory")
|
|
1077
1104
|
active_ws = _workspace_root()
|
|
1078
1105
|
|
|
1079
1106
|
if target:
|
|
@@ -1081,7 +1108,10 @@ def _resolve_project_root(args: dict) -> Tuple[Optional[str], Optional[str]]:
|
|
|
1081
1108
|
if active_ws and os.path.isdir(os.path.join(active_ws, target)):
|
|
1082
1109
|
target_abs = os.path.abspath(os.path.join(active_ws, target))
|
|
1083
1110
|
else:
|
|
1084
|
-
|
|
1111
|
+
resolved, _meta, _resolve_err = resolve_input_path(
|
|
1112
|
+
target, base=active_ws, mode="read", must_exist=True
|
|
1113
|
+
)
|
|
1114
|
+
target_abs = resolved or os.path.abspath(target)
|
|
1085
1115
|
else:
|
|
1086
1116
|
target_abs = os.path.abspath(target)
|
|
1087
1117
|
|
|
@@ -1179,7 +1209,18 @@ def _oumv_workspace_arg(args: dict, allow_path: bool = False) -> Tuple[Optional[
|
|
|
1179
1209
|
raw = str(args.get("path") or "").strip()
|
|
1180
1210
|
if not raw:
|
|
1181
1211
|
return _oumv_default_workspace(), None
|
|
1182
|
-
|
|
1212
|
+
if os.path.isabs(raw):
|
|
1213
|
+
ws = os.path.abspath(raw)
|
|
1214
|
+
else:
|
|
1215
|
+
# A relative repo name resolves against this server's workspace or the
|
|
1216
|
+
# one registered root that contains it; ambiguity is an error, never a
|
|
1217
|
+
# silent pick between open folders.
|
|
1218
|
+
resolved, _meta, resolve_err = resolve_input_path(
|
|
1219
|
+
raw, base=_oumv_default_workspace(), mode="read", must_exist=True
|
|
1220
|
+
)
|
|
1221
|
+
if not resolved:
|
|
1222
|
+
return None, resolve_err
|
|
1223
|
+
ws = resolved
|
|
1183
1224
|
if os.path.isfile(ws):
|
|
1184
1225
|
ws = os.path.dirname(ws)
|
|
1185
1226
|
if not os.path.isdir(ws):
|
|
@@ -1976,6 +2017,7 @@ _OUMV_ACTIONS = {
|
|
|
1976
2017
|
"status": "oumv_status",
|
|
1977
2018
|
"observe": "oumv_observe",
|
|
1978
2019
|
"understand": "oumv_understand",
|
|
2020
|
+
"brief": "oumv_brief",
|
|
1979
2021
|
"mutate": "oumv_mutate",
|
|
1980
2022
|
"verify": "oumv_verify",
|
|
1981
2023
|
"graph": "oumv_graph",
|
|
@@ -1994,6 +2036,7 @@ _HELPER_ACTIONS = {
|
|
|
1994
2036
|
"image": "optimize_image",
|
|
1995
2037
|
"compress": "compress_prompt",
|
|
1996
2038
|
"dict": "dict_catalog",
|
|
2039
|
+
"bundle-probe": "bundle_probe",
|
|
1997
2040
|
}
|
|
1998
2041
|
|
|
1999
2042
|
|
|
@@ -2079,7 +2122,7 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
2079
2122
|
# (dirname) produced target:null and a whole-repo dump.
|
|
2080
2123
|
file_target: Optional[str] = None
|
|
2081
2124
|
raw_path = str(args.get("path") or "").strip()
|
|
2082
|
-
if action in ("observe", "understand") and raw_path:
|
|
2125
|
+
if action in ("observe", "understand", "brief") and raw_path:
|
|
2083
2126
|
probe_base = str(args.get("workspace_dir") or "").strip() or _oumv_default_workspace() or os.getcwd()
|
|
2084
2127
|
probe = raw_path if os.path.isabs(raw_path) else os.path.join(probe_base, raw_path)
|
|
2085
2128
|
if os.path.isfile(probe):
|
|
@@ -2088,7 +2131,7 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
2088
2131
|
args,
|
|
2089
2132
|
allow_path=(
|
|
2090
2133
|
not file_target
|
|
2091
|
-
and action in ("status", "observe", "understand", "verify", "graph", "index", "preview", "build", "cancel")
|
|
2134
|
+
and action in ("status", "observe", "brief", "understand", "verify", "graph", "index", "preview", "build", "cancel")
|
|
2092
2135
|
),
|
|
2093
2136
|
)
|
|
2094
2137
|
if ws_err:
|
|
@@ -2165,13 +2208,16 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
2165
2208
|
return {"content": [{"type": "text", "text": rendered}]}
|
|
2166
2209
|
|
|
2167
2210
|
active_ws = _workspace_root()
|
|
2168
|
-
if path
|
|
2169
|
-
|
|
2170
|
-
path
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2211
|
+
if path:
|
|
2212
|
+
resolved, _meta_info, resolve_err = resolve_input_path(
|
|
2213
|
+
path,
|
|
2214
|
+
base=args.get("root") or active_ws,
|
|
2215
|
+
mode="read",
|
|
2216
|
+
must_exist=True,
|
|
2217
|
+
)
|
|
2218
|
+
if resolve_err:
|
|
2219
|
+
return {"isError": True, "content": [{"type": "text", "text": f"File not found: {path}. {resolve_err}"}]}
|
|
2220
|
+
path = resolved
|
|
2175
2221
|
|
|
2176
2222
|
if not path or not os.path.exists(path):
|
|
2177
2223
|
return {"isError": True, "content": [{"type": "text", "text": f"File not found: {path}"}]}
|
|
@@ -2684,7 +2730,7 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
2684
2730
|
window_tokens = None
|
|
2685
2731
|
budget = ContextBudget.estimate(
|
|
2686
2732
|
tracker, session_id=session_id, model=model, window_tokens=window_tokens,
|
|
2687
|
-
transcript_path=transcript_path
|
|
2733
|
+
transcript_path=transcript_path, discover_transcript=True
|
|
2688
2734
|
)
|
|
2689
2735
|
try:
|
|
2690
2736
|
from src.quality_score import ContextQualityScore
|
|
@@ -3139,7 +3185,10 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3139
3185
|
return os.path.abspath(value)
|
|
3140
3186
|
if active_ws and os.path.isdir(os.path.join(active_ws, value)):
|
|
3141
3187
|
return os.path.abspath(os.path.join(active_ws, value))
|
|
3142
|
-
|
|
3188
|
+
resolved, _meta, _resolve_err = resolve_input_path(
|
|
3189
|
+
value, base=active_ws, mode="read", must_exist=False
|
|
3190
|
+
)
|
|
3191
|
+
return resolved or os.path.abspath(value)
|
|
3143
3192
|
|
|
3144
3193
|
base_dir = _abs_candidate(str(explicit_root)) if explicit_root else None
|
|
3145
3194
|
if base_dir and not os.path.isdir(base_dir):
|
|
@@ -3192,7 +3241,7 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3192
3241
|
# repo outside the session workspace pass cwd + a repo-relative path, and
|
|
3193
3242
|
# anchoring that path to the active workspace used to surface as a bare
|
|
3194
3243
|
# "Invalid project path" for a directory that exists under cwd.
|
|
3195
|
-
raw_cwd = args.get("cwd")
|
|
3244
|
+
raw_cwd = args.get("root") or args.get("cwd")
|
|
3196
3245
|
if raw_cwd:
|
|
3197
3246
|
if not os.path.isabs(str(raw_cwd)) and active_ws and os.path.isdir(os.path.join(active_ws, str(raw_cwd))):
|
|
3198
3247
|
base_dir = os.path.abspath(os.path.join(active_ws, str(raw_cwd)))
|
|
@@ -3204,6 +3253,7 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3204
3253
|
base_dir = active_ws
|
|
3205
3254
|
|
|
3206
3255
|
# 1. Resolve base directory safely without scanning plugin or system roots
|
|
3256
|
+
single_file: Optional[str] = None
|
|
3207
3257
|
if raw_path:
|
|
3208
3258
|
if not os.path.isabs(raw_path):
|
|
3209
3259
|
if base_dir and os.path.isdir(os.path.join(base_dir, raw_path)):
|
|
@@ -3221,7 +3271,16 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3221
3271
|
target_path = os.path.abspath(raw_path)
|
|
3222
3272
|
|
|
3223
3273
|
if os.path.isfile(target_path):
|
|
3224
|
-
|
|
3274
|
+
single_file = target_path
|
|
3275
|
+
# Keep repo-relative display paths when the file sits inside the
|
|
3276
|
+
# explicit root; otherwise fall back to its parent directory.
|
|
3277
|
+
try:
|
|
3278
|
+
inside_base = bool(base_dir) and os.path.commonpath(
|
|
3279
|
+
[os.path.abspath(str(base_dir)), os.path.abspath(single_file)]
|
|
3280
|
+
) == os.path.abspath(str(base_dir))
|
|
3281
|
+
except ValueError:
|
|
3282
|
+
inside_base = False
|
|
3283
|
+
target_path = os.path.abspath(str(base_dir)) if inside_base else os.path.dirname(single_file)
|
|
3225
3284
|
if is_plugin_or_system_dir(target_path):
|
|
3226
3285
|
return _fallback_error("scoped_search", f"refusing to search system root or plugin dir '{raw_path}'")
|
|
3227
3286
|
else:
|
|
@@ -3249,6 +3308,9 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3249
3308
|
if not within_base or is_plugin_or_system_dir(candidate_subdir):
|
|
3250
3309
|
return _fallback_error("scoped_search", f"refusing to search outside target directory via scope '{raw_scope}'")
|
|
3251
3310
|
target_path = candidate_subdir
|
|
3311
|
+
if os.path.isfile(target_path):
|
|
3312
|
+
single_file = target_path
|
|
3313
|
+
target_path = os.path.dirname(target_path)
|
|
3252
3314
|
scope = "all"
|
|
3253
3315
|
|
|
3254
3316
|
max_res = _safe_int(args.get("max_results"), 25, lo=1, hi=100)
|
|
@@ -3269,7 +3331,8 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3269
3331
|
max_results=max_res,
|
|
3270
3332
|
case_sensitive=c_sens,
|
|
3271
3333
|
use_regex=u_regex,
|
|
3272
|
-
per_file=_safe_int(args.get("per_file"), 0, lo=0, hi=100)
|
|
3334
|
+
per_file=_safe_int(args.get("per_file"), 0, lo=0, hi=100),
|
|
3335
|
+
target_file=single_file
|
|
3273
3336
|
)
|
|
3274
3337
|
md_text = res["markdown"]
|
|
3275
3338
|
if not res.get("success", True):
|
|
@@ -3341,6 +3404,30 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3341
3404
|
except Exception as e:
|
|
3342
3405
|
return _fallback_error("read_web_page", f"error reading web page: {e}")
|
|
3343
3406
|
|
|
3407
|
+
elif name == "bundle_probe":
|
|
3408
|
+
target_url = str(args.get("url") or "").strip()
|
|
3409
|
+
if not target_url:
|
|
3410
|
+
return _fallback_error("bundle_probe", "missing required 'url' argument")
|
|
3411
|
+
expect = args.get("expect") if isinstance(args.get("expect"), list) else []
|
|
3412
|
+
reject = args.get("reject") if isinstance(args.get("reject"), list) else []
|
|
3413
|
+
chunks = args.get("chunks") if isinstance(args.get("chunks"), list) else None
|
|
3414
|
+
try:
|
|
3415
|
+
from src.bundle_probe import probe_bundle
|
|
3416
|
+
res = probe_bundle(target_url, expect=expect, reject=reject, chunks=chunks,
|
|
3417
|
+
timeout_ms=args.get("timeout_ms"))
|
|
3418
|
+
md_text = str(res.get("markdown") or "")
|
|
3419
|
+
tracker.record_event(
|
|
3420
|
+
session_id=_mcp_session_id(),
|
|
3421
|
+
event_type="DEPLOY_PROBE",
|
|
3422
|
+
original_tokens=max(1500, count_tokens(md_text) * 8),
|
|
3423
|
+
optimized_tokens=count_tokens(md_text),
|
|
3424
|
+
details={"url": target_url[:100], "ok": bool(res.get("ok")),
|
|
3425
|
+
"chunks": len(res.get("chunks") or [])}
|
|
3426
|
+
)
|
|
3427
|
+
return {"content": [{"type": "text", "text": md_text}]}
|
|
3428
|
+
except Exception as e:
|
|
3429
|
+
return _fallback_error("bundle_probe", f"bundle probe failed: {e}")
|
|
3430
|
+
|
|
3344
3431
|
elif name == "query_dependency":
|
|
3345
3432
|
pkg = str(args.get("package_name") or args.get("package") or "").strip()
|
|
3346
3433
|
lock_p = str(args.get("lockfile_path") or args.get("path") or "").strip() or None
|
|
@@ -3503,6 +3590,20 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3503
3590
|
except Exception as e:
|
|
3504
3591
|
return _fallback_error("oumv_observe", f"failed to observe OUMV runtime: {e}")
|
|
3505
3592
|
|
|
3593
|
+
elif name == "oumv_brief":
|
|
3594
|
+
try:
|
|
3595
|
+
from src.oumv_gateway import OUMVGateway
|
|
3596
|
+
tgt = str(args.get("target") or "").strip() or None
|
|
3597
|
+
sym = str(args.get("symbol") or "").strip() or None
|
|
3598
|
+
raw_path = str(args.get("path") or "").strip() or None
|
|
3599
|
+
ws, ws_err = _oumv_workspace_arg(args)
|
|
3600
|
+
if ws_err:
|
|
3601
|
+
return _fallback_error("oumv_brief", ws_err)
|
|
3602
|
+
res = OUMVGateway.brief(target=tgt, symbol=sym, workspace_dir=ws, path=raw_path)
|
|
3603
|
+
return {"content": [{"type": "text", "text": json.dumps(res, indent=2, ensure_ascii=False)}]}
|
|
3604
|
+
except Exception as e:
|
|
3605
|
+
return _fallback_error("oumv_brief", f"failed to build brief: {e}")
|
|
3606
|
+
|
|
3506
3607
|
elif name == "oumv_understand":
|
|
3507
3608
|
try:
|
|
3508
3609
|
from src.oumv_gateway import OUMVGateway
|
|
@@ -3638,13 +3739,19 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3638
3739
|
dry_run = bool(args.get("dry_run", False))
|
|
3639
3740
|
verify = args.get("verify")
|
|
3640
3741
|
verify_timeout = int(args.get("verify_timeout_sec") or 30)
|
|
3641
|
-
raw_cwd = args.get("cwd")
|
|
3742
|
+
raw_cwd = args.get("root") or args.get("cwd")
|
|
3642
3743
|
active_ws = _workspace_root()
|
|
3643
|
-
if raw_cwd:
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3744
|
+
if raw_cwd and not os.path.isabs(str(raw_cwd)) and active_ws and os.path.isdir(os.path.join(active_ws, str(raw_cwd))):
|
|
3745
|
+
raw_cwd = os.path.abspath(os.path.join(active_ws, str(raw_cwd)))
|
|
3746
|
+
# Absolute edit paths are accepted when they all live inside one root:
|
|
3747
|
+
# the resolver rebases them to repo-relative values and names the root.
|
|
3748
|
+
edits, abs_base, abs_err = rebase_edits(edits, cwd=raw_cwd)
|
|
3749
|
+
if abs_err:
|
|
3750
|
+
return _fallback_error("apply_edits", abs_err)
|
|
3751
|
+
if abs_base:
|
|
3752
|
+
cwd = abs_base
|
|
3753
|
+
elif raw_cwd:
|
|
3754
|
+
cwd = os.path.abspath(str(raw_cwd))
|
|
3648
3755
|
else:
|
|
3649
3756
|
cwd, err = _resolve_project_root(args)
|
|
3650
3757
|
if err or not cwd:
|
|
@@ -3765,13 +3872,15 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
|
|
|
3765
3872
|
if not queries:
|
|
3766
3873
|
return _fallback_error("batch_search", "missing required 'queries' list")
|
|
3767
3874
|
|
|
3768
|
-
raw_cwd = args.get("cwd") or args.get("project_path") or args.get("path")
|
|
3875
|
+
raw_cwd = args.get("root") or args.get("cwd") or args.get("project_path") or args.get("path")
|
|
3769
3876
|
active_ws = _workspace_root()
|
|
3770
3877
|
if raw_cwd:
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3878
|
+
resolved, _meta_info, resolve_err = resolve_input_path(
|
|
3879
|
+
raw_cwd, base=active_ws, mode="read", must_exist=True
|
|
3880
|
+
)
|
|
3881
|
+
if resolve_err:
|
|
3882
|
+
return _fallback_error("batch_search", resolve_err)
|
|
3883
|
+
cwd = os.path.dirname(resolved) if os.path.isfile(resolved) else resolved
|
|
3775
3884
|
else:
|
|
3776
3885
|
cwd, err = _resolve_project_root(args)
|
|
3777
3886
|
if err or not cwd:
|
|
@@ -4120,6 +4229,14 @@ def _tool_timeout(tool_name: str, tool_args: dict) -> float:
|
|
|
4120
4229
|
# Graph-backed calls may pay a one-time cold crawl; it is cached on disk, so
|
|
4121
4230
|
# the next call is milliseconds. TOKENSAFE_MCP_GRAPH_TIMEOUT tunes the ceiling.
|
|
4122
4231
|
return max(MCP_TOOL_TIMEOUT, MCP_GRAPH_TIMEOUT)
|
|
4232
|
+
if tool_name == "run_helper" and str(tool_args.get("action") or "").lower() in ("bundle-probe", "bundle_probe"):
|
|
4233
|
+
# Network probe: honour the caller's declared budget plus a margin so the
|
|
4234
|
+
# transport never cuts the call after its chunks were already fetched.
|
|
4235
|
+
try:
|
|
4236
|
+
declared_ms = int(tool_args.get("timeout_ms") or 6000)
|
|
4237
|
+
except (TypeError, ValueError):
|
|
4238
|
+
declared_ms = 6000
|
|
4239
|
+
return min(max(MCP_TOOL_TIMEOUT, declared_ms / 1000.0 + 2.0), 20.0)
|
|
4123
4240
|
return MCP_TOOL_TIMEOUT
|
|
4124
4241
|
|
|
4125
4242
|
|
|
@@ -4241,6 +4358,7 @@ def run_mcp_server():
|
|
|
4241
4358
|
extra_roots = workspace_roots_from_env() + workspace_roots_from_payload(params)
|
|
4242
4359
|
seen_roots = set()
|
|
4243
4360
|
extra_roots = [r for r in extra_roots if not (r in seen_roots or seen_roots.add(r))]
|
|
4361
|
+
register_roots([_oumv_default_workspace() or os.getcwd()] + extra_roots)
|
|
4244
4362
|
brief = build_workspace_brief(
|
|
4245
4363
|
_oumv_default_workspace() or os.getcwd(),
|
|
4246
4364
|
include_live=False,
|
package/src/metrics.py
CHANGED
|
@@ -693,6 +693,12 @@ class MetricsTracker:
|
|
|
693
693
|
life_saved - life_estimated
|
|
694
694
|
)
|
|
695
695
|
saved_estimated = (ev_row["active_saved_estimated"] if ev_row else 0) + life_estimated
|
|
696
|
+
if saved_estimated and saved_measured:
|
|
697
|
+
savings_basis = "mixed"
|
|
698
|
+
elif saved_estimated:
|
|
699
|
+
savings_basis = "estimated"
|
|
700
|
+
else:
|
|
701
|
+
savings_basis = "measured"
|
|
696
702
|
|
|
697
703
|
return {
|
|
698
704
|
"session_count": max(session_count, 1 if total_events > 0 else 0),
|
|
@@ -702,6 +708,7 @@ class MetricsTracker:
|
|
|
702
708
|
"total_saved_tokens": total_saved,
|
|
703
709
|
"total_saved_tokens_measured": saved_measured,
|
|
704
710
|
"total_saved_tokens_estimated": saved_estimated,
|
|
711
|
+
"total_saved_tokens_basis": savings_basis,
|
|
705
712
|
"overall_reduction_pct": round(overall_reduction, 1),
|
|
706
713
|
"total_usd_saved": round(total_usd, 4),
|
|
707
714
|
"total_usd_saved_approx": True, # USD is a derived estimate (~$3.0/M Claude Sonnet baseline), never a bill
|