@@ -499,6 +499,62 @@ def _is_typosquat(pkg_name: str, popular: set[str], max_distance: int = 2) -> st
499499 "hey" ,
500500}
501501
502+ # Bounded activation-intent signals for skill descriptions. Only description
503+ # clauses carrying one of these signals are treated as trigger-like; ordinary
504+ # capability prose (e.g. "Build projects") is skipped.
505+ _DESCRIPTION_ACTIVATION_RE = re .compile (
506+ r"\b(?:"
507+ r"whenever|every\s+time|each\s+time|"
508+ r"(?:all|any|every)\s+(?:messages?|requests?|questions?|queries?|inputs?|tasks?)|"
509+ r"any\s+(?:question|request|task|input|message)|"
510+ r"anything|everything|whatever|always"
511+ r")\b" ,
512+ re .IGNORECASE ,
513+ )
514+
515+ # Invocation/shadowing intent signals. A description only counts as a shadow
516+ # command when it shows the skill means to intercept or override a command.
517+ _DESCRIPTION_INVOCATION_RE = re .compile (
518+ r"\b(?:commands?|slash|invoke[sd]?|invoking|intercept(?:s|ed|ing)?|"
519+ r"override[sd]?|overriding|shadow(?:s|ed|ing)?)\b|/[a-z]" ,
520+ re .IGNORECASE ,
521+ )
522+
523+ # Unanchored baiting patterns for description clauses. The legacy TR3 patterns
524+ # are whole-string anchored for the explicit triggers field; descriptions need
525+ # substring matching so realistic activation prose is detected.
526+ _DESCRIPTION_BAITING_PATTERNS = (
527+ r"(?:anything|everything|whatever|always|"
528+ r"any\s+(?:question|request|task|input|message))" ,
529+ r"(?:when(?:ever)?|if|every\s+time)\s+(?:the\s+)?user\s+"
530+ r"(?:says?|asks?|types?|sends?)\s+"
531+ r"(?:anything|something|any\s+messages?|a\s+message)" ,
532+ r"(?:all|any|every)\s+(?:messages?|inputs?|requests?|queries?|questions?)" ,
533+ )
534+
535+ # Bounds for description clause extraction: keep the analysis cheap and the
536+ # extracted trigger phrases reviewable.
537+ _MAX_DESCRIPTION_CLAUSES = 8
538+ _MAX_DESCRIPTION_CLAUSE_CHARS = 120
539+
540+
541+ def _extract_description_trigger_clauses (description : str ) -> list [str ]:
542+ """Extract bounded trigger-like clauses from a skill description.
543+
544+ Splits the description into clauses and keeps only clauses carrying an
545+ activation-intent signal, so realistic activation prose is analyzed while
546+ ordinary capability prose is left alone.
547+ """
548+ clauses = re .split (r"[.;:!?]\s*|\s+-\s+" , description )
549+ extracted : list [str ] = []
550+ for clause in clauses [:_MAX_DESCRIPTION_CLAUSES ]:
551+ text = clause .strip ().strip ("," )
552+ if not text or len (text ) > _MAX_DESCRIPTION_CLAUSE_CHARS :
553+ continue
554+ if _DESCRIPTION_ACTIVATION_RE .search (text ):
555+ extracted .append (text )
556+ return extracted
557+
502558
503559def _pinned_version (operator : str | None , version : str | None ) -> str | None :
504560 """Return *version* only when the specifier pins one concrete release.
@@ -1841,17 +1897,22 @@ def _analyze_triggers(manifest: dict[str, object], skill_path: str) -> list[Find
18411897 """Analyze trigger-like manifest content for abuse patterns.
18421898
18431899 Agent Skills exposes activation intent through ``description``; legacy
1844- ``triggers`` metadata remains supported when present.
1900+ ``triggers`` metadata remains supported when present. Descriptions are not
1901+ passed to the legacy trigger grammar directly: only clauses carrying an
1902+ activation-intent signal are analyzed, with TR2 requiring invocation or
1903+ shadowing intent and TR3 using unanchored baiting patterns, so realistic
1904+ activation prose is detected while ordinary capability prose is skipped.
18451905 """
18461906 triggers : list [str ] = []
18471907 raw = manifest .get ("triggers" , [])
18481908 if isinstance (raw , list ):
18491909 triggers = [str (t ).strip () for t in raw if str (t ).strip ()]
1910+ description_clauses : list [str ] = []
18501911 if not triggers :
18511912 description = manifest .get ("description" )
18521913 if isinstance (description , str ) and description .strip ():
1853- triggers = [ description .strip ()]
1854- if not triggers :
1914+ description_clauses = _extract_description_trigger_clauses ( description .strip ())
1915+ if not triggers and not description_clauses :
18551916 return []
18561917
18571918 findings : list [Finding ] = []
@@ -1937,6 +1998,59 @@ def _analyze_triggers(manifest: dict[str, object], skill_path: str) -> list[Find
19371998 )
19381999 break
19392000
2001+ for i , clause in enumerate (description_clauses , 1 ):
2002+ clause_lower = clause .lower ().strip ()
2003+ words = clause_lower .split ()
2004+
2005+ # TR2 (description-calibrated): only flag a shadow command when the
2006+ # clause shows invocation or shadowing intent; ordinary capability
2007+ # prose such as "Build projects" stays out of the trigger path.
2008+ shadowed = sorted (
2009+ {cmd for cmd in _BUILTIN_COMMANDS if cmd in {w .lstrip ("/" ) for w in words }}
2010+ )
2011+ if shadowed and _DESCRIPTION_INVOCATION_RE .search (clause ):
2012+ findings .append (
2013+ Finding (
2014+ rule_id = "TR2" ,
2015+ message = (
2016+ f"Shadow Command Trigger: description clause '{ clause } ' "
2017+ f"conflicts with built-in command '{ shadowed [0 ]} '"
2018+ ),
2019+ severity = "MEDIUM" ,
2020+ confidence = 0.7 ,
2021+ file = file_ref ,
2022+ start_line = i ,
2023+ tags = tag ,
2024+ matched_text = clause ,
2025+ category = PatternCategory .TRIGGER_ABUSE .value ,
2026+ pattern = "Shadow Command Trigger" ,
2027+ )
2028+ )
2029+
2030+ # TR3 (description-calibrated): unanchored baiting patterns detect
2031+ # realistic activation prose such as "whenever the user sends any
2032+ # message", which the whole-string legacy grammar misses.
2033+ for bp in _DESCRIPTION_BAITING_PATTERNS :
2034+ if re .search (bp , clause_lower ):
2035+ findings .append (
2036+ Finding (
2037+ rule_id = "TR3" ,
2038+ message = (
2039+ f"Keyword Baiting Trigger: description clause '{ clause } ' "
2040+ "is designed to match all or most user inputs"
2041+ ),
2042+ severity = "MEDIUM" ,
2043+ confidence = 0.8 ,
2044+ file = file_ref ,
2045+ start_line = i ,
2046+ tags = tag ,
2047+ matched_text = clause ,
2048+ category = PatternCategory .TRIGGER_ABUSE .value ,
2049+ pattern = "Keyword Baiting Trigger" ,
2050+ )
2051+ )
2052+ break
2053+
19402054 return findings
19412055
19422056
0 commit comments