ghosttrace 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ahmed Allam
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,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: ghosttrace
3
+ Version: 0.1.0
4
+ Summary: Record AI agent decisions, including phantom branches.
5
+ Requires-Python: >=3.10
6
+ License-File: LICENSE
7
+ Requires-Dist: typer[all]>=0.9.0
8
+ Requires-Dist: rich>=13.0.0
9
+ Dynamic: license-file
@@ -0,0 +1,110 @@
1
+ <div align="center">
2
+
3
+ # 👻 GhostTrace
4
+
5
+ ### See what your AI agent *almost* did.
6
+
7
+ Record AI agent decisions — including **Phantom Branches**:
8
+ the actions your agent considered but rejected.
9
+
10
+ <p align="center">
11
+ <a href="https://github.com/AhmedAllam0/ghosttrace/stargazers">
12
+ <img src="https://img.shields.io/github/stars/AhmedAllam0/ghosttrace?style=for-the-badge&logo=github&color=yellow" alt="Stars" />
13
+ </a>
14
+ <a href="https://pypi.org/project/ghosttrace/">
15
+ <img src="https://img.shields.io/pypi/v/ghosttrace?style=for-the-badge&logo=pypi&color=blue" alt="PyPI Version" />
16
+ </a>
17
+ <a href="https://github.com/AhmedAllam0/ghosttrace">
18
+ <img src="https://img.shields.io/badge/python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python" />
19
+ </a>
20
+ <a href="https://github.com/AhmedAllam0/ghosttrace/blob/main/LICENSE">
21
+ <img src="https://img.shields.io/github/license/AhmedAllam0/ghosttrace?style=for-the-badge&color=green" alt="License" />
22
+ </a>
23
+ </p>
24
+
25
+ </div>
26
+
27
+ ---
28
+
29
+ ## The Problem
30
+
31
+ Your AI agent made a bad call. But you only see *what it did* — never *what it almost did*. The reasoning behind rejected alternatives is lost forever.
32
+
33
+ **GhostTrace fixes that.**
34
+
35
+ ---
36
+
37
+ ## What is GhostTrace?
38
+
39
+ | What you get today | What GhostTrace adds |
40
+ |---|---|
41
+ | ✅ Agent took action X | ✅ Agent took action X |
42
+ | ❌ Nothing else | 👻 Agent **rejected** action Y because... |
43
+ | | 👻 Agent **rejected** action Z because... |
44
+ | | 📄 Full trace saved to `.ghost.json` |
45
+
46
+ Think of it as **`git log` for your agent's brain** — including the commits it decided *not* to make.
47
+
48
+ ---
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install ghosttrace
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Quick Start
59
+
60
+ ```bash
61
+ # Record an agent run
62
+ ghosttrace record
63
+
64
+ # Replay chosen actions only
65
+ ghosttrace replay gt_abc123.ghost.json
66
+
67
+ # Replay WITH phantom branches 👻
68
+ ghosttrace replay gt_abc123.ghost.json --show-phantoms
69
+ ```
70
+
71
+ ---
72
+
73
+ ## What Are Phantom Branches?
74
+
75
+ At every decision point, an AI agent evaluates multiple possible actions. It picks one. The rest disappear — unless you're running GhostTrace.
76
+
77
+ Each phantom branch records:
78
+ - **What** the agent considered doing
79
+ - **Why** it seemed like a good idea
80
+ - **Why it was rejected** ← *this is the most valuable part*
81
+
82
+ ---
83
+
84
+ ## Roadmap
85
+
86
+ - [x] `.ghost.json` schema v0.1
87
+ - [x] `ghosttrace record`
88
+ - [x] `ghosttrace replay` with rich terminal UI
89
+ - [x] `--show-phantoms` flag
90
+ - [ ] LangChain / CrewAI / OpenAI Agents SDK hooks
91
+ - [ ] `ghosttrace diff` — compare two traces
92
+ - [ ] Assertion engine — `--must-reject "delete_database"`
93
+ - [ ] Web UI for trace exploration
94
+ - [ ] VS Code extension
95
+
96
+ ---
97
+
98
+ ## License
99
+
100
+ MIT
101
+
102
+ ---
103
+
104
+ <div align="center">
105
+
106
+ *See what your AI agent almost did.* 👻
107
+
108
+ ⭐ Star this repo if GhostTrace helped you!
109
+
110
+ </div>
@@ -0,0 +1,2 @@
1
+ """GhostTrace — Record the roads your AI agent didn't take."""
2
+ __version__ = "0.1.0"
@@ -0,0 +1,65 @@
1
+ """GhostTrace CLI — Record and replay AI agent decisions."""
2
+
3
+ import typer
4
+ from rich.console import Console
5
+
6
+ from ghosttrace.mock_agent import run_mock_agent
7
+ from ghosttrace.recorder import save_trace
8
+ from ghosttrace.replayer import replay
9
+
10
+ app = typer.Typer(
11
+ name="ghosttrace",
12
+ help="👻 GhostTrace — Record AI agent decisions, including phantom branches.",
13
+ add_completion=False,
14
+ )
15
+ console = Console()
16
+
17
+
18
+ @app.command()
19
+ def record(
20
+ goal: str = typer.Option(
21
+ "Refactor the auth module to use OAuth2",
22
+ "--goal", "-g",
23
+ help="The goal/task for the mock agent.",
24
+ ),
25
+ output: str = typer.Option(
26
+ None,
27
+ "--output", "-o",
28
+ help="Output file path. Defaults to <session_id>.ghost.json",
29
+ ),
30
+ ) -> None:
31
+ """Run a mock agent and record its decisions to a .ghost.json file."""
32
+ console.print("\n👻 [bold cyan]GhostTrace[/bold cyan] — Recording agent run...\n")
33
+
34
+ trace = run_mock_agent(goal=goal)
35
+ path = save_trace(trace, output_path=output)
36
+
37
+ steps = trace["summary"]["total_steps"]
38
+ phantoms = trace["summary"]["total_phantoms"]
39
+
40
+ console.print(f" ✅ Recorded [bold]{steps}[/bold] decisions with "
41
+ f"[bold red]{phantoms}[/bold red] phantom branches.")
42
+ console.print(f" 📄 Saved to [bold green]{path}[/bold green]\n")
43
+ console.print(f" [dim]Replay with:[/dim] ghosttrace replay {path}")
44
+ console.print(f" [dim]See ghosts:[/dim] ghosttrace replay {path} --show-phantoms\n")
45
+
46
+
47
+ @app.command()
48
+ def replay_cmd(
49
+ file: str = typer.Argument(..., help="Path to a .ghost.json file."),
50
+ show_phantoms: bool = typer.Option(
51
+ False,
52
+ "--show-phantoms",
53
+ help="Show phantom branches (rejected alternatives).",
54
+ ),
55
+ ) -> None:
56
+ """Replay a recorded agent trace from a .ghost.json file."""
57
+ replay(file, show_phantoms=show_phantoms)
58
+
59
+
60
+ # Typer registers commands by function name, so we alias for a clean CLI
61
+ app.command(name="replay")(replay_cmd)
62
+
63
+
64
+ if __name__ == "__main__":
65
+ app()
@@ -0,0 +1,128 @@
1
+ """
2
+ A dummy agent that simulates decision-making with phantom branches.
3
+ Swap this out for a real agent later.
4
+ """
5
+
6
+ import random
7
+ import uuid
8
+ from datetime import datetime, timezone
9
+
10
+
11
+ MOCK_DECISIONS = [
12
+ {
13
+ "context": "Agent is deciding how to approach the auth refactor.",
14
+ "chosen": {
15
+ "action": "read_file",
16
+ "target": "src/auth.py",
17
+ "reasoning": "Need to understand current auth implementation first.",
18
+ },
19
+ "phantoms": [
20
+ {
21
+ "action": "search_codebase",
22
+ "target": "grep 'auth' --recursive",
23
+ "reasoning": "Scan the whole codebase for auth references.",
24
+ "rejection_reason": "Too broad; better to start with the known entry point.",
25
+ },
26
+ {
27
+ "action": "write_file",
28
+ "target": "src/auth_oauth2.py",
29
+ "reasoning": "Start writing the new OAuth2 module immediately.",
30
+ "rejection_reason": "Premature — haven't read existing code yet.",
31
+ },
32
+ ],
33
+ },
34
+ {
35
+ "context": "Agent has read auth.py. Deciding next step.",
36
+ "chosen": {
37
+ "action": "write_file",
38
+ "target": "src/auth_oauth2.py",
39
+ "reasoning": "Create new OAuth2 module based on understood structure.",
40
+ },
41
+ "phantoms": [
42
+ {
43
+ "action": "edit_file",
44
+ "target": "src/auth.py",
45
+ "reasoning": "Modify existing file in-place.",
46
+ "rejection_reason": "Risky — better to create new file and migrate.",
47
+ },
48
+ ],
49
+ },
50
+ {
51
+ "context": "New OAuth2 module written. Deciding how to handle migration.",
52
+ "chosen": {
53
+ "action": "edit_file",
54
+ "target": "src/routes.py",
55
+ "reasoning": "Update route imports to point to new auth module.",
56
+ },
57
+ "phantoms": [
58
+ {
59
+ "action": "delete_file",
60
+ "target": "src/auth.py",
61
+ "reasoning": "Remove old auth module immediately.",
62
+ "rejection_reason": "Too aggressive — need to update consumers first.",
63
+ },
64
+ {
65
+ "action": "run_command",
66
+ "target": "python -m pytest",
67
+ "reasoning": "Run tests before changing imports.",
68
+ "rejection_reason": "Tests will fail anyway since new module isn't wired up yet.",
69
+ },
70
+ ],
71
+ },
72
+ {
73
+ "context": "Routes updated. Final verification step.",
74
+ "chosen": {
75
+ "action": "run_command",
76
+ "target": "python -m pytest tests/",
77
+ "reasoning": "Verify everything works end-to-end after migration.",
78
+ },
79
+ "phantoms": [
80
+ {
81
+ "action": "run_command",
82
+ "target": "python -m pytest tests/test_auth.py",
83
+ "reasoning": "Run only auth tests for speed.",
84
+ "rejection_reason": "Migration could break non-auth routes too; full suite is safer.",
85
+ },
86
+ ],
87
+ },
88
+ ]
89
+
90
+
91
+ def run_mock_agent(goal: str = "Refactor the auth module to use OAuth2") -> dict:
92
+ """Simulate an agent run and return a ghost trace dict."""
93
+ session_id = f"gt_{uuid.uuid4().hex[:8]}"
94
+ now = datetime.now(timezone.utc)
95
+
96
+ decisions = []
97
+ for i, mock in enumerate(MOCK_DECISIONS, start=1):
98
+ decisions.append(
99
+ {
100
+ "step": i,
101
+ "timestamp": (now).isoformat(),
102
+ "context": mock["context"],
103
+ "chosen": mock["chosen"],
104
+ "phantoms": mock["phantoms"],
105
+ }
106
+ )
107
+
108
+ total_phantoms = sum(len(d["phantoms"]) for d in decisions)
109
+
110
+ return {
111
+ "version": "0.1",
112
+ "session": {
113
+ "id": session_id,
114
+ "timestamp": now.isoformat(),
115
+ "agent": {
116
+ "name": "mock-agent",
117
+ "model": "gpt-4o-mock",
118
+ "version": "0.1.0",
119
+ },
120
+ "goal": goal,
121
+ },
122
+ "decisions": decisions,
123
+ "summary": {
124
+ "total_steps": len(decisions),
125
+ "total_phantoms": total_phantoms,
126
+ "outcome": "success",
127
+ },
128
+ }
@@ -0,0 +1,15 @@
1
+ """Handles writing .ghost.json files."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+
7
+ def save_trace(trace: dict, output_path: str | None = None) -> Path:
8
+ """Save a ghost trace dict to a .ghost.json file."""
9
+ if output_path is None:
10
+ session_id = trace["session"]["id"]
11
+ output_path = f"{session_id}.ghost.json"
12
+
13
+ path = Path(output_path)
14
+ path.write_text(json.dumps(trace, indent=2), encoding="utf-8")
15
+ return path
@@ -0,0 +1,97 @@
1
+ """Handles replaying .ghost.json files with rich output."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ from rich.console import Console
7
+ from rich.panel import Panel
8
+ from rich.text import Text
9
+ from rich.table import Table
10
+
11
+ console = Console()
12
+
13
+
14
+ def load_trace(filepath: str) -> dict:
15
+ """Load and return a ghost trace from a .ghost.json file."""
16
+ path = Path(filepath)
17
+ if not path.exists():
18
+ console.print(f"[red]Error:[/red] File not found: {filepath}")
19
+ raise SystemExit(1)
20
+ return json.loads(path.read_text(encoding="utf-8"))
21
+
22
+
23
+ def replay(filepath: str, show_phantoms: bool = False) -> None:
24
+ """Replay a ghost trace to the terminal."""
25
+ trace = load_trace(filepath)
26
+ session = trace["session"]
27
+ decisions = trace["decisions"]
28
+ summary = trace["summary"]
29
+
30
+ # Header
31
+ console.print()
32
+ console.print(
33
+ Panel(
34
+ f"[bold cyan]GhostTrace Replay[/bold cyan] 👻\n\n"
35
+ f" Session: [yellow]{session['id']}[/yellow]\n"
36
+ f" Agent: {session['agent']['name']} ({session['agent']['model']})\n"
37
+ f" Goal: [italic]{session['goal']}[/italic]\n"
38
+ f" Steps: {summary['total_steps']} | "
39
+ f" Phantoms: {summary['total_phantoms']}",
40
+ title="Session Info",
41
+ border_style="cyan",
42
+ )
43
+ )
44
+
45
+ # Decisions
46
+ for decision in decisions:
47
+ console.print()
48
+ step = decision["step"]
49
+ ctx = decision["context"]
50
+ chosen = decision["chosen"]
51
+
52
+ # Step header
53
+ console.rule(f"[bold]Step {step}[/bold]", style="blue")
54
+ console.print(f" [dim]{ctx}[/dim]\n")
55
+
56
+ # Chosen action
57
+ console.print(
58
+ Panel(
59
+ f"[green bold]✔ {chosen['action']}[/green bold] → "
60
+ f"[white]{chosen['target']}[/white]\n"
61
+ f" [dim]{chosen['reasoning']}[/dim]",
62
+ title="[green]Chosen Action[/green]",
63
+ border_style="green",
64
+ )
65
+ )
66
+
67
+ # Phantom branches
68
+ if show_phantoms and decision.get("phantoms"):
69
+ for j, phantom in enumerate(decision["phantoms"], start=1):
70
+ console.print(
71
+ Panel(
72
+ f"[red bold]✘ {phantom['action']}[/red bold] → "
73
+ f"[white]{phantom['target']}[/white]\n"
74
+ f" [dim italic]Considered:[/dim italic] {phantom['reasoning']}\n"
75
+ f" [red]Rejected:[/red] {phantom['rejection_reason']}",
76
+ title=f"[red]Phantom {j}[/red] 👻",
77
+ border_style="red",
78
+ style="dim",
79
+ )
80
+ )
81
+
82
+ # Footer
83
+ console.print()
84
+ console.rule(style="cyan")
85
+ outcome_color = "green" if summary["outcome"] == "success" else "red"
86
+ console.print(
87
+ f" Outcome: [{outcome_color} bold]{summary['outcome'].upper()}"
88
+ f"[/{outcome_color} bold] | "
89
+ f"{summary['total_steps']} steps, "
90
+ f"{summary['total_phantoms']} phantom branches"
91
+ )
92
+ if not show_phantoms and summary["total_phantoms"] > 0:
93
+ console.print(
94
+ f"\n [dim]💡 Tip: Re-run with [bold]--show-phantoms[/bold] to see "
95
+ f"{summary['total_phantoms']} rejected alternatives.[/dim]"
96
+ )
97
+ console.print()
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: ghosttrace
3
+ Version: 0.1.0
4
+ Summary: Record AI agent decisions, including phantom branches.
5
+ Requires-Python: >=3.10
6
+ License-File: LICENSE
7
+ Requires-Dist: typer[all]>=0.9.0
8
+ Requires-Dist: rich>=13.0.0
9
+ Dynamic: license-file
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ ghosttrace/__init__.py
5
+ ghosttrace/cli.py
6
+ ghosttrace/mock_agent.py
7
+ ghosttrace/recorder.py
8
+ ghosttrace/replayer.py
9
+ ghosttrace.egg-info/PKG-INFO
10
+ ghosttrace.egg-info/SOURCES.txt
11
+ ghosttrace.egg-info/dependency_links.txt
12
+ ghosttrace.egg-info/entry_points.txt
13
+ ghosttrace.egg-info/requires.txt
14
+ ghosttrace.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ghosttrace = ghosttrace.cli:app
@@ -0,0 +1,2 @@
1
+ typer[all]>=0.9.0
2
+ rich>=13.0.0
@@ -0,0 +1 @@
1
+ ghosttrace
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "ghosttrace"
3
+ version = "0.1.0"
4
+ description = "Record AI agent decisions, including phantom branches."
5
+ requires-python = ">=3.10"
6
+ dependencies = [
7
+ "typer[all]>=0.9.0",
8
+ "rich>=13.0.0",
9
+ ]
10
+
11
+ [project.scripts]
12
+ ghosttrace = "ghosttrace.cli:app"
13
+
14
+ [build-system]
15
+ requires = ["setuptools>=61.0"]
16
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+