artificial-intelligence-usage 0.0.7__tar.gz → 0.0.9__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.
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/PKG-INFO +4 -2
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/README.md +3 -1
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/pyproject.toml +1 -1
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.egg-info/PKG-INFO +4 -2
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.py +68 -3
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/tests/test_artificial_intelligence_usage.py +121 -2
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/setup.cfg +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.egg-info/SOURCES.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.egg-info/dependency_links.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.egg-info/entry_points.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.egg-info/requires.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/src/artificial_intelligence_usage.egg-info/top_level.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.9}/tests/test_publish_pypi.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: artificial-intelligence-usage
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.9
|
|
4
4
|
Summary: Analyze usage of artificial intelligence tool.
|
|
5
5
|
Author: Kaizten Analytics
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -19,7 +19,9 @@ latest session followed by daily and per-session prompt, token, and rate-limit u
|
|
|
19
19
|
|
|
20
20
|
- Reads rollout files below `~/.codex/sessions`.
|
|
21
21
|
- Shows the installed Codex and Claude CLI versions when those commands are
|
|
22
|
-
available
|
|
22
|
+
available, followed by the latest versions published under their official
|
|
23
|
+
npm packages. Latest-version checks require network access and display
|
|
24
|
+
`UNKNOWN` when a lookup fails.
|
|
23
25
|
- Shows status details from the most recently modified session.
|
|
24
26
|
- Reports sessions from the last 14 calendar days by default, including today.
|
|
25
27
|
- Counts user turns and cumulative tokens for each session.
|
|
@@ -7,7 +7,9 @@ latest session followed by daily and per-session prompt, token, and rate-limit u
|
|
|
7
7
|
|
|
8
8
|
- Reads rollout files below `~/.codex/sessions`.
|
|
9
9
|
- Shows the installed Codex and Claude CLI versions when those commands are
|
|
10
|
-
available
|
|
10
|
+
available, followed by the latest versions published under their official
|
|
11
|
+
npm packages. Latest-version checks require network access and display
|
|
12
|
+
`UNKNOWN` when a lookup fails.
|
|
11
13
|
- Shows status details from the most recently modified session.
|
|
12
14
|
- Reports sessions from the last 14 calendar days by default, including today.
|
|
13
15
|
- Counts user turns and cumulative tokens for each session.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: artificial-intelligence-usage
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.9
|
|
4
4
|
Summary: Analyze usage of artificial intelligence tool.
|
|
5
5
|
Author: Kaizten Analytics
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -19,7 +19,9 @@ latest session followed by daily and per-session prompt, token, and rate-limit u
|
|
|
19
19
|
|
|
20
20
|
- Reads rollout files below `~/.codex/sessions`.
|
|
21
21
|
- Shows the installed Codex and Claude CLI versions when those commands are
|
|
22
|
-
available
|
|
22
|
+
available, followed by the latest versions published under their official
|
|
23
|
+
npm packages. Latest-version checks require network access and display
|
|
24
|
+
`UNKNOWN` when a lookup fails.
|
|
23
25
|
- Shows status details from the most recently modified session.
|
|
24
26
|
- Reports sessions from the last 14 calendar days by default, including today.
|
|
25
27
|
- Counts user turns and cumulative tokens for each session.
|
|
@@ -9,6 +9,8 @@ import re
|
|
|
9
9
|
import shutil
|
|
10
10
|
import sqlite3
|
|
11
11
|
import subprocess
|
|
12
|
+
import urllib.error
|
|
13
|
+
import urllib.request
|
|
12
14
|
from collections import Counter, defaultdict
|
|
13
15
|
from dataclasses import dataclass
|
|
14
16
|
from datetime import date, datetime, timedelta
|
|
@@ -20,9 +22,15 @@ import langid
|
|
|
20
22
|
|
|
21
23
|
DEFAULT_DAYS = 14
|
|
22
24
|
SUPPORTED_TOOLS = (("Codex", "codex"), ("Claude", "claude"))
|
|
25
|
+
NPM_PACKAGES = {
|
|
26
|
+
"Codex": "@openai/codex",
|
|
27
|
+
"Claude": "@anthropic-ai/claude-code",
|
|
28
|
+
}
|
|
29
|
+
NPM_REGISTRY_TIMEOUT = 3
|
|
23
30
|
INTERNAL_USER_TEXT_TAGS = {
|
|
24
31
|
"codex_internal_context",
|
|
25
32
|
"environment_context",
|
|
33
|
+
"external_codex_apps",
|
|
26
34
|
"goal",
|
|
27
35
|
"goals",
|
|
28
36
|
"guardian_tool_descriptions",
|
|
@@ -96,7 +104,51 @@ def detect_installed_tool_versions() -> dict[str, str]:
|
|
|
96
104
|
return versions
|
|
97
105
|
|
|
98
106
|
|
|
99
|
-
def
|
|
107
|
+
def latest_tool_version(package: str) -> str:
|
|
108
|
+
"""Return the latest npm version for a package, or ``UNKNOWN`` on failure."""
|
|
109
|
+
package_path = package.replace("/", "%2f")
|
|
110
|
+
url = f"https://registry.npmjs.org/{package_path}/latest"
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
with urllib.request.urlopen(url, timeout=NPM_REGISTRY_TIMEOUT) as response:
|
|
114
|
+
metadata = json.loads(response.read())
|
|
115
|
+
except (OSError, TimeoutError, ValueError, urllib.error.URLError):
|
|
116
|
+
return "UNKNOWN"
|
|
117
|
+
|
|
118
|
+
version = metadata.get("version") if isinstance(metadata, dict) else None
|
|
119
|
+
return version.strip() if isinstance(version, str) and version.strip() else "UNKNOWN"
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def detect_latest_tool_versions(installed_versions: dict[str, str]) -> dict[str, str]:
|
|
123
|
+
"""Return latest npm versions for the tools that are currently installed."""
|
|
124
|
+
return {
|
|
125
|
+
name: latest_tool_version(NPM_PACKAGES[name])
|
|
126
|
+
for name in installed_versions
|
|
127
|
+
if name in NPM_PACKAGES
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def version_key(output: str) -> tuple | None:
|
|
132
|
+
"""Extract a semantic version and return its precedence key, if available."""
|
|
133
|
+
for token in output.split():
|
|
134
|
+
match = re.fullmatch(
|
|
135
|
+
r"v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?"
|
|
136
|
+
r"(?:\+[0-9A-Za-z.-]+)?",
|
|
137
|
+
token,
|
|
138
|
+
)
|
|
139
|
+
if match:
|
|
140
|
+
major, minor, patch, prerelease = match.groups()
|
|
141
|
+
identifiers = tuple(
|
|
142
|
+
(0, int(part)) if part.isdigit() else (1, part)
|
|
143
|
+
for part in prerelease.split(".")
|
|
144
|
+
) if prerelease else ()
|
|
145
|
+
return (int(major), int(minor), int(patch), bool(not prerelease), identifiers)
|
|
146
|
+
return None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def print_installed_tool_versions(
|
|
150
|
+
versions: dict[str, str], latest_versions: dict[str, str] | None = None
|
|
151
|
+
) -> None:
|
|
100
152
|
"""Print installed AI command-line tool versions when any are present."""
|
|
101
153
|
if not versions:
|
|
102
154
|
return
|
|
@@ -105,7 +157,17 @@ def print_installed_tool_versions(versions: dict[str, str]) -> None:
|
|
|
105
157
|
print("-" * 57)
|
|
106
158
|
for name, _command in SUPPORTED_TOOLS:
|
|
107
159
|
if name in versions:
|
|
108
|
-
|
|
160
|
+
latest_version = (latest_versions or {}).get(name, "UNKNOWN")
|
|
161
|
+
installed_key = version_key(versions[name])
|
|
162
|
+
latest_key = version_key(latest_version)
|
|
163
|
+
upgrade = (
|
|
164
|
+
" It must be upgraded"
|
|
165
|
+
if installed_key is not None and latest_key is not None
|
|
166
|
+
and latest_key > installed_key
|
|
167
|
+
else ""
|
|
168
|
+
)
|
|
169
|
+
print(f"{name + ':':<16} {versions[name]}{upgrade}")
|
|
170
|
+
print(f"{name + ' latest version:':<26} {latest_version}")
|
|
109
171
|
print()
|
|
110
172
|
|
|
111
173
|
|
|
@@ -570,6 +632,7 @@ def run_report(
|
|
|
570
632
|
tool_versions: dict[str, str] | None = None,
|
|
571
633
|
session_index_file: Path | None = None,
|
|
572
634
|
goals_database: Path | None = None,
|
|
635
|
+
latest_tool_versions: dict[str, str] | None = None,
|
|
573
636
|
) -> int:
|
|
574
637
|
"""Analyze sessions and print the status and daily usage report."""
|
|
575
638
|
current_day = today or date.today()
|
|
@@ -585,7 +648,9 @@ def run_report(
|
|
|
585
648
|
|
|
586
649
|
if tool_versions is None:
|
|
587
650
|
tool_versions = detect_installed_tool_versions()
|
|
588
|
-
|
|
651
|
+
if latest_tool_versions is None:
|
|
652
|
+
latest_tool_versions = detect_latest_tool_versions(tool_versions)
|
|
653
|
+
print_installed_tool_versions(tool_versions, latest_tool_versions)
|
|
589
654
|
|
|
590
655
|
codex_dir = sessions_dir.parent
|
|
591
656
|
session_names = read_session_names(
|
|
@@ -119,6 +119,55 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
119
119
|
timeout=5,
|
|
120
120
|
)
|
|
121
121
|
|
|
122
|
+
def test_latest_tool_version_reads_npm_latest_metadata(self):
|
|
123
|
+
response = io.BytesIO(b'{"version":"1.2.3"}')
|
|
124
|
+
with patch.object(
|
|
125
|
+
artificial_intelligence_usage.urllib.request,
|
|
126
|
+
"urlopen",
|
|
127
|
+
return_value=response,
|
|
128
|
+
) as urlopen:
|
|
129
|
+
version = artificial_intelligence_usage.latest_tool_version(
|
|
130
|
+
"@openai/codex"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
self.assertEqual(version, "1.2.3")
|
|
134
|
+
urlopen.assert_called_once_with(
|
|
135
|
+
"https://registry.npmjs.org/@openai%2fcodex/latest",
|
|
136
|
+
timeout=3,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def test_latest_tool_version_returns_unknown_when_lookup_fails(self):
|
|
140
|
+
cases = (
|
|
141
|
+
OSError("offline"),
|
|
142
|
+
ValueError("invalid JSON"),
|
|
143
|
+
)
|
|
144
|
+
for error in cases:
|
|
145
|
+
with self.subTest(error=error), patch.object(
|
|
146
|
+
artificial_intelligence_usage.urllib.request,
|
|
147
|
+
"urlopen",
|
|
148
|
+
side_effect=error,
|
|
149
|
+
):
|
|
150
|
+
self.assertEqual(
|
|
151
|
+
artificial_intelligence_usage.latest_tool_version(
|
|
152
|
+
"@anthropic-ai/claude-code"
|
|
153
|
+
),
|
|
154
|
+
"UNKNOWN",
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
def test_latest_tool_version_returns_unknown_for_missing_version(self):
|
|
158
|
+
response = io.BytesIO(b'{"name":"@openai/codex"}')
|
|
159
|
+
with patch.object(
|
|
160
|
+
artificial_intelligence_usage.urllib.request,
|
|
161
|
+
"urlopen",
|
|
162
|
+
return_value=response,
|
|
163
|
+
):
|
|
164
|
+
self.assertEqual(
|
|
165
|
+
artificial_intelligence_usage.latest_tool_version(
|
|
166
|
+
"@openai/codex"
|
|
167
|
+
),
|
|
168
|
+
"UNKNOWN",
|
|
169
|
+
)
|
|
170
|
+
|
|
122
171
|
def test_report_includes_installed_codex_and_claude_versions(self):
|
|
123
172
|
with tempfile.TemporaryDirectory() as directory:
|
|
124
173
|
output = io.StringIO()
|
|
@@ -131,12 +180,39 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
131
180
|
"Codex": "codex-cli 1.2.3",
|
|
132
181
|
"Claude": "2.0.1 (Claude Code)",
|
|
133
182
|
},
|
|
183
|
+
latest_tool_versions={
|
|
184
|
+
"Codex": "1.3.0",
|
|
185
|
+
"Claude": "2.1.0",
|
|
186
|
+
},
|
|
134
187
|
)
|
|
135
188
|
|
|
136
189
|
report = output.getvalue()
|
|
137
190
|
self.assertIn("Installed AI tools", report)
|
|
138
|
-
self.assertIn("Codex: codex-cli 1.2.3", report)
|
|
139
|
-
self.assertIn("
|
|
191
|
+
self.assertIn("Codex: codex-cli 1.2.3 It must be upgraded", report)
|
|
192
|
+
self.assertIn("Codex latest version: 1.3.0", report)
|
|
193
|
+
self.assertIn("Claude: 2.0.1 (Claude Code) It must be upgraded", report)
|
|
194
|
+
self.assertIn("Claude latest version: 2.1.0", report)
|
|
195
|
+
|
|
196
|
+
def test_upgrade_message_requires_a_newer_known_version(self):
|
|
197
|
+
cases = (
|
|
198
|
+
("codex-cli 0.170.0", "0.172.0", True),
|
|
199
|
+
("codex-cli 0.9.0", "0.10.0", True),
|
|
200
|
+
("codex-cli 1.0.0-rc.2", "1.0.0-rc.10", True),
|
|
201
|
+
("codex-cli 1.0.0-rc.1", "1.0.0", True),
|
|
202
|
+
("codex-cli 1.0.0", "1.0.0-rc.1", False),
|
|
203
|
+
("codex-cli 1.0.0", "1.0.0", False),
|
|
204
|
+
("codex-cli 2.0.0", "1.9.0", False),
|
|
205
|
+
("unknown", "1.0.0", False),
|
|
206
|
+
("codex-cli 1.0.0", "UNKNOWN", False),
|
|
207
|
+
)
|
|
208
|
+
for installed, latest, expected in cases:
|
|
209
|
+
with self.subTest(installed=installed, latest=latest):
|
|
210
|
+
output = io.StringIO()
|
|
211
|
+
with contextlib.redirect_stdout(output):
|
|
212
|
+
artificial_intelligence_usage.print_installed_tool_versions(
|
|
213
|
+
{"Codex": installed}, {"Codex": latest}
|
|
214
|
+
)
|
|
215
|
+
self.assertEqual("It must be upgraded" in output.getvalue(), expected)
|
|
140
216
|
|
|
141
217
|
def test_analyze_session_ignores_malformed_lines_and_uses_maximum_tokens(self):
|
|
142
218
|
with tempfile.TemporaryDirectory() as directory:
|
|
@@ -311,6 +387,49 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
311
387
|
"09:08:07",
|
|
312
388
|
)
|
|
313
389
|
|
|
390
|
+
def test_analyze_session_skips_external_codex_apps_context_for_first_prompt(self):
|
|
391
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
392
|
+
session_file = Path(directory) / "rollout-test.jsonl"
|
|
393
|
+
events = [
|
|
394
|
+
{
|
|
395
|
+
"type": "response_item",
|
|
396
|
+
"payload": {
|
|
397
|
+
"type": "message",
|
|
398
|
+
"role": "user",
|
|
399
|
+
"content": [
|
|
400
|
+
{
|
|
401
|
+
"type": "input_text",
|
|
402
|
+
"text": (
|
|
403
|
+
"<external_codex_apps>Connected app context"
|
|
404
|
+
"</external_codex_apps>"
|
|
405
|
+
),
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
"type": "response_item",
|
|
412
|
+
"payload": {
|
|
413
|
+
"type": "message",
|
|
414
|
+
"role": "user",
|
|
415
|
+
"content": [
|
|
416
|
+
{
|
|
417
|
+
"type": "input_text",
|
|
418
|
+
"text": "Summarize the latest report.",
|
|
419
|
+
}
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
]
|
|
424
|
+
session_file.write_text(
|
|
425
|
+
"\n".join(json.dumps(event) for event in events) + "\n",
|
|
426
|
+
encoding="utf-8",
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
analysis = artificial_intelligence_usage.analyze_session(session_file)
|
|
430
|
+
|
|
431
|
+
self.assertEqual(analysis.first_prompt, "Summarize the latest report.")
|
|
432
|
+
|
|
314
433
|
def test_analyze_session_uses_only_a_terminal_task_completion_as_finish(self):
|
|
315
434
|
with tempfile.TemporaryDirectory() as directory:
|
|
316
435
|
root = Path(directory)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|