tzero-mcp 10.7.4 → 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.
Files changed (127) hide show
  1. package/CHANGELOG.md +56 -29
  2. package/CONTRIBUTING.md +71 -71
  3. package/README.md +64 -64
  4. package/bin/tzero-mcp.js +62 -66
  5. package/bin/tzero.js +61 -65
  6. package/index.d.ts +25 -25
  7. package/index.js +15 -15
  8. package/package.json +88 -88
  9. package/src/addmcp.py +14 -11
  10. package/src/app.py +1810 -0
  11. package/src/main.py +1 -1
  12. package/src/pc_fixer_mcp.py +25 -0
  13. package/src/tzero/__init__.py +54 -0
  14. package/src/tzero/__main__.py +6 -0
  15. package/src/tzero/siber_akademi.ico +0 -0
  16. package/src/tzero/tzero_arch_test.py +463 -0
  17. package/src/{tzero_benchmark.py → tzero/tzero_benchmark.py} +475 -475
  18. package/src/tzero/tzero_blackboard.py +257 -0
  19. package/src/{tzero_bridge.py → tzero/tzero_bridge.py} +546 -362
  20. package/src/tzero/tzero_budget.py +195 -0
  21. package/src/{tzero_ci.py → tzero/tzero_ci.py} +153 -153
  22. package/src/{tzero_commit.py → tzero/tzero_commit.py} +192 -192
  23. package/src/tzero/tzero_contracts.py +1093 -0
  24. package/src/{tzero_cost.py → tzero/tzero_cost.py} +166 -163
  25. package/src/{tzero_dashboard.py → tzero/tzero_dashboard.py} +531 -19
  26. package/src/tzero/tzero_debt.py +461 -0
  27. package/src/{tzero_deps.py → tzero/tzero_deps.py} +179 -4
  28. package/src/{tzero_drift.py → tzero/tzero_drift.py} +208 -208
  29. package/src/{tzero_explain.py → tzero/tzero_explain.py} +73 -7
  30. package/src/{tzero_features.py → tzero/tzero_features.py} +19 -17
  31. package/src/tzero/tzero_federation.py +299 -0
  32. package/src/{tzero_fix.py → tzero/tzero_fix.py} +228 -228
  33. package/src/{tzero_fixer → tzero/tzero_fixer}/__init__.py +63 -63
  34. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_syntax_healer.py +464 -464
  35. package/src/{tzero_fixer → tzero/tzero_fixer}/ast_type_modernizer.py +288 -288
  36. package/src/{tzero_fixer → tzero/tzero_fixer}/async_io_modernizer.py +127 -127
  37. package/src/{tzero_fixer → tzero/tzero_fixer}/automated_regression_suite.py +600 -600
  38. package/src/{tzero_fixer → tzero/tzero_fixer}/benchmarks_and_diagnostics.py +174 -174
  39. package/src/{tzero_fixer → tzero/tzero_fixer}/ci_cd_self_healing_gate.py +246 -246
  40. package/src/{tzero_fixer → tzero/tzero_fixer}/code_duplicity_and_refactorer.py +151 -151
  41. package/src/{tzero_fixer → tzero/tzero_fixer}/code_smells_healer.py +260 -260
  42. package/src/{tzero_fixer → tzero/tzero_fixer}/cwe_remediator.py +171 -171
  43. package/src/{tzero_fixer → tzero/tzero_fixer}/dead_code_eliminator.py +150 -150
  44. package/src/{tzero_fixer → tzero/tzero_fixer}/dependency_vulnerability_auditor.py +309 -309
  45. package/src/{tzero_fixer → tzero/tzero_fixer}/git_advanced_surgeon.py +1 -1
  46. package/src/{tzero_fixer → tzero/tzero_fixer}/hardware_and_disk_doctor.py +1 -1
  47. package/src/{tzero_fixer → tzero/tzero_fixer}/import_graph_healer.py +412 -412
  48. package/src/{tzero_fixer → tzero/tzero_fixer}/interactive_tui.py +91 -91
  49. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base.py +295 -295
  50. package/src/{tzero_fixer → tzero/tzero_fixer}/knowledge_base_extended.py +940 -940
  51. package/src/{tzero_fixer → tzero/tzero_fixer}/linters_and_static_analyzer.py +307 -307
  52. package/src/{tzero_fixer → tzero/tzero_fixer}/mcp_server.py +49 -7
  53. package/src/{tzero_fixer → tzero/tzero_fixer}/os_doctor.py +502 -502
  54. package/src/{tzero_fixer → tzero/tzero_fixer}/packaging_abi_surgeon.py +1 -1
  55. package/src/{tzero_fixer → tzero/tzero_fixer}/pc_fixer_doctor.py +600 -599
  56. package/src/{tzero_fixer → tzero/tzero_fixer}/performance_and_memory_profiler.py +274 -274
  57. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_ast_parsers.py +313 -313
  58. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_build_healer.py +1 -1
  59. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_config_healer.py +318 -318
  60. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_doctor.py +372 -372
  61. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_linters.py +1 -1
  62. package/src/{tzero_fixer → tzero/tzero_fixer}/polyglot_schema_validator.py +305 -305
  63. package/src/{tzero_fixer → tzero/tzero_fixer}/security_cwe_database.py +444 -444
  64. package/src/{tzero_fixer → tzero/tzero_fixer}/security_deep_rules.py +114 -114
  65. package/src/{tzero_fixer → tzero/tzero_fixer}/security_rules_catalog.py +110 -110
  66. package/src/{tzero_fixer → tzero/tzero_fixer}/security_zero_leak.py +326 -326
  67. package/src/{tzero_fixer → tzero/tzero_fixer}/smart_patch_recommender.py +223 -223
  68. package/src/{tzero_fixer → tzero/tzero_fixer}/synthetic_workspace_generator.py +220 -220
  69. package/src/{tzero_fixer → tzero/tzero_fixer}/system_diagnostics_extended.py +1 -1
  70. package/src/{tzero_fixer → tzero/tzero_fixer}/system_repair_recipes.py +447 -447
  71. package/src/{tzero_fixer → tzero/tzero_fixer}/venv_doctor.py +309 -309
  72. package/src/tzero/tzero_golden.py +319 -0
  73. package/src/tzero/tzero_graph_hud.html +338 -0
  74. package/src/tzero/tzero_graph_rag.py +263 -0
  75. package/src/{tzero_guard.py → tzero/tzero_guard.py} +243 -243
  76. package/src/tzero/tzero_hooks.py +565 -0
  77. package/src/{tzero_infra.py → tzero/tzero_infra.py} +274 -274
  78. package/src/{tzero_jarvis → tzero/tzero_jarvis}/__init__.py +124 -124
  79. package/src/{tzero_jarvis → tzero/tzero_jarvis}/causal_graph.py +310 -310
  80. package/src/{tzero_jarvis → tzero/tzero_jarvis}/graph_visualizer.py +395 -395
  81. package/src/{tzero_jarvis → tzero/tzero_jarvis}/hybrid_search.py +214 -214
  82. package/src/{tzero_jarvis → tzero/tzero_jarvis}/latent_press.py +137 -137
  83. package/src/{tzero_jarvis → tzero/tzero_jarvis}/memory_consolidation.py +212 -212
  84. package/src/{tzero_jarvis → tzero/tzero_jarvis}/minhash_lsh.py +184 -184
  85. package/src/{tzero_jarvis → tzero/tzero_jarvis}/orchestrator.py +335 -335
  86. package/src/{tzero_jarvis → tzero/tzero_jarvis}/self_healing.py +308 -308
  87. package/src/{tzero_jarvis → tzero/tzero_jarvis}/semantic_compressor.py +887 -887
  88. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm.py +261 -261
  89. package/src/{tzero_jarvis → tzero/tzero_jarvis}/swarm_bft.py +144 -144
  90. package/src/{tzero_jarvis → tzero/tzero_jarvis}/workspace_orchestrator.py +1167 -1167
  91. package/src/{tzero_jarvis → tzero/tzero_jarvis}/zero_key_router.py +173 -173
  92. package/src/tzero/tzero_lsp.py +634 -0
  93. package/src/{tzero_mcp.py → tzero/tzero_mcp.py} +479 -100
  94. package/src/tzero/tzero_mutation.py +358 -0
  95. package/src/tzero/tzero_packer.py +577 -0
  96. package/src/{tzero_patch.py → tzero/tzero_patch.py} +624 -624
  97. package/src/{tzero_pc_fixer.py → tzero/tzero_pc_fixer.py} +12699 -12657
  98. package/src/{tzero_pipe.py → tzero/tzero_pipe.py} +95 -95
  99. package/src/tzero/tzero_polyglot.py +799 -0
  100. package/src/tzero/tzero_proxy.py +127 -0
  101. package/src/{tzero_reachability.py → tzero/tzero_reachability.py} +272 -272
  102. package/src/{tzero_replay.py → tzero/tzero_replay.py} +141 -141
  103. package/src/tzero/tzero_rust_bridge.py +198 -0
  104. package/src/tzero/tzero_scip.py +368 -0
  105. package/src/{tzero_security.py → tzero/tzero_security.py} +5 -2
  106. package/src/tzero/tzero_semantic_merge.py +189 -0
  107. package/src/tzero/tzero_snapshot.py +471 -0
  108. package/src/{tzero_stubs.py → tzero/tzero_stubs.py} +313 -313
  109. package/src/tzero/tzero_subagent_engine.py +459 -0
  110. package/src/{tzero_superdesign.py → tzero/tzero_superdesign.py} +774 -774
  111. package/src/{tzero_sync.py → tzero/tzero_sync.py} +241 -241
  112. package/src/{tzero_task_benchmark.py → tzero/tzero_task_benchmark.py} +458 -363
  113. package/src/{tzero_tui.py → tzero/tzero_tui.py} +91 -22
  114. package/src/tzero/tzero_turbo.py +264 -0
  115. package/src/{tzero_v3.py → tzero/tzero_v3.py} +628 -163
  116. package/src/tzero.py +2 -54
  117. package/test/package.test.js +55 -43
  118. package/src/tzero/jarvis/semantic_compressor.py +0 -373
  119. package/src/tzero_gateway.py +0 -885
  120. package/src/tzero_packer.py +0 -370
  121. package/src/tzero_polyglot.py +0 -422
  122. package/src/tzero_snapshot.py +0 -258
  123. /package/src/{siber_akademi_icon.py → tzero/siber_akademi_icon.py} +0 -0
  124. /package/src/{tzero_fixer → tzero/tzero_fixer}/amalgamation.py +0 -0
  125. /package/src/{tzero_fixer → tzero/tzero_fixer}/models.py +0 -0
  126. /package/src/{tzero_fixer → tzero/tzero_fixer}/orchestrator.py +0 -0
  127. /package/src/{tzero_neural_cortex.py → tzero/tzero_neural_cortex.py} +0 -0
