Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ libraries = [{ git = "https://github.com/cppalliance/dylints", rev = "982b297ede
# differs from this workspace's.
[workspace.metadata.workshop]
git = "https://github.com/cppalliance/runvil-workshop"
rev = "0381a776f37240bf900a035d572774af5054b705"
rev = "6f8ed26d438be9e4bf4296b36f1e6e42de13f28f"

[workspace.lints.rust]
unsafe_code = "deny"
Expand Down
153 changes: 153 additions & 0 deletions plan/2026-12-02-2-unified-tool-info.plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
name: Unified ToolInfo
overview: Consolidate all tool, MCP function, and prompt callable metadata into a single plain pub struct ToolInfo in gateway-types (using explicit Arc<ToolInfo> at shared catalog/binding/chat sites), sync its source verbatim into runvil-plugin-sdk over a JSON RvToolInfo C ABI (v0.9.0), and roll it out in small testable commits across Waves 1-4 (pushing to origin, opening PRs, waiting on CI, and merging to upstream at each wave).
todos:
- id: wave1-gateway-client
content: "Wave 1a (gateway-client): 3 testable commits (plan copy, add gateway_types::ToolInfo, replace ToolSchema with concrete Arc<ToolInfo>); verify all CI gates, push to origin, open PR to upstream, wait for green CI/reviews, and merge to upstream (SHA G)"
status: completed
- id: wave1-plugin-api
content: "Wave 1b (runvil-plugin-api, parallel with 1a once tool.rs is written): 3 testable commits (plan copy, sync tool_info.rs + xtask check + serde deps, bump contract to 0.9.0 with 24-byte JSON RvToolInfo); verify 1.85 MSRV + c-layout, push to origin, open PR, merge to upstream (SHA P)"
status: completed
- id: wave2-three-plugins
content: "Wave 2a (runvil-plugin-std, bashkit, web in parallel): 2 testable commits per repo (plan copy, pin SDK 0.9.0 at SHA P + Value/with_* updates); verify, push to origin, open PRs, and merge to upstream (SHAs S, B, W)"
status: completed
- id: wave2-harness
content: "Wave 2b (runvil-harness, parallel with 2a): 4 testable commits (plan copy, pin G + adopt ToolInfo across engine/harness/mcp on 0.8 loader, embed Arc<ToolInfo> in Frontmatter & drop Annotations, pin contract 0.9.0 at P + JSON RvToolInfo in loader/test-plugin + decisions); verify, push to origin, open PR, merge to upstream (SHA H)"
status: completed
- id: wave3-workshop-and-runvil
content: "Wave 3 (runvil-workshop, then runvil): 3 testable commits in workshop (plan copy, pin H/P/S/B/W + WorkshopBroker::chat, flatten prompt.tool_info() into /prompts/contract + UI tests), PR & merge to upstream (SHA K); then pin Workshop SHA K in runvil, PR & merge to upstream"
status: in_progress
isProject: false
---

# Unify Tool, Prompt, and MCP Metadata into `gateway_types::ToolInfo`

## Goal and Design Summary

Replace the separate tool, prompt-annotation, MCP-listing, and wire-schema structs across the fleet with one plain `pub struct ToolInfo` defined in `gateway-types` and copied verbatim into `runvil-plugin-sdk`:

- **Plain struct + explicit `Arc<ToolInfo>` for \(O(1)\) sharing (zero `serde/rc` needed)**: `ToolInfo` is a plain Rust struct with `pub` fields matching `ModelInfo`, `Message`, and `Error` in `gateway-types`. Single-owner boundaries (`Pack::tools() -> Vec<ToolInfo>`, `Pack::render(...) -> Result<Vec<ToolInfo>>`, `PackToolSets<ToolInfo>` in `EffectAnswer::Render`) move `ToolInfo` by value in \(O(1)\) so `Pack::render` mutates fields naturally and `EffectAnswer::Render` serializes without enabling `serde/rc`. Shared multi-owner lifetimes (`ToolCatalog`, `OfferedTool`, `ToolBinding`, `LuaToolHandle`, `Prompt`, `Effect::Chat`, `InferenceBroker::chat`) hold `Arc<ToolInfo>` explicitly so schemas and descriptions are never deep-copied across runs, Lua VMs, or model rounds.
- **100% self-describing flat struct (zero helper structs)**: `ToolInfo` holds `name`, `pack` (losslessly splitting 2+ segment `ToolId`s at the first `/`, e.g. `pack = Some("fixtures")`, `name = "tools/inspect"`), `wire_name` (plus `effective_wire_name` and `qualified_name` helpers), `title`, `description`, `input_schema`, optional `output_schema`, the 4 closed MCP hints (`read_only_hint`, `destructive_hint`, `idempotent_hint`, `open_world_hint`), and the 5 Engine execution flags (`structured_output`, `survives_stop`, `describes_tools`, `model_only_call`, `changes_files`).
- **Third-party safe & Engine-stage validated**: `ToolInfo::new` is infallible (preserving Engine tests that place unvalidated schemas into `ToolCatalog` and reject them at `scope` freeze), `output_schema: Option<Value>` is descriptive and optional, and `structured_output: bool` remains the explicit opt-in switch for Lua `tools.call` JSON decoding.
- **Standalone plugin repo**: `tool.rs` uses only `std`, `serde`, and `serde_json` (Rust 1.85 syntax, functions `<= 100` lines and `<= 7` args, no `#[non_exhaustive]`) and is copied into `runvil-plugin-sdk` and committed to Git, passing JSON text across `RvToolInfo` in C ABI v0.9.0.

## Git, Commit, PR, and Upstream Merge Protocol

Every downstream `Cargo.toml` pins `https://github.com/cppalliance/<repo>` (`upstream`) by exact commit SHA, while local `master` pushes to `git@github.com:vinniefalco/<repo>.git` (`origin`). Therefore each wave completes its `origin` push -> PR -> green CI -> `upstream` merge cycle before the next wave pins its merged `upstream` SHA:

1. **Stay on `master`** (no topical branches; `origin` is the fork, `upstream` is `cppalliance/*`). Sync `master` with `upstream/master` before starting each repo.
2. **Plan copy commit first**: Commit 1 in every touched repo adds `plan/2026-12-02-2-unified-tool-info.plan.md` so every commit message follows `.cursor/rules/commit.mdc` (`Plan: /plan/2026-12-02-2-unified-tool-info.plan.md`).
3. **Every commit is independently green**: Before each `git commit`, run `cargo fmt`, `cargo clippy` (warnings denied), and the workspace test suite (+ `xtask` / `public-api` / MSRV checks where applicable) so `git bisect` passes at every single commit.
4. **PR & merge per wave**: Push `master` to `origin`, open a PR against `cppalliance/<repo>:master` via `gh pr create`, monitor GitHub Actions checks and review comments until green, address any findings in follow-up testable commits, merge the PR to `upstream` via `gh pr merge`, and `git fetch upstream && git merge --ff-only upstream/master` locally to capture the exact merged `upstream` SHA for the next wave.

```mermaid
flowchart TD
GatewayTypes["gateway-types"] -->|"copy tool.rs"| PluginApi["plugin-api 0.9"]
GatewayTypes -->|"upstream SHA G"| Harness["runvil-harness"]
PluginApi -->|"upstream SHA P"| PluginStd["plugin-std"]
PluginApi -->|"upstream SHA P"| PluginBash["plugin-bashkit"]
PluginApi -->|"upstream SHA P"| PluginWeb["plugin-web"]
PluginApi -->|"upstream SHA P"| Harness
PluginStd -->|"upstream SHA S"| Workshop["runvil-workshop"]
PluginBash -->|"upstream SHA B"| Workshop
PluginWeb -->|"upstream SHA W"| Workshop
Harness -->|"upstream SHA H"| Workshop
Workshop -->|"upstream SHA K"| Runvil["runvil"]
```

## Wave 1: `gateway-client` and `runvil-plugin-api` (Parallel PRs once `tool.rs` is written)

### Wave 1a: `gateway-client` (3 Testable Commits -> Merged Upstream SHA `G`)

- **Commit 1**: Add `plan/2026-12-02-2-unified-tool-info.plan.md`.
- **Commit 2 (additive, keeps `ToolSchema` compiling)**: Add [`gateway-client/crates/gateway-types/src/tool.rs`](https://github.com/cppalliance/gateway-client/blob/master/crates/gateway-types/src/tool.rs) + unit tests, re-export `ToolInfo` from [`gateway-client/crates/gateway-types/src/lib.rs`](https://github.com/cppalliance/gateway-client/blob/master/crates/gateway-types/src/lib.rs) and [`gateway-client/crates/gateway-client/src/lib.rs`](https://github.com/cppalliance/gateway-client/blob/master/crates/gateway-client/src/lib.rs), and update both `public-api.txt` snapshots:
- Rust 1.85 syntax (no `let` chains), no `#[non_exhaustive]`, `<= 100` lines and `<= 7` args per function, `use std::fmt;`, text-only doc fences, and intra-doc links scoped strictly to `ToolInfo`:

```rust
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[expect(
clippy::struct_excessive_bools,
reason = "the five execution flags are independent properties of one tool"
)]
pub struct ToolInfo {
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pack: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub wire_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
pub description: String,
pub input_schema: Value,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub output_schema: Option<Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub read_only_hint: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub destructive_hint: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub idempotent_hint: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub open_world_hint: Option<bool>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub structured_output: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub survives_stop: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub describes_tools: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub model_only_call: bool,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub changes_files: bool,
}
```

- Provide infallible `ToolInfo::new(name, description, input_schema)`, `with_*` builders, `effective_wire_name(&self) -> Cow<'_, str>`, `qualified_name(&self) -> Cow<'_, str>`, and field getters.
- **Commit 3 (replace `ToolSchema` with concrete `Arc<ToolInfo>`)**: Update [`gateway-client/crates/gateway-types/src/request.rs`](https://github.com/cppalliance/gateway-client/blob/master/crates/gateway-types/src/request.rs), `request-tests.rs`, [`gateway-client/crates/gateway-types/src/broker.rs`](https://github.com/cppalliance/gateway-client/blob/master/crates/gateway-types/src/broker.rs), and [`gateway-client/crates/gateway-client/src/transport.rs`](https://github.com/cppalliance/gateway-client/blob/master/crates/gateway-client/src/transport.rs). Keep `tools` concrete (`Option<&[Arc<ToolInfo>]>` on `build_request_body` and `GatewayClient::complete`; `Vec<Arc<ToolInfo>>` on `InferenceBroker::chat`) so all 22 bare `None` / `Some(&[])` call sites infer cleanly without `E0282`. Validate `(tool.effective_wire_name(), &tool.input_schema)` via `validate_tool_schema` (retaining `ErrorCode::ToolSchemaInvalid = 509`), refresh both `public-api.txt` files, verify all CI gates (`+1.88`, `dylint`, `deny`, `nextest`), push to `origin`, open PR, and merge to `upstream` -> SHA `G`.

### Wave 1b: `runvil-plugin-api` v0.9.0 (3 Testable Commits -> Merged Upstream SHA `P`)

- **Commit 1**: Add `plan/2026-12-02-2-unified-tool-info.plan.md`.
- **Commit 2 (sync `tool_info.rs` + `xtask` check, keeping 0.8 ABI intact)**: Add `serde` and `serde_json` to [`runvil-plugin-api/Cargo.toml`](https://github.com/cppalliance/runvil-plugin-api/blob/master/Cargo.toml) and [`runvil-plugin-api/crates/runvil-plugin-sdk/Cargo.toml`](https://github.com/cppalliance/runvil-plugin-api/blob/master/crates/runvil-plugin-sdk/Cargo.toml) (`runvil-plugin-sys` stays `#![no_std]` with zero dependencies), copy `tool.rs` verbatim to [`runvil-plugin-api/crates/runvil-plugin-sdk/src/tool_info.rs`](https://github.com/cppalliance/runvil-plugin-api/blob/master/crates/runvil-plugin-sdk/src/tool_info.rs), and add `sync-tool-info` check in [`runvil-plugin-api/crates/build-xtask/src/main.rs`](https://github.com/cppalliance/runvil-plugin-api/blob/master/crates/build-xtask/src/main.rs). Verify `+1.85 check` and `cargo test` pass.
- **Commit 3 (bump C contract & SDK to `0.9.0` with JSON `RvToolInfo`)**:
- Update [`runvil-plugin-api/crates/runvil-plugin-sys/src/lib.rs`](https://github.com/cppalliance/runvil-plugin-api/blob/master/crates/runvil-plugin-sys/src/lib.rs) (`RV_API_MINOR = 9`, `RvToolInfo { size: u32, reserved: u32, json: RvStr }` size 24, `RV_MAX_TOOL_JSON = 262_144`, keeping `RV_MAX_TOOL_TEXT = 65_536` for `description`), regenerate [`runvil-plugin-api/crates/runvil-plugin-sys/include/runvil_plugin.h`](https://github.com/cppalliance/runvil-plugin-api/blob/master/crates/runvil-plugin-sys/include/runvil_plugin.h), and update [`runvil-plugin-api/tests/c-layout/src/lib.rs`](https://github.com/cppalliance/runvil-plugin-api/blob/master/tests/c-layout/src/lib.rs) + `layout.c`.
- Switch `runvil-plugin-sdk` (`src/tool.rs`, `src/entry/{pack,tool,file}.rs`, `src/testing.rs`, `src/testing/{pack,render,fixture}.rs`, `examples/hello-plugin/src/lib.rs`, `AGENTS.md`, `README.md`) to re-export `tool_info::ToolInfo`, keeping `let jsons: Vec<String>` alive across `extern "C"` render calls and updating `Mode::Respaced` in `testing/render.rs` for semantic JSON `Value` comparison.
- Verify all CI checks (`+1.85`, `c-layout`, `clippy`, `doc`), push to `origin`, open PR, and merge to `upstream` -> SHA `P`.

## Wave 2: Three Plugin Repos + `runvil-harness` (4 Parallel PRs once `G` and `P` Merge)

### Wave 2a: `runvil-plugin-std`, `runvil-plugin-bashkit`, and `runvil-plugin-web` (2 Testable Commits Each -> Merged SHAs `S`, `B`, `W`)

In each of [`runvil-plugin-std`](https://github.com/cppalliance/runvil-plugin-std), [`runvil-plugin-bashkit`](https://github.com/cppalliance/runvil-plugin-bashkit), and [`runvil-plugin-web`](https://github.com/cppalliance/runvil-plugin-web) independently in parallel:
- **Commit 1**: Add `plan/2026-12-02-2-unified-tool-info.plan.md`.
- **Commit 2**: Pin `runvil-plugin-sdk = "0.9.0"` at `P`, pass `serde_json::Value` directly to `ToolInfo::new` using `.with_wire_name(...)` and `.with_changes_files(true)`, update `[ToolInfo::with_changes_files]` doc link in [`runvil-plugin-std/crates/plugin-std/src/lib.rs`](https://github.com/cppalliance/runvil-plugin-std/blob/master/crates/plugin-std/src/lib.rs), and update `tool.input_schema` assertions in `pack-tests.rs` and `web-tests.rs`.
- Verify all checks (`build-checks`, `clippy`, `test`, `doc`), push to `origin`, open PRs, and merge to `upstream` -> SHAs `S`, `B`, `W`.

### Wave 2b: `runvil-harness` (4 Testable Commits -> Merged Upstream SHA `H`)

- **Commit 1**: Add `plan/2026-12-02-2-unified-tool-info.plan.md`.
- **Commit 2 (pin `gateway-types` at `G` and unify `ToolInfo` across Engine, Harness, and `plugin-mcp` while keeping loader on 0.8)**:
- Update [`Cargo.toml`](../Cargo.toml) to pin `gateway-client` / `gateway-types` at `G`.
- Delete `runvil_types::tools::ToolInfo` in [`crates/runvil-internal/types/src/tools.rs`](../crates/runvil-internal/types/src/tools.rs) and re-export `gateway_types::ToolInfo`. Split 2+ segment `ToolId`s at the first `/` (`pack` + `name`) and index `(ToolId, Arc<ToolInfo>)` inside `ToolCatalog`, `OfferedTool::Catalog`, `ToolBinding`, and `LuaToolHandle` (keeping `.id() -> &ToolId` borrowed at all 30+ Engine sites and `.parameters` userdata reading `input_schema`).
- Update `Effect::Chat` (`tools: Vec<Arc<ToolInfo>>`), `scope.rs`, `RunPacks`, `plugin-mcp` (`rmcp::model::Tool` -> `Arc<ToolInfo>` preserving `title`, `output_schema`, and hints while keeping `mcp/get_dynamic_tools` output unchanged), `harness-plugin-loader` (adapting 0.8 `RvToolInfo` into new `ToolInfo`), `harness-gateway-client`, and facades (`runvil-engine`, `runvil`, dropping `ToolSchema` re-exports and blessing `public-api.txt`). Every workspace test and `xtask` check passes at this commit.
- **Commit 3 (embed `Arc<ToolInfo>` in `Frontmatter` / `Prompt` and drop `pub struct Annotations`)**:
- In [`crates/runvil-internal/prompt/src/frontmatter.rs`](../crates/runvil-internal/prompt/src/frontmatter.rs) and `prompt.rs`, keep private `RawAnnotations` so every YAML error message and span test in `frontmatter-tests-annotations.rs` stays identical, build `tool: Arc<ToolInfo>` on `Frontmatter` (keeping `.name()`, `.description()`, `.title()`, `.args()` delegating on `Frontmatter` and adding `Frontmatter::tool_info` + `Prompt::tool_info`), remove `Annotations` from `runvil-engine` and `runvil`, and bless `public-api.txt`.
- **Commit 4 (pin `runvil-plugin-sys = "0.9.0"` at `P` and switch loader + `test-plugin` to JSON `RvToolInfo`)**:
- Pin `runvil-plugin-sys = "0.9.0"` at `P` in `Cargo.toml`.
- Delete `AddedTool`, `Offered`, and `raw_parameters` in [`crates/harness-internal/plugin-loader/src/pack.rs`](../crates/harness-internal/plugin-loader/src/pack.rs) and `session.rs`, deserializing `RvToolInfo.json` straight into `ToolInfo` (keeping `Vec<String>` alive across `send_render`).
- Update zero-dep [`crates/harness-internal/test-plugin/src/lib.rs`](../crates/harness-internal/test-plugin/src/lib.rs) + `lib-tests.rs` to contract `0.9` (`size == 24`, balanced-brace `object_of` helper for `"shape"`), add a `build-xtask` sync check when sibling repos are present, and update `decisions/tools-and-packs.md` and `decisions/prompt-language.md`.
- Run full pre-push + CI suite (`docs-claims.mjs`, `clippy`, `nextest`, `xtask tidy`, `+nightly-2026-09-05 xtask api`, `dylint`, `deny`), push to `origin`, open PR, and merge to `upstream` -> SHA `H`.

## Wave 3: `runvil-workshop` and `runvil` (Sequential Final Wave)

### Wave 3a: `runvil-workshop` (3 Testable Commits -> Merged Upstream SHA `K`)

- **Commit 1**: Add `plan/2026-12-02-2-unified-tool-info.plan.md`.
- **Commit 2 (pins + broker)**: Update [`runvil-workshop/Cargo.toml`](https://github.com/cppalliance/runvil-workshop/blob/master/Cargo.toml) to pin `runvil-harness` (`H`), `runvil-plugin-sdk` `0.9.0` (`P`), and `std-plugin` (`S`), `bashkit-plugin` (`B`), `web-plugin` (`W`), and switch `WorkshopBroker::chat` in [`runvil-workshop/crates/workshop/server/src/agents/broker.rs`](https://github.com/cppalliance/runvil-workshop/blob/master/crates/workshop/server/src/agents/broker.rs) to `Vec<Arc<runvil::ToolInfo>>`. Verify `cargo test` and `xtask tidy`.
- **Commit 3 (`/prompts/contract` + UI)**: Flatten `&**prompt.tool_info()` onto `ContractResponse` in [`runvil-workshop/crates/workshop/server/src/routes/prompts.rs`](https://github.com/cppalliance/runvil-workshop/blob/master/crates/workshop/server/src/routes/prompts.rs) (keeping explicit `null` for absent `runvil` and `max_tool_iterations`), and update `prompts-tests.rs`, [`runvil-workshop/crates/workshop/ui/src/services/run-api.ts`](https://github.com/cppalliance/runvil-workshop/blob/master/crates/workshop/ui/src/services/run-api.ts), `run-rows.ts`, `test/run-api.mjs`, and `test/run-panel.mjs`.
- Verify Rust + UI tests + `xtask tidy`, push to `origin`, open PR, and merge to `upstream` -> SHA `K`.

### Wave 3b: `runvil` (2 Testable Commits -> Merged Upstream)

- **Commit 1**: Add `plan/2026-12-02-2-unified-tool-info.plan.md`.
- **Commit 2**: Pin `[workspace.metadata.workshop]` in [`runvil/Cargo.toml`](https://github.com/cppalliance/runvil/blob/master/Cargo.toml) to SHA `K`, verify `xtask`, push to `origin`, open PR, and merge to `upstream`.
Loading