Skip to content

[UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default with .dil file persistence#235

Merged
data-douser merged 7 commits intonextfrom
copilot/update-codeql-query-compile-default
Apr 11, 2026
Merged

[UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default with .dil file persistence#235
data-douser merged 7 commits intonextfrom
copilot/update-codeql-query-compile-default

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

📝 Update Information

Primitive Details

  • Type: Tool
  • Name: codeql_query_compile
  • Update Category: Feature Enhancement

⚠️ CRITICAL: PR SCOPE VALIDATION

  • ONLY server implementation files are included
  • NO temporary or output files are included
  • NO unrelated configuration files are included
  • ALL existing tests continue to pass
  • NEW functionality is properly tested

  • Impact Scope: Localized

Update Metadata

  • Breaking Changes: No
  • API Compatibility: Enhanced (new optional parameters, default behavior change is additive)
  • Performance Impact: Neutral

🎯 Changes Description

Current Behavior

codeql_query_compile does not pass --dump-dil to the CLI, so compiled queries never produce DIL output unless the caller manually adds it via additionalArgs. No dedicated .dil file is produced.

Updated Behavior

--dump-dil is injected by default. After successful compilation, the DIL output from stdout is persisted to a dedicated <QueryName>.dil file in a log directory. The file path is included in the tool response. Callers can suppress DIL output via dump-dil: false or --no-dump-dil in additionalArgs. This matches GitHub.vscode-codeql behavior 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_logs tool 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

// BEFORE:
inputSchema: {
  query: z.string(),
  database: z.string().optional(),
  // ... no dump-dil or logDir parameters
}

// AFTER:
inputSchema: {
  query: z.string(),
  database: z.string().optional(),
  'dump-dil': z.boolean().optional()
    .describe('Print the optimized DIL intermediate representation. Enabled by default; pass false to disable.'),
  logDir: z.string().optional()
    .describe('Directory to write the .dil file. If not provided, a unique log directory is created automatically.'),
  // ...
}

Functionality Changes

In registerCLITool, the shared codeql_query_compile/codeql_resolve_metadata case is split. The compile case now:

  1. Injects dump-dil: true into options unless the caller explicitly passes dump-dil: false or --dump-dil/--no-dump-dil already appears in additionalArgs
  2. Creates a log directory (using getOrCreateLogDirectory) when dump-dil is not disabled
  3. After successful compilation, extracts DIL content from stdout and writes it to a <QueryName>.dil file in the log directory
  4. Appends the .dil file path to the tool response

Output Format Changes

// BEFORE:
Compilation successful

// AFTER:
Compilation successful
DIL:
  predicate#abc123
    SCAN table
    SELECT col1, col2

DIL file: /path/to/logs/query-run-2026-04-09T.../MyQuery.dil

🧪 Testing & Validation

Test Coverage Updates

  • Existing Tests: All 1325 tests across 60 files pass
  • New Test Cases: 13 new tests added (6 handler behavior + 7 tool definition)
  • Edge Case Tests: additionalArgs override scenarios and DIL file persistence covered

Validation Scenarios

  1. Default injection: --dump-dil appears in CLI options when no dump-dil param is provided
  2. Explicit disable: dump-dil: false prevents injection and no .dil file is created
  3. additionalArgs --no-dump-dil: Suppresses default injection, passes through to CLI
  4. additionalArgs --dump-dil: Prevents duplicate injection
  5. DIL file persistence: .dil file is created with correct content and path is in the response
  6. No DIL file when disabled: No .dil file or DIL file: in response when dump-dil: false

Test Results

  • Unit Tests: All pass (1325/1325)
  • Integration Tests: Client integration test assertions verify DIL file: and .dil in response

📋 Implementation Details

Files Modified

  • Core Implementation: server/src/tools/codeql/query-compile.ts — added dump-dil and logDir schema parameters, updated description
  • Supporting Libraries: server/src/lib/cli-tool-registry.ts — split case block, inject default, create log directory, persist .dil file post-execution, append file path to response
  • Tests: server/test/src/lib/cli-tool-registry.test.ts — 6 new handler behavior tests (4 dump-dil injection + 2 DIL file persistence)
  • Tests: server/test/src/tools/codeql/query-compile.test.ts — 7 tool definition tests (including logDir)
  • Integration: client/integration-tests/.../compile_query/test-config.json — test fixture with assertions for DIL file output

Dependencies

  • No New Dependencies

🔗 References

External References

🚀 Compatibility & Migration

Backward Compatibility

  • Fully Compatible: dump-dil is additive to stdout; .dil file is new output that does not affect existing workflows

API Evolution

  • Enhanced Parameters: dump-dil optional boolean and logDir optional string added
  • Maintained Contracts: All existing parameters and behavior preserved

👥 Review Guidelines

For Reviewers

  • ⚠️ SCOPE COMPLIANCE: Only server source, tests, and integration fixture
  • ⚠️ NO UNRELATED FILES: Clean diff
  • ⚠️ BACKWARD COMPATIBILITY: Existing callers unaffected (new output is additive)

Testing Instructions

npm run build-and-test

# Specific tests
cd server && npx vitest run test/src/lib/cli-tool-registry.test.ts
cd server && npx vitest run test/src/tools/codeql/query-compile.test.ts

📊 Impact Assessment

Server Impact

  • Startup Time: No impact
  • Runtime Stability: No impact
  • Resource Usage: Marginal increase in compile output size (DIL text) and one additional .dil file per compilation

AI Assistant Impact

  • Enhanced Accuracy: LLMs can review DIL to understand evaluation order before running queries
  • Better Coverage: Bridges gap between compile-time analysis and post-run profiling
  • Improved Reliability: Dedicated .dil file ensures DIL output is persistently available for future tooling

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>
Copilot AI changed the title [WIP] Update codeql_query_compile tool to use --dump-dil by default [UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default Apr 9, 2026
Copilot AI requested a review from data-douser April 9, 2026 04:34
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>
Copilot AI changed the title [UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default [UPDATE PRIMITIVE] codeql_query_compile enables --dump-dil by default with .dil file persistence Apr 10, 2026
Copilot AI requested a review from data-douser April 10, 2026 15:27
@data-douser data-douser marked this pull request as ready for review April 10, 2026 15:55
@data-douser data-douser requested review from a team and enyil as code owners April 10, 2026 15:55
Copilot AI review requested due to automatic review settings April 10, 2026 15:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and logDir (optional) parameters to the codeql_query_compile tool definition.
  • Update CLI tool registration to default-enable --dump-dil and 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 .dil persistence 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

Copilot AI review requested due to automatic review settings April 11, 2026 00:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and logDir (optional) parameters to the codeql_query_compile tool 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 .dil persistence.
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

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
Copilot AI review requested due to automatic review settings April 11, 2026 01:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_compile tool schema to include dump-dil and logDir, and update tool description/examples accordingly.
  • Update registerCLITool handling for codeql_query_compile to 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 .dil persistence 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

Comment on lines +559 to +571
// 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;
}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
        }

Copilot uses AI. Check for mistakes.
@data-douser data-douser merged commit a3a140b into next Apr 11, 2026
17 checks passed
@data-douser data-douser deleted the copilot/update-codeql-query-compile-default branch April 11, 2026 02:04
Copilot AI pushed a commit that referenced this pull request Apr 11, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Primitive Update]: codeql_query_compile tool must use --dump-dil by default

3 participants