Skip to content

Define rename-symbol contract and expand capability framework#67

Merged
leynos merged 12 commits intomainfrom
define-rename-symbol-contract-gy9w4v
Mar 5, 2026
Merged

Define rename-symbol contract and expand capability framework#67
leynos merged 12 commits intomainfrom
define-rename-symbol-contract-gy9w4v

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Feb 28, 2026

Summary

Introduce a formal capability contract system for plugin capabilities (starting with rename-symbol) and expand the plugin ecosystem to support capability declarations, contract validation, and capability-based discovery. This includes a new capability module, typed request validation, stable reason codes, and registry lookups, along with tests and documentation updates.

Changes

  • Add capability contract framework
    • New module: crates/weaver-plugins/src/capability/mod.rs
      • CapabilityId enum (RenameSymbol, ExtricateSymbol, ExtractMethod, ReplaceBody, ExtractPredicate)
      • ContractVersion struct with major/minor and compatibility checks
      • CapabilityContract trait for request/response validation
      • Re-exports for consumer crates
    • New module: crates/weaver-plugins/src/capability/reason_code.rs
      • ReasonCode enum with stable snake_case strings and serde support
    • New module: crates/weaver-plugins/src/capability/rename_symbol.rs
      • RENAME_SYMBOL_CONTRACT_VERSION constant (1.0)
      • RenameSymbolRequest with typed fields and extraction/validation from PluginRequest
      • RenameSymbolContract implementing CapabilityContract with validation rules
      • Helpers for validating successful diff output in responses
    • New tests: crates/weaver-plugins/src/capability/tests.rs
      • Serde round-trips, contract validation, version compatibility, reason codes
  • Extend core protocol/types
    • crates/weaver-plugins/src/protocol/mod.rs
      • Add optional reason_code: ReasonCode to PluginDiagnostic with serde defaults
      • Builder-style with_reason_code(code) and accessor reason_code()
  • Extend manifest handling
    • crates/weaver-plugins/src/manifest/mod.rs
      • Add capabilities: Vec field with serde(default)
      • with_capabilities(...) builder, capabilities() accessor
      • Sensor vs actuator guard: sensors must not declare actuator capabilities
  • Extend registry lookups
    • crates/weaver-plugins/src/registry/mod.rs
      • find_for_capability(id: CapabilityId) -> Vec<&PluginManifest>
      • find_for_language_and_capability(language: &str, id: CapabilityId) -> Vec<&PluginManifest>
  • Wiring and public API surface
    • crates/weaver-plugins/src/lib.rs
      • pub mod capability;
    • Re-export capability types for easier downstream use
  • Tests and behaviour-driven tests
    • Unit tests for capability contract and naming in crates/weaver-plugins/src/capability/tests.rs
    • Capability-based lookup tests in crates/weaver-plugins/src/registry/tests.rs
    • Behaviour tests scaffold: crates/weaver-plugins/src/tests/capability_behaviour.rs
    • BDD feature: crates/weaver-plugins/tests/features/capability_contract.feature
    • BDD step definitions: crates/weaver-plugins/src/tests/capability_behaviour.rs
  • Documentation and docs updates
    • docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md (new)
    • docs/users-guide.md: section detailing plugin capabilities, rename-symbol contract, reason codes, and manifest example
    • docs/roadmap.md: mark 5.2.1 as completed
  • Execution plan and examples
    • New capability-focused capability_contract feature scenarios to exercise contract validation, refusals, and manifest capabilities

Rationale

  • Provides a robust, versioned contract system for capabilities (starting with rename-symbol) to enable safe broker-plugin interaction.
  • Introduces stable, programmatic diagnostics via ReasonCode to support automation and tooling.
  • Enables capability-based routing and discovery via manifest capabilities and registry lookups.
  • Ensures backwards compatibility by using serde(default) for new fields and by validating only supported shapes in contracts.

Compatibility and Migration

  • Backwards compatible: new fields are optional/defaulted so existing manifests and diagnostics deserialize without changes.
  • Manifest validation enforces that sensor plugins do not declare actuator capabilities, preserving existing semantics.
  • No breaking changes to existing public API beyond the addition of new capabilities and fields; existing code should continue to function.

Testing plan

  • Unit tests covering: capability IDs, contract versioning, request/response validation, and reason-code serialization.
  • Registry tests for capability-based lookups and language capability intersections.
  • Behaviour-driven tests (BDD) for end-to-end contract validation, refusals with reason codes, and manifest capability handling.
  • All tests should pass with cargo test; lint/check-fmt should remain green.

Documentation and users' guide updates

  • Document the capability model, the five first-party capabilities, and the rename-symbol contract in the users guide.
  • Provide examples of manifest capability declarations and how reason codes appear in diagnostics.
  • Update roadmap to reflect completion of 5.2.1 and related notes.

