Skip to content

CLI-620 beforePromptSubmit hook for Cursor#436

Open
sophio-japharidze-sonarsource wants to merge 1 commit into
masterfrom
CLI-620_cursor_promptSubmit_hook
Open

CLI-620 beforePromptSubmit hook for Cursor#436
sophio-japharidze-sonarsource wants to merge 1 commit into
masterfrom
CLI-620_cursor_promptSubmit_hook

Conversation

@sophio-japharidze-sonarsource

Copy link
Copy Markdown
Contributor

Add a new feature to sonar integrate cursor - scanning prompts for secrets

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jun 10, 2026

Copy link
Copy Markdown

CLI-620

Comment thread src/cli/commands/integrate/cursor/declaration.ts
Comment thread src/cli/commands/hook/cursor-prompt-submit.ts
@netlify

netlify Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploy Preview for sonarqube-cli canceled.

Name Link
🔨 Latest commit a31f8aa
🔍 Latest deploy log https://app.netlify.com/projects/sonarqube-cli/deploys/6a29756b86e40b00083a3dfc

@netlify

netlify Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploy Preview for sonarqube-cli canceled.

Name Link
🔨 Latest commit 660161d
🔍 Latest deploy log https://app.netlify.com/projects/sonarqube-cli/deploys/6a2ace3cbfd1c600083e835f

@sonarqubecloud

Copy link
Copy Markdown

Agentic Analysis: Early Results

Agentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action.

1 issue(s) found across 1 file(s):

Rule File Line Message
typescript:S109 tests/integration/specs/hook/hook-cursor-prompt-submit.test.ts 168 No magic number: 0o644.

Analyzed by SonarQube Agentic Analysis in 2.9 s

@sophio-japharidze-sonarsource sophio-japharidze-sonarsource marked this pull request as ready for review June 11, 2026 15:03
@gitar-bot

gitar-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown
CI failed: An integration test in the analyze-sqaa suite timed out during hook execution when simulating an on-premise connection. This appears to be a resource contention or cleanup issue in the test harness rather than a regression from the Cursor hook implementation.

Overview

A single integration test failure was identified in the analyze-sqaa test suite. The build failed due to a beforeEach hook timeout occurring specifically during an on-premise connection scenario, which does not appear to be directly related to the changes introduced in this PR.

Failures

Integration test hook timeout (confidence: high)

  • Type: test
  • Affected jobs: 80832321994
  • Related to change: no
  • Root cause: A beforeEach hook in tests/integration/specs/analyze/analyze-sqaa.test.ts timed out while setting up or tearing down an on-premise connection mock, indicating a potential deadlock or resource leak in the test environment.
  • Suggested fix: Investigate the beforeEach hook lifecycle in analyze-sqaa.test.ts. Ensure that all mock servers and child processes associated with on-premise simulation are properly terminated. If the issue persists, consider increasing the timeout specifically for this test case or debugging the connection teardown logic.

Summary

  • Change-related failures: 0
  • Infrastructure/flaky failures: 1 (Integration test hook timeout)
  • Recommended action: Review the analyze-sqaa.test.ts integration test suite. This failure is likely an environmental or test-harness flakiness unrelated to the beforePromptSubmit hook implementation. Re-running the CI job may resolve the issue if it is non-deterministic.
Code Review ✅ Approved 2 resolved / 2 findings

Implements the beforePromptSubmit hook for Cursor to enable secret scanning on prompts and refactors MCP configuration helpers. All previous findings regarding payload naming and feature advertising have been addressed.

✅ 2 resolved
Quality: cursor command advertises SQAA/CAG it doesn't install

📄 src/cli/commands/integrate/cursor/declaration.ts:64-78
The integrate cursor command description states it "will configure the SonarQube MCP Server, install secrets scanning hooks, and configure SonarQube Agentic Analysis", and it declares a --skip-context option ("Skip the sonar-context-augmentation install/init/skill step"). However, cursorIntegration.features in src/cli/commands/integrate/cursor/declaration.ts only contains the sonar-secrets-prompt-hook and mcp-server features — there is no Context Augmentation (CAG) or SQAA feature (unlike Claude/Codex which call createContextAugmentationFeature). As a result --skip-context is a no-op and the description over-promises.

The test file comment confirms this is intentional staging ("Hook and CAG tests are added in subsequent PRs") and the command is hidden until GA, so impact is low. Consider trimming the description to mention only what is actually configured (MCP server + secrets hook) and dropping/documenting --skip-context until CAG is wired up, to avoid confusing users who run the hidden command.

Bug: Verify Cursor block payload field name user_message

📄 src/cli/commands/hook/cursor-prompt-submit.ts:56-61
cursorPromptSubmit emits { "continue": false, "user_message": "Sonar detected secrets in prompt" } to block a prompt. The integration test only round-trips the CLI's own output (output.user_message), so it does not validate the field name against Cursor's actual hook contract. If Cursor expects camelCase (userMessage) rather than snake_case (user_message), the prompt would still be blocked (continue: false takes effect) but the explanatory message may not be surfaced to the user. Please verify the exact field name against Cursor's hooks schema (https://cursor.com/docs/agent/hooks) and adjust if needed.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
79.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

1 participant