python-agent-harness 1.5.6.8__tar.gz → 1.5.7.1__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.
- {python_agent_harness-1.5.6.8/python_agent_harness.egg-info → python_agent_harness-1.5.7.1}/PKG-INFO +10 -7
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/README.md +9 -6
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/pyproject.toml +1 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/__init__.py +1 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/cli.py +5 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/controller.py +9 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/restore.py +6 -2
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/io/persistence.py +9 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/core.py +43 -15
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/session/commands.py +88 -11
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/session/config.py +13 -7
- {python_agent_harness-1.5.6.8/python_agent_harness → python_agent_harness-1.5.7.1/python_agent_harness/session}/hooks.py +1 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/session/session.py +15 -6
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/filesystem.py +19 -4
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tui/commands.py +70 -32
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tui/core.py +7 -3
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tui/input.py +16 -7
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1/python_agent_harness.egg-info}/PKG-INFO +10 -7
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness.egg-info/SOURCES.txt +1 -1
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/LICENSE +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/__main__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/agent.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/context_manager.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/models.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/planmode.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/subagent.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/token_estimator.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/core/tool_runner.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/headless.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/server.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/view.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/io/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/io/attachments.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/io/diffrender.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/io/text_filter.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/llm/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/llm/client.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/mcp/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/mcp/client.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/mcp/config.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/mcp/manager.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/agent.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/agents/reviewer.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/build-switch.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/commands/explain.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/compact.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/initialize.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/plan-mode.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/plan.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/review.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/subagent.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/summary.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/task-completion-rules.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/title.md +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/session/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/agent_tool.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/base.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/bash.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/diffapply.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/edit.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/edit_mac.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/glob.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/glob_mac.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/grep.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/grep_mac.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/mcp.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/planexit.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/question.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/read.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/skill.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/todo.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tools/write.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tui/__init__.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tui/mouse.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/tui/render.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness.egg-info/dependency_links.txt +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness.egg-info/entry_points.txt +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness.egg-info/requires.txt +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness.egg-info/top_level.txt +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/setup.cfg +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/tests/test_invariants.py +0 -0
- {python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/tests/test_scenarios.py +0 -0
{python_agent_harness-1.5.6.8/python_agent_harness.egg-info → python_agent_harness-1.5.7.1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-agent-harness
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.7.1
|
|
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
|
|
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
|
|
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.
|
|
7
|
+
version = "1.5.7.1"
|
|
8
8
|
description = "A lightweight, hackable mini-OpenCode written in Python."
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Huming Chen", email = "chenhuming@gmail.com"}
|
{python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/cli.py
RENAMED
|
@@ -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
|
{python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/entry/restore.py
RENAMED
|
@@ -79,8 +79,12 @@ def load_saved_session(path: str) -> SavedSession:
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
def restore_agent(controller: Controller, agent: str | None, report: Report) -> None:
|
|
82
|
-
"""Switch to the saved AGENT;
|
|
83
|
-
|
|
82
|
+
"""Switch to the saved AGENT; keep the current agent when the session
|
|
83
|
+
was saved without one (pre-agent-era file), and fall back to the
|
|
84
|
+
default agent (so no stale tool exclusions linger) when the saved
|
|
85
|
+
name no longer exists. A session saved on the default agent records
|
|
86
|
+
``default`` explicitly (see SessionPersistence.metadata_block), so it
|
|
87
|
+
still switches back even when a custom agent is active now."""
|
|
84
88
|
if not agent:
|
|
85
89
|
return
|
|
86
90
|
try:
|
{python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/io/persistence.py
RENAMED
|
@@ -170,10 +170,18 @@ class SessionPersistence:
|
|
|
170
170
|
# -- saving ---------------------------------------------------------------
|
|
171
171
|
def metadata_block(self) -> str:
|
|
172
172
|
lines = [";; Local Variables:"]
|
|
173
|
+
# The agent is ALWAYS recorded: the built-in default is stored
|
|
174
|
+
# as "default" rather than omitted, so "saved on the default
|
|
175
|
+
# agent" stays distinguishable from a pre-agent-era file (no
|
|
176
|
+
# key at all) and /restore can switch a currently-active custom
|
|
177
|
+
# agent back to the default prompt. switch_agent also stores
|
|
178
|
+
# None there on a default switch (see Session.switch_agent),
|
|
179
|
+
# which is normalized to the reserved name here.
|
|
180
|
+
agent = self.agent if self.agent else "default"
|
|
173
181
|
pairs = [
|
|
174
182
|
("python-agent-harness--project-dir", self.project_dir),
|
|
175
183
|
("python-agent-harness--model", self.model),
|
|
176
|
-
("python-agent-harness--agent",
|
|
184
|
+
("python-agent-harness--agent", agent),
|
|
177
185
|
]
|
|
178
186
|
for name, value in pairs:
|
|
179
187
|
if value is None:
|
{python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/prompts/core.py
RENAMED
|
@@ -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
|
|
35
|
-
|
|
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
|
|
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
|
|
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
|
|
701
|
-
"""
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
|
715
|
+
if not directory.is_dir():
|
|
710
716
|
return {}
|
|
711
717
|
agents: dict[str, str] = {}
|
|
712
|
-
for f in sorted(
|
|
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
|
|
@@ -9,13 +9,17 @@ the run's user text.
|
|
|
9
9
|
Tool availability per command:
|
|
10
10
|
- init/review: all tools EXCEPT PlanExit (they are one-shot runs that
|
|
11
11
|
must not end in a plan/build handoff)
|
|
12
|
-
- custom commands (prompts/commands/*.md): all tools, incl. PlanExit
|
|
12
|
+
- custom commands (prompts/commands/*.md and paths.command_path): all tools, incl. PlanExit
|
|
13
13
|
- compact/summary: no tools at all (direct chat_sync calls, like the
|
|
14
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``.
|
|
15
18
|
"""
|
|
16
19
|
|
|
17
20
|
from __future__ import annotations
|
|
18
21
|
|
|
22
|
+
import os
|
|
19
23
|
import re
|
|
20
24
|
import subprocess
|
|
21
25
|
from collections.abc import Callable
|
|
@@ -27,6 +31,23 @@ from ..prompts import read_prompt_file
|
|
|
27
31
|
PROMPTS_DIR = Path(__file__).parents[1] / "prompts"
|
|
28
32
|
COMMANDS_DIR = PROMPTS_DIR / "commands"
|
|
29
33
|
|
|
34
|
+
# Custom command files take precedence over the builtin slash commands (see
|
|
35
|
+
# ``find_command``), so a configured ``review.md`` replaces ``/review``. The
|
|
36
|
+
# one exception is ``/exit``: it is the only way out of an interactive
|
|
37
|
+
# session, so a command file may not shadow it. Such a file is skipped and
|
|
38
|
+
# ``/help`` reports it instead of silently dropping it.
|
|
39
|
+
UNOVERRIDABLE_COMMAND_NAMES = frozenset({"exit"})
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _prompt_file_ref(f: Path) -> str:
|
|
43
|
+
"""Reference for ``read_prompt_file``: relative to the packaged prompts
|
|
44
|
+
dir when the file lives inside it (backward compatible), absolute
|
|
45
|
+
otherwise (a custom command dir configured via ``paths.command_path``)."""
|
|
46
|
+
try:
|
|
47
|
+
return str(f.relative_to(PROMPTS_DIR))
|
|
48
|
+
except ValueError:
|
|
49
|
+
return os.path.abspath(f)
|
|
50
|
+
|
|
30
51
|
|
|
31
52
|
def _substitute(text: str, path: str, extra: str | None) -> str:
|
|
32
53
|
text = text.replace("${path}", path)
|
|
@@ -144,18 +165,32 @@ def custom_name(file: str) -> str:
|
|
|
144
165
|
return base.strip("-")
|
|
145
166
|
|
|
146
167
|
|
|
147
|
-
def
|
|
148
|
-
|
|
168
|
+
def _resolve_commands_dir(commands_dir: str | os.PathLike | None) -> Path | None:
|
|
169
|
+
"""Absolute path of a configured commands dir, or None when unset."""
|
|
170
|
+
if not commands_dir:
|
|
171
|
+
return None
|
|
172
|
+
return Path(os.path.abspath(os.path.expanduser(commands_dir)))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _scan_commands_dir(directory: Path) -> list[SessionCommand]:
|
|
176
|
+
"""Commands defined by the ``*.md`` files in *directory*.
|
|
177
|
+
|
|
178
|
+
Files whose name normalizes to nothing (``---.md``) and files that
|
|
179
|
+
would shadow an unoverridable builtin (see
|
|
180
|
+
``UNOVERRIDABLE_COMMAND_NAMES``) are skipped, so the advertised
|
|
181
|
+
listing only contains runnable commands.
|
|
182
|
+
"""
|
|
183
|
+
if not directory.is_dir():
|
|
149
184
|
return []
|
|
150
185
|
commands = []
|
|
151
|
-
for f in sorted(
|
|
186
|
+
for f in sorted(directory.glob("*.md")):
|
|
152
187
|
name = custom_name(f.name)
|
|
153
|
-
if not name:
|
|
188
|
+
if not name or name in UNOVERRIDABLE_COMMAND_NAMES:
|
|
154
189
|
continue
|
|
155
190
|
commands.append(
|
|
156
191
|
SessionCommand(
|
|
157
192
|
name=name,
|
|
158
|
-
prompt_file=
|
|
193
|
+
prompt_file=_prompt_file_ref(f),
|
|
159
194
|
kickoff="Proceed with the task described in your instructions.\n",
|
|
160
195
|
status=f" Running {name}...",
|
|
161
196
|
)
|
|
@@ -163,13 +198,55 @@ def load_custom_commands() -> list[SessionCommand]:
|
|
|
163
198
|
return commands
|
|
164
199
|
|
|
165
200
|
|
|
166
|
-
def
|
|
167
|
-
"""
|
|
201
|
+
def unoverridable_command_names(commands_dir: str | os.PathLike | None = None) -> list[str]:
|
|
202
|
+
"""Names in *commands_dir* skipped because the builtin cannot be replaced.
|
|
203
|
+
|
|
204
|
+
Only ``exit`` is in that set; ``/help`` reports the files so the user
|
|
205
|
+
is not left wondering why their command never ran.
|
|
206
|
+
"""
|
|
207
|
+
directory = _resolve_commands_dir(commands_dir)
|
|
208
|
+
if directory is None or not directory.is_dir():
|
|
209
|
+
return []
|
|
210
|
+
return sorted(
|
|
211
|
+
name
|
|
212
|
+
for name in (custom_name(f.name) for f in sorted(directory.glob("*.md")))
|
|
213
|
+
if name in UNOVERRIDABLE_COMMAND_NAMES
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def load_custom_commands(
|
|
218
|
+
commands_dir: str | os.PathLike | None = None,
|
|
219
|
+
) -> list[SessionCommand]:
|
|
220
|
+
"""Load custom commands from the bundled and the configured directory.
|
|
221
|
+
|
|
222
|
+
The bundled ``prompts/commands/`` commands are always loaded. When
|
|
223
|
+
*commands_dir* is set (``paths.command_path`` in the config file),
|
|
224
|
+
its files are layered on top: a configured command overrides a
|
|
225
|
+
bundled one of the same name, and the remaining bundled commands stay
|
|
226
|
+
available. A missing configured directory contributes nothing.
|
|
227
|
+
"""
|
|
228
|
+
merged = {c.name: c for c in _scan_commands_dir(COMMANDS_DIR)}
|
|
229
|
+
configured = _resolve_commands_dir(commands_dir)
|
|
230
|
+
if configured is not None:
|
|
231
|
+
merged.update({c.name: c for c in _scan_commands_dir(configured)})
|
|
232
|
+
return [merged[name] for name in sorted(merged)]
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def find_command(name: str, commands_dir: str | os.PathLike | None = None) -> SessionCommand | None:
|
|
236
|
+
"""Look up a command by name.
|
|
237
|
+
|
|
238
|
+
Command files win over the builtin prompt commands, so a configured
|
|
239
|
+
``review.md`` replaces ``/review`` and an ``init.md`` replaces
|
|
240
|
+
``/init``. Among command files the configured directory wins over
|
|
241
|
+
the bundled one (see ``load_custom_commands``); the remaining bundled
|
|
242
|
+
``initialize.md``/``review.md`` prompts back the builtins when no
|
|
243
|
+
command file claims the name.
|
|
244
|
+
"""
|
|
245
|
+
for c in load_custom_commands(commands_dir):
|
|
246
|
+
if c.name == name:
|
|
247
|
+
return c
|
|
168
248
|
if name == "init":
|
|
169
249
|
return initialize_command()
|
|
170
250
|
if name == "review":
|
|
171
251
|
return review_command()
|
|
172
|
-
for c in load_custom_commands():
|
|
173
|
-
if c.name == name:
|
|
174
|
-
return c
|
|
175
252
|
return None
|
{python_agent_harness-1.5.6.8 → python_agent_harness-1.5.7.1}/python_agent_harness/session/config.py
RENAMED
|
@@ -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
|
|
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
|
|
565
|
-
Values are expanded (~ → home) and resolved
|
|
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
|
|
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
|
|
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)
|
|
@@ -19,7 +19,6 @@ from ..core.models import AgentMode, ImagePart
|
|
|
19
19
|
from ..core.planmode import PlanMode
|
|
20
20
|
from ..core.subagent import run_subagent
|
|
21
21
|
from ..core.token_estimator import TokenCalibrator
|
|
22
|
-
from ..hooks import HookRunner
|
|
23
22
|
from ..io.attachments import image_placeholder
|
|
24
23
|
from ..io.diffrender import sanitize_for_display
|
|
25
24
|
from ..io.persistence import SessionPersistence, escape_role_headers
|
|
@@ -32,6 +31,7 @@ from ..tools import Registry, ToolContext
|
|
|
32
31
|
from ..tools.base import PendingToolResult, resolve_path
|
|
33
32
|
from ..tools.filesystem import cleanup_spooled_files
|
|
34
33
|
from ..tools.mcp import mcp_tools_from_manager
|
|
34
|
+
from .hooks import HookRunner
|
|
35
35
|
|
|
36
36
|
if TYPE_CHECKING:
|
|
37
37
|
from ..tools.base import ToolRuntime
|
|
@@ -94,6 +94,8 @@ class Session:
|
|
|
94
94
|
registry: Registry | None = None,
|
|
95
95
|
context_path: str | None = None,
|
|
96
96
|
skill_path: str | None = None,
|
|
97
|
+
agent_path: str | None = None,
|
|
98
|
+
command_path: str | None = None,
|
|
97
99
|
mcp: MCPConfig | None = None,
|
|
98
100
|
mcp_manager: MCPManager | None = None,
|
|
99
101
|
model_profiles: dict[str, dict] | None = None,
|
|
@@ -115,6 +117,11 @@ class Session:
|
|
|
115
117
|
self.alive = True
|
|
116
118
|
self._configured_context_path = context_path
|
|
117
119
|
self._configured_skill_path = skill_path
|
|
120
|
+
# Custom agent / command directories (paths.agent_path and
|
|
121
|
+
# paths.command_path in the config file); None = the bundled
|
|
122
|
+
# prompts/agents and prompts/commands directories.
|
|
123
|
+
self._configured_agent_path = agent_path
|
|
124
|
+
self._configured_command_path = command_path
|
|
118
125
|
# Config file path (None = default resolution) — /model re-reads
|
|
119
126
|
# the ``models`` section from it on every invocation
|
|
120
127
|
self.config_path = config_path
|
|
@@ -252,7 +259,7 @@ class Session:
|
|
|
252
259
|
self.notify_fn: Callable[[str, Any], None] | None = None
|
|
253
260
|
self.confirm_fn: Callable[[str], bool] | None = None
|
|
254
261
|
self.ask_fn: Callable[[list[dict]], str] | None = None
|
|
255
|
-
# shell-command hooks (see hooks.py); none until the entry point
|
|
262
|
+
# shell-command hooks (see session/hooks.py); none until the entry point
|
|
256
263
|
# installs the configured ones (cli.make_session)
|
|
257
264
|
self.install_hooks([])
|
|
258
265
|
# Per-thread run identity for event emission, tagged by
|
|
@@ -262,7 +269,7 @@ class Session:
|
|
|
262
269
|
self._emit_local = threading.local()
|
|
263
270
|
|
|
264
271
|
# ------------------------------------------------------------------
|
|
265
|
-
# shell-command hooks (see hooks.py)
|
|
272
|
+
# shell-command hooks (see session/hooks.py)
|
|
266
273
|
# ------------------------------------------------------------------
|
|
267
274
|
def install_hooks(self, hooks: list) -> None:
|
|
268
275
|
"""Replace the session's hooks with HOOKS (a list of ``hooks.Hook``).
|
|
@@ -970,8 +977,10 @@ class Session:
|
|
|
970
977
|
def switch_agent(self, name: str) -> tuple[bool, str]:
|
|
971
978
|
"""Switch the main agent's system prompt to a named agent.
|
|
972
979
|
|
|
973
|
-
Agent prompt files are discovered from the
|
|
974
|
-
directory
|
|
980
|
+
Agent prompt files are discovered from the bundled
|
|
981
|
+
``prompts/agents/`` directory plus the configured agents directory
|
|
982
|
+
(``paths.agent_path``, whose files override bundled names); see
|
|
983
|
+
``python_agent_harness.prompts.discover_agents``.
|
|
975
984
|
The pseudo-name ``default`` restores the original system prompt
|
|
976
985
|
saved at session construction. Returns (success, message).
|
|
977
986
|
"""
|
|
@@ -982,7 +991,7 @@ class Session:
|
|
|
982
991
|
self._agent_excluded_tools = ()
|
|
983
992
|
return True, "switched to default agent"
|
|
984
993
|
|
|
985
|
-
agents = discover_agents()
|
|
994
|
+
agents = discover_agents(self._configured_agent_path)
|
|
986
995
|
prompt_file = agents.get(name)
|
|
987
996
|
if prompt_file is None:
|
|
988
997
|
available = ", ".join(sorted([RESERVED_AGENT_NAME, *agents.keys()]))
|
|
@@ -37,6 +37,7 @@ import os
|
|
|
37
37
|
import shutil # noqa: F401 (mock target for tests)
|
|
38
38
|
import stat
|
|
39
39
|
import subprocess # noqa: F401 (mock target for tests)
|
|
40
|
+
import sys
|
|
40
41
|
import tempfile
|
|
41
42
|
import threading
|
|
42
43
|
import time
|
|
@@ -94,12 +95,26 @@ def _spool(text: str, label: str) -> str:
|
|
|
94
95
|
suffix=".txt",
|
|
95
96
|
dir=_spool_dir(),
|
|
96
97
|
)
|
|
97
|
-
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
98
|
-
f.write(text)
|
|
99
|
-
with _spooled_files_lock:
|
|
100
|
-
_spooled_files.append(temp_file)
|
|
101
98
|
except OSError:
|
|
102
99
|
return _truncate(text, label)
|
|
100
|
+
try:
|
|
101
|
+
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
102
|
+
f.write(text)
|
|
103
|
+
except BaseException:
|
|
104
|
+
# The file exists on disk but was never tracked (tracking happens
|
|
105
|
+
# after a successful write), so cleanup_spooled_files could never
|
|
106
|
+
# remove it. Unlink before propagating to the in-memory fallback:
|
|
107
|
+
# a failed spool must not leave an orphan in TMPDIR — worst case a
|
|
108
|
+
# large, secret-bearing partial write surviving the session.
|
|
109
|
+
with contextlib.suppress(OSError):
|
|
110
|
+
os.unlink(temp_file)
|
|
111
|
+
if isinstance(sys.exc_info()[1], OSError):
|
|
112
|
+
# ordinary write failure (ENOSPC, quota, ...): fall back to
|
|
113
|
+
# in-memory truncation as before
|
|
114
|
+
return _truncate(text, label)
|
|
115
|
+
raise
|
|
116
|
+
with _spooled_files_lock:
|
|
117
|
+
_spooled_files.append(temp_file)
|
|
103
118
|
lines = text.splitlines()
|
|
104
119
|
preview = "\n".join(lines[:SPOOL_LINES])
|
|
105
120
|
return (
|