mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
267eacfca2
## Why
CCA can select a capability root that lives in an executor environment,
but
Codex only had a host-filesystem plugin loader. Before selected executor
plugins can contribute MCP servers, we need a small package boundary
that can
answer:
> Does this selected root contain a plugin, and if so, what does its
manifest
> declare?
The answer must come from the selected environment's filesystem. A
failed
executor lookup must never fall back to the orchestrator filesystem.
## What this changes
This PR introduces:
```rust
PluginProvider::resolve(root)
-> Result<Option<ResolvedPlugin>, Error>
```
`ExecutorPluginProvider` resolves one `SelectedCapabilityRoot` through
its
exact `environment_id`. It checks the recognized manifest locations,
reads the
manifest through that environment's `ExecutorFileSystem`, and returns an
inert
`ResolvedPlugin` containing:
- the opaque selected-root ID;
- the environment-bound plugin root;
- the authority-bound manifest resource;
- parsed metadata and authority-bound component locators.
Descriptor construction rejects manifest or component paths outside the
selected package root, so consumers cannot accidentally lose the package
boundary when they receive a resolved plugin.
If the root has no plugin manifest, resolution returns `None`, allowing
the
caller to treat it as a standalone capability such as a skill.
```text
selected root: repo -> env-1:/workspace/repo
|
| env-1 filesystem only
v
.codex-plugin/plugin.json
|
v
ResolvedPlugin { authority, root, manifest }
```
The existing host loader and the new executor provider now share the
same
manifest parser. Existing `codex-core-plugins::manifest` type paths
remain
available through re-exports, so host behavior and callers are
unchanged.
## Scope
This is intentionally a non-user-visible package-resolution PR. It does
not:
- parse or register plugin MCP server configurations;
- activate skills, connectors, hooks, or MCP servers;
- change app-server wiring;
- introduce host fallback, caching, or lifecycle behavior.
#27670 has merged, and this PR is now based directly on `main`. Together
with
the resolved MCP catalog from #27634, it establishes the inputs needed
for the
executor stdio MCP vertical without changing the existing MCP runtime.
## Follow-up
The next PR will consume `ResolvedPlugin`, read its declared/default MCP
config
through the same executor filesystem, bind supported stdio servers to
that
environment, and feed those registrations into the resolved MCP catalog.
An
app-server E2E will prove that selecting an executor plugin exposes and
invokes
its tool on the owning executor.
Resume/fork semantics, dynamic environment replacement, and non-stdio
placement remain separate lifecycle decisions.
## Validation
- `just fmt`
- `cargo check --tests -p codex-plugin -p codex-core-plugins`
- `just bazel-lock-check`
- `git diff --check`
Test targets were compiled but not executed locally; CI will run the
test and
Clippy suites.
127 lines
4.1 KiB
Rust
127 lines
4.1 KiB
Rust
use super::PluginResourceLocator;
|
|
use super::ResolvedPlugin;
|
|
use super::ResolvedPluginError;
|
|
use crate::manifest::PluginManifest;
|
|
use crate::manifest::PluginManifestHooks;
|
|
use crate::manifest::PluginManifestInterface;
|
|
use crate::manifest::PluginManifestPaths;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
fn absolute(path: impl AsRef<std::path::Path>) -> AbsolutePathBuf {
|
|
AbsolutePathBuf::from_absolute_path_checked(path.as_ref()).expect("absolute test path")
|
|
}
|
|
|
|
fn resource(environment_id: &str, path: AbsolutePathBuf) -> PluginResourceLocator {
|
|
PluginResourceLocator::Environment {
|
|
environment_id: environment_id.to_string(),
|
|
path,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn environment_descriptor_binds_every_manifest_resource() {
|
|
let root = absolute(std::env::current_dir().expect("cwd").join("plugin-root"));
|
|
let manifest_path = root.join(".codex-plugin/plugin.json");
|
|
let skills = root.join("skills");
|
|
let mcp_servers = root.join(".mcp.json");
|
|
let apps = root.join(".app.json");
|
|
let hooks = root.join("hooks/hooks.json");
|
|
let composer_icon = root.join("assets/composer.svg");
|
|
let logo = root.join("assets/logo.svg");
|
|
let screenshot = root.join("assets/screenshot.png");
|
|
let manifest = PluginManifest {
|
|
name: "demo".to_string(),
|
|
version: None,
|
|
description: None,
|
|
keywords: Vec::new(),
|
|
paths: PluginManifestPaths {
|
|
skills: Some(skills.clone()),
|
|
mcp_servers: Some(mcp_servers.clone()),
|
|
apps: Some(apps.clone()),
|
|
hooks: Some(PluginManifestHooks::Paths(vec![hooks.clone()])),
|
|
},
|
|
interface: Some(PluginManifestInterface {
|
|
composer_icon: Some(composer_icon.clone()),
|
|
logo: Some(logo.clone()),
|
|
screenshots: vec![screenshot.clone()],
|
|
..PluginManifestInterface::default()
|
|
}),
|
|
};
|
|
|
|
let plugin = ResolvedPlugin::from_environment(
|
|
"selected-demo".to_string(),
|
|
"executor-1".to_string(),
|
|
root,
|
|
manifest_path.clone(),
|
|
manifest,
|
|
)
|
|
.expect("valid descriptor");
|
|
|
|
assert_eq!(
|
|
plugin.manifest_path(),
|
|
&resource("executor-1", manifest_path)
|
|
);
|
|
assert_eq!(
|
|
plugin.manifest(),
|
|
&PluginManifest {
|
|
name: "demo".to_string(),
|
|
version: None,
|
|
description: None,
|
|
keywords: Vec::new(),
|
|
paths: PluginManifestPaths {
|
|
skills: Some(resource("executor-1", skills)),
|
|
mcp_servers: Some(resource("executor-1", mcp_servers)),
|
|
apps: Some(resource("executor-1", apps)),
|
|
hooks: Some(PluginManifestHooks::Paths(vec![resource(
|
|
"executor-1",
|
|
hooks,
|
|
)])),
|
|
},
|
|
interface: Some(PluginManifestInterface {
|
|
composer_icon: Some(resource("executor-1", composer_icon)),
|
|
logo: Some(resource("executor-1", logo)),
|
|
screenshots: vec![resource("executor-1", screenshot)],
|
|
..PluginManifestInterface::default()
|
|
}),
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn environment_descriptor_rejects_resources_outside_package_root() {
|
|
let cwd = std::env::current_dir().expect("cwd");
|
|
let root = absolute(cwd.join("plugin-root"));
|
|
let outside = absolute(cwd.join("outside/.mcp.json"));
|
|
let manifest = PluginManifest {
|
|
name: "demo".to_string(),
|
|
version: None,
|
|
description: None,
|
|
keywords: Vec::new(),
|
|
paths: PluginManifestPaths {
|
|
skills: None,
|
|
mcp_servers: Some(outside.clone()),
|
|
apps: None,
|
|
hooks: None,
|
|
},
|
|
interface: None,
|
|
};
|
|
|
|
let err = ResolvedPlugin::from_environment(
|
|
"selected-demo".to_string(),
|
|
"executor-1".to_string(),
|
|
root.clone(),
|
|
root.join(".codex-plugin/plugin.json"),
|
|
manifest,
|
|
)
|
|
.expect_err("outside resource should fail");
|
|
|
|
assert_eq!(
|
|
err,
|
|
ResolvedPluginError::ResourceOutsideRoot {
|
|
root,
|
|
path: outside,
|
|
}
|
|
);
|
|
}
|