neos-triage 0.2.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.
- neos_triage-0.2.0/LICENSE +201 -0
- neos_triage-0.2.0/PKG-INFO +81 -0
- neos_triage-0.2.0/README.md +61 -0
- neos_triage-0.2.0/neos/__init__.py +24 -0
- neos_triage-0.2.0/neos/cli.py +253 -0
- neos_triage-0.2.0/neos/docs/ALERTS.md +135 -0
- neos_triage-0.2.0/neos/docs/DEPLOY.md +166 -0
- neos_triage-0.2.0/neos/docs/FAIR.md +118 -0
- neos_triage-0.2.0/neos/docs/USAGE.md +109 -0
- neos_triage-0.2.0/neos/label.py +136 -0
- neos_triage-0.2.0/neos/laws.py +78 -0
- neos_triage-0.2.0/neos/measure.py +236 -0
- neos_triage-0.2.0/neos/packet.py +98 -0
- neos_triage-0.2.0/neos/stream.py +191 -0
- neos_triage-0.2.0/neos/triage.py +280 -0
- neos_triage-0.2.0/neos_triage.egg-info/PKG-INFO +81 -0
- neos_triage-0.2.0/neos_triage.egg-info/SOURCES.txt +21 -0
- neos_triage-0.2.0/neos_triage.egg-info/dependency_links.txt +1 -0
- neos_triage-0.2.0/neos_triage.egg-info/entry_points.txt +2 -0
- neos_triage-0.2.0/neos_triage.egg-info/top_level.txt +1 -0
- neos_triage-0.2.0/pyproject.toml +46 -0
- neos_triage-0.2.0/setup.cfg +4 -0
- neos_triage-0.2.0/tests/test_triage.py +332 -0
|
@@ -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 2026 Devieswar Kancheti
|
|
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,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neos-triage
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Triage structured event streams by exact law. No model in the decision.
|
|
5
|
+
Author: Devieswar Kancheti
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/devkancheti4-design/neos-triage
|
|
8
|
+
Project-URL: Source, https://github.com/devkancheti4-design/neos-triage
|
|
9
|
+
Project-URL: Issues, https://github.com/devkancheti4-design/neos-triage/issues
|
|
10
|
+
Keywords: observability,alerting,triage,logs,siem,deterministic
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Topic :: System :: Logging
|
|
14
|
+
Classifier: Topic :: System :: Monitoring
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# neos-triage
|
|
22
|
+
|
|
23
|
+
**Triage structured event streams by exact law. No model in the decision.**
|
|
24
|
+
|
|
25
|
+
pip install neos-triage
|
|
26
|
+
neos /var/log/syslog
|
|
27
|
+
|
|
28
|
+
An LLM triaging events spends most of its tokens deciding whether an event
|
|
29
|
+
matters. That decision here is a handful of bit operations over a byte — so it
|
|
30
|
+
costs nothing, and a model only writes words for the ~1% that survive.
|
|
31
|
+
|
|
32
|
+
**75.9% fewer tokens** than a lean batched classifier, measured on 215,089 real
|
|
33
|
+
events with both sides using the same safe dedup. → [USAGE.md](USAGE.md)
|
|
34
|
+
|
|
35
|
+
## Read this before you deploy it
|
|
36
|
+
|
|
37
|
+
Measured against ground truth the tool cannot see — filesystem-check exit codes
|
|
38
|
+
recorded in a separate file — it caught **42 of 59** real incidents: **71.2%
|
|
39
|
+
recall, 95% CI [58.6%, 81.2%]**.
|
|
40
|
+
|
|
41
|
+
As originally shipped it caught **0 of 59**. A dedup credited with 97% of the
|
|
42
|
+
token saving was hiding a failure that recurs 1,113 times. Fixing it cost 13
|
|
43
|
+
points of the saving, because the 89% published earlier was the same result
|
|
44
|
+
with the incidents removed.
|
|
45
|
+
|
|
46
|
+
**False-page rate is still unmeasured.** Run it beside your existing alerting,
|
|
47
|
+
not instead of it. `neos label` / `neos score` produce the evidence for your
|
|
48
|
+
own stream. → [FAIR.md](FAIR.md), [DEPLOY.md](DEPLOY.md)
|
|
49
|
+
|
|
50
|
+
## How it works
|
|
51
|
+
|
|
52
|
+
event ──[adapter]──► PACKET ──► ROUTE ─ hands settle ─► REDIAL ──► DECLINE
|
|
53
|
+
a regex every step below is bit operations
|
|
54
|
+
|
|
55
|
+
`route()`, `redial()` and `decline()` are verified against compiled C kernels
|
|
56
|
+
over **all 256 inputs**. Nothing is trained, tuned or fitted. The laws never
|
|
57
|
+
see words — an adapter converts at the boundary and decides nothing, which is
|
|
58
|
+
why text arriving in an event cannot reach the control path.
|
|
59
|
+
|
|
60
|
+
Adapters auto-detect: syslog (ISO and BSD), `.NET`/Unity, tagged, NDJSON.
|
|
61
|
+
Below a 50% parse rate it **refuses** rather than reporting a confident 0%.
|
|
62
|
+
|
|
63
|
+
## What it will not do
|
|
64
|
+
|
|
65
|
+
It reports. It cannot send, write, execute or act — no `subprocess`, no
|
|
66
|
+
`exec`, no network, **zero dependencies**, all enforced by tests rather than
|
|
67
|
+
claimed.
|
|
68
|
+
|
|
69
|
+
## Tests
|
|
70
|
+
|
|
71
|
+
python3 tests/test_triage.py # 22
|
|
72
|
+
python3 fairtest.py # incident recall vs an independent oracle
|
|
73
|
+
|
|
74
|
+
Two properties are *proved*, not sampled: the hand set is **total** over all 64
|
|
75
|
+
packet shapes — no event is ruled and then dropped — and the decision path
|
|
76
|
+
imports nothing.
|
|
77
|
+
|
|
78
|
+
## Licence
|
|
79
|
+
|
|
80
|
+
Apache-2.0. The sibling project that carries fluidfix's AGPL kernel is not
|
|
81
|
+
distributed here.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# neos-triage
|
|
2
|
+
|
|
3
|
+
**Triage structured event streams by exact law. No model in the decision.**
|
|
4
|
+
|
|
5
|
+
pip install neos-triage
|
|
6
|
+
neos /var/log/syslog
|
|
7
|
+
|
|
8
|
+
An LLM triaging events spends most of its tokens deciding whether an event
|
|
9
|
+
matters. That decision here is a handful of bit operations over a byte — so it
|
|
10
|
+
costs nothing, and a model only writes words for the ~1% that survive.
|
|
11
|
+
|
|
12
|
+
**75.9% fewer tokens** than a lean batched classifier, measured on 215,089 real
|
|
13
|
+
events with both sides using the same safe dedup. → [USAGE.md](USAGE.md)
|
|
14
|
+
|
|
15
|
+
## Read this before you deploy it
|
|
16
|
+
|
|
17
|
+
Measured against ground truth the tool cannot see — filesystem-check exit codes
|
|
18
|
+
recorded in a separate file — it caught **42 of 59** real incidents: **71.2%
|
|
19
|
+
recall, 95% CI [58.6%, 81.2%]**.
|
|
20
|
+
|
|
21
|
+
As originally shipped it caught **0 of 59**. A dedup credited with 97% of the
|
|
22
|
+
token saving was hiding a failure that recurs 1,113 times. Fixing it cost 13
|
|
23
|
+
points of the saving, because the 89% published earlier was the same result
|
|
24
|
+
with the incidents removed.
|
|
25
|
+
|
|
26
|
+
**False-page rate is still unmeasured.** Run it beside your existing alerting,
|
|
27
|
+
not instead of it. `neos label` / `neos score` produce the evidence for your
|
|
28
|
+
own stream. → [FAIR.md](FAIR.md), [DEPLOY.md](DEPLOY.md)
|
|
29
|
+
|
|
30
|
+
## How it works
|
|
31
|
+
|
|
32
|
+
event ──[adapter]──► PACKET ──► ROUTE ─ hands settle ─► REDIAL ──► DECLINE
|
|
33
|
+
a regex every step below is bit operations
|
|
34
|
+
|
|
35
|
+
`route()`, `redial()` and `decline()` are verified against compiled C kernels
|
|
36
|
+
over **all 256 inputs**. Nothing is trained, tuned or fitted. The laws never
|
|
37
|
+
see words — an adapter converts at the boundary and decides nothing, which is
|
|
38
|
+
why text arriving in an event cannot reach the control path.
|
|
39
|
+
|
|
40
|
+
Adapters auto-detect: syslog (ISO and BSD), `.NET`/Unity, tagged, NDJSON.
|
|
41
|
+
Below a 50% parse rate it **refuses** rather than reporting a confident 0%.
|
|
42
|
+
|
|
43
|
+
## What it will not do
|
|
44
|
+
|
|
45
|
+
It reports. It cannot send, write, execute or act — no `subprocess`, no
|
|
46
|
+
`exec`, no network, **zero dependencies**, all enforced by tests rather than
|
|
47
|
+
claimed.
|
|
48
|
+
|
|
49
|
+
## Tests
|
|
50
|
+
|
|
51
|
+
python3 tests/test_triage.py # 22
|
|
52
|
+
python3 fairtest.py # incident recall vs an independent oracle
|
|
53
|
+
|
|
54
|
+
Two properties are *proved*, not sampled: the hand set is **total** over all 64
|
|
55
|
+
packet shapes — no event is ruled and then dropped — and the decision path
|
|
56
|
+
imports nothing.
|
|
57
|
+
|
|
58
|
+
## Licence
|
|
59
|
+
|
|
60
|
+
Apache-2.0. The sibling project that carries fluidfix's AGPL kernel is not
|
|
61
|
+
distributed here.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
neos -- exact laws for routing work, with no model in the decision.
|
|
3
|
+
|
|
4
|
+
route(observation_byte) -> how many voices open
|
|
5
|
+
redial(doubt_byte) -> how many must agree
|
|
6
|
+
decline(act, demand) -> whether the round is refused
|
|
7
|
+
|
|
8
|
+
Every function is a handful of bit operations over a byte, verified against
|
|
9
|
+
a compiled C kernel over all 256 inputs. Nothing is trained, tuned or fitted.
|
|
10
|
+
|
|
11
|
+
The laws never see words. A transducer converts at each boundary and decides
|
|
12
|
+
nothing. Where input already has fields -- events, alerts, telemetry --
|
|
13
|
+
that transducer is free, which is where this pays for itself.
|
|
14
|
+
"""
|
|
15
|
+
from .laws import route, redial, decline, ACT, DEM, HAVE, NEED, KOF, fold_route
|
|
16
|
+
from .measure import (hazards, doubts_actions, HAZARD_NAMES, DOUBT_NAMES,
|
|
17
|
+
deciding_hazards, deciding_doubts)
|
|
18
|
+
from .packet import Packet, SCHEMA
|
|
19
|
+
|
|
20
|
+
__all__ = ["route", "redial", "decline", "ACT", "DEM", "HAVE", "NEED", "KOF",
|
|
21
|
+
"fold_route", "hazards", "doubts_actions", "HAZARD_NAMES",
|
|
22
|
+
"DOUBT_NAMES", "deciding_hazards", "deciding_doubts",
|
|
23
|
+
"Packet", "SCHEMA"]
|
|
24
|
+
__version__ = "1.1.0"
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""
|
|
2
|
+
neos -- triage a structured event stream by exact law. No model in the loop.
|
|
3
|
+
|
|
4
|
+
python3 -m neos.cli /var/log/install.log
|
|
5
|
+
python3 -m neos.cli --json /var/log/syslog > verdicts.json
|
|
6
|
+
tail -f /var/log/app.log | python3 -m neos.cli -
|
|
7
|
+
|
|
8
|
+
Every disposition is a few bit operations over a byte. Nothing is trained,
|
|
9
|
+
nothing is sampled, and the same laws run here as in the mail agent -- see
|
|
10
|
+
ALERTS.md for what that does and does not buy.
|
|
11
|
+
"""
|
|
12
|
+
import sys, json, collections, argparse, os
|
|
13
|
+
from .stream import detect, read, ADAPTERS, Event
|
|
14
|
+
from .triage import (encode, signature, Dedup, rule, default_hands,
|
|
15
|
+
HAZARD_WHY, DOUBT_WHY)
|
|
16
|
+
from .laws import ACT, DEM
|
|
17
|
+
from .measure import HAZARD_NAMES, DOUBT_NAMES, deciding_hazards, deciding_doubts
|
|
18
|
+
|
|
19
|
+
MIN_PARSE = 0.50
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def disposition(case, held, act):
|
|
23
|
+
if act == 0: return "no-call"
|
|
24
|
+
if held: return "held"
|
|
25
|
+
if case.get("flags"): return "page"
|
|
26
|
+
if case.get("plan"): return "runbook"
|
|
27
|
+
if case.get("ticket"): return "ticket"
|
|
28
|
+
if case.get("archive"): return "suppress"
|
|
29
|
+
return "UNDISPOSED" # tests prove unreachable; if it prints, tell me
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def events(path, adapter):
|
|
33
|
+
if path == "-":
|
|
34
|
+
ad = adapter or ADAPTERS[0]
|
|
35
|
+
prev = None
|
|
36
|
+
for line in sys.stdin:
|
|
37
|
+
e = ad.parse(line.rstrip("\n"))
|
|
38
|
+
if e is None:
|
|
39
|
+
if prev is not None: prev.message += " " + line.strip()
|
|
40
|
+
continue
|
|
41
|
+
if prev is not None: yield prev
|
|
42
|
+
prev = e
|
|
43
|
+
if prev is not None: yield prev
|
|
44
|
+
else:
|
|
45
|
+
yield from read(path, adapter)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def verdicts(path, adapter, hands, budget, dedup_cap, stats=None,
|
|
49
|
+
window=300.0, every=20):
|
|
50
|
+
"""One pass. Yields a verdict dict per DISTINCT event, and the dedup so
|
|
51
|
+
the caller can report repeats. Shared by triage and label: if they used
|
|
52
|
+
separate loops the labelled sample would not describe the actual run."""
|
|
53
|
+
# stats is MUTABLE ON PURPOSE. Reading the total off the last yielded
|
|
54
|
+
# value undercounts by however many duplicates trail the final distinct
|
|
55
|
+
# event -- 914 of 215,089 on one real file, silently.
|
|
56
|
+
stats = {} if stats is None else stats
|
|
57
|
+
stats.setdefault("events", 0)
|
|
58
|
+
dd, spent, n = Dedup(cap=dedup_cap, window=window, every=every), 0.0, 0
|
|
59
|
+
stats["dedup"] = dd
|
|
60
|
+
for ev in events(path, adapter):
|
|
61
|
+
n += 1
|
|
62
|
+
stats["events"] = n
|
|
63
|
+
# RULE FIRST, DEDUP SECOND. The laws cost zero tokens, so there was
|
|
64
|
+
# never a reason to put a hash set in front of them -- and doing so
|
|
65
|
+
# gave 0% incident recall against independent ground truth, because
|
|
66
|
+
# a recurring failure was ruled once in 2024 and never again.
|
|
67
|
+
# Dedup belongs in front of the EXPENSIVE step (decode), which is
|
|
68
|
+
# what it still gates, not in front of the free one.
|
|
69
|
+
pkt = encode(ev)
|
|
70
|
+
act, dem, held, obs, doubt, case, acts = rule(
|
|
71
|
+
pkt, hands=hands, budget_used=spent, budget_cap=budget)
|
|
72
|
+
spent += len(acts)
|
|
73
|
+
if dd.seen(signature(ev), ev.epoch):
|
|
74
|
+
stats["ruled_then_deduped"] = stats.get("ruled_then_deduped", 0) + 1
|
|
75
|
+
continue
|
|
76
|
+
yield n, dd, {
|
|
77
|
+
"disposition": disposition(case, held, act),
|
|
78
|
+
"act": ACT[act], "demand": DEM[dem], "ident": ev.ident,
|
|
79
|
+
"ts": ev.ts, "level": ev.level, "message": ev.message[:400],
|
|
80
|
+
"hazards": [HAZARD_NAMES[i] for i in range(8) if obs >> i & 1],
|
|
81
|
+
"doubts": [DOUBT_NAMES[i] for i in range(8) if doubt >> i & 1],
|
|
82
|
+
"labels": case.get("labels", []), "confidence": pkt.confidence,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def resolve(path, fmt):
|
|
87
|
+
"""Adapter or a refusal. Below MIN_PARSE this returns None rather than
|
|
88
|
+
handing back a confident-looking result over 3% of a stream."""
|
|
89
|
+
if fmt:
|
|
90
|
+
return next(x for x in ADAPTERS if x.name == fmt), 1.0
|
|
91
|
+
if path == "-":
|
|
92
|
+
return ADAPTERS[0], 1.0
|
|
93
|
+
if not os.path.exists(path):
|
|
94
|
+
print(f"neos: no such file: {path}", file=sys.stderr)
|
|
95
|
+
return None, 0.0
|
|
96
|
+
ad, rate = detect(path)
|
|
97
|
+
if ad is None or rate < MIN_PARSE:
|
|
98
|
+
print(f"neos: cannot read this stream -- best adapter "
|
|
99
|
+
f"{ad.name if ad else 'none'} matched {100*rate:.1f}% of sampled "
|
|
100
|
+
f"lines (need {100*MIN_PARSE:.0f}%).\n Pass --format "
|
|
101
|
+
f"explicitly, or add an adapter to neos/stream.py.", file=sys.stderr)
|
|
102
|
+
return None, rate
|
|
103
|
+
return ad, rate
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def cmd_label(a):
|
|
107
|
+
"""Draw a stratified sample for a human to label."""
|
|
108
|
+
from .label import draw
|
|
109
|
+
ad, rate = resolve(a.path, a.format)
|
|
110
|
+
if ad is None:
|
|
111
|
+
return 3
|
|
112
|
+
rows = [v for _, _, v in verdicts(a.path, ad, default_hands(),
|
|
113
|
+
a.budget, a.dedup_cap)]
|
|
114
|
+
sample, strata = draw(rows, per_stratum=a.per_stratum, seed=a.seed)
|
|
115
|
+
with open(a.out, "w") as f:
|
|
116
|
+
f.write(json.dumps({"_strata": strata, "source": a.path,
|
|
117
|
+
"seed": a.seed}) + "\n")
|
|
118
|
+
for r in sample:
|
|
119
|
+
f.write(json.dumps(r, ensure_ascii=False) + "\n")
|
|
120
|
+
print(f"\n wrote {a.out} -- {len(sample):,} events sampled from "
|
|
121
|
+
f"{len(rows):,} distinct")
|
|
122
|
+
print(f" stratified, so the rare classes are represented:")
|
|
123
|
+
for d, n in sorted(strata.items()):
|
|
124
|
+
got = sum(1 for r in sample if r["disposition"] == d)
|
|
125
|
+
print(f" {d:12s} {got:>4,} sampled of {n:>8,} in the stream")
|
|
126
|
+
print(f"\n Now fill in the \"human\" field on each line with one of:")
|
|
127
|
+
print(f" ok the tool was right")
|
|
128
|
+
print(f" page / runbook / ticket / suppress what it SHOULD have been")
|
|
129
|
+
print(f"\n Then: neos score {a.out}\n")
|
|
130
|
+
return 0
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def cmd_score(a):
|
|
134
|
+
from .label import score
|
|
135
|
+
return score(a.path)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def main(argv=None):
|
|
139
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
140
|
+
SUB = {"triage", "label", "score"}
|
|
141
|
+
if not argv or (argv[0] not in SUB and not argv[0].startswith("-")):
|
|
142
|
+
argv = ["triage"] + argv # `neos foo.log` still means triage
|
|
143
|
+
elif argv and argv[0].startswith("-") and argv[0] not in ("-h", "--help"):
|
|
144
|
+
argv = ["triage"] + argv
|
|
145
|
+
|
|
146
|
+
top = argparse.ArgumentParser(prog="neos", description=__doc__,
|
|
147
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
148
|
+
sub = top.add_subparsers(dest="cmd", required=True)
|
|
149
|
+
|
|
150
|
+
sc = sub.add_parser("score", help="score a labelled review file")
|
|
151
|
+
sc.add_argument("path", help="review file written by `neos label`")
|
|
152
|
+
|
|
153
|
+
lb = sub.add_parser("label", help="draw a stratified sample for a human")
|
|
154
|
+
lb.add_argument("path", help="log file, or - for stdin")
|
|
155
|
+
lb.add_argument("-o", "--out", default="review.jsonl")
|
|
156
|
+
lb.add_argument("--per-stratum", type=int, default=40,
|
|
157
|
+
help="events sampled per disposition (default 40)")
|
|
158
|
+
lb.add_argument("--seed", type=int, default=0)
|
|
159
|
+
lb.add_argument("--format", choices=[x.name for x in ADAPTERS])
|
|
160
|
+
lb.add_argument("--dedup-cap", type=int, default=200_000)
|
|
161
|
+
lb.add_argument("--budget", type=float, default=1e9)
|
|
162
|
+
|
|
163
|
+
ap = sub.add_parser("triage", help="rule on a stream (default)")
|
|
164
|
+
ap.add_argument("path", help="log file, or - for stdin")
|
|
165
|
+
ap.add_argument("--format", choices=[a.name for a in ADAPTERS],
|
|
166
|
+
help="force an adapter instead of detecting one")
|
|
167
|
+
ap.add_argument("--json", action="store_true", help="one JSON verdict per line")
|
|
168
|
+
ap.add_argument("--only", choices=["page", "runbook", "ticket", "suppress", "held"],
|
|
169
|
+
help="print only this disposition (with --json)")
|
|
170
|
+
ap.add_argument("--dedup-cap", type=int, default=200_000)
|
|
171
|
+
ap.add_argument("--window", type=float, default=300.0,
|
|
172
|
+
help="seconds; a signature surfaces once per window "
|
|
173
|
+
"(0 disables windowing). THE SAFETY DIAL: too long "
|
|
174
|
+
"and independent incidents look like one repeat -- "
|
|
175
|
+
"at infinity this tool scored 0%% incident recall. "
|
|
176
|
+
"Too short and nothing dedupes. Default 300.")
|
|
177
|
+
ap.add_argument("--realert-every", type=int, default=20,
|
|
178
|
+
help="when a stream carries no usable timestamp, surface "
|
|
179
|
+
"every Nth repeat. Bounds how many hide in a row.")
|
|
180
|
+
ap.add_argument("--budget", type=float, default=1e9,
|
|
181
|
+
help="hands per run before SPENT narrows routing")
|
|
182
|
+
ap.add_argument("--why", action="store_true", help="explain each verdict")
|
|
183
|
+
a = top.parse_args(argv)
|
|
184
|
+
if a.cmd == "score":
|
|
185
|
+
return cmd_score(a)
|
|
186
|
+
if a.cmd == "label":
|
|
187
|
+
return cmd_label(a)
|
|
188
|
+
|
|
189
|
+
adapter, rate = resolve(a.path, a.format)
|
|
190
|
+
if adapter is None:
|
|
191
|
+
return 3 if os.path.exists(a.path) or a.path == "-" else 2
|
|
192
|
+
|
|
193
|
+
hands = default_hands()
|
|
194
|
+
out, stats = collections.Counter(), {}
|
|
195
|
+
for _n, dd, v in verdicts(a.path, adapter, hands, a.budget, a.dedup_cap,
|
|
196
|
+
stats, a.window, a.realert_every):
|
|
197
|
+
d = v["disposition"]
|
|
198
|
+
out[d] += 1
|
|
199
|
+
if a.json:
|
|
200
|
+
if a.only and d != a.only:
|
|
201
|
+
continue
|
|
202
|
+
print(json.dumps(v, ensure_ascii=False))
|
|
203
|
+
elif a.why and d in ("page", "runbook", "held"):
|
|
204
|
+
obs = doubt = 0
|
|
205
|
+
ev = type("E", (), {"ident": v["ident"], "message": v["message"]})
|
|
206
|
+
act = ACT.index(v["act"]); dem = DEM.index(v["demand"])
|
|
207
|
+
hz = [(h, HAZARD_WHY[HAZARD_NAMES.index(h)]) for h in v["hazards"]]
|
|
208
|
+
db = [(x, DOUBT_WHY[DOUBT_NAMES.index(x)]) for x in v["doubts"]]
|
|
209
|
+
print(f" [{d}] {v['ident']}: {v['message'][:90]}")
|
|
210
|
+
print(f" opened {ACT[act]}"
|
|
211
|
+
+ (f" because {hz[0][1]}" if hz else "")
|
|
212
|
+
+ f"; demands {DEM[dem]}"
|
|
213
|
+
+ (f" because {db[0][1]}" if db else "") + ".")
|
|
214
|
+
|
|
215
|
+
n, dd = stats.get("events", 0), stats.get("dedup")
|
|
216
|
+
if a.json:
|
|
217
|
+
return 0
|
|
218
|
+
if not n:
|
|
219
|
+
print("neos: no events read", file=sys.stderr); return 1
|
|
220
|
+
uniq = sum(out.values())
|
|
221
|
+
out["deduped"] = n - uniq
|
|
222
|
+
P = lambda c, t: f"{c:>9,} {100*c/t:6.2f}%" if t else f"{c:>9,} -"
|
|
223
|
+
print(f"\n {a.path} adapter={adapter.name if adapter else 'stdin'}"
|
|
224
|
+
+ (f" ({100*rate:.1f}% parsed)" if a.path != "-" else ""))
|
|
225
|
+
print(f" {n:,} events -> {uniq:,} distinct\n")
|
|
226
|
+
print(f" {'deduped (hash set, not a law)':32s} {P(out['deduped'], n)}")
|
|
227
|
+
for d in ("suppress", "ticket", "page", "runbook", "held", "no-call",
|
|
228
|
+
"UNDISPOSED"):
|
|
229
|
+
if out[d]:
|
|
230
|
+
print(f" {d:32s} {P(out[d], uniq)}"
|
|
231
|
+
+ (" <-- BUG: report this" if d == "UNDISPOSED" else ""))
|
|
232
|
+
words = out["runbook"]
|
|
233
|
+
print(f"\n events that ever become words {words:>9,} "
|
|
234
|
+
f"{100*words/n:6.4f}% of the stream")
|
|
235
|
+
if out["held"] == 0:
|
|
236
|
+
print(f"\n DECLINE did not fire on this stream. With {len(hands)} "
|
|
237
|
+
f"hands available the refusal")
|
|
238
|
+
print(f" path engages only when a round is short of voices -- it "
|
|
239
|
+
f"does fire on other")
|
|
240
|
+
print(f" streams (durable state changes demanding FULL). Not a pass; "
|
|
241
|
+
f"just untriggered.")
|
|
242
|
+
print(f" dedup window {a.window:.0f}s"
|
|
243
|
+
+ (f", re-alert every {a.realert_every} when a stream has no time"
|
|
244
|
+
if a.window else " (windowing OFF)"))
|
|
245
|
+
if dd.loudest(1):
|
|
246
|
+
sig, c = dd.loudest(1)[0]
|
|
247
|
+
print(f"\n loudest signature repeated {c:,} times")
|
|
248
|
+
print()
|
|
249
|
+
return 0
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
if __name__ == "__main__":
|
|
253
|
+
sys.exit(main())
|