CLI 命令参考
mddb --help 列出已安装版本的全部命令。所有 FILE 参数都指向 一个 UTF-8 Markdown 文件。JSON 输出使用真正的布尔值和 null。
本页上半部分是中文速查,参数与源码 mddb/cli.py 一致;下半部分 规范原文 直接引用仓库中的 docs/cli.md,二者如有出入以规范原文和 mddb --help 为准。
全局
| 用法 | 说明 |
|---|---|
mddb --version | 打印版本号 |
mddb --help | 列出命令;mddb 命令 --help 查看单个命令 |
创建与发现
| 命令 | 说明 |
|---|---|
mddb init FILE | 写入起始模板并打印文件名;文件已存在时拒绝覆盖 |
mddb tables FILE | 列出表名、来源、行数、字段与推断类型 |
mddb inspect FILE [--format table|json] | 列出所有可寻址路径(meta.*、sections.*、objects.*、tables.*、lists.*) |
mddb dump FILE [--format json] | 输出完整命名空间 JSON |
查询与修改表格
| 命令 | 说明 |
|---|---|
mddb query FILE SQL [--format table|json|csv|md] | 只读 SQLite 查询,默认 table 格式 |
mddb exec FILE SQL [--dry-run] | 单表单语句修改:INSERT/UPSERT、UPDATE、DELETE、ALTER TABLE … ADD COLUMN |
mddb query notebook.md 'SELECT id,title,status FROM tasks' --format json
mddb exec notebook.md "INSERT INTO tasks (id,title,status) VALUES (3,'Write docs','TODO')" --dry-run
mddb exec notebook.md "ALTER TABLE tasks ADD COLUMN owner TEXT" --dry-run一次只能执行一条语句;多条语句会以退出码 1 失败。
读写路径
| 命令 | 说明 |
|---|---|
mddb get FILE PATH [--format raw|json] | 读取元数据、段落、对象、表格或清单投影。默认 raw:字符串原样输出,其它值输出 JSON |
mddb set FILE PATH VALUE [--json] [--dry-run] | 在可写的 meta.*、sections.*、objects.* 路径写值。默认写字符串;--json 把 VALUE 按 JSON 解析 |
mddb get notebook.md objects.goals.limits.target_ms --format json
mddb set notebook.md objects.goals.limits.target_ms 250 --json --dry-run
mddb set notebook.md sections.summary 'Ship the docs site.' --dry-run命名清单
| 命令 | 说明 |
|---|---|
mddb list check FILE NAME TEXT [--dry-run] | 勾选命名清单中文本完全匹配的条目 |
mddb list uncheck FILE NAME TEXT [--dry-run] | 取消勾选 |
mddb list add FILE NAME TEXT [--done] [--dry-run] | 追加条目;--done 表示直接以已完成状态添加 |
只适用于带 <!-- mddb:list name=… --> 标记的清单。普通列表请用 资源 API。
报告与服务
| 命令 | 说明 |
|---|---|
mddb render FILE --template TEMPLATE -o OUTPUT | 把数据快照嵌入 HTML 模板,写到 OUTPUT(也可写作 --output) |
mddb serve FILE --template TEMPLATE [--host HOST] [--port PORT] | 只读实时视图,默认 127.0.0.1:8765 |
mddb workspace --directory DIRECTORY [--port PORT] [--seed] | 本机块工作空间与资源 API,默认端口 8772,只监听回环地址 |
Agent Skill
| 命令 | 说明 |
|---|---|
mddb skill path | 打印安装包自带 Skill 的目录 |
mddb skill install --target DIRECTORY | 把 Skill 安装到 DIRECTORY/mddb;已有不同内容时拒绝覆盖 |
预览与保存
exec、set、list 都支持 --dry-run:输出统一差异,不写文件。去掉 --dry-run 即保存,成功时没有输出。每次 CLI 调用都读取新的文件快照,之前的 dry-run 不会锁定之后调用的版本;需要把保存绑定到某次预览时,请使用 资源 API。
退出码
| 退出码 | 含义 |
|---|---|
0 | 成功 |
1 | 运行或校验失败 |
2 | 命令行参数无效 |
规范原文
以下内容直接引用自仓库 docs/cli.md(英文),随仓库更新。
mddb --help lists the installed commands. All file arguments refer to one UTF-8 Markdown file. JSON output uses real booleans and nulls.
| Command | Purpose |
|---|---|
init FILE | Create a starter; refuse an existing file |
tables FILE | Discover table names, columns and inferred types |
query FILE SQL --format json | Read-only SQLite projection; also table, csv and md output |
exec FILE SQL --dry-run | Diff for one-table INSERT/UPSERT, UPDATE, DELETE or ADD COLUMN |
inspect FILE --format json | Discover namespace paths |
get FILE PATH --format json | Read metadata, section, object, table or checklist projection |
set FILE PATH VALUE --json --dry-run | Preview a JSON value at a writable metadata/section/object path |
list check FILE NAME TEXT | Complete an exact named checklist item; also uncheck and add |
dump FILE | Complete namespace projection as JSON |
render FILE --template TEMPLATE -o OUTPUT | Embed a static data snapshot in HTML |
serve FILE --template TEMPLATE --port PORT | Read-only live view, loopback by default |
workspace --directory DIRECTORY | Local block UI and revision-bound write API |
skill path / skill install --target DIRECTORY | Locate or install the bundled Skill |
Remove --dry-run to save. set defaults to a string; --json parses JSON. list add accepts --done. Exit codes are 0 success, 1 runtime/validation failure, 2 invalid arguments. The CLI takes a fresh snapshot for each invocation; a previous dry-run does not pin a later invocation's revision. Use the resource API when the write must be bound to a specific preview snapshot.
Tables
Ordinary pipe tables work without markers. The nearest heading supplies a name; the CLI reports disambiguated names. A single table also has alias t and an alias based on the file stem. Quote identifiers with spaces. Explicit names, primary keys and types use an adjacent comment:
<!-- mddb:table name=tasks pk=id schema="id:int,title:text,status:text" -->
| id | title | status |
| --- | --- | --- |
| 1 | Review | TODO |Types: int/integer, real/float, text, bool/boolean. Otherwise infer from non-empty cells. Empty cells become SQL NULL; non-finite numbers, BLOB and NUL cannot be written. Escaped pipes/backslashes and line breaks round-trip through supported encodings. Updates preserve all bytes outside the target table, but reformat that table. SQL constraints added only in the temporary SQLite schema do not automatically persist to future reads.
Other namespaces
- YAML Frontmatter is addressed as
meta.statusormeta.release.version. - A section between
<!-- mddb:section name=summary -->and<!-- /mddb:section -->is addressed assections.summary. - A fenced JSON/YAML block preceded by
<!-- mddb:object name=goals format=json -->is addressed asobjects.goals, including nested keys and numeric array indices such asobjects.goals.items.0.name. - A checklist preceded by
<!-- mddb:list name=signoff -->is a named CLI checklist. Ordinary lists without that marker are managed through the workspace block API instead.
YAML is a documented subset for configuration data, not a full YAML implementation: mappings, sequences, scalar strings/numbers/booleans/null. Unsupported forms fail explicitly. A malformed optional namespace does not make the older table-only query interface parse that namespace.
HTML snapshots
Templates must contain exactly one closed <script id="mddb-data" type="application/json"></script>. MDDB embeds the namespace as escaped JSON. Template code controls display; template scripts are trusted local code. Export refuses to overwrite the source/template, including hard-link aliases. Generated reports have snapshot data; live preview rereads the file.