traceyard-cli 0.1.0__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.
- traceyard_cli/__init__.py +3 -0
- traceyard_cli/adapters.py +93 -0
- traceyard_cli/agent.py +168 -0
- traceyard_cli/app.py +457 -0
- traceyard_cli/config.py +182 -0
- traceyard_cli/events.py +214 -0
- traceyard_cli/queue.py +127 -0
- traceyard_cli/repository.py +175 -0
- traceyard_cli-0.1.0.dist-info/METADATA +97 -0
- traceyard_cli-0.1.0.dist-info/RECORD +13 -0
- traceyard_cli-0.1.0.dist-info/WHEEL +4 -0
- traceyard_cli-0.1.0.dist-info/entry_points.txt +2 -0
- traceyard_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
traceyard_cli/events.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""Provider-neutral local AgentRun evidence capture."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import stat
|
|
9
|
+
import subprocess
|
|
10
|
+
from dataclasses import asdict, dataclass
|
|
11
|
+
from datetime import UTC, datetime
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Literal
|
|
14
|
+
from uuid import NAMESPACE_URL, uuid4, uuid5
|
|
15
|
+
|
|
16
|
+
from .config import config_home
|
|
17
|
+
|
|
18
|
+
Provider = Literal["codex", "claude_code", "cursor"]
|
|
19
|
+
Status = Literal["started", "working", "waiting", "completed", "interrupted", "failed", "unknown"]
|
|
20
|
+
CaptureMode = Literal["metadata_only", "summary", "full"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True, slots=True)
|
|
24
|
+
class ChangedFile:
|
|
25
|
+
path_hash: str
|
|
26
|
+
change_kind: Literal["added", "modified", "deleted", "renamed"]
|
|
27
|
+
previous_path_hash: str | None = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True, slots=True)
|
|
31
|
+
class AgentEvent:
|
|
32
|
+
event_version: str
|
|
33
|
+
event_id: str
|
|
34
|
+
run_id: str
|
|
35
|
+
event_type: str
|
|
36
|
+
provider: Provider
|
|
37
|
+
provider_session_id: str
|
|
38
|
+
occurred_at: str
|
|
39
|
+
sequence: int
|
|
40
|
+
status: Status
|
|
41
|
+
repository_remote_hash: str | None
|
|
42
|
+
workspace_path_hash: str
|
|
43
|
+
branch: str | None
|
|
44
|
+
starting_sha: str | None
|
|
45
|
+
ending_sha: str | None
|
|
46
|
+
changed_files: tuple[ChangedFile, ...]
|
|
47
|
+
changed_file_count: int
|
|
48
|
+
candidate_commits: tuple[str, ...]
|
|
49
|
+
capture_mode: CaptureMode
|
|
50
|
+
summary: str | None
|
|
51
|
+
prompt: str | None
|
|
52
|
+
transcript: str | None
|
|
53
|
+
tool_data: dict[str, object] | None
|
|
54
|
+
|
|
55
|
+
def as_dict(self) -> dict[str, object]:
|
|
56
|
+
return asdict(self)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def hash_private_value(value: str) -> str:
|
|
60
|
+
return hashlib.sha256(value.encode("utf-8", errors="surrogateescape")).hexdigest()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def build_event(
|
|
64
|
+
*,
|
|
65
|
+
provider: Provider,
|
|
66
|
+
session_id: str,
|
|
67
|
+
root: Path,
|
|
68
|
+
status: Status,
|
|
69
|
+
occurred_at: datetime,
|
|
70
|
+
summary: str | None = None,
|
|
71
|
+
capture_mode: CaptureMode = "metadata_only",
|
|
72
|
+
prompt: str | None = None,
|
|
73
|
+
transcript: str | None = None,
|
|
74
|
+
tool_data: dict[str, object] | None = None,
|
|
75
|
+
) -> AgentEvent:
|
|
76
|
+
if occurred_at.tzinfo is None:
|
|
77
|
+
raise ValueError("occurred_at must be timezone-aware")
|
|
78
|
+
repository_root = _git(root, "rev-parse", "--show-toplevel")
|
|
79
|
+
resolved_root = Path(repository_root).resolve() if repository_root else root.resolve()
|
|
80
|
+
state_path = _state_path(provider, session_id)
|
|
81
|
+
state = _read_state(state_path)
|
|
82
|
+
current_head = _git(resolved_root, "rev-parse", "HEAD")
|
|
83
|
+
if not state:
|
|
84
|
+
state = {"started_sha": current_head, "sequence": -1}
|
|
85
|
+
stored_sequence = state.get("sequence", -1)
|
|
86
|
+
sequence = (stored_sequence if isinstance(stored_sequence, int) else -1) + 1
|
|
87
|
+
if status not in {"completed", "interrupted", "failed"}:
|
|
88
|
+
_write_state(state_path, {"started_sha": state.get("started_sha"), "sequence": sequence})
|
|
89
|
+
else:
|
|
90
|
+
state_path.unlink(missing_ok=True)
|
|
91
|
+
changed = (
|
|
92
|
+
_changed_files(resolved_root) if status in {"completed", "interrupted", "failed"} else ()
|
|
93
|
+
)
|
|
94
|
+
starting_sha = _sha(state.get("started_sha"))
|
|
95
|
+
candidate_commits = _candidate_commits(resolved_root, starting_sha, current_head)
|
|
96
|
+
remote = _git(resolved_root, "remote", "get-url", "origin")
|
|
97
|
+
safe_summary = summary.strip()[:4000] if summary and capture_mode != "metadata_only" else None
|
|
98
|
+
terminal = status in {"completed", "interrupted", "failed"}
|
|
99
|
+
event_name = (
|
|
100
|
+
"run.finished"
|
|
101
|
+
if terminal
|
|
102
|
+
else {"started": "run.started", "waiting": "run.waiting"}.get(status, "run.working")
|
|
103
|
+
)
|
|
104
|
+
return AgentEvent(
|
|
105
|
+
event_version="1.0",
|
|
106
|
+
event_id=str(uuid4()),
|
|
107
|
+
run_id=str(uuid5(NAMESPACE_URL, f"traceyard:{provider}:{session_id}")),
|
|
108
|
+
event_type=event_name,
|
|
109
|
+
provider=provider,
|
|
110
|
+
provider_session_id=session_id[:500],
|
|
111
|
+
occurred_at=occurred_at.astimezone(UTC).isoformat().replace("+00:00", "Z"),
|
|
112
|
+
sequence=sequence,
|
|
113
|
+
status=status,
|
|
114
|
+
repository_remote_hash=hash_private_value(remote) if remote else None,
|
|
115
|
+
workspace_path_hash=hash_private_value(str(resolved_root)),
|
|
116
|
+
branch=_git(resolved_root, "branch", "--show-current"),
|
|
117
|
+
starting_sha=starting_sha,
|
|
118
|
+
ending_sha=_sha(current_head),
|
|
119
|
+
changed_files=changed,
|
|
120
|
+
changed_file_count=len(changed),
|
|
121
|
+
candidate_commits=candidate_commits,
|
|
122
|
+
capture_mode=capture_mode,
|
|
123
|
+
summary=safe_summary,
|
|
124
|
+
prompt=prompt[:16_000] if prompt and capture_mode == "full" else None,
|
|
125
|
+
transcript=transcript[:100_000] if transcript and capture_mode == "full" else None,
|
|
126
|
+
tool_data=tool_data if tool_data and capture_mode == "full" else None,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _state_path(provider: Provider, session_id: str) -> Path:
|
|
131
|
+
return config_home() / "runs" / f"{provider}-{hash_private_value(session_id)}.json"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _read_state(path: Path) -> dict[str, object]:
|
|
135
|
+
try:
|
|
136
|
+
value = json.loads(path.read_text(encoding="utf-8"))
|
|
137
|
+
except OSError, json.JSONDecodeError:
|
|
138
|
+
return {}
|
|
139
|
+
return value if isinstance(value, dict) else {}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _write_state(path: Path, value: dict[str, object]) -> None:
|
|
143
|
+
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
144
|
+
path.write_text(json.dumps(value), encoding="utf-8")
|
|
145
|
+
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _git(root: Path, *args: str) -> str | None:
|
|
149
|
+
result = subprocess.run(
|
|
150
|
+
["git", "-C", str(root), *args], check=False, capture_output=True, text=True
|
|
151
|
+
)
|
|
152
|
+
return result.stdout.strip() if result.returncode == 0 and result.stdout.strip() else None
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _sha(value: object) -> str | None:
|
|
156
|
+
text = str(value) if value else ""
|
|
157
|
+
return (
|
|
158
|
+
text
|
|
159
|
+
if 40 <= len(text) <= 64 and all(character in "0123456789abcdef" for character in text)
|
|
160
|
+
else None
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _candidate_commits(root: Path, start: str | None, end: str | None) -> tuple[str, ...]:
|
|
165
|
+
if not start or not end or start == end:
|
|
166
|
+
return ()
|
|
167
|
+
output = _git(root, "rev-list", "--reverse", f"{start}..{end}")
|
|
168
|
+
return tuple(item for item in (output or "").splitlines() if _sha(item))[:500]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _changed_files(root: Path) -> tuple[ChangedFile, ...]:
|
|
172
|
+
result = subprocess.run(
|
|
173
|
+
[
|
|
174
|
+
"git",
|
|
175
|
+
"-C",
|
|
176
|
+
str(root),
|
|
177
|
+
"status",
|
|
178
|
+
"--porcelain=v1",
|
|
179
|
+
"-z",
|
|
180
|
+
"--untracked-files=all",
|
|
181
|
+
],
|
|
182
|
+
check=False,
|
|
183
|
+
capture_output=True,
|
|
184
|
+
)
|
|
185
|
+
if result.returncode != 0:
|
|
186
|
+
return ()
|
|
187
|
+
entries = result.stdout.decode("utf-8", errors="surrogateescape").split("\0")
|
|
188
|
+
changes: list[ChangedFile] = []
|
|
189
|
+
index = 0
|
|
190
|
+
while index < len(entries) and entries[index]:
|
|
191
|
+
entry = entries[index]
|
|
192
|
+
code, path = entry[:2], entry[3:]
|
|
193
|
+
previous = None
|
|
194
|
+
kind: Literal["added", "modified", "deleted", "renamed"]
|
|
195
|
+
if "R" in code and index + 1 < len(entries):
|
|
196
|
+
previous = path
|
|
197
|
+
index += 1
|
|
198
|
+
path = entries[index]
|
|
199
|
+
kind = "renamed"
|
|
200
|
+
elif "?" in code or "A" in code:
|
|
201
|
+
kind = "added"
|
|
202
|
+
elif "D" in code:
|
|
203
|
+
kind = "deleted"
|
|
204
|
+
else:
|
|
205
|
+
kind = "modified"
|
|
206
|
+
changes.append(
|
|
207
|
+
ChangedFile(
|
|
208
|
+
path_hash=hash_private_value(path),
|
|
209
|
+
change_kind=kind,
|
|
210
|
+
previous_path_hash=hash_private_value(previous) if previous else None,
|
|
211
|
+
)
|
|
212
|
+
)
|
|
213
|
+
index += 1
|
|
214
|
+
return tuple(changes[:2000])
|
traceyard_cli/queue.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Encrypted, ordered, corruption-tolerant local event queue."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sqlite3
|
|
9
|
+
import stat
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from datetime import UTC, datetime, timedelta
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from cryptography.fernet import Fernet, InvalidToken
|
|
16
|
+
|
|
17
|
+
from .config import config_home
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class QueuedEvent:
|
|
22
|
+
sequence: int
|
|
23
|
+
event_id: str
|
|
24
|
+
payload: dict[str, Any]
|
|
25
|
+
attempts: int
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class EncryptedEventQueue:
|
|
29
|
+
def __init__(self, token: str, path: Path | None = None) -> None:
|
|
30
|
+
key = hashlib.sha256(f"traceyard-queue-v1:{token}".encode()).digest()
|
|
31
|
+
import base64
|
|
32
|
+
|
|
33
|
+
self._fernet = Fernet(base64.urlsafe_b64encode(key))
|
|
34
|
+
self.path = path or config_home() / "queue.sqlite3"
|
|
35
|
+
self.path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
36
|
+
self._initialize()
|
|
37
|
+
|
|
38
|
+
def enqueue(self, event: dict[str, object]) -> bool:
|
|
39
|
+
event_id = str(event["event_id"])
|
|
40
|
+
ciphertext = self._fernet.encrypt(
|
|
41
|
+
json.dumps(event, separators=(",", ":"), sort_keys=True).encode()
|
|
42
|
+
)
|
|
43
|
+
with self._connect() as connection:
|
|
44
|
+
cursor = connection.execute(
|
|
45
|
+
"INSERT OR IGNORE INTO events(event_id, payload, attempts, available_at) "
|
|
46
|
+
"VALUES (?, ?, 0, ?)",
|
|
47
|
+
(event_id, ciphertext, _now_text()),
|
|
48
|
+
)
|
|
49
|
+
return cursor.rowcount == 1
|
|
50
|
+
|
|
51
|
+
def batch(self, *, limit: int = 100) -> tuple[QueuedEvent, ...]:
|
|
52
|
+
with self._connect() as connection:
|
|
53
|
+
rows = connection.execute(
|
|
54
|
+
"SELECT sequence, event_id, payload, attempts FROM events "
|
|
55
|
+
"WHERE quarantined = 0 AND available_at <= ? ORDER BY sequence LIMIT ?",
|
|
56
|
+
(_now_text(), max(1, min(limit, 100))),
|
|
57
|
+
).fetchall()
|
|
58
|
+
events: list[QueuedEvent] = []
|
|
59
|
+
for sequence, event_id, payload, attempts in rows:
|
|
60
|
+
try:
|
|
61
|
+
value = json.loads(self._fernet.decrypt(payload))
|
|
62
|
+
except InvalidToken, json.JSONDecodeError, TypeError:
|
|
63
|
+
self._quarantine(int(sequence))
|
|
64
|
+
continue
|
|
65
|
+
if not isinstance(value, dict):
|
|
66
|
+
self._quarantine(int(sequence))
|
|
67
|
+
continue
|
|
68
|
+
events.append(QueuedEvent(int(sequence), str(event_id), value, int(attempts)))
|
|
69
|
+
return tuple(events)
|
|
70
|
+
|
|
71
|
+
def acknowledge(self, sequences: tuple[int, ...]) -> None:
|
|
72
|
+
if not sequences:
|
|
73
|
+
return
|
|
74
|
+
placeholders = ",".join("?" for _ in sequences)
|
|
75
|
+
with self._connect() as connection:
|
|
76
|
+
connection.execute(f"DELETE FROM events WHERE sequence IN ({placeholders})", sequences)
|
|
77
|
+
|
|
78
|
+
def retry(self, sequences: tuple[int, ...], *, attempts: int) -> None:
|
|
79
|
+
if not sequences:
|
|
80
|
+
return
|
|
81
|
+
delay = min(300, 2 ** min(attempts, 8))
|
|
82
|
+
available = (datetime.now(UTC) + timedelta(seconds=delay)).isoformat()
|
|
83
|
+
placeholders = ",".join("?" for _ in sequences)
|
|
84
|
+
with self._connect() as connection:
|
|
85
|
+
connection.execute(
|
|
86
|
+
f"UPDATE events SET attempts = attempts + 1, available_at = ? "
|
|
87
|
+
f"WHERE sequence IN ({placeholders})",
|
|
88
|
+
(available, *sequences),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def inspect(self) -> dict[str, int]:
|
|
92
|
+
with self._connect() as connection:
|
|
93
|
+
queued, quarantined = connection.execute(
|
|
94
|
+
"SELECT count(*) FILTER (WHERE quarantined = 0), "
|
|
95
|
+
"count(*) FILTER (WHERE quarantined = 1) FROM events"
|
|
96
|
+
).fetchone()
|
|
97
|
+
return {"queued": int(queued), "quarantined": int(quarantined)}
|
|
98
|
+
|
|
99
|
+
def clear(self, *, include_quarantine: bool = False) -> int:
|
|
100
|
+
with self._connect() as connection:
|
|
101
|
+
cursor = connection.execute(
|
|
102
|
+
"DELETE FROM events"
|
|
103
|
+
if include_quarantine
|
|
104
|
+
else "DELETE FROM events WHERE quarantined = 0"
|
|
105
|
+
)
|
|
106
|
+
return int(cursor.rowcount)
|
|
107
|
+
|
|
108
|
+
def _quarantine(self, sequence: int) -> None:
|
|
109
|
+
with self._connect() as connection:
|
|
110
|
+
connection.execute("UPDATE events SET quarantined = 1 WHERE sequence = ?", (sequence,))
|
|
111
|
+
|
|
112
|
+
def _initialize(self) -> None:
|
|
113
|
+
with self._connect() as connection:
|
|
114
|
+
connection.execute(
|
|
115
|
+
"CREATE TABLE IF NOT EXISTS events ("
|
|
116
|
+
"sequence INTEGER PRIMARY KEY AUTOINCREMENT, event_id TEXT NOT NULL UNIQUE, "
|
|
117
|
+
"payload BLOB NOT NULL, attempts INTEGER NOT NULL, available_at TEXT NOT NULL, "
|
|
118
|
+
"quarantined INTEGER NOT NULL DEFAULT 0 CHECK (quarantined IN (0, 1)))"
|
|
119
|
+
)
|
|
120
|
+
os.chmod(self.path, stat.S_IRUSR | stat.S_IWUSR)
|
|
121
|
+
|
|
122
|
+
def _connect(self) -> sqlite3.Connection:
|
|
123
|
+
return sqlite3.connect(self.path)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _now_text() -> str:
|
|
127
|
+
return datetime.now(UTC).isoformat()
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Local, non-provider repository workflows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import re
|
|
7
|
+
import subprocess
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from datetime import UTC, datetime
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
from uuid import uuid4
|
|
13
|
+
|
|
14
|
+
import yaml
|
|
15
|
+
|
|
16
|
+
REQUIRED_FIELDS = {"traceyard_spec", "id", "name", "type", "lifecycle", "work_state", "updated_at"}
|
|
17
|
+
ALLOWED_TYPES = {"software", "research", "content", "infrastructure", "idea", "other"}
|
|
18
|
+
ALLOWED_LIFECYCLES = {
|
|
19
|
+
"idea",
|
|
20
|
+
"research",
|
|
21
|
+
"prototype",
|
|
22
|
+
"building",
|
|
23
|
+
"beta",
|
|
24
|
+
"production",
|
|
25
|
+
"maintenance",
|
|
26
|
+
"paused",
|
|
27
|
+
"archived",
|
|
28
|
+
}
|
|
29
|
+
ALLOWED_WORK_STATES = {"active", "blocked", "waiting", "idle", "done", "abandoned"}
|
|
30
|
+
SECRET_PATTERN = re.compile(r"(?i)(api[_-]?key|password|secret|token)\s*[:=]\s*[^\s]+")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, slots=True)
|
|
34
|
+
class ValidationResult:
|
|
35
|
+
valid: bool
|
|
36
|
+
diagnostics: tuple[dict[str, str], ...]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def validate_project(path: Path) -> ValidationResult:
|
|
40
|
+
if not path.is_file():
|
|
41
|
+
return ValidationResult(
|
|
42
|
+
False,
|
|
43
|
+
(
|
|
44
|
+
{
|
|
45
|
+
"level": "error",
|
|
46
|
+
"code": "document.missing",
|
|
47
|
+
"message": "PROJECT.md was not found",
|
|
48
|
+
},
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
text = path.read_text(encoding="utf-8")
|
|
52
|
+
if len(text.encode()) > 1_000_000:
|
|
53
|
+
return ValidationResult(
|
|
54
|
+
False,
|
|
55
|
+
(
|
|
56
|
+
{
|
|
57
|
+
"level": "error",
|
|
58
|
+
"code": "document.too_large",
|
|
59
|
+
"message": "PROJECT.md exceeds 1 MB",
|
|
60
|
+
},
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
if SECRET_PATTERN.search(text):
|
|
64
|
+
return ValidationResult(
|
|
65
|
+
False,
|
|
66
|
+
(
|
|
67
|
+
{
|
|
68
|
+
"level": "error",
|
|
69
|
+
"code": "document.possible_secret",
|
|
70
|
+
"message": "Possible credential-like content found",
|
|
71
|
+
},
|
|
72
|
+
),
|
|
73
|
+
)
|
|
74
|
+
parts = text.split("---", 2)
|
|
75
|
+
if len(parts) != 3 or parts[0].strip():
|
|
76
|
+
return ValidationResult(
|
|
77
|
+
False,
|
|
78
|
+
(
|
|
79
|
+
{
|
|
80
|
+
"level": "error",
|
|
81
|
+
"code": "frontmatter.missing",
|
|
82
|
+
"message": "PROJECT.md must start with YAML frontmatter",
|
|
83
|
+
},
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
try:
|
|
87
|
+
data: Any = yaml.safe_load(parts[1])
|
|
88
|
+
except yaml.YAMLError:
|
|
89
|
+
return ValidationResult(
|
|
90
|
+
False,
|
|
91
|
+
(
|
|
92
|
+
{
|
|
93
|
+
"level": "error",
|
|
94
|
+
"code": "frontmatter.invalid_yaml",
|
|
95
|
+
"message": "YAML frontmatter is invalid",
|
|
96
|
+
},
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
errors: list[dict[str, str]] = []
|
|
100
|
+
if not isinstance(data, dict):
|
|
101
|
+
errors.append(
|
|
102
|
+
{
|
|
103
|
+
"level": "error",
|
|
104
|
+
"code": "frontmatter.not_mapping",
|
|
105
|
+
"message": "Frontmatter must be a mapping",
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
else:
|
|
109
|
+
missing = sorted(REQUIRED_FIELDS - data.keys())
|
|
110
|
+
for field in missing:
|
|
111
|
+
errors.append(
|
|
112
|
+
{
|
|
113
|
+
"level": "error",
|
|
114
|
+
"code": "field.required",
|
|
115
|
+
"message": f"Missing required field: {field}",
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
if data.get("traceyard_spec") != 1:
|
|
119
|
+
errors.append(
|
|
120
|
+
{
|
|
121
|
+
"level": "error",
|
|
122
|
+
"code": "spec.unsupported",
|
|
123
|
+
"message": "traceyard_spec must be 1",
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
for key, allowed in (
|
|
127
|
+
("type", ALLOWED_TYPES),
|
|
128
|
+
("lifecycle", ALLOWED_LIFECYCLES),
|
|
129
|
+
("work_state", ALLOWED_WORK_STATES),
|
|
130
|
+
):
|
|
131
|
+
if key in data and data[key] not in allowed:
|
|
132
|
+
errors.append(
|
|
133
|
+
{"level": "error", "code": "field.invalid_enum", "message": f"Invalid {key}"}
|
|
134
|
+
)
|
|
135
|
+
return ValidationResult(not errors, tuple(errors))
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def initialize_repository(root: Path, *, name: str | None = None) -> tuple[Path, ...]:
|
|
139
|
+
project_path = root / "PROJECT.md"
|
|
140
|
+
if project_path.exists():
|
|
141
|
+
raise FileExistsError("PROJECT.md already exists; initialization will not overwrite it")
|
|
142
|
+
project_name = name or root.resolve().name
|
|
143
|
+
today = datetime.now(UTC).date().isoformat()
|
|
144
|
+
project_path.write_text(
|
|
145
|
+
"---\n"
|
|
146
|
+
f"traceyard_spec: 1\nid: {uuid4()}\nname: {project_name!r}\ntype: software\n"
|
|
147
|
+
f"lifecycle: building\nwork_state: active\nupdated_at: {today}\n---\n\n"
|
|
148
|
+
"# Purpose\n\nDescribe the durable purpose of this project.\n\n"
|
|
149
|
+
"# Current State\n\nDescribe the current meaningful state.\n\n"
|
|
150
|
+
"# Running\n\nNo declared environments.\n\n# Recent Meaningful Changes\n\n"
|
|
151
|
+
"# Decisions\n\n# Open Questions\n\n# Done\n\n# Abandoned\n",
|
|
152
|
+
encoding="utf-8",
|
|
153
|
+
)
|
|
154
|
+
config_path = root / ".traceyard" / "config.yaml"
|
|
155
|
+
config_path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
156
|
+
config_path.write_text("traceyard_config: 1\nproject_document: PROJECT.md\n", encoding="utf-8")
|
|
157
|
+
return project_path, config_path
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def repository_status(root: Path) -> dict[str, object]:
|
|
161
|
+
def git(*args: str) -> str | None:
|
|
162
|
+
result = subprocess.run(
|
|
163
|
+
["git", "-C", str(root), *args], check=False, capture_output=True, text=True
|
|
164
|
+
)
|
|
165
|
+
return result.stdout.strip() if result.returncode == 0 else None
|
|
166
|
+
|
|
167
|
+
validation = validate_project(root / "PROJECT.md")
|
|
168
|
+
remote = git("remote", "get-url", "origin")
|
|
169
|
+
return {
|
|
170
|
+
"valid": validation.valid,
|
|
171
|
+
"branch": git("branch", "--show-current"),
|
|
172
|
+
"head": git("rev-parse", "HEAD"),
|
|
173
|
+
"remote_hash": hashlib.sha256(remote.encode()).hexdigest() if remote else None,
|
|
174
|
+
"diagnostics": validation.diagnostics,
|
|
175
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: traceyard-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Traceyard local repository and agent collector CLI
|
|
5
|
+
Author: Zaniar Shokati
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: claude-code,codex,coding-agents,cursor,project-memory,traceyard
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Software Development
|
|
17
|
+
Requires-Python: <3.15,>=3.14
|
|
18
|
+
Requires-Dist: cryptography<51,>=44
|
|
19
|
+
Requires-Dist: httpx<1,>=0.28
|
|
20
|
+
Requires-Dist: pyyaml<7,>=6.0.2
|
|
21
|
+
Requires-Dist: typer<1,>=0.16
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: mypy<2,>=1.15; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest<10,>=8.3; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff<1,>=0.11; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Traceyard CLI
|
|
29
|
+
|
|
30
|
+
`traceyard` connects your repositories and coding agents to a Traceyard workspace. It scaffolds
|
|
31
|
+
and validates a repository's `PROJECT.md`, installs lifecycle hooks for Claude Code, Codex, and
|
|
32
|
+
Cursor, and uploads agent-run metadata so Traceyard can show which work happened on which project.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
Requires Python 3.14. `uv` downloads it automatically.
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
uv tool install traceyard-cli
|
|
40
|
+
# or
|
|
41
|
+
pipx install traceyard-cli
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Check the installation with `traceyard --version`.
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
Create a collector token in your Traceyard workspace, then:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
traceyard login --base-url https://YOUR_TRACEYARD_ADDRESS --token-stdin
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Inside each project repository:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
traceyard repo init # scaffold PROJECT.md
|
|
58
|
+
traceyard repo validate # check it against the PROJECT.md specification
|
|
59
|
+
traceyard agent install # hook Claude Code, Codex, and Cursor into this repository
|
|
60
|
+
traceyard sync # upload events queued while offline
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Privacy
|
|
64
|
+
|
|
65
|
+
Agent capture defaults to `metadata_only`. Summaries and full transcripts are collected only when
|
|
66
|
+
you opt in with `traceyard agent install --capture-mode summary` or `--capture-mode full`, and the
|
|
67
|
+
workspace policy can reduce what is kept. Queued events are stored in an encrypted local database.
|
|
68
|
+
Collector tokens are kept in the operating system's credential store (Keychain, Secret Service, or
|
|
69
|
+
DPAPI), never in plain text. File contents, local paths, remote URLs, and provider credentials are
|
|
70
|
+
never uploaded.
|
|
71
|
+
|
|
72
|
+
## Exit codes
|
|
73
|
+
|
|
74
|
+
`0` success, `2` invalid input, `3` credential-vault failure, `4` not logged in, `5` safe filesystem
|
|
75
|
+
or install refusal, `6` invalid `PROJECT.md`, `7` failed doctor check, `8` retryable network error,
|
|
76
|
+
`9` a permanently rejected item. Commands that may run in automation accept `--json`.
|
|
77
|
+
|
|
78
|
+
## Upgrade and uninstall
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
uv tool upgrade traceyard-cli
|
|
82
|
+
uv tool uninstall traceyard-cli
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Uninstalling does not delete your stored credential; run `traceyard auth logout` first.
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
This directory owns the `traceyard` command, repository contract workflows, local configuration,
|
|
90
|
+
the offline agent-event queue, and the Codex/Claude Code/Cursor adapters. Provider adapters
|
|
91
|
+
normalize into shared AgentRun envelopes, so provider-specific behavior never enters the core
|
|
92
|
+
lifecycle model. This package must not contain backend HTTP routes or reach into backend domain
|
|
93
|
+
persistence.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
traceyard_cli/__init__.py,sha256=tleH9YzRv_607ee5GKtW2_x0S95gCwFlTqG7gDXC-Aw,64
|
|
2
|
+
traceyard_cli/adapters.py,sha256=zzxJL5S84rHYy-5zoPP_58Cyne0TwzDHN-fItaVO4Pw,3003
|
|
3
|
+
traceyard_cli/agent.py,sha256=_GR37TxfEco9fTlLaXzmYZhJmrxkPL4TN-PYKuRG2NE,6430
|
|
4
|
+
traceyard_cli/app.py,sha256=IcoLcpR4CwGaWNX5eWu6rtIg4XfwKY8YRkhDd2S6mBY,15947
|
|
5
|
+
traceyard_cli/config.py,sha256=d3oanr5MMYBeMI9WhvFT31C4osCzkPFaOb0d0CkrDSg,6842
|
|
6
|
+
traceyard_cli/events.py,sha256=Nhc_B_MqHrl6VYo3l2H-DhF8Vuw_tZvTW7ROBciIEfA,7327
|
|
7
|
+
traceyard_cli/queue.py,sha256=ZmF8sQXXx321LFWE5K9VA1dkSy5Elm3NVJYfTT2jfTE,4905
|
|
8
|
+
traceyard_cli/repository.py,sha256=wwXHP-z2vrDsm4rfBA6HcjZIIF-8yR_AK1LqBXkmnAs,5854
|
|
9
|
+
traceyard_cli-0.1.0.dist-info/METADATA,sha256=WO22cEyiioLMm59rbEUm4aK5VCdZsKFLRBYhsc74WZ0,3418
|
|
10
|
+
traceyard_cli-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
11
|
+
traceyard_cli-0.1.0.dist-info/entry_points.txt,sha256=eN30G3LeVvVGhyoBA0w9_FS1dd5ysDOnc982a159VyM,53
|
|
12
|
+
traceyard_cli-0.1.0.dist-info/licenses/LICENSE,sha256=A9Q8tdax3R29lOEz9bUMFLsProfwZFakNcbDCezjEEU,1071
|
|
13
|
+
traceyard_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zaniar Shokati
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|