elliot-stack 1.0.17 → 1.0.19

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.
Files changed (46) hide show
  1. package/README.md +17 -0
  2. package/bin/install.cjs +322 -43
  3. package/hooks/repo-search-nudge.js +31 -0
  4. package/package.json +3 -2
  5. package/skills/estack-read-claude-session-history/SKILL.md +196 -0
  6. package/skills/estack-read-claude-session-history/references/jsonl-schema.md +126 -0
  7. package/skills/estack-read-claude-session-history/references/modes.md +366 -0
  8. package/skills/estack-read-claude-session-history/references/recipes.md +237 -0
  9. package/skills/estack-read-claude-session-history/scripts/lib/__init__.py +1 -0
  10. package/skills/estack-read-claude-session-history/scripts/lib/parser.py +460 -0
  11. package/skills/estack-read-claude-session-history/scripts/lib/paths.py +234 -0
  12. package/skills/estack-read-claude-session-history/scripts/lib/search.py +179 -0
  13. package/skills/estack-read-claude-session-history/scripts/lib/subagents.py +88 -0
  14. package/skills/estack-read-claude-session-history/scripts/lib/tools.py +144 -0
  15. package/skills/estack-read-claude-session-history/scripts/read_transcript.py +1448 -0
  16. package/skills/estack-read-claude-session-history/scripts/tests/conftest.py +40 -0
  17. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/README.md +20 -0
  18. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/all-noise.jsonl +4 -0
  19. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/basic-session.jsonl +2 -0
  20. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/interrupted.jsonl +2 -0
  21. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/multi-compact.jsonl +8 -0
  22. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/pending-user.jsonl +2 -0
  23. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-no-meta/subagents/agent-aaa.jsonl +2 -0
  24. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-no-meta.jsonl +2 -0
  25. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-parent/subagents/agent-xyz123.jsonl +2 -0
  26. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-parent/subagents/agent-xyz123.meta.json +1 -0
  27. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/subagent-parent.jsonl +4 -0
  28. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/time-spread.jsonl +6 -0
  29. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/timeline-day-test.jsonl +5 -0
  30. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/tool-zoo.jsonl +10 -0
  31. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/truncated.jsonl +3 -0
  32. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/unicode.jsonl +2 -0
  33. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/with-advisor.jsonl +3 -0
  34. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/with-compact.jsonl +5 -0
  35. package/skills/estack-read-claude-session-history/scripts/tests/fixtures/with-thinking.jsonl +2 -0
  36. package/skills/estack-read-claude-session-history/scripts/tests/test_backup_roots.py +56 -0
  37. package/skills/estack-read-claude-session-history/scripts/tests/test_json_format.py +201 -0
  38. package/skills/estack-read-claude-session-history/scripts/tests/test_modes.py +199 -0
  39. package/skills/estack-read-claude-session-history/scripts/tests/test_parser.py +195 -0
  40. package/skills/estack-read-claude-session-history/scripts/tests/test_paths.py +133 -0
  41. package/skills/estack-read-claude-session-history/scripts/tests/test_search.py +78 -0
  42. package/skills/estack-read-claude-session-history/scripts/tests/test_subagents.py +43 -0
  43. package/skills/estack-read-claude-session-history/scripts/tests/test_timeline.py +175 -0
  44. package/skills/estack-read-claude-session-history/scripts/tests/test_timezone_and_project.py +212 -0
  45. package/skills/estack-read-claude-session-history/scripts/tests/test_tools.py +80 -0
  46. package/skills/estack-repo-search/SKILL.md +0 -65
