artificial-intelligence-usage 0.0.7__tar.gz → 0.0.8__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.8}/PKG-INFO +4 -2
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/README.md +3 -1
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/pyproject.toml +1 -1
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.egg-info/PKG-INFO +4 -2
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.py +41 -2
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/tests/test_artificial_intelligence_usage.py +98 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/setup.cfg +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.egg-info/SOURCES.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.egg-info/dependency_links.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.egg-info/entry_points.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.egg-info/requires.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/src/artificial_intelligence_usage.egg-info/top_level.txt +0 -0
- {artificial_intelligence_usage-0.0.7 → artificial_intelligence_usage-0.0.8}/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.8
|
|
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.8
|
|
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,33 @@ 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 print_installed_tool_versions(
|
|
132
|
+
versions: dict[str, str], latest_versions: dict[str, str] | None = None
|
|
133
|
+
) -> None:
|
|
100
134
|
"""Print installed AI command-line tool versions when any are present."""
|
|
101
135
|
if not versions:
|
|
102
136
|
return
|
|
@@ -106,6 +140,8 @@ def print_installed_tool_versions(versions: dict[str, str]) -> None:
|
|
|
106
140
|
for name, _command in SUPPORTED_TOOLS:
|
|
107
141
|
if name in versions:
|
|
108
142
|
print(f"{name + ':':<16} {versions[name]}")
|
|
143
|
+
latest_version = (latest_versions or {}).get(name, "UNKNOWN")
|
|
144
|
+
print(f"{name + ' latest version:':<26} {latest_version}")
|
|
109
145
|
print()
|
|
110
146
|
|
|
111
147
|
|
|
@@ -570,6 +606,7 @@ def run_report(
|
|
|
570
606
|
tool_versions: dict[str, str] | None = None,
|
|
571
607
|
session_index_file: Path | None = None,
|
|
572
608
|
goals_database: Path | None = None,
|
|
609
|
+
latest_tool_versions: dict[str, str] | None = None,
|
|
573
610
|
) -> int:
|
|
574
611
|
"""Analyze sessions and print the status and daily usage report."""
|
|
575
612
|
current_day = today or date.today()
|
|
@@ -585,7 +622,9 @@ def run_report(
|
|
|
585
622
|
|
|
586
623
|
if tool_versions is None:
|
|
587
624
|
tool_versions = detect_installed_tool_versions()
|
|
588
|
-
|
|
625
|
+
if latest_tool_versions is None:
|
|
626
|
+
latest_tool_versions = detect_latest_tool_versions(tool_versions)
|
|
627
|
+
print_installed_tool_versions(tool_versions, latest_tool_versions)
|
|
589
628
|
|
|
590
629
|
codex_dir = sessions_dir.parent
|
|
591
630
|
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,18 @@ 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
191
|
self.assertIn("Codex: codex-cli 1.2.3", report)
|
|
192
|
+
self.assertIn("Codex latest version: 1.3.0", report)
|
|
139
193
|
self.assertIn("Claude: 2.0.1 (Claude Code)", report)
|
|
194
|
+
self.assertIn("Claude latest version: 2.1.0", report)
|
|
140
195
|
|
|
141
196
|
def test_analyze_session_ignores_malformed_lines_and_uses_maximum_tokens(self):
|
|
142
197
|
with tempfile.TemporaryDirectory() as directory:
|
|
@@ -311,6 +366,49 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
311
366
|
"09:08:07",
|
|
312
367
|
)
|
|
313
368
|
|
|
369
|
+
def test_analyze_session_skips_external_codex_apps_context_for_first_prompt(self):
|
|
370
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
371
|
+
session_file = Path(directory) / "rollout-test.jsonl"
|
|
372
|
+
events = [
|
|
373
|
+
{
|
|
374
|
+
"type": "response_item",
|
|
375
|
+
"payload": {
|
|
376
|
+
"type": "message",
|
|
377
|
+
"role": "user",
|
|
378
|
+
"content": [
|
|
379
|
+
{
|
|
380
|
+
"type": "input_text",
|
|
381
|
+
"text": (
|
|
382
|
+
"<external_codex_apps>Connected app context"
|
|
383
|
+
"</external_codex_apps>"
|
|
384
|
+
),
|
|
385
|
+
}
|
|
386
|
+
],
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
"type": "response_item",
|
|
391
|
+
"payload": {
|
|
392
|
+
"type": "message",
|
|
393
|
+
"role": "user",
|
|
394
|
+
"content": [
|
|
395
|
+
{
|
|
396
|
+
"type": "input_text",
|
|
397
|
+
"text": "Summarize the latest report.",
|
|
398
|
+
}
|
|
399
|
+
],
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
]
|
|
403
|
+
session_file.write_text(
|
|
404
|
+
"\n".join(json.dumps(event) for event in events) + "\n",
|
|
405
|
+
encoding="utf-8",
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
analysis = artificial_intelligence_usage.analyze_session(session_file)
|
|
409
|
+
|
|
410
|
+
self.assertEqual(analysis.first_prompt, "Summarize the latest report.")
|
|
411
|
+
|
|
314
412
|
def test_analyze_session_uses_only_a_terminal_task_completion_as_finish(self):
|
|
315
413
|
with tempfile.TemporaryDirectory() as directory:
|
|
316
414
|
root = Path(directory)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|