cli-usereq 0.68.0__py3-none-any.whl

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 (37) hide show
  1. cli_usereq-0.68.0.dist-info/METADATA +1134 -0
  2. cli_usereq-0.68.0.dist-info/RECORD +37 -0
  3. cli_usereq-0.68.0.dist-info/WHEEL +5 -0
  4. cli_usereq-0.68.0.dist-info/entry_points.txt +4 -0
  5. cli_usereq-0.68.0.dist-info/licenses/LICENSE +674 -0
  6. cli_usereq-0.68.0.dist-info/top_level.txt +1 -0
  7. usereq/__init__.py +62 -0
  8. usereq/__main__.py +17 -0
  9. usereq/cli.py +4963 -0
  10. usereq/compress.py +393 -0
  11. usereq/compress_files.py +134 -0
  12. usereq/doxygen_parser.py +172 -0
  13. usereq/find_constructs.py +394 -0
  14. usereq/generate_markdown.py +158 -0
  15. usereq/resources/docs/Document_Source_Code_in_Doxygen_Style.md +130 -0
  16. usereq/resources/docs/HDT_Test_Authoring_Guide.md +318 -0
  17. usereq/resources/docs/Requirements_Template.md +78 -0
  18. usereq/resources/prompts/analyze.md +191 -0
  19. usereq/resources/prompts/change.md +279 -0
  20. usereq/resources/prompts/check.md +190 -0
  21. usereq/resources/prompts/cover.md +271 -0
  22. usereq/resources/prompts/create.md +134 -0
  23. usereq/resources/prompts/fix.md +273 -0
  24. usereq/resources/prompts/flowchart.md +272 -0
  25. usereq/resources/prompts/implement.md +194 -0
  26. usereq/resources/prompts/new.md +278 -0
  27. usereq/resources/prompts/readme.md +234 -0
  28. usereq/resources/prompts/recreate.md +265 -0
  29. usereq/resources/prompts/refactor.md +265 -0
  30. usereq/resources/prompts/references.md +131 -0
  31. usereq/resources/prompts/renumber.md +150 -0
  32. usereq/resources/prompts/workflow.md +254 -0
  33. usereq/resources/prompts/write.md +129 -0
  34. usereq/resources/prompts-version.txt +1 -0
  35. usereq/source_analyzer.py +2280 -0
  36. usereq/static_check.py +812 -0
  37. usereq/token_counter.py +123 -0
@@ -0,0 +1,123 @@
1
+ """!
2
+ @file token_counter.py
3
+ @brief Token and character counting for generated output.
4
+ @details Uses tiktoken for accurate token counting compatible with OpenAI/Claude models.
5
+ @author GitHub Copilot
6
+ @version 0.0.70
7
+ """
8
+
9
+ import os
10
+
11
+ import tiktoken # pyright: ignore[reportMissingImports]
12
+
13
+
14
+ class TokenCounter:
15
+ """! @brief Count tokens using tiktoken encoding (cl100k_base by default).
16
+ @details Wrapper around tiktoken encoding to simplify token counting operations.
17
+ """
18
+
19
+ def __init__(self, encoding_name: str = "cl100k_base"):
20
+ """!
21
+ @brief Initialize token counter with a specific tiktoken encoding.
22
+ @param encoding_name Name of tiktoken encoding used for tokenization.
23
+ @details Implements the __init__ function behavior with deterministic control flow.
24
+ @return {None} Function return value.
25
+ """
26
+ self.encoding = tiktoken.get_encoding(encoding_name)
27
+
28
+ def count_tokens(self, content: str) -> int:
29
+ """! @brief Count tokens in content string.
30
+ @param content The text content to tokenize.
31
+ @return Integer count of tokens.
32
+ @details Uses `disallowed_special=()` to allow special tokens in input without raising errors. Returns 0 on failure.
33
+ """
34
+ try:
35
+ return len(self.encoding.encode(content, disallowed_special=()))
36
+ except Exception:
37
+ return 0
38
+
39
+ @staticmethod
40
+ def count_chars(content: str) -> int:
41
+ """!
42
+ @brief Count characters in content string.
43
+ @param content The text string.
44
+ @return Integer count of characters.
45
+ @details Implements the count_chars function behavior with deterministic control flow.
46
+ """
47
+ return len(content)
48
+
49
+
50
+ def count_file_metrics(content: str,
51
+ encoding_name: str = "cl100k_base") -> dict:
52
+ """!
53
+ @brief Count tokens and chars for a content string.
54
+ @param content The text content to measure.
55
+ @param encoding_name The tiktoken encoding name (default: "cl100k_base").
56
+ @return Dictionary with keys 'tokens' (int) and 'chars' (int).
57
+ @details Implements the count_file_metrics function behavior with deterministic control flow.
58
+ """
59
+ counter = TokenCounter(encoding_name)
60
+ return {
61
+ "tokens": counter.count_tokens(content),
62
+ "chars": TokenCounter.count_chars(content),
63
+ }
64
+
65
+
66
+ def count_files_metrics(file_paths: list,
67
+ encoding_name: str = "cl100k_base") -> list:
68
+ """! @brief Count tokens and chars for a list of files.
69
+ @param file_paths List of file paths to process.
70
+ @param encoding_name The tiktoken encoding name.
71
+ @return List of dictionaries, each containing 'file', 'tokens', 'chars', and optionally 'error'.
72
+ @details Iterates through files, reading content and counting metrics. Gracefully handles read errors.
73
+ """
74
+ counter = TokenCounter(encoding_name)
75
+ results = []
76
+ for path in file_paths:
77
+ try:
78
+ with open(path, "r", encoding="utf-8", errors="replace") as f:
79
+ content = f.read()
80
+ results.append({
81
+ "file": path,
82
+ "tokens": counter.count_tokens(content),
83
+ "chars": counter.count_chars(content),
84
+ })
85
+ except Exception as e:
86
+ results.append({
87
+ "file": path,
88
+ "tokens": 0,
89
+ "chars": 0,
90
+ "error": str(e),
91
+ })
92
+ return results
93
+
94
+
95
+ def format_pack_summary(results: list) -> str:
96
+ """! @brief Format a pack summary string from a list of file metrics.
97
+ @param results List of metrics dictionaries from count_files_metrics().
98
+ @return Formatted summary string with per-file details and totals.
99
+ @details Generates a human-readable report including icons, per-file stats, and aggregate totals.
100
+ """
101
+ lines = []
102
+ total_tokens = 0
103
+ total_chars = 0
104
+ total_files = len(results)
105
+
106
+ for r in results:
107
+ fname = os.path.basename(r["file"])
108
+ tokens = r["tokens"]
109
+ chars = r["chars"]
110
+ total_tokens += tokens
111
+ total_chars += chars
112
+ if "error" in r:
113
+ lines.append(f" ❌ {fname}: ERROR - {r['error']}")
114
+ else:
115
+ lines.append(f" 📄 {fname}: {tokens:,} tokens, {chars:,} chars")
116
+
117
+ lines.append("")
118
+ lines.append("📊 Pack Summary:")
119
+ lines.append("────────────────")
120
+ lines.append(f" Total Files: {total_files} files")
121
+ lines.append(f" Total Tokens: {total_tokens:,} tokens")
122
+ lines.append(f" Total Chars: {total_chars:,} chars")
123
+ return "\n".join(lines)