@aiyiran/myclaw 1.0.172 → 1.0.174

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/create_agent.js CHANGED
@@ -93,49 +93,37 @@ function buildBirthMessage() {
93
93
  }
94
94
 
95
95
  /**
96
- * 默认工作空间文件内容
96
+ * 从当前 workspace 模板目录复制默认文件,替换 agentId
97
+ * SOUL.md 使用 inject-workspaceAndSoul.js 中的学习伙伴模板
97
98
  */
98
99
  function defaultWorkspaceFiles(agentId) {
99
- return {
100
- 'AGENTS.md': (
101
- `# AGENTS.md - ${agentId}\n\n` +
102
- `This workspace belongs to the \`${agentId}\` agent.\n\n` +
103
- '## Startup\n' +
104
- '- Read `SOUL.md`\n' +
105
- '- Read `USER.md`\n' +
106
- '- Read recent memory if available\n\n' +
107
- '## Rules\n' +
108
- '- Be helpful, careful, and concise.\n' +
109
- '- Prefer using the existing workspace and defaults.\n' +
110
- '- Ask before destructive or external actions.\n'
111
- ),
112
- 'SOUL.md': (
113
- `# SOUL.md\n\n` +
114
- `You are \`${agentId}\`.\n\n` +
115
- 'Be useful, calm, direct, and trustworthy.\n' +
116
- 'Use the default OpenClaw behavior unless the user asks for something special.\n'
117
- ),
118
- 'USER.md': (
119
- '# USER.md\n\n' +
120
- '- Timezone: Asia/Shanghai\n\n' +
121
- 'Build understanding gradually and respectfully.\n'
122
- ),
123
- 'IDENTITY.md': (
124
- '# IDENTITY.md\n\n' +
125
- `- Name: ${agentId}\n` +
126
- '- Role: OpenClaw agent\n' +
127
- '- Vibe: practical, reliable, clear\n'
128
- ),
129
- 'HEARTBEAT.md': (
130
- '# HEARTBEAT.md\n\n' +
131
- '# Keep empty unless periodic checks are needed.\n'
132
- ),
133
- 'BOOTSTRAP.md': (
134
- `# BOOTSTRAP.md\n\n` +
135
- `You are a newly created OpenClaw agent named \`${agentId}\`.\n\n` +
136
- 'On first runs, learn your workspace files and begin helping.\n'
137
- ),
138
- };
100
+ const templateDir = path.resolve(__dirname, '..');
101
+ const templateFiles = ['AGENTS.md', 'USER.md', 'IDENTITY.md', 'HEARTBEAT.md', 'BOOTSTRAP.md'];
102
+ const files = {};
103
+
104
+ // 从根 workspace 复制其他文件
105
+ for (const fn of templateFiles) {
106
+ const src = path.join(templateDir, fn);
107
+ if (fs.existsSync(src)) {
108
+ let content = fs.readFileSync(src, 'utf8');
109
+ content = content.replace(/yiranclaw/g, agentId);
110
+ files[fn] = content;
111
+ }
112
+ }
113
+
114
+ // SOUL.md 使用学生学习伙伴模板
115
+ const soulModule = require('./inject-workspaceAndSoul');
116
+ // 直接读取模块里的 SOUL_CONTENT(不依赖导出,直接读源文件更可靠)
117
+ const soulSrc = path.join(__dirname, 'inject-workspaceAndSoul.js');
118
+ if (fs.existsSync(soulSrc)) {
119
+ const raw = fs.readFileSync(soulSrc, 'utf8');
120
+ const match = raw.match(/const SOUL_CONTENT = `([\s\S]*?)`;/);
121
+ if (match) {
122
+ files['SOUL.md'] = match[1];
123
+ }
124
+ }
125
+
126
+ return files;
139
127
  }
140
128
 
141
129
  // ============================================================================
package/index.js CHANGED
@@ -454,39 +454,66 @@ pause >nul
454
454
  const iconPath = path.join(myClawDir, 'openclaw.ico');
455
455
  const iconUrl = 'https://cdn.yiranlaoshi.com/software/myclaw/openclaw.ico';
456
456
 