Review tips

  • Focus on the contract implementation, especially validate_request and validate_response paths for rename-symbol.
  • Verify compatibility rules in ContractVersion and how is_compatible_with is used by the broker.
  • Check that manifest/sensor validation logic correctly rejects sensor plugins with actuator capabilities.
  • Validate new registry lookups behave as expected for capability-based discovery and language filtering.

If you want me to tweak the PR message (tone, depth, or section order), tell me your preferences and I’ll adjust accordingly.

📎 Task: https://www.devboxer.com/task/6720b407-5feb-4589-8ee8-2a3572c2ae4a

Summary by Sourcery

Introduce a versioned capability contract system (starting with rename-symbol) for actuator plugins, including manifest capability declarations, capability-based registry lookup, structured refusal reason codes on diagnostics, and corresponding tests and documentation updates.

New Features:

  • Add a capability module with identifiers, contract versioning, a rename-symbol capability contract, and stable refusal reason codes.
  • Allow plugin manifests to declare supported capabilities and expose them via builder and accessor methods.
  • Extend the plugin registry with capability and language-aware lookup functions.
  • Support optional reason_code fields on plugin diagnostics for programmatic error handling.
  • Add behaviour-driven tests and feature scenarios for capability contracts and validation flows.

Enhancements:

  • Document plugin capabilities, the rename-symbol contract, and reason codes in the user guide and execution plan docs, and mark the related roadmap item as complete.

Tests:

  • Add unit tests for capability identifiers, contract versioning, rename-symbol request/response validation, reason codes, manifest validation, registry capability lookups, and diagnostic reason_code behaviour.
  • Add BDD feature files and step definitions exercising capability contract validation, refusal handling, manifest capability rules, and version compatibility.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Feb 28, 2026

Reviewer's Guide

Introduces a capability contract subsystem centred on the rename-symbol capability, adds stable reason codes, wires capabilities into manifests and the registry, and exposes these types through the weaver-plugins public API along with unit/BDD tests and documentation updates.

Sequence diagram for rename-symbol request validation and plugin routing

sequenceDiagram
    actor User
    participant Daemon
    participant PluginRegistry
    participant RenameSymbolContract
    participant Plugin

    User->>Daemon: Request rename-symbol(uri, position, new_name)
    Daemon->>Daemon: Build PluginRequest(operation="rename-symbol")
    Daemon->>RenameSymbolContract: validate_request(PluginRequest)
    RenameSymbolContract-->>Daemon: Result Ok or PluginError
    alt request invalid
        Daemon-->>User: Error (validation failed)
    else request valid
        Daemon->>PluginRegistry: find_for_language_and_capability(language, CapabilityId::RenameSymbol)
        PluginRegistry-->>Daemon: Vec<PluginManifest>
        Daemon->>Plugin: Invoke with PluginRequest
        Plugin-->>Daemon: PluginResponse
        Daemon->>RenameSymbolContract: validate_response(PluginResponse)
        RenameSymbolContract-->>Daemon: Result Ok or PluginError
        alt response invalid
            Daemon-->>User: Error (contract violation)
        else response valid
            alt PluginResponse.success == true
                Daemon-->>User: Apply Diff output
            else PluginResponse.success == false
                Daemon->>Daemon: Inspect diagnostics and reason_code
                Daemon-->>User: Report failure with reason_code
            end
        end
    end
Loading

Class diagram for capability contracts, manifests, registry, and diagnostics

classDiagram
    direction LR

    class CapabilityId {
      <<enum>>
      +RenameSymbol
      +ExtricateSymbol
      +ExtractMethod
      +ReplaceBody
      +ExtractPredicate
      +as_str() String
    }

    class ContractVersion {
      +u16 major
      +u16 minor
      +new(major u16, minor u16) ContractVersion
      +major() u16
      +minor() u16
      +is_compatible_with(other ContractVersion) bool
    }

    class CapabilityContract {
      <<interface>>
      +capability_id() CapabilityId
      +version() ContractVersion
      +validate_request(request PluginRequest) Result~(), PluginError~
      +validate_response(response PluginResponse) Result~(), PluginError~
    }

    class RenameSymbolRequest {
      -String uri
      -String position
      -String new_name
      +new(uri String, position String, new_name String) RenameSymbolRequest
      +uri() String
      +position() String
      +new_name() String
      +extract(request PluginRequest) Result~RenameSymbolRequest, PluginError~
    }

    class RenameSymbolContract {
      +capability_id() CapabilityId
      +version() ContractVersion
      +validate_request(request PluginRequest) Result~(), PluginError~
      +validate_response(response PluginResponse) Result~(), PluginError~
    }

    class ReasonCode {
      <<enum>>
      +SymbolNotFound
      +MacroGenerated
      +AmbiguousReferences
      +UnsupportedLanguage
      +IncompletePayload
      +NameConflict
      +OperationNotSupported
      +as_str() String
    }

    class PluginManifest {
      -String name
      -String version
      -PluginKind kind
      -Vec~String~ languages
      -String executable
      -Vec~String~ args
      -u64 timeout_secs
      -Vec~CapabilityId~ capabilities
      +new(name String, version String, kind PluginKind, languages Vec~String~, executable String) PluginManifest
      +with_capabilities(capabilities Vec~CapabilityId~) PluginManifest
      +validate() Result~(), PluginError~
      +capabilities() Vec~CapabilityId~
    }

    class PluginDiagnostic {
      -Severity severity
      -String message
      -Option~PathBuf~ file
      -Option~u32~ line
      -Option~ReasonCode~ reason_code
      +new(severity Severity, message String) PluginDiagnostic
      +message() String
      +with_reason_code(code ReasonCode) PluginDiagnostic
      +reason_code() Option~ReasonCode~
    }

    class PluginRegistry {
      -manifests Map~String, PluginManifest~
      +register(manifest PluginManifest) Result~(), PluginError~
      +find_for_capability(id CapabilityId) Vec~PluginManifest~
      +find_for_language_and_capability(language String, id CapabilityId) Vec~PluginManifest~
    }

    class PluginRequest {
      -String operation
      -Map~String, Value~ arguments
      +arguments() Map~String, Value~
    }

    class PluginResponse {
      -bool success
      -PluginOutput output
      -Vec~PluginDiagnostic~ diagnostics
      +is_success() bool
      +output() PluginOutput
      +diagnostics() Vec~PluginDiagnostic~
    }

    class PluginOutput {
      <<enum>>
      +Diff
      +Analysis
      +Empty
    }

    CapabilityContract <|.. RenameSymbolContract
    RenameSymbolContract ..> RenameSymbolRequest : uses for validation
    PluginManifest "*" --> "*" CapabilityId : declares
    PluginDiagnostic --> ReasonCode : optional
    PluginRegistry "1" --> "*" PluginManifest : stores
    CapabilityContract ..> PluginRequest : validates
    CapabilityContract ..> PluginResponse : validates
    PluginResponse --> PluginOutput
    PluginResponse --> PluginDiagnostic
Loading

File-Level Changes

Change Details Files
Add capability contract infrastructure with versioning and a concrete rename-symbol contract.
  • Introduce CapabilityId enum with five first-party capabilities and kebab-case serde representation.
  • Define ContractVersion struct with major/minor, Display, serde, and compatibility check via is_compatible_with.
  • Define CapabilityContract trait that validates PluginRequest/PluginResponse pairs per capability.
  • Implement RenameSymbolRequest typed request extractor from PluginRequest::arguments with strict string/non-empty validation.
  • Implement RenameSymbolContract using RENAME_SYMBOL_CONTRACT_VERSION and enforcing diff output on successful responses.
  • Introduce ReasonCode enum with snake_case serde and helpers, used as stable refusal identifiers.
crates/weaver-plugins/src/capability/mod.rs
crates/weaver-plugins/src/capability/rename_symbol.rs
crates/weaver-plugins/src/capability/reason_code.rs
Extend plugin protocol and manifest to support capabilities and structured refusal diagnostics while remaining backward compatible.
  • Add capabilities: Vec with serde(default) to PluginManifest, plus with_capabilities() and capabilities() accessor.
  • Tighten manifest validation so Sensor plugins are rejected if they declare any capabilities; Actuators are allowed.
  • Add reason_code: Option with serde(default, skip_serializing_if) to PluginDiagnostic, plus builder/accessor methods.
  • Add focused tests around manifest defaults/capabilities, manifest validation, and PluginDiagnostic reason_code round-tripping.
crates/weaver-plugins/src/manifest/mod.rs
crates/weaver-plugins/src/manifest/tests.rs
crates/weaver-plugins/src/protocol/mod.rs
crates/weaver-plugins/src/protocol/tests.rs
Enable capability-based plugin discovery in the registry.
  • Add find_for_capability(CapabilityId) to PluginRegistry to filter manifests by declared capabilities.
  • Add find_for_language_and_capability(language, CapabilityId) intersecting language (case-insensitive) and capabilities.
  • Add tests that build a mixed capability_registry and assert correct inclusion/exclusion across capabilities and languages.
crates/weaver-plugins/src/registry/mod.rs
crates/weaver-plugins/src/registry/tests.rs
Expose capability types through the crate public API and add behaviour-driven coverage for capability contracts.
  • Export capability module from lib.rs and re-export CapabilityContract, CapabilityId, ContractVersion, ReasonCode, RenameSymbolContract, RenameSymbolRequest.
  • Add unit tests for CapabilityId/ContractVersion/RenameSymbolRequest/RenameSymbolContract/ReasonCode in capability/tests.rs.
  • Add BDD feature file for capability_contract and corresponding step definitions/world wiring in capability_behaviour.rs and tests/mod.rs.
