|
4 | 4 | import re
|
5 | 5 | import sys
|
6 | 6 | import termios
|
7 |
| -from typing import cast |
8 | 7 | import urllib.parse
|
9 | 8 | from collections.abc import Generator
|
10 | 9 | from pathlib import Path
|
| 10 | +from typing import cast |
11 | 11 |
|
12 | 12 | from .commands import action_descriptions, execute_cmd
|
13 | 13 | from .config import get_config
|
|
19 | 19 | from .message import Message
|
20 | 20 | from .prompts import get_workspace_prompt
|
21 | 21 | from .tools import (
|
| 22 | + ConfirmFunc, |
22 | 23 | ToolFormat,
|
23 | 24 | ToolUse,
|
24 |
| - has_tool, |
25 |
| - get_tools, |
26 | 25 | execute_msg,
|
27 |
| - ConfirmFunc, |
| 26 | + get_tools, |
| 27 | + has_tool, |
28 | 28 | set_tool_format,
|
29 | 29 | )
|
30 | 30 | from .tools.browser import read_url
|
@@ -126,41 +126,31 @@ def confirm_func(msg) -> bool:
|
126 | 126 | if prompt_msgs:
|
127 | 127 | while prompt_msgs:
|
128 | 128 | msg = prompt_msgs.pop(0)
|
129 |
| - if not msg.content.startswith("/") and msg.role == "user": |
130 |
| - msg = _include_paths(msg, workspace) |
131 |
| - manager.append(msg) |
132 | 129 | # if prompt is a user-command, execute it
|
133 |
| - if msg.role == "user" and execute_cmd(msg, manager, confirm_func): |
| 130 | + if execute_cmd(msg, manager, confirm_func): |
134 | 131 | continue
|
| 132 | + # else, collect paths |
| 133 | + msg = _include_paths(msg, workspace) |
| 134 | + manager.append(msg) |
135 | 135 |
|
136 | 136 | # Generate and execute response for this prompt
|
137 | 137 | while True:
|
138 | 138 | try:
|
139 | 139 | set_interruptible()
|
140 |
| - response_msgs = list( |
141 |
| - step( |
142 |
| - manager.log, |
143 |
| - stream, |
144 |
| - confirm_func, |
145 |
| - tool_format=tool_format_with_default, |
146 |
| - workspace=workspace, |
147 |
| - ) |
148 |
| - ) |
149 |
| - except KeyboardInterrupt: |
150 |
| - console.log("Interrupted. Stopping current execution.") |
151 |
| - manager.append(Message("system", INTERRUPT_CONTENT)) |
152 |
| - break |
| 140 | + for msg in step( |
| 141 | + manager.log, |
| 142 | + stream, |
| 143 | + confirm_func, |
| 144 | + tool_format=tool_format_with_default, |
| 145 | + workspace=workspace, |
| 146 | + ): |
| 147 | + manager.append(msg) |
| 148 | + # run any user-commands, if msg is from user |
| 149 | + if execute_cmd(msg, manager, confirm_func): |
| 150 | + break |
153 | 151 | finally:
|
154 | 152 | clear_interruptible()
|
155 | 153 |
|
156 |
| - for response_msg in response_msgs: |
157 |
| - manager.append(response_msg) |
158 |
| - # run any user-commands, if msg is from user |
159 |
| - if response_msg.role == "user" and execute_cmd( |
160 |
| - response_msg, manager, confirm_func |
161 |
| - ): |
162 |
| - break |
163 |
| - |
164 | 154 | # Check if there are any runnable tools left
|
165 | 155 | last_content = next(
|
166 | 156 | (
|
@@ -229,6 +219,8 @@ def step(
|
229 | 219 | msg = Message("user", inquiry, quiet=True)
|
230 | 220 | msg = _include_paths(msg, workspace)
|
231 | 221 | yield msg
|
| 222 | + if msg.content.startswith("/") and msg.role == "user": |
| 223 | + return |
232 | 224 | log = log.append(msg)
|
233 | 225 |
|
234 | 226 | # generate response and run tools
|
|
0 commit comments