Add ext/web with table-driven pages and polished admin CRUD.

Ship the web L1/plugin stack (bind tables, variable-named db.init, live render) and tighten the admin UI with sidebar, toolbar, forms, and activity log.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-11 11:42:17 +08:00
1 parent ab8ea8438f
commit 8041a2274c
26 files changed
+5689 -242

No files matched your search

+75 -41
View File
@@ -30,6 +30,12 @@ pub const CATALOG: &[ExtPackage] = &[
mq_files: &["ai/agent.mq.md", "ai/智能体.mq.md"],
native_crate: Some("marqdo_plugin_agent"),
},
ExtPackage {
id: "web",
description: "Dynamic website toolkit (ext/web) — page/db/bind/admin",
mq_files: &["web/web.mq.md", "web/网页.mq.md"],
native_crate: Some("marqdo_plugin_web"),
},
];
pub fn find_package(id: &str) -> Option<&'static ExtPackage> {
@@ -76,13 +82,29 @@ pub fn trusted_plugin_roots() -> Vec<PathBuf> {
roots
}
pub fn native_lib_filename() -> &'static str {
pub fn native_short_name(crate_or_id: &str) -> &str {
match crate_or_id {
"marqdo_plugin_agent" | "agent" => "agent",
"marqdo_plugin_web" | "web" => "web",
other => other,
}
}
pub fn native_lib_filename(short: &str) -> String {
let short = native_short_name(short);
if cfg!(windows) {
"agent.dll"
format!("{short}.dll")
} else if cfg!(target_os = "macos") {
"libagent.dylib"
format!("lib{short}.dylib")
} else {
"libagent.so"
format!("lib{short}.so")
}
}
pub fn native_env_var(short: &str) -> &'static str {
match native_short_name(short) {
"web" => "MARQDO_WEB_PLUGIN",
_ => "MARQDO_AGENT_PLUGIN",
}
}
@@ -148,10 +170,12 @@ fn find_source_file(name: &str) -> Result<PathBuf> {
);
}
fn find_native_plugin() -> Result<PathBuf> {
let name = native_lib_filename();
fn find_native_plugin(short: &str) -> Result<PathBuf> {
let short = native_short_name(short);
let name = native_lib_filename(short);
let env_key = native_env_var(short);
let mut candidates = Vec::new();
if let Ok(p) = env::var("MARQDO_AGENT_PLUGIN") {
if let Ok(p) = env::var(env_key) {
let p = PathBuf::from(p);
if p.is_file() {
return Ok(p);
@@ -160,27 +184,27 @@ fn find_native_plugin() -> Result<PathBuf> {
}
if let Ok(h) = env::var("MARQDO_EXT_SOURCE") {
let base = PathBuf::from(h);
candidates.push(base.join("native").join(name));
candidates.push(base.join(name));
candidates.push(base.join("native").join(&name));
candidates.push(base.join(&name));
}
// Honor CARGO_TARGET_DIR (sandbox / custom target roots) before cwd/target.
if let Ok(td) = env::var("CARGO_TARGET_DIR") {
let td = PathBuf::from(td);
candidates.push(td.join("debug").join(name));
candidates.push(td.join("release").join(name));
candidates.push(td.join("debug").join(&name));
candidates.push(td.join("release").join(&name));
}
if let Ok(cwd) = env::current_dir() {
candidates.push(cwd.join("target").join("debug").join(name));
candidates.push(cwd.join("target").join("release").join(name));
candidates.push(cwd.join("ext").join("native").join(name));
candidates.push(cwd.join("target").join("debug").join(&name));
candidates.push(cwd.join("target").join("release").join(&name));
candidates.push(cwd.join("ext").join("native").join(&name));
}
if let Ok(exe) = env::current_exe() {
if let Some(dir) = exe.parent() {
candidates.push(dir.join("ext").join("native").join(name));
candidates.push(dir.join("ext").join("native").join(&name));
// Same directory as the marqdo binary (typical: target/debug/).
candidates.push(dir.join(name));
candidates.push(dir.join(&name));
// target/debug/deps → target/debug
candidates.push(dir.join("..").join(name));
candidates.push(dir.join("..").join(&name));
}
}
for p in &candidates {
@@ -189,7 +213,7 @@ fn find_native_plugin() -> Result<PathBuf> {
}
}
bail!(
"cannot find native plugin `{name}` (run `cargo build -p marqdo_plugin_agent`, or `marqdo ext add agent`, or set MARQDO_AGENT_PLUGIN)"
"cannot find native plugin `{name}` (run `cargo build -p marqdo_plugin_{short}`, or `marqdo ext add {short}`, or set {env_key})"
);
}
@@ -220,11 +244,13 @@ pub fn add_ext(id: &str) -> Result<()> {
println!("installed {}", dest.display());
}
if pkg.native_crate.is_some() {
let src = find_native_plugin()?;
if let Some(crate_name) = pkg.native_crate {
let short = native_short_name(crate_name);
let lib_name = native_lib_filename(short);
let src = find_native_plugin(short)?;
let native_dir = root.join("native");
fs::create_dir_all(&native_dir)?;
let dest = native_dir.join(native_lib_filename());
let dest = native_dir.join(&lib_name);
fs::copy(&src, &dest)
.with_context(|| format!("copy {} → {}", src.display(), dest.display()))?;
println!("installed {}", dest.display());
@@ -232,11 +258,12 @@ pub fn add_ext(id: &str) -> Result<()> {
let abs = dest
.canonicalize()
.unwrap_or_else(|_| dest.clone());
let hint = root.join("agent.plugin");
let hint = root.join(format!("{short}.plugin"));
fs::write(&hint, abs.to_string_lossy().as_bytes())?;
println!("wrote {}", hint.display());
println!(
"hint: import works via install root; set MARQDO_AGENT_PLUGIN={} if load_native needs it",
"hint: import works via install root; set {}={} if load_native needs it",
native_env_var(short),
abs.display()
);
}
@@ -263,14 +290,15 @@ pub fn remove_ext(id: &str) -> Result<()> {
removed += 1;
}
}
if pkg.native_crate.is_some() {
let dest = root.join("native").join(native_lib_filename());
if let Some(crate_name) = pkg.native_crate {
let short = native_short_name(crate_name);
let dest = root.join("native").join(native_lib_filename(short));
if dest.is_file() {
fs::remove_file(&dest)?;
println!("removed {}", dest.display());
removed += 1;
}
let hint = root.join("agent.plugin");
let hint = root.join(format!("{short}.plugin"));
if hint.is_file() {
fs::remove_file(&hint)?;
removed += 1;
@@ -282,32 +310,34 @@ pub fn remove_ext(id: &str) -> Result<()> {
Ok(())
}
/// Resolve installed native plugin path for `name` (currently only `agent`).
/// Resolve installed native plugin path for `name` (`agent`, `web`, …).
/// Also falls back to cargo `target/{debug,release}` artifacts for local runs.
pub fn installed_native_path(name: &str) -> Option<PathBuf> {
if name != "agent" {
let short = native_short_name(name);
if !matches!(short, "agent" | "web") {
return None;
}
let lib_name = native_lib_filename(short);
for root in trusted_plugin_roots() {
let hint = root.join("agent.plugin");
let hint = root.join(format!("{short}.plugin"));
if let Ok(s) = fs::read_to_string(&hint) {
let p = PathBuf::from(s.trim());
if p.is_file() {
return Some(p);
}
}
let p = root.join("native").join(native_lib_filename());
let p = root.join("native").join(&lib_name);
if p.is_file() {
return Some(p);
}
}
if let Ok(p) = env::var("MARQDO_AGENT_PLUGIN") {
if let Ok(p) = env::var(native_env_var(short)) {
let p = PathBuf::from(p);
if p.is_file() {
return Some(p);
}
}
find_native_plugin().ok()
find_native_plugin(short).ok()
}
pub fn path_is_trusted_plugin(path: &Path) -> bool {
@@ -323,17 +353,21 @@ pub fn path_is_trusted_plugin(path: &Path) -> bool {
return true;
}
}
if let Ok(p) = env::var("MARQDO_AGENT_PLUGIN") {
let p = PathBuf::from(p);
let p = p.canonicalize().unwrap_or(p);
if p == path {
return true;
for key in ["MARQDO_AGENT_PLUGIN", "MARQDO_WEB_PLUGIN"] {
if let Ok(p) = env::var(key) {
let p = PathBuf::from(p);
let p = p.canonicalize().unwrap_or(p);
if p == path {
return true;
}
}
}
if let Ok(found) = find_native_plugin() {
let found = found.canonicalize().unwrap_or(found);
if found == path {
return true;
for short in ["agent", "web"] {
if let Ok(found) = find_native_plugin(short) {
let found = found.canonicalize().unwrap_or(found);
if found == path {
return true;
}
}
}
false