Skip to content

Commit 180dc27

Browse files
committed
fix(static): tighten description trigger analysis precision
Address MohammedAlkindi's follow-up on the repaired head: the invocation-intent slash branch now requires a token-start slash, so a slash embedded in a larger token (CI/CD) no longer reads as slash-command invocation intent for TR2. Trigger-phrase extraction skips filler words between the verb and the phrase, so 'asks to create a poster' no longer flags TR1 on 'to'. Regression tests: test_description_embedded_slash_not_invocation_intent and test_description_trigger_phrase_skips_filler_words; test_patterns_new.py 501 passed, ruff lint and format clean. Signed-off-by: Deepak Jain <[email protected]>
1 parent 3300434 commit 180dc27

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎src/skillspector/nodes/analyzers/static_patterns_supply_chain.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,19 +525,25 @@ def _is_typosquat(pkg_name: str, popular: set[str], max_distance: int = 2) -> st
525525

526526
# Invocation/shadowing intent signals. A description only counts as a shadow
527527
# command when it shows the skill means to intercept or override a command.
528+
# The slash branch only matches a slash that starts a token (a slash-command
529+
# invocation such as "/build"), never a slash embedded in a larger token:
530+
# "CI/CD" must not read as invocation intent for "build".
528531
_DESCRIPTION_INVOCATION_RE = re.compile(
529532
r"\b(?:commands?|slash|invoke[sd]?|invoking|intercept(?:s|ed|ing)?|"
530-
r"override[sd]?|overriding|shadow(?:s|ed|ing)?)\b|/[a-z]",
533+
r"override[sd]?|overriding|shadow(?:s|ed|ing)?)\b|(?<![\w/])/[a-z]",
531534
re.IGNORECASE,
532535
)
533536

534537
# Trigger-phrase extraction for the TR1 broad/short-trigger rule on
535538
# descriptions: the word or phrase the skill claims to activate on, as in
536-
# "whenever the user says hello".
539+
# "whenever the user says hello". Filler words between the verb and the
540+
# phrase ("asks to create", "asks for a poster") are skipped so the rule
541+
# judges the real trigger word, never a preposition like "to".
537542
_DESCRIPTION_TRIGGER_PHRASE_RE = re.compile(
538543
r"\b(?:whenever|when|if)\s+(?:the\s+)?user\s+"
539544
r"(?:says?|asks?|types?|sends?|requests?)\s+"
540-
r"(?:the\s+(?:word|phrase)\s+)?['\"]?(?P<phrase>[A-Za-z][\w-]{0,31})['\"]?",
545+
r"(?:(?:the\s+(?:word|phrase)|to|for|about|on|of|the|a|an|that)\s+)*"
546+
r"['\"]?(?P<phrase>[A-Za-z][\w-]{0,31})['\"]?",
541547
re.IGNORECASE,
542548
)
543549

‎tests/unit/test_patterns_new.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,28 @@ def test_description_shadow_command_without_activation_wording(self) -> None:
23022302
)
23032303
assert "TR2" in {finding.rule_id for finding in findings}
23042304

2305+
def test_description_embedded_slash_not_invocation_intent(self) -> None:
2306+
"""MohammedAlkindi #541: a slash inside a larger token (CI/CD) is not
2307+
slash-command invocation intent, so 'build' prose stays negative."""
2308+
findings = sc_mod._analyze_triggers(
2309+
{"description": "Audit CI/CD pipelines and run the build"},
2310+
"myskill",
2311+
)
2312+
assert findings == []
2313+
2314+
def test_description_trigger_phrase_skips_filler_words(self) -> None:
2315+
"""MohammedAlkindi #541: TR1 judges the real trigger word, not a
2316+
filler preposition after the verb."""
2317+
for description in (
2318+
"Use when the user asks to create a poster",
2319+
"Use when the user asks for a poster",
2320+
):
2321+
findings = sc_mod._analyze_triggers(
2322+
{"description": description},
2323+
"myskill",
2324+
)
2325+
assert findings == [], description
2326+
23052327
@pytest.mark.parametrize("target_len", [120, 121])
23062328
def test_description_long_clause_window_still_analyzed(self, target_len: int) -> None:
23072329
"""rng1995 #541 P1: 120/121-char clauses keep start-of-clause intent."""

0 commit comments

Comments
 (0)