Make file subtasks return #main value and expose it as plan.result.

Quiet spawn still hides child stdout; workbooks solidify to **returns**, agent-kb lives in the plugin, and multi-step follows OKF file relay rather than print-based answers.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-07 17:53:14 +08:00
1 parent fbece725e1
commit d1b33c78c6
55 files changed
+3498 -169

No files matched your search

+96 -2
View File
@@ -16,11 +16,18 @@ pub fn parse_expr(input: &str) -> Result<Expr> {
/// Argument / template RHS: prefer a full expression; else interpolated text.
/// Hyphenated prose (`none-falsy`) is not parsed as subtraction.
/// Quoted `"..."` always uses the expression parser (never the hyphen short-circuit).
pub fn parse_value_or_interp(input: &str) -> Result<Expr> {
let s = input.trim();
if s.is_empty() {
return Ok(Expr::Literal(Literal::Text(String::new())));
}
if s.starts_with('"') {
return match parse_expr(s) {
Ok(e) => Ok(e),
Err(_) => Ok(parse_interp(s)),
};
}
if has_hyphenated_prose(s) {
return Ok(parse_interp(s));
}
@@ -30,6 +37,60 @@ pub fn parse_value_or_interp(input: &str) -> Result<Expr> {
}
}
/// Call-arg / param-default values: like [`parse_value_or_interp`], but also treat a chain of
/// unspaced `Text / Text` divisions as a single path string (`a/b`, `.marqdo/agent-kb`).
/// Real math (`1/2`, `` `n` / 2 ``) is unchanged.
pub fn parse_call_arg_value(input: &str) -> Result<Expr> {
let s = input.trim();
if s.is_empty() {
return Ok(Expr::Literal(Literal::Text(String::new())));
}
if s.starts_with('"') {
return match parse_expr(s) {
Ok(e) => Ok(e),
Err(_) => Ok(parse_interp(s)),
};
}
if has_hyphenated_prose(s) {
return Ok(parse_interp(s));
}
match parse_expr(s) {
Ok(e) => Ok(collapse_text_div_path(e, s)),
Err(_) => Ok(parse_interp(s)),
}
}
fn is_text_only_div_chain(e: &Expr) -> bool {
match e {
Expr::Literal(Literal::Text(_)) => true,
Expr::Binary {
op: BinaryOp::Div,
left,
right,
} => is_text_only_div_chain(left) && matches!(right.as_ref(), Expr::Literal(Literal::Text(_))),
_ => false,
}
}
fn expr_has_div(e: &Expr) -> bool {
match e {
Expr::Binary {
op: BinaryOp::Div, ..
} => true,
Expr::Binary { left, right, .. } => expr_has_div(left) || expr_has_div(right),
Expr::Unary { expr, .. } => expr_has_div(expr),
_ => false,
}
}
fn collapse_text_div_path(e: Expr, raw: &str) -> Expr {
if expr_has_div(&e) && is_text_only_div_chain(&e) {
parse_interp(raw)
} else {
e
}
}
fn has_hyphenated_prose(s: &str) -> bool {
let chars: Vec<char> = s.chars().collect();
for i in 1..chars.len().saturating_sub(1) {
@@ -472,7 +533,7 @@ pub fn parse_call_tail(s: &str) -> Result<(CallExpr, usize)> {
let val_raw = after_eq[..val_end].trim_end();
args.push(Arg::Named {
name: key,
value: parse_value_or_interp(val_raw)?,
value: parse_call_arg_value(val_raw)?,
});
args_str = after_eq[val_end..].trim_start();
} else {
@@ -483,7 +544,7 @@ pub fn parse_call_tail(s: &str) -> Result<(CallExpr, usize)> {
if tok.is_empty() {
break;
}
args.push(Arg::Positional(parse_value_or_interp(tok)?));
args.push(Arg::Positional(parse_call_arg_value(tok)?));
args_str = rest.trim_start();
}
}
@@ -675,6 +736,37 @@ mod tests {
assert!(matches!(e, Expr::Interp(_)));
}
#[test]
fn call_arg_quoted_path_keeps_slashes() {
let e = parse_call_arg_value("\".marqdo/agent-runs\"").unwrap();
assert!(matches!(
e,
Expr::Literal(Literal::Text(ref s)) if s == ".marqdo/agent-runs"
));
let e = parse_value_or_interp("\".marqdo/agent-kb\"").unwrap();
assert!(matches!(
e,
Expr::Literal(Literal::Text(ref s)) if s == ".marqdo/agent-kb"
));
}
#[test]
fn call_arg_bare_path_not_division() {
let e = parse_call_arg_value("a/b/c").unwrap();
assert!(matches!(
e,
Expr::Literal(Literal::Text(ref s)) if s == "a/b/c"
));
let e = parse_call_arg_value("1/2").unwrap();
assert!(matches!(
e,
Expr::Binary {
op: BinaryOp::Div,
..
}
));
}
#[test]
fn bare_token_no_escape() {
let e = parse_expr("a\\nb").unwrap();
@@ -698,3 +790,5 @@ mod tests {
));
}
}
+79 -5
View File
@@ -2,7 +2,7 @@
mod expr;
pub use expr::{parse_call_after_gt, parse_expr, parse_value_or_interp};
pub use expr::{parse_call_after_gt, parse_call_arg_value, parse_expr, parse_value_or_interp};
use anyhow::{bail, Result};
@@ -521,14 +521,17 @@ impl<'a> Cursor<'a> {
break;
}
let trimmed = l.text.trim();
let cond_src = if let Some(rest) = strip_ordered(trimmed) {
rest
} else {
let Some(num) = ordered_item_number(trimmed) else {
break;
};
if ind != base_indent {
break;
}
// Same-indent restart at `1.` begins a new Branch statement.
if !arms.is_empty() && num == 1 {
break;
}
let cond_src = strip_ordered(trimmed).unwrap();
self.bump();
let condition = if cond_src == "*" || cond_src.is_empty() {
@@ -673,7 +676,7 @@ fn parse_param_line(trimmed: &str) -> Option<crate::ast::Param> {
if def_s.is_empty() {
return None;
}
Some(parse_value_or_interp(def_s).ok()?)
Some(parse_call_arg_value(def_s).ok()?)
} else if after.is_empty() {
None
} else {
@@ -843,6 +846,25 @@ fn is_ordered_branch(trimmed: &str) -> bool {
strip_ordered(trimmed).is_some()
}
/// Leading `N` in an ordered-list item `N. …` (1-based Markdown marker).
fn ordered_item_number(trimmed: &str) -> Option<u32> {
let mut chars = trimmed.chars();
let mut n: u32 = 0;
let mut saw_digit = false;
while let Some(c) = chars.next() {
if let Some(d) = c.to_digit(10) {
saw_digit = true;
n = n.saturating_mul(10).saturating_add(d);
continue;
}
if c == '.' && saw_digit {
return Some(n);
}
return None;
}
None
}
fn strip_ordered(trimmed: &str) -> Option<&str> {
let mut chars = trimmed.chars();
let mut saw_digit = false;
@@ -956,6 +978,58 @@ mod tests {
assert!(main.body.iter().any(|s| matches!(s, Stmt::Branch { .. })));
}
#[test]
fn consecutive_branches_restart_at_one() {
let m = parse_source(include_str!(
"../../tests/structure/branch-consecutive.mq.md"
))
.unwrap();
let branches: Vec<_> = m.functions[0]
.body
.iter()
.filter(|s| matches!(s, Stmt::Branch { .. }))
.collect();
assert_eq!(
branches.len(),
3,
"expected three Branch stmts, got {:?}",
m.functions[0].body
);
for b in &branches {
match b {
Stmt::Branch { arms, .. } => assert_eq!(arms.len(), 2),
_ => unreachable!(),
}
}
// Arm bodies must hold the prints (not leaked as sibling Calls).
match branches[0] {
Stmt::Branch { arms, .. } => {
assert!(
matches!(arms[0].body[0], Stmt::Call { .. }),
"first arm body={:?}",
arms[0].body
);
}
_ => unreachable!(),
}
}
#[test]
fn consecutive_branches_without_blank_line() {
let src = "# main\n\n1. True\n > print text=A\n2. *\n > print text=skip\n1. True\n > print text=B\n";
let m = parse_source(src).unwrap();
let branches: Vec<_> = m.functions[0]
.body
.iter()
.filter(|s| matches!(s, Stmt::Branch { .. }))
.collect();
assert_eq!(branches.len(), 2, "got {:?}", m.functions[0].body);
match branches[0] {
Stmt::Branch { arms, .. } => assert_eq!(arms.len(), 2),
_ => unreachable!(),
}
}
#[test]
fn parse_formula_assign_fence() {
let src = "# main\n\n`f` =\n$$\nx^2 - 2\n$$\n\n> print text=`f`\n";