assistant 2.2.0b1__tar.gz → 2.2.1b1__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 (116) hide show
  1. {assistant-2.2.0b1/assistant.egg-info → assistant-2.2.1b1}/PKG-INFO +57 -7
  2. {assistant-2.2.0b1 → assistant-2.2.1b1}/README.md +56 -6
  3. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/__init__.py +5 -1
  4. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/agent.py +102 -26
  5. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/builtin_cmds.py +82 -13
  6. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/config.py +46 -0
  7. assistant-2.2.1b1/assistant/display.py +134 -0
  8. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/listen/interface.py +6 -7
  9. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/main.py +13 -136
  10. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/memory.py +72 -1
  11. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/shell.py +504 -119
  12. assistant-2.2.1b1/assistant/ptk_shell/toolbox.py +132 -0
  13. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/setup_wizard.py +59 -0
  14. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/tools.py +125 -7
  15. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/traces/store.py +93 -40
  16. {assistant-2.2.0b1 → assistant-2.2.1b1/assistant.egg-info}/PKG-INFO +57 -7
  17. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant.egg-info/SOURCES.txt +5 -0
  18. {assistant-2.2.0b1 → assistant-2.2.1b1}/setup.cfg +0 -1
  19. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_builtin_cmds.py +178 -0
  20. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_compaction.py +114 -0
  21. assistant-2.2.1b1/tests/test_display.py +236 -0
  22. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_interrupt.py +17 -25
  23. assistant-2.2.1b1/tests/test_join_live.py +88 -0
  24. assistant-2.2.1b1/tests/test_setup_wizard.py +68 -0
  25. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_startup_performance.py +8 -5
  26. assistant-2.2.1b1/tests/test_thinking_loop.py +128 -0
  27. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_tools.py +55 -2
  28. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_tts_streaming.py +199 -25
  29. assistant-2.2.0b1/tests/test_setup_wizard.py +0 -22
  30. {assistant-2.2.0b1 → assistant-2.2.1b1}/LICENSE +0 -0
  31. {assistant-2.2.0b1 → assistant-2.2.1b1}/MANIFEST.in +0 -0
  32. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/__main__.py +0 -0
  33. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/as_client.py +0 -0
  34. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/as_service.py +0 -0
  35. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/codecache.py +0 -0
  36. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/compress.py +0 -0
  37. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/conditions.py +0 -0
  38. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/entry_points/__init__.py +0 -0
  39. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/entry_points/run_assistant.py +0 -0
  40. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/envindex.py +0 -0
  41. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/execer.py +0 -0
  42. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/history.py +0 -0
  43. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/listen/__init__.py +0 -0
  44. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/listen/__main__.py +0 -0
  45. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/listen/main.py +0 -0
  46. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/__init__.py +0 -0
  47. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/clear.py +0 -0
  48. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/exit.py +0 -0
  49. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/http_client.py +0 -0
  50. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/interface.py +0 -0
  51. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/message.py +0 -0
  52. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/__init__.py +0 -0
  53. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/google.py +0 -0
  54. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/llama_cpp.py +0 -0
  55. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/nim.py +0 -0
  56. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/ollama.py +0 -0
  57. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/openai.py +0 -0
  58. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/openrouter.py +0 -0
  59. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/providers/vllm.py +0 -0
  60. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/think.py +0 -0
  61. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/nlp/xonsh.py +0 -0
  62. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/parser.py +0 -0
  63. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/projectfile.py +0 -0
  64. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/__init__.py +0 -0
  65. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/bindings.py +0 -0
  66. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/completer.py +0 -0
  67. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/dialogs.py +0 -0
  68. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/floats.py +0 -0
  69. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/layout.py +0 -0
  70. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/operators.py +0 -0
  71. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/strformat_utils.py +0 -0
  72. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/styles.py +0 -0
  73. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/ptk_shell/windows.py +0 -0
  74. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/say/__init__.py +0 -0
  75. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/say/interface.py +0 -0
  76. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/time.py +0 -0
  77. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/tools_worker.py +0 -0
  78. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/traces/__init__.py +0 -0
  79. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/traces/cmd.py +0 -0
  80. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/traces/export.py +0 -0
  81. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/traces/schema.py +0 -0
  82. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/utils.py +0 -0
  83. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/version.py +0 -0
  84. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant/vocabulary.py +0 -0
  85. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant.egg-info/dependency_links.txt +0 -0
  86. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant.egg-info/entry_points.txt +0 -0
  87. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant.egg-info/requires.txt +0 -0
  88. {assistant-2.2.0b1 → assistant-2.2.1b1}/assistant.egg-info/top_level.txt +0 -0
  89. {assistant-2.2.0b1 → assistant-2.2.1b1}/pyproject.toml +0 -0
  90. {assistant-2.2.0b1 → assistant-2.2.1b1}/setup.py +0 -0
  91. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_bindings.py +0 -0
  92. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_compress.py +0 -0
  93. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_config.py +0 -0
  94. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_envindex.py +0 -0
  95. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_envindex_suggestions.py +0 -0
  96. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_git_hook.py +0 -0
  97. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_history_bridge.py +0 -0
  98. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_http_client.py +0 -0
  99. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_init.py +0 -0
  100. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_interrupt_real.py +0 -0
  101. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_listen_interrupt.py +0 -0
  102. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_memory.py +0 -0
  103. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_memory_sqlite.py +0 -0
  104. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_model_compare.py +0 -0
  105. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_projectfile.py +0 -0
  106. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_tmux_interactive.py +0 -0
  107. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_tool_handling.py +0 -0
  108. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_traces_agent.py +0 -0
  109. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_traces_cmd.py +0 -0
  110. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_traces_export.py +0 -0
  111. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_traces_schema.py +0 -0
  112. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_traces_store.py +0 -0
  113. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_utils.py +0 -0
  114. {assistant-2.2.0b1 → assistant-2.2.1b1}/tests/test_xontrib.py +0 -0
  115. {assistant-2.2.0b1 → assistant-2.2.1b1}/xontrib/__init__.py +0 -0
  116. {assistant-2.2.0b1 → assistant-2.2.1b1}/xontrib/assistant.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: assistant
