dsh-project-recall 0.3.0 → 0.3.1

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1 — 2026-11-22
4
+
5
+ 把 Codex 版 / 飞牛上的待办对齐进续忆。
6
+
7
+ - 新增 `scripts/import-from-nas.mjs`(`npm run import:nas`):从 Codex 版 project-memory 的 HTTP 接口拉计划,按「项目名 + 标题」去重后合并进续忆,默认 dry-run,`--apply` 才写;`--all` 连已结束的一起搬,`--token` 支持同步令牌。
8
+ - 两边的差异有了正式说法:续忆不读 Codex 版 SQLite,两个面板条数不同是设计如此;对齐走这个脚本,只增不改。
9
+ - README 补「与 Codex 版 / 飞牛对齐」一节。
10
+
3
11
  ## 0.3.0 — 2026-11-22
4
12
 
5
13
  在续忆里点一下「去做」,DSH 直接开一个会话来动手。
package/README.md CHANGED
@@ -101,6 +101,23 @@ HTTP 接口:`POST /project-memory/api/plans/:id/dispatch`,body 可带 `mode`
101
101
 
102
102
  建议在覆盖导入或清空前先导出一份 JSON。
103
103
 
104
+ ## 与 Codex 版 / 飞牛对齐
105
+
106
+ 续忆用的是 DSH 独立数据域,**不读** Codex 版(本机 SQLite + 飞牛 4318 服务)那份库,两边各记各的——所以同一个项目的待办会在两个面板里看到不同的条数,这是设计如此,不是丢数据。
107
+
108
+ 要把 Codex 版里还没结束的计划并进来,仓库带了一个一次性对齐脚本:
109
+
110
+ ```bash
111
+ node scripts/import-from-nas.mjs # dry-run,只打印会新增哪些
112
+ node scripts/import-from-nas.mjs --apply # 真正写进续忆
113
+ node scripts/import-from-nas.mjs --all # 连 done / dropped 一起
114
+ ```
115
+
116
+ - 源默认 `http://192.168.5.8:4318`(飞牛),目标默认 `http://127.0.0.1:52497`(本机 DSH),可用 `--source` / `--target` 或环境变量 `PROJECT_MEMORY_NAS_URL`、`DSH_URL` 覆盖。
117
+ - 默认只搬未结束(`candidate` / `idea` / `someday` / `planned` / `blocked`)的计划,按「项目名 + 标题」去重,已经存在的跳过;缺的项目会一起补上。
118
+ - 源需要 `x-sync-token` 时加 `--token`(或 `PROJECT_MEMORY_SYNC_TOKEN`)。
119
+ - 只会新增,不会改动或删除续忆里已有的计划。
120
+
104
121
  ## 数据
105
122
 
106
123
  - 使用 DSH `storageDomain` 的独立域 `project_memory`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-project-recall",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "续忆 — 为 DeepSeek Harness 保存跨会话的延后计划,并在合适的时候提醒你回来继续。",
@@ -24,6 +24,7 @@
24
24
  "index.js",
25
25
  "client.js",
26
26
  "lib/*.js",
27
+ "scripts/import-from-nas.mjs",
27
28
  "cordis.patch.yml",
28
29
  "locale/*.json",
29
30
  "icon.svg",
@@ -49,7 +50,8 @@
49
50
  },
50
51
  "scripts": {
51
52
  "test": "node --test",
52
- "check": "node --check index.js && node --check client.js && node --check lib/model.js && node --check lib/store.js && node --check lib/http.js && node --check lib/tools.js && node --check lib/dispatch.js"
53
+ "check": "node --check index.js && node --check client.js && node --check lib/model.js && node --check lib/store.js && node --check lib/http.js && node --check lib/tools.js && node --check lib/dispatch.js",
54
+ "import:nas": "node scripts/import-from-nas.mjs"
53
55
  },