crates/weaver-plugins/src/lib.rs
crates/weaver-plugins/src/capability/tests.rs
crates/weaver-plugins/src/tests/mod.rs
crates/weaver-plugins/src/tests/capability_behaviour.rs
crates/weaver-plugins/tests/features/capability_contract.feature
Document the capability model, rename-symbol contract, and mark roadmap task completion.
  • Add execution plan document describing the rename-symbol capability contract design, constraints, and decisions.
  • Extend users-guide with plugin capabilities section: capability identifiers, rename-symbol request schema, contract versioning, refusal reason codes, and manifest examples.
  • Mark roadmap item 5.2.1 as complete and make minor prose formatting tweaks in an existing execplan doc.
docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md
docs/users-guide.md
docs/roadmap.md
docs/execplans/5-1-1-entry-help.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 28, 2026

Summary by CodeRabbit

  • New Features

    • Added capability contracts including a rename-symbol capability and capability-based plugin routing by capability plus language (case-insensitive).
    • Manifests can declare capabilities; sensor plugins are rejected if they declare capabilities.
    • Diagnostic messages now include stable reason codes and can be attached to refusals.
  • Documentation

    • Expanded user guide and execplan with capability usage, manifest examples, routing behaviour and versioning semantics.

Walkthrough

Summarise the addition of a capability contract system: capability identifiers and versions, a CapabilityContract trait, stable refusal ReasonCode enum, rename-symbol contract with request/response validation, manifest capability declarations and validation, registry capability queries, plus tests and documentation.

Changes

Cohort / File(s) Summary
Capability Module Core
crates/weaver-plugins/src/capability/mod.rs, crates/weaver-plugins/src/capability/reason_code.rs, crates/weaver-plugins/src/capability/rename_symbol.rs
Add CapabilityId, ContractVersion, CapabilityContract trait; introduce ReasonCode enum; implement RenameSymbolContract, request extraction, response validation and public re-exports.
Public API Integration
crates/weaver-plugins/src/lib.rs, crates/weaver-plugins/src/manifest/mod.rs, crates/weaver-plugins/src/protocol/mod.rs, crates/weaver-plugins/src/registry/mod.rs
Expose capability types from crate root; add capabilities: Vec<CapabilityId> to PluginManifest with builder/validation (sensors forbidden); add reason_code to PluginDiagnostic; normalise languages on register; add find_for_capability and find_for_language_and_capability.
Unit & BDD Tests
crates/weaver-plugins/src/capability/tests.rs, crates/weaver-plugins/src/manifest/tests.rs, crates/weaver-plugins/src/protocol/tests.rs, crates/weaver-plugins/src/registry/tests.rs, crates/weaver-plugins/src/tests/capability_behaviour.rs, crates/weaver-plugins/src/tests/mod.rs
Add unit tests and BDD step definitions covering CapabilityId, ContractVersion, ReasonCode, RenameSymbolRequest/contract validation, manifest capability rules, registry lookups and version compatibility.
Test Features & Scenarios
crates/weaver-plugins/tests/features/capability_contract.feature
Add Gherkin scenarios validating valid/invalid rename-symbol requests, response requirements (diff on success), manifest constraints and version compatibility.
Documentation & Roadmap
docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md, docs/users-guide.md, docs/roadmap.md
Add ExecPlan and user-guide docs describing capabilities, contract semantics, reason codes and routing; mark the roadmap item completed and tighten acceptance criteria.
Build / Targets
crates/weaverd/Cargo.toml
Add [[bin]] block for weaverd binary target.
sequenceDiagram
  participant Client
  participant Broker as Daemon/Broker
  participant Registry
  participant Plugin as Actuator/Plugin
  Client->>Broker: send capability request (operation, args)
  Broker->>Registry: find_for_language_and_capability(language, capability)
  Registry-->>Broker: matching manifests
  Broker->>Plugin: forward PluginRequest
  Plugin-->>Broker: PluginResponse (success with Diff | failure with reason_code)
  Broker->>Broker: validate response against CapabilityContract
  Broker-->>Client: return validated response or error with ReasonCode
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

✨ Contracts stitched in versioned thread,
Requests parsed, responses wed,
Reason codes point where errors hide,
Registry routes the ready guide,
Rename flows now safely tried.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title precisely summarises the main changes: introducing a rename-symbol contract and expanding the capability framework across the crates/weaver-plugins ecosystem.
Description check ✅ Passed The description comprehensively covers the changeset, detailing new modules, extended types, manifest handling, registry lookups, tests, and documentation updates directly aligned with the actual changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch define-rename-symbol-contract-gy9w4v

Comment @coderabbitai help to get the list of available commands and usage tips.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Mar 1, 2026

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix:

crates/weaver-plugins/src/manifest/tests.rs

Comment on file