@@ -0,0 +1,40 @@
1
+ """Shared pytest fixtures and import-path setup."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ import pytest
9
+
10
+
11
+ # Ensure UTF-8 output regardless of console code page (Windows)
12
+ if sys.stdout.encoding and sys.stdout.encoding.lower() != "utf-8":
13
+ try:
14
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
15
+ except (AttributeError, OSError):
16
+ pass
17
+
18
+
19
+ THIS_DIR = Path(__file__).resolve().parent
20
+ SCRIPTS_DIR = THIS_DIR.parent
21
+ FIXTURES_DIR = THIS_DIR / "fixtures"
22
+
23
+ # Make `from lib...` work in tests
24
+ if str(SCRIPTS_DIR) not in sys.path:
25
+ sys.path.insert(0, str(SCRIPTS_DIR))
26
+
27
+
28
+ @pytest.fixture
29
+ def fixtures_dir() -> Path:
30
+ return FIXTURES_DIR
31
+
32
+
33
+ @pytest.fixture
34
+ def scripts_dir() -> Path:
35
+ return SCRIPTS_DIR
36
+
37
+
38
+ @pytest.fixture
39
+ def cli_path() -> Path:
40
+ return SCRIPTS_DIR / "read_transcript.py"
@@ -0,0 +1,20 @@
1
+ # Test fixtures
2
+
3
+ Hand-crafted minimal JSONL files, one scenario per file. Keep them small (≤50 lines) — they're easier to reason about than real session snapshots and don't carry PII.
4
+
5
+ | File | Purpose |
6
+ |---|---|
7
+ | `basic-session.jsonl` | One user + one assistant exchange. Sanity check for the parser. |
8
+ | `with-compact.jsonl` | Conversation interrupted by a single `/compact` marker. |
9
+ | `multi-compact.jsonl` | Two `/compact` markers — exercises "most recent" logic. |
10
+ | `with-advisor.jsonl` | Contains an `advisor_tool_result` block. |
11
+ | `with-thinking.jsonl` | Contains a `thinking` block plus normal text. |
12
+ | `all-noise.jsonl` | Only `ai-title` + `attachment` entries — should look empty to signal queries. |
13
+ | `subagent-parent.jsonl` | Parent session that spawns one subagent via the `Agent` tool. |
14
+ | `subagent-no-meta.jsonl` | Parent session with a sibling subagent file but no `.meta.json` sidecar — `load_meta` must fall back. |
15
+ | `tool-zoo.jsonl` | One call to each of Bash, Read, Edit, Write, Agent, Skill, Glob, Grep. |
16
+ | `time-spread.jsonl` | Six messages over a known time range — exercises `--since`/`--until`. |
17
+ | `truncated.jsonl` | Final line is missing its newline AND is malformed JSON — should be dropped silently. |
18
+ | `unicode.jsonl` | Contains emoji + CJK characters — exercises UTF-8 decoding. |
19
+ | `pending-user.jsonl` | Last assistant message ends with `?` — `infer_status` should return `pending-user`. |
20
+ | `interrupted.jsonl` | Final assistant message has a `tool_use` block with no matching `tool_result` — status `interrupted`. |
@@ -0,0 +1,4 @@
1
+ {"type":"ai-title","aiTitle":"Test session"}
2
+ {"type":"attachment","data":{"path":"foo.png"}}
3
+ {"type":"permission-mode","mode":"plan"}
4
+ {"type":"file-history-snapshot","content":{"file":"bar.py"}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Hello Claude"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Hi there. Here is help."}]}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Run a tool"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Running."},{"type":"tool_use","id":"toolu_999","name":"Bash","input":{"command":"sleep 999"}}]}}
@@ -0,0 +1,8 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"First"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"R1"}]}}
3
+ {"type":"user","timestamp":"2026-05-01T10:30:00Z","message":{"role":"user","content":"This session is being continued from a previous conversation. Round 1"}}
4
+ {"type":"user","timestamp":"2026-05-01T11:00:00Z","message":{"role":"user","content":"Mid"}}
5
+ {"type":"assistant","timestamp":"2026-05-01T11:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"R2"}]}}
6
+ {"type":"user","timestamp":"2026-05-01T11:30:00Z","message":{"role":"user","content":"This session is being continued from a previous conversation. Round 2"}}
7
+ {"type":"user","timestamp":"2026-05-01T12:00:00Z","message":{"role":"user","content":"Last"}}
8
+ {"type":"assistant","timestamp":"2026-05-01T12:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"R3"}]}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Hello"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Sure, do you want me to A, B, or C?"}]}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:10Z","message":{"role":"user","content":"Do thing"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:20Z","message":{"role":"assistant","content":[{"type":"text","text":"Done."}]}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Run an agent"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Agent ran."}]}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:10Z","message":{"role":"user","content":"Find the bug in foo.py"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:20Z","message":{"role":"assistant","content":[{"type":"text","text":"Found it: foo.py line 42 — off-by-one in loop bound."}]}}
@@ -0,0 +1 @@
1
+ {"agentType": "Explore", "description": "Find the bug in foo.py"}
@@ -0,0 +1,4 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Investigate the bug"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"toolu_01abc","name":"Agent","input":{"description":"Find the bug","prompt":"Look at file X","subagent_type":"Explore"}}]}}
3
+ {"type":"user","timestamp":"2026-05-01T10:00:30Z","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_01abc","content":"Found it in foo.py:42"}]}}
4
+ {"type":"assistant","timestamp":"2026-05-01T10:00:35Z","message":{"role":"assistant","content":[{"type":"text","text":"Got the report, patching foo.py."}]}}
@@ -0,0 +1,6 @@
1
+ {"type":"user","timestamp":"2026-04-15T08:00:00Z","message":{"role":"user","content":"Apr 15 morning"}}
2
+ {"type":"assistant","timestamp":"2026-04-15T08:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Apr 15 reply"}]}}
3
+ {"type":"user","timestamp":"2026-05-01T12:00:00Z","message":{"role":"user","content":"May 1 noon"}}
4
+ {"type":"assistant","timestamp":"2026-05-01T12:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"May 1 reply"}]}}
5
+ {"type":"user","timestamp":"2026-05-15T20:00:00Z","message":{"role":"user","content":"May 15 evening"}}
6
+ {"type":"assistant","timestamp":"2026-05-15T20:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"May 15 reply"}]}}
@@ -0,0 +1,5 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Start the CRM cleanup"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:05:00Z","message":{"role":"assistant","content":[{"type":"text","text":"Working on it."}]}}
3
+ {"type":"assistant","timestamp":"2026-05-01T10:08:00Z","message":{"role":"assistant","content":[{"type":"text","text":"First pass done."}]}}
4
+ {"type":"user","timestamp":"2026-05-01T12:00:00Z","message":{"role":"user","content":"Back — continue"}}
5
+ {"type":"assistant","timestamp":"2026-05-01T12:02:00Z","message":{"role":"assistant","content":[{"type":"text","text":"Resumed and finished."}]}}
@@ -0,0 +1,10 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Run all the tools"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:01Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t1","name":"Bash","input":{"command":"ls -la /tmp"}}]}}
3
+ {"type":"assistant","timestamp":"2026-05-01T10:00:02Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t2","name":"PowerShell","input":{"command":"Get-ChildItem"}}]}}
4
+ {"type":"assistant","timestamp":"2026-05-01T10:00:03Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t3","name":"Read","input":{"file_path":"C:\\foo.py","offset":1,"limit":50}}]}}
5
+ {"type":"assistant","timestamp":"2026-05-01T10:00:04Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t4","name":"Edit","input":{"file_path":"C:\\foo.py","old_string":"a","new_string":"b"}}]}}
6
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t5","name":"Write","input":{"file_path":"C:\\bar.py","content":"print('hi')"}}]}}
7
+ {"type":"assistant","timestamp":"2026-05-01T10:00:06Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t6","name":"Agent","input":{"description":"Find X","subagent_type":"Explore"}}]}}
8
+ {"type":"assistant","timestamp":"2026-05-01T10:00:07Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t7","name":"Skill","input":{"skill":"using-superpowers"}}]}}
9
+ {"type":"assistant","timestamp":"2026-05-01T10:00:08Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t8","name":"Glob","input":{"pattern":"**/*.py"}}]}}
10
+ {"type":"assistant","timestamp":"2026-05-01T10:00:09Z","message":{"role":"assistant","content":[{"type":"tool_use","id":"t9","name":"Grep","input":{"pattern":"TODO"}}]}}
@@ -0,0 +1,3 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Valid line"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Valid reply"}]}}
3
+ {"type":"user","timestamp":"2026-05-01T10:01:00Z","message":{"role":"user","content":"Trunc
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Hello 🌍, 你好"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Привет — 안녕하세요!"}]}}
@@ -0,0 +1,3 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Get advice"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"Calling advisor..."},{"type":"advisor_tool_result","content":{"text":"The advisor says do X then Y."}}]}}
3
+ {"type":"assistant","timestamp":"2026-05-01T10:00:10Z","message":{"role":"assistant","content":[{"type":"text","text":"OK, doing X."}]}}
@@ -0,0 +1,5 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"First question"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"First answer"}]}}
3
+ {"type":"user","timestamp":"2026-05-01T11:00:00Z","message":{"role":"user","content":"This session is being continued from a previous conversation. Summary follows..."}}
4
+ {"type":"user","timestamp":"2026-05-01T11:00:10Z","message":{"role":"user","content":"After compact"}}
5
+ {"type":"assistant","timestamp":"2026-05-01T11:00:15Z","message":{"role":"assistant","content":[{"type":"text","text":"Post-compact reply"}]}}
@@ -0,0 +1,2 @@
1
+ {"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"Solve this"}}
2
+ {"type":"assistant","timestamp":"2026-05-01T10:00:05Z","message":{"role":"assistant","content":[{"type":"thinking","thinking":"Let me think step by step..."},{"type":"text","text":"The answer is 42."}]}}
@@ -0,0 +1,56 @@
1
+ """Tests for backup-root resolution (--root mirror|snapshot-*|<abs-path>)."""
2
+
3
+ from pathlib import Path
4
+
5
+ import pytest
6
+
7
+ from lib import paths as P
8
+
9
+
10
+ def test_root_live_default():
11
+ assert P.resolve_root(None) == P.DEFAULT_LIVE_PROJECTS
12
+ assert P.resolve_root("live") == P.DEFAULT_LIVE_PROJECTS
13
+
14
+
15
+ def test_root_mirror_path_shape():
16
+ r = P.resolve_root("mirror")
17
+ parts = r.parts
18
+ assert ".claude-backups" in parts
19
+ assert "mirror" in parts
20
+ assert parts[-1] == "projects"
21
+
22
+
23
+ def test_root_snapshot_24h_path_shape():
24
+ r = P.resolve_root("snapshot-24h")
25
+ assert "snapshot-24h" in r.parts
26
+ assert r.name == "projects"
27
+
28
+
29
+ def test_root_all_known():
30
+ for name in ("mirror", "snapshot-24h", "snapshot-1w", "snapshot-1mo"):
31
+ r = P.resolve_root(name)
32
+ assert name in r.parts
33
+
34
+
35
+ def test_root_absolute_path(tmp_path: Path):
36
+ fake = tmp_path / "weird-root"
37
+ fake.mkdir()
38
+ assert P.resolve_root(str(fake)) == fake
39
+
40
+
41
+ def test_root_unknown_relative_raises():
42
+ with pytest.raises(ValueError):
43
+ P.resolve_root("bogus")
44
+
45
+
46
+ def test_find_project_dir_uses_root(tmp_path: Path):
47
+ # Build a fake root with a fake project dir
48
+ proj = tmp_path / "C--Users-foo-bar"
49
+ proj.mkdir()
50
+ found = P.find_project_dir("C:\\Users\\foo\\bar", root=tmp_path)
51
+ assert found == proj
52
+
53
+
54
+ def test_find_project_dir_not_found(tmp_path: Path):
55
+ with pytest.raises(FileNotFoundError):
56
+ P.find_project_dir("C:\\does\\not\\exist", root=tmp_path)
@@ -0,0 +1,201 @@
1
+ """Tests for --format json across modes."""
2
+
3
+ import json
4
+ import os
5
+ import shutil
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ import pytest
11
+
12
+
13
+ def _run_cli(cli_path, *args, env_overrides=None):
14
+ env = dict(os.environ)
15
+ env["PYTHONIOENCODING"] = "utf-8"
16
+ if env_overrides:
17
+ env.update(env_overrides)
18
+ return subprocess.run(
19
+ [sys.executable, str(cli_path), *args],
20
+ capture_output=True,
21
+ text=True,
22
+ encoding="utf-8",
23
+ env=env,
24
+ )
25
+
26
+
27
+ def _json(r):
28
+ assert r.returncode == 0, r.stderr
29
+ return json.loads(r.stdout)
30
+
31
+
32
+ def test_last_json(cli_path, fixtures_dir):
33
+ data = _json(_run_cli(
34
+ cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"),
35
+ "--mode", "last", "--format", "json",
36
+ ))
37
+ assert isinstance(data, list)
38
+ assert data[-1]["n_from_end"] == 1
39
+ assert "Here is help" in data[-1]["text"]
40
+
41
+
42
+ def test_json_alias_flag(cli_path, fixtures_dir):
43
+ data = _json(_run_cli(
44
+ cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"),
45
+ "--mode", "last", "--json",
46
+ ))
47
+ assert isinstance(data, list)
48
+
49
+
50
+ def test_advisor_json(cli_path, fixtures_dir):
51
+ data = _json(_run_cli(
52
+ cli_path, "--file", str(fixtures_dir / "with-advisor.jsonl"),
53
+ "--mode", "advisor", "--format", "json",
54
+ ))
55
+ assert data == ["The advisor says do X then Y."]
56
+
57
+
58
+ def test_pre_compact_json(cli_path, fixtures_dir):
59
+ data = _json(_run_cli(
60
+ cli_path, "--file", str(fixtures_dir / "with-compact.jsonl"),
61
+ "--mode", "pre-compact", "--format", "json",
62
+ ))
63
+ assert data["found_compact"] is True
64
+ assert any("First answer" in m["text"] for m in data["messages"])
65
+
66
+
67
+ def test_dump_json(cli_path, fixtures_dir):
68
+ data = _json(_run_cli(
69
+ cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"),
70
+ "--mode", "dump", "--format", "json",
71
+ ))
72
+ assert isinstance(data, list)
73
+ assert data[0]["role"] == "user"
74
+
75
+
76
+ def test_debug_json(cli_path, fixtures_dir):
77
+ data = _json(_run_cli(
78
+ cli_path, "--file", str(fixtures_dir / "with-advisor.jsonl"),
79
+ "--mode", "debug", "--format", "json",
80
+ ))
81
+ assert data["advisor_blocks"] == 1
82
+ assert "entry_types" in data
83
+
84
+
85
+ def test_brief_json(cli_path, fixtures_dir):
86
+ data = _json(_run_cli(
87
+ cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
88
+ "--mode", "brief", "--format", "json",
89
+ ))
90
+ assert data["exists"] is True
91
+ assert data["tool_counts"]["Bash"] == 1
92
+ assert isinstance(data["files_touched"], list)
93
+
94
+
95
+ def test_changelog_json(cli_path, fixtures_dir):
96
+ data = _json(_run_cli(
97
+ cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
98
+ "--mode", "changelog", "--format", "json",
99
+ ))
100
+ assert len(data) == 9
101
+ assert data[0]["tool"] == "Bash"
102
+ assert "input" not in data[0]
103
+
104
+
105
+ def test_tool_calls_json_includes_input(cli_path, fixtures_dir):
106
+ data = _json(_run_cli(
107
+ cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
108
+ "--mode", "tool-calls", "--format", "json", "--tool", "Bash",
109
+ ))
110
+ assert len(data) == 1
111
+ assert data[0]["input"]["command"] == "ls -la /tmp"
112
+
113
+
114
+ def test_file_edits_json(cli_path, fixtures_dir):
115
+ data = _json(_run_cli(
116
+ cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
117
+ "--mode", "file-edits", "--format", "json",
118
+ ))
119
+ paths = [row["path"] for row in data]
120
+ assert any("foo.py" in p for p in paths)
121
+
122
+
123
+ def test_subagent_finals_json(cli_path, fixtures_dir):
124
+ data = _json(_run_cli(
125
+ cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
126
+ "--mode", "subagent-finals", "--format", "json",
127
+ ))
128
+ assert data[0]["agentType"] == "Explore"
129
+ assert "Found it" in data[0]["text"]
130
+
131
+
132
+ def test_search_json_single_file(cli_path, fixtures_dir):
133
+ data = _json(_run_cli(
134
+ cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"),
135
+ "--mode", "search", "--query", "help", "--format", "json",
136
+ ))
137
+ assert len(data) == 1
138
+ assert data[0]["role"] == "assistant"
139
+
140
+
141
+ def test_list_json(cli_path, fixtures_dir, tmp_path):
142
+ fake_root = tmp_path / "projects"
143
+ fake_proj = fake_root / "C--fake-proj"
144
+ fake_proj.mkdir(parents=True)
145
+ shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
146
+ data = _json(_run_cli(
147
+ cli_path, "--root", str(fake_root), "--all-projects",
148
+ "--mode", "list", "--format", "json",
149
+ ))
150
+ assert len(data) == 1
151
+ assert data[0]["uuid"] == "abc"
152
+
153
+
154
+ def test_journal_json(cli_path, fixtures_dir, tmp_path):
155
+ fake_root = tmp_path / "projects"
156
+ fake_proj = fake_root / "C--fake-proj"
157
+ fake_proj.mkdir(parents=True)
158
+ shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "def.jsonl")
159
+ data = _json(_run_cli(
160
+ cli_path, "--root", str(fake_root), "--all-projects",
161
+ "--mode", "journal", "--since", "2020-01-01", "--format", "json",
162
+ ))
163
+ assert data[0]["uuid"] == "def"
164
+ assert data[0]["tool_counts"]["Bash"] == 1
165
+
166
+
167
+ def test_count_json(cli_path, fixtures_dir, tmp_path):
168
+ fake_root = tmp_path / "projects"
169
+ fake_proj = fake_root / "C--fake-proj"
170
+ fake_proj.mkdir(parents=True)
171
+ shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
172
+ data = _json(_run_cli(
173
+ cli_path, "--root", str(fake_root), "--all-projects",
174
+ "--mode", "count", "--query", "help", "--format", "json",
175
+ ))
176
+ assert data == {"sessions": 1, "messages": 2, "matches": 1}
177
+
178
+
179
+ def test_count_text_unchanged(cli_path, fixtures_dir, tmp_path):
180
+ fake_root = tmp_path / "projects"
181
+ fake_proj = fake_root / "C--fake-proj"
182
+ fake_proj.mkdir(parents=True)
183
+ shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
184
+ r = _run_cli(
185
+ cli_path, "--root", str(fake_root), "--all-projects",
186
+ "--mode", "count", "--query", "help",
187
+ )
188
+ assert r.returncode == 0
189
+ assert r.stdout.strip() == "1"
190
+ assert "1 sessions" in r.stderr
191
+
192
+
193
+ def test_diff_json(cli_path, fixtures_dir):
194
+ data = _json(_run_cli(
195
+ cli_path, "--mode", "diff",
196
+ "--file-a", str(fixtures_dir / "basic-session.jsonl"),
197
+ "--file-b", str(fixtures_dir / "with-thinking.jsonl"),
198
+ "--format", "json",
199
+ ))
200
+ sources = {m["source"] for m in data["messages"]}
201
+ assert sources == {"A", "B"}
@@ -0,0 +1,199 @@
1
+ """End-to-end CLI tests via subprocess.run.
2
+
3
+ Exercises mode dispatch + argument parsing. Library-level behavior is
4
+ covered by the unit tests in test_paths/parser/tools/search/subagents.
5
+ """
6
+
7
+ import json
8
+ import os
9
+ import shutil
10
+ import subprocess
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ import pytest
15
+
16
+
17
+ def _run_cli(cli_path, *args, env_overrides=None):
18
+ env = dict(os.environ)
19
+ env["PYTHONIOENCODING"] = "utf-8"
20
+ if env_overrides:
21
+ env.update(env_overrides)
22
+ return subprocess.run(
23
+ [sys.executable, str(cli_path), *args],
24
+ capture_output=True,
25
+ text=True,
26
+ encoding="utf-8",
27
+ env=env,
28
+ )
29
+
30
+
31
+ def test_help(cli_path):
32
+ r = _run_cli(cli_path, "--help")
33
+ assert r.returncode == 0
34
+ assert "--mode" in r.stdout
35
+
36
+
37
+ def test_last_mode(cli_path, fixtures_dir):
38
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"), "--mode", "last")
39
+ assert r.returncode == 0
40
+ assert "Here is help" in r.stdout
41
+
42
+
43
+ def test_advisor_mode(cli_path, fixtures_dir):
44
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "with-advisor.jsonl"), "--mode", "advisor")
45
+ assert r.returncode == 0
46
+ assert "advisor" in r.stdout.lower()
47
+
48
+
49
+ def test_pre_compact_mode(cli_path, fixtures_dir):
50
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "with-compact.jsonl"), "--mode", "pre-compact")
51
+ assert r.returncode == 0
52
+ assert "Pre-compact" in r.stdout or "First answer" in r.stdout
53
+
54
+
55
+ def test_debug_mode(cli_path, fixtures_dir):
56
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "basic-session.jsonl"), "--mode", "debug")
57
+ assert r.returncode == 0
58
+ assert "Entry type distribution" in r.stdout
59
+
60
+
61
+ def test_brief_mode(cli_path, fixtures_dir):
62
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "brief")
63
+ assert r.returncode == 0
64
+ body = r.stdout
65
+ # 6 lines expected
66
+ assert "intent:" in body
67
+ assert "last:" in body
68
+ assert "edits:" in body
69
+ assert "tools:" in body
70
+ assert "subagents:" in body
71
+
72
+
73
+ def test_brief_with_include_subagents(cli_path, fixtures_dir):
74
+ r = _run_cli(
75
+ cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
76
+ "--mode", "brief", "--include-subagents",
77
+ )
78
+ assert r.returncode == 0
79
+ assert "subagent" in r.stdout.lower()
80
+ assert "Found it" in r.stdout
81
+
82
+
83
+ def test_changelog(cli_path, fixtures_dir):
84
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "changelog")
85
+ assert r.returncode == 0
86
+ assert "Bash" in r.stdout
87
+ assert "Read" in r.stdout
88
+
89
+
90
+ def test_file_edits(cli_path, fixtures_dir):
91
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "file-edits")
92
+ assert r.returncode == 0
93
+ assert "foo.py" in r.stdout
94
+ assert "bar.py" in r.stdout
95
+
96
+
97
+ def test_tool_calls(cli_path, fixtures_dir):
98
+ r = _run_cli(cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"), "--mode", "tool-calls")
99
+ assert r.returncode == 0
100
+ assert "Bash" in r.stdout
101
+
102
+
103
+ def test_tool_calls_filter(cli_path, fixtures_dir):
104
+ r = _run_cli(
105
+ cli_path, "--file", str(fixtures_dir / "tool-zoo.jsonl"),
106
+ "--mode", "tool-calls", "--tool", "Bash",
107
+ )
108
+ assert r.returncode == 0
109
+ assert "Bash" in r.stdout
110
+ assert "Glob" not in r.stdout
111
+
112
+
113
+ def test_subagent_list(cli_path, fixtures_dir):
114
+ r = _run_cli(
115
+ cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
116
+ "--mode", "subagent-list",
117
+ )
118
+ assert r.returncode == 0
119
+ assert "agent-xyz123" in r.stdout
120
+
121
+
122
+ def test_subagent_finals(cli_path, fixtures_dir):
123
+ r = _run_cli(
124
+ cli_path, "--file", str(fixtures_dir / "subagent-parent.jsonl"),
125
+ "--mode", "subagent-finals",
126
+ )
127
+ assert r.returncode == 0
128
+ assert "Found it" in r.stdout
129
+
130
+
131
+ def test_diff_mode(cli_path, fixtures_dir):
132
+ r = _run_cli(
133
+ cli_path, "--mode", "diff",
134
+ "--file-a", str(fixtures_dir / "basic-session.jsonl"),
135
+ "--file-b", str(fixtures_dir / "with-thinking.jsonl"),
136
+ )
137
+ assert r.returncode == 0
138
+ assert "A>" in r.stdout
139
+ assert "B>" in r.stdout
140
+
141
+
142
+ def test_lookup_no_match(cli_path, fixtures_dir, tmp_path):
143
+ # Point --root at an empty dir so lookup definitely misses
144
+ r = _run_cli(cli_path, "--root", str(tmp_path), "--mode", "lookup", "--uuid", "nope")
145
+ assert r.returncode == 1
146
+
147
+
148
+ def test_list_legacy_format(cli_path, fixtures_dir, tmp_path):
149
+ # Build a fake project root + cwd that matches encoding
150
+ fake_root = tmp_path / "projects"
151
+ fake_proj = fake_root / "C--fake-proj"
152
+ fake_proj.mkdir(parents=True)
153
+ shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
154
+ r = _run_cli(cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj", "--list")
155
+ assert r.returncode == 0
156
+ assert "abc.jsonl" in r.stdout
157
+
158
+
159
+ def test_exclude_current(cli_path, fixtures_dir, tmp_path):
160
+ fake_root = tmp_path / "projects"
161
+ fake_proj = fake_root / "C--fake-proj"
162
+ fake_proj.mkdir(parents=True)
163
+ shutil.copy(fixtures_dir / "basic-session.jsonl", fake_proj / "abc.jsonl")
164
+ shutil.copy(fixtures_dir / "tool-zoo.jsonl", fake_proj / "def.jsonl")
165
+ r = _run_cli(
166
+ cli_path, "--root", str(fake_root), "--cwd", "C:\\fake\\proj",
167
+ "--mode", "list", "--exclude-current",
168
+ env_overrides={"CLAUDE_SESSION_ID": "abc"},
169
+ )
170
+ assert r.returncode == 0
171
+ assert "def" in r.stdout
172
+ assert "abc" not in r.stdout
173
+
174
+
175
+ def test_dump_large_file_degrades(cli_path, fixtures_dir, tmp_path):
176
+ # Build a 6MB padded fixture by writing many valid lines
177
+ big = tmp_path / "big.jsonl"
178
+ line = '{"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"'
179
+ pad = "x" * 1000 + '"}}\n'
180
+ with open(big, "w", encoding="utf-8") as f:
181
+ # Each line ~1KB → write ~7000 to hit 6MB+
182
+ for _ in range(7000):
183
+ f.write(line + pad)
184
+ r = _run_cli(cli_path, "--file", str(big), "--mode", "dump")
185
+ assert r.returncode == 0
186
+ assert "degraded" in r.stderr.lower()
187
+
188
+
189
+ def test_dump_large_file_force(cli_path, tmp_path):
190
+ big = tmp_path / "big.jsonl"
191
+ line = '{"type":"user","timestamp":"2026-05-01T10:00:00Z","message":{"role":"user","content":"'
192
+ pad = "x" * 1000 + '"}}\n'
193
+ with open(big, "w", encoding="utf-8") as f:
194
+ for _ in range(7000):
195
+ f.write(line + pad)
196
+ r = _run_cli(cli_path, "--file", str(big), "--mode", "dump", "--force-dump")
197
+ assert r.returncode == 0
198
+ # No degrade note when forced
199
+ assert "degraded" not in r.stderr.lower()