Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b40429295c | |||
| 8edb113632 | |||
| df234095b7 | |||
| b64b5e0f6d | |||
| f2d1f4efe7 | |||
| 54fef4768c | |||
| 0461f8e51f | |||
| 5db663cb63 | |||
| ad31e75af6 | |||
| 8384f53e28 | |||
| defa04d56d | |||
| 50d7b02850 | |||
| 89a6817e95 | |||
| 741186cbfb | |||
| b846ab5cd7 | |||
| 1a7cead619 | |||
| 44f9abe5d1 | |||
| 3fb49f16e4 | |||
| c8e713e50b | |||
| 63241f1859 | |||
| e15f26a7bb |
@@ -3,8 +3,6 @@ name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [master, develop]
|
||||
pull_request:
|
||||
branches: [master, develop]
|
||||
|
||||
vars:
|
||||
docker_prefix: "http://harbor.cleverthis.com/docker/"
|
||||
|
||||
@@ -245,6 +245,16 @@ each work group's fetch algorithm:
|
||||
The prompt body to pass to workers you spawn:
|
||||
```
|
||||
Implement or fix the indicated issue or pull request.
|
||||
|
||||
PR Compliance Checklist (MANDATORY — complete ALL items before creating a PR):
|
||||
[ ] 1. CHANGELOG.md — add entry under [Unreleased] section
|
||||
[ ] 2. CONTRIBUTORS.md — add or update contribution entry
|
||||
[ ] 3. Commit footer — include `ISSUES CLOSED: #<issue-number>` in the commit message
|
||||
[ ] 4. CI passes — all quality gates and tests green before requesting review
|
||||
[ ] 5. BDD/Behave tests — added or updated for the changed behaviour
|
||||
[ ] 6. Epic reference — PR description references the parent Epic issue number
|
||||
[ ] 7. Labels — applied via forgejo-label-manager: State/In Review, Priority/<level>, MoSCoW/<level>, Type/<type>
|
||||
[ ] 8. Milestone — PR assigned to the earliest open milestone matching the issue
|
||||
```
|
||||
```
|
||||
|
||||
|
||||
+44
-12
@@ -5,6 +5,21 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`agents project switch` command now implemented** (#8675 / #8623): Added the missing ``switch`` subcommand to the project management CLI group. Previously running ``agents project switch <name>`` resulted in ``Error: No such command 'switch'``. The new command accepts a namespaced project name (e.g. ``local/my-proj``), validates its existence, and persistently records the selection as the active project context for subsequent CLI operations. Supports ``--format`` flag (rich, json, yaml, plain) for output formatting. Full BDD test coverage via ``project_cli_commands.feature`` scenarios included.
|
||||
|
||||
- **Cross-actor subgraph cycle detection reads actor_ref field** (#1431): Fixed
|
||||
`_detect_subgraph_cycles()`, `_map_node()`, and the `compile_actor()` main loop
|
||||
in `src/cleveragents/actor/compiler.py` to read `actor_ref` from the top-level
|
||||
`NodeDefinition.actor_ref` field instead of `node.config.get("actor_ref", "")`.
|
||||
Because `actor_ref` is a typed, validated Pydantic field (not a key inside the
|
||||
untyped `config` dict), the old code always returned an empty string, causing
|
||||
cross-actor cycle detection to silently fail and leaving the system vulnerable to
|
||||
infinite recursion at runtime. Added Behave regression tests
|
||||
(`features/actor_subgraph_cycle_detection.feature`) and a Robot Framework
|
||||
integration test (`robot/actor_compiler.robot`) to prevent regressions.
|
||||
|
||||
### Changed
|
||||
|
||||
- **`agents session list` now displays full 26-character session ULIDs** (#10970): The Rich table
|
||||
@@ -24,6 +39,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
versions (<3.13.4) cannot be installed even if upstream transitive dependencies have loose
|
||||
version constraints.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Implementation Supervisor PR Compliance Checklist** (#9824): Added a mandatory
|
||||
8-item PR Compliance Checklist to the worker prompt body in `implementation-supervisor.md`
|
||||
that every implementation worker must complete before creating a PR. Checklist covers:
|
||||
CHANGELOG.md update, CONTRIBUTORS.md update, commit footer (`ISSUES CLOSED: #N`),
|
||||
CI verification, BDD tests, Epic reference, label application via `forgejo-label-manager`,
|
||||
and milestone assignment. This eliminates systemic PR merge blockers caused by workers
|
||||
omitting required items.
|
||||
|
||||
### Changed
|
||||
|
||||
- Restored `benchmark-regression` CI job to `master.yml` with `pull_request` trigger guard
|
||||
@@ -59,6 +84,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
- `agents actor context clear` command to reset actor message history and
|
||||
state while preserving the underlying context directory via `ContextManager`
|
||||
(#6370).
|
||||
- **Quick Start Guide** (PR #9245): Added `docs/quickstart.md` with an end-to-end quick start guide covering prerequisites, installation, project creation, resource registration, plan/apply workflow, and troubleshooting. Updated `mkdocs.yml` navigation to include the Quick Start page.
|
||||
|
||||
- **Plan checkpoint management CLI commands** (#8683): Added `agents plan checkpoint-list <plan-id>` and `agents plan checkpoint-delete <checkpoint-id>` commands. Listing output now highlights checkpoint ID, type, created timestamp, reason, phase, and decision linkage with a concise field summary footer across rich/table/json/yaml formats. Deletion supports batch IDs, interactive confirmation (skip with `--yes`), and structured JSON/YAML responses for automation-friendly scripting.
|
||||
- **Invariant Remove CLI Command** (#8530): Implemented `agents invariant remove <id>` command that soft-deletes an invariant by ID. The command displays a confirmation prompt before removal (bypassable with `--yes`/`-y`), outputs the removed invariant ID on success, and shows a clear error message when the invariant ID does not exist. Supports `--format` flag for JSON and YAML output. Full BDD test coverage and Robot Framework integration tests included.
|
||||
@@ -87,18 +113,6 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`InvariantService.get_effective_invariants()` adds action_name param for 4-tier merge** (#3128):
|
||||
Added an `action_name: str | None = None` parameter to
|
||||
`InvariantService.get_effective_invariants()`, promoting the invariant precedence chain to
|
||||
four tiers (**plan > action > project > global**) instead of three. The method now filters
|
||||
action-scoped invariants by `action_name` (when provided) and passes them as the second tier
|
||||
to `merge_invariants()`. Updated docstrings, `InvariantScope` documentation, and
|
||||
`InvariantSet.merge()` + `merge_invariants()` signatures across the domain model, service layer,
|
||||
CLI help text, benchmarks, Robot Framework tests, and new BDD scenarios (12 scenarios across
|
||||
`features/invariant_action_scope_effective.feature`) covering all four-precedence paths,
|
||||
deduplication semantics, action-scope filtering, and list_invariants effective-mode
|
||||
passthrough. (#3329)
|
||||
|
||||
- **`LLMTraceRepository.save()` premature commit breaks UnitOfWork transactions** (#7505):
|
||||
Replaced the unconditional `session.commit()` in `LLMTraceRepository.save()` with a
|
||||
dual-path implementation that respects the UnitOfWork (UoW) pattern. When an external
|
||||
@@ -298,6 +312,14 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Added
|
||||
|
||||
- **ACMS Index Data Model and File Traversal Engine** (#9579): Implements the
|
||||
foundational ACMS index data model with structured fields for file metadata
|
||||
(path, size, last modified, type), tag system, and hot/warm/cold/archive
|
||||
storage tier assignment. Introduces a timeout-safe large-project file traversal
|
||||
engine capable of handling 10,000+ files without memory exhaustion through
|
||||
chunked processing. Provides a complete index entry pipeline for creation,
|
||||
storage, and retrieval with full queryability by path, tag, type, and recency.
|
||||
|
||||
- **ACMS Large-Project Indexing BDD Coverage** (#8726): Added 7 Behave scenarios
|
||||
covering walk-based indexing of 10,000+ files without timeout, binary-file
|
||||
skipping, oversized-file skipping, git-checkout indexing, fallback to walk when
|
||||
@@ -306,6 +328,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
syscalls). Added `timeout=120` to git subprocess calls to prevent CI hangs.
|
||||
Cached `get_scoped_view` results in `When` steps to avoid redundant re-queries
|
||||
in `Then` steps.
|
||||
|
||||
- **Agent Evolution Pool Supervisor PR Metadata Assignment** (#7888): The
|
||||
agent-evolution-pool-supervisor now automatically looks up the Type/Automation
|
||||
label and the earliest open milestone from the repository before dispatching
|
||||
@@ -612,6 +635,15 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
response format from the OpenCode API `/session/status` endpoint instead of an array.
|
||||
Workers now dispatch and verify correctly, preventing incorrect session deletion.
|
||||
|
||||
---
|
||||
### Fixed
|
||||
|
||||
- **CLI (`agents actor remove`)** (#6491): Restores output parity with the
|
||||
other actor commands by honoring `--format`/`-f` for JSON/YAML/plain/Rich
|
||||
envelopes. Adds a Robot Framework regression test to assert the JSON
|
||||
envelope structure and updates the CLI synopsis in `docs/specification.md`
|
||||
to document the option.
|
||||
|
||||
---
|
||||
|
||||
## [3.8.0] -- 2026-04-05
|
||||
|
||||
+3
-3
@@ -7,7 +7,6 @@
|
||||
* Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
|
||||
* Luis Mendes <luis.p.mendes@gmail.com>
|
||||
* Rui Hu <rui.hu@cleverthis.com>
|
||||
* HAL 9000 <hal9000@cleverthis.com>
|
||||
|
||||
# Details
|
||||
|
||||
@@ -28,7 +27,8 @@ Below are some of the specific details of various contributions.
|
||||
* HAL 9000 has contributed the architecture-pool-supervisor milestone assignment feature (PR #8188 / issue #7521): added `forgejo_update_pull_request` permission and documented the PR workflow for major spec changes, enabling automatic milestone assignment for specification PRs.
|
||||
* HAL 9000 has contributed the git worktree TOCTOU race condition fix (PR #8178 / issue #7507): replaced the unsafe mkdtemp() + rmdir() pattern with a parent-directory approach to eliminate the race window in concurrent git worktree operations.
|
||||
* HAL 9000 has contributed the git_tools TOCTOU race condition fix (PR #8255 / issue #7619): eliminated the Time-Of-Check-To-Time-Of-Use race in `_get_base_env()` by adding double-checked locking with a module-level `threading.Lock`, preventing concurrent threads from writing conflicting environment snapshots.
|
||||
* HAL 9000 has contributed the mandatory PR compliance checklist to `implementation-supervisor.md` (#9824): added an 8-item checklist to the worker prompt body with concrete items covering CHANGELOG.md, CONTRIBUTORS.md, commit footer, CI verification, BDD tests, Epic reference, labels, and milestone assignment to eliminate systemic PR merge blockers.
|
||||
* HAL 9000 has contributed comprehensive milestone documentation for v3.6.0 (Advanced Concepts & Deferred Features) and v3.7.0 (TUI Implementation) (PR #9903): split into sub-documents covering context strategies, LLM backends, resource types, A2A rename, container tool execution, scope chain resolution, cost/safety budgets, E2E workflow tests, code review examples, plugin architecture, TUI layout, persona system, reference/command input, session management, configuration, and TuiMaterializer integration.
|
||||
* HAL 9000 has contributed the LLMTraceRepository data-integrity fix (PR #8185 / issue #7505): replaced the unconditional `session.commit()` in `LLMTraceRepository.save()` with a dual-path implementation that respects the UnitOfWork pattern — flushing only when an external session is provided, and flushing + committing + closing when operating standalone. This eliminates premature transaction commits, loss of rollback capability, and a docstring/implementation mismatch.
|
||||
|
||||
* HAL 9000 has contributed the invariant action-scope 4-tier merge fix (PR #3329 / issue #3128): added `action_name` parameter to `InvariantService.get_effective_invariants()`, promoted the invariant precedence chain from 3-tier (plan > project > global) to 4-tier (plan > action > project > global), updated `merge_invariants()` and `InvariantSet.merge()` signatures, refreshed CLI documentation, benchmarks, Robot Framework tests, and added 13 BDD scenarios covering 4-tier precedence, deduplication semantics, and action-scope filtering.
|
||||
* HAL 9000 has contributed the ACMS Index Data Model and File Traversal Engine (PR #9664 / issue #9579): foundational data structures for indexed context entries with hot/warm/cold/archive storage tier classification, tag system, and a timeout-safe chunked file traversal engine for large projects with 10,000+ files.
|
||||
* HAL 9000 has contributed the `agents project switch` CLI command (#8675 / #8623): implemented the ``switch`` subcommand for the project management group, enabling users to select a namespaced project as their active context from any working directory. Includes BDD test scenarios and proper error handling for non-existent projects.
|
||||
|
||||
@@ -74,7 +74,7 @@ class MergeSmallSuite:
|
||||
|
||||
def time_merge_small(self) -> None:
|
||||
"""Benchmark merge with ~13 invariants."""
|
||||
merge_invariants(self.plan, [], self.project, self.global_invs)
|
||||
merge_invariants(self.plan, self.project, self.global_invs)
|
||||
|
||||
|
||||
class MergeMediumSuite:
|
||||
@@ -88,7 +88,7 @@ class MergeMediumSuite:
|
||||
|
||||
def time_merge_medium(self) -> None:
|
||||
"""Benchmark merge with ~50 invariants."""
|
||||
merge_invariants(self.plan, [], self.project, self.global_invs)
|
||||
merge_invariants(self.plan, self.project, self.global_invs)
|
||||
|
||||
|
||||
class MergeLargeSuite:
|
||||
@@ -102,7 +102,7 @@ class MergeLargeSuite:
|
||||
|
||||
def time_merge_large(self) -> None:
|
||||
"""Benchmark merge with ~250 invariants."""
|
||||
merge_invariants(self.plan, [], self.project, self.global_invs)
|
||||
merge_invariants(self.plan, self.project, self.global_invs)
|
||||
|
||||
|
||||
class MergeDeduplicationSuite:
|
||||
@@ -137,7 +137,7 @@ class MergeDeduplicationSuite:
|
||||
|
||||
def time_merge_dedup(self) -> None:
|
||||
"""Benchmark merge with 60 invariants, all duplicates."""
|
||||
merge_invariants(self.plan, [], self.project, self.global_invs)
|
||||
merge_invariants(self.plan, self.project, self.global_invs)
|
||||
|
||||
|
||||
class InvariantSetMergeSuite:
|
||||
@@ -151,7 +151,7 @@ class InvariantSetMergeSuite:
|
||||
|
||||
def time_invariant_set_merge(self) -> None:
|
||||
"""Benchmark InvariantSet.merge()."""
|
||||
InvariantSet.merge(self.plan, [], self.project, self.global_invs)
|
||||
InvariantSet.merge(self.plan, self.project, self.global_invs)
|
||||
|
||||
|
||||
class ServiceEffectiveSuite:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# Quick Start Guide
|
||||
|
||||
This quick start guide will walk you through creating a new project, registering a resource, running a plan, and applying changes with CleverAgents.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Python 3.11+ and virtualenv
|
||||
- Git
|
||||
- A working CleverAgents installation (see development/testing.md for details)
|
||||
|
||||
## Install (local development)
|
||||
|
||||
```bash
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -e .[dev]
|
||||
```
|
||||
|
||||
## Create a new project
|
||||
|
||||
```bash
|
||||
# Create a new directory for your project
|
||||
mkdir my-project && cd my-project
|
||||
# Initialize a CleverAgents project (example command)
|
||||
cleveragents init --name my-project
|
||||
```
|
||||
|
||||
## Register a resource
|
||||
|
||||
Create a resource file under `resources/` (example YAML) and register it with the CLI or API.
|
||||
|
||||
## Plan and apply
|
||||
|
||||
```bash
|
||||
# Create a plan using an action on your project
|
||||
cleveragents plan use <action-name> --project my-project
|
||||
# List plans to find the plan ID
|
||||
cleveragents plan list
|
||||
# Review the plan, then apply it by plan ID
|
||||
cleveragents plan apply <plan-id>
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter issues running the examples above, consult `docs/development/testing.md` and the project README for local development tips.
|
||||
@@ -277,7 +277,7 @@ The following standards are integrated into the architecture:
|
||||
[(<span style="color: magenta;"><span style="color: cyan;">--temperature</span>|<span style="color: yellow;">-t</span></span>) <span style="color: #66cc66;"><TEMP></span>] [<span style="color: cyan;">--allow-rxpy-in-run-mode</span>]
|
||||
[<span style="color: cyan;">--skill</span> <span style="color: #66cc66;"><SKILL></span>]... <span style="color: #66cc66;"><NAME></span> <span style="color: #66cc66;"><PROMPT></span>
|
||||
<span style="color: cyan; font-weight: 600;">agents</span> actor add <span style="color: cyan;">--config</span>|<span style="color: yellow;">-c</span> <span style="color: #66cc66;"><FILE></span> [<span style="color: cyan;">--update</span>]
|
||||
<span style="color: cyan; font-weight: 600;">agents</span> actor remove <span style="color: #66cc66;"><NAME></span>
|
||||
<span style="color: cyan; font-weight: 600;">agents</span> actor remove [<span style="color: cyan;">--format</span> <span style="color: #66cc66;"><FORMAT></span>] <span style="color: #66cc66;"><NAME></span>
|
||||
<span style="color: cyan; font-weight: 600;">agents</span> actor list
|
||||
<span style="color: cyan; font-weight: 600;">agents</span> actor show <span style="color: #66cc66;"><NAME></span>
|
||||
<span style="color: cyan; font-weight: 600;">agents</span> actor context remove [<span style="color: cyan;">--yes</span>|<span style="color: yellow;">-y</span>] (<span style="color: magenta;"><span style="color: cyan;">--all</span>|<span style="color: yellow;">-a</span>|<span style="color: #66cc66;"><NAME></span></span>)
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
Feature: ACMS Index Data Model and File Traversal Engine
|
||||
As a developer
|
||||
I want to index large projects with 10,000+ files
|
||||
So that I can efficiently query and manage context entries at scale
|
||||
|
||||
Background:
|
||||
Given I have an ACMS index
|
||||
And I have a file traversal engine with chunk size 100
|
||||
|
||||
Scenario: Create an index entry with file metadata
|
||||
When I create an index entry with:
|
||||
| path | /project/src/main.py |
|
||||
| file_type | python |
|
||||
| size_bytes | 1024 |
|
||||
Then the index entry should have path "/project/src/main.py"
|
||||
And the index entry should have file type "python"
|
||||
And the index entry should have size 1024 bytes
|
||||
|
||||
Scenario: Add tags to an index entry
|
||||
Given I have an index entry with path "/project/src/main.py"
|
||||
When I add tag "core" to the entry
|
||||
And I add tag "important" to the entry
|
||||
Then the entry should have tag "core"
|
||||
And the entry should have tag "important"
|
||||
And the entry should have 2 tags
|
||||
|
||||
Scenario: Set tier level for an index entry
|
||||
Given I have an index entry with path "/project/src/main.py"
|
||||
When I set the tier level to "hot"
|
||||
Then the entry should have tier level "hot"
|
||||
|
||||
Scenario: Add entry to index
|
||||
Given I have an index entry with path "/project/src/main.py"
|
||||
When I add the entry to the index
|
||||
Then the index should contain 1 entry
|
||||
And I should be able to retrieve the entry by path "/project/src/main.py"
|
||||
|
||||
Scenario: Query index by path pattern
|
||||
Given I have an index with entries:
|
||||
| path | file_type |
|
||||
| /project/src/main.py | python |
|
||||
| /project/src/utils.py | python |
|
||||
| /project/tests/test_main.py | python |
|
||||
| /project/docs/readme.md | markdown |
|
||||
When I query the index by path pattern "src"
|
||||
Then I should get 2 results
|
||||
And the results should include "/project/src/main.py"
|
||||
And the results should include "/project/src/utils.py"
|
||||
|
||||
Scenario: Query index by file type
|
||||
Given I have an index with entries:
|
||||
| path | file_type |
|
||||
| /project/src/main.py | python |
|
||||
| /project/src/utils.py | python |
|
||||
| /project/src/app.js | javascript |
|
||||
| /project/docs/readme.md | markdown |
|
||||
When I query the index by file type "python"
|
||||
Then I should get 2 results
|
||||
And all results should have file type "python"
|
||||
|
||||
Scenario: Query index by tag
|
||||
Given I have an index with entries:
|
||||
| path | tags |
|
||||
| /project/src/main.py | core,important |
|
||||
| /project/src/utils.py | supporting |
|
||||
| /project/tests/test_main.py | test,important |
|
||||
When I query the index by tag "important"
|
||||
Then I should get 2 results
|
||||
And the results should include "/project/src/main.py"
|
||||
And the results should include "/project/tests/test_main.py"
|
||||
|
||||
Scenario: Query index by tier level
|
||||
Given I have an index with entries:
|
||||
| path | tier |
|
||||
| /project/src/main.py | hot |
|
||||
| /project/src/utils.py | warm |
|
||||
| /project/tests/test_main.py | cold |
|
||||
When I query the index by tier level "hot"
|
||||
Then I should get 1 result
|
||||
And the result should have path "/project/src/main.py"
|
||||
|
||||
Scenario: Query index by recency
|
||||
Given I have an index with entries from different dates
|
||||
When I query the index for entries modified after "2026-04-01"
|
||||
Then I should get entries modified after that date
|
||||
|
||||
Scenario: Traverse and index a directory with multiple files
|
||||
Given I have a test directory with 50 files
|
||||
When I traverse and index the directory
|
||||
Then the index should contain 50 entries
|
||||
And all entries should have valid file paths
|
||||
|
||||
Scenario: Handle large project traversal with chunked processing
|
||||
Given I have a test directory with 1000 files
|
||||
When I traverse and index the directory with chunk size 100
|
||||
Then the index should contain 1000 entries
|
||||
And the traversal should complete without timeout
|
||||
|
||||
Scenario: Exclude patterns during traversal
|
||||
Given I have a test directory with files including:
|
||||
| path |
|
||||
| /project/src/main.py |
|
||||
| /project/.git/config |
|
||||
| /project/__pycache__/main.cpython-39.pyc |
|
||||
| /project/src/utils.py |
|
||||
When I traverse and index the directory excluding ".git" and "__pycache__"
|
||||
Then the index should contain 2 entries
|
||||
And the index should not contain ".git" paths
|
||||
And the index should not contain "__pycache__" paths
|
||||
|
||||
Scenario: Get all entries from index
|
||||
Given I have an index with 5 entries
|
||||
When I get all entries from the index
|
||||
Then I should get 5 results
|
||||
|
||||
Scenario: Get entry count from index
|
||||
Given I have an index with 10 entries
|
||||
When I get the entry count
|
||||
Then the count should be 10
|
||||
|
||||
Scenario: Remove entry from index
|
||||
Given I have an index with 3 entries
|
||||
When I remove an entry by path
|
||||
Then the index should contain 2 entries
|
||||
|
||||
Scenario: Combined query with multiple filters
|
||||
Given I have an index with entries:
|
||||
| path | file_type | tags | tier |
|
||||
| /project/src/main.py | python | core,important | hot |
|
||||
| /project/src/utils.py | python | supporting | warm |
|
||||
| /project/tests/test_main.py | python | test | cold |
|
||||
| /project/docs/readme.md | markdown | docs | cold |
|
||||
When I query the index with filters:
|
||||
| path_pattern | src |
|
||||
| file_type | python |
|
||||
| tier | hot |
|
||||
Then I should get 1 result
|
||||
And the result should have path "/project/src/main.py"
|
||||
@@ -59,6 +59,11 @@ Feature: Actor CLI YAML-first alignment
|
||||
When I run actor remove with namespaced name
|
||||
Then the actor remove should succeed for namespaced name
|
||||
|
||||
Scenario: Actor remove outputs JSON format
|
||||
Given an actor CLI runner
|
||||
When I run actor remove with format json
|
||||
Then the actor remove output should be valid JSON envelope
|
||||
|
||||
Scenario: Actor update outputs JSON format
|
||||
Given an actor CLI runner
|
||||
When I run actor update with format json
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
Feature: Cross-actor subgraph cycle detection reads actor_ref field
|
||||
As a CleverAgents developer
|
||||
I want the actor compiler to correctly detect cross-actor subgraph cycles
|
||||
So that mutually-referencing actors raise SubgraphCycleError at compile time
|
||||
|
||||
Background:
|
||||
Given the actor compiler is available
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# Bug fix: actor_ref is a top-level NodeDefinition field
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
@tdd_issue @tdd_issue_1431
|
||||
Scenario: Mutually-referencing actors raise SubgraphCycleError
|
||||
Given actor "test/actor-a" has a subgraph node with actor_ref "test/actor-b"
|
||||
And actor "test/actor-b" has a subgraph node with actor_ref "test/actor-a"
|
||||
And a registry containing both actors
|
||||
When I compile actor "test/actor-a" with the registry resolver
|
||||
Then the compilation should raise SubgraphCycleError
|
||||
And the cycle error message should mention "cycle"
|
||||
|
||||
@tdd_issue @tdd_issue_1431
|
||||
Scenario: Non-cyclic subgraph reference compiles successfully
|
||||
Given actor "test/actor-x" has a subgraph node with actor_ref "test/actor-y"
|
||||
And actor "test/actor-y" has no subgraph nodes
|
||||
And a registry containing both actors
|
||||
When I compile actor "test/actor-x" with the registry resolver
|
||||
Then the actor compilation should succeed
|
||||
And the actor subgraph_refs should map "sub" to "test/actor-y"
|
||||
|
||||
@tdd_issue @tdd_issue_1431
|
||||
Scenario: Subgraph node actor_ref is reflected in compiled metadata
|
||||
Given actor "test/actor-p" has a subgraph node with actor_ref "test/actor-q"
|
||||
And actor "test/actor-q" has no subgraph nodes
|
||||
And a registry containing both actors
|
||||
When I compile actor "test/actor-p" with the registry resolver
|
||||
Then the actor compilation should succeed
|
||||
And the compiled node "sub" should have subgraph set to "test/actor-q"
|
||||
@@ -686,6 +686,12 @@ def after_scenario(context, scenario):
|
||||
pass # Ignore cleanup errors
|
||||
context.test_dir = None
|
||||
|
||||
# Clean up TemporaryDirectory objects created by ACMS index traversal tests
|
||||
if hasattr(context, "temp_dir") and context.temp_dir is not None:
|
||||
with contextlib.suppress(Exception):
|
||||
context.temp_dir.cleanup()
|
||||
context.temp_dir = None
|
||||
|
||||
# Clean up environment variables set during tests
|
||||
if hasattr(context, "env_vars_to_clean"):
|
||||
for key in context.env_vars_to_clean:
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
# BDD scenarios for issue #3128 — action-scoped invariants in get_effective_invariants()
|
||||
#
|
||||
# Verifies that InvariantService.get_effective_invariants() correctly includes
|
||||
# action-scoped invariants in the 4-tier precedence merge:
|
||||
# plan > action > project > global
|
||||
#
|
||||
# Also verifies that merge_invariants() and InvariantSet.merge() accept and
|
||||
# correctly process the action_invariants parameter.
|
||||
#
|
||||
# See: https://git.cleverthis.com/cleveragents/cleveragents-core/issues/3128
|
||||
|
||||
Feature: Action-scoped invariants included in effective invariant computation
|
||||
As a developer using InvariantService
|
||||
I want get_effective_invariants() to include action-scoped invariants
|
||||
So that the 4-tier precedence chain (plan > action > project > global) is fully enforced
|
||||
|
||||
# ================================================================
|
||||
# get_effective_invariants() — action_name parameter
|
||||
# ================================================================
|
||||
|
||||
Scenario: get_effective_invariants returns action-scoped invariants when action_name provided
|
||||
Given an invariant service with action and global invariants
|
||||
When I get effective invariants with action_name "deploy-service"
|
||||
Then the effective set should contain the action invariant "Do not modify public API"
|
||||
And the effective set should contain the global invariant "Log all changes"
|
||||
And the effective set should have 2 invariants
|
||||
|
||||
Scenario: get_effective_invariants includes all action invariants when action_name is None
|
||||
Given an invariant service with action and global invariants
|
||||
When I get effective invariants with no action_name
|
||||
Then the effective set should contain the action invariant "Do not modify public API"
|
||||
And the effective set should contain the global invariant "Log all changes"
|
||||
And the effective set should have 2 invariants
|
||||
|
||||
Scenario: get_effective_invariants with all four scopes returns all invariants
|
||||
Given an invariant service with invariants at all four scopes
|
||||
When I get effective invariants for plan "plan-001" action "deploy-service" and project "myapp"
|
||||
Then the effective set should have 4 invariants
|
||||
And the effective set should contain the plan invariant "Plan-level rule"
|
||||
And the effective set should contain the action invariant "Action-level rule"
|
||||
And the effective set should contain the project invariant "Project-level rule"
|
||||
And the effective set should contain the global invariant "Global-level rule"
|
||||
|
||||
Scenario: Action invariants have higher precedence than project invariants
|
||||
Given an invariant service with action and project invariants having the same text
|
||||
When I get effective invariants for plan "plan-001" action "deploy-service" and project "myapp"
|
||||
Then the effective set should have 1 invariant
|
||||
And the first effective invariant should have scope "action"
|
||||
|
||||
Scenario: Plan invariants have higher precedence than action invariants
|
||||
Given an invariant service with plan and action invariants having the same text
|
||||
When I get effective invariants for plan "plan-001" action "deploy-service" and project "myapp"
|
||||
Then the effective set should have 1 invariant
|
||||
And the first effective invariant should have scope "plan"
|
||||
|
||||
Scenario: get_effective_invariants filters action invariants by action_name
|
||||
Given an invariant service with two different action invariants
|
||||
When I get effective invariants with action_name "deploy-service"
|
||||
Then the effective set should contain the action invariant "Deploy constraint"
|
||||
And the effective set should not contain the action invariant "Build constraint"
|
||||
And the effective set should have 1 invariant
|
||||
|
||||
# ================================================================
|
||||
# list_invariants(effective=True) — action scope passthrough
|
||||
# ================================================================
|
||||
|
||||
Scenario: list_invariants with effective=True and action scope passes action_name
|
||||
Given an invariant service with action and global invariants
|
||||
When I list invariants with effective True and action scope "deploy-service"
|
||||
Then the listed effective set should contain the action invariant "Do not modify public API"
|
||||
And the listed effective set should contain the global invariant "Log all changes"
|
||||
|
||||
# ================================================================
|
||||
# merge_invariants() — 4-tier signature
|
||||
# ================================================================
|
||||
|
||||
Scenario: merge_invariants accepts action_invariants as second parameter
|
||||
Given I have plan action project and global invariant lists
|
||||
When I merge all four invariant tiers
|
||||
Then the merged result should have 4 invariants
|
||||
And the merged result should contain "Plan rule"
|
||||
And the merged result should contain "Action rule"
|
||||
And the merged result should contain "Project rule"
|
||||
And the merged result should contain "Global rule"
|
||||
|
||||
Scenario: merge_invariants deduplicates action invariants by text
|
||||
Given I have overlapping action and project invariant lists
|
||||
When I merge all four invariant tiers
|
||||
Then the merged result should have 1 invariant
|
||||
And the first merged invariant should have scope "action"
|
||||
|
||||
Scenario: merge_invariants with empty action list behaves like 3-tier merge
|
||||
Given I have plan project and global invariant lists with no action invariants
|
||||
When I merge all four invariant tiers with empty action list
|
||||
Then the merged result should have 3 invariants
|
||||
|
||||
# ================================================================
|
||||
# InvariantSet.merge() — 4-tier signature
|
||||
# ================================================================
|
||||
|
||||
Scenario: InvariantSet.merge accepts action_invariants as second parameter
|
||||
Given I have plan action project and global invariant lists
|
||||
When I merge all four tiers using InvariantSet
|
||||
Then the invariant set should have 4 invariants
|
||||
|
||||
Scenario: InvariantSet.merge with empty action list produces correct result
|
||||
Given I have plan project and global invariant lists with no action invariants
|
||||
When I merge all four tiers using InvariantSet with empty action list
|
||||
Then the invariant set should have 3 invariants
|
||||
@@ -0,0 +1,58 @@
|
||||
@mock_only
|
||||
Feature: PR Compliance Checklist in Implementation Supervisor
|
||||
|
||||
As an implementation supervisor
|
||||
I want to pass a mandatory PR compliance checklist to every worker prompt
|
||||
So that workers complete all required items before creating a PR and avoid systemic merge blockers
|
||||
|
||||
Background:
|
||||
Given the implementation-supervisor.md agent definition exists
|
||||
|
||||
Scenario: Supervisor worker prompt includes the PR compliance checklist
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes the PR compliance checklist section
|
||||
And the checklist is marked as MANDATORY
|
||||
|
||||
Scenario: Checklist item 1 — CHANGELOG.md update required
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a CHANGELOG.md checklist item
|
||||
And the item instructs workers to add an entry under the Unreleased section
|
||||
|
||||
Scenario: Checklist item 2 — CONTRIBUTORS.md update required
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a CONTRIBUTORS.md checklist item
|
||||
And the item instructs workers to add or update their contribution entry
|
||||
|
||||
Scenario: Checklist item 3 — commit footer required
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a commit footer checklist item
|
||||
And the item specifies the ISSUES CLOSED footer format
|
||||
|
||||
Scenario: Checklist item 4 — CI must pass before PR creation
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a CI passes checklist item
|
||||
And the item instructs workers to verify all quality gates are green
|
||||
|
||||
Scenario: Checklist item 5 — BDD/Behave tests required
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a BDD tests checklist item
|
||||
And the item instructs workers to add or update Behave feature files
|
||||
|
||||
Scenario: Checklist item 6 — Epic reference required in PR description
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes an Epic reference checklist item
|
||||
And the item instructs workers to reference the parent Epic issue number
|
||||
|
||||
Scenario: Checklist item 7 — Labels must be applied
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a labels checklist item
|
||||
And the item instructs workers to apply labels via forgejo-label-manager
|
||||
|
||||
Scenario: Checklist item 8 — Milestone must be assigned
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body includes a milestone checklist item
|
||||
And the item instructs workers to assign the earliest open milestone
|
||||
|
||||
Scenario: All 8 checklist items are present in the worker prompt
|
||||
When I read the implementation supervisor agent definition
|
||||
Then the worker prompt body contains all 8 mandatory checklist items
|
||||
@@ -224,3 +224,27 @@ Feature: Project CLI command functions coverage
|
||||
When I invoke project-delete for "local/del-sf" with yes and short force flag
|
||||
Then the project cmd output should contain "deleted"
|
||||
And the project cmd should succeed
|
||||
|
||||
# ── switch command (#8623 / #8675) ────────────────────────
|
||||
|
||||
Scenario: switch command in rich format switches active project
|
||||
Given a project "local/switch-test" is created in the commands DB
|
||||
When I invoke project-switch for "local/switch-test" default format
|
||||
Then the project cmd output should contain "switched to"
|
||||
And the project cmd should succeed
|
||||
|
||||
Scenario: switch command with json format returns project data
|
||||
Given a project "local/switch-json" is created in the commands DB
|
||||
When I invoke project-switch for "local/switch-json" format "json"
|
||||
Then the project cmd output should contain "namespaced_name"
|
||||
And the project cmd should succeed
|
||||
|
||||
Scenario: switch command with yaml format returns project data
|
||||
Given a project "local/switch-yaml" is created in the commands DB
|
||||
When I invoke project-switch for "local/switch-yaml" format "yaml"
|
||||
Then the project cmd output should contain "namespaced_name"
|
||||
And the project cmd should succeed
|
||||
|
||||
Scenario: switch command for nonexistent project fails
|
||||
When I invoke project-switch for "local/no-such-proj" default format
|
||||
Then the project cmd should fail
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
"""Step definitions for ACMS Index Data Model and File Traversal Engine tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from behave import given, then, when
|
||||
|
||||
from cleveragents.acms.index import (
|
||||
ACMSIndex,
|
||||
FileTraversalEngine,
|
||||
FileType,
|
||||
IndexEntry,
|
||||
TierLevel,
|
||||
)
|
||||
|
||||
|
||||
@given("I have an ACMS index")
|
||||
def step_create_index(context):
|
||||
"""Create a new ACMS index."""
|
||||
context.index = ACMSIndex()
|
||||
|
||||
|
||||
@given("I have a file traversal engine with chunk size {chunk_size:d}")
|
||||
def step_create_traversal_engine(context, chunk_size):
|
||||
"""Create a file traversal engine with specified chunk size."""
|
||||
context.engine = FileTraversalEngine(chunk_size=chunk_size)
|
||||
|
||||
|
||||
@when("I create an index entry with:")
|
||||
def step_create_index_entry(context):
|
||||
"""Create an index entry from table data."""
|
||||
data = {row["key"]: row["value"] for row in context.table}
|
||||
|
||||
file_type = FileType(data.get("file_type", "other"))
|
||||
size_bytes = int(data.get("size_bytes", "0"))
|
||||
|
||||
context.entry = IndexEntry(
|
||||
path=data["path"],
|
||||
file_type=file_type,
|
||||
size_bytes=size_bytes,
|
||||
created_at=datetime.now(),
|
||||
modified_at=datetime.now(),
|
||||
)
|
||||
|
||||
|
||||
@then('the index entry should have path "{path}"')
|
||||
def step_check_entry_path(context, path):
|
||||
"""Verify the index entry has the expected path."""
|
||||
assert context.entry.path == path
|
||||
|
||||
|
||||
@then('the index entry should have file type "{file_type}"')
|
||||
def step_check_entry_file_type(context, file_type):
|
||||
"""Verify the index entry has the expected file type."""
|
||||
assert context.entry.file_type == FileType(file_type)
|
||||
|
||||
|
||||
@then("the index entry should have size {size:d} bytes")
|
||||
def step_check_entry_size(context, size):
|
||||
"""Verify the index entry has the expected size."""
|
||||
assert context.entry.size_bytes == size
|
||||
|
||||
|
||||
@given('I have an index entry with path "{path}"')
|
||||
def step_create_entry_with_path(context, path):
|
||||
"""Create an index entry with a specific path."""
|
||||
context.entry = IndexEntry(
|
||||
path=path,
|
||||
file_type=FileType.PYTHON,
|
||||
size_bytes=1024,
|
||||
created_at=datetime.now(),
|
||||
modified_at=datetime.now(),
|
||||
)
|
||||
|
||||
|
||||
@when('I add tag "{tag}" to the entry')
|
||||
def step_add_tag_to_entry(context, tag):
|
||||
"""Add a tag to the current entry."""
|
||||
context.entry.add_tag(tag)
|
||||
|
||||
|
||||
@then('the entry should have tag "{tag}"')
|
||||
def step_check_entry_has_tag(context, tag):
|
||||
"""Verify the entry has a specific tag."""
|
||||
assert context.entry.has_tag(tag)
|
||||
|
||||
|
||||
@then("the entry should have {count:d} tags")
|
||||
def step_check_entry_tag_count(context, count):
|
||||
"""Verify the entry has the expected number of tags."""
|
||||
assert len(context.entry.tags) == count
|
||||
|
||||
|
||||
@when('I set the tier level to "{tier}"')
|
||||
def step_set_entry_tier(context, tier):
|
||||
"""Set the tier level for the entry."""
|
||||
context.entry.set_tier(TierLevel(tier))
|
||||
|
||||
|
||||
@then('the entry should have tier level "{tier}"')
|
||||
def step_check_entry_tier(context, tier):
|
||||
"""Verify the entry has the expected tier level."""
|
||||
assert context.entry.tier == TierLevel(tier)
|
||||
|
||||
|
||||
@when("I add the entry to the index")
|
||||
def step_add_entry_to_index(context):
|
||||
"""Add the current entry to the index."""
|
||||
context.index.add_entry(context.entry)
|
||||
|
||||
|
||||
@then("the index should contain {count:d} entry")
|
||||
def step_check_index_entry_count_singular(context, count):
|
||||
"""Verify the index has the expected number of entries."""
|
||||
assert context.index.get_entry_count() == count
|
||||
|
||||
|
||||
@then("the index should contain {count:d} entries")
|
||||
def step_check_index_entry_count(context, count):
|
||||
"""Verify the index has the expected number of entries."""
|
||||
assert context.index.get_entry_count() == count
|
||||
|
||||
|
||||
@then('I should be able to retrieve the entry by path "{path}"')
|
||||
def step_retrieve_entry_by_path(context, path):
|
||||
"""Verify we can retrieve an entry by path."""
|
||||
entry = context.index.get_entry(path)
|
||||
assert entry is not None
|
||||
assert entry.path == path
|
||||
|
||||
|
||||
@given("I have an index with entries:")
|
||||
def step_create_index_with_entries(context):
|
||||
"""Create an index with multiple entries from table data."""
|
||||
context.index = ACMSIndex()
|
||||
|
||||
for row in context.table:
|
||||
path = row["path"]
|
||||
file_type = FileType(row.get("file_type", "other"))
|
||||
|
||||
entry = IndexEntry(
|
||||
path=path,
|
||||
file_type=file_type,
|
||||
size_bytes=1024,
|
||||
created_at=datetime.now(),
|
||||
modified_at=datetime.now(),
|
||||
)
|
||||
|
||||
# Add tags if present
|
||||
if "tags" in row:
|
||||
for tag in row["tags"].split(","):
|
||||
entry.add_tag(tag.strip())
|
||||
|
||||
# Set tier if present
|
||||
if "tier" in row:
|
||||
entry.set_tier(TierLevel(row["tier"]))
|
||||
|
||||
context.index.add_entry(entry)
|
||||
|
||||
|
||||
@given("I have an index with {count:d} entries")
|
||||
def step_create_index_with_n_entries(context, count):
|
||||
"""Create an index with a specified number of entries."""
|
||||
context.index = ACMSIndex()
|
||||
for i in range(count):
|
||||
entry = IndexEntry(
|
||||
path=f"/project/file{i}.py",
|
||||
file_type=FileType.PYTHON,
|
||||
size_bytes=1024,
|
||||
created_at=datetime.now(),
|
||||
modified_at=datetime.now(),
|
||||
)
|
||||
context.index.add_entry(entry)
|
||||
|
||||
|
||||
@when('I query the index by path pattern "{pattern}"')
|
||||
def step_query_by_path_pattern(context, pattern):
|
||||
"""Query the index by path pattern."""
|
||||
context.query_results = context.index.query_by_path(pattern)
|
||||
|
||||
|
||||
@then("I should get {count:d} results")
|
||||
def step_check_query_result_count(context, count):
|
||||
"""Verify the query returned the expected number of results."""
|
||||
assert len(context.query_results) == count, (
|
||||
f"Expected {count} results, got {len(context.query_results)}"
|
||||
)
|
||||
|
||||
|
||||
@then("I should get {count:d} result")
|
||||
def step_check_query_result_count_singular(context, count):
|
||||
"""Verify the query returned the expected number of results (singular)."""
|
||||
assert len(context.query_results) == count, (
|
||||
f"Expected {count} result, got {len(context.query_results)}"
|
||||
)
|
||||
|
||||
|
||||
@then('the results should include "{path}"')
|
||||
def step_check_result_includes_path(context, path):
|
||||
"""Verify the query results include a specific path."""
|
||||
paths = [entry.path for entry in context.query_results]
|
||||
assert path in paths
|
||||
|
||||
|
||||
@when('I query the index by file type "{file_type}"')
|
||||
def step_query_by_file_type(context, file_type):
|
||||
"""Query the index by file type."""
|
||||
context.query_results = context.index.query_by_type(FileType(file_type))
|
||||
|
||||
|
||||
@then('all results should have file type "{file_type}"')
|
||||
def step_check_all_results_file_type(context, file_type):
|
||||
"""Verify all results have the expected file type."""
|
||||
expected_type = FileType(file_type)
|
||||
for entry in context.query_results:
|
||||
assert entry.file_type == expected_type
|
||||
|
||||
|
||||
@when('I query the index by tag "{tag}"')
|
||||
def step_query_by_tag(context, tag):
|
||||
"""Query the index by tag."""
|
||||
context.query_results = context.index.query_by_tag(tag)
|
||||
|
||||
|
||||
@when('I query the index by tier level "{tier}"')
|
||||
def step_query_by_tier(context, tier):
|
||||
"""Query the index by tier level."""
|
||||
context.query_results = context.index.query_by_tier(TierLevel(tier))
|
||||
|
||||
|
||||
@then('the result should have path "{path}"')
|
||||
def step_check_single_result_path(context, path):
|
||||
"""Verify the single result has the expected path."""
|
||||
assert len(context.query_results) == 1
|
||||
assert context.query_results[0].path == path
|
||||
|
||||
|
||||
@given("I have an index with entries from different dates")
|
||||
def step_create_index_with_dated_entries(context):
|
||||
"""Create an index with entries from different dates."""
|
||||
context.index = ACMSIndex()
|
||||
|
||||
now = datetime.now()
|
||||
dates = [
|
||||
now - timedelta(days=10),
|
||||
now - timedelta(days=5),
|
||||
now - timedelta(days=1),
|
||||
now,
|
||||
]
|
||||
|
||||
for i, date in enumerate(dates):
|
||||
entry = IndexEntry(
|
||||
path=f"/project/file{i}.py",
|
||||
file_type=FileType.PYTHON,
|
||||
size_bytes=1024,
|
||||
created_at=date,
|
||||
modified_at=date,
|
||||
)
|
||||
context.index.add_entry(entry)
|
||||
|
||||
|
||||
@when('I query the index for entries modified after "{date_str}"')
|
||||
def step_query_by_recency(context, date_str):
|
||||
"""Query the index for entries modified after a specific date."""
|
||||
# Parse date string (format: YYYY-MM-DD)
|
||||
date = datetime.strptime(date_str, "%Y-%m-%d")
|
||||
context.query_results = context.index.query_by_recency(date)
|
||||
|
||||
|
||||
@then("I should get entries modified after that date")
|
||||
def step_check_recency_results(context):
|
||||
"""Verify the recency query returned valid results."""
|
||||
assert len(context.query_results) > 0
|
||||
|
||||
|
||||
@given("I have a test directory with {count:d} files")
|
||||
def step_create_test_directory(context, count):
|
||||
"""Create a temporary directory with test files."""
|
||||
context.temp_dir = tempfile.TemporaryDirectory()
|
||||
temp_path = Path(context.temp_dir.name)
|
||||
|
||||
# Create subdirectories and files
|
||||
for i in range(count):
|
||||
subdir = temp_path / f"subdir{i % 10}"
|
||||
subdir.mkdir(exist_ok=True)
|
||||
|
||||
file_path = subdir / f"file{i}.py"
|
||||
file_path.write_text(f"# Test file {i}\nprint('Hello {i}')\n")
|
||||
|
||||
|
||||
@when("I traverse and index the directory")
|
||||
def step_traverse_and_index(context):
|
||||
"""Traverse and index the test directory."""
|
||||
context.engine.reset_index()
|
||||
context.index = context.engine.traverse_and_index(context.temp_dir.name)
|
||||
|
||||
|
||||
@when("I traverse and index the directory with chunk size {chunk_size:d}")
|
||||
def step_traverse_and_index_with_chunk_size(context, chunk_size):
|
||||
"""Traverse and index the test directory with a specific chunk size."""
|
||||
engine = FileTraversalEngine(chunk_size=chunk_size)
|
||||
context.index = engine.traverse_and_index(context.temp_dir.name)
|
||||
|
||||
|
||||
@then("all entries should have valid file paths")
|
||||
def step_check_valid_file_paths(context):
|
||||
"""Verify all entries have valid file paths."""
|
||||
for entry in context.index.get_all_entries():
|
||||
assert entry.path
|
||||
assert len(entry.path) > 0
|
||||
|
||||
|
||||
@then("the traversal should complete without timeout")
|
||||
def step_check_no_timeout(context):
|
||||
"""Verify the traversal completed without timeout."""
|
||||
# This step passes if we got here without timing out
|
||||
assert True
|
||||
|
||||
|
||||
@given("I have a test directory with files including:")
|
||||
def step_create_test_directory_with_specific_files(context):
|
||||
"""Create a test directory with specific files."""
|
||||
context.temp_dir = tempfile.TemporaryDirectory()
|
||||
temp_path = Path(context.temp_dir.name)
|
||||
|
||||
for row in context.table:
|
||||
file_path = temp_path / row["path"].lstrip("/")
|
||||
file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
file_path.write_text("test content")
|
||||
|
||||
|
||||
@when('I traverse and index the directory excluding "{exclude1}" and "{exclude2}"')
|
||||
def step_traverse_with_exclusions(context, exclude1, exclude2):
|
||||
"""Traverse and index with exclusion patterns."""
|
||||
context.engine.reset_index()
|
||||
context.index = context.engine.traverse_and_index(
|
||||
context.temp_dir.name,
|
||||
exclude_patterns=[exclude1, exclude2],
|
||||
)
|
||||
|
||||
|
||||
@then('the index should not contain "{pattern}" paths')
|
||||
def step_check_no_excluded_paths(context, pattern):
|
||||
"""Verify the index doesn't contain paths matching the pattern."""
|
||||
for entry in context.index.get_all_entries():
|
||||
assert pattern not in entry.path
|
||||
|
||||
|
||||
@when("I get all entries from the index")
|
||||
def step_get_all_entries(context):
|
||||
"""Get all entries from the index."""
|
||||
context.query_results = context.index.get_all_entries()
|
||||
|
||||
|
||||
@when("I get the entry count")
|
||||
def step_get_entry_count(context):
|
||||
"""Get the entry count from the index."""
|
||||
context.entry_count = context.index.get_entry_count()
|
||||
|
||||
|
||||
@then("the count should be {count:d}")
|
||||
def step_check_entry_count_value(context, count):
|
||||
"""Verify the entry count matches the expected value."""
|
||||
assert context.entry_count == count
|
||||
|
||||
|
||||
@when("I remove an entry by path")
|
||||
def step_remove_entry(context):
|
||||
"""Remove an entry from the index."""
|
||||
# Get the first entry's path
|
||||
entries = context.index.get_all_entries()
|
||||
if entries:
|
||||
context.index.remove_entry(entries[0].path)
|
||||
|
||||
|
||||
@when("I query the index with filters:")
|
||||
def step_query_with_combined_filters(context):
|
||||
"""Query the index with multiple filters."""
|
||||
filters = {row["filter"]: row["value"] for row in context.table}
|
||||
|
||||
path_pattern = filters.get("path_pattern")
|
||||
file_type_str = filters.get("file_type")
|
||||
tier_str = filters.get("tier")
|
||||
|
||||
file_type = FileType(file_type_str) if file_type_str else None
|
||||
tier = TierLevel(tier_str) if tier_str else None
|
||||
|
||||
context.query_results = context.index.query_combined(
|
||||
path_pattern=path_pattern,
|
||||
file_type=file_type,
|
||||
tier=tier,
|
||||
)
|
||||
@@ -337,6 +337,63 @@ def step_remove_namespaced_ok(context: Any) -> None:
|
||||
)
|
||||
|
||||
|
||||
@when("I run actor remove with format json")
|
||||
def step_remove_format_json(context: Any) -> None:
|
||||
with (
|
||||
patch("cleveragents.cli.commands.actor._get_services") as mock_svc,
|
||||
patch("cleveragents.cli.commands.actor._compute_actor_impact") as mock_impact,
|
||||
):
|
||||
mock_registry = MagicMock()
|
||||
mock_service = MagicMock()
|
||||
actor = _make_actor(
|
||||
name="local/remove-json",
|
||||
provider="json-provider",
|
||||
model="gpt-json",
|
||||
)
|
||||
mock_registry.get_actor.return_value = actor
|
||||
mock_impact.return_value = (2, 1, 3)
|
||||
mock_svc.return_value = (mock_service, mock_registry)
|
||||
|
||||
context.result = context.runner.invoke(
|
||||
actor_app,
|
||||
["remove", actor.name, "--format", "json"],
|
||||
)
|
||||
|
||||
context.mock_actor_registry = mock_registry
|
||||
context.actor = actor
|
||||
context.impact_counts = (2, 1, 3)
|
||||
|
||||
|
||||
@then("the actor remove output should be valid JSON envelope")
|
||||
def step_remove_json_valid(context: Any) -> None:
|
||||
assert context.result.exit_code == 0
|
||||
parsed = json.loads(context.result.output.strip())
|
||||
assert _ENVELOPE_KEYS.issubset(parsed.keys())
|
||||
assert parsed["command"] == f"agents actor remove {context.actor.name}"
|
||||
assert parsed["status"] == "ok"
|
||||
assert parsed["exit_code"] == 0
|
||||
data = _unwrap_envelope(parsed)
|
||||
assert isinstance(data, dict)
|
||||
actor_data = data.get("actor_removed", {})
|
||||
assert actor_data.get("name") == context.actor.name
|
||||
assert actor_data.get("provider") == context.actor.provider
|
||||
assert actor_data.get("model") == context.actor.model
|
||||
impact = data.get("impact", {})
|
||||
expected_sessions, expected_plans, expected_actions = context.impact_counts
|
||||
assert impact.get("sessions") == expected_sessions
|
||||
assert impact.get("active_plans") == expected_plans
|
||||
assert impact.get("actions_referencing") == expected_actions
|
||||
cleanup = data.get("cleanup", {})
|
||||
assert cleanup.get("config") == "kept on disk"
|
||||
assert cleanup.get("contexts") == "0 orphaned"
|
||||
messages = parsed.get("messages", [])
|
||||
assert messages, "expected messages in envelope"
|
||||
first_message = messages[0]
|
||||
assert first_message.get("level") == "ok"
|
||||
assert "Actor removed" in first_message.get("text", "")
|
||||
context.mock_actor_registry.remove_actor.assert_called_once_with(context.actor.name)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Update with --format
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@@ -135,7 +135,8 @@ def _subgraph_node(node_id: str, actor_ref: str = "") -> NodeDefinition:
|
||||
type=NodeType.SUBGRAPH,
|
||||
name=node_id.title(),
|
||||
description=f"Subgraph {node_id}",
|
||||
config={"actor_ref": actor_ref},
|
||||
config={},
|
||||
actor_ref=actor_ref if actor_ref else None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -186,7 +186,8 @@ def step_given_subgraph_ref(context: Context, ref_name: str) -> None:
|
||||
type=NodeType.SUBGRAPH,
|
||||
name="Sub",
|
||||
description="Subgraph",
|
||||
config={"actor_ref": ref_name},
|
||||
config={},
|
||||
actor_ref=ref_name,
|
||||
),
|
||||
]
|
||||
edges = [EdgeDefinition(from_node="main", to_node="sub")]
|
||||
@@ -241,7 +242,8 @@ def step_given_outer_referencing_inner(
|
||||
type=NodeType.SUBGRAPH,
|
||||
name="Sub",
|
||||
description="Subgraph",
|
||||
config={"actor_ref": inner_name},
|
||||
config={},
|
||||
actor_ref=inner_name,
|
||||
),
|
||||
]
|
||||
edges = [EdgeDefinition(from_node="main", to_node="sub")]
|
||||
@@ -260,7 +262,8 @@ def step_given_resolver_cycle(context: Context, inner_name: str, back_ref: str)
|
||||
type=NodeType.SUBGRAPH,
|
||||
name="Child",
|
||||
description="Back-ref",
|
||||
config={"actor_ref": back_ref},
|
||||
config={},
|
||||
actor_ref=back_ref,
|
||||
),
|
||||
]
|
||||
inner = _build_graph_config(inner_name, inner_nodes, [], "child", ["child"])
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
"""Step definitions for cross-actor subgraph cycle detection tests.
|
||||
|
||||
Tests for features/actor_subgraph_cycle_detection.feature — validates that
|
||||
the actor compiler correctly reads actor_ref from the top-level
|
||||
NodeDefinition field (not from node.config) when detecting cross-actor
|
||||
subgraph cycles.
|
||||
|
||||
This is the regression test for issue #1431: _detect_subgraph_cycles()
|
||||
was reading node.config.get("actor_ref", "") instead of node.actor_ref,
|
||||
causing cycle detection to always return an empty string and never detect
|
||||
cross-actor cycles.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from behave import given, then, when
|
||||
from behave.runner import Context
|
||||
|
||||
from cleveragents.actor.compiler import (
|
||||
SubgraphCycleError,
|
||||
compile_actor,
|
||||
)
|
||||
from cleveragents.actor.schema import (
|
||||
ActorConfigSchema,
|
||||
ActorType,
|
||||
EdgeDefinition,
|
||||
NodeDefinition,
|
||||
NodeType,
|
||||
RouteDefinition,
|
||||
)
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# Helpers
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _make_graph_actor(
|
||||
name: str,
|
||||
nodes: list[NodeDefinition],
|
||||
edges: list[EdgeDefinition],
|
||||
entry_node: str,
|
||||
exit_nodes: list[str],
|
||||
) -> ActorConfigSchema:
|
||||
"""Build a minimal valid GRAPH actor for testing."""
|
||||
route = RouteDefinition(
|
||||
nodes=nodes,
|
||||
edges=edges,
|
||||
entry_node=entry_node,
|
||||
exit_nodes=exit_nodes,
|
||||
)
|
||||
return ActorConfigSchema(
|
||||
name=name,
|
||||
type=ActorType.GRAPH,
|
||||
description=f"Test actor {name}",
|
||||
provider="openai",
|
||||
model="gpt-4",
|
||||
route=route,
|
||||
)
|
||||
|
||||
|
||||
def _make_agent_node(node_id: str) -> NodeDefinition:
|
||||
"""Build a minimal AGENT node."""
|
||||
return NodeDefinition(
|
||||
id=node_id,
|
||||
type=NodeType.AGENT,
|
||||
name=node_id.title(),
|
||||
description=f"Agent {node_id}",
|
||||
config={"agent": "default"},
|
||||
)
|
||||
|
||||
|
||||
def _make_subgraph_node(node_id: str, actor_ref: str) -> NodeDefinition:
|
||||
"""Build a SUBGRAPH node using the top-level actor_ref field.
|
||||
|
||||
The actor_ref is set as a first-class field on NodeDefinition, NOT
|
||||
inside config. This is the correct way to reference a subgraph actor.
|
||||
"""
|
||||
return NodeDefinition(
|
||||
id=node_id,
|
||||
type=NodeType.SUBGRAPH,
|
||||
name=node_id.title(),
|
||||
description=f"Subgraph {node_id}",
|
||||
config={},
|
||||
actor_ref=actor_ref,
|
||||
)
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# Given steps
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@given("the actor compiler is available")
|
||||
def step_compiler_available(context: Context) -> None:
|
||||
"""Ensure the actor compiler module is importable."""
|
||||
context.actor_registry: dict[str, ActorConfigSchema] = {}
|
||||
|
||||
|
||||
@given('actor "{name}" has a subgraph node with actor_ref "{ref}"')
|
||||
def step_actor_has_subgraph_ref(context: Context, name: str, ref: str) -> None:
|
||||
"""Create a GRAPH actor with one agent node and one subgraph node."""
|
||||
agent = _make_agent_node("start")
|
||||
sub = _make_subgraph_node("sub", actor_ref=ref)
|
||||
actor = _make_graph_actor(
|
||||
name,
|
||||
nodes=[agent, sub],
|
||||
edges=[EdgeDefinition(from_node="start", to_node="sub")],
|
||||
entry_node="start",
|
||||
exit_nodes=["sub"],
|
||||
)
|
||||
context.actor_registry[name] = actor
|
||||
context.actor_to_compile = name
|
||||
|
||||
|
||||
@given('actor "{name}" has no subgraph nodes')
|
||||
def step_actor_has_no_subgraph(context: Context, name: str) -> None:
|
||||
"""Create a GRAPH actor with only an agent node (no subgraph references)."""
|
||||
agent = _make_agent_node("leaf")
|
||||
actor = _make_graph_actor(
|
||||
name,
|
||||
nodes=[agent],
|
||||
edges=[],
|
||||
entry_node="leaf",
|
||||
exit_nodes=["leaf"],
|
||||
)
|
||||
context.actor_registry[name] = actor
|
||||
|
||||
|
||||
@given("a registry containing both actors")
|
||||
def step_registry_contains_both(context: Context) -> None:
|
||||
"""Set up the resolver from the accumulated registry."""
|
||||
registry = context.actor_registry
|
||||
|
||||
def resolver(actor_name: str) -> ActorConfigSchema | None:
|
||||
return registry.get(actor_name)
|
||||
|
||||
context.resolver = resolver
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# When steps
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@when('I compile actor "{name}" with the registry resolver')
|
||||
def step_compile_actor(context: Context, name: str) -> None:
|
||||
"""Compile the named actor using the registry resolver."""
|
||||
context.compile_error = None
|
||||
context.compiled = None
|
||||
actor = context.actor_registry[name]
|
||||
try:
|
||||
context.compiled = compile_actor(actor, actor_resolver=context.resolver)
|
||||
except Exception as exc:
|
||||
context.compile_error = exc
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# Then steps
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@then("the compilation should raise SubgraphCycleError")
|
||||
def step_raises_cycle_error(context: Context) -> None:
|
||||
"""Assert that compilation raised SubgraphCycleError."""
|
||||
assert context.compile_error is not None, (
|
||||
"Expected SubgraphCycleError but compilation succeeded"
|
||||
)
|
||||
assert isinstance(context.compile_error, SubgraphCycleError), (
|
||||
f"Expected SubgraphCycleError, got {type(context.compile_error).__name__}: "
|
||||
f"{context.compile_error}"
|
||||
)
|
||||
|
||||
|
||||
@then("the actor compilation should succeed")
|
||||
def step_actor_compilation_succeeds(context: Context) -> None:
|
||||
"""Assert that compilation succeeded without errors."""
|
||||
assert context.compile_error is None, (
|
||||
f"Expected compilation to succeed but got: {context.compile_error}"
|
||||
)
|
||||
assert context.compiled is not None
|
||||
|
||||
|
||||
@then('the cycle error message should mention "{text}"')
|
||||
def step_cycle_error_mentions(context: Context, text: str) -> None:
|
||||
"""Assert that the cycle error message contains the given text."""
|
||||
assert context.compile_error is not None
|
||||
msg = str(context.compile_error)
|
||||
assert text.lower() in msg.lower(), (
|
||||
f"Expected '{text}' in error message, got: {msg}"
|
||||
)
|
||||
|
||||
|
||||
@then('the actor subgraph_refs should map "{node}" to "{ref}"')
|
||||
def step_actor_subgraph_refs_map(context: Context, node: str, ref: str) -> None:
|
||||
"""Assert that the compiled metadata maps the node to the expected actor ref."""
|
||||
assert context.compiled is not None
|
||||
refs = context.compiled.metadata.subgraph_refs
|
||||
assert refs.get(node) == ref, (
|
||||
f"Expected subgraph_refs[{node!r}] == {ref!r}, got {refs}"
|
||||
)
|
||||
@@ -1,425 +0,0 @@
|
||||
"""Step definitions for invariant_action_scope_effective.feature.
|
||||
|
||||
Tests that InvariantService.get_effective_invariants() correctly includes
|
||||
action-scoped invariants in the 4-tier precedence merge:
|
||||
plan > action > project > global
|
||||
|
||||
Also tests that merge_invariants() and InvariantSet.merge() accept and
|
||||
correctly process the action_invariants parameter.
|
||||
|
||||
See: https://git.cleverthis.com/cleveragents/cleveragents-core/issues/3128
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from behave import given, then, when # type: ignore[import-untyped]
|
||||
|
||||
from cleveragents.application.services.invariant_service import InvariantService
|
||||
from cleveragents.domain.models.core.invariant import (
|
||||
Invariant,
|
||||
InvariantScope,
|
||||
InvariantSet,
|
||||
merge_invariants,
|
||||
)
|
||||
|
||||
# ================================================================
|
||||
# Givens — service setup
|
||||
# ================================================================
|
||||
|
||||
|
||||
@given("an invariant service with action and global invariants")
|
||||
def step_service_action_global(context: object) -> None:
|
||||
"""Set up a service with one action-scoped and one global invariant."""
|
||||
context.service = InvariantService()
|
||||
context.service.add_invariant(
|
||||
text="Do not modify public API",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Log all changes",
|
||||
scope=InvariantScope.GLOBAL,
|
||||
source_name="system",
|
||||
)
|
||||
|
||||
|
||||
@given("an invariant service with invariants at all four scopes")
|
||||
def step_service_all_four_scopes(context: object) -> None:
|
||||
"""Set up a service with one invariant at each of the four scopes."""
|
||||
context.service = InvariantService()
|
||||
context.service.add_invariant(
|
||||
text="Plan-level rule",
|
||||
scope=InvariantScope.PLAN,
|
||||
source_name="plan-001",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Action-level rule",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Project-level rule",
|
||||
scope=InvariantScope.PROJECT,
|
||||
source_name="myapp",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Global-level rule",
|
||||
scope=InvariantScope.GLOBAL,
|
||||
source_name="system",
|
||||
)
|
||||
|
||||
|
||||
@given("an invariant service with action and project invariants having the same text")
|
||||
def step_service_action_project_same_text(context: object) -> None:
|
||||
"""Set up a service where action and project invariants share the same text."""
|
||||
context.service = InvariantService()
|
||||
context.service.add_invariant(
|
||||
text="Shared constraint text",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Shared constraint text",
|
||||
scope=InvariantScope.PROJECT,
|
||||
source_name="myapp",
|
||||
)
|
||||
|
||||
|
||||
@given("an invariant service with plan and action invariants having the same text")
|
||||
def step_service_plan_action_same_text(context: object) -> None:
|
||||
"""Set up a service where plan and action invariants share the same text."""
|
||||
context.service = InvariantService()
|
||||
context.service.add_invariant(
|
||||
text="Shared constraint text",
|
||||
scope=InvariantScope.PLAN,
|
||||
source_name="plan-001",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Shared constraint text",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
|
||||
|
||||
@given("an invariant service with two different action invariants")
|
||||
def step_service_two_action_invariants(context: object) -> None:
|
||||
"""Set up a service with two action invariants from different actions."""
|
||||
context.service = InvariantService()
|
||||
context.service.add_invariant(
|
||||
text="Deploy constraint",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
context.service.add_invariant(
|
||||
text="Build constraint",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="build-service",
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Whens — get_effective_invariants calls
|
||||
# ================================================================
|
||||
|
||||
|
||||
@when('I get effective invariants with action_name "{action_name}"')
|
||||
def step_get_effective_with_action(context: object, action_name: str) -> None:
|
||||
"""Call get_effective_invariants with the given action_name."""
|
||||
context.effective = context.service.get_effective_invariants(
|
||||
action_name=action_name,
|
||||
)
|
||||
|
||||
|
||||
@when("I get effective invariants with no action_name")
|
||||
def step_get_effective_no_action(context: object) -> None:
|
||||
"""Call get_effective_invariants without an action_name."""
|
||||
context.effective = context.service.get_effective_invariants()
|
||||
|
||||
|
||||
@when(
|
||||
'I get effective invariants for plan "{plan_id}" action "{action_name}" and project "{project_name}"'
|
||||
)
|
||||
def step_get_effective_all_four(
|
||||
context: object, plan_id: str, action_name: str, project_name: str
|
||||
) -> None:
|
||||
"""Call get_effective_invariants with all four scope parameters."""
|
||||
context.effective = context.service.get_effective_invariants(
|
||||
plan_id=plan_id,
|
||||
action_name=action_name,
|
||||
project_name=project_name,
|
||||
)
|
||||
|
||||
|
||||
@when('I get effective invariants with only action_name "{action_name}"')
|
||||
def step_get_effective_only_action(context: object, action_name: str) -> None:
|
||||
"""Call get_effective_invariants with only action_name (no plan or project)."""
|
||||
context.effective = context.service.get_effective_invariants(
|
||||
action_name=action_name,
|
||||
)
|
||||
|
||||
|
||||
@when('I get effective invariants with action_name "{action_name}" for filtering')
|
||||
def step_get_effective_action_filter(context: object, action_name: str) -> None:
|
||||
"""Call get_effective_invariants to filter by specific action_name."""
|
||||
context.effective = context.service.get_effective_invariants(
|
||||
action_name=action_name,
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Whens — list_invariants with effective=True
|
||||
# ================================================================
|
||||
|
||||
|
||||
@when('I list invariants with effective True and action scope "{action_name}"')
|
||||
def step_list_effective_action(context: object, action_name: str) -> None:
|
||||
"""Call list_invariants with effective=True and action scope."""
|
||||
context.listed_effective = context.service.list_invariants(
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name=action_name,
|
||||
effective=True,
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Whens — merge_invariants() direct calls
|
||||
# ================================================================
|
||||
|
||||
|
||||
@given("I have plan action project and global invariant lists")
|
||||
def step_four_tier_lists(context: object) -> None:
|
||||
"""Create four separate invariant lists for merge testing."""
|
||||
context.plan_invs = [
|
||||
Invariant(text="Plan rule", scope=InvariantScope.PLAN, source_name="plan-001")
|
||||
]
|
||||
context.action_invs = [
|
||||
Invariant(
|
||||
text="Action rule",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
]
|
||||
context.project_invs = [
|
||||
Invariant(
|
||||
text="Project rule", scope=InvariantScope.PROJECT, source_name="myapp"
|
||||
)
|
||||
]
|
||||
context.global_invs = [
|
||||
Invariant(text="Global rule", scope=InvariantScope.GLOBAL, source_name="system")
|
||||
]
|
||||
|
||||
|
||||
@given("I have overlapping action and project invariant lists")
|
||||
def step_overlapping_action_project(context: object) -> None:
|
||||
"""Create action and project invariant lists with the same text."""
|
||||
context.plan_invs: list[Invariant] = []
|
||||
context.action_invs = [
|
||||
Invariant(
|
||||
text="Shared rule",
|
||||
scope=InvariantScope.ACTION,
|
||||
source_name="deploy-service",
|
||||
)
|
||||
]
|
||||
context.project_invs = [
|
||||
Invariant(text="Shared rule", scope=InvariantScope.PROJECT, source_name="myapp")
|
||||
]
|
||||
context.global_invs: list[Invariant] = []
|
||||
|
||||
|
||||
@given("I have plan project and global invariant lists with no action invariants")
|
||||
def step_three_tier_lists(context: object) -> None:
|
||||
"""Create three invariant lists (no action tier) for merge testing."""
|
||||
context.plan_invs = [
|
||||
Invariant(text="Plan rule", scope=InvariantScope.PLAN, source_name="plan-001")
|
||||
]
|
||||
context.action_invs: list[Invariant] = []
|
||||
context.project_invs = [
|
||||
Invariant(
|
||||
text="Project rule", scope=InvariantScope.PROJECT, source_name="myapp"
|
||||
)
|
||||
]
|
||||
context.global_invs = [
|
||||
Invariant(text="Global rule", scope=InvariantScope.GLOBAL, source_name="system")
|
||||
]
|
||||
|
||||
|
||||
@when("I merge all four invariant tiers")
|
||||
def step_merge_four_tiers(context: object) -> None:
|
||||
"""Call merge_invariants with all four tiers."""
|
||||
context.merged = merge_invariants(
|
||||
context.plan_invs,
|
||||
context.action_invs,
|
||||
context.project_invs,
|
||||
context.global_invs,
|
||||
)
|
||||
|
||||
|
||||
@when("I merge all four invariant tiers with empty action list")
|
||||
def step_merge_four_tiers_empty_action(context: object) -> None:
|
||||
"""Call merge_invariants with an empty action list."""
|
||||
context.merged = merge_invariants(
|
||||
context.plan_invs,
|
||||
[],
|
||||
context.project_invs,
|
||||
context.global_invs,
|
||||
)
|
||||
|
||||
|
||||
@when("I merge all four tiers using InvariantSet")
|
||||
def step_merge_invariant_set_four(context: object) -> None:
|
||||
"""Call InvariantSet.merge with all four tiers."""
|
||||
context.invariant_set = InvariantSet.merge(
|
||||
context.plan_invs,
|
||||
context.action_invs,
|
||||
context.project_invs,
|
||||
context.global_invs,
|
||||
)
|
||||
|
||||
|
||||
@when("I merge all four tiers using InvariantSet with empty action list")
|
||||
def step_merge_invariant_set_empty_action(context: object) -> None:
|
||||
"""Call InvariantSet.merge with an empty action list."""
|
||||
context.invariant_set = InvariantSet.merge(
|
||||
context.plan_invs,
|
||||
[],
|
||||
context.project_invs,
|
||||
context.global_invs,
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Thens — effective set assertions
|
||||
# ================================================================
|
||||
|
||||
|
||||
@then('the effective set should contain the action invariant "{text}"')
|
||||
def step_effective_contains_action(context: object, text: str) -> None:
|
||||
"""Assert the effective set contains an action invariant with the given text."""
|
||||
texts = [inv.text for inv in context.effective]
|
||||
assert text in texts, (
|
||||
f"Expected action invariant '{text}' in effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
@then('the effective set should not contain the action invariant "{text}"')
|
||||
def step_effective_not_contains_action(context: object, text: str) -> None:
|
||||
"""Assert the effective set does NOT contain an invariant with the given text."""
|
||||
texts = [inv.text for inv in context.effective]
|
||||
assert text not in texts, (
|
||||
f"Expected action invariant '{text}' to be absent from effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
@then('the effective set should contain the global invariant "{text}"')
|
||||
def step_effective_contains_global(context: object, text: str) -> None:
|
||||
"""Assert the effective set contains a global invariant with the given text."""
|
||||
texts = [inv.text for inv in context.effective]
|
||||
assert text in texts, (
|
||||
f"Expected global invariant '{text}' in effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
@then('the effective set should contain the plan invariant "{text}"')
|
||||
def step_effective_contains_plan(context: object, text: str) -> None:
|
||||
"""Assert the effective set contains a plan invariant with the given text."""
|
||||
texts = [inv.text for inv in context.effective]
|
||||
assert text in texts, (
|
||||
f"Expected plan invariant '{text}' in effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
@then('the effective set should contain the project invariant "{text}"')
|
||||
def step_effective_contains_project(context: object, text: str) -> None:
|
||||
"""Assert the effective set contains a project invariant with the given text."""
|
||||
texts = [inv.text for inv in context.effective]
|
||||
assert text in texts, (
|
||||
f"Expected project invariant '{text}' in effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
@then("the effective set should have {count:d} invariants")
|
||||
def step_effective_count(context: object, count: int) -> None:
|
||||
"""Assert the effective set has exactly the given number of invariants."""
|
||||
actual = len(context.effective)
|
||||
assert actual == count, f"Expected {count} effective invariants, got {actual}"
|
||||
|
||||
|
||||
@then("the effective set should have {count:d} invariant")
|
||||
def step_effective_count_singular(context: object, count: int) -> None:
|
||||
"""Assert the effective set has exactly the given number of invariants (singular)."""
|
||||
actual = len(context.effective)
|
||||
assert actual == count, f"Expected {count} effective invariant, got {actual}"
|
||||
|
||||
|
||||
@then('the first effective invariant should have scope "{scope}"')
|
||||
def step_first_effective_scope(context: object, scope: str) -> None:
|
||||
"""Assert the first invariant in the effective set has the given scope."""
|
||||
assert context.effective, "Effective set is empty"
|
||||
actual = context.effective[0].scope.value
|
||||
assert actual == scope, (
|
||||
f"Expected first effective invariant scope '{scope}', got '{actual}'"
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Thens — list_invariants effective assertions
|
||||
# ================================================================
|
||||
|
||||
|
||||
@then('the listed effective set should contain the action invariant "{text}"')
|
||||
def step_listed_effective_contains_action(context: object, text: str) -> None:
|
||||
"""Assert the listed effective set contains an action invariant with the given text."""
|
||||
texts = [inv.text for inv in context.listed_effective]
|
||||
assert text in texts, (
|
||||
f"Expected action invariant '{text}' in listed effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
@then('the listed effective set should contain the global invariant "{text}"')
|
||||
def step_listed_effective_contains_global(context: object, text: str) -> None:
|
||||
"""Assert the listed effective set contains a global invariant with the given text."""
|
||||
texts = [inv.text for inv in context.listed_effective]
|
||||
assert text in texts, (
|
||||
f"Expected global invariant '{text}' in listed effective set, got: {texts}"
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Thens — merge_invariants() assertions
|
||||
# ================================================================
|
||||
|
||||
|
||||
@then("the merged result should have {count:d} invariants")
|
||||
def step_merged_count_four(context: object, count: int) -> None:
|
||||
"""Assert the merged result has exactly the given number of invariants."""
|
||||
actual = len(context.merged)
|
||||
assert actual == count, f"Expected {count} merged invariants, got {actual}"
|
||||
|
||||
|
||||
@then('the merged result should contain "{text}"')
|
||||
def step_merged_contains_text(context: object, text: str) -> None:
|
||||
"""Assert the merged result contains an invariant with the given text."""
|
||||
texts = [inv.text for inv in context.merged]
|
||||
assert text in texts, f"Expected '{text}' in merged result, got: {texts}"
|
||||
|
||||
|
||||
@then('the first merged invariant should have scope "{scope}"')
|
||||
def step_first_merged_scope(context: object, scope: str) -> None:
|
||||
"""Assert the first invariant in the merged result has the given scope."""
|
||||
assert context.merged, "Merged result is empty"
|
||||
actual = context.merged[0].scope.value
|
||||
assert actual == scope, (
|
||||
f"Expected first merged invariant scope '{scope}', got '{actual}'"
|
||||
)
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Thens — InvariantSet.merge() assertions
|
||||
# ================================================================
|
||||
|
||||
|
||||
@then("the invariant set should have {count:d} invariant")
|
||||
def step_invariant_set_count_singular(context: object, count: int) -> None:
|
||||
"""Assert the InvariantSet has exactly the given number of invariants (singular)."""
|
||||
actual = len(context.invariant_set.invariants)
|
||||
assert actual == count, f"Expected {count} invariant in set, got {actual}"
|
||||
@@ -160,7 +160,6 @@ def step_plan_invariants_inactive(context):
|
||||
def step_merge(context):
|
||||
context.merged = merge_invariants(
|
||||
getattr(context, "plan_invariants", []),
|
||||
getattr(context, "action_invariants", []),
|
||||
getattr(context, "project_invariants", []),
|
||||
getattr(context, "global_invariants", []),
|
||||
)
|
||||
@@ -190,7 +189,6 @@ def step_merged_scope(context, idx, scope):
|
||||
def step_merge_invariant_set(context):
|
||||
inv_set = InvariantSet.merge(
|
||||
getattr(context, "plan_invariants", []),
|
||||
getattr(context, "action_invariants", []),
|
||||
getattr(context, "project_invariants", []),
|
||||
getattr(context, "global_invariants", []),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
"""Step definitions for PR compliance checklist in implementation supervisor."""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from behave import given, then, when
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[3]
|
||||
AGENT_DEF_PATH = PROJECT_ROOT / ".opencode" / "agents" / "implementation-supervisor.md"
|
||||
|
||||
|
||||
@given("the implementation-supervisor.md agent definition exists")
|
||||
def step_agent_def_exists(context: Any) -> None:
|
||||
"""Verify the implementation supervisor agent definition file exists."""
|
||||
assert AGENT_DEF_PATH.exists(), f"Agent definition not found at {AGENT_DEF_PATH}"
|
||||
context.agent_def_path = AGENT_DEF_PATH
|
||||
|
||||
|
||||
@when("I read the implementation supervisor agent definition")
|
||||
def step_read_agent_def(context: Any) -> None:
|
||||
"""Read the implementation supervisor agent definition."""
|
||||
context.agent_def_content = AGENT_DEF_PATH.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
@then("the worker prompt body includes the PR compliance checklist section")
|
||||
def step_prompt_includes_checklist(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes the PR compliance checklist."""
|
||||
assert "PR Compliance Checklist" in context.agent_def_content, (
|
||||
"Worker prompt body does not include 'PR Compliance Checklist'"
|
||||
)
|
||||
|
||||
|
||||
@then("the checklist is marked as MANDATORY")
|
||||
def step_checklist_is_mandatory(context: Any) -> None:
|
||||
"""Verify the checklist is marked as MANDATORY."""
|
||||
assert "MANDATORY" in context.agent_def_content, (
|
||||
"PR Compliance Checklist is not marked as MANDATORY"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a CHANGELOG.md checklist item")
|
||||
def step_prompt_includes_changelog_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a CHANGELOG.md checklist item."""
|
||||
assert "CHANGELOG.md" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a CHANGELOG.md checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to add an entry under the Unreleased section")
|
||||
def step_changelog_item_unreleased(context: Any) -> None:
|
||||
"""Verify the CHANGELOG.md item mentions the Unreleased section."""
|
||||
assert "[Unreleased]" in context.agent_def_content, (
|
||||
"CHANGELOG.md checklist item does not mention the [Unreleased] section"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a CONTRIBUTORS.md checklist item")
|
||||
def step_prompt_includes_contributors_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a CONTRIBUTORS.md checklist item."""
|
||||
assert "CONTRIBUTORS.md" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a CONTRIBUTORS.md checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to add or update their contribution entry")
|
||||
def step_contributors_item_add_update(context: Any) -> None:
|
||||
"""Verify the CONTRIBUTORS.md item instructs workers to add or update."""
|
||||
assert "add or update" in context.agent_def_content, (
|
||||
"CONTRIBUTORS.md checklist item does not instruct workers to add or update"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a commit footer checklist item")
|
||||
def step_prompt_includes_commit_footer_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a commit footer checklist item."""
|
||||
assert "Commit footer" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a commit footer checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item specifies the ISSUES CLOSED footer format")
|
||||
def step_commit_footer_issues_closed(context: Any) -> None:
|
||||
"""Verify the commit footer item specifies the ISSUES CLOSED format."""
|
||||
assert "ISSUES CLOSED" in context.agent_def_content, (
|
||||
"Commit footer checklist item does not specify the ISSUES CLOSED format"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a CI passes checklist item")
|
||||
def step_prompt_includes_ci_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a CI passes checklist item."""
|
||||
assert "CI passes" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a CI passes checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to verify all quality gates are green")
|
||||
def step_ci_item_quality_gates(context: Any) -> None:
|
||||
"""Verify the CI item instructs workers to verify quality gates."""
|
||||
assert "quality gates" in context.agent_def_content, (
|
||||
"CI checklist item does not mention quality gates"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a BDD tests checklist item")
|
||||
def step_prompt_includes_bdd_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a BDD/Behave tests checklist item."""
|
||||
assert "BDD/Behave tests" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a BDD/Behave tests checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to add or update Behave feature files")
|
||||
def step_bdd_item_feature_files(context: Any) -> None:
|
||||
"""Verify the BDD item instructs workers to add or update feature files."""
|
||||
assert "added or updated" in context.agent_def_content, (
|
||||
"BDD checklist item does not instruct workers to add or update feature files"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes an Epic reference checklist item")
|
||||
def step_prompt_includes_epic_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes an Epic reference checklist item."""
|
||||
assert "Epic reference" in context.agent_def_content, (
|
||||
"Worker prompt body does not include an Epic reference checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to reference the parent Epic issue number")
|
||||
def step_epic_item_parent_reference(context: Any) -> None:
|
||||
"""Verify the Epic item instructs workers to reference the parent Epic."""
|
||||
assert "parent Epic" in context.agent_def_content, (
|
||||
"Epic checklist item does not instruct workers to reference the parent Epic"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a labels checklist item")
|
||||
def step_prompt_includes_labels_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a labels checklist item."""
|
||||
assert "Labels" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a labels checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to apply labels via forgejo-label-manager")
|
||||
def step_labels_item_forgejo_label_manager(context: Any) -> None:
|
||||
"""Verify the labels item instructs workers to use forgejo-label-manager."""
|
||||
assert "forgejo-label-manager" in context.agent_def_content, (
|
||||
"Labels checklist item does not mention forgejo-label-manager"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body includes a milestone checklist item")
|
||||
def step_prompt_includes_milestone_item(context: Any) -> None:
|
||||
"""Verify the worker prompt body includes a milestone checklist item."""
|
||||
assert "Milestone" in context.agent_def_content, (
|
||||
"Worker prompt body does not include a milestone checklist item"
|
||||
)
|
||||
|
||||
|
||||
@then("the item instructs workers to assign the earliest open milestone")
|
||||
def step_milestone_item_earliest(context: Any) -> None:
|
||||
"""Verify the milestone item instructs workers to assign the earliest open milestone."""
|
||||
assert "earliest open milestone" in context.agent_def_content, (
|
||||
"Milestone checklist item does not mention the earliest open milestone"
|
||||
)
|
||||
|
||||
|
||||
@then("the worker prompt body contains all 8 mandatory checklist items")
|
||||
def step_prompt_contains_all_8_items(context: Any) -> None:
|
||||
"""Verify the worker prompt body contains all 8 mandatory checklist items."""
|
||||
required_items = [
|
||||
"CHANGELOG.md",
|
||||
"CONTRIBUTORS.md",
|
||||
"ISSUES CLOSED",
|
||||
"CI passes",
|
||||
"BDD/Behave tests",
|
||||
"Epic reference",
|
||||
"forgejo-label-manager",
|
||||
"earliest open milestone",
|
||||
]
|
||||
missing = [item for item in required_items if item not in context.agent_def_content]
|
||||
assert not missing, (
|
||||
f"Worker prompt body is missing the following checklist items: {missing}"
|
||||
)
|
||||
@@ -695,3 +695,23 @@ def step_cmd_json_has_deleted_at(context: Any) -> None:
|
||||
assert "deleted_at" in data, (
|
||||
f"Expected 'deleted_at' in command JSON data, got keys {list(data.keys())}"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Switch command (#8623 / #8675)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@when('I invoke project-switch for "{name}" default format')
|
||||
def step_invoke_switch(context: Any, name: str) -> None:
|
||||
from cleveragents.cli.commands.project import switch
|
||||
|
||||
_capture(context, switch, name=name)
|
||||
|
||||
|
||||
@when('I invoke project-switch for "{name}" format "{fmt}"')
|
||||
def step_invoke_switch_fmt(context: Any, name: str, fmt: str) -> None:
|
||||
from cleveragents.cli.commands.project import switch
|
||||
|
||||
_capture(context, switch, name=name, output_format=fmt)
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
"""Steps for TDD Issue #10507 — get_current_revision() SQLite threading fix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from behave import then, when
|
||||
|
||||
|
||||
def _run_get_current_revision_and_capture_kwargs(
|
||||
context: Any,
|
||||
) -> None:
|
||||
"""Shared helper: call get_current_revision() and capture create_engine kwargs.
|
||||
|
||||
Mocks ``create_engine`` and ``MigrationContext.configure`` so the call
|
||||
completes without a real database. The keyword arguments passed to
|
||||
``create_engine`` are stored on ``context.engine_creation_kwargs`` for
|
||||
subsequent assertion steps.
|
||||
"""
|
||||
fake_engine = MagicMock()
|
||||
fake_connection = MagicMock()
|
||||
fake_connection.__enter__ = MagicMock(return_value=fake_connection)
|
||||
fake_connection.__exit__ = MagicMock(return_value=False)
|
||||
fake_engine.connect.return_value = fake_connection
|
||||
|
||||
migration_ctx = MagicMock()
|
||||
migration_ctx.get_current_revision.return_value = None
|
||||
|
||||
captured_kwargs: list[dict[str, Any]] = []
|
||||
|
||||
def fake_create_engine(url: str, **kwargs: Any) -> MagicMock:
|
||||
captured_kwargs.append(kwargs)
|
||||
return fake_engine
|
||||
|
||||
with (
|
||||
patch(
|
||||
"cleveragents.infrastructure.database.migration_runner.create_engine",
|
||||
side_effect=fake_create_engine,
|
||||
),
|
||||
patch(
|
||||
"cleveragents.infrastructure.database.migration_runner.MigrationContext.configure",
|
||||
return_value=migration_ctx,
|
||||
),
|
||||
):
|
||||
context.revision_result = context.runner.get_current_revision()
|
||||
|
||||
context.engine_creation_kwargs = captured_kwargs
|
||||
|
||||
|
||||
@when("I request the current revision and capture the engine creation args")
|
||||
def step_when_capture_engine_args(context: Any) -> None:
|
||||
"""Call get_current_revision and capture the create_engine call arguments."""
|
||||
_run_get_current_revision_and_capture_kwargs(context)
|
||||
|
||||
|
||||
@then("the SQLite engine should be created with check_same_thread set to False")
|
||||
def step_then_sqlite_engine_has_check_same_thread(context: Any) -> None:
|
||||
"""Verify the SQLite engine was created with check_same_thread=False."""
|
||||
assert len(context.engine_creation_kwargs) == 1, (
|
||||
f"Expected exactly 1 create_engine call, got {len(context.engine_creation_kwargs)}"
|
||||
)
|
||||
kwargs = context.engine_creation_kwargs[0]
|
||||
assert "connect_args" in kwargs, (
|
||||
"Expected connect_args in create_engine kwargs for SQLite, "
|
||||
f"but got kwargs: {kwargs}"
|
||||
)
|
||||
assert kwargs["connect_args"].get("check_same_thread") is False, (
|
||||
"Expected check_same_thread=False in connect_args, "
|
||||
f"but got: {kwargs['connect_args']}"
|
||||
)
|
||||
|
||||
|
||||
@then("the non-SQLite engine should be created without check_same_thread")
|
||||
def step_then_non_sqlite_engine_no_check_same_thread(context: Any) -> None:
|
||||
"""Verify non-SQLite engines are not given check_same_thread."""
|
||||
assert len(context.engine_creation_kwargs) == 1, (
|
||||
f"Expected exactly 1 create_engine call, got {len(context.engine_creation_kwargs)}"
|
||||
)
|
||||
kwargs = context.engine_creation_kwargs[0]
|
||||
connect_args = kwargs.get("connect_args", {})
|
||||
assert "check_same_thread" not in connect_args, (
|
||||
"Expected check_same_thread to be absent for non-SQLite engine, "
|
||||
f"but got connect_args: {connect_args}"
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
@tdd_issue @tdd_issue_10507
|
||||
Feature: TDD Issue #10507 — get_current_revision() must pass check_same_thread=False for SQLite
|
||||
As a developer using MigrationRunner in a multi-threaded application
|
||||
I want get_current_revision() to work safely from background threads
|
||||
So that async startup flows and background migration checks do not crash
|
||||
|
||||
The root cause is that MigrationRunner.get_current_revision() calls
|
||||
create_engine(self.database_url) without connect_args={"check_same_thread": False}
|
||||
for SQLite databases. When called from a thread other than the one that
|
||||
created the engine, SQLite raises:
|
||||
ProgrammingError: SQLite objects created in a thread can only be
|
||||
used in that same thread.
|
||||
|
||||
The sibling method init_or_upgrade() already passes check_same_thread=False
|
||||
for SQLite, making this an inconsistency in the same class. Because
|
||||
get_pending_migrations() and check_migrations_needed() both delegate to
|
||||
get_current_revision(), the threading bug propagates to all three methods.
|
||||
|
||||
The fix adds connect_args={"check_same_thread": False} to the create_engine()
|
||||
call in get_current_revision() when the database URL starts with "sqlite",
|
||||
consistent with the existing pattern in init_or_upgrade().
|
||||
|
||||
Scenario: get_current_revision passes check_same_thread=False for SQLite engine
|
||||
Given a migration runner configured for "sqlite:///:memory:"
|
||||
When I request the current revision and capture the engine creation args
|
||||
Then the SQLite engine should be created with check_same_thread set to False
|
||||
|
||||
Scenario: get_current_revision does not pass check_same_thread for non-SQLite engine
|
||||
Given a migration runner configured for "postgresql://user:pass@localhost/testdb"
|
||||
When I request the current revision and capture the engine creation args
|
||||
Then the non-SQLite engine should be created without check_same_thread
|
||||
+2
-1
@@ -61,6 +61,7 @@ nav:
|
||||
- Reference/Command Input & Sessions: tui/input-and-sessions.md
|
||||
- Configuration, Key Bindings & Integration: tui/configuration-and-integration.md
|
||||
- FAQ: faq.md
|
||||
- Quick Start: quickstart.md
|
||||
- Changelog: CHANGELOG.md
|
||||
- Contributing: CONTRIBUTING.md
|
||||
- Reference: reference/
|
||||
@@ -93,7 +94,7 @@ nav:
|
||||
- ADR-025 Observability & Logging: adr/ADR-025-observability-and-logging.md
|
||||
- ADR-026 Agent-to-Agent Protocol (A2A): adr/ADR-026-agent-client-protocol.md
|
||||
- ADR-027 Language Server Protocol (LSP) Integration: adr/ADR-027-language-server-protocol.md
|
||||
- ADR-028 Agent Skills Standard (AgentSkills.io): adr/ADR-028-agent-skills-standard.md
|
||||
- ADR-028 Skill/Tool Abstraction Definition: adr/ADR-028-agent-skills-standard.md
|
||||
- ADR-029 Model Context Protocol (MCP) Adoption: adr/ADR-029-model-context-protocol.md
|
||||
- ADR-030 Skill Abstraction Definition: adr/ADR-030-skill-abstraction-definition.md
|
||||
- ADR-031 Actor Abstraction Definition: adr/ADR-031-actor-abstraction-definition.md
|
||||
|
||||
@@ -42,3 +42,15 @@ Reject LLM Actor Compilation
|
||||
Should Be Equal As Integers ${result.rc} 0
|
||||
Should Contain ${result.stdout} actor-compiler-expected-fail
|
||||
Should Contain ${result.stdout} GRAPH
|
||||
|
||||
Detect Cross-Actor Subgraph Cycle Via actor_ref Field
|
||||
[Documentation] Verify that mutually-referencing actors raise SubgraphCycleError.
|
||||
... This is the regression test for issue #1431: _detect_subgraph_cycles()
|
||||
... was reading node.config.get("actor_ref") instead of node.actor_ref,
|
||||
... causing cycle detection to silently fail.
|
||||
[Tags] slow
|
||||
${result}= Run Process ${PYTHON} ${HELPER} cycle-detect dummy cwd=${WORKSPACE}
|
||||
Log ${result.stdout}
|
||||
Log ${result.stderr}
|
||||
Should Be Equal As Integers ${result.rc} 0
|
||||
Should Contain ${result.stdout} actor-compiler-cycle-detected
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
*** Settings ***
|
||||
Documentation Integration tests for actor remove CLI format output
|
||||
Resource ${CURDIR}/common.resource
|
||||
Suite Setup Setup Test Environment
|
||||
Suite Teardown Cleanup Test Environment
|
||||
|
||||
*** Variables ***
|
||||
${HELPER} ${CURDIR}/helper_actor_remove_cli.py
|
||||
|
||||
*** Test Cases ***
|
||||
Actor Remove Format JSON Emits Spec Envelope
|
||||
[Documentation] Verify that ``actor remove --format json`` emits a spec-compliant envelope
|
||||
[Tags] actor_remove_cli_format
|
||||
${result}= Run Process ${PYTHON} ${HELPER} remove-json cwd=${WORKSPACE}
|
||||
Log ${result.stdout}
|
||||
Log ${result.stderr}
|
||||
Should Be Equal As Integers ${result.rc} 0
|
||||
Should Contain ${result.stdout} actor-remove-json-format-ok
|
||||
@@ -66,6 +66,82 @@ def main() -> int:
|
||||
print(f"actor-compiler-fail: {exc}")
|
||||
return 1
|
||||
|
||||
if command == "cycle-detect":
|
||||
# Test cross-actor cycle detection using actor_ref top-level field.
|
||||
# Creates two mutually-referencing actors and verifies SubgraphCycleError
|
||||
# is raised, confirming the fix for issue #1431.
|
||||
from cleveragents.actor.compiler import SubgraphCycleError
|
||||
from cleveragents.actor.schema import (
|
||||
ActorType,
|
||||
EdgeDefinition,
|
||||
NodeDefinition,
|
||||
NodeType,
|
||||
RouteDefinition,
|
||||
)
|
||||
|
||||
def _make_actor(
|
||||
name: str, subgraph_ref: str | None = None
|
||||
) -> ActorConfigSchema:
|
||||
if subgraph_ref is not None:
|
||||
nodes = [
|
||||
NodeDefinition(
|
||||
id="start",
|
||||
type=NodeType.AGENT,
|
||||
name="Start",
|
||||
description="Start",
|
||||
config={"agent": "default"},
|
||||
),
|
||||
NodeDefinition(
|
||||
id="sub",
|
||||
type=NodeType.SUBGRAPH,
|
||||
name="Sub",
|
||||
description="Subgraph",
|
||||
config={},
|
||||
actor_ref=subgraph_ref,
|
||||
),
|
||||
]
|
||||
edges = [EdgeDefinition(from_node="start", to_node="sub")]
|
||||
entry, exits = "start", ["sub"]
|
||||
else:
|
||||
nodes = [
|
||||
NodeDefinition(
|
||||
id="leaf",
|
||||
type=NodeType.AGENT,
|
||||
name="Leaf",
|
||||
description="Leaf",
|
||||
config={"agent": "default"},
|
||||
)
|
||||
]
|
||||
edges = []
|
||||
entry, exits = "leaf", ["leaf"]
|
||||
route = RouteDefinition(
|
||||
nodes=nodes, edges=edges, entry_node=entry, exit_nodes=exits
|
||||
)
|
||||
return ActorConfigSchema(
|
||||
name=name,
|
||||
type=ActorType.GRAPH,
|
||||
description=f"Test actor {name}",
|
||||
model="gpt-4",
|
||||
route=route,
|
||||
)
|
||||
|
||||
actor_a = _make_actor("test/actor-a", subgraph_ref="test/actor-b")
|
||||
actor_b = _make_actor("test/actor-b", subgraph_ref="test/actor-a")
|
||||
registry = {"test/actor-a": actor_a, "test/actor-b": actor_b}
|
||||
|
||||
try:
|
||||
compile_actor(actor_a, actor_resolver=registry.get)
|
||||
print(
|
||||
"actor-compiler-cycle-not-detected: FAIL — expected SubgraphCycleError"
|
||||
)
|
||||
return 1
|
||||
except SubgraphCycleError as exc:
|
||||
print(f"actor-compiler-cycle-detected: {exc}")
|
||||
return 0
|
||||
except Exception as exc:
|
||||
print(f"actor-compiler-unexpected-error: {exc}")
|
||||
return 1
|
||||
|
||||
print(f"Unknown command: {command}")
|
||||
return 1
|
||||
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
"""Helper script for Robot integration tests covering ``actor remove --format`` output.
|
||||
|
||||
Exercises the real ``agents`` CLI via subprocess — no mocking of any kind.
|
||||
A test actor is seeded via ``agents actor add``, then removed via
|
||||
``agents actor remove --format json``, and the resulting JSON envelope is
|
||||
validated against the spec.
|
||||
|
||||
Usage::
|
||||
|
||||
python helper_actor_remove_cli.py <command>
|
||||
|
||||
Where *command* is one of:
|
||||
|
||||
- ``remove-json`` — seed an actor, remove it with ``--format json``, validate envelope
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Ensure src is importable when run from workspace root
|
||||
_SRC = str(Path(__file__).resolve().parents[1] / "src")
|
||||
if _SRC not in sys.path:
|
||||
sys.path.insert(0, _SRC)
|
||||
|
||||
# Ensure robot/ is on the import path for helper_e2e_common.
|
||||
_ROBOT = str(Path(__file__).resolve().parent)
|
||||
if _ROBOT not in sys.path:
|
||||
sys.path.insert(0, _ROBOT)
|
||||
|
||||
from helper_e2e_common import cleanup_workspace, run_cli, setup_workspace # noqa: E402
|
||||
|
||||
_ACTOR_NAME = "local/robot-remove-actor"
|
||||
|
||||
_ACTOR_CONFIG: dict[str, object] = {
|
||||
"name": _ACTOR_NAME,
|
||||
"provider": "openai",
|
||||
"model": "gpt-4",
|
||||
}
|
||||
|
||||
|
||||
def _write_actor_config(workspace: str) -> str:
|
||||
"""Write actor config JSON to a temp file and return its path."""
|
||||
config_path = os.path.join(workspace, "robot_remove_actor.json")
|
||||
with open(config_path, "w", encoding="utf-8") as fh:
|
||||
json.dump(_ACTOR_CONFIG, fh)
|
||||
return config_path
|
||||
|
||||
|
||||
def test_remove_format_json() -> None:
|
||||
"""Seed an actor via the real CLI, remove it with ``--format json``.
|
||||
|
||||
Validates the resulting JSON envelope against the spec.
|
||||
"""
|
||||
workspace = setup_workspace(prefix="robot_actor_remove_")
|
||||
try:
|
||||
config_path = _write_actor_config(workspace)
|
||||
|
||||
# Step 1: Add the actor using the real CLI.
|
||||
add_result = run_cli(
|
||||
"actor",
|
||||
"add",
|
||||
_ACTOR_NAME,
|
||||
"--config",
|
||||
config_path,
|
||||
workspace=workspace,
|
||||
)
|
||||
assert add_result.returncode == 0, (
|
||||
f"actor add failed (rc={add_result.returncode}):\n"
|
||||
f"stdout: {add_result.stdout}\nstderr: {add_result.stderr}"
|
||||
)
|
||||
|
||||
# Step 2: Remove the actor with --format json using the real CLI.
|
||||
remove_result = run_cli(
|
||||
"actor",
|
||||
"remove",
|
||||
_ACTOR_NAME,
|
||||
"--format",
|
||||
"json",
|
||||
workspace=workspace,
|
||||
)
|
||||
assert remove_result.returncode == 0, (
|
||||
f"actor remove --format json failed (rc={remove_result.returncode}):\n"
|
||||
f"stdout: {remove_result.stdout}\nstderr: {remove_result.stderr}"
|
||||
)
|
||||
|
||||
# Step 3: Parse and validate the JSON envelope.
|
||||
output = remove_result.stdout.strip()
|
||||
assert output, (
|
||||
f"actor remove --format json produced no output.\n"
|
||||
f"stderr: {remove_result.stderr}"
|
||||
)
|
||||
|
||||
payload = json.loads(output)
|
||||
|
||||
assert payload["command"] == f"agents actor remove {_ACTOR_NAME}", (
|
||||
f"Unexpected command field: {payload.get('command')!r}"
|
||||
)
|
||||
assert payload["status"] == "ok", (
|
||||
f"Unexpected status: {payload.get('status')!r}"
|
||||
)
|
||||
assert payload["exit_code"] == 0, (
|
||||
f"Unexpected exit_code: {payload.get('exit_code')!r}"
|
||||
)
|
||||
|
||||
data = payload["data"]
|
||||
|
||||
removed = data.get("actor_removed", {})
|
||||
assert removed.get("name") == _ACTOR_NAME, (
|
||||
f"actor_removed.name mismatch: {removed.get('name')!r}"
|
||||
)
|
||||
assert removed.get("provider") == _ACTOR_CONFIG["provider"], (
|
||||
f"actor_removed.provider mismatch: {removed.get('provider')!r}"
|
||||
)
|
||||
assert removed.get("model") == _ACTOR_CONFIG["model"], (
|
||||
f"actor_removed.model mismatch: {removed.get('model')!r}"
|
||||
)
|
||||
|
||||
impact = data.get("impact", {})
|
||||
assert "sessions" in impact, f"Missing 'sessions' in impact: {impact}"
|
||||
assert "active_plans" in impact, f"Missing 'active_plans' in impact: {impact}"
|
||||
assert "actions_referencing" in impact, (
|
||||
f"Missing 'actions_referencing' in impact: {impact}"
|
||||
)
|
||||
|
||||
cleanup = data.get("cleanup", {})
|
||||
assert cleanup.get("config") == "kept on disk", (
|
||||
f"cleanup.config mismatch: {cleanup.get('config')!r}"
|
||||
)
|
||||
assert "contexts" in cleanup, f"Missing 'contexts' in cleanup: {cleanup}"
|
||||
|
||||
messages = payload.get("messages", [])
|
||||
assert messages, f"Expected non-empty messages list, got: {messages}"
|
||||
assert messages[0].get("level") == "ok", (
|
||||
f"Unexpected message level: {messages[0].get('level')!r}"
|
||||
)
|
||||
assert "Actor removed" in messages[0].get("text", ""), (
|
||||
f"Expected 'Actor removed' in message text: {messages[0].get('text')!r}"
|
||||
)
|
||||
|
||||
print("actor-remove-json-format-ok")
|
||||
|
||||
finally:
|
||||
cleanup_workspace(workspace)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
command = sys.argv[1] if len(sys.argv) > 1 else "remove-json"
|
||||
dispatch: dict[str, object] = {
|
||||
"remove-json": test_remove_format_json,
|
||||
}
|
||||
handler = dispatch.get(command)
|
||||
if handler is None:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
assert callable(handler)
|
||||
handler()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -867,7 +867,6 @@ def invariants_enforced_during_strategize() -> None:
|
||||
|
||||
merged = merge_invariants(
|
||||
plan_invariants=[plan_inv],
|
||||
action_invariants=[],
|
||||
project_invariants=[project_inv],
|
||||
global_invariants=[global_inv],
|
||||
)
|
||||
@@ -891,7 +890,6 @@ def invariants_enforced_during_strategize() -> None:
|
||||
|
||||
invariant_set = InvariantSet.merge(
|
||||
plan_invariants=[plan_inv],
|
||||
action_invariants=[],
|
||||
project_invariants=[project_inv],
|
||||
global_invariants=[global_inv],
|
||||
)
|
||||
|
||||
@@ -5,12 +5,22 @@ technology-specific vocabulary extensions, and the DetailLevelMap
|
||||
inheritance mechanism for resolving named detail levels across the
|
||||
ontology hierarchy (Layer 3 -> Layer 2 -> Layer 1 -> Layer 0).
|
||||
|
||||
Also provides the ACMS index data model and file traversal engine for
|
||||
indexing large projects.
|
||||
|
||||
Based on ``docs/specification.md`` ~lines 42333-42422, 44405-44420.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from cleveragents.acms import uko as _uko
|
||||
from cleveragents.acms.index import (
|
||||
ACMSIndex,
|
||||
FileTraversalEngine,
|
||||
FileType,
|
||||
IndexEntry,
|
||||
TierLevel,
|
||||
)
|
||||
from cleveragents.acms.uko import (
|
||||
CODE_DETAIL_LEVEL_MAP,
|
||||
FUNC_DETAIL_LEVEL_MAP,
|
||||
@@ -62,6 +72,14 @@ from cleveragents.acms.uko import (
|
||||
resolve_detail_level,
|
||||
)
|
||||
|
||||
# Re-export everything published by the ``uko`` sub-package so the two
|
||||
# ``__all__`` lists stay in sync automatically.
|
||||
__all__: list[str] = list(_uko.__all__)
|
||||
# Combine exports from both uko and index modules
|
||||
_uko_exports = list(_uko.__all__)
|
||||
_index_exports = [
|
||||
"ACMSIndex",
|
||||
"FileTraversalEngine",
|
||||
"FileType",
|
||||
"IndexEntry",
|
||||
"TierLevel",
|
||||
]
|
||||
|
||||
__all__: list[str] = _uko_exports + _index_exports
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
"""ACMS Index Data Model and File Traversal Engine.
|
||||
|
||||
Provides the foundational data model for indexed context entries and a
|
||||
file traversal engine that can handle 10,000+ files without timeout using
|
||||
chunked processing.
|
||||
|
||||
Based on issue #9579 and ``docs/specification.md`` ~lines 44405-44420.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from enum import StrEnum
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class FileType(StrEnum):
|
||||
"""File type enumeration for index entries."""
|
||||
|
||||
PYTHON = "python"
|
||||
JAVASCRIPT = "javascript"
|
||||
TYPESCRIPT = "typescript"
|
||||
JAVA = "java"
|
||||
RUST = "rust"
|
||||
MARKDOWN = "markdown"
|
||||
TEXT = "text"
|
||||
JSON = "json"
|
||||
YAML = "yaml"
|
||||
XML = "xml"
|
||||
OTHER = "other"
|
||||
|
||||
|
||||
class TierLevel(StrEnum):
|
||||
"""Tier assignment levels for context entries.
|
||||
|
||||
Aligns with the hot/warm/cold storage tier vocabulary used throughout
|
||||
the ACMS specification and milestone v3.4.0 acceptance criteria.
|
||||
"""
|
||||
|
||||
HOT = "hot" # Core/essential
|
||||
WARM = "warm" # Important
|
||||
COLD = "cold" # Supporting
|
||||
ARCHIVE = "archive" # Reference
|
||||
|
||||
|
||||
@dataclass
|
||||
class IndexEntry:
|
||||
"""Represents a single indexed context entry.
|
||||
|
||||
Attributes:
|
||||
path: Absolute or relative file path
|
||||
file_type: Type of file (from FileType enum)
|
||||
size_bytes: File size in bytes
|
||||
created_at: File creation timestamp
|
||||
modified_at: File modification timestamp
|
||||
tags: Set of tags for categorization
|
||||
tier: Tier assignment level
|
||||
metadata: Additional metadata dictionary
|
||||
"""
|
||||
|
||||
path: str
|
||||
file_type: FileType
|
||||
size_bytes: int
|
||||
created_at: datetime
|
||||
modified_at: datetime
|
||||
tags: set[str] = field(default_factory=set)
|
||||
tier: TierLevel = TierLevel.COLD
|
||||
metadata: dict[str, str] = field(default_factory=dict)
|
||||
|
||||
def add_tag(self, tag: str) -> None:
|
||||
"""Add a tag to this entry.
|
||||
|
||||
Args:
|
||||
tag: Tag string to add. Must be non-empty.
|
||||
|
||||
Raises:
|
||||
ValueError: If tag is empty or whitespace-only.
|
||||
"""
|
||||
if not tag or not tag.strip():
|
||||
raise ValueError("tag must be a non-empty string")
|
||||
self.tags.add(tag)
|
||||
|
||||
def remove_tag(self, tag: str) -> None:
|
||||
"""Remove a tag from this entry.
|
||||
|
||||
Args:
|
||||
tag: Tag string to remove. Must be non-empty.
|
||||
|
||||
Raises:
|
||||
ValueError: If tag is empty or whitespace-only.
|
||||
"""
|
||||
if not tag or not tag.strip():
|
||||
raise ValueError("tag must be a non-empty string")
|
||||
self.tags.discard(tag)
|
||||
|
||||
def has_tag(self, tag: str) -> bool:
|
||||
"""Check if entry has a specific tag."""
|
||||
return tag in self.tags
|
||||
|
||||
def set_tier(self, tier: TierLevel) -> None:
|
||||
"""Set the tier level for this entry."""
|
||||
self.tier = tier
|
||||
|
||||
|
||||
@dataclass
|
||||
class ACMSIndex:
|
||||
"""ACMS Index for storing and querying indexed context entries.
|
||||
|
||||
Provides storage and query capabilities for indexed files with support
|
||||
for filtering by path, tags, type, and recency.
|
||||
|
||||
Attributes:
|
||||
entries: Dictionary mapping file paths to IndexEntry objects
|
||||
"""
|
||||
|
||||
entries: dict[str, IndexEntry] = field(default_factory=dict)
|
||||
|
||||
def add_entry(self, entry: IndexEntry) -> None:
|
||||
"""Add an index entry to the index.
|
||||
|
||||
Args:
|
||||
entry: The IndexEntry to add. Must not be None.
|
||||
|
||||
Raises:
|
||||
TypeError: If entry is not an IndexEntry instance.
|
||||
"""
|
||||
if not isinstance(entry, IndexEntry):
|
||||
raise TypeError(
|
||||
f"entry must be an IndexEntry instance, got {type(entry).__name__}"
|
||||
)
|
||||
self.entries[entry.path] = entry
|
||||
|
||||
def remove_entry(self, path: str) -> bool:
|
||||
"""Remove an entry by path. Returns True if removed, False if not found."""
|
||||
if path in self.entries:
|
||||
del self.entries[path]
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_entry(self, path: str) -> IndexEntry | None:
|
||||
"""Get an entry by path."""
|
||||
return self.entries.get(path)
|
||||
|
||||
def query_by_path(self, path_pattern: str) -> list[IndexEntry]:
|
||||
"""Query entries by path pattern (substring match).
|
||||
|
||||
Args:
|
||||
path_pattern: Substring pattern to match against entry paths.
|
||||
Must be non-empty.
|
||||
|
||||
Raises:
|
||||
ValueError: If path_pattern is empty or whitespace-only.
|
||||
"""
|
||||
if not path_pattern or not path_pattern.strip():
|
||||
raise ValueError("path_pattern must be a non-empty string")
|
||||
return [entry for entry in self.entries.values() if path_pattern in entry.path]
|
||||
|
||||
def query_by_tag(self, tag: str) -> list[IndexEntry]:
|
||||
"""Query entries by tag."""
|
||||
return [entry for entry in self.entries.values() if entry.has_tag(tag)]
|
||||
|
||||
def query_by_type(self, file_type: FileType) -> list[IndexEntry]:
|
||||
"""Query entries by file type."""
|
||||
return [
|
||||
entry for entry in self.entries.values() if entry.file_type == file_type
|
||||
]
|
||||
|
||||
def query_by_tier(self, tier: TierLevel) -> list[IndexEntry]:
|
||||
"""Query entries by tier level."""
|
||||
return [entry for entry in self.entries.values() if entry.tier == tier]
|
||||
|
||||
def query_by_recency(
|
||||
self, after: datetime, before: datetime | None = None
|
||||
) -> list[IndexEntry]:
|
||||
"""Query entries by modification recency.
|
||||
|
||||
Args:
|
||||
after: Return entries modified after this datetime.
|
||||
before: Return entries modified before this datetime (optional).
|
||||
When both are provided, before must be >= after.
|
||||
|
||||
Returns:
|
||||
List of entries matching the recency criteria.
|
||||
|
||||
Raises:
|
||||
ValueError: If before is earlier than after when both are provided.
|
||||
"""
|
||||
if before is not None and before < after:
|
||||
raise ValueError(
|
||||
f"before ({before}) must be >= after ({after}) when both are provided"
|
||||
)
|
||||
results = [
|
||||
entry for entry in self.entries.values() if entry.modified_at >= after
|
||||
]
|
||||
if before:
|
||||
results = [entry for entry in results if entry.modified_at <= before]
|
||||
return results
|
||||
|
||||
def query_combined(
|
||||
self,
|
||||
path_pattern: str | None = None,
|
||||
tags: set[str] | None = None,
|
||||
file_type: FileType | None = None,
|
||||
tier: TierLevel | None = None,
|
||||
after: datetime | None = None,
|
||||
) -> list[IndexEntry]:
|
||||
"""Query entries with multiple filters (AND logic).
|
||||
|
||||
Args:
|
||||
path_pattern: Filter by path pattern
|
||||
tags: Filter by any of these tags
|
||||
file_type: Filter by file type
|
||||
tier: Filter by tier level
|
||||
after: Filter by modification date
|
||||
|
||||
Returns:
|
||||
List of entries matching all specified criteria
|
||||
"""
|
||||
results = list(self.entries.values())
|
||||
|
||||
if path_pattern:
|
||||
results = [entry for entry in results if path_pattern in entry.path]
|
||||
|
||||
if tags:
|
||||
results = [
|
||||
entry for entry in results if any(tag in entry.tags for tag in tags)
|
||||
]
|
||||
|
||||
if file_type:
|
||||
results = [entry for entry in results if entry.file_type == file_type]
|
||||
|
||||
if tier:
|
||||
results = [entry for entry in results if entry.tier == tier]
|
||||
|
||||
if after:
|
||||
results = [entry for entry in results if entry.modified_at >= after]
|
||||
|
||||
return results
|
||||
|
||||
def get_all_entries(self) -> list[IndexEntry]:
|
||||
"""Get all entries in the index."""
|
||||
return list(self.entries.values())
|
||||
|
||||
def get_entry_count(self) -> int:
|
||||
"""Get the total number of entries in the index."""
|
||||
return len(self.entries)
|
||||
|
||||
|
||||
class FileTraversalEngine:
|
||||
"""Engine for traversing and indexing files in large projects.
|
||||
|
||||
Handles 10,000+ files without timeout using chunked processing to
|
||||
prevent memory exhaustion.
|
||||
|
||||
Attributes:
|
||||
chunk_size: Number of files to process in each chunk
|
||||
index: The ACMS index to populate
|
||||
"""
|
||||
|
||||
def __init__(self, chunk_size: int = 100, index: ACMSIndex | None = None) -> None:
|
||||
"""Initialize the traversal engine.
|
||||
|
||||
Args:
|
||||
chunk_size: Number of files to process per chunk (default: 100).
|
||||
Must be a positive integer.
|
||||
index: Optional pre-populated ACMSIndex to use. If None, a new
|
||||
empty index is created (supports Dependency Inversion).
|
||||
|
||||
Raises:
|
||||
ValueError: If chunk_size is not a positive integer.
|
||||
"""
|
||||
if chunk_size <= 0:
|
||||
raise ValueError(f"chunk_size must be a positive integer, got {chunk_size}")
|
||||
self.chunk_size = chunk_size
|
||||
self.index = index if index is not None else ACMSIndex()
|
||||
|
||||
def _get_file_type(self, file_path: Path) -> FileType:
|
||||
"""Determine file type from extension."""
|
||||
suffix = file_path.suffix.lower()
|
||||
type_map = {
|
||||
".py": FileType.PYTHON,
|
||||
".js": FileType.JAVASCRIPT,
|
||||
".ts": FileType.TYPESCRIPT,
|
||||
".tsx": FileType.TYPESCRIPT,
|
||||
".java": FileType.JAVA,
|
||||
".rs": FileType.RUST,
|
||||
".md": FileType.MARKDOWN,
|
||||
".txt": FileType.TEXT,
|
||||
".json": FileType.JSON,
|
||||
".yaml": FileType.YAML,
|
||||
".yml": FileType.YAML,
|
||||
".xml": FileType.XML,
|
||||
}
|
||||
return type_map.get(suffix, FileType.OTHER)
|
||||
|
||||
def _create_index_entry(self, file_path: Path) -> IndexEntry | None:
|
||||
"""Create an index entry from a file path.
|
||||
|
||||
Args:
|
||||
file_path: Path to the file
|
||||
|
||||
Returns:
|
||||
IndexEntry if successful, None if file cannot be read
|
||||
"""
|
||||
try:
|
||||
stat = file_path.stat()
|
||||
return IndexEntry(
|
||||
path=str(file_path),
|
||||
file_type=self._get_file_type(file_path),
|
||||
size_bytes=stat.st_size,
|
||||
created_at=datetime.fromtimestamp(stat.st_ctime),
|
||||
modified_at=datetime.fromtimestamp(stat.st_mtime),
|
||||
)
|
||||
except (OSError, ValueError):
|
||||
return None
|
||||
|
||||
def _traverse_directory(
|
||||
self,
|
||||
root_path: Path,
|
||||
) -> Iterator[Path]:
|
||||
"""Recursively traverse directory and yield file paths.
|
||||
|
||||
Args:
|
||||
root_path: Root directory to traverse
|
||||
|
||||
Yields:
|
||||
Path objects for each file found
|
||||
"""
|
||||
try:
|
||||
for item in root_path.iterdir():
|
||||
if item.is_file():
|
||||
yield item
|
||||
elif item.is_dir():
|
||||
# Recursively traverse subdirectories
|
||||
yield from self._traverse_directory(item)
|
||||
except (OSError, PermissionError):
|
||||
# Skip directories we can't read
|
||||
pass
|
||||
|
||||
def traverse_and_index(
|
||||
self,
|
||||
root_path: str | Path,
|
||||
exclude_patterns: list[str] | None = None,
|
||||
) -> ACMSIndex:
|
||||
"""Traverse a directory and index all files.
|
||||
|
||||
Uses chunked processing to handle large projects without timeout
|
||||
or memory exhaustion.
|
||||
|
||||
Args:
|
||||
root_path: Root directory to traverse
|
||||
exclude_patterns: List of patterns to exclude
|
||||
(e.g., ['.git', '__pycache__'])
|
||||
|
||||
Returns:
|
||||
Populated ACMSIndex
|
||||
"""
|
||||
root = Path(root_path)
|
||||
if not root.exists():
|
||||
raise ValueError(f"Path does not exist: {root_path}")
|
||||
|
||||
exclude_patterns = exclude_patterns or []
|
||||
chunk: list[IndexEntry] = []
|
||||
|
||||
for file_path in self._traverse_directory(root):
|
||||
# Check if file matches any exclude pattern
|
||||
if any(pattern in str(file_path) for pattern in exclude_patterns):
|
||||
continue
|
||||
|
||||
# Create index entry
|
||||
entry = self._create_index_entry(file_path)
|
||||
if entry:
|
||||
chunk.append(entry)
|
||||
|
||||
# Process chunk when it reaches the size limit
|
||||
if len(chunk) >= self.chunk_size:
|
||||
self._process_chunk(chunk)
|
||||
chunk = []
|
||||
|
||||
# Process remaining entries
|
||||
if chunk:
|
||||
self._process_chunk(chunk)
|
||||
|
||||
return self.index
|
||||
|
||||
def _process_chunk(self, chunk: list[IndexEntry]) -> None:
|
||||
"""Process a chunk of index entries.
|
||||
|
||||
Args:
|
||||
chunk: List of IndexEntry objects to add to the index
|
||||
"""
|
||||
for entry in chunk:
|
||||
self.index.add_entry(entry)
|
||||
|
||||
def get_index(self) -> ACMSIndex:
|
||||
"""Get the current index."""
|
||||
return self.index
|
||||
|
||||
def reset_index(self) -> None:
|
||||
"""Reset the index to empty state."""
|
||||
self.index = ACMSIndex()
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ACMSIndex",
|
||||
"FileTraversalEngine",
|
||||
"FileType",
|
||||
"IndexEntry",
|
||||
"TierLevel",
|
||||
]
|
||||
@@ -137,7 +137,7 @@ def _map_node(node: NodeDefinition) -> lg_nodes.NodeConfig:
|
||||
config.get("function") if node.type == NodeType.CONDITIONAL else None
|
||||
),
|
||||
tools=config.get("tools", []) if node.type == NodeType.TOOL else [],
|
||||
subgraph=(config.get("actor_ref") if node.type == NodeType.SUBGRAPH else None),
|
||||
subgraph=(node.actor_ref if node.type == NodeType.SUBGRAPH else None),
|
||||
metadata=dict(config),
|
||||
)
|
||||
|
||||
@@ -187,6 +187,11 @@ def _detect_subgraph_cycles(
|
||||
"""Detect cycles in subgraph references across actors.
|
||||
|
||||
Returns list of actor names forming a cycle, or empty list.
|
||||
|
||||
The actor reference is read from the top-level actor_ref field on
|
||||
NodeDefinition, not from node.config. Reading from config
|
||||
would always return an empty string because actor_ref is stored as a
|
||||
first-class field on the schema model.
|
||||
"""
|
||||
if resolver is None:
|
||||
return []
|
||||
@@ -194,7 +199,7 @@ def _detect_subgraph_cycles(
|
||||
for node in route_nodes:
|
||||
if node.type != NodeType.SUBGRAPH:
|
||||
continue
|
||||
ref_name = node.config.get("actor_ref", "")
|
||||
ref_name = node.actor_ref or ""
|
||||
if not ref_name:
|
||||
continue
|
||||
if ref_name in visited:
|
||||
@@ -290,7 +295,7 @@ def compile_actor(
|
||||
all_lsp_bindings.extend(bindings)
|
||||
|
||||
if node_def.type == NodeType.SUBGRAPH:
|
||||
ref = node_def.config.get("actor_ref", "")
|
||||
ref = node_def.actor_ref or ""
|
||||
if ref:
|
||||
subgraph_refs[node_def.id] = ref
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ a dict keyed by invariant ID.
|
||||
|
||||
## Merge Precedence
|
||||
|
||||
Effective invariants are computed using plan > action > project > global order.
|
||||
Effective invariants are computed using plan > project > global order.
|
||||
See ``merge_invariants`` for de-duplication semantics.
|
||||
|
||||
Based on ``docs/specification.md`` and implementation plan Stage M3.5.
|
||||
@@ -124,7 +124,6 @@ class InvariantService:
|
||||
if effective:
|
||||
return self.get_effective_invariants(
|
||||
plan_id=source_name if scope == InvariantScope.PLAN else None,
|
||||
action_name=source_name if scope == InvariantScope.ACTION else None,
|
||||
project_name=source_name if scope == InvariantScope.PROJECT else None,
|
||||
)
|
||||
|
||||
@@ -168,19 +167,16 @@ class InvariantService:
|
||||
def get_effective_invariants(
|
||||
self,
|
||||
plan_id: str | None = None,
|
||||
action_name: str | None = None,
|
||||
project_name: str | None = None,
|
||||
) -> list[Invariant]:
|
||||
"""Return the merged precedence chain for a plan/action/project context.
|
||||
"""Return the merged precedence chain for a plan/project context.
|
||||
|
||||
Collects active invariants from each scope tier and merges them
|
||||
using plan > action > project > global precedence.
|
||||
using plan > project > global precedence.
|
||||
|
||||
Args:
|
||||
plan_id: Optional plan identifier to collect plan-scoped
|
||||
invariants.
|
||||
action_name: Optional action name to collect action-scoped
|
||||
invariants.
|
||||
project_name: Optional project name to collect project-scoped
|
||||
invariants.
|
||||
|
||||
@@ -195,12 +191,6 @@ class InvariantService:
|
||||
if inv.scope == InvariantScope.PLAN
|
||||
and (plan_id is None or inv.source_name == plan_id)
|
||||
]
|
||||
action_invs = [
|
||||
inv
|
||||
for inv in active
|
||||
if inv.scope == InvariantScope.ACTION
|
||||
and (action_name is None or inv.source_name == action_name)
|
||||
]
|
||||
project_invs = [
|
||||
inv
|
||||
for inv in active
|
||||
@@ -209,7 +199,7 @@ class InvariantService:
|
||||
]
|
||||
global_invs = [inv for inv in active if inv.scope == InvariantScope.GLOBAL]
|
||||
|
||||
return merge_invariants(plan_invs, action_invs, project_invs, global_invs)
|
||||
return merge_invariants(plan_invs, project_invs, global_invs)
|
||||
|
||||
def enforce_invariants(
|
||||
self,
|
||||
|
||||
@@ -816,12 +816,28 @@ def update(
|
||||
|
||||
|
||||
@app.command()
|
||||
def remove(name: Annotated[str, typer.Argument(help="Actor name to remove")]) -> None:
|
||||
def remove(
|
||||
name: Annotated[str, typer.Argument(help="Actor name to remove")],
|
||||
fmt: Annotated[
|
||||
str,
|
||||
typer.Option("--format", "-f", help=_FORMAT_HELP),
|
||||
] = OutputFormat.RICH.value,
|
||||
) -> None:
|
||||
"""Remove a custom actor.
|
||||
|
||||
Specify the namespaced name (e.g. ``local/my-actor``).
|
||||
"""
|
||||
|
||||
# Validate --format argument first; fail fast before any side effects.
|
||||
fmt_value = fmt.lower()
|
||||
_valid_formats = {f.value for f in OutputFormat}
|
||||
if fmt_value not in _valid_formats:
|
||||
raise typer.BadParameter(
|
||||
f"Invalid format {fmt!r}. "
|
||||
f"Supported values: {', '.join(sorted(_valid_formats))}",
|
||||
param_hint="'--format'",
|
||||
)
|
||||
|
||||
service, registry = _get_services()
|
||||
try:
|
||||
# Get actor details before removal for display
|
||||
@@ -844,6 +860,40 @@ def remove(name: Annotated[str, typer.Argument(help="Actor name to remove")]) ->
|
||||
else:
|
||||
service.remove_actor(name)
|
||||
|
||||
command_name = f"agents actor remove {name}"
|
||||
payload = {
|
||||
"actor_removed": {
|
||||
"name": name,
|
||||
"provider": actor_provider,
|
||||
"model": actor_model,
|
||||
},
|
||||
"impact": {
|
||||
"sessions": session_count,
|
||||
"active_plans": active_plan_count,
|
||||
"actions_referencing": action_count,
|
||||
},
|
||||
"cleanup": {
|
||||
"config": "kept on disk",
|
||||
# NOTE: context-cleanup count is deferred; always 0 for now.
|
||||
# Follow-up: implement dynamic orphaned-context detection.
|
||||
"contexts": "0 orphaned",
|
||||
},
|
||||
}
|
||||
messages = [{"level": "ok", "text": "Actor removed"}]
|
||||
|
||||
if fmt_value != OutputFormat.RICH.value:
|
||||
rendered = format_output(
|
||||
payload,
|
||||
fmt_value,
|
||||
command=command_name,
|
||||
status="ok",
|
||||
exit_code=0,
|
||||
messages=messages,
|
||||
)
|
||||
if rendered:
|
||||
console.print(rendered)
|
||||
return
|
||||
|
||||
# Display Actor Removed panel
|
||||
actor_info = (
|
||||
f"[cyan bold]Name:[/cyan bold] {name}\n"
|
||||
|
||||
@@ -176,7 +176,6 @@ def list_invariants(
|
||||
agents invariant list
|
||||
agents invariant list --global
|
||||
agents invariant list --effective --project myapp
|
||||
agents invariant list --effective --action deploy-service
|
||||
agents invariant list "data.*safe"
|
||||
"""
|
||||
try:
|
||||
|
||||
@@ -10,6 +10,7 @@ Commands:
|
||||
- ``agents project list [--namespace NS] [REGEX]``
|
||||
- ``agents project show <project>``
|
||||
- ``agents project delete [--force|-f] [--yes|-y] <name>``
|
||||
- ``agents project switch <name>`` — select a project as active context
|
||||
|
||||
Legacy file-filter sub-app is preserved for backward compatibility.
|
||||
|
||||
@@ -39,6 +40,11 @@ from cleveragents.core.exceptions import (
|
||||
ValidationError,
|
||||
)
|
||||
|
||||
from cleveragents.cli.commands.project_switch import switch_project
|
||||
|
||||
|
||||
_FORMAT_HELP = "Output format: json, yaml, plain, or rich (default: rich)"
|
||||
|
||||
# Create sub-app for project commands
|
||||
app = typer.Typer(help="Project management commands")
|
||||
file_filter_app = typer.Typer(
|
||||
@@ -47,8 +53,7 @@ file_filter_app = typer.Typer(
|
||||
console = _get_console()
|
||||
err_console = _get_err_console()
|
||||
|
||||
# Reusable --format option description
|
||||
_FORMAT_HELP = "Output format: json, yaml, plain, table, or rich (default: rich)"
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -257,11 +262,11 @@ def init_command(
|
||||
expand=False,
|
||||
)
|
||||
)
|
||||
console.print("[green]✓ OK[/green] Initialized (non-interactive)")
|
||||
console.print("[green] OK[/green] Initialized (non-interactive)")
|
||||
else:
|
||||
console.print(
|
||||
Panel(
|
||||
f"[green]✓[/green] Project '{project.name}' "
|
||||
f"[green][/] Project '{project.name}' "
|
||||
f"initialized successfully!\n\n"
|
||||
f"Location: {project.path / '.cleveragents'}\n"
|
||||
f"Database: SQLite\n"
|
||||
@@ -637,7 +642,7 @@ def create(
|
||||
if output_format.lower() == OutputFormat.RICH:
|
||||
console.print(
|
||||
Panel(
|
||||
f"[green]✓[/green] Project '{created.namespaced_name}' created.\n"
|
||||
f"[green][/green] Project '{created.namespaced_name}' created.\n"
|
||||
f"Namespace: {created.namespace}\n"
|
||||
f"Description: {created.description or '(none)'}\n"
|
||||
f"Resources: {len(created.linked_resources)}",
|
||||
@@ -706,7 +711,7 @@ def link_resource(
|
||||
if output_format.lower() == OutputFormat.RICH:
|
||||
ro_label = " (read-only)" if read_only else ""
|
||||
console.print(
|
||||
f"[green]✓[/green] Linked resource '{resource_name}'{ro_label} "
|
||||
f"[green][/green] Linked resource '{resource_name}'{ro_label} "
|
||||
f"to project '{project}'."
|
||||
)
|
||||
else:
|
||||
@@ -792,7 +797,7 @@ def unlink_resource(
|
||||
|
||||
if output_format.lower() == OutputFormat.RICH:
|
||||
console.print(
|
||||
f"[green]✓[/green] Unlinked resource '{resource_name}' "
|
||||
f"[green][/green] Unlinked resource '{resource_name}' "
|
||||
f"from project '{project}'."
|
||||
)
|
||||
else:
|
||||
@@ -979,7 +984,7 @@ def delete(
|
||||
raise typer.Exit(1)
|
||||
|
||||
if output_format.lower() == OutputFormat.RICH:
|
||||
console.print(f"[green]✓[/green] Project '{name}' deleted.")
|
||||
console.print(f"[green][/green] Project '{name}' deleted.")
|
||||
else:
|
||||
console.print(
|
||||
format_output(
|
||||
@@ -991,3 +996,28 @@ def delete(
|
||||
output_format,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@app.command(name="switch")
|
||||
def switch(
|
||||
name: Annotated[
|
||||
str,
|
||||
typer.Argument(help="Project namespaced name to switch to"),
|
||||
],
|
||||
output_format: Annotated[
|
||||
str,
|
||||
typer.Option("--format", "-f", help=_FORMAT_HELP),
|
||||
] = "rich",
|
||||
) -> None:
|
||||
"""Switch the active project context.
|
||||
|
||||
Selects the named ``namespaced_name`` project (e.g. ``local/my-proj``
|
||||
or ``team/svc``) as the active project. The selection is persisted so
|
||||
all subsequent CLI commands operate against this project by default.
|
||||
|
||||
Requires a project to exist in the registry; exits with an error and
|
||||
a clear message when the project is not found.
|
||||
|
||||
Based on Forgejo issue #8623 / PR #8675.
|
||||
"""
|
||||
switch_project(name=name, output_format=output_format)
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
"""Project switch command for CleverAgents CLI.
|
||||
|
||||
Implements ``agents project switch <name>`` to change the active/current
|
||||
project context. This allows users to operate on any registered project
|
||||
from any working directory without needing to ``cd`` into it first.
|
||||
|
||||
Based on Forgejo issue #8623 (bug: agents project switch missing).
|
||||
|
||||
Commands:
|
||||
- ``agents project switch <name>`` - select a project as the active context
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from typing import Any
|
||||
|
||||
import typer
|
||||
|
||||
from cleveragents.cli.formatting import OutputFormat, format_output
|
||||
from cleveragents.cli.renderers import _get_console, _get_err_console
|
||||
|
||||
console = _get_console()
|
||||
err_console = _get_err_console()
|
||||
|
||||
_FORMAT_HELP = "Output format: json, yaml, plain, table, or rich (default: rich)"
|
||||
|
||||
|
||||
def switch_project(
|
||||
name: str,
|
||||
output_format: str = "rich",
|
||||
) -> None:
|
||||
"""Switch the active project context to another project.
|
||||
|
||||
NAME is a ``namespaced_name`` (e.g. ``local/my-proj`` or
|
||||
``team/svc``). The command validates that the project exists in
|
||||
the registry and, if so, persistently records the selection so
|
||||
subsequent CLI calls operate against this context by default.
|
||||
|
||||
Args:
|
||||
name: Project namespaced name to switch to.
|
||||
output_format: Output format (rich, json, yaml, plain).
|
||||
"""
|
||||
from cleveragents.application.container import get_container
|
||||
|
||||
container = get_container()
|
||||
|
||||
# Resolve namespaced-project service
|
||||
svc = container.namespaced_project_service() if hasattr(container, 'namespaced_project_service') else None
|
||||
if svc is None:
|
||||
# Fall back to getting service via helper
|
||||
from cleveragents.cli.commands.project import _get_namespaced_project_service
|
||||
svc = _get_namespaced_project_service()
|
||||
|
||||
# Validate project exists
|
||||
try:
|
||||
proj = svc.get_project(name)
|
||||
except Exception as exc:
|
||||
err_console.print(f"[red]Project not found:[/red] {name}")
|
||||
raise typer.Exit(1) from exc
|
||||
|
||||
# Persist active-project selection via the project's .cleveragents dir
|
||||
proj_path = getattr(proj, 'path', None) or getattr(proj, 'local_path', None)
|
||||
if proj_path is not None:
|
||||
_persist_active_project(Path(proj_path), name)
|
||||
else:
|
||||
# Fallback: write to cwd project marker
|
||||
try:
|
||||
_persist_active_project(Path.cwd(), name)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
data = svc.project_to_dict(proj)
|
||||
|
||||
if output_format.lower() == OutputFormat.RICH:
|
||||
console.print(
|
||||
f"[green]Active project switched to "
|
||||
f"'{proj.namespaced_name}' ({proj.namespace}/{proj.name}).[/green]"
|
||||
)
|
||||
else:
|
||||
console.print(format_output(data, output_format))
|
||||
|
||||
|
||||
def _persist_active_project(project_dir: Path, namespaced_name: str) -> None:
|
||||
"""Persist the project name to {project_dir}/.cleveragents/project.name.
|
||||
|
||||
Args:
|
||||
project_dir: The resolved path of the project directory to use as context.
|
||||
namespaced_name: The project's namespaced name to persist.
|
||||
"""
|
||||
# Write project name inside the project's .cleveragents dir
|
||||
clever_dir = project_dir / ".cleveragents"
|
||||
try:
|
||||
clever_dir.mkdir(parents=True, exist_ok=True)
|
||||
except OSError:
|
||||
return
|
||||
|
||||
name_file = clever_dir / "project.name"
|
||||
try:
|
||||
name_file.write_text(namespaced_name, encoding="utf-8")
|
||||
except OSError:
|
||||
pass # Silently fail on write
|
||||
@@ -1,11 +1,10 @@
|
||||
"""Invariant domain models for CleverAgents.
|
||||
|
||||
Invariants are natural-language constraints on plan execution, scoped at
|
||||
global, project, action, or plan level. ACTION invariants participate
|
||||
directly in the 4-tier merge chain rather than being promoted to plan-level.
|
||||
The runtime precedence chain is:
|
||||
global, project, action, or plan level. When an action is used, its
|
||||
invariants are promoted to plan-level. The runtime precedence chain is:
|
||||
|
||||
plan > action > project > global
|
||||
plan > project > global
|
||||
|
||||
They are reconciled by the Invariant Reconciliation Actor at the start
|
||||
of Strategize and recorded as ``invariant_enforced`` decisions.
|
||||
@@ -16,17 +15,14 @@ of Strategize and recorded as ``invariant_enforced`` decisions.
|
||||
|------------|----------------------------------------------------|
|
||||
| ``GLOBAL`` | Applies to every plan in the system |
|
||||
| ``PROJECT``| Applies to plans targeting a specific project |
|
||||
| ``ACTION`` | Defined in an action template; between PLAN and PROJECT in precedence |
|
||||
| ``ACTION`` | Defined in an action template; promoted on ``use`` |
|
||||
| ``PLAN`` | Attached directly to a specific plan |
|
||||
|
||||
## Merge Precedence
|
||||
|
||||
When computing the effective set of invariants for a plan, the merge
|
||||
order is **plan > action > project > global**. Action-scoped invariants
|
||||
sit between plan and project in the precedence chain — they override
|
||||
project and global constraints but are themselves overridden by
|
||||
plan-level constraints. Duplicate texts (case-insensitive) are
|
||||
de-duplicated, keeping the highest-precedence copy.
|
||||
order is **plan > project > global**. Duplicate texts (case-insensitive)
|
||||
are de-duplicated, keeping the highest-precedence copy.
|
||||
|
||||
Based on ``docs/specification.md`` and implementation plan Stage M3.5.
|
||||
"""
|
||||
@@ -43,9 +39,8 @@ from ulid import ULID
|
||||
class InvariantScope(StrEnum):
|
||||
"""Scope at which an invariant applies.
|
||||
|
||||
Precedence (highest to lowest): PLAN > ACTION > PROJECT > GLOBAL.
|
||||
ACTION invariants participate directly in the 4-tier merge chain,
|
||||
sitting between PLAN and PROJECT in precedence order.
|
||||
Precedence (highest to lowest): PLAN > PROJECT > GLOBAL.
|
||||
ACTION invariants are promoted to PLAN scope at ``plan use`` time.
|
||||
"""
|
||||
|
||||
GLOBAL = "global"
|
||||
@@ -142,11 +137,10 @@ class InvariantSet(BaseModel):
|
||||
def merge(
|
||||
cls,
|
||||
plan_invariants: list[Invariant],
|
||||
action_invariants: list[Invariant],
|
||||
project_invariants: list[Invariant],
|
||||
global_invariants: list[Invariant],
|
||||
) -> InvariantSet:
|
||||
"""Merge invariants respecting plan > action > project > global precedence.
|
||||
"""Merge invariants respecting plan > project > global precedence.
|
||||
|
||||
De-duplicates by text (case-insensitive), keeping the copy from
|
||||
the highest-precedence tier. Within each tier, source ordering
|
||||
@@ -154,8 +148,7 @@ class InvariantSet(BaseModel):
|
||||
|
||||
Args:
|
||||
plan_invariants: Plan-level invariants (highest precedence).
|
||||
action_invariants: Action-level invariants (second precedence).
|
||||
project_invariants: Project-level invariants (third precedence).
|
||||
project_invariants: Project-level invariants.
|
||||
global_invariants: Global-level invariants (lowest precedence).
|
||||
|
||||
Returns:
|
||||
@@ -163,12 +156,7 @@ class InvariantSet(BaseModel):
|
||||
"""
|
||||
return cls(
|
||||
invariants=tuple(
|
||||
merge_invariants(
|
||||
plan_invariants,
|
||||
action_invariants,
|
||||
project_invariants,
|
||||
global_invariants,
|
||||
)
|
||||
merge_invariants(plan_invariants, project_invariants, global_invariants)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -177,11 +165,10 @@ class InvariantSet(BaseModel):
|
||||
|
||||
def merge_invariants(
|
||||
plan_invariants: list[Invariant],
|
||||
action_invariants: list[Invariant],
|
||||
project_invariants: list[Invariant],
|
||||
global_invariants: list[Invariant],
|
||||
) -> list[Invariant]:
|
||||
"""Merge invariants implementing plan > action > project > global precedence.
|
||||
"""Merge invariants implementing plan > project > global precedence.
|
||||
|
||||
De-duplicates by text (case-insensitive). The first occurrence
|
||||
(from the highest-precedence tier) wins. Within each tier, the
|
||||
@@ -189,8 +176,7 @@ def merge_invariants(
|
||||
|
||||
Args:
|
||||
plan_invariants: Plan-level invariants (highest precedence).
|
||||
action_invariants: Action-level invariants (second precedence).
|
||||
project_invariants: Project-level invariants (third precedence).
|
||||
project_invariants: Project-level invariants.
|
||||
global_invariants: Global-level invariants (lowest precedence).
|
||||
|
||||
Returns:
|
||||
@@ -199,13 +185,7 @@ def merge_invariants(
|
||||
seen: set[str] = set()
|
||||
result: list[Invariant] = []
|
||||
|
||||
tiers = (
|
||||
plan_invariants,
|
||||
action_invariants,
|
||||
project_invariants,
|
||||
global_invariants,
|
||||
)
|
||||
for inv_list in tiers:
|
||||
for inv_list in (plan_invariants, project_invariants, global_invariants):
|
||||
for inv in inv_list:
|
||||
if not inv.active:
|
||||
continue
|
||||
|
||||
@@ -151,6 +151,12 @@ class MigrationRunner:
|
||||
def get_current_revision(self) -> str | None:
|
||||
"""Get the current migration revision of the database.
|
||||
|
||||
For SQLite databases, the engine is created with
|
||||
``connect_args={"check_same_thread": False}`` so that this method
|
||||
can be safely called from any thread — including background threads
|
||||
used in async startup flows. This is consistent with the pattern
|
||||
used in :meth:`init_or_upgrade`.
|
||||
|
||||
Returns:
|
||||
Current revision ID or None if no migrations have been applied
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user