dsh-todo-time-log 0.6.0 → 0.6.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.
@@ -0,0 +1,573 @@
1
+ /**
2
+ * Import / export formatting for 「待办时间日志」 (dsh-todo-time-log).
3
+ *
4
+ * Export is lossless for the native JSON envelope and human-friendly for CSV.
5
+ * Import accepts every shape this plugin can produce plus a hand-written
6
+ * `Todo[]`:
7
+ *
8
+ * - native JSON envelope v1-v5 (`{ version, todos }`) — the same versions the
9
+ * store itself migrates on load;
10
+ * - a bare `Todo[]` array;
11
+ * - CSV with a header row (Chinese and English column aliases).
12
+ *
13
+ * Everything here is pure: no file system, no dsh imports. The Host HTTP route
14
+ * parses the uploaded text, then hands the normalized records to
15
+ * `TodoStore.importTodos()`, which owns merging, backups and persistence.
16
+ *
17
+ * CSV conventions (documented in README):
18
+ * - UTF-8 with BOM, CRLF line endings, RFC 4180 quoting;
19
+ * - timestamps are local `YYYY-MM-DD HH:mm:ss` (JSON keeps ISO-8601 UTC);
20
+ * - `files` uses `;` between workspace-relative paths;
21
+ * - `耗时(分钟)` is derived on export and ignored on import.
22
+ */
23
+
24
+ import {
25
+ MAX_TODOS,
26
+ STORE_VERSION,
27
+ extractStoreRows,
28
+ makeTodoId,
29
+ normalizeTodo,
30
+ } from './store.js';
31
+ import { formatLocalDateTime, nowIso, parseTimestamp, secondsBetween } from './time.js';
32
+
33
+ /** Formats accepted by `exportTodoData()`. */
34
+ export const EXPORT_FORMATS = Object.freeze(['json', 'csv']);
35
+ /** Formats accepted by `parseImportText()`. */
36
+ export const IMPORT_FORMATS = Object.freeze(['json', 'csv']);/** How many invalid rows an import result describes in detail. */
37
+ export const MAX_INVALID_DETAILS = 20;
38
+
39
+ const CSV_BOM = '\uFEFF';
40
+ const CSV_HEADER = Object.freeze([
41
+ 'ID',
42
+ '标题',
43
+ '分类',
44
+ '文件',
45
+ '状态',
46
+ '优先级',
47
+ '类型',
48
+ '创建时间',
49
+ '完成时间',
50
+ '更新时间',
51
+ '耗时(分钟)',
52
+ ]);
53
+
54
+ /** CSV display labels; the import aliases below accept both languages. */
55
+ const PRIORITY_CSV = Object.freeze({ high: '高', medium: '中', low: '低' });
56
+ const TYPE_CSV = Object.freeze({
57
+ bug: '缺陷',
58
+ feature: '新功能',
59
+ improvement: '改进',
60
+ question: '疑问',
61
+ chore: '杂项',
62
+ other: '其他',
63
+ });
64
+
65
+ const HEADER_ALIASES = Object.freeze({
66
+ id: ['id', '编号', '标识'],
67
+ title: ['title', '标题', '待办', '任务', '内容'],
68
+ project: ['project', '分类', '项目', '类别'],
69
+ files: ['files', 'file', '文件', '文件引用', '关联文件'],
70
+ status: ['status', '状态'],
71
+ priority: ['priority', '优先级'],
72
+ type: ['type', '类型'],
73
+ createdAt: ['createdat', 'created_at', 'created', '创建时间', '创建'],
74
+ completedAt: ['completedat', 'completed_at', 'completed', '完成时间', '完成'],
75
+ updatedAt: ['updatedat', 'updated_at', 'updated', '更新时间', '更新'],
76
+ });
77
+
78
+ const COMPLETED_STATUS_ALIASES = new Set([
79
+ 'completed', 'complete', 'done', 'closed', 'true', '1', '是',
80
+ '已完成', '完成', '已办', '已结束',
81
+ ]);
82
+ const PENDING_STATUS_ALIASES = new Set([
83
+ 'pending', 'todo', 'open', 'false', '0', '否', '未完成', '待办', '未开始',
84
+ ]);
85
+ const PRIORITY_ALIASES = Object.freeze({
86
+ high: 'high', 高: 'high', 紧急: 'high',
87
+ medium: 'medium', 中: 'medium', 普通: 'medium',
88
+ low: 'low', 低: 'low', 次要: 'low',
89
+ '': '', 未设置: '', 无: '',
90
+ });
91
+ const TYPE_ALIASES = Object.freeze({
92
+ bug: 'bug', 缺陷: 'bug', 故障: 'bug',
93
+ feature: 'feature', 新功能: 'feature', 功能: 'feature',
94
+ improvement: 'improvement', 改进: 'improvement', 优化: 'improvement',
95
+ question: 'question', 疑问: 'question', 问题: 'question',
96
+ chore: 'chore', 杂项: 'chore', 事务: 'chore',
97
+ other: 'other', 其他: 'other',
98
+ '': '', 未设置: '',
99
+ });
100
+
101
+ const NAIVE_DATETIME = /^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/;
102
+
103
+ /** Local-time `YYYYMMDD-HHmm`, used in export file names. */
104
+ function filenameStamp(now) {
105
+ const date = new Date(now);
106
+ const pad = (value) => String(value).padStart(2, '0');
107
+ return (
108
+ `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-`
109
+ + `${pad(date.getHours())}${pad(date.getMinutes())}`
110
+ );
111
+ }
112
+
113
+ /** Escape one CSV field (RFC 4180): quote when it contains `,` `"` CR or LF. */
114
+ function escapeCsvField(value) {
115
+ const text = value === null || value === undefined ? '' : String(value);
116
+ if (/[",\r\n]/.test(text)) return `"${text.replace(/"/g, '""')}"`;
117
+ return text;
118
+ }
119
+
120
+ /** Local display timestamp, or '' for an empty/invalid value. */
121
+ function csvTimestamp(value) {
122
+ return formatLocalDateTime(value, { dash: '' });
123
+ }
124
+
125
+ /** Completed duration in whole minutes; '' while pending. */
126
+ function durationMinutes(todo) {
127
+ if (todo.status !== 'completed' || todo.completedAt === null || todo.completedAt === undefined) {
128
+ return '';
129
+ }
130
+ const seconds = secondsBetween(todo.createdAt, todo.completedAt);
131
+ return seconds === null ? '' : String(Math.round(seconds / 60));
132
+ }
133
+
134
+ /**
135
+ * Build the native JSON document. Extra top-level fields (`exportedAt`,
136
+ * `exporter`, `count`) are ignored by every importer, including this plugin's.
137
+ *
138
+ * @param {object[]} todos
139
+ * @param {{ now?: number }} [options]
140
+ * @returns {string}
141
+ */
142
+ export function buildExportJson(todos, options = {}) {
143
+ const now = typeof options.now === 'number' ? options.now : Date.now();
144
+ const envelope = {
145
+ version: STORE_VERSION,
146
+ updatedAt: nowIso(now),
147
+ exportedAt: nowIso(now),
148
+ exporter: { name: 'dsh-todo-time-log' },
149
+ count: todos.length,
150
+ todos: todos.map((todo) => ({
151
+ id: todo.id,
152
+ title: todo.title,
153
+ project: todo.project ?? '',
154
+ files: Array.isArray(todo.files) ? todo.files.slice() : [],
155
+ status: todo.status === 'completed' ? 'completed' : 'pending',
156
+ priority: todo.priority ?? '',
157
+ type: todo.type ?? '',
158
+ createdAt: todo.createdAt,
159
+ completedAt: todo.completedAt ?? null,
160
+ updatedAt: todo.updatedAt,
161
+ })),
162
+ };
163
+ return `${JSON.stringify(envelope, null, 2)}\n`;
164
+ }
165
+
166
+ /**
167
+ * Build the CSV document (BOM + header + one row per todo).
168
+ *
169
+ * @param {object[]} todos
170
+ * @returns {string}
171
+ */
172
+ export function buildExportCsv(todos) {
173
+ const lines = [CSV_HEADER.map(escapeCsvField).join(',')];
174
+ for (const todo of todos) {
175
+ lines.push([
176
+ todo.id,
177
+ todo.title,
178
+ todo.project ?? '',
179
+ Array.isArray(todo.files) ? todo.files.join(';') : '',
180
+ todo.status === 'completed' ? '已完成' : '未完成',
181
+ PRIORITY_CSV[todo.priority] ?? '',
182
+ TYPE_CSV[todo.type] ?? '',
183
+ csvTimestamp(todo.createdAt),
184
+ csvTimestamp(todo.completedAt),
185
+ csvTimestamp(todo.updatedAt),
186
+ durationMinutes(todo),
187
+ ].map(escapeCsvField).join(','));
188
+ }
189
+ return `${CSV_BOM}${lines.join('\r\n')}\r\n`;
190
+ }
191
+
192
+ /**
193
+ * Serialize todos for download. `format` must be one of `EXPORT_FORMATS`; an
194
+ * unknown value falls back to JSON (the route validates it first).
195
+ *
196
+ * @param {object[]} todos
197
+ * @param {{ format?: string, now?: number }} [options]
198
+ * @returns {{ format: string, mime: string, filename: string, count: number, content: string }}
199
+ */
200
+ export function exportTodoData(todos, options = {}) {
201
+ const source = Array.isArray(todos) ? todos : [];
202
+ const now = typeof options.now === 'number' ? options.now : Date.now();
203
+ const format = options.format === 'csv' ? 'csv' : 'json';
204
+ const stamp = filenameStamp(now);
205
+ if (format === 'csv') {
206
+ return {
207
+ format,
208
+ mime: 'text/csv;charset=utf-8',
209
+ filename: `todos-${stamp}.csv`,
210
+ count: source.length,
211
+ content: buildExportCsv(source),
212
+ };
213
+ }
214
+ return {
215
+ format,
216
+ mime: 'application/json;charset=utf-8',
217
+ filename: `todos-${stamp}.json`,
218
+ count: source.length,
219
+ content: buildExportJson(source, { now }),
220
+ };
221
+ }
222
+
223
+ /** Parse a naive local `YYYY-MM-DD HH:mm[:ss]` or any `Date.parse`-able value. */
224
+ function importTimestamp(value) {
225
+ if (value instanceof Date) {
226
+ return Number.isFinite(value.getTime()) ? value.toISOString() : undefined;
227
+ }
228
+ if (typeof value === 'number') {
229
+ return Number.isFinite(value) ? new Date(value).toISOString() : undefined;
230
+ }
231
+ if (typeof value !== 'string') return undefined;
232
+ const text = value.trim();
233
+ if (text === '') return undefined;
234
+ const match = NAIVE_DATETIME.exec(text);
235
+ if (match !== null) {
236
+ const date = new Date(
237
+ Number(match[1]),
238
+ Number(match[2]) - 1,
239
+ Number(match[3]),
240
+ Number(match[4] ?? 0),
241
+ Number(match[5] ?? 0),
242
+ Number(match[6] ?? 0),
243
+ );
244
+ return Number.isFinite(date.getTime()) ? date.toISOString() : text;
245
+ }
246
+ const ms = parseTimestamp(text);
247
+ return ms === null ? text : new Date(ms).toISOString();
248
+ }
249
+
250
+ /** Map a status cell (English or Chinese) onto the stored enum. */
251
+ function importStatus(value, completedAt) {
252
+ const text = String(value ?? '').trim().toLowerCase();
253
+ if (COMPLETED_STATUS_ALIASES.has(text)) return 'completed';
254
+ if (PENDING_STATUS_ALIASES.has(text)) {
255
+ if (text === '' && completedAt !== null && completedAt !== undefined && completedAt !== '') {
256
+ return 'completed';
257
+ }
258
+ return 'pending';
259
+ }
260
+ return String(value ?? '').trim();
261
+ }
262
+
263
+ /** Map a priority cell (English or Chinese) onto the stored enum. */
264
+ function importPriority(value) {
265
+ const text = String(value ?? '').trim().toLowerCase();
266
+ return Object.prototype.hasOwnProperty.call(PRIORITY_ALIASES, text)
267
+ ? PRIORITY_ALIASES[text]
268
+ : String(value ?? '').trim();
269
+ }
270
+
271
+ /** Map a type cell (English or Chinese) onto the stored enum. */
272
+ function importType(value) {
273
+ const text = String(value ?? '').trim().toLowerCase();
274
+ return Object.prototype.hasOwnProperty.call(TYPE_ALIASES, text)
275
+ ? TYPE_ALIASES[text]
276
+ : String(value ?? '').trim();
277
+ }
278
+
279
+ /** Split a `files` cell (`;` or full-width `;`); arrays pass through. */
280
+ function importFiles(value) {
281
+ if (Array.isArray(value)) return value;
282
+ if (typeof value !== 'string' || value.trim() === '') return [];
283
+ return value.split(/[;;]/).map((file) => file.trim()).filter((file) => file !== '');
284
+ }
285
+
286
+ /** Coerce one JSON row into the shape `normalizeTodo()` expects. */
287
+ function prepareJsonRow(raw) {
288
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return raw;
289
+ const row = { ...raw };
290
+ row.files = importFiles(row.files);
291
+ row.status = importStatus(row.status, row.completedAt);
292
+ row.priority = importPriority(row.priority);
293
+ row.type = importType(row.type);
294
+ row.createdAt = importTimestamp(row.createdAt);
295
+ row.updatedAt = importTimestamp(row.updatedAt);
296
+ if (row.completedAt === null || row.completedAt === undefined || row.completedAt === '') {
297
+ row.completedAt = null;
298
+ } else {
299
+ row.completedAt = importTimestamp(row.completedAt);
300
+ }
301
+ return row;
302
+ }
303
+
304
+ /** Index a CSV header row onto the field names above. */
305
+ function mapCsvHeader(cells) {
306
+ const index = new Map();
307
+ cells.forEach((cell, position) => {
308
+ const header = String(cell ?? '').replace(/^\uFEFF/, '').trim().toLowerCase();
309
+ if (header === '') return;
310
+ for (const field of Object.keys(HEADER_ALIASES)) {
311
+ if (HEADER_ALIASES[field].includes(header) && !index.has(field)) {
312
+ index.set(field, position);
313
+ }
314
+ }
315
+ });
316
+ return index;
317
+ }
318
+
319
+ /**
320
+ * RFC 4180-compatible CSV reader: quoted fields, doubled quotes and embedded
321
+ * CR/LF inside quotes. Returns an array of rows (arrays of cell strings).
322
+ */
323
+ function parseCsvRows(text) {
324
+ const rows = [];
325
+ let row = [];
326
+ let field = '';
327
+ let inQuotes = false;
328
+ for (let i = 0; i < text.length; i += 1) {
329
+ const char = text[i];
330
+ if (inQuotes) {
331
+ if (char === '"') {
332
+ if (text[i + 1] === '"') {
333
+ field += '"';
334
+ i += 1;
335
+ } else {
336
+ inQuotes = false;
337
+ }
338
+ } else {
339
+ field += char;
340
+ }
341
+ continue;
342
+ }
343
+ if (char === '"') {
344
+ inQuotes = true;
345
+ continue;
346
+ }
347
+ if (char === ',') {
348
+ row.push(field);
349
+ field = '';
350
+ continue;
351
+ }
352
+ if (char === '\r' || char === '\n') {
353
+ if (char === '\r' && text[i + 1] === '\n') i += 1;
354
+ row.push(field);
355
+ field = '';
356
+ if (row.length > 1 || row[0] !== '') rows.push(row);
357
+ else if (row.length === 1 && row[0] === '') {
358
+ // blank line: ignore
359
+ }
360
+ row = [];
361
+ continue;
362
+ }
363
+ field += char;
364
+ }
365
+ if (field !== '' || row.length > 0) {
366
+ row.push(field);
367
+ if (row.length > 1 || row[0] !== '') rows.push(row);
368
+ }
369
+ return rows;
370
+ }
371
+
372
+ /** Detect JSON vs CSV from the first non-space character. */
373
+ function detectFormat(text) {
374
+ const head = text.replace(/^\uFEFF/, '').trimStart();
375
+ return head.startsWith('{') || head.startsWith('[') ? 'json' : 'csv';
376
+ }
377
+
378
+ /** Normalize a caller-provided format hint (`json`, `.csv`, MIME type). */
379
+ function normalizeFormat(value) {
380
+ if (typeof value !== 'string') return null;
381
+ const text = value.trim().toLowerCase().replace(/^\./, '');
382
+ if (text === 'json' || text === 'application/json' || text === 'text/json') return 'json';
383
+ if (text === 'csv' || text === 'text/csv' || text === 'application/csv') return 'csv';
384
+ return null;
385
+ }
386
+
387
+ /**
388
+ * Normalize parsed rows and fold duplicate ids (newest `updatedAt` wins).
389
+ * Row numbers in `invalid` are file row numbers (CSV: 1 = header).
390
+ */
391
+ function normalizeRows(rows, options) {
392
+ const { now, makeId, rowBase } = options;
393
+ const byId = new Map();
394
+ const invalid = [];
395
+ const notices = [];
396
+ let invalidCount = 0;
397
+ let repaired = 0;
398
+ let duplicates = 0;
399
+ rows.forEach((row, position) => {
400
+ const rowNumber = rowBase + position;
401
+ const normalized = normalizeTodo(row, { now, makeId });
402
+ if (normalized.todo === null) {
403
+ invalidCount += 1;
404
+ if (invalid.length < MAX_INVALID_DETAILS) {
405
+ invalid.push({
406
+ row: rowNumber,
407
+ message: normalized.notices[0] ?? '记录格式非法',
408
+ });
409
+ }
410
+ return;
411
+ }
412
+ const todo = normalized.todo;
413
+ const meaningful = normalized.notices.filter((notice) => !notice.includes('缺少 id'));
414
+ if (meaningful.length > 0) repaired += 1;
415
+ const existing = byId.get(todo.id);
416
+ if (existing === undefined) {
417
+ byId.set(todo.id, todo);
418
+ return;
419
+ }
420
+ duplicates += 1;
421
+ const existingMs = parseTimestamp(existing.updatedAt);
422
+ const incomingMs = parseTimestamp(todo.updatedAt);
423
+ if (incomingMs !== null && (existingMs === null || incomingMs > existingMs)) {
424
+ byId.set(todo.id, todo);
425
+ }
426
+ });
427
+ if (repaired > 0) notices.push(`已修复 ${repaired} 条记录的字段格式`);
428
+ if (duplicates > 0) notices.push(`文件内有 ${duplicates} 条重复 id 的记录,已保留更新时间较新的一条`);
429
+ if (invalidCount > 0) notices.push(`已跳过 ${invalidCount} 行无法识别的记录`);
430
+ return { records: [...byId.values()], invalid, invalidCount, notices };
431
+ }
432
+
433
+ function parseJsonImport(text, options) {
434
+ let parsed;
435
+ try {
436
+ parsed = JSON.parse(text.replace(/^\uFEFF/, ''));
437
+ } catch {
438
+ return { ok: false, code: 'IMPORT_INVALID', message: 'JSON 解析失败:文件不是合法 JSON' };
439
+ }
440
+ const extracted = extractStoreRows(parsed);
441
+ if (extracted.ok !== true) {
442
+ if (extracted.code === 'VERSION_UNSUPPORTED') {
443
+ return { ok: false, code: 'IMPORT_VERSION_UNSUPPORTED', message: extracted.message };
444
+ }
445
+ return { ok: false, code: 'IMPORT_INVALID', message: `JSON 结构异常:${extracted.message}` };
446
+ }
447
+ const rows = extracted.rows.map(prepareJsonRow);
448
+ const normalized = normalizeRows(rows, {
449
+ now: options.now,
450
+ makeId: options.makeId,
451
+ rowBase: 1,
452
+ });
453
+ if (normalized.records.length === 0) {
454
+ return {
455
+ ok: false,
456
+ code: 'IMPORT_INVALID',
457
+ message: '文件里没有可导入的待办(标题为空或记录格式非法)',
458
+ };
459
+ }
460
+ if (normalized.records.length > MAX_TODOS) {
461
+ return {
462
+ ok: false,
463
+ code: 'IMPORT_TOO_MANY',
464
+ message: `单次导入不能超过 ${MAX_TODOS} 条待办`,
465
+ };
466
+ }
467
+ const notices = normalized.notices.slice();
468
+ if (normalized.invalidCount > 0) {
469
+ notices.push(`共读取 ${rows.length} 行,有效 ${normalized.records.length} 条`);
470
+ }
471
+ return {
472
+ ok: true,
473
+ format: 'json',
474
+ records: normalized.records,
475
+ invalid: normalized.invalid,
476
+ invalidCount: normalized.invalidCount,
477
+ rowCount: rows.length,
478
+ notices,
479
+ };
480
+ }
481
+
482
+ function parseCsvImport(text, options) {
483
+ const rows = parseCsvRows(text.replace(/^\uFEFF/, ''));
484
+ if (rows.length === 0) {
485
+ return { ok: false, code: 'IMPORT_EMPTY', message: 'CSV 文件是空的' };
486
+ }
487
+ const header = mapCsvHeader(rows[0]);
488
+ if (!header.has('title')) {
489
+ return {
490
+ ok: false,
491
+ code: 'IMPORT_INVALID',
492
+ message: 'CSV 缺少「标题」列(可识别的列名:标题/title、分类/project、状态/status 等)',
493
+ };
494
+ }
495
+ const get = (row, field) => {
496
+ const position = header.get(field);
497
+ if (position === undefined) return undefined;
498
+ const cell = row[position];
499
+ return typeof cell === 'string' ? cell.trim() : '';
500
+ };
501
+ const dataRows = rows.slice(1).filter((row) => row.some((cell) => String(cell ?? '').trim() !== ''));
502
+ const prepared = dataRows.map((row) => ({
503
+ id: get(row, 'id'),
504
+ title: get(row, 'title'),
505
+ project: get(row, 'project'),
506
+ files: importFiles(get(row, 'files') ?? ''),
507
+ status: get(row, 'status') ?? '',
508
+ priority: get(row, 'priority'),
509
+ type: get(row, 'type'),
510
+ createdAt: get(row, 'createdAt'),
511
+ completedAt: get(row, 'completedAt'),
512
+ updatedAt: get(row, 'updatedAt'),
513
+ }));
514
+ const normalized = normalizeRows(prepared.map(prepareJsonRow), {
515
+ now: options.now,
516
+ makeId: options.makeId,
517
+ rowBase: 2,
518
+ });
519
+ if (normalized.records.length === 0) {
520
+ return {
521
+ ok: false,
522
+ code: 'IMPORT_INVALID',
523
+ message: 'CSV 里没有可导入的待办(标题为空或记录格式非法)',
524
+ };
525
+ }
526
+ if (normalized.records.length > MAX_TODOS) {
527
+ return {
528
+ ok: false,
529
+ code: 'IMPORT_TOO_MANY',
530
+ message: `单次导入不能超过 ${MAX_TODOS} 条待办`,
531
+ };
532
+ }
533
+ const notices = normalized.notices.slice();
534
+ if (normalized.invalidCount > 0) {
535
+ notices.push(`共读取 ${dataRows.length} 行,有效 ${normalized.records.length} 条`);
536
+ }
537
+ return {
538
+ ok: true,
539
+ format: 'csv',
540
+ records: normalized.records,
541
+ invalid: normalized.invalid,
542
+ invalidCount: normalized.invalidCount,
543
+ rowCount: dataRows.length,
544
+ notices,
545
+ };
546
+ }
547
+
548
+ /**
549
+ * Parse an uploaded file into normalized records.
550
+ *
551
+ * @param {string} text
552
+ * @param {{ format?: string, now?: number, makeId?: () => string }} [options]
553
+ * @returns {object}
554
+ */
555
+ export function parseImportText(text, options = {}) {
556
+ if (typeof text !== 'string' || text.trim() === '') {
557
+ return { ok: false, code: 'IMPORT_EMPTY', message: '导入内容为空' };
558
+ }
559
+ const now = typeof options.now === 'number' ? options.now : Date.now();
560
+ const makeId = typeof options.makeId === 'function' ? options.makeId : makeTodoId;
561
+ const requested = options.format === undefined || options.format === null || options.format === ''
562
+ ? null
563
+ : options.format;
564
+ const requestedFormat = requested === null ? null : normalizeFormat(requested);
565
+ if (requested !== null && requestedFormat === null) {
566
+ return { ok: false, code: 'IMPORT_FORMAT_UNSUPPORTED', message: '只支持 JSON 或 CSV 文件' };
567
+ }
568
+ const format = requestedFormat ?? detectFormat(text);
569
+ const parsed = format === 'json'
570
+ ? parseJsonImport(text, { now, makeId })
571
+ : parseCsvImport(text, { now, makeId });
572
+ return parsed;
573
+ }
package/package.json CHANGED
@@ -1,13 +1,24 @@
1
1
  {
2
2
  "name": "dsh-todo-time-log",
3
- "version": "0.6.0",
4
- "description": "查看待办事项,并记录与展示每个待办的创建时间与完成时间(Todo time log for DeepSeek Harness)",
3
+ "version": "0.6.2",
4
+ "description": "DeepSeek Harness 待办插件:自动记录每条待办的创建与完成时间,四视图(表格 / 看板 / 甘特图 / 日历)呈现真实耗时(Todo time log for DeepSeek Harness)",
5
5
  "keywords": [
6
6
  "dsh",
7
7
  "dsh-plugin",
8
+ "dsh-plugins",
9
+ "deepseek",
8
10
  "deepseek-harness",
11
+ "harness",
12
+ "plugins",
9
13
  "todo",
10
- "time-log"
14
+ "todo-list",
15
+ "time-log",
16
+ "time-tracking",
17
+ "gantt",
18
+ "kanban",
19
+ "calendar",
20
+ "productivity",
21
+ "ai-agent"
11
22
  ],
12
23
  "license": "MIT",
13
24
  "author": "FantasyStarry",
@@ -32,6 +43,7 @@
32
43
  "lib/files.js",
33
44
  "lib/parse.js",
34
45
  "lib/store.js",
46
+ "lib/transfer.js",
35
47
  "lib/time.js",
36
48
  "lib/client.js",
37
49
  "cordis.patch.yml",
@@ -53,11 +65,11 @@
53
65
  },
54
66
  "scripts": {
55
67
  "build": "node scripts/build-client.mjs",
56
- "check": "node --check lib/time.js && node --check lib/parse.js && node --check lib/files.js && node --check lib/store.js && node --check lib/index.js && node --check lib/client.js",
68
+ "check": "node --check lib/time.js && node --check lib/parse.js && node --check lib/files.js && node --check lib/store.js && node --check lib/transfer.js && node --check lib/index.js && node --check lib/client.js",
57
69
  "lint": "eslint .",
58
70
  "typecheck": "tsc -p tsconfig.json",
59
- "test": "node --test test/parse.test.mjs test/smoke.test.mjs test/http.test.mjs test/ui/panel.test.mjs test/store-concurrency.test.mjs",
60
- "test:coverage": "node --test --experimental-test-coverage test/parse.test.mjs test/smoke.test.mjs test/http.test.mjs test/ui/panel.test.mjs test/store-concurrency.test.mjs",
71
+ "test": "node --test test/parse.test.mjs test/smoke.test.mjs test/http.test.mjs test/transfer.test.mjs test/store-import.test.mjs test/http-transfer.test.mjs test/ui/panel.test.mjs test/store-concurrency.test.mjs",
72
+ "test:coverage": "node --test --experimental-test-coverage test/parse.test.mjs test/smoke.test.mjs test/http.test.mjs test/transfer.test.mjs test/store-import.test.mjs test/http-transfer.test.mjs test/ui/panel.test.mjs test/store-concurrency.test.mjs",
61
73
  "audit": "node test/client-audit.mjs",
62
74
  "verify": "npm run check && npm run lint && npm run typecheck && npm run build && npm test && npm run audit",
63
75
  "prepublishOnly": "npm run verify"