token-runtime 0.1.0a2__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.
- token_runtime-0.1.0a2/LICENSE +202 -0
- token_runtime-0.1.0a2/PKG-INFO +238 -0
- token_runtime-0.1.0a2/README.md +213 -0
- token_runtime-0.1.0a2/pyproject.toml +55 -0
- token_runtime-0.1.0a2/setup.cfg +4 -0
- token_runtime-0.1.0a2/src/token_runtime/__init__.py +1 -0
- token_runtime-0.1.0a2/src/token_runtime/adapters.py +181 -0
- token_runtime-0.1.0a2/src/token_runtime/agent_integrations.py +114 -0
- token_runtime-0.1.0a2/src/token_runtime/anthropic_adapter.py +301 -0
- token_runtime-0.1.0a2/src/token_runtime/anthropic_conformance.py +336 -0
- token_runtime-0.1.0a2/src/token_runtime/anthropic_preserved_thinking_cert.py +213 -0
- token_runtime-0.1.0a2/src/token_runtime/benchmark.py +106 -0
- token_runtime-0.1.0a2/src/token_runtime/capabilities.py +111 -0
- token_runtime-0.1.0a2/src/token_runtime/cli.py +284 -0
- token_runtime-0.1.0a2/src/token_runtime/codex_recertification.py +115 -0
- token_runtime-0.1.0a2/src/token_runtime/compat_cert.py +462 -0
- token_runtime-0.1.0a2/src/token_runtime/compatibility.py +81 -0
- token_runtime-0.1.0a2/src/token_runtime/config.py +72 -0
- token_runtime-0.1.0a2/src/token_runtime/conformance.py +36 -0
- token_runtime-0.1.0a2/src/token_runtime/contracts.py +70 -0
- token_runtime-0.1.0a2/src/token_runtime/engine.py +136 -0
- token_runtime-0.1.0a2/src/token_runtime/feature_flags.py +78 -0
- token_runtime-0.1.0a2/src/token_runtime/gateway.py +151 -0
- token_runtime-0.1.0a2/src/token_runtime/gemini_adapter.py +260 -0
- token_runtime-0.1.0a2/src/token_runtime/gemini_conformance.py +351 -0
- token_runtime-0.1.0a2/src/token_runtime/integrations.py +272 -0
- token_runtime-0.1.0a2/src/token_runtime/metrics.py +79 -0
- token_runtime-0.1.0a2/src/token_runtime/model.py +39 -0
- token_runtime-0.1.0a2/src/token_runtime/openai_certification.py +310 -0
- token_runtime-0.1.0a2/src/token_runtime/planner.py +96 -0
- token_runtime-0.1.0a2/src/token_runtime/reducers.py +179 -0
- token_runtime-0.1.0a2/src/token_runtime/store.py +36 -0
- token_runtime-0.1.0a2/src/token_runtime/strategies.py +50 -0
- token_runtime-0.1.0a2/src/token_runtime/terminal_ui.py +96 -0
- token_runtime-0.1.0a2/src/token_runtime.egg-info/PKG-INFO +238 -0
- token_runtime-0.1.0a2/src/token_runtime.egg-info/SOURCES.txt +79 -0
- token_runtime-0.1.0a2/src/token_runtime.egg-info/dependency_links.txt +1 -0
- token_runtime-0.1.0a2/src/token_runtime.egg-info/entry_points.txt +2 -0
- token_runtime-0.1.0a2/src/token_runtime.egg-info/requires.txt +6 -0
- token_runtime-0.1.0a2/src/token_runtime.egg-info/top_level.txt +1 -0
- token_runtime-0.1.0a2/tests/test_adapters.py +83 -0
- token_runtime-0.1.0a2/tests/test_agent_integration_safety.py +118 -0
- token_runtime-0.1.0a2/tests/test_agent_integrations.py +112 -0
- token_runtime-0.1.0a2/tests/test_alpha2_release_candidate.py +51 -0
- token_runtime-0.1.0a2/tests/test_anthropic_adapter.py +327 -0
- token_runtime-0.1.0a2/tests/test_anthropic_conformance.py +87 -0
- token_runtime-0.1.0a2/tests/test_anthropic_preserved_thinking_benchmark.py +168 -0
- token_runtime-0.1.0a2/tests/test_anthropic_preserved_thinking_cert.py +127 -0
- token_runtime-0.1.0a2/tests/test_anthropic_preserved_thinking_live.py +500 -0
- token_runtime-0.1.0a2/tests/test_benchmark.py +83 -0
- token_runtime-0.1.0a2/tests/test_capabilities.py +116 -0
- token_runtime-0.1.0a2/tests/test_cli.py +197 -0
- token_runtime-0.1.0a2/tests/test_codex_recertification.py +103 -0
- token_runtime-0.1.0a2/tests/test_compat_cert.py +491 -0
- token_runtime-0.1.0a2/tests/test_compatibility.py +83 -0
- token_runtime-0.1.0a2/tests/test_config.py +52 -0
- token_runtime-0.1.0a2/tests/test_conformance.py +81 -0
- token_runtime-0.1.0a2/tests/test_distribution.py +838 -0
- token_runtime-0.1.0a2/tests/test_docs_growth.py +57 -0
- token_runtime-0.1.0a2/tests/test_engine.py +129 -0
- token_runtime-0.1.0a2/tests/test_evolution_contracts.py +67 -0
- token_runtime-0.1.0a2/tests/test_evolution_runtime_isolation.py +126 -0
- token_runtime-0.1.0a2/tests/test_feature_flags.py +63 -0
- token_runtime-0.1.0a2/tests/test_gateway.py +128 -0
- token_runtime-0.1.0a2/tests/test_gemini_adapter.py +324 -0
- token_runtime-0.1.0a2/tests/test_gemini_conformance.py +84 -0
- token_runtime-0.1.0a2/tests/test_governance.py +55 -0
- token_runtime-0.1.0a2/tests/test_integrations.py +165 -0
- token_runtime-0.1.0a2/tests/test_metrics.py +55 -0
- token_runtime-0.1.0a2/tests/test_model.py +43 -0
- token_runtime-0.1.0a2/tests/test_openai_certification.py +247 -0
- token_runtime-0.1.0a2/tests/test_oss_surface.py +80 -0
- token_runtime-0.1.0a2/tests/test_planner.py +123 -0
- token_runtime-0.1.0a2/tests/test_public_benchmark.py +50 -0
- token_runtime-0.1.0a2/tests/test_public_classification.py +22 -0
- token_runtime-0.1.0a2/tests/test_public_ready.py +55 -0
- token_runtime-0.1.0a2/tests/test_public_release_pipeline.py +130 -0
- token_runtime-0.1.0a2/tests/test_reducers.py +151 -0
- token_runtime-0.1.0a2/tests/test_store.py +35 -0
- token_runtime-0.1.0a2/tests/test_strategies.py +45 -0
- token_runtime-0.1.0a2/tests/test_terminal_ui.py +41 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: token-runtime
|
|
3
|
+
Version: 0.1.0a2
|
|
4
|
+
Summary: Quality-preserving local context optimization runtime for LLM clients
|
|
5
|
+
Author: Tungvoc3199
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Tungvoc3199/token-runtime
|
|
8
|
+
Project-URL: Repository, https://github.com/Tungvoc3199/token-runtime
|
|
9
|
+
Project-URL: Issues, https://github.com/Tungvoc3199/token-runtime/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/Tungvoc3199/token-runtime/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: ai-agents,context-engineering,llm,token-optimization
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: build==1.6.0; extra == "dev"
|
|
21
|
+
Requires-Dist: coverage[toml]<8,>=7; extra == "dev"
|
|
22
|
+
Requires-Dist: pre-commit<5,>=4; extra == "dev"
|
|
23
|
+
Requires-Dist: ruff<1,>=0.12; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
<div align="center">
|
|
27
|
+
|
|
28
|
+
<img src="docs/assets/token-logo.svg" alt="TOKEN" width="760" />
|
|
29
|
+
|
|
30
|
+
### Reduce context when safe. Pass through when it isn't.
|
|
31
|
+
|
|
32
|
+
Local-first adaptive context optimization for Codex and OpenAI-compatible AI agents.
|
|
33
|
+
|
|
34
|
+
[](https://github.com/Tungvoc3199/token-runtime/actions/workflows/ci.yml)
|
|
35
|
+

|
|
36
|
+

|
|
37
|
+

|
|
38
|
+

|
|
39
|
+

|
|
40
|
+
[](https://github.com/Tungvoc3199/token-runtime/releases/tag/v0.1.0-alpha.2)
|
|
41
|
+
|
|
42
|
+
[Quickstart](#quickstart) · [Proof](#proof) · [How it works](#how-it-works) · [Safety](#safety-first-by-design) · [Compatibility](#compatibility) · [Compatibility matrix](docs/COMPATIBILITY.md) · [Security](SECURITY.md)
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
> **Alpha status:** Codex persistent integration is verified. TOKEN does not claim universal quality non-inferiority or guaranteed currency savings.
|
|
47
|
+
|
|
48
|
+
<div align="center">
|
|
49
|
+
|
|
50
|
+
<img src="docs/assets/token-hero.svg" alt="TOKEN adaptive context optimization flow" width="100%" />
|
|
51
|
+
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
TOKEN sits between a supported client and its OpenAI-compatible upstream. It removes deterministic redundancy only when the planner considers the request safe to optimize. Risky or unsupported requests are forwarded unchanged.
|
|
55
|
+
|
|
56
|
+
**No TLS MITM. No prompt logging. No provider/model switching.**
|
|
57
|
+
|
|
58
|
+
## Why TOKEN
|
|
59
|
+
|
|
60
|
+
- **Quality first** — saving tokens is never enough by itself.
|
|
61
|
+
- **Risk-aware bypass** — uncertain contexts take the original request path.
|
|
62
|
+
- **Deterministic V1** — no semantic or LLM summarization in the default path.
|
|
63
|
+
- **Reversible** — removed bytes are content-addressed in a private local recovery store.
|
|
64
|
+
- **Local-first** — optimization happens on the user's machine.
|
|
65
|
+
- **Transactional integrations** — managed config changes are hash-guarded and rollback-aware.
|
|
66
|
+
|
|
67
|
+
## Proof
|
|
68
|
+
|
|
69
|
+
### Live paired example
|
|
70
|
+
|
|
71
|
+
Same task, same route, same expected answer:
|
|
72
|
+
|
|
73
|
+
| | Without TOKEN | With TOKEN |
|
|
74
|
+
|---|---:|---:|
|
|
75
|
+
| Input tokens | 6,975 | **3,927** |
|
|
76
|
+
| Input reduction | — | **43.70%** |
|
|
77
|
+
| Result | correct | **correct** |
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
checkout pod OOMKilled; raise memory limit and redeploy
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The output above was identical with and without TOKEN in the paired live test.
|
|
84
|
+
|
|
85
|
+
### Final 64-workload benchmark
|
|
86
|
+
|
|
87
|
+
| Metric | Result |
|
|
88
|
+
|---|---:|
|
|
89
|
+
| Total workloads | 64 |
|
|
90
|
+
| Optimized | 40 |
|
|
91
|
+
| Deliberately bypassed | 24 |
|
|
92
|
+
| Eligible-workload estimated saving | **28.53%** |
|
|
93
|
+
| Overall corpus estimated saving | **10.61%** |
|
|
94
|
+
| Protected-byte fidelity | **100%** |
|
|
95
|
+
| Recovery-reference resolution | **100%** |
|
|
96
|
+
|
|
97
|
+
High-risk structured decision contexts are deliberately bypassed. These are estimated input-token results for the offline corpus, not a universal quality or billed-cost claim.
|
|
98
|
+
|
|
99
|
+
## How it works
|
|
100
|
+
|
|
101
|
+
```mermaid
|
|
102
|
+
flowchart LR
|
|
103
|
+
A[Codex / OpenAI-compatible client] --> B[TOKEN local gateway]
|
|
104
|
+
B --> C{Safe to optimize?}
|
|
105
|
+
C -- No --> D[Exact passthrough]
|
|
106
|
+
C -- Yes --> E[Deterministic reducers]
|
|
107
|
+
E --> F[Private reversible recovery]
|
|
108
|
+
D --> G[Existing upstream / router]
|
|
109
|
+
F --> G
|
|
110
|
+
G --> H[Same provider and model]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
TOKEN does not choose a cheaper model or silently reroute providers. The optimization boundary is the request context itself.
|
|
114
|
+
|
|
115
|
+
The V1 planner protects the active turn, protocol state, hard constraints, exact-edit material, current evidence, and decision-sensitive content. Eligible historical context can use exact duplicate removal, repeated-line collapse, recency-preserving deduplication, JSON-aware handling, and conservative tool-output reduction.
|
|
116
|
+
|
|
117
|
+
## Quickstart
|
|
118
|
+
|
|
119
|
+
Python 3.12+ is required.
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
python3 -m pip install . --no-build-isolation
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Preview integration changes first:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
token install --upstream http://127.0.0.1:20128 --root "$HOME" --dry-run
|
|
129
|
+
```
|
|
130
|
+
Apply and run:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
token install --upstream http://127.0.0.1:20128 --root "$HOME"
|
|
134
|
+
token serve
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Verify the path:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
token doctor
|
|
141
|
+
token status
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Rollback preview and uninstall:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
token uninstall --root "$HOME" --dry-run
|
|
148
|
+
token uninstall --root "$HOME"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
For Codex, TOKEN transactionally manages only the selected OpenAI-compatible provider `base_url`. Ambiguous provider selection or post-install config drift is refused instead of overwritten.
|
|
152
|
+
|
|
153
|
+
## Safety-first by design
|
|
154
|
+
|
|
155
|
+
| Context class | TOKEN behavior |
|
|
156
|
+
|---|---|
|
|
157
|
+
| Active/latest turn | Byte-protected |
|
|
158
|
+
| System/developer + protocol state | Protected |
|
|
159
|
+
| Hard constraints / exact-edit material | Protected or bypassed |
|
|
160
|
+
| Structured JSON + decision-bearing context | **Exact passthrough** |
|
|
161
|
+
| Unsupported/multimodal wire shapes | **Exact passthrough** |
|
|
162
|
+
| Eligible historical redundancy | Deterministic optimization |
|
|
163
|
+
| Internal parse/planner/reducer failure | Original request fallback |
|
|
164
|
+
|
|
165
|
+
## Compatibility
|
|
166
|
+
|
|
167
|
+
| Integration | Alpha status |
|
|
168
|
+
|---|---|
|
|
169
|
+
| OpenAI Responses API, text payloads | ✅ Supported |
|
|
170
|
+
| OpenAI Chat Completions, text payloads | ✅ Supported |
|
|
171
|
+
| Codex with OpenAI-compatible provider config | ✅ Transactional integration verified |
|
|
172
|
+
| Codex CLI 0.154.0 Responses boundary | ✅ `CERTIFIED` at the observed request/response boundary |
|
|
173
|
+
| Generic apps honoring `OPENAI_BASE_URL` | ✅ Supported |
|
|
174
|
+
| Local OpenAI-compatible gateways/routers | ✅ Supported |
|
|
175
|
+
| Anthropic Messages adapter/conformance | 🛡️ `PASSTHROUGH_ONLY`; offline conformance, not production gateway-wired |
|
|
176
|
+
| Gemini GenerateContent adapter/conformance | 🛡️ `PASSTHROUGH_ONLY`; offline conformance, not production gateway-wired |
|
|
177
|
+
| Multimodal optimization | 🛡️ `PASSTHROUGH_ONLY` |
|
|
178
|
+
|
|
179
|
+
`CERTIFIED` is always version- and boundary-specific. Canonical source can also contain adapters that are not deployed in the active gateway. See the [compatibility matrix](docs/COMPATIBILITY.md) for the exact evidence boundary.
|
|
180
|
+
|
|
181
|
+
## Operations
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
token doctor # config, state, gateway and upstream health
|
|
185
|
+
token status # local numeric optimization metrics
|
|
186
|
+
token benchmark # run the production planner/engine on a corpus
|
|
187
|
+
token optimize # inspect one request through the optimizer
|
|
188
|
+
token uninstall # remove TOKEN-managed integration state
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Telemetry uses an allowlist. Prompt bodies, authorization headers, API keys, and arbitrary request content are not persisted as metrics.
|
|
192
|
+
|
|
193
|
+
## Benchmarking
|
|
194
|
+
|
|
195
|
+
`token benchmark` uses the same planner and optimization engine as the gateway. Benchmark inputs expose context fields only; hidden grading labels are not given to the optimizer.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
token benchmark --file cases.json
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Stable baseline
|
|
202
|
+
|
|
203
|
+
The first verified alpha baseline is locked separately from ongoing development:
|
|
204
|
+
|
|
205
|
+
- Canonical stable tag: `TOKEN-V1-ALPHA-STABLE-20260909`
|
|
206
|
+
- Canonical stable branch: `stable/token-v1-alpha-20260909`
|
|
207
|
+
- Baseline commit: `e45a09859ec3df8c7bb15589bdc096e680884175`
|
|
208
|
+
|
|
209
|
+
Canonical development continues in the private source; stable refs are not advanced with normal feature work.
|
|
210
|
+
|
|
211
|
+
## Alpha boundaries
|
|
212
|
+
|
|
213
|
+
TOKEN currently **does not claim**:
|
|
214
|
+
|
|
215
|
+
- zero quality regression for every workload;
|
|
216
|
+
- a universal percentage reduction for all requests;
|
|
217
|
+
- actual currency savings from provider billing;
|
|
218
|
+
- broad provider-cache non-regression;
|
|
219
|
+
- production native Anthropic or Gemini gateway routing;
|
|
220
|
+
- multimodal context optimization.
|
|
221
|
+
|
|
222
|
+
The approved 24-call live campaign found a real regression class. The final policy responds by bypassing that class unchanged rather than attempting more aggressive compression.
|
|
223
|
+
|
|
224
|
+
## Documentation
|
|
225
|
+
|
|
226
|
+
- [Security and privacy contract](SECURITY.md)
|
|
227
|
+
- [Claims registry](docs/CLAIMS.md)
|
|
228
|
+
- [Compatibility matrix](docs/COMPATIBILITY.md)
|
|
229
|
+
- [Threat model](docs/THREAT-MODEL.md)
|
|
230
|
+
- [Release process](docs/RELEASE-PROCESS.md)
|
|
231
|
+
- [GitHub governance](docs/GITHUB-GOVERNANCE.md)
|
|
232
|
+
- [Public benchmark](benchmarks/README.md)
|
|
233
|
+
- [v0.1.0-alpha.2 release notes](docs/releases/v0.1.0-alpha.2.md)
|
|
234
|
+
- [Apache-2.0 license](LICENSE)
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
**Design principle:** optimize the context only when doing so is safer than leaving it alone.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="docs/assets/token-logo.svg" alt="TOKEN" width="760" />
|
|
4
|
+
|
|
5
|
+
### Reduce context when safe. Pass through when it isn't.
|
|
6
|
+
|
|
7
|
+
Local-first adaptive context optimization for Codex and OpenAI-compatible AI agents.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/Tungvoc3199/token-runtime/actions/workflows/ci.yml)
|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
[](https://github.com/Tungvoc3199/token-runtime/releases/tag/v0.1.0-alpha.2)
|
|
16
|
+
|
|
17
|
+
[Quickstart](#quickstart) · [Proof](#proof) · [How it works](#how-it-works) · [Safety](#safety-first-by-design) · [Compatibility](#compatibility) · [Compatibility matrix](docs/COMPATIBILITY.md) · [Security](SECURITY.md)
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
> **Alpha status:** Codex persistent integration is verified. TOKEN does not claim universal quality non-inferiority or guaranteed currency savings.
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
|
|
25
|
+
<img src="docs/assets/token-hero.svg" alt="TOKEN adaptive context optimization flow" width="100%" />
|
|
26
|
+
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
TOKEN sits between a supported client and its OpenAI-compatible upstream. It removes deterministic redundancy only when the planner considers the request safe to optimize. Risky or unsupported requests are forwarded unchanged.
|
|
30
|
+
|
|
31
|
+
**No TLS MITM. No prompt logging. No provider/model switching.**
|
|
32
|
+
|
|
33
|
+
## Why TOKEN
|
|
34
|
+
|
|
35
|
+
- **Quality first** — saving tokens is never enough by itself.
|
|
36
|
+
- **Risk-aware bypass** — uncertain contexts take the original request path.
|
|
37
|
+
- **Deterministic V1** — no semantic or LLM summarization in the default path.
|
|
38
|
+
- **Reversible** — removed bytes are content-addressed in a private local recovery store.
|
|
39
|
+
- **Local-first** — optimization happens on the user's machine.
|
|
40
|
+
- **Transactional integrations** — managed config changes are hash-guarded and rollback-aware.
|
|
41
|
+
|
|
42
|
+
## Proof
|
|
43
|
+
|
|
44
|
+
### Live paired example
|
|
45
|
+
|
|
46
|
+
Same task, same route, same expected answer:
|
|
47
|
+
|
|
48
|
+
| | Without TOKEN | With TOKEN |
|
|
49
|
+
|---|---:|---:|
|
|
50
|
+
| Input tokens | 6,975 | **3,927** |
|
|
51
|
+
| Input reduction | — | **43.70%** |
|
|
52
|
+
| Result | correct | **correct** |
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
checkout pod OOMKilled; raise memory limit and redeploy
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The output above was identical with and without TOKEN in the paired live test.
|
|
59
|
+
|
|
60
|
+
### Final 64-workload benchmark
|
|
61
|
+
|
|
62
|
+
| Metric | Result |
|
|
63
|
+
|---|---:|
|
|
64
|
+
| Total workloads | 64 |
|
|
65
|
+
| Optimized | 40 |
|
|
66
|
+
| Deliberately bypassed | 24 |
|
|
67
|
+
| Eligible-workload estimated saving | **28.53%** |
|
|
68
|
+
| Overall corpus estimated saving | **10.61%** |
|
|
69
|
+
| Protected-byte fidelity | **100%** |
|
|
70
|
+
| Recovery-reference resolution | **100%** |
|
|
71
|
+
|
|
72
|
+
High-risk structured decision contexts are deliberately bypassed. These are estimated input-token results for the offline corpus, not a universal quality or billed-cost claim.
|
|
73
|
+
|
|
74
|
+
## How it works
|
|
75
|
+
|
|
76
|
+
```mermaid
|
|
77
|
+
flowchart LR
|
|
78
|
+
A[Codex / OpenAI-compatible client] --> B[TOKEN local gateway]
|
|
79
|
+
B --> C{Safe to optimize?}
|
|
80
|
+
C -- No --> D[Exact passthrough]
|
|
81
|
+
C -- Yes --> E[Deterministic reducers]
|
|
82
|
+
E --> F[Private reversible recovery]
|
|
83
|
+
D --> G[Existing upstream / router]
|
|
84
|
+
F --> G
|
|
85
|
+
G --> H[Same provider and model]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
TOKEN does not choose a cheaper model or silently reroute providers. The optimization boundary is the request context itself.
|
|
89
|
+
|
|
90
|
+
The V1 planner protects the active turn, protocol state, hard constraints, exact-edit material, current evidence, and decision-sensitive content. Eligible historical context can use exact duplicate removal, repeated-line collapse, recency-preserving deduplication, JSON-aware handling, and conservative tool-output reduction.
|
|
91
|
+
|
|
92
|
+
## Quickstart
|
|
93
|
+
|
|
94
|
+
Python 3.12+ is required.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python3 -m pip install . --no-build-isolation
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Preview integration changes first:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
token install --upstream http://127.0.0.1:20128 --root "$HOME" --dry-run
|
|
104
|
+
```
|
|
105
|
+
Apply and run:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
token install --upstream http://127.0.0.1:20128 --root "$HOME"
|
|
109
|
+
token serve
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Verify the path:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
token doctor
|
|
116
|
+
token status
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Rollback preview and uninstall:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
token uninstall --root "$HOME" --dry-run
|
|
123
|
+
token uninstall --root "$HOME"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
For Codex, TOKEN transactionally manages only the selected OpenAI-compatible provider `base_url`. Ambiguous provider selection or post-install config drift is refused instead of overwritten.
|
|
127
|
+
|
|
128
|
+
## Safety-first by design
|
|
129
|
+
|
|
130
|
+
| Context class | TOKEN behavior |
|
|
131
|
+
|---|---|
|
|
132
|
+
| Active/latest turn | Byte-protected |
|
|
133
|
+
| System/developer + protocol state | Protected |
|
|
134
|
+
| Hard constraints / exact-edit material | Protected or bypassed |
|
|
135
|
+
| Structured JSON + decision-bearing context | **Exact passthrough** |
|
|
136
|
+
| Unsupported/multimodal wire shapes | **Exact passthrough** |
|
|
137
|
+
| Eligible historical redundancy | Deterministic optimization |
|
|
138
|
+
| Internal parse/planner/reducer failure | Original request fallback |
|
|
139
|
+
|
|
140
|
+
## Compatibility
|
|
141
|
+
|
|
142
|
+
| Integration | Alpha status |
|
|
143
|
+
|---|---|
|
|
144
|
+
| OpenAI Responses API, text payloads | ✅ Supported |
|
|
145
|
+
| OpenAI Chat Completions, text payloads | ✅ Supported |
|
|
146
|
+
| Codex with OpenAI-compatible provider config | ✅ Transactional integration verified |
|
|
147
|
+
| Codex CLI 0.154.0 Responses boundary | ✅ `CERTIFIED` at the observed request/response boundary |
|
|
148
|
+
| Generic apps honoring `OPENAI_BASE_URL` | ✅ Supported |
|
|
149
|
+
| Local OpenAI-compatible gateways/routers | ✅ Supported |
|
|
150
|
+
| Anthropic Messages adapter/conformance | 🛡️ `PASSTHROUGH_ONLY`; offline conformance, not production gateway-wired |
|
|
151
|
+
| Gemini GenerateContent adapter/conformance | 🛡️ `PASSTHROUGH_ONLY`; offline conformance, not production gateway-wired |
|
|
152
|
+
| Multimodal optimization | 🛡️ `PASSTHROUGH_ONLY` |
|
|
153
|
+
|
|
154
|
+
`CERTIFIED` is always version- and boundary-specific. Canonical source can also contain adapters that are not deployed in the active gateway. See the [compatibility matrix](docs/COMPATIBILITY.md) for the exact evidence boundary.
|
|
155
|
+
|
|
156
|
+
## Operations
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
token doctor # config, state, gateway and upstream health
|
|
160
|
+
token status # local numeric optimization metrics
|
|
161
|
+
token benchmark # run the production planner/engine on a corpus
|
|
162
|
+
token optimize # inspect one request through the optimizer
|
|
163
|
+
token uninstall # remove TOKEN-managed integration state
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Telemetry uses an allowlist. Prompt bodies, authorization headers, API keys, and arbitrary request content are not persisted as metrics.
|
|
167
|
+
|
|
168
|
+
## Benchmarking
|
|
169
|
+
|
|
170
|
+
`token benchmark` uses the same planner and optimization engine as the gateway. Benchmark inputs expose context fields only; hidden grading labels are not given to the optimizer.
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
token benchmark --file cases.json
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Stable baseline
|
|
177
|
+
|
|
178
|
+
The first verified alpha baseline is locked separately from ongoing development:
|
|
179
|
+
|
|
180
|
+
- Canonical stable tag: `TOKEN-V1-ALPHA-STABLE-20260909`
|
|
181
|
+
- Canonical stable branch: `stable/token-v1-alpha-20260909`
|
|
182
|
+
- Baseline commit: `e45a09859ec3df8c7bb15589bdc096e680884175`
|
|
183
|
+
|
|
184
|
+
Canonical development continues in the private source; stable refs are not advanced with normal feature work.
|
|
185
|
+
|
|
186
|
+
## Alpha boundaries
|
|
187
|
+
|
|
188
|
+
TOKEN currently **does not claim**:
|
|
189
|
+
|
|
190
|
+
- zero quality regression for every workload;
|
|
191
|
+
- a universal percentage reduction for all requests;
|
|
192
|
+
- actual currency savings from provider billing;
|
|
193
|
+
- broad provider-cache non-regression;
|
|
194
|
+
- production native Anthropic or Gemini gateway routing;
|
|
195
|
+
- multimodal context optimization.
|
|
196
|
+
|
|
197
|
+
The approved 24-call live campaign found a real regression class. The final policy responds by bypassing that class unchanged rather than attempting more aggressive compression.
|
|
198
|
+
|
|
199
|
+
## Documentation
|
|
200
|
+
|
|
201
|
+
- [Security and privacy contract](SECURITY.md)
|
|
202
|
+
- [Claims registry](docs/CLAIMS.md)
|
|
203
|
+
- [Compatibility matrix](docs/COMPATIBILITY.md)
|
|
204
|
+
- [Threat model](docs/THREAT-MODEL.md)
|
|
205
|
+
- [Release process](docs/RELEASE-PROCESS.md)
|
|
206
|
+
- [GitHub governance](docs/GITHUB-GOVERNANCE.md)
|
|
207
|
+
- [Public benchmark](benchmarks/README.md)
|
|
208
|
+
- [v0.1.0-alpha.2 release notes](docs/releases/v0.1.0-alpha.2.md)
|
|
209
|
+
- [Apache-2.0 license](LICENSE)
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
**Design principle:** optimize the context only when doing so is safer than leaving it alone.
|