Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e437e2cd3 | ||
|
|
23229a6ac9 | ||
|
|
58b65215a1 | ||
|
|
92c3f80055 | ||
|
|
8a66f803cb | ||
|
|
3ce59a4da8 | ||
|
|
90688741c5 | ||
|
|
70b88b3767 | ||
|
|
f859e6eeea | ||
|
|
6705e2e6b7 | ||
|
|
6e8a62928b | ||
|
|
398a0b7222 | ||
|
|
e8f1a3e126 | ||
|
|
8ea56cbe30 | ||
|
|
8085d06124 | ||
|
|
6f929dc2da | ||
|
|
dd22180269 | ||
|
|
cc48bf6d05 | ||
|
|
19f986953a | ||
|
|
770dee5199 | ||
|
|
f6612813e3 | ||
|
|
643ea06340 | ||
|
|
0cd64a7450 | ||
|
|
981faac022 | ||
|
|
f818834ec1 | ||
|
|
8d47507d15 | ||
|
|
1e1f05c087 | ||
|
|
06e61efc51 | ||
|
|
2dfa0b2a5b | ||
|
|
629ad8ed39 | ||
|
|
ee677478be | ||
|
|
edbf241d99 | ||
|
|
add6a7d32c | ||
|
|
c64ec99115 | ||
|
|
60a3b84a84 | ||
|
|
02a4f2d20d | ||
|
|
88490e3092 | ||
|
|
9031c106a1 | ||
|
|
633436e40f | ||
|
|
cf73fcf1ef | ||
|
|
e48fd5b0f4 | ||
|
|
b2f97e72c3 | ||
|
|
c7c0f66d1f | ||
|
|
d5ab9daebb | ||
|
|
5795236d1f | ||
|
|
e8d6dc92fc | ||
|
|
afe31cb2a8 | ||
|
|
905a67df32 | ||
|
|
f63b7ef48d | ||
|
|
393558ca97 | ||
|
|
0d9bd99fc0 | ||
|
|
a0c779e022 | ||
|
|
a82b6fdde1 | ||
|
|
3613ed7c4e | ||
|
|
9564dff777 | ||
|
|
f56deffefe | ||
|
|
bdedf3ecd8 | ||
|
|
b0ee958fcf | ||
|
|
e64f6b23b4 | ||
|
|
eed4f05ea4 | ||
|
|
d88ed274ed | ||
|
|
7fdd97f675 | ||
|
|
c299efe589 | ||
|
|
b3867c46db | ||
|
|
1a39a53d93 | ||
|
|
6d6f580d24 | ||
|
|
af05f19301 | ||
|
|
3201369470 | ||
|
|
05197378b3 | ||
|
|
f3b3152f07 | ||
|
|
22364f2f1b | ||
|
|
b69a90501d | ||
|
|
7ff881f506 | ||
|
|
9acbe10986 | ||
|
|
81989a26d7 | ||
|
|
cf0ba6dccd | ||
|
|
0de703f86a | ||
|
|
4907f92d84 |
No files matched your search
@@ -0,0 +1,46 @@
|
||||
name: Build cinematic Markdown-to-execution video
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [docs/markdown-execution-cinematic-v2]
|
||||
paths:
|
||||
- "scripts/render-markdown-execution-promo.py"
|
||||
- ".github/workflows/build-markdown-execution-video.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
video:
|
||||
if: github.ref_name == 'docs/markdown-execution-cinematic-v2'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 25
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: true
|
||||
- name: Prepare fonts, Chrome and Python tools
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y -qq ffmpeg fonts-noto-cjk
|
||||
python -m pip install --quiet pillow numpy markdown-it-py selenium
|
||||
google-chrome --version
|
||||
- name: Render promo video from two original images and Marqdo source
|
||||
run: python scripts/render-markdown-execution-promo.py
|
||||
- name: Check resulting video
|
||||
run: |
|
||||
test -s assets/marketing/marqdo-2.7.1-markdown-to-execution.mp4
|
||||
test -s assets/marketing/marqdo-2.7.1-markdown-to-execution-cover.jpg
|
||||
test -s assets/marketing/marqdo-2.7.1-markdown-to-execution.srt
|
||||
ffprobe -v error -show_entries format=duration,size:stream=codec_name,width,height -of json assets/marketing/marqdo-2.7.1-markdown-to-execution.mp4
|
||||
- name: Commit compiled video, poster and subtitles
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add assets/marketing/marqdo-2.7.1-markdown-to-execution.mp4 \
|
||||
assets/marketing/marqdo-2.7.1-markdown-to-execution-cover.jpg \
|
||||
assets/marketing/marqdo-2.7.1-markdown-to-execution.srt \
|
||||
assets/marketing/marqdo-procurement-standard-markdown.png
|
||||
git diff --cached --quiet || git commit -m "docs: publish cinematic Markdown-to-execution promotional film"
|
||||
git push origin HEAD:docs/markdown-execution-cinematic-v2
|
||||
@@ -0,0 +1,48 @@
|
||||
name: capture-procurement-marketing-assets
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [docs/executable-skill-showcase-271]
|
||||
paths:
|
||||
- "scripts/capture-procurement-showcase.py"
|
||||
- ".github/workflows/capture-procurement-marketing.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
capture:
|
||||
if: github.ref_name == 'docs/executable-skill-showcase-271'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: true
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.11"
|
||||
- name: Prepare Chrome, Chinese fonts and Python imaging
|
||||
run: |
|
||||
python -m pip install --quiet pillow selenium
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y -qq fonts-noto-cjk
|
||||
google-chrome --version
|
||||
- name: Download Marqdo v2.7.1 Linux release
|
||||
run: |
|
||||
mkdir -p /tmp/marqdo-marketing-cli
|
||||
curl -fL --retry 3 "https://github.com/cflmy/marqdo/releases/download/v2.7.1/marqdo-2.7.1-x86_64-unknown-linux-gnu.zip" -o /tmp/marqdo-marketing.zip
|
||||
unzip -q /tmp/marqdo-marketing.zip -d /tmp/marqdo-marketing-cli
|
||||
BIN="$(find /tmp/marqdo-marketing-cli -type f -name marqdo | head -n 1)"
|
||||
test -n "$BIN"
|
||||
chmod +x "$BIN"
|
||||
echo "CLI_BIN=$BIN" >> "$GITHUB_ENV"
|
||||
- name: Record real command outputs and capture real View
|
||||
run: python scripts/capture-procurement-showcase.py --cli "$CLI_BIN"
|
||||
- name: Commit reproducible promotional assets
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add assets/marketing/procurement-cli.gif assets/marketing/procurement-view.png
|
||||
git diff --cached --quiet || git commit -m "docs: capture live procurement CLI GIF and View screenshot"
|
||||
git push origin HEAD:docs/executable-skill-showcase-271
|
||||
@@ -15,6 +15,20 @@ jobs:
|
||||
run: |
|
||||
cargo build -p marqdo_plugin_agent --locked
|
||||
cargo build -p marqdo_plugin_llm --locked
|
||||
- name: Native agent choice and bounded recovery unit tests
|
||||
run: cargo test -p marqdo_plugin_agent --locked
|
||||
- name: Check short AI flow documents
|
||||
run: |
|
||||
cargo run --locked -- check ext/ai/flow.mq.md
|
||||
cargo run --locked -- check ext/ai/recovery.mq.md
|
||||
cargo run --locked -- check ext/ai/context.mq.md
|
||||
cargo run --locked -- check tests/ext/ai-native-flow.mq.md
|
||||
cargo run --locked -- check ext/ai/workflow.mq.md
|
||||
cargo run --locked -- check tests/ext/ai-native-workflow.mq.md
|
||||
- name: Native AI flow interpreter smoke (offline)
|
||||
run: |
|
||||
cargo run --locked -- run tests/ext/ai-native-flow.mq.md --effects plugin,fs.write
|
||||
cargo run --locked -- run tests/ext/ai-native-workflow.mq.md --effects plugin,fs.write
|
||||
- name: Workbench contracts (M00–M06 / F-subset)
|
||||
run: cargo test --test workbench_contracts --locked
|
||||
- name: Offline executable-knowledge gate
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
name: native-ai-flow
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- feat/native-ai-flow-recovery-20261118
|
||||
pull_request:
|
||||
paths:
|
||||
- 'plugins/agent/**'
|
||||
- 'ext/ai/flow.mq.md'
|
||||
- 'ext/ai/context.mq.md'
|
||||
- 'ext/ai/recovery.mq.md'
|
||||
- 'ext/ai/workflow.mq.md'
|
||||
- 'tests/ext/ai-native-*.mq.md'
|
||||
- '.github/workflows/native-ai-flow.yml'
|
||||
|
||||
jobs:
|
||||
agent:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- name: Build plugin and run native tests
|
||||
run: cargo test -p marqdo_plugin_agent --locked
|
||||
- name: Check the public Marqdo ABI libraries
|
||||
run: |
|
||||
cargo run --locked -- check ext/ai/flow.mq.md
|
||||
cargo run --locked -- check ext/ai/context.mq.md
|
||||
cargo run --locked -- check ext/ai/recovery.mq.md
|
||||
cargo run --locked -- check ext/ai/workflow.mq.md
|
||||
- name: Exercise offline integration through Marqdo
|
||||
run: |
|
||||
cargo run --locked -- run tests/ext/ai-native-flow.mq.md --effects plugin,fs.write
|
||||
cargo run --locked -- run tests/ext/ai-native-workflow.mq.md --effects plugin,fs.write
|
||||
@@ -0,0 +1,28 @@
|
||||
name: procurement-example-smoke
|
||||
on:
|
||||
push:
|
||||
branches: [main, docs/executable-skill-showcase-271]
|
||||
paths: ["examples/procurement/**", ".github/workflows/procurement-example.yml"]
|
||||
pull_request:
|
||||
paths: ["examples/procurement/**", ".github/workflows/procurement-example.yml"]
|
||||
jobs:
|
||||
smoke:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Fetch released v2.7.1 Linux CLI
|
||||
run: |
|
||||
curl -fL --retry 3 "https://github.com/cflmy/marqdo/releases/download/v2.7.1/marqdo-2.7.1-x86_64-unknown-linux-gnu.zip" -o /tmp/marqdo.zip
|
||||
unzip -q /tmp/marqdo.zip -d /tmp
|
||||
BIN="$(find /tmp -type f -name marqdo | head -n 1)"
|
||||
test -n "$BIN"
|
||||
chmod +x "$BIN"
|
||||
echo "CLI_BIN=$BIN" >> "$GITHUB_ENV"
|
||||
- name: Check and run procurement skill
|
||||
run: |
|
||||
"$CLI_BIN" check examples/procurement/index.mq.md
|
||||
"$CLI_BIN" call examples/procurement/index.mq.md 查询余额 已花费=120 --json
|
||||
"$CLI_BIN" call examples/procurement/index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=120 交付要求天数=7 --effects time.read,process.control --json | tee /tmp/allowed.json
|
||||
"$CLI_BIN" call examples/procurement/index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=360 交付要求天数=7 --effects time.read,process.control --json | tee /tmp/denied.json
|
||||
grep -q '本地模拟' /tmp/allowed.json
|
||||
grep -q '采购金额超过' /tmp/denied.json
|
||||
@@ -0,0 +1,43 @@
|
||||
name: Build Marqdo promotional video
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [docs/promo-video-271]
|
||||
paths:
|
||||
- scripts/make-procurement-promo.py
|
||||
- .github/workflows/promo-video.yml
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-video:
|
||||
if: github.ref_name == 'docs/promo-video-271'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: true
|
||||
- name: Prepare video environment
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq -y ffmpeg fonts-noto-cjk
|
||||
python -m pip install --quiet --disable-pip-version-check pillow numpy
|
||||
ffmpeg -version | head -n 2
|
||||
- name: Compose 32-second Marqdo video
|
||||
run: python scripts/make-procurement-promo.py
|
||||
- name: Verify deliverable
|
||||
run: |
|
||||
test -s assets/marketing/marqdo-2.7.1-promo.mp4
|
||||
test -s assets/marketing/marqdo-2.7.1-poster.jpg
|
||||
test -s assets/marketing/marqdo-2.7.1-promo.srt
|
||||
ffprobe -v error -show_entries format=duration,size -of default=noprint_wrappers=1 assets/marketing/marqdo-2.7.1-promo.mp4
|
||||
- name: Commit video into promotional branch
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add assets/marketing/marqdo-2.7.1-promo.mp4 assets/marketing/marqdo-2.7.1-poster.jpg assets/marketing/marqdo-2.7.1-promo.srt
|
||||
git diff --cached --quiet || git commit -m "docs: render Marqdo 2.7.1 promotional video from existing assets"
|
||||
git push origin HEAD:docs/promo-video-271
|
||||
@@ -668,6 +668,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"marqdo-plugin-sdk",
|
||||
"pulldown-cmark",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
|
||||
@@ -1,24 +1,127 @@
|
||||
# Marqdo
|
||||
# Marqdo — Your SKILL is now a TOOL.
|
||||
|
||||
**代码即文档。文档即知识库。知识即可执行。**
|
||||
<p align="center"><strong>Write it. Inspect it. Call it.</strong></p>
|
||||
<p align="center"><em>让 SKILL 真正成为工具:文档即知识,知识即可执行。</em></p>
|
||||
|
||||
Marqdo 把 Markdown **标记当作编程语法**:同一个 `.mq.md` 文件,既是给人读的文稿,也是给机器跑的程序。写文档的过程就是在写可执行逻辑——大型项目里,说明、示例与实现不再分叉成三份真相。它不是「又一个 Markdown 编程语言」,而是**文档原生的编程运行时(Document-native runtime)**——一门关于**可执行知识(Executable Knowledge)**的语言。
|
||||
<p align="center">
|
||||
<a href="https://github.com/cflmy/marqdo/releases/tag/v2.7.1"><img alt="release" src="https://img.shields.io/badge/release-v2.7.1-DDBA86?style=flat-square"></a>
|
||||
<a href="LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square"></a>
|
||||
<img alt="Rust runtime" src="https://img.shields.io/badge/runtime-Rust-B38E68?style=flat-square">
|
||||
<img alt="Pure by default" src="https://img.shields.io/badge/call-pure_by_default-467C83?style=flat-square">
|
||||
</p>
|
||||
|
||||
v2.2.0 起,`marqdo call` 可以直接调用这份文件里的一个函数。读的是同一页说明,跑的是同一个实现。知识因此可以当工具用,测试也不必再包一层 `# main`。
|
||||
**Marqdo is a Rust-based, document-native runtime for executable AI skills and tools.** Write human-readable prose, GFM tables, parameter contracts, and real functions in one `.mq.md` document. Call a function by its heading, inspect the implementation, and grant side effects explicitly.
|
||||
|
||||
欢迎访问 [marqdo 官方网站](https://www.marqdo.com/) 阅读更多特性与可执行文档。
|
||||
**Not a prompt wrapper.** The document is interpreted as a program by Marqdo; its tool functions are not merely natural-language instructions.
|
||||
|
||||
**链接语法**:[doc/design/link-syntax.md](doc/design/link-syntax.md) · 语法宪法:[doc/design/markdown-mapping.md](doc/design/markdown-mapping.md) · 对象:[objects.md](doc/design/objects.md) · 调用实参:[call-arguments.md](doc/design/call-arguments.md) · 用户站:[user-site.md](doc/design/user-site.md) · 浏览:[view.md](doc/design/view.md) · 调试:[view-debug.md](doc/design/view-debug.md) · OKF 清单:[catalog-cli.md](doc/design/catalog-cli.md) · Engineering Knowledge:[engineering-knowledge.md](doc/design/engineering-knowledge.md) · VS Code 扩展:[vscode-extension.md](doc/design/vscode-extension.md)(分支 **`vscode-extension`**;提交约定 [vscode-extension-commit.md](doc/design/vscode-extension-commit.md)) · **AI Skill**:[skills/marqdo/](skills/marqdo/)(说明 [ai-skill.md](doc/design/ai-skill.md)) · 官方扩展:[ext-llm.md](doc/design/ext-llm.md)(`ext/llm`)· [ext-agent.md](doc/design/ext-agent.md)(智能体开发框架)· [ext-cli.md](doc/design/ext-cli.md)(`marqdo ext list/add/remove`) · 原生插件 ABI:[ext-abi.md](doc/design/ext-abi.md)(`lib/plugin`) · 金样例:[tests/](tests/) · 用户文档:[public/](public/) · 变更:[CHANGELOG.md](CHANGELOG.md)
|
||||
<p align="center">
|
||||
<a href="#one-markdown-file-three-views-real-execution">56s film</a> ·
|
||||
<a href="#quickstart--one-function-one-command">Quickstart</a> ·
|
||||
<a href="#a-procurement-skill-with-a-600-budget">Procurement demo</a> ·
|
||||
<a href="#explore-the-view">View</a> ·
|
||||
<a href="doc/library-development.mq.md">Guide</a> ·
|
||||
<a href="https://www.marqdo.com/">Website</a> ·
|
||||
<a href="doc/releases/v2.7.1.md">Release notes</a>
|
||||
</p>
|
||||
|
||||
## One Markdown file. Three views. Real execution.
|
||||
|
||||
[](assets/marketing/marqdo-2.7.1-markdown-to-execution.mp4)
|
||||
|
||||
**[▶ Watch the 56-second film](assets/marketing/marqdo-2.7.1-markdown-to-execution.mp4)** · [Bilingual captions](assets/marketing/marqdo-2.7.1-markdown-to-execution.srt) · [Reproducible video source](scripts/render-markdown-execution-promo.py)
|
||||
|
||||
> **The point is not to invent a new document format.** A `.mq.md` file uses Markdown headings, paragraphs and tables. Ordinary Markdown renderers still show a readable document. Marqdo adds explicit execution semantics and a View that can inspect functions, values and their relationships on the same document.
|
||||
|
||||

|
||||
|
||||
<sub>**Concept artwork** showing the design principle: **source → ordinary Markdown rendering → Marqdo View**. Illustrative labels are not a live execution trace. The video includes [a real View screenshot](assets/marketing/user-procurement-view.png), [a standard Markdown rendering](assets/marketing/marqdo-procurement-standard-markdown.png) produced from the actual procurement source, and a business example verified with the 2.7.1 CLI.</sub>
|
||||
|
||||
**One `.mq.md` source, three ways to interact:**
|
||||
|
||||
| Source | Standard Markdown | Marqdo runtime + View |
|
||||
|---|---|---|
|
||||
| Edit the same Markdown text | Read headings, prose and data tables | Inspect the same document's calls, values and effects |
|
||||
| No separate prompt or tool implementation specification needed | Works as ordinary readable documentation | Call named functions with `marqdo call` |
|
||||
|
||||
|
||||
|
||||
## Quickstart — one function, one command
|
||||
|
||||
Install the [2.7.1 CLI release for Windows or Linux](https://github.com/cflmy/marqdo/releases/tag/v2.7.1), then run from this repository's root:
|
||||
|
||||
```bash
|
||||
marqdo call examples/calculator.mq.md 计算器.加法 a=2 b=3
|
||||
# => 5
|
||||
```
|
||||
|
||||
The function heading is the callable name. The function's explanation, parameters, return contract, and implementation live **in the same source file**. Use `--json` for machine-readable call results and diagnostics. No LLM key is needed for this quickstart.
|
||||
|
||||
## A procurement skill with a ¥600 budget
|
||||
|
||||
[Read the complete executable procurement document](examples/procurement/index.mq.md) · [How to run and verify the example](examples/procurement/README.md)
|
||||
|
||||
This is a **seven-tool, offline demonstration**. It knows the local supplier directory, queries a static price catalog, checks the budget, and conditionally creates a **simulated** work order. It also documents receipt handling, negotiation and supplier switching as unconnected stubs.
|
||||
|
||||

|
||||
|
||||
<sub>**Real CLI results**, edited into a short animation; the accepted order is explicitly **simulated** and never sent. [Capture workflow](scripts/capture-procurement-showcase.py) · [Passing checks](https://github.com/cflmy/marqdo/actions/runs/43358288563).</sub>
|
||||
|
||||
```bash
|
||||
# 1. Approve suppliers: paused or blacklisted entries are excluded.
|
||||
marqdo call examples/procurement/index.mq.md 查询采购商 "采购商状态='正常'" --json
|
||||
|
||||
# 2. Quote: SUP_JN, 8 ball bearings × ¥36 = ¥288 (sample price).
|
||||
marqdo call examples/procurement/index.mq.md 查询采购商价格 "采购商标识符='SUP_JN'" 数量=8 有效秒数=300 --json
|
||||
|
||||
# 3. Budget: ¥600 - ¥120 = ¥480.
|
||||
marqdo call examples/procurement/index.mq.md 查询余额 已花费=120 --json
|
||||
|
||||
# 4. Recheck supplier, quote, delivery and budget before a local mock order.
|
||||
marqdo call examples/procurement/index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=120 交付要求天数=7 --effects time.read,process.control --json
|
||||
|
||||
# 5. Over budget: ¥600 - ¥360 = ¥240 < ¥288. The mock work order must be denied.
|
||||
marqdo call examples/procurement/index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=360 交付要求天数=7 --effects time.read,process.control --json
|
||||
```
|
||||
|
||||
| Case | Budget check | Expected business result |
|
||||
|---|---|---|
|
||||
| `已花费=120` | ¥480 available ≥ ¥288 | `ok: true`, **local simulation only, not sent** |
|
||||
| `已花费=360` | ¥240 available < ¥288 | `ok: false`, budget denial |
|
||||
| `SUP_YY` | Supplier on blacklist | Excluded from quote / order |
|
||||
|
||||
**Why this matters:** The document doesn't merely tell an agent to obey a limit. The work-order **function itself** calls supplier validation, price lookup, and `查询余额` before returning an order record. Agent instructions and callable business logic can be inspected together.
|
||||
|
||||
> **Important limits:** Price and supplier records are fixtures; `已花费` is caller supplied. No authoritative budget ledger, concurrent reservation, live supplier prices, ERP messaging, real receipt, or payment is implemented. A successful **simulated** order is **not** a real transaction. The demo is a testable starting point, not a financial safety guarantee.
|
||||
|
||||
## Explore the View
|
||||
|
||||
Marqdo 2.7.1 improves the interactive reading experience: implementation details stay open when manually expanded, structured values are presented more clearly, and function/source links are easier to inspect. It **does not introduce new language syntax or APIs**.
|
||||
|
||||
```bash
|
||||
marqdo view examples/procurement --no-open
|
||||
```
|
||||
|
||||

|
||||
|
||||
<sub>**Original View screenshot provided by the project author.** Notice the natural document typography, values in the margins, and curved connections originating from function calls in the prose. [Additional automated View capture](assets/marketing/procurement-view.png) · [Static Markdown rendering](assets/marketing/marqdo-procurement-standard-markdown.png).</sub>
|
||||
|
||||
## One document, multiple uses
|
||||
|
||||
| Prompt-oriented agent skill | Marqdo executable skill |
|
||||
|---|---|
|
||||
| Natural-language tool instructions | Natural-language guidance **and** executable functions |
|
||||
| Description and code often separated | Heading, parameter table, return table and implementation in one `.mq.md` |
|
||||
| Validation may require separate wiring | Named function calls can be checked, executed and tested |
|
||||
| Prompts ask a model to comply | Runtime permissions control **declared** effects of a function call |
|
||||
| Hard to follow implementation through files | View links readable content and implementation details |
|
||||
|
||||
Agent Skills already support scripts; Marqdo's claim is **one document-native language surface** for authoring, inspecting, executing and reusing functions. This is **not** a claim of full formal verification, zero-delay execution, or OS-level isolation of all plugin/process behavior.
|
||||
|
||||
**Resources:** [Release v2.7.1](https://github.com/cflmy/marqdo/releases/tag/v2.7.1) · [Procurement example](examples/procurement/index.mq.md) · [Executable library authoring](doc/library-development.mq.md) · [Function calling](public/features/22-函数调用.mq.md) · [Link syntax](doc/design/link-syntax.md) · [Website](https://www.marqdo.com/)
|
||||
|
||||
---
|
||||
|
||||
标准库单文件本身就是手册:直接阅读[文件库](lib/文件.mq.md)、[集合库](lib/表.mq.md)等源码,按函数标题下的参数表、返回契约和动作说明调用;[工程实践](examples/stdlib-handbook/索引.mq.md)演示文件整理、CSV 汇总与文档维护。
|
||||
开发标准库和拓展库请直接阅读[可执行库开发指南](doc/library-development.mq.md):契约表、叙述式实现、遮蔽调用与多文件工程组织均有可运行示范。
|
||||
|
||||
|
||||
当前 CLI **2.7.1** 修复 View 详情展开后自动折叠,并改进函数、链接及结构化内容侧注;已有静态页面需重新导出。独立拓展库继续使用 **2.7.0**。参见[发布说明](doc/releases/v2.7.1.md)与[阅读示例](examples/view-details.mq.md)。
|
||||
|
||||
CLI **2.7.1** preserves View disclosure choices across layout and live updates. Regenerate existing static exports to include the fix; independent extension packs stay at **2.7.0**.
|
||||
## Deep dive · 语言、设计与执行系统
|
||||
|
||||
## 核心优势:可执行知识(Executable Knowledge)
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 132 KiB |
@@ -0,0 +1,35 @@
|
||||
1
|
||||
00:00:00,000 --> 00:00:04,800
|
||||
Your SKILL is now a TOOL.
|
||||
让 Markdown 直接承载可执行语义。
|
||||
|
||||
2
|
||||
00:00:04,800 --> 00:00:11,600
|
||||
源码态:标题、段落、表格都沿用 Markdown。
|
||||
执行逻辑就在文档之中。
|
||||
|
||||
3
|
||||
00:00:11,600 --> 00:00:18,000
|
||||
渲染态:同一份代码也能成为普通 Markdown 文档。
|
||||
|
||||
4
|
||||
00:00:18,000 --> 00:00:25,000
|
||||
源码态、标准 Markdown 渲染态、Marqdo View 态。
|
||||
三种视图,同一份源文件。
|
||||
|
||||
5
|
||||
00:00:25,000 --> 00:00:32,500
|
||||
一份 .mq.md,既可以阅读,也可以编译执行。
|
||||
|
||||
6
|
||||
00:00:32,500 --> 00:00:42,000
|
||||
真实 View 截图:函数调用和值沿着优雅曲线呈现。
|
||||
|
||||
7
|
||||
00:00:42,000 --> 00:00:50,800
|
||||
预算校验不是文字承诺,而是函数执行。
|
||||
模拟订单通过或拒绝,均由运行时返回结果。
|
||||
|
||||
8
|
||||
00:00:50,800 --> 00:00:56,000
|
||||
Marqdo 2.7.1 · github.com/cflmy/marqdo
|
||||
|
After Width: | Height: | Size: 78 KiB |
@@ -0,0 +1,29 @@
|
||||
1
|
||||
00:00:00,000 --> 00:00:03,900
|
||||
Your SKILL is now a TOOL.
|
||||
让 SKILL 真正成为工具。
|
||||
|
||||
2
|
||||
00:00:03,900 --> 00:00:09,000
|
||||
One readable document. Callable business logic.
|
||||
规则、数据、工具在同一份文档里。
|
||||
|
||||
3
|
||||
00:00:09,000 --> 00:00:17,400
|
||||
Five verified CLI calls, from quote to decision.
|
||||
真实 CLI 结果:询价、预算、模拟发单。
|
||||
|
||||
4
|
||||
00:00:17,400 --> 00:00:23,400
|
||||
¥120 spent: mock order. ¥360 spent: rejected.
|
||||
¥120 时模拟通过;¥360 时预算不足。
|
||||
|
||||
5
|
||||
00:00:23,400 --> 00:00:29,000
|
||||
Inspect the actual document in Marqdo View.
|
||||
查看 Marqdo 真实 View 页面。
|
||||
|
||||
6
|
||||
00:00:29,000 --> 00:00:32,000
|
||||
github.com/cflmy/marqdo
|
||||
开源 · Marqdo 2.7.1
|
||||
|
After Width: | Height: | Size: 161 KiB |
|
After Width: | Height: | Size: 139 KiB |
@@ -0,0 +1,42 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1340" height="720" viewBox="0 0 1340 720" role="img" aria-label="Animated illustration of a procurement skill being called, including a budget denial">
|
||||
<defs><linearGradient id="night" x1="0" y1="0" x2="1" y2="1"><stop stop-color="#0b1324"/><stop offset="1" stop-color="#1a2335"/></linearGradient></defs>
|
||||
<rect x="0" y="0" width="1340" height="720" rx="0" fill="url(#night)" stroke="none"/>
|
||||
<text x="46" y="52" fill="#f6d39c" font-size="30" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="700">Marqdo</text>
|
||||
<text x="207" y="50" fill="#9eacc1" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">/ EXECUTABLE SKILLS</text>
|
||||
<rect x="1137" y="25" width="165" height="38" rx="19" fill="#283348" stroke="#4b5b6b"/>
|
||||
<text x="1154" y="50" fill="#d3d9e4" font-size="15" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">2.7.1 · DEMO</text>
|
||||
<text x="46" y="109" fill="#f6f5ee" font-size="37" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="700">Your SKILL is now a TOOL.</text>
|
||||
<text x="47" y="141" fill="#a8b6c7" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">A human-readable document → callable business logic → structured results</text>
|
||||
<rect x="43" y="168" width="608" height="493" rx="18" fill="#182235" stroke="#38485c"/>
|
||||
<rect x="677" y="168" width="620" height="493" rx="18" fill="#111a2b" stroke="#38485c"/>
|
||||
<rect x="43" y="168" width="608" height="57" rx="18" fill="#263349" stroke="none"/>
|
||||
<rect x="677" y="168" width="620" height="57" rx="18" fill="#263349" stroke="none"/>
|
||||
<text x="65" y="204" fill="#f5dba9" font-size="20" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="600">index.mq.md</text>
|
||||
<text x="707" y="204" fill="#e5eaf4" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">$ marqdo call ... 向采购商发工单</text>
|
||||
<text x="66" y="266" fill="#faf7f1" font-size="27" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="700">## 向采购商发工单</text>
|
||||
<text x="66" y="307" fill="#a2b2ca" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">Read the rules. Call the function.</text>
|
||||
<rect x="65" y="328" width="564" height="166" rx="9" fill="#101a2a" stroke="none"/>
|
||||
<text x="86" y="365" fill="#abd6fa" font-size="19" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">报价 = 查询采购商价格(...)</text>
|
||||
<text x="86" y="407" fill="#abd6fa" font-size="19" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">预算 = 查询余额(已花费=...)</text>
|
||||
<text x="86" y="453" fill="#e9ba84" font-size="19" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">1. 剩余额度 < 本单金额 → 拒绝</text>
|
||||
<text x="65" y="552" fill="#d4e0ee" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">One file: prose + contracts + tables</text>
|
||||
<text x="65" y="588" fill="#d4e0ee" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">+ executable functions + result records</text>
|
||||
<text x="706" y="272" fill="#d7deef" font-size="19" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">SUP_JN 数量=8 单价=36</text>
|
||||
<text x="706" y="311" fill="#98aec9" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">最高预算 = ¥600</text>
|
||||
<g opacity=".18"><animate attributeName="opacity" values="0.18;0.18;1;1;0.18" keyTimes="0;0.04;0.09;0.91;1" dur="13s" repeatCount="indefinite"/><rect x="704" y="345" width="565" height="45" rx="9" fill="#233248" stroke="none"/><text x="719" y="374" fill="#9db5cf" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">01 SUPPLIER</text><text x="920" y="374" fill="#f5d8aa" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">SUP_JN · active</text></g>
|
||||
<g opacity=".18"><animate attributeName="opacity" values="0.18;0.18;1;1;0.18" keyTimes="0;0.19;0.24;0.91;1" dur="13s" repeatCount="indefinite"/><rect x="704" y="399" width="565" height="45" rx="9" fill="#233248" stroke="none"/><text x="719" y="428" fill="#9db5cf" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">02 QUOTE</text><text x="920" y="428" fill="#f5d8aa" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">8 × ¥36 = ¥288</text></g>
|
||||
<g opacity=".18"><animate attributeName="opacity" values="0.18;0.18;1;1;0.18" keyTimes="0;0.35;0.39999999999999997;0.91;1" dur="13s" repeatCount="indefinite"/><rect x="704" y="453" width="565" height="45" rx="9" fill="#233248" stroke="none"/><text x="719" y="482" fill="#9db5cf" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">03 BALANCE</text><text x="920" y="482" fill="#f5d8aa" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">¥600 - already spent</text></g>
|
||||
<g opacity=".18"><animate attributeName="opacity" values="0.18;0.18;1;1;0.18" keyTimes="0;0.53;0.5800000000000001;0.91;1" dur="13s" repeatCount="indefinite"/><rect x="704" y="507" width="565" height="45" rx="9" fill="#233248" stroke="none"/><text x="719" y="536" fill="#9db5cf" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">04 DECISION</text><text x="920" y="536" fill="#f5d8aa" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">check requested amount</text></g>
|
||||
<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;0.62;0.66;0.85;1" dur="13s" repeatCount="indefinite"/>
|
||||
<rect x="704" y="572" width="565" height="68" rx="10" fill="#193a34" stroke="#478a71"/>
|
||||
<text x="718" y="600" fill="#b5ebcb" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="600">✓ 已花费=120 ¥480 ≥ ¥288</text>
|
||||
<text x="718" y="625" fill="#d9f7e8" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">ok: true · 本地模拟,未发送</text>
|
||||
</g>
|
||||
<g opacity="0"><animate attributeName="opacity" values="0;0;0;1;1;0" keyTimes="0;0.78;0.84;0.88;0.95;1" dur="13s" repeatCount="indefinite"/>
|
||||
<rect x="704" y="572" width="565" height="68" rx="10" fill="#42252d" stroke="#a45a67"/>
|
||||
<text x="718" y="600" fill="#f8b1bc" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="600">✕ 已花费=360 ¥240 < ¥288</text>
|
||||
<text x="718" y="625" fill="#fde7ea" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">ok: false · 预算不足,拒绝工单</text>
|
||||
</g>
|
||||
<path d="M 652 430 C 665 429 674 429 688 430" fill="none" stroke="#f0c58c" stroke-width="3"/><circle cx="665" cy="429" r="4" fill="#f0c58c"><animate attributeName="cx" values="656;681;656" dur="2.5s" repeatCount="indefinite"/></circle>
|
||||
<text x="44" y="698" fill="#7e90a7" font-size="14" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">ILLUSTRATED EXPECTED FLOW · NOT A TERMINAL CAPTURE · NO REAL PURCHASE</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 7.4 KiB |
@@ -0,0 +1,35 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1340" height="740" viewBox="0 0 1340 740" role="img" aria-label="View-inspired editorial concept for the procurement function, not a real screenshot">
|
||||
<rect x="0" y="0" width="1340" height="740" rx="0" fill="#f8f6f0" stroke="none"/>
|
||||
<rect x="0" y="0" width="1340" height="68" rx="0" fill="#f2ede4" stroke="none"/>
|
||||
<text x="69" y="45" fill="#8d7358" font-size="29" font-family="Georgia,serif" font-weight="600">marqdo</text>
|
||||
<text x="577" y="43" fill="#665d53" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">文档 函数 执行 变量</text>
|
||||
<text x="1030" y="44" fill="#998773" font-size="13" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">VIEW CONCEPT / NOT CAPTURE</text>
|
||||
<line x1="325" y1="113" x2="325" y2="688" stroke="#e0d5c7"/><line x1="1032" y1="113" x2="1032" y2="688" stroke="#e0d5c7"/>
|
||||
<text x="374" y="128" fill="#b0895e" font-size="16" font-family="Georgia,'Noto Serif CJK SC',serif" font-weight="400">采购智能体</text>
|
||||
<text x="372" y="196" fill="#39352d" font-size="37" font-family="'Noto Serif CJK SC',Georgia,serif" font-weight="600">向采购商发工单</text>
|
||||
<text x="374" y="238" fill="#5d5851" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">核对准入、价格、交付与预算之后,生成本地模拟工单。</text>
|
||||
<line x1="374" y1="267" x2="993" y2="267" stroke="#b69b78"/>
|
||||
<text x="375" y="309" fill="#514a41" font-size="21" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="600">参数</text>
|
||||
<text x="375" y="348" fill="#5b5146" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">采购商标识符</text>
|
||||
<text x="625" y="348" fill="#96754f" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">text</text>
|
||||
<text x="811" y="348" fill="#8e8171" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">必填</text>
|
||||
<line x1="374" y1="365" x2="994" y2="365" stroke="#ded6c9"/>
|
||||
<text x="375" y="392" fill="#5b5146" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">数量 / 单价 / 已花费</text>
|
||||
<text x="625" y="392" fill="#96754f" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">number</text>
|
||||
<text x="811" y="392" fill="#8e8171" font-size="17" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">必填</text>
|
||||
<line x1="374" y1="408" x2="994" y2="408" stroke="#ded6c9"/>
|
||||
<text x="374" y="463" fill="#5e584f" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">发单前,必须再次查询并核对本轮的可用余额。</text>
|
||||
<rect x="373" y="483" width="618" height="48" rx="8" fill="#ebe3d5" stroke="none"/>
|
||||
<text x="391" y="513" fill="#805b35" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">预算 = [重新查询预算](查询余额(...))</text>
|
||||
<text x="374" y="565" fill="#7b5b4b" font-size="19" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">1. 剩余额度 < 本单金额</text>
|
||||
<text x="374" y="612" fill="#a06b5f" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400"> 返回 [预算不足,拒绝模拟工单](...)</text>
|
||||
<text x="375" y="682" fill="#8c8276" font-size="16" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">仅在全部检查通过时产生“本地模拟、未发送”的结果。</text>
|
||||
<path d="M 408 503 C 295 503 278 339 146 339" stroke="#ba9a75" stroke-width="1.7" fill="none"/><circle cx="408" cy="503" r="4.3" fill="#ba9a75"/>
|
||||
<text x="73" y="281" fill="#a78255" font-size="15" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">BUDGET CHECK</text>
|
||||
<text x="73" y="315" fill="#756350" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">已花费 ¥360</text>
|
||||
<text x="73" y="343" fill="#756350" font-size="18" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">剩余额度 ¥240</text>
|
||||
<path d="M 823 602 C 1010 586 1026 396 1122 396" stroke="#b7837e" stroke-width="1.7" fill="none"/><circle cx="823" cy="602" r="4.3" fill="#b7837e"/>
|
||||
<text x="1080" y="319" fill="#a67871" font-size="15" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">REJECTION</text>
|
||||
<text x="1080" y="354" fill="#945e55" font-size="22" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="700">¥240 < ¥288</text>
|
||||
<text x="1080" y="393" fill="#945e55" font-size="19" font-family="ui-monospace,Consolas,'Noto Sans CJK SC',monospace" font-weight="400">拒绝工单</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 204 KiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 523 KiB |
@@ -1,6 +1,8 @@
|
||||
marqdo (2.7.1-1ppa1) noble; urgency=medium
|
||||
marqdo (2.7.1-1ppa2) noble; urgency=medium
|
||||
|
||||
* Release 2.7.1; see the reviewed upstream CHANGELOG.
|
||||
* Stop reapplying the engineering compatibility fix already in upstream.
|
||||
* Include cached orig bytes until publication is confirmed by Launchpad.
|
||||
|
||||
-- Marqdo Maintainers <cflmy@users.noreply.github.com> Wed, 11 Nov 2026 00:03:29 +0800
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
engineering-stable-option.patch
|
||||
# engineering-stable-option.patch
|
||||
# The fix is already in upstream 2.7.1.
|
||||
@@ -0,0 +1,131 @@
|
||||
# Marqdo native agent flow — implementation contract
|
||||
|
||||
Status: **incremental, draft**. The core orchestration now has a plugin-only
|
||||
alternative to interpreter-stack suspension: a durable finite step state machine
|
||||
with explicit safe commit boundaries. Do not claim arbitrary stack-level
|
||||
continuation or exactly-once external writes based on a checkpoint file.
|
||||
|
||||
## Author surface (implemented in this branch)
|
||||
|
||||
| Module | Function | Contract |
|
||||
|---|---|---|
|
||||
| ext/ai/context.mq.md | scope | Select a bounded source excerpt using parsed Markdown headings; ambiguous names fail closed |
|
||||
| ext/ai/context.mq.md | pack | Compact caller-provided file/class/function text via ContextPackV2 |
|
||||
| ext/ai/flow.mq.md | ask/choose/parse_choice | One short decision, allowed-choice verification, at most one format repair |
|
||||
| ext/ai/flow.mq.md | input/reply | Durable step-boundary user-input gate keyed by id + source revision and scope |
|
||||
| ext/ai/flow.mq.md | start/wait/parallel | Existing Marqdo subtask scheduler, failure-preserving parallel result aggregation |
|
||||
| ext/ai/flow.mq.md | enter | Resolve only author-supplied registered skill name, run via standard subtask path |
|
||||
| ext/ai/recovery.mq.md | decide/save/load | Native error policy and CheckpointV2; no implicit unsafe re-execution |
|
||||
|
||||
The native agent plugin provides `agent_choice_parse`, `agent_context_scope`,
|
||||
`agent_input_open`, `agent_input_resume` and `agent_parallel_report`.
|
||||
Plugin errors must be visible, never converted into a fabricated successful answer.
|
||||
|
||||
## Invariants
|
||||
|
||||
- A model choice is untrusted data until verified against an explicit option list.
|
||||
- An imported module is **not** automatically part of a model prompt.
|
||||
- The requested heading scope, not the entire source file, is the prompt source.
|
||||
- A pending user-input gate owns a persistent checkpoint, not a blocked interpreter thread.
|
||||
- The same answer may be returned repeatedly; a competing answer or stale revision conflicts.
|
||||
- A completed subtask wait is distinct from a successful child exit.
|
||||
- Existing successful siblings remain visible when one subtask fails.
|
||||
- Writes, executable effects and external writes remain under ToolSpec permissions,
|
||||
the EffectLedger and source-version checks.
|
||||
- No component may silently broaden a tool's authorization on failure.
|
||||
|
||||
## Important limitations in this branch
|
||||
|
||||
The input/reply gate stores an explicit **step boundary**. It does not yet persist
|
||||
an arbitrary bytecode interpreter frame. Applications must choose and re-enter
|
||||
their next Marqdo function explicitly after receiving a verified input answer.
|
||||
The current source selector relies on a Markdown parser plus Marqdo heading
|
||||
conventions, not on the compiler's resolved module/class/function AST and symbols.
|
||||
Host identity inputs are supplied by the caller; production applications must
|
||||
attest them from their authenticated session, never use model-generated identity.
|
||||
The parallel wrapper reuses `subtask.run_many` and does not add durable child
|
||||
lease orchestration. Live provider tests and real 1B-model benchmarking remain open.
|
||||
|
||||
## Required VM/runtime completion: suspended execution
|
||||
|
||||
1. Introduce `WaitingInput` as a scheduler state, distinct from terminal failure.
|
||||
Save the logical run, program counter at a safe suspension boundary, bound
|
||||
inputs, variable snapshot, module and tool digests, and effect watermark.
|
||||
2. Resume via a new attempt linked to the original logical run, but never
|
||||
automatically repeat committed effects. Preserve cancellation and budget.
|
||||
3. The resume endpoint must be atomic (revision CAS), authenticate principal
|
||||
and workspace, verify source and tool schema revisions, and deduplicate
|
||||
repeated reply requests. Do not trust IDs inside model text.
|
||||
4. Handle interrupted worker, partial snapshot, stale input, invalid choice and
|
||||
unknown external write as separate outcomes. Treat unknown writes as
|
||||
reconciliation-required; do not invent exactly-once guarantees.
|
||||
5. Persist only serializable language values at declared safe points. If a
|
||||
foreign kernel, socket or native handle is live, explicitly refuse
|
||||
transparent frame recovery and preserve a safe step-level restart option.
|
||||
|
||||
## Required durable parallel execution
|
||||
|
||||
A parent dispatches child `.mq.md` functions using registered paths, grants
|
||||
minimal capabilities, shares budget and rate limits, and persists a child task
|
||||
manifest. Child completion records a status, value ref, output digest and ledger
|
||||
watermark before the parent merges results. For same-resource writes, use
|
||||
serialized revisions and explicit commit order. On parent cancellation, stop
|
||||
new children and request child cancellation; do not assume remote writes rolled
|
||||
back. On recovery, reconcile child attempts and reuse successful results.
|
||||
|
||||
## Release gates
|
||||
|
||||
| Test | Required observation |
|
||||
|---|---|
|
||||
| compiler/import check | All new `.mq.md` functions pass contract checks and execute via ABI |
|
||||
| small model outputs | Exact, labeled, fenced and numeric options normalize; mixed options fail |
|
||||
| input gate crash | After checkpoint, reply is committed once; alternate reply conflicts |
|
||||
| source drift | Original gate cannot resume against changed source revision |
|
||||
| context isolation | Class/function selectors reject ambiguity and ignore fenced headings |
|
||||
| concurrent partial | Failed/uncertain child never discards successful siblings |
|
||||
| unknown write | Neither retry nor recovered child duplicates an unconfirmed effect |
|
||||
| long-run cancellation | Worker/child task termination preserves usable artifacts and receipts |
|
||||
| compatibility | Existing `agent.step/plan/run` and workbooks remain callable |
|
||||
| model evaluation | Tokens/decision, semantic validity, end-to-end completion, recovery overhead |
|
||||
|
||||
Do not merge the branch as a completed runtime refactor until the relevant
|
||||
runtime gates, including crash injection and multi-worker concurrency, pass.
|
||||
|
||||
|
||||
## Plugin-only workflow (November 18 revision)
|
||||
|
||||
The Agent ABI plugin implements `agent_workflow_open/next/commit/cancel`.
|
||||
The small `ext/ai/workflow.mq.md` library wraps these primitives and provides
|
||||
`tick` to execute exactly one safe decision or document task per call.
|
||||
Source definitions have only five step kinds: `model`, `input`, `skill`,
|
||||
`parallel` and `return`. Model text is verified against declared options.
|
||||
`input` intentionally returns a waiting status; the UI supplies an answer
|
||||
through `commit` on a later invocation. There is no interpreter thread to
|
||||
hold and no need for a separate qdagent orchestration server.
|
||||
|
||||
The checkpoint records the source revision, caller-provided session and
|
||||
principal scope, next step index and the completed outputs. The same step
|
||||
cannot be silently committed twice. Mixed child outcomes preserve completed
|
||||
siblings in the checkpoint and **block** further automatic execution until
|
||||
the unknown/failed child operations are reconciled.
|
||||
|
||||
The state engine does not execute arbitrary unregistered tools directly:
|
||||
`tick` delegates to existing Marqdo ABI-backed SKILL/subtask functions.
|
||||
This is an implementation of **durable step-state recovery**, not a claim
|
||||
of transparent recovery for a suspended foreign function or native call.
|
||||
It provides the practical workflow needed for short qdagent SKILLs without
|
||||
altering the Marqdo interpreter.
|
||||
|
||||
### Security/reliability boundary still required for production
|
||||
|
||||
- The host must attest source digest, principal, session, permissions and
|
||||
registry, rather than accepting values copied from an LLM response.
|
||||
- Effectful child tools must use the existing EffectLedger and external
|
||||
receipt reconciliation; no automatic re-dispatch after an uncertain write.
|
||||
- Cancelling a workflow checkpoint does not automatically cancel previously
|
||||
spawned external children; the supervisor must propagate cancellation.
|
||||
- The current task runner is step-atomic, not a durable parallel child lease
|
||||
scheduler. A future plugin-only child manifest may use the host's existing
|
||||
`runtime` query API, but must not bypass process.exec or file-root grants.
|
||||
- Cross-process locks need a lease/owner-aware stale-lock recovery path;
|
||||
a stale lock currently fails closed and requires operator review.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Procurement skill · reproducible demo
|
||||
|
||||
This is a **local simulation** in one callable `.mq.md` source. It has no external purchase side effects and does not require an LLM API key.
|
||||
|
||||
## What it demonstrates
|
||||
|
||||
- A `¥600` spending limit with a caller-supplied balance.
|
||||
- An active supplier `SUP_JN`, quoting `¥36` for a sample bearing.
|
||||
- Eight units total `¥288` with an estimated seven-day delivery.
|
||||
- Supplier approval, quote comparison, budget check and local work-order generation as direct Marqdo function calls.
|
||||
- Unconnected capabilities (live quotes, real work orders and receipts, negotiation and supplier switching) explicitly labeled as stubs.
|
||||
|
||||
## Run from the repository root
|
||||
|
||||
```bash
|
||||
marqdo check examples/procurement/index.mq.md --narrative-ratio
|
||||
marqdo call examples/procurement/index.mq.md 查询采购商 "采购商状态='正常'" --json
|
||||
marqdo call examples/procurement/index.mq.md 查询采购商价格 "采购商标识符='SUP_JN'" 数量=8 有效秒数=300 --json
|
||||
marqdo call examples/procurement/index.mq.md 查询余额 已花费=120 --json
|
||||
marqdo call examples/procurement/index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=120 交付要求天数=7 --effects time.read,process.control --json
|
||||
marqdo call examples/procurement/index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=360 交付要求天数=7 --effects time.read,process.control --json
|
||||
marqdo call examples/procurement/index.mq.md 查询采购商价格 "采购商标识符='SUP_YY'" 数量=8 --json
|
||||
```
|
||||
|
||||
## Interpret the result
|
||||
|
||||
The return from `向采购商发工单` is a **business-level** `ok/value/error` map. In the low-spend case it should contain `ok=True`, `工单金额=288` and `状态="本地模拟,未发送"`. When already spent reaches `360`, the function should return `ok=False` and a budget rejection reason. The CLI's outer JSON call envelope is separate from this nested domain result.
|
||||
|
||||
These are **expected outcomes**, not independently verified terminal captures. The workflow [procurement-example.yml](../../.github/workflows/procurement-example.yml) exercises the commands using the released Linux CLI.
|
||||
|
||||
## Inspect in View
|
||||
|
||||
```bash
|
||||
marqdo view examples/procurement --no-open
|
||||
```
|
||||
|
||||
Open `向采购商发工单` and expand the annotations for `查询采购商价格`, `查询余额`, and `剩余额度`. Merely reading and expanding details does not execute side effects.
|
||||
|
||||
## Production integration boundaries
|
||||
|
||||
The real supplier quote API, persistent authoritative ledger, concurrent budget reservation, ERP transaction, order receipt, negotiation, and supplier switching are **not connected**. Before any real purchase, integrate server-side budget reservations, quote signatures/evidence, idempotent transactions, durable logs and an explicit human authorization policy.
|
||||
|
||||
The GIF-like animated [SVG storyboard](../../assets/marketing/procurement-flow.svg) and the [View-inspired concept](../../assets/marketing/procurement-view-concept.svg) are illustrations, not instrumented evidence.
|
||||
@@ -0,0 +1,469 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 采购智能体
|
||||
version: v1.1-demo
|
||||
description: 600 元采购预算下的供应商筛选、示例询价、预算审核和模拟工单;真实采购接口尚未接通。
|
||||
import:
|
||||
table: lib/table.mq.md
|
||||
time: lib/time.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
这是一份可阅读、可调用的采购工作手册,也是一份开发中的采购 SKILL。
|
||||
它把采购制度、供应商知识、模拟数据与操作工具放在同一个 Marqdo 文档里。
|
||||
当前版本只支持本地模拟采购,不会向真实供应商发消息、扣款或确认采购。
|
||||
|
||||
采购目标是在最高 600 元 的预算内,从状态正常、报价可接受且预计交期满足要求的供应商中,
|
||||
选择总成本最低的方案。价格相同时,应优先考虑交付可靠性,并保留供老板决策的理由。
|
||||
所有费用均以人民币元计算;样例不包含税费、运费、折扣及多币种换算。
|
||||
|
||||
采购工具不是自动取得授权的交易权限。智能体可解释和比较工具返回的数据,
|
||||
但必须遵守下面的门禁;真实下单、持久化预算占用、实时报价和最终回执都需要后续接入。
|
||||
|
||||
| 业务能力 | 本地状态 | 可信边界 |
|
||||
|---|---|---|
|
||||
| 查询采购商 | 已接通示例名录 | 只反映下文静态目录,不是在线主数据 |
|
||||
| 查询采购商价格 | 示例数据 | 价格与交期为测试样例,不是实时承诺 |
|
||||
| 查询余额 | 已接通计算逻辑 | `已花费` 由调用方提供,尚未读取持久账本 |
|
||||
| 向采购商发工单 | 本地模拟 | 会再次检查供应商、报价和预算,不真正发送 |
|
||||
| 检查工单 | 模拟回复 | 不能验证真实工单,也不会确认真实下单 |
|
||||
| 讲价 | 未接通,保留示例请求 | 不代表供应商已收到议价 |
|
||||
| 更换采购商 | 未接通,保留示例请求 | 不代表已经切换或重新询价 |
|
||||
|
||||
采购工作原则(阅读说明,非函数)
|
||||
|
||||
这里的工作原则是叙述知识,供智能体阅读;不是可调用函数。
|
||||
实际调用的函数均在下面的二级标题中定义。需要让规则成为真正的技术门禁时,
|
||||
必须在相应函数中重复检查,不能认为写在本节的文字会自动执行。
|
||||
|
||||
| 阶段 | 工具 | 通过条件 | 需要保留的证据 |
|
||||
|---|---|---|---|
|
||||
| 1. 准入 | 查询采购商 | 只考虑状态为“正常”的供应商 | 名录快照、筛选结果 |
|
||||
| 2. 比价 | 查询采购商价格 | 对候选逐家询价,比较相同商品、数量、交期与总额 | 各家报价及数据来源 |
|
||||
| 3. 预算 | 查询余额 | 每次拟发单前重新查询;剩余额度不小于本单总额 | 已花费、可用余额、本单金额 |
|
||||
| 4. 工单 | 向采购商发工单 | 准入、报价、交期和预算校验同时通过 | 模拟工单和校验摘要 |
|
||||
| 5. 回执 | 检查工单 | 只有真实回执和真实下单接口接通后才能确认交易 | 回执、处置决定 |
|
||||
|
||||
不可突破的边界是:黑名单供应商不询价、不发单;已暂停供应商也不参与比价。
|
||||
没有报价不得发单,超预算不得发单;回执不清楚时不能擅自认为已经下单。
|
||||
如果某家缺货,可以考虑另询一家;议价成功之前,不能用目标价格充当已确认价格。
|
||||
|
||||
示例演练。 采购 8 件深沟球轴承,假设本轮已花费 120 元、交付要求为 7 天。
|
||||
静态目录里,正常供应商的示例单价为江南配件 36 元、粤海精工 39 元、华东金属 42 元。
|
||||
在样例条件下江南配件报价总额为 288 元,余额为 480 元,能够生成模拟工单。
|
||||
北岭工贸虽然报价更低,但已经暂停;远洋贸易属于黑名单,两者都必须排除。
|
||||
|
||||
从本文件所在目录调用,建议使用结构化输出,以便把每次调用的入参和返回值另行归档:
|
||||
|
||||
```sh
|
||||
marqdo call index.mq.md 查询采购商 "采购商状态='正常'" --json
|
||||
marqdo call index.mq.md 查询采购商价格 "采购商标识符='SUP_JN'" "商品='深沟球轴承'" 数量=8 --json
|
||||
marqdo call index.mq.md 查询余额 已花费=120 --json
|
||||
marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=120 交付要求天数=7 --effects time.read,process.control --json
|
||||
marqdo call index.mq.md 检查工单 "工单号='MOCK-WO-示例'" "模拟回复='缺货'" --json
|
||||
```
|
||||
|
||||
以上第五条是独立的回执模拟,不是第四条工单的真实回执。
|
||||
将来接入真实系统以后,应使用实际返回的工单号,并从系统查询实际状态。
|
||||
示例中的 `--json` 是输出格式,不会自动建立审计账本;目前由调用方保存记录。
|
||||
|
||||
|
||||
维护约定:以后真正接通报价、ERP、账本与议价通道时,务必把“模拟”状态替换为真实的失败可恢复结果,
|
||||
并增加后端校验、并发预算占用、幂等与日志持久化。在真实验收之前,不得修改文档宣称已经完成交易。
|
||||
|
||||
建议使用以下命令对本文件做实际检查;这些命令是待在已安装 Marqdo 的工程环境中执行的验收步骤,
|
||||
不是本文件声称已经通过的测试结果:
|
||||
|
||||
```sh
|
||||
marqdo check index.mq.md --narrative-ratio
|
||||
marqdo call index.mq.md 查询采购商 "采购商状态='正常'" --json
|
||||
marqdo call index.mq.md 查询采购商价格 "采购商标识符='SUP_YY'" 数量=8 --json
|
||||
marqdo call index.mq.md 查询余额 已花费=550 --json
|
||||
marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=550 --effects time.read,process.control --json
|
||||
marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_BL'" 数量=8 单价=30 已花费=0 --effects time.read,process.control --json
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 查询采购商
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 采购商状态 | text | "全部" | 按状态筛选;可选“全部 / 正常 / 已暂停 / 黑名单” |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | 供应商记录列表;名称、标识符、状态、老板的评价、采购商的喜好;无匹配则为空列表 |
|
||||
|
||||
根据调用者传入的`采购商状态`="全部"筛选供应商目录。这份目录是可执行的本地样例,
|
||||
将来接入供应商主数据后,应在这里替换数据来源,保留相同的记录字段和筛选契约。
|
||||
|
||||
“全部”用于名录展示和审计;采购决策必须显式传入“正常”,
|
||||
不能因为全部名录里列出了黑名单供应商,就把它们作为可采购对象。
|
||||
这里的列表包含带首列“行”的 GFM 表格,因此每行都是一条可检索的记录。
|
||||
|
||||
`采购商名录` =
|
||||
|
||||
| 行 | 名称 | 标识符 | 状态 | 老板的评价 | 采购商的喜好 |
|
||||
|---|---|---|---|---|---|
|
||||
| 1 | 华东金属 | SUP_HD | 正常 | 交付稳定,价格较高 | 大批量,账期短 |
|
||||
| 2 | 江南配件 | SUP_JN | 正常 | 价格较低,偶有拖期 | 小批量,快单 |
|
||||
| 3 | 北岭工贸 | SUP_BL | 已暂停 | 曾出现质检不合格 | 定制订单 |
|
||||
| 4 | 粤海精工 | SUP_YH | 正常 | 老合作伙伴,可沟通价格 | 长期协议,年框 |
|
||||
| 5 | 远洋贸易 | SUP_YY | 黑名单 | 曾收款后失联 | 无 |
|
||||
|
||||
当筛选状态为“全部”时,提供完整目录供查看;
|
||||
这是查询目录,不代表所有供应商均允许交易。
|
||||
|
||||
1. `采购商状态` == "全部"
|
||||
我们返回*[返回完整示例名录](`采购商名录`)*。
|
||||
|
||||
其他状态使用表库的相等过滤,不直接手写循环。
|
||||
|
||||
我们返回*[按状态筛选采购商](table.where(list=`采购商名录`, key="状态", value=`采购商状态`))*。
|
||||
|
||||
## 查询采购商价格
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 采购商标识符 | text | 必填 | 需要询价的供应商标识,例如 SUP_JN |
|
||||
| 商品 | text | "深沟球轴承" | 本次询价的品名;样例目录目前只有这一种商品 |
|
||||
| 数量 | number | 1 | 采购件数,必须为正整数 |
|
||||
| 有效秒数 | number | 300 | 预留给真实报价接口的有效期参数;模拟价格不产生有效报价凭证 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 示例报价 map,含商品、数量、单价、总额、交期、来源及真实性标记;不允许询价或无数据时为 None |
|
||||
|
||||
使用`采购商标识符`查询`商品`="深沟球轴承"的示例价格,按`数量`=1计算总额。
|
||||
`有效秒数`=300只是将来真实询价服务的预留输入;它不会让静态价格自动变成实时价格。
|
||||
一个报价必须同时说明价格、来源及是否允许真实交易,不能仅凭生成时间认定报价有效。
|
||||
|
||||
先检查数量和保留的有效期是否合理。无效输入不应返回看似正常的价格。
|
||||
|
||||
1. `数量` <= 0 or int(`数量`) != `数量` or `有效秒数` <= 0
|
||||
我们返回*[数量或有效期不合法,拒绝询价](None)*。
|
||||
|
||||
询价前重新从准入目录检查供应商状态。即使示例价格表里包含已暂停或黑名单商户,
|
||||
也不能将它们的价格返回给采购智能体,防止“最低价优先”覆盖供应商准入规则。
|
||||
|
||||
我们先**正常名录 = [只读取可参与询价的供应商](查询采购商(采购商状态="正常"))**,
|
||||
再**候选 = [匹配当前供应商标识](table.where(list=`正常名录`, key="标识符", value=`采购商标识符`))**。
|
||||
|
||||
1. table.len(xs=`候选`) == 0
|
||||
我们返回*[供应商不存在或当前不可询价](None)*。
|
||||
|
||||
以下表格是用于开发与验收的静态价格及交期样例。所有行都不是实时供应商承诺。
|
||||
接入线上报价系统时,只替换“取得原始报价”的部分,并保留准入、总额和来源检查。
|
||||
|
||||
`示例价格目录` =
|
||||
|
||||
| 行 | 采购商标识符 | 商品 | 报价单价 | 预计交付天数 |
|
||||
|---|---|---|---|---|
|
||||
| 1 | SUP_HD | 深沟球轴承 | 42 | 3 |
|
||||
| 2 | SUP_JN | 深沟球轴承 | 36 | 7 |
|
||||
| 3 | SUP_BL | 深沟球轴承 | 30 | 2 |
|
||||
| 4 | SUP_YH | 深沟球轴承 | 39 | 5 |
|
||||
| 5 | SUP_YY | 深沟球轴承 | 20 | 1 |
|
||||
|
||||
取得单家供应商的目录条目,再匹配商品,避免将别的商品的价格用于本次采购。
|
||||
我们先**报价目录 = [供应商实时报价接口未接通,暂用本地示例价格](`示例价格目录`)**,
|
||||
让没有接通的服务状态在可检索标签中明确可见。
|
||||
|
||||
我们再**同商报价 = [从示例目录查找指定供应商](table.where(list=`报价目录`, key="采购商标识符", value=`采购商标识符`))**,
|
||||
再**命中报价 = [限定本次询价商品](table.where(list=`同商报价`, key="商品", value=`商品`))**。
|
||||
|
||||
1. table.len(xs=`命中报价`) == 0
|
||||
我们返回*[没有这件商品的示例报价](None)*。
|
||||
|
||||
从唯一一条样例记录取得单价和交期,然后计算相同数量的总金额。
|
||||
因为目前没有真实接口,返回的数据必须永久带有“模拟”标记,直到服务真正接入并验证。
|
||||
|
||||
我们先**报价条目 = [取出命中的示例记录](table.first(list=`命中报价`))**,
|
||||
然后**单价 = [读取单件报价](access(`报价条目`, "报价单价"))**,
|
||||
以及**交付周期 = [读取样例交付天数](access(`报价条目`, "预计交付天数"))**。
|
||||
本次报价的**报价总额 = [单价乘以购买数量](`单价` * `数量`)**。
|
||||
|
||||
`报价` =
|
||||
|
||||
| 采购商标识符 | 商品 | 单价 | 数量 | 报价总额 | 预计交付天数 | 报价来源 | 报价时间 | 报价生效至 | 可真实下单 |
|
||||
|---|---|---|---|---|---|---|---|---|---|
|
||||
| `采购商标识符` | `商品` | `单价` | `数量` | `报价总额` | `交付周期` | 示例目录(未接实时接口) | None | None | False |
|
||||
|
||||
我们返回*[这条可测试、不可用于真实下单的报价](`报价`)*,
|
||||
供后续比价和本地模拟使用;真实业务必须另外验证供应商提供的报价凭证。
|
||||
|
||||
## 查询余额
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 已花费 | number | 0 | 调用方已确认的本轮占用金额;不得为负,模拟运行期间不自动累加 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 预算 map,含最高预算、已花费、可用余额、还能下单;负数输入时为 None |
|
||||
|
||||
预算上限固定为 600 元。输入`已花费`=0代表一轮新的采购演练;
|
||||
后续每次准备发单时,必须传入已经确认或占用的实际累计金额。
|
||||
当前没有持久账本,这个数字由调用方维护;工具不会自动记账,也不能防止两个独立进程并发超支。
|
||||
|
||||
当已花费为负数时,拒绝计算,避免用负债务造出虚假的可用余额。
|
||||
|
||||
1. `已花费` < 0
|
||||
我们返回*[累计支出不允许为负数](None)*。
|
||||
|
||||
这次计算先**最高预算 = [读取采购预算上限](600)**,
|
||||
再**可用余额 = [计算还未占用的额度](`最高预算` - `已花费`)**。
|
||||
如果余额已经为零或更少,返回中应明确写“不能”,防止后续误发工单。
|
||||
|
||||
1. `可用余额` > 0
|
||||
`余额` =
|
||||
|
||||
| 最高预算 | 已花费 | 可用余额 | 还能下单 |
|
||||
|---|---|---|---|
|
||||
| `最高预算` | `已花费` | `可用余额` | 可以 |
|
||||
|
||||
我们返回*[预算仍有剩余额度](`余额`)*。
|
||||
|
||||
`余额` =
|
||||
|
||||
| 最高预算 | 已花费 | 可用余额 | 还能下单 |
|
||||
|---|---|---|---|
|
||||
| `最高预算` | `已花费` | `可用余额` | 不能 |
|
||||
|
||||
我们返回*[预算已用尽或已超支](`余额`)*。
|
||||
|
||||
## 向采购商发工单
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 采购商标识符 | text | 必填 | 接受模拟工单的供应商标识 |
|
||||
| 数量 | number | 必填 | 拟采购件数,必须为正整数 |
|
||||
| 单价 | number | 必填 | 本次拟采用的单价,必须与本次重新取得的示例报价一致 |
|
||||
| 已花费 | number | 必填 | 拟发单时的累计已占用金额;不得遗漏或默认为零 |
|
||||
| 商品 | text | "深沟球轴承" | 拟采购商品 |
|
||||
| 交付要求天数 | number | 7 | 最晚可接受交期;以自然日计,本地样例仅作演示 |
|
||||
| 采购文字 | text | "按标准规格采购" | 本单采购要求与备注 |
|
||||
| 休息秒数 | number | 0 | 仅用于测试等待效应的模拟延迟;并非真实供应商回执窗口 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | 含 ok 状态的结构化结果;成功时 value 为模拟工单,失败时 error 为原因;不代表已真实发送 |
|
||||
|
||||
根据调用者提供的`采购商标识符`、`数量`、`单价`、`已花费`,
|
||||
以及`商品`="深沟球轴承"、`交付要求天数`=7、`采购文字`="按标准规格采购"、`休息秒数`=0
|
||||
尝试创建一份本地模拟工单。这是整个采购流程的最后一道可执行防线;
|
||||
即使智能体漏做了前面的检查,本函数仍会再次询价并调用查询余额。
|
||||
|
||||
单次函数调用可以拒绝非法金额,但不能证明调用者传入的已花费真实,也没有跨调用的报价令牌或持久预算锁。
|
||||
后续要接通真实 ERP 时,必须增加服务端事务、幂等键、报价凭证核验和权威预算余额。
|
||||
在这些能力上线之前,此函数只返回本地模拟数据,不允许被当成真实采购指令。
|
||||
|
||||
基础输入必须合理。金额或天数为负、数量非正整数、等待时间过长都应在本阶段直接拒绝。
|
||||
使用内部失败助手统一构造 `ok=False` 的回执,避免产生半成品工单。
|
||||
|
||||
1. `数量` <= 0 or int(`数量`) != `数量` or `单价` <= 0 or `已花费` < 0 or `交付要求天数` < 0 or `休息秒数` < 0 or `休息秒数` > 300
|
||||
我们返回*[拒绝无效工单输入](_拒绝模拟工单(原因="数量、单价、金额或期限参数不合法"))*。
|
||||
|
||||
第一道业务门禁重新读取正常供应商,不信任调用方单独提供的标识符。
|
||||
|
||||
我们先**正常商户 = [从本地名录获取正常供应商](查询采购商(采购商状态="正常"))**,
|
||||
再**供应商命中 = [核实供应商仍然处于正常状态](table.where(list=`正常商户`, key="标识符", value=`采购商标识符`))**。
|
||||
|
||||
1. table.len(xs=`供应商命中`) == 0
|
||||
我们返回*[拒绝黑名单、暂停或不存在的供应商](_拒绝模拟工单(原因="供应商未通过准入审核"))*。
|
||||
|
||||
第二道门禁在本次调用中重新询价,既避免凭记忆下单,也防止调用方任意填写低价。
|
||||
但此阶段重新拿到的是静态示例价格,并不是供应商确认的线上报价。
|
||||
|
||||
我们先**报价 = [重新查本次商品与数量的模拟报价](查询采购商价格(采购商标识符=`采购商标识符`, 商品=`商品`, 数量=`数量`, 有效秒数=300))**。
|
||||
|
||||
1. `报价` == None
|
||||
我们返回*[未查到报价,禁止生成工单](_拒绝模拟工单(原因="此供应商没有可用的示例报价"))*。
|
||||
|
||||
报价存在后,核对输入价格与示例单价,以及交货要求;价格不一致时不允许自己改写报价。
|
||||
|
||||
我们先**询得单价 = [取本次询价单价](access(`报价`, "单价"))**,
|
||||
再**预计交期 = [取示例预计交期](access(`报价`, "预计交付天数"))**,
|
||||
同时**本单金额 = [取示例报价总额](access(`报价`, "报价总额"))**。
|
||||
|
||||
1. `单价` != `询得单价`
|
||||
我们返回*[价格未经本次询价确认,拒绝工单](_拒绝模拟工单(原因="拟采用单价与本次示例报价不一致"))*。
|
||||
|
||||
1. `预计交期` > `交付要求天数`
|
||||
我们返回*[预计交期不能满足要求,拒绝工单](_拒绝模拟工单(原因="示例交付周期超过可接受期限"))*。
|
||||
|
||||
第三道门禁必须在建立工单前调用查询余额,并使用本次输入的累计已花费金额。
|
||||
发工单不是先保存成功再补看余额;条件不成立时立即返回拒绝结果。
|
||||
|
||||
我们先**预算 = [在拟发单时重新查询预算](查询余额(已花费=`已花费`))**。
|
||||
|
||||
1. `预算` == None
|
||||
我们返回*[累计金额不合法,拒绝工单](_拒绝模拟工单(原因="本轮累计支出无效"))*。
|
||||
|
||||
我们再**剩余额度 = [读取可用于本单的余额](access(`预算`, "可用余额"))**。
|
||||
|
||||
1. `剩余额度` < `本单金额`
|
||||
我们返回*[本单超过剩余额度,拒绝工单](_拒绝模拟工单(原因="采购金额超过 600 元总预算的剩余额度"))*。
|
||||
|
||||
全部检查通过后才生成可追溯的模拟编号。编号只服务本地演练,
|
||||
同一秒内的多个调用可能产生相同编号,不能拿它代替生产级幂等键。
|
||||
|
||||
我们先**当前秒 = [读取本地模拟工单生成时间](time.now_unix())**,
|
||||
再**模拟工单号 = [生成带模拟前缀的工单号]("MOCK-WO-" + str(`当前秒`) + "-" + `采购商标识符` + "-" + str(`数量`))**。
|
||||
同时**预计已占用 = [计算此笔模拟工单对应的累计占用](`已花费` + `本单金额`)**,
|
||||
该数值只用于展示,不会写入持久账本。
|
||||
|
||||
只有显式要求演练延迟时才挂起。这种等待不会触发真实发送或获取真实回执。
|
||||
|
||||
1. `休息秒数` > 0
|
||||
我们先**等待毫秒 = [将模拟等待秒数换算为毫秒](`休息秒数` * 1000)**,
|
||||
再**[模拟等待回执窗口](time.sleep_ms(ms=`等待毫秒`))**。
|
||||
|
||||
`工单` =
|
||||
|
||||
| 工单号 | 采购商标识符 | 商品 | 数量 | 单价 | 工单金额 | 采购文字 | 已花费 | 本单后预计已占用 | 模拟交期天数 | 报价来源 | 状态 |
|
||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||
| `模拟工单号` | `采购商标识符` | `商品` | `数量` | `询得单价` | `本单金额` | `采购文字` | `已花费` | `预计已占用` | `预计交期` | 示例目录(未接实时接口) | 本地模拟,未发送 |
|
||||
|
||||
这一记录给智能体下一步检查模拟回执使用;它没有持久保存到任何订单系统,
|
||||
也没有自动修改预算余额。把`工单`作为 value,连同成功标记一起返回。
|
||||
|
||||
`成功回执` =
|
||||
|
||||
| ok | value | error |
|
||||
|---|---|---|
|
||||
| True | `工单` | None |
|
||||
|
||||
我们返回*[模拟校验通过,但真实发单尚未接通](`成功回执`)*。
|
||||
|
||||
## 检查工单
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 工单号 | text | 必填 | 待演练的工单编号;本地没有可核验的持久工单仓库 |
|
||||
| 模拟回复 | text | "不清楚" | 可选:有货 / 缺货 / 不清楚;默认采取保守处置 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | 工单号、回执、下一步、理由、来源;任何结果均不等于真实下单完成 |
|
||||
|
||||
读取调用方提供的`工单号`和`模拟回复`="不清楚",生成一份仅供开发的回执解释。
|
||||
本工具没有向供应商查询工单状态,也不核对该编号是否真实存在。
|
||||
真实环境必须改为用工单系统查回执、核对供应商身份,再按订单状态机处理。
|
||||
|
||||
有货并不代表已经付款或下单。即使示例回执说“有货”,
|
||||
当前可以做的也只是标记“模拟可推进”;在真实交易接口接通前必须停止。
|
||||
|
||||
1. `模拟回复` == "有货"
|
||||
`结论` =
|
||||
|
||||
| 工单号 | 回执 | 下一步 | 理由 | 数据来源 |
|
||||
|---|---|---|---|---|
|
||||
| `工单号` | 有货 | 待真实下单接口接通 | 模拟有货;不得视作已采购或已付款 | 模拟回复 |
|
||||
|
||||
我们返回*[保留模拟有货的回执结果](`结论`)*。
|
||||
|
||||
如果模拟回复表示缺货,就停止当前候选,重新筛选其他正常供应商并比价。
|
||||
更换采购商工具目前也未接通,所以不能把“准备更换”写成“更换成功”。
|
||||
|
||||
1. `模拟回复` == "缺货"
|
||||
`结论` =
|
||||
|
||||
| 工单号 | 回执 | 下一步 | 理由 | 数据来源 |
|
||||
|---|---|---|---|---|
|
||||
| `工单号` | 缺货 | 更换采购商(待接通) | 模拟缺货,应返回供应商选择和报价阶段 | 模拟回复 |
|
||||
|
||||
我们返回*[建议重新筛选采购商](`结论`)*。
|
||||
|
||||
对于不清楚或不属于约定值的回复,采取更保守的处置:不自动采购,
|
||||
只生成建议协商的下一步,避免把未定义状态解释为成功。
|
||||
|
||||
`结论` =
|
||||
|
||||
| 工单号 | 回执 | 下一步 | 理由 | 数据来源 |
|
||||
|---|---|---|---|---|
|
||||
| `工单号` | 不清楚 | 讲价或人工核实(待接通) | 回执没有提供足以真实下单的证据 | 模拟回复 |
|
||||
|
||||
我们返回*[回执不明确,停止自动确认](`结论`)*。
|
||||
|
||||
## 讲价
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 工单号 | text | 必填 | 需要发起议价请求的模拟工单号 |
|
||||
| 目标单价 | number | 必填 | 期望价格;必须为正数,不代表采购商已经接受 |
|
||||
| 理由 | text | "报价高于同期均价" | 给供应商看的议价依据,未来接通通道时使用 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 示例议价请求 map;目标单价不合法时为 None |
|
||||
|
||||
针对`工单号`提出`目标单价`,使用`理由`="报价高于同期均价"解释期望。
|
||||
议价通道当前尚未接通,这里刻意保留一条可执行的示例请求,
|
||||
方便开发者以后替换成真实消息投递和回执解析。
|
||||
|
||||
不能把期望价改写成询得单价,也不能认为发出模拟请求就获得了供应商同意。
|
||||
真实成交价必须依赖新的、可验证的报价凭证,再重新执行预算校验。
|
||||
|
||||
1. `目标单价` <= 0
|
||||
我们返回*[目标价格必须大于零](None)*。
|
||||
|
||||
`示例议价请求` =
|
||||
|
||||
| 工单号 | 目标单价 | 理由 | 状态 | 通道 |
|
||||
|---|---|---|---|---|
|
||||
| `工单号` | `目标单价` | `理由` | 未接通(仅保留模拟请求) | 示例议价通道 |
|
||||
|
||||
我们返回*[保留议价意图,等待接通真实通道](`示例议价请求`)*。
|
||||
|
||||
## 更换采购商
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 原采购商标识符 | text | 必填 | 已经不再适合本单的供应商标识 |
|
||||
| 商品 | text | "深沟球轴承" | 要继续寻找供应商的采购品名 |
|
||||
| 原因 | text | "原供应商缺货" | 记录更换的业务原因 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | 原供应商、商品、原因、状态与建议动作;不代表真正更换成功 |
|
||||
|
||||
对于`原采购商标识符`、`商品`="深沟球轴承"和`原因`="原供应商缺货",
|
||||
先保留更换意图,下一步应回到正常供应商名录并重新询价。
|
||||
目前没有接入供应商切换系统,不能直接把固定的候选名单解释成已经选定的下一家。
|
||||
|
||||
后续接通真实通道时,应使用同一份供应商准入规则,排除当前被放弃的供应商,
|
||||
重新比较报价、交期、预算,并重新生成工单;绝不能直接复用上一家供应商的报价。
|
||||
|
||||
`示例更换请求` =
|
||||
|
||||
| 原采购商标识符 | 商品 | 原因 | 状态 | 建议动作 |
|
||||
|---|---|---|---|---|
|
||||
| `原采购商标识符` | `商品` | `原因` | 未接通(仅保留模拟请求) | 重新查询正常供应商并逐家询价 |
|
||||
|
||||
我们返回*[供应商切换通道未接通,保存模拟更换请求](`示例更换请求`)*。
|
||||
|
||||
## _拒绝模拟工单
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 原因 | text | 必填 | 预算、供应商、报价、交期或输入不合格的具体原因 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | 统一的失败记录,ok=False、value=None、error=失败原因 |
|
||||
|
||||
内部辅助函数使用`原因`说明模拟工单没有通过哪一项门禁。
|
||||
所有拒绝出口都必须返回同样形态的结构化结果,便于智能体在读取 `ok` 之后决定是否继续。
|
||||
这里不抛异常、不发送工单,也不通过一个虚假的工单号掩盖失败。
|
||||
|
||||
`失败回执` =
|
||||
|
||||
| ok | value | error |
|
||||
|---|---|---|
|
||||
| False | None | `原因` |
|
||||
|
||||
我们返回*[用于拒绝发单的统一失败回执](`失败回执`)*。
|
||||
@@ -0,0 +1,48 @@
|
||||
# 采购智能体:验收与真实接口接入说明
|
||||
|
||||
## 工程放置方式
|
||||
|
||||
建议把 `index.mq.md` 放入 Marqdo 仓库的 `examples/procurement/`,或可以解析 `lib/table.mq.md` 和 `lib/time.mq.md` 的现有项目中。`import` 中沿用仓库根目录提供的公开标准库。下面命令假设从 `index.mq.md` 所在目录执行。
|
||||
|
||||
此文件目前是**采购业务 SKILL + 本地模拟工具集合**,不是可执行的真实采购交易系统。它仍需要负责决策的 Agent 调度各工具,并保存独立调用日志。
|
||||
|
||||
## 建议执行的验收用例(待运行)
|
||||
|
||||
| 场景 | 命令 | 预期 |
|
||||
|---|---|---|
|
||||
| 正常供应商 | `marqdo call index.mq.md 查询采购商 "采购商状态='正常'" --json` | 只返回 SUP_HD、SUP_JN、SUP_YH |
|
||||
| 黑名单询价 | `marqdo call index.mq.md 查询采购商价格 "采购商标识符='SUP_YY'" 数量=8 --json` | 返回 None |
|
||||
| 暂停供应商询价 | `marqdo call index.mq.md 查询采购商价格 "采购商标识符='SUP_BL'" 数量=8 --json` | 返回 None |
|
||||
| 正常报价 | `marqdo call index.mq.md 查询采购商价格 "采购商标识符='SUP_JN'" 数量=8 --json` | 示例单价 36、总额 288、交期 7 天、可真实下单 False |
|
||||
| 零数量询价 | `marqdo call index.mq.md 查询采购商价格 "采购商标识符='SUP_JN'" 数量=0 --json` | 返回 None |
|
||||
| 正常预算 | `marqdo call index.mq.md 查询余额 已花费=120 --json` | 可用余额 480 |
|
||||
| 用尽预算 | `marqdo call index.mq.md 查询余额 已花费=600 --json` | 余额 0、不能下单 |
|
||||
| 非法预算 | `marqdo call index.mq.md 查询余额 已花费=-1 --json` | 返回 None |
|
||||
| 模拟工单 | `marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=120 --effects time.read,process.control --json` | ok=True、状态为本地模拟未发送、模拟本单后预计占用 408 |
|
||||
| 超预算 | `marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=350 --effects time.read,process.control --json` | ok=False,不生成工单 |
|
||||
| 伪低价 | `marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=35 已花费=0 --effects time.read,process.control --json` | ok=False,不允许自行篡改示例报价 |
|
||||
| 交期不足 | `marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_JN'" 数量=8 单价=36 已花费=0 交付要求天数=5 --effects time.read,process.control --json` | ok=False,因为样例交期 7 天 |
|
||||
| 更快供应商 | `marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_YH'" 数量=8 单价=39 已花费=0 交付要求天数=5 --effects time.read,process.control --json` | ok=True,仅模拟 |
|
||||
| 无效供应商 | `marqdo call index.mq.md 向采购商发工单 "采购商标识符='SUP_YY'" 数量=8 单价=20 已花费=0 --effects time.read,process.control --json` | ok=False |
|
||||
| 缺货回执 | `marqdo call index.mq.md 检查工单 "工单号='MOCK-WO-test'" "模拟回复='缺货'" --json` | 下一步为更换采购商(未接通) |
|
||||
| 不明确回执 | `marqdo call index.mq.md 检查工单 "工单号='MOCK-WO-test'" --json` | 不认定下单成功,转人工或议价 |
|
||||
| 议价占位 | `marqdo call index.mq.md 讲价 "工单号='MOCK-WO-test'" 目标单价=34 --json` | 返回“未接通”的示例议价请求 |
|
||||
| 切换占位 | `marqdo call index.mq.md 更换采购商 "原采购商标识符='SUP_JN'" --json` | 返回“未接通”的示例切换请求 |
|
||||
|
||||
建议随后执行 `marqdo check index.mq.md --narrative-ratio`,并在仓库的 Tree、Bytecode 两种执行后端跑以上场景。上表是**验收设计和预期结果**,不代表这些命令已经在本环境执行。
|
||||
|
||||
## 真实系统接入路线
|
||||
|
||||
1. **供应商主数据**:替换 `查询采购商` 中的示例名录,保持相同字段,并加入供应商状态更新时间与可靠的准入校验。
|
||||
2. **报价**:替换 `查询采购商价格` 的静态样例源,增加供应商确认的报价编号、有效期、税运费与币种信息;只有真实服务确认后才允许真实下单。
|
||||
3. **预算账本**:把 `已花费` 的调用方输入升级为权威持久账本读数,并在工单提交前做原子预算预占、幂等和失败释放,防止并发超预算。
|
||||
4. **真实工单**:真实发送必须以服务端校验的报价、准入、预算预占凭证为依据;保存工单号、状态迁移、外部调用结果和完整审计轨迹。
|
||||
5. **真实回执与议价**:把 `模拟回复` 替换为工单服务查询结果;议价后重新获取报价,不能擅自修改原单价格;切换后重新比价。
|
||||
6. **Agent 层**:由调用者保存每一步的入参、原始结果、选择理由及关联编号。当前函数调用为无持久状态的模拟,尚不能担保跨进程审计或执行重放。
|
||||
|
||||
## 重要限制
|
||||
|
||||
- 本次改写参考了公开仓库源码与规范,但运行环境未提供 `marqdo` 可执行文件,因此没有实际完成 `marqdo check` 或函数调用测试。
|
||||
- 表格金额使用示例整数元;生产环境应使用整数分或经过审计的十进制金额库,避免浮点误差。
|
||||
- 当前“发工单”返回 `ok=True` 只表示本地演练的门禁通过,不表示真实订单提交成功。
|
||||
- 模拟工单号含秒级时间戳,不保证跨调用唯一,也不能充当生产幂等键。
|
||||
@@ -0,0 +1,113 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: AI context — short, explicit source scopes
|
||||
description: Pack user input and caller-provided file/class/function excerpts.
|
||||
import:
|
||||
agent: ext/ai/agent.mq.md
|
||||
plugin: lib/plugin.mq.md
|
||||
json: lib/json.mq.md
|
||||
---
|
||||
|
||||
Pass only the documentation that the next model decision needs. The supplied
|
||||
file/class/function snippets are data; they do not execute as Marqdo source.
|
||||
A future compiler-backed selector can supply these arguments from AST spans.
|
||||
This helper does not yet infer class/function scopes automatically.
|
||||
|
||||
## pack
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| user | text | required | Latest user input |
|
||||
| file | text | "" | File-level description excerpt |
|
||||
| class | text | "" | Current class excerpt |
|
||||
| function | text | "" | Current function excerpt |
|
||||
| budget_tokens | number | 2048 | Small-model context budget |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Bounded ContextPackV2 and compaction evidence |
|
||||
|
||||
Use `user`, `file`="", `class`="", `function`="", `budget_tokens`=2048 as the inputs for this operation.
|
||||
|
||||
Keep the latest request and current function first. Low-priority file context
|
||||
may be dropped under pressure; any important constraint must be in a retained
|
||||
field, not in a discardable tool transcript.
|
||||
|
||||
`items` =
|
||||
|
||||
| @ | origin | trust | priority | text | retain |
|
||||
|---|---|---|---|---|---|
|
||||
| 1 | user | user | 0 | `user` | True |
|
||||
| 2 | function | unknown | 1 | `function` | True |
|
||||
| 3 | class | unknown | 2 | `class` | False |
|
||||
| 4 | file | unknown | 3 | `file` | False |
|
||||
|
||||
Return *[Pack the supplied scopes and compact redundant context](agent.context_pack_compact(items=`items`, budget_tokens=`budget_tokens`, goal=`user`))*.
|
||||
|
||||
|
||||
## scope
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| scope | text | "function" | file / class / function / tool |
|
||||
| class | text | None | Class heading for disambiguation |
|
||||
| function | text | None | Function/tool heading |
|
||||
| source | text | None | Source override; otherwise current entry module |
|
||||
| max_chars | number | 1600 | Maximum Unicode characters |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Exact source excerpt, line range, or explicit ambiguity |
|
||||
|
||||
Use `scope`="function", `class`=None, `function`=None, `source`=None, `max_chars`=1600 as the inputs for this operation.
|
||||
|
||||
The native selector respects Markdown headings and ignores fenced-code heading
|
||||
lookalikes. Repeated function names require a class; missing/ambiguous scopes
|
||||
return an error value, never an unrelated or whole-file fallback.
|
||||
|
||||
We retain **p = [Locate native agent plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load native agent plugin](plugin.load(path=`p`))**.
|
||||
2. *
|
||||
Return *[No native parser available](json.parse(text="{\"ok\":false,\"status\":\"unavailable\",\"text\":null}"))*.
|
||||
|
||||
Return *[Project the requested document scope](agent_context_scope(source=`source`, scope=`scope`, class=`class`, function=`function`, max_chars=`max_chars`))*.
|
||||
|
||||
|
||||
## compose
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| user | text | required | Latest user input |
|
||||
| class | text | required | Current class name |
|
||||
| function | text | required | Current function name |
|
||||
| source | text | None | Override current entry source |
|
||||
| budget_tokens | number | 2048 | Small-model context budget |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | ContextPackV2 or an explicit failed selector |
|
||||
|
||||
Use `user`, `class`, `function`, `source`=None, `budget_tokens`=2048 as the inputs for this operation.
|
||||
|
||||
Project file, class and function scopes independently. Refuse ambiguous names
|
||||
rather than silently importing an unrelated class or the entire source. The
|
||||
latest user input stays in the retained portion of the resulting context pack.
|
||||
|
||||
We retain **f = [Select file preface](scope(scope="file", source=`source`, max_chars=500))**.
|
||||
We retain **c = [Select current class](scope(scope="class", class=`class`, source=`source`, max_chars=800))**.
|
||||
We retain **n = [Select current function](scope(scope="function", class=`class`, function=`function`, source=`source`, max_chars=1500))**.
|
||||
We retain **f_ok = [Check file selection](json.get(value=`f`, key="ok"))**.
|
||||
We retain **c_ok = [Check class selection](json.get(value=`c`, key="ok"))**.
|
||||
We retain **n_ok = [Check function selection](json.get(value=`n`, key="ok"))**.
|
||||
1. not `f_ok`
|
||||
Return *f*.
|
||||
2. not `c_ok`
|
||||
Return *c*.
|
||||
3. not `n_ok`
|
||||
Return *n*.
|
||||
4. *
|
||||
We retain **ft = [Read file preface](json.get(value=`f`, key="text"))**.
|
||||
We retain **ct = [Read class explanation](json.get(value=`c`, key="text"))**.
|
||||
We retain **nt = [Read function explanation](json.get(value=`n`, key="text"))**.
|
||||
Return *[Compact only the selected scopes](pack(user=`user`, file=`ft`, class=`ct`, function=`nt`, budget_tokens=`budget_tokens`))*.
|
||||
@@ -0,0 +1,246 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: AI flow — small-model choices and bounded subtasks
|
||||
description: Short model decisions, verified options and concurrent Marqdo documents.
|
||||
import:
|
||||
llm: ext/ai/llm.mq.md
|
||||
json: lib/json.mq.md
|
||||
plugin: lib/plugin.mq.md
|
||||
subtask: lib/subtask.mq.md
|
||||
---
|
||||
|
||||
This is the thin author-facing layer. A model returns a candidate; Marqdo checks
|
||||
it before routing. Invalid choices are not SKILL paths and never execute.
|
||||
Only the requested function and its inputs need to be in the model prompt.
|
||||
|
||||
## parse_choice
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| reply | text | required | Raw model reply, treated as data |
|
||||
| options | list | required | Allowed names, not paths or commands |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | {ok,value,status} or {ok:false,error} |
|
||||
|
||||
Use `reply`, `options` as the inputs for this operation.
|
||||
|
||||
Parsing accepts one exact name, a labeled name, a fenced name or a 1-based
|
||||
index. Ambiguous prose fails closed. Parsing never runs a tool or SKILL.
|
||||
|
||||
We retain **p = [Locate the installed agent plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load the agent plugin](plugin.load(path=`p`))**.
|
||||
2. *
|
||||
Return *[Missing native parser](json.parse(text="{\"ok\":false,\"status\":\"unavailable\",\"value\":null}"))*.
|
||||
|
||||
Return *[Parse and verify the choice](agent_choice_parse(reply=`reply`, options=`options`))*.
|
||||
|
||||
## choose
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| input | text | required | Current user request or local decision |
|
||||
| options | list | required | Small list of registered option names |
|
||||
| model | any | None | Existing provider model identifier |
|
||||
| repair | bool | True | Allow one format-only repair attempt |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Verified choice result, or explicit failure |
|
||||
|
||||
Use `input`, `options`, `model`=None, `repair`=True as the inputs for this operation.
|
||||
|
||||
Only ask for the option name. A failed first parse can receive one short
|
||||
format correction; never silently select the nearest-looking option.
|
||||
|
||||
We retain **opts = [Encode allowed values](json.stringify(value=`options`))**.
|
||||
We retain **prompt = "Choose exactly one of these options. Return its name only, no explanation:\n" + opts + "\nInput:\n" + input**.
|
||||
We retain **m = [Build one model handle](llm.create(model=`model`))**.
|
||||
We retain **turn = [Ask the model once](m.ask(prompt=`prompt`))**.
|
||||
We retain **err = [Check model transport error](json.get(value=`turn`, key="error"))**.
|
||||
1. `err`
|
||||
Return *turn*.
|
||||
2. *
|
||||
We retain **reply = [Read model answer](json.get(value=`turn`, key="text"))**.
|
||||
We retain **parsed = [Validate the model reply](parse_choice(reply=`reply`, options=`options`))**.
|
||||
We retain **ok = [Read validation status](json.get(value=`parsed`, key="ok"))**.
|
||||
1. `ok`
|
||||
Return *parsed*.
|
||||
2. `repair`
|
||||
We retain **fix = "Your answer was not an exact allowed option. Return only ONE option name from:\n" + opts**.
|
||||
We retain **fixed = [Retry the format only once](m.ask(prompt=`fix`))**.
|
||||
We retain **repair_error = [Read transport error](json.get(value=`fixed`, key="error"))**.
|
||||
1. `repair_error`
|
||||
Return *fixed*.
|
||||
2. *
|
||||
We retain **again = [Read corrected answer](json.get(value=`fixed`, key="text"))**.
|
||||
Return *[Validate the repaired reply](parse_choice(reply=`again`, options=`options`))*.
|
||||
3. *
|
||||
Return *parsed*.
|
||||
|
||||
## parallel
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| tasks | list | required | Existing .mq.md file tasks with arguments |
|
||||
| limit | number | 2 | Maximum simultaneously running tasks |
|
||||
| timeout_ms | number | 30000 | Execution timeout in milliseconds |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Succeeded, partial, failed or uncertain child outcomes |
|
||||
|
||||
Use `tasks`, `limit`=2, `timeout_ms`=30000 as the inputs for this operation.
|
||||
|
||||
Reuse the built-in subtask scheduler. Each child document returns via its
|
||||
`# main`, and successful siblings remain visible if another child fails.
|
||||
|
||||
We retain **results = [Run bounded Marqdo document tasks](subtask.run_many(tasks=`tasks`, limit=`limit`, timeout_ms=`timeout_ms`))**.
|
||||
We retain **p = [Locate native agent plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load native agent plugin](plugin.load(path=`p`))**.
|
||||
Return *[Preserve success, failure and uncertain child outcomes](agent_parallel_report(results=`results`))*.
|
||||
2. *
|
||||
Return *[Native result classifier unavailable](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
|
||||
## input
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable step ID |
|
||||
| question | text | required | User-visible question |
|
||||
| options | list | required | User-visible choices |
|
||||
| source_revision | text | required | Pinned Marqdo source revision |
|
||||
| session_id | text | None | Host-attested session |
|
||||
| principal_ref | text | None | Host-attested user scope |
|
||||
| freeform | bool | True | Allow custom user reply |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | waiting_input or previously committed reply |
|
||||
|
||||
Use `id`, `question`, `options`, `source_revision`, `session_id`=None, `principal_ref`=None, `freeform`=True as the inputs for this operation.
|
||||
|
||||
This does not park an interpreter stack. The caller persists a step-boundary
|
||||
checkpoint, displays the question, and on a new turn uses reply to continue.
|
||||
The host, not the LLM, must attest session and principal IDs.
|
||||
|
||||
We retain **p = [Locate native agent plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load native agent plugin](plugin.load(path=`p`))**.
|
||||
2. *
|
||||
Return *[No native gate available](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
Return *[Persist one waiting input gate](agent_input_open(id=`id`, question=`question`, options=`options`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`, freeform=`freeform`))*.
|
||||
|
||||
## reply
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Existing waiting step |
|
||||
| reply | text | required | New user response |
|
||||
| source_revision | text | required | Current pinned source revision |
|
||||
| session_id | text | None | Host-attested session |
|
||||
| principal_ref | text | None | Host-attested user scope |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Resolved answer, invalid reply or explicit conflict |
|
||||
|
||||
Use `id`, `reply`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
Matching repeated replies are idempotent. A conflicting reply, changed document
|
||||
or changed session fails without executing any SKILL or side effect.
|
||||
|
||||
We retain **p = [Locate native agent plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load native agent plugin](plugin.load(path=`p`))**.
|
||||
2. *
|
||||
Return *[No native gate available](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
Return *[Commit the verified user reply](agent_input_resume(id=`id`, reply=`reply`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
|
||||
|
||||
## enter
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| skill | text | required | Model-selected registered name |
|
||||
| registry | map | required | Trusted name → path mapping |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Subtask result, or blocked unknown skill |
|
||||
|
||||
Use `skill`, `registry` as the inputs for this operation.
|
||||
|
||||
Never execute a raw model-generated path. Resolve a registered skill name to
|
||||
an author-controlled document, then call its `# main` through the normal Marqdo
|
||||
subtask and effect permissions. The caller must provide a trusted registry.
|
||||
|
||||
We retain **path = [Resolve registered SKILL](json.get(value=`registry`, key=`skill`))**.
|
||||
1. not `path`
|
||||
Return *[Unknown skill is blocked](json.parse(text="{\"ok\":false,\"status\":\"unsupported_skill\"}"))*.
|
||||
2. *
|
||||
We retain **task = [Spawn registered Marqdo document](subtask.spawn(path=`path`))**.
|
||||
Return *[Await the subtask result](subtask.wait(id=`task`))*.
|
||||
|
||||
|
||||
## ask
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| prompt | text | required | Short local prompt |
|
||||
| model | any | None | Configured model selection |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | Model reply (not yet a verified tool call) |
|
||||
|
||||
Use `prompt`, `model`=None as the inputs for this operation.
|
||||
|
||||
Ask only what the current function needs. The reply remains data until an
|
||||
explicit verifier accepts it. The LLM adapter owns provider configuration.
|
||||
|
||||
Return *[Ask the configured model](llm.ask(prompt=`prompt`, model=`model`))*.
|
||||
|
||||
## start
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| path | text | required | Trusted registered Marqdo document |
|
||||
| args | list | None | Optional child CLI arguments |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | number | Child task handle |
|
||||
|
||||
Use `path`, `args`=None as the inputs for this operation.
|
||||
|
||||
Start an isolated SKILL document asynchronously, after the calling host has
|
||||
validated its path and required process.exec permission. No model-generated
|
||||
raw path is a valid grant.
|
||||
|
||||
Return *[Start one Marqdo document](subtask.spawn(path=`path`, args=`args`))*.
|
||||
|
||||
## wait
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | number | required | Child task handle |
|
||||
| timeout_ms | number | 30000 | Maximum wait time |
|
||||
| cancel | bool | False | Cancel on timeout |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Child result, timeout or cancellation |
|
||||
|
||||
Use `id`, `timeout_ms`=30000, `cancel`=False as the inputs for this operation.
|
||||
|
||||
A successful wait protocol is not proof of a successful child execution:
|
||||
inspect the child exit code before using its result.
|
||||
|
||||
Return *[Wait for the child](subtask.wait_timeout(id=`id`, timeout_ms=`timeout_ms`, cancel=`cancel`))*.
|
||||
@@ -9,7 +9,11 @@ Start here to choose an AI task. [Model calls](llm.mq.md) own prompts, model con
|
||||
stream collection and usage; [provider adapters](llm/index.mq.md) describe OpenAI-compatible
|
||||
and Ollama requests. [Agents](agent.mq.md) own call-site context, the explicit tool registry,
|
||||
policy routing, observations, workbook planning and continuation. [CoW trials](sandbox.mq.md)
|
||||
own isolated file changes and promotion. [Step routing](policies/step-route.mq.md) is readable
|
||||
own isolated file changes and promotion. [Native flow](flow.mq.md) provides short, verified model choices and bounded document
|
||||
concurrency; [context](context.mq.md) packs explicit source scopes; [recovery](recovery.mq.md)
|
||||
uses the native error policy and versioned checkpoints. These are lightweight
|
||||
interfaces, not a second agent runtime.
|
||||
[Step routing](policies/step-route.mq.md) is readable
|
||||
policy data, not a second agent language. Chinese users can start at [索引](索引.mq.md).
|
||||
|
||||
Begin with this offline stream example; it does not request credentials, install a plugin or
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: AI recovery — safe defaults for short SKILL functions
|
||||
description: Reuse the native error policy, durable checkpoints and effect ledger.
|
||||
import:
|
||||
agent: ext/ai/agent.mq.md
|
||||
---
|
||||
|
||||
Error handling belongs to Marqdo, not the model's prompt. The native policy
|
||||
never blindly repeats uncertain writes. Every resume must revalidate the
|
||||
current permission and source revision; a saved checkpoint is not authorization.
|
||||
|
||||
## decide
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| error | map | required | Structured AgentErrorV1 |
|
||||
| attempts | number | 0 | Number of attempts already made |
|
||||
| effect_class | text | "read" | Declared tool effect |
|
||||
| cancelled | bool | False | Parent cancellation status |
|
||||
| fingerprint_repeats | number | 0 | Identical failures without new evidence |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Safe recovery action with budget |
|
||||
|
||||
Use `error`, `attempts`=0, `effect_class`="read", `cancelled`=False, `fingerprint_repeats`=0 as the inputs for this operation.
|
||||
|
||||
This returns an action, not an automatic retry or permission to execute. For
|
||||
write or unknown effect, consult the effect ledger before taking another step.
|
||||
|
||||
Return *[Select a bounded recovery action](agent.error_decide_retry(error=`error`, attempts=`attempts`, effect_class=`effect_class`, cancelled=`cancelled`, fingerprint_repeats=`fingerprint_repeats`))*.
|
||||
|
||||
## save
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable logical run ID |
|
||||
| task | any | None | Current task or user request |
|
||||
| status | text | "waiting_input" | Current run status |
|
||||
| effect_ledger_watermark | any | None | Durable ledger boundary if available |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | CheckpointV2 write result |
|
||||
|
||||
Use `id`, `task`=None, `status`="waiting_input", `effect_ledger_watermark`=None as the inputs for this operation.
|
||||
|
||||
Use the existing atomic checkpoint writer. When ledger evidence is absent,
|
||||
a resumed writer requires manual review rather than automatic repetition.
|
||||
This function saves metadata; it does not suspend a Rust execution frame.
|
||||
|
||||
Return *[Save a versioned checkpoint](agent.resume_save(id=`id`, task=`task`, status=`status`, checkpoint_v2=True, effect_ledger_watermark=`effect_ledger_watermark`))*.
|
||||
|
||||
## load
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Previously saved logical run ID |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Checkpoint or missing/unsafe recovery status |
|
||||
|
||||
Use `id` as the inputs for this operation.
|
||||
|
||||
Loading a checkpoint does not execute any saved step. The caller must inspect
|
||||
recovery_mode and write_auto_resume before dispatching any effectful operation.
|
||||
|
||||
Return *[Inspect the saved checkpoint](agent.resume_load(id=`id`))*.
|
||||
@@ -0,0 +1,245 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Native AI workflow — durable, short, one-step-at-a-time execution
|
||||
description: Plugin-managed checkpointed decision flow without an external agent runtime.
|
||||
import:
|
||||
plugin: lib/plugin.mq.md
|
||||
json: lib/json.mq.md
|
||||
flow: ext/ai/flow.mq.md
|
||||
subtask: lib/subtask.mq.md
|
||||
---
|
||||
|
||||
Every step is an explicit commit boundary. The plugin stores accepted outputs,
|
||||
refuses stale documents and conflicting decisions, and exposes the next action.
|
||||
The caller must supply trusted session, principal and source revision fields;
|
||||
model text is never an identity or permission token.
|
||||
|
||||
## open
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable run ID |
|
||||
| steps | list | required | 1–128 ordered step records |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Created, resumed, or explicit conflict |
|
||||
|
||||
Use `id`, `steps`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
We retain **p = [Locate the Agent ABI plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load Agent ABI plugin](plugin.load(path=`p`))**.
|
||||
Return *[Open durable workflow](agent_workflow_open(id=`id`, steps=`steps`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *[Missing ABI plugin](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
## next
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable run ID |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Current action or terminal state |
|
||||
|
||||
Use `id`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
We retain **p = [Locate the Agent ABI plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load Agent ABI plugin](plugin.load(path=`p`))**.
|
||||
Return *[Find the next committed boundary](agent_workflow_next(id=`id`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *[Missing ABI plugin](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
## commit
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable run ID |
|
||||
| step_id | text | required | Exact current step |
|
||||
| response | any | required | Completed step output |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Committed next step or explicit failure |
|
||||
|
||||
Use `id`, `step_id`, `response`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
We retain **p = [Locate the Agent ABI plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load Agent ABI plugin](plugin.load(path=`p`))**.
|
||||
Return *[Validate and commit one step](agent_workflow_commit(id=`id`, step_id=`step_id`, response=`response`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *[Missing ABI plugin](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
## cancel
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable run ID |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Cancelled checkpoint status |
|
||||
|
||||
Use `id`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
We retain **p = [Locate the Agent ABI plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load Agent ABI plugin](plugin.load(path=`p`))**.
|
||||
Return *[Commit cancellation](agent_workflow_cancel(id=`id`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *[Missing ABI plugin](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
|
||||
## tick
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Running workflow |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| registry | map | None | Trusted SKILL registry |
|
||||
| model | any | None | Configured LLM |
|
||||
| session_id | text | None | Host-attested session |
|
||||
| principal_ref | text | None | Host-attested principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | New checkpoint state, or waiting_input for the UI |
|
||||
|
||||
Use `id`, `source_revision`, `registry`=None, `model`=None, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
Advance at most one step. Model text is a candidate, never direct
|
||||
execution. Waiting for a user returns immediately without holding a thread.
|
||||
A caller repeats tick after verified completion; UI replies use commit.
|
||||
|
||||
We retain **state = [Load the next action](next(id=`id`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))**.
|
||||
We retain **status = [Read action status](json.get(value=`state`, key="status"))**.
|
||||
1. `status` == "waiting_model"
|
||||
We retain **step = [Read model step](json.get(value=`state`, key="step"))**.
|
||||
We retain **step_id = [Read step identifier](json.get(value=`step`, key="id"))**.
|
||||
We retain **prompt = [Read local prompt](json.get(value=`step`, key="prompt"))**.
|
||||
We retain **options = [Read allowed decisions](json.get(value=`step`, key="options"))**.
|
||||
We retain **answer = [Make a bounded choice](flow.choose(input=`prompt`, options=`options`, model=`model`))**.
|
||||
We retain **valid = [Check model decision](json.get(value=`answer`, key="ok"))**.
|
||||
1. `valid`
|
||||
We retain **chosen = [Read verified model answer](json.get(value=`answer`, key="value"))**.
|
||||
Return *[Commit the model choice](commit(id=`id`, step_id=`step_id`, response=`chosen`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *answer*.
|
||||
2. `status` == "ready_tool"
|
||||
We retain **step = [Read tool step](json.get(value=`state`, key="step"))**.
|
||||
We retain **kind = [Read operation kind](json.get(value=`step`, key="kind"))**.
|
||||
We retain **step_id = [Read step identifier](json.get(value=`step`, key="id"))**.
|
||||
1. `kind` == "parallel"
|
||||
We retain **tasks = [Read child tasks](json.get(value=`step`, key="tasks"))**.
|
||||
We retain **report = [Run bounded parallel documents](flow.parallel(tasks=`tasks`))**.
|
||||
Return *[Commit all child outcomes](commit(id=`id`, step_id=`step_id`, response=`report`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. `kind` == "skill"
|
||||
We retain **name = [Read registered skill name](json.get(value=`step`, key="skill"))**.
|
||||
We retain **out = [Run registered SKILL only](flow.enter(skill=`name`, registry=`registry`))**.
|
||||
Return *[Commit verified child result](commit(id=`id`, step_id=`step_id`, response=`out`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
3. *
|
||||
Return *state*.
|
||||
3. `status` == "ready_return"
|
||||
We retain **step = [Read return step](json.get(value=`state`, key="step"))**.
|
||||
We retain **step_id = [Read step identifier](json.get(value=`step`, key="id"))**.
|
||||
We retain **value = [Read final value](json.get(value=`step`, key="value"))**.
|
||||
Return *[Commit the completed workflow](commit(id=`id`, step_id=`step_id`, response=`value`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
4. *
|
||||
Return *state*.
|
||||
|
||||
|
||||
## retry_plan
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Blocked workflow ID |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Failed-only read-task list or manual_review |
|
||||
|
||||
Use `id`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
Only a parallel step explicitly declared read-only and with no uncertain
|
||||
effects may return a retry plan. Completed siblings are not included.
|
||||
|
||||
We retain **p = [Locate Agent ABI plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load Agent ABI plugin](plugin.load(path=`p`))**.
|
||||
Return *[Select failed read-only children](agent_workflow_retry_plan(id=`id`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *[Native plugin unavailable](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
## retry_commit
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Blocked workflow ID |
|
||||
| results | list | required | New outcomes for failed children only |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Merged persistent report, or still blocked |
|
||||
|
||||
Use `id`, `results`, `source_revision`, `session_id`=None, `principal_ref`=None as the inputs for this operation.
|
||||
|
||||
Re-use successful child results from the checkpoint. New results fill failed
|
||||
slots only, in original order; a newly uncertain outcome blocks further work.
|
||||
|
||||
We retain **p = [Locate Agent ABI plugin](plugin.native_path(name="agent"))**.
|
||||
1. `p`
|
||||
We **[Load Agent ABI plugin](plugin.load(path=`p`))**.
|
||||
Return *[Merge verified read-only retries](agent_workflow_retry_commit(id=`id`, results=`results`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *[Native plugin unavailable](json.parse(text="{\"ok\":false,\"status\":\"unavailable\"}"))*.
|
||||
|
||||
## retry_failed
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Blocked workflow ID |
|
||||
| source_revision | text | required | Pinned source revision |
|
||||
| session_id | text | None | Trusted session |
|
||||
| principal_ref | text | None | Trusted principal |
|
||||
| limit | number | 2 | Max concurrent failed children |
|
||||
| timeout_ms | number | 30000 | Child timeout |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Recovered workflow, partial results or manual review |
|
||||
|
||||
Use `id`, `source_revision`, `session_id`=None, `principal_ref`=None, `limit`=2, `timeout_ms`=30000 as the inputs for this operation.
|
||||
|
||||
Run only the failed read-only tasks returned by the native checkpoint checker.
|
||||
Unknown external writes never reach this path.
|
||||
|
||||
We retain **plan = [Inspect safe retry manifest](retry_plan(id=`id`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))**.
|
||||
We retain **can_retry = [Check permitted recovery](json.get(value=`plan`, key="ok"))**.
|
||||
1. `can_retry`
|
||||
We retain **tasks = [Read failed-only children](json.get(value=`plan`, key="tasks"))**.
|
||||
We retain **outcomes = [Execute failed read-only children only](subtask.run_many(tasks=`tasks`, limit=`limit`, timeout_ms=`timeout_ms`))**.
|
||||
Return *[Merge with preserved completed children](retry_commit(id=`id`, results=`outcomes`, source_revision=`source_revision`, session_id=`session_id`, principal_ref=`principal_ref`))*.
|
||||
2. *
|
||||
Return *plan*.
|
||||
@@ -13,4 +13,5 @@ crate-type = ["cdylib"]
|
||||
[dependencies]
|
||||
marqdo-plugin-sdk = { path = "../../crates/marqdo-plugin-sdk" }
|
||||
serde_json = "1"
|
||||
pulldown-cmark = "0.12"
|
||||
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
|
||||
@@ -0,0 +1,197 @@
|
||||
//! Fail-closed choice parsing for small-model routing.
|
||||
//! This module only extracts a value; it never resolves or executes a SKILL.
|
||||
|
||||
use serde_json::{json, Value};
|
||||
|
||||
fn canonical(s: &str) -> String {
|
||||
s.trim()
|
||||
.trim_matches(|c: char| matches!(c, '"' | '\'' | '`' | '“' | '”' | '‘' | '’'))
|
||||
.trim()
|
||||
.to_lowercase()
|
||||
}
|
||||
|
||||
fn strip_fence(s: &str) -> &str {
|
||||
let s = s.trim();
|
||||
if !s.starts_with("```") {
|
||||
return s;
|
||||
}
|
||||
let Some(start) = s.find('\n') else {
|
||||
return s;
|
||||
};
|
||||
let body = &s[start + 1..];
|
||||
let Some(end) = body.find("```") else {
|
||||
return s;
|
||||
};
|
||||
if !body[end + 3..].trim().is_empty() {
|
||||
return s;
|
||||
}
|
||||
body[..end].trim()
|
||||
}
|
||||
|
||||
fn strip_label(s: &str) -> &str {
|
||||
let s = s.trim();
|
||||
let Some((head, tail)) = s.split_once([':', ':']) else {
|
||||
return s;
|
||||
};
|
||||
if matches!(
|
||||
head.trim().to_lowercase().as_str(),
|
||||
"choice" | "option" | "selected" | "选择" | "选项" | "答案"
|
||||
) {
|
||||
tail.trim()
|
||||
} else {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
fn structured_reply(raw: &str) -> Option<String> {
|
||||
let parsed: Value = serde_json::from_str(raw).ok()?;
|
||||
if let Some(s) = parsed.as_str() {
|
||||
return Some(s.to_string());
|
||||
}
|
||||
if let Some(list) = parsed.as_array() {
|
||||
if list.len() == 1 {
|
||||
return list[0].as_str().map(str::to_string);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
let map = parsed.as_object()?;
|
||||
// Refuse conflicting structured decisions instead of choosing first.
|
||||
let values: Vec<&str> = ["choice", "selected", "option", "选择"]
|
||||
.iter()
|
||||
.filter_map(|key| map.get(*key).and_then(Value::as_str))
|
||||
.collect();
|
||||
if values.is_empty() || values.iter().any(|s| *s != values[0]) {
|
||||
return None;
|
||||
}
|
||||
Some(values[0].to_string())
|
||||
}
|
||||
|
||||
fn single_choice(options: &[String], reply: &str) -> Option<String> {
|
||||
let raw = strip_label(strip_fence(reply));
|
||||
// Structured single-choice replies are accepted only through known fields,
|
||||
// and then still validated against the caller's exact allowlist.
|
||||
let decoded = structured_reply(raw);
|
||||
let raw = decoded.as_deref().unwrap_or(raw);
|
||||
// Small models often prepend a short selection verb. Accept only the
|
||||
// verb followed by a complete allowed value; explanations stay invalid.
|
||||
let raw = raw.trim();
|
||||
let raw = ["我选择", "我选", "I choose ", "I pick ", "选中"].iter()
|
||||
.find_map(|p| raw.strip_prefix(p).map(str::trim))
|
||||
.unwrap_or(raw);
|
||||
let value = canonical(raw);
|
||||
// Never infer a routing decision from arbitrary prose.
|
||||
let matches: Vec<&String> = options
|
||||
.iter()
|
||||
.filter(|opt| canonical(opt) == value)
|
||||
.collect();
|
||||
if matches.len() == 1 {
|
||||
return Some(matches[0].clone());
|
||||
}
|
||||
// A bare number denotes a 1-based index into the allowed list.
|
||||
if let Ok(index) = value.parse::<usize>() {
|
||||
if index > 0 && index <= options.len() {
|
||||
return Some(options[index - 1].clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Parse one permitted option from a small model response.
|
||||
/// Returns a status rather than treating arbitrary prose as a tool target.
|
||||
pub fn parse_choice(args: &Value) -> Result<Value, String> {
|
||||
let reply = args
|
||||
.get("reply")
|
||||
.and_then(Value::as_str)
|
||||
.ok_or_else(|| "missing text `reply`".to_string())?;
|
||||
let options = args
|
||||
.get("options")
|
||||
.and_then(Value::as_array)
|
||||
.ok_or_else(|| "options must be an array of strings".to_string())?;
|
||||
if options.is_empty() || options.len() > 64 {
|
||||
return Err("options must contain 1..=64 entries".to_string());
|
||||
}
|
||||
let mut allowed = Vec::with_capacity(options.len());
|
||||
for option in options {
|
||||
let name = option
|
||||
.as_str()
|
||||
.ok_or_else(|| "each option must be a string".to_string())?;
|
||||
if name.trim().is_empty() || name.len() > 128 {
|
||||
return Err("each option must contain 1..=128 UTF-8 bytes".to_string());
|
||||
}
|
||||
if allowed.iter().any(|p: &String| canonical(p) == canonical(name)) {
|
||||
return Err("options must be unique after normalization".to_string());
|
||||
}
|
||||
allowed.push(name.to_string());
|
||||
}
|
||||
if let Some(value) = single_choice(&allowed, reply) {
|
||||
Ok(json!({"ok": true, "value": value, "status": "accepted"}))
|
||||
} else {
|
||||
Ok(json!({
|
||||
"ok": false,
|
||||
"value": null,
|
||||
"status": "invalid",
|
||||
"error": {
|
||||
"code": "model.invalid_choice",
|
||||
"category": "invalid_output",
|
||||
"retryable": false,
|
||||
"recovery_action": "repair_output"
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn check(reply: &str) -> Value {
|
||||
parse_choice(&json!({"options": ["chat", "office"], "reply": reply})).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_exact_label_fence_and_number() {
|
||||
assert_eq!(check("chat")["value"], "chat");
|
||||
assert_eq!(check(" CHAT ")["value"], "chat");
|
||||
assert_eq!(check("选择:office")["value"], "office");
|
||||
assert_eq!(check("```text\nchat\n```")["value"], "chat");
|
||||
assert_eq!(check("2")["value"], "office");
|
||||
assert_eq!(check("我选择 chat")["value"], "chat");
|
||||
assert_eq!(check("I choose office")["value"], "office");
|
||||
assert_eq!(check(r#"{"choice":"chat"}"#)["value"], "chat");
|
||||
assert_eq!(check("[\"office\"]")["value"], "office");
|
||||
assert_eq!(check("```json\n{\"selected\":\"office\"}\n```")["value"], "office");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_prose_conflicts_and_out_of_range() {
|
||||
for reply in ["请选择 chat", "chat 或 office", "choice: chat,因为更合适", "3", ""] {
|
||||
let result = check(reply);
|
||||
assert_eq!(result["ok"], false, "accepted {reply:?}");
|
||||
assert_eq!(result["value"], Value::Null);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_conflicting_structured_decisions() {
|
||||
assert_eq!(check(r#"{"choice":"chat","option":"office"}"#)["ok"], false);
|
||||
assert_eq!(check(r#"{"choice":"../private.mq.md"}"#)["ok"], false);
|
||||
assert_eq!(check(r#"["chat","office"]"#)["ok"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_options_before_parsing() {
|
||||
for options in [
|
||||
json!([]),
|
||||
json!(["chat", "CHAT"]),
|
||||
json!(["chat", 10]),
|
||||
json!([""]),
|
||||
] {
|
||||
assert!(parse_choice(&json!({"options": options, "reply": "chat"})).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn never_extracts_arbitrary_skill_path() {
|
||||
assert_eq!(check("../../private.mq.md")["ok"], false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
//! Markdown-heading-backed, bounded context projection for Marqdo SKILLs.
|
||||
//! This is source selection, not execution: quoted text never becomes tool authority.
|
||||
//! Markdown events ignore fenced-code headings; ambiguous functions fail closed.
|
||||
|
||||
use pulldown_cmark::{Event, HeadingLevel, Parser, Tag, TagEnd};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Section {
|
||||
level: u8,
|
||||
title: String,
|
||||
start: usize,
|
||||
}
|
||||
|
||||
fn level_num(h: HeadingLevel) -> u8 {
|
||||
match h {
|
||||
HeadingLevel::H1 => 1,
|
||||
HeadingLevel::H2 => 2,
|
||||
HeadingLevel::H3 => 3,
|
||||
HeadingLevel::H4 => 4,
|
||||
HeadingLevel::H5 => 5,
|
||||
HeadingLevel::H6 => 6,
|
||||
}
|
||||
}
|
||||
|
||||
fn headings(source: &str) -> Vec<Section> {
|
||||
let mut out = Vec::new();
|
||||
let mut pending: Option<Section> = None;
|
||||
for (event, range) in Parser::new(source).into_offset_iter() {
|
||||
match event {
|
||||
Event::Start(Tag::Heading { level, .. }) => {
|
||||
pending = Some(Section {
|
||||
level: level_num(level),
|
||||
title: String::new(),
|
||||
start: range.start,
|
||||
});
|
||||
}
|
||||
Event::Text(text) | Event::Code(text) => {
|
||||
if let Some(section) = pending.as_mut() {
|
||||
section.title.push_str(&text);
|
||||
}
|
||||
}
|
||||
Event::End(TagEnd::Heading(_)) => {
|
||||
if let Some(mut section) = pending.take() {
|
||||
section.title = section.title.trim().to_string();
|
||||
out.push(section);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn class_for(headings: &[Section], index: usize) -> Option<&str> {
|
||||
headings[..index]
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|h| h.level == 1)
|
||||
.map(|h| h.title.as_str())
|
||||
}
|
||||
|
||||
fn frontmatter_end(source: &str) -> usize {
|
||||
if !source.starts_with("---\n") {
|
||||
return 0;
|
||||
}
|
||||
let mut pos = 4;
|
||||
for line in source[4..].split_inclusive('\n') {
|
||||
pos += line.len();
|
||||
if line.trim() == "---" {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
fn truncate_chars(text: &str, max_chars: usize) -> (&str, bool) {
|
||||
let Some((end, _)) = text.char_indices().nth(max_chars) else {
|
||||
return (text, false);
|
||||
};
|
||||
(&text[..end], true)
|
||||
}
|
||||
|
||||
pub fn project(args: &Value) -> Result<Value, String> {
|
||||
let source = match args.get("source").and_then(Value::as_str) {
|
||||
Some(s) => s.to_string(),
|
||||
None => crate::host_query_json("module_source")?
|
||||
.as_str()
|
||||
.ok_or_else(|| "module_source unavailable".to_string())?
|
||||
.to_string(),
|
||||
};
|
||||
let scope = args.get("scope").and_then(Value::as_str).unwrap_or("function");
|
||||
let class = args.get("class").and_then(Value::as_str);
|
||||
let function = args.get("function").and_then(Value::as_str);
|
||||
let maximum = args
|
||||
.get("max_chars")
|
||||
.and_then(Value::as_u64)
|
||||
.unwrap_or(1600)
|
||||
.clamp(32, 16000) as usize;
|
||||
// YAML frontmatter may look like a setext Markdown heading; never treat it
|
||||
// as a Marqdo class or function boundary.
|
||||
let front_end = frontmatter_end(&source);
|
||||
let marks: Vec<Section> = headings(&source)
|
||||
.into_iter()
|
||||
.filter(|heading| heading.start >= front_end)
|
||||
.collect();
|
||||
let results: Vec<(usize, usize)> = match scope {
|
||||
"file" => {
|
||||
let end = marks.first().map_or(source.len(), |h| h.start);
|
||||
let start = frontmatter_end(&source).min(end);
|
||||
vec![(start, end)]
|
||||
}
|
||||
"class" | "function" | "tool" => {
|
||||
let level = match scope {
|
||||
"class" => 1,
|
||||
"function" => 2,
|
||||
_ => 3,
|
||||
};
|
||||
let target = if level == 1 { class } else { function };
|
||||
let wanted = target.ok_or_else(|| format!("{scope} selector required"))?;
|
||||
marks
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(i, h)| {
|
||||
h.level == level
|
||||
&& h.title == wanted
|
||||
&& (level == 1 || class.is_none() || class_for(&marks, *i) == class)
|
||||
})
|
||||
.map(|(i, h)| {
|
||||
let end = marks[i + 1..]
|
||||
.iter()
|
||||
.find(|next| next.level <= level)
|
||||
.map_or(source.len(), |next| next.start);
|
||||
let end = if level == 1 {
|
||||
marks[i + 1..]
|
||||
.iter()
|
||||
.find(|next| next.level <= 2)
|
||||
.map_or(end, |next| next.start)
|
||||
} else {
|
||||
end
|
||||
};
|
||||
(h.start, end)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
_ => return Err("scope must be file, class, function or tool".to_string()),
|
||||
};
|
||||
if results.len() != 1 {
|
||||
return Ok(json!({
|
||||
"ok": false,
|
||||
"status": if results.is_empty() { "not_found" } else { "ambiguous" },
|
||||
"scope": scope,
|
||||
"matches": results.len(),
|
||||
"text": null
|
||||
}));
|
||||
}
|
||||
let (start, end) = results[0];
|
||||
let (slice, truncated) = truncate_chars(source[start..end].trim(), maximum);
|
||||
let line_start = source[..start].bytes().filter(|c| *c == b'\n').count() + 1;
|
||||
Ok(json!({
|
||||
"ok": true, "status": "accepted", "scope": scope,
|
||||
"text": slice, "truncated": truncated,
|
||||
"start_byte": start, "end_byte": end,
|
||||
"start_line": line_start,
|
||||
"source_kind": "markdown_headings"
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const DOC: &str = "---\ntitle: example\n---\nEntry instructions.\n\n# main\nClass instructions.\n\n## route\nReal body.\n```md\n## route\nfake\n```\n\n## other\nOther body.\n\n# helper\nHelper prose.\n\n## route\nSecond body.\n";
|
||||
|
||||
#[test]
|
||||
fn scope_is_bounded_and_fenced_headings_ignored() {
|
||||
let v = project(&json!({"source": DOC, "scope": "function", "class": "main", "function": "route"})).unwrap();
|
||||
assert_eq!(v["ok"], true);
|
||||
assert!(v["text"].as_str().unwrap().contains("Real body."));
|
||||
assert!(v["text"].as_str().unwrap().contains("fake"));
|
||||
assert!(!v["text"].as_str().unwrap().contains("Other body."));
|
||||
assert!(!v["text"].as_str().unwrap().contains("Second body."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ambiguous_function_fails_closed() {
|
||||
let v = project(&json!({"source": DOC, "scope": "function", "function": "route"})).unwrap();
|
||||
assert_eq!(v["status"], "ambiguous");
|
||||
assert_eq!(v["text"], Value::Null);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_scope_removes_frontmatter_and_class_prose_excludes_functions() {
|
||||
let a = project(&json!({"source": DOC, "scope": "file"})).unwrap();
|
||||
assert_eq!(a["text"], "Entry instructions.");
|
||||
let b = project(&json!({"source": DOC, "scope": "class", "class": "main"})).unwrap();
|
||||
assert!(b["text"].as_str().unwrap().contains("Class instructions."));
|
||||
assert!(!b["text"].as_str().unwrap().contains("Real body."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_truncation_does_not_split_characters() {
|
||||
let v = project(&json!({"source": "汉".repeat(100), "scope": "file", "max_chars": 32})).unwrap();
|
||||
assert_eq!(v["text"].as_str().unwrap().chars().count(), 32);
|
||||
assert_eq!(v["truncated"], true);
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,8 @@ fn ensure_dir(root: &Path) -> Result<(), String> {
|
||||
fs::create_dir_all(root).map_err(|e| format!("effects mkdir: {e}"))
|
||||
}
|
||||
|
||||
static EFFECT_TEMP_SEQUENCE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
|
||||
fn atomic_write_json(path: &Path, doc: &Value) -> Result<(), String> {
|
||||
let parent = path
|
||||
.parent()
|
||||
@@ -102,7 +104,8 @@ fn atomic_write_json(path: &Path, doc: &Value) -> Result<(), String> {
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("op.json"),
|
||||
std::process::id(),
|
||||
now_rfc3339().replace(':', "")
|
||||
format!("{}-{}", now_rfc3339().replace(':', ""),
|
||||
EFFECT_TEMP_SEQUENCE.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
|
||||
);
|
||||
let tmp = parent.join(tmp_name);
|
||||
let text = serde_json::to_string_pretty(doc).map_err(|e| e.to_string())?;
|
||||
@@ -425,12 +428,16 @@ fn fnv64(s: &str) -> u64 {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// Avoid process-global set_current_dir: Rust executes tests concurrently.
|
||||
// Keep each ledger in its own repository-relative, unique directory.
|
||||
static SCRATCH_SEQ: std::sync::atomic::AtomicU64 =
|
||||
std::sync::atomic::AtomicU64::new(0);
|
||||
|
||||
fn scratch(tag: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
let seq = SCRATCH_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let dir = PathBuf::from("target").join(format!(
|
||||
"mq-effects-{}-{}-{}",
|
||||
tag,
|
||||
std::process::id(),
|
||||
now_rfc3339().replace(':', "")
|
||||
tag, std::process::id(), seq
|
||||
));
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
@@ -440,14 +447,13 @@ mod tests {
|
||||
#[test]
|
||||
fn prepare_dedupe_and_collision() {
|
||||
let dir = scratch("prep");
|
||||
let prev = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
let ledger_dir = dir.join("led").to_string_lossy().to_string();
|
||||
let a = effects_prepare(&json!({
|
||||
"operation_id": "op1",
|
||||
"idempotency_key": "idem1",
|
||||
"args_digest": "sha256:a",
|
||||
"effect_class": "write",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run1",
|
||||
}))
|
||||
.unwrap();
|
||||
@@ -458,7 +464,7 @@ mod tests {
|
||||
"operation_id": "op1",
|
||||
"idempotency_key": "idem1",
|
||||
"args_digest": "sha256:a",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(again["deduped"], true);
|
||||
@@ -467,43 +473,41 @@ mod tests {
|
||||
"operation_id": "op2",
|
||||
"idempotency_key": "idem1",
|
||||
"args_digest": "sha256:b",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}));
|
||||
assert!(clash.unwrap_err().contains("collision"));
|
||||
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transition_and_watermark_gates_write_resume() {
|
||||
let dir = scratch("wm");
|
||||
let prev = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
let ledger_dir = dir.join("led").to_string_lossy().to_string();
|
||||
effects_prepare(&json!({
|
||||
"operation_id": "op_w",
|
||||
"idempotency_key": "idem_w",
|
||||
"args_digest": "sha256:w",
|
||||
"effect_class": "write",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run1",
|
||||
}))
|
||||
.unwrap();
|
||||
effects_transition(&json!({
|
||||
"operation_id": "op_w",
|
||||
"state": "started",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap();
|
||||
// Crash window: unknown — write auto-resume must stay closed.
|
||||
effects_transition(&json!({
|
||||
"operation_id": "op_w",
|
||||
"state": "unknown",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap();
|
||||
let wm1 = effects_watermark(&json!({
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run1",
|
||||
}))
|
||||
.unwrap();
|
||||
@@ -513,12 +517,12 @@ mod tests {
|
||||
effects_reconcile(&json!({
|
||||
"operation_id": "op_w",
|
||||
"outcome": "committed",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"result_ref": "receipt:1",
|
||||
}))
|
||||
.unwrap();
|
||||
let wm2 = effects_watermark(&json!({
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run1",
|
||||
}))
|
||||
.unwrap();
|
||||
@@ -526,7 +530,6 @@ mod tests {
|
||||
assert_eq!(wm2["open_unknown"], 0);
|
||||
assert!(wm2["watermark"].as_str().unwrap().starts_with("sha256-lite:"));
|
||||
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
@@ -535,32 +538,31 @@ mod tests {
|
||||
// Write "succeeds" locally only after reconcile; retry while unknown must not
|
||||
// look write_auto_resume_safe (MA-T03 watermark gate).
|
||||
let dir = scratch("mat03");
|
||||
let prev = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
let ledger_dir = dir.join("led").to_string_lossy().to_string();
|
||||
effects_prepare(&json!({
|
||||
"operation_id": "op_kill",
|
||||
"idempotency_key": "run|s|write_probe|sha256-lite:1",
|
||||
"args_digest": "sha256-lite:1",
|
||||
"effect_class": "write",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run_kill",
|
||||
}))
|
||||
.unwrap();
|
||||
effects_transition(&json!({
|
||||
"operation_id": "op_kill",
|
||||
"state": "started",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap();
|
||||
// Crash before commit:
|
||||
effects_transition(&json!({
|
||||
"operation_id": "op_kill",
|
||||
"state": "unknown",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap();
|
||||
let wm = effects_watermark(&json!({
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run_kill",
|
||||
}))
|
||||
.unwrap();
|
||||
@@ -572,7 +574,7 @@ mod tests {
|
||||
"idempotency_key": "run|s|write_probe|sha256-lite:1",
|
||||
"args_digest": "sha256-lite:1",
|
||||
"effect_class": "write",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run_kill",
|
||||
}))
|
||||
.unwrap();
|
||||
@@ -582,42 +584,39 @@ mod tests {
|
||||
effects_reconcile(&json!({
|
||||
"operation_id": "op_kill",
|
||||
"outcome": "committed",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"result_ref": "effect:op_kill",
|
||||
}))
|
||||
.unwrap();
|
||||
let wm2 = effects_watermark(&json!({
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
"logical_run_id": "run_kill",
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(wm2["write_auto_resume_safe"], true);
|
||||
assert_eq!(wm2["pending_writes"], 0);
|
||||
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn illegal_skip_started() {
|
||||
let dir = scratch("bad");
|
||||
let prev = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
let ledger_dir = dir.join("led").to_string_lossy().to_string();
|
||||
effects_prepare(&json!({
|
||||
"operation_id": "op_x",
|
||||
"idempotency_key": "idem_x",
|
||||
"args_digest": "sha256:x",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap();
|
||||
let err = effects_transition(&json!({
|
||||
"operation_id": "op_x",
|
||||
"state": "committed",
|
||||
"ledger_dir": "led",
|
||||
"ledger_dir": ledger_dir.clone(),
|
||||
}))
|
||||
.unwrap_err();
|
||||
assert!(err.contains("illegal transition"));
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,10 @@ pub fn decide_retry(args: &Value) -> Result<Value, String> {
|
||||
.get("max_arg_repairs")
|
||||
.and_then(|v| v.as_u64())
|
||||
.unwrap_or(1) as u32;
|
||||
let max_output_repair = args
|
||||
.get("max_output_repairs")
|
||||
.and_then(|v| v.as_u64())
|
||||
.unwrap_or(1) as u32;
|
||||
let effect_class = args
|
||||
.get("effect_class")
|
||||
.and_then(|v| v.as_str())
|
||||
@@ -145,6 +149,12 @@ pub fn decide_retry(args: &Value) -> Result<Value, String> {
|
||||
"invalid_arguments" if recovery == "repair_args" && attempts < max_arg_repair => Ok(
|
||||
decision("repair_args", "one_arg_repair", attempts, max_arg_repair),
|
||||
),
|
||||
"invalid_output" if recovery == "repair_output" && attempts < max_output_repair => Ok(
|
||||
decision("repair_output", "one_format_repair", attempts, max_output_repair),
|
||||
),
|
||||
"context_overflow" if recovery == "compact_context" && attempts == 0 => Ok(
|
||||
decision("compact_context", "one_bounded_compaction", attempts, 1),
|
||||
),
|
||||
"auth" | "forbidden" | "policy_denied" => Ok(decision(
|
||||
"needs_input",
|
||||
category,
|
||||
@@ -172,13 +182,17 @@ fn decision(action: &str, reason: &str, attempts: u32, max_attempts: u32) -> Val
|
||||
"reason": reason,
|
||||
"attempts_used": attempts,
|
||||
"max_attempts": max_attempts,
|
||||
"auto": matches!(action, "retry_step" | "repair_args"),
|
||||
"auto": matches!(action, "retry_step" | "repair_args" | "repair_output" | "compact_context"),
|
||||
})
|
||||
}
|
||||
|
||||
fn infer_category(code: &str) -> &'static str {
|
||||
let c = code.to_ascii_lowercase();
|
||||
if c.contains("timeout") || c.contains("429") || c.contains("5xx") || c.contains("connect") {
|
||||
if c.contains("context_overflow") || c.contains("context_length") {
|
||||
"context_overflow"
|
||||
} else if c.contains("invalid_choice") || c.contains("invalid_output") {
|
||||
"invalid_output"
|
||||
} else if c.contains("timeout") || c.contains("429") || c.contains("5xx") || c.contains("connect") {
|
||||
"transient"
|
||||
} else if c.contains("schema") || c.contains("argument") {
|
||||
"invalid_arguments"
|
||||
@@ -212,6 +226,8 @@ fn default_recovery(category: &str, effect_state: &str) -> &'static str {
|
||||
match category {
|
||||
"transient" => "retry_step",
|
||||
"invalid_arguments" => "repair_args",
|
||||
"invalid_output" => "repair_output",
|
||||
"context_overflow" => "compact_context",
|
||||
"auth" | "forbidden" | "policy_denied" | "needs_input" => "needs_input",
|
||||
"budget_exhausted" => "return_partial",
|
||||
"cancelled" => "stop",
|
||||
@@ -259,6 +275,27 @@ mod tests {
|
||||
assert_eq!(d["auto"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_repair_is_bounded_and_read_only() {
|
||||
let err = make_error(&json!({"code": "model.invalid_choice"})).unwrap();
|
||||
assert_eq!(err["category"], "invalid_output");
|
||||
let first = decide_retry(&json!({"error": err, "attempts": 0})).unwrap();
|
||||
assert_eq!(first["action"], "repair_output");
|
||||
let next = decide_retry(&json!({"error": err, "attempts": 1})).unwrap();
|
||||
assert_eq!(next["action"], "stop");
|
||||
let write = decide_retry(&json!({
|
||||
"error": err, "attempts": 0, "effect_class": "write"
|
||||
})).unwrap();
|
||||
assert_eq!(write["action"], "manual_review");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compaction_is_not_an_unbounded_model_loop() {
|
||||
let err = make_error(&json!({"code": "model.context_overflow"})).unwrap();
|
||||
assert_eq!(decide_retry(&json!({"error": err, "attempts": 0})).unwrap()["action"], "compact_context");
|
||||
assert_eq!(decide_retry(&json!({"error": err, "attempts": 1})).unwrap()["action"], "stop");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fingerprint_loop_stops() {
|
||||
let err = make_error(&json!({"code": "tool.timeout"})).unwrap();
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
//! Durable input gates for document-native SKILLs.
|
||||
//! Pausing is a committed *step boundary*, not serialization of a Rust stack.
|
||||
//! The caller resumes the next documented step with the saved answer.
|
||||
|
||||
use std::fs::{self, OpenOptions};
|
||||
use std::path::PathBuf;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::resume;
|
||||
|
||||
struct GateLock(PathBuf);
|
||||
impl Drop for GateLock {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::remove_file(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
fn text_arg<'a>(args: &'a Value, key: &str) -> Result<&'a str, String> {
|
||||
args.get(key)
|
||||
.and_then(Value::as_str)
|
||||
.filter(|s| !s.is_empty())
|
||||
.ok_or_else(|| format!("missing text `{key}`"))
|
||||
}
|
||||
|
||||
fn valid_id(s: &str) -> bool {
|
||||
!s.is_empty()
|
||||
&& s.len() <= 100
|
||||
&& s.bytes().all(|c| c.is_ascii_alphanumeric() || c == b'-' || c == b'_')
|
||||
}
|
||||
|
||||
fn root(args: &Value) -> Result<PathBuf, String> {
|
||||
let name = args
|
||||
.get("resume_dir")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or(".marqdo/agent-resume");
|
||||
let path = PathBuf::from(name);
|
||||
if path.is_absolute()
|
||||
|| path.components().any(|part| matches!(part, std::path::Component::ParentDir))
|
||||
{
|
||||
return Err("resume_dir must be a relative path without '..'".to_string());
|
||||
}
|
||||
fs::create_dir_all(&path).map_err(|e| format!("input gate mkdir: {e}"))?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
fn lock(args: &Value, id: &str) -> Result<GateLock, String> {
|
||||
if !valid_id(id) {
|
||||
return Err("input gate id must be 1..=100 ASCII letters, numbers, '_' or '-'".into());
|
||||
}
|
||||
let path = root(args)?.join(format!("{id}.input-lock"));
|
||||
OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&path)
|
||||
.map_err(|e| format!("input gate is busy or needs reconciliation: {e}"))?;
|
||||
Ok(GateLock(path))
|
||||
}
|
||||
|
||||
fn options(args: &Value) -> Result<Value, String> {
|
||||
let choices = args.get("options").and_then(Value::as_array)
|
||||
.ok_or_else(|| "options must be a list of 1..=32 short labels".to_string())?;
|
||||
if choices.is_empty() || choices.len() > 32 {
|
||||
return Err("options must contain 1..=32 choices".into());
|
||||
}
|
||||
for v in choices {
|
||||
let Some(s) = v.as_str() else {
|
||||
return Err("every option must be text".into());
|
||||
};
|
||||
if s.is_empty() || s.len() > 256 {
|
||||
return Err("each option must contain 1..=256 bytes".into());
|
||||
}
|
||||
}
|
||||
let empty = crate::choice::parse_choice(&json!({
|
||||
"options": choices, "reply": "__invalid_choice_probe__"
|
||||
}))?;
|
||||
// The parser checks duplicates and option size; the probe must not be accepted.
|
||||
if empty["ok"] == true {
|
||||
return Err("invalid reserved choice option".into());
|
||||
}
|
||||
Ok(Value::Array(choices.to_vec()))
|
||||
}
|
||||
|
||||
/// Create a durable waiting-input checkpoint. Repeated open never resets a
|
||||
/// previously answered gate. No external effect is performed.
|
||||
pub fn input_open(args: &Value) -> Result<Value, String> {
|
||||
let id = text_arg(args, "id")?;
|
||||
let _lock = lock(args, id)?;
|
||||
let labels = options(args)?;
|
||||
let query = text_arg(args, "question")?;
|
||||
let version = text_arg(args, "source_revision")?;
|
||||
let read_args = json!({"id": id, "resume_dir": args.get("resume_dir")});
|
||||
let existing = resume::resume_load(&read_args)?;
|
||||
if existing["found"] == true {
|
||||
let meta = &existing["meta"];
|
||||
let same = meta["question"] == query
|
||||
&& meta["options"] == labels
|
||||
&& meta["source_revision"] == version
|
||||
&& meta["session_id"] == *args.get("session_id").unwrap_or(&Value::Null)
|
||||
&& meta["principal_ref"] == *args.get("principal_ref").unwrap_or(&Value::Null);
|
||||
if same && existing["ok"] == true {
|
||||
let status = existing["status"].as_str().unwrap_or("unknown");
|
||||
return Ok(json!({
|
||||
"ok": true, "id": id, "status": status,
|
||||
"value": existing["result"], "reused": true,
|
||||
"question": query, "options": labels
|
||||
}));
|
||||
}
|
||||
return Ok(json!({"ok":false,"id":id,"status":"conflict",
|
||||
"error":{"code":"input.stale_or_reused_gate"}}));
|
||||
}
|
||||
let saved = resume::resume_save(&json!({
|
||||
"id": id, "resume_dir": args.get("resume_dir"),
|
||||
"checkpoint_v2": true,
|
||||
"status": "waiting_input",
|
||||
"task": query,
|
||||
"meta": {
|
||||
"question": query,
|
||||
"options": labels,
|
||||
"source_revision": version,
|
||||
"session_id": args.get("session_id").unwrap_or(&Value::Null),
|
||||
"principal_ref": args.get("principal_ref").unwrap_or(&Value::Null),
|
||||
"freeform": args.get("freeform").and_then(Value::as_bool).unwrap_or(true)
|
||||
}
|
||||
}))?;
|
||||
if saved["ok"] != true {
|
||||
return Err("unable to save input checkpoint".into());
|
||||
}
|
||||
Ok(json!({"ok": true, "id":id, "status":"waiting_input", "value":null,
|
||||
"question":query,"options":labels,"reused":false}))
|
||||
}
|
||||
|
||||
/// Resume a specific gate with a user response. Only a committed answer can be
|
||||
/// replayed: different duplicate replies conflict instead of re-triggering work.
|
||||
pub fn input_resume(args: &Value) -> Result<Value, String> {
|
||||
let id = text_arg(args, "id")?;
|
||||
let _lock = lock(args, id)?;
|
||||
let reply = text_arg(args, "reply")?;
|
||||
if reply.len() > 4096 {
|
||||
return Err("input reply must not exceed 4096 bytes".into());
|
||||
}
|
||||
let version = text_arg(args, "source_revision")?;
|
||||
let read_args = json!({"id": id, "resume_dir": args.get("resume_dir")});
|
||||
let existing = resume::resume_load(&read_args)?;
|
||||
if existing["ok"] != true || existing["schema"] != "CheckpointV2" {
|
||||
return Ok(json!({"ok":false,"status":"not_found_or_corrupt","id":id}));
|
||||
}
|
||||
let meta = &existing["meta"];
|
||||
if meta["source_revision"] != version
|
||||
|| meta["session_id"] != *args.get("session_id").unwrap_or(&Value::Null)
|
||||
|| meta["principal_ref"] != *args.get("principal_ref").unwrap_or(&Value::Null)
|
||||
{
|
||||
return Ok(json!({"ok":false,"status":"conflict","id":id,
|
||||
"error":{"code":"input.scope_or_revision_changed"}}));
|
||||
}
|
||||
// Normalize the answer before duplicate detection: the index "2" and
|
||||
// the selected label "office" must be the same committed response.
|
||||
let allowed = crate::choice::parse_choice(&json!({
|
||||
"options": meta["options"], "reply": reply
|
||||
}))?;
|
||||
let normalized = if allowed["ok"] == true {
|
||||
allowed["value"].clone()
|
||||
} else if meta["freeform"] == true && !reply.trim().is_empty() {
|
||||
json!(reply.trim())
|
||||
} else {
|
||||
return Ok(json!({"ok":false,"status":"invalid","id":id,
|
||||
"error":{"code":"input.invalid_choice"}}));
|
||||
};
|
||||
if existing["status"] == "resumed" {
|
||||
if existing["result"] == normalized {
|
||||
return Ok(json!({"ok":true,"status":"resumed","id":id,
|
||||
"value":normalized,"reused":true}));
|
||||
}
|
||||
return Ok(json!({"ok":false,"status":"conflict","id":id,
|
||||
"error":{"code":"input.already_answered"}}));
|
||||
}
|
||||
if existing["status"] != "waiting_input" {
|
||||
return Ok(json!({"ok":false,"status":"conflict","id":id}));
|
||||
}
|
||||
let saved = resume::resume_save(&json!({
|
||||
"id": id, "resume_dir": args.get("resume_dir"),
|
||||
"checkpoint_v2": true,
|
||||
"status": "resumed",
|
||||
"task": existing["task"],
|
||||
"meta": meta,
|
||||
"result": normalized
|
||||
}))?;
|
||||
if saved["ok"] != true {
|
||||
return Err("unable to commit resumed input".into());
|
||||
}
|
||||
Ok(json!({"ok":true,"status":"resumed","id":id,
|
||||
"value":normalized,"reused":false}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
static SEQ: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
fn fixture() -> (String, String) {
|
||||
let id = format!("gate_{}_{}",std::process::id(),SEQ.fetch_add(1,Ordering::Relaxed));
|
||||
let dir = format!("target/mq-gate-test-{id}");
|
||||
(id, dir)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn persists_answer_without_duplicate_side_effect_or_changed_reply() {
|
||||
let (id, dir) = fixture();
|
||||
let initial = json!({"id":id,"resume_dir":dir,"question":"Choose?",
|
||||
"options":["chat","office"],"source_revision":"v1",
|
||||
"session_id":"s1","principal_ref":"u1","freeform":false});
|
||||
assert_eq!(input_open(&initial).unwrap()["status"], "waiting_input");
|
||||
assert_eq!(input_open(&initial).unwrap()["reused"], true);
|
||||
let v = json!({"id":id,"resume_dir":dir,"reply":"2",
|
||||
"source_revision":"v1","session_id":"s1","principal_ref":"u1"});
|
||||
assert_eq!(input_resume(&v).unwrap()["value"], "office");
|
||||
assert_eq!(input_resume(&v).unwrap()["reused"], true);
|
||||
assert_eq!(input_resume(&json!({"id":id,"resume_dir":dir,
|
||||
"reply":"office","source_revision":"v1","session_id":"s1",
|
||||
"principal_ref":"u1"})).unwrap()["reused"], true);
|
||||
assert_eq!(input_resume(&json!({"id":id,"resume_dir":dir,
|
||||
"reply":"chat","source_revision":"v1","session_id":"s1",
|
||||
"principal_ref":"u1"})).unwrap()["status"], "conflict");
|
||||
assert_eq!(input_open(&initial).unwrap()["status"], "resumed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prevents_changed_source_or_unauthorized_session() {
|
||||
let (id, dir) = fixture();
|
||||
let initial = json!({"id":id,"resume_dir":dir,"question":"Proceed?",
|
||||
"options":["yes","no"],"source_revision":"v1",
|
||||
"session_id":"s1","principal_ref":"u1"});
|
||||
input_open(&initial).unwrap();
|
||||
for (rev,session) in [("v2","s1"),("v1","other")] {
|
||||
assert_eq!(input_resume(&json!({"id":id,"resume_dir":dir,"reply":"yes",
|
||||
"source_revision":rev,"session_id":session,
|
||||
"principal_ref":"u1"})).unwrap()["status"], "conflict");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_choice_keeps_gate_open_and_no_freeform_is_enforced() {
|
||||
let (id, dir) = fixture();
|
||||
input_open(&json!({"id":id,"resume_dir":dir,"question":"Pick",
|
||||
"options":["a","b"],"freeform":false,
|
||||
"source_revision":"v1"})).unwrap();
|
||||
assert_eq!(input_resume(&json!({"id":id,"resume_dir":dir,"reply":"??",
|
||||
"source_revision":"v1"})).unwrap()["status"], "invalid");
|
||||
assert_eq!(resume::resume_load(&json!({"id":id,"resume_dir":dir})).unwrap()["status"], "waiting_input");
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,24 @@
|
||||
//! Agent plugin (C ABI v2): layout helpers + session bag + context via host_query + agent-kb + v2 memory + adaptive route.
|
||||
|
||||
mod choice;
|
||||
mod context_pack;
|
||||
mod context_scope;
|
||||
mod corpus;
|
||||
mod effects;
|
||||
mod eng;
|
||||
mod error;
|
||||
mod input;
|
||||
mod kb;
|
||||
mod mcp_client;
|
||||
mod mcp_server;
|
||||
mod memory;
|
||||
mod output;
|
||||
mod parallel;
|
||||
mod resume;
|
||||
mod route;
|
||||
mod sandbox;
|
||||
mod tools;
|
||||
mod workflow;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CString;
|
||||
@@ -834,6 +839,17 @@ kb_ffi!(agent_resume_save, resume::resume_save, "agent_resume_save");
|
||||
kb_ffi!(agent_resume_load, resume::resume_load, "agent_resume_load");
|
||||
kb_ffi!(agent_resume_clear, resume::resume_clear, "agent_resume_clear");
|
||||
kb_ffi!(agent_resume_list, resume::resume_list, "agent_resume_list");
|
||||
kb_ffi!(agent_choice_parse, choice::parse_choice, "agent_choice_parse");
|
||||
kb_ffi!(agent_context_scope, context_scope::project, "agent_context_scope");
|
||||
kb_ffi!(agent_input_open, input::input_open, "agent_input_open");
|
||||
kb_ffi!(agent_input_resume, input::input_resume, "agent_input_resume");
|
||||
kb_ffi!(agent_parallel_report, parallel::report, "agent_parallel_report");
|
||||
kb_ffi!(agent_workflow_open, workflow::open, "agent_workflow_open");
|
||||
kb_ffi!(agent_workflow_next, workflow::next, "agent_workflow_next");
|
||||
kb_ffi!(agent_workflow_commit, workflow::commit, "agent_workflow_commit");
|
||||
kb_ffi!(agent_workflow_cancel, workflow::cancel, "agent_workflow_cancel");
|
||||
kb_ffi!(agent_workflow_retry_plan, workflow::retry_plan, "agent_workflow_retry_plan");
|
||||
kb_ffi!(agent_workflow_retry_commit, workflow::retry_commit, "agent_workflow_retry_commit");
|
||||
kb_ffi!(agent_error_make, error::make_error, "agent_error_make");
|
||||
kb_ffi!(agent_error_decide_retry, error::decide_retry, "agent_error_decide_retry");
|
||||
kb_ffi!(agent_tools_register, tools::tools_register, "agent_tools_register");
|
||||
@@ -963,6 +979,17 @@ pub unsafe extern "C" fn marqdo_plugin_init(host: *const MarqdoHostApi) -> c_int
|
||||
("agent_resume_load", "id,resume_dir", agent_resume_load),
|
||||
("agent_resume_clear", "id,resume_dir", agent_resume_clear),
|
||||
("agent_resume_list", "resume_dir", agent_resume_list),
|
||||
("agent_choice_parse", "reply,options", agent_choice_parse),
|
||||
("agent_context_scope", "source,scope,class,function", agent_context_scope),
|
||||
("agent_input_open", "id,question,options,source_revision", agent_input_open),
|
||||
("agent_input_resume", "id,reply,source_revision", agent_input_resume),
|
||||
("agent_parallel_report", "results", agent_parallel_report),
|
||||
("agent_workflow_open", "id,steps,source_revision", agent_workflow_open),
|
||||
("agent_workflow_next", "id,source_revision", agent_workflow_next),
|
||||
("agent_workflow_commit", "id,step_id,response,source_revision", agent_workflow_commit),
|
||||
("agent_workflow_cancel", "id,source_revision", agent_workflow_cancel),
|
||||
("agent_workflow_retry_plan", "id,source_revision", agent_workflow_retry_plan),
|
||||
("agent_workflow_retry_commit", "id,results,source_revision", agent_workflow_retry_commit),
|
||||
("agent_error_make", "code,message,category", agent_error_make),
|
||||
("agent_error_decide_retry", "error,attempts,effect_class", agent_error_decide_retry),
|
||||
("agent_tools_register", "spec,specs", agent_tools_register),
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
//! Deterministic fan-out results: never discard a successful sibling and never
|
||||
//! infer success from a completed wait protocol alone.
|
||||
|
||||
use serde_json::{json, Value};
|
||||
|
||||
pub fn report(args: &Value) -> Result<Value, String> {
|
||||
let results = args
|
||||
.get("results")
|
||||
.and_then(Value::as_array)
|
||||
.ok_or_else(|| "results must be ordered subtask result list".to_string())?;
|
||||
if results.len() > 10_000 {
|
||||
return Err("parallel result count exceeds scheduler limit".into());
|
||||
}
|
||||
let mut passed = 0usize;
|
||||
let mut failed = 0usize;
|
||||
let mut unknown = 0usize;
|
||||
let mut entries = Vec::with_capacity(results.len());
|
||||
for (index, child) in results.iter().enumerate() {
|
||||
let transport = child.get("ok").and_then(Value::as_bool);
|
||||
let body = child.get("value").unwrap_or(&Value::Null);
|
||||
let status = match (transport, body.get("code").and_then(Value::as_i64)) {
|
||||
(Some(true), Some(0)) => { passed += 1; "succeeded" }
|
||||
(Some(true), Some(_)) | (Some(false), _) => { failed += 1; "failed" }
|
||||
_ => { unknown += 1; "uncertain" }
|
||||
};
|
||||
// Raw child result is kept as data; the model sees only an optional
|
||||
// bounded summary. The host may store detailed output as an artifact.
|
||||
let detail = child.get("error")
|
||||
.and_then(Value::as_str)
|
||||
.or_else(|| body.get("stderr").and_then(Value::as_str))
|
||||
.unwrap_or("");
|
||||
let brief: String = detail.chars().take(280).collect();
|
||||
entries.push(json!({
|
||||
"index": index,
|
||||
"status": status,
|
||||
"summary": brief,
|
||||
"result": child
|
||||
}));
|
||||
}
|
||||
let status = if unknown != 0 {
|
||||
"uncertain"
|
||||
} else if failed == 0 {
|
||||
"succeeded"
|
||||
} else if passed > 0 {
|
||||
"partial"
|
||||
} else {
|
||||
"failed"
|
||||
};
|
||||
Ok(json!({
|
||||
"ok": failed == 0 && unknown == 0,
|
||||
"schema": "AgentParallelResultV1",
|
||||
"status": status,
|
||||
"succeeded": passed,
|
||||
"failed": failed,
|
||||
"uncertain": unknown,
|
||||
"items": entries
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn preserves_success_and_exposes_failed_child() {
|
||||
let result = report(&json!({"results":[
|
||||
{"ok":true,"value":{"code":0,"value":"good"}},
|
||||
{"ok":true,"value":{"code":2,"stderr":"failed"}},
|
||||
{"ok":false,"error":"timeout"}
|
||||
]})).unwrap();
|
||||
assert_eq!(result["status"], "partial");
|
||||
assert_eq!(result["succeeded"], 1);
|
||||
assert_eq!(result["failed"], 2);
|
||||
assert_eq!(result["items"][0]["status"], "succeeded");
|
||||
}
|
||||
#[test]
|
||||
fn unknown_child_cannot_be_mislabeled_successful() {
|
||||
let value = report(&json!({"results":[{"ok":true,"value":{"value":"no code"}}]})).unwrap();
|
||||
assert_eq!(value["status"], "uncertain");
|
||||
assert_eq!(value["ok"], false);
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,8 @@ fn ensure_dir(root: &Path) -> Result<(), String> {
|
||||
}
|
||||
|
||||
/// Atomic durable write: unique temp → write → flush/fsync → rename.
|
||||
static TEMP_SEQUENCE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
|
||||
fn atomic_write_json(path: &Path, doc: &Value) -> Result<(), String> {
|
||||
let parent = path
|
||||
.parent()
|
||||
@@ -96,7 +98,8 @@ fn atomic_write_json(path: &Path, doc: &Value) -> Result<(), String> {
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("ckpt.json"),
|
||||
std::process::id(),
|
||||
now_rfc3339().replace(':', "")
|
||||
format!("{}-{}", now_rfc3339().replace(':', ""),
|
||||
TEMP_SEQUENCE.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
|
||||
);
|
||||
let tmp = parent.join(tmp_name);
|
||||
let text = serde_json::to_string_pretty(doc).map_err(|e| e.to_string())?;
|
||||
@@ -396,7 +399,8 @@ mod tests {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let dir = std::env::temp_dir().join(format!("marqdo-resume-{label}-{nanos}"));
|
||||
// Do not mutate process-wide cwd from concurrent Rust unit tests.
|
||||
let dir = PathBuf::from("target").join(format!("marqdo-resume-{label}-{nanos}"));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
@@ -410,10 +414,7 @@ mod tests {
|
||||
#[test]
|
||||
fn atomic_v2_roundtrip_and_legacy_manual_review() {
|
||||
let dir = scratch("v2");
|
||||
// Use relative path via env cwd — chdir into scratch for this test.
|
||||
let prev = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
let rel = "ckpts";
|
||||
let rel = dir.join("ckpts").to_string_lossy().to_string();
|
||||
let saved = resume_save(&json!({
|
||||
"id": "run1",
|
||||
"schema": "CheckpointV2",
|
||||
@@ -491,23 +492,20 @@ mod tests {
|
||||
assert_eq!(unsafe_ck["recovery_mode"], "checkpoint_v2_read_only");
|
||||
assert_eq!(unsafe_ck["write_auto_resume"], false);
|
||||
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn corrupt_checkpoint_reports_error() {
|
||||
let dir = scratch("corrupt");
|
||||
let prev = std::env::current_dir().unwrap();
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
fs::create_dir_all("ckpts").unwrap();
|
||||
fs::write("ckpts/bad.json", "{not-json").unwrap();
|
||||
let loaded = resume_load(&json!({"id": "bad", "resume_dir": "ckpts"})).unwrap();
|
||||
let ckpts = dir.join("ckpts");
|
||||
fs::create_dir_all(&ckpts).unwrap();
|
||||
fs::write(ckpts.join("bad.json"), "{not-json").unwrap();
|
||||
let loaded = resume_load(&json!({"id": "bad", "resume_dir": ckpts.to_string_lossy()})).unwrap();
|
||||
assert_eq!(loaded["found"], true);
|
||||
assert_eq!(loaded["ok"], false);
|
||||
assert_eq!(loaded["error"]["code"], "checkpoint.corrupt");
|
||||
assert_eq!(loaded["recovery_mode"], "manual_review");
|
||||
std::env::set_current_dir(prev).unwrap();
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,591 @@
|
||||
//! Plugin-only durable step workflow.
|
||||
//! No interpreter-frame serialization: every model/tool decision is a checkpointed
|
||||
//! transition. This state machine issues actions but never executes arbitrary code.
|
||||
|
||||
use std::fs::{self, OpenOptions};
|
||||
use std::path::PathBuf;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::{choice, parallel, resume};
|
||||
|
||||
const MAX_STEPS: usize = 128;
|
||||
|
||||
struct Guard(PathBuf);
|
||||
impl Drop for Guard {
|
||||
fn drop(&mut self) { let _ = fs::remove_file(&self.0); }
|
||||
}
|
||||
|
||||
fn field<'a>(v: &'a Value, key: &str) -> Result<&'a str, String> {
|
||||
v.get(key).and_then(Value::as_str).filter(|x| !x.is_empty())
|
||||
.ok_or_else(|| format!("workflow requires text {key}"))
|
||||
}
|
||||
|
||||
fn safe_key(s: &str) -> bool {
|
||||
!s.is_empty() && s.len() <= 100
|
||||
&& s.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
|
||||
}
|
||||
|
||||
fn storage(args: &Value) -> Result<PathBuf, String> {
|
||||
let rel = args.get("resume_dir").and_then(Value::as_str)
|
||||
.unwrap_or(".marqdo/agent-resume");
|
||||
let path = PathBuf::from(rel);
|
||||
if path.is_absolute() || path.components().any(|part|
|
||||
matches!(part, std::path::Component::ParentDir | std::path::Component::Prefix(_)))
|
||||
{
|
||||
return Err("resume_dir must be relative with no parent traversal".into());
|
||||
}
|
||||
let base = crate::host_query_json("cwd").ok()
|
||||
.and_then(|v| v.as_str().map(PathBuf::from))
|
||||
.unwrap_or(std::env::current_dir().map_err(|e| e.to_string())?);
|
||||
let dir = base.join(path);
|
||||
fs::create_dir_all(&dir).map_err(|e| format!("workflow mkdir: {e}"))?;
|
||||
Ok(dir)
|
||||
}
|
||||
|
||||
fn lock(args: &Value, id: &str) -> Result<Guard, String> {
|
||||
if !safe_key(id) {
|
||||
return Err("workflow id must be <=100 ASCII letters, numbers, - or _".into());
|
||||
}
|
||||
let path = storage(args)?.join(format!("{id}.flow-lock"));
|
||||
OpenOptions::new().write(true).create_new(true).open(&path)
|
||||
.map_err(|e| format!("workflow busy or stale lock; review before recovering: {e}"))?;
|
||||
Ok(Guard(path))
|
||||
}
|
||||
|
||||
fn checkpoint_args(args: &Value, id: &str) -> Value {
|
||||
json!({"id": id, "resume_dir": args.get("resume_dir")})
|
||||
}
|
||||
|
||||
fn read(args: &Value, id: &str) -> Result<Value, String> {
|
||||
resume::resume_load(&checkpoint_args(args,id))
|
||||
}
|
||||
|
||||
fn context(args: &Value) -> Value {
|
||||
json!({
|
||||
"source_revision": args.get("source_revision").cloned().unwrap_or(Value::Null),
|
||||
"session_id": args.get("session_id").cloned().unwrap_or(Value::Null),
|
||||
"principal_ref": args.get("principal_ref").cloned().unwrap_or(Value::Null)
|
||||
})
|
||||
}
|
||||
|
||||
fn check_context(args: &Value, ckpt: &Value) -> bool {
|
||||
ckpt["meta"]["identity"] == context(args)
|
||||
}
|
||||
|
||||
fn validate_steps(args: &Value) -> Result<Value, String> {
|
||||
let steps = args.get("steps").and_then(Value::as_array)
|
||||
.ok_or_else(|| "steps must be a list".to_string())?;
|
||||
if steps.is_empty() || steps.len() > MAX_STEPS {
|
||||
return Err("steps must contain 1..=128 items".into());
|
||||
}
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for s in steps {
|
||||
let id = field(s, "id")?;
|
||||
if !safe_key(id) || !seen.insert(id) {
|
||||
return Err("step ids must be unique safe identifiers".into());
|
||||
}
|
||||
let kind = field(s, "kind")?;
|
||||
if !matches!(kind, "model" | "input" | "skill" | "parallel" | "return") {
|
||||
return Err(format!("unsupported step kind: {kind}"));
|
||||
}
|
||||
if matches!(kind, "model" | "input") {
|
||||
let options = s.get("options").and_then(Value::as_array)
|
||||
.ok_or_else(|| "choice step requires options list".to_string())?;
|
||||
let _ = choice::parse_choice(&json!({"reply":"","options":options}))?;
|
||||
if kind == "input" { let _ = field(s, "question")?; }
|
||||
if kind == "model" { let _ = field(s, "prompt")?; }
|
||||
}
|
||||
if kind == "skill" { let _ = field(s, "skill")?; }
|
||||
if kind == "parallel" && !s.get("tasks").is_some_and(Value::is_array) {
|
||||
return Err("parallel step requires tasks array".into());
|
||||
}
|
||||
}
|
||||
// Resolve all branch targets against frozen, forward-only step IDs.
|
||||
for (i, s) in steps.iter().enumerate() {
|
||||
let targets = s.get("next").and_then(Value::as_str).into_iter()
|
||||
.chain(s.get("routes").and_then(Value::as_object)
|
||||
.into_iter().flat_map(|m| m.values().filter_map(Value::as_str)));
|
||||
for target in targets {
|
||||
let position = steps.iter().position(|x|x["id"]==target)
|
||||
.ok_or_else(|| format!("unknown workflow target: {target}"))?;
|
||||
if position <= i {
|
||||
return Err("workflow routes must move forward to avoid loops".into());
|
||||
}
|
||||
}
|
||||
if let Some(routes)=s.get("routes").and_then(Value::as_object) {
|
||||
if !matches!(s["kind"].as_str(),Some("model"|"input")) {
|
||||
return Err("only choice steps may declare routes".into());
|
||||
}
|
||||
for key in routes.keys() {
|
||||
if !s["options"].as_array().is_some_and(|opts|
|
||||
opts.iter().any(|x|x.as_str()==Some(key.as_str()))) {
|
||||
return Err("route label is not a declared choice".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Value::Array(steps.clone()))
|
||||
}
|
||||
|
||||
fn advance_cursor(step:&Value, value:&Value, steps:&[Value], current:usize)->Result<usize,String> {
|
||||
let target=if let Some(routes)=step.get("routes").and_then(Value::as_object) {
|
||||
let label=value.as_str().ok_or("routed choice must return a text label")?;
|
||||
Some(routes.get(label).and_then(Value::as_str)
|
||||
.ok_or("chosen option is missing a declared route")?)
|
||||
} else {
|
||||
step.get("next").and_then(Value::as_str)
|
||||
};
|
||||
match target {
|
||||
None=>Ok(current+1),
|
||||
Some(name)=> {
|
||||
let n=steps.iter().position(|s|s["id"]==name)
|
||||
.ok_or("unknown target after checkpoint recovery")?;
|
||||
if n<=current {return Err("cyclic route refused".into())}
|
||||
Ok(n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn state(ckpt: &Value) -> Result<(&Value,usize),String> {
|
||||
let meta = ckpt.get("meta").ok_or("missing workflow metadata")?;
|
||||
if meta.get("kind").and_then(Value::as_str) != Some("MarqdoAgentFlowV1") {
|
||||
return Err("checkpoint is not a workflow".into());
|
||||
}
|
||||
let index = meta.get("cursor").and_then(Value::as_u64)
|
||||
.ok_or("missing workflow cursor")? as usize;
|
||||
Ok((meta,index))
|
||||
}
|
||||
|
||||
fn save(args: &Value, id: &str, meta: &Value, status: &str) -> Result<(),String> {
|
||||
let result = resume::resume_save(&json!({
|
||||
"id": id,
|
||||
"resume_dir": args.get("resume_dir"),
|
||||
"checkpoint_v2": true,
|
||||
"status": status,
|
||||
"meta": meta,
|
||||
"completed_steps": meta["completed"],
|
||||
"step_id": meta["steps"].get(meta["cursor"].as_u64().unwrap_or(0) as usize)
|
||||
.and_then(|x| x.get("id")).cloned().unwrap_or(Value::Null)
|
||||
}))?;
|
||||
if result["ok"] != true { return Err("workflow checkpoint write failed".into()); }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Register a bounded, frozen plan. Re-opening never resets a progressed plan.
|
||||
pub fn open(args: &Value) -> Result<Value,String> {
|
||||
let id = field(args,"id")?;
|
||||
let _guard = lock(args,id)?;
|
||||
let revision = field(args,"source_revision")?;
|
||||
if revision.len()>256 { return Err("source_revision too long".into()); }
|
||||
let steps = validate_steps(args)?;
|
||||
let existing = read(args,id)?;
|
||||
let identity = context(args);
|
||||
if existing["found"] == true {
|
||||
if existing["ok"] == true
|
||||
&& existing["meta"]["identity"] == identity
|
||||
&& existing["meta"]["steps"] == steps
|
||||
{
|
||||
return next_doc(&existing,id,true);
|
||||
}
|
||||
return Ok(json!({"ok":false,"status":"conflict","error":"workflow.id_or_revision_reused"}));
|
||||
}
|
||||
let meta = json!({
|
||||
"kind":"MarqdoAgentFlowV1",
|
||||
"identity":identity,
|
||||
"steps":steps,
|
||||
"cursor":0,
|
||||
"completed":[],
|
||||
});
|
||||
save(args,id,&meta,"running")?;
|
||||
Ok(json!({"ok":true,"id":id,"status":"created","cursor":0}))
|
||||
}
|
||||
|
||||
fn next_doc(ckpt: &Value, id: &str, reused: bool) -> Result<Value,String> {
|
||||
let (meta,index)=state(ckpt)?;
|
||||
let steps = meta["steps"].as_array().ok_or("invalid steps")?;
|
||||
if index>=steps.len() {
|
||||
return Ok(json!({"ok":true,"id":id,"status":"succeeded",
|
||||
"cursor":index,"completed":meta["completed"],"reused":reused}));
|
||||
}
|
||||
let step=&steps[index];
|
||||
let status=ckpt["status"].as_str().unwrap_or("running");
|
||||
if status=="blocked" || status=="uncertain" || status=="cancelled" {
|
||||
return Ok(json!({"ok":false,"id":id,"status":status,
|
||||
"cursor":index,"step":step,"completed":meta["completed"],
|
||||
"partial": meta.get("partial").cloned().unwrap_or(Value::Null)}));
|
||||
}
|
||||
// Never auto-dispatch effectful or unclassified child documents.
|
||||
// Those must be executed using the existing EffectLedger policy and an
|
||||
// independently verified receipt, not an arbitrary model instruction.
|
||||
if (step["kind"]=="skill" || step["kind"]=="parallel")
|
||||
&& step["effect_class"]!="read"
|
||||
{
|
||||
return Ok(json!({"ok":false,"id":id,"status":"manual_review",
|
||||
"cursor":index,"step":step,
|
||||
"reason":"automatic child dispatch requires an explicit read-only effect class"}));
|
||||
}
|
||||
let waiting=match step["kind"].as_str().unwrap_or("") {
|
||||
"model"=>"waiting_model",
|
||||
"input"=>"waiting_input",
|
||||
"skill" | "parallel"=>"ready_tool",
|
||||
"return"=>"ready_return",
|
||||
_=>"blocked"
|
||||
};
|
||||
Ok(json!({"ok":true,"id":id,"status":waiting,
|
||||
"cursor":index,"step":step,"completed":meta["completed"],"reused":reused}))
|
||||
}
|
||||
|
||||
/// Query the durable next action. This is non-blocking and does not invoke LLM.
|
||||
pub fn next(args: &Value) -> Result<Value,String> {
|
||||
let id=field(args,"id")?;
|
||||
let ckpt=read(args,id)?;
|
||||
if ckpt["ok"]!=true || !check_context(args,&ckpt) {
|
||||
return Ok(json!({"ok":false,"id":id,"status":"not_found_or_mismatched"}));
|
||||
}
|
||||
next_doc(&ckpt,id,false)
|
||||
}
|
||||
|
||||
/// Commit a verified result for the exact current step. All mutations are
|
||||
/// serialized with a lock; a completed step cannot be committed a second time.
|
||||
pub fn commit(args: &Value) -> Result<Value,String> {
|
||||
let id=field(args,"id")?;
|
||||
let _guard=lock(args,id)?;
|
||||
let step_id=field(args,"step_id")?;
|
||||
let ckpt=read(args,id)?;
|
||||
if ckpt["ok"]!=true || !check_context(args,&ckpt) {
|
||||
return Ok(json!({"ok":false,"status":"not_found_or_mismatched"}));
|
||||
}
|
||||
let (meta,index)=state(&ckpt)?;
|
||||
let steps=meta["steps"].as_array().ok_or("invalid steps")?;
|
||||
let response=args.get("response").ok_or("missing response")?;
|
||||
if index>=steps.len() {
|
||||
let previous = meta["completed"].as_array().ok_or("invalid completed")?;
|
||||
if previous.iter().any(|x|x["step_id"]==step_id && x["value"]==*response) {
|
||||
return Ok(json!({"ok":true,"status":"succeeded","reused":true}));
|
||||
}
|
||||
return Ok(json!({"ok":false,"status":"already_finished"}));
|
||||
}
|
||||
let step=&steps[index];
|
||||
if step["id"]!=step_id {
|
||||
if meta["completed"].as_array().is_some_and(|list|
|
||||
list.iter().any(|x|x["step_id"]==step_id && x["value"]==*response))
|
||||
{
|
||||
return Ok(json!({"ok":true,"status":"already_committed","reused":true}));
|
||||
}
|
||||
return Ok(json!({"ok":false,"status":"step_conflict"}));
|
||||
}
|
||||
if ckpt["status"]!="running" {
|
||||
return Ok(json!({"ok":false,"status":"blocked","reason":ckpt["status"]}));
|
||||
}
|
||||
let kind=field(step,"kind")?;
|
||||
let value = match kind {
|
||||
"model" | "input" => {
|
||||
let reply = response.as_str().ok_or("model/input response must be text")?;
|
||||
let valid=choice::parse_choice(&json!({"options":step["options"],"reply":reply}))?;
|
||||
if valid["ok"]!=true {
|
||||
return Ok(json!({"ok":false,"status":"invalid_choice",
|
||||
"error":valid["error"]}));
|
||||
}
|
||||
valid["value"].clone()
|
||||
}
|
||||
"skill" => {
|
||||
// A completed wait is not equivalent to a successful child process.
|
||||
let exit = response.get("value").and_then(|v| v.get("code"))
|
||||
.or_else(|| response.get("code")).and_then(Value::as_i64);
|
||||
if response["ok"]==false || exit != Some(0) {
|
||||
return Ok(json!({"ok":false,
|
||||
"status":if exit.is_none() {"uncertain"} else {"failed"},
|
||||
"reason":"child process exit code zero is required before commit"}));
|
||||
}
|
||||
response.clone()
|
||||
}
|
||||
"parallel" => {
|
||||
let report=if response["schema"]=="AgentParallelResultV1" {
|
||||
response.clone()
|
||||
} else {
|
||||
parallel::report(&json!({"results":response}))?
|
||||
};
|
||||
if report["ok"]!=true {
|
||||
let status=if report["uncertain"].as_u64().unwrap_or(0)>0 {
|
||||
"uncertain"
|
||||
} else {"blocked"};
|
||||
// Save the full manifest of successful and failed siblings before
|
||||
// returning. Do not run failed/unknown children automatically.
|
||||
let mut frozen=meta.clone();
|
||||
frozen["partial"]=report.clone();
|
||||
save(args,id,&frozen,status)?;
|
||||
return Ok(json!({"ok":false,"status":status,
|
||||
"report":report,"reason":"child results retained for reconciliation"}));
|
||||
}
|
||||
report
|
||||
}
|
||||
"return" => response.clone(),
|
||||
_ => return Err("invalid step kind".into()),
|
||||
};
|
||||
let target=advance_cursor(step,&value,steps,index)?;
|
||||
let mut new_meta=meta.clone();
|
||||
new_meta["cursor"]=json!(target);
|
||||
new_meta["completed"].as_array_mut().ok_or("completed not array")?
|
||||
.push(json!({"step_id":step_id,"value":value}));
|
||||
let terminal=target==steps.len();
|
||||
save(args,id,&new_meta,if terminal {"succeeded"} else {"running"})?;
|
||||
Ok(json!({"ok":true,"id":id,
|
||||
"status":if terminal {"succeeded"} else {"advanced"},
|
||||
"cursor":target,"value":value,"reused":false}))
|
||||
}
|
||||
|
||||
/// Produce a plan containing only previously failed *read-only* child tasks.
|
||||
/// "uncertain" children and effectful plans cannot be blindly retried.
|
||||
pub fn retry_plan(args: &Value) -> Result<Value,String> {
|
||||
let id=field(args,"id")?;
|
||||
let ckpt=read(args,id)?;
|
||||
if ckpt["ok"]!=true || !check_context(args,&ckpt) {
|
||||
return Ok(json!({"ok":false,"status":"not_found_or_mismatched"}));
|
||||
}
|
||||
let (meta,index)=state(&ckpt)?;
|
||||
if ckpt["status"]!="blocked" {
|
||||
return Ok(json!({"ok":false,"status":"not_retryable"}));
|
||||
}
|
||||
let step=&meta["steps"][index];
|
||||
if step["kind"]!="parallel" || step["effect_class"]!="read"
|
||||
|| meta["partial"]["uncertain"].as_u64().unwrap_or(1)!=0
|
||||
{
|
||||
return Ok(json!({"ok":false,"status":"manual_reconciliation_required"}));
|
||||
}
|
||||
let Some(items)=meta["partial"]["items"].as_array() else {
|
||||
return Err("partial report has no items".into());
|
||||
};
|
||||
let Some(tasks)=step["tasks"].as_array() else {
|
||||
return Err("parallel plan has no tasks".into());
|
||||
};
|
||||
if items.len()!=tasks.len() {
|
||||
return Err("partial report task count mismatch".into());
|
||||
}
|
||||
let mut failed=Vec::new();
|
||||
let mut indices=Vec::new();
|
||||
for (i,item) in items.iter().enumerate() {
|
||||
if item["index"]!=i {
|
||||
return Err("out-of-order child result index".into());
|
||||
}
|
||||
if item["status"]=="failed" {
|
||||
failed.push(tasks[i].clone());
|
||||
indices.push(i);
|
||||
} else if item["status"]!="succeeded" {
|
||||
return Ok(json!({"ok":false,"status":"manual_reconciliation_required"}));
|
||||
}
|
||||
}
|
||||
Ok(json!({"ok":true,"status":"retry_read_only",
|
||||
"id":id,"step_id":step["id"],"tasks":failed,"indices":indices}))
|
||||
}
|
||||
|
||||
/// Merge only the failed child slots with verified new outcomes.
|
||||
/// Successful results and their order remain untouched.
|
||||
pub fn retry_commit(args: &Value) -> Result<Value,String> {
|
||||
let id=field(args,"id")?;
|
||||
let _guard=lock(args,id)?;
|
||||
let ckpt=read(args,id)?;
|
||||
if ckpt["ok"]!=true || !check_context(args,&ckpt) {
|
||||
return Ok(json!({"ok":false,"status":"not_found_or_mismatched"}));
|
||||
}
|
||||
let (meta,index)=state(&ckpt)?;
|
||||
if ckpt["status"]!="blocked" {
|
||||
return Ok(json!({"ok":false,"status":"not_retryable"}));
|
||||
}
|
||||
let step=&meta["steps"][index];
|
||||
if step["kind"]!="parallel" || step["effect_class"]!="read"
|
||||
|| meta["partial"]["uncertain"].as_u64().unwrap_or(1)!=0
|
||||
{
|
||||
return Ok(json!({"ok":false,"status":"manual_reconciliation_required"}));
|
||||
}
|
||||
let items=meta["partial"]["items"].as_array()
|
||||
.ok_or("invalid partial report")?;
|
||||
let incoming=args.get("results").and_then(Value::as_array)
|
||||
.ok_or("retry_commit requires results list")?;
|
||||
let expected=items.iter().filter(|it|it["status"]=="failed").count();
|
||||
if incoming.len()!=expected {
|
||||
return Err("retry result count differs from failed child count".into());
|
||||
}
|
||||
let mut next=Vec::with_capacity(items.len());
|
||||
let mut replacement=incoming.iter();
|
||||
for item in items {
|
||||
if item["status"]=="succeeded" {
|
||||
next.push(item["result"].clone());
|
||||
} else if item["status"]=="failed" {
|
||||
next.push(replacement.next().ok_or("missing retry result")?.clone());
|
||||
} else {
|
||||
return Ok(json!({"ok":false,"status":"manual_reconciliation_required"}));
|
||||
}
|
||||
}
|
||||
let report=parallel::report(&json!({"results":next}))?;
|
||||
let mut updated=meta.clone();
|
||||
if report["ok"]==true {
|
||||
let target=advance_cursor(step,&report,
|
||||
updated["steps"].as_array().ok_or("steps missing")?,index)?;
|
||||
updated["cursor"]=json!(target);
|
||||
updated["partial"]=Value::Null;
|
||||
updated["completed"].as_array_mut().ok_or("completed not list")?
|
||||
.push(json!({"step_id":step["id"],"value":report}));
|
||||
let finished=target==updated["steps"].as_array().ok_or("steps missing")?.len();
|
||||
save(args,id,&updated,if finished {"succeeded"} else {"running"})?;
|
||||
Ok(json!({"ok":true,"status":if finished {"succeeded"} else {"advanced"},
|
||||
"cursor":target,"result":report}))
|
||||
} else {
|
||||
updated["partial"]=report.clone();
|
||||
save(args,id,&updated,if report["uncertain"].as_u64().unwrap_or(0)>0 {
|
||||
"uncertain" } else {"blocked"})?;
|
||||
Ok(json!({"ok":false,"status":"blocked","report":report}))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cancel(args: &Value) -> Result<Value,String> {
|
||||
let id=field(args,"id")?;
|
||||
let _guard=lock(args,id)?;
|
||||
let ckpt=read(args,id)?;
|
||||
if ckpt["ok"]!=true || !check_context(args,&ckpt) {
|
||||
return Ok(json!({"ok":false,"status":"not_found_or_mismatched"}));
|
||||
}
|
||||
if ckpt["status"]=="succeeded" {
|
||||
return Ok(json!({"ok":false,"status":"already_finished"}));
|
||||
}
|
||||
let (meta,_)=state(&ckpt)?;
|
||||
save(args,id,meta,"cancelled")?;
|
||||
Ok(json!({"ok":true,"id":id,"status":"cancelled"}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::{AtomicU64,Ordering};
|
||||
static SEQ: AtomicU64=AtomicU64::new(0);
|
||||
fn fixture()->Value {
|
||||
let n=SEQ.fetch_add(1,Ordering::Relaxed);
|
||||
json!({"id":format!("wf-{}-{n}",std::process::id()),
|
||||
"resume_dir":format!("target/workflow-test-{}-{n}",std::process::id()),
|
||||
"source_revision":"v1",
|
||||
"steps":[
|
||||
{"id":"choose","kind":"model","prompt":"Choose a skill","options":["chat","office"]},
|
||||
{"id":"answer","kind":"input","question":"OK?","options":["yes","no"]},
|
||||
{"id":"end","kind":"return"}
|
||||
]})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nonblocking_model_then_input_then_terminal() {
|
||||
let a=fixture();
|
||||
assert_eq!(open(&a).unwrap()["status"],"created");
|
||||
assert_eq!(next(&a).unwrap()["status"],"waiting_model");
|
||||
let mut c=a.clone();
|
||||
c["step_id"]=json!("choose");
|
||||
c["response"]=json!("office");
|
||||
assert_eq!(commit(&c).unwrap()["status"],"advanced");
|
||||
assert_eq!(next(&a).unwrap()["status"],"waiting_input");
|
||||
assert_eq!(commit(&c).unwrap()["status"],"already_committed");
|
||||
c["step_id"]=json!("answer");
|
||||
c["response"]=json!("yes");
|
||||
assert_eq!(commit(&c).unwrap()["status"],"advanced");
|
||||
c["step_id"]=json!("end");
|
||||
c["response"]=json!("ok");
|
||||
assert_eq!(commit(&c).unwrap()["status"],"succeeded");
|
||||
assert_eq!(next(&a).unwrap()["status"],"succeeded");
|
||||
assert_eq!(open(&a).unwrap()["status"],"succeeded");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_and_write_effects_never_auto_dispatch() {
|
||||
let mut a=fixture();
|
||||
a["steps"]=json!([{"id":"publish","kind":"skill","skill":"office"}]);
|
||||
open(&a).unwrap();
|
||||
assert_eq!(next(&a).unwrap()["status"],"manual_review");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn routes_skip_unselected_skill_branches() {
|
||||
let mut a=fixture();
|
||||
a["steps"]=json!([
|
||||
{"id":"decide","kind":"model","prompt":"Pick","options":["chat","office"],
|
||||
"routes":{"chat":"chat_skill","office":"office_skill"}},
|
||||
{"id":"chat_skill","kind":"skill","skill":"chat","effect_class":"read","next":"done"},
|
||||
{"id":"office_skill","kind":"skill","skill":"office","effect_class":"read","next":"done"},
|
||||
{"id":"done","kind":"return"}
|
||||
]);
|
||||
open(&a).unwrap();
|
||||
let mut c=a.clone();
|
||||
c["step_id"]=json!("decide");
|
||||
c["response"]=json!("office");
|
||||
assert_eq!(commit(&c).unwrap()["cursor"],2);
|
||||
assert_eq!(next(&a).unwrap()["step"]["id"],"office_skill");
|
||||
c["step_id"]=json!("office_skill");
|
||||
c["response"]=json!({"ok":true,"value":{"code":0}});
|
||||
assert_eq!(commit(&c).unwrap()["cursor"],3);
|
||||
assert_eq!(next(&a).unwrap()["step"]["id"],"done");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_change_conflict_and_invalid_model_choice() {
|
||||
let a=fixture();
|
||||
open(&a).unwrap();
|
||||
let mut bad=a.clone();
|
||||
bad["source_revision"]=json!("v2");
|
||||
assert_eq!(next(&bad).unwrap()["status"],"not_found_or_mismatched");
|
||||
assert_eq!(open(&bad).unwrap()["status"],"conflict");
|
||||
let mut c=a.clone();
|
||||
c["step_id"]=json!("choose");
|
||||
c["response"]=json!("chat or office");
|
||||
assert_eq!(commit(&c).unwrap()["status"],"invalid_choice");
|
||||
assert_eq!(next(&a).unwrap()["status"],"waiting_model");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_children_remain_durable_and_unknown_requires_reconciliation() {
|
||||
let mut a=fixture();
|
||||
a["steps"]=json!([{"id":"batch","kind":"parallel","tasks":[{"skill":"a"},{"skill":"b"}]}]);
|
||||
open(&a).unwrap();
|
||||
let mut c=a.clone();
|
||||
c["step_id"]=json!("batch");
|
||||
c["response"]=json!([
|
||||
{"ok":true,"value":{"code":0,"value":"useful"}},
|
||||
{"ok":false,"error":"connection lost"}
|
||||
]);
|
||||
assert_eq!(commit(&c).unwrap()["status"],"blocked");
|
||||
let after=next(&a).unwrap();
|
||||
assert_eq!(after["status"],"blocked");
|
||||
assert_eq!(after["partial"]["succeeded"],1);
|
||||
assert_eq!(after["partial"]["failed"],1);
|
||||
assert_eq!(commit(&c).unwrap()["status"],"blocked");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retries_only_failed_read_only_children_without_redoing_successes() {
|
||||
let mut a=fixture();
|
||||
a["steps"]=json!([{"id":"batch","kind":"parallel","effect_class":"read",
|
||||
"tasks":[{"path":"a.mq.md"},{"path":"b.mq.md"}]}]);
|
||||
open(&a).unwrap();
|
||||
let mut c=a.clone();
|
||||
c["step_id"]=json!("batch");
|
||||
c["response"]=json!([
|
||||
{"ok":true,"value":{"code":0,"value":"keep"}},
|
||||
{"ok":false,"error":"temporary timeout"}
|
||||
]);
|
||||
assert_eq!(commit(&c).unwrap()["status"],"blocked");
|
||||
let plan=retry_plan(&a).unwrap();
|
||||
assert_eq!(plan["indices"],json!([1]));
|
||||
assert_eq!(plan["tasks"].as_array().unwrap().len(),1);
|
||||
let mut retry=a.clone();
|
||||
retry["results"]=json!([{"ok":true,"value":{"code":0,"value":"fixed"}}]);
|
||||
assert_eq!(retry_commit(&retry).unwrap()["status"],"succeeded");
|
||||
let out=next(&a).unwrap();
|
||||
assert_eq!(out["completed"][0]["value"]["items"][0]["result"]["value"]["value"],"keep");
|
||||
assert_eq!(out["completed"][0]["value"]["items"][1]["result"]["value"]["value"],"fixed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_cancel_stops_future_commits() {
|
||||
let a=fixture();
|
||||
open(&a).unwrap();
|
||||
assert_eq!(cancel(&a).unwrap()["status"],"cancelled");
|
||||
let mut c=a.clone();
|
||||
c["step_id"]=json!("choose");
|
||||
c["response"]=json!("chat");
|
||||
assert_eq!(commit(&c).unwrap()["status"],"blocked");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reproducible marketing captures from the actual Marqdo 2.7.1 Linux CLI.
|
||||
|
||||
All procurement outputs are simulation-only. The GIF is a curated display of
|
||||
the real function-call JSON responses, not a filmed human typing session.
|
||||
The screenshot is taken with a real headless browser from marqdo view output.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
OUT = ROOT / "assets" / "marketing"
|
||||
SRC = "examples/procurement/index.mq.md"
|
||||
|
||||
def invoke(cli, fn, args=(), effects=None):
|
||||
cmd = [str(cli), "call", SRC, fn, *args]
|
||||
if effects:
|
||||
cmd += ["--effects", effects]
|
||||
cmd.append("--json")
|
||||
p = subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True, timeout=45)
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError("Command failed:\n" + " ".join(cmd) + "\n" + p.stdout + "\n" + p.stderr)
|
||||
try:
|
||||
result = json.loads(p.stdout)
|
||||
except json.JSONDecodeError as exc:
|
||||
raise RuntimeError(f"Non-JSON CLI response {p.stdout!r}") from exc
|
||||
if not result.get("ok"):
|
||||
raise RuntimeError("Marqdo call rejected: " + p.stdout)
|
||||
print("VERIFIED", fn, json.dumps(result, ensure_ascii=False))
|
||||
return result["result"]
|
||||
|
||||
def font(size, bold=False):
|
||||
for name in (
|
||||
"/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc" if bold else "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf" if bold else "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
):
|
||||
try:
|
||||
return ImageFont.truetype(name, size)
|
||||
except OSError:
|
||||
continue
|
||||
return ImageFont.load_default()
|
||||
|
||||
def frame(index, headline, invocation, details, emphasis=None, danger=False):
|
||||
W, H = 1200, 660
|
||||
img = Image.new("RGB", (W,H), (14,22,37))
|
||||
d = ImageDraw.Draw(img)
|
||||
gold = (238,201,145); muted = (159,178,204)
|
||||
d.rounded_rectangle((24,22,1175,635), radius=25, fill=(22,32,51), outline=(59,77,101), width=2)
|
||||
d.text((53,49), "Marqdo", font=font(30,True), fill=gold)
|
||||
d.text((231,57), "EXECUTABLE SKILLS / PROCUREMENT",font=font(19),fill=muted)
|
||||
d.rounded_rectangle((976,44,1138,82), radius=16, fill=(39,54,75))
|
||||
d.text((1000,54),"v2.7.1",font=font(18),fill=(216,227,239))
|
||||
d.text((53,139),headline,font=font(32,True),fill=(245,244,239))
|
||||
d.text((54,188),"CALL",font=font(16,True),fill=gold)
|
||||
d.rounded_rectangle((49,208,1150,293),radius=11,fill=(12,19,33))
|
||||
for i,line in enumerate(invocation):
|
||||
d.text((66,223+i*34),line,font=font(19),fill=(194,221,240))
|
||||
d.text((54,336),"ACTUAL CLI RESULT / DOMAIN FIELDS",font=font(16,True),fill=gold)
|
||||
d.rounded_rectangle((49,352,1150,536),radius=11,fill=(16,26,43))
|
||||
for i,line in enumerate(details[:5]):
|
||||
d.text((69,371+i*33),line,font=font(20),fill=(219,233,241))
|
||||
if emphasis:
|
||||
accent=(245,153,159) if danger else (155,231,185)
|
||||
d.rounded_rectangle((52,554,1149,609),radius=10,fill=(68,38,48) if danger else (30,67,57))
|
||||
d.text((71,569),emphasis,font=font(22,True),fill=accent)
|
||||
for i in range(5):
|
||||
x=79+i*219
|
||||
d.rounded_rectangle((x,621,x+204,628),radius=3,fill=gold if i<=index else (69,81,99))
|
||||
d.text((855,641),f"FRAME {index+1} / 5 · SIMULATED ONLY",font=font(13),fill=muted)
|
||||
return img
|
||||
|
||||
def make_gif(cli):
|
||||
suppliers=invoke(cli,"查询采购商",["采购商状态='正常'"])
|
||||
quote=invoke(cli,"查询采购商价格",["采购商标识符='SUP_JN'","数量=8","有效秒数=300"])
|
||||
balance=invoke(cli,"查询余额",["已花费=120"])
|
||||
orderargs=["采购商标识符='SUP_JN'","数量=8","单价=36","交付要求天数=7"]
|
||||
good=invoke(cli,"向采购商发工单",orderargs+["已花费=120"],effects="time.read,process.control")
|
||||
bad=invoke(cli,"向采购商发工单",orderargs+["已花费=360"],effects="time.read,process.control")
|
||||
assert isinstance(suppliers,list) and any(x.get("标识符")=="SUP_JN" for x in suppliers), suppliers
|
||||
assert quote["单价"]==36 and quote["报价总额"]==288,quote
|
||||
assert balance["可用余额"]==480,balance
|
||||
assert good["ok"] is True and good["value"]["工单金额"]==288 and good["value"]["状态"]=="本地模拟,未发送",good
|
||||
assert bad["ok"] is False and "采购金额超过" in bad["error"],bad
|
||||
|
||||
frames=[
|
||||
frame(0,"01 / Supplier approval",
|
||||
["$ marqdo call ... 查询采购商", " 采购商状态='正常'"],
|
||||
[f"result: {len(suppliers)} approved suppliers", "SUP_JN / 江南配件 / 正常", "Paused and blacklisted suppliers excluded."],
|
||||
"✓ SUP_JN passes supplier status"),
|
||||
frame(1,"02 / Quote lookup",
|
||||
["$ marqdo call ... 查询采购商价格", " 采购商标识符='SUP_JN' 数量=8 有效秒数=300"],
|
||||
[f"单价: ¥{quote['单价']}",f"数量: {quote['数量']}",f"报价总额: ¥{quote['报价总额']}","报价来源: 示例目录(未接实时接口)"],
|
||||
"✓ ¥36 × 8 = ¥288 — example quote"),
|
||||
frame(2,"03 / Budget check",
|
||||
["$ marqdo call ... 查询余额 已花费=120"],
|
||||
[f"最高预算: ¥{balance['最高预算']}",f"已花费: ¥{balance['已花费']}",f"可用余额: ¥{balance['可用余额']}","还能下单: "+str(balance["还能下单"])],
|
||||
"✓ ¥480 ≥ ¥288 — budget check passes"),
|
||||
frame(3,"04 / Callable simulated order",
|
||||
["$ marqdo call ... 向采购商发工单", " SUP_JN 数量=8 单价=36 已花费=120"],
|
||||
[f"result.ok: {str(good['ok']).lower()}", f"工单金额: ¥{good['value']['工单金额']}",f"状态: {good['value']['状态']}","No ERP message, payment or purchase was made."],
|
||||
"✓ SIMULATED ORDER ONLY — NOT SENT"),
|
||||
frame(4,"05 / Over-budget request denied",
|
||||
["$ marqdo call ... 向采购商发工单", " SUP_JN 数量=8 单价=36 已花费=360"],
|
||||
[f"result.ok: {str(bad['ok']).lower()}","最高预算: ¥600","剩余额度: ¥240","工单金额: ¥288", "错误: "+bad["error"]],
|
||||
"× WORK ORDER REFUSED AT RUNTIME",danger=True)
|
||||
]
|
||||
OUT.mkdir(parents=True,exist_ok=True)
|
||||
name=OUT/"procurement-cli.gif"
|
||||
frames[0].save(name,save_all=True,append_images=frames[1:],duration=[1600,1600,1600,1900,2300],loop=0,optimize=True)
|
||||
assert name.stat().st_size>10000, name
|
||||
print("GIF_WRITTEN",name,name.stat().st_size)
|
||||
|
||||
def make_screenshot(cli):
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
import time
|
||||
import tempfile
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
dest=Path(td)/"view"
|
||||
cmd=[str(cli),"view","output","examples/procurement","--out",str(dest),"--no-exec"]
|
||||
p=subprocess.run(cmd,cwd=ROOT,text=True,capture_output=True,timeout=90)
|
||||
if p.returncode:
|
||||
raise RuntimeError("View output error:\n"+p.stdout+"\n"+p.stderr)
|
||||
pages=sorted(dest.rglob("*.html"),key=lambda p:len(p.parts))
|
||||
print("VIEW_PAGES",[str(p.relative_to(dest)) for p in pages[:40]])
|
||||
if not pages:
|
||||
raise RuntimeError("No HTML pages emitted by Marqdo View")
|
||||
chosen=next((p for p in pages if "向采购商发工单" in p.read_text(encoding="utf-8",errors="replace")),pages[0])
|
||||
opts=Options()
|
||||
for arg in ["--headless=new","--no-sandbox","--disable-dev-shm-usage","--disable-gpu","--window-size=1500,1000"]:
|
||||
opts.add_argument(arg)
|
||||
driver=webdriver.Chrome(options=opts)
|
||||
try:
|
||||
driver.set_window_size(1500,1000)
|
||||
driver.get(chosen.as_uri())
|
||||
time.sleep(2)
|
||||
headings=driver.find_elements(By.CSS_SELECTOR,"h1,h2,h3,h4")
|
||||
matches=[el for el in headings if "向采购商发工单" in el.text]
|
||||
print("VIEW_HEADINGS",[(el.tag_name,el.text[:65]) for el in headings[:25]])
|
||||
if not matches:
|
||||
raise RuntimeError("Couldn't find procurement function heading in exported View")
|
||||
target=matches[0]
|
||||
driver.execute_script("arguments[0].scrollIntoView({block:'start'}); window.scrollBy(0,-115);",target)
|
||||
time.sleep(1)
|
||||
shot=OUT/"procurement-view.png"
|
||||
driver.save_screenshot(str(shot))
|
||||
assert shot.stat().st_size>20000,shot
|
||||
print("VIEW_SCREENSHOT_WRITTEN",shot,shot.stat().st_size)
|
||||
finally:
|
||||
driver.quit()
|
||||
|
||||
if __name__=="__main__":
|
||||
a=argparse.ArgumentParser()
|
||||
a.add_argument("--cli",required=True)
|
||||
args=a.parse_args()
|
||||
make_gif(Path(args.cli).resolve())
|
||||
make_screenshot(Path(args.cli).resolve())
|
||||
@@ -0,0 +1,369 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Make a 16:9 Marqdo promotional video from checked-in repository assets.
|
||||
|
||||
Inputs: GIF generated from actual v2.7.1 CLI results, and screenshot captured
|
||||
from actual v2.7.1 View. The budget scenario is explicitly simulated.
|
||||
Everything used to reproduce this movie is in the repository.
|
||||
No third-party soundtrack or music clips are used.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import wave
|
||||
from bisect import bisect_right
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ASSETS = ROOT / "assets" / "marketing"
|
||||
GIF = ASSETS / "procurement-cli.gif"
|
||||
VIEW = ASSETS / "procurement-view.png"
|
||||
PROC = ROOT / "examples" / "procurement" / "index.mq.md"
|
||||
OUT = ASSETS / "marqdo-2.7.1-promo.mp4"
|
||||
POSTER = ASSETS / "marqdo-2.7.1-poster.jpg"
|
||||
SUBTITLES = ASSETS / "marqdo-2.7.1-promo.srt"
|
||||
W, H, FPS = 1280, 720, 24
|
||||
DURATION = 32.0
|
||||
CUTS = [0.0, 3.9, 9.0, 17.4, 23.4, 29.0, DURATION]
|
||||
DARK = (11, 19, 32)
|
||||
GOLD = (232, 187, 123)
|
||||
LIGHT = (248, 246, 238)
|
||||
MUTED = (155, 174, 197)
|
||||
GREEN = (125, 224, 174)
|
||||
RED = (251, 151, 155)
|
||||
|
||||
def rgb(c):
|
||||
return tuple(c)
|
||||
|
||||
def choose_font(size, bold=False, serif=False):
|
||||
paths = [
|
||||
"/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc" if serif and bold else "",
|
||||
"/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc" if serif else "",
|
||||
"/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc" if bold else "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf" if bold else "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
]
|
||||
for p in paths:
|
||||
if not p:
|
||||
continue
|
||||
try:
|
||||
return ImageFont.truetype(p, size)
|
||||
except OSError:
|
||||
continue
|
||||
return ImageFont.load_default()
|
||||
|
||||
F = {
|
||||
"hero": choose_font(72, True),
|
||||
"big": choose_font(55, True),
|
||||
"h1": choose_font(42, True),
|
||||
"h2": choose_font(31, True),
|
||||
"mid": choose_font(25, True),
|
||||
"code": choose_font(23),
|
||||
"body": choose_font(22),
|
||||
"small": choose_font(17),
|
||||
"micro": choose_font(14),
|
||||
"zh": choose_font(28, serif=True),
|
||||
}
|
||||
|
||||
def text(draw, xy, msg, font, color=LIGHT, anchor=None):
|
||||
draw.text(xy, str(msg), font=font, fill=color, anchor=anchor)
|
||||
|
||||
def panel(draw, xy, fill=(24,35,54), outline=(51,67,89), rad=23, width=2):
|
||||
draw.rounded_rectangle(xy, radius=rad, fill=fill, outline=outline, width=width)
|
||||
|
||||
def mix(a, b, t):
|
||||
return a + (b-a)*t
|
||||
|
||||
def ease(x):
|
||||
u = max(0., min(1., x))
|
||||
return u*u*(3-2*u)
|
||||
|
||||
def appear(t, delay=0., span=.65):
|
||||
return ease((t-delay)/span)
|
||||
|
||||
def xshift(t, delay=.0):
|
||||
return int(38*(1-appear(t,delay)))
|
||||
|
||||
def opacity_overlay(base, overlay, alpha):
|
||||
return Image.blend(base, overlay, max(0.,min(1.,alpha)))
|
||||
|
||||
def clipped(src, size, center=(.5,.5), zoom=1):
|
||||
w,h=size
|
||||
if zoom > 1:
|
||||
p=ImageOps.fit(src,(int(w*zoom),int(h*zoom)),method=Image.Resampling.LANCZOS,centering=center)
|
||||
z=(p.width-w)//2
|
||||
v=(p.height-h)//2
|
||||
return p.crop((z,v,z+w,v+h))
|
||||
return ImageOps.fit(src,size,method=Image.Resampling.LANCZOS,centering=center)
|
||||
|
||||
def background(seed=0):
|
||||
im = Image.new("RGB",(W,H),DARK)
|
||||
pix=im.load()
|
||||
for y in range(H):
|
||||
for x in range(W):
|
||||
glow= max(0,1-math.hypot((x-1090)/1.3,(y-95)/1.1)/520)
|
||||
edge= max(0,1-math.hypot((x-25),y-690)/500)
|
||||
pix[x,y]=(int(11+14*glow+7*edge),int(19+9*glow+7*edge),int(32+13*glow+10*edge))
|
||||
d=ImageDraw.Draw(im)
|
||||
for x in range(45,W,82):
|
||||
d.line((x,0,x,H),fill=(18,29,45),width=1)
|
||||
for y in range(48,H,82):
|
||||
d.line((0,y,W,y),fill=(18,29,45),width=1)
|
||||
return im
|
||||
|
||||
BG=background()
|
||||
|
||||
def base_frame(t,scene):
|
||||
im=BG.copy()
|
||||
d=ImageDraw.Draw(im)
|
||||
# top identity, bottom running progress
|
||||
text(d,(63,35),"MARQDO",F["small"],GOLD)
|
||||
text(d,(168,36),"/ EXECUTABLE AI SKILLS",F["micro"],MUTED)
|
||||
d.rounded_rectangle((1079,21,1211,57),radius=15,fill=(40,51,68))
|
||||
text(d,(1095,30),"v2.7.1",F["small"],LIGHT)
|
||||
d.line((62,76,1214,76),fill=(48,61,80),width=2)
|
||||
d.line((62,694,1214,694),fill=(47,61,80),width=2)
|
||||
d.line((62,694,62+int((1152)*(t/DURATION)),694),fill=GOLD,width=4)
|
||||
text(d,(64,705),"DOCUMENT → FUNCTION → TOOL",F["micro"],(104,120,141))
|
||||
text(d,(1115,705),"%02d / 06" % (scene+1),F["micro"],(104,120,141))
|
||||
return im,d
|
||||
|
||||
def scene_hero(local,global_t):
|
||||
im,d=base_frame(global_t,0)
|
||||
a=appear(local,.07)
|
||||
yy=xshift(local,.08)
|
||||
text(d,(69,167+yy),"Your SKILL",F["hero"],LIGHT)
|
||||
text(d,(69,264+yy),"is now a",F["hero"],LIGHT)
|
||||
text(d,(69,361+yy),"TOOL.",F["hero"],GOLD)
|
||||
# typographic bar
|
||||
x=69
|
||||
d.rounded_rectangle((x,485,x+min(643,int(643*a)),489),radius=2,fill=GOLD)
|
||||
text(d,(71,520),"Write it. Inspect it. Call it.",F["mid"],LIGHT)
|
||||
text(d,(71,573),"让可读文档中的函数,真正成为可调用工具。",F["zh"],(224,219,205))
|
||||
d.rounded_rectangle((975,207,1169,493),radius=25,fill=(26,37,57),outline=(84,99,118),width=2)
|
||||
text(d,(1017,276),".mq.md",F["h2"],GOLD)
|
||||
text(d,(1017,357),"01 Read",F["small"],MUTED)
|
||||
text(d,(1017,399),"02 Call",F["small"],MUTED)
|
||||
text(d,(1017,441),"03 Check",F["small"],MUTED)
|
||||
return im
|
||||
|
||||
SOURCE_LINES=[
|
||||
"## 向采购商发工单",
|
||||
"采购商标识符 数量 单价 已花费",
|
||||
"",
|
||||
"正常商户 = 查询采购商(...)",
|
||||
"报价 = 查询采购商价格(...)",
|
||||
"预算 = 查询余额(已花费=...)",
|
||||
"",
|
||||
"1. 剩余额度 < 本单金额",
|
||||
" → 拒绝模拟工单",
|
||||
]
|
||||
def scene_source(local,global_t):
|
||||
im,d=base_frame(global_t,1)
|
||||
text(d,(71,110),"ONE DOCUMENT.",F["h1"],LIGHT)
|
||||
text(d,(71,159),"Contract, data, policy and implementation in the same .mq.md.",F["body"],MUTED)
|
||||
panel(d,(67,205,842,642),fill=(18,28,44),outline=(72,91,113))
|
||||
d.rounded_rectangle((67,205,842,254),radius=17,fill=(35,48,67))
|
||||
text(d,(93,218),"index.mq.md / procurement skill",F["small"],GOLD)
|
||||
ready=int(len(SOURCE_LINES)*ease((local-.40)/3.8))
|
||||
for i,ln in enumerate(SOURCE_LINES[:ready]):
|
||||
clr=GOLD if i in (0,7) else GREEN if i==8 else (178,204,232)
|
||||
text(d,(101,279+i*37),ln,F["code"],clr)
|
||||
panel(d,(863,205,1214,642),fill=(24,35,55),outline=(74,88,107))
|
||||
for j,(label,desc) in enumerate([
|
||||
("01 READ","human-readable"),
|
||||
("02 CHECK","typed contracts"),
|
||||
("03 CALL","marqdo call"),
|
||||
("04 RETURN","structured values")
|
||||
]):
|
||||
y=268+j*96
|
||||
d.rounded_rectangle((888,y,1187,y+66),radius=13,fill=(30,48,65))
|
||||
text(d,(907,y+11),label,F["small"],GOLD)
|
||||
text(d,(907,y+34),desc,F["micro"],(186,203,220))
|
||||
text(d,(71,662),"Excerpt simplified for screen layout; the full source is linked in the repository.",F["micro"],(110,135,154))
|
||||
return im
|
||||
|
||||
GIF_FRAMES=[]
|
||||
GIF_DURATIONS=[]
|
||||
if GIF.exists():
|
||||
im=Image.open(GIF)
|
||||
for i in range(getattr(im,"n_frames",1)):
|
||||
im.seek(i)
|
||||
GIF_FRAMES.append(im.convert("RGB").copy())
|
||||
GIF_DURATIONS.append(max(.3, im.info.get("duration",1600)/1000))
|
||||
if len(GIF_FRAMES) < 5:
|
||||
raise RuntimeError(f"Expected >= 5 real CLI demonstration frames, found {len(GIF_FRAMES)}")
|
||||
else:
|
||||
raise FileNotFoundError(GIF)
|
||||
GIF_CUM=[0.]
|
||||
for dur in GIF_DURATIONS:
|
||||
GIF_CUM.append(GIF_CUM[-1]+dur)
|
||||
GIF_CYCLE=GIF_CUM[-1]
|
||||
GIF_FITTED=[clipped(im,(1136,620)) for im in GIF_FRAMES]
|
||||
|
||||
def scene_cli(local,global_t):
|
||||
im,d=base_frame(global_t,2)
|
||||
# The 5 panels are constructed from real calls and validated in the original capture script.
|
||||
k=min(len(GIF_FITTED)-1,bisect_right(GIF_CUM,(local+.3)%GIF_CYCLE)-1)
|
||||
im.paste(GIF_FITTED[k],(72,73))
|
||||
d=ImageDraw.Draw(im)
|
||||
d.rectangle((73,73,1210,113),fill=(15,24,37))
|
||||
text(d,(91,82),"REAL CLI RETURNS / CURATED ANIMATED WALKTHROUGH",F["small"],GOLD)
|
||||
d.rectangle((76,664,1206,688),fill=(15,24,37))
|
||||
text(d,(87,665),"Supplier → Quote → Balance → Mock order → Over-budget refusal",F["small"],LIGHT)
|
||||
return im
|
||||
|
||||
def scene_outcomes(local,global_t):
|
||||
im,d=base_frame(global_t,3)
|
||||
text(d,(70,113),"THE LIMIT IS EXECUTED.",F["h1"])
|
||||
text(d,(70,164),"Two calls. Same unit price. Different accumulated spend.",F["body"],MUTED)
|
||||
q=ease((local-.6)/1.5)
|
||||
left=120+int(288*q)
|
||||
right=360+int(288*q)
|
||||
panel(d,(70,219,616,610),fill=(17,49,43),outline=(69,124,102))
|
||||
panel(d,(652,219,1202,610),fill=(55,29,39),outline=(150,78,90))
|
||||
text(d,(99,253),"ALLOWED · SIMULATION",F["small"],GREEN)
|
||||
text(d,(681,253),"DENIED · RUNTIME CHECK",F["small"],RED)
|
||||
text(d,(99,304),"¥120 + ¥288",F["h2"],LIGHT)
|
||||
text(d,(681,304),"¥360 + ¥288",F["h2"],LIGHT)
|
||||
text(d,(99,396),"¥"+str(left),F["hero"],GREEN)
|
||||
text(d,(681,396),"¥"+str(right),F["hero"],RED)
|
||||
text(d,(103,445),"≤ ¥600",F["mid"],(196,239,212))
|
||||
text(d,(686,445),"> ¥600",F["mid"],(255,202,211))
|
||||
d.line((100,476,581,476),fill=(77,119,101),width=2)
|
||||
d.line((681,476,1170,476),fill=(135,80,90),width=2)
|
||||
text(d,(101,497),"ok: true",F["mid"],GREEN)
|
||||
text(d,(680,497),"ok: false",F["mid"],RED)
|
||||
text(d,(101,553),"本地模拟,未发送",F["body"],(211,233,220))
|
||||
text(d,(680,553),"采购金额超过剩余额度",F["body"],(251,213,217))
|
||||
text(d,(71,651),"The function re-checks its own budget constraints. This is an offline example, not a real purchase.",F["micro"],MUTED)
|
||||
return im
|
||||
|
||||
VIEW_IMAGE=Image.open(VIEW).convert("RGB")
|
||||
VIEW_PANEL=(101,195,1179,635)
|
||||
VIEW_MASK=Image.new("L",(VIEW_PANEL[2]-VIEW_PANEL[0],VIEW_PANEL[3]-VIEW_PANEL[1]),0)
|
||||
ImageDraw.Draw(VIEW_MASK).rounded_rectangle((0,0,VIEW_MASK.width-1,VIEW_MASK.height-1),radius=18,fill=255)
|
||||
|
||||
def scene_view(local,global_t):
|
||||
im,d=base_frame(global_t,4)
|
||||
text(d,(70,111),"THE SAME SOURCE, BEAUTIFULLY INSPECTABLE.",F["h2"])
|
||||
text(d,(71,158),"Marqdo 2.7.1 View — an actual screenshot of the procurement function.",F["body"],MUTED)
|
||||
factor=1+.06*ease(local/5)
|
||||
content=clipped(VIEW_IMAGE,(VIEW_MASK.width,VIEW_MASK.height),center=(.50,.38),zoom=factor)
|
||||
im.paste(content,(VIEW_PANEL[0],VIEW_PANEL[1]),VIEW_MASK)
|
||||
d=ImageDraw.Draw(im)
|
||||
d.rounded_rectangle(VIEW_PANEL,radius=18,outline=(199,165,118),width=3)
|
||||
text(d,(104,665),"From marqdo view output • function 向采购商发工单",F["small"],(187,207,222))
|
||||
return im
|
||||
|
||||
def scene_outro(local,global_t):
|
||||
im,d=base_frame(global_t,5)
|
||||
text(d,(71,163),"One .mq.md",F["hero"],LIGHT)
|
||||
text(d,(71,260),"Many ways to use it.",F["h1"],GOLD)
|
||||
d.rounded_rectangle((70,365,1212,436),radius=19,fill=(33,49,67),outline=(81,101,124),width=2)
|
||||
text(d,(107,381),"Write it. Inspect it. Call it.",F["h2"],LIGHT)
|
||||
text(d,(73,490),"github.com/cflmy/marqdo",F["h1"],GOLD)
|
||||
text(d,(73,548),"Marqdo 2.7.1 • Rust-based document-native runtime",F["body"],MUTED)
|
||||
text(d,(73,613),"Demo uses simulated supplier data. No ERP connection or actual purchase.",F["small"],(176,190,204))
|
||||
return im
|
||||
|
||||
SCENE_FNS=[scene_hero,scene_source,scene_cli,scene_outcomes,scene_view,scene_outro]
|
||||
def render(t):
|
||||
i=min(len(SCENE_FNS)-1,bisect_right(CUTS,t)-1)
|
||||
im=SCENE_FNS[i](t-CUTS[i],t)
|
||||
end=CUTS[i+1]
|
||||
if i<len(SCENE_FNS)-1 and t > end-.43:
|
||||
other=SCENE_FNS[i+1](0,t)
|
||||
im=Image.blend(im,other,ease((t-(end-.43))/.43))
|
||||
return im
|
||||
|
||||
def make_audio(path):
|
||||
sr=24000
|
||||
count=round(DURATION*sr)
|
||||
times=np.arange(count,dtype=np.float64)/sr
|
||||
signal=np.zeros(count,dtype=np.float64)
|
||||
chords=[(110.0,164.8,220.0),(123.5,185.0,246.9),(130.8,196.0,261.6),(110.0,174.6,220.0),(123.5,185.0,246.9),(130.8,196.0,261.6)]
|
||||
for idx in range(6):
|
||||
start,end=CUTS[idx],CUTS[idx+1]
|
||||
mask=(times>=start)&(times<end)
|
||||
t=times[mask]-start
|
||||
fade=np.minimum(1,np.minimum(t/.8, (end-start-t)/.85).clip(min=0))
|
||||
notes=chords[idx]
|
||||
wavepad=(np.sin(2*np.pi*notes[0]*t)*0.54+
|
||||
np.sin(2*np.pi*notes[1]*t)*0.18+
|
||||
np.sin(2*np.pi*notes[2]*t)*0.12)
|
||||
signal[mask] += 0.12*fade*wavepad
|
||||
for at in CUTS[:-1]:
|
||||
start=int(at*sr)
|
||||
length=int(.16*sr)
|
||||
n=np.arange(length,dtype=np.float64)/sr
|
||||
chirp=(np.sin(2*np.pi*(640*n+680*n*n))*np.exp(-24*n))*0.12
|
||||
signal[start:start+length] += chirp
|
||||
signal *= np.minimum(1,np.minimum(times/1.2, (DURATION-times)/1.2).clip(min=0))
|
||||
pcm=np.clip(signal*32767,-32767,32767).astype(np.int16)
|
||||
with wave.open(str(path),"wb") as wav:
|
||||
wav.setnchannels(1);wav.setsampwidth(2);wav.setframerate(sr)
|
||||
wav.writeframes(pcm.tobytes())
|
||||
|
||||
def make_srt():
|
||||
times=[("00:00:00,000","00:00:03,900","Your SKILL is now a TOOL.\n让 SKILL 真正成为工具。"),
|
||||
("00:00:03,900","00:00:09,000","One readable document. Callable business logic.\n规则、数据、工具在同一份文档里。"),
|
||||
("00:00:09,000","00:00:17,400","Five verified CLI calls, from quote to decision.\n真实 CLI 结果:询价、预算、模拟发单。"),
|
||||
("00:00:17,400","00:00:23,400","¥120 spent: mock order. ¥360 spent: rejected.\n¥120 时模拟通过;¥360 时预算不足。"),
|
||||
("00:00:23,400","00:00:29,000","Inspect the actual document in Marqdo View.\n查看 Marqdo 真实 View 页面。"),
|
||||
("00:00:29,000","00:00:32,000","github.com/cflmy/marqdo\n开源 · Marqdo 2.7.1")]
|
||||
txt="\n\n".join(f"{i+1}\n{a} --> {b}\n{c}" for i,(a,b,c) in enumerate(times))+"\n"
|
||||
SUBTITLES.write_text(txt,encoding="utf-8")
|
||||
|
||||
def main():
|
||||
if not PROC.exists() or not VIEW.exists():
|
||||
raise FileNotFoundError("Expected procurement source and actual View screenshot")
|
||||
source=PROC.read_text("utf-8")
|
||||
assert "## 向采购商发工单" in source and "查询余额" in source
|
||||
assert VIEW_IMAGE.width >= 1200 and VIEW_IMAGE.height >= 700
|
||||
OUT.parent.mkdir(parents=True,exist_ok=True)
|
||||
POSTER_IMG=render(1.8)
|
||||
POSTER_IMG.save(POSTER,quality=92,optimize=True)
|
||||
make_srt()
|
||||
frames=int(DURATION*FPS)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
unscored=Path(tmp)/"silent.mp4"
|
||||
music=Path(tmp)/"music.wav"
|
||||
cmd=["ffmpeg","-y","-hide_banner","-loglevel","error","-f","rawvideo",
|
||||
"-pixel_format","rgb24","-video_size",f"{W}x{H}","-framerate",str(FPS),
|
||||
"-i","pipe:0","-an","-c:v","libx264","-preset","veryfast","-crf","21",
|
||||
"-pix_fmt","yuv420p","-movflags","+faststart",str(unscored)]
|
||||
proc=subprocess.Popen(cmd,stdin=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||
try:
|
||||
for k in range(frames):
|
||||
fr=render(k/FPS)
|
||||
proc.stdin.write(fr.tobytes())
|
||||
if k%120==0:
|
||||
print("rendered",k,"/",frames,flush=True)
|
||||
finally:
|
||||
if proc.stdin:
|
||||
proc.stdin.close()
|
||||
stderr=proc.stderr.read().decode(errors="replace")
|
||||
rc=proc.wait(timeout=70)
|
||||
if rc:
|
||||
raise RuntimeError("Video encoder error: "+stderr)
|
||||
make_audio(music)
|
||||
subprocess.run(["ffmpeg","-y","-hide_banner","-loglevel","error",
|
||||
"-i",str(unscored),"-i",str(music),"-c:v","copy","-c:a",
|
||||
"aac","-b:a","128k","-shortest","-movflags","+faststart",
|
||||
str(OUT)],check=True,timeout=90)
|
||||
print("VIDEO_WRITTEN",OUT,OUT.stat().st_size,flush=True)
|
||||
print("POSTER_WRITTEN",POSTER,POSTER.stat().st_size,flush=True)
|
||||
print("SUBTITLES_WRITTEN",SUBTITLES,SUBTITLES.stat().st_size,flush=True)
|
||||
ffprobe=subprocess.run(["ffprobe","-v","error","-show_entries",
|
||||
"format=duration,size:stream=codec_name,width,height",
|
||||
"-of","json",str(OUT)],capture_output=True,text=True,check=True)
|
||||
print("FFPROBE",ffprobe.stdout,flush=True)
|
||||
assert OUT.stat().st_size>1000000, "Suspiciously small encoded video"
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
@@ -115,11 +115,13 @@ rm -rf "$PKG_ROOT"
|
||||
mkdir -p "$PKG_ROOT" "$BUILD_AREA" "$RUST_CACHE"
|
||||
|
||||
REUSE_ORIG=0
|
||||
ORIG_PUBLISHED=0
|
||||
ORIG_SRC=""
|
||||
if [ "$FORCE_ORIG" != "1" ]; then
|
||||
# Prefer the bytes already accepted by Launchpad (rewriting .orig is rejected).
|
||||
if download_published_orig "$RUST_CACHE/$ORIG_NAME"; then
|
||||
ORIG_SRC="$RUST_CACHE/$ORIG_NAME"
|
||||
ORIG_PUBLISHED=1
|
||||
elif ORIG_SRC="$(resolve_existing_orig)"; then
|
||||
echo "warning: could not fetch PPA ${ORIG_NAME}; using local ${ORIG_SRC}" >&2
|
||||
echo "warning: if its sha256 differs from the archive, Launchpad will reject the upload" >&2
|
||||
@@ -223,8 +225,9 @@ ln -sfn "$BUILD_AREA/$ORIG_NAME" "$(dirname "$PKG_ROOT")/$ORIG_NAME"
|
||||
ls -lh "$BUILD_AREA/$ORIG_NAME"
|
||||
|
||||
cd "$PKG_ROOT"
|
||||
# -sd: debian-only upload (reuse published orig). -sa: include orig (new upstream).
|
||||
if [ "$REUSE_ORIG" -eq 1 ]; then
|
||||
# Local cache reuse does not prove Launchpad already has the orig archive.
|
||||
# Include its unchanged bytes until the published download succeeds.
|
||||
if [ "$ORIG_PUBLISHED" -eq 1 ]; then
|
||||
DEBUILD_ORIG_FLAG="-sd"
|
||||
echo "==> debuild -S ${DEBUILD_ORIG_FLAG} (key ${GPG_KEY}; not re-uploading .orig)"
|
||||
else
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Rebuild the Marqdo Markdown → View → execution promotional film.
|
||||
|
||||
Source imagery:
|
||||
- assets/marketing/user-procurement-view.png: original user-provided View capture
|
||||
- assets/marketing/source-markdown-view-concept.png: original generated concept art
|
||||
Other images are generated from the repository's actual procurement source.
|
||||
The purchasing demo is simulated, not an ERP transaction.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import math, subprocess, wave, tempfile
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageOps
|
||||
from markdown_it import MarkdownIt
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
A=ROOT/"assets"/"marketing"
|
||||
OUT=A/"marqdo-2.7.1-markdown-to-execution.mp4"
|
||||
POSTER=A/"marqdo-2.7.1-markdown-to-execution-cover.jpg"
|
||||
SRT=A/"marqdo-2.7.1-markdown-to-execution.srt"
|
||||
W,H=1600,900
|
||||
D=[4.8,6.8,6.4,7.0,7.5,9.5,8.8,5.2]
|
||||
IVORY=(249,247,242);INK=(37,35,34);GOLD=(191,146,81);PEARL=(242,232,214);DIM=(122,114,105);NIGHT=(18,23,32)
|
||||
REG="/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"
|
||||
BOLD="/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc"
|
||||
SERIF="/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"
|
||||
SERIFB="/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc"
|
||||
def f(size,mode="regular"):
|
||||
return ImageFont.truetype({"regular":REG,"bold":BOLD,"serif":SERIF,"serifbold":SERIFB}[mode],size)
|
||||
def txt(d,xy,s,size=26,color=INK,style="regular"):
|
||||
d.text(xy,str(s),font=f(size,style),fill=color)
|
||||
def card(d,box,fill=IVORY,stroke=(220,210,195),r=24):
|
||||
d.rounded_rectangle(box,radius=r,fill=fill,outline=stroke,width=2)
|
||||
def base(dark=False):
|
||||
im=Image.new("RGB",(W,H),NIGHT if dark else IVORY)
|
||||
d=ImageDraw.Draw(im)
|
||||
if dark:
|
||||
for j in range(8):
|
||||
d.arc((880+j*32,-200+j*26,1760+j*28,1030+j*25),158,268,fill=(68+j*7,60+j*6,51+j*4),width=2)
|
||||
else:
|
||||
for j in range(7):
|
||||
d.arc((-430+j*14,-500+j*14,500+j*25,520+j*25),35,150,fill=(238,224+j*2,207+j*2),width=2)
|
||||
return im
|
||||
def rounded_image(im,src,box,focus=(.5,.5)):
|
||||
x1,y1,x2,y2=box
|
||||
crop=ImageOps.fit(src,(x2-x1,y2-y1),method=Image.Resampling.LANCZOS,centering=focus)
|
||||
mask=Image.new("L",crop.size,0)
|
||||
ImageDraw.Draw(mask).rounded_rectangle((0,0,crop.width-1,crop.height-1),radius=18,fill=255)
|
||||
im.paste(crop,(x1,y1),mask)
|
||||
ImageDraw.Draw(im).rounded_rectangle(box,radius=18,outline=(200,177,145),width=2)
|
||||
def footer(d,text,dark=False):
|
||||
txt(d,(80,855),text,18,(148,158,171) if dark else DIM)
|
||||
def make_intro():
|
||||
im=base(True);d=ImageDraw.Draw(im)
|
||||
txt(d,(94,113),"MARQDO / v2.7.1",21,(233,197,146))
|
||||
txt(d,(90,221),"Your SKILL",83,IVORY,"serifbold")
|
||||
txt(d,(90,327),"is now a",83,IVORY,"serifbold")
|
||||
txt(d,(90,435),"TOOL.",91,(244,201,148),"serifbold")
|
||||
d.line((100,562,1040,562),fill=GOLD,width=3)
|
||||
txt(d,(102,613),"不只是让 AI 阅读文档。",35,(232,230,224),"serif")
|
||||
txt(d,(102,681),"让同一份 Markdown 承载可控执行流。",35,(232,230,224),"serif")
|
||||
footer(d,"WRITE ONCE · RENDER AS MARKDOWN · INSPECT AS RUNTIME",True)
|
||||
return im
|
||||
|
||||
source=(ROOT/"examples/procurement/index.mq.md").read_text(encoding="utf8")
|
||||
assert "## 查询采购商价格" in source
|
||||
section=source.split("## 查询采购商价格",1)[1].split("\n## ",1)[0]
|
||||
excerpt="## 查询采购商价格\n"+section
|
||||
lines=excerpt.splitlines()
|
||||
content=[]
|
||||
for line in lines:
|
||||
if len(content)>=18:break
|
||||
content.append(line)
|
||||
assert len(content)>10
|
||||
md=MarkdownIt("commonmark").enable("table")
|
||||
html=md.render("\n".join(content))
|
||||
document=f"""<!DOCTYPE html><html lang='zh'><head><meta charset='utf-8'>
|
||||
<style>html,body{{margin:0;background:#fcfbf6;color:#34302d}}
|
||||
body{{font-family:'Noto Serif CJK SC',serif;padding:64px 96px;font-size:26px;line-height:1.75}}
|
||||
h2{{font-size:43px;font-weight:700;margin:0 0 33px}}
|
||||
p{{margin:17px 0}}table{{font:20px/1.7 'Noto Sans CJK SC',sans-serif;width:100%;border-collapse:collapse;margin:26px 0}}
|
||||
td,th{{padding:12px 18px;border:1px solid #e1d7c8;text-align:left}}
|
||||
th{{background:#efe7d9}}tr:nth-child(even){{background:#f7f2e9}}em{{color:#8c704f}}
|
||||
</style></head><body>{html}</body></html>"""
|
||||
opts=Options()
|
||||
for arg in ["--headless=new","--no-sandbox","--disable-dev-shm-usage","--disable-gpu","--window-size=1450,1600"]:
|
||||
opts.add_argument(arg)
|
||||
browser=webdriver.Chrome(options=opts)
|
||||
try:
|
||||
browser.set_window_size(1450,1600)
|
||||
browser.get("data:text/html;charset=utf-8,"+__import__("urllib.parse",fromlist=["quote"]).quote(document))
|
||||
htmlscreen=A/"marqdo-procurement-standard-markdown.png"
|
||||
browser.save_screenshot(str(htmlscreen))
|
||||
assert htmlscreen.stat().st_size>20000
|
||||
finally:
|
||||
browser.quit()
|
||||
RENDER=Image.open(htmlscreen).convert("RGB")
|
||||
USER=Image.open(A/"user-procurement-view.png").convert("RGB")
|
||||
CONCEPT=Image.open(A/"source-markdown-view-concept.png").convert("RGB")
|
||||
|
||||
def make_source():
|
||||
im=base(True);d=ImageDraw.Draw(im)
|
||||
txt(d,(78,69),"01 / SOURCE",21,(226,192,141))
|
||||
txt(d,(77,123),"源码态:它本来就是 Markdown",54,IVORY,"serifbold")
|
||||
txt(d,(80,209),"普通段落保持可读,标题、参数表和返回契约仍是 Markdown。",28,(187,198,213))
|
||||
card(d,(75,265,1520,797),(28,38,51),(78,89,105),23)
|
||||
card(d,(76,265,1519,332),(43,53,70),(43,53,70),23)
|
||||
for j,col in enumerate([(190,97,91),(224,173,97),(109,173,130)]):
|
||||
d.ellipse((105+j*33,293,122+j*33,310),fill=col)
|
||||
txt(d,(256,282),"index.mq.md · 查询采购商价格",24,(227,227,222))
|
||||
for i,line in enumerate(content[:16]):
|
||||
value=line[:77].replace("\t"," ")
|
||||
clr=(232,193,133) if value.startswith("#") or "返回" in value else ((164,214,201) if "正常" in value else (221,226,230))
|
||||
txt(d,(106,358+i*25),f"{i+1:02d} {value}",20,clr)
|
||||
footer(d,"ACTUAL .mq.md EXCERPT · source: examples/procurement/index.mq.md",True)
|
||||
return im
|
||||
|
||||
def make_render():
|
||||
im=base();d=ImageDraw.Draw(im)
|
||||
txt(d,(81,69),"02 / STANDARD MARKDOWN",21,(170,126,67))
|
||||
txt(d,(77,128),"渲染态:它首先是一篇文档",56,INK,"serifbold")
|
||||
txt(d,(80,205),"同一段源码,无需定制语法高亮,也可以按 Markdown 阅读。",29,DIM)
|
||||
card(d,(80,265,1516,839),(255,254,251))
|
||||
rounded_image(im,RENDER,(120,290,1469,814),(.5,.19))
|
||||
txt(ImageDraw.Draw(im),(1145,280),"STANDARD MARKDOWN",18,(167,115,55))
|
||||
footer(ImageDraw.Draw(im),"A MARKDOWN-IT RENDER · FROM THE SAME SOURCE")
|
||||
return im
|
||||
|
||||
def make_triple():
|
||||
im=base();d=ImageDraw.Draw(im)
|
||||
txt(d,(75,60),"03 / THREE VIEWS, ONE FILE",21,(170,126,67))
|
||||
txt(d,(76,130),"同一份 .mq.md,三种视图",55,INK,"serifbold")
|
||||
txt(d,(81,211),"源码能编写,Markdown 能阅读,View 能看到函数、值和执行依赖。",27,DIM)
|
||||
screens=[("SOURCE / 源码",make_source()),("MARKDOWN / 渲染",RENDER),("VIEW / 执行",USER)]
|
||||
xlist=[75,578,1081]
|
||||
for i,(label,src) in enumerate(screens):
|
||||
x=xlist[i];tw=442
|
||||
card(d,(x,280,x+tw,777),(255,254,250))
|
||||
txt(d,(x+21,301),label,23,(130,95,56))
|
||||
rounded_image(im,src,(x+15,349,x+tw-15,749),(.50,.38))
|
||||
d=ImageDraw.Draw(im)
|
||||
for x in [523,1026]:
|
||||
d.line((x,530,x+49,530),fill=GOLD,width=4)
|
||||
d.polygon([(x+49,530),(x+32,519),(x+32,541)],fill=GOLD)
|
||||
footer(d,"NOT THREE FILES · ONE DOCUMENT + EXECUTION SEMANTICS")
|
||||
return im
|
||||
|
||||
def make_concept():
|
||||
im=base();d=ImageDraw.Draw(im)
|
||||
txt(d,(72,58),"04 / DESIGN LANGUAGE",21,(170,126,67))
|
||||
rounded_image(im,CONCEPT,(55,112,1545,850),(.5,.5))
|
||||
txt(ImageDraw.Draw(im),(92,855),"CONCEPT ART · Source → Rendered Markdown → Marqdo View",18,DIM)
|
||||
return im
|
||||
|
||||
def make_view():
|
||||
im=base();d=ImageDraw.Draw(im)
|
||||
txt(d,(78,62),"05 / REAL MARQDO VIEW",21,(170,126,67))
|
||||
txt(d,(78,127),"在文档上,看见它的执行流",58,INK,"serifbold")
|
||||
txt(d,(80,216),"自然语言依然是主体,执行信息沿优雅的曲线引出。",28,DIM)
|
||||
card(d,(70,278,1530,841),(255,254,250))
|
||||
rounded_image(im,USER,(88,295,1513,817),(.50,.50))
|
||||
footer(ImageDraw.Draw(im),"ACTUAL VIEW SCREENSHOT · PROVIDED BY THE PROJECT AUTHOR")
|
||||
return im
|
||||
|
||||
def make_execution():
|
||||
im=base(True);d=ImageDraw.Draw(im)
|
||||
txt(d,(80,66),"06 / EXECUTABLE FUNCTIONS",21,(230,192,137))
|
||||
txt(d,(80,132),"在哪里执行?就在同一份文档的函数里。",53,IVORY,"serifbold")
|
||||
txt(d,(84,216),"说明是可读的,规则却会通过函数调用实际检查。",28,(183,198,211))
|
||||
card(d,(76,275,1519,367),(30,42,57),(78,88,100))
|
||||
txt(d,(99,303),"marqdo call examples/procurement/index.mq.md 查询余额 已花费=120",25,(233,218,188))
|
||||
card(d,(76,418,760,775),(25,55,48),(70,124,96))
|
||||
card(d,(790,418,1520,775),(58,34,43),(154,85,96))
|
||||
txt(d,(110,455),"PASS / LOCAL SIMULATION",24,(150,227,185))
|
||||
txt(d,(822,455),"DENIED / BUDGET CHECK",24,(249,164,170))
|
||||
txt(d,(112,533),"¥120 + ¥288",43,IVORY)
|
||||
txt(d,(823,533),"¥360 + ¥288",43,IVORY)
|
||||
txt(d,(113,606),"¥408",86,(146,229,185),"bold")
|
||||
txt(d,(823,606),"¥648",86,(250,162,166),"bold")
|
||||
txt(d,(115,720),"ok: true · 本地模拟,未发送",23,(217,237,224))
|
||||
txt(d,(824,720),"ok: false · 超预算拒绝",23,(248,216,217))
|
||||
footer(d,"OUTCOMES VERIFIED WITH MARQDO 2.7.1 CLI · NO REAL ORDER WAS SENT",True)
|
||||
return im
|
||||
|
||||
def make_outro():
|
||||
im=base(True);d=ImageDraw.Draw(im)
|
||||
txt(d,(97,157),"Marqdo",90,IVORY,"serifbold")
|
||||
txt(d,(98,313),"Write it. Read it. Run it.",61,(238,195,136),"serifbold")
|
||||
d.line((99,431,1480,431),fill=GOLD,width=3)
|
||||
txt(d,(101,500),"A document-native runtime for executable AI skills.",31,(217,221,225))
|
||||
txt(d,(101,649),"github.com/cflmy/marqdo",43,IVORY)
|
||||
footer(d,"Marqdo v2.7.1 · Apache 2.0 · simulated procurement demo",True)
|
||||
return im
|
||||
|
||||
slides=[make_intro(),make_source(),make_render(),make_triple(),make_concept(),make_view(),make_execution(),make_outro()]
|
||||
A.mkdir(parents=True,exist_ok=True)
|
||||
slides[0].save(POSTER,quality=95)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp=Path(tmp);clips=[]
|
||||
for i,(still,dur) in enumerate(zip(slides,D)):
|
||||
imagefile=tmp/f"slide_{i:02d}.png"
|
||||
still.save(imagefile)
|
||||
clip=tmp/f"clip_{i:02d}.mp4"
|
||||
filt=f"scale=1280:720,zoompan=z='min(zoom+0.00016,1.02)':x='iw/2-iw/zoom/2':y='ih/2-ih/zoom/2':d=1:s=1280x720:fps=24,fade=t=in:st=0:d=0.4,fade=t=out:st={dur-.5}:d=0.5,format=yuv420p"
|
||||
cmd=["ffmpeg","-y","-hide_banner","-loglevel","error","-loop","1","-framerate","24","-t",str(dur),"-i",str(imagefile),"-vf",filt,"-an","-c:v","libx264","-preset","veryfast","-crf","19","-pix_fmt","yuv420p",str(clip)]
|
||||
subprocess.run(cmd,check=True,timeout=200)
|
||||
clips.append(clip)
|
||||
print("RENDERED_SLIDE",i,flush=True)
|
||||
playlist=tmp/"concat.txt"
|
||||
playlist.write_text("\n".join(f"file '{c}'" for c in clips)+"\n")
|
||||
silent=tmp/"silent.mp4"
|
||||
subprocess.run(["ffmpeg","-y","-hide_banner","-loglevel","error","-f","concat","-safe","0","-i",str(playlist),"-c","copy",str(silent)],check=True,timeout=90)
|
||||
sr=24000
|
||||
total=sum(D);ts=np.arange(int(total*sr))/sr
|
||||
sound=np.zeros(len(ts))
|
||||
at=0.
|
||||
for i,dur in enumerate(D):
|
||||
mask=(ts>=at)&(ts<at+dur);tt=ts[mask]-at
|
||||
a=np.minimum(np.minimum(tt/.8,(dur-tt)/.8),1).clip(0,1)
|
||||
note=[110.,123.47,130.81,146.83,110.,123.47,130.81,110.][i]
|
||||
sound[mask]+=a*.12*(.55*np.sin(2*np.pi*note*tt)+.2*np.sin(2*np.pi*note*1.5*tt)+.12*np.sin(2*np.pi*note*2*tt))
|
||||
at+=dur
|
||||
sound*=np.minimum(np.minimum(ts/1.2,(total-ts)/1.2),1).clip(0,1)
|
||||
wav=tmp/"ambience.wav"
|
||||
with wave.open(str(wav),"wb") as w:
|
||||
w.setnchannels(1);w.setsampwidth(2);w.setframerate(sr)
|
||||
w.writeframes((sound*32767).astype(np.int16).tobytes())
|
||||
subprocess.run(["ffmpeg","-y","-hide_banner","-loglevel","error","-i",str(silent),"-i",str(wav),"-c:v","copy","-c:a","aac","-b:a","160k","-shortest","-movflags","+faststart",str(OUT)],check=True,timeout=90)
|
||||
|
||||
times=[0,4.8,11.6,18,25,32.5,42,50.8,56]
|
||||
messages=[
|
||||
"Your SKILL is now a TOOL.\n让 Markdown 直接承载可执行语义。",
|
||||
"源码态:标题、段落、表格都沿用 Markdown。\n执行逻辑就在文档之中。",
|
||||
"渲染态:同一份代码也能成为普通 Markdown 文档。",
|
||||
"源码态、标准 Markdown 渲染态、Marqdo View 态。\n三种视图,同一份源文件。",
|
||||
"一份 .mq.md,既可以阅读,也可以编译执行。",
|
||||
"真实 View 截图:函数调用和值沿着优雅曲线呈现。",
|
||||
"预算校验不是文字承诺,而是函数执行。\n模拟订单通过或拒绝,均由运行时返回结果。",
|
||||
"Marqdo 2.7.1 · github.com/cflmy/marqdo"
|
||||
]
|
||||
def stamp(s):
|
||||
ms=int(round(s*1000))
|
||||
h=ms//3600000;ms%=3600000;m=ms//60000;ms%=60000
|
||||
return f"{h:02d}:{m:02d}:{ms//1000:02d},{ms%1000:03d}"
|
||||
SRT.write_text("\n\n".join(f"{i+1}\n{stamp(times[i])} --> {stamp(times[i+1])}\n{msg}" for i,msg in enumerate(messages))+"\n",encoding="utf-8")
|
||||
print("VIDEO",OUT,OUT.stat().st_size)
|
||||
print("COVER",POSTER,POSTER.stat().st_size)
|
||||
print("SRT",SRT,SRT.stat().st_size)
|
||||
assert OUT.stat().st_size>800000 and sum(D)==56
|
||||
@@ -0,0 +1,70 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: AI native flow offline smoke
|
||||
import:
|
||||
flow: ext/ai/flow.mq.md
|
||||
context: ext/ai/context.mq.md
|
||||
json: lib/json.mq.md
|
||||
sys: lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
This fixture tests the real Marqdo interface without a model provider.
|
||||
It refuses an invalid choice and retrieves only the designated function
|
||||
rather than guessing another SKILL or importing the full document.
|
||||
|
||||
**opts = > json.parse text=["chat","office"]**
|
||||
**pick = > flow.parse_choice reply="选择:office" options=`opts`**
|
||||
**value = > json.get value=`pick` key="value"**
|
||||
1. `value` == "office"
|
||||
**_ = 1**
|
||||
2. *
|
||||
**debug_pick = > json.stringify value=`pick`**
|
||||
> print text=`debug_pick`
|
||||
> sys.exit code=11
|
||||
|
||||
**structured = > flow.parse_choice reply="{\"choice\":\"chat\"}" options=`opts`**
|
||||
**structure_value = > json.get value=`structured` key="value"**
|
||||
1. `structure_value` == "chat"
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=16
|
||||
|
||||
**invalid = > flow.parse_choice reply="chat 或 office" options=`opts`**
|
||||
**not_ok = > json.get value=`invalid` key="ok"**
|
||||
1. `not_ok`
|
||||
> sys.exit code=12
|
||||
2. *
|
||||
**_ = 1**
|
||||
|
||||
**ctx = > context.scope scope="function" class="main" function="probe" max_chars=200**
|
||||
**ok = > json.get value=`ctx` key="ok"**
|
||||
1. `ok`
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=13
|
||||
|
||||
**packed = > context.compose user="Test the route" class="main" function="probe" budget_tokens=2048**
|
||||
**pack_schema = > json.get value=`packed` key="schema"**
|
||||
1. `pack_schema` == "ContextPackV2"
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=15
|
||||
|
||||
**gate = > flow.input id="ai_native_flow_ci_gate" question="Continue?" options=`opts` source_revision="fixture-v1" freeform=False**
|
||||
**answered = > flow.reply id="ai_native_flow_ci_gate" reply="office" source_revision="fixture-v1"**
|
||||
**answer = > json.get value=`answered` key="value"**
|
||||
1. `answer` == "office"
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=14
|
||||
|
||||
Return *"ai-flow-native-ok"*.
|
||||
|
||||
## probe
|
||||
|
||||
This private helper's narrative should be extracted by the scoped selector
|
||||
without including the root SKILL or neighboring function definitions.
|
||||
|
||||
Return *"probe"*.
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: ABI-native durable agent workflow test
|
||||
import:
|
||||
workflow: ext/ai/workflow.mq.md
|
||||
json: lib/json.mq.md
|
||||
sys: lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Offline test: the same Marqdo program advances through model choice, user
|
||||
input and terminal state with plugin-owned durable checkpoints.
|
||||
|
||||
**steps = > json.parse text=[{"id":"intent","kind":"model","prompt":"Choose next skill","options":["chat","office"]},{"id":"confirm","kind":"input","question":"Continue?","options":["yes","no"]},{"id":"end","kind":"return"}]**
|
||||
**opened = > workflow.open id="abi_flow_ci_20261118" steps=`steps` source_revision="flow-v1"**
|
||||
**o = > json.get value=`opened` key="ok"**
|
||||
1. `o`
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=21
|
||||
|
||||
**first = > workflow.next id="abi_flow_ci_20261118" source_revision="flow-v1"**
|
||||
**first_state = > json.get value=`first` key="status"**
|
||||
1. `first_state` == "waiting_model"
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=22
|
||||
|
||||
**c1 = > workflow.commit id="abi_flow_ci_20261118" step_id="intent" response="chat" source_revision="flow-v1"**
|
||||
**done1 = > json.get value=`c1` key="ok"**
|
||||
1. `done1`
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=23
|
||||
|
||||
**second = > workflow.tick id="abi_flow_ci_20261118" source_revision="flow-v1"**
|
||||
**second_state = > json.get value=`second` key="status"**
|
||||
1. `second_state` == "waiting_input"
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=24
|
||||
|
||||
**c2 = > workflow.commit id="abi_flow_ci_20261118" step_id="confirm" response="yes" source_revision="flow-v1"**
|
||||
**done2 = > json.get value=`c2` key="ok"**
|
||||
1. `done2`
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=25
|
||||
|
||||
**c3 = > workflow.tick id="abi_flow_ci_20261118" source_revision="flow-v1"**
|
||||
**complete = > workflow.next id="abi_flow_ci_20261118" source_revision="flow-v1"**
|
||||
**status = > json.get value=`complete` key="status"**
|
||||
1. `status` == "succeeded"
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=26
|
||||
|
||||
**partial_steps = > json.parse text=[{"id":"children","kind":"parallel","effect_class":"read","tasks":[{"path":"worker-a.mq.md"},{"path":"worker-b.mq.md"}]}]**
|
||||
**new_batch = > workflow.open id="abi_flow_partial_ci_20261118" steps=`partial_steps` source_revision="flow-v1"**
|
||||
**parts = > json.parse text=[{"ok":true,"value":{"code":0,"value":"useful"}},{"ok":false,"error":"timeout"}]**
|
||||
**stopped = > workflow.commit id="abi_flow_partial_ci_20261118" step_id="children" response=`parts` source_revision="flow-v1"**
|
||||
**reloaded = > workflow.next id="abi_flow_partial_ci_20261118" source_revision="flow-v1"**
|
||||
**partial = > json.get value=`reloaded` key="partial"**
|
||||
**survivors = > json.get value=`partial` key="succeeded"**
|
||||
1. `survivors` == 1
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=27
|
||||
|
||||
**retry_plan = > workflow.retry_plan id="abi_flow_partial_ci_20261118" source_revision="flow-v1"**
|
||||
**allowed = > json.get value=`retry_plan` key="ok"**
|
||||
1. `allowed`
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=28
|
||||
**repaired = > json.parse text=[{"ok":true,"value":{"code":0,"value":"repaired"}}]**
|
||||
**merged = > workflow.retry_commit id="abi_flow_partial_ci_20261118" results=`repaired` source_revision="flow-v1"**
|
||||
**merged_ok = > json.get value=`merged` key="ok"**
|
||||
1. `merged_ok`
|
||||
**_ = 1**
|
||||
2. *
|
||||
> sys.exit code=29
|
||||
|
||||
Return *"durable-agent-flow-ok"*.
|
||||