nx-kv 0.62.1 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +2 -1
  3. package/package.json +1 -1
  4. package/src/core/db/seed-templates.ts +75 -3
  5. package/src/modules/docs/actions/_manifest.generated.ts +3 -0
  6. package/src/modules/docs/actions/docs-main.ts +39 -0
  7. package/src/modules/docs/refs.ts +75 -0
  8. package/src/web/frontend/api/cli-tree.json +15 -0
  9. package/src/web/frontend/api/client.generated.ts +10 -0
  10. package/src/web/frontend/components/icons.tsx +12 -0
  11. package/src/web/frontend/components/md/live-block.tsx +20 -5
  12. package/src/web/frontend/components/md/md-panes-root.tsx +4 -0
  13. package/src/web/frontend/components/md/md-panes.tsx +27 -1
  14. package/src/web/frontend/components/popup/style.css +4 -0
  15. package/src/web/frontend/components/sidebar/index.tsx +1 -0
  16. package/src/web/frontend/modules/md/styles/editor.css +24 -0
  17. package/src/web/frontend/modules/md/styles/panels.css +14 -2
  18. package/src/web/frontend/modules/md/template-locks.ts +105 -0
  19. package/src/web/frontend/modules/md/use-templates.ts +16 -5
  20. package/src/web/frontend/modules/prompts/template-preview.ts +70 -0
  21. package/src/web/frontend/page/dir/index.tsx +21 -9
  22. package/src/web/frontend/page/dir/task-actions.ts +2 -1
  23. package/src/web/frontend/page/dir/task.tsx +2 -2
  24. package/src/web/frontend/page/group/index.tsx +8 -11
  25. package/src/web/frontend/page/refs/index.tsx +49 -10
  26. package/src/web/frontend/page/refs/style.css +4 -0
  27. package/src/web/frontend/page/repos/block-tabs.tsx +30 -24
  28. package/src/web/frontend/page/repos/branch-picker.tsx +29 -20
  29. package/src/web/frontend/page/repos/doc-block.tsx +9 -2
  30. package/src/web/frontend/page/repos/index.tsx +63 -31
  31. package/src/web/frontend/page/repos/ref-block.tsx +6 -6
  32. package/src/web/frontend/page/repos/repo-table.tsx +10 -10
  33. package/src/web/frontend/page/repos/search-results.tsx +114 -0
  34. package/src/web/frontend/page/settings/index.tsx +0 -14
  35. package/src/web/frontend/page/templates/index.tsx +70 -30
  36. package/src/web/frontend/page/templates/style.css +62 -0
  37. package/src/web/frontend/page/templates/template-list.tsx +198 -0
  38. package/src/web/frontend/panels.tsx +2 -2
  39. package/src/web/frontend/refs/api.ts +10 -0
  40. package/src/web/frontend/refs/ops.ts +15 -0
  41. package/src/web/frontend/styles/repos-branch.css +72 -0
  42. package/src/web/frontend/types.ts +2 -0
  43. package/src/web/public/assets/app-context-DDQnrPSP.js +1 -0
  44. package/src/web/public/assets/bar-CYWfxHfm.js +1 -0
  45. package/src/web/public/assets/{board-view-CxihNjDm.js → board-view-BVennxTs.js} +1 -1
  46. package/src/web/public/assets/button-BEWXOABr.js +1 -0
  47. package/src/web/public/assets/composer-launch-Bor4ngrQ.js +1 -0
  48. package/src/web/public/assets/composer-panel-C7mNI7EW.js +1 -0
  49. package/src/web/public/assets/dag-BzdFYMml.js +1 -0
  50. package/src/web/public/assets/dir-CcffxXL2.js +3 -0
  51. package/src/web/public/assets/doc-BxWVzWkw.js +6 -0
  52. package/src/web/public/assets/frontmatter-CN6IlxWU.js +2 -0
  53. package/src/web/public/assets/group-C5Yu3oJr.js +1 -0
  54. package/src/web/public/assets/index-BvyZ1MA2.js +2 -0
  55. package/src/web/public/assets/index-Cp-TtHyA.css +1 -0
  56. package/src/web/public/assets/md-history-DejKuR12.js +39 -0
  57. package/src/web/public/assets/{md-parse-no7xfuA1.js → md-parse-C9Vd6ejP.js} +1 -1
  58. package/src/web/public/assets/member-picker-Cvbv24IK.js +1 -0
  59. package/src/web/public/assets/{model-YH7aER_y.js → model-Cc2EoUQp.js} +1 -1
  60. package/src/web/public/assets/overview-CctJfO3D.js +1 -0
  61. package/src/web/public/assets/{frontmatter-BZrdOH46.css → popup-BAvk7J7u.css} +1 -1
  62. package/src/web/public/assets/{frontmatter-CK4ti7be.js → popup-D8KWI6-Q.js} +1 -2
  63. package/src/web/public/assets/progress-CawQRCQf.js +3 -0
  64. package/src/web/public/assets/refs-DJdKV8_H.css +1 -0
  65. package/src/web/public/assets/refs-VbDnDTV0.js +2 -0
  66. package/src/web/public/assets/repo-form-modal-Dkdvu_uN.js +1 -0
  67. package/src/web/public/assets/repos-CY0eZheu.js +16 -0
  68. package/src/web/public/assets/route-crumb-BcDPd7Ht.js +1 -0
  69. package/src/web/public/assets/settings-D3T-vgCl.js +1 -0
  70. package/src/web/public/assets/status-tag-BD_0iWMB.js +1 -0
  71. package/src/web/public/assets/task-CkCD82h_.js +11 -0
  72. package/src/web/public/assets/task-row-CQgzQmzu.js +1 -0
  73. package/src/web/public/assets/{task-utils-BIUeGQ-v.js → task-utils-DpnPjZKJ.js} +1 -1
  74. package/src/web/public/assets/templates-BcuCbT4U.js +10 -0
  75. package/src/web/public/assets/templates-gNdtaMI2.css +1 -0
  76. package/src/web/public/assets/use-rail-drag-DMvr8-GE.js +1 -0
  77. package/src/web/public/assets/{workspace-BFjAH4-Z.js → workspace-D3jbcTwf.js} +2 -2
  78. package/src/web/public/index.html +17 -15
  79. package/src/web/frontend/page/settings/task-templates-section.tsx +0 -124
  80. package/src/web/public/assets/app-context-DJ_8MHEG.js +0 -1
  81. package/src/web/public/assets/bar-D_n00iZf.js +0 -1
  82. package/src/web/public/assets/composer-launch-DKpTk_et.js +0 -1
  83. package/src/web/public/assets/composer-panel-BuTQ4otm.js +0 -1
  84. package/src/web/public/assets/dag-B-5Zh9um.js +0 -1
  85. package/src/web/public/assets/dir-XjJQx6mX.js +0 -3
  86. package/src/web/public/assets/doc-nLsdRBww.js +0 -6
  87. package/src/web/public/assets/group-DzkX_qJJ.js +0 -1
  88. package/src/web/public/assets/index-Cuio6jjI.css +0 -1
  89. package/src/web/public/assets/index-kP1chg-J.js +0 -2
  90. package/src/web/public/assets/md-history-Hu_Zzy11.js +0 -39
  91. package/src/web/public/assets/member-picker-BmpHTUrK.js +0 -1
  92. package/src/web/public/assets/overview-BkzCE6-x.js +0 -1
  93. package/src/web/public/assets/progress-uUW8vQTZ.js +0 -3
  94. package/src/web/public/assets/refs-Bs0RZMWI.js +0 -2
  95. package/src/web/public/assets/refs-CIdrPlDN.css +0 -1
  96. package/src/web/public/assets/repo-form-modal-Bwr95n7V.js +0 -1
  97. package/src/web/public/assets/repos-DceWSdjD.js +0 -16
  98. package/src/web/public/assets/route-crumb-D73iZP1h.js +0 -1
  99. package/src/web/public/assets/settings-D9LFuVWi.js +0 -1
  100. package/src/web/public/assets/status-tag-DfTirXD_.js +0 -1
  101. package/src/web/public/assets/task-1TZaYQJI.js +0 -11
  102. package/src/web/public/assets/task-row-DFH4lNSh.js +0 -1
  103. package/src/web/public/assets/templates-B8sOtXTt.js +0 -1
  104. package/src/web/public/assets/use-rail-drag-CWKmhXVF.js +0 -1
  105. /package/src/web/public/assets/{repo-form-modal-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,39 @@
2
2
 
3
3
  本文件对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.63.0] - 2026-11-17 文档主篇 / 全局检索 / 模板插槽三块收口(#144–#147、#217、#218)
6
+
7
+ ### Added
8
+
9
+ - **文档列表「⋯ → 设为主篇」**(#144):面板行尾菜单可以直接把某一篇设成宿主的**主篇**,
10
+ 主篇行多一枚绿色「主篇」标签(以前只有标题颜色不同,看不出谁是主篇)。
11
+ 新增 `docs.main`(CLI `nx-kv docs main --repo|--board --ref`,HTTP `POST /api/docs/main`):
12
+ 语义是**换位**——目标从附加篇摘出、**原主篇退回附加篇**,两边都不丢归属;
13
+ 目标没绑在这个宿主上直接报错,重复设同一篇幂等。
14
+ (老的 `docs bind` 只换指针、不动附加篇:目标本来在附加篇会出现「同一篇两份」,
15
+ 原主篇则失去归属、3 天后被孤儿清理——面板因此不走那条。)
16
+ - **任务模板成为独立列表页**(#217):侧边栏新增「任务模板」入口,`#/templates` 是真正的
17
+ 列表页(设置页的「任务模板」tab 下线);每张模板卡可「预览」渲染结果
18
+ (没值的槽位显示成〔槽位名〕)。
19
+ - **模板骨架只读 + 插槽可编辑**(#217/#218):模板正文里含插槽的段落,在用它建出的任务里
20
+ **只读**、插槽块可编辑(`template-locks.ts` 纯派生下标集合,零数据迁移);
21
+ 模板身份写进任务正文 frontmatter `template:<id>`;插槽统一一个名字 **`{{content}}`**
22
+ (可写多次共用同值),出厂模板正文自愈成 `{{content}}` 版(旧编辑器渲染后写回的产物,
23
+ 下次开库恢复;差一个字都不动)。
24
+ - **分组选择器底部「+ 新建分组」**(#145):弹窗问名字即建组并切过去,不用再绕「分组管理」。
25
+
26
+ ### Changed
27
+
28
+ - **仓库页文案统一「分组」**(#145):界面上一律「分组」,「分支」只是当初的比喻;
29
+ 同时删掉选择器底部与分组信息条里的解释文字(一行只留必要信息)。
30
+ - **搜索框上移到分组信息条 + 检索改成全局**(#146):搜索框与分组名同行(不再跟着区块按钮走),
31
+ 有词时区块按钮让位给「搜索结果」页——`仓库 N · 参考仓库 M · 文档 K` + 三段各一张表
32
+ (同样的行与动作,不是只读视图),一键清除回到原视图。
33
+ - **文档列表行尾只留一个 ⋯**(#147):原来那个红色 ×(移出)也收进菜单,与
34
+ 「设为主篇 / 复制 refId」并列,hint 写明「只解除归属,文档本身不删」。
35
+ - **md 窄列排版补齐紧凑档**:编辑列被挤到 ~640px 以下时标题、块距、代码块按档收紧
36
+ (宽栏排版零变化)。
37
+
5
38
  ## [0.62.1] - 2026-11-16 仓库页第二轮:计数去重、按钮收拢进 ⋯、行内补图标(#143)
6
39
 
7
40
  ### Changed
@@ -68,7 +68,8 @@
68
68
  | `docs ref unbind` | `--ref` `--type` `--repo` `--group` | 摘归属(文档与正文保留) |
69
69
  | `docs remove` | `--ref` | 删整篇 |
70
70
  | `docs bindings` | `--ref` \| `--host <repoKey>` \| `--group <groupKey>` | 归属查询:`--host` 只给仓库自己的(含参考仓库);`--group` 给组域(组 → 组内 → 成员仓库自己 → **组内参考仓库自己**)。每行带 `hostKind`(`dev` / `ref` / `group`) |
71
- | `docs bind` / `docs link` / `docs note-bind` | `--repo`/`--board` `--ref` `--path` `--note` `--remove` `--before` `--reset` | 宿主文档集的增删改(`bind` 主篇,`link` 目录补充,`note-bind` 组内描述) |
71
+ | `docs bind` / `docs link` / `docs note-bind` | `--repo`/`--board` `--ref` `--path` `--note` `--remove` `--before` `--reset` | 宿主文档集的增删改(`bind` 主篇指针,`link` 目录补充,`note-bind` 组内描述) |
72
+ | `docs main` | `--repo`/`--board`(二选一)`--ref` \| `--path` | **把某一篇设为主篇**(换位):目标从附加篇摘出、原主篇退回附加篇,两边都不丢归属。面板「文档列表 → 行尾 ⋯ → 设为主篇」走这条;`docs bind` 只换指针、会把原主篇甩成孤儿 |
72
73
  | `docs attach` / `detach` / `attachments` / `attach-note` | `--ref` + 附件参数 | 文档附件(用法同 `localtask attach`) |
73
74
  | `docs mdfile` / `mdfiles` / `link-file` | `--attachment` / `--missing` / `--path` | md 文件指针相关 |
74
75
  | `docs gc` | `--apply` | 清没有正文的 ref(默认只报数) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.62.1",
3
+ "version": "0.63.0",
4
4
  "description": "nx-kv — 本机任务队列(localtask)+ 文档库 + 仓库登记:serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,7 +17,44 @@
17
17
  import type { DbApi } from './driver.js';
18
18
 
19
19
  /**
20
- * 内置「ref 生成」任务模板的正文(#137)。
20
+ * 插槽的**统一写法**(#218):`{{content}}`。
21
+ *
22
+ * 为什么不许自定义名字:#217 的锁定判定靠「模板里有槽位就把它当可编辑出口」,
23
+ * 名字各写各的(`{{问题}}` / `{{任务}}` / `{{需求}}`)时,一眼看不出哪段是插槽,
24
+ * 也没法在文案里给用户一个固定说法。所以对用户只认一个名字 —— 一个模板可以有
25
+ * 多个 `{{content}}`,它们共享同一个值(模板正文里重复出现同一段内容时用得上)。
26
+ *
27
+ * 渲染层仍按 `{{名字}}` 通用解析(老模板不至于一升级就失效),但出厂文本、
28
+ * 新建骨架、面板文案一律只出现 `content`。
29
+ */
30
+ export const SLOT_NAME = 'content';
31
+
32
+ /** 内置模板的槽位默认值:提示文字,不是空串(空块看不出该写什么)。 */
33
+ const CONTENT_HINT = '(把你要问这个仓库的问题写在这里)';
34
+
35
+ /** 模板正文里有没有插槽(含 `{{content}}` 或任何 `{{名字}}`)。 */
36
+ function hasSlot(body: string): boolean {
37
+ return /\{\{\s*[^}{\s][^{}]*?\s*\}\}/.test(String(body || ''));
38
+ }
39
+
40
+ /**
41
+ * 出厂正文「被当成普通正文保存过一次」的样子:插槽已经渲染成默认值。
42
+ *
43
+ * #217 的模板编辑器曾经把正文渲染后再给用户编辑(保存即把 `{{content}}`
44
+ * 写成提示文字),库里因此留下一批「没有插槽的内置模板」。#218 修了编辑器,
45
+ * 同时用这个形态做**自愈判据**:body 与它逐字相同 = 用户没改过内容,可以安全
46
+ * 恢复成带插槽的出厂文本;差一个字都不动(T06:内置不被代码覆盖用户编辑)。
47
+ */
48
+ function renderedFactoryBody(t: { body: string; vars?: Readonly<Record<string, unknown>> }): string {
49
+ const vals = t.vars || {};
50
+ return String(t.body || '').replace(/\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g, (_all, name) => {
51
+ const v = vals[String(name).trim()];
52
+ return v === undefined || v === null ? '' : String(v);
53
+ });
54
+ }
55
+
56
+ /**
57
+ * 内置「ref 生成」任务模板的正文(#137;#218 起插槽统一 `{{content}}`)。
21
58
  *
22
59
  * 它是**新任务正文骨架**:用户在这个仓库里提一个问题 → agent 按正文里的
23
60
  * 「零知识起步 SOP」走一遍 → 这轮问答被归档成一篇 ref,挂进该仓库的文档列表。
@@ -27,7 +64,7 @@ import type { DbApi } from './driver.js';
27
64
  */
28
65
  export const NEWTASK_REF_BODY = `## 本轮问题
29
66
 
30
- (把你要问这个仓库的问题写在这里)
67
+ {{content}}
31
68
 
32
69
  ---
33
70
 
@@ -105,7 +142,10 @@ export const BUILTIN_TEMPLATES = Object.freeze([
105
142
  slot: 'suffix',
106
143
  body: NEWTASK_REF_BODY,
107
144
  varsSchema: [],
108
- vars: {},
145
+ // 槽位默认值 = 用户看到的「填这里」提示:渲染后任务里不是空块,点进去改成自己的问题即可。
146
+ // 默认值是**提示文字**而不是空串,是因为 #217 之后这块在编辑器里是「可编辑插槽」——
147
+ // 空块看不出该写什么。
148
+ vars: { [SLOT_NAME]: CONTENT_HINT },
109
149
  isDefault: 1,
110
150
  },
111
151
  {
@@ -204,5 +244,37 @@ export function seedBuiltinTemplates(conn: DbApi, atMs: number): number {
204
244
  }
205
245
  );
206
246
  }
247
+ // ③ 出厂正文自愈(#218):插槽被旧编辑器吃掉的 builtin 行恢复成带 {{content}} 的出厂文本
248
+ healRenderedBuiltinBodies(conn, atMs);
207
249
  return BUILTIN_TEMPLATES.length;
208
250
  }
251
+
252
+ /**
253
+ * 出厂正文自愈(#218;seedBuiltinTemplates 的第 ③ 步,独立导出以便单测)。
254
+ *
255
+ * 命中条件只有一个:内置行的 body **等于**「出厂文本按默认值渲染后的样子」。
256
+ * 那正是旧编辑器「先渲染再编辑、保存回库」留下的产物 —— 插槽变成了提示文字。
257
+ * 用户只要动过任何一个字(改写骨架、换掉提示、加一段),body 就对不上,一律不动。
258
+ *
259
+ * 返回被恢复的模板 id(正常库上是空数组,幂等)。
260
+ */
261
+ export function healRenderedBuiltinBodies(conn: DbApi, atMs: number): string[] {
262
+ const healed: string[] = [];
263
+ for (const t of BUILTIN_TEMPLATES) {
264
+ if (!hasSlot(t.body)) continue;
265
+ const eaten = renderedFactoryBody(t);
266
+ if (eaten === t.body) continue;
267
+ const row = conn.get('SELECT body, builtin FROM templates WHERE id = :id', { id: t.id }) as
268
+ | { body?: string; builtin?: number }
269
+ | undefined;
270
+ if (!row || !Number(row.builtin)) continue;
271
+ if (String(row.body || '') !== eaten) continue;
272
+ conn.run(
273
+ `UPDATE templates SET body = :body, vars = :vars, updated_at = :at
274
+ WHERE id = :id AND builtin = 1`,
275
+ { id: t.id, body: t.body, vars: JSON.stringify(t.vars || {}), at: atMs },
276
+ );
277
+ healed.push(t.id);
278
+ }
279
+ return healed;
280
+ }
@@ -24,6 +24,7 @@ import { DocsBindingsAction } from './docs-bindings.js';
24
24
  import { DocsGcAction } from './docs-gc.js';
25
25
  import { DocsIndexAction } from './docs-index.js';
26
26
  import { DocsLinkAction } from './docs-link.js';
27
+ import { DocsMainAction } from './docs-main.js';
27
28
  import { DocsNotebindAction } from './docs-notebind.js';
28
29
  import { DocsOrphansPurgeAction } from './docs-orphans-purge.js';
29
30
  import { DocsOrphansAction } from './docs-orphans.js';
@@ -48,6 +49,7 @@ export const ACTIONS: readonly (new (deps: Container) => ActionBase)[] = [
48
49
  DocsGcAction,
49
50
  DocsIndexAction,
50
51
  DocsLinkAction,
52
+ DocsMainAction,
51
53
  DocsNotebindAction,
52
54
  DocsOrphansPurgeAction,
53
55
  DocsOrphansAction,
@@ -72,6 +74,7 @@ export { DocsBindingsAction };
72
74
  export { DocsGcAction };
73
75
  export { DocsIndexAction };
74
76
  export { DocsLinkAction };
77
+ export { DocsMainAction };
75
78
  export { DocsNotebindAction };
76
79
  export { DocsOrphansPurgeAction };
77
80
  export { DocsOrphansAction };
@@ -0,0 +1,39 @@
1
+ // docs.main —— 把某一篇设为宿主的**主篇**(#144)。
2
+ //
3
+ // 与 docs.bind 的分工:
4
+ // · `docs bind` 是「指定主篇指针」的老命令,只换指针、不动附加篇(CLI 专用);
5
+ // · `docs main` 是**换位**:目标从附加篇摘出、原主篇退回附加篇,两边都不丢归属。
6
+ // 面板的「⋯ → 设为主篇」走这条(面板只认真实语义,不制造孤儿文档)。
7
+ //
8
+ // 宿主:`--repo <仓库>` 或 `--board <组>`(二选一);目标是 `--ref <refId>` 或 `--path`。
9
+ import { action } from '../../../runtime/action-decorator.js';
10
+ import { z } from 'zod';
11
+ import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
12
+ import * as refsNs from '../refs.js';
13
+ const refs: any = refsNs;
14
+
15
+ /** docs.main 的入参契约(CLI 与 HTTP 共用同一份)。 */
16
+ const input = z.object({
17
+ repo: z.string().optional().describe('仓库(id / key / 名称)——与 --board 二选一'),
18
+ board: z.string().optional().describe('项目组(id / key / 名称)——与 --repo 二选一'),
19
+ ref: z.string().optional().describe('文档 refId(ref_<16hex>)'),
20
+ path: z.string().optional().describe('外部文件绝对路径(会登记成 origin=external 的 ref)'),
21
+ });
22
+
23
+ export class DocsMainAction extends ActionBase<typeof input> {
24
+ @action({
25
+ id: 'docs.main',
26
+ cli: ['docs', 'main'],
27
+ http: ['POST', '/api/docs/main'],
28
+ summary: '把某一篇设为主篇:原主篇退回附加篇(不丢归属),目标从附加篇摘出(不会出现两份)',
29
+ input,
30
+ render: (d: any) => (
31
+ d && d.alreadyMain
32
+ ? `已经是主篇: ${d.name}`
33
+ : `已设为主篇: ${d.name}(原主篇${d.previous ? ` ${d.previous} ` : ' '}退回附加篇;列表共 ${d.count} 篇)`
34
+ ),
35
+ })
36
+ override async run(ctx: ActionInput<this['_input']>) {
37
+ return refs.setDocMain(ctx);
38
+ }
39
+ }
@@ -94,6 +94,81 @@ export async function setDocRef({ repo, board, ref, path, reset }: SetDocRefInpu
94
94
  return res;
95
95
  }
96
96
 
97
+ /** setDocMain 的入参:宿主(repo / board 二选一)+ 目标文档(ref / path)。 */
98
+ export interface SetDocMainInput {
99
+ repo?: unknown;
100
+ board?: unknown;
101
+ ref?: unknown;
102
+ path?: unknown;
103
+ }
104
+
105
+ /**
106
+ * 把某一篇设成宿主的**主篇**(#144)。
107
+ *
108
+ * 与 `docs bind` 的差别(用户视角正是这一点):这是**换位**,不是覆盖——
109
+ * · 目标那篇如果已经在附加篇(docLinks)里,先把它摘出来,避免同一篇出现两次;
110
+ * · 原主篇还在、且不是目标 → 挪到 docLinks 头部,**保住它的归属**
111
+ * (`docs bind` 会直接把原主篇甩成孤儿,3 天后被清理);
112
+ * · 目标没绑在这个宿主上 → 显式报错,先加进列表(不做「顺手加一篇」的隐式行为)。
113
+ *
114
+ * 宿主 = 仓库(repo.doc/docLinks)或组(board.doc/docLinks);组内仓库描述
115
+ * (board.repoDocs)不在这个语义里。
116
+ */
117
+ export async function setDocMain({ repo, board, ref, path }: SetDocMainInput = {}): Promise<any> {
118
+ if (!!repo === !!board) throw badInput('请给 --repo <仓库> 或 --board <看板>(二选一)');
119
+ const docRef = await docRefOf({ ref, path });
120
+ const { mutateStore, deriveKey, boardKeyOf } = await reposBridge();
121
+ const nk = { normalizeKey, boardKeyOf };
122
+ const repoKeyIn = makeRepoKeyIn({ normalizeKey, deriveKey });
123
+ const res = await mutateStore((s: any) => {
124
+ const host = repo
125
+ ? (() => {
126
+ const rkey = repoKeyIn(s, repo);
127
+ if (!rkey) throw notFound('repo 不存在: ' + String(repo));
128
+ const r = s.repos.find((x: any) => deriveKey(x) === rkey);
129
+ if (!r) throw notFound('repo 不存在: ' + String(repo));
130
+ return r;
131
+ })()
132
+ : (() => {
133
+ const b = findBoardIn(s, board, nk);
134
+ if (!b) throw notFound('看板不存在: ' + String(board));
135
+ return b;
136
+ })();
137
+ const links: any[] = Array.isArray(host.docLinks) ? host.docLinks : [];
138
+ const inLinks = links.findIndex((x: any) => x && x.ref === docRef.ref);
139
+ const isMain = !!(host.doc && host.doc.ref === docRef.ref);
140
+ if (isMain && inLinks < 0) {
141
+ return { changed: false, alreadyMain: true, name: host.name, key: deriveKey(host), ref: docRef.ref };
142
+ }
143
+ // 目标必须已经在这个宿主的文档列表里(主篇或附加篇)。不在这里就显式报错——
144
+ // 「顺手把它加成主篇」是隐式行为,会让列表凭空多一篇。
145
+ if (!isMain && inLinks < 0) {
146
+ throw conflict('这篇不在这个宿主的文档列表里:先加进去(repo doc add / docs link)再设主篇');
147
+ }
148
+ // ① 目标从附加篇里摘出来(同一篇不能既是主篇又在附加篇里)
149
+ if (inLinks >= 0) links.splice(inLinks, 1);
150
+ // ② 原主篇退回附加篇头部(保住归属;只有它还在、且不是目标时才动)
151
+ const prev = host.doc;
152
+ if (prev && prev.ref && prev.ref !== docRef.ref) links.unshift(prev);
153
+ // ③ 目标上位
154
+ host.doc = docRef;
155
+ if (links.length) host.docLinks = links;
156
+ else delete host.docLinks;
157
+ host.updatedAt = new Date().toISOString();
158
+ return {
159
+ changed: true,
160
+ alreadyMain: false,
161
+ name: host.name,
162
+ key: deriveKey(host),
163
+ ref: docRef.ref,
164
+ previous: prev && prev.ref ? prev.ref : '',
165
+ count: links.length + 1,
166
+ };
167
+ });
168
+ await syncRefIndex();
169
+ return res;
170
+ }
171
+
97
172
  /** setNoteDocRef 的入参。 */
98
173
  export interface SetNoteDocRefInput {
99
174
  board?: string;
@@ -1098,6 +1098,21 @@
1098
1098
  },
1099
1099
  "children": []
1100
1100
  },
1101
+ {
1102
+ "name": "main",
1103
+ "path": [
1104
+ "docs",
1105
+ "main"
1106
+ ],
1107
+ "action": {
1108
+ "id": "docs.main",
1109
+ "module": "docs",
1110
+ "summary": "把某一篇设为主篇:原主篇退回附加篇(不丢归属),目标从附加篇摘出(不会出现两份)",
1111
+ "usage": "docs main",
1112
+ "http": "POST /api/docs/main"
1113
+ },
1114
+ "children": []
1115
+ },
1101
1116
  {
1102
1117
  "name": "note-bind",
1103
1118
  "path": [
@@ -30,6 +30,7 @@ import type {
30
30
  DocsGcAction,
31
31
  DocsIndexAction,
32
32
  DocsLinkAction,
33
+ DocsMainAction,
33
34
  DocsOrphansAction,
34
35
  DocsOrphansPurgeAction,
35
36
  } from '../../../modules/docs/actions/_manifest.generated.js';
@@ -287,6 +288,8 @@ export interface ApiClient {
287
288
  index(): Promise<Awaited<ReturnType<InstanceType<typeof DocsIndexAction>['run']>>>;
288
289
  /** 维护组的附加文档列表(--ref <refId> | --path <外部路径> + --note;--remove <序号> 移除;--before <序号> 插位;同 ref 重复添加 = 更新) */
289
290
  link(input: z.input<InstanceType<typeof DocsLinkAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsLinkAction>['run']>>>;
291
+ /** 把某一篇设为主篇:原主篇退回附加篇(不丢归属),目标从附加篇摘出(不会出现两份) */
292
+ main(input?: z.input<InstanceType<typeof DocsMainAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsMainAction>['run']>>>;
290
293
  /** 孤儿到期清理(默认只预演;--apply 软删空正文到期孤儿,有正文的只列清单) */
291
294
  purge(input?: z.input<InstanceType<typeof DocsOrphansPurgeAction>['_input']>): Promise<Awaited<ReturnType<InstanceType<typeof DocsOrphansPurgeAction>['run']>>>;
292
295
  /** 列出无归属的孤儿文档(失绑时间 / 剩余天数 / 是否有正文;只读) */
@@ -891,6 +894,13 @@ export function createApiClient(transport: Transport): ApiClient {
891
894
  const body = { "board": inp["board"], "ref": inp["ref"], "path": inp["path"], "note": inp["note"], "remove": inp["remove"], "before": inp["before"] };
892
895
  return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof DocsLinkAction>['run']>>;
893
896
  },
897
+ // action: docs.main
898
+ async main(input?: z.input<InstanceType<typeof DocsMainAction>['_input']>) {
899
+ const inp = input ?? ({} as z.input<InstanceType<typeof DocsMainAction>['_input']>);
900
+ const path = `/api/docs/main`;
901
+ const body = { "repo": inp["repo"], "board": inp["board"], "ref": inp["ref"], "path": inp["path"] };
902
+ return (await transport.request("POST", path, body)) as Awaited<ReturnType<InstanceType<typeof DocsMainAction>['run']>>;
903
+ },
894
904
  // action: docs.orphans.purge
895
905
  async purge(input?: z.input<InstanceType<typeof DocsOrphansPurgeAction>['_input']>) {
896
906
  const inp = input ?? ({} as z.input<InstanceType<typeof DocsOrphansPurgeAction>['_input']>);
@@ -24,6 +24,18 @@ const ICONS: Record<string, ReactNode> = {
24
24
  <path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
25
25
  </>
26
26
  ),
27
+ // #144:主篇(星)/ 链接(复制 refId)——文档列表的 ⋯ 菜单用
28
+ star: (
29
+ <>
30
+ <path d="m12 3.6 2.6 5.3 5.9.9-4.3 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8L3.5 9.8l5.9-.9z" />
31
+ </>
32
+ ),
33
+ link: (
34
+ <>
35
+ <path d="M10.2 13.8a3.6 3.6 0 0 0 5.1 0l2.6-2.6a3.6 3.6 0 0 0-5.1-5.1l-1.2 1.2" />
36
+ <path d="M13.8 10.2a3.6 3.6 0 0 0-5.1 0l-2.6 2.6a3.6 3.6 0 0 0 5.1 5.1l1.2-1.2" />
37
+ </>
38
+ ),
27
39
  search: (
28
40
  <>
29
41
  <circle cx="11" cy="11" r="6.5" />
@@ -33,6 +33,10 @@ interface LiveBlockProps {
33
33
  rail?: ReactNode;
34
34
  /** 拖拽落点指示:插到本块之前还是之后(null = 不是落点) */
35
35
  dropEdge?: 'before' | 'after' | null;
36
+ /** 模板骨架块:只读(点击不进编辑、不渲染把手)。由 template-locks 派生。 */
37
+ locked?: boolean;
38
+ /** 模板插槽块:可编辑,但加视觉标记(这里是要填内容的地方)。 */
39
+ slot?: boolean;
36
40
  }
37
41
 
38
42
  export default function LiveBlock({
@@ -53,6 +57,8 @@ export default function LiveBlock({
53
57
  pendingFormatRef,
54
58
  rail = null,
55
59
  dropEdge = null,
60
+ locked = false,
61
+ slot = false,
56
62
  }: LiveBlockProps) {
57
63
  const taRef = useRef<HTMLTextAreaElement | null>(null);
58
64
  const display = normalizeBlockText(text);
@@ -100,7 +106,7 @@ export default function LiveBlock({
100
106
  // 拖拽落点指示(拖拽排序时由父组件的列表级 dragover 算出)
101
107
  const dropCls = dropEdge ? ` is-drop-${dropEdge}` : '';
102
108
 
103
- if (focused) {
109
+ if (focused && !locked) {
104
110
  return (
105
111
  <div className={`mdw-lp-block is-edit kind-${kind}${dropCls}`} data-i={index}>
106
112
  {rail}
@@ -142,19 +148,28 @@ export default function LiveBlock({
142
148
 
143
149
  return (
144
150
  <div
145
- className={`mdw-lp-block is-view kind-${kind}${isEmptyBlock(text) ? ' is-empty' : ''}${hit ? ' is-hit' : ''}${dropCls}`}
151
+ className={`mdw-lp-block is-view kind-${kind}${isEmptyBlock(text) ? ' is-empty' : ''}${hit ? ' is-hit' : ''}${dropCls}${locked ? ' is-locked' : ''}${slot ? ' is-slot' : ''}`}
146
152
  data-i={index}
147
153
  role="button"
148
- tabIndex={0}
149
- onClick={(e) => onViewClick(e, index)}
154
+ tabIndex={locked ? -1 : 0}
155
+ aria-readonly={locked || undefined}
156
+ title={locked ? '模板骨架:只读(要改这段,请去任务模板里改)' : undefined}
157
+ onClick={(e) => {
158
+ // 模板骨架块不可进编辑态:点击不再冒泡到「聚焦」逻辑(勾选框也不响应)
159
+ if (locked) return;
160
+ onViewClick(e, index);
161
+ }}
150
162
  onKeyDown={(e) => {
163
+ if (locked) return;
151
164
  if (e.key === 'Enter' || e.key === ' ') {
152
165
  e.preventDefault();
153
166
  onFocus(index);
154
167
  }
155
168
  }}
156
169
  >
157
- {rail}
170
+ {locked ? null : rail}
171
+ {locked && <span className="mdw-lp-lock" aria-hidden>模板</span>}
172
+ {slot && <span className="mdw-lp-slot" aria-hidden>插槽</span>}
158
173
  {html ? (
159
174
  <div className="mdw-lp-view" dangerouslySetInnerHTML={{ __html: html }} />
160
175
  ) : (
@@ -34,6 +34,8 @@ export interface MdPanesProps {
34
34
  onCloseSelMenu?: (() => void) | null;
35
35
  hideTitle?: boolean;
36
36
  attachHost?: AttachHost | null;
37
+ /** 模板编辑器的插槽块下标(#218):只加「插槽」徽标,不产生只读块。 */
38
+ tplSlotBlocks?: Set<number> | null;
37
39
  }
38
40
 
39
41
  /** 实时预览 / 源码 / 阅读 */
@@ -56,6 +58,7 @@ export const MdPanes = forwardRef<HTMLElement, MdPanesProps>(function MdPanes(
56
58
  onCloseSelMenu = null,
57
59
  hideTitle = false,
58
60
  attachHost = null,
61
+ tplSlotBlocks = null,
59
62
  },
60
63
  articleRef
61
64
  ) {
@@ -175,6 +178,7 @@ export const MdPanes = forwardRef<HTMLElement, MdPanesProps>(function MdPanes(
175
178
  onCloseSelMenu={onCloseSelMenu}
176
179
  hideTitle={hideTitle}
177
180
  attachHost={attachHost}
181
+ tplSlotBlocks={tplSlotBlocks}
178
182
  />
179
183
  </div>
180
184
  );
@@ -21,6 +21,7 @@ import {
21
21
  useEffect,
22
22
  useImperativeHandle,
23
23
  useLayoutEffect,
24
+ useMemo,
24
25
  useRef,
25
26
  } from 'react';
26
27
  import type {
@@ -57,6 +58,9 @@ import {
57
58
  toggleNthTodo,
58
59
  } from '../../modules/md/md-edit-ops.js';
59
60
  import { isFrontmatterBlock, normalizeBlockText } from '../../modules/md/md-parse.js';
61
+ import { computeTemplateLocks } from '../../modules/md/template-locks.js';
62
+ import { templateIdOf } from '../../modules/prompts/template-preview.js';
63
+ import { useApp } from '../../app-context.jsx';
60
64
  import type { Attachment } from './attach-common.js';
61
65
 
62
66
  export { MdPanes, ModeSeg } from './md-panes-root.jsx';
@@ -149,6 +153,13 @@ interface LivePreviewProps {
149
153
  onCloseSelMenu?: (() => void) | null;
150
154
  hideTitle?: boolean;
151
155
  attachHost?: AttachHost | null;
156
+ /**
157
+ * 调用方直接声明的插槽块下标(模板编辑器用,#218)。
158
+ * 任务编辑器的插槽来自正文 frontmatter 的模板身份(locks.slots);
159
+ * 模板编辑器编辑的就是模板本身、没有身份可言,所以由调用方按
160
+ * 「哪块含 {{content}}」算好递进来 —— 只加插槽徽标,不产生只读块。
161
+ */
162
+ tplSlotBlocks?: Set<number> | null;
152
163
  }
153
164
 
154
165
  /**
@@ -157,7 +168,7 @@ interface LivePreviewProps {
157
168
  */
158
169
  function LivePreview({
159
170
  title, body, onTitle, onBody, articleRef, attachments, docKey, onFiles, editorApiRef, onTextSel,
160
- onCloseSelMenu, hideTitle = false, attachHost = null,
171
+ onCloseSelMenu, hideTitle = false, attachHost = null, tplSlotBlocks = null,
161
172
  }: LivePreviewProps) {
162
173
  const {
163
174
  blocks, focus, setFocus, pendingSelRef, pendingFormatRef, liveTaRef,
@@ -172,6 +183,19 @@ function LivePreview({
172
183
  // 拖拽排序:落点判定在列表级(一个 dragover 管整张列表),把手在块侧栏里
173
184
  const drag = useBlockDrag(moveBlock);
174
185
 
186
+ // 模板生成的任务(正文 frontmatter 的 `template: <id>`):骨架块只读、插槽块可编辑。
187
+ // 纯派生——锁定范围由「模板当下的正文 + 这条任务的正文」算出来,模板改了自动跟随;
188
+ // 不是模板任务(没有该键)就完全不锁,编辑器行为与以前一致。
189
+ const app = useApp();
190
+ const locks = useMemo(() => {
191
+ const id = templateIdOf(body);
192
+ if (!id) return null;
193
+ const tplBody = (app.tpl?.templates || []).find((t) => t.id === id)?.body || '';
194
+ if (!String(tplBody).trim()) return null;
195
+ const r = computeTemplateLocks(body, tplBody);
196
+ return r.locked.size || r.slots.size ? r : null;
197
+ }, [body, app.tpl?.templates]);
198
+
175
199
  // ── 跨块选区(#124):块粒度的「统一删除」────────────────────────────
176
200
  // 视图块是渲染好的 HTML,选区字符偏移无法精确映射回各块源码(markdown
177
201
  // 标记在渲染时被剥掉)——沿用本编辑器一贯的保守口径(#98 同源):**升到
@@ -405,6 +429,8 @@ function LivePreview({
405
429
  text={b}
406
430
  focused={focus === i}
407
431
  hit={hitBlock === i}
432
+ locked={!!locks?.locked.has(i)}
433
+ slot={!!(locks?.slots.has(i) || tplSlotBlocks?.has(i))}
408
434
  attachments={attachments}
409
435
  pendingSelRef={pendingSelRef}
410
436
  pendingFormatRef={pendingFormatRef}
@@ -61,4 +61,8 @@
61
61
  }
62
62
  .pp-menu-item:hover { background: var(--soft); }
63
63
  .pp-menu-item.danger { color: var(--danger); }
64
+ /* 菜单项图标(#144 起 RowMenuItem 支持 icon):图标说类别、文字说动作 */
65
+ .pp-menu-item-ico { display: inline-flex; flex: none; color: var(--mid); }
66
+ .pp-menu-item:hover .pp-menu-item-ico,
67
+ .pp-menu-item.danger:hover .pp-menu-item-ico { color: currentColor; }
64
68
  .pp-sep { height: 1px; background: var(--line); margin: 4px 6px; }
@@ -465,6 +465,7 @@ export default function Sidebar({
465
465
  </div>
466
466
 
467
467
  <div className="sfoot">
468
+ {footEntry('#/templates', 'list', '任务模板')}
468
469
  {footEntry('#/overview', 'overview', '全部目录总览')}
469
470
  {footEntry('#/repos', 'repo', '仓库管理')}
470
471
  {waitingCount > 0 && (
@@ -341,3 +341,27 @@
341
341
  @media (max-width:720px){
342
342
  .mdw-block-rail{left:auto;right:0;top:-10px}
343
343
  }
344
+
345
+ /* ─── 模板生成的任务:骨架只读 / 插槽可编辑(#217)──────────────────────
346
+ 判定来自 modules/md/template-locks.ts(纯派生),这里只负责「看得出区别」:
347
+ 骨架块左侧一道实线 + 极淡底,鼠标不是文本光标;插槽块左侧虚线(这里才是要填的)。
348
+ 徽标默认不显示,悬停才出——常驻角标会让整页像调试视图。 */
349
+ .mdw-lp-block.is-locked{
350
+ padding-left:10px;
351
+ cursor:default;
352
+ box-shadow:inset 3px 0 0 var(--line-strong,#C9C6BE);
353
+ background:linear-gradient(90deg, rgba(22,24,28,.05), transparent 40%);
354
+ }
355
+ .mdw-lp-block.is-slot{
356
+ padding-left:10px;
357
+ box-shadow:inset 2px 0 0 var(--mdw-accent-line,#B7D4C8);
358
+ }
359
+ .mdw-lp-lock,.mdw-lp-slot{
360
+ position:absolute;right:0;top:0;
361
+ font:500 9.5px/1.6 system-ui,-apple-system,sans-serif;
362
+ padding:0 6px;border-radius:999px;
363
+ border:1px solid var(--line,#E4E2DC);background:var(--soft,#F1F0EC);color:var(--mid,#8A8578);
364
+ opacity:0;transition:opacity .12s;pointer-events:none;user-select:none;
365
+ }
366
+ .mdw-lp-slot{color:var(--mdw-accent,#2F6F5E);border-color:var(--mdw-accent-line,#B7D4C8);background:var(--mdw-accent-soft,#E8F2EE)}
367
+ .mdw-lp-block:hover .mdw-lp-lock,.mdw-lp-block:hover .mdw-lp-slot{opacity:1}
@@ -340,13 +340,25 @@ button.cmp-quote:focus-visible{outline:2px solid var(--mdw-accent-line,#B7D4C8);
340
340
  }
341
341
  /* 工具栏/纸面自适应走容器查询:随编辑列实际宽度分级折叠——
342
342
  640 纸面紧凑(#78 后动作区只剩 新任务/提交/更多,无需再按宽收动作)。
343
- 此前用视口媒体查询,进程 rail 一开窄列就静默裁掉按钮( overflow:hidden 兜底) */
343
+ 此前用视口媒体查询,进程 rail 一开窄列就静默裁掉按钮( overflow:hidden 兜底)。
344
+ 2026-11-16「太挤了」:窄列只收纸面 padding 不够——大标题、标题字号、块距、
345
+ 代码块都要跟着收,整页节奏才回来;全部写在块容器/纸面层,不破坏 #31 的
346
+ 视图↔编辑等高约束 */
344
347
  @container mdwmain (max-width: 960px){
345
348
  .mdw-lp-sheet,.mdw-reader{padding:20px 22px 56px}
349
+ .mdw-lp input.mdw-lp-title,.mdw-lp textarea.mdw-lp-title,.mdw-reader-title{font-size:24px;margin-bottom:22px}
346
350
  }
347
351
  @container mdwmain (max-width: 640px){
348
352
  .mdw-lp-sheet,.mdw-reader{padding:16px 16px 48px}
349
- .mdw-lp input.mdw-lp-title,.mdw-lp textarea.mdw-lp-title,.mdw-reader-title{font-size:24px}
353
+ .mdw-lp input.mdw-lp-title,.mdw-lp textarea.mdw-lp-title,.mdw-reader-title{font-size:20px;margin-bottom:14px}
354
+ .mdw-lp-view h1,.mdw-preview h1{font-size:18px}
355
+ .mdw-lp-view h2,.mdw-preview h2{font-size:15px}
356
+ .mdw-lp-view pre,.mdw-preview pre{margin:6px 0;padding:8px 10px;font-size:11.5px;line-height:1.5}
357
+ /* 块距收一档(块容器承担,视图↔编辑仍等高) */
358
+ .mdw-lp-block.kind-h1{padding-top:6px;padding-bottom:10px}
359
+ .mdw-lp-block.kind-h2{padding-top:10px;padding-bottom:8px}
360
+ .mdw-lp-block.kind-h3{padding-top:8px;padding-bottom:8px}
361
+ .mdw-lp-gap{min-height:1.2em}
350
362
  }
351
363
 
352
364
  /* 快捷键速查面板:外壳走 popup/Modal(pp-card pp-lg + .mdw-sheet 追加类),