copilot-session-tools 0.19.0__tar.gz → 0.19.2__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.
Files changed (37) hide show
  1. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/CHANGELOG.md +4 -0
  2. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/PKG-INFO +3 -1
  3. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/README.md +2 -0
  4. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/pyproject.toml +1 -1
  5. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/pyproject.toml.orig +1 -1
  6. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/__init__.py +1 -1
  7. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/cli.py +2 -2
  8. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/db_search.py +36 -26
  9. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/db_storage.py +2 -0
  10. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/__init__.py +1 -1
  11. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/cli.py +235 -176
  12. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/transcript_cleanup.py +7 -8
  13. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/web/templates/session.html +4 -3
  14. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/LICENSE +0 -0
  15. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/content_types.py +0 -0
  16. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/database.py +0 -0
  17. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/db_retrieval.py +0 -0
  18. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/db_schema.py +0 -0
  19. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/html_exporter.py +0 -0
  20. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/markdown_exporter.py +0 -0
  21. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/py.typed +0 -0
  22. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/refresh.py +0 -0
  23. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/content.py +0 -0
  24. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/diff.py +0 -0
  25. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/discovery.py +0 -0
  26. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/git.py +0 -0
  27. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/models.py +0 -0
  28. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/shared.py +0 -0
  29. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/scanner/vscode.py +0 -0
  30. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/sources.py +0 -0
  31. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/utils.py +0 -0
  32. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/version_check.py +0 -0
  33. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/web/__init__.py +0 -0
  34. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/web/templates/error.html +0 -0
  35. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/web/templates/index.html +0 -0
  36. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/web/templates/sources.html +0 -0
  37. {copilot_session_tools-0.19.0 → copilot_session_tools-0.19.2}/src/copilot_session_tools/web/webapp.py +0 -0
@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
21
  - **Refresh and fallback**: Chronicle discovery, JSONL enrichment, staleness checks, targeted enrichment, and orphan cleanup now operate per source. Disabled or unavailable sources retain archived content.
22
22
  - **Application filters**: The `cli` button now includes only the built-in Copilot CLI source. Every added source gets its own lowercase button, such as `scout`, while VS Code editions remain separate.
23
23
 
24
+ ### Fixed
25
+
26
+ - **Search**: Queries containing punctuation such as `.`, `/`, `@`, `,`, `+`, or `'` (e.g. `db_search.py`) no longer fail with `fts5: syntax error`. Any non-bareword token is now quoted, while `^` and trailing `*` operators are preserved. Tool, file, command, and thinking searches now match the raw search text instead of the FTS5-escaped string.
27
+
24
28
  ## [0.17.1] - 2026-06-30
25
29
 
26
30
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: copilot-session-tools
3
- Version: 0.19.0
3
+ Version: 0.19.2
4
4
  Summary: A collection of tools for VS Code GitHub Copilot chat history
5
5
  Keywords: copilot,github,vscode,chat,archive,history
6
6
  Author: Arithmomaniac
@@ -230,6 +230,8 @@ Features:
230
230
  - **Dark mode** via CSS `prefers-color-scheme`
231
231
  - **Incremental refresh** without restarting
232
232
 
233
+ CLI root-agent selection is tracked separately from delegated agent streams. Events with a top-level `agentId` retain their identity and source-event references inside nested task messages; they do not replace the parent root-agent interval or appear as root-user requests. Legacy child tools using `parentToolCallId` remain supported. Existing sessions are reparsed when their stored parser version is older than the current scanner.
234
+
233
235
  ## Transcript Cleanup
234
236
 
235
237
  Voice-dictated user messages often come out garbled (repeated words, filler words, broken sentences). Transcript cleanup uses an LLM to rewrite them, using the assistant's response and reasoning as context for what you actually meant.
@@ -196,6 +196,8 @@ Features:
196
196
  - **Dark mode** via CSS `prefers-color-scheme`
197
197
  - **Incremental refresh** without restarting
198
198
 
199
+ CLI root-agent selection is tracked separately from delegated agent streams. Events with a top-level `agentId` retain their identity and source-event references inside nested task messages; they do not replace the parent root-agent interval or appear as root-user requests. Legacy child tools using `parentToolCallId` remain supported. Existing sessions are reparsed when their stored parser version is older than the current scanner.
200
+
199
201
  ## Transcript Cleanup
200
202
 
201
203
  Voice-dictated user messages often come out garbled (repeated words, filler words, broken sentences). Transcript cleanup uses an LLM to rewrite them, using the assistant's response and reasoning as context for what you actually meant.
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "copilot-session-tools"
7
- version = "0.19.0"
7
+ version = "0.19.2"
8
8
  description = "A collection of tools for VS Code GitHub Copilot chat history"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "copilot-session-tools"
7
- version = "0.19.0"
7
+ version = "0.19.2"
8
8
  description = "A collection of tools for VS Code GitHub Copilot chat history"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -12,7 +12,7 @@ This project borrows patterns from several open-source projects:
12
12
  - tad-hq/universal-session-viewer: FTS5 full-text search design
