refactor: convert Marqdo into the ecosystem integration repository
This commit is contained in:
1 parent
1c55baabd5
commit
4c5c102593
1880 files changed
+998
-308724
No files matched your search
@@ -1,13 +0,0 @@
|
||||
# agent-okf-flywheel(Wave B0)
|
||||
|
||||
演示 **文档即知识库(OKF)**:固化工作簿 promote 后,相同 goal 的 `plan` 走 `cache=hit`(`llm_free` 路径),无需再问模型。
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo -p marqdo_plugin_agent
|
||||
export MARQDO_EXT="$PWD/.marqdo-ext"
|
||||
./target/release/marqdo run examples/agent-okf-flywheel/index.mq.md
|
||||
```
|
||||
|
||||
期望:`promoted` · `hit` · `flywheel-ok`。
|
||||
|
||||
见 [okf.md](../../doc/design/okf.md) · [agent-framework-2026-09.md](../../doc/research/agent-framework-2026-09.md)。
|
||||
@@ -1,70 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: agent-okf-flywheel (Wave B0)
|
||||
description: Promote solidified workbook; second plan is cache=hit — document as knowledge base (OKF).
|
||||
import:
|
||||
llm: ext/ai/llm.mq.md
|
||||
agent: ext/ai/agent.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
json: lib/json.mq.md
|
||||
plugin: lib/plugin.mq.md
|
||||
sys: lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
This is an offline knowledge-reuse workflow, not a request to an external model. It loads the agent plugin, promotes the visible workbook for one exact goal and asks the same agent goal again. The expected hit comes from the promoted knowledge base. The dummy key only satisfies model setup; it is not a credential or evidence that a model call succeeded.
|
||||
|
||||
The example uses its own named files under .marqdo and replaces that example knowledge base on rerun. Grant the actual plugin and filesystem effects in a disposable example root. Promotion and execution are separate outcomes: inspect promoted first, then cache, match and the returned result. A hit marker alone does not prove that an unrelated new goal is safe to reuse.
|
||||
|
||||
OKF flywheel offline: promote → plan same goal → `cache=hit` (no live LLM required for the hit path).
|
||||
|
||||
We first **p = [Compute p](plugin.native_path(name="agent"))** for the next step.
|
||||
1. `p`
|
||||
We now **[Call plugin.load](> plugin.load path=`p`)**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="no-agent-plugin")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
|
||||
We now **[Call sys.env set](> sys.env_set name="OPENAI_API_KEY" value="offline-okf-dummy")**.
|
||||
We first **model = [Compute model](llm.llm())** for the next step.
|
||||
We first **tools = [Compute tools](json.parse(text="[]"))** for the next step.
|
||||
We first **助手 = [Compute 助手](agent.agent(model=`model`, tools=`tools`, standing="offline okf flywheel"))** for the next step.
|
||||
|
||||
We first **kb = ".marqdo/agent-kb-example-flywheel"** for the next step.
|
||||
We first **wb = ".marqdo/agent-runs/example-pong-solid.mq.md"** for the next step.
|
||||
We first **goal = "Reply with exactly the word pong and nothing else."** for the next step.
|
||||
We first **body = "---\ntitle: okf pong\n---\n\n# main\n\n*msg = \"pong\"*\n\n**msg**\n"** for the next step.
|
||||
|
||||
1. > fs.exists path=`kb`
|
||||
We now **[Call fs.remove](> fs.remove path=`kb`)**.
|
||||
2. *
|
||||
---
|
||||
|
||||
We now **[Call fs.write text](> fs.write_text path=`wb` text=`body`)**.
|
||||
|
||||
We first **prom = [Compute prom](agent_kb_promote(kb_dir=`kb`, goal=`goal`, workbook=`wb`))** for the next step.
|
||||
We first **okp = [Compute okp](json.get(value=`prom`, key="promoted"))** for the next step.
|
||||
1. `okp`
|
||||
We now **[Display this step's result](> print text="promoted")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="promote-fail")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
|
||||
We first **out = [Compute out](> `助手`.plan goal=`goal` max_rounds=2 writeback=False kb_dir=`kb` explore_n=0 promote=False)** for the next step.
|
||||
We first **cache = [Compute cache](json.get(value=`out`, key="cache"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`cache`)**.
|
||||
We first **match = [Compute match](json.get(value=`out`, key="match"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`match`)**.
|
||||
We first **val = [Compute val](json.get(value=`out`, key="result"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`val`)**.
|
||||
|
||||
1. `cache` == "hit"
|
||||
We now **[Display this step's result](> print text="flywheel-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="flywheel-miss")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
@@ -1,16 +0,0 @@
|
||||
# agent-pong(Wave B0)
|
||||
|
||||
演示 Marqdo 智能体宪法:**代码即文档** — 模型上下文含 **call site** 与本文件 **source**;工具是同文件里的 `## 获取时间`。
|
||||
|
||||
```bash
|
||||
# 仓库根目录
|
||||
cargo build --release -p marqdo -p marqdo_plugin_agent
|
||||
export MARQDO_EXT="$PWD/.marqdo-ext" # 或: marqdo ext add agent
|
||||
# 可选 live:仓库根 `.env` + `AGENT_LIVE=1 marqdo run examples/agent-pong/index.mq.md`
|
||||
./target/release/marqdo run examples/agent-pong/index.mq.md
|
||||
```
|
||||
|
||||
期望离线输出含:`call-site-ok` · `source-ok` · `tool-in-source-ok`。
|
||||
配置真实 `.env` 时还会跑一次 `step`(CALL 工具)。
|
||||
|
||||
见 [agent-framework-2026-09.md](../../doc/research/agent-framework-2026-09.md)。
|
||||
@@ -1,103 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: agent-pong (Wave B0)
|
||||
description: >-
|
||||
Constitution demo — call_site + source in step context; optional live CALL via .env.
|
||||
Code is documentation; tools are ## in this same file.
|
||||
import:
|
||||
llm: ext/ai/llm.mq.md
|
||||
agent: ext/ai/agent.mq.md
|
||||
json: lib/json.mq.md
|
||||
plugin: lib/plugin.mq.md
|
||||
sys: lib/sys.mq.md
|
||||
time: lib/time.mq.md
|
||||
---
|
||||
|
||||
## 获取时间
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
Return today's date string (tool visible in source to the model).
|
||||
|
||||
We first **u = [Compute u](time.now_unix())** for the next step.
|
||||
After these steps, return *time.format(unix=`u`, pattern="%Y-%m-%d")*.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
This entry first verifies what the agent can read about its own call site. It assembles a step context and checks for the call-site section, source section and the actual time-tool name before considering an optional live step. The tool table points to the real local function; it is not an independently maintained tool description detached from the source.
|
||||
|
||||
Normal demonstration stops at context evidence and does not require a paid model response. AGENT_LIVE and an available key together opt into the separate live branch. Context markers establish prompt content, not the correctness of a future model answer. Keep the tool result and returned status visible when exercising that branch; never replace a missing credential with a fixed successful response.
|
||||
|
||||
We first **p = [Compute p](plugin.native_path(name="agent"))** for the next step.
|
||||
1. `p`
|
||||
We now **[Call plugin.load](> plugin.load path=`p`)**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="no-agent-plugin")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
|
||||
We now **[Call llm.load env](> llm.load_env path="../../.env")**.
|
||||
|
||||
`工具表` =
|
||||
|
||||
| 工具 |
|
||||
|------|
|
||||
| 获取时间 |
|
||||
|
||||
We first **model = [Compute model](llm.llm())** for the next step.
|
||||
We first **助手 = [Compute 助手](agent.agent(model=`model`, tools=`工具表`, standing="You are a Marqdo agent. Prefer CALL:获取时间 when the task needs today's date."))** for the next step.
|
||||
|
||||
Assert constitution markers in the assembled prompt (call site before how-to-act):
|
||||
|
||||
We first **ctx = [Compute ctx](agent.build_step_context(agent=`助手`, task="What is today's date? Use the tool in this runbook."))** for the next step.
|
||||
|
||||
We first **parts = [Compute parts](split(value=`ctx`, sep="--- call site ---"))** for the next step.
|
||||
We first **n = [Compute n](len(value=`parts`))** for the next step.
|
||||
1. `n` > 1
|
||||
We now **[Display this step's result](> print text="call-site-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="call-site-missing")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
|
||||
We first **parts2 = [Compute parts2](split(value=`ctx`, sep="--- source (.mq.md) ---"))** for the next step.
|
||||
We first **n2 = [Compute n2](len(value=`parts2`))** for the next step.
|
||||
1. `n2` > 1
|
||||
We now **[Display this step's result](> print text="source-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="source-missing")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
|
||||
We first **parts3 = [Compute parts3](split(value=`ctx`, sep="获取时间"))** for the next step.
|
||||
We first **n3 = [Compute n3](len(value=`parts3`))** for the next step.
|
||||
1. `n3` > 1
|
||||
We now **[Display this step's result](> print text="tool-in-source-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="tool-in-source-missing")**.
|
||||
We now **[Call sys.exit](> sys.exit code=1)**.
|
||||
|
||||
We first **site = [Compute site](agent_call_site())** for the next step.
|
||||
We first **fn = [Compute fn](json.get(value=`site`, key="function"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`fn`)**.
|
||||
|
||||
Optional live step — set env AGENT_LIVE=1 and put keys in repo-root `.env`:
|
||||
|
||||
We first **live = [Compute live](sys.env_get(name="AGENT_LIVE"))** for the next step.
|
||||
We first **key = [Compute key](sys.env_get(name="OPENAI_API_KEY"))** for the next step.
|
||||
1. `live` == "1"
|
||||
1. `key`
|
||||
We first **out = [Compute out](> `助手`.step task="请调用获取时间工具,然后只回复日期字符串。" writeback=False)** for the next step.
|
||||
We first **status = [Compute status](json.get(value=`out`, key="status"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`status`)**.
|
||||
We first **tool = [Compute tool](json.get(value=`out`, key="tool"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`tool`)**.
|
||||
We first **result = [Compute result](json.get(value=`out`, key="result"))** for the next step.
|
||||
We now **[Display this step's result](> print text=`result`)**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="live-skipped-no-key")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="live-skipped")**.
|
||||
@@ -1,13 +0,0 @@
|
||||
# agent-sandbox-okf(O1)
|
||||
|
||||
演示 **opt-in 沙盒试跑 + 表风格**(少 json 胶水):`agent.trial` 写入先落 upper,`commit=False` 时宿主不变,成功后再 `commit=True`。
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo -p marqdo_plugin_agent
|
||||
export MARQDO_EXT="$PWD/ext"
|
||||
./target/release/marqdo run examples/agent-sandbox-okf/index.mq.md
|
||||
```
|
||||
|
||||
期望:`dry-ok` · `host-clean` · `wet-ok` · `proof-visible` · `profile-default`。
|
||||
|
||||
见 [ext-ai-optimize.md](../../doc/roadmap/ext-ai-optimize.md) · 金样 [agent-sandbox-optin.mq.md](../../tests/ext/agent-sandbox-optin.mq.md)。
|
||||
@@ -1,69 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: agent-sandbox-okf — trial then commit
|
||||
description: >
|
||||
O1 example: opt-in sandbox trial with GFM-table returns and link-index reads.
|
||||
import:
|
||||
agent: ext/ai/agent.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
The two trials intentionally differ only in commit. First inspect a successful dry trial and verify that note.txt has not appeared in the host directory. Then run the committed trial, read the host file and compare its actual content. This separates an observed proposal from an observed filesystem change; neither ok alone nor a proposed path establishes that a commit happened.
|
||||
|
||||
Use a disposable filesystem root: the example replaces its named _example_sbx directory and leaves the committed evidence there for inspection. It does not promise to roll back a committed external effect. Read the returned profile as part of the trial evidence, and keep failures visible rather than manufacturing a success marker when the expected file is absent.
|
||||
|
||||
Short demo: write via `agent.trial`, prove the host is clean until commit.
|
||||
|
||||
We first **had = [Compute had](fs.exists(path="_example_sbx"))** for the next step.
|
||||
1. `had`
|
||||
We now **[Call fs.remove](> fs.remove path="_example_sbx")**.
|
||||
2. *
|
||||
We first **_ = 0** for the next step.
|
||||
|
||||
We now **[Call fs.make dir](> fs.make_dir path="_example_sbx")**.
|
||||
|
||||
We first **dry = [Compute dry](agent.trial(root="_example_sbx", write_path="note.txt", text="sandbox-okf", commit=False))** for the next step.
|
||||
We first **dry_ok = [ok](access(`dry`, "ok"))** for the next step.
|
||||
We first **dry_committed = [committed](access(`dry`, "committed"))** for the next step.
|
||||
1. `dry_ok`
|
||||
1. not `dry_committed`
|
||||
We now **[Display this step's result](> print text="dry-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="dry-bad-commit")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="dry-fail")**.
|
||||
|
||||
We first **leaked = [Compute leaked](fs.exists(path="_example_sbx/note.txt"))** for the next step.
|
||||
1. `leaked`
|
||||
We now **[Display this step's result](> print text="host-leaked")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="host-clean")**.
|
||||
|
||||
We first **wet = [Compute wet](agent.trial(root="_example_sbx", write_path="note.txt", text="sandbox-okf", commit=True))** for the next step.
|
||||
We first **wet_ok = [ok](access(`wet`, "ok"))** for the next step.
|
||||
We first **wet_committed = [committed](access(`wet`, "committed"))** for the next step.
|
||||
1. `wet_ok`
|
||||
1. `wet_committed`
|
||||
We now **[Display this step's result](> print text="wet-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="wet-no-commit")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="wet-fail")**.
|
||||
|
||||
We first **body = [Compute body](fs.read_text(path="_example_sbx/note.txt"))** for the next step.
|
||||
1. `body` == "sandbox-okf"
|
||||
We now **[Display this step's result](> print text="proof-visible")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="proof-missing")**.
|
||||
|
||||
We first **pname = [name](access([profile](access(`wet`, "profile")), "name"))** for the next step.
|
||||
1. `pname` == "default"
|
||||
We now **[Display this step's result](> print text="profile-default")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="profile-other")**.
|
||||
@@ -1,33 +0,0 @@
|
||||
# browser-app:可读源码中的浏览器工程
|
||||
|
||||
从 [index.mq.md](index.mq.md) 开始阅读和执行,再沿 [组件入口](components/index.mq.md) 查看布局。首页拆成列表与计时,网络页再拆成输出、批量请求和 WebSocket 控件;内容在 content 中保留普通 Markdown,控件叶子使用原生 View 节点。
|
||||
|
||||
浏览器程序是 [static/app.mq.md](static/app.mq.md)。事件表、参数与返回契约就在回调旁边;操作用可读标签表达,列表文本始终保留为数据。样式入口为 [styles/index.mq.md](styles/index.mq.md),旁边的字面表保留旧页面全部 59 条声明,并给出 View 包装层的几何适配。
|
||||
|
||||
| 能力 | 实际行为与边界 |
|
||||
|---|---|
|
||||
| 列表 | 原生记录保留独立 ID;重复内容可单独删除,特殊字符使用 text,删除按钮使用 children |
|
||||
| 草稿 | localStorage 保存输入框文本;完成回调确认保存,缺失值与空草稿分别处理;条目不跨刷新保存 |
|
||||
| 历史 | 三个面板使用真实 pathname;popstate 只反映现有位置,不重复 push;直接打开 /about 或 /net 返回首页 |
|
||||
| 计时 | 同名计时器替换,停止保留已累计次数 |
|
||||
| 批量请求 | 两个公开 UUID 请求可能失败;输出每项真实状态、响应体或错误 |
|
||||
| WebSocket | 本地 /live 原生回声资源;展示实际打开、消息、错误与关闭回调 |
|
||||
| 剪贴板与下载 | 导出当前列表文本;即时提示仅确认已发起,浏览器策略仍可能阻止完成 |
|
||||
|
||||
在仓库根目录构建当前官方运行时,再启动原生服务器。需要已经可用的 Rust/WASM 工具链和本仓库工程、网络插件;缺少 WASM 标准库时先阅读 [工作区工具链手册](../../skills/marqdo-dev/toolchain.mq.md),并将返回的 compiler 传给 build_browser。生成资源与编译样式不作为业务源码提交。
|
||||
|
||||
```sh
|
||||
marqdo call skills/marqdo-dev/index.mq.md build_browser 'out="examples/browser-app/static"' --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
|
||||
marqdo call examples/browser-app/index.mq.md serve --effects plugin,fs.write,network.write --fs-root examples/browser-app --require-ok --json
|
||||
```
|
||||
|
||||
打开 http://127.0.0.1:18095。控件等待实际启动成功后启用;缺失资源返回明确失败,不能把加载说明当作已运行。服务只监听本机,示例不引入数据库、认证或持久条目存储。
|
||||
|
||||
开发验证同样通过可执行手册完成。下列浏览器任务原生复制当前运行时,并运行真实页面交互;它覆盖重复项、字面文本、草稿、历史、计时、导出内容、受控批量请求失败与本地 WebSocket 收发。Node/Playwright 是自动化测试的外联边界,文件读写与任务编排仍由 Marqdo 执行。
|
||||
|
||||
```sh
|
||||
marqdo call skills/marqdo-dev/index.mq.md check 'path="examples/browser-app/index.mq.md"' --effects plugin --require-ok --json
|
||||
marqdo call skills/marqdo-dev/index.mq.md test_browser --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
|
||||
```
|
||||
|
||||
后续修改先阅读 [编程规范](../../doc/library-development.mq.md),再修改一个职责的组件或回调。需要新的浏览器宿主能力时扩充正式 bridge 与标准库契约,保留真实浏览器验收;不在父组件中重新拼接 HTML 或业务 JavaScript。
|
||||
@@ -1,25 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: About panel Markdown leaf
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
About is a terminal Markdown leaf, so further layout splitting would add no useful responsibility. Read its content through the native filesystem under the granted site root. The wrapper supplies only its client visibility id and initial hidden state. The page describes official host capabilities without embedding implementation JavaScript or an HTML shell.
|
||||
|
||||
We **source = [Read the literal About content](fs.read_text(path="content/about.md"))** and **children = [Keep it as ordinary Markdown](component.markdown(text=`source`, slot="about-content"))**.
|
||||
|
||||
`attrs` =
|
||||
|
||||
| id | hidden |
|
||||
|---|---|
|
||||
| panel-about | True |
|
||||
|
||||
Return *[Describe the initially hidden About panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="about"))*.
|
||||
@@ -1,70 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Native browser control leaves
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## button
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Event target shared with the client wire table |
|
||||
| label | text | required | Literal visible action |
|
||||
| secondary | bool | False | Use the retained secondary palette |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | One disabled native button awaiting successful runtime boot |
|
||||
|
||||
Use `id`, `label` and `secondary`=False for one leaf. The button starts disabled, carries type button and is enabled only after the official runtime boots successfully. Its label remains plain text. The caller chooses placement; this helper neither binds a click handler nor hides a sibling layout. Keep its id aligned with static/app.mq.md.
|
||||
|
||||
`attrs` =
|
||||
|
||||
| id | type | disabled |
|
||||
|---|---|---|
|
||||
| `id` | button | True |
|
||||
|
||||
We **style = ""**.
|
||||
1. `secondary`
|
||||
We **style = "secondary"**.
|
||||
Return *[Describe one literal native action](component.element(kind="button", value=`label`, attrs=`attrs`, style=`style`, slot=`id`))*.
|
||||
|
||||
## input
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Client value target |
|
||||
| hint | text | required | Plain placeholder text |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | One disabled text input |
|
||||
|
||||
Use `id` and `hint` for the draft or socket message. A native text input preserves its ordinary editing semantics and starts disabled until WASM is ready. The hint is placeholder text rather than a markup template. The component owns one control; the client selects its value through the wire table when the adjacent action is clicked.
|
||||
|
||||
`attrs` =
|
||||
|
||||
| id | type | placeholder | disabled |
|
||||
|---|---|---|---|
|
||||
| `id` | text | `hint` | True |
|
||||
|
||||
Return *[Describe this native value input](component.element(kind="input", attrs=`attrs`, slot=`id`))*.
|
||||
|
||||
## text
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| id | text | required | Stable output target |
|
||||
| value | text | required | Literal initial text |
|
||||
| kind | text | "text" | Native text or pre output |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | One escaped text leaf |
|
||||
|
||||
Use `id`, `value` and `kind`="text" for an output target. Select pre for the runtime log and ordinary text for the path, tick count or network outcome. Initial and later content stays literal: the renderer escapes this value and callbacks use set_text. This leaf declares no timer or network operation; those belong to the browser program.
|
||||
|
||||
We **attrs = [Retain the exact output target](table.put(in=None, at="id", value=`id`))**.
|
||||
Return *[Describe the literal output leaf](component.element(kind=`kind`, value=`value`, attrs=`attrs`, slot=`id`))*.
|
||||
@@ -1,33 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Draft and list editor
|
||||
import:
|
||||
controls: ../controls.mq.md
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
The editor contains one draft input, three draft actions, the export actions and an initially empty native list. The client owns records, stable identities and delegated deletion; no authored list HTML is stored here. Save persists only the draft under this origin. Copy and Download export current item text while list state remains in browser session memory.
|
||||
|
||||
We **heading = [Read the plain editor heading](component.markdown(text="## 待办"))** and **input = [Describe the exact draft target](controls.input(id="draft", hint="新项…"))** and **children = [Place input after its heading](table.concat(a=`heading`, b=`input`))**.
|
||||
|
||||
`actions` =
|
||||
|
||||
| @ | id | label | secondary |
|
||||
|---|---|---|---|
|
||||
| 1 | add | 添加 | False |
|
||||
| 2 | save | 存草稿 | True |
|
||||
| 3 | load | 读草稿 | True |
|
||||
| 4 | copy-log | 复制列表 | True |
|
||||
| 5 | dl-list | 下载列表 | True |
|
||||
|
||||
- [Describe each native action leaf](for actions as action)
|
||||
We **button = [Keep this action separate from state](controls.button(id=access(action, "id"), label=access(action, "label"), secondary=access(action, "secondary")))** and **children = [Preserve the authored action order](table.concat(a=`children`, b=`button`))**.
|
||||
We **empty = [Start the empty native list](table.empty_list())** and **attrs = [Retain the delegated list target](table.put(in=None, at="id", value="items"))** and **list = [Describe the list container](component.wrap(children=`empty`, kind="list", attrs=`attrs`, slot="items"))**.
|
||||
Return *[Keep the list after its editing controls](table.concat(a=`children`, b=`list`))*.
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Home panel assembly
|
||||
import:
|
||||
editor: editor.mq.md
|
||||
timer: timer.mq.md
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
Home has two independent children: the list editor and the named timer. This parent expresses only that ordering and the panel identity used by the client. Start with Home visible; About and Network are hidden in their own definitions. State and transport do not belong in layout tables, and changing one child does not require copying the entire page.
|
||||
|
||||
We **list = [Assemble the editor responsibility](editor.nodes())** and **clock = [Assemble the timer responsibility](timer.nodes())** and **children = [Keep the two home regions ordered](table.concat(a=`list`, b=`clock`))** and **attrs = [Name the client visibility target](table.put(in=None, at="id", value="panel-home"))**.
|
||||
Return *[Describe the initially visible Home panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="home"))*.
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Named timer controls
|
||||
import:
|
||||
controls: ../controls.mq.md
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
This region describes the tick output and its two actions. The client increments retained state only when the named timer actually calls back. Start replaces a timer with the same id; Stop preserves the count. This layout performs no sleeping or counting on the server, and its native text output can be tested independently of timer scheduling.
|
||||
|
||||
We **label = [Describe the timer label](component.markdown(text="计时(秒):"))** and **counter = [Describe the initial count](controls.text(id="tick", value="0"))** and **start = [Describe the explicit start action](controls.button(id="start-tick", label="开始"))** and **stop = [Describe the explicit stop action](controls.button(id="stop-tick", label="停止", secondary=True))** and **content = [Keep label before count](table.concat(a=`label`, b=`counter`))** and **actions = [Keep the two actions together](table.concat(a=`start`, b=`stop`))** and **children = [Place actions beside their output](table.concat(a=`content`, b=`actions`))**.
|
||||
Return *[Wrap this one timer responsibility](component.wrap(children=`children`, kind="row", slot="timer"))*.
|
||||
@@ -1,50 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Browser example recursive page assembly
|
||||
import:
|
||||
navigation: navigation.mq.md
|
||||
home: home/index.mq.md
|
||||
about: about.mq.md
|
||||
network: network/index.mq.md
|
||||
controls: controls.mq.md
|
||||
component: ext/web/component/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
Read this root to see the whole page: introduction, path, navigation, three panels, feedback and runtime. Follow one import at a time until a child is a plain Markdown leaf or native control. Business values never become a page HTML string. The official runtime starts only after the server has staged the current built assets and the actual client source. Controls stay disabled until boot succeeds; missing resources therefore remain visible as a loading failure. The readiness target and enable selectors are typed resource metadata, not executable snippets. Styles reference the generated stylesheet produced by serve. Server discovery reads the terminal content leaves under the granted root; the browser receives the same ordered region tree.
|
||||
|
||||
We **source = [Read the plain introduction](fs.read_text(path="content/intro.md"))** and **intro = [Retain its Markdown](component.markdown(text=`source`, slot="intro"))** and **path = [Describe the initial pathname](controls.text(id="path", value="path: /"))** and **nav = [Assemble the authored destinations](navigation.nodes())** and **home = [Assemble list and timer](home.nodes())** and **about = [Read the About leaf](about.nodes())** and **network = [Assemble independent network controls](network.nodes())** and **log = [Describe literal runtime feedback](controls.text(id="log", value="loading…", kind="pre"))** and **style = [Reference the compiled declarative theme](component.asset(url="/static/theme.css", kind="stylesheet"))**.
|
||||
|
||||
`runtime_attrs` =
|
||||
|
||||
| type | data-mq-wasm | data-mq-source-url | data-mq-ready | data-mq-enable |
|
||||
|---|---|---|---|---|
|
||||
| module | "/static/marqdo_wasm.wasm" | "/static/app.mq.md" | "#log" | "#draft,#add,#save,#load,#start-tick,#stop-tick,#fetch-all,#ws-open,#ws-msg,#ws-send,#ws-close,#copy-log,#dl-list" |
|
||||
|
||||
We **runtime = [Declare the official module and readiness targets](component.asset(url="/static/marqdo-bridge.js", attrs=`runtime_attrs`, slot="runtime"))**.
|
||||
|
||||
`groups` =
|
||||
|
||||
| rows |
|
||||
|---|
|
||||
| `intro` |
|
||||
| `path` |
|
||||
| `nav` |
|
||||
| `home` |
|
||||
| `about` |
|
||||
| `network` |
|
||||
| `log` |
|
||||
| `style` |
|
||||
| `runtime` |
|
||||
|
||||
We **children = [Start the complete ordered page](table.empty_list())**.
|
||||
- [Retain each independently inspectable region](for groups as group)
|
||||
We **children = [Keep typed children in reading order](table.concat(a=`children`, b=`group`))**.
|
||||
Return *[Wrap the recursive page once](component.wrap(children=`children`, slot="browser-app", style="browser-app"))*.
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Three browser panel destinations
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
Navigation contains three ordinary links with stable ids. Their fragment destinations leave a readable fallback without issuing a server page request. The official wire table intercepts each click and requests one deliberate history entry. Back and Forward only repaint the already selected panel. This component does not own client state or generate navigation JavaScript.
|
||||
|
||||
`destinations` =
|
||||
|
||||
| @ | id | href | label |
|
||||
|---|---|---|---|
|
||||
| 1 | nav-home | "#/" | 首页 |
|
||||
| 2 | nav-about | "#/about" | 关于 |
|
||||
| 3 | nav-net | "#/net" | 网络 |
|
||||
|
||||
We **links = [Start the ordered native navigation](table.empty_list())**.
|
||||
- [Declare each independently named destination](for destinations as destination)
|
||||
We **label = [Read its literal label](access(destination, "label"))** and **id = [Read its stable event target](access(destination, "id"))** and **href = [Read its fallback destination](access(destination, "href"))**.
|
||||
|
||||
`attrs` =
|
||||
|
||||
| id | href |
|
||||
|---|---|
|
||||
| `id` | `href` |
|
||||
|
||||
We **link = [Describe this native destination](component.element(kind="link", value=`label`, attrs=`attrs`))** and **links = [Preserve navigation order](table.concat(a=`links`, b=`link`))**.
|
||||
Return *[Place those links in a navigation region](component.wrap(children=`links`, kind="nav", slot="navigation"))*.
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Network panel assembly
|
||||
import:
|
||||
socket: socket.mq.md
|
||||
controls: ../controls.mq.md
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
Network places plain explanatory content, the actual response output, a batch-fetch action and a local echo group. Batch requests retain the original public demonstration endpoint and may fail; ordered callback records show each status and body. Socket transport is local and independent. The panel starts hidden and the browser client alone selects it.
|
||||
|
||||
We **heading = [Describe the network responsibility](component.markdown(text="## 网络\n\n批量请求显示每项的实际状态;WebSocket 使用本机 /live 回声服务。"))** and **output = [Describe literal transport feedback](controls.text(id="net-out", value="idle"))** and **fetch = [Describe the batch request action](controls.button(id="fetch-all", label="fetch_all ×2 uuid"))** and **echo = [Assemble local socket controls](socket.nodes())** and **first = [Place feedback below its explanation](table.concat(a=`heading`, b=`output`))** and **last = [Keep fetch before socket interaction](table.concat(a=`fetch`, b=`echo`))** and **children = [Preserve the two network responsibilities](table.concat(a=`first`, b=`last`))**.
|
||||
|
||||
`attrs` =
|
||||
|
||||
| id | hidden |
|
||||
|---|---|
|
||||
| panel-net | True |
|
||||
|
||||
Return *[Describe the initially hidden Network panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="network"))*.
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Local echo socket controls
|
||||
import:
|
||||
controls: ../controls.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Structured View rows for this component |
|
||||
|
||||
The echo group contains Open, the message input, Send and Close as separate native leaves. The server binds /live, and the official bridge sends the browser program’s transport instructions. Actual lifecycle callbacks update the network output. This component performs no handshake itself and does not rely on availability of a public echo service.
|
||||
|
||||
We **open = [Describe the connection action](controls.button(id="ws-open", label="WS 打开"))** and **message = [Describe exact message input](controls.input(id="ws-msg", hint="ws 消息"))** and **send = [Describe the explicit send action](controls.button(id="ws-send", label="WS 发送"))** and **close = [Describe the explicit close action](controls.button(id="ws-close", label="WS 关闭", secondary=True))** and **first = [Keep open before message entry](table.concat(a=`open`, b=`message`))** and **last = [Keep send before close](table.concat(a=`send`, b=`close`))**.
|
||||
Return *[Keep the local echo interaction ordered](table.concat(a=`first`, b=`last`))*.
|
||||
@@ -1,5 +0,0 @@
|
||||
## 关于
|
||||
|
||||
从 `index.mq.md` 阅读工程入口,沿 `components/index.mq.md` 逐层查看布局,再阅读 `static/app.mq.md` 的事件与回调。
|
||||
|
||||
普通内容使用 Markdown,控件使用原生节点,列表保留带独立 ID 的记录。浏览器执行官方 bridge 提供的 DOM、历史、存储与网络能力,无需作者撰写业务 JavaScript。
|
||||
@@ -1,3 +0,0 @@
|
||||
# Marqdo browser-app
|
||||
|
||||
列表、草稿存储、历史导航、计时、批量请求、WebSocket、剪贴板和下载。页面和业务流程均由 Marqdo 源码表达,浏览器宿主能力由官方 bridge 提供。
|
||||
@@ -1,55 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: web
|
||||
view: main
|
||||
route: /
|
||||
title: Marqdo browser-app
|
||||
import:
|
||||
page: components/index.mq.md
|
||||
styles: styles/index.mq.md
|
||||
web: ext/web/web.mq.md
|
||||
http: ext/net/http.mq.md
|
||||
socket: ext/net/websocket.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
result: lib/result.mq.md
|
||||
---
|
||||
|
||||
This is the callable engineering entry. Follow components/index.mq.md for recursive layout, static/app.mq.md for browser state and effects, and styles/index.mq.md for the retained theme. Plain content is Markdown; controls and resources remain native structured values. There is no authored HTML host or business JavaScript. Serve runs from the checkout root with --fs-root examples/browser-app.
|
||||
|
||||
## main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Inspectable native page rows |
|
||||
|
||||
The Document delegates page assembly to its component root. Home, About and Network are client panels within this one page, with their own independently readable components. The client controls visibility and history while ordinary content remains Markdown. This function does not start a server, fetch public endpoints or open a socket. Read the returned tree as layout data, and call serve for a real running application.
|
||||
|
||||
Return *[Assemble the recursive browser demonstration](page.nodes())*.
|
||||
|
||||
## serve
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| root | text | "examples/browser-app" | Explicit site directory relative to the checkout |
|
||||
| port | number | 18095 | Loopback listen port |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Blocking listener or missing-asset failure |
|
||||
|
||||
Use `root`="examples/browser-app" and `port`=18095 with plugin,fs.write,network.write and the site filesystem root. Build current browser assets through the development handbook first. Both generated assets must exist before theme compilation or listening; missing files produce an actionable Result. The native filesystem writes only the explicit compiled stylesheet. No Python static server or generated shell workflow is needed.
|
||||
|
||||
Discovery prepares the Document and the static mount. Direct /about and /net visits redirect to the entry page, matching the transient panel-state model; Back and Forward inside a live page retain their actual history positions. A separate local network resource binds /live for anonymous demonstration echo. This loopback example does not authenticate or persist item records. Keep every returned app value and listen only after binding all resources.
|
||||
|
||||
`assets` =
|
||||
|
||||
| file |
|
||||
|---|
|
||||
| static/marqdo_wasm.wasm |
|
||||
| static/marqdo-bridge.js |
|
||||
|
||||
- [Require current official browser resources](for assets as file)
|
||||
1. not [The required runtime asset exists](fs.exists(path=`file`))
|
||||
Return *[Expose the actual build prerequisite](result.error(code="browser_app.assets", message="call build_browser and stage its assets in examples/browser-app/static before serve", operation="serve"))*.
|
||||
We **css = [Compile the retained declarative theme](styles.css())** and **[Write only the generated stylesheet](fs.atomic_write(path="static/theme.css", text=`css`))** and **app = [Discover the native Document and static assets](web.prepare(root=`root`, host="127.0.0.1", port=`port`, static_dir="static"))** and **app = [Retain a direct About entry](http.redirect(app=`app`, from="/about", to="/", permanent=False))** and **app = [Retain a direct Network entry](http.redirect(app=`app`, from="/net", to="/", permanent=False))** and **app = [Bind the actual local echo resource](socket.route(app=`app`, path="/live", mode="echo", require_auth=False))**.
|
||||
Return *[Listen after the real resources are ready](web.listen(app=`app`))*.
|
||||
@@ -1,568 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Browser effects — native records and explicit completion
|
||||
description: list CRUD, storage, navigate, interval, fetch_all, ws — GFM + lib/browser
|
||||
import:
|
||||
browser: lib/browser.mq.md
|
||||
table: lib/table.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Initial browser view/state record |
|
||||
|
||||
This entry prepares browser instructions; it does not itself fetch a URL or manipulate a server filesystem. The host page must supply the selectors listed below. List state uses native records with stable ids, keeping duplicate text and literal newlines independent. The wire table maps each UI event to one actual callback, including delegated item buttons, history navigation, timer controls, parallel fetches and a named WebSocket connection.
|
||||
|
||||
Event declarations contain no user values interpolated into code. Input values flow through callback parameters while the server page remains a separate document.
|
||||
|
||||
The returned boot record combines event registration and a storage lookup, without pushing an initial history entry. The browser bridge applies those instructions and dispatches later events into the callbacks. Draft text, tick count, route and socket identifier belong to that browser instance. Storage callbacks complete asynchronously; the initial return is not proof that a saved draft was found.
|
||||
|
||||
We **ticks = 0** as the retained count before the first real timer event.
|
||||
We **items = [Start native list state](table.empty_list())** and **next_id = 1** for independent record identities.
|
||||
We **route_path = "/"** as this browser instance’s panel state.
|
||||
We **ws_id = "echo"** as the one named local connection.
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 | 委托 | 值选择器 |
|
||||
|---|--------|------|------|------|----------|
|
||||
| 1 | "#add" | click | add | | "#draft" |
|
||||
| 2 | "#save" | click | save_draft | | "#draft" |
|
||||
| 3 | "#load" | click | load_draft | | |
|
||||
| 4 | "#start-tick" | click | start_tick | | |
|
||||
| 5 | "#stop-tick" | click | stop_tick | | |
|
||||
| 6 | "#nav-home" | click | go_home | | |
|
||||
| 7 | "#nav-about" | click | go_about | | |
|
||||
| 8 | "#nav-net" | click | go_net | | |
|
||||
| 9 | "window" | popstate | on_pop | | |
|
||||
| 10 | "#items" | click | on_item | "button[data-id]" | |
|
||||
| 11 | "#fetch-all" | click | do_fetch_all | | |
|
||||
| 12 | "#ws-open" | click | ws_open | | |
|
||||
| 13 | "#ws-send" | click | ws_send | | "#ws-msg" |
|
||||
| 14 | "#ws-close" | click | ws_close | | |
|
||||
| 15 | "#copy-log" | click | copy_log | | |
|
||||
| 16 | "#dl-list" | click | dl_list | | |
|
||||
|
||||
`st` =
|
||||
|
||||
| op | key | then |
|
||||
|----|-----|------|
|
||||
| get | mq-draft | on_draft |
|
||||
|
||||
`boot` =
|
||||
|
||||
| wire | storage |
|
||||
|---|---|
|
||||
| `wire` | `st` |
|
||||
|
||||
After these steps, return *boot*.
|
||||
|
||||
## add
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| value | text | "" | Exact draft text supplied by the add control |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Native list refresh, input clear and focus; None for empty text |
|
||||
|
||||
Use `value`="" from the input. Retain each nonempty value exactly as one record, including quotes, angle brackets or a literal newline. A monotonically assigned id separates duplicate titles; deleting one must not erase its siblings. This direct callback updates entry state, then passes those records explicitly to the pure renderer. No business value is interpolated into HTML.
|
||||
|
||||
The input clears and regains focus after a real local addition. An empty string returns None without changing records or consuming an id. This list is session memory; only the separately saved draft uses browser storage.
|
||||
|
||||
1. `value` == ""
|
||||
Return *None* because there is no new item.
|
||||
We **id = [Assign an independent stable identity](str(next_id))** and **next_id = next_id + 1**.
|
||||
|
||||
`record` =
|
||||
|
||||
| id | text |
|
||||
|---|---|
|
||||
| `id` | `value` |
|
||||
|
||||
We **items = [Retain the actual text record](table.append(list=`items`, item=`record`))** and **view = [Render typed labels and delete controls](_list(records=`items`))** and **clear = [Clear the completed input](browser.set_value(sel="#draft", value=""))** and **focus = [Return to the draft control](browser.focus(sel="#draft"))**.
|
||||
We **view = [Keep the independent list and value effects](browser.merge(a=`view`, b=`clear`))**.
|
||||
Return *[Keep focus with the completed list update](browser.merge(a=`view`, b=`focus`))*.
|
||||
|
||||
## on_item
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| data_id | text | "" | Stable id supplied by the delegated delete button |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Remaining native records and removal feedback, or None for an unknown id |
|
||||
|
||||
Use `data_id`="" from button[data-id]. Compare identities rather than text, so duplicate values and values containing newlines stay independent. Preserve remaining order and do nothing for an empty or unknown id. The renderer receives retained records explicitly; it does not infer client state inside a normal helper call.
|
||||
|
||||
A deletion rebuilds the same list through typed controls and reports the removed id as text. It neither modifies a saved draft nor changes timer, transport or route state. Ids are not recycled after deletion, avoiding a stale event selecting a different later item.
|
||||
|
||||
1. `data_id` == ""
|
||||
Return *None* for an absent selection.
|
||||
We **remaining = [Start the retained row order](table.empty_list())**.
|
||||
- [Keep every record except the selected identity](for items as item)
|
||||
1. access(`item`, "id") != `data_id`
|
||||
We **remaining = [Keep this independent record](table.append(list=`remaining`, item=`item`))**.
|
||||
1. len(`remaining`) == len(`items`)
|
||||
Return *None* because no selected identity exists.
|
||||
We **items = remaining** and **view = [Render the actual retained rows](_list(records=`items`))** and **message = "removed " + data_id** and **status = [Describe the observed local removal](browser.set_text(sel="#log", text=`message`))**.
|
||||
Return *[Keep list and feedback together](browser.merge(a=`view`, b=`status`))*.
|
||||
|
||||
## save_draft
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| value | text | "" | Exact text selected from the draft input |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Storage write request; completion arrives at on_saved |
|
||||
|
||||
Use `value`="" from the draft control. The storage record names the local key and its completion callback. Return the request immediately; only on_saved can announce a successful write. An intentionally empty draft is valid and differs from an absent key. Storage belongs to this browser origin, while list records stay in session memory. Returning this record does not write server files or grant process access.
|
||||
|
||||
`request` =
|
||||
|
||||
| op | key | value | then |
|
||||
|---|---|---|---|
|
||||
| set | mq-draft | `value` | on_saved |
|
||||
|
||||
Return *[Ask the browser to persist the exact draft](browser.storage(spec=`request`))*.
|
||||
|
||||
## load_draft
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Storage read request with an explicit completion callback |
|
||||
|
||||
Request mq-draft from this browser origin. The callback distinguishes a missing key, an empty saved value and a failed read. No input is cleared while the read is pending, and this operation never replaces the native item list. The same read runs at boot, so a reload restores the saved draft without claiming to persist list records.
|
||||
|
||||
`request` =
|
||||
|
||||
| op | key | then |
|
||||
|---|---|---|
|
||||
| get | mq-draft | on_draft |
|
||||
|
||||
Return *[Request the stored draft and its actual outcome](browser.storage(spec=`request`))*.
|
||||
|
||||
## on_draft
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Actual storage-read completion |
|
||||
| value | text | "" | Stored draft text, including an intentionally empty value |
|
||||
| found | bool | False | Whether the key actually existed |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Restored value and feedback, or actual missing/failure feedback |
|
||||
|
||||
Use `ok`=True, `value`="" and `found`=False from storage. A missing key differs from a stored empty draft, and an unsuccessful read must not be described as absence. Restore the exact value only after a successful read with found=True. This changes the draft input, not the native item list, and never interprets the stored text as code.
|
||||
|
||||
1. not `ok`
|
||||
Return *[Keep a failed read visible](browser.set_text(sel="#log", text="draft read failed"))*.
|
||||
1. not `found`
|
||||
Return *[Keep an absent draft visible](browser.set_text(sel="#log", text="no draft"))*.
|
||||
We **value_effect = [Restore exact stored draft text](browser.set_value(sel="#draft", value=`value`))** and **status = [Confirm the observed read](browser.set_text(sel="#log", text="draft loaded"))**.
|
||||
Return *[Keep the actual value and feedback](browser.merge(a=`value_effect`, b=`status`))*.
|
||||
|
||||
## start_tick
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | One named repeating timer instruction |
|
||||
|
||||
Start tick at one-second intervals. The bridge replaces a timer with the same id, so repeated Start clicks do not accumulate independent clocks. Each callback increments the session counter once. This returns an instruction; it is neither a blocking sleep nor proof that one second has passed. Stop cancels future callbacks and preserves the accumulated display.
|
||||
|
||||
Return *[Start or replace the one named timer](browser.interval(ms=1000, then="on_tick", id="tick"))*.
|
||||
|
||||
## stop_tick
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Cancellation of the named timer |
|
||||
|
||||
Cancel tick through its explicit id. Calling Stop before Start is harmless, and stopping does not reset the visible count or alter other timers. A later Start resumes counting from retained state. The browser owns the timer handle; authors do not keep a JavaScript handle or generate a client program to clear it.
|
||||
|
||||
Return *[Cancel future callbacks for this timer](browser.clear_interval(id="tick"))*.
|
||||
|
||||
## on_tick
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Whether this timer callback is valid |
|
||||
| id | text | "" | Actual named timer id |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Updated count, or None for a failed/unrelated callback |
|
||||
|
||||
Use `ok`=True and `id`="" from the timer. Count only successful events belonging to tick; unrelated callbacks must not change this counter. Retained ticks belongs to the direct browser callback, rather than being supplied by the event. A manual call to this function constructs the same text effect but does not prove that a real timer fired.
|
||||
|
||||
1. not `ok` or `id` != "tick"
|
||||
Return *None* for an unrelated timer outcome.
|
||||
We **ticks = ticks + 1** and **label = [Format the actual accumulated count](str(ticks))**.
|
||||
Return *[Display that observed timer count](browser.set_text(sel="#tick", text=`label`))*.
|
||||
|
||||
## go_home
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Selected panel effects and one actual navigation request |
|
||||
|
||||
Select / from its authored navigation control. This direct callback updates the retained panel state and requests exactly one history entry. The helper receives the path explicitly rather than assuming an ordinary call captures entry bindings. Back/Forward uses on_pop, which renders without navigation. No server request or page HTML is constructed here.
|
||||
|
||||
We **route_path = "/"**.
|
||||
Return *[Render and request this one deliberate navigation](_view(route=`route_path`, push=True))*.
|
||||
|
||||
## go_about
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Selected panel effects and one actual navigation request |
|
||||
|
||||
Select /about from its authored navigation control. This direct callback updates the retained panel state and requests exactly one history entry. The helper receives the path explicitly rather than assuming an ordinary call captures entry bindings. Back/Forward uses on_pop, which renders without navigation. No server request or page HTML is constructed here.
|
||||
|
||||
We **route_path = "/about"**.
|
||||
Return *[Render and request this one deliberate navigation](_view(route=`route_path`, push=True))*.
|
||||
|
||||
## go_net
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Selected panel effects and one actual navigation request |
|
||||
|
||||
Select /net from its authored navigation control. This direct callback updates the retained panel state and requests exactly one history entry. The helper receives the path explicitly rather than assuming an ordinary call captures entry bindings. Back/Forward uses on_pop, which renders without navigation. No server request or page HTML is constructed here.
|
||||
|
||||
We **route_path = "/net"**.
|
||||
Return *[Render and request this one deliberate navigation](_view(route=`route_path`, push=True))*.
|
||||
|
||||
## on_pop
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| path | text | "" | Actual browser pathname, including optional query string |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | History-selected panel effects without pushing history again |
|
||||
|
||||
Use `path`="" from the real popstate callback. Keep its normalized panel route in the differently named entry state, avoiding accidental shadowing of a callback parameter. The browser has already selected this history entry, so returning navigate would add an incorrect new entry. Query text does not choose a different panel; only the known pathname is used.
|
||||
|
||||
We **parts = [Separate the pathname from query text](text.str_split(s=`path`, sep="?"))** and **route_path = [Keep the actual panel path](table.first(list=`parts`))**.
|
||||
Return *[Reflect the actual history position](_view(route=`route_path`))*.
|
||||
|
||||
## show_path
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Current panel visibility and label without history mutation |
|
||||
|
||||
This direct browser callback reads retained route_path and delegates pure rendering with explicit input. It never pushes another history entry, so a repaint cannot trap Back/Forward. Call the navigation callbacks to request a new route. Server routing and page structure remain separate responsibilities; unknown browser paths select the home panel.
|
||||
|
||||
Return *[Refresh the retained panel without navigating](_view(route=`route_path`))*.
|
||||
|
||||
## do_fetch_all
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
Queue two independent browser fetches and return an immediate loading message together with the request instruction. Results arrive through on_fetch_all; this initial return does not contain either HTTP response. The request table keeps both URLs visible and avoids generating JavaScript to construct the batch.
|
||||
|
||||
The example endpoint is external and may fail or be unavailable. Consumers must inspect the actual callback records rather than count request declarations as successful responses. Browser network policy still applies; no backend file or shell operation is authorized by this instruction.
|
||||
|
||||
`reqs` =
|
||||
|
||||
| @ | url |
|
||||
|---|-----|
|
||||
| 1 | "https://httpbin.org/uuid" |
|
||||
| 2 | "https://httpbin.org/uuid" |
|
||||
|
||||
We **msg = [Describe the pending batch](browser.set_text(sel="#net-out", text="fetch_all…"))** and **requests = [Request both actual HTTP outcomes](browser.fetch_all(requests=`reqs`, then="on_fetch_all"))**.
|
||||
Return *[Keep pending feedback with its asynchronous requests](browser.merge(a=`msg`, b=`requests`))*.
|
||||
|
||||
## on_fetch_all
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Whether the batch callback itself completed |
|
||||
| results | any | None | Ordered per-request ok/status/body/error records |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Actual per-request outcomes shown as plain text |
|
||||
|
||||
Use `ok`=True and `results`=None from the bridge. A completed batch can still contain failed HTTP or network operations; the outer callback flag does not make each record successful. Show the real ordered records, including status, body and errors, rather than a fixed completion message. Text output cannot become HTML or a browser command.
|
||||
|
||||
A missing result list stays visibly unavailable. Public endpoints remain demonstration dependencies; local tests supply controlled responses and a failure. This callback does not retry a request or replace its body with a predetermined answer.
|
||||
|
||||
1. not `ok`
|
||||
Return *[Keep batch failure visible](browser.set_text(sel="#net-out", text="fetch_all failed"))*.
|
||||
1. `results` == None
|
||||
Return *[Keep absent results distinct](browser.set_text(sel="#net-out", text="fetch_all returned no results"))*.
|
||||
We **message = [Retain actual request outcomes](str(results))**.
|
||||
Return *[Display observed successes and failures literally](browser.set_text(sel="#net-out", text=`message`))*.
|
||||
|
||||
## ws_open
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Named local WebSocket request and lifecycle callbacks |
|
||||
|
||||
Open the site’s /live echo resource under the explicit echo id. A relative URL uses the current origin and its transport security, allowing the example to run without a public echo provider. The server separately binds this native network resource. Returning the record only requests a connection; open, message, error and close callbacks describe actual transport outcomes. Subsequent send and close instructions reuse the same id.
|
||||
|
||||
`request` =
|
||||
|
||||
| op | id | url | then_open | then_message | then_error | then_close |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
| open | `ws_id` | "/live" | on_ws_open | on_ws_msg | on_ws_err | on_ws_close |
|
||||
|
||||
Return *[Request the local echo connection](browser.ws(spec=`request`))*.
|
||||
|
||||
## on_ws_open
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Actual connection completion |
|
||||
| id | text | "" | Connected socket id |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Confirmed connection text, or None for a failed/unrelated callback |
|
||||
|
||||
Use `ok`=True and `id`="" from the real transport. Accept only the named echo socket; a different resource cannot announce this widget ready. This callback confirms the handshake, while sending still requires a separate user action. It neither invents a received message nor marks a requested connection successful before the bridge reports it.
|
||||
|
||||
1. not `ok` or `id` != `ws_id`
|
||||
Return *None* for an unrelated connection.
|
||||
Return *[Confirm the observed handshake](browser.set_text(sel="#net-out", text="ws open"))*.
|
||||
|
||||
## on_ws_msg
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Actual message completion |
|
||||
| data | text | "" | Exact received text |
|
||||
| id | text | "" | Receiving socket id |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Literal received message, or None for a failed/unrelated callback |
|
||||
|
||||
Use `ok`=True, `data`="" and `id`="" from the echo connection. Preserve the complete received text, including quotes and angle brackets. Display it through set_text so a message is data rather than page markup. Receipt is independent of the send click: the remote resource may respond later or close without replying.
|
||||
|
||||
1. not `ok` or `id` != `ws_id`
|
||||
Return *None* for an unrelated message.
|
||||
We **message = "ws ← " + data**.
|
||||
Return *[Display the actual echo as plain text](browser.set_text(sel="#net-out", text=`message`))*.
|
||||
|
||||
## on_ws_err
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | False | Failure flag supplied by the bridge |
|
||||
| error | text | "" | Actual transport failure text |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Visible transport failure |
|
||||
|
||||
Use `ok`=False and `error`="" from the transport callback. Keep the actual error text in the output rather than substituting a success message. The callback performs no automatic reconnect and sends no pending message. Reopening is an explicit user operation; failures remain inspectable while the rest of the page can continue operating.
|
||||
|
||||
We **message = "ws error: " + error**.
|
||||
Return *[Expose the actual connection failure](browser.set_text(sel="#net-out", text=`message`))*.
|
||||
|
||||
## on_ws_close
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Actual close callback flag |
|
||||
| id | text | "" | Closed socket id |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Observed close text, or None for an unrelated socket |
|
||||
|
||||
Use `ok`=True and `id`="" after the bridge observes closure. The named socket may close because of the user’s request or the server. This is a lifecycle observation and does not itself initiate another close or reopen. Leave list state, draft and timer untouched so transport changes remain independent of local page work.
|
||||
|
||||
1. `id` != `ws_id`
|
||||
Return *None* for an unrelated socket.
|
||||
Return *[Report the observed connection closure](browser.set_text(sel="#net-out", text="ws closed"))*.
|
||||
|
||||
## ws_send
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| value | text | "" | Exact text selected from the message input |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Send request for the existing named socket |
|
||||
|
||||
Use `value`="" as the message payload. Sending preserves literal text and addresses the existing echo socket; it does not create a second hidden connection. Open first and wait for the real connection callback. The request is not an echo result: only on_ws_msg displays a received response, and transport failures remain visible through the bridge.
|
||||
|
||||
`request` =
|
||||
|
||||
| op | id | data |
|
||||
|---|---|---|
|
||||
| send | `ws_id` | `value` |
|
||||
|
||||
Return *[Send exact text through the named connection](browser.ws(spec=`request`))*.
|
||||
|
||||
## ws_close
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Close request for the named socket |
|
||||
|
||||
Ask the bridge to close echo, reusing the same identity as open and send. The close callback supplies the observed lifecycle result. Returning this instruction does not delete page records or cancel the independent timer. Closing an absent connection is harmless; opening a later connection remains an explicit user action.
|
||||
|
||||
`request` =
|
||||
|
||||
| op | id |
|
||||
|---|---|
|
||||
| close | `ws_id` |
|
||||
|
||||
Return *[Request closure of this connection](browser.ws(spec=`request`))*.
|
||||
|
||||
## copy_log
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Clipboard request and truthful queued feedback |
|
||||
|
||||
Export the retained item texts in their current order, including duplicate values and literal newlines. The native records remain unchanged. This browser capability is a request: policy, user activation or the destination environment may prevent completion. The bridge exposes errors, and the immediate feedback says queued because no completion callback confirms a final clipboard write or saved file.
|
||||
|
||||
We **plain = [Read the current literal list export](_plain(records=`items`))** and **request = [Request clipboard delivery](browser.clipboard(text=`plain`))** and **status = [Describe only the requested operation](browser.set_text(sel="#log", text="clipboard request queued"))**.
|
||||
Return *[Keep the request and its truthful feedback](browser.merge(a=`request`, b=`status`))*.
|
||||
|
||||
## dl_list
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Download request and truthful queued feedback |
|
||||
|
||||
Export the retained item texts in their current order, including duplicate values and literal newlines. The native records remain unchanged. This browser capability is a request: policy, user activation or the destination environment may prevent completion. The bridge exposes errors, and the immediate feedback says queued because no completion callback confirms a final clipboard write or saved file.
|
||||
|
||||
We **plain = [Read the current literal list export](_plain(records=`items`))** and **request = [Request the plain-text download](browser.download(body=`plain`, filename="items.txt"))** and **status = [Describe only the requested operation](browser.set_text(sel="#log", text="download request queued"))**.
|
||||
Return *[Keep the request and its truthful feedback](browser.merge(a=`request`, b=`status`))*.
|
||||
|
||||
## _list
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| records | list | required | Native id/text records in visible order |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Structured list effect with literal labels and native delete buttons |
|
||||
|
||||
Use `records` from the direct callback's retained state. Each row contains a span label and button as typed children. The button's data-id carries the independent record identity; visible business text stays in text, never html. The official bridge escapes it and preserves delegation without rebuilding the parent page.
|
||||
|
||||
This helper is pure and receives records explicitly. It does not read hidden entry state, delete anything or assume that a returned effect has already reached the DOM. The existing host list and event wiring own those later steps.
|
||||
|
||||
We **rows = [Start the native visible row records](table.empty_list())**.
|
||||
- [Describe one label and native delete action](for records as record)
|
||||
We **id = [Retain the exact row identity](access(record, "id"))** and **value = [Retain literal business text](access(record, "text"))**.
|
||||
|
||||
`label` =
|
||||
|
||||
| tag | text |
|
||||
|---|---|
|
||||
| span | `value` |
|
||||
|
||||
`attributes` =
|
||||
|
||||
| type | data-id |
|
||||
|---|---|
|
||||
| button | `id` |
|
||||
|
||||
`button` =
|
||||
|
||||
| tag | text | attrs |
|
||||
|---|---|---|
|
||||
| button | 删 | `attributes` |
|
||||
|
||||
`children` =
|
||||
|
||||
| node |
|
||||
|---|
|
||||
| `label` |
|
||||
| `button` |
|
||||
|
||||
`row` =
|
||||
|
||||
| tag | children |
|
||||
|---|---|
|
||||
| li | `children` |
|
||||
|
||||
We **rows = [Retain this typed row](table.append(list=`rows`, item=`row`))**.
|
||||
Return *[Update only the existing list](browser.render_list(sel="#items", items=`rows`))*.
|
||||
|
||||
|
||||
## _view
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| route | text | required | Selected panel pathname |
|
||||
| push | bool | False | Explicit navigation callback requests one history entry |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Actual boolean panel visibility, path label and optional deliberate navigation |
|
||||
|
||||
Use `route` and `push`=False. Only /about and /net select secondary panels; other paths render Home. Hidden attributes are actual booleans, while False removes the attribute. The pure helper receives its path explicitly and does not pretend to capture the browser entry state.
|
||||
|
||||
History observations use the default without navigation; authored link callbacks opt in once. Keep all three targets inside a single set_attr record because effect merging is shallow and otherwise one target map could overwrite another. This function performs no fetch, storage write or socket operation.
|
||||
|
||||
We **selected = "/"**.
|
||||
1. `route` == "/about" or `route` == "/net"
|
||||
We **selected = route**.
|
||||
We **home = [Describe Home visibility](table.put(in=None, at="hidden", value=(`selected` != "/")))** and **about = [Describe About visibility](table.put(in=None, at="hidden", value=(`selected` != "/about")))** and **network = [Describe Network visibility](table.put(in=None, at="hidden", value=(`selected` != "/net")))**.
|
||||
|
||||
`targets` =
|
||||
|
||||
| #panel-home | #panel-about | #panel-net |
|
||||
|---|---|---|
|
||||
| `home` | `about` | `network` |
|
||||
|
||||
We **visibility = [Keep every panel target together](browser.wrap(key="set_attr", value=`targets`))** and **message = "path: " + selected** and **label = [Display the selected path](browser.set_text(sel="#path", text=`message`))** and **effects = [Keep independent visibility and text effects](browser.merge(a=`visibility`, b=`label`))**.
|
||||
1. `push`
|
||||
We **navigation = [Request one intentional history entry](browser.navigate(url=`selected`))** and **effects = [Keep navigation with its actual panel effects](browser.merge(a=`effects`, b=`navigation`))**.
|
||||
Return *effects* after describing the real selected panel.
|
||||
|
||||
|
||||
## _plain
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| records | list | required | Native text records in retained order |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | Literal newline-joined values for copy or download |
|
||||
|
||||
Use `records` to retain the original plain-text export purpose without turning the client state into a newline-encoded database. Each item's text remains a single native value; newlines are introduced only in this human-readable export. This pure transformation neither writes the clipboard nor starts a download, and it does not encode HTML.
|
||||
|
||||
We **values = [Select actual text fields in order](table.pluck(list=`records`, key="text"))**.
|
||||
Return *[Form the intended text export](text.str_join(xs=`values`, sep="\n"))*.
|
||||
|
||||
## on_saved
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Actual storage-write completion |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Feedback for the completed write |
|
||||
|
||||
Use `ok`=True from the storage callback. Confirm saving after the browser reports completion, rather than when the user merely clicks Save. A failed callback remains a failure message. Host storage exceptions also appear through the official bridge error channel; this function cannot turn an unavailable storage service into a successful write.
|
||||
|
||||
1. not `ok`
|
||||
Return *[Expose the failed write](browser.set_text(sel="#log", text="draft save failed"))*.
|
||||
Return *[Confirm the completed write](browser.set_text(sel="#log", text="draft saved"))*.
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Retained browser theme compilation
|
||||
import:
|
||||
document: lib/document.mq.md
|
||||
web: ext/web/web.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
## css
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | Original theme declarations followed by bounded View geometry |
|
||||
|
||||
Call with fs.read and plugin under the site root. The original table retains every declaration from the former host page, including fonts, green palette, panel spacing and feedback surfaces. The geometry table only adapts native View wrappers and long text for a narrow viewport. Compilation returns CSS through the existing native style capability; it neither writes a file nor starts a server. Serve owns the explicit generated output. Review the data leaf when adjusting appearance and verify actual computed styles in the browser.
|
||||
|
||||
We **original = [Read all retained declarations](document.read_table(path="styles/theme.tables.md", title="original"))** and **geometry = [Read explicit native wrapper rules](document.read_table(path="styles/theme.tables.md", title="geometry"))** and **base = [Compile the retained theme](web.make_style(name="original", table=`original`))** and **wrappers = [Compile bounded View adaptation](web.make_style(name="geometry", table=`geometry`))**.
|
||||
Return *[Keep original cascade before native adaptation](`base` + "\n" + `wrappers`)*.
|
||||
@@ -1,88 +0,0 @@
|
||||
# Browser example theme
|
||||
|
||||
This literal data preserves the original browser-app palette, typefaces, spacing, backgrounds and controls. Region selectors are scoped to the native View frame. Callable compilation is documented in index.mq.md beside this data.
|
||||
|
||||
## original
|
||||
|
||||
Every original declaration appears in its original order. Only selectors gain the known frame address, keeping basic preview defaults from overriding the authored theme.
|
||||
|
||||
| selector | property | value |
|
||||
|---|---|---|
|
||||
| ":root" | "--ink" | "#1a1f1c" |
|
||||
| ":root" | "--paper" | "#e8efe6" |
|
||||
| ":root" | "--accent" | "#2f6f4e" |
|
||||
| ":root" | "--muted" | "#5a6b60" |
|
||||
| "*" | "box-sizing" | "border-box" |
|
||||
| "body" | "margin" | "0" |
|
||||
| "body" | "min-height" | "100vh" |
|
||||
| "body" | "font-family" | "\"IBM Plex Sans\", \"Noto Sans SC\", sans-serif" |
|
||||
| "body" | "color" | "var(--ink)" |
|
||||
| "body" | "background" | "linear-gradient(165deg, #f3f7f2, var(--paper))" |
|
||||
| "body" | "padding" | "2rem clamp(1rem, 4vw, 3rem)" |
|
||||
| ".mq-document .browser-app h1" | "font-family" | "\"IBM Plex Serif\", \"Noto Serif SC\", serif" |
|
||||
| ".mq-document .browser-app h1" | "margin" | "0 0 0.35rem" |
|
||||
| ".mq-document .browser-app .lead" | "color" | "var(--muted)" |
|
||||
| ".mq-document .browser-app .lead" | "max-width" | "42rem" |
|
||||
| ".mq-document .browser-app nav a" | "margin-right" | "0.75rem" |
|
||||
| ".mq-document .browser-app nav a" | "color" | "var(--accent)" |
|
||||
| ".mq-document .browser-app section" | "margin" | "1.5rem 0" |
|
||||
| ".mq-document .browser-app section" | "padding" | "1rem 0" |
|
||||
| ".mq-document .browser-app section" | "border-top" | "1px solid #c5d4c9" |
|
||||
| ".mq-document .browser-app #path" | "font-family" | "ui-monospace, monospace" |
|
||||
| ".mq-document .browser-app #path" | "color" | "var(--muted)" |
|
||||
| ".mq-document .browser-app #items" | "list-style" | "none" |
|
||||
| ".mq-document .browser-app #items" | "padding" | "0" |
|
||||
| ".mq-document .browser-app #items" | "margin" | "0.75rem 0" |
|
||||
| ".mq-document .browser-app #items li" | "display" | "flex" |
|
||||
| ".mq-document .browser-app #items li" | "align-items" | "center" |
|
||||
| ".mq-document .browser-app #items li" | "gap" | "0.5rem" |
|
||||
| ".mq-document .browser-app #items li" | "padding" | "0.4rem 0.6rem" |
|
||||
| ".mq-document .browser-app #items li" | "margin-bottom" | "0.35rem" |
|
||||
| ".mq-document .browser-app #items li" | "background" | "rgba(255,255,255,0.65)" |
|
||||
| ".mq-document .browser-app #items li" | "border" | "1px solid #b7c7bb" |
|
||||
| ".mq-document .browser-app #items button" | "margin-left" | "auto" |
|
||||
| ".mq-document .browser-app input[type=\"text\"]" | "padding" | "0.45rem 0.65rem" |
|
||||
| ".mq-document .browser-app input[type=\"text\"]" | "border" | "1px solid #b7c7bb" |
|
||||
| ".mq-document .browser-app input[type=\"text\"]" | "width" | "min(16rem, 70%)" |
|
||||
| ".mq-document .browser-app button" | "padding" | "0.45rem 0.9rem" |
|
||||
| ".mq-document .browser-app button" | "border" | "0" |
|
||||
| ".mq-document .browser-app button" | "background" | "var(--accent)" |
|
||||
| ".mq-document .browser-app button" | "color" | "#f5faf6" |
|
||||
| ".mq-document .browser-app button" | "font" | "inherit" |
|
||||
| ".mq-document .browser-app button" | "cursor" | "pointer" |
|
||||
| ".mq-document .browser-app button" | "margin" | "0.2rem 0.35rem 0.2rem 0" |
|
||||
| ".mq-document .browser-app button.secondary" | "background" | "#3a4740" |
|
||||
| ".mq-document .browser-app #tick, #net-out" | "font-variant-numeric" | "tabular-nums" |
|
||||
| ".mq-document .browser-app #net-out" | "min-height" | "2.5rem" |
|
||||
| ".mq-document .browser-app #net-out" | "padding" | "0.6rem 0.75rem" |
|
||||
| ".mq-document .browser-app #net-out" | "background" | "rgba(255,255,255,0.55)" |
|
||||
| ".mq-document .browser-app #net-out" | "border" | "1px solid #b7c7bb" |
|
||||
| ".mq-document .browser-app #net-out" | "white-space" | "pre-wrap" |
|
||||
| ".mq-document .browser-app #net-out" | "word-break" | "break-all" |
|
||||
| ".mq-document .browser-app pre" | "margin-top" | "1rem" |
|
||||
| ".mq-document .browser-app pre" | "padding" | "0.85rem 1rem" |
|
||||
| ".mq-document .browser-app pre" | "background" | "#122018" |
|
||||
| ".mq-document .browser-app pre" | "color" | "#d7eadc" |
|
||||
| ".mq-document .browser-app pre" | "font-size" | "0.8rem" |
|
||||
| ".mq-document .browser-app pre" | "overflow" | "auto" |
|
||||
| ".mq-document .browser-app pre" | "max-width" | "42rem" |
|
||||
| ".mq-document .browser-app .err" | "color" | "#ffb4a8" |
|
||||
|
||||
## geometry
|
||||
|
||||
These additions adapt the preview wrappers and keep native controls and literal long text within a narrow viewport. They do not replace the retained palette or typography.
|
||||
|
||||
| selector | property | value |
|
||||
|---|---|---|
|
||||
| ".mq-document .mq-view" | "max-width" | "none" |
|
||||
| ".mq-document .mq-view" | "margin" | "0" |
|
||||
| ".mq-document .mq-view" | "padding" | "0" |
|
||||
| ".mq-document .mq-view" | "font-family" | "inherit" |
|
||||
| ".mq-document .mq-view" | "line-height" | "inherit" |
|
||||
| ".mq-document .browser-app" | "display" | "block" |
|
||||
| ".mq-document .browser-app .mq-column" | "display" | "block" |
|
||||
| ".mq-document .browser-app .mq-row" | "flex-wrap" | "wrap" |
|
||||
| ".mq-document .browser-app #items span" | "overflow-wrap" | "anywhere" |
|
||||
| ".mq-document .browser-app button" | "max-width" | "100%" |
|
||||
| ".mq-document .browser-app pre" | "white-space" | "pre-wrap" |
|
||||
| ".mq-document .browser-app pre" | "overflow-wrap" | "anywhere" |
|
||||
@@ -1,39 +0,0 @@
|
||||
# 计算器
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 供下述方法复用的对象或类型命名空间;直接调用所需的子函数。 |
|
||||
|
||||
这是一个普通的 Marqdo 文档。
|
||||
|
||||
其中包含一些可以复用的数学计算知识。
|
||||
|
||||
## 加法
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| a | any | 必填 | Left operand supplied to this calculation |
|
||||
| b | any | 必填 | Right operand supplied to this calculation |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 下文显式返回的计算值或结构化结果;分支存在时遵循实际命中的分支。 |
|
||||
|
||||
计算两个数字`a`和`b`的和。
|
||||
|
||||
完成上述步骤后,返回*[计算结果]((`a` + `b`))*。
|
||||
|
||||
## 乘法
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| a | any | 必填 | Left operand supplied to this calculation |
|
||||
| b | any | 必填 | Right operand supplied to this calculation |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 下文显式返回的计算值或结构化结果;分支存在时遵循实际命中的分支。 |
|
||||
|
||||
计算两个数字`a`和`b`的积。
|
||||
|
||||
完成上述步骤后,返回*[计算结果]((`a` * `b`))*。
|
||||
@@ -1,7 +0,0 @@
|
||||
# 代码即文档 · 周末咖啡手账
|
||||
|
||||
```bash
|
||||
marqdo run examples/code-as-docs/index.mq.md
|
||||
```
|
||||
|
||||
菜单与订单是表,计价嵌在段落里,结账像写日记。取元用 `[键](集合)`,循环用 `- [行](订单)`,与 [collection-access-link.md](../../doc/design/collection-access-link.md) 一致。
|
||||
@@ -1,134 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 代码即文档 · 周末咖啡手账
|
||||
description: >-
|
||||
一份可读可跑的周末手账:菜单是表,计价写在段落里,结账读起来像日记。
|
||||
---
|
||||
|
||||
周六的咖啡馆手账——下面既是给人看的说明,也是可以 `marqdo run` 的程序。
|
||||
**说明**性的加粗只是强调;真正算账的步骤也用粗体写在句子里,算完的值用斜体交回去。
|
||||
|
||||
---
|
||||
|
||||
## 单价
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 价 | any | 必填 | 同一币种下单件商品的标价 |
|
||||
| 杯数 | any | 1 | 参与本次计价的杯数,未提供时使用正文默认值 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 逐行累加得到的订单总额 |
|
||||
|
||||
一杯标价为`价`的饮品,默认`杯数`=1。先把**总额 = 价 * 杯数**算清,再返回*总额*。
|
||||
|
||||
## 会员折
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 原价 | any | 必填 | 应用折扣之前的原始金额 |
|
||||
| 折扣 | any | 0.85 | 价格乘数;0.85 表示支付原价的百分之八十五 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 下文显式返回的计算值或结构化结果;分支存在时遵循实际命中的分支。 |
|
||||
|
||||
会员单要原价`原价`;店里默认八五折,记作`折扣`=0.85。
|
||||
先算**应付 = 原价 * 折扣**,再返回*应付*。
|
||||
|
||||
## 结账摘要
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 品名 | any | 必填 | 收据或摘要中显示的商品名称 |
|
||||
| 价 | any | 必填 | 同一币种下单件商品的标价 |
|
||||
| 杯数 | any | 1 | 参与本次计价的杯数,未提供时使用正文默认值 |
|
||||
| 会员 | any | False | 是否采用本示例的会员折扣分支 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 包含商品、数量和实付金额的显示文案 |
|
||||
|
||||
客人点了`品名`,单价`价`,杯数`杯数`=1;是否`会员`=False。
|
||||
|
||||
按杯数问单价:**小计 = 单价 价=`价` 杯数=`杯数`**。
|
||||
|
||||
1. `会员`
|
||||
我们先**实付 = [计算并保存 实付](会员折(原价=`小计`))**,供下一步使用。
|
||||
我们先**标签 = "会员价"**,供下一步使用。
|
||||
2. *
|
||||
我们先**实付 = `小计`**,供下一步使用。
|
||||
我们先**标签 = "原价"**,供下一步使用。
|
||||
|
||||
对账时拼成一句人话:
|
||||
|
||||
我们先**文案 = ((((((`品名` + " ×") + `杯数`) + " → ") + `标签`) + " ") + `实付`)**,供下一步使用。
|
||||
完成上述步骤后,返回*文案*。
|
||||
|
||||
## 印章加一
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 印 | any | 必填 | 积分卡当前已有的印章数量 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 下文显式返回的计算值或结构化结果;分支存在时遵循实际命中的分支。 |
|
||||
|
||||
积分卡上的`印`,每喝一杯就**印 = 印 + 1**,接着返回*印*。
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
|
||||
|
||||
这份手账把定价规则放在真正的结账函数里,入口只组织今天的几笔订单。菜单横表是品名到单价的记录,外卖行表则是多条带有数量和会员标记的订单;两者的数据形态不同,因此先按名称取价,再逐行传给同一个摘要函数。
|
||||
|
||||
会员示例与原价对照使用同一套参数和默认值,避免正文与实现各维护一份优惠规则。金额在本例中使用普通运行时数值,会员折扣可能产生小数;这里没有宣称采用专门的货币舍入模型。需要真实计费精度时应另行规定最小单位与舍入步骤,不能把展示摘要的文本当成准确记账凭证。
|
||||
|
||||
打印的是已经计算出的摘要,后续业务若要复用它应直接传递该值,而不是解析输出文字。最后给积分卡加一只改变演示中的印章值,不写入用户文件,也不代表某个真实账户已经更新。
|
||||
|
||||
今日黑板价目——表格给人扫一眼,程序当字典用:
|
||||
|
||||
`菜单` =
|
||||
|
||||
| 美式 | 拿铁 | 燕麦拿铁 |
|
||||
|------|------|----------|
|
||||
| 18 | 28 | 32 |
|
||||
|
||||
---
|
||||
|
||||
上午来了位会员,点两杯拿铁。品名写进`名`,价钱从菜单里取:
|
||||
|
||||
我们先**名 = "拿铁"**,供下一步使用。
|
||||
我们先**价 = [名](access(`菜单`, `名`))**,供下一步使用。
|
||||
我们先**摘要 = [计算并保存 摘要](结账摘要(品名=`名`, 价=`价`, 杯数=2, 会员=True))**,供下一步使用。
|
||||
**打印 内容=`摘要`**
|
||||
|
||||
旁桌只要一杯普通美式,对照一下原价:
|
||||
|
||||
我们先**对照 = [计算并保存 对照](结账摘要(品名="美式", 价=[美式](access(`菜单`, "美式"))))**,供下一步使用。
|
||||
**打印 内容=`对照`**
|
||||
|
||||
---
|
||||
|
||||
下午把外卖单抄成行表,一行一行结:
|
||||
|
||||
`今日订单` =
|
||||
|
||||
| @ | 品名 | 单价 | 杯数 | 会员 |
|
||||
|---|------|------|------|------|
|
||||
| 1 | 燕麦拿铁 | 32 | 1 | True |
|
||||
| 2 | 美式 | 18 | 2 | False |
|
||||
|
||||
- [行](遍历 今日订单 为 行)
|
||||
我们先**一行 = [计算并保存 一行](结账摘要(品名=[品名](access(`行`, "品名")), 价=[单价](access(`行`, "单价")), 杯数=[杯数](access(`行`, "杯数")), 会员=[会员](access(`行`, "会员"))))**,供下一步使用。
|
||||
**打印 内容=`一行`**
|
||||
|
||||
打烊前给积分卡盖一个章:
|
||||
|
||||
我们先**印 = 41**,供下一步使用。
|
||||
我们先**印 = [计算并保存 印](印章加一(印=`印`))**,供下一步使用。
|
||||
**打印 内容=`印`**
|
||||
@@ -1,35 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: resolve_config
|
||||
capability: config.resolve
|
||||
status: stable
|
||||
---
|
||||
|
||||
Use when: final normalized configuration is required.
|
||||
|
||||
# config
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Object/type namespace for the child functions below; call the intended child directly |
|
||||
|
||||
## resolve_config
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| path | any | required | Filesystem path under the granted root; this callback's prose identifies URL paths separately |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; this unit completes the operations described below without a data return |
|
||||
The shared input protocol also accepts `path`. We **[Accept this documented input without changing the result](`path`)**.
|
||||
|
||||
Input `path`, used by the steps below.
|
||||
|
||||
`defaults` =
|
||||
|
||||
| host | port |
|
||||
|------|------|
|
||||
| localhost | 8080 |
|
||||
|
||||
* defaults
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Engineering Knowledge demo
|
||||
description: Tiny project demonstrating Capability Catalog + reuse + decisions.
|
||||
---
|
||||
|
||||
# Engineering Knowledge demo
|
||||
|
||||
|
||||
This folder is a miniature “large engineering” slice: config resolution already exists.
|
||||
Before generating a new loader, run:
|
||||
|
||||
```bash
|
||||
marqdo knowledge examples/engineering-knowledge -o examples/engineering-knowledge/.marqdo
|
||||
marqdo reuse "load and resolve configuration" examples/engineering-knowledge -o examples/engineering-knowledge/.marqdo
|
||||
marqdo duplicate examples/engineering-knowledge -o examples/engineering-knowledge/.marqdo
|
||||
```
|
||||
|
||||
Expected: **REUSE config.resolve**, not a new `load_configuration`.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
* "see README via catalog/reuse CLI"
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
type: Decision
|
||||
id: ADR-022
|
||||
title: Cache is not persistence
|
||||
status: accepted
|
||||
applies_to:
|
||||
- config.resolve
|
||||
---
|
||||
|
||||
# Cache is not persistence
|
||||
|
||||
## Decision
|
||||
|
||||
Redis is only used for ephemeral cache.
|
||||
|
||||
## Reason
|
||||
|
||||
The application must remain correct when Redis is unavailable.
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
type: Constraint
|
||||
id: C-014
|
||||
title: Centralized config resolution
|
||||
status: stable
|
||||
applies_to:
|
||||
- config.resolve
|
||||
---
|
||||
|
||||
# Centralized config resolution
|
||||
|
||||
All configuration resolution must go through `resolve_config`.
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
type: Failure
|
||||
id: F-008
|
||||
title: Do not invent a second config loader
|
||||
status: resolved
|
||||
---
|
||||
|
||||
# Do not invent a second config loader
|
||||
|
||||
## Failed approach
|
||||
|
||||
Added `load_configuration` beside `resolve_config`.
|
||||
|
||||
## Failure
|
||||
|
||||
Divergent defaults and error handling.
|
||||
|
||||
## Correct approach
|
||||
|
||||
Call `resolve_config`.
|
||||
@@ -1,44 +0,0 @@
|
||||
# 可执行知识系统示例:订单含税总额
|
||||
|
||||
这是 [可执行知识系统设计](../../doc/design/executable-knowledge-system.md) 的目标示例,
|
||||
已按当前 occlusion 语法落地为**可运行**订单链(Tree / Bytecode)。
|
||||
|
||||
| 文件 | 图中的职责 | 关键步骤 |
|
||||
|---|---|---|
|
||||
| `corpus/tax-policy-2026.md` | E:证据 | 税率原文 |
|
||||
| `schema/order.mq.md` | C:概念 | 订单/订单行字段与单位 |
|
||||
| `knowledge/tax-2026.mq.md` | K:原子知识 | `标准税率.查询` + `sources:` |
|
||||
| `knowledge/negative-refund.mq.md` | 负知识 | 折扣不适用于退款 |
|
||||
| `capabilities/order-pricing.mq.md` | D:推导知识 | 取元、调用、循环、汇总 |
|
||||
| `docs/invoice-answer.mq.md` | N:叙述知识 | 含税结论 + NarrativeRef |
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
marqdo run examples/executable-knowledge/docs/invoice-answer.mq.md --backend tree
|
||||
marqdo run examples/executable-knowledge/docs/invoice-answer.mq.md --backend bytecode
|
||||
# → 113
|
||||
marqdo knowledge examples/executable-knowledge -o /tmp/ek
|
||||
marqdo knowledge impact "标准税率.查询" examples/executable-knowledge --json
|
||||
```
|
||||
|
||||
门禁:`cargo test --test executable_knowledge s4_examples_bookstore_chain_runs_both_backends --locked`
|
||||
|
||||
## 读法
|
||||
|
||||
`[]()` 的每一次出现都是命名步骤(observe / derive / iterate / call / narrate):
|
||||
|
||||
```markdown
|
||||
[订单行金额](access(行, "金额")) # observe
|
||||
[本行含税价](金额 * (1 + 税率)) # derive
|
||||
[逐个订单行](遍历 行列表 为 行) # iterate
|
||||
这张订单的含税总额是[含税总价](总额)。 # narrate
|
||||
```
|
||||
|
||||
## 运行状态
|
||||
|
||||
| 子集 | 状态 | 证据 |
|
||||
|---|---|---|
|
||||
| 发票含税链双后端 `113` | **可运行** | 上表命令 / EK 门禁 |
|
||||
| 来源 `sourced` + impact 下游 | **可运行** | knowledge 投影 + impact |
|
||||
| 负知识文档 | **已收录** | `knowledge/negative-refund.mq.md`(发现层;非执行目标) |
|
||||
@@ -1,52 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
id: capability.order-pricing
|
||||
type: Capability
|
||||
import:
|
||||
tax: ../knowledge/tax-2026.mq.md
|
||||
---
|
||||
|
||||
# 订单定价
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 供下述方法复用的对象或类型命名空间;直接调用所需的子函数。 |
|
||||
|
||||
按订单行取未税金额与品类,套用税率后汇总含税总额。
|
||||
|
||||
## 含税价
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 行 | any | 必填 | 订单行记录;按相邻数据表提供金额、品类等字段 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 本次计算得到的结果 |
|
||||
|
||||
输入`行`,按下方步骤使用这个值。
|
||||
|
||||
我们先**金额 = [订单行金额](access(`行`, "金额"))**,供下一步使用。
|
||||
我们先**品类 = [订单行品类](access(`行`, "品类"))**,供下一步使用。
|
||||
我们先**税率 = [计算并保存 税率](tax.标准税率.查询(品类=`品类`))**,供下一步使用。
|
||||
我们先**结果 = [本行含税价]((`金额` * (1 + `税率`)))**,供下一步使用。
|
||||
完成上述步骤后,返回*结果*。
|
||||
|
||||
## 含税总额
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 订单 | any | 必填 | 包含行记录集合的订单数据;税率与金额字段由本示例约定 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 逐行累加得到的订单总额 |
|
||||
|
||||
输入`订单`,按下方步骤使用这个值。
|
||||
|
||||
我们先**行列表 = [订单行列表](access(`订单`, "行"))**,供下一步使用。
|
||||
我们先**总额 = 0**,供下一步使用。
|
||||
- [逐个订单行](遍历 行列表 为 行)
|
||||
我们先**行含税价 = [计算并保存 行含税价](订单定价.含税价(行=`行`))**,供下一步使用。
|
||||
我们先**总额 = [累加]((`总额` + `行含税价`))**,供下一步使用。
|
||||
完成上述步骤后,返回*总额*。
|
||||
@@ -1,5 +0,0 @@
|
||||
# 2026 年标准增值税率
|
||||
|
||||
本示例的原始证据:标准税率为 13%。
|
||||
|
||||
此文件只作来源定位,不执行。
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
id: document.invoice-answer
|
||||
type: Answer
|
||||
import:
|
||||
pricing: ../capabilities/order-pricing.mq.md
|
||||
json: lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
发票回答:演示订单一行图书,未税金额 100。
|
||||
|
||||
We first **订单 = [Compute 订单](json.parse(text="{\"行\":[{\"金额\":100,\"品类\":\"书\"}]}"))** for the next step.
|
||||
We first **总额 = [Compute 总额](pricing.订单定价.含税总额(订单=`订单`))** for the next step.
|
||||
|
||||
这张订单的含税总额是[含税总价](总额)。
|
||||
|
||||
We now **[Display this step's result](> print text=`总额`)**.
|
||||
@@ -1,22 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
id: knowledge.negative.discount-not-for-refund
|
||||
type: Failure
|
||||
title: 折扣不适用于退款
|
||||
---
|
||||
|
||||
# 折扣不适用于退款
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Object/type namespace for the child functions below; call the intended child directly |
|
||||
|
||||
负知识:退款结算不得套用会员折扣。Agent 复用折扣能力时应拒绝该适用面。
|
||||
|
||||
## 说明
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
After these steps, return *[不适用](`false`)*.
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
id: knowledge.tax.standard-2026
|
||||
type: Fact
|
||||
sources:
|
||||
- ../corpus/tax-policy-2026.md#2026 年标准增值税率
|
||||
applicability:
|
||||
region: CN
|
||||
valid_until: 2099-12-31
|
||||
---
|
||||
|
||||
# 标准税率
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Object/type namespace for the child functions below; call the intended child directly |
|
||||
|
||||
当前政策下的标准增值税率。`品类` 预留给差异化税率;本演示固定返回标准税率。
|
||||
|
||||
## 查询
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
`品类`
|
||||
|
||||
After these steps, return *[标准税率](0.13)*.
|
||||
@@ -1,27 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
id: schema.order
|
||||
type: Schema
|
||||
---
|
||||
|
||||
# 订单
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| 行 | list | 待计价的订单行;每一项遵守下方独立对象的字段契约 |
|
||||
|
||||
订单只收拢本次计算需要的行记录,不替调用方补缺失金额或品类。
|
||||
每一行使用同一金额单位,税率知识由能力模块选择;此处只描述数据形态。
|
||||
|
||||
# 订单行
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| 金额 | number | 未税金额 |
|
||||
| 品类 | text | 用于选择税率 |
|
||||
|
||||
订单行是独立的顶层对象类型,因此订单中的列表元素可以引用它。
|
||||
字段表紧接对象标题,避免将类型声明误写成具有参数和返回值的普通函数。
|
||||
|
||||
行字段的运行时契约约束列表本身;元素形态按订单行的字段说明提供,
|
||||
不把尚未支持的泛型类型拼写当成已经执行的逐元素校验。
|
||||
@@ -1,151 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Native report tools and a persistent Intl formatter
|
||||
import:
|
||||
foreign: lib/foreign.mq.md
|
||||
table: lib/table.mq.md
|
||||
stats: lib/stats.mq.md
|
||||
math: lib/math.mq.md
|
||||
result: lib/result.mq.md
|
||||
---
|
||||
|
||||
This module keeps order analysis in native Marqdo and uses Node Intl only for
|
||||
locale-aware currency formatting. Import it from a report page or call its
|
||||
two public functions separately. There is no executable main in this module;
|
||||
the English and Chinese public feature pages compose the full callable view.
|
||||
|
||||
From the repository root, call analyze_orders with an orders row list and
|
||||
--effects none. It returns ordinary report data. Pass that report to
|
||||
format_summary with --effects process.exec for the bounded persistent formatter.
|
||||
A missing Node executable is an explicit failed Result; native analysis remains
|
||||
available without it. No Python interpreter is required.
|
||||
|
||||
## analyze_orders
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| orders | list | required | Order rows with a region and numeric amount; no file or network IO |
|
||||
| region_key | text | "region" | Field whose value identifies a group |
|
||||
| amount_key | text | "amount" | Numeric amount field in every row |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Native report with regions, total, count and average |
|
||||
|
||||
Use `orders`, `region_key`="region" and `amount_key`="amount" for the
|
||||
whole analysis. Grouping, ordering, arithmetic, means and population deviation
|
||||
all use Marqdo and its standard libraries. Each region retains orders, total,
|
||||
mean and z_span, so moving the boundary does not remove the analysis. The data
|
||||
is a row list, not a JSON program or an opaque host dataframe.
|
||||
|
||||
The report has one row per region in sorted key order. Population variance is
|
||||
the mean squared deviation; a singleton or equal-valued group has zero spread,
|
||||
for which the normalization denominator is one and z_span is zero. The maximum
|
||||
normalized deviation is the same statistic the previous kernel example displayed.
|
||||
Values are ordinary runtime numbers, not a financial decimal model; the formatter
|
||||
later chooses presentation precision without changing this report.
|
||||
|
||||
Empty input returns no regions and zero totals/average. Missing fields and invalid
|
||||
amounts preserve native diagnostics; do not replace them with invented zeroes.
|
||||
The function is pure and needs no interpreter, plugin, process, file or network
|
||||
grant. Its actual return can be checked with marqdo call before preparing a view.
|
||||
The native report is also the only analysis value copied into external kernels:
|
||||
there is no second implementation of grouping or statistics in another language.
|
||||
|
||||
We **groups = [Group native rows and order their original keys](table.sort_by(list=table.group_by(list=`orders`, key=`region_key`), key="key"))** and **regions = [Start native summary rows](table.empty_list())**.
|
||||
- [Summarize each region through native values](for groups as group)
|
||||
We **rows = [Read this group's original rows](access(group, "rows"))** and **region = [Retain its region key](access(group, "key"))** and **values = [Read numeric amounts](table.pluck(list=`rows`, key=`amount_key`))**.
|
||||
We **mean = [Compute the native arithmetic mean](stats.mean(list=`values`))** and **squared = 0.0**.
|
||||
- [Accumulate population squared deviation](for values as value)
|
||||
We **squared = squared + (value - mean) * (value - mean)**.
|
||||
We **sigma = [Compute population spread](math.sqrt(value=`squared` / len(values)))**.
|
||||
1. `sigma` <= 0
|
||||
We **sigma = 1** so equal-valued groups keep a zero normalized span.
|
||||
We **count = [Count this region's values](len(values))** and **total = [Sum the region in Marqdo](table.aggregate(list=`values`))** and **maximum = [Read its largest amount](table.aggregate(list=`values`, op="max"))** and **z_span = (maximum - mean) / sigma**.
|
||||
|
||||
`row` =
|
||||
|
||||
| region | orders | total | mean | z_span |
|
||||
|---|---|---|---|---|
|
||||
| `region` | `count` | `total` | `mean` | `z_span` |
|
||||
|
||||
We **regions = [Retain this native summary row](table.append(list=`regions`, item=`row`))**.
|
||||
We **count = [Count all input orders](len(orders))** and **total = [Sum all native amounts](table.aggregate(list=`orders`, key=`amount_key`))** and **average = 0**.
|
||||
1. `count` > 0
|
||||
We **average = [Use the native mean without integer division](stats.mean(list=table.pluck(list=`orders`, key=`amount_key`)))** for a nonempty report.
|
||||
|
||||
`report` =
|
||||
|
||||
| regions | total | count | average |
|
||||
|---|---|---|---|
|
||||
| `regions` | `total` | `count` | `average` |
|
||||
|
||||
After the native analysis we return *report*.
|
||||
|
||||
## format_summary
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| report | map | required | Native analyze_orders result with total and average |
|
||||
| locale | text | "en-US" | Locale understood by Node Intl; currency is CNY |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Result containing localized total and average strings |
|
||||
|
||||
Use `report` and `locale`="en-US" only for the presentation gap:
|
||||
locale-aware currency formatting is provided here by Node's built-in Intl.
|
||||
The source makes that external boundary explicit. It does not read or write files,
|
||||
recalculate the native report, import a package or use Python. Node must already
|
||||
be installed; probe it before creating a kernel and return a real failure if
|
||||
it is unavailable.
|
||||
|
||||
One persistent kernel receives JSON copies of the report and locale. The first
|
||||
evaluation creates a formatter and formats the total; the second reuses that
|
||||
same formatter for the already-computed native average. A fresh process without
|
||||
its previous state could not run the second expression successfully. The helper
|
||||
checks each evaluation's ok field and closes a live kernel before returning,
|
||||
including handled evaluation errors. A dead kernel has already been retired and
|
||||
must not be closed a second time.
|
||||
|
||||
This function needs process.exec. Native policy or serialization diagnostics
|
||||
remain diagnostics, not synthetic currency strings. Kernel values cannot become
|
||||
guessed handles, and an opaque handle never crosses a CLI JSON boundary. Only
|
||||
the two actual formatted strings leave this task in its successful Result.
|
||||
|
||||
We **probe = [Check the explicit external interpreter](foreign.probe(lang="node"))**.
|
||||
1. not access(`probe`, "ok")
|
||||
Return *[Keep the missing interpreter visible](result.error(code="example.node", message=str(`probe`), operation="format_summary"))*.
|
||||
We **kernel = [Open one persistent formatter kernel](foreign.session_open(lang="node"))** and **copied = [Copy the native report as ordinary data](foreign.session_set(id=`kernel`, name="report", value=`report`))** and **selected = [Copy the requested display locale](foreign.session_set(id=`kernel`, name="locale", value=`locale`))**.
|
||||
|
||||
`formatter_code` =
|
||||
```node
|
||||
var money = new Intl.NumberFormat(locale, {style: "currency", currency: "CNY"});
|
||||
money.format(report.total)
|
||||
```
|
||||
|
||||
We **first = [Create the formatter and format the native total](foreign.session_eval(id=`kernel`, code=`formatter_code`))**.
|
||||
1. not access(`first`, "ok")
|
||||
1. access(`first`, "alive")
|
||||
We **closed = [Close a still-live failed formatter](foreign.session_close(id=`kernel`))**.
|
||||
Return *[Keep the actual formatter failure](result.error(code="example.format", message=str(`first`), operation="format_summary"))*.
|
||||
|
||||
`average_code` =
|
||||
```node
|
||||
money.format(report.average)
|
||||
```
|
||||
|
||||
We **second = [Reuse the formatter's persistent state](foreign.session_eval(id=`kernel`, code=`average_code`))**.
|
||||
1. not access(`second`, "ok")
|
||||
1. access(`second`, "alive")
|
||||
We **closed = [Close a live kernel after the second failure](foreign.session_close(id=`kernel`))**.
|
||||
Return *[Keep the actual reuse failure](result.error(code="example.format", message=str(`second`), operation="format_summary"))*.
|
||||
We **total = [Read the actual formatted total](access(first, "result"))** and **average = [Read the actual formatted average](access(second, "result"))** and **closed = [Close the consumed formatter kernel](foreign.session_close(id=`kernel`))**.
|
||||
|
||||
`formatted` =
|
||||
|
||||
| total | average |
|
||||
|---|---|
|
||||
| `total` | `average` |
|
||||
|
||||
Return *[The real locale-aware strings](result.ok(value=`formatted`))*.
|
||||
@@ -1,91 +0,0 @@
|
||||
# 知识分层示例:本体 → 知识个体 → 调用面
|
||||
|
||||
这个目录演示 [知识分层设计](../../doc/design/knowledge-layers.md):
|
||||
|
||||
| 层 | 文件 | 内容 |
|
||||
|----|------|------|
|
||||
| **L0 原始语料** | `corpus/libai.md` | 李白原文;不执行,只作出处 |
|
||||
| **L1 本体 / 模式** | `poet.mq.md` | `# 诗人` + 字段/类型表 |
|
||||
| **L2 可执行知识** | `libai.mq.md` | `# 李白 = > 诗人` + `##` 事实 + 来源 |
|
||||
| **L3 调用面** | `main.mq.md` / `main.compat.mq.md` | `[]()` 类调用 |
|
||||
|
||||
> **关键术语**:`# 李白 = > 诗人` 是**知识个体/单体知识类**(语法上是继承/特化),
|
||||
> 不是运行时实例;`> 李白` 才是运行时 map 实例。
|
||||
|
||||
## 今天可跑(v2.0.0 兼容)
|
||||
|
||||
```bash
|
||||
marqdo run examples/knowledge-layers/main.compat.mq.md
|
||||
# 701
|
||||
```
|
||||
|
||||
`main.compat.mq.md` 用当前能力完成同一件事:
|
||||
|
||||
```markdown
|
||||
---
|
||||
import libai:libai.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**li = > libai.李白**
|
||||
**year = > `li`.出生年份**
|
||||
> print text=`year`
|
||||
```
|
||||
|
||||
- `import` 绑定知识文档;
|
||||
- `> libai.李白` 构造实例;
|
||||
- `` `li`.出生年份 `` 调用实例方法;
|
||||
- 当前 `libai.mq.md` 还保留 `import poet:poet.mq.md`,因为 v2.0.0 的跨文档继承需要 import;
|
||||
v2.1 的项目类索引会去掉这个 import。
|
||||
|
||||
## 目标(v2.1)
|
||||
|
||||
`main.mq.md`:
|
||||
|
||||
```markdown
|
||||
# main
|
||||
|
||||
诗人李白的出生年份是[出生年份](李白.出生年份)。
|
||||
```
|
||||
|
||||
- `李白` 是项目类索引里的知识个体;
|
||||
- `出生年份` 是它的类函数;
|
||||
- 正文链接由 `view`/`check` 解析;`run` 不执行;
|
||||
- 要终端输出,把同一段代码放进代码链接并加 `print`。
|
||||
|
||||
期望:
|
||||
|
||||
```bash
|
||||
$ marqdo run examples/knowledge-layers/main.mq.md
|
||||
# 无输出(正文链接不执行)
|
||||
|
||||
$ marqdo check examples/knowledge-layers/main.mq.md --json
|
||||
{"code":"link.ok", ...}
|
||||
```
|
||||
|
||||
`view` 期望显示:
|
||||
|
||||
```text
|
||||
诗人李白的出生年份是 701。
|
||||
↑
|
||||
悬浮:出生年份 → 李白.出生年份
|
||||
class 李白 · () -> number · value 701
|
||||
来源:corpus/libai.md#出生年份
|
||||
```
|
||||
|
||||
## 为什么 `# 李白 = > 诗人` 不是「实例化」
|
||||
|
||||
- `# 诗人` 是类/本体;
|
||||
- `# 李白 = > 诗人` 是**继承/特化**,表达「李白是诗人」;
|
||||
- 但它带有一个命名个体的全部事实,所以是**单体知识类**;
|
||||
- `李白.出生年份` 是类调用,不需要 `> 李白` 构造实例;
|
||||
- 如果要运行时实例,仍可 `**li = > 李白**`,它是 map + `_type`,和知识个体分离。
|
||||
|
||||
详见 [doc/design/knowledge-layers.md](../../doc/design/knowledge-layers.md)。
|
||||
|
||||
## 相关
|
||||
|
||||
- 链接语法:[doc/design/link-syntax.md](../../doc/design/link-syntax.md)
|
||||
- 证据复核:[doc/research/occlusion-vs-executable-knowledge-2026-10.md](../../doc/research/occlusion-vs-executable-knowledge-2026-10.md)
|
||||
- 旧遮蔽设计:[doc/design/occlusion-syntax.md](../../doc/design/occlusion-syntax.md)
|
||||
@@ -1,5 +0,0 @@
|
||||
# 李白
|
||||
|
||||
李白,字太白,唐代诗人,生于公元 701 年。
|
||||
|
||||
这段是**原始语料**:它不执行,只作为知识出处。
|
||||
@@ -1,30 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: Fact
|
||||
id: libai
|
||||
title: 李白
|
||||
import:
|
||||
poet: poet.mq.md
|
||||
---
|
||||
|
||||
# 李白 = > 诗人
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 供下述方法复用的对象或类型命名空间;直接调用所需的子函数。 |
|
||||
|
||||
## 姓名
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 下文显式返回的计算值或结构化结果;分支存在时遵循实际命中的分支。 |
|
||||
|
||||
完成上述步骤后,返回*"李白"*。
|
||||
|
||||
## 出生年份
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| 701 | number | 公元 701 年;来源:corpus/libai.md#出生年份 |
|
||||
|
||||
完成上述步骤后,返回*701*。
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
import:
|
||||
libai: libai.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**li = > libai.李白**
|
||||
**year = > `li`.出生年份**
|
||||
> print text=`year`
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
诗人李白的出生年份是[出生年份](李白.出生年份)。
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
# 诗人
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 空值;本段完成下述操作,不额外返回业务数据。 |
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| 姓名 | text | 诗人姓名 |
|
||||
| 出生年份 | number | 公元年份 |
|
||||
@@ -1,14 +0,0 @@
|
||||
# Marqdo 知识锚点 + 自动证明示例
|
||||
|
||||
面向 CLI 2.8.0,原 Markdown 语法不变:
|
||||
|
||||
```sh
|
||||
marqdo knowledge examples/knowledge-proof/
|
||||
marqdo prove examples/knowledge-proof/main.mq.md --json
|
||||
marqdo knowledge examples/knowledge-proof/
|
||||
```
|
||||
|
||||
知识编译后,查看 `.marqdo/anchors.json`、`.marqdo/claims.json`、`.marqdo/refs.json`、`.marqdo/graph/edges.json` 以及 `.marqdo/proof-index.json`(具体输出目录取决于 CLI --out)。
|
||||
证明调用另外生成其证明目录下的 `knowledge-links.json`。运行 CLI 时是否有 Lean 决定该定理能否获得真正的 `proved` 状态;没有 Lean 只能是 `checked` 或 `unverified`。在此案例中,`长度(轨迹)=0` 是函数级定理,并非内部的“计算结果”步骤已经独立证明正确。
|
||||
|
||||
`[计算知识节点](#@计算结果)` 是**同函数内的静态知识引用**。跨文件引用请从 `anchors.json` 拿完整 `mq://...#anchor-...` 地址,不要猜测哈希。两个同名标记不共享地址,会被标记为无公共锚点。
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 可寻址、可验证的知识步骤
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
## 计算
|
||||
|
||||
| 定理 | 结论 | 前提 | 策略 |
|
||||
|---|---|---|---|
|
||||
| 无外部操作 | 长度(轨迹) = 0 | | auto |
|
||||
|
||||
这里的 [计算知识节点](#@计算结果) 和 [定理声明](#@无外部操作) 都是可解析的知识引用;
|
||||
它不会再次执行运算,也不会自动继承函数的形式化证明。
|
||||
|
||||
**答案 = [计算结果](2 * 3)**
|
||||
|
||||
*答案*
|
||||
@@ -1,803 +0,0 @@
|
||||
//! Audit library source with the real parser, and compare executable ASTs across prose refactors.
|
||||
use anyhow::{Context, Result};
|
||||
use marqdo::{ast::*, diagnostics::Span};
|
||||
use serde_json::{json, Value};
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
fn files(dir: &Path, out: &mut Vec<PathBuf>) -> Result<()> {
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let p = entry?.path();
|
||||
if p.is_dir() {
|
||||
files(&p, out)?
|
||||
} else if p.to_string_lossy().ends_with(".mq.md") {
|
||||
out.push(p)
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn expr(e: Expr) -> Expr {
|
||||
match e {
|
||||
Expr::Occluded { payload, .. } => payload
|
||||
.map(|p| expr(*p))
|
||||
.unwrap_or(Expr::Literal(Literal::None)),
|
||||
Expr::Unary { op, expr: e } => Expr::Unary {
|
||||
op,
|
||||
expr: Box::new(expr(*e)),
|
||||
},
|
||||
Expr::Binary { op, left, right } => Expr::Binary {
|
||||
op,
|
||||
left: Box::new(expr(*left)),
|
||||
right: Box::new(expr(*right)),
|
||||
},
|
||||
Expr::Call(c) => {
|
||||
let c = call(c);
|
||||
pure_literal_call(&c).unwrap_or(Expr::Call(c))
|
||||
}
|
||||
Expr::List(xs) => Expr::List(xs.into_iter().map(expr).collect()),
|
||||
Expr::Map(xs) => Expr::Map(xs.into_iter().map(|(k, v)| (k, expr(v))).collect()),
|
||||
Expr::Index { base, label } => Expr::Index {
|
||||
base: Box::new(expr(*base)),
|
||||
label,
|
||||
},
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
fn call(mut c: CallExpr) -> CallExpr {
|
||||
for a in &mut c.args {
|
||||
match a {
|
||||
Arg::Positional(e) | Arg::Named { value: e, .. } => *e = expr(e.clone()),
|
||||
}
|
||||
}
|
||||
c
|
||||
}
|
||||
// Only the explicitly supported pure literal-building cases are folded. This is
|
||||
// a refactor audit, not an evaluator: unknown calls and nonconstant data remain.
|
||||
fn literal_json_value(v: serde_json::Value) -> Option<Expr> {
|
||||
use serde_json::Value as J;
|
||||
Some(Expr::Literal(match v {
|
||||
J::Null => Literal::None,
|
||||
J::Bool(b) => Literal::Bool(b),
|
||||
J::String(s) => Literal::Text(s),
|
||||
J::Number(n) => {
|
||||
if let Some(i) = n.as_i64() {
|
||||
if i.unsigned_abs() > 9_007_199_254_740_991 {
|
||||
return None;
|
||||
}
|
||||
Literal::Int(i)
|
||||
} else {
|
||||
let n = n.as_f64()?;
|
||||
if !n.is_finite() || (n.fract() == 0.0 && n.abs() > 9_007_199_254_740_991.0) {
|
||||
return None;
|
||||
}
|
||||
Literal::Num(n)
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
}))
|
||||
}
|
||||
// Read JSON literals without accepting duplicate keys or unsafe numeric coercions.
|
||||
fn flat_json_record(text: &str) -> Option<Expr> {
|
||||
struct Constant;
|
||||
impl<'de> serde::Deserialize<'de> for ConstantExpr {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
|
||||
de.deserialize_any(Constant).map(ConstantExpr)
|
||||
}
|
||||
}
|
||||
struct ConstantExpr(Expr);
|
||||
impl<'de> serde::de::Visitor<'de> for Constant {
|
||||
type Value = Expr;
|
||||
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
f.write_str("constant JSON in the exact audit numeric domain")
|
||||
}
|
||||
fn visit_unit<E: serde::de::Error>(self) -> Result<Expr, E> {
|
||||
Ok(Expr::Literal(Literal::None))
|
||||
}
|
||||
fn visit_bool<E: serde::de::Error>(self, b: bool) -> Result<Expr, E> {
|
||||
Ok(Expr::Literal(Literal::Bool(b)))
|
||||
}
|
||||
fn visit_str<E: serde::de::Error>(self, s: &str) -> Result<Expr, E> {
|
||||
Ok(Expr::Literal(Literal::Text(s.into())))
|
||||
}
|
||||
fn visit_i64<E: serde::de::Error>(self, n: i64) -> Result<Expr, E> {
|
||||
literal_json_value(n.into()).ok_or_else(|| E::custom("unsafe integer"))
|
||||
}
|
||||
fn visit_u64<E: serde::de::Error>(self, n: u64) -> Result<Expr, E> {
|
||||
literal_json_value(n.into()).ok_or_else(|| E::custom("unsafe integer"))
|
||||
}
|
||||
fn visit_f64<E: serde::de::Error>(self, n: f64) -> Result<Expr, E> {
|
||||
let n = serde_json::Number::from_f64(n).ok_or_else(|| E::custom("nonfinite number"))?;
|
||||
literal_json_value(n.into()).ok_or_else(|| E::custom("unsafe number"))
|
||||
}
|
||||
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut seq: A) -> Result<Expr, A::Error> {
|
||||
let mut values = Vec::new();
|
||||
while let Some(ConstantExpr(v)) = seq.next_element()? {
|
||||
values.push(v);
|
||||
}
|
||||
Ok(Expr::List(values))
|
||||
}
|
||||
fn visit_map<A: serde::de::MapAccess<'de>>(self, mut map: A) -> Result<Expr, A::Error> {
|
||||
use serde::de::Error;
|
||||
let mut fields = std::collections::BTreeMap::new();
|
||||
while let Some((key, ConstantExpr(value))) = map.next_entry::<String, ConstantExpr>()? {
|
||||
if fields.insert(key, value).is_some() {
|
||||
return Err(A::Error::custom("duplicate key"));
|
||||
}
|
||||
}
|
||||
Ok(Expr::Map(fields.into_iter().collect()))
|
||||
}
|
||||
}
|
||||
let ConstantExpr(value) = serde_json::from_str::<ConstantExpr>(text).ok()?;
|
||||
Some(value)
|
||||
}
|
||||
fn pure_literal_call(c: &CallExpr) -> Option<Expr> {
|
||||
let name = c
|
||||
.path
|
||||
.as_ref()
|
||||
.map(|p| p.join("."))
|
||||
.unwrap_or_else(|| c.callee.clone());
|
||||
let get = |key: &str| {
|
||||
c.args.iter().find_map(|a| match a {
|
||||
Arg::Named { name, value } if name == key => Some(value),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
match name.as_str() {
|
||||
"json.parse" => {
|
||||
if let Expr::Literal(Literal::Text(text)) = get("text")? {
|
||||
flat_json_record(text)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
"table.put" if matches!(get("in")?, Expr::Literal(Literal::None)) => {
|
||||
if let Expr::Literal(Literal::Text(key)) = get("at")? {
|
||||
let value = get("value")?;
|
||||
if matches!(value, Expr::Literal(_)) {
|
||||
Some(Expr::Map(vec![(key.clone(), value.clone())]))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
"table.empty_list" => Some(Expr::List(Vec::new())),
|
||||
"table.from_pairs" => {
|
||||
let Expr::List(rows) = get("pairs")? else {
|
||||
return None;
|
||||
};
|
||||
let mut fields = Vec::new();
|
||||
let mut seen = std::collections::BTreeSet::new();
|
||||
for row in rows {
|
||||
let Expr::Map(pairs) = row else {
|
||||
return None;
|
||||
};
|
||||
let Some((_, Expr::Literal(Literal::Text(key)))) =
|
||||
pairs.iter().find(|(k, _)| k == "key")
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
let Some((_, value)) = pairs.iter().find(|(k, _)| k == "value") else {
|
||||
return None;
|
||||
};
|
||||
if !constant(value) || !seen.insert(key.clone()) {
|
||||
return None;
|
||||
}
|
||||
fields.push((key.clone(), value.clone()));
|
||||
}
|
||||
Some(Expr::Map(fields))
|
||||
}
|
||||
"text.str_join" => {
|
||||
let Expr::List(rows) = get("xs")? else {
|
||||
return None;
|
||||
};
|
||||
let Expr::Literal(Literal::Text(separator)) = get("sep")? else {
|
||||
return None;
|
||||
};
|
||||
let rows = rows
|
||||
.iter()
|
||||
.map(|e| {
|
||||
if let Expr::Literal(Literal::Text(s)) = e {
|
||||
Some(s.as_str())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()?;
|
||||
Some(Expr::Literal(Literal::Text(rows.join(separator))))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn constant(e: &Expr) -> bool {
|
||||
match e {
|
||||
Expr::Literal(_) => true,
|
||||
Expr::List(xs) => xs.iter().all(constant),
|
||||
Expr::Map(xs) => xs.iter().all(|(_, v)| constant(v)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn substitute(e: Expr, temps: &std::collections::BTreeMap<String, Expr>) -> Expr {
|
||||
let e = match e {
|
||||
Expr::Var(name) if temps.contains_key(&name) => temps[&name].clone(),
|
||||
Expr::Call(mut c) => {
|
||||
for a in &mut c.args {
|
||||
match a {
|
||||
Arg::Named { value, .. } | Arg::Positional(value) => {
|
||||
*value = substitute(value.clone(), temps)
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Call(c)
|
||||
}
|
||||
Expr::Map(xs) => Expr::Map(
|
||||
xs.into_iter()
|
||||
.map(|(k, v)| (k, substitute(v, temps)))
|
||||
.collect(),
|
||||
),
|
||||
Expr::List(xs) => Expr::List(xs.into_iter().map(|v| substitute(v, temps)).collect()),
|
||||
Expr::Occluded {
|
||||
payload: Some(v), ..
|
||||
} => substitute(*v, temps),
|
||||
Expr::Unary { op, expr: v } => Expr::Unary {
|
||||
op,
|
||||
expr: Box::new(substitute(*v, temps)),
|
||||
},
|
||||
Expr::Binary { op, left, right } => Expr::Binary {
|
||||
op,
|
||||
left: Box::new(substitute(*left, temps)),
|
||||
right: Box::new(substitute(*right, temps)),
|
||||
},
|
||||
other => other,
|
||||
};
|
||||
expr(e)
|
||||
}
|
||||
fn canonical_statements(statements: Vec<Stmt>) -> Vec<Stmt> {
|
||||
fn block(
|
||||
statements: Vec<Stmt>,
|
||||
mut temps: std::collections::BTreeMap<String, Expr>,
|
||||
) -> Vec<Stmt> {
|
||||
let mut out = Vec::new();
|
||||
for s in statements {
|
||||
let s = statement(s);
|
||||
let s = match s {
|
||||
Stmt::Assign {
|
||||
name,
|
||||
value,
|
||||
span,
|
||||
end_line,
|
||||
} => {
|
||||
let value = substitute(value, &temps);
|
||||
if name.starts_with("_literal_") && constant(&value) {
|
||||
temps.insert(name, value);
|
||||
continue;
|
||||
}
|
||||
Stmt::Assign {
|
||||
name,
|
||||
value,
|
||||
span,
|
||||
end_line,
|
||||
}
|
||||
}
|
||||
Stmt::Return { value, span } => Stmt::Return {
|
||||
value: substitute(value, &temps),
|
||||
span,
|
||||
},
|
||||
Stmt::Expr { value, span } => Stmt::Expr {
|
||||
value: substitute(value, &temps),
|
||||
span,
|
||||
},
|
||||
Stmt::Branch { arms, span } => Stmt::Branch {
|
||||
arms: arms
|
||||
.into_iter()
|
||||
.map(|a| BranchArm {
|
||||
condition: a.condition.map(|e| substitute(e, &temps)),
|
||||
body: block(a.body, temps.clone()),
|
||||
})
|
||||
.collect(),
|
||||
span,
|
||||
},
|
||||
Stmt::ForEach {
|
||||
item,
|
||||
collection,
|
||||
label,
|
||||
body,
|
||||
span,
|
||||
} => Stmt::ForEach {
|
||||
item,
|
||||
collection,
|
||||
label,
|
||||
body: block(body, temps.clone()),
|
||||
span,
|
||||
},
|
||||
Stmt::While {
|
||||
condition,
|
||||
body,
|
||||
span,
|
||||
} => Stmt::While {
|
||||
condition: substitute(condition, &temps),
|
||||
body: block(body, temps.clone()),
|
||||
span,
|
||||
},
|
||||
other => other,
|
||||
};
|
||||
out.push(s);
|
||||
}
|
||||
out
|
||||
}
|
||||
block(statements, std::collections::BTreeMap::new())
|
||||
}
|
||||
|
||||
fn statement(s: Stmt) -> Stmt {
|
||||
let span = Span::new(0, 0);
|
||||
match s {
|
||||
Stmt::Assign { name, value, .. } => Stmt::Assign {
|
||||
name,
|
||||
value: expr(value),
|
||||
span,
|
||||
end_line: 0,
|
||||
},
|
||||
Stmt::Return { value, .. } => Stmt::Return {
|
||||
value: expr(value),
|
||||
span,
|
||||
},
|
||||
Stmt::Call { call: c, .. } => Stmt::Expr {
|
||||
value: Expr::Call(call(c)),
|
||||
span,
|
||||
},
|
||||
Stmt::Expr { value, .. } => Stmt::Expr {
|
||||
value: expr(value),
|
||||
span,
|
||||
},
|
||||
Stmt::Branch { arms, .. } => Stmt::Branch {
|
||||
arms: arms
|
||||
.into_iter()
|
||||
.map(|a| BranchArm {
|
||||
condition: a.condition.map(expr),
|
||||
body: a.body.into_iter().map(statement).collect(),
|
||||
})
|
||||
.collect(),
|
||||
span,
|
||||
},
|
||||
Stmt::While {
|
||||
condition, body, ..
|
||||
} => Stmt::While {
|
||||
condition: expr(condition),
|
||||
body: body.into_iter().map(statement).collect(),
|
||||
span,
|
||||
},
|
||||
Stmt::ForEach {
|
||||
item,
|
||||
collection,
|
||||
body,
|
||||
..
|
||||
} => Stmt::ForEach {
|
||||
item,
|
||||
collection,
|
||||
body: body.into_iter().map(statement).collect(),
|
||||
span,
|
||||
label: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
fn quote(s: &str) -> String {
|
||||
serde_json::to_string(s).unwrap().replace('`', "\\`")
|
||||
}
|
||||
fn render(e: &Expr) -> Result<String> {
|
||||
Ok(match e {
|
||||
Expr::Literal(l) => match l {
|
||||
Literal::None => "None".into(),
|
||||
Literal::Bool(b) => if *b { "True" } else { "False" }.into(),
|
||||
Literal::Int(n) => n.to_string(),
|
||||
Literal::Num(n) => {
|
||||
let text = n.to_string();
|
||||
if text.contains('.') || text.contains(['e', 'E']) {
|
||||
text
|
||||
} else {
|
||||
format!("{text}.0")
|
||||
}
|
||||
}
|
||||
Literal::Text(s) => quote(s),
|
||||
},
|
||||
Expr::Var(n) => format!("`{n}`"),
|
||||
Expr::Interp(parts) => {
|
||||
let mut s = String::new();
|
||||
for p in parts {
|
||||
match p {
|
||||
InterpPart::Lit(t) => s.push_str(&t.replace('`', "\\`")),
|
||||
InterpPart::Var(v) => s.push_str(&format!("`{v}`")),
|
||||
InterpPart::Index { .. } => {
|
||||
anyhow::bail!("legacy interpolated index needs review")
|
||||
}
|
||||
}
|
||||
}
|
||||
serde_json::to_string(&s)?.replace("\\\\`", "\\`")
|
||||
}
|
||||
Expr::Call(c) => render_call(c)?,
|
||||
Expr::Unary { op, expr: e } => format!(
|
||||
"({}{})",
|
||||
match op {
|
||||
UnaryOp::Not => "not ",
|
||||
UnaryOp::Neg => "-",
|
||||
},
|
||||
render(e)?
|
||||
),
|
||||
Expr::Binary { op, left, right } => format!(
|
||||
"({} {} {})",
|
||||
render(left)?,
|
||||
match op {
|
||||
BinaryOp::Add => "+",
|
||||
BinaryOp::Sub => "-",
|
||||
BinaryOp::Mul => "*",
|
||||
BinaryOp::Div => "/",
|
||||
BinaryOp::Eq => "==",
|
||||
BinaryOp::Ne => "!=",
|
||||
BinaryOp::Lt => "<",
|
||||
BinaryOp::Le => "<=",
|
||||
BinaryOp::Gt => ">",
|
||||
BinaryOp::Ge => ">=",
|
||||
BinaryOp::And => "and",
|
||||
BinaryOp::Or => "or",
|
||||
},
|
||||
render(right)?
|
||||
),
|
||||
Expr::List(xs) => format!(
|
||||
"[{}]",
|
||||
xs.iter()
|
||||
.map(render)
|
||||
.collect::<Result<Vec<_>>>()?
|
||||
.join(", ")
|
||||
),
|
||||
Expr::Map(xs) => format!(
|
||||
"{{{}}}",
|
||||
xs.iter()
|
||||
.map(|(k, v)| Ok(format!("{}: {}", quote(k), render(v)?)))
|
||||
.collect::<Result<Vec<_>>>()?
|
||||
.join(", ")
|
||||
),
|
||||
Expr::Occluded {
|
||||
label,
|
||||
payload: Some(p),
|
||||
} => format!("[{}]({})", label.replace(']', "\\]"), render(p)?),
|
||||
Expr::Occluded { payload: None, .. } => "None".into(),
|
||||
_ => anyhow::bail!("expression needs manual rendering: {e:?}"),
|
||||
})
|
||||
}
|
||||
fn render_call(c: &CallExpr) -> Result<String> {
|
||||
let target = if let Some(r) = &c.receiver {
|
||||
format!("`{r}`.{}", c.callee)
|
||||
} else if let Some(p) = &c.path {
|
||||
p.join(".")
|
||||
} else {
|
||||
c.callee.clone()
|
||||
};
|
||||
let c = c.with_modifiers_expanded().map_err(anyhow::Error::msg)?;
|
||||
let args = c
|
||||
.args
|
||||
.iter()
|
||||
.map(|a| {
|
||||
Ok(match a {
|
||||
Arg::Positional(e) => render(e)?,
|
||||
Arg::Named { name, value } => format!("{name}={}", render(value)?),
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
if c.receiver.is_some() {
|
||||
Ok(format!("> {target} {} ", args.join(" ")))
|
||||
} else {
|
||||
Ok(format!("{target}({})", args.join(", ")))
|
||||
}
|
||||
}
|
||||
fn receiver_call(c: &CallExpr, f: &Function, imports: &[String]) -> CallExpr {
|
||||
let mut c = c.clone();
|
||||
if let Some(path) = &c.path {
|
||||
if path.len() == 2
|
||||
&& f.params.iter().any(|p| p.name == path[0])
|
||||
&& !imports.contains(&path[0])
|
||||
{
|
||||
c.receiver = Some(path[0].clone());
|
||||
c.path = None;
|
||||
}
|
||||
}
|
||||
c
|
||||
}
|
||||
fn render_value(v: &Expr, f: &Function, imports: &[String]) -> Result<String> {
|
||||
match v {
|
||||
Expr::Call(c) => render_call(&receiver_call(c, f, imports)),
|
||||
Expr::Occluded {
|
||||
label,
|
||||
payload: Some(v),
|
||||
} => Ok(format!(
|
||||
"[{}]({})",
|
||||
label.replace(']', "\\]"),
|
||||
render_value(v, f, imports)?
|
||||
)),
|
||||
other => render(other),
|
||||
}
|
||||
}
|
||||
// A qualified call through a parameter and its explicit receiver form resolve
|
||||
// the same object when that name is not an imported module binding.
|
||||
fn normalize_receiver_text(mut body: String, params: &Value, imports: &[String]) -> String {
|
||||
for p in params.as_array().unwrap() {
|
||||
let name = p["name"].as_str().unwrap();
|
||||
if imports.iter().any(|i| i == name) {
|
||||
continue;
|
||||
}
|
||||
let quoted = serde_json::to_string(name).unwrap();
|
||||
let pattern = format!(
|
||||
r#"path: Some\(\[{}, "[^"\n]+"\]\), receiver: None"#,
|
||||
regex::escape("ed)
|
||||
);
|
||||
let re = regex::Regex::new(&pattern).unwrap();
|
||||
body = re
|
||||
.replace_all(&body, format!("path: None, receiver: Some({quoted})"))
|
||||
.into_owned();
|
||||
}
|
||||
body
|
||||
}
|
||||
fn collect(fs: &[Function], prefix: &str, source: &str, imports: &[String], out: &mut Vec<Value>) {
|
||||
for f in fs {
|
||||
let name = if prefix.is_empty() {
|
||||
f.name.clone()
|
||||
} else {
|
||||
format!("{prefix}.{}", f.name)
|
||||
};
|
||||
let mut calls = Vec::new();
|
||||
marqdo::ast::walk_stmts(f, &mut |s| {
|
||||
if let Stmt::Call { call, span } = s {
|
||||
calls.push(json!({"line":span.line,"rendered":render_call(&receiver_call(call, f, imports)).ok(),"call":format!("{call:?}")}))
|
||||
}
|
||||
});
|
||||
let mut statements = Vec::new();
|
||||
marqdo::ast::walk_stmts(f, &mut |s| {
|
||||
let (kind, name, value, line, end) = match s {
|
||||
Stmt::Assign {
|
||||
name,
|
||||
value,
|
||||
span,
|
||||
end_line,
|
||||
} => (
|
||||
"assign",
|
||||
Some(name.as_str()),
|
||||
Some(value),
|
||||
span.line,
|
||||
*end_line,
|
||||
),
|
||||
Stmt::Return { value, span } => ("return", None, Some(value), span.line, span.line),
|
||||
Stmt::Expr { value, span } => ("expr", None, Some(value), span.line, span.line),
|
||||
Stmt::Call { call, span } => {
|
||||
statements.push(json!({"kind":"call", "line":span.line, "rendered":render_call(&receiver_call(call, f, imports)).ok(), "callee":call.callee, "path":call.path, "receiver":call.receiver}));
|
||||
return;
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
let mut inner = value;
|
||||
while let Some(Expr::Occluded {
|
||||
payload: Some(p), ..
|
||||
}) = inner
|
||||
{
|
||||
inner = Some(p);
|
||||
}
|
||||
let target = match inner {
|
||||
Some(Expr::Call(c)) => {
|
||||
Some(json!({"callee":c.callee,"path":c.path,"receiver":c.receiver}))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
statements.push(json!({"kind":kind,"name":name,"line":line,"end":end,"rendered":value.and_then(|v|render_value(v, f, imports).ok()),"target":target,"value":value.map(|v|format!("{v:?}"))}));
|
||||
});
|
||||
out.push(json!({"name":name,"short_name":f.name,"line":f.span.line,"level":f.level,"base":f.base,"receiver":function_uses_receiver(f),"params":f.params.iter().map(|p|json!({"name":p.name,"line":p.span.line,"default":p.default.as_ref().map(|e|format!("{:?}",expr(e.clone()))),"default_source":p.default.as_ref().and_then(|e|render(e).ok()),"type":f.contract.as_ref().and_then(|c|c.params.iter().find(|x|x.name==p.name)).map(|p|p.ty.name()).unwrap_or("any".into())})).collect::<Vec<_>>(),"returns":f.contract.as_ref().and_then(|c|c.returns.as_ref()).map(|r|r.ty.name()).unwrap_or("any".into()),"contract":f.contract.as_ref().map(|c|format!("{c:?}")),"body":format!("{:?}",canonical_statements(f.body.clone())),"calls":calls,"statements":statements,"narrative":marqdo::narrative_ratio::measure_source_units(source,std::slice::from_ref(f)).first().map(|r|r.ratio)}));
|
||||
collect(&f.children, &name, source, imports, out);
|
||||
}
|
||||
}
|
||||
fn difference(description: String, before: Value, after: Value) -> Value {
|
||||
use sha2::Digest;
|
||||
let digest = |value: Value| {
|
||||
format!(
|
||||
"{:x}",
|
||||
sha2::Sha256::digest(serde_json::to_vec(&value).unwrap())
|
||||
)
|
||||
};
|
||||
json!({"difference":description,"before":digest(before),"after":digest(after)})
|
||||
}
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let baseline = args
|
||||
.iter()
|
||||
.position(|x| x == "--compare")
|
||||
.map(|i| fs::read_to_string(&args[i + 1]))
|
||||
.transpose()?
|
||||
.map(|s| serde_json::from_str::<Value>(&s))
|
||||
.transpose()?;
|
||||
let original = args
|
||||
.iter()
|
||||
.position(|x| x == "--from")
|
||||
.map(|i| fs::read_to_string(&args[i + 1]))
|
||||
.transpose()?
|
||||
.map(|s| serde_json::from_str::<Value>(&s))
|
||||
.transpose()?;
|
||||
let mut paths = Vec::new();
|
||||
files(Path::new("lib"), &mut paths)?;
|
||||
files(Path::new("ext"), &mut paths)?;
|
||||
paths.sort();
|
||||
if let Some(input) = &original {
|
||||
paths.retain(|p| input.get(p.to_str().unwrap()).is_some());
|
||||
}
|
||||
let mut result = serde_json::Map::new();
|
||||
let mut differences = Vec::new();
|
||||
for path in paths {
|
||||
let key = path.to_str().context("UTF-8 library path")?;
|
||||
let source = if let Some(s) = original
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(key))
|
||||
.and_then(|m| m["source"].as_str())
|
||||
{
|
||||
s.to_owned()
|
||||
} else {
|
||||
fs::read_to_string(&path)?
|
||||
};
|
||||
let module = marqdo::parse::parse_source(&source).with_context(|| key.to_owned())?;
|
||||
let mut functions = Vec::new();
|
||||
let imports: Vec<_> = module
|
||||
.imports
|
||||
.iter()
|
||||
.map(|i| i.bind.clone())
|
||||
.chain(module.uses.iter().map(|i| i.bind.clone()))
|
||||
.collect();
|
||||
collect(&module.functions, "", &source, &imports, &mut functions);
|
||||
let reports = marqdo::narrative_ratio::measure_source_units(&source, &module.functions);
|
||||
for f in &mut functions {
|
||||
let report = reports.iter().find(|r| json!(r.line) == f["line"]).unwrap();
|
||||
f["narrative_chars"] = json!(report.narrative);
|
||||
f["code_chars"] = json!(report.total - report.narrative);
|
||||
f["narrative"] = json!(
|
||||
reports
|
||||
.iter()
|
||||
.find(|r| json!(r.line) == f["line"])
|
||||
.unwrap()
|
||||
.ratio
|
||||
);
|
||||
}
|
||||
if let Some(old) = baseline.as_ref().and_then(|b| b.get(key)) {
|
||||
for o in old["functions"].as_array().unwrap() {
|
||||
match functions.iter().find(|f| f["name"] == o["name"]) {
|
||||
None => differences.push(difference(
|
||||
format!("removed {key} {}", o["name"]),
|
||||
json!({"level":o["level"],"base":o["base"],"receiver":o["receiver"],"params":o["params"].as_array().unwrap().iter().map(|p|json!([p["name"],p["default"]])).collect::<Vec<_>>(),"body":o["body"]}),
|
||||
Value::Null,
|
||||
)),
|
||||
Some(n) => {
|
||||
for field in ["level", "base", "receiver", "body"] {
|
||||
let same = if field == "body" {
|
||||
normalize_receiver_text(
|
||||
n[field].as_str().unwrap().to_owned(),
|
||||
&o["params"],
|
||||
&imports,
|
||||
) == normalize_receiver_text(
|
||||
o[field].as_str().unwrap().to_owned(),
|
||||
&o["params"],
|
||||
&imports,
|
||||
)
|
||||
} else {
|
||||
n[field] == o[field]
|
||||
};
|
||||
if !same {
|
||||
differences.push(difference(format!("{key} {} changed {field}", o["name"]), o[field].clone(), n[field].clone()));
|
||||
}
|
||||
}
|
||||
let sig = |f: &Value| {
|
||||
f["params"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|p| json!([p["name"], p["default"]]))
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
if sig(n) != sig(o) {
|
||||
differences.push(difference(format!("{key} {} changed parameters", o["name"]),json!(sig(o)),json!(sig(n))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.insert(
|
||||
key.to_owned(),
|
||||
json!({"source": source, "functions": functions}),
|
||||
);
|
||||
}
|
||||
if let Some(i) = args.iter().position(|x| x == "--snapshot") {
|
||||
fs::write(&args[i + 1], serde_json::to_vec_pretty(&result)?)?;
|
||||
}
|
||||
println!(
|
||||
"{} library files, {} functions",
|
||||
result.len(),
|
||||
result
|
||||
.values()
|
||||
.map(|f| f["functions"].as_array().unwrap().len())
|
||||
.sum::<usize>()
|
||||
);
|
||||
if let Some(i) = args.iter().position(|x| x == "--differences") {
|
||||
fs::write(&args[i + 1], serde_json::to_vec_pretty(&differences)?)?;
|
||||
}
|
||||
if baseline.is_some() {
|
||||
let reviewed = args
|
||||
.iter()
|
||||
.position(|x| x == "--reviewed-fixes")
|
||||
.map(|i| fs::read_to_string(&args[i + 1]))
|
||||
.transpose()?
|
||||
.map(|text| serde_json::from_str::<Vec<Value>>(&text))
|
||||
.transpose()?
|
||||
.unwrap_or_default();
|
||||
let matches = |d: &Value, r: &Value| {
|
||||
["difference", "before", "after"]
|
||||
.iter()
|
||||
.all(|k| d[*k] == r[*k])
|
||||
&& r["reason"].as_str().is_some_and(|s| !s.trim().is_empty())
|
||||
};
|
||||
let unreviewed: Vec<_> = differences
|
||||
.iter()
|
||||
.filter(|d| !reviewed.iter().any(|r| matches(d, r)))
|
||||
.collect();
|
||||
let stale: Vec<_> = reviewed
|
||||
.iter()
|
||||
.filter(|r| !differences.iter().any(|d| matches(d, r)))
|
||||
.collect();
|
||||
println!("{} executable differences, {} exact reviewed fixes, {} unreviewed, {} stale review records",
|
||||
differences.len(),differences.len()-unreviewed.len(),unreviewed.len(),stale.len());
|
||||
for d in &unreviewed {
|
||||
println!("{}", d["difference"]);
|
||||
}
|
||||
if !unreviewed.is_empty() || !stale.is_empty() {
|
||||
anyhow::bail!(
|
||||
"review executable differences; only exact before/after digests are accepted"
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn json_literal_audit_rejects_duplicates_unsafe_numbers_and_trailing_data() {
|
||||
for text in [
|
||||
r#"{"x":1,"x":2}"#,
|
||||
r#"{"nested":{"x":1,"x":2}}"#,
|
||||
r#"{"x":9007199254740992}"#,
|
||||
r#"{} false"#,
|
||||
r#"{"x":NaN}"#,
|
||||
] {
|
||||
assert!(flat_json_record(text).is_none(), "{text}");
|
||||
}
|
||||
let value = flat_json_record(r#"{"z":[null,true,"a\nb"],"a":1}"#).unwrap();
|
||||
assert!(constant(&value));
|
||||
let Expr::Map(fields) = value else {
|
||||
panic!("map expected");
|
||||
};
|
||||
assert_eq!(fields[0].0, "a");
|
||||
assert_eq!(fields[1].0, "z");
|
||||
}
|
||||
#[test]
|
||||
fn only_supported_constant_builders_are_folded() {
|
||||
for code in [
|
||||
"unknown(text=\"{}\")",
|
||||
"json.parse(text=`input`)",
|
||||
"table.put(in=`input`, at=\"key\", value=1)",
|
||||
"text.str_join(xs=`rows`, sep=\"\\n\")",
|
||||
] {
|
||||
let Expr::Call(call) = marqdo::parse::expr::parse_expr(code).unwrap() else {
|
||||
panic!("call expected");
|
||||
};
|
||||
assert!(pure_literal_call(&call).is_none(), "{code}");
|
||||
}
|
||||
let Expr::Call(call) =
|
||||
marqdo::parse::expr::parse_expr("json.parse(text=\"{\\\"key\\\":null}\")").unwrap()
|
||||
else {
|
||||
panic!("call expected");
|
||||
};
|
||||
assert!(pure_literal_call(&call).is_some());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
# linalg-least-squares
|
||||
|
||||
Overdetermined least squares via `ext/linalg`: `factorize kind=qr`, `Qᵀb`, solve `R`, plus a heatmap SVG of `A`.
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo_plugin_linalg
|
||||
marqdo ext add linalg # once (re-run after rebuilding the plugin)
|
||||
marqdo run examples/linalg-least-squares/index.mq.md
|
||||
# optional: marqdo view examples/linalg-least-squares/
|
||||
```
|
||||
|
||||
Design: [ext-linalg.md](../../doc/design/ext-linalg.md) · sibling: [linalg-svd](../linalg-svd/).
|
||||
@@ -1,42 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Least squares via lstsq
|
||||
description: Overdetermined Ax≈b with ext/linalg lstsq + heatmap.
|
||||
import:
|
||||
la: ext/linalg/linalg.mq.md
|
||||
math: lib/math.mq.md
|
||||
---
|
||||
|
||||
# Least squares from a runnable document
|
||||
|
||||
|
||||
Fit a line through three points with an overdetermined `A x ≈ b` using `lstsq` (QR path). A heatmap makes the design matrix visible in `view`.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
`A` =
|
||||
$$
|
||||
\begin{bmatrix}1&0\\1&1\\1&2\end{bmatrix}
|
||||
$$
|
||||
|
||||
`b` =
|
||||
$$
|
||||
\begin{pmatrix}1\\2\\2\end{pmatrix}
|
||||
$$
|
||||
|
||||
We first **A = [Compute A](la.from_formula(formula=`A`))** for the next step.
|
||||
We first **b = [Compute b](la.from_formula(formula=`b`))** for the next step.
|
||||
|
||||
We first **_ = [Compute _](la.draw(factor=`A`, kind="heatmap", theme="light", path="ls-heatmap.svg"))** for the next step.
|
||||
|
||||
We first **ls = [Compute ls](la.lstsq(a=`A`, b=`b`))** for the next step.
|
||||
We first **x = [x](access(`ls`, "x"))** for the next step.
|
||||
We first **resid = [residual_fro](access(`ls`, "residual_fro"))** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`x`)**.
|
||||
We now **[Display this step's result](> print text=`resid`)**.
|
||||
We now **[Display this step's result](> print text="ls-ok")**.
|
||||
@@ -1,12 +0,0 @@
|
||||
# linalg-svd
|
||||
|
||||
Dense SVD via `ext/linalg`: singular values + structure / hinton SVG.
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo_plugin_linalg
|
||||
marqdo ext add linalg
|
||||
marqdo run examples/linalg-svd/index.mq.md
|
||||
# optional: marqdo view examples/linalg-svd/
|
||||
```
|
||||
|
||||
Design: [ext-linalg.md](../../doc/design/ext-linalg.md) · sibling: [linalg-least-squares](../linalg-least-squares/).
|
||||
@@ -1,32 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: SVD structure demo
|
||||
description: Diagonal SVD + structure SVG via ext/linalg.
|
||||
import:
|
||||
la: ext/linalg/linalg.mq.md
|
||||
---
|
||||
|
||||
# SVD from a runnable document
|
||||
|
||||
|
||||
A diagonal matrix has singular values on the diagonal. Prefer matrix values and methods; `factorize` / `draw` stay explicit for teaching SVGs.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
`M` =
|
||||
$$
|
||||
\begin{bmatrix}4&0\\0&2\end{bmatrix}
|
||||
$$
|
||||
|
||||
We first **M = [Compute M](la.from_formula(formula=`M`))** for the next step.
|
||||
We first **f = [Compute f](la.factorize(matrix=`M`, kind="svd"))** for the next step.
|
||||
We first **S = [S](access(`f`, "S"))** for the next step.
|
||||
We first **_ = [Compute _](la.draw(factor=`f`, kind="svd", theme="light", path="svd-structure.svg"))** for the next step.
|
||||
We first **hm = [Compute hm](la.draw(factor=`M`, kind="hinton", path="svd-hinton.svg"))** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`S`)**.
|
||||
We now **[Display this step's result](> print text="svd-ok")**.
|
||||
@@ -1,11 +0,0 @@
|
||||
# linalg-transpose
|
||||
|
||||
Formula-document example: declare symbols with a GFM table, check \((AB)^\top = B^\top A^\top\) via `ascii` (auto-simplify).
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo_plugin_linalg
|
||||
marqdo ext add linalg
|
||||
marqdo run examples/linalg-transpose/index.mq.md
|
||||
```
|
||||
|
||||
Design: [ext-linalg-formula-doc.md](../../doc/design/ext-linalg-formula-doc.md).
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Transpose identity (formula document)
|
||||
description: (AB)^T = B^T A^T as a runnable lecture fragment.
|
||||
import:
|
||||
la: ext/linalg/linalg.mq.md
|
||||
---
|
||||
|
||||
# Transpose reverses products
|
||||
|
||||
|
||||
Declare shapes in a table, form \(P = AB\), then check \((AB)^\top = B^\top A^\top\) by running the document.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
`shapes` =
|
||||
|
||||
| @ | name | rows | cols |
|
||||
|---|------|------|------|
|
||||
| 1 | A | 2 | 3 |
|
||||
| 2 | B | 3 | 2 |
|
||||
|
||||
We first **env = [Compute env](la.declare(table=`shapes`))** for the next step.
|
||||
We first **A = [A](access(`env`, "A"))** for the next step.
|
||||
We first **B = [B](access(`env`, "B"))** for the next step.
|
||||
We first **P = (`A` * `B`)** for the next step.
|
||||
We first **t = [Compute t](> `P`.T_ascii)** for the next step.
|
||||
We now **[Display this step's result](> print text=`t`)**.
|
||||
1. `t` == "B^T*A^T"
|
||||
We now **[Display this step's result](> print text="identity-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="identity-fail")**.
|
||||
@@ -1,109 +0,0 @@
|
||||
# 链接语法示例:两文档,一次类调用
|
||||
|
||||
这个目录是 [链接语法设计声明](../../doc/design/link-syntax.md) 的**目标示例**:
|
||||
|
||||
> `[李白的出生年份](李白.李白的出生年份)`
|
||||
> 不是新的语法:`[]` 是 Markdown 链接的描述,`()` 是已有调用;
|
||||
> `# 李白` 是类,`## 李白的出生年份` 是函数,`李白.李白的出生年份` 是类调用。
|
||||
|
||||
## 文件
|
||||
|
||||
| 文件 | 作用 | v2.0.0 可跑 | v2.1 目标 |
|
||||
|------|------|-------------|-----------|
|
||||
| `libai.mq.md` | 知识文档:`# 李白` → `## 李白的出生年份` → `*701*` | ✅ | ✅ |
|
||||
| `main.mq.md` | 用户原始示例:正文链接 + 类调用 | ❌(安静无输出) | ✅ view 显示;`run` 加 print 输出 |
|
||||
| `main.compat.mq.md` | 当前等价写法:`import` + 实例 + 本地链接 | ✅(输出 `701`) | ✅ |
|
||||
| `expected-link-info.json` | 目标 `LinkInfo` 形状 | — | — |
|
||||
| `links.lock.yaml` | 可选锁文件形状 | — | — |
|
||||
|
||||
> **v2.0.0 的 `main.mq.md` 不会报错,也不会有输出**——因为:
|
||||
> 1. 正文链接默认不执行(叙述默认安全);
|
||||
> 2. `李白.李白的出生年份` 目前被当成变量/实例方法路径,类调用还没实现。
|
||||
>
|
||||
> v2.1 的目标是:`view` 显示这个链接的目标、类、函数、签名、值;`check` 返回 LinkInfo;
|
||||
> 要终端输出,就在代码链接里加 `print`。
|
||||
|
||||
## 今天可跑
|
||||
|
||||
```bash
|
||||
marqdo run examples/link-syntax/main.compat.mq.md
|
||||
# 701
|
||||
```
|
||||
|
||||
`main.compat.mq.md` 用当前能力完成了同一件事:
|
||||
|
||||
```markdown
|
||||
---
|
||||
markup: occlusion
|
||||
import libai:libai.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**li = > libai.李白**
|
||||
**year = [李白的出生年份](li.李白的出生年份())**
|
||||
> print text=`year`
|
||||
```
|
||||
|
||||
- `import` 绑定知识文档;
|
||||
- `> libai.李白` 构造对象(当前 `#` 是对象/类型);
|
||||
- `li.李白的出生年份()` 调用实例方法;
|
||||
- `[]()` 把调用包成一句人话。
|
||||
|
||||
这正是 v2.0.0 的「实例方法」路径;v2.1 要把 `##` 恢复为**类函数**,
|
||||
让 `李白.李白的出生年份` 直接调用,去掉 `import`/实例两步。
|
||||
|
||||
## 目标形式
|
||||
|
||||
`main.mq.md`:
|
||||
|
||||
```markdown
|
||||
# main
|
||||
用户想要知道李白的出生年份,我们要告诉用户[李白的出生年份](李白.李白的出生年份)
|
||||
```
|
||||
|
||||
v2.1 期望:
|
||||
|
||||
```bash
|
||||
$ marqdo run examples/link-syntax/main.mq.md
|
||||
# 无输出(正文链接不执行;加 print 才有输出)
|
||||
|
||||
$ marqdo check examples/link-syntax/main.mq.md --json
|
||||
{"code":"link.ok", ...}
|
||||
```
|
||||
|
||||
`view` 期望:
|
||||
|
||||
```text
|
||||
用户想要知道李白的出生年份,我们要告诉用户 701。
|
||||
↑
|
||||
悬浮:李白的出生年份 → 李白.李白的出生年份
|
||||
class 李白 · function · () -> number · value 701
|
||||
```
|
||||
|
||||
要终端输出:
|
||||
|
||||
```markdown
|
||||
# main
|
||||
|
||||
**year = [李白的出生年份](李白.李白的出生年份)**
|
||||
> print text=`year`
|
||||
```
|
||||
|
||||
```bash
|
||||
$ marqdo run examples/link-syntax/main.mq.md
|
||||
701
|
||||
```
|
||||
|
||||
## 为什么是 `李白.李白的出生年份`
|
||||
|
||||
- `# 李白` 是类;
|
||||
- `## 李白的出生年份` 是类下的函数;
|
||||
- `李白.李白的出生年份` 是**类调用**;
|
||||
- `[]` 是描述,`()` 是已有调用;没有新语法,没有协议前缀,没有别名开关。
|
||||
|
||||
## 相关
|
||||
|
||||
- 设计声明:[doc/design/link-syntax.md](../../doc/design/link-syntax.md)
|
||||
- 证据复核:[doc/research/occlusion-vs-executable-knowledge-2026-10.md](../../doc/research/occlusion-vs-executable-knowledge-2026-10.md)
|
||||
- 旧遮蔽设计:[doc/design/occlusion-syntax.md](../../doc/design/occlusion-syntax.md)
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"label": "李白的出生年份",
|
||||
"source": {
|
||||
"file": "main.mq.md",
|
||||
"line": 2,
|
||||
"col": 26
|
||||
},
|
||||
"target": {
|
||||
"class": "李白",
|
||||
"function": "李白的出生年份",
|
||||
"doc": "libai.mq.md",
|
||||
"kind": "class_function",
|
||||
"signature": {
|
||||
"params": [],
|
||||
"returns": "number"
|
||||
},
|
||||
"instance_only": false
|
||||
},
|
||||
"status": "ok",
|
||||
"value": null,
|
||||
"fingerprint": "sha256:<target-body-hash>"
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: Fact
|
||||
id: libai
|
||||
title: 李白
|
||||
description: 李白知识文档:一个可被其他文档链接调用的知识单元
|
||||
status: stable
|
||||
---
|
||||
|
||||
# 李白
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 供下述方法复用的对象或类型命名空间;直接调用所需的子函数。 |
|
||||
|
||||
这个文档存储了李白的信息。
|
||||
|
||||
## 李白的出生年份
|
||||
|
||||
李白的出生年份是公元 701 年。
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| 701 | number | 公元 701 年 |
|
||||
|
||||
完成上述步骤后,返回*701*。
|
||||
@@ -1,9 +0,0 @@
|
||||
version: 1
|
||||
generated_by: marqdo/2.1.0
|
||||
links:
|
||||
- from: main.mq.md
|
||||
label: 李白的出生年份
|
||||
to: libai.mq.md::李白.李白的出生年份
|
||||
kind: class_function
|
||||
signature: "() -> number"
|
||||
fingerprint: sha256:<target-body-hash>
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
import:
|
||||
libai: libai.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
**li = > libai.李白**
|
||||
**year = [李白的出生年份](li.李白的出生年份())**
|
||||
> print text=`year`
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
用户想要知道李白的出生年份,我们要告诉用户[李白的出生年份](李白.李白的出生年份)
|
||||
@@ -1,40 +0,0 @@
|
||||
# examples/marqdo-blog
|
||||
|
||||
Marqdo **Web Artifact** blog (ADR 0007).
|
||||
|
||||
## Layout
|
||||
|
||||
```text
|
||||
index.mq.md # type: web · / · data_source: posts
|
||||
pages/about.mq.md # 类型: 网页 · /about
|
||||
pages/post.mq.md # type: web · /post/{slug} · data_where
|
||||
api/ping.mq.md # type: endpoint · GET /api/ping
|
||||
api/echo.mq.md # type: endpoint · POST /api/echo
|
||||
db/posts.mq.md # ext/data schema + seed + open
|
||||
public/ # static (mounted at /static)
|
||||
serve.mq.md # web.serve + db open
|
||||
smoke.sh # curl checks against a running serve
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
从仓库根使用当前 CLI 和开发手册准备原生插件,再调用启动函数:
|
||||
|
||||
```sh
|
||||
target/debug/marqdo call skills/marqdo-dev/index.mq.md prepare_web --effects plugin --fs-root . --require-ok --json
|
||||
target/debug/marqdo call examples/marqdo-blog/serve.mq.md main --effects plugin,fs.write,network.write --fs-root examples/marqdo-blog --require-ok --json
|
||||
```
|
||||
|
||||
默认数据库按授权站点根解析到 data/blog.db,重启保留已有文章。准备工程插件见开发入口的 prepare_engineering;验收使用独占副本,不删除现有数据库。
|
||||
|
||||
|
||||
| Path | Artifact |
|
||||
|------|----------|
|
||||
| `/` | Document home + post cards |
|
||||
| `/about` | ZH Document |
|
||||
| `/post/{slug}` | Document detail |
|
||||
| `/api/ping` | Endpoint JSON |
|
||||
| `/api/echo` | Endpoint JSON echo |
|
||||
| `/static/*` | public assets |
|
||||
|
||||
Design: [ext-web-artifact.md](../../doc/design/ext-web-artifact.md).
|
||||
@@ -1,30 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: endpoint
|
||||
method: POST
|
||||
path: /api/echo
|
||||
request: json
|
||||
response: json
|
||||
auth: none
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Result or browser effect record assembled below |
|
||||
|
||||
Echo request fields bound via Artifact Metadata (`arg` overlays).
|
||||
|
||||
We first **msg = `message`** for the next step.
|
||||
1. not `msg`
|
||||
We first **msg = ""** for the next step.
|
||||
2. *
|
||||
|
||||
`out` =
|
||||
|
||||
| ok | message |
|
||||
|----|---------|
|
||||
| True | `msg` |
|
||||
|
||||
After these steps, return *out*.
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: endpoint
|
||||
method: GET
|
||||
path: /api/ping
|
||||
request: none
|
||||
response: json
|
||||
auth: none
|
||||
description: Health ping — documentation is the API (ADR 0007).
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Result or browser effect record assembled below |
|
||||
|
||||
`out` =
|
||||
|
||||
| ok | service |
|
||||
|----|---------|
|
||||
| True | marqdo-blog |
|
||||
|
||||
After these steps, return *out*.
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
## 页脚
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
站点页脚。放版权与概览链接。
|
||||
|
||||
`页脚` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| © 2026 Marqdo 博客 | / | |
|
||||
| 关于 | /about | |
|
||||
| 后台 | /admin | |
|
||||
|
||||
After these steps, return *页脚*.
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
## 导航
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
站点顶部导航。首项是站点名(渐变 Logo 由主题 CSS 处理),`后台` 指向需要登录的 `/admin`。
|
||||
|
||||
`导航` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| Marqdo 博客 | / | |
|
||||
| 首页 | / | |
|
||||
| 标签 | /tags | |
|
||||
| 关于 | /about | |
|
||||
| 后台 | /admin | |
|
||||
|
||||
After these steps, return *导航*.
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
## 侧栏
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
右侧归档面板:文章入口、标签、实时小部件。
|
||||
|
||||
`侧栏` =
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| 全部文章 | / | |
|
||||
| 标签归档 | /tags | |
|
||||
| 关于本站 | /about | |
|
||||
| 发布文章 | /admin/new | |
|
||||
| 实时终端 | /#live | |
|
||||
|
||||
After these steps, return *侧栏*.
|
||||
@@ -1,61 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 当前 Artifact 博客数据调用手册
|
||||
import:
|
||||
document: lib/document.mq.md
|
||||
data: ext/data/db.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
本文件负责可调用的说明与编排,[posts.tables.md](posts.tables.md)负责可独立阅读的 Markdown 常量。调用时把 --fs-root 指向 examples/marqdo-blog,读取需要 fs.read;连接数据库或编译样式时还需要 plugin。
|
||||
|
||||
## schema
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
当前站点的文章字段包括标题、slug、摘要、正文、标签和创建日期。原生数据库初始化器负责 id;本结构保留当前自动列表与详情页所需字段。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [posts.tables.md](posts.tables.md#schema);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取schema的实际 Markdown 常量](document.read_table(path="db/posts.tables.md", title="schema"))*.
|
||||
|
||||
## seed
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
两篇当前站点的起始文章保留稳定 slug、内容与日期。只有调用 open 且文章表为空时才插入;读取种子本身不会改变现有文章。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [posts.tables.md](posts.tables.md#seed);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取seed的实际 Markdown 常量](document.read_table(path="db/posts.tables.md", title="seed"))*.
|
||||
|
||||
## open
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| url | any | None | None 使用授权站点根内 data/blog.db;验收可传独占绝对 URI |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 已初始化且保留原有文章的实际数据库资源 |
|
||||
|
||||
使用`url`=None,以 examples/marqdo-blog 为 --fs-root 授予 fs.write 与 plugin。默认路径先通过固有能力创建 data 目录,再解析真实绝对文件地址,避免被插件模块位置或终端工作目录影响。显式 SQLite 路径同样经过根目录和符号链接检查;其他受支持后端按其连接契约执行,文件授权不限制外部数据库服务。
|
||||
|
||||
字段与种子由原生 Markdown 读取器保留字面类型。初始化只确保文章表存在,再查一行判断是否已有业务数据;只为空表插入原来的两条记录。已有或部分填充的表都原样保留,这不是列迁移器,也不会删除或重排用户文章。连接、结构或插入失败应停止启动,不能继续监听并声称数据库已经准备好。
|
||||
|
||||
隔离验收使用调用者拥有的临时站点副本,保留同一资源继续查询与写入。进程退出、连接关闭后再清理该目录,不对示例的现有 data 目录执行重置。读取结构或种子本身不写库,写入只发生在这份明确初始化流程里。
|
||||
|
||||
1. `url` == None
|
||||
我们 **[创建本站默认数据目录](fs.make_dirs(path="data"))**、**file = [按原生授权根解析数据库文件](fs.resolve(path="data/blog.db"))** 和 **url = "sqlite:" + file**。
|
||||
1. [明确选择 SQLite 后端](text.starts_with(text=`url`, prefix="sqlite:"))
|
||||
我们 **file = [取出实际 SQLite 地址](text.replace(text=`url`, old="sqlite:", new="", count=1))**、**file = [检查根目录和符号链接边界](fs.resolve(path=`file`))** 和 **url = "sqlite:" + file**。
|
||||
我们 **store = [连接实际选择的数据库](data.db(url=`url`))** 和 **fields = [读取当前文章结构](schema())**。
|
||||
接着 **[确保文章结构但不清空数据](> `store`.init name="posts" fields=`fields`)** 和 **existing = [检查是否已有业务文章](> `store`.select table="posts" limit=1)**。
|
||||
1. not `existing`
|
||||
我们 **rows = [读取空表使用的原始记录](seed())** 和 **[只初始化空表](> `store`.insert table="posts" rows=`rows`)**。
|
||||
准备完成后返回 *store*,供当前服务流程继续使用。
|
||||
@@ -1,25 +0,0 @@
|
||||
# 当前 Artifact 博客数据
|
||||
|
||||
这里保存原生字面 GFM 数据。调用函数通过 document.read_table 读取所选章节;不会执行本文件中的说明或示例。
|
||||
|
||||
## schema
|
||||
|
||||
当前站点的文章字段包括标题、slug、摘要、正文、标签和创建日期。原生数据库初始化器负责 id;本结构保留当前自动列表与详情页所需字段。
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| title | text | False |
|
||||
| slug | text | False |
|
||||
| summary | text | True |
|
||||
| content | text | True |
|
||||
| tag | text | True |
|
||||
| created_at | text | True |
|
||||
|
||||
## seed
|
||||
|
||||
两篇当前站点的起始文章保留稳定 slug、内容与日期。只有调用 open 且文章表为空时才插入;读取种子本身不会改变现有文章。
|
||||
|
||||
| title | slug | summary | content | tag | created_at |
|
||||
|-------|------|---------|---------|-----|------------|
|
||||
| Hello Marqdo | hello | Welcome | Hello — executable documents. | intro | 2026-09-01 |
|
||||
| Artifact Web | artifact-web | Document first | Pages are mq.md files. | design | 2026-09-28 |
|
||||
@@ -1,44 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 博客表结构调用手册
|
||||
import:
|
||||
document: lib/document.mq.md
|
||||
---
|
||||
|
||||
本文件负责可调用的说明与编排,[schema.tables.md](schema.tables.md)负责可独立阅读的 Markdown 常量。调用时把 --fs-root 指向 examples/marqdo-blog,读取需要 fs.read;连接数据库或编译样式时还需要 plugin。
|
||||
|
||||
## posts
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
文章结构保留 id、标题、slug、摘要、Markdown 正文、主标签和时间字段。slug 对应文章详情路由;可空声明控制存储约束,路由授权仍由端点或门禁负责。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [schema.tables.md](schema.tables.md#posts);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取posts的实际 Markdown 常量](document.read_table(path="db/schema.tables.md", title="posts"))*.
|
||||
|
||||
## tags
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
标签结构保留显示名称与稳定 slug。显示文字可以改动,路由和文章主标签应继续引用稳定标识;唯一索引需要在正式迁移中明确声明。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [schema.tables.md](schema.tables.md#tags);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取tags的实际 Markdown 常量](document.read_table(path="db/schema.tables.md", title="tags"))*.
|
||||
|
||||
## post_tags
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
关联结构保留文章与标签标识。种子关系依赖空数据库中预期的插入顺序;向已有用户库导入时应先映射真实 id,不能直接复用演示序号。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [schema.tables.md](schema.tables.md#post_tags);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取post_tags的实际 Markdown 常量](document.read_table(path="db/schema.tables.md", title="post_tags"))*.
|
||||
@@ -1,38 +0,0 @@
|
||||
# 博客表结构
|
||||
|
||||
这里保存原生字面 GFM 数据。调用函数通过 document.read_table 读取所选章节;不会执行本文件中的说明或示例。
|
||||
|
||||
## posts
|
||||
|
||||
文章结构保留 id、标题、slug、摘要、Markdown 正文、主标签和时间字段。slug 对应文章详情路由;可空声明控制存储约束,路由授权仍由端点或门禁负责。
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| title | text | false |
|
||||
| slug | text | false |
|
||||
| summary | text | true |
|
||||
| content | text | true |
|
||||
| tag | text | true |
|
||||
| created_at | text | true |
|
||||
| updated_at | text | true |
|
||||
|
||||
## tags
|
||||
|
||||
标签结构保留显示名称与稳定 slug。显示文字可以改动,路由和文章主标签应继续引用稳定标识;唯一索引需要在正式迁移中明确声明。
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| name | text | false |
|
||||
| slug | text | false |
|
||||
|
||||
## post_tags
|
||||
|
||||
关联结构保留文章与标签标识。种子关系依赖空数据库中预期的插入顺序;向已有用户库导入时应先映射真实 id,不能直接复用演示序号。
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| post_id | integer | false |
|
||||
| tag_id | integer | false |
|
||||
@@ -1,44 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 博客演示种子调用手册
|
||||
import:
|
||||
document: lib/document.mq.md
|
||||
---
|
||||
|
||||
本文件负责可调用的说明与编排,[seed.tables.md](seed.tables.md)负责可独立阅读的 Markdown 常量。调用时把 --fs-root 指向 examples/marqdo-blog,读取需要 fs.read;连接数据库或编译样式时还需要 plugin。
|
||||
|
||||
## posts
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
六篇演示文章覆盖文档、路由、原生集合、实时通信、会话和数据库。日期用于稳定排序,正文保持 Markdown 数据;这些常量不会自行写入数据库。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [seed.tables.md](seed.tables.md#posts);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取posts的实际 Markdown 常量](document.read_table(path="db/seed.tables.md", title="posts"))*.
|
||||
|
||||
## tags
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
演示标签保留原始顺序与 slug,便于在独立空库中验证文章关联。读取这些行没有插入或删除效果;现有用户标签应由显式迁移管理。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [seed.tables.md](seed.tables.md#tags);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取tags的实际 Markdown 常量](document.read_table(path="db/seed.tables.md", title="tags"))*.
|
||||
|
||||
## post_tags
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
关联行保持文章与标签的演示对应关系。它们适用于按同一顺序初始化的空库;已有数据需要重新映射 id,读取函数不会清空或重建任何表。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [seed.tables.md](seed.tables.md#post_tags);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取post_tags的实际 Markdown 常量](document.read_table(path="db/seed.tables.md", title="post_tags"))*.
|
||||
@@ -1,45 +0,0 @@
|
||||
# 博客演示种子
|
||||
|
||||
这里保存原生字面 GFM 数据。调用函数通过 document.read_table 读取所选章节;不会执行本文件中的说明或示例。
|
||||
|
||||
## posts
|
||||
|
||||
六篇演示文章覆盖文档、路由、原生集合、实时通信、会话和数据库。日期用于稳定排序,正文保持 Markdown 数据;这些常量不会自行写入数据库。
|
||||
|
||||
| 行 | title | slug | summary | content | tag | created_at | updated_at |
|
||||
|----|-------|------|---------|---------|-----|------------|------------|
|
||||
| 1 | 你好,Marqdo 博客 | hello-marqdo | 用 Marqdo 的 web 扩展库搭建的第一个博客。表格即组件、文档即代码。 | 这是一篇介绍博客系统的文章。它由 Marqdo 脚本在启动时写入 SQLite,通过 ext/web 的组件装配渲染成页面。 | marqdo | 2026-08-01 | 2026-08-02 |
|
||||
| 2 | 动态路由与文章详情 | dynamic-routing | 如何用 /post/{slug} 动态路由渲染单篇文章。 | 本文说明动态路由机制:作者面注册带 {slug} 占位符的路由,请求时把路径参数注入页面查询条件。 | web | 2026-08-05 | 2026-08-05 |
|
||||
| 3 | 用 GFM 表格表达数据 | gfm-tables | Marqdo 的字典操作不依赖 json 库,GFM 表格即可完成。 | 表格即数据、表格即组件。这篇文章展示如何在 .mq.md 里用横向表写种子数据,用脚注索引读取字段。 | tutorial | 2026-08-10 | 2026-08-11 |
|
||||
| 4 | WebSocket 实时小部件 | websocket-live | 给博客加一个实时回显的 WebSocket 端点。 | 通过 app.路由实时 注册 /live 端点,配合 public/live.js 在首页显示实时连接状态。 | realtime | 2026-08-15 | 2026-08-15 |
|
||||
| 5 | 会话与登录鉴权 | session-auth | 后台用 session 门禁保护,只有登录用户能发布文章。 | 用 app.鉴权 配置管理员用户表,/admin 下的 CRUD 页面都需要有效会话。 | web | 2026-08-18 | 2026-08-20 |
|
||||
| 6 | 数据库与 CRUD | database-crud | 博客的文章、标签、关联全部由 SQLite 支撑。 | db.初始化 建表、db.插入 写种子、后台表单增删改。文章与标签通过 post_tags 关联。 | database | 2026-08-20 | 2026-08-21 |
|
||||
|
||||
## tags
|
||||
|
||||
演示标签保留原始顺序与 slug,便于在独立空库中验证文章关联。读取这些行没有插入或删除效果;现有用户标签应由显式迁移管理。
|
||||
|
||||
| 行 | name | slug |
|
||||
|----|------|------|
|
||||
| 1 | Marqdo | marqdo |
|
||||
| 2 | Web | web |
|
||||
| 3 | 教程 | tutorial |
|
||||
| 4 | 数据库 | database |
|
||||
| 5 | 实时 | realtime |
|
||||
|
||||
## post_tags
|
||||
|
||||
关联行保持文章与标签的演示对应关系。它们适用于按同一顺序初始化的空库;已有数据需要重新映射 id,读取函数不会清空或重建任何表。
|
||||
|
||||
| 行 | post_id | tag_id |
|
||||
|----|---------|--------|
|
||||
| 1 | 1 | 1 |
|
||||
| 2 | 1 | 2 |
|
||||
| 3 | 2 | 2 |
|
||||
| 4 | 3 | 1 |
|
||||
| 5 | 3 | 3 |
|
||||
| 6 | 4 | 5 |
|
||||
| 7 | 4 | 2 |
|
||||
| 8 | 5 | 2 |
|
||||
| 9 | 6 | 4 |
|
||||
| 10 | 6 | 1 |
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: web
|
||||
title: Marqdo 博客
|
||||
route: /
|
||||
method: GET
|
||||
data_source: posts
|
||||
data_order: -created_at
|
||||
description: >-
|
||||
Document Artifact 首页(ADR 0007):正文即文档,列表来自 data_source。
|
||||
导入:
|
||||
网页: ext/web/网页.mq.md
|
||||
---
|
||||
|
||||
# Marqdo 博客
|
||||
|
||||
可执行文档即网页。本站用 Artifact Metadata 声明路由;文章列表由 `data_source: posts` 在服务时加载。
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
类型: 网页
|
||||
路由: /about
|
||||
方法: GET
|
||||
标题: 关于
|
||||
---
|
||||
|
||||
# 关于 Marqdo
|
||||
|
||||
|
||||
Marqdo 是可执行文档语言:文档即程序,程序即知识。
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: web
|
||||
title: Post
|
||||
route: /post/{slug}
|
||||
method: GET
|
||||
data_source: posts
|
||||
data_where: slug={slug}
|
||||
description: Dynamic Document route — body is the article shell; data from Resource.
|
||||
---
|
||||
|
||||
# Post
|
||||
|
||||
Article page for `{slug}`. List and detail data are provided by `ext/data` at serve time when `data_source` is set on the Artifact.
|
||||
@@ -1,2 +0,0 @@
|
||||
‰PNG
|
||||
|
||||
|
Before Width: | Height: | Size: 8 B |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#1a5f4a"/><text x="16" y="22" text-anchor="middle" font-size="16" font-family="Georgia,serif" fill="#f4f7f5">M</text></svg>
|
||||
|
Before Width: | Height: | Size: 226 B |
@@ -1,40 +0,0 @@
|
||||
// 实时 WebSocket 小部件(连接 /live 端点)。
|
||||
// 连接 ws://host/live,发送输入,展示服务器回显。
|
||||
(function () {
|
||||
var out = document.getElementById("live-out");
|
||||
var input = document.getElementById("live-msg");
|
||||
var btn = document.getElementById("live-send");
|
||||
var status = document.getElementById("live-status");
|
||||
if (!out || !input || !btn || !status) return;
|
||||
|
||||
var proto = location.protocol === "https:" ? "wss" : "ws";
|
||||
var ws = new WebSocket(proto + "://" + location.host + "/live");
|
||||
status.textContent = "connecting…";
|
||||
|
||||
ws.onopen = function () {
|
||||
status.textContent = "connected";
|
||||
btn.disabled = false;
|
||||
};
|
||||
ws.onmessage = function (ev) {
|
||||
var p = document.createElement("p");
|
||||
p.textContent = "echo: " + ev.data;
|
||||
out.appendChild(p);
|
||||
out.scrollTop = out.scrollHeight;
|
||||
};
|
||||
ws.onclose = function () {
|
||||
status.textContent = "closed";
|
||||
btn.disabled = true;
|
||||
};
|
||||
ws.onerror = function () {
|
||||
status.textContent = "error";
|
||||
btn.disabled = true;
|
||||
};
|
||||
|
||||
btn.onclick = function () {
|
||||
var m = input.value.trim();
|
||||
if (m) ws.send(m);
|
||||
};
|
||||
input.addEventListener("keydown", function (e) {
|
||||
if (e.key === "Enter") btn.onclick();
|
||||
});
|
||||
})();
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#1a5f4a"/><text x="16" y="22" text-anchor="middle" font-size="16" font-family="Georgia,serif" fill="#f4f7f5">M</text></svg>
|
||||
|
Before Width: | Height: | Size: 226 B |
@@ -1,28 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Callable Artifact blog launcher
|
||||
import:
|
||||
web: ext/web/web.mq.md
|
||||
posts: db/posts.mq.md
|
||||
---
|
||||
|
||||
This launcher starts the ordinary Markdown/data-source Documents and declared JSON Endpoints. It owns data preparation and listener lifetime; the index remains readable page content. From the checkout use marqdo call examples/marqdo-blog/serve.mq.md main with --effects plugin,fs.write,network.write and --fs-root examples/marqdo-blog.
|
||||
|
||||
## main
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| root | text | "examples/marqdo-blog" | Explicit discovery root relative to the checkout |
|
||||
| port | number | 18081 | Local loopback listen port |
|
||||
| url | any | None | None uses the retained site-root database; tests supply an owned URI |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Blocking listener after database preparation and declared-route discovery |
|
||||
|
||||
Use `root`="examples/marqdo-blog", `port`=18081 and `url`=None from the checkout. The ordinary callable heading makes this workflow available through call, while Document bodies remain Markdown. Native filesystem resolution keeps SQLite under the actual granted site root, independently of the terminal working directory. Existing articles are retained and only an empty table receives demonstration rows.
|
||||
|
||||
Discovery follows the actual route metadata for Home, About, slug detail, Ping and Echo. Ordinary Documents keep their existing request-time data-source behavior. Starting this workflow is an explicit local network action, not a side effect of reading a library. The listener blocks until the supervising caller stops the process; no detached daemon or database reset is implied.
|
||||
|
||||
We **store = [Prepare the retained current blog data](posts.open(url=`url`))**.
|
||||
Return *[Discover and listen with the actual site context](web.serve(root=`root`, host="127.0.0.1", port=`port`, db=`store`, static_dir="public"))*.
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Artifact blog smoke (ADR 0007). Usage: bash examples/marqdo-blog/smoke.sh
|
||||
# Expects serve.mq.md already listening on BASE (default 18081).
|
||||
set -uo pipefail
|
||||
BASE="${BASE:-http://127.0.0.1:18081}"
|
||||
PASS=0; FAIL=0
|
||||
ok() { echo " ok: $1"; PASS=$((PASS+1)); }
|
||||
bad() { echo " FAIL: $1"; FAIL=$((FAIL+1)); }
|
||||
|
||||
echo "== Document home =="
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/")
|
||||
[ "$code" = "200" ] && ok "GET / -> $code" || bad "GET / -> $code"
|
||||
curl -s "$BASE/" | grep -q '<title>Marqdo 博客</title>' && ok "title" || bad "title"
|
||||
curl -s "$BASE/" | grep -q 'class="card"' && ok "data_source cards" || bad "cards missing"
|
||||
curl -s "$BASE/" | grep -q 'Hello Marqdo' && ok "seed title" || bad "seed title missing"
|
||||
|
||||
echo "== Static =="
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/static/live.js")
|
||||
[ "$code" = "200" ] && ok "GET /static/live.js -> $code" || bad "static -> $code"
|
||||
|
||||
echo "== Dynamic Document =="
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/post/hello")
|
||||
[ "$code" = "200" ] && ok "GET /post/hello -> $code" || bad "post detail -> $code"
|
||||
curl -s "$BASE/post/hello" | grep -q 'article-title' && ok "article title" || bad "article title missing"
|
||||
|
||||
echo "== ZH Document =="
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/about")
|
||||
[ "$code" = "200" ] && ok "GET /about -> $code" || bad "about -> $code"
|
||||
curl -s "$BASE/about" | grep -q '关于 Marqdo' && ok "about body" || bad "about body missing"
|
||||
|
||||
echo "== Endpoint =="
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/api/ping")
|
||||
[ "$code" = "200" ] && ok "GET /api/ping -> $code" || bad "ping -> $code"
|
||||
curl -s "$BASE/api/ping" | grep -q 'marqdo-blog' && ok "ping json" || bad "ping json missing"
|
||||
code=$(curl -s -o /tmp/mq_blog_echo.json -w "%{http_code}" \
|
||||
-H 'Content-Type: application/json' -d '{"message":"hi"}' "$BASE/api/echo")
|
||||
[ "$code" = "200" ] && ok "POST /api/echo -> $code" || bad "echo -> $code"
|
||||
grep -q '"message":"hi"' /tmp/mq_blog_echo.json && ok "echo body" || bad "echo body missing"
|
||||
|
||||
echo
|
||||
echo "通过 $PASS / $((PASS+FAIL))"
|
||||
[ "$FAIL" = "0" ] || exit 1
|
||||
@@ -1,149 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 博客主题字面样式调用手册
|
||||
import:
|
||||
document: lib/document.mq.md
|
||||
web: ext/web/web.mq.md
|
||||
text: lib/text.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
本文件负责可调用的说明与编排,[theme.tables.md](theme.tables.md)负责可独立阅读的 Markdown 常量。调用时把 --fs-root 指向 examples/marqdo-blog,读取需要 fs.read;连接数据库或编译样式时还需要 plugin。
|
||||
|
||||
## 基础
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
基础段声明纸张、文字和强调色变量,以及字体与页面骨架。返回值仍是原生样式表数据,编译与浏览器加载由各自的明确步骤完成。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#基础);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取基础的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="基础"))*.
|
||||
|
||||
## 顶栏
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
顶栏段保留吸顶导航、磨砂背景、品牌渐变与链接状态。选择器与值都位于数据叶子,调用函数说明用途,避免把整套声明堆进执行流程。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#顶栏);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取顶栏的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="顶栏"))*.
|
||||
|
||||
## 侧栏
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
侧栏段保留归档面板的布局、链接间距和悬停反馈。它只提供样式数据,具体侧栏内容仍由独立组件或 Document 负责。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#侧栏);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取侧栏的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="侧栏"))*.
|
||||
|
||||
## 主体
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
主体段定义内容区留白、标题和导语的排版节奏。数据读取保持原有字段和值;主题编译不会替页面构造布局节点。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#主体);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取主体的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="主体"))*.
|
||||
|
||||
## 卡片
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
卡片段保留文章列表的网格、阴影、封面和悬停状态。样式类名应与页面输出保持一致;此函数只读取声明,不查询文章数据。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#卡片);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取卡片的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="卡片"))*.
|
||||
|
||||
## 页脚
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
页脚段保留页面末尾的留白、分隔线和链接外观。页脚若分为多个布局区域,仍应沿组件目录拆分,样式声明不会代替工程结构。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#页脚);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取页脚的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="页脚"))*.
|
||||
|
||||
## 表单
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
表单段保留输入控件、按钮和管理操作的状态样式。字段校验、保存和鉴权属于数据与安全资源;样式只改变已存在控件的外观。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#表单);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取表单的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="表单"))*.
|
||||
|
||||
## 响应式
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 与原字面表一致的数据类型和记录/列式形态 |
|
||||
|
||||
响应式段保留窄屏断点、侧栏流向、内容间距和列表列数。媒体条件仍由原生样式编译器读取,浏览器结果需要实际窄屏验证。
|
||||
|
||||
从站点根目录授予 fs.read 后调用。实际常量位于 [theme.tables.md](theme.tables.md#响应式);读取过程保留数值、布尔、空值和表格形态,并检查标题与行列结构。数据文件中的说明不会作为程序运行。
|
||||
|
||||
完成后返回*[读取响应式的实际 Markdown 常量](document.read_table(path="styles/theme.tables.md", title="响应式"))*.
|
||||
|
||||
## _编译段
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 名称 | text | 必填 | theme.tables.md 中精确且唯一的样式章节名 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | 由所选样式声明编译的 CSS |
|
||||
|
||||
使用`名称`选择一个具有独立职责的声明段,授权 fs.read 和 plugin。字面表读取保留原始选择器、属性和值,原生样式编译器负责媒体条件及 CSS 单元格处理。标题错误会保留文档诊断;此步骤不写文件,也不会把样式附加到浏览器。
|
||||
|
||||
我们 **数据 = [读取这一段的实际样式常量](document.read_table(path="styles/theme.tables.md", title=`名称`))**。
|
||||
完成后返回*[编译所选声明段](web.make_style(name=`名称`, table=`数据`))*.
|
||||
|
||||
|
||||
## 全局
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | 全部声明段按稳定顺序编译的 CSS 文本 |
|
||||
|
||||
从站点根授权 fs.read 与 plugin 后调用。名称表保留基础、导航、侧栏、主体、卡片、页脚、表单和断点的原有顺序;每段通过同一编译步骤读取自己的 Markdown 常量。变量声明因此先于使用它们的组件规则,响应式覆盖放在最后。返回值仍是 CSS 文本,保存与资源引用由明确的后续步骤完成。各命名数据函数也继续保留,方便独立检查某个区域。
|
||||
|
||||
`names` =
|
||||
|
||||
| 名称 |
|
||||
|---|
|
||||
| 基础 |
|
||||
| 顶栏 |
|
||||
| 侧栏 |
|
||||
| 主体 |
|
||||
| 卡片 |
|
||||
| 页脚 |
|
||||
| 表单 |
|
||||
| 响应式 |
|
||||
|
||||
我们 **parts = [开始有序的 CSS 段列表](table.empty_list())**。
|
||||
- [依次编译每个独立声明段](for names as name)
|
||||
我们 **css = [编译当前区域](_编译段(名称=`name`))**,并 **parts = [保留覆盖顺序](table.append(list=`parts`, item=`css`))**。
|
||||
完成后返回*[按区域顺序连接 CSS](text.str_join(xs=`parts`, sep="\n"))*.
|
||||
@@ -1,330 +0,0 @@
|
||||
# 博客主题字面样式
|
||||
|
||||
这里保存原生字面 GFM 数据。调用函数通过 document.read_table 读取所选章节;不会执行本文件中的说明或示例。
|
||||
|
||||
## 基础
|
||||
|
||||
基础段声明纸张、文字和强调色变量,以及字体与页面骨架。返回值仍是原生样式表数据,编译与浏览器加载由各自的明确步骤完成。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| :root | --ink | #1c1917 |
|
||||
| :root | --ink-soft | #44403c |
|
||||
| :root | --muted | #78716c |
|
||||
| :root | --faint | #a8a29e |
|
||||
| :root | --paper | #f7f5f2 |
|
||||
| :root | --card | #ffffff |
|
||||
| :root | --line | #e7e5e4 |
|
||||
| :root | --accent | #4f46e5 |
|
||||
| :root | --accent-2 | #7c3aed |
|
||||
| :root | --accent-ink | #ffffff |
|
||||
| :root | --radius | 16px |
|
||||
| :root | --shadow | 0 1px 2px rgba(28,25,23,.05), 0 8px 24px rgba(28,25,23,.06) |
|
||||
| :root | --shadow-lg | 0 4px 12px rgba(28,25,23,.08), 0 20px 48px rgba(28,25,23,.12) |
|
||||
| :root | --serif | "Noto Serif SC", Georgia, "Songti SC", serif |
|
||||
| :root | --sans | "Noto Sans SC", "IBM Plex Sans", system-ui, -apple-system, sans-serif |
|
||||
| html | scroll-behavior | smooth |
|
||||
| * | box-sizing | border-box |
|
||||
| ::selection | background | rgba(79,70,229,.18) |
|
||||
| body | margin | 0 |
|
||||
| body | font-family | var(--sans) |
|
||||
| body | background | var(--paper) |
|
||||
| body | color | var(--ink) |
|
||||
| body | display | grid |
|
||||
| body | min-height | 100vh |
|
||||
| body | line-height | 1.7 |
|
||||
| body | grid-template-rows | auto 1fr auto |
|
||||
| body.has-sidebar | grid-template-columns | 15rem 1fr |
|
||||
| body.has-sidebar | grid-template-areas | "top top" "side main" "foot foot" |
|
||||
| body.no-sidebar | grid-template-areas | "top" "main" "foot" |
|
||||
|
||||
## 顶栏
|
||||
|
||||
顶栏段保留吸顶导航、磨砂背景、品牌渐变与链接状态。选择器与值都位于数据叶子,调用函数说明用途,避免把整套声明堆进执行流程。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| header.topnav | grid-area | top |
|
||||
| header.topnav | position | sticky |
|
||||
| header.topnav | top | 0 |
|
||||
| header.topnav | z-index | 20 |
|
||||
| header.topnav | background | rgba(255,255,255,.82) |
|
||||
| header.topnav | backdrop-filter | blur(10px) |
|
||||
| header.topnav | -webkit-backdrop-filter | blur(10px) |
|
||||
| header.topnav | border-bottom | 1px solid var(--line) |
|
||||
| header.topnav | padding | .9rem 2rem |
|
||||
| header.topnav | display | flex |
|
||||
| header.topnav | align-items | center |
|
||||
| header.topnav | justify-content | space-between |
|
||||
| ul.nav | list-style | none |
|
||||
| ul.nav | margin | 0 |
|
||||
| ul.nav | padding | 0 |
|
||||
| ul.nav | display | flex |
|
||||
| ul.nav | align-items | center |
|
||||
| ul.nav | gap | .35rem |
|
||||
| ul.nav li | margin | 0 |
|
||||
| ul.nav a | display | inline-block |
|
||||
| ul.nav a | padding | .45rem .9rem |
|
||||
| ul.nav a | border-radius | 999px |
|
||||
| ul.nav a | color | var(--ink-soft) |
|
||||
| ul.nav a | font-weight | 500 |
|
||||
| ul.nav a | text-decoration | none |
|
||||
| ul.nav a | transition | background .18s ease, color .18s ease |
|
||||
| ul.nav a:hover | background | rgba(79,70,229,.1) |
|
||||
| ul.nav a:hover | color | var(--accent) |
|
||||
| ul.nav li:first-child a | font-family | var(--serif) |
|
||||
| ul.nav li:first-child a | font-size | 1.25rem |
|
||||
| ul.nav li:first-child a | font-weight | 700 |
|
||||
| ul.nav li:first-child a | background | linear-gradient(120deg, var(--accent), var(--accent-2)) |
|
||||
| ul.nav li:first-child a | -webkit-background-clip | text |
|
||||
| ul.nav li:first-child a | background-clip | text |
|
||||
| ul.nav li:first-child a | -webkit-text-fill-color | transparent |
|
||||
| ul.nav li:first-child a | color | transparent |
|
||||
| ul.nav li:first-child a | padding-left | .2rem |
|
||||
| ul.nav li:first-child a | padding-right | .2rem |
|
||||
|
||||
## 侧栏
|
||||
|
||||
侧栏段保留归档面板的布局、链接间距和悬停反馈。它只提供样式数据,具体侧栏内容仍由独立组件或 Document 负责。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| aside.side | grid-area | side |
|
||||
| aside.side | padding | 2rem 1.25rem |
|
||||
| aside.side | border-right | 1px solid var(--line) |
|
||||
| aside.side | background | linear-gradient(180deg, #fbfaf8, #f3f1ec) |
|
||||
| ul.side-nav | list-style | none |
|
||||
| ul.side-nav | margin | 0 |
|
||||
| ul.side-nav | padding | 0 |
|
||||
| ul.side-nav | display | flex |
|
||||
| ul.side-nav | flex-direction | column |
|
||||
| ul.side-nav | gap | .25rem |
|
||||
| ul.side-nav li | margin | 0 |
|
||||
| ul.side-nav a | display | block |
|
||||
| ul.side-nav a | padding | .55rem .85rem |
|
||||
| ul.side-nav a | border-radius | 10px |
|
||||
| ul.side-nav a | color | var(--ink-soft) |
|
||||
| ul.side-nav a | text-decoration | none |
|
||||
| ul.side-nav a | font-weight | 500 |
|
||||
| ul.side-nav a | transition | background .15s ease, transform .15s ease, color .15s ease |
|
||||
| ul.side-nav a:hover | background | #fff |
|
||||
| ul.side-nav a:hover | color | var(--accent) |
|
||||
| ul.side-nav a:hover | transform | translateX(4px) |
|
||||
| ul.side-nav a:hover | box-shadow | 0 1px 3px rgba(28,25,23,.08) |
|
||||
|
||||
## 主体
|
||||
|
||||
主体段定义内容区留白、标题和导语的排版节奏。数据读取保持原有字段和值;主题编译不会替页面构造布局节点。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| main.main | grid-area | main |
|
||||
| main.main | padding | 2.5rem 2.5rem 3.5rem |
|
||||
| main.main | max-width | 76rem |
|
||||
| main.main | width | 100% |
|
||||
| .main-intro | margin-bottom | .5rem |
|
||||
| .main-intro h1 | font-family | var(--serif) |
|
||||
| .main-intro h1 | margin | 0 0 .5rem |
|
||||
| .main-intro h1 | font-size | clamp(2rem, 5vw, 2.9rem) |
|
||||
| .main-intro h1 | line-height | 1.2 |
|
||||
| .main-intro h1 | font-weight | 700 |
|
||||
| .main-intro h1 | letter-spacing | -.01em |
|
||||
| .main-intro p | color | var(--muted) |
|
||||
| .main-intro p | margin | 0 |
|
||||
| .main-intro p | font-size | 1.05rem |
|
||||
|
||||
## 卡片
|
||||
|
||||
卡片段保留文章列表的网格、阴影、封面和悬停状态。样式类名应与页面输出保持一致;此函数只读取声明,不查询文章数据。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| .content.cards | display | grid |
|
||||
| .content.cards | gap | 1.5rem |
|
||||
| .content.cards | margin-top | 2rem |
|
||||
| .content.cards | grid-template-columns | repeat(auto-fill, minmax(17rem, 1fr)) |
|
||||
| .content.cards article.card | background | var(--card) |
|
||||
| .content.cards article.card | border | 1px solid var(--line) |
|
||||
| .content.cards article.card | border-radius | var(--radius) |
|
||||
| .content.cards article.card | padding | 1.6rem 1.7rem |
|
||||
| .content.cards article.card | box-shadow | var(--shadow) |
|
||||
| .content.cards article.card | transition | transform .22s ease, box-shadow .22s ease, border-color .22s ease |
|
||||
| .content.cards article.card | display | flex |
|
||||
| .content.cards article.card | flex-direction | column |
|
||||
| .content.cards article.card | gap | .55rem |
|
||||
| .content.cards article.card:hover | transform | translateY(-6px) |
|
||||
| .content.cards article.card:hover | box-shadow | var(--shadow-lg) |
|
||||
| .content.cards article.card:hover | border-color | rgba(79,70,229,.35) |
|
||||
| .content.cards a.card-link | text-decoration | none |
|
||||
| .content.cards a.card-link | color | inherit |
|
||||
| .content.cards a.card-link | display | flex |
|
||||
| .content.cards a.card-link | flex-direction | column |
|
||||
| .content.cards a.card-link | gap | .55rem |
|
||||
| .content.cards a.card-link | height | 100% |
|
||||
| .content.cards a.card-link:hover | color | inherit |
|
||||
| .content.cards h2 | font-family | var(--serif) |
|
||||
| .content.cards h2 | margin | 0 |
|
||||
| .content.cards h2 | font-size | 1.35rem |
|
||||
| .content.cards h2 | line-height | 1.35 |
|
||||
| .content.cards h2 | font-weight | 700 |
|
||||
| .content.cards h2 | transition | color .18s ease |
|
||||
| .content.cards a.card-link:hover h2 | color | var(--accent) |
|
||||
| .card-meta | font-size | .82rem |
|
||||
| .card-meta | color | var(--faint) |
|
||||
| .card-meta | letter-spacing | .04em |
|
||||
| .card-meta | text-transform | uppercase |
|
||||
| .card-tag | align-self | flex-start |
|
||||
| .card-tag | font-size | .78rem |
|
||||
| .card-tag | color | var(--accent) |
|
||||
| .card-tag | background | rgba(79,70,229,.08) |
|
||||
| .card-tag | padding | .15rem .65rem |
|
||||
| .card-tag | border-radius | 999px |
|
||||
| .card-tag | font-weight | 600 |
|
||||
| .content.cards p | color | var(--muted) |
|
||||
| .content.cards p | margin | 0 |
|
||||
| .content.cards p | font-size | .95rem |
|
||||
| .content.cards p | flex | 1 |
|
||||
|
||||
## 页脚
|
||||
|
||||
页脚段保留页面末尾的留白、分隔线和链接外观。页脚若分为多个布局区域,仍应沿组件目录拆分,样式声明不会代替工程结构。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| footer.foot | grid-area | foot |
|
||||
| footer.foot | padding | 1.4rem 2rem |
|
||||
| footer.foot | border-top | 1px solid var(--line) |
|
||||
| footer.foot | color | var(--muted) |
|
||||
| footer.foot | background | #fff |
|
||||
| footer.foot | font-size | .9rem |
|
||||
| footer.foot | display | flex |
|
||||
| footer.foot | justify-content | space-between |
|
||||
| footer.foot | align-items | center |
|
||||
| footer.foot | flex-wrap | wrap |
|
||||
| footer.foot | gap | .5rem |
|
||||
| ul.foot-nav | list-style | none |
|
||||
| ul.foot-nav | margin | 0 |
|
||||
| ul.foot-nav | padding | 0 |
|
||||
| ul.foot-nav | display | flex |
|
||||
| ul.foot-nav | gap | 1rem |
|
||||
| ul.foot-nav | flex-wrap | wrap |
|
||||
| ul.foot-nav li | margin | 0 |
|
||||
| ul.foot-nav a | color | var(--muted) |
|
||||
| ul.foot-nav a | text-decoration | none |
|
||||
| ul.foot-nav a:hover | color | var(--accent) |
|
||||
|
||||
## 表单
|
||||
|
||||
表单段保留输入控件、按钮和管理操作的状态样式。字段校验、保存和鉴权属于数据与安全资源;样式只改变已存在控件的外观。
|
||||
|
||||
| 选择器 | 属性 | 值 |
|
||||
|--------|------|-----|
|
||||
| .site-form | margin-top | 1.75rem |
|
||||
| .site-form | max-width | 34rem |
|
||||
| .site-form | background | var(--card) |
|
||||
| .site-form | border | 1px solid var(--line) |
|
||||
| .site-form | border-radius | var(--radius) |
|
||||
| .site-form | padding | 1.8rem |
|
||||
| .site-form | box-shadow | var(--shadow) |
|
||||
| .site-form form | display | grid |
|
||||
| .site-form form | gap | 1rem |
|
||||
| .site-form label | display | grid |
|
||||
| .site-form label | gap | .35rem |
|
||||
| .site-form label | font-size | .92rem |
|
||||
| .site-form label | font-weight | 600 |
|
||||
| .site-form label | color | var(--ink-soft) |
|
||||
| .site-form input | padding | .65rem .8rem |
|
||||
| .site-form input | border | 1px solid var(--line) |
|
||||
| .site-form input | border-radius | 10px |
|
||||
| .site-form input | font | inherit |
|
||||
| .site-form input | background | #fdfcfb |
|
||||
| .site-form input | transition | border-color .15s ease, box-shadow .15s ease |
|
||||
| .site-form textarea | padding | .65rem .8rem |
|
||||
| .site-form textarea | border | 1px solid var(--line) |
|
||||
| .site-form textarea | border-radius | 10px |
|
||||
| .site-form textarea | font | inherit |
|
||||
| .site-form textarea | background | #fdfcfb |
|
||||
| .site-form textarea | transition | border-color .15s ease, box-shadow .15s ease |
|
||||
| .site-form select | padding | .65rem .8rem |
|
||||
| .site-form select | border | 1px solid var(--line) |
|
||||
| .site-form select | border-radius | 10px |
|
||||
| .site-form select | font | inherit |
|
||||
| .site-form select | background | #fdfcfb |
|
||||
| .site-form select | transition | border-color .15s ease, box-shadow .15s ease |
|
||||
| .site-form input:focus | outline | none |
|
||||
| .site-form input:focus | border-color | var(--accent) |
|
||||
| .site-form input:focus | box-shadow | 0 0 0 3px rgba(79,70,229,.12) |
|
||||
| .site-form textarea:focus | outline | none |
|
||||
| .site-form textarea:focus | border-color | var(--accent) |
|
||||
| .site-form textarea:focus | box-shadow | 0 0 0 3px rgba(79,70,229,.12) |
|
||||
| .site-form select:focus | outline | none |
|
||||
| .site-form select:focus | border-color | var(--accent) |
|
||||
| .site-form select:focus | box-shadow | 0 0 0 3px rgba(79,70,229,.12) |
|
||||
| .site-form input[readonly] | background | #f5f5f4 |
|
||||
| .site-form input[readonly] | color | var(--muted) |
|
||||
| .site-form textarea | min-height | 10rem |
|
||||
| .site-form textarea | resize | vertical |
|
||||
| .site-form .err | color | #b91c1c |
|
||||
| .site-form .err | font-size | .85rem |
|
||||
| .site-form .actions | display | flex |
|
||||
| .site-form .actions | gap | .75rem |
|
||||
| .site-form .actions | align-items | center |
|
||||
| .site-form .actions | flex-wrap | wrap |
|
||||
| .site-form .actions | padding-top | .25rem |
|
||||
| .site-form button | background | linear-gradient(120deg, var(--accent), var(--accent-2)) |
|
||||
| .site-form button | color | var(--accent-ink) |
|
||||
| .site-form button | border | 0 |
|
||||
| .site-form button | padding | .6rem 1.3rem |
|
||||
| .site-form button | border-radius | 999px |
|
||||
| .site-form button | cursor | pointer |
|
||||
| .site-form button | font-weight | 600 |
|
||||
| .site-form button | font-size | .95rem |
|
||||
| .site-form button | transition | opacity .15s ease, transform .15s ease, box-shadow .15s ease |
|
||||
| .site-form button:hover | opacity | .92 |
|
||||
| .site-form button:hover | transform | translateY(-1px) |
|
||||
| .site-form button:hover | box-shadow | 0 6px 18px rgba(79,70,229,.3) |
|
||||
| .site-form a.btn | display | inline-block |
|
||||
| .site-form a.btn | padding | .6rem 1.3rem |
|
||||
| .site-form a.btn | border-radius | 999px |
|
||||
| .site-form a.btn | border | 1px solid var(--line) |
|
||||
| .site-form a.btn | color | var(--ink-soft) |
|
||||
| .site-form a.btn | text-decoration | none |
|
||||
| .site-form a.btn | font-weight | 500 |
|
||||
| .site-form a.btn | font-size | .95rem |
|
||||
| .site-form .meta | color | var(--muted) |
|
||||
| .site-form .meta | font-size | .9rem |
|
||||
| .site-form .admin-list | margin | 0 |
|
||||
| .site-form .admin-list | padding | 0 |
|
||||
| .site-form .admin-list | list-style | none |
|
||||
| .site-form .admin-list | display | grid |
|
||||
| .site-form .admin-list | gap | .5rem |
|
||||
| .site-form .admin-list li | background | #fdfcfb |
|
||||
| .site-form .admin-list li | border | 1px solid var(--line) |
|
||||
| .site-form .admin-list li | border-radius | 10px |
|
||||
| .site-form .admin-list li | padding | .6rem .9rem |
|
||||
| .site-form .admin-list li | display | flex |
|
||||
| .site-form .admin-list li | justify-content | space-between |
|
||||
| .site-form .admin-list li | align-items | center |
|
||||
| .site-form .admin-list li | gap | 1rem |
|
||||
| .site-form .admin-list a | color | var(--accent) |
|
||||
| .site-form .admin-list a | text-decoration | none |
|
||||
| .site-form .admin-list a | font-size | .9rem |
|
||||
|
||||
## 响应式
|
||||
|
||||
响应式段保留窄屏断点、侧栏流向、内容间距和列表列数。媒体条件仍由原生样式编译器读取,浏览器结果需要实际窄屏验证。
|
||||
|
||||
| 媒体 | 选择器 | 属性 | 值 |
|
||||
|------|--------|------|-----|
|
||||
| (max-width: 860px) | body.has-sidebar | grid-template-columns | 1fr |
|
||||
| (max-width: 860px) | body.has-sidebar | grid-template-areas | "top" "main" "side" "foot" |
|
||||
| (max-width: 860px) | aside.side | border-right | 0 |
|
||||
| (max-width: 860px) | aside.side | border-bottom | 1px solid var(--line) |
|
||||
| (max-width: 860px) | aside.side | padding | 1rem 2rem |
|
||||
| (max-width: 860px) | ul.side-nav | flex-direction | row |
|
||||
| (max-width: 860px) | ul.side-nav | flex-wrap | wrap |
|
||||
| (max-width: 860px) | main.main | padding | 1.75rem 1.25rem 2.5rem |
|
||||
| (max-width: 860px) | header.topnav | padding | .75rem 1.25rem |
|
||||
| (max-width: 860px) | footer.foot | padding | 1.2rem 1.25rem |
|
||||
| (max-width: 860px) | .content.cards | grid-template-columns | 1fr |
|
||||
| (max-width: 520px) | ul.nav | flex-wrap | wrap |
|
||||
@@ -1,51 +0,0 @@
|
||||
# oa2026-showcase
|
||||
|
||||
用于 2026 开源项目大赛作品介绍文档的可运行示例。
|
||||
|
||||
| 文件 | 展示的能力 | 运行 |
|
||||
|------|------------|------|
|
||||
| `add.mq.md` | 叙述统一、粗体即代码、斜体即返回 | `marqdo run examples/oa2026-showcase/add.mq.md` |
|
||||
| `invoice.mq.md` | 表格即数据、循环、分支、断言 | `marqdo run examples/oa2026-showcase/invoice.mq.md` |
|
||||
| `calculus.mq.md` | 公式即变量、求导、求根、绘图 | `marqdo run examples/oa2026-showcase/calculus.mq.md` |
|
||||
| `bell.mq.md` | 量子电路、概率、断言、SVG 派生物 | `marqdo run examples/oa2026-showcase/bell.mq.md` |
|
||||
| `foreign-node.mq.md` | 外联一次性执行、持久会话、显式传值 | `marqdo run examples/oa2026-showcase/foreign-node.mq.md` |
|
||||
|
||||
## 预期输出
|
||||
|
||||
```text
|
||||
$ marqdo run examples/oa2026-showcase/add.mq.md
|
||||
42
|
||||
|
||||
$ marqdo run examples/oa2026-showcase/invoice.mq.md
|
||||
960
|
||||
912
|
||||
966
|
||||
within-cap
|
||||
|
||||
$ marqdo run examples/oa2026-showcase/calculus.mq.md
|
||||
3*x^2 - 3
|
||||
9
|
||||
[-1.7320508076, 0, 1.7320508076]
|
||||
plot-ok
|
||||
|
||||
$ marqdo run examples/oa2026-showcase/foreign-node.mq.md
|
||||
{华东: 420, 华北: 220, 华南: 230}
|
||||
华东: 420
|
||||
华南: 230
|
||||
华北: 220
|
||||
|
||||
华东: 420
|
||||
华北: 300
|
||||
华南: 230
|
||||
|
||||
$ marqdo run examples/oa2026-showcase/bell.mq.md
|
||||
{00: 0.5, 11: 0.5}
|
||||
0.5
|
||||
0.5
|
||||
bell-00-ok
|
||||
bell-11-ok
|
||||
bell-draw-ok
|
||||
```
|
||||
|
||||
`bell.mq.md` 运行后会生成 `bell-circuit.svg` 与 `bell-probs.svg`;
|
||||
`calculus.mq.md` 运行后会生成 `calculus-plot.svg`。
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
---
|
||||
|
||||
## 加一
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| n | any | 必填 | Numeric input advanced or calculated by this example |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 下文显式返回的计算值或结构化结果;分支存在时遵循实际命中的分支。 |
|
||||
|
||||
对于输入变量`n`,我们执行 **`n` = `n` + 1**,然后把更新后的值作为结果返回 *`n`*。
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | 空值;按顺序执行本页的演示步骤,观察输出或已说明的副作用。 |
|
||||
|
||||
从 41 出发调用「加一」,把结果存进`r`并打印。
|
||||
|
||||
我们先**r = [计算并保存 r](加一(n=41))**,供下一步使用。
|
||||
随后我们**[显示当前步骤的结果](> print text=`r`)**。
|
||||
@@ -1,24 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="320" height="136" viewBox="0 0 320.0 136.0" data-theme="light" role="img" aria-label="quantum circuit"><defs>
|
||||
<linearGradient id="mq-bg" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#eef3f9"/>
|
||||
<stop offset="55%" stop-color="#ffffff"/>
|
||||
<stop offset="100%" stop-color="#eef3f9"/>
|
||||
</linearGradient>
|
||||
<filter id="mq-glow" x="-40%" y="-40%" width="180%" height="180%">
|
||||
<feGaussianBlur stdDeviation="2.2" result="b"/>
|
||||
<feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
|
||||
</filter>
|
||||
<filter id="mq-soft" x="-20%" y="-20%" width="140%" height="140%">
|
||||
<feDropShadow dx="0" dy="1.5" stdDeviation="1.8" flood-color="#3d5afe" flood-opacity="0.35"/>
|
||||
</filter>
|
||||
</defs><rect width="320.0" height="136.0" rx="14" fill="url(#mq-bg)"/>
|
||||
<rect x="1.5" y="1.5" width="317.0" height="133.0" rx="12.5" fill="none" stroke="#e2eaf3" stroke-width="1" opacity="0.55"/><line x1="96" y1="36" x2="296" y2="36" stroke="#4a5a6a" stroke-width="3.2" stroke-linecap="round" opacity="0.28"/>
|
||||
<line x1="96" y1="36" x2="296" y2="36" stroke="#4a5a6a" stroke-width="1.8" stroke-linecap="round"/><rect x="51" y="25" width="38" height="22" rx="7" fill="#ffffff" stroke="#e2eaf3" stroke-width="1"/>
|
||||
<text x="70" y="36" text-anchor="middle" dominant-baseline="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="13" font-weight="700" letter-spacing="0.02em" fill="#15202b">q0</text><line x1="96" y1="100" x2="296" y2="100" stroke="#4a5a6a" stroke-width="3.2" stroke-linecap="round" opacity="0.28"/>
|
||||
<line x1="96" y1="100" x2="296" y2="100" stroke="#4a5a6a" stroke-width="1.8" stroke-linecap="round"/><rect x="51" y="89" width="38" height="22" rx="7" fill="#ffffff" stroke="#e2eaf3" stroke-width="1"/>
|
||||
<text x="70" y="100" text-anchor="middle" dominant-baseline="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="13" font-weight="700" letter-spacing="0.02em" fill="#15202b">q1</text><rect x="116" y="16" width="40" height="40" rx="8" fill="#3d5afe" stroke="#ffffff" stroke-width="1.1" data-gate-family="clifford" filter="url(#mq-soft)" opacity="0.98"/>
|
||||
<text x="136" y="36" text-anchor="middle" dominant-baseline="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="14" font-weight="700" fill="#ffffff">H</text><line x1="216" y1="36" x2="216" y2="100" stroke="#1a237e" stroke-width="2.25" data-gate-family="clifford"/>
|
||||
<circle cx="216" cy="36" r="5.2" fill="#1a237e" filter="url(#mq-glow)"/>
|
||||
<circle cx="216" cy="100" r="13" fill="#3d5afe" stroke="#1a237e" stroke-width="1.6" filter="url(#mq-soft)" opacity="0.96"/>
|
||||
<line x1="216" y1="87" x2="216" y2="113" stroke="#1a237e" stroke-width="2"/>
|
||||
<line x1="203" y1="100" x2="229" y2="100" stroke="#1a237e" stroke-width="2"/></svg>
|
||||
|
Before Width: | Height: | Size: 2.7 KiB |
@@ -1,14 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="152" height="180" viewBox="0 0 152.0 180.0" data-theme="light" role="img" aria-label="measurement probabilities"><defs>
|
||||
<linearGradient id="mq-bg" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#eef3f9"/>
|
||||
<stop offset="55%" stop-color="#ffffff"/>
|
||||
<stop offset="100%" stop-color="#eef3f9"/>
|
||||
</linearGradient>
|
||||
<filter id="mq-glow" x="-40%" y="-40%" width="180%" height="180%">
|
||||
<feGaussianBlur stdDeviation="2.2" result="b"/>
|
||||
<feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
|
||||
</filter>
|
||||
<filter id="mq-soft" x="-20%" y="-20%" width="140%" height="140%">
|
||||
<feDropShadow dx="0" dy="1.5" stdDeviation="1.8" flood-color="#3d5afe" flood-opacity="0.35"/>
|
||||
</filter>
|
||||
</defs><rect width="152.0" height="180.0" rx="14" fill="url(#mq-bg)"/><line x1="36" y1="144" x2="136" y2="144" stroke="#4a5560" stroke-width="1.2"/><line x1="36" y1="24" x2="36" y2="144" stroke="#4a5560" stroke-width="1.2"/><text x="8" y="28" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="10" fill="#15202b">1</text><text x="8" y="148" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="10" fill="#15202b">0</text><rect x="40" y="83.99999999999999" width="36" height="60.000000000000014" rx="4" fill="#3d5afe" stroke="#1a237e" stroke-width="1" filter="url(#mq-soft)"/><text x="58" y="162" text-anchor="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="11" fill="#15202b">00</text><text x="58" y="78.99999999999999" text-anchor="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="10" fill="#5a6a7a">0.50</text><rect x="88" y="83.99999999999999" width="36" height="60.000000000000014" rx="4" fill="#3d5afe" stroke="#1a237e" stroke-width="1" filter="url(#mq-soft)"/><text x="106" y="162" text-anchor="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="11" fill="#15202b">11</text><text x="106" y="78.99999999999999" text-anchor="middle" font-family="ui-monospace,Menlo,Consolas,monospace" font-size="10" fill="#5a6a7a">0.50</text></svg>
|
||||
|
Before Width: | Height: | Size: 2.0 KiB |
@@ -1,64 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 贝尔态:两个量子比特如何一起回答
|
||||
description: 从一条假设开始,搭电路、看概率、画图,并用断言验收。
|
||||
import:
|
||||
quantum: ext/quantum/circuit/index.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
贝尔态:一次可读的量子实验。
|
||||
|
||||
我们先做一个假设:如果对第一个量子比特施加 Hadamard 门,再用它控制第二个量子比特翻转,
|
||||
那么测量结果不会出现「一个 0、一个 1」,只会出现「00」或「11」。
|
||||
|
||||
下面的表不是配置,而是实验步骤本身。读者先读实验设计,再读执行结果。
|
||||
|
||||
`步骤` =
|
||||
|
||||
| 步骤 | gate | qubits |
|
||||
|------|------|--------|
|
||||
| 1 | H | 0 |
|
||||
| 2 | CX | 0,1 |
|
||||
|
||||
We first **电路 = [Compute 电路](quantum.circuit(qubits=2, steps=`步骤`))** for the next step.
|
||||
We first **概率 = [Compute 概率](> `电路`.probabilities)** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`概率`)**.
|
||||
|
||||
---
|
||||
|
||||
我们期待什么?如果假设成立,`概率`应该只在「00」与「11」上有值,而且各占一半。
|
||||
先把两个关键概率取出来,读者不必在长映射里找:
|
||||
|
||||
We first **p00 = [00](access(`概率`, "00"))** for the next step.
|
||||
We first **p11 = [11](access(`概率`, "11"))** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`p00`)**.
|
||||
We now **[Display this step's result](> print text=`p11`)**.
|
||||
|
||||
下面的断言不是装饰:如果电路写错,或者门接错,运行会直接失败。
|
||||
|
||||
1. `p00` > 0.49
|
||||
We now **[Display this step's result](> print text="bell-00-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="bell-00-fail")**.
|
||||
|
||||
1. `p11` > 0.49
|
||||
We now **[Display this step's result](> print text="bell-11-ok")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="bell-11-fail")**.
|
||||
|
||||
---
|
||||
|
||||
图不是截图,而是这份文档运行后生成的派生物。电路图和概率图都来自同一个`电路`。
|
||||
|
||||
We first **_ = [Compute _](> `电路`.draw path="bell-circuit.svg" theme="light")** for the next step.
|
||||
We first **_ = [Compute _](> `电路`.draw kind="probs" path="bell-probs.svg" theme="light")** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text="bell-draw-ok")**.
|
||||
@@ -1,17 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 520 360" width="520" height="360" role="img" aria-label="function plot">
|
||||
<defs>
|
||||
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z" fill="#4b5563"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<style>
|
||||
.grid { stroke: #e5e7eb; stroke-width: 1; }
|
||||
.axis { stroke: #4b5563; stroke-width: 1.5; }
|
||||
.tick { stroke: #4b5563; stroke-width: 1; }
|
||||
.curve { fill: none; stroke: #1f6feb; stroke-width: 2; }
|
||||
.pt { fill: #1f6feb; }
|
||||
.axis-label { font: 12px ui-sans-serif, system-ui, sans-serif; fill: #374151; font-weight: 600; }
|
||||
.tick-label { font: 10px ui-sans-serif, system-ui, sans-serif; fill: #6b7280; }
|
||||
</style>
|
||||
<line x1="36.00" y1="36" x2="36.00" y2="324" class="grid"/><line x1="110.67" y1="36" x2="110.67" y2="324" class="grid"/><line x1="185.33" y1="36" x2="185.33" y2="324" class="grid"/><line x1="260.00" y1="36" x2="260.00" y2="324" class="grid"/><line x1="334.67" y1="36" x2="334.67" y2="324" class="grid"/><line x1="409.33" y1="36" x2="409.33" y2="324" class="grid"/><line x1="484.00" y1="36" x2="484.00" y2="324" class="grid"/><line x1="36" y1="289.09" x2="484" y2="289.09" class="grid"/><line x1="36" y1="252.73" x2="484" y2="252.73" class="grid"/><line x1="36" y1="216.36" x2="484" y2="216.36" class="grid"/><line x1="36" y1="180.00" x2="484" y2="180.00" class="grid"/><line x1="36" y1="143.64" x2="484" y2="143.64" class="grid"/><line x1="36" y1="107.27" x2="484" y2="107.27" class="grid"/><line x1="36" y1="70.91" x2="484" y2="70.91" class="grid"/><line x1="36" y1="180.00" x2="484" y2="180.00" class="axis" marker-end="url(#arrow)"/><line x1="260.00" y1="324" x2="260.00" y2="36" class="axis" marker-end="url(#arrow)"/><text x="488.00" y="184.00" class="axis-label">x</text><text x="266.00" y="40.00" class="axis-label">y</text><line x1="36.00" y1="176.00" x2="36.00" y2="184.00" class="tick"/><text x="36.00" y="194.00" text-anchor="middle" class="tick-label">-3</text><line x1="110.67" y1="176.00" x2="110.67" y2="184.00" class="tick"/><text x="110.67" y="194.00" text-anchor="middle" class="tick-label">-2</text><line x1="185.33" y1="176.00" x2="185.33" y2="184.00" class="tick"/><text x="185.33" y="194.00" text-anchor="middle" class="tick-label">-1</text><line x1="334.67" y1="176.00" x2="334.67" y2="184.00" class="tick"/><text x="334.67" y="194.00" text-anchor="middle" class="tick-label">1</text><line x1="409.33" y1="176.00" x2="409.33" y2="184.00" class="tick"/><text x="409.33" y="194.00" text-anchor="middle" class="tick-label">2</text><line x1="484.00" y1="176.00" x2="484.00" y2="184.00" class="tick"/><text x="484.00" y="194.00" text-anchor="middle" class="tick-label">3</text><line x1="256.00" y1="289.09" x2="264.00" y2="289.09" class="tick"/><text x="252.00" y="289.09" text-anchor="end" dominant-baseline="middle" class="tick-label">-15</text><line x1="256.00" y1="252.73" x2="264.00" y2="252.73" class="tick"/><text x="252.00" y="252.73" text-anchor="end" dominant-baseline="middle" class="tick-label">-10</text><line x1="256.00" y1="216.36" x2="264.00" y2="216.36" class="tick"/><text x="252.00" y="216.36" text-anchor="end" dominant-baseline="middle" class="tick-label">-5</text><line x1="256.00" y1="143.64" x2="264.00" y2="143.64" class="tick"/><text x="252.00" y="143.64" text-anchor="end" dominant-baseline="middle" class="tick-label">5</text><line x1="256.00" y1="107.27" x2="264.00" y2="107.27" class="tick"/><text x="252.00" y="107.27" text-anchor="end" dominant-baseline="middle" class="tick-label">10</text><line x1="256.00" y1="70.91" x2="264.00" y2="70.91" class="tick"/><text x="252.00" y="70.91" text-anchor="end" dominant-baseline="middle" class="tick-label">15</text><text x="252.00" y="194.00" class="tick-label">0</text><path d="M 36.00 310.91 L 38.24 305.73 L 40.48 300.67 L 42.72 295.72 L 44.96 290.89 L 47.20 286.18 L 49.44 281.57 L 51.68 277.07 L 53.92 272.69 L 56.16 268.41 L 58.40 264.24 L 60.64 260.18 L 62.88 256.22 L 65.12 252.36 L 67.36 248.61 L 69.60 244.96 L 71.84 241.40 L 74.08 237.95 L 76.32 234.60 L 78.56 231.34 L 80.80 228.17 L 83.04 225.11 L 85.28 222.13 L 87.52 219.25 L 89.76 216.45 L 92.00 213.75 L 94.24 211.13 L 96.48 208.61 L 98.72 206.17 L 100.96 203.81 L 103.20 201.53 L 105.44 199.34 L 107.68 197.23 L 109.92 195.20 L 112.16 193.25 L 114.40 191.38 L 116.64 189.58 L 118.88 187.86 L 121.12 186.22 L 123.36 184.64 L 125.60 183.14 L 127.84 181.71 L 130.08 180.35 L 132.32 179.06 L 134.56 177.83 L 136.80 176.67 L 139.04 175.57 L 141.28 174.54 L 143.52 173.57 L 145.76 172.67 L 148.00 171.82 L 150.24 171.03 L 152.48 170.30 L 154.72 169.62 L 156.96 169.00 L 159.20 168.44 L 161.44 167.93 L 163.68 167.47 L 165.92 167.06 L 168.16 166.70 L 170.40 166.39 L 172.64 166.12 L 174.88 165.90 L 177.12 165.73 L 179.36 165.60 L 181.60 165.51 L 183.84 165.46 L 186.08 165.46 L 188.32 165.49 L 190.56 165.56 L 192.80 165.67 L 195.04 165.81 L 197.28 165.98 L 199.52 166.19 L 201.76 166.43 L 204.00 166.70 L 206.24 167.01 L 208.48 167.33 L 210.72 167.69 L 212.96 168.07 L 215.20 168.48 L 217.44 168.91 L 219.68 169.36 L 221.92 169.84 L 224.16 170.33 L 226.40 170.84 L 228.64 171.38 L 230.88 171.92 L 233.12 172.48 L 235.36 173.06 L 237.60 173.65 L 239.84 174.25 L 242.08 174.86 L 244.32 175.49 L 246.56 176.12 L 248.80 176.75 L 251.04 177.39 L 253.28 178.04 L 255.52 178.69 L 257.76 179.35 L 260.00 180.00 L 262.24 180.65 L 264.48 181.31 L 266.72 181.96 L 268.96 182.61 L 271.20 183.25 L 273.44 183.88 L 275.68 184.51 L 277.92 185.14 L 280.16 185.75 L 282.40 186.35 L 284.64 186.94 L 286.88 187.52 L 289.12 188.08 L 291.36 188.62 L 293.60 189.16 L 295.84 189.67 L 298.08 190.16 L 300.32 190.64 L 302.56 191.09 L 304.80 191.52 L 307.04 191.93 L 309Line truncated
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 6.8 KiB |
@@ -1,38 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 一份可执行的求导讲义
|
||||
description: 公式、求导、求根、求值与绘图,在同一条叙述里完成。
|
||||
import:
|
||||
math: lib/math.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
我们从一条曲线开始。下面这个公式既是排版出来的数学对象,
|
||||
也是运行时可以直接求导、求根与绘图的`f`。
|
||||
|
||||
`f` =
|
||||
$$
|
||||
x^3 - 3*x
|
||||
$$
|
||||
|
||||
对它求导,得到`df`;再让`df`在 x = 2 处取值,得到切线斜率。
|
||||
|
||||
We first **df = [Compute df](math.diff(formula=`f`, var="x"))** for the next step.
|
||||
We first **slope = [Compute slope](math.eval(formula=`df`, var="x", value=2))** for the next step.
|
||||
We now **[Display this step's result](> print text=`df`)**.
|
||||
We now **[Display this step's result](> print text=`slope`)**.
|
||||
|
||||
曲线与 x 轴的交点同样可以被机器找出来。这里不需要另写一段脚本。
|
||||
|
||||
We first **roots = [Compute roots](math.solve(formula=`f`, var="x", min=-3, max=3))** for the next step.
|
||||
We now **[Display this step's result](> print text=`roots`)**.
|
||||
|
||||
最后把公式画成图。图不是截图,而是本文档运行产生的派生物。
|
||||
|
||||
We first **_svg = [Compute _svg](math.plot(formula=`f`, var="x", min=-3, max=3, path="calculus-plot.svg"))** for the next step.
|
||||
We now **[Display this step's result](> print text="plot-ok")**.
|
||||
@@ -1,116 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 原生订单分析与 Node Intl 展示边界
|
||||
import:
|
||||
native: ../foreign-native-report/index.mq.md
|
||||
foreign: lib/foreign.mq.md
|
||||
table: lib/table.mq.md
|
||||
result: lib/result.mq.md
|
||||
---
|
||||
|
||||
订单分析应先使用已经具备的原生能力。只有本地化货币展示交给 Node Intl;一次性执行和持久会话都是明确的外联边界,文件操作与通用数据处理不需要 Python 或外部读取器。
|
||||
|
||||
从仓库根目录调用:`marqdo call examples/oa2026-showcase/foreign-node.mq.md main --require-ok --effects process.exec --fs-root . --json`。只需原生分析时,可直接 call 共享模块的 analyze_orders,不需要任何进程授权。
|
||||
|
||||
## main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Result:前后两份原生分析、实际排序结果与一次性/持久格式化结果 |
|
||||
|
||||
成功时 value 的字段如下。先检查最外层 ok,再按字段读取;这里列出的数据都是本轮实际计算或执行得到的值。
|
||||
|
||||
| value 中的字段 | 值的形态 | 直接含义 |
|
||||
|---|---|---|
|
||||
| before | 原生分析记录 | 五笔订单的总额 870、数量 5、平均值 174 与按区域保留的统计行 |
|
||||
| after | 原生分析记录 | 追加八十元订单后,总额 950、数量 6、平均值约 158.3333;不做展示舍入 |
|
||||
| initial_ranking | 原生行记录列表 | 首轮按区域总额降序排列;每行保留区域、数量、总额、均值与标准化跨度 |
|
||||
| updated_ranking | 原生行记录列表 | 更新后的区域总额依次为 420、300、230;排序返回新列表 |
|
||||
| one_shot | 两个展示文本字段 | 一次性进程返回的 total 与 average,只表示首轮报告的本地化展示 |
|
||||
| persistent_initial | 两个展示文本字段 | 持久格式器对同一首轮报告得到的 total 与 average,可与一次性结果核对 |
|
||||
| persistent_updated | 两个展示文本字段 | 持久格式器展示更新后的报告;950.00 与 158.33 是展示文本,不覆盖原生数值 |
|
||||
|
||||
|
||||
本例先处理五笔订单:总额为八百七十,随后追加一笔华北的八十元订单,总额变为九百五十。分组、计数、平均值、追加和按区域总额排序全部使用 Marqdo 固有能力;不再在 Node 中维护另一份订单分析程序。共享模块中的 analyze_orders 是唯一的分析实现,其参数与字段表可以直接阅读和调用。
|
||||
|
||||
外联只承担确实缺失的本地化展示。第一次通过本文件的 format_once 演示标准输入上的 JSON 往返;两次共享 format_summary 分别展示原生修改前后的结果。每次共享调用都在同一内核内建立格式器、复用它格式化平均值并关闭资源,实际生命周期写在对应函数中,而不是把一个句柄藏进跨命令的 JSON 字符串。
|
||||
|
||||
总额排序也保留在原生流程中:先按 total 升序,再反转得到降序记录。排序不会改变原始订单或报告,每个返回行仍包含区域、订单数和总额。追加发生在 Marqdo 集合中,随后将重新计算出的值拷贝给展示边界,避免外部内核与原生数据各保留一份会悄悄分叉的业务状态。
|
||||
|
||||
调用需要 process.exec 和 Node,不读写用户文件,也不安装包。先检查共享格式化任务的 ok,再使用 value;一次性 JSON 协议失败则保留原生诊断。成功结果携带真正的原生数据和展示字符串,既能继续被其他函数使用,也能核对展示没有替代数值计算。查看返回结果比只读一条“完成”打印更能证明这一轮执行发生了什么。
|
||||
|
||||
`订单` =
|
||||
|
||||
| @ | 区域 | 金额 |
|
||||
|---|---|---|
|
||||
| 1 | 华东 | 120 |
|
||||
| 2 | 华东 | 300 |
|
||||
| 3 | 华南 | 90 |
|
||||
| 4 | 华南 | 140 |
|
||||
| 5 | 华北 | 220 |
|
||||
|
||||
We **before = [在原生标准库中完成首轮订单分析](native.analyze_orders(orders=`订单`, region_key="区域", amount_key="金额"))** and
|
||||
**initial_ranking = [保留首轮按区域总额降序的原生行记录](table.reverse(list=table.sort_by(list=access(before, "regions"), key="total")))** and
|
||||
**one_shot = [只把首轮报告的展示交给一次性进程](format_once(report=`before`))** and
|
||||
**initial = [用共享持久内核流程展示同一份原生结果](native.format_summary(report=`before`, locale="zh-CN"))**。
|
||||
1. not access(`initial`, "ok")
|
||||
返回*initial*,保留真实运行失败。
|
||||
|
||||
`追加` =
|
||||
|
||||
| 区域 | 金额 |
|
||||
|---|---|
|
||||
| 华北 | 80 |
|
||||
|
||||
We **orders = [在原生集合中追加新订单](table.append(list=`订单`, item=`追加`))** and
|
||||
**after = [用同一份原生实现重新计算完整报告](native.analyze_orders(orders=`orders`, region_key="区域", amount_key="金额"))** and
|
||||
**updated_ranking = [在原生集合中保留更新后的降序记录](table.reverse(list=table.sort_by(list=access(after, "regions"), key="total")))** and
|
||||
**updated = [把更新后的原生结果交给展示边界](native.format_summary(report=`after`, locale="zh-CN"))**。
|
||||
1. not access(`updated`, "ok")
|
||||
返回*updated*,保留持久内核的失败出口。
|
||||
We **persistent_initial = [保留首轮实际格式化文本](access(initial, "value"))** and **persistent_updated = [保留更新后的实际展示文本](access(updated, "value"))**。
|
||||
|
||||
`观察` =
|
||||
|
||||
| before | after | initial_ranking | updated_ranking | one_shot | persistent_initial | persistent_updated |
|
||||
|---|---|---|---|---|---|---|
|
||||
| `before` | `after` | `initial_ranking` | `updated_ranking` | `one_shot` | `persistent_initial` | `persistent_updated` |
|
||||
|
||||
完成原生分析与明确的展示外联后,我们返回*[本次实际观察到的数据与结果](result.ok(value=`观察`))*。
|
||||
|
||||
## format_once
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| report | map | required | 原生分析结果,包含 total 与 average 数值 |
|
||||
| locale | text | "zh-CN" | Node Intl 使用的展示语言区域 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | 直接返回 total/average 本地化文本;子进程或 JSON 失败保留原生诊断 |
|
||||
|
||||
使用 `report` 和 `locale`="zh-CN" 补足本地化货币展示。一次性外联只接收已经计算好的总额与平均值,不分组、不排序、不修改订单。传入数据由 Marqdo 的 input 通道编码为 JSON;Node 从标准输入流接收它,不读取任何路径,也不额外生成文件。
|
||||
|
||||
代码围栏明确写出进程如何消费输入、建立 Intl 格式器以及输出唯一的 JSON 记录。标准输出只承载这个协议值,诊断保留在错误通道;混入其他打印会导致 JSON 解析失败,而不是被当作部分成功。这里选择人民币展示,不声称进行汇率换算或货币精度计算。
|
||||
|
||||
调用需要 process.exec 与已安装的 Node,超时为五秒。foreign.call 在进程失败或输出不是合法 JSON 时给出原生诊断,因此本函数的成功值就是格式化记录,不再套一个假造的通过标记。这个一次性子进程结束后没有可复用状态;持久会话的创建、两次求值和关闭由共享原生报表手册中的 format_summary 展示。
|
||||
|
||||
`输入` =
|
||||
|
||||
| report | locale |
|
||||
|---|---|
|
||||
| `report` | `locale` |
|
||||
|
||||
`格式化代码` =
|
||||
```node
|
||||
let raw = "";
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.on("data", chunk => { raw += chunk; });
|
||||
process.stdin.on("end", () => {
|
||||
const input = JSON.parse(raw);
|
||||
const money = new Intl.NumberFormat(input.locale, {style: "currency", currency: "CNY"});
|
||||
console.log(JSON.stringify({total: money.format(input.report.total), average: money.format(input.report.average)}));
|
||||
});
|
||||
```
|
||||
|
||||
接收完整输入后,我们返回*[执行有界的一次性展示边界并解析真实 JSON 返回](foreign.call(code=`格式化代码`, input=`输入`, timeout=5))*。
|
||||
@@ -1,49 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 一张订单,一份可执行的业务说明
|
||||
description: 叙述、数据、计算与断言共享同一个 .mq.md 源文件。
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
这份文档不是代码旁边的说明,也不是说明里贴的代码。下表既是给人读的订单,
|
||||
也是运行时直接使用的记录集合;下面的句子既解释业务规则,也参与计算。
|
||||
|
||||
`订单` =
|
||||
|
||||
| @ | 客户 | 单价 | 数量 | 提前天数 |
|
||||
|---|------|------|------|----------|
|
||||
| 1 | 青山实验室 | 120 | 3 | 10 |
|
||||
| 2 | 远望中心 | 80 | 5 | 4 |
|
||||
| 3 | 星尘工坊 | 200 | 1 | 14 |
|
||||
|
||||
逐行把「单价 × 数量」累加进`小计`。读者看到的是清单,机器执行的是同一张表。
|
||||
|
||||
We first **小计 = 0** for the next step.
|
||||
- [行](遍历 订单 为 行)
|
||||
We first **小计 = (`小计` + ([单价](access(`行`, "单价")) * [数量](access(`行`, "数量"))))** for the next step.
|
||||
|
||||
业务约定写在叙述里:提前不少于七天,整单按九五折;否则原价。
|
||||
本单最早提前 14 天。
|
||||
|
||||
We first **最早提前 = 14** for the next step.
|
||||
1. `最早提前` >= 7
|
||||
We first **折后 = ((`小计` * 95) / 100)** for the next step.
|
||||
2. *
|
||||
We first **折后 = `小计`** for the next step.
|
||||
|
||||
把结果、依据和判断一起写进文档。下面的断言如果跑不通,文档本身就是错的。
|
||||
|
||||
We first **含税 = ((`折后` * 106) / 100)** for the next step.
|
||||
We now **[Display this step's result](> print text=`小计`)**.
|
||||
We now **[Display this step's result](> print text=`折后`)**.
|
||||
We now **[Display this step's result](> print text=`含税`)**.
|
||||
|
||||
1. `含税` < 10000
|
||||
We now **[Display this step's result](> print text="within-cap")**.
|
||||
2. *
|
||||
We now **[Display this step's result](> print text="over-cap")**.
|
||||
@@ -1,43 +0,0 @@
|
||||
# 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.
|
||||
@@ -1,469 +0,0 @@
|
||||
---
|
||||
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 | `原因` |
|
||||
|
||||
我们返回*[用于拒绝发单的统一失败回执](`失败回执`)*。
|
||||
@@ -1,48 +0,0 @@
|
||||
# 采购智能体:验收与真实接口接入说明
|
||||
|
||||
## 工程放置方式
|
||||
|
||||
建议把 `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` 只表示本地演练的门禁通过,不表示真实订单提交成功。
|
||||
- 模拟工单号含秒级时间戳,不保证跨调用唯一,也不能充当生产幂等键。
|
||||
@@ -1,11 +0,0 @@
|
||||
# quantum-bell
|
||||
|
||||
Bell |Φ⁺⟩ via `ext/quantum` circuit table + draw (default `theme=dark` tech lab SVG).
|
||||
|
||||
```bash
|
||||
cargo build -p marqdo_plugin_quantum
|
||||
marqdo ext add quantum # after rebuild, so view loads the new .so
|
||||
marqdo run examples/quantum-bell/index.mq.md
|
||||
```
|
||||
|
||||
Writes `bell.svg` next to the program (sandbox cwd). Themes: `theme="dark"|"light"|"bw"` — see [ext-quantum-viz-style.md](../../doc/design/ext-quantum-viz-style.md).
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Bell state
|
||||
description: H then CX; probabilities ≈ 1/2; circuit SVG.
|
||||
import:
|
||||
quantum: ext/quantum/circuit/index.mq.md
|
||||
math: lib/math.mq.md
|
||||
json: lib/json.mq.md
|
||||
---
|
||||
|
||||
# Bell |Φ+⟩
|
||||
|
||||
|
||||
H on qubit 0, then CNOT(0→1). Ideal measurement: |00⟩ and |11⟩ each with probability 1/2.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
`steps` =
|
||||
|
||||
| step | gate | qubits |
|
||||
|------|------|--------|
|
||||
| 1 | H | 0 |
|
||||
| 2 | CX | 0,1 |
|
||||
|
||||
We first **qc = [Compute qc](quantum.circuit(qubits=2, steps=`steps`))** for the next step.
|
||||
We first **p = [Compute p](qc.probabilities())** for the next step.
|
||||
We first **_ = [Compute _](qc.draw(path="bell.svg"))** for the next step.
|
||||
We first **_ = [Compute _](qc.draw(kind="probs", path="bell-probs.svg"))** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`p`)**.
|
||||
@@ -1,14 +0,0 @@
|
||||
# quantum-entanglement
|
||||
|
||||
Bell |Φ⁺⟩ **entanglement lab** via `ext/quantum` Q7/Q8: density matrix, partial trace, Schmidt entropy, and SVG plots (circuit themed dark by default; hinton / qsphere / multibloch / city).
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo_plugin_quantum
|
||||
marqdo ext add quantum # once (re-run after rebuilding the plugin)
|
||||
marqdo run examples/quantum-entanglement/index.mq.md
|
||||
# optional: marqdo view examples/quantum-entanglement/
|
||||
```
|
||||
|
||||
Prints probabilities, full/reduced purity, ⟨ZZ⟩, and Schmidt entropy; writes SVGs next to the program (sandbox cwd). Circuit/probs/bloch accept `theme="dark"|"light"|"bw"`.
|
||||
|
||||
Design: [ext-quantum-q7.md](../../doc/design/ext-quantum-q7.md) · [ext-quantum-viz-style.md](../../doc/design/ext-quantum-viz-style.md) · sibling: [quantum-bell](../quantum-bell/).
|
||||
@@ -1,56 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Entanglement lab
|
||||
description: Bell state — density, partial trace, Schmidt, themed SVG (Q7/Q8).
|
||||
import:
|
||||
quantum: ext/quantum/circuit/index.mq.md
|
||||
math: lib/math.mq.md
|
||||
---
|
||||
|
||||
# Entanglement from a runnable document
|
||||
|
||||
|
||||
Build |Φ⁺⟩ with H then CX. Full-state purity stays 1; tracing out one qubit yields a mixed state (purity 1/2). Schmidt coefficients and entropy quantify the bipartition. SVG plots (hinton / qsphere / multibloch) make the same facts visible.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
Prepare a two-qubit Bell state by applying H and then controlled-X. The full density matrix is pure, while tracing out one qubit leaves a mixed reduced state; these are different questions about the same state. The ZZ expectation and Schmidt entropy give complementary checks, not additional measurements of an evolving physical device.
|
||||
|
||||
The five SVG outputs are real artifacts written through the quantum drawing API, so run in a disposable filesystem root with its required plugin and write effects. Their different views share the calculated state. Keep both numeric observations and generated paths when verifying the example; a successful file write alone does not establish the entanglement values.
|
||||
|
||||
`steps` =
|
||||
|
||||
| step | gate | qubits |
|
||||
|------|------|--------|
|
||||
| 1 | H | 0 |
|
||||
| 2 | CX | 0,1 |
|
||||
|
||||
We first **qc = [Compute qc](quantum.circuit(qubits=2, steps=`steps`))** for the next step.
|
||||
We first **p = [Compute p](> `qc`.probabilities)** for the next step.
|
||||
|
||||
We first **rho = [Compute rho](> `qc`.density)** for the next step.
|
||||
We first **pur = [Compute pur](> `rho`.purity)** for the next step.
|
||||
We first **red = [Compute red](> `rho`.partial_trace keep=0)** for the next step.
|
||||
We first **rpur = [Compute rpur](> `red`.purity)** for the next step.
|
||||
|
||||
We first **zz = "ZZ"** for the next step.
|
||||
We first **ezz = [Compute ezz](> `qc`.expect obs=`zz`)** for the next step.
|
||||
|
||||
We first **sch = [Compute sch](> `qc`.schmidt cut=1)** for the next step.
|
||||
We first **ent = [entropy](access(`sch`, "entropy"))** for the next step.
|
||||
|
||||
We first **_ = [Compute _](> `qc`.draw path="entangle-circuit.svg" theme="dark")** for the next step.
|
||||
We first **_ = [Compute _](> `qc`.draw kind="hinton" path="entangle-hinton.svg")** for the next step.
|
||||
We first **_ = [Compute _](> `qc`.draw kind="qsphere" path="entangle-qsphere.svg")** for the next step.
|
||||
We first **_ = [Compute _](> `qc`.draw kind="multibloch" path="entangle-multibloch.svg")** for the next step.
|
||||
We first **_ = [Compute _](> `rho`.draw kind="city" path="entangle-city.svg")** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`p`)**.
|
||||
We now **[Display this step's result](> print text=`pur`)**.
|
||||
We now **[Display this step's result](> print text=`rpur`)**.
|
||||
We now **[Display this step's result](> print text=`ezz`)**.
|
||||
We now **[Display this step's result](> print text=`ent`)**.
|
||||
@@ -1,36 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: GHZ state
|
||||
description: 3-qubit GHZ; |000⟩/|111⟩ ≈ 1/2; probs + H matrix heatmap.
|
||||
import:
|
||||
quantum: ext/quantum/circuit/index.mq.md
|
||||
gate: ext/quantum/gate/index.mq.md
|
||||
---
|
||||
|
||||
# GHZ
|
||||
|
||||
|
||||
H on qubit 0, CX(0→1), CX(0→2). Ideal: |000⟩ and |111⟩ each with probability 1/2.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
`steps` =
|
||||
|
||||
| step | gate | qubits |
|
||||
|------|------|--------|
|
||||
| 1 | H | 0 |
|
||||
| 2 | CX | 0,1 |
|
||||
| 3 | CX | 0,2 |
|
||||
|
||||
We first **qc = [Compute qc](quantum.circuit(qubits=3, steps=`steps`))** for the next step.
|
||||
We first **p = [Compute p](qc.probabilities())** for the next step.
|
||||
We first **_ = [Compute _](qc.draw(path="ghz.svg"))** for the next step.
|
||||
We first **_ = [Compute _](qc.draw(kind="probs", path="ghz-probs.svg"))** for the next step.
|
||||
We first **H = [Compute H](gate.gate(name="H"))** for the next step.
|
||||
We first **_ = [Compute _](H.draw(kind="matrix", path="ghz-h-matrix.svg"))** for the next step.
|
||||
|
||||
We now **[Display this step's result](> print text=`p`)**.
|
||||
@@ -1,25 +0,0 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Quantum skill call demo
|
||||
description: >-
|
||||
Agent-style flow via ext/quantum index and domain modules (Bell probabilities).
|
||||
import:
|
||||
circuit: ext/quantum/circuit/index.mq.md
|
||||
simulate: ext/quantum/simulate/index.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | None; execute this page's documented steps in order and observe their output or stated effects |
|
||||
|
||||
Build Phi-plus with domain skills, then print ideal probabilities. Prefer the
|
||||
same steps via marqdo call with --effects plugin and toget when an agent drives
|
||||
the session.
|
||||
|
||||
We first **qc = [Compute qc](circuit.new(qubits=2, steps=None))** for the next step.
|
||||
We first **qc = [Compute qc](circuit.hadamard(circuit=`qc`, qubit=0))** for the next step.
|
||||
We first **qc = [Compute qc](circuit.cnot(circuit=`qc`, control=0, target=1))** for the next step.
|
||||
We first **p = [Compute p](simulate.probabilities(circuit=`qc`))** for the next step.
|
||||
We now **[Display this step's result](> print text=`p`)**.
|
||||
Loaded 100 of 1880 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user