-
Notifications
You must be signed in to change notification settings - Fork 2
[UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default with .dil file persistence
#235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default with .dil file persistence
#235
Changes from 3 commits
9c89b29
7e6bf0d
f19ee41
d927751
a8b8c8f
15d537f
309c2b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "toolName": "codeql_query_compile", | ||
| "arguments": { | ||
|
data-douser marked this conversation as resolved.
|
||
| "query": "server/ql/javascript/examples/src/ExampleQuery1/ExampleQuery1.ql" | ||
|
data-douser marked this conversation as resolved.
|
||
| }, | ||
|
data-douser marked this conversation as resolved.
|
||
| "assertions": { | ||
| "responseContains": ["DIL file:", ".dil"] | ||
| } | ||
| } | ||
|
data-douser marked this conversation as resolved.
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ import { resolveQueryPath } from './query-resolver'; | |
| import { cacheDatabaseAnalyzeResults, processQueryRunResults } from './result-processor'; | ||
| import { getUserWorkspaceDir, packageRootDir } from '../utils/package-paths'; | ||
| import { existsSync, mkdirSync, realpathSync, rmSync, writeFileSync } from 'fs'; | ||
| import { delimiter, dirname, isAbsolute, join, resolve } from 'path'; | ||
| import { delimiter, dirname, basename, isAbsolute, join, resolve } from 'path'; | ||
|
data-douser marked this conversation as resolved.
Outdated
|
||
| import * as yaml from 'js-yaml'; | ||
| import { createProjectTempDir } from '../utils/temp-dir'; | ||
|
|
||
|
|
@@ -459,8 +459,28 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition | |
| } | ||
|
|
||
| case 'codeql_query_compile': | ||
| // Handle query parameter as positional argument | ||
| if (query) { | ||
| positionalArgs = [...positionalArgs, query as string]; | ||
| } | ||
| // Enable --dump-dil by default unless the user explicitly set | ||
| // dump-dil to false or passed --no-dump-dil / --dump-dil in | ||
| // additionalArgs (which takes precedence). | ||
| if (options['dump-dil'] === undefined) { | ||
| const pending = Array.isArray(options.additionalArgs) | ||
| ? options.additionalArgs as string[] | ||
| : []; | ||
| const hasDilOverride = pending.some( | ||
| arg => arg === '--no-dump-dil' || arg === '--dump-dil' | ||
| ); | ||
| if (!hasDilOverride) { | ||
| options['dump-dil'] = true; | ||
| } | ||
| } | ||
| break; | ||
|
|
||
| case 'codeql_resolve_metadata': | ||
| // Handle query parameter as positional argument for query compilation and metadata tools | ||
| // Handle query parameter as positional argument for metadata tools | ||
| if (query) { | ||
| positionalArgs = [...positionalArgs, query as string]; | ||
| } | ||
|
|
@@ -536,6 +556,13 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition | |
| } | ||
| } | ||
|
|
||
| // Set up log directory for compile runs to persist DIL output | ||
| let compileLogDir: string | undefined; | ||
| if (name === 'codeql_query_compile' && options['dump-dil'] !== false) { | ||
| compileLogDir = getOrCreateLogDirectory(customLogDir as string | undefined); | ||
| logger.info(`Using log directory for ${name}: ${compileLogDir}`); | ||
| } | ||
|
data-douser marked this conversation as resolved.
Outdated
Comment on lines
+559
to
+571
|
||
|
|
||
| // Extract additionalArgs from options so they are passed as raw CLI | ||
| // arguments instead of being transformed into --additionalArgs=value | ||
| // by buildCodeQLArgs. | ||
|
|
@@ -697,8 +724,29 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition | |
| cacheDatabaseAnalyzeResults({ ...params, database: resolvedDb, output: options.output, format: options.format }, logger); | ||
| } | ||
|
|
||
| // Post-execution: persist DIL output to a .dil file for codeql_query_compile | ||
| let dilFilePath: string | undefined; | ||
| if (name === 'codeql_query_compile' && result.success && compileLogDir && result.stdout) { | ||
| try { | ||
| const queryBaseName = query | ||
| ? basename(query as string, '.ql') | ||
| : 'query'; | ||
| dilFilePath = join(compileLogDir, `${queryBaseName}.dil`); | ||
| writeFileSync(dilFilePath, result.stdout, 'utf8'); | ||
| logger.info(`Saved DIL output to ${dilFilePath}`); | ||
| } catch (dilError) { | ||
| logger.warn(`Failed to save DIL output: ${dilError}`); | ||
| dilFilePath = undefined; | ||
| } | ||
| } | ||
|
|
||
| // Process the result | ||
| const processedResult = resultProcessor(result, params); | ||
| let processedResult = resultProcessor(result, params); | ||
|
|
||
| // Append DIL file path to the response for codeql_query_compile | ||
| if (dilFilePath) { | ||
| processedResult += `\n\nDIL file: ${dilFilePath}`; | ||
| } | ||
|
|
||
| return { | ||
| content: [{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.