@codacy/gate-cli 0.8.0 → 0.9.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.
Files changed (2) hide show
  1. package/bin/gate.js +124 -31
  2. package/package.json +1 -1
package/bin/gate.js CHANGED
@@ -11993,6 +11993,64 @@ function buildOfflineFallback(reason, staticResults) {
11993
11993
  };
11994
11994
  }
11995
11995
 
11996
+ // src/lib/analysis-mode.ts
11997
+ var DEBUG_PHRASES = [
11998
+ "not working",
11999
+ "doesn't work",
12000
+ "doesn't work",
12001
+ "does not work",
12002
+ "isn't working",
12003
+ "is not working",
12004
+ "can't figure out",
12005
+ "stack trace"
12006
+ ];
12007
+ var DEBUG_WORDS = [
12008
+ "fix",
12009
+ "bug",
12010
+ "broken",
12011
+ "crash",
12012
+ "crashing",
12013
+ "failing",
12014
+ "debug",
12015
+ "debugging",
12016
+ "investigate",
12017
+ "troubleshoot",
12018
+ "regression",
12019
+ "wrong"
12020
+ ];
12021
+ var DEBUG_PATTERN = new RegExp(
12022
+ [
12023
+ ...DEBUG_PHRASES.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")),
12024
+ ...DEBUG_WORDS.map((w) => `\\b${w}\\b`)
12025
+ ].join("|"),
12026
+ "i"
12027
+ );
12028
+ var FALSE_POSITIVE_PATTERNS = [
12029
+ /\b(?:add|create|implement|write|build|design|set\s*up)\b.{0,20}\berror\b/i,
12030
+ /\berror\s+handling\b/i,
12031
+ /\berror\s+boundar(?:y|ies)\b/i,
12032
+ /\berror\s+(?:type|class|page|component|message|code|enum)\b/i,
12033
+ /\b(?:add|create|implement|write|build)\b.{0,20}\b(?:fix|debug|issue)\b/i
12034
+ ];
12035
+ function hasDebugIntent(prompt) {
12036
+ if (!DEBUG_PATTERN.test(prompt)) return false;
12037
+ for (const fp of FALSE_POSITIVE_PATTERNS) {
12038
+ if (fp.test(prompt)) return false;
12039
+ }
12040
+ return true;
12041
+ }
12042
+ function detectAnalysisMode(noFilesChanged, assistantResponse, conversationPrompts) {
12043
+ if (noFilesChanged && !!assistantResponse) {
12044
+ return "plan";
12045
+ }
12046
+ for (const prompt of conversationPrompts) {
12047
+ if (hasDebugIntent(prompt)) {
12048
+ return "debug";
12049
+ }
12050
+ }
12051
+ return "standard";
12052
+ }
12053
+
11996
12054
  // src/commands/analyze.ts
11997
12055
  var MAX_ASSISTANT_RESPONSE_CHARS = 8e3;
