tokenpak 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (666) hide show
  1. tokenpak-1.0.0/LICENSE +21 -0
  2. tokenpak-1.0.0/LICENSE_COMMERCIAL.md +108 -0
  3. tokenpak-1.0.0/PKG-INFO +517 -0
  4. tokenpak-1.0.0/README.md +441 -0
  5. tokenpak-1.0.0/pyproject.toml +146 -0
  6. tokenpak-1.0.0/setup.cfg +4 -0
  7. tokenpak-1.0.0/tests/test_ab_optimizer.py +525 -0
  8. tokenpak-1.0.0/tests/test_adapter_roundtrip.py +62 -0
  9. tokenpak-1.0.0/tests/test_adoption_killers.py +696 -0
  10. tokenpak-1.0.0/tests/test_agent_registry.py +417 -0
  11. tokenpak-1.0.0/tests/test_alias_compressor.py +223 -0
  12. tokenpak-1.0.0/tests/test_artifact_store_schemas.py +514 -0
  13. tokenpak-1.0.0/tests/test_async_proxy_server.py +362 -0
  14. tokenpak-1.0.0/tests/test_attribution.py +188 -0
  15. tokenpak-1.0.0/tests/test_autonomous_broker.py +374 -0
  16. tokenpak-1.0.0/tests/test_baseline_registry_delta_detector.py +383 -0
  17. tokenpak-1.0.0/tests/test_basic.py +69 -0
  18. tokenpak-1.0.0/tests/test_batch2_core_modules.py +458 -0
  19. tokenpak-1.0.0/tests/test_benchmark.py +313 -0
  20. tokenpak-1.0.0/tests/test_budget.py +213 -0
  21. tokenpak-1.0.0/tests/test_budget_controller.py +87 -0
  22. tokenpak-1.0.0/tests/test_budget_intelligence.py +195 -0
  23. tokenpak-1.0.0/tests/test_cache_e2e_determinism.py +514 -0
  24. tokenpak-1.0.0/tests/test_cache_optimizations.py +519 -0
  25. tokenpak-1.0.0/tests/test_cache_telemetry.py +263 -0
  26. tokenpak-1.0.0/tests/test_calibrator.py +347 -0
  27. tokenpak-1.0.0/tests/test_canon_session_fix.py +215 -0
  28. tokenpak-1.0.0/tests/test_capabilities.py +30 -0
  29. tokenpak-1.0.0/tests/test_capsule_builder.py +381 -0
  30. tokenpak-1.0.0/tests/test_capsule_builder_proxy_module.py +133 -0
  31. tokenpak-1.0.0/tests/test_capsule_integration.py +380 -0
  32. tokenpak-1.0.0/tests/test_chunk_shapes.py +354 -0
  33. tokenpak-1.0.0/tests/test_circuit_breaker.py +524 -0
  34. tokenpak-1.0.0/tests/test_citation_tracker.py +236 -0
  35. tokenpak-1.0.0/tests/test_claim_evidence_indexer.py +367 -0
  36. tokenpak-1.0.0/tests/test_claim_indexer.py +336 -0
  37. tokenpak-1.0.0/tests/test_classifier_first_router.py +514 -0
  38. tokenpak-1.0.0/tests/test_cli_proxy_integration.py +463 -0
  39. tokenpak-1.0.0/tests/test_cli_serve_smoke.py +152 -0
  40. tokenpak-1.0.0/tests/test_code_compaction_v2.py +406 -0
  41. tokenpak-1.0.0/tests/test_code_extractor.py +532 -0
  42. tokenpak-1.0.0/tests/test_compaction_modes.py +407 -0
  43. tokenpak-1.0.0/tests/test_compare_leaderboard.py +247 -0
  44. tokenpak-1.0.0/tests/test_compile_report.py +563 -0
  45. tokenpak-1.0.0/tests/test_compression_dictionary.py +229 -0
  46. tokenpak-1.0.0/tests/test_compression_ratio_regression.py +197 -0
  47. tokenpak-1.0.0/tests/test_compression_telemetry.py +323 -0
  48. tokenpak-1.0.0/tests/test_config.py +25 -0
  49. tokenpak-1.0.0/tests/test_connection_pool.py +463 -0
  50. tokenpak-1.0.0/tests/test_context_composer.py +340 -0
  51. tokenpak-1.0.0/tests/test_context_contracts.py +278 -0
  52. tokenpak-1.0.0/tests/test_context_handoff.py +359 -0
  53. tokenpak-1.0.0/tests/test_cooldown_manager.py +575 -0
  54. tokenpak-1.0.0/tests/test_cost_budget_cli.py +492 -0
  55. tokenpak-1.0.0/tests/test_cost_intelligence.py +519 -0
  56. tokenpak-1.0.0/tests/test_cost_tracker.py +162 -0
  57. tokenpak-1.0.0/tests/test_credential_passthrough.py +241 -0
  58. tokenpak-1.0.0/tests/test_cross_doc_normalization.py +470 -0
  59. tokenpak-1.0.0/tests/test_debug_logger.py +26 -0
  60. tokenpak-1.0.0/tests/test_debug_mode.py +187 -0
  61. tokenpak-1.0.0/tests/test_dedup.py +225 -0
  62. tokenpak-1.0.0/tests/test_deterministic_prompt_pack.py +494 -0
  63. tokenpak-1.0.0/tests/test_diff_command.py +219 -0
  64. tokenpak-1.0.0/tests/test_directives.py +503 -0
  65. tokenpak-1.0.0/tests/test_disclosure.py +95 -0
  66. tokenpak-1.0.0/tests/test_doc_extractor.py +590 -0
  67. tokenpak-1.0.0/tests/test_doctor.py +722 -0
  68. tokenpak-1.0.0/tests/test_document_parser.py +544 -0
  69. tokenpak-1.0.0/tests/test_e2e_proxy.py +300 -0
  70. tokenpak-1.0.0/tests/test_e2e_proxy_smoke.py +453 -0
  71. tokenpak-1.0.0/tests/test_enterprise_audit.py +350 -0
  72. tokenpak-1.0.0/tests/test_enterprise_policy_stubs.py +210 -0
  73. tokenpak-1.0.0/tests/test_entity_extraction_pipeline.py +66 -0
  74. tokenpak-1.0.0/tests/test_error_normalizer.py +50 -0
  75. tokenpak-1.0.0/tests/test_escalation.py +133 -0
  76. tokenpak-1.0.0/tests/test_exec_cli.py +86 -0
  77. tokenpak-1.0.0/tests/test_extractors_batch.py +261 -0
  78. tokenpak-1.0.0/tests/test_failover_engine.py +600 -0
  79. tokenpak-1.0.0/tests/test_failover_footer.py +277 -0
  80. tokenpak-1.0.0/tests/test_failover_provider_detection.py +500 -0
  81. tokenpak-1.0.0/tests/test_failover_translators.py +650 -0
  82. tokenpak-1.0.0/tests/test_failure_memory.py +243 -0
  83. tokenpak-1.0.0/tests/test_fidelity_tiers.py +383 -0
  84. tokenpak-1.0.0/tests/test_file_watcher.py +380 -0
  85. tokenpak-1.0.0/tests/test_fingerprint_sync.py +324 -0
  86. tokenpak-1.0.0/tests/test_fleet_command.py +349 -0
  87. tokenpak-1.0.0/tests/test_glossary.py +103 -0
  88. tokenpak-1.0.0/tests/test_goals.py +688 -0
  89. tokenpak-1.0.0/tests/test_graceful_degradation.py +356 -0
  90. tokenpak-1.0.0/tests/test_graceful_shutdown.py +423 -0
  91. tokenpak-1.0.0/tests/test_handoff_protocol.py +287 -0
  92. tokenpak-1.0.0/tests/test_ingest_proxy_v4.py +277 -0
  93. tokenpak-1.0.0/tests/test_integration_edge_calculation.py +233 -0
  94. tokenpak-1.0.0/tests/test_integration_feature_engineering.py +445 -0
  95. tokenpak-1.0.0/tests/test_integration_full_pipeline.py +434 -0
  96. tokenpak-1.0.0/tests/test_integration_probability_calibration.py +255 -0
  97. tokenpak-1.0.0/tests/test_integration_xml_parser.py +144 -0
  98. tokenpak-1.0.0/tests/test_intelligence_deep_health.py +438 -0
  99. tokenpak-1.0.0/tests/test_intelligence_security.py +343 -0
  100. tokenpak-1.0.0/tests/test_intent_classifier.py +358 -0
  101. tokenpak-1.0.0/tests/test_intent_example_selector.py +78 -0
  102. tokenpak-1.0.0/tests/test_intent_policy.py +240 -0
  103. tokenpak-1.0.0/tests/test_intent_state_schemas.py +282 -0
  104. tokenpak-1.0.0/tests/test_learning_store.py +464 -0
  105. tokenpak-1.0.0/tests/test_license_activation_flow.py +488 -0
  106. tokenpak-1.0.0/tests/test_license_admin_cli.py +349 -0
  107. tokenpak-1.0.0/tests/test_license_system.py +353 -0
  108. tokenpak-1.0.0/tests/test_locks.py +155 -0
  109. tokenpak-1.0.0/tests/test_log_extractor.py +532 -0
  110. tokenpak-1.0.0/tests/test_macro_engine.py +456 -0
  111. tokenpak-1.0.0/tests/test_macro_scheduler_hooks.py +285 -0
  112. tokenpak-1.0.0/tests/test_memory_promoter.py +381 -0
  113. tokenpak-1.0.0/tests/test_metrics_reporter.py +374 -0
  114. tokenpak-1.0.0/tests/test_miss_detector.py +381 -0
  115. tokenpak-1.0.0/tests/test_module_toggle_matrix.py +515 -0
  116. tokenpak-1.0.0/tests/test_oauth_routing.py +317 -0
  117. tokenpak-1.0.0/tests/test_obsidian_frontmatter.py +109 -0
  118. tokenpak-1.0.0/tests/test_optimize.py +192 -0
  119. tokenpak-1.0.0/tests/test_oss_recipes.py +293 -0
  120. tokenpak-1.0.0/tests/test_output_formatter.py +51 -0
  121. tokenpak-1.0.0/tests/test_passthrough.py +259 -0
  122. tokenpak-1.0.0/tests/test_phase3_integration.py +592 -0
  123. tokenpak-1.0.0/tests/test_phase5b_query_api.py +813 -0
  124. tokenpak-1.0.0/tests/test_platform_adapters.py +165 -0
  125. tokenpak-1.0.0/tests/test_post_run.py +130 -0
  126. tokenpak-1.0.0/tests/test_precompute.py +406 -0
  127. tokenpak-1.0.0/tests/test_precondition_gates.py +317 -0
  128. tokenpak-1.0.0/tests/test_prefetcher.py +52 -0
  129. tokenpak-1.0.0/tests/test_prefix_registry.py +317 -0
  130. tokenpak-1.0.0/tests/test_premade_macros.py +46 -0
  131. tokenpak-1.0.0/tests/test_preview_command.py +93 -0
  132. tokenpak-1.0.0/tests/test_privacy.py +382 -0
  133. tokenpak-1.0.0/tests/test_prometheus_metrics.py +379 -0
  134. tokenpak-1.0.0/tests/test_prompt_builder.py +178 -0
  135. tokenpak-1.0.0/tests/test_prompt_cache_breakpoints.py +78 -0
  136. tokenpak-1.0.0/tests/test_proxy_adapters.py +356 -0
  137. tokenpak-1.0.0/tests/test_proxy_endpoints.py +622 -0
  138. tokenpak-1.0.0/tests/test_proxy_error_paths.py +453 -0
  139. tokenpak-1.0.0/tests/test_proxy_health.py +280 -0
  140. tokenpak-1.0.0/tests/test_proxy_health_monitoring.py +531 -0
  141. tokenpak-1.0.0/tests/test_proxy_v4_cache_stats.py +54 -0
  142. tokenpak-1.0.0/tests/test_proxy_v4_endpoints.py +637 -0
  143. tokenpak-1.0.0/tests/test_proxy_v4_upstream_routes.py +81 -0
  144. tokenpak-1.0.0/tests/test_proxy_workflow_integration.py +377 -0
  145. tokenpak-1.0.0/tests/test_prune_retain.py +288 -0
  146. tokenpak-1.0.0/tests/test_quality_per_token.py +381 -0
  147. tokenpak-1.0.0/tests/test_query_rewriter.py +310 -0
  148. tokenpak-1.0.0/tests/test_recipe_sdk.py +295 -0
  149. tokenpak-1.0.0/tests/test_recipes_engine.py +409 -0
  150. tokenpak-1.0.0/tests/test_remaining_modules.py +541 -0
  151. tokenpak-1.0.0/tests/test_replay_cli.py +315 -0
  152. tokenpak-1.0.0/tests/test_replay_store.py +230 -0
  153. tokenpak-1.0.0/tests/test_report_alerts.py +509 -0
  154. tokenpak-1.0.0/tests/test_request_audit.py +252 -0
  155. tokenpak-1.0.0/tests/test_request_logging.py +386 -0
  156. tokenpak-1.0.0/tests/test_request_validation.py +594 -0
  157. tokenpak-1.0.0/tests/test_response_validation.py +409 -0
  158. tokenpak-1.0.0/tests/test_retrieval_scoring.py +302 -0
  159. tokenpak-1.0.0/tests/test_retrieval_scoring_coverage.py +325 -0
  160. tokenpak-1.0.0/tests/test_retrieval_watchdog.py +351 -0
  161. tokenpak-1.0.0/tests/test_retry.py +394 -0
  162. tokenpak-1.0.0/tests/test_router_e2e.py +162 -0
  163. tokenpak-1.0.0/tests/test_routing_fallback.py +310 -0
  164. tokenpak-1.0.0/tests/test_routing_rules.py +306 -0
  165. tokenpak-1.0.0/tests/test_runbook_generator.py +277 -0
  166. tokenpak-1.0.0/tests/test_salience_extractors.py +299 -0
  167. tokenpak-1.0.0/tests/test_savings_cmd.py +193 -0
  168. tokenpak-1.0.0/tests/test_schema_converter.py +121 -0
  169. tokenpak-1.0.0/tests/test_schema_extractor.py +335 -0
  170. tokenpak-1.0.0/tests/test_script_hooks.py +41 -0
  171. tokenpak-1.0.0/tests/test_security_hardening.py +326 -0
  172. tokenpak-1.0.0/tests/test_segmentizer_coverage.py +488 -0
  173. tokenpak-1.0.0/tests/test_semantic_cache.py +317 -0
  174. tokenpak-1.0.0/tests/test_semantic_map.py +378 -0
  175. tokenpak-1.0.0/tests/test_semantic_slicing.py +410 -0
  176. tokenpak-1.0.0/tests/test_serve_multiworker.py +332 -0
  177. tokenpak-1.0.0/tests/test_session_capsules.py +84 -0
  178. tokenpak-1.0.0/tests/test_setup_wizard.py +312 -0
  179. tokenpak-1.0.0/tests/test_shadow_mode.py +362 -0
  180. tokenpak-1.0.0/tests/test_shadow_reader.py +366 -0
  181. tokenpak-1.0.0/tests/test_skill_compiler.py +255 -0
  182. tokenpak-1.0.0/tests/test_slot_filler.py +713 -0
  183. tokenpak-1.0.0/tests/test_source_adapters.py +336 -0
  184. tokenpak-1.0.0/tests/test_stability_scorer.py +223 -0
  185. tokenpak-1.0.0/tests/test_stable_cache_wire.py +157 -0
  186. tokenpak-1.0.0/tests/test_stats_api.py +20 -0
  187. tokenpak-1.0.0/tests/test_stats_footer.py +247 -0
  188. tokenpak-1.0.0/tests/test_storage.py +448 -0
  189. tokenpak-1.0.0/tests/test_stream_translator.py +26 -0
  190. tokenpak-1.0.0/tests/test_streaming.py +537 -0
  191. tokenpak-1.0.0/tests/test_table_extractor.py +289 -0
  192. tokenpak-1.0.0/tests/test_teacher_pack_builder.py +55 -0
  193. tokenpak-1.0.0/tests/test_team_features.py +337 -0
  194. tokenpak-1.0.0/tests/test_tier1_integration.py +626 -0
  195. tokenpak-1.0.0/tests/test_tier2_integration.py +786 -0
  196. tokenpak-1.0.0/tests/test_tier_aware_help.py +228 -0
  197. tokenpak-1.0.0/tests/test_tiered_help.py +350 -0
  198. tokenpak-1.0.0/tests/test_timeline_dashboard.py +196 -0
  199. tokenpak-1.0.0/tests/test_tool_orchestration.py +306 -0
  200. tokenpak-1.0.0/tests/test_tool_schema_registry.py +224 -0
  201. tokenpak-1.0.0/tests/test_topic_aware_compaction.py +425 -0
  202. tokenpak-1.0.0/tests/test_trace.py +374 -0
  203. tokenpak-1.0.0/tests/test_trackedge.py +511 -0
  204. tokenpak-1.0.0/tests/test_trackedge_features.py +359 -0
  205. tokenpak-1.0.0/tests/test_trackedge_pace_speed.py +189 -0
  206. tokenpak-1.0.0/tests/test_treesitter.py +861 -0
  207. tokenpak-1.0.0/tests/test_trigger_cli.py +297 -0
  208. tokenpak-1.0.0/tests/test_triggers.py +411 -0
  209. tokenpak-1.0.0/tests/test_triggers_cali.py +153 -0
  210. tokenpak-1.0.0/tests/test_user_templates.py +205 -0
  211. tokenpak-1.0.0/tests/test_validation_framework.py +425 -0
  212. tokenpak-1.0.0/tests/test_validation_gate.py +68 -0
  213. tokenpak-1.0.0/tests/test_vault_indexer_full.py +91 -0
  214. tokenpak-1.0.0/tests/test_vendor_classifier.py +219 -0
  215. tokenpak-1.0.0/tests/test_workflow_budget.py +451 -0
  216. tokenpak-1.0.0/tests/test_workflow_cli.py +301 -0
  217. tokenpak-1.0.0/tests/test_workflow_performance.py +237 -0
  218. tokenpak-1.0.0/tokenpak/__init__.py +171 -0
  219. tokenpak-1.0.0/tokenpak/__main__.py +7 -0
  220. tokenpak-1.0.0/tokenpak/adapters/__init__.py +51 -0
  221. tokenpak-1.0.0/tokenpak/adapters/anthropic.py +258 -0
  222. tokenpak-1.0.0/tokenpak/adapters/base.py +212 -0
  223. tokenpak-1.0.0/tokenpak/adapters/langchain.py +174 -0
  224. tokenpak-1.0.0/tokenpak/adapters/litellm.py +192 -0
  225. tokenpak-1.0.0/tokenpak/adapters/openai.py +251 -0
  226. tokenpak-1.0.0/tokenpak/agent/__init__.py +1 -0
  227. tokenpak-1.0.0/tokenpak/agent/adapters/__init__.py +27 -0
  228. tokenpak-1.0.0/tokenpak/agent/adapters/base.py +59 -0
  229. tokenpak-1.0.0/tokenpak/agent/adapters/claude_cli.py +50 -0
  230. tokenpak-1.0.0/tokenpak/agent/adapters/generic.py +41 -0
  231. tokenpak-1.0.0/tokenpak/agent/adapters/openclaw.py +50 -0
  232. tokenpak-1.0.0/tokenpak/agent/adapters/registry.py +56 -0
  233. tokenpak-1.0.0/tokenpak/agent/agentic/__init__.py +154 -0
  234. tokenpak-1.0.0/tokenpak/agent/agentic/capabilities.py +269 -0
  235. tokenpak-1.0.0/tokenpak/agent/agentic/error_normalizer.py +156 -0
  236. tokenpak-1.0.0/tokenpak/agent/agentic/failure_memory.py +357 -0
  237. tokenpak-1.0.0/tokenpak/agent/agentic/handoff.py +517 -0
  238. tokenpak-1.0.0/tokenpak/agent/agentic/learning.py +894 -0
  239. tokenpak-1.0.0/tokenpak/agent/agentic/locks.py +248 -0
  240. tokenpak-1.0.0/tokenpak/agent/agentic/memory_promoter.py +304 -0
  241. tokenpak-1.0.0/tokenpak/agent/agentic/precondition_gates.py +432 -0
  242. tokenpak-1.0.0/tokenpak/agent/agentic/prefetcher.py +175 -0
  243. tokenpak-1.0.0/tokenpak/agent/agentic/proxy_workflow.py +167 -0
  244. tokenpak-1.0.0/tokenpak/agent/agentic/registry.py +211 -0
  245. tokenpak-1.0.0/tokenpak/agent/agentic/retry.py +528 -0
  246. tokenpak-1.0.0/tokenpak/agent/agentic/runbook_generator.py +446 -0
  247. tokenpak-1.0.0/tokenpak/agent/agentic/skill_compiler.py +360 -0
  248. tokenpak-1.0.0/tokenpak/agent/agentic/state_collector.py +389 -0
  249. tokenpak-1.0.0/tokenpak/agent/agentic/test_workflow_performance.py +360 -0
  250. tokenpak-1.0.0/tokenpak/agent/agentic/validation_framework.py +723 -0
  251. tokenpak-1.0.0/tokenpak/agent/agentic/workflow.py +457 -0
  252. tokenpak-1.0.0/tokenpak/agent/agentic/workflow_budget.py +363 -0
  253. tokenpak-1.0.0/tokenpak/agent/agentic/workflow_performance.py +285 -0
  254. tokenpak-1.0.0/tokenpak/agent/auth/__init__.py +0 -0
  255. tokenpak-1.0.0/tokenpak/agent/auth/cooldown_manager.py +246 -0
  256. tokenpak-1.0.0/tokenpak/agent/auth/oauth_manager.py +368 -0
  257. tokenpak-1.0.0/tokenpak/agent/cli/__init__.py +9 -0
  258. tokenpak-1.0.0/tokenpak/agent/cli/commands/__init__.py +23 -0
  259. tokenpak-1.0.0/tokenpak/agent/cli/commands/budget.py +633 -0
  260. tokenpak-1.0.0/tokenpak/agent/cli/commands/compliance.py +134 -0
  261. tokenpak-1.0.0/tokenpak/agent/cli/commands/compression.py +21 -0
  262. tokenpak-1.0.0/tokenpak/agent/cli/commands/config.py +123 -0
  263. tokenpak-1.0.0/tokenpak/agent/cli/commands/cost.py +403 -0
  264. tokenpak-1.0.0/tokenpak/agent/cli/commands/dashboard.py +412 -0
  265. tokenpak-1.0.0/tokenpak/agent/cli/commands/debug.py +52 -0
  266. tokenpak-1.0.0/tokenpak/agent/cli/commands/diff.py +303 -0
  267. tokenpak-1.0.0/tokenpak/agent/cli/commands/doctor.py +480 -0
  268. tokenpak-1.0.0/tokenpak/agent/cli/commands/exec.py +198 -0
  269. tokenpak-1.0.0/tokenpak/agent/cli/commands/fingerprint.py +209 -0
  270. tokenpak-1.0.0/tokenpak/agent/cli/commands/handoff.py +231 -0
  271. tokenpak-1.0.0/tokenpak/agent/cli/commands/help.py +324 -0
  272. tokenpak-1.0.0/tokenpak/agent/cli/commands/index.py +111 -0
  273. tokenpak-1.0.0/tokenpak/agent/cli/commands/last.py +119 -0
  274. tokenpak-1.0.0/tokenpak/agent/cli/commands/license.py +121 -0
  275. tokenpak-1.0.0/tokenpak/agent/cli/commands/maintenance.py +51 -0
  276. tokenpak-1.0.0/tokenpak/agent/cli/commands/metrics.py +233 -0
  277. tokenpak-1.0.0/tokenpak/agent/cli/commands/optimize.py +528 -0
  278. tokenpak-1.0.0/tokenpak/agent/cli/commands/policy.py +172 -0
  279. tokenpak-1.0.0/tokenpak/agent/cli/commands/preview.py +136 -0
  280. tokenpak-1.0.0/tokenpak/agent/cli/commands/prune.py +232 -0
  281. tokenpak-1.0.0/tokenpak/agent/cli/commands/replay.py +263 -0
  282. tokenpak-1.0.0/tokenpak/agent/cli/commands/retain.py +219 -0
  283. tokenpak-1.0.0/tokenpak/agent/cli/commands/route.py +36 -0
  284. tokenpak-1.0.0/tokenpak/agent/cli/commands/savings.py +319 -0
  285. tokenpak-1.0.0/tokenpak/agent/cli/commands/serve.py +99 -0
  286. tokenpak-1.0.0/tokenpak/agent/cli/commands/sla.py +147 -0
  287. tokenpak-1.0.0/tokenpak/agent/cli/commands/status.py +174 -0
  288. tokenpak-1.0.0/tokenpak/agent/cli/commands/teacher.py +68 -0
  289. tokenpak-1.0.0/tokenpak/agent/cli/commands/template.py +204 -0
  290. tokenpak-1.0.0/tokenpak/agent/cli/commands/trigger.py +7 -0
  291. tokenpak-1.0.0/tokenpak/agent/cli/commands/vault.py +32 -0
  292. tokenpak-1.0.0/tokenpak/agent/cli/commands/workflow.py +428 -0
  293. tokenpak-1.0.0/tokenpak/agent/cli/main.py +855 -0
  294. tokenpak-1.0.0/tokenpak/agent/cli/trigger_cmd.py +330 -0
  295. tokenpak-1.0.0/tokenpak/agent/compression/__init__.py +91 -0
  296. tokenpak-1.0.0/tokenpak/agent/compression/alias_compressor.py +309 -0
  297. tokenpak-1.0.0/tokenpak/agent/compression/canon.py +455 -0
  298. tokenpak-1.0.0/tokenpak/agent/compression/dedup.py +178 -0
  299. tokenpak-1.0.0/tokenpak/agent/compression/dictionary.py +307 -0
  300. tokenpak-1.0.0/tokenpak/agent/compression/directives.py +647 -0
  301. tokenpak-1.0.0/tokenpak/agent/compression/fidelity_tiers.py +545 -0
  302. tokenpak-1.0.0/tokenpak/agent/compression/instruction_table.py +219 -0
  303. tokenpak-1.0.0/tokenpak/agent/compression/pipeline.py +205 -0
  304. tokenpak-1.0.0/tokenpak/agent/compression/query_rewriter.py +365 -0
  305. tokenpak-1.0.0/tokenpak/agent/compression/recipes.py +637 -0
  306. tokenpak-1.0.0/tokenpak/agent/compression/salience/__init__.py +34 -0
  307. tokenpak-1.0.0/tokenpak/agent/compression/salience/code_extractor.py +269 -0
  308. tokenpak-1.0.0/tokenpak/agent/compression/salience/detect.py +70 -0
  309. tokenpak-1.0.0/tokenpak/agent/compression/salience/doc_extractor.py +147 -0
  310. tokenpak-1.0.0/tokenpak/agent/compression/salience/log_extractor.py +196 -0
  311. tokenpak-1.0.0/tokenpak/agent/compression/salience/router.py +128 -0
  312. tokenpak-1.0.0/tokenpak/agent/compression/schema_extractor.py +530 -0
  313. tokenpak-1.0.0/tokenpak/agent/compression/segmentizer.py +594 -0
  314. tokenpak-1.0.0/tokenpak/agent/compression/slot_filler.py +293 -0
  315. tokenpak-1.0.0/tokenpak/agent/config.py +166 -0
  316. tokenpak-1.0.0/tokenpak/agent/dashboard/__init__.py +6 -0
  317. tokenpak-1.0.0/tokenpak/agent/dashboard/export_api.py +120 -0
  318. tokenpak-1.0.0/tokenpak/agent/dashboard/export_csv.py +187 -0
  319. tokenpak-1.0.0/tokenpak/agent/dashboard/session_filter.py +260 -0
  320. tokenpak-1.0.0/tokenpak/agent/debug/__init__.py +6 -0
  321. tokenpak-1.0.0/tokenpak/agent/debug/logger.py +61 -0
  322. tokenpak-1.0.0/tokenpak/agent/debug/state.py +90 -0
  323. tokenpak-1.0.0/tokenpak/agent/fingerprint/__init__.py +22 -0
  324. tokenpak-1.0.0/tokenpak/agent/fingerprint/generator.py +207 -0
  325. tokenpak-1.0.0/tokenpak/agent/fingerprint/privacy.py +44 -0
  326. tokenpak-1.0.0/tokenpak/agent/fingerprint/sync.py +372 -0
  327. tokenpak-1.0.0/tokenpak/agent/ingest/__init__.py +37 -0
  328. tokenpak-1.0.0/tokenpak/agent/ingest/api.py +176 -0
  329. tokenpak-1.0.0/tokenpak/agent/ingest/claim_indexer.py +276 -0
  330. tokenpak-1.0.0/tokenpak/agent/ingest/cross_doc.py +784 -0
  331. tokenpak-1.0.0/tokenpak/agent/ingest/disclosure.py +183 -0
  332. tokenpak-1.0.0/tokenpak/agent/ingest/document_parser.py +861 -0
  333. tokenpak-1.0.0/tokenpak/agent/ingest/schema_converter.py +134 -0
  334. tokenpak-1.0.0/tokenpak/agent/ingest/table_extractor.py +464 -0
  335. tokenpak-1.0.0/tokenpak/agent/ingest/test_document_parser.py +400 -0
  336. tokenpak-1.0.0/tokenpak/agent/license/__init__.py +23 -0
  337. tokenpak-1.0.0/tokenpak/agent/license/activation.py +244 -0
  338. tokenpak-1.0.0/tokenpak/agent/license/admin_cli.py +267 -0
  339. tokenpak-1.0.0/tokenpak/agent/license/keys.py +188 -0
  340. tokenpak-1.0.0/tokenpak/agent/license/store.py +158 -0
  341. tokenpak-1.0.0/tokenpak/agent/license/validator.py +301 -0
  342. tokenpak-1.0.0/tokenpak/agent/macros/__init__.py +104 -0
  343. tokenpak-1.0.0/tokenpak/agent/macros/engine.py +550 -0
  344. tokenpak-1.0.0/tokenpak/agent/macros/hooks.py +454 -0
  345. tokenpak-1.0.0/tokenpak/agent/macros/premade_macros.py +225 -0
  346. tokenpak-1.0.0/tokenpak/agent/macros/scheduler.py +250 -0
  347. tokenpak-1.0.0/tokenpak/agent/macros/script_hooks.py +235 -0
  348. tokenpak-1.0.0/tokenpak/agent/memory/__init__.py +17 -0
  349. tokenpak-1.0.0/tokenpak/agent/memory/session_capsules.py +150 -0
  350. tokenpak-1.0.0/tokenpak/agent/proxy/__init__.py +35 -0
  351. tokenpak-1.0.0/tokenpak/agent/proxy/capsule_builder.py +80 -0
  352. tokenpak-1.0.0/tokenpak/agent/proxy/capsule_integration.py +242 -0
  353. tokenpak-1.0.0/tokenpak/agent/proxy/circuit_breaker.py +349 -0
  354. tokenpak-1.0.0/tokenpak/agent/proxy/connection_pool.py +448 -0
  355. tokenpak-1.0.0/tokenpak/agent/proxy/degradation.py +183 -0
  356. tokenpak-1.0.0/tokenpak/agent/proxy/example_selector.py +139 -0
  357. tokenpak-1.0.0/tokenpak/agent/proxy/failover.py +301 -0
  358. tokenpak-1.0.0/tokenpak/agent/proxy/failover_engine.py +642 -0
  359. tokenpak-1.0.0/tokenpak/agent/proxy/intent_policy.py +551 -0
  360. tokenpak-1.0.0/tokenpak/agent/proxy/oauth.py +274 -0
  361. tokenpak-1.0.0/tokenpak/agent/proxy/passthrough.py +273 -0
  362. tokenpak-1.0.0/tokenpak/agent/proxy/prompt_builder.py +1088 -0
  363. tokenpak-1.0.0/tokenpak/agent/proxy/providers/__init__.py +22 -0
  364. tokenpak-1.0.0/tokenpak/agent/proxy/providers/anthropic.py +229 -0
  365. tokenpak-1.0.0/tokenpak/agent/proxy/providers/detector.py +183 -0
  366. tokenpak-1.0.0/tokenpak/agent/proxy/providers/google.py +144 -0
  367. tokenpak-1.0.0/tokenpak/agent/proxy/providers/openai.py +164 -0
  368. tokenpak-1.0.0/tokenpak/agent/proxy/providers/stream_translator.py +540 -0
  369. tokenpak-1.0.0/tokenpak/agent/proxy/providers/translator.py +784 -0
  370. tokenpak-1.0.0/tokenpak/agent/proxy/proxy.py +62 -0
  371. tokenpak-1.0.0/tokenpak/agent/proxy/router.py +308 -0
  372. tokenpak-1.0.0/tokenpak/agent/proxy/server.py +1553 -0
  373. tokenpak-1.0.0/tokenpak/agent/proxy/server_async.py +1006 -0
  374. tokenpak-1.0.0/tokenpak/agent/proxy/startup.py +131 -0
  375. tokenpak-1.0.0/tokenpak/agent/proxy/stats.py +240 -0
  376. tokenpak-1.0.0/tokenpak/agent/proxy/stats_api.py +49 -0
  377. tokenpak-1.0.0/tokenpak/agent/proxy/streaming.py +181 -0
  378. tokenpak-1.0.0/tokenpak/agent/proxy/test_prompt_pack.py +352 -0
  379. tokenpak-1.0.0/tokenpak/agent/proxy/tool_schema_registry.py +242 -0
  380. tokenpak-1.0.0/tokenpak/agent/query/__init__.py +1 -0
  381. tokenpak-1.0.0/tokenpak/agent/query/api.py +408 -0
  382. tokenpak-1.0.0/tokenpak/agent/recipe_sdk.py +687 -0
  383. tokenpak-1.0.0/tokenpak/agent/regression/__init__.py +58 -0
  384. tokenpak-1.0.0/tokenpak/agent/regression/artifact_reuse.py +161 -0
  385. tokenpak-1.0.0/tokenpak/agent/regression/baseline_registry.py +95 -0
  386. tokenpak-1.0.0/tokenpak/agent/regression/classifier.py +119 -0
  387. tokenpak-1.0.0/tokenpak/agent/regression/delta_detector.py +189 -0
  388. tokenpak-1.0.0/tokenpak/agent/regression/feature_detector.py +168 -0
  389. tokenpak-1.0.0/tokenpak/agent/regression/retrieval_watchdog.py +437 -0
  390. tokenpak-1.0.0/tokenpak/agent/regression/stability_scorer.py +330 -0
  391. tokenpak-1.0.0/tokenpak/agent/regression/tests/test_classifier.py +86 -0
  392. tokenpak-1.0.0/tokenpak/agent/routing/__init__.py +1 -0
  393. tokenpak-1.0.0/tokenpak/agent/routing/fallback.py +248 -0
  394. tokenpak-1.0.0/tokenpak/agent/routing/rules.py +24 -0
  395. tokenpak-1.0.0/tokenpak/agent/semantic/__init__.py +38 -0
  396. tokenpak-1.0.0/tokenpak/agent/semantic/term_card_builder.py +492 -0
  397. tokenpak-1.0.0/tokenpak/agent/semantic/term_resolver.py +343 -0
  398. tokenpak-1.0.0/tokenpak/agent/semantic/test_proxy_integration.py +342 -0
  399. tokenpak-1.0.0/tokenpak/agent/semantic/test_term_resolver.py +438 -0
  400. tokenpak-1.0.0/tokenpak/agent/state_schemas/__init__.py +37 -0
  401. tokenpak-1.0.0/tokenpak/agent/teacher/__init__.py +5 -0
  402. tokenpak-1.0.0/tokenpak/agent/teacher/builder.py +217 -0
  403. tokenpak-1.0.0/tokenpak/agent/team/__init__.py +17 -0
  404. tokenpak-1.0.0/tokenpak/agent/team/agent_registry.py +223 -0
  405. tokenpak-1.0.0/tokenpak/agent/team/shared_vault.py +221 -0
  406. tokenpak-1.0.0/tokenpak/agent/team/templates.py +242 -0
  407. tokenpak-1.0.0/tokenpak/agent/telemetry/__init__.py +35 -0
  408. tokenpak-1.0.0/tokenpak/agent/telemetry/budget.py +389 -0
  409. tokenpak-1.0.0/tokenpak/agent/telemetry/collector.py +194 -0
  410. tokenpak-1.0.0/tokenpak/agent/telemetry/cost_tracker.py +256 -0
  411. tokenpak-1.0.0/tokenpak/agent/telemetry/demo.py +40 -0
  412. tokenpak-1.0.0/tokenpak/agent/telemetry/footer.py +103 -0
  413. tokenpak-1.0.0/tokenpak/agent/telemetry/replay.py +299 -0
  414. tokenpak-1.0.0/tokenpak/agent/telemetry/storage.py +154 -0
  415. tokenpak-1.0.0/tokenpak/agent/triggers/__init__.py +7 -0
  416. tokenpak-1.0.0/tokenpak/agent/triggers/daemon.py +192 -0
  417. tokenpak-1.0.0/tokenpak/agent/triggers/matcher.py +58 -0
  418. tokenpak-1.0.0/tokenpak/agent/triggers/store.py +103 -0
  419. tokenpak-1.0.0/tokenpak/agent/vault/__init__.py +27 -0
  420. tokenpak-1.0.0/tokenpak/agent/vault/ast_parser.py +245 -0
  421. tokenpak-1.0.0/tokenpak/agent/vault/blocks.py +290 -0
  422. tokenpak-1.0.0/tokenpak/agent/vault/chunk_shapes.py +376 -0
  423. tokenpak-1.0.0/tokenpak/agent/vault/indexer.py +202 -0
  424. tokenpak-1.0.0/tokenpak/agent/vault/retrieval.py +524 -0
  425. tokenpak-1.0.0/tokenpak/agent/vault/scoring.py +256 -0
  426. tokenpak-1.0.0/tokenpak/agent/vault/slicer.py +263 -0
  427. tokenpak-1.0.0/tokenpak/agent/vault/sqlite_retrieval.py +530 -0
  428. tokenpak-1.0.0/tokenpak/agent/vault/symbols.py +168 -0
  429. tokenpak-1.0.0/tokenpak/agent/vault/watcher.py +338 -0
  430. tokenpak-1.0.0/tokenpak/alerts.py +295 -0
  431. tokenpak-1.0.0/tokenpak/api/__init__.py +10 -0
  432. tokenpak-1.0.0/tokenpak/api/routes.py +185 -0
  433. tokenpak-1.0.0/tokenpak/artifact_store.py +431 -0
  434. tokenpak-1.0.0/tokenpak/assembler.py +337 -0
  435. tokenpak-1.0.0/tokenpak/attribution.py +263 -0
  436. tokenpak-1.0.0/tokenpak/benchmark.py +1405 -0
  437. tokenpak-1.0.0/tokenpak/broker.py +298 -0
  438. tokenpak-1.0.0/tokenpak/budget.py +90 -0
  439. tokenpak-1.0.0/tokenpak/budget_controller.py +149 -0
  440. tokenpak-1.0.0/tokenpak/budgeter.py +417 -0
  441. tokenpak-1.0.0/tokenpak/cache/__init__.py +72 -0
  442. tokenpak-1.0.0/tokenpak/cache/prefix_registry.py +224 -0
  443. tokenpak-1.0.0/tokenpak/cache/registry.py +121 -0
  444. tokenpak-1.0.0/tokenpak/cache/semantic_cache.py +341 -0
  445. tokenpak-1.0.0/tokenpak/cache/stable_cache.py +125 -0
  446. tokenpak-1.0.0/tokenpak/cache/telemetry.py +356 -0
  447. tokenpak-1.0.0/tokenpak/cache/volatile_cache.py +122 -0
  448. tokenpak-1.0.0/tokenpak/cache_report.py +50 -0
  449. tokenpak-1.0.0/tokenpak/calibration.py +187 -0
  450. tokenpak-1.0.0/tokenpak/calibrator.py +346 -0
  451. tokenpak-1.0.0/tokenpak/capsule/__init__.py +15 -0
  452. tokenpak-1.0.0/tokenpak/capsule/builder.py +362 -0
  453. tokenpak-1.0.0/tokenpak/citation_tracker.py +200 -0
  454. tokenpak-1.0.0/tokenpak/cli.py +5533 -0
  455. tokenpak-1.0.0/tokenpak/cli_doctor.py +198 -0
  456. tokenpak-1.0.0/tokenpak/compaction/__init__.py +54 -0
  457. tokenpak-1.0.0/tokenpak/compaction/modes.py +229 -0
  458. tokenpak-1.0.0/tokenpak/compaction/policy.py +282 -0
  459. tokenpak-1.0.0/tokenpak/compaction/topic_aware.py +345 -0
  460. tokenpak-1.0.0/tokenpak/compiler.py +207 -0
  461. tokenpak-1.0.0/tokenpak/complexity.py +309 -0
  462. tokenpak-1.0.0/tokenpak/config_loader.py +265 -0
  463. tokenpak-1.0.0/tokenpak/config_validator.py +294 -0
  464. tokenpak-1.0.0/tokenpak/connectors/__init__.py +42 -0
  465. tokenpak-1.0.0/tokenpak/connectors/base.py +95 -0
  466. tokenpak-1.0.0/tokenpak/connectors/base_source.py +81 -0
  467. tokenpak-1.0.0/tokenpak/connectors/git_adapter.py +110 -0
  468. tokenpak-1.0.0/tokenpak/connectors/github.py +174 -0
  469. tokenpak-1.0.0/tokenpak/connectors/google_drive.py +133 -0
  470. tokenpak-1.0.0/tokenpak/connectors/local.py +70 -0
  471. tokenpak-1.0.0/tokenpak/connectors/notion.py +181 -0
  472. tokenpak-1.0.0/tokenpak/connectors/notion_adapter.py +186 -0
  473. tokenpak-1.0.0/tokenpak/connectors/obsidian.py +109 -0
  474. tokenpak-1.0.0/tokenpak/connectors/url_adapter.py +153 -0
  475. tokenpak-1.0.0/tokenpak/context_composer.py +274 -0
  476. tokenpak-1.0.0/tokenpak/core.py +342 -0
  477. tokenpak-1.0.0/tokenpak/daily_report.py +212 -0
  478. tokenpak-1.0.0/tokenpak/dashboard/__init__.py +47 -0
  479. tokenpak-1.0.0/tokenpak/elo.py +164 -0
  480. tokenpak-1.0.0/tokenpak/engines/__init__.py +28 -0
  481. tokenpak-1.0.0/tokenpak/engines/base.py +42 -0
  482. tokenpak-1.0.0/tokenpak/engines/heuristic.py +45 -0
  483. tokenpak-1.0.0/tokenpak/engines/llmlingua.py +80 -0
  484. tokenpak-1.0.0/tokenpak/enterprise/__init__.py +10 -0
  485. tokenpak-1.0.0/tokenpak/enterprise/audit.py +413 -0
  486. tokenpak-1.0.0/tokenpak/enterprise/compliance.py +529 -0
  487. tokenpak-1.0.0/tokenpak/enterprise/governance.py +240 -0
  488. tokenpak-1.0.0/tokenpak/enterprise/policy.py +211 -0
  489. tokenpak-1.0.0/tokenpak/enterprise/sla.py +228 -0
  490. tokenpak-1.0.0/tokenpak/escalation.py +122 -0
  491. tokenpak-1.0.0/tokenpak/evidence_pack.py +236 -0
  492. tokenpak-1.0.0/tokenpak/extraction/__init__.py +13 -0
  493. tokenpak-1.0.0/tokenpak/extraction/extractor.py +161 -0
  494. tokenpak-1.0.0/tokenpak/extraction/models.py +88 -0
  495. tokenpak-1.0.0/tokenpak/extraction/patterns.py +41 -0
  496. tokenpak-1.0.0/tokenpak/fleet.py +282 -0
  497. tokenpak-1.0.0/tokenpak/formatting/__init__.py +4 -0
  498. tokenpak-1.0.0/tokenpak/formatting/colors.py +33 -0
  499. tokenpak-1.0.0/tokenpak/formatting/formatter.py +56 -0
  500. tokenpak-1.0.0/tokenpak/formatting/modes.py +19 -0
  501. tokenpak-1.0.0/tokenpak/formatting/symbols.py +19 -0
  502. tokenpak-1.0.0/tokenpak/goals.py +492 -0
  503. tokenpak-1.0.0/tokenpak/handlers/__init__.py +1 -0
  504. tokenpak-1.0.0/tokenpak/handlers/rate_limit.py +73 -0
  505. tokenpak-1.0.0/tokenpak/integrations/__init__.py +1 -0
  506. tokenpak-1.0.0/tokenpak/integrations/litellm/__init__.py +38 -0
  507. tokenpak-1.0.0/tokenpak/integrations/litellm/formatter.py +158 -0
  508. tokenpak-1.0.0/tokenpak/integrations/litellm/middleware.py +182 -0
  509. tokenpak-1.0.0/tokenpak/integrations/litellm/parser.py +76 -0
  510. tokenpak-1.0.0/tokenpak/integrations/litellm/proxy.py +156 -0
  511. tokenpak-1.0.0/tokenpak/intelligence/__init__.py +1 -0
  512. tokenpak-1.0.0/tokenpak/intelligence/ab_optimizer.py +631 -0
  513. tokenpak-1.0.0/tokenpak/intelligence/ab_router.py +244 -0
  514. tokenpak-1.0.0/tokenpak/intelligence/auth.py +313 -0
  515. tokenpak-1.0.0/tokenpak/intelligence/cost_intelligence.py +435 -0
  516. tokenpak-1.0.0/tokenpak/intelligence/cost_router.py +264 -0
  517. tokenpak-1.0.0/tokenpak/intelligence/deep_health.py +369 -0
  518. tokenpak-1.0.0/tokenpak/intelligence/license_endpoint.py +156 -0
  519. tokenpak-1.0.0/tokenpak/intelligence/server.py +366 -0
  520. tokenpak-1.0.0/tokenpak/intent_classifier.py +434 -0
  521. tokenpak-1.0.0/tokenpak/middleware/__init__.py +56 -0
  522. tokenpak-1.0.0/tokenpak/middleware/audit_trail.py +175 -0
  523. tokenpak-1.0.0/tokenpak/middleware/logger.py +237 -0
  524. tokenpak-1.0.0/tokenpak/middleware/logging_middleware.py +209 -0
  525. tokenpak-1.0.0/tokenpak/middleware/semantic_cache_middleware.py +153 -0
  526. tokenpak-1.0.0/tokenpak/middleware/tests/__init__.py +0 -0
  527. tokenpak-1.0.0/tokenpak/middleware/tests/conftest.py +10 -0
  528. tokenpak-1.0.0/tokenpak/middleware/tests/test_audit_trail.py +220 -0
  529. tokenpak-1.0.0/tokenpak/middleware/tests/test_logger.py +294 -0
  530. tokenpak-1.0.0/tokenpak/middleware/tests/test_logging_middleware.py +138 -0
  531. tokenpak-1.0.0/tokenpak/miss_detector.py +461 -0
  532. tokenpak-1.0.0/tokenpak/monitoring/__init__.py +21 -0
  533. tokenpak-1.0.0/tokenpak/monitoring/audit_trail.py +165 -0
  534. tokenpak-1.0.0/tokenpak/monitoring/health.py +217 -0
  535. tokenpak-1.0.0/tokenpak/monitoring/metrics.py +386 -0
  536. tokenpak-1.0.0/tokenpak/monitoring/request_logger.py +517 -0
  537. tokenpak-1.0.0/tokenpak/pack.py +455 -0
  538. tokenpak-1.0.0/tokenpak/post_run.py +268 -0
  539. tokenpak-1.0.0/tokenpak/precompute.py +634 -0
  540. tokenpak-1.0.0/tokenpak/pricing.py +143 -0
  541. tokenpak-1.0.0/tokenpak/processors/__init__.py +38 -0
  542. tokenpak-1.0.0/tokenpak/processors/code.py +474 -0
  543. tokenpak-1.0.0/tokenpak/processors/code_treesitter.py +532 -0
  544. tokenpak-1.0.0/tokenpak/processors/data.py +137 -0
  545. tokenpak-1.0.0/tokenpak/processors/text.py +195 -0
  546. tokenpak-1.0.0/tokenpak/profiles.py +129 -0
  547. tokenpak-1.0.0/tokenpak/proxy/__init__.py +3 -0
  548. tokenpak-1.0.0/tokenpak/proxy/adapters/__init__.py +34 -0
  549. tokenpak-1.0.0/tokenpak/proxy/adapters/anthropic_adapter.py +115 -0
  550. tokenpak-1.0.0/tokenpak/proxy/adapters/base.py +179 -0
  551. tokenpak-1.0.0/tokenpak/proxy/adapters/canonical.py +34 -0
  552. tokenpak-1.0.0/tokenpak/proxy/adapters/google_adapter.py +129 -0
  553. tokenpak-1.0.0/tokenpak/proxy/adapters/openai_chat_adapter.py +89 -0
  554. tokenpak-1.0.0/tokenpak/proxy/adapters/openai_responses_adapter.py +114 -0
  555. tokenpak-1.0.0/tokenpak/proxy/adapters/passthrough_adapter.py +76 -0
  556. tokenpak-1.0.0/tokenpak/proxy/adapters/registry.py +42 -0
  557. tokenpak-1.0.0/tokenpak/proxy/credential_passthrough.py +283 -0
  558. tokenpak-1.0.0/tokenpak/py.typed +0 -0
  559. tokenpak-1.0.0/tokenpak/reference_fetcher.py +151 -0
  560. tokenpak-1.0.0/tokenpak/reference_scanner.py +124 -0
  561. tokenpak-1.0.0/tokenpak/registry.py +326 -0
  562. tokenpak-1.0.0/tokenpak/report.py +299 -0
  563. tokenpak-1.0.0/tokenpak/request_audit.py +211 -0
  564. tokenpak-1.0.0/tokenpak/routing/__init__.py +3 -0
  565. tokenpak-1.0.0/tokenpak/routing/rules.py +359 -0
  566. tokenpak-1.0.0/tokenpak/routing_ledger.py +268 -0
  567. tokenpak-1.0.0/tokenpak/schemas/__init__.py +8 -0
  568. tokenpak-1.0.0/tokenpak/schemas/artifact.py +76 -0
  569. tokenpak-1.0.0/tokenpak/schemas/chunk.py +66 -0
  570. tokenpak-1.0.0/tokenpak/schemas/retrieval_cache.py +87 -0
  571. tokenpak-1.0.0/tokenpak/schemas/source_map.py +69 -0
  572. tokenpak-1.0.0/tokenpak/security.py +216 -0
  573. tokenpak-1.0.0/tokenpak/semantic/__init__.py +27 -0
  574. tokenpak-1.0.0/tokenpak/semantic/loader.py +213 -0
  575. tokenpak-1.0.0/tokenpak/semantic/resolver.py +292 -0
  576. tokenpak-1.0.0/tokenpak/shadow_hook.py +157 -0
  577. tokenpak-1.0.0/tokenpak/shadow_reader.py +558 -0
  578. tokenpak-1.0.0/tokenpak/span_extractor.py +227 -0
  579. tokenpak-1.0.0/tokenpak/state_manager.py +388 -0
  580. tokenpak-1.0.0/tokenpak/telemetry/__init__.py +35 -0
  581. tokenpak-1.0.0/tokenpak/telemetry/adapters/__init__.py +33 -0
  582. tokenpak-1.0.0/tokenpak/telemetry/adapters/anthropic.py +199 -0
  583. tokenpak-1.0.0/tokenpak/telemetry/adapters/base.py +93 -0
  584. tokenpak-1.0.0/tokenpak/telemetry/adapters/gemini.py +229 -0
  585. tokenpak-1.0.0/tokenpak/telemetry/adapters/openai.py +231 -0
  586. tokenpak-1.0.0/tokenpak/telemetry/adapters/registry.py +194 -0
  587. tokenpak-1.0.0/tokenpak/telemetry/anon_metrics.py +274 -0
  588. tokenpak-1.0.0/tokenpak/telemetry/api.py +189 -0
  589. tokenpak-1.0.0/tokenpak/telemetry/cache.py +229 -0
  590. tokenpak-1.0.0/tokenpak/telemetry/canonical.py +166 -0
  591. tokenpak-1.0.0/tokenpak/telemetry/collector.py +213 -0
  592. tokenpak-1.0.0/tokenpak/telemetry/config.py +108 -0
  593. tokenpak-1.0.0/tokenpak/telemetry/cost.py +659 -0
  594. tokenpak-1.0.0/tokenpak/telemetry/dashboard/__init__.py +8 -0
  595. tokenpak-1.0.0/tokenpak/telemetry/dashboard/dashboard.py +1053 -0
  596. tokenpak-1.0.0/tokenpak/telemetry/dashboard/pagination.py +127 -0
  597. tokenpak-1.0.0/tokenpak/telemetry/dashboard/query_builder.py +213 -0
  598. tokenpak-1.0.0/tokenpak/telemetry/event_schema.py +365 -0
  599. tokenpak-1.0.0/tokenpak/telemetry/insights.py +511 -0
  600. tokenpak-1.0.0/tokenpak/telemetry/integrity/__init__.py +0 -0
  601. tokenpak-1.0.0/tokenpak/telemetry/integrity/anomalies.py +353 -0
  602. tokenpak-1.0.0/tokenpak/telemetry/integrity/reconciliation.py +209 -0
  603. tokenpak-1.0.0/tokenpak/telemetry/integrity/validation.py +249 -0
  604. tokenpak-1.0.0/tokenpak/telemetry/milestones.py +391 -0
  605. tokenpak-1.0.0/tokenpak/telemetry/models.py +344 -0
  606. tokenpak-1.0.0/tokenpak/telemetry/operational/__init__.py +0 -0
  607. tokenpak-1.0.0/tokenpak/telemetry/operational/api.py +229 -0
  608. tokenpak-1.0.0/tokenpak/telemetry/operational/health.py +176 -0
  609. tokenpak-1.0.0/tokenpak/telemetry/operational/metrics.py +158 -0
  610. tokenpak-1.0.0/tokenpak/telemetry/operational/pruning.py +166 -0
  611. tokenpak-1.0.0/tokenpak/telemetry/pipeline.py +364 -0
  612. tokenpak-1.0.0/tokenpak/telemetry/pipeline_trace.py +106 -0
  613. tokenpak-1.0.0/tokenpak/telemetry/pricing.py +419 -0
  614. tokenpak-1.0.0/tokenpak/telemetry/prometheus.py +371 -0
  615. tokenpak-1.0.0/tokenpak/telemetry/proxy_trace_integration.py +170 -0
  616. tokenpak-1.0.0/tokenpak/telemetry/query.py +259 -0
  617. tokenpak-1.0.0/tokenpak/telemetry/query_models.py +50 -0
  618. tokenpak-1.0.0/tokenpak/telemetry/reporter.py +172 -0
  619. tokenpak-1.0.0/tokenpak/telemetry/response_models.py +259 -0
  620. tokenpak-1.0.0/tokenpak/telemetry/rollups.py +641 -0
  621. tokenpak-1.0.0/tokenpak/telemetry/segmentizer.py +1020 -0
  622. tokenpak-1.0.0/tokenpak/telemetry/server.py +1055 -0
  623. tokenpak-1.0.0/tokenpak/telemetry/settings.py +160 -0
  624. tokenpak-1.0.0/tokenpak/telemetry/stats.py +178 -0
  625. tokenpak-1.0.0/tokenpak/telemetry/storage.py +1314 -0
  626. tokenpak-1.0.0/tokenpak/telemetry/storage_base.py +314 -0
  627. tokenpak-1.0.0/tokenpak/telemetry/storage_events.py +231 -0
  628. tokenpak-1.0.0/tokenpak/telemetry/storage_rollups.py +340 -0
  629. tokenpak-1.0.0/tokenpak/telemetry/storage_segments.py +88 -0
  630. tokenpak-1.0.0/tokenpak/telemetry/storage_usage.py +361 -0
  631. tokenpak-1.0.0/tokenpak/tests/test_config_validation.py +472 -0
  632. tokenpak-1.0.0/tokenpak/tests/test_config_validation_simple.py +205 -0
  633. tokenpak-1.0.0/tokenpak/tests/test_config_validator_edge_cases.py +350 -0
  634. tokenpak-1.0.0/tokenpak/tests/test_cost_cache_module.py +606 -0
  635. tokenpak-1.0.0/tokenpak/tests/test_cost_integration.py +420 -0
  636. tokenpak-1.0.0/tokenpak/tests/test_proxy_integration.py +88 -0
  637. tokenpak-1.0.0/tokenpak/tests/test_proxy_module.py +359 -0
  638. tokenpak-1.0.0/tokenpak/tests/test_routing_integration.py +23 -0
  639. tokenpak-1.0.0/tokenpak/tests/test_savings_display.py +249 -0
  640. tokenpak-1.0.0/tokenpak/tests/test_schemas_integration.py +79 -0
  641. tokenpak-1.0.0/tokenpak/tests/test_telemetry_integration.py +278 -0
  642. tokenpak-1.0.0/tokenpak/tests/test_validation_gate_integration.py +382 -0
  643. tokenpak-1.0.0/tokenpak/timeline.py +206 -0
  644. tokenpak-1.0.0/tokenpak/tokens.py +134 -0
  645. tokenpak-1.0.0/tokenpak/trace.py +404 -0
  646. tokenpak-1.0.0/tokenpak/user_templates.py +199 -0
  647. tokenpak-1.0.0/tokenpak/validation/__init__.py +63 -0
  648. tokenpak-1.0.0/tokenpak/validation/frontmatter.py +120 -0
  649. tokenpak-1.0.0/tokenpak/validation/request_schema.py +289 -0
  650. tokenpak-1.0.0/tokenpak/validation/request_validator.py +620 -0
  651. tokenpak-1.0.0/tokenpak/validation/response_schema.py +120 -0
  652. tokenpak-1.0.0/tokenpak/validation/validator.py +326 -0
  653. tokenpak-1.0.0/tokenpak/validation_gate.py +145 -0
  654. tokenpak-1.0.0/tokenpak/validator.py +470 -0
  655. tokenpak-1.0.0/tokenpak/vendor_classifier.py +166 -0
  656. tokenpak-1.0.0/tokenpak/version_check.py +147 -0
  657. tokenpak-1.0.0/tokenpak/walker.py +82 -0
  658. tokenpak-1.0.0/tokenpak/watchdog.py +329 -0
  659. tokenpak-1.0.0/tokenpak/wire.py +62 -0
  660. tokenpak-1.0.0/tokenpak/workflow_performance.py +321 -0
  661. tokenpak-1.0.0/tokenpak.egg-info/PKG-INFO +517 -0
  662. tokenpak-1.0.0/tokenpak.egg-info/SOURCES.txt +664 -0
  663. tokenpak-1.0.0/tokenpak.egg-info/dependency_links.txt +1 -0
  664. tokenpak-1.0.0/tokenpak.egg-info/entry_points.txt +3 -0
  665. tokenpak-1.0.0/tokenpak.egg-info/requires.txt +23 -0
  666. tokenpak-1.0.0/tokenpak.egg-info/top_level.txt +1 -0
