tickettriage 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: tickettriage
3
+ Version: 0.1.0
4
+ Summary: Rule-based and AI-powered ticket classification, priority enrichment, and triage automation — part of the Libre Ticket Suite
5
+ Author-email: Leonardo Benitez <lsbenitezpereira@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: repository, https://github.com/LeonardoSanBenitez/TicketTriage
8
+ Project-URL: documentation, https://github.com/LeonardoSanBenitez/TicketTriage
9
+ Keywords: ticket,itsm,triage,classification,incident,priority,automation
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0; extra == "dev"
26
+ Requires-Dist: mypy>=1.10; extra == "dev"
27
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # TicketTriage
31
+
32
+ **Rule-based and AI-powered ticket classification, priority enrichment, and triage automation.**
33
+
34
+ Part of the [Libre Ticket Suite](https://github.com/LeonardoSanBenitez) — open-source Python libraries for modern ticket/alert/incident handling automation.
35
+
36
+ ## What it does
37
+
38
+ TicketTriage provides a composable, fully-typed **rule engine** for classifying and enriching tickets. Given a ticket (from TicketSync or any dict), it evaluates an ordered set of rules and produces a TriageResult containing updated priority, added tags, metadata, and audit notes.
39
+
40
+ ## Quick start
41
+
42
+ ```python
43
+ from tickettriage import Classifier, RuleSet, Rule, Condition, RuleAction
44
+ from tickettriage.rules import ConditionField, ConditionOp
45
+
46
+ ruleset = RuleSet("production")
47
+ ruleset.add_rule(Rule(
48
+ name="production-outage",
49
+ conditions=[
50
+ Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage"),
51
+ ],
52
+ action=RuleAction(
53
+ set_priority="critical",
54
+ add_tags=["sev1", "page-oncall"],
55
+ notes="Outage keyword detected — auto-escalated to critical",
56
+ ),
57
+ stop_on_match=True,
58
+ ))
59
+ ruleset.add_rule(Rule(
60
+ name="cve-security",
61
+ conditions=[
62
+ Condition(ConditionField.TITLE, ConditionOp.REGEX, r"CVE-\d{4}-\d+"),
63
+ ],
64
+ action=RuleAction(set_priority="high", add_tags=["security"]),
65
+ ))
66
+
67
+ classifier = Classifier(ruleset)
68
+ result = classifier.classify({"title": "Production outage: CVE-2024-1234"})
69
+ print(result.priority) # "critical"
70
+ print(result.matched_rules) # ["production-outage"] (stopped after first match)
71
+ print(result.added_tags) # ["sev1", "page-oncall"]
72
+ ```
73
+
74
+ ## Design philosophy
75
+
76
+ - **Zero mandatory dependencies** — pure Python stdlib.
77
+ - **Composable rules** — chain as many conditions as you need (logical AND).
78
+ - **Ordered evaluation** — rules run in insertion order; `stop_on_match=True` acts as a circuit breaker.
79
+ - **Fully typed** — mypy --strict compatible.
80
+ - **TDD** — CI runs on Python 3.10, 3.11, 3.12.
81
+
82
+ ## Roadmap
83
+
84
+ - AI/LLM enrichment backend (opt-in, via Ollama or any OpenAI-compat endpoint)
85
+ - YAML/TOML rule serialization (load rules from config files)
86
+ - Async classifier for high-throughput event streams
87
+
88
+ ## License
89
+
90
+ Apache-2.0
@@ -0,0 +1,61 @@
1
+ # TicketTriage
2
+
3
+ **Rule-based and AI-powered ticket classification, priority enrichment, and triage automation.**
4
+
5
+ Part of the [Libre Ticket Suite](https://github.com/LeonardoSanBenitez) — open-source Python libraries for modern ticket/alert/incident handling automation.
6
+
7
+ ## What it does
8
+
9
+ TicketTriage provides a composable, fully-typed **rule engine** for classifying and enriching tickets. Given a ticket (from TicketSync or any dict), it evaluates an ordered set of rules and produces a TriageResult containing updated priority, added tags, metadata, and audit notes.
10
+
11
+ ## Quick start
12
+
13
+ ```python
14
+ from tickettriage import Classifier, RuleSet, Rule, Condition, RuleAction
15
+ from tickettriage.rules import ConditionField, ConditionOp
16
+
17
+ ruleset = RuleSet("production")
18
+ ruleset.add_rule(Rule(
19
+ name="production-outage",
20
+ conditions=[
21
+ Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage"),
22
+ ],
23
+ action=RuleAction(
24
+ set_priority="critical",
25
+ add_tags=["sev1", "page-oncall"],
26
+ notes="Outage keyword detected — auto-escalated to critical",
27
+ ),
28
+ stop_on_match=True,
29
+ ))
30
+ ruleset.add_rule(Rule(
31
+ name="cve-security",
32
+ conditions=[
33
+ Condition(ConditionField.TITLE, ConditionOp.REGEX, r"CVE-\d{4}-\d+"),
34
+ ],
35
+ action=RuleAction(set_priority="high", add_tags=["security"]),
36
+ ))
37
+
38
+ classifier = Classifier(ruleset)
39
+ result = classifier.classify({"title": "Production outage: CVE-2024-1234"})
40
+ print(result.priority) # "critical"
41
+ print(result.matched_rules) # ["production-outage"] (stopped after first match)
42
+ print(result.added_tags) # ["sev1", "page-oncall"]
43
+ ```
44
+
45
+ ## Design philosophy
46
+
47
+ - **Zero mandatory dependencies** — pure Python stdlib.
48
+ - **Composable rules** — chain as many conditions as you need (logical AND).
49
+ - **Ordered evaluation** — rules run in insertion order; `stop_on_match=True` acts as a circuit breaker.
50
+ - **Fully typed** — mypy --strict compatible.
51
+ - **TDD** — CI runs on Python 3.10, 3.11, 3.12.
52
+
53
+ ## Roadmap
54
+
55
+ - AI/LLM enrichment backend (opt-in, via Ollama or any OpenAI-compat endpoint)
56
+ - YAML/TOML rule serialization (load rules from config files)
57
+ - Async classifier for high-throughput event streams
58
+
59
+ ## License
60
+
61
+ Apache-2.0
@@ -0,0 +1,54 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tickettriage"
7
+ version = "0.1.0"
8
+ description = "Rule-based and AI-powered ticket classification, priority enrichment, and triage automation — part of the Libre Ticket Suite"
9
+ readme = "README.md"
10
+ license = {text = "Apache-2.0"}
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ {name = "Leonardo Benitez", email = "lsbenitezpereira@gmail.com"},
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 2 - Pre-Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: System Administrators",
19
+ "License :: OSI Approved :: Apache Software License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ "Topic :: System :: Systems Administration",
26
+ "Typing :: Typed",
27
+ ]
28
+ keywords = ["ticket", "itsm", "triage", "classification", "incident", "priority", "automation"]
29
+
30
+ [project.urls]
31
+ repository = "https://github.com/LeonardoSanBenitez/TicketTriage"
32
+ documentation = "https://github.com/LeonardoSanBenitez/TicketTriage"
33
+
34
+ [project.optional-dependencies]
35
+ dev = [
36
+ "pytest>=8.0",
37
+ "mypy>=1.10",
38
+ "pytest-asyncio>=0.23",
39
+ ]
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["."]
43
+ include = ["tickettriage*"]
44
+
45
+ [tool.setuptools.package-data]
46
+ tickettriage = ["py.typed"]
47
+
48
+ [tool.mypy]
49
+ strict = true
50
+ python_version = "3.10"
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests"]
54
+ asyncio_mode = "auto"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,165 @@
1
+ """Tests for Classifier and RuleSet."""
2
+
3
+ import pytest
4
+
5
+ from tickettriage.classifier import Classifier, RuleSet, TriageResult
6
+ from tickettriage.rules import (
7
+ Condition,
8
+ ConditionField,
9
+ ConditionOp,
10
+ Rule,
11
+ RuleAction,
12
+ )
13
+
14
+
15
+ def make_outage_rule(stop: bool = False) -> Rule:
16
+ return Rule(
17
+ name="outage-rule",
18
+ conditions=[Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage")],
19
+ action=RuleAction(set_priority="critical", add_tags=["sev1"], notes="Outage detected"),
20
+ stop_on_match=stop,
21
+ )
22
+
23
+
24
+ def make_security_rule() -> Rule:
25
+ return Rule(
26
+ name="security-rule",
27
+ conditions=[Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "cve")],
28
+ action=RuleAction(set_priority="high", add_tags=["security"]),
29
+ )
30
+
31
+
32
+ class TestRuleSet:
33
+ def test_empty_ruleset(self) -> None:
34
+ rs = RuleSet()
35
+ assert len(rs) == 0
36
+
37
+ def test_add_rule(self) -> None:
38
+ rs = RuleSet()
39
+ rs.add_rule(make_outage_rule())
40
+ assert len(rs) == 1
41
+
42
+ def test_chaining(self) -> None:
43
+ rs = RuleSet().add_rule(make_outage_rule()).add_rule(make_security_rule())
44
+ assert len(rs) == 2
45
+
46
+ def test_name(self) -> None:
47
+ rs = RuleSet(name="production-triage")
48
+ assert rs.name == "production-triage"
49
+
50
+
51
+ class TestClassifierNoMatch:
52
+ def test_no_rules_returns_empty_result(self) -> None:
53
+ c = Classifier(RuleSet())
54
+ result = c.classify({"title": "Something"})
55
+ assert result.priority is None
56
+ assert result.added_tags == []
57
+ assert result.matched_rules == []
58
+
59
+ def test_rule_not_matching(self) -> None:
60
+ rs = RuleSet().add_rule(make_outage_rule())
61
+ c = Classifier(rs)
62
+ result = c.classify({"title": "Routine maintenance"})
63
+ assert result.priority is None
64
+ assert "outage-rule" not in result.matched_rules
65
+
66
+
67
+ class TestClassifierSingleRule:
68
+ def test_single_rule_matches(self) -> None:
69
+ rs = RuleSet().add_rule(make_outage_rule())
70
+ c = Classifier(rs)
71
+ result = c.classify({"title": "Production outage us-east-1"})
72
+ assert result.priority == "critical"
73
+ assert "sev1" in result.added_tags
74
+ assert "outage-rule" in result.matched_rules
75
+
76
+ def test_notes_collected(self) -> None:
77
+ rs = RuleSet().add_rule(make_outage_rule())
78
+ c = Classifier(rs)
79
+ result = c.classify({"title": "outage"})
80
+ assert "Outage detected" in result.notes
81
+
82
+
83
+ class TestClassifierMultipleRules:
84
+ def test_both_rules_match(self) -> None:
85
+ rs = RuleSet().add_rule(make_outage_rule()).add_rule(make_security_rule())
86
+ c = Classifier(rs)
87
+ # title matches both
88
+ result = c.classify({"title": "CVE outage exploit"})
89
+ assert "outage-rule" in result.matched_rules
90
+ assert "security-rule" in result.matched_rules
91
+
92
+ def test_last_matching_rule_wins_priority(self) -> None:
93
+ rs = (
94
+ RuleSet()
95
+ .add_rule(make_outage_rule()) # sets critical
96
+ .add_rule(make_security_rule()) # sets high
97
+ )
98
+ c = Classifier(rs)
99
+ result = c.classify({"title": "CVE outage"})
100
+ # Both match; last wins
101
+ assert result.priority == "high"
102
+
103
+ def test_tags_deduplicated(self) -> None:
104
+ r1 = Rule(
105
+ name="r1",
106
+ conditions=[],
107
+ action=RuleAction(add_tags=["security"]),
108
+ )
109
+ r2 = Rule(
110
+ name="r2",
111
+ conditions=[],
112
+ action=RuleAction(add_tags=["security", "backend"]),
113
+ )
114
+ c = Classifier(RuleSet(rules=[r1, r2]))
115
+ result = c.classify({})
116
+ assert result.added_tags.count("security") == 1
117
+ assert "backend" in result.added_tags
118
+
119
+
120
+ class TestClassifierStopOnMatch:
121
+ def test_stop_on_match_prevents_later_rules(self) -> None:
122
+ rs = (
123
+ RuleSet()
124
+ .add_rule(make_outage_rule(stop=True)) # matches and stops
125
+ .add_rule(make_security_rule()) # should NOT run
126
+ )
127
+ c = Classifier(rs)
128
+ result = c.classify({"title": "CVE outage"})
129
+ assert "outage-rule" in result.matched_rules
130
+ assert "security-rule" not in result.matched_rules
131
+
132
+ def test_stop_on_match_not_triggered_when_no_match(self) -> None:
133
+ rs = (
134
+ RuleSet()
135
+ .add_rule(make_outage_rule(stop=True)) # does NOT match
136
+ .add_rule(make_security_rule()) # should run
137
+ )
138
+ c = Classifier(rs)
139
+ result = c.classify({"title": "CVE exploit"})
140
+ assert "outage-rule" not in result.matched_rules
141
+ assert "security-rule" in result.matched_rules
142
+
143
+
144
+ class TestClassifierMetadata:
145
+ def test_metadata_merged(self) -> None:
146
+ r1 = Rule(
147
+ name="r1",
148
+ conditions=[],
149
+ action=RuleAction(set_metadata={"team": "infra"}),
150
+ )
151
+ r2 = Rule(
152
+ name="r2",
153
+ conditions=[],
154
+ action=RuleAction(set_metadata={"oncall": "alice"}),
155
+ )
156
+ c = Classifier(RuleSet(rules=[r1, r2]))
157
+ result = c.classify({})
158
+ assert result.metadata == {"team": "infra", "oncall": "alice"}
159
+
160
+ def test_metadata_later_rule_overwrites(self) -> None:
161
+ r1 = Rule(name="r1", conditions=[], action=RuleAction(set_metadata={"team": "infra"}))
162
+ r2 = Rule(name="r2", conditions=[], action=RuleAction(set_metadata={"team": "security"}))
163
+ c = Classifier(RuleSet(rules=[r1, r2]))
164
+ result = c.classify({})
165
+ assert result.metadata["team"] == "security"
@@ -0,0 +1,12 @@
1
+ """Smoke tests."""
2
+
3
+ import tickettriage
4
+
5
+
6
+ def test_hello_ticket() -> None:
7
+ assert tickettriage.hello_ticket() == "hello ticket"
8
+
9
+
10
+ def test_version_string() -> None:
11
+ assert isinstance(tickettriage.__version__, str)
12
+ assert len(tickettriage.__version__) > 0
@@ -0,0 +1,93 @@
1
+ """Tests for Rule, Condition, and RuleAction primitives."""
2
+
3
+ import pytest
4
+
5
+ from tickettriage.rules import (
6
+ Condition,
7
+ ConditionField,
8
+ ConditionOp,
9
+ Rule,
10
+ RuleAction,
11
+ )
12
+
13
+
14
+ class TestConditionContains:
15
+ def test_title_contains_match(self) -> None:
16
+ c = Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage")
17
+ assert c.matches({"title": "Production outage in us-east-1"}) is True
18
+
19
+ def test_title_contains_case_insensitive(self) -> None:
20
+ c = Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "OUTAGE")
21
+ assert c.matches({"title": "production outage"}) is True
22
+
23
+ def test_title_contains_no_match(self) -> None:
24
+ c = Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage")
25
+ assert c.matches({"title": "Routine maintenance"}) is False
26
+
27
+ def test_missing_field_no_match(self) -> None:
28
+ c = Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "x")
29
+ assert c.matches({}) is False
30
+
31
+
32
+ class TestConditionEquals:
33
+ def test_equals_match(self) -> None:
34
+ c = Condition(ConditionField.PRIORITY, ConditionOp.EQUALS, "high")
35
+ assert c.matches({"priority": "high"}) is True
36
+
37
+ def test_equals_no_match(self) -> None:
38
+ c = Condition(ConditionField.PRIORITY, ConditionOp.EQUALS, "high")
39
+ assert c.matches({"priority": "low"}) is False
40
+
41
+ def test_not_equals(self) -> None:
42
+ c = Condition(ConditionField.STATUS, ConditionOp.NOT_EQUALS, "closed")
43
+ assert c.matches({"status": "open"}) is True
44
+ assert c.matches({"status": "closed"}) is False
45
+
46
+
47
+ class TestConditionRegex:
48
+ def test_regex_match(self) -> None:
49
+ c = Condition(ConditionField.TITLE, ConditionOp.REGEX, r"CVE-\d{4}-\d+")
50
+ assert c.matches({"title": "Security: CVE-2024-12345 in openssl"}) is True
51
+
52
+ def test_regex_no_match(self) -> None:
53
+ c = Condition(ConditionField.TITLE, ConditionOp.REGEX, r"CVE-\d{4}-\d+")
54
+ assert c.matches({"title": "Routine update"}) is False
55
+
56
+
57
+ class TestConditionTags:
58
+ def test_tags_contains(self) -> None:
59
+ c = Condition(ConditionField.TAGS, ConditionOp.CONTAINS, "sec")
60
+ assert c.matches({"tags": ["security", "backend"]}) is True
61
+
62
+ def test_tags_in(self) -> None:
63
+ c = Condition(ConditionField.TAGS, ConditionOp.IN, ["sev1", "critical"])
64
+ assert c.matches({"tags": ["sev1", "database"]}) is True
65
+ assert c.matches({"tags": ["backend"]}) is False
66
+
67
+ def test_tags_empty(self) -> None:
68
+ c = Condition(ConditionField.TAGS, ConditionOp.CONTAINS, "x")
69
+ assert c.matches({"tags": []}) is False
70
+
71
+
72
+ class TestConditionIn:
73
+ def test_in_match(self) -> None:
74
+ c = Condition(ConditionField.SOURCE, ConditionOp.IN, ["github", "jira"])
75
+ assert c.matches({"source": "github"}) is True
76
+
77
+ def test_in_no_match(self) -> None:
78
+ c = Condition(ConditionField.SOURCE, ConditionOp.IN, ["github", "jira"])
79
+ assert c.matches({"source": "pagerduty"}) is False
80
+
81
+
82
+ class TestRule:
83
+ def test_rule_name(self) -> None:
84
+ r = Rule(
85
+ name="test-rule",
86
+ conditions=[],
87
+ action=RuleAction(),
88
+ )
89
+ assert r.name == "test-rule"
90
+
91
+ def test_stop_on_match_default_false(self) -> None:
92
+ r = Rule(name="x", conditions=[], action=RuleAction())
93
+ assert r.stop_on_match is False
@@ -0,0 +1,27 @@
1
+ """
2
+ TicketTriage — Rule-based and AI-powered ticket classification, priority enrichment,
3
+ and triage automation.
4
+
5
+ Part of the Libre Ticket Suite.
6
+ """
7
+
8
+ from tickettriage.classifier import Classifier, RuleSet, TriageResult
9
+ from tickettriage.rules import Rule, RuleAction, Condition, ConditionField, ConditionOp
10
+
11
+ __version__ = "0.1.0"
12
+ __all__ = [
13
+ "Classifier",
14
+ "RuleSet",
15
+ "TriageResult",
16
+ "Rule",
17
+ "RuleAction",
18
+ "Condition",
19
+ "ConditionField",
20
+ "ConditionOp",
21
+ "__version__",
22
+ ]
23
+
24
+
25
+ def hello_ticket() -> str:
26
+ """Return a greeting — used to verify the package installs and imports correctly."""
27
+ return "hello ticket"
@@ -0,0 +1,125 @@
1
+ """
2
+ Classifier: applies a RuleSet to produce a TriageResult.
3
+
4
+ The Classifier is the core engine of TicketTriage. It evaluates rules in order
5
+ and accumulates all matching actions into a TriageResult.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass, field
11
+ from typing import Any, Optional
12
+
13
+ from tickettriage.rules import Rule
14
+
15
+
16
+ @dataclass
17
+ class TriageResult:
18
+ """
19
+ The output of classifying a ticket.
20
+
21
+ Attributes:
22
+ priority: The final priority after applying all matching rules.
23
+ None means no rule changed the priority.
24
+ added_tags: Tags added by matching rules (deduplicated, ordered).
25
+ metadata: Merged metadata from all matching rules.
26
+ matched_rules: Names of rules that matched, in evaluation order.
27
+ notes: Concatenated notes from all matching rules.
28
+ """
29
+
30
+ priority: Optional[str] = None
31
+ added_tags: list[str] = field(default_factory=list)
32
+ metadata: dict[str, Any] = field(default_factory=dict)
33
+ matched_rules: list[str] = field(default_factory=list)
34
+ notes: str = ""
35
+
36
+
37
+ class RuleSet:
38
+ """
39
+ An ordered, named collection of triage rules.
40
+
41
+ Rules are evaluated in insertion order. Use stop_on_match=True on a Rule
42
+ to prevent subsequent rules from being evaluated.
43
+ """
44
+
45
+ def __init__(self, name: str = "default", rules: Optional[list[Rule]] = None) -> None:
46
+ self.name = name
47
+ self._rules: list[Rule] = list(rules) if rules else []
48
+
49
+ def add_rule(self, rule: Rule) -> "RuleSet":
50
+ """Append a rule. Returns self for chaining."""
51
+ self._rules.append(rule)
52
+ return self
53
+
54
+ def __len__(self) -> int:
55
+ return len(self._rules)
56
+
57
+ def __iter__(self) -> Any:
58
+ return iter(self._rules)
59
+
60
+
61
+ class Classifier:
62
+ """
63
+ Evaluates a RuleSet against a ticket and returns a TriageResult.
64
+
65
+ Usage::
66
+
67
+ from tickettriage import Classifier, RuleSet, Rule, Condition, RuleAction
68
+ from tickettriage.rules import ConditionField, ConditionOp
69
+
70
+ ruleset = RuleSet("production")
71
+ ruleset.add_rule(Rule(
72
+ name="production-outage",
73
+ conditions=[
74
+ Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage"),
75
+ ],
76
+ action=RuleAction(set_priority="critical", add_tags=["sev1"]),
77
+ ))
78
+
79
+ classifier = Classifier(ruleset)
80
+ result = classifier.classify({"title": "Production outage in us-east-1"})
81
+ # result.priority == "critical"
82
+ """
83
+
84
+ def __init__(self, ruleset: RuleSet) -> None:
85
+ self._ruleset = ruleset
86
+
87
+ def classify(self, ticket_data: dict[str, Any]) -> TriageResult:
88
+ """
89
+ Evaluate all rules against ticket_data and return a TriageResult.
90
+
91
+ Args:
92
+ ticket_data: A dict with ticket fields. Typically produced by
93
+ Ticket.to_dict() from TicketSync, but any dict works.
94
+
95
+ Returns:
96
+ A TriageResult accumulating the effects of all matching rules.
97
+ """
98
+ result = TriageResult()
99
+ seen_tags: set[str] = set()
100
+
101
+ for rule in self._ruleset:
102
+ if all(cond.matches(ticket_data) for cond in rule.conditions):
103
+ result.matched_rules.append(rule.name)
104
+
105
+ if rule.action.set_priority is not None:
106
+ result.priority = rule.action.set_priority
107
+
108
+ for tag in rule.action.add_tags:
109
+ if tag not in seen_tags:
110
+ result.added_tags.append(tag)
111
+ seen_tags.add(tag)
112
+
113
+ result.metadata.update(rule.action.set_metadata)
114
+
115
+ if rule.action.notes:
116
+ result.notes = (
117
+ result.notes + "\n" + rule.action.notes
118
+ if result.notes
119
+ else rule.action.notes
120
+ )
121
+
122
+ if rule.stop_on_match:
123
+ break
124
+
125
+ return result
File without changes
@@ -0,0 +1,123 @@
1
+ """
2
+ Rule primitives for TicketTriage.
3
+
4
+ A Rule pairs a Condition (what to match) with a RuleAction (what to do when matched).
5
+ Rules are evaluated by the Classifier against ticket fields.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from dataclasses import dataclass, field
12
+ from enum import Enum
13
+ from typing import Any, Optional
14
+
15
+
16
+ class ConditionField(str, Enum):
17
+ """Ticket fields that conditions can match against."""
18
+
19
+ TITLE = "title"
20
+ DESCRIPTION = "description"
21
+ TAGS = "tags"
22
+ PRIORITY = "priority"
23
+ STATUS = "status"
24
+ ASSIGNEE = "assignee"
25
+ REPORTER = "reporter"
26
+ SOURCE = "source"
27
+
28
+
29
+ class ConditionOp(str, Enum):
30
+ """Comparison operators for conditions."""
31
+
32
+ CONTAINS = "contains" # substring match (case-insensitive)
33
+ EQUALS = "equals" # exact match
34
+ REGEX = "regex" # regex match against field value
35
+ IN = "in" # value is in a list
36
+ NOT_CONTAINS = "not_contains"
37
+ NOT_EQUALS = "not_equals"
38
+
39
+
40
+ @dataclass
41
+ class Condition:
42
+ """
43
+ A single matching condition.
44
+
45
+ Attributes:
46
+ field: Which ticket field to inspect.
47
+ op: Comparison operator.
48
+ value: The value to compare against.
49
+ """
50
+
51
+ field: ConditionField
52
+ op: ConditionOp
53
+ value: Any
54
+
55
+ def matches(self, ticket_data: dict[str, Any]) -> bool:
56
+ """Evaluate this condition against a ticket field value."""
57
+ field_value = ticket_data.get(self.field.value, "")
58
+
59
+ if self.field == ConditionField.TAGS:
60
+ # Tags is a list; "contains" means "any tag contains substring"
61
+ tags: list[str] = field_value if isinstance(field_value, list) else []
62
+ if self.op == ConditionOp.CONTAINS:
63
+ return any(self.value.lower() in t.lower() for t in tags)
64
+ if self.op == ConditionOp.IN:
65
+ check: list[str] = self.value if isinstance(self.value, list) else [self.value]
66
+ return any(t in check for t in tags)
67
+ if self.op == ConditionOp.EQUALS:
68
+ return self.value in tags
69
+ else:
70
+ text = str(field_value).lower() if field_value is not None else ""
71
+ val = str(self.value).lower() if not isinstance(self.value, list) else self.value
72
+
73
+ if self.op == ConditionOp.CONTAINS:
74
+ return str(val) in text
75
+ if self.op == ConditionOp.NOT_CONTAINS:
76
+ return str(val) not in text
77
+ if self.op == ConditionOp.EQUALS:
78
+ return text == str(val)
79
+ if self.op == ConditionOp.NOT_EQUALS:
80
+ return text != str(val)
81
+ if self.op == ConditionOp.REGEX:
82
+ return bool(re.search(str(self.value), str(field_value), re.IGNORECASE))
83
+ if self.op == ConditionOp.IN:
84
+ check_list: list[str] = [str(v).lower() for v in self.value]
85
+ return text in check_list
86
+
87
+ return False
88
+
89
+
90
+ @dataclass
91
+ class RuleAction:
92
+ """
93
+ The action to apply when a rule matches.
94
+
95
+ Attributes:
96
+ set_priority: Override the ticket priority (e.g. 'high').
97
+ add_tags: Tags to append to the ticket's tag list.
98
+ set_metadata: Key-value pairs to merge into ticket.metadata.
99
+ notes: Human-readable explanation of why this action was applied.
100
+ """
101
+
102
+ set_priority: Optional[str] = None
103
+ add_tags: list[str] = field(default_factory=list)
104
+ set_metadata: dict[str, Any] = field(default_factory=dict)
105
+ notes: str = ""
106
+
107
+
108
+ @dataclass
109
+ class Rule:
110
+ """
111
+ A named triage rule: match all conditions, then apply an action.
112
+
113
+ Attributes:
114
+ name: Unique human-readable name.
115
+ conditions: All conditions must match (logical AND).
116
+ action: The action applied when all conditions match.
117
+ stop_on_match: If True, no further rules are evaluated after this one matches.
118
+ """
119
+
120
+ name: str
121
+ conditions: list[Condition]
122
+ action: RuleAction
123
+ stop_on_match: bool = False
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: tickettriage
3
+ Version: 0.1.0
4
+ Summary: Rule-based and AI-powered ticket classification, priority enrichment, and triage automation — part of the Libre Ticket Suite
5
+ Author-email: Leonardo Benitez <lsbenitezpereira@gmail.com>
6
+ License: Apache-2.0
7
+ Project-URL: repository, https://github.com/LeonardoSanBenitez/TicketTriage
8
+ Project-URL: documentation, https://github.com/LeonardoSanBenitez/TicketTriage
9
+ Keywords: ticket,itsm,triage,classification,incident,priority,automation
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0; extra == "dev"
26
+ Requires-Dist: mypy>=1.10; extra == "dev"
27
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # TicketTriage
31
+
32
+ **Rule-based and AI-powered ticket classification, priority enrichment, and triage automation.**
33
+
34
+ Part of the [Libre Ticket Suite](https://github.com/LeonardoSanBenitez) — open-source Python libraries for modern ticket/alert/incident handling automation.
35
+
36
+ ## What it does
37
+
38
+ TicketTriage provides a composable, fully-typed **rule engine** for classifying and enriching tickets. Given a ticket (from TicketSync or any dict), it evaluates an ordered set of rules and produces a TriageResult containing updated priority, added tags, metadata, and audit notes.
39
+
40
+ ## Quick start
41
+
42
+ ```python
43
+ from tickettriage import Classifier, RuleSet, Rule, Condition, RuleAction
44
+ from tickettriage.rules import ConditionField, ConditionOp
45
+
46
+ ruleset = RuleSet("production")
47
+ ruleset.add_rule(Rule(
48
+ name="production-outage",
49
+ conditions=[
50
+ Condition(ConditionField.TITLE, ConditionOp.CONTAINS, "outage"),
51
+ ],
52
+ action=RuleAction(
53
+ set_priority="critical",
54
+ add_tags=["sev1", "page-oncall"],
55
+ notes="Outage keyword detected — auto-escalated to critical",
56
+ ),
57
+ stop_on_match=True,
58
+ ))
59
+ ruleset.add_rule(Rule(
60
+ name="cve-security",
61
+ conditions=[
62
+ Condition(ConditionField.TITLE, ConditionOp.REGEX, r"CVE-\d{4}-\d+"),
63
+ ],
64
+ action=RuleAction(set_priority="high", add_tags=["security"]),
65
+ ))
66
+
67
+ classifier = Classifier(ruleset)
68
+ result = classifier.classify({"title": "Production outage: CVE-2024-1234"})
69
+ print(result.priority) # "critical"
70
+ print(result.matched_rules) # ["production-outage"] (stopped after first match)
71
+ print(result.added_tags) # ["sev1", "page-oncall"]
72
+ ```
73
+
74
+ ## Design philosophy
75
+
76
+ - **Zero mandatory dependencies** — pure Python stdlib.
77
+ - **Composable rules** — chain as many conditions as you need (logical AND).
78
+ - **Ordered evaluation** — rules run in insertion order; `stop_on_match=True` acts as a circuit breaker.
79
+ - **Fully typed** — mypy --strict compatible.
80
+ - **TDD** — CI runs on Python 3.10, 3.11, 3.12.
81
+
82
+ ## Roadmap
83
+
84
+ - AI/LLM enrichment backend (opt-in, via Ollama or any OpenAI-compat endpoint)
85
+ - YAML/TOML rule serialization (load rules from config files)
86
+ - Async classifier for high-throughput event streams
87
+
88
+ ## License
89
+
90
+ Apache-2.0
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ tests/test_classifier.py
5
+ tests/test_hello.py
6
+ tests/test_rules.py
7
+ tickettriage/__init__.py
8
+ tickettriage/classifier.py
9
+ tickettriage/py.typed
10
+ tickettriage/rules.py
11
+ tickettriage.egg-info/PKG-INFO
12
+ tickettriage.egg-info/SOURCES.txt
13
+ tickettriage.egg-info/dependency_links.txt
14
+ tickettriage.egg-info/requires.txt
15
+ tickettriage.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+
2
+ [dev]
3
+ pytest>=8.0
4
+ mypy>=1.10
5
+ pytest-asyncio>=0.23
@@ -0,0 +1 @@
1
+ tickettriage