11998
12056
  async function readStopHookStdin() {
@@ -12051,11 +12109,12 @@ async function runAnalyze(opts, globals) {
12051
12109
  if (noFilesChanged && !assistantResponse) {
12052
12110
  passAndExit("No analyzable files changed");
12053
12111
  }
12054
- const planOnly = noFilesChanged && !!assistantResponse;
12055
12112
  const allForReview = Array.from(/* @__PURE__ */ new Set([...analyzable, ...reviewable]));
12056
12113
  const conversation = await readAndClearConversationBuffer();
12057
12114
  const specs = discoverSpecs();
12058
12115
  const plans = discoverPlans();
12116
+ const conversationPrompts = (conversation?.prompts ?? []).map((p) => p.prompt);
12117
+ let analysisMode = detectAnalysisMode(noFilesChanged, assistantResponse, conversationPrompts);
12059
12118
  let staticResults = {
12060
12119
  tool: "@codacy/analysis-cli",
12061
12120
  findings: [],
@@ -12070,37 +12129,69 @@ async function runAnalyze(opts, globals) {
12070
12129
  let contentHash = null;
12071
12130
  let iteration = 1;
12072
12131
  let currentCommit = "";
12073
- if (!planOnly) {
12132
+ if (analysisMode !== "plan") {
12074
12133
  const debounceSeconds = parseInt(opts.debounce, 10);
12075
12134
  const debounceSkip = checkDebounce(debounceSeconds);
12076
- if (debounceSkip) passAndExit(debounceSkip);
12077
- const allCheckable = Array.from(/* @__PURE__ */ new Set([...analyzable, ...reviewable, ...securityFiles]));
12078
- const mtimeSkip = checkMtime(allCheckable, hasRecentCommitFiles);
12079
- if (mtimeSkip) passAndExit(mtimeSkip);
12080
- recordAnalysisStart();
12081
- const hashResult = checkContentHash(allCheckable);
12082
- if (hashResult.skip) passAndExit(hashResult.skip);
12083
- contentHash = hashResult.hash;
12084
- const recentForReview = narrowToRecent(allForReview);
12085
- if (!opts.skipStatic && isCodacyAvailable()) {
12086
- const allScannable = Array.from(/* @__PURE__ */ new Set([...analyzable, ...securityFiles]));
12087
- staticResults = runCodacyAnalysis(allScannable);
12088
- }
12089
- codeDelta = collectCodeDelta(recentForReview, {
12090
- maxFiles: parseInt(opts.maxFiles, 10),
12091
- maxFileBytes: parseInt(opts.maxFileSize, 10),
12092
- maxTotalBytes: parseInt(opts.maxTotalSize, 10)
12093
- });
12094
- if (codeDelta.files.length === 0 && staticResults.findings.length === 0) {
12095
- passAndExit("No files within size limits to analyze");
12135
+ if (debounceSkip) {
12136
+ if (assistantResponse) {
12137
+ analysisMode = "plan";
12138
+ } else {
12139
+ passAndExit(debounceSkip);
12140
+ }
12096
12141
  }
12097
- snapshotResult = generateSnapshotDiffs(codeDelta.files);
12098
- currentCommit = getCurrentCommit();
12099
- const maxIterations = parseInt(opts.maxIterations, 10);
12100
- const iterResult = checkMaxIterations(currentCommit, maxIterations, contentHash ?? void 0);
12101
- if (iterResult.skip) passAndExit(iterResult.skip);
12102
- iteration = iterResult.iteration;
12103
- } else {
12142
+ if (analysisMode !== "plan") {
12143
+ const allCheckable = Array.from(/* @__PURE__ */ new Set([...analyzable, ...reviewable, ...securityFiles]));
12144
+ const mtimeSkip = checkMtime(allCheckable, hasRecentCommitFiles);
12145
+ if (mtimeSkip) {
12146
+ if (assistantResponse) {
12147
+ analysisMode = "plan";
12148
+ } else {
12149
+ passAndExit(mtimeSkip);
12150
+ }
12151
+ }
12152
+ }
12153
+ if (analysisMode !== "plan") {
12154
+ recordAnalysisStart();
12155
+ const allCheckable = Array.from(/* @__PURE__ */ new Set([...analyzable, ...reviewable, ...securityFiles]));
12156
+ const hashResult = checkContentHash(allCheckable);
12157
+ if (hashResult.skip) {
12158
+ if (assistantResponse) {
12159
+ analysisMode = "plan";
12160
+ } else {
12161
+ passAndExit(hashResult.skip);
12162
+ }
12163
+ }
12164
+ contentHash = hashResult.hash;
12165
+ if (analysisMode !== "plan") {
12166
+ const recentForReview = narrowToRecent(allForReview);
12167
+ if (!opts.skipStatic && isCodacyAvailable()) {
12168
+ const allScannable = Array.from(/* @__PURE__ */ new Set([...analyzable, ...securityFiles]));
12169
+ staticResults = runCodacyAnalysis(allScannable);
12170
+ }
12171
+ codeDelta = collectCodeDelta(recentForReview, {
12172
+ maxFiles: parseInt(opts.maxFiles, 10),
12173
+ maxFileBytes: parseInt(opts.maxFileSize, 10),
12174
+ maxTotalBytes: parseInt(opts.maxTotalSize, 10)
12175
+ });
12176
+ if (codeDelta.files.length === 0 && staticResults.findings.length === 0) {
12177
+ if (assistantResponse) {
12178
+ analysisMode = "plan";
12179
+ } else {
12180
+ passAndExit("No files within size limits to analyze");
12181
+ }
12182
+ }
12183
+ }
12184
+ }
12185
+ if (analysisMode !== "plan") {
12186
+ snapshotResult = generateSnapshotDiffs(codeDelta.files);
12187
+ currentCommit = getCurrentCommit();
12188
+ const maxIterations = parseInt(opts.maxIterations, 10);
12189
+ const iterResult = checkMaxIterations(currentCommit, maxIterations, contentHash ?? void 0);
12190
+ if (iterResult.skip) passAndExit(iterResult.skip);
12191
+ iteration = iterResult.iteration;
12192
+ }
12193
+ }
12194
+ if (analysisMode === "plan") {
12104
12195
  recordAnalysisStart();
12105
12196
  currentCommit = getCurrentCommit();
12106
12197
  }
@@ -12117,7 +12208,9 @@ async function runAnalyze(opts, globals) {
12117
12208
  code_delta: codeDelta,
12118
12209
  changed_files: allForReview,
12119
12210
  standard_version: "latest",
12120
- plan_only: planOnly,
12211
+ analysis_mode: analysisMode,
12212
+ plan_only: analysisMode === "plan",
12213
+ // backwards compat
12121
12214
  context: {
12122
12215
  agent_model: process.env.CLAUDE_MODEL ?? "unknown",
12123
12216
  agent_harness: "claude-code",
@@ -12510,7 +12603,7 @@ function registerInitCommand(program2) {
12510
12603
  }
12511
12604
 
12512
12605
  // src/cli.ts
12513
- program.name("gate").description("CLI for GATE.md quality gate service").version("0.8.0").option("--token <token>", "Override authentication token").option("--service-url <url>", "Override service URL").option("--verbose", "Log HTTP requests/responses to stderr");
12606
+ program.name("gate").description("CLI for GATE.md quality gate service").version("0.9.0").option("--token <token>", "Override authentication token").option("--service-url <url>", "Override service URL").option("--verbose", "Log HTTP requests/responses to stderr");
12514
12607
  registerAuthCommands(program);
12515
12608
  registerHooksCommands(program);
12516
12609
  registerIntentCommands(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/gate-cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "CLI for GATE.md quality gate service",
5
5
  "bin": {
6
6
  "gate": "./bin/gate.js"