fn manifest_without_capabilities_deserialises_to_empty() {
    let json = r#"{
        "name": "test",
        "version": "0.1",
        "kind": "actuator",
        "languages": ["rust"],
        "executable": "/bin/test"
    }"#;
    let m: PluginManifest = serde_json::from_str(json).expect("deserialise");
    assert!(m.capabilities().is_empty());
}

❌ New issue: Code Duplication
The module contains 2 functions with similar structure: manifest_deserialise_defaults_timeout,manifest_without_capabilities_deserialises_to_empty

@coderabbitai

This comment was marked as resolved.

@leynos leynos changed the title Define rename-symbol capability contract and extend manifest/registry Define rename-symbol contract and expand capability framework Mar 1, 2026
codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Mar 1, 2026

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix:

crates/weaver-plugins/src/manifest/tests.rs

Comment on file

    assert_manifest_from_json(json, |m| {
        assert_eq!(m.timeout_secs(), 30);
        assert!(m.args().is_empty());
    });
}

❌ New issue: Code Duplication
The module contains 2 functions with similar structure: manifest_deserialise_defaults_timeout,manifest_without_capabilities_deserialises_to_empty

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 1, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the current state of the manifest tests file
cat crates/weaver-plugins/src/manifest/tests.rs

Length of output: 6271


@leynos: The previous fix was successfully applied—both tests now use the assert_manifest_from_json helper to eliminate the deserialisation duplication. The CodeScene report is flagging the remaining structural similarity, but this is acceptable in test code.

Why the remaining similarity is acceptable

These are independent test cases with distinct purposes:

  • manifest_deserialise_defaults_timeout validates default timeout and empty args (using a sensor manifest)
  • manifest_without_capabilities_deserialises_to_empty validates empty capabilities (using an actuator manifest)

Each has:

  • Different JSON payloads (sensor vs actuator, different fields being tested)
  • Different assertions (timeout/args vs capabilities)
  • Clear, single responsibility

The pattern define JSON → call helper with closure is a common, idiomatic test structure in Rust. Further extraction would harm test quality by:

  • Reducing clarity and readability
  • Coupling independent test scenarios
  • Making it harder to understand what each test validates

Recommendation

Accept this duplication. Test independence and clarity trump DRY when tests are validating different behaviour. If CodeScene continues to flag this, configure it to:

  • Increase the duplication threshold for test modules
  • Exclude **/tests.rs from duplication analysis
  • Whitelist this specific pattern

No further refactoring is needed—the tests are well-structured as they stand.

