python-agent-harness 1.5.6.9__tar.gz → 1.5.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {python_agent_harness-1.5.6.9/python_agent_harness.egg-info → python_agent_harness-1.5.7.2}/PKG-INFO +10 -7
  2. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/README.md +9 -6
  3. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/pyproject.toml +1 -1
  4. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/__init__.py +1 -1
  5. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/cli.py +5 -1
  6. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/controller.py +9 -1
  7. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/llm/client.py +8 -2
  8. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/mcp/config.py +12 -0
  9. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/core.py +43 -15
  10. python_agent_harness-1.5.7.2/python_agent_harness/session/commands.py +248 -0
  11. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/session/config.py +13 -7
  12. {python_agent_harness-1.5.6.9/python_agent_harness → python_agent_harness-1.5.7.2/python_agent_harness/session}/hooks.py +1 -1
  13. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/session/session.py +15 -6
  14. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/filesystem.py +19 -4
  15. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/grep.py +1 -1
  16. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/read.py +5 -5
  17. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/write.py +2 -1
  18. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tui/commands.py +70 -32
  19. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tui/core.py +7 -3
  20. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tui/input.py +16 -7
  21. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2/python_agent_harness.egg-info}/PKG-INFO +10 -7
  22. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness.egg-info/SOURCES.txt +1 -1
  23. python_agent_harness-1.5.6.9/python_agent_harness/session/commands.py +0 -175
  24. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/LICENSE +0 -0
  25. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/__main__.py +0 -0
  26. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/__init__.py +0 -0
  27. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/agent.py +0 -0
  28. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/context_manager.py +0 -0
  29. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/models.py +0 -0
  30. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/planmode.py +0 -0
  31. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/subagent.py +0 -0
  32. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/token_estimator.py +0 -0
  33. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/core/tool_runner.py +0 -0
  34. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/__init__.py +0 -0
  35. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/headless.py +0 -0
  36. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/restore.py +0 -0
  37. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/server.py +0 -0
  38. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/entry/view.py +0 -0
  39. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/io/__init__.py +0 -0
  40. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/io/attachments.py +0 -0
  41. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/io/diffrender.py +0 -0
  42. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/io/persistence.py +0 -0
  43. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/io/text_filter.py +0 -0
  44. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/llm/__init__.py +0 -0
  45. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/mcp/__init__.py +0 -0
  46. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/mcp/client.py +0 -0
  47. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/mcp/manager.py +0 -0
  48. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/__init__.py +0 -0
  49. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/agent.md +0 -0
  50. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/agents/reviewer.md +0 -0
  51. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/build-switch.md +0 -0
  52. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/commands/explain.md +0 -0
  53. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/compact.md +0 -0
  54. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/initialize.md +0 -0
  55. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/plan-mode.md +0 -0
  56. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/plan.md +0 -0
  57. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/review.md +0 -0
  58. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/subagent.md +0 -0
  59. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/summary.md +0 -0
  60. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/task-completion-rules.md +0 -0
  61. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/prompts/title.md +0 -0
  62. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/session/__init__.py +0 -0
  63. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/__init__.py +0 -0
  64. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/agent_tool.py +0 -0
  65. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/base.py +0 -0
  66. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/bash.py +0 -0
  67. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/diffapply.py +0 -0
  68. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/edit.py +0 -0
  69. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/edit_mac.py +0 -0
  70. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/glob.py +0 -0
  71. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/glob_mac.py +0 -0
  72. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/grep_mac.py +0 -0
  73. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/mcp.py +0 -0
  74. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/planexit.py +0 -0
  75. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/question.py +0 -0
  76. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/skill.py +0 -0
  77. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tools/todo.py +0 -0
  78. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tui/__init__.py +0 -0
  79. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tui/mouse.py +0 -0
  80. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness/tui/render.py +0 -0
  81. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness.egg-info/dependency_links.txt +0 -0
  82. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness.egg-info/entry_points.txt +0 -0
  83. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness.egg-info/requires.txt +0 -0
  84. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/python_agent_harness.egg-info/top_level.txt +0 -0
  85. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/setup.cfg +0 -0
  86. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/tests/test_invariants.py +0 -0
  87. {python_agent_harness-1.5.6.9 → python_agent_harness-1.5.7.2}/tests/test_scenarios.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-agent-harness
3
- Version: 1.5.6.9
3
+ Version: 1.5.7.2
4
4
  Summary: A lightweight, hackable mini-OpenCode written in Python.
5
5
  Author-email: Huming Chen <chenhuming@gmail.com>
6
6
  License-Expression: MIT
