saibo-kanban 0.0.0-stage → 0.2.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ ## 0.2.2
4
+
5
+ - 修正 `bin` 路径(去掉 `./`),npm 不再丢弃 CLI 入口。
6
+ - 首个 npm 版本(0.2.1 因暂存发布流程被撤回)。
7
+
8
+ ## 0.2.1
9
+
10
+ - 新增 CLI `saibo-board`(`bin/board.mjs`):`list / inbox / add / show / accept / unaccept /
11
+ archive / restore / update / search / brief`。人的操作走本地直写,不经过模型。
12
+ - `store.history(id)`:读取单条目的完整修订历史。
13
+
14
+ ## 0.2.0
15
+
16
+ - `core.js`:条目模型、类型/状态校验、状态机、字段级 diff、简报、检索。
17
+ - `store.js`:`$DSH_HOME/saibo_kanban/records.jsonl` 只追加台账;乐观锁(`expectedRev`);归档/恢复;
18
+ 合并与取代语义;重新加载按修订重放。
19
+ - `tools.js`:六个工具 `board_brief / board_record / board_update / board_supersede / board_merge / board_search`。
20
+ AI 只能字段级 patch、不能写 done、不能改确认状态。
21
+ - `test/run.mjs`:12 项自测,覆盖记录、冲突、状态机、接受、取代、合并、归档过滤、重放。
22
+
23
+ ## 0.1.0
24
+
25
+ - 骨架:`package.json`(bundle patch、exports、files、engines)、`cordis.patch.yml`、
26
+ 中英文 locale、图标、README、DETAIL、LICENSE、CHANGELOG。
27
+ - 尚未注册工具或界面,安装后不可用。
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 saibo_kanban contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,83 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # 赛博看板 / Saibo Kanban
2
+
3
+ 一个给 DeepSeek Harness 用的**活看�?*:AI 负责起草,人负责分拣,每次改动都有修订记录�?
4
+ > 当前版本 0.2.0:六个积木级工具已经可用(记�?/ 修改 / 取代 / 合并 / 检�?/ 简报)�?> 界面(收件箱 / 看板 / 表格)在 0.3.0 接入�?
5
+ ## 为什么做这个
6
+
7
+ - AI 写东西准确率 80�?0%,会漏、会改口。看板要能用,错的地方必�?*一眼看见、一秒改掉、随时能回滚**�?- 人没有填表的意愿,但有改和删的意愿。所以:**AI 写草�?�?收件�?�?人做接受/退�?合并/删除**,全程本地动作,不经过模型,不花 token�?- Excel 的问题不是「表格」,是没有行身份、字段约束和变更历史。看板就是一�?*有状态的智能表格**�?
8
+ ## 设计(三视图、三入口�?
9
+ - **收件�?*:AI 写的草稿都在这,人只做分拣�?- **看板**:拖拽换�?= 改状态;虚线�?= 待确认�?- **表格**:点单元格直接改;改一个字段不需要打开表单�?- **详情抽屉**:全字段 + 修订历史 + 来源(哪次会话、哪条消息)�?- 表单只出现在两个地方:新建(一行快加)和导入映射。没有全字段录入弹窗�?
10
+ 数据模型:条目带稳定 ID,每次写入都�?*新修�?*(字段级 diff、作者、来源),不是覆盖�?AI 只能字段�?patch,不能整条覆盖、不能标完成、不能物理删除——这些是代码闸,不是提示词约定�?
11
+ ## 安装
12
+
13
+ **npm(发布后�?*
14
+
15
+ ```bash
16
+ dsh plugin --profile web add saibo-kanban
17
+ ```
18
+
19
+ **GitHub 源码**
20
+
21
+ ```bash
22
+ dsh plugin --profile web add github:QuChen-D/saibo_kanban
23
+ ```
24
+
25
+ **本地开�?*
26
+
27
+ ```bash
28
+ dsh plugin --profile web add /absolute/path/to/saibo_kanban
29
+ ```
30
+
31
+ ## 数据
32
+
33
+ 存放�?`$DSH_HOME/saibo_kanban/records.jsonl`(只追加),可用 `config.dataDir` 改�?卸载插件不删除数据�?
34
+ ## 静态原�?
35
+ [`demo/index.html`](demo/index.html) 是产品手感的单文件原型:表格 / 看板 / 收件箱三视图�?就地编辑、拖拽、修订历史�? 秒撤销。不依赖任何构建,双击即开;数据只存在浏览�?localStorage�?
36
+ 它验证的�?0.3.0 要搬�?DSH 的交互,不是最终实现�?
37
+ ## 怎么用(现在就能用)
38
+
39
+ **1. 在对话里�?agent �?*
40
+
41
+ ```
42
+ 记一条:把导入改成列映射 + 预览
43
+ 看看板简�?找一下关于表单的条目
44
+ ```
45
+
46
+ agent 会调 `board_*` 工具。注意:AI 写进去的�?*待确认草�?*,要在收件箱里由人接受�?
47
+ **2. �?CLI(人的入口,0 token�?*
48
+
49
+ ```bash
50
+ node bin/board.mjs inbox # 看待确认
51
+ node bin/board.mjs accept <id> # 接受
52
+ node bin/board.mjs add "标题" --kind decision --scope 存储
53
+ node bin/board.mjs list # 全部条目
54
+ node bin/board.mjs show <id> # 详情 + 修订历史
55
+ node bin/board.mjs brief # 简报(只读已确认)
56
+ ```
57
+
58
+ 数据默认�?`$DSH_HOME/saibo_kanban/records.jsonl`,可�?`--data-dir` 或环境变�?`SAIBO_DATA_DIR` 指定�?
59
+ **3. 页面�?.3.0 接入�?*
60
+
61
+ 收件�?/ 看板 / 表格三视图,行为�?`demo/index.html` 一致�?
62
+ ## 工具
63
+
64
+ | 工具 | 作用 |
65
+ |---|---|
66
+ | `board_brief` | 读简报:按状态列出已确认条目,附待确认草稿数 |
67
+ | `board_record` | 写入一条草稿(默认待确认),进收件�?|
68
+ | `board_update` | 按字段改一条,必须�?`expectedRev` |
69
+ | `board_supersede` | 用新条目取代旧条目,旧条目保留并指向新条�?|
70
+ | `board_merge` | 合并两条以上,来源归档并指向新条�?|
71
+ | `board_search` | 按关键词 / 状�?/ 类型 / 范围检�?|
72
+
73
+ ## 路线�?
74
+ - [x] 0.1.0 骨架:manifest、patch、locale、图标、文�?- [x] 0.2.0 `core.js` + `store.js` + 六个工具
75
+ - [ ] 0.3.0 DSH �?React 页面(表�?看板/收件箱)
76
+ - [ ] 0.4.0 xlsx 导入(列映射 + 预览 + 冲突报告�?- [ ] 0.5.0 brief 注入与复用统�?
77
+ ## 开�?
78
+ ```bash
79
+ npm run check # 语法检�?npm test # 12 项自测(不依�?DSH�?```
80
+
81
+ ## License
82
+
83
+ MIT
package/bin/board.mjs ADDED
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 赛博看板的人机界面(CLI)。
4
+ *
5
+ * 这是「人」的入口:0 token、本地直写台账。页面做好之前先用它,
6
+ * 页面做好之后两者共用同一份 store 与规则。
7
+ *
8
+ * saibo-board list [--status todo] [--scope 看板插件] [--all]
9
+ * saibo-board inbox
10
+ * saibo-board add "标题" [--kind decision] [--scope 存储] [--body "正文"]
11
+ * saibo-board show <id>
12
+ * saibo-board accept <id> | unaccept <id>
13
+ * saibo-board archive <id> | restore <id>
14
+ * saibo-board update <id> [--title ...] [--status ...] [--kind ...] [--scope ...] [--body ...]
15
+ * saibo-board search <关键词>
16
+ * saibo-board brief [--scope ...]
17
+ */
18
+ import fs from 'node:fs';
19
+ import path from 'node:path';
20
+ import { Store, defaultDataDir } from '../store.js';
21
+ import { STATUSES, DEFAULT_KINDS, normalizeKinds } from '../core.js';
22
+
23
+ const argv = process.argv.slice(2);
24
+ const command = argv[0];
25
+ const positionals = [];
26
+ const flags = {};
27
+ for (let i = 1; i < argv.length; i += 1) {
28
+ const token = argv[i];
29
+ if (token.startsWith('--')) {
30
+ const key = token.slice(2);
31
+ const next = argv[i + 1];
32
+ if (next !== undefined && !next.startsWith('--')) {
33
+ flags[key] = next;
34
+ i += 1;
35
+ } else {
36
+ flags[key] = true;
37
+ }
38
+ } else {
39
+ positionals.push(token);
40
+ }
41
+ }
42
+
43
+ const kindLabel = id => (DEFAULT_KINDS.find(k => k.id === id) || { label: id }).label;
44
+ const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
45
+
46
+ function dataDir() {
47
+ return flags['data-dir'] || process.env.SAIBO_DATA_DIR || defaultDataDir();
48
+ }
49
+
50
+ function openStore() {
51
+ const store = new Store({ dataDir: dataDir(), kinds: normalizeKinds(null) }).load();
52
+ return store;
53
+ }
54
+
55
+ function printItem(item) {
56
+ const mark = item.verified ? '✓' : '◌';
57
+ const parts = [
58
+ item.id,
59
+ `r${item.rev}`,
60
+ statusLabel(item.status),
61
+ kindLabel(item.kind),
62
+ item.scope || '—',
63
+ `${mark} ${item.title}`
64
+ ];
65
+ if (item.archived) parts.push('(已归档)');
66
+ if (item.supersededBy) parts.push(`→ ${item.supersededBy}`);
67
+ console.log(parts.join(' '));
68
+ }
69
+
70
+ function usage() {
71
+ console.log(`赛博看板 CLI
72
+
73
+ list [--status <状态>] [--kind <类型>] [--scope <范围>] [--query <词>] [--all]
74
+ inbox
75
+ add <标题> [--kind <类型>] [--scope <范围>] [--body <正文>]
76
+ show <id>
77
+ accept <id> 把条目标为已确认
78
+ unaccept <id> 取消确认
79
+ archive <id> 归档(不删除)
80
+ restore <id> 撤销归档
81
+ update <id> [--title ...] [--status ...] [--kind ...] [--scope ...] [--body ...]
82
+ search <关键词>
83
+ brief [--scope <范围>]
84
+
85
+ 数据目录:${dataDir()}
86
+ `);
87
+ }
88
+
89
+ const store = openStore();
90
+
91
+ switch (command) {
92
+ case 'list': {
93
+ const result = store.list({
94
+ status: flags.status,
95
+ kind: flags.kind,
96
+ scope: flags.scope,
97
+ query: flags.query,
98
+ includeArchived: flags.all === true,
99
+ draft: flags.drafts === true ? true : undefined,
100
+ limit: 200
101
+ });
102
+ if (result.items.length === 0) {
103
+ console.log('(空)');
104
+ } else {
105
+ result.items.forEach(printItem);
106
+ console.log(`\n共 ${result.total} 条${result.truncated ? '(已截断)' : ''}`);
107
+ }
108
+ break;
109
+ }
110
+ case 'inbox': {
111
+ const result = store.list({ draft: true, limit: 200 });
112
+ if (result.items.length === 0) {
113
+ console.log('收件箱是空的。');
114
+ } else {
115
+ result.items.forEach(printItem);
116
+ console.log(`\n待确认 ${result.total} 条。用 accept <id> 接受,archive <id> 删除。`);
117
+ }
118
+ break;
119
+ }
120
+ case 'add': {
121
+ const title = positionals.join(' ');
122
+ if (!title) { usage(); process.exitCode = 1; break; }
123
+ const item = store.record({
124
+ title,
125
+ kind: flags.kind || 'task',
126
+ scope: flags.scope || '',
127
+ body: flags.body || ''
128
+ }, { by: 'human', verified: true, note: '人工添加' });
129
+ console.log(`已添加 ${item.id}(r${item.rev})`);
130
+ break;
131
+ }
132
+ case 'show': {
133
+ const id = positionals[0];
134
+ if (!id) { usage(); process.exitCode = 1; break; }
135
+ const item = store.get(id);
136
+ console.log(`${item.id} ${item.title}`);
137
+ console.log(` 类型 ${kindLabel(item.kind)} · 状态 ${statusLabel(item.status)} · 范围 ${item.scope || '—'} · ${item.verified ? '已确认' : '待确认'}${item.archived ? ' · 已归档' : ''}`);
138
+ if (item.body) console.log(`\n${item.body}`);
139
+ console.log('\n修订历史:');
140
+ for (const event of store.history(id)) {
141
+ const changes = Object.entries(event.changes)
142
+ .map(([field, pair]) => `${field}: ${pair.from || '∅'} → ${pair.to || '∅'}`)
143
+ .join(';');
144
+ console.log(` r${event.rev} ${event.time.slice(0, 16).replace('T', ' ')} ${event.by} ${event.note || ''}`);
145
+ if (changes) console.log(` ${changes}`);
146
+ }
147
+ break;
148
+ }
149
+ case 'accept':
150
+ case 'unaccept': {
151
+ const id = positionals[0];
152
+ if (!id) { usage(); process.exitCode = 1; break; }
153
+ store.setVerified(id, command === 'accept', { by: 'human' });
154
+ console.log(`${id} → ${command === 'accept' ? '已确认' : '待确认'}`);
155
+ break;
156
+ }
157
+ case 'archive':
158
+ case 'restore': {
159
+ const id = positionals[0];
160
+ if (!id) { usage(); process.exitCode = 1; break; }
161
+ if (command === 'archive') store.archive(id, { by: 'human' });
162
+ else store.restore(id, { by: 'human' });
163
+ console.log(`${id} → ${command === 'archive' ? '已归档' : '已恢复'}`);
164
+ break;
165
+ }
166
+ case 'update': {
167
+ const id = positionals[0];
168
+ if (!id) { usage(); process.exitCode = 1; break; }
169
+ const current = store.get(id);
170
+ const patch = {};
171
+ for (const field of ['title', 'kind', 'status', 'scope', 'body']) {
172
+ if (typeof flags[field] === 'string') patch[field] = flags[field];
173
+ }
174
+ if (Object.keys(patch).length === 0) { usage(); process.exitCode = 1; break; }
175
+ const result = store.update(id, patch, { by: 'human', expectedRev: current.rev, note: '人工修改' });
176
+ console.log(result.changed ? `${id} → r${result.item.rev}` : '没有字段变化');
177
+ break;
178
+ }
179
+ case 'search': {
180
+ const query = positionals.join(' ');
181
+ const result = store.list({ query, includeArchived: true, limit: 200 });
182
+ if (result.items.length === 0) console.log('没有匹配的条目');
183
+ else result.items.forEach(printItem);
184
+ break;
185
+ }
186
+ case 'brief': {
187
+ console.log(store.brief({}));
188
+ break;
189
+ }
190
+ default:
191
+ usage();
192
+ if (command !== undefined) process.exitCode = 1;
193
+ }
@@ -0,0 +1,5 @@
1
+ # saibo_kanban bundle patch: one row. Rules live in config, never in this file.
2
+ - insert:
3
+ - id: saibo_kanban
4
+ name: saibo_kanban
5
+ config: {}
package/core.js ADDED
@@ -0,0 +1,166 @@
1
+ /**
2
+ * core.js — 纯领域逻辑,零宿主依赖。
3
+ *
4
+ * 这里只做三件事:校验、状态机、简报。不碰文件、不碰 DSH。
5
+ * store.js 负责持久化,tools.js 负责模型接口,页面负责渲染;三者共用这一份规则。
6
+ */
7
+
8
+ export const DEFAULT_KINDS = [
9
+ { id: 'task', label: '任务' },
10
+ { id: 'decision', label: '决策' },
11
+ { id: 'pitfall', label: '踩坑' },
12
+ { id: 'design', label: '设计' }
13
+ ];
14
+
15
+ export const STATUSES = [
16
+ { id: 'backlog', label: '待规划' },
17
+ { id: 'todo', label: '待办' },
18
+ { id: 'in_progress', label: '进行中' },
19
+ { id: 'in_review', label: '待验收' },
20
+ { id: 'done', label: '已完成' },
21
+ { id: 'blocked', label: '受阻' }
22
+ ];
23
+
24
+ const STATUS_IDS = new Set(STATUSES.map(s => s.id));
25
+
26
+ /** 允许的状态流转。done 只允许人写;AI 在 tools 层被额外拦住。 */
27
+ export const TRANSITIONS = {
28
+ backlog: ['todo', 'in_progress', 'blocked'],
29
+ todo: ['backlog', 'in_progress', 'blocked'],
30
+ in_progress: ['todo', 'in_review', 'blocked'],
31
+ in_review: ['in_progress', 'blocked', 'done'],
32
+ done: ['in_progress'],
33
+ blocked: ['backlog', 'todo', 'in_progress']
34
+ };
35
+
36
+ export class BoardError extends Error {
37
+ constructor(code, message) {
38
+ super(message);
39
+ this.name = 'BoardError';
40
+ this.code = code;
41
+ }
42
+ }
43
+
44
+ /** 可在修订里被改的字段。id / rev / createdAt / 来源 / verified 都不在此列。 */
45
+ export const EDITABLE_FIELDS = ['title', 'kind', 'status', 'scope', 'body'];
46
+
47
+ export function normalizeKinds(input) {
48
+ if (!Array.isArray(input) || input.length === 0) return DEFAULT_KINDS.map(k => ({ ...k }));
49
+ const seen = new Set();
50
+ const kinds = [];
51
+ for (const raw of input) {
52
+ const id = typeof raw === 'string' ? raw : raw && raw.id;
53
+ if (typeof id !== 'string' || !id.trim()) continue;
54
+ const key = id.trim();
55
+ if (seen.has(key)) continue;
56
+ seen.add(key);
57
+ kinds.push({ id: key, label: (raw && raw.label) || key });
58
+ }
59
+ return kinds.length > 0 ? kinds : DEFAULT_KINDS.map(k => ({ ...k }));
60
+ }
61
+
62
+ export function assertKind(kind, kinds) {
63
+ if (typeof kind !== 'string' || !kinds.some(k => k.id === kind)) {
64
+ throw new BoardError('INVALID_KIND', `未知类型 "${kind}",可用:${kinds.map(k => k.id).join(' / ')}`);
65
+ }
66
+ }
67
+
68
+ export function assertStatus(status) {
69
+ if (!STATUS_IDS.has(status)) {
70
+ throw new BoardError('INVALID_STATUS', `未知状态 "${status}",可用:${[...STATUS_IDS].join(' / ')}`);
71
+ }
72
+ }
73
+
74
+ export function assertTitle(title) {
75
+ if (typeof title !== 'string' || !title.trim()) {
76
+ throw new BoardError('INVALID_TITLE', '标题不能为空');
77
+ }
78
+ if (title.length > 200) {
79
+ throw new BoardError('INVALID_TITLE', '标题最长 200 字');
80
+ }
81
+ return title.trim();
82
+ }
83
+
84
+ /** 检查一次状态流转;by='ai' 时额外禁止直接写 done。 */
85
+ export function assertTransition(from, to, by) {
86
+ if (from === to) return;
87
+ assertStatus(to);
88
+ const allowed = TRANSITIONS[from] || [];
89
+ if (!allowed.includes(to)) {
90
+ throw new BoardError('INVALID_TRANSITION', `状态不能从 ${from} 直接变成 ${to}`);
91
+ }
92
+ if (to === 'done' && by === 'ai') {
93
+ throw new BoardError('HUMAN_ONLY', 'done 只能由人写:AI 最多把条目移到 in_review');
94
+ }
95
+ }
96
+
97
+ export function nextId() {
98
+ const t = Date.now().toString(36);
99
+ const r = Math.random().toString(36).slice(2, 6);
100
+ return `b-${t}${r}`;
101
+ }
102
+
103
+ /** 生成字段级 diff:{ field: { from, to } },未变化的字段不出现。 */
104
+ export function diffFields(item, patch, fields = EDITABLE_FIELDS) {
105
+ const changes = {};
106
+ for (const field of fields) {
107
+ if (!(field in patch)) continue;
108
+ const from = item[field] ?? '';
109
+ const to = patch[field] ?? '';
110
+ if (from !== to) changes[field] = { from, to };
111
+ }
112
+ return changes;
113
+ }
114
+
115
+ export function isDraft(item) {
116
+ return !item.verified;
117
+ }
118
+
119
+ /** 简报:默认只吃已确认条目,草稿只报数量。 */
120
+ export function buildBrief(items, options = {}) {
121
+ const maxChars = options.maxChars ?? 4000;
122
+ const includeDrafts = options.includeDrafts === true;
123
+ const active = items.filter(i => !i.archived);
124
+ const drafts = active.filter(isDraft);
125
+ const confirmed = active.filter(i => i.verified);
126
+ const pool = includeDrafts ? active : confirmed;
127
+
128
+ const byStatus = new Map(STATUSES.map(s => [s.id, []]));
129
+ for (const item of pool) {
130
+ if (byStatus.has(item.status)) byStatus.get(item.status).push(item);
131
+ }
132
+
133
+ const lines = [];
134
+ lines.push('## 看板简报');
135
+ const counts = STATUSES
136
+ .map(s => `${s.label} ${byStatus.get(s.id).length}`)
137
+ .join(' · ');
138
+ lines.push(`- 统计:${counts}`);
139
+ if (drafts.length > 0 && !includeDrafts) {
140
+ lines.push(`- 另有 ${drafts.length} 条待确认草稿未列入(人点过「接受」后才会进入简报)`);
141
+ }
142
+
143
+ const order = ['blocked', 'in_review', 'in_progress', 'todo', 'backlog', 'done'];
144
+ for (const status of order) {
145
+ const list = byStatus.get(status) || [];
146
+ if (list.length === 0) continue;
147
+ lines.push('');
148
+ lines.push(`### ${STATUSES.find(s => s.id === status).label}(${list.length})`);
149
+ for (const item of list) {
150
+ const meta = [item.kind, item.scope].filter(Boolean).join(' · ');
151
+ lines.push(`- \`${item.id}\` ${item.title}${meta ? `(${meta})` : ''}`);
152
+ }
153
+ }
154
+
155
+ const text = lines.join('\n');
156
+ if (text.length <= maxChars) return text;
157
+ return text.slice(0, maxChars - 20) + '\n…(简报已截断)';
158
+ }
159
+
160
+ /** 关键词匹配:标题、正文、范围、id。 */
161
+ export function matchesQuery(item, query) {
162
+ if (!query) return true;
163
+ const q = query.toLowerCase();
164
+ return [item.id, item.title, item.body, item.scope]
165
+ .some(v => typeof v === 'string' && v.toLowerCase().includes(q));
166
+ }
package/docs/DETAIL.md ADDED
@@ -0,0 +1,30 @@
1
+ # 赛博看板
2
+
3
+ AI 与人共用的活看板。当前版本 **0.2.0**:六个工具可用,界面在 0.3.0 接入。
4
+
5
+ ## 设计
6
+
7
+ - **收件箱**:AI 起草的条目先落到这里,人只做四件事——接受、退回、合并、删除。
8
+ - **看板**:按状态分列,拖拽换列即改状态。
9
+ - **表格**:主界面。点单元格就地改字段,不需要打开表单。
10
+ - **详情抽屉**:全字段、修订历史、来源追溯。
11
+ - **确认状态**:AI 写入默认「待确认」,人点过才变「已确认」;未确认的条目不进入任何下游摘要。
12
+
13
+ ## 修订,不覆盖
14
+
15
+ 每次修改生成一条新修订,记录字段级「改前 → 改后」、修改者和时间。任何一次 AI 改动都能看到,也能回滚。
16
+ AI 只能按字段 patch,不能整条覆盖、不能标记完成、不能物理删除。
17
+
18
+ ## 数据位置
19
+
20
+ `$DSH_HOME/saibo_kanban/records.jsonl`(只追加,可用 `config.dataDir` 修改)。卸载插件不删除数据。
21
+
22
+ ## 使用
23
+
24
+ 安装后在任意会话里让 agent 用 `board_record` 记一条,用 `board_brief` 取简报;
25
+ 人的确认与归档用 CLI:`node bin/board.mjs inbox` 查看,`accept <id>` 接受。
26
+ 0.3.0 起看板页面会出现在 DSH 中(表格 / 看板 / 收件箱三视图)。
27
+
28
+ ## 许可
29
+
30
+ MIT
package/icon.svg ADDED
@@ -0,0 +1,12 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Saibo Kanban">
2
+ <rect width="64" height="64" rx="14" fill="#111827"/>
3
+ <rect x="11" y="13" width="11" height="38" rx="3" fill="#1f2937"/>
4
+ <rect x="26.5" y="13" width="11" height="38" rx="3" fill="#1f2937"/>
5
+ <rect x="42" y="13" width="11" height="38" rx="3" fill="#1f2937"/>
6
+ <rect x="13.5" y="17" width="6" height="9" rx="2" fill="#38bdf8"/>
7
+ <rect x="13.5" y="29" width="6" height="12" rx="2" fill="#38bdf8" opacity=".5"/>
8
+ <rect x="29" y="17" width="6" height="13" rx="2" fill="#a78bfa"/>
9
+ <rect x="29" y="33" width="6" height="8" rx="2" fill="#a78bfa" opacity=".5"/>
10
+ <rect x="44.5" y="17" width="6" height="6" rx="2" fill="#34d399"/>
11
+ <rect x="44.5" y="26" width="6" height="11" rx="2" fill="#34d399" opacity=".5"/>
12
+ </svg>
package/index.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * saibo_kanban — AI 与人共用的活看板。
3
+ *
4
+ * 0.2.0:注册六个积木级工具,数据落在 $DSH_HOME/saibo_kanban/records.jsonl。
5
+ * 界面(收件箱/看板/表格)在 0.3.0 接入,共用同一份 core 与 store。
6
+ */
7
+ import { Store, defaultDataDir } from './store.js';
8
+ import { createTools } from './tools.js';
9
+ import { normalizeKinds } from './core.js';
10
+
11
+ export const inject = ['tools'];
12
+
13
+ export function apply(ctx, config) {
14
+ const settings = config && typeof config === 'object' ? config : {};
15
+ const dataDir = typeof settings.dataDir === 'string' && settings.dataDir.trim()
16
+ ? settings.dataDir
17
+ : defaultDataDir();
18
+ const kinds = normalizeKinds(settings.kinds);
19
+ const store = new Store({ dataDir, kinds }).load();
20
+ const tools = createTools(store, {
21
+ kinds,
22
+ maxBriefChars: Number.isFinite(settings.maxBriefChars) ? settings.maxBriefChars : 4000
23
+ });
24
+
25
+ for (const tool of tools) {
26
+ ctx.effect(() => ctx.tools.register(tool), `saibo_kanban: ${tool.name}`);
27
+ }
28
+ }
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Saibo Kanban",
4
+ "description": "A living board shared by you and the agent: drafts land in an inbox, you triage, and every edit is a revision you can roll back.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "赛博看板",
4
+ "description": "AI 与人共用的活看板:草稿进收件箱,人只做分拣,每次改动留修订,可回滚。",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "saibo-kanban",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.2",
4
+ "description": "AI 与人共用的活看板:草稿进收件箱、人做分拣、字段级修订可回滚,零 token 纠错。",
5
+ "keywords": [
6
+ "dsh",
7
+ "deepseek-harness",
8
+ "dsh-plugin",
9
+ "kanban",
10
+ "taskboard",
11
+ "ai-agent"
12
+ ],
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "engines": {
16
+ "node": ">=22",
17
+ "dsh": ">=0.2.2-rc.1"
18
+ },
19
+ "exports": {
20
+ ".": "./index.js",
21
+ "./core": "./core.js",
22
+ "./store": "./store.js",
23
+ "./locale/*.json": "./locale/*.json",
24
+ "./icon": "./icon.svg"
25
+ },
26
+ "files": [
27
+ "index.js",
28
+ "core.js",
29
+ "store.js",
30
+ "tools.js",
31
+ "bin",
32
+ "cordis.patch.yml",
33
+ "locale/*.json",
34
+ "docs",
35
+ "icon.svg",
36
+ "README.md",
37
+ "CHANGELOG.md",
38
+ "LICENSE"
39
+ ],
40
+ "bin": {
41
+ "saibo-board": "bin/board.mjs"
42
+ },
43
+ "dsh": {
44
+ "bundle": {
45
+ "patch": "./cordis.patch.yml"
46
+ }
47
+ },
48
+ "scripts": {
49
+ "check": "node --check index.js && node --check core.js && node --check store.js && node --check tools.js",
50
+ "test": "node test/run.mjs"
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/QuChen-D/saibo_kanban.git"
55
+ },
56
+ "homepage": "https://github.com/QuChen-D/saibo_kanban#readme",
57
+ "bugs": {
58
+ "url": "https://github.com/QuChen-D/saibo_kanban/issues"
59
+ }
60
+ }
package/store.js ADDED
@@ -0,0 +1,331 @@
1
+ /**
2
+ * store.js — 本地 JSONL 追加台账。
3
+ *
4
+ * 一条记录 = 一次修订(含完整快照),只追加、不覆盖。
5
+ * 换 SQLite / PG 时只需要换掉这个文件,core 和 tools 不动。
6
+ */
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import os from 'node:os';
10
+ import {
11
+ BoardError, assertTitle, assertKind, assertStatus, assertTransition,
12
+ diffFields, nextId, isDraft, buildBrief, matchesQuery
13
+ } from './core.js';
14
+
15
+ const SCHEMA_VERSION = 1;
16
+ const FILE_NAME = 'records.jsonl';
17
+
18
+ export function defaultDataDir() {
19
+ const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
20
+ return path.join(home, 'saibo_kanban');
21
+ }
22
+
23
+ function emptyItem() {
24
+ return {
25
+ id: '', title: '', kind: 'task', status: 'backlog', scope: '', body: '',
26
+ source: null, verified: false, archived: false,
27
+ rev: 0, createdAt: '', updatedAt: '', supersededBy: null, mergedInto: null
28
+ };
29
+ }
30
+
31
+ export class Store {
32
+ constructor(options = {}) {
33
+ this.dataDir = options.dataDir || defaultDataDir();
34
+ this.file = path.join(this.dataDir, FILE_NAME);
35
+ this.kinds = options.kinds;
36
+ this.items = new Map();
37
+ this.events = 0;
38
+ this.badLines = 0;
39
+ }
40
+
41
+ load() {
42
+ this.items.clear();
43
+ this.events = 0;
44
+ this.badLines = 0;
45
+ if (!fs.existsSync(this.file)) return this;
46
+ const raw = fs.readFileSync(this.file, 'utf8');
47
+ for (const line of raw.split(/\r?\n/)) {
48
+ if (!line.trim()) continue;
49
+ let event;
50
+ try { event = JSON.parse(line); } catch { this.badLines += 1; continue; }
51
+ if (!event || event.v !== SCHEMA_VERSION || !event.item || !event.item.id) { this.badLines += 1; continue; }
52
+ this.events += 1;
53
+ const current = this.items.get(event.item.id);
54
+ if (!current || current.rev <= event.item.rev) {
55
+ this.items.set(event.item.id, event.item);
56
+ }
57
+ }
58
+ return this;
59
+ }
60
+
61
+ append(event) {
62
+ fs.mkdirSync(this.dataDir, { recursive: true });
63
+ const line = JSON.stringify(event) + '\n';
64
+ const fd = fs.openSync(this.file, 'a');
65
+ try {
66
+ fs.writeSync(fd, line);
67
+ fs.fsyncSync(fd);
68
+ } finally {
69
+ fs.closeSync(fd);
70
+ }
71
+ this.events += 1;
72
+ this.items.set(event.item.id, event.item);
73
+ }
74
+
75
+ get(id) {
76
+ const item = this.items.get(id);
77
+ if (!item) throw new BoardError('NOT_FOUND', `没有找到条目 ${id}`);
78
+ return item;
79
+ }
80
+
81
+ /** 新建条目。AI 写入默认 verified=false;人写入可以直接 verified=true。 */
82
+ record(input, context = {}) {
83
+ const by = context.by === 'human' ? 'human' : 'ai';
84
+ const now = new Date().toISOString();
85
+ const title = assertTitle(input.title);
86
+ const kind = input.kind || 'task';
87
+ assertKind(kind, this.kinds);
88
+ const status = input.status || 'backlog';
89
+ assertStatus(status);
90
+ if (status === 'done' && by === 'ai') {
91
+ throw new BoardError('HUMAN_ONLY', 'done 只能由人写:AI 最多把条目移到 in_review');
92
+ }
93
+ const item = emptyItem();
94
+ item.id = input.id || nextId();
95
+ if (this.items.has(item.id)) throw new BoardError('DUPLICATE_ID', `条目 ${item.id} 已存在`);
96
+ item.title = title;
97
+ item.kind = kind;
98
+ item.status = status;
99
+ item.scope = typeof input.scope === 'string' ? input.scope : '';
100
+ item.body = typeof input.body === 'string' ? input.body : '';
101
+ item.source = normalizeSource(input.source);
102
+ item.verified = context.verified === true;
103
+ item.rev = 1;
104
+ item.createdAt = now;
105
+ item.updatedAt = now;
106
+ this.append({
107
+ v: SCHEMA_VERSION, id: item.id, rev: item.rev, time: now, by,
108
+ note: context.note || '创建',
109
+ changes: { created: { from: '', to: title } },
110
+ item
111
+ });
112
+ return item;
113
+ }
114
+
115
+ /** 字段级修改。必须带 expectedRev;冲突即拒绝,不自动重试。 */
116
+ update(id, patch, context = {}) {
117
+ const by = context.by === 'human' ? 'human' : 'ai';
118
+ const current = this.get(id);
119
+ if (current.archived) throw new BoardError('ARCHIVED', `条目 ${id} 已归档,不能再修改`);
120
+ if (current.supersededBy) throw new BoardError('SUPERSEDED', `条目 ${id} 已被 ${current.supersededBy} 取代`);
121
+ if (typeof context.expectedRev !== 'number' || context.expectedRev !== current.rev) {
122
+ throw new BoardError('STALE_REVISION',
123
+ `修订冲突:当前是 r${current.rev},你给的是 r${context.expectedRev ?? '缺失'}。请重新读取后再改`);
124
+ }
125
+ const next = { ...current };
126
+ const safe = {};
127
+ for (const field of ['title', 'kind', 'status', 'scope', 'body']) {
128
+ if (patch[field] === undefined) continue;
129
+ safe[field] = patch[field];
130
+ }
131
+ if ('title' in safe) safe.title = assertTitle(safe.title);
132
+ if ('kind' in safe) { assertKind(safe.kind, this.kinds); }
133
+ if ('status' in safe) {
134
+ assertStatus(safe.status);
135
+ assertTransition(current.status, safe.status, by);
136
+ }
137
+ if ('scope' in safe && typeof safe.scope !== 'string') {
138
+ throw new BoardError('INVALID_SCOPE', 'scope 必须是字符串');
139
+ }
140
+ if ('body' in safe && typeof safe.body !== 'string') {
141
+ throw new BoardError('INVALID_BODY', 'body 必须是字符串');
142
+ }
143
+ const changes = diffFields(current, safe);
144
+ if (Object.keys(changes).length === 0) {
145
+ return { item: current, changed: false, changes: {} };
146
+ }
147
+ Object.assign(next, safe);
148
+ next.rev = current.rev + 1;
149
+ next.updatedAt = new Date().toISOString();
150
+ this.append({
151
+ v: SCHEMA_VERSION, id, rev: next.rev, time: next.updatedAt, by,
152
+ note: context.note || '', changes, item: next
153
+ });
154
+ return { item: next, changed: true, changes };
155
+ }
156
+
157
+ /** 人点「接受」:verified=true。 */
158
+ accept(id, context = {}) {
159
+ return this.setVerified(id, true, { ...context, by: 'human', note: context.note || '接受' });
160
+ }
161
+
162
+ setVerified(id, verified, context = {}) {
163
+ const current = this.get(id);
164
+ if (current.verified === verified) return { item: current, changed: false };
165
+ if (context.by !== 'human') {
166
+ throw new BoardError('HUMAN_ONLY', '确认状态只能由人改');
167
+ }
168
+ const next = { ...current, verified, rev: current.rev + 1, updatedAt: new Date().toISOString() };
169
+ this.append({
170
+ v: SCHEMA_VERSION, id, rev: next.rev, time: next.updatedAt, by: 'human',
171
+ note: context.note || (verified ? '接受' : '取消确认'),
172
+ changes: { verified: { from: String(current.verified), to: String(verified) } },
173
+ item: next
174
+ });
175
+ return { item: next, changed: true };
176
+ }
177
+
178
+ /** 用新条目取代旧条目;旧条目保留,标记 supersededBy。 */
179
+ supersede(id, replacement, context = {}) {
180
+ const old = this.get(id);
181
+ if (old.archived) throw new BoardError('ARCHIVED', `条目 ${id} 已归档,不能再取代`);
182
+ if (typeof context.expectedRev !== 'number' || context.expectedRev !== old.rev) {
183
+ throw new BoardError('STALE_REVISION',
184
+ `修订冲突:当前是 r${old.rev},你给的是 r${context.expectedRev ?? '缺失'}`);
185
+ }
186
+ const by = context.by === 'human' ? 'human' : 'ai';
187
+ const replacementStatus = replacement.status || 'in_review';
188
+ if (replacementStatus === 'done' && by === 'ai') {
189
+ throw new BoardError('HUMAN_ONLY', 'done 只能由人写');
190
+ }
191
+ const created = this.record({
192
+ ...replacement,
193
+ kind: replacement.kind || old.kind,
194
+ scope: replacement.scope ?? old.scope,
195
+ body: replacement.body ?? old.body,
196
+ source: replacement.source || old.source,
197
+ status: replacementStatus
198
+ }, { by, note: context.note || `取代 ${old.id}`, verified: false });
199
+ const next = { ...old, supersededBy: created.id, rev: old.rev + 1, updatedAt: new Date().toISOString() };
200
+ this.append({
201
+ v: SCHEMA_VERSION, id, rev: next.rev, time: next.updatedAt, by,
202
+ note: context.note || `被 ${created.id} 取代`,
203
+ changes: { supersededBy: { from: '', to: created.id } }, item: next
204
+ });
205
+ return { old: next, created };
206
+ }
207
+
208
+ /** 合并多条到一个新条目;来源条目归档并标记 mergedInto。 */
209
+ merge(ids, merged, context = {}) {
210
+ if (!Array.isArray(ids) || ids.length < 2) {
211
+ throw new BoardError('INVALID_INPUT', 'merge 至少需要两个条目');
212
+ }
213
+ const by = context.by === 'human' ? 'human' : 'ai';
214
+ const sources = ids.map(id => this.get(id));
215
+ for (const src of sources) {
216
+ if (src.archived) throw new BoardError('ARCHIVED', `条目 ${src.id} 已归档`);
217
+ if (src.supersededBy) throw new BoardError('SUPERSEDED', `条目 ${src.id} 已被取代`);
218
+ }
219
+ const created = this.record({
220
+ title: merged.title,
221
+ kind: merged.kind || sources[0].kind,
222
+ status: merged.status || 'in_review',
223
+ scope: merged.scope ?? sources[0].scope,
224
+ body: merged.body ?? sources.map(s => s.body).filter(Boolean).join('\n\n'),
225
+ source: merged.source || sources[0].source
226
+ }, { by, note: context.note || `合并 ${sources.map(s => s.id).join(' + ')}` });
227
+ const now = new Date().toISOString();
228
+ for (const src of sources) {
229
+ const next = {
230
+ ...src, mergedInto: created.id, archived: true,
231
+ rev: src.rev + 1, updatedAt: now
232
+ };
233
+ this.append({
234
+ v: SCHEMA_VERSION, id: src.id, rev: next.rev, time: now, by,
235
+ note: context.note || `合并进 ${created.id}`,
236
+ changes: { mergedInto: { from: '', to: created.id }, archived: { from: 'false', to: 'true' } },
237
+ item: next
238
+ });
239
+ }
240
+ return { created, sources: ids };
241
+ }
242
+
243
+ /** 归档(人操作):不删除,可撤销。 */
244
+ archive(id, context = {}) {
245
+ const current = this.get(id);
246
+ if (current.archived) return { item: current, changed: false };
247
+ const now = new Date().toISOString();
248
+ const next = { ...current, archived: true, rev: current.rev + 1, updatedAt: now };
249
+ this.append({
250
+ v: SCHEMA_VERSION, id, rev: next.rev, time: now,
251
+ by: context.by === 'human' ? 'human' : 'ai',
252
+ note: context.note || '归档',
253
+ changes: { archived: { from: 'false', to: 'true' } }, item: next
254
+ });
255
+ return { item: next, changed: true };
256
+ }
257
+
258
+ restore(id, context = {}) {
259
+ const current = this.get(id);
260
+ if (!current.archived) return { item: current, changed: false };
261
+ const now = new Date().toISOString();
262
+ const next = { ...current, archived: false, rev: current.rev + 1, updatedAt: now };
263
+ this.append({
264
+ v: SCHEMA_VERSION, id, rev: next.rev, time: now,
265
+ by: context.by === 'human' ? 'human' : 'ai',
266
+ note: context.note || '撤销归档',
267
+ changes: { archived: { from: 'true', to: 'false' } }, item: next
268
+ });
269
+ return { item: next, changed: true };
270
+ }
271
+
272
+ list(options = {}) {
273
+ const limit = Math.max(1, Math.min(options.limit ?? 50, 200));
274
+ const out = [];
275
+ for (const item of this.items.values()) {
276
+ if (!options.includeArchived && item.archived) continue;
277
+ if (options.status && item.status !== options.status) continue;
278
+ if (options.kind && item.kind !== options.kind) continue;
279
+ if (options.scope && item.scope !== options.scope) continue;
280
+ if (options.draft === true && item.verified) continue;
281
+ if (options.draft === false && !item.verified) continue;
282
+ if (!matchesQuery(item, options.query)) continue;
283
+ out.push(item);
284
+ }
285
+ out.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
286
+ return { items: out.slice(0, limit), total: out.length, truncated: out.length > limit };
287
+ }
288
+
289
+ brief(options = {}) {
290
+ const items = [...this.items.values()];
291
+ return buildBrief(items, options);
292
+ }
293
+
294
+ stats() {
295
+ const all = [...this.items.values()];
296
+ return {
297
+ total: all.length,
298
+ active: all.filter(i => !i.archived).length,
299
+ drafts: all.filter(i => !i.archived && isDraft(i)).length,
300
+ archived: all.filter(i => i.archived).length,
301
+ rev: this.events
302
+ };
303
+ }
304
+
305
+ /** 读取某个条目的完整修订历史(直接扫文件,不改内存)。 */
306
+ history(id) {
307
+ if (!fs.existsSync(this.file)) return [];
308
+ const raw = fs.readFileSync(this.file, 'utf8');
309
+ const out = [];
310
+ for (const line of raw.split(/\r?\n/)) {
311
+ if (!line.trim()) continue;
312
+ let event;
313
+ try { event = JSON.parse(line); } catch { continue; }
314
+ if (event.id !== id) continue;
315
+ out.push({ rev: event.rev, time: event.time, by: event.by, note: event.note, changes: event.changes });
316
+ }
317
+ return out.sort((a, b) => a.rev - b.rev);
318
+ }
319
+ }
320
+
321
+ function normalizeSource(source) {
322
+ if (!source) return null;
323
+ if (typeof source === 'string') return { type: 'manual', ref: source };
324
+ if (typeof source === 'object') {
325
+ return {
326
+ type: typeof source.type === 'string' ? source.type : 'manual',
327
+ ref: typeof source.ref === 'string' ? source.ref : ''
328
+ };
329
+ }
330
+ return null;
331
+ }
package/tools.js ADDED
@@ -0,0 +1,289 @@
1
+ /**
2
+ * tools.js — 暴露给模型的六个积木级工具。
3
+ *
4
+ * 每个工具只做一件事;规则从 core/store 来,不在这里重复。
5
+ * AI 的边界在 store 里执行:字段级 patch、不能写 done、不能物理删除。
6
+ */
7
+ import { DEFAULT_KINDS, STATUSES, BoardError } from './core.js';
8
+
9
+ const text = value => [{ type: 'text', text: value }];
10
+
11
+ function serialize(value) {
12
+ return JSON.stringify(value, null, 2);
13
+ }
14
+
15
+ function fail(error) {
16
+ if (error instanceof BoardError) {
17
+ const err = new Error(`${error.code}: ${error.message}`);
18
+ err.code = error.code;
19
+ throw err;
20
+ }
21
+ throw error;
22
+ }
23
+
24
+ function wrap(fn) {
25
+ return async (args, exec) => {
26
+ try {
27
+ return await fn(args || {}, exec);
28
+ } catch (error) {
29
+ fail(error);
30
+ }
31
+ };
32
+ }
33
+
34
+ export function createTools(store, options = {}) {
35
+ const kinds = options.kinds || DEFAULT_KINDS;
36
+ const kindIds = kinds.map(k => k.id);
37
+ const statusIds = STATUSES.map(s => s.id);
38
+ const maxBriefChars = options.maxBriefChars ?? 4000;
39
+
40
+ return [
41
+ {
42
+ name: 'board_brief',
43
+ description: '读取看板简报:按状态列出已确认条目,附待确认草稿数量。只读,不修改数据。',
44
+ parameters: {
45
+ type: 'object',
46
+ properties: {
47
+ scope: { type: 'string', description: '只保留这个范围的条目,例如“看板插件”;省略表示全部' },
48
+ maxChars: { type: 'number', description: '返回文本上限,默认取插件配置' }
49
+ },
50
+ additionalProperties: false
51
+ },
52
+ output: {
53
+ schema: {
54
+ type: 'object',
55
+ properties: { markdown: { type: 'string' }, stats: { type: 'object' } },
56
+ required: ['markdown', 'stats']
57
+ },
58
+ render: (_args, value) => text(value.markdown)
59
+ },
60
+ execute: wrap(async args => {
61
+ const items = [...store.items.values()];
62
+ const scoped = args.scope ? items.filter(i => i.scope === args.scope) : items;
63
+ const markdown = store.brief({
64
+ maxChars: Number.isFinite(args.maxChars) ? args.maxChars : maxBriefChars
65
+ });
66
+ const stats = { ...store.stats(), inScope: scoped.length };
67
+ return {
68
+ markdown: args.scope
69
+ ? markdown + `\n\n(范围 ${args.scope}:${scoped.length} 条)`
70
+ : markdown,
71
+ stats
72
+ };
73
+ })
74
+ },
75
+ {
76
+ name: 'board_record',
77
+ description: '把一条新条目写进看板,默认进入收件箱待确认(verified=false)。先用一句话说清楚,再补正文。',
78
+ parameters: {
79
+ type: 'object',
80
+ properties: {
81
+ title: { type: 'string', description: '一句话标题,必填,最长 200 字' },
82
+ kind: { type: 'string', enum: kindIds, description: '条目类型,默认 task' },
83
+ scope: { type: 'string', description: '所属范围,例如“看板插件”“存储”;不确定就省略' },
84
+ body: { type: 'string', description: '补充说明,Markdown;可以省略' },
85
+ status: { type: 'string', enum: statusIds.filter(s => s !== 'done'), description: '初始状态,默认 backlog' },
86
+ source: {
87
+ type: 'object',
88
+ description: '来源:type=session/file/web/manual,ref=会话 id 或文件名',
89
+ properties: { type: { type: 'string' }, ref: { type: 'string' } },
90
+ additionalProperties: false
91
+ }
92
+ },
93
+ required: ['title'],
94
+ additionalProperties: false
95
+ },
96
+ output: {
97
+ schema: {
98
+ type: 'object',
99
+ properties: { id: { type: 'string' }, rev: { type: 'number' }, item: { type: 'object' } },
100
+ required: ['id', 'rev']
101
+ },
102
+ render: (_args, value) => text(`已记录 ${value.id}(r${value.rev},待确认)`)
103
+ },
104
+ execute: wrap(async args => {
105
+ const item = store.record(args, { by: 'ai', note: 'AI 记录', verified: false });
106
+ return { id: item.id, rev: item.rev, item: publicItem(item) };
107
+ })
108
+ },
109
+ {
110
+ name: 'board_update',
111
+ description: '按字段修改一条已确认或待确认的条目。必须带当前修订号;只能改 title/kind/status/scope/body,不能改确认状态。',
112
+ parameters: {
113
+ type: 'object',
114
+ properties: {
115
+ id: { type: 'string', description: '条目 id,例如 b-xxxx' },
116
+ expectedRev: { type: 'number', description: '你读到的当前修订号;不一致会拒绝,需重新读取' },
117
+ title: { type: 'string' },
118
+ kind: { type: 'string', enum: kindIds },
119
+ status: { type: 'string', enum: statusIds },
120
+ scope: { type: 'string' },
121
+ body: { type: 'string' },
122
+ note: { type: 'string', description: '这次改动的理由,会写进修订历史' }
123
+ },
124
+ required: ['id', 'expectedRev'],
125
+ additionalProperties: false
126
+ },
127
+ output: {
128
+ schema: {
129
+ type: 'object',
130
+ properties: { id: { type: 'string' }, rev: { type: 'number' }, changed: { type: 'boolean' }, changes: { type: 'object' } },
131
+ required: ['id', 'rev', 'changed']
132
+ },
133
+ render: (_args, value) => text(value.changed
134
+ ? `已更新 ${value.id} → r${value.rev}(${Object.keys(value.changes || {}).join(', ')})`
135
+ : `没有字段变化,${value.id} 仍是 r${value.rev}`)
136
+ },
137
+ execute: wrap(async args => {
138
+ const patch = {};
139
+ for (const field of ['title', 'kind', 'status', 'scope', 'body']) {
140
+ if (args[field] !== undefined) patch[field] = args[field];
141
+ }
142
+ const result = store.update(args.id, patch, {
143
+ by: 'ai', expectedRev: args.expectedRev, note: args.note || 'AI 修改'
144
+ });
145
+ return {
146
+ id: result.item.id,
147
+ rev: result.item.rev,
148
+ changed: result.changed,
149
+ changes: result.changes || {},
150
+ item: publicItem(result.item)
151
+ };
152
+ })
153
+ },
154
+ {
155
+ name: 'board_supersede',
156
+ description: '用一条新条目取代旧条目(旧条目保留并指向新条目)。用于结论变了、旧条目不能再直接改的场景。',
157
+ parameters: {
158
+ type: 'object',
159
+ properties: {
160
+ id: { type: 'string', description: '被取代的旧条目 id' },
161
+ expectedRev: { type: 'number', description: '旧条目当前修订号' },
162
+ title: { type: 'string', description: '新条目的标题' },
163
+ kind: { type: 'string', enum: kindIds },
164
+ scope: { type: 'string' },
165
+ body: { type: 'string' },
166
+ status: { type: 'string', enum: statusIds.filter(s => s !== 'done'), description: '新条目状态,默认 in_review' },
167
+ note: { type: 'string' }
168
+ },
169
+ required: ['id', 'expectedRev', 'title'],
170
+ additionalProperties: false
171
+ },
172
+ output: {
173
+ schema: {
174
+ type: 'object',
175
+ properties: { oldId: { type: 'string' }, newId: { type: 'string' }, rev: { type: 'number' } },
176
+ required: ['oldId', 'newId']
177
+ },
178
+ render: (_args, value) => text(`已用 ${value.newId} 取代 ${value.oldId}`)
179
+ },
180
+ execute: wrap(async args => {
181
+ const result = store.supersede(args.id, {
182
+ title: args.title,
183
+ kind: args.kind,
184
+ scope: args.scope,
185
+ body: args.body,
186
+ status: args.status || 'in_review'
187
+ }, { by: 'ai', expectedRev: args.expectedRev, note: args.note || `AI 取代 ${args.id}` });
188
+ return { oldId: result.old.id, newId: result.created.id, rev: result.created.rev };
189
+ })
190
+ },
191
+ {
192
+ name: 'board_merge',
193
+ description: '把两条以上重复或相近的条目合并成一条新条目;来源条目归档并指向新条目。',
194
+ parameters: {
195
+ type: 'object',
196
+ properties: {
197
+ ids: { type: 'array', items: { type: 'string' }, description: '要合并的条目 id,至少两个' },
198
+ title: { type: 'string', description: '合并后条目的标题' },
199
+ kind: { type: 'string', enum: kindIds },
200
+ scope: { type: 'string' },
201
+ body: { type: 'string', description: '合并后的正文;省略则拼接各来源正文' },
202
+ status: { type: 'string', enum: statusIds.filter(s => s !== 'done'), description: '默认 in_review' },
203
+ note: { type: 'string' }
204
+ },
205
+ required: ['ids', 'title'],
206
+ additionalProperties: false
207
+ },
208
+ output: {
209
+ schema: {
210
+ type: 'object',
211
+ properties: { id: { type: 'string' }, merged: { type: 'array' } },
212
+ required: ['id']
213
+ },
214
+ render: (_args, value) => text(`已合并 ${value.merged.length} 条 → ${value.id}`)
215
+ },
216
+ execute: wrap(async args => {
217
+ const result = store.merge(args.ids, {
218
+ title: args.title,
219
+ kind: args.kind,
220
+ scope: args.scope,
221
+ body: args.body,
222
+ status: args.status || 'in_review'
223
+ }, { by: 'ai', note: args.note || 'AI 合并' });
224
+ return { id: result.created.id, merged: result.sources };
225
+ })
226
+ },
227
+ {
228
+ name: 'board_search',
229
+ description: '检索看板条目:按关键词、状态、类型、范围过滤,返回紧凑列表(默认不含归档与历史修订)。',
230
+ parameters: {
231
+ type: 'object',
232
+ properties: {
233
+ query: { type: 'string', description: '关键词,匹配标题/正文/范围/id' },
234
+ status: { type: 'string', enum: statusIds },
235
+ kind: { type: 'string', enum: kindIds },
236
+ scope: { type: 'string' },
237
+ includeArchived: { type: 'boolean', description: '是否包含已归档条目,默认 false' },
238
+ limit: { type: 'number', description: '最多返回条数,默认 20,上限 200' }
239
+ },
240
+ additionalProperties: false
241
+ },
242
+ output: {
243
+ schema: {
244
+ type: 'object',
245
+ properties: {
246
+ total: { type: 'number' }, truncated: { type: 'boolean' },
247
+ items: { type: 'array', items: { type: 'object' } }
248
+ },
249
+ required: ['total', 'items']
250
+ },
251
+ render: (_args, value) => text(value.items.length === 0
252
+ ? '没有匹配的条目'
253
+ : value.items.map(i => `- ${i.id} ${i.title}(${i.status}${i.scope ? ' · ' + i.scope : ''}${i.verified ? '' : ' · 待确认'})`).join('\n'))
254
+ },
255
+ execute: wrap(async args => {
256
+ const result = store.list({
257
+ query: args.query,
258
+ status: args.status,
259
+ kind: args.kind,
260
+ scope: args.scope,
261
+ includeArchived: args.includeArchived === true,
262
+ limit: Math.min(Math.max(args.limit || 20, 1), 200)
263
+ });
264
+ return {
265
+ total: result.total,
266
+ truncated: result.truncated,
267
+ items: result.items.map(publicItem)
268
+ };
269
+ })
270
+ }
271
+ ];
272
+ }
273
+
274
+ function publicItem(item) {
275
+ return {
276
+ id: item.id,
277
+ title: item.title,
278
+ kind: item.kind,
279
+ status: item.status,
280
+ scope: item.scope,
281
+ body: item.body,
282
+ verified: item.verified,
283
+ archived: item.archived,
284
+ rev: item.rev,
285
+ updatedAt: item.updatedAt,
286
+ supersededBy: item.supersededBy,
287
+ mergedInto: item.mergedInto
288
+ };
289
+ }