dsh-tiddlywiki 0.3.1 → 0.4.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.
package/README.md CHANGED
@@ -1,212 +1,258 @@
1
- # dsh-tiddlywiki
2
-
3
- TiddlyWiki 5 as the DSH **persistent knowledge base**. Agent can read/write
4
- tiddlers through `tiddlywiki_*` tools; the human edits in a full TiddlyWiki
5
- editor embedded in the GUI center column; the chat area gets a floating
6
- quick-note widget. Data syncs/backs up through **git**; configuration moves
7
- between machines through **dsh-market**.
8
-
9
- > 设计文档:`notes/dsh-tiddlywiki-plugin-design.md`(已锁定)。本 README 是安装/配置/使用/发布要点。
10
-
11
- ---
12
-
13
- ## 为什么做这个(初衷)
14
-
15
- agent 干活的时候,人常是干坐着的——想随手写点什么,又不想切来切去:开个便签、再切到笔记软件、再切回来,思路早断了。市面上没找到一款专门给这种「陪跑式摸鱼」用的 DSH 插件;去联动别的笔记软件,又总觉得隔了一层、动静太大。
16
-
17
- TiddlyWiki 的特性正好合适:单文件、纯文本、wiki 语法、自带 git 同步,天生适合**随手写点小东西**。于是把它做成 DSH 的原生插件——不用离开当前界面,聊天区右下角就有个快速笔记,想写就写;要正经编辑,弹出 TW 原生编辑器;写下的东西自动进 git,既是知识库也是备份。
18
-
19
- ---
20
-
21
- ## 它能做什么
22
-
23
- | 能力 | 说明 |
24
- |---|---|
25
- | Agent 工具 | `tiddlywiki_search` / `get` / `put` / `delete` / `git_sync` |
26
- | 人编辑 | 侧边栏「TiddlyWiki」入口 → 中央列内嵌完整 TW 编辑器(iframe 直连 TW 服务) |
27
- | 快速笔记 | 聊天区右下角常驻悬浮控件(可折叠,**Markdown 语法高亮**、**文件上传**、可多选/自动补全 tag,Ctrl+Enter 保存;设置页可整体隐藏) |
28
- | 一键同步 | 右下角「同步」悬浮按钮 + 设置页「同步」按钮:点一下 pull → commit → push;按钮状态点实时反映 git 状态(待提交/可更新/已同步),可配置隐藏 |
29
- | 零摩擦生命周期 | dsh 自动启动/关闭;TW 子进程崩溃自动重启(退避);端口/目录/首次 git init 全自动 |
30
- | 同步 | 单线程交替模型:开工 pull,收工 commit+push,自动 commit(60s 防抖,可关) |
31
-
32
- ## 安装
33
-
34
- 插件随 dsh 插件系统安装,三种方式任选(装完**重启 dsh web** 生效;把 `--profile web` 换成你自己的 profile 名):
35
-
36
- ```bash
37
- # ① npm 发布包(推荐)
38
- dsh plugin --profile web add dsh-tiddlywiki
39
-
40
- # ② 直接从 GitHub 安装(需要 git;仓库已含预构建的 lib,开箱即用)
41
- dsh plugin --profile web add github:bbqisbbq/dsh-tiddlywiki
42
-
43
- # ③ 本地开发 / 改源码(link 方式:改完 src 后 npm run build 即生效,免重装)
44
- dsh plugin --profile web add link:C:\Users\bbq\.dsh\plugins\dsh-tiddlywiki
45
- ```
46
-
47
- 首次启动会向 wiki **写入一次**「dsh-tiddlywiki 插件说明」笔记(tag `docs`)。
48
-
49
- ## 发布 / 仓库
50
-
51
- - **GitHub(公开)**:https://github.com/bbqisbbq/dsh-tiddlywiki
52
- - **npm**:`dsh-tiddlywiki`(`npm i dsh-tiddlywiki`;https://www.npmjs.com/package/dsh-tiddlywiki
53
- - **说明笔记**:插件在**首次启动**时向 wiki **写入一次**「`dsh-tiddlywiki 插件说明`」笔记(tag `docs`)——只写一次、手动编辑不被覆盖、**删除后重启不会自动恢复**(一次性标记;清空 wiki 重装会再写入)。当前 live wiki 里已有一份。
54
-
55
- ## 可被检索的标准字段
56
-
57
- 为方便 GitHub / npm / 搜索引擎发现,包与仓库带以下标准元数据:
58
-
59
- | 字段 | 值 |
60
- |---|---|
61
- | npm 包名 | `dsh-tiddlywiki` |
62
- | npm `keywords` | `dsh` `dsh-plugin` `tiddlywiki` `knowledge-base` `note-taking` `notes` `wiki` `git-sync` `agent-tools` `plugin` |
63
- | GitHub topics | `dsh` `dsh-plugin` `tiddlywiki` `wiki` `knowledge-base` `knowledge-management` `note-taking` `notes` `second-brain` `productivity` `git` `git-sync` `plugin` `agent` `agent-tools` `ai` `typescript` `nodejs`(共 18 个) |
64
- | `description` | 见 package.json(一句话说明插件的用途) |
65
- | `license` | MIT |
66
- | `homepage` / `repository` / `bugs` | 均指向 https://github.com/bbqisbbq/dsh-tiddlywiki |
67
-
68
- > GitHub topics 规范([官方文档](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics)):仅小写字母/数字/连字符、≤50 字符、每仓库 ≤20 个;用官方 **Replace all repository topics** 端点(`PUT /repos/{owner}/{repo}/topics`)设置。上表已按此执行并覆盖「用途 / 主题 / 语言 / 技术栈」。
69
-
70
- ## 配置
71
-
72
- 插件行默认如下(缺省即用默认值,无需手动配置)。如需自定义,编辑
73
- `profiles/web/cordis.patch.yml` profile bundle 层,给该行加 `config:`:
74
-
75
- ```yaml
76
- - id: dsh-tiddlywiki
77
- name: dsh-tiddlywiki
78
- config:
79
- wikiRoot: "$DSH_HOME/tiddlywiki" # 缺省自动展开
80
- wiki: "main"
81
- port: 0 # 0 = 自动探测空闲端口
82
- git:
83
- autoCommit: true
84
- debounceMs: 60000
85
- remote: "" # = 仅本地 commit;填了才 push
86
- branch: "main"
87
- note:
88
- tag: "inbox"
89
- ui:
90
- showQuickNote: true # 是否显示右下角「快速笔记」按钮
91
- showPanelStatus: true # 是否显示 TW 面板右下角「状态/重载」悬浮按钮
92
- showSyncButton: true # 是否显示右下角「同步」悬浮按钮
93
- auth:
94
- username: "" # 默认 loopback 匿名;暴露到非 loopback 时才需要
95
- password: ""
96
- ```
97
-
98
- `config:` 块随 profile 被 dsh-market 带走;wiki 数据(`$DSH_HOME/tiddlywiki`)
99
- git,不走 dsh-market。
100
-
101
- > 运行时配置:设置页(见「设置页」)写入的 `$:/plugins/dsh-tiddlywiki/config`
102
- > tiddler `config:` 块之上的覆盖层(tiddler 优先、随 wiki git 同步)。
103
- > 无需改动 cordis 也能改 note tag / git 开关 / ui 开关等。
104
-
105
- ## 使用
106
-
107
- ### Agent(工具)
108
-
109
- - `tiddlywiki_search {query, tag?}` — 检索非系统 tiddler,返回标题/标签/摘要。
110
- - `tiddlywiki_get {title}` — 读单个 tiddler 全文。
111
- - `tiddlywiki_put {title, text, tags?, fields?}` 写/覆盖 tiddler。
112
- - `tiddlywiki_delete {title}` — 删除 tiddler。
113
- - `tiddlywiki_git_sync {action: pull|push|sync, message?}` git 操作。
114
-
115
- 同步纪律(三条):开工先 `pull --rebase --autostash`;收工 `commit + push`;
116
- 自动 commit 防抖 60s。真冲突 → abort 并报冲突文件,agent 人工处理,不自动吞数据。
117
- **pull 若拉到新内容,`action=pull`/`sync` 会自动重启 TW(同端口)**,后续读写/搜索
118
- 均为最新快照,不会读到旧缓存。
119
-
120
- ### 人(GUI)
121
-
122
- - 侧边栏「TiddlyWiki」按钮开关中央编辑器面板。
123
- - 右下角「快速笔记」悬浮控件:写草稿/随手记,**Markdown 语法高亮**(打字即高亮标题/代码/粗斜体/链接等),支持**文件上传**(点「📎 上传」或直接把文件拖进编辑器——文件存到 wiki 的 `files/` 文件夹并随 git 同步,图片插入 `![名](/files/名)`、其它文件插入 `[名](/files/名)`,在 TW 里可直接打开),Ctrl+Enter 保存为独立 tiddler;笔记的 `type` **自动设为 `text/markdown`**,所以上传的图片/链接在 TW 里按 Markdown 正常渲染(而不是显示原始 `![..]` 文本),「在 TW 中编辑」保存后也保持该类型;
124
- 或点「**✏️ TW 中编辑**」——保存后**弹出独立小窗**(可拖动/缩放)加载 TiddlyWiki **原生编辑器**编辑该条。
125
- - 右下角「**同步**」悬浮按钮:点一下对 wiki 仓库做 **pull → commit → push**,按钮上的状态点实时反映 git 状态(🟢 已同步 / 🟡 有未提交改动 / 🔴 落后于远端 / ⚪ 离线),悬停可看分支/领先/落后/上次同步时间;每 30s 自动刷新。
126
- 若这次 pull 实际拉到了新内容,**TW 服务会自动重启(同端口)**,保证界面显示的是最新快照而不是旧缓存(无需手动去面板点「重启 TW」)。
127
- - 面板服务异常时显示错误 +「重试」按钮(POST `/dsh-tiddlywiki/restart`)。
128
-
129
- ### 设置页(插件/主题管理 + 配置)
130
-
131
- DSH **设置 TiddlyWiki 知识库** 是插件的配置面板(`settings.section`):
132
-
133
- | 区块 | 内容 |
134
- |---|---|
135
- | 状态/重启 | TW 运行状态 + git 概览 + 「**同步**」按钮(pull→commit→push)+ 「重启 TW」按钮 |
136
- | 常规配置 | 快速笔记默认 tag、git 自动 commit/防抖/远端/分支、**ui 开关**(快速笔记/面板状态/同步按钮)——改了什么保存什么 |
137
- | 插件管理 | 自带官方插件勾选(可搜索)→ 应用并自动重启 TW |
138
- | 主题管理 | 自带主题**多选加载 + 单选活动** → 应用并自动重启 TW |
139
- | 语言管理 | 自带官方语言包勾选(含 zh-Hans/zh-CN 简体)→ 应用并自动重启 TW |
140
-
141
- - 配置写入 wiki 内的 `$:/plugins/dsh-tiddlywiki/config` tiddler(JSON),随 git 同步;
142
- 作为 **cordis `config:` 块之上的覆盖层**(tiddler 优先),以后加配置项只需扩展该对象。
143
- - git 类配置修改后在 **重启 dsh web 后生效**(bootstrap 时读取)。
144
- - 插件/主题/语言均只管理 tiddlywiki 包**自带**的官方清单(`plugins/tiddlywiki/*`、
145
- `themes/tiddlywiki/*`、包根 `languages/*`),全部离线、官方原版。
146
- - **主题机制(重点)**:TW 视觉主题由 **`$:/theme`** tiddler 决定(浏览器 themeManager),
147
- `info.themes` 只决定**加载哪些主题插件**。主题之间有**依赖链**
148
- (`plugin.info` 的 `dependents`):`vanilla ← snowwhite ← heavier/centralised/readonly/starlight`,
149
- `vanilla ← tight/seamless`。设置页因此是**两层**:每行主题一个 `☑ 加载`(多选,
150
- = TW 里可用的主题)加一个 `◉ 活动`(单选 = 当前视觉主题)。应用时插件会:
151
- 1. 把加载集(含所选活动主题)的**完整依赖链**写入 `info.themes`(如 heavier
152
- `[vanilla, snowwhite, heavier]`),否则激活 heavier 时会丢掉 70KB 的 vanilla 基座样式;
153
- 2. 把 **`$:/theme` 设为所选活动主题**(激活它),然后重启 TW。
154
- 样式为空壳的主题(如本版 tight-heavier)会自动从清单里隐藏,避免选了没效果。
155
-
156
- ### 界面语言(中文)
157
-
158
- TW 的界面语言由**语言插件**决定,不是某个配置字符串。tiddlywiki 包在
159
- `node_modules/tiddlywiki/languages/` 下**自带全部官方语言包**(zh-Hans 简体、zh-CN、
160
- zh-Hant、en-GB、ja-JP…),本插件离线启用即可:
161
-
162
- - **设置 → TiddlyWiki 知识库 → 语言管理**:勾选 `zh-Hans`(简体)→「应用语言(重启 TW)」。
163
- 插件会把它写入 `tiddlywiki.info` 的 `languages` 数组,并固定 `$:/language` 为
164
- `$:/languages/zh-Hans`,重启后 TW 界面即变为简体中文(已持久化,重启仍在)。
165
- - **配置自动应用**:在设置页常规配置里写入 `uiLanguage: "zh-Hans"`,每次启动 dsh web
166
- 自动启用该语言并固定 `$:/language`(若尚未启用)。留空则不干预。
167
- - 中文包缺字/想换繁中:语言管理里改勾 `zh-Hant` 或 `zh-TW` 再应用即可。
168
-
169
- ## 开发
170
-
171
- ```bash
172
- npm install
173
- npm run typecheck # tsc --noEmit
174
- npm run build # clean + host tsdown + client tsdown + wrap
175
- npm run selftest # headless:spawn TW → REST 读写 → git → 退出回收
176
- ```
177
-
178
- 产物约定(§4.4 教训,发布必守):`lib/` 内**零** `@deepseek-ai` 运行时 import
179
- (`src/sdk.ts` 自实现 `defineTool` / `dshHomePath`,类型用结构接口)。
180
- 发布前用 `grep -r "@deepseek-ai" lib/` 验证。
181
-
182
- ## 发布
183
-
184
- ```bash
185
- # 版本号在 package.json;文件白名单见 files 字段
186
- npm publish
187
- ```
188
-
189
- `tiddlywiki` 依赖体较大(含全部语言包/插件),发布文档需注明。
190
-
191
- ## 结构
192
-
193
- ```
194
- src/
195
- ├── index.ts # host 入口:装配 WikiServer/路由/工具/prompt/自动 commit
196
- ├── sdk.ts # 自包含 defineTool + dshHomePath(零 @deepseek-ai 运行时依赖)
197
- ├── host/
198
- │ ├── wiki.ts # WikiServer:spawn/kill/自愈/端口探测/就绪轮询
199
- │ ├── tw-api.ts # TiddlyWeb REST 客户端
200
- │ ├── git.ts # git init/commit/pull/push/sync/status + AutoCommitter
201
- │ ├── routes.ts # /status /note /restart /api/* 路由
202
- │ ├── admin.ts # 设置页后台:tiddlywiki.info 读写 + 目录枚举 + /admin/* 路由
203
- │ ├── config.ts # ConfigStore:cordis config 基底 + 配置 tiddler 覆盖层
204
- │ └── tools.ts # 5 个工具(列表式注册,可扩展)
205
- └── client/
206
- ├── index.ts # client 入口(纯 DOM + settings.section 注册,永不 throw)
207
- ├── styles.ts / state.ts / toast.ts
208
- ├── sidebar-entry.ts # 侧边栏入口
209
- ├── panel.ts # 中央列 iframe 面板(fixed 覆盖层,钉住整列)
210
- ├── note-widget.ts # 悬浮快速笔记
211
- └── settings-page.ts # 设置页(插件/主题/语言管理 + 常规配置)
212
- ```
1
+ # dsh-tiddlywiki
2
+
3
+ > TiddlyWiki 5 as the DSH **persistent knowledge base** a shared long-term memory for AI and human: the agent reads/writes tiddlers through `tiddlywiki_*` tools, you edit in a full TiddlyWiki editor or jot notes in a floating widget, and everything syncs/backs up through **git**.
4
+
5
+ [![npm](https://img.shields.io/npm/v/dsh-tiddlywiki)](https://www.npmjs.com/package/dsh-tiddlywiki)
6
+ [![license](https://img.shields.io/npm/l/dsh-tiddlywiki)](https://github.com/bbqisbbq/dsh-tiddlywiki/blob/main/LICENSE)
7
+ [![GitHub](https://img.shields.io/github/stars/bbqisbbq/dsh-tiddlywiki)](https://github.com/bbqisbbq/dsh-tiddlywiki)
8
+
9
+ Agent 干活的时候,人常是干坐着的——想随手写点什么,又不想切来切去。TiddlyWiki 单文件、纯文本、wiki 语法、自带 git 同步,天生适合**随手写点小东西**。于是把它做成 DSH 原生插件:不用离开当前界面,聊天区右下角就有快速笔记;要正经编辑,弹出 TW 原生编辑器;写下的内容自动进 git,既是知识库也是备份。
10
+
11
+ ---
12
+
13
+ ## ✨ 特性一览
14
+
15
+ | 能力 | 说明 |
16
+ |---|---|
17
+ | 🤖 **Agent 工具** | `tiddlywiki_search` / `get` / `put` / `delete` / `git_sync` 五个工具:检索、读写、删除、git 同步 |
18
+ | 🧭 **内嵌编辑器** | 侧边栏「TiddlyWiki」入口 → 中央列内嵌完整 TW 5 编辑器(iframe 直连 TW 服务) |
19
+ | 📝 **快速笔记** | 聊天区右下角悬浮控件:**CodeMirror 6** Markdown 编辑器(语法高亮 + 撤销/重做)、文件上传、多选/自动补全 tag,Ctrl+Enter 保存;可整体隐藏 |
20
+ | 🔄 **一键同步** | 右下角「同步」按钮:pull → commit → push;状态点实时反映 git 状态(已同步/待提交/可更新/离线) |
21
+ | ⚙️ **设置页** | DSH 设置 →「TiddlyWiki 知识库」:插件/主题/语言管理与运行配置,应用后自动重启 TW |
22
+ | 🛡 **零摩擦生命周期** | 随 dsh 自动启停;TW 子进程崩溃自动重启(退避);端口/目录/首次 git init 全自动 |
23
+ | 💾 **数据即备份** | wiki 文件夹本身就是一个 git 仓库;自动 commit(60s 防抖,可关),配置随 dsh-market 迁移 |
24
+
25
+ ---
26
+
27
+ ## 📦 安装
28
+
29
+ 插件随 dsh 插件系统安装,三种方式任选(装完**重启 dsh web** 生效;把 `--profile web` 换成你自己的 profile 名):
30
+
31
+ ```bash
32
+ # ① npm 发布包(推荐)
33
+ dsh plugin --profile web add dsh-tiddlywiki
34
+
35
+ # ② 直接从 GitHub 安装(需要 git;仓库已含预构建 lib,开箱即用)
36
+ dsh plugin --profile web add github:bbqisbbq/dsh-tiddlywiki
37
+
38
+ # 本地开发 / 改源码(link 方式:改完 src 后 npm run build 即生效,免重装)
39
+ dsh plugin --profile web add link:/path/to/your/dsh-tiddlywiki
40
+ ```
41
+
42
+ 首次启动会自动完成三件事:**初始化 wiki 目录**、**`git init` 并提交基线**、向 wiki **写入一次**「dsh-tiddlywiki 插件说明」笔记(tag `docs`)。
43
+
44
+ ---
45
+
46
+ ## 🚀 快速开始(2 分钟上手)
47
+
48
+ 1. **安装并重启** dsh web(见上)。
49
+ 2. 点左侧侧边栏「**TiddlyWiki**」→ 中央打开完整 TW 编辑器;此时右下角已有「📝 快速笔记」和「🔄 同步」两个悬浮按钮。
50
+ 3. **随手记**:点右下角「快速笔记」,写两行、打上 tag,`Ctrl+Enter` 保存——它成为一个独立 tiddler,并自动进入 git。
51
+ 4. **正经排版**:在笔记里点「✏️ 在 TW 中编辑」,弹出 TW 原生编辑器小窗继续写。
52
+ 5. **收工同步**:点右下角「同步」按钮,一键 pull commit → push,把今天的记录推到远端备份。
53
+ 6. **让 Agent 参与**:直接在聊天里说「把刚才的会议纪要存进知识库」——Agent 会用 `tiddlywiki_*` 工具读写。
54
+
55
+ > 想直接看 Agent 侧完整能力?跳到 [📖 使用指南](#-使用指南)。
56
+
57
+ ---
58
+
59
+ ## 📖 使用指南
60
+
61
+ ### 🤖 Agent:5 个工具
62
+
63
+ | 工具 | 参数 | 说明 |
64
+ |---|---|---|
65
+ | `tiddlywiki_search` | `query`, `tag?` | 检索非系统 tiddler,返回标题/标签/摘要 |
66
+ | `tiddlywiki_get` | `title` | 读单个 tiddler 全文 |
67
+ | `tiddlywiki_put` | `title`, `text`, `tags?`, `fields?` | 写/覆盖 tiddler;`fields` 可带业务字段(如 `{"type":"meeting","date":"2026-09-02"}`) |
68
+ | `tiddlywiki_delete` | `title` | 删除 tiddler(幂等) |
69
+ | `tiddlywiki_git_sync` | `action: pull\|push\|sync`, `message?` | git 操作 |
70
+
71
+ **知识库同步纪律(三条)**:
72
+
73
+ 1. 开工先 `tiddlywiki_git_sync action=pull`(rebase + autostash;真冲突会自动 abort 并报冲突文件)。
74
+ 2. 收工 `tiddlywiki_git_sync action=sync`(pull → commit → push)。
75
+ 3. 插件自动 commit 兜底(60s 防抖,可关),手动 sync 用于需要主动推送的场合。
76
+
77
+ > ⚠️ pull 若拉到新内容,`pull` / `sync` 会自动**重启 TW(同端口)**,后续读写/搜索都是最新快照,不会读到旧缓存。
78
+
79
+ **建议**:把 wiki 当作长期记忆库——会议纪要、决策记录、调研笔记、随手的想法都可存成独立 tiddler(tag 建议 `inbox` / `meeting` / `decision` 等便于检索);自动建笔记时,除业务 tag 外也带上**当前 workspace 名**,方便按项目归集。
80
+
81
+ ### 🧑‍💻 给人:界面操作
82
+
83
+ **🧭 中央列编辑器** — 侧边栏「TiddlyWiki」按钮开关中央编辑器面板(iframe 直连 TW 服务),完整 TW 5 编辑器。
84
+
85
+ **📝 快速笔记** 聊天区右下角悬浮控件(可折叠):
86
+ - **CodeMirror 6 编辑器**:真正的 Markdown 语法树高亮(标题/列表/代码/链接/表格/任务清单/删除线等,GFM),支持撤销/重做与行内编辑体验;
87
+ - **文件上传**:点「📎 上传」或直接把文件拖进编辑器——文件存到 wiki 的 `files/` 文件夹并随 git 同步;图片插入 `![名](/files/名)`、其它文件插入 `[名](/files/名)`,在 TW 里可直接打开;
88
+ - **Ctrl+Enter 保存**为独立 tiddler;笔记 `type` 自动设为 `text/markdown`,所以上传的图片/链接在 TW 里按 Markdown 正常渲染;
89
+ - 点「**✏️ 在 TW 中编辑**」→ 保存后弹出**独立小窗**(可拖动/缩放)加载 TW 原生编辑器编辑该条。
90
+
91
+ **🔄 一键同步** 右下角「同步」悬浮按钮:点一下做 pull → commit → push,按钮上的状态点实时反映 git 状态:
92
+ 🟢 已同步 · 🟡 有未提交改动 · 🔴 落后于远端 · ⚪ 离线;悬停可看分支/领先/落后/上次同步时间;每 30s 自动刷新。
93
+ 若这次 pull 拉到了新内容,TW 服务自动重启(同端口),界面立即显示最新快照(无需手动去面板点「重启 TW」)。
94
+
95
+ **🔧 面板异常** — 面板服务异常时显示错误 +「重试」按钮(POST `/dsh-tiddlywiki/restart`)。
96
+
97
+ ### ⚙️ 设置页(DSH 设置 →「TiddlyWiki 知识库」)
98
+
99
+ | 区块 | 内容 |
100
+ |---|---|
101
+ | 状态/重启 | TW 运行状态 + git 概览 + 「同步」按钮 + 「重启 TW」按钮 |
102
+ | 常规配置 | 快速笔记默认 tag、git 自动 commit/防抖/远端/分支、ui 开关(快速笔记/面板状态/同步按钮)——改了什么保存什么 |
103
+ | 插件管理 | 自带官方插件勾选(可搜索)→ 应用并自动重启 TW |
104
+ | 主题管理 | 自带主题**多选加载 + 单选活动** → 应用并自动重启 TW |
105
+ | 语言管理 | 自带官方语言包勾选(含 zh-Hans 简体)→ 应用并自动重启 TW |
106
+
107
+ - 配置写入 wiki 内的 `$:/plugins/dsh-tiddlywiki/config` tiddler(JSON),随 git 同步,作为 **cordis `config:` 块之上的覆盖层**(tiddler 优先)。
108
+ - git 类配置修改后**重启 dsh web 生效**(bootstrap 时读取)。
109
+ - 插件/主题/语言只管理 tiddlywiki 包**自带**的官方清单(`plugins/tiddlywiki/*`、`themes/tiddlywiki/*`、包根 `languages/*`),全部离线、官方原版。
110
+
111
+ **主题机制(重点)**:TW 视觉主题由 **`$:/theme`** tiddler 决定,`info.themes` 只决定**加载哪些主题插件**。主题之间有**依赖链**(`plugin.info` `dependents`):`vanilla ← snowwhite ← heavier/centralised/readonly/starlight`,`vanilla ← tight/seamless`。设置页因此是**两层**:每行主题一个 `☑ 加载`(多选 = TW 里可用的主题)+ `◉ 活动`(单选 = 当前视觉主题)。应用时插件会:
112
+
113
+ 1. 把加载集(含所选活动主题)的**完整依赖链**写入 `info.themes`(如 heavier `[vanilla, snowwhite, heavier]`),否则激活 heavier 时会丢掉 70KB 的 vanilla 基座样式;
114
+ 2. 把 **`$:/theme`** 设为所选活动主题,然后重启 TW。
115
+
116
+ 样式为空壳的主题(如 tight-heavier)会自动从清单里隐藏,避免选了没效果。
117
+
118
+ ### 🌐 界面语言(中文)
119
+
120
+ TW 的界面语言由**语言插件**决定,不是某个配置字符串。tiddlywiki 包自带全部官方语言包(`node_modules/tiddlywiki/languages/`,含 zh-Hans 简体、zh-CN、zh-Hant、en-GB、ja-JP…),本插件离线启用即可:
121
+
122
+ - **设置页 → 语言管理**:勾选 `zh-Hans`(简体)→「应用语言(重启 TW)」——写入 `tiddlywiki.info` 的 `languages` 数组并固定 `$:/language` 为 `$:/languages/zh-Hans`,重启后 TW 界面即简体中文(持久化,重启仍在)。
123
+ - **配置自动应用**:在常规配置写入 `uiLanguage: "zh-Hans"`,每次启动 dsh web 时自动启用该语言并固定 `$:/language`(若尚未启用)。留空则不干预。
124
+ - **想换繁中**:语言管理里改勾 `zh-Hant` / `zh-TW` 再应用。
125
+
126
+ ---
127
+
128
+ ## 🔄 同步与数据
129
+
130
+ - wiki 文件夹**本身就是一个 git 仓库**(默认 `$DSH_HOME/tiddlywiki`,`wiki` 子目录为内容)。插件自动维护 `.gitignore`(忽略 TW 临时文件)与自动 commit(默认 60s 防抖)。
131
+ - **同步模型**:单线程交替——开工 `pull`,收工 `commit + push`;冲突策略是 **rebase + autostash,真冲突 abort 并报文件**,绝不自动吞数据。
132
+ - 配置远端(`git.remote`)后,插件首次启动会 `ensureRemote` 并尝试首次 push;失败可稍后用 `tiddlywiki_git_sync` 或「同步」按钮重试。
133
+ - **插件配置**(`config` tiddler)随 wiki 的 git 同步;**插件本体**(cordis 行与配置块)随 profile 被 dsh-market 带走。
134
+
135
+ ---
136
+
137
+ ## 🛠 配置
138
+
139
+ 插件行默认如下(缺省即用默认值,无需手动配置)。如需自定义,编辑 `profiles/web/cordis.patch.yml` profile bundle 层,给该行加 `config:`:
140
+
141
+ ```yaml
142
+ - id: dsh-tiddlywiki
143
+ name: dsh-tiddlywiki
144
+ config:
145
+ wikiRoot: "$DSH_HOME/tiddlywiki" # 缺省自动展开
146
+ wiki: "main"
147
+ port: 0 # 0 = 自动探测空闲端口
148
+ git:
149
+ autoCommit: true
150
+ debounceMs: 60000
151
+ remote: "" # = 仅本地 commit;填了才 push
152
+ branch: "main"
153
+ note:
154
+ tag: "inbox"
155
+ ui:
156
+ showQuickNote: true # 是否显示右下角「快速笔记」按钮
157
+ showPanelStatus: true # 是否显示 TW 面板右下角「状态/重载」悬浮按钮
158
+ showSyncButton: true # 是否显示右下角「同步」悬浮按钮
159
+ auth:
160
+ username: "" # 默认 loopback 匿名;暴露到非 loopback 时才需要
161
+ password: ""
162
+ ```
163
+
164
+ > **运行时配置**:设置页写入的 `$:/plugins/dsh-tiddlywiki/config` tiddler 是 `config:` 块之上的覆盖层(tiddler 优先、随 wiki 的 git 同步)。无需改动 cordis 也能改 note tag / git 开关 / ui 开关等。
165
+ > `config:` 块随 profile 被 dsh-market 带走;wiki 数据走 git,不走 dsh-market。
166
+
167
+ ---
168
+
169
+ ## 👨‍💻 开发
170
+
171
+ 需要 **Node.js ≥ 22**(DSH 本身已满足)。
172
+
173
+ ```bash
174
+ npm install
175
+ npm run typecheck # tsc --noEmit
176
+ npm run build # clean + host tsdown + client tsdown + wrap
177
+ npm run selftest # headless:spawn TW → REST 读写 → git → 退出回收
178
+ ```
179
+
180
+ **产物约定**(发布必守):`lib/` 内**零** `@deepseek-ai` 运行时 import(`src/sdk.ts` 自实现 `defineTool` / `dshHomePath`,类型用结构接口)。发布前用 `grep -r "@deepseek-ai" lib/` 验证。
181
+
182
+ **客户端依赖**:快速笔记编辑器用 CodeMirror 6(`@codemirror/*`、`@lezer/*`)做 Markdown 高亮,构建时由 tsdown **打包进 `lib/client.bundle.js`**(它们放在 `devDependencies`,因为运行时用的是预构建 bundle,用户安装无需拉取)。「零依赖自研高亮」已成历史——浏览器端只要求构建产物自包含。
183
+
184
+ ### 路由参考(开发者)
185
+
186
+ 同源路由(走 DSH web server),Client 直连、无 CORS:
187
+
188
+ | 路由 | 方法 | 用途 |
189
+ |---|---|---|
190
+ | `/dsh-tiddlywiki/status` | GET | 面板健康(service / url / git / tag / ui) |
191
+ | `/dsh-tiddlywiki/note` | POST | 快速笔记 → 独立 tiddler |
192
+ | `/dsh-tiddlywiki/edit` | POST | 打开 TW 原生编辑器(draft) |
193
+ | `/dsh-tiddlywiki/tags` | GET | 现有非系统 tag(自动补全) |
194
+ | `/dsh-tiddlywiki/sync` | POST | 一键 pull → commit → push |
195
+ | `/dsh-tiddlywiki/upload` | POST | 文件上传到 `files/`(原始 body + `X-Filename`) |
196
+ | `/dsh-tiddlywiki/restart` | POST | 重启 TW 子进程 |
197
+ | `/dsh-tiddlywiki/api/*` | any | 透传到 TW 服务(JSON) |
198
+
199
+ ---
200
+
201
+ ## 📦 发布
202
+
203
+ ```bash
204
+ # 版本号在 package.json;文件白名单见 files 字段
205
+ npm publish
206
+ ```
207
+
208
+ `tiddlywiki` 依赖体较大(含全部语言包/插件),发布文档需注明。
209
+
210
+ ---
211
+
212
+ ## 🗂 项目结构
213
+
214
+ ```
215
+ src/
216
+ ├── index.ts # host 入口:装配 WikiServer/路由/工具/prompt/自动 commit
217
+ ├── sdk.ts # 自包含 defineTool + dshHomePath(零 @deepseek-ai 运行时依赖)
218
+ ├── host/
219
+ │ ├── wiki.ts # WikiServer:spawn/kill/自愈/端口探测/就绪轮询
220
+ │ ├── tw-api.ts # TiddlyWeb REST 客户端
221
+ │ ├── git.ts # git init/commit/pull/push/sync/status + AutoCommitter
222
+ │ ├── routes.ts # /status /note /edit /tags /sync /upload /restart /api/* 路由
223
+ │ ├── admin.ts # 设置页后台:tiddlywiki.info 读写 + 目录枚举 + /admin/* 路由
224
+ │ ├── config.ts # ConfigStore:cordis config 基底 + 配置 tiddler 覆盖层
225
+ │ ├── seed-notes.ts # 首次启动一次性写入「插件说明」笔记
226
+ │ └── tools.ts # 5 个工具(列表式注册,可扩展)
227
+ └── client/
228
+ ├── index.ts # client 入口(纯 DOM + settings.section 注册,永不 throw)
229
+ ├── styles.ts / state.ts / toast.ts
230
+ ├── sidebar-entry.ts # 侧边栏入口
231
+ ├── panel.ts # 中央列 iframe 面板(fixed 覆盖层,钉住整列)
232
+ ├── note-widget.ts # 悬浮快速笔记
233
+ ├── markdown-editor.ts # 快速笔记编辑器(CodeMirror 6 + Lezer Markdown 高亮)
234
+ ├── sync-button.ts # 一键同步悬浮按钮
235
+ ├── editor-popup.ts # 原生编辑器弹出小窗
236
+ └── settings-page.ts # 设置页(插件/主题/语言管理 + 常规配置)
237
+ ```
238
+
239
+ ---
240
+
241
+ ## 🔗 仓库与发布元数据
242
+
243
+ - **GitHub(公开)**:https://github.com/bbqisbbq/dsh-tiddlywiki
244
+ - **npm**:`dsh-tiddlywiki`(https://www.npmjs.com/package/dsh-tiddlywiki)
245
+ - **说明笔记**:插件在**首次启动**时向 wiki **写入一次**「`dsh-tiddlywiki 插件说明`」笔记(tag `docs`)——只写一次、手动编辑不被覆盖、**删除后重启不会自动恢复**(一次性标记;清空 wiki 重装会再写入)。
246
+
247
+ **可被检索的标准字段**(为 GitHub / npm / 搜索引擎发现):
248
+
249
+ | 字段 | 值 |
250
+ |---|---|
251
+ | npm 包名 | `dsh-tiddlywiki` |
252
+ | npm `keywords` | `dsh` `dsh-plugin` `tiddlywiki` `knowledge-base` `note-taking` `notes` `wiki` `git-sync` `agent-tools` `plugin` |
253
+ | GitHub topics | `dsh` `dsh-plugin` `tiddlywiki` `wiki` `knowledge-base` `knowledge-management` `note-taking` `notes` `second-brain` `productivity` `git` `git-sync` `plugin` `agent` `agent-tools` `ai` `typescript` `nodejs`(共 18 个) |
254
+ | `description` | 见 package.json(一句话说明插件的用途) |
255
+ | `license` | MIT |
256
+ | `homepage` / `repository` / `bugs` | 均指向 https://github.com/bbqisbbq/dsh-tiddlywiki |
257
+
258
+ > GitHub topics 规范([官方文档](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/classifying-your-repository-with-topics)):仅小写字母/数字/连字符、≤50 字符、每仓库 ≤20 个;用官方 **Replace all repository topics** 端点(`PUT /repos/{owner}/{repo}/topics`)设置。上表已按此执行并覆盖「用途 / 主题 / 语言 / 技术栈」。