dsh-project-recall 0.3.0 → 0.4.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 +21 -0
- package/README.md +29 -1
- package/client.js +112 -0
- package/index.js +9 -1
- package/lib/http.js +25 -0
- package/lib/store.js +42 -6
- package/lib/sync.js +225 -0
- package/lib/tools.js +31 -0
- package/package.json +8 -5
- package/scripts/import-from-nas.mjs +112 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0 — 2026-11-22
|
|
4
|
+
|
|
5
|
+
对齐不必再手动跑脚本:续忆自己会定时把 Codex 版补齐。
|
|
6
|
+
|
|
7
|
+
- 设置页新增「自动对齐 Codex 版」:开关、地址、间隔(分钟)都在里面,还有一个「立即对齐」。地址填 `http://192.168.5.8:4318`(飞牛)或本机 `:4318`。
|
|
8
|
+
- 插件启动 15 秒后试一次,之后每分钟看一眼是否到点;按「项目 + 标题」去重,只增不改,失败的只记日志并在设置页显示,不打扰面板。
|
|
9
|
+
- 环境变量 `PROJECT_MEMORY_NAS_URL` / `PROJECT_MEMORY_SYNC_TOKEN` 可以预设地址和令牌,首次装好就自动开着。
|
|
10
|
+
- 新 HTTP 接口 `GET /project-memory/api/sync`(看配置与上次结果)、`POST /project-memory/api/sync`(立刻对齐,body 可带 `source` / `interval_minutes` / `include_closed`)。
|
|
11
|
+
- 新 Agent 工具 `project_memory_sync_now`:问「为什么两边条数不一样 / 对齐一下」时,Agent 自己就能跑。
|
|
12
|
+
- `scripts/import-from-nas.mjs` 改为复用 `lib/sync.js` 的同一套去重逻辑,脚本和插件不会再算出两种结果。
|
|
13
|
+
- 测试:新增 `test/sync.test.js`,HTTP 侧补 `/sync` 用例,共 40 个用例全绿。
|
|
14
|
+
- 修 `package.json` 里的仓库地址(原 `hhse` 账号已不存在)指向备份仓库 `hseons/dsh-backup`。
|
|
15
|
+
|
|
16
|
+
## 0.3.1 — 2026-11-22
|
|
17
|
+
|
|
18
|
+
把 Codex 版 / 飞牛上的待办对齐进续忆。
|
|
19
|
+
|
|
20
|
+
- 新增 `scripts/import-from-nas.mjs`(`npm run import:nas`):从 Codex 版 project-memory 的 HTTP 接口拉计划,按「项目名 + 标题」去重后合并进续忆,默认 dry-run,`--apply` 才写;`--all` 连已结束的一起搬,`--token` 支持同步令牌。
|
|
21
|
+
- 两边的差异有了正式说法:续忆不读 Codex 版 SQLite,两个面板条数不同是设计如此;对齐走这个脚本,只增不改。
|
|
22
|
+
- README 补「与 Codex 版 / 飞牛对齐」一节。
|
|
23
|
+
|
|
3
24
|
## 0.3.0 — 2026-11-22
|
|
4
25
|
|
|
5
26
|
在续忆里点一下「去做」,DSH 直接开一个会话来动手。
|
package/README.md
CHANGED
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
- **完整上下文**:为什么现在不做、什么条件下回来、下一步从哪继续,都记在详情里。
|
|
22
22
|
- **搜索与项目筛选**:按关键词、项目查找已经记过的事。
|
|
23
23
|
- **Agent 原生工具**:DSH 里的模型可以直接提出、搜索、更新计划。
|
|
24
|
+
- **自动对齐 Codex 版**:设置页填一次地址,之后按间隔把 Codex 版 / 飞牛里还没结束的计划补进来,只增不改。
|
|
24
25
|
- **备份与恢复**:设置页导出/导入 JSON;支持合并或覆盖,清空数据需要手动输入确认。
|
|
25
26
|
- **本地优先**:数据只保存在本机 DSH 数据域,不发送任何遥测。
|
|
26
27
|
|
|
27
28
|
## 要求
|
|
28
29
|
|
|
29
30
|
- DSH `>= 0.2.1-rc.3`
|
|
30
|
-
- 当前版本:`0.
|
|
31
|
+
- 当前版本:`0.4.0`(自动对齐版)
|
|
31
32
|
|
|
32
33
|
## 安装
|
|
33
34
|
|
|
@@ -86,6 +87,7 @@ HTTP 接口:`POST /project-memory/api/plans/:id/dispatch`,body 可带 `mode`
|
|
|
86
87
|
| `project_memory_get_plan` | 读取单条计划的完整上下文 |
|
|
87
88
|
| `project_memory_update_plan` | 修改状态、复盘时间、内容 |
|
|
88
89
|
| `project_memory_dispatch_plan` | 把一件计划交给一个会真正动手的会话执行 |
|
|
90
|
+
| `project_memory_sync_now` | 立刻与 Codex 版 / 飞牛对一次齐 |
|
|
89
91
|
|
|
90
92
|
模型会被提示:只记录**明确推迟的具体工作**,模糊想法和普通待办不记;调用时尽量传入当前工作目录的绝对路径。
|
|
91
93
|
|
|
@@ -101,6 +103,32 @@ HTTP 接口:`POST /project-memory/api/plans/:id/dispatch`,body 可带 `mode`
|
|
|
101
103
|
|
|
102
104
|
建议在覆盖导入或清空前先导出一份 JSON。
|
|
103
105
|
|
|
106
|
+
## 与 Codex 版 / 飞牛对齐
|
|
107
|
+
|
|
108
|
+
续忆用的是 DSH 独立数据域,**不读** Codex 版(本机 SQLite + 飞牛 4318 服务)那份库,两边各记各的——所以同一个项目的待办会在两个面板里看到不同的条数,这是设计如此,不是丢数据。
|
|
109
|
+
|
|
110
|
+
要把 Codex 版里还没结束的计划并进来,两种办法:
|
|
111
|
+
|
|
112
|
+
**自动(推荐)**:设置 →「续忆」→「自动对齐 Codex 版」
|
|
113
|
+
|
|
114
|
+
- 打开开关、填地址(`http://192.168.5.8:4318` 或本机 `:4318`)、设间隔(默认 30 分钟),下面有「立即对齐」和上次结果。
|
|
115
|
+
- 插件启动 15 秒后试一次,之后每分钟检查是否到点;按「项目 + 标题」去重,只增不改。
|
|
116
|
+
- 失败不打扰面板,只在设置页留一行原因;地址填 `PROJECT_MEMORY_NAS_URL` 环境变量可在装好时就默认开着。
|
|
117
|
+
- Agent 侧有 `project_memory_sync_now`,问一句「对齐一下」它就能跑;接口是 `POST /project-memory/api/sync`。
|
|
118
|
+
|
|
119
|
+
**手动**:仓库带了一个一次性对齐脚本(与自动对齐共用同一套去重逻辑):
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
node scripts/import-from-nas.mjs # dry-run,只打印会新增哪些
|
|
123
|
+
node scripts/import-from-nas.mjs --apply # 真正写进续忆
|
|
124
|
+
node scripts/import-from-nas.mjs --all # 连 done / dropped 一起
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- 源默认 `http://192.168.5.8:4318`(飞牛),目标默认 `http://127.0.0.1:52497`(本机 DSH),可用 `--source` / `--target` 或环境变量 `PROJECT_MEMORY_NAS_URL`、`DSH_URL` 覆盖。
|
|
128
|
+
- 默认只搬未结束(`candidate` / `idea` / `someday` / `planned` / `blocked`)的计划,按「项目名 + 标题」去重,已经存在的跳过;缺的项目会一起补上。
|
|
129
|
+
- 源需要 `x-sync-token` 时加 `--token`(或 `PROJECT_MEMORY_SYNC_TOKEN`)。
|
|
130
|
+
- 只会新增,不会改动或删除续忆里已有的计划。
|
|
131
|
+
|
|
104
132
|
## 数据
|
|
105
133
|
|
|
106
134
|
- 使用 DSH `storageDomain` 的独立域 `project_memory`。
|
package/client.js
CHANGED
|
@@ -1469,6 +1469,7 @@ window.__ModuleLoader__.load({
|
|
|
1469
1469
|
const [mode, setMode] = useState('merge');
|
|
1470
1470
|
const [resetOpen, setResetOpen] = useState(false);
|
|
1471
1471
|
const [resetText, setResetText] = useState('');
|
|
1472
|
+
const [syncForm, setSyncForm] = useState(null);
|
|
1472
1473
|
const fileRef = useRef(null);
|
|
1473
1474
|
|
|
1474
1475
|
const refresh = useCallback(async () => {
|
|
@@ -1483,6 +1484,10 @@ window.__ModuleLoader__.load({
|
|
|
1483
1484
|
refresh();
|
|
1484
1485
|
}, [refresh]);
|
|
1485
1486
|
|
|
1487
|
+
useEffect(() => {
|
|
1488
|
+
if (data?.preferences?.sync) setSyncForm(data.preferences.sync);
|
|
1489
|
+
}, [data]);
|
|
1490
|
+
|
|
1486
1491
|
async function exportData() {
|
|
1487
1492
|
setBusy(true);
|
|
1488
1493
|
try {
|
|
@@ -1539,6 +1544,44 @@ window.__ModuleLoader__.load({
|
|
|
1539
1544
|
}
|
|
1540
1545
|
}
|
|
1541
1546
|
|
|
1547
|
+
async function saveSync(patch) {
|
|
1548
|
+
setSyncForm((current) => ({ ...(current ?? {}), ...patch }));
|
|
1549
|
+
setBusy(true);
|
|
1550
|
+
try {
|
|
1551
|
+
const result = await api('/settings', {
|
|
1552
|
+
method: 'PATCH',
|
|
1553
|
+
body: JSON.stringify({ sync: patch }),
|
|
1554
|
+
});
|
|
1555
|
+
setData((current) => (current ? { ...current, preferences: result.preferences } : current));
|
|
1556
|
+
setMessage('已保存对齐设置');
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
setMessage(error.message);
|
|
1559
|
+
} finally {
|
|
1560
|
+
setBusy(false);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
async function syncNow() {
|
|
1565
|
+
setBusy(true);
|
|
1566
|
+
try {
|
|
1567
|
+
const result = await api('/sync', { method: 'POST', body: JSON.stringify({}) });
|
|
1568
|
+
const imported = result?.result?.imported ?? 0;
|
|
1569
|
+
const projects = result?.result?.projects ?? 0;
|
|
1570
|
+
setMessage(
|
|
1571
|
+
imported > 0
|
|
1572
|
+
? `已对齐:补进 ${imported} 条计划、${projects} 个项目`
|
|
1573
|
+
: result?.result?.error
|
|
1574
|
+
? `对齐失败:${result.result.error}`
|
|
1575
|
+
: '已对齐:两边本来就是一致的',
|
|
1576
|
+
);
|
|
1577
|
+
await refresh();
|
|
1578
|
+
} catch (error) {
|
|
1579
|
+
setMessage(error.message);
|
|
1580
|
+
} finally {
|
|
1581
|
+
setBusy(false);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1542
1585
|
async function resetAll() {
|
|
1543
1586
|
setBusy(true);
|
|
1544
1587
|
try {
|
|
@@ -1583,6 +1626,69 @@ window.__ModuleLoader__.load({
|
|
|
1583
1626
|
h('button', { className: 'pm-btn pm-btn-ghost', onClick: exportData, disabled: busy }, busy ? '导出中…' : '导出 JSON'),
|
|
1584
1627
|
h('button', { className: 'pm-btn pm-btn-danger', onClick: () => setResetOpen(true), disabled: busy }, '清空数据'),
|
|
1585
1628
|
),
|
|
1629
|
+
h(
|
|
1630
|
+
'div',
|
|
1631
|
+
{ className: 'pm-sync' },
|
|
1632
|
+
h('h4', null, '自动对齐 Codex 版'),
|
|
1633
|
+
h(
|
|
1634
|
+
'p',
|
|
1635
|
+
{ className: 'pm-muted' },
|
|
1636
|
+
'续忆用的是 DSH 自己的数据域,不读 Codex 版(本机 SQLite / 飞牛 4318)那份库,所以两个面板条数会不同。打开后按间隔把那边还没结束的计划补进来,只增不改。',
|
|
1637
|
+
),
|
|
1638
|
+
h(
|
|
1639
|
+
'label',
|
|
1640
|
+
{ className: 'pm-sync-check' },
|
|
1641
|
+
h('input', {
|
|
1642
|
+
type: 'checkbox',
|
|
1643
|
+
checked: syncForm?.enabled === true,
|
|
1644
|
+
disabled: busy,
|
|
1645
|
+
onChange: (event) => saveSync({ enabled: event.target.checked }),
|
|
1646
|
+
}),
|
|
1647
|
+
h('span', null, '打开自动对齐'),
|
|
1648
|
+
),
|
|
1649
|
+
h(
|
|
1650
|
+
'label',
|
|
1651
|
+
{ className: 'pm-sync-row' },
|
|
1652
|
+
h('span', null, 'Codex 版地址'),
|
|
1653
|
+
h('input', {
|
|
1654
|
+
type: 'text',
|
|
1655
|
+
value: syncForm?.source ?? '',
|
|
1656
|
+
placeholder: 'http://192.168.5.8:4318',
|
|
1657
|
+
'aria-label': 'Codex 版地址',
|
|
1658
|
+
onChange: (event) => setSyncForm({ ...(syncForm ?? {}), source: event.target.value }),
|
|
1659
|
+
onBlur: (event) => saveSync({ source: event.target.value, enabled: event.target.value.trim() !== '' }),
|
|
1660
|
+
}),
|
|
1661
|
+
),
|
|
1662
|
+
h(
|
|
1663
|
+
'label',
|
|
1664
|
+
{ className: 'pm-sync-row' },
|
|
1665
|
+
h('span', null, '间隔(分钟)'),
|
|
1666
|
+
h('input', {
|
|
1667
|
+
type: 'number',
|
|
1668
|
+
min: 5,
|
|
1669
|
+
step: 5,
|
|
1670
|
+
value: syncForm?.interval_minutes ?? 30,
|
|
1671
|
+
'aria-label': '对齐间隔(分钟)',
|
|
1672
|
+
onChange: (event) => setSyncForm({ ...(syncForm ?? {}), interval_minutes: Number(event.target.value) }),
|
|
1673
|
+
onBlur: (event) => {
|
|
1674
|
+
const minutes = Number(event.target.value);
|
|
1675
|
+
if (Number.isInteger(minutes) && minutes >= 5) saveSync({ interval_minutes: minutes });
|
|
1676
|
+
},
|
|
1677
|
+
}),
|
|
1678
|
+
),
|
|
1679
|
+
h(
|
|
1680
|
+
'div',
|
|
1681
|
+
{ className: 'pm-settings-actions' },
|
|
1682
|
+
h('button', { className: 'pm-btn pm-btn-ghost', onClick: syncNow, disabled: busy }, busy ? '对齐中…' : '立即对齐'),
|
|
1683
|
+
),
|
|
1684
|
+
h(
|
|
1685
|
+
'p',
|
|
1686
|
+
{ className: 'pm-muted' },
|
|
1687
|
+
syncForm?.last_run_at
|
|
1688
|
+
? `上次对齐 ${fmtDate(syncForm.last_run_at, true)} · 新增 ${syncForm.last_imported ?? 0} 条${syncForm.last_error ? ` · 失败:${syncForm.last_error}` : ''}`
|
|
1689
|
+
: '还没跑过对齐。',
|
|
1690
|
+
),
|
|
1691
|
+
),
|
|
1586
1692
|
h('input', {
|
|
1587
1693
|
ref: fileRef,
|
|
1588
1694
|
type: 'file',
|
|
@@ -1866,6 +1972,12 @@ window.__ModuleLoader__.load({
|
|
|
1866
1972
|
.pm-settings { padding: 4px 0 10px; }
|
|
1867
1973
|
.pm-settings h3 { margin: 0 0 5px; font-size: 14px; }
|
|
1868
1974
|
.pm-settings p { margin: 0 0 12px; font-size: 12px; line-height: 1.6; }
|
|
1975
|
+
.pm-sync { border-top: 1px solid var(--dsw-alias-border-l1); margin: 14px 0 4px; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
|
|
1976
|
+
.pm-sync h4 { margin: 0; font-size: 13px; font-weight: 600; }
|
|
1977
|
+
.pm-sync-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--pm-muted); }
|
|
1978
|
+
.pm-sync-row input[type="text"], .pm-sync-row input[type="number"] { flex: 1; min-width: 120px; background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l1); border-radius: 8px; color: inherit; font-size: 12px; padding: 6px 9px; }
|
|
1979
|
+
.pm-sync-row input[type="number"] { flex: 0 0 84px; }
|
|
1980
|
+
.pm-sync-check { display: flex; align-items: center; gap: 7px; font-size: 12px; }
|
|
1869
1981
|
.pm-settings-grid { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
|
|
1870
1982
|
.pm-settings-grid > div { border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); border-radius: 10px; padding: 9px 12px; min-width: 82px; display: flex; flex-direction: column; gap: 2px; }
|
|
1871
1983
|
.pm-settings-grid strong { font-size: 19px; }
|
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { domainSpec } from './lib/model.js';
|
|
|
3
3
|
import { registerTools } from './lib/tools.js';
|
|
4
4
|
import { API_PREFIX, createApi } from './lib/http.js';
|
|
5
5
|
import { dispatchPlan } from './lib/dispatch.js';
|
|
6
|
+
import { startAutoSync } from './lib/sync.js';
|
|
6
7
|
|
|
7
8
|
export const name = 'project-memory';
|
|
8
9
|
export const inject = ['storageDomain', 'tools', 'systemPrompt'];
|
|
@@ -16,6 +17,7 @@ const STORE_METHODS = [
|
|
|
16
17
|
'capturePlan',
|
|
17
18
|
'updatePlan',
|
|
18
19
|
'markDispatched',
|
|
20
|
+
'recordSyncRun',
|
|
19
21
|
'reviewPlan',
|
|
20
22
|
'decorate',
|
|
21
23
|
'listPlans',
|
|
@@ -50,7 +52,12 @@ export function apply(ctx, config = {}) {
|
|
|
50
52
|
lazyStore[method] = (...args) => storePromise.then((store) => store[method](...args));
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
const autoSync = startAutoSync(ctx, storePromise, { logger: ctx.logger });
|
|
56
|
+
|
|
57
|
+
registerTools(ctx, lazyStore, {
|
|
58
|
+
dispatch: (plan, options) => dispatchPlan(ctx, plan, options),
|
|
59
|
+
sync: (options) => autoSync.tick(options),
|
|
60
|
+
});
|
|
54
61
|
|
|
55
62
|
ctx.effect(
|
|
56
63
|
() =>
|
|
@@ -70,6 +77,7 @@ export function apply(ctx, config = {}) {
|
|
|
70
77
|
path: API_PREFIX,
|
|
71
78
|
handler: createApi(storePromise, {
|
|
72
79
|
dispatch: (plan, options) => dispatchPlan(hostCtx, plan, options),
|
|
80
|
+
sync: (options) => autoSync.tick(options),
|
|
73
81
|
}),
|
|
74
82
|
}),
|
|
75
83
|
'project-memory api',
|
package/lib/http.js
CHANGED
|
@@ -137,6 +137,31 @@ export function createApi(storeSource, options = {}) {
|
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
if (method === 'GET' && sub === '/sync') {
|
|
141
|
+
const preferences = store.getPreferences();
|
|
142
|
+
sendJson(res, 200, { sync: preferences.sync ?? null });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (method === 'POST' && sub === '/sync') {
|
|
147
|
+
if (typeof options.sync !== 'function') {
|
|
148
|
+
throw new HttpError(503, '这个运行时没有启用自动对齐');
|
|
149
|
+
}
|
|
150
|
+
const body = await readJsonBody(req);
|
|
151
|
+
if (body && Object.keys(body).length > 0) {
|
|
152
|
+
await store.updatePreferences({ sync: body });
|
|
153
|
+
}
|
|
154
|
+
const preferences = store.getPreferences();
|
|
155
|
+
const config = preferences.sync ?? {};
|
|
156
|
+
if (!config.source) throw new HttpError(400, '先填 Codex 版地址(例如 http://192.168.5.8:4318)');
|
|
157
|
+
if (config.enabled === false) await store.updatePreferences({ sync: { enabled: true } });
|
|
158
|
+
const result = await options.sync({ force: true });
|
|
159
|
+
if (result && typeof result === 'object' && result.at) await store.recordSyncRun(result);
|
|
160
|
+
const after = store.getPreferences();
|
|
161
|
+
sendJson(res, 200, { result, sync: after.sync ?? null });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
140
165
|
if (method === 'POST' && sub === '/plans') {
|
|
141
166
|
const body = await readJsonBody(req);
|
|
142
167
|
const input = {
|
package/lib/store.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
projectSchema,
|
|
11
11
|
settingsSchema,
|
|
12
12
|
} from './model.js';
|
|
13
|
+
import { defaultSyncConfig } from './sync.js';
|
|
13
14
|
|
|
14
15
|
const ALLOWED_UPDATE_FIELDS = new Set([
|
|
15
16
|
'title',
|
|
@@ -87,6 +88,7 @@ export class ProjectMemoryStore {
|
|
|
87
88
|
locale: 'zh',
|
|
88
89
|
default_project_id: null,
|
|
89
90
|
stale_days: this.staleDays,
|
|
91
|
+
sync: defaultSyncConfig(),
|
|
90
92
|
updated_at: nowIso(),
|
|
91
93
|
});
|
|
92
94
|
}
|
|
@@ -399,12 +401,17 @@ export class ProjectMemoryStore {
|
|
|
399
401
|
}
|
|
400
402
|
|
|
401
403
|
getPreferences() {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
404
|
+
const stored = this.settings.get('preferences');
|
|
405
|
+
if (!stored) {
|
|
406
|
+
return {
|
|
407
|
+
locale: 'zh',
|
|
408
|
+
default_project_id: null,
|
|
409
|
+
stale_days: this.staleDays,
|
|
410
|
+
sync: defaultSyncConfig(),
|
|
411
|
+
updated_at: nowIso(),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
return stored.sync ? stored : { ...stored, sync: defaultSyncConfig() };
|
|
408
415
|
}
|
|
409
416
|
|
|
410
417
|
async updatePreferences(patch = {}) {
|
|
@@ -418,10 +425,39 @@ export class ProjectMemoryStore {
|
|
|
418
425
|
next.stale_days = patch.stale_days;
|
|
419
426
|
this.staleDays = patch.stale_days;
|
|
420
427
|
}
|
|
428
|
+
if (patch.sync && typeof patch.sync === 'object' && !Array.isArray(patch.sync)) {
|
|
429
|
+
const current = next.sync ?? defaultSyncConfig();
|
|
430
|
+
const merged = { ...current };
|
|
431
|
+
if (typeof patch.sync.enabled === 'boolean') merged.enabled = patch.sync.enabled;
|
|
432
|
+
if (typeof patch.sync.source === 'string') merged.source = patch.sync.source.trim().replace(/\/+$/, '');
|
|
433
|
+
if (typeof patch.sync.token === 'string') merged.token = patch.sync.token.trim();
|
|
434
|
+
if (Number.isInteger(patch.sync.interval_minutes) && patch.sync.interval_minutes >= 5) {
|
|
435
|
+
merged.interval_minutes = patch.sync.interval_minutes;
|
|
436
|
+
}
|
|
437
|
+
if (typeof patch.sync.include_closed === 'boolean') merged.include_closed = patch.sync.include_closed;
|
|
438
|
+
if (merged.enabled && !merged.source) merged.enabled = false;
|
|
439
|
+
next.sync = merged;
|
|
440
|
+
}
|
|
421
441
|
await this.settings.put('preferences', next);
|
|
422
442
|
return next;
|
|
423
443
|
}
|
|
424
444
|
|
|
445
|
+
async recordSyncRun({ at, imported = 0, projects = 0, skipped = 0, error = '', source } = {}) {
|
|
446
|
+
const current = this.getPreferences();
|
|
447
|
+
const sync = {
|
|
448
|
+
...(current.sync ?? defaultSyncConfig()),
|
|
449
|
+
last_run_at: at || nowIso(),
|
|
450
|
+
last_imported: Number(imported) || 0,
|
|
451
|
+
last_projects: Number(projects) || 0,
|
|
452
|
+
last_skipped: Number(skipped) || 0,
|
|
453
|
+
last_error: String(error || ''),
|
|
454
|
+
};
|
|
455
|
+
if (typeof source === 'string' && source.trim() !== '') sync.last_source = source;
|
|
456
|
+
const next = { ...current, sync, updated_at: nowIso() };
|
|
457
|
+
await this.settings.put('preferences', next);
|
|
458
|
+
return sync;
|
|
459
|
+
}
|
|
460
|
+
|
|
425
461
|
exportAll() {
|
|
426
462
|
return {
|
|
427
463
|
format: 'dsh-project-recall',
|
package/lib/sync.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 与 Codex 版 project-memory(本机 SQLite / 飞牛上的 4318 服务)对齐。
|
|
3
|
+
*
|
|
4
|
+
* 续忆用 DSH 独立数据域,不读那份 SQLite;这里通过它的 HTTP 接口把「还没结束」的计划
|
|
5
|
+
* 拉过来,按「项目名 + 标题」去重,只增不改。可以手动触发,也可以按间隔自动跑。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const OPEN_STATUSES = new Set(['candidate', 'idea', 'someday', 'planned', 'blocked']);
|
|
9
|
+
export const DEFAULT_INTERVAL_MINUTES = 30;
|
|
10
|
+
const FETCH_TIMEOUT_MS = 8000;
|
|
11
|
+
|
|
12
|
+
function trim(value) {
|
|
13
|
+
return String(value ?? '').trim();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function normalizeKey(projectName, title) {
|
|
17
|
+
return `${trim(projectName).toLowerCase()}::${trim(title).replace(/\s+/g, ' ').toLowerCase()}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function defaultSyncConfig(env = process.env) {
|
|
21
|
+
const source = trim(env.PROJECT_MEMORY_NAS_URL).replace(/\/+$/, '');
|
|
22
|
+
return {
|
|
23
|
+
enabled: Boolean(source),
|
|
24
|
+
source,
|
|
25
|
+
token: trim(env.PROJECT_MEMORY_SYNC_TOKEN),
|
|
26
|
+
interval_minutes: DEFAULT_INTERVAL_MINUTES,
|
|
27
|
+
include_closed: false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function codexPlanToImport(plan) {
|
|
32
|
+
return {
|
|
33
|
+
id: plan.id,
|
|
34
|
+
project_id: plan.project_id,
|
|
35
|
+
title: plan.title,
|
|
36
|
+
details: plan.details ?? '',
|
|
37
|
+
status: plan.status,
|
|
38
|
+
reason_deferred: plan.reason_deferred ?? '',
|
|
39
|
+
reactivation_conditions: Array.isArray(plan.reactivation_conditions) ? plan.reactivation_conditions : [],
|
|
40
|
+
tags: Array.isArray(plan.tags) ? plan.tags : [],
|
|
41
|
+
priority: plan.priority ?? 'medium',
|
|
42
|
+
effort: plan.effort ?? 'unknown',
|
|
43
|
+
source_type: plan.source_type ?? 'conversation',
|
|
44
|
+
source_ref: plan.source_ref ?? '',
|
|
45
|
+
source_excerpt: plan.source_excerpt ?? '',
|
|
46
|
+
review_at: plan.review_at ?? null,
|
|
47
|
+
last_reviewed_at: plan.last_reviewed_at ?? null,
|
|
48
|
+
completed_at: plan.completed_at ?? null,
|
|
49
|
+
created_at: plan.created_at,
|
|
50
|
+
updated_at: plan.updated_at,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 纯函数:算出要补哪些项目和计划。store 侧只传 exportAll() 的快照。
|
|
56
|
+
*/
|
|
57
|
+
export function buildAlignPayload({ remoteProjects = [], remotePlans = [], existingProjects = [], existingPlans = [], includeClosed = false } = {}) {
|
|
58
|
+
const projectName = new Map(remoteProjects.map((project) => [project.id, project.name]));
|
|
59
|
+
const existingProjectNames = new Map(existingProjects.map((project) => [project.id, project.name]));
|
|
60
|
+
const existingByName = new Map(existingProjects.map((project) => [trim(project.name).toLowerCase(), project]));
|
|
61
|
+
// 同名项目直接复用本地的 id,避免同一个项目在面板里出现两次
|
|
62
|
+
const remoteToLocal = new Map();
|
|
63
|
+
for (const project of remoteProjects) {
|
|
64
|
+
const match = existingByName.get(trim(project.name).toLowerCase());
|
|
65
|
+
if (match) remoteToLocal.set(project.id, match.id);
|
|
66
|
+
}
|
|
67
|
+
const localProjectId = (remoteId) => remoteToLocal.get(remoteId) ?? remoteId;
|
|
68
|
+
|
|
69
|
+
const seen = new Set(
|
|
70
|
+
existingPlans.map((plan) => normalizeKey(plan.project?.name ?? existingProjectNames.get(plan.project_id) ?? '', plan.title)),
|
|
71
|
+
);
|
|
72
|
+
const knownProjectIds = new Set(existingProjects.map((project) => project.id));
|
|
73
|
+
|
|
74
|
+
const wanted = remotePlans.filter((plan) => includeClosed || OPEN_STATUSES.has(plan.status));
|
|
75
|
+
const plans = [];
|
|
76
|
+
for (const plan of wanted) {
|
|
77
|
+
const projectId = localProjectId(plan.project_id);
|
|
78
|
+
const name = projectName.get(plan.project_id) ?? '未归档';
|
|
79
|
+
const key = normalizeKey(name, plan.title);
|
|
80
|
+
if (seen.has(key)) continue;
|
|
81
|
+
seen.add(key);
|
|
82
|
+
plans.push({ ...codexPlanToImport(plan), project_id: projectId });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const projects = [];
|
|
86
|
+
for (const plan of plans) {
|
|
87
|
+
if (projects.some((project) => project.id === plan.project_id)) continue;
|
|
88
|
+
if (knownProjectIds.has(plan.project_id)) continue;
|
|
89
|
+
const project = remoteProjects.find((item) => localProjectId(item.id) === plan.project_id);
|
|
90
|
+
projects.push({
|
|
91
|
+
id: plan.project_id,
|
|
92
|
+
name: project?.name ?? '未归档',
|
|
93
|
+
root_path: trim(project?.root_path) || 'inbox',
|
|
94
|
+
created_at: project?.created_at ?? plan.created_at,
|
|
95
|
+
updated_at: project?.updated_at ?? plan.updated_at,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return { projects, plans, checked: wanted.length, skipped: wanted.length - plans.length };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function fetchJson(url, { token = '', timeoutMs = FETCH_TIMEOUT_MS, fetchImpl = globalThis.fetch } = {}) {
|
|
103
|
+
if (typeof fetchImpl !== 'function') throw new Error('当前运行时没有 fetch');
|
|
104
|
+
const controller = new AbortController();
|
|
105
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
106
|
+
try {
|
|
107
|
+
const response = await fetchImpl(url, {
|
|
108
|
+
headers: token ? { 'x-sync-token': token } : {},
|
|
109
|
+
signal: controller.signal,
|
|
110
|
+
});
|
|
111
|
+
if (!response.ok) throw new Error(`${url} → HTTP ${response.status}`);
|
|
112
|
+
return await response.json();
|
|
113
|
+
} finally {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function alignFromCodex(store, options = {}) {
|
|
119
|
+
const source = trim(options.source).replace(/\/+$/, '');
|
|
120
|
+
if (!source) throw new Error('没有配置 Codex 版地址');
|
|
121
|
+
const token = trim(options.token);
|
|
122
|
+
const includeClosed = options.include_closed === true;
|
|
123
|
+
const fetchOptions = { token, timeoutMs: options.timeoutMs, fetchImpl: options.fetchImpl };
|
|
124
|
+
|
|
125
|
+
const [remoteProjects, remotePlans] = await Promise.all([
|
|
126
|
+
fetchJson(`${source}/api/projects`, fetchOptions),
|
|
127
|
+
fetchJson(`${source}/api/plans`, fetchOptions),
|
|
128
|
+
]);
|
|
129
|
+
const snapshot = store.exportAll();
|
|
130
|
+
const payload = buildAlignPayload({
|
|
131
|
+
remoteProjects: Array.isArray(remoteProjects) ? remoteProjects : remoteProjects.projects ?? [],
|
|
132
|
+
remotePlans: Array.isArray(remotePlans) ? remotePlans : remotePlans.plans ?? [],
|
|
133
|
+
existingProjects: snapshot.projects ?? [],
|
|
134
|
+
existingPlans: snapshot.plans ?? [],
|
|
135
|
+
includeClosed,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const at = new Date().toISOString();
|
|
139
|
+
if (payload.plans.length === 0) {
|
|
140
|
+
return { at, source, checked: payload.checked, imported: 0, projects: 0, skipped: payload.skipped };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const result = await store.importAll(
|
|
144
|
+
{ format: 'dsh-project-recall', version: 1, projects: payload.projects, plans: payload.plans },
|
|
145
|
+
{ mode: 'merge' },
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
at,
|
|
149
|
+
source,
|
|
150
|
+
checked: payload.checked,
|
|
151
|
+
imported: result.plans?.imported ?? payload.plans.length,
|
|
152
|
+
projects: result.projects?.imported ?? payload.projects.length,
|
|
153
|
+
skipped: payload.skipped,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 按偏好里的 sync 配置定时对齐:启动后 15 秒试一次,之后每分钟看一眼是否到点。
|
|
159
|
+
* 失败只记日志,不打扰界面;成功且真有新增时才会写一条 info 日志。
|
|
160
|
+
*/
|
|
161
|
+
export function startAutoSync(ctx, storePromise, options = {}) {
|
|
162
|
+
const logger = options.logger ?? ctx.logger;
|
|
163
|
+
const tickMs = options.tickMs ?? 60_000;
|
|
164
|
+
const initialDelayMs = options.initialDelayMs ?? 15_000;
|
|
165
|
+
let interval;
|
|
166
|
+
let boot;
|
|
167
|
+
|
|
168
|
+
const tick = async ({ force = false } = {}) => {
|
|
169
|
+
if (tick.running) return { skipped: 'running' };
|
|
170
|
+
tick.running = true;
|
|
171
|
+
try {
|
|
172
|
+
const store = await storePromise;
|
|
173
|
+
const config = store.getPreferences().sync ?? {};
|
|
174
|
+
const source = trim(config.source);
|
|
175
|
+
if (!config.enabled || !source) return { skipped: 'disabled' };
|
|
176
|
+
const minutes = Math.max(5, Number(config.interval_minutes) || DEFAULT_INTERVAL_MINUTES);
|
|
177
|
+
const last = config.last_run_at ? Date.parse(config.last_run_at) : Number.NaN;
|
|
178
|
+
if (!force && Number.isFinite(last) && Date.now() - last < minutes * 60_000) return { skipped: 'waiting' };
|
|
179
|
+
try {
|
|
180
|
+
const result = await alignFromCodex(store, {
|
|
181
|
+
source,
|
|
182
|
+
token: config.token,
|
|
183
|
+
include_closed: config.include_closed === true,
|
|
184
|
+
});
|
|
185
|
+
await store.recordSyncRun({ ...result, error: '' });
|
|
186
|
+
if (result.imported > 0) {
|
|
187
|
+
logger?.info?.(`[project-memory] 自动对齐:从 Codex 版补进 ${result.imported} 条计划`);
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
const message = String(error?.message || error);
|
|
192
|
+
await store.recordSyncRun({ at: new Date().toISOString(), imported: 0, error: message });
|
|
193
|
+
logger?.warn?.(`[project-memory] 自动对齐失败:${message}`);
|
|
194
|
+
return { error: message };
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
tick.running = false;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const start = () => {
|
|
202
|
+
boot = setTimeout(() => {
|
|
203
|
+
void tick();
|
|
204
|
+
interval = setInterval(() => void tick(), tickMs);
|
|
205
|
+
if (typeof interval.unref === 'function') interval.unref();
|
|
206
|
+
}, initialDelayMs);
|
|
207
|
+
if (typeof boot.unref === 'function') boot.unref();
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const dispose = () => {
|
|
211
|
+
clearTimeout(boot);
|
|
212
|
+
clearInterval(interval);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
if (typeof ctx.effect === 'function') {
|
|
216
|
+
ctx.effect(() => {
|
|
217
|
+
start();
|
|
218
|
+
return dispose;
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
start();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return { tick, dispose };
|
|
225
|
+
}
|
package/lib/tools.js
CHANGED
|
@@ -264,6 +264,37 @@ export function registerTools(ctx, store, options = {}) {
|
|
|
264
264
|
},
|
|
265
265
|
),
|
|
266
266
|
|
|
267
|
+
defineTool(
|
|
268
|
+
'project_memory_sync_now',
|
|
269
|
+
'Align 续忆 with the Codex edition (local SQLite / NAS 4318 service) right now: pull plans that are missing here, dedupe by project name + title, only add. Use when the user asks why the two panels differ, or says 对齐 / 同步一下 / sync the backlog.',
|
|
270
|
+
{
|
|
271
|
+
type: 'object',
|
|
272
|
+
properties: {
|
|
273
|
+
source: { type: 'string', description: 'Base URL of the Codex edition, e.g. http://192.168.5.8:4318. Defaults to the saved setting.' },
|
|
274
|
+
include_closed: { type: 'boolean', description: 'Also pull done / dropped plans.' },
|
|
275
|
+
},
|
|
276
|
+
additionalProperties: false,
|
|
277
|
+
},
|
|
278
|
+
async (args) => {
|
|
279
|
+
if (typeof options.sync !== 'function') {
|
|
280
|
+
throw new Error('这个运行时没有启用对齐服务');
|
|
281
|
+
}
|
|
282
|
+
if (typeof args.source === 'string' && args.source.trim() !== '') {
|
|
283
|
+
await store.updatePreferences({ sync: { enabled: true, source: args.source } });
|
|
284
|
+
}
|
|
285
|
+
const preferences = await store.getPreferences();
|
|
286
|
+
if (!preferences.sync?.source) {
|
|
287
|
+
throw new Error('先填 Codex 版地址,例如 http://192.168.5.8:4318');
|
|
288
|
+
}
|
|
289
|
+
if (args.include_closed === true) {
|
|
290
|
+
await store.updatePreferences({ sync: { include_closed: true } });
|
|
291
|
+
}
|
|
292
|
+
const result = await options.sync({ force: true });
|
|
293
|
+
const after = await store.getPreferences();
|
|
294
|
+
return { result, sync: after.sync ?? null };
|
|
295
|
+
},
|
|
296
|
+
),
|
|
297
|
+
|
|
267
298
|
defineTool(
|
|
268
299
|
'project_memory_update_plan',
|
|
269
300
|
'Update a saved plan. Use for status changes, rescheduling review, editing title/details, or marking done/dropped after the user confirms.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-project-recall",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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,15 +50,17 @@
|
|
|
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 && node --check lib/sync.js && node --check scripts/import-from-nas.mjs",
|
|
54
|
+
"import:nas": "node scripts/import-from-nas.mjs"
|
|
53
55
|
},
|
|
54
56
|
"repository": {
|
|
55
57
|
"type": "git",
|
|
56
|
-
"url": "git+https://github.com/
|
|
58
|
+
"url": "git+https://github.com/hseons/dsh-backup.git",
|
|
59
|
+
"directory": "local-plugins/dsh-project-recall"
|
|
57
60
|
},
|
|
58
|
-
"homepage": "https://github.com/
|
|
61
|
+
"homepage": "https://github.com/hseons/dsh-backup/tree/main/local-plugins/dsh-project-recall#readme",
|
|
59
62
|
"bugs": {
|
|
60
|
-
"url": "https://github.com/
|
|
63
|
+
"url": "https://github.com/hseons/dsh-backup/issues"
|
|
61
64
|
},
|
|
62
65
|
"publishConfig": {
|
|
63
66
|
"access": "public"
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
* 插件里的自动对齐用的是同一套去重逻辑(lib/sync.js),所以两边结果一致。
|
|
8
|
+
*
|
|
9
|
+
* node scripts/import-from-nas.mjs # 看差异
|
|
10
|
+
* node scripts/import-from-nas.mjs --apply # 真导入
|
|
11
|
+
* node scripts/import-from-nas.mjs --all # 连 done/dropped 一起
|
|
12
|
+
* node scripts/import-from-nas.mjs --source http://127.0.0.1:4318 --target http://127.0.0.1:52497
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { buildAlignPayload, fetchJson } from '../lib/sync.js';
|
|
16
|
+
|
|
17
|
+
function parseArgs(argv) {
|
|
18
|
+
const options = {
|
|
19
|
+
source: process.env.PROJECT_MEMORY_NAS_URL || 'http://192.168.5.8:4318',
|
|
20
|
+
target: process.env.DSH_URL || 'http://127.0.0.1:52497',
|
|
21
|
+
token: process.env.PROJECT_MEMORY_SYNC_TOKEN || '',
|
|
22
|
+
apply: false,
|
|
23
|
+
all: false,
|
|
24
|
+
};
|
|
25
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
26
|
+
const arg = argv[index];
|
|
27
|
+
if (arg === '--apply') options.apply = true;
|
|
28
|
+
else if (arg === '--all') options.all = true;
|
|
29
|
+
else if (arg === '--source') options.source = argv[++index];
|
|
30
|
+
else if (arg === '--target') options.target = argv[++index];
|
|
31
|
+
else if (arg === '--token') options.token = argv[++index];
|
|
32
|
+
else if (arg === '--help' || arg === '-h') {
|
|
33
|
+
console.log('用法: node scripts/import-from-nas.mjs [--apply] [--all] [--source URL] [--target URL] [--token TOKEN]');
|
|
34
|
+
process.exit(0);
|
|
35
|
+
} else {
|
|
36
|
+
console.error(`未知参数: ${arg}`);
|
|
37
|
+
process.exit(2);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
options.source = String(options.source || '').replace(/\/+$/, '');
|
|
41
|
+
options.target = String(options.target || '').replace(/\/+$/, '');
|
|
42
|
+
return options;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getJson(url, headers = {}) {
|
|
46
|
+
const response = await fetch(url, { headers });
|
|
47
|
+
if (!response.ok) throw new Error(`${url} → HTTP ${response.status}`);
|
|
48
|
+
return response.json();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function main() {
|
|
52
|
+
const options = parseArgs(process.argv.slice(2));
|
|
53
|
+
|
|
54
|
+
console.log(`源(Codex 版): ${options.source}`);
|
|
55
|
+
console.log(`目标(DSH 续忆): ${options.target}`);
|
|
56
|
+
|
|
57
|
+
const [remoteProjects, remotePlans, exported] = await Promise.all([
|
|
58
|
+
fetchJson(`${options.source}/api/projects`, { token: options.token }),
|
|
59
|
+
fetchJson(`${options.source}/api/plans`, { token: options.token }),
|
|
60
|
+
// /plans 只返回未结束的计划,去重要用 /export 的全量(含 done/dropped)
|
|
61
|
+
getJson(`${options.target}/project-memory/api/export`, { origin: options.target }),
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
const payload = buildAlignPayload({
|
|
65
|
+
remoteProjects: Array.isArray(remoteProjects) ? remoteProjects : remoteProjects.projects ?? [],
|
|
66
|
+
remotePlans: Array.isArray(remotePlans) ? remotePlans : remotePlans.plans ?? [],
|
|
67
|
+
existingProjects: exported.projects ?? [],
|
|
68
|
+
existingPlans: exported.plans ?? [],
|
|
69
|
+
includeClosed: options.all,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(
|
|
73
|
+
`源里 ${payload.checked} 条(${options.all ? '全部状态' : '仅未结束'}),DSH 侧现有 ${(exported.plans ?? []).length} 条。`,
|
|
74
|
+
);
|
|
75
|
+
if (payload.plans.length === 0) {
|
|
76
|
+
console.log('没有需要新增的计划,两边已经对齐。');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log(`\n会新增 ${payload.plans.length} 条:`);
|
|
81
|
+
for (const plan of payload.plans) {
|
|
82
|
+
console.log(` • [${plan.status}] ${String(plan.title).slice(0, 70)}`);
|
|
83
|
+
}
|
|
84
|
+
if (payload.projects.length > 0) {
|
|
85
|
+
console.log(`\n会补 ${payload.projects.length} 个项目:${payload.projects.map((project) => project.name).join('、')}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!options.apply) {
|
|
89
|
+
console.log('\n这是 dry-run。确认无误后加 --apply 真正写进 DSH 续忆。');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const response = await fetch(`${options.target}/project-memory/api/import`, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: { 'content-type': 'application/json', origin: options.target },
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
format: 'dsh-project-recall',
|
|
98
|
+
version: 1,
|
|
99
|
+
projects: payload.projects,
|
|
100
|
+
plans: payload.plans,
|
|
101
|
+
mode: 'merge',
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
const text = await response.text();
|
|
105
|
+
if (!response.ok) throw new Error(`导入失败 HTTP ${response.status}: ${text.slice(0, 300)}`);
|
|
106
|
+
console.log(`\n导入完成: ${text}`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
main().catch((error) => {
|
|
110
|
+
console.error(`失败: ${error.message}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
});
|