13
13
  """
14
14
 
15
- __version__ = "0.19.0"
15
+ __version__ = "0.19.2"
16
16
 
17
17
  from .content_types import (
18
18
  CONTENT_TYPES,
@@ -1294,9 +1294,9 @@ def cleanup(
1294
1294
  typer.Option(
1295
1295
  "--model",
1296
1296
  "-m",
1297
- help="LiteLLM model for cleanup (e.g., github_copilot/gpt-5.4-mini).",
1297
+ help="LiteLLM model for cleanup (e.g., github_copilot/gemini-3.8-flash).",
1298
1298
  ),
1299
- ] = "github_copilot/gpt-5.4-mini",
1299
+ ] = "github_copilot/gemini-3.8-flash",
1300
1300
  dry_run: Annotated[
1301
1301
  bool,
1302
1302
  typer.Option(
@@ -18,6 +18,7 @@ class ParsedQuery:
18
18
  """Represents a parsed search query with extracted field filters."""
19
19
 
20
20
  fts_query: str # The FTS5 query string for content search
21
+ text_query: str = "" # Unescaped search text (field prefixes removed) for LIKE matching
21
22
  role: str | None = None # Extracted role filter (user/assistant)
22
23
  workspace: str | None = None # Extracted workspace filter
23
24
  workspaces: list[str] | None = None # All extracted workspace filters
@@ -53,16 +54,21 @@ def _validate_date_format(date_str: str) -> str | None:
53
54
  return None
54
55
 
55
56
 
57
+ # FTS5 bareword characters: ASCII alphanumerics, underscore, non-ASCII, and \x1a
58
+ _FTS5_BAREWORD_RE = re.compile("[A-Za-z0-9_\x1a\u0080-\U0010ffff]+")
59
+
60
+
56
61
  def _escape_fts5_token(token: str) -> str:
57
62
  """Escape a single FTS5 token to prevent syntax errors.
58
63
 
