Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This document provides foundational context, architectural principles, and opera
- Mitigate Server-Side Request Forgery (SSRF) and network egress risks by validating destination endpoints.
- **Defensive Subprocess Management & Process Group Isolation**:
- When invoking external commands or background workers via `subprocess.Popen`, never terminate processes using simple `proc.kill()`, which leaves spawned subshells as zombies adopted by PID 1.
- Isolate execution into a dedicated POSIX process group (`start_new_session=True` on `subprocess.Popen`) and terminate the entire hierarchy by signalling the group by its id (`os.killpg(proc.pid, signal.SIGTERM)`). See `Shell._terminate_process_group` in `src/devops_cli/ai/harness/shell.py`.
- Isolate execution into a dedicated POSIX process group (`start_new_session=True` on `subprocess.Popen`) and terminate the entire hierarchy by signalling the group by its id (`os.killpg(proc.pid, signal.SIGTERM)`). See `_terminate_process_group` in `src/devops_cli/sandbox/host.py`.
- **Protection Against Container Starvation & Killing**:
- **Prohibition of `RLIMIT_NPROC`**: In Linux, `setrlimit(RLIMIT_NPROC, ...)` applies per-real-UID across the entire container, NOT per-process tree. Setting `RLIMIT_NPROC` inside child hooks or tests starves ambient container processes (VS Code Server, shells), causing `os.fork()` to fail with `EAGAIN`. Never enforce process caps via `RLIMIT_NPROC` or execute fork bombs in tests.
- **Terminal File Descriptor Safety**: Never call `os.set_blocking(fd, False)` or set `O_NONBLOCK` on standard descriptors `{0, 1, 2}`. Setting non-blocking mode on STDOUT/PTY corrupts terminal I/O for VS Code Server.
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/1836.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Removed
- The Pydantic AI Harness port that no command used is deleted: the shell, filesystem, memory, planning, compaction, sub-agent, docs, repo-context and conversation-search modules of `devops_cli.ai.harness`, the coder, researcher, Macroscope and Playwright agents, and the capability clones in `devops_cli.ai.agents.capabilities` that copy what `pydantic_ai.capabilities` already ships. `devops ai harness` is unchanged, the `Skills` capability that nothing built goes with them, and `HarnessExecutionError` and `MemoryOperationConflictError` are gone with their only caller ([#1836](https://github.com/dan-petty/devops-cli/issues/1836)).
2 changes: 0 additions & 2 deletions docs/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ The Exit Code column is the exception's `exit_code` attribute. Only `devops clou
| `GitOperationError` | `GIT_OPERATION_ERROR` | `1` | Git | Base exception for Git repository and branch operation failures. |
| `GitOpsSyncError` | `GITOPS_SYNC_ERROR` | `1` | K8s | Raised when GitOps synchronization trigger or reconciliation fails. |
| `HTTPTimeoutTypeError` | `VALIDATION_ERROR` | `1` | Devops_cli.http.client | Raised when an invalid timeout parameter type is provided. |
| `HarnessExecutionError` | `HARNESS_EXECUTION_ERROR` | `1` | Ai | Raised when execution of an AI test harness or benchmark fails. |
| `HarnessValidationError` | `HARNESS_VALIDATION_ERROR` | `1` | Ai | Raised when an AI evaluation or harness schema validation fails. |
| `IncompleteToolCall` | `INCOMPLETE_TOOL_CALL` | `27` | Ai | Raised when a model stops due to token limit while emitting a tool call. |
| `InsecureConfigError` | `E_INSECURE_CONFIG` | `126` | Security | Raised when an unencrypted plaintext secret token is found in configuration files. |
Expand All @@ -87,7 +86,6 @@ The Exit Code column is the exception's `exit_code` attribute. Only `devops clou
| `LibraryIngestionError` | `LIBRARY_INGESTION_ERROR` | `1` | Ai | Base exception for package introspection and library ingestion errors. |
| `LibraryNotFoundError` | `LIBRARY_NOT_FOUND_ERROR` | `1` | Ai | Raised when target package cannot be imported or found in the environment. |
| `LogfireConfigurationError` | `LOGFIRE_CONFIG_ERROR` | `1` | Telemetry | Raised when Logfire configuration fails or credentials cannot be retrieved. |
| `MemoryOperationConflictError` | `HARNESS_EXECUTION_ERROR` | `1` | Devops_cli.ai.harness.memory | Raised when an optimistic concurrency conflict or duplicate operation occurs in memory store. |
| `MemoryProfilerError` | `PROFILER_ERROR` | `1` | Devops_cli.telemetry.memory_profiler | Domain exception raised when memory profiling target resolution or execution fails. |
| `ModelAPIError` | `MODEL_API_ERROR` | `22` | Ai | Raised when a model provider API request fails. |
| `ModelBundleError` | `MODEL_BUNDLE_ERROR` | `1` | Ai | Raised when an AI model bundle cannot be located, resolved, or loaded. |
Expand Down
2 changes: 0 additions & 2 deletions docs/SELF_IMPROVEMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,6 @@ prompts from two task files that never existed and scored the fix as the code un
The DevSecOps and robustness review session `20260913-231617` produced 13 findings. 11 findings were confirmed and remediated with test-first fixes; 2 findings were classified as false-positive hallucinations and disarmed:

1. **Path Containment & Traversal Hardening**:
- `SqlitePlanStore`: Constrained database paths to project roots, temp paths, or user home; blocked arbitrary system paths.
- `DEVOPS_CLI_CONFIG`: Validated path traversal and forbidden system paths when loading config from environment.
- `run_subprocess` / `run_subprocess_async`: Enforced path containment and system path rejection on caller-supplied `cwd`.
- `devcontainer` mounts: Enforced path traversal checks on volume mount targets.
Expand Down Expand Up @@ -1144,7 +1143,6 @@ The DevSecOps and Architecture review session `20260915-124521` produced 22 find
3. **Symlink Traversal & Path Containment Hardening (CWE-22 / CWE-59)**:
- `argo/gitops.py` (`_scan_directory_manifests`): Explicitly skipped symlinks (`is_symlink()`) and enforced repository root containment (`resolved.is_relative_to(repo_root)`).
- `security/gitleaks.py` (`_resolve_scan_files`): Enforced `_is_safe_file` validation across candidate lists, individual files, and directory trees, skipping symlinks and out-of-bounds files.
- `ai/harness/filesystem.py` (`_list_directory`): Added symlink skipping guard.
- `ai/rag/indexer.py` (`_is_indexable_file`): Skipped symlinks and verified root containment.
- `config/settings.py` (`_find_project_config_path`): Disallowed symlinks and forbidden system paths.

Expand Down
27 changes: 27 additions & 0 deletions docs/agent/tasks/task-1836-unwired-harness-port.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Task: Delete the Unwired Harness Port and the Capability Clones Nothing Imports (#1836)

**Issue**: [#1836](https://github.com/dan-petty/devops-cli/issues/1836)
**Scope**: scope/ai
**Feasibility**: At the base, an AST import graph over `src/devops_cli` (entry points: every `commands/` and `server/` module and `main`) reaches only `ai/harness/slots.py`, `ai/harness/skills.py` and `ai/harness/constants.py`, through `commands/ai_harness.py`. The ten other modules under `ai/harness/` (5,186 lines) load only because `ai/harness/__init__.py` imports them. No `importlib`, `__import__`, entry point or registry names them or the classes in `ai/agents/capabilities.py`: `AgentSpec.capabilities` is an untyped list. A per-symbol scan of `ai/agents/capabilities.py` found importers outside the deleted code for `BaseCapability`, `HandleDeferredToolCalls`, `SystemReminders`, `_accepts_positional_arguments` and the `ToolCallPart`, `DeferredToolRequests`, `DeferredToolResults`, `ToolApproved` and `ToolDenied` re-exports only. The pinned pydantic-ai 2.54.0 already exports `Thinking`, `WebSearch`, `WebFetch`, `MCP`, `NativeTool`, `PrefixTools` and the other clone names from `pydantic_ai.capabilities`, so nothing is lost. After the deletion `ruff check`, `mypy --strict` and the whole collected suite (11,372 tests) import cleanly, and `devops ai harness status` still runs. A `git grep` over `src` found no caller of `is_private_ip_or_localhost`, `format_plan_reminder_as_xml` or `harness.skills.Skills` outside the deleted modules, their own exports and their own tests.

## Description
The harness package was a port of Pydantic AI Harness capabilities (shell, filesystem, memory, planning, compaction, sub-agents, docs, repo context, conversation search, a coder, a researcher, a Macroscope reviewer and a Playwright browser) that no command, server tool or other module used. `ai/agents/capabilities.py` held a second set of unused clones of capabilities that pydantic-ai ships itself. Both are deleted with their tests. No shim replaces them: if the capabilities are wanted later, they come from pydantic-ai or from pydantic-ai-harness, which pins pydantic-ai-slim 2.59.0 against our 2.54.0, so adopting it is a separate dependency decision.

- `ai/harness/` loses `agents.py`, `compaction.py`, `conversation.py`, `docs.py`, `filesystem.py`, `memory.py`, `planning.py`, `repo_context.py`, `shell.py` and `workflow.py`. `__init__.py` exports only what `skills.py` and `slots.py` define. `constants.py` is deleted: its seven prompt constants, command and pattern sets, `HarnessDeprecationWarning` and logger served the deleted modules, and `UNSUPPORTED_BEHAVIORAL_SKILL_FIELDS` served only the `Skills` capability. `skills.py` keeps `ParsedSkill` and `normalize_skill_name`, which `slots.py` uses, and loses the `Skills` capability (nothing in `src` built it), its frontmatter helpers and a second copy of `DEFAULT_PYAI_DOCS_TOPICS`.
- `ai/agents/capabilities.py` keeps `BaseCapability`, `HandleDeferredToolCalls`, `SystemReminders`, `_accepts_positional_arguments` and the five re-exports, and goes from 1,116 lines to 232. `BaseCapability.prefix_tools` and `BaseCapability.with_metadata` go with the clones they returned: `prefix_tools` falls back to the upstream method; `with_metadata` is removed with no replacement. The module docstring and `HandleDeferredToolCalls.handle_deferred` no longer name deleted classes.
- The seven task prompts only `harness/constants.py` loaded are deleted from `ai/tasks/`: `advisor_system`, `summarizing_compaction`, `coder_agent`, `researcher_agent`, `macroscope_guidance`, `planning_guidance` and `playwright_guidance`.
- `HarnessExecutionError` was raised only by `memory.py`. It is deleted with `MemoryOperationConflictError`, `CONST_ERROR_CODE_HARNESS_EXECUTION`, the `CONST_DOMAIN_EXCEPTION_MODULES` entry for the memory module and `CONST_SQLITE_PER_CONNECTION_DATABASES`. `docs/ERRORS.md` is regenerated and loses both rows.
- Sixteen `DEFAULT_*` constants used only by the clones leave `config/defaults.py` and `config/__init__.py`: the three thread-executor settings, the identifiers of the select-model, resolve-model, prepare-tools, prefix-tools, return-schema, tool-metadata, content-filter, reinject-prompt, process-history and process-event-stream clones, `DEFAULT_AGENT_STREAM_EVENT_KIND`, `DEFAULT_THINKING_EFFORT` and `DEFAULT_REASONING_FORMAT`. `DEFAULT_SHELL_BG_OUTPUT_LINES` and `DEFAULT_SHELL_DRAIN_TIMEOUT_SECONDS` go with the shell. `DEFAULT_PLAN_REMINDER_ID` and `DEFAULT_PLAN_REMINDER_CADENCE` stay: `agent.py` and `SystemReminders` use them.
- The shared lists follow the deletion: the harness keys in `tests/fixtures/swallowed_failures_ceilings.json`, the harness paths in the bare-exception list of `tests/test_architectural_invariants.py`, the compaction reset in `tests/conftest.py`, the memory-conflict row `tests/test_docs.py` pinned, and the `harness docs` rows of `tests/test_http_egress.py`. AGENTS.md now names `_terminate_process_group` in `src/devops_cli/sandbox/host.py` as the guarded process-group termination, in place of the deleted `Shell` method. The two bullets of the historical case-study section of `docs/SELF_IMPROVEMENT.md` that described fixes in deleted code are removed.
- Tests: `tests/test_harness.py` is deleted: it exercised the deleted modules and the `Skills` capability, and the `normalize_skill_name` check it held moves to `tests/test_harness_slots.py`, next to the skill slot that calls it. Tests that reached live code only through a clone are rewritten with a `BaseCapability` subclass or `SystemReminders`: the on-demand `load_capability` test in `tests/test_pydantic_agent.py`, the `BaseCapability` subclass test and a new `MCPToolset` test in `tests/test_ai_agent_capabilities.py`, the capability tests of `tests/test_pydantic_ai_native_capabilities.py`, and the `Thinking()` placeholders of `tests/test_ai_agent_deferred_tools.py`. `tests/test_validation.py` keeps the `k8s.domain` and `cloudflare.domain` validation as `test_settings_domain_validation`, the only test of that Settings validation, and drops the clone halves. It also gains `test_settings_domain_refuses_every_spelling_of_the_root_name`, which feeds `@` and the IDNA full stops to the validator branch that rejects the root name. The numbered section comments of the touched test modules are renumbered, and the docstring of `tests/test_subsystem_containment_and_redaction.py` no longer lists the two groups of tests deleted from it.
- Ceilings only go down: `DEFAULT_C901_SUPPRESSION_CEILING` falls from 47 to 28, `src type: ignore` from 89 to 71, `tests type: ignore` from 228 to 139 and `tests noqa: F401` from 4 to 3, the counts the suppression collector of `tests/test_architectural_invariants.py` measures on this tree.
- Orphans of the deletion: `common_tools.is_private_ip_or_localhost` (its only caller was `harness/agents.py`) and `format_prompt.format_plan_reminder_as_xml` (its only caller was `harness/planning.py`) are deleted with the two `DEFAULT_XML_PLAN_REMINDER_*` constants and the test of the formatter. `validate_configured_domain` in `core/dns_names.py` loses its IP-literal early return and its fall-through field label, which only the deleted capability domain lists reached; it now names `k8s.domain` or `cloudflare.domain` from the model title, as the two settings fields are its only users.
- Not done: `common_tools.web_fetch_tool` and `duckduckgo_search_tool` had their callers in the deleted code and are left with none in `src`. So do the other tool factories of `common_tools.py` (`exa_*`, `image_generation_tool`, `x_search_tool`, `tavily_search_tool`), which had none before this change. Deleting the module's tool family takes the untrusted-page renderer, its dependencies and the egress tests of `tests/test_common_tools.py`, `tests/test_native_common_tools.py` and `tests/test_http_egress.py` with it, which is a decision about the whole module, not a part of this deletion. It is [#1854](https://github.com/dan-petty/devops-cli/issues/1854), which reduces `common_tools.py` to `tavily_search`; the dead pydantic_ai facades are [#1852](https://github.com/dan-petty/devops-cli/issues/1852), and the unwired agent extras are part of [#1121](https://github.com/dan-petty/devops-cli/issues/1121).

## Acceptance Criteria
- [x] The ten harness modules and every `ai/agents/capabilities.py` symbol without a caller outside the deleted code are deleted together with their tests, and none is skipped or xfailed. A search of `src`, `tests`, `AGENTS.md`, `README.md` and `docs` (outside `docs/agent/tasks`, `docs/agent/archive` and `CHANGELOG.md`) for the deleted module paths and class names finds nothing.
- [x] The import graph from `commands/`, `server/` and `main` reaches no deleted module, and the deleted modules are absent from the tree afterwards.
- [x] The harness slots, the remaining capability, agent, deferred-tool, export-surface, hygiene and architectural-invariant tests pass, with only tests that referenced deleted names removed or rewritten.
- [x] AGENTS.md names a function that exists as the process-group termination reference, `CONST_DOMAIN_EXCEPTION_MODULES` and the invariants list name no deleted module, the ceilings fixture has no key for a deleted file, and `docs/ERRORS.md` is regenerated and `uv run devops docs check` reports every file up to date.
- [x] `ruff check`, `ruff format --check` and `mypy` pass over `src` and `tests`, and no module under `ai/agents/` or `ai/pydantic_ai_bridge.py` loses covered lines.
- Pending a person: `uv run devops ci` passes on the delivering tree. This change ran the targeted tests and a full-suite coverage run, not the gate.
Loading