assistant 2.2.0a3__tar.gz → 2.2.0b1__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.
- {assistant-2.2.0a3/assistant.egg-info → assistant-2.2.0b1}/PKG-INFO +1 -1
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/__init__.py +1 -1
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/agent.py +8 -1
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/envindex.py +12 -1
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/completer.py +17 -5
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/shell.py +53 -6
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/setup_wizard.py +18 -12
- {assistant-2.2.0a3 → assistant-2.2.0b1/assistant.egg-info}/PKG-INFO +1 -1
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_envindex_suggestions.py +73 -5
- {assistant-2.2.0a3 → assistant-2.2.0b1}/LICENSE +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/MANIFEST.in +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/README.md +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/__main__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/as_client.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/as_service.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/builtin_cmds.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/codecache.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/compress.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/conditions.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/config.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/entry_points/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/entry_points/run_assistant.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/execer.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/history.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/listen/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/listen/__main__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/listen/interface.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/listen/main.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/main.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/memory.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/clear.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/exit.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/http_client.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/interface.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/message.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/google.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/llama_cpp.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/nim.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/ollama.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/openai.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/openrouter.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/providers/vllm.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/think.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/nlp/xonsh.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/parser.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/projectfile.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/bindings.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/dialogs.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/floats.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/layout.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/operators.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/strformat_utils.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/styles.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/ptk_shell/windows.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/say/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/say/interface.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/time.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/tools.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/tools_worker.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/traces/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/traces/cmd.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/traces/export.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/traces/schema.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/traces/store.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/utils.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/version.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant/vocabulary.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant.egg-info/SOURCES.txt +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant.egg-info/dependency_links.txt +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant.egg-info/entry_points.txt +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant.egg-info/requires.txt +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/assistant.egg-info/top_level.txt +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/pyproject.toml +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/setup.cfg +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/setup.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_bindings.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_builtin_cmds.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_compaction.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_compress.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_config.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_envindex.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_git_hook.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_history_bridge.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_http_client.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_init.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_interrupt.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_interrupt_real.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_listen_interrupt.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_memory.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_memory_sqlite.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_model_compare.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_projectfile.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_setup_wizard.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_startup_performance.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_tmux_interactive.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_tool_handling.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_tools.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_traces_agent.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_traces_cmd.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_traces_export.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_traces_schema.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_traces_store.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_tts_streaming.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_utils.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/tests/test_xontrib.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/xontrib/__init__.py +0 -0
- {assistant-2.2.0a3 → assistant-2.2.0b1}/xontrib/assistant.py +0 -0
|
@@ -5,7 +5,7 @@ import warnings
|
|
|
5
5
|
warnings.filterwarnings("ignore", category=DeprecationWarning, module="webrtcvad")
|
|
6
6
|
warnings.filterwarnings("ignore", category=UserWarning, module="webrtcvad")
|
|
7
7
|
|
|
8
|
-
__version__ = "2.2.
|
|
8
|
+
__version__ = "2.2.0b1"
|
|
9
9
|
|
|
10
10
|
USERNAME = os.environ.get("USER", "root")
|
|
11
11
|
HOME = os.environ.get("HOME", f"/home/{USERNAME}" if USERNAME != "root" else "/root")
|
|
@@ -450,7 +450,14 @@ class Orchestrator:
|
|
|
450
450
|
from assistant.envindex import env_index, render_suggestions
|
|
451
451
|
|
|
452
452
|
budget = int(getattr(cfg, "suggestions_budget", 800) or 800)
|
|
453
|
-
|
|
453
|
+
# Completion case: when the query is a single token, the user
|
|
454
|
+
# is mid-typing a completion — only names that extend the typed
|
|
455
|
+
# stem are valid candidates (``rm R`` → ``RELEASE_NOTES_*``,
|
|
456
|
+
# never ``README.md``). Multi-token queries stay unfiltered.
|
|
457
|
+
prefix = None
|
|
458
|
+
if len(query.split()) == 1:
|
|
459
|
+
prefix = query.strip()
|
|
460
|
+
suggestion = env_index.suggestions(query=query, limit=6, prefix=prefix)
|
|
454
461
|
entries = suggestion.get("results", [])
|
|
455
462
|
if entries:
|
|
456
463
|
body = render_suggestions(entries, budget=budget)
|
|
@@ -278,7 +278,9 @@ class EnvIndex:
|
|
|
278
278
|
scored.sort(key=lambda x: (-x[0], x[1]["category"], x[1]["name"]))
|
|
279
279
|
return {"results": [e for _, e in scored[:limit]]}
|
|
280
280
|
|
|
281
|
-
def suggest(
|
|
281
|
+
def suggest(
|
|
282
|
+
self, query: str, limit: int = 6, prefix: Optional[str] = None
|
|
283
|
+
) -> Dict[str, Any]:
|
|
282
284
|
"""Suggestions for ``query``, filtered by type and scored by frequency.
|
|
283
285
|
|
|
284
286
|
Reuses :meth:`search` for query relevance, then boosts each entry by how
|
|
@@ -287,6 +289,12 @@ class EnvIndex:
|
|
|
287
289
|
are kept in separate buckets so a single suggestion never mixes the two;
|
|
288
290
|
the final ``results`` interleave both buckets in weighted order.
|
|
289
291
|
|
|
292
|
+
When ``prefix`` is given, only entries whose name starts with it are
|
|
293
|
+
kept — the completion case: the user already typed the stem, so a
|
|
294
|
+
suggestion must extend it (``rm R`` → ``RELEASE_NOTES_*``, never
|
|
295
|
+
``README.md``). ``prefix`` is matched case-insensitively and applies
|
|
296
|
+
to both buckets.
|
|
297
|
+
|
|
290
298
|
Best-effort: never raises, never blocks on history. Returns
|
|
291
299
|
``{"results": [], "commands": [], "ctx": []}`` for empty queries.
|
|
292
300
|
"""
|
|
@@ -298,6 +306,9 @@ class EnvIndex:
|
|
|
298
306
|
if not query or not query.strip():
|
|
299
307
|
return empty
|
|
300
308
|
results = self.search(query, limit=100)["results"]
|
|
309
|
+
if prefix:
|
|
310
|
+
p = prefix.lower()
|
|
311
|
+
results = [e for e in results if e["name"].lower().startswith(p)]
|
|
301
312
|
if not results:
|
|
302
313
|
return empty
|
|
303
314
|
|
|
@@ -321,16 +321,28 @@ class AssistantCompleter:
|
|
|
321
321
|
|
|
322
322
|
# Get first word only (avoid multi-word completions confusing the UI)
|
|
323
323
|
pred_clean = pred.split()[0] if pred.split() else pred
|
|
324
|
+
# Strip trailing space (xonsh completions often include it)
|
|
325
|
+
pred_clean = pred_clean.rstrip()
|
|
324
326
|
|
|
325
327
|
if not pred_clean or pred_clean in seen:
|
|
326
328
|
continue
|
|
327
329
|
seen.add(pred_clean)
|
|
328
330
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
331
|
+
# The prediction must extend the typed stem (case-insensitive
|
|
332
|
+
# startswith). When the user typed ``rm R``, only ``R*``
|
|
333
|
+
# candidates are valid completions — the LLM's raw output is
|
|
334
|
+
# unfiltered and would otherwise surface ``README.md`` next to
|
|
335
|
+
# ``RELEASE_NOTES_*``.
|
|
336
|
+
if word_before_cursor and not pred_clean.lower().startswith(
|
|
337
|
+
word_before_cursor.lower()
|
|
338
|
+
):
|
|
339
|
+
continue
|
|
340
|
+
|
|
341
|
+
# The completion text replaces the typed stem: ``rm R`` +
|
|
342
|
+
# ``README.md`` → ``rm README.md`` (not ``rm R README.md``).
|
|
343
|
+
# ``start_position=-len(word_before_cursor)`` tells PTK to
|
|
344
|
+
# overwrite the stem, so the text must be the full candidate.
|
|
345
|
+
combined_word = pred_clean
|
|
334
346
|
meta = "✨" if self._completion_enabled and self.agent else "📋"
|
|
335
347
|
|
|
336
348
|
yield from (
|
|
@@ -371,11 +371,34 @@ class AssistantShell(PromptToolkitShell):
|
|
|
371
371
|
self.prompter: PromptSession = PromptSession(**ptk_args)
|
|
372
372
|
|
|
373
373
|
self.prompt_formatter = PTKPromptFormatter(self)
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
374
|
+
|
|
375
|
+
# Wrap in a deduplicating completer that strips trailing whitespace
|
|
376
|
+
# before comparing, so 'README.md' and 'README.md ' are deduplicated.
|
|
377
|
+
|
|
378
|
+
class _DedupCompleter:
|
|
379
|
+
def __init__(self, inner):
|
|
380
|
+
self.inner = inner
|
|
381
|
+
|
|
382
|
+
def get_completions(self, document, complete_event):
|
|
383
|
+
seen = set()
|
|
384
|
+
for comp in self.inner.get_completions(document, complete_event):
|
|
385
|
+
key = (
|
|
386
|
+
document.text[: document.cursor_position + comp.start_position]
|
|
387
|
+
+ comp.text.rstrip()
|
|
388
|
+
+ document.text[document.cursor_position:]
|
|
389
|
+
)
|
|
390
|
+
if key in seen:
|
|
391
|
+
continue
|
|
392
|
+
seen.add(key)
|
|
393
|
+
yield comp
|
|
394
|
+
|
|
395
|
+
self.pt_completer = _DedupCompleter(
|
|
396
|
+
merge_completers(
|
|
397
|
+
[
|
|
398
|
+
AssistantCompleter(),
|
|
399
|
+
PromptToolkitCompleter(self.completer, self.ctx, self),
|
|
400
|
+
]
|
|
401
|
+
)
|
|
379
402
|
)
|
|
380
403
|
|
|
381
404
|
# Use the xonsh bindings from parent init (which includes multiline_carriage_return)
|
|
@@ -1577,7 +1600,6 @@ class AssistantShell(PromptToolkitShell):
|
|
|
1577
1600
|
hist.last_cmd_rtn = 0
|
|
1578
1601
|
|
|
1579
1602
|
return response or ""
|
|
1580
|
-
|
|
1581
1603
|
def _try_builtin(self, line):
|
|
1582
1604
|
"""Try to dispatch a built-in command. Returns True if handled."""
|
|
1583
1605
|
stripped = line.strip()
|
|
@@ -1591,6 +1613,31 @@ class AssistantShell(PromptToolkitShell):
|
|
|
1591
1613
|
cmd_info = BUILTIN_COMMANDS[cmd_name]
|
|
1592
1614
|
fn = cmd_info.get("fn")
|
|
1593
1615
|
if fn is not None:
|
|
1616
|
+
# Reset terminal to a clean state before running the builtin.
|
|
1617
|
+
# prompt_toolkit's Application leaves the cursor at the prompt
|
|
1618
|
+
# position and may have the terminal in raw mode or with
|
|
1619
|
+
# modifyOtherKeys enabled. A nested prompt_toolkit app (e.g.
|
|
1620
|
+
# questionary in the wizard) will mis-render if the terminal
|
|
1621
|
+
# state is not reset first.
|
|
1622
|
+
try:
|
|
1623
|
+
import sys
|
|
1624
|
+
import tty
|
|
1625
|
+
import termios
|
|
1626
|
+
|
|
1627
|
+
fd = sys.stdin.fileno()
|
|
1628
|
+
# Disable modifyOtherKeys (mode 4) if enabled.
|
|
1629
|
+
sys.stdout.write("\x1b[>4;0m")
|
|
1630
|
+
sys.stdout.flush()
|
|
1631
|
+
# Reset terminal attributes to a known state (cooked mode,
|
|
1632
|
+
# echo on, etc.) so the nested app starts clean.
|
|
1633
|
+
try:
|
|
1634
|
+
attrs = termios.tcgetattr(fd)
|
|
1635
|
+
tty.setcookes(fd)
|
|
1636
|
+
except Exception:
|
|
1637
|
+
pass
|
|
1638
|
+
except Exception:
|
|
1639
|
+
pass
|
|
1640
|
+
|
|
1594
1641
|
rest = m.group(2).strip()
|
|
1595
1642
|
if rest:
|
|
1596
1643
|
fn(rest.split())
|
|
@@ -98,6 +98,15 @@ def load_existing_config(config_path: Optional[str] = None) -> bool:
|
|
|
98
98
|
return False
|
|
99
99
|
|
|
100
100
|
|
|
101
|
+
def _confirm_exit_without_saving() -> bool:
|
|
102
|
+
"""Ask the user to confirm exiting without saving.
|
|
103
|
+
|
|
104
|
+
Returns True if the user confirms, False if they cancel.
|
|
105
|
+
"""
|
|
106
|
+
return questionary.confirm(
|
|
107
|
+
"Are you sure you want to exit without saving?", default=False
|
|
108
|
+
).ask()
|
|
109
|
+
|
|
101
110
|
def run_main_menu() -> bool:
|
|
102
111
|
"""Main interactive menu for configuration management."""
|
|
103
112
|
cfg = get_config(force_reload=False)
|
|
@@ -150,19 +159,16 @@ def run_main_menu() -> bool:
|
|
|
150
159
|
console.print(f"[bold green]Configuration saved to {cfg.path}[/bold green]")
|
|
151
160
|
return True
|
|
152
161
|
elif choice == "Exit Without Saving ([Ctrl] + [C])":
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if choice is None:
|
|
156
|
-
# Ctrl+C in a menu also yields None: treat it as "exit without
|
|
157
|
-
# saving" (with confirmation) instead of re-asking forever.
|
|
158
|
-
console.print("[yellow]You are about to lose all unsaved changes.[/yellow]")
|
|
159
|
-
confirm = questionary.confirm(
|
|
160
|
-
"Are you sure you want to exit without saving?", default=False
|
|
161
|
-
).ask()
|
|
162
|
-
if confirm:
|
|
162
|
+
# Explicit menu item: confirm once, then exit (or re-ask if cancelled).
|
|
163
|
+
if _confirm_exit_without_saving():
|
|
163
164
|
return False
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
continue
|
|
166
|
+
elif choice is None:
|
|
167
|
+
# Ctrl+C in a menu: treat as "exit without saving" (with confirmation)
|
|
168
|
+
# instead of re-asking forever.
|
|
169
|
+
if _confirm_exit_without_saving():
|
|
170
|
+
return False
|
|
171
|
+
continue
|
|
166
172
|
|
|
167
173
|
def manage_providers(cfg) -> None:
|
|
168
174
|
"""Manage LLM providers."""
|
|
@@ -225,6 +225,27 @@ class TestSuggest:
|
|
|
225
225
|
assert r["results"] == []
|
|
226
226
|
assert r["commands"] == [] and r["ctx"] == []
|
|
227
227
|
|
|
228
|
+
def test_prefix_filters_by_name_startswith(self, monkeypatch):
|
|
229
|
+
entries = [
|
|
230
|
+
{"name": "rm", "category": "bin", "description": "remove files"},
|
|
231
|
+
{"name": "rm_rf", "category": "alias", "description": ""},
|
|
232
|
+
{"name": "README.md", "category": "bin", "description": ""},
|
|
233
|
+
{"name": "RELEASE_NOTES_2.2.0a3.md", "category": "bin", "description": ""},
|
|
234
|
+
{"name": "git", "category": "bin", "description": "vcs"},
|
|
235
|
+
]
|
|
236
|
+
idx = _patched_index(monkeypatch, entries)
|
|
237
|
+
r = idx.suggest("R", limit=6, prefix="R")
|
|
238
|
+
names = [e["name"] for e in r["results"]]
|
|
239
|
+
# Case-insensitive startswith: only the R* entries survive (git does
|
|
240
|
+
# not start with "r").
|
|
241
|
+
assert names == ["rm", "rm_rf", "README.md", "RELEASE_NOTES_2.2.0a3.md"]
|
|
242
|
+
|
|
243
|
+
def test_prefix_empty_when_no_match(self, monkeypatch):
|
|
244
|
+
entries = [{"name": "git", "category": "bin", "description": "vcs"}]
|
|
245
|
+
idx = _patched_index(monkeypatch, entries)
|
|
246
|
+
r = idx.suggest("zzz", limit=6, prefix="zzz")
|
|
247
|
+
assert r["results"] == [] and r["commands"] == [] and r["ctx"] == []
|
|
248
|
+
|
|
228
249
|
def test_suggestions_alias(self, monkeypatch):
|
|
229
250
|
# ``suggestions`` is an alias for ``suggest`` (prompt injection snippet)
|
|
230
251
|
entries = [{"name": "git", "category": "bin", "description": "vcs"}]
|
|
@@ -370,7 +391,7 @@ class TestDynamicEnvSuggestionBlock:
|
|
|
370
391
|
monkeypatch.setattr(idx, "_ensure", _ensure)
|
|
371
392
|
monkeypatch.setattr(envindex_mod, "env_index", idx, raising=True)
|
|
372
393
|
|
|
373
|
-
def _suggestions(query, limit=6):
|
|
394
|
+
def _suggestions(query, limit=6, prefix=None):
|
|
374
395
|
return {"results": results, "commands": results, "ctx": []}
|
|
375
396
|
|
|
376
397
|
monkeypatch.setattr(idx, "suggestions", _suggestions)
|
|
@@ -463,10 +484,8 @@ class TestDynamicEnvSuggestionBlock:
|
|
|
463
484
|
|
|
464
485
|
orch._cfg = get_config()
|
|
465
486
|
# Also need env_index.suggestions present; patch on the injected mod
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
sys.modules["assistant.envindex"].env_index.suggestions = (
|
|
469
|
-
lambda query, limit=6: {
|
|
487
|
+
__import__("sys").modules["assistant.envindex"].env_index.suggestions = (
|
|
488
|
+
lambda query, limit=6, prefix=None: {
|
|
470
489
|
"results": [{"name": "git", "category": "bin", "description": "vcs"}],
|
|
471
490
|
"commands": [],
|
|
472
491
|
"ctx": [],
|
|
@@ -475,6 +494,55 @@ class TestDynamicEnvSuggestionBlock:
|
|
|
475
494
|
orch._dynamic_env_blocks("git")
|
|
476
495
|
assert seen["budget"] == 123
|
|
477
496
|
|
|
497
|
+
def test_single_token_query_passes_prefix(self, monkeypatch):
|
|
498
|
+
seen = {}
|
|
499
|
+
|
|
500
|
+
def _suggestions(query, limit=6, prefix=None):
|
|
501
|
+
seen["prefix"] = prefix
|
|
502
|
+
return {"results": [], "commands": [], "ctx": []}
|
|
503
|
+
|
|
504
|
+
self._patch_index(monkeypatch, [])
|
|
505
|
+
# Re-patch with the capturing fake (overrides _patch_index's fake).
|
|
506
|
+
import assistant.envindex as envindex_mod
|
|
507
|
+
|
|
508
|
+
envindex_mod.env_index.suggestions = _suggestions
|
|
509
|
+
monkeypatch.setattr(
|
|
510
|
+
"assistant.config.Config.suggestions_enabled",
|
|
511
|
+
property(lambda self: True),
|
|
512
|
+
)
|
|
513
|
+
monkeypatch.setattr(
|
|
514
|
+
"assistant.config.Config.suggestions_budget",
|
|
515
|
+
property(lambda self: 800),
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
orch = self._orch(monkeypatch)
|
|
519
|
+
orch._dynamic_env_blocks("R")
|
|
520
|
+
assert seen["prefix"] == "R"
|
|
521
|
+
|
|
522
|
+
def test_multi_token_query_passes_no_prefix(self, monkeypatch):
|
|
523
|
+
seen = {}
|
|
524
|
+
|
|
525
|
+
def _suggestions(query, limit=6, prefix=None):
|
|
526
|
+
seen["prefix"] = prefix
|
|
527
|
+
return {"results": [], "commands": [], "ctx": []}
|
|
528
|
+
|
|
529
|
+
self._patch_index(monkeypatch, [])
|
|
530
|
+
import assistant.envindex as envindex_mod
|
|
531
|
+
|
|
532
|
+
envindex_mod.env_index.suggestions = _suggestions
|
|
533
|
+
monkeypatch.setattr(
|
|
534
|
+
"assistant.config.Config.suggestions_enabled",
|
|
535
|
+
property(lambda self: True),
|
|
536
|
+
)
|
|
537
|
+
monkeypatch.setattr(
|
|
538
|
+
"assistant.config.Config.suggestions_budget",
|
|
539
|
+
property(lambda self: 800),
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
orch = self._orch(monkeypatch)
|
|
543
|
+
orch._dynamic_env_blocks("rm R")
|
|
544
|
+
assert seen["prefix"] is None
|
|
545
|
+
|
|
478
546
|
|
|
479
547
|
class TestEnvSummary:
|
|
480
548
|
def test_env_summary_includes_previous_conversations(self, tmp_path, monkeypatch):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|