Skip to content

Commit 912dadc

Browse files
committed
fix(static): skip stacked determiners in TR3 objects and accept passive auxiliaries in TR2
- TR3: up to three determiners, quantifiers or "of" after a qualifier are transparent and "of" is never judged as the object, so "about all the services" and "about all your Terraform modules" stay bounded while "with any of them" stays universal. - TR2: a passive interception claim may use "is/are being", "will be" or "has/have been" and one adverb before the participle ("is always intercepted", "are now shadowed", "has been overridden"); a negation ("is not intercepted") still does not count. Signed-off-by: Edson <[email protected]>
1 parent 6e6d54b commit 912dadc

2 files changed

Lines changed: 76 additions & 12 deletions

File tree

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,15 @@ def _is_typosquat(
775775
# Universal-scope signals for description clauses. The scope must be
776776
# unconditional: a subject or domain qualifier such as "about PostgreSQL",
777777
# "with PDF files" or "related to Kubernetes" keeps the clause describing a
778-
# capability, not a catch-all trigger. A leading determiner or quantifier is
779-
# transparent ("about this codebase", "about any AWS service" are still
780-
# bounded by the noun after it). A qualifier whose object is only a pronoun or
781-
# a generic noun ("anything with it", "anything with anyone", "anything
782-
# related to any topic", "any messages with any content") bounds nothing and
783-
# stays universal. Broad prepositions ("in", "for", "on") are deliberately not
784-
# qualifiers: "any message in the chat" is still every message.
778+
# capability, not a catch-all trigger. Up to three leading determiners,
779+
# quantifiers or "of" are transparent ("about this codebase", "about any AWS
780+
# service", "about all the services", "about all of the services" are still
781+
# bounded by the noun after them). A qualifier whose object is only a pronoun
782+
# or a generic noun ("anything with it", "anything with anyone", "anything
783+
# with any of them", "anything related to any topic", "any messages with any
784+
# content") bounds nothing and stays universal. Broad prepositions ("in",
785+
# "for", "on") are deliberately not qualifiers: "any message in the chat" is
786+
# still every message.
785787
_DESCRIPTION_SCOPE_DETERMINER = (
786788
r"(?:the|a|an|this|that|these|those|any|all|every|each|some|"
787789
r"my|your|our|their|its|his|her)"
@@ -797,8 +799,8 @@ def _is_typosquat(
797799
r"(?:all|any|every)\s+(?:messages?|requests?|questions?|queries?|inputs?|tasks?)"
798800
r")\b"
799801
r"(?!\s+(?:about|with|involving|regarding|concerning|(?:related|relating)\s+to)\s+"
800-
rf"(?:{_DESCRIPTION_SCOPE_DETERMINER}\s+)?"
801-
rf"(?!(?:{_DESCRIPTION_UNBOUNDED_OBJECT}|{_DESCRIPTION_SCOPE_DETERMINER})\b)[a-z0-9])",
802+
rf"(?:(?:{_DESCRIPTION_SCOPE_DETERMINER}|of)\s+){{0,3}}"
803+
rf"(?!(?:{_DESCRIPTION_UNBOUNDED_OBJECT}|{_DESCRIPTION_SCOPE_DETERMINER}|of)\b)[a-z0-9])",
802804
re.IGNORECASE,
803805
)
804806

@@ -833,9 +835,16 @@ def _is_typosquat(
833835
re.IGNORECASE,
834836
)
835837
# Passive interception claims name the command before the verb: "the built-in
836-
# deploy command is intercepted", "types deploy it is intercepted".
838+
# deploy command is intercepted", "types deploy it is intercepted", "the deploy
839+
# command will be intercepted", "deploy commands are now shadowed". The
840+
# auxiliary may be "is"/"are" (optionally "being"), "gets", "will be" or
841+
# "has/have been", and one adverb may precede the participle. The adverb slot
842+
# takes a short list plus "-ly" words, so a negation ("is not intercepted",
843+
# "is never shadowed") does not count.
837844
_DESCRIPTION_PASSIVE_INTERCEPTION_RE = re.compile(
838-
r"(?<![\w/.~-])/?([a-z][\w-]*)\s+(?:commands?\s+|it\s+)?(?:is|are|gets?)\s+"
845+
r"(?<![\w/.~-])/?([a-z][\w-]*)\s+(?:commands?\s+|it\s+)?"
846+
r"(?:(?:is|are)(?:\s+being)?|gets?|will\s+be|ha(?:s|ve)\s+been)\s+"
847+
r"(?:(?:always|now|also|still|already|[a-z]+ly)\s+)?"
839848
r"(?:intercepted|overridden|shadowed|invoked)\b",
840849
re.IGNORECASE,
841850
)
@@ -962,7 +971,8 @@ def _description_shadowed_commands(clause: str) -> list[str]:
962971
Only commands tied to interception evidence count: a slash-command token
963972
whose whole name is a built-in, a built-in named anywhere after an
964973
invocation/interception/override verb in the clause, or a built-in that a
965-
passive claim names right before the verb ("deploy is intercepted").
974+
passive claim names right before its auxiliary ("deploy is intercepted",
975+
"deploy command has been overridden").
966976
Returns the sorted set of shadowed built-in commands.
967977
"""
968978
shadowed = {

‎tests/unit/test_patterns_new.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,10 @@ def test_description_relative_path_not_shadow_command(self, description: str) ->
26932693
"Diagnose and fix build failures caused by stale overrides",
26942694
id="capability_prose_overrides",
26952695
),
2696+
pytest.param(
2697+
"The deploy command is not intercepted by this skill",
2698+
id="passive_negated",
2699+
),
26962700
],
26972701
)
26982702
def test_description_noun_matching_builtin_not_shadow_command(self, description: str) -> None:
@@ -2743,6 +2747,31 @@ def test_description_noun_matching_builtin_not_shadow_command(self, description:
27432747
"commit",
27442748
id="passive_overridden",
27452749
),
2750+
pytest.param(
2751+
"The built-in deploy command is always intercepted by this skill",
2752+
"deploy",
2753+
id="passive_adverb",
2754+
),
2755+
pytest.param(
2756+
"The deploy command is being intercepted by this skill",
2757+
"deploy",
2758+
id="passive_is_being",
2759+
),
2760+
pytest.param(
2761+
"The deploy command will be intercepted by this skill",
2762+
"deploy",
2763+
id="passive_will_be",
2764+
),
2765+
pytest.param(
2766+
"Deploy commands are now shadowed by this skill",
2767+
"deploy",
2768+
id="passive_are_now",
2769+
),
2770+
pytest.param(
2771+
"The git commit command has been overridden by this skill",
2772+
"commit",
2773+
id="passive_has_been",
2774+
),
27462775
],
27472776
)
27482777
def test_description_shadow_command_object_still_tr2(
@@ -2790,6 +2819,23 @@ def test_description_shadow_command_object_still_tr2(
27902819
"Use this skill whenever the user wants to do anything with any PDF file",
27912820
id="quantifier_any_pdf",
27922821
),
2822+
pytest.param(
2823+
"Use this skill whenever the user asks any questions about all the services "
2824+
"in the cluster",
2825+
id="predeterminer_all_the",
2826+
),
2827+
pytest.param(
2828+
"Use whenever the user asks anything about all your Terraform modules",
2829+
id="predeterminer_all_your",
2830+
),
2831+
pytest.param(
2832+
"Use whenever the user asks anything about all these files",
2833+
id="predeterminer_all_these",
2834+
),
2835+
pytest.param(
2836+
"Use whenever the user asks anything about all of the services",
2837+
id="quantifier_of_the",
2838+
),
27932839
],
27942840
)
27952841
def test_description_domain_qualified_scope_not_tr3(self, description: str) -> None:
@@ -2837,6 +2883,14 @@ def test_description_domain_qualified_scope_not_tr3(self, description: str) -> N
28372883
"Use this skill whenever the user asks anything regarding everyone",
28382884
id="indefinite_everyone",
28392885
),
2886+
pytest.param(
2887+
"Use this skill whenever the user does anything with any of them",
2888+
id="quantifier_any_of_them",
2889+
),
2890+
pytest.param(
2891+
"Use this skill whenever the user does anything with each of them",
2892+
id="quantifier_each_of_them",
2893+
),
28402894
],
28412895
)
28422896
def test_description_unqualified_scope_still_tr3(self, description: str) -> None:

0 commit comments

Comments
 (0)