54
56
  "repository": {
55
57
  "type": "git",
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 把 Codex 版 project-memory(本机 SQLite / 飞牛上的 4318 服务)里还没结束的计划
4
+ * 合并进 DSH 续忆(dsh-project-recall)的 project_memory 存储域。
5
+ *
6
+ * 默认只做 dry-run,打印「会新增哪些」,加 --apply 才真的写。
7
+ *
8
+ * node scripts/import-from-nas.mjs # 看差异
9
+ * node scripts/import-from-nas.mjs --apply # 真导入
10
+ * node scripts/import-from-nas.mjs --all # 连 done/dropped 一起
11
+ * node scripts/import-from-nas.mjs --source http://127.0.0.1:4318 --target http://127.0.0.1:52497
12
+ */
13
+
14
+ const OPEN_STATUSES = new Set(['candidate', 'idea', 'someday', 'planned', 'blocked']);
15
+
16
+ function parseArgs(argv) {
17
+ const options = {
18
+ source: process.env.PROJECT_MEMORY_NAS_URL || 'http://192.168.5.8:4318',
19
+ target: process.env.DSH_URL || 'http://127.0.0.1:52497',
20
+ token: process.env.PROJECT_MEMORY_SYNC_TOKEN || '',
21
+ apply: false,
22
+ all: false,
23
+ };
24
+ for (let index = 0; index < argv.length; index += 1) {
25
+ const arg = argv[index];
26
+ if (arg === '--apply') options.apply = true;
27
+ else if (arg === '--all') options.all = true;
28
+ else if (arg === '--source') options.source = argv[++index];
29
+ else if (arg === '--target') options.target = argv[++index];
30
+ else if (arg === '--token') options.token = argv[++index];
31
+ else if (arg === '--help' || arg === '-h') {
32
+ console.log('用法: node scripts/import-from-nas.mjs [--apply] [--all] [--source URL] [--target URL] [--token TOKEN]');
33
+ process.exit(0);
34
+ } else {
35
+ console.error(`未知参数: ${arg}`);
36
+ process.exit(2);
37
+ }
38
+ }
39
+ options.source = String(options.source || '').replace(/\/+$/, '');
40
+ options.target = String(options.target || '').replace(/\/+$/, '');
41
+ return options;
42
+ }
43
+
44
+ function trim(value) {
45
+ return String(value ?? '').trim();
46
+ }
47
+
48
+ function key(projectName, title) {
49
+ return `${trim(projectName).toLowerCase()}::${trim(title).replace(/\s+/g, ' ').toLowerCase()}`;
50
+ }
51
+
52
+ async function getJson(url, headers = {}) {
53
+ const response = await fetch(url, { headers });
54
+ if (!response.ok) {
55
+ throw new Error(`${url} → HTTP ${response.status}`);
56
+ }
57
+ return response.json();
58
+ }
59
+
60
+ async function main() {
61
+ const options = parseArgs(process.argv.slice(2));
62
+ const headers = options.token ? { 'x-sync-token': options.token } : {};
63
+
64
+ console.log(`源(Codex 版): ${options.source}`);
65
+ console.log(`目标(DSH 续忆): ${options.target}`);
66
+
67
+ const [remoteProjects, remotePlans, exported] = await Promise.all([
68
+ getJson(`${options.source}/api/projects`, headers),
69
+ getJson(`${options.source}/api/plans`, headers),
70
+ // /plans 只返回未结束的计划,去重要用 /export 的全量(含 done/dropped)
71
+ getJson(`${options.target}/project-memory/api/export`, { origin: options.target }),
72
+ ]);
73
+
74
+ const projects = Array.isArray(remoteProjects) ? remoteProjects : remoteProjects.projects ?? [];
75
+ const plans = Array.isArray(remotePlans) ? remotePlans : remotePlans.plans ?? [];
76
+ const existing = Array.isArray(exported) ? exported : exported.plans ?? [];
77
+ const projectName = new Map(projects.map((project) => [project.id, project.name]));
78
+ const targetProjects = Array.isArray(exported) ? [] : exported.projects ?? [];
79
+ const targetProjectName = new Map(targetProjects.map((project) => [project.id, project.name]));
80
+
81
+ const seen = new Set(
82
+ existing.map((plan) => key(plan.project?.name ?? targetProjectName.get(plan.project_id) ?? '', plan.title)),
83
+ );
84
+ const knownProjectIds = new Set(existing.map((plan) => plan.project_id));
85
+
86
+ const wanted = plans.filter((plan) => options.all || OPEN_STATUSES.has(plan.status));
87
+ const fresh = [];
88
+ for (const plan of wanted) {
89
+ const name = projectName.get(plan.project_id) ?? '未归档';
90
+ const planKey = key(name, plan.title);
91
+ if (seen.has(planKey)) continue;
92
+ seen.add(planKey);
93
+ fresh.push({ plan, name });
94
+ }
95
+
96
+ const wantedProjects = new Map();
97
+ for (const { plan, name } of fresh) {
98
+ const project = projects.find((item) => item.id === plan.project_id);
99
+ const id = project?.id ?? 'inbox';
100
+ if (knownProjectIds.has(id)) continue;
101
+ wantedProjects.set(id, {
102
+ id,
103
+ name: name || '未归档',
104
+ root_path: project?.root_path ?? 'inbox',
105
+ created_at: project?.created_at ?? plan.created_at,
106
+ updated_at: project?.updated_at ?? plan.updated_at,
107
+ });
108
+ }
109
+
110
+ console.log(`源里 ${plans.length} 条(${options.all ? '全部状态' : '仅未结束'} ${wanted.length} 条),DSH 侧现有 ${existing.length} 条。`);
111
+ if (fresh.length === 0) {
112
+ console.log('没有需要新增的计划,两边已经对齐。');
113
+ return;
114
+ }
115
+
116
+ console.log(`\n会新增 ${fresh.length} 条:`);
117
+ for (const { plan, name } of fresh) {
118
+ console.log(` • [${plan.status}] ${trim(plan.title).slice(0, 70)} (${name})`);
119
+ }
120
+ if (wantedProjects.size > 0) {
121
+ console.log(`\n会补 ${wantedProjects.size} 个项目:${[...wantedProjects.values()].map((project) => project.name).join('、')}`);
122
+ }
123
+
124
+ if (!options.apply) {
125
+ console.log('\n这是 dry-run。确认无误后加 --apply 真正写进 DSH 续忆。');
126
+ return;
127
+ }
128
+
129
+ const payload = {
130
+ format: 'dsh-project-recall',
131
+ version: 1,
132
+ projects: [...wantedProjects.values()],
133
+ plans: fresh.map(({ plan }) => ({
134
+ id: plan.id,
135
+ project_id: plan.project_id,
136
+ title: plan.title,
137
+ details: plan.details ?? '',
138
+ status: plan.status,
139
+ reason_deferred: plan.reason_deferred ?? '',
140
+ reactivation_conditions: Array.isArray(plan.reactivation_conditions) ? plan.reactivation_conditions : [],
141
+ tags: Array.isArray(plan.tags) ? plan.tags : [],
142
+ priority: plan.priority ?? 'medium',
143
+ effort: plan.effort ?? 'unknown',
144
+ source_type: plan.source_type ?? 'conversation',
145
+ source_ref: plan.source_ref ?? '',
146
+ source_excerpt: plan.source_excerpt ?? '',
147
+ review_at: plan.review_at ?? null,
148
+ last_reviewed_at: plan.last_reviewed_at ?? null,
149
+ completed_at: plan.completed_at ?? null,
150
+ created_at: plan.created_at,
151
+ updated_at: plan.updated_at,
152
+ })),
153
+ };
154
+
155
+ const response = await fetch(`${options.target}/project-memory/api/import`, {
156
+ method: 'POST',
157
+ headers: { 'content-type': 'application/json', origin: options.target },
158
+ body: JSON.stringify({ ...payload, mode: 'merge' }),
159
+ });
160
+ const text = await response.text();
161
+ if (!response.ok) {
162
+ throw new Error(`导入失败 HTTP ${response.status}: ${text.slice(0, 300)}`);
163
+ }
164
+ console.log(`\n导入完成: ${text}`);
165
+ }
166
+
167
+ main().catch((error) => {
168
+ console.error(`失败: ${error.message}`);
169
+ process.exit(1);
170
+ });