An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:memo: Clarify and test daily note reuse across entry points https://github.com/siyuan-note/siyuan/issues/19938
Daniel9345883e4e2f
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20210110181011-fbhoesf.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20210110181011-fbhoesf.syindex 9c12d618da..310088b0e6 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20210110181011-fbhoesf.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20210110181011-fbhoesf.sy@@ -6,7 +6,7 @@"id": "20210110181011-fbhoesf","title": "Daily notes","type": "doc",- "updated": "20261024164212"+ "updated": "20261027135536"},"Children": [{@@ -15,7 +15,7 @@"HeadingLevel": 2,"Properties": {"id": "20260613180619-15jwt8e",- "updated": "20261024164212"+ "updated": "20261027135536"},"Children": [{@@ -44,7 +44,7 @@"HeadingLevel": 3,"Properties": {"id": "20260613180619-njydei7",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -59,7 +59,7 @@"ListData": {},"Properties": {"id": "20260613180619-y24gzqt",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -173,7 +173,7 @@},"Properties": {"id": "20260613180619-4cz2avf",- "updated": "20260613180619"+ "updated": "20261027135536"},"Children": [{@@ -181,17 +181,17 @@"Type": "NodeParagraph","Properties": {"id": "20260613180619-byb9lcr",- "updated": "20260613180619"+ "updated": "20261027135536"},"Children": [{"Type": "NodeTextMark","TextMarkType": "strong",- "TextMarkTextContent": "First Open"+ "TextMarkTextContent": "Opening behavior"},{"Type": "NodeText",- "Data": ": When opening the diary for today, if a document for that date does not yet exist, the system creates one based on the configured save path and template; if it already exists, it opens directly"+ "Data": ": The button and shortcut open the document at the name and location resolved from today's save path template, or create it if missing. They do not search by the daily note date attribute, so renaming or moving the original can cause another daily note to be created"}]}@@ -205,7 +205,7 @@"HeadingLevel": 3,"Properties": {"id": "20261008101708-b7c9jyj",- "updated": "20261024164212"+ "updated": "20261027135536"},"Children": [{@@ -343,12 +343,12 @@"Type": "NodeParagraph","Properties": {"id": "20261024164212-ma3a2a1",- "updated": "20261024164212"+ "updated": "20261027135536"},"Children": [{"Type": "NodeText",- "Data": "Selecting a candidate reuses the daily note for that date in the target notebook, including moved or renamed documents that retain their daily note date attribute."+ "Data": "Selecting a candidate first searches the target notebook by the daily note date attribute, including moved or renamed documents that retain it. If several match, the document at the template name and location is preferred; otherwise, the one with the smallest ID is used. If the ordinary button creates another daily note at that location, date candidates will prefer it. Neither entry point reapplies the content template when reusing a document."}]},@@ -357,12 +357,12 @@"Type": "NodeParagraph","Properties": {"id": "20261024161816-m4mro3d",- "updated": "20261024161816"+ "updated": "20261027135536"},"Children": [{"Type": "NodeText",- "Data": "If none exists, the daily note settings are used to create it and insert a reference. The path template, now in the content template, and the daily note date attribute use the target date; actual creation and update timestamps retain the real operation time."+ "Data": "If no date attribute matches, the document at the template name and location is reused or created, and a reference is inserted. The path template, now in the content template, and the daily note date attribute use the target date; actual creation and update timestamps retain the real operation time."}]},diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20210110175347-2xrwoiq.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20210110175347-2xrwoiq.syindex f07501c700..8ec65b74ca 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20210110175347-2xrwoiq.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20210110175347-2xrwoiq.sy@@ -6,7 +6,7 @@"id": "20210110175347-2xrwoiq","title": "日记","type": "doc",- "updated": "20261016202635"+ "updated": "20261027135536"},"Children": [{@@ -15,7 +15,7 @@"HeadingLevel": 2,"Properties": {"id": "20260613180438-q02mnqc",- "updated": "20261016202635"+ "updated": "20261027135536"},"Children": [{@@ -44,7 +44,7 @@"HeadingLevel": 3,"Properties": {"id": "20260613180438-ficw3e7",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -59,7 +59,7 @@"ListData": {},"Properties": {"id": "20260613180438-lbirm0p",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -173,7 +173,7 @@},"Properties": {"id": "20260613180438-z1k8myy",- "updated": "20260613180438"+ "updated": "20261027135536"},"Children": [{@@ -181,17 +181,17 @@"Type": "NodeParagraph","Properties": {"id": "20260613180438-8dp3b89",- "updated": "20260613180438"+ "updated": "20261027135536"},"Children": [{"Type": "NodeTextMark","TextMarkType": "strong",- "TextMarkTextContent": "首次打开"+ "TextMarkTextContent": "打开规则"},{"Type": "NodeText",- "Data": ":打开当天日记时,若对应日期的文档尚不存在,系统会根据配置的存放路径和模板生成;已存在则直接打开"+ "Data": ":按钮和快捷键按当天的存放路径模板确定文档名称和位置,存在则打开,不存在则创建;不会按日记日期属性查找,因此原日记改名或移动后可能另建一篇"}]}@@ -205,7 +205,7 @@"HeadingLevel": 3,"Properties": {"id": "20261008101708-5rm6q63",- "updated": "20261008172530"+ "updated": "20261027135536"},"Children": [{@@ -324,12 +324,12 @@"Type": "NodeParagraph","Properties": {"id": "20261008101708-m616klc",- "updated": "20261008172530"+ "updated": "20261027135536"},"Children": [{"Type": "NodeText",- "Data": "输入和查看候选不会创建文档。尚未创建的日记显示“新建日记”和日历加号图标。创建请求发出后移动光标,引用仍插入原输入位置;原内容被修改或删除时不覆盖新的内容。选中后会复用目标笔记本中对应日期的日记,包括已移动或重命名但保留日记日期属性的文档;不存在时才按日记设置创建并插入引用。路径模板、正文模板中的 now 和日记日期属性使用目标日期,实际创建和更新时间保持真实操作时间。"+ "Data": "输入和查看候选不会创建文档。尚未创建的日记显示“新建日记”和日历加号图标。创建请求发出后移动光标,引用仍插入原输入位置;原内容被修改或删除时不覆盖新的内容。选中后优先按日记日期属性查找目标笔记本中的日记,包括已移动或重命名但保留该属性的文档。多篇匹配时优先选择模板名称和位置对应的文档,否则按 ID 升序选择。若普通按钮另建了模板位置的日记,日期候选会改为优先选择它。没有日期属性匹配时,再复用或创建模板位置的文档并插入引用。两个入口复用已有文档时均不会重新应用正文模板。路径模板、正文模板中的 now 和日记日期属性使用目标日期,实际创建和更新时间保持真实操作时间。"}]},diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123154-fd5e001.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123154-fd5e001.syindex d7c1dc9382..3e43a8b430 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123154-fd5e001.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123154-fd5e001.sy@@ -6,7 +6,7 @@"id": "20211226123154-fd5e001","title": "日記","type": "doc",- "updated": "20261016202635"+ "updated": "20261027135536"},"Children": [{@@ -15,7 +15,7 @@"HeadingLevel": 2,"Properties": {"id": "20260613181022-74zgp84",- "updated": "20261016202635"+ "updated": "20261027135536"},"Children": [{@@ -44,7 +44,7 @@"HeadingLevel": 3,"Properties": {"id": "20260613181022-p6wso87",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -59,7 +59,7 @@"ListData": {},"Properties": {"id": "20260613181022-o9qpabe",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -173,7 +173,7 @@},"Properties": {"id": "20260613181022-8q0ayvo",- "updated": "20260613181022"+ "updated": "20261027135536"},"Children": [{@@ -181,17 +181,17 @@"Type": "NodeParagraph","Properties": {"id": "20260613181022-2uvw34h",- "updated": "20260613181022"+ "updated": "20261027135536"},"Children": [{"Type": "NodeTextMark","TextMarkType": "strong",- "TextMarkTextContent": "首次打開"+ "TextMarkTextContent": "打開規則"},{"Type": "NodeText",- "Data": ":打開當天日記時,若對應日期的文件尚不存在,系統會根據設定的存放路徑和範本生成;已存在則直接打開"+ "Data": ":按鈕和快捷鍵依當天的存放路徑範本決定文件名稱和位置,存在則打開,不存在則建立;不會依日記日期屬性查找,因此原日記重新命名或移動後可能另建一篇"}]}@@ -205,7 +205,7 @@"HeadingLevel": 3,"Properties": {"id": "20261008101708-lr0o7zn",- "updated": "20261008172530"+ "updated": "20261027135536"},"Children": [{@@ -324,12 +324,12 @@"Type": "NodeParagraph","Properties": {"id": "20261008101708-j20nycr",- "updated": "20261008172530"+ "updated": "20261027135536"},"Children": [{"Type": "NodeText",- "Data": "輸入和查看候選不會建立文件。尚未建立的日記顯示「新建日記」和日曆加號圖示。建立請求送出後移動游標,區塊引用仍插入原輸入位置;原內容被修改或刪除時不覆蓋新的內容。選取後會沿用目標筆記本中對應日期的日記,包括已移動或重新命名但保留日記日期屬性的文件;不存在時才依日記設定建立並插入區塊引用。路徑範本、內容範本中的 now 和日記日期屬性使用目標日期,實際建立和更新時間保持真實操作時間。"+ "Data": "輸入和查看候選不會建立文件。尚未建立的日記顯示「新建日記」和日曆加號圖示。建立請求送出後移動游標,區塊引用仍插入原輸入位置;原內容被修改或刪除時不覆蓋新的內容。選取後優先依日記日期屬性查找目標筆記本中的日記,包括已移動或重新命名但保留該屬性的文件。多篇符合時優先選擇範本名稱和位置對應的文件,否則依 ID 升序選擇。若一般按鈕另建了範本位置的日記,日期候選會改為優先選擇它。沒有日期屬性符合時,再沿用或建立範本位置的文件並插入區塊引用。兩個入口沿用既有文件時均不會重新套用內容範本。路徑範本、內容範本中的 now 和日記日期屬性使用目標日期,實際建立和更新時間保持真實操作時間。"}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-scr2p21.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-scr2p21.syindex 274d6253f9..cf53850a3b 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-scr2p21.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-scr2p21.sy@@ -7,7 +7,7 @@"id": "20240530101000-scr2p21","title": "デイリーノート","type": "doc",- "updated": "20261024161816"+ "updated": "20261027135536"},"Children": [{@@ -16,7 +16,7 @@"HeadingLevel": 2,"Properties": {"id": "20260613180757-9fax3mg",- "updated": "20261024161816"+ "updated": "20261027135536"},"Children": [{@@ -45,7 +45,7 @@"HeadingLevel": 3,"Properties": {"id": "20260613180757-m1xjudy",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -60,7 +60,7 @@"ListData": {},"Properties": {"id": "20260613180757-woy35en",- "updated": "20260809232000"+ "updated": "20261027135536"},"Children": [{@@ -174,7 +174,7 @@},"Properties": {"id": "20260613180757-5v7czcr",- "updated": "20260613180757"+ "updated": "20261027135536"},"Children": [{@@ -182,17 +182,17 @@"Type": "NodeParagraph","Properties": {"id": "20260613180757-iu677jw",- "updated": "20260613180757"+ "updated": "20261027135536"},"Children": [{"Type": "NodeTextMark","TextMarkType": "strong",- "TextMarkTextContent": "初回表示"+ "TextMarkTextContent": "表示の動作"},{"Type": "NodeText",- "Data": ":当日の日記を開く際、該当日付のドキュメントがまだ存在しない場合は、設定された保存パスとテンプレートに基づいて生成されます。既に存在する場合はそのまま開きます"+ "Data": ":ボタンとショートカットは、当日の保存パステンプレートから決まる名前と場所のドキュメントを開き、存在しなければ作成します。日記の日付属性では検索しないため、元の日記を移動または名前変更すると別の日記が作成される場合があります"}]}@@ -206,7 +206,7 @@"HeadingLevel": 3,"Properties": {"id": "20261008101708-mjx358e",- "updated": "20261024161816"+ "updated": "20261027135536"},"Children": [{@@ -325,12 +325,12 @@"Type": "NodeParagraph","Properties": {"id": "20261008101708-pvky8qm",- "updated": "20261024161816"+ "updated": "20261027135536"},"Children": [{"Type": "NodeText",- "Data": "入力や候補の表示だけではドキュメントを作成しません。未作成の日記には新規デイリーノートの表示とカレンダーのプラスアイコンを使用します。作成要求後にカーソルを移動しても参照は元の入力位置に挿入されます。元の入力が変更または削除された場合は新しい内容を上書きしません。候補を選択すると、対象ノートブックの対応する日付のデイリーノートを再利用します。"+ "Data": "入力や候補の表示だけではドキュメントを作成しません。未作成の日記には新規デイリーノートの表示とカレンダーのプラスアイコンを使用します。作成要求後にカーソルを移動しても参照は元の入力位置に挿入されます。元の入力が変更または削除された場合は新しい内容を上書きしません。候補を選択すると、対象ノートブック内で日記の日付属性による検索を優先します。"}]},@@ -339,12 +339,12 @@"Type": "NodeParagraph","Properties": {"id": "20261024161816-jp220mt",- "updated": "20261024161816"+ "updated": "20261027135536"},"Children": [{"Type": "NodeText",- "Data": "日記の日付属性が残っていれば、移動や名前変更後のドキュメントも再利用します。存在しない場合のみ、日記の設定に従って作成して参照を挿入します。パステンプレート、本文テンプレート内の now、日記の日付属性には対象日付を使用し、実際の作成・更新時刻は操作時刻を保持します。"+ "Data": "日記の日付属性が残っていれば、移動や名前変更後のドキュメントも再利用します。複数が一致する場合はテンプレートの名前と場所に対応するドキュメントを優先し、それ以外は ID の昇順で選択します。通常のボタンでテンプレートの場所に別の日記を作成すると、日付候補もその日記を優先します。日付属性が一致する日記がなければ、テンプレートの場所のドキュメントを再利用または作成して参照を挿入します。どちらの入り口でも、既存のドキュメントを再利用する際に本文テンプレートを再適用しません。パステンプレート、本文テンプレート内の now、日記の日付属性には対象日付を使用し、実際の作成・更新時刻は操作時刻を保持します。"}]},diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.tsindex f9a29b11ed..a27faa500c 100644--- a/app/src/types/api/index.d.ts+++ b/app/src/types/api/index.d.ts@@ -5418,6 +5418,12 @@ export interface APIPOSTRoutes {/** 服务器路由要求;资源权限与笔记本租约仍由内核校验 */authorization?: readonly ["authenticated","admin","writable"];};+ /**+ * 省略 date、传空串或 null 时,按当天的命名和路径模板复用或创建,与日记按钮、快捷键一致。+ * 显式指定日期(包括今天)时,先按目标笔记本的日记日期属性复用,改名或移动后仍可找到原日记。+ * 多个日期匹配优先选择模板目标,否则按 ID 升序选择;无日期匹配时再复用或创建模板目标。+ * 两种入口复用已有文档均不重新应用正文模板;普通入口补建模板目标后,日期入口可能改为优先选择该目标。+ */"/api/filetree/createDailyNote": {request: FileTreeDailyNoteRequestInput;response: { "code": 0; "data": FileTreeCreateData; "msg": string; } | { "code": -1 | 1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -5490,6 +5496,10 @@ export interface APIPOSTRoutes {/** 服务器路由要求;资源权限与笔记本租约仍由内核校验 */authorization?: readonly ["authenticated","admin","writable"];};+ /**+ * 按日期属性预览日记,不创建文档;省略 date、传空串或 null 时查询当天。+ * 多个日期匹配优先选择模板目标,否则按 ID 升序选择;无日期匹配时再检查模板目标。+ */"/api/filetree/getDailyNoteInfo": {request: DailyNoteInfoRequestInput;response: { "code": 0; "data": DailyNoteInfo | null; "msg": string; } | { "code": -1 | 1; "data": { "closeTimeout": number; } | null; "msg": string; };diff --git a/docs/DOCUMENT-ADDRESSING.md b/docs/DOCUMENT-ADDRESSING.mdindex 9fe35ff387..a23ee3bef1 100644--- a/docs/DOCUMENT-ADDRESSING.md+++ b/docs/DOCUMENT-ADDRESSING.md@@ -208,14 +208,15 @@ Configuration-derived previews retain the source notebook, workflow purpose, eff| Entry point | Preserved behavior and migration focus || --- | --- || Ordinary creation and creation from block references | Create directly under known parent IDs; pass titles separately and retain document IDs in generated references |-| Daily notes | Reuse by the daily-note date attribute first; retain template-target preference for multiple matches and ID ordering otherwise; do not reapply body templates to existing notes |+| Daily-note button and shortcut | With no explicit date, reuse the target produced by today's naming and path template; renaming or moving the original note away from that target can result in another note being created |+| Date references and explicit-date APIs | First reuse notes with the date attribute in the target notebook; prefer the template target among matching notes, otherwise select by ascending ID; without a date match, reuse or create the template target || Shorthands | Distinguish appending to an explicit target from creating a new target; clear the source only after destination persistence succeeds || New database items | Preserve attribute values, bindings, and sorting; retain the final document ID in the creation plan || Template document trees | Preserve previews, ID remapping, insertion order, and grouped undo and redo; validate path, name, and configuration conditions on commit and expose partial completion || MCP and built-in Agent | Document tools prefer notebook plus `parentID`, with an empty string for root; legacy paths share ancestor validation and reject ambiguous single targets || Desktop, browser, and mobile | Inspect menus, shortcuts, dialogs, and handlers separately; shared utility migration does not replace platform verification |-Daily-note reuse is an explicit existing business rule. The generic resolver's ambiguity policy must not turn every multiple-date match into an error; template-target preference compares structured identity chains instead.+Daily notes retain two entry-point policies: omitting `date`, passing an empty string, or passing `null` to `createDailyNote` uses the ordinary button's template-target policy; an explicit date (including today) and `getDailyNoteInfo` use date attributes. The date entry can still reuse a renamed or moved note while the ordinary button may create a new template target; once that target also carries the day's date attribute, the date entry prefers it. Neither entry reapplies body templates when reusing an existing note. Multiple date matches follow this selection order rather than always returning ambiguity; template-target matching compares structured identity chains.## Search and derived indexesdiff --git a/docs/DOCUMENT-ADDRESSING.zh-CN.md b/docs/DOCUMENT-ADDRESSING.zh-CN.mdindex 83a00ab14a..74cecafbc2 100644--- a/docs/DOCUMENT-ADDRESSING.zh-CN.md+++ b/docs/DOCUMENT-ADDRESSING.zh-CN.md@@ -208,14 +208,15 @@| 入口 | 保持的业务行为与迁移重点 || --- | --- || 普通新建及块引用新建 | 已知父 ID 直接创建;新标题独立传递,生成的引用保存文档 ID |-| 日记 | 先按日记日期属性复用;多个匹配时保留现有模板目标优先、否则按 ID 排序的规则,已有日记不重新应用正文模板 |+| 日记按钮及快捷键 | 未指定日期,按当天求值后的命名和路径模板复用目标;原日记改名或移动后不再匹配目标时,可另建日记 |+| 日期引用及指定日期接口 | 先按目标笔记本中的日记日期属性复用;多个匹配时优先选择模板目标,否则按 ID 升序选择;无日期匹配时再复用或创建模板目标 || 速记 | 明确追加目标或新建目标;目标持久化成功后才清理来源 || 数据库新建条目 | 保留属性值、绑定关系和排序;创建计划保存最终文档 ID || 模板文档树 | 保留预览、ID 重映射、插入顺序及整组撤销和重做;提交校验路径、名称与配置条件并展示部分完成结果 || MCP 与内置 Agent | 文档工具优先使用笔记本及 `parentID`,空字符串表示根;旧路径复用祖先链判定,单目标同名歧义返回错误 || 桌面、浏览器和移动端 | 分别检查菜单、快捷键、对话框及事件处理;共享工具函数迁移不能代替各端验证 |-日记的既有复用策略是明确的业务规则,不因通用解析器拒绝歧义而改成所有同日期情况均报错;模板目标优先匹配改为结构化身份链比较。+日记保留两种入口的业务边界:`createDailyNote` 省略 `date`、传空字符串或 `null` 时沿用普通按钮的模板目标策略;显式传入日期(包括今天)及 `getDailyNoteInfo` 按日期属性查找。改名或移动后的原日记仍可被日期入口复用,但普通按钮可能创建新的模板目标;该目标同样带有当天日期属性后,日期入口会优先选择它。两种入口复用已有日记时均不重新应用正文模板。多个同日期匹配保留上述选择顺序,不改为一律报错;模板目标匹配使用结构化身份链比较。## 搜索与派生索引diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.goindex 2b11137112..22775f7b3a 100644--- a/kernel/apicontract/contracts.go+++ b/kernel/apicontract/contracts.go@@ -1161,8 +1161,15 @@ var DuplicateDoc = define[FileTreeIDRequest, FileTreeDuplicateData]("duplicateDo// DuplicateDocTree evaluates block collection rules for every copied document and block, initializing only new rows.var DuplicateDocTree = define[FileTreeIDRequest, FileTreeDuplicateData]("duplicateDocTree", "/api/filetree/duplicateDocTree", AuthenticatedAccess|AdminAccess|WritableAccess, JSONBody, ResponseOptions{}, "POST")var CreateDoc = define[FileTreeCreateRequest, FileTreeCreateData]("createDoc", "/api/filetree/createDoc", AuthenticatedAccess|AdminAccess|WritableAccess, JSONBody, ResponseOptions{}, "POST")++// CreateDailyNote 省略 date、传空串或 null 时,按当天的命名和路径模板复用或创建,与日记按钮、快捷键一致。+// 显式指定日期(包括今天)时,先按目标笔记本的日记日期属性复用,改名或移动后仍可找到原日记。+// 多个日期匹配优先选择模板目标,否则按 ID 升序选择;无日期匹配时再复用或创建模板目标。+// 两种入口复用已有文档均不重新应用正文模板;普通入口补建模板目标后,日期入口可能改为优先选择该目标。var CreateDailyNote = define[FileTreeDailyNoteRequest, FileTreeCreateData]("createDailyNote", "/api/filetree/createDailyNote", AuthenticatedAccess|AdminAccess|WritableAccess, JSONBody, ResponseOptions{AdditionalCodes: []int{1}}, "POST")+// GetDailyNoteInfo 按日期属性预览日记,不创建文档;省略 date、传空串或 null 时查询当天。+// 多个日期匹配优先选择模板目标,否则按 ID 升序选择;无日期匹配时再检查模板目标。var GetDailyNoteInfo = define[DailyNoteInfoRequest, *DailyNoteInfo]("getDailyNoteInfo", "/api/filetree/getDailyNoteInfo", AuthenticatedAccess|AdminAccess, JSONBody, ResponseOptions{AdditionalCodes: []int{1}}, "POST")// 使用编辑器 Markdown 语法选项,并按 `/api/import/importStdMd` 的规则转换标准脚注。diff --git a/kernel/apicontract/filetree_remaining.go b/kernel/apicontract/filetree_remaining.goindex 8603c34c69..d7777cb4bb 100644--- a/kernel/apicontract/filetree_remaining.go+++ b/kernel/apicontract/filetree_remaining.go@@ -85,7 +85,7 @@ type FileTreeCreateRequest struct {type FileTreeDailyNoteRequest struct {Notebook string `json:"notebook"`App string `json:"app" api:"optional,nullable"`- // Date 为本地公历日期 YYYY-MM-DD;省略、空串或 null 时使用当天。+ // Date 为本地公历日期 YYYY-MM-DD;省略、空串或 null 时按当天的命名及路径模板复用或创建,不按日期属性查找。// 指定日期时复用同笔记本的日记日期属性,路径和正文模板中的 now 使用目标日期。// 日期无效返回 -1;多个匹配优先选择模板路径对应的文档,否则按文档 ID 升序选择。// 返回文档 ID,已有文档不重新应用正文模板;加密笔记本的响应保留解锁租约。diff --git a/kernel/model/daily_note_fts5_test.go b/kernel/model/daily_note_fts5_test.gonew file mode 100644index 0000000000..f2e53b99fb--- /dev/null+++ b/kernel/model/daily_note_fts5_test.go@@ -0,0 +1,113 @@+//go:build fts5++package model++import (+ "bytes"+ "os"+ "path/filepath"+ "slices"+ "testing"+ "time"++ "github.com/siyuan-note/siyuan/kernel/sql"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestDailyNoteReuseAcrossEntryPoints(t *testing.T) {+ for _, change := range []string{"rename", "move"} {+ t.Run(change, func(t *testing.T) {+ fixture := setupStructureTransactionTest(t)+ setupFoldTransactionDatabase(t, fixture)+ boxConf := fixture.box.GetConf()+ boxConf.DailyNoteSavePath = "/Daily notes/Today"+ if err := fixture.box.SaveConf(boxConf); err != nil {+ t.Fatal(err)+ }++ date := time.Now()+ originalPath, existed, err := CreateDailyNote(fixture.box.ID)+ if err != nil || existed {+ t.Fatalf("create initial daily note: %s %v %v", originalPath, existed, err)+ }+ originalID := util.GetTreeID(originalPath)+ if change == "rename" {+ if err = RenameDoc(fixture.box.ID, originalPath, "Daily summary"); err != nil {+ t.Fatal(err)+ }+ } else {+ if err = MoveDocs([]string{fixture.box.ID + originalPath}, fixture.box.ID, "/", nil); err != nil {+ t.Fatal(err)+ }+ originalPath = "/" + originalID + ".sy"+ }++ readSource := func(id string) []byte {+ t.Helper()+ tree, loadErr := LoadTreeByBlockID(id)+ if loadErr != nil {+ t.Fatal(loadErr)+ }+ data, readErr := os.ReadFile(filepath.Join(util.DataDir, tree.Box, tree.Path))+ if readErr != nil {+ t.Fatal(readErr)+ }+ return data+ }+ assertDateTarget := func(wantID string) {+ t.Helper()+ info, infoErr := GetDailyNoteInfo(fixture.box.ID, date)+ if infoErr != nil || info == nil || !info.Existed || info.ID != wantID {+ t.Fatalf("date preview: got %+v (%v), want %s", info, infoErr, wantID)+ }+ p, reused, createErr := CreateDailyNoteAt(fixture.box.ID, date)+ if createErr != nil || !reused || util.GetTreeID(p) != wantID {+ t.Fatalf("dated entry: got %s %v (%v), want %s", p, reused, createErr, wantID)+ }+ }++ // 日期入口仍定位改名或移动后的日记,普通入口则按模板补建缺失目标。+ originalSource := readSource(originalID)+ assertDateTarget(originalID)+ targetPath, reused, err := CreateDailyNote(fixture.box.ID)+ if err != nil || reused || util.GetTreeID(targetPath) == originalID {+ t.Fatalf("ordinary entry did not create its missing template target: %s %v %v", targetPath, reused, err)+ }+ targetID := util.GetTreeID(targetPath)+ targetSource := readSource(targetID)++ // 已有目标不重新应用正文模板,即使当前配置指向一个不存在的模板。+ boxConf.DailyNoteTemplatePath = "/missing-body-template.md"+ if err = fixture.box.SaveConf(boxConf); err != nil {+ t.Fatal(err)+ }+ for range 2 {+ assertDateTarget(targetID)+ p, reused, createErr := CreateDailyNote(fixture.box.ID)+ if createErr != nil || !reused || p != targetPath {+ t.Fatalf("ordinary entry did not reuse its template target: %s %v %v", p, reused, createErr)+ }+ }+ if !bytes.Equal(originalSource, readSource(originalID)) || !bytes.Equal(targetSource, readSource(targetID)) {+ t.Fatal("alternating daily-note entries changed an existing source")+ }++ // 两篇同日期日记均不匹配新模板目标时,日期入口按 ID 升序选择,且不创建缺失目标。+ boxConf.DailyNoteSavePath = "/Another location/Today"+ if err = fixture.box.SaveConf(boxConf); err != nil {+ t.Fatal(err)+ }+ wantIDs := []string{originalID, targetID}+ slices.Sort(wantIDs)+ assertDateTarget(wantIDs[0])+ sql.FlushQueue()+ ids, err := sql.QueryDailyNoteRootIDsInBox(fixture.box.ID, DailyNoteAttrPrefix+date.Format("20060102"), date.Format("20060102"))+ if err != nil || !slices.Equal(ids, wantIDs) {+ t.Fatalf("unexpected daily-note documents: %v (%v), want %v", ids, err, wantIDs)+ }+ if !bytes.Equal(originalSource, readSource(originalID)) || !bytes.Equal(targetSource, readSource(targetID)) {+ t.Fatal("date fallback changed an existing source")+ }+ })+ }+}