feat(ext): extension selection + lock v4, inspect --extensions (RFC-EXT-0001 PR-04)

- marqdo.yaml.extensions accepts only ./path or @alias/path, resolves to a
  regular file inside its owning package, never grants
- lock_version 4 records plugin/kernel/provider manifest+artifact identity;
  v3 requires explicit 'marqdo lock' migration; sync/check/run compare identity
- check stays static; run re-verifies artifact bytes; pure/strict refuse
- inspect --extensions reports declared/locked identity, plugin descriptors and
  stdlib aliases with authorization 'not_granted'
- black-box extension_selection suite (13) + package-layer tests; specs/ADR-0056
- workspace gate: fmt/clippy clean, 599 passed across 67 targets
This commit is contained in:
cflmy committed 2026-11-22 00:43:18 +08:00
1 parent 1f6fd644a0
commit 89555382e0
19 files changed
+2240 -63

No files matched your search

+40 -2
View File
@@ -20,6 +20,7 @@ pub fn execute(
Ok(prepared) => prepared,
Err(code) => return code,
};
let extension_sources = prepared.loaded.extension_sources.clone();
let project = prepared.loaded;
let static_plugins = prepared.plugins;
if project.has_errors() {
@@ -51,6 +52,43 @@ pub fn execute(
return 2;
}
};
// A project-declared extension is activation, not authorization, but it is
// still third-party executable code. `pure`/`strict` never activate it.
if !extension_sources.is_empty() && mode != SandboxMode::Project {
let code = if mode == SandboxMode::Strict {
"strict.unsupported_grant"
} else {
"cli.invalid_grants"
};
let message = format!(
"this project declares {} extension activation source(s) in {}; \
--mode {} cannot activate third-party extensions. Use --mode project \
with explicit grants, or remove the extensions block",
extension_sources.len(),
marqdo_package::MANIFEST_FILE,
settings.mode
);
emit_error(json, command_name, code, &message);
return 2;
}
let mut kernel_paths = settings.kernels.clone();
kernel_paths.extend(
extension_sources
.iter()
.filter(|extension| extension.kind == marqdo_package::ExtensionKind::Kernel)
.map(|extension| extension.path.clone()),
);
kernel_paths.sort();
kernel_paths.dedup();
let mut provider_paths = settings.providers.clone();
provider_paths.extend(
extension_sources
.iter()
.filter(|extension| extension.kind == marqdo_package::ExtensionKind::Provider)
.map(|extension| extension.path.clone()),
);
provider_paths.sort();
provider_paths.dedup();
if mode == SandboxMode::Strict {
if let Err(error) = settings.strict_preflight() {
emit_error(json, command_name, "strict.unsupported_grant", &error);
@@ -121,7 +159,7 @@ pub fn execute(
if let Some(timeout) = settings.timeout {
host.budget.deadline = Some(Instant::now() + Duration::from_secs(timeout));
}
for kernel_path in &settings.kernels {
for kernel_path in &kernel_paths {
if let Err(error) = load_kernel_descriptor(&mut host, kernel_path) {
if json {
output::print_json(&json!({"success": false, "error": error}));
@@ -139,7 +177,7 @@ pub fn execute(
// current target artifact, check the exact grant and reject duplicate
// names/kinds *before* any provider or plugin worker process is spawned
// (RFC-EXT-0001 §5.4.6/§18.2 T6–T7).
let providers = match provider_manifest::read_provider_manifests(&settings.providers) {
let providers = match provider_manifest::read_provider_manifests(&provider_paths) {
Ok(providers) => providers,
Err(error) => {
emit_prepare_error(json, command_name, &error);