Land quantum Q4 visuals and gate Stream to LLM/agent imports.

Add probs/Bloch draw kinds and matches_matrix, plus feature docs; hide the view Stream panel unless llm/agent is imported, and stop rewriting method names like 绘图 through host_plot aliases.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-12 12:36:51 +08:00
1 parent 25b7be6739
commit eea6fe1a0e
20 files changed
+852 -23

No files matched your search

+2 -1
View File
@@ -517,7 +517,8 @@ impl Interpreter {
call: &CallExpr,
) -> Result<Value> {
let mut call = call.clone();
if call.path.is_none() {
// Method callees keep author names (`绘图` on quantum ≠ math `host_plot`).
if call.path.is_none() && call.receiver.is_none() {
let callee = crate::aliases::normalize_call_callee_and_args(
&call.callee,
&mut call.args,
+9 -4
View File
@@ -1839,8 +1839,13 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
(
"pending",
"input",
"Fill preset input, then <strong>Run with input</strong> — output streams in the panel (no page reload)."
.to_string(),
if vm.show_stream {
"Fill preset input, then <strong>Run with input</strong> — output streams in the panel (no page reload)."
.to_string()
} else {
"Fill preset input, then <strong>Run with input</strong>."
.to_string()
},
)
} else if vm.auto_stream {
(
@@ -1949,7 +1954,7 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
};
let plan_card = plan_result_card(&vm.stdout, links);
let stream_panel = match links {
LinkMode::Live => r#"<div class="stream-panel">
LinkMode::Live if vm.show_stream => r#"<div class="stream-panel">
<div class="stream-head">
<strong>Stream</strong>
<button type="button" id="stream-run">Run</button>
@@ -1962,7 +1967,7 @@ pub fn page_file(files: &[PathBuf], rel: &str, vm: &FileViewModel, links: &LinkM
<button type="button" class="stream-jump" id="stream-jump" hidden>↓ Latest</button>
</div>"#
.to_string(),
LinkMode::Static { .. } => String::new(),
_ => String::new(),
};
let main = format!(
r#"
+12 -4
View File
@@ -25,7 +25,7 @@ use crate::view::debug_page::{build_debug_model, page_debug};
use crate::view::html::{escape, page_file, page_index, LinkMode};
use crate::view::render::{
collect_input_prompts, render_bindings_html, render_module_structure, render_right_rail,
FileViewModel,
uses_stream_panel, FileViewModel,
};
use crate::{run_file_capture, RunOptions};
@@ -329,9 +329,16 @@ pub(crate) fn build_file_view(
};
let effective = effective_stdin(&source, stdin_lines);
let awaiting_input = awaiting_preset_input(&input_prompts, stdin_lines, &source);
// Live + has `input` + stdin ready → stream via client `/api/run` (no page-blocking capture).
let auto_stream =
live && !input_prompts.is_empty() && !awaiting_input && !stdin_lines.is_empty();
let show_stream = module_opt
.as_ref()
.map(uses_stream_panel)
.unwrap_or(false);
// Live + LLM/agent import + has `input` + stdin ready → stream via client `/api/run`.
let auto_stream = live
&& show_stream
&& !input_prompts.is_empty()
&& !awaiting_input
&& !stdin_lines.is_empty();
// Same host caps as `marqdo run`. Soft exit + sleep clamp only.
let mut opts = RunOptions::default();
opts.stdin_lines = effective.clone();
@@ -397,6 +404,7 @@ pub(crate) fn build_file_view(
input_prompts,
awaiting_input,
auto_stream,
show_stream,
plots,
bindings_html: std::mem::take(&mut bindings_html),
})
+33
View File
@@ -39,6 +39,8 @@ pub struct FileViewModel {
pub awaiting_input: bool,
/// Live view: stdin present — skip blocking page-load run; client auto-starts Stream SSE.
pub auto_stream: bool,
/// Show the LLM/agent Stream panel (live view only; gated on ext llm/agent import).
pub show_stream: bool,
/// SVG plots from math lib (embedded in Execution).
pub plots: Vec<String>,
/// HTML for Variables panel (entry bindings after run).
@@ -54,6 +56,28 @@ pub fn collect_input_prompts(module: &Module) -> Vec<String> {
out
}
/// Stream panel is for LLM/agent token streaming — only when those ext packages are imported.
pub fn uses_stream_panel(module: &Module) -> bool {
module.imports.iter().any(|imp| import_enables_stream(&imp.path))
}
fn import_enables_stream(path: &str) -> bool {
let norm = path.replace('\\', "/");
let lower = norm.to_ascii_lowercase();
lower.contains("ext/ai/llm")
|| lower.contains("/llm.mq.md")
|| lower.ends_with("llm.mq.md")
|| lower.contains("ext/llm")
|| norm.contains("ext/ai/大模型")
|| norm.contains("大模型.mq.md")
|| lower.contains("ext/ai/agent")
|| lower.contains("/agent.mq.md")
|| lower.ends_with("agent.mq.md")
|| lower.contains("ext/agent")
|| norm.contains("ext/ai/智能体")
|| norm.contains("智能体.mq.md")
}
fn collect_input_prompts_fun(fun: &Function, out: &mut Vec<String>) {
for stmt in &fun.body {
collect_input_prompts_stmt(stmt, out);
@@ -1199,4 +1223,13 @@ mod tests {
assert!(html.contains("vars-table"), "{html}");
assert!(html.contains(">xs<") || html.contains("vars-name\">xs"), "{html}");
}
#[test]
fn stream_panel_gated_on_llm_or_agent_import() {
let hello = crate::parse::parse_source(include_str!("../../tests/structure/hello.mq.md"))
.unwrap();
assert!(!uses_stream_panel(&hello));
let llm = crate::parse::parse_source(include_str!("../../tests/ext/llm-import.mq.md")).unwrap();
assert!(uses_stream_panel(&llm));
}
}