python-agent-harness 1.5.7.2__tar.gz → 1.5.7.4__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.7.2/python_agent_harness.egg-info → python_agent_harness-1.5.7.4}/PKG-INFO +6 -2
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/README.md +5 -1
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/pyproject.toml +1 -1
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/__init__.py +1 -1
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/agent.py +3 -12
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/context_manager.py +0 -3
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/models.py +0 -1
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/tool_runner.py +1 -20
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/cli.py +18 -14
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/controller.py +1 -3
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/headless.py +0 -3
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/server.py +6 -15
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/attachments.py +1 -17
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/diffrender.py +0 -4
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/persistence.py +4 -10
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/llm/client.py +134 -8
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/core.py +3 -4
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/session/commands.py +2 -5
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/session/config.py +100 -42
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/session/session.py +46 -18
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/agent_tool.py +1 -8
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/base.py +10 -9
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/diffapply.py +0 -2
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/edit.py +0 -1
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/filesystem.py +79 -7
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/glob.py +0 -3
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/planexit.py +0 -2
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/question.py +0 -2
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tui/commands.py +246 -21
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tui/input.py +1 -2
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tui/render.py +4 -5
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4/python_agent_harness.egg-info}/PKG-INFO +6 -2
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/tests/test_scenarios.py +2 -1
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/LICENSE +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/__main__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/planmode.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/subagent.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/token_estimator.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/restore.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/view.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/text_filter.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/llm/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/mcp/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/mcp/client.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/mcp/config.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/mcp/manager.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/agent.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/agents/reviewer.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/build-switch.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/commands/explain.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/compact.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/initialize.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/plan-mode.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/plan.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/review.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/subagent.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/summary.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/task-completion-rules.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/prompts/title.md +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/session/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/session/hooks.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/bash.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/edit_mac.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/glob_mac.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/grep.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/grep_mac.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/mcp.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/read.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/skill.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/todo.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tools/write.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tui/__init__.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tui/core.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/tui/mouse.py +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness.egg-info/SOURCES.txt +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness.egg-info/dependency_links.txt +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness.egg-info/entry_points.txt +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness.egg-info/requires.txt +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness.egg-info/top_level.txt +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/setup.cfg +0 -0
- {python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/tests/test_invariants.py +0 -0
{python_agent_harness-1.5.7.2/python_agent_harness.egg-info → python_agent_harness-1.5.7.4}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-agent-harness
|
|
3
|
-
Version: 1.5.7.
|
|
3
|
+
Version: 1.5.7.4
|
|
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
|
|
@@ -136,7 +136,7 @@ Custom commands from `prompts/commands/*.md` and `paths.command_path` are always
|
|
|
136
136
|
|
|
137
137
|
### Custom agents
|
|
138
138
|
|
|
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
|
|
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`, except `default`, which cannot be shadowed. 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`).
|
|
@@ -164,6 +164,9 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
|
|
|
164
164
|
"context_windows": {
|
|
165
165
|
"deepseek-v4": 1000000
|
|
166
166
|
},
|
|
167
|
+
"supervision": {
|
|
168
|
+
"max_nudges": 1
|
|
169
|
+
},
|
|
167
170
|
"paths": {
|
|
168
171
|
"context_path": null,
|
|
169
172
|
"skill_path": null,
|
|
@@ -191,6 +194,7 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
|
|
|
191
194
|
- **`llm`** — main LLM config. Optional keys: `temperature`, `max_tokens`, `timeout`, `reasoning_effort`, `stream`, `supports_image_input`. `run --no-stream` overrides `stream`. `supports_image_input` (default `false`) controls whether `@path` images are sent or stripped.
|
|
192
195
|
- **`models`** — named LLM profiles for `/model` switching. Partial settings; unset keys inherit from `llm`. `default` restores the main config.
|
|
193
196
|
- **`context_windows`** — per-model context-window overrides (tokens). Keys are model names or substrings; first match wins. Overrides `CONTEXT_WINDOWS` in `config.py`.
|
|
197
|
+
- **`supervision.max_nudges`** — completion-supervision budget: how many times the harness nudges the model back to work when it stops with a terminal answer. The budget is **per tool round** (it resets on every tool round), so the effective cap is `max_nudges × tool rounds`. Default `1`, which suits a model that rarely stops early; raise it for a weaker model that keeps stopping before the work is done, or set `0` to disable supervision. Each nudge costs one extra LLM round (a full history re-send), so a high value is expensive.
|
|
194
198
|
- **`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.
|
|
195
199
|
- **`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.
|
|
196
200
|
- **`paths.context_path` / `paths.skill_path`** — locations for context files and skills. Default: project-local `contexts/` and `skills/`.
|
|
@@ -102,7 +102,7 @@ Custom commands from `prompts/commands/*.md` and `paths.command_path` are always
|
|
|
102
102
|
|
|
103
103
|
### Custom agents
|
|
104
104
|
|
|
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
|
|
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`, except `default`, which cannot be shadowed. 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`).
|
|
@@ -130,6 +130,9 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
|
|
|
130
130
|
"context_windows": {
|
|
131
131
|
"deepseek-v4": 1000000
|
|
132
132
|
},
|
|
133
|
+
"supervision": {
|
|
134
|
+
"max_nudges": 1
|
|
135
|
+
},
|
|
133
136
|
"paths": {
|
|
134
137
|
"context_path": null,
|
|
135
138
|
"skill_path": null,
|
|
@@ -157,6 +160,7 @@ All LLM settings live in `~/.config/python-agent-harness/config.json`. Environme
|
|
|
157
160
|
- **`llm`** — main LLM config. Optional keys: `temperature`, `max_tokens`, `timeout`, `reasoning_effort`, `stream`, `supports_image_input`. `run --no-stream` overrides `stream`. `supports_image_input` (default `false`) controls whether `@path` images are sent or stripped.
|
|
158
161
|
- **`models`** — named LLM profiles for `/model` switching. Partial settings; unset keys inherit from `llm`. `default` restores the main config.
|
|
159
162
|
- **`context_windows`** — per-model context-window overrides (tokens). Keys are model names or substrings; first match wins. Overrides `CONTEXT_WINDOWS` in `config.py`.
|
|
163
|
+
- **`supervision.max_nudges`** — completion-supervision budget: how many times the harness nudges the model back to work when it stops with a terminal answer. The budget is **per tool round** (it resets on every tool round), so the effective cap is `max_nudges × tool rounds`. Default `1`, which suits a model that rarely stops early; raise it for a weaker model that keeps stopping before the work is done, or set `0` to disable supervision. Each nudge costs one extra LLM round (a full history re-send), so a high value is expensive.
|
|
160
164
|
- **`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.
|
|
161
165
|
- **`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.
|
|
162
166
|
- **`paths.context_path` / `paths.skill_path`** — locations for context files and skills. Default: project-local `contexts/` and `skills/`.
|
|
@@ -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.
|
|
7
|
+
version = "1.5.7.4"
|
|
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.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/core/agent.py
RENAMED
|
@@ -64,6 +64,7 @@ class _SupervisorSession(Protocol):
|
|
|
64
64
|
|
|
65
65
|
alive: bool
|
|
66
66
|
compacting: bool
|
|
67
|
+
config_path: str | None
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
class AgentLoop:
|
|
@@ -112,28 +113,17 @@ class AgentLoop:
|
|
|
112
113
|
# round budget: an interactive TUI run still runs until the
|
|
113
114
|
# model finishes or the user aborts
|
|
114
115
|
self.max_rounds = max_rounds
|
|
115
|
-
# Optional wall-clock budget for unattended runs (None = off)
|
|
116
116
|
self.timeout = timeout
|
|
117
117
|
self.pending: list[ToolCall] = []
|
|
118
118
|
self.error: str | None = None
|
|
119
119
|
self.harness_injected: bool = False
|
|
120
120
|
self.supervisor = Supervisor(session)
|
|
121
|
-
# extracted machinery (no logic changes): tool execution and
|
|
122
|
-
# context/compaction live in tool_runner.py / context_manager.py;
|
|
123
|
-
# the loop delegates to them and keeps the FSM state
|
|
124
121
|
self._tool_runner = ToolRunner(self)
|
|
125
122
|
self._context_manager = ContextManager(self)
|
|
126
|
-
# FSM state: `state` is the current state, `info` the per-round
|
|
127
|
-
# context read by the transition-table predicates, `history`
|
|
128
|
-
# the states visited so far (newest last), `rounds` the number
|
|
129
|
-
# of WAIT visits (sub-agent budget), and `result` the final
|
|
130
|
-
# return value recorded by the terminal state's handler.
|
|
131
123
|
self.state = self.WAIT
|
|
132
124
|
self.info: dict[str, Any] = {}
|
|
133
125
|
self.history: list[str] = []
|
|
134
126
|
self.rounds = 0
|
|
135
|
-
# Thread-local wall-clock deadline bookkeeping: sub-agent loops
|
|
136
|
-
# run in their own threads, so a shared attribute would race
|
|
137
127
|
self._local = threading.local()
|
|
138
128
|
self.terminal_text: str | None = None
|
|
139
129
|
self.result: str | None = None
|
|
@@ -851,6 +841,7 @@ class Supervisor:
|
|
|
851
841
|
def __init__(self, session: _SupervisorSession) -> None:
|
|
852
842
|
self.session = session
|
|
853
843
|
self.nudge_count = 0
|
|
844
|
+
self.max_nudges = config.load_max_nudges(getattr(session, "config_path", None))
|
|
854
845
|
|
|
855
846
|
# -- helpers -----------------------------------------------------------
|
|
856
847
|
@property
|
|
@@ -863,7 +854,7 @@ class Supervisor:
|
|
|
863
854
|
A dead session can never record nudges, so without this guard
|
|
864
855
|
the machine could loop forever on terminal responses.
|
|
865
856
|
"""
|
|
866
|
-
return self.alive and self.nudge_count <
|
|
857
|
+
return self.alive and self.nudge_count < self.max_nudges
|
|
867
858
|
|
|
868
859
|
def inject_nudge(self) -> bool:
|
|
869
860
|
"""Increment the nudge counter. Returns True on success; never raises.
|
|
@@ -42,9 +42,6 @@ class ContextManager:
|
|
|
42
42
|
)
|
|
43
43
|
loop.session.calibrator.last_raw_estimate = raw
|
|
44
44
|
calibrated = loop.session.calibrator.calibrate(raw)
|
|
45
|
-
# Prefer the client's window (config overrides -> patterns ->
|
|
46
|
-
# default, resolved per access); fall back to the static
|
|
47
|
-
# resolver for clients without the property (test doubles).
|
|
48
45
|
client = loop.session.client
|
|
49
46
|
window = getattr(client, "context_window", None)
|
|
50
47
|
if window is None:
|
|
@@ -6,13 +6,6 @@ state (``messages`` / ``pending`` / ``info``) through the loop
|
|
|
6
6
|
reference. Tool calls are always executed and delivered via the
|
|
7
7
|
loop's ``_execute_tool_call`` / ``_deliver_tool_result`` methods so
|
|
8
8
|
subclass or test overrides of those methods keep working.
|
|
9
|
-
|
|
10
|
-
When every call in a round is readonly (``Tool.is_readonly = True``),
|
|
11
|
-
the round is dispatched concurrently via a thread pool: readonly tools
|
|
12
|
-
only read state, so none can depend on another's side effects, and
|
|
13
|
-
running them in parallel reduces latency for read-heavy rounds (e.g.
|
|
14
|
-
the model reading several files at once). Mixed rounds (any
|
|
15
|
-
non-readonly tool) fall back to the original sequential dispatch.
|
|
16
9
|
"""
|
|
17
10
|
|
|
18
11
|
from __future__ import annotations
|
|
@@ -53,15 +46,7 @@ def sanitize_tool_result(result: object) -> str:
|
|
|
53
46
|
|
|
54
47
|
|
|
55
48
|
class ToolRunner:
|
|
56
|
-
"""Runs and delivers tool calls for one agent loop.
|
|
57
|
-
|
|
58
|
-
Mirrors gptel's `gptel--handle-tool-use': synchronous tools
|
|
59
|
-
(Read, Edit, Glob, ...) execute ONE AT A TIME, in call order;
|
|
60
|
-
asynchronous tools (Bash, Agent — those whose ``run`` returns a
|
|
61
|
-
``PendingToolResult``) are dispatched in line and run concurrently
|
|
62
|
-
in the background, their results awaited afterwards, again in
|
|
63
|
-
original call order.
|
|
64
|
-
"""
|
|
49
|
+
"""Runs and delivers tool calls for one agent loop."""
|
|
65
50
|
|
|
66
51
|
def __init__(self, loop: Any) -> None:
|
|
67
52
|
self.loop = loop
|
|
@@ -263,10 +248,6 @@ class ToolRunner:
|
|
|
263
248
|
appended by the WAIT state. Results land in
|
|
264
249
|
``self.info["tool_result"]`` and are delivered by the TRET
|
|
265
250
|
state in original tool-call order.
|
|
266
|
-
|
|
267
|
-
Synchronous tools run ONE AT A TIME in model-emitted order
|
|
268
|
-
(gptel-style); asynchronous tools (Bash, Agent) are dispatched
|
|
269
|
-
in line and run concurrently in the background.
|
|
270
251
|
"""
|
|
271
252
|
loop = self.loop
|
|
272
253
|
pending = list(loop.pending)
|
{python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/cli.py
RENAMED
|
@@ -53,7 +53,16 @@ def make_session(
|
|
|
53
53
|
# (so a CLI/caller model override is inherited too when the
|
|
54
54
|
# subagent_llm model is unset)
|
|
55
55
|
settings["model"] = model
|
|
56
|
-
|
|
56
|
+
# One config read for both views: the fully resolved settings (to
|
|
57
|
+
# decide whether the sub-agent needs its own client) and the
|
|
58
|
+
# explicit overrides only (per-request options must stay "unset =
|
|
59
|
+
# inherit the main value at use time" — a value resolved here would
|
|
60
|
+
# pin the model active at session start, so a later /model switch
|
|
61
|
+
# would keep sending the previous model's reasoning_effort, which
|
|
62
|
+
# the new backend rejects).
|
|
63
|
+
subagent_overrides = config.load_subagent_overrides(config_path)
|
|
64
|
+
subagent_settings = dict(settings)
|
|
65
|
+
subagent_settings.update(subagent_overrides)
|
|
57
66
|
client = Client(
|
|
58
67
|
base_url=settings["base_url"],
|
|
59
68
|
api_key=settings["api_key"],
|
|
@@ -128,11 +137,13 @@ def make_session(
|
|
|
128
137
|
stream=effective_stream,
|
|
129
138
|
supports_image_input=settings["supports_image_input"],
|
|
130
139
|
subagent_client=subagent_client,
|
|
131
|
-
subagent_temperature=
|
|
132
|
-
subagent_max_tokens=
|
|
133
|
-
subagent_reasoning_effort=
|
|
134
|
-
subagent_stream=(
|
|
135
|
-
|
|
140
|
+
subagent_temperature=subagent_overrides.get("temperature"),
|
|
141
|
+
subagent_max_tokens=subagent_overrides.get("max_tokens"),
|
|
142
|
+
subagent_reasoning_effort=subagent_overrides.get("reasoning_effort"),
|
|
143
|
+
subagent_stream=(
|
|
144
|
+
effective_stream if stream is not None else subagent_overrides.get("stream")
|
|
145
|
+
),
|
|
146
|
+
subagent_supports_image_input=subagent_overrides.get("supports_image_input"),
|
|
136
147
|
registry=registry,
|
|
137
148
|
context_path=paths.get("context_path"),
|
|
138
149
|
skill_path=paths.get("skill_path"),
|
|
@@ -231,8 +242,6 @@ def cmd_headless(args: argparse.Namespace) -> int:
|
|
|
231
242
|
if prompt is None:
|
|
232
243
|
prompt = sys.stdin.read()
|
|
233
244
|
runner = run_headless_jsonl if getattr(args, "json", False) else run_headless
|
|
234
|
-
# Unattended budgets: explicit flags win over the config file's
|
|
235
|
-
# headless section (0/negative disables the budget entirely).
|
|
236
245
|
max_rounds, timeout = _resolve_budgets(args, config.load_headless_limits(args.config))
|
|
237
246
|
return runner(
|
|
238
247
|
session,
|
|
@@ -257,9 +266,6 @@ def cmd_serve(args: argparse.Namespace) -> int:
|
|
|
257
266
|
try:
|
|
258
267
|
from .server import run_serve
|
|
259
268
|
|
|
260
|
-
# Per-run budgets: explicit flags win over the config file's
|
|
261
|
-
# serve section (0/negative disables). Applied to EACH submit
|
|
262
|
-
# — the process is resident, so every run gets a fresh budget.
|
|
263
269
|
max_rounds, timeout = _resolve_budgets(args, config.load_serve_limits(args.config))
|
|
264
270
|
return run_serve(
|
|
265
271
|
session,
|
|
@@ -347,7 +353,6 @@ def cmd_config(args: argparse.Namespace) -> int:
|
|
|
347
353
|
f"reasoning_effort={subagent_settings['reasoning_effort']} "
|
|
348
354
|
f"stream={subagent_settings['stream']} timeout={subagent_settings['timeout']}"
|
|
349
355
|
)
|
|
350
|
-
# Show model profiles for /model command
|
|
351
356
|
model_profiles = config.load_models_config(args.path)
|
|
352
357
|
if model_profiles:
|
|
353
358
|
print("models:")
|
|
@@ -357,7 +362,6 @@ def cmd_config(args: argparse.Namespace) -> int:
|
|
|
357
362
|
print(f" {name}: model={model_name}, base_url={base_url}")
|
|
358
363
|
else:
|
|
359
364
|
print("models: (none configured — add a 'models' section to use /model)")
|
|
360
|
-
# Show context-window overrides
|
|
361
365
|
context_windows = config.load_context_windows_config(args.path)
|
|
362
366
|
if context_windows:
|
|
363
367
|
print("context_windows:")
|
|
@@ -365,9 +369,9 @@ def cmd_config(args: argparse.Namespace) -> int:
|
|
|
365
369
|
print(f" {pattern}: {size}")
|
|
366
370
|
else:
|
|
367
371
|
print("context_windows: (none configured — built-in table in config.py applies)")
|
|
368
|
-
# Show default agent
|
|
369
372
|
default_agent = config.load_default_agent(args.path)
|
|
370
373
|
print(f"default_agent: {default_agent or '(default: agent.md)'}")
|
|
374
|
+
print(f"supervision.max_nudges: {config.load_max_nudges(args.path)}")
|
|
371
375
|
max_rounds, timeout = config.load_headless_limits(args.path)
|
|
372
376
|
if max_rounds is None and timeout is None:
|
|
373
377
|
print(
|
|
@@ -311,7 +311,7 @@ class Controller:
|
|
|
311
311
|
# from a previous run so a finished task's todos don't stay
|
|
312
312
|
# pinned into the next task.
|
|
313
313
|
self.clear_todos()
|
|
314
|
-
#
|
|
314
|
+
# Invalidate any worker still
|
|
315
315
|
# unwinding from a previous run — from this point on it is stale
|
|
316
316
|
# and must never touch shared state. Bump before clearing the
|
|
317
317
|
# event so there is no instant where an old worker sees "not
|
|
@@ -361,7 +361,6 @@ class Controller:
|
|
|
361
361
|
return text, cleaned_text.strip() or "(attachment)", [], warnings
|
|
362
362
|
cleaned_text, attachments, errors = parse_at_references(text, str(self.project_dir))
|
|
363
363
|
if errors and not attachments and not cleaned_text.strip():
|
|
364
|
-
# All references failed and nothing else to send
|
|
365
364
|
return None, "", errors, []
|
|
366
365
|
# Build the user message: multimodal if there are attachments,
|
|
367
366
|
# plain text otherwise (preserving the existing text-only path).
|
|
@@ -372,7 +371,6 @@ class Controller:
|
|
|
372
371
|
for att in attachments:
|
|
373
372
|
parts.append(att.part)
|
|
374
373
|
user_msg = Message(role="user", content=parts)
|
|
375
|
-
# The display text is the user-facing text (without image data)
|
|
376
374
|
display_text = (
|
|
377
375
|
cleaned_text.strip()
|
|
378
376
|
or f"({len(attachments)} image attachment{'s' if len(attachments) != 1 else ''})"
|
{python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/headless.py
RENAMED
|
@@ -361,9 +361,6 @@ def run_headless(
|
|
|
361
361
|
return 1
|
|
362
362
|
answer = final_answer_text(session)
|
|
363
363
|
if answer:
|
|
364
|
-
# api_safe: the answer carries whatever the conversation carried
|
|
365
|
-
# (a restored non-UTF-8 session), and a strict-UTF-8 stdout
|
|
366
|
-
# raised UnicodeEncodeError here — losing the result line.
|
|
367
364
|
view.out.write(api_safe(answer) + "\n")
|
|
368
365
|
view.out.flush()
|
|
369
366
|
return 1 if view.errors else 0
|
{python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/entry/server.py
RENAMED
|
@@ -141,12 +141,9 @@ from .headless import (
|
|
|
141
141
|
|
|
142
142
|
DEFAULT_ANSWER_TIMEOUT = 0.0 # wait forever for a host answer
|
|
143
143
|
|
|
144
|
-
# Named features advertised on the ``ready`` line.
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
# instead of inferring a feature's absence from events that never
|
|
148
|
-
# arrive. Add a capability when behaviour a host can branch on is
|
|
149
|
-
# introduced; never repurpose an existing name.
|
|
144
|
+
# Named features advertised on the ``ready`` line. Add a capability
|
|
145
|
+
# when behaviour a host can branch on is introduced; never repurpose
|
|
146
|
+
# an existing name.
|
|
150
147
|
CAPABILITIES = (
|
|
151
148
|
"submit", # run a prompt
|
|
152
149
|
"answer", # deliver a mid-run answer to an ask
|
|
@@ -497,9 +494,8 @@ class AgentServer:
|
|
|
497
494
|
self.err = err if err is not None else sys.stderr
|
|
498
495
|
self.answer_timeout = answer_timeout
|
|
499
496
|
# Per-run budgets (None = unlimited), applied to EVERY submit.
|
|
500
|
-
#
|
|
501
|
-
#
|
|
502
|
-
# so a driving host cannot raise its own ceiling.
|
|
497
|
+
# Held here — not taken off the wire — so a driving host cannot
|
|
498
|
+
# raise its own ceiling.
|
|
503
499
|
self.max_rounds = max_rounds
|
|
504
500
|
self.timeout = timeout
|
|
505
501
|
self.view: ServerView | None = None
|
|
@@ -623,18 +619,13 @@ class AgentServer:
|
|
|
623
619
|
# Per-run budget: Controller.submit derives budget_top_level
|
|
624
620
|
# from max_rounds being set, so passing it is what opts this
|
|
625
621
|
# run into a finite round cap (default None = unlimited, the
|
|
626
|
-
# interactive behavior).
|
|
627
|
-
# loop normally, so the run still ends with a result line
|
|
628
|
-
# carrying errors[].code = "budget"/"timeout" and real usage.
|
|
622
|
+
# interactive behavior).
|
|
629
623
|
handle = self.controller.submit(
|
|
630
624
|
prompt,
|
|
631
625
|
max_rounds=self.max_rounds,
|
|
632
626
|
timeout=self.timeout,
|
|
633
627
|
)
|
|
634
628
|
if self._cancel_pending.is_set():
|
|
635
|
-
# A cancel op landed before submit() — submit cleared the
|
|
636
|
-
# session cancel event at run start, so re-apply it now
|
|
637
|
-
# (the run must unwind; TUI parity for a Ctrl-C at turn start).
|
|
638
629
|
self._cancel_pending.clear()
|
|
639
630
|
self.session.cancel()
|
|
640
631
|
model = self.session.model
|
{python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/attachments.py
RENAMED
|
@@ -219,11 +219,6 @@ def parse_at_references(
|
|
|
219
219
|
|
|
220
220
|
for match in pattern.finditer(text):
|
|
221
221
|
raw_path = match.group(1)
|
|
222
|
-
# Strip trailing sentence/closing punctuation from the path
|
|
223
|
-
# token: "@file.png." / "@file.png," / "(@file.png)" must
|
|
224
|
-
# resolve "file.png", not "file.png." / "file.png," / "file.png)".
|
|
225
|
-
# The stripped characters are left in the text (the replacement
|
|
226
|
-
# below only swaps the @ + path token).
|
|
227
222
|
stripped = raw_path.rstrip(".,;:!?)]}>\"'")
|
|
228
223
|
if not stripped:
|
|
229
224
|
continue
|
|
@@ -235,13 +230,6 @@ def parse_at_references(
|
|
|
235
230
|
# can see what failed
|
|
236
231
|
continue
|
|
237
232
|
attachments.append(result)
|
|
238
|
-
# Replace the @path token. For image attachments, the image
|
|
239
|
-
# bytes are already in an ImagePart — leaving the file path in
|
|
240
|
-
# the text causes some models to try reading the file with
|
|
241
|
-
# tools, so replace it with a generic [image] placeholder.
|
|
242
|
-
# For text attachments, keep the path (it provides context for
|
|
243
|
-
# the inlined content). The trailing punctuation stripped
|
|
244
|
-
# above stays in the text.
|
|
245
233
|
full_match = match.group(0)
|
|
246
234
|
if isinstance(result.part, ImagePart):
|
|
247
235
|
replacements.append((full_match, full_match.replace("@" + stripped, "[image]", 1)))
|
|
@@ -259,8 +247,7 @@ def _has_image_signature(data: bytes, media_type: str) -> bool:
|
|
|
259
247
|
"""True when DATA's magic bytes match MEDIA_TYPE's signature.
|
|
260
248
|
|
|
261
249
|
Any of the type's signatures matching at its offset is enough
|
|
262
|
-
(e.g. GIF87a or GIF89a for image/gif).
|
|
263
|
-
signature offset+length can never match.
|
|
250
|
+
(e.g. GIF87a or GIF89a for image/gif).
|
|
264
251
|
"""
|
|
265
252
|
signatures = _IMAGE_SIGNATURES.get(media_type)
|
|
266
253
|
if not signatures:
|
|
@@ -290,7 +277,6 @@ def _validate_and_create(resolved: str, display_path: str) -> ParsedAttachment |
|
|
|
290
277
|
ext = Path(resolved).suffix.lower()
|
|
291
278
|
basename = os.path.basename(resolved)
|
|
292
279
|
|
|
293
|
-
# Image files
|
|
294
280
|
if ext in IMAGE_EXTENSIONS:
|
|
295
281
|
size = os.path.getsize(resolved)
|
|
296
282
|
if size > MAX_IMAGE_SIZE:
|
|
@@ -312,7 +298,6 @@ def _validate_and_create(resolved: str, display_path: str) -> ParsedAttachment |
|
|
|
312
298
|
resolved, ImagePart(data=data, media_type=media_type, path=resolved)
|
|
313
299
|
)
|
|
314
300
|
|
|
315
|
-
# Text files
|
|
316
301
|
if ext in TEXT_EXTENSIONS or basename in TEXT_BASENAMES or not ext:
|
|
317
302
|
size = os.path.getsize(resolved)
|
|
318
303
|
if size > MAX_TEXT_SIZE:
|
|
@@ -328,7 +313,6 @@ def _validate_and_create(resolved: str, display_path: str) -> ParsedAttachment |
|
|
|
328
313
|
return AttachmentError(display_path, f"cannot read file: {e}")
|
|
329
314
|
return ParsedAttachment(resolved, TextPart(text=content))
|
|
330
315
|
|
|
331
|
-
# Unknown extension: try to read as text
|
|
332
316
|
size = os.path.getsize(resolved)
|
|
333
317
|
if size > MAX_TEXT_SIZE:
|
|
334
318
|
return AttachmentError(
|
{python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/diffrender.py
RENAMED
|
@@ -66,10 +66,6 @@ def unified_diff(
|
|
|
66
66
|
for line in diff:
|
|
67
67
|
out.append(line)
|
|
68
68
|
if line[:1] in ("-", "+", " ") and not line.endswith("\n"):
|
|
69
|
-
# a content line at EOF without a trailing newline: difflib
|
|
70
|
-
# emits it bare, which would corrupt the joined text; mark
|
|
71
|
-
# it like git does so the diff round-trips (the Edit tool's
|
|
72
|
-
# diff mode parses markers and applies them)
|
|
73
69
|
out.append("\n\\n")
|
|
74
70
|
return "".join(out)
|
|
75
71
|
|
{python_agent_harness-1.5.7.2 → python_agent_harness-1.5.7.4}/python_agent_harness/io/persistence.py
RENAMED
|
@@ -356,13 +356,9 @@ def parse_saved_body(body: str) -> list:
|
|
|
356
356
|
messages.append(Message(role=role, content=content))
|
|
357
357
|
|
|
358
358
|
for line in body.splitlines():
|
|
359
|
-
# Check for a role header: **user**: ... or **assistant**: ...
|
|
360
359
|
header = split_role_header(line)
|
|
361
360
|
if header is not None:
|
|
362
361
|
role, rest = header
|
|
363
|
-
# Save the previous block (tool blocks lose their
|
|
364
|
-
# tool_call_id/name; system blocks would duplicate the
|
|
365
|
-
# live system prompt the client prepends per request)
|
|
366
362
|
if current_role is not None and current_role not in ("tool", "system"):
|
|
367
363
|
_flush(current_role, current_lines)
|
|
368
364
|
current_role = role
|
|
@@ -370,7 +366,7 @@ def parse_saved_body(body: str) -> list:
|
|
|
370
366
|
continue
|
|
371
367
|
current_lines.append(unescape_role_header(line))
|
|
372
368
|
|
|
373
|
-
#
|
|
369
|
+
# flush the last block
|
|
374
370
|
if current_role is not None and current_role not in ("tool", "system"):
|
|
375
371
|
_flush(current_role, current_lines)
|
|
376
372
|
|
|
@@ -384,20 +380,18 @@ def find_session_by_title(query: str) -> str | None:
|
|
|
384
380
|
and the derived title. Returns the most recent match, or None.
|
|
385
381
|
"""
|
|
386
382
|
query_lower = query.lower()
|
|
387
|
-
# Strip .md from query if present, for cleaner substring matching
|
|
388
383
|
query_stem = query_lower[:-3] if query_lower.endswith(".md") else query_lower
|
|
389
|
-
files = SessionPersistence.list_sessions()
|
|
384
|
+
files = SessionPersistence.list_sessions()
|
|
390
385
|
for f in files:
|
|
391
386
|
basename = os.path.basename(f)
|
|
392
387
|
basename_lower = basename.lower()
|
|
393
|
-
# Exact basename match (with or without .md)
|
|
394
388
|
if basename_lower == query_lower or basename_lower == query_lower + ".md":
|
|
395
389
|
return f
|
|
396
|
-
#
|
|
390
|
+
# substring match against the filename
|
|
397
391
|
name_part = basename[:-3] if basename.endswith(".md") else basename
|
|
398
392
|
if query_stem in name_part.lower():
|
|
399
393
|
return f
|
|
400
|
-
#
|
|
394
|
+
# match against the derived title
|
|
401
395
|
title = title_from_filename(f)
|
|
402
396
|
if title and query_stem in title.lower():
|
|
403
397
|
return f
|