Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions src/history/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,43 @@

const CONVENTIONAL_PREFIX_RE = /^(feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([^)]+\))?:\s*/;

const BASE_FORM_VERBS_WITH_SUFFIXES = new Set([
'bleed',
'breed',
'bring',
'cling',
'ding',
'embed',
'exceed',
'feed',
'fling',
'heed',
'imbed',
'king',
'need',
'ping',
'proceed',
'ring',
'seed',
'shed',
'sing',
'sling',
'speed',
'spring',
'sting',
'string',
'swing',
'wed',
'wing',
'wring',
'zing',
]);

function isDescriptiveVerb(verb: string): boolean {
verb = verb.toLowerCase();
return !BASE_FORM_VERBS_WITH_SUFFIXES.has(verb) && (verb.endsWith('ed') || verb.endsWith('ing'));
Comment on lines +42 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize verb casing before suffix classification.

verb preserves commit-message casing, but the exception set is lowercase. Therefore fix: Bring retries is incorrectly treated as descriptive and lowers the imperative rate.

  • src/history/store.ts#L42-L43: normalize verb before both the exception lookup and suffix checks.
  • tests/history-profile.test.mjs#L70-L85: capitalize bring in the fixture (or add a capitalized case) and retain the expected 2 / 3 rate.
Proposed fix
 function isDescriptiveVerb(verb: string): boolean {
-  return !BASE_FORM_VERBS_WITH_SUFFIXES.has(verb) && (verb.endsWith('ed') || verb.endsWith('ing'));
+  const normalizedVerb = verb.toLowerCase();
+  return !BASE_FORM_VERBS_WITH_SUFFIXES.has(normalizedVerb)
+    && (normalizedVerb.endsWith('ed') || normalizedVerb.endsWith('ing'));
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isDescriptiveVerb(verb: string): boolean {
return !BASE_FORM_VERBS_WITH_SUFFIXES.has(verb) && (verb.endsWith('ed') || verb.endsWith('ing'));
function isDescriptiveVerb(verb: string): boolean {
const normalizedVerb = verb.toLowerCase();
return !BASE_FORM_VERBS_WITH_SUFFIXES.has(normalizedVerb)
&& (normalizedVerb.endsWith('ed') || normalizedVerb.endsWith('ing'));
}
📍 Affects 2 files
  • src/history/store.ts#L42-L43 (this comment)
  • tests/history-profile.test.mjs#L70-L85
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/history/store.ts` around lines 42 - 43, Normalize the verb to lowercase
at the start of isDescriptiveVerb before both BASE_FORM_VERBS_WITH_SUFFIXES
lookup and suffix checks. Update tests/history-profile.test.mjs lines 70-85 to
use capitalized “Bring” in the fixture while retaining the expected 2 / 3
imperative rate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize case before checking base-form exceptions

When history contains sentence-case subjects such as Ping server, the extracted verb is Ping, which misses the lowercase ping entry and is classified as descriptive solely because it ends in ing. Repositories using capitalized subjects therefore get an artificially low imperative rate, potentially suppressing the imperative-mood prompt when the rate falls below 50%; lowercase the verb before both checks.

AGENTS.md reference: AGENTS.md:L63-L63

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Account for compound base verbs in suffix detection

When an imperative subject begins with a compound base verb such as fix: reseed database, reseed ends in ed but is absent from the exception set even though its root seed is present, so the new denominator logic records it as descriptive. The same applies to forms such as preseed and valid base verbs such as shred, causing the learned tone and resulting prompt guidance to be wrong for those histories; the exception logic needs to recognize these base forms rather than relying on this incomplete list.

AGENTS.md reference: AGENTS.md:L63-L63

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle derived base-form verbs before suffix classification

When a commit uses an imperative derived verb such as fix: reseed database, the exact allowlist does not contain reseed, so the ed suffix incorrectly marks it as descriptive. For example, a history containing that subject and fix: added retry produces an imperative rate of 0 instead of 50%, preventing buildStyleGuidance() from preserving the repository's imperative style. Prefix-derived forms such as reseed and preseed need classification beyond an exact-word allowlist.

Useful? React with 👍 / 👎.

}

const HISTORY_LOCK_RETRY_MS = 25;
const HISTORY_LOCK_STALE_MS = 60_000;
const HISTORY_LOCK_TIMEOUT_MS = HISTORY_LOCK_STALE_MS + 10_000;
Expand Down Expand Up @@ -309,17 +346,11 @@
const verbMatch = firstLine.match(
/^(?:feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(?:\([^)]+\))?:\s*(\w+)/,
);
if (verbMatch) {
const verb = verbMatch[1]!;
if (!verb.endsWith('ed') && !verb.endsWith('ing')) {
imperativeCount++;
imperativeSampleCount++;
}
} else {
const firstWord = firstLine.match(/^\w+/);
if (firstWord && !firstWord[0]!.endsWith('ed') && !firstWord[0]!.endsWith('ing')) {
const verb = verbMatch?.[1] ?? firstLine.match(/^\w+/)?.[0];

Check warning on line 349 in src/history/store.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the "RegExp.exec()" method instead.

See more on https://sonarcloud.io/project/issues?id=404-PF_commit-echo&issues=AZ-wcbHw4CZyFP_GwVgq&open=AZ-wcbHw4CZyFP_GwVgq&pullRequest=248
if (verb) {
imperativeSampleCount++;
if (!isDescriptiveVerb(verb)) {
imperativeCount++;
Comment on lines +351 to 353

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve base-form verbs ending in suffix-like text

When history contains base-form imperative verbs whose spelling ends in ed or ing (such as seed or bring), incrementing the denominator here while excluding those verbs from the numerator misclassifies them as descriptive. For fix: add retries, fix: bring retries, and fix: added retries, the rate becomes 1/3 instead of the correct 2/3, so buildStyleGuidance() no longer emits imperative guidance at its 0.5 threshold; classify the verb form rather than relying solely on its suffix before counting the sample.

AGENTS.md reference: AGENTS.md:L63-L63

Useful? React with 👍 / 👎.

imperativeSampleCount++;
}
}

Expand Down
28 changes: 26 additions & 2 deletions tests/history-profile.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function restoreEnv(name, value) {
}
}

test('buildProfile excludes descriptive verb forms from the imperative-rate denominator', async () => {
test('buildProfile counts descriptive verb forms in the imperative-rate denominator', async () => {
const originalHome = process.env.HOME;
const originalAppData = process.env.APPDATA;
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
Expand All @@ -58,7 +58,31 @@ test('buildProfile excludes descriptive verb forms from the imperative-rate deno
const profile = await buildProfile(10);

assert.equal(profile.totalCommits, 3);
assert.equal(profile.imperativeRate, 1);
assert.equal(profile.imperativeRate, 1 / 3);
} finally {
restoreEnv('HOME', originalHome);
restoreEnv('APPDATA', originalAppData);
restoreEnv('XDG_CONFIG_HOME', originalXdgConfigHome);
rmSync(tempHome, { recursive: true, force: true });
}
});

test('buildProfile recognizes base-form verbs that end in descriptive suffixes', async () => {
const originalHome = process.env.HOME;
const originalAppData = process.env.APPDATA;
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
const tempHome = mkdtempSync(join(tmpdir(), 'commit-echo-home-'));

try {
process.env.HOME = tempHome;
process.env.APPDATA = join(tempHome, 'AppData', 'Roaming');
process.env.XDG_CONFIG_HOME = join(tempHome, '.config');
writeHistory(tempHome, ['fix: add retries', 'fix: Bring retries', 'fix: added retries']);

const profile = await buildProfile(10);

assert.equal(profile.totalCommits, 3);
assert.equal(profile.imperativeRate, 2 / 3);
} finally {
restoreEnv('HOME', originalHome);
restoreEnv('APPDATA', originalAppData);
Expand Down