ripperdoc 0.2.8__py3-none-any.whl → 0.2.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. ripperdoc/__init__.py +1 -1
  2. ripperdoc/cli/cli.py +257 -123
  3. ripperdoc/cli/commands/__init__.py +2 -1
  4. ripperdoc/cli/commands/agents_cmd.py +138 -8
  5. ripperdoc/cli/commands/clear_cmd.py +9 -4
  6. ripperdoc/cli/commands/config_cmd.py +1 -1
  7. ripperdoc/cli/commands/context_cmd.py +3 -2
  8. ripperdoc/cli/commands/doctor_cmd.py +18 -4
  9. ripperdoc/cli/commands/exit_cmd.py +1 -0
  10. ripperdoc/cli/commands/hooks_cmd.py +27 -53
  11. ripperdoc/cli/commands/models_cmd.py +27 -10
  12. ripperdoc/cli/commands/permissions_cmd.py +27 -9
  13. ripperdoc/cli/commands/resume_cmd.py +9 -3
  14. ripperdoc/cli/commands/stats_cmd.py +244 -0
  15. ripperdoc/cli/commands/status_cmd.py +4 -4
  16. ripperdoc/cli/commands/tasks_cmd.py +8 -4
  17. ripperdoc/cli/ui/file_mention_completer.py +2 -1
  18. ripperdoc/cli/ui/interrupt_handler.py +2 -3
  19. ripperdoc/cli/ui/message_display.py +4 -2
  20. ripperdoc/cli/ui/panels.py +1 -0
  21. ripperdoc/cli/ui/provider_options.py +247 -0
  22. ripperdoc/cli/ui/rich_ui.py +403 -81
  23. ripperdoc/cli/ui/spinner.py +54 -18
  24. ripperdoc/cli/ui/thinking_spinner.py +1 -2
  25. ripperdoc/cli/ui/tool_renderers.py +8 -2
  26. ripperdoc/cli/ui/wizard.py +213 -0
  27. ripperdoc/core/agents.py +19 -6
  28. ripperdoc/core/config.py +51 -17
  29. ripperdoc/core/custom_commands.py +7 -6
  30. ripperdoc/core/default_tools.py +101 -12
  31. ripperdoc/core/hooks/config.py +1 -3
  32. ripperdoc/core/hooks/events.py +27 -28
  33. ripperdoc/core/hooks/executor.py +4 -6
  34. ripperdoc/core/hooks/integration.py +12 -21
  35. ripperdoc/core/hooks/llm_callback.py +59 -0
  36. ripperdoc/core/hooks/manager.py +40 -15
  37. ripperdoc/core/permissions.py +118 -12
  38. ripperdoc/core/providers/anthropic.py +109 -36
  39. ripperdoc/core/providers/gemini.py +70 -5
  40. ripperdoc/core/providers/openai.py +89 -24
  41. ripperdoc/core/query.py +273 -68
  42. ripperdoc/core/query_utils.py +2 -0
  43. ripperdoc/core/skills.py +9 -3
  44. ripperdoc/core/system_prompt.py +4 -2
  45. ripperdoc/core/tool.py +17 -8
  46. ripperdoc/sdk/client.py +79 -4
  47. ripperdoc/tools/ask_user_question_tool.py +5 -3
  48. ripperdoc/tools/background_shell.py +307 -135
  49. ripperdoc/tools/bash_output_tool.py +1 -1
  50. ripperdoc/tools/bash_tool.py +63 -24
  51. ripperdoc/tools/dynamic_mcp_tool.py +29 -8
  52. ripperdoc/tools/enter_plan_mode_tool.py +1 -1
  53. ripperdoc/tools/exit_plan_mode_tool.py +1 -1
  54. ripperdoc/tools/file_edit_tool.py +167 -54
  55. ripperdoc/tools/file_read_tool.py +28 -4
  56. ripperdoc/tools/file_write_tool.py +13 -10
  57. ripperdoc/tools/glob_tool.py +3 -2
  58. ripperdoc/tools/grep_tool.py +3 -2
  59. ripperdoc/tools/kill_bash_tool.py +1 -1
  60. ripperdoc/tools/ls_tool.py +1 -1
  61. ripperdoc/tools/lsp_tool.py +615 -0
  62. ripperdoc/tools/mcp_tools.py +13 -10
  63. ripperdoc/tools/multi_edit_tool.py +8 -7
  64. ripperdoc/tools/notebook_edit_tool.py +7 -4
  65. ripperdoc/tools/skill_tool.py +1 -1
  66. ripperdoc/tools/task_tool.py +519 -69
  67. ripperdoc/tools/todo_tool.py +2 -2
  68. ripperdoc/tools/tool_search_tool.py +3 -2
  69. ripperdoc/utils/conversation_compaction.py +9 -5
  70. ripperdoc/utils/file_watch.py +214 -5
  71. ripperdoc/utils/json_utils.py +2 -1
  72. ripperdoc/utils/lsp.py +806 -0
  73. ripperdoc/utils/mcp.py +11 -3
  74. ripperdoc/utils/memory.py +4 -2
  75. ripperdoc/utils/message_compaction.py +21 -7
  76. ripperdoc/utils/message_formatting.py +14 -7
  77. ripperdoc/utils/messages.py +126 -67
  78. ripperdoc/utils/path_ignore.py +35 -8
  79. ripperdoc/utils/permissions/path_validation_utils.py +2 -1
  80. ripperdoc/utils/permissions/shell_command_validation.py +427 -91
  81. ripperdoc/utils/permissions/tool_permission_utils.py +174 -15
  82. ripperdoc/utils/safe_get_cwd.py +2 -1
  83. ripperdoc/utils/session_heatmap.py +244 -0
  84. ripperdoc/utils/session_history.py +13 -6
  85. ripperdoc/utils/session_stats.py +293 -0
  86. ripperdoc/utils/todo.py +2 -1
  87. ripperdoc/utils/token_estimation.py +6 -1
  88. {ripperdoc-0.2.8.dist-info → ripperdoc-0.2.10.dist-info}/METADATA +8 -2
  89. ripperdoc-0.2.10.dist-info/RECORD +129 -0
  90. ripperdoc-0.2.8.dist-info/RECORD +0 -121
  91. {ripperdoc-0.2.8.dist-info → ripperdoc-0.2.10.dist-info}/WHEEL +0 -0
  92. {ripperdoc-0.2.8.dist-info → ripperdoc-0.2.10.dist-info}/entry_points.txt +0 -0
  93. {ripperdoc-0.2.8.dist-info → ripperdoc-0.2.10.dist-info}/licenses/LICENSE +0 -0
  94. {ripperdoc-0.2.8.dist-info → ripperdoc-0.2.10.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,7 @@
1
1
  from rich.markup import escape
2
+ from rich import box
3
+ from rich.panel import Panel
4
+ from rich.table import Table
2
5
 
3
6
  from ripperdoc.core.agents import (
4
7
  AGENT_DIR_NAME,
@@ -8,14 +11,38 @@ from ripperdoc.core.agents import (
8
11
  save_agent_definition,
9
12
  )
10
13
  from ripperdoc.core.config import get_global_config
14
+ from ripperdoc.tools.task_tool import (
15
+ list_agent_runs,
16
+ get_agent_run_snapshot,
17
+ cancel_agent_run,
18
+ )
11
19
  from ripperdoc.utils.log import get_logger
12
20
 
13
- from typing import Any
21
+ from typing import Any, Dict, Optional
14
22
  from .base import SlashCommand
15
23
 
16
24
  logger = get_logger()
17
25
 
18
26
 
27
+ def _format_duration(duration_ms: float | None) -> str:
28
+ if duration_ms is None:
29
+ return "-"
30
+ try:
31
+ duration = float(duration_ms)
32
+ except (TypeError, ValueError):
33
+ return "-"
34
+ if duration < 1000:
35
+ return f"{int(duration)} ms"
36
+ seconds = duration / 1000.0
37
+ if seconds < 60:
38
+ return f"{seconds:.1f}s"
39
+ minutes, secs = divmod(int(seconds), 60)
40
+ if minutes < 60:
41
+ return f"{minutes}m {secs}s"
42
+ hours, mins = divmod(minutes, 60)
43
+ return f"{hours}h {mins}m"
44
+
45
+
19
46
  def _handle(ui: Any, trimmed_arg: str) -> bool:
20
47
  console = ui.console
21
48
  tokens = trimmed_arg.split()
@@ -39,18 +66,118 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
39
66
  "[bold]/agents delete <name> [location][/bold] — "
40
67
  "delete agent (location: user|project, default user)"
41
68
  )
69
+ console.print("[bold]/agents runs[/bold] — list subagent runs")
70
+ console.print("[bold]/agents show <id>[/bold] — show subagent run details")
71
+ console.print("[bold]/agents cancel <id>[/bold] — cancel a background subagent run")
42
72
  console.print(
43
73
  f"[dim]Agent files live in ~/.ripperdoc/{AGENT_DIR_NAME} "
44
74
  f"or ./.ripperdoc/{AGENT_DIR_NAME}[/dim]"
45
75
  )
46
76
  console.print(
47
- "[dim]Model can be a profile name or pointer (task/main/etc). Defaults to 'task'.[/dim]"
77
+ "[dim]Model can be a profile name or pointer (main/quick). Defaults to 'main'.[/dim]"
48
78
  )
49
79
 
50
80
  if subcmd in ("help", "-h", "--help"):
51
81
  print_agents_usage()
52
82
  return True
53
83
 
84
+ if subcmd in ("runs", "run", "tasks", "status"):
85
+ console = ui.console
86
+ run_ids = list_agent_runs()
87
+ if not run_ids:
88
+ console.print(
89
+ Panel("No subagent runs recorded", title="Subagent runs", box=box.ROUNDED)
90
+ )
91
+ return True
92
+
93
+ table = Table(box=box.SIMPLE_HEAVY, expand=True)
94
+ table.add_column("ID", style="cyan", no_wrap=True)
95
+ table.add_column("Status", style="magenta", no_wrap=True)
96
+ table.add_column("Agent", style="white", no_wrap=True)
97
+ table.add_column("Duration", style="dim", no_wrap=True)
98
+ table.add_column("Background", style="dim", no_wrap=True)
99
+ table.add_column("Result", style="white")
100
+
101
+ for run_id in sorted(run_ids):
102
+ snapshot: Dict[Any, Any] = get_agent_run_snapshot(run_id) or {}
103
+ result_text = snapshot.get("result_text") or snapshot.get("error") or ""
104
+ result_preview = (
105
+ result_text if len(result_text) <= 80 else result_text[:77] + "..."
106
+ )
107
+ table.add_row(
108
+ escape(run_id),
109
+ escape(snapshot.get("status") or "unknown"),
110
+ escape(snapshot.get("agent_type") or "unknown"),
111
+ _format_duration(snapshot.get("duration_ms")),
112
+ "yes" if snapshot.get("is_background") else "no",
113
+ escape(result_preview),
114
+ )
115
+
116
+ console.print(
117
+ Panel(table, title="Subagent runs", box=box.ROUNDED, padding=(1, 2)),
118
+ markup=False,
119
+ )
120
+ console.print(
121
+ "[dim]Use /agents show <id> for details or /agents cancel <id> to stop a background run.[/dim]"
122
+ )
123
+ return True
124
+
125
+ if subcmd in ("show", "info", "details"):
126
+ if len(tokens) < 2:
127
+ console.print("[red]Usage: /agents show <id>[/red]")
128
+ return True
129
+ run_id = tokens[1]
130
+ snapshot = get_agent_run_snapshot(run_id) # type: ignore[assignment]
131
+ if not snapshot:
132
+ console.print(f"[red]No subagent run found with id '{escape(run_id)}'.[/red]")
133
+ return True
134
+ details = Table(box=box.SIMPLE_HEAVY, show_header=False)
135
+ details.add_row("ID", escape(run_id))
136
+ details.add_row("Status", escape(snapshot.get("status") or "unknown"))
137
+ details.add_row("Agent", escape(snapshot.get("agent_type") or "unknown"))
138
+ details.add_row("Duration", _format_duration(snapshot.get("duration_ms")))
139
+ details.add_row(
140
+ "Background", "yes" if snapshot.get("is_background") else "no"
141
+ )
142
+ if snapshot.get("model_used"):
143
+ details.add_row("Model", escape(str(snapshot.get("model_used"))))
144
+ if snapshot.get("tool_use_count"):
145
+ details.add_row("Tool uses", str(snapshot.get("tool_use_count")))
146
+ if snapshot.get("missing_tools"):
147
+ details.add_row("Missing tools", escape(", ".join(snapshot["missing_tools"])))
148
+ if snapshot.get("error"):
149
+ details.add_row("Error", escape(str(snapshot.get("error"))))
150
+ console.print(
151
+ Panel(details, title=f"Subagent {escape(run_id)}", box=box.ROUNDED, padding=(1, 2)),
152
+ markup=False,
153
+ )
154
+ result_text = snapshot.get("result_text")
155
+ if result_text:
156
+ console.print(Panel(escape(result_text), title="Result", box=box.SIMPLE))
157
+ return True
158
+
159
+ if subcmd in ("cancel", "kill", "stop"):
160
+ if len(tokens) < 2:
161
+ console.print("[red]Usage: /agents cancel <id>[/red]")
162
+ return True
163
+ run_id = tokens[1]
164
+ runner = getattr(ui, "run_async", None)
165
+ try:
166
+ if callable(runner):
167
+ cancelled = runner(cancel_agent_run(run_id))
168
+ else:
169
+ import asyncio
170
+
171
+ cancelled = asyncio.run(cancel_agent_run(run_id))
172
+ except (OSError, RuntimeError, ValueError) as exc:
173
+ console.print(f"[red]Failed to cancel '{escape(run_id)}': {escape(str(exc))}[/red]")
174
+ return True
175
+ if cancelled:
176
+ console.print(f"[green]Cancelled subagent {escape(run_id)}[/green]")
177
+ else:
178
+ console.print(f"[yellow]No running subagent found for '{escape(run_id)}'.[/yellow]")
179
+ return True
180
+
54
181
  if subcmd in ("create", "add"):
55
182
  agent_name = tokens[1] if len(tokens) > 1 else console.input("Agent name: ").strip()
56
183
  if not agent_name:
@@ -84,7 +211,7 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
84
211
 
85
212
  config = get_global_config()
86
213
  pointer_map = config.model_pointers.model_dump()
87
- default_model_value = model_arg or pointer_map.get("task", "task")
214
+ default_model_value = model_arg or pointer_map.get("main", "main")
88
215
  model_input = (
89
216
  console.input(f"Model profile or pointer [{default_model_value}]: ").strip()
90
217
  or default_model_value
@@ -116,7 +243,8 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
116
243
  print_agents_usage()
117
244
  logger.warning(
118
245
  "[agents_cmd] Failed to create agent: %s: %s",
119
- type(exc).__name__, exc,
246
+ type(exc).__name__,
247
+ exc,
120
248
  extra={"agent": agent_name, "session_id": getattr(ui, "session_id", None)},
121
249
  )
122
250
  return True
@@ -148,7 +276,8 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
148
276
  print_agents_usage()
149
277
  logger.warning(
150
278
  "[agents_cmd] Failed to delete agent: %s: %s",
151
- type(exc).__name__, exc,
279
+ type(exc).__name__,
280
+ exc,
152
281
  extra={"agent": agent_name, "session_id": getattr(ui, "session_id", None)},
153
282
  )
154
283
  return True
@@ -203,7 +332,7 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
203
332
 
204
333
  config = get_global_config()
205
334
  pointer_map = config.model_pointers.model_dump()
206
- model_default = target_agent.model or pointer_map.get("task", "task")
335
+ model_default = target_agent.model or pointer_map.get("main", "main")
207
336
  model_input = (
208
337
  console.input(f"Model profile or pointer [{model_default}]: ").strip() or model_default
209
338
  )
@@ -226,7 +355,8 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
226
355
  print_agents_usage()
227
356
  logger.warning(
228
357
  "[agents_cmd] Failed to update agent: %s: %s",
229
- type(exc).__name__, exc,
358
+ type(exc).__name__,
359
+ exc,
230
360
  extra={"agent": agent_name, "session_id": getattr(ui, "session_id", None)},
231
361
  )
232
362
  return True
@@ -242,7 +372,7 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
242
372
  console.print(f" • {escape(agent.agent_type)} ({escape(str(location))})", markup=False)
243
373
  console.print(f" {escape(agent.when_to_use)}", markup=False)
244
374
  console.print(f" tools: {escape(tools_str)}", markup=False)
245
- console.print(f" model: {escape(agent.model or 'task (default)')}", markup=False)
375
+ console.print(f" model: {escape(agent.model or 'main (default)')}", markup=False)
246
376
  if agents.failed_files:
247
377
  console.print("[yellow]Some agent files could not be loaded:[/yellow]")
248
378
  for path, error in agents.failed_files:
@@ -3,16 +3,21 @@ from .base import SlashCommand
3
3
 
4
4
 
5
5
  def _handle(ui: Any, _: str) -> bool:
6
+ try:
7
+ ui._run_session_end("clear")
8
+ except (AttributeError, RuntimeError, ValueError):
9
+ pass
6
10
  ui.conversation_messages = []
7
11
  ui.console.print("[green]✓ Conversation cleared[/green]")
12
+ try:
13
+ ui._run_session_start("clear")
14
+ except (AttributeError, RuntimeError, ValueError):
15
+ pass
8
16
  return True
9
17
 
10
18
 
11
19
  command = SlashCommand(
12
- name="clear",
13
- description="Clear conversation history",
14
- handler=_handle,
15
- aliases=("new",)
20
+ name="clear", description="Clear conversation history", handler=_handle, aliases=("new",)
16
21
  )
17
22
 
18
23
 
@@ -16,7 +16,7 @@ def _handle(ui: Any, _: str) -> bool:
16
16
  ui.console.print(
17
17
  f"\n[bold]Model (main -> {escape(str(main_pointer))}):[/bold] {escape(str(model_label))}"
18
18
  )
19
- ui.console.print(f"[bold]Safe Mode:[/bold] {escape(str(ui.safe_mode))}")
19
+ ui.console.print(f"[bold]Yolo Mode:[/bold] {escape(str(ui.yolo_mode))}")
20
20
  ui.console.print(f"[bold]Verbose:[/bold] {escape(str(ui.verbose))}")
21
21
  return True
22
22
 
@@ -40,7 +40,7 @@ def _handle(ui: Any, _: str) -> bool:
40
40
  if not ui.query_context:
41
41
  ui.query_context = QueryContext(
42
42
  tools=ui.get_default_tools(),
43
- safe_mode=ui.safe_mode,
43
+ yolo_mode=ui.yolo_mode,
44
44
  verbose=ui.verbose,
45
45
  )
46
46
 
@@ -126,7 +126,8 @@ def _handle(ui: Any, _: str) -> bool:
126
126
  except (OSError, RuntimeError, AttributeError, TypeError) as exc:
127
127
  logger.warning(
128
128
  "[context_cmd] Failed to summarize MCP tools: %s: %s",
129
- type(exc).__name__, exc,
129
+ type(exc).__name__,
130
+ exc,
130
131
  extra={"session_id": getattr(ui, "session_id", None)},
131
132
  )
132
133
  for line in lines:
@@ -125,10 +125,17 @@ def _mcp_status(
125
125
  servers = asyncio.run(_load())
126
126
  else:
127
127
  servers = runner(_load())
128
- except (OSError, RuntimeError, ConnectionError, ValueError, TypeError) as exc: # pragma: no cover - defensive
128
+ except (
129
+ OSError,
130
+ RuntimeError,
131
+ ConnectionError,
132
+ ValueError,
133
+ TypeError,
134
+ ) as exc: # pragma: no cover - defensive
129
135
  logger.warning(
130
136
  "[doctor] Failed to load MCP servers: %s: %s",
131
- type(exc).__name__, exc,
137
+ type(exc).__name__,
138
+ exc,
132
139
  exc_info=exc,
133
140
  )
134
141
  rows.append(_status_row("MCP", "error", f"Failed to load MCP config: {exc}"))
@@ -161,10 +168,17 @@ def _project_status(project_path: Path) -> Tuple[str, str, str]:
161
168
  return _status_row(
162
169
  "Project config", "ok", f".ripperdoc/config.json loaded for {project_path}"
163
170
  )
164
- except (OSError, IOError, json.JSONDecodeError, ValueError, TypeError) as exc: # pragma: no cover - defensive
171
+ except (
172
+ OSError,
173
+ IOError,
174
+ json.JSONDecodeError,
175
+ ValueError,
176
+ TypeError,
177
+ ) as exc: # pragma: no cover - defensive
165
178
  logger.warning(
166
179
  "[doctor] Failed to load project config: %s: %s",
167
- type(exc).__name__, exc,
180
+ type(exc).__name__,
181
+ exc,
168
182
  exc_info=exc,
169
183
  )
170
184
  return _status_row(
@@ -4,6 +4,7 @@ from .base import SlashCommand
4
4
 
5
5
  def _handle(ui: Any, _: str) -> bool:
6
6
  ui.console.print("[yellow]Goodbye![/yellow]")
7
+ ui._exit_reason = "prompt_input_exit"
7
8
  ui._should_exit = True
8
9
  return True
9
10
 
@@ -56,15 +56,9 @@ class HookConfigTarget:
56
56
  def _print_usage(console: Any) -> None:
57
57
  """Display available subcommands."""
58
58
  console.print("[bold]/hooks[/bold] — show configured hooks")
59
- console.print(
60
- "[bold]/hooks add [scope][/bold] — guided creator (scope: local|project|global)"
61
- )
62
- console.print(
63
- "[bold]/hooks edit [scope][/bold] — step-by-step edit of an existing hook"
64
- )
65
- console.print(
66
- "[bold]/hooks delete [scope][/bold] — remove a hook entry (alias: del)"
67
- )
59
+ console.print("[bold]/hooks add [scope][/bold] — guided creator (scope: local|project|global)")
60
+ console.print("[bold]/hooks edit [scope][/bold] — step-by-step edit of an existing hook")
61
+ console.print("[bold]/hooks delete [scope][/bold] — remove a hook entry (alias: del)")
68
62
  console.print(
69
63
  "[dim]Scopes: local=.ripperdoc/hooks.local.json (git-ignored), "
70
64
  "project=.ripperdoc/hooks.json (shared), "
@@ -96,7 +90,9 @@ def _get_targets(project_path: Path) -> List[HookConfigTarget]:
96
90
  ]
97
91
 
98
92
 
99
- def _select_target(console: Any, project_path: Path, scope_hint: Optional[str]) -> Optional[HookConfigTarget]:
93
+ def _select_target(
94
+ console: Any, project_path: Path, scope_hint: Optional[str]
95
+ ) -> Optional[HookConfigTarget]:
100
96
  """Prompt user to choose a hooks config target."""
101
97
  targets = _get_targets(project_path)
102
98
 
@@ -122,9 +118,7 @@ def _select_target(console: Any, project_path: Path, scope_hint: Optional[str])
122
118
  f" [dim]{target.description}[/dim]"
123
119
  )
124
120
 
125
- choice = console.input(
126
- f"Location [1-{len(targets)}, default {default_idx + 1}]: "
127
- ).strip()
121
+ choice = console.input(f"Location [1-{len(targets)}, default {default_idx + 1}]: ").strip()
128
122
 
129
123
  if not choice:
130
124
  return targets[default_idx]
@@ -151,9 +145,7 @@ def _load_hooks_json(console: Any, path: Path) -> Dict[str, List[Dict[str, Any]]
151
145
  logger.warning("[hooks_cmd] Invalid JSON in %s: %s", path, exc)
152
146
  return {}
153
147
  except (OSError, IOError, PermissionError) as exc:
154
- console.print(
155
- f"[red]Unable to read {escape(str(path))}: {escape(str(exc))}[/red]"
156
- )
148
+ console.print(f"[red]Unable to read {escape(str(path))}: {escape(str(exc))}[/red]")
157
149
  logger.warning("[hooks_cmd] Failed to read %s: %s", path, exc)
158
150
  return {}
159
151
 
@@ -176,9 +168,7 @@ def _load_hooks_json(console: Any, path: Path) -> Dict[str, List[Dict[str, Any]]
176
168
  if not isinstance(hooks_list, list):
177
169
  continue
178
170
  cleaned_hooks = [h for h in hooks_list if isinstance(h, dict)]
179
- cleaned_matchers.append(
180
- {"matcher": matcher.get("matcher"), "hooks": cleaned_hooks}
181
- )
171
+ cleaned_matchers.append({"matcher": matcher.get("matcher"), "hooks": cleaned_hooks})
182
172
  if cleaned_matchers:
183
173
  hooks[event_name] = cleaned_matchers
184
174
 
@@ -229,9 +219,7 @@ def _render_hooks_overview(ui: Any, project_path: Path) -> bool:
229
219
  if target.path.exists():
230
220
  ui.console.print(f" [green]✓[/green] {target.label}: {target.path}")
231
221
  else:
232
- ui.console.print(
233
- f" [dim]○[/dim] {target.label}: {target.path} [dim](not found)[/dim]"
234
- )
222
+ ui.console.print(f" [dim]○[/dim] {target.label}: {target.path} [dim](not found)[/dim]")
235
223
 
236
224
  ui.console.print()
237
225
 
@@ -289,9 +277,7 @@ def _render_hooks_overview(ui: Any, project_path: Path) -> bool:
289
277
  ui.console.print(table)
290
278
  ui.console.print()
291
279
 
292
- ui.console.print(
293
- "[dim]Tip: Hooks run in order. /hooks add launches a guided setup.[/dim]"
294
- )
280
+ ui.console.print("[dim]Tip: Hooks run in order. /hooks add launches a guided setup.[/dim]")
295
281
  return True
296
282
 
297
283
 
@@ -338,32 +324,28 @@ def _prompt_matcher_selection(
338
324
  if event_name not in MATCHER_EVENTS:
339
325
  if matchers:
340
326
  return matchers[0]
341
- matcher = {"matcher": None, "hooks": []}
342
- matchers.append(matcher)
343
- return matcher
327
+ default_matcher: Dict[str, Any] = {"matcher": None, "hooks": []}
328
+ matchers.append(default_matcher)
329
+ return default_matcher
344
330
 
345
331
  if not matchers:
346
- console.print(
347
- "\nMatcher (tool name or regex). Leave empty to match all tools (*)."
348
- )
332
+ console.print("\nMatcher (tool name or regex). Leave empty to match all tools (*).")
349
333
  pattern = console.input("Matcher: ").strip() or "*"
350
- matcher = {"matcher": pattern, "hooks": []}
351
- matchers.append(matcher)
352
- return matcher
334
+ first_matcher: Dict[str, Any] = {"matcher": pattern, "hooks": []}
335
+ matchers.append(first_matcher)
336
+ return first_matcher
353
337
 
354
338
  console.print("\nSelect matcher:")
355
339
  for idx, matcher in enumerate(matchers, start=1):
356
340
  label = matcher.get("matcher") or "*"
357
- hook_count = len(matcher.get("hooks", []))
341
+ hook_count = len(matcher.get("hooks") or [])
358
342
  console.print(f" [{idx}] {escape(str(label))} ({hook_count} hook(s))")
359
343
  new_idx = len(matchers) + 1
360
344
  console.print(f" [{new_idx}] New matcher pattern")
361
345
 
362
346
  default_choice = 1
363
347
  while True:
364
- choice = console.input(
365
- f"Matcher [1-{new_idx}, default {default_choice}]: "
366
- ).strip()
348
+ choice = console.input(f"Matcher [1-{new_idx}, default {default_choice}]: ").strip()
367
349
  if not choice:
368
350
  choice = str(default_choice)
369
351
  if choice.isdigit():
@@ -372,9 +354,9 @@ def _prompt_matcher_selection(
372
354
  return matchers[idx - 1]
373
355
  if idx == new_idx:
374
356
  pattern = console.input("New matcher (blank for '*'): ").strip() or "*"
375
- matcher = {"matcher": pattern, "hooks": []}
376
- matchers.append(matcher)
377
- return matcher
357
+ created_matcher: Dict[str, Any] = {"matcher": pattern, "hooks": []}
358
+ matchers.append(created_matcher)
359
+ return created_matcher
378
360
  console.print("[red]Choose a matcher number from the list.[/red]")
379
361
 
380
362
 
@@ -410,9 +392,7 @@ def _prompt_hook_details(
410
392
  )
411
393
  while True:
412
394
  hook_type = (
413
- console.input(
414
- f"Hook type ({type_label}) [default {default_type}]: "
415
- ).strip()
395
+ console.input(f"Hook type ({type_label}) [default {default_type}]: ").strip()
416
396
  or default_type
417
397
  ).lower()
418
398
  if hook_type in allowed_types:
@@ -424,14 +404,10 @@ def _prompt_hook_details(
424
404
  if hook_type == "prompt":
425
405
  existing_prompt = (existing_hook or {}).get("prompt", "")
426
406
  if existing_prompt:
427
- console.print(
428
- f"[dim]Current prompt:[/dim] {escape(existing_prompt)}", markup=False
429
- )
407
+ console.print(f"[dim]Current prompt:[/dim] {escape(existing_prompt)}", markup=False)
430
408
  while True:
431
409
  prompt_text = (
432
- console.input(
433
- "Prompt template (use $ARGUMENTS for JSON input): "
434
- ).strip()
410
+ console.input("Prompt template (use $ARGUMENTS for JSON input): ").strip()
435
411
  or existing_prompt
436
412
  )
437
413
  if prompt_text:
@@ -519,9 +495,7 @@ def _handle_edit(ui: Any, tokens: List[str], project_path: Path) -> bool:
519
495
 
520
496
  hooks = _load_hooks_json(console, target.path)
521
497
  if not hooks:
522
- console.print(
523
- "[yellow]No hooks found in this file. Use /hooks add to create one.[/yellow]"
524
- )
498
+ console.print("[yellow]No hooks found in this file. Use /hooks add to create one.[/yellow]")
525
499
  return True
526
500
 
527
501
  event_options = list(hooks.keys())
@@ -35,7 +35,9 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
35
35
  console.print("[bold]/models edit <name>[/bold] — edit an existing model profile")
36
36
  console.print("[bold]/models delete <name>[/bold] — delete a model profile")
37
37
  console.print("[bold]/models use <name>[/bold] — set the main model pointer")
38
- console.print("[bold]/models use <pointer> <name>[/bold] — set a specific pointer (main/task/reasoning/quick)")
38
+ console.print(
39
+ "[bold]/models use <pointer> <name>[/bold] — set a specific pointer (main/quick)"
40
+ )
39
41
 
40
42
  def parse_int(prompt_text: str, default_value: Optional[int]) -> Optional[int]:
41
43
  raw = console.input(prompt_text).strip()
@@ -186,7 +188,8 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
186
188
  console.print(f"[red]Failed to save model: {escape(str(exc))}[/red]")
187
189
  logger.warning(
188
190
  "[models_cmd] Failed to save model profile: %s: %s",
189
- type(exc).__name__, exc,
191
+ type(exc).__name__,
192
+ exc,
190
193
  extra={"profile": profile_name, "session_id": getattr(ui, "session_id", None)},
191
194
  )
192
195
  return True
@@ -295,7 +298,8 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
295
298
  console.print(f"[red]Failed to update model: {escape(str(exc))}[/red]")
296
299
  logger.warning(
297
300
  "[models_cmd] Failed to update model profile: %s: %s",
298
- type(exc).__name__, exc,
301
+ type(exc).__name__,
302
+ exc,
299
303
  extra={"profile": profile_name, "session_id": getattr(ui, "session_id", None)},
300
304
  )
301
305
  return True
@@ -319,21 +323,24 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
319
323
  print_models_usage()
320
324
  logger.warning(
321
325
  "[models_cmd] Failed to delete model profile: %s: %s",
322
- type(exc).__name__, exc,
326
+ type(exc).__name__,
327
+ exc,
323
328
  extra={"profile": target, "session_id": getattr(ui, "session_id", None)},
324
329
  )
325
330
  return True
326
331
 
327
332
  if subcmd in ("use", "main", "set-main"):
328
333
  # Support both "/models use <profile>" and "/models use <pointer> <profile>"
329
- valid_pointers = {"main", "task", "reasoning", "quick"}
334
+ valid_pointers = {"main", "quick"}
330
335
 
331
336
  if len(tokens) >= 3:
332
337
  # /models use <pointer> <profile>
333
338
  pointer = tokens[1].lower()
334
339
  target = tokens[2]
335
340
  if pointer not in valid_pointers:
336
- console.print(f"[red]Invalid pointer '{escape(pointer)}'. Valid pointers: {', '.join(valid_pointers)}[/red]")
341
+ console.print(
342
+ f"[red]Invalid pointer '{escape(pointer)}'. Valid pointers: {', '.join(valid_pointers)}[/red]"
343
+ )
337
344
  print_models_usage()
338
345
  return True
339
346
  elif len(tokens) >= 2:
@@ -346,9 +353,14 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
346
353
  pointer = "main"
347
354
  target = tokens[1]
348
355
  else:
349
- pointer = console.input("Pointer (main/task/reasoning/quick) [main]: ").strip().lower() or "main"
356
+ pointer = (
357
+ console.input("Pointer (main/quick) [main]: ").strip().lower()
358
+ or "main"
359
+ )
350
360
  if pointer not in valid_pointers:
351
- console.print(f"[red]Invalid pointer '{escape(pointer)}'. Valid pointers: {', '.join(valid_pointers)}[/red]")
361
+ console.print(
362
+ f"[red]Invalid pointer '{escape(pointer)}'. Valid pointers: {', '.join(valid_pointers)}[/red]"
363
+ )
352
364
  return True
353
365
  target = console.input(f"Model to use for '{pointer}': ").strip()
354
366
 
@@ -364,8 +376,13 @@ def _handle(ui: Any, trimmed_arg: str) -> bool:
364
376
  print_models_usage()
365
377
  logger.warning(
366
378
  "[models_cmd] Failed to set model pointer: %s: %s",
367
- type(exc).__name__, exc,
368
- extra={"pointer": pointer, "profile": target, "session_id": getattr(ui, "session_id", None)},
379
+ type(exc).__name__,
380
+ exc,
381
+ extra={
382
+ "pointer": pointer,
383
+ "profile": target,
384
+ "session_id": getattr(ui, "session_id", None),
385
+ },
369
386
  )
370
387
  return True
371
388