457
- const psScript = `
458
- $ErrorActionPreference = 'SilentlyContinue'
459
- if (-not (Test-Path '${iconPath.replace(/\\/g, '\\\\')}')) {
460
- Invoke-WebRequest -Uri '${iconUrl}' -OutFile '${iconPath.replace(/\\/g, '\\\\')}' -UseBasicParsing
461
- }
462
- $ws = New-Object -ComObject WScript.Shell
463
- $sc = $ws.CreateShortcut('${lnkPath.replace(/\\/g, '\\\\')}')
464
- $sc.TargetPath = '${batPath.replace(/\\/g, '\\\\')}'
465
- $sc.WorkingDirectory = '${myClawDir.replace(/\\/g, '\\\\')}'
466
- $sc.WindowStyle = 1
467
- $sc.IconLocation = '${iconPath.replace(/\\/g, '\\\\')}'
468
- $sc.Description = 'OpenClaw'
469
- $sc.Save()
470
-
471
- # 创建「我的私人龙虾」工作目录快捷方式(如不存在)
472
- $workspaceLnk = '${desktopPath}\\我的私人龙虾.lnk'
473
- if (-not (Test-Path $workspaceLnk)) {
474
- $ws2 = New-Object -ComObject WScript.Shell
475
- $sc2 = $ws2.CreateShortcut($workspaceLnk)
476
- $sc2.TargetPath = '\\\\wsl.localhost\\OpenClaw\\root\\.openclaw\\workspace'
477
- $sc2.WorkingDirectory = '\\\\wsl.localhost\\OpenClaw\\root\\.openclaw\\workspace'
478
- $sc2.Description = 'OpenClaw Workspace'
479
- $sc2.IconLocation = 'C:\\Windows\\System32\\SHELL32.dll,4'
480
- $sc2.Save()
481
- }
482
-
483
- Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class Shell { [DllImport("shell32.dll")] public static extern void SHChangeNotify(int e, int f, IntPtr i1, IntPtr i2); }' -ErrorAction SilentlyContinue
484
- [Shell]::SHChangeNotify(0x08000000, 0, [IntPtr]::Zero, [IntPtr]::Zero)
485
- `;
457
+ const psFile = path.join(myClawDir, 'create-shortcuts.ps1');
458
+ const psContent = [
459
+ '$ErrorActionPreference = \'Continue\'',
460
+ '',
461
+ '# 下载图标(如不存在)',
462
+ 'if (-not (Test-Path \'' + iconPath + '\')) {',
463
+ ' try { Invoke-WebRequest -Uri \'' + iconUrl + '\' -OutFile \'' + iconPath + '\' -UseBasicParsing } catch {}',
464
+ '}',
465
+ '',
466
+ '# 创建 OpenClaw 启动快捷方式',
467
+ '$ws = New-Object -ComObject WScript.Shell',
468
+ '$sc = $ws.CreateShortcut(\'' + lnkPath + '\')',
469
+ '$sc.TargetPath = \'' + batPath + '\'',
470
+ '$sc.WorkingDirectory = \'' + myClawDir + '\'',
471
+ '$sc.WindowStyle = 1',
472
+ '$sc.IconLocation = \'' + iconPath + '\'',
473
+ '$sc.Description = \'OpenClaw\'',
474
+ '$sc.Save()',
475
+ 'Write-Host \'[bat] OpenClaw shortcut created\'',
476
+ '',
477
+ '# 创建「我的私人龙虾」工作目录快捷方式(如不存在)',
478
+ '$workspaceLnk = \'' + desktopPath + '\\我的私人龙虾.lnk\'',
479
+ 'if (-not (Test-Path $workspaceLnk)) {',
480
+ ' $ws2 = New-Object -ComObject WScript.Shell',
481
+ ' $sc2 = $ws2.CreateShortcut($workspaceLnk)',
482
+ ' $sc2.TargetPath = \'\\\\wsl.localhost\\OpenClaw\\root\\.openclaw\\workspace\'',
483
+ ' $sc2.WorkingDirectory = \'\\\\wsl.localhost\\OpenClaw\\root\\.openclaw\\workspace\'',
484
+ ' $sc2.Description = \'OpenClaw Workspace\'',
485
+ ' $sc2.IconLocation = \'C:\\Windows\\System32\\SHELL32.dll,4\'',
486
+ ' $sc2.Save()',
487
+ ' Write-Host \'[bat] workspace shortcut created\'',
488
+ '} else {',
489
+ ' Write-Host \'[bat] workspace shortcut already exists\'',
490
+ '}',
491
+ '',
492
+ '# 刷新桌面',
493
+ 'try {',
494
+ ' Add-Type -TypeDefinition \'using System; using System.Runtime.InteropServices; public class ShellRefresh { [DllImport(\"shell32.dll\")] public static extern void SHChangeNotify(int e, int f, IntPtr i1, IntPtr i2); }\' -ErrorAction Stop',
495
+ ' [ShellRefresh]::SHChangeNotify(0x08000000, 0, [IntPtr]::Zero, [IntPtr]::Zero)',
496
+ ' Write-Host \'[bat] desktop refreshed\'',
497
+ '} catch {',
498
+ ' Write-Host \'[bat] refresh skipped\'',
499
+ '}',
500
+ ].join('\r\n');
501
+
502
+ // UTF-8 BOM + 写入
503
+ fs.writeFileSync(psFile, '\uFEFF' + psContent, 'utf8');
486
504
 
