From fae0cd4b18b5b4bd072ef2c1d6aa7f04378db39e Mon Sep 17 00:00:00 2001 From: cflmy Date: Fri, 20 Nov 2026 10:56:26 +0800 Subject: [PATCH] fix(host,cli): enforce console capability and label call --json output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - host: `打印` checks the console capability at the execution point (pure and project modes grant it, but the boundary is now real instead of decorative). - cli: `marqdo call --json` reports "command":"call" instead of "run". --- crates/cli/src/commands.rs | 7 ++++--- crates/marqdo-host/src/host.rs | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/commands.rs b/crates/cli/src/commands.rs index ae89a7d..c8f7429 100644 --- a/crates/cli/src/commands.rs +++ b/crates/cli/src/commands.rs @@ -485,6 +485,7 @@ pub fn execute( json: bool, trace: bool, ) -> i32 { + let command_name = if function.is_some() { "call" } else { "run" }; let project = match load_project(file, json) { Ok(project) => project, Err(code) => return code, @@ -492,7 +493,7 @@ pub fn execute( if project.has_errors() { if json { output::print_json(&json!({ - "command": "run", + "command": command_name, "success": false, "diagnostics": output::diagnostics_json(&project.diagnostics), })); @@ -589,7 +590,7 @@ pub fn execute( Ok(outcome) => { if json { output::print_json(&json!({ - "command": "run", + "command": command_name, "success": true, "value": marqdo_value::to_wire(&outcome.value), "stdout": stdout_text, @@ -616,7 +617,7 @@ pub fn execute( Err(error) => { if json { output::print_json(&json!({ - "command": "run", + "command": command_name, "success": false, "stdout": stdout_text, "error": runtime_error_json(&error, &project), diff --git a/crates/marqdo-host/src/host.rs b/crates/marqdo-host/src/host.rs index 5f6cfa0..cefe6e9 100644 --- a/crates/marqdo-host/src/host.rs +++ b/crates/marqdo-host/src/host.rs @@ -254,6 +254,13 @@ impl StdHost { args: Vec, ctx: &ExecutionContext, ) -> Result { + if !self.capabilities.console { + return Err(RuntimeError::new( + ErrorCategory::PermissionDenied, + ctx.span, + "program output (console) capability was not granted", + )); + } if args.len() != 1 { return Err(arity(ctx.span, "打印", 1, args.len())); }