openclaw-sync-assistant 0.0.7 → 0.0.9

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/index.js CHANGED
@@ -18,144 +18,145 @@ module.exports = {
18
18
  console.log("✅ openclaw-sync-assistant 插件已激活!");
19
19
  }
20
20
 
21
- // 对于一些旧版本的 OpenClaw 或不同规范,可能需要挂载在 extensions 对象上
22
- if (
23
- context.api &&
24
- context.api.commands &&
25
- typeof context.api.commands.registerCommand === "function"
26
- ) {
27
- try {
28
- context.api.commands.registerCommand("sync.setup", () =>
29
- this.executeCommand("sync.setup", {}, context),
30
- );
31
- } catch (e) {
32
- if (process.env.DEBUG === "openclaw:sync") {
33
- console.error(e);
34
- }
21
+ // 检查是否已经配置过
22
+ let hasConfigured = false;
23
+ if (context.api && context.api.config && context.api.config.get) {
24
+ const currentMethod = await context.api.config.get(
25
+ "openclaw-sync-assistant.syncMethod",
26
+ );
27
+ if (currentMethod) {
28
+ hasConfigured = true;
35
29
  }
36
30
  }
31
+
32
+ // 如果未配置,则在安装/首次加载时触发引导向导
33
+ if (!hasConfigured) {
34
+ await this.runSetupWizard(context);
35
+ }
36
+
37
+ // 根据模式启动后台服务的逻辑占位
38
+ // if (config.syncMethod === 'p2p') startP2PService(context);
39
+ // else if (config.syncMethod === 'github') startGitSyncService(context);
37
40
  },
38
41
 
39
42
  /**
40
- * 插件命令执行函数 (通过 openclaw.plugin.json 中的 commands 声明触发)
41
- * @param {string} commandId - 触发的命令 ID
42
- * @param {object} args - 命令参数
43
- * @param {object} context - OpenClaw 插件上下文
43
+ * 运行配置引导向导
44
44
  */
45
- async executeCommand(commandId, args, context) {
46
- if (commandId === "sync.setup") {
47
- console.log("\n");
48
- intro(pc.bgCyan(pc.black(" OpenClaw Sync Assistant Setup ")));
49
-
50
- const syncMethod = await select({
51
- message: "请选择同步方式 (Sync Method):",
52
- options: [
53
- { value: "p2p", label: "点对点直连 (P2P - 基于 Hyperswarm)" },
54
- { value: "github", label: "GitHub 托管 (基于 Git 仓库)" },
55
- ],
56
- });
45
+ async runSetupWizard(context) {
46
+ console.log("\n");
47
+ intro(pc.bgCyan(pc.black(" OpenClaw Sync Assistant 初始配置引导 ")));
48
+ console.log(
49
+ pc.gray(
50
+ "提示: 你可以随时按 Ctrl+C 跳过此向导,稍后在配置文件中手动设置。\n",
51
+ ),
52
+ );
57
53
 
58
- const syncMode = await select({
59
- message: "请选择同步模式 (Sync Mode):",
60
- options: [
61
- {
62
- value: "decentralized",
63
- label:
64
- "去中心模式 (Decentralized - 适合多设备对等同步,随时随地拉取)",
65
- },
66
- {
67
- value: "centralized",
68
- label:
69
- "中心模式 (Centralized - 适合以某台设备或仓库为主的主从同步)",
70
- },
71
- ],
72
- });
54
+ const syncMethod = await select({
55
+ message: "请选择同步方式 (Sync Method):",
56
+ options: [
57
+ { value: "skip", label: "跳过配置 (稍后设置)" },
58
+ { value: "p2p", label: "点对点直连 (P2P - 基于 Hyperswarm)" },
59
+ { value: "github", label: "GitHub 托管 (基于 Git 仓库)" },
60
+ ],
61
+ });
73
62
 
74
- let syncSecret = "";
75
- let githubRepo = "";
76
-
77
- if (syncMethod === "p2p") {
78
- syncSecret = await text({
79
- message:
80
- "请输入您的同步密钥 (Sync Secret, 用于生成 P2P 发现的 Topic 和加密数据):",
81
- placeholder: "例如: my-super-secret-key",
82
- validate(value) {
83
- if (value.length === 0) return "同步密钥不能为空!";
84
- },
85
- });
86
- } else if (syncMethod === "github") {
87
- githubRepo = await text({
88
- message: "请输入用于同步的 GitHub 仓库地址:",
89
- placeholder: "例如: https://github.com/your-name/sync-repo.git",
90
- validate(value) {
91
- if (value.length === 0) return "GitHub 仓库地址不能为空!";
92
- },
93
- });
94
- }
63
+ if (syncMethod === "skip" || typeof syncMethod === "symbol") {
64
+ outro(pc.yellow("已跳过同步配置。你可以稍后修改 openclaw.json 来启用。"));
65
+ return;
66
+ }
67
+
68
+ const syncMode = await select({
69
+ message: "请选择同步模式 (Sync Mode):",
70
+ options: [
71
+ {
72
+ value: "decentralized",
73
+ label: "去中心模式 (Decentralized - 适合多设备对等同步)",
74
+ },
75
+ {
76
+ value: "centralized",
77
+ label: "中心模式 (Centralized - 适合以某台设备为主的主从同步)",
78
+ },
79
+ { value: "skip", label: "跳过" },
80
+ ],
81
+ });
95
82
 
96
- const syncItems = await multiselect({
97
- message: "请选择要同步的内容:",
98
- options: [
99
- { value: "Config", label: "Config", hint: "OpenClaw 核心配置" },
100
- { value: "Auth", label: "Auth", hint: "认证信息" },
101
- { value: "Sessions", label: "Sessions", hint: "会话记录" },
102
- { value: "Workspace", label: "Workspace", hint: "工作区状态" },
103
- ],
104
- required: true,
83
+ if (syncMode === "skip" || typeof syncMode === "symbol") {
84
+ outro(pc.yellow("已跳过同步配置。"));
85
+ return;
86
+ }
87
+
88
+ let syncSecret = "";
89
+ let githubRepo = "";
90
+
91
+ if (syncMethod === "p2p") {
92
+ syncSecret = await text({
93
+ message: "请输入您的同步密钥 (Sync Secret, 用于生成 P2P 发现和加密):",
94
+ placeholder: "例如: my-super-secret-key (直接回车可跳过)",
95
+ });
96
+ if (typeof syncSecret === "symbol") return;
97
+ } else if (syncMethod === "github") {
98
+ githubRepo = await text({
99
+ message: "请输入用于同步的 GitHub 仓库地址:",
100
+ placeholder: "例如: https://github.com/... (直接回车可跳过)",
105
101
  });
102
+ if (typeof githubRepo === "symbol") return;
103
+ }
106
104
 
107
- const s = spinner();
108
- s.start(
109
- `正在初始化 [${syncMethod.toUpperCase()} - ${syncMode}] 同步服务...`,
110
- );
105
+ const syncItems = await multiselect({
106
+ message: "请选择要同步的内容 (按空格勾选,回车确认):",
107
+ options: [
108
+ { value: "Config", label: "Config", hint: "OpenClaw 核心配置" },
109
+ { value: "Auth", label: "Auth", hint: "认证信息" },
110
+ { value: "Workspace", label: "Workspace", hint: "工作区状态" },
111
+ ],
112
+ required: false,
113
+ });
114
+
115
+ if (typeof syncItems === "symbol") return;
116
+
117
+ const s = spinner();
118
+ s.start(`正在保存初始配置...`);
111
119
 
112
- // 如果通过 executeCommand 传入的 context 带有 api,则更新配置
113
- if (
114
- context &&
115
- context.api &&
116
- context.api.config &&
117
- context.api.config.update
118
- ) {
120
+ if (
121
+ context &&
122
+ context.api &&
123
+ context.api.config &&
124
+ context.api.config.update
125
+ ) {
126
+ await context.api.config.update(
127
+ "openclaw-sync-assistant.syncMethod",
128
+ syncMethod,
129
+ );
130
+ await context.api.config.update(
131
+ "openclaw-sync-assistant.syncMode",
132
+ syncMode,
133
+ );
134
+ if (syncSecret) {
119
135
  await context.api.config.update(
120
- "openclaw-sync-assistant.syncMethod",
121
- syncMethod,
136
+ "openclaw-sync-assistant.syncSecret",
137
+ syncSecret,
122
138
  );
139
+ }
140
+ if (githubRepo) {
123
141
  await context.api.config.update(
124
- "openclaw-sync-assistant.syncMode",
125
- syncMode,
142
+ "openclaw-sync-assistant.githubRepo",
143
+ githubRepo,
126
144
  );
127
- if (syncSecret)
128
- await context.api.config.update(
129
- "openclaw-sync-assistant.syncSecret",
130
- syncSecret,
131
- );
132
- if (githubRepo)
133
- await context.api.config.update(
134
- "openclaw-sync-assistant.githubRepo",
135
- githubRepo,
136
- );
145
+ }
146
+ if (syncItems && syncItems.length > 0) {
137
147
  await context.api.config.update(
138
148
  "openclaw-sync-assistant.syncItems",
139
149
  syncItems,
140
150
  );
141
- } else {
142
- if (process.env.DEBUG === "openclaw:sync") {
143
- console.log(
144
- "提示: 未找到 context.api.config.update,配置未持久化保存。",
145
- );
146
- }
147
151
  }
148
-
149
- await new Promise((resolve) => setTimeout(resolve, 1500));
150
-
151
- s.stop("配置已保存!");
152
-
153
- outro(
154
- pc.green(
155
- `✔ 配置完成!同步助手后台服务已按 [${syncMethod.toUpperCase()} - ${syncMode}] 接管状态同步。`,
156
- ),
157
- );
158
152
  }
153
+
154
+ s.stop("配置已保存!");
155
+ outro(
156
+ pc.green(
157
+ `✔ 配置向导完成!后台服务将按 [${syncMethod.toUpperCase()}] 模式运行。`,
158
+ ),
159
+ );
159
160
  },
160
161
 
161
162
  /**
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "openclaw-sync-assistant",
3
3
  "name": "openclaw-sync-assistant",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "OpenClaw Sync Assistant Plugin",
6
6
  "commands": [
7
7
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-sync-assistant",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "An OpenClaw plugin for P2P file and data synchronization using Hyperswarm and Hyperdrive ecosystem.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",