487
505
  try {
488
506
  const { execSync } = require('child_process');
489
- execSync(`powershell -NoProfile -Command "${psScript.replace(/"/g, '\\"').replace(/\n/g, '; ')}"`, { stdio: 'pipe' });
507
+ const psOutput = execSync('powershell -NoProfile -ExecutionPolicy Bypass -File "' + psFile + '"', {
508
+ encoding: 'utf8',
509
+ stdio: ['pipe', 'pipe', 'pipe'],
510
+ });
511
+ // 打印 PowerShell 的详细日志
512
+ if (psOutput) {
513
+ psOutput.trim().split('\n').forEach(line => {
514
+ if (line.trim()) console.log(' ' + line.trim());
515
+ });
516
+ }
490
517
 
491
518
  console.log('');
492
519
  console.log('[' + colors.green + '成功' + colors.nc + '] 桌面快捷方式已创建!');
@@ -1015,7 +1042,8 @@ const MENU_ITEMS = [
1015
1042
  { key: 'patch', label: '修复', cmd: 'mc patch', desc: '给 AI 助手装上新技能和好看的外衣', action: runPatch },
1016
1043
  { key: 'reinstall', label: '重装', cmd: 'mc longxia', desc: '出了大问题?把 AI 助手删了重新安装', action: runReinstall },
1017
1044
  { key: 'uninstall', label: '卸载', cmd: 'mc uninstall', desc: '卸载 MyClaw,恢复 npm 源地址', action: runUninstall },
1018
- { key: 'wsl2reinstall', label: 'WSL2虚拟机重装', cmd: 'mc wsl2 --remote', desc: '强制从网络重新下载并重装 WSL2 虚拟机(仅限 Windows)', action: () => {
1045
+ { key: 'wsl2reinstall', label: 'WSL2虚拟机重装', cmd: 'mc wsl2 --remote --force-phase1', desc: '强制从网络重新下载并重装 WSL2 虚拟机(仅限 Windows)', action: () => {
1046
+ process.argv.push('--remote', '--force-phase1');
1019
1047
  const wsl2 = require('./wsl2');
1020
1048
  wsl2.run();
1021
1049
  }},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.172",
3
+ "version": "1.0.174",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/restrict.js CHANGED
@@ -111,7 +111,7 @@ function run() {
111
111
  if (existing.includes('[automount]')) {
112
112
  newContent = existing.replace(/\[automount\][^\[]*/, '[automount]\nenabled = false\n');
113
113
  } else {
114
- newContent = existing + (existing.endsWith('\n') ? '' : '\n') + '[automount]\nenabled = false\n';
114
+ newContent = existing + (existing.endsWith('\n') ? '' : '\n') + '[automount]\nenabled = false\n[interop]\nappendWindowsPath = false\n';
115
115
  }
116
116
 
117
117
  const script = [
package/start.js CHANGED
@@ -68,18 +68,10 @@ function startWindows() {
68
68
 
69
69
  // Step 2.5: 自动检测虚拟机屏蔽(safe)
70
70
  console.log('[safe] 虚拟机屏蔽...');
71
- try {
72
- const conf = execSync('wsl -d OpenClaw -u root -- cat /etc/wsl.conf 2>/dev/null', {
73
- encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'],
74
- });
75
- if (conf.includes('enabled = false') || conf.includes('enabled=false')) {
76
- console.log(' ' + C.g + '[已开启]' + C.nc);
77
- } else {
78
- console.log(' ' + C.y + '[未开启,正在启用...]' + C.nc);
79
- try { execSync('myclaw safe', { stdio: 'inherit', timeout: 30000 }); } catch {}
80
- }
81
- } catch {
82
- // wsl.conf 不存在,说明还没开启
71
+ const restrict = require('./restrict');
72
+ if (restrict.isAlreadySafe()) {
73
+ console.log(' ' + C.g + '[已开启]' + C.nc);
74
+ } else {
83
75
  console.log(' ' + C.y + '[未开启,正在启用...]' + C.nc);
84
76
  try { execSync('myclaw safe', { stdio: 'inherit', timeout: 30000 }); } catch {}
85
77
  }