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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- run: python -m pip install --upgrade pip
- run: python -m pip install -c requirements-dev.lock -e ".[dev]"
- run: ruff check .
- run: mypy src tests
- run: mypy src tests scripts
- run: coverage run -m pytest
- run: coverage report --fail-under=90
- run: python -m build
Expand Down Expand Up @@ -91,12 +91,17 @@ jobs:
with:
python-version: "3.13"
- run: python -m pip install -c requirements-dev.lock -e ".[dev]"
- name: Run real-agent regression corpus
- name: Run scripted agent workflow regression corpus
run: >-
ai-dev benchmark corpus
--manifest examples/benchmarks/agent-corpus.json
--trials 3
--timeout 60
- name: Verify a primed repository workflow
run: >-
ai-dev benchmark run
--suite examples/benchmarks/repository-small.json
--variant ai-dev --cache-state warm --trials 1 --timeout 120
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
Expand Down
12 changes: 8 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ cross-platform behavior are covered where applicable.

## Active work

There are no known incomplete P1 or P2 implementation items for the 1.0-1.2 contracts. The planned
product capability set is complete. New work is maintenance and must be justified by a supported
platform change, security issue, dependency update, reproducible regression, or backward-compatible
integration requirement.
The [development tracker](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/144) links to
current acceptance criteria. The roadmap documents the capabilities shipped in the 1.x contracts.

