connectbase-client 6.21.2 → 6.23.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/CHANGELOG.md +32 -0
- package/dist/cli.js +1639 -195
- package/dist/connect-base.umd.js +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -68,36 +68,1438 @@ __export(cli_exports, {
|
|
|
68
68
|
});
|
|
69
69
|
module.exports = __toCommonJS(cli_exports);
|
|
70
70
|
var crypto = __toESM(require("crypto"));
|
|
71
|
-
var
|
|
72
|
-
var
|
|
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/
|
|
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 blenderLive = await this.blenderPing();
|
|
224
|
+
return text(
|
|
225
|
+
JSON.stringify(
|
|
226
|
+
{
|
|
227
|
+
os: `${process.platform} ${os.release()} ${process.arch}`,
|
|
228
|
+
work_dir: this.dir,
|
|
229
|
+
skills_dir: this.skillsDir,
|
|
230
|
+
installed_skills: this.listSkills().map((k) => k.name),
|
|
231
|
+
programs: this.programs,
|
|
232
|
+
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)`,
|
|
233
|
+
notes: [
|
|
234
|
+
"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.",
|
|
235
|
+
"\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."
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
null,
|
|
239
|
+
2
|
|
240
|
+
)
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "read_skill",
|
|
246
|
+
// 설명은 tools/list 때 설치된 스킬 목록으로 채운다 (toolList)
|
|
247
|
+
description: "",
|
|
248
|
+
inputSchema: {
|
|
249
|
+
type: "object",
|
|
250
|
+
properties: {
|
|
251
|
+
name: { type: "string", description: "\uC2A4\uD0AC \uC774\uB984 (\uBAA9\uB85D\uC758 \uC774\uB984)" }
|
|
252
|
+
},
|
|
253
|
+
required: ["name"]
|
|
254
|
+
},
|
|
255
|
+
annotations: ro,
|
|
256
|
+
run: async (a) => {
|
|
257
|
+
const k = this.listSkills().find((x) => x.name === str(a.name));
|
|
258
|
+
if (!k)
|
|
259
|
+
return text(
|
|
260
|
+
`\uC124\uCE58\uB41C \uC2A4\uD0AC\uC774 \uC544\uB2D9\uB2C8\uB2E4: ${str(a.name)}
|
|
261
|
+
${this.skillIndexText()}`,
|
|
262
|
+
true
|
|
263
|
+
);
|
|
264
|
+
const body = fs.readFileSync(path.join(k.dir, "SKILL.md"), "utf-8").split("{{SKILL_DIR}}").join(k.dir);
|
|
265
|
+
const head = `> \uC2A4\uD0AC \uD3F4\uB354(skill_dir): ${k.dir}
|
|
266
|
+
> \uC774 \uC2A4\uD0AC\uC740 \uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130\uC5D0\uC11C \uB3C8\uB2E4. \uBCF8\uBB38\uC758 {{SKILL_DIR}}, ~/.claude/skills/<\uC774\uB984>, ~/.codex/skills/<\uC774\uB984> \uC740 \uC704 skill_dir(\uB2E4\uB978 \uC2A4\uD0AC\uC774\uBA74 \uADF8 \uC2A4\uD0AC \uD3F4\uB354)\uB85C \uBC14\uAFD4 \uC77D\uB294\uB2E4.
|
|
267
|
+
> \uC178 \uBA85\uB839\uC740 run(90\uCD08 \uB118\uC73C\uBA74 background=true \uB4A4 job_status), \uD30C\uC77C\uC740 read_file, write_file, list_files, \uADF8\uB9BC \uD655\uC778\uC740 view_image, \uADF8\uB9BC \uC0DD\uC131\uC740 image_generate, \uB0B4\uB824\uBC1B\uAE30\uB294 download, \uACB0\uACFC \uAC74\uB124\uAE30\uB294 upload_to_storage, \uC2E4\uD589 \uC911\uC778 Blender \uB294 execute_blender_code \uB4F1\uC73C\uB85C \uD55C\uB2E4.
|
|
268
|
+
> \uD544\uC694\uD55C \uD504\uB85C\uADF8\uB7A8\uC774 \uC5C6\uC73C\uBA74(local_info \uB85C \uD655\uC778) \uC124\uCE58 \uBC29\uBC95\uC744 \uC54C\uB824 \uC8FC\uACE0 \uAE30\uB2E4\uB9B0\uB2E4. \uD558\uC704 \uC5D0\uC774\uC804\uD2B8\uB85C \uAC80\uD1A0\uD558\uB77C\uB294 \uACF3\uC740 \uC2A4\uC2A4\uB85C \uC0C8 \uB208\uC73C\uB85C \uB2E4\uC2DC \uBCF8\uB2E4.
|
|
269
|
+
|
|
270
|
+
`;
|
|
271
|
+
return text(head + body);
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: "skill_install",
|
|
276
|
+
description: "\uC0AC\uC6A9\uC790\uAC00 \uC6D0\uD560 \uB54C \uC2A4\uD0AC\uC744 \uC774 \uCEF4\uD4E8\uD130\uC5D0 \uC124\uCE58\uD55C\uB2E4 (SKILL.md \uC640 references/, scripts/ \uB97C \uD1B5\uC9F8\uB85C). source: GitHub 'owner/repo' (\uC800\uC7A5\uC18C\uC758 \uC2A4\uD0AC \uBAA8\uB450), 'owner/repo/\uD3F4\uB354[@ref]' (\uADF8 \uD3F4\uB354\uC758 \uC2A4\uD0AC), github.com \uC8FC\uC18C, \uB610\uB294 \uC774 \uCEF4\uD4E8\uD130\uC758 \uD3F4\uB354 \uACBD\uB85C. update=true \uBA74 \uC774\uBBF8 \uC788\uB294 \uAC83\uB3C4 \uB2E4\uC2DC \uBC1B\uB294\uB2E4.",
|
|
277
|
+
inputSchema: {
|
|
278
|
+
type: "object",
|
|
279
|
+
properties: {
|
|
280
|
+
source: {
|
|
281
|
+
type: "string",
|
|
282
|
+
description: "owner/repo[/\uD3F4\uB354][@ref], GitHub \uC8FC\uC18C, \uB610\uB294 \uD3F4\uB354 \uACBD\uB85C"
|
|
283
|
+
},
|
|
284
|
+
update: { type: "boolean" }
|
|
285
|
+
},
|
|
286
|
+
required: ["source"]
|
|
287
|
+
},
|
|
288
|
+
run: async (a) => this.skillInstall(str(a.source), a.update === true)
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: "list_files",
|
|
292
|
+
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.",
|
|
293
|
+
inputSchema: {
|
|
294
|
+
type: "object",
|
|
295
|
+
properties: { path: { type: "string" }, depth: { type: "number" } }
|
|
296
|
+
},
|
|
297
|
+
annotations: ro,
|
|
298
|
+
run: async (a) => {
|
|
299
|
+
const root = this.inDir(str(a.path, "."));
|
|
300
|
+
const depth = Math.min(num(a.depth, 1), 4);
|
|
301
|
+
const lines = [];
|
|
302
|
+
const walk = (d, lvl) => {
|
|
303
|
+
for (const n of fs.readdirSync(d, { withFileTypes: true }).sort((x, y) => x.name.localeCompare(y.name))) {
|
|
304
|
+
if (n.name === "node_modules" || n.name === ".git" || n.name === "__pycache__")
|
|
305
|
+
continue;
|
|
306
|
+
const p = path.join(d, n.name);
|
|
307
|
+
const rel = path.relative(this.dir, p);
|
|
308
|
+
if (n.isDirectory()) {
|
|
309
|
+
lines.push(`${rel}/`);
|
|
310
|
+
if (lvl < depth) walk(p, lvl + 1);
|
|
311
|
+
} else lines.push(`${rel} ${fs.statSync(p).size}B`);
|
|
312
|
+
if (lines.length > 2e3) return;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
walk(root, 1);
|
|
316
|
+
return text(lines.join("\n") || "(\uBE44\uC5B4 \uC788\uC74C)");
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "read_file",
|
|
321
|
+
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.",
|
|
322
|
+
inputSchema: {
|
|
323
|
+
type: "object",
|
|
324
|
+
properties: {
|
|
325
|
+
path: { type: "string" },
|
|
326
|
+
offset: { type: "number", description: "\uC2DC\uC791 \uAE00\uC790 \uC704\uCE58" }
|
|
327
|
+
},
|
|
328
|
+
required: ["path"]
|
|
329
|
+
},
|
|
330
|
+
annotations: ro,
|
|
331
|
+
run: async (a) => {
|
|
332
|
+
const p = this.inDir(str(a.path));
|
|
333
|
+
const all = fs.readFileSync(p, "utf-8").split("{{SKILL_DIR}}").join(this.skillDirOf(p) ?? "{{SKILL_DIR}}");
|
|
334
|
+
const off = Math.max(0, num(a.offset, 0));
|
|
335
|
+
const part = all.slice(off, off + MAX_READ);
|
|
336
|
+
const more = off + MAX_READ < all.length ? `
|
|
337
|
+
|
|
338
|
+
\u2026(\uC774\uC5B4\uC11C \uC77D\uAE30: offset=${off + MAX_READ}, \uC804\uCCB4 ${all.length}\uC790)` : "";
|
|
339
|
+
return text(part + more);
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: "write_file",
|
|
344
|
+
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.",
|
|
345
|
+
inputSchema: {
|
|
346
|
+
type: "object",
|
|
347
|
+
properties: { path: { type: "string" }, content: { type: "string" } },
|
|
348
|
+
required: ["path", "content"]
|
|
349
|
+
},
|
|
350
|
+
run: async (a) => {
|
|
351
|
+
const p = this.inDir(str(a.path));
|
|
352
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
353
|
+
fs.writeFileSync(p, str(a.content));
|
|
354
|
+
return text(`\uC37C\uC2B5\uB2C8\uB2E4: ${p} (${Buffer.byteLength(str(a.content))}B)`);
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: "run",
|
|
359
|
+
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.",
|
|
360
|
+
inputSchema: {
|
|
361
|
+
type: "object",
|
|
362
|
+
properties: {
|
|
363
|
+
command: { type: "string" },
|
|
364
|
+
cwd: {
|
|
365
|
+
type: "string",
|
|
366
|
+
description: "\uC791\uC5C5 \uD3F4\uB354 \uAE30\uC900 (\uAE30\uBCF8 \uC791\uC5C5 \uD3F4\uB354)"
|
|
367
|
+
},
|
|
368
|
+
timeout: { type: "number", description: "\uCD08 (\uAE30\uBCF8 90, \uCD5C\uB300 100)" },
|
|
369
|
+
background: { type: "boolean" }
|
|
370
|
+
},
|
|
371
|
+
required: ["command"]
|
|
372
|
+
},
|
|
373
|
+
run: async (a) => this.run(
|
|
374
|
+
str(a.command),
|
|
375
|
+
str(a.cwd, "."),
|
|
376
|
+
num(a.timeout, 90),
|
|
377
|
+
a.background === true
|
|
378
|
+
)
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: "job_status",
|
|
382
|
+
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.",
|
|
383
|
+
inputSchema: {
|
|
384
|
+
type: "object",
|
|
385
|
+
properties: {
|
|
386
|
+
id: { type: "string" },
|
|
387
|
+
wait: {
|
|
388
|
+
type: "number",
|
|
389
|
+
description: "\uB05D\uB0A0 \uB54C\uAE4C\uC9C0 \uAE30\uB2E4\uB9B4 \uCD08 (\uCD5C\uB300 100)"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
annotations: ro,
|
|
394
|
+
run: async (a) => this.jobStatus(str(a.id), num(a.wait, 0))
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: "job_stop",
|
|
398
|
+
description: "background \uC791\uC5C5\uC744 \uBA48\uCD98\uB2E4.",
|
|
399
|
+
inputSchema: {
|
|
400
|
+
type: "object",
|
|
401
|
+
properties: { id: { type: "string" } },
|
|
402
|
+
required: ["id"]
|
|
403
|
+
},
|
|
404
|
+
run: async (a) => {
|
|
405
|
+
const j = this.jobs.get(str(a.id));
|
|
406
|
+
if (!j) return text("\uADF8\uB7F0 \uC791\uC5C5\uC774 \uC5C6\uC2B5\uB2C8\uB2E4", true);
|
|
407
|
+
j.kill();
|
|
408
|
+
return text(`\uBA48\uCDA4 \uC694\uCCAD: ${j.id}`);
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: "view_image",
|
|
413
|
+
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.",
|
|
414
|
+
inputSchema: {
|
|
415
|
+
type: "object",
|
|
416
|
+
properties: { path: { type: "string" } },
|
|
417
|
+
required: ["path"]
|
|
418
|
+
},
|
|
419
|
+
annotations: ro,
|
|
420
|
+
run: async (a) => {
|
|
421
|
+
const p = this.inDir(str(a.path));
|
|
422
|
+
const mime = imageMime(p);
|
|
423
|
+
if (!mime)
|
|
424
|
+
return text(
|
|
425
|
+
"\uADF8\uB9BC \uD30C\uC77C(png, jpg, webp, gif)\uB9CC \uBCFC \uC218 \uC788\uC2B5\uB2C8\uB2E4",
|
|
426
|
+
true
|
|
427
|
+
);
|
|
428
|
+
const buf = fs.readFileSync(p);
|
|
429
|
+
if (buf.length > MAX_IMAGE)
|
|
430
|
+
return text(
|
|
431
|
+
`\uADF8\uB9BC\uC774 \uB108\uBB34 \uD07D\uB2C8\uB2E4 (${buf.length}B). \uB354 \uC791\uAC8C \uB80C\uB354\uD574 \uC8FC\uC138\uC694`,
|
|
432
|
+
true
|
|
433
|
+
);
|
|
434
|
+
return {
|
|
435
|
+
content: [
|
|
436
|
+
{ type: "image", data: buf.toString("base64"), mimeType: mime },
|
|
437
|
+
{ type: "text", text: `${p} (${buf.length}B)` }
|
|
438
|
+
]
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
name: "download",
|
|
444
|
+
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.",
|
|
445
|
+
inputSchema: {
|
|
446
|
+
type: "object",
|
|
447
|
+
properties: { url: { type: "string" }, path: { type: "string" } },
|
|
448
|
+
required: ["url", "path"]
|
|
449
|
+
},
|
|
450
|
+
run: async (a) => {
|
|
451
|
+
const url = str(a.url);
|
|
452
|
+
if (!/^https?:\/\//.test(url))
|
|
453
|
+
return text("http(s) \uC8FC\uC18C\uB9CC \uBC1B\uC2B5\uB2C8\uB2E4", true);
|
|
454
|
+
const p = this.inDir(str(a.path));
|
|
455
|
+
const r = await fetch(url, { redirect: "follow" });
|
|
456
|
+
if (!r.ok) return text(`\uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: HTTP ${r.status}`, true);
|
|
457
|
+
const buf = Buffer.from(await r.arrayBuffer());
|
|
458
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
459
|
+
fs.writeFileSync(p, buf);
|
|
460
|
+
return text(`\uBC1B\uC558\uC2B5\uB2C8\uB2E4: ${p} (${buf.length}B)`);
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: "upload_to_storage",
|
|
465
|
+
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.",
|
|
466
|
+
inputSchema: {
|
|
467
|
+
type: "object",
|
|
468
|
+
properties: {
|
|
469
|
+
path: { type: "string" },
|
|
470
|
+
folder: {
|
|
471
|
+
type: "string",
|
|
472
|
+
description: "\uC2A4\uD1A0\uB9AC\uC9C0 \uC548 \uD3F4\uB354 (\uAE30\uBCF8 local-runner)"
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
required: ["path"]
|
|
476
|
+
},
|
|
477
|
+
run: async (a) => this.uploadToStorage(str(a.path), str(a.folder, "local-runner"))
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
name: "image_generate",
|
|
481
|
+
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.",
|
|
482
|
+
inputSchema: {
|
|
483
|
+
type: "object",
|
|
484
|
+
properties: {
|
|
485
|
+
prompt: { type: "string" },
|
|
486
|
+
out: {
|
|
487
|
+
type: "string",
|
|
488
|
+
description: "\uC800\uC7A5\uD560 \uACBD\uB85C (\uC791\uC5C5 \uD3F4\uB354 \uAE30\uC900, .png)"
|
|
489
|
+
},
|
|
490
|
+
input_images: {
|
|
491
|
+
type: "array",
|
|
492
|
+
items: { type: "string" },
|
|
493
|
+
description: "\uC791\uC5C5 \uD3F4\uB354 \uC548\uC758 \uC785\uB825 \uADF8\uB9BC \uACBD\uB85C\uB4E4"
|
|
494
|
+
},
|
|
495
|
+
provider: { type: "string" },
|
|
496
|
+
model: { type: "string" }
|
|
497
|
+
},
|
|
498
|
+
required: ["prompt", "out"]
|
|
499
|
+
},
|
|
500
|
+
run: async (a) => this.imageGenerate(a)
|
|
501
|
+
},
|
|
502
|
+
// ── 실행 중인 Blender (BlenderMCP 애드온) — 스킬 문서가 부르는 이름 그대로 ──
|
|
503
|
+
{
|
|
504
|
+
name: "execute_blender_code",
|
|
505
|
+
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.",
|
|
506
|
+
inputSchema: {
|
|
507
|
+
type: "object",
|
|
508
|
+
properties: { code: { type: "string" } },
|
|
509
|
+
required: ["code"]
|
|
510
|
+
},
|
|
511
|
+
run: async (a) => this.blenderCall("execute_code", { code: str(a.code) })
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
name: "get_scene_info",
|
|
515
|
+
description: "\uC2E4\uD589 \uC911\uC778 Blender \uC758 \uC7A5\uBA74 \uC815\uBCF4 (BlenderMCP).",
|
|
516
|
+
inputSchema: { type: "object", properties: {} },
|
|
517
|
+
annotations: ro,
|
|
518
|
+
run: async () => this.blenderCall("get_scene_info", {})
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: "get_object_info",
|
|
522
|
+
description: "\uC2E4\uD589 \uC911\uC778 Blender \uC758 \uBB3C\uCCB4 \uC815\uBCF4 (BlenderMCP).",
|
|
523
|
+
inputSchema: {
|
|
524
|
+
type: "object",
|
|
525
|
+
properties: { object_name: { type: "string" } },
|
|
526
|
+
required: ["object_name"]
|
|
527
|
+
},
|
|
528
|
+
annotations: ro,
|
|
529
|
+
run: async (a) => this.blenderCall("get_object_info", { name: str(a.object_name) })
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: "get_viewport_screenshot",
|
|
533
|
+
description: "\uC2E4\uD589 \uC911\uC778 Blender \uC758 \uBDF0\uD3EC\uD2B8 \uD654\uBA74\uC744 \uBCF8\uB2E4 (BlenderMCP).",
|
|
534
|
+
inputSchema: {
|
|
535
|
+
type: "object",
|
|
536
|
+
properties: { max_size: { type: "number" } }
|
|
537
|
+
},
|
|
538
|
+
annotations: ro,
|
|
539
|
+
run: async (a) => {
|
|
540
|
+
const tmp = path.join(
|
|
541
|
+
os.tmpdir(),
|
|
542
|
+
`cb_blender_shot_${process.pid}_${Date.now()}.png`
|
|
543
|
+
);
|
|
544
|
+
const r = await this.blenderCall("get_viewport_screenshot", {
|
|
545
|
+
max_size: num(a.max_size, 800),
|
|
546
|
+
filepath: tmp,
|
|
547
|
+
format: "png"
|
|
548
|
+
});
|
|
549
|
+
if (r.isError) return r;
|
|
550
|
+
if (!fs.existsSync(tmp))
|
|
551
|
+
return text("Blender \uAC00 \uD654\uBA74\uC744 \uC800\uC7A5\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4", true);
|
|
552
|
+
const data = fs.readFileSync(tmp).toString("base64");
|
|
553
|
+
fs.rmSync(tmp, { force: true });
|
|
554
|
+
return { content: [{ type: "image", data, mimeType: "image/png" }] };
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
];
|
|
558
|
+
}
|
|
559
|
+
skillDirOf(p) {
|
|
560
|
+
const rel = path.relative(this.skillsDir, p);
|
|
561
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) return null;
|
|
562
|
+
return path.join(this.skillsDir, rel.split(path.sep)[0]);
|
|
563
|
+
}
|
|
564
|
+
/** 설치된 스킬 (skills/<이름>/SKILL.md 의 머리말 name, description). */
|
|
565
|
+
listSkills() {
|
|
566
|
+
if (!fs.existsSync(this.skillsDir)) return [];
|
|
567
|
+
const out = [];
|
|
568
|
+
for (const d of fs.readdirSync(this.skillsDir, { withFileTypes: true })) {
|
|
569
|
+
if (!d.isDirectory()) continue;
|
|
570
|
+
const dir = path.join(this.skillsDir, d.name);
|
|
571
|
+
const md = path.join(dir, "SKILL.md");
|
|
572
|
+
if (!fs.existsSync(md)) continue;
|
|
573
|
+
const head = /^---\r?\n([\s\S]*?)\r?\n---/.exec(
|
|
574
|
+
fs.readFileSync(md, "utf-8")
|
|
575
|
+
);
|
|
576
|
+
const field = (k) => {
|
|
577
|
+
if (!head) return "";
|
|
578
|
+
const lines = head[1].split(/\r?\n/);
|
|
579
|
+
const at = lines.findIndex((l) => l.startsWith(`${k}:`));
|
|
580
|
+
if (at < 0) return "";
|
|
581
|
+
let v = lines[at].slice(k.length + 1).trim();
|
|
582
|
+
if (/^[>|][-+]?$/.test(v) || v === "") {
|
|
583
|
+
const more = [];
|
|
584
|
+
for (const l of lines.slice(at + 1)) {
|
|
585
|
+
if (/^\s+\S/.test(l)) more.push(l.trim());
|
|
586
|
+
else break;
|
|
587
|
+
}
|
|
588
|
+
v = more.join(" ");
|
|
589
|
+
}
|
|
590
|
+
return v.replace(/^["']|["']$/g, "");
|
|
591
|
+
};
|
|
592
|
+
out.push({ name: d.name, description: field("description"), dir });
|
|
593
|
+
}
|
|
594
|
+
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
595
|
+
}
|
|
596
|
+
/** read_skill 도구 설명: 설치된 스킬 목록이 곧 AI 가 보는 "스킬 표지" 다. */
|
|
597
|
+
skillIndexText() {
|
|
598
|
+
const skills = this.listSkills();
|
|
599
|
+
if (!skills.length)
|
|
600
|
+
return "\uC774 \uCEF4\uD4E8\uD130\uC5D0 \uC124\uCE58\uB41C \uC2A4\uD0AC\uC774 \uC544\uC9C1 \uC5C6\uC2B5\uB2C8\uB2E4. \uC0AC\uC6A9\uC790\uAC00 `npx connectbase-client local --add <GitHub \uC8FC\uC18C>` \uB85C \uC124\uCE58\uD558\uAC70\uB098, \uC0AC\uC6A9\uC790\uAC00 \uC6D0\uD558\uBA74 skill_install \uB85C \uBC1B\uB294\uB2E4.";
|
|
601
|
+
let t = "\uC774 \uCEF4\uD4E8\uD130\uC5D0 \uC124\uCE58\uB41C \uC2A4\uD0AC (\uC77C\uC774 \uB9DE\uC73C\uBA74 read_skill \uB85C \uBCF8\uBB38\uC744 \uC77D\uACE0 \uADF8\uB300\uB85C \uB530\uB978\uB2E4):\n";
|
|
602
|
+
for (const k of skills) {
|
|
603
|
+
const line = `- ${k.name}: ${k.description.slice(0, 220)}
|
|
604
|
+
`;
|
|
605
|
+
if (t.length + line.length > 7e3) {
|
|
606
|
+
t += `- \u2026 \uC678 ${skills.length - t.split("\n- ").length + 1}\uAC1C (list_files skills \uB85C \uBCF8\uB2E4)
|
|
607
|
+
`;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
t += line;
|
|
611
|
+
}
|
|
612
|
+
return t;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* 스킬 설치. source:
|
|
616
|
+
* - GitHub: owner/repo[/폴더][@ref] 또는 https://github.com/owner/repo[/tree/ref/폴더]
|
|
617
|
+
* 폴더에 SKILL.md 가 있으면 그 스킬 하나, 없으면 그 아래 SKILL.md 가 있는 폴더를 모두 받는다 (저장소 통째로).
|
|
618
|
+
* - 이 컴퓨터의 폴더 경로 (./my-skill, ~/skills/x): 그대로 복사한다.
|
|
619
|
+
*/
|
|
620
|
+
async installSkills(source, update2 = false) {
|
|
621
|
+
const src0 = source.trim();
|
|
622
|
+
const localPath = path.resolve(src0.replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
623
|
+
if (/^[.~/\\]|^[A-Za-z]:[\\/]/.test(src0) && fs.existsSync(localPath)) {
|
|
624
|
+
return this.copySkills(localPath, `${localPath}`, update2);
|
|
625
|
+
}
|
|
626
|
+
let s = src0.replace(/^https:\/\/github\.com\//, "").replace(/\.git$/, "");
|
|
627
|
+
let ref = "HEAD";
|
|
628
|
+
const tree = /^([^/]+\/[^/]+)\/(?:tree|blob)\/([^/]+)\/?(.*)$/.exec(s);
|
|
629
|
+
if (tree) {
|
|
630
|
+
ref = tree[2];
|
|
631
|
+
s = `${tree[1]}/${tree[3]}`.replace(/\/SKILL\.md$/i, "").replace(/\/+$/, "");
|
|
632
|
+
}
|
|
633
|
+
const at = s.lastIndexOf("@");
|
|
634
|
+
if (at > 0) {
|
|
635
|
+
ref = s.slice(at + 1);
|
|
636
|
+
s = s.slice(0, at);
|
|
637
|
+
}
|
|
638
|
+
const m = /^([\w.-]+)\/([\w.-]+)(?:\/(.+))?$/.exec(s);
|
|
639
|
+
if (!m)
|
|
640
|
+
throw new Error(
|
|
641
|
+
"GitHub \uC8FC\uC18C(owner/repo[/\uD3F4\uB354][@ref]) \uB098 \uC774 \uCEF4\uD4E8\uD130\uC758 \uD3F4\uB354 \uACBD\uB85C\uB97C \uC8FC\uC138\uC694"
|
|
642
|
+
);
|
|
643
|
+
const [, owner, repo, sub = ""] = m;
|
|
644
|
+
const tarBin = this.programs.tar ?? findPrograms().tar;
|
|
645
|
+
if (!tarBin)
|
|
646
|
+
throw new Error(
|
|
647
|
+
"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)"
|
|
648
|
+
);
|
|
649
|
+
const r = await fetch(
|
|
650
|
+
`https://codeload.github.com/${owner}/${repo}/tar.gz/${ref}`
|
|
651
|
+
);
|
|
652
|
+
if (!r.ok)
|
|
653
|
+
throw new Error(
|
|
654
|
+
`GitHub \uC5D0\uC11C \uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: HTTP ${r.status} (${owner}/${repo}@${ref})`
|
|
655
|
+
);
|
|
656
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "cb_skill_"));
|
|
657
|
+
try {
|
|
658
|
+
fs.writeFileSync(
|
|
659
|
+
path.join(tmp, "src.tgz"),
|
|
660
|
+
Buffer.from(await r.arrayBuffer())
|
|
661
|
+
);
|
|
662
|
+
const x = await this.exec(`"${tarBin}" -xzf src.tgz`, tmp, 120);
|
|
663
|
+
if (x.code !== 0) throw new Error(`\uC555\uCD95\uC744 \uD480\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${x.out}`);
|
|
664
|
+
const top = fs.readdirSync(tmp).find((n) => n !== "src.tgz");
|
|
665
|
+
const root = top ? path.join(tmp, top, ...sub.split("/").filter(Boolean)) : "";
|
|
666
|
+
if (!root || !fs.existsSync(root))
|
|
667
|
+
throw new Error(`\uADF8 \uACBD\uB85C\uAC00 \uC800\uC7A5\uC18C\uC5D0 \uC5C6\uC2B5\uB2C8\uB2E4: ${sub || "(\uB9E8 \uC704)"}`);
|
|
668
|
+
return this.copySkills(
|
|
669
|
+
root,
|
|
670
|
+
`${owner}/${repo}${sub ? `/${sub}` : ""}@${ref}`,
|
|
671
|
+
update2
|
|
672
|
+
);
|
|
673
|
+
} finally {
|
|
674
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
copySkills(root, origin, update2) {
|
|
678
|
+
const found = [];
|
|
679
|
+
const walk = (d, depth) => {
|
|
680
|
+
if (fs.existsSync(path.join(d, "SKILL.md"))) {
|
|
681
|
+
found.push(d);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (depth >= 4) return;
|
|
685
|
+
for (const n of fs.readdirSync(d, { withFileTypes: true }))
|
|
686
|
+
if (n.isDirectory() && !n.name.startsWith(".") && n.name !== "node_modules")
|
|
687
|
+
walk(path.join(d, n.name), depth + 1);
|
|
688
|
+
};
|
|
689
|
+
walk(root, 0);
|
|
690
|
+
if (!found.length)
|
|
691
|
+
throw new Error("SKILL.md \uAC00 \uC788\uB294 \uD3F4\uB354\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4");
|
|
692
|
+
const installed = [];
|
|
693
|
+
const skipped = [];
|
|
694
|
+
for (const dir of found) {
|
|
695
|
+
const name = path.basename(dir);
|
|
696
|
+
const dest = path.join(this.skillsDir, name);
|
|
697
|
+
if (fs.existsSync(path.join(dest, "SKILL.md")) && !update2) {
|
|
698
|
+
skipped.push(name);
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
702
|
+
fs.cpSync(dir, dest, { recursive: true });
|
|
703
|
+
const rel = path.relative(root, dir).split(path.sep).join("/");
|
|
704
|
+
fs.writeFileSync(
|
|
705
|
+
path.join(dest, ".source"),
|
|
706
|
+
`${origin}${rel ? ` (${rel})` : ""}
|
|
707
|
+
`
|
|
708
|
+
);
|
|
709
|
+
installed.push(name);
|
|
710
|
+
}
|
|
711
|
+
if (installed.length)
|
|
712
|
+
this.log(`\uC2A4\uD0AC \uC124\uCE58: ${installed.join(", ")} \u2190 ${origin}`);
|
|
713
|
+
if (installed.length) this.opts.onSkillsChanged?.();
|
|
714
|
+
return { installed, skipped };
|
|
715
|
+
}
|
|
716
|
+
/** 설치된 스킬을 원래 주소에서 다시 받는다. */
|
|
717
|
+
async updateSkills() {
|
|
718
|
+
const sources = /* @__PURE__ */ new Set();
|
|
719
|
+
for (const k of this.listSkills()) {
|
|
720
|
+
const f = path.join(k.dir, ".source");
|
|
721
|
+
if (!fs.existsSync(f)) continue;
|
|
722
|
+
const line = fs.readFileSync(f, "utf-8").trim();
|
|
723
|
+
const origin = line.replace(/ \(.*\)$/, "");
|
|
724
|
+
const rel = /\((.*)\)$/.exec(line)?.[1];
|
|
725
|
+
const [base, ref] = origin.split("@");
|
|
726
|
+
if (ref && /^[0-9a-f]{40}$/.test(ref)) continue;
|
|
727
|
+
sources.add(
|
|
728
|
+
rel && !path.isAbsolute(base) ? `${base}/${rel}@${ref ?? "HEAD"}` : origin
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
const done = [];
|
|
732
|
+
for (const s of sources)
|
|
733
|
+
done.push(...(await this.installSkills(s, true)).installed);
|
|
734
|
+
return done;
|
|
735
|
+
}
|
|
736
|
+
async skillInstall(source, update2) {
|
|
737
|
+
try {
|
|
738
|
+
const r = await this.installSkills(source, update2);
|
|
739
|
+
const names = [...r.installed, ...r.skipped];
|
|
740
|
+
const dirs = names.map((n) => path.join(this.skillsDir, n));
|
|
741
|
+
return text(
|
|
742
|
+
`${r.installed.length ? `\uC124\uCE58: ${r.installed.join(", ")}` : ""}${r.skipped.length ? `${r.installed.length ? "\n" : ""}\uC774\uBBF8 \uC788\uC74C(update=true \uBA74 \uB2E4\uC2DC \uBC1B\uC74C): ${r.skipped.join(", ")}` : ""}
|
|
743
|
+
|
|
744
|
+
` + (dirs.length === 1 ? this.describeSkill(dirs[0], "\uC900\uBE44\uB428") : "read_skill(name) \uC73C\uB85C \uBCF8\uBB38\uC744 \uC77D\uB294\uB2E4.")
|
|
745
|
+
);
|
|
746
|
+
} catch (e) {
|
|
747
|
+
return text(e instanceof Error ? e.message : String(e), true);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
describeSkill(dest, head) {
|
|
751
|
+
const files = [];
|
|
752
|
+
const walk = (d) => {
|
|
753
|
+
for (const n of fs.readdirSync(d, { withFileTypes: true })) {
|
|
754
|
+
const p = path.join(d, n.name);
|
|
755
|
+
if (n.isDirectory()) walk(p);
|
|
756
|
+
else files.push(path.relative(dest, p));
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
walk(dest);
|
|
760
|
+
const req = [
|
|
761
|
+
"requirements.txt",
|
|
762
|
+
"tools/package.json",
|
|
763
|
+
"package.json"
|
|
764
|
+
].filter((f) => fs.existsSync(path.join(dest, f)));
|
|
765
|
+
return JSON.stringify(
|
|
766
|
+
{
|
|
767
|
+
result: head,
|
|
768
|
+
skill_dir: dest,
|
|
769
|
+
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.",
|
|
770
|
+
dependency_files: req,
|
|
771
|
+
files: files.sort().slice(0, 400)
|
|
772
|
+
},
|
|
773
|
+
null,
|
|
774
|
+
2
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
exec(command, cwd, timeoutSec) {
|
|
778
|
+
return new Promise((resolve4) => {
|
|
779
|
+
const child = (0, import_node_child_process.spawn)(command, {
|
|
780
|
+
cwd,
|
|
781
|
+
shell: true,
|
|
782
|
+
env: this.env(),
|
|
783
|
+
windowsHide: true
|
|
784
|
+
});
|
|
785
|
+
let out = "";
|
|
786
|
+
const add = (b) => {
|
|
787
|
+
out += b.toString();
|
|
788
|
+
if (out.length > MAX_OUT * 4) out = out.slice(-MAX_OUT * 2);
|
|
789
|
+
};
|
|
790
|
+
child.stdout.on("data", add);
|
|
791
|
+
child.stderr.on("data", add);
|
|
792
|
+
let timedOut = false;
|
|
793
|
+
const t = setTimeout(() => {
|
|
794
|
+
timedOut = true;
|
|
795
|
+
killTree(child.pid);
|
|
796
|
+
}, timeoutSec * 1e3);
|
|
797
|
+
child.on("close", (code) => {
|
|
798
|
+
clearTimeout(t);
|
|
799
|
+
resolve4({ code, out, timedOut });
|
|
800
|
+
});
|
|
801
|
+
child.on("error", (e) => {
|
|
802
|
+
clearTimeout(t);
|
|
803
|
+
resolve4({ code: -1, out: out + String(e), timedOut });
|
|
804
|
+
});
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
async run(command, cwd, timeout, background) {
|
|
808
|
+
if (!command.trim()) return text("command \uAC00 \uBE44\uC5C8\uC2B5\uB2C8\uB2E4", true);
|
|
809
|
+
const dir = this.inDir(cwd || ".");
|
|
810
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
811
|
+
this.log(
|
|
812
|
+
`\uC2E4\uD589${background ? " (\uBC31\uADF8\uB77C\uC6B4\uB4DC)" : ""}: ${command} [${path.relative(this.dir, dir) || "."}]`
|
|
813
|
+
);
|
|
814
|
+
if (background) {
|
|
815
|
+
const id = `job${++this.jobSeq}`;
|
|
816
|
+
const child = (0, import_node_child_process.spawn)(command, {
|
|
817
|
+
cwd: dir,
|
|
818
|
+
shell: true,
|
|
819
|
+
env: this.env(),
|
|
820
|
+
windowsHide: true
|
|
821
|
+
});
|
|
822
|
+
const job = {
|
|
823
|
+
id,
|
|
824
|
+
command,
|
|
825
|
+
cwd: dir,
|
|
826
|
+
started: Date.now(),
|
|
827
|
+
out: "",
|
|
828
|
+
kill: () => killTree(child.pid)
|
|
829
|
+
};
|
|
830
|
+
const add = (b) => {
|
|
831
|
+
job.out += b.toString();
|
|
832
|
+
if (job.out.length > MAX_OUT * 4) job.out = job.out.slice(-MAX_OUT * 2);
|
|
833
|
+
};
|
|
834
|
+
child.stdout.on("data", add);
|
|
835
|
+
child.stderr.on("data", add);
|
|
836
|
+
child.on("close", (code) => {
|
|
837
|
+
job.code = code;
|
|
838
|
+
job.ended = Date.now();
|
|
839
|
+
this.log(`\uC791\uC5C5 \uB05D: ${id} (\uCF54\uB4DC ${code})`);
|
|
840
|
+
});
|
|
841
|
+
child.on("error", (e) => {
|
|
842
|
+
job.out += String(e);
|
|
843
|
+
job.code = -1;
|
|
844
|
+
job.ended = Date.now();
|
|
845
|
+
});
|
|
846
|
+
this.jobs.set(id, job);
|
|
847
|
+
return text(
|
|
848
|
+
`\uC2DC\uC791\uD588\uC2B5\uB2C8\uB2E4: ${id}. job_status(id="${id}", wait=60) \uB85C \uBD05\uB2C8\uB2E4.`
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
const limit = Math.min(Math.max(timeout, 1), 100);
|
|
852
|
+
const r = await this.exec(command, dir, limit);
|
|
853
|
+
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.
|
|
854
|
+
` : `\uC885\uB8CC \uCF54\uB4DC ${r.code}
|
|
855
|
+
`;
|
|
856
|
+
return text(head + tail(r.out), r.timedOut || r.code !== 0);
|
|
857
|
+
}
|
|
858
|
+
async jobStatus(id, wait) {
|
|
859
|
+
if (!id) {
|
|
860
|
+
const list = [...this.jobs.values()].map((j2) => ({
|
|
861
|
+
id: j2.id,
|
|
862
|
+
command: j2.command.slice(0, 120),
|
|
863
|
+
running: j2.ended === void 0,
|
|
864
|
+
code: j2.code
|
|
865
|
+
}));
|
|
866
|
+
return text(JSON.stringify(list, null, 2) || "[]");
|
|
867
|
+
}
|
|
868
|
+
const j = this.jobs.get(id);
|
|
869
|
+
if (!j) return text("\uADF8\uB7F0 \uC791\uC5C5\uC774 \uC5C6\uC2B5\uB2C8\uB2E4", true);
|
|
870
|
+
const until = Date.now() + Math.min(Math.max(wait, 0), 100) * 1e3;
|
|
871
|
+
while (j.ended === void 0 && Date.now() < until)
|
|
872
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
873
|
+
const secs = Math.round(((j.ended ?? Date.now()) - j.started) / 1e3);
|
|
874
|
+
const state = j.ended === void 0 ? `\uC2E4\uD589 \uC911 (${secs}\uCD08)` : `\uB05D\uB0A8 (\uCF54\uB4DC ${j.code}, ${secs}\uCD08)`;
|
|
875
|
+
return text(
|
|
876
|
+
`${j.id}: ${state}
|
|
877
|
+
${tail(j.out)}`,
|
|
878
|
+
j.ended !== void 0 && j.code !== 0
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
// ── 실행 중인 Blender: BlenderMCP 애드온 소켓 (JSON 한 덩어리 보내고 JSON 한 덩어리 받기) ──
|
|
882
|
+
get blenderPort() {
|
|
883
|
+
return this.opts.blenderMcpPort ?? (Number(process.env.BLENDER_MCP_PORT) || 9876);
|
|
884
|
+
}
|
|
885
|
+
blenderSend(type, params, timeoutMs = 18e4) {
|
|
886
|
+
return new Promise((resolve4, reject) => {
|
|
887
|
+
const sock = net.createConnection({
|
|
888
|
+
host: "127.0.0.1",
|
|
889
|
+
port: this.blenderPort
|
|
890
|
+
});
|
|
891
|
+
let buf = Buffer.alloc(0);
|
|
892
|
+
const timer = setTimeout(() => {
|
|
893
|
+
sock.destroy();
|
|
894
|
+
reject(
|
|
895
|
+
new Error(
|
|
896
|
+
`Blender \uC751\uB2F5\uC774 ${timeoutMs / 1e3}\uCD08 \uC548\uC5D0 \uC624\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4`
|
|
897
|
+
)
|
|
898
|
+
);
|
|
899
|
+
}, timeoutMs);
|
|
900
|
+
sock.on("connect", () => sock.write(JSON.stringify({ type, params })));
|
|
901
|
+
sock.on("data", (d) => {
|
|
902
|
+
buf = Buffer.concat([buf, d]);
|
|
903
|
+
try {
|
|
904
|
+
const obj = JSON.parse(buf.toString("utf-8"));
|
|
905
|
+
clearTimeout(timer);
|
|
906
|
+
sock.end();
|
|
907
|
+
resolve4(obj);
|
|
908
|
+
} catch {
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
sock.on("error", (e) => {
|
|
912
|
+
clearTimeout(timer);
|
|
913
|
+
reject(e);
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
async blenderPing() {
|
|
918
|
+
try {
|
|
919
|
+
await this.blenderSend("get_scene_info", {}, 3e3);
|
|
920
|
+
return true;
|
|
921
|
+
} catch {
|
|
922
|
+
return false;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
async blenderCall(type, params) {
|
|
926
|
+
try {
|
|
927
|
+
const r = await this.blenderSend(type, params);
|
|
928
|
+
if (r.status === "error")
|
|
929
|
+
return text(`Blender \uC624\uB958: ${str(r.message)}`, true);
|
|
930
|
+
const res = r.result ?? r;
|
|
931
|
+
return text(typeof res === "string" ? res : JSON.stringify(res, null, 2));
|
|
932
|
+
} catch (e) {
|
|
933
|
+
return text(
|
|
934
|
+
`\uC2E4\uD589 \uC911\uC778 Blender \uC5D0 \uBD99\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (localhost:${this.blenderPort}): ${e instanceof Error ? e.message : e}
|
|
935
|
+
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.`,
|
|
936
|
+
true
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
async uploadToStorage(p, folder) {
|
|
941
|
+
const abs = this.inDir(p);
|
|
942
|
+
if (!fs.existsSync(abs)) return text(`\uD30C\uC77C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${p}`, true);
|
|
943
|
+
try {
|
|
944
|
+
const url = await uploadFile(this.opts, abs, folder);
|
|
945
|
+
this.log(`\uC62C\uB9BC: ${path.basename(abs)} \u2192 ${url}`);
|
|
946
|
+
return text(
|
|
947
|
+
JSON.stringify({ uploaded: path.basename(abs), url }, null, 2)
|
|
948
|
+
);
|
|
949
|
+
} catch (e) {
|
|
950
|
+
return text(e instanceof Error ? e.message : String(e), true);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
async imageGenerate(a) {
|
|
954
|
+
const out = this.inDir(str(a.out));
|
|
955
|
+
const parts = [{ type: "text", text: str(a.prompt) }];
|
|
956
|
+
for (const ip of Array.isArray(a.input_images) ? a.input_images : []) {
|
|
957
|
+
const abs = this.inDir(String(ip));
|
|
958
|
+
const mime = imageMime(abs) ?? "image/png";
|
|
959
|
+
parts.push({
|
|
960
|
+
type: "image_url",
|
|
961
|
+
image_url: {
|
|
962
|
+
url: `data:${mime};base64,${fs.readFileSync(abs).toString("base64")}`
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
const body = {
|
|
967
|
+
messages: [{ role: "user", content: parts }],
|
|
968
|
+
timeoutSeconds: 300
|
|
969
|
+
};
|
|
970
|
+
if (str(a.provider)) body.provider = str(a.provider);
|
|
971
|
+
if (str(a.model)) body.model = str(a.model);
|
|
972
|
+
try {
|
|
973
|
+
if (!this.opts.publicKey)
|
|
974
|
+
return text(
|
|
975
|
+
"\uC544\uC9C1 ConnectBase \uC571\uC5D0 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4 (\uD130\uB110 \uC900\uBE44 \uC804)",
|
|
976
|
+
true
|
|
977
|
+
);
|
|
978
|
+
const resp = await fetch(`${this.opts.baseUrl}/v1/public/ai/chat`, {
|
|
979
|
+
method: "POST",
|
|
980
|
+
headers: {
|
|
981
|
+
"Content-Type": "application/json",
|
|
982
|
+
"X-Public-Key": this.opts.publicKey
|
|
983
|
+
},
|
|
984
|
+
body: JSON.stringify(body)
|
|
985
|
+
});
|
|
986
|
+
const raw = await resp.text();
|
|
987
|
+
if (!resp.ok)
|
|
988
|
+
return text(
|
|
989
|
+
`ConnectBase \uADF8\uB9BC \uBAA8\uB378 \uD638\uCD9C \uC2E4\uD328 (HTTP ${resp.status}): ${raw.slice(0, 400)}`,
|
|
990
|
+
true
|
|
991
|
+
);
|
|
992
|
+
const r = JSON.parse(raw);
|
|
993
|
+
const images = r.images ?? [];
|
|
994
|
+
if (!images.length)
|
|
995
|
+
return text(
|
|
996
|
+
`\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.`,
|
|
997
|
+
true
|
|
998
|
+
);
|
|
999
|
+
const src = str(images[0].url);
|
|
1000
|
+
const buf = src.startsWith("data:") ? Buffer.from(src.split(",", 2)[1], "base64") : Buffer.from(await (await fetch(src)).arrayBuffer());
|
|
1001
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
1002
|
+
fs.writeFileSync(out, buf);
|
|
1003
|
+
return text(
|
|
1004
|
+
`\uC800\uC7A5\uD588\uC2B5\uB2C8\uB2E4: ${out} (${buf.length}B). view_image \uB85C \uD655\uC778\uD558\uC138\uC694.`
|
|
1005
|
+
);
|
|
1006
|
+
} catch (e) {
|
|
1007
|
+
return text(e instanceof Error ? e.message : String(e), true);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
// ── MCP (Streamable HTTP, JSON 응답) ──
|
|
1011
|
+
async handleRpc(msg) {
|
|
1012
|
+
const id = msg.id;
|
|
1013
|
+
const method = str(msg.method);
|
|
1014
|
+
const ok = (result) => ({ jsonrpc: "2.0", id, result });
|
|
1015
|
+
const fail = (code, message) => ({
|
|
1016
|
+
jsonrpc: "2.0",
|
|
1017
|
+
id,
|
|
1018
|
+
error: { code, message }
|
|
1019
|
+
});
|
|
1020
|
+
if (id === void 0) return null;
|
|
1021
|
+
switch (method) {
|
|
1022
|
+
case "initialize": {
|
|
1023
|
+
const want = str(msg.params?.protocolVersion);
|
|
1024
|
+
return ok({
|
|
1025
|
+
protocolVersion: PROTOCOL_VERSIONS.includes(want) ? want : PROTOCOL_VERSIONS[0],
|
|
1026
|
+
capabilities: { tools: { listChanged: false } },
|
|
1027
|
+
serverInfo: { name: "connectbase-local", version: "1.0.0" },
|
|
1028
|
+
instructions: "\uC0AC\uC6A9\uC790 \uCEF4\uD4E8\uD130\uC758 \uB85C\uCEEC \uC2E4\uD589\uAE30. \uC774 \uCEF4\uD4E8\uD130\uC5D0 \uC124\uCE58\uB41C \uC2A4\uD0AC(read_skill \uC124\uBA85\uC758 \uBAA9\uB85D)\uC744 \uC77D\uACE0, \uADF8 \uC2A4\uD0AC\uC774 \uC694\uAD6C\uD558\uB294 \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. \uD504\uB85C\uADF8\uB7A8 \uD655\uC778\uC740 local_info."
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
case "ping":
|
|
1032
|
+
return ok({});
|
|
1033
|
+
case "tools/list":
|
|
1034
|
+
return ok({
|
|
1035
|
+
tools: this.tools.map(
|
|
1036
|
+
({ name, description, inputSchema, annotations }) => ({
|
|
1037
|
+
name,
|
|
1038
|
+
description: name === "read_skill" ? this.skillIndexText() : description,
|
|
1039
|
+
inputSchema,
|
|
1040
|
+
...annotations ? { annotations } : {}
|
|
1041
|
+
})
|
|
1042
|
+
)
|
|
1043
|
+
});
|
|
1044
|
+
case "tools/call": {
|
|
1045
|
+
const p = msg.params ?? {};
|
|
1046
|
+
const tool = this.tools.find((t) => t.name === p.name);
|
|
1047
|
+
if (!tool) return fail(-32602, `\uC5C6\uB294 \uB3C4\uAD6C: ${str(p.name)}`);
|
|
1048
|
+
try {
|
|
1049
|
+
return ok(await tool.run(p.arguments ?? {}));
|
|
1050
|
+
} catch (e) {
|
|
1051
|
+
return ok(text(e instanceof Error ? e.message : String(e), true));
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
default:
|
|
1055
|
+
return fail(-32601, `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBA54\uC11C\uB4DC: ${method}`);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
/** 127.0.0.1 에서만 듣는 MCP 서버. 밖에서는 터널(프록시 토큰)로만 들어온다. */
|
|
1059
|
+
listen() {
|
|
1060
|
+
const server = http.createServer(async (req, res) => {
|
|
1061
|
+
if (req.method === "GET" || req.method === "DELETE") {
|
|
1062
|
+
res.writeHead(req.method === "DELETE" ? 200 : 405, { Allow: "POST" }).end();
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (req.method !== "POST") {
|
|
1066
|
+
res.writeHead(405).end();
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const chunks = [];
|
|
1070
|
+
for await (const c of req) chunks.push(c);
|
|
1071
|
+
let body;
|
|
1072
|
+
try {
|
|
1073
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
1074
|
+
} catch {
|
|
1075
|
+
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
1076
|
+
JSON.stringify({
|
|
1077
|
+
jsonrpc: "2.0",
|
|
1078
|
+
id: null,
|
|
1079
|
+
error: { code: -32700, message: "parse error" }
|
|
1080
|
+
})
|
|
1081
|
+
);
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
const msgs = Array.isArray(body) ? body : [body];
|
|
1085
|
+
const replies = (await Promise.all(msgs.map((m) => this.handleRpc(m)))).filter(Boolean);
|
|
1086
|
+
if (!replies.length) {
|
|
1087
|
+
res.writeHead(202).end();
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
const out = JSON.stringify(Array.isArray(body) ? replies : replies[0]);
|
|
1091
|
+
res.writeHead(200, {
|
|
1092
|
+
"Content-Type": "application/json",
|
|
1093
|
+
"Mcp-Session-Id": "local"
|
|
1094
|
+
}).end(out);
|
|
1095
|
+
});
|
|
1096
|
+
return new Promise((resolve4, reject) => {
|
|
1097
|
+
server.once("error", reject);
|
|
1098
|
+
server.listen(this.opts.port, "127.0.0.1", () => resolve4(server));
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
function killTree(pid) {
|
|
1103
|
+
if (!pid) return;
|
|
1104
|
+
try {
|
|
1105
|
+
if (process.platform === "win32")
|
|
1106
|
+
(0, import_node_child_process.spawn)("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
1107
|
+
windowsHide: true
|
|
1108
|
+
});
|
|
1109
|
+
else process.kill(pid, "SIGTERM");
|
|
1110
|
+
} catch {
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
var uploadFile = async (_o, _abs, _folder) => {
|
|
1114
|
+
throw new Error("\uD30C\uC77C \uC2A4\uD1A0\uB9AC\uC9C0 \uC62C\uB9AC\uAE30\uAC00 \uC544\uC9C1 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4");
|
|
1115
|
+
};
|
|
1116
|
+
function setUploader(fn) {
|
|
1117
|
+
uploadFile = fn;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// src/local-command.ts
|
|
1121
|
+
var LOCAL_SERVER_NAME = "\uB0B4 \uCEF4\uD4E8\uD130 (\uB85C\uCEEC \uC2E4\uD589\uAE30)";
|
|
1122
|
+
var STATE_PATH = path2.join(os2.homedir(), ".connectbase", "local-runner.json");
|
|
1123
|
+
function loadState() {
|
|
1124
|
+
try {
|
|
1125
|
+
const s = JSON.parse(fs2.readFileSync(STATE_PATH, "utf-8"));
|
|
1126
|
+
return { apps: s.apps ?? {}, token: s.token };
|
|
1127
|
+
} catch {
|
|
1128
|
+
return { apps: {} };
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
function saveState(s) {
|
|
1132
|
+
fs2.mkdirSync(path2.dirname(STATE_PATH), { recursive: true });
|
|
1133
|
+
fs2.writeFileSync(STATE_PATH, `${JSON.stringify(s, null, 2)}
|
|
1134
|
+
`, {
|
|
1135
|
+
mode: 384
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
function localToken() {
|
|
1139
|
+
const s = loadState();
|
|
1140
|
+
if (!s.token) {
|
|
1141
|
+
s.token = (0, import_node_crypto.randomBytes)(24).toString("base64url");
|
|
1142
|
+
saveState(s);
|
|
1143
|
+
}
|
|
1144
|
+
return s.token;
|
|
1145
|
+
}
|
|
1146
|
+
function mcpUrlFor(baseUrl) {
|
|
1147
|
+
if (process.env.CONNECTBASE_MCP_URL) return process.env.CONNECTBASE_MCP_URL;
|
|
1148
|
+
try {
|
|
1149
|
+
const u = new URL(baseUrl);
|
|
1150
|
+
if (u.hostname.startsWith("api."))
|
|
1151
|
+
return `${u.protocol}//mcp.${u.hostname.slice(4)}/mcp`;
|
|
1152
|
+
} catch {
|
|
1153
|
+
}
|
|
1154
|
+
return "https://mcp.connectbase.world/mcp";
|
|
1155
|
+
}
|
|
1156
|
+
async function mcpTool(mcpUrl, secretKey, name, args) {
|
|
1157
|
+
const headers = {
|
|
1158
|
+
"Content-Type": "application/json",
|
|
1159
|
+
Accept: "application/json, text/event-stream",
|
|
1160
|
+
Authorization: `Bearer ${secretKey}`
|
|
1161
|
+
};
|
|
1162
|
+
const post = async (body) => {
|
|
1163
|
+
const r = await fetch(mcpUrl, {
|
|
1164
|
+
method: "POST",
|
|
1165
|
+
headers,
|
|
1166
|
+
body: JSON.stringify(body)
|
|
1167
|
+
});
|
|
1168
|
+
const sid = r.headers.get("mcp-session-id");
|
|
1169
|
+
if (sid) headers["Mcp-Session-Id"] = sid;
|
|
1170
|
+
const raw = await r.text();
|
|
1171
|
+
if (!r.ok)
|
|
1172
|
+
throw new Error(
|
|
1173
|
+
`MCP ${name} \uC2E4\uD328 (HTTP ${r.status}): ${raw.slice(0, 300)}`
|
|
1174
|
+
);
|
|
1175
|
+
const json = raw.trimStart().startsWith("{") ? raw : raw.split("\n").filter((l) => l.startsWith("data:")).map((l) => l.slice(5).trim()).pop() ?? "{}";
|
|
1176
|
+
return JSON.parse(json);
|
|
1177
|
+
};
|
|
1178
|
+
await post({
|
|
1179
|
+
jsonrpc: "2.0",
|
|
1180
|
+
id: 1,
|
|
1181
|
+
method: "initialize",
|
|
1182
|
+
params: {
|
|
1183
|
+
protocolVersion: "2025-06-18",
|
|
1184
|
+
capabilities: {},
|
|
1185
|
+
clientInfo: { name: "connectbase-local", version: "1" }
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
const res = await post({
|
|
1189
|
+
jsonrpc: "2.0",
|
|
1190
|
+
id: 2,
|
|
1191
|
+
method: "tools/call",
|
|
1192
|
+
params: { name, arguments: args }
|
|
1193
|
+
});
|
|
1194
|
+
const result = res.result ?? {};
|
|
1195
|
+
const t = (result.content ?? []).map((c) => c.text ?? "").join("");
|
|
1196
|
+
if (result.isError || res.error)
|
|
1197
|
+
throw new Error(`${name}: ${t || JSON.stringify(res.error)}`);
|
|
1198
|
+
try {
|
|
1199
|
+
return JSON.parse(t);
|
|
1200
|
+
} catch {
|
|
1201
|
+
return { text: t };
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
async function ensurePublicKey(baseUrl, secretKey, appId, st) {
|
|
1205
|
+
if (st.publicKey) return st.publicKey;
|
|
1206
|
+
const r = await fetch(`${baseUrl}/v1/public/cli/apps/${appId}/public-keys`, {
|
|
1207
|
+
method: "POST",
|
|
1208
|
+
headers: { "Content-Type": "application/json", "X-Public-Key": secretKey },
|
|
1209
|
+
body: "{}"
|
|
1210
|
+
});
|
|
1211
|
+
if (r.status !== 201)
|
|
1212
|
+
throw new Error(`\uACF5\uAC1C \uD0A4\uB97C \uBC1C\uAE09\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (HTTP ${r.status})`);
|
|
1213
|
+
st.publicKey = (await r.json()).key;
|
|
1214
|
+
return st.publicKey;
|
|
1215
|
+
}
|
|
1216
|
+
async function registerServer(mcpUrl, secretKey, appId, url, token, st) {
|
|
1217
|
+
const serverUrl = `${url.replace(/\/+$/, "")}/mcp`;
|
|
1218
|
+
const auth = {
|
|
1219
|
+
auth_type: "custom_header",
|
|
1220
|
+
header_name: "X-Proxy-Token",
|
|
1221
|
+
header_value: token
|
|
1222
|
+
};
|
|
1223
|
+
if (!st.serverId) {
|
|
1224
|
+
const list = await mcpTool(mcpUrl, secretKey, "list_external_mcp_servers", {
|
|
1225
|
+
app_id: appId
|
|
1226
|
+
});
|
|
1227
|
+
const arr = (list.servers ?? list.items ?? list.data ?? []) || [];
|
|
1228
|
+
const found = Array.isArray(arr) ? arr.find((s) => s.name === LOCAL_SERVER_NAME) : void 0;
|
|
1229
|
+
if (found) st.serverId = found.id;
|
|
1230
|
+
}
|
|
1231
|
+
if (st.serverId) {
|
|
1232
|
+
if (st.serverUrl === serverUrl) return "\uADF8\uB300\uB85C";
|
|
1233
|
+
try {
|
|
1234
|
+
await mcpTool(mcpUrl, secretKey, "update_external_mcp_server", {
|
|
1235
|
+
app_id: appId,
|
|
1236
|
+
server_id: st.serverId,
|
|
1237
|
+
server_url: serverUrl,
|
|
1238
|
+
...auth,
|
|
1239
|
+
enabled: true
|
|
1240
|
+
});
|
|
1241
|
+
st.serverUrl = serverUrl;
|
|
1242
|
+
return "\uC8FC\uC18C \uACE0\uCE68";
|
|
1243
|
+
} catch (e) {
|
|
1244
|
+
if (!String(e).includes("not found") && !String(e).includes("\uCC3E\uC744 \uC218 \uC5C6"))
|
|
1245
|
+
throw e;
|
|
1246
|
+
st.serverId = void 0;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
const created = await mcpTool(
|
|
1250
|
+
mcpUrl,
|
|
1251
|
+
secretKey,
|
|
1252
|
+
"create_external_mcp_server",
|
|
1253
|
+
{
|
|
1254
|
+
app_id: appId,
|
|
1255
|
+
name: LOCAL_SERVER_NAME,
|
|
1256
|
+
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.",
|
|
1257
|
+
server_url: serverUrl,
|
|
1258
|
+
transport_type: "streamable_http",
|
|
1259
|
+
...auth
|
|
1260
|
+
}
|
|
1261
|
+
);
|
|
1262
|
+
st.serverId = String(
|
|
1263
|
+
created.id ?? created.server?.id ?? ""
|
|
1264
|
+
);
|
|
1265
|
+
st.serverUrl = serverUrl;
|
|
1266
|
+
return "\uC0C8\uB85C \uB4F1\uB85D";
|
|
1267
|
+
}
|
|
1268
|
+
function makeUploader(mcpUrl, getSt, save) {
|
|
1269
|
+
return async (o, abs, folder) => {
|
|
1270
|
+
if (!o.secretKey || !o.appId || !o.publicKey)
|
|
1271
|
+
throw new Error(
|
|
1272
|
+
"\uC544\uC9C1 ConnectBase \uC571\uC5D0 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4 (\uD130\uB110 \uC900\uBE44 \uC804)"
|
|
1273
|
+
);
|
|
1274
|
+
const st = getSt();
|
|
1275
|
+
const h = {
|
|
1276
|
+
"Content-Type": "application/json",
|
|
1277
|
+
"X-Public-Key": o.publicKey,
|
|
1278
|
+
"X-User-Secret-Key": o.secretKey
|
|
1279
|
+
};
|
|
1280
|
+
if (!st.storageId) {
|
|
1281
|
+
const r = await fetch(`${o.baseUrl}/v1/public/storages/files`, {
|
|
1282
|
+
headers: h
|
|
1283
|
+
});
|
|
1284
|
+
const body = await r.json().catch(() => ({}));
|
|
1285
|
+
const list = body.storages ?? body.items ?? body.data ?? body;
|
|
1286
|
+
const found = Array.isArray(list) ? list.find((s) => s.name === "\uB85C\uCEEC \uC2E4\uD589\uAE30 \uACB0\uACFC") : void 0;
|
|
1287
|
+
if (found) st.storageId = found.id;
|
|
1288
|
+
else {
|
|
1289
|
+
const c = await mcpTool(mcpUrl, o.secretKey, "create_file_storage", {
|
|
1290
|
+
app_id: o.appId,
|
|
1291
|
+
name: "\uB85C\uCEEC \uC2E4\uD589\uAE30 \uACB0\uACFC",
|
|
1292
|
+
description: "connectbase local \uC774 \uC62C\uB9B0 \uACB0\uACFC \uD30C\uC77C",
|
|
1293
|
+
// 실행기는 Origin 없는 서버 호출로 올린다
|
|
1294
|
+
allow_server_to_server: true
|
|
1295
|
+
});
|
|
1296
|
+
st.storageId = String(
|
|
1297
|
+
c.id ?? c.storage?.id ?? ""
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
save();
|
|
1301
|
+
}
|
|
1302
|
+
const buf = fs2.readFileSync(abs);
|
|
1303
|
+
const name = path2.basename(abs);
|
|
1304
|
+
const mime = {
|
|
1305
|
+
".glb": "model/gltf-binary",
|
|
1306
|
+
".gltf": "model/gltf+json",
|
|
1307
|
+
".png": "image/png",
|
|
1308
|
+
".jpg": "image/jpeg",
|
|
1309
|
+
".jpeg": "image/jpeg",
|
|
1310
|
+
".webp": "image/webp",
|
|
1311
|
+
".mp4": "video/mp4",
|
|
1312
|
+
".fbx": "application/octet-stream",
|
|
1313
|
+
".obj": "text/plain",
|
|
1314
|
+
".json": "application/json"
|
|
1315
|
+
}[path2.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
1316
|
+
const base = `${o.baseUrl}/v1/public/storages/files/${st.storageId}`;
|
|
1317
|
+
const presign = () => fetch(
|
|
1318
|
+
`${base}/presigned-url/path/${encodeURIComponent(folder)}/${encodeURIComponent(name)}`,
|
|
1319
|
+
{
|
|
1320
|
+
method: "POST",
|
|
1321
|
+
headers: h,
|
|
1322
|
+
body: JSON.stringify({
|
|
1323
|
+
file_name: name,
|
|
1324
|
+
file_size: buf.length,
|
|
1325
|
+
mime_type: mime,
|
|
1326
|
+
overwrite: true
|
|
1327
|
+
})
|
|
1328
|
+
}
|
|
1329
|
+
);
|
|
1330
|
+
let pre = await presign();
|
|
1331
|
+
if (pre.status === 403 && (await pre.clone().text()).includes("server_to_server_denied")) {
|
|
1332
|
+
await mcpTool(mcpUrl, o.secretKey, "update_file_storage_security", {
|
|
1333
|
+
app_id: o.appId,
|
|
1334
|
+
storage_id: st.storageId,
|
|
1335
|
+
allow_server_to_server: true
|
|
1336
|
+
});
|
|
1337
|
+
pre = await presign();
|
|
1338
|
+
}
|
|
1339
|
+
if (!pre.ok)
|
|
1340
|
+
throw new Error(
|
|
1341
|
+
`\uC62C\uB9AC\uAE30 \uC900\uBE44 \uC2E4\uD328 (HTTP ${pre.status}): ${(await pre.text()).slice(0, 300)}`
|
|
1342
|
+
);
|
|
1343
|
+
const p = await pre.json();
|
|
1344
|
+
const put = await fetch(p.upload_url, {
|
|
1345
|
+
method: "PUT",
|
|
1346
|
+
headers: { "Content-Type": mime, ...p.upload_headers ?? {} },
|
|
1347
|
+
body: buf
|
|
1348
|
+
});
|
|
1349
|
+
if (!put.ok) throw new Error(`\uC62C\uB9AC\uAE30 \uC2E4\uD328 (HTTP ${put.status})`);
|
|
1350
|
+
const done = await fetch(`${base}/complete-upload`, {
|
|
1351
|
+
method: "POST",
|
|
1352
|
+
headers: h,
|
|
1353
|
+
body: JSON.stringify({ file_id: p.file_id })
|
|
1354
|
+
});
|
|
1355
|
+
if (!done.ok)
|
|
1356
|
+
throw new Error(
|
|
1357
|
+
`\uC62C\uB9AC\uAE30 \uB9C8\uBB34\uB9AC \uC2E4\uD328 (HTTP ${done.status}): ${(await done.text()).slice(0, 300)}`
|
|
1358
|
+
);
|
|
1359
|
+
return String((await done.json()).url ?? "");
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
async function runLocal(config, opts, startTunnel2, out) {
|
|
1363
|
+
const dir = path2.resolve(
|
|
1364
|
+
opts.dir || path2.join(os2.homedir(), "ConnectBaseLocal")
|
|
1365
|
+
);
|
|
1366
|
+
const port = opts.port || 47800;
|
|
1367
|
+
let syncTools = () => {
|
|
1368
|
+
};
|
|
1369
|
+
const runner = new LocalRunner({
|
|
1370
|
+
dir,
|
|
1371
|
+
port,
|
|
1372
|
+
baseUrl: config.baseUrl,
|
|
1373
|
+
log: (l) => out.info(l),
|
|
1374
|
+
onSkillsChanged: () => syncTools()
|
|
1375
|
+
});
|
|
1376
|
+
for (const src of (opts.add ?? "").split(",").map((x) => x.trim()).filter(Boolean)) {
|
|
1377
|
+
try {
|
|
1378
|
+
const r = await runner.installSkills(src, opts.update === true);
|
|
1379
|
+
out.success(
|
|
1380
|
+
`\uC2A4\uD0AC \uC124\uCE58 ${src}: ${r.installed.length ? r.installed.join(", ") : "(\uC0C8\uB85C \uBC1B\uC740 \uAC83 \uC5C6\uC74C)"}${r.skipped.length ? ` / \uC774\uBBF8 \uC788\uC74C: ${r.skipped.join(", ")} (--update \uB85C \uB2E4\uC2DC \uBC1B\uAE30)` : ""}`
|
|
1381
|
+
);
|
|
1382
|
+
} catch (e) {
|
|
1383
|
+
out.warn(`\uC2A4\uD0AC \uC124\uCE58 \uC2E4\uD328 ${src}: ${e instanceof Error ? e.message : e}`);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
if (opts.update && !opts.add) {
|
|
1387
|
+
try {
|
|
1388
|
+
const done = await runner.updateSkills();
|
|
1389
|
+
out.success(
|
|
1390
|
+
`\uC2A4\uD0AC \uAC31\uC2E0: ${done.length ? done.join(", ") : "(\uAC31\uC2E0\uD560 \uAC83 \uC5C6\uC74C \u2014 \uACE0\uC815 \uCEE4\uBC0B\uC73C\uB85C \uBC1B\uC740 \uC2A4\uD0AC\uC740 \uADF8\uB300\uB85C)"}`
|
|
1391
|
+
);
|
|
1392
|
+
} catch (e) {
|
|
1393
|
+
out.warn(`\uC2A4\uD0AC \uAC31\uC2E0 \uC2E4\uD328: ${e instanceof Error ? e.message : e}`);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
await runner.listen();
|
|
1397
|
+
const skills = runner.listSkills().map((k) => k.name);
|
|
1398
|
+
out.info(
|
|
1399
|
+
skills.length ? `\uC124\uCE58\uB41C \uC2A4\uD0AC ${skills.length}\uAC1C: ${skills.join(", ")}` : "\uC124\uCE58\uB41C \uC2A4\uD0AC\uC774 \uC5C6\uC2B5\uB2C8\uB2E4. \uC608: npx connectbase-client local --add yorusd1/yoruskills"
|
|
1400
|
+
);
|
|
1401
|
+
const programs = Object.entries(findPrograms()).map(([k, v]) => v ? k : `${k}(\uC5C6\uC74C)`).join(", ");
|
|
1402
|
+
out.success(`\uB85C\uCEEC \uC2E4\uD589\uAE30: http://127.0.0.1:${port}/mcp \uC791\uC5C5 \uD3F4\uB354: ${dir}`);
|
|
1403
|
+
out.info(`\uCC3E\uC740 \uD504\uB85C\uADF8\uB7A8: ${programs}`);
|
|
1404
|
+
const mcpUrl = mcpUrlFor(config.baseUrl);
|
|
1405
|
+
const token = localToken();
|
|
1406
|
+
let state = loadState();
|
|
1407
|
+
let current = {};
|
|
1408
|
+
setUploader(
|
|
1409
|
+
makeUploader(
|
|
1410
|
+
mcpUrl,
|
|
1411
|
+
() => current,
|
|
1412
|
+
() => saveState(state)
|
|
1413
|
+
)
|
|
1414
|
+
);
|
|
1415
|
+
await startTunnel2(port, config, {
|
|
1416
|
+
appId: opts.appId,
|
|
1417
|
+
force: opts.force,
|
|
1418
|
+
token,
|
|
1419
|
+
// 도구 호출은 ConnectBase 가 120초에서 끊는다(run, job_status 는 100초까지). 여유를 두고, 그림 결과는 base64 로 수 MB 다
|
|
1420
|
+
timeout: 180,
|
|
1421
|
+
maxBody: 64,
|
|
1422
|
+
onReady: (info2) => {
|
|
1423
|
+
void (async () => {
|
|
1424
|
+
state = loadState();
|
|
1425
|
+
current = state.apps[info2.appId] ?? {};
|
|
1426
|
+
state.apps[info2.appId] = current;
|
|
1427
|
+
runner.opts.appId = info2.appId;
|
|
1428
|
+
runner.opts.secretKey = info2.secretKey;
|
|
1429
|
+
try {
|
|
1430
|
+
runner.opts.publicKey = await ensurePublicKey(
|
|
1431
|
+
config.baseUrl,
|
|
1432
|
+
info2.secretKey,
|
|
1433
|
+
info2.appId,
|
|
1434
|
+
current
|
|
1435
|
+
);
|
|
1436
|
+
const how = await registerServer(
|
|
1437
|
+
mcpUrl,
|
|
1438
|
+
info2.secretKey,
|
|
1439
|
+
info2.appId,
|
|
1440
|
+
info2.url,
|
|
1441
|
+
token,
|
|
1442
|
+
current
|
|
1443
|
+
);
|
|
1444
|
+
saveState(state);
|
|
1445
|
+
const serverId = current.serverId;
|
|
1446
|
+
let timer;
|
|
1447
|
+
syncTools = () => {
|
|
1448
|
+
clearTimeout(timer);
|
|
1449
|
+
timer = setTimeout(() => {
|
|
1450
|
+
if (serverId)
|
|
1451
|
+
mcpTool(mcpUrl, info2.secretKey, "sync_external_mcp_tools", {
|
|
1452
|
+
app_id: info2.appId,
|
|
1453
|
+
server_id: serverId
|
|
1454
|
+
}).catch(
|
|
1455
|
+
(e) => out.warn(
|
|
1456
|
+
`\uB3C4\uAD6C \uBAA9\uB85D \uAC31\uC2E0 \uC2E4\uD328: ${e instanceof Error ? e.message : e}`
|
|
1457
|
+
)
|
|
1458
|
+
);
|
|
1459
|
+
}, 1500);
|
|
1460
|
+
};
|
|
1461
|
+
syncTools();
|
|
1462
|
+
out.success(
|
|
1463
|
+
`\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.`
|
|
1464
|
+
);
|
|
1465
|
+
out.info(
|
|
1466
|
+
"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."
|
|
1467
|
+
);
|
|
1468
|
+
} catch (e) {
|
|
1469
|
+
saveState(state);
|
|
1470
|
+
out.warn(`MCP \uC11C\uBC84 \uB4F1\uB85D \uC2E4\uD328: ${e instanceof Error ? e.message : e}`);
|
|
1471
|
+
out.info(
|
|
1472
|
+
`\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}`
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
})();
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// src/tunnel-utils.ts
|
|
1481
|
+
var fs3 = __toESM(require("fs"));
|
|
1482
|
+
var os3 = __toESM(require("os"));
|
|
1483
|
+
var path3 = __toESM(require("path"));
|
|
82
1484
|
function getTunnelLockDir() {
|
|
83
|
-
const platform2 =
|
|
1485
|
+
const platform2 = os3.platform();
|
|
84
1486
|
if (platform2 === "darwin") {
|
|
85
|
-
return
|
|
86
|
-
|
|
1487
|
+
return path3.join(
|
|
1488
|
+
os3.homedir(),
|
|
87
1489
|
"Library",
|
|
88
1490
|
"Application Support",
|
|
89
1491
|
"connectbase",
|
|
90
1492
|
"tunnel-locks"
|
|
91
1493
|
);
|
|
92
1494
|
} else if (platform2 === "win32") {
|
|
93
|
-
return
|
|
94
|
-
process.env.LOCALAPPDATA ||
|
|
1495
|
+
return path3.join(
|
|
1496
|
+
process.env.LOCALAPPDATA || path3.join(os3.homedir(), "AppData", "Local"),
|
|
95
1497
|
"connectbase",
|
|
96
1498
|
"tunnel-locks"
|
|
97
1499
|
);
|
|
98
1500
|
}
|
|
99
|
-
const stateHome = process.env.XDG_STATE_HOME ||
|
|
100
|
-
return
|
|
1501
|
+
const stateHome = process.env.XDG_STATE_HOME || path3.join(os3.homedir(), ".local", "state");
|
|
1502
|
+
return path3.join(stateHome, "connectbase", "tunnel-locks");
|
|
101
1503
|
}
|
|
102
1504
|
function isProcessAlive(pid) {
|
|
103
1505
|
try {
|
|
@@ -109,21 +1511,21 @@ function isProcessAlive(pid) {
|
|
|
109
1511
|
}
|
|
110
1512
|
function acquireTunnelLock(appID, port, force, version) {
|
|
111
1513
|
const lockDir = getTunnelLockDir();
|
|
112
|
-
|
|
113
|
-
const lockPath =
|
|
1514
|
+
fs3.mkdirSync(lockDir, { recursive: true });
|
|
1515
|
+
const lockPath = path3.join(lockDir, `${appID}-${port}.lock`);
|
|
114
1516
|
const lockData = {
|
|
115
1517
|
pid: process.pid,
|
|
116
1518
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
117
1519
|
appID,
|
|
118
1520
|
port,
|
|
119
|
-
host:
|
|
1521
|
+
host: os3.hostname(),
|
|
120
1522
|
version
|
|
121
1523
|
};
|
|
122
1524
|
if (!force) {
|
|
123
1525
|
try {
|
|
124
|
-
const fd =
|
|
125
|
-
|
|
126
|
-
|
|
1526
|
+
const fd = fs3.openSync(lockPath, "wx");
|
|
1527
|
+
fs3.writeSync(fd, JSON.stringify(lockData, null, 2));
|
|
1528
|
+
fs3.closeSync(fd);
|
|
127
1529
|
return lockPath;
|
|
128
1530
|
} catch (e) {
|
|
129
1531
|
if (e.code !== "EEXIST") {
|
|
@@ -132,7 +1534,7 @@ function acquireTunnelLock(appID, port, force, version) {
|
|
|
132
1534
|
}
|
|
133
1535
|
try {
|
|
134
1536
|
const existing = JSON.parse(
|
|
135
|
-
|
|
1537
|
+
fs3.readFileSync(lockPath, "utf-8")
|
|
136
1538
|
);
|
|
137
1539
|
if (isProcessAlive(existing.pid)) {
|
|
138
1540
|
return `LOCKED:${existing.pid}:${existing.startedAt}:${existing.host}`;
|
|
@@ -140,12 +1542,12 @@ function acquireTunnelLock(appID, port, force, version) {
|
|
|
140
1542
|
} catch {
|
|
141
1543
|
}
|
|
142
1544
|
}
|
|
143
|
-
|
|
1545
|
+
fs3.writeFileSync(lockPath, JSON.stringify(lockData, null, 2));
|
|
144
1546
|
return lockPath;
|
|
145
1547
|
}
|
|
146
1548
|
function releaseTunnelLock(lockPath) {
|
|
147
1549
|
try {
|
|
148
|
-
|
|
1550
|
+
fs3.unlinkSync(lockPath);
|
|
149
1551
|
} catch {
|
|
150
1552
|
}
|
|
151
1553
|
}
|
|
@@ -176,7 +1578,7 @@ function handleTunnelError(msg, appId, localPort) {
|
|
|
176
1578
|
}
|
|
177
1579
|
|
|
178
1580
|
// src/cli.ts
|
|
179
|
-
var VERSION = "6.
|
|
1581
|
+
var VERSION = "6.23.0" ? "6.23.0" : getPackageVersion();
|
|
180
1582
|
var DEFAULT_BASE_URL = "https://api.connectbase.world";
|
|
181
1583
|
var colors = {
|
|
182
1584
|
reset: "\x1B[0m",
|
|
@@ -315,23 +1717,23 @@ var MIME_BY_EXT = {
|
|
|
315
1717
|
".safetensors": "application/octet-stream"
|
|
316
1718
|
};
|
|
317
1719
|
function guessMimeType(filePath) {
|
|
318
|
-
if (ALLOWED_EXTENSIONLESS_FILES.has(
|
|
1720
|
+
if (ALLOWED_EXTENSIONLESS_FILES.has(path4.basename(filePath))) {
|
|
319
1721
|
return "text/plain; charset=utf-8";
|
|
320
1722
|
}
|
|
321
|
-
return MIME_BY_EXT[
|
|
1723
|
+
return MIME_BY_EXT[path4.extname(filePath).toLowerCase()] || "application/octet-stream";
|
|
322
1724
|
}
|
|
323
1725
|
function isAllowedDeployExt(filePath) {
|
|
324
|
-
if (ALLOWED_EXTENSIONLESS_FILES.has(
|
|
1726
|
+
if (ALLOWED_EXTENSIONLESS_FILES.has(path4.basename(filePath))) {
|
|
325
1727
|
return true;
|
|
326
1728
|
}
|
|
327
|
-
return ALLOWED_EXTENSIONS.has(
|
|
1729
|
+
return ALLOWED_EXTENSIONS.has(path4.extname(filePath).toLowerCase());
|
|
328
1730
|
}
|
|
329
1731
|
function isBinaryDeployExt(filePath) {
|
|
330
|
-
return BINARY_EXTENSIONS.has(
|
|
1732
|
+
return BINARY_EXTENSIONS.has(path4.extname(filePath).toLowerCase());
|
|
331
1733
|
}
|
|
332
1734
|
function isExtensionlessDataFile(filePath) {
|
|
333
|
-
const base =
|
|
334
|
-
return
|
|
1735
|
+
const base = path4.basename(filePath);
|
|
1736
|
+
return path4.extname(base) === "" && !ALLOWED_EXTENSIONLESS_FILES.has(base);
|
|
335
1737
|
}
|
|
336
1738
|
var WEB_FILE_MAX_STORED_BYTES = 6 * 1024 * 1024 - 64 * 1024;
|
|
337
1739
|
var DEPLOY_REQUEST_BUDGET_BYTES = 96 * 1024 * 1024;
|
|
@@ -412,10 +1814,10 @@ function loadConfig() {
|
|
|
412
1814
|
baseUrl: envBaseUrl || DEFAULT_BASE_URL,
|
|
413
1815
|
baseUrlFromRepo: false
|
|
414
1816
|
};
|
|
415
|
-
const rcPath =
|
|
416
|
-
if (
|
|
1817
|
+
const rcPath = path4.join(process.cwd(), ".connectbaserc");
|
|
1818
|
+
if (fs4.existsSync(rcPath)) {
|
|
417
1819
|
try {
|
|
418
|
-
const rcContent = JSON.parse(
|
|
1820
|
+
const rcContent = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
|
|
419
1821
|
if (rcContent.publicKey) config.publicKey = rcContent.publicKey;
|
|
420
1822
|
if (rcContent.secretKey) config.secretKey = rcContent.secretKey;
|
|
421
1823
|
if (rcContent.storageId) config.storageId = rcContent.storageId;
|
|
@@ -440,16 +1842,16 @@ function collectDeployFiles(dir, options = {}) {
|
|
|
440
1842
|
}
|
|
441
1843
|
function collectFiles(dir, baseDir, skipped, options) {
|
|
442
1844
|
const files = [];
|
|
443
|
-
const entries =
|
|
1845
|
+
const entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
444
1846
|
for (const entry of entries) {
|
|
445
|
-
const fullPath =
|
|
446
|
-
const relativePath =
|
|
1847
|
+
const fullPath = path4.join(dir, entry.name);
|
|
1848
|
+
const relativePath = path4.relative(baseDir, fullPath);
|
|
447
1849
|
if (entry.isDirectory()) {
|
|
448
1850
|
if (!entry.name.startsWith(".")) {
|
|
449
1851
|
files.push(...collectFiles(fullPath, baseDir, skipped, options));
|
|
450
1852
|
}
|
|
451
1853
|
} else if (entry.isFile()) {
|
|
452
|
-
const ext =
|
|
1854
|
+
const ext = path4.extname(entry.name).toLowerCase();
|
|
453
1855
|
if (entry.name.startsWith(".")) {
|
|
454
1856
|
continue;
|
|
455
1857
|
}
|
|
@@ -461,9 +1863,9 @@ function collectFiles(dir, baseDir, skipped, options) {
|
|
|
461
1863
|
const isBinary = extensionlessData || BINARY_EXTENSIONS.has(ext);
|
|
462
1864
|
let content;
|
|
463
1865
|
if (isBinary) {
|
|
464
|
-
content =
|
|
1866
|
+
content = fs4.readFileSync(fullPath).toString("base64");
|
|
465
1867
|
} else {
|
|
466
|
-
content =
|
|
1868
|
+
content = fs4.readFileSync(fullPath, "utf-8");
|
|
467
1869
|
}
|
|
468
1870
|
const normalized = normalizeRelativePath(relativePath);
|
|
469
1871
|
files.push({
|
|
@@ -489,7 +1891,7 @@ function formatSkippedFilesReport(skipped, limit = SKIPPED_FILES_LIST_LIMIT) {
|
|
|
489
1891
|
}
|
|
490
1892
|
const byExt = /* @__PURE__ */ new Map();
|
|
491
1893
|
for (const p of skipped) {
|
|
492
|
-
const ext =
|
|
1894
|
+
const ext = path4.extname(p).toLowerCase() || "(\uD655\uC7A5\uC790 \uC5C6\uC74C)";
|
|
493
1895
|
byExt.set(ext, (byExt.get(ext) ?? 0) + 1);
|
|
494
1896
|
}
|
|
495
1897
|
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 +1971,7 @@ async function requestDeployPresign(baseStorageUrl, headers, files, timeoutMs) {
|
|
|
569
1971
|
return parsed?.urls ?? [];
|
|
570
1972
|
}
|
|
571
1973
|
function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
|
|
572
|
-
return new Promise((
|
|
1974
|
+
return new Promise((resolve4, reject) => {
|
|
573
1975
|
let parsed;
|
|
574
1976
|
try {
|
|
575
1977
|
parsed = new URL(uploadUrl);
|
|
@@ -581,7 +1983,7 @@ function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
|
|
|
581
1983
|
reject(new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5C5\uB85C\uB4DC URL \uC2A4\uD0B4: ${parsed.protocol}`));
|
|
582
1984
|
return;
|
|
583
1985
|
}
|
|
584
|
-
const lib = parsed.protocol === "https:" ? https :
|
|
1986
|
+
const lib = parsed.protocol === "https:" ? https : http2;
|
|
585
1987
|
const options = {
|
|
586
1988
|
hostname: parsed.hostname,
|
|
587
1989
|
port: parsed.port || (parsed.protocol === "https:" ? 443 : 80),
|
|
@@ -600,7 +2002,7 @@ function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
|
|
|
600
2002
|
res.on("end", () => {
|
|
601
2003
|
const status = res.statusCode || 0;
|
|
602
2004
|
if (status >= 200 && status < 300) {
|
|
603
|
-
|
|
2005
|
+
resolve4();
|
|
604
2006
|
return;
|
|
605
2007
|
}
|
|
606
2008
|
reject(
|
|
@@ -735,15 +2137,15 @@ function apiErrorMessage(data, status) {
|
|
|
735
2137
|
if (typeof data === "string") return data.trim() || fallback;
|
|
736
2138
|
if (typeof data !== "object" || data === null) return fallback;
|
|
737
2139
|
const body = data;
|
|
738
|
-
const
|
|
2140
|
+
const str2 = (v) => typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
739
2141
|
let message;
|
|
740
2142
|
let suggestion;
|
|
741
2143
|
if (typeof body.error === "object" && body.error !== null) {
|
|
742
2144
|
const detail = body.error;
|
|
743
|
-
message =
|
|
744
|
-
suggestion =
|
|
2145
|
+
message = str2(detail.message) ?? str2(detail.code);
|
|
2146
|
+
suggestion = str2(detail.suggestion);
|
|
745
2147
|
} else {
|
|
746
|
-
message =
|
|
2148
|
+
message = str2(body.message) ?? str2(body.error);
|
|
747
2149
|
}
|
|
748
2150
|
if (!message) {
|
|
749
2151
|
const raw = JSON.stringify(body);
|
|
@@ -752,10 +2154,10 @@ function apiErrorMessage(data, status) {
|
|
|
752
2154
|
return suggestion ? `${message} (${suggestion})` : message;
|
|
753
2155
|
}
|
|
754
2156
|
async function makeRequest(url, method, headers, body, reqOpts = {}) {
|
|
755
|
-
return new Promise((
|
|
2157
|
+
return new Promise((resolve4, reject) => {
|
|
756
2158
|
const parsedUrl = new URL(url);
|
|
757
2159
|
const isHttps = parsedUrl.protocol === "https:";
|
|
758
|
-
const lib = isHttps ? https :
|
|
2160
|
+
const lib = isHttps ? https : http2;
|
|
759
2161
|
const bodyBuffer = body ? Buffer.from(body, "utf-8") : null;
|
|
760
2162
|
const options = {
|
|
761
2163
|
hostname: parsedUrl.hostname,
|
|
@@ -778,12 +2180,12 @@ async function makeRequest(url, method, headers, body, reqOpts = {}) {
|
|
|
778
2180
|
res.on("end", () => {
|
|
779
2181
|
const data = Buffer.concat(chunks).toString("utf8");
|
|
780
2182
|
try {
|
|
781
|
-
|
|
2183
|
+
resolve4({
|
|
782
2184
|
status: res.statusCode || 0,
|
|
783
2185
|
data: data ? JSON.parse(data) : null
|
|
784
2186
|
});
|
|
785
2187
|
} catch {
|
|
786
|
-
|
|
2188
|
+
resolve4({ status: res.statusCode || 0, data });
|
|
787
2189
|
}
|
|
788
2190
|
});
|
|
789
2191
|
});
|
|
@@ -816,27 +2218,27 @@ function computeDeployTimeout(totalBytes, override) {
|
|
|
816
2218
|
return Math.max(DEPLOY_TIMEOUT_MIN_MS, DEPLOY_TIMEOUT_BASE_MS + sizeBased);
|
|
817
2219
|
}
|
|
818
2220
|
async function deploy(directory, config, isDev = false, deployOpts = {}) {
|
|
819
|
-
const dir =
|
|
820
|
-
if (!
|
|
2221
|
+
const dir = path4.resolve(directory);
|
|
2222
|
+
if (!fs4.existsSync(dir)) {
|
|
821
2223
|
error(`\uB514\uB809\uD1A0\uB9AC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${dir}`);
|
|
822
2224
|
process.exit(1);
|
|
823
2225
|
}
|
|
824
|
-
const pkgPath =
|
|
825
|
-
if (
|
|
2226
|
+
const pkgPath = path4.join(process.cwd(), "package.json");
|
|
2227
|
+
if (fs4.existsSync(pkgPath)) {
|
|
826
2228
|
try {
|
|
827
|
-
const pkg = JSON.parse(
|
|
2229
|
+
const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
|
|
828
2230
|
const pm = packageManagerCommands(detectPackageManager(process.cwd()));
|
|
829
2231
|
const inside = runningInsidePackageScript(pkg.scripts ?? {});
|
|
830
2232
|
for (const line of buildFirstHint(pkg, pm, inside)) warn(line);
|
|
831
2233
|
} catch {
|
|
832
2234
|
}
|
|
833
2235
|
}
|
|
834
|
-
if (!
|
|
2236
|
+
if (!fs4.statSync(dir).isDirectory()) {
|
|
835
2237
|
error(`${dir}\uB294 \uB514\uB809\uD1A0\uB9AC\uAC00 \uC544\uB2D9\uB2C8\uB2E4`);
|
|
836
2238
|
process.exit(1);
|
|
837
2239
|
}
|
|
838
|
-
const indexPath =
|
|
839
|
-
if (!
|
|
2240
|
+
const indexPath = path4.join(dir, "index.html");
|
|
2241
|
+
if (!fs4.existsSync(indexPath)) {
|
|
840
2242
|
error("index.html \uD30C\uC77C\uC774 \uD544\uC694\uD569\uB2C8\uB2E4");
|
|
841
2243
|
process.exit(1);
|
|
842
2244
|
}
|
|
@@ -1195,15 +2597,15 @@ function prompt(question) {
|
|
|
1195
2597
|
input: process.stdin,
|
|
1196
2598
|
output: process.stdout
|
|
1197
2599
|
});
|
|
1198
|
-
return new Promise((
|
|
2600
|
+
return new Promise((resolve4) => {
|
|
1199
2601
|
rl.question(question, (answer) => {
|
|
1200
2602
|
rl.close();
|
|
1201
|
-
|
|
2603
|
+
resolve4(answer.trim());
|
|
1202
2604
|
});
|
|
1203
2605
|
});
|
|
1204
2606
|
}
|
|
1205
2607
|
function promptSecret(question) {
|
|
1206
|
-
return new Promise((
|
|
2608
|
+
return new Promise((resolve4) => {
|
|
1207
2609
|
process.stdout.write(question);
|
|
1208
2610
|
const input = [];
|
|
1209
2611
|
if (!process.stdin.isTTY) {
|
|
@@ -1213,7 +2615,7 @@ function promptSecret(question) {
|
|
|
1213
2615
|
});
|
|
1214
2616
|
rl.question("", (answer) => {
|
|
1215
2617
|
rl.close();
|
|
1216
|
-
|
|
2618
|
+
resolve4(answer.trim());
|
|
1217
2619
|
});
|
|
1218
2620
|
return;
|
|
1219
2621
|
}
|
|
@@ -1228,7 +2630,7 @@ function promptSecret(question) {
|
|
|
1228
2630
|
process.stdin.pause();
|
|
1229
2631
|
process.stdin.removeListener("data", onData);
|
|
1230
2632
|
process.stdout.write("\n");
|
|
1231
|
-
|
|
2633
|
+
resolve4(input.join("").trim());
|
|
1232
2634
|
return;
|
|
1233
2635
|
} else if (code === 3) {
|
|
1234
2636
|
process.stdin.setRawMode(false);
|
|
@@ -1279,8 +2681,8 @@ function browserOpenCommand(url, platform2 = process.platform) {
|
|
|
1279
2681
|
function openBrowser(url) {
|
|
1280
2682
|
const opener = browserOpenCommand(url);
|
|
1281
2683
|
if (!opener) return;
|
|
1282
|
-
const { spawn } = require("child_process");
|
|
1283
|
-
const child =
|
|
2684
|
+
const { spawn: spawn2 } = require("child_process");
|
|
2685
|
+
const child = spawn2(opener.command, opener.args, {
|
|
1284
2686
|
stdio: "ignore",
|
|
1285
2687
|
detached: true
|
|
1286
2688
|
});
|
|
@@ -1291,7 +2693,7 @@ function openBrowser(url) {
|
|
|
1291
2693
|
function browserAuthStartBody() {
|
|
1292
2694
|
return {
|
|
1293
2695
|
flow: "user_code",
|
|
1294
|
-
hostname:
|
|
2696
|
+
hostname: os4.hostname(),
|
|
1295
2697
|
os: `${process.platform} ${process.arch}`,
|
|
1296
2698
|
cli_version: VERSION
|
|
1297
2699
|
};
|
|
@@ -1347,7 +2749,7 @@ ${colors.cyan}\uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uB85C\uADF8\uC778\uD558\uC13
|
|
|
1347
2749
|
process.stdout.write(
|
|
1348
2750
|
`\r${colors.blue}${frame}${colors.reset} \uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uC2B9\uC778 \uB300\uAE30 \uC911...`
|
|
1349
2751
|
);
|
|
1350
|
-
await new Promise((
|
|
2752
|
+
await new Promise((resolve4) => setTimeout(resolve4, pollInterval));
|
|
1351
2753
|
try {
|
|
1352
2754
|
const pollRes = await makeRequest(
|
|
1353
2755
|
`${baseUrl}/v1/public/cli-auth/poll/${session_id}`,
|
|
@@ -1442,11 +2844,11 @@ ${colors.dim}\uC778\uC99D \uBC29\uC2DD\uC744 \uC120\uD0DD\uD558\uC138\uC694:${co
|
|
|
1442
2844
|
return entered;
|
|
1443
2845
|
}
|
|
1444
2846
|
function saveSecretKeyToRc(secretKey, dir = process.cwd()) {
|
|
1445
|
-
const rcPath =
|
|
2847
|
+
const rcPath = path4.join(dir, ".connectbaserc");
|
|
1446
2848
|
let rcData = {};
|
|
1447
|
-
if (
|
|
2849
|
+
if (fs4.existsSync(rcPath)) {
|
|
1448
2850
|
try {
|
|
1449
|
-
rcData = JSON.parse(
|
|
2851
|
+
rcData = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
|
|
1450
2852
|
} catch {
|
|
1451
2853
|
}
|
|
1452
2854
|
}
|
|
@@ -1484,11 +2886,11 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
|
|
|
1484
2886
|
);
|
|
1485
2887
|
process.exit(1);
|
|
1486
2888
|
}
|
|
1487
|
-
const rcPath =
|
|
2889
|
+
const rcPath = path4.join(cwd, ".connectbaserc");
|
|
1488
2890
|
let existingRc = {};
|
|
1489
|
-
if (
|
|
2891
|
+
if (fs4.existsSync(rcPath)) {
|
|
1490
2892
|
try {
|
|
1491
|
-
existingRc = JSON.parse(
|
|
2893
|
+
existingRc = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
|
|
1492
2894
|
} catch {
|
|
1493
2895
|
}
|
|
1494
2896
|
if (nonInteractive) {
|
|
@@ -1531,7 +2933,7 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
|
|
|
1531
2933
|
}
|
|
1532
2934
|
let appId = "";
|
|
1533
2935
|
let publicKey = "";
|
|
1534
|
-
const projectName =
|
|
2936
|
+
const projectName = path4.basename(cwd);
|
|
1535
2937
|
const reuseKeyIfSameApp = (selectedAppId) => {
|
|
1536
2938
|
if (existingRc.appId === selectedAppId && existingRc.publicKey?.startsWith("cb_pk_")) {
|
|
1537
2939
|
publicKey = existingRc.publicKey;
|
|
@@ -1614,10 +3016,10 @@ ${colors.dim}\uB0B4 \uC571 \uBAA9\uB85D:${colors.reset}`);
|
|
|
1614
3016
|
`
|
|
1615
3017
|
${colors.blue}?${colors.reset} \uC120\uD0DD (\uBC88\uD638): `
|
|
1616
3018
|
);
|
|
1617
|
-
const
|
|
1618
|
-
if (
|
|
1619
|
-
appId = apps[
|
|
1620
|
-
success(`\uC120\uD0DD\uB428: ${apps[
|
|
3019
|
+
const num2 = parseInt(choice, 10);
|
|
3020
|
+
if (num2 > 0 && num2 <= apps.length) {
|
|
3021
|
+
appId = apps[num2 - 1].id;
|
|
3022
|
+
success(`\uC120\uD0DD\uB428: ${apps[num2 - 1].name}`);
|
|
1621
3023
|
if (!reuseKeyIfSameApp(appId)) await issuePublicKey(appId);
|
|
1622
3024
|
}
|
|
1623
3025
|
}
|
|
@@ -1713,10 +3115,10 @@ ${colors.dim}\uAE30\uC874 \uC6F9 \uC2A4\uD1A0\uB9AC\uC9C0:${colors.reset}`);
|
|
|
1713
3115
|
`
|
|
1714
3116
|
${colors.blue}?${colors.reset} \uC120\uD0DD (\uBC88\uD638): `
|
|
1715
3117
|
);
|
|
1716
|
-
const
|
|
1717
|
-
if (
|
|
1718
|
-
storageId = storages[
|
|
1719
|
-
success(`\uC120\uD0DD\uB428: ${storages[
|
|
3118
|
+
const num2 = parseInt(choice, 10);
|
|
3119
|
+
if (num2 > 0 && num2 <= storages.length) {
|
|
3120
|
+
storageId = storages[num2 - 1].id;
|
|
3121
|
+
success(`\uC120\uD0DD\uB428: ${storages[num2 - 1].name}`);
|
|
1720
3122
|
}
|
|
1721
3123
|
}
|
|
1722
3124
|
if (!storageId) {
|
|
@@ -1806,17 +3208,17 @@ ${colors.dim}Claude Code\uC5D0\uC11C MCP\uAC00 \uC790\uB3D9 \uC5F0\uACB0\uB429\u
|
|
|
1806
3208
|
`);
|
|
1807
3209
|
}
|
|
1808
3210
|
function detectBuildDir() {
|
|
1809
|
-
if (
|
|
1810
|
-
if (
|
|
1811
|
-
if (
|
|
1812
|
-
const nextConfig = ["next.config.js", "next.config.mjs", "next.config.ts"].map((f) =>
|
|
1813
|
-
if (nextConfig ||
|
|
3211
|
+
if (fs4.existsSync(path4.join(process.cwd(), "dist"))) return "./dist";
|
|
3212
|
+
if (fs4.existsSync(path4.join(process.cwd(), "build"))) return "./build";
|
|
3213
|
+
if (fs4.existsSync(path4.join(process.cwd(), "out"))) return "./out";
|
|
3214
|
+
const nextConfig = ["next.config.js", "next.config.mjs", "next.config.ts"].map((f) => path4.join(process.cwd(), f)).find((f) => fs4.existsSync(f));
|
|
3215
|
+
if (nextConfig || fs4.existsSync(path4.join(process.cwd(), ".next"))) {
|
|
1814
3216
|
if (nextConfig) {
|
|
1815
3217
|
try {
|
|
1816
|
-
const src =
|
|
3218
|
+
const src = fs4.readFileSync(nextConfig, "utf-8");
|
|
1817
3219
|
if (!/output\s*:\s*['"]export['"]/.test(src)) {
|
|
1818
3220
|
warn(
|
|
1819
|
-
`Next.js \uAC10\uC9C0: \uC815\uC801 \uBC30\uD3EC\uD558\uB824\uBA74 ${
|
|
3221
|
+
`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
3222
|
);
|
|
1821
3223
|
}
|
|
1822
3224
|
} catch {
|
|
@@ -1824,25 +3226,25 @@ function detectBuildDir() {
|
|
|
1824
3226
|
}
|
|
1825
3227
|
return "./out";
|
|
1826
3228
|
}
|
|
1827
|
-
if (
|
|
3229
|
+
if (fs4.existsSync(path4.join(process.cwd(), "vite.config.ts")) || fs4.existsSync(path4.join(process.cwd(), "vite.config.js")))
|
|
1828
3230
|
return "./dist";
|
|
1829
3231
|
return "./dist";
|
|
1830
3232
|
}
|
|
1831
3233
|
function writeSecretFile(filePath, content) {
|
|
1832
3234
|
try {
|
|
1833
|
-
if (
|
|
3235
|
+
if (fs4.existsSync(filePath)) fs4.chmodSync(filePath, 384);
|
|
1834
3236
|
} catch {
|
|
1835
3237
|
}
|
|
1836
|
-
|
|
3238
|
+
fs4.writeFileSync(filePath, content, { mode: 384 });
|
|
1837
3239
|
}
|
|
1838
3240
|
function addToGitignore(entry, basePath) {
|
|
1839
3241
|
const dir = basePath || process.cwd();
|
|
1840
|
-
const gitignorePath =
|
|
1841
|
-
if (
|
|
1842
|
-
const content =
|
|
3242
|
+
const gitignorePath = path4.join(dir, ".gitignore");
|
|
3243
|
+
if (fs4.existsSync(gitignorePath)) {
|
|
3244
|
+
const content = fs4.readFileSync(gitignorePath, "utf-8");
|
|
1843
3245
|
const lines = content.split(/\r?\n/).map((l) => l.trim());
|
|
1844
3246
|
if (!lines.includes(entry)) {
|
|
1845
|
-
|
|
3247
|
+
fs4.appendFileSync(gitignorePath, `
|
|
1846
3248
|
# Connect Base
|
|
1847
3249
|
${entry}
|
|
1848
3250
|
`);
|
|
@@ -1851,7 +3253,7 @@ ${entry}
|
|
|
1851
3253
|
info(`.gitignore\uC5D0 \uC774\uBBF8 ${entry}\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4`);
|
|
1852
3254
|
}
|
|
1853
3255
|
} else {
|
|
1854
|
-
|
|
3256
|
+
fs4.writeFileSync(gitignorePath, `# Connect Base
|
|
1855
3257
|
${entry}
|
|
1856
3258
|
`);
|
|
1857
3259
|
success(".gitignore \uC0DD\uC131 \uC644\uB8CC");
|
|
@@ -1882,8 +3284,8 @@ function ancestorCommandLines(maxDepth = 8) {
|
|
|
1882
3284
|
let ppid = 0;
|
|
1883
3285
|
try {
|
|
1884
3286
|
if (process.platform === "linux") {
|
|
1885
|
-
cmd =
|
|
1886
|
-
const stat =
|
|
3287
|
+
cmd = fs4.readFileSync(`/proc/${pid}/cmdline`).toString("utf8").replace(/\0/g, " ").trim();
|
|
3288
|
+
const stat = fs4.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
1887
3289
|
ppid = parseInt(
|
|
1888
3290
|
stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1],
|
|
1889
3291
|
10
|
|
@@ -1927,7 +3329,7 @@ function buildFirstHint(pkg, pm, insideScript) {
|
|
|
1927
3329
|
function detectPackageManager(startDir = process.cwd()) {
|
|
1928
3330
|
try {
|
|
1929
3331
|
const pkg = JSON.parse(
|
|
1930
|
-
|
|
3332
|
+
fs4.readFileSync(path4.join(startDir, "package.json"), "utf-8")
|
|
1931
3333
|
);
|
|
1932
3334
|
const declared = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : "";
|
|
1933
3335
|
if (declared === "npm" || declared === "pnpm" || declared === "yarn" || declared === "bun") {
|
|
@@ -1943,13 +3345,13 @@ function detectPackageManager(startDir = process.cwd()) {
|
|
|
1943
3345
|
["package-lock.json", "npm"],
|
|
1944
3346
|
["npm-shrinkwrap.json", "npm"]
|
|
1945
3347
|
];
|
|
1946
|
-
let dir =
|
|
3348
|
+
let dir = path4.resolve(startDir);
|
|
1947
3349
|
for (; ; ) {
|
|
1948
3350
|
for (const [file, pm] of lockfiles) {
|
|
1949
|
-
if (
|
|
3351
|
+
if (fs4.existsSync(path4.join(dir, file))) return pm;
|
|
1950
3352
|
}
|
|
1951
|
-
if (
|
|
1952
|
-
const parent =
|
|
3353
|
+
if (fs4.existsSync(path4.join(dir, ".git"))) break;
|
|
3354
|
+
const parent = path4.dirname(dir);
|
|
1953
3355
|
if (parent === dir) break;
|
|
1954
3356
|
dir = parent;
|
|
1955
3357
|
}
|
|
@@ -1963,13 +3365,13 @@ function packageManagerCommands(pm) {
|
|
|
1963
3365
|
};
|
|
1964
3366
|
}
|
|
1965
3367
|
function addDeployScript(deployDir, pm) {
|
|
1966
|
-
const pkgPath =
|
|
1967
|
-
if (!
|
|
3368
|
+
const pkgPath = path4.join(process.cwd(), "package.json");
|
|
3369
|
+
if (!fs4.existsSync(pkgPath)) {
|
|
1968
3370
|
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
3371
|
return { needsInstall: false };
|
|
1970
3372
|
}
|
|
1971
3373
|
try {
|
|
1972
|
-
const pkg = JSON.parse(
|
|
3374
|
+
const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
|
|
1973
3375
|
if (!pkg.scripts) pkg.scripts = {};
|
|
1974
3376
|
const declared = (name) => Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
1975
3377
|
let needsInstall = false;
|
|
@@ -1987,7 +3389,7 @@ function addDeployScript(deployDir, pm) {
|
|
|
1987
3389
|
pkg.scripts.deploy = pkg.scripts.build ? `${pm.run("build")} && ${deployCmd}` : deployCmd;
|
|
1988
3390
|
success("package.json\uC5D0 deploy \uC2A4\uD06C\uB9BD\uD2B8 \uCD94\uAC00 \uC644\uB8CC");
|
|
1989
3391
|
}
|
|
1990
|
-
|
|
3392
|
+
fs4.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
1991
3393
|
`);
|
|
1992
3394
|
if (needsInstall) {
|
|
1993
3395
|
success(
|
|
@@ -2018,32 +3420,32 @@ function detectMonorepo(gitRoot) {
|
|
|
2018
3420
|
root: gitRoot,
|
|
2019
3421
|
isSubPackage: false
|
|
2020
3422
|
};
|
|
2021
|
-
if (
|
|
3423
|
+
if (fs4.existsSync(path4.join(gitRoot, "pnpm-workspace.yaml"))) {
|
|
2022
3424
|
result.type = "pnpm";
|
|
2023
|
-
} else if (
|
|
3425
|
+
} else if (fs4.existsSync(path4.join(gitRoot, "turbo.json"))) {
|
|
2024
3426
|
result.type = "turborepo";
|
|
2025
|
-
} else if (
|
|
3427
|
+
} else if (fs4.existsSync(path4.join(gitRoot, "nx.json"))) {
|
|
2026
3428
|
result.type = "nx";
|
|
2027
|
-
} else if (
|
|
3429
|
+
} else if (fs4.existsSync(path4.join(gitRoot, "lerna.json"))) {
|
|
2028
3430
|
result.type = "lerna";
|
|
2029
3431
|
} else {
|
|
2030
|
-
const rootPkgPath =
|
|
2031
|
-
if (
|
|
3432
|
+
const rootPkgPath = path4.join(gitRoot, "package.json");
|
|
3433
|
+
if (fs4.existsSync(rootPkgPath)) {
|
|
2032
3434
|
try {
|
|
2033
|
-
const pkg = JSON.parse(
|
|
3435
|
+
const pkg = JSON.parse(fs4.readFileSync(rootPkgPath, "utf-8"));
|
|
2034
3436
|
if (pkg.workspaces) {
|
|
2035
|
-
result.type =
|
|
3437
|
+
result.type = fs4.existsSync(path4.join(gitRoot, "yarn.lock")) ? "yarn" : "npm";
|
|
2036
3438
|
}
|
|
2037
3439
|
} catch {
|
|
2038
3440
|
}
|
|
2039
3441
|
}
|
|
2040
3442
|
}
|
|
2041
3443
|
if (result.type !== "none" && cwd !== gitRoot) {
|
|
2042
|
-
const cwdPkgPath =
|
|
2043
|
-
if (
|
|
3444
|
+
const cwdPkgPath = path4.join(cwd, "package.json");
|
|
3445
|
+
if (fs4.existsSync(cwdPkgPath)) {
|
|
2044
3446
|
result.isSubPackage = true;
|
|
2045
3447
|
try {
|
|
2046
|
-
const pkg = JSON.parse(
|
|
3448
|
+
const pkg = JSON.parse(fs4.readFileSync(cwdPkgPath, "utf-8"));
|
|
2047
3449
|
result.subPackageName = pkg.name;
|
|
2048
3450
|
} catch {
|
|
2049
3451
|
}
|
|
@@ -2055,7 +3457,7 @@ var DOCS_MANIFEST_FILE = ".connectbase-manifest.json";
|
|
|
2055
3457
|
function readDocsManifest(docsDir) {
|
|
2056
3458
|
try {
|
|
2057
3459
|
const parsed = JSON.parse(
|
|
2058
|
-
|
|
3460
|
+
fs4.readFileSync(path4.join(docsDir, DOCS_MANIFEST_FILE), "utf-8")
|
|
2059
3461
|
);
|
|
2060
3462
|
if (parsed && Array.isArray(parsed.files)) return parsed;
|
|
2061
3463
|
} catch {
|
|
@@ -2117,14 +3519,14 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
2117
3519
|
info(`\uBAA8\uB178\uB808\uD3EC \uAC10\uC9C0: ${monorepo.type} (\uB8E8\uD2B8: ${gitRoot})`);
|
|
2118
3520
|
if (monorepo.isSubPackage) {
|
|
2119
3521
|
info(
|
|
2120
|
-
`\uD604\uC7AC \uC11C\uBE0C \uD328\uD0A4\uC9C0: ${monorepo.subPackageName ||
|
|
3522
|
+
`\uD604\uC7AC \uC11C\uBE0C \uD328\uD0A4\uC9C0: ${monorepo.subPackageName || path4.basename(process.cwd())}`
|
|
2121
3523
|
);
|
|
2122
3524
|
}
|
|
2123
3525
|
}
|
|
2124
|
-
const docsDir =
|
|
2125
|
-
const rootClaudeMd =
|
|
2126
|
-
if (!
|
|
2127
|
-
|
|
3526
|
+
const docsDir = path4.join(gitRoot, ".claude", "docs");
|
|
3527
|
+
const rootClaudeMd = path4.join(gitRoot, "CLAUDE.md");
|
|
3528
|
+
if (!fs4.existsSync(docsDir)) {
|
|
3529
|
+
fs4.mkdirSync(docsDir, { recursive: true });
|
|
2128
3530
|
}
|
|
2129
3531
|
if (!quiet) info("SDK \uAC1C\uBC1C \uAC00\uC774\uB4DC \uB2E4\uC6B4\uB85C\uB4DC \uC911...");
|
|
2130
3532
|
try {
|
|
@@ -2141,21 +3543,21 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
2141
3543
|
const hasher = crypto.createHash("sha256");
|
|
2142
3544
|
const newFiles = [];
|
|
2143
3545
|
for (const section of sections) {
|
|
2144
|
-
const safeName =
|
|
3546
|
+
const safeName = path4.basename(section.filename);
|
|
2145
3547
|
newFiles.push(safeName);
|
|
2146
3548
|
hasher.update(safeName).update("\0").update(section.content).update("\0");
|
|
2147
3549
|
}
|
|
2148
3550
|
const contentHash = hasher.digest("hex");
|
|
2149
3551
|
const prevManifest = readDocsManifest(docsDir);
|
|
2150
3552
|
const allPresent = newFiles.every(
|
|
2151
|
-
(f) =>
|
|
3553
|
+
(f) => fs4.existsSync(path4.join(docsDir, f))
|
|
2152
3554
|
);
|
|
2153
3555
|
if (prevManifest && prevManifest.contentHash === contentHash && allPresent) {
|
|
2154
3556
|
if (!quiet) success("SDK \uBB38\uC11C\uAC00 \uC774\uBBF8 \uCD5C\uC2E0\uC785\uB2C8\uB2E4");
|
|
2155
3557
|
updateRootClaudeMd(rootClaudeMd, quiet);
|
|
2156
3558
|
if (monorepo.isSubPackage) {
|
|
2157
3559
|
createSubPackageClaudeMd(
|
|
2158
|
-
|
|
3560
|
+
path4.join(process.cwd(), "CLAUDE.md"),
|
|
2159
3561
|
gitRoot,
|
|
2160
3562
|
quiet
|
|
2161
3563
|
);
|
|
@@ -2166,16 +3568,16 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
2166
3568
|
|
|
2167
3569
|
`;
|
|
2168
3570
|
for (const section of sections) {
|
|
2169
|
-
const safeName =
|
|
2170
|
-
|
|
3571
|
+
const safeName = path4.basename(section.filename);
|
|
3572
|
+
fs4.writeFileSync(path4.join(docsDir, safeName), stamp + section.content);
|
|
2171
3573
|
}
|
|
2172
|
-
const staleCandidates = prevManifest ? prevManifest.files.map((f) =>
|
|
3574
|
+
const staleCandidates = prevManifest ? prevManifest.files.map((f) => path4.basename(f)) : LEGACY_DOC_FILES;
|
|
2173
3575
|
for (const old of staleCandidates) {
|
|
2174
3576
|
if (newFiles.includes(old)) continue;
|
|
2175
|
-
const oldPath =
|
|
2176
|
-
if (
|
|
3577
|
+
const oldPath = path4.join(docsDir, old);
|
|
3578
|
+
if (fs4.existsSync(oldPath)) {
|
|
2177
3579
|
try {
|
|
2178
|
-
|
|
3580
|
+
fs4.unlinkSync(oldPath);
|
|
2179
3581
|
if (!quiet) info(`\uC2A4\uD14C\uC77C \uBB38\uC11C \uC0AD\uC81C: ${old}`);
|
|
2180
3582
|
} catch {
|
|
2181
3583
|
}
|
|
@@ -2187,8 +3589,8 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
2187
3589
|
contentHash,
|
|
2188
3590
|
files: newFiles
|
|
2189
3591
|
};
|
|
2190
|
-
|
|
2191
|
-
|
|
3592
|
+
fs4.writeFileSync(
|
|
3593
|
+
path4.join(docsDir, DOCS_MANIFEST_FILE),
|
|
2192
3594
|
`${JSON.stringify(manifest, null, 2)}
|
|
2193
3595
|
`
|
|
2194
3596
|
);
|
|
@@ -2199,7 +3601,7 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
2199
3601
|
updateRootClaudeMd(rootClaudeMd, quiet);
|
|
2200
3602
|
if (monorepo.isSubPackage) {
|
|
2201
3603
|
createSubPackageClaudeMd(
|
|
2202
|
-
|
|
3604
|
+
path4.join(process.cwd(), "CLAUDE.md"),
|
|
2203
3605
|
gitRoot,
|
|
2204
3606
|
quiet
|
|
2205
3607
|
);
|
|
@@ -2218,10 +3620,10 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
2218
3620
|
|
|
2219
3621
|
\uC0C1\uC138 \uAD6C\uD604\uBC95\uC740 MCP \`search_sdk_docs\` \uB3C4\uAD6C\uB85C \uAC80\uC0C9\uD558\uC138\uC694.
|
|
2220
3622
|
`;
|
|
2221
|
-
|
|
3623
|
+
fs4.writeFileSync(path4.join(docsDir, "project-rules.md"), fallbackContent);
|
|
2222
3624
|
updateRootClaudeMd(rootClaudeMd);
|
|
2223
3625
|
if (monorepo.isSubPackage) {
|
|
2224
|
-
const subClaudeMd =
|
|
3626
|
+
const subClaudeMd = path4.join(process.cwd(), "CLAUDE.md");
|
|
2225
3627
|
createSubPackageClaudeMd(subClaudeMd, gitRoot);
|
|
2226
3628
|
}
|
|
2227
3629
|
success(`.claude/docs/ \uC0DD\uC131 \uC644\uB8CC (\uAE30\uBCF8)`);
|
|
@@ -2244,8 +3646,8 @@ function updateRootClaudeMd(claudeMdPath, quiet = false) {
|
|
|
2244
3646
|
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
3647
|
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
3648
|
${endMarker}`;
|
|
2247
|
-
if (
|
|
2248
|
-
let content =
|
|
3649
|
+
if (fs4.existsSync(claudeMdPath)) {
|
|
3650
|
+
let content = fs4.readFileSync(claudeMdPath, "utf-8");
|
|
2249
3651
|
const startIdx = content.indexOf(startMarker);
|
|
2250
3652
|
const endIdx = content.indexOf(endMarker);
|
|
2251
3653
|
if (startIdx !== -1 && endIdx !== -1) {
|
|
@@ -2255,10 +3657,10 @@ ${endMarker}`;
|
|
|
2255
3657
|
|
|
2256
3658
|
${content.trimStart()}`;
|
|
2257
3659
|
}
|
|
2258
|
-
|
|
3660
|
+
fs4.writeFileSync(claudeMdPath, content);
|
|
2259
3661
|
if (!quiet) info("CLAUDE.md\uC5D0 ConnectBase \uCC38\uC870 \uC5C5\uB370\uC774\uD2B8 \uC644\uB8CC");
|
|
2260
3662
|
} else {
|
|
2261
|
-
|
|
3663
|
+
fs4.writeFileSync(claudeMdPath, `# \uD504\uB85C\uC81D\uD2B8
|
|
2262
3664
|
|
|
2263
3665
|
${sdkBlock}
|
|
2264
3666
|
`);
|
|
@@ -2268,7 +3670,7 @@ ${sdkBlock}
|
|
|
2268
3670
|
function createSubPackageClaudeMd(subClaudeMdPath, gitRoot, quiet = false) {
|
|
2269
3671
|
const startMarker = "<!-- CONNECTBASE_SUB_START -->";
|
|
2270
3672
|
const endMarker = "<!-- CONNECTBASE_SUB_END -->";
|
|
2271
|
-
const relPath =
|
|
3673
|
+
const relPath = path4.relative(path4.dirname(subClaudeMdPath), gitRoot);
|
|
2272
3674
|
const subBlock = `${startMarker}
|
|
2273
3675
|
## ConnectBase SDK
|
|
2274
3676
|
|
|
@@ -2280,8 +3682,8 @@ function createSubPackageClaudeMd(subClaudeMdPath, gitRoot, quiet = false) {
|
|
|
2280
3682
|
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
3683
|
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
3684
|
${endMarker}`;
|
|
2283
|
-
if (
|
|
2284
|
-
let content =
|
|
3685
|
+
if (fs4.existsSync(subClaudeMdPath)) {
|
|
3686
|
+
let content = fs4.readFileSync(subClaudeMdPath, "utf-8");
|
|
2285
3687
|
const startIdx = content.indexOf(startMarker);
|
|
2286
3688
|
const endIdx = content.indexOf(endMarker);
|
|
2287
3689
|
if (startIdx !== -1 && endIdx !== -1) {
|
|
@@ -2294,11 +3696,11 @@ ${subBlock}
|
|
|
2294
3696
|
} else {
|
|
2295
3697
|
return;
|
|
2296
3698
|
}
|
|
2297
|
-
|
|
3699
|
+
fs4.writeFileSync(subClaudeMdPath, content);
|
|
2298
3700
|
} else {
|
|
2299
|
-
|
|
3701
|
+
fs4.writeFileSync(
|
|
2300
3702
|
subClaudeMdPath,
|
|
2301
|
-
`# ${
|
|
3703
|
+
`# ${path4.basename(path4.dirname(subClaudeMdPath))}
|
|
2302
3704
|
|
|
2303
3705
|
${subBlock}
|
|
2304
3706
|
`
|
|
@@ -2316,7 +3718,7 @@ async function setupMcp(secretKey, baseUrl = DEFAULT_BASE_URL) {
|
|
|
2316
3718
|
info(`MCP \uC124\uC815\uC740 \uD504\uB85C\uC81D\uD2B8 \uB8E8\uD2B8(${root})\uC5D0 \uC0DD\uC131\uB429\uB2C8\uB2E4`);
|
|
2317
3719
|
}
|
|
2318
3720
|
}
|
|
2319
|
-
const mcpConfigPath =
|
|
3721
|
+
const mcpConfigPath = path4.join(root, ".mcp.json");
|
|
2320
3722
|
if (secretKey) {
|
|
2321
3723
|
const check = await fetchAppsWithSecretKey(baseUrl, secretKey).catch(
|
|
2322
3724
|
() => null
|
|
@@ -2351,17 +3753,17 @@ async function setupMcp(secretKey, baseUrl = DEFAULT_BASE_URL) {
|
|
|
2351
3753
|
}
|
|
2352
3754
|
};
|
|
2353
3755
|
let mcpConfig = { mcpServers: {} };
|
|
2354
|
-
if (
|
|
3756
|
+
if (fs4.existsSync(mcpConfigPath)) {
|
|
2355
3757
|
try {
|
|
2356
|
-
mcpConfig = JSON.parse(
|
|
3758
|
+
mcpConfig = JSON.parse(fs4.readFileSync(mcpConfigPath, "utf-8"));
|
|
2357
3759
|
if (!mcpConfig.mcpServers || typeof mcpConfig.mcpServers !== "object") {
|
|
2358
3760
|
mcpConfig.mcpServers = {};
|
|
2359
3761
|
}
|
|
2360
3762
|
} catch {
|
|
2361
3763
|
const backupPath = `${mcpConfigPath}.backup`;
|
|
2362
|
-
|
|
3764
|
+
fs4.copyFileSync(mcpConfigPath, backupPath);
|
|
2363
3765
|
try {
|
|
2364
|
-
|
|
3766
|
+
fs4.chmodSync(backupPath, 384);
|
|
2365
3767
|
} catch {
|
|
2366
3768
|
}
|
|
2367
3769
|
warn(`.mcp.json \uD30C\uC2F1 \uC2E4\uD328, \uBC31\uC5C5 \uC0DD\uC131: ${backupPath}`);
|
|
@@ -2422,14 +3824,14 @@ function findSubPackagesWithConfig(gitRoot) {
|
|
|
2422
3824
|
const results = [];
|
|
2423
3825
|
const candidates = ["apps", "packages", "projects", "services", "libs"];
|
|
2424
3826
|
for (const candidate of candidates) {
|
|
2425
|
-
const dir =
|
|
2426
|
-
if (!
|
|
3827
|
+
const dir = path4.join(gitRoot, candidate);
|
|
3828
|
+
if (!fs4.existsSync(dir)) continue;
|
|
2427
3829
|
try {
|
|
2428
|
-
const entries =
|
|
3830
|
+
const entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
2429
3831
|
for (const entry of entries) {
|
|
2430
3832
|
if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
|
|
2431
|
-
const subDir =
|
|
2432
|
-
if (
|
|
3833
|
+
const subDir = path4.join(dir, entry.name);
|
|
3834
|
+
if (fs4.existsSync(path4.join(subDir, ".connectbaserc"))) {
|
|
2433
3835
|
results.push(subDir);
|
|
2434
3836
|
}
|
|
2435
3837
|
}
|
|
@@ -2437,13 +3839,13 @@ function findSubPackagesWithConfig(gitRoot) {
|
|
|
2437
3839
|
}
|
|
2438
3840
|
}
|
|
2439
3841
|
try {
|
|
2440
|
-
const entries =
|
|
3842
|
+
const entries = fs4.readdirSync(gitRoot, { withFileTypes: true });
|
|
2441
3843
|
for (const entry of entries) {
|
|
2442
3844
|
if (!entry.isDirectory() || entry.name.startsWith(".") || candidates.includes(entry.name))
|
|
2443
3845
|
continue;
|
|
2444
3846
|
if (entry.name === "node_modules") continue;
|
|
2445
|
-
const subDir =
|
|
2446
|
-
if (
|
|
3847
|
+
const subDir = path4.join(gitRoot, entry.name);
|
|
3848
|
+
if (fs4.existsSync(path4.join(subDir, ".connectbaserc")) && !results.includes(subDir)) {
|
|
2447
3849
|
results.push(subDir);
|
|
2448
3850
|
}
|
|
2449
3851
|
}
|
|
@@ -2487,7 +3889,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
2487
3889
|
info(`ConnectBase\uB97C \uC0AC\uC6A9\uD558\uB294 \uC11C\uBE0C \uD328\uD0A4\uC9C0 ${subPackages.length}\uAC1C \uBC1C\uACAC:`);
|
|
2488
3890
|
for (const sp of subPackages) {
|
|
2489
3891
|
log(
|
|
2490
|
-
` ${colors.dim}\u2022 ${
|
|
3892
|
+
` ${colors.dim}\u2022 ${path4.relative(projectRoot, sp)}${colors.reset}`
|
|
2491
3893
|
);
|
|
2492
3894
|
}
|
|
2493
3895
|
}
|
|
@@ -2499,14 +3901,14 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
2499
3901
|
}
|
|
2500
3902
|
if (!opts.skipMcp) {
|
|
2501
3903
|
log("");
|
|
2502
|
-
const mcpConfigPath =
|
|
2503
|
-
if (
|
|
3904
|
+
const mcpConfigPath = path4.join(projectRoot, ".mcp.json");
|
|
3905
|
+
if (fs4.existsSync(mcpConfigPath)) {
|
|
2504
3906
|
let secretKey = config.secretKey;
|
|
2505
3907
|
if (!secretKey) {
|
|
2506
|
-
const rootRcPath =
|
|
2507
|
-
if (
|
|
3908
|
+
const rootRcPath = path4.join(projectRoot, ".connectbaserc");
|
|
3909
|
+
if (fs4.existsSync(rootRcPath)) {
|
|
2508
3910
|
try {
|
|
2509
|
-
const rc = JSON.parse(
|
|
3911
|
+
const rc = JSON.parse(fs4.readFileSync(rootRcPath, "utf-8"));
|
|
2510
3912
|
secretKey = rc.secretKey;
|
|
2511
3913
|
} catch {
|
|
2512
3914
|
}
|
|
@@ -2517,7 +3919,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
2517
3919
|
for (const sp of subPackages) {
|
|
2518
3920
|
try {
|
|
2519
3921
|
const rc = JSON.parse(
|
|
2520
|
-
|
|
3922
|
+
fs4.readFileSync(path4.join(sp, ".connectbaserc"), "utf-8")
|
|
2521
3923
|
);
|
|
2522
3924
|
if (rc.secretKey) {
|
|
2523
3925
|
secretKey = rc.secretKey;
|
|
@@ -2529,7 +3931,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
2529
3931
|
}
|
|
2530
3932
|
if (secretKey) {
|
|
2531
3933
|
try {
|
|
2532
|
-
const mcpConfig = JSON.parse(
|
|
3934
|
+
const mcpConfig = JSON.parse(fs4.readFileSync(mcpConfigPath, "utf-8"));
|
|
2533
3935
|
const servers = mcpConfig.mcpServers || {};
|
|
2534
3936
|
if (servers["connect-base"]) {
|
|
2535
3937
|
servers["connect-base"] = {
|
|
@@ -2568,15 +3970,15 @@ ${colors.green}\uC5C5\uB370\uC774\uD2B8 \uC644\uB8CC!${colors.reset}
|
|
|
2568
3970
|
`);
|
|
2569
3971
|
}
|
|
2570
3972
|
function setupMonorepoRoot(projectRoot, monorepo) {
|
|
2571
|
-
const rootPkgPath =
|
|
2572
|
-
if (!
|
|
3973
|
+
const rootPkgPath = path4.join(projectRoot, "package.json");
|
|
3974
|
+
if (!fs4.existsSync(rootPkgPath)) {
|
|
2573
3975
|
warn(
|
|
2574
3976
|
"\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
3977
|
);
|
|
2576
3978
|
return;
|
|
2577
3979
|
}
|
|
2578
3980
|
try {
|
|
2579
|
-
const pkg = JSON.parse(
|
|
3981
|
+
const pkg = JSON.parse(fs4.readFileSync(rootPkgPath, "utf-8"));
|
|
2580
3982
|
if (!pkg.scripts) pkg.scripts = {};
|
|
2581
3983
|
let changed = false;
|
|
2582
3984
|
if (!pkg.scripts["cb:update"]) {
|
|
@@ -2592,7 +3994,7 @@ function setupMonorepoRoot(projectRoot, monorepo) {
|
|
|
2592
3994
|
changed = true;
|
|
2593
3995
|
}
|
|
2594
3996
|
if (changed) {
|
|
2595
|
-
|
|
3997
|
+
fs4.writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
2596
3998
|
`);
|
|
2597
3999
|
success("\uBAA8\uB178\uB808\uD3EC \uB8E8\uD2B8\uC5D0 \uD3B8\uC758 \uC2A4\uD06C\uB9BD\uD2B8 \uCD94\uAC00 \uC644\uB8CC");
|
|
2598
4000
|
log(` ${colors.dim}\uC0AC\uC6A9\uBC95:${colors.reset}`);
|
|
@@ -2992,12 +4394,12 @@ ${colors.dim}\uB0B4 \uC571 \uBAA9\uB85D:${colors.reset}`);
|
|
|
2992
4394
|
`
|
|
2993
4395
|
${colors.blue}?${colors.reset} \uC571 \uC120\uD0DD (\uBC88\uD638): `
|
|
2994
4396
|
);
|
|
2995
|
-
const
|
|
2996
|
-
if (
|
|
2997
|
-
success(`\uC120\uD0DD\uB428: ${apps[
|
|
2998
|
-
return { appId: apps[
|
|
4397
|
+
const num2 = parseInt(choice, 10);
|
|
4398
|
+
if (num2 > 0 && num2 <= apps.length) {
|
|
4399
|
+
success(`\uC120\uD0DD\uB428: ${apps[num2 - 1].name}`);
|
|
4400
|
+
return { appId: apps[num2 - 1].id };
|
|
2999
4401
|
}
|
|
3000
|
-
const projectName =
|
|
4402
|
+
const projectName = path4.basename(process.cwd());
|
|
3001
4403
|
const appName = await prompt(
|
|
3002
4404
|
`${colors.blue}?${colors.reset} \uC571 \uC774\uB984 (${projectName}): `
|
|
3003
4405
|
) || projectName;
|
|
@@ -3048,9 +4450,9 @@ async function registerEndpointBinding(baseUrl, appId, secretKey, tunnelId, labe
|
|
|
3048
4450
|
`"${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
4451
|
);
|
|
3050
4452
|
} else {
|
|
3051
|
-
const
|
|
4453
|
+
const text2 = await res.text().catch(() => "");
|
|
3052
4454
|
error(
|
|
3053
|
-
`Endpoint "${label}" \uC790\uB3D9 \uB4F1\uB85D \uC2E4\uD328 (status ${res.status}): ${
|
|
4455
|
+
`Endpoint "${label}" \uC790\uB3D9 \uB4F1\uB85D \uC2E4\uD328 (status ${res.status}): ${text2 || "(\uBE48 \uC751\uB2F5)"}`
|
|
3054
4456
|
);
|
|
3055
4457
|
if (res.status === 401) {
|
|
3056
4458
|
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 +4482,11 @@ async function startTunnel(port, config, tunnelOpts) {
|
|
|
3080
4482
|
info("Secret Key\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. \uBE0C\uB77C\uC6B0\uC800 \uB85C\uADF8\uC778\uC73C\uB85C \uBC1C\uAE09\uD569\uB2C8\uB2E4...");
|
|
3081
4483
|
try {
|
|
3082
4484
|
const sk = await browserAuthFlow();
|
|
3083
|
-
const rcPath2 =
|
|
4485
|
+
const rcPath2 = path4.join(process.cwd(), ".connectbaserc");
|
|
3084
4486
|
let rcData = {};
|
|
3085
|
-
if (
|
|
4487
|
+
if (fs4.existsSync(rcPath2)) {
|
|
3086
4488
|
try {
|
|
3087
|
-
rcData = JSON.parse(
|
|
4489
|
+
rcData = JSON.parse(fs4.readFileSync(rcPath2, "utf-8"));
|
|
3088
4490
|
} catch {
|
|
3089
4491
|
}
|
|
3090
4492
|
}
|
|
@@ -3103,11 +4505,11 @@ async function startTunnel(port, config, tunnelOpts) {
|
|
|
3103
4505
|
} else {
|
|
3104
4506
|
config.secretKey = tunnelKey;
|
|
3105
4507
|
}
|
|
3106
|
-
const rcPath =
|
|
4508
|
+
const rcPath = path4.join(process.cwd(), ".connectbaserc");
|
|
3107
4509
|
let savedAppId = tunnelOpts?.appId || "";
|
|
3108
4510
|
if (!savedAppId) {
|
|
3109
4511
|
try {
|
|
3110
|
-
const rc = JSON.parse(
|
|
4512
|
+
const rc = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
|
|
3111
4513
|
if (rc.tunnelAppId) savedAppId = rc.tunnelAppId;
|
|
3112
4514
|
} catch {
|
|
3113
4515
|
}
|
|
@@ -3115,9 +4517,9 @@ async function startTunnel(port, config, tunnelOpts) {
|
|
|
3115
4517
|
const { appId } = await resolveApp(tunnelKey, config.baseUrl, savedAppId);
|
|
3116
4518
|
try {
|
|
3117
4519
|
let rcData = {};
|
|
3118
|
-
if (
|
|
4520
|
+
if (fs4.existsSync(rcPath)) {
|
|
3119
4521
|
try {
|
|
3120
|
-
rcData = JSON.parse(
|
|
4522
|
+
rcData = JSON.parse(fs4.readFileSync(rcPath, "utf-8"));
|
|
3121
4523
|
} catch {
|
|
3122
4524
|
}
|
|
3123
4525
|
}
|
|
@@ -3199,7 +4601,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
|
|
|
3199
4601
|
function connect() {
|
|
3200
4602
|
const target = currentUrl();
|
|
3201
4603
|
const targetHttps = target.protocol === "https:";
|
|
3202
|
-
const lib = targetHttps ? https :
|
|
4604
|
+
const lib = targetHttps ? https : http2;
|
|
3203
4605
|
const wsKey = crypto.randomBytes(16).toString("base64");
|
|
3204
4606
|
const reqOptions = {
|
|
3205
4607
|
hostname: target.hostname,
|
|
@@ -3392,7 +4794,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
|
|
|
3392
4794
|
}
|
|
3393
4795
|
}
|
|
3394
4796
|
}
|
|
3395
|
-
const localAgent = new
|
|
4797
|
+
const localAgent = new http2.Agent({ keepAlive: true, maxSockets: 64 });
|
|
3396
4798
|
function routeStreamData(sock, streamId, payload) {
|
|
3397
4799
|
const f = streams.get(skey(sock, streamId));
|
|
3398
4800
|
if (!f) return;
|
|
@@ -3455,7 +4857,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
|
|
|
3455
4857
|
localHeaders.host = `localhost:${localPort}`;
|
|
3456
4858
|
let started = false;
|
|
3457
4859
|
let cancelled = false;
|
|
3458
|
-
const localReq =
|
|
4860
|
+
const localReq = http2.request(
|
|
3459
4861
|
{
|
|
3460
4862
|
hostname: "127.0.0.1",
|
|
3461
4863
|
port: localPort,
|
|
@@ -3570,7 +4972,7 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
|
|
|
3570
4972
|
localHeaders.upgrade = "websocket";
|
|
3571
4973
|
let cancelled = false;
|
|
3572
4974
|
let upstream = null;
|
|
3573
|
-
const req =
|
|
4975
|
+
const req = http2.request({
|
|
3574
4976
|
hostname: "127.0.0.1",
|
|
3575
4977
|
port: localPort,
|
|
3576
4978
|
path: fullPath,
|
|
@@ -3718,6 +5120,17 @@ ${colors.cyan}ConnectBase Tunnel${colors.reset}`);
|
|
|
3718
5120
|
const readyFeatures = Array.isArray(msg.features) ? msg.features : [];
|
|
3719
5121
|
negotiatedWsOpcode = readyFeatures.includes("ws_opcode");
|
|
3720
5122
|
success(`\uD130\uB110 \uD65C\uC131\uD654!`);
|
|
5123
|
+
if (tunnelOpts?.onReady && tunnelUrl) {
|
|
5124
|
+
try {
|
|
5125
|
+
tunnelOpts.onReady({
|
|
5126
|
+
url: tunnelUrl,
|
|
5127
|
+
proxyToken,
|
|
5128
|
+
appId,
|
|
5129
|
+
secretKey: tunnelKey
|
|
5130
|
+
});
|
|
5131
|
+
} catch {
|
|
5132
|
+
}
|
|
5133
|
+
}
|
|
3721
5134
|
log(
|
|
3722
5135
|
`${colors.green}\u2192${colors.reset} URL: ${colors.cyan}${tunnelUrl}${colors.reset}`
|
|
3723
5136
|
);
|
|
@@ -3863,6 +5276,10 @@ ${colors.yellow}\uBA85\uB839\uC5B4:${colors.reset}
|
|
|
3863
5276
|
promote [releaseId] QA \uAC80\uC99D \uD6C4 production \uBC18\uC601 (\uBBF8\uC9C0\uC815: \uCD5C\uC2E0 \uBC30\uD3EC, \uACFC\uAC70 id: \uB864\uBC31)
|
|
3864
5277
|
releases \uBC30\uD3EC \uC774\uB825 \uC870\uD68C (release \uBC88\uD638/\uC0C1\uD0DC/production\xB7QA \uD3EC\uC778\uD130)
|
|
3865
5278
|
tunnel <port> \uB85C\uCEEC \uC11C\uBE44\uC2A4\uB97C \uC778\uD130\uB137\uC5D0 \uB178\uCD9C
|
|
5279
|
+
local \uC124\uCE58\uAC00 \uD544\uC694\uD55C \uC2A4\uD0AC\uC744 \uB0B4 PC \uC5D0\uC11C \uC4F0\uAC8C \uC5F0\uACB0 (\uB85C\uCEEC \uC2E4\uD589\uAE30: Blender, ZBrush, Python \u2026)
|
|
5280
|
+
--add <GitHub owner/repo[/\uD3F4\uB354][@ref] | \uC8FC\uC18C | \uD3F4\uB354> \uC2A4\uD0AC \uC124\uCE58 (\uC5EC\uB7EC \uBC88 \uAC00\uB2A5)
|
|
5281
|
+
--update \uC124\uCE58\uB41C \uC2A4\uD0AC \uB2E4\uC2DC \uBC1B\uAE30 --dir <\uD3F4\uB354> \uC791\uC5C5 \uD3F4\uB354 (\uAE30\uBCF8 ~/ConnectBaseLocal)
|
|
5282
|
+
\uC608: npx connectbase-client local --add yorusd1/yoruskills
|
|
3866
5283
|
|
|
3867
5284
|
${colors.yellow}\uCF54\uB4DC \uBD84\uC11D (MCP \uD1B5\uD574 \uC0AC\uC6A9):${colors.reset}
|
|
3868
5285
|
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:
|
|
@@ -4004,8 +5421,8 @@ async function enforceBaseUrlPolicy(baseUrl, opts) {
|
|
|
4004
5421
|
process.exit(1);
|
|
4005
5422
|
}
|
|
4006
5423
|
function isOutsideProject(dir, root) {
|
|
4007
|
-
const
|
|
4008
|
-
return
|
|
5424
|
+
const relative3 = path4.relative(path4.resolve(root), path4.resolve(root, dir));
|
|
5425
|
+
return relative3 === ".." || relative3.startsWith(`..${path4.sep}`) || path4.isAbsolute(relative3);
|
|
4009
5426
|
}
|
|
4010
5427
|
function parseArgs(args) {
|
|
4011
5428
|
const result = {
|
|
@@ -4037,6 +5454,14 @@ function parseArgs(args) {
|
|
|
4037
5454
|
result.options.token = args[++i];
|
|
4038
5455
|
} else if (arg === "-a" || arg === "--app") {
|
|
4039
5456
|
result.options.appId = args[++i];
|
|
5457
|
+
} else if (arg === "--dir") {
|
|
5458
|
+
result.options.dir = args[++i];
|
|
5459
|
+
} else if (arg === "--port") {
|
|
5460
|
+
result.options.port = args[++i];
|
|
5461
|
+
} else if (arg === "--add") {
|
|
5462
|
+
result.options.add = result.options.add ? `${result.options.add},${args[++i]}` : args[++i];
|
|
5463
|
+
} else if (arg === "--update") {
|
|
5464
|
+
result.options.update = "true";
|
|
4040
5465
|
} else if (arg === "--force") {
|
|
4041
5466
|
result.options.force = "true";
|
|
4042
5467
|
} else if (arg === "-y" || arg === "--yes") {
|
|
@@ -4151,8 +5576,8 @@ async function main() {
|
|
|
4151
5576
|
if (parsed.options.skipDocs !== "true") {
|
|
4152
5577
|
try {
|
|
4153
5578
|
const docsRoot = getGitRoot() || getProjectRoot();
|
|
4154
|
-
if (
|
|
4155
|
-
|
|
5579
|
+
if (fs4.existsSync(
|
|
5580
|
+
path4.join(docsRoot, ".claude", "docs", DOCS_MANIFEST_FILE)
|
|
4156
5581
|
)) {
|
|
4157
5582
|
const refreshed = await downloadDocs(docsRoot, {
|
|
4158
5583
|
quiet: true,
|
|
@@ -4183,6 +5608,25 @@ async function main() {
|
|
|
4183
5608
|
} else {
|
|
4184
5609
|
await listReleases(config);
|
|
4185
5610
|
}
|
|
5611
|
+
} else if (parsed.command === "local") {
|
|
5612
|
+
const port = parsed.options.port ? parseInt(parsed.options.port, 10) : 47800;
|
|
5613
|
+
if (Number.isNaN(port) || port < 1 || port > 65535) {
|
|
5614
|
+
error("\uC720\uD6A8\uD55C \uD3EC\uD2B8 \uBC88\uD638\uB97C \uC785\uB825\uD558\uC138\uC694 (1-65535)");
|
|
5615
|
+
process.exit(1);
|
|
5616
|
+
}
|
|
5617
|
+
await runLocal(
|
|
5618
|
+
config,
|
|
5619
|
+
{
|
|
5620
|
+
dir: parsed.options.dir,
|
|
5621
|
+
port,
|
|
5622
|
+
appId: parsed.options.appId,
|
|
5623
|
+
force: parsed.options.force === "true",
|
|
5624
|
+
add: parsed.options.add,
|
|
5625
|
+
update: parsed.options.update === "true"
|
|
5626
|
+
},
|
|
5627
|
+
(p, c, o) => startTunnel(p, c, o),
|
|
5628
|
+
{ info, success, warn }
|
|
5629
|
+
);
|
|
4186
5630
|
} else if (parsed.command === "tunnel") {
|
|
4187
5631
|
const portStr = parsed.args[0];
|
|
4188
5632
|
if (!portStr) {
|