@liuchen64/dsh-config-sync 0.0.0-stage → 0.1.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.
Files changed (36) hide show
  1. package/client.js +361 -0
  2. package/cordis.patch.yml +14 -0
  3. package/dist/index.d.ts +40 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +32 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/internal/config/options.d.ts +26 -0
  8. package/dist/internal/config/options.d.ts.map +1 -0
  9. package/dist/internal/config/options.js +36 -0
  10. package/dist/internal/config/options.js.map +1 -0
  11. package/dist/internal/rpc/endpoints.d.ts +27 -0
  12. package/dist/internal/rpc/endpoints.d.ts.map +1 -0
  13. package/dist/internal/rpc/endpoints.js +70 -0
  14. package/dist/internal/rpc/endpoints.js.map +1 -0
  15. package/dist/internal/sync/backup.d.ts +14 -0
  16. package/dist/internal/sync/backup.d.ts.map +1 -0
  17. package/dist/internal/sync/backup.js +35 -0
  18. package/dist/internal/sync/backup.js.map +1 -0
  19. package/dist/internal/sync/git.d.ts +21 -0
  20. package/dist/internal/sync/git.d.ts.map +1 -0
  21. package/dist/internal/sync/git.js +87 -0
  22. package/dist/internal/sync/git.js.map +1 -0
  23. package/dist/internal/sync/include.d.ts +23 -0
  24. package/dist/internal/sync/include.d.ts.map +1 -0
  25. package/dist/internal/sync/include.js +40 -0
  26. package/dist/internal/sync/include.js.map +1 -0
  27. package/dist/internal/sync/inspect.d.ts +25 -0
  28. package/dist/internal/sync/inspect.d.ts.map +1 -0
  29. package/dist/internal/sync/inspect.js +59 -0
  30. package/dist/internal/sync/inspect.js.map +1 -0
  31. package/dist/internal/sync/service.d.ts +81 -0
  32. package/dist/internal/sync/service.d.ts.map +1 -0
  33. package/dist/internal/sync/service.js +249 -0
  34. package/dist/internal/sync/service.js.map +1 -0
  35. package/package.json +51 -3
  36. package/README.md +0 -3
