saibo-kanban 0.4.0 → 0.5.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ - 表格加表头(# / 编号 / 标题 / 类型 / 状态 / 范围 / 修订)和行序号。
6
+ - 归档条目默认隐藏,新增「显示归档 / 隐藏归档」切换;归档行淡化并带「已归档」徽标。
7
+ - 详情抽屉对归档条目显示「恢复」而不是「归档」。
8
+
9
+ ## 0.4.1
10
+
11
+ - 导入改为页面操作:看板面板 → 「导入 xlsx」→ 选文件 → 预览数量 → 确认导入。
12
+ - 导入映射抽到 `lib/import-map.js`,页面与 CLI 共用;导入按「范围 + 标题」去重。
13
+
3
14
  ## 0.4.0
4
15
 
5
16
  - 新增 xlsx 导入:`node bin/import.mjs --xlsx <文件> [--dry-run]`。
package/README.md CHANGED
@@ -63,14 +63,18 @@ node bin/board.mjs show <id>
63
63
  node bin/board.mjs brief
64
64
  ```
65
65
 
66
- **导入 xlsx**
66
+ **页面导入(推荐)**
67
+
68
+ 看板面板 → 右上角「导入 xlsx」→ 选择文件 → 看预览(主表 / 滚动项 / 节点说明各多少条)→ 确认导入。
69
+
70
+ **命令行导入**
67
71
 
68
72
  ```bash
69
- node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run # 先看映射
70
- node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" # 真正写入
73
+ node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run
74
+ node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx"
71
75
  ```
72
76
 
73
- 主表进归档(历史台账),长期滚动项进活跃列,节点说明合成一条 design 资产。
77
+ 主表进归档(历史台账),长期滚动项进活跃列,节点说明合成一条 design 资产;重复条目按「范围 + 标题」跳过。
74
78
 
75
79
  ## 工具
76
80
 
package/bin/import.mjs CHANGED
@@ -1,19 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * 导入 xlsx 到看板。
3
+ * 命令行导入(页面导入之外的备用入口)。
4
4
  *
5
5
  * node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run
6
6
  * node bin/import.mjs --xlsx "..." --data-dir "C:\...\.dsh\saibo_kanban"
7
7
  *
8
- * 规则:
9
- * - 任务主表:全部导入为已归档(历史台账),状态 done
10
- * - 长期滚动项:导入为活跃条目,按状态映射
11
- * - 节点说明:整页文本合成一条 design 资产
8
+ * 页面操作是主路径:看板面板 → 导入 → 选择 xlsx。
12
9
  */
13
10
  import path from 'node:path';
14
11
  import { readXlsx } from '../lib/xlsx.js';
12
+ import { buildImport, describeImport } from '../lib/import-map.js';
15
13
  import { Store, defaultDataDir } from '../store.js';
16
- import { normalizeKinds, STATUSES } from '../core.js';
14
+ import { normalizeKinds } from '../core.js';
17
15
 
18
16
  const argv = process.argv.slice(2);
19
17
  const flags = {};
@@ -31,169 +29,38 @@ if (!file) {
31
29
  console.error('用法: node bin/import.mjs --xlsx <文件> [--dry-run] [--data-dir <目录>]');
32
30
  process.exit(1);
33
31
  }
34
- const dryRun = flags['dry-run'] === true;
35
- const dataDir = flags['data-dir'] || defaultDataDir();
36
-
37
- const STATUS_MAP = {
38
- DONE: 'done',
39
- 'DONE(描述修正)': 'done',
40
- 'DONE(已覆盖)': 'done',
41
- TODO: 'todo',
42
- PARTIAL: 'in_progress',
43
- FIX: 'in_progress',
44
- BLOCKED: 'blocked',
45
- 暂缓: 'backlog'
46
- };
47
-
48
- const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
49
-
50
- function headerIndex(rows, name) {
51
- for (let i = 0; i < Math.min(rows.length, 5); i += 1) {
52
- if ((rows[i] || []).some(v => String(v).trim() === name)) return i;
53
- }
54
- return 1;
55
- }
56
-
57
- function col(rows, headerRow, name) {
58
- const row = rows[headerRow] || [];
59
- for (let i = 0; i < row.length; i += 1) if (String(row[i]).trim() === name) return i;
60
- return -1;
61
- }
62
-
63
- function cell(row, idx) {
64
- if (idx < 0) return '';
65
- const v = row[idx];
66
- return v === undefined || v === null ? '' : String(v).trim();
67
- }
68
-
69
- function mapMain(rows) {
70
- const h = headerIndex(rows, '编号');
71
- const cId = col(rows, h, '编号');
72
- const cGroup = col(rows, h, '分组');
73
- const cTitle = col(rows, h, '名称');
74
- const cBody = col(rows, h, '详细说明');
75
- const cStatus = col(rows, h, '状态');
76
- const cType = col(rows, h, '类型');
77
- const out = [];
78
- for (let i = h + 1; i < rows.length; i += 1) {
79
- const title = cell(rows[i], cTitle);
80
- if (!title) continue;
81
- const status = STATUS_MAP[cell(rows[i], cStatus)] || 'done';
82
- out.push({
83
- title,
84
- body: [
85
- cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
86
- cell(rows[i], cType) ? `类型:${cell(rows[i], cType)}` : '',
87
- cell(rows[i], cBody)
88
- ].filter(Boolean).join('\n'),
89
- kind: 'task',
90
- scope: cell(rows[i], cGroup),
91
- status,
92
- archived: true,
93
- ext: cell(rows[i], cId)
94
- });
95
- }
96
- return out;
97
- }
98
-
99
- function mapRolling(rows) {
100
- const h = headerIndex(rows, '编号');
101
- const cId = col(rows, h, '编号');
102
- const cGroup = col(rows, h, '分组');
103
- const cTitle = col(rows, h, '名称');
104
- const cBody = col(rows, h, '详细说明');
105
- const cStatus = col(rows, h, '状态');
106
- const cPri = col(rows, h, '优先级');
107
- const cRoll = col(rows, h, '滚动次数');
108
- const cFirst = col(rows, h, '首次来源');
109
- const cLast = col(rows, h, '最近来源');
110
- const out = [];
111
- for (let i = h + 1; i < rows.length; i += 1) {
112
- const title = cell(rows[i], cTitle);
113
- if (!title) continue;
114
- const status = STATUS_MAP[cell(rows[i], cStatus)] || 'todo';
115
- out.push({
116
- title,
117
- body: [
118
- cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
119
- cell(rows[i], cBody),
120
- cell(rows[i], cPri) ? `优先级:${cell(rows[i], cPri)}` : '',
121
- cell(rows[i], cRoll) ? `滚动次数:${cell(rows[i], cRoll)}` : '',
122
- cell(rows[i], cFirst) ? `首次来源:${cell(rows[i], cFirst)}` : '',
123
- cell(rows[i], cLast) ? `最近来源:${cell(rows[i], cLast)}` : ''
124
- ].filter(Boolean).join('\n'),
125
- kind: 'task',
126
- scope: cell(rows[i], cGroup),
127
- status,
128
- archived: false,
129
- ext: cell(rows[i], cId)
130
- });
131
- }
132
- return out;
133
- }
134
-
135
- function mapNotes(rows) {
136
- const text = rows.map(r => cell(r, 0)).join('\n').trim();
137
- if (!text) return null;
138
- const firstLine = text.split('\n').find(l => l.trim()) || '节点说明';
139
- return {
140
- title: firstLine.replace(/^#+\s*/, '').slice(0, 120),
141
- body: text,
142
- kind: 'design',
143
- scope: '设计',
144
- status: 'done',
145
- archived: false,
146
- ext: 'nodes'
147
- };
148
- }
149
32
 
150
33
  const sheets = readXlsx(file);
151
- const byName = new Map(sheets.map(s => [s.name, s.rows]));
152
- const mainRows = byName.get('任务主表') || sheets[0]?.rows || [];
153
- const rollingRows = byName.get('长期滚动项') || sheets[1]?.rows || [];
154
- const notesRows = byName.get('节点说明') || sheets[2]?.rows || [];
155
-
156
- const main = mapMain(mainRows);
157
- const rolling = mapRolling(rollingRows);
158
- const notes = mapNotes(notesRows);
159
-
34
+ const plan = buildImport(sheets);
35
+ const desc = describeImport(plan);
160
36
  console.log(`文件:${file}`);
161
- console.log(`主表 ${main.length} 条(归档,done)`);
162
- console.log(`滚动项 ${rolling.length} 条(活跃)`);
163
- console.log(`节点说明:${notes ? '1 条' : '无'}`);
164
- console.log('状态分布:', Object.fromEntries([...new Set(rolling.map(r => r.status))].map(s => [statusLabel(s), rolling.filter(r => r.status === s).length])));
165
-
166
- const titles = new Map();
167
- for (const r of rolling) titles.set(r.title, (titles.get(r.title) || 0) + 1);
168
- const dup = [...titles.entries()].filter(([, n]) => n > 1);
169
- console.log(`滚动项重名:${dup.length} 组`);
37
+ console.log(`主表 ${desc.main} 条(归档,done)`);
38
+ console.log(`滚动项 ${desc.rolling} 条(活跃)`);
39
+ console.log(`节点说明:${desc.notes} 条`);
40
+ console.log('状态分布:', desc.byStatus);
170
41
  console.log('样例:');
171
- for (const r of rolling.slice(0, 2)) console.log(' -', r.status, '|', r.scope, '|', r.title);
172
- for (const r of main.slice(0, 1)) console.log(' -', r.status, '|', r.scope, '|', r.title, '(归档)');
42
+ for (const s of desc.samples) console.log(' -', s.status, '|', s.scope, '|', s.title);
173
43
 
174
- if (dryRun) {
175
- console.log('\n--dry-run:不写入。去掉 --dry-run 才导入。');
44
+ if (flags['dry-run'] === true) {
45
+ console.log('\n--dry-run:不写入。');
176
46
  process.exit(0);
177
47
  }
178
48
 
49
+ const dataDir = flags['data-dir'] || defaultDataDir();
179
50
  const store = new Store({ dataDir, kinds: normalizeKinds(null) }).load();
180
- let written = 0;
181
- for (const item of main) {
51
+ const existing = new Set([...store.items.values()].map(i => `${i.scope}|${i.title}`));
52
+ let imported = 0;
53
+ let skipped = 0;
54
+ const write = (item, note) => {
55
+ if (existing.has(`${item.scope}|${item.title}`)) { skipped += 1; return; }
182
56
  const created = store.record({
183
57
  title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
184
- }, { by: 'human', note: '导入:任务主表' });
185
- store.archive(created.id, { by: 'human', note: '导入历史台账' });
186
- written += 1;
187
- }
188
- for (const item of rolling) {
189
- store.record({
190
- title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
191
- }, { by: 'human', note: '导入:长期滚动项' });
192
- written += 1;
193
- }
194
- if (notes) {
195
- store.record({ title: notes.title, kind: notes.kind, scope: notes.scope, body: notes.body, status: notes.status },
196
- { by: 'human', note: '导入:节点说明' });
197
- written += 1;
198
- }
199
- console.log(`\n已导入 ${written} 条到 ${path.join(dataDir, 'records.jsonl')}`);
58
+ }, { by: 'human', note });
59
+ if (item.archived) store.archive(created.id, { by: 'human', note: '导入历史台账' });
60
+ existing.add(`${item.scope}|${item.title}`);
61
+ imported += 1;
62
+ };
63
+ for (const item of plan.main) write(item, '导入:任务主表');
64
+ for (const item of plan.rolling) write(item, '导入:长期滚动项');
65
+ if (plan.notes) write(plan.notes, '导入:节点说明');
66
+ console.log(`\n已导入 ${imported} 条,跳过重复 ${skipped} 条 → ${path.join(dataDir, 'records.jsonl')}`);
package/client.js CHANGED
@@ -23,8 +23,17 @@ window.__ModuleLoader__.load({
23
23
  const kindLabel = id => (KINDS.find(k => k.id === id) || { label: id }).label;
24
24
  const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
25
25
 
26
- async function api(method, args) {
27
- const res = await fetch('/saibo-kanban/api', {
26
+ function toBase64(buf) {
27
+ const bytes = new Uint8Array(buf);
28
+ let s = '';
29
+ const chunk = 0x8000;
30
+ for (let i = 0; i < bytes.length; i += chunk) {
31
+ s += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk));
32
+ }
33
+ return btoa(s);
34
+ }
35
+
36
+ async function api(method, args) { const res = await fetch('/saibo-kanban/api', {
28
37
  method: 'POST',
29
38
  headers: { 'content-type': 'application/json' },
30
39
  body: JSON.stringify({ method, args: args || {} })
@@ -63,6 +72,13 @@ window.__ModuleLoader__.load({
63
72
  .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
73
  .sk-sel:hover { border-color:var(--dsw-alias-border-l1,#e6e7eb); background:var(--dsw-alias-bg-layer-1,#fff); }
65
74
  .sk-rev { width:44px; flex:none; text-align:right; font-size:11.5px; color:var(--dsw-alias-label-secondary,#6b7280); }
75
+ .sk-num { width:34px; flex:none; text-align:right; font-size:11.5px; color:var(--dsw-alias-label-secondary,#6b7280); }
76
+ .sk-th { background:var(--dsw-alias-bg-layer-2,#f7f8fa); font-size:11.5px; font-weight:600; color:var(--dsw-alias-label-secondary,#6b7280); position:sticky; top:0; z-index:1; }
77
+ .sk-col-k { width:76px; flex:none; }
78
+ .sk-col-s { width:92px; flex:none; }
79
+ .sk-col-sc { width:120px; flex:none; }
80
+ .sk-row.arch { opacity:.6; }
81
+ .sk-badge { margin-left:6px; font-size:10.5px; color:var(--dsw-alias-label-secondary,#6b7280); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:999px; padding:0 6px; vertical-align:1px; }
66
82
  .sk-board { display:grid; grid-template-columns:repeat(6,minmax(160px,1fr)); gap:10px; align-items:start; }
67
83
  .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
84
  .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); }
@@ -86,11 +102,20 @@ window.__ModuleLoader__.load({
86
102
  .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
103
  .sk-empty { padding:40px; text-align:center; color:var(--dsw-alias-label-secondary,#6b7280); }
88
104
  .sk-rail { display:flex; align-items:center; justify-content:center; }
105
+ .sk-modal { position:absolute; inset:0; background:rgba(15,18,25,.35); display:flex; align-items:center; justify-content:center; z-index:8; }
106
+ .sk-dialog { width:min(520px,92%); background:var(--dsw-alias-bg-layer-1,#fff); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:12px; box-shadow:0 18px 48px rgba(16,24,40,.22); padding:16px; display:flex; flex-direction:column; gap:10px; }
107
+ .sk-dialog h3 { margin:0; font-size:15px; }
108
+ .sk-dialog .hint { color:var(--dsw-alias-label-secondary,#6b7280); font-size:12px; line-height:1.6; }
109
+ .sk-dialog .row { display:flex; gap:8px; justify-content:flex-end; }
110
+ .sk-dialog input[type=file] { font:inherit; font-size:12.5px; }
111
+ .sk-kv { display:flex; gap:12px; flex-wrap:wrap; font-size:12.5px; }
112
+ .sk-kv b { font-weight:650; }
89
113
  `;
90
114
 
91
115
  function Panel() {
92
116
  const [items, setItems] = useState([]);
93
117
  const [view, setView] = useState('table');
118
+ const [showArchived, setShowArchived] = useState(false);
94
119
  const [query, setQuery] = useState('');
95
120
  const [error, setError] = useState('');
96
121
  const [detail, setDetail] = useState(null);
@@ -99,6 +124,10 @@ window.__ModuleLoader__.load({
99
124
  const [overCol, setOverCol] = useState(null);
100
125
  const [toast, setToast] = useState('');
101
126
  const [busy, setBusy] = useState(false);
127
+ const [imp, setImp] = useState(null);
128
+ const [impBusy, setImpBusy] = useState(false);
129
+ const [impError, setImpError] = useState('');
130
+ const fileRef = useRef(null);
102
131
  const toastTimer = useRef(null);
103
132
 
104
133
  const say = useCallback(msg => {
@@ -109,11 +138,11 @@ window.__ModuleLoader__.load({
109
138
 
110
139
  const load = useCallback(async () => {
111
140
  try {
112
- const r = await api('list');
141
+ const r = await api('list', { includeArchived: showArchived });
113
142
  setItems(r.items);
114
143
  setError('');
115
144
  } catch (e) { setError(e.message); }
116
- }, []);
145
+ }, [showArchived]);
117
146
 
118
147
  useEffect(() => { load(); }, [load]);
119
148
 
@@ -168,6 +197,28 @@ window.__ModuleLoader__.load({
168
197
  h('input', {
169
198
  className: 'sk-search', placeholder: '搜索标题 / 编号 / 范围',
170
199
  value: query, onChange: e => setQuery(e.target.value)
200
+ }),
201
+ h('button', {
202
+ className: 'sk-btn' + (showArchived ? ' primary' : ''),
203
+ onClick: () => setShowArchived(v => !v)
204
+ }, showArchived ? '隐藏归档' : '显示归档'),
205
+ h('button', { className: 'sk-btn', onClick: () => fileRef.current && fileRef.current.click() }, '导入 xlsx'),
206
+ h('input', {
207
+ ref: fileRef, type: 'file', accept: '.xlsx', style: { display: 'none' },
208
+ onChange: async e => {
209
+ const file = e.target.files && e.target.files[0];
210
+ e.target.value = '';
211
+ if (!file) return;
212
+ setImpBusy(true); setImpError('');
213
+ try {
214
+ const buf = await file.arrayBuffer();
215
+ const data = toBase64(buf);
216
+ const r = await api('import.preview', { data });
217
+ setImp({ name: file.name, data, summary: r.summary });
218
+ } catch (err) {
219
+ setImp({ name: file.name, data: null, summary: null, error: err.message });
220
+ } finally { setImpBusy(false); }
221
+ }
171
222
  })
172
223
  );
173
224
 
@@ -184,8 +235,19 @@ window.__ModuleLoader__.load({
184
235
  content = h('div', null,
185
236
  quick,
186
237
  h('div', { className: 'sk-panel' },
238
+ h('div', { className: 'sk-row sk-th' },
239
+ h('span', { className: 'sk-num' }, '#'),
240
+ h('span', { className: 'sk-id' }, '编号'),
241
+ h('span', { className: 'sk-name', style: { cursor: 'default' } }, '标题'),
242
+ h('span', { className: 'sk-col-k' }, '类型'),
243
+ h('span', { className: 'sk-col-s' }, '状态'),
244
+ h('span', { className: 'sk-col-sc' }, '范围'),
245
+ h('span', { className: 'sk-rev' }, '修订'),
246
+ h('span', { style: { width: 44 } }, '')
247
+ ),
187
248
  visible.length === 0 ? h('div', { className: 'sk-empty' }, '还没有条目。跟 agent 说“记一条…”,或在上面的输入框快加。') :
188
- visible.map(item => h('div', { key: item.id, className: 'sk-row' },
249
+ visible.map((item, index) => h('div', { key: item.id, className: 'sk-row' + (item.archived ? ' arch' : '') },
250
+ h('span', { className: 'sk-num' }, String(index + 1)),
189
251
  h('span', { className: 'sk-id' }, item.id),
190
252
  h('div', {
191
253
  className: 'sk-name',
@@ -198,17 +260,17 @@ window.__ModuleLoader__.load({
198
260
  if (e.key === 'Enter') e.currentTarget.blur();
199
261
  if (e.key === 'Escape') setEditing(null);
200
262
  }
201
- }) : item.title),
263
+ }) : item.title, item.archived ? h('span', { className: 'sk-badge' }, '已归档') : null),
202
264
  h('select', {
203
- className: 'sk-sel', value: item.kind,
265
+ className: 'sk-sel sk-col-k', value: item.kind,
204
266
  onChange: e => update(item.id, item.rev, { kind: e.target.value })
205
267
  }, KINDS.map(k => h('option', { key: k.id, value: k.id }, k.label))),
206
268
  h('select', {
207
- className: 'sk-sel', value: item.status,
269
+ className: 'sk-sel sk-col-s', value: item.status,
208
270
  onChange: e => setStatus(item, e.target.value)
209
271
  }, STATUSES.map(s => h('option', { key: s.id, value: s.id }, s.label))),
210
272
  h('select', {
211
- className: 'sk-sel', value: item.scope || '',
273
+ className: 'sk-sel sk-col-sc', value: item.scope || '',
212
274
  onChange: e => update(item.id, item.rev, { scope: e.target.value })
213
275
  }, h('option', { value: '' }, '范围'), SCOPES.map(s => h('option', { key: s, value: s }, s))),
214
276
  h('span', { className: 'sk-rev' }, 'r' + item.rev),
@@ -307,10 +369,15 @@ window.__ModuleLoader__.load({
307
369
  className: 'sk-sel', value: detail.item.scope || '',
308
370
  onChange: e => update(detail.item.id, detail.item.rev, { scope: e.target.value })
309
371
  }, 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
- }, '归档')
372
+ detail.item.archived
373
+ ? h('button', {
374
+ className: 'sk-btn',
375
+ onClick: () => run(() => api('restore', { id: detail.item.id }), '已恢复').then(() => setDetail(null))
376
+ }, '恢复')
377
+ : h('button', {
378
+ className: 'sk-btn danger',
379
+ onClick: () => run(() => api('archive', { id: detail.item.id }), '已归档').then(() => setDetail(null))
380
+ }, '归档')
314
381
  ),
315
382
  h('div', { className: 'sk-hist' },
316
383
  h('h4', null, '修订历史(点“回滚”回到那一版)'),
@@ -331,10 +398,40 @@ window.__ModuleLoader__.load({
331
398
  )
332
399
  ) : null;
333
400
 
401
+ const importDialog = imp ? h('div', { className: 'sk-modal' },
402
+ h('div', { className: 'sk-dialog' },
403
+ h('h3', null, '导入 ' + (imp.name || 'xlsx')),
404
+ imp.error ? h('div', { className: 'hint', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, imp.error) : null,
405
+ imp.summary ? h('div', { className: 'sk-kv' },
406
+ h('span', null, '主表 ', h('b', null, String(imp.summary.main)), ' 条(归档)'),
407
+ h('span', null, '滚动项 ', h('b', null, String(imp.summary.rolling)), ' 条(活跃)'),
408
+ h('span', null, '节点说明 ', h('b', null, String(imp.summary.notes)), ' 条')
409
+ ) : h('div', { className: 'hint' }, impBusy ? '解析中…' : ''),
410
+ imp.summary ? h('div', { className: 'hint' },
411
+ Object.entries(imp.summary.byStatus || {}).map(([k, v]) => k + ' ' + v).join(' · ')) : null,
412
+ h('div', { className: 'row' },
413
+ h('button', { className: 'sk-btn', onClick: () => { setImp(null); setImpError(''); } }, '取消'),
414
+ imp.summary ? h('button', {
415
+ className: 'sk-btn primary',
416
+ onClick: async () => {
417
+ setImpBusy(true); setImpError('');
418
+ try {
419
+ const r = await api('import.apply', { data: imp.data });
420
+ setImp(null); await load();
421
+ say('已导入 ' + r.imported + ' 条,跳过重复 ' + r.skipped + ' 条');
422
+ } catch (err) { setImpError(err.message); }
423
+ finally { setImpBusy(false); }
424
+ }
425
+ }, impBusy ? '导入中…' : '确认导入') : null
426
+ )
427
+ )
428
+ ) : null;
429
+
334
430
  return h('div', { className: 'sk', style: { position: 'relative' } },
335
431
  h('style', null, CSS),
336
432
  head,
337
433
  h('div', { className: 'sk-body' }, error ? h('div', { className: 'sk-empty', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, error) : content),
434
+ importDialog,
338
435
  drawer,
339
436
  toast ? h('div', { className: 'sk-toast' }, toast) : null
340
437
  );
package/index.js CHANGED
@@ -8,6 +8,8 @@
8
8
  import { Store, defaultDataDir } from './store.js';
9
9
  import { createTools } from './tools.js';
10
10
  import { normalizeKinds } from './core.js';
11
+ import { readXlsxBuffer } from './lib/xlsx.js';
12
+ import { buildImport, describeImport } from './lib/import-map.js';
11
13
 
12
14
  export const inject = ['tools', 'webServer'];
13
15
 
@@ -96,6 +98,14 @@ function dispatch(store, method, args) {
96
98
  case 'brief': {
97
99
  return { markdown: store.brief({}) };
98
100
  }
101
+ case 'import.preview': {
102
+ const plan = buildImport(readXlsxBuffer(decodeData(args.data)));
103
+ return { summary: describeImport(plan) };
104
+ }
105
+ case 'import.apply': {
106
+ const plan = buildImport(readXlsxBuffer(decodeData(args.data)));
107
+ return applyPlan(store, plan);
108
+ }
99
109
  default:
100
110
  throw new Error(`未知方法: ${method}`);
101
111
  }
@@ -117,6 +127,30 @@ function publicItem(item) {
117
127
  };
118
128
  }
119
129
 
130
+ function decodeData(data) {
131
+ if (typeof data !== 'string' || data.length < 16) throw new Error('没有收到文件内容');
132
+ return Buffer.from(data, 'base64');
133
+ }
134
+
135
+ function applyPlan(store, plan) {
136
+ const existing = new Set([...store.items.values()].map(i => `${i.scope}|${i.title}`));
137
+ let imported = 0;
138
+ let skipped = 0;
139
+ const write = (item, note) => {
140
+ if (existing.has(`${item.scope}|${item.title}`)) { skipped += 1; return; }
141
+ const created = store.record({
142
+ title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
143
+ }, { by: 'human', note });
144
+ if (item.archived) store.archive(created.id, { by: 'human', note: '导入历史台账' });
145
+ existing.add(`${item.scope}|${item.title}`);
146
+ imported += 1;
147
+ };
148
+ for (const item of plan.main) write(item, '导入:任务主表');
149
+ for (const item of plan.rolling) write(item, '导入:长期滚动项');
150
+ if (plan.notes) write(plan.notes, '导入:节点说明');
151
+ return { imported, skipped, summary: describeImport(plan) };
152
+ }
153
+
120
154
  function readJsonBody(req) {
121
155
  return new Promise((resolve, reject) => {
122
156
  let body = '';
@@ -0,0 +1,145 @@
1
+ /**
2
+ * import-map.js — xlsx 工作表 → 看板条目的映射规则。
3
+ *
4
+ * CLI 和页面共用这一份,避免两边规则漂移。
5
+ */
6
+ import { STATUSES } from '../core.js';
7
+
8
+ export const STATUS_MAP = {
9
+ DONE: 'done',
10
+ 'DONE(描述修正)': 'done',
11
+ 'DONE(已覆盖)': 'done',
12
+ TODO: 'todo',
13
+ PARTIAL: 'in_progress',
14
+ FIX: 'in_progress',
15
+ BLOCKED: 'blocked',
16
+ 暂缓: 'backlog'
17
+ };
18
+
19
+ const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
20
+
21
+ function headerIndex(rows, name) {
22
+ for (let i = 0; i < Math.min(rows.length, 5); i += 1) {
23
+ if ((rows[i] || []).some(v => String(v).trim() === name)) return i;
24
+ }
25
+ return 1;
26
+ }
27
+
28
+ function col(rows, headerRow, name) {
29
+ const row = rows[headerRow] || [];
30
+ for (let i = 0; i < row.length; i += 1) if (String(row[i]).trim() === name) return i;
31
+ return -1;
32
+ }
33
+
34
+ function cell(row, idx) {
35
+ if (idx < 0) return '';
36
+ const v = row[idx];
37
+ return v === undefined || v === null ? '' : String(v).trim();
38
+ }
39
+
40
+ export function mapMain(rows) {
41
+ const h = headerIndex(rows, '编号');
42
+ const cId = col(rows, h, '编号');
43
+ const cGroup = col(rows, h, '分组');
44
+ const cTitle = col(rows, h, '名称');
45
+ const cBody = col(rows, h, '详细说明');
46
+ const cStatus = col(rows, h, '状态');
47
+ const cType = col(rows, h, '类型');
48
+ const out = [];
49
+ for (let i = h + 1; i < rows.length; i += 1) {
50
+ const title = cell(rows[i], cTitle);
51
+ if (!title) continue;
52
+ out.push({
53
+ title,
54
+ body: [
55
+ cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
56
+ cell(rows[i], cType) ? `类型:${cell(rows[i], cType)}` : '',
57
+ cell(rows[i], cBody)
58
+ ].filter(Boolean).join('\n'),
59
+ kind: 'task',
60
+ scope: cell(rows[i], cGroup),
61
+ status: STATUS_MAP[cell(rows[i], cStatus)] || 'done',
62
+ archived: true,
63
+ ext: cell(rows[i], cId)
64
+ });
65
+ }
66
+ return out;
67
+ }
68
+
69
+ export function mapRolling(rows) {
70
+ const h = headerIndex(rows, '编号');
71
+ const cId = col(rows, h, '编号');
72
+ const cGroup = col(rows, h, '分组');
73
+ const cTitle = col(rows, h, '名称');
74
+ const cBody = col(rows, h, '详细说明');
75
+ const cStatus = col(rows, h, '状态');
76
+ const cPri = col(rows, h, '优先级');
77
+ const cRoll = col(rows, h, '滚动次数');
78
+ const cFirst = col(rows, h, '首次来源');
79
+ const cLast = col(rows, h, '最近来源');
80
+ const out = [];
81
+ for (let i = h + 1; i < rows.length; i += 1) {
82
+ const title = cell(rows[i], cTitle);
83
+ if (!title) continue;
84
+ out.push({
85
+ title,
86
+ body: [
87
+ cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
88
+ cell(rows[i], cBody),
89
+ cell(rows[i], cPri) ? `优先级:${cell(rows[i], cPri)}` : '',
90
+ cell(rows[i], cRoll) ? `滚动次数:${cell(rows[i], cRoll)}` : '',
91
+ cell(rows[i], cFirst) ? `首次来源:${cell(rows[i], cFirst)}` : '',
92
+ cell(rows[i], cLast) ? `最近来源:${cell(rows[i], cLast)}` : ''
93
+ ].filter(Boolean).join('\n'),
94
+ kind: 'task',
95
+ scope: cell(rows[i], cGroup),
96
+ status: STATUS_MAP[cell(rows[i], cStatus)] || 'todo',
97
+ archived: false,
98
+ ext: cell(rows[i], cId)
99
+ });
100
+ }
101
+ return out;
102
+ }
103
+
104
+ export function mapNotes(rows) {
105
+ const text = rows.map(r => cell(r, 0)).join('\n').trim();
106
+ if (!text) return null;
107
+ const firstLine = text.split('\n').find(l => l.trim()) || '节点说明';
108
+ return {
109
+ title: firstLine.replace(/^#+\s*/, '').slice(0, 120),
110
+ body: text,
111
+ kind: 'design',
112
+ scope: '设计',
113
+ status: 'done',
114
+ archived: false,
115
+ ext: 'nodes'
116
+ };
117
+ }
118
+
119
+ /** 把工作簿整理成待导入集合。 */
120
+ export function buildImport(sheets) {
121
+ const byName = new Map(sheets.map(s => [s.name, s.rows]));
122
+ const mainRows = byName.get('任务主表') || sheets[0]?.rows || [];
123
+ const rollingRows = byName.get('长期滚动项') || sheets[1]?.rows || [];
124
+ const notesRows = byName.get('节点说明') || sheets[2]?.rows || [];
125
+ return {
126
+ main: mapMain(mainRows),
127
+ rolling: mapRolling(rollingRows),
128
+ notes: mapNotes(notesRows)
129
+ };
130
+ }
131
+
132
+ export function describeImport({ main, rolling, notes }) {
133
+ const byStatus = {};
134
+ for (const item of rolling) {
135
+ const label = statusLabel(item.status);
136
+ byStatus[label] = (byStatus[label] || 0) + 1;
137
+ }
138
+ return {
139
+ main: main.length,
140
+ rolling: rolling.length,
141
+ notes: notes ? 1 : 0,
142
+ byStatus,
143
+ samples: rolling.slice(0, 5).map(r => ({ title: r.title, scope: r.scope, status: r.status }))
144
+ };
145
+ }
package/lib/xlsx.js CHANGED
@@ -124,7 +124,11 @@ function readSheet(xml, shared) {
124
124
 
125
125
  /** 读取工作簿,返回 [{ name, rows }],rows 为二维字符串数组。 */
126
126
  export function readXlsx(file) {
127
- const buf = fs.readFileSync(file);
127
+ return readXlsxBuffer(fs.readFileSync(file));
128
+ }
129
+
130
+ /** 从内存读取工作簿(页面导入用)。 */
131
+ export function readXlsxBuffer(buf) {
128
132
  const entries = readEntries(buf);
129
133
  const shared = readSharedStrings(readFile(buf, entries, 'xl/sharedStrings.xml'));
130
134
  const workbook = readFile(buf, entries, 'xl/workbook.xml');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saibo-kanban",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "AI 与人共用的活看板:草稿进收件箱、人做分拣、字段级修订可回滚,零 token 纠错。",
5
5
  "keywords": [
6
6
  "dsh",