@aiyiran/myclaw 1.0.171 → 1.0.173

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 (3) hide show
  1. package/create_agent.js +16 -41
  2. package/index.js +65 -30
  3. package/package.json +1 -1
package/create_agent.js CHANGED
@@ -93,49 +93,24 @@ function buildBirthMessage() {
93
93
  }
94
94
 
95
95
  /**
96
- * 默认工作空间文件内容
96
+ * 从当前 workspace 模板目录复制默认文件,替换 agentId
97
97
  */
98
98
  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
- };
99
+ const templateDir = path.resolve(__dirname, '..');
100
+ const templateFiles = ['AGENTS.md', 'SOUL.md', 'USER.md', 'IDENTITY.md', 'HEARTBEAT.md', 'BOOTSTRAP.md'];
101
+ const files = {};
102
+
103
+ for (const fn of templateFiles) {
104
+ const src = path.join(templateDir, fn);
105
+ if (fs.existsSync(src)) {
106
+ let content = fs.readFileSync(src, 'utf8');
107
+ // 把模板中的 yiranclaw(或当前 workspace 名)替换为新 agentId
108
+ content = content.replace(/yiranclaw/g, agentId);
109
+ files[fn] = content;
110
+ }
111
+ }
112
+
113
+ return files;
139
114
  }
140
115
 
141
116
  // ============================================================================
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,6 +1042,14 @@ 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 },
1045
+ { key: 'wsl2reinstall', label: 'WSL2虚拟机重装', cmd: 'mc wsl2 --remote', desc: '强制从网络重新下载并重装 WSL2 虚拟机(仅限 Windows)', action: () => {
1046
+ const wsl2 = require('./wsl2');
1047
+ wsl2.run();
1048
+ }},
1049
+ { key: 'safe', label: '虚拟机屏蔽', cmd: 'mc safe', desc: '禁止 WSL2 访问 Windows 盘符(仅限 Windows)', action: () => {
1050
+ const restrict = require('./restrict');
1051
+ restrict.run();
1052
+ }},
1018
1053
  { key: 'quit', label: '退出', cmd: 'Ctrl+C', desc: '不玩了,下次见', action: () => { console.log(' 👋 再见!\n'); process.exit(0); } },
1019
1054
  ];
1020
1055
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.171",
3
+ "version": "1.0.173",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {