netra-zen 1.2.0__py3-none-any.whl → 1.2.1__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.
@@ -1,146 +1,146 @@
1
- #!/usr/bin/env python3
2
- """
3
- Demonstration of log collection from .claude/Projects
4
-
5
- This script shows how the zen --apex --send-logs functionality works
6
- """
7
- import sys
8
- from pathlib import Path
9
- import json
10
-
11
- # Add parent to path for imports
12
- sys.path.insert(0, str(Path(__file__).parent.parent))
13
-
14
- from scripts.agent_logs import collect_recent_logs
15
-
16
-
17
- def demo_log_collection():
18
- """Demonstrate log collection with various scenarios"""
19
-
20
- print("=" * 60)
21
- print("Zen Apex Log Collection Demo")
22
- print("=" * 60)
23
- print()
24
-
25
- # Check if .claude/Projects exists
26
- claude_path = Path.home() / ".claude" / "Projects"
27
-
28
- if not claude_path.exists():
29
- print("❌ .claude/Projects does not exist")
30
- print(f" Expected location: {claude_path}")
31
- print()
32
- print("Creating test directory...")
33
- claude_path.mkdir(parents=True, exist_ok=True)
34
- test_project = claude_path / "demo-project"
35
- test_project.mkdir(exist_ok=True)
36
-
37
- # Create sample log
38
- sample_log = {
39
- "type": "demo_event",
40
- "timestamp": "2025-01-08T12:00:00",
41
- "message": "This is a demo log entry",
42
- "data": {"key": "value"}
43
- }
44
- (test_project / "demo-session.jsonl").write_text(json.dumps(sample_log) + "\n")
45
- print(f"✅ Created demo project at {test_project}")
46
- print()
47
-
48
- # Scenario 1: Collect with defaults
49
- print("Scenario 1: Collect logs with defaults (limit=1, auto-detect project)")
50
- print("-" * 60)
51
- logs = collect_recent_logs(limit=1)
52
-
53
- if logs:
54
- print(f"✅ Collected {len(logs)} log entries")
55
- print(f" Total entries: {len(logs)}")
56
- print()
57
- print(" Sample entry (first):")
58
- print(f" {json.dumps(logs[0], indent=4)}")
59
- else:
60
- print("⚠️ No logs found")
61
- print(" Tip: Run Claude Code with some commands to generate logs")
62
- print()
63
-
64
- # Scenario 2: List available projects
65
- print("Scenario 2: List available projects")
66
- print("-" * 60)
67
- if claude_path.exists():
68
- projects = [p for p in claude_path.iterdir() if p.is_dir()]
69
- if projects:
70
- print(f"Found {len(projects)} project(s):")
71
- for proj in sorted(projects, key=lambda p: p.stat().st_mtime, reverse=True):
72
- jsonl_count = len(list(proj.glob("*.jsonl")))
73
- mtime = proj.stat().st_mtime
74
- from datetime import datetime
75
- mtime_str = datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M:%S")
76
- marker = " ← most recent" if proj == projects[0] else ""
77
- print(f" • {proj.name}: {jsonl_count} .jsonl files (modified: {mtime_str}){marker}")
78
- else:
79
- print(" No projects found")
80
- print()
81
-
82
- # Scenario 3: Collect from specific project
83
- if claude_path.exists():
84
- projects = [p for p in claude_path.iterdir() if p.is_dir()]
85
- if projects:
86
- specific_project = projects[0].name
87
- print(f"Scenario 3: Collect from specific project '{specific_project}'")
88
- print("-" * 60)
89
- logs = collect_recent_logs(limit=3, project_name=specific_project)
90
- if logs:
91
- print(f"✅ Collected {len(logs)} entries from '{specific_project}'")
92
- print(f" Entry types: {[log.get('type', 'unknown') for log in logs[:3]]}")
93
- else:
94
- print(f"⚠️ No logs in '{specific_project}'")
95
- print()
96
-
97
- # Scenario 4: Show what would be sent with --send-logs
98
- print("Scenario 4: What gets sent with 'zen --apex --send-logs --message \"..\"'")
99
- print("-" * 60)
100
- logs = collect_recent_logs(limit=1)
101
- if logs:
102
- payload_preview = {
103
- "type": "user_message",
104
- "payload": {
105
- "content": "your message here",
106
- "run_id": "cli_20250108_120000_12345",
107
- "thread_id": "cli_thread_abc123def456",
108
- "timestamp": "2025-01-08T12:00:00",
109
- "jsonl_logs": logs # This is what gets attached
110
- }
111
- }
112
- print("Payload structure:")
113
- print(json.dumps(payload_preview, indent=2)[:500] + "...")
114
- print()
115
- print(f"✅ {len(logs)} log entries would be attached to the message")
116
- else:
117
- print("⚠️ No logs would be attached (none found)")
118
- print()
119
-
120
- # Summary
121
- print("=" * 60)
122
- print("Summary")
123
- print("=" * 60)
124
- print()
125
- print("To use log forwarding with zen --apex:")
126
- print()
127
- print(" # Basic usage (default: 1 log file for best results)")
128
- print(" zen --apex --send-logs --message \"analyze these sessions\"")
129
- print()
130
- print(" # Custom number of logs (default: 1 for best results)")
131
- print(" zen --apex --send-logs --message \"review recent log\" (analyzes 1 file)")
132
- print(" # Multiple files (use with caution - keep payload under 1MB)")
133
- print(" zen --apex --send-logs --logs-count 2 --message \"review last 2\"")
134
- print()
135
- print(" # Specific project")
136
- if claude_path.exists() and list(claude_path.iterdir()):
137
- first_project = list(p for p in claude_path.iterdir() if p.is_dir())[0].name
138
- print(f" zen --apex --send-logs --logs-project {first_project} --message \"...\"")
139
- else:
140
- print(" zen --apex --send-logs --logs-project PROJECT_NAME --message \"...\"")
141
- print()
142
- print("=" * 60)
143
-
144
-
145
- if __name__ == "__main__":
146
- demo_log_collection()
1
+ #!/usr/bin/env python3
2
+ """
3
+ Demonstration of log collection from .claude/Projects
4
+
5
+ This script shows how the zen --apex --send-logs functionality works
6
+ """
7
+ import sys
8
+ from pathlib import Path
9
+ import json
10
+
11
+ # Add parent to path for imports
12
+ sys.path.insert(0, str(Path(__file__).parent.parent))
13
+
14
+ from scripts.agent_logs import collect_recent_logs
15
+
16
+
17
+ def demo_log_collection():
18
+ """Demonstrate log collection with various scenarios"""
19
+
20
+ print("=" * 60)
21
+ print("Zen Apex Log Collection Demo")
22
+ print("=" * 60)
23
+ print()
24
+
25
+ # Check if .claude/Projects exists
26
+ claude_path = Path.home() / ".claude" / "Projects"
27
+
28
+ if not claude_path.exists():
29
+ print("❌ .claude/Projects does not exist")
30
+ print(f" Expected location: {claude_path}")
31
+ print()
32
+ print("Creating test directory...")
33
+ claude_path.mkdir(parents=True, exist_ok=True)
34
+ test_project = claude_path / "demo-project"
35
+ test_project.mkdir(exist_ok=True)
36
+
37
+ # Create sample log
38
+ sample_log = {
39
+ "type": "demo_event",
40
+ "timestamp": "2025-01-08T12:00:00",
41
+ "message": "This is a demo log entry",
42
+ "data": {"key": "value"}
43
+ }
44
+ (test_project / "demo-session.jsonl").write_text(json.dumps(sample_log) + "\n")
45
+ print(f"✅ Created demo project at {test_project}")
46
+ print()
47
+
48
+ # Scenario 1: Collect with defaults
49
+ print("Scenario 1: Collect logs with defaults (limit=1, auto-detect project)")
50
+ print("-" * 60)
51
+ logs = collect_recent_logs(limit=1)
52
+
53
+ if logs:
54
+ print(f"✅ Collected {len(logs)} log entries")
55
+ print(f" Total entries: {len(logs)}")
56
+ print()
57
+ print(" Sample entry (first):")
58
+ print(f" {json.dumps(logs[0], indent=4)}")
59
+ else:
60
+ print("⚠️ No logs found")
61
+ print(" Tip: Run Claude Code with some commands to generate logs")
62
+ print()
63
+
64
+ # Scenario 2: List available projects
65
+ print("Scenario 2: List available projects")
66
+ print("-" * 60)
67
+ if claude_path.exists():
68
+ projects = [p for p in claude_path.iterdir() if p.is_dir()]
69
+ if projects:
70
+ print(f"Found {len(projects)} project(s):")
71
+ for proj in sorted(projects, key=lambda p: p.stat().st_mtime, reverse=True):
72
+ jsonl_count = len(list(proj.glob("*.jsonl")))
73
+ mtime = proj.stat().st_mtime
74
+ from datetime import datetime
75
+ mtime_str = datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M:%S")
76
+ marker = " ← most recent" if proj == projects[0] else ""
77
+ print(f" • {proj.name}: {jsonl_count} .jsonl files (modified: {mtime_str}){marker}")
78
+ else:
79
+ print(" No projects found")
80
+ print()
81
+
82
+ # Scenario 3: Collect from specific project
83
+ if claude_path.exists():
84
+ projects = [p for p in claude_path.iterdir() if p.is_dir()]
85
+ if projects:
86
+ specific_project = projects[0].name
87
+ print(f"Scenario 3: Collect from specific project '{specific_project}'")
88
+ print("-" * 60)
89
+ logs = collect_recent_logs(limit=3, project_name=specific_project)
90
+ if logs:
91
+ print(f"✅ Collected {len(logs)} entries from '{specific_project}'")
92
+ print(f" Entry types: {[log.get('type', 'unknown') for log in logs[:3]]}")
93
+ else:
94
+ print(f"⚠️ No logs in '{specific_project}'")
95
+ print()
96
+
97
+ # Scenario 4: Show what would be sent with --send-logs
98
+ print("Scenario 4: What gets sent with 'zen --apex --send-logs --message \"..\"'")
99
+ print("-" * 60)
100
+ logs = collect_recent_logs(limit=1)
101
+ if logs:
102
+ payload_preview = {
103
+ "type": "user_message",
104
+ "payload": {
105
+ "content": "your message here",
106
+ "run_id": "cli_20250108_120000_12345",
107
+ "thread_id": "cli_thread_abc123def456",
108
+ "timestamp": "2025-01-08T12:00:00",
109
+ "jsonl_logs": logs # This is what gets attached
110
+ }
111
+ }
112
+ print("Payload structure:")
113
+ print(json.dumps(payload_preview, indent=2)[:500] + "...")
114
+ print()
115
+ print(f"✅ {len(logs)} log entries would be attached to the message")
116
+ else:
117
+ print("⚠️ No logs would be attached (none found)")
118
+ print()
119
+
120
+ # Summary
121
+ print("=" * 60)
122
+ print("Summary")
123
+ print("=" * 60)
124
+ print()
125
+ print("To use log forwarding with zen --apex:")
126
+ print()
127
+ print(" # Basic usage (default: 1 log file for best results)")
128
+ print(" zen --apex --send-logs --message \"analyze these sessions\"")
129
+ print()
130
+ print(" # Custom number of logs (default: 1 for best results)")
131
+ print(" zen --apex --send-logs --message \"review recent log\" (analyzes 1 file)")
132
+ print(" # Multiple files (use with caution - keep payload under 1MB)")
133
+ print(" zen --apex --send-logs --logs-count 2 --message \"review last 2\"")
134
+ print()
135
+ print(" # Specific project")
136
+ if claude_path.exists() and list(claude_path.iterdir()):
137
+ first_project = list(p for p in claude_path.iterdir() if p.is_dir())[0].name
138
+ print(f" zen --apex --send-logs --logs-project {first_project} --message \"...\"")
139
+ else:
140
+ print(" zen --apex --send-logs --logs-project PROJECT_NAME --message \"...\"")
141
+ print()
142
+ print("=" * 60)
143
+
144
+
145
+ if __name__ == "__main__":
146
+ demo_log_collection()
@@ -1,75 +1,75 @@
1
- #!/usr/bin/env python3
2
- """Embed telemetry credentials for release builds.
3
-
4
- Usage:
5
- COMMUNITY_CREDENTIALS="<base64-json>" python scripts/embed_release_credentials.py
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- import base64
11
- import json
12
- import os
13
- import sys
14
- from pathlib import Path
15
-
16
-
17
- PROJECT_ROOT = Path(__file__).resolve().parents[1]
18
- TARGET_FILE = PROJECT_ROOT / "zen" / "telemetry" / "embedded_credentials.py"
19
-
20
-
21
- def main() -> int:
22
- encoded = os.getenv("COMMUNITY_CREDENTIALS", "").strip()
23
- if not encoded:
24
- print(
25
- "COMMUNITY_CREDENTIALS is not set. Set the base64-encoded "
26
- "service-account JSON before running this script.",
27
- file=sys.stderr,
28
- )
29
- return 1
30
-
31
- try:
32
- decoded = base64.b64decode(encoded)
33
- info = json.loads(decoded)
34
- except Exception as exc: # pragma: no cover - defensive guard
35
- print(f"Failed to decode telemetry credentials: {exc}", file=sys.stderr)
36
- return 2
37
-
38
- project_id = info.get("project_id", "netra-telemetry-public")
39
- encoded_literal = repr(encoded)
40
-
41
- generated = f'''"""Embedded telemetry credentials. AUTO-GENERATED - DO NOT COMMIT."""
42
-
43
- import base64
44
- import json
45
- from google.oauth2 import service_account
46
-
47
- _EMBEDDED_CREDENTIALS_B64 = {encoded_literal}
48
- _CREDENTIALS_DICT = json.loads(
49
- base64.b64decode(_EMBEDDED_CREDENTIALS_B64.encode("utf-8"))
50
- )
51
-
52
-
53
- def get_embedded_credentials():
54
- """Return service account credentials."""
55
- try:
56
- return service_account.Credentials.from_service_account_info(
57
- _CREDENTIALS_DICT,
58
- scopes=["https://www.googleapis.com/auth/trace.append"],
59
- )
60
- except Exception:
61
- return None
62
-
63
-
64
- def get_project_id() -> str:
65
- """Return GCP project ID."""
66
- return _CREDENTIALS_DICT.get("project_id", {project_id!r})
67
- '''
68
-
69
- TARGET_FILE.write_text(generated)
70
- print(f"Embedded release credentials written to {TARGET_FILE.relative_to(PROJECT_ROOT)}")
71
- return 0
72
-
73
-
74
- if __name__ == "__main__":
75
- raise SystemExit(main())
1
+ #!/usr/bin/env python3
2
+ """Embed telemetry credentials for release builds.
3
+
4
+ Usage:
5
+ COMMUNITY_CREDENTIALS="<base64-json>" python scripts/embed_release_credentials.py
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import base64
11
+ import json
12
+ import os
13
+ import sys
14
+ from pathlib import Path
15
+
16
+
17
+ PROJECT_ROOT = Path(__file__).resolve().parents[1]
18
+ TARGET_FILE = PROJECT_ROOT / "zen" / "telemetry" / "embedded_credentials.py"
19
+
20
+
21
+ def main() -> int:
22
+ encoded = os.getenv("COMMUNITY_CREDENTIALS", "").strip()
23
+ if not encoded:
24
+ print(
25
+ "COMMUNITY_CREDENTIALS is not set. Set the base64-encoded "
26
+ "service-account JSON before running this script.",
27
+ file=sys.stderr,
28
+ )
29
+ return 1
30
+
31
+ try:
32
+ decoded = base64.b64decode(encoded)
33
+ info = json.loads(decoded)
34
+ except Exception as exc: # pragma: no cover - defensive guard
35
+ print(f"Failed to decode telemetry credentials: {exc}", file=sys.stderr)
36
+ return 2
37
+
38
+ project_id = info.get("project_id", "netra-telemetry-public")
39
+ encoded_literal = repr(encoded)
40
+
41
+ generated = f'''"""Embedded telemetry credentials. AUTO-GENERATED - DO NOT COMMIT."""
42
+
43
+ import base64
44
+ import json
45
+ from google.oauth2 import service_account
46
+
47
+ _EMBEDDED_CREDENTIALS_B64 = {encoded_literal}
48
+ _CREDENTIALS_DICT = json.loads(
49
+ base64.b64decode(_EMBEDDED_CREDENTIALS_B64.encode("utf-8"))
50
+ )
51
+
52
+
53
+ def get_embedded_credentials():
54
+ """Return service account credentials."""
55
+ try:
56
+ return service_account.Credentials.from_service_account_info(
57
+ _CREDENTIALS_DICT,
58
+ scopes=["https://www.googleapis.com/auth/trace.append"],
59
+ )
60
+ except Exception:
61
+ return None
62
+
63
+
64
+ def get_project_id() -> str:
65
+ """Return GCP project ID."""
66
+ return _CREDENTIALS_DICT.get("project_id", {project_id!r})
67
+ '''
68
+
69
+ TARGET_FILE.write_text(generated)
70
+ print(f"Embedded release credentials written to {TARGET_FILE.relative_to(PROJECT_ROOT)}")
71
+ return 0
72
+
73
+
74
+ if __name__ == "__main__":
75
+ raise SystemExit(main())