Skip to content

Commit 83e784e

Browse files
committed
fix(static): keep main's TR2/TR3 detections that the #669 narrowing dropped
- TR2: an interception verb again governs any built-in after it in the clause, not only the next four words before a conjunction. Tokens inside paths are skipped. - TR3: quantifier and personal-pronoun objects (any, all, every, each, some, you, me, us, him, her) do not bound a universal trigger. - A home-relative path such as ~/build is not a slash command. Signed-off-by: Edson <[email protected]>
1 parent 388af29 commit 83e784e

2 files changed

Lines changed: 62 additions & 17 deletions

File tree

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ def _is_typosquat(
776776
# unconditional: a subject or domain qualifier such as "about PostgreSQL",
777777
# "with PDF files" or "related to Kubernetes" keeps the clause describing a
778778
# capability, not a catch-all trigger. A qualifier whose object is only a
779-
# pronoun ("anything with it") bounds nothing and stays universal. Broad
779+
# pronoun or a quantifier ("anything with it", "anything with you",
780+
# "anything related to any topic") bounds nothing and stays universal. Broad
780781
# prepositions ("in", "for", "on") are deliberately not qualifiers: "any
781782
# message in the chat" is still every message.
782783
_DESCRIPTION_UNIVERSAL_SCOPE_RE = re.compile(
@@ -785,7 +786,8 @@ def _is_typosquat(
785786
r"(?:all|any|every)\s+(?:messages?|requests?|questions?|queries?|inputs?|tasks?)"
786787
r")\b"
787788
r"(?!\s+(?:about|with|involving|regarding|concerning|(?:related|relating)\s+to)\s+"
788-
r"(?!(?:it|this|that|them|anything|everything|whatever)\b)[a-z0-9])",
789+
r"(?!(?:it|this|that|them|anything|everything|whatever|"
790+
r"any|all|every|each|some|you|me|us|him|her)\b)[a-z0-9])",
789791
re.IGNORECASE,
790792
)
791793

@@ -809,18 +811,17 @@ def _is_typosquat(
809811
# The shadowed command must also be the object of that evidence, not any
810812
# built-in word that happens to share the clause: a slash-command token names
811813
# a command by its whole name ("/ask-matt" is "ask-matt", not the built-in
812-
# "ask"), and an interception verb names the command it governs within the
813-
# next few words ("Overrides the build command"). A built-in word used as an
814-
# ordinary noun elsewhere in the clause ("wants an ask answered") is not an
815-
# invocation of that command.
816-
_DESCRIPTION_SLASH_COMMAND_RE = re.compile(r"(?<![\w/])/([a-z][\w-]*)", re.IGNORECASE)
814+
# "ask"), and an interception verb governs the built-ins that follow it in
815+
# the clause ("Intercepts and replaces the built-in deploy command"). A
816+
# slash-command token that is not a built-in ("/ask-matt") stays one name, and
817+
# a home-relative path ("~/build") is not a slash command.
818+
_DESCRIPTION_SLASH_COMMAND_RE = re.compile(r"(?<![\w/.~])/([a-z][\w-]*)", re.IGNORECASE)
817819
_DESCRIPTION_INTERCEPTION_VERB_RE = re.compile(
818820
r"\b(?:invoke[sd]?|invoking|intercept(?:s|ed|ing)?|"
819821
r"override[sd]?|overriding|shadow(?:s|ed|ing)?)\b",
820822
re.IGNORECASE,
821823
)
822-
_DESCRIPTION_COMMAND_TOKEN_RE = re.compile(r"/?([a-z][\w-]*)", re.IGNORECASE)
823-
_MAX_INTERCEPTION_OBJECT_WORDS = 4
824+
_DESCRIPTION_COMMAND_TOKEN_RE = re.compile(r"(?<![\w/.~-])/?([a-z][\w-]*)", re.IGNORECASE)
824825

825826
# Trigger-phrase extraction for the TR1 broad/short-trigger rule on
826827
# descriptions: the word or phrase the skill claims to activate on, as in
@@ -941,20 +942,18 @@ def _description_shadowed_commands(clause: str) -> list[str]:
941942
"""Built-in commands a description clause claims to invoke or intercept.
942943
943944
Only commands tied to interception evidence count: a slash-command token
944-
whose whole name is a built-in, or a built-in named within a few words
945-
after an invocation/interception/override verb (before any clause
946-
boundary). Returns the sorted set of shadowed built-in commands.
945+
whose whole name is a built-in, or a built-in named anywhere after an
946+
invocation/interception/override verb in the clause. Returns the sorted
947+
set of shadowed built-in commands.
947948
"""
948949
shadowed = {
949950
match.group(1).lower()
950951
for match in _DESCRIPTION_SLASH_COMMAND_RE.finditer(clause)
951952
if match.group(1).lower() in _BUILTIN_COMMANDS
952953
}
953-
for verb in _DESCRIPTION_INTERCEPTION_VERB_RE.finditer(clause):
954-
rest = clause[verb.end() :]
955-
boundary = _DESCRIPTION_CONDITION_BOUNDARY_RE.search(rest)
956-
span = rest[: boundary.start()] if boundary else rest
957-
tokens = _DESCRIPTION_COMMAND_TOKEN_RE.findall(span)[:_MAX_INTERCEPTION_OBJECT_WORDS]
954+
verb = _DESCRIPTION_INTERCEPTION_VERB_RE.search(clause)
955+
if verb is not None:
956+
tokens = _DESCRIPTION_COMMAND_TOKEN_RE.findall(clause[verb.end() :])
958957
shadowed.update(t.lower() for t in tokens if t.lower() in _BUILTIN_COMMANDS)
959958
return sorted(shadowed)
960959

‎tests/unit/test_patterns_new.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,19 @@ def test_description_scope_bound_to_activation_condition(self, description: str)
26652665
findings = sc_mod._analyze_triggers({"description": description}, "myskill")
26662666
assert findings == []
26672667

2668+
@pytest.mark.parametrize(
2669+
"description",
2670+
[
2671+
pytest.param("Use when the user opens ~/build", id="home_relative_path"),
2672+
pytest.param("Use when the user edits ~/deploy/config.yaml", id="home_path_dir"),
2673+
],
2674+
)
2675+
def test_description_relative_path_not_shadow_command(self, description: str) -> None:
2676+
"""#669: a home-relative path ("~/build") is not a slash command, so it
2677+
does not shadow the built-in it happens to contain."""
2678+
findings = sc_mod._analyze_triggers({"description": description}, "myskill")
2679+
assert not any(finding.rule_id == "TR2" for finding in findings)
2680+
26682681
@pytest.mark.parametrize(
26692682
"description",
26702683
[
@@ -2693,6 +2706,24 @@ def test_description_noun_matching_builtin_not_shadow_command(self, description:
26932706
),
26942707
pytest.param("Overrides the git commit command", "commit", id="verb_object"),
26952708
pytest.param("Shadows /help for every request", "help", id="verb_slash_object"),
2709+
pytest.param(
2710+
"Intercepts and replaces the built-in deploy command",
2711+
"deploy",
2712+
id="verb_then_conjunction",
2713+
),
2714+
pytest.param(
2715+
"Overrides the default behavior of the git commit command",
2716+
"commit",
2717+
id="verb_distant_object",
2718+
),
2719+
pytest.param(
2720+
"Intercepts every invocation of the deploy command",
2721+
"deploy",
2722+
id="verb_invocation_of",
2723+
),
2724+
pytest.param(
2725+
"Invoked whenever the user types deploy", "deploy", id="verb_whenever_types"
2726+
),
26962727
],
26972728
)
26982729
def test_description_shadow_command_object_still_tr2(
@@ -2740,6 +2771,21 @@ def test_description_domain_qualified_scope_not_tr3(self, description: str) -> N
27402771
id="broad_preposition",
27412772
),
27422773
pytest.param("Use this skill whenever the user asks about anything", id="no_qualifier"),
2774+
pytest.param(
2775+
"Use this skill whenever the user discusses anything with you",
2776+
id="pronoun_you",
2777+
),
2778+
pytest.param(
2779+
"Use this skill whenever the user discusses anything with me", id="pronoun_me"
2780+
),
2781+
pytest.param(
2782+
"Use this skill whenever the user asks anything related to any topic",
2783+
id="quantifier_any_topic",
2784+
),
2785+
pytest.param(
2786+
"Use whenever the user sends any messages with any content",
2787+
id="quantifier_any_content",
2788+
),
27432789
],
27442790
)
27452791
def test_description_unqualified_scope_still_tr3(self, description: str) -> None:

0 commit comments

Comments
 (0)