openclaw-weiyuan-init 1.0.119 → 1.0.127

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/bin/cli.js CHANGED
@@ -3,11 +3,12 @@
3
3
  const { program } = require('commander');
4
4
  const chalk = require('chalk');
5
5
  const { runInit, runClean, runStatus } = require('../lib/commands');
6
+ const { version } = require('../package.json');
6
7
 
7
8
  program
8
9
  .name('openclaw-weiyuan-init')
9
10
  .description('OpenClaw Weiyuan Skill 一键初始化工具')
10
- .version('1.0.0');
11
+ .version(version);
11
12
 
12
13
  program
13
14
  .command('init')
package/lib/commands.js CHANGED
@@ -456,7 +456,19 @@ async function persistReleaseNotes(weiyuanPath, notes) {
456
456
 
457
457
  function resolveWorkspacePath(workspaceOption) {
458
458
  const raw = (workspaceOption || DEFAULT_CONFIG.workspaceName).trim();
459
- const target = path.isAbsolute(raw) ? raw : path.join(process.cwd(), raw);
459
+ const cwd = process.cwd();
460
+ const workspaceName = DEFAULT_CONFIG.workspaceName.toLowerCase();
461
+ const cwdBase = path.basename(cwd).toLowerCase();
462
+ const rawParts = raw.replace(/\\/g, '/').split('/').map((x) => String(x || '').trim()).filter(Boolean);
463
+ if (cwdBase === workspaceName) {
464
+ if (!raw || raw === '.' || raw === './' || raw === '.\\') {
465
+ return cwd;
466
+ }
467
+ if (rawParts.length > 0 && rawParts.every((part) => part.toLowerCase() === workspaceName)) {
468
+ return cwd;
469
+ }
470
+ }
471
+ const target = path.isAbsolute(raw) ? raw : path.join(cwd, raw);
460
472
  if (path.basename(target).toLowerCase() === DEFAULT_CONFIG.workspaceName.toLowerCase()) {
461
473
  return target;
462
474
  }
package/lib/identity.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs-extra');
2
2
  const os = require('os');
3
+ const path = require('path');
3
4
  const crypto = require('crypto');
4
5
  const axios = require('axios');
5
6
  const naclImport = require('tweetnacl');
@@ -64,12 +65,66 @@ function normalizeBusinessServerUrl(serverUrl) {
64
65
  }
65
66
  }
66
67
 
67
- async function registerIdentity(serverUrl, identity) {
68
+ function applyIdentityProxyMetadata(identity, initInfo) {
69
+ const next = identity && typeof identity === 'object' ? { ...identity } : {};
70
+ const lobsterId = String(next.lobsterId || '').trim();
71
+ const effectiveLobsterId = String(initInfo && initInfo.effectiveLobsterId || '').trim();
72
+ const ownerLobsterId = String(initInfo && initInfo.ownerLobsterId || '').trim();
73
+ const accountModeRaw = String(initInfo && initInfo.accountMode || initInfo && initInfo.mode || '').trim();
74
+ const accountMode = accountModeRaw === 'agent' || accountModeRaw === 'owner' ? accountModeRaw : '';
75
+ const accountTypeRaw = String(initInfo && initInfo.accountType || '').trim().toLowerCase();
76
+ const accountType = accountTypeRaw === 'auto' || accountTypeRaw === 'weiyuan' || accountTypeRaw === 'lob' ? accountTypeRaw : '';
77
+ const displayAccountId = String((initInfo && (initInfo.displayAccountId || initInfo.account)) || '').trim();
78
+ if (effectiveLobsterId && effectiveLobsterId !== lobsterId) next.effectiveLobsterId = effectiveLobsterId;
79
+ else delete next.effectiveLobsterId;
80
+ if (ownerLobsterId && ownerLobsterId !== lobsterId) next.ownerLobsterId = ownerLobsterId;
81
+ else delete next.ownerLobsterId;
82
+ if (accountMode) next.accountMode = accountMode;
83
+ else delete next.accountMode;
84
+ if (accountType) next.accountType = accountType;
85
+ else delete next.accountType;
86
+ if (displayAccountId) next.displayAccountId = displayAccountId;
87
+ else delete next.displayAccountId;
88
+ return next;
89
+ }
90
+
91
+ function normalizeSkillVersionText(raw) {
92
+ const text = String(raw || '').trim().replace(/^v/i, '');
93
+ return text && text !== '0.0.0' ? text : '';
94
+ }
95
+
96
+ async function readLocalSkillVersion(workspacePath) {
97
+ const weiyuanPath = path.join(String(workspacePath || ''), 'weiyuan');
98
+ const candidates = [
99
+ path.join(weiyuanPath, 'package.json'),
100
+ path.join(weiyuanPath, 'release-notes', 'latest.json'),
101
+ path.join(weiyuanPath, 'manifest.json'),
102
+ ];
103
+ for (const file of candidates) {
104
+ try {
105
+ const parsed = await fs.readJson(file);
106
+ const version = normalizeSkillVersionText(parsed && parsed.version);
107
+ if (version) return version;
108
+ } catch (_) {
109
+ }
110
+ }
111
+ try {
112
+ const plain = await fs.readFile(path.join(weiyuanPath, '.version'), 'utf8');
113
+ const version = normalizeSkillVersionText(plain);
114
+ if (version) return version;
115
+ } catch (_) {
116
+ }
117
+ return '';
118
+ }
119
+
120
+ async function registerIdentity(serverUrl, identity, workspacePath) {
121
+ const skillVersion = await readLocalSkillVersion(workspacePath);
68
122
  const body = {
69
123
  lobsterId: identity.lobsterId,
70
124
  publicKeyBase64: identity.publicKeyBase64,
71
125
  identityHash: identity.identityHash,
72
- recoveryHint: identity && identity.meta ? identity.meta.recoveryHint : undefined
126
+ recoveryHint: identity && identity.meta ? identity.meta.recoveryHint : undefined,
127
+ skillVersion: skillVersion || undefined
73
128
  };
74
129
  const timestampMs = String(Date.now());
75
130
  const nonce = `nonce_${Math.random().toString(16).slice(2)}`;
@@ -127,7 +182,7 @@ async function createIdentityFile(identityPath, serverUrl, workspacePath) {
127
182
  recoveryHint: (existing.meta && existing.meta.recoveryHint) || buildRecoveryHint(workspacePath)
128
183
  }
129
184
  };
130
- const initInfo = await registerIdentity(serverUrl, identity);
185
+ const initInfo = await registerIdentity(serverUrl, identity, workspacePath);
131
186
  const serverLobsterId = String(initInfo && initInfo.lobsterId || '').trim();
132
187
  if (serverLobsterId) {
133
188
  identity.lobsterId = serverLobsterId;
@@ -151,7 +206,8 @@ async function createIdentityFile(identityPath, serverUrl, workspacePath) {
151
206
  .filter(([k, v]) => k && Number.isFinite(v))
152
207
  )
153
208
  : {};
154
- await fs.writeJson(identityPath, identity, { spaces: 2 });
209
+ const nextIdentity = applyIdentityProxyMetadata(identity, initInfo);
210
+ await fs.writeJson(identityPath, nextIdentity, { spaces: 2 });
155
211
  return { created: true, initInfo: initInfo || null };
156
212
  }
157
213
  }
@@ -176,7 +232,7 @@ async function createIdentityFile(identityPath, serverUrl, workspacePath) {
176
232
  }
177
233
  };
178
234
 
179
- const initInfo = await registerIdentity(serverUrl, identity);
235
+ const initInfo = await registerIdentity(serverUrl, identity, workspacePath);
180
236
  const serverLobsterId = String(initInfo && initInfo.lobsterId || '').trim();
181
237
  if (serverLobsterId) {
182
238
  identity.lobsterId = serverLobsterId;
@@ -200,7 +256,8 @@ async function createIdentityFile(identityPath, serverUrl, workspacePath) {
200
256
  .filter(([k, v]) => k && Number.isFinite(v))
201
257
  )
202
258
  : {};
203
- await fs.writeJson(identityPath, identity, { spaces: 2 });
259
+ const nextIdentity = applyIdentityProxyMetadata(identity, initInfo);
260
+ await fs.writeJson(identityPath, nextIdentity, { spaces: 2 });
204
261
  return { created: true, initInfo: initInfo || null };
205
262
  } catch (error) {
206
263
  return { created: false, initInfo: null, error: error && error.message ? String(error.message) : 'identity_create_failed' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-weiyuan-init",
3
- "version": "1.0.119",
3
+ "version": "1.0.127",
4
4
  "description": "OpenClaw Weiyuan Skill 一键初始化工具",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {