@taptap/maker 0.0.11 → 0.0.12

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/dist/maker.js CHANGED
@@ -3233,8 +3233,8 @@ var require_utils = __commonJS({
3233
3233
  }
3234
3234
  return ind;
3235
3235
  }
3236
- function removeDotSegments(path14) {
3237
- let input2 = path14;
3236
+ function removeDotSegments(path15) {
3237
+ let input2 = path15;
3238
3238
  const output2 = [];
3239
3239
  let nextSlash = -1;
3240
3240
  let len = 0;
@@ -3433,8 +3433,8 @@ var require_schemes = __commonJS({
3433
3433
  wsComponent.secure = void 0;
3434
3434
  }
3435
3435
  if (wsComponent.resourceName) {
3436
- const [path14, query] = wsComponent.resourceName.split("?");
3437
- wsComponent.path = path14 && path14 !== "/" ? path14 : void 0;
3436
+ const [path15, query] = wsComponent.resourceName.split("?");
3437
+ wsComponent.path = path15 && path15 !== "/" ? path15 : void 0;
3438
3438
  wsComponent.query = query;
3439
3439
  wsComponent.resourceName = void 0;
3440
3440
  }
@@ -12491,12 +12491,12 @@ var require_dist = __commonJS({
12491
12491
  throw new Error(`Unknown format "${name}"`);
12492
12492
  return f;
12493
12493
  };
12494
- function addFormats(ajv, list, fs12, exportName) {
12494
+ function addFormats(ajv, list, fs13, exportName) {
12495
12495
  var _a3;
12496
12496
  var _b;
12497
12497
  (_a3 = (_b = ajv.opts.code).formats) !== null && _a3 !== void 0 ? _a3 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
12498
12498
  for (const f of list)
12499
- ajv.addFormat(f, fs12[f]);
12499
+ ajv.addFormat(f, fs13[f]);
12500
12500
  }
12501
12501
  module.exports = exports = formatsPlugin;
12502
12502
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -12509,8 +12509,8 @@ var require_windows = __commonJS({
12509
12509
  "node_modules/isexe/windows.js"(exports, module) {
12510
12510
  module.exports = isexe;
12511
12511
  isexe.sync = sync;
12512
- var fs12 = __require("fs");
12513
- function checkPathExt(path14, options) {
12512
+ var fs13 = __require("fs");
12513
+ function checkPathExt(path15, options) {
12514
12514
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
12515
12515
  if (!pathext) {
12516
12516
  return true;
@@ -12521,25 +12521,25 @@ var require_windows = __commonJS({
12521
12521
  }
12522
12522
  for (var i = 0; i < pathext.length; i++) {
12523
12523
  var p = pathext[i].toLowerCase();
12524
- if (p && path14.substr(-p.length).toLowerCase() === p) {
12524
+ if (p && path15.substr(-p.length).toLowerCase() === p) {
12525
12525
  return true;
12526
12526
  }
12527
12527
  }
12528
12528
  return false;
12529
12529
  }
12530
- function checkStat(stat, path14, options) {
12530
+ function checkStat(stat, path15, options) {
12531
12531
  if (!stat.isSymbolicLink() && !stat.isFile()) {
12532
12532
  return false;
12533
12533
  }
12534
- return checkPathExt(path14, options);
12534
+ return checkPathExt(path15, options);
12535
12535
  }
12536
- function isexe(path14, options, cb) {
12537
- fs12.stat(path14, function(er, stat) {
12538
- cb(er, er ? false : checkStat(stat, path14, options));
12536
+ function isexe(path15, options, cb) {
12537
+ fs13.stat(path15, function(er, stat) {
12538
+ cb(er, er ? false : checkStat(stat, path15, options));
12539
12539
  });
12540
12540
  }
12541
- function sync(path14, options) {
12542
- return checkStat(fs12.statSync(path14), path14, options);
12541
+ function sync(path15, options) {
12542
+ return checkStat(fs13.statSync(path15), path15, options);
12543
12543
  }
12544
12544
  }
12545
12545
  });
@@ -12549,14 +12549,14 @@ var require_mode = __commonJS({
12549
12549
  "node_modules/isexe/mode.js"(exports, module) {
12550
12550
  module.exports = isexe;
12551
12551
  isexe.sync = sync;
12552
- var fs12 = __require("fs");
12553
- function isexe(path14, options, cb) {
12554
- fs12.stat(path14, function(er, stat) {
12552
+ var fs13 = __require("fs");
12553
+ function isexe(path15, options, cb) {
12554
+ fs13.stat(path15, function(er, stat) {
12555
12555
  cb(er, er ? false : checkStat(stat, options));
12556
12556
  });
12557
12557
  }
12558
- function sync(path14, options) {
12559
- return checkStat(fs12.statSync(path14), options);
12558
+ function sync(path15, options) {
12559
+ return checkStat(fs13.statSync(path15), options);
12560
12560
  }
12561
12561
  function checkStat(stat, options) {
12562
12562
  return stat.isFile() && checkMode(stat, options);
@@ -12580,7 +12580,7 @@ var require_mode = __commonJS({
12580
12580
  // node_modules/isexe/index.js
12581
12581
  var require_isexe = __commonJS({
12582
12582
  "node_modules/isexe/index.js"(exports, module) {
12583
- var fs12 = __require("fs");
12583
+ var fs13 = __require("fs");
12584
12584
  var core;
12585
12585
  if (process.platform === "win32" || global.TESTING_WINDOWS) {
12586
12586
  core = require_windows();
@@ -12589,7 +12589,7 @@ var require_isexe = __commonJS({
12589
12589
  }
12590
12590
  module.exports = isexe;
12591
12591
  isexe.sync = sync;
12592
- function isexe(path14, options, cb) {
12592
+ function isexe(path15, options, cb) {
12593
12593
  if (typeof options === "function") {
12594
12594
  cb = options;
12595
12595
  options = {};
@@ -12599,7 +12599,7 @@ var require_isexe = __commonJS({
12599
12599
  throw new TypeError("callback not provided");
12600
12600
  }
12601
12601
  return new Promise(function(resolve, reject) {
12602
- isexe(path14, options || {}, function(er, is) {
12602
+ isexe(path15, options || {}, function(er, is) {
12603
12603
  if (er) {
12604
12604
  reject(er);
12605
12605
  } else {
@@ -12608,7 +12608,7 @@ var require_isexe = __commonJS({
12608
12608
  });
12609
12609
  });
12610
12610
  }
12611
- core(path14, options || {}, function(er, is) {
12611
+ core(path15, options || {}, function(er, is) {
12612
12612
  if (er) {
12613
12613
  if (er.code === "EACCES" || options && options.ignoreErrors) {
12614
12614
  er = null;
@@ -12618,9 +12618,9 @@ var require_isexe = __commonJS({
12618
12618
  cb(er, is);
12619
12619
  });
12620
12620
  }
12621
- function sync(path14, options) {
12621
+ function sync(path15, options) {
12622
12622
  try {
12623
- return core.sync(path14, options || {});
12623
+ return core.sync(path15, options || {});
12624
12624
  } catch (er) {
12625
12625
  if (options && options.ignoreErrors || er.code === "EACCES") {
12626
12626
  return false;
@@ -12636,7 +12636,7 @@ var require_isexe = __commonJS({
12636
12636
  var require_which = __commonJS({
12637
12637
  "node_modules/which/which.js"(exports, module) {
12638
12638
  var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
12639
- var path14 = __require("path");
12639
+ var path15 = __require("path");
12640
12640
  var COLON = isWindows ? ";" : ":";
12641
12641
  var isexe = require_isexe();
12642
12642
  var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
@@ -12674,7 +12674,7 @@ var require_which = __commonJS({
12674
12674
  return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
12675
12675
  const ppRaw = pathEnv[i];
12676
12676
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
12677
- const pCmd = path14.join(pathPart, cmd);
12677
+ const pCmd = path15.join(pathPart, cmd);
12678
12678
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
12679
12679
  resolve(subStep(p, i, 0));
12680
12680
  });
@@ -12701,7 +12701,7 @@ var require_which = __commonJS({
12701
12701
  for (let i = 0; i < pathEnv.length; i++) {
12702
12702
  const ppRaw = pathEnv[i];
12703
12703
  const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
12704
- const pCmd = path14.join(pathPart, cmd);
12704
+ const pCmd = path15.join(pathPart, cmd);
12705
12705
  const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
12706
12706
  for (let j = 0; j < pathExt.length; j++) {
12707
12707
  const cur = p + pathExt[j];
@@ -12749,7 +12749,7 @@ var require_path_key = __commonJS({
12749
12749
  var require_resolveCommand = __commonJS({
12750
12750
  "node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
12751
12751
  "use strict";
12752
- var path14 = __require("path");
12752
+ var path15 = __require("path");
12753
12753
  var which = require_which();
12754
12754
  var getPathKey = require_path_key();
12755
12755
  function resolveCommandAttempt(parsed, withoutPathExt) {
@@ -12767,7 +12767,7 @@ var require_resolveCommand = __commonJS({
12767
12767
  try {
12768
12768
  resolved = which.sync(parsed.command, {
12769
12769
  path: env[getPathKey({ env })],
12770
- pathExt: withoutPathExt ? path14.delimiter : void 0
12770
+ pathExt: withoutPathExt ? path15.delimiter : void 0
12771
12771
  });
12772
12772
  } catch (e) {
12773
12773
  } finally {
@@ -12776,7 +12776,7 @@ var require_resolveCommand = __commonJS({
12776
12776
  }
12777
12777
  }
12778
12778
  if (resolved) {
12779
- resolved = path14.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
12779
+ resolved = path15.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
12780
12780
  }
12781
12781
  return resolved;
12782
12782
  }
@@ -12830,8 +12830,8 @@ var require_shebang_command = __commonJS({
12830
12830
  if (!match) {
12831
12831
  return null;
12832
12832
  }
12833
- const [path14, argument] = match[0].replace(/#! ?/, "").split(" ");
12834
- const binary = path14.split("/").pop();
12833
+ const [path15, argument] = match[0].replace(/#! ?/, "").split(" ");
12834
+ const binary = path15.split("/").pop();
12835
12835
  if (binary === "env") {
12836
12836
  return argument;
12837
12837
  }
@@ -12844,16 +12844,16 @@ var require_shebang_command = __commonJS({
12844
12844
  var require_readShebang = __commonJS({
12845
12845
  "node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
12846
12846
  "use strict";
12847
- var fs12 = __require("fs");
12847
+ var fs13 = __require("fs");
12848
12848
  var shebangCommand = require_shebang_command();
12849
12849
  function readShebang(command) {
12850
12850
  const size = 150;
12851
12851
  const buffer = Buffer.alloc(size);
12852
12852
  let fd;
12853
12853
  try {
12854
- fd = fs12.openSync(command, "r");
12855
- fs12.readSync(fd, buffer, 0, size, 0);
12856
- fs12.closeSync(fd);
12854
+ fd = fs13.openSync(command, "r");
12855
+ fs13.readSync(fd, buffer, 0, size, 0);
12856
+ fs13.closeSync(fd);
12857
12857
  } catch (e) {
12858
12858
  }
12859
12859
  return shebangCommand(buffer.toString());
@@ -12866,7 +12866,7 @@ var require_readShebang = __commonJS({
12866
12866
  var require_parse = __commonJS({
12867
12867
  "node_modules/cross-spawn/lib/parse.js"(exports, module) {
12868
12868
  "use strict";
12869
- var path14 = __require("path");
12869
+ var path15 = __require("path");
12870
12870
  var resolveCommand = require_resolveCommand();
12871
12871
  var escape2 = require_escape();
12872
12872
  var readShebang = require_readShebang();
@@ -12891,7 +12891,7 @@ var require_parse = __commonJS({
12891
12891
  const needsShell = !isExecutableRegExp.test(commandFile);
12892
12892
  if (parsed.options.forceShell || needsShell) {
12893
12893
  const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
12894
- parsed.command = path14.normalize(parsed.command);
12894
+ parsed.command = path15.normalize(parsed.command);
12895
12895
  parsed.command = escape2.command(parsed.command);
12896
12896
  parsed.args = parsed.args.map((arg) => escape2.argument(arg, needsDoubleEscapeMetaChars));
12897
12897
  const shellCommand = [parsed.command].concat(parsed.args).join(" ");
@@ -12987,7 +12987,7 @@ var require_cross_spawn = __commonJS({
12987
12987
  enoent.hookChildProcess(spawned, parsed);
12988
12988
  return spawned;
12989
12989
  }
12990
- function spawnSync5(command, args, options) {
12990
+ function spawnSync6(command, args, options) {
12991
12991
  const parsed = parse3(command, args, options);
12992
12992
  const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
12993
12993
  result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
@@ -12995,7 +12995,7 @@ var require_cross_spawn = __commonJS({
12995
12995
  }
12996
12996
  module.exports = spawn5;
12997
12997
  module.exports.spawn = spawn5;
12998
- module.exports.sync = spawnSync5;
12998
+ module.exports.sync = spawnSync6;
12999
12999
  module.exports._parse = parse3;
13000
13000
  module.exports._enoent = enoent;
13001
13001
  }
@@ -13003,8 +13003,8 @@ var require_cross_spawn = __commonJS({
13003
13003
 
13004
13004
  // src/maker/server/mcp.ts
13005
13005
  import { execFileSync, spawn as spawn4 } from "node:child_process";
13006
- import fs8 from "node:fs";
13007
- import path9 from "node:path";
13006
+ import fs9 from "node:fs";
13007
+ import path10 from "node:path";
13008
13008
 
13009
13009
  // node_modules/zod/v3/helpers/util.js
13010
13010
  var util;
@@ -13365,8 +13365,8 @@ function getErrorMap() {
13365
13365
 
13366
13366
  // node_modules/zod/v3/helpers/parseUtil.js
13367
13367
  var makeIssue = (params) => {
13368
- const { data, path: path14, errorMaps, issueData } = params;
13369
- const fullPath = [...path14, ...issueData.path || []];
13368
+ const { data, path: path15, errorMaps, issueData } = params;
13369
+ const fullPath = [...path15, ...issueData.path || []];
13370
13370
  const fullIssue = {
13371
13371
  ...issueData,
13372
13372
  path: fullPath
@@ -13481,11 +13481,11 @@ var errorUtil;
13481
13481
 
13482
13482
  // node_modules/zod/v3/types.js
13483
13483
  var ParseInputLazyPath = class {
13484
- constructor(parent, value, path14, key) {
13484
+ constructor(parent, value, path15, key) {
13485
13485
  this._cachedPath = [];
13486
13486
  this.parent = parent;
13487
13487
  this.data = value;
13488
- this._path = path14;
13488
+ this._path = path15;
13489
13489
  this._key = key;
13490
13490
  }
13491
13491
  get path() {
@@ -17134,10 +17134,10 @@ function mergeDefs(...defs) {
17134
17134
  function cloneDef(schema) {
17135
17135
  return mergeDefs(schema._zod.def);
17136
17136
  }
17137
- function getElementAtPath(obj, path14) {
17138
- if (!path14)
17137
+ function getElementAtPath(obj, path15) {
17138
+ if (!path15)
17139
17139
  return obj;
17140
- return path14.reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
17140
+ return path15.reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
17141
17141
  }
17142
17142
  function promiseAllObject(promisesObj) {
17143
17143
  const keys = Object.keys(promisesObj);
@@ -17522,11 +17522,11 @@ function aborted(x, startIndex = 0) {
17522
17522
  }
17523
17523
  return false;
17524
17524
  }
17525
- function prefixIssues(path14, issues) {
17525
+ function prefixIssues(path15, issues) {
17526
17526
  return issues.map((iss) => {
17527
17527
  var _a3;
17528
17528
  (_a3 = iss).path ?? (_a3.path = []);
17529
- iss.path.unshift(path14);
17529
+ iss.path.unshift(path15);
17530
17530
  return iss;
17531
17531
  });
17532
17532
  }
@@ -28048,7 +28048,7 @@ function isElectron() {
28048
28048
 
28049
28049
  // src/maker/server/identify.ts
28050
28050
  import fs2 from "node:fs";
28051
- import path3 from "node:path";
28051
+ import path2 from "node:path";
28052
28052
 
28053
28053
  // src/maker/storage.ts
28054
28054
  import fs from "node:fs";
@@ -28075,13 +28075,13 @@ function getMakerHome() {
28075
28075
  return process.env[MAKER_HOME_ENV] || path.join(os.homedir(), MAKER_DIR);
28076
28076
  }
28077
28077
  function getJwtPath() {
28078
- return path.join(getMakerHome(), "jwt.json");
28078
+ return getMakerCredentialPath("jwt.json");
28079
28079
  }
28080
28080
  function getPatPath() {
28081
- return path.join(getMakerHome(), "pat.json");
28081
+ return getMakerCredentialPath("pat.json");
28082
28082
  }
28083
28083
  function getTapAuthPath() {
28084
- return path.join(getMakerHome(), "tap-auth.json");
28084
+ return getMakerCredentialPath("tap-auth.json");
28085
28085
  }
28086
28086
  function getLegacyPatPath() {
28087
28087
  return path.join(os.homedir(), ".maker-pat");
@@ -28109,8 +28109,6 @@ function savePat(pat) {
28109
28109
  ...pat,
28110
28110
  saved_at: (/* @__PURE__ */ new Date()).toISOString()
28111
28111
  });
28112
- fs.writeFileSync(getLegacyPatPath(), `${pat.token}
28113
- `, "utf8");
28114
28112
  }
28115
28113
  function loadTapAuth() {
28116
28114
  const auth2 = readJsonFile(getTapAuthPath());
@@ -28147,9 +28145,177 @@ function saveProjectConfig(projectRoot, config2) {
28147
28145
  function getProjectMarkerDirName() {
28148
28146
  return PROJECT_DIR;
28149
28147
  }
28148
+ function getMakerCredentialPath(fileName) {
28149
+ return path.join(getMakerHome(), fileName);
28150
+ }
28151
+
28152
+ // src/maker/server/identify.ts
28153
+ function parseConfig(configPath) {
28154
+ try {
28155
+ const parsed = JSON.parse(fs2.readFileSync(configPath, "utf8"));
28156
+ return (parsed == null ? void 0 : parsed.project_id) ? parsed : null;
28157
+ } catch {
28158
+ return null;
28159
+ }
28160
+ }
28161
+ function findProjectConfig(startDir = process.cwd()) {
28162
+ let current = path2.resolve(startDir);
28163
+ while (current.length > 0) {
28164
+ const configPath = getProjectConfigPath(current);
28165
+ if (fs2.existsSync(configPath)) {
28166
+ const config2 = parseConfig(configPath);
28167
+ if (config2) {
28168
+ return {
28169
+ projectId: config2.project_id,
28170
+ configPath,
28171
+ projectRoot: current,
28172
+ config: config2,
28173
+ source: "cwd"
28174
+ };
28175
+ }
28176
+ }
28177
+ const parent = path2.dirname(current);
28178
+ if (parent === current) {
28179
+ return { source: "none" };
28180
+ }
28181
+ current = parent;
28182
+ }
28183
+ return { source: "none" };
28184
+ }
28185
+ function identifyMakerProject(options) {
28186
+ if (options == null ? void 0 : options.projectId) {
28187
+ return {
28188
+ projectId: options.projectId,
28189
+ source: "argv"
28190
+ };
28191
+ }
28192
+ if (process.env.MAKER_PROJECT_ID) {
28193
+ return {
28194
+ projectId: process.env.MAKER_PROJECT_ID,
28195
+ source: "env"
28196
+ };
28197
+ }
28198
+ return findProjectConfig((options == null ? void 0 : options.cwd) || process.cwd());
28199
+ }
28200
+ function formatIdentifyHint() {
28201
+ return [
28202
+ "当前目录尚未绑定 Maker 项目。",
28203
+ "",
28204
+ "初始化流程请运行 `taptap-maker init`;缺少本地鉴权时 CLI 会自动进入登录授权。",
28205
+ "本地鉴权失效时请运行 `taptap-maker login`。",
28206
+ "",
28207
+ `clone 成功后会在当前目录写入 ${getProjectMarkerDirName()}/config.json。`
28208
+ ].join("\n");
28209
+ }
28210
+
28211
+ // src/maker/server/hiddenStdioTransport.ts
28212
+ import { spawn as spawn2 } from "node:child_process";
28213
+ import { PassThrough as PassThrough2 } from "node:stream";
28214
+ var HiddenStdioClientTransport = class {
28215
+ constructor(serverParams) {
28216
+ this.serverParams = serverParams;
28217
+ this.abortController = new AbortController();
28218
+ this.readBuffer = new ReadBuffer();
28219
+ this.stderrStream = serverParams.stderr === "pipe" || serverParams.stderr === "overlapped" ? new PassThrough2() : null;
28220
+ }
28221
+ async start() {
28222
+ if (this.process) {
28223
+ throw new Error("HiddenStdioClientTransport already started.");
28224
+ }
28225
+ await new Promise((resolve, reject) => {
28226
+ var _a3, _b, _c;
28227
+ this.process = spawn2(this.serverParams.command, this.serverParams.args ?? [], {
28228
+ env: this.serverParams.env,
28229
+ stdio: ["pipe", "pipe", this.serverParams.stderr ?? "inherit"],
28230
+ shell: false,
28231
+ signal: this.abortController.signal,
28232
+ windowsHide: true,
28233
+ cwd: this.serverParams.cwd
28234
+ });
28235
+ this.process.on("error", (error2) => {
28236
+ var _a4, _b2;
28237
+ if (error2.name === "AbortError") {
28238
+ (_a4 = this.onclose) == null ? void 0 : _a4.call(this);
28239
+ return;
28240
+ }
28241
+ reject(error2);
28242
+ (_b2 = this.onerror) == null ? void 0 : _b2.call(this, error2);
28243
+ });
28244
+ this.process.on("spawn", () => resolve());
28245
+ this.process.on("close", () => {
28246
+ var _a4;
28247
+ this.process = void 0;
28248
+ (_a4 = this.onclose) == null ? void 0 : _a4.call(this);
28249
+ });
28250
+ (_a3 = this.process.stdin) == null ? void 0 : _a3.on("error", (error2) => {
28251
+ var _a4;
28252
+ return (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error2);
28253
+ });
28254
+ (_b = this.process.stdout) == null ? void 0 : _b.on("data", (chunk) => {
28255
+ this.readBuffer.append(chunk);
28256
+ this.processReadBuffer();
28257
+ });
28258
+ (_c = this.process.stdout) == null ? void 0 : _c.on("error", (error2) => {
28259
+ var _a4;
28260
+ return (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error2);
28261
+ });
28262
+ if (this.stderrStream && this.process.stderr) {
28263
+ this.process.stderr.pipe(this.stderrStream);
28264
+ }
28265
+ });
28266
+ }
28267
+ get stderr() {
28268
+ var _a3;
28269
+ return this.stderrStream || ((_a3 = this.process) == null ? void 0 : _a3.stderr) || null;
28270
+ }
28271
+ get pid() {
28272
+ var _a3;
28273
+ return ((_a3 = this.process) == null ? void 0 : _a3.pid) ?? null;
28274
+ }
28275
+ async close() {
28276
+ this.abortController.abort();
28277
+ this.process = void 0;
28278
+ this.readBuffer.clear();
28279
+ }
28280
+ async send(message) {
28281
+ var _a3;
28282
+ const stdin = (_a3 = this.process) == null ? void 0 : _a3.stdin;
28283
+ if (!stdin) {
28284
+ throw new Error("Not connected");
28285
+ }
28286
+ const json2 = serializeMessage(message);
28287
+ if (stdin.write(json2)) {
28288
+ return;
28289
+ }
28290
+ await new Promise((resolve) => stdin.once("drain", resolve));
28291
+ }
28292
+ processReadBuffer() {
28293
+ var _a3, _b;
28294
+ for (; ; ) {
28295
+ try {
28296
+ const message = this.readBuffer.readMessage();
28297
+ if (message === null) {
28298
+ break;
28299
+ }
28300
+ (_a3 = this.onmessage) == null ? void 0 : _a3.call(this, message);
28301
+ } catch (error2) {
28302
+ (_b = this.onerror) == null ? void 0 : _b.call(this, error2 instanceof Error ? error2 : new Error(String(error2)));
28303
+ }
28304
+ }
28305
+ }
28306
+ };
28307
+
28308
+ // src/maker/cli/projects.ts
28309
+ import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
28310
+ import fs5 from "node:fs";
28311
+ import path6 from "node:path";
28312
+
28313
+ // src/maker/config.ts
28314
+ import fs3 from "node:fs";
28315
+ import path4 from "node:path";
28150
28316
 
28151
28317
  // src/core/utils/env.ts
28152
- import * as path2 from "node:path";
28318
+ import * as path3 from "node:path";
28153
28319
  import * as os2 from "node:os";
28154
28320
  import process5 from "node:process";
28155
28321
  var ENVIRONMENT_ENDPOINTS = {
@@ -28245,11 +28411,11 @@ var EnvConfig = class {
28245
28411
  // --------------------------------------------------------------------------
28246
28412
  /** 缓存目录 */
28247
28413
  static get cacheDir() {
28248
- return getEnv("TAPTAP_MCP_CACHE_DIR", path2.join(os2.tmpdir(), "taptap-mcp", "cache"));
28414
+ return getEnv("TAPTAP_MCP_CACHE_DIR", path3.join(os2.tmpdir(), "taptap-mcp", "cache"));
28249
28415
  }
28250
28416
  /** 临时文件目录 */
28251
28417
  static get tempDir() {
28252
- return getEnv("TAPTAP_MCP_TEMP_DIR", path2.join(os2.tmpdir(), "taptap-mcp", "temp"));
28418
+ return getEnv("TAPTAP_MCP_TEMP_DIR", path3.join(os2.tmpdir(), "taptap-mcp", "temp"));
28253
28419
  }
28254
28420
  /** 工作区根目录 */
28255
28421
  static get workspaceRoot() {
@@ -28390,6 +28556,8 @@ var MAKER_ENDPOINTS = {
28390
28556
  remoteMcpServerUrl: "https://fuping.agnt.xd.com/mcp/v1"
28391
28557
  }
28392
28558
  };
28559
+ var MAKER_PROJECT_ENV_CONFIG_FILE = path4.join(".maker", "taptap-maker.local.json");
28560
+ var makerEnvironmentOverride;
28393
28561
  var MAKER_ENV_OVERRIDES = {
28394
28562
  apiBase: {
28395
28563
  current: "TAPTAP_MAKER_API_BASE",
@@ -28416,8 +28584,21 @@ var MAKER_ENV_OVERRIDES = {
28416
28584
  legacy: "MAKER_WEB_URL"
28417
28585
  }
28418
28586
  };
28419
- function getMakerEnvironment(environment) {
28420
- return environment || EnvConfig.environment;
28587
+ function setMakerEnvironmentOverride(environment) {
28588
+ makerEnvironmentOverride = environment;
28589
+ }
28590
+ function getMakerEnvironment(environment, cwd = process.cwd()) {
28591
+ if (environment) {
28592
+ return environment;
28593
+ }
28594
+ if (makerEnvironmentOverride) {
28595
+ return makerEnvironmentOverride;
28596
+ }
28597
+ const envValue = process.env.TAPTAP_MCP_ENV;
28598
+ if (envValue === "rnd" || envValue === "production") {
28599
+ return envValue;
28600
+ }
28601
+ return getProjectLocalEnvironment(cwd) || EnvConfig.environment;
28421
28602
  }
28422
28603
  function getMakerEndpoints(environment) {
28423
28604
  const env = getMakerEnvironment(environment);
@@ -28435,8 +28616,23 @@ function getMakerWebUrl(environment) {
28435
28616
  const endpoints = getMakerEndpoints(environment);
28436
28617
  return requireMakerEndpoint("webUrl", endpoints.webUrl, environment).replace(/\/$/, "");
28437
28618
  }
28438
- function getMakerPatTokensUrl(environment) {
28439
- return `${getMakerWebUrl(environment)}/pat-tokens`;
28619
+ function getMakerApiBaseUrl(environment) {
28620
+ const endpoints = getMakerEndpoints(environment);
28621
+ return requireMakerEndpoint("apiBase", endpoints.apiBase, environment).replace(/\/$/, "");
28622
+ }
28623
+ function getMakerProjectEnvironmentConfigPath(cwd = process.cwd()) {
28624
+ let current = path4.resolve(cwd);
28625
+ for (; ; ) {
28626
+ const candidate = path4.join(current, MAKER_PROJECT_ENV_CONFIG_FILE);
28627
+ if (fs3.existsSync(candidate)) {
28628
+ return candidate;
28629
+ }
28630
+ const parent = path4.dirname(current);
28631
+ if (parent === current) {
28632
+ return void 0;
28633
+ }
28634
+ current = parent;
28635
+ }
28440
28636
  }
28441
28637
  function requireMakerEndpoint(name, value, environment) {
28442
28638
  if (!value) {
@@ -28456,167 +28652,20 @@ function requireMakerEndpoint(name, value, environment) {
28456
28652
  function getOverride(envNames) {
28457
28653
  return process.env[envNames.current] || process.env[envNames.legacy];
28458
28654
  }
28459
-
28460
- // src/maker/server/identify.ts
28461
- function parseConfig(configPath) {
28655
+ function getProjectLocalEnvironment(cwd) {
28656
+ const configPath = getMakerProjectEnvironmentConfigPath(cwd);
28657
+ if (!configPath) {
28658
+ return void 0;
28659
+ }
28462
28660
  try {
28463
- const parsed = JSON.parse(fs2.readFileSync(configPath, "utf8"));
28464
- return (parsed == null ? void 0 : parsed.project_id) ? parsed : null;
28661
+ const raw = fs3.readFileSync(configPath, "utf8");
28662
+ const data = JSON.parse(raw);
28663
+ const env = data.env || data.environment;
28664
+ return env === "rnd" || env === "production" ? env : void 0;
28465
28665
  } catch {
28466
- return null;
28467
- }
28468
- }
28469
- function findProjectConfig(startDir = process.cwd()) {
28470
- let current = path3.resolve(startDir);
28471
- while (current.length > 0) {
28472
- const configPath = getProjectConfigPath(current);
28473
- if (fs2.existsSync(configPath)) {
28474
- const config2 = parseConfig(configPath);
28475
- if (config2) {
28476
- return {
28477
- projectId: config2.project_id,
28478
- configPath,
28479
- projectRoot: current,
28480
- config: config2,
28481
- source: "cwd"
28482
- };
28483
- }
28484
- }
28485
- const parent = path3.dirname(current);
28486
- if (parent === current) {
28487
- return { source: "none" };
28488
- }
28489
- current = parent;
28490
- }
28491
- return { source: "none" };
28492
- }
28493
- function identifyMakerProject(options) {
28494
- if (options == null ? void 0 : options.projectId) {
28495
- return {
28496
- projectId: options.projectId,
28497
- source: "argv"
28498
- };
28499
- }
28500
- if (process.env.MAKER_PROJECT_ID) {
28501
- return {
28502
- projectId: process.env.MAKER_PROJECT_ID,
28503
- source: "env"
28504
- };
28666
+ return void 0;
28505
28667
  }
28506
- return findProjectConfig((options == null ? void 0 : options.cwd) || process.cwd());
28507
28668
  }
28508
- function formatIdentifyHint() {
28509
- return [
28510
- "当前目录尚未绑定 Maker 项目。",
28511
- "",
28512
- "初始化流程请参考 taptap-maker-local skill。",
28513
- `Maker PAT 页面:${getMakerPatTokensUrl()}`,
28514
- "",
28515
- `clone 成功后会在当前目录写入 ${getProjectMarkerDirName()}/config.json。`
28516
- ].join("\n");
28517
- }
28518
-
28519
- // src/maker/server/hiddenStdioTransport.ts
28520
- import { spawn as spawn2 } from "node:child_process";
28521
- import { PassThrough as PassThrough2 } from "node:stream";
28522
- var HiddenStdioClientTransport = class {
28523
- constructor(serverParams) {
28524
- this.serverParams = serverParams;
28525
- this.abortController = new AbortController();
28526
- this.readBuffer = new ReadBuffer();
28527
- this.stderrStream = serverParams.stderr === "pipe" || serverParams.stderr === "overlapped" ? new PassThrough2() : null;
28528
- }
28529
- async start() {
28530
- if (this.process) {
28531
- throw new Error("HiddenStdioClientTransport already started.");
28532
- }
28533
- await new Promise((resolve, reject) => {
28534
- var _a3, _b, _c;
28535
- this.process = spawn2(this.serverParams.command, this.serverParams.args ?? [], {
28536
- env: this.serverParams.env,
28537
- stdio: ["pipe", "pipe", this.serverParams.stderr ?? "inherit"],
28538
- shell: false,
28539
- signal: this.abortController.signal,
28540
- windowsHide: true,
28541
- cwd: this.serverParams.cwd
28542
- });
28543
- this.process.on("error", (error2) => {
28544
- var _a4, _b2;
28545
- if (error2.name === "AbortError") {
28546
- (_a4 = this.onclose) == null ? void 0 : _a4.call(this);
28547
- return;
28548
- }
28549
- reject(error2);
28550
- (_b2 = this.onerror) == null ? void 0 : _b2.call(this, error2);
28551
- });
28552
- this.process.on("spawn", () => resolve());
28553
- this.process.on("close", () => {
28554
- var _a4;
28555
- this.process = void 0;
28556
- (_a4 = this.onclose) == null ? void 0 : _a4.call(this);
28557
- });
28558
- (_a3 = this.process.stdin) == null ? void 0 : _a3.on("error", (error2) => {
28559
- var _a4;
28560
- return (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error2);
28561
- });
28562
- (_b = this.process.stdout) == null ? void 0 : _b.on("data", (chunk) => {
28563
- this.readBuffer.append(chunk);
28564
- this.processReadBuffer();
28565
- });
28566
- (_c = this.process.stdout) == null ? void 0 : _c.on("error", (error2) => {
28567
- var _a4;
28568
- return (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error2);
28569
- });
28570
- if (this.stderrStream && this.process.stderr) {
28571
- this.process.stderr.pipe(this.stderrStream);
28572
- }
28573
- });
28574
- }
28575
- get stderr() {
28576
- var _a3;
28577
- return this.stderrStream || ((_a3 = this.process) == null ? void 0 : _a3.stderr) || null;
28578
- }
28579
- get pid() {
28580
- var _a3;
28581
- return ((_a3 = this.process) == null ? void 0 : _a3.pid) ?? null;
28582
- }
28583
- async close() {
28584
- this.abortController.abort();
28585
- this.process = void 0;
28586
- this.readBuffer.clear();
28587
- }
28588
- async send(message) {
28589
- var _a3;
28590
- const stdin = (_a3 = this.process) == null ? void 0 : _a3.stdin;
28591
- if (!stdin) {
28592
- throw new Error("Not connected");
28593
- }
28594
- const json2 = serializeMessage(message);
28595
- if (stdin.write(json2)) {
28596
- return;
28597
- }
28598
- await new Promise((resolve) => stdin.once("drain", resolve));
28599
- }
28600
- processReadBuffer() {
28601
- var _a3, _b;
28602
- for (; ; ) {
28603
- try {
28604
- const message = this.readBuffer.readMessage();
28605
- if (message === null) {
28606
- break;
28607
- }
28608
- (_a3 = this.onmessage) == null ? void 0 : _a3.call(this, message);
28609
- } catch (error2) {
28610
- (_b = this.onerror) == null ? void 0 : _b.call(this, error2 instanceof Error ? error2 : new Error(String(error2)));
28611
- }
28612
- }
28613
- }
28614
- };
28615
-
28616
- // src/maker/cli/projects.ts
28617
- import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
28618
- import fs4 from "node:fs";
28619
- import path5 from "node:path";
28620
28669
 
28621
28670
  // src/maker/auth/jwt.ts
28622
28671
  var MAKER_JWT_ENV = "MAKER_JWT";
@@ -28720,8 +28769,8 @@ function requireMakerPat(manualPat) {
28720
28769
  throw new Error(
28721
28770
  [
28722
28771
  "Maker PAT not found.",
28723
- "Provide a PAT through the pat argument, MAKER_PAT/PAT environment variable,",
28724
- "or save it to ~/.taptap-maker/pat.json / ~/.maker-pat."
28772
+ "Run `taptap-maker login` to complete Maker CLI login,",
28773
+ "or provide MAKER_PAT/PAT only for CI/emergency fallback."
28725
28774
  ].join(" ")
28726
28775
  );
28727
28776
  }
@@ -28756,9 +28805,8 @@ async function requestMakerPat(options) {
28756
28805
  throw new Error(
28757
28806
  [
28758
28807
  "Maker PAT not found.",
28759
- "Provide a PAT through the pat argument, MAKER_PAT/PAT environment variable,",
28760
- "or save it interactively with `taptap-maker pat set`.",
28761
- "Creating a new PAT still requires a legacy Maker JWT."
28808
+ "Run `taptap-maker login` to complete Maker CLI login,",
28809
+ "or provide MAKER_PAT/PAT only for CI/emergency fallback."
28762
28810
  ].join(" ")
28763
28811
  );
28764
28812
  }
@@ -28876,14 +28924,45 @@ function formatGitMissingMessage(environment) {
28876
28924
 
28877
28925
  // src/maker/cli/devKit.ts
28878
28926
  import { spawnSync as spawnSync2 } from "node:child_process";
28879
- import fs3 from "node:fs";
28927
+ import fs4 from "node:fs";
28880
28928
  import os3 from "node:os";
28881
- import path4 from "node:path";
28929
+ import path5 from "node:path";
28930
+
28931
+ // src/maker/fetchTimeout.ts
28932
+ var DEFAULT_SHORT_FETCH_TIMEOUT_MS = 10 * 1e3;
28933
+ var DEFAULT_DOWNLOAD_FETCH_TIMEOUT_MS = 10 * 60 * 1e3;
28934
+ async function fetchWithTimeout(fetchImpl, url2, init, timeoutMs, label) {
28935
+ const controller = new AbortController();
28936
+ const timer = setTimeout(() => {
28937
+ controller.abort();
28938
+ }, timeoutMs);
28939
+ try {
28940
+ return await fetchImpl(url2, {
28941
+ ...init,
28942
+ signal: controller.signal
28943
+ });
28944
+ } catch (error2) {
28945
+ if (controller.signal.aborted) {
28946
+ throw new Error(`${label} timed out after ${timeoutMs}ms`);
28947
+ }
28948
+ throw error2;
28949
+ } finally {
28950
+ clearTimeout(timer);
28951
+ }
28952
+ }
28953
+
28954
+ // src/maker/cli/devKit.ts
28882
28955
  var AI_DEV_KIT_URLS = {
28883
28956
  production: "https://urhox-demo-platform.spark.xd.com/ai-dev-kit/pd/stable/ai-dev-kit.zip",
28884
28957
  rnd: "https://urhox-demo-platform.spark.xd.com/ai-dev-kit/rnd/latest/ai-dev-kit.zip"
28885
28958
  };
28886
28959
  var DEFAULT_AI_DEV_KIT_URL = AI_DEV_KIT_URLS.production;
28960
+ var AI_DEV_KIT_VERSION_METADATA_FILE = path5.join(".maker", "ai-dev-kit-version.json");
28961
+ var AI_DEV_KIT_DOWNLOAD_ENV = {
28962
+ production: "pd",
28963
+ rnd: "rnd"
28964
+ };
28965
+ var AI_DEV_KIT_VERSION_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
28887
28966
  function resolveDefaultAiDevKitUrl(environment = EnvConfig.environment) {
28888
28967
  return AI_DEV_KIT_URLS[environment] || AI_DEV_KIT_URLS.production;
28889
28968
  }
@@ -28916,9 +28995,9 @@ var DEV_KIT_MANAGED_ENTRY_CANDIDATES = [
28916
28995
  var SKIPPED_TOP_LEVEL_ENTRIES = /* @__PURE__ */ new Set(["scripts", ".DS_Store", "ai-dev-kit.zip"]);
28917
28996
  var SKILL_INSTALLER_OUTPUT_ENTRIES = [".claude", ".codex", ".cursor", ".gemini"];
28918
28997
  function inspectAiDevKit(targetDir) {
28919
- const resolvedTargetDir = path4.resolve(targetDir);
28998
+ const resolvedTargetDir = path5.resolve(targetDir);
28920
28999
  const presentEntries = DEV_KIT_REQUIRED_ENTRIES.filter(
28921
- (entry) => fs3.existsSync(path4.join(resolvedTargetDir, entry))
29000
+ (entry) => fs4.existsSync(path5.join(resolvedTargetDir, entry))
28922
29001
  );
28923
29002
  const missingEntries = DEV_KIT_REQUIRED_ENTRIES.filter(
28924
29003
  (entry) => !presentEntries.includes(entry)
@@ -28928,29 +29007,138 @@ function inspectAiDevKit(targetDir) {
28928
29007
  requiredEntries: [...DEV_KIT_REQUIRED_ENTRIES],
28929
29008
  presentEntries,
28930
29009
  missingEntries,
28931
- ready: missingEntries.length === 0
29010
+ ready: missingEntries.length === 0,
29011
+ installedVersion: readAiDevKitVersionMetadata(resolvedTargetDir)
29012
+ };
29013
+ }
29014
+ function getAiDevKitVersionMetadataPath(targetDir) {
29015
+ return path5.join(path5.resolve(targetDir), AI_DEV_KIT_VERSION_METADATA_FILE);
29016
+ }
29017
+ function readAiDevKitVersionMetadata(targetDir) {
29018
+ const metadataPath = getAiDevKitVersionMetadataPath(targetDir);
29019
+ if (!fs4.existsSync(metadataPath)) {
29020
+ return void 0;
29021
+ }
29022
+ try {
29023
+ const data = JSON.parse(
29024
+ fs4.readFileSync(metadataPath, "utf8")
29025
+ );
29026
+ if (data.env !== "production" && data.env !== "rnd" || !isValidDevKitVersion(data.version) || typeof data.source_url !== "string" || typeof data.installed_at !== "string") {
29027
+ return void 0;
29028
+ }
29029
+ return data;
29030
+ } catch {
29031
+ return void 0;
29032
+ }
29033
+ }
29034
+ function writeAiDevKitVersionMetadata(targetDir, metadata) {
29035
+ const metadataPath = getAiDevKitVersionMetadataPath(targetDir);
29036
+ fs4.mkdirSync(path5.dirname(metadataPath), { recursive: true });
29037
+ fs4.writeFileSync(metadataPath, `${JSON.stringify(metadata, null, 2)}
29038
+ `, "utf8");
29039
+ }
29040
+ async function fetchAiDevKitVersions(options = {}) {
29041
+ const env = getMakerEnvironment(options.environment);
29042
+ const versionsUrl = getAiDevKitVersionsUrl(env);
29043
+ const fetchFn = options.fetchImpl || fetch;
29044
+ const response = await fetchWithTimeout(
29045
+ fetchFn,
29046
+ versionsUrl,
29047
+ {
29048
+ headers: {
29049
+ Accept: "application/json"
29050
+ }
29051
+ },
29052
+ options.timeoutMs ?? DEFAULT_SHORT_FETCH_TIMEOUT_MS,
29053
+ "AI dev kit version check"
29054
+ );
29055
+ if (!response.ok) {
29056
+ throw new Error(
29057
+ `AI dev kit version check failed: HTTP ${response.status} ${response.statusText}`
29058
+ );
29059
+ }
29060
+ const payload = await response.json();
29061
+ if (!payload.current || !isValidDevKitVersion(payload.current.version)) {
29062
+ throw new Error("AI dev kit version check failed: missing current.version");
29063
+ }
29064
+ return payload;
29065
+ }
29066
+ async function resolveAiDevKitDownload(options = {}) {
29067
+ const env = getMakerEnvironment(options.environment);
29068
+ const versionsUrl = getAiDevKitVersionsUrl(env);
29069
+ try {
29070
+ const version2 = await fetchAiDevKitVersions({
29071
+ environment: env,
29072
+ fetchImpl: options.fetchImpl,
29073
+ timeoutMs: options.versionCheckTimeoutMs
29074
+ });
29075
+ return {
29076
+ environment: env,
29077
+ url: getAiDevKitDownloadUrl(env, version2.current.version),
29078
+ versionsUrl,
29079
+ version: version2
29080
+ };
29081
+ } catch (error2) {
29082
+ return {
29083
+ environment: env,
29084
+ url: resolveDefaultAiDevKitUrl(env),
29085
+ versionsUrl,
29086
+ versionCheckError: error2 instanceof Error ? error2.message : String(error2)
29087
+ };
29088
+ }
29089
+ }
29090
+ async function checkAiDevKitUpdate(targetDir, options = {}) {
29091
+ var _a3;
29092
+ const resolvedTargetDir = path5.resolve(targetDir);
29093
+ const installed = readAiDevKitVersionMetadata(resolvedTargetDir);
29094
+ const download = await resolveAiDevKitDownload({
29095
+ environment: options.environment,
29096
+ fetchImpl: options.fetchImpl,
29097
+ versionCheckTimeoutMs: options.versionCheckTimeoutMs
29098
+ });
29099
+ const latest = (_a3 = download.version) == null ? void 0 : _a3.current;
29100
+ return {
29101
+ targetDir: resolvedTargetDir,
29102
+ installed,
29103
+ latest,
29104
+ latestDownloadUrl: download.url,
29105
+ updateAvailable: Boolean(latest && (!installed || installed.version !== latest.version)),
29106
+ versionCheckError: download.versionCheckError
28932
29107
  };
28933
29108
  }
28934
29109
  function listPresentDevKitManagedEntries(targetDir) {
28935
- const resolvedTargetDir = path4.resolve(targetDir);
29110
+ const resolvedTargetDir = path5.resolve(targetDir);
28936
29111
  return DEV_KIT_MANAGED_ENTRY_CANDIDATES.filter(
28937
- (entry) => fs3.existsSync(path4.join(resolvedTargetDir, entry))
29112
+ (entry) => fs4.existsSync(path5.join(resolvedTargetDir, entry))
28938
29113
  );
28939
29114
  }
28940
29115
  async function installAiDevKit(options = {}) {
28941
- const targetDir = path4.resolve(options.targetDir || ".");
28942
- fs3.mkdirSync(targetDir, { recursive: true });
28943
- const preparedSource = options.sourceDir ? path4.resolve(options.sourceDir) : await downloadAndExtractDevKit(options.url || resolveDefaultAiDevKitUrl());
29116
+ var _a3;
29117
+ const targetDir = path5.resolve(options.targetDir || ".");
29118
+ fs4.mkdirSync(targetDir, { recursive: true });
29119
+ const download = options.sourceDir ? void 0 : options.url ? void 0 : await resolveAiDevKitDownload({
29120
+ environment: options.environment,
29121
+ fetchImpl: options.fetchImpl,
29122
+ versionCheckTimeoutMs: options.versionCheckTimeoutMs
29123
+ });
29124
+ const downloadUrl = options.url || (download == null ? void 0 : download.url) || resolveDefaultAiDevKitUrl(options.environment);
29125
+ const preparedSource = options.sourceDir ? path5.resolve(options.sourceDir) : await downloadAndExtractDevKit(downloadUrl, options.fetchImpl, options.downloadTimeoutMs);
28944
29126
  const sourceDir = resolveDevKitRoot(preparedSource);
28945
- const entries = fs3.readdirSync(sourceDir, { withFileTypes: true });
29127
+ const entries = fs4.readdirSync(sourceDir, { withFileTypes: true });
28946
29128
  const installedEntries = [];
28947
29129
  const skippedEntries = [];
29130
+ if (options.replaceManagedEntries) {
29131
+ replaceDevKitManagedEntries(
29132
+ targetDir,
29133
+ entries.map((entry) => entry.name)
29134
+ );
29135
+ }
28948
29136
  for (const entry of entries) {
28949
29137
  if (SKIPPED_TOP_LEVEL_ENTRIES.has(entry.name)) {
28950
29138
  skippedEntries.push(entry.name);
28951
29139
  continue;
28952
29140
  }
28953
- copyEntry(path4.join(sourceDir, entry.name), path4.join(targetDir, entry.name), {
29141
+ copyEntry(path5.join(sourceDir, entry.name), path5.join(targetDir, entry.name), {
28954
29142
  preserveExisting: options.preserveExisting
28955
29143
  });
28956
29144
  installedEntries.push(entry.name);
@@ -28964,27 +29152,35 @@ async function installAiDevKit(options = {}) {
28964
29152
  installedEntries.push(entry);
28965
29153
  }
28966
29154
  }
28967
- const stagedGitignorePath = path4.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE);
29155
+ const stagedGitignorePath = path5.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE);
28968
29156
  writeDevKitStagedGitignore(stagedGitignorePath, [
28969
29157
  ...installedEntries,
28970
29158
  ...listPresentSkillInstallerOutputEntries(targetDir)
28971
29159
  ]);
29160
+ const versionMetadata = ((_a3 = download == null ? void 0 : download.version) == null ? void 0 : _a3.current) && writeResolvedDevKitVersionMetadata(
29161
+ targetDir,
29162
+ download.environment,
29163
+ download.url,
29164
+ download.version.current
29165
+ );
28972
29166
  return {
28973
29167
  targetDir,
28974
29168
  sourceDir,
28975
29169
  installedEntries: installedEntries.sort(),
28976
29170
  skippedEntries: skippedEntries.sort(),
28977
- gitignorePath: path4.join(targetDir, ".gitignore"),
29171
+ gitignorePath: path5.join(targetDir, ".gitignore"),
28978
29172
  stagedGitignorePath,
28979
- skillInstaller
29173
+ skillInstaller,
29174
+ download,
29175
+ versionMetadata
28980
29176
  };
28981
29177
  }
28982
29178
  function inspectAiDevKitSkillInstallStatus(targetDir) {
28983
- const resolvedTargetDir = path4.resolve(targetDir);
29179
+ const resolvedTargetDir = path5.resolve(targetDir);
28984
29180
  const targets = SKILL_INSTALLER_OUTPUT_ENTRIES.map((entry) => {
28985
- const skillsDir = path4.join(resolvedTargetDir, entry, "skills");
28986
- const present = fs3.existsSync(skillsDir) && fs3.statSync(skillsDir).isDirectory();
28987
- const skillCount = present ? fs3.readdirSync(skillsDir, { withFileTypes: true }).filter((item) => item.isDirectory() || item.isSymbolicLink()).length : 0;
29181
+ const skillsDir = path5.join(resolvedTargetDir, entry, "skills");
29182
+ const present = fs4.existsSync(skillsDir) && fs4.statSync(skillsDir).isDirectory();
29183
+ const skillCount = present ? fs4.readdirSync(skillsDir, { withFileTypes: true }).filter((item) => item.isDirectory() || item.isSymbolicLink()).length : 0;
28988
29184
  return {
28989
29185
  name: entry.replace(/^\./, ""),
28990
29186
  path: skillsDir,
@@ -29007,15 +29203,15 @@ function createDevKitGitignoreBlock(entries) {
29007
29203
  return [DEV_KIT_IGNORE_BEGIN, ...ignoreEntries, DEV_KIT_IGNORE_END].join("\n");
29008
29204
  }
29009
29205
  function writeDevKitStagedGitignore(stagedGitignorePath, entries) {
29010
- fs3.writeFileSync(stagedGitignorePath, `${createDevKitGitignoreBlock(entries)}
29206
+ fs4.writeFileSync(stagedGitignorePath, `${createDevKitGitignoreBlock(entries)}
29011
29207
  `, "utf8");
29012
29208
  }
29013
29209
  function ensureMakerAssetPolicyInstructionFiles(targetDir) {
29014
- const resolvedTargetDir = path4.resolve(targetDir);
29015
- fs3.mkdirSync(resolvedTargetDir, { recursive: true });
29016
- const agentsPath = path4.join(resolvedTargetDir, AGENTS_INSTRUCTION_FILE);
29017
- const existingAgents = fs3.existsSync(agentsPath) ? fs3.readFileSync(agentsPath, "utf8") : "";
29018
- fs3.writeFileSync(agentsPath, prependMakerAssetPolicyBlock(existingAgents), "utf8");
29210
+ const resolvedTargetDir = path5.resolve(targetDir);
29211
+ fs4.mkdirSync(resolvedTargetDir, { recursive: true });
29212
+ const agentsPath = path5.join(resolvedTargetDir, AGENTS_INSTRUCTION_FILE);
29213
+ const existingAgents = fs4.existsSync(agentsPath) ? fs4.readFileSync(agentsPath, "utf8") : "";
29214
+ fs4.writeFileSync(agentsPath, prependMakerAssetPolicyBlock(existingAgents), "utf8");
29019
29215
  return [AGENTS_INSTRUCTION_FILE];
29020
29216
  }
29021
29217
  function prependMakerAssetPolicyBlock(existing) {
@@ -29070,7 +29266,7 @@ function createMakerAssetPolicyBlock() {
29070
29266
  ].join("\n");
29071
29267
  }
29072
29268
  function mergeDevKitGitignoreBlock(gitignorePath, block) {
29073
- const existing = fs3.existsSync(gitignorePath) ? fs3.readFileSync(gitignorePath, "utf8") : "";
29269
+ const existing = fs4.existsSync(gitignorePath) ? fs4.readFileSync(gitignorePath, "utf8") : "";
29074
29270
  const withoutOldBlock = existing.replace(
29075
29271
  new RegExp(
29076
29272
  `${escapeRegExp(DEV_KIT_IGNORE_BEGIN)}[\\s\\S]*?${escapeRegExp(DEV_KIT_IGNORE_END)}\\n?`,
@@ -29079,44 +29275,90 @@ function mergeDevKitGitignoreBlock(gitignorePath, block) {
29079
29275
  ""
29080
29276
  ).trimEnd();
29081
29277
  const next = [withoutOldBlock, block, ""].filter((part) => part.length > 0).join("\n\n");
29082
- fs3.writeFileSync(gitignorePath, next, "utf8");
29278
+ fs4.writeFileSync(gitignorePath, next, "utf8");
29083
29279
  }
29084
29280
  function finalizeStagedDevKitGitignore(targetDir) {
29085
- const stagedGitignorePath = path4.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE);
29086
- if (!fs3.existsSync(stagedGitignorePath)) {
29281
+ const stagedGitignorePath = path5.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE);
29282
+ if (!fs4.existsSync(stagedGitignorePath)) {
29087
29283
  return false;
29088
29284
  }
29089
- const block = fs3.readFileSync(stagedGitignorePath, "utf8").trim();
29285
+ const block = fs4.readFileSync(stagedGitignorePath, "utf8").trim();
29090
29286
  if (block.length > 0) {
29091
- mergeDevKitGitignoreBlock(path4.join(targetDir, ".gitignore"), block);
29287
+ mergeDevKitGitignoreBlock(path5.join(targetDir, ".gitignore"), block);
29092
29288
  }
29093
- fs3.rmSync(stagedGitignorePath, { force: true });
29289
+ fs4.rmSync(stagedGitignorePath, { force: true });
29094
29290
  return true;
29095
29291
  }
29096
29292
  function copyEntry(source, target, options = {}) {
29097
- const stat = fs3.statSync(source);
29293
+ const stat = fs4.statSync(source);
29098
29294
  if (stat.isDirectory()) {
29099
- fs3.mkdirSync(target, { recursive: true });
29100
- for (const child of fs3.readdirSync(source)) {
29295
+ fs4.mkdirSync(target, { recursive: true });
29296
+ for (const child of fs4.readdirSync(source)) {
29101
29297
  if (child === ".DS_Store") {
29102
29298
  continue;
29103
29299
  }
29104
- copyEntry(path4.join(source, child), path4.join(target, child), options);
29300
+ copyEntry(path5.join(source, child), path5.join(target, child), options);
29105
29301
  }
29106
29302
  return;
29107
29303
  }
29108
29304
  if (stat.isFile()) {
29109
- if (options.preserveExisting && fs3.existsSync(target)) {
29305
+ if (options.preserveExisting && fs4.existsSync(target)) {
29110
29306
  return;
29111
29307
  }
29112
- fs3.mkdirSync(path4.dirname(target), { recursive: true });
29113
- fs3.copyFileSync(source, target);
29308
+ fs4.mkdirSync(path5.dirname(target), { recursive: true });
29309
+ fs4.copyFileSync(source, target);
29114
29310
  }
29115
29311
  }
29312
+ function replaceDevKitManagedEntries(targetDir, sourceEntryNames) {
29313
+ const candidates = /* @__PURE__ */ new Set();
29314
+ for (const entry of sourceEntryNames) {
29315
+ if (!SKIPPED_TOP_LEVEL_ENTRIES.has(entry)) {
29316
+ candidates.add(entry);
29317
+ }
29318
+ }
29319
+ for (const entry of readManagedGitignoreEntries(path5.join(targetDir, ".gitignore"))) {
29320
+ candidates.add(entry);
29321
+ }
29322
+ for (const entry of readManagedGitignoreEntries(
29323
+ path5.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE)
29324
+ )) {
29325
+ candidates.add(entry);
29326
+ }
29327
+ for (const entry of candidates) {
29328
+ if (!entry || ALWAYS_IGNORED_LOCAL_ENTRIES.includes(entry)) {
29329
+ continue;
29330
+ }
29331
+ if (!DEV_KIT_MANAGED_ENTRY_CANDIDATES.includes(entry)) {
29332
+ continue;
29333
+ }
29334
+ fs4.rmSync(path5.join(targetDir, entry), { recursive: true, force: true });
29335
+ }
29336
+ }
29337
+ function readManagedGitignoreEntries(gitignorePath) {
29338
+ if (!fs4.existsSync(gitignorePath)) {
29339
+ return [];
29340
+ }
29341
+ const content = fs4.readFileSync(gitignorePath, "utf8");
29342
+ const blockPattern = new RegExp(
29343
+ `${escapeRegExp(DEV_KIT_IGNORE_BEGIN)}\\n([\\s\\S]*?)\\n${escapeRegExp(DEV_KIT_IGNORE_END)}`,
29344
+ "g"
29345
+ );
29346
+ const entries = [];
29347
+ for (const match of content.matchAll(blockPattern)) {
29348
+ const block = match[1] || "";
29349
+ for (const line of block.split(/\r?\n/)) {
29350
+ const entry = line.trim().replace(/\/$/, "");
29351
+ if (entry && !entry.startsWith("#")) {
29352
+ entries.push(entry);
29353
+ }
29354
+ }
29355
+ }
29356
+ return entries;
29357
+ }
29116
29358
  function installAiDevKitSkills(targetDir, options = {}) {
29117
29359
  var _a3;
29118
- const toolsDir = path4.join(targetDir, "tools");
29119
- if (!fs3.existsSync(toolsDir) || !fs3.statSync(toolsDir).isDirectory()) {
29360
+ const toolsDir = path5.join(targetDir, "tools");
29361
+ if (!fs4.existsSync(toolsDir) || !fs4.statSync(toolsDir).isDirectory()) {
29120
29362
  return {
29121
29363
  ok: false,
29122
29364
  status: "skipped",
@@ -29128,8 +29370,8 @@ function installAiDevKitSkills(targetDir, options = {}) {
29128
29370
  }
29129
29371
  const isWindows = process.platform === "win32";
29130
29372
  const scriptName = isWindows ? "install-skills.ps1" : "install-skills.sh";
29131
- const scriptPath = path4.join(toolsDir, scriptName);
29132
- if (!fs3.existsSync(scriptPath)) {
29373
+ const scriptPath = path5.join(toolsDir, scriptName);
29374
+ if (!fs4.existsSync(scriptPath)) {
29133
29375
  return {
29134
29376
  ok: false,
29135
29377
  status: "skipped",
@@ -29191,20 +29433,48 @@ function runDevKitSkillInstallerForInstall(targetDir, options = {}) {
29191
29433
  }
29192
29434
  function listPresentSkillInstallerOutputEntries(targetDir) {
29193
29435
  return SKILL_INSTALLER_OUTPUT_ENTRIES.filter(
29194
- (entry) => fs3.existsSync(path4.join(targetDir, entry))
29436
+ (entry) => fs4.existsSync(path5.join(targetDir, entry))
29195
29437
  );
29196
29438
  }
29197
- async function downloadAndExtractDevKit(url2) {
29198
- const tempDir = fs3.mkdtempSync(path4.join(os3.tmpdir(), "taptap-maker-ai-dev-kit-"));
29199
- const zipPath = path4.join(tempDir, "ai-dev-kit.zip");
29200
- const response = await fetch(url2);
29439
+ function getAiDevKitVersionsUrl(environment) {
29440
+ const endpoints = getMakerEndpoints(environment);
29441
+ const remoteMcpServerUrl = requireMakerEndpoint(
29442
+ "remoteMcpServerUrl",
29443
+ endpoints.remoteMcpServerUrl,
29444
+ environment
29445
+ ).replace(/\/$/, "");
29446
+ return `${remoteMcpServerUrl}/ai-dev-kit/versions`;
29447
+ }
29448
+ function getAiDevKitDownloadUrl(environment, version2) {
29449
+ return `https://urhox-demo-platform.spark.xd.com/ai-dev-kit/${AI_DEV_KIT_DOWNLOAD_ENV[environment]}/${version2}/ai-dev-kit.zip`;
29450
+ }
29451
+ function isValidDevKitVersion(version2) {
29452
+ return typeof version2 === "string" && AI_DEV_KIT_VERSION_PATTERN.test(version2);
29453
+ }
29454
+ function writeResolvedDevKitVersionMetadata(targetDir, environment, sourceUrl, current) {
29455
+ const metadata = {
29456
+ env: environment,
29457
+ version: current.version,
29458
+ md5: current.md5,
29459
+ size: current.size,
29460
+ uploaded_at: current.uploaded_at,
29461
+ source_url: sourceUrl,
29462
+ installed_at: (/* @__PURE__ */ new Date()).toISOString()
29463
+ };
29464
+ writeAiDevKitVersionMetadata(targetDir, metadata);
29465
+ return metadata;
29466
+ }
29467
+ async function downloadAndExtractDevKit(url2, fetchImpl = fetch, timeoutMs = DEFAULT_DOWNLOAD_FETCH_TIMEOUT_MS) {
29468
+ const tempDir = fs4.mkdtempSync(path5.join(os3.tmpdir(), "taptap-maker-ai-dev-kit-"));
29469
+ const zipPath = path5.join(tempDir, "ai-dev-kit.zip");
29470
+ const response = await fetchWithTimeout(fetchImpl, url2, {}, timeoutMs, "AI dev kit download");
29201
29471
  if (!response.ok) {
29202
29472
  throw new Error(`AI dev kit download failed: HTTP ${response.status} ${response.statusText}`);
29203
29473
  }
29204
29474
  const payload = Buffer.from(await response.arrayBuffer());
29205
- fs3.writeFileSync(zipPath, payload);
29475
+ fs4.writeFileSync(zipPath, payload);
29206
29476
  extractZip(zipPath, tempDir);
29207
- fs3.rmSync(zipPath, { force: true });
29477
+ fs4.rmSync(zipPath, { force: true });
29208
29478
  return tempDir;
29209
29479
  }
29210
29480
  function extractZip(zipPath, targetDir) {
@@ -29332,11 +29602,11 @@ function shellQuote(value) {
29332
29602
  return `'${value.replace(/'/g, "'\\''")}'`;
29333
29603
  }
29334
29604
  function resolveDevKitRoot(sourceDir) {
29335
- const directEntries = fs3.existsSync(sourceDir) ? fs3.readdirSync(sourceDir) : [];
29605
+ const directEntries = fs4.existsSync(sourceDir) ? fs4.readdirSync(sourceDir) : [];
29336
29606
  if (looksLikeDevKitRoot(sourceDir)) {
29337
29607
  return sourceDir;
29338
29608
  }
29339
- const childDirs = directEntries.map((entry) => path4.join(sourceDir, entry)).filter((entryPath) => fs3.existsSync(entryPath) && fs3.statSync(entryPath).isDirectory());
29609
+ const childDirs = directEntries.map((entry) => path5.join(sourceDir, entry)).filter((entryPath) => fs4.existsSync(entryPath) && fs4.statSync(entryPath).isDirectory());
29340
29610
  for (const childDir of childDirs) {
29341
29611
  if (looksLikeDevKitRoot(childDir)) {
29342
29612
  return childDir;
@@ -29345,7 +29615,7 @@ function resolveDevKitRoot(sourceDir) {
29345
29615
  throw new Error(`AI dev kit root not found under ${sourceDir}`);
29346
29616
  }
29347
29617
  function looksLikeDevKitRoot(dir) {
29348
- return fs3.existsSync(path4.join(dir, "engine-docs")) || fs3.existsSync(path4.join(dir, ".emmylua")) || fs3.existsSync(path4.join(dir, "urhox-libs"));
29618
+ return fs4.existsSync(path5.join(dir, "engine-docs")) || fs4.existsSync(path5.join(dir, ".emmylua")) || fs4.existsSync(path5.join(dir, "urhox-libs"));
29349
29619
  }
29350
29620
  function formatIgnoreEntry(entry) {
29351
29621
  if (entry === ".DS_Store") {
@@ -29463,7 +29733,7 @@ async function listMakerProjects(options) {
29463
29733
  }
29464
29734
  async function cloneMakerProject(options) {
29465
29735
  var _a3, _b, _c, _d, _e, _f, _g, _h;
29466
- const target = path5.resolve(options.targetDir);
29736
+ const target = path6.resolve(options.targetDir);
29467
29737
  ensureTargetCanBindApp(target, options.appId);
29468
29738
  const warnings = createPreCloneWarnings(target);
29469
29739
  (_a3 = options.onProgress) == null ? void 0 : _a3.call(options, {
@@ -29629,7 +29899,7 @@ async function pushMakerProject(options) {
29629
29899
  phase: "prepare",
29630
29900
  message: "Preparing Maker project push"
29631
29901
  });
29632
- const requestedCwd = path5.resolve(options.cwd);
29902
+ const requestedCwd = path6.resolve(options.cwd);
29633
29903
  const workspace = resolveUsableMakerGitWorkspace(requestedCwd);
29634
29904
  const cwd = workspace.projectRoot;
29635
29905
  const project = loadProjectConfig(cwd);
@@ -29935,7 +30205,7 @@ async function inspectMakerRemoteSyncStatus(cwd) {
29935
30205
  }
29936
30206
  function getMakerRemoteSyncFailureNextAction(failure) {
29937
30207
  if (failure.classification === "auth") {
29938
- return `暂时无法检查 Maker 远端是否有新提交:Git 鉴权失败。PAT 页面:${getMakerPatTokensUrl()}。请在该页面创建新的 Maker PAT,然后运行 \`taptap-maker pat set\` 并粘贴 PAT 后,再重新读取 maker://status。`;
30208
+ return "暂时无法检查 Maker 远端是否有新提交:Git 鉴权失败。请运行 `taptap-maker login` 重新完成 Maker 登录授权后,再重新读取 maker://status。";
29939
30209
  }
29940
30210
  return "暂时无法检查 Maker 远端是否有新提交。请把 failure 信息反馈给用户;如果只是 503、5xx、超时或网络中断,可稍后重新读取 maker://status。";
29941
30211
  }
@@ -30156,7 +30426,7 @@ function nextActionForFailure(classification) {
30156
30426
  case "git_missing":
30157
30427
  return "本机未检测到可用的 Git。请用户自行安装 Git,并在 `git --version` 可用后重启 MCP 客户端再重试;安装前不要执行 clone、fetch、commit 或 push。";
30158
30428
  case "auth":
30159
- return `Maker Git 鉴权失败。PAT 页面:${getMakerPatTokensUrl()}。请在该页面创建新的 Maker PAT,然后运行 \`taptap-maker pat set\` 并粘贴 PAT 后重试。`;
30429
+ return "Maker Git 鉴权失败。请运行 `taptap-maker login` 重新完成 Maker 登录授权后重试。";
30160
30430
  case "remote_transient":
30161
30431
  return "远端 Maker git 服务临时不可用。本地 commit 会保留;不要手动执行通用 git push,稍后直接重试 maker_build_current_directory。";
30162
30432
  case "branch_not_allowed":
@@ -30260,7 +30530,7 @@ function makeAuthenticatedGitUrl(gitUrl, pat) {
30260
30530
  return gitUrl.replace(/^https:\/\//, `https://git:${encodeURIComponent(pat)}@`);
30261
30531
  }
30262
30532
  async function fetchAndCheckoutTarget(target, authUrl, pat, onProgress) {
30263
- if (fs4.existsSync(target) && hasDirectoryEntries(target)) {
30533
+ if (fs5.existsSync(target) && hasDirectoryEntries(target)) {
30264
30534
  onProgress == null ? void 0 : onProgress({
30265
30535
  progress: 10,
30266
30536
  total: 100,
@@ -30307,23 +30577,23 @@ function emitFirstCloneWaitNotice(onProgress, phase) {
30307
30577
  });
30308
30578
  }
30309
30579
  function hasDirectoryEntries(target) {
30310
- if (!fs4.existsSync(target)) {
30580
+ if (!fs5.existsSync(target)) {
30311
30581
  return false;
30312
30582
  }
30313
- return fs4.readdirSync(target).length > 0;
30583
+ return fs5.readdirSync(target).length > 0;
30314
30584
  }
30315
30585
  function listLocalFiles(root) {
30316
- if (!fs4.existsSync(root)) {
30586
+ if (!fs5.existsSync(root)) {
30317
30587
  return [];
30318
30588
  }
30319
30589
  const files = [];
30320
30590
  const visit = (dir, relativeDir) => {
30321
- for (const entry of fs4.readdirSync(dir, { withFileTypes: true })) {
30591
+ for (const entry of fs5.readdirSync(dir, { withFileTypes: true })) {
30322
30592
  const relativePath = relativeDir ? `${relativeDir}/${entry.name}` : entry.name;
30323
30593
  if (entry.name === ".git" || relativePath === ".maker-mcp" || relativePath.startsWith(".maker-mcp/") || entry.name === ".DS_Store") {
30324
30594
  continue;
30325
30595
  }
30326
- const fullPath = path5.join(dir, entry.name);
30596
+ const fullPath = path6.join(dir, entry.name);
30327
30597
  if (entry.isDirectory()) {
30328
30598
  visit(fullPath, relativePath);
30329
30599
  continue;
@@ -30337,10 +30607,10 @@ function listLocalFiles(root) {
30337
30607
  return files;
30338
30608
  }
30339
30609
  function listPreCloneNoticeFiles(root) {
30340
- if (!fs4.existsSync(root)) {
30610
+ if (!fs5.existsSync(root)) {
30341
30611
  return [];
30342
30612
  }
30343
- return fs4.readdirSync(root, { withFileTypes: true }).filter((entry) => !isIgnorablePreCloneEntry(entry.name)).map((entry) => entry.name).sort();
30613
+ return fs5.readdirSync(root, { withFileTypes: true }).filter((entry) => !isIgnorablePreCloneEntry(entry.name)).map((entry) => entry.name).sort();
30344
30614
  }
30345
30615
  function createPreCloneWarnings(target) {
30346
30616
  const preCloneLocalFiles = listPreCloneNoticeFiles(target);
@@ -30463,7 +30733,7 @@ function ensureOwnGitRoot(repoDir) {
30463
30733
  );
30464
30734
  }
30465
30735
  function inspectMakerDirectoryGitStatus(cwd) {
30466
- const targetDir = path5.resolve(cwd);
30736
+ const targetDir = path6.resolve(cwd);
30467
30737
  const gitRoot = resolveGitRoot(targetDir);
30468
30738
  const gitDir = resolveGitDir(targetDir);
30469
30739
  const makerBinding = findMakerProjectBinding(targetDir);
@@ -30536,16 +30806,16 @@ function formatMakerGitRootMismatch(status) {
30536
30806
  }
30537
30807
  function findMakerProjectBinding(startDir) {
30538
30808
  var _a3;
30539
- let current = path5.resolve(startDir);
30809
+ let current = path6.resolve(startDir);
30540
30810
  while (current.length > 0) {
30541
30811
  const configPath = getProjectConfigPath(current);
30542
- if (fs4.existsSync(configPath) && ((_a3 = loadProjectConfig(current)) == null ? void 0 : _a3.project_id)) {
30812
+ if (fs5.existsSync(configPath) && ((_a3 = loadProjectConfig(current)) == null ? void 0 : _a3.project_id)) {
30543
30813
  return {
30544
30814
  projectRoot: current,
30545
30815
  configPath
30546
30816
  };
30547
30817
  }
30548
- const parent = path5.dirname(current);
30818
+ const parent = path6.dirname(current);
30549
30819
  if (parent === current) {
30550
30820
  return null;
30551
30821
  }
@@ -30555,7 +30825,7 @@ function findMakerProjectBinding(startDir) {
30555
30825
  }
30556
30826
  function resolveGitRoot(cwd) {
30557
30827
  try {
30558
- return path5.resolve(readGitSync(["-C", cwd, "rev-parse", "--show-toplevel"]).trim());
30828
+ return path6.resolve(readGitSync(["-C", cwd, "rev-parse", "--show-toplevel"]).trim());
30559
30829
  } catch {
30560
30830
  return void 0;
30561
30831
  }
@@ -30563,7 +30833,7 @@ function resolveGitRoot(cwd) {
30563
30833
  function resolveGitDir(cwd) {
30564
30834
  try {
30565
30835
  const gitDir = readGitSync(["-C", cwd, "rev-parse", "--git-dir"]).trim();
30566
- return path5.isAbsolute(gitDir) ? path5.resolve(gitDir) : path5.resolve(cwd, gitDir);
30836
+ return path6.isAbsolute(gitDir) ? path6.resolve(gitDir) : path6.resolve(cwd, gitDir);
30567
30837
  } catch {
30568
30838
  return void 0;
30569
30839
  }
@@ -30572,9 +30842,9 @@ function samePath(left, right) {
30572
30842
  return normalizePathForCompare(left) === normalizePathForCompare(right);
30573
30843
  }
30574
30844
  function normalizePathForCompare(value) {
30575
- const resolved = path5.resolve(value);
30845
+ const resolved = path6.resolve(value);
30576
30846
  try {
30577
- return fs4.realpathSync.native(resolved);
30847
+ return fs5.realpathSync.native(resolved);
30578
30848
  } catch {
30579
30849
  return resolved;
30580
30850
  }
@@ -30903,18 +31173,24 @@ function normalizeTapAuthResponse(data) {
30903
31173
  raw: data
30904
31174
  };
30905
31175
  }
30906
- function getMakerTapTokenUrl() {
30907
- const tapTokenUrl = getMakerEndpoints().tapTokenUrl;
30908
- return requireMakerEndpoint("tapTokenUrl", tapTokenUrl);
31176
+ function getMakerTapTokenUrl(environment) {
31177
+ const tapTokenUrl = getMakerEndpoints(environment).tapTokenUrl;
31178
+ return requireMakerEndpoint("tapTokenUrl", tapTokenUrl, environment);
30909
31179
  }
30910
- async function requestTapAuthWithPat(manualPat) {
31180
+ async function requestTapAuthWithPat(manualPat, environment, options = {}) {
30911
31181
  const pat = requireMakerPat(manualPat);
30912
- const response = await fetch(getMakerTapTokenUrl(), {
30913
- headers: {
30914
- Authorization: `Bearer ${pat.token}`,
30915
- Accept: "application/json"
30916
- }
30917
- });
31182
+ const response = await fetchWithTimeout(
31183
+ options.fetchImpl || fetch,
31184
+ getMakerTapTokenUrl(environment),
31185
+ {
31186
+ headers: {
31187
+ Authorization: `Bearer ${pat.token}`,
31188
+ Accept: "application/json"
31189
+ }
31190
+ },
31191
+ options.timeoutMs ?? DEFAULT_SHORT_FETCH_TIMEOUT_MS,
31192
+ "TapTap token request"
31193
+ );
30918
31194
  const text = await response.text();
30919
31195
  let json2 = {};
30920
31196
  if (text) {
@@ -30933,8 +31209,8 @@ async function requestTapAuthWithPat(manualPat) {
30933
31209
  }
30934
31210
 
30935
31211
  // src/maker/cli/skill.ts
30936
- import fs5 from "node:fs";
30937
- import path6 from "node:path";
31212
+ import fs6 from "node:fs";
31213
+ import path7 from "node:path";
30938
31214
  import { fileURLToPath } from "node:url";
30939
31215
  var MAKER_LOCAL_SKILL_NAME = "taptap-maker-local";
30940
31216
  var MAKER_DEV_KIT_GUIDE_SKILL_NAME = "taptap-maker-dev-kit-guide";
@@ -30953,7 +31229,7 @@ var BUNDLED_SKILLS = [
30953
31229
  function formatMakerSkillStatus(_options = {}) {
30954
31230
  const skillDocuments = BUNDLED_SKILLS.map((skill) => ({
30955
31231
  name: skill.name,
30956
- path: path6.join(resolveMakerSkillSourceDir(skill.name), "SKILL.md")
31232
+ path: path7.join(resolveMakerSkillSourceDir(skill.name), "SKILL.md")
30957
31233
  }));
30958
31234
  return [
30959
31235
  "TapTap Maker workflow guide documents",
@@ -30986,11 +31262,11 @@ function formatMakerSkillStatus(_options = {}) {
30986
31262
  }
30987
31263
  function resolveMakerSkillSourceDir(skillName = MAKER_LOCAL_SKILL_NAME) {
30988
31264
  const candidates = [
30989
- path6.join(process.cwd(), "skills", skillName),
31265
+ path7.join(process.cwd(), "skills", skillName),
30990
31266
  getBundledSkillSourceDir(skillName)
30991
31267
  ].filter(Boolean);
30992
31268
  for (const candidate of candidates) {
30993
- if (fs5.existsSync(path6.join(candidate, "SKILL.md"))) {
31269
+ if (fs6.existsSync(path7.join(candidate, "SKILL.md"))) {
30994
31270
  return candidate;
30995
31271
  }
30996
31272
  }
@@ -31003,13 +31279,13 @@ function getBundledSkillSourceDir(skillName) {
31003
31279
  return null;
31004
31280
  }
31005
31281
  const bundlePath = fileURLToPath(__MAKER_BUNDLE_URL__);
31006
- const packageRoot = path6.dirname(path6.dirname(bundlePath));
31007
- return path6.join(packageRoot, "skills", skillName);
31282
+ const packageRoot = path7.dirname(path7.dirname(bundlePath));
31283
+ return path7.join(packageRoot, "skills", skillName);
31008
31284
  }
31009
31285
 
31010
31286
  // src/maker/server/runtimeLogs.ts
31011
- import fs6 from "node:fs";
31012
- import path7 from "node:path";
31287
+ import fs7 from "node:fs";
31288
+ import path8 from "node:path";
31013
31289
  var DEFAULT_RUNTIME_LOG_SINCE_SECONDS = 600;
31014
31290
  var DEFAULT_RUNTIME_LOG_IDLE_TIMEOUT_MS = 10 * 60 * 1e3;
31015
31291
  var MAX_RUNTIME_LOG_WINDOW_SECONDS = 3600;
@@ -31150,19 +31426,19 @@ async function pullRuntimeLogs(options) {
31150
31426
  }
31151
31427
  function resetRuntimeLogs(projectRoot) {
31152
31428
  const runtimeDir = getRuntimeLogDir(projectRoot);
31153
- fs6.mkdirSync(runtimeDir, { recursive: true });
31429
+ fs7.mkdirSync(runtimeDir, { recursive: true });
31154
31430
  for (const file2 of RUNTIME_LOG_FILES_TO_RESET) {
31155
- fs6.rmSync(path7.join(runtimeDir, file2), { force: true });
31431
+ fs7.rmSync(path8.join(runtimeDir, file2), { force: true });
31156
31432
  }
31157
31433
  return runtimeDir;
31158
31434
  }
31159
31435
  function readRuntimeLogState(projectRoot) {
31160
31436
  const statePath = getRuntimeLogStatePath(projectRoot);
31161
- if (!fs6.existsSync(statePath)) {
31437
+ if (!fs7.existsSync(statePath)) {
31162
31438
  return null;
31163
31439
  }
31164
31440
  try {
31165
- const state = JSON.parse(fs6.readFileSync(statePath, "utf8"));
31441
+ const state = JSON.parse(fs7.readFileSync(statePath, "utf8"));
31166
31442
  return isRuntimeLogState(state) ? state : null;
31167
31443
  } catch {
31168
31444
  return null;
@@ -31190,9 +31466,9 @@ function normalizeRuntimeLogQueryResult(result) {
31190
31466
  };
31191
31467
  }
31192
31468
  function writeRuntimeLogRawResponse(projectRoot, raw) {
31193
- const rawPath = path7.join(getRuntimeLogDir(projectRoot), "last-query-runtime-logs-result.json");
31194
- fs6.mkdirSync(path7.dirname(rawPath), { recursive: true });
31195
- fs6.writeFileSync(
31469
+ const rawPath = path8.join(getRuntimeLogDir(projectRoot), "last-query-runtime-logs-result.json");
31470
+ fs7.mkdirSync(path8.dirname(rawPath), { recursive: true });
31471
+ fs7.writeFileSync(
31196
31472
  rawPath,
31197
31473
  `${JSON.stringify({ capturedAt: (/* @__PURE__ */ new Date()).toISOString(), raw }, null, 2)}
31198
31474
  `,
@@ -31201,7 +31477,7 @@ function writeRuntimeLogRawResponse(projectRoot, raw) {
31201
31477
  return rawPath;
31202
31478
  }
31203
31479
  function appendRuntimeLogs(projectRoot, logs) {
31204
- fs6.mkdirSync(getRuntimeLogDir(projectRoot), { recursive: true });
31480
+ fs7.mkdirSync(getRuntimeLogDir(projectRoot), { recursive: true });
31205
31481
  if (logs.length === 0) {
31206
31482
  return { files: [], written: 0 };
31207
31483
  }
@@ -31209,7 +31485,7 @@ function appendRuntimeLogs(projectRoot, logs) {
31209
31485
  let written = 0;
31210
31486
  for (const log of logs) {
31211
31487
  const line = JSON.stringify(compactRuntimeLogEntry(log));
31212
- fs6.appendFileSync(filePath, `${line}
31488
+ fs7.appendFileSync(filePath, `${line}
31213
31489
  `, "utf8");
31214
31490
  written += 1;
31215
31491
  }
@@ -31217,11 +31493,11 @@ function appendRuntimeLogs(projectRoot, logs) {
31217
31493
  }
31218
31494
  function writeRuntimeLogState(projectRoot, state) {
31219
31495
  const statePath = getRuntimeLogStatePath(projectRoot);
31220
- fs6.mkdirSync(path7.dirname(statePath), { recursive: true });
31496
+ fs7.mkdirSync(path8.dirname(statePath), { recursive: true });
31221
31497
  const tempPath = `${statePath}.${process.pid}.${Date.now()}.tmp`;
31222
- fs6.writeFileSync(tempPath, `${JSON.stringify(state, null, 2)}
31498
+ fs7.writeFileSync(tempPath, `${JSON.stringify(state, null, 2)}
31223
31499
  `, "utf8");
31224
- fs6.renameSync(tempPath, statePath);
31500
+ fs7.renameSync(tempPath, statePath);
31225
31501
  }
31226
31502
  function writeRuntimeLogFailureState(projectRoot, options) {
31227
31503
  const nowIso = new Date(options.nowMs()).toISOString();
@@ -31253,13 +31529,13 @@ function isNonRetryableRuntimeLogError(error2) {
31253
31529
  );
31254
31530
  }
31255
31531
  function getRuntimeLogDir(projectRoot) {
31256
- return path7.join(projectRoot, ".maker", "logs", "runtime");
31532
+ return path8.join(projectRoot, ".maker", "logs", "runtime");
31257
31533
  }
31258
31534
  function getRuntimeLogStatePath(projectRoot) {
31259
- return path7.join(getRuntimeLogDir(projectRoot), "state.json");
31535
+ return path8.join(getRuntimeLogDir(projectRoot), "state.json");
31260
31536
  }
31261
31537
  function getRuntimeLogPath(projectRoot) {
31262
- return path7.join(getRuntimeLogDir(projectRoot), MERGED_RUNTIME_LOG_FILE);
31538
+ return path8.join(getRuntimeLogDir(projectRoot), MERGED_RUNTIME_LOG_FILE);
31263
31539
  }
31264
31540
  function resolveNextRuntimeLogCursor(result) {
31265
31541
  const maxLogTime = result.logs.reduce((max, log) => {
@@ -31384,8 +31660,8 @@ function compactRuntimeLogEntry(entry) {
31384
31660
  }
31385
31661
 
31386
31662
  // src/maker/server/proxyAssets.ts
31387
- import fs7 from "node:fs";
31388
- import path8 from "node:path";
31663
+ import fs8 from "node:fs";
31664
+ import path9 from "node:path";
31389
31665
  var IMAGE_ASSET_DIRS = ["assets/image"];
31390
31666
  var VIDEO_ASSET_DIRS = ["assets/video"];
31391
31667
  var AUDIO_ASSET_DIRS = ["assets/audio"];
@@ -31629,8 +31905,8 @@ async function materializeAsset(options) {
31629
31905
  };
31630
31906
  }
31631
31907
  const bytes = Buffer.from(await response.arrayBuffer());
31632
- fs7.mkdirSync(path8.dirname(absolutePath), { recursive: true });
31633
- fs7.writeFileSync(absolutePath, bytes);
31908
+ fs8.mkdirSync(path9.dirname(absolutePath), { recursive: true });
31909
+ fs8.writeFileSync(absolutePath, bytes);
31634
31910
  return { localPath: relativePath, absolutePath, download: { success: true } };
31635
31911
  } catch (error2) {
31636
31912
  return {
@@ -31644,12 +31920,12 @@ async function materializeAsset(options) {
31644
31920
  function createUniqueAssetPath(options) {
31645
31921
  const stem = `${sanitizeAssetBaseName(options.baseName)}_${formatAssetTimestamp(options.now)}`;
31646
31922
  for (let index = 1; index <= 9999; index += 1) {
31647
- const relativePath = path8.posix.join(
31923
+ const relativePath = path9.posix.join(
31648
31924
  options.relativeDir,
31649
31925
  `${stem}${index === 1 ? "" : `_${index}`}.${options.extension}`
31650
31926
  );
31651
- const absolutePath = path8.join(options.targetDir, ...relativePath.split("/"));
31652
- if (!fs7.existsSync(absolutePath)) {
31927
+ const absolutePath = path9.join(options.targetDir, ...relativePath.split("/"));
31928
+ if (!fs8.existsSync(absolutePath)) {
31653
31929
  return { relativePath, absolutePath };
31654
31930
  }
31655
31931
  }
@@ -31732,7 +32008,7 @@ function findRegistryAssetByName(value, registry2, assetDirs) {
31732
32008
  if (!isKnownAssetPath(localPath, assetDirs)) {
31733
32009
  return false;
31734
32010
  }
31735
- const basename = path8.posix.basename(localPath);
32011
+ const basename = path9.posix.basename(localPath);
31736
32012
  const stem = basename.replace(/\.[^.]+$/, "");
31737
32013
  return basename === value || stem === value || record2.name === value || record2.taskId === value;
31738
32014
  });
@@ -31745,13 +32021,13 @@ function findRegistryAssetByName(value, registry2, assetDirs) {
31745
32021
  }
31746
32022
  function findLocalAssetByName(targetDir, value, assetDirs) {
31747
32023
  var _a3;
31748
- const hasExtension = Boolean(path8.extname(value));
32024
+ const hasExtension = Boolean(path9.extname(value));
31749
32025
  const candidates = [];
31750
32026
  for (const assetDir of assetDirs) {
31751
- const absoluteDir = path8.join(targetDir, ...assetDir.split("/"));
32027
+ const absoluteDir = path9.join(targetDir, ...assetDir.split("/"));
31752
32028
  let entries;
31753
32029
  try {
31754
- entries = fs7.readdirSync(absoluteDir);
32030
+ entries = fs8.readdirSync(absoluteDir);
31755
32031
  } catch {
31756
32032
  continue;
31757
32033
  }
@@ -31760,11 +32036,11 @@ function findLocalAssetByName(targetDir, value, assetDirs) {
31760
32036
  if (hasExtension ? entry !== value : stem !== value && !stem.startsWith(`${value}_`)) {
31761
32037
  continue;
31762
32038
  }
31763
- const absolutePath = path8.join(absoluteDir, entry);
32039
+ const absolutePath = path9.join(absoluteDir, entry);
31764
32040
  try {
31765
32041
  candidates.push({
31766
- localPath: path8.posix.join(assetDir, entry),
31767
- mtimeMs: fs7.statSync(absolutePath).mtimeMs
32042
+ localPath: path9.posix.join(assetDir, entry),
32043
+ mtimeMs: fs8.statSync(absolutePath).mtimeMs
31768
32044
  });
31769
32045
  } catch {
31770
32046
  }
@@ -31774,7 +32050,7 @@ function findLocalAssetByName(targetDir, value, assetDirs) {
31774
32050
  return (_a3 = candidates[0]) == null ? void 0 : _a3.localPath;
31775
32051
  }
31776
32052
  function isKnownAssetPath(relativePath, assetDirs) {
31777
- if (relativePath.startsWith("../") || path8.isAbsolute(relativePath)) {
32053
+ if (relativePath.startsWith("../") || path9.isAbsolute(relativePath)) {
31778
32054
  return false;
31779
32055
  }
31780
32056
  return assetDirs.some(
@@ -31788,31 +32064,31 @@ function upsertGeneratedAssetRecord(targetDir, localPath, record2) {
31788
32064
  const registry2 = readGeneratedAssetRegistry(targetDir);
31789
32065
  registry2[localPath] = record2;
31790
32066
  const registryPath = getGeneratedAssetRegistryPath(targetDir);
31791
- fs7.mkdirSync(path8.dirname(registryPath), { recursive: true });
31792
- fs7.writeFileSync(registryPath, `${JSON.stringify(registry2, null, 2)}
32067
+ fs8.mkdirSync(path9.dirname(registryPath), { recursive: true });
32068
+ fs8.writeFileSync(registryPath, `${JSON.stringify(registry2, null, 2)}
31793
32069
  `, "utf8");
31794
32070
  }
31795
32071
  function readGeneratedAssetRegistry(targetDir) {
31796
32072
  const registryPath = getGeneratedAssetRegistryPath(targetDir);
31797
- if (!fs7.existsSync(registryPath)) {
32073
+ if (!fs8.existsSync(registryPath)) {
31798
32074
  return {};
31799
32075
  }
31800
32076
  try {
31801
- const parsed = JSON.parse(fs7.readFileSync(registryPath, "utf8"));
32077
+ const parsed = JSON.parse(fs8.readFileSync(registryPath, "utf8"));
31802
32078
  return isRecord(parsed) ? parsed : {};
31803
32079
  } catch {
31804
32080
  return {};
31805
32081
  }
31806
32082
  }
31807
32083
  function getGeneratedAssetRegistryPath(targetDir) {
31808
- return path8.join(targetDir, ".maker", "assets", "generated-assets.json");
32084
+ return path9.join(targetDir, ".maker", "assets", "generated-assets.json");
31809
32085
  }
31810
32086
  function normalizeAssetRegistryKey(targetDir, value) {
31811
32087
  if (/^https?:\/\//i.test(value) || value.startsWith("data:")) {
31812
32088
  return void 0;
31813
32089
  }
31814
- const relative = path8.isAbsolute(value) ? path8.relative(targetDir, value) : value;
31815
- return relative.split(path8.sep).join("/");
32090
+ const relative = path9.isAbsolute(value) ? path9.relative(targetDir, value) : value;
32091
+ return relative.split(path9.sep).join("/");
31816
32092
  }
31817
32093
  function isRecord(value) {
31818
32094
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -31841,7 +32117,7 @@ function extensionFromUrl(url2) {
31841
32117
  }
31842
32118
  try {
31843
32119
  const pathname = new URL(url2).pathname;
31844
- const extension = path8.extname(pathname).replace(/^\./, "").toLowerCase();
32120
+ const extension = path9.extname(pathname).replace(/^\./, "").toLowerCase();
31845
32121
  return extension || void 0;
31846
32122
  } catch {
31847
32123
  return void 0;
@@ -31849,7 +32125,7 @@ function extensionFromUrl(url2) {
31849
32125
  }
31850
32126
 
31851
32127
  // src/maker/server/mcp.ts
31852
- var VERSION = true ? "0.0.11" : "dev";
32128
+ var VERSION = true ? "0.0.12" : "dev";
31853
32129
  var DEFAULT_BUILD_TIMEOUT_MS = 10 * 60 * 1e3;
31854
32130
  var DEFAULT_PROXY_RETRY_ATTEMPTS = 5;
31855
32131
  var DEFAULT_PROXY_RETRY_DELAY_MS = 30 * 1e3;
@@ -32204,16 +32480,16 @@ async function startMakerMcpServer() {
32204
32480
  async function formatStatus(options = {}) {
32205
32481
  var _a3;
32206
32482
  const targetDir = resolveMakerToolTargetDir(options.targetDir);
32483
+ const env = getMakerEnvironment(void 0, targetDir);
32207
32484
  const identify = identifyMakerProject({ cwd: targetDir });
32208
32485
  const gitDirectoryStatus = inspectMakerDirectoryGitStatus(targetDir);
32209
32486
  const remoteSyncText = identify.projectRoot && gitDirectoryStatus.isUsableMakerGitRepo && !options.skipRemoteSync ? await formatMakerRemoteSyncStatusSafely(identify.projectRoot) : identify.projectRoot && gitDirectoryStatus.isUsableMakerGitRepo ? formatMakerRemoteSyncSkipped() : "";
32210
32487
  const pat = loadPat();
32211
32488
  let tapAuth = loadTapAuth();
32212
- const makerPatTokensUrl = getMakerPatTokensUrl();
32213
32489
  let tapAuthRefreshText = "";
32214
32490
  if (pat && !tapAuth) {
32215
32491
  try {
32216
- tapAuth = await requestTapAuthWithPat(pat.token);
32492
+ tapAuth = await requestTapAuthWithPat(pat.token, env);
32217
32493
  tapAuthRefreshText = [
32218
32494
  "TapTap token",
32219
32495
  "",
@@ -32238,6 +32514,7 @@ async function formatStatus(options = {}) {
32238
32514
  "TapTap Maker MCP status",
32239
32515
  "",
32240
32516
  `- version: ${VERSION}`,
32517
+ `- env: ${env}`,
32241
32518
  `- tap_auth: ${tapAuth ? "found" : "missing"} (${getTapAuthPath()})`,
32242
32519
  `- pat: ${pat ? "found" : "missing"} (${getPatPath()})`,
32243
32520
  `- target_dir: ${targetDir}`,
@@ -32256,17 +32533,38 @@ async function formatStatus(options = {}) {
32256
32533
  "",
32257
32534
  identify.projectRoot ? await formatMakerProxyToolsStatusSafely({ targetDir: identify.projectRoot }) : "",
32258
32535
  "",
32259
- pat ? "" : ["Auth next step", "", `Maker PAT 缺失。PAT 页面:${makerPatTokensUrl}`].join("\n"),
32536
+ formatAuthNextStep({ hasPat: Boolean(pat), isProjectBound: Boolean(identify.projectRoot) }),
32260
32537
  "",
32261
32538
  tapAuthRefreshText,
32262
32539
  "",
32263
- identify.projectRoot ? await formatAiDevKitStatus(identify.projectRoot) : "",
32540
+ identify.projectRoot ? await formatAiDevKitStatus(identify.projectRoot, {
32541
+ environment: env,
32542
+ skipVersionCheck: options.skipRemoteSync
32543
+ }) : "",
32264
32544
  "",
32265
32545
  formatMakerSkillStatus({ projectRoot: identify.projectRoot || targetDir }),
32266
32546
  "",
32267
32547
  projectSection
32268
32548
  ].filter(Boolean).join("\n");
32269
32549
  }
32550
+ function formatAuthNextStep(options) {
32551
+ if (options.hasPat) {
32552
+ return "";
32553
+ }
32554
+ if (options.isProjectBound) {
32555
+ return [
32556
+ "Auth next step",
32557
+ "",
32558
+ "Maker PAT 缺失。请运行 `taptap-maker login` 刷新登录授权。"
32559
+ ].join("\n");
32560
+ }
32561
+ return [
32562
+ "Initialization next step",
32563
+ "",
32564
+ "当前目录尚未绑定 Maker 项目。请运行 `taptap-maker init`。",
32565
+ "如果缺少 Maker PAT,CLI 会在 init 流程内自动打开登录授权页面并完成本地保存。"
32566
+ ].join("\n");
32567
+ }
32270
32568
  function formatMakerRemoteSyncSkipped() {
32271
32569
  return [
32272
32570
  "Maker remote sync",
@@ -32432,22 +32730,31 @@ function formatAiDialogueDirectoryHint(targetDir) {
32432
32730
  }
32433
32731
  function resolveMakerToolTargetDir(targetDir) {
32434
32732
  if (targetDir) {
32435
- return path9.resolve(targetDir);
32733
+ return path10.resolve(targetDir);
32436
32734
  }
32437
32735
  return process.cwd();
32438
32736
  }
32439
- async function formatAiDevKitStatus(projectRoot) {
32737
+ async function formatAiDevKitStatus(projectRoot, options = {}) {
32440
32738
  const devKitStatus = inspectAiDevKit(projectRoot);
32739
+ const updateStatus = options.skipVersionCheck ? void 0 : await checkAiDevKitUpdate(projectRoot, { environment: options.environment });
32441
32740
  if (devKitStatus.ready) {
32442
- return formatAiDevKitStatusLines("ready", devKitStatus).join("\n");
32741
+ return formatAiDevKitStatusLines("ready", devKitStatus, updateStatus).join("\n");
32443
32742
  }
32444
32743
  return [
32445
- ...formatAiDevKitStatusLines("missing", devKitStatus),
32744
+ ...formatAiDevKitStatusLines("missing", devKitStatus, updateStatus),
32446
32745
  "- next_step: 请运行 taptap-maker dev-kit update,或重新执行 taptap-maker init。"
32447
32746
  ].join("\n");
32448
32747
  }
32449
- function formatAiDevKitStatusLines(status, devKitStatus) {
32748
+ function formatAiDevKitStatusLines(status, devKitStatus, updateStatus) {
32749
+ var _a3, _b;
32450
32750
  const skillStatus = inspectAiDevKitSkillInstallStatus(devKitStatus.targetDir);
32751
+ const versionLines = updateStatus ? [
32752
+ `- installed_version: ${((_a3 = updateStatus.installed) == null ? void 0 : _a3.version) || "(unknown)"}`,
32753
+ `- latest_version: ${((_b = updateStatus.latest) == null ? void 0 : _b.version) || "(unknown)"}`,
32754
+ `- update_available: ${updateStatus.updateAvailable ? "yes" : "no"}`,
32755
+ updateStatus.versionCheckError ? `- version_check: ${updateStatus.versionCheckError}` : "",
32756
+ updateStatus.updateAvailable ? "- next_step: 请运行 taptap-maker dev-kit update。" : ""
32757
+ ].filter(Boolean) : ["- version_check: skipped"];
32451
32758
  return [
32452
32759
  "AI dev kit",
32453
32760
  "",
@@ -32455,6 +32762,7 @@ function formatAiDevKitStatusLines(status, devKitStatus) {
32455
32762
  `- required_entries: ${devKitStatus.requiredEntries.join(", ")}`,
32456
32763
  `- present_entries: ${devKitStatus.presentEntries.join(", ") || "(none)"}`,
32457
32764
  `- missing_entries: ${devKitStatus.missingEntries.join(", ") || "(none)"}`,
32765
+ ...versionLines,
32458
32766
  `- skill_install_status: ${skillStatus.status}`,
32459
32767
  `- skill_install_summary: ${skillStatus.summary}`
32460
32768
  ];
@@ -32473,7 +32781,7 @@ async function formatAutoProjectListFromPat() {
32473
32781
  return [
32474
32782
  "本地已有 Maker PAT,但自动列出 Maker Apps 失败。",
32475
32783
  `原因:${error2 instanceof Error ? error2.message : String(error2)}`,
32476
- `如果 PAT 已失效,请运行 taptap-maker pat set 并粘贴新的 Maker PAT。PAT 页面:${getMakerPatTokensUrl()}`
32784
+ "如果本地鉴权已失效,请运行 `taptap-maker login` 重新完成 Maker 登录授权。"
32477
32785
  ].join("\n");
32478
32786
  }
32479
32787
  }
@@ -32522,14 +32830,14 @@ function formatStatusProjectList(projects) {
32522
32830
  ].filter((line) => line !== void 0).join("\n");
32523
32831
  }
32524
32832
  function formatClonePartialStateLines(targetDir) {
32525
- const resolvedTargetDir = path9.resolve(targetDir);
32833
+ const resolvedTargetDir = path10.resolve(targetDir);
32526
32834
  const identify = identifyMakerProject({ cwd: resolvedTargetDir });
32527
32835
  const gitStatus = inspectMakerDirectoryGitStatus(resolvedTargetDir);
32528
32836
  const devKitStatus = inspectAiDevKit(resolvedTargetDir);
32529
- const stagedDevKitGitignorePath = path9.join(resolvedTargetDir, DEV_KIT_GITIGNORE_STAGING_FILE);
32837
+ const stagedDevKitGitignorePath = path10.join(resolvedTargetDir, DEV_KIT_GITIGNORE_STAGING_FILE);
32530
32838
  const projectBound = Boolean(identify.projectId);
32531
32839
  const gitInitialized = Boolean(
32532
- gitStatus.isOwnGitRoot || fs8.existsSync(path9.join(resolvedTargetDir, ".git"))
32840
+ gitStatus.isOwnGitRoot || fs9.existsSync(path10.join(resolvedTargetDir, ".git"))
32533
32841
  );
32534
32842
  const safeToRetry = !projectBound;
32535
32843
  return [
@@ -32543,7 +32851,7 @@ function formatClonePartialStateLines(targetDir) {
32543
32851
  identify.configPath ? `- config: ${identify.configPath}` : "",
32544
32852
  `- ai_dev_kit_present: ${devKitStatus.ready ? "yes" : "no"}`,
32545
32853
  `- ai_dev_kit_missing_entries: ${devKitStatus.missingEntries.join(", ") || "(none)"}`,
32546
- `- staged_dev_kit_gitignore: ${fs8.existsSync(stagedDevKitGitignorePath) ? "yes" : "no"}`,
32854
+ `- staged_dev_kit_gitignore: ${fs9.existsSync(stagedDevKitGitignorePath) ? "yes" : "no"}`,
32547
32855
  `- safe_to_retry: ${safeToRetry ? "yes" : "no"}`,
32548
32856
  safeToRetry ? "- next_step: 可以直接重试 taptap-maker init;如果连续失败,建议换一个全新的独立目录重新 clone。" : "- next_step: 当前目录已经有 Maker 绑定信息;先运行 taptap-maker doctor 或读取 maker://status 确认状态。"
32549
32857
  ].filter(Boolean);
@@ -32557,9 +32865,10 @@ function createRemoteProxyContext(options) {
32557
32865
  }
32558
32866
  const projectConfig = loadProjectConfig(identify.projectRoot);
32559
32867
  const projectId = (projectConfig == null ? void 0 : projectConfig.project_id) || identify.projectId;
32868
+ const env = getMakerEnvironment(options.env, identify.projectRoot);
32560
32869
  const tapAuth = loadTapAuth();
32561
32870
  if (!tapAuth) {
32562
- throw new Error("Tap auth not found. Run taptap-maker pat set and paste a Maker PAT first.");
32871
+ throw new Error("Tap auth not found. Run `taptap-maker login` first.");
32563
32872
  }
32564
32873
  let userId = projectConfig == null ? void 0 : projectConfig.user_id;
32565
32874
  if (!userId) {
@@ -32571,7 +32880,6 @@ function createRemoteProxyContext(options) {
32571
32880
  "Cannot resolve user_id. Re-run taptap-maker init with PAT so the project config can cache user_id."
32572
32881
  );
32573
32882
  }
32574
- const env = getMakerEnvironment(options.env);
32575
32883
  const serverUrl = options.serverUrl || requireMakerEndpoint("remoteMcpServerUrl", getMakerEndpoints(env).remoteMcpServerUrl, env);
32576
32884
  const projectPath = `${projectId}/workspace`;
32577
32885
  const proxyCfg = {
@@ -32616,7 +32924,7 @@ function resolveEmbeddedProxyCommand(options) {
32616
32924
  }
32617
32925
  return {
32618
32926
  command: process.execPath,
32619
- args: [path9.resolve(makerEntry), "__maker-proxy"]
32927
+ args: [path10.resolve(makerEntry), "__maker-proxy"]
32620
32928
  };
32621
32929
  }
32622
32930
  function createToolProgressReporter(progressToken, extra, operationName) {
@@ -32918,18 +33226,18 @@ async function attachRuntimeLogWatch(buildResult, startWatch) {
32918
33226
  }
32919
33227
  }
32920
33228
  async function startRuntimeLogWatch(buildResult) {
32921
- const runtimeDir = path9.join(buildResult.projectRoot, ".maker", "logs", "runtime");
32922
- fs8.mkdirSync(runtimeDir, { recursive: true });
32923
- const stdoutLog = path9.join(runtimeDir, "watcher.out.log");
32924
- const stderrLog = path9.join(runtimeDir, "watcher.err.log");
32925
- const pidFile = path9.join(runtimeDir, "watcher.pid");
33229
+ const runtimeDir = path10.join(buildResult.projectRoot, ".maker", "logs", "runtime");
33230
+ fs9.mkdirSync(runtimeDir, { recursive: true });
33231
+ const stdoutLog = path10.join(runtimeDir, "watcher.out.log");
33232
+ const stderrLog = path10.join(runtimeDir, "watcher.err.log");
33233
+ const pidFile = path10.join(runtimeDir, "watcher.pid");
32926
33234
  const previous = stopExistingRuntimeLogWatcher(pidFile);
32927
- const outFd = fs8.openSync(stdoutLog, "a");
32928
- const errFd = fs8.openSync(stderrLog, "a");
33235
+ const outFd = fs9.openSync(stdoutLog, "a");
33236
+ const errFd = fs9.openSync(stderrLog, "a");
32929
33237
  const command = formatRuntimeLogWatchCommand(buildResult);
32930
33238
  if (previous.previousStopError) {
32931
- fs8.closeSync(outFd);
32932
- fs8.closeSync(errFd);
33239
+ fs9.closeSync(outFd);
33240
+ fs9.closeSync(errFd);
32933
33241
  return {
32934
33242
  started: false,
32935
33243
  command: command.text,
@@ -32992,18 +33300,18 @@ async function startRuntimeLogWatch(buildResult) {
32992
33300
  ...previous
32993
33301
  };
32994
33302
  } finally {
32995
- fs8.closeSync(outFd);
32996
- fs8.closeSync(errFd);
33303
+ fs9.closeSync(outFd);
33304
+ fs9.closeSync(errFd);
32997
33305
  }
32998
33306
  }
32999
33307
  function stopExistingRuntimeLogWatcher(pidFile, options = {}) {
33000
- if (!fs8.existsSync(pidFile)) {
33308
+ if (!fs9.existsSync(pidFile)) {
33001
33309
  return {};
33002
33310
  }
33003
33311
  const pidState = readRuntimeLogWatcherPidState(pidFile);
33004
33312
  const pid = pidState == null ? void 0 : pidState.pid;
33005
33313
  if (!Number.isInteger(pid) || pid <= 0) {
33006
- fs8.rmSync(pidFile, { force: true });
33314
+ fs9.rmSync(pidFile, { force: true });
33007
33315
  return {};
33008
33316
  }
33009
33317
  try {
@@ -33011,7 +33319,7 @@ function stopExistingRuntimeLogWatcher(pidFile, options = {}) {
33011
33319
  const processCommand = (options.getProcessCommand || getProcessCommand)(pid);
33012
33320
  const verifiedCommand = getVerifiedRuntimeLogWatcherCommand(processCommand, pidState);
33013
33321
  if (!verifiedCommand) {
33014
- fs8.rmSync(pidFile, { force: true });
33322
+ fs9.rmSync(pidFile, { force: true });
33015
33323
  return {
33016
33324
  previousPid: pid,
33017
33325
  previousStopped: false,
@@ -33021,7 +33329,7 @@ function stopExistingRuntimeLogWatcher(pidFile, options = {}) {
33021
33329
  process.kill(pid, "SIGTERM");
33022
33330
  const stopped = (options.waitForExit || waitForProcessExit)(pid, WATCHER_STOP_TIMEOUT_MS);
33023
33331
  if (stopped) {
33024
- fs8.rmSync(pidFile, { force: true });
33332
+ fs9.rmSync(pidFile, { force: true });
33025
33333
  return { previousPid: pid, previousStopped: true };
33026
33334
  }
33027
33335
  return {
@@ -33030,7 +33338,7 @@ function stopExistingRuntimeLogWatcher(pidFile, options = {}) {
33030
33338
  previousStopError: `process ${pid} did not exit after SIGTERM within ${WATCHER_STOP_TIMEOUT_MS}ms`
33031
33339
  };
33032
33340
  } catch (error2) {
33033
- fs8.rmSync(pidFile, { force: true });
33341
+ fs9.rmSync(pidFile, { force: true });
33034
33342
  const code = error2 && typeof error2 === "object" && "code" in error2 ? String(error2.code) : "";
33035
33343
  if (code === "ESRCH") {
33036
33344
  return { previousPid: pid, previousStopped: false };
@@ -33043,7 +33351,7 @@ function stopExistingRuntimeLogWatcher(pidFile, options = {}) {
33043
33351
  }
33044
33352
  }
33045
33353
  function readRuntimeLogWatcherPidState(pidFile) {
33046
- const raw = fs8.readFileSync(pidFile, "utf8").trim();
33354
+ const raw = fs9.readFileSync(pidFile, "utf8").trim();
33047
33355
  if (!raw) {
33048
33356
  return null;
33049
33357
  }
@@ -33059,7 +33367,7 @@ function readRuntimeLogWatcherPidState(pidFile) {
33059
33367
  }
33060
33368
  }
33061
33369
  function writeRuntimeLogWatcherPidFile(pidFile, state) {
33062
- fs8.writeFileSync(pidFile, `${JSON.stringify(state, null, 2)}
33370
+ fs9.writeFileSync(pidFile, `${JSON.stringify(state, null, 2)}
33063
33371
  `, "utf8");
33064
33372
  }
33065
33373
  function getProcessCommand(pid) {
@@ -33145,10 +33453,10 @@ function formatRuntimeLogWatchCommand(buildResult) {
33145
33453
  };
33146
33454
  }
33147
33455
  function resolveMakerCliEntry() {
33148
- return process.argv[1] || path9.resolve(process.cwd(), "dist", "maker.js");
33456
+ return process.argv[1] || path10.resolve(process.cwd(), "dist", "maker.js");
33149
33457
  }
33150
33458
  function getRuntimeLogFilePath(projectRoot) {
33151
- return path9.join(projectRoot, ".maker", "logs", "runtime", "runtime.log");
33459
+ return path10.join(projectRoot, ".maker", "logs", "runtime", "runtime.log");
33152
33460
  }
33153
33461
  async function refreshMakerPreview(buildResult) {
33154
33462
  const makerEnv = buildResult.env === "rnd" || buildResult.env === "production" ? buildResult.env : void 0;
@@ -33162,7 +33470,7 @@ async function refreshMakerPreview(buildResult) {
33162
33470
  ok: false,
33163
33471
  status: 0,
33164
33472
  url: url2,
33165
- error: "Maker PAT not found. Run taptap-maker pat set and paste a Maker PAT first."
33473
+ error: "Maker PAT not found. Run `taptap-maker login` first."
33166
33474
  };
33167
33475
  }
33168
33476
  const controller = new AbortController();
@@ -33279,7 +33587,7 @@ function createBuildArgs(projectRoot, options) {
33279
33587
  if (options.scriptsPath) {
33280
33588
  buildArgs.scriptsPath = options.scriptsPath;
33281
33589
  }
33282
- if (!options.entry && !options.scriptsPath && !options.entryClient && !options.entryServer && !options.multiplayer && fs8.existsSync(path9.join(projectRoot, "scripts", "main.lua"))) {
33590
+ if (!options.entry && !options.scriptsPath && !options.entryClient && !options.entryServer && !options.multiplayer && fs9.existsSync(path10.join(projectRoot, "scripts", "main.lua"))) {
33283
33591
  buildArgs.entry = "main.lua";
33284
33592
  buildArgs.scriptsPath = "scripts";
33285
33593
  }
@@ -33291,7 +33599,7 @@ function createBuildArgs(projectRoot, options) {
33291
33599
  }
33292
33600
  if (options.multiplayer) {
33293
33601
  buildArgs.multiplayer = options.multiplayer;
33294
- } else if (!fs8.existsSync(path9.join(projectRoot, ".project", "settings.json"))) {
33602
+ } else if (!fs9.existsSync(path10.join(projectRoot, ".project", "settings.json"))) {
33295
33603
  buildArgs.multiplayer = { enabled: false };
33296
33604
  }
33297
33605
  return buildArgs;
@@ -33453,11 +33761,11 @@ function formatRuntimeLogWatchNextActionLines(result) {
33453
33761
  ((_a3 = result.runtimeLogWatch) == null ? void 0 : _a3.pid) ? `- watch_pid: ${result.runtimeLogWatch.pid}` : "",
33454
33762
  `- watch_command: ${command}`,
33455
33763
  ((_b = result.runtimeLogWatch) == null ? void 0 : _b.command) ? `- actual_watch_command: ${result.runtimeLogWatch.command}` : "",
33456
- `- local_file: ${path9.join(result.projectRoot, ".maker", "logs", "runtime", "runtime.log")}`,
33764
+ `- local_file: ${path10.join(result.projectRoot, ".maker", "logs", "runtime", "runtime.log")}`,
33457
33765
  ((_c = result.runtimeLogWatch) == null ? void 0 : _c.stdoutLog) ? `- watcher_stdout: ${result.runtimeLogWatch.stdoutLog}` : "",
33458
33766
  ((_d = result.runtimeLogWatch) == null ? void 0 : _d.stderrLog) ? `- watcher_stderr: ${result.runtimeLogWatch.stderrLog}` : "",
33459
33767
  ((_e = result.runtimeLogWatch) == null ? void 0 : _e.pidFile) ? `- watcher_pid_file: ${result.runtimeLogWatch.pidFile}` : "",
33460
- `- state_file: ${path9.join(result.projectRoot, ".maker", "logs", "runtime", "state.json")}`,
33768
+ `- state_file: ${path10.join(result.projectRoot, ".maker", "logs", "runtime", "state.json")}`,
33461
33769
  ((_f = result.runtimeLogWatch) == null ? void 0 : _f.previousPid) ? `- previous_watch_pid: ${result.runtimeLogWatch.previousPid}` : "",
33462
33770
  ((_g = result.runtimeLogWatch) == null ? void 0 : _g.previousStopped) !== void 0 ? `- previous_watch_stopped: ${result.runtimeLogWatch.previousStopped ? "yes" : "no"}` : "",
33463
33771
  ((_h = result.runtimeLogWatch) == null ? void 0 : _h.previousStopError) ? `- previous_watch_stop_error: ${result.runtimeLogWatch.previousStopError}` : "",
@@ -33572,13 +33880,156 @@ function indent(value) {
33572
33880
  }
33573
33881
 
33574
33882
  // src/maker/cli/commands.ts
33575
- import { spawnSync as spawnSync4 } from "node:child_process";
33576
- import crypto from "node:crypto";
33577
- import fs9 from "node:fs";
33883
+ import { spawnSync as spawnSync5 } from "node:child_process";
33884
+ import crypto2 from "node:crypto";
33885
+ import fs10 from "node:fs";
33578
33886
  import os4 from "node:os";
33579
- import path10 from "node:path";
33887
+ import path11 from "node:path";
33580
33888
  import readline from "node:readline/promises";
33581
33889
  import { stdin as input, stdout as output } from "node:process";
33890
+
33891
+ // src/maker/auth/cliLogin.ts
33892
+ import { spawnSync as spawnSync4 } from "node:child_process";
33893
+ import crypto from "node:crypto";
33894
+ var DEFAULT_TIMEOUT_MS = 10 * 60 * 1e3;
33895
+ var DEFAULT_POLL_INTERVAL_MS = 1e3;
33896
+ function createCliLoginCode() {
33897
+ return crypto.randomBytes(24).toString("base64url");
33898
+ }
33899
+ function getMakerCliLoginUrl(code, env) {
33900
+ const url2 = new URL("/pat-tokens", getMakerWebUrl(env));
33901
+ url2.searchParams.set("code", code);
33902
+ return url2.toString();
33903
+ }
33904
+ function getMakerCliLoginResultUrl(code, env) {
33905
+ const url2 = new URL("cli-auth/result", `${getMakerApiBaseUrl(env)}/`);
33906
+ url2.searchParams.set("code", code);
33907
+ return url2.toString();
33908
+ }
33909
+ async function loginWithCliAuthCode(options = {}) {
33910
+ var _a3;
33911
+ const env = options.env || getMakerEnvironment();
33912
+ const code = createCliLoginCode();
33913
+ const authUrl = getMakerCliLoginUrl(code, env);
33914
+ (_a3 = options.onStatus) == null ? void 0 : _a3.call(
33915
+ options,
33916
+ `Opening Maker PAT page: ${authUrl}
33917
+ 请在页面登录并点击“创建 token”,CLI 会继续等待授权结果。`
33918
+ );
33919
+ if (options.openBrowser !== false) {
33920
+ openBrowser(authUrl);
33921
+ }
33922
+ const pat = await pollCliLoginResult(code, {
33923
+ ...options,
33924
+ env
33925
+ });
33926
+ return {
33927
+ ...pat,
33928
+ code,
33929
+ auth_url: authUrl
33930
+ };
33931
+ }
33932
+ async function pollCliLoginResult(code, options) {
33933
+ const fetchImpl = options.fetchImpl || fetch;
33934
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
33935
+ const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
33936
+ const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_SHORT_FETCH_TIMEOUT_MS;
33937
+ const deadline = Date.now() + timeoutMs;
33938
+ const resultUrl = getMakerCliLoginResultUrl(code, options.env);
33939
+ let lastPollError;
33940
+ for (; ; ) {
33941
+ if (Date.now() >= deadline) {
33942
+ const suffix = lastPollError ? ` Last polling error: ${formatError2(lastPollError)}` : "";
33943
+ throw new Error(
33944
+ `Maker CLI login timed out. Run \`taptap-maker login\` and try again.${suffix}`
33945
+ );
33946
+ }
33947
+ let response;
33948
+ try {
33949
+ response = await fetchWithTimeout(
33950
+ fetchImpl,
33951
+ resultUrl,
33952
+ {
33953
+ headers: {
33954
+ Accept: "application/json"
33955
+ }
33956
+ },
33957
+ Math.min(requestTimeoutMs, Math.max(1, deadline - Date.now())),
33958
+ "Maker CLI login poll"
33959
+ );
33960
+ } catch (error2) {
33961
+ lastPollError = error2;
33962
+ await delay(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
33963
+ continue;
33964
+ }
33965
+ const json2 = await readJsonResponse(response);
33966
+ if (!response.ok) {
33967
+ throw new Error(
33968
+ `Maker CLI login poll failed: HTTP ${response.status} ${JSON.stringify(json2)}`
33969
+ );
33970
+ }
33971
+ const normalized = normalizePollResponse(json2);
33972
+ if (normalized.status === "authorized") {
33973
+ if (!normalized.token) {
33974
+ throw new Error("Maker CLI login result does not contain PAT token.");
33975
+ }
33976
+ return {
33977
+ token: normalized.token,
33978
+ expires_at: normalized.expires_at,
33979
+ raw: json2
33980
+ };
33981
+ }
33982
+ if (normalized.status === "expired" || normalized.status === "consumed") {
33983
+ throw new Error(`Maker CLI login ${normalized.status}. Run \`taptap-maker login\` again.`);
33984
+ }
33985
+ await delay(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
33986
+ }
33987
+ }
33988
+ function normalizePollResponse(data) {
33989
+ const source = data.data || data;
33990
+ const token = source.pat || source.token || source.access_token;
33991
+ return {
33992
+ status: source.status || data.status || (token ? "authorized" : "pending"),
33993
+ token,
33994
+ expires_at: source.expires_at
33995
+ };
33996
+ }
33997
+ async function readJsonResponse(response) {
33998
+ const text = await response.text();
33999
+ if (!text) {
34000
+ return {};
34001
+ }
34002
+ try {
34003
+ return JSON.parse(text);
34004
+ } catch {
34005
+ return { error: text };
34006
+ }
34007
+ }
34008
+ function openBrowser(url2) {
34009
+ const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
34010
+ const args = process.platform === "win32" ? ["/c", "start", "", url2] : [url2];
34011
+ const result = spawnSync4(command, args, {
34012
+ stdio: "ignore",
34013
+ windowsHide: true
34014
+ });
34015
+ if (result.error || result.status !== 0) {
34016
+ process.stderr.write(
34017
+ `Open this Maker PAT URL in your browser, then log in and click "创建 token":
34018
+ ${url2}
34019
+ `
34020
+ );
34021
+ }
34022
+ }
34023
+ function delay(ms) {
34024
+ return new Promise((resolve) => {
34025
+ setTimeout(resolve, ms);
34026
+ });
34027
+ }
34028
+ function formatError2(error2) {
34029
+ return error2 instanceof Error ? error2.message : String(error2);
34030
+ }
34031
+
34032
+ // src/maker/cli/commands.ts
33582
34033
  var DEFAULT_MCP_NAME = "taptap-maker";
33583
34034
  var MAKER_NPM_PACKAGE = "@taptap/maker";
33584
34035
  var TWO_PART_COMMANDS = /* @__PURE__ */ new Set(["pat", "mcp", "dev-kit", "logs"]);
@@ -33596,6 +34047,7 @@ var BOOLEAN_OPTIONS = /* @__PURE__ */ new Set([
33596
34047
  var PAT_ARG_WARNING = "Warning: passing Maker PAT via command-line arguments exposes it via ps/shell history; prefer the interactive prompt or --pat-stdin.\n";
33597
34048
  async function runMakerCli(argv) {
33598
34049
  const parsed = parseArgs(argv);
34050
+ setMakerEnvironmentOverride(makerEnvOption(parsed));
33599
34051
  const ctx = { json: Boolean(parsed.options.json) };
33600
34052
  const [command, subcommand] = parsed.command;
33601
34053
  if (!command || command === "help" || command === "--help" || command === "-h") {
@@ -33614,6 +34066,10 @@ async function runMakerCli(argv) {
33614
34066
  await runApps(parsed, ctx);
33615
34067
  return;
33616
34068
  }
34069
+ if (command === "login") {
34070
+ await runLogin(parsed, ctx);
34071
+ return;
34072
+ }
33617
34073
  if (command === "pat" && subcommand === "set") {
33618
34074
  await runPatSet(parsed, ctx);
33619
34075
  return;
@@ -33687,7 +34143,7 @@ function toOptionKey(value) {
33687
34143
  }
33688
34144
  async function runInit(parsed, ctx) {
33689
34145
  rejectPackageOption(parsed);
33690
- const targetDir = path10.resolve(stringOption(parsed, "target_dir") || process.cwd());
34146
+ const targetDir = path11.resolve(stringOption(parsed, "target_dir") || process.cwd());
33691
34147
  const env = makerEnvOption(parsed);
33692
34148
  const skipConfirm = booleanOption(parsed, "skip_confirm");
33693
34149
  const skipMcpInstall = booleanOption(parsed, "skip_mcp_install");
@@ -33704,7 +34160,7 @@ async function runInit(parsed, ctx) {
33704
34160
  emit(ctx, "doctor", "Git is available", { version: git.version });
33705
34161
  const pat = await resolvePat(parsed, ctx);
33706
34162
  emit(ctx, "pat", "Maker PAT ready", { saved: getPatPath() });
33707
- const tapAuth = await requestTapAuthWithPat(pat).catch((error2) => {
34163
+ const tapAuth = await requestTapAuthWithPat(pat, env).catch((error2) => {
33708
34164
  throw appendPatRecoveryUrl(error2, parsed);
33709
34165
  });
33710
34166
  emit(ctx, "tap_auth", "TapTap token exchanged and saved", {
@@ -33749,7 +34205,8 @@ async function runInit(parsed, ctx) {
33749
34205
  emit(ctx, "clone", "Maker project cloned or fetched", cloneResult);
33750
34206
  await prepareDevKit(targetDir, ctx, {
33751
34207
  finalizeGitignore: true,
33752
- forceInstall: true
34208
+ forceInstall: true,
34209
+ environment: env
33753
34210
  });
33754
34211
  if (!skipMcpInstall) {
33755
34212
  const ides = parseIdeList(stringOption(parsed, "register_mcp") || "codex,cursor,claude");
@@ -33776,27 +34233,35 @@ async function runInit(parsed, ctx) {
33776
34233
  });
33777
34234
  }
33778
34235
  async function runDoctor(parsed, ctx) {
33779
- const targetDir = path10.resolve(stringOption(parsed, "target_dir") || process.cwd());
34236
+ var _a3, _b;
34237
+ const targetDir = path11.resolve(stringOption(parsed, "target_dir") || process.cwd());
34238
+ const env = makerEnvOption(parsed);
33780
34239
  const git = checkGitEnvironment();
33781
34240
  const pat = loadPat();
33782
34241
  const tapAuth = loadTapAuth();
33783
34242
  const identify = identifyMakerProject({ cwd: targetDir });
33784
- const devKit = inspectAiDevKit(identify.projectRoot || targetDir);
34243
+ const isProjectBound = Boolean(identify.projectRoot);
34244
+ const projectRoot = identify.projectRoot || targetDir;
34245
+ const devKit = inspectAiDevKit(projectRoot);
34246
+ const devKitUpdate = await checkAiDevKitUpdate(projectRoot, { environment: env });
33785
34247
  if (ctx.json) {
33786
34248
  writeJson({
34249
+ env,
33787
34250
  git,
33788
34251
  auth: {
33789
34252
  pat: Boolean(pat),
33790
34253
  tap_auth: Boolean(tapAuth)
33791
34254
  },
33792
34255
  project: identify,
33793
- dev_kit: devKit
34256
+ dev_kit: devKit,
34257
+ dev_kit_update: devKitUpdate
33794
34258
  });
33795
34259
  return;
33796
34260
  }
33797
34261
  process.stdout.write(
33798
34262
  [
33799
34263
  "TapTap Maker doctor",
34264
+ `env: ${env}`,
33800
34265
  "",
33801
34266
  "Git",
33802
34267
  formatGitEnvironmentStatus(git),
@@ -33804,7 +34269,7 @@ async function runDoctor(parsed, ctx) {
33804
34269
  "Auth",
33805
34270
  `- pat: ${pat ? "found" : "missing"} (${getPatPath()})`,
33806
34271
  `- tap_auth: ${tapAuth ? "found" : "missing"} (${getTapAuthPath()})`,
33807
- pat ? "" : `- pat_page: ${getMakerPatTokensUrl(makerEnvOption(parsed))}`,
34272
+ pat ? "" : isProjectBound ? "- next_auth_step: taptap-maker login" : "- next_step: taptap-maker init",
33808
34273
  "",
33809
34274
  "Project",
33810
34275
  `- target_dir: ${targetDir}`,
@@ -33814,8 +34279,12 @@ async function runDoctor(parsed, ctx) {
33814
34279
  "AI dev kit",
33815
34280
  `- ready: ${devKit.ready ? "yes" : "no"}`,
33816
34281
  `- missing_entries: ${devKit.missingEntries.join(", ") || "(none)"}`,
34282
+ `- installed_version: ${((_a3 = devKitUpdate.installed) == null ? void 0 : _a3.version) || "(unknown)"}`,
34283
+ `- latest_version: ${((_b = devKitUpdate.latest) == null ? void 0 : _b.version) || "(unknown)"}`,
34284
+ `- update_available: ${devKitUpdate.updateAvailable ? "yes" : "no"}`,
34285
+ devKitUpdate.versionCheckError ? `- version_check: ${devKitUpdate.versionCheckError}` : "",
33817
34286
  "",
33818
- formatMakerSkillStatus({ projectRoot: identify.projectRoot || targetDir }),
34287
+ formatMakerSkillStatus({ projectRoot }),
33819
34288
  ""
33820
34289
  ].filter(Boolean).join("\n")
33821
34290
  );
@@ -33837,10 +34306,29 @@ async function runApps(parsed, ctx) {
33837
34306
  process.stdout.write(`${formatMakerProjectList(projects, { showAll })}
33838
34307
  `);
33839
34308
  }
34309
+ async function runLogin(parsed, ctx) {
34310
+ const env = makerEnvOption(parsed);
34311
+ const pat = await loginWithCliAuthCode({
34312
+ env,
34313
+ onStatus: (message) => emit(ctx, "login", message)
34314
+ });
34315
+ saveManualMakerPat(pat.token);
34316
+ const tapAuth = await requestTapAuthWithPat(pat.token, env).catch((error2) => {
34317
+ throw appendPatRecoveryUrl(error2, parsed);
34318
+ });
34319
+ emit(ctx, "login", "Maker CLI login completed", {
34320
+ env,
34321
+ code: pat.code,
34322
+ pat_path: getPatPath(),
34323
+ tap_auth_path: getTapAuthPath(),
34324
+ kid: mask(tapAuth.kid)
34325
+ });
34326
+ }
33840
34327
  async function runPatSet(parsed, ctx) {
33841
34328
  const pat = await resolvePatSet(parsed, ctx);
33842
34329
  saveManualMakerPat(pat);
33843
- const tapAuth = await requestTapAuthWithPat(pat).catch((error2) => {
34330
+ const env = makerEnvOption(parsed);
34331
+ const tapAuth = await requestTapAuthWithPat(pat, env).catch((error2) => {
33844
34332
  throw appendPatRecoveryUrl(error2, parsed);
33845
34333
  });
33846
34334
  emit(ctx, "pat", "Maker PAT and TapTap token saved", {
@@ -33851,7 +34339,7 @@ async function runPatSet(parsed, ctx) {
33851
34339
  }
33852
34340
  async function resolvePatSet(parsed, ctx) {
33853
34341
  if (booleanOption(parsed, "pat_stdin") || booleanOption(parsed, "pat_from_stdin")) {
33854
- const pat = fs9.readFileSync(0, "utf8").trim();
34342
+ const pat = fs10.readFileSync(0, "utf8").trim();
33855
34343
  if (!pat) {
33856
34344
  throw new Error("No PAT found on stdin.");
33857
34345
  }
@@ -33864,10 +34352,13 @@ async function resolvePatSet(parsed, ctx) {
33864
34352
  return fromPositional || fromOption;
33865
34353
  }
33866
34354
  if (!ctx.json) {
33867
- process.stdout.write(`Create one at: ${getMakerPatTokensUrl(makerEnvOption(parsed))}
33868
- `);
34355
+ process.stdout.write("Starting Maker CLI login...\n");
33869
34356
  }
33870
- return promptRequired("PAT");
34357
+ const result = await loginWithCliAuthCode({
34358
+ env: makerEnvOption(parsed),
34359
+ onStatus: (message) => emit(ctx, "login", message)
34360
+ });
34361
+ return result.token;
33871
34362
  }
33872
34363
  async function runMcpInstall(parsed, ctx) {
33873
34364
  rejectPackageOption(parsed);
@@ -33890,7 +34381,7 @@ async function runMcpVerify(parsed, ctx) {
33890
34381
  rejectPackageOption(parsed);
33891
34382
  const mode = mcpVerifyModeOption(parsed);
33892
34383
  const command = mode === "npx" ? getNpxCliCommand(MAKER_NPM_PACKAGE) : getCurrentCliCommand();
33893
- const result = spawnSync4(command.command, [...command.args, "help"], {
34384
+ const result = spawnSync5(command.command, [...command.args, "help"], {
33894
34385
  encoding: "utf8"
33895
34386
  });
33896
34387
  const failureType = classifyMcpVerifyFailure(result);
@@ -33979,17 +34470,19 @@ function getMcpVerifyNextSteps(mode, commandText) {
33979
34470
  ];
33980
34471
  }
33981
34472
  async function runDevKitUpdate(parsed, ctx) {
33982
- const targetDir = path10.resolve(stringOption(parsed, "target_dir") || process.cwd());
34473
+ const targetDir = path11.resolve(stringOption(parsed, "target_dir") || process.cwd());
33983
34474
  const result = await installAiDevKit({
33984
34475
  targetDir,
33985
- preserveExisting: true
34476
+ preserveExisting: false,
34477
+ replaceManagedEntries: true,
34478
+ environment: makerEnvOption(parsed)
33986
34479
  });
33987
34480
  finalizeStagedDevKitGitignore(targetDir);
33988
34481
  emit(ctx, "dev_kit", formatDevKitInstallMessage("AI dev kit updated", result), result);
33989
34482
  emitDevKitSkillInstallerFailure(ctx, result.skillInstaller, "AI skills install failed");
33990
34483
  }
33991
34484
  async function runLogsWatch(parsed, ctx) {
33992
- const targetDir = path10.resolve(stringOption(parsed, "target_dir") || process.cwd());
34485
+ const targetDir = path11.resolve(stringOption(parsed, "target_dir") || process.cwd());
33993
34486
  const intervalMs = parseDurationMs(stringOption(parsed, "interval") || "5s");
33994
34487
  const timeoutMs = numberOption(parsed, "timeout_ms") ?? 60 * 1e3;
33995
34488
  const maxPolls = numberOption(parsed, "max_polls");
@@ -33999,9 +34492,9 @@ async function runLogsWatch(parsed, ctx) {
33999
34492
  serverUrl: stringOption(parsed, "server_url"),
34000
34493
  env: makerEnvOption(parsed)
34001
34494
  });
34002
- const runtimeDir = path10.join(proxy.projectRoot, ".maker", "logs", "runtime");
34003
- const runtimeLog = path10.join(runtimeDir, "runtime.log");
34004
- const pidFile = path10.join(runtimeDir, "watcher.pid");
34495
+ const runtimeDir = path11.join(proxy.projectRoot, ".maker", "logs", "runtime");
34496
+ const runtimeLog = path11.join(runtimeDir, "runtime.log");
34497
+ const pidFile = path11.join(runtimeDir, "watcher.pid");
34005
34498
  const replacedWatcher = registerRuntimeLogWatcherProcess(pidFile);
34006
34499
  const runtimeLogClient = createRemoteRuntimeLogClient(proxy, timeoutMs);
34007
34500
  emit(ctx, "logs_watch_start", "Maker runtime log watcher started", {
@@ -34046,10 +34539,10 @@ async function runLogsWatch(parsed, ctx) {
34046
34539
  }
34047
34540
  }
34048
34541
  function registerRuntimeLogWatcherProcess(pidFile) {
34049
- fs9.mkdirSync(path10.dirname(pidFile), { recursive: true });
34542
+ fs10.mkdirSync(path11.dirname(pidFile), { recursive: true });
34050
34543
  const existingPid = readPidFile(pidFile);
34051
34544
  const previous = existingPid && existingPid !== process.pid ? stopExistingRuntimeLogWatcher(pidFile) : {};
34052
- fs9.writeFileSync(
34545
+ fs10.writeFileSync(
34053
34546
  pidFile,
34054
34547
  `${JSON.stringify(
34055
34548
  {
@@ -34067,10 +34560,10 @@ function registerRuntimeLogWatcherProcess(pidFile) {
34067
34560
  return previous;
34068
34561
  }
34069
34562
  function readPidFile(pidFile) {
34070
- if (!fs9.existsSync(pidFile)) {
34563
+ if (!fs10.existsSync(pidFile)) {
34071
34564
  return void 0;
34072
34565
  }
34073
- const raw = fs9.readFileSync(pidFile, "utf8").trim();
34566
+ const raw = fs10.readFileSync(pidFile, "utf8").trim();
34074
34567
  let pid = Number(raw);
34075
34568
  if (!Number.isInteger(pid) || pid <= 0) {
34076
34569
  try {
@@ -34090,7 +34583,7 @@ function installRuntimeLogWatcherPidCleanup(pidFile) {
34090
34583
  }
34091
34584
  cleaned = true;
34092
34585
  if (readPidFile(pidFile) === process.pid) {
34093
- fs9.rmSync(pidFile, { force: true });
34586
+ fs10.rmSync(pidFile, { force: true });
34094
34587
  }
34095
34588
  };
34096
34589
  process.once("exit", cleanup);
@@ -34114,18 +34607,20 @@ async function resolvePat(parsed, ctx) {
34114
34607
  }
34115
34608
  if (booleanOption(parsed, "skip_confirm")) {
34116
34609
  throw new Error(
34117
- `Maker PAT missing. Create one at ${getMakerPatTokensUrl(makerEnvOption(parsed))}`
34610
+ "Maker PAT missing. Run `taptap-maker login` or provide --pat/MAKER_PAT for non-interactive init."
34118
34611
  );
34119
34612
  }
34120
- const patPage = getMakerPatTokensUrl(makerEnvOption(parsed));
34121
- emit(ctx, "pat_required", "Maker PAT is required", {
34122
- pat_page: patPage
34613
+ emit(ctx, "pat_required", "Maker login is required", {
34614
+ next_step: "taptap-maker login"
34123
34615
  });
34124
34616
  if (!ctx.json) {
34125
- process.stdout.write(`Create one at: ${patPage}
34126
- `);
34617
+ process.stdout.write("Starting Maker CLI login...\n");
34127
34618
  }
34128
- const pat = await promptRequired("Paste Maker PAT");
34619
+ const loginResult = await loginWithCliAuthCode({
34620
+ env: makerEnvOption(parsed),
34621
+ onStatus: (message) => emit(ctx, "login", message)
34622
+ });
34623
+ const pat = loginResult.token;
34129
34624
  saveManualMakerPat(pat);
34130
34625
  return pat;
34131
34626
  }
@@ -34197,7 +34692,7 @@ async function prepareDevKit(targetDir, ctx, options = {}) {
34197
34692
  onStart: (event) => emitSkillInstallerStart(ctx, event)
34198
34693
  });
34199
34694
  writeDevKitStagedGitignore(
34200
- path10.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE),
34695
+ path11.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE),
34201
34696
  listPresentDevKitManagedEntries(targetDir)
34202
34697
  );
34203
34698
  if (options.finalizeGitignore) {
@@ -34214,7 +34709,7 @@ async function prepareDevKit(targetDir, ctx, options = {}) {
34214
34709
  );
34215
34710
  } catch (error2) {
34216
34711
  writeDevKitStagedGitignore(
34217
- path10.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE),
34712
+ path11.join(targetDir, DEV_KIT_GITIGNORE_STAGING_FILE),
34218
34713
  listPresentDevKitManagedEntries(targetDir)
34219
34714
  );
34220
34715
  if (options.finalizeGitignore) {
@@ -34232,6 +34727,7 @@ ${detail}`, {
34232
34727
  const result = await installAiDevKit({
34233
34728
  targetDir,
34234
34729
  preserveExisting: options.preserveExisting,
34730
+ environment: options.environment,
34235
34731
  onSkillInstallerStart: (event) => emitSkillInstallerStart(ctx, event)
34236
34732
  });
34237
34733
  if (options.finalizeGitignore) {
@@ -34271,19 +34767,13 @@ ${detail}`, {
34271
34767
  error: detail
34272
34768
  });
34273
34769
  }
34274
- function appendPatRecoveryUrl(error2, parsed) {
34770
+ function appendPatRecoveryUrl(error2, _parsed) {
34275
34771
  const message = error2 instanceof Error ? error2.message : String(error2);
34276
- if (!isPatValidationFailure(message) || message.includes("/pat-tokens")) {
34772
+ if (!isPatValidationFailure(message)) {
34277
34773
  return error2 instanceof Error ? error2 : new Error(message);
34278
34774
  }
34279
- const patPage = getMakerPatTokensUrl(makerEnvOption(parsed));
34280
34775
  return new Error(
34281
- [
34282
- message,
34283
- "",
34284
- `PAT 页面:${patPage}`,
34285
- "请在该页面创建新的 Maker PAT,然后运行 `taptap-maker pat set` 并粘贴 PAT。"
34286
- ].join("\n")
34776
+ [message, "", "请运行 `taptap-maker login` 重新完成 Maker CLI 登录授权。"].join("\n")
34287
34777
  );
34288
34778
  }
34289
34779
  function isPatValidationFailure(message) {
@@ -34307,7 +34797,7 @@ function installMcpConfig(ide, options) {
34307
34797
  }
34308
34798
  function installMcpConfigUnsafe(ide, options) {
34309
34799
  if (ide === "codex") {
34310
- const configPath = path10.join(os4.homedir(), ".codex", "config.toml");
34800
+ const configPath = path11.join(os4.homedir(), ".codex", "config.toml");
34311
34801
  mergeCodexMcpConfig(configPath, options);
34312
34802
  return {
34313
34803
  ide,
@@ -34317,7 +34807,7 @@ function installMcpConfigUnsafe(ide, options) {
34317
34807
  };
34318
34808
  }
34319
34809
  if (ide === "cursor") {
34320
- const configPath = path10.join(os4.homedir(), ".cursor", "mcp.json");
34810
+ const configPath = path11.join(os4.homedir(), ".cursor", "mcp.json");
34321
34811
  mergeJsonMcpConfig(configPath, options);
34322
34812
  return {
34323
34813
  ide,
@@ -34331,7 +34821,7 @@ function installMcpConfigUnsafe(ide, options) {
34331
34821
  if (claudeResult.ok) {
34332
34822
  return { ide, ok: true, message: "✓ Claude Code MCP config updated with claude mcp add" };
34333
34823
  }
34334
- const configPath = path10.join(os4.homedir(), ".claude.json");
34824
+ const configPath = path11.join(os4.homedir(), ".claude.json");
34335
34825
  mergeJsonMcpConfig(configPath, options);
34336
34826
  return {
34337
34827
  ide,
@@ -34348,13 +34838,13 @@ function mergeJsonMcpConfig(configPath, options) {
34348
34838
  const mcpServers = asObject(existing.mcpServers);
34349
34839
  mcpServers[options.mcpName] = createJsonMcpServerConfig(options);
34350
34840
  existing.mcpServers = mcpServers;
34351
- fs9.mkdirSync(path10.dirname(configPath), { recursive: true });
34352
- fs9.writeFileSync(configPath, `${JSON.stringify(existing, null, 2)}
34841
+ fs10.mkdirSync(path11.dirname(configPath), { recursive: true });
34842
+ fs10.writeFileSync(configPath, `${JSON.stringify(existing, null, 2)}
34353
34843
  `, "utf8");
34354
34844
  }
34355
34845
  function mergeCodexMcpConfig(configPath, options) {
34356
34846
  const backupPath = backupIfExists(configPath);
34357
- const existing = fs9.existsSync(configPath) ? fs9.readFileSync(configPath, "utf8") : "";
34847
+ const existing = fs10.existsSync(configPath) ? fs10.readFileSync(configPath, "utf8") : "";
34358
34848
  const sectionPattern = createCodexMcpSectionPattern(options.mcpName);
34359
34849
  const withoutOld = existing.replace(sectionPattern, "").trimEnd();
34360
34850
  const command = getNpxCommand();
@@ -34367,9 +34857,9 @@ function mergeCodexMcpConfig(configPath, options) {
34367
34857
  `TAPTAP_MCP_ENV = "${options.env}"`,
34368
34858
  ""
34369
34859
  ].join("\n");
34370
- fs9.mkdirSync(path10.dirname(configPath), { recursive: true });
34371
- fs9.writeFileSync(configPath, [withoutOld, section].filter(Boolean).join("\n\n"), "utf8");
34372
- const updated = fs9.readFileSync(configPath, "utf8");
34860
+ fs10.mkdirSync(path11.dirname(configPath), { recursive: true });
34861
+ fs10.writeFileSync(configPath, [withoutOld, section].filter(Boolean).join("\n\n"), "utf8");
34862
+ const updated = fs10.readFileSync(configPath, "utf8");
34373
34863
  const duplicates = findCodexMcpTableDuplicates(updated, options.mcpName);
34374
34864
  if (duplicates.length > 0) {
34375
34865
  restoreBackup(configPath, backupPath);
@@ -34422,7 +34912,7 @@ function normalizeCodexMcpTablePath(tablePath, mcpName) {
34422
34912
  }
34423
34913
  function tryClaudeMcpAdd(options) {
34424
34914
  const command = process.platform === "win32" ? "claude.cmd" : "claude";
34425
- const result = spawnSync4(
34915
+ const result = spawnSync5(
34426
34916
  command,
34427
34917
  [
34428
34918
  "mcp",
@@ -34474,10 +34964,10 @@ function rejectPackageOption(parsed) {
34474
34964
  }
34475
34965
  }
34476
34966
  function readJsonObject(filePath) {
34477
- if (!fs9.existsSync(filePath)) {
34967
+ if (!fs10.existsSync(filePath)) {
34478
34968
  return {};
34479
34969
  }
34480
- return JSON.parse(fs9.readFileSync(filePath, "utf8"));
34970
+ return JSON.parse(fs10.readFileSync(filePath, "utf8"));
34481
34971
  }
34482
34972
  function asObject(value) {
34483
34973
  if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -34486,26 +34976,26 @@ function asObject(value) {
34486
34976
  return {};
34487
34977
  }
34488
34978
  function backupIfExists(filePath) {
34489
- if (!fs9.existsSync(filePath)) {
34979
+ if (!fs10.existsSync(filePath)) {
34490
34980
  return void 0;
34491
34981
  }
34492
34982
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\..+$/, "");
34493
34983
  const backupPath = `${filePath}.bak.${stamp}`;
34494
- fs9.copyFileSync(filePath, backupPath);
34984
+ fs10.copyFileSync(filePath, backupPath);
34495
34985
  return backupPath;
34496
34986
  }
34497
34987
  function restoreBackup(filePath, backupPath) {
34498
34988
  if (backupPath) {
34499
- fs9.copyFileSync(backupPath, filePath);
34989
+ fs10.copyFileSync(backupPath, filePath);
34500
34990
  return;
34501
34991
  }
34502
- fs9.rmSync(filePath, { force: true });
34992
+ fs10.rmSync(filePath, { force: true });
34503
34993
  }
34504
34994
  function saveInitState(targetDir, state) {
34505
- fs9.mkdirSync(getMakerHome(), { recursive: true });
34506
- const key = crypto.createHash("sha256").update(path10.resolve(targetDir)).digest("hex").slice(0, 16);
34507
- fs9.writeFileSync(
34508
- path10.join(getMakerHome(), `init-state-${key}.json`),
34995
+ fs10.mkdirSync(getMakerHome(), { recursive: true });
34996
+ const key = crypto2.createHash("sha256").update(path11.resolve(targetDir)).digest("hex").slice(0, 16);
34997
+ fs10.writeFileSync(
34998
+ path11.join(getMakerHome(), `init-state-${key}.json`),
34509
34999
  `${JSON.stringify({ ...state, updated_at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2)}
34510
35000
  `,
34511
35001
  "utf8"
@@ -34640,7 +35130,8 @@ function makerEnvOption(parsed) {
34640
35130
  if (env === "rnd" || env === "production") {
34641
35131
  return env;
34642
35132
  }
34643
- return getMakerEnvironment();
35133
+ const targetDir = stringOption(parsed, "target_dir");
35134
+ return getMakerEnvironment(void 0, targetDir ? path11.resolve(targetDir) : process.cwd());
34644
35135
  }
34645
35136
  function mcpVerifyModeOption(parsed) {
34646
35137
  const mode = stringOption(parsed, "mode") || "npx";
@@ -34684,8 +35175,9 @@ function printHelp() {
34684
35175
  " taptap-maker doctor [--target-dir DIR] [--env rnd|production] [--json]",
34685
35176
  " taptap-maker apps [--pat PAT] [--all] [--json]",
34686
35177
  " # --pat warns: PAT appears in ps/history",
35178
+ " taptap-maker login [--env rnd|production] [--json]",
34687
35179
  " taptap-maker pat set [--pat-stdin] [--json]",
34688
- " taptap-maker pat set [PAT|--pat PAT] [--json] # warns: PAT appears in ps/history",
35180
+ " taptap-maker pat set [PAT|--pat PAT] [--json] # fallback; warns: PAT appears in ps/history",
34689
35181
  " taptap-maker install [--ide codex,cursor,claude] [--env rnd|production]",
34690
35182
  " [--json] # alias for mcp install",
34691
35183
  " taptap-maker mcp install [--ide codex,cursor,claude] [--env rnd|production]",
@@ -34711,14 +35203,14 @@ function formatCliError(error2) {
34711
35203
  }
34712
35204
 
34713
35205
  // src/maker/crashLog.ts
34714
- import fs10 from "node:fs";
34715
- import path11 from "node:path";
35206
+ import fs11 from "node:fs";
35207
+ import path12 from "node:path";
34716
35208
  var DEFAULT_MAX_BYTES = 1024 * 1024;
34717
35209
  var DEFAULT_MAX_ENTRY_BYTES = 16 * 1024;
34718
35210
  function appendMakerCrashLog(source, error2, options = {}) {
34719
35211
  const makerHome = getMakerHome();
34720
- fs10.mkdirSync(makerHome, { recursive: true });
34721
- const logPath = path11.join(makerHome, "mcp-crash.log");
35212
+ fs11.mkdirSync(makerHome, { recursive: true });
35213
+ const logPath = path12.join(makerHome, "mcp-crash.log");
34722
35214
  const maxBytes = positiveInteger(options.maxBytes) || resolveEnvBytes("TAPTAP_MAKER_CRASH_LOG_MAX_BYTES", DEFAULT_MAX_BYTES);
34723
35215
  const maxEntryBytes = positiveInteger(options.maxEntryBytes) || resolveEnvBytes("TAPTAP_MAKER_CRASH_LOG_MAX_ENTRY_BYTES", DEFAULT_MAX_ENTRY_BYTES);
34724
35216
  const message = error2 instanceof Error ? error2.stack || error2.message : String(error2);
@@ -34728,31 +35220,31 @@ function appendMakerCrashLog(source, error2, options = {}) {
34728
35220
  );
34729
35221
  const entryBytes = Buffer.byteLength(entry, "utf8");
34730
35222
  rotateIfNeeded(logPath, maxBytes, entryBytes);
34731
- fs10.appendFileSync(logPath, entry, "utf8");
35223
+ fs11.appendFileSync(logPath, entry, "utf8");
34732
35224
  }
34733
35225
  function rotateIfNeeded(logPath, maxBytes, incomingBytes) {
34734
- if (!fs10.existsSync(logPath)) {
35226
+ if (!fs11.existsSync(logPath)) {
34735
35227
  return;
34736
35228
  }
34737
- const currentBytes = fs10.statSync(logPath).size;
35229
+ const currentBytes = fs11.statSync(logPath).size;
34738
35230
  if (currentBytes + incomingBytes <= maxBytes) {
34739
35231
  return;
34740
35232
  }
34741
35233
  const rotatedPath = `${logPath}.1`;
34742
35234
  writeFileTail(logPath, rotatedPath, maxBytes);
34743
- fs10.writeFileSync(logPath, "", "utf8");
35235
+ fs11.writeFileSync(logPath, "", "utf8");
34744
35236
  }
34745
35237
  function writeFileTail(sourcePath, targetPath, maxBytes) {
34746
- const size = fs10.statSync(sourcePath).size;
35238
+ const size = fs11.statSync(sourcePath).size;
34747
35239
  const bytesToRead = Math.min(size, maxBytes);
34748
35240
  const start = Math.max(0, size - bytesToRead);
34749
- const fd = fs10.openSync(sourcePath, "r");
35241
+ const fd = fs11.openSync(sourcePath, "r");
34750
35242
  try {
34751
35243
  const buffer = Buffer.alloc(bytesToRead);
34752
- fs10.readSync(fd, buffer, 0, bytesToRead, start);
34753
- fs10.writeFileSync(targetPath, buffer);
35244
+ fs11.readSync(fd, buffer, 0, bytesToRead, start);
35245
+ fs11.writeFileSync(targetPath, buffer);
34754
35246
  } finally {
34755
- fs10.closeSync(fd);
35247
+ fs11.closeSync(fd);
34756
35248
  }
34757
35249
  }
34758
35250
  function truncateUtf8(value, maxBytes) {
@@ -34944,13 +35436,13 @@ function createFetchWithInit(baseFetch = fetch, baseInit) {
34944
35436
  }
34945
35437
 
34946
35438
  // node_modules/pkce-challenge/dist/index.node.js
34947
- var crypto2;
35439
+ var crypto3;
34948
35440
  var _a2;
34949
- crypto2 = ((_a2 = globalThis.crypto) == null ? void 0 : _a2.webcrypto) ?? // Node.js [18-16] REPL
35441
+ crypto3 = ((_a2 = globalThis.crypto) == null ? void 0 : _a2.webcrypto) ?? // Node.js [18-16] REPL
34950
35442
  globalThis.crypto ?? // Node.js >18
34951
35443
  import("node:crypto").then((m) => m.webcrypto);
34952
35444
  async function getRandomValues(size) {
34953
- return (await crypto2).getRandomValues(new Uint8Array(size));
35445
+ return (await crypto3).getRandomValues(new Uint8Array(size));
34954
35446
  }
34955
35447
  async function random(size) {
34956
35448
  const mask2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
@@ -34966,7 +35458,7 @@ async function generateVerifier(length) {
34966
35458
  return await random(length);
34967
35459
  }
34968
35460
  async function generateChallenge(code_verifier) {
34969
- const buffer = await (await crypto2).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
35461
+ const buffer = await (await crypto3).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
34970
35462
  return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
34971
35463
  }
34972
35464
  async function pkceChallenge(length) {
@@ -36036,14 +36528,14 @@ var StreamableHTTPClientTransport = class {
36036
36528
  (_a3 = this.onerror) == null ? void 0 : _a3.call(this, new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
36037
36529
  return;
36038
36530
  }
36039
- const delay = this._getNextReconnectionDelay(attemptCount);
36531
+ const delay2 = this._getNextReconnectionDelay(attemptCount);
36040
36532
  this._reconnectionTimeout = setTimeout(() => {
36041
36533
  this._startOrAuthSse(options).catch((error2) => {
36042
36534
  var _a4;
36043
36535
  (_a4 = this.onerror) == null ? void 0 : _a4.call(this, new Error(`Failed to reconnect SSE stream: ${error2 instanceof Error ? error2.message : String(error2)}`));
36044
36536
  this._scheduleReconnection(options, attemptCount + 1);
36045
36537
  });
36046
- }, delay);
36538
+ }, delay2);
36047
36539
  }
36048
36540
  _handleSseStream(stream, options, isReconnectable) {
36049
36541
  if (!stream) {
@@ -36321,8 +36813,8 @@ var StreamableHTTPClientTransport = class {
36321
36813
  };
36322
36814
 
36323
36815
  // src/mcp-proxy/proxy.ts
36324
- import * as path13 from "node:path";
36325
- import * as crypto4 from "node:crypto";
36816
+ import * as path14 from "node:path";
36817
+ import * as crypto5 from "node:crypto";
36326
36818
 
36327
36819
  // src/mcp-proxy/cookieJar.ts
36328
36820
  var CookieJar = class {
@@ -36503,9 +36995,9 @@ function createCookieFetch(cookieJar) {
36503
36995
  }
36504
36996
 
36505
36997
  // src/core/utils/logWriter.ts
36506
- import * as fs11 from "node:fs";
36507
- import * as path12 from "node:path";
36508
- import * as crypto3 from "node:crypto";
36998
+ import * as fs12 from "node:fs";
36999
+ import * as path13 from "node:path";
37000
+ import * as crypto4 from "node:crypto";
36509
37001
 
36510
37002
  // src/core/types/log.ts
36511
37003
  var LOG_LEVEL_PRIORITY = {
@@ -36545,7 +37037,7 @@ var LogWriter = class {
36545
37037
  return;
36546
37038
  }
36547
37039
  try {
36548
- await fs11.promises.mkdir(this.config.logDir, { recursive: true });
37040
+ await fs12.promises.mkdir(this.config.logDir, { recursive: true });
36549
37041
  await this.cleanupOldLogs();
36550
37042
  this.initialized = true;
36551
37043
  } catch (error2) {
@@ -36568,7 +37060,7 @@ var LogWriter = class {
36568
37060
  */
36569
37061
  getLogFilePath(date5) {
36570
37062
  const d = date5 || this.getCurrentDate();
36571
- return path12.join(this.config.logDir, `${this.config.prefix}-${d}.log`);
37063
+ return path13.join(this.config.logDir, `${this.config.prefix}-${d}.log`);
36572
37064
  }
36573
37065
  /**
36574
37066
  * 获取或创建写入流
@@ -36583,7 +37075,7 @@ var LogWriter = class {
36583
37075
  }
36584
37076
  this.currentDate = date5;
36585
37077
  try {
36586
- this.writeStream = fs11.createWriteStream(this.getLogFilePath(date5), {
37078
+ this.writeStream = fs12.createWriteStream(this.getLogFilePath(date5), {
36587
37079
  flags: "a",
36588
37080
  encoding: "utf8"
36589
37081
  });
@@ -36635,11 +37127,11 @@ var LogWriter = class {
36635
37127
  if (this.shouldWriteToFile(level) && this.initialized && this.config.enabled) {
36636
37128
  try {
36637
37129
  const filePath = this.getLogFilePath();
36638
- const dir = path12.dirname(filePath);
36639
- if (!fs11.existsSync(dir)) {
36640
- fs11.mkdirSync(dir, { recursive: true });
37130
+ const dir = path13.dirname(filePath);
37131
+ if (!fs12.existsSync(dir)) {
37132
+ fs12.mkdirSync(dir, { recursive: true });
36641
37133
  }
36642
- fs11.appendFileSync(filePath, message, "utf8");
37134
+ fs12.appendFileSync(filePath, message, "utf8");
36643
37135
  } catch {
36644
37136
  }
36645
37137
  }
@@ -36650,7 +37142,7 @@ var LogWriter = class {
36650
37142
  async cleanupOldLogs() {
36651
37143
  if (this.config.maxDays <= 0) return;
36652
37144
  try {
36653
- const files = await fs11.promises.readdir(this.config.logDir);
37145
+ const files = await fs12.promises.readdir(this.config.logDir);
36654
37146
  const cutoffDate = /* @__PURE__ */ new Date();
36655
37147
  cutoffDate.setDate(cutoffDate.getDate() - this.config.maxDays);
36656
37148
  const prefix = this.config.prefix;
@@ -36665,7 +37157,7 @@ var LogWriter = class {
36665
37157
  if (!Number.isNaN(year) && !Number.isNaN(month) && !Number.isNaN(day)) {
36666
37158
  const fileDate = new Date(year, month - 1, day);
36667
37159
  if (fileDate < cutoffDate) {
36668
- await fs11.promises.unlink(path12.join(this.config.logDir, file2));
37160
+ await fs12.promises.unlink(path13.join(this.config.logDir, file2));
36669
37161
  process.stderr.write(`[LogWriter] Deleted old log: ${file2}
36670
37162
  `);
36671
37163
  }
@@ -36736,10 +37228,10 @@ var TapTapMCPProxy = class {
36736
37228
  const { user_id, project_id } = this.config.tenant;
36737
37229
  let logDir;
36738
37230
  if (user_id && project_id) {
36739
- logDir = path13.join(logRoot, "proxy", user_id, project_id);
37231
+ logDir = path14.join(logRoot, "proxy", user_id, project_id);
36740
37232
  } else {
36741
- const kidHash = crypto4.createHash("sha256").update(this.config.auth.kid).digest("hex").substring(0, 8);
36742
- logDir = path13.join(logRoot, "proxy", kidHash);
37233
+ const kidHash = crypto5.createHash("sha256").update(this.config.auth.kid).digest("hex").substring(0, 8);
37234
+ logDir = path14.join(logRoot, "proxy", kidHash);
36743
37235
  }
36744
37236
  return new LogWriter({
36745
37237
  logDir,
@@ -37374,8 +37866,9 @@ function printHelp2() {
37374
37866
  " taptap-maker doctor [--target-dir DIR] [--env rnd|production] [--json]",
37375
37867
  " taptap-maker apps [--pat PAT] [--all] [--json]",
37376
37868
  " # --pat warns: PAT appears in ps/history",
37869
+ " taptap-maker login [--env rnd|production] [--json]",
37377
37870
  " taptap-maker pat set [--pat-stdin] [--json]",
37378
- " taptap-maker pat set [PAT|--pat PAT] [--json] # warns: PAT appears in ps/history",
37871
+ " taptap-maker pat set [PAT|--pat PAT] [--json] # fallback; warns: PAT appears in ps/history",
37379
37872
  " taptap-maker install [--ide codex,cursor,claude] [--env rnd|production]",
37380
37873
  " [--json] # alias for mcp install",
37381
37874
  " taptap-maker mcp install [--ide codex,cursor,claude] [--env rnd|production]",