3
- Version: 2.2.0b1
3
+ Version: 2.2.1b1
4
4
  Summary: Your very own Assistant. Because you deserve it.
5
5
  Home-page: https://gitlab.com/waser-technologies/technologies/assistant
6
6
  Author: Danny Waser
@@ -126,6 +126,8 @@ pacman -S python-assistant
126
126
 
127
127
  </details>
128
128
 
129
+ Read [Use Assistant as Your Default Shell](#use-assistant-as-your-default-shell) for more information.
130
+
129
131
  ### 2. Run the Configuration Wizard
130
132
 
131
133
  On the first launch the wizard starts automatically. You can also re-run it at any time:
@@ -153,7 +155,7 @@ The configuration is saved to `~/.assistant/config.toml`.
153
155
  assistant
154
156
  ```
155
157
 
156
- That's it — you're in. Type commands, ask questions, or mix both.
158
+ That's it: you're in. Type commands, ask questions, or mix both.
157
159
 
158
160
  ---
159
161
 
@@ -434,16 +436,64 @@ Toggle shortcuts (Ctrl+O, Ctrl+Q) update the config automatically when pressed,
434
436
 
435
437
  ## Use Assistant as Your Default Shell
436
438
 
437
- > **This is not recommended in beta!**
439
+ Assistant is a full Xonsh shell, so it reads the same RC files (`~/.config/xonsh/rc.xsh` or `~/.xonshrc`) which means your existing config carries over as-is.
440
+
441
+ Read more about Xonsh [Installation Guide](https://xon.sh/install.html) and its [Run Control Files](https://xon.sh/xonshrc.html).
442
+
443
+ ### Install Assistant in a Stable, Isolated Environment
444
+
445
+ (so a system Python upgrade can't break your shell)
446
+
447
+ **Example with `uv`**
448
+
449
+ ```bash
450
+ env_root=~/.venvs
451
+ env_path=${env_root}/assistant
452
+ python_path=${env_path}/bin/python
453
+ mkdir -p $env_root
454
+ uv venv $env_path --python 3.13
455
+ uv pip install --python ${python_path} assistant
456
+ ```
457
+
458
+ From there to update Assistant, simply run:
459
+ ```bash
460
+ uv pip install --python ${python_path} -U assistant
461
+ ```
462
+
463
+ ### Create a Dedicated Terminal Profile
464
+
465
+ Since Assistant is a natural language shell and Xonsh is not ready to be fully POSIX compliant,
466
+ it is highly recommended that you create a dedicated profile for Assistant beside Xonsh and your other shells,
467
+ directly inside your terminal application,
468
+ where you can set Assistant as your default shell, instead of registering it for the system.
469
+
470
+ The path to Assistant is defined as shown in this example.
471
+ ```bash
472
+ assistant_bin=${env_path}/bin/assistant
473
+ ```
474
+
475
+ You can also create a symbolic link to Assistant in `~/.local/bin` (or any other location in `$PATH`) so that Assistant is easily accessible.
476
+
477
+ ```bash
478
+ ln -s $assistant_bin ~/.local/bin
479
+ ```
480
+
481
+ Or you could add `${env_path}/bin` to your `$PATH`.
438
482
 
439
- You should be able to add the location of `assistant` at the end of `/etc/shells`. You'll then be able to set `Assistant` as your default shell using `chsh`.
483
+ ### Register Assistant as a Shell for the System
484
+ > [!WARNING]
485
+ > If you read the Xonsh installation guide correctly, you understand that **you shouldn't try this method** unless:
486
+ > 1. you know what you are doing and want to test deeper interaction with the POSIX compliance of the system
487
+ > 2. you are ready to assume the consequences of potentially triggering multiple inference calls every time the system executes a command that exits with a non-zero code.
488
+ >
489
+ > Do the following at your own risk.
440
490
 
441
491
  ```bash
442
- sudo sh -c 'w=$(which assistant); echo $w >> /etc/shells'
443
- chsh -s $(which assistant)
492
+ sudo sh -c "echo ${assistant_bin} >> /etc/shells"
493
+ chsh -s $assistant_bin
444
494
  ```
445
495
 
446
- Log out and when you come back, `Assistant` should be your default shell.
496
+ Log out and back in, Assistant is now your default shell.
447
497
 
448
498
  ---
449
499
 
@@ -75,6 +75,8 @@ pacman -S python-assistant
75
75
 
76
76
  </details>
77
77
 
78
+ Read [Use Assistant as Your Default Shell](#use-assistant-as-your-default-shell) for more information.
79
+
78
80
  ### 2. Run the Configuration Wizard
79
81
 
80
82
  On the first launch the wizard starts automatically. You can also re-run it at any time:
@@ -102,7 +104,7 @@ The configuration is saved to `~/.assistant/config.toml`.
102
104
  assistant
103
105
  ```
104
106
 
105
- That's it — you're in. Type commands, ask questions, or mix both.
107
+ That's it: you're in. Type commands, ask questions, or mix both.
106
108
 
107
109
  ---
108
110
 
@@ -383,16 +385,64 @@ Toggle shortcuts (Ctrl+O, Ctrl+Q) update the config automatically when pressed,
383
385
 
384
386
  ## Use Assistant as Your Default Shell
385
387
 
386
- > **This is not recommended in beta!**
388
+ Assistant is a full Xonsh shell, so it reads the same RC files (`~/.config/xonsh/rc.xsh` or `~/.xonshrc`) which means your existing config carries over as-is.
389
+
390
+ Read more about Xonsh [Installation Guide](https://xon.sh/install.html) and its [Run Control Files](https://xon.sh/xonshrc.html).
391
+
392
+ ### Install Assistant in a Stable, Isolated Environment
393
+
394
+ (so a system Python upgrade can't break your shell)
395
+
396
+ **Example with `uv`**
397
+
398
+ ```bash
399
+ env_root=~/.venvs
400
+ env_path=${env_root}/assistant
401
+ python_path=${env_path}/bin/python
402
+ mkdir -p $env_root
403
+ uv venv $env_path --python 3.13
404
+ uv pip install --python ${python_path} assistant
405
+ ```
406
+
407
+ From there to update Assistant, simply run:
408
+ ```bash
409
+ uv pip install --python ${python_path} -U assistant
410
+ ```
411
+
412
+ ### Create a Dedicated Terminal Profile
413
+
414
+ Since Assistant is a natural language shell and Xonsh is not ready to be fully POSIX compliant,
415
+ it is highly recommended that you create a dedicated profile for Assistant beside Xonsh and your other shells,
416
+ directly inside your terminal application,
417
+ where you can set Assistant as your default shell, instead of registering it for the system.
418
+
419
+ The path to Assistant is defined as shown in this example.
420
+ ```bash
421
+ assistant_bin=${env_path}/bin/assistant
422
+ ```
423
+
424
+ You can also create a symbolic link to Assistant in `~/.local/bin` (or any other location in `$PATH`) so that Assistant is easily accessible.
425
+
426
+ ```bash
427
+ ln -s $assistant_bin ~/.local/bin
428
+ ```
429
+
430
+ Or you could add `${env_path}/bin` to your `$PATH`.
387
431
 
388
- You should be able to add the location of `assistant` at the end of `/etc/shells`. You'll then be able to set `Assistant` as your default shell using `chsh`.
432
+ ### Register Assistant as a Shell for the System
433
+ > [!WARNING]
434
+ > If you read the Xonsh installation guide correctly, you understand that **you shouldn't try this method** unless:
435
+ > 1. you know what you are doing and want to test deeper interaction with the POSIX compliance of the system
436
+ > 2. you are ready to assume the consequences of potentially triggering multiple inference calls every time the system executes a command that exits with a non-zero code.
437
+ >
438
+ > Do the following at your own risk.
389
439
 
390
440
  ```bash
391
- sudo sh -c 'w=$(which assistant); echo $w >> /etc/shells'
392
- chsh -s $(which assistant)
441
+ sudo sh -c "echo ${assistant_bin} >> /etc/shells"
442
+ chsh -s $assistant_bin
393
443
  ```
394
444
 
395
- Log out and when you come back, `Assistant` should be your default shell.
445
+ Log out and back in, Assistant is now your default shell.
396
446
 
397
447
  ---
398
448
 
@@ -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.0b1"
8
+ __version__ = "2.2.1b1"
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")
@@ -131,7 +131,9 @@ DEFAULT_CONFIG = {
131
131
  "max_turns": 50,
132
132
  "temperature": 0.1,
133
133
  "max_command_output_length": 10000,
134
+ "max_tool_output_lines": 50,
134
135
  "command_timeout": 180,
136
+ "tool_timeouts": {"xonsh": 180, "web_search": 15, "read_webpage": 20},
135
137
  },
136
138
  "memory": {
137
139
  "enabled": False,
@@ -161,6 +163,8 @@ DEFAULT_CONFIG = {
161
163
  # end of the system prompt, after the "Relevant commands" block.
162
164
  "suggestions_enabled": True,
163
165
  "suggestions_budget": 800,
166
+ "thinking_loop_enabled": True,
167
+ "thinking_loop_max_turns": 5,
164
168
  },
165
169
  "voice": {
166
170
  "tts_enabled": True,
@@ -11,7 +11,7 @@ import types
11
11
  from typing import Any, Callable, Dict, List, Optional
12
12
 
13
13
  from assistant.config import DEFAULT_CONFIG_PATH, get_config
14
- from assistant.main import get_random_thinking_sentence
14
+ from assistant.nlp.interface import get_random_thinking_sentence
15
15
  from assistant.memory import memory
16
16
  from assistant.nlp.providers import get_provider
17
17
  from assistant.nlp.xonsh import XONSH_INTRO
@@ -43,6 +43,10 @@ class Agent:
43
43
  model_cfg = cfg.get_model_config(model_id)
44
44
  self.model_name = model_cfg.get("id", "qwen3.5:latest")
45
45
  self.context_length = model_cfg.get("context_length", 256000)
46
+ # NOTE: config key "max_token" is shared between the completer (wants 1 = single word)
47
+ # and the main agent (wants a full output budget). The clamp below enforces a minimum
48
+ # of 4096 tokens for the agent, so the completer's max_token=1 is safely overridden.
49
+ self.max_tokens = max(4096, int(model_cfg.get("max_token", 4096)))
46
50
  self.think = model_cfg.get("think", False)
47
51
 
48
52
  # Resolve Provider
@@ -144,6 +148,10 @@ class Orchestrator:
144
148
  self._summ_model_id = None # Resolved dedicated model id
145
149
  self._active_agent = None # Agent of the current chat turn
146
150
 
151
+ # Thinking-loop detection (Phase 8): consecutive thinking turns + one-shot nudge flag.
152
+ self._consecutive_thinking_turns = 0
153
+ self._thinking_warned = False
154
+
147
155
  self._ensure_config()
148
156
 
149
157
  # Session setup: trace recording (Phase 1). Controlled by config
@@ -661,6 +669,10 @@ class Orchestrator:
661
669
  total_turns = 0
662
670
  max_turns = self._cfg.max_turns or 50
663
671
 
672
+ # Reset thinking-loop detection state for this chat() call.
673
+ self._consecutive_thinking_turns = 0
674
+ self._thinking_warned = False
675
+
664
676
  # Sync the static sys prompt once per session if possible
665
677
  # Cache for system prompt tokens to avoid re-calculating identical blocks
666
678
  while total_turns < max_turns:
@@ -774,6 +786,7 @@ class Orchestrator:
774
786
  temperature=self._cfg.temperature,
775
787
  think=use_think,
776
788
  tools=use_tools,
789
+ max_tokens=agent.max_tokens,
777
790
  )
778
791
  if _is_debug:
779
792
  sys.stderr.write(f"[DEBUG] Calling API ({agent.model_name})...\n")
@@ -782,7 +795,7 @@ class Orchestrator:
782
795
  self._emit(
783
796
  {
784
797
  "type": "status",
785
- "text": f"{agent.name}: {get_random_thinking_sentence()()}...",
798
+ "text": f"{agent.name}: {get_random_thinking_sentence()}...",
786
799
  }
787
800
  )
788
801
  if _is_debug:
@@ -823,6 +836,10 @@ class Orchestrator:
823
836
  return ctx + [{"role": "assistant", "content": ""}]
824
837
  raise e
825
838
 
839
+ # Thinking-loop detection (Phase 8): nudge the model after N consecutive
840
+ # thinking turns so it stops reasoning and answers directly.
841
+ self._detect_thinking_loop(think_text, context_messages)
842
+
826
843
  assistant_msg = {"role": "assistant", "content": visible}
827
844
  # Count tokens after adding reasoning - reasoning is preserved for trace
828
845
  # fidelity (kept in the message), so it counts toward the token budget.
@@ -1137,6 +1154,42 @@ class Orchestrator:
1137
1154
 
1138
1155
  return visible, think_text, tool_calls, is_streamed, response_meta
1139
1156
 
1157
+ def _detect_thinking_loop(self, think_text, context_messages):
1158
+ """Detect a thinking loop and nudge the model to answer directly.
1159
+
1160
+ After ``thinking_loop_max_turns`` consecutive turns where the model
1161
+ produced only reasoning (no visible content, no tool calls), inject a
1162
+ one-shot user-role nudge into ``context_messages`` and emit a status
1163
+ event. The nudge fires once per ``chat()`` call (``_thinking_warned``);
1164
+ any turn with visible content or tool calls resets the counter.
1165
+
1166
+ Args:
1167
+ think_text: The reasoning text from this turn (empty if none).
1168
+ context_messages: The mutable message list to append the nudge to.
1169
+ """
1170
+ if think_text:
1171
+ self._consecutive_thinking_turns += 1
1172
+ loop_max = self._cfg.thinking_loop_max_turns
1173
+ if (
1174
+ self._cfg.thinking_loop_enabled
1175
+ and loop_max > 0
1176
+ and self._consecutive_thinking_turns >= loop_max
1177
+ and not self._thinking_warned
1178
+ ):
1179
+ self._thinking_warned = True
1180
+ context_messages.append(
1181
+ {"role": "user", "content": "Please stop reasoning and answer directly."}
1182
+ )
1183
+ self._emit(
1184
+ {
1185
+ "type": "status",
1186
+ "text": "⚠️ detected thinking loop — nudging model to answer directly",
1187
+ }
1188
+ )
1189
+ else:
1190
+ self._consecutive_thinking_turns = 0
1191
+ self._thinking_warned = False
1192
+
1140
1193
  def _get_summ_agent(self):
1141
1194
  """Resolve the LLM used by density-layer compaction (couches 1-3).
1142
1195
 
@@ -1189,7 +1242,10 @@ class Orchestrator:
1189
1242
  # Use config limit or a generous 64k default.
1190
1243
  # We no longer hard-cap at 32k to allow modern large-context models.
1191
1244
  effective_limit = int(agent.context_length or 64000)
1192
- context_limit = effective_limit * threshold
1245
+ # Reserve a minimum output budget so the model always has room to respond.
1246
+ # The input must never consume more than (context_length - output_reserve).
1247
+ output_reserve = max(4096, int(agent.max_tokens or 4096))
1248
+ context_limit = min(int(effective_limit * threshold), effective_limit - output_reserve)
1193
1249
 
1194
1250
  current_tokens = count_messages_tokens(run_messages)
1195
1251
  if current_tokens > context_limit:
@@ -1212,6 +1268,14 @@ class Orchestrator:
1212
1268
  run_messages.clear()
1213
1269
  run_messages.extend(system_msgs)
1214
1270
  run_messages.extend([m for m in context_messages if m["role"] != "system"])
1271
+ # Hard safety net: if compaction still left us over the limit,
1272
+ # drop oldest non-system messages until we fit.
1273
+ while count_messages_tokens(run_messages) > context_limit:
1274
+ non_system = [i for i, m in enumerate(run_messages) if m.get("role") != "system"]
1275
+ if not non_system:
1276
+ break
1277
+ oldest_idx = non_system[0]
1278
+ run_messages.pop(oldest_idx)
1215
1279
  # Couche 3 rolling summary: injected as a trailing system block (the
1216
1280
  # lead system prompt is never mutated, keeping the KV-cache warm). It
1217
1281
  # lives outside the compaction branch so a summary produced earlier is
@@ -1331,35 +1395,24 @@ class Orchestrator:
1331
1395
  if "sigint_pipe_w" in _params:
1332
1396
  extra_kwargs["sigint_pipe_w"] = sigint_pipe_w
1333
1397
 
1398
+ _t0 = time.monotonic()
1334
1399
  res = fn(args, **extra_kwargs)
1400
+ _wall = time.monotonic() - _t0
1335
1401
  except KeyboardInterrupt as ke:
1336
1402
  # Re-raise KeyboardInterrupt so parent loop can handle cleanup
1337
1403
  raise ke
1338
1404
 
1339
1405
  # Check for abort after tool execution
1340
1406
  if self._abort_event.is_set():
1341
- self._abort_event.clear()
1342
1407
  return None
1343
1408
 
1344
- self._emit(
1345
- {
1346
- "type": "tool_output",
1347
- "command": cmd_display,
1348
- "output": res["content"],
1349
- "is_error": res["is_error"],
1350
- }
1351
- )
1352
-
1353
- tool_msg = {
1354
- "role": "tool",
1355
- "tool_call_id": t.id,
1356
- "name": fn_name,
1357
- "content": res["content"] or "",
1358
- }
1359
- # Soft bound (rtk-like): if the output exceeds the context budget,
1360
- # compress it for the model context (deterministic, command-aware).
1361
- # The full output is kept on _full_output for trace storage.
1362
- content = tool_msg["content"]
1409
+ # Structured display payload (e.g. search_conversation rows)
1410
+ # rides the event for the shell; it never enters tool_msg, so
1411
+ # the LLM context stays the flat ``content`` string.
1412
+ # Compute the output ONCE, shared by the model context and the
1413
+ # user display (issue #10: they must always be the same).
1414
+ content = res["content"] or ""
1415
+ display_output = content
1363
1416
  if content:
1364
1417
  bound = getattr(self._cfg, "max_tool_output_in_context", None)
1365
1418
  if not bound:
@@ -1372,13 +1425,36 @@ class Orchestrator:
1372
1425
  if bound and len(content) > bound:
1373
1426
  from assistant.compress import compress_tool_output
1374
1427
 
1375
- tool_msg["_full_output"] = content
1376
- tool_msg["content"] = compress_tool_output(
1428
+ display_output = compress_tool_output(
1377
1429
  content,
1378
1430
  command=cmd_display if fn_name == "xonsh" else fn_name,
1379
1431
  limit=bound,
1380
1432
  )
1381
- tool_msg["_compressed"] = True
1433
+
1434
+ event = {
1435
+ "type": "tool_output",
1436
+ "command": cmd_display,
1437
+ "tool": fn_name,
1438
+ "output": display_output,
1439
+ "is_error": res["is_error"],
1440
+ "wall": round(_wall, 3),
1441
+ "artifact": len(display_output or ""),
1442
+ }
1443
+ if res.get("results") is not None:
1444
+ event["results"] = res["results"]
1445
+ if res.get("result_kind"):
1446
+ event["result_kind"] = res["result_kind"]
1447
+ self._emit(event)
1448
+
1449
+ tool_msg = {
1450
+ "role": "tool",
1451
+ "tool_call_id": t.id,
1452
+ "name": fn_name,
1453
+ "content": display_output,
1454
+ }
1455
+ if display_output != content:
1456
+ tool_msg["_full_output"] = content
1457
+ tool_msg["_compressed"] = True
1382
1458
  # Optimization: populate cache immediately
1383
1459
  tool_msg["_tokens"] = count_message_tokens(tool_msg)
1384
1460
  context_messages.append(tool_msg)
@@ -1,12 +1,18 @@
1
1
  """Implements a simple echo command for xonsh."""
2
2
 
3
3
  import os
4
+ import sys
4
5
 
5
6
  from xonsh.built_ins import XSH
6
7
  from xonsh.tools import unthreadable
7
8
 
8
9
  from assistant.traces.cmd import TRACES_HELP, traces_fn
9
10
 
11
+ # Byte-identical to what terminfo's `clear` emits for tmux-256color/xterm
12
+ # (`\x1b[H` home + `\x1b[J` erase-below); no scrollback wipe, matching the
13
+ # external binary's behaviour so `clear` still looks like `clear`.
14
+ TERMINAL_CLEAR = "\x1b[H\x1b[J"
15
+
10
16
 
11
17
  def _log_md(shell, content):
12
18
  """Helper to lazily load and log Markdown content."""
@@ -124,9 +130,40 @@ def pwd_fn(args, stdin=None):
124
130
  return 0
125
131
 
126
132
 
133
+ CLEAR_HELP = """Usage: clear
134
+ Clear the terminal screen.
135
+
136
+ Runs in-process: the reset sequence is written straight to the terminal
137
+ instead of spawning the external `clear` binary through xonsh's command
138
+ pipeline (which costs a fork/exec plus the usual compile and capture pass)."""
139
+
140
+
141
+ def clear_fn(args, stdin=None):
142
+ """Clear the terminal screen."""
143
+ if args is None:
144
+ args = []
145
+ if "-h" in args or "--help" in args:
146
+ print(CLEAR_HELP)
147
+ return 0
148
+ sys.stdout.write(TERMINAL_CLEAR)
149
+ sys.stdout.flush()
150
+ return 0
151
+
152
+
127
153
  def assistant_fn(args, stdin=None):
128
- import subprocess
154
+ """Start a new assistant session (no args) or run a direct command.
155
+
156
+ With no arguments the behaviour depends on the context:
129
157
 
158
+ - interactive: start a brand-new session (reset the conversation context)
159
+ and show the intro exactly like at startup (spinner + streamed panel +
160
+ TTS karaoke).
161
+ - non-interactive (``assistant assistant``): print the intro text in a
162
+ single chunk on stdout, with no streaming display, spinner, or TTS.
163
+
164
+ With a subcommand (``-h``/``version``/...) the matching command runs.
165
+ Any other argument is sent to the assistant as a query.
166
+ """
130
167
  shell = XSH.shell.shell
131
168
 
132
169
  if args is None:
@@ -136,9 +173,9 @@ def assistant_fn(args, stdin=None):
136
173
  output = """# Help for the `assistant` command
137
174
  ```text
138
175
  Usage: assistant [SUBCOMMAND]
139
- Direct assistant commands:
140
- -h, --help Show this help
141
- version Show version
176
+ (no args) New session (interactive) / print the intro (non-interactive)
177
+ -h, --help Show this help
178
+ version Show version
142
179
  ```
143
180
  """
144
181
  _log_md(shell, output)
@@ -146,19 +183,46 @@ Direct assistant commands:
146
183
 
147
184
  if args and args[0] in ("version", "--version", "-V"):
148
185
  from assistant import __version__
186
+ # Here (in an interactive session),
187
+ # we should try to feed the string version
188
+ # of Assistant to the LM has a system output
189
+ # like when an error happens and we feed it to the LM
190
+ # with the user input for context.
191
+ # TODO: Implement LM response to version
192
+ _log_md(shell, f"Version {__version__}")
193
+ return 0
149
194
 
150
- _log_md(shell, f"Assistant version {__version__}")
195
+ if args:
196
+ # A real subcommand/query: send it to the assistant.
197
+ response = shell.kernel_interface.assistant("assistant " + " ".join(args))
198
+ if response:
199
+ _log_md(shell, response)
151
200
  return 0
152
201
 
153
- response = None
154
- if not args:
155
- response = shell.kernel_interface.assistant("Assistant?")
202
+ # No args: new session (interactive) or quick intro (non-interactive).
203
+ if XSH.env.get("XONSH_INTERACTIVE", False):
204
+ try:
205
+ shell.kernel_interface.agent_client.clear_context()
206
+ except Exception:
207
+ pass
208
+ shell.generate_intro()
209
+ else:
210
+ chunks = []
156
211
 
157
- if response is None and args is not None:
158
- response = shell.kernel_interface.assistant("assistant " + " ".join(args))
212
+ def _collect(event):
213
+ if event.get("type") == "response_stream":
214
+ c = event.get("text", "")
215
+ if c:
216
+ chunks.append(c)
159
217
 
160
- if response:
161
- _log_md(shell, response)
218
+ try:
219
+ shell.kernel_interface.get_intro(on_event=_collect)
220
+ except Exception as e:
221
+ shell.log_error(e)
222
+ return 0
223
+ intro_text = "".join(chunks).strip()
224
+ if intro_text:
225
+ print(intro_text)
162
226
  return 0
163
227
 
164
228
 
@@ -940,7 +1004,7 @@ BUILTIN_COMMANDS = {
940
1004
  },
941
1005
  "assistant": {
942
1006
  "fn": assistant_fn,
943
- "description": "Direct assistant commands (start/stop/restart services, etc.)",
1007
+ "description": "Start a new session (interactive) or print the intro (non-interactive); -h/version for info",
944
1008
  "usage": "Usage: assistant [SUBCOMMAND]",
945
1009
  },
946
1010
  "listen": {
@@ -963,4 +1027,9 @@ BUILTIN_COMMANDS = {
963
1027
  "description": "Print the current working directory",
964
1028
  "usage": PWD_HELP,
965
1029
  },
1030
+ "clear": {
1031
+ "fn": clear_fn,
1032
+ "description": "Clear the terminal screen",
1033
+ "usage": CLEAR_HELP,
1034
+ },
966
1035
  }
@@ -243,6 +243,27 @@ class Config:
243
243
  "command_timeout", DEFAULT_CONFIG["execution"]["command_timeout"]
244
244
  )
245
245
 
246
+ @property
247
+ def tool_timeouts(self) -> dict:
248
+ """Per-tool timeout (seconds) overrides; falls back to command_timeout."""
249
+ return self.raw.get("execution", {}).get(
250
+ "tool_timeouts", DEFAULT_CONFIG["execution"]["tool_timeouts"]
251
+ )
252
+
253
+ def get_tool_timeout(self, tool_name: str) -> int:
254
+ """Resolve the timeout (seconds) for a tool, falling back to command_timeout.
255
+
256
+ An explicit per-tool value wins; a missing or invalid entry falls back
257
+ to the global ``command_timeout``.
258
+ """
259
+ timeouts = self.tool_timeouts
260
+ if tool_name in timeouts:
261
+ try:
262
+ return int(timeouts[tool_name])
263
+ except (TypeError, ValueError):
264
+ pass
265
+ return self.command_timeout
266
+
246
267
  @property
247
268
  def memory_enabled(self) -> bool:
248
269
  return self.raw.get("memory", {}).get(
@@ -288,6 +309,14 @@ class Config:
288
309
  DEFAULT_CONFIG["execution"]["max_command_output_length"],
289
310
  )
290
311
 
312
+ @property
313
+ def max_tool_output_lines(self) -> int:
314
+ """Display-only line cap for tool output panels (0 = no line cap)."""
315
+ return self.raw.get("execution", {}).get(
316
+ "max_tool_output_lines",
317
+ DEFAULT_CONFIG["execution"]["max_tool_output_lines"],
318
+ )
319
+
291
320
  @property
292
321
  def compaction_threshold(self) -> float:
293
322
  return self.raw.get("context", {}).get(
@@ -418,6 +447,23 @@ class Config:
418
447
  )
419
448
  )
420
449
 
450
+ @property
451
+ def thinking_loop_enabled(self) -> bool:
452
+ """Toggle for thinking-loop detection (nudge model after N thinking turns)."""
453
+ return self.raw.get("context", {}).get(
454
+ "thinking_loop_enabled", DEFAULT_CONFIG["context"]["thinking_loop_enabled"]
455
+ )
456
+
457
+ @property
458
+ def thinking_loop_max_turns(self) -> int:
459
+ """Max consecutive thinking turns before a nudge (0 disables)."""
460
+ return int(
461
+ self.raw.get("context", {}).get(
462
+ "thinking_loop_max_turns",
463
+ DEFAULT_CONFIG["context"]["thinking_loop_max_turns"],
464
+ )
465
+ )
466
+
421
467
  @property
422
468
  def traces_enabled(self) -> bool:
423
469
  """Trace recording switch (Phase 1: on by default, explicit opt-out)."""