connectbase-client 6.21.1 → 6.22.0

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/cli.js CHANGED
@@ -68,36 +68,1224 @@ __export(cli_exports, {
68
68
  });
69
69
  module.exports = __toCommonJS(cli_exports);
70
70
  var crypto = __toESM(require("crypto"));
71
- var fs2 = __toESM(require("fs"));
72
- var http = __toESM(require("http"));
71
+ var fs4 = __toESM(require("fs"));
72
+ var http2 = __toESM(require("http"));
73
73
  var https = __toESM(require("https"));
74
+ var os4 = __toESM(require("os"));
75
+ var path4 = __toESM(require("path"));
76
+ var readline = __toESM(require("readline"));
77
+
78
+ // src/local-command.ts
79
+ var import_node_crypto = require("crypto");
80
+ var fs2 = __toESM(require("fs"));
74
81
  var os2 = __toESM(require("os"));
75
82
  var path2 = __toESM(require("path"));
76
- var readline = __toESM(require("readline"));
77
83
 
78
- // src/tunnel-utils.ts
84
+ // src/local-runner.ts
85
+ var import_node_child_process = require("child_process");
79
86
  var fs = __toESM(require("fs"));
87
+ var http = __toESM(require("http"));
88
+ var net = __toESM(require("net"));
80
89
  var os = __toESM(require("os"));
81
90
  var path = __toESM(require("path"));
91
+ var MAX_OUT = 24e3;
92
+ var MAX_READ = 2e5;
93
+ var MAX_IMAGE = 8 * 1024 * 1024;
94
+ var PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
95
+ var text = (t, isError = false) => ({
96
+ content: [{ type: "text", text: t }],
97
+ ...isError ? { isError } : {}
98
+ });
99
+ var tail = (s, n = MAX_OUT) => s.length > n ? `\u2026(\uC55E ${s.length - n}\uC790 \uC0DD\uB7B5)
100
+ ${s.slice(-n)}` : s;
101
+ var str = (v, d = "") => typeof v === "string" ? v : d;
102
+ var num = (v, d) => typeof v === "number" && Number.isFinite(v) ? v : d;
103
+ function imageMime(p) {
104
+ const ext = path.extname(p).toLowerCase();
105
+ return {
106
+ ".png": "image/png",
107
+ ".jpg": "image/jpeg",
108
+ ".jpeg": "image/jpeg",
109
+ ".webp": "image/webp",
110
+ ".gif": "image/gif"
111
+ }[ext] ?? null;
112
+ }
113
+ function findPrograms() {
114
+ const which = (names, extra = []) => {
115
+ const dirs = (process.env.PATH ?? "").split(path.delimiter).filter(Boolean);
116
+ const exts = process.platform === "win32" ? ["", ".exe", ".cmd", ".bat"] : [""];
117
+ for (const n of names) {
118
+ if (path.isAbsolute(n) && fs.existsSync(n)) return n;
119
+ for (const d of dirs)
120
+ for (const e of exts) {
121
+ const p = path.join(d, n + e);
122
+ if (fs.existsSync(p)) return p;
123
+ }
124
+ }
125
+ for (const p of extra) if (fs.existsSync(p)) return p;
126
+ return null;
127
+ };
128
+ const globDirs = (root, pattern, sub) => {
129
+ try {
130
+ return fs.readdirSync(root).filter((n) => pattern.test(n)).sort().reverse().map((n) => path.join(root, n, sub));
131
+ } catch {
132
+ return [];
133
+ }
134
+ };
135
+ const blenderExtra = process.platform === "win32" ? globDirs(
136
+ "C:\\Program Files\\Blender Foundation",
137
+ /^Blender/,
138
+ "blender.exe"
139
+ ) : process.platform === "darwin" ? ["/Applications/Blender.app/Contents/MacOS/Blender"] : [
140
+ "/snap/bin/blender",
141
+ "/usr/bin/blender",
142
+ ...globDirs("/opt", /^blender/i, "blender")
143
+ ];
144
+ const zbrushExtra = process.platform === "darwin" ? globDirs(
145
+ "/Applications",
146
+ /^Maxon ZBrush/,
147
+ "ZBrush.app/Contents/MacOS/ZBrush"
148
+ ) : process.platform === "win32" ? globDirs("C:\\Program Files", /^Maxon ZBrush/, "ZBrush.exe") : [];
149
+ return {
150
+ blender: process.env.BLENDER_BIN && fs.existsSync(process.env.BLENDER_BIN) ? process.env.BLENDER_BIN : which(["blender"], blenderExtra),
151
+ zbrush: which([], zbrushExtra),
152
+ python: which(
153
+ process.platform === "win32" ? ["python", "py"] : ["python3", "python"]
154
+ ),
155
+ uv: which(
156
+ ["uv"],
157
+ [
158
+ path.join(
159
+ os.homedir(),
160
+ ".local",
161
+ "bin",
162
+ process.platform === "win32" ? "uv.exe" : "uv"
163
+ ),
164
+ path.join(os.homedir(), ".cargo", "bin", "uv")
165
+ ]
166
+ ),
167
+ node: process.execPath,
168
+ npm: which(["npm"]),
169
+ git: which(["git"]),
170
+ ffmpeg: which(["ffmpeg"]),
171
+ tar: which(["tar"])
172
+ };
173
+ }
174
+ var LocalRunner = class {
175
+ constructor(opts) {
176
+ this.jobs = /* @__PURE__ */ new Map();
177
+ this.jobSeq = 0;
178
+ this.opts = opts;
179
+ this.dir = path.resolve(opts.dir);
180
+ this.skillsDir = path.join(this.dir, "skills");
181
+ fs.mkdirSync(this.skillsDir, { recursive: true });
182
+ this.programs = findPrograms();
183
+ this.tools = this.defineTools();
184
+ }
185
+ log(line) {
186
+ (this.opts.log ?? console.log)(line);
187
+ }
188
+ /** 작업 폴더 안의 경로로 푼다. 절대 경로도 작업 폴더 안이어야 한다. */
189
+ inDir(p) {
190
+ const abs = path.resolve(
191
+ this.dir,
192
+ p.replace(/^~(?=$|[\\/])/, os.homedir())
193
+ );
194
+ const rel = path.relative(this.dir, abs);
195
+ if (rel.startsWith("..") || path.isAbsolute(rel))
196
+ throw new Error(
197
+ `\uC791\uC5C5 \uD3F4\uB354(${this.dir}) \uBC16\uC758 \uACBD\uB85C\uB294 \uC4F8 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${p}`
198
+ );
199
+ return abs;
200
+ }
201
+ env() {
202
+ const e = {
203
+ ...process.env,
204
+ CONNECTBASE_LOCAL_DIR: this.dir,
205
+ PYTHONUNBUFFERED: "1"
206
+ };
207
+ if (this.programs.blender) {
208
+ e.BLENDER_BIN = e.BLENDER_BIN || this.programs.blender;
209
+ e.BLENDER = e.BLENDER || this.programs.blender;
210
+ }
211
+ return e;
212
+ }
213
+ defineTools() {
214
+ const ro = { readOnlyHint: true };
215
+ return [
216
+ {
217
+ name: "local_info",
218
+ description: "\uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130 \uC815\uBCF4: OS, \uC791\uC5C5 \uD3F4\uB354, \uBC1B\uC544 \uB454 \uC2A4\uD0AC, \uCC3E\uC740 \uD504\uB85C\uADF8\uB7A8(blender, zbrush, python, uv, node, npm, git, ffmpeg) \uACBD\uB85C\uC640 BlenderMCP \uC5F0\uACB0 \uC5EC\uBD80. \uC2A4\uD0AC\uC744 \uC4F0\uAE30 \uC804\uC5D0 \uBA3C\uC800 \uBCF8\uB2E4.",
219
+ inputSchema: { type: "object", properties: {} },
220
+ annotations: ro,
221
+ run: async () => {
222
+ this.programs = findPrograms();
223
+ const skills = fs.existsSync(this.skillsDir) ? fs.readdirSync(this.skillsDir) : [];
224
+ const blenderLive = await this.blenderPing();
225
+ return text(
226
+ JSON.stringify(
227
+ {
228
+ os: `${process.platform} ${os.release()} ${process.arch}`,
229
+ work_dir: this.dir,
230
+ skills_dir: this.skillsDir,
231
+ installed_skills: skills,
232
+ programs: this.programs,
233
+ blender_mcp: blenderLive ? `\uC5F0\uACB0\uB428 (localhost:${this.blenderPort})` : `\uC5C6\uC74C (Blender \uC5D0\uC11C BlenderMCP \uC560\uB4DC\uC628 > Start \uB97C \uB204\uB974\uBA74 execute_blender_code \uB4F1\uC744 \uC4F8 \uC218 \uC788\uB2E4)`,
234
+ notes: [
235
+ "run \uC758 \uBA85\uB839\uC740 \uC791\uC5C5 \uD3F4\uB354\uC5D0\uC11C \uB3C8\uB2E4. BLENDER_BIN, BLENDER \uD658\uACBD\uBCC0\uC218\uC5D0 \uCC3E\uC740 Blender \uACBD\uB85C\uAC00 \uB4E4\uC5B4 \uC788\uB2E4.",
236
+ "\uC2A4\uD0AC \uBB38\uC11C\uC758 {{SKILL_DIR}}, ~/.claude/skills/<\uC774\uB984>, ~/.codex/skills/<\uC774\uB984> \uC740 skill_install \uC774 \uC54C\uB824 \uC900 \uACBD\uB85C\uB85C \uBC14\uAFD4 \uC4F4\uB2E4."
237
+ ]
238
+ },
239
+ null,
240
+ 2
241
+ )
242
+ );
243
+ }
244
+ },
245
+ {
246
+ name: "skill_install",
247
+ description: "GitHub \uC758 \uC2A4\uD0AC \uD3F4\uB354(SKILL.md, references/, scripts/, assets/ \u2026)\uB97C \uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130\uC758 \uC791\uC5C5 \uD3F4\uB354\uC5D0 \uD1B5\uC9F8\uB85C \uBC1B\uB294\uB2E4. source \uB294 'owner/repo/\uACBD\uB85C@\uCEE4\uBC0B' (\uC608: yorusd1/yoruskills/skills/vehicle@cb7bc264b). \uC774\uBBF8 \uC788\uC73C\uBA74 \uADF8\uB300\uB85C \uB450\uACE0 \uACBD\uB85C\uB9CC \uC54C\uB824 \uC900\uB2E4 (update=true \uBA74 \uB2E4\uC2DC \uBC1B\uB294\uB2E4). \uB3CC\uB824\uC900 skill_dir \uC774 \uC2A4\uD0AC \uBB38\uC11C\uC758 {{SKILL_DIR}} \uC774\uB2E4.",
248
+ inputSchema: {
249
+ type: "object",
250
+ properties: {
251
+ source: { type: "string", description: "owner/repo/\uD3F4\uB354\uACBD\uB85C@ref" },
252
+ update: { type: "boolean" }
253
+ },
254
+ required: ["source"]
255
+ },
256
+ run: async (a) => this.skillInstall(str(a.source), a.update === true)
257
+ },
258
+ {
259
+ name: "list_files",
260
+ description: "\uC791\uC5C5 \uD3F4\uB354 \uC548\uC758 \uD3F4\uB354 \uB0B4\uC6A9\uC744 \uBCF8\uB2E4 (path \uB294 \uC791\uC5C5 \uD3F4\uB354 \uAE30\uC900, \uC608: skills/vehicle/references). depth \uB85C \uD558\uC704 \uD3F4\uB354\uAE4C\uC9C0.",
261
+ inputSchema: {
262
+ type: "object",
263
+ properties: { path: { type: "string" }, depth: { type: "number" } }
264
+ },
265
+ annotations: ro,
266
+ run: async (a) => {
267
+ const root = this.inDir(str(a.path, "."));
268
+ const depth = Math.min(num(a.depth, 1), 4);
269
+ const lines = [];
270
+ const walk = (d, lvl) => {
271
+ for (const n of fs.readdirSync(d, { withFileTypes: true }).sort((x, y) => x.name.localeCompare(y.name))) {
272
+ if (n.name === "node_modules" || n.name === ".git" || n.name === "__pycache__")
273
+ continue;
274
+ const p = path.join(d, n.name);
275
+ const rel = path.relative(this.dir, p);
276
+ if (n.isDirectory()) {
277
+ lines.push(`${rel}/`);
278
+ if (lvl < depth) walk(p, lvl + 1);
279
+ } else lines.push(`${rel} ${fs.statSync(p).size}B`);
280
+ if (lines.length > 2e3) return;
281
+ }
282
+ };
283
+ walk(root, 1);
284
+ return text(lines.join("\n") || "(\uBE44\uC5B4 \uC788\uC74C)");
285
+ }
286
+ },
287
+ {
288
+ name: "read_file",
289
+ description: "\uC791\uC5C5 \uD3F4\uB354 \uC548\uC758 \uAE00 \uD30C\uC77C\uC744 \uC77D\uB294\uB2E4 (\uC2A4\uD0AC\uC758 references/*.md, \uC2A4\uD06C\uB9BD\uD2B8, \uB85C\uADF8, JSON). \uAE38\uBA74 offset \uC73C\uB85C \uC774\uC5B4 \uC77D\uB294\uB2E4.",
290
+ inputSchema: {
291
+ type: "object",
292
+ properties: {
293
+ path: { type: "string" },
294
+ offset: { type: "number", description: "\uC2DC\uC791 \uAE00\uC790 \uC704\uCE58" }
295
+ },
296
+ required: ["path"]
297
+ },
298
+ annotations: ro,
299
+ run: async (a) => {
300
+ const p = this.inDir(str(a.path));
301
+ const all = fs.readFileSync(p, "utf-8").split("{{SKILL_DIR}}").join(this.skillDirOf(p) ?? "{{SKILL_DIR}}");
302
+ const off = Math.max(0, num(a.offset, 0));
303
+ const part = all.slice(off, off + MAX_READ);
304
+ const more = off + MAX_READ < all.length ? `
305
+
306
+ \u2026(\uC774\uC5B4\uC11C \uC77D\uAE30: offset=${off + MAX_READ}, \uC804\uCCB4 ${all.length}\uC790)` : "";
307
+ return text(part + more);
308
+ }
309
+ },
310
+ {
311
+ name: "write_file",
312
+ description: "\uC791\uC5C5 \uD3F4\uB354 \uC548\uC5D0 \uAE00 \uD30C\uC77C\uC744 \uC4F4\uB2E4 (\uBE4C\uB4DC \uC2A4\uD06C\uB9BD\uD2B8, spec.json, \uC124\uC815). \uD3F4\uB354\uB294 \uC790\uB3D9\uC73C\uB85C \uB9CC\uB4E0\uB2E4.",
313
+ inputSchema: {
314
+ type: "object",
315
+ properties: { path: { type: "string" }, content: { type: "string" } },
316
+ required: ["path", "content"]
317
+ },
318
+ run: async (a) => {
319
+ const p = this.inDir(str(a.path));
320
+ fs.mkdirSync(path.dirname(p), { recursive: true });
321
+ fs.writeFileSync(p, str(a.content));
322
+ return text(`\uC37C\uC2B5\uB2C8\uB2E4: ${p} (${Buffer.byteLength(str(a.content))}B)`);
323
+ }
324
+ },
325
+ {
326
+ name: "run",
327
+ description: "\uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130\uC5D0\uC11C \uC178 \uBA85\uB839\uC744 \uC2E4\uD589\uD55C\uB2E4 (python, uv run, node, npm, blender -b \u2026, ffmpeg, \uC2A4\uD0AC\uC758 scripts). cwd \uB294 \uC791\uC5C5 \uD3F4\uB354 \uAE30\uC900. 90\uCD08 \uB118\uAC8C \uAC78\uB9B4 \uC218 \uC788\uB294 \uB80C\uB354, \uAD7D\uAE30, \uC124\uCE58\uB294 background=true \uB85C \uB3CC\uB9AC\uACE0 job_status \uB85C \uBCF8\uB2E4 (ConnectBase \uAC00 \uB3C4\uAD6C \uD638\uCD9C\uC744 120\uCD08\uC5D0\uC11C \uB04A\uB294\uB2E4). \uAE30\uBCF8 \uC2DC\uAC04 \uD55C\uB3C4 90\uCD08, \uCD5C\uB300 100\uCD08.",
328
+ inputSchema: {
329
+ type: "object",
330
+ properties: {
331
+ command: { type: "string" },
332
+ cwd: {
333
+ type: "string",
334
+ description: "\uC791\uC5C5 \uD3F4\uB354 \uAE30\uC900 (\uAE30\uBCF8 \uC791\uC5C5 \uD3F4\uB354)"
335
+ },
336
+ timeout: { type: "number", description: "\uCD08 (\uAE30\uBCF8 90, \uCD5C\uB300 100)" },
337
+ background: { type: "boolean" }
338
+ },
339
+ required: ["command"]
340
+ },
341
+ run: async (a) => this.run(
342
+ str(a.command),
343
+ str(a.cwd, "."),
344
+ num(a.timeout, 90),
345
+ a.background === true
346
+ )
347
+ },
348
+ {
349
+ name: "job_status",
350
+ description: "background \uB85C \uB3CC\uB9B0 \uBA85\uB839\uC758 \uC0C1\uD0DC\uC640 \uCD9C\uB825 \uB05D\uBD80\uBD84. id \uB97C \uBE44\uC6B0\uBA74 \uBAA8\uB4E0 \uC791\uC5C5 \uBAA9\uB85D.",
351
+ inputSchema: {
352
+ type: "object",
353
+ properties: {
354
+ id: { type: "string" },
355
+ wait: {
356
+ type: "number",
357
+ description: "\uB05D\uB0A0 \uB54C\uAE4C\uC9C0 \uAE30\uB2E4\uB9B4 \uCD08 (\uCD5C\uB300 100)"
358
+ }
359
+ }
360
+ },
361
+ annotations: ro,
362
+ run: async (a) => this.jobStatus(str(a.id), num(a.wait, 0))
363
+ },
364
+ {
365
+ name: "job_stop",
366
+ description: "background \uC791\uC5C5\uC744 \uBA48\uCD98\uB2E4.",
367
+ inputSchema: {
368
+ type: "object",
369
+ properties: { id: { type: "string" } },
370
+ required: ["id"]
371
+ },
372
+ run: async (a) => {
373
+ const j = this.jobs.get(str(a.id));
374
+ if (!j) return text("\uADF8\uB7F0 \uC791\uC5C5\uC774 \uC5C6\uC2B5\uB2C8\uB2E4", true);
375
+ j.kill();
376
+ return text(`\uBA48\uCDA4 \uC694\uCCAD: ${j.id}`);
377
+ }
378
+ },
379
+ {
380
+ name: "view_image",
381
+ description: "\uC791\uC5C5 \uD3F4\uB354 \uC548\uC758 \uADF8\uB9BC(PNG, JPG, WebP)\uC744 \uBCF8\uB2E4 \u2014 \uB80C\uB354, \uB9AC\uBDF0 \uC2DC\uD2B8, \uBE44\uAD50 \uADF8\uB9BC, \uC2A4\uD06C\uB9B0\uC0F7 \uD310\uC815\uC6A9.",
382
+ inputSchema: {
383
+ type: "object",
384
+ properties: { path: { type: "string" } },
385
+ required: ["path"]
386
+ },
387
+ annotations: ro,
388
+ run: async (a) => {
389
+ const p = this.inDir(str(a.path));
390
+ const mime = imageMime(p);
391
+ if (!mime)
392
+ return text(
393
+ "\uADF8\uB9BC \uD30C\uC77C(png, jpg, webp, gif)\uB9CC \uBCFC \uC218 \uC788\uC2B5\uB2C8\uB2E4",
394
+ true
395
+ );
396
+ const buf = fs.readFileSync(p);
397
+ if (buf.length > MAX_IMAGE)
398
+ return text(
399
+ `\uADF8\uB9BC\uC774 \uB108\uBB34 \uD07D\uB2C8\uB2E4 (${buf.length}B). \uB354 \uC791\uAC8C \uB80C\uB354\uD574 \uC8FC\uC138\uC694`,
400
+ true
401
+ );
402
+ return {
403
+ content: [
404
+ { type: "image", data: buf.toString("base64"), mimeType: mime },
405
+ { type: "text", text: `${p} (${buf.length}B)` }
406
+ ]
407
+ };
408
+ }
409
+ },
410
+ {
411
+ name: "download",
412
+ description: "\uC8FC\uC18C(https)\uC758 \uD30C\uC77C\uC744 \uC791\uC5C5 \uD3F4\uB354\uC5D0 \uBC1B\uB294\uB2E4 \u2014 \uCC38\uACE0 \uADF8\uB9BC, \uC124\uACC4\uB3C4, CC0 \uD14D\uC2A4\uCC98, \uD30C\uC77C \uC2A4\uD1A0\uB9AC\uC9C0\uC758 \uD30C\uC77C.",
413
+ inputSchema: {
414
+ type: "object",
415
+ properties: { url: { type: "string" }, path: { type: "string" } },
416
+ required: ["url", "path"]
417
+ },
418
+ run: async (a) => {
419
+ const url = str(a.url);
420
+ if (!/^https?:\/\//.test(url))
421
+ return text("http(s) \uC8FC\uC18C\uB9CC \uBC1B\uC2B5\uB2C8\uB2E4", true);
422
+ const p = this.inDir(str(a.path));
423
+ const r = await fetch(url, { redirect: "follow" });
424
+ if (!r.ok) return text(`\uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: HTTP ${r.status}`, true);
425
+ const buf = Buffer.from(await r.arrayBuffer());
426
+ fs.mkdirSync(path.dirname(p), { recursive: true });
427
+ fs.writeFileSync(p, buf);
428
+ return text(`\uBC1B\uC558\uC2B5\uB2C8\uB2E4: ${p} (${buf.length}B)`);
429
+ }
430
+ },
431
+ {
432
+ name: "upload_to_storage",
433
+ description: "\uC791\uC5C5 \uD3F4\uB354\uC758 \uACB0\uACFC \uD30C\uC77C(GLB, FBX, PNG, MP4, .blend \u2026)\uC744 \uC774 \uC571\uC758 \uD30C\uC77C \uC2A4\uD1A0\uB9AC\uC9C0\uC5D0 \uC62C\uB9AC\uACE0 \uC8FC\uC18C\uB97C \uB3CC\uB824\uC900\uB2E4. \uC0AC\uC6A9\uC790\uC5D0\uAC8C \uACB0\uACFC\uB97C \uAC74\uB12C \uB54C \uC4F4\uB2E4.",
434
+ inputSchema: {
435
+ type: "object",
436
+ properties: {
437
+ path: { type: "string" },
438
+ folder: {
439
+ type: "string",
440
+ description: "\uC2A4\uD1A0\uB9AC\uC9C0 \uC548 \uD3F4\uB354 (\uAE30\uBCF8 local-runner)"
441
+ }
442
+ },
443
+ required: ["path"]
444
+ },
445
+ run: async (a) => this.uploadToStorage(str(a.path), str(a.folder, "local-runner"))
446
+ },
447
+ {
448
+ name: "image_generate",
449
+ description: "\uC774 \uC571\uC5D0 \uB4F1\uB85D\uD55C \uADF8\uB9BC \uBAA8\uB378\uB85C \uADF8\uB9BC\uC744 \uB9CC\uB4E4\uAC70\uB098 \uACE0\uCCD0 \uC791\uC5C5 \uD3F4\uB354\uC5D0 \uC800\uC7A5\uD55C\uB2E4 (\uC2A4\uD0AC\uC758 image_gen, \uCC38\uACE0 \uADF8\uB9BC \uB9CC\uB4E4\uAE30, UV \uC2DC\uD2B8 \uC0C9\uCE60). input_images \uB97C \uC8FC\uBA74 \uADF8 \uADF8\uB9BC\uB4E4\uC744 \uBCF4\uACE0 \uACE0\uCE5C\uB2E4. provider, model \uC740 \uC571 \uC124\uC815 > AI \uC5D0 \uB4F1\uB85D\uD55C \uADF8\uB9BC \uCD9C\uB825 \uBAA8\uB378.",
450
+ inputSchema: {
451
+ type: "object",
452
+ properties: {
453
+ prompt: { type: "string" },
454
+ out: {
455
+ type: "string",
456
+ description: "\uC800\uC7A5\uD560 \uACBD\uB85C (\uC791\uC5C5 \uD3F4\uB354 \uAE30\uC900, .png)"
457
+ },
458
+ input_images: {
459
+ type: "array",
460
+ items: { type: "string" },
461
+ description: "\uC791\uC5C5 \uD3F4\uB354 \uC548\uC758 \uC785\uB825 \uADF8\uB9BC \uACBD\uB85C\uB4E4"
462
+ },
463
+ provider: { type: "string" },
464
+ model: { type: "string" }
465
+ },
466
+ required: ["prompt", "out"]
467
+ },
468
+ run: async (a) => this.imageGenerate(a)
469
+ },
470
+ // ── 실행 중인 Blender (BlenderMCP 애드온) — 스킬 문서가 부르는 이름 그대로 ──
471
+ {
472
+ name: "execute_blender_code",
473
+ description: "\uC2E4\uD589 \uC911\uC778 Blender \uC5D0\uC11C Python(bpy) \uCF54\uB4DC\uB97C \uC2E4\uD589\uD55C\uB2E4 (BlenderMCP \uC560\uB4DC\uC628 > Start \uD544\uC694). \uC2A4\uD0AC\uC774 'Execute via Blender MCP' \uB77C\uACE0 \uD560 \uB54C \uC4F4\uB2E4. \uD5E4\uB4DC\uB9AC\uC2A4\uB85C \uCDA9\uBD84\uD558\uBA74 run \uC73C\uB85C blender -b \uB97C \uC4F4\uB2E4.",
474
+ inputSchema: {
475
+ type: "object",
476
+ properties: { code: { type: "string" } },
477
+ required: ["code"]
478
+ },
479
+ run: async (a) => this.blenderCall("execute_code", { code: str(a.code) })
480
+ },
481
+ {
482
+ name: "get_scene_info",
483
+ description: "\uC2E4\uD589 \uC911\uC778 Blender \uC758 \uC7A5\uBA74 \uC815\uBCF4 (BlenderMCP).",
484
+ inputSchema: { type: "object", properties: {} },
485
+ annotations: ro,
486
+ run: async () => this.blenderCall("get_scene_info", {})
487
+ },
488
+ {
489
+ name: "get_object_info",
490
+ description: "\uC2E4\uD589 \uC911\uC778 Blender \uC758 \uBB3C\uCCB4 \uC815\uBCF4 (BlenderMCP).",
491
+ inputSchema: {
492
+ type: "object",
493
+ properties: { object_name: { type: "string" } },
494
+ required: ["object_name"]
495
+ },
496
+ annotations: ro,
497
+ run: async (a) => this.blenderCall("get_object_info", { name: str(a.object_name) })
498
+ },
499
+ {
500
+ name: "get_viewport_screenshot",
501
+ description: "\uC2E4\uD589 \uC911\uC778 Blender \uC758 \uBDF0\uD3EC\uD2B8 \uD654\uBA74\uC744 \uBCF8\uB2E4 (BlenderMCP).",
502
+ inputSchema: {
503
+ type: "object",
504
+ properties: { max_size: { type: "number" } }
505
+ },
506
+ annotations: ro,
507
+ run: async (a) => {
508
+ const tmp = path.join(
509
+ os.tmpdir(),
510
+ `cb_blender_shot_${process.pid}_${Date.now()}.png`
511
+ );
512
+ const r = await this.blenderCall("get_viewport_screenshot", {
513
+ max_size: num(a.max_size, 800),
514
+ filepath: tmp,
515
+ format: "png"
516
+ });
517
+ if (r.isError) return r;
518
+ if (!fs.existsSync(tmp))
519
+ return text("Blender \uAC00 \uD654\uBA74\uC744 \uC800\uC7A5\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4", true);
520
+ const data = fs.readFileSync(tmp).toString("base64");
521
+ fs.rmSync(tmp, { force: true });
522
+ return { content: [{ type: "image", data, mimeType: "image/png" }] };
523
+ }
524
+ }
525
+ ];
526
+ }
527
+ skillDirOf(p) {
528
+ const rel = path.relative(this.skillsDir, p);
529
+ if (rel.startsWith("..") || path.isAbsolute(rel)) return null;
530
+ return path.join(this.skillsDir, rel.split(path.sep)[0]);
531
+ }
532
+ async skillInstall(source, update2) {
533
+ const m = /^([\w.-]+)\/([\w.-]+)\/(.+?)(?:@([\w./-]+))?$/.exec(
534
+ source.trim().replace(/^https:\/\/github\.com\//, "").replace(/\/tree\/([^/]+)\//, "/@$1/")
535
+ );
536
+ if (!m)
537
+ return text("source \uB294 owner/repo/\uD3F4\uB354\uACBD\uB85C@ref \uAF34\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4", true);
538
+ const [, owner, repo, sub, ref = "HEAD"] = m;
539
+ const name = path.basename(sub.replace(/\/+$/, ""));
540
+ const dest = path.join(this.skillsDir, name);
541
+ if (fs.existsSync(path.join(dest, "SKILL.md")) && !update2)
542
+ return text(this.describeSkill(dest, "\uC774\uBBF8 \uC788\uC2B5\uB2C8\uB2E4"));
543
+ const tarBin = this.programs.tar ?? findPrograms().tar;
544
+ if (!tarBin)
545
+ return text(
546
+ "tar \uBA85\uB839\uC744 \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (Windows 10 \uC774\uC0C1, macOS, Linux \uC5D0\uB294 \uAE30\uBCF8\uC73C\uB85C \uC788\uC2B5\uB2C8\uB2E4)",
547
+ true
548
+ );
549
+ const r = await fetch(
550
+ `https://codeload.github.com/${owner}/${repo}/tar.gz/${ref}`
551
+ );
552
+ if (!r.ok)
553
+ return text(
554
+ `GitHub \uC5D0\uC11C \uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: HTTP ${r.status} (${owner}/${repo}@${ref})`,
555
+ true
556
+ );
557
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "cb_skill_"));
558
+ try {
559
+ const tgz = path.join(tmp, "src.tgz");
560
+ fs.writeFileSync(tgz, Buffer.from(await r.arrayBuffer()));
561
+ const x = await this.exec(`"${tarBin}" -xzf src.tgz`, tmp, 120);
562
+ if (x.code !== 0) return text(`\uC555\uCD95\uC744 \uD480\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${x.out}`, true);
563
+ const top = fs.readdirSync(tmp).find((n) => n !== "src.tgz");
564
+ const src = top ? path.join(tmp, top, ...sub.split("/")) : "";
565
+ if (!src || !fs.existsSync(path.join(src, "SKILL.md")))
566
+ return text(`\uADF8 \uACBD\uB85C\uC5D0 SKILL.md \uAC00 \uC5C6\uC2B5\uB2C8\uB2E4: ${sub}`, true);
567
+ fs.rmSync(dest, { recursive: true, force: true });
568
+ fs.cpSync(src, dest, { recursive: true });
569
+ fs.writeFileSync(
570
+ path.join(dest, ".source"),
571
+ `${owner}/${repo}/${sub}@${ref}
572
+ `
573
+ );
574
+ } finally {
575
+ fs.rmSync(tmp, { recursive: true, force: true });
576
+ }
577
+ this.log(`\uC2A4\uD0AC \uBC1B\uC74C: ${name} \u2190 ${source}`);
578
+ return text(this.describeSkill(dest, "\uBC1B\uC558\uC2B5\uB2C8\uB2E4"));
579
+ }
580
+ describeSkill(dest, head) {
581
+ const files = [];
582
+ const walk = (d) => {
583
+ for (const n of fs.readdirSync(d, { withFileTypes: true })) {
584
+ const p = path.join(d, n.name);
585
+ if (n.isDirectory()) walk(p);
586
+ else files.push(path.relative(dest, p));
587
+ }
588
+ };
589
+ walk(dest);
590
+ const req = [
591
+ "requirements.txt",
592
+ "tools/package.json",
593
+ "package.json"
594
+ ].filter((f) => fs.existsSync(path.join(dest, f)));
595
+ return JSON.stringify(
596
+ {
597
+ result: head,
598
+ skill_dir: dest,
599
+ note: "\uC2A4\uD0AC \uBB38\uC11C\uC758 {{SKILL_DIR}}, ~/.claude/skills/<\uC774\uB984>, ~/.codex/skills/<\uC774\uB984> \uC740 skill_dir \uB85C \uBC14\uAFD4 \uC4F4\uB2E4. \uD30C\uC77C\uC740 read_file \uB85C \uC77D\uACE0 \uC2A4\uD06C\uB9BD\uD2B8\uB294 run \uC73C\uB85C \uB3CC\uB9B0\uB2E4.",
600
+ dependency_files: req,
601
+ files: files.sort().slice(0, 400)
602
+ },
603
+ null,
604
+ 2
605
+ );
606
+ }
607
+ exec(command, cwd, timeoutSec) {
608
+ return new Promise((resolve4) => {
609
+ const child = (0, import_node_child_process.spawn)(command, {
610
+ cwd,
611
+ shell: true,
612
+ env: this.env(),
613
+ windowsHide: true
614
+ });
615
+ let out = "";
616
+ const add = (b) => {
617
+ out += b.toString();
618
+ if (out.length > MAX_OUT * 4) out = out.slice(-MAX_OUT * 2);
619
+ };
620
+ child.stdout.on("data", add);
621
+ child.stderr.on("data", add);
622
+ let timedOut = false;
623
+ const t = setTimeout(() => {
624
+ timedOut = true;
625
+ killTree(child.pid);
626
+ }, timeoutSec * 1e3);
627
+ child.on("close", (code) => {
628
+ clearTimeout(t);
629
+ resolve4({ code, out, timedOut });
630
+ });
631
+ child.on("error", (e) => {
632
+ clearTimeout(t);
633
+ resolve4({ code: -1, out: out + String(e), timedOut });
634
+ });
635
+ });
636
+ }
637
+ async run(command, cwd, timeout, background) {
638
+ if (!command.trim()) return text("command \uAC00 \uBE44\uC5C8\uC2B5\uB2C8\uB2E4", true);
639
+ const dir = this.inDir(cwd || ".");
640
+ fs.mkdirSync(dir, { recursive: true });
641
+ this.log(
642
+ `\uC2E4\uD589${background ? " (\uBC31\uADF8\uB77C\uC6B4\uB4DC)" : ""}: ${command} [${path.relative(this.dir, dir) || "."}]`
643
+ );
644
+ if (background) {
645
+ const id = `job${++this.jobSeq}`;
646
+ const child = (0, import_node_child_process.spawn)(command, {
647
+ cwd: dir,
648
+ shell: true,
649
+ env: this.env(),
650
+ windowsHide: true
651
+ });
652
+ const job = {
653
+ id,
654
+ command,
655
+ cwd: dir,
656
+ started: Date.now(),
657
+ out: "",
658
+ kill: () => killTree(child.pid)
659
+ };
660
+ const add = (b) => {
661
+ job.out += b.toString();
662
+ if (job.out.length > MAX_OUT * 4) job.out = job.out.slice(-MAX_OUT * 2);
663
+ };
664
+ child.stdout.on("data", add);
665
+ child.stderr.on("data", add);
666
+ child.on("close", (code) => {
667
+ job.code = code;
668
+ job.ended = Date.now();
669
+ this.log(`\uC791\uC5C5 \uB05D: ${id} (\uCF54\uB4DC ${code})`);
670
+ });
671
+ child.on("error", (e) => {
672
+ job.out += String(e);
673
+ job.code = -1;
674
+ job.ended = Date.now();
675
+ });
676
+ this.jobs.set(id, job);
677
+ return text(
678
+ `\uC2DC\uC791\uD588\uC2B5\uB2C8\uB2E4: ${id}. job_status(id="${id}", wait=60) \uB85C \uBD05\uB2C8\uB2E4.`
679
+ );
680
+ }
681
+ const limit = Math.min(Math.max(timeout, 1), 100);
682
+ const r = await this.exec(command, dir, limit);
683
+ const head = r.timedOut ? `\uC2DC\uAC04 \uD55C\uB3C4(${limit}\uCD08)\uB97C \uB118\uC5B4 \uBA48\uCDC4\uC2B5\uB2C8\uB2E4. \uC624\uB798 \uAC78\uB9AC\uBA74 background=true \uB85C \uB3CC\uB9AC\uC138\uC694.
684
+ ` : `\uC885\uB8CC \uCF54\uB4DC ${r.code}
685
+ `;
686
+ return text(head + tail(r.out), r.timedOut || r.code !== 0);
687
+ }
688
+ async jobStatus(id, wait) {
689
+ if (!id) {
690
+ const list = [...this.jobs.values()].map((j2) => ({
691
+ id: j2.id,
692
+ command: j2.command.slice(0, 120),
693
+ running: j2.ended === void 0,
694
+ code: j2.code
695
+ }));
696
+ return text(JSON.stringify(list, null, 2) || "[]");
697
+ }
698
+ const j = this.jobs.get(id);
699
+ if (!j) return text("\uADF8\uB7F0 \uC791\uC5C5\uC774 \uC5C6\uC2B5\uB2C8\uB2E4", true);
700
+ const until = Date.now() + Math.min(Math.max(wait, 0), 100) * 1e3;
701
+ while (j.ended === void 0 && Date.now() < until)
702
+ await new Promise((r) => setTimeout(r, 500));
703
+ const secs = Math.round(((j.ended ?? Date.now()) - j.started) / 1e3);
704
+ const state = j.ended === void 0 ? `\uC2E4\uD589 \uC911 (${secs}\uCD08)` : `\uB05D\uB0A8 (\uCF54\uB4DC ${j.code}, ${secs}\uCD08)`;
705
+ return text(
706
+ `${j.id}: ${state}
707
+ ${tail(j.out)}`,
708
+ j.ended !== void 0 && j.code !== 0
709
+ );
710
+ }
711
+ // ── 실행 중인 Blender: BlenderMCP 애드온 소켓 (JSON 한 덩어리 보내고 JSON 한 덩어리 받기) ──
712
+ get blenderPort() {
713
+ return this.opts.blenderMcpPort ?? (Number(process.env.BLENDER_MCP_PORT) || 9876);
714
+ }
715
+ blenderSend(type, params, timeoutMs = 18e4) {
716
+ return new Promise((resolve4, reject) => {
717
+ const sock = net.createConnection({
718
+ host: "127.0.0.1",
719
+ port: this.blenderPort
720
+ });
721
+ let buf = Buffer.alloc(0);
722
+ const timer = setTimeout(() => {
723
+ sock.destroy();
724
+ reject(
725
+ new Error(
726
+ `Blender \uC751\uB2F5\uC774 ${timeoutMs / 1e3}\uCD08 \uC548\uC5D0 \uC624\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4`
727
+ )
728
+ );
729
+ }, timeoutMs);
730
+ sock.on("connect", () => sock.write(JSON.stringify({ type, params })));
731
+ sock.on("data", (d) => {
732
+ buf = Buffer.concat([buf, d]);
733
+ try {
734
+ const obj = JSON.parse(buf.toString("utf-8"));
735
+ clearTimeout(timer);
736
+ sock.end();
737
+ resolve4(obj);
738
+ } catch {
739
+ }
740
+ });
741
+ sock.on("error", (e) => {
742
+ clearTimeout(timer);
743
+ reject(e);
744
+ });
745
+ });
746
+ }
747
+ async blenderPing() {
748
+ try {
749
+ await this.blenderSend("get_scene_info", {}, 3e3);
750
+ return true;
751
+ } catch {
752
+ return false;
753
+ }
754
+ }
755
+ async blenderCall(type, params) {
756
+ try {
757
+ const r = await this.blenderSend(type, params);
758
+ if (r.status === "error")
759
+ return text(`Blender \uC624\uB958: ${str(r.message)}`, true);
760
+ const res = r.result ?? r;
761
+ return text(typeof res === "string" ? res : JSON.stringify(res, null, 2));
762
+ } catch (e) {
763
+ return text(
764
+ `\uC2E4\uD589 \uC911\uC778 Blender \uC5D0 \uBD99\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (localhost:${this.blenderPort}): ${e instanceof Error ? e.message : e}
765
+ Blender \uC5D0 BlenderMCP \uC560\uB4DC\uC628(github.com/ahujasid/blender-mcp \uC758 addon.py)\uC744 \uC124\uCE58\uD558\uACE0 N \uD328\uB110 > BlenderMCP > Start \uB97C \uB204\uB974\uC138\uC694. \uD5E4\uB4DC\uB9AC\uC2A4\uB85C \uCDA9\uBD84\uD558\uBA74 run \uC73C\uB85C blender -b \uB97C \uC4F0\uC138\uC694.`,
766
+ true
767
+ );
768
+ }
769
+ }
770
+ async uploadToStorage(p, folder) {
771
+ const abs = this.inDir(p);
772
+ if (!fs.existsSync(abs)) return text(`\uD30C\uC77C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${p}`, true);
773
+ try {
774
+ const url = await uploadFile(this.opts, abs, folder);
775
+ this.log(`\uC62C\uB9BC: ${path.basename(abs)} \u2192 ${url}`);
776
+ return text(
777
+ JSON.stringify({ uploaded: path.basename(abs), url }, null, 2)
778
+ );
779
+ } catch (e) {
780
+ return text(e instanceof Error ? e.message : String(e), true);
781
+ }
782
+ }
783
+ async imageGenerate(a) {
784
+ const out = this.inDir(str(a.out));
785
+ const parts = [{ type: "text", text: str(a.prompt) }];
786
+ for (const ip of Array.isArray(a.input_images) ? a.input_images : []) {
787
+ const abs = this.inDir(String(ip));
788
+ const mime = imageMime(abs) ?? "image/png";
789
+ parts.push({
790
+ type: "image_url",
791
+ image_url: {
792
+ url: `data:${mime};base64,${fs.readFileSync(abs).toString("base64")}`
793
+ }
794
+ });
795
+ }
796
+ const body = {
797
+ messages: [{ role: "user", content: parts }],
798
+ timeoutSeconds: 300
799
+ };
800
+ if (str(a.provider)) body.provider = str(a.provider);
801
+ if (str(a.model)) body.model = str(a.model);
802
+ try {
803
+ if (!this.opts.publicKey)
804
+ return text(
805
+ "\uC544\uC9C1 ConnectBase \uC571\uC5D0 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4 (\uD130\uB110 \uC900\uBE44 \uC804)",
806
+ true
807
+ );
808
+ const resp = await fetch(`${this.opts.baseUrl}/v1/public/ai/chat`, {
809
+ method: "POST",
810
+ headers: {
811
+ "Content-Type": "application/json",
812
+ "X-Public-Key": this.opts.publicKey
813
+ },
814
+ body: JSON.stringify(body)
815
+ });
816
+ const raw = await resp.text();
817
+ if (!resp.ok)
818
+ return text(
819
+ `ConnectBase \uADF8\uB9BC \uBAA8\uB378 \uD638\uCD9C \uC2E4\uD328 (HTTP ${resp.status}): ${raw.slice(0, 400)}`,
820
+ true
821
+ );
822
+ const r = JSON.parse(raw);
823
+ const images = r.images ?? [];
824
+ if (!images.length)
825
+ return text(
826
+ `\uBAA8\uB378(${str(r.provider)} ${str(r.model)})\uC774 \uADF8\uB9BC\uC744 \uB3CC\uB824\uC8FC\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4. \uADF8\uB9BC \uCD9C\uB825 \uBAA8\uB378(Gemini \uC774\uBBF8\uC9C0, OpenRouter \uC774\uBBF8\uC9C0 \uBAA8\uB378 \uB4F1)\uC744 \uC571 \uC124\uC815 > AI \uC5D0 \uB4F1\uB85D\uD558\uACE0 provider, model \uB85C \uC9C0\uC815\uD558\uC138\uC694.`,
827
+ true
828
+ );
829
+ const src = str(images[0].url);
830
+ const buf = src.startsWith("data:") ? Buffer.from(src.split(",", 2)[1], "base64") : Buffer.from(await (await fetch(src)).arrayBuffer());
831
+ fs.mkdirSync(path.dirname(out), { recursive: true });
832
+ fs.writeFileSync(out, buf);
833
+ return text(
834
+ `\uC800\uC7A5\uD588\uC2B5\uB2C8\uB2E4: ${out} (${buf.length}B). view_image \uB85C \uD655\uC778\uD558\uC138\uC694.`
835
+ );
836
+ } catch (e) {
837
+ return text(e instanceof Error ? e.message : String(e), true);
838
+ }
839
+ }
840
+ // ── MCP (Streamable HTTP, JSON 응답) ──
841
+ async handleRpc(msg) {
842
+ const id = msg.id;
843
+ const method = str(msg.method);
844
+ const ok = (result) => ({ jsonrpc: "2.0", id, result });
845
+ const fail = (code, message) => ({
846
+ jsonrpc: "2.0",
847
+ id,
848
+ error: { code, message }
849
+ });
850
+ if (id === void 0) return null;
851
+ switch (method) {
852
+ case "initialize": {
853
+ const want = str(msg.params?.protocolVersion);
854
+ return ok({
855
+ protocolVersion: PROTOCOL_VERSIONS.includes(want) ? want : PROTOCOL_VERSIONS[0],
856
+ capabilities: { tools: { listChanged: false } },
857
+ serverInfo: { name: "connectbase-local", version: "1.0.0" },
858
+ instructions: "\uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130\uC758 \uB85C\uCEEC \uC2E4\uD589\uAE30. \uACF5\uAC1C \uC2A4\uD0AC\uC774 \uC694\uAD6C\uD558\uB294 \uD30C\uC77C \uC77D\uAE30, \uC2A4\uD06C\uB9BD\uD2B8 \uC2E4\uD589, Blender(\uD5E4\uB4DC\uB9AC\uC2A4/\uC2E4\uD589 \uC911), ZBrush \uBE0C\uB9AC\uC9C0, \uADF8\uB9BC \uBCF4\uAE30\uB97C \uC5EC\uAE30\uC11C \uD55C\uB2E4. \uBA3C\uC800 local_info, \uC2A4\uD0AC\uC740 skill_install \uB85C \uBC1B\uB294\uB2E4."
859
+ });
860
+ }
861
+ case "ping":
862
+ return ok({});
863
+ case "tools/list":
864
+ return ok({
865
+ tools: this.tools.map(
866
+ ({ name, description, inputSchema, annotations }) => ({
867
+ name,
868
+ description,
869
+ inputSchema,
870
+ ...annotations ? { annotations } : {}
871
+ })
872
+ )
873
+ });
874
+ case "tools/call": {
875
+ const p = msg.params ?? {};
876
+ const tool = this.tools.find((t) => t.name === p.name);
877
+ if (!tool) return fail(-32602, `\uC5C6\uB294 \uB3C4\uAD6C: ${str(p.name)}`);
878
+ try {
879
+ return ok(await tool.run(p.arguments ?? {}));
880
+ } catch (e) {
881
+ return ok(text(e instanceof Error ? e.message : String(e), true));
882
+ }
883
+ }
884
+ default:
885
+ return fail(-32601, `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBA54\uC11C\uB4DC: ${method}`);
886
+ }
887
+ }
888
+ /** 127.0.0.1 에서만 듣는 MCP 서버. 밖에서는 터널(프록시 토큰)로만 들어온다. */
889
+ listen() {
890
+ const server = http.createServer(async (req, res) => {
891
+ if (req.method === "GET" || req.method === "DELETE") {
892
+ res.writeHead(req.method === "DELETE" ? 200 : 405, { Allow: "POST" }).end();
893
+ return;
894
+ }
895
+ if (req.method !== "POST") {
896
+ res.writeHead(405).end();
897
+ return;
898
+ }
899
+ const chunks = [];
900
+ for await (const c of req) chunks.push(c);
901
+ let body;
902
+ try {
903
+ body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
904
+ } catch {
905
+ res.writeHead(400, { "Content-Type": "application/json" }).end(
906
+ JSON.stringify({
907
+ jsonrpc: "2.0",
908
+ id: null,
909
+ error: { code: -32700, message: "parse error" }
910
+ })
911
+ );
912
+ return;
913
+ }
914
+ const msgs = Array.isArray(body) ? body : [body];
915
+ const replies = (await Promise.all(msgs.map((m) => this.handleRpc(m)))).filter(Boolean);
916
+ if (!replies.length) {
917
+ res.writeHead(202).end();
918
+ return;
919
+ }
920
+ const out = JSON.stringify(Array.isArray(body) ? replies : replies[0]);
921
+ res.writeHead(200, {
922
+ "Content-Type": "application/json",
923
+ "Mcp-Session-Id": "local"
924
+ }).end(out);
925
+ });
926
+ return new Promise((resolve4, reject) => {
927
+ server.once("error", reject);
928
+ server.listen(this.opts.port, "127.0.0.1", () => resolve4(server));
929
+ });
930
+ }
931
+ };
932
+ function killTree(pid) {
933
+ if (!pid) return;
934
+ try {
935
+ if (process.platform === "win32")
936
+ (0, import_node_child_process.spawn)("taskkill", ["/pid", String(pid), "/T", "/F"], {
937
+ windowsHide: true
938
+ });
939
+ else process.kill(pid, "SIGTERM");
940
+ } catch {
941
+ }
942
+ }
943
+ var uploadFile = async (_o, _abs, _folder) => {
944
+ throw new Error("\uD30C\uC77C \uC2A4\uD1A0\uB9AC\uC9C0 \uC62C\uB9AC\uAE30\uAC00 \uC544\uC9C1 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4");
945
+ };
946
+ function setUploader(fn) {
947
+ uploadFile = fn;
948
+ }
949
+
950
+ // src/local-command.ts
951
+ var LOCAL_SERVER_NAME = "\uB0B4 \uCEF4\uD4E8\uD130 (\uB85C\uCEEC \uC2E4\uD589\uAE30)";
952
+ var STATE_PATH = path2.join(os2.homedir(), ".connectbase", "local-runner.json");
953
+ function loadState() {
954
+ try {
955
+ const s = JSON.parse(fs2.readFileSync(STATE_PATH, "utf-8"));
956
+ return { apps: s.apps ?? {}, token: s.token };
957
+ } catch {
958
+ return { apps: {} };
959
+ }
960
+ }
961
+ function saveState(s) {
962
+ fs2.mkdirSync(path2.dirname(STATE_PATH), { recursive: true });
963
+ fs2.writeFileSync(STATE_PATH, `${JSON.stringify(s, null, 2)}
964
+ `, {
965
+ mode: 384
966
+ });
967
+ }
968
+ function localToken() {
969
+ const s = loadState();
970
+ if (!s.token) {
971
+ s.token = (0, import_node_crypto.randomBytes)(24).toString("base64url");
972
+ saveState(s);
973
+ }
974
+ return s.token;
975
+ }
976
+ function mcpUrlFor(baseUrl) {
977
+ if (process.env.CONNECTBASE_MCP_URL) return process.env.CONNECTBASE_MCP_URL;
978
+ try {
979
+ const u = new URL(baseUrl);
980
+ if (u.hostname.startsWith("api."))
981
+ return `${u.protocol}//mcp.${u.hostname.slice(4)}/mcp`;
982
+ } catch {
983
+ }
984
+ return "https://mcp.connectbase.world/mcp";
985
+ }
986
+ async function mcpTool(mcpUrl, secretKey, name, args) {
987
+ const headers = {
988
+ "Content-Type": "application/json",
989
+ Accept: "application/json, text/event-stream",
990
+ Authorization: `Bearer ${secretKey}`
991
+ };
992
+ const post = async (body) => {
993
+ const r = await fetch(mcpUrl, {
994
+ method: "POST",
995
+ headers,
996
+ body: JSON.stringify(body)
997
+ });
998
+ const sid = r.headers.get("mcp-session-id");
999
+ if (sid) headers["Mcp-Session-Id"] = sid;
1000
+ const raw = await r.text();
1001
+ if (!r.ok)
1002
+ throw new Error(
1003
+ `MCP ${name} \uC2E4\uD328 (HTTP ${r.status}): ${raw.slice(0, 300)}`
1004
+ );
1005
+ const json = raw.trimStart().startsWith("{") ? raw : raw.split("\n").filter((l) => l.startsWith("data:")).map((l) => l.slice(5).trim()).pop() ?? "{}";
1006
+ return JSON.parse(json);
1007
+ };
1008
+ await post({
1009
+ jsonrpc: "2.0",
1010
+ id: 1,
1011
+ method: "initialize",
1012
+ params: {
1013
+ protocolVersion: "2025-06-18",
1014
+ capabilities: {},
1015
+ clientInfo: { name: "connectbase-local", version: "1" }
1016
+ }
1017
+ });
1018
+ const res = await post({
1019
+ jsonrpc: "2.0",
1020
+ id: 2,
1021
+ method: "tools/call",
1022
+ params: { name, arguments: args }
1023
+ });
1024
+ const result = res.result ?? {};
1025
+ const t = (result.content ?? []).map((c) => c.text ?? "").join("");
1026
+ if (result.isError || res.error)
1027
+ throw new Error(`${name}: ${t || JSON.stringify(res.error)}`);
1028
+ try {
1029
+ return JSON.parse(t);
1030
+ } catch {
1031
+ return { text: t };
1032
+ }
1033
+ }
1034
+ async function ensurePublicKey(baseUrl, secretKey, appId, st) {
1035
+ if (st.publicKey) return st.publicKey;
1036
+ const r = await fetch(`${baseUrl}/v1/public/cli/apps/${appId}/public-keys`, {
1037
+ method: "POST",
1038
+ headers: { "Content-Type": "application/json", "X-Public-Key": secretKey },
1039
+ body: "{}"
1040
+ });
1041
+ if (r.status !== 201)
1042
+ throw new Error(`\uACF5\uAC1C \uD0A4\uB97C \uBC1C\uAE09\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (HTTP ${r.status})`);
1043
+ st.publicKey = (await r.json()).key;
1044
+ return st.publicKey;
1045
+ }
1046
+ async function registerServer(mcpUrl, secretKey, appId, url, token, st) {
1047
+ const serverUrl = `${url.replace(/\/+$/, "")}/mcp`;
1048
+ const auth = {
1049
+ auth_type: "custom_header",
1050
+ header_name: "X-Proxy-Token",
1051
+ header_value: token
1052
+ };
1053
+ if (!st.serverId) {
1054
+ const list = await mcpTool(mcpUrl, secretKey, "list_external_mcp_servers", {
1055
+ app_id: appId
1056
+ });
1057
+ const arr = (list.servers ?? list.items ?? list.data ?? []) || [];
1058
+ const found = Array.isArray(arr) ? arr.find((s) => s.name === LOCAL_SERVER_NAME) : void 0;
1059
+ if (found) st.serverId = found.id;
1060
+ }
1061
+ if (st.serverId) {
1062
+ if (st.serverUrl === serverUrl) return "\uADF8\uB300\uB85C";
1063
+ try {
1064
+ await mcpTool(mcpUrl, secretKey, "update_external_mcp_server", {
1065
+ app_id: appId,
1066
+ server_id: st.serverId,
1067
+ server_url: serverUrl,
1068
+ ...auth,
1069
+ enabled: true
1070
+ });
1071
+ st.serverUrl = serverUrl;
1072
+ return "\uC8FC\uC18C \uACE0\uCE68";
1073
+ } catch (e) {
1074
+ if (!String(e).includes("not found") && !String(e).includes("\uCC3E\uC744 \uC218 \uC5C6"))
1075
+ throw e;
1076
+ st.serverId = void 0;
1077
+ }
1078
+ }
1079
+ const created = await mcpTool(
1080
+ mcpUrl,
1081
+ secretKey,
1082
+ "create_external_mcp_server",
1083
+ {
1084
+ app_id: appId,
1085
+ name: LOCAL_SERVER_NAME,
1086
+ description: "\uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130\uC758 \uB85C\uCEEC \uC2E4\uD589\uAE30 (connectbase local). \uACF5\uAC1C \uC2A4\uD0AC\uC744 \uBC1B\uC544 references \uB97C \uC77D\uACE0 scripts \uB97C \uC2E4\uD589\uD558\uACE0, Blender(\uD5E4\uB4DC\uB9AC\uC2A4, \uC2E4\uD589 \uC911), ZBrush \uBE0C\uB9AC\uC9C0, Python, uv, Node, ffmpeg \uB97C \uC4F4\uB2E4.",
1087
+ server_url: serverUrl,
1088
+ transport_type: "streamable_http",
1089
+ ...auth
1090
+ }
1091
+ );
1092
+ st.serverId = String(
1093
+ created.id ?? created.server?.id ?? ""
1094
+ );
1095
+ st.serverUrl = serverUrl;
1096
+ return "\uC0C8\uB85C \uB4F1\uB85D";
1097
+ }
1098
+ function makeUploader(mcpUrl, getSt, save) {
1099
+ return async (o, abs, folder) => {
1100
+ if (!o.secretKey || !o.appId || !o.publicKey)
1101
+ throw new Error(
1102
+ "\uC544\uC9C1 ConnectBase \uC571\uC5D0 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4 (\uD130\uB110 \uC900\uBE44 \uC804)"
1103
+ );
1104
+ const st = getSt();
1105
+ const h = {
1106
+ "Content-Type": "application/json",
1107
+ "X-Public-Key": o.publicKey,
1108
+ "X-User-Secret-Key": o.secretKey
1109
+ };
1110
+ if (!st.storageId) {
1111
+ const r = await fetch(`${o.baseUrl}/v1/public/storages/files`, {
1112
+ headers: h
1113
+ });
1114
+ const body = await r.json().catch(() => ({}));
1115
+ const list = body.storages ?? body.items ?? body.data ?? body;
1116
+ const found = Array.isArray(list) ? list.find((s) => s.name === "\uB85C\uCEEC \uC2E4\uD589\uAE30 \uACB0\uACFC") : void 0;
1117
+ if (found) st.storageId = found.id;
1118
+ else {
1119
+ const c = await mcpTool(mcpUrl, o.secretKey, "create_file_storage", {
1120
+ app_id: o.appId,
1121
+ name: "\uB85C\uCEEC \uC2E4\uD589\uAE30 \uACB0\uACFC",
1122
+ description: "connectbase local \uC774 \uC62C\uB9B0 \uACB0\uACFC \uD30C\uC77C",
1123
+ // 실행기는 Origin 없는 서버 호출로 올린다
1124
+ allow_server_to_server: true
1125
+ });
1126
+ st.storageId = String(
1127
+ c.id ?? c.storage?.id ?? ""
1128
+ );
1129
+ }
1130
+ save();
1131
+ }
1132
+ const buf = fs2.readFileSync(abs);
1133
+ const name = path2.basename(abs);
1134
+ const mime = {
1135
+ ".glb": "model/gltf-binary",
1136
+ ".gltf": "model/gltf+json",
1137
+ ".png": "image/png",
1138
+ ".jpg": "image/jpeg",
1139
+ ".jpeg": "image/jpeg",
1140
+ ".webp": "image/webp",
1141
+ ".mp4": "video/mp4",
1142
+ ".fbx": "application/octet-stream",
1143
+ ".obj": "text/plain",
1144
+ ".json": "application/json"
1145
+ }[path2.extname(name).toLowerCase()] ?? "application/octet-stream";
1146
+ const base = `${o.baseUrl}/v1/public/storages/files/${st.storageId}`;
1147
+ const presign = () => fetch(
1148
+ `${base}/presigned-url/path/${encodeURIComponent(folder)}/${encodeURIComponent(name)}`,
1149
+ {
1150
+ method: "POST",
1151
+ headers: h,
1152
+ body: JSON.stringify({
1153
+ file_name: name,
1154
+ file_size: buf.length,
1155
+ mime_type: mime,
1156
+ overwrite: true
1157
+ })
1158
+ }
1159
+ );
1160
+ let pre = await presign();
1161
+ if (pre.status === 403 && (await pre.clone().text()).includes("server_to_server_denied")) {
1162
+ await mcpTool(mcpUrl, o.secretKey, "update_file_storage_security", {
1163
+ app_id: o.appId,
1164
+ storage_id: st.storageId,
1165
+ allow_server_to_server: true
1166
+ });
1167
+ pre = await presign();
1168
+ }
1169
+ if (!pre.ok)
1170
+ throw new Error(
1171
+ `\uC62C\uB9AC\uAE30 \uC900\uBE44 \uC2E4\uD328 (HTTP ${pre.status}): ${(await pre.text()).slice(0, 300)}`
1172
+ );
1173
+ const p = await pre.json();
1174
+ const put = await fetch(p.upload_url, {
1175
+ method: "PUT",
1176
+ headers: { "Content-Type": mime, ...p.upload_headers ?? {} },
1177
+ body: buf
1178
+ });
1179
+ if (!put.ok) throw new Error(`\uC62C\uB9AC\uAE30 \uC2E4\uD328 (HTTP ${put.status})`);
1180
+ const done = await fetch(`${base}/complete-upload`, {
1181
+ method: "POST",
1182
+ headers: h,
1183
+ body: JSON.stringify({ file_id: p.file_id })
1184
+ });
1185
+ if (!done.ok)
1186
+ throw new Error(
1187
+ `\uC62C\uB9AC\uAE30 \uB9C8\uBB34\uB9AC \uC2E4\uD328 (HTTP ${done.status}): ${(await done.text()).slice(0, 300)}`
1188
+ );
1189
+ return String((await done.json()).url ?? "");
1190
+ };
1191
+ }
1192
+ async function runLocal(config, opts, startTunnel2, out) {
1193
+ const dir = path2.resolve(
1194
+ opts.dir || path2.join(os2.homedir(), "ConnectBaseLocal")
1195
+ );
1196
+ const port = opts.port || 47800;
1197
+ const runner = new LocalRunner({
1198
+ dir,
1199
+ port,
1200
+ baseUrl: config.baseUrl,
1201
+ log: (l) => out.info(l)
1202
+ });
1203
+ await runner.listen();
1204
+ const programs = Object.entries(findPrograms()).map(([k, v]) => v ? k : `${k}(\uC5C6\uC74C)`).join(", ");
1205
+ out.success(`\uB85C\uCEEC \uC2E4\uD589\uAE30: http://127.0.0.1:${port}/mcp \uC791\uC5C5 \uD3F4\uB354: ${dir}`);
1206
+ out.info(`\uCC3E\uC740 \uD504\uB85C\uADF8\uB7A8: ${programs}`);
1207
+ const mcpUrl = mcpUrlFor(config.baseUrl);
1208
+ const token = localToken();
1209
+ let state = loadState();
1210
+ let current = {};
1211
+ setUploader(
1212
+ makeUploader(
1213
+ mcpUrl,
1214
+ () => current,
1215
+ () => saveState(state)
1216
+ )
1217
+ );
1218
+ await startTunnel2(port, config, {
1219
+ appId: opts.appId,
1220
+ force: opts.force,
1221
+ token,
1222
+ // 도구 호출은 ConnectBase 가 120초에서 끊는다(run, job_status 는 100초까지). 여유를 두고, 그림 결과는 base64 로 수 MB 다
1223
+ timeout: 180,
1224
+ maxBody: 64,
1225
+ onReady: (info2) => {
1226
+ void (async () => {
1227
+ state = loadState();
1228
+ current = state.apps[info2.appId] ?? {};
1229
+ state.apps[info2.appId] = current;
1230
+ runner.opts.appId = info2.appId;
1231
+ runner.opts.secretKey = info2.secretKey;
1232
+ try {
1233
+ runner.opts.publicKey = await ensurePublicKey(
1234
+ config.baseUrl,
1235
+ info2.secretKey,
1236
+ info2.appId,
1237
+ current
1238
+ );
1239
+ const how = await registerServer(
1240
+ mcpUrl,
1241
+ info2.secretKey,
1242
+ info2.appId,
1243
+ info2.url,
1244
+ token,
1245
+ current
1246
+ );
1247
+ saveState(state);
1248
+ out.success(
1249
+ `\uC571\uC758 \uC678\uBD80 MCP \uC11C\uBC84 "${LOCAL_SERVER_NAME}" ${how}. \uCF58\uC194 > AI \uB3C4\uAD6C > MCP \uC11C\uBC84\uC5D0\uC11C \uBCFC \uC218 \uC788\uC2B5\uB2C8\uB2E4.`
1250
+ );
1251
+ out.info(
1252
+ "AI \uAC00 \uC774 \uCEF4\uD4E8\uD130\uC5D0\uC11C \uBA85\uB839\uC744 \uC2E4\uD589\uD560 \uB54C\uB9C8\uB2E4 \uCF58\uC194\uC5D0\uC11C \uD655\uC778\uC744 \uBB3B\uC2B5\uB2C8\uB2E4. \uBB3B\uC9C0 \uC54A\uAC8C \uD558\uB824\uBA74 \uADF8 MCP \uC11C\uBC84\uC758 \uC790\uB3D9 \uC2B9\uC778\uC744 \uCF1C\uC138\uC694."
1253
+ );
1254
+ } catch (e) {
1255
+ saveState(state);
1256
+ out.warn(`MCP \uC11C\uBC84 \uB4F1\uB85D \uC2E4\uD328: ${e instanceof Error ? e.message : e}`);
1257
+ out.info(
1258
+ `\uCF58\uC194 > AI \uB3C4\uAD6C > MCP \uC11C\uBC84 > \uCD94\uAC00 \uC5D0\uC11C \uC9C1\uC811 \uB123\uC5B4\uB3C4 \uB429\uB2C8\uB2E4: \uC8FC\uC18C ${info2.url}/mcp, \uD5E4\uB354 X-Proxy-Token: ${token}`
1259
+ );
1260
+ }
1261
+ })();
1262
+ }
1263
+ });
1264
+ }
1265
+
1266
+ // src/tunnel-utils.ts
1267
+ var fs3 = __toESM(require("fs"));
1268
+ var os3 = __toESM(require("os"));
1269
+ var path3 = __toESM(require("path"));
82
1270
  function getTunnelLockDir() {
83
- const platform2 = os.platform();
1271
+ const platform2 = os3.platform();
84
1272
  if (platform2 === "darwin") {
85
- return path.join(
86
- os.homedir(),
1273
+ return path3.join(
1274
+ os3.homedir(),
87
1275
  "Library",
88
1276
  "Application Support",
89
1277
  "connectbase",
90
1278
  "tunnel-locks"
91
1279
  );
92
1280
  } else if (platform2 === "win32") {
93
- return path.join(
94
- process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local"),
1281
+ return path3.join(
1282
+ process.env.LOCALAPPDATA || path3.join(os3.homedir(), "AppData", "Local"),
95
1283
  "connectbase",
96
1284
  "tunnel-locks"
97
1285
  );
98
1286
  }
99
- const stateHome = process.env.XDG_STATE_HOME || path.join(os.homedir(), ".local", "state");
100
- return path.join(stateHome, "connectbase", "tunnel-locks");
1287
+ const stateHome = process.env.XDG_STATE_HOME || path3.join(os3.homedir(), ".local", "state");
1288
+ return path3.join(stateHome, "connectbase", "tunnel-locks");
101
1289
  }
102
1290
  function isProcessAlive(pid) {
103
1291
  try {
@@ -109,21 +1297,21 @@ function isProcessAlive(pid) {
109
1297
  }
110
1298
  function acquireTunnelLock(appID, port, force, version) {
111
1299
  const lockDir = getTunnelLockDir();
112
- fs.mkdirSync(lockDir, { recursive: true });
113
- const lockPath = path.join(lockDir, `${appID}-${port}.lock`);
1300
+ fs3.mkdirSync(lockDir, { recursive: true });
1301
+ const lockPath = path3.join(lockDir, `${appID}-${port}.lock`);
114
1302
  const lockData = {
115
1303
  pid: process.pid,
116
1304
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
117
1305
  appID,
118
1306
  port,
119
- host: os.hostname(),
1307
+ host: os3.hostname(),
120
1308
  version
121
1309
  };
122
1310
  if (!force) {
123
1311
  try {
124
- const fd = fs.openSync(lockPath, "wx");
125
- fs.writeSync(fd, JSON.stringify(lockData, null, 2));
126
- fs.closeSync(fd);
1312
+ const fd = fs3.openSync(lockPath, "wx");
1313
+ fs3.writeSync(fd, JSON.stringify(lockData, null, 2));
1314
+ fs3.closeSync(fd);
127
1315
  return lockPath;
128
1316
  } catch (e) {
129
1317
  if (e.code !== "EEXIST") {
@@ -132,7 +1320,7 @@ function acquireTunnelLock(appID, port, force, version) {
132
1320
  }
133
1321
  try {
134
1322
  const existing = JSON.parse(
135
- fs.readFileSync(lockPath, "utf-8")
1323
+ fs3.readFileSync(lockPath, "utf-8")
136
1324
  );
137
1325
  if (isProcessAlive(existing.pid)) {
138
1326
  return `LOCKED:${existing.pid}:${existing.startedAt}:${existing.host}`;
@@ -140,12 +1328,12 @@ function acquireTunnelLock(appID, port, force, version) {
140
1328
  } catch {
141
1329
  }
142
1330
  }
143
- fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2));
1331
+ fs3.writeFileSync(lockPath, JSON.stringify(lockData, null, 2));
144
1332
  return lockPath;
145
1333
  }
146
1334
  function releaseTunnelLock(lockPath) {
147
1335
  try {
148
- fs.unlinkSync(lockPath);
1336
+ fs3.unlinkSync(lockPath);
149
1337
  } catch {
150
1338
  }
151
1339
  }
@@ -176,7 +1364,7 @@ function handleTunnelError(msg, appId, localPort) {
176
1364
  }
177
1365
 
178
1366
  // src/cli.ts
179
- var VERSION = "6.21.1" ? "6.21.1" : getPackageVersion();
1367
+ var VERSION = "6.22.0" ? "6.22.0" : getPackageVersion();
180
1368
  var DEFAULT_BASE_URL = "https://api.connectbase.world";
181
1369
  var colors = {
182
1370
  reset: "\x1B[0m",
@@ -315,23 +1503,23 @@ var MIME_BY_EXT = {
315
1503
  ".safetensors": "application/octet-stream"
316
1504
  };
317
1505
  function guessMimeType(filePath) {
318
- if (ALLOWED_EXTENSIONLESS_FILES.has(path2.basename(filePath))) {
1506
+ if (ALLOWED_EXTENSIONLESS_FILES.has(path4.basename(filePath))) {
319
1507
  return "text/plain; charset=utf-8";
320
1508
  }
321
- return MIME_BY_EXT[path2.extname(filePath).toLowerCase()] || "application/octet-stream";
1509
+ return MIME_BY_EXT[path4.extname(filePath).toLowerCase()] || "application/octet-stream";
322
1510
  }
323
1511
  function isAllowedDeployExt(filePath) {
324
- if (ALLOWED_EXTENSIONLESS_FILES.has(path2.basename(filePath))) {
1512
+ if (ALLOWED_EXTENSIONLESS_FILES.has(path4.basename(filePath))) {
325
1513
  return true;
326
1514
  }
327
- return ALLOWED_EXTENSIONS.has(path2.extname(filePath).toLowerCase());
1515
+ return ALLOWED_EXTENSIONS.has(path4.extname(filePath).toLowerCase());
328
1516
  }
329
1517
  function isBinaryDeployExt(filePath) {
330
- return BINARY_EXTENSIONS.has(path2.extname(filePath).toLowerCase());
1518
+ return BINARY_EXTENSIONS.has(path4.extname(filePath).toLowerCase());
331
1519
  }
332
1520
  function isExtensionlessDataFile(filePath) {
333
- const base = path2.basename(filePath);
334
- return path2.extname(base) === "" && !ALLOWED_EXTENSIONLESS_FILES.has(base);
1521
+ const base = path4.basename(filePath);
1522
+ return path4.extname(base) === "" && !ALLOWED_EXTENSIONLESS_FILES.has(base);
335
1523
  }
336
1524
  var WEB_FILE_MAX_STORED_BYTES = 6 * 1024 * 1024 - 64 * 1024;
337
1525
  var DEPLOY_REQUEST_BUDGET_BYTES = 96 * 1024 * 1024;
@@ -412,10 +1600,10 @@ function loadConfig() {
412
1600
  baseUrl: envBaseUrl || DEFAULT_BASE_URL,
413
1601
  baseUrlFromRepo: false
414
1602
  };
415
- const rcPath = path2.join(process.cwd(), ".connectbaserc");
416
- if (fs2.existsSync(rcPath)) {
1603
+ const rcPath = path4.join(process.cwd(), ".connectbaserc");
1604
+ if (fs4.existsSync(rcPath)) {
417
1605
  try {
418
- const rcContent = JSON.parse(fs2.readFileSync(rcPath, "utf-8"));
1606
+ const rcContent = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
419
1607
  if (rcContent.publicKey) config.publicKey = rcContent.publicKey;
420
1608
  if (rcContent.secretKey) config.secretKey = rcContent.secretKey;
421
1609
  if (rcContent.storageId) config.storageId = rcContent.storageId;
@@ -440,16 +1628,16 @@ function collectDeployFiles(dir, options = {}) {
440
1628
  }
441
1629
  function collectFiles(dir, baseDir, skipped, options) {
442
1630
  const files = [];
443
- const entries = fs2.readdirSync(dir, { withFileTypes: true });
1631
+ const entries = fs4.readdirSync(dir, { withFileTypes: true });
444
1632
  for (const entry of entries) {
445
- const fullPath = path2.join(dir, entry.name);
446
- const relativePath = path2.relative(baseDir, fullPath);
1633
+ const fullPath = path4.join(dir, entry.name);
1634
+ const relativePath = path4.relative(baseDir, fullPath);
447
1635
  if (entry.isDirectory()) {
448
1636
  if (!entry.name.startsWith(".")) {
449
1637
  files.push(...collectFiles(fullPath, baseDir, skipped, options));
450
1638
  }
451
1639
  } else if (entry.isFile()) {
452
- const ext = path2.extname(entry.name).toLowerCase();
1640
+ const ext = path4.extname(entry.name).toLowerCase();
453
1641
  if (entry.name.startsWith(".")) {
454
1642
  continue;
455
1643
  }
@@ -461,9 +1649,9 @@ function collectFiles(dir, baseDir, skipped, options) {
461
1649
  const isBinary = extensionlessData || BINARY_EXTENSIONS.has(ext);
462
1650
  let content;
463
1651
  if (isBinary) {
464
- content = fs2.readFileSync(fullPath).toString("base64");
1652
+ content = fs4.readFileSync(fullPath).toString("base64");
465
1653
  } else {
466
- content = fs2.readFileSync(fullPath, "utf-8");
1654
+ content = fs4.readFileSync(fullPath, "utf-8");
467
1655
  }
468
1656
  const normalized = normalizeRelativePath(relativePath);
469
1657
  files.push({
@@ -489,7 +1677,7 @@ function formatSkippedFilesReport(skipped, limit = SKIPPED_FILES_LIST_LIMIT) {
489
1677
  }
490
1678
  const byExt = /* @__PURE__ */ new Map();
491
1679
  for (const p of skipped) {
492
- const ext = path2.extname(p).toLowerCase() || "(\uD655\uC7A5\uC790 \uC5C6\uC74C)";
1680
+ const ext = path4.extname(p).toLowerCase() || "(\uD655\uC7A5\uC790 \uC5C6\uC74C)";
493
1681
  byExt.set(ext, (byExt.get(ext) ?? 0) + 1);
494
1682
  }
495
1683
  const extSummary = [...byExt.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([ext, n]) => `${ext} ${n}\uAC1C`).join(", ");
@@ -569,7 +1757,7 @@ async function requestDeployPresign(baseStorageUrl, headers, files, timeoutMs) {
569
1757
  return parsed?.urls ?? [];
570
1758
  }
571
1759
  function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
572
- return new Promise((resolve2, reject) => {
1760
+ return new Promise((resolve4, reject) => {
573
1761
  let parsed;
574
1762
  try {
575
1763
  parsed = new URL(uploadUrl);
@@ -581,7 +1769,7 @@ function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
581
1769
  reject(new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5C5\uB85C\uB4DC URL \uC2A4\uD0B4: ${parsed.protocol}`));
582
1770
  return;
583
1771
  }
584
- const lib = parsed.protocol === "https:" ? https : http;
1772
+ const lib = parsed.protocol === "https:" ? https : http2;
585
1773
  const options = {
586
1774
  hostname: parsed.hostname,
587
1775
  port: parsed.port || (parsed.protocol === "https:" ? 443 : 80),
@@ -600,7 +1788,7 @@ function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
600
1788
  res.on("end", () => {
601
1789
  const status = res.statusCode || 0;
602
1790
  if (status >= 200 && status < 300) {
603
- resolve2();
1791
+ resolve4();
604
1792
  return;
605
1793
  }
606
1794
  reject(
@@ -735,15 +1923,15 @@ function apiErrorMessage(data, status) {
735
1923
  if (typeof data === "string") return data.trim() || fallback;
736
1924
  if (typeof data !== "object" || data === null) return fallback;
737
1925
  const body = data;
738
- const str = (v) => typeof v === "string" && v.trim() ? v.trim() : void 0;
1926
+ const str2 = (v) => typeof v === "string" && v.trim() ? v.trim() : void 0;
739
1927
  let message;
740
1928
  let suggestion;
741
1929
  if (typeof body.error === "object" && body.error !== null) {
742
1930
  const detail = body.error;
743
- message = str(detail.message) ?? str(detail.code);
744
- suggestion = str(detail.suggestion);
1931
+ message = str2(detail.message) ?? str2(detail.code);
1932
+ suggestion = str2(detail.suggestion);
745
1933
  } else {
746
- message = str(body.message) ?? str(body.error);
1934
+ message = str2(body.message) ?? str2(body.error);
747
1935
  }
748
1936
  if (!message) {
749
1937
  const raw = JSON.stringify(body);
@@ -752,10 +1940,10 @@ function apiErrorMessage(data, status) {
752
1940
  return suggestion ? `${message} (${suggestion})` : message;
753
1941
  }
754
1942
  async function makeRequest(url, method, headers, body, reqOpts = {}) {
755
- return new Promise((resolve2, reject) => {
1943
+ return new Promise((resolve4, reject) => {
756
1944
  const parsedUrl = new URL(url);
757
1945
  const isHttps = parsedUrl.protocol === "https:";
758
- const lib = isHttps ? https : http;
1946
+ const lib = isHttps ? https : http2;
759
1947
  const bodyBuffer = body ? Buffer.from(body, "utf-8") : null;
760
1948
  const options = {
761
1949
  hostname: parsedUrl.hostname,
@@ -778,12 +1966,12 @@ async function makeRequest(url, method, headers, body, reqOpts = {}) {
778
1966
  res.on("end", () => {
779
1967
  const data = Buffer.concat(chunks).toString("utf8");
780
1968
  try {
781
- resolve2({
1969
+ resolve4({
782
1970
  status: res.statusCode || 0,
783
1971
  data: data ? JSON.parse(data) : null
784
1972
  });
785
1973
  } catch {
786
- resolve2({ status: res.statusCode || 0, data });
1974
+ resolve4({ status: res.statusCode || 0, data });
787
1975
  }
788
1976
  });
789
1977
  });
@@ -816,27 +2004,27 @@ function computeDeployTimeout(totalBytes, override) {
816
2004
  return Math.max(DEPLOY_TIMEOUT_MIN_MS, DEPLOY_TIMEOUT_BASE_MS + sizeBased);
817
2005
  }
818
2006
  async function deploy(directory, config, isDev = false, deployOpts = {}) {
819
- const dir = path2.resolve(directory);
820
- if (!fs2.existsSync(dir)) {
2007
+ const dir = path4.resolve(directory);
2008
+ if (!fs4.existsSync(dir)) {
821
2009
  error(`\uB514\uB809\uD1A0\uB9AC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${dir}`);
822
2010
  process.exit(1);
823
2011
  }
824
- const pkgPath = path2.join(process.cwd(), "package.json");
825
- if (fs2.existsSync(pkgPath)) {
2012
+ const pkgPath = path4.join(process.cwd(), "package.json");
2013
+ if (fs4.existsSync(pkgPath)) {
826
2014
  try {
827
- const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
2015
+ const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
828
2016
  const pm = packageManagerCommands(detectPackageManager(process.cwd()));
829
2017
  const inside = runningInsidePackageScript(pkg.scripts ?? {});
830
2018
  for (const line of buildFirstHint(pkg, pm, inside)) warn(line);
831
2019
  } catch {
832
2020
  }
833
2021
  }
834
- if (!fs2.statSync(dir).isDirectory()) {
2022
+ if (!fs4.statSync(dir).isDirectory()) {
835
2023
  error(`${dir}\uB294 \uB514\uB809\uD1A0\uB9AC\uAC00 \uC544\uB2D9\uB2C8\uB2E4`);
836
2024
  process.exit(1);
837
2025
  }
838
- const indexPath = path2.join(dir, "index.html");
839
- if (!fs2.existsSync(indexPath)) {
2026
+ const indexPath = path4.join(dir, "index.html");
2027
+ if (!fs4.existsSync(indexPath)) {
840
2028
  error("index.html \uD30C\uC77C\uC774 \uD544\uC694\uD569\uB2C8\uB2E4");
841
2029
  process.exit(1);
842
2030
  }
@@ -1195,15 +2383,15 @@ function prompt(question) {
1195
2383
  input: process.stdin,
1196
2384
  output: process.stdout
1197
2385
  });
1198
- return new Promise((resolve2) => {
2386
+ return new Promise((resolve4) => {
1199
2387
  rl.question(question, (answer) => {
1200
2388
  rl.close();
1201
- resolve2(answer.trim());
2389
+ resolve4(answer.trim());
1202
2390
  });
1203
2391
  });
1204
2392
  }
1205
2393
  function promptSecret(question) {
1206
- return new Promise((resolve2) => {
2394
+ return new Promise((resolve4) => {
1207
2395
  process.stdout.write(question);
1208
2396
  const input = [];
1209
2397
  if (!process.stdin.isTTY) {
@@ -1213,7 +2401,7 @@ function promptSecret(question) {
1213
2401
  });
1214
2402
  rl.question("", (answer) => {
1215
2403
  rl.close();
1216
- resolve2(answer.trim());
2404
+ resolve4(answer.trim());
1217
2405
  });
1218
2406
  return;
1219
2407
  }
@@ -1228,7 +2416,7 @@ function promptSecret(question) {
1228
2416
  process.stdin.pause();
1229
2417
  process.stdin.removeListener("data", onData);
1230
2418
  process.stdout.write("\n");
1231
- resolve2(input.join("").trim());
2419
+ resolve4(input.join("").trim());
1232
2420
  return;
1233
2421
  } else if (code === 3) {
1234
2422
  process.stdin.setRawMode(false);
@@ -1279,8 +2467,8 @@ function browserOpenCommand(url, platform2 = process.platform) {
1279
2467
  function openBrowser(url) {
1280
2468
  const opener = browserOpenCommand(url);
1281
2469
  if (!opener) return;
1282
- const { spawn } = require("child_process");
1283
- const child = spawn(opener.command, opener.args, {
2470
+ const { spawn: spawn2 } = require("child_process");
2471
+ const child = spawn2(opener.command, opener.args, {
1284
2472
  stdio: "ignore",
1285
2473
  detached: true
1286
2474
  });
@@ -1291,7 +2479,7 @@ function openBrowser(url) {
1291
2479
  function browserAuthStartBody() {
1292
2480
  return {
1293
2481
  flow: "user_code",
1294
- hostname: os2.hostname(),
2482
+ hostname: os4.hostname(),
1295
2483
  os: `${process.platform} ${process.arch}`,
1296
2484
  cli_version: VERSION
1297
2485
  };
@@ -1347,7 +2535,7 @@ ${colors.cyan}\uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uB85C\uADF8\uC778\uD558\uC13
1347
2535
  process.stdout.write(
1348
2536
  `\r${colors.blue}${frame}${colors.reset} \uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uC2B9\uC778 \uB300\uAE30 \uC911...`
1349
2537
  );
1350
- await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
2538
+ await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
1351
2539
  try {
1352
2540
  const pollRes = await makeRequest(
1353
2541
  `${baseUrl}/v1/public/cli-auth/poll/${session_id}`,
@@ -1442,11 +2630,11 @@ ${colors.dim}\uC778\uC99D \uBC29\uC2DD\uC744 \uC120\uD0DD\uD558\uC138\uC694:${co
1442
2630
  return entered;
1443
2631
  }
1444
2632
  function saveSecretKeyToRc(secretKey, dir = process.cwd()) {
1445
- const rcPath = path2.join(dir, ".connectbaserc");
2633
+ const rcPath = path4.join(dir, ".connectbaserc");
1446
2634
  let rcData = {};
1447
- if (fs2.existsSync(rcPath)) {
2635
+ if (fs4.existsSync(rcPath)) {
1448
2636
  try {
1449
- rcData = JSON.parse(fs2.readFileSync(rcPath, "utf-8"));
2637
+ rcData = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
1450
2638
  } catch {
1451
2639
  }
1452
2640
  }
@@ -1484,11 +2672,11 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
1484
2672
  );
1485
2673
  process.exit(1);
1486
2674
  }
1487
- const rcPath = path2.join(cwd, ".connectbaserc");
2675
+ const rcPath = path4.join(cwd, ".connectbaserc");
1488
2676
  let existingRc = {};
1489
- if (fs2.existsSync(rcPath)) {
2677
+ if (fs4.existsSync(rcPath)) {
1490
2678
  try {
1491
- existingRc = JSON.parse(fs2.readFileSync(rcPath, "utf-8"));
2679
+ existingRc = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
1492
2680
  } catch {
1493
2681
  }
1494
2682
  if (nonInteractive) {
@@ -1531,7 +2719,7 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
1531
2719
  }
1532
2720
  let appId = "";
1533
2721
  let publicKey = "";
1534
- const projectName = path2.basename(cwd);
2722
+ const projectName = path4.basename(cwd);
1535
2723
  const reuseKeyIfSameApp = (selectedAppId) => {
1536
2724
  if (existingRc.appId === selectedAppId && existingRc.publicKey?.startsWith("cb_pk_")) {
1537
2725
  publicKey = existingRc.publicKey;
@@ -1614,10 +2802,10 @@ ${colors.dim}\uB0B4 \uC571 \uBAA9\uB85D:${colors.reset}`);
1614
2802
  `
1615
2803
  ${colors.blue}?${colors.reset} \uC120\uD0DD (\uBC88\uD638): `
1616
2804
  );
1617
- const num = parseInt(choice, 10);
1618
- if (num > 0 && num <= apps.length) {
1619
- appId = apps[num - 1].id;
1620
- success(`\uC120\uD0DD\uB428: ${apps[num - 1].name}`);
2805
+ const num2 = parseInt(choice, 10);
2806
+ if (num2 > 0 && num2 <= apps.length) {
2807
+ appId = apps[num2 - 1].id;
2808
+ success(`\uC120\uD0DD\uB428: ${apps[num2 - 1].name}`);
1621
2809
  if (!reuseKeyIfSameApp(appId)) await issuePublicKey(appId);
1622
2810
  }
1623
2811
  }
@@ -1713,10 +2901,10 @@ ${colors.dim}\uAE30\uC874 \uC6F9 \uC2A4\uD1A0\uB9AC\uC9C0:${colors.reset}`);
1713
2901
  `
1714
2902
  ${colors.blue}?${colors.reset} \uC120\uD0DD (\uBC88\uD638): `
1715
2903
  );
1716
- const num = parseInt(choice, 10);
1717
- if (num > 0 && num <= storages.length) {
1718
- storageId = storages[num - 1].id;
1719
- success(`\uC120\uD0DD\uB428: ${storages[num - 1].name}`);
2904
+ const num2 = parseInt(choice, 10);
2905
+ if (num2 > 0 && num2 <= storages.length) {
2906
+ storageId = storages[num2 - 1].id;
2907
+ success(`\uC120\uD0DD\uB428: ${storages[num2 - 1].name}`);
1720
2908
  }
1721
2909
  }
1722
2910
  if (!storageId) {
@@ -1806,17 +2994,17 @@ ${colors.dim}Claude Code\uC5D0\uC11C MCP\uAC00 \uC790\uB3D9 \uC5F0\uACB0\uB429\u
1806
2994
  `);
1807
2995
  }
1808
2996
  function detectBuildDir() {
1809
- if (fs2.existsSync(path2.join(process.cwd(), "dist"))) return "./dist";
1810
- if (fs2.existsSync(path2.join(process.cwd(), "build"))) return "./build";
1811
- if (fs2.existsSync(path2.join(process.cwd(), "out"))) return "./out";
1812
- const nextConfig = ["next.config.js", "next.config.mjs", "next.config.ts"].map((f) => path2.join(process.cwd(), f)).find((f) => fs2.existsSync(f));
1813
- if (nextConfig || fs2.existsSync(path2.join(process.cwd(), ".next"))) {
2997
+ if (fs4.existsSync(path4.join(process.cwd(), "dist"))) return "./dist";
2998
+ if (fs4.existsSync(path4.join(process.cwd(), "build"))) return "./build";
2999
+ if (fs4.existsSync(path4.join(process.cwd(), "out"))) return "./out";
3000
+ const nextConfig = ["next.config.js", "next.config.mjs", "next.config.ts"].map((f) => path4.join(process.cwd(), f)).find((f) => fs4.existsSync(f));
3001
+ if (nextConfig || fs4.existsSync(path4.join(process.cwd(), ".next"))) {
1814
3002
  if (nextConfig) {
1815
3003
  try {
1816
- const src = fs2.readFileSync(nextConfig, "utf-8");
3004
+ const src = fs4.readFileSync(nextConfig, "utf-8");
1817
3005
  if (!/output\s*:\s*['"]export['"]/.test(src)) {
1818
3006
  warn(
1819
- `Next.js \uAC10\uC9C0: \uC815\uC801 \uBC30\uD3EC\uD558\uB824\uBA74 ${path2.basename(nextConfig)}\uC5D0 output: 'export' \uC124\uC815\uC774 \uD544\uC694\uD569\uB2C8\uB2E4`
3007
+ `Next.js \uAC10\uC9C0: \uC815\uC801 \uBC30\uD3EC\uD558\uB824\uBA74 ${path4.basename(nextConfig)}\uC5D0 output: 'export' \uC124\uC815\uC774 \uD544\uC694\uD569\uB2C8\uB2E4`
1820
3008
  );
1821
3009
  }
1822
3010
  } catch {
@@ -1824,25 +3012,25 @@ function detectBuildDir() {
1824
3012
  }
1825
3013
  return "./out";
1826
3014
  }
1827
- if (fs2.existsSync(path2.join(process.cwd(), "vite.config.ts")) || fs2.existsSync(path2.join(process.cwd(), "vite.config.js")))
3015
+ if (fs4.existsSync(path4.join(process.cwd(), "vite.config.ts")) || fs4.existsSync(path4.join(process.cwd(), "vite.config.js")))
1828
3016
  return "./dist";
1829
3017
  return "./dist";
1830
3018
  }
1831
3019
  function writeSecretFile(filePath, content) {
1832
3020
  try {
1833
- if (fs2.existsSync(filePath)) fs2.chmodSync(filePath, 384);
3021
+ if (fs4.existsSync(filePath)) fs4.chmodSync(filePath, 384);
1834
3022
  } catch {
1835
3023
  }
1836
- fs2.writeFileSync(filePath, content, { mode: 384 });
3024
+ fs4.writeFileSync(filePath, content, { mode: 384 });
1837
3025
  }
1838
3026
  function addToGitignore(entry, basePath) {
1839
3027
  const dir = basePath || process.cwd();
1840
- const gitignorePath = path2.join(dir, ".gitignore");
1841
- if (fs2.existsSync(gitignorePath)) {
1842
- const content = fs2.readFileSync(gitignorePath, "utf-8");
3028
+ const gitignorePath = path4.join(dir, ".gitignore");
3029
+ if (fs4.existsSync(gitignorePath)) {
3030
+ const content = fs4.readFileSync(gitignorePath, "utf-8");
1843
3031
  const lines = content.split(/\r?\n/).map((l) => l.trim());
1844
3032
  if (!lines.includes(entry)) {
1845
- fs2.appendFileSync(gitignorePath, `
3033
+ fs4.appendFileSync(gitignorePath, `
1846
3034
  # Connect Base
1847
3035
  ${entry}
1848
3036
  `);
@@ -1851,7 +3039,7 @@ ${entry}
1851
3039
  info(`.gitignore\uC5D0 \uC774\uBBF8 ${entry}\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4`);
1852
3040
  }
1853
3041
  } else {
1854
- fs2.writeFileSync(gitignorePath, `# Connect Base
3042
+ fs4.writeFileSync(gitignorePath, `# Connect Base
1855
3043
  ${entry}
1856
3044
  `);
1857
3045
  success(".gitignore \uC0DD\uC131 \uC644\uB8CC");
@@ -1882,8 +3070,8 @@ function ancestorCommandLines(maxDepth = 8) {
1882
3070
  let ppid = 0;
1883
3071
  try {
1884
3072
  if (process.platform === "linux") {
1885
- cmd = fs2.readFileSync(`/proc/${pid}/cmdline`).toString("utf8").replace(/\0/g, " ").trim();
1886
- const stat = fs2.readFileSync(`/proc/${pid}/stat`, "utf8");
3073
+ cmd = fs4.readFileSync(`/proc/${pid}/cmdline`).toString("utf8").replace(/\0/g, " ").trim();
3074
+ const stat = fs4.readFileSync(`/proc/${pid}/stat`, "utf8");
1887
3075
  ppid = parseInt(
1888
3076
  stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1],
1889
3077
  10
@@ -1927,7 +3115,7 @@ function buildFirstHint(pkg, pm, insideScript) {
1927
3115
  function detectPackageManager(startDir = process.cwd()) {
1928
3116
  try {
1929
3117
  const pkg = JSON.parse(
1930
- fs2.readFileSync(path2.join(startDir, "package.json"), "utf-8")
3118
+ fs4.readFileSync(path4.join(startDir, "package.json"), "utf-8")
1931
3119
  );
1932
3120
  const declared = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : "";
1933
3121
  if (declared === "npm" || declared === "pnpm" || declared === "yarn" || declared === "bun") {
@@ -1943,13 +3131,13 @@ function detectPackageManager(startDir = process.cwd()) {
1943
3131
  ["package-lock.json", "npm"],
1944
3132
  ["npm-shrinkwrap.json", "npm"]
1945
3133
  ];
1946
- let dir = path2.resolve(startDir);
3134
+ let dir = path4.resolve(startDir);
1947
3135
  for (; ; ) {
1948
3136
  for (const [file, pm] of lockfiles) {
1949
- if (fs2.existsSync(path2.join(dir, file))) return pm;
3137
+ if (fs4.existsSync(path4.join(dir, file))) return pm;
1950
3138
  }
1951
- if (fs2.existsSync(path2.join(dir, ".git"))) break;
1952
- const parent = path2.dirname(dir);
3139
+ if (fs4.existsSync(path4.join(dir, ".git"))) break;
3140
+ const parent = path4.dirname(dir);
1953
3141
  if (parent === dir) break;
1954
3142
  dir = parent;
1955
3143
  }
@@ -1963,13 +3151,13 @@ function packageManagerCommands(pm) {
1963
3151
  };
1964
3152
  }
1965
3153
  function addDeployScript(deployDir, pm) {
1966
- const pkgPath = path2.join(process.cwd(), "package.json");
1967
- if (!fs2.existsSync(pkgPath)) {
3154
+ const pkgPath = path4.join(process.cwd(), "package.json");
3155
+ if (!fs4.existsSync(pkgPath)) {
1968
3156
  warn("package.json\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC5B4 deploy \uC2A4\uD06C\uB9BD\uD2B8\uB97C \uCD94\uAC00\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4");
1969
3157
  return { needsInstall: false };
1970
3158
  }
1971
3159
  try {
1972
- const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
3160
+ const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
1973
3161
  if (!pkg.scripts) pkg.scripts = {};
1974
3162
  const declared = (name) => Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
1975
3163
  let needsInstall = false;
@@ -1987,7 +3175,7 @@ function addDeployScript(deployDir, pm) {
1987
3175
  pkg.scripts.deploy = pkg.scripts.build ? `${pm.run("build")} && ${deployCmd}` : deployCmd;
1988
3176
  success("package.json\uC5D0 deploy \uC2A4\uD06C\uB9BD\uD2B8 \uCD94\uAC00 \uC644\uB8CC");
1989
3177
  }
1990
- fs2.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
3178
+ fs4.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
1991
3179
  `);
1992
3180
  if (needsInstall) {
1993
3181
  success(
@@ -2018,32 +3206,32 @@ function detectMonorepo(gitRoot) {
2018
3206
  root: gitRoot,
2019
3207
  isSubPackage: false
2020
3208
  };
2021
- if (fs2.existsSync(path2.join(gitRoot, "pnpm-workspace.yaml"))) {
3209
+ if (fs4.existsSync(path4.join(gitRoot, "pnpm-workspace.yaml"))) {
2022
3210
  result.type = "pnpm";
2023
- } else if (fs2.existsSync(path2.join(gitRoot, "turbo.json"))) {
3211
+ } else if (fs4.existsSync(path4.join(gitRoot, "turbo.json"))) {
2024
3212
  result.type = "turborepo";
2025
- } else if (fs2.existsSync(path2.join(gitRoot, "nx.json"))) {
3213
+ } else if (fs4.existsSync(path4.join(gitRoot, "nx.json"))) {
2026
3214
  result.type = "nx";
2027
- } else if (fs2.existsSync(path2.join(gitRoot, "lerna.json"))) {
3215
+ } else if (fs4.existsSync(path4.join(gitRoot, "lerna.json"))) {
2028
3216
  result.type = "lerna";
2029
3217
  } else {
2030
- const rootPkgPath = path2.join(gitRoot, "package.json");
2031
- if (fs2.existsSync(rootPkgPath)) {
3218
+ const rootPkgPath = path4.join(gitRoot, "package.json");
3219
+ if (fs4.existsSync(rootPkgPath)) {
2032
3220
  try {
2033
- const pkg = JSON.parse(fs2.readFileSync(rootPkgPath, "utf-8"));
3221
+ const pkg = JSON.parse(fs4.readFileSync(rootPkgPath, "utf-8"));
2034
3222
  if (pkg.workspaces) {
2035
- result.type = fs2.existsSync(path2.join(gitRoot, "yarn.lock")) ? "yarn" : "npm";
3223
+ result.type = fs4.existsSync(path4.join(gitRoot, "yarn.lock")) ? "yarn" : "npm";
2036
3224
  }
2037
3225
  } catch {
2038
3226
  }
2039
3227
  }
2040
3228
  }
2041
3229
  if (result.type !== "none" && cwd !== gitRoot) {
2042
- const cwdPkgPath = path2.join(cwd, "package.json");
2043
- if (fs2.existsSync(cwdPkgPath)) {
3230
+ const cwdPkgPath = path4.join(cwd, "package.json");
3231
+ if (fs4.existsSync(cwdPkgPath)) {
2044
3232
  result.isSubPackage = true;
2045
3233
  try {
2046
- const pkg = JSON.parse(fs2.readFileSync(cwdPkgPath, "utf-8"));
3234
+ const pkg = JSON.parse(fs4.readFileSync(cwdPkgPath, "utf-8"));
2047
3235
  result.subPackageName = pkg.name;
2048
3236
  } catch {
2049
3237
  }
@@ -2055,7 +3243,7 @@ var DOCS_MANIFEST_FILE = ".connectbase-manifest.json";
2055
3243
  function readDocsManifest(docsDir) {
2056
3244
  try {
2057
3245
  const parsed = JSON.parse(
2058
- fs2.readFileSync(path2.join(docsDir, DOCS_MANIFEST_FILE), "utf-8")
3246
+ fs4.readFileSync(path4.join(docsDir, DOCS_MANIFEST_FILE), "utf-8")
2059
3247
  );
2060
3248
  if (parsed && Array.isArray(parsed.files)) return parsed;
2061
3249
  } catch {
@@ -2117,14 +3305,14 @@ async function downloadDocs(baseDir, opts = {}) {
2117
3305
  info(`\uBAA8\uB178\uB808\uD3EC \uAC10\uC9C0: ${monorepo.type} (\uB8E8\uD2B8: ${gitRoot})`);
2118
3306
  if (monorepo.isSubPackage) {
2119
3307
  info(
2120
- `\uD604\uC7AC \uC11C\uBE0C \uD328\uD0A4\uC9C0: ${monorepo.subPackageName || path2.basename(process.cwd())}`
3308
+ `\uD604\uC7AC \uC11C\uBE0C \uD328\uD0A4\uC9C0: ${monorepo.subPackageName || path4.basename(process.cwd())}`
2121
3309
  );
2122
3310
  }
2123
3311
  }
2124
- const docsDir = path2.join(gitRoot, ".claude", "docs");
2125
- const rootClaudeMd = path2.join(gitRoot, "CLAUDE.md");
2126
- if (!fs2.existsSync(docsDir)) {
2127
- fs2.mkdirSync(docsDir, { recursive: true });
3312
+ const docsDir = path4.join(gitRoot, ".claude", "docs");
3313
+ const rootClaudeMd = path4.join(gitRoot, "CLAUDE.md");
3314
+ if (!fs4.existsSync(docsDir)) {
3315
+ fs4.mkdirSync(docsDir, { recursive: true });
2128
3316
  }
2129
3317
  if (!quiet) info("SDK \uAC1C\uBC1C \uAC00\uC774\uB4DC \uB2E4\uC6B4\uB85C\uB4DC \uC911...");
2130
3318
  try {
@@ -2141,21 +3329,21 @@ async function downloadDocs(baseDir, opts = {}) {
2141
3329
  const hasher = crypto.createHash("sha256");
2142
3330
  const newFiles = [];
2143
3331
  for (const section of sections) {
2144
- const safeName = path2.basename(section.filename);
3332
+ const safeName = path4.basename(section.filename);
2145
3333
  newFiles.push(safeName);
2146
3334
  hasher.update(safeName).update("\0").update(section.content).update("\0");
2147
3335
  }
2148
3336
  const contentHash = hasher.digest("hex");
2149
3337
  const prevManifest = readDocsManifest(docsDir);
2150
3338
  const allPresent = newFiles.every(
2151
- (f) => fs2.existsSync(path2.join(docsDir, f))
3339
+ (f) => fs4.existsSync(path4.join(docsDir, f))
2152
3340
  );
2153
3341
  if (prevManifest && prevManifest.contentHash === contentHash && allPresent) {
2154
3342
  if (!quiet) success("SDK \uBB38\uC11C\uAC00 \uC774\uBBF8 \uCD5C\uC2E0\uC785\uB2C8\uB2E4");
2155
3343
  updateRootClaudeMd(rootClaudeMd, quiet);
2156
3344
  if (monorepo.isSubPackage) {
2157
3345
  createSubPackageClaudeMd(
2158
- path2.join(process.cwd(), "CLAUDE.md"),
3346
+ path4.join(process.cwd(), "CLAUDE.md"),
2159
3347
  gitRoot,
2160
3348
  quiet
2161
3349
  );
@@ -2166,16 +3354,16 @@ async function downloadDocs(baseDir, opts = {}) {
2166
3354
 
2167
3355
  `;
2168
3356
  for (const section of sections) {
2169
- const safeName = path2.basename(section.filename);
2170
- fs2.writeFileSync(path2.join(docsDir, safeName), stamp + section.content);
3357
+ const safeName = path4.basename(section.filename);
3358
+ fs4.writeFileSync(path4.join(docsDir, safeName), stamp + section.content);
2171
3359
  }
2172
- const staleCandidates = prevManifest ? prevManifest.files.map((f) => path2.basename(f)) : LEGACY_DOC_FILES;
3360
+ const staleCandidates = prevManifest ? prevManifest.files.map((f) => path4.basename(f)) : LEGACY_DOC_FILES;
2173
3361
  for (const old of staleCandidates) {
2174
3362
  if (newFiles.includes(old)) continue;
2175
- const oldPath = path2.join(docsDir, old);
2176
- if (fs2.existsSync(oldPath)) {
3363
+ const oldPath = path4.join(docsDir, old);
3364
+ if (fs4.existsSync(oldPath)) {
2177
3365
  try {
2178
- fs2.unlinkSync(oldPath);
3366
+ fs4.unlinkSync(oldPath);
2179
3367
  if (!quiet) info(`\uC2A4\uD14C\uC77C \uBB38\uC11C \uC0AD\uC81C: ${old}`);
2180
3368
  } catch {
2181
3369
  }
@@ -2187,8 +3375,8 @@ async function downloadDocs(baseDir, opts = {}) {
2187
3375
  contentHash,
2188
3376
  files: newFiles
2189
3377
  };
2190
- fs2.writeFileSync(
2191
- path2.join(docsDir, DOCS_MANIFEST_FILE),
3378
+ fs4.writeFileSync(
3379
+ path4.join(docsDir, DOCS_MANIFEST_FILE),
2192
3380
  `${JSON.stringify(manifest, null, 2)}
2193
3381
  `
2194
3382
  );
@@ -2199,7 +3387,7 @@ async function downloadDocs(baseDir, opts = {}) {
2199
3387
  updateRootClaudeMd(rootClaudeMd, quiet);
2200
3388
  if (monorepo.isSubPackage) {
2201
3389
  createSubPackageClaudeMd(
2202
- path2.join(process.cwd(), "CLAUDE.md"),
3390
+ path4.join(process.cwd(), "CLAUDE.md"),
2203
3391
  gitRoot,
2204
3392
  quiet
2205
3393
  );
@@ -2218,10 +3406,10 @@ async function downloadDocs(baseDir, opts = {}) {
2218
3406
 
2219
3407
  \uC0C1\uC138 \uAD6C\uD604\uBC95\uC740 MCP \`search_sdk_docs\` \uB3C4\uAD6C\uB85C \uAC80\uC0C9\uD558\uC138\uC694.
2220
3408
  `;
2221
- fs2.writeFileSync(path2.join(docsDir, "project-rules.md"), fallbackContent);
3409
+ fs4.writeFileSync(path4.join(docsDir, "project-rules.md"), fallbackContent);
2222
3410
  updateRootClaudeMd(rootClaudeMd);
2223
3411
  if (monorepo.isSubPackage) {
2224
- const subClaudeMd = path2.join(process.cwd(), "CLAUDE.md");
3412
+ const subClaudeMd = path4.join(process.cwd(), "CLAUDE.md");
2225
3413
  createSubPackageClaudeMd(subClaudeMd, gitRoot);
2226
3414
  }
2227
3415
  success(`.claude/docs/ \uC0DD\uC131 \uC644\uB8CC (\uAE30\uBCF8)`);
@@ -2244,8 +3432,8 @@ function updateRootClaudeMd(claudeMdPath, quiet = false) {
2244
3432
  2. \uCF54\uB4DC\uB97C \uC791\uC131\uD558\uAE30 \uC804 \`search_sdk_docs("\uD0A4\uC6CC\uB4DC")\`\uB85C SDK \uAD6C\uD604 \uBC29\uBC95\uC744 \uAC80\uC0C9\uD558\uACE0, \uAC80\uC0C9 \uACB0\uACFC\uC758 \uCF54\uB4DC \uD328\uD134\uC744 \uADF8\uB300\uB85C \uB530\uB974\uC138\uC694
2245
3433
  3. \`search_sdk_docs\` \uB3C4\uAD6C\uAC00 \uBCF4\uC774\uC9C0 \uC54A\uC73C\uBA74 MCP\uAC00 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC740 \uC0C1\uD0DC\uC785\uB2C8\uB2E4 \u2014 \uC0AC\uC6A9\uC790\uC5D0\uAC8C \`npx connectbase-client mcp\` \uC2E4\uD589\uC744 \uC548\uB0B4\uD558\uC138\uC694 (Secret Key \uD544\uC694)
2246
3434
  ${endMarker}`;
2247
- if (fs2.existsSync(claudeMdPath)) {
2248
- let content = fs2.readFileSync(claudeMdPath, "utf-8");
3435
+ if (fs4.existsSync(claudeMdPath)) {
3436
+ let content = fs4.readFileSync(claudeMdPath, "utf-8");
2249
3437
  const startIdx = content.indexOf(startMarker);
2250
3438
  const endIdx = content.indexOf(endMarker);
2251
3439
  if (startIdx !== -1 && endIdx !== -1) {
@@ -2255,10 +3443,10 @@ ${endMarker}`;
2255
3443
 
2256
3444
  ${content.trimStart()}`;
2257
3445
  }
2258
- fs2.writeFileSync(claudeMdPath, content);
3446
+ fs4.writeFileSync(claudeMdPath, content);
2259
3447
  if (!quiet) info("CLAUDE.md\uC5D0 ConnectBase \uCC38\uC870 \uC5C5\uB370\uC774\uD2B8 \uC644\uB8CC");
2260
3448
  } else {
2261
- fs2.writeFileSync(claudeMdPath, `# \uD504\uB85C\uC81D\uD2B8
3449
+ fs4.writeFileSync(claudeMdPath, `# \uD504\uB85C\uC81D\uD2B8
2262
3450
 
2263
3451
  ${sdkBlock}
2264
3452
  `);
@@ -2268,7 +3456,7 @@ ${sdkBlock}
2268
3456
  function createSubPackageClaudeMd(subClaudeMdPath, gitRoot, quiet = false) {
2269
3457
  const startMarker = "<!-- CONNECTBASE_SUB_START -->";
2270
3458
  const endMarker = "<!-- CONNECTBASE_SUB_END -->";
2271
- const relPath = path2.relative(path2.dirname(subClaudeMdPath), gitRoot);
3459
+ const relPath = path4.relative(path4.dirname(subClaudeMdPath), gitRoot);
2272
3460
  const subBlock = `${startMarker}
2273
3461
  ## ConnectBase SDK
2274
3462
 
@@ -2280,8 +3468,8 @@ function createSubPackageClaudeMd(subClaudeMdPath, gitRoot, quiet = false) {
2280
3468
  2. \uCF54\uB4DC\uB97C \uC791\uC131\uD558\uAE30 \uC804 \`search_sdk_docs("\uD0A4\uC6CC\uB4DC")\`\uB85C SDK \uAD6C\uD604 \uBC29\uBC95\uC744 \uAC80\uC0C9\uD558\uC138\uC694
2281
3469
  3. \`search_sdk_docs\` \uB3C4\uAD6C\uAC00 \uBCF4\uC774\uC9C0 \uC54A\uC73C\uBA74 \uC0AC\uC6A9\uC790\uC5D0\uAC8C \`npx connectbase-client mcp\` \uC2E4\uD589\uC744 \uC548\uB0B4\uD558\uC138\uC694
2282
3470
  ${endMarker}`;
2283
- if (fs2.existsSync(subClaudeMdPath)) {
2284
- let content = fs2.readFileSync(subClaudeMdPath, "utf-8");
3471
+ if (fs4.existsSync(subClaudeMdPath)) {
3472
+ let content = fs4.readFileSync(subClaudeMdPath, "utf-8");
2285
3473
  const startIdx = content.indexOf(startMarker);
2286
3474
  const endIdx = content.indexOf(endMarker);
2287
3475
  if (startIdx !== -1 && endIdx !== -1) {
@@ -2294,11 +3482,11 @@ ${subBlock}
2294
3482
  } else {
2295
3483
  return;
2296
3484
  }
2297
- fs2.writeFileSync(subClaudeMdPath, content);
3485
+ fs4.writeFileSync(subClaudeMdPath, content);
2298
3486
  } else {
2299
- fs2.writeFileSync(
3487
+ fs4.writeFileSync(
2300
3488
  subClaudeMdPath,
2301
- `# ${path2.basename(path2.dirname(subClaudeMdPath))}
3489
+ `# ${path4.basename(path4.dirname(subClaudeMdPath))}
2302
3490
 
2303
3491
  ${subBlock}
2304
3492
  `
@@ -2316,7 +3504,7 @@ async function setupMcp(secretKey, baseUrl = DEFAULT_BASE_URL) {
2316
3504
  info(`MCP \uC124\uC815\uC740 \uD504\uB85C\uC81D\uD2B8 \uB8E8\uD2B8(${root})\uC5D0 \uC0DD\uC131\uB429\uB2C8\uB2E4`);
2317
3505
  }
2318
3506
  }
2319
- const mcpConfigPath = path2.join(root, ".mcp.json");
3507
+ const mcpConfigPath = path4.join(root, ".mcp.json");
2320
3508
  if (secretKey) {
2321
3509
  const check = await fetchAppsWithSecretKey(baseUrl, secretKey).catch(
2322
3510
  () => null
@@ -2351,17 +3539,17 @@ async function setupMcp(secretKey, baseUrl = DEFAULT_BASE_URL) {
2351
3539
  }
2352
3540
  };
2353
3541
  let mcpConfig = { mcpServers: {} };
2354
- if (fs2.existsSync(mcpConfigPath)) {
3542
+ if (fs4.existsSync(mcpConfigPath)) {
2355
3543
  try {
2356
- mcpConfig = JSON.parse(fs2.readFileSync(mcpConfigPath, "utf-8"));
3544
+ mcpConfig = JSON.parse(fs4.readFileSync(mcpConfigPath, "utf-8"));
2357
3545
  if (!mcpConfig.mcpServers || typeof mcpConfig.mcpServers !== "object") {
2358
3546
  mcpConfig.mcpServers = {};
2359
3547
  }
2360
3548
  } catch {
2361
3549
  const backupPath = `${mcpConfigPath}.backup`;
2362
- fs2.copyFileSync(mcpConfigPath, backupPath);
3550
+ fs4.copyFileSync(mcpConfigPath, backupPath);
2363
3551
  try {
2364
- fs2.chmodSync(backupPath, 384);
3552
+ fs4.chmodSync(backupPath, 384);
2365
3553
  } catch {
2366
3554
  }
2367
3555
  warn(`.mcp.json \uD30C\uC2F1 \uC2E4\uD328, \uBC31\uC5C5 \uC0DD\uC131: ${backupPath}`);
@@ -2422,14 +3610,14 @@ function findSubPackagesWithConfig(gitRoot) {
2422
3610
  const results = [];
2423
3611
  const candidates = ["apps", "packages", "projects", "services", "libs"];
2424
3612
  for (const candidate of candidates) {
2425
- const dir = path2.join(gitRoot, candidate);
2426
- if (!fs2.existsSync(dir)) continue;
3613
+ const dir = path4.join(gitRoot, candidate);
3614
+ if (!fs4.existsSync(dir)) continue;
2427
3615
  try {
2428
- const entries = fs2.readdirSync(dir, { withFileTypes: true });
3616
+ const entries = fs4.readdirSync(dir, { withFileTypes: true });
2429
3617
  for (const entry of entries) {
2430
3618
  if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
2431
- const subDir = path2.join(dir, entry.name);
2432
- if (fs2.existsSync(path2.join(subDir, ".connectbaserc"))) {
3619
+ const subDir = path4.join(dir, entry.name);
3620
+ if (fs4.existsSync(path4.join(subDir, ".connectbaserc"))) {
2433
3621
  results.push(subDir);
2434
3622
  }
2435
3623
  }
@@ -2437,13 +3625,13 @@ function findSubPackagesWithConfig(gitRoot) {
2437
3625
  }
2438
3626
  }
2439
3627
  try {
2440
- const entries = fs2.readdirSync(gitRoot, { withFileTypes: true });
3628
+ const entries = fs4.readdirSync(gitRoot, { withFileTypes: true });
2441
3629
  for (const entry of entries) {
2442
3630
  if (!entry.isDirectory() || entry.name.startsWith(".") || candidates.includes(entry.name))
2443
3631
  continue;
2444
3632
  if (entry.name === "node_modules") continue;
2445
- const subDir = path2.join(gitRoot, entry.name);
2446
- if (fs2.existsSync(path2.join(subDir, ".connectbaserc")) && !results.includes(subDir)) {
3633
+ const subDir = path4.join(gitRoot, entry.name);
3634
+ if (fs4.existsSync(path4.join(subDir, ".connectbaserc")) && !results.includes(subDir)) {
2447
3635
  results.push(subDir);
2448
3636
  }
2449
3637
  }
@@ -2487,7 +3675,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
2487
3675
  info(`ConnectBase\uB97C \uC0AC\uC6A9\uD558\uB294 \uC11C\uBE0C \uD328\uD0A4\uC9C0 ${subPackages.length}\uAC1C \uBC1C\uACAC:`);
2488
3676
  for (const sp of subPackages) {
2489
3677
  log(
2490
- ` ${colors.dim}\u2022 ${path2.relative(projectRoot, sp)}${colors.reset}`
3678
+ ` ${colors.dim}\u2022 ${path4.relative(projectRoot, sp)}${colors.reset}`
2491
3679
  );
2492
3680
  }
2493
3681
  }
@@ -2499,14 +3687,14 @@ ${colors.cyan}ConnectBase Update${colors.reset}
2499
3687
  }
2500
3688
  if (!opts.skipMcp) {
2501
3689
  log("");
2502
- const mcpConfigPath = path2.join(projectRoot, ".mcp.json");
2503
- if (fs2.existsSync(mcpConfigPath)) {
3690
+ const mcpConfigPath = path4.join(projectRoot, ".mcp.json");
3691
+ if (fs4.existsSync(mcpConfigPath)) {
2504
3692
  let secretKey = config.secretKey;
2505
3693
  if (!secretKey) {
2506
- const rootRcPath = path2.join(projectRoot, ".connectbaserc");
2507
- if (fs2.existsSync(rootRcPath)) {
3694
+ const rootRcPath = path4.join(projectRoot, ".connectbaserc");
3695
+ if (fs4.existsSync(rootRcPath)) {
2508
3696
  try {
2509
- const rc = JSON.parse(fs2.readFileSync(rootRcPath, "utf-8"));
3697
+ const rc = JSON.parse(fs4.readFileSync(rootRcPath, "utf-8"));
2510
3698
  secretKey = rc.secretKey;
2511
3699
  } catch {
2512
3700
  }
@@ -2517,7 +3705,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
2517
3705
  for (const sp of subPackages) {
2518
3706
  try {
2519
3707
  const rc = JSON.parse(
2520
- fs2.readFileSync(path2.join(sp, ".connectbaserc"), "utf-8")
3708
+ fs4.readFileSync(path4.join(sp, ".connectbaserc"), "utf-8")
2521
3709
  );
2522
3710
  if (rc.secretKey) {
2523
3711
  secretKey = rc.secretKey;
@@ -2529,7 +3717,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
2529
3717
  }
2530
3718
  if (secretKey) {
2531
3719
  try {
2532
- const mcpConfig = JSON.parse(fs2.readFileSync(mcpConfigPath, "utf-8"));
3720
+ const mcpConfig = JSON.parse(fs4.readFileSync(mcpConfigPath, "utf-8"));
2533
3721
  const servers = mcpConfig.mcpServers || {};
2534
3722
  if (servers["connect-base"]) {
2535
3723
  servers["connect-base"] = {
@@ -2568,15 +3756,15 @@ ${colors.green}\uC5C5\uB370\uC774\uD2B8 \uC644\uB8CC!${colors.reset}
2568
3756
  `);
2569
3757
  }
2570
3758
  function setupMonorepoRoot(projectRoot, monorepo) {
2571
- const rootPkgPath = path2.join(projectRoot, "package.json");
2572
- if (!fs2.existsSync(rootPkgPath)) {
3759
+ const rootPkgPath = path4.join(projectRoot, "package.json");
3760
+ if (!fs4.existsSync(rootPkgPath)) {
2573
3761
  warn(
2574
3762
  "\uD504\uB85C\uC81D\uD2B8 \uB8E8\uD2B8\uC5D0 package.json\uC774 \uC5C6\uC5B4 \uD3B8\uC758 \uC2A4\uD06C\uB9BD\uD2B8\uB97C \uCD94\uAC00\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4"
2575
3763
  );
2576
3764
  return;
2577
3765
  }
2578
3766
  try {
2579
- const pkg = JSON.parse(fs2.readFileSync(rootPkgPath, "utf-8"));
3767
+ const pkg = JSON.parse(fs4.readFileSync(rootPkgPath, "utf-8"));
2580
3768
  if (!pkg.scripts) pkg.scripts = {};
2581
3769
  let changed = false;
2582
3770
  if (!pkg.scripts["cb:update"]) {
@@ -2592,7 +3780,7 @@ function setupMonorepoRoot(projectRoot, monorepo) {
2592
3780
  changed = true;
2593
3781
  }
2594
3782
  if (changed) {
2595
- fs2.writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}
3783
+ fs4.writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}
2596
3784
  `);
2597
3785
  success("\uBAA8\uB178\uB808\uD3EC \uB8E8\uD2B8\uC5D0 \uD3B8\uC758 \uC2A4\uD06C\uB9BD\uD2B8 \uCD94\uAC00 \uC644\uB8CC");
2598
3786
  log(` ${colors.dim}\uC0AC\uC6A9\uBC95:${colors.reset}`);
@@ -2992,12 +4180,12 @@ ${colors.dim}\uB0B4 \uC571 \uBAA9\uB85D:${colors.reset}`);
2992
4180
  `
2993
4181
  ${colors.blue}?${colors.reset} \uC571 \uC120\uD0DD (\uBC88\uD638): `
2994
4182
  );
2995
- const num = parseInt(choice, 10);
2996
- if (num > 0 && num <= apps.length) {
2997
- success(`\uC120\uD0DD\uB428: ${apps[num - 1].name}`);
2998
- return { appId: apps[num - 1].id };
4183
+ const num2 = parseInt(choice, 10);
4184
+ if (num2 > 0 && num2 <= apps.length) {
4185
+ success(`\uC120\uD0DD\uB428: ${apps[num2 - 1].name}`);
4186
+ return { appId: apps[num2 - 1].id };
2999
4187
  }
3000
- const projectName = path2.basename(process.cwd());
4188
+ const projectName = path4.basename(process.cwd());
3001
4189
  const appName = await prompt(
3002
4190
  `${colors.blue}?${colors.reset} \uC571 \uC774\uB984 (${projectName}): `
3003
4191
  ) || projectName;
@@ -3048,9 +4236,9 @@ async function registerEndpointBinding(baseUrl, appId, secretKey, tunnelId, labe
3048
4236
  `"${label}" \uB77C\uBCA8\uC774 \uB2E4\uB978 \uD130\uB110\uC5D0 \uC774\uBBF8 \uBB36\uC5EC \uC788\uC2B5\uB2C8\uB2E4. \uC774 \uD130\uB110\uB85C \uC62E\uAE30\uB824\uBA74 \uCF58\uC194\uC5D0\uC11C endpoint \uC758 tunnel_id \uB97C \uC218\uC815(PATCH)\uD558\uC138\uC694.`
3049
4237
  );
3050
4238
  } else {
3051
- const text = await res.text().catch(() => "");
4239
+ const text2 = await res.text().catch(() => "");
3052
4240
  error(
3053
- `Endpoint "${label}" \uC790\uB3D9 \uB4F1\uB85D \uC2E4\uD328 (status ${res.status}): ${text || "(\uBE48 \uC751\uB2F5)"}`
4241
+ `Endpoint "${label}" \uC790\uB3D9 \uB4F1\uB85D \uC2E4\uD328 (status ${res.status}): ${text2 || "(\uBE48 \uC751\uB2F5)"}`
3054
4242
  );
3055
4243
  if (res.status === 401) {
3056
4244
  info("cb_sk_ Secret Key \uC778\uC9C0, \uCF58\uC194\uC5D0\uC11C \uD68C\uC218\uB418\uC9C0 \uC54A\uC558\uB294\uC9C0 \uD655\uC778\uD558\uC138\uC694.");
@@ -3080,11 +4268,11 @@ async function startTunnel(port, config, tunnelOpts) {
3080
4268
  info("Secret Key\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. \uBE0C\uB77C\uC6B0\uC800 \uB85C\uADF8\uC778\uC73C\uB85C \uBC1C\uAE09\uD569\uB2C8\uB2E4...");
3081
4269
  try {
3082
4270
  const sk = await browserAuthFlow();
3083
- const rcPath2 = path2.join(process.cwd(), ".connectbaserc");
4271
+ const rcPath2 = path4.join(process.cwd(), ".connectbaserc");
3084
4272
  let rcData = {};
3085
- if (fs2.existsSync(rcPath2)) {
4273
+ if (fs4.existsSync(rcPath2)) {
3086
4274
  try {
3087
- rcData = JSON.parse(fs2.readFileSync(rcPath2, "utf-8"));
4275
+ rcData = JSON.parse(fs4.readFileSync(rcPath2, "utf-8"));
3088
4276
  } catch {
3089
4277
  }
3090
4278
  }
@@ -3103,11 +4291,11 @@ async function startTunnel(port, config, tunnelOpts) {
3103
4291
  } else {
3104
4292
  config.secretKey = tunnelKey;
3105
4293
  }
3106
- const rcPath = path2.join(process.cwd(), ".connectbaserc");
4294
+ const rcPath = path4.join(process.cwd(), ".connectbaserc");
3107
4295
  let savedAppId = tunnelOpts?.appId || "";
3108
4296
  if (!savedAppId) {
3109
4297
  try {
3110
- const rc = JSON.parse(fs2.readFileSync(rcPath, "utf-8"));
4298
+ const rc = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
3111
4299
  if (rc.tunnelAppId) savedAppId = rc.tunnelAppId;
3112
4300
  } catch {
3113
4301
  }
@@ -3115,9 +4303,9 @@ async function startTunnel(port, config, tunnelOpts) {
3115
4303
  const { appId } = await resolveApp(tunnelKey, config.baseUrl, savedAppId);
3116
4304
  try {
3117
4305
  let rcData = {};
3118
- if (fs2.existsSync(rcPath)) {
4306
+ if (fs4.existsSync(rcPath)) {
3119
4307
  try {
3120
- rcData = JSON.parse(fs2.readFileSync(rcPath, "utf-8"));
4308
+ rcData = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
3121
4309
  } catch {
3122
4310
  }
3123
4311
  }
@@ -3199,7 +4387,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
3199
4387
  function connect() {
3200
4388
  const target = currentUrl();
3201
4389
  const targetHttps = target.protocol === "https:";
3202
- const lib = targetHttps ? https : http;
4390
+ const lib = targetHttps ? https : http2;
3203
4391
  const wsKey = crypto.randomBytes(16).toString("base64");
3204
4392
  const reqOptions = {
3205
4393
  hostname: target.hostname,
@@ -3392,7 +4580,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
3392
4580
  }
3393
4581
  }
3394
4582
  }
3395
- const localAgent = new http.Agent({ keepAlive: true, maxSockets: 64 });
4583
+ const localAgent = new http2.Agent({ keepAlive: true, maxSockets: 64 });
3396
4584
  function routeStreamData(sock, streamId, payload) {
3397
4585
  const f = streams.get(skey(sock, streamId));
3398
4586
  if (!f) return;
@@ -3412,6 +4600,36 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
3412
4600
  } catch {
3413
4601
  }
3414
4602
  }
4603
+ function rejectStreamOpen(sock, streamId, e) {
4604
+ const reason = e instanceof Error ? e.message : String(e);
4605
+ warn(`\uC694\uCCAD\uC744 \uB85C\uCEEC \uC11C\uBC84\uB85C \uB118\uAE30\uC9C0 \uBABB\uD574 400 \uC73C\uB85C \uB2F5\uD569\uB2C8\uB2E4: ${reason}`);
4606
+ streams.delete(skey(sock, streamId));
4607
+ sendControl(sock, {
4608
+ type: "stream_response",
4609
+ stream_id: streamId,
4610
+ status: 400,
4611
+ headers: { "content-type": "application/json" }
4612
+ });
4613
+ sendBinary(
4614
+ sock,
4615
+ streamId,
4616
+ Buffer.from(
4617
+ JSON.stringify({
4618
+ error: `tunnel client rejected the request: ${reason}`
4619
+ })
4620
+ )
4621
+ );
4622
+ sendControl(sock, {
4623
+ type: "stream_eof",
4624
+ stream_id: streamId,
4625
+ side: "upstream"
4626
+ });
4627
+ sendControl(sock, {
4628
+ type: "stream_close",
4629
+ stream_id: streamId,
4630
+ error: `request_rejected: ${reason}`
4631
+ });
4632
+ }
3415
4633
  function startHTTPStream(sock, streamId, open, localPort) {
3416
4634
  const method = open.method || "GET";
3417
4635
  const reqPath = open.path || "/";
@@ -3425,7 +4643,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
3425
4643
  localHeaders.host = `localhost:${localPort}`;
3426
4644
  let started = false;
3427
4645
  let cancelled = false;
3428
- const localReq = http.request(
4646
+ const localReq = http2.request(
3429
4647
  {
3430
4648
  hostname: "127.0.0.1",
3431
4649
  port: localPort,
@@ -3540,7 +4758,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
3540
4758
  localHeaders.upgrade = "websocket";
3541
4759
  let cancelled = false;
3542
4760
  let upstream = null;
3543
- const req = http.request({
4761
+ const req = http2.request({
3544
4762
  hostname: "127.0.0.1",
3545
4763
  port: localPort,
3546
4764
  path: fullPath,
@@ -3688,6 +4906,17 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
3688
4906
  const readyFeatures = Array.isArray(msg.features) ? msg.features : [];
3689
4907
  negotiatedWsOpcode = readyFeatures.includes("ws_opcode");
3690
4908
  success(`\uD130\uB110 \uD65C\uC131\uD654!`);
4909
+ if (tunnelOpts?.onReady && tunnelUrl) {
4910
+ try {
4911
+ tunnelOpts.onReady({
4912
+ url: tunnelUrl,
4913
+ proxyToken,
4914
+ appId,
4915
+ secretKey: tunnelKey
4916
+ });
4917
+ } catch {
4918
+ }
4919
+ }
3691
4920
  log(
3692
4921
  `${colors.green}\u2192${colors.reset} URL: ${colors.cyan}${tunnelUrl}${colors.reset}`
3693
4922
  );
@@ -3757,10 +4986,14 @@ ${colors.dim}Ctrl+C\uB85C \uC885\uB8CC${colors.reset}
3757
4986
  break;
3758
4987
  }
3759
4988
  const kind = msg.kind || "http";
3760
- if (kind === "ws") {
3761
- startWSStream(sock, sid, msg, localPort);
3762
- } else {
3763
- startHTTPStream(sock, sid, msg, localPort);
4989
+ try {
4990
+ if (kind === "ws") {
4991
+ startWSStream(sock, sid, msg, localPort);
4992
+ } else {
4993
+ startHTTPStream(sock, sid, msg, localPort);
4994
+ }
4995
+ } catch (e) {
4996
+ rejectStreamOpen(sock, sid, e);
3764
4997
  }
3765
4998
  break;
3766
4999
  }
@@ -3829,6 +5062,7 @@ ${colors.yellow}\uBA85\uB839\uC5B4:${colors.reset}
3829
5062
  promote [releaseId] QA \uAC80\uC99D \uD6C4 production \uBC18\uC601 (\uBBF8\uC9C0\uC815: \uCD5C\uC2E0 \uBC30\uD3EC, \uACFC\uAC70 id: \uB864\uBC31)
3830
5063
  releases \uBC30\uD3EC \uC774\uB825 \uC870\uD68C (release \uBC88\uD638/\uC0C1\uD0DC/production\xB7QA \uD3EC\uC778\uD130)
3831
5064
  tunnel <port> \uB85C\uCEEC \uC11C\uBE44\uC2A4\uB97C \uC778\uD130\uB137\uC5D0 \uB178\uCD9C
5065
+ local \uC774 \uCEF4\uD4E8\uD130\uC758 \uD504\uB85C\uADF8\uB7A8(Blender, ZBrush, Python \u2026)\uC744 ConnectBase AI \uAC00 \uC4F0\uAC8C \uC5F0\uACB0 (\uC2A4\uD0AC \uC2E4\uD589\uAE30)
3832
5066
 
3833
5067
  ${colors.yellow}\uCF54\uB4DC \uBD84\uC11D (MCP \uD1B5\uD574 \uC0AC\uC6A9):${colors.reset}
3834
5068
  AI \uB3C4\uAD6C(Claude, Cursor \uB4F1)\uC5D0\uC11C MCP\uB97C \uC124\uC815\uD558\uBA74 \uB2E4\uC74C \uBD84\uC11D \uAE30\uB2A5\uC744 \uC0AC\uC6A9\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4:
@@ -3970,8 +5204,8 @@ async function enforceBaseUrlPolicy(baseUrl, opts) {
3970
5204
  process.exit(1);
3971
5205
  }
3972
5206
  function isOutsideProject(dir, root) {
3973
- const relative2 = path2.relative(path2.resolve(root), path2.resolve(root, dir));
3974
- return relative2 === ".." || relative2.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative2);
5207
+ const relative3 = path4.relative(path4.resolve(root), path4.resolve(root, dir));
5208
+ return relative3 === ".." || relative3.startsWith(`..${path4.sep}`) || path4.isAbsolute(relative3);
3975
5209
  }
3976
5210
  function parseArgs(args) {
3977
5211
  const result = {
@@ -4003,6 +5237,10 @@ function parseArgs(args) {
4003
5237
  result.options.token = args[++i];
4004
5238
  } else if (arg === "-a" || arg === "--app") {
4005
5239
  result.options.appId = args[++i];
5240
+ } else if (arg === "--dir") {
5241
+ result.options.dir = args[++i];
5242
+ } else if (arg === "--port") {
5243
+ result.options.port = args[++i];
4006
5244
  } else if (arg === "--force") {
4007
5245
  result.options.force = "true";
4008
5246
  } else if (arg === "-y" || arg === "--yes") {
@@ -4117,8 +5355,8 @@ async function main() {
4117
5355
  if (parsed.options.skipDocs !== "true") {
4118
5356
  try {
4119
5357
  const docsRoot = getGitRoot() || getProjectRoot();
4120
- if (fs2.existsSync(
4121
- path2.join(docsRoot, ".claude", "docs", DOCS_MANIFEST_FILE)
5358
+ if (fs4.existsSync(
5359
+ path4.join(docsRoot, ".claude", "docs", DOCS_MANIFEST_FILE)
4122
5360
  )) {
4123
5361
  const refreshed = await downloadDocs(docsRoot, {
4124
5362
  quiet: true,
@@ -4149,6 +5387,23 @@ async function main() {
4149
5387
  } else {
4150
5388
  await listReleases(config);
4151
5389
  }
5390
+ } else if (parsed.command === "local") {
5391
+ const port = parsed.options.port ? parseInt(parsed.options.port, 10) : 47800;
5392
+ if (Number.isNaN(port) || port < 1 || port > 65535) {
5393
+ error("\uC720\uD6A8\uD55C \uD3EC\uD2B8 \uBC88\uD638\uB97C \uC785\uB825\uD558\uC138\uC694 (1-65535)");
5394
+ process.exit(1);
5395
+ }
5396
+ await runLocal(
5397
+ config,
5398
+ {
5399
+ dir: parsed.options.dir,
5400
+ port,
5401
+ appId: parsed.options.appId,
5402
+ force: parsed.options.force === "true"
5403
+ },
5404
+ (p, c, o) => startTunnel(p, c, o),
5405
+ { info, success, warn }
5406
+ );
4152
5407
  } else if (parsed.command === "tunnel") {
4153
5408
  const portStr = parsed.args[0];
4154
5409
  if (!portStr) {