pi-agent-cli-lc 0.7.0__tar.gz → 0.9.0__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.
- pi_agent_cli_lc-0.9.0/AGENTS.md +208 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/PKG-INFO +9 -5
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/README.md +1 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/agent.example.toml +38 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/agent.py +273 -42
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/auth_methods.py +16 -2
- pi_agent_cli_lc-0.9.0/pi_agent_cli/auto_classifier.py +666 -0
- pi_agent_cli_lc-0.9.0/pi_agent_cli/auto_mode.py +788 -0
- pi_agent_cli_lc-0.9.0/pi_agent_cli/auto_reasons.py +104 -0
- pi_agent_cli_lc-0.9.0/pi_agent_cli/auto_rules.py +2258 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/evaluator.py +1 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/config.py +207 -3
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/factory.py +11 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/headless.py +1 -1
- pi_agent_cli_lc-0.9.0/pi_agent_cli/permission_modes.py +128 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/permissions.py +48 -27
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/prompt_options.py +9 -4
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/setup_command.py +62 -14
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pyproject.toml +12 -4
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/_print_agent.py +2 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/_tool_agent.py +12 -7
- pi_agent_cli_lc-0.9.0/tests/data/auto_corpus/README.md +140 -0
- pi_agent_cli_lc-0.9.0/tests/data/auto_corpus/cassette.json +981 -0
- pi_agent_cli_lc-0.9.0/tests/data/auto_corpus/dev.jsonl +630 -0
- pi_agent_cli_lc-0.9.0/tests/data/auto_corpus/heldout.jsonl +106 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_acp_agent.py +11 -10
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_acp_auth_methods.py +18 -0
- pi_agent_cli_lc-0.9.0/tests/test_acp_stdio_tools.py +703 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_classifier.py +1261 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_comment_floor.py +595 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_corpus.py +402 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_corpus_model.py +534 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_eval_real.py +561 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_floor_wrappers.py +125 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_mode_checks.py +294 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_model_redteam.py +634 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_model_step.py +1153 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_reasons.py +75 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_rules.py +2257 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_unknown_model.py +474 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_wiring.py +1282 -0
- pi_agent_cli_lc-0.9.0/tests/test_auto_wiring_redteam.py +696 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_background_turns.py +2 -2
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_client_mcp.py +1 -1
- pi_agent_cli_lc-0.9.0/tests/test_config.py +605 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_extension_notices.py +2 -2
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_extension_trust.py +5 -3
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_git_context.py +10 -3
- pi_agent_cli_lc-0.9.0/tests/test_git_snapshot_trust.py +296 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_headless.py +57 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_mcp_notice.py +1 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_pelican_real_llm.py +1 -1
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_permission_annotations.py +52 -10
- pi_agent_cli_lc-0.9.0/tests/test_permission_mode_wire.py +434 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_project_resource_trust.py +2 -2
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_project_trust_prompt.py +6 -2
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_setup_command.py +108 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_trust_store.py +7 -1
- pi_agent_cli_lc-0.7.0/AGENTS.md +0 -149
- pi_agent_cli_lc-0.7.0/tests/test_acp_stdio_tools.py +0 -304
- pi_agent_cli_lc-0.7.0/tests/test_config.py +0 -263
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/.gitignore +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/config.toml.example +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/local.env.example +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/__init__.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/__main__.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/__init__.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/collector.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/docker_runner.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/egress_policy.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/golden_seed.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/models.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/pelican.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/benchmarks/task_loader.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/client_mcp.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/context_files.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/create_harness.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/events.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/extension_notices.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/extension_trust.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/git_context.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/mcp_notice.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/session_list.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/system_prompt.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/trust_fingerprint.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/trust_prompt.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/pi_agent_cli/trust_store.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/snapshots/default_coding_tools_prompt.txt +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_acp_shutdown.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_acp_stdio_contract.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_agent_info.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_benchmark_loader.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_blank_session_reopen.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_console_scripts.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_context_files.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_docker_runner_verifier_head.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_docker_runner_verifier_isolation.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_evaluator_cache.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_extension_wiring.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_factory_skills.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_first_run_errors.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_golden_checkpoint.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_headless_trust.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_model_reasoning.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_pelican_benchmark.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_print_shutdown.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_project_trust_decision.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_project_workflow_trust.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_session_chosen_id.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_session_lifecycle.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_session_list.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_session_list_paging.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_system_prompt.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_trust_fingerprint.py +0 -0
- {pi_agent_cli_lc-0.7.0 → pi_agent_cli_lc-0.9.0}/tests/test_trust_prompt.py +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# pi-agent-cli
|
|
2
|
+
|
|
3
|
+
Standard-ACP agent over `AgentHarness`. Two modes:
|
|
4
|
+
|
|
5
|
+
| Mode | Entry | Purpose |
|
|
6
|
+
|------|-------|---------|
|
|
7
|
+
| ACP stdio | `python -m pi_agent_cli` | TUI-spawned agent; `/new` `/resume` `/quit` map to ACP methods |
|
|
8
|
+
| Headless | `python -m pi_agent_cli -p "prompt"` | One-shot turn, prints assistant text, exits; exit status 1 and `error: <reason>` on stderr when the model fails |
|
|
9
|
+
| Setup | `python -m pi_agent_cli --setup` | Asks for a model and an API key in a terminal and writes `agent.toml` and `local.env` (see First run) |
|
|
10
|
+
|
|
11
|
+
Headless flags: `--system-prompt`, `--append-system-prompt`, `--no-context-files`, `--no-git-context` — see `--help`. `--trust-project-extensions` works in both modes (see Project extensions).
|
|
12
|
+
|
|
13
|
+
## Config
|
|
14
|
+
|
|
15
|
+
Home: `~/.pi-python/` (override with `PI_HOME`). One resolver, `pi_agent_core.home.pi_home` (re-exported as `config.pi_home`), serves the CLI, the extension loader (`<home>/extensions`, exposed to extensions as `pi.home`) and the workflow extension (saved workflows, journals); `create_session_harness` hands the session's home to the harness so they cannot disagree. Two config files with distinct owners:
|
|
16
|
+
|
|
17
|
+
| File | Owner | Scope |
|
|
18
|
+
|------|-------|-------|
|
|
19
|
+
| `agent.toml` | Python agent | model, permission, skills, prompt overrides |
|
|
20
|
+
| `config.toml` | Rust TUI only | TUI settings (`[ui]`, theme, sandbox); a key the TUI knows, written with another type, stops it |
|
|
21
|
+
|
|
22
|
+
Keep the two files apart. The TUI is strict about the keys it knows and tolerant of the keys it does not know (measured with `zypi`; execution log section 10.10, item 3). A `config.toml` that is missing, has an unknown table or key, or has a Python `[model]` table starts normally. These stop `zypi` with exit code 1: a top-level `permission = "ask"` (the TUI expects a table there), a `[[models]]` array, and invalid TOML. A wrong type for `[agent].command` is ignored without a message. The agent reads `agent.toml`; only when that file does not exist does it fall back to `config.toml` (`load_config`, kept for old setups). The TUI reads `[agent].command` from `agent.toml` and, if that file does not set it, from `config.toml` (`acp/spawn.rs`); it reads no other agent key.
|
|
23
|
+
|
|
24
|
+
`local.env` in home loads `KEY=VALUE` pairs into env without overwriting (secrets stay out of TOML). See `agent.example.toml` for all keys.
|
|
25
|
+
|
|
26
|
+
## First run: `--setup` and the terminal login
|
|
27
|
+
|
|
28
|
+
A home with no `agent.toml` has no model and no key. The configuration then falls back to the provider `mock`, which LangChain does not have. Design: `docs/specs/2026-10-28-acp-terminal-auth-setup-design.md`.
|
|
29
|
+
|
|
30
|
+
- **What the user sees.** A turn with no model fails with `No model is set. Run the agent with --setup, or add a [model] table to <agent.toml>.` (`factory._say_when_no_model` wraps the LangChain stream function; the scripted LLM `PI_USE_MOCK=1` is not touched). `-p` writes `error: <reason>` to stderr and exits 1 when the model fails; stdout keeps only an answer.
|
|
31
|
+
- **`--setup`** (`setup_command.py`) asks in a terminal and writes the files. It needs a terminal on stdin and stdout (exit 2 if not) and saves nothing when the input ends. `agent.toml` gets a `[model]` table: a new file, or the table at the end of a file that has none, with the text that is there kept to the byte. It refuses, before the first question, a file that is not TOML, a `[model]` table that sets no provider, and a home that has only the old `config.toml` (a new `agent.toml` would hide that file from the agent). The key goes to `local.env` as `NAME=key`: mode 0600 on POSIX, read without echo, never printed, logged or written to `agent.toml`. Both files are replaced by a rename of a file written beside them, and a symbolic link is followed. A model that has no key gets only the key question; a model that has one is asked before the key is replaced. A new model whose key variable already has a value (in the real environment, which wins, or in `local.env`) gets no key question and no `local.env` write: the agent reads the variable where it is (a value in the environment makes the final text say that a client has to pass the variable on). A running agent keeps the old key (`load_local_env` never overwrites), so a replaced key needs a new agent process.
|
|
32
|
+
- **The terminal login** (`auth_methods.py`). `initialize` offers `--setup` as an authentication method, but only to a client that says it can run one. `auth.terminal = true` (Zed) gets a method of type `terminal` (`args = ["--setup"]`; Zed adds them to the agent command). `_meta["terminal-auth"] = true` alone (older clients, the registry validator) gets a method of the default type that has the whole command in `_meta["terminal-auth"]` and `PI_HOME` in its `env`. Any other client, `zypi` included, gets `authMethods: []`, and the pager relies on that (`standard_acp` in `event_loop.rs`). The SDK drops an invalid item of `authMethods` without a word (a plain `AuthMethodTerminal` has no `type`), so build it with `TerminalAuthMethod(type="terminal", …)` and read the raw JSON in a test.
|
|
33
|
+
- **When a session is sent to it** (`agent.py`). `config_problem()` says why a configuration cannot run a turn (no model; or `api_key_env` and the provider's own variable both empty). `session/new` then answers `auth_required` (-32000) to a client that can run the login, and makes no session. Other clients get the session. `session/load` and `session/resume` never refuse. While there is a problem, the agent reads `agent.toml` and `local.env` again at `new`, `load` and `resume`, because `--setup` runs in the client's terminal while the agent is up. `authenticate("pi-setup")` answers `{}` when there is no problem and `auth_required` when there is; any other id is `invalid_params`. An agent that was given its own `config` or `stream_fn` offers nothing.
|
|
34
|
+
|
|
35
|
+
## Model selection (`/model`)
|
|
36
|
+
|
|
37
|
+
Standard ACP **Session Config Options** — `session/set_model` is gone upstream (SDK ≥ 0.11). `new_session` / `load_session` / `resume_session` return `configOptions` with one select (`id="model"`, `category="model"`, `currentValue`, `options`); the client switches with `session/set_config_option` (`PiAcpAgent.set_config_option` → `harness.set_model`, response carries the full option set). Choices = `[model]` + optional `[[models]]` tables in `agent.toml` (`ModelChoice`, `CliConfig.model_choices()`). The model is persisted in the session (`model_change`) and restored on load/resume if still configured. Legacy `_meta` hints (`pi/currentModelId`, `pi/currentModelDisplayName`, `pi/provider`) are still emitted for older clients. Each choice carries its own `api_key_env`: `get_api_key` answers only for that choice's provider (`factory.api_key_for_choice`), and `Model.reasoning` follows `CliConfig.model_reasoning` whichever choice is active.
|
|
38
|
+
|
|
39
|
+
## Project trust
|
|
40
|
+
|
|
41
|
+
A project's own content is used only if the project is trusted: `<cwd>/.pi-python/extensions` (imported — i.e. executed — when a session opens), `<cwd>/.pi-python/workflows` (each `*.py` becomes a slash command with a description the repository wrote, and a command that has the model run the script), `<cwd>/.pi/SYSTEM.md`, `<cwd>/.pi/APPEND_SYSTEM.md`, and `[skills].paths` entries relative to the project (`.pi/skills`) — `trust_fingerprint.gated_project_resources` lists them. One more thing is gated that is not a file of the project: the `<git_status>` block (`prompt_options._git_status_block`). `git status` runs the program that `core.fsmonitor` in the repository's own `.git/config` names, so a project that ships its `.git` could run code at session start. The block is taken only when the session's `ProjectTrust` says yes. The trust reason `nothing` (the project ships nothing gated) counts as untrusted, so **by default there is no block**; the user gets one with `--trust-project-extensions`, `default_project_trust = "always"`, `[extensions] trusted_projects` or a saved answer. It is not in `gated_project_resources` (nothing to fingerprint or to ask about), so no question is asked for it and the "left out" notice does not name it. The model can still run `git status` through `bash` (a tool call, so permissions apply). One tool call is gated on trust as well: `workflow` with `isolation=true` (`pi-dynamic-workflows`, `worktree.py`) runs `git worktree add`, `git add`, `git diff` and `git apply` in the project, which run the `post-checkout` hook, the filters, `core.fsmonitor` and `diff.external` that the repository names. In a project that is not trusted the call is refused (no run, no silent fallback to no isolation); the extension reads `pi.project_trusted`. Never read the decision from a file inside the project, or a repository could trust itself. Not gated: entry-point packages, `~/.pi-python/extensions`, `<pi home>/workflows` (the user's own), `AGENTS.md` / `CLAUDE.md` (upstream loads them whatever the trust), prompts set in `agent.toml`, and absolute or `~` skills paths. The workflows are read by the dynamic-workflows extension, not by the CLI: it asks `pi.project_trusted` (the harness's `trust_project_extensions`, final by the time extensions activate), so an extension that reads anything under `<cwd>/.pi-python/` must do the same. Design: `docs/specs/2026-09-22-phase7-extension-api-design.md` §4.4.
|
|
42
|
+
|
|
43
|
+
`extension_trust.decide_project_trust(config, cwd, home=)` returns a `ProjectTrustDecision` (hashes files: call it off the event loop). Order: `PI_TRUST_PROJECT_EXTENSIONS` / `--trust-project-extensions` → `default_project_trust = "always"` (or the older `trust_project_extensions`; an explicit `default_project_trust` wins) → `[extensions] trusted_projects` in the **home** `agent.toml` (absolute paths; subdirectories count) → nothing gated (`nothing`) → files cannot be fingerprinted (`unpinnable`: no question, use `trusted_projects`) → an answer saved in `<home>/agent/trust.json` whose fingerprint still matches (`saved`) → `default_project_trust = "never"` → otherwise `undecided` / `changed` (a saved answer for other files), which an ACP client is asked about. `project_extensions_trusted` is the file-free subset (configuration and command line only).
|
|
44
|
+
|
|
45
|
+
- **Who asks.** Only the ACP agent (`agent.py`), and only when the decision `can_ask` and a client is connected. Headless never asks (upstream pi does not prompt in non-interactive modes either) but honours `saved`. The question (`trust_prompt.py`) is preceded by an ordinary agent message naming the directory, the files and what each does (the TUI shows a permission request's title and options only), then a `session/request_permission` with `Don't trust` (`reject_once`, first) and `Trust and remember` (`allow_always`). **No `allow_once` option, deliberately**: clients may answer tool permissions for the user (the TUI's YOLO mode takes the first `allow_once`), and this is not that decision. Only the exact trust option id, selected, is a yes (never reuse `permissions.outcome_allows`, which treats every selected id with text that does not start with `reject` as yes); asking happens whatever the `permission` mode says.
|
|
46
|
+
- **When.** After the `session/new` (`load`, `resume`) response has gone out — clients drop requests for sessions they have not registered (`_deferred_session_setup`) — and extensions load only after the answer; `prompt()` waits for it (`session/cancel` or closing the session ends the wait; `_SessionTrust`). One question per project at a time (`_project_locks`); the later session decides afresh and normally finds the saved answer. The answer is checked against the disk again after the dialog (`modified` if the files moved), then `TrustStore.remember` (atomic, fail-closed; an unwritable store leaves the session trusted and says so). Refusals are not remembered. `ProjectTrust` is the session's live answer that `create_session_harness`, `load_system_prompt_options` and `load_session_resources` read, so a yes takes effect without rebuilding the session (`AgentHarness.set_trust_project_extensions`, valid until extensions load).
|
|
47
|
+
- **What was left out** is logged and reported to the user with the reason (`untrusted_project_notice(why=)`: not decided, changed since trusted, changed while asked, declined, could not ask, `never`, unpinnable) — ACP agent message after `session/new`, headless stderr.
|
|
48
|
+
- **Fingerprint** (`trust_fingerprint.fingerprint_resources`): SHA-256 over file contents of everything gated (recursive; `__pycache__` and `.git` skipped; symlinks followed with a loop guard; regular files only; at most 2000 entries and 64 MiB, else `None`) — contents, not mtimes. Stored per exact directory (`TrustStore`: `project_key` = `normcase(realpath)`), not per subtree.
|
|
49
|
+
|
|
50
|
+
## Tool permissions
|
|
51
|
+
|
|
52
|
+
`permission` in `agent.toml` is `ask` (default), `auto` or `always-approve`. `always-approve` never asks. `ask` and `auto` ask, and headless (`-p`) forces `always-approve`, so it asks nobody. In `ask` mode a tool call goes to the client as `session/request_permission` **unless the tool declares itself harmless** (`permissions.needs_permission`): `annotations.readOnlyHint is True`, or `destructiveHint is False` and `openWorldHint is False`. `auto` starts from the same test and decides the rest by rules (see Auto mode). A value of `permission` that is not one of the three is read as `ask`, and the user is told. Names and meanings are MCP's, with MCP's worst-case defaults — no annotations means asked — and the values must be real booleans. Tool names do not matter for this test (there is no allow-list).
|
|
53
|
+
|
|
54
|
+
- **Where annotations live.** `ToolAnnotations` (`pi_agent_core.types`) on `SimpleTool`, `CodingTool` and `ToolDefinition` (extensions); `from_langchain_tool` reads the four hints from `tool.metadata`. `AgentHarness.check_tool_call` looks the tool up **by name in the session's own tool table** and puts its annotations on `ToolCallEvent.annotations` — the session's loop and workflow sub-agents share that path, so a sub-agent's call is judged by the session's tool of the same name (a name the session lacks is asked about).
|
|
55
|
+
- **Our own tools.** `read` / `grep` / `find` / `ls`: read-only. `web_search` / `fetch_url`: read-only and open-world. `goal_update` / `goal_complete`: not read-only, not destructive, not open-world (they only keep notes in the session). `bash` / `edit` / `write` and `workflow` say nothing on purpose. A new tool that only reads, or only keeps the agent's own notes, should say so, or `ask` mode will interrupt the user for it.
|
|
56
|
+
- **Hints are the author's word**, never verified. There is no per-tool allow-list in `agent.toml`; to let an undeclared third-party tool through, give it annotations or use `always-approve`. Auto does not let it through: a tool that declares nothing always asks in Auto (design decision D7).
|
|
57
|
+
- **What `zypi` offers.** The TUI tells the agent `ask`, `auto` or `always-approve` (`pi/yolo_mode_changed`: Shift+Tab goes Normal, Auto, Always-Approve; `--always-approve`; `--permission-mode default|auto|bypassPermissions`), and puts the mode of a start in `_meta.yoloMode` / `_meta.autoMode` of `session/new`. **A start with nothing chosen is Normal (`ask`), not Auto** (design decision D5b): the launch code of the pager (`agent_modes::launch_auto`) does not use the soft default of the vendored resolver. Auto starts only when the user chose it (`--permission-mode auto`, or `[ui] permission_mode = "auto"` in `config.toml`, which the settings page saves). The pager still hides Plan and a settings "Default" (`tui/crates/codegen/pi-pager/src/app/agent_modes.rs`: the constants `PLAN` and `DEFAULT`, the code behind them kept), and `--permission-mode` refuses `plan`, `acceptEdits` and `dontAsk`. The agent has no Plan mode and none is planned (design decision D10): `session/set_mode` takes `ask` and `auto` only, and `default` in `pi/yolo_mode_changed` is ignored. `scripts/tui_pty/mode_probe.py` and `python_agent_e2e.rs` (the two Auto cases) hold what `zypi` does against this agent; `docs/PLAN/archive/PLAN-RUST-AGENT-RUNTIME-REMOVAL-EXECUTION-LOG.md` section 10.13 has the history.
|
|
58
|
+
|
|
59
|
+
A prompt that arrives while a turn the client did not start (a `workflow` result delivered through `trigger_message`) is still running waits for that turn rather than failing `busy`; `session/cancel` and closing the session end the wait, and two prompts in flight from the client are still `busy` (`PiAcpAgent._run_prompt`). The ACP v2-draft `state_update` is deliberately not sent: the v1 SDK and the Rust crate under the TUI reject it. Design: `docs/specs/2026-09-22-phase7-extension-api-design.md` §12 and §13.
|
|
60
|
+
|
|
61
|
+
## Auto mode
|
|
62
|
+
|
|
63
|
+
`permission = "auto"` is a real mode. Auto runs the calls that are clearly in scope and asks about the rest. It never refuses a call by itself: the outcomes are "run" and "ask" (decision D4). Design, decisions and test plan: `docs/specs/2026-11-02-auto-mode-design.md`.
|
|
64
|
+
|
|
65
|
+
**State of the work.** Auto decides with rules (PR 1a: the rules; PR 1b: the wiring) and, for a `bash` call that no rule decides, with a model step (PR 2). The pager offers the mode (PR 3: `AUTO = true`; it merged after PR 2, decision D9). `[auto] classifier = "model"` is the default. `classifier = "rules"` turns the model step off: then a `bash` call that the rules cannot show to be safe asks the user, as it did in PR 1b. `permission = "auto"` meant "no question" before PR 1b. It now asks, and the entry message says so. Headless (`-p`) moved to `always-approve` to keep the old behaviour (decision D1; `CHANGELOG.md`).
|
|
66
|
+
|
|
67
|
+
**The decision** (`auto_rules.decide` gives ALLOW, ASK or JUDGE; with `classifier = "rules"`, `decide_rules_only` turns a JUDGE into an ASK; one call at a time; the first step that answers wins):
|
|
68
|
+
|
|
69
|
+
1. The tool declares itself harmless (`needs_permission`): the call runs, and Auto does not look at it. Auto never asks about a call that `ask` runs with no question (rule A0). Auto does not record these calls.
|
|
70
|
+
2. The floor. A match asks, and nothing turns it into a yes: a path outside the project folder or on the protected list, a delete or an overwrite that git cannot undo, network that sends or installs (a list of program names, `_NETWORK` in `auto_rules.py`: `curl`, `ssh`, `rsync`, `rclone`, `mail`, `twine`, `ngrok` and more; a program that the list does not name, such as `hg push`, goes to the model), secrets, a command that hides what it does (`eval`, `$(...)`, `python -c`, here-documents), a command that leaves the limits of the Bash tool (`&`, `setsid`, `timeout` for more than 300 seconds), project code in a project that is not trusted (`git` too: the config of a repository can name a program that `git status` runs), and a tool that declares nothing and is not our own `bash`, `edit` or `write` (a third-party tool, an MCP tool, `workflow`).
|
|
71
|
+
3. The allow rules: `write` and `edit` inside the project folder (a new file, or a file inside a git work tree), and `bash` that the parser shows to be read-only.
|
|
72
|
+
4. A `bash` call that the parser can read, and that no rule decides, is left open (JUDGE, rule id `bash.not_proven`). The model step answers for it (next section). With `classifier = "rules"` it asks (reason `unclear`). One exception: a call that may hold a shell comment asks by the floor with the rule id `bash.comment` and the reason `comment`, and no model sees it (`auto_rules.may_hold_comment`: a `#` that starts a word outside quotes, or text that the scan cannot follow, such as `$(`, a back quote or a quote that does not end). A call that the rules prove read-only keeps its ALLOW with a comment, and a floor rule keeps its own reason.
|
|
73
|
+
5. Anything else asks (reason `unclear`).
|
|
74
|
+
|
|
75
|
+
A form that the rules know to be dangerous is not left open. It asks by the floor with the rule id `bash.barred.<kind>`, so that no model is called and no model answer can allow it (red-team decision D-07, `auto_rules.BARRED_KINDS`): an option of a read-only program that runs a program or writes a file (`option`), a banned operand (`operand`; `date` that sets the clock), a glob at the start of a word that can become such an option (`lead_glob`; `rg foo *`), a `git` option that runs a pager or an external diff (`git_option`), a device that never ends (`endless_device`; `/dev/zero`), the version flag of a program that reads the project first (`version_flag`), and a file of the project that has the name of a read-only program (`disguise`; `./git`). A test covers each kind.
|
|
76
|
+
|
|
77
|
+
**M-06 is NARROWED, not closed** (red-team finding of the third review: text in the command that tells the checker how to answer moved real models from ASK to ALLOW on calls that must ask). **Closed:** the comment channel, for every model (`bash.comment`, above). **Open:** the string-argument channel (3 of 300 answers on two models that fail the gate of the design record; 0 of 270 on the three small models that pass it; 0 of 180 on the larger ones), and the places that have only a first probe (a comment inside the code of a program, file names, branch names, environment values: 0 of 360 answers on six models, with one or two rows for each place). A `#` inside quotes or inside a word is not read as a comment, so such a call still goes to the model. Use a judge model that passed the gate as it was measured (the four models of the table in the design record, section 12.3; `[auto] model`). The two that failed it are the two that moved here. The corpus labels of dx041 and dx042 changed after that measurement (destructive to ambiguous): that changed a label and not an answer, so it does not make those two models safe judges. `[auto] classifier = "rules"` never lets a model allow a call. The rule asks about a plain comment that no rule proves read-only (`make test # run the unit tests`): that is its cost. Design record: section 12.8.
|
|
78
|
+
|
|
79
|
+
The question to the user holds the reason as one fixed sentence (`auto_reasons.sentence`), for example `bash (Auto: leaves the project folder)`. It never holds command text, a file name or text from a model.
|
|
80
|
+
|
|
81
|
+
**The model step** (`auto_classifier.py`; `[auto] classifier = "model"`, the default). The model is asked about a `bash` call that no rule decided (JUDGE), and about nothing else: a floor match, an allow rule, a barred form and every other tool are decided before, and a model cannot turn their ASK into a yes (invariant 9b). Each call is judged alone. Nothing is cached.
|
|
82
|
+
|
|
83
|
+
- **What it gets.** One request. The system prompt is the fixed policy text (`POLICY`; its hash, `POLICY_HASH`, goes into the record and into the cassette). The one user message holds two blocks of JSON: the user's own messages of this session (the first one and the newest ones, at most 4000 characters in all; never text of the assistant or of a tool) and the call (tool name, working folder, arguments). The tags of the blocks carry a random token of this call, characters that cannot be seen are written as escapes, and everything inside is JSON, so a command cannot close a tag or pass for an order. A call whose arguments are longer than 8192 characters as JSON, or that holds the token, is not sent: it asks (`model.too_long`). The model never judges a part of a command.
|
|
84
|
+
- **How it is asked.** No tools, temperature 0, 16 output tokens, reasoning off, no retries. The request is not part of the history of the session. It goes to the `stream_fn` of the harness, with the same key as the turn (`StreamOptions.temperature` and `max_tokens` are core options for this; every other caller leaves them unset).
|
|
85
|
+
- **Which model.** The model of the session, read again for each call (`/model` can change it), or the `[model]` / `[[models]]` entry that `[auto] model` names. The user's messages and the command go to the provider of that model. An id that is not there asks (`model.no_model`), and the user is told: with `classifier = "model"`, the entry message of Auto has one sentence that names the id and says that no model judges and a shell command that needs a judge asks (`auto_mode.unknown_judge`, `UNKNOWN_MODEL_ENTRY_SENTENCE`; it takes the place of the sentence that names a model), and the agent logs one warning for each notice. The id is shown as one printable line of at most 64 characters, and nothing else of a model entry is shown (no `base_url`, no key, no name of a key variable). The notice does not raise and changes no decision. The note of `load_config` ("Settings in agent.toml that are not used") names the id in every mode, as before. `tests/test_auto_unknown_model.py`.
|
|
86
|
+
- **What it answers.** One line: `ALLOW`, or `ASK` and one code of a fixed list (`DESTRUCTIVE`, `OUTSIDE_SCOPE`, `NETWORK`, `SECRETS`, `EXEC_UNKNOWN`, `PERSISTENCE`, `UNCLEAR`). The parser takes only a normal answer (stop reason `stop`) that is exactly this text, after spaces, tabs and line ends are cut from its ends. Anything else asks: other words, a lower-case word, quotes, a second line, a code that is not on the list, an answer that was cut off, a tool call, an empty answer, an error. Thinking blocks are skipped. The text of the model is never shown to the user and is never kept; the user sees one fixed sentence (`auto_reasons`).
|
|
87
|
+
- **Failures ask.** A timeout (`[auto] timeout_seconds`: `model.timeout`), a failed request (`model.request_failed`), an answer that cannot be read (`model.unparseable`), no model (`model.no_model`), `session/cancel` or a closed session (`model.cancelled`), an error in the step (`model.error`). The step never raises: a failure is an ASK, not an error of the agent.
|
|
88
|
+
- **The circuit breaker.** After three failures in a row the step sends no request for five minutes, and each call asks (`model.breaker_open`). The user is told once, and the message names the two ways out (`classifier = "rules"`, or another `[auto] model`). After the pause one request goes out. A readable answer closes the breaker, and another failure opens it again.
|
|
89
|
+
- **The record and the cost.** One short request for each call that no rule decides (about 700 input tokens; the measured cost of a decision is in the design record, section 12). A decision of the model goes into the record with `classifier`, `model`, `policy`, `tokens_in`, `tokens_out` and `cost_usd`. `/auto-log` shows the counts of the step (judged, answered, failed, not sent), tokens, cost when the provider reports it, and the time.
|
|
90
|
+
- **What can go wrong in use.** A model that thinks by default and runs out of the 16 tokens before it answers (some gateway models) answers nothing: every call asks, and the breaker opens. Name another model with `[auto] model`. A model can allow a call that is not safe. The corpus shows how often it did for the models that were tried (design record, section 12); it is a measurement and not a proof. The floor, the allow rules and the barred forms do not depend on the model.
|
|
91
|
+
|
|
92
|
+
**What a session adds** (`auto_mode.AutoSession`; one for each session, built before the extensions load):
|
|
93
|
+
|
|
94
|
+
- **One call at a time.** The rules judge a call on the files as they are when the call is judged. The harness would judge all calls of one assistant message first and run them after, so a `write` could change the files that the next call is judged on. While Auto is on, `AutoSession` sets `harness.tool_execution = "sequential"` and `execution_mode = "sequential"` on every tool, and puts both back when the session leaves Auto. The order is decide, run, decide, run (`tests/test_auto_wiring.py`, `packages/pi-agent-harness/tests/test_harness_tool_execution.py`). A workflow sub-agent that has a `tool_call_gate` runs its calls one by one too. If a call is judged while an earlier call of its message is still open (Auto was switched on during that message, or a tool came late), the call asks. The id of a call comes from the model, so `AutoSession` counts how many calls with one id are open: two calls with one id are two calls. Two sub-agents still run side by side, so a call of one can be judged while the other changes the files (design risk R4). A sandbox is the defence.
|
|
95
|
+
- **A checked context.** The rules trust the context that they get. At the start of Auto, and again for every call, `AutoSession` checks it: the project folder is absolute and exists; the home folder, `PI_HOME`, every `[auto] extra_roots` entry and every protected path are absolute; `builtin` is set by the identity of the tool object that the harness holds when the session starts (an extension can register its own tool with the name `bash`); `PATH` has no empty or relative entry; the Bash tool runs bash; and no value of `[auto]` is one that Auto cannot work with (this one is read again for every call, because the agent reads `agent.toml` again when it could not run a turn). While one check fails, every call that does not declare itself harmless asks. The user sees the problems in the entry message of Auto (when the session starts in Auto, or when the mode changes to Auto). A setting of `[auto]` that Auto cannot work with is told at the start of a session in any other mode too.
|
|
96
|
+
- **The protected list.** A write to a file that something else runs later asks: `auto_rules.DEFAULT_PROTECTED_GLOBS` (`.husky/*`, `.githooks/*`, `.claude/*`, `.cursor/*`, `.mcp.json`, `.vscode/tasks.json`, `.github/workflows/*`). The session gives the rules `default_protected_globs()`: each entry with `**/` in front, so `app/.husky/pre-commit` of a monorepo asks too. A glob that starts with `**/` matches at any depth below a project root (the folders above the root do not count). A glob that ends in `/*` protects the folder as well: `mv hooks .husky`, `cp -r hooks .husky`, `mkdir .husky` and a read of `.husky` ask (`path.protected_glob`), because the call puts new files into the folder or shows its content without naming a file in it. A shell glob in a call is tried against the names that the protected globs spell out (`.mcp.js*` can be `.mcp.json`, `.github/workf*/ci.yml` can be a workflow), as it is tried against the names of secrets. A call that is not read-only and names, as a whole, a folder on the way to a protected glob (`.github`, `.vscode`, and `tmpl/.github` at any depth below a root) asks with `path.protected_leading`; a read-only call (`ls .github`, `git log -- .vscode`) and a path below the folder (`.github/ISSUE_TEMPLATE/bug.yml`) do not. A call that puts content into a protected folder without naming the folder or a file in it (`git apply fix.patch`, `patch`, `tar -x`, `unzip`, `git checkout`, `cp -r tmpl/. .`) is the "write, then run" gap of the design (R3): the rules do not read the content, and the model step sees only the call. `Makefile`, `package.json` and `conftest.py` are not on the list: the agent changes them in ordinary work, and a question each time would make Auto useless. To change the list, change the one constant. A test covers each entry. The home `agent.toml` adds entries with `[auto] protected`. When the project is the home folder, a write to a hidden name directly below it, or to `bin`, `go/bin`, `Library`, `Applications` or `AppData`, asks too (`path.home_persistence`): the shell, an editor or the system runs those files later. A project that is below the home folder keeps its own hidden and `bin` folders.
|
|
97
|
+
- **Limits for a call that Auto allowed.** A `bash` call that Auto allowed runs with a time limit and an output limit (`[auto] bash_timeout_seconds`, default 300; `bash_max_output_mb`, default 64). The Bash tool asks for the limits of each call (`create_bash_tool(limits_for_call=)`, `BashLimitRegistry`). The shorter of the model's own timeout and the limit wins. The Bash tool stops a call by killing the process group of the shell, so a command that leaves that group would outlive the limit. These asks: `&` (a job in the background), `setsid`, and `timeout` for more than 300 seconds in all, or `timeout 0` (`timeout --foreground` stays in the group). `bash_timeout_seconds` has to be a number above 0 and not above the largest time that the Bash tool takes (2147483 seconds); any other value is dropped, and Auto uses 300. A call that the user allowed after a question has no limit: the user chose it. A `bash` call of a workflow sub-agent follows the same rule: the registry key is the id that the gate saw (`subagent-<run>:<id>`), and `HarnessSubagentExecutor` builds its Bash tool with `bash_limits_for_call` (from the harness bridge).
|
|
98
|
+
- **The record.** Each decision that Auto makes goes into the session file as a `pi.auto_decision` entry (tool call id, tool, outcome, `by`, reason code, rule id, milliseconds; for a call that went to the model also `classifier`, `model`, the policy hash, tokens and cost; no command text and no text of the model). `/auto-log` shows the counts, a line for the model step and the last 20 decisions. The command exists in every session, also in `ask`.
|
|
99
|
+
- **Fail closed.** `AutoSession.decide` never raises, and it has a time limit (`DECISION_TIMEOUT_SECONDS`, and the model timeout on top when the model step is on). An error, a timeout or a state that it cannot read is an ASK (`internal_error`, `checker_unavailable`). `session/cancel`, closing the session and loading a session over an open one (the old `AutoSession` is replaced) end a request that waits for the model. The call does not run, and after `session/cancel` the user is not asked.
|
|
100
|
+
|
|
101
|
+
**Config** (`[auto]` in the home `agent.toml`; a project file never sets it): `classifier` (`"model"`, the default, or `"rules"`, which turns the model step off; any other value is read as `"rules"` and named in a message), `model` (the `id` of the `[model]` or `[[models]]` entry that judges; empty: the model of the session), `timeout_seconds` (the time that the model has to answer: above 0 and at most 120, default 8), `extra_roots` (absolute folders that count like the project folder), `protected` (globs that always ask), `bash_timeout_seconds`, `bash_max_output_mb`. A value that cannot be used is dropped and named in a message, except an entry of `protected`: that one tightens Auto, so a bad one makes Auto ask about every call until the file is right.
|
|
102
|
+
|
|
103
|
+
**On the wire** (`permission_modes.py`, `agent.py`). The mode belongs to the session, not to the process. `session/new`, `load` and `resume` return a `mode` config option (category `mode`; `ask` and `auto`) and `modes`. A client changes the mode with `session/set_config_option` (`mode`) or `session/set_mode`. Only `ask` and `auto` can be chosen with these items (decision D6). `always-approve` shows as the current value of a session that is in it, and `agent.toml` or a legacy item sets it. Any other value is `invalid_params`. The pager's legacy items stay (decision D5): `_meta.autoMode` and `_meta.yoloMode` in the session requests (a flag that is false or missing says nothing), and the notification `pi/yolo_mode_changed`. The notification has no session id, so it moves every open session, and it sets the start mode of sessions that open later. When Auto starts in a session (at the start, or by a change), the user gets the entry message (`auto_mode.entry_message`).
|
|
104
|
+
|
|
105
|
+
**What Auto does not protect.** Auto guards what a call writes or runs. It does not guard what a call reads or sends:
|
|
106
|
+
|
|
107
|
+
- `read`, `grep`, `find`, `ls`, `fetch_url` and `web_search` declare themselves harmless, so they run with no question for any path or URL. They can read a secret and show it to the model, and `fetch_url` can send it to a server (the old gap, decision D8; `ask` mode has it too).
|
|
108
|
+
- A recursive or a glob read inside `bash` runs with no question as well, because it only reads: `grep -r token .`, `rg --hidden -uuu`, `git grep`, `git log -p`, `cat *`. It can print a protected file that it never names.
|
|
109
|
+
- The boundary is a sandbox (`zypi --sandbox`, a container or a VM). Auto is a convenience, and it is not that boundary. The entry message and every doc must say no more than this.
|
|
110
|
+
|
|
111
|
+
**Tests.** `tests/test_auto_rules.py`, `test_auto_reasons.py` and `test_auto_corpus.py` (the rules and the labelled corpus); `test_auto_mode_checks.py` and `test_auto_wiring.py` (the session: checks, order, limits, record, a link that leaves the project); `test_auto_classifier.py` (the model step alone: the parser of the answer, the data block, the request, the timeout, `session/cancel`, the breaker, the counters; a property test that garbage from a model never allows) and `test_auto_model_step.py` (the step in the pipeline and in the session: the order, one test for each barred form of D-07, what the model is given, which model, the record, `/auto-log`, the entry message); `test_auto_corpus_model.py` (the corpus through the real step with scripted broken models, and with the cassette of recorded answers) and `test_auto_eval_real.py` (the runner for a real model, with a fake network); `test_auto_comment_floor.py` (the comment rule of M-06: the detector against the `shlex` module and against the lexer of the rules with seeded strings, the rule in `decide`, in a session and in an agent); `test_auto_floor_wrappers.py` (50 floor commands behind 47 wrappers, about one second: none gets to the model); `test_auto_wiring_redteam.py` (the second review: ways out of the limits of `bash`, `git` in an untrusted project, protected files below the root, a project that is the home folder, calls with one id); `test_permission_mode_wire.py` and the mode section of `test_acp_stdio_tools.py` (the wire, with a real agent process; these tests need bash, and the link tests need symbolic links, so they skip where there is none). Three scripts guard a change of Auto. `python scripts/auto_eval.py` (the corpus through the rules and through the scripted models; exit 1 when a gate fails) and `python scripts/auto_eval.py --replay` (the model step with the recorded answers) are gates before a push. `python scripts/auto_mutation_check.py` breaks one rule, one wiring step or one fail-closed path of the model step at a time, and every break must fail a test (about 11 minutes on four cores). `python scripts/auto_eval.py --real --max-usd 0.50` asks a real model (OpenRouter; the key only from `OPENROUTER_API_KEY`; the request log goes to a folder outside the repository; manual, never in CI). A change of `POLICY` makes the cassette stale: record it again with `--real --record-cassette`.
|
|
112
|
+
|
|
113
|
+
## TUI spawn
|
|
114
|
+
|
|
115
|
+
The Rust TUI (`zypi`) spawns the Python agent via (priority order):
|
|
116
|
+
|
|
117
|
+
1. `PI_AGENT_COMMAND` env var
|
|
118
|
+
2. `[agent].command` in `agent.toml`, then in `config.toml`
|
|
119
|
+
3. `PI_PYTHON` env var (appends `-m pi_agent_cli`)
|
|
120
|
+
|
|
121
|
+
**The agent's stderr.** The TUI owns the screen, and its own fd 2 is `/dev/null` (`pi_tty_utils::redirect_native_stderr`), so the agent's stderr goes to `<home>/logs/agent.stderr.log` instead (`acp/spawn.rs`, `agent_stderr`): appended across runs, one `--- agent started <time> (zypi pid N) ---` line per spawn, mode 0600 on Unix (a traceback can quote prompts, paths and keys), and a log longer than 1 MiB is moved to `agent.stderr.log.1` at the next spawn. A log that cannot be opened is skipped, not fatal. This is where a Python traceback or a warning from the agent ends up; the agent should still write diagnostics to stderr, not stdout (stdout is the ACP channel). `-p` runs are not redirected: there the agent's stderr is the user's terminal.
|
|
122
|
+
|
|
123
|
+
**When the agent exits on its own.** The stdio bridge (`acp/spawn.rs`) waits on the child next to the cancel token, so an agent that dies is noticed instead of leaving requests to hang. It drains what the agent had already written, builds one message (`agent_exit_message`: the program, its exit status, and the last 12 lines / 4 KiB of `agent.stderr.log`), fails every pending request, and ends the bridge with that message. `connect()` reports a failed `initialize` as that message (`explain_failed_start`): `failed to spawn ACP agent` plus the program and `PI_AGENT_COMMAND` for a program that is not there, `exited on its own (exit status: 1)` plus the traceback's tail for a Python that lacks `pi_agent_cli`. Once the TUI is up, `AgentProcessGuard` prints `Error: …` on the restored terminal. So an agent must not exit on an error it can handle, and anything it prints to stderr before it dies reaches the user. `zypi`'s own exit status is unchanged. `tui/crates/codegen/pi-pager/tests/python_agent_e2e.rs` runs the pager's ACP client against this agent, including these failures (needs a Python with `pi_agent_cli`: `PI_E2E_PYTHON`; `PI_E2E_REQUIRED=1` makes its absence a failure, as in `tui-ci.yml` and `tui-e2e.yml`). A change under `pi_agent_cli/` (or of `tests/_tool_agent.py`) runs this file alone in CI (`tui-e2e.yml`): no other Rust test reads the agent.
|
|
124
|
+
|
|
125
|
+
## MCP servers
|
|
126
|
+
|
|
127
|
+
The agent has **no** MCP client: it opens no MCP connection and starts no MCP server process. Phase 6 decided this, in line with upstream pi ("No MCP"). The 0.5.0 notes called it a Phase 4 non-goal, but Phase 4 did not discuss MCP. What a client passes in `mcp_servers` (`session/new`, `load`, `resume`, and the reopen of a blank session) goes to the harness as data, and an extension can use it:
|
|
128
|
+
|
|
129
|
+
- **Hand-over.** `client_mcp.client_mcp_servers()` turns the ACP models (or plain dicts) into `ClientMcpServer` records (`pi_agent_core.extensions`: `name`, `transport`, `command`, `args`, `env`, `url`, `headers`; the fields that can hold a token are `repr=False`). A name is one line of printable text. An empty name becomes `server-<n>`, and a repeated name gets `-2`, `-3`. A server that cannot be used (no command, no URL, unknown type) is skipped with a warning that names it. `_bind_session` gives the list to `harness.set_client_mcp_servers()` before the extensions load. An extension reads it as `pi.client_mcp_servers` and takes servers with `pi.claim_client_mcp_servers(names)`. The optional `pi-mcp-py` package is such an extension (design: `docs/specs/2026-10-23-mcp-extension-design.md`).
|
|
130
|
+
- **Capabilities.** `initialize` always sends an `mcpCapabilities` object. `http` and `sse` are `true` only when the `pi-mcp` entry point is installed (`mcp_extension_installed()` reads package metadata and imports nothing, so a broken extension still counts). ACP allows stdio servers always.
|
|
131
|
+
- **The notice.** A server that no extension claimed is not connected. For these servers, and only these, the agent logs a warning (names only) and sends one agent message (`mcp_notice`, from `_deferred_session_setup`, after the response has flushed like the other notices). It tells the user to install `pi-mcp-py`, or, when the entry point is there, that no extension took the servers over. Only the **names** are used: `env`, `headers`, `args` and `url` routinely hold tokens. `zypi` sends an empty list (it used to forward whatever it found in `.mcp.json`, `~/.claude.json` and Cursor's `mcp.json`), so there the notice never appears. It is for other ACP clients (an editor that passes its own servers).
|
|
132
|
+
- **Lines for the user from an extension.** `pi.notify(text)` becomes a `NoticeEvent`, and `project_event` shows it as an agent message. The client drops what it gets before it knows the session (zed#60199), so the agent holds such a line (`_held_notices`) until `_deferred_session_setup` has advertised the commands (`_open_notices`). Later lines go out at once. Opening the session again closes this gate again. Closing or deleting the session forgets what was held.
|
|
133
|
+
- **Turn barriers.** An extension can register `pi.add_turn_barrier(wait)`. `prompt()` awaits `harness.wait_turn_barriers()` after the question about the project and before the turn starts. `session/cancel` ends that wait (the prompt returns `cancelled`). Closing or deleting the session, or opening it again, ends it too (`_drop_trust` sets the cancel event). The harness awaits the same barriers before it builds the tool list, and a barrier that is done returns at once.
|
|
134
|
+
- **A session that is opened again.** `_bind_session` puts the new harness in place first, and then closes the old one (`close()` stops its turn and runs the cleanup callbacks of its extensions). Before, the old harness was dropped without `close()`, and what its extensions had started (an MCP server is a child process) kept running.
|
|
135
|
+
|
|
136
|
+
Tests: `tests/test_client_mcp.py`, `tests/test_mcp_notice.py`; the hooks: `pi_agent_core/tests/test_client_mcp_hooks.py`, `packages/pi-agent-harness/tests/test_client_mcp_harness.py`.
|
|
137
|
+
|
|
138
|
+
## Listing sessions
|
|
139
|
+
|
|
140
|
+
`session/list` returns `SESSION_LIST_PAGE_SIZE` (50) sessions at a time, newest first, with `nextCursor` while more follow; the TUI keeps asking until it is gone. The order is the harness's (`JsonlSessionRepo.list_page`): creation time, which the session file names start with, so a page reads a file's header only when it gets that far and costs the files it looks at, not the directory (a `cwd` filter makes it skip other projects' files). `nextCursor` is opaque to the client and carries the file name the next page continues below; the agent keeps nothing between requests, so a cursor survives a restart, a session created meanwhile is simply newer than the cursor, and one deleted meanwhile moves nothing. A page that carries a cursor is never followed by an empty one (the agent looks one session ahead). A string the agent did not issue is `invalid_params`. `updated_at` is still the file's mtime, so it need not be in the order of the list.
|
|
141
|
+
|
|
142
|
+
Looking a session up by id (`load` / `resume` / `pi/session/delete`) is `JsonlSessionRepo.find`: the file name ends in `-<id>.jsonl`, so only that file's header is read. `scripts/session_list_bench.py` measures all of this against the real agent (`start`, first page, every page, `session/load`) on a synthetic home; numbers and the decisions that rest on them are in `docs/PLAN/archive/PLAN-RUST-AGENT-RUNTIME-REMOVAL-EXECUTION-LOG.md` §10.11.
|
|
143
|
+
|
|
144
|
+
The TUI finds a session only through this list and `session/load` (`tui/crates/codegen/pi-pager/src/app/session_resolve.rs`; the `/resume` picker uses the same page walker, `acp/session_list.rs`). It reads no session file: the gate `gates.session_disk_reads` in `scripts/tui_baseline.toml` fails when its code does. Once the agent is up, `--continue` and `--resume` without a value take the session of the directory with the latest `updatedAt` (all pages are read); `--resume <id>` finds the id in every directory and loads it in the `cwd` that the list gives; `--resume <title>` compares `title` (letter case and spaces at the ends are ignored); `--session-id <id>` reads every page and refuses an id that is listed. So `sessionId`, `cwd`, `title` and `updatedAt` of a listed session are part of the contract with the TUI. An agent that does not offer `session/list` cannot be resumed with a flag. A new session has no file until its first message (`DeferredJsonlSessionStorage`; plan decision 17): until then `session/list` does not show it, so `--continue` cannot take a session in which nobody typed. `session/load` and `session/resume` of its id open it again, empty (`_reopen_blank_session`), and do not write a file: Zed saves the id of every thread that shows something (a notice of the agent counts) and asks for it after a restart, and "not found" left that thread dead ("Failed to Launch"). This holds for an id in the form the agent gives out (a UUID, lower case, hyphens), so a UUID that no session ever had opens too (`zypi export <uuid>` then says "no conversation content", not "not found"). Any other id is still "not found". The agent keeps the id that the client chose with `--session-id` while the session has no file, and looks for it in the files once more at the first message. A file that an older version wrote with a header only is still listed, with the title `(no messages)`. Each page lists the directory again, so reading all pages costs pages × directory size: `--session-id` takes about 1.3–1.8 s at 1,000 sessions and 28–34 s at 5,000, which is over the 30 s limit of the lookup on Windows (`walk all` in `scripts/session_list_bench.py`). The owner decided to leave it: it is fine below 1,000 sessions (plan decision 18).
|
|
145
|
+
|
|
146
|
+
## Extensions beyond ACP v1
|
|
147
|
+
|
|
148
|
+
The register of every item on the wire that is not standard ACP is `docs/specs/2026-11-05-acp-extension-registry.md`: name, direction, schema, who sends it, who reads it, tests, status, and how to add one. Change the register in the same pull request as the code. This file keeps what is specific to the agent's code. Where the notes of each item are: X1 `pi/session/delete` in "Listing sessions" (how a session is looked up); X4 the `pi/*` model hints in "Model selection (`/model`)"; X7 `_meta.yoloMode` / `_meta.autoMode` and X8 `pi/yolo_mode_changed` in "Tool permissions" and in "Auto mode" ("On the wire"); X5 `_meta.isReplay` and X6 the terminal keys are set in `events.py` and need no note here. The two items below are X2 and X3.
|
|
149
|
+
|
|
150
|
+
- **`_meta.sessionId` on `session/new` (X2)** is the TUI's `--session-id`: ACP v1 has no field for the id of a new session. The agent (`_chosen_session_id`, `_create_session_with_id`) takes it as the session's id. It must be a UUID in any form `uuid.UUID` reads, and comes back canonical (lower case, hyphens); anything else is `invalid_params`, because the id ends up in a file name. An id already in use is `invalid_params` too, whatever directory the session that has it belongs to: the repository would not refuse it (file names start with the creation time, so a second file with the same id fits beside the first), and a later `session/load` would find either. Requests for the same id at once make one session (`_chosen_id_lock`). The id also stays taken while its session has no file yet (`_reserved_ids`: it leaves when the session is closed or deleted); a blank session that a client opens again with `session/load` keeps its id in the same way, but the id that the agent itself gives to a new session is not kept (the check would cost every session a directory listing). Two agent processes on one home are not covered: the check at the first message (`_refuse_id_taken_meanwhile`) makes the gap smaller, and does not close it. The question is `JsonlSessionRepo.has_session`, which opens a file only when its name does not already say it belongs to another session (`find` would read every header for an id nobody has); the one thing it takes on trust is a file renamed by hand to carry another id. What a free id still costs is the directory listing, about 0.07 s at 1,000 sessions and 0.3 s at 5,000 on both Windows and WSL2, against 8–20 ms for a session with an id of the agent's own (`scripts/session_list_bench.py`, the last block of its output). Nearly all of that is `LocalExecutionEnv.list_dir` building a `FileInfo` per entry (`os.listdir` of the same 5,000 files: 2–11 ms), which `session/list` pays on every page too. `tests/test_session_chosen_id.py`.
|
|
151
|
+
- **`_meta["pi/cwd"]` in the response that opens a session (X3)** (`new`, `load`, `resume`) is the directory the session works in. `load` and `resume` take a `cwd` as well, and the one saved with the session wins; a client that only knows where it was started (`zypi --resume <id>` from another directory) learns the real one here. Nothing in the TUI reads it yet.
|
|
152
|
+
|
|
153
|
+
## ACP contract tests
|
|
154
|
+
|
|
155
|
+
`tests/test_acp_stdio_contract.py` drives an agent *process* over stdio the way the TUI does: `initialize`, `session/new`, streamed `prompt`, the `model` config option, `session/list` (first-prompt title), `session/load` replay and `session/resume` across a restart, `session/close`, a client-chosen id on `session/new` (and a taken one refused), the directory `session/load` reports, unknown methods answered with an error, exit code 0 on stdin EOF. It uses the mock LLM (`PI_USE_MOCK=1`) and a throw-away `PI_HOME`. Set `PI_ACP_CONTRACT_COMMAND` to run the same suite against another stdio ACP agent (it must honour `PI_HOME` and answer prompts with `Hello from mock`, without network), e.g. a future `pi-rust`.
|
|
156
|
+
|
|
157
|
+
The mock LLM never calls a tool, so the tool side of the contract has its own file: `tests/test_acp_stdio_tools.py` drives `tests/_tool_agent.py` (the real `serve()` with a scripted LLM turn that calls one tool; `PI_TEST_TOOL_CALL` picks the call, `PI_TEST_PERMISSION` the mode) and checks, over the wire, what the pager relies on: in `ask` mode a `write` call is announced as a `tool_call` update, then put as `session/request_permission` (title, kind, `raw_input`, the two options `allow-once` / `reject-once`) before the tool runs; `allow-once` runs it, `reject-once` and a `cancelled` outcome do not and the turn still ends; `always-approve` never asks; `auto` asks about a call that its rules do not allow, with the reason in the title, and runs one that they allow with no question; the mode over the wire (the `mode` option, `session/set_mode`, the legacy `_meta` flags and `pi/yolo_mode_changed`); `session/cancel` ends a prompt as `cancelled` (while a question is open, and while a `bash` call runs, which is then reaped; POSIX only), and is harmless with nothing running or for an unknown session. The scripted stream ends `aborted` once the signal is set, as the LangChain adapter does, so these tests do not depend on a real provider's abort handling.
|
|
158
|
+
|
|
159
|
+
`__main__.serve()` starts `run_agent(..., use_unstable_protocol=True)`: `initialize` advertises `session/close` and `session/resume`, which the SDK serves only with that flag.
|
|
160
|
+
|
|
161
|
+
## Stopping the agent
|
|
162
|
+
|
|
163
|
+
The agent must reap the tools it is running when its client goes away: the TUI closes the agent's stdin and kills it only after a grace period (`acp/spawn.rs`, `AGENT_EOF_GRACE`). `serve()` ends on EOF on stdin (`run_agent` returns, `asyncio.run` cancels the turns in flight, each `bash` tool kills its process group) and on SIGTERM / SIGHUP (the main task is cancelled, same path); all exit 0. SIGHUP matters because a terminal that goes away, or a TUI killed while it is the session leader, sends it to the foreground process group, which includes the agent; its default action kills the agent before it can reap anything. A repeated signal gets the default action (the handlers remove themselves on the first one), so an agent that hangs while it stops — a thread that cannot be cancelled keeps `asyncio.run` from returning — can still be killed. SIGKILL cannot be handled and orphans the tools. `tests/test_acp_shutdown.py` runs `tests/_tool_agent.py` (the real `serve()` with a scripted `bash` call, or a stuck thread) and checks EOF, SIGTERM, SIGHUP and the repeated signal; POSIX only.
|
|
164
|
+
|
|
165
|
+
**`-p` runs** have no stdin to close: `zypi -p` starts the agent as a child on the user's own terminal. They get the same stop signals (`_print_main`: the turn is cancelled, the tools are reaped, the exit status is 128 + the signal number), and zypi names itself in `PI_AGENT_PARENT_PID`, which the agent turns into a watch: every 0.5 s it checks `os.getppid()` and stops the same way once that pid is no longer its parent. That is how a zypi killed alone (`kill -9`, `kill <pid>`, an IDE's stop button) is noticed; a terminal hang-up or Ctrl+C reaches both anyway. The variable counts only if it names the agent's actual parent, or a process that is already gone (the parent died while the agent was starting); a live process that is not the parent is a wrapper script in between, and the watch stays off. `main()` removes the variable from the environment first thing, so a tool or a nested `-p` cannot inherit it. POSIX only: on Windows `getppid()` keeps naming the dead parent. `tests/test_print_shutdown.py` runs `tests/_print_agent.py` (the real `main()` with a scripted `bash` call) and checks both signals, a killed parent, an unrelated live pid, a parent that is already gone, and which values count. End to end, against a built `zypi` (Linux), `scripts/tui_pty/exit_matrix.py` (TUI: six ways out, two launch styles, with or without `--sandbox`) and `scripts/tui_pty/print_exit.py` (`zypi -p`, only zypi signalled) check that nothing is left running; see the README there.
|
|
166
|
+
|
|
167
|
+
## System prompt pipeline
|
|
168
|
+
|
|
169
|
+
`build_system_prompt` (`system_prompt.py`) assembles:
|
|
170
|
+
|
|
171
|
+
1. Base prompt with tool snippets and `prompt_guidelines`
|
|
172
|
+
2. `append_system_prompt` (config or CLI flag)
|
|
173
|
+
3. Context files — `context_files.py` walks cwd → repo root collecting `AGENTS.md`, `CLAUDE.md`; a custom `.pi/SYSTEM.md` / `.pi/APPEND_SYSTEM.md` replaces or extends the base prompt only for a trusted project (see Project trust)
|
|
174
|
+
4. Git status — `<git_status>` from `git_context.py` when cwd is a repo, `[git] enabled` is on (`--no-git-context` turns it off, headless only) **and the project is trusted** (see Project trust; untrusted or undecided: no block, no `git` process); the prompt inputs (files, git subprocesses) are built in a worker thread, and `timeout_seconds` is one budget for the whole snapshot. Trust is read each time the prompt is built, not once: the harness caches the prompt, and the cache is cleared when the model, the thinking level, the tools or the resources change (and then `git` runs again, for a trusted project). A "Trust and remember" answer calls `set_resources`, which clears it, so the block appears from the next turn, with a snapshot taken then; the first prompt waits for the answer, so normally nothing was cached before. A grant alone does not rebuild a prompt that is already cached
|
|
175
|
+
5. Skills from `[skills].paths`, formatted as `<available_skills>`
|
|
176
|
+
|
|
177
|
+
`build_coding_agent_harness_system_prompt` (`create_harness.py`) wraps this for harness use.
|
|
178
|
+
|
|
179
|
+
## Modules
|
|
180
|
+
|
|
181
|
+
| Module | Role |
|
|
182
|
+
|--------|------|
|
|
183
|
+
| `agent.py` | `PiAcpAgent` — ACP methods, permission handling, event projection |
|
|
184
|
+
| `config.py` | TOML loading, `pi_home()`, `CliConfig` dataclass (and `AutoConfig`, the `[auto]` table); `read_local_env`, `config_problem`, `no_model_message` |
|
|
185
|
+
| `setup_command.py` | `--setup`: the dialog and the writers of `agent.toml` and `local.env` |
|
|
186
|
+
| `auth_methods.py` | The terminal login for `initialize` (two forms), and the `auth_required` error |
|
|
187
|
+
| `factory.py` | `create_session_harness` — wires tools, model, stream_fn, skills into harness |
|
|
188
|
+
| `extension_trust.py` | `decide_project_trust` / `ProjectTrust`: whether a project may load its own extensions, saved workflows, prompt files and skills; the "skipped" and "could not be saved" notices |
|
|
189
|
+
| `trust_fingerprint.py` | The gated resources of a project and a content fingerprint of them |
|
|
190
|
+
| `trust_store.py` | `<home>/agent/trust.json`: answers saved per directory with the fingerprint they were about |
|
|
191
|
+
| `trust_prompt.py` | The `session/request_permission` question (shape, option ids, how an answer is read) and its explanation message |
|
|
192
|
+
| `extension_notices.py` | The "these extensions failed to load" notice (`AgentHarness.failed_extensions`): ACP agent message after `session/new`, headless stderr |
|
|
193
|
+
| `client_mcp.py` | The MCP servers a client passes (ACP models or dicts) as `ClientMcpServer` records for the harness; `mcp_extension_installed()` (entry-point metadata only) |
|
|
194
|
+
| `mcp_notice.py` | The "these MCP servers were not connected" notice: names only, never `env` / `headers` / `args` / `url` |
|
|
195
|
+
| `system_prompt.py` | `build_system_prompt`, tool snippet/guideline consumption |
|
|
196
|
+
| `context_files.py` | AGENTS.md / CLAUDE.md / .pi/SYSTEM.md discovery |
|
|
197
|
+
| `git_context.py` | Read-only branch and `git status` snapshot for the system prompt |
|
|
198
|
+
| `headless.py` | `-p` one-shot mode, prompt override application |
|
|
199
|
+
| `events.py` | Internal events → ACP `session_update` projection |
|
|
200
|
+
| `permissions.py` | Tool permission gating (ask / auto / always-approve): `needs_permission` (a tool that declares itself harmless is never asked about, in `ask` and in `auto`), the title of a question (it holds the reason when Auto asks), the allowed outcome (see Tool permissions) |
|
|
201
|
+
| `auto_rules.py` | The Auto rules: `decide` / `decide_rules_only` over a `ToolCall` and an `AutoContext` (`build_context`); the floor, the allow rules, the `bash` parser, the barred forms (D-07), `DEFAULT_PROTECTED_GLOBS`. No model, no session state (see Auto mode) |
|
|
202
|
+
| `auto_classifier.py` | The model step of Auto: the policy text, the answer parser, the data block, `ModelClassifier` (timeout, cancel, circuit breaker, counters) and `UserMessageLog`. It calls no tool and has no session state beyond the breaker |
|
|
203
|
+
| `auto_reasons.py` | The reason codes of an Auto decision and their fixed sentences for the user |
|
|
204
|
+
| `auto_mode.py` | `AutoSession`: Auto in one session (calls one by one, the checks of the context, the model step and the choice of its model, the record and `/auto-log`, the limits of `bash`) and the messages of Auto |
|
|
205
|
+
| `permission_modes.py` | The permission mode on the ACP wire: the `mode` option, `modes`, and the legacy `_meta` flags and notification |
|
|
206
|
+
| `session_list.py` | `session/list` display data: first-user-message title and file-mtime `updated_at` (bounded read), `SESSION_LIST_PAGE_SIZE`, the opaque `nextCursor` (`encode_cursor` / `decode_cursor`) |
|
|
207
|
+
| `create_harness.py` | Harness-level system prompt, coding tool wiring |
|
|
208
|
+
| `benchmarks/` | Pelican benchmark suite, evaluator, Docker runner |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pi-agent-cli-lc
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Standard ACP agent over AgentHarness (no x.ai extensions)
|
|
5
5
|
Project-URL: Homepage, https://github.com/zy1233/pi-python
|
|
6
6
|
Project-URL: Website, https://zycode.dev
|
|
@@ -20,10 +20,14 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
20
20
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
21
|
Classifier: Typing :: Typed
|
|
22
22
|
Requires-Python: >=3.11
|
|
23
|
-
Requires-Dist: agent-client-protocol
|
|
24
|
-
Requires-Dist: pi-agent-core-lc==0.
|
|
25
|
-
Requires-Dist: pi-agent-harness-lc==0.
|
|
23
|
+
Requires-Dist: agent-client-protocol<1.0.0,>=0.12.0
|
|
24
|
+
Requires-Dist: pi-agent-core-lc[openai]==0.9.0
|
|
25
|
+
Requires-Dist: pi-agent-harness-lc==0.9.0
|
|
26
26
|
Requires-Dist: pydantic>=2.0
|
|
27
|
+
Provides-Extra: anthropic
|
|
28
|
+
Requires-Dist: pi-agent-core-lc[anthropic]==0.9.0; extra == 'anthropic'
|
|
29
|
+
Provides-Extra: deepseek
|
|
30
|
+
Requires-Dist: pi-agent-core-lc[deepseek]==0.9.0; extra == 'deepseek'
|
|
27
31
|
Description-Content-Type: text/markdown
|
|
28
32
|
|
|
29
33
|
# pi-agent-cli-lc
|
|
@@ -35,7 +39,7 @@ Standard [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) agent o
|
|
|
35
39
|
- headless one-shot: `python -m pi_agent_cli -p "..."`
|
|
36
40
|
- Headless prompt overrides (override `agent.toml` `[prompt]`): `--system-prompt`, `--system-prompt-file`, `--append-system-prompt` / `--rules`, `--append-system-prompt-file`, `--no-context-files`
|
|
37
41
|
- Config: `~/.pi-python/agent.toml` (see `agent.example.toml` in this directory)
|
|
38
|
-
- First run: `python -m pi_agent_cli --setup` asks for a model and an API key in a terminal. It writes `agent.toml` and `local.env` (the key) in the home. An editor that can run a terminal login (Zed) offers the same dialog as the login "Set up model and API key"
|
|
42
|
+
- First run: `python -m pi_agent_cli --setup` asks for a model and an API key in a terminal. It writes `agent.toml` and `local.env` (the key) in the home. It asks no key, and writes no `local.env`, when the variable that you name already has a value. An editor that can run a terminal login (Zed) offers the same dialog as the login "Set up model and API key"
|
|
39
43
|
- No `x.ai/*` vendor RPCs — core + harness + ACP only
|
|
40
44
|
|
|
41
45
|
Install:
|
|
@@ -7,7 +7,7 @@ Standard [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) agent o
|
|
|
7
7
|
- headless one-shot: `python -m pi_agent_cli -p "..."`
|
|
8
8
|
- Headless prompt overrides (override `agent.toml` `[prompt]`): `--system-prompt`, `--system-prompt-file`, `--append-system-prompt` / `--rules`, `--append-system-prompt-file`, `--no-context-files`
|
|
9
9
|
- Config: `~/.pi-python/agent.toml` (see `agent.example.toml` in this directory)
|
|
10
|
-
- First run: `python -m pi_agent_cli --setup` asks for a model and an API key in a terminal. It writes `agent.toml` and `local.env` (the key) in the home. An editor that can run a terminal login (Zed) offers the same dialog as the login "Set up model and API key"
|
|
10
|
+
- First run: `python -m pi_agent_cli --setup` asks for a model and an API key in a terminal. It writes `agent.toml` and `local.env` (the key) in the home. It asks no key, and writes no `local.env`, when the variable that you name already has a value. An editor that can run a terminal login (Zed) offers the same dialog as the login "Set up model and API key"
|
|
11
11
|
- No `x.ai/*` vendor RPCs — core + harness + ACP only
|
|
12
12
|
|
|
13
13
|
Install:
|
|
@@ -10,6 +10,19 @@ permission = "ask" # ask | auto | always-approve
|
|
|
10
10
|
# `ask` asks before each tool call, except for tools that declare themselves harmless: read-only
|
|
11
11
|
# or only keeping the agent's own notes (read, grep, find, ls, web_search, fetch_url, goal_*).
|
|
12
12
|
# A tool that declares nothing is asked about; bash, edit, write and workflow always are.
|
|
13
|
+
# `auto` runs those harmless calls too, and the calls that its rules show to be safe: an edit in
|
|
14
|
+
# the project folder, a shell command that only reads. It asks about the rest: a path outside the
|
|
15
|
+
# project, a delete, the network, a command that hides what it does, a tool that declares
|
|
16
|
+
# nothing, and workflow. A shell command that its rules cannot judge goes to a model, which
|
|
17
|
+
# answers allow or ask. If the model does not allow it, does not answer in time, or answers in a
|
|
18
|
+
# way that Auto cannot read, you are asked (see [auto] at the end of this file). It never
|
|
19
|
+
# refuses a call by itself.
|
|
20
|
+
# `auto` is not a sandbox. read, grep, find, ls, fetch_url and web_search run with no question
|
|
21
|
+
# for any path or URL, and so does a recursive read in a shell command (grep -r, git grep, cat *).
|
|
22
|
+
# They can show a secret to the model, and fetch_url can send it to a server. Use a sandbox
|
|
23
|
+
# (zypi --sandbox, a container or a VM) when that matters.
|
|
24
|
+
# `always-approve` asks about nothing. Headless (-p) runs always use it. Before this version,
|
|
25
|
+
# `auto` meant "ask about nothing": use `always-approve` for that.
|
|
13
26
|
|
|
14
27
|
thinking_level = "off" # off | minimal | low | medium | high | xhigh
|
|
15
28
|
max_turns = 50
|
|
@@ -54,7 +67,9 @@ command = "python -m pi_agent_cli"
|
|
|
54
67
|
[git]
|
|
55
68
|
# A `git status` snapshot (branch name and the paths of changed and untracked files) is added to
|
|
56
69
|
# the system prompt at the start of a session, so it is sent to the model provider with every
|
|
57
|
-
# request. Set enabled = false if such names are sensitive.
|
|
70
|
+
# request. Set enabled = false if such names are sensitive. Only for a trusted project (see
|
|
71
|
+
# [extensions]): `git status` runs the program that the repository's own .git/config names in
|
|
72
|
+
# `core.fsmonitor`, so it is not run in a project nobody vouched for.
|
|
58
73
|
# enabled = true
|
|
59
74
|
# timeout_seconds = 2 # one budget for the whole snapshot (up to four git commands), not per command
|
|
60
75
|
# max_status_lines = 40
|
|
@@ -82,3 +97,25 @@ command = "python -m pi_agent_cli"
|
|
|
82
97
|
# trust_project_extensions = false # older switch: true means default_project_trust = "always"
|
|
83
98
|
# # (an explicit default_project_trust wins)
|
|
84
99
|
# One-off alternatives: --trust-project-extensions, or PI_TRUST_PROJECT_EXTENSIONS=1
|
|
100
|
+
|
|
101
|
+
[auto]
|
|
102
|
+
# Settings of the `auto` mode. Only this file sets them, never a config inside the project.
|
|
103
|
+
# classifier = "model" # "model" (default): a shell command that the rules cannot judge goes to a
|
|
104
|
+
# # model. It gets your messages of this session and the command, and
|
|
105
|
+
# # answers allow or ask. "rules": no model is called; such a command asks.
|
|
106
|
+
# model = "" # the id of the [model] or [[models]] entry that judges (empty: the model
|
|
107
|
+
# # of the session). A model that thinks before it answers cannot do this
|
|
108
|
+
# # (it has 16 output tokens): every command would ask. An id that no entry
|
|
109
|
+
# # has: Auto says so when it starts (and logs a warning). No model judges,
|
|
110
|
+
# # so such a command asks. Fix the id, or set classifier = "rules".
|
|
111
|
+
# timeout_seconds = 8 # the time that the model has to answer (above 0, at most 120). No answer
|
|
112
|
+
# # in time: you are asked. Three failures in a row stop the model step for
|
|
113
|
+
# # five minutes.
|
|
114
|
+
# extra_roots = [] # absolute folders that count like the project folder
|
|
115
|
+
# protected = [] # more globs that always ask, for example ["deploy/*", "**/secrets/*"].
|
|
116
|
+
# # A glob that starts with **/ matches at any depth below the project.
|
|
117
|
+
# # Built in, at any depth: .husky/*, .githooks/*, .claude/*, .cursor/*,
|
|
118
|
+
# # .mcp.json, .vscode/tasks.json, .github/workflows/*
|
|
119
|
+
# bash_timeout_seconds = 300 # a shell command that Auto let through stops after this time (at most
|
|
120
|
+
# # 2147483; a command that leaves the process group asks) ...
|
|
121
|
+
# bash_max_output_mb = 64 # ... or after it has printed this much
|