traceyard-cli 0.1.0__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.
@@ -0,0 +1,27 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
7
+ .coverage
8
+ htmlcov/
9
+ *.egg-info/
10
+ .venv/
11
+
12
+ # JavaScript
13
+ node_modules/
14
+ dist/
15
+ coverage/
16
+ playwright-report/
17
+ test-results/
18
+
19
+ # Editors and operating systems
20
+ .DS_Store
21
+ .idea/
22
+ .vscode/
23
+
24
+ # Local configuration and secrets
25
+ .env
26
+ .env.*
27
+ !.env.example
@@ -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.
@@ -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,70 @@
1
+ # Traceyard CLI
2
+
3
+ `traceyard` connects your repositories and coding agents to a Traceyard workspace. It scaffolds
4
+ and validates a repository's `PROJECT.md`, installs lifecycle hooks for Claude Code, Codex, and
5
+ Cursor, and uploads agent-run metadata so Traceyard can show which work happened on which project.
6
+
7
+ ## Install
8
+
9
+ Requires Python 3.14. `uv` downloads it automatically.
10
+
11
+ ```sh
12
+ uv tool install traceyard-cli
13
+ # or
14
+ pipx install traceyard-cli
15
+ ```
16
+
17
+ Check the installation with `traceyard --version`.
18
+
19
+ ## Quick start
20
+
21
+ Create a collector token in your Traceyard workspace, then:
22
+
23
+ ```sh
24
+ traceyard login --base-url https://YOUR_TRACEYARD_ADDRESS --token-stdin
25
+ ```
26
+
27
+ Inside each project repository:
28
+
29
+ ```sh
30
+ traceyard repo init # scaffold PROJECT.md
31
+ traceyard repo validate # check it against the PROJECT.md specification
32
+ traceyard agent install # hook Claude Code, Codex, and Cursor into this repository
33
+ traceyard sync # upload events queued while offline
34
+ ```
35
+
36
+ ## Privacy
37
+
38
+ Agent capture defaults to `metadata_only`. Summaries and full transcripts are collected only when
39
+ you opt in with `traceyard agent install --capture-mode summary` or `--capture-mode full`, and the
40
+ workspace policy can reduce what is kept. Queued events are stored in an encrypted local database.
41
+ Collector tokens are kept in the operating system's credential store (Keychain, Secret Service, or
42
+ DPAPI), never in plain text. File contents, local paths, remote URLs, and provider credentials are
43
+ never uploaded.
44
+
45
+ ## Exit codes
46
+
47
+ `0` success, `2` invalid input, `3` credential-vault failure, `4` not logged in, `5` safe filesystem
48
+ or install refusal, `6` invalid `PROJECT.md`, `7` failed doctor check, `8` retryable network error,
49
+ `9` a permanently rejected item. Commands that may run in automation accept `--json`.
50
+
51
+ ## Upgrade and uninstall
52
+
53
+ ```sh
54
+ uv tool upgrade traceyard-cli
55
+ uv tool uninstall traceyard-cli
56
+ ```
57
+
58
+ Uninstalling does not delete your stored credential; run `traceyard auth logout` first.
59
+
60
+ ## Development
61
+
62
+ This directory owns the `traceyard` command, repository contract workflows, local configuration,
63
+ the offline agent-event queue, and the Codex/Claude Code/Cursor adapters. Provider adapters
64
+ normalize into shared AgentRun envelopes, so provider-specific behavior never enters the core
65
+ lifecycle model. This package must not contain backend HTTP routes or reach into backend domain
66
+ persistence.
67
+
68
+ ## License
69
+
70
+ MIT. See `LICENSE`.
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "traceyard-cli"
7
+ version = "0.1.0"
8
+ description = "Traceyard local repository and agent collector CLI"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Zaniar Shokati" }]
13
+ keywords = ["traceyard", "project-memory", "coding-agents", "claude-code", "codex", "cursor"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Topic :: Software Development",
23
+ ]
24
+ requires-python = ">=3.14,<3.15"
25
+ dependencies = [
26
+ "cryptography>=44,<51",
27
+ "httpx>=0.28,<1",
28
+ "PyYAML>=6.0.2,<7",
29
+ "typer>=0.16,<1",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = ["mypy>=1.15,<2", "pytest>=8.3,<10", "ruff>=0.11,<1"]
34
+
35
+ [project.scripts]
36
+ traceyard = "traceyard_cli.app:main"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/traceyard_cli"]
40
+
41
+ [tool.hatch.build.targets.sdist]
42
+ include = ["src/traceyard_cli", "README.md", "LICENSE", "pyproject.toml"]
43
+
44
+ [tool.ruff]
45
+ extend = "../backend/pyproject.toml"
@@ -0,0 +1,3 @@
1
+ """Traceyard local CLI and collector."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,93 @@
1
+ """Provider payload adapters. Core capture never branches on provider payload shape."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from .events import Provider, Status
10
+
11
+
12
+ @dataclass(frozen=True, slots=True)
13
+ class AdapterEvent:
14
+ provider: Provider
15
+ session_id: str
16
+ root: Path
17
+ status: Status
18
+ summary: str | None = None
19
+
20
+
21
+ def adapt_payload(provider: Provider, payload: dict[str, Any]) -> AdapterEvent:
22
+ if provider == "codex":
23
+ return _codex(payload)
24
+ if provider == "claude_code":
25
+ return _claude(payload)
26
+ return _cursor(payload)
27
+
28
+
29
+ def _required_text(payload: dict[str, Any], *keys: str) -> str:
30
+ for key in keys:
31
+ value = payload.get(key)
32
+ if isinstance(value, str) and value.strip():
33
+ return value.strip()
34
+ raise ValueError(f"missing required provider field: {' or '.join(keys)}")
35
+
36
+
37
+ def _codex(payload: dict[str, Any]) -> AdapterEvent:
38
+ event = _required_text(payload, "hook_event_name")
39
+ status: Status = {
40
+ "SessionStart": "started",
41
+ "Stop": "working",
42
+ "Interrupt": "interrupted",
43
+ "SessionEnd": "completed",
44
+ }.get(event, "working") # type: ignore[assignment]
45
+ return AdapterEvent(
46
+ provider="codex",
47
+ session_id=_required_text(payload, "session_id"),
48
+ root=Path(_required_text(payload, "cwd")),
49
+ status=status,
50
+ summary=payload.get("last_assistant_message")
51
+ if isinstance(payload.get("last_assistant_message"), str)
52
+ else None,
53
+ )
54
+
55
+
56
+ def _claude(payload: dict[str, Any]) -> AdapterEvent:
57
+ event = _required_text(payload, "hook_event_name")
58
+ status: Status = {
59
+ "SessionStart": "started",
60
+ "Notification": "waiting",
61
+ "Stop": "working",
62
+ "SessionEnd": "completed",
63
+ }.get(event, "working") # type: ignore[assignment]
64
+ return AdapterEvent(
65
+ provider="claude_code",
66
+ session_id=_required_text(payload, "session_id"),
67
+ root=Path(_required_text(payload, "cwd")),
68
+ status=status,
69
+ summary=payload.get("last_assistant_message")
70
+ if isinstance(payload.get("last_assistant_message"), str)
71
+ else None,
72
+ )
73
+
74
+
75
+ def _cursor(payload: dict[str, Any]) -> AdapterEvent:
76
+ event_type = _required_text(payload, "type")
77
+ subtype = str(payload.get("subtype", ""))
78
+ if event_type == "system" and subtype == "init":
79
+ status: Status = "started"
80
+ elif event_type == "result":
81
+ status = (
82
+ "failed" if payload.get("is_error") is True or subtype != "success" else "completed"
83
+ )
84
+ else:
85
+ status = "working"
86
+ summary = payload.get("result") if isinstance(payload.get("result"), str) else None
87
+ return AdapterEvent(
88
+ provider="cursor",
89
+ session_id=_required_text(payload, "session_id"),
90
+ root=Path(_required_text(payload, "cwd") if "cwd" in payload else "."),
91
+ status=status,
92
+ summary=summary,
93
+ )
@@ -0,0 +1,168 @@
1
+ """Provider hook installation and safe diagnostics."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import shutil
8
+ import stat
9
+ from pathlib import Path
10
+ from typing import Literal
11
+
12
+ from .config import CredentialStore, config_home
13
+
14
+ PROVIDERS = ("codex", "claude_code", "cursor")
15
+ MANAGED_COMMAND_PREFIX = "traceyard agent emit --provider "
16
+
17
+
18
+ CaptureMode = Literal["metadata_only", "summary", "full"]
19
+
20
+
21
+ def install_hooks(
22
+ provider: str, repository_root: Path, capture_mode: CaptureMode = "metadata_only"
23
+ ) -> tuple[Path, ...]:
24
+ selected = PROVIDERS if provider == "all" else (provider,)
25
+ if any(item not in PROVIDERS for item in selected):
26
+ raise ValueError(f"Unsupported provider: {provider}")
27
+ adapter_root = config_home() / "adapters"
28
+ adapter_root.mkdir(mode=0o700, parents=True, exist_ok=True)
29
+ installed: list[Path] = []
30
+ for item in selected:
31
+ descriptor = adapter_root / f"{item}.json"
32
+ descriptor.write_text(
33
+ json.dumps(
34
+ {
35
+ "adapter_version": "1.0",
36
+ "provider": item,
37
+ "capture_mode": capture_mode,
38
+ "command": f"{MANAGED_COMMAND_PREFIX}{item}",
39
+ },
40
+ indent=2,
41
+ )
42
+ + "\n",
43
+ encoding="utf-8",
44
+ )
45
+ os.chmod(descriptor, stat.S_IRUSR | stat.S_IWUSR)
46
+ installed.append(descriptor)
47
+ if item == "codex":
48
+ installed.append(_merge_hook_file(repository_root / ".codex" / "hooks.json", item))
49
+ elif item == "claude_code":
50
+ installed.append(_merge_hook_file(repository_root / ".claude" / "settings.json", item))
51
+ else:
52
+ installed.append(_write_cursor_adapter(repository_root))
53
+ return tuple(installed)
54
+
55
+
56
+ def configured_capture_mode(provider: str) -> CaptureMode:
57
+ """Read the explicit local mode; invalid or absent configuration fails private."""
58
+
59
+ path = config_home() / "adapters" / f"{provider}.json"
60
+ try:
61
+ value = json.loads(path.read_text(encoding="utf-8")).get("capture_mode")
62
+ except OSError, json.JSONDecodeError, AttributeError:
63
+ return "metadata_only"
64
+ return value if value in {"metadata_only", "summary", "full"} else "metadata_only"
65
+
66
+
67
+ def _merge_hook_file(path: Path, provider: str) -> Path:
68
+ if path.exists():
69
+ try:
70
+ document = json.loads(path.read_text(encoding="utf-8"))
71
+ except json.JSONDecodeError as error:
72
+ raise ValueError(f"Refusing to replace invalid JSON: {path}") from error
73
+ if not isinstance(document, dict):
74
+ raise ValueError(f"Refusing to replace non-object JSON: {path}")
75
+ else:
76
+ document = {}
77
+ hooks = document.setdefault("hooks", {})
78
+ if not isinstance(hooks, dict):
79
+ raise TypeError(f"Refusing to replace invalid hooks object: {path}")
80
+ events: tuple[str, ...] = ("SessionStart", "Stop", "SessionEnd")
81
+ if provider == "claude_code":
82
+ events = (*events, "Notification")
83
+ command = f"{MANAGED_COMMAND_PREFIX}{provider}"
84
+ for event in events:
85
+ groups = hooks.setdefault(event, [])
86
+ if not isinstance(groups, list):
87
+ raise TypeError(f"Refusing to replace invalid {event} hooks: {path}")
88
+ if not _contains_command(groups, command):
89
+ groups.append({"hooks": [{"type": "command", "command": command, "timeout": 3}]})
90
+ path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
91
+ path.write_text(json.dumps(document, indent=2) + "\n", encoding="utf-8")
92
+ return path
93
+
94
+
95
+ def _contains_command(groups: list[object], command: str) -> bool:
96
+ for group in groups:
97
+ if not isinstance(group, dict) or not isinstance(group.get("hooks"), list):
98
+ continue
99
+ for handler in group["hooks"]:
100
+ if isinstance(handler, dict) and handler.get("command") == command:
101
+ return True
102
+ return False
103
+
104
+
105
+ def _write_cursor_adapter(root: Path) -> Path:
106
+ path = root / ".traceyard" / "cursor-adapter.json"
107
+ path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
108
+ path.write_text(
109
+ json.dumps(
110
+ {
111
+ "adapter_version": "1.0",
112
+ "provider": "cursor",
113
+ "input": "cursor-agent --print --output-format stream-json",
114
+ "collector": "traceyard agent stream --provider cursor",
115
+ },
116
+ indent=2,
117
+ )
118
+ + "\n",
119
+ encoding="utf-8",
120
+ )
121
+ return path
122
+
123
+
124
+ def doctor(store: CredentialStore, repository_root: Path | None = None) -> dict[str, object]:
125
+ adapter_root = config_home() / "adapters"
126
+ adapters: dict[str, str] = {}
127
+ for provider in PROVIDERS:
128
+ path = adapter_root / f"{provider}.json"
129
+ if not path.exists():
130
+ adapters[provider] = "not_installed"
131
+ continue
132
+ try:
133
+ document = json.loads(path.read_text(encoding="utf-8"))
134
+ adapters[provider] = "ok" if document.get("provider") == provider else "invalid"
135
+ except OSError, json.JSONDecodeError:
136
+ adapters[provider] = "invalid"
137
+ hooks: dict[str, str] = {}
138
+ if repository_root is not None:
139
+ for provider, relative in {
140
+ "codex": ".codex/hooks.json",
141
+ "claude_code": ".claude/settings.json",
142
+ "cursor": ".traceyard/cursor-adapter.json",
143
+ }.items():
144
+ hooks[provider] = "ok" if (repository_root / relative).is_file() else "not_installed"
145
+ token_available = store.get_token() is not None
146
+ git_available = shutil.which("git") is not None
147
+ healthy = (
148
+ token_available
149
+ and git_available
150
+ and all(value in {"ok", "not_installed"} for value in adapters.values())
151
+ )
152
+ remediation: list[str] = []
153
+ if not token_available:
154
+ remediation.append("Run `traceyard login` or set TRACEYARD_TOKEN for this process.")
155
+ if not git_available:
156
+ remediation.append("Install Git and ensure it is on PATH.")
157
+ if "invalid" in adapters.values():
158
+ remediation.append("Re-run `traceyard agent install --provider <provider>`.")
159
+ return {
160
+ "status": "ok" if healthy else "failed",
161
+ "checks": {
162
+ "credential": "ok" if token_available else "missing",
163
+ "git": "ok" if git_available else "missing",
164
+ "adapters": adapters,
165
+ "hooks": hooks,
166
+ },
167
+ "remediation": remediation,
168
+ }