| Priority | Issues |
| --- | --- |
| P0 | [MCP metadata #131](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/131), [correctness gate #134](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/134), [agent measurement #133](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/133), [managed stop race #146](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/146) |
| P1 | [Node diagnostics #128](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/128), [repository navigation #136](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/136), [MCP symbol lookup #137](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/137), [module responsibilities #135](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/135), [adoption #138](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/138), [failure loops #139](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/139), [affected tests #140](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/140) |
| P2 | [Verified repository knowledge #141](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/141), [FTS5 evaluation #142](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/142), [native profiling #143](https://github.com/MatthiasLew/ai-dev-cli-tools/issues/143) |

## Deferred or explicitly out of scope

Expand Down
56 changes: 49 additions & 7 deletions docs/BENCHMARKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ ai-dev benchmark gate <baseline.json> <candidate.json> --require-reported-tokens
The corpus includes a repeated MCP `build_context` task that compares a forced full refresh with
an explicitly acknowledged unchanged receipt. Both variants must retain the same outcome,
precision, and recall while the receipt satisfies the configured token-reduction threshold.
The context acknowledgement, adaptive selection and feedback delta suites store their trial
evidence for a separate validator. Their fixture version is 2 to reflect the stricter oracles.

Cold and warm results are deliberately separate and cannot be compared with each other. A
comparison is valid only when the suite name, fixture version, cache state, and validated outcome
signatures match and every trial succeeds.
Cold and warm results are compared within the same cache state. Give a suite an optional
`warmup_command` array to prime the cache after each reset and before each measured warm trial.
The warmup must succeed. Its time is recorded separately. Existing suites without a warmup
report `cache_preparation: reset_only`; use their reset semantics when interpreting the label.
A comparison requires the same suite, fixture version, cache preparation, and outcome signatures.

Each run records median end-to-end time, time to an actionable result, standard deviation,
Each run records median and nearest-rank p95 for end-to-end and measured execution time,
time to an actionable result, standard deviation,
commands, validation subprocesses, masked agent-visible bytes, estimated tokens, timeouts,
correctness, fixture identity, and a local machine profile. Token estimates use
masked_utf8_bytes_divided_by_4; they are a stable approximation, not a model tokenizer claim.
Expand All @@ -57,7 +62,7 @@ Raw JSON and compact Markdown reports stay under `.ai/benchmarks/`.
bounds, required token reduction is not achieved, precision/recall fall below their floors, or false negatives exceed the allowance. Use
`--min-token-reduction PERCENT` to require a measured improvement rather than merely permitting no
regression. The
versioned corpus runs six representative agent tasks, including adaptive-off versus adaptive-on
versioned corpus runs seven scripted agent tasks, including adaptive-off versus adaptive-on
context selection and full versus session-delta feedback, and applies the shared thresholds from
`examples/benchmarks/agent-corpus.json`; it is suitable as a CI release gate.

Expand All @@ -74,8 +79,9 @@ recall were not reported; their zero medians must not be interpreted as measured

Use `--client codex|claude|cursor|gemini|generic` to label runs from a real client adapter. A real adapter
should emit `input_tokens` or `output_tokens` in its private metrics line. The
`--require-reported-tokens` gate fails unless every candidate trial contains provider-reported
usage; this prevents estimated character counts from being presented as real client token data.
`--require-reported-tokens` gate requires provider-reported usage in every trial of both variants.
Use the same instrumentation in both variants. The gate checks input and output token medians
separately from the estimate gate.

Every comparison and gate is advisory and requires human approval. A passing candidate that is
both faster and smaller returns `adopt_candidate`; a passing tradeoff returns `keep_baseline`; any
Expand Down Expand Up @@ -130,3 +136,39 @@ ai-dev benchmark run --suite examples/benchmarks/agent-repair-workflow.json --va
ai-dev benchmark run --suite examples/benchmarks/agent-repair-workflow.json --variant ai-dev --trials 3 --cache-state cold
ai-dev benchmark compare .ai/benchmarks/runs/<baseline>.json .ai/benchmarks/runs/<candidate>.json
~~~

## Repository and real-agent trials

`repository-small.json` and `repository-monorepo.json` use generated Git fixtures. The larger
fixture has 40 Python workspaces and 1,000 workload modules. Each trial measures CLI startup,
scan, index and semantic index, a repeated index invocation, Git inspection after editing a file,
symbol lookup, context building, affected-test planning, and MCP startup plus `project_status`.
The validator independently checks fixture coverage, the edited file hash, old/new symbols,
cache reuse, the expected test selection, and the MCP result. Baseline forces repository index
rebuilds, while the candidate updates incrementally. The optional warmup builds both indexes.

Run both variants for each cache state and size, serially in a given checkout. Use 20 or more
trials for tail analysis. A nearest-rank p95 from three trials is the maximum of those three.

~~~bash
ai-dev benchmark run --suite examples/benchmarks/repository-small.json --variant baseline --cache-state cold --trials 3 --timeout 120
ai-dev benchmark run --suite examples/benchmarks/repository-small.json --variant ai-dev --cache-state cold --trials 3 --timeout 120
ai-dev benchmark compare <baseline-run.json> <ai-dev-run.json>
ai-dev benchmark gate <baseline-run.json> <ai-dev-run.json>
~~~

`real-agent-repair.json` runs a disposable synthetic repair through a locally configured agent
driver. Set `AI_DEV_BENCHMARK_AGENT_CONFIG` to an absolute JSON file with `baseline` and `ai-dev`
argument arrays for that driver. The process starts in the disposable fixture and receives
`AI_DEV_BENCHMARK_PROMPT` and `AI_DEV_BENCHMARK_VARIANT`. Keep the same prompt, model version,
permissions and instrumentation on both sides. Enable ai-dev only for the candidate. Configure
the requested client and any provider access outside the harness. The separate validator checks
the edited function with held-out pricing and normalization cases.

Run both variants with `--client <client> --cache-state cold` and pass the resulting reports to
`benchmark gate --require-reported-tokens`. The driver should record per-tool elapsed time and
source reads from local client events in its own sanitized trial log, and emit counts and actual
provider input/output usage through `AI_DEV_BENCHMARK_METRICS`. Derive selection metrics from
fixture ground truth. Keep missing measurements unavailable and record pricing version, cached
input and provider-specific usage separately if calculating cost. The supplied real-agent fixture
resets to a cold local state. A real-agent warm protocol and matched cost study are tracked in #133.
4 changes: 4 additions & 0 deletions docs/MCP_SERVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ than running it as an unsupervised background daemon.

## Compatibility and testing

`tools/call` accepts the optional MCP `params._meta` object. The server validates the shape of
the optional `progressToken` and accepts extension metadata. Tool handlers receive only the
validated `params.arguments`. The server does not send progress notifications.

The source test suite verifies initialization, tool discovery, notifications, parse errors,
strict arguments, preview defaults, read-only status behavior, concise structured results, CLI
wiring, and installed-wheel initialization. MCP tool names and required input fields should
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmarks/agent-adaptive-context.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schema_version": "1.0",
"name": "agent-adaptive-context",
"fixture_version": "1",
"fixture_version": "2",
"working_directory": "examples/benchmarks/fixtures/agent-workflow",
"reset_command": [
"python",
Expand Down
6 changes: 3 additions & 3 deletions examples/benchmarks/agent-context-acknowledgement.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"schema_version": "1.0",
"name": "agent-context-acknowledgement",
"fixture_version": "1",
"fixture_version": "2",
"working_directory": ".",
"reset_command": ["python", "-c", "pass"],
"validation_command": ["python", "-c", "print('unchanged-context-confirmed')"],
"reset_command": ["python", "scripts/benchmark_mcp_context_ack.py", "reset"],
"validation_command": ["python", "scripts/benchmark_mcp_context_ack.py", "validate"],
"variants": {
"baseline": ["python", "scripts/benchmark_mcp_context_ack.py", "baseline"],
"ai-dev": ["python", "scripts/benchmark_mcp_context_ack.py", "ai-dev"]
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmarks/agent-feedback-delta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schema_version": "1.0",
"name": "agent-feedback-delta",
"fixture_version": "1",
"fixture_version": "2",
"working_directory": "examples/benchmarks/fixtures/agent-workflow",
"reset_command": [
"python",
Expand Down
28 changes: 28 additions & 0 deletions examples/benchmarks/real-agent-repair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"schema_version": "1.0",
"name": "real-agent-repair",
"fixture_version": "1",
"working_directory": ".",
"reset_command": [
"python",
"scripts/benchmark_real_agent.py",
"reset"
],
"validation_command": [
"python",
"scripts/benchmark_real_agent.py",
"validate"
],
"variants": {
"baseline": [
"python",
"scripts/benchmark_real_agent.py",
"baseline"
],
"ai-dev": [
"python",
"scripts/benchmark_real_agent.py",
"ai-dev"
]
}
}
38 changes: 38 additions & 0 deletions examples/benchmarks/repository-monorepo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"schema_version": "1.0",
"name": "repository-monorepo",
"fixture_version": "1",
"working_directory": ".",
"reset_command": [
"python",
"scripts/benchmark_repository.py",
"monorepo",
"reset"
],
"warmup_command": [
"python",
"scripts/benchmark_repository.py",
"monorepo",
"warmup"
],
"validation_command": [
"python",
"scripts/benchmark_repository.py",
"monorepo",
"validate"
],
"variants": {
"baseline": [
"python",
"scripts/benchmark_repository.py",
"monorepo",
"baseline"
],
"ai-dev": [
"python",
"scripts/benchmark_repository.py",
"monorepo",
"ai-dev"
]
}
}
38 changes: 38 additions & 0 deletions examples/benchmarks/repository-small.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"schema_version": "1.0",
"name": "repository-small",
"fixture_version": "1",
"working_directory": ".",
"reset_command": [
"python",
"scripts/benchmark_repository.py",
"small",
"reset"
],
"warmup_command": [
"python",
"scripts/benchmark_repository.py",
"small",
"warmup"
],
"validation_command": [
"python",
"scripts/benchmark_repository.py",
"small",
"validate"
],
"variants": {
"baseline": [
"python",
"scripts/benchmark_repository.py",
"small",
"baseline"
],
"ai-dev": [
"python",
"scripts/benchmark_repository.py",
"small",
"ai-dev"
]
}
}
55 changes: 47 additions & 8 deletions scripts/benchmark_agent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ROOT = Path(__file__).resolve().parents[1]
FIXTURE = ROOT / "examples" / "benchmarks" / "fixtures" / "agent-workflow"
ADAPTIVE_FIXTURE = FIXTURE / ".ai" / "adaptive-context"
TRIAL_EVIDENCE = FIXTURE / ".ai" / "benchmark-evidence.json"
PRICING = FIXTURE / "src" / "pricing.py"
FIXED = "return subtotal + tax"
BROKEN = "return subtotal - tax"
Expand Down Expand Up @@ -246,6 +247,7 @@ def _adaptive(variant: str, started: float) -> int:
visible = json.dumps(report.summary, separators=(",", ":"))
selected = _selected_paths(report.summary)
actionable = time.monotonic() - started
_write_evidence("adaptive", variant, report.summary)
print(visible)
_metrics(
commands=3,
Expand All @@ -268,6 +270,7 @@ def _feedback_delta(variant: str, started: float) -> int:
)
visible = json.dumps(summary, separators=(",", ":"))
actionable = time.monotonic() - started
_write_evidence("feedback-delta", variant, summary)
print(visible)
_metrics(
commands=1,
Expand All @@ -280,14 +283,7 @@ def _feedback_delta(variant: str, started: float) -> int:

def _validate(scenario: str) -> int:
if scenario in {"adaptive", "feedback-delta"}:
if scenario == "feedback-delta":
print("verified:feedback-delta:semantic-state-preserved")
return 0
if not ADAPTIVE_FIXTURE.is_dir():
print("adaptive context fixture was not created", file=sys.stderr)
return 1
print("verified:adaptive:complete-selection")
return 0
return _validate_evidence(scenario)
if scenario == "repair" and BROKEN in PRICING.read_text(encoding="utf-8"):
print("repair was not applied", file=sys.stderr)
return 1
Expand All @@ -300,6 +296,49 @@ def _validate(scenario: str) -> int:
return 0


def _write_evidence(scenario: str, variant: str, summary: dict[str, object]) -> None:
TRIAL_EVIDENCE.parent.mkdir(parents=True, exist_ok=True)
TRIAL_EVIDENCE.write_text(
json.dumps({"scenario": scenario, "variant": variant, "summary": summary}), encoding="utf-8"
)


def _validate_evidence(scenario: str) -> int:
if not TRIAL_EVIDENCE.is_file():
print(f"Missing benchmark evidence for {scenario}.", file=sys.stderr)
return 1
evidence = json.loads(TRIAL_EVIDENCE.read_text(encoding="utf-8"))
assert evidence["scenario"] == scenario
summary = evidence["summary"]
adaptive_variant = evidence["variant"] == "ai-dev"
if scenario == "adaptive":
expected = {f"module-{index}.md": f"# Public module {index}" for index in range(1, 5)}
selected = {row["path"]: row["content"] for row in summary["selected_files"]}
assert selected.keys() == expected.keys()
assert all(selected[path].startswith(heading) for path, heading in expected.items())
assert summary["adaptive_context"]["enabled"] is adaptive_variant
else:
validation = summary["validation"]
context = summary["context"]
assert summary["decision"]["ready"] is True
assert summary["changes"]["files"] == ["src/app.py"]
assert validation["status"] == context["status"] == "success"
assert validation["checks_total"] == 24 and validation["checks_failed"] == 0
assert context["incremental"]["context_id"] == "stable-context"
assert summary["delta"]["state_fingerprint"] == "stable-state"
assert summary["delta"]["reused"] is adaptive_variant
if adaptive_variant:
assert validation["result_count"] == 24
assert context["selected_file_count"] == 1
assert summary["observations"]["current_evidence_id"] == "observation:stable"
else:
assert len(validation["results"]) == 24
assert [row["path"] for row in context["selected_files"]] == ["src/app.py"]
assert summary["observations"]["current"]["evidence_id"] == "observation:stable"
print(f"Verified {scenario} fixture outcome")
return 0


def _pytest(tests: list[str]) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[
Expand Down
Loading
Loading