artificial-intelligence-usage 0.0.5__tar.gz → 0.0.7__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.5 → artificial_intelligence_usage-0.0.7}/PKG-INFO +6 -3
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/README.md +5 -2
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/pyproject.toml +1 -1
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.egg-info/PKG-INFO +6 -3
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.py +44 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/tests/test_artificial_intelligence_usage.py +59 -3
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/setup.cfg +0 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.egg-info/SOURCES.txt +0 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.egg-info/dependency_links.txt +0 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.egg-info/entry_points.txt +0 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.egg-info/requires.txt +0 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/src/artificial_intelligence_usage.egg-info/top_level.txt +0 -0
- {artificial_intelligence_usage-0.0.5 → artificial_intelligence_usage-0.0.7}/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.7
|
|
4
4
|
Summary: Analyze usage of artificial intelligence tool.
|
|
5
5
|
Author: Kaizten Analytics
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -27,8 +27,11 @@ latest session followed by daily and per-session prompt, token, and rate-limit u
|
|
|
27
27
|
include automatic goal continuations, while background tasks such as guardian
|
|
28
28
|
reviews are excluded.
|
|
29
29
|
- Shows a second table with one row per session, including its start time,
|
|
30
|
-
session name (up to 10 characters), first-prompt preview (up to
|
|
31
|
-
characters), GitHub repository, usage, and language.
|
|
30
|
+
finish time, session name (up to 10 characters), first-prompt preview (up to
|
|
31
|
+
20 characters), model, GitHub repository, usage, and language. When a session
|
|
32
|
+
records multiple models, the table shows the first one. A session is finished
|
|
33
|
+
when its final rollout event is `task_complete`; otherwise its finish value is
|
|
34
|
+
`In progress`.
|
|
32
35
|
- Reads session names from `~/.codex/session_index.jsonl`. Missing names and
|
|
33
36
|
prompts display as `Unknown`.
|
|
34
37
|
- For goal-only sessions, reads the goal objective from
|
|
@@ -15,8 +15,11 @@ latest session followed by daily and per-session prompt, token, and rate-limit u
|
|
|
15
15
|
include automatic goal continuations, while background tasks such as guardian
|
|
16
16
|
reviews are excluded.
|
|
17
17
|
- Shows a second table with one row per session, including its start time,
|
|
18
|
-
session name (up to 10 characters), first-prompt preview (up to
|
|
19
|
-
characters), GitHub repository, usage, and language.
|
|
18
|
+
finish time, session name (up to 10 characters), first-prompt preview (up to
|
|
19
|
+
20 characters), model, GitHub repository, usage, and language. When a session
|
|
20
|
+
records multiple models, the table shows the first one. A session is finished
|
|
21
|
+
when its final rollout event is `task_complete`; otherwise its finish value is
|
|
22
|
+
`In progress`.
|
|
20
23
|
- Reads session names from `~/.codex/session_index.jsonl`. Missing names and
|
|
21
24
|
prompts display as `Unknown`.
|
|
22
25
|
- For goal-only sessions, reads the goal objective from
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: artificial-intelligence-usage
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Analyze usage of artificial intelligence tool.
|
|
5
5
|
Author: Kaizten Analytics
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -27,8 +27,11 @@ latest session followed by daily and per-session prompt, token, and rate-limit u
|
|
|
27
27
|
include automatic goal continuations, while background tasks such as guardian
|
|
28
28
|
reviews are excluded.
|
|
29
29
|
- Shows a second table with one row per session, including its start time,
|
|
30
|
-
session name (up to 10 characters), first-prompt preview (up to
|
|
31
|
-
characters), GitHub repository, usage, and language.
|
|
30
|
+
finish time, session name (up to 10 characters), first-prompt preview (up to
|
|
31
|
+
20 characters), model, GitHub repository, usage, and language. When a session
|
|
32
|
+
records multiple models, the table shows the first one. A session is finished
|
|
33
|
+
when its final rollout event is `task_complete`; otherwise its finish value is
|
|
34
|
+
`In progress`.
|
|
32
35
|
- Reads session names from `~/.codex/session_index.jsonl`. Missing names and
|
|
33
36
|
prompts display as `Unknown`.
|
|
34
37
|
- For goal-only sessions, reads the goal objective from
|
|
@@ -42,9 +42,11 @@ class SessionAnalysis:
|
|
|
42
42
|
plan_prompts: int
|
|
43
43
|
goal_prompts: int
|
|
44
44
|
repository: str
|
|
45
|
+
model: str
|
|
45
46
|
language: str
|
|
46
47
|
session_id: str | None
|
|
47
48
|
first_prompt: str | None
|
|
49
|
+
finish: str
|
|
48
50
|
|
|
49
51
|
|
|
50
52
|
def positive_int(value: str) -> int:
|
|
@@ -122,6 +124,21 @@ def format_timestamp(value: str | int | float | None) -> str:
|
|
|
122
124
|
return "unknown"
|
|
123
125
|
|
|
124
126
|
|
|
127
|
+
def format_time(value: str | int | float | None) -> str:
|
|
128
|
+
"""Format an ISO or Unix timestamp as a local time."""
|
|
129
|
+
try:
|
|
130
|
+
if isinstance(value, str):
|
|
131
|
+
timestamp = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
132
|
+
elif isinstance(value, (int, float)):
|
|
133
|
+
timestamp = datetime.fromtimestamp(value).astimezone()
|
|
134
|
+
else:
|
|
135
|
+
return "Unknown"
|
|
136
|
+
|
|
137
|
+
return timestamp.astimezone().strftime("%H:%M:%S")
|
|
138
|
+
except (OverflowError, OSError, ValueError):
|
|
139
|
+
return "Unknown"
|
|
140
|
+
|
|
141
|
+
|
|
125
142
|
def format_window(minutes: Any) -> str:
|
|
126
143
|
"""Return a compact label for a rate-limit window."""
|
|
127
144
|
if not isinstance(minutes, (int, float)):
|
|
@@ -455,8 +472,11 @@ def analyze_session(session_file: Path) -> SessionAnalysis:
|
|
|
455
472
|
total_tokens = 0
|
|
456
473
|
prompt_counts: Counter[str] = Counter()
|
|
457
474
|
repository = "Unknown"
|
|
475
|
+
model = "Unknown"
|
|
458
476
|
session_id = None
|
|
459
477
|
first_prompt = None
|
|
478
|
+
last_event_is_task_complete = False
|
|
479
|
+
last_event_timestamp = None
|
|
460
480
|
|
|
461
481
|
with session_file.open("r", encoding="utf-8") as file_handle:
|
|
462
482
|
for line in file_handle:
|
|
@@ -466,6 +486,11 @@ def analyze_session(session_file: Path) -> SessionAnalysis:
|
|
|
466
486
|
continue
|
|
467
487
|
|
|
468
488
|
payload = event.get("payload") or {}
|
|
489
|
+
last_event_is_task_complete = (
|
|
490
|
+
event.get("type") == "event_msg"
|
|
491
|
+
and payload.get("type") == "task_complete"
|
|
492
|
+
)
|
|
493
|
+
last_event_timestamp = event.get("timestamp")
|
|
469
494
|
|
|
470
495
|
if event.get("type") == "session_meta":
|
|
471
496
|
candidate_session_id = payload.get("id") or payload.get("session_id")
|
|
@@ -474,6 +499,11 @@ def analyze_session(session_file: Path) -> SessionAnalysis:
|
|
|
474
499
|
git = payload.get("git") or {}
|
|
475
500
|
repository = github_repository(git.get("repository_url"))
|
|
476
501
|
|
|
502
|
+
if event.get("type") == "turn_context" and model == "Unknown":
|
|
503
|
+
candidate_model = payload.get("model")
|
|
504
|
+
if isinstance(candidate_model, str) and candidate_model:
|
|
505
|
+
model = candidate_model
|
|
506
|
+
|
|
477
507
|
if (
|
|
478
508
|
event.get("type") == "event_msg"
|
|
479
509
|
and payload.get("type") == "task_started"
|
|
@@ -509,9 +539,15 @@ def analyze_session(session_file: Path) -> SessionAnalysis:
|
|
|
509
539
|
plan_prompts=prompt_counts["plan"],
|
|
510
540
|
goal_prompts=prompt_counts["goal"],
|
|
511
541
|
repository=repository,
|
|
542
|
+
model=model,
|
|
512
543
|
language=detect_language(first_prompt),
|
|
513
544
|
session_id=session_id,
|
|
514
545
|
first_prompt=first_prompt,
|
|
546
|
+
finish=(
|
|
547
|
+
format_time(last_event_timestamp)
|
|
548
|
+
if last_event_is_task_complete
|
|
549
|
+
else "In progress"
|
|
550
|
+
),
|
|
515
551
|
)
|
|
516
552
|
|
|
517
553
|
|
|
@@ -660,12 +696,18 @@ def run_report(
|
|
|
660
696
|
len("Repository"),
|
|
661
697
|
*(len(analysis.repository) for _date, _path, analysis in session_rows),
|
|
662
698
|
)
|
|
699
|
+
model_width = max(
|
|
700
|
+
len("Model"),
|
|
701
|
+
*(len(analysis.model) for _date, _path, analysis in session_rows),
|
|
702
|
+
)
|
|
663
703
|
session_header = (
|
|
664
704
|
f"{'Date':<12} "
|
|
665
705
|
f"{'Start':<8} "
|
|
706
|
+
f"{'Finish':<11} "
|
|
666
707
|
f"{'Repository':<{repository_width}} "
|
|
667
708
|
f"{'Name':<10} "
|
|
668
709
|
f"{'First prompt':<20} "
|
|
710
|
+
f"{'Model':<{model_width}} "
|
|
669
711
|
f"{'Turns':>8} "
|
|
670
712
|
f"{'Normal':>8} "
|
|
671
713
|
f"{'Plan':>8} "
|
|
@@ -690,9 +732,11 @@ def run_report(
|
|
|
690
732
|
print(
|
|
691
733
|
f"{date_label:<12} "
|
|
692
734
|
f"{session_start_time(session_file):<8} "
|
|
735
|
+
f"{analysis.finish:<11} "
|
|
693
736
|
f"{analysis.repository:<{repository_width}} "
|
|
694
737
|
f"{session_name:<10} "
|
|
695
738
|
f"{prompt_preview:<20} "
|
|
739
|
+
f"{analysis.model:<{model_width}} "
|
|
696
740
|
f"{analysis.turns:>8} "
|
|
697
741
|
f"{analysis.normal_prompts:>8} "
|
|
698
742
|
f"{analysis.plan_prompts:>8} "
|
|
@@ -65,6 +65,13 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
65
65
|
},
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
def task_complete_event(self, timestamp: str = "2026-10-04T10:05:06") -> dict:
|
|
69
|
+
return {
|
|
70
|
+
"timestamp": timestamp,
|
|
71
|
+
"type": "event_msg",
|
|
72
|
+
"payload": {"type": "task_complete"},
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
def test_positive_int_accepts_positive_values(self):
|
|
69
76
|
self.assertEqual(artificial_intelligence_usage.positive_int("7"), 7)
|
|
70
77
|
|
|
@@ -159,9 +166,11 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
159
166
|
plan_prompts=0,
|
|
160
167
|
goal_prompts=0,
|
|
161
168
|
repository="Unknown",
|
|
169
|
+
model="Unknown",
|
|
162
170
|
language="Unknown",
|
|
163
171
|
session_id=None,
|
|
164
172
|
first_prompt=None,
|
|
173
|
+
finish="In progress",
|
|
165
174
|
),
|
|
166
175
|
)
|
|
167
176
|
|
|
@@ -215,9 +224,11 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
215
224
|
plan_prompts=1,
|
|
216
225
|
goal_prompts=1,
|
|
217
226
|
repository="Unknown",
|
|
227
|
+
model="Unknown",
|
|
218
228
|
language="Unknown",
|
|
219
229
|
session_id=None,
|
|
220
230
|
first_prompt=None,
|
|
231
|
+
finish="In progress",
|
|
221
232
|
),
|
|
222
233
|
)
|
|
223
234
|
|
|
@@ -237,6 +248,8 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
237
248
|
}
|
|
238
249
|
},
|
|
239
250
|
},
|
|
251
|
+
{"type": "turn_context", "payload": {"model": "gpt-test"}},
|
|
252
|
+
{"type": "turn_context", "payload": {"model": "gpt-later"}},
|
|
240
253
|
{
|
|
241
254
|
"type": "response_item",
|
|
242
255
|
"payload": {
|
|
@@ -285,6 +298,7 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
285
298
|
analysis = artificial_intelligence_usage.analyze_session(session_file)
|
|
286
299
|
|
|
287
300
|
self.assertEqual(analysis.repository, "kaizten/example")
|
|
301
|
+
self.assertEqual(analysis.model, "gpt-test")
|
|
288
302
|
self.assertEqual(analysis.language, "Spanish")
|
|
289
303
|
self.assertEqual(analysis.session_id, "session-example")
|
|
290
304
|
self.assertEqual(
|
|
@@ -297,6 +311,45 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
297
311
|
"09:08:07",
|
|
298
312
|
)
|
|
299
313
|
|
|
314
|
+
def test_analyze_session_uses_only_a_terminal_task_completion_as_finish(self):
|
|
315
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
316
|
+
root = Path(directory)
|
|
317
|
+
completed_session = root / "rollout-completed.jsonl"
|
|
318
|
+
completed_session.write_text(
|
|
319
|
+
json.dumps(self.task_complete_event("2026-10-04T12:34:56"))
|
|
320
|
+
+ "\nnot-json\n",
|
|
321
|
+
encoding="utf-8",
|
|
322
|
+
)
|
|
323
|
+
active_session = root / "rollout-active.jsonl"
|
|
324
|
+
active_session.write_text(
|
|
325
|
+
json.dumps(self.task_complete_event())
|
|
326
|
+
+ "\n"
|
|
327
|
+
+ json.dumps(
|
|
328
|
+
{
|
|
329
|
+
"timestamp": "2026-10-04T10:06:00",
|
|
330
|
+
"type": "event_msg",
|
|
331
|
+
"payload": {"type": "task_started"},
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
+ "\n",
|
|
335
|
+
encoding="utf-8",
|
|
336
|
+
)
|
|
337
|
+
invalid_session = root / "rollout-invalid.jsonl"
|
|
338
|
+
invalid_session.write_text(
|
|
339
|
+
json.dumps(self.task_complete_event("not-a-timestamp")) + "\n",
|
|
340
|
+
encoding="utf-8",
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
completed = artificial_intelligence_usage.analyze_session(
|
|
344
|
+
completed_session
|
|
345
|
+
)
|
|
346
|
+
active = artificial_intelligence_usage.analyze_session(active_session)
|
|
347
|
+
invalid = artificial_intelligence_usage.analyze_session(invalid_session)
|
|
348
|
+
|
|
349
|
+
self.assertEqual(completed.finish, "12:34:56")
|
|
350
|
+
self.assertEqual(active.finish, "In progress")
|
|
351
|
+
self.assertEqual(invalid.finish, "Unknown")
|
|
352
|
+
|
|
300
353
|
def test_github_repository_supports_https_and_rejects_other_hosts(self):
|
|
301
354
|
self.assertEqual(
|
|
302
355
|
artificial_intelligence_usage.github_repository(
|
|
@@ -480,6 +533,7 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
480
533
|
plan_prompt,
|
|
481
534
|
goal_prompt,
|
|
482
535
|
self.token_event(100),
|
|
536
|
+
self.task_complete_event(),
|
|
483
537
|
],
|
|
484
538
|
)
|
|
485
539
|
self.write_session(
|
|
@@ -524,16 +578,18 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
524
578
|
self.assertIn("70% remaining", report)
|
|
525
579
|
self.assertIn("55% remaining", report)
|
|
526
580
|
self.assertIn("Sessions", report)
|
|
581
|
+
self.assertRegex(report, r"Start\s+Finish\s+Repository")
|
|
527
582
|
self.assertIn("Name", report)
|
|
528
583
|
self.assertIn("First prompt", report)
|
|
584
|
+
self.assertRegex(report, r"First prompt\s+Model\s+Turns")
|
|
529
585
|
self.assertIn("Repository", report)
|
|
530
586
|
self.assertRegex(
|
|
531
587
|
report,
|
|
532
|
-
r"2026-10-04\s+09:00:00\s+kaizten/example\s+Updated se\s+Please update the us\s+1\s+1\s+1\s+1\s+English\s+100",
|
|
588
|
+
r"2026-10-04\s+09:00:00\s+10:05:06\s+kaizten/example\s+Updated se\s+Please update the us\s+gpt-test\s+1\s+1\s+1\s+1\s+English\s+100",
|
|
533
589
|
)
|
|
534
590
|
self.assertRegex(
|
|
535
591
|
report,
|
|
536
|
-
r"2026-10-04\s+10:00:00\s+Unknown\s+Unknown\s+Please update the us\s+2\s+1\s+0\s+0\s+English\s+250",
|
|
592
|
+
r"2026-10-04\s+10:00:00\s+In progress\s+Unknown\s+Unknown\s+Please update the us\s+Unknown\s+2\s+1\s+0\s+0\s+English\s+250",
|
|
537
593
|
)
|
|
538
594
|
self.assertLess(report.index("09:00:00"), report.index("10:00:00"))
|
|
539
595
|
daily_report = report[report.index("Date") :]
|
|
@@ -589,7 +645,7 @@ class ArtificialIntelligenceUsageTests(unittest.TestCase):
|
|
|
589
645
|
session_table = output.getvalue()[output.getvalue().index("Sessions") :]
|
|
590
646
|
self.assertRegex(
|
|
591
647
|
session_table,
|
|
592
|
-
r"11:00:00\s+Unknown\s+Unknown\s+Run the existing tes\s+0\s+0\s+0\s+1\s+Unknown\s+75",
|
|
648
|
+
r"11:00:00\s+In progress\s+Unknown\s+Unknown\s+Run the existing tes\s+Unknown\s+0\s+0\s+0\s+1\s+Unknown\s+75",
|
|
593
649
|
)
|
|
594
650
|
|
|
595
651
|
def test_main_can_be_called_repeatedly(self):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|