modellab-cli 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -3,10 +3,19 @@
3
3
  独立 Node.js 24 命令行客户端,使用版本化公共契约和 SDK,不引用服务端或 Web 源码。
4
4
 
5
5
  ```sh
6
- npm install -g modellab-cli@0.1.0
6
+ npx modellab-cli@0.1.1 install
7
7
  modellab --version
8
8
  ```
9
9
 
10
+ 一键安装将 CLI 全局安装,并将包内所有操作 Skill 同步到 `~/.agents/skills`。Claude Code 从 `~/.claude/skills` 中的逐个目录软链接读取同一份内容。
11
+
12
+ ```sh
13
+ # 只安装 CLI
14
+ npm install -g modellab-cli@0.1.1
15
+ # 使用已安装的 CLI,把操作 Skill 装到当前项目
16
+ modellab install --skip-cli --target .agents/skills
17
+ ```
18
+
10
19
  ## 本地构建
11
20
 
12
21
  ```sh
@@ -15,7 +24,7 @@ pnpm check
15
24
  pnpm test
16
25
  pnpm skill:pack
17
26
  npm pack --pack-destination release
18
- npm install -g ./release/modellab-cli-0.1.0.tgz
27
+ npm install -g ./release/modellab-cli-0.1.1.tgz
19
28
  modellab --version
20
29
  ```
21
30
 
@@ -59,12 +68,11 @@ modellab api call budgets.set --file budget.json --json
59
68
  ## 独立操作 Skill
60
69
 
61
70
  ```sh
62
- modellab integrations skills install --target codex --skill-version 0.1.0
63
- modellab integrations skills install --target claude --skill-version 0.1.0
71
+ modellab integrations skills install --skill-version 0.1.0
64
72
  # 或手工解压 release/modellab-operations-0.1.0.tgz 到目标工具的 Skill 目录。
65
73
  ```
66
74
 
67
- 操作包名为 modellab-operations,类型 operation-skill-package。它与服务端 instruction_skill 资源分离。安装检查路径和文件哈希,拒绝覆盖已有修改;可用 --directory 安装到新目录后比较。CLI 升级不会自动改写已经安装的 Skill。
75
+ 操作包名为 `modellab-operations`,类型为 `operation-skill-package`。项目内的 `.agents/skills` 会在同一项目的 `.claude/skills` 建立链接。自定义目录可以用 `--directory` 或 `install --target` 指定。安装会校验文件哈希,迁移未修改的旧 Claude 副本,并保留本地修改和其他 Skill。可在新目录安装后比较差异。
68
76
 
69
77
  `tests/standalone-smoke.mjs` 从 npm tarball 安装到全新临时目录,再连接指定测试服务验证登录、项目创建、运行、SSE、等待、重评和 Skill 安装。需要已完成本地浏览器假模型配置,或按测试脚本提供自己的测试环境。
70
78
 
