-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartifact.py
More file actions
78 lines (68 loc) · 2.4 KB
/
artifact.py
File metadata and controls
78 lines (68 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Artifact Registry for CoreStack Agent System
- Tracks all data artifacts, API responses, and processing results
- Provides caching, versioning, and lineage tracking
"""
import json
import hashlib
import sqlite3
import time
class ArtifactRegistry:
def __init__(self, db_path="artifacts.db"):
self.conn = sqlite3.connect(db_path)
self._init_db()
def _init_db(self):
c = self.conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS artifacts (
id TEXT PRIMARY KEY,
type TEXT,
content TEXT,
parent_id TEXT,
timestamp REAL
)
""")
self.conn.commit()
def register(self, artifact_type, content, parent_id=None):
artifact_json = json.dumps(content, sort_keys=True)
artifact_id = hashlib.sha256(artifact_json.encode()).hexdigest()
timestamp = time.time()
c = self.conn.cursor()
c.execute("""
INSERT OR IGNORE INTO artifacts (id, type, content, parent_id, timestamp)
VALUES (?, ?, ?, ?, ?)
""", (artifact_id, artifact_type, artifact_json, parent_id, timestamp))
self.conn.commit()
return artifact_id
def get(self, artifact_id):
c = self.conn.cursor()
c.execute("SELECT type, content, parent_id, timestamp FROM artifacts WHERE id=?", (artifact_id,))
row = c.fetchone()
if row:
return {
"id": artifact_id,
"type": row[0],
"content": json.loads(row[1]),
"parent_id": row[2],
"timestamp": row[3]
}
return None
def find_by_type(self, artifact_type):
c = self.conn.cursor()
c.execute("SELECT id, content FROM artifacts WHERE type=?", (artifact_type,))
return [(row[0], json.loads(row[1])) for row in c.fetchall()]
def get_stats(self):
"""
Get registry statistics
Returns:
Dictionary with counts by artifact type and total count
"""
cursor = self.conn.cursor()
cursor.execute("SELECT type, COUNT(*) FROM artifacts GROUP BY type")
type_counts = dict(cursor.fetchall())
cursor.execute("SELECT COUNT(*) FROM artifacts")
total_count = cursor.fetchone()[0]
return {
"total_artifacts": total_count,
"by_type": type_counts
}