@lark-apaas/miaoda-cli 0.1.24-alpha.4f6196e → 0.1.24-alpha.54e1135

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.
@@ -6,11 +6,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.extractLaneFromTgzKey = extractLaneFromTgzKey;
7
7
  exports.syncSandboxSkills = syncSandboxSkills;
8
8
  exports.validateSandboxSyncOpts = validateSandboxSyncOpts;
9
+ const node_child_process_1 = require("node:child_process");
9
10
  const node_fs_1 = __importDefault(require("node:fs"));
10
11
  const node_path_1 = __importDefault(require("node:path"));
11
12
  const npm_pack_1 = require("../utils/npm-pack");
12
13
  const error_1 = require("../utils/error");
13
14
  const logger_1 = require("../utils/logger");
15
+ /**
16
+ * 覆盖式清空目录,权限兜底:`chmod -R u+w` → `rm -rf` → `fs.rmSync`。
17
+ *
18
+ * 为什么要 chmod:沙箱里 skill 目录 owner 是当前用户 (gem),但老
19
+ * `update-skills.sh` 会显式 `chmod -R a-w` 把 skill 目录锁只读(防用户改 skill 内容)。
20
+ * gem 是 owner 但没 write 权限,unlink 里面文件挂 EACCES;shell `rm -rf` 也过不去。
21
+ * 因为 gem 是 owner,`chmod -R u+w` 能自己给自己加写权限(不需要 sudo,绕过沙箱
22
+ * "no new privileges" 容器 flag)。
23
+ */
24
+ function forceRemoveDir(dir) {
25
+ if (!node_fs_1.default.existsSync(dir))
26
+ return;
27
+ // 先 chmod -R u+w 恢复写权限(应对老 update.sh 的 `chmod -R a-w` 只读锁)
28
+ try {
29
+ (0, node_child_process_1.execFileSync)('chmod', ['-R', 'u+w', dir], { stdio: ['ignore', 'ignore', 'pipe'] });
30
+ }
31
+ catch (err) {
32
+ (0, logger_1.debug)(`sandbox-skills: chmod -R u+w ${dir} failed: ${err.message}`);
33
+ }
34
+ // 主档:shell rm -rf
35
+ try {
36
+ (0, node_child_process_1.execFileSync)('rm', ['-rf', dir], { stdio: ['ignore', 'ignore', 'pipe'] });
37
+ if (!node_fs_1.default.existsSync(dir))
38
+ return;
39
+ }
40
+ catch (err) {
41
+ (0, logger_1.debug)(`sandbox-skills: rm -rf ${dir} failed: ${err.message}`);
42
+ }
43
+ // Fallback:Node fs.rmSync 尽力而为
44
+ node_fs_1.default.rmSync(dir, { recursive: true, force: true });
45
+ }
14
46
  const PACKAGE_BY_TYPE = {
15
47
  miaoda: '@lark-apaas/coding-miaoda-sandbox',
16
48
  'miaoda-modern': '@lark-apaas/coding-miaoda-sandbox',
@@ -87,7 +119,10 @@ function syncSandboxSkills(opts) {
87
119
  ? node_path_1.default.join(targetDir, 'skills')
88
120
  : node_path_1.default.join(targetDir, '.agent', 'skills');
89
121
  // 覆盖式:清空目标 skill 根目录(对齐 cp-skills.sh 行为,避免遗留老 skill)
90
- node_fs_1.default.rmSync(skillsRoot, { recursive: true, force: true });
122
+ // 用 forceRemoveDir 兜底:老沙箱可能残留其他用户写的 stale 文件(例如老 update.sh
123
+ // 以 root 跑,写下 root owned 的 `.last-update`),fs.rmSync {force:true} 遇到 EACCES
124
+ // 会 throw。见 forceRemoveDir 注释。
125
+ forceRemoveDir(skillsRoot);
91
126
  node_fs_1.default.mkdirSync(skillsRoot, { recursive: true });
92
127
  const syncedTop = [];
93
128
  if (businessLine !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-cli",
3
- "version": "0.1.24-alpha.4f6196e",
3
+ "version": "0.1.24-alpha.54e1135",
4
4
  "description": "Miaoda 平台命令行工具,面向 Agent 调用",
5
5
  "type": "commonjs",
6
6
  "bin": {