Loveca db02b77837
feat(plugins): add evidence-gated skill self-evolution example (#7984)
* feat(plugins): add evidence-gated skill self-evolution example

Demonstrates the #7884 roadmap deliverable: a proposed change, the regression
case it fixes, the old and new results, and a rollback to a known-good version,
driven only through the public SkillMutationService contract merged in #5645.

The example stages a candidate against a sealed completed-run evidence anchor,
evaluates recorded JSON regression cases against both frozen bundles with a
deterministic static evaluator (never executing package content), and commits
only a "justified" verdict with an AssessmentRef binding the report to the
exact candidate hash and base revision. Unjustified or failed proposals are
discarded; revert stays append-only. Ships an HTTP walkthrough surface, an
offline lifecycle test against a contract-faithful fake host, and a README
section proposing a concrete evidence standard for the automatic-publication
discussion.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(skill-evolution): resolve request models and honor APPLIED publication

The walkthrough routes had never been exercised through FastAPI. With
`from __future__ import annotations`, request models defined inside
`build_router` are unresolvable forward references, so FastAPI read `body`
as a query parameter and every POST answered 422. Move the models to module
scope and cover the routes through TestClient.

A committed operation reports `publication == "APPLIED"`; `READY` is a
`views` state. The committed check listed READY, so a successful apply never
flipped `record.committed` and the ALREADY_COMMITTED guard never fired. Fix
the check, mirror the real literals in the lifecycle fake host, and assert
both the flag and the second-apply refusal.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(skill-evolution): address review feedback and register the example catalog

- Bind walkthrough routes to the authenticated principal: owner checks on propose/apply/revert, owner-scoped listing, and non-disclosing 404s.
- Map unknown skills, proposals and operations to 404 for both NOT_FOUND and the real host's NOT_FOUND_OR_FORBIDDEN; map broken case files to 400.
- Ignore URL paths and trim sentence punctuation when extracting in-package references.
- Validate config.enabled's type instead of treating any non-False value as on.
- Soften the README claim about report persistence and add CHANGELOG entries.
- Register the example in the frontend extension catalog, fixing frontend-unit-tests.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(skill-evolution): narrow case-file error mapping and cover run visibility

- Label ValueError as CASE_INVALID only on POST /proposals, the route that actually loads case files; apply and revert now surface host bugs as 500 instead of pointing at the case directory.
- Cover the request-scoped run-evidence reader the real Gateway installs: hidden anchor returns 403 SOURCE_NOT_VISIBLE before the host is touched, a denied resolver returns 403, and a visible anchor still proceeds.
- Add regressions pinning host ValueError on apply/revert to 500.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* docs(changelog): drop contributor changelog entry per policy

Contributor PRs no longer modify CHANGELOG.md or CHANGELOG_zh.md (#8202);
maintainers add the entry at merge time.

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Nan Gao <thunderggnn@gmail.com>
2026-11-16 16:04:42 +08:00

45 lines
1.6 KiB
Python

"""Evidence-gated skill self-evolution example.
Demonstrates the roadmap deliverable: a proposed change, the regression case it
fixes, the old and new results, and a rollback to a known-good version — all
through the host ``SkillMutationService`` contract merged in #5645.
Install via ``config.yaml -> plugins:`` with a ``host_access.skill_mutations``
grant (see README.md). Without the grant the service fails to start and the
Gateway reports a diagnostic; nothing else changes.
"""
from __future__ import annotations
from collections.abc import Mapping
from pathlib import Path
from typing import Any
from deerflow_extension_api import ExtensionInstall, ExtensionRegistry, extension
from deerflow_extension_skill_evolution.service import EvolutionService, build_router
__all__ = ["install"]
_DEFAULT_CASES_DIR = Path(__file__).resolve().parent / "cases"
@extension(api="0.2.11", name="skill-evolution")
def install(registry: ExtensionRegistry, config: Mapping[str, Any]) -> None:
"""Register the evolution service and its HTTP walkthrough surface."""
# ``is False`` alone would silently keep the plugin on for ``enabled: 0`` or
# ``enabled: "false"``; a mistyped off switch must fail the deployment.
enabled = config.get("enabled", True)
if type(enabled) is not bool:
raise ValueError(f"skill-evolution: config.enabled must be a boolean, got {enabled!r}")
if not enabled:
return
cases_dir = config.get("cases_dir")
service = EvolutionService(cases_dir=Path(cases_dir) if cases_dir else _DEFAULT_CASES_DIR)
registry.service(service)
registry.routers((build_router(service),))
_entry_point: ExtensionInstall = install