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

+30
View File
@@ -0,0 +1,30 @@
---
title: agent inspect_workbook (offline)
description: Parse named writeback slots from a fixture workbook path.
> ext/ai/agent.mq.md
> lib/json.mq.md
> lib/fs.mq.md
---
# main
*`paths` = > json.parse text={"f":".marqdo/agent-runs/inspect-fixture.mq.md"} *
*`fixture` = > json.get value=`paths` key=f *
*`body` = > json.parse text={"t":"# main\n\n> print text=hi\n<!-- marqdo-out ok\n{\"status\":\"ok\",\"result\":\"done\"}\n-->\n<!-- marqdo-out error\npending\n-->\n"} *
*`t` = > json.get value=`body` key=t *
> fs.write_text path=`fixture` text=`t`
*`obs` = > agent.inspect_workbook path=`fixture` exit_code=0 *
*`code` = > json.get value=`obs` key=exit_code *
> print text=`code`
*`ok` = > json.get value=`obs` key=last_ok *
*`has` = > split value=`ok` sep=done *
*`n` = > len value=`has` *
1. `n` > 1
> print text=ok-slot
2. *
> print text=ok-missing
*`err` = > json.get value=`obs` key=last_error *
> print text=`err`
+67
View File
@@ -0,0 +1,67 @@
---
title: OKF agent-kb promote + lookup + spawn (offline)
description: Promote a solidified workbook, lookup by goal, spawn without parent LLM.
> ext/ai/agent.mq.md
> lib/fs.mq.md
> lib/json.mq.md
> lib/subtask.mq.md
> lib/plugin.mq.md
> lib/sys.mq.md
---
# main
*`p` = > plugin.native_path name=agent *
1. `p`
> plugin.load path=`p`
2. *
> print text=no-agent-plugin
> sys.exit code=1
*`paths` = > json.parse text={"kb":".marqdo/agent-kb","wb":".marqdo/agent-runs/pong-solid.mq.md","goal":"Reply with exactly the word pong and nothing else.","body":"---\ntitle: pong skill\n---\n\n# main\n\n**pong**\n"} *
*`kb` = > json.get value=`paths` key=kb *
*`wb` = > json.get value=`paths` key=wb *
*`goal` = > json.get value=`paths` key=goal *
*`body` = > json.get value=`paths` key=body *
> fs.write_text path=`wb` text=`body`
*`sig` = > agent_goal_sig goal=`goal` *
> print text=`sig`
*`slug0` = > agent_goal_slug goal=`goal` *
> print text=`slug0`
*`prom` = > agent_kb_promote kb_dir=`kb` goal=`goal` workbook=`wb` *
*`okp` = > json.get value=`prom` key=promoted *
1. `okp`
> print text=promoted
2. *
> print text=promote-fail
*`st` = > json.get value=`prom` key=status *
> print text=`st`
*`slug` = > json.get value=`prom` key=slug *
> print text=`slug`
*`hit` = > agent_kb_lookup kb_dir=`kb` goal=`goal` *
1. `hit`
> print text=lookup-ok
2. *
> print text=lookup-miss
*`res` = > json.get value=`hit` key=resource *
*`id` = > subtask.spawn path=`res` *
*`waited` = > subtask.wait id=`id` *
*`code` = > json.get value=`waited` key=code *
*`val` = > json.get value=`waited` key=value *
> print text=`code`
> print text=`val`
*`hit2` = > agent_kb_lookup kb_dir=`kb` goal=`goal` *
*`res2` = > json.get value=`hit2` key=resource *
1. `res` == `res2`
> print text=stable-path
2. *
> print text=path-drift
+36
View File
@@ -0,0 +1,36 @@
---
title: agent plan confirm (offline)
description: Create workbook skeleton with confirm=True; no LLM spawn loop.
> ext/ai/llm.mq.md
> ext/ai/agent.mq.md
> lib/json.mq.md
> lib/fs.mq.md
---
# main
> llm.load_env path=.env
*`model` = > llm.llm *
*`tools` = > json.parse text=[] *
*`助手` = > agent.agent model=`model` tools=`tools` standing=offline plan confirm *
*`out` = > `助手`.plan goal=say hi confirm=True workbook_dir=".marqdo/agent-runs" writeback=False *
*`st` = > json.get value=`out` key=status *
> print text=`st`
*`path` = > json.get value=`out` key=workbook *
*`ex` = > fs.exists path=`path` *
1. `ex`
> print text=workbook-ok
2. *
> print text=workbook-missing
*`src` = > fs.read_text path=`path` *
*`parts` = > split value=`src` sep=agent.agent *
*`n` = > len value=`parts` *
1. `n` > 1
> print text=skeleton-ok
2. *
> print text=skeleton-bad
+48
View File
@@ -0,0 +1,48 @@
---
title: agent plan decision + dual skeleton (offline)
description: extract_plan_decision/summary; dual skeleton contains research+writer; patch apply on fixture.
> ext/ai/agent.mq.md
> lib/json.mq.md
> lib/fs.mq.md
---
# main
*`samples` = > json.parse text={"done":"DECISION: DONE\nSUMMARY: all good\n","cont":"DECISION: CONTINUE\nPATCH:\n<<<\nFIND\nold\n===\nREPLACE\nnew\n>>>\n","zh":"决定:完成\n汇总:好了\n"} *
*`d1` = > json.get value=`samples` key=done *
*`r1` = > agent.extract_plan_decision reply=`d1` *
> print text=`r1`
*`s1` = > agent.extract_plan_summary reply=`d1` *
> print text=`s1`
*`d2` = > json.get value=`samples` key=cont *
*`r2` = > agent.extract_plan_decision reply=`d2` *
> print text=`r2`
*`d3` = > json.get value=`samples` key=zh *
*`r3` = > agent.extract_plan_decision reply=`d3` *
> print text=`r3`
*`dual` = > agent.render_workbook_skeleton goal=demo skeleton=dual *
*`has_r` = > split value=`dual` sep=research *
*`n_r` = > len value=`has_r` *
1. `n_r` > 1
> print text=dual-ok
2. *
> print text=dual-missing
*`has_s` = > split value=`dual` sep=Solidify *
*`n_s` = > len value=`has_s` *
1. `n_s` > 1
> print text=solidify-ok
2. *
> print text=solidify-missing
*`paths` = > json.parse text={"p":".marqdo/agent-runs/decision-patch.md","t":"keep old keep"} *
*`path` = > json.get value=`paths` key=p *
*`seed` = > json.get value=`paths` key=t *
> fs.write_text path=`path` text=`seed`
*`n` = > fs.apply_patch_blocks path=`path` text=`d2` *
> print text=`n`
*`out` = > fs.read_text path=`path` *
> print text=`out`
+43
View File
@@ -0,0 +1,43 @@
---
title: ext/agent plan live (DeepSeek)
description: Full plan loop — spawn workbook, inspect, secondary plan; simple pong goal.
> ext/ai/llm.mq.md
> ext/ai/agent.mq.md
> lib/json.mq.md
> lib/fs.mq.md
---
# main
> llm.load_env path=.env
*`model` = > llm.llm *
*`tools` = > json.parse text=[] *
*`助手` = > agent.agent model=`model` tools=`tools` standing=You are a Marqdo agent-development master. Prefer DONE when the workbook already satisfies the goal. *
*`out` = > `助手`.plan goal=Reply with exactly the word pong and nothing else. max_rounds=3 writeback=False *
*`st` = > json.get value=`out` key=status *
> print text=`st`
*`sum` = > json.get value=`out` key=summary *
1. `sum`
> print text=`sum`
2. *
> print text=no-summary
*`cache` = > json.get value=`out` key=cache *
> print text=`cache`
*`path` = > json.get value=`out` key=workbook *
*`ex` = > fs.exists path=`path` *
1. `ex`
> print text=workbook-ok
2. *
> print text=workbook-missing
*`out2` = > `助手`.plan goal=Reply with exactly the word pong and nothing else. max_rounds=3 writeback=False *
*`st2` = > json.get value=`out2` key=status *
> print text=`st2`
*`cache2` = > json.get value=`out2` key=cache *
> print text=`cache2`
+23
View File
@@ -0,0 +1,23 @@
---
title: fs text_patch / apply_patch_blocks (offline)
> lib/fs.mq.md
> lib/json.mq.md
---
# main
*`paths` = > json.parse text={"p":".marqdo/agent-runs/patch-demo.md","t":"alpha beta gamma"} *
*`path` = > json.get value=`paths` key=p *
*`seed` = > json.get value=`paths` key=t *
> fs.write_text path=`path` text=`seed`
> fs.text_patch path=`path` find=beta replace=BETA
*`s1` = > fs.read_text path=`path` *
> print text=`s1`
*`reply` = > json.parse text={"t":"DECISION: CONTINUE\n<<<\nFIND\nalpha\n===\nREPLACE\nALPHA\n>>>\n<<<\nFIND\ngamma\n===\nREPLACE\nGAMMA\n>>>\n"} *
*`t` = > json.get value=`reply` key=t *
*`n` = > fs.apply_patch_blocks path=`path` text=`t` *
> print text=`n`
*`s2` = > fs.read_text path=`path` *
> print text=`s2`
+207 -4
View File
@@ -85,6 +85,14 @@ fn structure_branch() {
assert_out("tests/structure/branch.mq.md", "零");
}
#[test]
fn structure_branch_consecutive() {
assert_out(
"tests/structure/branch-consecutive.mq.md",
"A\nB\nelse-ok",
);
}
#[test]
fn structure_loop() {
assert_out(
@@ -452,6 +460,15 @@ fn bytecode_branch() {
assert_out_backend("tests/structure/branch.mq.md", "bytecode", "零");
}
#[test]
fn bytecode_branch_consecutive() {
assert_out_backend(
"tests/structure/branch-consecutive.mq.md",
"bytecode",
"A\nB\nelse-ok",
);
}
#[test]
fn bytecode_loop() {
assert_out_backend(
@@ -591,10 +608,92 @@ fn catalog_writes_yaml() {
assert!(yaml.contains("type: Marqdo Catalog"));
assert!(yaml.contains("structure/hello"));
assert!(yaml.contains("utils.mq.md"), "{yaml}");
assert!(yaml.contains("concepts:"), "{yaml}");
let index = std::fs::read_to_string(dir.join("index.md")).unwrap();
assert!(index.contains("## Modules"), "{index}");
assert!(index.contains("## Agent knowledge"), "{index}");
// Import graph: structure/import/main depends on utils — clickable on module page.
let import_page = std::fs::read_to_string(
dir.join("modules")
.join("structure__import__main.md"),
)
.unwrap();
assert!(
yaml.contains("???????") || yaml.contains("imports:
- utils.mq.md"),
"{yaml}"
import_page.contains("](") && import_page.contains("utils"),
"depends should link to utils module: {import_page}"
);
}
#[test]
fn ext_mq_md_never_calls_host() {
// Hard rule: ext/**/*.mq.md must not invoke host_* (use lib/* or plugin names).
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("ext");
let mut offenders = Vec::new();
fn walk(dir: &std::path::Path, out: &mut Vec<String>) {
let Ok(rd) = std::fs::read_dir(dir) else {
return;
};
for ent in rd.flatten() {
let p = ent.path();
if p.is_dir() {
walk(&p, out);
continue;
}
let name = p.file_name().and_then(|n| n.to_str()).unwrap_or("");
if !name.ends_with(".mq.md") {
continue;
}
let Ok(src) = std::fs::read_to_string(&p) else {
continue;
};
for (i, line) in src.lines().enumerate() {
let t = line.trim_start();
// Executable call lines / bindings that invoke host_*.
if (t.starts_with('>') || t.starts_with('*')) && t.contains("host_") {
out.push(format!("{}:{}: {line}", p.display(), i + 1));
}
}
}
}
walk(&root, &mut offenders);
assert!(
offenders.is_empty(),
"ext must not call host_* (use lib/* or agent_* plugin names):\n{}",
offenders.join("\n")
);
}
#[test]
fn catalog_includes_agent_kb_concepts() {
let dir = tempfile_dir("mq-cat-kb");
// Ensure a concept exists under tests/ext agent-kb (offline reuse test leaves one).
let (code, _, stderr) = run(&[
"run",
"tests/ext/agent-kb-reuse.mq.md",
]);
assert_eq!(code, 0, "seed kb via reuse test: {stderr}");
let (code, _, stderr) = run(&[
"catalog",
"tests/ext",
"-o",
dir.to_str().unwrap(),
]);
assert_eq!(code, 0, "{stderr}");
let yaml = std::fs::read_to_string(dir.join("catalog.yaml")).unwrap();
assert!(
yaml.contains("Marqdo Task") || yaml.contains("Marqdo Agent Skill"),
"expected agent-kb concepts in catalog: {yaml}"
);
assert!(
dir.join("concepts").join("tasks").exists()
|| dir.join("concepts").join("skills").exists(),
"concepts should be copied into catalog out dir"
);
let index = std::fs::read_to_string(dir.join("index.md")).unwrap();
assert!(
!index.contains("No `.marqdo/agent-kb` concepts"),
"{index}"
);
}
@@ -687,7 +786,7 @@ fn lib_writeback_get() {
#[test]
fn lib_subtask_spawn() {
assert_out("tests/lib/subtask-spawn.mq.md", "done");
assert_out("tests/lib/subtask-spawn.mq.md", "child-ok\ndone\nquiet-ok");
}
#[test]
@@ -874,6 +973,55 @@ fn ext_agent_framework_smoke() {
);
}
#[test]
fn ext_fs_text_patch() {
assert_out(
"tests/ext/fs-text-patch.mq.md",
"alpha BETA gamma\n2\nALPHA BETA GAMMA",
);
}
#[test]
fn ext_agent_inspect_workbook() {
assert_out(
"tests/ext/agent-inspect-fixture.mq.md",
"0\nok-slot\npending",
);
}
#[test]
fn ext_agent_plan_confirm() {
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_agent"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build agent plugin");
assert!(status.success(), "failed to build marqdo_plugin_agent");
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["run", "tests/ext/agent-plan-confirm.mq.md"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.expect("run agent-plan-confirm");
let code = output.status.code().unwrap_or(1);
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(code, 0, "agent-plan-confirm stderr={stderr}");
assert_eq!(
stdout.trim_end(),
"pending\nworkbook-ok\nskeleton-ok",
"agent-plan-confirm"
);
}
#[test]
fn ext_agent_plan_decision() {
assert_out(
"tests/ext/agent-plan-decision.mq.md",
"DONE\nall good\nCONTINUE\nDONE\ndual-ok\nsolidify-ok\n1\nkeep new keep",
);
}
#[test]
fn ext_llm_complete_live() {
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
@@ -932,6 +1080,61 @@ fn ext_agent_run_live() {
"writeback must not be printed to stdout"
);
}
#[test]
fn ext_agent_plan_live() {
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_agent"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build agent plugin");
assert!(status.success(), "failed to build marqdo_plugin_agent");
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["run", "tests/ext/agent-plan-live.mq.md"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output()
.expect("run agent-plan-live");
let code = output.status.code().unwrap_or(1);
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert_eq!(code, 0, "agent-plan-live stderr={stderr}");
let lines: Vec<&str> = stdout.trim_end().lines().collect();
assert!(
lines.iter().any(|l| *l == "ok"),
"agent-plan-live missing ok: stdout={stdout}"
);
assert!(
lines.iter().any(|l| *l == "workbook-ok"),
"agent-plan-live missing workbook-ok: stdout={stdout}"
);
assert!(
lines.iter().filter(|l| **l == "hit").count() >= 1,
"agent-plan-live expected OKF hit: stdout={stdout}"
);
}
#[test]
fn ext_agent_kb_reuse() {
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_agent"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build agent plugin");
assert!(status.success(), "failed to build marqdo_plugin_agent");
let goal = "Reply with exactly the word pong and nothing else.";
let mut h: u64 = 5381;
for b in goal.as_bytes() {
h = h.wrapping_mul(33).wrapping_add(u64::from(*b));
}
let sig = format!("{h:016x}")[..12].to_string();
let slug = "reply-with-exactly-the-word-pong-and-nothing-els";
// Default file-subtask quiet: no child print on parent stdout; answer via wait.value.
let expect = format!("{sig}\n{slug}\npromoted\nstable\n{slug}\nlookup-ok\n0\npong\nstable-path");
assert_out("tests/ext/agent-kb-reuse.mq.md", &expect);
}
#[test]
fn lib_net_encode() {
assert_out("tests/lib/net-encode.mq.md", "a+b");
+1 -1
View File
@@ -4,4 +4,4 @@ title: subtask child
# main
> print text=child-ok
**child_ok**
+24 -2
View File
@@ -1,12 +1,34 @@
---
title: subtask spawn join
> lib/subtask.mq.md
> lib/json.mq.md
---
# main
*`id` = > subtask.spawn path=subtask-child.mq.md *
*`id` = > subtask.spawn path=subtask-child.mq.md quiet=False *
*`code` = > subtask.wait id=`id` *
*`waited` = > subtask.wait id=`id` *
*`code` = > json.get value=`waited` key=code *
*`val` = > json.get value=`waited` key=value *
1. `code` == 0
> print text=`val`
2. *
> print text=fail
> print text=done
*`id2` = > subtask.spawn path=subtask-child.mq.md *
*`waited2` = > subtask.wait id=`id2` *
*`code2` = > json.get value=`waited2` key=code *
*`val2` = > json.get value=`waited2` key=value *
1. `code2` == 0
1. `val2` == "child-ok"
> print text=quiet-ok
2. *
> print text=quiet-bad-value
2. *
> print text=quiet-fail
+24
View File
@@ -0,0 +1,24 @@
---
title: consecutive branches restart at 1.
description: Same-indent `1.` after a completed list is a new Branch, not more arms.
---
# main
*`a` = True*
*`b` = True*
1. `a`
> print text=A
2. *
> print text=not-A
1. `b`
> print text=B
2. *
> print text=not-B
1. False
> print text=no
2. *
> print text=else-ok