@leynos leynos marked this pull request as ready for review March 1, 2026 03:43
sourcery-ai[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@leynos

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

echo "=== 1. Checking RenameSymbolContract::validate_request for operation check ==="
sed -n '/impl CapabilityContract for RenameSymbolContract/,/^}/p' crates/weaver-plugins/src/capability/rename_symbol.rs | grep -A 20 "fn validate_request"

echo -e "\n=== 2. Checking registry helpers for language normalization ==="
echo "--- Check register method for normalization at registration time ---"
sed -n '/pub fn register/,/^    }/p' crates/weaver-plugins/src/registry/mod.rs

echo -e "\n--- Check find_for_capability ---"
sed -n '/pub fn find_for_capability/,/^    }/p' crates/weaver-plugins/src/registry/mod.rs

echo -e "\n--- Check find_for_language_and_capability ---"
sed -n '/pub fn find_for_language_and_capability/,/^    }/p' crates/weaver-plugins/src/registry/mod.rs

echo -e "\n=== 3. Checking manifest validation message (Comment 1) ==="
sed -n '195,215p' crates/weaver-plugins/src/manifest/mod.rs

echo -e "\n=== 4. Checking capability trait docs (Comment 2) ==="
sed -n '145,175p' crates/weaver-plugins/src/capability/mod.rs

echo -e "\n=== 5. Checking parse_kv_pairs tests (Comment 3) ==="
rg -n "^#\[test\]" -A 1 crates/weaver-plugins/src/tests/capability_behaviour.rs | grep -A 1 "parse_kv_pairs"

echo -e "\n=== 6. Checking ADR acronym expansion (Comment 4) ==="
sed -n '150,165p' docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md

echo -e "\n=== 7. Checking BDD acronym expansion (Comment 5) ==="
sed -n '28,38p' docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md

Length of output: 5397


@leynos: Yes, all seven review comments have now been resolved! Here's the complete status:

✅ All Resolved (7/7)

Overall Comments

  1. validate_request operation check
    The implementation now validates that request.operation() matches the expected capability string ("rename-symbol"), returning PluginError::InvalidOutput if there's a mismatch.

  2. Registry helpers optimization
    Languages are now normalised at registration time via manifest.normalise_languages() in the register() method. The lookup methods now only allocate a lowercase copy of the search term once per call (unavoidable), whilst all manifest languages are pre-normalised, eliminating the repeated per-manifest allocations during filtering.

Individual Comments

  1. Comment 1 (manifest validation message)
    The error message now reads "sensor plugins must not declare any capabilities", correctly matching the check being performed.

  2. Comment 2 (capability docs error type)
    The documentation now says Returns a [PluginError] without specifying a variant, removing the misleading reference to InvalidOutput.

  3. Comment 3 (parse_kv_pairs unit tests)
    Three unit tests have been added:

    • parse_kv_pairs_empty_input
    • parse_kv_pairs_multiple_pairs
    • parse_kv_pairs_ignores_tokens_without_equals
  4. Comment 4 (ADR acronym expansion)
    Line 157 now reads "Architecture Decision Record (ADR) 001 defines exactly...", properly expanding the acronym on first use.

  5. Comment 5 (BDD acronym expansion)
    Line 33 now reads "New behaviour-driven development (BDD) scenarios in...", properly expanding the acronym on first use.

All review comments have been successfully addressed! 🎉

(\_/)
(^.^)
(> <) Comprehensive fixes applied!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/weaver-plugins/src/capability/tests.rs`:
- Around line 185-255: Multiple tests repeat the same RenameSymbolContract
setup; convert them to rstest fixtures and parameterised cases by creating a
fixture that returns the RenameSymbolContract instance (and another fixture that
returns the common args via make_rename_args) and then replace redundant tests
(contract_validate_valid_request, contract_validate_invalid_request,
contract_validate_wrong_operation_rejects,
contract_validate_successful_diff_response,
contract_validate_successful_non_diff_response_fails,
contract_validate_failed_response_passes) with #[rstest] parameterised cases
that take the fixture(s) and inputs (e.g., operation name, PluginOutput
variants, PluginResponse success/failure) and assert
validate_request/validate_response outcomes; keep separate small tests for
capability_id() and version() (contract_capability_id and contract_version)
unchanged but call the fixture if desired.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9318fd1 and 255e5e2.

📒 Files selected for processing (3)
  • crates/weaver-plugins/src/capability/mod.rs
  • crates/weaver-plugins/src/capability/tests.rs
  • docs/execplans/5-1-1-entry-help.md

Comment thread crates/weaver-plugins/src/capability/tests.rs Outdated
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

leynos and others added 2 commits March 4, 2026 00:05
…h validation

- Define CapabilityId enum for plugin refactoring capabilities as per ADR 001.
- Implement ContractVersion for versioning with compatibility checks.
- Create CapabilityContract trait for validating plugin requests and responses.
- Add rename-symbol contract with typed request, validation logic for requests and responses.
- Introduce ReasonCode enum for standardized refusal diagnostics.
- Extend PluginManifest to declare supported capabilities with validation.
- Add optional reason_code field to PluginDiagnostic for structured refusal reasons.
- Implement PluginRegistry methods for capability-based plugin lookup.
- Provide comprehensive unit and BDD tests validating contract and manifest extensions.
- Update documentation with detailed capability contract and usage info.

This completes roadmap item 5.2.1 by enforcing a stable, versioned contract for the rename-symbol capability, enabling reliable broker-plugin interactions and structured error handling.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
…tests

Introduced `assert_manifest_from_json` helper to reduce repeated deserialization
code in manifest tests, improving readability and maintainability.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
leynos and others added 6 commits March 4, 2026 00:05
…act requests

- Introduce non-empty string checks for 'uri', 'position', and 'new_name' fields in rename-symbol requests.
- Add operation check to ensure requests match the expected 'rename-symbol' operation.
- Improve error messaging for invalid or empty fields in request extraction.
- Update BDD scenarios and unit tests to cover new validation cases.
- Refactor capability contract validation error descriptions for clarity.
- Adjust manifest validation error to clarify sensor plugins must not declare any capabilities.
- Minor docs updates for terminology consistency and user guide corrections.

These changes increase robustness of the rename-symbol capability contract by ensuring requests are correctly formed and explicitly validated before processing.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
…lookup

Normalize all language entries in plugin manifests to ASCII lowercase during registration. This enables allocation-free lookups when querying plugins by language, improving performance and consistency in language matching.

Additionally, update the find_for_language and find_for_language_and_capability methods to leverage the normalized language list, avoiding repeated allocations and case conversions.

Update docs to fix a minor wording issue regarding ADR 001.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
- Updated spelling of `serialize` and `deserialize` to British English `serialise` and `deserialise` in capability plugin tests.
- Fixed documentation to spell `centralised` correctly.
- Minor wording clarification in capability module docs (expanded ADR to full form).

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Refactor RenameSymbolContract tests to utilize rstest fixtures for cleaner
and more maintainable test code. Introduced fixtures for contract and valid
rename requests, replacing manual setup in each test case. The changes
improve test readability and leverage rstest features effectively.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Added assertions using matches! to verify that errors returned from validate_request and validate_response are specifically of type PluginError::InvalidOutput. This improves test precision and clarity by checking error variants, not only error messages.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
…tests

Refined the error handling in rename-symbol related tests by matching PluginError::InvalidOutput explicitly. This improves test clarity and robustness by verifying specific error variants and their messages instead of relying on string containment checks alone.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
@devboxerhub devboxerhub Bot force-pushed the define-rename-symbol-contract-gy9w4v branch from 77c663e to 43c6d3c Compare March 4, 2026 00:07
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/weaver-plugins/tests/features/capability_contract.feature`:
- Around line 72-75: Add a trailing newline at the end of the feature file so
the file ends with a single newline character; locate the "Scenario: Contract
version incompatibility with different major" block (the Given/And/Then lines)
and ensure there is a newline after the final line "Then the versions are
incompatible" so the file conforms to POSIX/linter expectations.

In `@docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md`:
- Around line 410-421: Insert an explicit caption line immediately above the
Markdown table that starts with the header row "| File                         
| Current lines | Planned additions | Projected total |" in
docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md; add a
brief descriptive caption (e.g., "Table: Line-budget projection for files
modified by the rename-symbol capability") on its own line so the table is
captioned per the documentation guideline.

In `@docs/users-guide.md`:
- Around line 730-737: The tables listing capability identifiers (e.g., rows
containing `rename-symbol`, `extricate-symbol`, `extract-method`,
`replace-body`, `extract-predicate`) need a one-line caption immediately above
each table; update the documentation by inserting a short descriptive caption
line (e.g., "Table: Code transformation capabilities") directly before each such
markdown table in the capabilities section, and apply the same change to the
other tables referenced that list identifiers (the tables near the other
identifier groups noted in the comment) so every table and diagram has a
caption.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d905eae and 43c6d3c.

📒 Files selected for processing (17)
  • crates/weaver-plugins/src/capability/mod.rs
  • crates/weaver-plugins/src/capability/reason_code.rs
  • crates/weaver-plugins/src/capability/rename_symbol.rs
  • crates/weaver-plugins/src/capability/tests.rs
  • crates/weaver-plugins/src/lib.rs
  • crates/weaver-plugins/src/manifest/mod.rs
  • crates/weaver-plugins/src/manifest/tests.rs
  • crates/weaver-plugins/src/protocol/mod.rs
  • crates/weaver-plugins/src/protocol/tests.rs
  • crates/weaver-plugins/src/registry/mod.rs
  • crates/weaver-plugins/src/registry/tests.rs
  • crates/weaver-plugins/src/tests/capability_behaviour.rs
  • crates/weaver-plugins/src/tests/mod.rs
  • crates/weaver-plugins/tests/features/capability_contract.feature
  • docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md
  • docs/roadmap.md
  • docs/users-guide.md

Comment thread crates/weaver-plugins/tests/features/capability_contract.feature
Comment thread docs/users-guide.md
Insert descriptive caption lines immediately above each Markdown
table in the rename-symbol execplan and users-guide so every table
is captioned per the documentation guidelines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Mar 4, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 4, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

The shared rust-build-release GitHub Action resolves binary paths
from Cargo manifest metadata.  Without an explicit [[bin]] entry
the action returned `undefined`, causing "Unable to locate
executable file: undefined" during the "Get human-readable stats"
step of the release dry run.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/users-guide.md (1)

848-848: ⚠️ Potential issue | 🟡 Minor

Expand the LSP acronym on first use.

The acronym "LSP" appears here without prior expansion. Spell out "Language Server Protocol (LSP)" on first use to comply with documentation standards.

📝 Proposed fix
-The daemon sends the LSP `initialize` handshake followed by
+The daemon sends the Language Server Protocol (LSP) `initialize` handshake followed by

As per coding guidelines: "Expand any uncommon acronym on first use in documentation (e.g., Continuous Integration (CI))."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/users-guide.md` at line 848, Update the documentation to expand the
acronym on first use: replace the bare "LSP `initialize` handshake" with
"Language Server Protocol (LSP) `initialize` handshake" (locate the occurrence
of "LSP" near the phrase "`initialize` handshake" in the users-guide text) so
the full form appears once before continuing to use the "LSP" abbreviation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md`:
- Around line 312-313: Replace US spellings with en-GB throughout the document:
change every occurrence of "serialized" to "serialised" and "serialization" to
"serialisation" in narrative prose (for example the phrase "serialized as
snake_case strings" and the later occurrence around the "serialization"
wording). Ensure only prose is changed (leave code, API names or examples that
must remain US-spelled untouched) and run a quick search for both terms to
update all instances consistently.
- Around line 26-27: Update the documented validation steps that currently state
"Running `make check-fmt && make lint && make test` passes..." to include the
additional Markdown quality gates by adding `make markdownlint`, `make fmt`, and
`make nixie` to the sequence and examples; specifically edit the occurrence
around the existing `make check-fmt && make lint && make test` sentence and the
repeated block referenced (the other occurrence in the 356-380 region) so the
docs show running `make check-fmt`, then `make markdownlint`, `make fmt`, `make
nixie`, `make lint`, and `make test` (and update any example shell snippet to
pipe output to logs as in the proposed patch).

---

Outside diff comments:
In `@docs/users-guide.md`:
- Line 848: Update the documentation to expand the acronym on first use: replace
the bare "LSP `initialize` handshake" with "Language Server Protocol (LSP)
`initialize` handshake" (locate the occurrence of "LSP" near the phrase
"`initialize` handshake" in the users-guide text) so the full form appears once
before continuing to use the "LSP" abbreviation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a3ae9d22-400f-4e06-befb-6a7df9d5fe71

📥 Commits

Reviewing files that changed from the base of the PR and between 43c6d3c and 6f616aa.

📒 Files selected for processing (3)
  • crates/weaverd/Cargo.toml
  • docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md
  • docs/users-guide.md

Comment thread docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md Outdated
leynos and others added 2 commits March 5, 2026 12:57
Spell out "Language Server Protocol (LSP)" at the first occurrence
so readers encounter the full form before subsequent abbreviations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Stage D modifies documentation, so the quality gates and
validation commands must include `make markdownlint` alongside
the existing fmt, lint, and test checks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md (1)

26-27: ⚠️ Potential issue | 🟠 Major

Add the full documentation quality gates to validation commands.

Update every documented validation sequence to include make markdownlint, make fmt, and make nixie, and keep the shell example aligned.

Proposed patch
-- Running `make check-fmt && make lint && make test && make markdownlint`
+- Running `make check-fmt && make markdownlint && make fmt && make nixie && make lint && make test`
   passes with no regressions.
@@
-- Validation: `make check-fmt && make lint && make test && make markdownlint`
+- Validation: `make check-fmt && make markdownlint && make fmt && make nixie && make lint && make test`
   all pass.
@@
 ```sh
 set -o pipefail
 make check-fmt 2>&1 | tee /tmp/check-fmt.log
+make markdownlint 2>&1 | tee /tmp/markdownlint.log
+make fmt 2>&1 | tee /tmp/fmt.log
+make nixie 2>&1 | tee /tmp/nixie.log
 make lint 2>&1 | tee /tmp/lint.log
 make test 2>&1 | tee /tmp/test.log
-make markdownlint 2>&1 | tee /tmp/markdownlint.log
</details>

As per coding guidelines: "`**/*.md`: Validate Markdown files using `make markdownlint`.", "`**/*.md`: Run `make fmt` after any documentation changes to format all Markdown files and fix table markup.", and "`**/*.md`: Validate Mermaid diagrams in Markdown files by running `make nixie`."


Also applies to: 356-357, 377-383

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md around
lines 26 - 27, Update the documented validation sequences (the shell example
that currently runs "make check-fmt && make lint && make test && make
markdownlint") to include the full documentation quality gates by adding "make
markdownlint", "make fmt", and "make nixie" to the sequence and reorder the
tee'd commands to match the proposed patch (e.g., run "make check-fmt", then
"make markdownlint", "make fmt", "make nixie", then "make lint" and "make test")
so the example and each listed validation step (references: the shell example
lines invoking make check-fmt, make lint, make test, make markdownlint) are
consistent with the coding guidelines for validating and formatting Markdown.


</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>

Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In @docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md:

  • Around line 26-27: Update the documented validation sequences (the shell
    example that currently runs "make check-fmt && make lint && make test && make
    markdownlint") to include the full documentation quality gates by adding "make
    markdownlint", "make fmt", and "make nixie" to the sequence and reorder the
    tee'd commands to match the proposed patch (e.g., run "make check-fmt", then
    "make markdownlint", "make fmt", "make nixie", then "make lint" and "make test")
    so the example and each listed validation step (references: the shell example
    lines invoking make check-fmt, make lint, make test, make markdownlint) are
    consistent with the coding guidelines for validating and formatting Markdown.

</details>

---

<details>
<summary>ℹ️ Review info</summary>

<details>
<summary>⚙️ Run configuration</summary>

**Configuration used**: Organization UI

**Review profile**: ASSERTIVE

**Plan**: Pro

**Run ID**: `bf21fa96-7902-4bad-b5d0-f358fe1fad07`

</details>

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 6f616aa61f380a48a51e7bfb384c434450a15b86 and 21a9f435c92281a29964a2911377c834668be3bf.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `docs/execplans/5-2-1-define-the-rename-symbol-capability-contract.md`
* `docs/users-guide.md`

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@leynos leynos merged commit 596fff2 into main Mar 5, 2026
11 checks passed
@leynos leynos deleted the define-rename-symbol-contract-gy9w4v branch March 5, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant