windows-exe-decompiler-mcp-server 0.1.0
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_INSTALLATION.md +69 -0
- package/COPILOT_INSTALLATION.md +77 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/bin/windows-exe-decompiler-mcp-server.js +3 -0
- package/dist/analysis-provenance.d.ts +184 -0
- package/dist/analysis-provenance.js +74 -0
- package/dist/analysis-task-runner.d.ts +31 -0
- package/dist/analysis-task-runner.js +160 -0
- package/dist/artifact-inventory.d.ts +23 -0
- package/dist/artifact-inventory.js +175 -0
- package/dist/cache-manager.d.ts +128 -0
- package/dist/cache-manager.js +454 -0
- package/dist/confidence-semantics.d.ts +66 -0
- package/dist/confidence-semantics.js +122 -0
- package/dist/config.d.ts +335 -0
- package/dist/config.js +193 -0
- package/dist/database.d.ts +227 -0
- package/dist/database.js +601 -0
- package/dist/decompiler-worker.d.ts +441 -0
- package/dist/decompiler-worker.js +1962 -0
- package/dist/dynamic-trace.d.ts +95 -0
- package/dist/dynamic-trace.js +629 -0
- package/dist/env-validator.d.ts +15 -0
- package/dist/env-validator.js +249 -0
- package/dist/error-handler.d.ts +28 -0
- package/dist/error-handler.example.d.ts +22 -0
- package/dist/error-handler.example.js +141 -0
- package/dist/error-handler.js +139 -0
- package/dist/ghidra-analysis-status.d.ts +49 -0
- package/dist/ghidra-analysis-status.js +178 -0
- package/dist/ghidra-config.d.ts +134 -0
- package/dist/ghidra-config.js +464 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +200 -0
- package/dist/job-queue.d.ts +169 -0
- package/dist/job-queue.js +407 -0
- package/dist/logger.d.ts +106 -0
- package/dist/logger.js +176 -0
- package/dist/policy-guard.d.ts +115 -0
- package/dist/policy-guard.js +243 -0
- package/dist/process-output.d.ts +15 -0
- package/dist/process-output.js +90 -0
- package/dist/prompts/function-explanation-review.d.ts +5 -0
- package/dist/prompts/function-explanation-review.js +64 -0
- package/dist/prompts/semantic-name-review.d.ts +5 -0
- package/dist/prompts/semantic-name-review.js +63 -0
- package/dist/runtime-correlation.d.ts +34 -0
- package/dist/runtime-correlation.js +279 -0
- package/dist/runtime-paths.d.ts +3 -0
- package/dist/runtime-paths.js +11 -0
- package/dist/selection-diff.d.ts +667 -0
- package/dist/selection-diff.js +53 -0
- package/dist/semantic-name-suggestion-artifacts.d.ts +116 -0
- package/dist/semantic-name-suggestion-artifacts.js +314 -0
- package/dist/server.d.ts +129 -0
- package/dist/server.js +578 -0
- package/dist/tools/artifact-read.d.ts +235 -0
- package/dist/tools/artifact-read.js +317 -0
- package/dist/tools/artifacts-diff.d.ts +728 -0
- package/dist/tools/artifacts-diff.js +304 -0
- package/dist/tools/artifacts-list.d.ts +515 -0
- package/dist/tools/artifacts-list.js +389 -0
- package/dist/tools/attack-map.d.ts +290 -0
- package/dist/tools/attack-map.js +519 -0
- package/dist/tools/cache-observability.d.ts +4 -0
- package/dist/tools/cache-observability.js +36 -0
- package/dist/tools/code-function-cfg.d.ts +50 -0
- package/dist/tools/code-function-cfg.js +102 -0
- package/dist/tools/code-function-decompile.d.ts +55 -0
- package/dist/tools/code-function-decompile.js +103 -0
- package/dist/tools/code-function-disassemble.d.ts +43 -0
- package/dist/tools/code-function-disassemble.js +185 -0
- package/dist/tools/code-function-explain-apply.d.ts +255 -0
- package/dist/tools/code-function-explain-apply.js +225 -0
- package/dist/tools/code-function-explain-prepare.d.ts +535 -0
- package/dist/tools/code-function-explain-prepare.js +276 -0
- package/dist/tools/code-function-explain-review.d.ts +397 -0
- package/dist/tools/code-function-explain-review.js +589 -0
- package/dist/tools/code-function-rename-apply.d.ts +248 -0
- package/dist/tools/code-function-rename-apply.js +220 -0
- package/dist/tools/code-function-rename-prepare.d.ts +506 -0
- package/dist/tools/code-function-rename-prepare.js +279 -0
- package/dist/tools/code-function-rename-review.d.ts +574 -0
- package/dist/tools/code-function-rename-review.js +761 -0
- package/dist/tools/code-functions-list.d.ts +37 -0
- package/dist/tools/code-functions-list.js +91 -0
- package/dist/tools/code-functions-rank.d.ts +34 -0
- package/dist/tools/code-functions-rank.js +90 -0
- package/dist/tools/code-functions-reconstruct.d.ts +2725 -0
- package/dist/tools/code-functions-reconstruct.js +2807 -0
- package/dist/tools/code-functions-search.d.ts +39 -0
- package/dist/tools/code-functions-search.js +90 -0
- package/dist/tools/code-reconstruct-export.d.ts +1212 -0
- package/dist/tools/code-reconstruct-export.js +4002 -0
- package/dist/tools/code-reconstruct-plan.d.ts +274 -0
- package/dist/tools/code-reconstruct-plan.js +342 -0
- package/dist/tools/dotnet-metadata-extract.d.ts +541 -0
- package/dist/tools/dotnet-metadata-extract.js +355 -0
- package/dist/tools/dotnet-reconstruct-export.d.ts +567 -0
- package/dist/tools/dotnet-reconstruct-export.js +1151 -0
- package/dist/tools/dotnet-types-list.d.ts +325 -0
- package/dist/tools/dotnet-types-list.js +201 -0
- package/dist/tools/dynamic-dependencies.d.ts +115 -0
- package/dist/tools/dynamic-dependencies.js +213 -0
- package/dist/tools/dynamic-memory-import.d.ts +10 -0
- package/dist/tools/dynamic-memory-import.js +567 -0
- package/dist/tools/dynamic-trace-import.d.ts +10 -0
- package/dist/tools/dynamic-trace-import.js +235 -0
- package/dist/tools/entrypoint-fallback-disasm.d.ts +30 -0
- package/dist/tools/entrypoint-fallback-disasm.js +89 -0
- package/dist/tools/ghidra-analyze.d.ts +88 -0
- package/dist/tools/ghidra-analyze.js +208 -0
- package/dist/tools/ghidra-health.d.ts +37 -0
- package/dist/tools/ghidra-health.js +212 -0
- package/dist/tools/ioc-export.d.ts +209 -0
- package/dist/tools/ioc-export.js +542 -0
- package/dist/tools/packer-detect.d.ts +165 -0
- package/dist/tools/packer-detect.js +284 -0
- package/dist/tools/pe-exports-extract.d.ts +175 -0
- package/dist/tools/pe-exports-extract.js +253 -0
- package/dist/tools/pe-fingerprint.d.ts +234 -0
- package/dist/tools/pe-fingerprint.js +269 -0
- package/dist/tools/pe-imports-extract.d.ts +105 -0
- package/dist/tools/pe-imports-extract.js +245 -0
- package/dist/tools/report-generate.d.ts +157 -0
- package/dist/tools/report-generate.js +457 -0
- package/dist/tools/report-summarize.d.ts +2131 -0
- package/dist/tools/report-summarize.js +596 -0
- package/dist/tools/runtime-detect.d.ts +135 -0
- package/dist/tools/runtime-detect.js +247 -0
- package/dist/tools/sample-ingest.d.ts +94 -0
- package/dist/tools/sample-ingest.js +327 -0
- package/dist/tools/sample-profile-get.d.ts +183 -0
- package/dist/tools/sample-profile-get.js +121 -0
- package/dist/tools/sandbox-execute.d.ts +441 -0
- package/dist/tools/sandbox-execute.js +392 -0
- package/dist/tools/strings-extract.d.ts +375 -0
- package/dist/tools/strings-extract.js +314 -0
- package/dist/tools/strings-floss-decode.d.ts +143 -0
- package/dist/tools/strings-floss-decode.js +259 -0
- package/dist/tools/system-health.d.ts +434 -0
- package/dist/tools/system-health.js +446 -0
- package/dist/tools/task-cancel.d.ts +21 -0
- package/dist/tools/task-cancel.js +70 -0
- package/dist/tools/task-status.d.ts +27 -0
- package/dist/tools/task-status.js +106 -0
- package/dist/tools/task-sweep.d.ts +22 -0
- package/dist/tools/task-sweep.js +77 -0
- package/dist/tools/tool-help.d.ts +340 -0
- package/dist/tools/tool-help.js +261 -0
- package/dist/tools/yara-scan.d.ts +554 -0
- package/dist/tools/yara-scan.js +313 -0
- package/dist/types.d.ts +266 -0
- package/dist/types.js +41 -0
- package/dist/worker-pool.d.ts +204 -0
- package/dist/worker-pool.js +650 -0
- package/dist/workflows/deep-static.d.ts +104 -0
- package/dist/workflows/deep-static.js +276 -0
- package/dist/workflows/function-explanation-review.d.ts +655 -0
- package/dist/workflows/function-explanation-review.js +440 -0
- package/dist/workflows/reconstruct.d.ts +2053 -0
- package/dist/workflows/reconstruct.js +666 -0
- package/dist/workflows/semantic-name-review.d.ts +2418 -0
- package/dist/workflows/semantic-name-review.js +521 -0
- package/dist/workflows/triage.d.ts +659 -0
- package/dist/workflows/triage.js +1374 -0
- package/dist/workspace-manager.d.ts +150 -0
- package/dist/workspace-manager.js +411 -0
- package/ghidra_scripts/DecompileFunction.java +487 -0
- package/ghidra_scripts/DecompileFunction.py +150 -0
- package/ghidra_scripts/ExtractCFG.java +256 -0
- package/ghidra_scripts/ExtractCFG.py +233 -0
- package/ghidra_scripts/ExtractFunctions.java +442 -0
- package/ghidra_scripts/ExtractFunctions.py +101 -0
- package/ghidra_scripts/README.md +125 -0
- package/ghidra_scripts/SearchFunctionReferences.java +380 -0
- package/helpers/DotNetMetadataProbe/DotNetMetadataProbe.csproj +9 -0
- package/helpers/DotNetMetadataProbe/Program.cs +566 -0
- package/install-to-codex.ps1 +178 -0
- package/install-to-copilot.ps1 +303 -0
- package/package.json +101 -0
- package/requirements.txt +9 -0
- package/workers/requirements-dynamic.txt +11 -0
- package/workers/requirements.txt +8 -0
- package/workers/speakeasy_compat.py +175 -0
- package/workers/static_worker.py +5183 -0
- package/workers/yara_rules/default.yar +33 -0
- package/workers/yara_rules/malware_families.yar +93 -0
- package/workers/yara_rules/packers.yar +80 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workflow.semantic_name_review
|
|
3
|
+
* High-level orchestration for semantic naming review plus optional reconstruct export refresh.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { createCodeFunctionRenameReviewHandler } from '../tools/code-function-rename-review.js';
|
|
7
|
+
import { createReconstructWorkflowHandler } from './reconstruct.js';
|
|
8
|
+
import { AnalysisProvenanceSchema } from '../analysis-provenance.js';
|
|
9
|
+
import { AnalysisSelectionDiffSchema } from '../selection-diff.js';
|
|
10
|
+
const TOOL_NAME = 'workflow.semantic_name_review';
|
|
11
|
+
export const semanticNameReviewWorkflowInputSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
sample_id: z.string().describe('Sample ID (format: sha256:<hex>)'),
|
|
14
|
+
address: z.string().optional().describe('Optional specific function address'),
|
|
15
|
+
symbol: z.string().optional().describe('Optional specific function symbol'),
|
|
16
|
+
topk: z
|
|
17
|
+
.number()
|
|
18
|
+
.int()
|
|
19
|
+
.min(1)
|
|
20
|
+
.max(20)
|
|
21
|
+
.default(6)
|
|
22
|
+
.describe('When address/symbol not provided, review up to top-K functions'),
|
|
23
|
+
max_functions: z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.min(1)
|
|
27
|
+
.max(20)
|
|
28
|
+
.default(6)
|
|
29
|
+
.describe('Maximum number of functions included in the naming review bundle'),
|
|
30
|
+
include_resolved: z
|
|
31
|
+
.boolean()
|
|
32
|
+
.default(false)
|
|
33
|
+
.describe('Include already resolved functions in the initial review request'),
|
|
34
|
+
auto_include_resolved_on_empty: z
|
|
35
|
+
.boolean()
|
|
36
|
+
.default(true)
|
|
37
|
+
.describe('Retry in audit mode with include_resolved=true when unresolved selection is empty'),
|
|
38
|
+
analysis_goal: z
|
|
39
|
+
.string()
|
|
40
|
+
.min(1)
|
|
41
|
+
.max(400)
|
|
42
|
+
.default('Reverse-engineer the prepared functions and propose precise human-readable semantic names.')
|
|
43
|
+
.describe('Human-readable analysis goal injected into the MCP prompt and sampling request'),
|
|
44
|
+
session_tag: z
|
|
45
|
+
.string()
|
|
46
|
+
.optional()
|
|
47
|
+
.describe('Optional semantic naming session tag used for artifact grouping'),
|
|
48
|
+
evidence_scope: z
|
|
49
|
+
.enum(['all', 'latest', 'session'])
|
|
50
|
+
.default('all')
|
|
51
|
+
.describe('Runtime evidence scope forwarded to review and optional reconstruct/export refresh'),
|
|
52
|
+
evidence_session_tag: z
|
|
53
|
+
.string()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe('Optional runtime evidence session selector used when evidence_scope=session or to narrow all/latest results'),
|
|
56
|
+
semantic_scope: z
|
|
57
|
+
.enum(['all', 'latest', 'session'])
|
|
58
|
+
.default('all')
|
|
59
|
+
.describe('Semantic naming artifact scope used for review and optional reconstruct/export refresh'),
|
|
60
|
+
semantic_session_tag: z
|
|
61
|
+
.string()
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('Optional semantic naming session selector used when semantic_scope=session or to narrow all/latest results'),
|
|
64
|
+
compare_evidence_scope: z
|
|
65
|
+
.enum(['all', 'latest', 'session'])
|
|
66
|
+
.optional()
|
|
67
|
+
.describe('Optional baseline runtime evidence scope used when refreshing export for comparison-aware workflow output'),
|
|
68
|
+
compare_evidence_session_tag: z
|
|
69
|
+
.string()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('Optional baseline runtime evidence session selector used when compare_evidence_scope=session'),
|
|
72
|
+
compare_semantic_scope: z
|
|
73
|
+
.enum(['all', 'latest', 'session'])
|
|
74
|
+
.optional()
|
|
75
|
+
.describe('Optional baseline semantic artifact scope used when refreshing export for comparison-aware workflow output'),
|
|
76
|
+
compare_semantic_session_tag: z
|
|
77
|
+
.string()
|
|
78
|
+
.optional()
|
|
79
|
+
.describe('Optional baseline semantic artifact session selector used when compare_semantic_scope=session'),
|
|
80
|
+
persist_artifact: z
|
|
81
|
+
.boolean()
|
|
82
|
+
.default(true)
|
|
83
|
+
.describe('Persist the prepare bundle artifact before requesting external semantic review'),
|
|
84
|
+
auto_apply: z
|
|
85
|
+
.boolean()
|
|
86
|
+
.default(true)
|
|
87
|
+
.describe('Persist accepted suggestions automatically via code.function.rename.apply'),
|
|
88
|
+
rerun_reconstruct: z
|
|
89
|
+
.boolean()
|
|
90
|
+
.default(true)
|
|
91
|
+
.describe('Rerun code.functions.reconstruct after apply to materialize llm/hybrid validated names'),
|
|
92
|
+
temperature: z
|
|
93
|
+
.number()
|
|
94
|
+
.min(0)
|
|
95
|
+
.max(1)
|
|
96
|
+
.default(0.2)
|
|
97
|
+
.describe('Sampling temperature passed to the connected MCP client'),
|
|
98
|
+
max_tokens: z
|
|
99
|
+
.number()
|
|
100
|
+
.int()
|
|
101
|
+
.min(200)
|
|
102
|
+
.max(8000)
|
|
103
|
+
.default(1800)
|
|
104
|
+
.describe('Maximum sampling tokens requested from the connected MCP client'),
|
|
105
|
+
include_context: z
|
|
106
|
+
.enum(['none', 'thisServer', 'allServers'])
|
|
107
|
+
.default('none')
|
|
108
|
+
.describe('Requested MCP sampling context scope; clients may ignore this preference'),
|
|
109
|
+
model_hint: z
|
|
110
|
+
.string()
|
|
111
|
+
.min(1)
|
|
112
|
+
.max(120)
|
|
113
|
+
.optional()
|
|
114
|
+
.describe('Optional advisory model-family hint for client-mediated MCP sampling'),
|
|
115
|
+
cost_priority: z
|
|
116
|
+
.number()
|
|
117
|
+
.min(0)
|
|
118
|
+
.max(1)
|
|
119
|
+
.default(0.1)
|
|
120
|
+
.describe('Advisory model selection preference for sampling cost'),
|
|
121
|
+
speed_priority: z
|
|
122
|
+
.number()
|
|
123
|
+
.min(0)
|
|
124
|
+
.max(1)
|
|
125
|
+
.default(0.2)
|
|
126
|
+
.describe('Advisory model selection preference for sampling latency'),
|
|
127
|
+
intelligence_priority: z
|
|
128
|
+
.number()
|
|
129
|
+
.min(0)
|
|
130
|
+
.max(1)
|
|
131
|
+
.default(0.95)
|
|
132
|
+
.describe('Advisory model selection preference for reasoning quality'),
|
|
133
|
+
system_prompt: z
|
|
134
|
+
.string()
|
|
135
|
+
.min(1)
|
|
136
|
+
.max(800)
|
|
137
|
+
.optional()
|
|
138
|
+
.describe('Optional extra system prompt for the client-mediated semantic naming review'),
|
|
139
|
+
rerun_export: z
|
|
140
|
+
.boolean()
|
|
141
|
+
.default(true)
|
|
142
|
+
.describe('After successful apply, rerun workflow.reconstruct to refresh rewrite/export output'),
|
|
143
|
+
export_path: z
|
|
144
|
+
.enum(['auto', 'native', 'dotnet'])
|
|
145
|
+
.default('auto')
|
|
146
|
+
.describe('Routing strategy used when rerun_export=true'),
|
|
147
|
+
export_topk: z
|
|
148
|
+
.number()
|
|
149
|
+
.int()
|
|
150
|
+
.min(1)
|
|
151
|
+
.max(40)
|
|
152
|
+
.default(12)
|
|
153
|
+
.describe('Top-K high-value functions used for optional reconstruct/export refresh'),
|
|
154
|
+
export_name: z
|
|
155
|
+
.string()
|
|
156
|
+
.min(1)
|
|
157
|
+
.max(64)
|
|
158
|
+
.optional()
|
|
159
|
+
.describe('Optional export folder name used for the refresh run'),
|
|
160
|
+
include_plan: z
|
|
161
|
+
.boolean()
|
|
162
|
+
.default(false)
|
|
163
|
+
.describe('Include code.reconstruct.plan when rerun_export=true'),
|
|
164
|
+
include_obfuscation_fallback: z
|
|
165
|
+
.boolean()
|
|
166
|
+
.default(true)
|
|
167
|
+
.describe('When routing to .NET path, generate IL fallback notes when needed'),
|
|
168
|
+
fallback_on_error: z
|
|
169
|
+
.boolean()
|
|
170
|
+
.default(true)
|
|
171
|
+
.describe('When primary export path fails, automatically try the alternative path'),
|
|
172
|
+
allow_partial: z
|
|
173
|
+
.boolean()
|
|
174
|
+
.default(true)
|
|
175
|
+
.describe('When all export paths fail, still return runtime/plan as partial output'),
|
|
176
|
+
validate_build: z
|
|
177
|
+
.boolean()
|
|
178
|
+
.default(false)
|
|
179
|
+
.describe('Compile the refreshed native reconstruction when rerun_export=true'),
|
|
180
|
+
run_harness: z
|
|
181
|
+
.boolean()
|
|
182
|
+
.default(false)
|
|
183
|
+
.describe('Execute reconstruct_harness after a successful refreshed native build'),
|
|
184
|
+
compiler_path: z
|
|
185
|
+
.string()
|
|
186
|
+
.min(1)
|
|
187
|
+
.max(260)
|
|
188
|
+
.optional()
|
|
189
|
+
.describe('Optional explicit clang compiler path for the refresh run'),
|
|
190
|
+
build_timeout_ms: z
|
|
191
|
+
.number()
|
|
192
|
+
.int()
|
|
193
|
+
.min(5000)
|
|
194
|
+
.max(300000)
|
|
195
|
+
.default(60000)
|
|
196
|
+
.describe('Timeout for native clang build validation in milliseconds'),
|
|
197
|
+
run_timeout_ms: z
|
|
198
|
+
.number()
|
|
199
|
+
.int()
|
|
200
|
+
.min(5000)
|
|
201
|
+
.max(300000)
|
|
202
|
+
.default(30000)
|
|
203
|
+
.describe('Timeout for reconstruct_harness execution in milliseconds'),
|
|
204
|
+
reuse_cached: z
|
|
205
|
+
.boolean()
|
|
206
|
+
.default(true)
|
|
207
|
+
.describe('Reuse cached reconstruct workflow results for the optional refresh run'),
|
|
208
|
+
})
|
|
209
|
+
.refine((value) => value.evidence_scope !== 'session' || Boolean(value.evidence_session_tag?.trim()), {
|
|
210
|
+
message: 'evidence_session_tag is required when evidence_scope=session',
|
|
211
|
+
path: ['evidence_session_tag'],
|
|
212
|
+
})
|
|
213
|
+
.refine((value) => value.semantic_scope !== 'session' || Boolean(value.semantic_session_tag?.trim()), {
|
|
214
|
+
message: 'semantic_session_tag is required when semantic_scope=session',
|
|
215
|
+
path: ['semantic_session_tag'],
|
|
216
|
+
})
|
|
217
|
+
.refine((value) => value.compare_evidence_scope !== 'session' || Boolean(value.compare_evidence_session_tag?.trim()), {
|
|
218
|
+
message: 'compare_evidence_session_tag is required when compare_evidence_scope=session',
|
|
219
|
+
path: ['compare_evidence_session_tag'],
|
|
220
|
+
})
|
|
221
|
+
.refine((value) => value.compare_semantic_scope !== 'session' || Boolean(value.compare_semantic_session_tag?.trim()), {
|
|
222
|
+
message: 'compare_semantic_session_tag is required when compare_semantic_scope=session',
|
|
223
|
+
path: ['compare_semantic_session_tag'],
|
|
224
|
+
});
|
|
225
|
+
export const semanticNameReviewWorkflowOutputSchema = z.object({
|
|
226
|
+
ok: z.boolean(),
|
|
227
|
+
data: z
|
|
228
|
+
.object({
|
|
229
|
+
sample_id: z.string(),
|
|
230
|
+
review: z.object({
|
|
231
|
+
review_status: z.string(),
|
|
232
|
+
prompt_name: z.string(),
|
|
233
|
+
client: z.object({
|
|
234
|
+
name: z.string().nullable(),
|
|
235
|
+
version: z.string().nullable(),
|
|
236
|
+
sampling_available: z.boolean(),
|
|
237
|
+
}),
|
|
238
|
+
prepare: z.object({
|
|
239
|
+
prepared_count: z.number().int().nonnegative(),
|
|
240
|
+
unresolved_count: z.number().int().nonnegative(),
|
|
241
|
+
include_resolved: z.boolean(),
|
|
242
|
+
artifact_id: z.string().nullable(),
|
|
243
|
+
}),
|
|
244
|
+
sampling: z.object({
|
|
245
|
+
attempted: z.boolean(),
|
|
246
|
+
model: z.string().nullable(),
|
|
247
|
+
stop_reason: z.string().nullable(),
|
|
248
|
+
parsed_suggestion_count: z.number().int().nonnegative(),
|
|
249
|
+
}),
|
|
250
|
+
apply: z.object({
|
|
251
|
+
attempted: z.boolean(),
|
|
252
|
+
accepted_count: z.number().int().nonnegative(),
|
|
253
|
+
rejected_count: z.number().int().nonnegative(),
|
|
254
|
+
artifact_id: z.string().nullable(),
|
|
255
|
+
}),
|
|
256
|
+
confidence_policy: z.object({
|
|
257
|
+
calibrated: z.boolean(),
|
|
258
|
+
rule_priority_over_llm: z.boolean(),
|
|
259
|
+
llm_acceptance_threshold: z.number().min(0).max(1),
|
|
260
|
+
meaning: z.string(),
|
|
261
|
+
}),
|
|
262
|
+
reconstruct: z.object({
|
|
263
|
+
attempted: z.boolean(),
|
|
264
|
+
reconstructed_count: z.number().int().nonnegative(),
|
|
265
|
+
llm_or_hybrid_count: z.number().int().nonnegative(),
|
|
266
|
+
functions: z.array(z.object({
|
|
267
|
+
function: z.string(),
|
|
268
|
+
address: z.string(),
|
|
269
|
+
validated_name: z.string().nullable(),
|
|
270
|
+
resolution_source: z.string().nullable(),
|
|
271
|
+
})),
|
|
272
|
+
}),
|
|
273
|
+
}),
|
|
274
|
+
export: z.object({
|
|
275
|
+
attempted: z.boolean(),
|
|
276
|
+
status: z.enum(['completed', 'failed', 'skipped']),
|
|
277
|
+
selected_path: z.enum(['native', 'dotnet']).nullable(),
|
|
278
|
+
export_tool: z.string().nullable(),
|
|
279
|
+
export_root: z.string().nullable(),
|
|
280
|
+
manifest_path: z.string().nullable(),
|
|
281
|
+
build_validation_status: z.string().nullable(),
|
|
282
|
+
harness_validation_status: z.string().nullable(),
|
|
283
|
+
provenance: AnalysisProvenanceSchema.nullable(),
|
|
284
|
+
selection_diffs: AnalysisSelectionDiffSchema.nullable(),
|
|
285
|
+
notes: z.array(z.string()),
|
|
286
|
+
}),
|
|
287
|
+
next_steps: z.array(z.string()),
|
|
288
|
+
})
|
|
289
|
+
.optional(),
|
|
290
|
+
warnings: z.array(z.string()).optional(),
|
|
291
|
+
errors: z.array(z.string()).optional(),
|
|
292
|
+
artifacts: z.array(z.any()).optional(),
|
|
293
|
+
metrics: z
|
|
294
|
+
.object({
|
|
295
|
+
elapsed_ms: z.number(),
|
|
296
|
+
tool: z.string(),
|
|
297
|
+
})
|
|
298
|
+
.optional(),
|
|
299
|
+
});
|
|
300
|
+
export const semanticNameReviewWorkflowToolDefinition = {
|
|
301
|
+
name: TOOL_NAME,
|
|
302
|
+
description: 'Run semantic naming review end-to-end for any MCP-capable LLM client, then optionally refresh reconstruct/export output with the applied names.',
|
|
303
|
+
inputSchema: semanticNameReviewWorkflowInputSchema,
|
|
304
|
+
outputSchema: semanticNameReviewWorkflowOutputSchema,
|
|
305
|
+
};
|
|
306
|
+
export function createSemanticNameReviewWorkflowHandler(workspaceManager, database, cacheManager, mcpServer, dependencies) {
|
|
307
|
+
const renameReviewHandler = dependencies?.renameReviewHandler ||
|
|
308
|
+
createCodeFunctionRenameReviewHandler(workspaceManager, database, cacheManager, mcpServer);
|
|
309
|
+
const reconstructWorkflowHandler = dependencies?.reconstructWorkflowHandler ||
|
|
310
|
+
createReconstructWorkflowHandler(workspaceManager, database, cacheManager);
|
|
311
|
+
return async (args) => {
|
|
312
|
+
const startTime = Date.now();
|
|
313
|
+
const warnings = [];
|
|
314
|
+
const errors = [];
|
|
315
|
+
const artifacts = [];
|
|
316
|
+
try {
|
|
317
|
+
const input = semanticNameReviewWorkflowInputSchema.parse(args);
|
|
318
|
+
const reviewResult = await renameReviewHandler({
|
|
319
|
+
sample_id: input.sample_id,
|
|
320
|
+
address: input.address,
|
|
321
|
+
symbol: input.symbol,
|
|
322
|
+
topk: input.topk,
|
|
323
|
+
max_functions: input.max_functions,
|
|
324
|
+
include_resolved: input.include_resolved,
|
|
325
|
+
auto_include_resolved_on_empty: input.auto_include_resolved_on_empty,
|
|
326
|
+
analysis_goal: input.analysis_goal,
|
|
327
|
+
session_tag: input.session_tag,
|
|
328
|
+
evidence_scope: input.evidence_scope,
|
|
329
|
+
evidence_session_tag: input.evidence_session_tag,
|
|
330
|
+
semantic_scope: input.semantic_scope,
|
|
331
|
+
semantic_session_tag: input.semantic_session_tag,
|
|
332
|
+
persist_artifact: input.persist_artifact,
|
|
333
|
+
auto_apply: input.auto_apply,
|
|
334
|
+
rerun_reconstruct: input.rerun_reconstruct,
|
|
335
|
+
temperature: input.temperature,
|
|
336
|
+
max_tokens: input.max_tokens,
|
|
337
|
+
include_context: input.include_context,
|
|
338
|
+
model_hint: input.model_hint,
|
|
339
|
+
cost_priority: input.cost_priority,
|
|
340
|
+
speed_priority: input.speed_priority,
|
|
341
|
+
intelligence_priority: input.intelligence_priority,
|
|
342
|
+
system_prompt: input.system_prompt,
|
|
343
|
+
});
|
|
344
|
+
warnings.push(...(reviewResult.warnings || []));
|
|
345
|
+
artifacts.push(...(reviewResult.artifacts || []));
|
|
346
|
+
if (!reviewResult.ok) {
|
|
347
|
+
return {
|
|
348
|
+
ok: false,
|
|
349
|
+
errors: reviewResult.errors || ['code.function.rename.review failed'],
|
|
350
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
351
|
+
artifacts: artifacts.length > 0 ? artifacts : undefined,
|
|
352
|
+
metrics: {
|
|
353
|
+
elapsed_ms: Date.now() - startTime,
|
|
354
|
+
tool: TOOL_NAME,
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const reviewData = (reviewResult.data || {});
|
|
359
|
+
const acceptedCount = Number(reviewData?.apply?.accepted_count || 0);
|
|
360
|
+
const llmOrHybridCount = Number(reviewData?.reconstruct?.llm_or_hybrid_count || 0);
|
|
361
|
+
const canRefreshExport = input.rerun_export &&
|
|
362
|
+
reviewData.review_status === 'sampled_and_applied' &&
|
|
363
|
+
(acceptedCount > 0 || llmOrHybridCount > 0);
|
|
364
|
+
let exportSummary = {
|
|
365
|
+
attempted: false,
|
|
366
|
+
status: 'skipped',
|
|
367
|
+
selected_path: null,
|
|
368
|
+
export_tool: null,
|
|
369
|
+
export_root: null,
|
|
370
|
+
manifest_path: null,
|
|
371
|
+
build_validation_status: null,
|
|
372
|
+
harness_validation_status: null,
|
|
373
|
+
provenance: null,
|
|
374
|
+
selection_diffs: null,
|
|
375
|
+
notes: [],
|
|
376
|
+
};
|
|
377
|
+
if (canRefreshExport) {
|
|
378
|
+
const exportResult = await reconstructWorkflowHandler({
|
|
379
|
+
sample_id: input.sample_id,
|
|
380
|
+
path: input.export_path,
|
|
381
|
+
topk: input.export_topk,
|
|
382
|
+
export_name: input.export_name,
|
|
383
|
+
validate_build: input.validate_build,
|
|
384
|
+
run_harness: input.run_harness,
|
|
385
|
+
compiler_path: input.compiler_path,
|
|
386
|
+
build_timeout_ms: input.build_timeout_ms,
|
|
387
|
+
run_timeout_ms: input.run_timeout_ms,
|
|
388
|
+
evidence_scope: input.evidence_scope,
|
|
389
|
+
evidence_session_tag: input.evidence_session_tag,
|
|
390
|
+
compare_evidence_scope: input.compare_evidence_scope,
|
|
391
|
+
compare_evidence_session_tag: input.compare_evidence_session_tag,
|
|
392
|
+
semantic_scope: input.semantic_scope === 'all' && input.session_tag ? 'session' : input.semantic_scope,
|
|
393
|
+
semantic_session_tag: input.semantic_session_tag || input.session_tag,
|
|
394
|
+
compare_semantic_scope: input.compare_semantic_scope,
|
|
395
|
+
compare_semantic_session_tag: input.compare_semantic_session_tag,
|
|
396
|
+
include_plan: input.include_plan,
|
|
397
|
+
include_obfuscation_fallback: input.include_obfuscation_fallback,
|
|
398
|
+
fallback_on_error: input.fallback_on_error,
|
|
399
|
+
allow_partial: input.allow_partial,
|
|
400
|
+
reuse_cached: input.reuse_cached,
|
|
401
|
+
});
|
|
402
|
+
warnings.push(...(exportResult.warnings || []));
|
|
403
|
+
artifacts.push(...(exportResult.artifacts || []));
|
|
404
|
+
if (!exportResult.ok) {
|
|
405
|
+
errors.push(...(exportResult.errors || ['workflow.reconstruct failed during export refresh']));
|
|
406
|
+
exportSummary = {
|
|
407
|
+
attempted: true,
|
|
408
|
+
status: 'failed',
|
|
409
|
+
selected_path: null,
|
|
410
|
+
export_tool: null,
|
|
411
|
+
export_root: null,
|
|
412
|
+
manifest_path: null,
|
|
413
|
+
build_validation_status: null,
|
|
414
|
+
harness_validation_status: null,
|
|
415
|
+
provenance: null,
|
|
416
|
+
selection_diffs: null,
|
|
417
|
+
notes: ['Refresh export failed after semantic name apply.'],
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
const exportData = (exportResult.data || {});
|
|
422
|
+
exportSummary = {
|
|
423
|
+
attempted: true,
|
|
424
|
+
status: 'completed',
|
|
425
|
+
selected_path: exportData.selected_path || null,
|
|
426
|
+
export_tool: exportData.export?.tool || null,
|
|
427
|
+
export_root: exportData.export?.export_root || null,
|
|
428
|
+
manifest_path: exportData.export?.manifest_path || null,
|
|
429
|
+
build_validation_status: exportData.export?.build_validation_status || null,
|
|
430
|
+
harness_validation_status: exportData.export?.harness_validation_status || null,
|
|
431
|
+
provenance: exportData.provenance || null,
|
|
432
|
+
selection_diffs: exportData.selection_diffs || null,
|
|
433
|
+
notes: Array.isArray(exportData.notes) ? exportData.notes : [],
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
else if (input.rerun_export) {
|
|
438
|
+
exportSummary.notes.push(reviewData.review_status === 'prompt_contract_only'
|
|
439
|
+
? 'Refresh export skipped because no sampled suggestions were applied yet.'
|
|
440
|
+
: 'Refresh export skipped because no llm/hybrid name updates were materialized.');
|
|
441
|
+
}
|
|
442
|
+
const nextSteps = [
|
|
443
|
+
...(Array.isArray(reviewData.next_steps) ? reviewData.next_steps : []),
|
|
444
|
+
...exportSummary.notes,
|
|
445
|
+
];
|
|
446
|
+
return {
|
|
447
|
+
ok: errors.length === 0,
|
|
448
|
+
data: {
|
|
449
|
+
sample_id: input.sample_id,
|
|
450
|
+
review: {
|
|
451
|
+
review_status: reviewData.review_status || 'unknown',
|
|
452
|
+
prompt_name: reviewData.prompt_name || 'reverse.semantic_name_review',
|
|
453
|
+
client: {
|
|
454
|
+
name: reviewData.client?.name || null,
|
|
455
|
+
version: reviewData.client?.version || null,
|
|
456
|
+
sampling_available: Boolean(reviewData.client?.sampling_available),
|
|
457
|
+
},
|
|
458
|
+
prepare: {
|
|
459
|
+
prepared_count: Number(reviewData.prepare?.prepared_count || 0),
|
|
460
|
+
unresolved_count: Number(reviewData.prepare?.unresolved_count || 0),
|
|
461
|
+
include_resolved: Boolean(reviewData.prepare?.include_resolved),
|
|
462
|
+
artifact_id: reviewData.prepare?.artifact_id || null,
|
|
463
|
+
},
|
|
464
|
+
sampling: {
|
|
465
|
+
attempted: Boolean(reviewData.sampling?.attempted),
|
|
466
|
+
model: reviewData.sampling?.model || null,
|
|
467
|
+
stop_reason: reviewData.sampling?.stop_reason || null,
|
|
468
|
+
parsed_suggestion_count: Number(reviewData.sampling?.parsed_suggestion_count || 0),
|
|
469
|
+
},
|
|
470
|
+
apply: {
|
|
471
|
+
attempted: Boolean(reviewData.apply?.attempted),
|
|
472
|
+
accepted_count: acceptedCount,
|
|
473
|
+
rejected_count: Number(reviewData.apply?.rejected_count || 0),
|
|
474
|
+
artifact_id: reviewData.apply?.artifact_id || null,
|
|
475
|
+
},
|
|
476
|
+
confidence_policy: {
|
|
477
|
+
calibrated: Boolean(reviewData.confidence_policy?.calibrated),
|
|
478
|
+
rule_priority_over_llm: reviewData.confidence_policy?.rule_priority_over_llm !== false,
|
|
479
|
+
llm_acceptance_threshold: Number(reviewData.confidence_policy?.llm_acceptance_threshold ?? 0.62),
|
|
480
|
+
meaning: String(reviewData.confidence_policy?.meaning ||
|
|
481
|
+
'Naming confidence remains heuristic. Rule-based names currently take priority, and pure LLM suggestions are promoted only after meeting the acceptance threshold.'),
|
|
482
|
+
},
|
|
483
|
+
reconstruct: {
|
|
484
|
+
attempted: Boolean(reviewData.reconstruct?.attempted),
|
|
485
|
+
reconstructed_count: Number(reviewData.reconstruct?.reconstructed_count || 0),
|
|
486
|
+
llm_or_hybrid_count: llmOrHybridCount,
|
|
487
|
+
functions: Array.isArray(reviewData.reconstruct?.functions)
|
|
488
|
+
? reviewData.reconstruct.functions.map((item) => ({
|
|
489
|
+
function: String(item.function || ''),
|
|
490
|
+
address: String(item.address || ''),
|
|
491
|
+
validated_name: item.validated_name || null,
|
|
492
|
+
resolution_source: item.resolution_source || null,
|
|
493
|
+
}))
|
|
494
|
+
: [],
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
export: exportSummary,
|
|
498
|
+
next_steps: nextSteps,
|
|
499
|
+
},
|
|
500
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
501
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
502
|
+
artifacts: artifacts.length > 0 ? artifacts : undefined,
|
|
503
|
+
metrics: {
|
|
504
|
+
elapsed_ms: Date.now() - startTime,
|
|
505
|
+
tool: TOOL_NAME,
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
return {
|
|
511
|
+
ok: false,
|
|
512
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
513
|
+
metrics: {
|
|
514
|
+
elapsed_ms: Date.now() - startTime,
|
|
515
|
+
tool: TOOL_NAME,
|
|
516
|
+
},
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
//# sourceMappingURL=semantic-name-review.js.map
|