[UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default with .dil file persistence#235
Conversation
Add dump-dil parameter to the codeql_query_compile tool inputSchema and inject --dump-dil by default in registerCLITool handler unless explicitly disabled via dump-dil: false or --no-dump-dil in additionalArgs. Includes server unit tests and client integration test improvements. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/7a489b70-8f73-406f-9a75-e8a15951cde2 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
codeql_query_compile enables --dump-dil by default
client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json
Show resolved
Hide resolved
After successful compilation with --dump-dil, extract the DIL content from stdout and save it to a dedicated .dil file in a log directory. The file path is appended to the tool response. - Add logDir parameter to codeql_query_compile tool - Create log directory and write .dil file post-execution - Add server unit tests for DIL file persistence - Update integration test assertions to verify DIL file output Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/7ba868e5-1215-4130-bc06-10dfb15ebf14 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
codeql_query_compile enables --dump-dil by defaultcodeql_query_compile enables --dump-dil by default with .dil file persistence
There was a problem hiding this comment.
Pull request overview
Enhances the codeql_query_compile MCP tool to enable --dump-dil by default and persist the resulting DIL output to a dedicated .dil file, exposing that file path back to callers for downstream analysis workflows.
Changes:
- Add
dump-dil(optional) andlogDir(optional) parameters to thecodeql_query_compiletool definition. - Update CLI tool registration to default-enable
--dump-diland write compile stdout to<QueryName>.dil, appending the file path to the tool response. - Add/extend unit and integration tests to cover default injection and
.dilpersistence behavior.
Show a summary per file
| File | Description |
|---|---|
| server/src/tools/codeql/query-compile.ts | Extends tool schema/description and examples with dump-dil + logDir. |
| server/src/lib/cli-tool-registry.ts | Implements default --dump-dil injection and post-run .dil persistence + response annotation. |
| server/test/src/lib/cli-tool-registry.test.ts | Adds handler-behavior tests for default injection/overrides and .dil file creation. |
| server/test/src/tools/codeql/query-compile.test.ts | Adds tool-definition tests validating new schema fields. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json | Adds an integration assertion that the response includes a .dil file reference. |
| server/dist/codeql-development-mcp-server.js | Updates built output to reflect the source changes. |
Copilot's findings
- Files reviewed: 5/7 changed files
- Comments generated: 4
client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json
Show resolved
Hide resolved
client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR enhances the codeql_query_compile MCP tool so it enables --dump-dil by default (unless explicitly disabled/overridden) and persists the compilation stdout to a dedicated .dil file in a log directory, returning the file path in the tool response.
Changes:
- Add
dump-dil(optional) andlogDir(optional) parameters to thecodeql_query_compiletool definition and update descriptions/examples. - Update the CLI tool registry handler to default-inject
--dump-dil, create a log directory, persist stdout to<QueryName>.dil, and append the file path to the response. - Add/extend unit + integration tests to cover default injection, override behavior, and
.dilpersistence.
Show a summary per file
| File | Description |
|---|---|
| server/src/lib/cli-tool-registry.ts | Implements default --dump-dil injection, log-dir selection, .dil persistence, and response augmentation for codeql_query_compile. |
| server/src/tools/codeql/query-compile.ts | Extends tool schema/docs with dump-dil + logDir and updates examples. |
| server/test/src/lib/cli-tool-registry.test.ts | Adds handler-behavior tests for injection/overrides and .dil file persistence. |
| server/test/src/tools/codeql/query-compile.test.ts | Adds tool-definition tests for new schema fields. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json | Adds an integration assertion that the response includes a .dil file reference. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/before/test_query.ql | Removes an unused fixture query file from the integration test case. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/before/codeql-pack.lock.yml | Removes an unused fixture lockfile from the integration test case. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/after/test_query.ql | Removes an unused fixture query file from the integration test case. |
| server/dist/codeql-development-mcp-server.js | Updates the bundled build output to reflect the source changes. |
Copilot's findings
- Files reviewed: 8/10 changed files
- Comments generated: 5
client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json
Show resolved
Hide resolved
Address PR #235 review comments for codeql_query_compile DIL persistence: - Reorder path imports alphabetically (basename, delimiter, dirname, ...) - Update logDir description to match pattern used by query-run, test-run, and database-analyze (mentions CODEQL_QUERY_LOG_DIR and default path) - Defer compile log directory creation to post-execution so failed compilations do not leave empty directories behind - Make DIL file test hermetic by controlling CODEQL_QUERY_LOG_DIR via a test-scoped temp directory and restoring it in a finally block - Add test verifying no empty log directory on compilation failure - Add test verifying logDir description matches other CLI tools
There was a problem hiding this comment.
Pull request overview
This PR enhances the codeql_query_compile MCP tool to enable --dump-dil by default and persist the resulting DIL stdout into a dedicated .dil file under a managed log directory, returning that file path in the tool response. This aligns compile-time output with downstream tooling that wants to inspect the optimized evaluation plan before running queries.
Changes:
- Extend the
codeql_query_compiletool schema to includedump-dilandlogDir, and update tool description/examples accordingly. - Update
registerCLIToolhandling forcodeql_query_compileto default-inject--dump-dil, lazily create a log dir on success, write<QueryBaseName>.dil, and append the file path to the response. - Add/extend unit tests and an integration test fixture to validate default injection and
.dilpersistence behavior.
Show a summary per file
| File | Description |
|---|---|
| server/src/tools/codeql/query-compile.ts | Adds dump-dil and logDir parameters and updates tool description/examples. |
| server/src/lib/cli-tool-registry.ts | Implements default --dump-dil injection, computes effective enablement, persists stdout to .dil, and appends the file path to the response. |
| server/test/src/tools/codeql/query-compile.test.ts | New tests validating tool definition/schema properties (including logDir description). |
| server/test/src/lib/cli-tool-registry.test.ts | Adds tests for default injection, overrides via dump-dil / additionalArgs, and .dil file persistence. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json | Adds an integration test assertion that compile responses include a .dil reference. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/before/test_query.ql | Removes previously inlined query fixture (now using static server/ql/... input). |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/before/codeql-pack.lock.yml | Removes an unused pack lock fixture from the integration test case. |
| client/integration-tests/primitives/tools/codeql_query_compile/compile_query/after/test_query.ql | Removes unused “after” fixture copy of the inlined query. |
| server/dist/codeql-development-mcp-server.js | Regenerated bundled output reflecting source changes (and lockfile/dependency drift). |
| package-lock.json | Large lockfile update affecting multiple packages/versions. |
Copilot's findings
- Files reviewed: 8/11 changed files
- Comments generated: 2
| // Compute an effective "dump-dil enabled" flag for codeql_query_compile | ||
| // that accounts for both `dump-dil: false` and `--no-dump-dil` in | ||
| // `additionalArgs`. The log directory is created lazily post-success | ||
| // to avoid leaving empty directories behind on compilation failures. | ||
| let effectiveDumpDilEnabled = false; | ||
| if (name === 'codeql_query_compile') { | ||
| const pendingArgs = Array.isArray(options.additionalArgs) | ||
| ? options.additionalArgs as string[] | ||
| : []; | ||
| const effectiveDumpDilDisabled = options['dump-dil'] === false | ||
| || pendingArgs.includes('--no-dump-dil'); | ||
| effectiveDumpDilEnabled = !effectiveDumpDilDisabled; | ||
| } |
There was a problem hiding this comment.
effectiveDumpDilEnabled is computed as disabled when the named parameter sets dump-dil: false, even if additionalArgs includes an explicit --dump-dil. That contradicts the stated precedence of additionalArgs and will skip .dil persistence even though the CLI will likely emit DIL. Consider normalizing options['dump-dil'] based on additionalArgs (treat --dump-dil / --no-dump-dil as authoritative and avoid emitting conflicting flags), and derive effectiveDumpDilEnabled from the resulting effective CLI args.
See below for a potential fix:
// Extract additionalArgs from options so they are passed as raw CLI
// arguments instead of being transformed into --additionalArgs=value
// by buildCodeQLArgs.
let rawAdditionalArgs = Array.isArray(options.additionalArgs)
? options.additionalArgs as string[]
: [];
delete options.additionalArgs;
// Normalize dump-dil handling so explicit raw CLI flags in
// `additionalArgs` take precedence over the named parameter and the
// CLI does not receive conflicting duplicates.
const lastDumpDilFlag = [...rawAdditionalArgs].reverse().find(
(arg) => arg === '--dump-dil' || arg === '--no-dump-dil',
);
if (lastDumpDilFlag === '--dump-dil') {
options['dump-dil'] = true;
} else if (lastDumpDilFlag === '--no-dump-dil') {
options['dump-dil'] = false;
}
if (lastDumpDilFlag !== undefined) {
rawAdditionalArgs = rawAdditionalArgs.filter(
(arg) => arg !== '--dump-dil' && arg !== '--no-dump-dil',
);
}
// Compute an effective "dump-dil enabled" flag for codeql_query_compile
// from the normalized effective CLI options. The log directory is
// created lazily post-success to avoid leaving empty directories
// behind on compilation failures.
let effectiveDumpDilEnabled = false;
if (name === 'codeql_query_compile') {
effectiveDumpDilEnabled = options['dump-dil'] !== false;
}
client/integration-tests/primitives/tools/codeql_query_compile/compile_query/test-config.json
Show resolved
Hide resolved
Address PR #235 review comments for codeql_query_compile DIL persistence: - Reorder path imports alphabetically (basename, delimiter, dirname, ...) - Update logDir description to match pattern used by query-run, test-run, and database-analyze (mentions CODEQL_QUERY_LOG_DIR and default path) - Defer compile log directory creation to post-execution so failed compilations do not leave empty directories behind - Make DIL file test hermetic by controlling CODEQL_QUERY_LOG_DIR via a test-scoped temp directory and restoring it in a finally block - Add test verifying no empty log directory on compilation failure - Add test verifying logDir description matches other CLI tools Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
📝 Update Information
Primitive Details
codeql_query_compileUpdate Metadata
🎯 Changes Description
Current Behavior
codeql_query_compiledoes not pass--dump-dilto the CLI, so compiled queries never produce DIL output unless the caller manually adds it viaadditionalArgs. No dedicated.dilfile is produced.Updated Behavior
--dump-dilis injected by default. After successful compilation, the DIL output from stdout is persisted to a dedicated<QueryName>.dilfile in a log directory. The file path is included in the tool response. Callers can suppress DIL output viadump-dil: falseor--no-dump-dilinadditionalArgs. This matchesGitHub.vscode-codeqlbehavior and gives LLMs access to pre-run evaluation order analysis.Motivation
DIL output enables calling LLMs to review expected query evaluation behavior before running a query, complementing the existing
profile_codeql_query_from_logstool which analyzes post-run evaluation logs. Persisting the DIL to a dedicated file ensures it is available for future reference and tooling integration.🔄 Before vs. After Comparison
API Changes
Functionality Changes
In
registerCLITool, the sharedcodeql_query_compile/codeql_resolve_metadatacase is split. The compile case now:dump-dil: trueinto options unless the caller explicitly passesdump-dil: falseor--dump-dil/--no-dump-dilalready appears inadditionalArgsgetOrCreateLogDirectory) whendump-dilis not disabled<QueryName>.dilfile in the log directory.dilfile path to the tool responseOutput Format Changes
🧪 Testing & Validation
Test Coverage Updates
Validation Scenarios
--dump-dilappears in CLI options when nodump-dilparam is provideddump-dil: falseprevents injection and no.dilfile is created--no-dump-dil: Suppresses default injection, passes through to CLI--dump-dil: Prevents duplicate injection.dilfile is created with correct content and path is in the response.dilfile orDIL file:in response whendump-dil: falseTest Results
DIL file:and.dilin response📋 Implementation Details
Files Modified
server/src/tools/codeql/query-compile.ts— addeddump-dilandlogDirschema parameters, updated descriptionserver/src/lib/cli-tool-registry.ts— split case block, inject default, create log directory, persist.dilfile post-execution, append file path to responseserver/test/src/lib/cli-tool-registry.test.ts— 6 new handler behavior tests (4 dump-dil injection + 2 DIL file persistence)server/test/src/tools/codeql/query-compile.test.ts— 7 tool definition tests (includinglogDir)client/integration-tests/.../compile_query/test-config.json— test fixture with assertions for DIL file outputDependencies
🔗 References
External References
codeql query compile --dump-dilCLI docs🚀 Compatibility & Migration
Backward Compatibility
dump-dilis additive to stdout;.dilfile is new output that does not affect existing workflowsAPI Evolution
dump-diloptional boolean andlogDiroptional string added👥 Review Guidelines
For Reviewers
Testing Instructions
📊 Impact Assessment
Server Impact
.dilfile per compilationAI Assistant Impact
.dilfile ensures DIL output is persistently available for future tooling