tokenpak-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TokenPak Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,108 @@
1
+ # TokenPak Commercial License
2
+
3
+ This document describes the commercial licensing terms for TokenPak Pro, Team, and Enterprise editions.
4
+
5
+ ## Open Source (TokenPak OSS)
6
+
7
+ TokenPak OSS is licensed under the MIT License. See [LICENSE](./LICENSE) for details.
8
+
9
+ You may use TokenPak OSS for any purpose, including commercial applications, without charge or restriction.
10
+
11
+ ---
12
+
13
+ ## Commercial Editions
14
+
15
+ ### TokenPak Pro
16
+
17
+ **Monthly subscription: $99/month**
18
+
19
+ Pro license grants:
20
+ - Access to TokenPak Cloud Dashboard
21
+ - Managed API proxy service
22
+ - Advanced analytics and reporting
23
+ - Priority email support (24-48hr response)
24
+ - All OSS features
25
+
26
+ **Terms:**
27
+ - Per-seat licensing (1 developer per license)
28
+ - Monthly or annual billing (annual = 2 months free)
29
+ - Cancel anytime
30
+ - No refunds for partial months
31
+
32
+ ---
33
+
34
+ ### TokenPak Team
35
+
36
+ **Monthly subscription: $299/month (up to 10 users)**
37
+
38
+ Team license grants:
39
+ - All Pro features
40
+ - Multi-user collaboration
41
+ - Team billing and invoicing
42
+ - Role-based access control
43
+ - Shared dashboards and reports
44
+ - Slack integration for alerts
45
+
46
+ **Terms:**
47
+ - Base plan includes 10 seats
48
+ - Additional seats: $25/user/month
49
+ - Annual billing available (2 months free)
50
+ - Cancel anytime
51
+
52
+ ---
53
+
54
+ ### TokenPak Enterprise
55
+
56
+ **Custom pricing**
57
+
58
+ Enterprise license grants:
59
+ - All Team features
60
+ - Self-hosted deployment option
61
+ - On-premises installation support
62
+ - Custom integrations (Datadog, Splunk, etc.)
63
+ - Dedicated support engineer
64
+ - SLA with uptime guarantees
65
+ - Compliance documentation (SOC2, HIPAA, GDPR)
66
+ - Volume discounts
67
+
68
+ **Terms:**
69
+ - Annual contracts (minimum 1 year)
70
+ - Custom pricing based on scale and requirements
71
+ - Contact sales@tokenpak.ai for quote
72
+
73
+ ---
74
+
75
+ ## Usage Restrictions (Commercial Editions)
76
+
77
+ Commercial licenses **do not** permit:
78
+
79
+ 1. Reselling or sublicensing TokenPak as a standalone product
80
+ 2. Removing or obscuring TokenPak branding in managed services
81
+ 3. Using Pro/Team features in competing compression products
82
+ 4. Sharing credentials across organizations
83
+
84
+ ## Ownership
85
+
86
+ TokenPak and all commercial features remain the intellectual property of TokenPak Inc. Commercial licenses grant usage rights only, not ownership.
87
+
88
+ ## Support
89
+
90
+ | Tier | Support Channel | Response Time |
91
+ |------|-----------------|---------------|
92
+ | OSS | GitHub Issues | Community (no SLA) |
93
+ | Pro | Email | 24-48 hours |
94
+ | Team | Email + Slack | 12-24 hours |
95
+ | Enterprise | Dedicated + Phone | 4 hours (critical) |
96
+
97
+ ## Upgrades and Downgrades
98
+
99
+ - Upgrade from OSS → Pro: Instant, self-service
100
+ - Upgrade from Pro → Team: Prorated billing
101
+ - Downgrade: Takes effect next billing cycle
102
+ - Enterprise → lower tier: Contact sales
103
+
104
+ ## Questions?
105
+
106
+ - Email: licensing@tokenpak.ai
107
+ - Sales: sales@tokenpak.ai
108
+ - Documentation: https://docs.tokenpak.ai
@@ -0,0 +1,517 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokenpak
3
+ Version: 1.0.0
4
+ Summary: Slash LLM costs with intelligent context compression, smart routing, and cost tracking
5
+ Author-email: Kevin Yang <kaywhy331@gmail.com>
6
+ Maintainer-email: Kevin Yang <kaywhy331@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 TokenPak Contributors
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/tokenpak/tokenpak
30
+ Project-URL: Documentation, https://github.com/tokenpak/tokenpak/blob/main/README.md
31
+ Project-URL: Bug Reports, https://github.com/tokenpak/tokenpak/issues
32
+ Project-URL: Source Code, https://github.com/tokenpak/tokenpak
33
+ Project-URL: Changelog, https://github.com/tokenpak/tokenpak/blob/main/CHANGELOG.md
34
+ Keywords: llm,ai,proxy,token-optimization,openai,anthropic,compression,context,context-window,tokens,cost-tracking,routing
35
+ Classifier: Development Status :: 5 - Production/Stable
36
+ Classifier: Intended Audience :: Developers
37
+ Classifier: Intended Audience :: Science/Research
38
+ Classifier: License :: OSI Approved :: MIT License
39
+ Classifier: Operating System :: OS Independent
40
+ Classifier: Programming Language :: Python :: 3
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Programming Language :: Python :: 3.13
45
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
46
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
47
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
48
+ Classifier: Topic :: System :: Networking
49
+ Classifier: Topic :: Utilities
50
+ Classifier: Typing :: Typed
51
+ Requires-Python: >=3.10
52
+ Description-Content-Type: text/markdown
53
+ License-File: LICENSE
54
+ License-File: LICENSE_COMMERCIAL.md
55
+ Requires-Dist: aiohttp>=3.9.0
56
+ Requires-Dist: pyyaml>=6.0
57
+ Requires-Dist: click>=8.1.0
58
+ Requires-Dist: starlette>=0.36.0
59
+ Requires-Dist: uvicorn>=0.27.0
60
+ Requires-Dist: httpx>=0.26.0
61
+ Requires-Dist: h2<5,>=3
62
+ Requires-Dist: watchdog>=3.0.0
63
+ Provides-Extra: dev
64
+ Requires-Dist: pytest>=7.0; extra == "dev"
65
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
66
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
67
+ Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
68
+ Requires-Dist: black>=24.0.0; extra == "dev"
69
+ Requires-Dist: ruff>=0.2.0; extra == "dev"
70
+ Provides-Extra: tokens
71
+ Requires-Dist: tiktoken>=0.5.0; extra == "tokens"
72
+ Provides-Extra: docs
73
+ Requires-Dist: mkdocs>=1.5.0; extra == "docs"
74
+ Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
75
+ Dynamic: license-file
76
+
77
+ # TokenPak
78
+
79
+ ![Tests](https://img.shields.io/badge/tests-passing-brightgreen)
80
+ ![Coverage](https://img.shields.io/badge/coverage-54%25-brightgreen)
81
+ ![Python](https://img.shields.io/badge/python-3.8+-blue)
82
+ ![License](https://img.shields.io/badge/license-MIT-blue)
83
+ ![PyPI](https://img.shields.io/badge/pypi-1.0.0-blue)
84
+
85
+ > **Zero-token operations. Maximum context efficiency.**
86
+
87
+ TokenPak is an open-source LLM proxy agent that compresses context, routes requests intelligently, and tracks costs — all without touching your prompts or credentials.
88
+
89
+ **Protocol spec (v1.0):**
90
+ - 📜 Spec: [`docs/PROTOCOL.md`](docs/PROTOCOL.md)
91
+ - ✅ Schema: [`schemas/tokenpak-v1.0.json`](schemas/tokenpak-v1.0.json)
92
+ - 🧪 Validator: [`tokenpak/validator.py`](tokenpak/validator.py)
93
+ - 🧩 Examples: [`examples/`](examples/)
94
+
95
+ [![CI](https://github.com/tokenpak/tokenpak/actions/workflows/ci.yml/badge.svg)](https://github.com/tokenpak/tokenpak/actions)
96
+ [![PyPI version](https://img.shields.io/pypi/v/tokenpak.svg)](https://pypi.org/project/tokenpak/)
97
+ [![Python 3.10+](https://img.shields.io/pypi/pyversions/tokenpak.svg)](https://pypi.org/project/tokenpak/)
98
+ [![Downloads](https://static.pepy.tech/badge/tokenpak/month)](https://pepy.tech/project/tokenpak)
99
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
100
+ [![codecov](https://codecov.io/gh/tokenpak/tokenpak/branch/main/graph/badge.svg)](https://codecov.io/gh/tokenpak/tokenpak)
101
+
102
+ ---
103
+
104
+ ## 3 Commands to Savings
105
+
106
+ ```bash
107
+ pip install tokenpak # install
108
+ tokenpak serve --port 8766 --workers 4 # start proxy (4 CPU cores)
109
+ tokenpak cost --week # watch savings grow
110
+ ```
111
+
112
+ Point your LLM client's base URL at `http://localhost:8766`. That's it — **zero config required.**
113
+
114
+ ---
115
+
116
+ ## See It In Action
117
+
118
+ ![TokenPak compression demo](docs/demo/demo.gif)
119
+
120
+ > **48.9% token reduction** — across real payloads, zero config. 5,074 → 2,594 tokens in <1ms.
121
+
122
+ ---
123
+
124
+ ## What It Does
125
+
126
+ - **Compresses context** before it hits the API — fewer tokens, lower cost
127
+ - **Routes requests** to the right model (fast/cheap vs. powerful/expensive)
128
+ - **Tracks costs** locally — per model, per session, per agent
129
+ - **Indexes your vault** for instant semantic search without an LLM call
130
+ - **80%+ of operations cost zero tokens** — CLI-first, deterministic
131
+
132
+ ## Core Principles
133
+
134
+ | Principle | What it means |
135
+ |-----------|---------------|
136
+ | **Zero Data** | We never see your prompts, code, or responses |
137
+ | **Zero Credentials** | Pure passthrough proxy — no API keys stored |
138
+ | **Zero Lock-in** | Downgrade anytime; keep all your data |
139
+ | **Zero Tokens for Ops** | Status, search, cost reports — all free |
140
+
141
+ ---
142
+
143
+ ## Architecture
144
+
145
+ ```mermaid
146
+ graph LR
147
+ subgraph Your Machine
148
+ Client["LLM Client\n(Claude Code / OpenAI SDK)"]
149
+ Proxy["TokenPak Proxy\n:8766"]
150
+ Vault["Local Vault\n(semantic index)"]
151
+ end
152
+
153
+ subgraph Pipeline
154
+ P1["① Segment\nSplit into blocks"]
155
+ P2["② Fingerprint\nDetect type"]
156
+ P3["③ Compress\nApply recipe"]
157
+ P4["④ Budget\nPrioritize tokens"]
158
+ P5["⑤ Assemble\nRebuild prompt"]
159
+ end
160
+
161
+ subgraph Routing
162
+ R1["Route Rules\n(model/prefix/tokens)"]
163
+ R2["Provider A\n(OpenAI)"]
164
+ R3["Provider B\n(Anthropic)"]
165
+ end
166
+
167
+ Client -->|"request"| Proxy
168
+ Proxy --> R1
169
+ R1 -->|"rule match"| R2
170
+ R1 -->|"fallback"| R3
171
+ Proxy --> P1 --> P2 --> P3 --> P4 --> P5
172
+ Proxy <-->|"zero-token search"| Vault
173
+ P5 -->|"compressed request"| R2
174
+ R2 -->|"response"| Client
175
+ ```
176
+
177
+ **Key insight:** The compression pipeline runs locally, before the request leaves your machine. The LLM never sees your raw tokens — only the compressed version.
178
+
179
+ ---
180
+
181
+ ## Plans
182
+
183
+ | Feature | OSS | Pro | Team |
184
+ |---|:---:|:---:|:---:|
185
+ | Context compression | ✅ | ✅ | ✅ |
186
+ | Model routing | ✅ | ✅ | ✅ |
187
+ | Cost tracking | ✅ | ✅ | ✅ |
188
+ | Vault indexing + search | ✅ | ✅ | ✅ |
189
+ | CLI + proxy | ✅ | ✅ | ✅ |
190
+ | A/B testing | ✅ | ✅ | ✅ |
191
+ | Replay + debug | ✅ | ✅ | ✅ |
192
+ | Advanced compression recipes | — | ✅ | ✅ |
193
+ | Budget enforcement + alerts | — | ✅ | ✅ |
194
+ | Priority support | — | ✅ | ✅ |
195
+ | Multi-agent coordination | — | — | ✅ |
196
+ | Shared vault (team) | — | — | ✅ |
197
+ | RBAC + audit logs | — | — | ✅ |
198
+ | Seat management | — | — | ✅ |
199
+ | SSO / enterprise auth | — | — | ✅ |
200
+ | On-premises deployment | — | — | ✅ |
201
+ | **Price** | **Free** | **$99/mo** | **$299/mo** |
202
+
203
+ **Enterprise:** Custom pricing for large organizations. [Contact sales](mailto:sales@tokenpak.ai).
204
+
205
+ [→ View full pricing](docs/PRODUCT_STRATEGY.md#product-tiers) | [→ License details](LICENSE_COMMERCIAL.md)
206
+
207
+ ---
208
+
209
+ ## Token Savings (QMD + TokenPak)
210
+
211
+ | Configuration | Avg tokens/req | Reduction |
212
+ |---|---:|---:|
213
+ | Baseline (no optimization) | 20,801 | — |
214
+ | QMD only | 6,136 | 70% |
215
+ | QMD + TokenPak | 3,265 | **84%** |
216
+
217
+ Consistent **~43% additional savings** on top of QMD across writing, coding, legal, and ops tasks.
218
+
219
+ ---
220
+
221
+ ## Performance
222
+
223
+ TokenPak is engineered for speed. Compilation must feel free — if it adds perceptible latency, developers won't adopt it.
224
+
225
+ ### Compile Latency Targets
226
+
227
+ | Pack Size | Blocks | Tokens | p50 target | p95 hard limit |
228
+ |-----------|--------|--------|------------|----------------|
229
+ | **Small** | 2–3 | ~500 | < 20ms | < 30ms |
230
+ | **Medium** | ~10 | ~5,000 | < 30ms | < 50ms |
231
+ | **Large** | ~50 | ~50,000 | < 50ms | < 100ms |
232
+
233
+ Latency gates are **enforced in CI on every PR** — p95 breaches block merge.
234
+
235
+ ### Run Benchmarks
236
+
237
+ ```bash
238
+ # Full benchmark suite with pytest-benchmark
239
+ pytest tests/benchmarks/ -v --benchmark-json=benchmark.json
240
+
241
+ # Check thresholds (CI gate)
242
+ python scripts/check_benchmark_thresholds.py benchmark.json
243
+
244
+ # View latency summary
245
+ pytest tests/benchmarks/test_compile_performance.py::TestCompilePerformancePlain::test_all_three_packs_summary -s
246
+ ```
247
+
248
+ ### Internal Optimizations
249
+
250
+ | Optimization | Improvement |
251
+ |---|---|
252
+ | LRU token cache | **25x** faster repeated counting |
253
+ | Batch SQLite transactions | **60%** faster indexing |
254
+ | Pre-compiled regex | **30%** faster processing |
255
+ | Connection pooling + WAL | Reduced I/O overhead |
256
+
257
+ **Benchmark (572-file vault):**
258
+ ```
259
+ Indexing throughput: 2,738 files/sec
260
+ Indexing speedup: 55x faster than baseline
261
+ Search latency: 22.7ms/query
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Adoption Ladder — Use One Feature First
267
+
268
+ TokenPak is designed for incremental adoption. You don't need to adopt the full system.
269
+ Start with one feature and grow from there.
270
+
271
+ | Level | What you get | Import |
272
+ |-------|-------------|--------|
273
+ | **1 — Token counting** | Count tokens in any string | `from tokenpak import count_tokens` |
274
+ | **2 — Simple packing** | Pack a prompt in one call | `from tokenpak import pack_prompt` |
275
+ | **3 — Block-based context** | Priority + quality control | `from tokenpak import ContextPack, PackBlock` |
276
+ | **4 — Full protocol** | Compile reports + all output formats | `compiled.to_messages()` / `compiled.to_anthropic()` |
277
+ | **5 — Wire format** | Serialize for cross-agent transfer | `compiled.to_json()` |
278
+
279
+ ### Level 1: Token counting (zero config)
280
+
281
+ ```python
282
+ from tokenpak import count_tokens
283
+
284
+ tokens = count_tokens("My prompt text")
285
+ print(f"{tokens} tokens")
286
+ ```
287
+
288
+ ### Level 2: Simple packing (one function)
289
+
290
+ ```python
291
+ from tokenpak import pack_prompt
292
+
293
+ prompt = pack_prompt(
294
+ system="You are a helpful assistant.",
295
+ docs=my_large_docs, # high priority — kept first
296
+ history=chat_history, # low priority — trimmed if needed
297
+ budget=8000,
298
+ )
299
+ ```
300
+
301
+ ### Level 3: Block-based context
302
+
303
+ ```python
304
+ from tokenpak import ContextPack, PackBlock
305
+
306
+ pack = ContextPack(budget=8000)
307
+ pack.add(PackBlock(id="system", type="instructions", content=system_prompt, priority="critical"))
308
+ pack.add(PackBlock(id="docs", type="knowledge", content=api_docs, priority="high"))
309
+ pack.add(PackBlock(id="search", type="evidence", content=results, priority="medium", quality=0.8))
310
+ ```
311
+
312
+ ### Level 4: Full protocol
313
+
314
+ ```python
315
+ compiled = pack.compile()
316
+
317
+ # Works with OpenAI
318
+ from openai import OpenAI
319
+ OpenAI().chat.completions.create(model="gpt-4o", messages=compiled.to_messages())
320
+
321
+ # Works with Anthropic
322
+ from anthropic import Anthropic
323
+ system, messages = compiled.to_anthropic()
324
+ Anthropic().messages.create(model="claude-3-5-sonnet-latest", system=system, messages=messages)
325
+
326
+ # Works with LiteLLM / Ollama (same format)
327
+ from litellm import completion
328
+ completion(model="ollama/mistral", messages=compiled.to_messages())
329
+
330
+ # Inspect every decision
331
+ print(compiled.report)
332
+ ```
333
+
334
+ ### Level 5: Wire format
335
+
336
+ ```python
337
+ import json
338
+
339
+ payload = json.dumps(compiled.to_json()) # serialize
340
+ recovered = json.loads(payload) # deserialize anywhere
341
+ print(recovered["text"]) # compiled prompt
342
+ print(recovered["report"]["summary"]) # compile stats
343
+ ```
344
+
345
+ > **Key guarantee:** Every level works independently. Level 3 does not require Level 4.
346
+ > The SDK works with no gateway, no cloud, and no required external dependencies.
347
+
348
+ ---
349
+
350
+ ## How Compression Works
351
+
352
+ TokenPak intercepts requests before they reach the LLM and applies a multi-stage pipeline:
353
+
354
+ 1. **Segmentize** — split content into semantic blocks
355
+ 2. **Fingerprint** — identify block type (code, docs, config…)
356
+ 3. **Apply recipe** — use declarative rules to compress that block type
357
+ 4. **Budget** — allocate tokens using a quadratic priority algorithm
358
+ 5. **Assemble** — reconstruct the compressed prompt
359
+
360
+ Result: same semantic content, 20–60% fewer tokens.
361
+
362
+ ---
363
+
364
+ ## CLI Reference
365
+
366
+ ### Core
367
+
368
+ ```bash
369
+ tokenpak serve --port 8766 [--workers N] # start proxy (default: cpu_count//2 workers)
370
+ tokenpak status [--full] # proxy health
371
+ tokenpak cost [--week|--month] # cost report
372
+ tokenpak savings [--lifetime] # token savings summary
373
+ ```
374
+
375
+ ### Compression & Debug
376
+
377
+ ```bash
378
+ tokenpak compress <file> # dry-run compression
379
+ tokenpak demo [--verbose] # see pipeline on real data
380
+ tokenpak trace [--id <id>] # trace a pipeline run
381
+ tokenpak debug on # capture raw/compressed pairs
382
+ ```
383
+
384
+ ### Vault & Indexing
385
+
386
+ ```bash
387
+ tokenpak index [<path>] # index a directory
388
+ tokenpak vault search "query" # semantic search (zero tokens)
389
+ tokenpak calibrate ~/vault # auto-tune workers for this host
390
+ ```
391
+
392
+ ### Model Routing
393
+
394
+ ```bash
395
+ tokenpak route add --model 'gpt-4*' --target anthropic/claude-3-haiku-20240307
396
+ tokenpak route list
397
+ tokenpak route test "write unit tests"
398
+ ```
399
+
400
+ ### Templates & Replay
401
+
402
+ ```bash
403
+ tokenpak template list
404
+ tokenpak template use my-tpl
405
+ tokenpak replay list
406
+ tokenpak replay <id> --diff
407
+ ```
408
+
409
+ ---
410
+
411
+ ## Directory Structure
412
+
413
+ ```
414
+ tokenpak/
415
+ ├── tokenpak/
416
+ │ ├── agent/
417
+ │ │ ├── compression/ # pipeline, segmentizer, recipes, directives
418
+ │ │ ├── proxy/ # request routing + streaming
419
+ │ │ ├── routing/ # manual route rules
420
+ │ │ ├── telemetry/ # cost tracking, storage
421
+ │ │ ├── vault/ # indexer, ast_parser, symbols
422
+ │ │ ├── license/ # key generation, validation, store
423
+ │ │ └── team/ # multi-agent coordination, shared vault
424
+ │ ├── engines/
425
+ │ │ ├── heuristic.py # Rule-based compaction
426
+ │ │ └── llmlingua.py # ML-powered compaction (optional)
427
+ │ └── processors/
428
+ │ ├── code.py # Python/JS structure extraction
429
+ │ ├── text.py # Markdown/HTML compression
430
+ │ └── data.py # JSON/YAML/CSV handling
431
+ ├── portal/ # self-service web portal
432
+ ├── recipes/oss/ # built-in compression recipes (YAML)
433
+ ├── tests/
434
+ └── pyproject.toml
435
+ ```
436
+
437
+ ---
438
+
439
+ ## Configuration
440
+
441
+ Default config: `~/.tokenpak/config.json`
442
+
443
+ ```json
444
+ {
445
+ "proxy": {
446
+ "port": 8766,
447
+ "passthrough_url": "https://api.openai.com"
448
+ },
449
+ "compression": {
450
+ "enabled": true,
451
+ "level": "balanced"
452
+ },
453
+ "budget": {
454
+ "monthly_usd": null,
455
+ "alert_at_pct": 80
456
+ },
457
+ "vault": {
458
+ "db_path": ".tokenpak/registry.db",
459
+ "watch": false
460
+ }
461
+ }
462
+ ```
463
+
464
+ ---
465
+
466
+ ## Requirements
467
+
468
+ - Python 3.10+
469
+ - No external dependencies for core functionality
470
+ - Optional: `tiktoken` for accurate token counting
471
+ - Optional: `llmlingua` for ML-powered compression
472
+
473
+ ---
474
+
475
+ ## Contributing
476
+
477
+ We welcome issues, pull requests, and feedback of all kinds!
478
+
479
+ - 🐛 **Bug reports** → [Open an issue](https://github.com/tokenpak/tokenpak/issues/new?template=bug_report.md)
480
+ - 💡 **Feature requests** → [Request a feature](https://github.com/tokenpak/tokenpak/issues/new?template=feature_request.md)
481
+ - 💬 **Questions & ideas** → [GitHub Discussions](https://github.com/tokenpak/tokenpak/discussions)
482
+ - 📖 **Full guide** → [CONTRIBUTING.md](CONTRIBUTING.md)
483
+ - 📋 **Version history** → [CHANGELOG.md](CHANGELOG.md)
484
+
485
+ ### Quick setup
486
+
487
+ ```bash
488
+ git clone https://github.com/tokenpak/tokenpak
489
+ cd tokenpak
490
+ pip install -e ".[dev]"
491
+ pytest tests/ -q
492
+ ```
493
+
494
+ ### Dual-remote push (required for CI)
495
+
496
+ TokenPak uses two remotes: `origin` (GitHub) and `shared` (internal QA). Always push with the verified script:
497
+
498
+ ```bash
499
+ bash scripts/push-verified.sh
500
+ ```
501
+
502
+ This pushes to both remotes and SSH-verifies the commit hash landed. **Never use bare `git push origin`** — the QA remote will be skipped.
503
+
504
+ ### Guidelines
505
+
506
+ - All new features need tests (`tests/test_<module>.py`)
507
+ - Keep CLI commands backward-compatible
508
+ - Compression recipes live in `recipes/oss/` as YAML
509
+ - Run `pytest tests/ -q` before opening a PR
510
+ - See [ARCHITECTURE.md](ARCHITECTURE.md) for system design
511
+ - See [CHANGELOG.md](CHANGELOG.md) for version history and release notes
512
+
513
+ ---
514
+
515
+ ## License
516
+
517
+ MIT — see [LICENSE](LICENSE)