10 KiB
name, description
| name | description |
|---|---|
| marqdo-dev | Develop Marqdo programs and libraries the readable way: GFM tables as data, code-as-documentation, table.put over json.set chains, lib/ext authoring. Use when writing or refactoring .mq.md, creating lib/* or ext/*, reviewing Marqdo style, fixing unreadable json glue, or when the user asks how to develop Marqdo / 如何开发 marqdo. |
Marqdo development (author + library)
Read this before writing or expanding .mq.md. Syntax basics stay in marqdo; this skill is the style and library craft contract.
Non-negotiable: code is documentation
A .mq.md file must stay readable as Markdown. If a human cannot skim the data and intent without decoding nested json.set / json.append chains, the code is wrong.
| Prefer | Avoid |
|---|---|
| GFM tables for maps, lists, records, wire, commands | Building the same with json.set / json.append |
Named library helpers (web.*, browser.*, table.*) |
Copy-paste effect-map glue in every handler |
table.put for one dynamic key |
Long json.set pipelines |
json.parse / json.stringify / json.quote only |
Using json as a general dict builder |
lib/json is for parse / stringify / quote. Collection edits use GFM tables and lib/table (doc/design/stdlib-table.md).
How to shape data
1. GFM table geometry (memorize)
| Shape | Result |
|---|---|
| 1 column | list |
| ≥2 columns, one data row | map (headers = keys) |
| ≥2 columns, many rows | map of lists (column-oriented) |
First header @ / 行 / row |
list of maps (row records) |
Cells are expressions (doc/design/table-cell-expressions.md): bare words = text, `var` = variable, quote paths// ratios.
2. Good patterns (copy these — not json.set)
Wire / steps / commands — @ record table:
`wire` =
| @ | 选择器 | 事件 | 调用 |
|---|--------|------|------|
| 1 | "#bump" | click | bump |
Multi-key return / boot — map table with variable cells:
`boot` =
| wire | set_text |
|------|----------|
| `wire` | `set_text` |
Agent / LLM result map — one readable row, not a json.parse + json.set chain:
`out` =
| status | task | result | llm_calls | tokens |
|--------|------|--------|-----------|--------|
| ok | `task` | `reply` | `llm_calls` | `tokens` |
*out*
Soft error pack (transport / gate failure) — still a table humans can skim:
`pack` =
| finish | text | error | usage | tool_calls |
|--------|------|-------|-------|------------|
| error | "" | `msg` | `usage0` | `empty_tc` |
*pack*
Optional / conditional key — sparse table.put after the static table (one dynamic key only):
`out` =
| status | task |
|--------|------|
| error | `task` |
1. `err`
**out = > table.put in=`out` at="error" value=`err`**
2. *
**_ = 1**
Empty list / empty map — prefer stdlib seeds over json.parse text=[] / {}:
**empty_tc = > table.empty_list**
**empty_map = > table.empty_map**
Single dynamic key from scratch — one table.put (or a helper), not a json chain:
**`set_text` = table.put in=None at="#log" value=msg**
**table.put in=None at="set_text" value=set_text**
Better still — call a named helper:
**browser.set_text sel="#log" text=msg**
When json.* is OK: json.parse / json.stringify / json.quote on wire text; json.get to read an opaque map. Never use json.set / json.append to build author-facing structures.
3. Bad pattern (do not write — and do not copy from old ext/ai)
**`ret` = json.set map=None key="set_text" value=…**
**`ret` = json.set map=ret key="canvas" value=…**
**`cmds` = json.append list=cmds item=c0**
**`out` = json.parse text={"status":"ok"}**
**`out` = json.set map=out key="task" value=task**
Matching surrounding legacy json.set in ext/ai/*.mq.md is not compliance. Refactor the call site to tables / table.put instead of extending the glue.
Writing application .mq.md
- Frontmatter: title + imports (
table, domain libs). Do not importjsonunless parsing strings. # main: state binds, then tables for wire/config, return boot map via table or helper.##handlers: short prose OK; data as tables; return viabrowser.*/web.*/ onetable.put.- Blank line between comment paragraphs and code.
- Run
marqdo run path.mq.mdfrom repo root. - Calls in narrative: explain the action in its sentence, for example
读取之后得到**结果 = [读取文件](文件.读文本(路径=`路径`))**。Return in the sentence with完成后返回*结果*。Keep real control structures and data tables separate when that improves reading. The label describes intent; the payload contains the actual call. See the executable library development guide. - Do not use
##inside# mainfor document sectioning — those become nested functions. Use paragraphs /---breaks instead. - Index: use
access(collection, key)(or取);[描述](payload)is executable occlusion, never an index by label.
Browser client programs: prefer nested import: with browser: lib/browser.mq.md (no native plugin). Server sites: Artifact Metadata (type: web|endpoint) + ext/web facade + ext/data / ext/security / ext/net — see ext-web-artifact.md. Never restore compose_* / app.configure.
Developing libraries (lib/*, ext/*)
Start with the executable library development guide: parameter/return tables below headings, prose >50%, inline assignments/returns and occlusion labels. Single-file stdlib needs no index; multi-file extensions organize through index.mq.md.
Design background + waves: lib-code-as-docs.md · roadmap/lib-ext-code-as-docs.md.
Goals
- Authors see tables and short calls; library may hide
table.put/ host calls. - One concern per helper; name the effect (
set_text,canvas, …), do not expose bag surgery. - EN + ZH pair when shipping user-facing libs (
lib/browser.mq.md↔lib/浏览器.mq.md,ext/web↔ext/web/网页.mq.md). ext/**never callshost_*— use plugins / public lib only (doc/design/ext-agent.md).- Collection get:
access(coll, key); bracket labels are inert descriptions. Calls in examples may use修饰 [fn] …or classic>/ bold.
Library checklist
- Single-file stdlib is its own handbook; no forced index/module guide directory
- Parameter/type/default table directly below the function heading, then return contract
- Prose parameters; remove legacy
+declarations in standard library sources - Explain purpose, real input shape, output, failure and limits; narrative >50% per function
- Put assignments, occlusion calls and returns in explanatory sentences where natural; reserve separate blocks for real structure
- Use
[action](actual code)inside return/statement markers for opaque host calls - One actual example + short implementation; never pad prose to satisfy the ratio
- Public examples use tables + helpers, not json glue
- Read with
access(c, k); foreach- [description](遍历 coll 为 item) - Function heading names the tool; tables and task explanation follow it
- Defaults on params; omit
Nonefields in merged maps - No
json.setchains in new code — usetable.put/table.merge/ GFM marqdo runon a tiny demo underexamples/or inline smoke
Where helpers live
| Need | Place |
|---|---|
| Browser effect maps (WASM client) | lib/browser.mq.md |
| Site HTML / HTTP | ext/web Document/Endpoint + View tables |
| DB / cache / storage | ext/data |
| Auth / OIDC / RBAC | ext/security |
| List/map primitives | lib/table.mq.md |
| Parse JSON text | lib/json.mq.md only |
Refactoring existing glue
When editing a file full of json.set:
- Turn static structures into GFM tables.
- Replace repeated effect shapes with
browser.*/web.text_patch/web.dom_patch. - Leave at most sparse
table.putfor dynamic keys. - Drop unused
json:(or other) entries under nestedimport:.
Anti-patterns
| Wrong | Right |
|---|---|
json.set × N to build boot |
GFM map table or browser/web helper |
json.append to build command list |
@ record table |
| Dummy column to force a 1-key map | table.put or helper |
Importing ext/web only for text_patch in WASM |
lib/browser (no native plugin) |
| Unreadable nested maps as “clever” | Flatten into tables humans can read |
Related
- Syntax: marqdo/SKILL.md · examples.md
- Tables:
doc/design/stdlib-table.md·doc/design/table-cell-expressions.md - Browser effects:
doc/roadmap/browser-wasm-e.md·doc/roadmap/browser-wasm-f.md - Release: marqdo-release
渐进式契约 + MLSP(Phase 2/3 落地后的开发戒律)
- 契约实现:
src/contract.rs(类型词汇 / 三形状契约表解析 / 合并 / 四边界校验诊断);src/parse/mod.rs::extract_function_contract(位置 + 形状双重判定,在升参推断之前执行; 绑定表与普通文档表绝不吃 ⇒ 无契约文件零回归)。契约表从 body 移除——元数据永不执行。 - 静态互查:
src/check.rs(marqdo check [--json])——契约行 vs 升参推断形参双向漂移、 未知类型名、错位契约;Error ⇒ 非零退出。 - AI 工具面:
src/mlsp.rs(marqdo mlsp,行分隔 JSON)——locate/syntax/validate/repair_targets/schema。语法唯一事实来源 =parse::CORE_CONSTRUCTS(CI 守卫与doc/design/core-surface.md同步);MLSP 只加检索别名,不定义语法。 - 准入戒律:新特性先过
doc/design/layers.md三层归属(Language 层改动须 ADR + core-surface); 新契约形状/类型词汇 = 文档层扩展,进src/contract.rs,不进词法/语法。 - 错误出口唯一:
src/load.rs::label_error已示范——装载层/任何新代码都不许把Diagnostic拍平成字符串;错误链里必须能Diagnostic::find找回结构化诊断(AI/MLSP 面)。