package/client.js ADDED
@@ -0,0 +1,361 @@
1
+ window.__ModuleLoader__.load({
2
+ id: '@liuchen64/dsh-config-sync',
3
+ factory(require) {
4
+ const React = require('react');
5
+ const h = React.createElement;
6
+
7
+ /** 状态 → 颜色 / 文案 */
8
+ const PHASES = {
9
+ unbound: { color: '#9ca3af', text: '未绑定远端' },
10
+ idle: { color: '#22c55e', text: '就绪' },
11
+ syncing: { color: '#3b82f6', text: '同步中' },
12
+ conflict: { color: '#f59e0b', text: '需要选择' },
13
+ error: { color: '#ef4444', text: '失败' },
14
+ };
15
+
16
+ const CHANGE_TEXT = { added: '新增', modified: '修改', deleted: '删除', renamed: '重命名' };
17
+
18
+ function phaseOf(status) {
19
+ return PHASES[status?.phase] ?? PHASES.idle;
20
+ }
21
+
22
+ /** 上次同步时间只显示到分钟 */
23
+ function formatTime(iso) {
24
+ if (typeof iso !== 'string') return '从未';
25
+ const date = new Date(iso);
26
+ if (Number.isNaN(date.getTime())) return '从未';
27
+ const pad = (n) => String(n).padStart(2, '0');
28
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
29
+ }
30
+
31
+ function ChangeList(title, changes) {
32
+ if (changes.length === 0) {
33
+ return h(
34
+ 'div',
35
+ { style: { flex: 1, minWidth: 0 } },
36
+ h('div', { style: { fontWeight: 600, marginBottom: 4 } }, `${title}(0)`),
37
+ h('div', { style: { opacity: 0.6, fontSize: '12px' } }, '无差异'),
38
+ );
39
+ }
40
+ const shown = changes.slice(0, 8);
41
+ return h(
42
+ 'div',
43
+ { style: { flex: 1, minWidth: 0 } },
44
+ h('div', { style: { fontWeight: 600, marginBottom: 4 } }, `${title}(${changes.length})`),
45
+ h(
46
+ 'ul',
47
+ { style: { margin: 0, paddingLeft: '16px', fontSize: '12px', lineHeight: 1.6 } },
48
+ ...shown.map((change) =>
49
+ h(
50
+ 'li',
51
+ { key: `${title}:${change.path}`, style: { overflowWrap: 'anywhere' } },
52
+ `${CHANGE_TEXT[change.change] ?? change.change} ${change.path}`,
53
+ ),
54
+ ),
55
+ changes.length > shown.length
56
+ ? h('li', { style: { opacity: 0.6 } }, `…还有 ${changes.length - shown.length} 个`)
57
+ : null,
58
+ ),
59
+ );
60
+ }
61
+
62
+ function ConfigSyncPanel(props) {
63
+ const call = props.call;
64
+ const [status, setStatus] = React.useState(null);
65
+ const [inspect, setInspect] = React.useState(null);
66
+ const [busy, setBusy] = React.useState('');
67
+ const [notice, setNotice] = React.useState('');
68
+
69
+ const refresh = React.useCallback(async () => {
70
+ const answered = await call('config-sync/status');
71
+ if (!answered.ok) {
72
+ setNotice(answered.error?.message ?? '读取状态失败');
73
+ return;
74
+ }
75
+ setStatus(answered.value);
76
+ if (answered.value?.phase === 'conflict') {
77
+ const detail = await call('config-sync/inspect');
78
+ setInspect(detail.ok ? detail.value : null);
79
+ } else {
80
+ setInspect(null);
81
+ }
82
+ }, [call]);
83
+
84
+ React.useEffect(() => {
85
+ refresh().catch((error) => {
86
+ setNotice(String(error));
87
+ });
88
+ const timer = setInterval(() => {
89
+ refresh().catch(() => {});
90
+ }, 5000);
91
+ return () => {
92
+ clearInterval(timer);
93
+ };
94
+ }, [refresh]);
95
+
96
+ const run = React.useCallback(
97
+ async (action, label) => {
98
+ setBusy(action);
99
+ setNotice('');
100
+ try {
101
+ const answered = await call(`config-sync/${action}`);
102
+ if (!answered.ok) {
103
+ setNotice(`${label}失败:${answered.error?.message ?? '未知原因'}`);
104
+ } else if (answered.value?.backup) {
105
+ setNotice(`已用远端覆盖本地,原内容备份在:${answered.value.backup}`);
106
+ } else {
107
+ setNotice(`${label}完成`);
108
+ }
109
+ await refresh();
110
+ } catch (error) {
111
+ setNotice(`${label}失败:${String(error)}`);
112
+ } finally {
113
+ setBusy('');
114
+ }
115
+ },
116
+ [call, refresh],
117
+ );
118
+
119
+ const phase = phaseOf(status);
120
+ const needsChoice = status?.phase === 'conflict';
121
+
122
+ return h(
123
+ 'div',
124
+ {
125
+ role: 'dialog',
126
+ 'aria-label': '配置同步',
127
+ style: {
128
+ position: 'fixed',
129
+ right: '16px',
130
+ bottom: '72px',
131
+ width: '460px',
132
+ maxWidth: 'calc(100vw - 32px)',
133
+ padding: '14px 16px',
134
+ borderRadius: '10px',
135
+ border: '1px solid color-mix(in srgb, currentColor 18%, transparent)',
136
+ background: 'Canvas',
137
+ color: 'CanvasText',
138
+ boxShadow: '0 12px 32px rgba(0, 0, 0, 0.28)',
139
+ fontSize: '13px',
140
+ lineHeight: 1.5,
141
+ zIndex: 60,
142
+ },
143
+ },
144
+ h(
145
+ 'div',
146
+ { style: { display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '10px' } },
147
+ h('strong', null, '配置同步'),
148
+ h('span', { style: { color: phase.color } }, `● ${phase.text}`),
149
+ h(
150
+ 'button',
151
+ {
152
+ type: 'button',
153
+ onClick: props.onClose,
154
+ style: {
155
+ marginLeft: 'auto',
156
+ background: 'none',
157
+ border: 0,
158
+ cursor: 'pointer',
159
+ color: 'inherit',
160
+ opacity: 0.7,
161
+ },
162
+ 'aria-label': '关闭',
163
+ },
164
+ '✕',
165
+ ),
166
+ ),
167
+ h(
168
+ 'div',
169
+ {
170
+ style: {
171
+ display: 'grid',
172
+ gridTemplateColumns: 'auto 1fr',
173
+ gap: '2px 10px',
174
+ marginBottom: '10px',
175
+ },
176
+ },
177
+ h('span', { style: { opacity: 0.7 } }, '远端'),
178
+ h('span', { style: { overflowWrap: 'anywhere' } }, status?.remote || '未配置'),
179
+ h('span', { style: { opacity: 0.7 } }, '分支'),
180
+ h('span', null, status?.branch || '—'),
181
+ h('span', { style: { opacity: 0.7 } }, '上次同步'),
182
+ h('span', null, formatTime(status?.lastSyncAt)),
183
+ ),
184
+ needsChoice
185
+ ? h(
186
+ 'div',
187
+ {
188
+ style: {
189
+ border: '1px solid color-mix(in srgb, currentColor 16%, transparent)',
190
+ borderRadius: '8px',
191
+ padding: '10px',
192
+ marginBottom: '10px',
193
+ },
194
+ },
195
+ h(
196
+ 'div',
197
+ { style: { fontWeight: 600, marginBottom: '6px' } },
198
+ '本地与远端不一致,需要选一边覆盖',
199
+ ),
200
+ h(
201
+ 'div',
202
+ { style: { display: 'flex', gap: '14px' } },
203
+ ChangeList('本地改动', inspect?.localChanges ?? []),
204
+ ChangeList('远端改动', inspect?.remoteChanges ?? []),
205
+ ),
206
+ h(
207
+ 'div',
208
+ { style: { display: 'flex', gap: '8px', marginTop: '10px' } },
209
+ h(
210
+ 'button',
211
+ {
212
+ type: 'button',
213
+ disabled: busy !== '',
214
+ onClick: () => run('force-pull', '用远端覆盖本地'),
215
+ style: { flex: 1 },
216
+ },
217
+ '用远端覆盖本地',
218
+ ),
219
+ h(
220
+ 'button',
221
+ {
222
+ type: 'button',
223
+ disabled: busy !== '',
224
+ onClick: () => run('force-push', '用本地覆盖远端'),
225
+ style: { flex: 1 },
226
+ },
227
+ '用本地覆盖远端',
228
+ ),
229
+ ),
230
+ h(
231
+ 'div',
232
+ { style: { opacity: 0.65, fontSize: '12px', marginTop: '6px' } },
233
+ '覆盖本地前会先备份到 ~/.dsh/.config-sync-backup/',
234
+ ),
235
+ )
236
+ : null,
237
+ h(
238
+ 'div',
239
+ { style: { display: 'flex', gap: '8px' } },
240
+ h(
241
+ 'button',
242
+ { type: 'button', disabled: busy !== '', onClick: () => run('sync', '同步') },
243
+ busy === 'sync' ? '同步中…' : '立即同步',
244
+ ),
245
+ h(
246
+ 'button',
247
+ { type: 'button', disabled: busy !== '', onClick: () => run('pull', '拉取') },
248
+ '仅拉取',
249
+ ),
250
+ h(
251
+ 'button',
252
+ { type: 'button', disabled: busy !== '', onClick: () => run('push', '推送') },
253
+ '仅推送',
254
+ ),
255
+ ),
256
+ notice !== ''
257
+ ? h(
258
+ 'div',
259
+ { style: { marginTop: '8px', opacity: 0.85, overflowWrap: 'anywhere' } },
260
+ notice,
261
+ )
262
+ : null,
263
+ );
264
+ }
265
+
266
+ function ConfigSyncEntry(props) {
267
+ const [open, setOpen] = React.useState(false);
268
+ const [status, setStatus] = React.useState(null);
269
+ const call = props.call;
270
+
271
+ React.useEffect(() => {
272
+ let cancelled = false;
273
+ const read = () => {
274
+ call('config-sync/status')
275
+ .then((answered) => {
276
+ if (!cancelled && answered.ok) setStatus(answered.value);
277
+ })
278
+ .catch(() => {});
279
+ };
280
+ read();
281
+ const timer = setInterval(read, 10000);
282
+ return () => {
283
+ cancelled = true;
284
+ clearInterval(timer);
285
+ };
286
+ }, [call]);
287
+
288
+ const phase = phaseOf(status);
289
+ const wide = props.wide !== false;
290
+
291
+ return h(
292
+ 'div',
293
+ { style: { position: 'relative' } },
294
+ h(
295
+ 'button',
296
+ {
297
+ type: 'button',
298
+ onClick: () => setOpen((value) => !value),
299
+ title: `配置同步:${phase.text}${status?.lastSyncAt ? `,上次同步 ${formatTime(status.lastSyncAt)}` : ''}`,
300
+ 'aria-label': '配置同步',
301
+ style: {
302
+ display: 'flex',
303
+ alignItems: 'center',
304
+ gap: '8px',
305
+ width: wide ? '100%' : '40px',
306
+ height: '32px',
307
+ padding: wide ? '0 10px' : 0,
308
+ justifyContent: wide ? 'flex-start' : 'center',
309
+ background: 'none',
310
+ border: 0,
311
+ borderRadius: '6px',
312
+ color: 'inherit',
313
+ cursor: 'pointer',
314
+ fontSize: '13px',
315
+ opacity: 0.85,
316
+ },
317
+ },
318
+ h('span', { style: { color: phase.color, fontSize: '11px' } }, '●'),
319
+ wide ? h('span', null, '配置同步') : null,
320
+ ),
321
+ open
322
+ ? h(ConfigSyncPanel, {
323
+ call,
324
+ onClose: () => {
325
+ setOpen(false);
326
+ },
327
+ })
328
+ : null,
329
+ );
330
+ }
331
+
332
+ return {
333
+ inject: ['slots', 'connection'],
334
+ apply(ctx) {
335
+ const call = async (endpoint) => {
336
+ try {
337
+ return await ctx.connection.rpc.call('/api', endpoint, {});
338
+ } catch (error) {
339
+ return {
340
+ ok: false,
341
+ error: { code: 'call-failed', message: String(error), details: {} },
342
+ };
343
+ }
344
+ };
345
+
346
+ ctx.slots.inject('sidebar.footer.action', () =>
347
+ ctx.slots.register(
348
+ {
349
+ name: 'sidebar.footer.action',
350
+ id: 'config-sync',
351
+ order: 20,
352
+ label: '配置同步',
353
+ inject: () => ({ call }),
354
+ },
355
+ ConfigSyncEntry,
356
+ ),
357
+ );
358
+ },
359
+ };
360
+ },
361
+ });
@@ -0,0 +1,14 @@
1
+ # 配置同步插件:把本机 ~/.dsh 里的白名单配置同步到 git
2
+ #
3
+ # remote / branch / include 都在这里配;include 是白名单,
4
+ # node_modules、.plugin-manager、pnpm-lock.yaml 永远排除。
5
+ - insert:
6
+ - id: config-sync
7
+ name: "@liuchen64/dsh-config-sync"
8
+ config:
9
+ remote: git@gitee.com:folding-fan/dsh-config.git
10
+ branch: main
11
+ include:
12
+ - cordis.patch.yml
13
+ - profiles
14
+ - skills
@@ -0,0 +1,40 @@
1
+ /**
2
+ * DSH 插件入口:把本机配置同步到 git 仓库
3
+ *
4
+ * - internal/config/options.ts 配置归一与 $DSH_HOME 定位
5
+ * - internal/sync/include.ts 白名单 pathspec 与体积上限
6
+ * - internal/sync/git.ts git 调用、超时与失败归类
7
+ * - internal/sync/inspect.ts 本地/远端的文件级对照
8
+ * - internal/sync/backup.ts 强拉前的本地备份
9
+ * - internal/sync/service.ts 同步状态机与操作序列(进程内互斥)
10
+ * - internal/rpc/endpoints.ts /api 上的 config-sync/* 端点
11
+ *
12
+ * 浏览器侧(client.js)用 ctx.connection.rpc.call('/api', 'config-sync/<动作>', {}) 触发,
13
+ * 状态与差异都走端点直读,不占用会话投影。
14
+ */
15
+ import { type RpcHandler } from './internal/rpc/endpoints.js';
16
+ export { DEFAULT_INCLUDE, resolveHome, resolveOptions } from './internal/config/options.js';
17
+ export { ENDPOINTS, matchesEndpoint } from './internal/rpc/endpoints.js';
18
+ export { BACKUP_DIR, backupLocal } from './internal/sync/backup.js';
19
+ export { classifyGitFailure, GIT_TIMEOUT_MS } from './internal/sync/git.js';
20
+ export { buildPathspecs, checkSizes, FILE_LIMIT_BYTES, TOTAL_LIMIT_BYTES, } from './internal/sync/include.js';
21
+ export type { FileChange, FileChangeKind, InspectState } from './internal/sync/inspect.js';
22
+ export { deriveState, listAllFiles, parseNameStatus } from './internal/sync/inspect.js';
23
+ export type { InspectResult, SyncFailure, SyncOutcome, SyncPhase, SyncStatus, } from './internal/sync/service.js';
24
+ export { ConfigSyncService } from './internal/sync/service.js';
25
+ /** 声明依赖的 Connection 服务:缺少它的 profile 里插件保持未激活,而不是抛错 */
26
+ export declare const inject: string[];
27
+ /** 共用 /api 通道上的一个拦截器 */
28
+ interface ConnectionRpc {
29
+ intercept(channel: '/api', matches: (endpoint: string) => boolean, handler: RpcHandler): () => Promise<void>;
30
+ }
31
+ /** 只用到 effect 与 connection.rpc,避免为此引入 DSH 包类型依赖 */
32
+ interface HostContext {
33
+ effect(setup: () => () => Promise<void>): unknown;
34
+ connection: {
35
+ readonly rpc: ConnectionRpc;
36
+ };
37
+ }
38
+ /** 注册 config-sync/* 端点;拦截器是插件 fiber 上的 effect,卸载即移除 */
39
+ export declare function apply(ctx: HostContext, config: unknown): void;
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAqC,KAAK,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAGjG,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACxF,YAAY,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,sDAAsD;AACtD,eAAO,MAAM,MAAM,UAAiB,CAAC;AAErC,wBAAwB;AACxB,UAAU,aAAa;IACrB,SAAS,CACP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,EACtC,OAAO,EAAE,UAAU,GAClB,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,mDAAmD;AACnD,UAAU,WAAW;IACnB,MAAM,CAAC,KAAK,EAAE,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IAClD,UAAU,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAA;KAAE,CAAC;CAC7C;AAED,uDAAuD;AACvD,wBAAgB,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAK7D"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * DSH 插件入口:把本机配置同步到 git 仓库
3
+ *
4
+ * - internal/config/options.ts 配置归一与 $DSH_HOME 定位
5
+ * - internal/sync/include.ts 白名单 pathspec 与体积上限
6
+ * - internal/sync/git.ts git 调用、超时与失败归类
7
+ * - internal/sync/inspect.ts 本地/远端的文件级对照
8
+ * - internal/sync/backup.ts 强拉前的本地备份
9
+ * - internal/sync/service.ts 同步状态机与操作序列(进程内互斥)
10
+ * - internal/rpc/endpoints.ts /api 上的 config-sync/* 端点
11
+ *
12
+ * 浏览器侧(client.js)用 ctx.connection.rpc.call('/api', 'config-sync/<动作>', {}) 触发,
13
+ * 状态与差异都走端点直读,不占用会话投影。
14
+ */
15
+ import { resolveOptions } from './internal/config/options.js';
16
+ import { createRpcHandler, matchesEndpoint } from './internal/rpc/endpoints.js';
17
+ import { ConfigSyncService } from './internal/sync/service.js';
18
+ export { DEFAULT_INCLUDE, resolveHome, resolveOptions } from './internal/config/options.js';
19
+ export { ENDPOINTS, matchesEndpoint } from './internal/rpc/endpoints.js';
20
+ export { BACKUP_DIR, backupLocal } from './internal/sync/backup.js';
21
+ export { classifyGitFailure, GIT_TIMEOUT_MS } from './internal/sync/git.js';
22
+ export { buildPathspecs, checkSizes, FILE_LIMIT_BYTES, TOTAL_LIMIT_BYTES, } from './internal/sync/include.js';
23
+ export { deriveState, listAllFiles, parseNameStatus } from './internal/sync/inspect.js';
24
+ export { ConfigSyncService } from './internal/sync/service.js';
25
+ /** 声明依赖的 Connection 服务:缺少它的 profile 里插件保持未激活,而不是抛错 */
26
+ export const inject = ['connection'];
27
+ /** 注册 config-sync/* 端点;拦截器是插件 fiber 上的 effect,卸载即移除 */
28
+ export function apply(ctx, config) {
29
+ const service = new ConfigSyncService(resolveOptions(config));
30
+ ctx.effect(() => ctx.connection.rpc.intercept('/api', matchesEndpoint, createRpcHandler(service)));
31
+ }
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAmB,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EACL,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAQxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,sDAAsD;AACtD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAC,CAAC;AAiBrC,uDAAuD;AACvD,MAAM,UAAU,KAAK,CAAC,GAAgB,EAAE,MAAe;IACrD,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CACd,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CACjF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * options.ts — 把插件行里的 config 归一成运行选项
3
+ *
4
+ * 仓库根固定为 $DSH_HOME(~/.dsh),不做路径映射:
5
+ * 白名单里的路径就是 home 下的相对路径。
6
+ */
7
+ /** 默认白名单:只同步配置与技能,不含会话、缓存、插件依赖 */
8
+ export declare const DEFAULT_INCLUDE: readonly ['cordis.patch.yml', 'profiles', 'skills'];
9
+ /** 归一后的运行选项 */
10
+ export interface SyncOptions {
11
+ /** git 仓库根,即 $DSH_HOME */
12
+ readonly home: string;
13
+ /** 远端地址,空串表示未绑定 */
14
+ readonly remote: string;
15
+ readonly branch: string;
16
+ /** 相对 home 的白名单路径 */
17
+ readonly include: readonly string[];
18
+ }
19
+ /**
20
+ * 定位 $DSH_HOME:优先显式配置,其次环境变量,再由 profile 目录回推,
21
+ * 最后落到 ~/.dsh。
22
+ */
23
+ export declare function resolveHome(configured?: string): string;
24
+ /** 解析插件配置;缺省值都取保守的一侧(不同步、不打标签) */
25
+ export declare function resolveOptions(config: unknown): SyncOptions;
26
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/internal/config/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,kCAAkC;AAClC,eAAO,MAAM,eAAe,YAAI,kBAAkB,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AAEnF,eAAe;AACf,MAAM,WAAW,WAAW;IAC1B,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mBAAmB;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qBAAqB;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAUD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAOvD;AAED,kCAAkC;AAClC,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,WAAW,CAQ3D"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * options.ts — 把插件行里的 config 归一成运行选项
3
+ *
4
+ * 仓库根固定为 $DSH_HOME(~/.dsh),不做路径映射:
5
+ * 白名单里的路径就是 home 下的相对路径。
6
+ */
7
+ import { homedir } from 'node:os';
8
+ import { resolve } from 'node:path';
9
+ /** 默认白名单:只同步配置与技能,不含会话、缓存、插件依赖 */
10
+ export const DEFAULT_INCLUDE = ['cordis.patch.yml', 'profiles', 'skills'];
11
+ /**
12
+ * 定位 $DSH_HOME:优先显式配置,其次环境变量,再由 profile 目录回推,
13
+ * 最后落到 ~/.dsh。
14
+ */
15
+ export function resolveHome(configured) {
16
+ if (configured !== undefined && configured !== '')
17
+ return resolve(configured);
18
+ const fromEnv = process.env.DSH_HOME;
19
+ if (fromEnv !== undefined && fromEnv !== '')
20
+ return resolve(fromEnv);
21
+ const profileDir = process.env.DSH_PROFILE_DIR;
22
+ if (profileDir !== undefined && profileDir !== '')
23
+ return resolve(profileDir, '..', '..');
24
+ return resolve(homedir(), '.dsh');
25
+ }
26
+ /** 解析插件配置;缺省值都取保守的一侧(不同步、不打标签) */
27
+ export function resolveOptions(config) {
28
+ const raw = (config ?? {});
29
+ return {
30
+ home: resolveHome(raw.home),
31
+ remote: raw.remote ?? '',
32
+ branch: raw.branch ?? 'main',
33
+ include: raw.include !== undefined && raw.include.length > 0 ? raw.include : DEFAULT_INCLUDE,
34
+ };
35
+ }
36
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/internal/config/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,kCAAkC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,kBAAkB,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AAqBnF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,UAAmB;IAC7C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE;QAAE,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9E,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IACrE,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAC/C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE;QAAE,OAAO,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1F,OAAO,OAAO,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,CAAc,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC;QAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;QACxB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,MAAM;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;KAC7F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * endpoints.ts — 暴露给浏览器侧的 RPC 端点
3
+ *
4
+ * 挂在 Connection 的共享 /api 通道上,只在 endpoint 属于本方前缀时接管;
5
+ * 其余 endpoint 交给共享通道的兜底逻辑(404)。
6
+ */
7
+ import type { ConfigSyncService } from '../sync/service.js';
8
+ /** 本方接管的 endpoint 清单 */
9
+ export declare const ENDPOINTS: readonly ['config-sync/status', 'config-sync/inspect', 'config-sync/sync', 'config-sync/pull', 'config-sync/push', 'config-sync/force-pull', 'config-sync/force-push'];
10
+ /** 共享通道的归属判定 */
11
+ export declare function matchesEndpoint(endpoint: string): boolean;
12
+ export interface RpcFailure {
13
+ readonly code: string;
14
+ readonly message: string;
15
+ readonly details: object;
16
+ }
17
+ export type RpcResult = {
18
+ readonly ok: true;
19
+ readonly value: unknown;
20
+ } | {
21
+ readonly ok: false;
22
+ readonly error: RpcFailure;
23
+ };
24
+ /** 与 Connection 的 RpcHandler 形状一致;用不上的入参由实现省略 */
25
+ export type RpcHandler = (endpoint: string, payload: unknown, signal: AbortSignal, peer: unknown) => Promise<RpcResult>;
26
+ export declare function createRpcHandler(service: ConfigSyncService): RpcHandler;
27
+ //# sourceMappingURL=endpoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../../src/internal/rpc/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAe,MAAM,oBAAoB,CAAC;AAEzE,wBAAwB;AACxB,eAAO,MAAM,SAAS,YACpB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,CAChB,CAAC;AAEX,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC9C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAEvD,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAAG,CACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,OAAO,KACV,OAAO,CAAC,SAAS,CAAC,CAAC;AAuBxB,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CA4BvE"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * endpoints.ts — 暴露给浏览器侧的 RPC 端点
3
+ *
4
+ * 挂在 Connection 的共享 /api 通道上,只在 endpoint 属于本方前缀时接管;
5
+ * 其余 endpoint 交给共享通道的兜底逻辑(404)。
6
+ */
7
+ /** 本方接管的 endpoint 清单 */
8
+ export const ENDPOINTS = [
9
+ 'config-sync/status',
10
+ 'config-sync/inspect',
11
+ 'config-sync/sync',
12
+ 'config-sync/pull',
13
+ 'config-sync/push',
14
+ 'config-sync/force-pull',
15
+ 'config-sync/force-push',
16
+ ];
17
+ /** 共享通道的归属判定 */
18
+ export function matchesEndpoint(endpoint) {
19
+ return ENDPOINTS.includes(endpoint);
20
+ }
21
+ function failureOf(error) {
22
+ return {
23
+ ok: false,
24
+ error: {
25
+ code: 'inspect-failed',
26
+ message: error instanceof Error ? error.message : String(error),
27
+ details: {},
28
+ },
29
+ };
30
+ }
31
+ function fromOutcome(outcome) {
32
+ if (outcome.ok) {
33
+ return { ok: true, value: { committed: outcome.committed, backup: outcome.backup } };
34
+ }
35
+ return {
36
+ ok: false,
37
+ error: { code: outcome.failure.kind, message: outcome.failure.message, details: {} },
38
+ };
39
+ }
40
+ export function createRpcHandler(service) {
41
+ return async (endpoint) => {
42
+ switch (endpoint) {
43
+ case 'config-sync/status':
44
+ return { ok: true, value: service.status() };
45
+ case 'config-sync/inspect':
46
+ try {
47
+ return { ok: true, value: await service.inspect() };
48
+ }
49
+ catch (error) {
50
+ return failureOf(error);
51
+ }
52
+ case 'config-sync/sync':
53
+ return fromOutcome(await service.sync());
54
+ case 'config-sync/pull':
55
+ return fromOutcome(await service.pull());
56
+ case 'config-sync/push':
57
+ return fromOutcome(await service.push());
58
+ case 'config-sync/force-pull':
59
+ return fromOutcome(await service.forcePull());
60
+ case 'config-sync/force-push':
61
+ return fromOutcome(await service.forcePush());
62
+ default:
63
+ return {
64
+ ok: false,
65
+ error: { code: 'unknown-endpoint', message: `未知端点:${endpoint}`, details: {} },
66
+ };
67
+ }
68
+ };
69
+ }
70
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../../src/internal/rpc/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,wBAAwB;AACxB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,oBAAoB;IACpB,qBAAqB;IACrB,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AAEX,gBAAgB;AAChB,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAQ,SAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7D,CAAC;AAoBD,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC/D,OAAO,EAAE,EAAE;SACZ;KACF,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,OAAoB;IACvC,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACvF,CAAC;IACD,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;KACrF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE;QACxB,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,oBAAoB;gBACvB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,KAAK,qBAAqB;gBACxB,IAAI,CAAC;oBACH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;gBACtD,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;gBAC1B,CAAC;YACH,KAAK,kBAAkB;gBACrB,OAAO,WAAW,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3C,KAAK,kBAAkB;gBACrB,OAAO,WAAW,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3C,KAAK,kBAAkB;gBACrB,OAAO,WAAW,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3C,KAAK,wBAAwB;gBAC3B,OAAO,WAAW,CAAC,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;YAChD,KAAK,wBAAwB;gBAC3B,OAAO,WAAW,CAAC,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;YAChD;gBACE,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,QAAQ,QAAQ,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;iBAC9E,CAAC;QACN,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * backup.ts — 强拉前的本地备份
3
+ *
4
+ * 覆盖式对齐远端之前,把白名单内容整份拷到 $DSH_HOME/.config-sync-backup/<时间戳>/,
5
+ * 出问题还能捞回来。依赖目录与缓存不进备份,否则一次备份就是几百 MB。
6
+ */
7
+ /** 备份目录名,相对 $DSH_HOME;已列进 git 排除规则,不会被再次同步 */
8
+ export declare const BACKUP_DIR = ".config-sync-backup";
9
+ /**
10
+ * 备份白名单内容。
11
+ * @returns 备份目录绝对路径;没有可备份的内容时返回 null。
12
+ */
13
+ export declare function backupLocal(home: string, include: readonly string[]): Promise<string | null>;
14
+ //# sourceMappingURL=backup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../../../src/internal/sync/backup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,8CAA8C;AAC9C,eAAO,MAAM,UAAU,wBAAwB,CAAC;AAUhD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB"}