saibo-kanban 0.2.3 → 0.3.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/CHANGELOG.md +20 -6
- package/README.md +95 -83
- package/client.js +374 -0
- package/core.js +4 -13
- package/index.js +113 -5
- package/package.json +7 -1
- package/store.js +44 -9
- package/tools.js +35 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- 新增页面:左侧「看板」入口 + 中央面板(收件箱 / 看板 / 表格三视图)。
|
|
6
|
+
- host 新增 `/saibo-kanban/api`:list / get / create / update / archive / restore / rollback / brief。
|
|
7
|
+
- 权限对等:AI 与人同一套规则;新增 `board_rollback`,回滚本身也记一条修订。
|
|
8
|
+
- 移除 `verified` 确认机制(回滚兜底),简报改为列出全部条目。
|
|
9
|
+
|
|
3
10
|
## 0.2.3
|
|
4
11
|
|
|
5
|
-
-
|
|
12
|
+
- 修正 bundle patch 的行名(`saibo-kanban`),否则安装后 loader 会去 import 不存在的 `saibo_kanban`。
|
|
6
13
|
|
|
7
14
|
## 0.2.2
|
|
8
15
|
|
|
9
|
-
- 修正 `bin`
|
|
16
|
+
- 修正 `bin` 路径(去掉 `./`),npm 不再丢弃 CLI 入口。
|
|
17
|
+
|
|
10
18
|
## 0.2.1
|
|
11
19
|
|
|
12
|
-
- 新增 CLI `saibo-board
|
|
13
|
-
|
|
20
|
+
- 新增 CLI `saibo-board`:list / inbox / add / show / accept / unaccept / archive / restore / update / search / brief。
|
|
21
|
+
- `store.history(id)`:读取单条目的完整修订历史。
|
|
22
|
+
|
|
14
23
|
## 0.2.0
|
|
15
24
|
|
|
16
|
-
- `core.js
|
|
25
|
+
- `core.js`:条目模型、类型/状态校验、状态机、字段级 diff、简报、检索。
|
|
26
|
+
- `store.js`:`$DSH_HOME/saibo_kanban/records.jsonl` 只追加台账;乐观锁(`expectedRev`);
|
|
27
|
+
归档 / 恢复;合并与取代语义;重新加载按修订重放。
|
|
28
|
+
- `tools.js`:六个工具 `board_brief / record / update / supersede / merge / search`。
|
|
29
|
+
|
|
17
30
|
## 0.1.0
|
|
18
31
|
|
|
19
|
-
- 骨架:`package.json`(bundle patch、exports、files、engines)、`cordis.patch.yml
|
|
32
|
+
- 骨架:`package.json`(bundle patch、exports、files、engines)、`cordis.patch.yml`、
|
|
33
|
+
中英文 locale、图标、README、DETAIL、LICENSE、CHANGELOG。
|
package/README.md
CHANGED
|
@@ -1,83 +1,95 @@
|
|
|
1
|
-
# 赛博看板 / Saibo Kanban
|
|
2
|
-
|
|
3
|
-
一个给 DeepSeek Harness
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
|
69
|
-
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
# 赛博看板 / Saibo Kanban
|
|
2
|
+
|
|
3
|
+
一个给 DeepSeek Harness 用的**活看板**:AI 负责起草,人负责调整,每次改动都能回滚。
|
|
4
|
+
|
|
5
|
+
> 当前版本 0.3.0:左侧出现「看板」入口,中央面板有收件箱 / 看板 / 表格三视图;
|
|
6
|
+
> 七个工具(含回滚)。AI 与人权限对等,出错就回滚。
|
|
7
|
+
|
|
8
|
+
## 为什么做这个
|
|
9
|
+
|
|
10
|
+
- AI 写东西准确率 80–90%,会漏、会改口。所以每条改动都留修订,**错了一键回滚**。
|
|
11
|
+
- 人没有填表的意愿,但有改和删的意愿。页面以表格为主界面,点单元格就能改。
|
|
12
|
+
- Excel 的问题不是「表格」,是没有行身份、字段约束和变更历史。看板就是一张**有状态的智能表格**。
|
|
13
|
+
|
|
14
|
+
## 设计
|
|
15
|
+
|
|
16
|
+
- **收件箱**:最近变更的条目,用来快速扫一眼。
|
|
17
|
+
- **看板**:按状态分列,拖拽换列。
|
|
18
|
+
- **表格**:主界面,点标题直接改,类型/状态/范围用下拉。
|
|
19
|
+
- **详情抽屉**:全字段 + 修订历史,每一版都有「回滚」。
|
|
20
|
+
|
|
21
|
+
数据模型:条目带稳定 ID,每次写入都是**新修订**(字段级 diff、作者、来源),不是覆盖。
|
|
22
|
+
权限对等:AI 可以标完成、可以归档;人通过页面做同样的事。防跑偏靠状态机校验、必填校验、乐观锁(带错修订号就拒绝)和回滚。
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
**npm**
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
dsh plugin --profile web add saibo-kanban
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**GitHub 源码**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
dsh plugin --profile web add github:QuChen-D/saibo_kanban
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**在 DSH 里操作**:左侧「插件」→ 添加插件 → 安装第三方插件 → 输入 `saibo-kanban`。
|
|
39
|
+
|
|
40
|
+
## 数据
|
|
41
|
+
|
|
42
|
+
存放在 `$DSH_HOME/saibo_kanban/records.jsonl`(只追加),可用 `config.dataDir` 改。
|
|
43
|
+
卸载插件不删除数据。
|
|
44
|
+
|
|
45
|
+
## 怎么用
|
|
46
|
+
|
|
47
|
+
**对话**
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
记一条:把导入改成列映射 + 预览,范围 导入
|
|
51
|
+
看看板简报
|
|
52
|
+
找一下关于表单的条目
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**页面**:左侧「看板」图标 → 收件箱 / 看板 / 表格。
|
|
56
|
+
|
|
57
|
+
**CLI**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
node bin/board.mjs list
|
|
61
|
+
node bin/board.mjs add "标题" --kind decision --scope 存储
|
|
62
|
+
node bin/board.mjs show <id>
|
|
63
|
+
node bin/board.mjs brief
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 工具
|
|
67
|
+
|
|
68
|
+
| 工具 | 作用 |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `board_brief` | 读简报:按状态列出全部条目 |
|
|
71
|
+
| `board_record` | 写入一条新条目 |
|
|
72
|
+
| `board_update` | 按字段改一条,必须带 `expectedRev` |
|
|
73
|
+
| `board_supersede` | 用新条目取代旧条目,旧条目保留并指向新条目 |
|
|
74
|
+
| `board_merge` | 合并两条以上,来源归档并指向新条目 |
|
|
75
|
+
| `board_rollback` | 回滚到任意修订,回滚本身也记一条修订 |
|
|
76
|
+
| `board_search` | 按关键词 / 状态 / 类型 / 范围检索 |
|
|
77
|
+
|
|
78
|
+
## 路线图
|
|
79
|
+
|
|
80
|
+
- [x] 0.1.0 骨架
|
|
81
|
+
- [x] 0.2.0 核心 + 工具
|
|
82
|
+
- [x] 0.3.0 DSH 内页面(表格 / 看板 / 收件箱)+ 回滚
|
|
83
|
+
- [ ] 0.4.0 xlsx 导入(列映射 + 预览 + 冲突报告)
|
|
84
|
+
- [ ] 0.5.0 brief 注入与复用统计
|
|
85
|
+
|
|
86
|
+
## 开发
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm run check # 语法检查
|
|
90
|
+
npm test # 自测(不依赖 DSH)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
package/client.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'saibo-kanban',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
const { useState, useEffect, useMemo, useCallback, useRef } = React;
|
|
7
|
+
|
|
8
|
+
const KINDS = [
|
|
9
|
+
{ id: 'task', label: '任务' },
|
|
10
|
+
{ id: 'decision', label: '决策' },
|
|
11
|
+
{ id: 'pitfall', label: '踩坑' },
|
|
12
|
+
{ id: 'design', label: '设计' }
|
|
13
|
+
];
|
|
14
|
+
const STATUSES = [
|
|
15
|
+
{ id: 'backlog', label: '待规划' },
|
|
16
|
+
{ id: 'todo', label: '待办' },
|
|
17
|
+
{ id: 'in_progress', label: '进行中' },
|
|
18
|
+
{ id: 'in_review', label: '待验收' },
|
|
19
|
+
{ id: 'done', label: '已完成' },
|
|
20
|
+
{ id: 'blocked', label: '受阻' }
|
|
21
|
+
];
|
|
22
|
+
const SCOPES = ['看板插件', '存储', '表单', '导入', '编排', '记忆'];
|
|
23
|
+
const kindLabel = id => (KINDS.find(k => k.id === id) || { label: id }).label;
|
|
24
|
+
const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
|
|
25
|
+
|
|
26
|
+
async function api(method, args) {
|
|
27
|
+
const res = await fetch('/saibo-kanban/api', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: { 'content-type': 'application/json' },
|
|
30
|
+
body: JSON.stringify({ method, args: args || {} })
|
|
31
|
+
});
|
|
32
|
+
const data = await res.json();
|
|
33
|
+
if (!data.ok) throw new Error(data.error || '请求失败');
|
|
34
|
+
return data.result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const CSS = `
|
|
38
|
+
.sk { display:flex; flex-direction:column; height:100%; min-height:0; background:var(--dsw-alias-bg-base,#f6f7f9); color:var(--dsw-alias-label-primary,#17181a); font-size:13.5px; }
|
|
39
|
+
.sk * { box-sizing:border-box; }
|
|
40
|
+
.sk-head { display:flex; align-items:center; gap:12px; padding:12px 18px; border-bottom:1px solid var(--dsw-alias-border-l1,#e6e7eb); background:var(--dsw-alias-bg-layer-1,#fff); flex:none; }
|
|
41
|
+
.sk-title { font-weight:650; font-size:15px; }
|
|
42
|
+
.sk-tabs { display:flex; gap:2px; padding:3px; border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:9px; background:var(--dsw-alias-bg-layer-2,#fbfbfc); }
|
|
43
|
+
.sk-tab { border:0; background:transparent; color:var(--dsw-alias-label-secondary,#6b7280); padding:5px 12px; border-radius:7px; font:inherit; font-weight:550; cursor:pointer; }
|
|
44
|
+
.sk-tab.on { background:var(--dsw-alias-bg-layer-1,#fff); color:var(--dsw-alias-label-primary,#17181a); box-shadow:0 1px 2px rgba(16,24,40,.08); }
|
|
45
|
+
.sk-search { margin-left:auto; width:min(280px,30vw); padding:6px 10px; border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:8px; background:var(--dsw-alias-bg-layer-1,#fff); color:inherit; font:inherit; outline:none; }
|
|
46
|
+
.sk-search:focus { border-color:var(--dsw-alias-brand-primary,#2563eb); }
|
|
47
|
+
.sk-btn { border:1px solid var(--dsw-alias-border-l1,#e6e7eb); background:var(--dsw-alias-bg-layer-1,#fff); color:inherit; border-radius:7px; padding:5px 11px; font:inherit; font-size:12.5px; font-weight:550; cursor:pointer; }
|
|
48
|
+
.sk-btn:hover { border-color:var(--dsw-alias-border-l2,#c9ccd3); }
|
|
49
|
+
.sk-btn.primary { background:var(--dsw-alias-brand-primary,#2563eb); border-color:var(--dsw-alias-brand-primary,#2563eb); color:#fff; }
|
|
50
|
+
.sk-btn.danger { color:var(--dsw-alias-state-error-primary,#dc2626); }
|
|
51
|
+
.sk-body { flex:1; min-height:0; overflow:auto; padding:14px 18px 40px; }
|
|
52
|
+
.sk-quick { display:flex; gap:8px; align-items:center; margin-bottom:12px; background:var(--dsw-alias-bg-layer-1,#fff); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:10px; padding:8px 12px; }
|
|
53
|
+
.sk-quick input { flex:1; border:0; outline:none; background:transparent; color:inherit; font:inherit; padding:4px; }
|
|
54
|
+
.sk-quick .sk-k { color:var(--dsw-alias-label-secondary,#6b7280); font-size:12px; }
|
|
55
|
+
.sk-panel { background:var(--dsw-alias-bg-layer-1,#fff); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:10px; overflow:hidden; }
|
|
56
|
+
.sk-row { display:flex; align-items:center; gap:10px; padding:8px 12px; border-top:1px solid var(--dsw-alias-border-l1,#f0f1f4); }
|
|
57
|
+
.sk-row:first-child { border-top:0; }
|
|
58
|
+
.sk-row:hover { background:var(--dsw-alias-bg-layer-2,#fbfbfc); }
|
|
59
|
+
.sk-id { font-family:ui-monospace,Consolas,monospace; font-size:11.5px; color:var(--dsw-alias-label-secondary,#6b7280); width:86px; flex:none; }
|
|
60
|
+
.sk-name { flex:1; min-width:140px; cursor:text; border-radius:5px; padding:2px 4px; margin:-2px -4px; }
|
|
61
|
+
.sk-name:hover { background:var(--dsw-alias-bg-layer-2,#f3f4f6); }
|
|
62
|
+
.sk-name input { width:100%; border:1px solid var(--dsw-alias-brand-primary,#2563eb); border-radius:5px; padding:2px 4px; background:var(--dsw-alias-bg-layer-1,#fff); color:inherit; font:inherit; outline:none; }
|
|
63
|
+
.sk-sel { border:1px solid transparent; background:transparent; color:inherit; font:inherit; font-size:12px; border-radius:6px; padding:3px 4px; cursor:pointer; max-width:110px; }
|
|
64
|
+
.sk-sel:hover { border-color:var(--dsw-alias-border-l1,#e6e7eb); background:var(--dsw-alias-bg-layer-1,#fff); }
|
|
65
|
+
.sk-rev { width:44px; flex:none; text-align:right; font-size:11.5px; color:var(--dsw-alias-label-secondary,#6b7280); }
|
|
66
|
+
.sk-board { display:grid; grid-template-columns:repeat(6,minmax(160px,1fr)); gap:10px; align-items:start; }
|
|
67
|
+
.sk-col { background:var(--dsw-alias-bg-layer-2,#f3f4f6); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:10px; min-height:110px; }
|
|
68
|
+
.sk-col-head { display:flex; align-items:center; gap:6px; padding:9px 11px; font-weight:600; font-size:12.5px; color:var(--dsw-alias-label-secondary,#6b7280); border-bottom:1px solid var(--dsw-alias-border-l1,#e6e7eb); }
|
|
69
|
+
.sk-col-body { padding:7px; display:flex; flex-direction:column; gap:7px; min-height:70px; }
|
|
70
|
+
.sk-col.over { outline:2px dashed var(--dsw-alias-brand-primary,#2563eb); outline-offset:-3px; }
|
|
71
|
+
.sk-card { background:var(--dsw-alias-bg-layer-1,#fff); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:9px; padding:8px 10px; cursor:grab; }
|
|
72
|
+
.sk-card .t { font-weight:550; line-height:1.4; font-size:13px; }
|
|
73
|
+
.sk-card .m { margin-top:5px; display:flex; gap:6px; color:var(--dsw-alias-label-secondary,#6b7280); font-size:11.5px; }
|
|
74
|
+
.sk-drawer { position:absolute; top:0; right:0; bottom:0; width:min(460px,92%); background:var(--dsw-alias-bg-layer-1,#fff); border-left:1px solid var(--dsw-alias-border-l1,#e6e7eb); box-shadow:-8px 0 24px rgba(16,24,40,.08); display:flex; flex-direction:column; z-index:5; }
|
|
75
|
+
.sk-drawer-head { display:flex; align-items:center; gap:8px; padding:12px 14px; border-bottom:1px solid var(--dsw-alias-border-l1,#e6e7eb); }
|
|
76
|
+
.sk-drawer-body { flex:1; overflow:auto; padding:14px; display:flex; flex-direction:column; gap:12px; }
|
|
77
|
+
.sk-field { display:flex; flex-direction:column; gap:4px; }
|
|
78
|
+
.sk-field label { font-size:11.5px; color:var(--dsw-alias-label-secondary,#6b7280); }
|
|
79
|
+
.sk-field input, .sk-field select, .sk-field textarea { border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:7px; padding:6px 8px; background:var(--dsw-alias-bg-layer-1,#fff); color:inherit; font:inherit; outline:none; width:100%; }
|
|
80
|
+
.sk-field textarea { min-height:90px; resize:vertical; }
|
|
81
|
+
.sk-hist { border-top:1px solid var(--dsw-alias-border-l1,#e6e7eb); padding-top:8px; }
|
|
82
|
+
.sk-hist h4 { margin:0 0 6px; font-size:11.5px; color:var(--dsw-alias-label-secondary,#6b7280); font-weight:600; }
|
|
83
|
+
.sk-h { display:flex; gap:8px; align-items:baseline; padding:6px 0; border-bottom:1px dashed var(--dsw-alias-border-l1,#f0f1f4); font-size:12px; }
|
|
84
|
+
.sk-h .by { font-weight:600; }
|
|
85
|
+
.sk-h .chg { color:var(--dsw-alias-label-secondary,#6b7280); flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
86
|
+
.sk-toast { position:absolute; left:50%; bottom:18px; transform:translateX(-50%); background:var(--dsw-alias-label-primary,#17181a); color:var(--dsw-alias-bg-base,#fff); padding:8px 14px; border-radius:9px; font-size:12.5px; z-index:9; }
|
|
87
|
+
.sk-empty { padding:40px; text-align:center; color:var(--dsw-alias-label-secondary,#6b7280); }
|
|
88
|
+
.sk-rail { display:flex; align-items:center; justify-content:center; }
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
function Panel() {
|
|
92
|
+
const [items, setItems] = useState([]);
|
|
93
|
+
const [view, setView] = useState('table');
|
|
94
|
+
const [query, setQuery] = useState('');
|
|
95
|
+
const [error, setError] = useState('');
|
|
96
|
+
const [detail, setDetail] = useState(null);
|
|
97
|
+
const [editing, setEditing] = useState(null);
|
|
98
|
+
const [draft, setDraft] = useState('');
|
|
99
|
+
const [overCol, setOverCol] = useState(null);
|
|
100
|
+
const [toast, setToast] = useState('');
|
|
101
|
+
const [busy, setBusy] = useState(false);
|
|
102
|
+
const toastTimer = useRef(null);
|
|
103
|
+
|
|
104
|
+
const say = useCallback(msg => {
|
|
105
|
+
setToast(msg);
|
|
106
|
+
if (toastTimer.current) clearTimeout(toastTimer.current);
|
|
107
|
+
toastTimer.current = setTimeout(() => setToast(''), 2600);
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const load = useCallback(async () => {
|
|
111
|
+
try {
|
|
112
|
+
const r = await api('list');
|
|
113
|
+
setItems(r.items);
|
|
114
|
+
setError('');
|
|
115
|
+
} catch (e) { setError(e.message); }
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
useEffect(() => { load(); }, [load]);
|
|
119
|
+
|
|
120
|
+
const run = useCallback(async (fn, ok) => {
|
|
121
|
+
setBusy(true);
|
|
122
|
+
try { await fn(); await load(); if (ok) say(ok); }
|
|
123
|
+
catch (e) { setError(e.message); }
|
|
124
|
+
finally { setBusy(false); }
|
|
125
|
+
}, [load, say]);
|
|
126
|
+
|
|
127
|
+
const visible = useMemo(() => {
|
|
128
|
+
const q = query.trim().toLowerCase();
|
|
129
|
+
if (!q) return items;
|
|
130
|
+
return items.filter(i => (i.title + ' ' + i.id + ' ' + (i.scope || '')).toLowerCase().includes(q));
|
|
131
|
+
}, [items, query]);
|
|
132
|
+
|
|
133
|
+
const openDetail = useCallback(async id => {
|
|
134
|
+
try { setDetail(await api('get', { id })); }
|
|
135
|
+
catch (e) { setError(e.message); }
|
|
136
|
+
}, []);
|
|
137
|
+
|
|
138
|
+
const update = useCallback((id, rev, patch) => run(
|
|
139
|
+
() => api('update', { id, expectedRev: rev, patch }),
|
|
140
|
+
'已保存'
|
|
141
|
+
), [run]);
|
|
142
|
+
|
|
143
|
+
const create = useCallback(title => {
|
|
144
|
+
const t = title.trim();
|
|
145
|
+
if (!t) return;
|
|
146
|
+
run(() => api('create', { title: t }), '已新建');
|
|
147
|
+
}, [run]);
|
|
148
|
+
|
|
149
|
+
const setStatus = useCallback((item, status) => {
|
|
150
|
+
if (item.status === status) return;
|
|
151
|
+
update(item.id, item.rev, { status });
|
|
152
|
+
}, [update]);
|
|
153
|
+
|
|
154
|
+
const commitTitle = useCallback((item) => {
|
|
155
|
+
const v = draft.trim();
|
|
156
|
+
setEditing(null);
|
|
157
|
+
if (v && v !== item.title) update(item.id, item.rev, { title: v });
|
|
158
|
+
}, [draft, update]);
|
|
159
|
+
|
|
160
|
+
const head = h('div', { className: 'sk-head' },
|
|
161
|
+
h('span', { className: 'sk-title' }, '看板'),
|
|
162
|
+
h('div', { className: 'sk-tabs' },
|
|
163
|
+
['inbox', 'board', 'table'].map(v => h('button', {
|
|
164
|
+
key: v, className: 'sk-tab' + (view === v ? ' on' : ''),
|
|
165
|
+
onClick: () => setView(v)
|
|
166
|
+
}, v === 'inbox' ? '收件箱' : v === 'board' ? '看板' : '表格'))
|
|
167
|
+
),
|
|
168
|
+
h('input', {
|
|
169
|
+
className: 'sk-search', placeholder: '搜索标题 / 编号 / 范围',
|
|
170
|
+
value: query, onChange: e => setQuery(e.target.value)
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const quick = h('div', { className: 'sk-quick' },
|
|
175
|
+
h('span', { className: 'sk-k' }, '+'),
|
|
176
|
+
h('input', {
|
|
177
|
+
placeholder: '快加一条(回车新建)',
|
|
178
|
+
onKeyDown: e => { if (e.key === 'Enter') { create(e.currentTarget.value); e.currentTarget.value = ''; } }
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
let content = null;
|
|
183
|
+
if (view === 'table') {
|
|
184
|
+
content = h('div', null,
|
|
185
|
+
quick,
|
|
186
|
+
h('div', { className: 'sk-panel' },
|
|
187
|
+
visible.length === 0 ? h('div', { className: 'sk-empty' }, '还没有条目。跟 agent 说“记一条…”,或在上面的输入框快加。') :
|
|
188
|
+
visible.map(item => h('div', { key: item.id, className: 'sk-row' },
|
|
189
|
+
h('span', { className: 'sk-id' }, item.id),
|
|
190
|
+
h('div', {
|
|
191
|
+
className: 'sk-name',
|
|
192
|
+
onClick: () => { setEditing(item.id); setDraft(item.title); }
|
|
193
|
+
}, editing === item.id ? h('input', {
|
|
194
|
+
autoFocus: true, value: draft,
|
|
195
|
+
onChange: e => setDraft(e.target.value),
|
|
196
|
+
onBlur: () => commitTitle(item),
|
|
197
|
+
onKeyDown: e => {
|
|
198
|
+
if (e.key === 'Enter') e.currentTarget.blur();
|
|
199
|
+
if (e.key === 'Escape') setEditing(null);
|
|
200
|
+
}
|
|
201
|
+
}) : item.title),
|
|
202
|
+
h('select', {
|
|
203
|
+
className: 'sk-sel', value: item.kind,
|
|
204
|
+
onChange: e => update(item.id, item.rev, { kind: e.target.value })
|
|
205
|
+
}, KINDS.map(k => h('option', { key: k.id, value: k.id }, k.label))),
|
|
206
|
+
h('select', {
|
|
207
|
+
className: 'sk-sel', value: item.status,
|
|
208
|
+
onChange: e => setStatus(item, e.target.value)
|
|
209
|
+
}, STATUSES.map(s => h('option', { key: s.id, value: s.id }, s.label))),
|
|
210
|
+
h('select', {
|
|
211
|
+
className: 'sk-sel', value: item.scope || '',
|
|
212
|
+
onChange: e => update(item.id, item.rev, { scope: e.target.value })
|
|
213
|
+
}, h('option', { value: '' }, '范围'), SCOPES.map(s => h('option', { key: s, value: s }, s))),
|
|
214
|
+
h('span', { className: 'sk-rev' }, 'r' + item.rev),
|
|
215
|
+
h('button', { className: 'sk-btn', onClick: () => openDetail(item.id) }, '详情')
|
|
216
|
+
))
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
} else if (view === 'board') {
|
|
220
|
+
content = h('div', null,
|
|
221
|
+
quick,
|
|
222
|
+
h('div', { className: 'sk-board' },
|
|
223
|
+
STATUSES.map(s => {
|
|
224
|
+
const list = visible.filter(i => i.status === s.id);
|
|
225
|
+
return h('div', {
|
|
226
|
+
key: s.id,
|
|
227
|
+
className: 'sk-col' + (overCol === s.id ? ' over' : ''),
|
|
228
|
+
onDragOver: e => { e.preventDefault(); setOverCol(s.id); },
|
|
229
|
+
onDragLeave: () => setOverCol(c => c === s.id ? null : c),
|
|
230
|
+
onDrop: e => {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
const id = e.dataTransfer.getData('text/plain');
|
|
233
|
+
const item = items.find(i => i.id === id);
|
|
234
|
+
setOverCol(null);
|
|
235
|
+
if (item) setStatus(item, s.id);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
h('div', { className: 'sk-col-head' }, s.label, h('span', { style: { marginLeft: 'auto' } }, String(list.length))),
|
|
239
|
+
h('div', { className: 'sk-col-body' },
|
|
240
|
+
list.map(item => h('div', {
|
|
241
|
+
key: item.id, className: 'sk-card', draggable: true,
|
|
242
|
+
onDragStart: e => e.dataTransfer.setData('text/plain', item.id),
|
|
243
|
+
onDoubleClick: () => openDetail(item.id)
|
|
244
|
+
},
|
|
245
|
+
h('div', { className: 't' }, item.title),
|
|
246
|
+
h('div', { className: 'm' },
|
|
247
|
+
h('span', null, kindLabel(item.kind)),
|
|
248
|
+
h('span', null, item.scope || '未定范围'),
|
|
249
|
+
h('span', { style: { marginLeft: 'auto' } }, 'r' + item.rev)
|
|
250
|
+
)))
|
|
251
|
+
));
|
|
252
|
+
})
|
|
253
|
+
)
|
|
254
|
+
);
|
|
255
|
+
} else {
|
|
256
|
+
const recent = visible.slice().sort((a, b) => (b.updatedAt || '').localeCompare(a.updatedAt || '')).slice(0, 30);
|
|
257
|
+
content = h('div', null,
|
|
258
|
+
quick,
|
|
259
|
+
h('div', { className: 'sk-panel' },
|
|
260
|
+
recent.length === 0 ? h('div', { className: 'sk-empty' }, '还没有条目。') :
|
|
261
|
+
recent.map(item => h('div', { key: item.id, className: 'sk-row' },
|
|
262
|
+
h('span', { className: 'sk-id' }, item.id),
|
|
263
|
+
h('span', { style: { flex: 1, fontWeight: 550 } }, item.title),
|
|
264
|
+
h('span', { style: { color: 'var(--dsw-alias-label-secondary,#6b7280)', fontSize: 12 } },
|
|
265
|
+
statusLabel(item.status) + ' · ' + kindLabel(item.kind) + (item.scope ? ' · ' + item.scope : '')),
|
|
266
|
+
h('span', { className: 'sk-rev' }, 'r' + item.rev),
|
|
267
|
+
h('button', { className: 'sk-btn', onClick: () => openDetail(item.id) }, '查看')
|
|
268
|
+
))
|
|
269
|
+
)
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const drawer = detail ? h('div', { className: 'sk-drawer' },
|
|
274
|
+
h('div', { className: 'sk-drawer-head' },
|
|
275
|
+
h('span', { className: 'sk-id' }, detail.item.id),
|
|
276
|
+
h('span', { style: { fontWeight: 600, flex: 1 } }, '条目详情'),
|
|
277
|
+
h('button', { className: 'sk-btn', onClick: () => setDetail(null) }, '关闭')
|
|
278
|
+
),
|
|
279
|
+
h('div', { className: 'sk-drawer-body' },
|
|
280
|
+
h('div', { className: 'sk-field' }, h('label', null, '标题'),
|
|
281
|
+
h('input', {
|
|
282
|
+
key: detail.item.id + ':' + detail.item.rev,
|
|
283
|
+
defaultValue: detail.item.title,
|
|
284
|
+
onBlur: e => {
|
|
285
|
+
const v = e.target.value.trim();
|
|
286
|
+
if (v && v !== detail.item.title) update(detail.item.id, detail.item.rev, { title: v });
|
|
287
|
+
}
|
|
288
|
+
})),
|
|
289
|
+
h('div', { className: 'sk-field' }, h('label', null, '内容'),
|
|
290
|
+
h('textarea', {
|
|
291
|
+
key: detail.item.id + ':' + detail.item.rev + ':body',
|
|
292
|
+
defaultValue: detail.item.body || '',
|
|
293
|
+
onBlur: e => {
|
|
294
|
+
if (e.target.value !== (detail.item.body || '')) update(detail.item.id, detail.item.rev, { body: e.target.value });
|
|
295
|
+
}
|
|
296
|
+
})),
|
|
297
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
298
|
+
h('select', {
|
|
299
|
+
className: 'sk-sel', value: detail.item.status,
|
|
300
|
+
onChange: e => setStatus(detail.item, e.target.value)
|
|
301
|
+
}, STATUSES.map(s => h('option', { key: s.id, value: s.id }, s.label))),
|
|
302
|
+
h('select', {
|
|
303
|
+
className: 'sk-sel', value: detail.item.kind,
|
|
304
|
+
onChange: e => update(detail.item.id, detail.item.rev, { kind: e.target.value })
|
|
305
|
+
}, KINDS.map(k => h('option', { key: k.id, value: k.id }, k.label))),
|
|
306
|
+
h('select', {
|
|
307
|
+
className: 'sk-sel', value: detail.item.scope || '',
|
|
308
|
+
onChange: e => update(detail.item.id, detail.item.rev, { scope: e.target.value })
|
|
309
|
+
}, h('option', { value: '' }, '范围'), SCOPES.map(s => h('option', { key: s, value: s }, s))),
|
|
310
|
+
h('button', {
|
|
311
|
+
className: 'sk-btn danger',
|
|
312
|
+
onClick: () => run(() => api('archive', { id: detail.item.id }), '已归档').then(() => setDetail(null))
|
|
313
|
+
}, '归档')
|
|
314
|
+
),
|
|
315
|
+
h('div', { className: 'sk-hist' },
|
|
316
|
+
h('h4', null, '修订历史(点“回滚”回到那一版)'),
|
|
317
|
+
detail.history.slice().reverse().map(ev => h('div', { key: ev.rev, className: 'sk-h' },
|
|
318
|
+
h('span', { className: 'by' }, ev.by === 'human' ? '人' : 'AI'),
|
|
319
|
+
h('span', null, 'r' + ev.rev),
|
|
320
|
+
h('span', { className: 'chg' }, summarize(ev)),
|
|
321
|
+
h('button', {
|
|
322
|
+
className: 'sk-btn',
|
|
323
|
+
onClick: () => api('rollback', { id: detail.item.id, rev: ev.rev })
|
|
324
|
+
.then(() => api('get', { id: detail.item.id }))
|
|
325
|
+
.then(d => { setDetail(d); return load(); })
|
|
326
|
+
.then(() => say('已回滚到 r' + ev.rev))
|
|
327
|
+
.catch(e => setError(e.message))
|
|
328
|
+
}, '回滚')
|
|
329
|
+
))
|
|
330
|
+
)
|
|
331
|
+
)
|
|
332
|
+
) : null;
|
|
333
|
+
|
|
334
|
+
return h('div', { className: 'sk', style: { position: 'relative' } },
|
|
335
|
+
h('style', null, CSS),
|
|
336
|
+
head,
|
|
337
|
+
h('div', { className: 'sk-body' }, error ? h('div', { className: 'sk-empty', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, error) : content),
|
|
338
|
+
drawer,
|
|
339
|
+
toast ? h('div', { className: 'sk-toast' }, toast) : null
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function summarize(ev) {
|
|
344
|
+
if (!ev.changes) return '';
|
|
345
|
+
return Object.keys(ev.changes).map(k => {
|
|
346
|
+
const c = ev.changes[k];
|
|
347
|
+
return k + ': ' + String(c.from || '∅') + ' → ' + String(c.to || '∅');
|
|
348
|
+
}).join(';');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function RailIcon(props) {
|
|
352
|
+
const size = props && props.size ? props.size : 18;
|
|
353
|
+
return h('svg', {
|
|
354
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
|
|
355
|
+
stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round'
|
|
356
|
+
},
|
|
357
|
+
h('rect', { x: 3, y: 4, width: 5, height: 16, rx: 1.2 }),
|
|
358
|
+
h('rect', { x: 10, y: 4, width: 5, height: 16, rx: 1.2 }),
|
|
359
|
+
h('rect', { x: 17, y: 4, width: 4, height: 16, rx: 1.2 }));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
inject: ['slots'],
|
|
364
|
+
apply(ctx) {
|
|
365
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
366
|
+
name: 'sidebar.panellist', id: 'saibo-kanban', order: 6, label: '看板'
|
|
367
|
+
}, props => h('span', { className: 'sk-rail' }, h(RailIcon, props))));
|
|
368
|
+
ctx.slots.inject('main', () => ctx.slots.register({
|
|
369
|
+
name: 'main', key: 'saibo-kanban'
|
|
370
|
+
}, Panel));
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
});
|
package/core.js
CHANGED
|
@@ -81,17 +81,14 @@ export function assertTitle(title) {
|
|
|
81
81
|
return title.trim();
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
export function assertTransition(from, to
|
|
84
|
+
/** 检查一次状态流转;权限对等,AI 与人同一套规则。 */
|
|
85
|
+
export function assertTransition(from, to) {
|
|
86
86
|
if (from === to) return;
|
|
87
87
|
assertStatus(to);
|
|
88
88
|
const allowed = TRANSITIONS[from] || [];
|
|
89
89
|
if (!allowed.includes(to)) {
|
|
90
90
|
throw new BoardError('INVALID_TRANSITION', `状态不能从 ${from} 直接变成 ${to}`);
|
|
91
91
|
}
|
|
92
|
-
if (to === 'done' && by === 'ai') {
|
|
93
|
-
throw new BoardError('HUMAN_ONLY', 'done 只能由人写:AI 最多把条目移到 in_review');
|
|
94
|
-
}
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
export function nextId() {
|
|
@@ -116,14 +113,11 @@ export function isDraft(item) {
|
|
|
116
113
|
return !item.verified;
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
/**
|
|
116
|
+
/** 简报:列出全部未归档条目;回滚兜底,不再区分确认状态。 */
|
|
120
117
|
export function buildBrief(items, options = {}) {
|
|
121
118
|
const maxChars = options.maxChars ?? 4000;
|
|
122
|
-
const includeDrafts = options.includeDrafts === true;
|
|
123
119
|
const active = items.filter(i => !i.archived);
|
|
124
|
-
const
|
|
125
|
-
const confirmed = active.filter(i => i.verified);
|
|
126
|
-
const pool = includeDrafts ? active : confirmed;
|
|
120
|
+
const pool = active;
|
|
127
121
|
|
|
128
122
|
const byStatus = new Map(STATUSES.map(s => [s.id, []]));
|
|
129
123
|
for (const item of pool) {
|
|
@@ -136,9 +130,6 @@ export function buildBrief(items, options = {}) {
|
|
|
136
130
|
.map(s => `${s.label} ${byStatus.get(s.id).length}`)
|
|
137
131
|
.join(' · ');
|
|
138
132
|
lines.push(`- 统计:${counts}`);
|
|
139
|
-
if (drafts.length > 0 && !includeDrafts) {
|
|
140
|
-
lines.push(`- 另有 ${drafts.length} 条待确认草稿未列入(人点过「接受」后才会进入简报)`);
|
|
141
|
-
}
|
|
142
133
|
|
|
143
134
|
const order = ['blocked', 'in_review', 'in_progress', 'todo', 'backlog', 'done'];
|
|
144
135
|
for (const status of order) {
|
package/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* saibo-kanban — AI 与人共用的活看板。
|
|
3
3
|
*
|
|
4
|
-
* 0.
|
|
5
|
-
*
|
|
4
|
+
* 0.3.0:六个工具 + 一个页面(收件箱 / 看板 / 表格)。
|
|
5
|
+
* 数据落在 $DSH_HOME/saibo_kanban/records.jsonl;页面通过 /saibo-kanban/api 读写。
|
|
6
|
+
* 权限对等:人通过 UI、AI 通过工具,都走同一份 store 与规则;回滚兜底。
|
|
6
7
|
*/
|
|
7
8
|
import { Store, defaultDataDir } from './store.js';
|
|
8
9
|
import { createTools } from './tools.js';
|
|
9
10
|
import { normalizeKinds } from './core.js';
|
|
10
11
|
|
|
11
|
-
export const inject = ['tools'];
|
|
12
|
+
export const inject = ['tools', 'webServer'];
|
|
12
13
|
|
|
13
14
|
export function apply(ctx, config) {
|
|
14
15
|
const settings = config && typeof config === 'object' ? config : {};
|
|
@@ -23,6 +24,113 @@ export function apply(ctx, config) {
|
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
for (const tool of tools) {
|
|
26
|
-
ctx.effect(() => ctx.tools.register(tool), `
|
|
27
|
+
ctx.effect(() => ctx.tools.register(tool), `saibo-kanban: ${tool.name}`);
|
|
27
28
|
}
|
|
29
|
+
|
|
30
|
+
ctx.effect(() => ctx.webServer.register({
|
|
31
|
+
kind: 'prefix',
|
|
32
|
+
path: '/saibo-kanban/api',
|
|
33
|
+
handler: async (req, res) => {
|
|
34
|
+
if (req.method !== 'POST') {
|
|
35
|
+
res.writeHead(405, { 'content-type': 'application/json' });
|
|
36
|
+
res.end(JSON.stringify({ ok: false, error: 'method not allowed' }));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const payload = await readJsonBody(req);
|
|
41
|
+
const result = dispatch(store, payload.method, payload.args || {});
|
|
42
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
43
|
+
res.end(JSON.stringify({ ok: true, result }));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
46
|
+
res.end(JSON.stringify({
|
|
47
|
+
ok: false,
|
|
48
|
+
error: error && error.message ? error.message : 'unknown error',
|
|
49
|
+
code: error && error.code ? error.code : undefined
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}), 'saibo-kanban: /saibo-kanban/api');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function dispatch(store, method, args) {
|
|
57
|
+
switch (method) {
|
|
58
|
+
case 'list': {
|
|
59
|
+
const result = store.list({ includeArchived: args.includeArchived === true, limit: 500 });
|
|
60
|
+
return { items: result.items.map(publicItem), total: result.total };
|
|
61
|
+
}
|
|
62
|
+
case 'get': {
|
|
63
|
+
const item = store.get(args.id);
|
|
64
|
+
return { item: publicItem(item), history: store.history(args.id) };
|
|
65
|
+
}
|
|
66
|
+
case 'create': {
|
|
67
|
+
const item = store.record({
|
|
68
|
+
title: args.title,
|
|
69
|
+
kind: args.kind || 'task',
|
|
70
|
+
scope: args.scope || '',
|
|
71
|
+
body: args.body || '',
|
|
72
|
+
status: args.status || 'backlog'
|
|
73
|
+
}, { by: 'human', note: '页面新建' });
|
|
74
|
+
return { item: publicItem(item) };
|
|
75
|
+
}
|
|
76
|
+
case 'update': {
|
|
77
|
+
const result = store.update(args.id, args.patch || {}, {
|
|
78
|
+
by: 'human',
|
|
79
|
+
expectedRev: args.expectedRev,
|
|
80
|
+
note: args.note || '页面修改'
|
|
81
|
+
});
|
|
82
|
+
return { item: publicItem(result.item), changed: result.changed, changes: result.changes };
|
|
83
|
+
}
|
|
84
|
+
case 'archive': {
|
|
85
|
+
const result = store.archive(args.id, { by: 'human', note: '页面归档' });
|
|
86
|
+
return { item: publicItem(result.item) };
|
|
87
|
+
}
|
|
88
|
+
case 'restore': {
|
|
89
|
+
const result = store.restore(args.id, { by: 'human', note: '页面恢复' });
|
|
90
|
+
return { item: publicItem(result.item) };
|
|
91
|
+
}
|
|
92
|
+
case 'rollback': {
|
|
93
|
+
const result = store.rollback(args.id, args.rev, { by: 'human', note: args.note || `回滚到 r${args.rev}` });
|
|
94
|
+
return { item: publicItem(result.item) };
|
|
95
|
+
}
|
|
96
|
+
case 'brief': {
|
|
97
|
+
return { markdown: store.brief({}) };
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
throw new Error(`未知方法: ${method}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function publicItem(item) {
|
|
105
|
+
return {
|
|
106
|
+
id: item.id,
|
|
107
|
+
title: item.title,
|
|
108
|
+
kind: item.kind,
|
|
109
|
+
status: item.status,
|
|
110
|
+
scope: item.scope,
|
|
111
|
+
body: item.body,
|
|
112
|
+
archived: item.archived,
|
|
113
|
+
rev: item.rev,
|
|
114
|
+
updatedAt: item.updatedAt,
|
|
115
|
+
supersededBy: item.supersededBy,
|
|
116
|
+
mergedInto: item.mergedInto
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function readJsonBody(req) {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
let body = '';
|
|
123
|
+
req.setEncoding('utf8');
|
|
124
|
+
req.on('data', chunk => {
|
|
125
|
+
body += chunk;
|
|
126
|
+
if (body.length > 4 * 1024 * 1024) {
|
|
127
|
+
reject(new Error('body too large'));
|
|
128
|
+
req.destroy();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
req.on('end', () => {
|
|
132
|
+
try { resolve(body ? JSON.parse(body) : {}); } catch (error) { reject(error); }
|
|
133
|
+
});
|
|
134
|
+
req.on('error', reject);
|
|
135
|
+
});
|
|
28
136
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saibo-kanban",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "AI 与人共用的活看板:草稿进收件箱、人做分拣、字段级修订可回滚,零 token 纠错。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": "./index.js",
|
|
21
|
+
"./client": "./client.js",
|
|
21
22
|
"./core": "./core.js",
|
|
22
23
|
"./store": "./store.js",
|
|
23
24
|
"./locale/*.json": "./locale/*.json",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"index.js",
|
|
29
|
+
"client.js",
|
|
28
30
|
"core.js",
|
|
29
31
|
"store.js",
|
|
30
32
|
"tools.js",
|
|
@@ -43,6 +45,10 @@
|
|
|
43
45
|
"dsh": {
|
|
44
46
|
"bundle": {
|
|
45
47
|
"patch": "./cordis.patch.yml"
|
|
48
|
+
},
|
|
49
|
+
"client": {
|
|
50
|
+
"inject": [],
|
|
51
|
+
"platform": "web"
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
54
|
"scripts": {
|
package/store.js
CHANGED
|
@@ -87,9 +87,6 @@ export class Store {
|
|
|
87
87
|
assertKind(kind, this.kinds);
|
|
88
88
|
const status = input.status || 'backlog';
|
|
89
89
|
assertStatus(status);
|
|
90
|
-
if (status === 'done' && by === 'ai') {
|
|
91
|
-
throw new BoardError('HUMAN_ONLY', 'done 只能由人写:AI 最多把条目移到 in_review');
|
|
92
|
-
}
|
|
93
90
|
const item = emptyItem();
|
|
94
91
|
item.id = input.id || nextId();
|
|
95
92
|
if (this.items.has(item.id)) throw new BoardError('DUPLICATE_ID', `条目 ${item.id} 已存在`);
|
|
@@ -99,7 +96,6 @@ export class Store {
|
|
|
99
96
|
item.scope = typeof input.scope === 'string' ? input.scope : '';
|
|
100
97
|
item.body = typeof input.body === 'string' ? input.body : '';
|
|
101
98
|
item.source = normalizeSource(input.source);
|
|
102
|
-
item.verified = context.verified === true;
|
|
103
99
|
item.rev = 1;
|
|
104
100
|
item.createdAt = now;
|
|
105
101
|
item.updatedAt = now;
|
|
@@ -132,7 +128,7 @@ export class Store {
|
|
|
132
128
|
if ('kind' in safe) { assertKind(safe.kind, this.kinds); }
|
|
133
129
|
if ('status' in safe) {
|
|
134
130
|
assertStatus(safe.status);
|
|
135
|
-
assertTransition(current.status, safe.status
|
|
131
|
+
assertTransition(current.status, safe.status);
|
|
136
132
|
}
|
|
137
133
|
if ('scope' in safe && typeof safe.scope !== 'string') {
|
|
138
134
|
throw new BoardError('INVALID_SCOPE', 'scope 必须是字符串');
|
|
@@ -185,9 +181,6 @@ export class Store {
|
|
|
185
181
|
}
|
|
186
182
|
const by = context.by === 'human' ? 'human' : 'ai';
|
|
187
183
|
const replacementStatus = replacement.status || 'in_review';
|
|
188
|
-
if (replacementStatus === 'done' && by === 'ai') {
|
|
189
|
-
throw new BoardError('HUMAN_ONLY', 'done 只能由人写');
|
|
190
|
-
}
|
|
191
184
|
const created = this.record({
|
|
192
185
|
...replacement,
|
|
193
186
|
kind: replacement.kind || old.kind,
|
|
@@ -296,7 +289,6 @@ export class Store {
|
|
|
296
289
|
return {
|
|
297
290
|
total: all.length,
|
|
298
291
|
active: all.filter(i => !i.archived).length,
|
|
299
|
-
drafts: all.filter(i => !i.archived && isDraft(i)).length,
|
|
300
292
|
archived: all.filter(i => i.archived).length,
|
|
301
293
|
rev: this.events
|
|
302
294
|
};
|
|
@@ -316,6 +308,49 @@ export class Store {
|
|
|
316
308
|
}
|
|
317
309
|
return out.sort((a, b) => a.rev - b.rev);
|
|
318
310
|
}
|
|
311
|
+
|
|
312
|
+
/** 取某个修订的完整快照(回滚用)。 */
|
|
313
|
+
revision(id, rev) {
|
|
314
|
+
if (!fs.existsSync(this.file)) return null;
|
|
315
|
+
const raw = fs.readFileSync(this.file, 'utf8');
|
|
316
|
+
let found = null;
|
|
317
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
318
|
+
if (!line.trim()) continue;
|
|
319
|
+
let event;
|
|
320
|
+
try { event = JSON.parse(line); } catch { continue; }
|
|
321
|
+
if (event.id === id && event.rev === rev && event.item) found = event.item;
|
|
322
|
+
}
|
|
323
|
+
return found;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* 回滚到指定修订:把那一版的字段写成一条新的修订。
|
|
328
|
+
* 历史不销毁;回滚本身也可再回滚。
|
|
329
|
+
*/
|
|
330
|
+
rollback(id, rev, context = {}) {
|
|
331
|
+
const current = this.get(id);
|
|
332
|
+
const target = this.revision(id, rev);
|
|
333
|
+
if (!target) throw new BoardError('NOT_FOUND', `条目 ${id} 没有 r${rev}`);
|
|
334
|
+
const now = new Date().toISOString();
|
|
335
|
+
const next = {
|
|
336
|
+
...target,
|
|
337
|
+
id: current.id,
|
|
338
|
+
createdAt: current.createdAt,
|
|
339
|
+
rev: current.rev + 1,
|
|
340
|
+
updatedAt: now,
|
|
341
|
+
archived: false,
|
|
342
|
+
supersededBy: null,
|
|
343
|
+
mergedInto: null
|
|
344
|
+
};
|
|
345
|
+
this.append({
|
|
346
|
+
v: SCHEMA_VERSION, id, rev: next.rev, time: now,
|
|
347
|
+
by: context.by === 'human' ? 'human' : 'ai',
|
|
348
|
+
note: context.note || `回滚到 r${rev}`,
|
|
349
|
+
changes: { rollback: { from: `r${current.rev}`, to: `r${rev}` } },
|
|
350
|
+
item: next
|
|
351
|
+
});
|
|
352
|
+
return { item: next, changed: true };
|
|
353
|
+
}
|
|
319
354
|
}
|
|
320
355
|
|
|
321
356
|
function normalizeSource(source) {
|
package/tools.js
CHANGED
|
@@ -40,7 +40,7 @@ export function createTools(store, options = {}) {
|
|
|
40
40
|
return [
|
|
41
41
|
{
|
|
42
42
|
name: 'board_brief',
|
|
43
|
-
description: '
|
|
43
|
+
description: '读取看板简报:按状态列出全部条目。只读,不修改数据。',
|
|
44
44
|
parameters: {
|
|
45
45
|
type: 'object',
|
|
46
46
|
properties: {
|
|
@@ -74,7 +74,7 @@ export function createTools(store, options = {}) {
|
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
name: 'board_record',
|
|
77
|
-
description: '
|
|
77
|
+
description: '把一条新条目写进看板。先用一句话说清楚,再补正文。',
|
|
78
78
|
parameters: {
|
|
79
79
|
type: 'object',
|
|
80
80
|
properties: {
|
|
@@ -99,16 +99,16 @@ export function createTools(store, options = {}) {
|
|
|
99
99
|
properties: { id: { type: 'string' }, rev: { type: 'number' }, item: { type: 'object' } },
|
|
100
100
|
required: ['id', 'rev']
|
|
101
101
|
},
|
|
102
|
-
render: (_args, value) => text(`已记录 ${value.id}(r${value.rev}
|
|
102
|
+
render: (_args, value) => text(`已记录 ${value.id}(r${value.rev})`)
|
|
103
103
|
},
|
|
104
104
|
execute: wrap(async args => {
|
|
105
|
-
const item = store.record(args, { by: 'ai', note: 'AI 记录'
|
|
105
|
+
const item = store.record(args, { by: 'ai', note: 'AI 记录' });
|
|
106
106
|
return { id: item.id, rev: item.rev, item: publicItem(item) };
|
|
107
107
|
})
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
name: 'board_update',
|
|
111
|
-
description: '
|
|
111
|
+
description: '按字段修改一条条目。必须带当前修订号;只能改 title/kind/status/scope/body。',
|
|
112
112
|
parameters: {
|
|
113
113
|
type: 'object',
|
|
114
114
|
properties: {
|
|
@@ -224,6 +224,35 @@ export function createTools(store, options = {}) {
|
|
|
224
224
|
return { id: result.created.id, merged: result.sources };
|
|
225
225
|
})
|
|
226
226
|
},
|
|
227
|
+
{
|
|
228
|
+
name: 'board_rollback',
|
|
229
|
+
description: '把条目回滚到之前的某个修订。历史不销毁,回滚本身也记一条修订。',
|
|
230
|
+
parameters: {
|
|
231
|
+
type: 'object',
|
|
232
|
+
properties: {
|
|
233
|
+
id: { type: 'string', description: '条目 id' },
|
|
234
|
+
rev: { type: 'number', description: '要回到的修订号' },
|
|
235
|
+
note: { type: 'string', description: '回滚理由,会写进修订历史' }
|
|
236
|
+
},
|
|
237
|
+
required: ['id', 'rev'],
|
|
238
|
+
additionalProperties: false
|
|
239
|
+
},
|
|
240
|
+
output: {
|
|
241
|
+
schema: {
|
|
242
|
+
type: 'object',
|
|
243
|
+
properties: { id: { type: 'string' }, rev: { type: 'number' } },
|
|
244
|
+
required: ['id', 'rev']
|
|
245
|
+
},
|
|
246
|
+
render: (_args, value) => text(`已回滚 ${value.id} → r${value.rev}`)
|
|
247
|
+
},
|
|
248
|
+
execute: wrap(async args => {
|
|
249
|
+
const result = store.rollback(args.id, args.rev, {
|
|
250
|
+
by: 'ai',
|
|
251
|
+
note: args.note || `AI 回滚到 r${args.rev}`
|
|
252
|
+
});
|
|
253
|
+
return { id: result.item.id, rev: result.item.rev };
|
|
254
|
+
})
|
|
255
|
+
},
|
|
227
256
|
{
|
|
228
257
|
name: 'board_search',
|
|
229
258
|
description: '检索看板条目:按关键词、状态、类型、范围过滤,返回紧凑列表(默认不含归档与历史修订)。',
|
|
@@ -250,7 +279,7 @@ export function createTools(store, options = {}) {
|
|
|
250
279
|
},
|
|
251
280
|
render: (_args, value) => text(value.items.length === 0
|
|
252
281
|
? '没有匹配的条目'
|
|
253
|
-
: value.items.map(i => `- ${i.id} ${i.title}(${i.status}${i.scope ? ' · ' + i.scope : ''}
|
|
282
|
+
: value.items.map(i => `- ${i.id} ${i.title}(${i.status}${i.scope ? ' · ' + i.scope : ''})`).join('\n'))
|
|
254
283
|
},
|
|
255
284
|
execute: wrap(async args => {
|
|
256
285
|
const result = store.list({
|