contextos-auditor 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.
- contextos_auditor-0.1.0/.gitignore +23 -0
- contextos_auditor-0.1.0/CHANGELOG.md +119 -0
- contextos_auditor-0.1.0/LICENSE +155 -0
- contextos_auditor-0.1.0/PKG-INFO +489 -0
- contextos_auditor-0.1.0/README.md +288 -0
- contextos_auditor-0.1.0/contextos_auditor/__init__.py +26 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/__init__.py +0 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/audit_emit.py +148 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/base.py +317 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/compat.py +101 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/dedupe.py +53 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/otel_export.py +124 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/pricing.py +92 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/redact.py +76 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/shadow_kit.py +309 -0
- contextos_auditor-0.1.0/contextos_auditor/_internal/tokens.py +57 -0
- contextos_auditor-0.1.0/contextos_auditor/autogen.py +180 -0
- contextos_auditor-0.1.0/contextos_auditor/cli.py +371 -0
- contextos_auditor-0.1.0/contextos_auditor/crewai.py +108 -0
- contextos_auditor-0.1.0/contextos_auditor/demo.py +193 -0
- contextos_auditor-0.1.0/contextos_auditor/langgraph.py +153 -0
- contextos_auditor-0.1.0/contextos_auditor/openai_agents.py +139 -0
- contextos_auditor-0.1.0/contextos_auditor/report.py +782 -0
- contextos_auditor-0.1.0/contextos_auditor/server.py +120 -0
- contextos_auditor-0.1.0/docs/product-hunt-launch.md +86 -0
- contextos_auditor-0.1.0/docs/screenshots/live-dashboard.png +0 -0
- contextos_auditor-0.1.0/pyproject.toml +51 -0
- contextos_auditor-0.1.0/scripts/build_binary.sh +64 -0
- contextos_auditor-0.1.0/tests/__init__.py +0 -0
- contextos_auditor-0.1.0/tests/test_compat_warnings.py +38 -0
- contextos_auditor-0.1.0/tests/test_crash_isolation.py +106 -0
- contextos_auditor-0.1.0/tests/test_crewai_public_adapter.py +91 -0
- contextos_auditor-0.1.0/tests/test_dashboard_enhancements.py +285 -0
- contextos_auditor-0.1.0/tests/test_demo.py +109 -0
- contextos_auditor-0.1.0/tests/test_history.py +73 -0
- contextos_auditor-0.1.0/tests/test_model_backfill.py +45 -0
- contextos_auditor-0.1.0/tests/test_no_network_calls.py +119 -0
- contextos_auditor-0.1.0/tests/test_optimiser_cta.py +71 -0
- contextos_auditor-0.1.0/tests/test_otel_export.py +87 -0
- contextos_auditor-0.1.0/tests/test_pricing.py +91 -0
- contextos_auditor-0.1.0/tests/test_public_api_surface.py +56 -0
- contextos_auditor-0.1.0/tests/test_redaction.py +119 -0
- contextos_auditor-0.1.0/tests/test_server_sse_parse.py +24 -0
- contextos_auditor-0.1.0/tests/test_trace_view.py +61 -0
- contextos_auditor-0.1.0/tests/test_watch_waits_for_session.py +94 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.venv/
|
|
2
|
+
.venv-fw/
|
|
3
|
+
traces/
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.pyc
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
out/
|
|
8
|
+
fixtures/java/
|
|
9
|
+
*.class
|
|
10
|
+
scripts/natbatch.jobs
|
|
11
|
+
dashboard/web/node_modules/
|
|
12
|
+
node_modules/
|
|
13
|
+
dashboard/web/dist/
|
|
14
|
+
dashboard/web/*.tsbuildinfo
|
|
15
|
+
.tokcache/
|
|
16
|
+
packages/agentcost-kit-js/dist/
|
|
17
|
+
packages/agentcost-kit-js/*.tsbuildinfo
|
|
18
|
+
packages/agentcost-kit-py/*.egg-info/
|
|
19
|
+
packages/agentcost-kit-py/build/
|
|
20
|
+
packages/agentcost-kit-py/dist/
|
|
21
|
+
|
|
22
|
+
# contextos-auditor local session captures (contain raw tool args/results)
|
|
23
|
+
.contextos/
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `contextos-auditor` are documented here.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] — unreleased (pre-PyPI)
|
|
6
|
+
|
|
7
|
+
Initial public release candidate. Not yet published to PyPI — install from
|
|
8
|
+
source in the meantime (see README Quickstart).
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Nested turn → tool-call trace (AUD-013)**: `report`/`watch` (terminal
|
|
12
|
+
and HTML/live dashboard) now render a per-turn breakdown of which tools
|
|
13
|
+
were called and which write triggered waste detection, instead of only
|
|
14
|
+
bottom-line totals -- built from data `shadow_session()` already
|
|
15
|
+
computes, no new instrumentation. Live-verified via screenshot.
|
|
16
|
+
- **`contextos-auditor history` command (AUD-014)**: lists every recorded
|
|
17
|
+
session under `--audit-root`, newest first, with framework/model/status/
|
|
18
|
+
turns/tokens/cost/save% columns, `--limit N` (default 20, `0` = no cap).
|
|
19
|
+
Reads only the session files each run already writes; no new database
|
|
20
|
+
or aggregation step.
|
|
21
|
+
- **Optional secret-pattern redaction (AUD-016)**: `attach(...,
|
|
22
|
+
redact_secrets=True)` (or `CONTEXTOS_REDACT_SECRETS=1`) scrubs
|
|
23
|
+
recognizable secret-shaped substrings (AWS/OpenAI/GitHub/Slack-style
|
|
24
|
+
keys, JWTs, PEM private keys, generic `api_key=`/`password=`/`token=`
|
|
25
|
+
assignments) from recorded tool args/results with `[REDACTED]`,
|
|
26
|
+
replacing only the matched value -- not the whole tool call, so real
|
|
27
|
+
file content the write-waste detector needs stays intact. Off by
|
|
28
|
+
default; live-verified that waste detection keeps working correctly
|
|
29
|
+
with it turned on.
|
|
30
|
+
- **Optional OTel export (AUD-012)**: `pip install contextos-auditor[otel]`
|
|
31
|
+
plus `attach(..., otel_endpoint="http://localhost:4318/v1/traces")` (or
|
|
32
|
+
the `CONTEXTOS_OTEL_ENDPOINT` env var, zero code changes) makes every
|
|
33
|
+
adapter additionally export each turn as a real OTel span following the
|
|
34
|
+
GenAI semantic conventions (`gen_ai.system`, `gen_ai.request.model`,
|
|
35
|
+
`gen_ai.usage.input_tokens/output_tokens`, `gen_ai.tool.name`, ...) --
|
|
36
|
+
verified against a real local OTLP/HTTP receiver. Strictly additive and
|
|
37
|
+
opt-in: the local JSONL trail is unaffected either way, and a missing
|
|
38
|
+
package or unreachable collector degrades to one `UserWarning`, never a
|
|
39
|
+
crash in the agent's real run.
|
|
40
|
+
- **Real $ cost estimate (AUD-011)**: sessions for models in a small,
|
|
41
|
+
hand-curated, dated pricing snapshot (`_internal/pricing.py`, sourced
|
|
42
|
+
from litellm's publicly maintained pricing table) now show an
|
|
43
|
+
estimated `$` figure alongside token counts in `watch`/`watch --serve`/
|
|
44
|
+
`report`, clearly labeled "list price as of DATE, not your negotiated
|
|
45
|
+
rate". Unpriced models show "no dated pricing available" rather than a
|
|
46
|
+
guessed number — the Auditor's honesty-culture rule (never invent a
|
|
47
|
+
billing figure) still holds, this just widens what counts as "real".
|
|
48
|
+
- Fixed **AUD-018**: the model name is now backfilled from the first real
|
|
49
|
+
LLM event a framework reports (e.g. CrewAI's
|
|
50
|
+
`LLMCallCompletedEvent.model`) instead of staying `unknown` for the
|
|
51
|
+
entire session when no `model_hint` was passed to `attach()`.
|
|
52
|
+
- Fixed **AUD-017/AUD-019**: `watch`/`watch --serve` now poll and wait for
|
|
53
|
+
a session to appear instead of exiting immediately if the dashboard is
|
|
54
|
+
opened before the agent run starts (at least as natural an order as the
|
|
55
|
+
reverse). Plain `watch` also now detects a finished/errored session and
|
|
56
|
+
stops on its own instead of refreshing forever until Ctrl-C.
|
|
57
|
+
- Free, local-only Agent Auditor (**free for any use, commercial included
|
|
58
|
+
— licensed under PolyForm Shield 1.0.0, noncompete only, see LICENSE**):
|
|
59
|
+
attach one line to an
|
|
60
|
+
existing CrewAI / LangGraph / AutoGen / OpenAI Agents SDK agent and
|
|
61
|
+
watch its real token cost live. No signup, no telemetry, no data leaves
|
|
62
|
+
the machine it runs on.
|
|
63
|
+
- **Crash isolation (AUD-009)**: every adapter handler and
|
|
64
|
+
`FrameworkAuditSession` entry point is now `@guarded` — an internal
|
|
65
|
+
Auditor failure (malformed usage dict, SDK version drift, full disk)
|
|
66
|
+
can never propagate into the agent's real execution path. Fixed a
|
|
67
|
+
critical case in the AutoGen adapter where a recording failure could
|
|
68
|
+
previously discard an already-successful, already-billed LLM call
|
|
69
|
+
result.
|
|
70
|
+
- Public adapters for all 4 frameworks (`contextos_auditor.crewai`,
|
|
71
|
+
`.langgraph`, `.openai_agents`, `.autogen`), each vendoring (not
|
|
72
|
+
importing) the corresponding internal `dashboard/adapters/*` logic so
|
|
73
|
+
the package has zero dependency on the toku monorepo at runtime.
|
|
74
|
+
- `contextos-auditor` CLI: `watch` (terminal table, auto-refreshing HTML,
|
|
75
|
+
or `--serve` for a localhost-only live browser view over Server-Sent
|
|
76
|
+
Events), `report` (one-shot static summary), `doctor` (checks which
|
|
77
|
+
framework SDKs are importable and whether their installed version falls
|
|
78
|
+
inside this release's tested range).
|
|
79
|
+
- Project-local `.contextos/audit/` output directory by default (no
|
|
80
|
+
assumption the caller lives inside any particular repo layout).
|
|
81
|
+
- Per-framework `[crewai]`/`[langgraph]`/`[autogen]`/`[openai-agents]`/
|
|
82
|
+
`[all]` optional extras; zero required runtime dependencies.
|
|
83
|
+
- Hard, CI-enforced network-isolation test suite
|
|
84
|
+
(`tests/test_no_network_calls.py`): the live `--serve` view is proven,
|
|
85
|
+
not just claimed, to make outbound connections only to loopback.
|
|
86
|
+
- SDK version-drift detection (`_internal/compat.py`): a one-time
|
|
87
|
+
`UserWarning` (never a hard failure) when an installed framework SDK
|
|
88
|
+
version falls outside the range the vendored adapter was last verified
|
|
89
|
+
against, surfaced proactively in `contextos-auditor doctor`.
|
|
90
|
+
- `scripts/build_binary.sh`: builds a standalone, single-file CLI binary
|
|
91
|
+
(PyInstaller, built from a clean venv with zero framework extras) for
|
|
92
|
+
teammates who want to `watch`/`report`/`doctor` a session without any
|
|
93
|
+
Python/pip on their machine at all. Verified to run correctly in a fully
|
|
94
|
+
empty environment (`env -i`, no PATH/PYTHONHOME).
|
|
95
|
+
|
|
96
|
+
### Fixed
|
|
97
|
+
- **P0**: `watch --serve`'s live dashboard corrupted itself into visible
|
|
98
|
+
raw `\n`/quote-mark text after the very first live update. The server
|
|
99
|
+
correctly JSON-encodes each SSE fragment (`json.dumps(fragment)`) but
|
|
100
|
+
the injected client-side JS assigned the raw, still-encoded string
|
|
101
|
+
straight into `document.body.innerHTML` instead of decoding it first.
|
|
102
|
+
Found via a real headless-Chrome screenshot of the running dashboard,
|
|
103
|
+
not code review. Fixed: client now does `JSON.parse(e.data)` before
|
|
104
|
+
use. Regression test: `tests/test_server_sse_parse.py`.
|
|
105
|
+
- Restyled `watch`/`watch --serve`/`--html`'s dashboard to match the
|
|
106
|
+
marketing site's dark theme (same background/panel/accent colors,
|
|
107
|
+
mono-font numeric table, teal-for-positive/red-for-negative percent)
|
|
108
|
+
instead of the previous unstyled light-mode default — this is now the
|
|
109
|
+
one visual identity used everywhere the product shows a UI. Deliberately
|
|
110
|
+
does not load the marketing site's Google Fonts (system-font fallback
|
|
111
|
+
only), keeping the dashboard's own zero-external-network guarantee
|
|
112
|
+
(AUD-005) intact for the actual tool, not just the marketing page.
|
|
113
|
+
|
|
114
|
+
### Known limitations
|
|
115
|
+
- The `_internal/*.py` vendor copies are manually synced against the
|
|
116
|
+
monorepo's `dashboard/`/`kit/`/`spike/` originals — not automatic. See
|
|
117
|
+
README.
|
|
118
|
+
- No hosted/team dashboard in this package by design; that's a paid-tier
|
|
119
|
+
feature. This package is local-only, always.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
PolyForm Shield License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
4
|
+
|
|
5
|
+
Required Notice: Copyright Suraj Jha (https://github.com/surajJha)
|
|
6
|
+
|
|
7
|
+
Licensor Line of Business: ContextOS agent token/cost auditing and
|
|
8
|
+
optimisation tooling (contextos-auditor, contextos-optimiser)
|
|
9
|
+
|
|
10
|
+
Plain-English summary (not a substitute for the terms below): you may use
|
|
11
|
+
this software for **any** purpose, including inside a commercial company
|
|
12
|
+
and on commercial products, free of charge. You may modify it and
|
|
13
|
+
redistribute it. The one thing you may not do is use it to provide a
|
|
14
|
+
product that competes with ContextOS.
|
|
15
|
+
|
|
16
|
+
## Acceptance
|
|
17
|
+
|
|
18
|
+
In order to get any license under these terms, you must agree to them as
|
|
19
|
+
both strict obligations and conditions to all your licenses.
|
|
20
|
+
|
|
21
|
+
## Copyright License
|
|
22
|
+
|
|
23
|
+
The licensor grants you a copyright license for the software to do
|
|
24
|
+
everything you might do with the software that would otherwise infringe
|
|
25
|
+
the licensor's copyright in it for any permitted purpose. However, you may
|
|
26
|
+
only distribute the software according to Distribution License and make
|
|
27
|
+
changes or new works based on the software according to Changes and New
|
|
28
|
+
Works License.
|
|
29
|
+
|
|
30
|
+
## Distribution License
|
|
31
|
+
|
|
32
|
+
The licensor grants you an additional copyright license to distribute
|
|
33
|
+
copies of the software. Your license to distribute covers distributing the
|
|
34
|
+
software with changes and new works permitted by Changes and New Works
|
|
35
|
+
License.
|
|
36
|
+
|
|
37
|
+
## Notices
|
|
38
|
+
|
|
39
|
+
You must ensure that anyone who gets a copy of any part of the software
|
|
40
|
+
from you also gets a copy of these terms or the URL for them above, as
|
|
41
|
+
well as copies of any plain-text lines beginning with `Required Notice:`
|
|
42
|
+
that the licensor provided with the software. For example:
|
|
43
|
+
|
|
44
|
+
> Required Notice: Copyright Suraj Jha (https://github.com/surajJha)
|
|
45
|
+
|
|
46
|
+
## Changes and New Works License
|
|
47
|
+
|
|
48
|
+
The licensor grants you an additional copyright license to make changes
|
|
49
|
+
and new works based on the software for any permitted purpose.
|
|
50
|
+
|
|
51
|
+
## Patent License
|
|
52
|
+
|
|
53
|
+
The licensor grants you a patent license for the software that covers
|
|
54
|
+
patent claims the licensor can license, or becomes able to license, that
|
|
55
|
+
you would infringe by using the software.
|
|
56
|
+
|
|
57
|
+
## Noncompete
|
|
58
|
+
|
|
59
|
+
Any purpose is a permitted purpose, except for providing any product that
|
|
60
|
+
competes with the software or any product the licensor or any of its
|
|
61
|
+
affiliates provides using the software.
|
|
62
|
+
|
|
63
|
+
## Competition
|
|
64
|
+
|
|
65
|
+
Goods and services compete even when they provide functionality through
|
|
66
|
+
different kinds of interfaces or for different technical platforms.
|
|
67
|
+
Applications can compete with services, libraries with plugins, frameworks
|
|
68
|
+
with development tools, and so on, even if they're written in different
|
|
69
|
+
programming languages or for different computer architectures. Goods and
|
|
70
|
+
services compete even when provided free of charge. If you market a
|
|
71
|
+
product as a practical substitute for the software or another product, it
|
|
72
|
+
definitely competes.
|
|
73
|
+
|
|
74
|
+
## New Products
|
|
75
|
+
|
|
76
|
+
If you are using the software to provide a product that does not compete,
|
|
77
|
+
but the licensor or any of its affiliates brings your product into
|
|
78
|
+
competition by providing a new version of the software or another product
|
|
79
|
+
using the software, you may continue using versions of the software
|
|
80
|
+
available under these terms beforehand to provide your competing product,
|
|
81
|
+
but not any later versions.
|
|
82
|
+
|
|
83
|
+
## Discontinued Products
|
|
84
|
+
|
|
85
|
+
You may begin using the software to compete with a product or service that
|
|
86
|
+
the licensor or any of its affiliates has stopped providing, unless the
|
|
87
|
+
licensor includes a plain-text line beginning with `Licensor Line of
|
|
88
|
+
Business:` with the software that mentions that line of business.
|
|
89
|
+
|
|
90
|
+
## Sales of Business
|
|
91
|
+
|
|
92
|
+
If the licensor or any of its affiliates sells a line of business
|
|
93
|
+
developing the software or using the software to provide a product, the
|
|
94
|
+
buyer can also enforce Noncompete for that product.
|
|
95
|
+
|
|
96
|
+
## Fair Use
|
|
97
|
+
|
|
98
|
+
You may have "fair use" rights for the software under the law. These terms
|
|
99
|
+
do not limit them.
|
|
100
|
+
|
|
101
|
+
## No Other Rights
|
|
102
|
+
|
|
103
|
+
These terms do not allow you to sublicense or transfer any of your
|
|
104
|
+
licenses to anyone else, or prevent the licensor from granting licenses to
|
|
105
|
+
anyone else. These terms do not imply any other licenses.
|
|
106
|
+
|
|
107
|
+
## Patent Defense
|
|
108
|
+
|
|
109
|
+
If you make any written claim that the software infringes or contributes
|
|
110
|
+
to infringement of any patent, your patent license for the software
|
|
111
|
+
granted under these terms ends immediately. If your company makes such a
|
|
112
|
+
claim, your patent license ends immediately for work on behalf of your
|
|
113
|
+
company.
|
|
114
|
+
|
|
115
|
+
## Violations
|
|
116
|
+
|
|
117
|
+
The first time you are notified in writing that you have violated any of
|
|
118
|
+
these terms, or done anything with the software not covered by your
|
|
119
|
+
licenses, your licenses can nonetheless continue if you come into full
|
|
120
|
+
compliance with these terms, and take practical steps to correct past
|
|
121
|
+
violations, within 32 days of receiving notice. Otherwise, all your
|
|
122
|
+
licenses end immediately.
|
|
123
|
+
|
|
124
|
+
## No Liability
|
|
125
|
+
|
|
126
|
+
***As far as the law allows, the software comes as is, without any
|
|
127
|
+
warranty or condition, and the licensor will not be liable to you for any
|
|
128
|
+
damages arising out of these terms or the use or nature of the software,
|
|
129
|
+
under any kind of legal claim.***
|
|
130
|
+
|
|
131
|
+
## Definitions
|
|
132
|
+
|
|
133
|
+
The **licensor** is the individual or entity offering these terms, and the
|
|
134
|
+
**software** is the software the licensor makes available under these
|
|
135
|
+
terms.
|
|
136
|
+
|
|
137
|
+
A **product** can be a good or service, or a combination of them.
|
|
138
|
+
|
|
139
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
140
|
+
|
|
141
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of
|
|
142
|
+
organization that you work for, plus all its affiliates.
|
|
143
|
+
|
|
144
|
+
**Affiliates** means the other organizations that an organization has
|
|
145
|
+
control over, is under the control of, or is under common control with.
|
|
146
|
+
|
|
147
|
+
**Control** means ownership of substantially all the assets of an entity,
|
|
148
|
+
or the power to direct its management and policies by vote, contract, or
|
|
149
|
+
otherwise. Control can be direct or indirect.
|
|
150
|
+
|
|
151
|
+
**Your licenses** are all the licenses granted to you for the software
|
|
152
|
+
under these terms.
|
|
153
|
+
|
|
154
|
+
**Use** means anything you do with the software requiring one of your
|
|
155
|
+
licenses.
|