tzero-mcp 10.7.3 → 11.0.0
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.
- package/CHANGELOG.md +44 -577
- package/CONTRIBUTING.md +71 -71
- package/README.md +64 -64
- package/bin/tzero-mcp.js +62 -65
- package/bin/tzero.js +61 -64
- package/index.d.ts +25 -25
- package/index.js +15 -15
- package/package.json +88 -67
- package/src/addmcp.py +14 -11
- package/src/app.py +1810 -0
- package/src/main.py +1 -1
- package/src/pc_fixer_mcp.py +25 -0
- package/src/tzero/__init__.py +54 -0
- package/src/tzero/__main__.py +6 -0
- package/src/tzero/siber_akademi.ico +0 -0
- package/src/tzero/tzero_arch_test.py +463 -0
- package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +475 -475
- package/src/tzero/tzero_blackboard.py +257 -0
- package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +546 -362
- package/src/tzero/tzero_budget.py +195 -0
- package/src/{tzero_ci.py → tzero/tzero_ci.py} +153 -153
- package/src/{tzero_commit.py → tzero/tzero_commit.py} +192 -192
- package/src/tzero/tzero_contracts.py +1093 -0
- package/src/{tzero_cost.py → tzero/tzero_cost.py} +166 -163
- package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +531 -19
- package/src/tzero/tzero_debt.py +461 -0
- package/src/{tzero_deps.py → tzero/tzero_deps.py} +179 -4
- package/src/{tzero_drift.py → tzero/tzero_drift.py} +208 -208
- package/src/{tzero_explain.py → tzero/tzero_explain.py} +73 -7
- package/src/{tzero_features.py → tzero/tzero_features.py} +19 -17
- package/src/tzero/tzero_federation.py +299 -0
- package/src/{tzero_fix.py → tzero/tzero_fix.py} +228 -228
- package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +63 -63
- package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +464 -464
- package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +288 -288
- package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +127 -127
- package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +600 -600
- package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +174 -174
- package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +246 -246
- package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +151 -151
- package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +260 -260
- package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +171 -171
- package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +150 -150
- package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +309 -309
- package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +412 -412
- package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +91 -91
- package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +295 -295
- package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +940 -940
- package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +307 -307
- package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +49 -7
- package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +502 -502
- package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +600 -599
- package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +274 -274
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +313 -313
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +318 -318
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +372 -372
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +305 -305
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +444 -444
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +114 -114
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +110 -110
- package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +326 -326
- package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +223 -223
- package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +220 -220
- package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +1 -1
- package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +447 -447
- package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +309 -309
- package/src/tzero/tzero_golden.py +319 -0
- package/src/tzero/tzero_graph_hud.html +338 -0
- package/src/tzero/tzero_graph_rag.py +263 -0
- package/src/{tzero_guard.py → tzero/tzero_guard.py} +243 -243
- package/src/tzero/tzero_hooks.py +565 -0
- package/src/{tzero_infra.py → tzero/tzero_infra.py} +274 -274
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +124 -124
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +310 -310
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +395 -395
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +214 -214
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +137 -137
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +212 -212
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +184 -184
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +335 -335
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +308 -308
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +887 -887
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +261 -261
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +144 -144
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +1167 -1167
- package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +173 -173
- package/src/tzero/tzero_lsp.py +634 -0
- package/src/{tzero_mcp.py → tzero/tzero_mcp.py} +479 -100
- package/src/tzero/tzero_mutation.py +358 -0
- package/src/tzero/tzero_packer.py +577 -0
- package/src/{tzero_patch.py → tzero/tzero_patch.py} +624 -624
- package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +12699 -12657
- package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +95 -95
- package/src/tzero/tzero_polyglot.py +799 -0
- package/src/tzero/tzero_proxy.py +127 -0
- package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +272 -272
- package/src/{tzero_replay.py → tzero/tzero_replay.py} +141 -141
- package/src/tzero/tzero_rust_bridge.py +198 -0
- package/src/tzero/tzero_scip.py +368 -0
- package/src/{tzero_security.py → tzero/tzero_security.py} +5 -2
- package/src/tzero/tzero_semantic_merge.py +189 -0
- package/src/tzero/tzero_snapshot.py +471 -0
- package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +313 -313
- package/src/tzero/tzero_subagent_engine.py +459 -0
- package/src/{tzero_superdesign.py → tzero/tzero_superdesign.py} +774 -774
- package/src/{tzero_sync.py → tzero/tzero_sync.py} +241 -241
- package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +458 -363
- package/src/{tzero_tui.py → tzero/tzero_tui.py} +91 -22
- package/src/tzero/tzero_turbo.py +264 -0
- package/src/{tzero_v3.py → tzero/tzero_v3.py} +628 -163
- package/src/tzero.py +2 -54
- package/test/package.test.js +55 -19
- package/src/tzero/jarvis/semantic_compressor.py +0 -373
- package/src/tzero_gateway.py +0 -885
- package/src/tzero_packer.py +0 -370
- package/src/tzero_polyglot.py +0 -422
- package/src/tzero_snapshot.py +0 -258
- /package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +0 -0
- /package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +0 -0
- /package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +0 -0
|
@@ -1,363 +1,458 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
T-Zero Task-Completion & Real Tokenizer Benchmark Engine
|
|
4
|
-
=========================================================
|
|
5
|
-
Empirically benchmarks token reduction and task-completion correctness
|
|
6
|
-
comparing Raw Codebase Ingestion against T-Zero Tier-2 Smart Skeletons.
|
|
7
|
-
Uses official BPE tokenizer (tiktoken cl100k_base / o200k_base) for exact token counts.
|
|
8
|
-
|
|
9
|
-
Author: Siber Akademi (Toprak Ahmet Aydoğmuş)
|
|
10
|
-
License: MIT
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
import ast
|
|
14
|
-
import json
|
|
15
|
-
import os
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
tiktoken
|
|
26
|
-
TIKTOKEN_AVAILABLE =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
self.
|
|
88
|
-
self.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
"""
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if
|
|
239
|
-
|
|
240
|
-
new_body
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
new_body
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
T-Zero Task-Completion & Real Tokenizer Benchmark Engine
|
|
4
|
+
=========================================================
|
|
5
|
+
Empirically benchmarks token reduction and task-completion correctness
|
|
6
|
+
comparing Raw Codebase Ingestion against T-Zero Tier-2 Smart Skeletons.
|
|
7
|
+
Uses official BPE tokenizer (tiktoken cl100k_base / o200k_base) for exact token counts.
|
|
8
|
+
|
|
9
|
+
Author: Siber Akademi (Toprak Ahmet Aydoğmuş)
|
|
10
|
+
License: MIT
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import ast
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import sys
|
|
18
|
+
import time
|
|
19
|
+
import urllib.error
|
|
20
|
+
import urllib.request
|
|
21
|
+
from dataclasses import dataclass, field, asdict
|
|
22
|
+
from typing import Dict, List, Any, Optional
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
import tiktoken
|
|
26
|
+
TIKTOKEN_AVAILABLE = True
|
|
27
|
+
except ImportError:
|
|
28
|
+
tiktoken = None
|
|
29
|
+
TIKTOKEN_AVAILABLE = False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def count_bpe_tokens(text: str, model_encoding: str = "cl100k_base") -> int:
|
|
33
|
+
"""Calculates exact BPE tokens using tiktoken if available, else standard char/4 fallback."""
|
|
34
|
+
if TIKTOKEN_AVAILABLE and tiktoken is not None:
|
|
35
|
+
try:
|
|
36
|
+
enc = tiktoken.get_encoding(model_encoding)
|
|
37
|
+
return len(enc.encode(text, disallowed_special=()))
|
|
38
|
+
except Exception:
|
|
39
|
+
pass
|
|
40
|
+
return max(1, len(text) // 4)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass
|
|
44
|
+
class TaskEvaluationResult:
|
|
45
|
+
task_id: str
|
|
46
|
+
task_title: str
|
|
47
|
+
raw_bpe_tokens: int
|
|
48
|
+
tzero_bpe_tokens: int
|
|
49
|
+
token_savings_pct: float
|
|
50
|
+
signature_contract_retention_pct: float
|
|
51
|
+
syntax_valid: bool
|
|
52
|
+
hallucination_count: int
|
|
53
|
+
task_success: bool
|
|
54
|
+
latency_ms: float
|
|
55
|
+
description: str
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class TaskBenchmarkReport:
|
|
60
|
+
version: str = "11.0.0"
|
|
61
|
+
tokenizer: str = "tiktoken (cl100k_base)" if TIKTOKEN_AVAILABLE else "character-ratio fallback"
|
|
62
|
+
total_tasks: int = 0
|
|
63
|
+
passed_tasks: int = 0
|
|
64
|
+
success_rate_pct: float = 0.0
|
|
65
|
+
average_token_reduction_pct: float = 0.0
|
|
66
|
+
total_raw_tokens: int = 0
|
|
67
|
+
total_tzero_tokens: int = 0
|
|
68
|
+
results: List[TaskEvaluationResult] = field(default_factory=list)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class TaskCompletionBenchmark:
|
|
72
|
+
"""
|
|
73
|
+
Evaluates whether an AI coding agent with signature-only surrounding context
|
|
74
|
+
(T-Zero Tier-2 Smart Skeleton) can successfully synthesize correct, valid,
|
|
75
|
+
and non-hallucinated code compared to raw full-file context ingestion.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
TASKS = [
|
|
79
|
+
{
|
|
80
|
+
"id": "TASK-01",
|
|
81
|
+
"title": "Cross-Module Token Bucket Rate Limiter",
|
|
82
|
+
"description": "Implement rate limiting middleware calling RedisSessionStore, MetricsCollector, and AuditLogger.",
|
|
83
|
+
"dependency_code": '''
|
|
84
|
+
class RedisSessionStore:
|
|
85
|
+
"""Handles high-throughput distributed session state."""
|
|
86
|
+
def __init__(self, cluster_url: str, pool_size: int = 20, timeout_ms: int = 500):
|
|
87
|
+
self.cluster_url = cluster_url
|
|
88
|
+
self.pool_size = pool_size
|
|
89
|
+
self.timeout_ms = timeout_ms
|
|
90
|
+
self._connected = True
|
|
91
|
+
self._cache = {}
|
|
92
|
+
|
|
93
|
+
def get_token_quota(self, client_id: str) -> int:
|
|
94
|
+
"""Retrieves remaining token quota for client."""
|
|
95
|
+
# Simulated complex implementation (50 lines)
|
|
96
|
+
val = self._cache.get(client_id, 1000)
|
|
97
|
+
for i in range(10):
|
|
98
|
+
val = max(0, val - 1)
|
|
99
|
+
return val
|
|
100
|
+
|
|
101
|
+
def decrement_quota(self, client_id: str, tokens: int = 1) -> bool:
|
|
102
|
+
"""Atomically decrements quota by specified tokens."""
|
|
103
|
+
curr = self.get_token_quota(client_id)
|
|
104
|
+
if curr >= tokens:
|
|
105
|
+
self._cache[client_id] = curr - tokens
|
|
106
|
+
return True
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
class MetricsCollector:
|
|
110
|
+
"""Emits OpenTelemetry compliant counters and histograms."""
|
|
111
|
+
def record_latency(self, metric_name: str, duration_ms: float, tags: dict = None) -> None:
|
|
112
|
+
"""Records latency in milliseconds."""
|
|
113
|
+
pass
|
|
114
|
+
|
|
115
|
+
def increment_counter(self, counter_name: str, value: int = 1, labels: dict = None) -> None:
|
|
116
|
+
"""Increments dimensional metric counter."""
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
class AuditLogger:
|
|
120
|
+
"""Enterprise zero-leak audit logging engine."""
|
|
121
|
+
def log_security_event(self, event_type: str, actor_id: str, severity: str = "INFO") -> None:
|
|
122
|
+
"""Appends tamper-evident security record."""
|
|
123
|
+
pass
|
|
124
|
+
''',
|
|
125
|
+
"focus_prompt": "Synthesize a client rate-limiter function using RedisSessionStore, MetricsCollector, and AuditLogger.",
|
|
126
|
+
"target_implementation": '''
|
|
127
|
+
def enforce_rate_limit(client_id: str, store: RedisSessionStore, metrics: MetricsCollector, audit: AuditLogger) -> bool:
|
|
128
|
+
"""Validates and decrements token quota while recording audit events."""
|
|
129
|
+
quota = store.get_token_quota(client_id)
|
|
130
|
+
if quota <= 0:
|
|
131
|
+
audit.log_security_event("RATE_LIMIT_EXCEEDED", client_id, severity="WARNING")
|
|
132
|
+
metrics.increment_counter("rate_limit_blocks", 1, {"client": client_id})
|
|
133
|
+
return False
|
|
134
|
+
store.decrement_quota(client_id, 1)
|
|
135
|
+
metrics.increment_counter("rate_limit_allows", 1, {"client": client_id})
|
|
136
|
+
return True
|
|
137
|
+
'''
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"id": "TASK-02",
|
|
141
|
+
"title": "Crypto Vault Key Rotation & Signature Verification",
|
|
142
|
+
"description": "Rotate encryption keys and sign payloads using KeyringVault and HMACEngine.",
|
|
143
|
+
"dependency_code": '''
|
|
144
|
+
class KeyringVault:
|
|
145
|
+
"""Interfaces with platform credential manager."""
|
|
146
|
+
def __init__(self, service_name: str = "tzero_vault"):
|
|
147
|
+
self.service_name = service_name
|
|
148
|
+
self._keys = {}
|
|
149
|
+
|
|
150
|
+
def get_active_signing_key(self, key_id: str) -> bytes:
|
|
151
|
+
"""Retrieves cryptographically secure key material."""
|
|
152
|
+
return b"sec_master_key_990_deterministic_bytes_fixed"
|
|
153
|
+
|
|
154
|
+
def rotate_key(self, key_id: str, new_material: bytes) -> bool:
|
|
155
|
+
"""Rotates key material atomically."""
|
|
156
|
+
self._keys[key_id] = new_material
|
|
157
|
+
return True
|
|
158
|
+
|
|
159
|
+
class HMACEngine:
|
|
160
|
+
"""Deterministic HMAC-SHA256 signature generator."""
|
|
161
|
+
def generate_digest(self, secret_key: bytes, payload: bytes) -> str:
|
|
162
|
+
"""Computes hexadecimal digest."""
|
|
163
|
+
import hashlib, hmac
|
|
164
|
+
return hmac.new(secret_key, payload, hashlib.sha256).hexdigest()
|
|
165
|
+
|
|
166
|
+
def verify_digest(self, secret_key: bytes, payload: bytes, expected_digest: str) -> bool:
|
|
167
|
+
"""Constant-time verification of digest."""
|
|
168
|
+
computed = self.generate_digest(secret_key, payload)
|
|
169
|
+
import hmac
|
|
170
|
+
return hmac.compare_digest(computed, expected_digest)
|
|
171
|
+
''',
|
|
172
|
+
"focus_prompt": "Implement sign_and_record_payload function using KeyringVault and HMACEngine.",
|
|
173
|
+
"target_implementation": '''
|
|
174
|
+
def sign_and_record_payload(payload_bytes: bytes, key_id: str, vault: KeyringVault, hmac_eng: HMACEngine) -> str:
|
|
175
|
+
"""Signs payload using active key from vault."""
|
|
176
|
+
signing_key = vault.get_active_signing_key(key_id)
|
|
177
|
+
digest = hmac_eng.generate_digest(signing_key, payload_bytes)
|
|
178
|
+
return digest
|
|
179
|
+
'''
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"id": "TASK-03",
|
|
183
|
+
"title": "AST Slicer & Blast Radius Impact Assessment",
|
|
184
|
+
"description": "Calculate downstream dependent blast radius using CallGraphDAG and SymbolTable.",
|
|
185
|
+
"dependency_code": '''
|
|
186
|
+
class SymbolTable:
|
|
187
|
+
"""Maintains indexed AST symbol hierarchy."""
|
|
188
|
+
def __init__(self):
|
|
189
|
+
self.symbols = {}
|
|
190
|
+
|
|
191
|
+
def lookup_symbol(self, symbol_path: str) -> Optional[dict]:
|
|
192
|
+
"""Resolves symbol metadata by qualified name."""
|
|
193
|
+
return self.symbols.get(symbol_path)
|
|
194
|
+
|
|
195
|
+
def register_symbol(self, symbol_path: str, meta: dict) -> None:
|
|
196
|
+
"""Registers a symbol in the table."""
|
|
197
|
+
self.symbols[symbol_path] = meta
|
|
198
|
+
|
|
199
|
+
class CallGraphDAG:
|
|
200
|
+
"""Directed acyclic graph tracking caller-callee relationships."""
|
|
201
|
+
def get_downstream_dependents(self, symbol_path: str) -> List[str]:
|
|
202
|
+
"""Returns direct and transitive caller symbol paths."""
|
|
203
|
+
return ["app.api.routes", "app.workers.indexer"]
|
|
204
|
+
|
|
205
|
+
def compute_blast_radius_score(self, dependents: List[str]) -> float:
|
|
206
|
+
"""Calculates bounded 0-100 blast radius impact."""
|
|
207
|
+
return min(100.0, len(dependents) * 18.5)
|
|
208
|
+
''',
|
|
209
|
+
"focus_prompt": "Implement analyze_symbol_impact function using SymbolTable and CallGraphDAG.",
|
|
210
|
+
"target_implementation": '''
|
|
211
|
+
def analyze_symbol_impact(symbol_path: str, table: SymbolTable, dag: CallGraphDAG) -> dict:
|
|
212
|
+
"""Calculates blast radius impact for modified symbol."""
|
|
213
|
+
sym = table.lookup_symbol(symbol_path)
|
|
214
|
+
dependents = dag.get_downstream_dependents(symbol_path)
|
|
215
|
+
score = dag.compute_blast_radius_score(dependents)
|
|
216
|
+
return {
|
|
217
|
+
"symbol": symbol_path,
|
|
218
|
+
"exists": sym is not None,
|
|
219
|
+
"dependents_count": len(dependents),
|
|
220
|
+
"blast_radius_score": score,
|
|
221
|
+
"safe_to_patch": score < 40.0
|
|
222
|
+
}
|
|
223
|
+
'''
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
@classmethod
|
|
228
|
+
def prune_to_ast_skeleton(cls, python_code: str) -> str:
|
|
229
|
+
"""Prunes function/method bodies to docstrings & ellipsis, preserving full signatures & types."""
|
|
230
|
+
try:
|
|
231
|
+
tree = ast.parse(python_code)
|
|
232
|
+
except SyntaxError:
|
|
233
|
+
return python_code
|
|
234
|
+
|
|
235
|
+
class SkeletonPruner(ast.NodeTransformer):
|
|
236
|
+
def visit_FunctionDef(self, node):
|
|
237
|
+
self.generic_visit(node)
|
|
238
|
+
# Keep docstring if present
|
|
239
|
+
doc = ast.get_docstring(node)
|
|
240
|
+
new_body = []
|
|
241
|
+
if doc:
|
|
242
|
+
new_body.append(ast.Expr(value=ast.Constant(value=doc)))
|
|
243
|
+
new_body.append(ast.Expr(value=ast.Constant(value=Ellipsis)))
|
|
244
|
+
node.body = new_body
|
|
245
|
+
return node
|
|
246
|
+
|
|
247
|
+
def visit_AsyncFunctionDef(self, node):
|
|
248
|
+
self.generic_visit(node)
|
|
249
|
+
doc = ast.get_docstring(node)
|
|
250
|
+
new_body = []
|
|
251
|
+
if doc:
|
|
252
|
+
new_body.append(ast.Expr(value=ast.Constant(value=doc)))
|
|
253
|
+
new_body.append(ast.Expr(value=ast.Constant(value=Ellipsis)))
|
|
254
|
+
node.body = new_body
|
|
255
|
+
return node
|
|
256
|
+
|
|
257
|
+
pruned = SkeletonPruner().visit(tree)
|
|
258
|
+
ast.fix_missing_locations(pruned)
|
|
259
|
+
return ast.unparse(pruned)
|
|
260
|
+
|
|
261
|
+
@classmethod
|
|
262
|
+
def evaluate_all(cls) -> TaskBenchmarkReport:
|
|
263
|
+
"""Executes standard 3-task offline benchmark evaluation."""
|
|
264
|
+
return cls.evaluate_suite(suite="core")
|
|
265
|
+
|
|
266
|
+
@classmethod
|
|
267
|
+
def _build_adversarial_tasks(cls) -> List[Dict[str, str]]:
|
|
268
|
+
"""Synthesizes 8 multi-file cross-domain verification tasks for adversarial accuracy audits."""
|
|
269
|
+
specs = [
|
|
270
|
+
("ADV-01", "Order Settlement Contract", "OrderLedger", "settle_invoice", "tx_id: str, cents: int", "bool"),
|
|
271
|
+
("ADV-02", "Zero-Leak Token Masker", "SecretVault", "redact_payload", "raw_text: str", "str"),
|
|
272
|
+
("ADV-03", "AST Dependency Graph", "ImportResolver", "topological_order", "nodes: list", "list"),
|
|
273
|
+
("ADV-04", "Budget Allocator Pack", "WindowPacker", "allocate_tiers", "limit: int, items: list", "dict"),
|
|
274
|
+
("ADV-05", "Merkle Chunk Signer", "ChunkVerifier", "compute_root", "hashes: list", "str"),
|
|
275
|
+
("ADV-06", "Polyglot Signature Extractor", "SyntaxScanner", "extract_headers", "source: str, ext: str", "str"),
|
|
276
|
+
("ADV-07", "Mutation Killer Evaluator", "MutantHarness", "evaluate_mutant", "module_path: str", "float"),
|
|
277
|
+
("ADV-08", "Semantic Merge Healer", "ConflictResolver", "reconcile_hunk", "left: str, right: str", "str"),
|
|
278
|
+
]
|
|
279
|
+
tasks: List[Dict[str, str]] = []
|
|
280
|
+
for tid, title, cls_name, method_name, sig_args, ret_type in specs:
|
|
281
|
+
body_lines = "\n".join(
|
|
282
|
+
f" step_{i} = len(str({sig_args.split(':')[0].strip()})) + {i * 7}"
|
|
283
|
+
for i in range(18)
|
|
284
|
+
)
|
|
285
|
+
return_value = 'True' if ret_type == 'bool' else ('1.0' if ret_type == 'float' else ('[]' if ret_type == 'list' else ('{}' if ret_type == 'dict' else '"ok"')))
|
|
286
|
+
dep_code = (
|
|
287
|
+
f"class {cls_name}:\n"
|
|
288
|
+
f' """{title} domain contract."""\n'
|
|
289
|
+
f" def __init__(self, strict: bool = True):\n"
|
|
290
|
+
f" self.strict = strict\n\n"
|
|
291
|
+
f" def {method_name}(self, {sig_args}) -> {ret_type}:\n"
|
|
292
|
+
f"{body_lines}\n"
|
|
293
|
+
f" return {return_value}\n"
|
|
294
|
+
)
|
|
295
|
+
call_args = ", ".join(
|
|
296
|
+
'""' if "str" in a else ("[]" if "list" in a else "128")
|
|
297
|
+
for a in sig_args.split(",")
|
|
298
|
+
)
|
|
299
|
+
target_impl = (
|
|
300
|
+
f"def run_{tid.lower().replace('-', '_')}(svc):\n"
|
|
301
|
+
f" return svc.{method_name}({call_args})\n"
|
|
302
|
+
)
|
|
303
|
+
tasks.append({
|
|
304
|
+
"id": tid,
|
|
305
|
+
"title": title,
|
|
306
|
+
"description": f"Verify AST skeleton preserves {cls_name}.{method_name} under adversarial load.",
|
|
307
|
+
"dependency_code": dep_code,
|
|
308
|
+
"target_implementation": target_impl,
|
|
309
|
+
})
|
|
310
|
+
return tasks
|
|
311
|
+
|
|
312
|
+
@staticmethod
|
|
313
|
+
def _query_ollama_implementation(
|
|
314
|
+
pruned_dep: str,
|
|
315
|
+
task_title: str,
|
|
316
|
+
ollama_model: str,
|
|
317
|
+
ollama_url: str,
|
|
318
|
+
) -> str:
|
|
319
|
+
prompt = (
|
|
320
|
+
f"Write ONLY Python code implementing a helper calling this AST contract for '{task_title}':\n"
|
|
321
|
+
f"```python\n{pruned_dep}\n```"
|
|
322
|
+
)
|
|
323
|
+
req = urllib.request.Request(
|
|
324
|
+
ollama_url,
|
|
325
|
+
data=json.dumps({"model": ollama_model, "prompt": prompt, "stream": False}).encode("utf-8"),
|
|
326
|
+
headers={"Content-Type": "application/json"},
|
|
327
|
+
method="POST",
|
|
328
|
+
)
|
|
329
|
+
with urllib.request.urlopen(req, timeout=15) as resp:
|
|
330
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
331
|
+
raw = str(data.get("response") or "")
|
|
332
|
+
fence = re.search(r"```(?:python)?\s*(.*?)```", raw, re.DOTALL)
|
|
333
|
+
return fence.group(1).strip() if fence else raw.strip()
|
|
334
|
+
|
|
335
|
+
@classmethod
|
|
336
|
+
def evaluate_suite(
|
|
337
|
+
cls,
|
|
338
|
+
suite: str = "core",
|
|
339
|
+
ollama_model: Optional[str] = None,
|
|
340
|
+
ollama_url: str = "http://127.0.0.1:11434/api/generate",
|
|
341
|
+
limit_tasks: Optional[int] = None,
|
|
342
|
+
) -> TaskBenchmarkReport:
|
|
343
|
+
"""Executes benchmark evaluation across 'core' (3 tasks) or 'adversarial' (8 tasks), optionally querying Ollama."""
|
|
344
|
+
report = TaskBenchmarkReport()
|
|
345
|
+
total_raw = 0
|
|
346
|
+
total_tzero = 0
|
|
347
|
+
reductions = []
|
|
348
|
+
|
|
349
|
+
task_list = cls._build_adversarial_tasks() if suite == "adversarial" else list(cls.TASKS)
|
|
350
|
+
if limit_tasks is not None:
|
|
351
|
+
task_list = task_list[:limit_tasks]
|
|
352
|
+
|
|
353
|
+
for task in task_list:
|
|
354
|
+
t0 = time.perf_counter()
|
|
355
|
+
dep_code = task["dependency_code"]
|
|
356
|
+
target_impl = task["target_implementation"]
|
|
357
|
+
|
|
358
|
+
raw_context = dep_code + "\n" + target_impl
|
|
359
|
+
raw_tokens = count_bpe_tokens(raw_context)
|
|
360
|
+
|
|
361
|
+
pruned_dep = cls.prune_to_ast_skeleton(dep_code)
|
|
362
|
+
tzero_context = pruned_dep + "\n" + target_impl
|
|
363
|
+
tzero_tokens = count_bpe_tokens(tzero_context)
|
|
364
|
+
|
|
365
|
+
if ollama_model:
|
|
366
|
+
try:
|
|
367
|
+
target_impl = cls._query_ollama_implementation(
|
|
368
|
+
pruned_dep=pruned_dep,
|
|
369
|
+
task_title=task["title"],
|
|
370
|
+
ollama_model=ollama_model,
|
|
371
|
+
ollama_url=ollama_url,
|
|
372
|
+
)
|
|
373
|
+
except (urllib.error.URLError, OSError, ValueError) as exc:
|
|
374
|
+
print(f"[WARN] Ollama benchmark query failed for {task['id']}: {exc}", file=sys.stderr)
|
|
375
|
+
target_impl = ""
|
|
376
|
+
|
|
377
|
+
saved = raw_tokens - tzero_tokens
|
|
378
|
+
savings_pct = (saved / raw_tokens * 100.0) if raw_tokens else 0.0
|
|
379
|
+
|
|
380
|
+
target_ast = None
|
|
381
|
+
syntax_valid = False
|
|
382
|
+
if target_impl.strip():
|
|
383
|
+
try:
|
|
384
|
+
target_ast = ast.parse(target_impl)
|
|
385
|
+
syntax_valid = True
|
|
386
|
+
except SyntaxError:
|
|
387
|
+
syntax_valid = False
|
|
388
|
+
|
|
389
|
+
dep_ast = ast.parse(pruned_dep)
|
|
390
|
+
declared_methods = {
|
|
391
|
+
node.name
|
|
392
|
+
for node in ast.walk(dep_ast)
|
|
393
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
called_methods = set()
|
|
397
|
+
if target_ast is not None:
|
|
398
|
+
for node in ast.walk(target_ast):
|
|
399
|
+
if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
|
|
400
|
+
called_methods.add(node.func.attr)
|
|
401
|
+
|
|
402
|
+
hallucinations = sum(1 for cm in called_methods if cm not in declared_methods)
|
|
403
|
+
retention_pct = 100.0 if not hallucinations else max(0.0, 100.0 - (hallucinations * 25.0))
|
|
404
|
+
task_success = syntax_valid and (hallucinations == 0)
|
|
405
|
+
|
|
406
|
+
latency_ms = (time.perf_counter() - t0) * 1000.0
|
|
407
|
+
|
|
408
|
+
res = TaskEvaluationResult(
|
|
409
|
+
task_id=task["id"],
|
|
410
|
+
task_title=task["title"],
|
|
411
|
+
raw_bpe_tokens=raw_tokens,
|
|
412
|
+
tzero_bpe_tokens=tzero_tokens,
|
|
413
|
+
token_savings_pct=round(savings_pct, 1),
|
|
414
|
+
signature_contract_retention_pct=round(retention_pct, 1),
|
|
415
|
+
syntax_valid=syntax_valid,
|
|
416
|
+
hallucination_count=hallucinations,
|
|
417
|
+
task_success=task_success,
|
|
418
|
+
latency_ms=round(latency_ms, 2),
|
|
419
|
+
description=task["description"],
|
|
420
|
+
)
|
|
421
|
+
report.results.append(res)
|
|
422
|
+
total_raw += raw_tokens
|
|
423
|
+
total_tzero += tzero_tokens
|
|
424
|
+
reductions.append(savings_pct)
|
|
425
|
+
|
|
426
|
+
report.total_tasks = len(task_list)
|
|
427
|
+
report.passed_tasks = sum(1 for r in report.results if r.task_success)
|
|
428
|
+
report.success_rate_pct = round(report.passed_tasks / max(1, report.total_tasks) * 100.0, 1)
|
|
429
|
+
report.average_token_reduction_pct = round(sum(reductions) / max(1, len(reductions)), 1)
|
|
430
|
+
report.total_raw_tokens = total_raw
|
|
431
|
+
report.total_tzero_tokens = total_tzero
|
|
432
|
+
|
|
433
|
+
return report
|
|
434
|
+
|
|
435
|
+
@classmethod
|
|
436
|
+
def format_terminal_summary(cls, report: TaskBenchmarkReport) -> str:
|
|
437
|
+
"""Formats ANSI-styled benchmark summary table."""
|
|
438
|
+
lines = []
|
|
439
|
+
lines.append("=" * 78)
|
|
440
|
+
lines.append(" T-ZERO TASK-COMPLETION & BPE TOKENIZER BENCHMARK REPORT (v11.0.0)")
|
|
441
|
+
lines.append(f" Tokenizer: {report.tokenizer} | Tasks Evaluated: {report.total_tasks}")
|
|
442
|
+
lines.append("=" * 78)
|
|
443
|
+
lines.append(f"{'Task ID':<10} | {'Raw BPE':<8} | {'T-Zero':<8} | {'Saved %':<8} | {'Contract %':<10} | {'Status'}")
|
|
444
|
+
lines.append("-" * 78)
|
|
445
|
+
for r in report.results:
|
|
446
|
+
status = "PASS (0 Halluc)" if r.task_success else "FAIL"
|
|
447
|
+
lines.append(f"{r.task_id:<10} | {r.raw_bpe_tokens:<8} | {r.tzero_bpe_tokens:<8} | {r.token_savings_pct:<7}% | {r.signature_contract_retention_pct:<9}% | {status}")
|
|
448
|
+
lines.append("-" * 78)
|
|
449
|
+
lines.append(f"OVERALL TASK SUCCESS RATE: {report.success_rate_pct}% ({report.passed_tasks}/{report.total_tasks} Tasks Clean)")
|
|
450
|
+
lines.append(f"AVERAGE TOKEN REDUCTION : {report.average_token_reduction_pct}% (BPE Exact Tokens)")
|
|
451
|
+
lines.append(f"TOTAL TOKENS BENCHMARKED: {report.total_raw_tokens} -> {report.total_tzero_tokens} tokens")
|
|
452
|
+
lines.append("=" * 78)
|
|
453
|
+
return "\n".join(lines)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
if __name__ == "__main__":
|
|
457
|
+
rep = TaskCompletionBenchmark.evaluate_all()
|
|
458
|
+
print(TaskCompletionBenchmark.format_terminal_summary(rep))
|