Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 86b0c62e69 | |||
| 14223dbc25 | |||
| 4167f7371a | |||
| 8e0fa1733f | |||
| f10ec45c75 | |||
| 415785a358 | |||
| 143538c200 | |||
| dafe37da7a | |||
| b47f9440ba | |||
| e75db02f2c | |||
| 64d7b22620 |
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.3
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ temperature: 0.2
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
color: success
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -7,7 +7,11 @@ hidden: true
|
||||
temperature: 0.3
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -7,7 +7,11 @@ temperature: 0.2
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
color: "#059669"
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -61,6 +65,7 @@ You manually fix a specific pull request. The user tells you which PR to fix. Yo
|
||||
4. Fix the code — address both CI failures and review feedback.
|
||||
5. Run quality gates locally (`nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e integration_tests`).
|
||||
6. Commit and push using `git-commit-helper`.
|
||||
7. Clean up the isolated clone using `repo-isolator`.
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ hidden: true
|
||||
temperature: 0.1
|
||||
# No model specified — tier is set by the supervisor via tier selectors
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
color: warning
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ temperature: 0.1
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
color: warning
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -9,7 +9,11 @@ temperature: 0.1
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
color: warning
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -46,7 +50,7 @@ permission:
|
||||
|
||||
# PR CI Test Fixer
|
||||
|
||||
You fix failing CI checks on a PR branch. You work in an isolated clone directory.
|
||||
You fix failing CI checks on a PR branch. You work in an isolated clone directory — `$WORK_DIR` is always a path inside `/tmp/` created by `repo-isolator`. All file edits and every git operation (`add`, `commit`, `push`, branch switching) must be performed inside `$WORK_DIR`, never against `/app`.
|
||||
|
||||
## What You Do
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
description: >
|
||||
PR merge supervisor. Continuously monitors open PRs for merge readiness,
|
||||
verifies all seven merge criteria, handles pre-merge rebasing, and performs
|
||||
verifies all merge criteria, handles pre-merge rebasing with conflict resolution, and performs
|
||||
verified merges. Calls pr-merge-worker as a blocking subagent for rebase
|
||||
operations (no async worker sessions).
|
||||
mode: subagent
|
||||
@@ -10,7 +10,11 @@ temperature: 0.1
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
color: "#059669"
|
||||
permission:
|
||||
edit: deny
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: deny
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -53,7 +57,7 @@ permission:
|
||||
|
||||
# PR Merge Supervisor
|
||||
|
||||
You are a supervisor that monitors open PRs for merge readiness, verifies all criteria are met, and merges them. You call `pr-merge-worker` as a **blocking subagent** for rebase operations when PRs are behind the base branch. Unlike other supervisors, you do NOT use async-agent-manager to dispatch workers — you invoke the worker directly via the Task tool and block until it completes.
|
||||
You are a supervisor that monitors open PRs for merge readiness, verifies all criteria are met, rebases stale PR, resolves conflicts, and merges them. You call `pr-merge-worker` as a **blocking subagent** for rebase operations with conflict resolution when PRs are behind the base branch. Unlike other supervisors, you do NOT use async-agent-manager to dispatch workers — you invoke the worker directly via the Task tool and block until it completes.
|
||||
|
||||
## What You Receive
|
||||
|
||||
@@ -99,9 +103,11 @@ Before merging any PR, the following must be true:
|
||||
5. **No `needs feedback` label** — the PR is not waiting for human input
|
||||
6. **Not blocked** — no `Blocked` label
|
||||
|
||||
**Note:** The above criteria do not need to be satisfied before dispatching a `pr-merge-worker`. While they must be satisfied before the actual merge, the rebasing and conflict resolution steps are still useful even if it isnt ready to be merged.
|
||||
|
||||
## Workers
|
||||
|
||||
You call `pr-merge-worker` as a **blocking subagent** (via the Task tool) for rebase operations when PRs are behind the base branch. The worker runs synchronously within your process — you block until it finishes, then continue your cycle. There are no async sessions for workers; this is intentional to simplify coordination since only one rebase happens at a time.
|
||||
You call `pr-merge-worker` as a **blocking subagent** (via the Task tool) for rebase operations with conflict resolution when PRs are behind the base branch. The worker runs synchronously within your process — you block until it finishes, then continue your cycle. There are no async sessions for workers; this is intentional to simplify coordination since only one rebase happens at a time.
|
||||
|
||||
## Main Loop
|
||||
|
||||
@@ -109,9 +115,9 @@ Poll every 5 minutes using `bash("sleep 300", timeout=360000)`.
|
||||
|
||||
Each cycle:
|
||||
1. List all open PRs. (the forgejo task paginates so be sure to go through every page)
|
||||
2. for each PR that is marked as mergable attempt to do a fast-forward merge, as always do the mandatory post-merge verification.
|
||||
2. For all other PR (including those you attempted to merge but were unsuccessful), filter those that having passing CI quality gates/tests.
|
||||
4. For each PR that needs rebasing (prioritized by: milestone order lowest first, then priority label, then MoSCoW label, then issue number), call `pr-merge-worker` as a **blocking subagent** via the Task tool. Pass the PR number, repository info, and credentials in the prompt. The worker will rebase onto the latest master, resolve conflicts, wait for CI, and attempt a fast-forward merge. You block until the worker finishes before processing the next PR.
|
||||
2. for each PR that can be merged (has a passing CI,, isn't stale, and has at least 1 approval review) do a fast-forward or rebase merge, as always do the mandatory post-merge verification.
|
||||
3. For all other PR (including those you attempted to merge but were unsuccessful) order them as follows: 1) CI passes and has one or more review approval 2) CI is failing without conflicts and has one or more review approval 3) CI is failing with conflicts and has one or more review approval 4) All other PRs, within each of those four categories sort by priority label with the most critical label ("Priority/CI Blocking") coming first.
|
||||
4. For each PR, in the order specified in step 2 above, call `pr-merge-worker` as a **blocking subagent** via the Task tool. Pass the PR number, repository info, and credentials in the prompt. The worker will rebase onto the latest master, resolve conflicts, wait for CI, and attempt a fast-forward or rebase merge. You block until the worker finishes before processing the next PR.
|
||||
5. For any PR that were successfully merged update linked issues, and the PR itself, to `State/Completed` via `forgejo-label-manager`.
|
||||
|
||||
## Tracking
|
||||
@@ -131,6 +137,5 @@ Each cycle:
|
||||
**Automated by CleverAgents Bot**
|
||||
Supervisor: PR Merge | Agent: pr-merge-pool-supervisor
|
||||
```
|
||||
|
||||
6. **Apply labels via `forgejo-label-manager`.** Never apply labels directly or using the Forgejo MCP/task. All label operations must go through `forgejo-label-manager`.
|
||||
7. **Exhaustive pagination for all list results.** Every tool call, REST/curl request, or any other command that returns a list must be treated as potentially paginated and incomplete. Always set `limit` to its maximum available value (use `limit=50` for Forgejo MCP tools; use `limit=50` or higher for direct REST/curl calls). After each list response, check whether the number of returned items equals the page size — if so, there are likely more results; fetch the next page (`page=2`, `page=3`, …) and continue until receiving a partial page. Never assume the first response is the complete result. This rule applies to every list-returning call without exception. *Examples specific to this agent (not exhaustive):* `forgejo_list_repo_pull_requests` (default 20 — must use `limit=50` and paginate ALL pages; every open PR must be assessed for merge readiness or a mergeable PR gets left unmerged indefinitely); `forgejo_list_pull_reviews` (paginate to check that all review rounds have been considered before merging); `forgejo_list_issue_comments` (paginate to read the full comment history on linked issues when updating state post-merge).
|
||||
5. **Apply labels via `forgejo-label-manager`.** Never apply labels directly or using the Forgejo MCP/task. All label operations must go through `forgejo-label-manager`.
|
||||
6. **Exhaustive pagination for all list results.** Every tool call, REST/curl request, or any other command that returns a list must be treated as potentially paginated and incomplete. Always set `limit` to its maximum available value (use `limit=50` for Forgejo MCP tools; use `limit=50` or higher for direct REST/curl calls). After each list response, check whether the number of returned items equals the page size — if so, there are likely more results; fetch the next page (`page=2`, `page=3`, …) and continue until receiving a partial page. Never assume the first response is the complete result. This rule applies to every list-returning call without exception. *Examples specific to this agent (not exhaustive):* `forgejo_list_repo_pull_requests` (default 20 — must use `limit=50` and paginate ALL pages; every open PR must be assessed for merge readiness or a mergeable PR gets left unmerged indefinitely); `forgejo_list_pull_reviews` (paginate to check that all review rounds have been considered before merging); `forgejo_list_issue_comments` (paginate to read the full comment history on linked issues when updating state post-merge).
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
---
|
||||
description: >
|
||||
PR merge worker. Performs a single rebase operation on a PR branch that is
|
||||
behind the base branch, then exits. Called as a blocking subagent by the
|
||||
PR merge worker. Performs a single rebase operation with conflict resolution on a PR branch that is
|
||||
behind the base branch, then waits for CI to finish and attempts a merge. Called as a blocking subagent by the
|
||||
PR merge supervisor (not launched as an async session).
|
||||
mode: subagent
|
||||
hidden: true
|
||||
temperature: 0.1
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
"external_directory":
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -46,19 +50,19 @@ You perform a single rebase operation on a PR branch, resolve any conflicts, and
|
||||
## Procedure
|
||||
|
||||
Your prompt tells you which PR to rebase. You must:
|
||||
1. Create an isolated clone using the `repo-isolator` subagent ensuring you pass it the branch used by the PR.
|
||||
1. Create an isolated clone using the `repo-isolator` subagent ensuring you pass it the branch used by the PR. Make sure all work is done within this clone's directory.
|
||||
2. Rebase it onto the base branch (usually `master`).
|
||||
3. Resolve any conflicts that arise by reviewing the recent git history and using that to fix the conflicts
|
||||
4. Force-push with lease using `git-commit-helper`
|
||||
5. Clean up the clone.
|
||||
6. Poll every minute using `bash("sleep 60", timeout=360000)` to sleep, checking each time if the CI Quality Gates have finished
|
||||
7. Once the quality gates finish then merge with a fast-forward if the PR is mergable, if not then skip the merge.
|
||||
7. Once the quality gates finish then merge with a fast-forward or rebase merge if the PR is mergable, if not then skip the merge.
|
||||
8. Report back with any relevant details.
|
||||
|
||||
## Rules
|
||||
|
||||
1. **One task, then exit.** Do not loop. Do not sleep. Do not look for more work.
|
||||
2. **Force-push with lease only.** Never use `--force` without `--lease`.
|
||||
3. **Clean up your clone.** Delete the temporary directory before exiting.
|
||||
3. **Clean up your clone.** Delete the temporary clone directory before exiting.
|
||||
4. **Apply labels via `forgejo-label-manager`.** Never apply labels directly or using the Forgejo MCP/task. All label operations must go through `forgejo-label-manager`.
|
||||
5. **Exhaustive pagination for all list results.** Every tool call, REST/curl request, or any other command that returns a list must be treated as potentially paginated and incomplete. Always set `limit` to its maximum available value (use `limit=50` for Forgejo MCP tools; use `limit=50` or higher for direct REST/curl calls). After each list response, check whether the number of returned items equals the page size — if so, there are likely more results; fetch the next page (`page=2`, `page=3`, …) and continue until receiving a partial page. Never assume the first response is the complete result. This rule applies to every list-returning call without exception. *Examples specific to this agent (not exhaustive):* `git log` listing commits during conflict resolution must be fully read; any future REST/curl calls returning JSON arrays must be paginated.
|
||||
|
||||
@@ -9,7 +9,11 @@ temperature: 0.2
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
color: primary
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -29,6 +33,8 @@ permission:
|
||||
task:
|
||||
"*": deny
|
||||
"forgejo-label-manager": allow
|
||||
"repo-isolator": allow
|
||||
"git-commit-helper": allow
|
||||
"forgejo_*": allow
|
||||
# CRITICAL: Never list repo-level labels — use org labels via forgejo-label-manager
|
||||
"forgejo_list_repo_labels": deny
|
||||
@@ -60,5 +66,6 @@ You set up project infrastructure from scratch. Your caller provides the product
|
||||
1. **Detect before creating.** Always check if something exists before creating it.
|
||||
2. **Never overwrite.** If a file or label already exists, skip it.
|
||||
3. **Credentials from prompt.** All Forgejo PAT, git identity, etc. come from the caller's prompt.
|
||||
4. **Apply labels via `forgejo-label-manager`.** Never apply labels directly or using the Forgejo MCP/task. All label operations must go through `forgejo-label-manager`.
|
||||
5. **Exhaustive pagination for all list results.** Every tool call, REST/curl request, or any other command that returns a list must be treated as potentially paginated and incomplete. Always set `limit` to its maximum available value (use `limit=50` for Forgejo MCP tools; use `limit=50` or higher for direct REST/curl calls). After each list response, check whether the number of returned items equals the page size — if so, there are likely more results; fetch the next page (`page=2`, `page=3`, …) and continue until receiving a partial page. Never assume the first response is the complete result. This rule applies to every list-returning call without exception. *Examples specific to this agent (not exhaustive):* any `forgejo_list_*` calls used when checking for existing labels, milestones, or workflows must be paginated — missing one means re-creating something that already exists.
|
||||
4. **Work in an isolated clone.** Use `repo-isolator` to create an isolated clone of the target repository in `/tmp/`. All file creation and edits must be done in the clone — never directly in `/app`. Use `git-commit-helper` to commit and push changes. Clean up the isolated clone using `repo-isolator` when done.
|
||||
5. **Apply labels via `forgejo-label-manager`.** Never apply labels directly or using the Forgejo MCP/task. All label operations must go through `forgejo-label-manager`.
|
||||
6. **Exhaustive pagination for all list results.** Every tool call, REST/curl request, or any other command that returns a list must be treated as potentially paginated and incomplete. Always set `limit` to its maximum available value (use `limit=50` for Forgejo MCP tools; use `limit=50` or higher for direct REST/curl calls). After each list response, check whether the number of returned items equals the page size — if so, there are likely more results; fetch the next page (`page=2`, `page=3`, …) and continue until receiving a partial page. Never assume the first response is the complete result. This rule applies to every list-returning call without exception. *Examples specific to this agent (not exhaustive):* any `forgejo_list_*` calls used when checking for existing labels, milestones, or workflows must be paginated — missing one means re-creating something that already exists.
|
||||
|
||||
@@ -9,7 +9,9 @@ temperature: 0.1
|
||||
model: openai/gpt-5-codex
|
||||
color: "#6B7280"
|
||||
permission:
|
||||
edit: deny
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
webfetch: deny
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -37,6 +39,8 @@ permission:
|
||||
# CRITICAL: DO NOT use forgejo_add_issue_labels directly
|
||||
# Always delegate to forgejo-label-manager for label operations
|
||||
"forgejo_add_issue_labels": deny
|
||||
"external_directory":
|
||||
"/tmp/**": allow
|
||||
---
|
||||
|
||||
# Repository Isolator
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -11,7 +11,11 @@ temperature: 0.1
|
||||
model: openai/gpt-5-codex
|
||||
color: accent
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -9,7 +9,11 @@ temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
color: warning
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -7,7 +7,11 @@ hidden: true
|
||||
temperature: 0.0
|
||||
model: openai/gpt-5-codex
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: deny
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -7,7 +7,11 @@ hidden: true
|
||||
temperature: 0.0
|
||||
model: anthropic/claude-haiku-4-5
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: deny
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -7,7 +7,11 @@ hidden: true
|
||||
temperature: 0.0
|
||||
model: anthropic/claude-opus-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: deny
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -7,7 +7,11 @@ hidden: true
|
||||
temperature: 0.0
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: deny
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.1
|
||||
model: anthropic/claude-sonnet-4-6
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
@@ -53,6 +57,7 @@ Your prompt provides the current milestone status data and the timeline file for
|
||||
3. Add new entries — never overwrite existing ones.
|
||||
4. Commit using `git-commit-helper` with a Conventional Changelog message.
|
||||
5. Push and exit. (No PR needed — timeline updates go directly to master.)
|
||||
6. Clean up the isolated clone using `repo-isolator`.
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.1
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -8,7 +8,11 @@ hidden: true
|
||||
temperature: 0.2
|
||||
# NO MODEL SPECIFIED - inherits from caller (tier selector)
|
||||
permission:
|
||||
edit: allow
|
||||
edit:
|
||||
"*": deny
|
||||
"/tmp/**": allow
|
||||
external_directory:
|
||||
"/tmp/**": allow
|
||||
webfetch: allow
|
||||
bash:
|
||||
"*": deny
|
||||
|
||||
@@ -5,6 +5,13 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add `docs/api/decisions.md` — decision recording and tree CLI reference (v3.2.0)
|
||||
- Add `docs/api/invariants.md` — invariant management CLI reference (v3.2.0)
|
||||
- Add `docs/api/checkpoints.md` — checkpoint and rollback CLI reference (v3.3.0)
|
||||
- Add `docs/api/plan-corrections.md` — plan correction modes and subplan system overview (v3.2.0/v3.3.0)
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Automation Profile Silent Fallback** (#8232): `_resolve_profile_for_plan` in
|
||||
@@ -163,6 +170,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
`sandbox_root=.cleveragents/sandbox/`, so LLM file output (`FILE:` blocks)
|
||||
is written to disk during the execute phase. (#4222)
|
||||
|
||||
- **SubplanExecutionService fail_fast cancellation** (#7582): Fixed a race condition where
|
||||
already-running parallel subplans were not cancelled when `fail_fast` fired. Previously,
|
||||
`Future.cancel()` only prevented queued futures from starting but had no effect on
|
||||
in-flight futures that completed after `stop_flag` was set — their `COMPLETE` results
|
||||
were incorrectly included in the merge output. The fix adds a post-completion guard that
|
||||
overrides any non-`ERRORED`/non-`CANCELLED` result to `CANCELLED` when `stop_flag` is
|
||||
active, and clears the associated output to prevent it from entering the merge. Also
|
||||
replaces the O(n) linear `status` lookup in the `as_completed()` loop with an O(1)
|
||||
`status_map` dict pre-computed before the executor block.
|
||||
|
||||
- **Robot Framework TDD Listener Guards** (#5436): Added three guard conditions to the
|
||||
`tdd_expected_fail_listener` `end_test()` function to prevent blindly inverting ALL test
|
||||
failures to passes, which was masking infrastructure errors and causing flaky CI behavior.
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
"""ASV benchmarks for LangGraph execution hotspots.
|
||||
|
||||
Measures performance of:
|
||||
- GraphExecutor.step execution
|
||||
- RouterNode.route decision making
|
||||
- Checkpoint read/write operations
|
||||
- Graph state transitions
|
||||
- Node execution throughput
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from cleveragents.langgraph.graph import GraphConfig, LangGraph
|
||||
from cleveragents.langgraph.nodes import Edge, Node, NodeConfig, NodeType
|
||||
from cleveragents.langgraph.state import GraphState
|
||||
except ModuleNotFoundError:
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
||||
from cleveragents.langgraph.graph import GraphConfig, LangGraph
|
||||
from cleveragents.langgraph.nodes import Edge, Node, NodeConfig, NodeType
|
||||
from cleveragents.langgraph.state import GraphState
|
||||
|
||||
|
||||
def _create_simple_graph() -> LangGraph:
|
||||
"""Create a simple representative plan graph for benchmarking."""
|
||||
config = GraphConfig(
|
||||
name="bench-graph",
|
||||
nodes={
|
||||
"start": NodeConfig(name="start", type=NodeType.START),
|
||||
"process": NodeConfig(name="process", type=NodeType.FUNCTION),
|
||||
"route": NodeConfig(name="route", type=NodeType.CONDITIONAL),
|
||||
"end": NodeConfig(name="end", type=NodeType.END),
|
||||
},
|
||||
edges=[
|
||||
Edge(source="start", target="process"),
|
||||
Edge(source="process", target="route"),
|
||||
Edge(source="route", target="end"),
|
||||
],
|
||||
entry_point="start",
|
||||
checkpointing=False,
|
||||
)
|
||||
return LangGraph(config)
|
||||
|
||||
|
||||
def _create_checkpoint_graph() -> LangGraph:
|
||||
"""Create a graph with checkpointing enabled for persistence benchmarks."""
|
||||
checkpoint_dir = Path("/tmp/langgraph_bench_checkpoints")
|
||||
checkpoint_dir.mkdir(exist_ok=True)
|
||||
|
||||
config = GraphConfig(
|
||||
name="bench-graph-checkpoint",
|
||||
nodes={
|
||||
"start": NodeConfig(name="start", type=NodeType.START),
|
||||
"process": NodeConfig(name="process", type=NodeType.FUNCTION),
|
||||
"end": NodeConfig(name="end", type=NodeType.END),
|
||||
},
|
||||
edges=[
|
||||
Edge(source="start", target="process"),
|
||||
Edge(source="process", target="end"),
|
||||
],
|
||||
entry_point="start",
|
||||
checkpointing=True,
|
||||
checkpoint_dir=checkpoint_dir,
|
||||
)
|
||||
return LangGraph(config)
|
||||
|
||||
|
||||
def _create_complex_graph() -> LangGraph:
|
||||
"""Create a more complex graph with multiple nodes for throughput testing."""
|
||||
config = GraphConfig(
|
||||
name="bench-graph-complex",
|
||||
nodes={
|
||||
"start": NodeConfig(name="start", type=NodeType.START),
|
||||
"node1": NodeConfig(name="node1", type=NodeType.FUNCTION),
|
||||
"node2": NodeConfig(name="node2", type=NodeType.FUNCTION),
|
||||
"node3": NodeConfig(name="node3", type=NodeType.FUNCTION),
|
||||
"route": NodeConfig(name="route", type=NodeType.CONDITIONAL),
|
||||
"end": NodeConfig(name="end", type=NodeType.END),
|
||||
},
|
||||
edges=[
|
||||
Edge(source="start", target="node1"),
|
||||
Edge(source="node1", target="node2"),
|
||||
Edge(source="node2", target="node3"),
|
||||
Edge(source="node3", target="route"),
|
||||
Edge(source="route", target="end"),
|
||||
],
|
||||
entry_point="start",
|
||||
checkpointing=False,
|
||||
parallel_execution=True,
|
||||
)
|
||||
return LangGraph(config)
|
||||
|
||||
|
||||
class LangGraphExecutionSuite:
|
||||
"""Benchmark LangGraph execution hotspots."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize graphs for benchmarking."""
|
||||
self.simple_graph = _create_simple_graph()
|
||||
self.checkpoint_graph = _create_checkpoint_graph()
|
||||
self.complex_graph = _create_complex_graph()
|
||||
|
||||
# Sample input state
|
||||
self.sample_state = GraphState()
|
||||
|
||||
def time_simple_graph_execute(self) -> None:
|
||||
"""Measure simple graph execution time."""
|
||||
asyncio.run(self.simple_graph.execute(self.sample_state))
|
||||
|
||||
def time_complex_graph_execute(self) -> None:
|
||||
"""Measure complex graph execution time."""
|
||||
asyncio.run(self.complex_graph.execute(self.sample_state))
|
||||
|
||||
def time_checkpoint_graph_execute(self) -> None:
|
||||
"""Measure graph execution with checkpointing enabled."""
|
||||
asyncio.run(self.checkpoint_graph.execute(self.sample_state))
|
||||
|
||||
def time_state_manager_get_state(self) -> None:
|
||||
"""Measure state manager state retrieval."""
|
||||
self.simple_graph.state_manager.get_state()
|
||||
|
||||
def time_state_manager_update_state(self) -> None:
|
||||
"""Measure state manager state update."""
|
||||
new_state = GraphState()
|
||||
self.simple_graph.state_manager.state = new_state
|
||||
|
||||
def track_graph_nodes_count(self) -> int:
|
||||
"""Track number of nodes in simple graph."""
|
||||
return len(self.simple_graph.nodes)
|
||||
|
||||
def track_graph_edges_count(self) -> int:
|
||||
"""Track number of edges in simple graph."""
|
||||
return len(self.simple_graph.config.edges)
|
||||
|
||||
def track_execution_history_length(self) -> int:
|
||||
"""Track execution history length after execution."""
|
||||
return len(self.simple_graph.get_execution_history())
|
||||
|
||||
|
||||
class LangGraphRouterNodeSuite:
|
||||
"""Benchmark RouterNode routing performance."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize router node for benchmarking."""
|
||||
self.router_config = NodeConfig(
|
||||
name="router",
|
||||
type=NodeType.CONDITIONAL,
|
||||
condition={"type": "simple_condition"},
|
||||
)
|
||||
self.router_node = Node(self.router_config)
|
||||
|
||||
def time_router_node_creation(self) -> None:
|
||||
"""Measure router node instantiation time."""
|
||||
Node(self.router_config)
|
||||
|
||||
def time_router_node_config_access(self) -> None:
|
||||
"""Measure router node config access."""
|
||||
_ = self.router_node.config.condition
|
||||
|
||||
|
||||
class LangGraphStateTransitionSuite:
|
||||
"""Benchmark graph state transitions and updates."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize state for benchmarking."""
|
||||
self.state = GraphState()
|
||||
self.graph = _create_simple_graph()
|
||||
|
||||
def time_state_creation(self) -> None:
|
||||
"""Measure GraphState creation time."""
|
||||
GraphState()
|
||||
|
||||
def time_state_dict_conversion(self) -> None:
|
||||
"""Measure state to dict conversion."""
|
||||
self.state.to_dict()
|
||||
|
||||
def time_state_from_dict(self) -> None:
|
||||
"""Measure state from dict creation."""
|
||||
GraphState.from_dict({"messages": []})
|
||||
|
||||
def time_state_copy(self) -> None:
|
||||
"""Measure state copy operation."""
|
||||
self.state.copy()
|
||||
@@ -0,0 +1,200 @@
|
||||
"""ASV benchmarks for TUI rendering and command routing performance.
|
||||
|
||||
Measures performance of:
|
||||
- TUI layout and render cycle time
|
||||
- Slash command catalog hydration
|
||||
- Command routing overhead
|
||||
- Widget rendering performance
|
||||
- Session view updates
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from cleveragents.tui.slash_catalog import (
|
||||
SLASH_COMMAND_SPECS,
|
||||
SlashCommandSpec,
|
||||
slash_command_specs,
|
||||
)
|
||||
except ModuleNotFoundError:
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
||||
from cleveragents.tui.slash_catalog import (
|
||||
SLASH_COMMAND_SPECS,
|
||||
SlashCommandSpec,
|
||||
slash_command_specs,
|
||||
)
|
||||
|
||||
|
||||
def _build_command_index() -> dict[str, list[SlashCommandSpec]]:
|
||||
"""Build a command index grouped by category."""
|
||||
index: dict[str, list[SlashCommandSpec]] = {}
|
||||
for spec in SLASH_COMMAND_SPECS:
|
||||
if spec.group not in index:
|
||||
index[spec.group] = []
|
||||
index[spec.group].append(spec)
|
||||
return index
|
||||
|
||||
|
||||
def _filter_commands_by_prefix(prefix: str) -> list[SlashCommandSpec]:
|
||||
"""Filter commands by prefix for autocomplete."""
|
||||
return [cmd for cmd in SLASH_COMMAND_SPECS if cmd.command.startswith(prefix)]
|
||||
|
||||
|
||||
class TUISlashCatalogSuite:
|
||||
"""Benchmark TUI slash command catalog operations."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize catalog for benchmarking."""
|
||||
self.catalog = SLASH_COMMAND_SPECS
|
||||
self.command_index = _build_command_index()
|
||||
|
||||
def time_catalog_iteration(self) -> None:
|
||||
"""Measure time to iterate through all commands."""
|
||||
for _ in self.catalog:
|
||||
pass
|
||||
|
||||
def time_catalog_grouping(self) -> None:
|
||||
"""Measure time to group commands by category."""
|
||||
_build_command_index()
|
||||
|
||||
def time_catalog_prefix_filter(self) -> None:
|
||||
"""Measure time to filter commands by prefix."""
|
||||
_filter_commands_by_prefix("session:")
|
||||
|
||||
def time_catalog_search(self) -> None:
|
||||
"""Measure time to search for a specific command."""
|
||||
target = "plan:execute"
|
||||
for cmd in self.catalog:
|
||||
if cmd.command == target:
|
||||
break
|
||||
|
||||
def time_command_spec_creation(self) -> None:
|
||||
"""Measure time to create a SlashCommandSpec."""
|
||||
SlashCommandSpec(
|
||||
command="test:command",
|
||||
group="Test",
|
||||
description="Test command",
|
||||
)
|
||||
|
||||
def track_catalog_size(self) -> int:
|
||||
"""Track total number of commands in catalog."""
|
||||
return len(self.catalog)
|
||||
|
||||
def track_unique_groups(self) -> int:
|
||||
"""Track number of unique command groups."""
|
||||
return len(self.command_index)
|
||||
|
||||
def track_largest_group_size(self) -> int:
|
||||
"""Track size of largest command group."""
|
||||
return max(len(cmds) for cmds in self.command_index.values())
|
||||
|
||||
|
||||
class TUICommandRoutingSuite:
|
||||
"""Benchmark TUI command routing performance."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize routing structures for benchmarking."""
|
||||
self.catalog = SLASH_COMMAND_SPECS
|
||||
self.command_map = {cmd.command: cmd for cmd in self.catalog}
|
||||
|
||||
def time_command_lookup(self) -> None:
|
||||
"""Measure time to lookup a command in the map."""
|
||||
_ = self.command_map.get("session:create")
|
||||
|
||||
def time_command_validation(self) -> None:
|
||||
"""Measure time to validate a command exists."""
|
||||
command = "plan:execute"
|
||||
command in self.command_map
|
||||
|
||||
def time_group_lookup(self) -> None:
|
||||
"""Measure time to find all commands in a group."""
|
||||
group = "Session"
|
||||
[cmd for cmd in self.catalog if cmd.group == group]
|
||||
|
||||
def time_description_search(self) -> None:
|
||||
"""Measure time to search commands by description."""
|
||||
search_term = "session"
|
||||
[
|
||||
cmd
|
||||
for cmd in self.catalog
|
||||
if search_term.lower() in cmd.description.lower()
|
||||
]
|
||||
|
||||
def track_command_map_size(self) -> int:
|
||||
"""Track size of command lookup map."""
|
||||
return len(self.command_map)
|
||||
|
||||
|
||||
class TUISessionViewSuite:
|
||||
"""Benchmark TUI session view operations."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize session view for benchmarking."""
|
||||
from cleveragents.tui.app import SessionView
|
||||
|
||||
self.session = SessionView(
|
||||
session_id="bench-session-001",
|
||||
transcript=["message 1", "message 2", "message 3"],
|
||||
)
|
||||
|
||||
def time_session_view_creation(self) -> None:
|
||||
"""Measure time to create a SessionView."""
|
||||
from cleveragents.tui.app import SessionView
|
||||
|
||||
SessionView(
|
||||
session_id="test-session",
|
||||
transcript=["test message"],
|
||||
)
|
||||
|
||||
def time_transcript_append(self) -> None:
|
||||
"""Measure time to append to transcript."""
|
||||
self.session.transcript.append("new message")
|
||||
|
||||
def time_transcript_iteration(self) -> None:
|
||||
"""Measure time to iterate through transcript."""
|
||||
for _ in self.session.transcript:
|
||||
pass
|
||||
|
||||
def track_session_id_length(self) -> int:
|
||||
"""Track session ID length."""
|
||||
return len(self.session.session_id)
|
||||
|
||||
def track_transcript_size(self) -> int:
|
||||
"""Track transcript message count."""
|
||||
return len(self.session.transcript)
|
||||
|
||||
|
||||
class TUIWidgetRenderingSuite:
|
||||
"""Benchmark TUI widget rendering operations."""
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Initialize widgets for benchmarking."""
|
||||
self.command_specs = SLASH_COMMAND_SPECS
|
||||
self.sample_text = "Sample widget content for rendering"
|
||||
|
||||
def time_command_spec_string_conversion(self) -> None:
|
||||
"""Measure time to convert command spec to string."""
|
||||
spec = self.command_specs[0]
|
||||
str(spec)
|
||||
|
||||
def time_command_spec_formatting(self) -> None:
|
||||
"""Measure time to format command spec for display."""
|
||||
spec = self.command_specs[0]
|
||||
f"{spec.command} - {spec.description}"
|
||||
|
||||
def time_text_rendering_short(self) -> None:
|
||||
"""Measure time to render short text."""
|
||||
len(self.sample_text)
|
||||
|
||||
def time_text_rendering_long(self) -> None:
|
||||
"""Measure time to render long text."""
|
||||
long_text = self.sample_text * 100
|
||||
len(long_text)
|
||||
|
||||
def track_widget_content_size(self) -> int:
|
||||
"""Track size of widget content."""
|
||||
return len(self.sample_text)
|
||||
@@ -0,0 +1,237 @@
|
||||
# Checkpoint and Rollback API (v3.3.0)
|
||||
|
||||
CleverAgents supports checkpointing and rollback to snapshot sandbox state during plan
|
||||
execution and restore it later. This page documents the CLI commands and Python API for
|
||||
managing checkpoints.
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Checkpointing introduced in **v3.3.0** allows operators to:
|
||||
|
||||
- Snapshot sandbox state at key points during plan execution.
|
||||
- Roll back to a previous snapshot to undo tool side-effects.
|
||||
- Integrate with the decision-correction revert flow for targeted re-execution.
|
||||
|
||||
Checkpoints are immutable records stored in the `checkpoint_metadata` SQLite table and
|
||||
backed by a `CheckpointRepository`. The `CheckpointService` is registered in the DI
|
||||
container and injected into `ToolRunner`, `SubplanExecutionService`, and `PlanExecutor`.
|
||||
|
||||
---
|
||||
|
||||
## CLI Reference
|
||||
|
||||
### `agents plan checkpoint list`
|
||||
|
||||
List all checkpoints for a plan.
|
||||
|
||||
```bash
|
||||
agents plan checkpoint list <PLAN_ID> [OPTIONS]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--format`, `-f` | Output format: `json`, `yaml`, `plain`, `table`, `rich` |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# List checkpoints for a plan
|
||||
agents plan checkpoint list 01HXYZ1234567890ABCDEFGH
|
||||
|
||||
# JSON output for scripting
|
||||
agents plan checkpoint list 01HXYZ1234567890ABCDEFGH --format json
|
||||
```
|
||||
|
||||
Each checkpoint entry shows:
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `checkpoint_id` | ULID identifier |
|
||||
| `checkpoint_type` | `pre_write`, `post_step`, or `manual` |
|
||||
| `decision_id` | Optional decision this checkpoint is aligned to |
|
||||
| `sandbox_ref` | Git commit hash or patch reference |
|
||||
| `size_bytes` | Size of the checkpoint data |
|
||||
| `created_at` | UTC creation timestamp |
|
||||
|
||||
---
|
||||
|
||||
### `agents plan rollback`
|
||||
|
||||
Roll back a plan's sandbox to a previously captured checkpoint.
|
||||
|
||||
```bash
|
||||
agents plan rollback [--yes|-y] <PLAN_ID> <CHECKPOINT_ID>
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--yes`, `-y` | Skip the interactive confirmation prompt |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# Rollback with confirmation prompt
|
||||
agents plan rollback 01HXYZ1234567890ABCDEFGH 01HABC1234567890ABCDEFGH
|
||||
|
||||
# Skip confirmation (for scripts/CI)
|
||||
agents plan rollback --yes 01HXYZ1234567890ABCDEFGH 01HABC1234567890ABCDEFGH
|
||||
```
|
||||
|
||||
**JSON output envelope** (when using `--format json`):
|
||||
|
||||
```json
|
||||
{
|
||||
"rollback_summary": {
|
||||
"plan_id": "...",
|
||||
"from_checkpoint_id": "...",
|
||||
"restored_files_count": 3
|
||||
},
|
||||
"changes_reverted": ["path/to/file1.py", "path/to/file2.py"],
|
||||
"impact": {
|
||||
"files_affected": 3
|
||||
},
|
||||
"post_rollback_state": {
|
||||
"active_checkpoint": "...",
|
||||
"plan_id": "..."
|
||||
},
|
||||
"timing": {
|
||||
"elapsed_seconds": 0.042
|
||||
},
|
||||
"messages": ["Rollback completed successfully."]
|
||||
}
|
||||
```
|
||||
|
||||
**Error cases:**
|
||||
|
||||
| Error | Cause |
|
||||
|-------|-------|
|
||||
| `Rollback blocked: plan is already applied` | Plan has reached terminal `applied` state |
|
||||
| `Rollback blocked: sandbox is missing` | Sandbox was cleaned up before rollback |
|
||||
| `Not found: checkpoint` | Checkpoint ID does not exist |
|
||||
| `Validation Error` | Checkpoint does not belong to the specified plan |
|
||||
|
||||
---
|
||||
|
||||
## Checkpoint Lifecycle
|
||||
|
||||
### Checkpoint Types
|
||||
|
||||
| Type | When Created |
|
||||
|------|-------------|
|
||||
| `pre_write` | Automatically before each write-tool execution |
|
||||
| `post_step` | Automatically after each write-tool execution |
|
||||
| `manual` | Via `CheckpointService.create_checkpoint()` directly |
|
||||
|
||||
### Automatic Checkpoint Triggers (v3.8.0+)
|
||||
|
||||
The execution engine supports four automatic triggers, configurable via
|
||||
`core.checkpoints.auto_create_on`:
|
||||
|
||||
| Trigger | When | Component |
|
||||
|---------|------|-----------|
|
||||
| `on_tool_write` | Before each write-tool execution | `ToolRunner` |
|
||||
| `on_tool_write_complete` | After each write-tool execution | `ToolRunner` |
|
||||
| `on_subplan_spawn` | Before first subplan execution attempt | `SubplanExecutionService` |
|
||||
| `on_error` | When the Execute phase fails | `PlanExecutor` |
|
||||
|
||||
**Configuration:**
|
||||
|
||||
```toml
|
||||
[core.checkpoints]
|
||||
auto_create_on = ["on_tool_write", "on_tool_write_complete", "on_subplan_spawn", "on_error"]
|
||||
```
|
||||
|
||||
To disable all automatic checkpoints:
|
||||
|
||||
```toml
|
||||
[core.checkpoints]
|
||||
auto_create_on = []
|
||||
```
|
||||
|
||||
### Retention Policy
|
||||
|
||||
A `CheckpointRetentionPolicy` governs how many checkpoints a plan may keep:
|
||||
|
||||
| Field | Default | Range |
|
||||
|-------|---------|-------|
|
||||
| `max_checkpoints` | 50 | 1–100 |
|
||||
| `auto_prune` | `true` | — |
|
||||
|
||||
When `auto_prune` is enabled and the count exceeds `max_checkpoints`, the oldest
|
||||
**interior** checkpoints are removed. The first (earliest) and most recent checkpoints
|
||||
are always preserved.
|
||||
|
||||
---
|
||||
|
||||
## Checkpoint Data Model
|
||||
|
||||
Each checkpoint stores:
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `checkpoint_id` | ULID | Unique identifier |
|
||||
| `plan_id` | ULID | The plan that owns this checkpoint |
|
||||
| `sandbox_ref` | str | Git commit hash or patch reference |
|
||||
| `decision_id` | ULID \| None | Optional decision alignment |
|
||||
| `checkpoint_type` | str | `pre_write`, `post_step`, or `manual` |
|
||||
| `resource_id` | ULID \| None | Optional resource association |
|
||||
| `filesystem_path` | str | Relative path within the checkpoint directory |
|
||||
| `size_bytes` | int | Size of the checkpoint data in bytes |
|
||||
| `created_at` | datetime | UTC creation timestamp |
|
||||
| `metadata` | dict | Audit metadata: `reason`, `source_tool`, `phase`, `extra` |
|
||||
|
||||
---
|
||||
|
||||
## Python API
|
||||
|
||||
The `CheckpointService` is obtained from the DI container:
|
||||
|
||||
```python
|
||||
from cleveragents.application.container import get_container
|
||||
|
||||
checkpoint_service = get_container().checkpoint_service()
|
||||
|
||||
# Create a manual checkpoint
|
||||
checkpoint = checkpoint_service.create_checkpoint(
|
||||
plan_id="01HV...",
|
||||
sandbox_ref="abc123",
|
||||
checkpoint_type="manual",
|
||||
metadata={"reason": "pre-correction snapshot", "phase": "execute"},
|
||||
)
|
||||
|
||||
# List checkpoints for a plan
|
||||
checkpoints = checkpoint_service.list_checkpoints(plan_id="01HV...")
|
||||
|
||||
# Roll back to a checkpoint
|
||||
result = checkpoint_service.rollback_to_checkpoint(
|
||||
plan_id="01HV...",
|
||||
checkpoint_id="01HABC...",
|
||||
)
|
||||
print(f"Restored {result.restored_files_count} files")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Rollback Guards
|
||||
|
||||
The rollback operation enforces two guards:
|
||||
|
||||
1. **Plan is applied** — Once a plan reaches the `applied` terminal state, rollback is
|
||||
rejected with a `BusinessRuleViolation`.
|
||||
2. **Sandbox is missing** — If the sandbox has been cleaned up, rollback is rejected
|
||||
because there is nothing to restore.
|
||||
|
||||
---
|
||||
|
||||
## See Also
|
||||
|
||||
- [`docs/reference/checkpointing.md`](../reference/checkpointing.md) — Full checkpointing domain model reference
|
||||
- [`docs/api/plan-corrections.md`](plan-corrections.md) — Plan correction modes (revert uses checkpoints)
|
||||
- [ADR-015: Sandbox & Checkpoint](../adr/ADR-015-sandbox-and-checkpoint.md)
|
||||
- [ADR-035: Decision Tree Rollback & Replay](../adr/ADR-035-decision-tree-rollback-and-replay.md)
|
||||
@@ -0,0 +1,348 @@
|
||||
# Decision Recording and Tree API (v3.2.0)
|
||||
|
||||
The decision subsystem records every choice point during a plan's Strategize and Execute
|
||||
phases as a persistent tree of **Decision** nodes. This page documents the CLI commands
|
||||
and Python API for inspecting and navigating that tree.
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
During the **Strategize** phase, the strategy actor records each significant choice as a
|
||||
`Decision` node. Decisions are linked parent-to-child to form a tree rooted at the
|
||||
`prompt_definition` node (the original plan prompt). The tree is persisted to SQLite via
|
||||
`DecisionRepository` and can be queried at any time — even after the plan has completed.
|
||||
|
||||
Key capabilities introduced in **v3.2.0**:
|
||||
|
||||
- Automatic decision recording for every strategy and execution choice.
|
||||
- Context snapshots (SHA-256 hash + storage pointer) captured alongside each decision.
|
||||
- Alternatives-considered tracking for every decision node.
|
||||
- Full tree rendering via `agents plan tree`.
|
||||
- Per-decision explanation via `agents plan explain`.
|
||||
|
||||
---
|
||||
|
||||
## CLI Reference
|
||||
|
||||
### `agents plan tree`
|
||||
|
||||
Display the decision tree for a plan.
|
||||
|
||||
```bash
|
||||
agents plan tree <PLAN_ID> [OPTIONS]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--format`, `-f` | Output format: `json`, `yaml`, `plain`, `table`, `rich` (default: `rich`) |
|
||||
| `--show-superseded` | Include superseded decisions in the tree |
|
||||
| `--depth` | Maximum tree depth to render (0 = unlimited, default: 0) |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# Default rich tree view
|
||||
agents plan tree 01HXYZ1234567890ABCDEFGH
|
||||
|
||||
# Table format
|
||||
agents plan tree 01HXYZ1234567890ABCDEFGH --format table
|
||||
|
||||
# Include superseded decisions (e.g. after a correction)
|
||||
agents plan tree 01HXYZ1234567890ABCDEFGH --show-superseded
|
||||
|
||||
# Limit depth to 2 levels
|
||||
agents plan tree 01HXYZ1234567890ABCDEFGH --depth 2
|
||||
|
||||
# JSON output for scripting
|
||||
agents plan tree 01HXYZ1234567890ABCDEFGH --format json
|
||||
```
|
||||
|
||||
**Rich output** renders an indented tree with decision type labels, sequence numbers,
|
||||
and full 26-character ULIDs so that IDs can be copied directly into follow-up commands
|
||||
such as `agents plan explain` or `agents plan correct`.
|
||||
|
||||
---
|
||||
|
||||
### `agents plan explain`
|
||||
|
||||
Show full details for a single decision node, including alternatives considered,
|
||||
context snapshot, and actor reasoning.
|
||||
|
||||
```bash
|
||||
agents plan explain <DECISION_ID> [OPTIONS]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--format`, `-f` | Output format: `json`, `yaml`, `plain`, `table`, `rich` |
|
||||
| `--show-context` | Include context snapshot details (hash, storage ref, resources) |
|
||||
| `--show-reasoning` | Include rationale and raw actor reasoning trace |
|
||||
|
||||
Alternatives considered are **always** included in the output regardless of flags.
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# Default rich output
|
||||
agents plan explain 01HXYZ1234567890ABCDEFGH
|
||||
|
||||
# JSON with full context snapshot
|
||||
agents plan explain 01HXYZ1234567890ABCDEFGH --format json --show-context
|
||||
|
||||
# Show actor reasoning trace
|
||||
agents plan explain 01HXYZ1234567890ABCDEFGH --show-reasoning
|
||||
|
||||
# YAML with all details
|
||||
agents plan explain 01HXYZ1234567890ABCDEFGH --format yaml \
|
||||
--show-context --show-reasoning
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Decision Data Model
|
||||
|
||||
Each decision node stores the following fields.
|
||||
|
||||
### Identity
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `decision_id` | ULID | Auto-generated unique identifier |
|
||||
| `plan_id` | ULID | Parent plan |
|
||||
| `parent_decision_id` | ULID \| None | Parent node; `None` for the root |
|
||||
| `sequence_number` | int | Monotonic order within the plan (0-indexed, never reused) |
|
||||
|
||||
### Classification
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `decision_type` | `DecisionType` | One of 11 enum values (see table below) |
|
||||
|
||||
**Decision types:**
|
||||
|
||||
| Type | Phase | Description |
|
||||
|------|-------|-------------|
|
||||
| `prompt_definition` | Strategize | Root decision — the plan prompt |
|
||||
| `invariant_enforced` | Strategize | An invariant constraint was applied |
|
||||
| `strategy_choice` | Strategize | High-level approach chosen |
|
||||
| `implementation_choice` | Execute | How to implement a specific task |
|
||||
| `resource_selection` | Execute | Which resources to read / modify |
|
||||
| `subplan_spawn` | Strategize | Decision to create a child plan |
|
||||
| `subplan_parallel_spawn` | Strategize | Spawn a group of child plans in parallel |
|
||||
| `tool_invocation` | Execute | Which skill / tool to use |
|
||||
| `error_recovery` | Execute | How to handle a failure |
|
||||
| `validation_response` | Execute | Response to a validation failure |
|
||||
| `user_intervention` | Any | User-provided guidance / correction |
|
||||
|
||||
### Content
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `question` | str | What question was being answered |
|
||||
| `chosen_option` | str | The option that was selected |
|
||||
| `alternatives_considered` | list[str] | Other options that were evaluated |
|
||||
| `confidence_score` | float \| None | 0.0–1.0 confidence, or `None` |
|
||||
|
||||
### Context Snapshot
|
||||
|
||||
Every decision captures a `ContextSnapshot` for replay and correction:
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `hot_context_hash` | str | SHA-256 hash of the context window at decision time |
|
||||
| `hot_context_ref` | str | Storage pointer to the full serialised context |
|
||||
| `relevant_resources` | list[ResourceRef] | Resources in scope at decision time |
|
||||
| `actor_state_ref` | str | LangGraph actor checkpoint reference |
|
||||
|
||||
### Rationale
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `rationale` | str | Human-readable explanation |
|
||||
| `actor_reasoning` | str \| None | Raw LLM reasoning trace |
|
||||
|
||||
### Downstream Impact
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `downstream_decision_ids` | list[ULID] | Decisions that depend on this one |
|
||||
| `downstream_plan_ids` | list[ULID] | Child plans spawned from this decision |
|
||||
| `artifacts_produced` | list[ArtifactRef] | Artifacts created by this decision |
|
||||
|
||||
### Correction Metadata
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `is_correction` | bool | `True` if this decision corrects another |
|
||||
| `corrects_decision_id` | ULID \| None | Original decision being corrected |
|
||||
| `correction_reason` | str \| None | Why the correction was made |
|
||||
| `superseded_by` | ULID \| None | Decision that replaced this one |
|
||||
|
||||
---
|
||||
|
||||
## Tree Structure
|
||||
|
||||
Decisions form a tree via `parent_decision_id`:
|
||||
|
||||
```
|
||||
prompt_definition (root, parent=None)
|
||||
├── invariant_enforced
|
||||
├── strategy_choice
|
||||
│ ├── implementation_choice
|
||||
│ │ ├── resource_selection
|
||||
│ │ └── tool_invocation
|
||||
│ └── subplan_spawn
|
||||
└── strategy_choice
|
||||
```
|
||||
|
||||
The `prompt_definition` type is always the root and must have
|
||||
`parent_decision_id = None`. The **current tree** consists of all decisions where
|
||||
`superseded_by IS NULL`. Superseded decisions are hidden by default in `agents plan tree`
|
||||
but can be shown with `--show-superseded`.
|
||||
|
||||
---
|
||||
|
||||
## Decision Persistence
|
||||
|
||||
Decisions are persisted to SQLite via `DecisionRepository` in the
|
||||
`cleveragents.infrastructure.database` package. The service layer
|
||||
(`DecisionService`) supports two modes:
|
||||
|
||||
| Mode | UnitOfWork | Storage |
|
||||
|------|------------|---------|
|
||||
| In-memory | `None` | Internal dicts |
|
||||
| Persisted | provided | SQLite via `DecisionRepository` + in-memory write-through cache |
|
||||
|
||||
When a `UnitOfWork` is wired, mutations are written to the database first, then the
|
||||
in-memory cache is updated (write-through).
|
||||
|
||||
**Python API — recording a decision:**
|
||||
|
||||
```python
|
||||
from cleveragents.application.services.decision_service import DecisionService
|
||||
from cleveragents.domain.models.core.decision import DecisionType
|
||||
|
||||
svc = DecisionService(unit_of_work=uow)
|
||||
|
||||
decision = svc.record_decision(
|
||||
plan_id="01HV...",
|
||||
decision_type=DecisionType.STRATEGY_CHOICE,
|
||||
question="Which approach should we take?",
|
||||
chosen_option="Build a REST API",
|
||||
alternatives_considered=["GraphQL API", "gRPC service"],
|
||||
confidence_score=0.85,
|
||||
rationale="REST is simpler and better supported by existing tooling.",
|
||||
)
|
||||
```
|
||||
|
||||
**Python API — retrieving the tree:**
|
||||
|
||||
```python
|
||||
# BFS from root(s), level by level
|
||||
tree = svc.get_tree(plan_id="01HV...")
|
||||
|
||||
# Walk from a decision up to the root
|
||||
path = svc.get_path_to_root(decision_id="01HXYZ...")
|
||||
|
||||
# List all decisions for a plan, ordered by sequence number
|
||||
decisions = svc.list_decisions(plan_id="01HV...")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## See Also
|
||||
|
||||
- [`docs/reference/decision_model.md`](../reference/decision_model.md) — Full domain model reference
|
||||
- [`docs/reference/decision_service.md`](../reference/decision_service.md) — `DecisionService` API reference
|
||||
- [`docs/api/plan-corrections.md`](plan-corrections.md) — Correction modes and subplan system
|
||||
- [ADR-007: Decision Tree & Correction](../adr/ADR-007-decision-tree-and-correction.md)
|
||||
- [ADR-033: Decision Recording Protocol](../adr/ADR-033-decision-recording-protocol.md)
|
||||
- [ADR-034: Decision Tree Versioning & History](../adr/ADR-034-decision-tree-versioning-and-history.md)
|
||||
diff --git a/docs/api/invariants.md b/docs/api/invariants.md
|
||||
new file mode 100644
|
||||
index 0000000..2222222
|
||||
--- /dev/null
|
||||
+++ b/docs/api/invariants.md
|
||||
@@ -0,0 +1,274 @@
|
||||
# Invariant Management API (v3.2.0)
|
||||
|
||||
Invariants are natural-language constraints that govern plan execution. They are
|
||||
evaluated at the start of the Strategize phase by the **Invariant Reconciliation Actor**
|
||||
and recorded in the decision tree as `invariant_enforced` nodes.
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Invariants introduced in **v3.2.0** provide a declarative way to constrain what a plan
|
||||
may do. They are scoped (global, project, action, or plan), merged by precedence, and
|
||||
de-duplicated before enforcement. Violations block the phase transition and emit
|
||||
`INVARIANT_VIOLATED` events.
|
||||
|
||||
Key capabilities:
|
||||
|
||||
- Four scope levels: `GLOBAL`, `PROJECT`, `ACTION`, `PLAN`.
|
||||
- Merge precedence: plan > project > global (action invariants are promoted to plan scope).
|
||||
- Automatic enforcement at every phase transition via `InvariantReconciliationActor`.
|
||||
- CLI commands for adding, listing, and removing invariants.
|
||||
|
||||
---
|
||||
|
||||
## CLI Reference
|
||||
|
||||
### `agents invariant add`
|
||||
|
||||
Create a new invariant constraint.
|
||||
|
||||
```bash
|
||||
agents invariant add <NAME> --description <DESC> [SCOPE_FLAG]
|
||||
```
|
||||
|
||||
**Scope flags:**
|
||||
|
||||
| Flag | Scope | Description |
|
||||
|------|-------|-------------|
|
||||
| `--global` | `GLOBAL` | Applies to every plan in the system |
|
||||
| `--project <NAME>` | `PROJECT` | Applies to plans targeting the named project |
|
||||
| `--plan <PLAN_ID>` | `PLAN` | Attached directly to a specific plan |
|
||||
| `--action <ACTION>` | `ACTION` | Defined in an action template; promoted on `plan use` |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# Global invariant
|
||||
agents invariant add --global "Never delete production data"
|
||||
|
||||
# Project-scoped invariant
|
||||
agents invariant add --project myapp "All API changes need tests"
|
||||
|
||||
# Plan-specific invariant
|
||||
agents invariant add --plan 01HXYZ... "Use Python 3.13 only"
|
||||
|
||||
# Action-scoped invariant
|
||||
agents invariant add --action local/code-coverage "Minimum 80% coverage"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `agents invariant list`
|
||||
|
||||
Display invariants, optionally filtered by scope or project.
|
||||
|
||||
```bash
|
||||
agents invariant list [PATTERN] [OPTIONS]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--global` | Show only global invariants |
|
||||
| `--project <NAME>` | Show only invariants for the named project |
|
||||
| `--effective --project <NAME>` | Show the merged effective set for a project |
|
||||
| `--format`, `-f` | Output format: `json`, `yaml`, `plain`, `table`, `rich` |
|
||||
@@ -0,0 +1,245 @@
|
||||
# Invariant Management API (v3.2.0)
|
||||
|
||||
Invariants are natural-language constraints that govern plan execution. They are
|
||||
evaluated at the start of the Strategize phase by the **Invariant Reconciliation Actor**
|
||||
and recorded in the decision tree as `invariant_enforced` nodes.
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Invariants introduced in **v3.2.0** provide a declarative way to constrain what a plan
|
||||
may do. They are scoped (global, project, action, or plan), merged by precedence, and
|
||||
de-duplicated before enforcement. Violations block the phase transition and emit
|
||||
`INVARIANT_VIOLATED` events.
|
||||
|
||||
Key capabilities:
|
||||
|
||||
- Four scope levels: `GLOBAL`, `PROJECT`, `ACTION`, `PLAN`.
|
||||
- Merge precedence: plan > project > global (action invariants are promoted to plan scope).
|
||||
- Automatic enforcement at every phase transition via `InvariantReconciliationActor`.
|
||||
- CLI commands for adding, listing, and removing invariants.
|
||||
|
||||
---
|
||||
|
||||
## CLI Reference
|
||||
|
||||
### `agents invariant add`
|
||||
|
||||
Create a new invariant constraint.
|
||||
|
||||
```bash
|
||||
agents invariant add <NAME> --description <DESC> [SCOPE_FLAG]
|
||||
```
|
||||
|
||||
**Scope flags:**
|
||||
|
||||
| Flag | Scope | Description |
|
||||
|------|-------|-------------|
|
||||
| `--global` | `GLOBAL` | Applies to every plan in the system |
|
||||
| `--project <NAME>` | `PROJECT` | Applies to plans targeting the named project |
|
||||
| `--plan <PLAN_ID>` | `PLAN` | Attached directly to a specific plan |
|
||||
| `--action <ACTION>` | `ACTION` | Defined in an action template; promoted on `plan use` |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# Global invariant
|
||||
agents invariant add --global "Never delete production data"
|
||||
|
||||
# Project-scoped invariant
|
||||
agents invariant add --project myapp "All API changes need tests"
|
||||
|
||||
# Plan-specific invariant
|
||||
agents invariant add --plan 01HXYZ... "Use Python 3.13 only"
|
||||
|
||||
# Action-scoped invariant
|
||||
agents invariant add --action local/code-coverage "Minimum 80% coverage"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `agents invariant list`
|
||||
|
||||
Display invariants, optionally filtered by scope or project.
|
||||
|
||||
```bash
|
||||
agents invariant list [PATTERN] [OPTIONS]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--global` | Show only global invariants |
|
||||
| `--project <NAME>` | Show only invariants for the named project |
|
||||
| `--effective --project <NAME>` | Show the merged effective set for a project |
|
||||
| `--format`, `-f` | Output format: `json`, `yaml`, `plain`, `table`, `rich` |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# List all active invariants
|
||||
agents invariant list
|
||||
|
||||
# Filter by scope
|
||||
agents invariant list --global
|
||||
agents invariant list --project myapp
|
||||
|
||||
# Show merged effective set for a project
|
||||
agents invariant list --effective --project myapp
|
||||
|
||||
# Filter by regex pattern
|
||||
agents invariant list "data.*safe"
|
||||
|
||||
# JSON output
|
||||
agents invariant list --format json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `agents invariant remove`
|
||||
|
||||
Remove (soft-delete) an invariant by its ULID.
|
||||
|
||||
```bash
|
||||
agents invariant remove <INVARIANT_ID> [--yes]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--yes` | Skip the interactive confirmation prompt |
|
||||
|
||||
**Examples:**
|
||||
|
||||
```bash
|
||||
# With confirmation prompt
|
||||
agents invariant remove 01HXYZ...
|
||||
|
||||
# Skip confirmation
|
||||
agents invariant remove --yes 01HXYZ...
|
||||
```
|
||||
|
||||
Removal sets `active=False` on the invariant record; it is not hard-deleted. This
|
||||
preserves the audit trail for enforcement records that reference the invariant.
|
||||
|
||||
---
|
||||
|
||||
## Scope Hierarchy and Merge Precedence
|
||||
|
||||
When computing the effective invariant set for a plan, the precedence chain is:
|
||||
|
||||
```
|
||||
plan > project > global
|
||||
```
|
||||
|
||||
- **Plan-level** invariants take highest precedence.
|
||||
- **Project-level** invariants apply next.
|
||||
- **Global-level** invariants are lowest precedence.
|
||||
- **Action-level** invariants are promoted to plan scope when `plan use` is called.
|
||||
|
||||
### De-duplication
|
||||
|
||||
Invariants are de-duplicated by text (case-insensitive). When the same constraint text
|
||||
appears at multiple scopes, only the highest-precedence copy is kept.
|
||||
|
||||
### Merge Example
|
||||
|
||||
Given:
|
||||
|
||||
- Global: "Never delete production data", "Log all changes"
|
||||
- Project (`myapp`): "All API changes need tests", "Log all changes"
|
||||
- Plan: "Use Python 3.13 only"
|
||||
|
||||
The effective set for a plan targeting `myapp` would be:
|
||||
|
||||
1. "Use Python 3.13 only" (plan)
|
||||
2. "All API changes need tests" (project)
|
||||
3. "Log all changes" (project — shadows the global duplicate)
|
||||
4. "Never delete production data" (global)
|
||||
|
||||
---
|
||||
|
||||
## Invariant Enforcement During Strategize
|
||||
|
||||
At the start of the Strategize phase, the `InvariantReconciliationActor`:
|
||||
|
||||
1. Calls `InvariantService.get_effective_invariants(plan_id, project_name)` to collect
|
||||
the merged invariant set.
|
||||
2. Evaluates each invariant against the current plan context.
|
||||
3. Creates an `InvariantEnforcementRecord` for each invariant.
|
||||
4. Records an `invariant_enforced` decision in the decision tree.
|
||||
5. Emits `INVARIANT_VIOLATED` for each violated invariant.
|
||||
6. Blocks the phase transition with `ReconciliationBlockedError` if any invariant fails.
|
||||
|
||||
### Enforcement Record
|
||||
|
||||
Each record contains:
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `invariant_id` | ULID of the invariant |
|
||||
| `enforced` | Whether the invariant was successfully enforced |
|
||||
| `actor_response` | Response text from the reconciliation actor |
|
||||
| `decision_id` | ULID of the associated `invariant_enforced` decision node |
|
||||
|
||||
### Violation Model
|
||||
|
||||
When an invariant is violated, an `InvariantViolation` is created:
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `invariant_id` | ULID of the violated invariant |
|
||||
| `violated_text` | The invariant text that was violated |
|
||||
| `severity` | `error`, `warning`, or `info` |
|
||||
| `details` | Additional violation context |
|
||||
|
||||
---
|
||||
|
||||
## Python API
|
||||
|
||||
The `InvariantService` is registered as a Singleton in the DI container. Obtain it via
|
||||
`container.invariant_service()` rather than constructing it directly.
|
||||
|
||||
```python
|
||||
from cleveragents.application.services.invariant_service import InvariantService
|
||||
from cleveragents.domain.models.core.invariant import InvariantScope
|
||||
|
||||
service = InvariantService(event_bus=event_bus)
|
||||
|
||||
# Add an invariant
|
||||
inv = service.add_invariant(
|
||||
text="All output files must be UTF-8 encoded",
|
||||
scope=InvariantScope.PROJECT,
|
||||
source_name="my-project",
|
||||
)
|
||||
|
||||
# List effective invariants for a plan
|
||||
effective = service.get_effective_invariants(
|
||||
plan_id="01HV...",
|
||||
project_name="my-project",
|
||||
)
|
||||
|
||||
# Remove an invariant (soft-delete)
|
||||
service.remove_invariant(invariant_id="01HXYZ...")
|
||||
```
|
||||
|
||||
**Key methods:**
|
||||
|
||||
| Method | Returns | Description |
|
||||
|--------|---------|-------------|
|
||||
| `add_invariant(text, scope, source_name)` | `Invariant` | Add a new invariant |
|
||||
| `list_invariants(scope, source_name, effective)` | `list[Invariant]` | Filter invariants |
|
||||
| `remove_invariant(invariant_id)` | `Invariant` | Soft-delete (sets `active=False`) |
|
||||
| `get_effective_invariants(plan_id, project_name)` | `list[Invariant]` | Merged precedence chain |
|
||||
| `enforce_invariants(plan_id, invariants, actor_response, violated_ids)` | `list[InvariantEnforcementRecord]` | Create enforcement records |
|
||||
|
||||
---
|
||||
|
||||
## See Also
|
||||
|
||||
- [`docs/reference/invariants.md`](../reference/invariants.md) — Full invariant domain model reference
|
||||
- [`docs/api/decisions.md`](decisions.md) — Decision recording and tree CLI reference
|
||||
- [ADR-016: Invariant System](../adr/ADR-016-invariant-system.md)
|
||||
@@ -0,0 +1,272 @@
|
||||
# Plan Correction API (v3.2.0 / v3.3.0)
|
||||
|
||||
The correction subsystem allows operators to modify a plan's decision tree after
|
||||
execution by either **reverting** a subtree of decisions or **appending** new guidance
|
||||
as a child plan. This page documents the CLI commands, correction modes, and the
|
||||
subplan system that powers append-mode corrections.
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Plan corrections introduced across **v3.2.0** and **v3.3.0** provide two complementary
|
||||
modes for adapting a plan's strategy without discarding accumulated context:
|
||||
|
||||
| Mode | Effect |
|
||||
|------|--------|
|
||||
| `revert` | Invalidates the targeted decision and all descendants; re-executes from that point |
|
||||
| `append` | Preserves the original decision; spawns a new child plan with operator guidance |
|
||||
|
||||
Corrections never mutate existing decisions. Instead, a new `Decision` is created with
|
||||
`is_correction=True` and `corrects_decision_id` pointing to the original. The original
|
||||
decision has its `superseded_by` field set to the new decision's ID.
|
||||
|
||||
---
|
||||
|
||||
## CLI Reference
|
||||
|
||||
### `agents plan correct`
|
||||
|
||||
Apply a correction to a plan's decision tree.
|
||||
|
||||
```bash
|
||||
agents plan correct <PLAN_ID> --decision <DECISION_ID> --mode <MODE> --guidance <TEXT> [OPTIONS]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--decision` | ULID of the decision to correct (required) |
|
||||
| `--mode` | Correction mode: `revert` or `append` (required) |
|
||||
| `--guidance` | Operator guidance text (1–10,000 characters, required) |
|
||||
| `--dry-run` | Preview impact without making changes |
|
||||
| `--yes`, `-y` | Skip the interactive confirmation prompt |
|
||||
| `--format`, `-f` | Output format: `json`, `yaml`, `plain`, `table`, `rich` |
|
||||
|
||||
**Revert mode — re-execute from a targeted decision point:**
|
||||
|
||||
```bash
|
||||
agents plan correct 01HXYZ... \
|
||||
--decision 01HABC... \
|
||||
--mode=revert \
|
||||
--guidance "Use a safer database migration approach"
|
||||
```
|
||||
|
||||
This invalidates the targeted decision and every descendant reachable via BFS traversal.
|
||||
Associated artifacts are archived and affected child plans are rolled back. The plan then
|
||||
re-executes from the targeted decision point using the operator's guidance.
|
||||
|
||||
**Append mode — add guidance without recomputing:**
|
||||
|
||||
```bash
|
||||
agents plan correct 01HXYZ... \
|
||||
--decision 01HABC... \
|
||||
--mode=append \
|
||||
--guidance "Add input validation to the API endpoint"
|
||||
```
|
||||
|
||||
This preserves the original decision and spawns a **new child plan** rooted at the target
|
||||
node. The child plan carries the operator's guidance and produces additional decisions
|
||||
without disturbing the existing tree.
|
||||
|
||||
**Dry-run preview:**
|
||||
|
||||
```bash
|
||||
agents plan correct 01HXYZ... \
|
||||
--decision 01HABC... \
|
||||
--mode=revert \
|
||||
--guidance "..." \
|
||||
--dry-run
|
||||
```
|
||||
|
||||
The dry-run report includes:
|
||||
|
||||
- **impact** — Affected decisions, files, child plans, estimated cost, and risk level.
|
||||
- **decisions_to_invalidate** — Decision IDs that *would* be marked invalid (revert only).
|
||||
- **child_plans_to_rollback** — Child plans that *would* be rolled back.
|
||||
- **estimated_recompute_time_seconds** — Wall-clock estimate.
|
||||
- **warnings** — Human-readable cautions (e.g. high risk).
|
||||
|
||||
---
|
||||
|
||||
## Correction Modes in Detail
|
||||
|
||||
### Revert Mode
|
||||
|
||||
Invalidates the targeted decision and every descendant reachable via BFS traversal:
|
||||
|
||||
```
|
||||
┌─── D1 (target) ◄── revert starts here
|
||||
│ │
|
||||
│ ┌──┴──┐
|
||||
│ D2 D3 ← all invalidated
|
||||
│ │
|
||||
│ D4 ← also invalidated
|
||||
```
|
||||
|
||||
**Risk classification** based on affected decision count:
|
||||
|
||||
| Affected Count | Risk Level |
|
||||
|----------------|------------|
|
||||
| ≤ 3 | low |
|
||||
| 4 – 10 | medium |
|
||||
| > 10 | high |
|
||||
|
||||
### Append Mode
|
||||
|
||||
Preserves the original decision and spawns a new child plan:
|
||||
|
||||
```
|
||||
D1 (target)
|
||||
│
|
||||
┌──┴──────────┐
|
||||
D2 (original) CP-new ← child plan appended
|
||||
```
|
||||
|
||||
The child plan runs in its own sandbox and its results are merged back into the parent
|
||||
plan using the configured merge strategy.
|
||||
|
||||
---
|
||||
|
||||
## Correction Status Lifecycle
|
||||
|
||||
```
|
||||
PENDING → ANALYZING → EXECUTING → APPLIED
|
||||
→ FAILED
|
||||
PENDING → CANCELLED
|
||||
ANALYZING → CANCELLED
|
||||
```
|
||||
|
||||
Each execution of a correction is tracked as a `CorrectionAttemptRecord`. Multiple
|
||||
attempts may exist for a single correction (e.g. if a first attempt fails and the
|
||||
operator retries).
|
||||
|
||||
---
|
||||
|
||||
## Subplan System Overview
|
||||
|
||||
The **append** correction mode relies on the subplan system to spawn and execute child
|
||||
plans. Subplans are also used directly during Strategize when the strategy actor decides
|
||||
to decompose work into parallel or sequential child plans.
|
||||
|
||||
### Spawning Child Plans
|
||||
|
||||
When a `subplan_spawn` or `subplan_parallel_spawn` decision is recorded during
|
||||
Strategize, the `SubplanService` handles the spawn workflow:
|
||||
|
||||
1. Extract spawn decisions from `DecisionService`.
|
||||
2. Build `SpawnEntry` objects from those decisions.
|
||||
3. Validate resource scopes, merge strategy, and parallelism bounds.
|
||||
4. Create `SubplanStatus` and `SpawnMetadata` for each entry.
|
||||
5. Return the result for the caller to persist on the parent plan.
|
||||
|
||||
### Execution Modes
|
||||
|
||||
| Mode | Description |
|
||||
|------|-------------|
|
||||
| `sequential` | Execute one at a time in order |
|
||||
| `parallel` | Execute concurrently (up to `max_parallel`, default 5) |
|
||||
| `dependency_ordered` | Respect DAG dependencies via topological sort |
|
||||
|
||||
### Three-Way Merge
|
||||
|
||||
After subplans complete, their sandbox outputs are merged using the configured
|
||||
`SubplanMergeStrategy`:
|
||||
|
||||
| Strategy | Description |
|
||||
|----------|-------------|
|
||||
| `git_three_way` | Three-way merge via `git merge-file` (default) |
|
||||
| `sequential_apply` | Apply changes in completion order |
|
||||
| `fail_on_conflict` | Raise `MergeConflictError` on any conflict |
|
||||
| `last_wins` | Final subplan's output overwrites earlier ones |
|
||||
|
||||
The `git_three_way` strategy uses `git merge-file` to combine non-overlapping changes
|
||||
from different subplans automatically. Overlapping changes produce conflict markers in
|
||||
the output.
|
||||
|
||||
### Subplan Configuration
|
||||
|
||||
```yaml
|
||||
subplan_config:
|
||||
execution_mode: parallel # sequential | parallel | dependency_ordered
|
||||
merge_strategy: git_three_way # git_three_way | sequential_apply | fail_on_conflict | last_wins
|
||||
max_parallel: 5 # 1-50, for parallel mode
|
||||
fail_fast: false # stop all on first failure
|
||||
timeout_per_subplan_seconds: ~ # optional per-subplan timeout
|
||||
retry_failed: true # auto-retry failed subplans
|
||||
max_retries: 2 # 0-5, max retry attempts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase Reversion
|
||||
|
||||
When corrections cannot be resolved within the current strategy, the plan may revert to
|
||||
an earlier lifecycle phase:
|
||||
|
||||
| Source Phase | Target Phase | Trigger |
|
||||
|-------------|-------------|---------|
|
||||
| Execute | Strategize | Validation failures block apply; constraints too restrictive |
|
||||
| Apply (constrained) | Strategize | Cannot proceed within current strategy constraints |
|
||||
|
||||
Phase reversion is subject to a **loop guard**: each plan may revert at most **3 times**
|
||||
(`Plan.MAX_REVERSIONS`). Once this limit is reached, both automatic and manual
|
||||
reversions are blocked.
|
||||
|
||||
Manual reversion via CLI:
|
||||
|
||||
```bash
|
||||
agents plan revert <plan_id> --to-phase strategize --reason "constraints too strict"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Python API
|
||||
|
||||
```python
|
||||
from cleveragents.application.services.correction_service import CorrectionService
|
||||
from cleveragents.domain.models.core.correction import CorrectionMode
|
||||
|
||||
correction_service = CorrectionService(unit_of_work=uow)
|
||||
|
||||
# Request a correction
|
||||
correction = correction_service.request_correction(
|
||||
plan_id="01HV...",
|
||||
original_decision_id="01HABC...",
|
||||
mode=CorrectionMode.REVERT,
|
||||
guidance="Use a safer database migration approach",
|
||||
)
|
||||
|
||||
# Preview impact (dry run)
|
||||
report = correction_service.generate_dry_run_report(correction.id)
|
||||
print(f"Risk: {report.impact.risk_level}, Affected: {len(report.decisions_to_invalidate)}")
|
||||
|
||||
# Execute the correction
|
||||
correction_service.execute_correction(correction.id)
|
||||
```
|
||||
|
||||
**Key service methods:**
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `request_correction()` | Create a new correction request |
|
||||
| `analyze_impact()` | BFS impact analysis on the decision tree |
|
||||
| `generate_dry_run_report()` | Full report without side effects |
|
||||
| `execute_revert()` | Invalidate subtree + archive artifacts |
|
||||
| `execute_append()` | Spawn child plan preserving original decision |
|
||||
| `execute_correction()` | Dispatch to revert or append based on mode |
|
||||
| `get_correction()` | Retrieve a correction by ID |
|
||||
| `list_corrections()` | List corrections (optional plan_id filter) |
|
||||
| `cancel_correction()` | Cancel a pending/analyzing correction |
|
||||
|
||||
---
|
||||
|
||||
## See Also
|
||||
|
||||
- [`docs/reference/decision_correction.md`](../reference/decision_correction.md) — Full correction domain model reference
|
||||
- [`docs/reference/subplans.md`](../reference/subplans.md) — Subplan execution and merge strategies
|
||||
- [`docs/reference/phase_reversion.md`](../reference/phase_reversion.md) — Phase reversion state machine
|
||||
- [`docs/api/decisions.md`](decisions.md) — Decision recording and tree CLI reference
|
||||
- [`docs/api/checkpoints.md`](checkpoints.md) — Checkpoint and rollback CLI reference
|
||||
- [ADR-007: Decision Tree & Correction](../adr/ADR-007-decision-tree-and-correction.md)
|
||||
+79
-52
@@ -10,26 +10,27 @@ The following chart shows all 29 epics across 9 legendary workstreams, 7 milesto
|
||||
@startgantt
|
||||
|
||||
title CleverAgents Core — Epic-Level Project Schedule
|
||||
footer Generated 2026-04-10 | 29 Epics | 9 Legendaries | 7 Milestones | 6 Developers | ~1650 SP | ~25 open bugs | 225 open PRs | Session 4 active
|
||||
footer Generated 2026-04-14 | 29 Epics | 9 Legendaries | 7 Milestones | 6 Developers | ~1650 SP | ~435 open PRs | 3956 open issues | AUTO-TIME-1
|
||||
|
||||
Project starts 2026-02-03
|
||||
saturday are closed
|
||||
sunday are closed
|
||||
printscale weekly zoom 2
|
||||
|
||||
today is 2026-04-10
|
||||
today is 2026-04-14
|
||||
today is colored in #FF6666
|
||||
|
||||
' ================================================================
|
||||
' GANTT CHART UPDATE LOG (Day 100 — 2026-04-10)
|
||||
' Changes: Day 100 refresh (cycle 2). Session 4 active (issue #4799, 32 workers).
|
||||
' Open PRs: 221→225 (new PRs opened by agents). Open bugs: ~25 (Type/Bug label).
|
||||
' M3 32% (249/770, scope expanded!), M4 49% (108/220), M5 43% (133/313),
|
||||
' M6 18% (197/1085, scope massively expanded!), M7 38% (150/400),
|
||||
' M8 45% (425/944), M9 28% (131/475).
|
||||
' Massive scope expansion across all milestones since Day 98.
|
||||
' pr-merge-pool-supervisor added as 17th supervisor. PR review reduced to 1 approval.
|
||||
' git worktree sandbox merged. ACMS indexing pipeline wired.
|
||||
' GANTT CHART UPDATE LOG (Day 104 — 2026-04-14) [AUTO-TIME-1]
|
||||
' Changes: Schedule adherence check. v3.0.0 CLOSED (164 issues, 100%).
|
||||
' v3.1.0 CLOSED (108 issues, 100%). Active milestones v3.2.0–v3.9.0.
|
||||
' M3 (v3.2.0) 21.9% (273/1247, 974 open). M4 (v3.3.0) 34.8% (111/319, 208 open).
|
||||
' M5 (v3.4.0) 34.7% (142/409, 267 open). M6 (v3.5.0) 16.3% (220/1350, 1130 open).
|
||||
' M7 (v3.6.0) 31.2% (153/491, 338 open). M8 (v3.7.0) 41.2% (428/1040, 612 open).
|
||||
' M9 (v3.8.0) 26.6% (135/508, 373 open). v3.9.0 6.9% (4/58, 54 open).
|
||||
' Total open issues: 3,956. Open PRs: ~435. Open Bugs: ~3.
|
||||
' Milestones v3.2.0–v3.6.0 are past their planned due dates.
|
||||
' v3.7.0–v3.9.0 have no assigned deadlines.
|
||||
' ================================================================
|
||||
|
||||
<style>
|
||||
@@ -231,7 +232,7 @@ ganttDiagram {
|
||||
|
||||
[Decisions + Validations M3 (#357)] as [M3] on {Luis} {Hamza} {Brent} {Jeff} requires 4 days
|
||||
[M3] starts at [M2]'s end
|
||||
[M3] is 65% completed
|
||||
[M3] is 25% completed
|
||||
[M3] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
' ── v3.3.0 MILESTONE ─────────────────────────────────────────
|
||||
@@ -252,13 +253,13 @@ ganttDiagram {
|
||||
|
||||
[Corrections + Checkpoints M4 (#358)] as [M4] on {Luis} {Jeff} {Brent} {Hamza} requires 3 days
|
||||
[M4] starts at [M3]'s end
|
||||
[M4] is 60% completed
|
||||
[M4] is 40% completed
|
||||
[M4] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
|
||||
[Security + Safety Hardening (#362)] as [SEC] on {Luis} requires 3 days
|
||||
[SEC] starts 2026-03-02
|
||||
[SEC] is 80% completed
|
||||
[SEC] is 36% completed
|
||||
[SEC] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
[Provider Fixes + Runtime (#363)] as [PROV] on {Luis} requires 2 days
|
||||
@@ -283,12 +284,12 @@ ganttDiagram {
|
||||
|
||||
[ACMS v1 + Context Scaling M5 (#359)] as [M5] on {Hamza} {Jeff} {Aditya} {Brent} requires 4 days
|
||||
[M5] starts at [M4]'s end
|
||||
[M5] is 68% completed
|
||||
[M5] is 36% completed
|
||||
[M5] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
[Autonomy Hardening + Stubs M6 (#360)] as [M6] on {Luis} {Jeff} {Hamza} {Brent} requires 5 days
|
||||
[M6] starts at [M5]'s end
|
||||
[M6] is 55% completed
|
||||
[M6] is 17% completed
|
||||
[M6] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
|
||||
@@ -299,7 +300,7 @@ ganttDiagram {
|
||||
|
||||
[Large Project Autonomy (#369)] as [LARGE] on {Luis} {Brent} {Jeff} requires 4 days
|
||||
[LARGE] starts 2026-03-17
|
||||
[LARGE] is 43% completed
|
||||
[LARGE] is 42% completed
|
||||
[LARGE] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
' ── v3.5.0 MILESTONE ─────────────────────────────────────────
|
||||
@@ -319,13 +320,13 @@ ganttDiagram {
|
||||
|
||||
[Post-MVP Deferred Work (#366)] as [POST] on {Luis} {Hamza} {Jeff} {Rui} {Brent} requires 8 days
|
||||
[POST] starts at [M6]'s end
|
||||
[POST] is 0% completed
|
||||
[POST] is colored in #E8E8E8/Silver
|
||||
[POST] is 33% completed
|
||||
[POST] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
[Multi-Agent RDF System (#367)] as [RDF] on {Aditya} requires 5 days
|
||||
[RDF] starts 2026-03-24
|
||||
[RDF] is 0% completed
|
||||
[RDF] is colored in #E8E8E8/Silver
|
||||
[RDF] is 33% completed
|
||||
[RDF] is colored in LightSkyBlue/SteelBlue
|
||||
|
||||
' ── v3.6.0 MILESTONE ─────────────────────────────────────────
|
||||
' Gate: All post-MVP deferred work
|
||||
@@ -401,15 +402,18 @@ legend right
|
||||
| v3.5.0 | Mar 10 | 2 | 151 | Autonomy hardening + server stubs |
|
||||
| v3.6.0 | Mar 27 | 2 | 100 | Deferred work |
|
||||
----
|
||||
**Risk Register (Day 100 — 2026-04-10)**
|
||||
|= Epic |= Completion |= Risk |= Blocker |
|
||||
| M3 (#357) | 32% | **CRITICAL** | 521 open issues in v3.2.0 (scope expanded 320→770) |
|
||||
| M4 (#358) | 49% | **CRITICAL** | 112 open issues in v3.3.0 |
|
||||
| M5 (#359) | 43% | **HIGH** | 180 open issues in v3.4.0 |
|
||||
| M6 (#360) | 18% | **CRITICAL** | 888 open issues in v3.5.0 (massive scope expansion) |
|
||||
| M7 (#361) | 38% | **HIGH** | 250 open issues in v3.6.0 |
|
||||
| M8 (#362) | 45% | **HIGH** | 519 open issues in v3.7.0 |
|
||||
| SEC (#363) | 28% | **HIGH** | 344 open issues in v3.8.0 |
|
||||
**Risk Register (Day 104 — 2026-04-14) [AUTO-TIME-1]**
|
||||
|= Milestone |= Completion |= Risk |= Blocker |
|
||||
| v3.0.0 | 100% ✅ | **CLOSED** | Complete — 164 issues closed |
|
||||
| v3.1.0 | 100% ✅ | **CLOSED** | Complete — 108 issues closed |
|
||||
| v3.2.0 | 21.9% | **CRITICAL** | 974 open issues; past due 2026-02-26 |
|
||||
| v3.3.0 | 34.8% | **CRITICAL** | 208 open issues; past due 2026-03-02 |
|
||||
| v3.4.0 | 34.7% | **CRITICAL** | 267 open issues; past due 2026-03-06 |
|
||||
| v3.5.0 | 16.3% | **CRITICAL** | 1130 open issues; past due 2026-03-10 |
|
||||
| v3.6.0 | 31.2% | **HIGH** | 338 open issues; past due 2026-03-28 |
|
||||
| v3.7.0 | 41.2% | **HIGH** | 612 open issues; no deadline |
|
||||
| v3.8.0 | 26.6% | **HIGH** | 373 open issues; no deadline |
|
||||
| v3.9.0 | 6.9% | **MEDIUM** | 54 open issues; no deadline |
|
||||
----
|
||||
**Color Key**
|
||||
|= Color |= Meaning |
|
||||
@@ -417,11 +421,12 @@ legend right
|
||||
| <back:LightSkyBlue> </back> | In Progress |
|
||||
| <back:#E8E8E8> </back> | Not Started |
|
||||
| <back:Gold> <> </back> | Milestone Target |
|
||||
| <back:#FF6666> | </back> | Today (2026-04-10) |
|
||||
| <back:#FF6666> | </back> | Today (2026-04-14) |
|
||||
----
|
||||
29 Epics | 9 Legendaries | 7 Milestones | 6 Developers
|
||||
~1649 total story points | ~3300 estimated hours
|
||||
**~25 open bugs (Type/Bug) — 225 open PRs — Session 4 active (32 workers)**
|
||||
**v3.0.0 ✅ CLOSED (164 issues) — v3.1.0 ✅ CLOSED (108 issues)**
|
||||
**3,956 open issues — ~435 open PRs — v3.2.0–v3.9.0 active [AUTO-TIME-1 2026-04-14]**
|
||||
end legend
|
||||
|
||||
@endgantt
|
||||
@@ -445,7 +450,7 @@ saturday are closed
|
||||
sunday are closed
|
||||
printscale weekly zoom 2
|
||||
|
||||
today is 2026-04-10
|
||||
today is 2026-04-14
|
||||
today is colored in #FF6666
|
||||
|
||||
<style>
|
||||
@@ -1950,11 +1955,11 @@ legend right
|
||||
| <back:LightSkyBlue> </back> | Issue: In Progress |
|
||||
| <back:#E8E8E8> </back> | Issue: Not Started |
|
||||
| <back:Gold> <> </back> | Milestone Target |
|
||||
| <back:#FF6666> | </back> | Today (2026-04-10) |
|
||||
| <back:#FF6666> | </back> | Today (2026-04-14) |
|
||||
----
|
||||
271 Issues | 29 Epics | 9 Legendaries | 7 Milestones
|
||||
~1649 total story points | ~3300 estimated hours
|
||||
**~5 open bugs (Type/Bug) — 219 open PRs — Session 4 active (32 workers)**
|
||||
**v3.0.0 ✅ CLOSED — v3.1.0 ✅ CLOSED — 3,956 open issues — ~435 open PRs [AUTO-TIME-1 2026-04-14]**
|
||||
end legend
|
||||
|
||||
@endgantt
|
||||
@@ -1966,13 +1971,13 @@ This section provides a high-level overview of the CleverAgents implementation r
|
||||
|
||||
### Current Status Summary
|
||||
|
||||
As of Day 100 (2026-04-10), the project has **225 open PRs** and **~2777 open issues** across active milestones. **Session 4 is active (launched 2026-04-08, issue #4799) with 32 parallel workers and full supervisor fleet**. Bug count is **~25 open bugs** (Type/Bug label; UAT issues tracked separately). M8 (v3.7.0) is now **45% complete** (425/944 issues closed). M3 (v3.2.0) at **32%** (249/770 — scope massively expanded), M4 (v3.3.0) at **49%** (108/220), M5 (v3.4.0) at **43%** (133/313), M6 (v3.5.0) at **18%** (197/1085 — scope massively expanded), M7 (v3.6.0) at **38%** (150/400).
|
||||
As of 2026-04-14 [AUTO-TIME-1], the project has **~435 open PRs** and **3,956 open issues** across active milestones. **v3.0.0 and v3.1.0 are CLOSED and 100% complete.** Active development spans v3.2.0–v3.9.0. Milestones v3.2.0–v3.6.0 are past their planned due dates. v3.7.0–v3.9.0 have no assigned deadlines.
|
||||
|
||||
**M1, M2 fully complete. M3 (v3.2.0)**: 33% complete (248/757), 509 open issues — scope expanded massively. **M4 (v3.3.0)**: 49% complete (108/220), 112 open issues. **M5 (v3.4.0)**: 44% complete (133/301), 168 open issues. **M6 (v3.5.0)**: 18% complete (197/1065), 868 open issues — scope expanded massively. **M7 (v3.6.0)**: 38% complete (150/392), 242 open issues. **M8 (v3.7.0)**: 45% complete (423/938), 515 open issues. All milestones M3-M7 are **overdue**; M8 is in active v3.7.0 development.
|
||||
**v3.0.0 ✅ CLOSED** (164 issues, 100% complete). **v3.1.0 ✅ CLOSED** (108 issues, 100% complete). **v3.2.0**: 21.9% complete (273 closed, 974 open) — past due 2026-02-26. **v3.3.0**: 34.8% complete (111 closed, 208 open) — past due 2026-03-02. **v3.4.0**: 34.7% complete (142 closed, 267 open) — past due 2026-03-06. **v3.5.0**: 16.3% complete (220 closed, 1,130 open) — past due 2026-03-10. **v3.6.0**: 31.2% complete (153 closed, 338 open) — past due 2026-03-28. **v3.7.0**: 41.2% complete (428 closed, 612 open) — no deadline. **v3.8.0**: 26.6% complete (135 closed, 373 open) — no deadline. **v3.9.0**: 6.9% complete (4 closed, 54 open) — no deadline.
|
||||
|
||||
!!! warning "Schedule Risk: All Milestones M3-M7 Overdue — Massive Scope Expansion — Session 4 Active (Day 100: 219 Open PRs, M3/M6 Scope Exploded)"
|
||||
!!! warning "Schedule Risk: v3.0.0 and v3.1.0 Complete — Milestones v3.2.0–v3.6.0 Overdue — 3,956 Open Issues — ~435 Open PRs [AUTO-TIME-1 2026-04-14]"
|
||||
|
||||
All milestones M3 through M7 have passed their target dates. **Session 4 active (launched 2026-04-08, issue #4799) with 32 parallel workers**. Open PRs at **219** (up from 1 — agents opened many new PRs). Open bugs at **~5** (Type/Bug label). Session tracker issue: #4799. **Current priorities**: (1) **M3 scope explosion** — 509 open issues (was 85 at Day 98); scope grew from 320 to 757 total. (2) **M6 scope explosion** — 868 open issues (was 450 at Day 98); scope grew from 638 to 1065 total. (3) **Merge 219 open PRs** — pr-merge-pool-supervisor added as 17th supervisor. (4) **Continue M8 push** — 45% complete, 515 issues remaining. (5) **Clear M4/M5 backlogs** — M4 at 49% (112 open), M5 at 44% (168 open).
|
||||
**v3.0.0 ✅ CLOSED** (164 issues). **v3.1.0 ✅ CLOSED** (108 issues). All milestones v3.2.0 through v3.6.0 have passed their target dates. Open PRs at **~435**. Total open issues: **3,956**. Open Bugs: **~3**. **Current priorities**: (1) **v3.2.0** — 974 open issues, 21.9% complete, past due 2026-02-26. (2) **v3.5.0** — 1,130 open issues, 16.3% complete, past due 2026-03-10. (3) **v3.7.0** — 612 open issues, 41.2% complete, no deadline. (4) **v3.3.0/v3.4.0/v3.6.0** — 208/267/338 open issues respectively. (5) **v3.8.0/v3.9.0** — 373/54 open issues, no deadlines.
|
||||
|
||||
### Parallel Workstreams
|
||||
|
||||
@@ -2140,18 +2145,21 @@ The following areas are substantially implemented and are no longer blocking:
|
||||
|
||||
The milestones and their target dates are:
|
||||
|
||||
| Milestone | Version | Target Date | Day # | Focus |
|
||||
|-----------|---------|------------|-------|-------|
|
||||
| M1 | v3.0.0 | 2026-02-15 | Day 7 | Minimal local source-code workflow |
|
||||
| M2 | v3.1.0 | 2026-02-22 | Day 14 | Actor graphs + tool sources |
|
||||
| M3 | v3.2.0 | 2026-02-26 | Day 18 | Decisions + validations + invariants |
|
||||
| M4 | v3.3.0 | 2026-03-02 | Day 22 | Corrections + subplans + checkpoints |
|
||||
| M5 | v3.4.0 | 2026-03-06 | Day 26 | ACMS v1 + context scaling |
|
||||
| M6 | v3.5.0 | 2026-03-10 | Day 30 | Autonomy hardening |
|
||||
| M7 | v3.6.0 | 2026-03-28 | Day 48 | Advanced Concepts & Deferred Features |
|
||||
| M8 | v3.7.0 | Not set | N/A | TUI Implementation |
|
||||
| M9 | v3.8.0 | Not Set | N/A | Server Implementation |
|
||||
| Post-MVP | Not Set | Not Set | N/A | Deferred work |
|
||||
| Milestone | Version | Target Date | Day # | Focus | Status |
|
||||
|-----------|---------|------------|-------|-------|--------|
|
||||
| M1 | v3.0.0 | 2026-02-15 | Day 7 | Minimal local source-code workflow | ✅ CLOSED (164 issues) |
|
||||
| M2 | v3.1.0 | 2026-02-22 | Day 14 | Actor graphs + tool sources | ✅ CLOSED (108 issues) |
|
||||
| M3 | v3.2.0 | 2026-02-26 | Day 18 | Decisions + validations + invariants | ⚠️ 21.9% (974 open) |
|
||||
| M4 | v3.3.0 | 2026-03-02 | Day 22 | Corrections + subplans + checkpoints | ⚠️ 34.8% (208 open) |
|
||||
| M5 | v3.4.0 | 2026-03-06 | Day 26 | ACMS v1 + context scaling | ⚠️ 34.7% (267 open) |
|
||||
| M6 | v3.5.0 | 2026-03-10 | Day 30 | Autonomy hardening | ⚠️ 16.3% (1130 open) |
|
||||
| M7 | v3.6.0 | 2026-03-28 | Day 48 | Advanced Concepts & Deferred Features | ⚠️ 31.2% (338 open) |
|
||||
| M8 | v3.7.0 | Not set | N/A | TUI Implementation | 🔄 41.2% (612 open) |
|
||||
| M9 | v3.8.0 | Not Set | N/A | Server Implementation | 🔄 26.6% (373 open) |
|
||||
| M10 | v3.9.0 | Not Set | N/A | Extended features | 🔄 6.9% (54 open) |
|
||||
| Post-MVP | Not Set | Not Set | N/A | Deferred work | 🔄 In Progress |
|
||||
|
||||
_Table updated by [AUTO-TIME-1] on 2026-04-14_
|
||||
|
||||
Day numbers are relative to the project kickoff on **February 9, 2026**.
|
||||
|
||||
@@ -2291,7 +2299,7 @@ Items without an assigned milestone represent backlog work to be addressed after
|
||||
|
||||
### Schedule Risk Summary
|
||||
|
||||
As of Day 96 (2026-04-06), all milestones M3 through M7 are **overdue**. The original 7-8 day slippage has grown to **20+ days** for M3-M6. **Session 3 is active with 16 parallel workers (~71 total agents)**. Open PRs now at **108** (down from 183 — 75 PRs merged/closed!). Open bugs at **~878** (stable). M8 (v3.7.0) at **46% complete** (418/917 closed). M9 (v3.8.0) at **28% complete** (131/467 closed). Session tracker: #3775. Critical path: PR #3774 (Click 8.2+ fix) must be merged; 108 open PRs need review and merge; M3/M4/M5/M6/M7 all overdue; M8 at 46% with 499 issues remaining; ~878 open bugs need TDD counterparts and systematic triage.
|
||||
As of 2026-04-14 [AUTO-TIME-1], **v3.0.0 and v3.1.0 are CLOSED and 100% complete**. All milestones v3.2.0 through v3.6.0 are **overdue**. Open PRs at **~435**. Total open issues: **3,956** across v3.2.0–v3.9.0. Open Bugs: **~3**. v3.2.0 at **21.9%** (273/1247 closed, 974 open). v3.3.0 at **34.8%** (111/319 closed, 208 open). v3.4.0 at **34.7%** (142/409 closed, 267 open). v3.5.0 at **16.3%** (220/1350 closed, 1,130 open). v3.6.0 at **31.2%** (153/491 closed, 338 open). v3.7.0 at **41.2%** (428/1040 closed, 612 open). v3.8.0 at **26.6%** (135/508 closed, 373 open). v3.9.0 at **6.9%** (4/58 closed, 54 open). Milestones v3.7.0–v3.9.0 have no assigned deadlines.
|
||||
|
||||
**Day 50 planning actions (completed)**: (a) 2 reviewers assigned to all 20 open PRs. (b) Comments posted on #1154 and #1168 recommending closure. (c) Escalation comments on PRs with missing branches. (d) Issue #1206 created for `@tdd_expected_fail` tag cleanup. (e) Timeline updated with Day 50 schedule adherence entry.
|
||||
|
||||
@@ -5316,3 +5324,22 @@ Story points per developer per milestone.
|
||||
| M9 | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ~TBD SP |
|
||||
| M6+ | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ~TBD SP |
|
||||
| **Total** | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ~1649 SP |
|
||||
|
||||
### 2026-04-14 — Schedule Adherence Check [AUTO-TIME-1]
|
||||
|
||||
| Milestone | State | Open Issues | Closed Issues | Completion | Status |
|
||||
|-----------|--------|-------------|---------------|------------|--------|
|
||||
| v3.0.0 | CLOSED | 0 | 164 | 100% | ✅ Complete |
|
||||
| v3.1.0 | CLOSED | 0 | 108 | 100% | ✅ Complete |
|
||||
| v3.2.0 | OPEN | 974 | 273 | 21.9% | ⚠️ Behind (due 2026-02-26) |
|
||||
| v3.3.0 | OPEN | 208 | 111 | 34.8% | ⚠️ Behind (due 2026-03-02) |
|
||||
| v3.4.0 | OPEN | 267 | 142 | 34.7% | ⚠️ Behind (due 2026-03-06) |
|
||||
| v3.5.0 | OPEN | 1130 | 220 | 16.3% | ⚠️ Behind (due 2026-03-10) |
|
||||
| v3.6.0 | OPEN | 338 | 153 | 31.2% | ⚠️ Behind (due 2026-03-28) |
|
||||
| v3.7.0 | OPEN | 612 | 428 | 41.2% | 🔄 In Progress (no deadline) |
|
||||
| v3.8.0 | OPEN | 373 | 135 | 26.6% | 🔄 In Progress (no deadline) |
|
||||
| v3.9.0 | OPEN | 54 | 4 | 6.9% | 🔄 In Progress (no deadline) |
|
||||
|
||||
**Summary**: v3.0.0 and v3.1.0 are complete. Active development spans v3.2.0–v3.9.0 with 3,956 open issues, ~435 open PRs, and ~3 open bugs. Milestones v3.2.0–v3.6.0 are past their planned due dates. v3.7.0–v3.9.0 have no assigned deadlines.
|
||||
|
||||
_Updated by [AUTO-TIME-1] on 2026-04-14_
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
Feature: Plan Tree Decision Rendering
|
||||
As a user
|
||||
I want to view the decision tree of a plan
|
||||
So that I can audit the decision history and identify correction points
|
||||
|
||||
Background:
|
||||
Given a plan with ID "plan-test-001"
|
||||
And the plan has the following decisions:
|
||||
| decision_id | type | parent_id | question | chosen_option | status |
|
||||
| d-001 | prompt_definition | None | What is the task? | Analyze code | completed |
|
||||
| d-002 | strategy_choice | d-001 | Which strategy to use? | Iterative | completed |
|
||||
| d-003 | tool_selection | d-002 | Which tool for linting? | ruff | completed |
|
||||
| d-004 | parameter | d-002 | Set max retries? | 3 | reverted |
|
||||
| d-005 | branch | d-001 | Await confirmation? | pending | pending |
|
||||
|
||||
Scenario: Display plan tree in rich format
|
||||
When I run "agents plan tree plan-test-001"
|
||||
Then the output should contain "Plan Decision Tree: plan-test-001"
|
||||
And the output should contain "d-001"
|
||||
And the output should contain "prompt_definition"
|
||||
And the output should contain "completed"
|
||||
And the output should contain "d-002"
|
||||
And the output should contain "strategy_choice"
|
||||
And the output should contain "d-003"
|
||||
And the output should contain "tool_selection"
|
||||
And the output should contain "d-004"
|
||||
And the output should contain "parameter"
|
||||
And the output should contain "reverted"
|
||||
And the output should contain "d-005"
|
||||
And the output should contain "branch"
|
||||
And the output should contain "pending"
|
||||
|
||||
Scenario: Display plan tree in plain text format
|
||||
When I run "agents plan tree plan-test-001 --format plain"
|
||||
Then the output should contain "Plan Decision Tree: plan-test-001"
|
||||
And the output should contain "`--" or "|--"
|
||||
And the output should contain "[completed]"
|
||||
And the output should contain "[reverted]"
|
||||
And the output should contain "[pending]"
|
||||
|
||||
Scenario: Display plan tree in JSON format
|
||||
When I run "agents plan tree plan-test-001 --format json"
|
||||
Then the output should be valid JSON
|
||||
And the JSON should contain "plan_id": "plan-test-001"
|
||||
And the JSON should contain "root"
|
||||
And the JSON root should have "decision_id": "d-001"
|
||||
And the JSON root should have "children" array with 2 items
|
||||
|
||||
Scenario: Limit tree depth to 1
|
||||
When I run "agents plan tree plan-test-001 --depth 1"
|
||||
Then the output should contain "d-001"
|
||||
And the output should contain "d-002"
|
||||
And the output should NOT contain "d-003"
|
||||
And the output should NOT contain "d-004"
|
||||
|
||||
Scenario: Limit tree depth to 2
|
||||
When I run "agents plan tree plan-test-001 --depth 2"
|
||||
Then the output should contain "d-001"
|
||||
And the output should contain "d-002"
|
||||
And the output should contain "d-003"
|
||||
And the output should contain "d-004"
|
||||
And the output should NOT contain "d-005"
|
||||
|
||||
Scenario: Handle non-existent plan ID
|
||||
When I run "agents plan tree plan-nonexistent"
|
||||
Then the exit code should be non-zero
|
||||
And the output should contain "not found"
|
||||
|
||||
Scenario: Handle plan with no decisions
|
||||
Given a plan with ID "plan-empty"
|
||||
When I run "agents plan tree plan-empty"
|
||||
Then the output should contain "not found" or "no decisions"
|
||||
|
||||
Scenario: Tree structure is hierarchical
|
||||
When I run "agents plan tree plan-test-001 --format plain"
|
||||
Then the output should show d-002 as a child of d-001
|
||||
And the output should show d-003 as a child of d-002
|
||||
And the output should show d-004 as a child of d-002
|
||||
And the output should show d-005 as a child of d-001
|
||||
@@ -0,0 +1,253 @@
|
||||
"""Step definitions for plan tree decision rendering feature."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
from behave import given, then, when
|
||||
from behave.runner import Context
|
||||
|
||||
from cleveragents.domain.models.core.decision import Decision, DecisionType
|
||||
from cleveragents.domain.models.core.plan import Plan
|
||||
|
||||
|
||||
@given('a plan with ID "{plan_id}"')
|
||||
def step_create_plan(context: Context, plan_id: str) -> None:
|
||||
"""Create a test plan with the given ID."""
|
||||
if not hasattr(context, "plans"):
|
||||
context.plans = {}
|
||||
|
||||
plan = Plan(
|
||||
plan_id=plan_id,
|
||||
name=f"Test Plan {plan_id}",
|
||||
description="Test plan for decision tree rendering",
|
||||
)
|
||||
context.plans[plan_id] = plan
|
||||
|
||||
|
||||
@given("the plan has the following decisions")
|
||||
def step_add_decisions(context: Context) -> None:
|
||||
"""Add decisions to the current plan."""
|
||||
if not hasattr(context, "decisions"):
|
||||
context.decisions = {}
|
||||
|
||||
# Get the last created plan
|
||||
plan_id = list(context.plans.keys())[-1]
|
||||
|
||||
for row in context.table:
|
||||
decision_id = row["decision_id"]
|
||||
decision_type = DecisionType(row["type"])
|
||||
parent_id = row["parent_id"] if row["parent_id"] != "None" else None
|
||||
question = row["question"]
|
||||
chosen_option = row["chosen_option"]
|
||||
status = row["status"]
|
||||
|
||||
decision = Decision(
|
||||
decision_id=decision_id,
|
||||
plan_id=plan_id,
|
||||
parent_decision_id=parent_id,
|
||||
sequence_number=len(context.decisions),
|
||||
decision_type=decision_type,
|
||||
question=question,
|
||||
chosen_option=chosen_option,
|
||||
rationale=f"Rationale for {chosen_option}",
|
||||
created_at=datetime.now(datetime.UTC),
|
||||
)
|
||||
|
||||
# Add status attribute (not in base model, but needed for rendering)
|
||||
decision.status = status
|
||||
|
||||
context.decisions[decision_id] = decision
|
||||
|
||||
|
||||
@when('I run "agents plan tree {plan_id}"')
|
||||
def step_run_plan_tree_command(context: Context, plan_id: str) -> None:
|
||||
"""Run the plan tree command."""
|
||||
context.last_command = ["agents", "plan", "tree", plan_id]
|
||||
step_run_command(context)
|
||||
|
||||
|
||||
@when('I run "agents plan tree {plan_id} --format {format_type}"')
|
||||
def step_run_plan_tree_with_format(
|
||||
context: Context, plan_id: str, format_type: str
|
||||
) -> None:
|
||||
"""Run the plan tree command with format option."""
|
||||
context.last_command = [
|
||||
"agents",
|
||||
"plan",
|
||||
"tree",
|
||||
plan_id,
|
||||
"--format",
|
||||
format_type,
|
||||
]
|
||||
step_run_command(context)
|
||||
|
||||
|
||||
@when('I run "agents plan tree {plan_id} --depth {depth}"')
|
||||
def step_run_plan_tree_with_depth(
|
||||
context: Context, plan_id: str, depth: str
|
||||
) -> None:
|
||||
"""Run the plan tree command with depth option."""
|
||||
context.last_command = [
|
||||
"agents",
|
||||
"plan",
|
||||
"tree",
|
||||
plan_id,
|
||||
"--depth",
|
||||
depth,
|
||||
]
|
||||
step_run_command(context)
|
||||
|
||||
|
||||
@when('I run "agents plan tree {plan_id} --format {format_type} --depth {depth}"')
|
||||
def step_run_plan_tree_with_format_and_depth(
|
||||
context: Context, plan_id: str, format_type: str, depth: str
|
||||
) -> None:
|
||||
"""Run the plan tree command with both format and depth options."""
|
||||
context.last_command = [
|
||||
"agents",
|
||||
"plan",
|
||||
"tree",
|
||||
plan_id,
|
||||
"--format",
|
||||
format_type,
|
||||
"--depth",
|
||||
depth,
|
||||
]
|
||||
step_run_command(context)
|
||||
|
||||
|
||||
def step_run_command(context: Context) -> None:
|
||||
"""Execute the command and capture output."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
context.last_command,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10,
|
||||
)
|
||||
context.last_exit_code = result.returncode
|
||||
context.last_output = result.stdout + result.stderr
|
||||
except subprocess.TimeoutExpired:
|
||||
context.last_exit_code = 124
|
||||
context.last_output = "Command timed out"
|
||||
except Exception as e:
|
||||
context.last_exit_code = 1
|
||||
context.last_output = str(e)
|
||||
|
||||
|
||||
@then("the output should contain {text}")
|
||||
def step_output_contains(context: Context, text: str) -> None:
|
||||
"""Check that output contains the given text."""
|
||||
# Remove quotes if present
|
||||
text = text.strip('"')
|
||||
assert text in context.last_output, (
|
||||
f"Expected '{text}' in output, but got:\n{context.last_output}"
|
||||
)
|
||||
|
||||
|
||||
@then("the output should NOT contain {text}")
|
||||
def step_output_not_contains(context: Context, text: str) -> None:
|
||||
"""Check that output does not contain the given text."""
|
||||
# Remove quotes if present
|
||||
text = text.strip('"')
|
||||
assert text not in context.last_output, (
|
||||
f"Expected '{text}' NOT in output, but got:\n{context.last_output}"
|
||||
)
|
||||
|
||||
|
||||
@then("the exit code should be non-zero")
|
||||
def step_exit_code_nonzero(context: Context) -> None:
|
||||
"""Check that exit code is non-zero."""
|
||||
assert context.last_exit_code != 0, (
|
||||
f"Expected non-zero exit code, but got {context.last_exit_code}"
|
||||
)
|
||||
|
||||
|
||||
@then("the output should be valid JSON")
|
||||
def step_output_is_valid_json(context: Context) -> None:
|
||||
"""Check that output is valid JSON."""
|
||||
try:
|
||||
context.last_json = json.loads(context.last_output)
|
||||
except json.JSONDecodeError as e:
|
||||
raise AssertionError(
|
||||
f"Output is not valid JSON: {e}\nOutput: {context.last_output}"
|
||||
) from e
|
||||
|
||||
|
||||
@then('the JSON should contain "{key}": "{value}"')
|
||||
def step_json_contains_key_value(
|
||||
context: Context, key: str, value: str
|
||||
) -> None:
|
||||
"""Check that JSON contains a specific key-value pair."""
|
||||
assert key in context.last_json, (
|
||||
f"Expected key '{key}' in JSON, but got: {context.last_json}"
|
||||
)
|
||||
assert context.last_json[key] == value, (
|
||||
f"Expected {key}={value}, but got {key}={context.last_json[key]}"
|
||||
)
|
||||
|
||||
|
||||
@then("the JSON root should have {key}: {value}")
|
||||
def step_json_root_has_key_value(
|
||||
context: Context, key: str, value: str
|
||||
) -> None:
|
||||
"""Check that JSON root has a specific key-value pair."""
|
||||
root = context.last_json.get("root", {})
|
||||
assert key in root, (
|
||||
f"Expected key '{key}' in JSON root, but got: {root}"
|
||||
)
|
||||
assert root[key] == value, (
|
||||
f"Expected {key}={value}, but got {key}={root[key]}"
|
||||
)
|
||||
|
||||
|
||||
@then("the JSON root should have {key} array with {count} items")
|
||||
def step_json_root_has_array(
|
||||
context: Context, key: str, count: str
|
||||
) -> None:
|
||||
"""Check that JSON root has an array with specific count."""
|
||||
root = context.last_json.get("root", {})
|
||||
assert key in root, (
|
||||
f"Expected key '{key}' in JSON root, but got: {root}"
|
||||
)
|
||||
assert isinstance(root[key], list), (
|
||||
f"Expected {key} to be an array, but got {type(root[key])}"
|
||||
)
|
||||
expected_count = int(count)
|
||||
assert len(root[key]) == expected_count, (
|
||||
f"Expected {key} to have {expected_count} items, "
|
||||
f"but got {len(root[key])}"
|
||||
)
|
||||
|
||||
|
||||
@then("the output should show {child_id} as a child of {parent_id}")
|
||||
def step_output_shows_hierarchy(
|
||||
context: Context, child_id: str, parent_id: str
|
||||
) -> None:
|
||||
"""Check that output shows correct hierarchy."""
|
||||
# This is a simplified check - in a real scenario, we'd parse the tree structure
|
||||
lines = context.last_output.split("\n")
|
||||
parent_line_idx = None
|
||||
child_line_idx = None
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
if parent_id in line:
|
||||
parent_line_idx = i
|
||||
if child_id in line:
|
||||
child_line_idx = i
|
||||
|
||||
assert parent_line_idx is not None, (
|
||||
f"Parent {parent_id} not found in output"
|
||||
)
|
||||
assert child_line_idx is not None, (
|
||||
f"Child {child_id} not found in output"
|
||||
)
|
||||
assert parent_line_idx < child_line_idx, (
|
||||
f"Parent {parent_id} should appear before child {child_id}"
|
||||
)
|
||||
|
||||
|
||||
__all__ = []
|
||||
@@ -258,6 +258,15 @@ Feature: Subplan Execution and Merge
|
||||
Then the first subplan should be errored
|
||||
And the remaining subplans should have CANCELLED status
|
||||
|
||||
@parallel @cancel_status
|
||||
Scenario: Parallel fail_fast marks in-flight futures as CANCELLED
|
||||
Given a parent plan with 3 subplans in parallel mode with fail_fast
|
||||
And the subplan executor will block for 1 seconds
|
||||
And the first subplan will fail with "ValidationError: schema mismatch"
|
||||
When the subplans are executed
|
||||
Then the first subplan should be errored
|
||||
And the remaining subplans should have CANCELLED status
|
||||
|
||||
# --- Dependency-ordered concurrent execution ---
|
||||
|
||||
@dependency_ordered @concurrent
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
Feature: Plan Lifecycle Decision Root Type
|
||||
As a developer
|
||||
I want to ensure that the root decision recorded during start_strategize is prompt_definition
|
||||
So that the decision tree has the correct root node type
|
||||
|
||||
Background:
|
||||
Given I have a plan lifecycle service with decision service
|
||||
|
||||
Scenario: start_strategize records prompt_definition as root decision
|
||||
Given an action "local/test-action" with description "Test action description"
|
||||
And a plan created from "local/test-action"
|
||||
When I start strategize on the plan
|
||||
Then the root decision should be recorded with type "prompt_definition"
|
||||
And the root decision question should be "What is the plan prompt?"
|
||||
And the root decision chosen_option should contain the plan description
|
||||
@@ -0,0 +1,260 @@
|
||||
"""Unit tests for plan tree renderers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from cleveragents.application.services.plan_tree_service import DecisionTreeNode
|
||||
from cleveragents.cli.output.plan_tree_renderers import (
|
||||
JsonPlanTreeRenderer,
|
||||
PlainPlanTreeRenderer,
|
||||
RichPlanTreeRenderer,
|
||||
get_renderer,
|
||||
)
|
||||
from cleveragents.domain.models.core.decision import Decision, DecisionType
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_decision_tree() -> DecisionTreeNode:
|
||||
"""Create a sample decision tree for testing."""
|
||||
now = datetime.now(datetime.UTC)
|
||||
|
||||
root_decision = Decision(
|
||||
decision_id="d-001",
|
||||
plan_id="plan-001",
|
||||
parent_decision_id=None,
|
||||
sequence_number=0,
|
||||
decision_type=DecisionType.PROMPT_DEFINITION,
|
||||
question="What is the task?",
|
||||
chosen_option="Analyze code",
|
||||
rationale="User requested analysis",
|
||||
created_at=now,
|
||||
)
|
||||
root_decision.status = "completed"
|
||||
|
||||
child_decision = Decision(
|
||||
decision_id="d-002",
|
||||
plan_id="plan-001",
|
||||
parent_decision_id="d-001",
|
||||
sequence_number=1,
|
||||
decision_type=DecisionType.STRATEGY_CHOICE,
|
||||
question="Which strategy?",
|
||||
chosen_option="Iterative",
|
||||
rationale="Best approach",
|
||||
created_at=now,
|
||||
)
|
||||
child_decision.status = "completed"
|
||||
|
||||
root_node = DecisionTreeNode(decision=root_decision, depth=0)
|
||||
child_node = DecisionTreeNode(decision=child_decision, depth=1)
|
||||
root_node.children.append(child_node)
|
||||
|
||||
return root_node
|
||||
|
||||
|
||||
class TestRichPlanTreeRenderer:
|
||||
"""Tests for RichPlanTreeRenderer."""
|
||||
|
||||
def test_render_includes_plan_id(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes plan ID."""
|
||||
renderer = RichPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "Plan Decision Tree: plan-001" in output
|
||||
|
||||
def test_render_includes_decision_ids(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes decision IDs."""
|
||||
renderer = RichPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "d-001" in output
|
||||
assert "d-002" in output
|
||||
|
||||
def test_render_includes_decision_types(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes decision types."""
|
||||
renderer = RichPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "prompt_definition" in output
|
||||
assert "strategy_choice" in output
|
||||
|
||||
def test_render_includes_status(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes status."""
|
||||
renderer = RichPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "[completed]" in output
|
||||
|
||||
def test_render_includes_timestamp(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes timestamp."""
|
||||
renderer = RichPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
# Check for ISO format timestamp
|
||||
assert "T" in output # ISO format includes T
|
||||
|
||||
def test_render_includes_summary(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes summary."""
|
||||
renderer = RichPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "User requested analysis" in output or "Analyze code" in output
|
||||
|
||||
|
||||
class TestPlainPlanTreeRenderer:
|
||||
"""Tests for PlainPlanTreeRenderer."""
|
||||
|
||||
def test_render_includes_plan_id(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes plan ID."""
|
||||
renderer = PlainPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "Plan Decision Tree: plan-001" in output
|
||||
|
||||
def test_render_uses_ascii_connectors(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render uses ASCII connectors."""
|
||||
renderer = PlainPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
# Should contain ASCII tree connectors
|
||||
assert "|--" in output or "`--" in output
|
||||
|
||||
def test_render_includes_status_in_brackets(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render includes status in brackets."""
|
||||
renderer = PlainPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
assert "[completed" in output
|
||||
|
||||
def test_render_no_color_codes(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that plain renderer has no color codes."""
|
||||
renderer = PlainPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
# Should not contain rich color codes
|
||||
assert "[green]" not in output
|
||||
assert "[red]" not in output
|
||||
assert "[yellow]" not in output
|
||||
|
||||
|
||||
class TestJsonPlanTreeRenderer:
|
||||
"""Tests for JsonPlanTreeRenderer."""
|
||||
|
||||
def test_render_returns_valid_json(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that render returns valid JSON."""
|
||||
import json
|
||||
|
||||
renderer = JsonPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
|
||||
# Should not raise
|
||||
data = json.loads(output)
|
||||
assert isinstance(data, dict)
|
||||
|
||||
def test_render_includes_plan_id(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that JSON includes plan ID."""
|
||||
import json
|
||||
|
||||
renderer = JsonPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
data = json.loads(output)
|
||||
|
||||
assert data["plan_id"] == "plan-001"
|
||||
|
||||
def test_render_includes_root_node(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that JSON includes root node."""
|
||||
import json
|
||||
|
||||
renderer = JsonPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
data = json.loads(output)
|
||||
|
||||
assert "root" in data
|
||||
assert data["root"]["decision_id"] == "d-001"
|
||||
|
||||
def test_render_includes_children(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that JSON includes children."""
|
||||
import json
|
||||
|
||||
renderer = JsonPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
data = json.loads(output)
|
||||
|
||||
root = data["root"]
|
||||
assert "children" in root
|
||||
assert len(root["children"]) == 1
|
||||
assert root["children"][0]["decision_id"] == "d-002"
|
||||
|
||||
def test_render_includes_all_fields(
|
||||
self, sample_decision_tree: DecisionTreeNode
|
||||
) -> None:
|
||||
"""Test that JSON includes all required fields."""
|
||||
import json
|
||||
|
||||
renderer = JsonPlanTreeRenderer()
|
||||
output = renderer.render(sample_decision_tree, "plan-001")
|
||||
data = json.loads(output)
|
||||
|
||||
root = data["root"]
|
||||
assert "decision_id" in root
|
||||
assert "plan_id" in root
|
||||
assert "type" in root
|
||||
assert "timestamp" in root
|
||||
assert "question" in root
|
||||
assert "chosen_option" in root
|
||||
assert "status" in root
|
||||
assert "summary" in root
|
||||
|
||||
|
||||
class TestGetRenderer:
|
||||
"""Tests for get_renderer function."""
|
||||
|
||||
def test_get_renderer_returns_rich_renderer(self) -> None:
|
||||
"""Test that get_renderer returns RichPlanTreeRenderer."""
|
||||
renderer = get_renderer("rich")
|
||||
assert isinstance(renderer, RichPlanTreeRenderer)
|
||||
|
||||
def test_get_renderer_returns_plain_renderer(self) -> None:
|
||||
"""Test that get_renderer returns PlainPlanTreeRenderer."""
|
||||
renderer = get_renderer("plain")
|
||||
assert isinstance(renderer, PlainPlanTreeRenderer)
|
||||
|
||||
def test_get_renderer_returns_json_renderer(self) -> None:
|
||||
"""Test that get_renderer returns JsonPlanTreeRenderer."""
|
||||
renderer = get_renderer("json")
|
||||
assert isinstance(renderer, JsonPlanTreeRenderer)
|
||||
|
||||
def test_get_renderer_raises_for_unknown_format(self) -> None:
|
||||
"""Test that get_renderer raises for unknown format."""
|
||||
with pytest.raises(ValueError):
|
||||
get_renderer("unknown")
|
||||
@@ -0,0 +1,239 @@
|
||||
"""Unit tests for PlanTreeService."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from cleveragents.application.services.plan_tree_service import (
|
||||
DecisionTreeNode,
|
||||
PlanTreeService,
|
||||
)
|
||||
from cleveragents.domain.models.core.decision import Decision, DecisionType
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_plan_repository() -> MagicMock:
|
||||
"""Create a mock plan repository."""
|
||||
return MagicMock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_decision_repository() -> MagicMock:
|
||||
"""Create a mock decision repository."""
|
||||
return MagicMock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def plan_tree_service(
|
||||
mock_plan_repository: MagicMock,
|
||||
mock_decision_repository: MagicMock,
|
||||
) -> PlanTreeService:
|
||||
"""Create a PlanTreeService instance."""
|
||||
return PlanTreeService(mock_plan_repository, mock_decision_repository)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_decisions() -> list[Decision]:
|
||||
"""Create sample decisions for testing."""
|
||||
now = datetime.now(datetime.UTC)
|
||||
|
||||
decisions = [
|
||||
Decision(
|
||||
decision_id="d-001",
|
||||
plan_id="plan-001",
|
||||
parent_decision_id=None,
|
||||
sequence_number=0,
|
||||
decision_type=DecisionType.PROMPT_DEFINITION,
|
||||
question="What is the task?",
|
||||
chosen_option="Analyze code",
|
||||
rationale="User requested code analysis",
|
||||
created_at=now,
|
||||
),
|
||||
Decision(
|
||||
decision_id="d-002",
|
||||
plan_id="plan-001",
|
||||
parent_decision_id="d-001",
|
||||
sequence_number=1,
|
||||
decision_type=DecisionType.STRATEGY_CHOICE,
|
||||
question="Which strategy?",
|
||||
chosen_option="Iterative",
|
||||
rationale="Iterative approach is best",
|
||||
created_at=now,
|
||||
),
|
||||
Decision(
|
||||
decision_id="d-003",
|
||||
plan_id="plan-001",
|
||||
parent_decision_id="d-002",
|
||||
sequence_number=2,
|
||||
decision_type=DecisionType.TOOL_SELECTION,
|
||||
question="Which tool?",
|
||||
chosen_option="ruff",
|
||||
rationale="ruff is fast",
|
||||
created_at=now,
|
||||
),
|
||||
Decision(
|
||||
decision_id="d-004",
|
||||
plan_id="plan-001",
|
||||
parent_decision_id="d-001",
|
||||
sequence_number=3,
|
||||
decision_type=DecisionType.BRANCH,
|
||||
question="Await confirmation?",
|
||||
chosen_option="yes",
|
||||
rationale="Need user input",
|
||||
created_at=now,
|
||||
),
|
||||
]
|
||||
|
||||
# Add status attribute for testing
|
||||
for decision in decisions:
|
||||
decision.status = "completed"
|
||||
|
||||
return decisions
|
||||
|
||||
|
||||
class TestPlanTreeService:
|
||||
"""Tests for PlanTreeService."""
|
||||
|
||||
def test_get_decision_tree_returns_none_for_nonexistent_plan(
|
||||
self,
|
||||
plan_tree_service: PlanTreeService,
|
||||
mock_plan_repository: MagicMock,
|
||||
) -> None:
|
||||
"""Test that get_decision_tree returns None for non-existent plan."""
|
||||
mock_plan_repository.get_by_id.return_value = None
|
||||
|
||||
result = plan_tree_service.get_decision_tree("plan-nonexistent")
|
||||
|
||||
assert result is None
|
||||
mock_plan_repository.get_by_id.assert_called_once_with(
|
||||
"plan-nonexistent"
|
||||
)
|
||||
|
||||
def test_get_decision_tree_returns_none_for_plan_with_no_decisions(
|
||||
self,
|
||||
plan_tree_service: PlanTreeService,
|
||||
mock_plan_repository: MagicMock,
|
||||
mock_decision_repository: MagicMock,
|
||||
) -> None:
|
||||
"""Test that get_decision_tree returns None for plan with no decisions."""
|
||||
mock_plan = MagicMock()
|
||||
mock_plan_repository.get_by_id.return_value = mock_plan
|
||||
mock_decision_repository.find_by_plan_id.return_value = []
|
||||
|
||||
result = plan_tree_service.get_decision_tree("plan-001")
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_get_decision_tree_builds_correct_tree_structure(
|
||||
self,
|
||||
plan_tree_service: PlanTreeService,
|
||||
mock_plan_repository: MagicMock,
|
||||
mock_decision_repository: MagicMock,
|
||||
sample_decisions: list[Decision],
|
||||
) -> None:
|
||||
"""Test that get_decision_tree builds correct tree structure."""
|
||||
mock_plan = MagicMock()
|
||||
mock_plan_repository.get_by_id.return_value = mock_plan
|
||||
mock_decision_repository.find_by_plan_id.return_value = sample_decisions
|
||||
|
||||
root = plan_tree_service.get_decision_tree("plan-001")
|
||||
|
||||
assert root is not None
|
||||
assert root.decision.decision_id == "d-001"
|
||||
assert len(root.children) == 2 # d-002 and d-004
|
||||
assert root.children[0].decision.decision_id == "d-002"
|
||||
assert root.children[1].decision.decision_id == "d-004"
|
||||
assert len(root.children[0].children) == 1 # d-003
|
||||
assert root.children[0].children[0].decision.decision_id == "d-003"
|
||||
|
||||
def test_get_decision_tree_respects_depth_limit(
|
||||
self,
|
||||
plan_tree_service: PlanTreeService,
|
||||
mock_plan_repository: MagicMock,
|
||||
mock_decision_repository: MagicMock,
|
||||
sample_decisions: list[Decision],
|
||||
) -> None:
|
||||
"""Test that get_decision_tree respects depth limit."""
|
||||
mock_plan = MagicMock()
|
||||
mock_plan_repository.get_by_id.return_value = mock_plan
|
||||
mock_decision_repository.find_by_plan_id.return_value = sample_decisions
|
||||
|
||||
# Depth 1: only root and immediate children
|
||||
root = plan_tree_service.get_decision_tree("plan-001", depth=1)
|
||||
|
||||
assert root is not None
|
||||
assert len(root.children) == 2
|
||||
assert len(root.children[0].children) == 0 # d-003 should not be included
|
||||
assert len(root.children[1].children) == 0
|
||||
|
||||
def test_get_tree_summary_returns_correct_statistics(
|
||||
self,
|
||||
plan_tree_service: PlanTreeService,
|
||||
mock_decision_repository: MagicMock,
|
||||
sample_decisions: list[Decision],
|
||||
) -> None:
|
||||
"""Test that get_tree_summary returns correct statistics."""
|
||||
mock_decision_repository.find_by_plan_id.return_value = sample_decisions
|
||||
|
||||
summary = plan_tree_service.get_tree_summary("plan-001")
|
||||
|
||||
assert summary["plan_id"] == "plan-001"
|
||||
assert summary["total_decisions"] == 4
|
||||
assert summary["max_depth"] == 2
|
||||
assert summary["status_counts"]["completed"] == 4
|
||||
|
||||
def test_get_tree_summary_for_empty_plan(
|
||||
self,
|
||||
plan_tree_service: PlanTreeService,
|
||||
mock_decision_repository: MagicMock,
|
||||
) -> None:
|
||||
"""Test that get_tree_summary handles empty plan."""
|
||||
mock_decision_repository.find_by_plan_id.return_value = []
|
||||
|
||||
summary = plan_tree_service.get_tree_summary("plan-empty")
|
||||
|
||||
assert summary["plan_id"] == "plan-empty"
|
||||
assert summary["total_decisions"] == 0
|
||||
assert summary["max_depth"] == 0
|
||||
|
||||
|
||||
class TestDecisionTreeNode:
|
||||
"""Tests for DecisionTreeNode."""
|
||||
|
||||
def test_to_dict_includes_all_fields(
|
||||
self, sample_decisions: list[Decision]
|
||||
) -> None:
|
||||
"""Test that to_dict includes all required fields."""
|
||||
decision = sample_decisions[0]
|
||||
node = DecisionTreeNode(decision=decision, depth=0)
|
||||
|
||||
result = node.to_dict()
|
||||
|
||||
assert result["decision_id"] == "d-001"
|
||||
assert result["plan_id"] == "plan-001"
|
||||
assert result["type"] == "prompt_definition"
|
||||
assert "timestamp" in result
|
||||
assert result["question"] == "What is the task?"
|
||||
assert result["chosen_option"] == "Analyze code"
|
||||
assert result["status"] == "completed"
|
||||
assert result["summary"] == "User requested code analysis"
|
||||
assert result["children"] == []
|
||||
|
||||
def test_to_dict_includes_children(
|
||||
self, sample_decisions: list[Decision]
|
||||
) -> None:
|
||||
"""Test that to_dict includes children."""
|
||||
parent = sample_decisions[0]
|
||||
child = sample_decisions[1]
|
||||
|
||||
parent_node = DecisionTreeNode(decision=parent, depth=0)
|
||||
child_node = DecisionTreeNode(decision=child, depth=1)
|
||||
parent_node.children.append(child_node)
|
||||
|
||||
result = parent_node.to_dict()
|
||||
|
||||
assert len(result["children"]) == 1
|
||||
assert result["children"][0]["decision_id"] == "d-002"
|
||||
@@ -23,6 +23,10 @@ nav:
|
||||
- Configuration: api/config.md
|
||||
- AI Providers: api/providers.md
|
||||
- TUI: api/tui.md
|
||||
- Decisions: api/decisions.md
|
||||
- Invariants: api/invariants.md
|
||||
- Checkpoints: api/checkpoints.md
|
||||
- Plan Corrections: api/plan-corrections.md
|
||||
- Modules:
|
||||
- Shell Safety: modules/shell-safety.md
|
||||
- UKO Provenance Tracking: modules/uko-provenance.md
|
||||
|
||||
@@ -1387,11 +1387,14 @@ class PlanLifecycleService:
|
||||
self._commit_plan(plan)
|
||||
self._logger.info("Strategize started", plan_id=plan_id)
|
||||
|
||||
# Record the root decision: prompt_definition
|
||||
# This represents the plan's prompt/description and is the
|
||||
# root of the decision tree
|
||||
self._try_record_decision(
|
||||
plan_id=plan_id,
|
||||
decision_type="strategy_choice",
|
||||
question="Which strategy should the plan follow?",
|
||||
chosen_option=f"Begin strategize phase for plan {plan_id}",
|
||||
decision_type="prompt_definition",
|
||||
question="What is the plan prompt?",
|
||||
chosen_option=plan.description or plan.action_name or plan_id,
|
||||
)
|
||||
|
||||
return plan
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
"""Service for rendering and querying the decision tree of a plan.
|
||||
|
||||
This service provides methods to retrieve and render the decision tree
|
||||
of a plan, including support for depth limiting, multiple output formats
|
||||
(rich, plain text, JSON), and error handling for non-existent plans.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from cleveragents.domain.models.core.decision import Decision
|
||||
from cleveragents.domain.repositories import (
|
||||
DecisionRepositoryProtocol,
|
||||
LifecyclePlanRepositoryProtocol,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class DecisionTreeNode:
|
||||
"""A node in the decision tree with nested children."""
|
||||
|
||||
decision: Decision
|
||||
children: list[DecisionTreeNode] = field(default_factory=list)
|
||||
depth: int = 0
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
"""Convert node to dictionary for JSON serialization."""
|
||||
return {
|
||||
"decision_id": self.decision.decision_id,
|
||||
"plan_id": self.decision.plan_id,
|
||||
"type": str(self.decision.decision_type),
|
||||
"timestamp": self.decision.created_at.isoformat(),
|
||||
"question": self.decision.question,
|
||||
"chosen_option": self.decision.chosen_option,
|
||||
"status": getattr(self.decision, "status", "completed"),
|
||||
"summary": self.decision.rationale or self.decision.chosen_option,
|
||||
"children": [child.to_dict() for child in self.children],
|
||||
}
|
||||
|
||||
|
||||
class PlanTreeService:
|
||||
"""Service for retrieving and rendering plan decision trees."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
plan_repository: LifecyclePlanRepositoryProtocol,
|
||||
decision_repository: DecisionRepositoryProtocol,
|
||||
) -> None:
|
||||
"""Initialize the service with required repositories.
|
||||
|
||||
Args:
|
||||
plan_repository: Repository for accessing plan data.
|
||||
decision_repository: Repository for accessing decision data.
|
||||
"""
|
||||
self.plan_repository = plan_repository
|
||||
self.decision_repository = decision_repository
|
||||
|
||||
def get_decision_tree(
|
||||
self, plan_id: str, depth: int | None = None
|
||||
) -> DecisionTreeNode | None:
|
||||
"""Get the decision tree for a plan.
|
||||
|
||||
Args:
|
||||
plan_id: The ULID of the plan.
|
||||
depth: Maximum depth to include in the tree (None = unlimited).
|
||||
|
||||
Returns:
|
||||
The root DecisionTreeNode of the tree, or None if plan not found.
|
||||
|
||||
Raises:
|
||||
ValueError: If plan_id is invalid.
|
||||
"""
|
||||
# Verify plan exists
|
||||
plan = self.plan_repository.get(plan_id)
|
||||
if not plan:
|
||||
return None
|
||||
|
||||
# Get all decisions for the plan
|
||||
decisions = self.decision_repository.get_by_plan(plan_id)
|
||||
if not decisions:
|
||||
return None
|
||||
|
||||
# Build a map of decision_id -> Decision for quick lookup
|
||||
decision_map: dict[str, Decision] = {d.decision_id: d for d in decisions}
|
||||
|
||||
# Find root decisions (those with no parent)
|
||||
root_decisions = [d for d in decisions if d.parent_decision_id is None]
|
||||
|
||||
if not root_decisions:
|
||||
return None
|
||||
|
||||
# Build tree from root(s)
|
||||
# Note: typically there's only one root (prompt_definition)
|
||||
root_node = self._build_tree_node(
|
||||
root_decisions[0], decision_map, depth=0, max_depth=depth
|
||||
)
|
||||
|
||||
return root_node
|
||||
|
||||
def _build_tree_node(
|
||||
self,
|
||||
decision: Decision,
|
||||
decision_map: dict[str, Decision],
|
||||
depth: int,
|
||||
max_depth: int | None,
|
||||
) -> DecisionTreeNode:
|
||||
"""Recursively build a tree node and its children.
|
||||
|
||||
Args:
|
||||
decision: The decision to create a node for.
|
||||
decision_map: Map of all decisions by ID.
|
||||
depth: Current depth in the tree.
|
||||
max_depth: Maximum depth to include (None = unlimited).
|
||||
|
||||
Returns:
|
||||
A DecisionTreeNode with children populated up to max_depth.
|
||||
"""
|
||||
node = DecisionTreeNode(decision=decision, depth=depth)
|
||||
|
||||
# Stop if we've reached max depth
|
||||
if max_depth is not None and depth >= max_depth:
|
||||
return node
|
||||
|
||||
# Find children of this decision
|
||||
children = [
|
||||
d
|
||||
for d in decision_map.values()
|
||||
if d.parent_decision_id == decision.decision_id
|
||||
]
|
||||
|
||||
# Recursively build child nodes
|
||||
for child in sorted(children, key=lambda d: d.sequence_number):
|
||||
child_node = self._build_tree_node(
|
||||
child, decision_map, depth + 1, max_depth
|
||||
)
|
||||
node.children.append(child_node)
|
||||
|
||||
return node
|
||||
|
||||
def get_tree_summary(self, plan_id: str) -> dict[str, Any]:
|
||||
"""Get summary statistics about a plan's decision tree.
|
||||
|
||||
Args:
|
||||
plan_id: The ULID of the plan.
|
||||
|
||||
Returns:
|
||||
Dictionary with summary statistics.
|
||||
"""
|
||||
decisions = self.decision_repository.get_by_plan(plan_id)
|
||||
|
||||
if not decisions:
|
||||
return {
|
||||
"plan_id": plan_id,
|
||||
"total_decisions": 0,
|
||||
"max_depth": 0,
|
||||
"status_counts": {"pending": 0, "completed": 0, "reverted": 0},
|
||||
}
|
||||
|
||||
# Count decisions by status
|
||||
status_counts = {"pending": 0, "completed": 0, "reverted": 0}
|
||||
for decision in decisions:
|
||||
status = getattr(decision, "status", "completed")
|
||||
if status in status_counts:
|
||||
status_counts[status] += 1
|
||||
|
||||
# Calculate max depth
|
||||
max_depth = self._calculate_max_depth(decisions)
|
||||
|
||||
return {
|
||||
"plan_id": plan_id,
|
||||
"total_decisions": len(decisions),
|
||||
"max_depth": max_depth,
|
||||
"status_counts": status_counts,
|
||||
}
|
||||
|
||||
def _calculate_max_depth(self, decisions: list[Decision]) -> int:
|
||||
"""Calculate the maximum depth of the decision tree.
|
||||
|
||||
Args:
|
||||
decisions: List of all decisions in the plan.
|
||||
|
||||
Returns:
|
||||
The maximum depth (0 if only root, 1 if root + children, etc.).
|
||||
"""
|
||||
if not decisions:
|
||||
return 0
|
||||
|
||||
# Build parent map
|
||||
parent_map: dict[str | None, list[str]] = {}
|
||||
for decision in decisions:
|
||||
parent_id = decision.parent_decision_id
|
||||
if parent_id not in parent_map:
|
||||
parent_map[parent_id] = []
|
||||
parent_map[parent_id].append(decision.decision_id)
|
||||
|
||||
# Find roots
|
||||
roots = parent_map.get(None, [])
|
||||
if not roots:
|
||||
return 0
|
||||
|
||||
# BFS to find max depth
|
||||
max_depth = 0
|
||||
queue = [(root_id, 0) for root_id in roots]
|
||||
|
||||
while queue:
|
||||
decision_id, current_depth = queue.pop(0)
|
||||
max_depth = max(max_depth, current_depth)
|
||||
|
||||
# Add children to queue
|
||||
children = parent_map.get(decision_id, [])
|
||||
for child_id in children:
|
||||
queue.append((child_id, current_depth + 1))
|
||||
|
||||
return max_depth
|
||||
|
||||
|
||||
__all__ = ["DecisionTreeNode", "PlanTreeService"]
|
||||
@@ -301,6 +301,7 @@ class SubplanExecutionService:
|
||||
completion_order: list[str] = []
|
||||
stop_flag = False
|
||||
timeout = self._config.timeout_per_subplan_seconds
|
||||
status_map = {status.subplan_id: status for status in statuses}
|
||||
|
||||
with ThreadPoolExecutor(max_workers=max_workers) as pool:
|
||||
future_to_id: dict[Future[tuple[SubplanStatus, dict[str, str]]], str] = {}
|
||||
@@ -315,20 +316,26 @@ class SubplanExecutionService:
|
||||
|
||||
for future in as_completed(future_to_id):
|
||||
subplan_id = future_to_id[future]
|
||||
original_status = status_map[subplan_id]
|
||||
try:
|
||||
result_status, output = future.result()
|
||||
except CancelledError:
|
||||
result_status = self._cancel_status(
|
||||
next(s for s in statuses if s.subplan_id == subplan_id)
|
||||
)
|
||||
result_status = self._cancel_status(original_status)
|
||||
output = {}
|
||||
except Exception as exc: # pragma: no cover - defensive
|
||||
result_status = self._error_status(
|
||||
next(s for s in statuses if s.subplan_id == subplan_id),
|
||||
original_status,
|
||||
str(exc),
|
||||
)
|
||||
output = {}
|
||||
|
||||
if stop_flag and result_status.status not in (
|
||||
ProcessingState.ERRORED,
|
||||
ProcessingState.CANCELLED,
|
||||
):
|
||||
result_status = self._cancel_status(original_status)
|
||||
output = {}
|
||||
|
||||
results_map[subplan_id] = (result_status, output)
|
||||
completion_order.append(subplan_id)
|
||||
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
"""Renderers for the plan decision tree in various output formats.
|
||||
|
||||
Supports Rich (colored terminal), plain text (ASCII), and JSON output formats.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import ClassVar
|
||||
|
||||
from cleveragents.application.services.plan_tree_service import DecisionTreeNode
|
||||
|
||||
|
||||
class PlanTreeRenderer:
|
||||
"""Base class for plan tree renderers."""
|
||||
|
||||
def render(self, root_node: DecisionTreeNode, plan_id: str) -> str:
|
||||
"""Render the decision tree.
|
||||
|
||||
Args:
|
||||
root_node: The root node of the decision tree.
|
||||
plan_id: The plan ID for display.
|
||||
|
||||
Returns:
|
||||
Rendered tree as a string.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class RichPlanTreeRenderer(PlanTreeRenderer):
|
||||
"""Renderer for rich terminal output with colors and formatting."""
|
||||
|
||||
# Status color codes
|
||||
STATUS_COLORS: ClassVar[dict[str, str]] = {
|
||||
"pending": "[yellow]",
|
||||
"completed": "[green]",
|
||||
"reverted": "[red]",
|
||||
}
|
||||
|
||||
STATUS_RESET: ClassVar[str] = "[/]"
|
||||
|
||||
def render(self, root_node: DecisionTreeNode, plan_id: str) -> str:
|
||||
"""Render the decision tree with rich formatting.
|
||||
|
||||
Args:
|
||||
root_node: The root node of the decision tree.
|
||||
plan_id: The plan ID for display.
|
||||
|
||||
Returns:
|
||||
Rendered tree as a rich-formatted string.
|
||||
"""
|
||||
lines = [f"Plan Decision Tree: {plan_id}"]
|
||||
self._render_node(root_node, lines, is_last=True, prefix="")
|
||||
return "\n".join(lines)
|
||||
|
||||
def _render_node(
|
||||
self,
|
||||
node: DecisionTreeNode,
|
||||
lines: list[str],
|
||||
is_last: bool,
|
||||
prefix: str,
|
||||
) -> None:
|
||||
"""Recursively render a node and its children.
|
||||
|
||||
Args:
|
||||
node: The node to render.
|
||||
lines: List to append rendered lines to.
|
||||
is_last: Whether this is the last child of its parent.
|
||||
prefix: The prefix to use for tree connectors.
|
||||
"""
|
||||
decision = node.decision
|
||||
status = getattr(decision, "status", "completed")
|
||||
|
||||
# Format status with color
|
||||
status_color = self.STATUS_COLORS.get(status, "")
|
||||
status_str = f"{status_color}[{status}]{self.STATUS_RESET}"
|
||||
|
||||
# Format timestamp
|
||||
timestamp = decision.created_at.isoformat()
|
||||
|
||||
# Format summary (use rationale if available, otherwise chosen option)
|
||||
summary = decision.rationale or decision.chosen_option
|
||||
|
||||
# Build the line
|
||||
connector = "└── " if is_last else "├── "
|
||||
line = (
|
||||
f"{prefix}{connector}{status_str} {decision.decision_id} | "
|
||||
f"{decision.decision_type!s:20} | {timestamp} | {summary}"
|
||||
)
|
||||
lines.append(line)
|
||||
|
||||
# Render children
|
||||
if node.children:
|
||||
extension = " " if is_last else "│ "
|
||||
for i, child in enumerate(node.children):
|
||||
is_last_child = i == len(node.children) - 1
|
||||
self._render_node(
|
||||
child, lines, is_last_child, prefix + extension
|
||||
)
|
||||
|
||||
|
||||
class PlainPlanTreeRenderer(PlanTreeRenderer):
|
||||
"""Renderer for plain text output with ASCII tree connectors."""
|
||||
|
||||
def render(self, root_node: DecisionTreeNode, plan_id: str) -> str:
|
||||
"""Render the decision tree with ASCII formatting.
|
||||
|
||||
Args:
|
||||
root_node: The root node of the decision tree.
|
||||
plan_id: The plan ID for display.
|
||||
|
||||
Returns:
|
||||
Rendered tree as a plain text string.
|
||||
"""
|
||||
lines = [f"Plan Decision Tree: {plan_id}"]
|
||||
self._render_node(root_node, lines, is_last=True, prefix="")
|
||||
return "\n".join(lines)
|
||||
|
||||
def _render_node(
|
||||
self,
|
||||
node: DecisionTreeNode,
|
||||
lines: list[str],
|
||||
is_last: bool,
|
||||
prefix: str,
|
||||
) -> None:
|
||||
"""Recursively render a node and its children.
|
||||
|
||||
Args:
|
||||
node: The node to render.
|
||||
lines: List to append rendered lines to.
|
||||
is_last: Whether this is the last child of its parent.
|
||||
prefix: The prefix to use for tree connectors.
|
||||
"""
|
||||
decision = node.decision
|
||||
status = getattr(decision, "status", "completed")
|
||||
|
||||
# Format timestamp
|
||||
timestamp = decision.created_at.isoformat()
|
||||
|
||||
# Format summary
|
||||
summary = decision.rationale or decision.chosen_option
|
||||
|
||||
# Build the line with ASCII connectors
|
||||
connector = "`-- " if is_last else "|-- "
|
||||
line = (
|
||||
f"{prefix}{connector}[{status:10}] {decision.decision_id} | "
|
||||
f"{decision.decision_type!s:20} | {timestamp} | {summary}"
|
||||
)
|
||||
lines.append(line)
|
||||
|
||||
# Render children
|
||||
if node.children:
|
||||
extension = " " if is_last else "| "
|
||||
for i, child in enumerate(node.children):
|
||||
is_last_child = i == len(node.children) - 1
|
||||
self._render_node(
|
||||
child, lines, is_last_child, prefix + extension
|
||||
)
|
||||
|
||||
|
||||
class JsonPlanTreeRenderer(PlanTreeRenderer):
|
||||
"""Renderer for JSON output."""
|
||||
|
||||
def render(self, root_node: DecisionTreeNode, plan_id: str) -> str:
|
||||
"""Render the decision tree as JSON.
|
||||
|
||||
Args:
|
||||
root_node: The root node of the decision tree.
|
||||
plan_id: The plan ID for display.
|
||||
|
||||
Returns:
|
||||
Rendered tree as a JSON string.
|
||||
"""
|
||||
tree_dict = {
|
||||
"plan_id": plan_id,
|
||||
"root": root_node.to_dict(),
|
||||
}
|
||||
return json.dumps(tree_dict, indent=2)
|
||||
|
||||
|
||||
def get_renderer(format_type: str) -> PlanTreeRenderer:
|
||||
"""Get a renderer for the specified format.
|
||||
|
||||
Args:
|
||||
format_type: The format type ('rich', 'plain', or 'json').
|
||||
|
||||
Returns:
|
||||
A PlanTreeRenderer instance.
|
||||
|
||||
Raises:
|
||||
ValueError: If format_type is not recognized.
|
||||
"""
|
||||
renderers = {
|
||||
"rich": RichPlanTreeRenderer,
|
||||
"plain": PlainPlanTreeRenderer,
|
||||
"json": JsonPlanTreeRenderer,
|
||||
}
|
||||
|
||||
if format_type not in renderers:
|
||||
raise ValueError(
|
||||
f"Unknown format: {format_type}. "
|
||||
f"Supported formats: {', '.join(renderers.keys())}"
|
||||
)
|
||||
|
||||
return renderers[format_type]()
|
||||
|
||||
|
||||
__all__ = [
|
||||
"JsonPlanTreeRenderer",
|
||||
"PlainPlanTreeRenderer",
|
||||
"PlanTreeRenderer",
|
||||
"RichPlanTreeRenderer",
|
||||
"get_renderer",
|
||||
]
|
||||
Reference in New Issue
Block a user