@@ -79,8 +79,8 @@ Edit `~/.config/python-agent-harness/config.json` and set your `base_url`, `api_
79
79
  - **Persistent sessions** — auto-saved after every response to `~/.local/share/python-agent-harness/sessions/`, with LLM-generated titles and `/restore --latest` / `/sessions`.
80
80
  - **Focused TUI** — Rich-based with pinned status bar, Todos panel, inline diff rendering, and a `prompt_toolkit` editor with history and completion. `Esc+Enter` submits, `Ctrl-D` quits, `Ctrl-C` cancels.
81
81
  - **MCP support** — optional via `[mcp]` extra. MCP tools become ordinary agent tools (`mcp__<server>__<tool>`). Supports `stdio`, `streamable-http`, and `sse` transports.
82
- - **Slash commands** — built-in `/init`, `/review`, `/explain`, etc., plus custom commands from `prompts/commands/*.md`.
83
- - **Custom agents** — switch the main agent's system prompt at runtime with `/agent`. Agent files live in `prompts/agents/*.md` and support `name:` and `exclude_tools:` frontmatter.
82
+ - **Slash commands** — built-in `/init`, `/review`, `/explain`, etc., plus custom commands from `prompts/commands/*.md` (extendable via `paths.command_path`).
83
+ - **Custom agents** — switch the main agent's system prompt at runtime with `/agent`. Agent files live in `prompts/agents/*.md` (extendable via `paths.agent_path`) and support `name:` and `exclude_tools:` frontmatter.
84
84
  - **Hooks** — shell commands on `tool.before` / `tool.after` / `agent.start` / `agent.end`: block risky tool calls, feed linter output back to the model, add per-turn context, notify on completion. See [Hooks](#hooks).
85
85
  - **Embeddable runtime boundaries** — `headless --json` for one-shot CI/scripting; `serve` for hosting apps (resident process, bidirectional protocol: multi-turn memory, mid-run Q&A, protocol-level cancel).
86
86
 
@@ -132,11 +132,11 @@ A persistent, bidirectional runtime for hosting applications. Keeps the `Control
132
132
  | `/help` | List available commands |
133
133
  | `/exit` | Quit |
134
134
 
135
- Custom commands from `prompts/commands/*.md` are also registered (TUI only).
135
+ Custom commands from `prompts/commands/*.md` and `paths.command_path` are always registered (TUI only). A command file **replaces** the command of the same name — builtin or bundled (precedence: configured > bundled > builtin), except `/exit`, which cannot be shadowed. `/help` lists the overrides.
136
136
 
137
137
  ### Custom agents
138
138
 
139
- Agent files are markdown (`.md`) in `prompts/agents/`. Each becomes a switchable profile via `/agent`. Optional YAML frontmatter:
139
+ Agent files are markdown (`.md`) in `prompts/agents/`. Files in `paths.agent_path` are merged on top (a same-named configured agent wins; the rest stay available). Each becomes a switchable profile via `/agent`. Optional YAML frontmatter:
140
140
 
141
141
  - `name:` — override the agent name (defaults to file stem)
142
142
  - `exclude_tools:` — list of tool names to hide. Matches by exact name, glob (`mcp__git__*`), or `__`-delimited prefix (`mcp__git` hides `mcp__git__list_repos` but `Write` does NOT hide `TodoWrite`).
@@ -166,7 +166,9 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
166
166
  },
167
167
  "paths": {
168
168
  "context_path": null,
169
- "skill_path": null
169
+ "skill_path": null,
170
+ "agent_path": null,
171
+ "command_path": null
170
172
  },
171
173
  "mcp": {
172
174
  "servers": {
@@ -190,8 +192,9 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
190
192
  - **`models`** — named LLM profiles for `/model` switching. Partial settings; unset keys inherit from `llm`. `default` restores the main config.
191
193
  - **`context_windows`** — per-model context-window overrides (tokens). Keys are model names or substrings; first match wins. Overrides `CONTEXT_WINDOWS` in `config.py`.
192
194
  - **`subagent_llm`** — LLM config for `Agent` tool. Unset values inherit from `llm`. Set `profile` to reuse a `models` entry. Precedence: profile > `subagent_llm` > `llm` > env vars.
193
- - **`default_agent`** — agent name to use at session start (must exist in `prompts/agents/`). `null` = built-in default.
195
+ - **`default_agent`** — agent name to use at session start (must exist in the discovered agent set: bundled `prompts/agents/` plus `paths.agent_path`). `null` = built-in default.
194
196
  - **`paths.context_path` / `paths.skill_path`** — locations for context files and skills. Default: project-local `contexts/` and `skills/`.
197
+ - **`paths.agent_path` / `paths.command_path`** — extra directories for custom agents and slash commands, **merged** on top of the bundled `prompts/agents/` and `prompts/commands/`: a same-named configured file wins, everything else stays available. Absolute paths and `~` supported. (`context_path`/`skill_path` instead *replace* the project-local default.)
195
198
  - **`mcp.servers`** — MCP server config (requires `[mcp]` extra). Each supports `transport`, `command`, `args`, `env`, `url`, `headers`, `parallel`, `timeout`, `enabled`.
196
199
  - **`headless` / `serve`** — optional budget limits: `max_rounds` (LLM rounds) and `timeout` (wall-clock seconds). `--max-rounds` / `--timeout` override per call; `<= 0` or `null` disables. Unset = unlimited.
197
200
  - **`hooks`** — shell-command hooks; see [Hooks](#hooks).
@@ -45,8 +45,8 @@ Edit `~/.config/python-agent-harness/config.json` and set your `base_url`, `api_
45
45
  - **Persistent sessions** — auto-saved after every response to `~/.local/share/python-agent-harness/sessions/`, with LLM-generated titles and `/restore --latest` / `/sessions`.
46
46
  - **Focused TUI** — Rich-based with pinned status bar, Todos panel, inline diff rendering, and a `prompt_toolkit` editor with history and completion. `Esc+Enter` submits, `Ctrl-D` quits, `Ctrl-C` cancels.
47
47
  - **MCP support** — optional via `[mcp]` extra. MCP tools become ordinary agent tools (`mcp__<server>__<tool>`). Supports `stdio`, `streamable-http`, and `sse` transports.
48
- - **Slash commands** — built-in `/init`, `/review`, `/explain`, etc., plus custom commands from `prompts/commands/*.md`.
49
- - **Custom agents** — switch the main agent's system prompt at runtime with `/agent`. Agent files live in `prompts/agents/*.md` and support `name:` and `exclude_tools:` frontmatter.
48
+ - **Slash commands** — built-in `/init`, `/review`, `/explain`, etc., plus custom commands from `prompts/commands/*.md` (extendable via `paths.command_path`).
49
+ - **Custom agents** — switch the main agent's system prompt at runtime with `/agent`. Agent files live in `prompts/agents/*.md` (extendable via `paths.agent_path`) and support `name:` and `exclude_tools:` frontmatter.
50
50
  - **Hooks** — shell commands on `tool.before` / `tool.after` / `agent.start` / `agent.end`: block risky tool calls, feed linter output back to the model, add per-turn context, notify on completion. See [Hooks](#hooks).
51
51
  - **Embeddable runtime boundaries** — `headless --json` for one-shot CI/scripting; `serve` for hosting apps (resident process, bidirectional protocol: multi-turn memory, mid-run Q&A, protocol-level cancel).
52
52
 
@@ -98,11 +98,11 @@ A persistent, bidirectional runtime for hosting applications. Keeps the `Control
98
98
  | `/help` | List available commands |
99
99
  | `/exit` | Quit |
100
100
 
101
- Custom commands from `prompts/commands/*.md` are also registered (TUI only).
101
+ Custom commands from `prompts/commands/*.md` and `paths.command_path` are always registered (TUI only). A command file **replaces** the command of the same name — builtin or bundled (precedence: configured > bundled > builtin), except `/exit`, which cannot be shadowed. `/help` lists the overrides.
102
102
 
103
103
  ### Custom agents
104
104
 
105
- Agent files are markdown (`.md`) in `prompts/agents/`. Each becomes a switchable profile via `/agent`. Optional YAML frontmatter:
105
+ Agent files are markdown (`.md`) in `prompts/agents/`. Files in `paths.agent_path` are merged on top (a same-named configured agent wins; the rest stay available). Each becomes a switchable profile via `/agent`. Optional YAML frontmatter:
106
106
 
107
107
  - `name:` — override the agent name (defaults to file stem)
108
108
  - `exclude_tools:` — list of tool names to hide. Matches by exact name, glob (`mcp__git__*`), or `__`-delimited prefix (`mcp__git` hides `mcp__git__list_repos` but `Write` does NOT hide `TodoWrite`).
@@ -132,7 +132,9 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
132
132
  },
133
133
  "paths": {
134
134
  "context_path": null,
135
- "skill_path": null
135
+ "skill_path": null,
136
+ "agent_path": null,
137
+ "command_path": null
136
138
  },
137
139
  "mcp": {
138
140
  "servers": {
@@ -156,8 +158,9 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
156
158
  - **`models`** — named LLM profiles for `/model` switching. Partial settings; unset keys inherit from `llm`. `default` restores the main config.
157
159
  - **`context_windows`** — per-model context-window overrides (tokens). Keys are model names or substrings; first match wins. Overrides `CONTEXT_WINDOWS` in `config.py`.
158
160
  - **`subagent_llm`** — LLM config for `Agent` tool. Unset values inherit from `llm`. Set `profile` to reuse a `models` entry. Precedence: profile > `subagent_llm` > `llm` > env vars.
159
- - **`default_agent`** — agent name to use at session start (must exist in `prompts/agents/`). `null` = built-in default.
161
+ - **`default_agent`** — agent name to use at session start (must exist in the discovered agent set: bundled `prompts/agents/` plus `paths.agent_path`). `null` = built-in default.
160
162
  - **`paths.context_path` / `paths.skill_path`** — locations for context files and skills. Default: project-local `contexts/` and `skills/`.
163
+ - **`paths.agent_path` / `paths.command_path`** — extra directories for custom agents and slash commands, **merged** on top of the bundled `prompts/agents/` and `prompts/commands/`: a same-named configured file wins, everything else stays available. Absolute paths and `~` supported. (`context_path`/`skill_path` instead *replace* the project-local default.)
161
164
  - **`mcp.servers`** — MCP server config (requires `[mcp]` extra). Each supports `transport`, `command`, `args`, `env`, `url`, `headers`, `parallel`, `timeout`, `enabled`.
162
165
  - **`headless` / `serve`** — optional budget limits: `max_rounds` (LLM rounds) and `timeout` (wall-clock seconds). `--max-rounds` / `--timeout` override per call; `<= 0` or `null` disables. Unset = unlimited.
163
166
  - **`hooks`** — shell-command hooks; see [Hooks](#hooks).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-agent-harness"
7
- version = "1.5.6.9"
7
+ version = "1.5.7.2"
8
8
  description = "A lightweight, hackable mini-OpenCode written in Python."
9
9
  authors = [
10
10
  {name = "Huming Chen", email = "chenhuming@gmail.com"}
@@ -7,7 +7,7 @@ from .mcp.config import MCPConfig, MCPServerConfig
7
7
  from .mcp.manager import MCPManager
8
8
  from .session.session import Session
9
9
 
10
- __version__ = "1.5.6.9"
10
+ __version__ = "1.5.7.2"
11
11
 
12
12
  __all__ = [
13
13
  "Client",
@@ -8,7 +8,7 @@ Commands:
8
8
  runs repeatedly, answer mid-run questions, cancel
9
9
  config [--init] show effective LLM config / write a template file
10
10
 
11
- Custom commands (prompts/commands/*.md) — like init, review,
11
+ Custom commands (prompts/commands/*.md, or paths.command_path) — like init, review,
12
12
  sessions, restore and summary/explain — are TUI slash commands only;
13
13
  they are NOT registered as CLI subcommands.
14
14
 
@@ -136,6 +136,8 @@ def make_session(
136
136
  registry=registry,
137
137
  context_path=paths.get("context_path"),
138
138
  skill_path=paths.get("skill_path"),
139
+ agent_path=paths.get("agent_path"),
140
+ command_path=paths.get("command_path"),
139
141
  mcp=mcp_config,
140
142
  model_profiles=model_profiles,
141
143
  default_agent=default_agent,
@@ -305,6 +307,8 @@ def cmd_config(args: argparse.Namespace) -> int:
305
307
  print(f"timeout: {settings['timeout']}")
306
308
  print(f"context_path: {paths['context_path'] or '(default: <project>/contexts)'}")
307
309
  print(f"skill_path: {paths['skill_path'] or '(default: <project>/skills)'}")
310
+ print(f"agent_path: {paths['agent_path'] or '(unset: bundled prompts/agents only)'}")
311
+ print(f"command_path: {paths['command_path'] or '(unset: bundled prompts/commands only)'}")
308
312
  if mcp_config.servers:
309
313
  for name, server in mcp_config.servers.items():
310
314
  status = "enabled" if server.enabled else "disabled"
@@ -24,10 +24,10 @@ from typing import Any
24
24
 
25
25
  from ..core.agent import run_agent_loop
26
26
  from ..core.models import ImagePart, Message, TextPart, api_safe
27
- from ..hooks import RunStatus
28
27
  from ..io.attachments import AttachmentError, parse_at_references
29
28
  from ..io.text_filter import strip_final_check
30
29
  from ..session import config
30
+ from ..session.hooks import RunStatus
31
31
  from ..session.session import Session
32
32
  from .view import View
33
33
 
@@ -211,6 +211,14 @@ class Controller:
211
211
  def configured_context_path(self) -> str | None:
212
212
  return self.session._configured_context_path
213
213
 
214
+ @property
215
+ def configured_agent_path(self) -> str | None:
216
+ return self.session._configured_agent_path
217
+
218
+ @property
219
+ def configured_command_path(self) -> str | None:
220
+ return self.session._configured_command_path
221
+
214
222
  @property
215
223
  def startup_warnings(self) -> list[str]:
216
224
  return self.session.startup_warnings
@@ -1000,8 +1000,14 @@ class Client:
1000
1000
  {"id": "", "name": "", "arguments": ""},
1001
1001
  )
1002
1002
  fn = tc.get("function") or {}
1003
- entry["id"] += tc.get("id") or ""
1004
- entry["name"] += fn.get("name") or ""
1003
+ # id/name are not incremental like arguments: some backends and
1004
+ # proxies resend them in EVERY chunk, and appending blindly made
1005
+ # "ReadRead" (an unknown tool) out of a repeated "Read". A piece
1006
+ # equal to what is already accumulated is such a repeat and is
1007
+ # skipped; a genuinely split value ("Re" + "ad") still appends.
1008
+ for key, piece in (("id", tc.get("id")), ("name", fn.get("name"))):
1009
+ if isinstance(piece, str) and piece and piece != entry[key]:
1010
+ entry[key] += piece
1005
1011
  frag = fn.get("arguments") or ""
1006
1012
  if isinstance(frag, dict):
1007
1013
  frag = json.dumps(frag, ensure_ascii=False)
@@ -24,6 +24,7 @@ over this.
24
24
 
25
25
  from __future__ import annotations
26
26
 
27
+ import math
27
28
  from collections.abc import Mapping
28
29
  from dataclasses import dataclass, field
29
30
  from typing import Any
@@ -69,6 +70,17 @@ class MCPServerConfig:
69
70
  raise ValueError(f"MCP server {label!r}: stdio transport requires `command`")
70
71
  elif not self.url:
71
72
  raise ValueError(f"MCP server {label!r}: {self.transport} transport requires `url`")
73
+ # timeout flows into ``time.monotonic() + timeout`` and the SDK's
74
+ # read timeout; a string/bool/non-finite value from the JSON config
75
+ # would otherwise only fail mid-run with an opaque TypeError.
76
+ # bool is excluded explicitly because it is an int subclass.
77
+ t = self.timeout
78
+ if t is not None and (
79
+ isinstance(t, bool) or not isinstance(t, (int, float)) or not math.isfinite(t) or t <= 0
80
+ ):
81
+ raise ValueError(
82
+ f"MCP server {label!r}: `timeout` must be a positive number of seconds, got {t!r}"
83
+ )
72
84
 
73
85
 
74
86
  @dataclass
@@ -31,8 +31,15 @@ RESERVED_AGENT_NAME = "default"
31
31
 
32
32
 
33
33
  def read_prompt_file(name: str) -> str:
34
- """Read a prompt file from the package prompts dir."""
35
- path = PROMPTS_DIR / name
34
+ """Read a prompt file.
35
+
36
+ ``name`` is either relative to the packaged prompts directory or an
37
+ absolute path (a custom command configured outside the package, see
38
+ ``paths.command_path``).
39
+ """
40
+ path = Path(os.path.expanduser(name))
41
+ if not path.is_absolute():
42
+ path = PROMPTS_DIR / path
36
43
  return path.read_text(encoding="utf-8")
37
44
 
38
45
 
@@ -621,8 +628,10 @@ def compacted_messages(summary: str, prompts: list[str], resume: bool = False) -
621
628
 
622
629
 
623
630
  # ---- custom agent discovery -----------------------------------------------
624
- # Agent prompt files are markdown files (``*.md``) in
625
- # ``prompts/agents/``. Each file becomes a switchable agent profile
631
+ # Agent prompt files are markdown files (``*.md``) in the bundled
632
+ # ``prompts/agents/`` directory and, when configured, in
633
+ # ``paths.agent_path`` too (configured names override bundled ones).
634
+ # Each file becomes a switchable agent profile
626
635
  # available via the ``/agent`` TUI command. The file's stem (e.g.
627
636
  # ``reviewer.md`` → ``reviewer``) is the agent name; an optional YAML
628
637
  # frontmatter ``name:`` can override it, and an optional
@@ -630,7 +639,7 @@ def compacted_messages(summary: str, prompts: list[str], resume: bool = False) -
630
639
  # entry matches by exact name, glob pattern, or ``__``-delimited
631
640
  # prefix, e.g. ``mcp__git`` or ``mcp__git__*``). The built-in
632
641
  # ``default`` agent (``prompts/agent.md``) is always available and
633
- # cannot be overridden by a file in this directory.
642
+ # cannot be overridden by a file in these directories.
634
643
 
635
644
 
636
645
  def _agent_frontmatter(path: Path) -> dict[str, Any]:
@@ -697,21 +706,40 @@ def agent_exclude_tools(path: Path | str) -> tuple[str, ...]:
697
706
  return tuple(_agent_frontmatter(Path(path)).get("exclude_tools", ()))
698
707
 
699
708
 
700
- def discover_agents() -> dict[str, str]:
701
- """Discover all custom agents in the ``prompts/agents/`` directory.
702
-
703
- Returns a dict mapping agent name → absolute path to the prompt
704
- file. Files without a valid name are skipped. The built-in
705
- ``default`` agent is NOT included here — callers add it separately.
706
- A file claiming the reserved name ``default`` (via stem or
707
- frontmatter) is skipped: the built-in agent always wins.
709
+ def _scan_agents_dir(directory: Path) -> dict[str, str]:
710
+ """Map agent name → resolved prompt path for the ``*.md`` files in
711
+ *directory*. Files without a valid name are skipped, as is a file
712
+ claiming the reserved name ``default``. A missing directory yields
713
+ an empty dict.
708
714
  """
709
- if not AGENTS_DIR.is_dir():
715
+ if not directory.is_dir():
710
716
  return {}
711
717
  agents: dict[str, str] = {}
712
- for f in sorted(AGENTS_DIR.glob("*.md")):
718
+ for f in sorted(directory.glob("*.md")):
713
719
  name = _agent_name_from_file(f)
714
720
  if not name or name == RESERVED_AGENT_NAME:
715
721
  continue
716
722
  agents[name] = str(f.resolve())
717
723
  return agents
724
+
725
+
726
+ def discover_agents(agents_dir: str | os.PathLike | None = None) -> dict[str, str]:
727
+ """Discover custom agents from the bundled and the configured directory.
728
+
729
+ Returns a dict mapping agent name → absolute path to the prompt
730
+ file. Files without a valid name are skipped. The built-in
731
+ ``default`` agent is NOT included here — callers add it separately.
732
+ A file claiming the reserved name ``default`` (via stem or
733
+ frontmatter) is skipped: the built-in agent always wins.
734
+
735
+ The bundled ``prompts/agents/`` profiles are always discovered. When
736
+ *agents_dir* is set (``paths.agent_path`` in the config file), its
737
+ files are layered on top: a configured agent overrides a bundled one
738
+ of the same name, and the rest of the bundled profiles stay
739
+ available. A missing configured directory contributes nothing.
740
+ """
741
+ agents = _scan_agents_dir(AGENTS_DIR)
742
+ if agents_dir:
743
+ configured = Path(os.path.abspath(os.path.expanduser(agents_dir)))
744
+ agents.update(_scan_agents_dir(configured))
745
+ return agents
@@ -0,0 +1,248 @@
1
+ """Session commands: init, review, custom commands (TUI slash commands).
2
+
3
+ Ported from gptel-agent-harness-commands.el. Commands run inside the
4
+ current TUI session (tui._run_slash_command): the command's prompt
5
+ file becomes the run's system prompt, the project context and
6
+ task-completion rules stay in front of it, and the kickoff message is
7
+ the run's user text.
8
+
9
+ Tool availability per command:
10
+ - init/review: all tools EXCEPT PlanExit (they are one-shot runs that
11
+ must not end in a plan/build handoff)
12
+ - custom commands (prompts/commands/*.md and paths.command_path): all tools, incl. PlanExit
13
+ - compact/summary: no tools at all (direct chat_sync calls, like the
14
+ session-title generation)
15
+
16
+ Precedence: a command file (configured dir first, then bundled) replaces
17
+ the builtin slash command of the same name — see ``find_command``.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import os
23
+ import re
24
+ from collections.abc import Callable
25
+ from pathlib import Path
26
+ from typing import Any
27
+
28
+ from ..prompts import _git_toplevel, read_prompt_file
29
+
30
+ PROMPTS_DIR = Path(__file__).parents[1] / "prompts"
31
+ COMMANDS_DIR = PROMPTS_DIR / "commands"
32
+
33
+ # Custom command files take precedence over the builtin slash commands (see
34
+ # ``find_command``), so a configured ``review.md`` replaces ``/review``. The
35
+ # one exception is ``/exit``: it is the only way out of an interactive
36
+ # session, so a command file may not shadow it. Such a file is skipped and
37
+ # ``/help`` reports it instead of silently dropping it.
38
+ UNOVERRIDABLE_COMMAND_NAMES = frozenset({"exit"})
39
+
40
+
41
+ def _prompt_file_ref(f: Path) -> str:
42
+ """Reference for ``read_prompt_file``: relative to the packaged prompts
43
+ dir when the file lives inside it (backward compatible), absolute
44
+ otherwise (a custom command dir configured via ``paths.command_path``)."""
45
+ try:
46
+ return str(f.relative_to(PROMPTS_DIR))
47
+ except ValueError:
48
+ return os.path.abspath(f)
49
+
50
+
51
+ def _substitute(text: str, path: str, extra: str | None) -> str:
52
+ text = text.replace("${path}", path)
53
+ text = text.replace("$ARGUMENTS", extra or "")
54
+ return text
55
+
56
+
57
+ def _project_root(cwd: str) -> str:
58
+ """Best-effort project root (git worktree root, else parent with AGENTS.md).
59
+
60
+ Inside a git repository this delegates to ``prompts.core._git_toplevel``
61
+ so slash commands and project-context loading agree on the root.
62
+ Outside a repository the nearest ancestor holding ``AGENTS.md`` wins,
63
+ else *cwd* itself.
64
+ """
65
+ d = Path(cwd).resolve()
66
+ ancestors = [d, *d.parents]
67
+ if any((p / ".git").exists() for p in ancestors):
68
+ return _git_toplevel(cwd)
69
+ for parent in ancestors:
70
+ if (parent / "AGENTS.md").exists():
71
+ return str(parent)
72
+ return cwd
73
+
74
+
75
+ class SessionCommand:
76
+ """A configured session command (init/review/custom...)."""
77
+
78
+ def __init__(
79
+ self,
80
+ name: str,
81
+ prompt_file: str,
82
+ kickoff: str,
83
+ status: str,
84
+ validate_dir: bool = False,
85
+ allow_planexit: bool = True,
86
+ ) -> None:
87
+ self.name = name
88
+ self.prompt_file = prompt_file
89
+ self.kickoff = kickoff
90
+ self.status = status
91
+ self.validate_dir = validate_dir
92
+ self.allow_planexit = allow_planexit
93
+
94
+ def prepare(
95
+ self,
96
+ project_dir: str | None = None,
97
+ extra: str | None = None,
98
+ ) -> tuple[str, str, str]:
99
+ """Resolve (cwd, system_prompt, kickoff) without creating a session.
100
+
101
+ Used by the TUI slash commands, which run inside the current
102
+ session.
103
+ """
104
+ cwd = project_dir or _project_root(os.getcwd())
105
+ prompt = _substitute(read_prompt_file(self.prompt_file), cwd, extra)
106
+ kickoff = self.kickoff
107
+ if "${path}" in kickoff:
108
+ kickoff = kickoff.replace("${path}", cwd)
109
+ return cwd, prompt, kickoff
110
+
111
+
112
+ def initialize_command() -> SessionCommand:
113
+ return SessionCommand(
114
+ name="initialize",
115
+ prompt_file="initialize.md",
116
+ kickoff="Analyze the repository at ${path} and create/update AGENTS.md.\n",
117
+ status=" Initializing...",
118
+ validate_dir=True,
119
+ allow_planexit=False,
120
+ )
121
+
122
+
123
+ def review_command() -> SessionCommand:
124
+ return SessionCommand(
125
+ name="review",
126
+ prompt_file="review.md",
127
+ kickoff="Review the requested code changes.",
128
+ status=" Reviewing...",
129
+ allow_planexit=False,
130
+ )
131
+
132
+
133
+ def hide_planexit(session: Any) -> Callable[[], None] | None:
134
+ """Remove the PlanExit tool from SESSION's registry for a command run.
135
+
136
+ Used by init/review (``allow_planexit=False``), which may use every
137
+ tool except PlanExit: the run must not end in a plan/build handoff.
138
+ Custom commands keep PlanExit and skip this. Returns a callable
139
+ that restores the previous registration state (the tool is
140
+ stateless, so a fresh instance is equivalent), or None when there
141
+ was nothing to hide (PlanExit not registered — e.g. a build-mode
142
+ session, or a session without a registry). Call the returned
143
+ callable when the run finishes, including on cancellation or error.
144
+ """
145
+ registry = getattr(session, "registry", None)
146
+ if registry is None or registry.get("PlanExit") is None:
147
+ return None
148
+ registry.unregister("PlanExit")
149
+
150
+ def restore() -> None:
151
+ from ..tools import PlanExit
152
+
153
+ registry.register(PlanExit())
154
+
155
+ return restore
156
+
157
+
158
+ def custom_name(file: str) -> str:
159
+ base = Path(file).stem.lower()
160
+ base = re.sub(r"[^a-z0-9]+", "-", base)
161
+ return base.strip("-")
162
+
163
+
164
+ def _resolve_commands_dir(commands_dir: str | os.PathLike | None) -> Path | None:
165
+ """Absolute path of a configured commands dir, or None when unset."""
166
+ if not commands_dir:
167
+ return None
168
+ return Path(os.path.abspath(os.path.expanduser(commands_dir)))
169
+
170
+
171
+ def _scan_commands_dir(directory: Path) -> list[SessionCommand]:
172
+ """Commands defined by the ``*.md`` files in *directory*.
173
+
174
+ Files whose name normalizes to nothing (``---.md``) and files that
175
+ would shadow an unoverridable builtin (see
176
+ ``UNOVERRIDABLE_COMMAND_NAMES``) are skipped, so the advertised
177
+ listing only contains runnable commands.
178
+ """
179
+ if not directory.is_dir():
180
+ return []
181
+ commands = []
182
+ for f in sorted(directory.glob("*.md")):
183
+ name = custom_name(f.name)
184
+ if not name or name in UNOVERRIDABLE_COMMAND_NAMES:
185
+ continue
186
+ commands.append(
187
+ SessionCommand(
188
+ name=name,
189
+ prompt_file=_prompt_file_ref(f),
190
+ kickoff="Proceed with the task described in your instructions.\n",
191
+ status=f" Running {name}...",
192
+ )
193
+ )
194
+ return commands
195
+
196
+
197
+ def unoverridable_command_names(commands_dir: str | os.PathLike | None = None) -> list[str]:
198
+ """Names in *commands_dir* skipped because the builtin cannot be replaced.
199
+
200
+ Only ``exit`` is in that set; ``/help`` reports the files so the user
201
+ is not left wondering why their command never ran.
202
+ """
203
+ directory = _resolve_commands_dir(commands_dir)
204
+ if directory is None or not directory.is_dir():
205
+ return []
206
+ return sorted(
207
+ name
208
+ for name in (custom_name(f.name) for f in sorted(directory.glob("*.md")))
209
+ if name in UNOVERRIDABLE_COMMAND_NAMES
210
+ )
211
+
212
+
213
+ def load_custom_commands(
214
+ commands_dir: str | os.PathLike | None = None,
215
+ ) -> list[SessionCommand]:
216
+ """Load custom commands from the bundled and the configured directory.
217
+
218
+ The bundled ``prompts/commands/`` commands are always loaded. When
219
+ *commands_dir* is set (``paths.command_path`` in the config file),
220
+ its files are layered on top: a configured command overrides a
221
+ bundled one of the same name, and the remaining bundled commands stay
222
+ available. A missing configured directory contributes nothing.
223
+ """
224
+ merged = {c.name: c for c in _scan_commands_dir(COMMANDS_DIR)}
225
+ configured = _resolve_commands_dir(commands_dir)
226
+ if configured is not None:
227
+ merged.update({c.name: c for c in _scan_commands_dir(configured)})
228
+ return [merged[name] for name in sorted(merged)]
229
+
230
+
231
+ def find_command(name: str, commands_dir: str | os.PathLike | None = None) -> SessionCommand | None:
232
+ """Look up a command by name.
233
+
234
+ Command files win over the builtin prompt commands, so a configured
235
+ ``review.md`` replaces ``/review`` and an ``init.md`` replaces
236
+ ``/init``. Among command files the configured directory wins over
237
+ the bundled one (see ``load_custom_commands``); the remaining bundled
238
+ ``initialize.md``/``review.md`` prompts back the builtins when no
239
+ command file claims the name.
240
+ """
241
+ for c in load_custom_commands(commands_dir):
242
+ if c.name == name:
243
+ return c
244
+ if name == "init":
245
+ return initialize_command()
246
+ if name == "review":
247
+ return review_command()
248
+ return None
@@ -244,6 +244,8 @@ DEFAULT_LLM: dict = {
244
244
  DEFAULT_PATHS: dict = {
245
245
  "context_path": None,
246
246
  "skill_path": None,
247
+ "agent_path": None,
248
+ "command_path": None,
247
249
  }
248
250
 
249
251
  # Sub-agent LLM overrides: every key defaults to None, meaning "inherit
@@ -319,9 +321,11 @@ CONFIG_TEMPLATE = """\
319
321
  "env_passthrough": []
320
322
  }},
321
323
  "paths": {{
322
- "_comment": "Optional overrides for context and skill directories. Absolute paths or ~ expansion supported.",
324
+ "_comment": "Optional overrides for context files, skills, custom agents, and custom commands. Absolute paths or ~ expansion supported. context_path/skill_path replace the project-local default; agent_path/command_path are merged on top of the bundled prompts/ directories, where a same-named configured file wins.",
323
325
  "context_path": null,
324
- "skill_path": null
326
+ "skill_path": null,
327
+ "agent_path": null,
328
+ "command_path": null
325
329
  }},
326
330
  "hooks": {{
327
331
  "_comment": "Optional shell-command hooks (see README 'Hooks'). Events: tool.before, tool.after, agent.start, agent.end; each a list of {{command, matcher?, timeout?, fail_closed?, env_passthrough?}}. A command runs via /bin/sh -c in the project dir with the event as JSON on stdin. Exit 2 = tool.before: block the call (stderr = reason); tool.after: stderr is feedback appended to the result. agent.start: stdout (exit 0) is context for the turn. agent.end: notification. The payload is model-written (untrusted): never eval it. Secret-looking env vars are removed unless listed in env_passthrough. Keys starting with _ are ignored: copy entries from _examples to enable them.",
@@ -561,9 +565,11 @@ def load_serve_limits(path: str | os.PathLike | None = None) -> tuple[int | None
561
565
  def load_paths_config(path: str | os.PathLike | None = None) -> dict:
562
566
  """Load paths settings from the config file.
563
567
 
564
- Returns a dict with ``context_path`` and ``skill_path`` keys.
565
- Values are expanded (~ → home) and resolved to absolute paths when
566
- set; None means "use default discovery logic".
568
+ Returns a dict with ``context_path``, ``skill_path``, ``agent_path``,
569
+ and ``command_path`` keys. Values are expanded (~ → home) and resolved
570
+ to absolute paths when set; None means "use default discovery logic"
571
+ (for ``agent_path``/``command_path``: the bundled ``prompts/``
572
+ directories only, since those are merged rather than replaced).
567
573
  """
568
574
  settings = dict(DEFAULT_PATHS)
569
575
  try:
@@ -573,7 +579,7 @@ def load_paths_config(path: str | os.PathLike | None = None) -> dict:
573
579
  paths = data.get("paths") or {}
574
580
  if not isinstance(paths, dict):
575
581
  return settings
576
- for key in ("context_path", "skill_path"):
582
+ for key in ("context_path", "skill_path", "agent_path", "command_path"):
577
583
  val = paths.get(key)
578
584
  if isinstance(val, str) and val.strip():
579
585
  settings[key] = os.path.abspath(os.path.expanduser(val.strip()))
@@ -608,7 +614,7 @@ def load_hooks(path: str | os.PathLike | None = None) -> list:
608
614
  file or a malformed entry raises ValueError, so a configured guard
609
615
  stops the session instead of being silently dropped.
610
616
  """
611
- from ..hooks import parse_hooks # lazy: keep config import-light
617
+ from .hooks import parse_hooks # lazy: keep config import-light
612
618
 
613
619
  section = _read_config(path).get("hooks")
614
620
  try:
@@ -317,7 +317,7 @@ def _stop(proc: subprocess.Popen[bytes], readers: list[threading.Thread]) -> Non
317
317
  def _env_builder() -> Callable[[Hook], dict[str, str]]:
318
318
  """Per-event environment: os.environ snapshotted and scrubbed ONCE
319
319
  (the scrub can stat paths), then each hook's passthrough added back."""
320
- from .tools.bash import scrubbed_env # lazy: avoids an import cycle
320
+ from ..tools.bash import scrubbed_env # lazy: avoids an import cycle
321
321
 
322
322
  full = dict(os.environ)
323
323
  base = scrubbed_env(full)