59
- FTS5 has special operators like:
60
- - Dash (-) which means NOT
61
- - Colon (:) for column specification
62
- - Parentheses, brackets for grouping
64
+ FTS5 only accepts unquoted "barewords" made of ASCII letters, digits,
65
+ underscores, and non-ASCII characters. Any other character (``.``, ``/``,
66
+ ``-``, ``:``, ``@``, ``,``, ``+``, ``'``, parentheses, ...) is a syntax
67
+ error unless the token is quoted as a string.
63
68
 
64
- If a token is already quoted, leave it as-is.
65
- Otherwise, wrap it in quotes if it contains special characters.
69
+ If a token is already quoted, leave it as-is. Otherwise, wrap it in quotes
70
+ if it is not a bareword. A leading ``^`` (first-token) and trailing ``*``
71
+ (prefix match) are preserved as operators.
66
72
 
67
73
  Args:
68
74
  token: A single search token (word or phrase).
@@ -74,23 +80,25 @@ def _escape_fts5_token(token: str) -> str:
74
80
  return token
75
81
 
76
82
  # If already quoted, leave as-is
77
- if token.startswith('"') and token.endswith('"'):
83
+ if len(token) >= 2 and token.startswith('"') and token.endswith('"'):
78
84
  return token
79
85
 
80
- # FTS5 special characters that need escaping:
81
- # - (dash/NOT operator), : (column spec), (, ), [, ]
82
- # Note: We don't need to escape * (prefix match) or ^ (first token)
83
- # as these are useful operators users might want to use
84
- special_chars = ["-", ":", "(", ")", "[", "]"]
86
+ prefix = "^" if token.startswith("^") else ""
87
+ core = token[len(prefix) :]
88
+ suffix = "*" if core.endswith("*") else ""
89
+ if suffix:
90
+ core = core[:-1]
85
91
 
86
- # Check if token contains any special characters
87
- if any(char in token for char in special_chars):
88
- # Escape internal quotes by doubling them (FTS5 convention)
89
- escaped = token.replace('"', '""')
90
- # Wrap in quotes
91
- return f'"{escaped}"'
92
+ if not core:
93
+ # Lone operator characters (e.g. "*" or "^") are searched literally
94
+ return '"' + token.replace('"', '""') + '"'
95
+
96
+ if _FTS5_BAREWORD_RE.fullmatch(core):
97
+ return token
92
98
 
93
- return token
99
+ # Escape internal quotes by doubling them (FTS5 convention)
100
+ escaped = core.replace('"', '""')
101
+ return f'{prefix}"{escaped}"{suffix}'
94
102
 
95
103
 
96
104
  def parse_search_query(query: str) -> ParsedQuery:
@@ -161,6 +169,7 @@ def parse_search_query(query: str) -> ParsedQuery:
161
169
  # 1. Quoted phrases (keep as-is)
162
170
  # 2. Unquoted words (escape special chars and join with spaces for implicit AND)
163
171
 
172
+ raw_tokens: list[str] = []
164
173
  if not remaining_query:
165
174
  fts_query = ""
166
175
  else:
@@ -169,13 +178,13 @@ def parse_search_query(query: str) -> ParsedQuery:
169
178
  # Pattern to match quoted strings or individual words
170
179
  token_pattern = r'"[^"]*"|[^\s"]+'
171
180
 
172
- for match in re.finditer(token_pattern, remaining_query):
173
- token = match.group(0)
174
- # Clean up any empty quotes
175
- if token == '""':
176
- continue
181
+ query_tokens = [token for token in re.findall(token_pattern, remaining_query) if token != '""']
182
+ for index, token in enumerate(query_tokens):
183
+ raw_tokens.append(token[1:-1] if len(token) >= 2 and token.startswith('"') and token.endswith('"') else token)
177
184
  # Escape FTS5 special characters in the token
178
- escaped_token = _escape_fts5_token(token)
185
+ # Quoted phrases and whitespace can separate operators from their operands.
186
+ is_operator = (token == "^" and index + 1 < len(query_tokens)) or (token == "*" and index > 0)
187
+ escaped_token = token if is_operator else _escape_fts5_token(token)
179
188
  tokens.append(escaped_token)
180
189
 
181
190
  # Join tokens with space (FTS5 uses implicit AND)
@@ -183,6 +192,7 @@ def parse_search_query(query: str) -> ParsedQuery:
183
192
 
184
193
  return ParsedQuery(
185
194
  fts_query=fts_query,
195
+ text_query=" ".join(raw_tokens),
186
196
  role=role,
187
197
  workspace=workspaces[0] if workspaces else None,
188
198
  workspaces=workspaces or None,
@@ -915,7 +925,7 @@ def execute_search(
915
925
  )
916
926
 
917
927
  # For tool/file/command/thinking searches, use LIKE matching
918
- search_terms = fts_query if fts_query else query
928
+ search_terms = parsed.text_query if fts_query else query
919
929
  like_pattern = f"%{search_terms}%"
920
930
 
921
931
  if include_tools and len(results) < limit and search_terms:
@@ -151,6 +151,8 @@ CREATE TABLE IF NOT EXISTS cst_content_blocks (
151
151
  agent_id TEXT
152
152
  );
153
153
  CREATE INDEX IF NOT EXISTS idx_cst_content_blocks_message ON cst_content_blocks(message_id);
154
+ -- Avoid scanning every content block for each deleted message's SET NULL action.
155
+ CREATE INDEX IF NOT EXISTS idx_cst_content_blocks_child_message ON cst_content_blocks(child_message_id);
154
156
 
155
157
  CREATE TABLE IF NOT EXISTS cst_root_agent_intervals (
156
158
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -5,7 +5,7 @@ Data structures are informed by:
5
5
  - microsoft/vscode (https://github.com/microsoft/vscode)
6
6
  """
7
7
 
8
- PARSER_VERSION = 8
8
+ PARSER_VERSION = 9
9
9
 
10
10
  from .cli import _parse_cli_jsonl_file, _parse_workspace_yaml
11
11
  from .content import (
@@ -2,7 +2,9 @@
2
2
 
3
3
  import html
4
4
  import json
5
+ import logging
5
6
  import re
7
+ from dataclasses import dataclass
6
8
  from pathlib import Path
7
9
  from typing import cast
8
10
 
@@ -31,6 +33,7 @@ _SESSION_REFERENCE_PATTERN = re.compile(
31
33
  re.IGNORECASE,
32
34
  )
33
35
  _FORK_BOUNDARY_PATTERN = re.compile(rf" before event (?P<event_id>{_SESSION_ID_PATTERN})", re.IGNORECASE)
36
+ logger = logging.getLogger(__name__)
34
37
 
35
38
 
36
39
  def _as_tool_argument_dict(arguments: object) -> dict[str, object]:
@@ -719,7 +722,169 @@ class _CliSessionBuilder:
719
722
  self.current_assistant_tool_invocations.append(tool_inv)
720
723
 
721
724
 
722
- def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
725
+ @dataclass
726
+ class _CliSessionIndex:
727
+ events_by_agent: dict[str | None, list[dict]]
728
+ metadata_events: list[dict]
729
+ fusion_statuses: dict[str, str]
730
+ tool_executions: dict
731
+ subagent_child_tools: dict[str, list[str]]
732
+ subagent_child_structured: dict[str, list[tuple]]
733
+ subagent_failures: dict[str, str]
734
+ subagent_completions: set[str]
735
+ bg_agent_results: dict[str, str]
736
+ bg_agent_id_map: dict[str, str]
737
+ agent_display_names: dict[str, str]
738
+ root_agent_intervals: list[RootAgentInterval]
739
+ updated_at: str | None
740
+
741
+
742
+ def _index_cli_events(events: list[dict]) -> _CliSessionIndex:
743
+ tool_executions: dict = {}
744
+ root_agent_intervals: list[RootAgentInterval] = []
745
+ active_root_agent: RootAgentInterval | None = None
746
+ subagent_child_tools: dict[str, list[str]] = {}
747
+ subagent_child_structured: dict[str, list[tuple]] = {}
748
+ subagent_failures: dict[str, str] = {}
749
+ subagent_completions: set[str] = set()
750
+ subagent_started_ids: set[str] = set()
751
+ bg_agent_results: dict[str, str] = {}
752
+ bg_agent_id_map: dict[str, str] = {}
753
+ agent_display_names: dict[str, str] = {}
754
+ metadata_events: dict[str, dict] = {}
755
+ for event in events:
756
+ event_type = event.get("type", "")
757
+ event_data = event.get("data", {})
758
+ timestamp = event.get("timestamp")
759
+
760
+ if event_type == "session.start":
761
+ metadata_events.setdefault("start", event)
762
+ elif event_type == "session.info":
763
+ info_type = event_data.get("infoType")
764
+ message = event_data.get("message", "")
765
+ if info_type == "folder_trust" and message.startswith("Folder ") and " has been added" in message:
766
+ metadata_events.setdefault("folder_trust", event)
767
+ elif info_type == "authentication" and "as user: " in message:
768
+ metadata_events.setdefault("authentication", event)
769
+
770
+ if event_type == "tool.execution_start":
771
+ tool_call_id = event_data.get("toolCallId")
772
+ if tool_call_id:
773
+ if tool_call_id not in tool_executions:
774
+ tool_executions[tool_call_id] = {"start": None, "complete": None, "user_requested": False}
775
+ tool_executions[tool_call_id]["start"] = event
776
+ parent_tcid = event_data.get("parentToolCallId")
777
+ if parent_tcid:
778
+ tool_name = event_data.get("toolName", "")
779
+ if tool_name not in ("report_intent", "read_agent", "read_powershell", "read_bash", "skill", "task"):
780
+ arguments = event_data.get("arguments", {})
781
+ display = _format_tool_display_message(tool_name, arguments)
782
+ if display:
783
+ subagent_child_tools.setdefault(parent_tcid, []).append(display)
784
+ subagent_child_structured.setdefault(parent_tcid, []).append((tool_call_id, tool_name, arguments))
785
+ elif event_type == "tool.user_requested":
786
+ tool_call_id = event_data.get("toolCallId")
787
+ if tool_call_id:
788
+ if tool_call_id not in tool_executions:
789
+ tool_executions[tool_call_id] = {"start": None, "complete": None, "user_requested": True}
790
+ else:
791
+ tool_executions[tool_call_id]["user_requested"] = True
792
+ elif event_type == "tool.execution_complete":
793
+ tool_call_id = event_data.get("toolCallId")
794
+ if tool_call_id:
795
+ if tool_call_id not in tool_executions:
796
+ tool_executions[tool_call_id] = {"start": None, "complete": None, "user_requested": False}
797
+ tool_executions[tool_call_id]["complete"] = event
798
+ result_obj = event_data.get("result", {})
799
+ result_content = result_obj.get("content", "") if isinstance(result_obj, dict) else ""
800
+ if result_content.startswith("Agent started in background with agent_id: "):
801
+ bg_id = result_content.split("agent_id: ", 1)[1].split(".")[0].strip()
802
+ bg_agent_id_map[tool_call_id] = bg_id
803
+ start_info = tool_executions[tool_call_id].get("start")
804
+ if start_info:
805
+ args = _as_tool_argument_dict(start_info.get("data", {}).get("arguments", {}))
806
+ agent_type = _get_tool_arg_str(args, "agent_type", "agent")
807
+ desc = _get_tool_arg_str(args, "description")
808
+ agent_display_names[bg_id] = f"{agent_type}: {desc}" if desc else agent_type
809
+ start_info = tool_executions[tool_call_id].get("start")
810
+ if start_info and start_info.get("data", {}).get("toolName") == "read_agent" and isinstance(result_obj, dict):
811
+ detailed = result_obj.get("detailedContent", "")
812
+ result_from_content = result_content.split("Result:\n", 1)[-1].strip() if "Result:\n" in result_content else ""
813
+ best = result_from_content if len(result_from_content) > len(detailed) else detailed
814
+ if best:
815
+ args = _as_tool_argument_dict(start_info["data"].get("arguments", {}))
816
+ agent_id = str(args.get("agent_id", ""))
817
+ if len(best) > len(bg_agent_results.get(agent_id, "")):
818
+ bg_agent_results[agent_id] = best
819
+ elif event_type == "subagent.failed":
820
+ tool_call_id = event_data.get("toolCallId", "")
821
+ if tool_call_id:
822
+ subagent_failures[tool_call_id] = event_data.get("error") or ""
823
+ elif event_type == "subagent.started":
824
+ tool_call_id = event_data.get("toolCallId", "")
825
+ if tool_call_id:
826
+ subagent_started_ids.add(tool_call_id)
827
+ elif event_type == "subagent.completed":
828
+ tool_call_id = event_data.get("toolCallId", "")
829
+ if tool_call_id:
830
+ subagent_completions.add(tool_call_id)
831
+ elif event_type == "subagent.selected":
832
+ if timestamp is None or event.get("agentId"):
833
+ continue
834
+ if active_root_agent is not None:
835
+ active_root_agent.end_timestamp = timestamp
836
+ root_agent_intervals.append(active_root_agent)
837
+ agent_name = event_data.get("agentName") or event_data.get("agentDisplayName") or "unknown"
838
+ tools = event_data.get("tools")
839
+ active_root_agent = RootAgentInterval(
840
+ agent_name=agent_name,
841
+ agent_display_name=event_data.get("agentDisplayName") or agent_name,
842
+ start_timestamp=timestamp,
843
+ tools=tools if isinstance(tools, list) else None,
844
+ )
845
+ elif event_type == "subagent.deselected":
846
+ if not event.get("agentId") and active_root_agent is not None:
847
+ active_root_agent.end_timestamp = timestamp
848
+ root_agent_intervals.append(active_root_agent)
849
+ active_root_agent = None
850
+ if active_root_agent is not None:
851
+ root_agent_intervals.append(active_root_agent)
852
+ for tcid in subagent_started_ids:
853
+ if tcid not in subagent_completions and tcid not in subagent_failures and tool_executions.get(tcid, {}).get("complete") is not None:
854
+ subagent_completions.add(tcid)
855
+
856
+ events_by_agent: dict[str | None, list[dict]] = {}
857
+ for event in events:
858
+ owner = event.get("agentId") or None
859
+ if event.get("type") in ("subagent.started", "subagent.completed", "subagent.failed"):
860
+ execution = tool_executions.get(event.get("data", {}).get("toolCallId"), {})
861
+ owner = (execution.get("start") or {}).get("agentId") or None
862
+ events_by_agent.setdefault(owner, []).append(event)
863
+ return _CliSessionIndex(
864
+ events_by_agent=events_by_agent,
865
+ metadata_events=list(metadata_events.values()),
866
+ fusion_statuses=_build_fusion_statuses(events),
867
+ tool_executions=tool_executions,
868
+ subagent_child_tools=subagent_child_tools,
869
+ subagent_child_structured=subagent_child_structured,
870
+ subagent_failures=subagent_failures,
871
+ subagent_completions=subagent_completions,
872
+ bg_agent_results=bg_agent_results,
873
+ bg_agent_id_map=bg_agent_id_map,
874
+ agent_display_names=agent_display_names,
875
+ root_agent_intervals=root_agent_intervals,
876
+ updated_at=events[-1].get("timestamp"),
877
+ )
878
+
879
+
880
+ def _parse_cli_jsonl_file(
881
+ file_path: Path,
882
+ *,
883
+ _events: list[dict] | None = None,
884
+ _agent_id: str | None = None,
885
+ _agent_nesting_level: int = 0,
886
+ _index: _CliSessionIndex | None = None,
887
+ ) -> ChatSession | None:
723
888
  """Parse a GitHub Copilot CLI JSONL session file.
724
889
 
725
890
  CLI sessions are stored as JSONL (JSON Lines) where each line is a JSON object
@@ -749,24 +914,24 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
749
914
  ChatSession object or None if parsing fails.
750
915
  """
751
916
  try:
752
- events = []
753
-
754
- with file_path.open(encoding="utf-8") as f:
755
- for line in f:
756
- line = line.strip()
757
- if not line:
758
- continue
759
-
760
- try:
761
- data = ssrjson.loads(line)
762
- events.append(data)
763
- except ssrjson.JSONDecodeError:
764
- continue
765
-
766
- if not events:
767
- return None
768
-
769
- fusion_statuses = _build_fusion_statuses(events)
917
+ if _index is None:
918
+ events = _events
919
+ if events is None:
920
+ events = []
921
+ with file_path.open(encoding="utf-8") as f:
922
+ for line in f:
923
+ line = line.strip()
924
+ if not line:
925
+ continue
926
+ try:
927
+ events.append(ssrjson.loads(line))
928
+ except ssrjson.JSONDecodeError:
929
+ continue
930
+ if not events:
931
+ return None
932
+ _index = _index_cli_events(events)
933
+ events = _index.events_by_agent.get(_agent_id, [])
934
+ fusion_statuses = _index.fusion_statuses
770
935
 
771
936
  # Extract session metadata from session.start event
772
937
  session_id = None
@@ -774,7 +939,7 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
774
939
  session_start_context: dict = {}
775
940
  session_title_from_event: str | None = None
776
941
 
777
- for event in events:
942
+ for event in _index.metadata_events:
778
943
  event_type = event.get("type", "")
779
944
  event_data = event.get("data", {})
780
945
 
@@ -796,7 +961,7 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
796
961
  requester_username = None
797
962
  session_repository = session_start_context.get("repository") # e.g. "owner/repo"
798
963
 
799
- for event in events:
964
+ for event in _index.metadata_events:
800
965
  if event.get("type") == "session.info":
801
966
  event_data = event.get("data", {})
802
967
  info_type = event_data.get("infoType")
@@ -831,158 +996,19 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
831
996
  source="initial",
832
997
  )
833
998
 
834
- # Build tool execution map: toolCallId -> (start_data, complete_data, user_requested)
835
- tool_executions: dict = {}
836
- root_agent_intervals: list[RootAgentInterval] = []
837
- active_root_agent: RootAgentInterval | None = None
838
- # Map parent agent toolCallId -> list of child tool display names
839
- subagent_child_tools: dict[str, list[str]] = {}
840
- # Map parent agent toolCallId -> list of (ToolInvocation | None, CommandRun | None, content_blocks)
841
- subagent_child_structured: dict[str, list[tuple]] = {}
842
- # Track which subagents failed (toolCallId -> error message)
843
- subagent_failures: dict[str, str] = {}
844
- # Track which subagents completed successfully
845
- subagent_completions: set[str] = set()
846
- # Track all subagent.started toolCallIds (for inferring completion)
847
- subagent_started_ids: set[str] = set()
848
- # Map agent-N -> best result text from read_agent (for background agents)
849
- bg_agent_results: dict[str, str] = {}
850
- # Map task toolCallId -> agent-N id (parsed from background placeholder)
851
- bg_agent_id_map: dict[str, str] = {}
852
- # Map agent-N -> display title (e.g., "Explore Agent: Find auth")
853
- agent_display_names: dict[str, str] = {}
854
- for event in events:
855
- event_type = event.get("type", "")
856
- event_data = event.get("data", {})
857
- timestamp = event.get("timestamp")
858
-
859
- if event_type == "tool.execution_start":
860
- tool_call_id = event_data.get("toolCallId")
861
- if tool_call_id:
862
- if tool_call_id not in tool_executions:
863
- tool_executions[tool_call_id] = {"start": None, "complete": None, "user_requested": False}
864
- tool_executions[tool_call_id]["start"] = event
865
- # Track child tools of subagents
866
- parent_tcid = event_data.get("parentToolCallId")
867
- if parent_tcid:
868
- tool_name = event_data.get("toolName", "")
869
- # Skip internal/meta tools from child tool display
870
- if tool_name not in ("report_intent", "read_agent", "read_powershell", "read_bash", "skill", "task"):
871
- arguments = event_data.get("arguments", {})
872
- display = _format_tool_display_message(tool_name, arguments)
873
- if display:
874
- subagent_child_tools.setdefault(parent_tcid, []).append(display)
875
- # Also store structured data for child tool (toolCallId, toolName, arguments)
876
- subagent_child_structured.setdefault(parent_tcid, []).append((tool_call_id, tool_name, arguments))
877
-
878
- elif event_type == "tool.user_requested":
879
- # User explicitly requested this tool execution
880
- tool_call_id = event_data.get("toolCallId")
881
- if tool_call_id:
882
- if tool_call_id not in tool_executions:
883
- tool_executions[tool_call_id] = {"start": None, "complete": None, "user_requested": True}
884
- else:
885
- tool_executions[tool_call_id]["user_requested"] = True
886
-
887
- elif event_type == "tool.execution_complete":
888
- tool_call_id = event_data.get("toolCallId")
889
- if tool_call_id:
890
- if tool_call_id not in tool_executions:
891
- tool_executions[tool_call_id] = {"start": None, "complete": None, "user_requested": False}
892
- tool_executions[tool_call_id]["complete"] = event
893
- # Map task toolCallId -> agent_id from background placeholder
894
- result_obj = event_data.get("result", {})
895
- result_content = result_obj.get("content", "") if isinstance(result_obj, dict) else ""
896
- if result_content.startswith("Agent started in background with agent_id: "):
897
- bg_id = result_content.split("agent_id: ", 1)[1].split(".")[0].strip()
898
- bg_agent_id_map[tool_call_id] = bg_id
899
- # Build display name from task tool arguments
900
- start_info = tool_executions[tool_call_id].get("start")
901
- if start_info:
902
- args = _as_tool_argument_dict(start_info.get("data", {}).get("arguments", {}))
903
- agent_type = _get_tool_arg_str(args, "agent_type", "agent")
904
- desc = _get_tool_arg_str(args, "description")
905
- agent_display_names[bg_id] = f"{agent_type}: {desc}" if desc else agent_type
906
- # Collect read_agent results for background agents
907
- start_info = tool_executions[tool_call_id].get("start")
908
- if start_info and start_info.get("data", {}).get("toolName") == "read_agent" and isinstance(result_obj, dict):
909
- content = result_content
910
- detailed = result_obj.get("detailedContent", "")
911
- # Extract result text from content after "Result:\n" header
912
- result_from_content = ""
913
- if content and "Result:\n" in content:
914
- result_from_content = content.split("Result:\n", 1)[-1].strip()
915
- # Use the longer of content-after-Result vs detailedContent
916
- best = result_from_content if len(result_from_content) > len(detailed) else detailed
917
- if best:
918
- args = _as_tool_argument_dict(start_info["data"].get("arguments", {}))
919
- agent_id = str(args.get("agent_id", ""))
920
- # Only keep the best (longest) result per agent
921
- if len(best) > len(bg_agent_results.get(agent_id, "")):
922
- bg_agent_results[agent_id] = best
923
-
924
- elif event_type == "subagent.failed":
925
- tool_call_id = event_data.get("toolCallId", "")
926
- error = event_data.get("error") or ""
927
- if tool_call_id:
928
- subagent_failures[tool_call_id] = error
929
-
930
- elif event_type == "subagent.started":
931
- tool_call_id = event_data.get("toolCallId", "")
932
- if tool_call_id:
933
- subagent_started_ids.add(tool_call_id)
934
-
935
- elif event_type == "subagent.completed":
936
- tool_call_id = event_data.get("toolCallId", "")
937
- if tool_call_id:
938
- subagent_completions.add(tool_call_id)
939
-
940
- elif event_type == "subagent.selected":
941
- if timestamp is None:
942
- continue
943
- if active_root_agent is not None:
944
- active_root_agent.end_timestamp = timestamp
945
- root_agent_intervals.append(active_root_agent)
946
- agent_name = event_data.get("agentName") or event_data.get("agentDisplayName") or "unknown"
947
- agent_display_name = event_data.get("agentDisplayName") or agent_name
948
- tools = event_data.get("tools")
949
- active_root_agent = RootAgentInterval(
950
- agent_name=agent_name,
951
- agent_display_name=agent_display_name,
952
- start_timestamp=timestamp,
953
- tools=tools if isinstance(tools, list) else None,
954
- )
955
-
956
- elif event_type == "subagent.deselected":
957
- if active_root_agent is not None:
958
- active_root_agent.end_timestamp = timestamp
959
- root_agent_intervals.append(active_root_agent)
960
- active_root_agent = None
961
-
962
- if active_root_agent is not None:
963
- root_agent_intervals.append(active_root_agent)
964
-
965
- # Infer subagent completion from tool.execution_complete when no
966
- # explicit subagent.completed event was emitted (common in older CLI versions)
967
- for tcid in subagent_started_ids:
968
- if tcid not in subagent_completions and tcid not in subagent_failures:
969
- exec_info = tool_executions.get(tcid, {})
970
- if exec_info.get("complete") is not None:
971
- subagent_completions.add(tcid)
972
-
973
999
  # Build messages using VSCode-style rendering:
974
1000
  # - Process events in order
975
1001
  # - Combine consecutive assistant messages
976
1002
  # - Interleave tool invocations inline with content
977
1003
  builder = _CliSessionBuilder(
978
- tool_executions,
979
- subagent_child_tools,
980
- subagent_failures,
981
- bg_agent_results,
982
- bg_agent_id_map,
983
- subagent_completions,
984
- subagent_child_structured,
985
- agent_display_names,
1004
+ _index.tool_executions,
1005
+ _index.subagent_child_tools,
1006
+ _index.subagent_failures,
1007
+ _index.bg_agent_results,
1008
+ _index.bg_agent_id_map,
1009
+ _index.subagent_completions,
1010
+ _index.subagent_child_structured,
1011
+ _index.agent_display_names,
986
1012
  )
987
1013
 
988
1014
  for event in events:
@@ -990,8 +1016,8 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
990
1016
  event_data = event.get("data", {})
991
1017
  timestamp = event.get("timestamp")
992
1018
 
993
- # Skip events belonging to a subagent — they have parentToolCallId
994
- if event_data.get("parentToolCallId"):
1019
+ # Legacy child events without agent identity are rendered by the caller.
1020
+ if event_data.get("parentToolCallId") and _agent_id is None:
995
1021
  continue
996
1022
 
997
1023
  if event_type == "user.message":
@@ -1293,8 +1319,7 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
1293
1319
  role="assistant",
1294
1320
  content=content,
1295
1321
  agent_display_name=title,
1296
- # TODO: For multi-level nesting, derive from parent's nesting level
1297
- agent_nesting_level=1,
1322
+ agent_nesting_level=_agent_nesting_level + 1,
1298
1323
  source_event_id=builder.current_assistant_source_event_id,
1299
1324
  tool_invocations=nested_tool_invocations,
1300
1325
  command_runs=nested_command_runs,
@@ -1302,6 +1327,37 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
1302
1327
  file_changes=nested_consolidated_changes,
1303
1328
  )
1304
1329
 
1330
+ stream_agent_id = event.get("agentId")
1331
+ if stream_agent_id and stream_agent_id != _agent_id:
1332
+ child_session = _parse_cli_jsonl_file(
1333
+ file_path,
1334
+ _index=_index,
1335
+ _agent_id=stream_agent_id,
1336
+ _agent_nesting_level=_agent_nesting_level + 2,
1337
+ )
1338
+ if child_session is None:
1339
+ logger.error("Failed to parse delegated agent stream %s in %s", stream_agent_id, file_path)
1340
+ return None
1341
+ if child_session.messages:
1342
+ child_msg = ChatMessage(
1343
+ role="assistant",
1344
+ content="",
1345
+ timestamp=timestamp,
1346
+ source_event_id=event.get("id"),
1347
+ agent_id=stream_agent_id,
1348
+ agent_display_name=title,
1349
+ agent_nesting_level=_agent_nesting_level + 1,
1350
+ children=child_session.messages,
1351
+ content_blocks=[
1352
+ ContentBlock(kind="subagent", content=message.content, description=message.role.title(), child_message=message)
1353
+ for message in child_session.messages
1354
+ ],
1355
+ )
1356
+ nested_blocks = child_msg.content_blocks
1357
+ nested_tool_invocations = []
1358
+ nested_command_runs = []
1359
+ nested_consolidated_changes = []
1360
+
1305
1361
  block = ContentBlock(
1306
1362
  kind=kind,
1307
1363
  content=content,
@@ -1309,7 +1365,7 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
1309
1365
  child_message=child_msg,
1310
1366
  prompt=_get_tool_arg_str(req_args, "prompt"),
1311
1367
  is_background=is_bg,
1312
- agent_id=bg_id if is_bg else "",
1368
+ agent_id=stream_agent_id or (bg_id if is_bg else ""),
1313
1369
  )
1314
1370
  # Also set deprecated fields for backward compat during transition
1315
1371
  block.content_blocks = nested_blocks
@@ -1575,7 +1631,7 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
1575
1631
  builder.flush_assistant_message()
1576
1632
 
1577
1633
  messages = builder.messages
1578
- if not messages:
1634
+ if not messages and _agent_id is None:
1579
1635
  return None
1580
1636
 
1581
1637
  # Post-process: collect shell IO entries and attach to parent CommandRun
@@ -1635,7 +1691,7 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
1635
1691
  source_file_mtime, source_file_size = _get_file_metadata(file_path)
1636
1692
 
1637
1693
  # Get updated_at from last event timestamp
1638
- updated_at = events[-1].get("timestamp") if events else None
1694
+ updated_at = _index.updated_at
1639
1695
 
1640
1696
  # Determine session title: prefer session.title_changed event, then workspace.yaml, then first intent
1641
1697
  custom_title = None
@@ -1671,9 +1727,12 @@ def _parse_cli_jsonl_file(file_path: Path) -> ChatSession | None:
1671
1727
  source_file_size=source_file_size,
1672
1728
  type="cli",
1673
1729
  repository_url=repository_url,
1674
- root_agent_intervals=root_agent_intervals,
1730
+ root_agent_intervals=_index.root_agent_intervals if _agent_id is None else [],
1675
1731
  context_entries=context_entries,
1676
1732
  )
1733
+ for message in messages:
1734
+ message.agent_id = _agent_id
1735
+ message.agent_nesting_level = _agent_nesting_level
1677
1736
  session.parser_version = PARSER_VERSION
1678
1737
  return session
1679
1738
  except (OSError, Exception):
@@ -111,16 +111,13 @@ def session_needs_cleanup(session: ChatSession, threshold: float = 0.3) -> list[
111
111
  # Batch LLM cleanup
112
112
  # ---------------------------------------------------------------------------
113
113
 
114
- # GPT-5.4-mini chosen via Artificial Analysis IFBench (instruction following):
115
- # gpt-5.4-mini: 0.733 IFBench, 179 tok/s, $1.69/1M
116
- # gpt-4o-mini: not ranked (legacy)
117
- # claude-4.5-haiku: 0.543 IFBench — weaker at following cleanup rules
118
- # IFBench is the most relevant AA metric for transcript cleanup, which
119
- # requires precise instruction following over raw reasoning ability.
120
- DEFAULT_MODEL = "github_copilot/gpt-5.4-mini"
114
+ # Gemini 3.8 Flash medium keeps this high-volume structured cleanup role bounded
115
+ # while replacing the retiring Gemini 3.5 default.
116
+ DEFAULT_MODEL = "github_copilot/gemini-3.8-flash"
117
+ DEFAULT_REASONING_EFFORT = "medium"
121
118
 
122
119
  # Models that require the /responses API (not available on /chat/completions)
123
- _RESPONSES_ONLY_MODELS = frozenset({"gpt-5.4-mini", "gpt-5.4", "gpt-5.4-nano"})
120
+ _RESPONSES_ONLY_MODELS = frozenset({"gpt-5.4-mini", "gpt-5.4"})
124
121
 
125
122
  _SYSTEM_PROMPT = """\
126
123
  You are a transcript cleanup assistant for Copilot chat sessions.
@@ -417,6 +414,8 @@ def call_cleanup_llm(
417
414
  kwargs: dict = {}
418
415
  if not _needs_responses_api(model):
419
416
  kwargs["temperature"] = 0.0
417
+ if model == DEFAULT_MODEL:
418
+ kwargs["reasoning_effort"] = DEFAULT_REASONING_EFFORT
420
419
 
421
420
  parsed = _structured_completion(
422
421
  model=model,
@@ -2063,7 +2063,8 @@ footer a {
2063
2063
 
2064
2064
  /* Toggle hide rules — driven by Alpine settings panel */
2065
2065
  .hide-thinking .thinking-block { display: none !important; }
2066
- .hide-system-messages .message.system { display: none !important; }
2066
+ .hide-system-messages .message.system,
2067
+ .hide-system-messages .subagent-system-message { display: none !important; }
2067
2068
  .hide-diffs .file-change .diff { display: none !important; }
2068
2069
  .hide-tool-inputs .tool-section-input { display: none !important; }
2069
2070
  /* Tools OFF: hide collapsible wrappers + section header + summaries, show inline fallbacks */
@@ -2935,7 +2936,7 @@ input:checked + .toggle-switch::after {
2935
2936
  <span class="status-badge {{ block.description or '' }}">{{ block.content }}</span>
2936
2937
  {% endif %}
2937
2938
  {% elif block.kind in ('subagent', 'subagent_failed', 'subagent_incomplete') %}
2938
- <details class="subagent-block{% if block.kind == 'subagent_failed' %} subagent-failed{% endif %}{% if block.is_background %} subagent-background{% endif %}"{% if block.agent_id %} id="agent-{{ block.agent_id }}"{% endif %} open>
2939
+ {% set is_nested_system = block.child_message and block.child_message.role == 'system' %}{% if not is_nested_system or not static or include_system_messages %}<details class="subagent-block{% if is_nested_system %} subagent-system-message{% endif %}{% if block.kind == 'subagent_failed' %} subagent-failed{% endif %}{% if block.is_background %} subagent-background{% endif %}"{% if block.agent_id %} id="agent-{{ block.agent_id }}"{% endif %} open>
2939
2940
  <summary>
2940
2941
  <span class="collapsible-icon" aria-hidden="true">▼</span>
2941
2942
  <span class="subagent-label">{{ block.description or 'Agent' }}</span>
@@ -2984,7 +2985,7 @@ input:checked + .toggle-switch::after {
2984
2985
  {% endif %}
2985
2986
  {% endif %}
2986
2987
  </div>
2987
- </details>
2988
+ </details>{% endif %}
2988
2989
  {% elif block.kind == 'thinking' and (include_thinking is not defined or include_thinking) %}
2989
2990
  <details class="thinking-block" open>
2990
2991
  <summary>