Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:memo: Use plain language in documentation and API reference (#19518)

Jeffrey Chen72b837905b85
diff --git a/.github/CONTRIBUTING.zh-CN.md b/.github/CONTRIBUTING.zh-CN.md
index 495c8f9bb8..f15b66b1a8 100644
--- a/.github/CONTRIBUTING.zh-CN.md
+++ b/.github/CONTRIBUTING.zh-CN.md
@@ -14,7 +14,7 @@ Electron 44 要求 macOS 13 或更高版本,Windows 和 Linux 仅支持 64 位
版本以 [`app/package.json`](../app/package.json) 的 `packageManager` 字段为准;该字段变更后,请相应调整上述命令中的版本号。此安装方式与 [CI](workflows/cd.yml) 保持一致。
-不要与 pnpm 独立安装脚本(`@pnpm/exe`)混用。不同的 pnpm 发行包可能改变 `app/pnpm-lock.yaml` 中的 `packageManagerDependencies` 元数据,产生与依赖无关的锁文件变更。如果此前安装过独立版 pnpm,请将其移出 `PATH` 或卸载,确保优先使用通过 npm 安装的 pnpm。安装依赖前,请用 `pnpm --version` 核对版本是否与 `packageManager` 一致,并在 Windows 上用 `where.exe pnpm`、在 macOS/Linux 上用 `command -v pnpm` 检查可执行文件的位置。提交前请检查锁文件差异,排除因切换安装方式产生的纯元数据变更。
+不要与 pnpm 独立安装脚本(`@pnpm/exe`)混用。不同的 pnpm 发行包可能改变 `app/pnpm-lock.yaml` 中的 `packageManagerDependencies` 元数据,产生与依赖无关的锁文件变更。如果此前安装过独立版 pnpm,请将其移出 `PATH` 或卸载,以确保优先使用通过 npm 安装的 pnpm。安装依赖前,请用 `pnpm --version` 核对版本是否与 `packageManager` 一致,并在 Windows 上用 `where.exe pnpm`、在 macOS/Linux 上用 `command -v pnpm` 检查可执行文件的位置。提交前请检查锁文件差异,排除因切换安装方式产生的纯元数据变更。
<details>
<summary>适用于中国大陆</summary>
@@ -41,7 +41,7 @@ NPM 镜像:
注意:Electron 42 起在 `pnpm install` 时不再自动下载二进制。需先执行 `pnpm run install:electron`(中国大陆请先设置 `ELECTRON_MIRROR`)拉取二进制,再 `pnpm run start`。
-注意:在开发环境下不会自动拉起内核进程,需要先手动拉起内核进程。
+注意:在开发环境下不会自动启动内核进程,需要先手动启动。
## 内核
diff --git a/README.zh-CN.md b/README.zh-CN.md
index fc2640ec95..6ef4474cc3 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -102,7 +102,7 @@
- 数据库
- 表格视图
- 闪卡间隔重复
-- 接入 OpenAI 接口支持人工智能写作和问答聊天
+- 连接 OpenAI 接口支持人工智能写作和问答聊天
- Tesseract OCR
- 模板片段
- JavaScript/CSS 代码片段
@@ -193,7 +193,7 @@
入口点在构建 Docker 镜像时设置:`ENTRYPOINT ["/opt/siyuan/entrypoint.sh"]`。该脚本允许更改将在容器内运行的用户的 `PUID` 和 `PGID`。这对于解决从主机挂载目录时的权限问题尤为重要。`PUID` 和 `PGID` 可以作为环境变量传递,这样在访问主机挂载的目录时就能更容易地确保正确的权限。
-使用 `docker run b3log/siyuan` 运行容器时,请带入以下参数:
+使用 `docker run b3log/siyuan` 运行容器时,请指定以下参数:
- `--workspace`:指定工作空间文件夹路径,在宿主机上通过 `-v` 挂载到容器中
- `--accessAuthCode`:指定锁屏密码
@@ -264,7 +264,7 @@ services:
在此设置中:
- PUID “和 ”PGID "是动态设置并传递给容器的
-- 如果没有提供这些变量,将使用默认的 `1000`
+- 如果没有提供这些变量,则使用默认的 `1000`
在环境中指定 `PUID` 和 `PGID` 后,就无需在 compose 文件中明确设置 `user` 指令(`user: '1000:1000'`)。容器将在启动时根据这些环境变量动态调整用户和组。
@@ -319,7 +319,7 @@ kubectl -n siyuan port-forward service/siyuan-siyuan 6806:6806
远程访问时,请使用独立的 HTTPS 域名,以及支持代理 `/ws` WebSocket 连接的 Ingress 控制器,不要进行 URL 重写。配置 `ingress`,并通过 `networkPolicy.ingressFrom` 允许控制器所在命名空间的流量;默认策略仅允许同命名空间的入站流量和 DNS 出站流量。云端同步等外部服务需要显式配置出站规则。TLS、现有 Secret 和存储配置请参阅 [Chart 指南及生产环境示例](https://helmforge.dev/docs/charts/siyuan)。
- **一个工作区只能有一个写入实例:** 不要增加副本数,也不要将同一工作区挂载到另一个运行中的实例,即使使用 ReadWriteMany 存储也不例外。Chart 使用 `Recreate` 策略,升级时会先停止旧实例,再启动新实例,因此会有服务中断。
-- **持久化:** 完整工作区挂载在 `/siyuan/workspace`。默认情况下,卸载 Chart 会保留其创建的 PVC,但删除命名空间或 PVC 仍可能导致数据丢失。通过 `persistence.existingClaim` 复用保留或恢复后的存储卷声明。
+- **持久化:** 完整工作区挂载在 `/siyuan/workspace`。默认情况下,卸载 Chart 会保留其创建的 PVC,但删除命名空间或 PVC 仍可能导致数据丢失。可通过 `persistence.existingClaim` 复用保留或恢复后的存储卷声明。
- **备份与升级:** 备份完整工作区前,请正常停止写入实例,或使用能够保证应用一致性的备份流程。仅复制运行中的 SQLite 索引文件无法保证备份完整且一致。请妥善保管保存锁屏密码的 Secret、加密密钥和加密笔记本恢复密码,并在独立 PVC 上测试恢复。升级前先备份,并确认新版本是否涉及存储格式变更:Helm 回滚不会撤销数据迁移。
Docker 部署的限制同样适用:仅支持浏览器访问,不支持桌面端和移动端应用连接,不支持导出 PDF、HTML 和 Word 格式,也不支持导入 Markdown 文件。
@@ -564,7 +564,7 @@ CLI 可执行文件为 `<安装目录>/resources/kernel/SiYuan-Kernel`,可通
### 思源是如何存储数据的?
-数据保存在工作空间文件夹下,在工作空间 data 文件夹下:
+数据保存在工作空间 data 文件夹下:
- `assets` 用于保存所有插入的资源文件
- `emojis` 用于保存自定义图标表情图片
@@ -580,7 +580,7 @@ CLI 可执行文件为 `<安装目录>/resources/kernel/SiYuan-Kernel`,可通
不支持通过第三方同步盘进行数据同步,否则可能会导致数据损坏。
-虽然不支持第三方同步盘,但是支持对接第三方云端存储(会员特权)。
+虽然不支持第三方同步盘,但是支持连接第三方云端存储(会员特权)。
### 思源是开源的吗?
diff --git a/docs/API-CONTRACTS.md b/docs/API-CONTRACTS.md
index 44c64a4f14..b47765d27c 100644
--- a/docs/API-CONTRACTS.md
+++ b/docs/API-CONTRACTS.md
@@ -34,7 +34,7 @@ Encrypted notebook lifecycle endpoints use typed requests and responses while re
## Compatibility requirements
-Encrypted notebook system-lock endpoints preserve administrator authorization and read-only checks. The boolean preference lives in system configuration, outside authenticated key backups. `TestAPIContractNotebookSystemLock` covers persistence, disabled behavior, independence from the idle timeout, multiple notebooks (including an unlocked but unmounted notebook), repeated locking, denied reads after locking, and authenticated reads of unchanged ciphertext after re-unlocking. It is included in the full kernel command below; run it separately with `go test -tags "fts5 sqlcipher" ./api -run 'TestAPIContractNotebook(SystemLock|CryptoAuthorization)$' -count=1`. `TestNotebookSystemLockContract` covers strict boolean input and `TestRouteCoverage` checks registration and handler bindings.
+Encrypted notebook system-lock endpoints preserve administrator authorization and read-only checks. The boolean preference is stored in system configuration, outside authenticated key backups. `TestAPIContractNotebookSystemLock` covers persistence, disabled behavior, independence from the idle timeout, multiple notebooks (including an unlocked but unmounted notebook), repeated locking, denied reads after locking, and authenticated reads of unchanged ciphertext after re-unlocking. It is included in the full kernel command below; run it separately with `go test -tags "fts5 sqlcipher" ./api -run 'TestAPIContractNotebook(SystemLock|CryptoAuthorization)$' -count=1`. `TestNotebookSystemLockContract` covers strict boolean input and `TestRouteCoverage` checks registration and handler bindings.
At migration completion on September 14, 2026, all 629 method/path registrations in `kernel/api/router.go` were contracted and the legacy list was empty. At that baseline, four `ANY` registrations expanded to 661 concrete method/path pairs in generated metadata. Use the generator and route coverage checks for current counts as endpoints are added. Static resources, the main application WebSocket, and other transport services registered by `kernel/server/serve.go` are outside this API route inventory.
@@ -48,7 +48,7 @@ Plugin private services declare their existing serialization modes, raw files, r
Network contracts retain request bytes, multipart fields, headers, URL and TLS diagnostics, including complete certificate public-key structures and large integers. Forward proxy options preserve validation order, numeric truncation, response encodings, and protocol-defined JSON payloads. HTTP, EventSource, and WebSocket proxies retain upstream statuses and bytes, repeated-header behavior, security headers, stream cancellation, and connection cleanup. Echo wildcard paths bind their own adapter while sharing the same handler behavior.
-Attribute-view contracts declare table, gallery, and kanban results separately and retain missing base fields, cell patches, and null values. Known patch fields retain their supplied presence without filling omitted fields with zero values. Current, history, and snapshot rendering use their corresponding request types; callers handle error payloads before updating views. Row sorting, publish admission, encrypted-notebook leases, and fast JSON rendering preserve their existing behavior. Shared frontend and plugin declarations reflect the fields actually present in each view and cell.
+Attribute-view contracts declare table, gallery, and kanban results separately and retain missing base fields, cell patches, and null values. Known patch fields retain their supplied presence without populating omitted fields with zero values. Current, history, and snapshot rendering use their corresponding request types; callers handle error payloads before updating views. Row sorting, publish admission, encrypted-notebook leases, and fast JSON rendering preserve their existing behavior. Shared frontend and plugin declarations reflect the fields actually present in each view and cell.
AI contracts retain provider configuration, model discovery and matching, confirmation decisions, session extensions, and numeric and omission semantics. Editor and agent streams declare their actual SSE events; disconnection closes upstream requests, and stream lifetimes remain within the request. OAuth pages retain their media types, HTTP statuses, and security headers. Session permission notifications use `WithAfterWrite` to preserve response-before-broadcast ordering. Arbitrary JSON remains limited to protocol extension fields and tool results.
@@ -68,7 +68,7 @@ Sync contracts retain numeric truncation, conditional direction validation in ma
Marketplace contracts retain required-field ordering, whitespace handling, theme mode dependencies, rating availability and rate-limit payloads, and local-package upload errors. Package and appearance responses declare their complete nested structures, including the fixed five-element rating distribution. Upload requests keep first-file selection and overwrite parsing. Installation, removal, authentication, and publish restrictions remain in the existing business handlers and middleware.
-Plugin information queries retain path, query-string, and JSON-body name precedence, including whitespace and business error codes 1 through 4. URL parameters bypass body decoding, and list queries ignore the body. Plugin and RPC-method lists retain nullable arrays and entries. HTTP JSON-RPC has a separate contract for single and batch requests, success and error replies, and notification-only HTTP 204 responses. Plugin admission occurs before body reads, batch errors retain their order, and arbitrary JSON is limited to RPC parameters, results, and error details. RPC WebSocket routes declare HTTP 101 upgrades, HTTP 404 plugin admission errors, HTTP 400 text rejections, and separate incoming calls and outgoing replies or notifications. Origin authorization and connection cleanup remain in the existing upgrade lifecycle.
+Plugin information queries retain path, query-string, and JSON-body name precedence, including whitespace and business error codes 1 through 4. URL parameters skip body decoding, and list queries ignore the body. Plugin and RPC-method lists retain nullable arrays and entries. HTTP JSON-RPC has a separate contract for single and batch requests, success and error replies, and notification-only HTTP 204 responses. Plugin admission occurs before body reads, batch errors retain their order, and arbitrary JSON is limited to RPC parameters, results, and error details. RPC WebSocket routes declare HTTP 101 upgrades, HTTP 404 plugin admission errors, HTTP 400 text rejections, and separate incoming calls and outgoing replies or notifications. Origin authorization and connection cleanup remain in the existing upgrade lifecycle.
Search contracts retain pagination defaults and numeric truncation, path validation and deduplication, ignored historical subtype filters, and null versus empty arrays. Reference search distinguishes correlation-only responses from block results and retains notebook admission before deferred parameter validation. SQL search authorization, publish filtering, encrypted notebook leases, cancellation responses, and read-only embed-update no-ops remain in their original order. Desktop and mobile callers share generated request types.
@@ -104,7 +104,7 @@ Use `FailureWithTimeout` when a business error must preserve its message display
Notebook configuration updates use a typed partial object. The `legacyobject` field option preserves the existing JSON round-trip's numeric normalization and case-insensitive struct binding; optional pointer fields leave existing values unchanged when omitted or null. Encryption fields are decoded for input compatibility but never applied by the configuration patch. `Base64Bytes` explicitly models historical byte-slice inputs as Base64 strings or byte arrays.
-`JSONValue` is reserved for fields whose wire protocol explicitly accepts arbitrary JSON, such as an echoed correlation ID. Its schema is a recursive union of null, booleans, numbers, strings, arrays, and objects; it does not stand in for a structured request or response. Word-count results retain their fixed statistics fields independently of the correlation value.
+`JSONValue` is reserved for fields whose wire protocol explicitly accepts arbitrary JSON, such as an echoed correlation ID. Its schema is a recursive union of null, booleans, numbers, strings, arrays, and objects; it does not substitute for a structured request or response. Word-count results retain their fixed statistics fields independently of the correlation value.
Heading transaction queries return `BlockTransaction` with typed operations and preserve empty, null, and undo-operation payloads. `BlockOperationResult` declares the finite union of text, block ID arrays, and null. Conversion from the model's polymorphic fields rejects unsupported types; attribute-view operation payloads use their action-specific contracts. The editor's operation type also accepts the empty column-type field returned by non-attribute-view operations.
@@ -112,7 +112,7 @@ All `/api/block/` routes use contracts. Heading-level queries retain batch-ID pr
Storage contracts keep arbitrary JSON limited to storage values; keys, recent documents, search criteria, inline styles, and attribute-view palettes have structured types. Recent-document mutations retain their read-only no-op before parsing the body. An optional typed `beforeDecode` callback on `contractHandler` preserves this ordering and may return a response before decoding; route checks still require an explicit endpoint binding. Inline-style version 1 updates preserve existing built-in configuration, while version 2 and palette requests retain their struct-decoding compatibility.
-`DirectJSONOutput` preserves protocols that return their own JSON objects or arrays without the kernel envelope. Use `SuccessDirectJSON` for these payloads. Endpoints that also support empty notification responses explicitly declare `NoContent` and return `SuccessNoContent`; HTTP validation requires status 204 and an empty body. Authentication and read-only failures retain the kernel error envelope. Generated declarations record the direct output mode and optional empty-response support.
+`DirectJSONOutput` preserves protocols that return their own JSON objects or arrays without the kernel envelope. Use `SuccessDirectJSON` for these payloads. Endpoints that also support empty notification responses explicitly declare `NoContent` and return `SuccessNoContent`; HTTP validation requires status 204 and an empty body. However, authentication and read-only failures retain the kernel error envelope. Generated declarations record the direct output mode and optional empty-response support.
## File and streaming protocols
@@ -124,7 +124,7 @@ Endpoints with an empty HTTP response list its permitted statuses in `EmptyRespo
Page responses use `HTTPContentOptions` to declare permitted HTTP status and media-type pairs and `SuccessHTTPContent` to preserve their bytes. This uses the existing binary transport and keeps JSON middleware errors separate. `FastJSON` preserves selected large responses' accelerated JSON encoder without changing their typed payloads or response envelope; encoding failures retain the standard encoder fallback.
-`WebSocketOutput` uses `WebSocketOptions` to declare incoming and outgoing message types and the plugin admission failure status. `UpgradeWebSocket` hands the response writer to the connection lifecycle from `contractHandler`; `RejectWebSocket` serializes the declared rejection payload. Generated route metadata includes both message schemas, and `ValidateWebSocketMessage` validates frames separately from handshake responses and middleware envelopes. Handshake validation checks HTTP status and body; network regression tests verify upgrade headers, Origin rejection, message exchange, and cancellation.
+`WebSocketOutput` uses `WebSocketOptions` to declare incoming and outgoing message types and the plugin admission failure status. `UpgradeWebSocket` transfers the response writer to the connection lifecycle from `contractHandler`; `RejectWebSocket` serializes the declared rejection payload. Generated route metadata includes both message schemas, and `ValidateWebSocketMessage` validates frames separately from handshake responses and middleware envelopes. Handshake validation checks HTTP status and body; network regression tests verify upgrade headers, Origin rejection, message exchange, and cancellation.
Optional `*string` form fields preserve omission separately from an explicit empty string; use `nonnullable` because multipart text fields cannot contain JSON null. Import handlers use this distinction for defaults and delayed field validation. Upload progress starts before multipart parsing, and parse failures clear it before responding; Gin's cached form is reused for typed binding.
@@ -144,7 +144,7 @@ Dynamic multipart endpoints use `MultipartFields` to retain every text value and
Custom block search uses the optional `customBlock` type filter. Explicit API type maps select only their enabled types; omitted type maps use search settings, which enable custom blocks by default. Saved criteria preserve omission separately from `false` so older frontend search configurations can inherit the setting. `TestCustomBlockSearch` regressions cover configuration compatibility, saved criteria, filtering, and FTS updates; `TestAPIContractSettingConfigCompatibility` and `TestAPIContractSettingCompletePayloads` cover the setting contract. All are included in the full kernel command below.
-`TestAPIContractFileTreeMissingDocuments` exercises actual HTTP responses for missing documents during path lookup, removal, renaming, duplication, and moving. It checks business errors and preserved `closeTimeout` values against the response contracts and runs in the full kernel command below. Run it separately with `go test -tags "fts5 sqlcipher" ./api -run TestAPIContractFileTreeMissingDocuments -count=1` from `kernel/`.
+`TestAPIContractFileTreeMissingDocuments` tests actual HTTP responses for missing documents during path lookup, removal, renaming, duplication, and moving. It checks business errors and preserved `closeTimeout` values against the response contracts and runs in the full kernel command below. Run it separately with `go test -tags "fts5 sqlcipher" ./api -run TestAPIContractFileTreeMissingDocuments -count=1` from `kernel/`.
`swapBlockRef` accepts the optional boolean `originalToEmbed`. Omission or `false` keeps the reference at the original definition position; `true` replaces it with an embed querying the moved definition ID. `includeChildren` retains its heading and list behavior. `TestSwapBlockRefContractCompatibility` and `TestSwapBlockRefNodes` cover request defaults, invalid options, and both replacement modes across document, heading, and list cases; they run in the full kernel command below.
diff --git a/docs/API-CONTRACTS.zh-CN.md b/docs/API-CONTRACTS.zh-CN.md
index e040883431..0b223ab207 100644
--- a/docs/API-CONTRACTS.zh-CN.md
+++ b/docs/API-CONTRACTS.zh-CN.md
@@ -14,11 +14,11 @@
4. 更新实际响应、兼容输入和严格类型测试,运行生成器,再修正编译器指出的调用问题
5. 同步 `petal` 的生成声明和相关公共声明;公开接口同步更新接口文档
-生成检查读取实际路由与处理函数声明,验证方法、路径、处理函数和契约适配器的对应关系。CI 对照变更前的清单阻止增加存量记录。不得通过 `any`、类型断言或修改存量清单绕过契约检查。
+生成检查读取实际路由与处理函数声明,验证方法、路径、处理函数和契约适配器的对应关系。CI 对照变更前的清单阻止增加存量记录。不得通过 `any`、类型断言或修改存量清单规避契约检查。
## 契约与实现
-`kernel/apicontract/` 下的各模块文件定义请求、响应和端点,`contracts.go` 将其汇总到端点注册表。契约包独立于内核启动、数据库和持久化模型,生成器可以单独运行。API 入口通过 `contractHandler` 绑定端点,请求参数和成功返回值受到 Go 泛型签名约束;响应载荷通过构造函数设置,不能直接给通用 `ret.Data` 赋值。业务校验继续使用现有辅助函数,`contractFailure` 保留其错误码、消息和已支持的错误载荷。
+`kernel/apicontract/` 下的各模块文件定义请求、响应和端点,`contracts.go` 将其汇总到端点注册表。契约包独立于内核启动、数据库和持久化模型,因此生成器可以单独运行。API 入口通过 `contractHandler` 绑定端点,请求参数和成功返回值受到 Go 泛型签名约束;响应载荷通过构造函数设置,不能直接给通用 `ret.Data` 赋值。业务校验继续使用现有辅助函数,`contractFailure` 保留其错误码、消息和已支持的错误载荷。
生成器从同一组 Go 类型生成 `app/src/types/api/index.d.ts` 和 `kernel/apicontract/schema.json`。后者包含共享的 `$defs` 和每个端点的请求、响应 schema,测试使用同一套 schema 检查实际 HTTP 响应。类型声明不会在运行时验证 JSON,CI 中的处理函数测试负责验证序列化结果。
@@ -28,7 +28,7 @@
`Notebook` 是接口载荷,业务模型通过显式转换映射到该载荷,回归测试比较完整 JSON,包括各个加密状态。修改契约不会改变 `.sy`、数据库、历史、同步或加密格式。
-笔记本创建、重命名、删除、关闭、图标更新和排序已接入类型契约。重命名、删除和图标更新会去除笔记本 ID 两端空白;关闭保留空白并交给 ID 校验。空名称和空图标仍交给业务层处理,重命名失败保留提示显示时长。
+笔记本创建、重命名、删除、关闭、图标更新和排序已纳入类型契约。重命名、删除和图标更新会去除笔记本 ID 两端空白;关闭保留空白并由 ID 校验处理。空名称和空图标仍由业务层处理,重命名失败保留提示显示时长。
加密笔记本生命周期接口使用类型化请求与响应,保留密码去除两端空白、分钟数截断与负值归零、管理员权限、租约获取和挂载失败回滚。密钥派生、密文格式及恢复材料仍由模型层维护。
@@ -36,9 +36,9 @@
加密笔记本系统锁屏接口保留管理员鉴权和只读检查。布尔开关保存在系统配置中,不进入密钥备份的认证数据。`TestAPIContractNotebookSystemLock` 覆盖配置持久化、关闭开关、独立于闲置时间、多笔记本(包括仅解锁未挂载的笔记本)、重复锁定、锁定后拒绝读取,以及重新解锁后认证读取未改变的密文。该测试已包含在下文的内核全量命令中,也可单独运行 `go test -tags "fts5 sqlcipher" ./api -run 'TestAPIContractNotebook(SystemLock|CryptoAuthorization)$' -count=1`。`TestNotebookSystemLockContract` 覆盖严格布尔输入,`TestRouteCoverage` 检查路由注册和处理器绑定。
-2026 年 9 月 14 日迁移完成时,`kernel/api/router.go` 中的 629 条方法和路径注册均已接入契约,旧路由清单为空。该基线中的 4 条 `ANY` 注册在生成声明中展开为 661 条具体方法和路径。后续新增接口时,以生成器和路由覆盖检查的统计为准。由 `kernel/server/serve.go` 注册的静态资源、应用主 WebSocket 和其他传输服务不属于这份 API 路由清单。
+2026 年 9 月 14 日迁移完成时,`kernel/api/router.go` 中的 629 条方法和路径注册均已纳入契约,旧路由清单为空。该基线中的 4 条 `ANY` 注册在生成声明中展开为 661 条具体方法和路径。后续新增接口时,以生成器和路由覆盖检查的统计为准。由 `kernel/server/serve.go` 注册的静态资源、应用主 WebSocket 和其他传输服务不属于这份 API 路由清单。
-系统契约保留完整配置、工作空间管理、上传、认证、OIDC 响应分支、启动事件流以及空响应和二进制响应。前端在读取持久化布局和快捷键的位置收窄类型,保留原有默认值修复、废弃键清理和绑定过滤逻辑。配置导入、导出和退出保持原有生命周期及加密行为。
+系统契约保留完整配置、工作空间管理、上传、认证、OIDC 响应分支、启动事件流以及空响应和二进制响应。前端在读取持久化布局和快捷键的位置缩小类型,保留原有默认值修复、废弃键清理和绑定过滤逻辑。配置导入、导出和退出保持原有生命周期及加密行为。
事务契约按动作区分全部 98 个已知操作,并在显式未知操作兼容分支中排除这些名称。前端使用同一组有限操作联合。私有原始输入保留历史字段、被忽略的值、模型异步错误和回传载荷,类型声明不把模型校验提前到 HTTP 准入阶段。撤销、重做、标题操作、响应租约及事务持久化格式保持原有行为。
@@ -48,7 +48,7 @@
网络契约保留请求字节、表单字段、请求头、URL 和 TLS 诊断信息,包括完整证书公钥结构与大整数。转发代理选项保留校验顺序、数字截断、响应编码及协议定义的 JSON 载荷。HTTP、EventSource 和 WebSocket 代理保留上游状态与字节、重复请求头行为、安全响应头、流取消和连接清理。回显通配路径绑定独立适配器,并共用相同业务处理。
-数据库契约分别声明表格、画廊和看板结果,保留基础字段缺失、单元格局部修改及 null 值。已知修改字段保留传入状态,不以零值补齐未提供的字段。当前、历史和快照渲染使用对应请求类型,调用端先处理错误载荷再更新视图。行排序、发布准入、加密笔记本租约和快速 JSON 渲染保留既有行为。前端和插件的共享声明按视图及单元格实际提供的字段同步。
+数据库契约分别声明表格、画廊和看板结果,保留基础字段缺失、单元格局部修改及 null 值。已知修改字段保留传入状态,不以零值填充未提供的字段。当前、历史和快照渲染使用对应请求类型,调用端先处理错误载荷再更新视图。行排序、发布准入、加密笔记本租约和快速 JSON 渲染保留既有行为。前端和插件的共享声明按视图及单元格实际提供的字段同步。
AI 契约保留供应商配置、模型发现与匹配、确认结果、会话扩展字段,以及数值和省略语义。编辑器和智能体流声明实际 SSE 事件,断开连接时关闭上游请求,流生命周期仍位于请求内部。OAuth 页面保留媒体类型、HTTP 状态和安全响应头。会话权限通知使用 `WithAfterWrite`,保留先响应再广播的顺序。任意 JSON 仅用于协议扩展字段和工具结果。
@@ -90,7 +90,7 @@ SQL 查询契约保留成功信封顶层的 `limit` 和 `truncated`。`SuccessSQ
- 参数处理:保持默认值、空白处理、数字转换和已支持的历史输入规则;不得隐式扩大或缩小接受范围
- 响应结构:保持字段名称、类型、可空性和省略规则,区分 `{}`、`[]` 与 `null`,完整声明成功、提示和失败等响应分支
- 错误行为:保持 HTTP 状态、业务错误码、消息、附加错误载荷和提示显示时长,不将已有业务失败重新解释为成功
-- 权限与生命周期:保持认证、角色、只读和发布权限校验,以及加密笔记本的操作准入、租约范围与释放时机;兼容处理不得绕过授权或认证解密
+- 权限与生命周期:保持认证、角色、只读和发布权限校验,以及加密笔记本的操作准入、租约范围与释放时机;兼容处理不得规避授权或认证解密
具体接口的特殊行为由契约定义、兼容解码和回归测试共同记录。测试应覆盖实际 HTTP 序列化结果、边界输入和权限场景,不能只验证类型能否编译。
@@ -108,7 +108,7 @@ SQL 查询契约保留成功信封顶层的 `limit` 和 `truncated`。`SuccessSQ
标题事务查询使用 `BlockTransaction` 返回有类型的操作,保留空数组、空值和撤销操作载荷。`BlockOperationResult` 明确声明文本、块 ID 数组和空值的有限联合类型。业务模型中的多态字段转换时拒绝不支持的类型,属性视图操作载荷使用各动作对应的契约。编辑器操作类型同时接受非属性视图操作返回的空列类型字段。
-全部 `/api/block/` 路由已使用契约。标题级别查询保留批量 ID 优先、去重、小数级别截断、文档结构体绑定和消息展示时长。文档转换结果包含六级标题计数和有类型的事务。引用检查仅校验所选范围使用的字段,保留忽略字段及笔记本参数去空白规则,并保留布尔错误载荷、发布过滤和持续到响应序列化完成的笔记本租约。这些特殊输入规则使用私有的入口专用类型解码函数,普通接口继续通过字段声明解码。最近更新结果使用递归的 `SearchBlock` 载荷,包含可为空的引用、子块和卡片元数据。
+全部 `/api/block/` 路由已使用契约。标题级别查询保留批量 ID 优先、去重、小数级别截断、文档结构体绑定和消息展示时长。文档转换结果包含六级标题计数和有类型的事务。引用检查仅校验所选范围使用的字段,保留忽略字段及笔记本参数去空白规则,并保留布尔错误载荷、发布过滤和持续到响应序列化完成的笔记本租约。这些特殊输入规则使用私有的入口专用类型解码函数,而普通接口继续通过字段声明解码。最近更新结果使用递归的 `SearchBlock` 载荷,包含可为空的引用、子块和卡片元数据。
存储契约仅在存储值中允许任意 JSON,键、最近文档、搜索条件、行内样式和属性视图调色板均使用结构化类型。最近文档写入接口保留只读角色在解析请求体前直接返回成功的行为。`contractHandler` 可选的类型化 `beforeDecode` 回调用于保留这一执行顺序,允许在解码前返回响应;路由检查仍要求显式绑定端点。行内样式版本 1 的更新保留已有内置配置,版本 2 和调色板请求保留结构体解码的兼容行为。
@@ -118,13 +118,13 @@ SQL 查询契约保留成功信封顶层的 `limit` 和 `truncated`。`SuccessSQ
`RawSSEOptions` 和 `RawWebSocketOptions` 声明以字节为载荷的广播协议,通过 `ValidateRawSSEEvent` 和 `ValidateRawWebSocketFrame` 单独校验事件及帧元数据;JSON 事件与 RPC 消息保留各自既有校验。原始 WebSocket 的错误由升级器写出,不使用 `RejectWebSocket`。
-JSON SSE 接口通过 `SSEOptions` 和 `SSEEvent` 声明各事件名称及载荷。`StreamSSE` 在请求上下文内执行原有流生命周期,取消与清理仍在该生命周期内完成。HTTP 校验区分 `text/event-stream` 与声明过的流建立前 JSON 错误,`ValidateSSEEvent` 单独校验各事件的 JSON 载荷。生成声明包含事件类型。`fetchPost` 和 `fetchGet` 将完整流缓冲为文本,`fetchSyncPost` 仍解析 JSON,不用于读取事件流。
+JSON SSE 接口通过 `SSEOptions` 和 `SSEEvent` 声明各事件名称及载荷。`StreamSSE` 在请求上下文内执行原有流生命周期,取消与清理仍在该生命周期内完成。HTTP 校验区分 `text/event-stream` 与声明过的流建立前 JSON 错误,`ValidateSSEEvent` 单独校验各事件的 JSON 载荷。生成声明包含事件类型。`fetchPost` 和 `fetchGet` 将完整流缓冲为文本,`fetchSyncPost` 仍解析 JSON,因此不用于读取事件流。
允许空 HTTP 响应的端点通过 `EmptyResponseStatuses` 列出允许状态,并返回 `EmptyHTTPResponse`;其他响应继续使用各自声明的结构。`RedirectHTTPContent` 保留标准重定向状态、Location 响应头和转义后的 HTML 正文。`RawBody` 将未读取的原始请求流留给协议处理函数。`ProxyOptions` 区分 HTTP 字节、EventSource 字节和 WebSocket 帧,保留上游状态,不将其解释为内核业务错误码。代理准入错误与中间件信封分别校验。`ANY` 注册仍按一条记录检查覆盖率,生成元数据时展开为路由器的九种 HTTP 方法。响应校验保留 JSON 数字精度,包括超过浮点范围的证书整数,不改变请求侧的数字转换。
页面响应通过 `HTTPContentOptions` 声明允许的 HTTP 状态与媒体类型组合,通过 `SuccessHTTPContent` 保留原始字节,复用既有二进制传输并单独处理 JSON 中间件错误。`FastJSON` 为指定的大体量响应保留快速 JSON 编码,不改变有类型载荷及响应信封;编码失败时仍回退到标准编码器。
-`WebSocketOutput` 通过 `WebSocketOptions` 声明入站和出站消息类型及插件准入失败状态。`UpgradeWebSocket` 在 `contractHandler` 的响应阶段将写入器交给连接生命周期;`RejectWebSocket` 序列化声明的拒绝载荷。生成的路由元数据包含双向消息模式,`ValidateWebSocketMessage` 单独校验连接内消息,避免与握手响应或中间件信封混淆。握手校验检查 HTTP 状态和响应体,网络回归验证升级头、Origin 拒绝、消息交互和取消后的连接关闭。
+`WebSocketOutput` 通过 `WebSocketOptions` 声明入站和出站消息类型及插件准入失败状态。`UpgradeWebSocket` 在 `contractHandler` 的响应阶段将写入器传递给连接生命周期;`RejectWebSocket` 序列化声明的拒绝载荷。生成的路由元数据包含双向消息模式,`ValidateWebSocketMessage` 单独校验连接内消息,避免与握手响应或中间件信封混淆。握手校验检查 HTTP 状态和响应体,网络回归验证升级头、Origin 拒绝、消息交互和取消后的连接关闭。
可选的 `*string` 表单字段区分未传字段与显式空字符串,并使用 `nonnullable`,因为表单文本不能包含 JSON 空值。导入处理器据此保留默认值和延后校验的行为。上传进度在解析表单前启动,解析失败时先清理进度再返回;类型绑定复用 Gin 缓存的表单。
@@ -134,9 +134,9 @@ JSON SSE 接口通过 `SSEOptions` 和 `SSEEvent` 声明各事件名称及载荷
文件上传使用 `MultipartBody`。请求结构体以线协议字段名声明字符串和 `*multipart.FileHeader` 字段;文件 schema 使用 `type: string` 与 `format: binary`,生成 `Blob` 类型。适配器保留 Gin 的表单解析方式,重复字段取首值;文件内容继续通过 `Open` 读取,处理函数保留读取及恢复逻辑。未支持的字段类型和绑定选项会使生成失败。
-声明为 `[]*multipart.FileHeader` 的固定字段按原顺序接收全部文件,生成 `Array<Blob>`。可选文件列表缺省时保留 nil;文本与单文件字段仍取首值。`SuccessWithMessage` 保留成功响应中的非空提示,包括批量上传部分成功的情况。
+声明为 `[]*multipart.FileHeader` 的固定字段按原顺序接收全部文件,生成 `Array<Blob>`。可选文件列表缺省时保留 nil;文本与单文件字段仍取首值。`SuccessWithMessage` 保留成功响应中的非空提示,包括批量上传部分成功。
-前端从类型化字段构造 `ContractFormData`,再交给现有请求函数。生成签名检查端点所需字段并区分文件与字符串,普通 `FormData` 不能满足上传接口的契约。可缺省字段不写入表单,字符串不裁剪空白。插件调用方构造表单时可实现生成的 `APIFormData<Request>` 接口。
+前端从类型化字段构造 `ContractFormData`,再传递给现有请求函数。生成签名检查端点所需字段并区分文件与字符串,普通 `FormData` 不能满足上传接口的契约。可缺省字段不写入表单,字符串不裁剪空白。插件调用方构造表单时可实现生成的 `APIFormData<Request>` 接口。
动态上传接口使用 `MultipartFields` 保留每个字段名对应的全部文本值和文件。请求模式将字段名映射为文本或二进制值的数组,`ContractFormData` 将数组中的每一项追加为同名表单字段。固定字段上传仍绑定首个值。广播发布保留先处理文本、再处理文件的顺序及逐条消息的错误结果。端点专用的 `DecodeFailure` 处理保留原有解析错误码和载荷。
@@ -150,7 +150,7 @@ JSON SSE 接口通过 `SSEOptions` 和 `SSEEvent` 声明各事件名称及载荷
`TestAPIContractFileTreeMissingDocuments` 通过实际 HTTP 响应覆盖查询路径、删除、重命名、复制和移动不存在的文档,按响应契约检查业务错误及保留的 `closeTimeout`,已包含在下方的内核全量测试命令中。可在 `kernel/` 中执行 `go test -tags "fts5 sqlcipher" ./api -run TestAPIContractFileTreeMissingDocuments -count=1` 单独验证。
-资源引用扫描将定义文件缺失或定义 ID 无效的数据库记录到可选的 `unavailableAttributeViews` 列表,不阻断查询、预演或替换。每项包含笔记本 ID 与名称、文档 ID 与路径及人类可读路径、块 ID、数据库 ID 和原因。已存在但无法读取或内容损坏的定义仍返回错误。保存前重新校验缺失文件快照,避免漏掉扫描期间恢复的定义。当前按需下载规则不包含数据库定义,回归测试会检查这一前提。缺失定义回归覆盖模型和实际 HTTP 契约,包括关闭的笔记本和共享定义。
+资源引用扫描将定义文件缺失或定义 ID 无效的数据库记录到可选的 `unavailableAttributeViews` 列表,不阻断查询、预演或替换。每项包含笔记本 ID 与名称、文档 ID 与路径及人类可读路径、块 ID、数据库 ID 和原因。已存在但无法读取或内容损坏的定义仍返回错误。保存前重新校验缺失文件快照,避免遗漏扫描期间恢复的定义。当前按需下载规则不包含数据库定义,回归测试会检查这一前提。缺失定义回归覆盖模型和实际 HTTP 契约,包括关闭的笔记本和共享定义。
资源引用查询和替换契约保留单资源请求,同时支持批量参数。批量结果按输入顺序返回每项状态、原因、引用和改动文件数;顶层计数对共享文件去重。空批次、重复源路径、链式和循环映射会被拒绝。独立映射可以在其他项失败时完成,共享文件写入失败归属所有受影响映射。扫描期间允许编辑,保存前校验工作区快照;取消和无变化重试保留源数据。`TestAssetRelink` 回归覆盖单资源兼容、批量校验、共享文档、数据库及 OCR 保存、历史和并发编辑,已包含在下方完整内核测试命令中。
@@ -163,7 +163,7 @@ pnpm run lint
pnpm test
```
-上述生成命令同时更新本仓库与 `petal`,无须再单独执行不带 `--petal` 的生成命令。`--petal` 路径相对于生成器的工作目录 `kernel/`,示例对应同级仓库。CI 只检查本仓库产物,本地跨仓库同步须使用该参数核对插件声明。
+上述生成命令同时更新本仓库与 `petal`,无须再单独执行不带 `--petal` 的生成命令。`--petal` 路径相对于生成器的工作目录 `kernel/`,示例对应同级仓库。CI 只检查本仓库产物,而本地跨仓库同步须使用该参数核对插件声明。
在 `kernel/` 下运行:
diff --git a/docs/API.md b/docs/API.md
index 7ac0a0d6c6..56943309f3 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -132,7 +132,7 @@ if (response.code === 0 && response.data) {
}
```
-See the [generated route declarations](../app/src/types/api/index.d.ts) for exact coverage and the [contract maintenance guide](API-CONTRACTS.md) for generation and compatibility rules. Type declarations do not perform runtime JSON validation.
+See the [generated route declarations](../app/src/types/api/index.d.ts) for exact coverage and the [contract maintenance guide](API-CONTRACTS.md) for generation and compatibility rules. Type declarations do not validate JSON at runtime.
### Behavior semantics
@@ -789,7 +789,7 @@ Move documents by `id`:
* `"/assets/sub/"`: workspace/data/assets/sub/ folder
Under normal circumstances, it is recommended to use the first method, which is stored in the assets folder of the
- workspace, putting in a subdirectory has some side effects, please refer to the assets chapter of the user guide.
+ workspace, since putting in a subdirectory has some side effects, please refer to the assets chapter of the user guide.
* `file[]`: Uploaded file list
* Return value
@@ -823,7 +823,7 @@ Move documents by `id`:
* `errFiles`: List of filenames with errors in upload processing
* `failedFiles`: Files explicitly reported as failed. `index` is the file's index in `file[]`, `name` is its upload filename, and `error` is the failure message. This field may omit files that were not attempted or not reported individually; use `succFiles` when each input item must be identified unambiguously
* `succFiles`: Successfully processed files in input order. `index` is the file's index in `file[]`, `name` is its upload filename, and `path` is the uploaded asset path. Use this field when a batch can contain duplicate filenames
- * `succMap`: Compatibility mapping for existing callers. The key is the upload filename and the value is assets/foo-id.png. When a batch contains duplicate filenames, only the last item with a given key remains in this map
+ * `succMap`: Compatibility mapping for existing callers. The key is the upload filename and the value is assets/foo-id.png. However, when a batch contains duplicate filenames, only the last item with a given key remains in this map
## Blocks
@@ -1294,7 +1294,7 @@ Move documents by `id`:
* `stmt`: SQL statement
-Without an explicit outer `LIMIT`, results default to at most `search.limit` rows (the configured search result limit). Use explicit `LIMIT` and `OFFSET` clauses to paginate, with a stable, unique ordering such as `ORDER BY hpath, id`. An explicit outer `LIMIT` overrides the default, including values larger than `search.limit`.
+Without an explicit outer `LIMIT`, results default to at most `search.limit` rows (the configured search result limit). Use explicit `LIMIT` and `OFFSET` clauses to paginate, with a stable, unique ordering such as `ORDER BY hpath, id`. However, an explicit outer `LIMIT` overrides the default, including values larger than `search.limit`.
* Return value
@@ -1310,7 +1310,7 @@ Without an explicit outer `LIMIT`, results default to at most `search.limit` row
}
```
-On success, `data` remains an array. `limit` is the server default limit applied to this query, or `0` when the SQL supplies an explicit outer `LIMIT`; it is not the value of that explicit clause. `truncated` is `true` only when the server default limit omitted at least one result row. Exactly reaching the limit does not imply truncation. For the example above, `LIMIT 7` is explicit, so `limit` is `0` and `truncated` is `false`. These fields are omitted on errors.
+On success, `data` remains an array. `limit` is the server default limit applied to this query, or `0` when the SQL supplies an explicit outer `LIMIT`; it is not the value of that explicit clause. `truncated` is `true` only when the server default limit omitted at least one result row. Exactly meeting the limit does not imply truncation. For the example above, `LIMIT 7` is explicit, so `limit` is `0` and `truncated` is `false`. These fields are omitted on errors.
Note: To ensure data security, access to this interface is prohibited in Publish Mode.
@@ -1786,7 +1786,7 @@ Note: To ensure data security, access to this interface is prohibited in Publish
`text` preserves the existing behavior and converts the character set to UTF-8 when applicable. The binary encodings encode the response body before character-set conversion; existing HTTP content decoding behavior, such as gzip decompression, is unchanged.
- The response body is limited to 32 MiB after HTTP content decoding. If the limit is exceeded, the API returns error code `10` without a partial body. Use `/api/network/proxy` for large files or streaming responses.
+ The response body is limited to 32 MiB after HTTP content decoding. If the limit is exceeded, the API returns error code `10` without a partial body. Therefore, use `/api/network/proxy` for large files or streaming responses.
* Return value
```json
@@ -2050,8 +2050,8 @@ The field types (`keyType`) are:
}
```
- * `data.view`: The rendered view instance. Its shape depends on `viewType`: `table` returns `columns`/`rows`/`rowCount`, while `gallery` and `kanban` return `fields`/`cards`/`cardCount`. When grouping is enabled, `groups` contains a view instance for each group, including `groupKey`/`groupValue`. `view` also carries `filters`, `sorts`, `group`, `showIcon`, `wrapField`, `groupFolded`, and `groupHidden`. Note: active filters or grouping can make the item list empty even when the total item count is greater than 0
- * `data.view.columns[]`: Each has `id`, `name`, `type`, `icon`, `wrap`, `hidden`, `desc`, `calc`, `numberFormat`, `template`, `renderTemplate`, `pin`, `width`; `select`/`mSelect` columns additionally carry `options`. Gallery and kanban fields expose the same field metadata under `data.view.fields[]`
+ * `data.view`: The rendered view instance. Its shape depends on `viewType`: `table` returns `columns`/`rows`/`rowCount`, while `gallery` and `kanban` return `fields`/`cards`/`cardCount`. When grouping is enabled, `groups` contains a view instance for each group, including `groupKey`/`groupValue`. `view` also includes `filters`, `sorts`, `group`, `showIcon`, `wrapField`, `groupFolded`, and `groupHidden`. Note: active filters or grouping can make the item list empty even when the total item count is greater than 0
+ * `data.view.columns[]`: Each has `id`, `name`, `type`, `icon`, `wrap`, `hidden`, `desc`, `calc`, `numberFormat`, `template`, `renderTemplate`, `pin`, `width`; `select`/`mSelect` columns additionally include `options`. Gallery and kanban fields expose the same field metadata under `data.view.fields[]`
* `data.view.columns[].renderTemplate`: Optional display template for a normal field. It changes only the displayed content; the field's stored typed value remains unchanged
* `data.view.rows[].id`: The table row's **item ID** (`itemID`). It also equals `value.blockID` in that row's primary-key cell. For a bound row, the bound block ID is stored in `value.block.id` in the primary-key cell; these are distinct concepts and must not be assumed equal
* `data.view.cards[].id`: The **item ID** (`itemID`) of a gallery or kanban card. When grouping is enabled, table rows or cards are in the corresponding view instances under `groups[]`
@@ -2212,7 +2212,7 @@ The field types (`keyType`) are:
}
```
- * `data.av`: The full `AttributeView` definition — fields (`keyValues`), field ordering (`keyIDs`, may be `null`), and all views with their raw layout config (`table`/`gallery`/`kanban`) and item ordering (`itemIds`). The compatibility `viewID` is computed as the first available view and is not persisted. Returns no rendered rows or pagination; use [Render](#Render) for computed rows
+ * `data.av`: The full `AttributeView` definition — fields (`keyValues`), field ordering (`keyIDs`, may be `null`), and all views with their raw layout config (`table`/`gallery`/`kanban`) and item ordering (`itemIds`). The compatibility `viewID` is computed as the first available view and is not persisted. Returns no rendered rows or pagination; therefore, use [Render](#Render) for computed rows
### Get primary key values
@@ -2273,7 +2273,7 @@ The field types (`keyType`) are:
}
```
- * `data.rows`: A `KeyValues` object holding the primary-key (`block`) field and its paginated values
+ * `data.rows`: A `KeyValues` object containing the primary-key (`block`) field and its paginated values
* `data.blockIDs`: IDs of all database blocks (mirrors) that reference this database
* `data.total`: Number of primary-key values after filtering and before pagination
@@ -2405,7 +2405,7 @@ For rich text, `text.rich.content` is the authoritative Kramdown source. The ker
### Add items
-Adds one or more items (rows). Each source can either bind an existing block (`isDetached: false`) or create a detached row that only lives inside the view (`isDetached: true`).
+Adds one or more items (rows). Each source can either bind an existing block (`isDetached: false`) or create a detached row that exists only inside the view (`isDetached: true`).
* `/api/av/addAttributeViewBlocks`
* Parameters
@@ -2494,7 +2494,7 @@ Switches the layout type of the view selected by the database block between `tab
* `avID`: Database ID
* `blockID`: The database block that owns the view
* `layoutType`: Target layout — one of `table`, `gallery`, `kanban`
-* Return value: same shape as [Render](#Render). When switching to `kanban` and a group is configured, `data.view` carries a `groups[]` array; each group is a view instance with `groupKey`, `groupValue`, plus kanban-specific fields (`coverFrom`, `cardAspectRatio`, `cardSize`, `fitImage`, `displayFieldName`, `fillColBackgroundColor`, `fields`)
+* Return value: same shape as [Render](#Render). When switching to `kanban` and a group is configured, `data.view` contains a `groups[]` array; each group is a view instance with `groupKey`, `groupValue`, plus kanban-specific fields (`coverFrom`, `cardAspectRatio`, `cardSize`, `fitImage`, `displayFieldName`, `fillColBackgroundColor`, `fields`)
### Set grouping
@@ -2585,7 +2585,7 @@ Returns the current filter and sort rules of the view bound to a database block.
}
```
- * `data.filters`: Array of `ViewFilter`. The top level holds a single root group node `{ "combination": "and"|"or", "filters": [...] }`; the array elements are either leaf filters or nested group nodes, enabling recursive AND/OR combinations.
+ * `data.filters`: Array of `ViewFilter`. The top level contains a single root group node `{ "combination": "and"|"or", "filters": [...] }`; the array elements are either leaf filters or nested group nodes, enabling recursive AND/OR combinations.
* `data.filters[].column`: Field (column) ID the filter applies to (leaf node only)
* `data.filters[].valueSource`: Optional value source for a leaf node — `stored` is the default when omitted, and `rendered` filters the field's display-template result
* `data.filters[].operator`: Filter operator (see the operator table below; leaf node only)
@@ -2644,7 +2644,7 @@ Returns the current filter and sort rules of the view bound to a database block.
* `avID`: Database ID
* `blockID`: The database block that owns the view
- * `data`: Full new array of `ViewFilter` objects that **replaces** the view's existing filters entirely (see [Get filter and sort](#Get-filter-and-sort)). Pass `[]` to clear all filters. The top level holds a single root group node `{ "combination": "and"|"or", "filters": [...] }`; the array elements are either leaf filters or nested group nodes, enabling recursive AND/OR combinations
+ * `data`: Full new array of `ViewFilter` objects that **replaces** the view's existing filters entirely (see [Get filter and sort](#Get-filter-and-sort)). Pass `[]` to clear all filters. The top level contains a single root group node `{ "combination": "and"|"or", "filters": [...] }`; the array elements are either leaf filters or nested group nodes, enabling recursive AND/OR combinations
* Return value
```json
diff --git a/docs/API.zh-CN.md b/docs/API.zh-CN.md
index 6e47475c64..42dd62480a 100644
--- a/docs/API.zh-CN.md
+++ b/docs/API.zh-CN.md
@@ -104,7 +104,7 @@
* 端点:`http://127.0.0.1:6806`
* 除非接口中另有说明,否则 API 接口均使用 POST 方法
-* 使用 JSON 入参的接口,参数为 JSON 字符串,放置到 body 里,标头 Content-Type 为 `application/json`
+* 使用 JSON 入参的接口,参数为 JSON 字符串,写入 body 里,标头 Content-Type 为 `application/json`
* 返回值
```json
@@ -139,7 +139,7 @@ if (response.code === 0 && response.data) {
* 只有在本文档中设有独立接口说明的接口属于公开 API。其他内核路由和 `/api/transactions` 操作属于内部实现,除非另有说明,否则不承诺兼容性和行为稳定性
* `code: 0` 表示接口处理请求时未报告错误,只保证该接口明确说明的结果,不表示相关索引、缓存、WebSocket 广播或同步状态均已更新
* 省略字段、`null`、空对象和空数组的含义由各接口定义。对象或数组是替换、合并还是局部修改现有状态,以及顺序是否具有意义,也以各接口说明为准
-* 接口可能裁剪、忽略、补全或转换输入。接口说明会返回规范化结果时,调用方应将返回的 `data` 作为实际接受的结果
+* 接口可能裁剪、忽略、填充或转换输入。接口说明会返回规范化结果时,调用方应将返回的 `data` 作为实际接受的结果
* 不要根据操作名称推断其为只读操作。存在持久化副作用时,各接口会说明其影响范围
* 只有接口明确说明时,相同请求才保证幂等或可以安全重试。响应中断或结果无法确定时,应尽可能先读取当前状态再决定是否重试
@@ -783,11 +783,11 @@ if (response.code === 0 && response.data) {
* `/api/asset/upload`
* 参数为 HTTP Multipart 表单
- * `assetsDirPath`:资源文件存放的文件夹路径,以 data 文件夹作为根路径,比如:
+ * `assetsDirPath`:资源文件保存的文件夹路径,以 data 文件夹作为根路径,比如:
* `"/assets/"`:工作空间/data/assets/ 文件夹
* `"/assets/sub/"`:工作空间/data/assets/sub/ 文件夹
- 常规情况下建议用第一种,统一存放到工作空间资源文件夹下,放在子目录有一些副作用,请参考用户指南资源文件章节。
+ 常规情况下建议用第一种,统一保存在工作空间资源文件夹下,因为写入子目录有一些副作用,请参考用户指南资源文件章节。
* `file[]`:上传的文件列表
* 返回值
@@ -1290,7 +1290,7 @@ if (response.code === 0 && response.data) {
* `stmt`:SQL 脚本
-未显式指定外层 `LIMIT` 时,默认最多返回 `search.limit` 行,即设置中的搜索结果条数。请使用显式的 `LIMIT` 和 `OFFSET` 分页,并采用稳定且唯一的排序,例如 `ORDER BY hpath, id`。显式外层 `LIMIT` 会覆盖默认限制,可以大于 `search.limit`。
+未显式指定外层 `LIMIT` 时,默认最多返回 `search.limit` 行,即设置中的搜索结果条数。因此,请使用显式的 `LIMIT` 和 `OFFSET` 分页,并采用稳定且唯一的排序,例如 `ORDER BY hpath, id`。显式外层 `LIMIT` 会覆盖默认限制,可以大于 `search.limit`。
* 返回值
@@ -1643,9 +1643,9 @@ if (response.code === 0 && response.data) {
* `/api/convert/pandoc`
* 工作目录
- * 执行调用 pandoc 命令时工作目录会被设置在 `工作空间/temp/convert/pandoc/${test}` 下
+ * 执行 pandoc 命令时工作目录会被设置在 `工作空间/temp/convert/pandoc/${test}` 下
* 可先通过 API [`写入文件`](#写入文件) 将待转换文件写入该目录
- * 然后再调用该 API 进行转换,转换后的文件也会被写入该目录
+ * 然后再调用该 API 转换,转换后的文件也会被写入该目录
* 最后调用 API [`获取文件`](#获取文件) 获取转换后的文件内容
* 或者调用 API [`通过 Markdown 创建文档`](#通过-markdown-创建文档)
* 或者调用内部 API `importStdMd` 将转换后的文件夹直接导入
@@ -1781,7 +1781,7 @@ if (response.code === 0 && response.data) {
`text` 保持现有行为,在适用时将字符集转换为 UTF-8。二进制编码作用于字符集转换前的响应正文数据;gzip 解压等现有 HTTP 内容解码行为不变。
- HTTP 内容解码后的响应正文上限为 32 MiB,超限时返回错误码 `10` 且不返回部分正文。大文件或流式响应请使用 `/api/network/proxy`。
+ HTTP 内容解码后的响应正文上限为 32 MiB,超限时返回错误码 `10` 且不返回部分正文。因此,大文件或流式响应请使用 `/api/network/proxy`。
* 返回值
```json
@@ -1822,11 +1822,11 @@ if (response.code === 0 && response.data) {
* 请求方法:任意 HTTP 方法
* 查询参数
- * `u`:必填,目标 `http` 或 `https` URL 使用 Go `base64.RawURLEncoding` 编码后的字符串,也就是 URL 安全且不带 `=` 补位的 Base64
+ * `u`:必填,目标 `http` 或 `https` URL 使用 Go `base64.RawURLEncoding` 编码后的字符串,也就是 URL 安全且不带 `=` 填充的 Base64
* `h`:可选,请求标头 JSON 使用同样方式编码后的字符串,JSON 类型为 `map[string][]string`,例如 `{"Authorization":["Bearer token"]}`
* `t`:可选,连接超时时间,使用 Go `time.ParseDuration` 格式,例如 `30s`、`1500ms`
* 请求体:原样转发当前请求体,当前请求的完整 `Content-Type` 标头会转发到目标请求
-* 返回值:直接返回目标服务的 HTTP 状态码和响应体,不包裹 `code`、`msg`、`data`;目标服务响应标头会添加 `Siyuan-Proxy-` 前缀后返回,例如 `Content-Type` 会返回为 `Siyuan-Proxy-Content-Type`
+* 返回值:直接返回目标服务的 HTTP 状态码和响应体,不封装 `code`、`msg`、`data`;目标服务响应标头会添加 `Siyuan-Proxy-` 前缀后返回,例如 `Content-Type` 会返回为 `Siyuan-Proxy-Content-Type`
#### WebSocket 正向代理
@@ -1848,7 +1848,7 @@ if (response.code === 0 && response.data) {
* `u`:必填,目标 `http` 或 `https` URL 使用 Go `base64.RawURLEncoding` 编码后的字符串
* `h`:可选,请求标头 JSON 使用同样方式编码后的字符串,JSON 类型为 `map[string][]string`
* `t`:可选,连接超时时间,使用 Go `time.ParseDuration` 格式,例如 `30s`、`1500ms`
-* 返回值:直接流式返回目标服务的 HTTP 状态码和响应体,不包裹 `code`、`msg`、`data`;如果请求标头中没有 `Accept`,会自动使用 `text/event-stream`;目标服务响应标头会添加 `Siyuan-Proxy-` 前缀后返回
+* 返回值:直接流式返回目标服务的 HTTP 状态码和响应体,不封装 `code`、`msg`、`data`;如果请求标头中没有 `Accept`,会自动使用 `text/event-stream`;目标服务响应标头会添加 `Siyuan-Proxy-` 前缀后返回
## 系统
@@ -2486,7 +2486,7 @@ if (response.code === 0 && response.data) {
* `avID`: 数据库 ID
* `blockID`: 拥有该视图的数据库块
* `layoutType`: 目标布局——`table`、`gallery`、`kanban` 之一
-* 返回值:与 [渲染](#渲染) 返回结构相同。当切换到 `kanban` 且已配置分组时,`data.view` 携带 `groups[]` 数组;每个分组是视图实例,含 `groupKey`、`groupValue`,以及看板特有字段(`coverFrom`、`cardAspectRatio`、`cardSize`、`fitImage`、`displayFieldName`、`fillColBackgroundColor`、`fields`)
+* 返回值:与 [渲染](#渲染) 返回结构相同。当切换到 `kanban` 且已配置分组时,`data.view` 包含 `groups[]` 数组;每个分组是视图实例,含 `groupKey`、`groupValue`,以及看板特有字段(`coverFrom`、`cardAspectRatio`、`cardSize`、`fitImage`、`displayFieldName`、`fillColBackgroundColor`、`fields`)
### 设置分组
@@ -2548,7 +2548,7 @@ if (response.code === 0 && response.data) {
}
```
- 配置后(真实抓取的响应),过滤与排序形如:
+ 配置后(真实获取的响应),过滤与排序形如:
```json
{
diff --git a/docs/ASSET-DOWNLOAD.md b/docs/ASSET-DOWNLOAD.md
index bf874276dc..05e4f382b1 100644
--- a/docs/ASSET-DOWNLOAD.md
+++ b/docs/ASSET-DOWNLOAD.md
@@ -8,11 +8,11 @@ Related issue: https://github.com/siyuan-note/siyuan/issues/19149
`sync.assetDownloadMode` is a device setting: `0` downloads everything and `1` downloads on demand; the default is `0`. Desktop and mobile clients share the setting and kernel implementation. It applies to official cloud, S3, WebDAV, and local filesystem sync.
-On-demand mode always synchronizes complete file metadata and non-asset content, including documents, databases, configuration, and keys. Asset-directory `ocr-texts.json`, PDF annotation `.sya` files, and hidden helper files also remain fully synchronized. Downloaded assets are not automatically evicted. Enabling on-demand mode on a device that already has all content does not immediately reduce disk usage.
+On-demand mode always synchronizes complete file metadata and non-asset content, including documents, databases, configuration, and keys. Asset-directory `ocr-texts.json`, PDF annotation `.sya` files, and hidden helper files also remain fully synchronized. Downloaded assets are not automatically evicted. Therefore, enabling on-demand mode on a device that already has all content does not immediately reduce disk usage.
## User interaction
-The first access to an undownloaded asset reuses chunks already in the local repository and downloads only the missing chunks. Once downloaded, the asset continues to receive updates during subsequent syncs. Existing local content does not require a network connection, account login, or enabled sync. Cloud access uses the account and service permissions of data sync.
+The first access to an undownloaded asset reuses chunks already in the local repository and downloads only the missing chunks. Once downloaded, the asset continues to receive updates during subsequent syncs. Existing local content does not require a network connection, account login, or enabled sync. Cloud access, however, uses the account and service permissions of data sync.
## Data and storage
@@ -20,11 +20,11 @@ The first access to an undownloaded asset reuses chunks already in the local rep
Undownloaded assets remain part of the logical file inventory of current data and snapshots. Indexing must not interpret their absence from local disk as deletion, and sync must not upload chunks from an undownloaded old version. Ordinary indexing continues to track materialized files. Asset deletion, rename, and move operations fetch the relevant content before performing the existing file operation.
-Changing sync ignore rules first fetches newly ignored undownloaded assets, then stops tracking them while retaining local content and historical chunks. If content cannot be obtained, the previous state is retained and an error is returned. Upload-only mode fetches only chunks required by actual upload candidates and does not materialize unvisited assets in the workspace.
+Changing sync ignore rules first fetches newly ignored undownloaded assets, then stops tracking them while retaining local content and historical chunks. If content cannot be obtained, then the previous state is retained and an error is returned. Upload-only mode fetches only chunks required by actual upload candidates and does not materialize unvisited assets in the workspace.
Sync merge uses a recoverable apply journal that records the target asset inventory, previous versions, and cloud baseline. Before applying changes, it verifies that local files still match expectations and preserves additional local edits made during downloading. Only sync explicitly initiates recovery; creating a repository instance or reading an asset does not rewrite documents as a side effect. After files and references are updated, pending change records remain until the kernel finishes cache, index, and UI updates. Partial failures use the actual disk state to account for changes already written, so retries do not omit them. Pending records are an optional field in device-state version 1. Existing authenticated state and journals without that field remain readable and recoverable without changing the encryption format. Source switching and asset materialization are serialized. Repository operations share the existing mutex and reload authenticated device state so an old instance cannot overwrite newer state.
-On-demand reads and historical chunk retrieval report actual cloud download traffic and request counts, aggregating batch retrieval. Local chunk reuse and LAN downloads do not count as cloud traffic, and repeated reads do not report the same traffic again.
+On-demand reads and historical chunk retrieval report actual cloud download traffic and request counts, aggregating batch retrieval. However, local chunk reuse and LAN downloads do not count as cloud traffic, and repeated reads do not report the same traffic again.
## Implementation and interfaces
@@ -32,15 +32,15 @@ On-demand reads and historical chunk retrieval report actual cloud download traf
Internal logical-path resolution, asset search, missing-asset checks, and file-size queries use logical metadata without downloading content. Displaying images, playing audio or video, opening PDFs, following asset links, copying assets, and exporting fetch content when needed. `/api/asset/resolveAssetPath`, which prepares a physical path for external opening, also fetches the asset first. HTTP and raw file APIs validate paths, symbolic links, publish permissions, and encrypted-notebook permissions before downloading.
-Exports prefetch referenced assets before holding notebook read locks and creating output artifacts. Reads use each document's actual notebook and complete path. The scope includes child and related documents, footnotes, query embeds, title images, databases, and related-database assets. Footnote assets in single-file exports are included independently of whether related documents are exported separately. Directory assets are completed from the logical inventory rather than disk traversal alone. Download and copy failures propagate to the caller; an output with missing assets is not reported as successful.
+Exports prefetch referenced assets before holding notebook read locks and creating output artifacts. Reads use each document's actual notebook and complete path. The scope includes child and related documents, footnotes, query embeds, title images, databases, and related-database assets. Footnote assets in single-file exports are included independently of whether related documents are exported separately. Directory assets are downloaded from the logical inventory rather than disk traversal alone. Download and copy failures propagate to the caller; an output with missing assets is not reported as successful.
-Downloaded encrypted assets retain their original ciphertext. Existing authenticated decryption handles reads and exports, preserving compatibility with released asset formats. Key envelopes, MasterSalt, AAD, and key derivation do not change, and authentication errors never fall back to plaintext. Notebook admission is checked before reading or plaintext export, and network waits do not occur while holding a notebook read lock. Reading an asset in a locked notebook or merely enumerating filenames does not download content. Full sync, ciphertext backups, and history preservation before deletion may fetch original ciphertext.
+Downloaded encrypted assets retain their original ciphertext. Existing authenticated decryption handles reads and exports, preserving compatibility with released asset formats. Key envelopes, MasterSalt, AAD, and key derivation do not change, and authentication errors never fall back to plaintext. Notebook admission is checked before reading or plaintext export, and network waits do not occur while holding a notebook read lock. Reading an asset in a locked notebook or merely enumerating filenames does not download content. However, full sync, ciphertext backups, and history preservation before deletion may fetch original ciphertext.
## Compatibility and recovery
Local snapshots on on-demand devices may contain only part of the asset content; the UI indicates this separately through `requiresDownload`. Historical asset reads retrieve chunks for that snapshot's exact file version without overwriting current workspace assets. Downloading a complete cloud snapshot checks every target file's chunks even when its metadata already exists. Failure does not create a success tag.
-Before restoring a snapshot, fetch the assets required by both the current workspace and the target snapshot. Switching back to full download fetches current assets and missing historical content in all retained snapshots; failure preserves the previous setting. Source switching, cloud cleanup, deletion of the current cloud directory, and repository or key resets check these dependencies and retain the previous source while they are incomplete. Repository rebuilding may clear device state and its marker only after authenticating the old state and completing its dependencies.
+Before restoring a snapshot, fetch the assets required by both the current workspace and the target snapshot. Switching back to full download fetches current assets and missing historical content in all retained snapshots; failure preserves the previous setting. Source switching, cloud cleanup, deletion of the current cloud directory, and repository or key resets check these dependencies and retain the previous source while they are incomplete. Repository rebuilding may clear device state and its marker only after authenticating the old state and making its dependencies complete.
Signing out of the official cloud can retain the original source identity so local indexing and downloaded snapshots remain usable, followed by reauthentication with the original account. While dependencies remain incomplete, changing regions, changing accounts, and deleting the account are protected by integrity checks.
@@ -48,6 +48,6 @@ Incomplete historical snapshots still depend on retention of the corresponding c
## Verification
-Implementation spans `siyuan`, `dejavu`, and `petal`. The kernel uses `dejavu` asset-download and snapshot-completeness APIs. Publish the dependency and update the module version before release. Local development may use a temporary `replace` pointing to the `dejavu` checkout; do not commit it.
+Implementation spans `siyuan`, `dejavu`, and `petal`. The kernel uses `dejavu` asset-download and snapshot-completeness APIs. Therefore, publish the dependency and update the module version before release. Local development may use a temporary `replace` pointing to the `dejavu` checkout; do not commit it.
-Regression coverage includes sync between full and on-demand devices, one-way sync, repeated indexing, remote version updates, concurrent materialization, local-edit protection, interrupted apply recovery, state authentication failures, source changes, historical snapshot completion, directory-asset exports, and existing encrypted asset formats. Run `pnpm run lint` for the frontend and `python scripts/check-lang-keys.py` for translations. Do not verify by building frontend artifacts or compiling and running the kernel.
+Regression coverage includes sync between full and on-demand devices, one-way sync, repeated indexing, remote version updates, concurrent materialization, local-edit protection, interrupted apply recovery, state authentication failures, source changes, historical snapshot population, directory-asset exports, and existing encrypted asset formats. Run `pnpm run lint` for the frontend and `python scripts/check-lang-keys.py` for translations. Do not verify by building frontend artifacts or compiling and running the kernel.
diff --git a/docs/ASSET-DOWNLOAD.zh-CN.md b/docs/ASSET-DOWNLOAD.zh-CN.md
index 7d12f710bd..613a564917 100644
--- a/docs/ASSET-DOWNLOAD.zh-CN.md
+++ b/docs/ASSET-DOWNLOAD.zh-CN.md
@@ -8,7 +8,7 @@
`sync.assetDownloadMode` 是设备配置,`0` 为全部下载,`1` 为按需下载,默认值为 `0`。桌面端和移动端共用设置及内核实现,适用于官方云、S3、WebDAV 和本地文件系统同步。
-按需模式始终同步完整文件元数据以及文档、数据库、配置、密钥等非资源内容。资源目录中的 `ocr-texts.json`、PDF 批注 `.sya` 文件和隐藏辅助文件也保持完整同步。没有自动清理已下载资源的策略;在已有完整数据的设备上启用按需模式,不会立即减少磁盘占用。
+按需模式始终同步完整文件元数据以及文档、数据库、配置、密钥等非资源内容。资源目录中的 `ocr-texts.json`、PDF 批注 `.sya` 文件和隐藏辅助文件也保持完整同步。没有自动清理已下载资源的策略;因此在已有完整数据的设备上启用按需模式,不会立即减少磁盘占用。
## 用户交互
@@ -18,36 +18,36 @@
`dejavu` 在工作空间的 `conf/asset-downloads.json` 中保存经过仓库密钥认证加密的设备状态,包含显式版本、来源标识、未下载资源的完整文件版本,以及未完成应用操作的恢复日志。状态不参与数据同步。仓库中的 `asset-downloads-v1` 标记用于检测当前实现遗漏配置或丢失状态;状态丢失、未知版本或认证失败均返回错误并保留原始材料。
-未下载资源仍属于当前数据和快照的逻辑文件清单。索引不能将其本地缺席解释为删除,同步不能上传尚未下载的旧版本分块。已经物化的文件由普通索引继续跟踪;资源删除、改名和移动入口先补齐相关内容,再执行原有文件操作。
+未下载资源仍属于当前数据和快照的逻辑文件清单。索引不能将其本地缺席解释为删除,同步不能上传尚未下载的旧版本分块。已经物化的文件由普通索引继续跟踪;资源删除、改名和移动入口先下载缺失的相关内容,再执行原有文件操作。
-修改同步忽略规则时,先补齐新被忽略的未下载资源,再停止跟踪,保留本地内容和历史分块;无法获取内容时保留原状态并报错。仅上传模式只补齐实际上传候选所需的分块,不将未访问的资源物化到工作区。
+修改同步忽略规则时,先下载新被忽略的未下载资源,再停止跟踪,保留本地内容和历史分块;无法获取内容时保留原状态并报错。仅上传模式只下载实际上传候选所需的分块,不将未访问的资源物化到工作区。
同步合并采用可恢复的应用日志,记录目标资源清单、变更前版本和云端基线。应用前检查本地文件是否仍符合预期,保留下载期间的本地额外修改。恢复只能由同步流程显式发起,创建仓库实例和读取资源不会顺带改写文档。文件及引用更新后,另行保留待确认的变更记录,直到内核完成缓存、索引和界面更新;中途失败也按磁盘实际状态处理已经落盘的部分,重试不会遗漏这些变更。待确认记录是设备状态第一版中的可选字段,现有不含该字段的已认证状态和应用日志仍可读取并恢复,不改变加密格式。来源切换与资源物化串行化,仓库内部操作共享原有互斥锁,并重新读取已认证的设备状态,避免旧实例覆盖新状态。
-按需读取和历史分块补齐会上报实际发生的云端下载流量与请求次数,批量补齐合并上报;复用本地分块和局域网下载不计入云端流量,重复读取不会重复上报。
+按需读取和历史分块填充会上报实际发生的云端下载流量与请求次数,批量填充合并上报;而复用本地分块和局域网下载不计入云端流量,重复读取不会重复上报。
## 实现与接口
### 读取与导出
-内部逻辑路径解析、资源搜索、缺失检查和文件大小查询只读取逻辑元数据,不触发下载。实际显示图片、播放音视频、打开 PDF、访问资源链接、复制资源或导出时才补齐内容。用于为外部打开准备实际文件路径的 `/api/asset/resolveAssetPath` 也会先补齐资源。HTTP 和原始文件 API 先完成路径、符号链接、发布权限及加密笔记本权限检查,再执行下载。
+内部逻辑路径解析、资源搜索、缺失检查和文件大小查询只读取逻辑元数据,不触发下载。实际显示图片、播放音视频、打开 PDF、访问资源链接、复制资源或导出时才下载缺失内容。用于为外部打开准备实际文件路径的 `/api/asset/resolveAssetPath` 也会先下载资源。HTTP 和原始文件 API 先完成路径、符号链接、发布权限及加密笔记本权限检查,再执行下载。
-导出在持有笔记本读锁和创建产物之前预取引用资源,按每个文档实际所属的笔记本和完整路径读取,范围包含子文档、关联文档、脚注、查询嵌入、题头图、数据库及关联数据库中的资源。单文件导出中的脚注资源不受是否另行导出关联文档影响。目录资源根据逻辑清单补齐,不能只依靠磁盘遍历。下载或复制失败向上传播,不将缺少资源的产物报告为成功。
+导出在持有笔记本读锁和创建产物之前预取引用资源,按每个文档实际所属的笔记本和完整路径读取,范围包含子文档、关联文档、脚注、查询嵌入、题头图、数据库及关联数据库中的资源。单文件导出中的脚注资源不受是否另行导出关联文档影响。目录资源根据逻辑清单下载,不能只依靠磁盘遍历。下载或复制失败向上传播,不将缺少资源的产物报告为成功。
-加密资源下载后仍保持原始密文,读取和导出继续由现有认证解密流程处理,兼容已发布的资源格式。不改变密钥信封、主盐、AAD 或密钥派生,不通过明文回退处理认证错误。读取和明文导出前检查笔记本准入,不在持有笔记本读锁期间等待网络。锁定笔记本的资源读取请求和仅枚举文件名不会触发下载;完整同步、密文备份及删除前保存历史可以补齐原始密文。
+加密资源下载后仍保持原始密文,读取和导出继续由现有认证解密流程处理,兼容已发布的资源格式。不改变密钥信封、主盐、AAD 或密钥派生,不通过明文回退处理认证错误。读取和明文导出前检查笔记本准入,不在持有笔记本读锁期间等待网络。锁定笔记本的资源读取请求和仅枚举文件名不会触发下载;但完整同步、密文备份及删除前保存历史可以下载原始密文。
## 兼容与恢复
-按需设备的本地快照可能只有部分资源内容,界面通过 `requiresDownload` 独立提示。读取历史资源按该快照的精确文件版本补齐分块,不覆盖工作区当前资源。完整云端快照下载检查所有目标文件的分块,即使其元数据已经存在也不跳过检查;失败时不创建成功标签。
+按需设备的本地快照可能只有部分资源内容,界面通过 `requiresDownload` 独立提示。读取历史资源按该快照的精确文件版本填充分块,不覆盖工作区当前资源。完整云端快照下载检查所有目标文件的分块,即使其元数据已经存在也不跳过检查;失败时不创建成功标签。
-恢复快照前,先补齐当前工作区和目标快照所需的资源。切回全部下载时,同时补齐当前资源和所有保留快照缺少的历史内容;失败则保留原设置。切换同步来源、云端清理、删除当前云目录及重置仓库或密钥前检查这些依赖,未完成时保留原来源。重建仓库前,只有旧状态认证成功且依赖完整,才能清除设备状态和标记。
+恢复快照前,先下载当前工作区和目标快照所需的资源。切回全部下载时,同时下载当前资源和所有保留快照缺少的历史内容;失败则保留原设置。切换同步来源、云端清理、删除当前云目录及重置仓库或密钥前检查这些依赖,未完成时保留原来源。重建仓库前,只有旧状态认证成功且依赖完整,才能清除设备状态和标记。
官方云登出允许保留原来源标识,以便本地索引和已下载快照继续使用,随后重新认证原账号。存在未完成依赖时,跨区登录、换账号和注销账号受完整性检查保护。
-未补齐的历史快照仍依赖对应云端内容的保留。其他设备清理云端或外部删除云对象可能使历史版本无法下载,因此部分本地快照不等价于完整离线备份。需要离线备份或更换来源时,应先完成全部下载。旧版本客户端不了解设备状态标记,降级前也必须完成全部下载;标记不能阻止旧版本把未下载文件当作本地删除。
+未下载完整的历史快照仍依赖对应云端内容的保留。其他设备清理云端或外部删除云对象可能使历史版本无法下载,因此部分本地快照不等价于完整离线备份。需要离线备份或更换来源时,应先完成全部下载。旧版本客户端不了解设备状态标记,降级前也必须完成全部下载;标记不能阻止旧版本把未下载文件当作本地删除。
## 验证范围
-实现同时涉及 `siyuan`、`dejavu` 和 `petal`。内核调用新增的 `dejavu` 资源下载及快照完整性接口,发布时应先发布依赖并更新模块版本。本地开发可使用临时 `replace` 指向 `dejavu` 检出,该替换不能提交。
+实现同时涉及 `siyuan`、`dejavu` 和 `petal`。内核调用新增的 `dejavu` 资源下载及快照完整性接口,因此发布时应先发布依赖并更新模块版本。本地开发可使用临时 `replace` 指向 `dejavu` 检出,该替换不能提交。
-回归覆盖完整与按需设备互相同步、单向同步、重复索引、远端版本更新、并发物化、本地修改保护、应用中断恢复、状态认证失败、来源变更、历史快照补齐、目录资源导出和已有加密资源格式。前端执行 `pnpm run lint`,语言执行 `python scripts/check-lang-keys.py`;不通过构建前端产物或编译运行内核进行验证。
+回归覆盖完整与按需设备互相同步、单向同步、重复索引、远端版本更新、并发物化、本地修改保护、应用中断恢复、状态认证失败、来源变更、历史快照填充、目录资源导出和已有加密资源格式。前端执行 `pnpm run lint`,语言执行 `python scripts/check-lang-keys.py`;不通过构建前端产物或编译运行内核验证。
diff --git a/docs/ENCRYPTED-NOTEBOOK.md b/docs/ENCRYPTED-NOTEBOOK.md
index 95a8572691..d2e0b4cf81 100644
--- a/docs/ENCRYPTED-NOTEBOOK.md
+++ b/docs/ENCRYPTED-NOTEBOOK.md
@@ -100,7 +100,7 @@ An encrypted notebook is an island; some features are unsupported because of the
## User interaction
-On Windows and macOS, Settings - Authentication - Encrypted Notebook provides an optional “Follow system screen lock” switch, disabled by default. It locks all unlocked encrypted notebooks in workspaces whose kernels are owned by the desktop app, independently of the idle timeout (including when that timeout is zero). Remote connections, browser clients, Linux, and mobile clients do not emit this desktop system-lock action. System unlock never unlocks a notebook automatically.
+On Windows and macOS, Settings - Authentication - Encrypted Notebook provides an optional “Follow system screen lock” switch, disabled by default. It locks all unlocked encrypted notebooks in workspaces whose kernels are owned by the desktop app, independently of the idle timeout (including when that timeout is zero). Remote connections, browser clients, Linux, and mobile clients do not emit this desktop system-lock action. However, system unlock never unlocks a notebook automatically.
The desktop main process gives responsive editor windows up to one second to submit pending input, then invokes the authenticated kernel lock operation. The kernel waits for an ongoing unlock before collecting unlocked notebooks and reuses normal unmounting to drain transactions, save history, revoke access, and clear managed keys and caches. Unresponsive windows cannot indefinitely prevent locking; input that has not reached the kernel cannot be guaranteed to persist. Failed requests are retried on system unlock or resume. This is an asynchronous lock operation, not a guarantee that the OS waits for completion before suspending.
@@ -172,7 +172,7 @@ When sync removes an encrypted notebook currently mounted on this device, the ke
If the notebook still shows as locked on the new device after sync, that is normal — click it and enter the master password.
-Sync recovery can validate backup integrity but cannot prove that a backup is the newest version. Keep an independently versioned key backup. When historical copies conflict, the system cannot determine freshness automatically; before recovery, the user confirms a version from trusted source and time information.
+Sync recovery can validate backup integrity but cannot prove that a backup is the newest version. Therefore, keep an independently versioned key backup. When historical copies conflict, the system cannot determine freshness automatically; before recovery, the user confirms a version from trusted source and time information.
#### Import and export
@@ -186,7 +186,7 @@ Sync recovery can validate backup integrity but cannot prove that a backup is th
It cannot be recovered — by design (no backdoor). Even if the ciphertext has been synced to the cloud, it cannot be decrypted without the master password. You must remember the master password; using a password manager is recommended.
#### Recovering from a lost key backup
-If both `conf/conf.json` and the key backup in the sync directory are lost (an extreme case), re-enabling the encrypted-notebook feature will be rejected with a prompt to restore the backup file. As long as you can recover `data-crypto-backup.json` from another synced device or a previously exported key file, you can import it via the "Import key" button shown in `Disabled` or `RecoveryRequired`, or manually put it back at `<workspace>/data/.siyuan/` and re-enable, then unlock with the master password matching that key.
+If both `conf/conf.json` and the key backup in the sync directory are lost (an extreme case), re-enabling the encrypted-notebook feature will be rejected with a prompt to restore the backup file. As long as you can recover `data-crypto-backup.json` from another synced device or a previously exported key file, you can import it via the "Import key" button shown in `Disabled` or `RecoveryRequired`, or manually restore it to `<workspace>/data/.siyuan/` and re-enable, then unlock with the master password matching that key.
Restoring deleted encrypted-notebook history also requires the global key backup matching its WrappedDEK and the master password. While you still need that local recovery path, do not permanently purge either the history or its matching key backup; disabling must refuse to proceed when it discovers such a dependency.
@@ -226,7 +226,7 @@ Restoring deleted encrypted-notebook history also requires the global key backup
2. Lock after use: Reduce the DEK's exposure time in memory
-3. Don't put all your notes in encrypted notebooks: Only put what is truly sensitive
+3. Don't store all your notes in encrypted notebooks: Store only what is truly sensitive
4. Master password strength: Recommend 12+ characters, mixed case + digits + symbols
@@ -259,9 +259,9 @@ User master password
MasterSalt is the global root of KEK derivation — the master password + MasterSalt derive the KEK via Argon2id, and the KEK then unwraps each notebook's WrappedDEK. Losing MasterSalt permanently locks the data: even with the same master password, a changed salt derives a different KEK, so old WrappedDEKs cannot be unwrapped. A backup-and-recovery mechanism is therefore introduced.
-Backup: `<DataDir>/.siyuan/data-crypto-backup.json`, holding the full NotebookCrypto (MasterSalt/KEKVerifier/KDFParams/HistoryKEKs). Located inside DataDir, it enters the dejavu sync scope. It is refreshed when enabling encrypted notebooks and when changing the master password. It may be deleted on disable only after confirming that no live encrypted notebook and no kernel-enumerable history or recovery snapshot depends on it, or after the user explicitly chooses to purge those recovery artifacts permanently. The file uses plaintext JSON, with the verifier and historical KEKs stored as ciphertext, matching their representation in `conf/conf.json`.
+Backup: `<DataDir>/.siyuan/data-crypto-backup.json`, storing the full NotebookCrypto (MasterSalt/KEKVerifier/KDFParams/HistoryKEKs). Located inside DataDir, it therefore enters the dejavu sync scope. It is refreshed when enabling encrypted notebooks and when changing the master password. It may be deleted on disable only after confirming that no live encrypted notebook and no kernel-enumerable history or recovery snapshot depends on it, or after the user explicitly chooses to purge those recovery artifacts permanently. The file uses plaintext JSON, with the verifier and historical KEKs stored as ciphertext, matching their representation in `conf/conf.json`.
-Each encrypted notebook separately stores `<DataDir>/<boxID>/.siyuan/notebook-crypto-backup.json`, containing that notebook's BoxEncryption key envelope (WrappedDEK/WrapNonce and authenticated metadata). The global `data-crypto-backup.json` supplies the KEK derivation identity, while the per-notebook `notebook-crypto-backup.json` supplies the wrapped DEK; neither file can replace the other.
+Each encrypted notebook separately stores `<DataDir>/<boxID>/.siyuan/notebook-crypto-backup.json`, containing that notebook's BoxEncryption key envelope (WrappedDEK/WrapNonce and authenticated metadata). The global `data-crypto-backup.json` supplies the KEK derivation identity, while the per-notebook `notebook-crypto-backup.json` supplies the wrapped DEK; therefore, neither file can replace the other.
Recovery triggers (covering scenarios such as conf.json loss, sync to a new device, importing Data.zip):
@@ -322,7 +322,7 @@ Prerequisite: `restoreNotebookCryptoConfigFromBackup` only takes effect when the
- `DEKProvider` callback injected (avoids circular dependency)
-- Decrypts after read, encrypts before write; cache holds plaintext
+- Decrypts after read, encrypts before write; cache stores plaintext
- Reading an encrypted notebook's title requires a full read + decrypt before parsing
@@ -375,9 +375,9 @@ Encrypted-notebook operations (dedicated read path, with boxID):
→ encrypted blocktree SQLite database → encrypted content SQLite database
```
-Write path: Centralized funnel; selects db by notebook. Index queue, blocktree writers, index corrections are all routed by notebook.
+Write path: Converges on a single entry point; selects db by notebook. Index queue, blocktree writers, index corrections are all routed by notebook.
-Read path: Three-layer fall-through — the handler layer dispatches by the `notebook` parameter; original functions forward to the InBox variant (normal path passes empty boxID); the low-level wrapper decides routing by whether the encrypted SQLite database is open, with empty boxID always going to the global SQLite database.
+Read path: Three-layer fall-through — the handler layer dispatches by the `notebook` parameter; original functions forward to the InBox variant (normal path passes empty boxID); the low-level wrapper decides routing by whether the encrypted SQLite database is open, whereas an empty boxID always goes to the global SQLite database.
Deep full-routing principle: Every SQL call on the read path of an encrypted notebook (including deep helpers: ref counts, block name/alias, child-block recursion, FTS counts, highlighting, mention search, refs definition queries, etc.) is routed to the encrypted SQLite database and never leaks to the global SQLite database.
@@ -387,17 +387,17 @@ Generic-entry fallback: Core functions like `GetBlockTree` / `ExistBlockTree` /
Block refs of an encrypted notebook: normal within the notebook, forbidden across the encrypted boundary. Three layers of defense:
-1. Frontend search dispatch: When typing `((` or `{{` in an encrypted notebook triggers a search, the request carries a `notebook` parameter; the kernel only searches that notebook's own encrypted SQLite database, so results exclude other notebooks' blocks
+1. Frontend search dispatch: When typing `((` or `{{` in an encrypted notebook triggers a search, the request includes a `notebook` parameter; the kernel only searches that notebook's own encrypted SQLite database, so results exclude other notebooks' blocks
2. Handler dispatch: Encrypted notebooks call a dedicated search variant
-3. Write-time fallback check: Before a transaction commits, the tree is walked and each block-ref node is checked for crossing the boundary; if so, it is downgraded to plain text (ref attributes cleared, anchor text kept). Defends against hand-entered block IDs, drag-and-drop, paste, direct API calls
+3. Write-time fallback check: Before a transaction commits, the tree is traversed and each block-ref node is checked for crossing the boundary; if so, it is downgraded to plain text (ref attributes cleared, anchor text kept). Defends against hand-entered block IDs, drag-and-drop, paste, direct API calls
### Cross-boundary move rules
Encrypted notebooks forbid moving documents across the encrypted boundary (normal ↔ encrypted, bidirectional).
-Data-corruption risk: Cross-notebook moves use a filesystem Rename to directly move `.sy` bytes, with no encrypt/decrypt conversion. Ciphertext moved to a normal directory is unreadable; plaintext moved to an encrypted directory is unreadable. Indexes also cannot be migrated across dbs.
+Data-corruption risk: Cross-notebook moves use a filesystem Rename to directly move `.sy` bytes, with no encrypt/decrypt conversion. Therefore, ciphertext moved to a normal directory is unreadable; plaintext moved to an encrypted directory is unreadable. Indexes also cannot be migrated across dbs.
Move within the same encrypted notebook: A `.sy` ciphertext object's AAD binds only its stable basename, not its parent directory. A move that preserves the basename follows normal within-notebook move semantics and may Rename ciphertext verbatim without re-enveloping the root or descendants. Only a basename change verifies and decrypts with the old basename and re-envelopes with the new one. Indexes are updated after the move, and failure handling remains the same as for a normal notebook; no additional encrypted hierarchy metadata is introduced.
@@ -442,7 +442,7 @@ Performance summary:
The global state is `Disabled`, `Enabled`, or `RecoveryRequired`. In normal steady state, `Disabled` has no live encrypted notebook or kernel-enumerable key dependency. If startup discovers encrypted notebooks or recovery artifacts while global configuration is missing or disabled, it enters `RecoveryRequired`, never treats them as normal notebooks, and waits for a matching key backup to be restored. Under `Enabled`, each encrypted notebook independently has one of these states: `Locked`, `Unlocking`, `Unlocked`, `Locking`, or `Error`, and starts as `Locked` after application startup.
-Encrypted identity detection is fail-closed. If a valid boxID has a missing or damaged `conf.json` or notebook key backup, the presence of a current ciphertext marker or an encryption identity already confirmed by the current process puts the notebook in `Error` and denies normal-notebook reads and writes; the kernel never auto-creates an `Encrypted=false` configuration. Only the notebook-deletion flow may remove the runtime identity, after draining lifecycle leases and clearing the local DEK, mount marker, dedicated databases, and caches.
+Encrypted identity detection is fail-closed. If a valid boxID has a missing or damaged `conf.json` or notebook key backup, the presence of a current ciphertext marker or an encryption identity already confirmed by the current process sets the notebook to `Error` and denies normal-notebook reads and writes; the kernel never auto-creates an `Encrypted=false` configuration. Only the notebook-deletion flow may remove the runtime identity, after draining lifecycle leases and clearing the local DEK, mount marker, dedicated databases, and caches.
| Transition | Preconditions | Invariants after success | Failure handling |
|---|---|---|---|
@@ -487,7 +487,7 @@ Table-cell rich text uses document `Spec: "4"` and an optional `TableCellRich` s
### Security boundary
-Security premise: An encrypted notebook provides its strongest application-level protection while closed (locked). After locking completes, new operations are denied, managed DEK handles and database connections are removed, and kernel-managed plaintext caches, temporary files, and tokens are cleaned on a best-effort basis; this does not promise erasure of every transient copy in the Go runtime, OS swap, crash dumps, or storage media. When open (unlocked), the application holds a usable DEK handle, and callers authorized by the main application — APIs, third-party plugins, AI/LLM (including MCP and agents) — can read plaintext content and use in-notebook search through supported notebook-specific entry points; global search, semantic search, and embedding vectorization do not participate. The publish service is an explicit exception: publish readers and anonymous visitors cannot enumerate or read encrypted notebooks regardless of unlock state, and publish passwords, visibility configuration, and `publishAccess.json` cannot override this rule. The kernel CLI likewise rejects encrypted notebooks and their raw files regardless of lock state. Encryption protects data at rest and unreachability through supported entry points after locking; it does not protect visibility to callers authorized by the main application while unlocked. Treat an unlocked encrypted notebook as a normal notebook in active use within the main application and lock it immediately afterwards.
+Security premise: An encrypted notebook provides its strongest application-level protection while closed (locked). After locking completes, new operations are denied, managed DEK handles and database connections are removed, and kernel-managed plaintext caches, temporary files, and tokens are cleaned on a best-effort basis; this does not promise erasure of every transient copy in the Go runtime, OS swap, crash dumps, or storage media. When open (unlocked), the application holds a usable DEK handle, and callers authorized by the main application — APIs, third-party plugins, AI/LLM (including MCP and agents) — can read plaintext content and use in-notebook search through supported notebook-specific entry points; global search, semantic search, and embedding vectorization do not participate. The publish service is an explicit exception: publish readers and anonymous visitors cannot enumerate or read encrypted notebooks regardless of unlock state, and publish passwords, visibility configuration, and `publishAccess.json` cannot override this rule. The kernel CLI likewise rejects encrypted notebooks and their raw files regardless of lock state. Encryption protects data at rest and unreachability through supported entry points after locking; it does not protect visibility to callers authorized by the main application while unlocked. Therefore, treat an unlocked encrypted notebook as a normal notebook in active use within the main application and lock it immediately afterwards.
Protected (ciphertext on disk):
@@ -519,7 +519,7 @@ Not protected:
- The content field of history indexes (left empty; neither plaintext nor ciphertext)
-- Metadata leakage (encryption does not conceal): file count, directory structure, file sizes, modification times (mtime), asset file extensions, blockID timestamps. Encrypted-notebook asset filenames are desensitized to `uuid-blockID.ext` but the extension is visible; old ciphertext retained in sync endpoints or historical snapshots is held by those storage providers, and the encrypted notebook cannot revoke their copies
+- Metadata leakage (encryption does not conceal): file count, directory structure, file sizes, modification times (mtime), asset file extensions, blockID timestamps. Encrypted-notebook asset filenames are desensitized to `uuid-blockID.ext` but the extension is visible; old ciphertext retained in sync endpoints or historical snapshots is held by those storage providers, so the encrypted notebook cannot revoke their copies
API protection:
@@ -575,7 +575,7 @@ Backup persistence follows the project's existing file-write semantics. The glob
An HMAC proves only that a party without the KEK did not alter the backup; it does not prove that the backup is the latest version. The current scope introduces no trusted external monotonic counter, so an authenticated historical backup or ciphertext may pass validation. `BackupID` and `CreatedAt` are information for diagnostics and manual comparison, not rollback anchors. Sync, history, and recovery flows must not describe successful authentication as proof of freshness or source trust. Strong rollback prevention requires independent trusted state and is outside this design's scope.
-Sync endpoints and offline backups are storage that may be lost, copied, or rolled back but cannot read plaintext. Trustworthy KEK-based authentication cannot be established before the master password is entered. Users keep at least one independent, versioned key backup and understand that losing the master password or every matching MasterSalt backup is unrecoverable. While a live encrypted notebook, deleted-notebook history, or kernel-enumerable local recovery snapshot depends on the current NotebookCrypto, disabling must refuse to delete global configuration and backup; only an explicit permanent purge of those recovery artifacts removes the dependency. External and remote copies cannot be enumerated reliably, so retaining their matching key backup is the user's responsibility.
+Sync endpoints and offline backups are storage that may be lost, copied, or rolled back but cannot read plaintext. Trustworthy KEK-based authentication cannot be established before the master password is entered. Therefore, users keep at least one independent, versioned key backup and understand that losing the master password or every matching MasterSalt backup is unrecoverable. While a live encrypted notebook, deleted-notebook history, or kernel-enumerable local recovery snapshot depends on the current NotebookCrypto, disabling must refuse to delete global configuration and backup; only an explicit permanent purge of those recovery artifacts removes the dependency. External and remote copies cannot be enumerated reliably, so retaining their matching key backup is the user's responsibility.
| Category | May be exposed |
|---|---|
@@ -629,7 +629,7 @@ Parent directories below the history root are not part of AAD. Every history ent
| Disk inspection of files, assets, databases, WAL/SHM, history, snapshots, and logs | No readable body, asset contents, original asset names, or plaintext SQLite pages exist in encrypted-notebook persistent locations; `temp/` may contain plaintext during export or after cleanup failure |
| Restart after an abnormal exit | Startup removes at least entries under `temp/export/` whose first-level name is a valid boxID; generic temporary-directory initialization may also remove other exports and plugin temporary files |
| Ciphertext tampering, path substitution, and backup corruption | Authentication or format validation fails safely; never fall back to a normal path, generate replacement key material, or silently overwrite configuration |
-| Both an encrypted notebook's `conf.json` and notebook key backup are missing, or sync removes an encrypted notebook that is currently open locally | Ciphertext or runtime identity puts the former in `Error` without creating a normal configuration; the latter drains in-flight leases and clears the DEK, mount, dedicated databases, caches, and indexes even though `Conf.GetBox` is empty after deletion |
+| Both an encrypted notebook's `conf.json` and notebook key backup are missing, or sync removes an encrypted notebook that is currently open locally | Ciphertext or runtime identity sets the former to `Error` without creating a normal configuration; the latter drains in-flight leases and clears the DEK, mount, dedicated databases, caches, and indexes even though `Conf.GetBox` is empty after deletion |
| Nonce randomness failure or discovering nonce reuse afterwards | Reject before encryption on randomness failure; no persistent lifetime invocation bound is currently enforced. AES-GCM authentication cannot detect nonce reuse that already occurred; discovery requires migration to a new DEK, not merely changing the master password |
| Replay an authenticated historical ciphertext object or key backup | It may validate as an authentic old version but is never claimed to be freshest or from a trusted source; rollback risk is explicit, and the current design does not claim rollback prevention |
| Master-password change and KEK rewrapping | WrappedDEKs, historical KEKs, and backups update through a recoverable transaction; the current password can recover old envelopes after repeated password changes, notebook deletion, backup import, and interrupted migration; old-password exposure warnings remain accurate |
diff --git a/docs/ENCRYPTED-NOTEBOOK.zh-CN.md b/docs/ENCRYPTED-NOTEBOOK.zh-CN.md
index c64768a428..7dcf3b904a 100644
--- a/docs/ENCRYPTED-NOTEBOOK.zh-CN.md
+++ b/docs/ENCRYPTED-NOTEBOOK.zh-CN.md
@@ -18,7 +18,7 @@
| 笔记本身份 | 动态 boxID + `BoxConf.Encrypted: true` 标志位 |
| 数量 | 支持多个加密笔记本 |
| 密码 | 共用主密码(KEK 包络,每个笔记本独立 DEK) |
-| 解锁粒度 | 严格每笔记本单独解锁(KEK 用完即弃,每次跑 Argon2id ~1 秒) |
+| 解锁粒度 | 严格每笔记本单独解锁(KEK 用完即弃,每次执行 Argon2id ~1 秒) |
| SQLite 数据库方案 | 每个加密笔记本物理独立 SQLCipher SQLite 数据库,与全局 siyuan.db 隔离 |
| 隔离原则 | 每个加密笔记本是一个独立孤岛——与普通笔记本隔离,加密笔记本之间也互相隔离。数据、块引、数据库镜像、移动都不跨加密笔记本边界。解锁一个加密笔记本不影响其他加密笔记本的锁定状态。 |
| 全局功能 | 加密笔记本完全不参与(全局搜索/关系图/块引都看不到它) |
@@ -58,10 +58,10 @@
| 资源文件重命名 | 支持 | 不支持(脱敏文件名重命名会破坏映射) |
| 资源文件文字识别(OCR) | 支持 | 不支持,与解锁状态无关 |
| 导入 | 支持 | 支持(.sy.zip 和 Markdown,落盘前自动 DEK 加密) |
-| 笔记本内搜索 | 走全局 SQLite 数据库 | 走加密 SQLite 数据库 |
-| 反链面板 | 走全局 SQLite 数据库 | 走加密 SQLite 数据库(含 mention 子查询) |
-| 打开文档 / 大纲 / 面包屑 / 块信息 / 悬浮预览 | 走全局 SQLite 数据库 | 走加密 SQLite 数据库 |
-| 数据库 | 走全局存储 + 全局 SQLite 数据库 | 走笔记本级存储(DEK 加密)+ 加密 SQLite 数据库 |
+| 笔记本内搜索 | 使用全局 SQLite 数据库 | 使用加密 SQLite 数据库 |
+| 反链面板 | 使用全局 SQLite 数据库 | 使用加密 SQLite 数据库(含 mention 子查询) |
+| 打开文档 / 大纲 / 面包屑 / 块信息 / 悬浮预览 | 使用全局 SQLite 数据库 | 使用加密 SQLite 数据库 |
+| 数据库 | 使用全局存储 + 全局 SQLite 数据库 | 使用笔记本级存储(DEK 加密)+ 加密 SQLite 数据库 |
| 文件历史 | 支持 | 支持(密文 .sy 原样存历史目录;历史条目保留快照写入时的 boxID、对象类型和稳定文件基名,查看/回滚以三者作为 AAD 上下文解密) |
| 已删除笔记本历史 | 支持 | 支持(删除前整个目录密文备份,恢复时原样拷回;恢复还需要匹配的全局密钥备份和主密码) |
| 嵌入向量化 / 语义搜索 | 参与 | 不参与(加密数据不进全局 block_embeddings 表,嵌入流水线只读全局库;与解锁状态无关) |
@@ -88,9 +88,9 @@
- 发布:发布服务面向只读或匿名访问者,加密笔记本无论锁定或解锁均不参与发布,且不能通过发布密码或可见性配置启用
-- 书签:全局聚合视图(扫全局 siyuan.db),加密笔记本不支持
+- 书签:全局聚合视图(扫描全局 siyuan.db),加密笔记本不支持
-- 标签:全局聚合视图(扫全局 spans 表),加密笔记本不支持
+- 标签:全局聚合视图(扫描全局 spans 表),加密笔记本不支持
- 资源文件重命名:加密笔记本的 asset 文件名已脱敏为 `uuid-blockID.ext`,磁盘文件名参与 AAD,重命名需要重新封装整个资源
@@ -100,7 +100,7 @@
## 用户交互
-Windows 和 macOS 桌面端在 设置 - 鉴权 - 加密笔记本 中提供「跟随系统锁屏」开关,默认关闭。开启后,系统锁屏会锁定桌面端自行启动的各工作空间内核中的所有已解锁加密笔记本,独立于闲置自动锁定时间生效,闲置时间为零时也有效。远程连接、浏览器、Linux 和移动端不触发此桌面系统锁屏操作。系统解锁不会自动解锁笔记本。
+Windows 和 macOS 桌面端在 设置 - 鉴权 - 加密笔记本 中提供「跟随系统锁屏」开关,默认关闭。开启后,系统锁屏会锁定桌面端自行启动的各工作空间内核中的所有已解锁加密笔记本,独立于闲置自动锁定时间生效,闲置时间为零时也有效。远程连接、浏览器、Linux 和移动端不触发此桌面系统锁屏操作。但系统解锁不会自动解锁笔记本。
桌面主进程最多等待一秒,让正常响应的编辑器窗口提交待保存输入,然后调用经过认证的内核锁定接口。内核等待正在进行的解锁完成,再收集已解锁笔记本,复用正常卸载流程排空事务、保存历史、撤销访问并清除受管理的密钥和缓存。无响应窗口不能无限阻止锁定,尚未送达内核的输入无法保证保存。请求失败时,在系统解锁或唤醒后重试。这是异步锁定操作,不保证操作系统在休眠前等待其完成。
@@ -166,7 +166,7 @@ Windows 和 macOS 桌面端在 设置 - 鉴权 - 加密笔记本 中提供「跟
1. 在新设备配置好相同的同步账号并完成同步
-2. 同步会把密钥备份拉到本地,内核自动恢复"已启用"状态
+2. 同步会把密钥备份拉取到本地,内核自动恢复"已启用"状态
3. 直接点击加密笔记本,输入主密码即可解锁使用
@@ -186,7 +186,7 @@ Windows 和 macOS 桌面端在 设置 - 鉴权 - 加密笔记本 中提供「跟
无法恢复——这是设计使然(没有后门)。即使密文已同步到云端,没有主密码也解不开。务必牢记主密码,建议使用密码管理器保存。
#### 密钥备份丢失的恢复
-若 `conf/conf.json` 与同步目录里的密钥备份同时丢失(极端情况),重新启用加密笔记本会被拒绝并提示恢复备份文件。只要能从其他已同步的设备或之前导出的密钥文件找回 `data-crypto-backup.json`,可通过 `Disabled` 或 `RecoveryRequired` 状态下显示的「导入密钥」按钮导入,或手动放回 `<工作区>/data/.siyuan/` 后重新启用,即可用该密钥对应的主密码解锁。
+若 `conf/conf.json` 与同步目录里的密钥备份同时丢失(极端情况),重新启用加密笔记本会被拒绝并提示恢复备份文件。只要能从其他已同步的设备或之前导出的密钥文件找回 `data-crypto-backup.json`,可通过 `Disabled` 或 `RecoveryRequired` 状态下显示的「导入密钥」按钮导入,或手动恢复到 `<工作区>/data/.siyuan/` 后重新启用,即可用该密钥对应的主密码解锁。
恢复已删除加密笔记本的历史同样需要与其 WrappedDEK 匹配的全局密钥备份和主密码。只要仍要保留这类本地恢复能力,就不要永久清除其历史或匹配的密钥备份;禁用流程应在发现这类依赖时拒绝继续。
@@ -226,7 +226,7 @@ Windows 和 macOS 桌面端在 设置 - 鉴权 - 加密笔记本 中提供「跟
2. 用完即锁:减少 DEK 在内存的暴露时间
-3. 不要把所有笔记都放加密笔记本:只放真正敏感的
+3. 不要把所有笔记都保存在加密笔记本:只保存真正敏感的
4. 主密码强度:建议 12 位以上,混合大小写 + 数字 + 符号
@@ -259,27 +259,27 @@ Windows 和 macOS 桌面端在 设置 - 鉴权 - 加密笔记本 中提供「跟
MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2id 派生 KEK,KEK 再解开各笔记本的 WrappedDEK。MasterSalt 丢失等于数据永久锁死:即使输入相同主密码,因 salt 变化派生出的 KEK 不同,旧 WrappedDEK 无法解开。为此引入备份与恢复机制。
-备份:`<DataDir>/.siyuan/data-crypto-backup.json`,保存整套 NotebookCrypto(MasterSalt/KEKVerifier/KDFParams/HistoryKEKs)。位于 DataDir 内,进入 dejavu 同步范围。启用加密笔记本、修改主密码时刷新;只有禁用前确认不存在现存加密笔记本,也不存在依赖该备份的内核可枚举历史或恢复快照,或用户明确选择永久清除这些恢复数据后,才能删除。备份文件按明文 JSON 存储,其中 verifier 和历史 KEK 均为密文,与 `conf/conf.json` 的存储方式一致。
+备份:`<DataDir>/.siyuan/data-crypto-backup.json`,保存整套 NotebookCrypto(MasterSalt/KEKVerifier/KDFParams/HistoryKEKs)。位于 DataDir 内,因此进入 dejavu 同步范围。启用加密笔记本、修改主密码时刷新;只有禁用前确认不存在现存加密笔记本,也不存在依赖该备份的内核可枚举历史或恢复快照,或用户明确选择永久清除这些恢复数据后,才能删除。备份文件按明文 JSON 存储,其中 verifier 和历史 KEK 均为密文,与 `conf/conf.json` 的存储方式一致。
-每个加密笔记本另行保存 `<DataDir>/<boxID>/.siyuan/notebook-crypto-backup.json`,其中包含该笔记本的 BoxEncryption 密钥包络(WrappedDEK/WrapNonce 和认证元数据)。全局 `data-crypto-backup.json` 提供 KEK 派生身份,单笔记本 `notebook-crypto-backup.json` 提供已封装 DEK,两者不能相互替代。
+每个加密笔记本另行保存 `<DataDir>/<boxID>/.siyuan/notebook-crypto-backup.json`,其中包含该笔记本的 BoxEncryption 密钥包络(WrappedDEK/WrapNonce 和认证元数据)。全局 `data-crypto-backup.json` 提供 KEK 派生身份,单笔记本 `notebook-crypto-backup.json` 提供已封装 DEK,因此两者不能相互替代。
恢复触发点(覆盖 conf.json 丢失 / 同步到新设备 / 导入 Data.zip 等场景):
| 触发场景 | 函数 | 需要主密码? | 说明 |
|---|---|---|---|
-| 同步完成后(拉取到备份文件) | `restoreNotebookCryptoConfigFromBackup` | 否 | 把配置装回本机 conf.json 并置 `Enabled=true`,UI 显示"已启用、锁定" |
+| 同步完成后(拉取到备份文件) | `restoreNotebookCryptoConfigFromBackup` | 否 | 把配置写回本机 conf.json 并置 `Enabled=true`,UI 显示"已启用、锁定" |
| 导入 Data.zip 后 | `restoreNotebookCryptoConfigFromBackup` | 否 | 同上,覆盖"备份随 Data.zip 到达本机但本机未启用"的情况 |
-| 用户输主密码解锁(兜底) | `tryRestoreNotebookCryptoFromBackup` | 是 | `deriveKEK` 在本机 `Enabled=false` 时尝试恢复,校验主密码后返回 KEK |
+| 用户输主密码解锁(最终保障) | `tryRestoreNotebookCryptoFromBackup` | 是 | `deriveKEK` 在本机 `Enabled=false` 时尝试恢复,校验主密码后返回 KEK |
| 用户手动启用(恢复保护) | `tryRestoreNotebookCryptoFromBackup` | 是 | 已存在加密笔记本时拒绝生成新 salt,改为从备份恢复并校验主密码 |
-配置恢复 vs 密钥恢复分离:配置恢复只需读备份文件、装回 salt/verifier(不需主密码,因 salt 不保密、没主密码仍解不开数据);密钥恢复才需主密码派生 KEK 并校验 verifier。这让同步/导入后能自动进入"已启用"状态,用户输主密码即可解锁。
+配置恢复 vs 密钥恢复分离:配置恢复只需读备份文件、写回 salt/verifier(不需主密码,因 salt 不保密、没主密码仍解不开数据);密钥恢复才需主密码派生 KEK 并校验 verifier。这让同步/导入后能自动进入"已启用"状态,用户输主密码即可解锁。
手动导出与导入密钥:除自动同步外,用户可在 设置 - 鉴权 - 加密笔记本 手动导出与导入密钥备份,作为同步之外的独立恢复途径(如同步不可用、跨账号迁移、物理离线转存)。
| 操作 | 入口 | 说明 |
|---|---|---|
| 导出密钥 | 已启用状态下显示 | 把 `data-crypto-backup.json` 复制到 export 目录供下载,用户自行保管(API:`/api/notebook/exportNotebookCryptoBackup`) |
-| 导入密钥 | `Disabled` 或 `RecoveryRequired` 状态下显示 | 选本地备份文件上传,校验合法后写回 `<DataDir>/.siyuan/` 并装回本机配置(`Enabled=true`)。后续用该密钥对应的主密码解锁(API:`/api/notebook/importNotebookCryptoBackup`) |
+| 导入密钥 | `Disabled` 或 `RecoveryRequired` 状态下显示 | 选本地备份文件上传,校验合法后写回 `<DataDir>/.siyuan/` 并恢复本机配置(`Enabled=true`)。后续用该密钥对应的主密码解锁(API:`/api/notebook/importNotebookCryptoBackup`) |
导入恢复保护:完整的 `Enabled` 配置拒绝导入,避免覆盖现有 salt 并孤立 WrappedDEK;`RecoveryRequired` 仅在候选密钥通过认证且能解开全部现存加密笔记本及内核可枚举的已删除笔记本历史依赖时允许导入。备份文件本身不含主密码(salt 不保密、verifier 是密文),导出和导入不涉及明文数据泄漏,解锁仍需主密码。
@@ -375,9 +375,9 @@ assets 加密:
→ 加密 blocktree SQLite 数据库 → 加密 content SQLite 数据库
```
-写路径:集中收口,按笔记本选 SQLite 数据库。索引队列、blocktree 写函数、索引订正全部按笔记本路由。
+写路径:集中于统一入口,按笔记本选 SQLite 数据库。索引队列、blocktree 写函数、索引订正全部按笔记本路由。
-读路径:三层 fall-through——handler 层按 `notebook` 参数分流;原函数转发到 InBox 版(普通路径传空 boxID);底层 wrapper 按加密 SQLite 数据库 是否打开决定路由,空 boxID 必走全局 SQLite 数据库。
+读路径:三层 fall-through——handler 层按 `notebook` 参数分流;原函数转发到 InBox 版(普通路径传空 boxID);底层 wrapper 按加密 SQLite 数据库 是否打开决定路由,空 boxID 必定使用全局 SQLite 数据库。
深度全路由原则:加密笔记本的读操作经过的每一个 sql 调用(含深层 helper:引用计数、块名/别名、子块递归、FTS 计数、高亮、mention 搜索、refs 定义查询等)都路由到加密 SQLite 数据库,绝不泄漏到全局 SQLite 数据库。
@@ -391,17 +391,17 @@ assets 加密:
2. handler 分流:加密笔记本调专用搜索版
-3. 落库兜底校验:事务落库前遍历树,对每个块引节点判定是否跨边界,跨边界则降级为纯文本(清空引用属性,保留锚文本)。防御手工输入块 ID、拖拽、粘贴、API 直调
+3. 落库最终校验:事务落库前遍历树,对每个块引节点判定是否跨边界,跨边界则降级为纯文本(清空引用属性,保留锚文本)。以防御手工输入块 ID、拖拽、粘贴、API 直调
### 跨边界移动规则
加密笔记本禁止文档跨加密边界移动(普通 ↔ 加密,双向)。
-数据损坏风险:跨笔记本移动用文件系统 Rename 直搬 `.sy` 字节流,不经加解密转换。密文搬到普通目录不可读,明文搬到加密目录不可读。索引也无法跨库迁移。
+数据损坏风险:跨笔记本移动用文件系统 Rename 直接移动 `.sy` 字节流,不经加解密转换。因此密文移动到普通目录不可读,明文移动到加密目录不可读。索引也无法跨库迁移。
同一加密笔记本内移动:`.sy` 密文 AAD 只绑定稳定文件基名,不绑定父目录。文件基名不变的移动按普通笔记本的同箱移动语义原样 Rename 密文,不需要重新封装根文档或子文档;只有文件基名本身变化时才使用旧基名验证解密并按新基名重新封装。移动完成后更新索引,失败处理与普通笔记本一致,不额外引入加密层级元数据。
-安全泄漏风险:从加密笔记本移动到普通笔记本时——文档正文脱离加密保护;关联 resources 必须一起搬出解密;绑定块与子文档的引用网被割裂或连带泄漏;索引元数据跨库迁移破坏隔离。
+安全泄漏风险:从加密笔记本移动到普通笔记本时——文档正文脱离加密保护;关联 resources 必须一起移出解密;绑定块与子文档的引用网被割裂或连带泄漏;索引元数据跨库迁移破坏隔离。
设计立场:加密笔记本是孤岛,内容不进出(从加密笔记本移出到普通笔记本会泄漏明文;反之会损坏密文)。
@@ -440,7 +440,7 @@ assets 加密:
### 状态机与并发规则
-全局状态为 `Disabled`、`Enabled` 或 `RecoveryRequired`。正常稳态下,`Disabled` 不得存在现存加密笔记本或内核可枚举的密钥依赖;如果启动时在全局配置缺失或禁用的情况下发现加密笔记本或恢复数据,必须进入 `RecoveryRequired`,拒绝把它们当作普通笔记本,直到恢复匹配的密钥备份。`Enabled` 下每个加密笔记本独立处于 `Locked`、`Unlocking`、`Unlocked`、`Locking` 或 `Error`,应用启动后均从 `Locked` 开始。
+全局状态为 `Disabled`、`Enabled` 或 `RecoveryRequired`。正常稳态下,`Disabled` 不得存在现存加密笔记本或内核可枚举的密钥依赖;如果启动时全局配置缺失或禁用,发现加密笔记本或恢复数据,必须进入 `RecoveryRequired`,拒绝把它们当作普通笔记本,直到恢复匹配的密钥备份。`Enabled` 下每个加密笔记本独立处于 `Locked`、`Unlocking`、`Unlocked`、`Locking` 或 `Error`,应用启动后均从 `Locked` 开始。
加密身份判定必须 fail-closed。合法 boxID 的 `conf.json` 或笔记本密钥备份缺失、损坏时,只要磁盘上存在当前密文格式标识,或当前进程已经确认过该笔记本的加密身份,就必须把笔记本置为 `Error` 并拒绝普通笔记本读写,不能自动生成 `Encrypted=false` 的配置。只有笔记本删除流程在排空生命周期租约并清除本机 DEK、挂载标记、专属数据库和缓存后,才能移除运行时加密身份。
@@ -519,7 +519,7 @@ assets 加密:
- 历史索引的 content 字段(留空,不存明文也不存密文)
-- 元数据泄漏(加密不掩盖以下信息):文件数量、目录结构、文件大小、修改时间(mtime)、asset 文件扩展名、blockID 时间戳。加密笔记本的 asset 文件名虽脱敏为 `uuid-blockID.ext`,但扩展名可见;同步端/历史快照中的旧密文也由各存储方自行保管,加密笔记本无法吊销其副本
+- 元数据泄漏(加密不掩盖以下信息):文件数量、目录结构、文件大小、修改时间(mtime)、asset 文件扩展名、blockID 时间戳。加密笔记本的 asset 文件名虽脱敏为 `uuid-blockID.ext`,但扩展名可见;同步端/历史快照中的旧密文也由各存储方自行保管,因此加密笔记本无法吊销其副本
API 防护:
@@ -575,7 +575,7 @@ SQLCipher 的主数据库、WAL、SHM、回滚日志、临时文件和备份副
HMAC 只能证明备份内容未被不知道 KEK 的一方篡改,不能证明它是最新版本。当前范围不引入可信外部单调计数器,因此一个认证有效的历史备份或历史密文可能通过校验;`BackupID` 和 `CreatedAt` 只是供诊断和人工比较的信息,不是防回滚锚点。同步、历史或恢复流程不得把“认证成功”表述为“最新”或“来源可信”;真正防回滚需要独立可信状态,超出本设计范围。
-同步端和离线备份被视为可丢失、可复制、可回滚但不能读取明文的存储。输入主密码前不能建立基于 KEK 的可信认证;用户应保留至少一份独立、版本化的密钥备份,并理解丢失主密码或全部匹配的 MasterSalt 备份均不可恢复。只要现存加密笔记本、已删除笔记本历史或内核可枚举的本地恢复快照仍依赖当前 NotebookCrypto,禁用功能就必须拒绝删除全局配置和备份;用户明确永久清除这些恢复数据后才可解除依赖。外部与远端副本无法可靠枚举,是否保留其匹配密钥备份由用户负责。
+同步端和离线备份被视为可丢失、可复制、可回滚但不能读取明文的存储。输入主密码前不能建立基于 KEK 的可信认证;因此用户应保留至少一份独立、版本化的密钥备份,并理解丢失主密码或全部匹配的 MasterSalt 备份均不可恢复。只要现存加密笔记本、已删除笔记本历史或内核可枚举的本地恢复快照仍依赖当前 NotebookCrypto,禁用功能就必须拒绝删除全局配置和备份;用户明确永久清除这些恢复数据后才可解除依赖。外部与远端副本无法可靠枚举,是否保留其匹配密钥备份由用户负责。
| 类别 | 是否可泄露 |
|---|---|
diff --git a/docs/PINNED-DOCUMENTS.md b/docs/PINNED-DOCUMENTS.md
index 214c213bff..bed76de829 100644
--- a/docs/PINNED-DOCUMENTS.md
+++ b/docs/PINNED-DOCUMENTS.md
@@ -10,7 +10,7 @@ The pinned section appears at the top of the document panel and uses pinned docu
## User interaction
-The section appears when it contains pinned documents and hides automatically when empty, on both desktop and mobile. Pin the first document through its context menu; once the section is visible, documents can also be added by dragging. Unpinning the last document hides the section. Incoming synchronized pin data updates visibility in the same way. There is no separate visibility switch, and previously saved visibility settings no longer affect the section. Collapsing the section preserves its entries and their order.
+The section appears when it contains pinned documents and hides automatically when empty, on both desktop and mobile. Pin the first document through its context menu; once the section is visible, documents can also be added by dragging. Unpinning the last document hides the section. Pin data obtained from sync updates visibility in the same way. There is no separate visibility switch, and previously saved visibility settings no longer affect the section. Collapsing the section preserves its entries and their order.
| Operation | Behavior |
|---|---|
diff --git a/docs/PINNED-DOCUMENTS.zh-CN.md b/docs/PINNED-DOCUMENTS.zh-CN.md
index 6f29e088aa..5b821dee2c 100644
--- a/docs/PINNED-DOCUMENTS.zh-CN.md
+++ b/docs/PINNED-DOCUMENTS.zh-CN.md
@@ -10,11 +10,11 @@
## 用户交互
-桌面端和移动端均在有置顶文档时显示置顶区域,没有时自动隐藏。首个置顶通过文档菜单创建,区域显示后也可通过拖拽添加。取消最后一个置顶后区域自动隐藏,同步收到的置顶列表也按相同规则更新显隐。没有独立显隐开关,已保存的旧显隐配置不再影响该区域。折叠区域会保留置顶文档及其顺序。
+桌面端和移动端均在有置顶文档时显示置顶区域,没有时则自动隐藏。首个置顶通过文档菜单创建,区域显示后也可通过拖拽添加。取消最后一个置顶后区域自动隐藏,同步获取到的置顶列表也按相同规则更新显隐。没有独立显隐开关,已保存的旧显隐配置不再影响该区域。折叠区域会保留置顶文档及其顺序。
| 操作 | 行为 |
|---|---|
-| 菜单置顶 | 新入口放在最顶部;已置顶时同一菜单项切换为取消置顶 |
+| 菜单置顶 | 新入口置于最顶部;已置顶时同一菜单项切换为取消置顶 |
| 多选文档 | 同时提供置顶和取消置顶,不区分是否已置顶;包含加密笔记本文档时不提供置顶 |
| 笔记本更多菜单 | 启用笔记本顶级文档后,普通笔记本提供置顶或取消置顶;置顶入口展开后显示该笔记本的可见顶层文档 |
| 置顶文档右键或更多 | 打开文档菜单,支持取消置顶、重命名等操作 |
@@ -30,11 +30,11 @@
| 删除文档或笔记本 | 清理相关入口;读取列表时也过滤不存在的源文档 |
| 加密笔记本 | 不显示置顶操作,服务端拒绝新增,也不返回已有异常入口 |
-根层的拖放提示使用插入线,行中部使用文档高亮,明确区分创建入口和移动源文档。移动到自身或后代的校验交由已有文档移动接口执行。子文档列表按照源文档的有效排序加载;置顶操作不写入 `sort.json`,不改变排序继承。
+根层的拖放提示使用插入线,行中部使用文档高亮,明确区分创建入口和移动源文档。移动到自身或后代的校验由已有文档移动接口执行。子文档列表按照源文档的有效排序加载;置顶操作不写入 `sort.json`,不改变排序继承。
## 数据与存储
-`data/storage/pinned-docs.json` 使用版本 1 格式:`{"version":1,"docs":[{"id":"文档 ID","notebook":"笔记本 ID"}]}`。数组顺序即根层顺序,仅保存标识,不缓存文档内容。文件进入现有数据同步和快照流程,服从工作区同步忽略规则;仅此文件发生同步变更时也刷新文档树面板。跨设备同时编辑沿用现有同步文件冲突处理机制。
+`data/storage/pinned-docs.json` 使用版本 1 格式:`{"version":1,"docs":[{"id":"文档 ID","notebook":"笔记本 ID"}]}`。数组顺序即根层顺序,仅保存标识,不缓存文档内容。文件进入现有数据同步和快照流程,并服从工作区同步忽略规则;仅此文件发生同步变更时也刷新文档树面板。跨设备同时编辑沿用现有同步文件冲突处理机制。
同一内核内的更新由互斥锁串行处理,接口接受相对位置操作,避免客户端提交整份旧列表覆盖其他窗口新增的入口。
@@ -49,7 +49,7 @@
| `/api/filetree/getPinnedDocs` | 无需请求体 | 数组,每项包含 `id`、`notebook`、`name`、`path`、`icon`、`subFileCount`、`unavailable`、`childrenSortMode` |
| `/api/filetree/updatePinnedDocs` | `ids: string[]`、`action: "pin"或"unpin"`,可选 `targetID: string`、`after: boolean` | `null` |
-未指定目标时,置顶操作放到最顶部;指定目标时插入其前面,`after: true` 则插入其后面。取消置顶忽略位置参数。批量请求先校验所有源文档,失败时不写入部分结果。置顶区子树继续通过现有文档列表、移动和排序接口操作,不新增文档副本。
+未指定目标时,置顶操作置于最顶部;指定目标时插入其前面,`after: true` 则插入其后面。取消置顶忽略位置参数。批量请求先校验所有源文档,失败时不写入部分结果。置顶区子树继续通过现有文档列表、移动和排序接口操作,不新增文档副本。
## 兼容与恢复
diff --git a/docs/README.md b/docs/README.md
index 0de423eef6..fcf1025d65 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -34,7 +34,7 @@ On-demand assets, encrypted notebooks, pinned documents, tab blocks, and templat
| Compatibility and recovery | Existing-data support, version rules, failure preservation, interruption recovery, and security boundaries |
| Verification | Required checks for normal, error, concurrent, cross-platform, and existing-data scenarios |
-API contract maintenance, file formats, and workspace layout are maintenance specifications or reference manuals. Organize them by topic rather than imposing the feature design structure.
+API contract maintenance, file formats, and workspace layout are maintenance specifications or reference manuals. Therefore, organize them by topic rather than imposing the feature design structure.
## Style and formatting
diff --git a/docs/README.zh-CN.md b/docs/README.zh-CN.md
index 2e667d93f0..ef6b0a7024 100644
--- a/docs/README.zh-CN.md
+++ b/docs/README.zh-CN.md
@@ -23,7 +23,7 @@
## 功能设计文档结构
-资源按需下载、加密笔记本、文档置顶、页签块和模板管理使用以下二级章节,专题细节放在对应章节的三级标题下。
+资源按需下载、加密笔记本、文档置顶、页签块和模板管理使用以下二级章节,专题细节置于对应章节的三级标题下。
| 章节 | 内容 |
|---|---|
@@ -34,7 +34,7 @@
| 兼容与恢复 | 已有数据支持、版本规则、失败保留、中断恢复和安全边界 |
| 验证范围 | 正常、异常、并发、跨端和旧数据场景的检查要求 |
-接口契约维护、文件格式和工作区布局属于维护规范或参考手册,按主题组织章节,不套用功能设计结构。
+接口契约维护、文件格式和工作区布局属于维护规范或参考手册,因此按主题组织章节,不套用功能设计结构。
## 文风与格式
diff --git a/docs/SY-FORMAT.md b/docs/SY-FORMAT.md
index deaf83bd89..21103ee01f 100644
--- a/docs/SY-FORMAT.md
+++ b/docs/SY-FORMAT.md
@@ -19,7 +19,7 @@ This guide distinguishes the format that new writers should emit from historical
| Term | Meaning |
|---|---|
| **Required** | Required in newly generated canonical data |
-| **Optional** | May be omitted because the field is empty or carries `omitempty` |
+| **Optional** | May be omitted because the field is empty or contains `omitempty` |
| **Compatible input** | Historical or external data that the reader may accept and preserve, repair, or upgrade according to explicit compatibility rules |
Unless a section explicitly says otherwise, "required" refers to canonical new writes. `dataparser.ParseJSON` is a compatibility reader rather than a strict schema validator: for example, it can add a missing empty paragraph, assign a missing block ID, and upgrade an old `Spec`.
@@ -105,7 +105,7 @@ Division of labor among the four paths:
- `Properties.updated` is the same 14-digit timestamp; semantics: "last updated time".
- When changing block content or structure, refresh `Properties.updated` on the changed block, its block-level ancestors, applicable preceding headings, and the document root.
- When you change any block's `ID`, you must **sync** `Properties.id`. Its `Properties.updated` must be no earlier than the creation time encoded by the new ID.
-- Compatible historical input may lack `updated`; canonical new writes should always include it on block nodes.
+- Compatible historical input may lack `updated`; however, canonical new writes should always include it on block nodes.
---
@@ -159,7 +159,7 @@ NodeList NodeList
└─ NodeParagraph └─ NodeCodeBlock ← illegal
```
-**Nested lists** are written by wrapping another `NodeList` (`NodeListItem` falls into the default `CanContain` branch and cannot directly contain another `NodeListItem`):
+**Nested lists** are written by wrapping another `NodeList` (`NodeListItem` follows the default `CanContain` branch and cannot directly contain another `NodeListItem`):
```
✅ Correct ❌ Wrong
@@ -235,7 +235,7 @@ NodeList NodeList
| `Checked` | bool | boolean | Compatibility metadata derived while parsing a task marker; it is not an aggregate for the whole list and may be omitted |
| `Marker` | []byte | **base64 string** | The marker text, **base64-encoded**; may include a delimiter (`"MS4="` = `1.`) or not (`"MQ=="` = `1`) |
-> Key distinction: **`BulletChar`/`Delimiter` are `byte` in code and appear as int codepoints in JSON**; **`Marker` is `[]byte` in code and appears as a base64 string in JSON**. `Marker`/`BulletChar`/`Delimiter` all carry `omitempty` and may be omitted.
+> Key distinction: **`BulletChar`/`Delimiter` are `byte` in code and appear as int codepoints in JSON**; **`Marker` is `[]byte` in code and appears as a base64 string in JSON**. `Marker`/`BulletChar`/`Delimiter` all contain `omitempty` and may be omitted.
### 5.5 Task marker
@@ -290,7 +290,7 @@ An arbitrary non-space marker such as `!` is also treated as checked and preserv
| `WARNING` | `Warning` | `⚠️` |
| `CAUTION` | `Caution` | `🚨` |
-The table lists the five built-in types and their defaults. Custom `CalloutType`, title, and icon values are also supported. `CalloutIcon` is a literal emoji for `CalloutIconType: 0` (the default, omitted by `omitempty`); `CalloutIconType: 1` means `CalloutIcon` is a custom icon path.
+The table lists the five built-in types and their defaults. However, custom `CalloutType`, title, and icon values are also supported. `CalloutIcon` is a literal emoji for `CalloutIconType: 0` (the default, omitted by `omitempty`); `CalloutIconType: 1` means `CalloutIcon` is a custom icon path.
### 5.8 Super block (nestable; three-marker envelope)
@@ -304,7 +304,7 @@ The table lists the five built-in types and their defaults. Custom `CalloutType`
] }
```
-> `NodeSuperBlockLayoutMarker.Data` can only be `"row"` (vertical) or `"col"` (horizontal). A canonical super block contains the open marker, layout marker, at least one content block, and close marker — at least four children total. It may contain multiple content blocks, can nest, and can hold ordinary content blocks including itself, but not a bare tab item.
+> `NodeSuperBlockLayoutMarker.Data` can only be `"row"` (vertical) or `"col"` (horizontal). A canonical super block contains the open marker, layout marker, at least one content block, and close marker — at least four children total. It may contain multiple content blocks, can nest, and can contain ordinary content blocks including itself, but not a bare tab item.
### 5.9 Embed block (five-part structure `{{ ... }}`)
@@ -321,7 +321,7 @@ The table lists the five built-in types and their defaults. Custom `CalloutType`
### 5.9.1 Tabbed container and tab item (Spec 3)
-`NodeTabs` and `NodeTabItem` are real container blocks with their own `ID`, `Properties.id` and `Properties.updated`. A tabs container holds only tab items; each item holds ordinary content blocks, including nested tabs, and always has at least one body block. Use an empty paragraph for an empty body. A standalone tab item is an editing fragment and cannot be a direct document child.
+`NodeTabs` and `NodeTabItem` are real container blocks with their own `ID`, `Properties.id` and `Properties.updated`. A tabs container contains only tab items; each item contains ordinary content blocks, including nested tabs, and always has at least one body block. Use an empty paragraph for an empty body. A standalone tab item is an editing fragment and cannot be a direct document child.
```json
{
@@ -342,7 +342,7 @@ The table lists the five built-in types and their defaults. Custom `CalloutType`
`NodeTabItem.Properties["tabs-task"]` optionally preserves the original task-list marker. Absence means an ordinary tab, one ASCII space means incomplete, and other supported single-character task markers (including `X`, `/`, and `?`) retain their exact values. Task status is independent of title content and active-tab selection. Markdown export preserves it as an item IAL immediately after the `@tab` title line, for example `{: tabs-task="/"}`. Attribute values must use the same escaping as other IAL values. Conversion back to a task list restores the current marker; conversion to an ordinary list removes the task attribute.
-Documents containing either node require at least `Spec: "3"`; documents using table-cell rich text use Spec 4. Ordinary documents remain on Spec 2. Never lower the version after removing a feature. Check the raw root `Spec` before passing JSON to a tolerant parser, because unknown node types can otherwise lose their children. Unsupported versions must not be repaired and written back.
+Documents containing either node require at least `Spec: "3"`; documents using table-cell rich text use Spec 4. Ordinary documents remain on Spec 2. Never lower the version after removing a feature. Check the raw root `Spec` before passing JSON to a tolerant parser, because unknown node types can otherwise cause their children to be lost. Unsupported versions must not be repaired and written back.
The internal Markdown syntax uses `::: tabs` to open a group and `@tab <inline title>` to start each item; `@tab:active <inline title>` identifies the selected item. The opening fence requires at least three colons and whitespace (spaces or tabs) before `tabs`; canonical output uses one space. Items have no closing marker; the group closes with a standalone fence containing the same number of colons as its opening fence. Outer fences must be longer than nested fences. Indentation is optional, and canonical output computes fence lengths from nesting depth without adding indentation to tab bodies. Old `:::tabs` and `:::tab` syntax is not recognized; existing `.sy` tab nodes retain the same structure.
@@ -364,10 +364,10 @@ An item's IAL appears immediately after its title marker, with no intervening bl
```
Notes:
-- `NodeCodeBlockCode` carries the code content (in `Data`, raw text with `\n` escaped); it's an inline child of `NodeCodeBlock`.
+- `NodeCodeBlockCode` contains the code content (in `Data`, raw text with `\n` escaped); it's an inline child of `NodeCodeBlock`.
- The surrounding fence markers (Open/Info/Close) are likewise inline children.
-- `CodeBlockInfo` is the **base64-encoded language** (`"Z28="` = `go`). The parent's six fields (`IsFencedCodeBlock`/`CodeBlockFenceChar`/`CodeBlockFenceLen`/`CodeBlockOpenFence`/`CodeBlockInfo`/`CodeBlockCloseFence`) all carry `omitempty` and may be omitted as needed — newer `.sy` files often write only `"IsFencedCodeBlock": true`.
-- The current SiYuan Markdown configuration disables indented code blocks (`SetIndentCodeBlock(false)`); canonical new code blocks are fenced.
+- `CodeBlockInfo` is the **base64-encoded language** (`"Z28="` = `go`). The parent's six fields (`IsFencedCodeBlock`/`CodeBlockFenceChar`/`CodeBlockFenceLen`/`CodeBlockOpenFence`/`CodeBlockInfo`/`CodeBlockCloseFence`) all contain `omitempty` and may be omitted as needed — newer `.sy` files often write only `"IsFencedCodeBlock": true`.
+- The current SiYuan Markdown configuration disables indented code blocks (`SetIndentCodeBlock(false)`); therefore, canonical new code blocks are fenced.
### 5.11 Math block (three-part structure)
@@ -390,7 +390,7 @@ Notes:
{ "Type": "NodeAudio", "ID": "...", "Data": "<audio controls src=\"assets/x.wav\"></audio>", "Properties": { "id": "...", "updated": "..." } }
```
-> These five **have no `Children`**; the HTML content (JSON-escaped) goes directly in the top-level `Data`.
+> These five **have no `Children`**; the HTML content (JSON-escaped) is written directly to the top-level `Data`.
### 5.13 Table
@@ -414,13 +414,13 @@ Notes:
- `Data` (`thead`/`tr`/`th`/`td`) may be **omitted** in compact files.
- `Properties.colgroup` stores a `|`-separated CSS style string for each column; empty segments represent columns without an explicit style.
- A table's optional `Properties.caption` stores its caption HTML.
-- A `NodeTableCell` may carry `Properties.colspan`, `Properties.rowspan`, and `Properties.style` for merged-cell and cell-style state.
+- A `NodeTableCell` may contain `Properties.colspan`, `Properties.rowspan`, and `Properties.style` for merged-cell and cell-style state.
-A cell with rich block content additionally carries `"TableCellRich": {"spec": 1, "format": "kramdown", "content": "- first\n- second"}`. This source is authoritative; `Children` remains an inline projection with readable list markers and line breaks. Internal paragraphs, lists, code, and math do not become document blocks and have no persistent block IDs. Images, references to existing blocks, and supported inline formatting remain in the projection for indexing and resource handling. A rich table retains `Properties.custom-sy-table-rich = "1"`; BlockDOM updates must retain this marker even when all rich cells become inline-only or empty, so a writer that omits the source cannot silently replace a rich table.
+A cell with rich block content additionally contains `"TableCellRich": {"spec": 1, "format": "kramdown", "content": "- first\n- second"}`. This source is authoritative; `Children` remains an inline projection with readable list markers and line breaks. Internal paragraphs, lists, code, and math do not become document blocks and have no persistent block IDs. Images, references to existing blocks, and supported inline formatting remain in the projection for indexing and resource handling. A rich table retains `Properties.custom-sy-table-rich = "1"`; BlockDOM updates must retain this marker even when all rich cells become inline-only or empty, so a writer that omits the source cannot silently replace a rich table.
Only paragraphs, headings, lists, blockquotes, ordinary code, and math are supported inside the fragment. Nested tables, databases, superblocks, tabs, callouts, query embeds, executable diagrams, media, widgets, and HTML blocks are rejected. BlockDOM stores the source envelope as UTF-8 JSON encoded with unpadded URL-safe Base64 in the cell's `data-sy-table-cell-rich` attribute. Internal Kramdown uses the corresponding `table-cell-rich` cell IAL; neither representation is a standard Markdown interchange format.
-Readers validate the source version and content before rebuilding the projection. Missing, null, unknown, or malformed envelope fields are errors, and unsupported input must remain unchanged. Ordinary cells have no envelope and are never reinterpreted as Markdown. Opening a cell or editing only ordinary inline content preserves its existing representation. Adding block content for the first time creates the rich envelope and raises the document `Spec` to `4`. Existing rich envelopes remain present when their content becomes inline-only or empty; the document version is never lowered. Standard Markdown uses a readable inline projection, while HTML, PDF, and Word exports expand the fragment only in a transient export tree. Encrypted notebooks authenticate the existing document envelope before parsing this same JSON; key derivation, AAD, and recovery material are unchanged.
+Readers validate the source version and content before rebuilding the projection. Missing, null, unknown, or malformed envelope fields are errors, and unsupported input must remain unchanged. Ordinary cells have no envelope and are never reinterpreted as Markdown. Opening a cell or editing only ordinary inline content preserves its existing representation. Adding block content for the first time creates the rich envelope and raises the document `Spec` to `4`. Existing rich envelopes nevertheless remain present when their content becomes inline-only or empty; the document version is never lowered. Standard Markdown uses a readable inline projection, while HTML, PDF, and Word exports expand the fragment only in a transient export tree. Encrypted notebooks authenticate the existing document envelope before parsing this same JSON; key derivation, AAD, and recovery material are unchanged.
### 5.14 AttributeView block (database; leaf)
@@ -505,7 +505,7 @@ Samples:
{ "Type": "NodeTextMark", "TextMarkType": "inline-memo", "TextMarkInlineMemoContent": "an inline note", "TextMarkTextContent": "note" }
```
-- `TextMarkBlockRefSubtype`: `"s"` = static anchor text, `"d"` = dynamic anchor text (the anchor text follows the target block's content; note that "embed block" is a separate node `NodeBlockQueryEmbed`, unrelated to this).
+- `TextMarkBlockRefSubtype`: `"s"` = static anchor text, `"d"` = dynamic anchor text (the anchor text follows the target block's content; "embed block" is a separate node `NodeBlockQueryEmbed`, unrelated to this).
- `TextMarkType` may stack multiple marks separated by spaces, e.g. `"strong em"`.
- `TextMarkTextContent` is not present on every type (`inline-math` lacks it).
- Strikethrough **supports only double-tilde `~~x~~`**, not single-tilde `~x~` (`SetGFMStrikethrough1(false)`).
@@ -513,7 +513,7 @@ Samples:
### 6.3 Styled inline text: pairing rules
-A `NodeTextMark` carrying color/effects (with `Properties.style`) **must be immediately followed by a** `NodeKramdownSpanIAL`, and the two must share the exact same style text:
+A `NodeTextMark` that contains color/effects (with `Properties.style`) **must be immediately followed by a** `NodeKramdownSpanIAL`, and the two must share the exact same style text:
```json
{ "Type": "NodeTextMark", "Properties": { "style": "color: var(--b3-font-color1); background-color: var(--b3-font-background1);" },
@@ -521,7 +521,7 @@ A `NodeTextMark` carrying color/effects (with `Properties.style`) **must be imme
{ "Type": "NodeKramdownSpanIAL", "Data": "{: style=\"color: var(--b3-font-color1); background-color: var(--b3-font-background1);\"}" }
```
-> When generating styled inline text, these two nodes must appear as a pair, otherwise the kramdown round-trip will drop the style.
+> When generating styled inline text, these two nodes must appear as a pair, otherwise the kramdown round-trip will cause the style to be lost.
### 6.4 `NodeImage` (seven-part core; optional title adds two nodes)
@@ -541,7 +541,7 @@ A `NodeTextMark` carrying color/effects (with `Properties.style`) **must be imme
- Editor-generated image nodes normally have `Data` = `"span"`; compatible compact data may omit an empty `Data`.
- `NodeBang`/`NodeOpenBracket`/`NodeCloseBracket`/`NodeOpenParen`/`NodeCloseParen` markers **may omit** `Data`.
-- `NodeLinkText` and `NodeLinkDest` carry the alt text and destination. When a title exists, insert `NodeLinkSpace` and `NodeLinkTitle` immediately before `NodeCloseParen`; the seven-node form without them is also valid.
+- `NodeLinkText` and `NodeLinkDest` contain the alt text and destination. When a title exists, insert `NodeLinkSpace` and `NodeLinkTitle` immediately before `NodeCloseParen`; the seven-node form without them is also valid.
### 6.5 Line breaks and backslash escapes
@@ -672,9 +672,9 @@ When generating or compatibly editing a `.sy` that SiYuan can load cleanly, veri
| Adding `Children` to AttributeView, Widget, or CustomBlock nodes | They are leaves — use `Data` or their type-specific fields |
| Changing `ID` without syncing `Properties.id` | The two must match |
| Updating only the directly edited block's timestamp | Also refresh its block ancestors, applicable preceding headings, and the document root |
-| `inline-math` carrying `TextMarkTextContent` | It only has `TextMarkInlineMathContent` |
+| `inline-math` containing `TextMarkTextContent` | It only has `TextMarkInlineMathContent` |
| Fabricating block-ref / AV target IDs | Targets must really exist |
-| Hanging a paragraph directly under `NodeList` | `NodeList` can only contain `NodeListItem` — wrap first |
+| Making a paragraph a direct child of `NodeList` | `NodeList` can only contain `NodeListItem` — wrap first |
| Adding U+200B text nodes on both sides of every inline element | Preserve existing U+200B; let Protyle add editor-DOM caret placeholders contextually |
| Generating `NodeGitConflict`, footnotes, ToC, YAML, etc. | They are disabled for canonical writes; compatibility readers may still encounter historical or external nodes |
diff --git a/docs/SY-FORMAT.zh-CN.md b/docs/SY-FORMAT.zh-CN.md
index 31a9d8a32d..25047dfc7e 100644
--- a/docs/SY-FORMAT.zh-CN.md
+++ b/docs/SY-FORMAT.zh-CN.md
@@ -5,12 +5,12 @@
> 规范写入基准:普通文档为 Spec `2`,包含页签的文档为 Spec `3`,使用表格单元格富文本的文档为 Spec `4`;兼容读取器可以升级旧版或缺少 `Spec` 的数据。
> 核验样本:`20200825162036-4dx365o.sy`(排版元素)、`20200905090211-2vixtlf.sy`(内容块类型)。
> 本文档所有结论均基于真实样本及当前 Lute / 思源内核源码核验。上述样本包含少量已知的历史遗留数据;样本与当前源码不一致时,规范写入规则以当前源码为准。
-> 本指南描述普通笔记本中的明文 `.sy` JSON,或已解锁加密笔记本的解密后 AST。加密笔记本磁盘上的 `.sy` 文件是密文,不能当作 JSON 直接编辑。
+> 本指南描述普通笔记本中的明文 `.sy` JSON,或已解锁加密笔记本的解密后 AST。但加密笔记本磁盘上的 `.sy` 文件是密文,不能当作 JSON 直接编辑。
> 配套文档:[`WORKSPACE.zh-CN.md`](./WORKSPACE.zh-CN.md) 讲工作区在磁盘上的整体布局(笔记本、父子文档、资源文件的组织方式);本文档专注 `.sy` 文件**内部**的 JSON 结构。
## 0. 概述
-明文 `.sy` 文件是序列化为 JSON 的 Lute AST 树。根节点为 `NodeDocument`,正文是递归嵌套的 `Children` 数组。不存在单独维护的 JSON Schema;Lute 的 `ast.Node` 和 `ListData` Go 结构体是序列化格式的事实来源。树中保存文档 AST 及其 IAL,资源文件、属性视图定义和可重建索引则位于树外。
+明文 `.sy` 文件是序列化为 JSON 的 Lute AST 树。根节点为 `NodeDocument`,正文是递归嵌套的 `Children` 数组。不存在单独维护的 JSON Schema;因此 Lute 的 `ast.Node` 和 `ListData` Go 结构体是序列化格式的事实来源。树中保存文档 AST 及其 IAL,资源文件、属性视图定义和可重建索引则位于树外。
## 0.1 规范写入与兼容读取
@@ -22,13 +22,13 @@
| **可选** | 字段为空或带有 `omitempty` 时可以省略 |
| **兼容输入** | 读取器可按明确兼容规则接收并保留、修复或升级的历史或外部数据 |
-除非某节另有说明,本文的“必需”均指新数据的规范写入要求。`dataparser.ParseJSON` 是兼容读取器,而不是严格的 Schema 校验器;例如,它可以补入缺失的空段落、为缺少 ID 的块分配 ID,并升级旧版 `Spec`。
+除非某节另有说明,本文的“必需”均指新数据的规范写入要求。`dataparser.ParseJSON` 是兼容读取器,而不是严格的 Schema 校验器;例如,它可以填充缺失的空段落、为缺少 ID 的块分配 ID,并升级旧版 `Spec`。
---
## 0.5 何时直接读写 `.sy`(优先级)
-思源提供了 **HTTP API、MCP、CLI** 三条官方路径来修改数据。**默认应优先使用它们**,因为内核会负责 AST 序列化、块 ID 分配,以及两套索引的同步——块树索引(`blocktree.db`,块 ID 到文件路径的映射,块引用和面包屑依赖它)和全文搜索索引(`siyuan.db` + FTS5)。直接改盘绕过了这些逻辑,容易导致索引不一致。
+思源提供了 **HTTP API、MCP、CLI** 三条官方路径来修改数据。**默认应优先使用它们**,因为内核会负责 AST 序列化、块 ID 分配,以及两套索引的同步——块树索引(`blocktree.db`,块 ID 到文件路径的映射,块引用和面包屑依赖它)和全文搜索索引(`siyuan.db` + FTS5)。直接改盘绕过了这些逻辑,因此容易导致索引不一致。
**仅当官方路径不便时,才直接以 JSON 读写 `.sy`**。适用场景:
- 批量离线迁移(冷初始化工作区、外部数据导入;工作区的磁盘布局见 [`WORKSPACE.zh-CN.md`](./WORKSPACE.zh-CN.md))
@@ -92,7 +92,7 @@
| `Children` | array | 容器和结构复合节点 | 子节点数组 |
| 类型专属字段 | - | 按类型 | 如 `HeadingLevel`、`ListData`、`TextMarkType`、`AttributeViewID` |
-**核心判别规则**:`Type` 决定节点是否为块,`ast.Node.IsBlock()` 是权威判断;不能根据是否存在 `ID` 判断。规范数据中的每个块都有 `ID` 及与之匹配的 `Properties.id`,新建的内联或标记节点则没有这些字段。旧版缺陷生成的历史文件可能在 `NodeCodeBlockCode`、`NodeMathBlockContent` 等非块节点上带有 ID。兼容读取器和编辑器可在规范化过程中清理这些遗留的 `ID` / `Properties.id` 字段,但必须按 `Type` 判断节点类型,不能仅因 `ID` 不符合规范而删除节点本身。
+**核心判别规则**:`Type` 决定节点是否为块,`ast.Node.IsBlock()` 是权威判断;因此不能根据是否存在 `ID` 判断。规范数据中的每个块都有 `ID` 及与之匹配的 `Properties.id`,新建的内联或标记节点则没有这些字段。旧版缺陷生成的历史文件可能在 `NodeCodeBlockCode`、`NodeMathBlockContent` 等非块节点上带有 ID。兼容读取器和编辑器可在规范化过程中清理这些遗留的 `ID` / `Properties.id` 字段,但必须按 `Type` 判断节点类型,不能仅因 `ID` 不符合规范而删除节点本身。
---
@@ -121,7 +121,7 @@
`NodeText`、`NodeTextMark`、`NodeImage`、`NodeKramdownSpanIAL`、`NodeSoftBreak`、`NodeBr`、`NodeBackslash`、`NodeBackslashContent`、`NodeHeadingC8hMarker`、`NodeBlockquoteMarker`、`NodeTaskListItemMarker`、`NodeBang`、`NodeOpenBracket`、`NodeCloseBracket`、`NodeOpenParen`、`NodeCloseParen`、`NodeLinkText`、`NodeLinkDest`、`NodeLinkSpace`、`NodeLinkTitle`、`NodeCodeBlockCode`、`NodeCodeBlockFenceOpenMarker`、`NodeCodeBlockFenceInfoMarker`、`NodeCodeBlockFenceCloseMarker`、`NodeMathBlockContent`、`NodeMathBlockOpenMarker`、`NodeMathBlockCloseMarker`、`NodeSuperBlockOpenMarker`、`NodeSuperBlockLayoutMarker`、`NodeSuperBlockCloseMarker`、`NodeOpenBrace`、`NodeCloseBrace`、`NodeBlockQueryEmbedScript`、`NodeTableHead`、`NodeTableRow`、`NodeTableCell`
-> “叶子块”表示该节点不能包含其他**块节点**;它仍可拥有结构性内联子节点,例如代码块、数学块和表格。
+> “叶子块”表示该节点不能包含其他**块节点**;但它仍可拥有结构性内联子节点,例如代码块、数学块和表格。
> 上述“规范数据中无 ID”是规范写入规则。显式规范化过程可以清理兼容历史非块节点已有的 `ID`,但不能用该字段判断节点是否为块,也不能据此删除节点本身。
> 规范写入禁用的类型,包括解析器禁用的语法及仅用于检测的 `NodeGitConflict` 节点族,列于 §11,因此未纳入此目录。
@@ -150,7 +150,7 @@
### 5.3 列表(关键:用 `ListData.Typ` 区分类型)
-> **★ 列表的规范结构约束**:`NodeList` 的直接子节点**只能**是 `NodeListItem`,即 `CanContain` 返回 `NodeListItem == nodeType`。段落、代码块、子列表等任何其他块都**不能**直接挂在 `NodeList` 下,必须先包一层 `NodeListItem`。`dataparser.ParseJSON` 不会将其作为严格校验步骤,因此直接写入器必须自行验证结构。
+> **★ 列表的规范结构约束**:`NodeList` 的直接子节点**只能**是 `NodeListItem`,即 `CanContain` 返回 `NodeListItem == nodeType`。段落、代码块、子列表等任何其他块都**不能**直接作为 `NodeList` 的子节点,必须先包一层 `NodeListItem`。`dataparser.ParseJSON` 不会将其作为严格校验步骤,因此直接写入器必须自行验证结构。
```
✅ 正确 ❌ 错误
@@ -159,7 +159,7 @@ NodeList NodeList
└─ NodeParagraph └─ NodeCodeBlock ← 非法
```
-**嵌套列表**的正确写法是再套一层 `NodeList`(`NodeListItem` 走默认 `CanContain` 分支,不能直接含另一个 `NodeListItem`):
+**嵌套列表**的正确写法是再套一层 `NodeList`(`NodeListItem` 按默认 `CanContain` 分支处理,不能直接含另一个 `NodeListItem`):
```
✅ 正确 ❌ 错误
@@ -257,7 +257,7 @@ NodeList NodeList
{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 33 }
```
-`TaskListItemMarker` 是 Go `byte`,因此 JSON 使用数字保存其 ASCII 码点。当前渲染优先读取该字段,并在兼容旧数据时回退到 `TaskListItemChecked`。AST 直接由 Markdown 解析而来时,`Data` 可能存在,例如 `"[X]"`;编辑器生成的 `.sy` 数据通常省略它,不能将 `Data` 当作任务状态的权威来源。
+`TaskListItemMarker` 是 Go `byte`,因此 JSON 使用数字保存其 ASCII 码点。当前渲染优先读取该字段,并在兼容旧数据时回退到 `TaskListItemChecked`。AST 直接由 Markdown 解析而来时,`Data` 可能存在,例如 `"[X]"`;但编辑器生成的 `.sy` 数据通常省略它,不能将 `Data` 当作任务状态的权威来源。
### 5.6 引述块
@@ -321,7 +321,7 @@ NodeList NodeList
### 5.9.1 页签容器与页签项(Spec 3)
-`NodeTabs` 和 `NodeTabItem` 都是真实容器块,具有独立的 `ID`、`Properties.id` 和 `Properties.updated`。页签容器只容纳页签项;页签项容纳普通内容块及嵌套页签容器,每页至少有一个正文块,空正文使用空段落。独立页签项仅作为编辑片段,不能直接挂在文档下。
+`NodeTabs` 和 `NodeTabItem` 都是真实容器块,具有独立的 `ID`、`Properties.id` 和 `Properties.updated`。页签容器只容纳页签项;页签项容纳普通内容块及嵌套页签容器,每页至少有一个正文块,空正文使用空段落。独立页签项仅作为编辑片段,因此不能直接作为文档的子节点。
```json
{
@@ -342,9 +342,9 @@ NodeList NodeList
包含这两类节点的文档必须至少使用 `Spec: "3"`;使用表格单元格富文本的文档为 Spec 4,普通文档保持 Spec 2。移除功能后不降低版本。向容错解析器传递 JSON 之前,先读取根的原始 `Spec`,避免未知节点的子内容被清空;不得修复并写回不支持的版本。
-内部 Markdown 使用 `::: tabs` 开始一组页签,`@tab <行级标题>` 开始一个页签项,`@tab:active <行级标题>` 标识选中项。开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符,规范输出使用一个空格。页签项没有单独的结束标记;整组以独占一行、与开始围栏冒号数量相同的结束围栏闭合。外层围栏必须比内层长,缩进可选;规范输出根据嵌套深度计算围栏长度,不额外缩进页签正文。旧的 `:::tabs`、`:::tab` 语法不再识别,既有 `.sy` 页签节点结构保持不变。
+内部 Markdown 使用 `::: tabs` 开始一组页签,`@tab <行级标题>` 开始一个页签项,`@tab:active <行级标题>` 标识选中项。开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符,规范输出使用一个空格。页签项没有单独的结束标记;整组以独占一行、与开始围栏冒号数量相同的结束围栏闭合。外层围栏必须比内层长,缩进可选;规范输出根据嵌套深度计算围栏长度,不额外缩进页签正文。旧的 `:::tabs`、`:::tab` 语法不再识别,但既有 `.sy` 页签节点结构保持不变。
-页签项的 IAL 紧接标题标记下一行,中间不留空行,之后以空行分隔正文。整组容器的 IAL 位于结束围栏之后,正文块的 IAL 紧随对应正文块。导入时,第一个有效的 `@tab:active` 标记决定 `tabs-active-id`,优先于组 IAL 中的值;没有选中标记时保留有效的 `tabs-active-id`,缺失或失效时回退到第一页。嵌套各组独立保存选择。代码块中的标记按字面保留;正文行首的字面标记使用 `\@tab` 或 `\@tab:active` 转义。标准 Markdown 导出所有页签的标题段落及正文;HTML 可增强为交互页签,打印、PDF 和 Word 展示全部页签。完整约定参见[页签块](TAB-BLOCK.zh-CN.md)。
+页签项的 IAL 位于标题标记的下一行,中间不留空行,之后以空行分隔正文。整组容器的 IAL 位于结束围栏之后,正文块的 IAL 位于对应正文块之后。导入时,第一个有效的 `@tab:active` 标记决定 `tabs-active-id`,优先于组 IAL 中的值;没有选中标记时保留有效的 `tabs-active-id`,缺失或失效时回退到第一页。嵌套各组独立保存选择。代码块中的标记按字面保留;正文行首的字面标记使用 `\@tab` 或 `\@tab:active` 转义。标准 Markdown 导出所有页签的标题段落及正文;HTML 可增强为交互页签,打印、PDF 和 Word 展示全部页签。完整约定参见[页签块](TAB-BLOCK.zh-CN.md)。
### 5.10 代码块(四段结构,仅围栏式)
@@ -363,7 +363,7 @@ NodeList NodeList
要点:
-- `NodeCodeBlockCode` 承载代码内容(放 `Data`,原始文本,`\n` 转义),是 `NodeCodeBlock` 的内联子节点。
+- `NodeCodeBlockCode` 承载代码内容(写入 `Data`,原始文本,`\n` 转义),是 `NodeCodeBlock` 的内联子节点。
- 外围 fence marker(Open/Info/Close)同样是内联子节点。
- `CodeBlockInfo` 是**语言名的 base64**(`"Z28="` = `go`)。父节点上的六个字段(`IsFencedCodeBlock` / `CodeBlockFenceChar` / `CodeBlockFenceLen` / `CodeBlockOpenFence` / `CodeBlockInfo` / `CodeBlockCloseFence`)均带 `omitempty`,可按需省略;较新的 `.sy` 文件通常只写 `"IsFencedCodeBlock": true`。
- 当前思源 Markdown 配置禁用缩进式代码块(`SetIndentCodeBlock(false)`);规范新代码块采用围栏式结构。
@@ -389,7 +389,7 @@ NodeList NodeList
{ "Type": "NodeAudio", "ID": "...", "Data": "<audio controls src=\"assets/x.wav\"></audio>", "Properties": { "id": "...", "updated": "..." } }
```
-> 这五种节点**没有 `Children`**;HTML 内容经 JSON 转义后直接放在顶层 `Data` 中。
+> 这五种节点**没有 `Children`**;HTML 内容经 JSON 转义后直接写入顶层 `Data` 中。
### 5.13 表格
@@ -419,7 +419,7 @@ NodeList NodeList
片段内部只支持段落、标题、列表、引述、普通代码和公式。不支持嵌套表格、数据库、超级块、页签、提示块、查询嵌入、可执行图表、媒体、挂件和 HTML 块。BlockDOM 将源内容封装为 UTF-8 JSON,使用无填充的 URL 安全 Base64 编码,保存在单元格的 `data-sy-table-cell-rich` 属性中。内部 Kramdown 使用对应的 `table-cell-rich` 单元格 IAL;这两种表示都不是标准 Markdown 交换格式。
-读取器先校验源内容版本和内容,再重建投影。封装字段缺失、为 null、未知或格式错误时必须报错,不支持的输入必须保持原样。普通单元格没有此封装,不能将其中的文字重新解释为 Markdown。仅打开单元格或编辑普通行级内容时保留现有表示。首次添加块内容时创建富文本封装,并将文档 `Spec` 提升到 `4`。已有富文本封装在内容变为纯行级或空内容后仍保留,文档版本不降低。标准 Markdown 导出使用可读的内联投影;HTML、PDF 和 Word 导出仅在临时导出树中展开片段。加密笔记本在解析同一 JSON 之前,先认证现有文档加密封装;密钥派生、AAD 和恢复材料均不改变。
+读取器先校验源内容版本和内容,再重建投影。封装字段缺失、为 null、未知或格式错误时必须报错,不支持的输入必须保持原样。普通单元格没有此封装,因此不能将其中的文字重新解释为 Markdown。仅打开单元格或编辑普通行级内容时保留现有表示。首次添加块内容时创建富文本封装,并将文档 `Spec` 提升到 `4`。已有富文本封装在内容变为纯行级或空内容后仍保留,文档版本不降低。标准 Markdown 导出使用可读的内联投影;HTML、PDF 和 Word 导出仅在临时导出树中展开片段。加密笔记本在解析同一 JSON 之前,先认证现有文档加密封装;密钥派生、AAD 和恢复材料均不改变。
### 5.14 数据库块(AttributeView,叶子)
@@ -431,7 +431,7 @@ NodeList NodeList
```
- **没有 Children**。
-- `AttributeViewID` 指向 AV 表数据,该数据存放在单独的 `.json` 中;**不要**凭空构造此 ID。
+- `AttributeViewID` 指向 AV 表数据,该数据保存在单独的 `.json` 中;**不要**凭空构造此 ID。
- `AttributeViewType`:`table` / `kanban` / `gallery` 等。该值由载体绑定视图的布局派生,不是独立的视图选择器。
- 可选的 `custom-sy-av-view` 记录当前视图 ID。缺失或未指向所引用 AttributeView 中的视图时,回退到 AttributeView 的当前视图或首个可用视图。
@@ -520,7 +520,7 @@ NodeList NodeList
{ "Type": "NodeKramdownSpanIAL", "Data": "{: style=\"color: var(--b3-font-color1); background-color: var(--b3-font-background1);\"}" }
```
-> AI 生成带样式的内联文本时,这两节点必须成对出现,否则 kramdown 往返会丢样式。
+> AI 生成带样式的内联文本时,这两节点必须成对出现,否则 kramdown 往返会导致样式丢失。
### 6.4 `NodeImage`(七段核心结构;可选标题增加两个节点)
@@ -641,7 +641,7 @@ NodeList NodeList
4. ☐ 根据 `Type` 而不是 `ID` 判断块;不要为新内联或标记节点添加 ID,只能将历史非块 ID 作为字段规范化清理,不能删除节点本身
5. ☐ 修改内容或结构时,刷新被修改块、其块级祖先、适用的前置标题以及文档根节点的 `updated`
6. ☐ 列表通过 `ListData.Typ` 区分(`0` 或省略表示无序,`1` 表示有序,`3` 表示任务),`NodeList` 和每个 `NodeListItem` 都使用对应的 `Typ`
-7. ☐ `NodeList` 的直接子节点**只能**是 `NodeListItem`;嵌套列表应在列表项中再放一个 `NodeList`
+7. ☐ `NodeList` 的直接子节点**只能**是 `NodeListItem`;嵌套列表应在列表项中再创建一个 `NodeList`
8. ☐ Go `byte` 字段(`BulletChar`、`Delimiter`、`TaskListItemMarker`)是 JSON 数字;Go `[]byte` 字段(`Marker`、围栏、信息)是 base64 字符串
9. ☐ 任务标记使用 `TaskListItemMarker` 保存原始标记字节(`32` 表示空格,`88` 表示 `X`,其他非空格字节表示已勾选);`TaskListItemChecked` 是兼容回退,`Data` 不是权威状态
10. ☐ 代码块有四个结构子节点,数学块有三个,查询嵌入块有五个,超级块使用开始、布局、结束标记包裹至少一个内容块
@@ -649,7 +649,7 @@ NodeList NodeList
12. ☐ 内容字符串保持原文;只有 `[]byte` 字段使用 base64
13. ☐ 现代内联格式优先使用 `NodeTextMark`,而不是旧式 `NodeStrong` / `NodeEmphasis` / `NodeLink`
14. ☐ 带样式的 `NodeTextMark` 后紧跟配对的 `NodeKramdownSpanIAL`
-15. ☐ HTML / IFrame / Widget / Video / Audio / AttributeView / CustomBlock 节点是没有 `Children` 的叶子;内容放在 `Data` 或类型专属字段中
+15. ☐ HTML / IFrame / Widget / Video / Audio / AttributeView / CustomBlock 节点是没有 `Children` 的叶子;内容写入 `Data` 或类型专属字段中
16. ☐ 不要凭空构造 `AttributeViewID` 或块引用目标 ID;它们必须指向真实的属性视图或块
17. ☐ 不要生成 `NodeGitConflict`、脚注、ToC、YAML、LinkRef、HeadingID 等禁用类型;兼容读取历史或外部数据时应容忍它们
18. ☐ 编辑时保留已有的 U+200B 文本,但不要在内联元素周围统一合成零宽空格节点
@@ -670,10 +670,10 @@ NodeList NodeList
| 带样式 `TextMark` 不配 IAL | 必须配 `NodeKramdownSpanIAL` |
| 给 AttributeView、Widget 或 CustomBlock 节点添加 `Children` | 它们是叶子,应使用 `Data` 或类型专属字段 |
| 改 `ID` 不同步 `Properties.id` | 二者必须一致 |
-| 只更新时间戳被直接编辑的块 | 还要刷新其块级祖先、适用的前置标题以及文档根节点 |
+| 只更新被直接编辑的块的时间戳 | 还要刷新其块级祖先、适用的前置标题以及文档根节点 |
| `inline-math` 带 `TextMarkTextContent` | 它只有 `TextMarkInlineMathContent` |
| 凭空构造块引用或属性视图的目标 ID | 目标必须真实存在 |
-| 把段落直接挂到 `NodeList` 下 | `NodeList` 只能含 `NodeListItem`,必须先包一层 |
+| 把段落直接作为 `NodeList` 的子节点 | `NodeList` 只能含 `NodeListItem`,必须先包一层 |
| 在每个内联元素两侧都添加 U+200B 文本节点 | 保留已有 U+200B;由 Protyle 按上下文添加编辑器 DOM 光标占位符 |
| 生成 `NodeGitConflict`、脚注、ToC、YAML 等节点 | 它们属于规范写入禁用类型;兼容读取器仍可能遇到历史或外部节点 |
diff --git a/docs/TAB-BLOCK.md b/docs/TAB-BLOCK.md
index 8bd5d8bc8d..5500b9b208 100644
--- a/docs/TAB-BLOCK.md
+++ b/docs/TAB-BLOCK.md
@@ -12,7 +12,7 @@ A tab block groups content in a single container and switches between groups thr
### Menus and editing
-The block icon operates on the whole container. Block icon menu - Tabbed container contains the top and left layout choices, followed by a separator and Task. All three options display their selection indicators on the right. These entries and the separator are registered in the configurable menu catalog for visibility and ordering.
+The block icon operates on the whole container. Block icon menu - Tabbed container contains the top and left layout choices, then a separator and Task. All three options display their selection indicators on the right. These entries and the separator are registered in the configurable menu catalog for visibility and ordering.
A title's context menu operates on that item. It offers copying a block reference and, when editable, renaming, duplication and deletion. Task items also offer Custom task status. The header has no separate More button. Whole-container conversion is available through block icon menu - Turn into, including unordered lists, ordered lists, task lists and super blocks.
@@ -32,7 +32,7 @@ Clicking a state icon does not select the tab or start renaming: incomplete beco
List-to-tabs conversion affects only the current level. Each direct list item's first paragraph becomes its title, retaining the complete text, inline formatting, references, links, ID and attributes without duplicating it in the body. If the first block is not a paragraph, the title is empty and that block stays in the body. Nested lists and tabs are not flattened. Conversion selects the first tab.
-Converting back places a separate title paragraph first, removes `tabs-title` and appends the body. A nonempty string title creates a new paragraph. Identical title and body text is not deduplicated. A list item containing only a title receives a body placeholder on conversion to tabs. Conversion back omits only a `tabs-placeholder` paragraph that is still empty and has no inline elements, user attributes or reference count.
+Converting back places a separate title paragraph first, removes `tabs-title` and appends the body. A nonempty string title creates a new paragraph. Identical title and body text is not deduplicated. A list item containing only a title receives a body placeholder on conversion to tabs. By contrast, conversion back omits only a `tabs-placeholder` paragraph that is still empty and has no inline elements, user attributes or reference count.
Task-list conversion preserves incomplete, complete and custom states. Converting to a task list restores the current `tabs-task`; items without that attribute become incomplete. Conversion to an ordinary list removes the task attribute. Ordered lists restart at 1. Layout and selection are not retained as backups for reverse conversion.
@@ -44,7 +44,7 @@ In editable editors, explicit selection and selection triggered by search or blo
When restoring position after refresh or restart, persisted selection takes precedence over a stale caret in a hidden item. Focus moves to the selected body without reusing the stale text offset. Explicit navigation to hidden content activates each containing tab. An incoming selection that would hide content currently being edited is deferred to avoid interrupting focus and IME composition.
-Items use ordinary block-reference syntax, such as `((20260905120000-item001 'Tab title'))`, without a dedicated reference syntax. The target is the item ID, and navigation selects that item. Reference hover previews include the parent container for rendering. References and resources in string titles belong to the item; those in separate title paragraphs belong to the original paragraph ID.
+Items use ordinary block-reference syntax, such as `((20260905120000-item001 'Tab title'))`, without a dedicated reference syntax. The target is the item ID, and navigation selects that item. Reference hover previews include the parent container for rendering. References and resources in string titles belong to the item, whereas those in separate title paragraphs belong to the original paragraph ID.
Dragging a navigation title moves the entire item; dragging a body block moves content. Sorting previews move adjacent buttons out of the drop position, fade the dragged button and scroll near navigation edges, using the appropriate axis for each layout. Dropping commits one transaction; canceling or returning to the original position commits none. Cross-group moves update both groups in one transaction. Read-only targets and descendants of the dragged item reject drops.
@@ -67,9 +67,9 @@ Deleting the active item selects the next item if available, otherwise the previ
Child order determines tab order. Empty and duplicate titles are valid, and UI placeholder text is not saved as content. A separate title paragraph retains its ID, block attributes and complete inline content.
-Canonical data contains at least one item and at least one body block per item, using an empty paragraph when needed. The kernel's `NormalizeTabs` fills empty containers and bodies and repairs selection and invalid layout attributes. When the frontend deletes or moves away the last item, it converts the original container into an empty paragraph while retaining the container ID.
+Canonical data contains at least one item and at least one body block per item, using an empty paragraph when needed. The kernel's `NormalizeTabs` creates missing empty containers and bodies and repairs selection and invalid layout attributes. When the frontend deletes or moves away the last item, it converts the original container into an empty paragraph while retaining the container ID.
-Moving preserves IDs. When copying, inserting templates, importing or restoring regenerates IDs, it also remaps `tabs-active-id` and internal block references and block links in titles; external references retain their targets. A standalone item is a valid editing fragment and receives a tab container when pasted into ordinary content. Internal Markdown round trips temporarily wrap such fragments and restore their original fragment identity afterward.
+Moving preserves IDs. When copying, inserting templates, importing or restoring regenerates IDs, it also remaps `tabs-active-id` and internal block references and block links in titles, whereas external references retain their targets. A standalone item is a valid editing fragment and receives a tab container when pasted into ordinary content. Internal Markdown round trips temporarily wrap such fragments and restore their original fragment identity afterward.
### Markdown syntax
@@ -85,7 +85,7 @@ Instructions for Linux.
:::
```
-Opening fences contain at least three colons followed by spaces or tabs before `tabs`; canonical output uses one space. `@tab` or `@tab:active` starts a direct item. A nonempty inline title is separated from the marker by spaces or tabs. Items have no closing marker; the group closes with a standalone colon fence matching its opening length.
+Opening fences contain at least three colons, then spaces or tabs, before `tabs`; canonical output uses one space. `@tab` or `@tab:active` starts a direct item. A nonempty inline title is separated from the marker by spaces or tabs. Items have no closing marker, whereas the group closes with a standalone colon fence matching its opening length.
The first valid `@tab:active` in a group selects an item and takes precedence over `tabs-active-id` in the group IAL. Without that marker, a valid attribute is retained; otherwise the first item is selected. Internal Markdown emits the selected item as `@tab:active`. Nested groups are handled independently.
@@ -107,9 +107,9 @@ Outer content.
::::
```
-Markers inside code blocks remain literal. Escape literal item markers at the start of body lines as `\@tab` or `\@tab:active`. An isolated `@tab` outside a group is ordinary text. Content before the first marker becomes an item with an empty title. Incomplete input closes within the parser's scope, and canonical output supplies closing fences. Old `:::tabs` and `:::tab` forms are not tab syntax; existing `.sy` tab node structures are unaffected.
+Markers inside code blocks remain literal. Escape literal item markers at the start of body lines as `\@tab` or `\@tab:active`. An isolated `@tab` outside a group is ordinary text. Content before the first marker becomes an item with an empty title. Incomplete input closes within the parser's scope, and canonical output supplies closing fences. Old `:::tabs` and `:::tab` forms are not tab syntax; however, existing `.sy` tab node structures are unaffected.
-Item IAL goes immediately after the title marker with no intervening blank line, followed by a blank line before the body. Group IAL follows the closing fence, and body-block IAL follows its corresponding block. Task state also uses item IAL:
+Item IAL is on the line after the title marker with no intervening blank line, and a blank line separates it from the body. Group IAL is placed after the closing fence, and body-block IAL is placed after its corresponding block. Task state also uses item IAL:
```markdown
::: tabs
@@ -122,7 +122,7 @@ Body.
{: id="20260905120000-tabs001" tabs-active-id="20260905120000-item001" tabs-position="left"}
```
-Internal Markdown emits a separate title paragraph as the first paragraph, retaining `tabs-title="true"`, its ID and attributes. The `@tab` line then omits duplicate title text. Structured clipboard Markdown instead puts the complete title on the `@tab` line and omits the duplicate title paragraph.
+Internal Markdown emits a separate title paragraph as the first paragraph, retaining `tabs-title="true"`, its ID and attributes. The `@tab` line then omits duplicate title text. Structured clipboard Markdown instead writes the complete title on the `@tab` line and omits the duplicate title paragraph.
## Implementation and interfaces
@@ -130,15 +130,15 @@ Internal Markdown emits a separate title paragraph as the first paragraph, retai
`NodeTabs` renders as `.tabs` with direct `.tab-item` children. Navigation lives in `.tabs-header.protyle-action` and has no content block ID. The original title is `.tab-item-title.callout-title` inside `.tab-item-info`; the body is `.tab-item-content`, without reusing the callout body class. During editing, `.tabs-title-editor` overlays the corresponding navigation button.
-The container uses a theme border and rounded corners. Top navigation scrolls horizontally. Left navigation sizes to content, with an 80px minimum header width and a column limit of the smaller of 200px and 40% of container width. A 48px gap leaves room for body block controls. Containers narrower than 420px temporarily display top navigation without changing `tabs-position`.
+The container uses a theme border and rounded corners. Top navigation scrolls horizontally. Left navigation sizes to content, with an 80px minimum header width and a column limit of the smaller of 200px and 40% of container width. A 48px gap provides room for body block controls. Containers narrower than 420px temporarily display top navigation without changing `tabs-position`.
-Navigation provides `tablist`, `tab` and `tabpanel` semantics with independent DOM IDs for each rendering instance. Arrow keys, Home and End move navigation focus; Enter or Space activates an item. Title editing follows text-editing key handling. Hidden items continue receiving data updates, and becoming visible reprocesses size-dependent render nodes and databases.
+Navigation provides `tablist`, `tab` and `tabpanel` semantics with independent DOM IDs for each rendering instance. Arrow keys, Home and End move navigation focus; Enter or Space activates an item. Title editing uses text-editing key handling. Hidden items continue receiving data updates, whereas becoming visible reprocesses size-dependent render nodes and databases.
### Indexing and export
Titles participate in full-text indexing, reference and resource scanning, dynamic anchor text and history differences. String titles use temporary inline trees; separate title paragraphs use ordinary paragraph processing without duplicate scanning. Block names take precedence over titles as reference anchor text. Headings inside tabs do not participate in document heading numbering, and folding does not cross item boundaries.
-Internal Markdown retains full structure and attributes. Structured output with `TabsMarkdown` enabled preserves fences, complete inline titles, active markers and task-state IAL. Clipboard output omits complete block IAL such as block IDs. Flattened output with that option disabled emits every item's title and body in order. Ordinary text-selection copying removes navigation, hidden bodies and container wrappers.
+Internal Markdown retains full structure and attributes. Structured output with `TabsMarkdown` enabled preserves fences, complete inline titles, active markers and task-state IAL. Clipboard output omits complete block IAL such as block IDs. By contrast, flattened output with that option disabled emits every item's title and body in order. Ordinary text-selection copying removes navigation, hidden bodies and container wrappers.
HTML initially shows all content and hides inactive items only after interactive initialization succeeds. Printing, PDF and Word expand all items, including nested content.
@@ -155,8 +155,8 @@ HTML initially shows all content and hides inactive items only after interactive
## Compatibility and recovery
-Documents containing tab nodes use `Spec 3`; ordinary documents use `Spec 2`, and upgraded documents are not automatically downgraded. JSON readers reject unsupported future versions before parsing and repair. Import paths in old clients that bypass version checks do not have this protection and must not process new-format documents. Lute supplies the nodes and syntax, so both the generated frontend script and the kernel dependency must include that support. `kernel/go.mod` records the actual dependency version.
+Documents containing tab nodes use `Spec 3`; ordinary documents use `Spec 2`, and upgraded documents are not automatically downgraded. JSON readers reject unsupported future versions before parsing and repair. However, import paths in old clients that bypass version checks do not have this protection and must not process new-format documents. Lute supplies the nodes and syntax, so both the generated frontend script and the kernel dependency must include that support. `kernel/go.mod` records the actual dependency version.
## Verification
-Verify empty-container normalization, round trips for string titles and separate title paragraphs, selection repair, ID remapping during copying and import, and Markdown fences at different nesting depths. Editing checks cover title formatting, IME composition, task state, list and super-block conversion, undo, deletion of the last item, and moves across groups. UI checks cover top and left layouts, narrow-container fallback, keyboard navigation, temporary read-only selection, and updates to hidden items. Export checks cover structured and flattened Markdown, printing every item, title-resource scanning, and rejection of unsupported document versions.
+Verify empty-container normalization, round trips for string titles and separate title paragraphs, selection repair, ID remapping during copying and import, and Markdown fences at different nesting depths. Editing checks include title formatting, IME composition, task state, list and super-block conversion, undo, deletion of the last item, and moves across groups. UI checks include top and left layouts, narrow-container fallback, keyboard navigation, temporary read-only selection, and updates to hidden items. Export checks include structured and flattened Markdown, printing every item, title-resource scanning, and rejection of unsupported document versions.
diff --git a/docs/TAB-BLOCK.zh-CN.md b/docs/TAB-BLOCK.zh-CN.md
index 0724fbade5..bca7fc27bc 100644
--- a/docs/TAB-BLOCK.zh-CN.md
+++ b/docs/TAB-BLOCK.zh-CN.md
@@ -6,7 +6,7 @@
## 功能范围
-页签块将多个内容分组放在同一容器内,通过顶部或左侧的标题导航切换显示。每个页签项都是具有独立块 ID 的容器,可包含普通块和嵌套页签块。
+页签块将多个内容分组置于同一容器内,通过顶部或左侧的标题导航切换显示。每个页签项都是具有独立块 ID 的容器,可包含普通块和嵌套页签块。
## 用户交互
@@ -32,7 +32,7 @@
列表转页签只转换当前层级。每个直属列表项的首个段落成为标题,保留全文、行级格式、引用、链接、ID 和属性,不在正文中重复保留。首个块不是段落时使用空标题,原块保留在正文。子列表和嵌套页签不展开;转换后选中第一页。
-转回列表时将独立标题段落移回首部,移除 `tabs-title`,正文接在后面;非空字符串标题生成新段落。标题与正文即使文字相同也不去重。只有标题的列表项转页签时会补正文落点,转回时仅省略仍为空且没有行级元素、用户属性或引用计数的 `tabs-placeholder` 段落。
+转回列表时将独立标题段落移回首部,移除 `tabs-title`,正文排在其后;非空字符串标题生成新段落。标题与正文即使文字相同也不去重。只有标题的列表项转页签时会创建正文落点,而转回时仅省略仍为空且没有行级元素、用户属性或引用计数的 `tabs-placeholder` 段落。
任务列表转页签保留未完成、完成和自定义状态;转为任务列表时恢复当前 `tabs-task`,没有任务属性的项默认为未完成。转为普通列表移除任务属性。有序列表重新从 1 编号,布局和选择状态不作为反向转换的备份保存。
@@ -42,9 +42,9 @@
可写编辑器的主动切换,以及搜索和块引用定位触发的切换,通过属性接口保存 `tabs-active-id`,并排在编辑事务之后。切页不占用正文撤销栈,不更新正文修改时间,但会落盘并同步。只读页面、嵌入预览、历史预览和导出 HTML 可临时切换,不写回选择。
-刷新或重启恢复位置时,持久化的页签选择优先于隐藏页中的旧光标;焦点转到当前页正文,不复用过期文本偏移。主动定位隐藏内容时逐层激活所属页签。外部选择更新若会隐藏正在编辑的正文,延后界面切换,避免打断焦点和输入法组合。
+刷新或重启恢复位置时,持久化的页签选择优先于隐藏页中的旧光标;焦点转到当前页正文,不复用过期文本偏移。主动定位隐藏内容时逐层激活所属页签。外部选择更新若会隐藏正在编辑的正文,则延后界面切换,避免打断焦点和输入法组合。
-页签项使用普通块引用语法,例如 `((20260905120000-item001 '页签标题'))`,不引入专用引用语法。引用目标是页签项 ID,定位时切到对应页签;引用悬浮预览补齐父页签容器以正常渲染。字符串标题的引用和资源归属于页签项,独立标题段落的引用和资源归属于其原段落 ID。
+页签项使用普通块引用语法,例如 `((20260905120000-item001 '页签标题'))`,不引入专用引用语法。引用目标是页签项 ID,定位时切到对应页签;引用悬浮预览补充缺失的父页签容器以正常渲染。字符串标题的引用和资源归属于页签项,而独立标题段落的引用和资源归属于其原段落 ID。
拖动导航标题移动整页,拖动正文块移动内容。排序预览让相邻按钮让出落点,淡化被拖动按钮,并在导航边缘自动滚动;横向和纵向布局使用相应方向。松开后提交一次事务,取消或拖回原位不提交。跨组移动在同一事务中调整两组状态,只读目标和自身后代不接受落入。
@@ -63,13 +63,13 @@
| `tabs-active-id` | 保存在容器 IAL 中的选中直属页签项 ID,缺失或失效时回退到第一页 |
| `tabs-position` | 保存在容器 IAL 中的布局,取值为 `top` 或 `left`,默认 `top` |
| `tabs-task` | 保存在页签项 IAL 中的任务状态字符,缺失表示普通页签 |
-| `tabs-placeholder="true"` | 标记列表转页签时自动补出的空正文段落 |
+| `tabs-placeholder="true"` | 标记列表转页签时自动生成的空正文段落 |
页签顺序由子节点顺序决定。标题允许重复和清空,空标题的界面占位文字不写入内容。独立标题段落保留自身 ID、块属性和完整行级内容。
-规范数据至少有一个页签项,每页至少有一个正文块,空正文使用空段落。内核的 `NormalizeTabs` 补齐空容器和空正文,并修复选中项及无效布局属性。前端删除或移走最后一页时,将原页签容器转换为空段落并保留容器 ID。
+规范数据至少有一个页签项,每页至少有一个正文块,空正文使用空段落。内核的 `NormalizeTabs` 补充缺失的空容器和空正文,并修复选中项及无效布局属性。前端删除或移走最后一页时,将原页签容器转换为空段落并保留容器 ID。
-移动保留 ID。复制、模板插入、导入和恢复中重建 ID 时,同步映射 `tabs-active-id` 及标题中的内部块引用和块链接,外部引用保持原目标。独立页签项是合法编辑片段,粘贴到普通正文时补齐页签容器;片段经过内部 Markdown 转换时使用临时包装,并按片段身份恢复。
+移动保留 ID。复制、模板插入、导入和恢复中重建 ID 时,同步映射 `tabs-active-id` 及标题中的内部块引用和块链接,而外部引用保持原目标。独立页签项是合法编辑片段,粘贴到普通正文时创建页签容器;片段经过内部 Markdown 转换时使用临时包装,并按片段身份恢复。
### Markdown 语法
@@ -85,7 +85,7 @@ Linux 下的说明。
:::
```
-开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符,规范输出使用一个空格。`@tab` 或 `@tab:active` 开始一个直属页签项,有标题时以空格或制表符分隔标记和行级标题。页签项没有独立结束标记,整组以独占一行、与开始围栏等长的冒号围栏闭合。
+开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符,规范输出使用一个空格。`@tab` 或 `@tab:active` 开始一个直属页签项,有标题时以空格或制表符分隔标记和行级标题。页签项没有独立结束标记,而整组以独占一行、与开始围栏等长的冒号围栏闭合。
一组内第一个有效的 `@tab:active` 指定选中项,优先于组 IAL 中的 `tabs-active-id`。没有该标记时保留有效属性,否则回退到第一页。内部 Markdown 将选中项输出为 `@tab:active`,嵌套各组独立处理。
@@ -107,9 +107,9 @@ Linux 下的说明。
::::
```
-代码块中的标记按字面保留。正文行首的字面页签标记使用 `\@tab` 或 `\@tab:active` 转义。组外孤立的 `@tab` 是普通文字;首个标记前的正文保存在空标题页签中。不完整输入在解析范围内收束,规范输出补齐结束围栏。旧的 `:::tabs`、`:::tab` 不识别为页签语法,既有 `.sy` 页签节点结构不受影响。
+代码块中的标记按字面保留。正文行首的字面页签标记使用 `\@tab` 或 `\@tab:active` 转义。组外孤立的 `@tab` 是普通文字;首个标记前的正文保存在空标题页签中。不完整输入在解析范围内结束,规范输出补充缺失的结束围栏。旧的 `:::tabs`、`:::tab` 不识别为页签语法,不过既有 `.sy` 页签节点结构不受影响。
-页签项 IAL 紧接标题标记下一行,中间不留空行,之后以空行分隔正文。组 IAL 放在结束围栏之后,正文块 IAL 紧随相应正文块。任务状态也使用页签项 IAL:
+页签项 IAL 位于标题标记下一行,中间不留空行,之后以空行分隔正文。组 IAL 位于结束围栏之后,正文块 IAL 紧随相应正文块。任务状态也使用页签项 IAL:
```markdown
::: tabs
@@ -122,7 +122,7 @@ Linux 下的说明。
{: id="20260905120000-tabs001" tabs-active-id="20260905120000-item001" tabs-position="left"}
```
-独立标题段落在内部 Markdown 中作为首个段落输出,并保留 `tabs-title="true"`、ID 和属性;此时 `@tab` 行不重复标题文字。剪贴板的结构化 Markdown 则把完整标题放到 `@tab` 行,不再重复输出标题段落。
+独立标题段落在内部 Markdown 中作为首个段落输出,并保留 `tabs-title="true"`、ID 和属性;此时 `@tab` 行不重复标题文字。剪贴板的结构化 Markdown 则把完整标题写入 `@tab` 行,不再重复输出标题段落。
## 实现与接口
@@ -132,13 +132,13 @@ Linux 下的说明。
容器使用主题边框和圆角。顶部导航可横向滚动;左侧导航按内容分配宽度,最小宽度为 80px,列宽上限为 200px 和容器宽度的 40% 中的较小值,正文侧保留 48px 的块标操作间隔。容器宽度小于 420px 时临时显示顶部导航,不改写 `tabs-position`。
-导航提供 `tablist`、`tab`、`tabpanel` 语义,各渲染实例使用独立 DOM 标识。方向键、Home 和 End 移动导航焦点,Enter 或空格激活;标题编辑时按文本编辑规则处理。隐藏页继续接收数据更新,显示时重新处理依赖尺寸的渲染节点和数据库。
+导航提供 `tablist`、`tab`、`tabpanel` 语义,各渲染实例使用独立 DOM 标识。方向键、Home 和 End 移动导航焦点,Enter 或空格激活;标题编辑时按文本编辑规则处理。隐藏页继续接收数据更新,显示时则重新处理依赖尺寸的渲染节点和数据库。
### 索引与导出
标题参与全文索引、引用及资源扫描、动态锚文本和历史差异。字符串标题通过临时行级树处理,独立标题段落按普通段落处理,避免重复扫描。块命名优先于标题作为引用锚文本。页签内的标题块不参与文档标题编号,折叠不跨越页签项边界。
-内部 Markdown 保留完整结构和属性。启用 `TabsMarkdown` 的结构化输出保留围栏、完整行级标题、选中标记和任务状态 IAL;剪贴板不输出块 ID 等完整块 IAL。关闭该选项的平铺输出按顺序输出各页标题和正文。普通文字选区复制会移除导航、隐藏正文及页签容器包装。
+内部 Markdown 保留完整结构和属性。启用 `TabsMarkdown` 的结构化输出保留围栏、完整行级标题、选中标记和任务状态 IAL;剪贴板不输出块 ID 等完整块 IAL。关闭该选项的平铺输出则按顺序输出各页标题和正文。普通文字选区复制会移除导航、隐藏正文及页签容器包装。
HTML 在初始化前显示全部内容,交互初始化成功后才隐藏未选中的页。打印、PDF 和 Word 展开全部页签,包括嵌套内容。
@@ -155,7 +155,7 @@ HTML 在初始化前显示全部内容,交互初始化成功后才隐藏未选
## 兼容与恢复
-包含页签节点的文档使用 `Spec 3`,普通文档使用 `Spec 2`,已升级文档不自动降级。JSON 读取入口在解析和修复前拒绝不支持的未来版本。旧客户端中绕过版本检查的导入入口不具备这种保护,不能用于处理新格式文档。节点和语法由 Lute 提供,前端生成脚本与内核依赖需要包含对应能力;仓库实际依赖版本以 `kernel/go.mod` 为准。
+包含页签节点的文档使用 `Spec 3`,普通文档使用 `Spec 2`,已升级文档不自动降级。JSON 读取入口在解析和修复前拒绝不支持的未来版本。旧客户端中绕过版本检查的导入入口则不具备这种保护,不能用于处理新格式文档。节点和语法由 Lute 提供,因此前端生成脚本与内核依赖需要包含对应能力;仓库实际依赖版本以 `kernel/go.mod` 为准。
## 验证范围
diff --git a/docs/TEMPLATE-MANAGER.md b/docs/TEMPLATE-MANAGER.md
index f1f41b1f0a..5a7af2f2eb 100644
--- a/docs/TEMPLATE-MANAGER.md
+++ b/docs/TEMPLATE-MANAGER.md
@@ -14,19 +14,19 @@ Open the manager from a template entry's Template manager button in the editor's
The left pane displays a collapsible tree of directories and Markdown files under `data/templates`, with directories first. Search matches template names or full paths and expands parent directories of matches. Clearing search restores the previous expansion state. Clicking a directory selects it and toggles its children without changing the editor or preview. New templates and folders default to the selected directory, while Save and Preview still apply to the template being edited. Rename changes only the name and retains the parent directory; moving across directories uses a directory picker. Existing targets are not overwritten. Successful creation, rename, or move clears search and expands the target parent. Rename and move do not rewrite template paths referenced by other templates, notebook configuration, or documents; those references require corresponding updates.
-Template package directories containing `template.json` cannot be renamed or moved, preserving package identity and marketplace updates. Templates inside a package remain editable. Existing files retain their original names and are not rejected because of valid characters such as single quotes.
+Template package directories containing `template.json` cannot be renamed or moved, preserving package identity and marketplace updates. However, templates inside a package remain editable. Existing files retain their original names and are not rejected because of valid characters such as single quotes.
### Editing and saving
-The right pane edits source in a plain text field. Saving checks the file version recorded when reading. If sync or another window changed the file, the manager rejects the overwrite; retain current edits and refresh before resolving the conflict. Switching files, refreshing, or closing asks for confirmation before discarding unsaved changes. Templates with Windows line endings retain them when saved.
+The right pane edits source in a plain text field. Saving checks the file version recorded when reading. If sync or another window changed the file, then the manager rejects the overwrite; retain current edits and refresh before resolving the conflict. Switching files, refreshing, or closing asks for confirmation before discarding unsaved changes. Templates with Windows line endings retain them when saved.
-Deletion directly removes the selected file or directory and all its contents without writing to a separate trash folder. This cannot be undone. Templates do not participate in file history, so file history cannot restore them. Existing content under `data/templates/.trash/` is not automatically cleaned up, and that hidden directory remains absent from template search and management lists.
+Deletion directly removes the selected file or directory and all its contents without writing to a separate trash folder. This cannot be undone. Templates are not part of file history, so file history cannot restore them. Existing content under `data/templates/.trash/` is not automatically cleaned up, and that hidden directory remains absent from template search and management lists.
### Preview
Preview template runs the current editor content without saving it or inserting it into a document. The default context is the document or block used to open the manager. Preview context shows the selected name, an explanation of its purpose, and a document picker that can search for another context document. This search selects the context document, not templates in the left pane. Rendering uses the selected document's title, ID, and other information without modifying that document. Title, ID, path, and SQL results depend on the selected context and current data.
-Preview uses existing read-only rendering. It neither saves source nor commits a document-tree creation plan. The preview background follows the editor theme in light and dark modes rather than using a fixed white background. Database previews use tables and do not reproduce every interaction available after insertion.
+Preview uses existing read-only rendering. It neither saves source nor commits a document-tree creation plan. The preview background follows the editor theme in light and dark modes rather than using a fixed white background. Database previews use tables and therefore do not reproduce every interaction available after insertion.
Templates using `createDocTree` display the planned document names, hierarchy, and count in the preview, including templates with no body.
@@ -64,10 +64,10 @@ UI renaming reuses existing filename handling: ASCII slash `/` becomes full-widt
## Compatibility and recovery
-Existing templates retain their original filenames, Windows line endings, and support for document attributes declared directly at the end of the file. New standalone attribute exports use `siyuan-template-doc-attrs-v1` to preserve evaluation position. Moving and renaming do not migrate external template references; callers must update those paths.
+Existing templates retain their original filenames, Windows line endings, and support for document attributes declared directly at the end of the file. New standalone attribute exports use `siyuan-template-doc-attrs-v1` to preserve evaluation position. Moving and renaming do not migrate external template references; therefore callers must update those paths.
-File-version conflicts preserve current editor content and reject overwrites. Deletion creates no file history and cannot be undone through the manager. Existing `data/templates/.trash/` content remains and is not automatically cleaned up.
+File-version conflicts preserve current editor content and reject overwrites. Deletion creates no file history and therefore cannot be undone through the manager. Existing `data/templates/.trash/` content remains and is not automatically cleaned up.
## Verification
-Verify file-tree ordering, expansion state after search, target directories for creation and moves, valid filename access, package-directory protection, version conflicts, and unsaved-change confirmation. Preview checks cover unsaved source, context changes, read-only rendering, document-tree plans, and theme changes. Export checks cover directory fallback, memory updates only after success, database-range detection, attribute evaluation position, and old-template compatibility. Deletion checks cover path boundaries, symbolic links, revisions, and preservation of existing hidden recovery directories.
+Verify file-tree ordering, expansion state after search, target directories for creation and moves, valid filename access, package-directory protection, version conflicts, and unsaved-change confirmation. Preview checks include unsaved source, context changes, read-only rendering, document-tree plans, and theme changes. Export checks include directory fallback, memory updates only after success, database-range detection, attribute evaluation position, and old-template compatibility. Deletion checks include path boundaries, symbolic links, revisions, and preservation of existing hidden recovery directories.
diff --git a/docs/TEMPLATE-MANAGER.zh-CN.md b/docs/TEMPLATE-MANAGER.zh-CN.md
index 1d5f680a6d..640f6f91b1 100644
--- a/docs/TEMPLATE-MANAGER.zh-CN.md
+++ b/docs/TEMPLATE-MANAGER.zh-CN.md
@@ -12,21 +12,21 @@
### 文件管理
-左侧以可折叠的文件夹树列出 `data/templates` 中的目录和 Markdown 文件,目录优先排列。搜索框匹配模板名称或完整路径,搜索结果自动展开父目录,清空搜索后恢复原来的展开状态。点击目录名称选中目录并展开或收起子项,右侧编辑内容和预览保持不变;选中目录后,新建模板或文件夹默认放入该目录,保存和预览仍作用于右侧正在编辑的模板。重命名只修改名称并保留父目录,跨目录移动使用目录选择器;已有目标不会被覆盖。新建、重命名和移动成功后清空搜索并展开目标的父目录。重命名或移动不会自动改写其他模板、笔记本配置或文档中引用的模板路径,需要相应调整。
+左侧以可折叠的文件夹树列出 `data/templates` 中的目录和 Markdown 文件,目录优先排列。搜索框匹配模板名称或完整路径,搜索结果自动展开父目录,清空搜索后恢复原来的展开状态。点击目录名称选中目录并展开或收起子项,右侧编辑内容和预览保持不变;选中目录后,新建模板或文件夹默认创建在该目录,保存和预览仍作用于右侧正在编辑的模板。重命名只修改名称并保留父目录,跨目录移动使用目录选择器;已有目标不会被覆盖。新建、重命名和移动成功后清空搜索并展开目标的父目录。重命名或移动不会自动改写其他模板、笔记本配置或文档中引用的模板路径,需要相应调整。
-包含 `template.json` 的模板包目录不支持重命名或移动,以保留包身份和集市更新能力;包内模板仍可编辑。访问已有文件时保留原始文件名,不因单引号等合法字符而拒绝访问。
+包含 `template.json` 的模板包目录不支持重命名或移动,以保留包身份和集市更新能力;不过包内模板仍可编辑。访问已有文件时保留原始文件名,不因单引号等合法字符而拒绝访问。
### 编辑与保存
-右侧使用纯文本框编辑源码。保存前会核对读取时的文件版本;如果同步或另一个窗口已经修改了文件,会拒绝覆盖,需要保留当前编辑内容并刷新后处理。切换文件、刷新或关闭窗口时,有未保存的修改会要求确认放弃。已有 Windows 换行的模板保存时继续使用 Windows 换行。
+右侧使用纯文本框编辑源码。保存前会核对读取时的文件版本;如果同步或另一个窗口已经修改了文件,则会拒绝覆盖,需要保留当前编辑内容并刷新后处理。切换文件、刷新或关闭窗口时,有未保存的修改会要求确认放弃。已有 Windows 换行的模板保存时继续使用 Windows 换行。
-删除会直接移除选中的文件或整个目录及其内容,不再写入独立垃圾箱,此操作无法撤销。模板没有接入文件历史,不能依赖文件历史恢复。旧版本已经保留在 `data/templates/.trash/` 中的内容不会自动清理,该隐藏目录仍不出现在模板搜索和管理列表中。
+删除会直接移除选中的文件或整个目录及其内容,不再写入独立垃圾箱,此操作无法撤销。模板未纳入文件历史,因此不能依赖文件历史恢复。旧版本已经保留在 `data/templates/.trash/` 中的内容不会自动清理,该隐藏目录仍不出现在模板搜索和管理列表中。
### 预览
点击「预览模板」执行当前文本框中的内容,无须先保存或插入文档。默认使用打开窗口时的文档或块作为上下文;「预览上下文」直接显示当前选择的名称、用途说明和文档选择控件,可以搜索并选择其他文档。此处搜索的是上下文文档,不是左侧模板列表。预览使用所选文档的标题、ID 等信息运行模板,不会修改该文档;标题、ID、路径和 SQL 查询等结果取决于所选上下文及当前数据。
-预览使用现有只读渲染模式,不保存当前源码,也不提交文档树创建计划。预览区域使用编辑器的主题背景色,随明暗主题切换,不固定为白色。数据库预览仍使用表格展示,不能等同于实际插入后的全部交互效果。
+预览使用现有只读渲染模式,不保存当前源码,也不提交文档树创建计划。预览区域使用编辑器的主题背景色,随明暗主题切换,不固定为白色。数据库预览仍使用表格展示,因此不能等同于实际插入后的全部交互效果。
使用 `createDocTree` 的模板会在预览区显示将创建的文档名称、层级和数量,即使模板没有正文,也能查看创建计划。
@@ -46,7 +46,7 @@
```
````
-这种代码块的属性仍在原来的模板位置求值,完成渲染后再合并到文档根节点,因此可以引用跨代码块的条件分支、循环和模板定义中的局部变量。实际执行的显式声明优先,未执行的分支不会覆盖源文档属性;文档 ID 仍由导出流程维护,更新时间不导出。包含其他正文、条件语句或嵌套在容器中的属性代码块继续按普通模板内容导出,不进行属性提取。
+这种代码块的属性仍在原来的模板位置求值,完成渲染后再合并到文档根节点,因此可以引用跨代码块的条件分支、循环和模板定义中的局部变量。实际执行的显式声明优先,未执行的分支不会覆盖源文档属性;文档 ID 仍由导出流程维护,更新时间不导出。包含其他正文、条件语句或嵌套在容器中的属性代码块继续按普通模板内容导出,不提取属性。
新导出的独立属性声明使用语言标记为 `siyuan-template-doc-attrs-v1` 的代码块保存原始求值位置;渲染器在解析模板结果时合并属性并移除该代码块。已有直接在文件末尾声明文档属性的模板继续受支持,无须转换文件。
@@ -64,9 +64,9 @@
## 兼容与恢复
-已有模板继续按原文件名读取,保留 Windows 换行及直接在文件末尾声明文档属性的旧写法。新导出的独立属性声明使用 `siyuan-template-doc-attrs-v1` 保存求值位置。移动和重命名不自动迁移外部模板引用,调用方需要同步调整引用路径。
+已有模板继续按原文件名读取,保留 Windows 换行及直接在文件末尾声明文档属性的旧写法。新导出的独立属性声明使用 `siyuan-template-doc-attrs-v1` 保存求值位置。移动和重命名不自动迁移外部模板引用,因此调用方需要同步调整引用路径。
-文件版本冲突时保留当前编辑内容并拒绝覆盖。删除操作不生成文件历史,无法通过模板管理撤销;已有 `data/templates/.trash/` 内容继续保留且不自动清理。
+文件版本冲突时保留当前编辑内容并拒绝覆盖。删除操作不生成文件历史,因此无法通过模板管理撤销;已有 `data/templates/.trash/` 内容继续保留且不自动清理。
## 验证范围
diff --git a/docs/WORKSPACE.md b/docs/WORKSPACE.md
index f6027a96bb..6ce69c82d9 100644
--- a/docs/WORKSPACE.md
+++ b/docs/WORKSPACE.md
@@ -3,12 +3,12 @@
[中文](WORKSPACE.zh-CN.md)
> This document describes how a SiYuan workspace is organized on disk.
-> It complements [`SY-FORMAT.md`](./SY-FORMAT.md): the latter covers the **internal** JSON structure of a `.sy` file, while this one covers the **overall** file-system layout of the workspace.
+> It complements [`SY-FORMAT.md`](./SY-FORMAT.md): the latter describes the **internal** JSON structure of a `.sy` file, while this one describes the **overall** file-system layout of the workspace.
> All conclusions are verified against a real workspace and the kernel source.
## 0. Overview
-A SiYuan workspace is a **self-describing** directory tree: notebooks, documents, and assets live on disk as files and directories. **The filename is the ID; the directory structure is the document hierarchy.** The file system contains the authoritative source content, while SQLite databases under `temp/` are rebuildable indexes and caches. Normal-notebook content is readable directly; encrypted-notebook content is ciphertext and must be accessed through the unlocked kernel.
+A SiYuan workspace is a **self-describing** directory tree: notebooks, documents, and assets live on disk as files and directories. **The filename is the ID; the directory structure is the document hierarchy.** The file system contains the authoritative source content, while SQLite databases under `temp/` are rebuildable indexes and caches. Normal-notebook content is readable directly, whereas encrypted-notebook content is ciphertext and must be accessed through the unlocked kernel.
---
@@ -98,7 +98,7 @@ That is, the physical path segments `assets` / `templates` / `widgets` / `emojis
### Persistent data vs rebuildable indexes
-`data/storage/` contains persistent structured data such as attribute-view definitions and plugin state. The SQLite files in `temp/` are derived indexes and caches: normal notebooks use the global `siyuan.db` and `blocktree.db`, while each unlocked encrypted notebook uses independent SQLCipher databases. Deleting or rebuilding an index must not be confused with deleting the source `.sy`, asset, or database-definition files.
+`data/storage/` contains persistent structured data such as attribute-view definitions and plugin state. The SQLite files in `temp/` are derived indexes and caches: normal notebooks use the global `siyuan.db` and `blocktree.db`, while each unlocked encrypted notebook uses independent SQLCipher databases. Therefore, deleting or rebuilding an index must not be confused with deleting the source `.sy`, asset, or database-definition files.
### How a notebook is recognized
@@ -107,7 +107,7 @@ That is, the physical path segments `assets` / `templates` / `widgets` / `emojis
1. Skip reserved names;
2. Must be a directory (not a file);
3. The directory name must match the NodeID format (`ast.IsNodeIDPattern`);
-4. If all the above hold → that directory name is the `box.ID` (notebook ID).
+4. If all the above are met → that directory name is the `box.ID` (notebook ID).
---
@@ -132,13 +132,13 @@ Code evidence:
- Expanding children (`Ls`): given a `.sy` path, strip the `.sy` suffix, check whether the same-named directory exists, and list its entries if so.
- Child depth (`GetChildDocDepth`): walks the same-named directory accordingly.
-> ⚠️ This means: **moving or renaming a document that has children must also move its same-named directory**, otherwise the children get orphaned.
+> ⚠️ This means: **moving or renaming a document that has children must also move its same-named directory**, otherwise the child documents can no longer be located.
### Top-level notebook document exception
When the top-level notebook document feature is enabled, the kernel creates `<boxID>.sy` directly inside the notebook directory. Its document rootID is exactly the notebook ID, so the notebook and its top-level document share one ID.
-The switch is stored at `fileTree.boxDocEnabled` in `conf/conf.json`. It defaults to enabled for new workspaces; an existing configuration that does not contain the field is initialized as disabled.
+The switch is stored at `fileTree.boxDocEnabled` in `conf/conf.json`. It defaults to enabled for new workspaces; if an existing configuration does not contain the field, it is initialized as disabled.
The top-level notebook document is a virtual parent for every ordinary document stored directly under `<boxID>/`. Unlike an ordinary parent document, its children remain in the notebook directory and are **not** moved into a `<boxID>/<boxID>/` directory. For example:
@@ -190,7 +190,7 @@ An encrypted notebook still stores its name, closed state, and key-recovery enve
Read/write sites: `GetConf` / `SaveConf`. The path is hard-coded as `<DataDir>/<boxID>/.siyuan/conf.json`.
-`boxDoc.json` contains a metadata spec version and the top-level document ID. At runtime the kernel derives that document ID directly from `box.ID`; the metadata file is retained so `.sy.zip` import can identify the source notebook's top-level document and remap it to the destination notebook ID.
+`boxDoc.json` contains a metadata spec version and the top-level document ID. At runtime the kernel derives that document ID directly from `box.ID`, whereas the metadata file is retained so `.sy.zip` import can identify the source notebook's top-level document and remap it to the destination notebook ID.
Encrypted notebooks retain recovery metadata in `conf.json` and `notebook-crypto-backup.json`, but their `.sy`, notebook-local assets, and attribute-view definitions are ciphertext. See [ENCRYPTED-NOTEBOOK.md](./ENCRYPTED-NOTEBOOK.md) for the encryption boundary, database isolation, and recovery design.
@@ -205,13 +205,13 @@ Be careful to distinguish the two `conf.json` files:
| `conf/conf.json` | **Workspace root** | Workspace-level global config (appearance / langs / system / editor / sync / repo, etc.) |
| `<boxID>/.siyuan/conf.json` | **Inside a notebook** | That notebook only (BoxConf) |
-`conf/conf.json` holds UI appearance, account, sync, AI, flashcard, and other workspace-level settings.
+`conf/conf.json` contains UI appearance, account, sync, AI, flashcard, and other workspace-level settings.
---
## 7. Workspace-level hidden config: `data/.siyuan/`
-`data/.siyuan/` is different from the per-notebook `.siyuan/` — the former holds **workspace-level** rules and state:
+`data/.siyuan/` is different from the per-notebook `.siyuan/` — the former contains **workspace-level** rules and state:
| File | Purpose |
|---|---|
@@ -235,7 +235,7 @@ Most entries are optional and are created only when the corresponding feature is
Two coexisting locations:
-1. **Global `data/assets/`** — the main one. Naming convention looks like `<original-base>-<NodeID>.<ext>` (e.g. `640-20240927104411-0jh7x96.webp`). Referenced inside documents as the relative path `assets/xxx`.
+1. **Global `data/assets/`** — the main one. The naming convention has the form `<original-base>-<NodeID>.<ext>` (e.g. `640-20240927104411-0jh7x96.webp`). Referenced inside documents as the relative path `assets/xxx`.
2. **Per-notebook `<notebook>/assets/`** — used by the built-in guide and required for encrypted notebooks; ordinary unencrypted user notebooks generally don't have one.
Asset-link prefix recognition: only `assets/`, `emojis/`, `plugins/`, `public/`, and `widgets/` are accepted as legal asset-link prefixes.
@@ -264,7 +264,7 @@ These are physical identifiers. A notebook's display name comes from `BoxConf.na
### Document absolute path
-A document's absolute path on disk = `data/<boxID>/<relative-path>`, where `<relative-path>` looks like `/20221126104620-m06prws/20230928134805-z11t56h.sy` (POSIX style, leading `/`).
+A document's absolute path on disk = `data/<boxID>/<relative-path>`, where `<relative-path>` has the form `/20221126104620-m06prws/20230928134805-z11t56h.sy` (POSIX style, leading `/`).
Extracting the doc ID from a path (`GetTreeID`): simply `filepath.Base(path)` with the `.sy` suffix removed.
@@ -274,9 +274,9 @@ Extracting the doc ID from a path (`GetTreeID`): simply `filepath.Base(path)` wi
HPath is **not authoritative data stored in the `.sy` source file** — it is derived when loading a document (`LoadTreeByData`) and may be cached in rebuildable indexes such as `blocktree.db`:
-1. Split the document's own relative path by `/`, drop the leading empty segment and the trailing self segment, yielding the **ID segments of each ancestor document**.
+1. Split the document's own relative path by `/`, remove the leading empty segment and the trailing self segment, yielding the **ID segments of each ancestor document**.
2. For each ancestor ID, build `<ancestorID>.sy` and read its `title` via `DocIAL()` (a **streaming read of `Properties` only**, without parsing the whole tree). Encrypted `.sy` files must first be read and decrypted in full before the properties can be parsed.
-3. Join the titles with `/` and append the current document's title → an HPath like `/Parent/Child/Current`.
+3. Concatenate the titles with `/` and concatenate the current document's title → an HPath like `/Parent/Child/Current`.
4. If some ancestor `.sy` is missing, the kernel **auto-creates** an `Untitled` parent (issue #7376).
> This is the fundamental reason "directory structure is data": **moving or renaming a file/directory directly changes the document's HPath and breadcrumbs** — because HPath is entirely derived from the directory chain.
@@ -307,7 +307,7 @@ When writing files directly:
| Document | Layer | Question answered |
|---|---|---|
-| **This one (WORKSPACE)** | File-system layer | "What does a workspace look like on disk? How are notebooks/documents/assets organized?" |
-| **SY-FORMAT** | AST layer | "What does the JSON tree inside a `.sy` file look like? What node types/fields exist?" |
+| **This one (WORKSPACE)** | File-system layer | "How is a workspace organized on disk? How are notebooks/documents/assets organized?" |
+| **SY-FORMAT** | AST layer | "What is the structure of the JSON tree inside a `.sy` file? What node types/fields exist?" |
-The two are complementary: this document tells you where a `.sy` file **lives, what it's named, and who shares its directory**; SY-FORMAT tells you **what's inside** it.
+The two are complementary: this document describes where a `.sy` file **lives, what it's named, and who shares its directory**; SY-FORMAT describes **what's inside** it.
diff --git a/docs/WORKSPACE.zh-CN.md b/docs/WORKSPACE.zh-CN.md
index 8935130d35..3fba851e28 100644
--- a/docs/WORKSPACE.zh-CN.md
+++ b/docs/WORKSPACE.zh-CN.md
@@ -3,12 +3,12 @@
[English](WORKSPACE.md)
> 本文档描述 SiYuan 工作区在磁盘上的目录与文件组织。
-> 它与 [`SY-FORMAT.zh-CN.md`](./SY-FORMAT.zh-CN.md) 互补:后者讲 `.sy` 文件**内部**的 JSON 结构,本文档讲工作区**整体**在文件系统中的布局。
+> 它与 [`SY-FORMAT.zh-CN.md`](./SY-FORMAT.zh-CN.md) 互补:后者说明 `.sy` 文件**内部**的 JSON 结构,而本文档说明工作区**整体**在文件系统中的布局。
> 所有结论基于真实工作区与内核代码核验。
## 0. 概述
-SiYuan 工作区是一棵**自描述**的目录树:笔记本、文档和资源文件以文件或目录形式存在磁盘上。**文件名即 ID,目录结构即文档层级**。文件系统保存权威的原始内容,`temp/` 下的 SQLite 数据库则是可重建的索引和缓存。普通笔记本内容可以直接读取;加密笔记本内容以密文落盘,必须通过已解锁的内核访问。
+SiYuan 工作区是一棵**自描述**的目录树:笔记本、文档和资源文件以文件或目录形式存在磁盘上。**文件名即 ID,目录结构即文档层级**。文件系统保存权威的原始内容,`temp/` 下的 SQLite 数据库则是可重建的索引和缓存。普通笔记本内容可以直接读取;而加密笔记本内容以密文落盘,必须通过已解锁的内核访问。
---
@@ -98,7 +98,7 @@ func IsReservedFilename(baseName string) bool {
### 持久化数据与可重建索引
-`data/storage/` 保存属性视图定义和插件状态等持久化结构化数据。`temp/` 中的 SQLite 文件是派生索引和缓存:普通笔记本使用全局 `siyuan.db` 和 `blocktree.db`,每个已解锁的加密笔记本则使用独立的 SQLCipher 数据库。删除或重建索引不能与删除源 `.sy`、资源文件或数据库定义文件混为一谈。
+`data/storage/` 保存属性视图定义和插件状态等持久化结构化数据。`temp/` 中的 SQLite 文件是派生索引和缓存:普通笔记本使用全局 `siyuan.db` 和 `blocktree.db`,每个已解锁的加密笔记本则使用独立的 SQLCipher 数据库。因此删除或重建索引不能与删除源 `.sy`、资源文件或数据库定义文件混为一谈。
### 笔记本的判定规则
@@ -129,16 +129,16 @@ func IsReservedFilename(baseName string) bool {
代码佐证:
-- 展开子文档(`Ls`):传入 `.sy` 路径,去掉 `.sy` 后缀,检查同名目录是否存在,存在则列出其子项。
+- 展开子文档(`Ls`):传入 `.sy` 路径,去掉 `.sy` 后缀,检查同名目录是否存在,若存在则列出其子项。
- 子文档深度(`GetChildDocDepth`):同理 walk 同名目录。
-> ⚠️ 这意味着:**移动或改名一个有子文档的文档,必须同步移动它的同名目录**,否则子文档会失联。
+> ⚠️ 这意味着:**移动或改名一个有子文档的文档,必须同步移动它的同名目录**,否则子文档将无法被定位。
### 顶层笔记本文档例外
启用顶层笔记本文档功能后,内核会在笔记本目录中直接创建 `<boxID>.sy`。该文档的 rootID 就是笔记本 ID,因此笔记本与其顶层文档共用同一个 ID。
-开关保存在 `conf/conf.json` 的 `fileTree.boxDocEnabled` 中。新工作区默认启用;已有配置中缺少该字段时初始化为关闭。
+开关保存在 `conf/conf.json` 的 `fileTree.boxDocEnabled` 中。新工作区默认启用;若已有配置中缺少该字段,则初始化为关闭。
顶层笔记本文档是笔记本根层所有普通文档的虚拟父文档。与普通父文档不同,它的子文档仍然位于笔记本目录中,**不会**移动到 `<boxID>/<boxID>/` 目录。例如:
@@ -190,7 +190,7 @@ data/<boxID>/
读写位置:`GetConf` / `SaveConf`。路径硬编码为 `<DataDir>/<boxID>/.siyuan/conf.json`。
-`boxDoc.json` 包含元数据规范版本和顶层文档 ID。运行时内核直接从 `box.ID` 推导该文档 ID;保留此元数据文件是为了让 `.sy.zip` 导入过程能够识别源笔记本的顶层文档,并将其重新映射为目标笔记本 ID。
+`boxDoc.json` 包含元数据规范版本和顶层文档 ID。运行时内核直接从 `box.ID` 推导该文档 ID;而保留此元数据文件是为了让 `.sy.zip` 导入过程能够识别源笔记本的顶层文档,并将其重新映射为目标笔记本 ID。
加密笔记本在 `conf.json` 和 `notebook-crypto-backup.json` 中保留恢复元数据,但其 `.sy`、笔记本本地资源文件和属性视图定义均以密文落盘。加密边界、数据库隔离和恢复设计详见 [ENCRYPTED-NOTEBOOK.zh-CN.md](./ENCRYPTED-NOTEBOOK.zh-CN.md)。
@@ -276,18 +276,18 @@ HPath **不是存储在 `.sy` 原始文件中的权威数据**,而是在加载
1. 文档自身的相对路径按 `/` 拆分,去掉开头空段和结尾自身段,得到**各级父文档的 ID 段**。
2. 对每个父 ID,拼出 `<父ID>.sy`,用 `DocIAL()`(**流式只读 `Properties`**,不解析整棵树)读出该父文档的 `title`。加密 `.sy` 文件必须先完整读取并解密,然后才能解析属性。
-3. 把各级 title 用 `/` 串起来,末尾接当前文档 title → 得到形如 `/父标题/子标题/当前标题` 的 HPath。
-4. 若某父 `.sy` 缺失,内核会**自动补建**一个 `Untitled` 父文档(对应 issue #7376)。
+3. 把各级 title 用 `/` 连接,末尾拼接当前文档 title → 得到形如 `/父标题/子标题/当前标题` 的 HPath。
+4. 若某父 `.sy` 缺失,内核会**自动创建**一个 `Untitled` 父文档(对应 issue #7376)。
> 这是「目录结构即数据」的根本原因:**移动或重命名文件/目录,会直接改变文档的 HPath 与面包屑**——因为 HPath 完全派生自目录链。
-顶层笔记本文档会进行特殊处理:其 API HPath 为 `/`,完整的人类可读路径为笔记本名称;根层普通文档在逻辑上显示为它的下级文档,但文件仍然直接存放在笔记本目录中。
+顶层笔记本文档会特殊处理:其 API HPath 为 `/`,完整的人类可读路径为笔记本名称;根层普通文档在逻辑上显示为它的下级文档,但文件仍然直接存放在笔记本目录中。
---
## 11. 直接操作文件系统的注意事项
-> 与 [SY-FORMAT.zh-CN.md §0.5](./SY-FORMAT.zh-CN.md#05-何时直接读写-sy优先级) 一致:**修改数据优先走 HTTP API / MCP / CLI**,由内核负责索引同步。直接操作文件系统仅用于批量离线迁移、冷初始化等场景。
+> 与 [SY-FORMAT.zh-CN.md §0.5](./SY-FORMAT.zh-CN.md#05-何时直接读写-sy优先级) 一致:**修改数据优先通过 HTTP API / MCP / CLI**,由内核负责索引同步。直接操作文件系统仅用于批量离线迁移、冷初始化等场景。
不要直接修改加密笔记本的持久化文件。原始文件 API 会拒绝读取、枚举或修改加密笔记本目录。离线检查受保护内容时只能看到密文,但 `conf.json` 等非内容元数据仍可读取。应在解锁笔记本后使用专用 API,以保持加密、认证和隔离索引的一致性。
@@ -307,7 +307,7 @@ HPath **不是存储在 `.sy` 原始文件中的权威数据**,而是在加载
| 文档 | 范畴 | 回答的问题 |
|---|---|---|
-| **本文档(WORKSPACE)** | 文件系统层 | 「一个工作区在磁盘上长什么样?笔记本、文档和资源文件怎么组织?」 |
-| **SY-FORMAT** | AST 层 | 「一个 `.sy` 文件内部的 JSON 树长什么样?有哪些节点类型和字段?」 |
+| **本文档(WORKSPACE)** | 文件系统层 | 「一个工作区在磁盘上如何组织?笔记本、文档和资源文件如何布局?」 |
+| **SY-FORMAT** | AST 层 | 「一个 `.sy` 文件内部的 JSON 树是什么结构?有哪些节点类型和字段?」 |
-两者互补:本文档告诉你 `.sy` 文件**放在哪、叫什么名、与谁同目录**;SY-FORMAT 告诉你 `.sy` 文件**里面写什么**。
+两者互补:本文档说明 `.sy` 文件**放在哪、叫什么名、与谁同目录**;SY-FORMAT 说明 `.sy` 文件**里面写什么**。