package/dist/index.js CHANGED
@@ -7429,10 +7429,10 @@ var require_resolve_block_map = __commonJS({
7429
7429
  let offset = bm.offset;
7430
7430
  let commentEnd = null;
7431
7431
  for (const collItem of bm.items) {
7432
- const { start, key, sep, value } = collItem;
7432
+ const { start, key, sep: sep2, value } = collItem;
7433
7433
  const keyProps = resolveProps.resolveProps(start, {
7434
7434
  indicator: "explicit-key-ind",
7435
- next: key ?? sep?.[0],
7435
+ next: key ?? sep2?.[0],
7436
7436
  offset,
7437
7437
  onError,
7438
7438
  parentIndent: bm.indent,
@@ -7446,7 +7446,7 @@ var require_resolve_block_map = __commonJS({
7446
7446
  else if ("indent" in key && key.indent !== bm.indent)
7447
7447
  onError(offset, "BAD_INDENT", startColMsg);
7448
7448
  }
7449
- if (!keyProps.anchor && !keyProps.tag && !sep) {
7449
+ if (!keyProps.anchor && !keyProps.tag && !sep2) {
7450
7450
  commentEnd = keyProps.end;
7451
7451
  if (keyProps.comment) {
7452
7452
  if (map.comment)
@@ -7470,7 +7470,7 @@ var require_resolve_block_map = __commonJS({
7470
7470
  ctx.atKey = false;
7471
7471
  if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
7472
7472
  onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
7473
- const valueProps = resolveProps.resolveProps(sep ?? [], {
7473
+ const valueProps = resolveProps.resolveProps(sep2 ?? [], {
7474
7474
  indicator: "map-value-ind",
7475
7475
  next: value,
7476
7476
  offset: keyNode.range[2],
@@ -7486,7 +7486,7 @@ var require_resolve_block_map = __commonJS({
7486
7486
  if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
7487
7487
  onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
7488
7488
  }
7489
- const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
7489
+ const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep2, null, valueProps, onError);
7490
7490
  if (ctx.schema.compat)
7491
7491
  utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
7492
7492
  offset = valueNode.range[2];
@@ -7577,7 +7577,7 @@ var require_resolve_end = __commonJS({
7577
7577
  let comment = "";
7578
7578
  if (end) {
7579
7579
  let hasSpace = false;
7580
- let sep = "";
7580
+ let sep2 = "";
7581
7581
  for (const token of end) {
7582
7582
  const { source, type } = token;
7583
7583
  switch (type) {
@@ -7591,13 +7591,13 @@ var require_resolve_end = __commonJS({
7591
7591
  if (!comment)
7592
7592
  comment = cb;
7593
7593
  else
7594
- comment += sep + cb;
7595
- sep = "";
7594
+ comment += sep2 + cb;
7595
+ sep2 = "";
7596
7596
  break;
7597
7597
  }
7598
7598
  case "newline":
7599
7599
  if (comment)
7600
- sep += source;
7600
+ sep2 += source;
7601
7601
  hasSpace = true;
7602
7602
  break;
7603
7603
  default:
@@ -7640,18 +7640,18 @@ var require_resolve_flow_collection = __commonJS({
7640
7640
  let offset = fc.offset + fc.start.source.length;
7641
7641
  for (let i = 0; i < fc.items.length; ++i) {
7642
7642
  const collItem = fc.items[i];
7643
- const { start, key, sep, value } = collItem;
7643
+ const { start, key, sep: sep2, value } = collItem;
7644
7644
  const props = resolveProps.resolveProps(start, {
7645
7645
  flow: fcName,
7646
7646
  indicator: "explicit-key-ind",
7647
- next: key ?? sep?.[0],
7647
+ next: key ?? sep2?.[0],
7648
7648
  offset,
7649
7649
  onError,
7650
7650
  parentIndent: fc.indent,
7651
7651
  startOnNewline: false
7652
7652
  });
7653
7653
  if (!props.found) {
7654
- if (!props.anchor && !props.tag && !sep && !value) {
7654
+ if (!props.anchor && !props.tag && !sep2 && !value) {
7655
7655
  if (i === 0 && props.comma)
7656
7656
  onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
7657
7657
  else if (i < fc.items.length - 1)
@@ -7705,8 +7705,8 @@ var require_resolve_flow_collection = __commonJS({
7705
7705
  }
7706
7706
  }
7707
7707
  }
7708
- if (!isMap && !sep && !props.found) {
7709
- const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep, null, props, onError);
7708
+ if (!isMap && !sep2 && !props.found) {
7709
+ const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep2, null, props, onError);
7710
7710
  coll.items.push(valueNode);
7711
7711
  offset = valueNode.range[2];
7712
7712
  if (isBlock(value))
@@ -7718,7 +7718,7 @@ var require_resolve_flow_collection = __commonJS({
7718
7718
  if (isBlock(key))
7719
7719
  onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
7720
7720
  ctx.atKey = false;
7721
- const valueProps = resolveProps.resolveProps(sep ?? [], {
7721
+ const valueProps = resolveProps.resolveProps(sep2 ?? [], {
7722
7722
  flow: fcName,
7723
7723
  indicator: "map-value-ind",
7724
7724
  next: value,
@@ -7729,8 +7729,8 @@ var require_resolve_flow_collection = __commonJS({
7729
7729
  });
7730
7730
  if (valueProps.found) {
7731
7731
  if (!isMap && !props.found && ctx.options.strict) {
7732
- if (sep)
7733
- for (const st of sep) {
7732
+ if (sep2)
7733
+ for (const st of sep2) {
7734
7734
  if (st === valueProps.found)
7735
7735
  break;
7736
7736
  if (st.type === "newline") {
@@ -7747,7 +7747,7 @@ var require_resolve_flow_collection = __commonJS({
7747
7747
  else
7748
7748
  onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
7749
7749
  }
7750
- const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep, null, valueProps, onError) : null;
7750
+ const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep2, null, valueProps, onError) : null;
7751
7751
  if (valueNode) {
7752
7752
  if (isBlock(value))
7753
7753
  onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
@@ -7927,7 +7927,7 @@ var require_resolve_block_scalar = __commonJS({
7927
7927
  chompStart = i + 1;
7928
7928
  }
7929
7929
  let value = "";
7930
- let sep = "";
7930
+ let sep2 = "";
7931
7931
  let prevMoreIndented = false;
7932
7932
  for (let i = 0; i < contentStart; ++i)
7933
7933
  value += lines[i][0].slice(trimIndent) + "\n";
@@ -7944,24 +7944,24 @@ var require_resolve_block_scalar = __commonJS({
7944
7944
  indent = "";
7945
7945
  }
7946
7946
  if (type === Scalar.Scalar.BLOCK_LITERAL) {
7947
- value += sep + indent.slice(trimIndent) + content;
7948
- sep = "\n";
7947
+ value += sep2 + indent.slice(trimIndent) + content;
7948
+ sep2 = "\n";
7949
7949
  } else if (indent.length > trimIndent || content[0] === " ") {
7950
- if (sep === " ")
7951
- sep = "\n";
7952
- else if (!prevMoreIndented && sep === "\n")
7953
- sep = "\n\n";
7954
- value += sep + indent.slice(trimIndent) + content;
7955
- sep = "\n";
7950
+ if (sep2 === " ")
7951
+ sep2 = "\n";
7952
+ else if (!prevMoreIndented && sep2 === "\n")
7953
+ sep2 = "\n\n";
7954
+ value += sep2 + indent.slice(trimIndent) + content;
7955
+ sep2 = "\n";
7956
7956
  prevMoreIndented = true;
7957
7957
  } else if (content === "") {
7958
- if (sep === "\n")
7958
+ if (sep2 === "\n")
7959
7959
  value += "\n";
7960
7960
  else
7961
- sep = "\n";
7961
+ sep2 = "\n";
7962
7962
  } else {
7963
- value += sep + content;
7964
- sep = " ";
7963
+ value += sep2 + content;
7964
+ sep2 = " ";
7965
7965
  prevMoreIndented = false;
7966
7966
  }
7967
7967
  }
@@ -8144,25 +8144,25 @@ var require_resolve_flow_scalar = __commonJS({
8144
8144
  trimBoth = /^[ \t]+|[ \t]+$/g;
8145
8145
  }
8146
8146
  let res = match[1].replace(trimEnd, "");
8147
- let sep = " ";
8147
+ let sep2 = " ";
8148
8148
  let pos = line.lastIndex;
8149
8149
  while (match = line.exec(source)) {
8150
8150
  const lm = match[1].replace(trimBoth, "");
8151
8151
  if (lm === "") {
8152
- if (sep === "\n")
8153
- res += sep;
8152
+ if (sep2 === "\n")
8153
+ res += sep2;
8154
8154
  else
8155
- sep = "\n";
8155
+ sep2 = "\n";
8156
8156
  } else {
8157
- res += sep + lm;
8158
- sep = " ";
8157
+ res += sep2 + lm;
8158
+ sep2 = " ";
8159
8159
  }
8160
8160
  pos = line.lastIndex;
8161
8161
  }
8162
8162
  const last = /[ \t]*(.*)/sy;
8163
8163
  last.lastIndex = pos;
8164
8164
  match = last.exec(source);
8165
- return res + sep + (match?.[1] ?? "");
8165
+ return res + sep2 + (match?.[1] ?? "");
8166
8166
  }
8167
8167
  function doubleQuotedValue(source, onError) {
8168
8168
  let res = "";
@@ -8972,14 +8972,14 @@ var require_cst_stringify = __commonJS({
8972
8972
  }
8973
8973
  }
8974
8974
  }
8975
- function stringifyItem({ start, key, sep, value }) {
8975
+ function stringifyItem({ start, key, sep: sep2, value }) {
8976
8976
  let res = "";
8977
8977
  for (const st of start)
8978
8978
  res += st.source;
8979
8979
  if (key)
8980
8980
  res += stringifyToken(key);
8981
- if (sep)
8982
- for (const st of sep)
8981
+ if (sep2)
8982
+ for (const st of sep2)
8983
8983
  res += st.source;
8984
8984
  if (value)
8985
8985
  res += stringifyToken(value);
@@ -10146,18 +10146,18 @@ var require_parser = __commonJS({
10146
10146
  if (this.type === "map-value-ind") {
10147
10147
  const prev = getPrevProps(this.peek(2));
10148
10148
  const start = getFirstKeyStartProps(prev);
10149
- let sep;
10149
+ let sep2;
10150
10150
  if (scalar.end) {
10151
- sep = scalar.end;
10152
- sep.push(this.sourceToken);
10151
+ sep2 = scalar.end;
10152
+ sep2.push(this.sourceToken);
10153
10153
  delete scalar.end;
10154
10154
  } else
10155
- sep = [this.sourceToken];
10155
+ sep2 = [this.sourceToken];
10156
10156
  const map = {
10157
10157
  type: "block-map",
10158
10158
  offset: scalar.offset,
10159
10159
  indent: scalar.indent,
10160
- items: [{ start, key: scalar, sep }]
10160
+ items: [{ start, key: scalar, sep: sep2 }]
10161
10161
  };
10162
10162
  this.onKeyLine = true;
10163
10163
  this.stack[this.stack.length - 1] = map;
@@ -10310,15 +10310,15 @@ var require_parser = __commonJS({
10310
10310
  } else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
10311
10311
  const start2 = getFirstKeyStartProps(it.start);
10312
10312
  const key = it.key;
10313
- const sep = it.sep;
10314
- sep.push(this.sourceToken);
10313
+ const sep2 = it.sep;
10314
+ sep2.push(this.sourceToken);
10315
10315
  delete it.key;
10316
10316
  delete it.sep;
10317
10317
  this.stack.push({
10318
10318
  type: "block-map",
10319
10319
  offset: this.offset,
10320
10320
  indent: this.indent,
10321
- items: [{ start: start2, key, sep }]
10321
+ items: [{ start: start2, key, sep: sep2 }]
10322
10322
  });
10323
10323
  } else if (start.length > 0) {
10324
10324
  it.sep = it.sep.concat(start, this.sourceToken);
@@ -10512,13 +10512,13 @@ var require_parser = __commonJS({
10512
10512
  const prev = getPrevProps(parent);
10513
10513
  const start = getFirstKeyStartProps(prev);
10514
10514
  fixFlowSeqItems(fc);
10515
- const sep = fc.end.splice(1, fc.end.length);
10516
- sep.push(this.sourceToken);
10515
+ const sep2 = fc.end.splice(1, fc.end.length);
10516
+ sep2.push(this.sourceToken);
10517
10517
  const map = {
10518
10518
  type: "block-map",
10519
10519
  offset: fc.offset,
10520
10520
  indent: fc.indent,
10521
- items: [{ start, key: fc, sep }]
10521
+ items: [{ start, key: fc, sep: sep2 }]
10522
10522
  };
10523
10523
  this.onKeyLine = true;
10524
10524
  this.stack[this.stack.length - 1] = map;
@@ -10796,6 +10796,9 @@ var require_dist = __commonJS({
10796
10796
  }
10797
10797
  });
10798
10798
 
10799
+ // src/index.ts
10800
+ import { spawn as spawn2 } from "node:child_process";
10801
+
10799
10802
  // node_modules/.pnpm/commander@14.0.3/node_modules/commander/esm.mjs
10800
10803
  var import_index = __toESM(require_commander(), 1);
10801
10804
  var {
@@ -14464,92 +14467,221 @@ function readBuzSuite(text) {
14464
14467
  }
14465
14468
 
14466
14469
  // src/skills.ts
14470
+ import { createHash as createHash2 } from "node:crypto";
14467
14471
  import {
14468
- readFile as readFile2,
14469
- mkdir as mkdir2,
14470
- copyFile,
14471
14472
  lstat,
14472
- realpath
14473
+ mkdir as mkdir2,
14474
+ mkdtemp,
14475
+ readdir,
14476
+ readFile as readFile2,
14477
+ readlink,
14478
+ realpath,
14479
+ rename as rename2,
14480
+ rm,
14481
+ symlink,
14482
+ writeFile as writeFile2
14473
14483
  } from "node:fs/promises";
14474
- import { fileURLToPath } from "node:url";
14475
14484
  import { homedir as homedir2 } from "node:os";
14476
- import { join as join2, relative, isAbsolute, resolve } from "node:path";
14477
- import { createHash as createHash2 } from "node:crypto";
14478
- var skillDirectory = fileURLToPath(
14479
- new URL("../skills/modellab/", import.meta.url)
14480
- );
14481
- async function installSkill(target, version, destination) {
14482
- const manifest = JSON.parse(
14483
- await readFile2(join2(skillDirectory, "manifest.json"), "utf8")
14485
+ import { basename, dirname, join as join2, relative, resolve, sep } from "node:path";
14486
+ import { fileURLToPath } from "node:url";
14487
+ var bundledDirectory = fileURLToPath(new URL("../skills/", import.meta.url));
14488
+ async function installBundledSkills(destination = defaultDirectory()) {
14489
+ const entries = await readdir(bundledDirectory, { withFileTypes: true });
14490
+ const skills = await Promise.all(
14491
+ entries.filter((entry) => entry.isDirectory()).map((entry) => readSkill(join2(bundledDirectory, entry.name)))
14484
14492
  );
14485
- if (version !== manifest.version)
14486
- throw new Error(
14487
- `\u6B64 CLI \u5185\u9644 Skill ${manifest.version}\uFF0C\u8BF7\u4F7F\u7528\u5339\u914D\u7684 Skill \u7248\u672C`
14488
- );
14489
- const homes = {
14490
- codex: join2(homedir2(), ".codex", "skills"),
14491
- claude: join2(homedir2(), ".claude", "skills")
14493
+ if (skills.length === 0) throw new Error("CLI \u5185\u6CA1\u6709\u53EF\u5B89\u88C5\u7684\u64CD\u4F5C Skill");
14494
+ return installSkills(skills, destination);
14495
+ }
14496
+ async function installSkill(target, version, destination) {
14497
+ if (!destination && !["agents", "codex", "claude"].includes(target))
14498
+ throw new Error("\u652F\u6301 agents\u3001codex\u3001claude\uFF1B\u4E5F\u53EF\u7528 --directory \u6307\u5B9A\u76EE\u5F55");
14499
+ const skill = await readSkill(join2(bundledDirectory, "modellab"));
14500
+ if (version !== void 0 && version !== skill.version)
14501
+ throw new Error(`\u6B64 CLI \u5185\u9644 Skill ${skill.version}\uFF0C\u8BF7\u4F7F\u7528\u5339\u914D\u7684 Skill \u7248\u672C`);
14502
+ const result = await installSkills([skill], destination ?? defaultDirectory());
14503
+ return result.installed[0];
14504
+ }
14505
+ function defaultDirectory() {
14506
+ return join2(homedir2(), ".agents", "skills");
14507
+ }
14508
+ async function readSkill(directory2) {
14509
+ const manifestPath = join2(directory2, "manifest.json");
14510
+ if (!(await lstat(manifestPath)).isFile())
14511
+ throw new Error(`Skill \u6E05\u5355\u5FC5\u987B\u662F\u666E\u901A\u6587\u4EF6\uFF1A${manifestPath}`);
14512
+ const manifestFile = await readFile2(manifestPath);
14513
+ const { name, version, packageType, files: digests } = JSON.parse(manifestFile.toString());
14514
+ if (typeof name !== "string" || !/^[a-z0-9][a-z0-9-]*$/.test(name) || typeof version !== "string" || packageType !== "operation-skill-package" || typeof digests !== "object" || !digests || !Object.hasOwn(digests, "SKILL.md") || Object.hasOwn(digests, "manifest.json"))
14515
+ throw new Error(`Skill \u6E05\u5355\u65E0\u6548\uFF1A${manifestPath}`);
14516
+ const files = /* @__PURE__ */ new Map([["manifest.json", manifestFile]]);
14517
+ const expectedFiles = Object.keys(digests);
14518
+ const entries = await readdir(directory2, { recursive: true, withFileTypes: true });
14519
+ for (const entry of entries) {
14520
+ const file = join2(entry.parentPath, entry.name);
14521
+ const key = relative(directory2, file).split(sep).join("/");
14522
+ if (entry.isDirectory() && expectedFiles.some((name2) => name2.startsWith(key + "/")))
14523
+ continue;
14524
+ if (entry.isDirectory()) throw new Error(`Skill \u5305\u542B\u6E05\u5355\u5916\u7684\u76EE\u5F55\uFF1A${file}`);
14525
+ if (!entry.isFile()) throw new Error(`Skill \u5305\u542B\u7B26\u53F7\u94FE\u63A5\u6216\u7279\u6B8A\u6587\u4EF6\uFF1A${file}`);
14526
+ if (key === "manifest.json") continue;
14527
+ if (!Object.hasOwn(digests, key)) throw new Error(`Skill \u5305\u542B\u6E05\u5355\u5916\u7684\u6587\u4EF6\uFF1A${file}`);
14528
+ const data = await readFile2(file);
14529
+ if (createHash2("sha256").update(data).digest("hex") !== digests[key])
14530
+ throw new Error(`Skill \u5185\u5BB9\u54C8\u5E0C\u6821\u9A8C\u5931\u8D25\uFF1A${file}`);
14531
+ files.set(key, data);
14532
+ }
14533
+ if (files.size !== expectedFiles.length + 1)
14534
+ throw new Error(`Skill \u7F3A\u5C11\u6E05\u5355\u58F0\u660E\u7684\u6587\u4EF6\uFF1A${directory2}`);
14535
+ return { name, version, files };
14536
+ }
14537
+ async function installSkills(skills, destination) {
14538
+ if (new Set(skills.map(({ name }) => name)).size !== skills.length)
14539
+ throw new Error("CLI \u5185\u9644\u64CD\u4F5C Skill \u540D\u79F0\u91CD\u590D");
14540
+ const target = resolve(destination);
14541
+ const parent = dirname(target);
14542
+ const claudeTarget = basename(target) === "skills" && basename(parent) === ".agents" ? join2(dirname(parent), ".claude", "skills") : void 0;
14543
+ await mkdir2(target, { recursive: true });
14544
+ const targetRoot = await realpath(target);
14545
+ let claudeRoot;
14546
+ if (claudeTarget) {
14547
+ await mkdir2(claudeTarget, { recursive: true });
14548
+ claudeRoot = await realpath(claudeTarget);
14549
+ }
14550
+ const plans = [];
14551
+ for (const skill of skills) {
14552
+ const path = join2(targetRoot, skill.name);
14553
+ const destinationEntry = await existingEntry(path);
14554
+ const installed = destinationEntry && await readInstalledSkill(path, destinationEntry, skill);
14555
+ const claudePath = claudeRoot && claudeRoot !== targetRoot ? join2(claudeRoot, skill.name) : void 0;
14556
+ const claudeEntry = claudePath && await existingEntry(claudePath);
14557
+ let linked = false;
14558
+ if (claudePath && claudeEntry) {
14559
+ if (claudeEntry.isSymbolicLink()) {
14560
+ const linkTarget = resolve(dirname(claudePath), await readlink(claudePath));
14561
+ linked = linkTarget === path || await realpath(claudePath).catch(() => void 0) === path;
14562
+ if (!linked) throw new Error(`Claude Skill \u94FE\u63A5\u5DF2\u6307\u5411\u5176\u4ED6\u4F4D\u7F6E\uFF1A${claudePath}`);
14563
+ } else {
14564
+ await readInstalledSkill(claudePath, claudeEntry, skill);
14565
+ }
14566
+ }
14567
+ plans.push({ skill, path, installed, claudePath, claudeEntry, linked });
14568
+ }
14569
+ for (const { skill, path, installed, claudePath, claudeEntry, linked } of plans) {
14570
+ if (installed?.version !== skill.version)
14571
+ await replaceEntry(path, Boolean(installed), async (stage) => {
14572
+ await mkdir2(stage);
14573
+ for (const [name, contents] of skill.files) {
14574
+ const file = join2(stage, name);
14575
+ await mkdir2(dirname(file), { recursive: true });
14576
+ await writeFile2(file, contents);
14577
+ }
14578
+ });
14579
+ if (claudePath && !linked) {
14580
+ const windows = process.platform === "win32";
14581
+ const link = (entry) => symlink(
14582
+ windows ? path : relative(dirname(claudePath), path),
14583
+ entry,
14584
+ windows ? "junction" : "dir"
14585
+ );
14586
+ if (claudeEntry) await replaceEntry(claudePath, true, link);
14587
+ else await link(claudePath);
14588
+ }
14589
+ }
14590
+ return {
14591
+ target,
14592
+ ...claudeTarget ? { claudeTarget } : {},
14593
+ installed: plans.map(({ path, skill }) => ({ path, version: skill.version }))
14492
14594
  };
14493
- const root = destination ?? homes[target];
14494
- if (!root)
14495
- throw new Error(
14496
- "\u652F\u6301 codex\u3001claude\uFF1B\u5176\u4ED6\u5DE5\u5177\u8BF7\u7528 --directory \u6307\u5B9A Skill \u76EE\u5F55"
14497
- );
14498
- await mkdir2(root, { recursive: true });
14499
- const resolvedRoot = await realpath(root), installPath = join2(resolvedRoot, "modellab-operations");
14595
+ }
14596
+ async function existingEntry(path) {
14500
14597
  try {
14501
- const info = await lstat(installPath);
14502
- if (info.isSymbolicLink()) throw new Error("\u62D2\u7EDD\u5199\u5165\u7B26\u53F7\u94FE\u63A5 Skill \u76EE\u5F55");
14503
- } catch (e) {
14504
- if (e.code !== "ENOENT") throw e;
14505
- }
14506
- const changes = [];
14507
- for (const [name, digest] of Object.entries(manifest.files)) {
14508
- const output = resolve(installPath, name);
14509
- if (isAbsolute(name) || relative(installPath, output).startsWith(".."))
14510
- throw new Error("Skill \u5305\u5305\u542B\u975E\u6CD5\u8DEF\u5F84");
14511
- const source = join2(skillDirectory, name);
14512
- if (!(await lstat(source)).isFile())
14513
- throw new Error("Skill \u5305\u4E0D\u5141\u8BB8\u7B26\u53F7\u94FE\u63A5");
14514
- const data = await readFile2(source);
14515
- if (createHash2("sha256").update(data).digest("hex") !== digest)
14516
- throw new Error("Skill \u5185\u5BB9\u54C8\u5E0C\u6821\u9A8C\u5931\u8D25");
14517
- try {
14518
- if ((await lstat(output)).isSymbolicLink())
14519
- throw new Error("\u62D2\u7EDD\u5199\u5165\u7B26\u53F7\u94FE\u63A5 Skill \u6587\u4EF6");
14520
- const local = await readFile2(output);
14521
- if (!local.equals(data)) changes.push(name);
14522
- } catch (e) {
14523
- if (e.code !== "ENOENT") throw e;
14524
- }
14598
+ return await lstat(path);
14599
+ } catch (error) {
14600
+ if (error.code !== "ENOENT") throw error;
14601
+ return void 0;
14525
14602
  }
14526
- if (changes.length) {
14527
- const error = new Error(
14528
- "\u68C0\u6D4B\u5230\u5DF2\u6709 Skill \u5185\u5BB9\u53D8\u5316\uFF0C\u5DF2\u4FDD\u7559\u672C\u5730\u6587\u4EF6\u3002\u8BF7\u4F7F\u7528\u65B0\u76EE\u5F55\u5B89\u88C5\u540E\u6BD4\u8F83\u3002"
14529
- );
14530
- error.details = { files: changes };
14531
- throw error;
14532
- }
14533
- for (const name of [...Object.keys(manifest.files), "manifest.json"]) {
14534
- const output = join2(installPath, name);
14535
- await mkdir2(resolve(output, ".."), { recursive: true });
14536
- const parent = await realpath(resolve(output, ".."));
14537
- if (relative(installPath, parent).startsWith(".."))
14538
- throw new Error("Skill \u76EE\u6807\u8DEF\u5F84\u8D8A\u754C");
14603
+ }
14604
+ async function readInstalledSkill(path, entry, incoming) {
14605
+ if (entry.isSymbolicLink()) throw new Error(`\u62D2\u7EDD\u5199\u5165\u7B26\u53F7\u94FE\u63A5 Skill \u76EE\u5F55\uFF1A${path}`);
14606
+ try {
14607
+ const installed = await readSkill(path);
14608
+ if (installed.name !== incoming.name || installed.version === incoming.version && (installed.files.size !== incoming.files.size || [...installed.files].some(([name, contents]) => !incoming.files.get(name)?.equals(contents))))
14609
+ throw new Error("Skill \u6E05\u5355\u4E0E\u540C\u7248\u672C\u5B89\u88C5\u5305\u4E0D\u4E00\u81F4");
14610
+ return installed;
14611
+ } catch (error) {
14612
+ throw new Error(`\u68C0\u6D4B\u5230\u5DF2\u6709 Skill \u5185\u5BB9\u53D8\u5316\uFF0C\u5DF2\u4FDD\u7559\u672C\u5730\u6587\u4EF6\u3002\u8BF7\u4F7F\u7528\u65B0\u76EE\u5F55\u5B89\u88C5\u540E\u6BD4\u8F83\uFF1A${path}`, {
14613
+ cause: error
14614
+ });
14615
+ }
14616
+ }
14617
+ async function replaceEntry(path, exists, stageEntry) {
14618
+ const scratch = await mkdtemp(join2(dirname(path), ".modellab-install-"));
14619
+ const staged = join2(scratch, "new");
14620
+ const previous = join2(scratch, "previous");
14621
+ let keepBackup = false;
14622
+ try {
14623
+ await stageEntry(staged);
14624
+ if (exists) await rename2(path, previous);
14539
14625
  try {
14540
- if ((await lstat(output)).isSymbolicLink())
14541
- throw new Error("\u62D2\u7EDD\u5199\u5165\u7B26\u53F7\u94FE\u63A5 Skill \u6587\u4EF6");
14542
- } catch (e) {
14543
- if (e.code !== "ENOENT") throw e;
14626
+ await rename2(staged, path);
14627
+ } catch (error) {
14628
+ if (exists) {
14629
+ keepBackup = true;
14630
+ await rename2(previous, path);
14631
+ keepBackup = false;
14632
+ }
14633
+ throw error;
14544
14634
  }
14545
- await copyFile(join2(skillDirectory, name), output);
14635
+ } finally {
14636
+ if (!keepBackup) await rm(scratch, { recursive: true, force: true });
14546
14637
  }
14547
- return { path: installPath, version: manifest.version };
14548
14638
  }
14549
14639
 
14640
+ // package.json
14641
+ var package_default = {
14642
+ private: false,
14643
+ version: "0.1.1",
14644
+ type: "module",
14645
+ engines: {
14646
+ node: ">=24 <25"
14647
+ },
14648
+ packageManager: "pnpm@10.30.3",
14649
+ name: "modellab-cli",
14650
+ description: "ModelLab API command line client",
14651
+ bin: {
14652
+ modellab: "dist/index.js"
14653
+ },
14654
+ files: [
14655
+ "dist",
14656
+ "skills"
14657
+ ],
14658
+ scripts: {
14659
+ dev: "node --import tsx src/index.ts",
14660
+ build: "tsc --noEmit && node release/build.mjs",
14661
+ check: "tsc --noEmit",
14662
+ test: "vitest run",
14663
+ prepack: "pnpm build",
14664
+ "skill:pack": "node release/pack-skill.mjs"
14665
+ },
14666
+ devDependencies: {
14667
+ "@types/node": "^24.10.0",
14668
+ "@types/semver": "^7.7.1",
14669
+ typescript: "^5.9.3",
14670
+ tsx: "^4.20.6",
14671
+ vitest: "^3.2.4",
14672
+ "@modellab/contracts": "file:vendor/contracts.tgz",
14673
+ "@modellab/sdk": "file:vendor/sdk.tgz",
14674
+ commander: "^14.0.2",
14675
+ yaml: "^2.8.1",
14676
+ semver: "^7.7.3",
14677
+ esbuild: "0.28.2"
14678
+ }
14679
+ };
14680
+
14550
14681
  // src/index.ts
14682
+ var { name: packageName, version: cliVersion } = package_default;
14551
14683
  var program2 = new Command();
14552
- program2.name("modellab").version("0.1.0").description("ModelLab \u9879\u76EE\u3001\u914D\u7F6E\u3001\u6D4B\u8BD5\u4E0E\u7ED3\u679C\u5BA2\u6237\u7AEF").option("--profile <name>", "\u670D\u52A1\u914D\u7F6E").option("--project <id>", "\u9879\u76EE ID").option("--json", "\u7ED3\u6784\u5316 JSON \u8F93\u51FA").option("--no-input", "\u7981\u7528\u4EA4\u4E92").option(
14684
+ program2.name("modellab").version(cliVersion).description("ModelLab \u9879\u76EE\u3001\u914D\u7F6E\u3001\u6D4B\u8BD5\u4E0E\u7ED3\u679C\u5BA2\u6237\u7AEF").option("--profile <name>", "\u670D\u52A1\u914D\u7F6E").option("--project <id>", "\u9879\u76EE ID").option("--json", "\u7ED3\u6784\u5316 JSON \u8F93\u51FA").option("--no-input", "\u7981\u7528\u4EA4\u4E92").option(
14553
14685
  "--timeout <seconds>",
14554
14686
  "\u7B49\u5F85\u8D85\u65F6\u79D2\u6570",
14555
14687
  (value) => {
@@ -15035,7 +15167,28 @@ for (const family of [
15035
15167
  );
15036
15168
  }
15037
15169
  }
15038
- program2.command("integrations").command("skills").command("install").requiredOption("--target <name>").option("--skill-version <version>", "\u72EC\u7ACB Skill \u7248\u672C", "0.1.0").option("--directory <path>", "\u81EA\u5B9A\u4E49\u5B89\u88C5\u7236\u76EE\u5F55").action(
15170
+ program2.command("install").description("\u5168\u5C40\u5B89\u88C5\u5F53\u524D\u7248\u672C CLI \u5E76\u540C\u6B65\u5185\u9644\u7684\u64CD\u4F5C Skill").option("--skip-cli", "\u4EC5\u5B89\u88C5\u64CD\u4F5C Skill").option("--skip-skills", "\u4EC5\u5B89\u88C5 CLI").option("--target <path>", "\u64CD\u4F5C Skill \u5B89\u88C5\u7236\u76EE\u5F55").action(async ({ skipCli, skipSkills, target }) => {
15171
+ if (skipCli && skipSkills) throw new Error("\u8BF7\u81F3\u5C11\u9009\u62E9\u5B89\u88C5 CLI \u6216\u64CD\u4F5C Skill");
15172
+ if (skipSkills && target) throw new Error("--target \u7528\u4E8E\u5B89\u88C5\u64CD\u4F5C Skill");
15173
+ const cli = skipCli ? void 0 : await installCliGlobally();
15174
+ const skills = skipSkills ? void 0 : await installBundledSkills(target);
15175
+ out({ cli, skills });
15176
+ });
15177
+ async function installCliGlobally() {
15178
+ const spec = `${packageName}@${cliVersion}`;
15179
+ const args = ["install", "--global", "--prefer-online", spec];
15180
+ const options = { stdio: ["ignore", "ignore", "inherit"] };
15181
+ const child = process.platform === "win32" ? spawn2("cmd.exe", ["/d", "/s", "/c", ["npm", ...args].join(" ")], options) : spawn2("npm", args, options);
15182
+ await new Promise((resolve2, reject) => {
15183
+ child.once("error", reject);
15184
+ child.once("close", (code, signal) => {
15185
+ if (code === 0) resolve2();
15186
+ else reject(new Error(`npm \u5B89\u88C5 ${spec} \u5931\u8D25\uFF08${signal ?? code}\uFF09`));
15187
+ });
15188
+ });
15189
+ return { name: packageName, version: cliVersion };
15190
+ }
15191
+ program2.command("integrations").command("skills").command("install").option("--target <name>", "\u517C\u5BB9\u5DE5\u5177\u540D\u79F0", "agents").option("--skill-version <version>", "\u72EC\u7ACB Skill \u7248\u672C").option("--directory <path>", "\u81EA\u5B9A\u4E49\u5B89\u88C5\u7236\u76EE\u5F55").action(
15039
15192
  async (o) => out(await installSkill(o.target, o.skillVersion, o.directory))
15040
15193
  );
15041
15194
  async function main() {