@@ -1,163 +1,166 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- Siber Akademi — T-Zero Real-Time Token Cost & Financial ROI Cockpit.
4
- Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
5
- License: MIT
6
-
7
- Calculates exact token footprints, API cost per query, and team financial ROI
8
- comparing raw full-codebase injection against T-Zero AST-pruned context
9
- across Claude 3.5 Sonnet, Claude 3 Opus, GPT-4o, Gemini 1.5 Pro, and DeepSeek V3.
10
- """
11
-
12
- import os
13
- import sys
14
- import json
15
- from dataclasses import dataclass, field
16
- from typing import Dict, List, Any, Optional
17
-
18
- from tzero_packer import TokenBudgetPacker
19
-
20
-
21
- @dataclass
22
- class ModelCostComparison:
23
- model_name: str
24
- price_per_million: float
25
- raw_cost_per_query: float
26
- tzero_cost_per_query: float
27
- savings_per_query: float
28
- savings_pct: float
29
- monthly_team_savings: float # Based on 5,500 queries/month team benchmark
30
-
31
-
32
- @dataclass
33
- class CostReport:
34
- workspace_dir: str
35
- total_files: int
36
- raw_tokens: int
37
- tzero_pruned_tokens: int
38
- tokens_saved: int
39
- reduction_pct: float
40
- comparisons: List[ModelCostComparison] = field(default_factory=list)
41
-
42
-
43
- class TokenCostCalculator:
44
- """Calculates quantitative financial ROI and token savings across LLM models."""
45
-
46
- # Provider pricing per 1,000,000 input tokens (as of late 2026 standard market rates)
47
- MODEL_RATES: Dict[str, float] = {
48
- "Anthropic Claude 3.5 Sonnet": 3.00,
49
- "Anthropic Claude 3 Opus": 15.00,
50
- "OpenAI GPT-4o": 2.50,
51
- "Google Gemini 1.5 Pro": 1.25,
52
- "DeepSeek V3": 0.14
53
- }
54
-
55
- QUERIES_PER_MONTH_BENCHMARK = 5500 # 5 developers x 50 prompts/day x 22 work days
56
-
57
- @classmethod
58
- def calculate_cost(cls, workspace_dir: str = ".") -> CostReport:
59
- """Computes comprehensive cost and token reduction metrics for the workspace."""
60
- abs_root = os.path.abspath(workspace_dir)
61
- entries = TokenBudgetPacker.scan_workspace(abs_root, max_files=200)
62
-
63
- raw_total = sum(e.raw_tokens for e in entries)
64
- # Pruned AST context token volume (averages T-2 / T-3 representations)
65
- pruned_total = sum(e.tier_tokens.get("T-3", max(1, e.raw_tokens // 10)) for e in entries)
66
-
67
- # Fallback safety if empty
68
- if raw_total <= 0:
69
- raw_total = 100000
70
- pruned_total = 8500
71
-
72
- tokens_saved = max(0, raw_total - pruned_total)
73
- reduction_pct = round(((tokens_saved / raw_total) * 100), 1)
74
-
75
- comparisons = []
76
- for model_name, rate in cls.MODEL_RATES.items():
77
- raw_cost = (raw_total / 1_000_000) * rate
78
- tzero_cost = (pruned_total / 1_000_000) * rate
79
- savings = max(0.0, raw_cost - tzero_cost)
80
- pct = round((savings / raw_cost * 100), 1) if raw_cost > 0 else 0.0
81
- monthly_savings = savings * cls.QUERIES_PER_MONTH_BENCHMARK
82
-
83
- comparisons.append(ModelCostComparison(
84
- model_name=model_name,
85
- price_per_million=rate,
86
- raw_cost_per_query=raw_cost,
87
- tzero_cost_per_query=tzero_cost,
88
- savings_per_query=savings,
89
- savings_pct=pct,
90
- monthly_team_savings=monthly_savings
91
- ))
92
-
93
- return CostReport(
94
- workspace_dir=abs_root,
95
- total_files=len(entries),
96
- raw_tokens=raw_total,
97
- tzero_pruned_tokens=pruned_total,
98
- tokens_saved=tokens_saved,
99
- reduction_pct=reduction_pct,
100
- comparisons=comparisons
101
- )
102
-
103
- @classmethod
104
- def render_cli(cls, report: CostReport) -> None:
105
- """Renders rich ANSI terminal cost & ROI cockpit."""
106
- print("\n" + "=" * 80)
107
- print("💰 \033[36mT-ZERO REAL-TIME TOKEN COST & FINANCIAL ROI COCKPIT\033[0m")
108
- print("=" * 80)
109
- print(f"📁 Workspace: \033[33m{report.workspace_dir}\033[0m ({report.total_files} active code files)")
110
- print(f"📦 Raw Context: \033[31m{report.raw_tokens:,} tokens\033[0m / query")
111
- print(f"⚡ T-Zero Pruned: \033[32m{report.tzero_pruned_tokens:,} tokens\033[0m / query")
112
- print(f"🎯 Net Reduction: \033[32m-{report.tokens_saved:,} tokens (-{report.reduction_pct}%)\033[0m")
113
- print("-" * 80)
114
- print(f"{'LLM Model':<30} | {'Raw / Query':<11} | {'T-Zero':<8} | {'Saved %':<7} | {'Monthly ROI':<12}")
115
- print("-" * 80)
116
-
117
- for c in report.comparisons:
118
- raw_str = f"${c.raw_cost_per_query:.3f}"
119
- tz_str = f"${c.tzero_cost_per_query:.3f}"
120
- saved_str = f"-{c.savings_pct}%"
121
- roi_str = f"\033[32m+${c.monthly_team_savings:,.2f}/mo\033[0m"
122
- print(f"{c.model_name:<30} | {raw_str:<11} | {tz_str:<8} | {saved_str:<7} | {roi_str}")
123
-
124
- print("=" * 80)
125
- print("💡 \033[33mBased on standard team benchmark: 5 developers x 50 AI queries/day (5,500 queries/mo).\033[0m")
126
- print("🚀 \033[32m100% Offline AST compression guarantees $0 compute costs on local machine.\033[0m\n")
127
-
128
- @classmethod
129
- def to_json(cls, report: CostReport) -> str:
130
- """Serializes report into JSON."""
131
- return json.dumps({
132
- "workspace_dir": report.workspace_dir,
133
- "total_files": report.total_files,
134
- "raw_tokens": report.raw_tokens,
135
- "tzero_pruned_tokens": report.tzero_pruned_tokens,
136
- "tokens_saved": report.tokens_saved,
137
- "reduction_pct": report.reduction_pct,
138
- "comparisons": [
139
- {
140
- "model": c.model_name,
141
- "price_per_million": c.price_per_million,
142
- "raw_cost_per_query": round(c.raw_cost_per_query, 4),
143
- "tzero_cost_per_query": round(c.tzero_cost_per_query, 4),
144
- "savings_per_query": round(c.savings_per_query, 4),
145
- "savings_pct": c.savings_pct,
146
- "monthly_team_savings_usd": round(c.monthly_team_savings, 2)
147
- }
148
- for c in report.comparisons
149
- ]
150
- }, indent=2)
151
-
152
-
153
- def main():
154
- target = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith("-") else "."
155
- rep = TokenCostCalculator.calculate_cost(target)
156
- if "--json" in sys.argv:
157
- print(TokenCostCalculator.to_json(rep))
158
- else:
159
- TokenCostCalculator.render_cli(rep)
160
-
161
-
162
- if __name__ == "__main__":
163
- main()
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Siber Akademi — T-Zero Real-Time Token Cost & Financial ROI Cockpit.
4
+ Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
5
+ License: MIT
6
+
7
+ Calculates exact token footprints, API cost per query, and team financial ROI
8
+ comparing raw full-codebase injection against T-Zero AST-pruned context
9
+ across Claude 3.5 Sonnet, Claude 3 Opus, GPT-4o, Gemini 1.5 Pro, and DeepSeek V3.
10
+ """
11
+
12
+ import os
13
+ import sys
14
+ import json
15
+ from dataclasses import dataclass, field
16
+ from typing import Dict, List, Any, Optional
17
+
18
+ from tzero.tzero_packer import TokenBudgetPacker
19
+
20
+
21
+ @dataclass
22
+ class ModelCostComparison:
23
+ model_name: str
24
+ price_per_million: float
25
+ raw_cost_per_query: float
26
+ tzero_cost_per_query: float
27
+ savings_per_query: float
28
+ savings_pct: float
29
+ monthly_team_savings: float # Based on 5,500 queries/month team benchmark
30
+
31
+
32
+ @dataclass
33
+ class CostReport:
34
+ workspace_dir: str
35
+ total_files: int
36
+ raw_tokens: int
37
+ tzero_pruned_tokens: int
38
+ tokens_saved: int
39
+ reduction_pct: float
40
+ comparisons: List[ModelCostComparison] = field(default_factory=list)
41
+
42
+
43
+ class TokenCostCalculator:
44
+ """Calculates quantitative financial ROI and token savings across LLM models."""
45
+
46
+ # Provider pricing per 1,000,000 input tokens (as of late 2026 standard market rates)
47
+ MODEL_RATES: Dict[str, float] = {
48
+ "Anthropic Claude 3.7 Sonnet (Thinking)": 3.00,
49
+ "Anthropic Claude 3.5 Sonnet": 3.00,
50
+ "Anthropic Claude 3 Opus": 15.00,
51
+ "OpenAI GPT-4.5 Preview": 75.00,
52
+ "OpenAI GPT-4o": 2.50,
53
+ "Google Gemini 2.5 Pro": 1.25,
54
+ "Google Gemini 1.5 Pro": 1.25,
55
+ "DeepSeek V3": 0.14
56
+ }
57
+
58
+ QUERIES_PER_MONTH_BENCHMARK = 5500 # 5 developers x 50 prompts/day x 22 work days
59
+
60
+ @classmethod
61
+ def calculate_cost(cls, workspace_dir: str = ".") -> CostReport:
62
+ """Computes comprehensive cost and token reduction metrics for the workspace."""
63
+ abs_root = os.path.abspath(workspace_dir)
64
+ entries = TokenBudgetPacker.scan_workspace(abs_root, max_files=200)
65
+
66
+ raw_total = sum(e.raw_tokens for e in entries)
67
+ # Pruned AST context token volume (averages T-2 / T-3 representations)
68
+ pruned_total = sum(e.tier_tokens.get("T-3", max(1, e.raw_tokens // 10)) for e in entries)
69
+
70
+ # Fallback safety if empty
71
+ if raw_total <= 0:
72
+ raw_total = 100000
73
+ pruned_total = 8500
74
+
75
+ tokens_saved = max(0, raw_total - pruned_total)
76
+ reduction_pct = round(((tokens_saved / raw_total) * 100), 1)
77
+
78
+ comparisons = []
79
+ for model_name, rate in cls.MODEL_RATES.items():
80
+ raw_cost = (raw_total / 1_000_000) * rate
81
+ tzero_cost = (pruned_total / 1_000_000) * rate
82
+ savings = max(0.0, raw_cost - tzero_cost)
83
+ pct = round((savings / raw_cost * 100), 1) if raw_cost > 0 else 0.0
84
+ monthly_savings = savings * cls.QUERIES_PER_MONTH_BENCHMARK
85
+
86
+ comparisons.append(ModelCostComparison(
87
+ model_name=model_name,
88
+ price_per_million=rate,
89
+ raw_cost_per_query=raw_cost,
90
+ tzero_cost_per_query=tzero_cost,
91
+ savings_per_query=savings,
92
+ savings_pct=pct,
93
+ monthly_team_savings=monthly_savings
94
+ ))
95
+
96
+ return CostReport(
97
+ workspace_dir=abs_root,
98
+ total_files=len(entries),
99
+ raw_tokens=raw_total,
100
+ tzero_pruned_tokens=pruned_total,
101
+ tokens_saved=tokens_saved,
102
+ reduction_pct=reduction_pct,
103
+ comparisons=comparisons
104
+ )
105
+
106
+ @classmethod
107
+ def render_cli(cls, report: CostReport) -> None:
108
+ """Renders rich ANSI terminal cost & ROI cockpit."""
109
+ print("\n" + "=" * 80)
110
+ print("💰 \033[36mT-ZERO REAL-TIME TOKEN COST & FINANCIAL ROI COCKPIT\033[0m")
111
+ print("=" * 80)
112
+ print(f"📁 Workspace: \033[33m{report.workspace_dir}\033[0m ({report.total_files} active code files)")
113
+ print(f"📦 Raw Context: \033[31m{report.raw_tokens:,} tokens\033[0m / query")
114
+ print(f"⚡ T-Zero Pruned: \033[32m{report.tzero_pruned_tokens:,} tokens\033[0m / query")
115
+ print(f"🎯 Net Reduction: \033[32m-{report.tokens_saved:,} tokens (-{report.reduction_pct}%)\033[0m")
116
+ print("-" * 80)
117
+ print(f"{'LLM Model':<30} | {'Raw / Query':<11} | {'T-Zero':<8} | {'Saved %':<7} | {'Monthly ROI':<12}")
118
+ print("-" * 80)
119
+
120
+ for c in report.comparisons:
121
+ raw_str = f"${c.raw_cost_per_query:.3f}"
122
+ tz_str = f"${c.tzero_cost_per_query:.3f}"
123
+ saved_str = f"-{c.savings_pct}%"
124
+ roi_str = f"\033[32m+${c.monthly_team_savings:,.2f}/mo\033[0m"
125
+ print(f"{c.model_name:<30} | {raw_str:<11} | {tz_str:<8} | {saved_str:<7} | {roi_str}")
126
+
127
+ print("=" * 80)
128
+ print("💡 \033[33mBased on standard team benchmark: 5 developers x 50 AI queries/day (5,500 queries/mo).\033[0m")
129
+ print("🚀 \033[32m100% Offline AST compression guarantees $0 compute costs on local machine.\033[0m\n")
130
+
131
+ @classmethod
132
+ def to_json(cls, report: CostReport) -> str:
133
+ """Serializes report into JSON."""
134
+ return json.dumps({
135
+ "workspace_dir": report.workspace_dir,
136
+ "total_files": report.total_files,
137
+ "raw_tokens": report.raw_tokens,
138
+ "tzero_pruned_tokens": report.tzero_pruned_tokens,
139
+ "tokens_saved": report.tokens_saved,
140
+ "reduction_pct": report.reduction_pct,
141
+ "comparisons": [
142
+ {
143
+ "model": c.model_name,
144
+ "price_per_million": c.price_per_million,
145
+ "raw_cost_per_query": round(c.raw_cost_per_query, 4),
146
+ "tzero_cost_per_query": round(c.tzero_cost_per_query, 4),
147
+ "savings_per_query": round(c.savings_per_query, 4),
148
+ "savings_pct": c.savings_pct,
149
+ "monthly_team_savings_usd": round(c.monthly_team_savings, 2)
150
+ }
151
+ for c in report.comparisons
152
+ ]
153
+ }, indent=2)
154
+
155
+
156
+ def main():
157
+ target = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith("-") else "."
158
+ rep = TokenCostCalculator.calculate_cost(target)
159
+ if "--json" in sys.argv:
160
+ print(TokenCostCalculator.to_json(rep))
161
+ else:
162
+ TokenCostCalculator.render_cli(rep)
163
+
164
+
165
+ if __name__ == "__main__":
166
+ main()