connectbase-client 6.23.0 → 6.24.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 +11 -0
- package/dist/cli.js +712 -280
- package/dist/connect-base.umd.js +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -68,29 +68,381 @@ __export(cli_exports, {
|
|
|
68
68
|
});
|
|
69
69
|
module.exports = __toCommonJS(cli_exports);
|
|
70
70
|
var crypto = __toESM(require("crypto"));
|
|
71
|
-
var
|
|
71
|
+
var fs5 = __toESM(require("fs"));
|
|
72
72
|
var http2 = __toESM(require("http"));
|
|
73
73
|
var https = __toESM(require("https"));
|
|
74
74
|
var os4 = __toESM(require("os"));
|
|
75
|
-
var
|
|
75
|
+
var path5 = __toESM(require("path"));
|
|
76
76
|
var readline = __toESM(require("readline"));
|
|
77
77
|
|
|
78
78
|
// src/local-command.ts
|
|
79
79
|
var import_node_crypto = require("crypto");
|
|
80
|
-
var
|
|
80
|
+
var fs3 = __toESM(require("fs"));
|
|
81
81
|
var os2 = __toESM(require("os"));
|
|
82
|
-
var
|
|
82
|
+
var path3 = __toESM(require("path"));
|
|
83
83
|
|
|
84
|
-
// src/local-
|
|
84
|
+
// src/local-mcp-hub.ts
|
|
85
85
|
var import_node_child_process = require("child_process");
|
|
86
86
|
var fs = __toESM(require("fs"));
|
|
87
|
+
var path = __toESM(require("path"));
|
|
88
|
+
var LOCAL_CONFIG_FILE = "connectbase-local.json";
|
|
89
|
+
var CALL_TIMEOUT_MS = 1e5;
|
|
90
|
+
var START_TIMEOUT_MS = 6e4;
|
|
91
|
+
function loadLocalConfig(dir) {
|
|
92
|
+
const p = path.join(dir, LOCAL_CONFIG_FILE);
|
|
93
|
+
if (!fs.existsSync(p)) return { mcpServers: {} };
|
|
94
|
+
const raw = JSON.parse(fs.readFileSync(p, "utf-8"));
|
|
95
|
+
return { mcpServers: raw.mcpServers ?? {} };
|
|
96
|
+
}
|
|
97
|
+
function saveLocalConfig(dir, cfg) {
|
|
98
|
+
const p = path.join(dir, LOCAL_CONFIG_FILE);
|
|
99
|
+
let prev = {};
|
|
100
|
+
try {
|
|
101
|
+
prev = JSON.parse(fs.readFileSync(p, "utf-8"));
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
fs.writeFileSync(
|
|
105
|
+
p,
|
|
106
|
+
`${JSON.stringify({ ...prev, mcpServers: cfg.mcpServers }, null, 2)}
|
|
107
|
+
`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
function parseMcpFlag(flag) {
|
|
111
|
+
const eq = flag.indexOf("=");
|
|
112
|
+
if (eq <= 0)
|
|
113
|
+
throw new Error(
|
|
114
|
+
`--mcp \uB294 \uC774\uB984=\uBA85\uB839 \uAF34\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4 (\uC608: --mcp blender="uvx blender-mcp"): ${flag}`
|
|
115
|
+
);
|
|
116
|
+
const name = flag.slice(0, eq).trim();
|
|
117
|
+
const rest = flag.slice(eq + 1).trim();
|
|
118
|
+
if (!/^[\w.-]+$/.test(name))
|
|
119
|
+
throw new Error(`MCP \uC774\uB984\uC740 \uC601\uBB38, \uC22B\uC790, - _ . \uB9CC \uC501\uB2C8\uB2E4: ${name}`);
|
|
120
|
+
if (/^https?:\/\//.test(rest)) return { name, def: { url: rest } };
|
|
121
|
+
const parts = rest.match(/"[^"]*"|'[^']*'|\S+/g)?.map((p) => p.replace(/^["']|["']$/g, "")) ?? [];
|
|
122
|
+
if (!parts.length) throw new Error(`--mcp ${name} \uC758 \uBA85\uB839\uC774 \uBE44\uC5C8\uC2B5\uB2C8\uB2E4`);
|
|
123
|
+
return { name, def: { command: parts[0], args: parts.slice(1) } };
|
|
124
|
+
}
|
|
125
|
+
var StdioClient = class {
|
|
126
|
+
constructor(name, def, baseEnv, cwd) {
|
|
127
|
+
this.name = name;
|
|
128
|
+
this.def = def;
|
|
129
|
+
this.baseEnv = baseEnv;
|
|
130
|
+
this.cwd = cwd;
|
|
131
|
+
this.buf = "";
|
|
132
|
+
this.seq = 0;
|
|
133
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
134
|
+
this.stderrTail = "";
|
|
135
|
+
}
|
|
136
|
+
alive() {
|
|
137
|
+
return !!this.proc && this.proc.exitCode === null && !this.proc.killed;
|
|
138
|
+
}
|
|
139
|
+
async start() {
|
|
140
|
+
const proc = (0, import_node_child_process.spawn)(this.def.command, this.def.args ?? [], {
|
|
141
|
+
cwd: this.def.cwd ? path.resolve(this.cwd, this.def.cwd) : this.cwd,
|
|
142
|
+
env: { ...this.baseEnv, ...this.def.env ?? {} },
|
|
143
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
144
|
+
// Windows 의 npx, uvx 는 .cmd 라 셸로 띄워야 한다
|
|
145
|
+
shell: process.platform === "win32",
|
|
146
|
+
windowsHide: true
|
|
147
|
+
});
|
|
148
|
+
this.proc = proc;
|
|
149
|
+
proc.stdout?.on("data", (d) => {
|
|
150
|
+
this.buf += d.toString();
|
|
151
|
+
let i = this.buf.indexOf("\n");
|
|
152
|
+
while (i >= 0) {
|
|
153
|
+
const line = this.buf.slice(0, i).trim();
|
|
154
|
+
this.buf = this.buf.slice(i + 1);
|
|
155
|
+
if (line) this.onLine(line);
|
|
156
|
+
i = this.buf.indexOf("\n");
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
proc.stderr?.on("data", (d) => {
|
|
160
|
+
this.stderrTail = (this.stderrTail + d.toString()).slice(-2e3);
|
|
161
|
+
});
|
|
162
|
+
const fail = (why) => {
|
|
163
|
+
for (const [, p] of this.pending) {
|
|
164
|
+
clearTimeout(p.timer);
|
|
165
|
+
p.reject(
|
|
166
|
+
new Error(
|
|
167
|
+
`${this.name}: ${why}${this.stderrTail ? `
|
|
168
|
+
${this.stderrTail.slice(-600)}` : ""}`
|
|
169
|
+
)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
this.pending.clear();
|
|
173
|
+
};
|
|
174
|
+
proc.on("exit", (code) => fail(`MCP \uC11C\uBC84\uAC00 \uB05D\uB0AC\uC2B5\uB2C8\uB2E4 (\uCF54\uB4DC ${code})`));
|
|
175
|
+
proc.on("error", (e) => fail(`\uB744\uC6B0\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${e.message}`));
|
|
176
|
+
}
|
|
177
|
+
onLine(line) {
|
|
178
|
+
let msg;
|
|
179
|
+
try {
|
|
180
|
+
msg = JSON.parse(line);
|
|
181
|
+
} catch {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const id = msg.id;
|
|
185
|
+
if (id === void 0 || !this.pending.has(id)) return;
|
|
186
|
+
const p = this.pending.get(id);
|
|
187
|
+
this.pending.delete(id);
|
|
188
|
+
if (!p) return;
|
|
189
|
+
clearTimeout(p.timer);
|
|
190
|
+
if (msg.error)
|
|
191
|
+
p.reject(
|
|
192
|
+
new Error(`${this.name}: ${JSON.stringify(msg.error).slice(0, 500)}`)
|
|
193
|
+
);
|
|
194
|
+
else p.resolve(msg.result ?? {});
|
|
195
|
+
}
|
|
196
|
+
request(method, params, timeoutMs = CALL_TIMEOUT_MS) {
|
|
197
|
+
return new Promise((resolve5, reject) => {
|
|
198
|
+
if (!this.alive())
|
|
199
|
+
return reject(new Error(`${this.name}: MCP \uC11C\uBC84\uAC00 \uAEBC\uC838 \uC788\uC2B5\uB2C8\uB2E4`));
|
|
200
|
+
const id = ++this.seq;
|
|
201
|
+
const timer = setTimeout(() => {
|
|
202
|
+
this.pending.delete(id);
|
|
203
|
+
reject(
|
|
204
|
+
new Error(
|
|
205
|
+
`${this.name}: ${Math.round(timeoutMs / 1e3)}\uCD08 \uC548\uC5D0 \uB2F5\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4`
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
}, timeoutMs);
|
|
209
|
+
this.pending.set(id, { resolve: resolve5, reject, timer });
|
|
210
|
+
this.proc?.stdin?.write(
|
|
211
|
+
`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
212
|
+
`
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
notify(method) {
|
|
217
|
+
this.proc?.stdin?.write(`${JSON.stringify({ jsonrpc: "2.0", method })}
|
|
218
|
+
`);
|
|
219
|
+
}
|
|
220
|
+
close() {
|
|
221
|
+
try {
|
|
222
|
+
this.proc?.kill();
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var HttpClient = class {
|
|
228
|
+
constructor(name, def) {
|
|
229
|
+
this.name = name;
|
|
230
|
+
this.def = def;
|
|
231
|
+
this.seq = 0;
|
|
232
|
+
this.ok = false;
|
|
233
|
+
}
|
|
234
|
+
alive() {
|
|
235
|
+
return this.ok;
|
|
236
|
+
}
|
|
237
|
+
async start() {
|
|
238
|
+
this.ok = true;
|
|
239
|
+
}
|
|
240
|
+
async request(method, params, timeoutMs = CALL_TIMEOUT_MS) {
|
|
241
|
+
const headers = {
|
|
242
|
+
"Content-Type": "application/json",
|
|
243
|
+
Accept: "application/json, text/event-stream",
|
|
244
|
+
...this.def.headers ?? {}
|
|
245
|
+
};
|
|
246
|
+
if (this.session) headers["Mcp-Session-Id"] = this.session;
|
|
247
|
+
const ctrl = new AbortController();
|
|
248
|
+
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
249
|
+
try {
|
|
250
|
+
const id = ++this.seq;
|
|
251
|
+
const r = await fetch(this.def.url, {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers,
|
|
254
|
+
body: JSON.stringify({ jsonrpc: "2.0", id, method, params }),
|
|
255
|
+
signal: ctrl.signal
|
|
256
|
+
});
|
|
257
|
+
const sid = r.headers.get("mcp-session-id");
|
|
258
|
+
if (sid) this.session = sid;
|
|
259
|
+
const raw = await r.text();
|
|
260
|
+
if (!r.ok)
|
|
261
|
+
throw new Error(`${this.name}: HTTP ${r.status} ${raw.slice(0, 300)}`);
|
|
262
|
+
const body = raw.trimStart().startsWith("{") ? raw : raw.split("\n").filter((l) => l.startsWith("data:")).map((l) => l.slice(5).trim()).filter(
|
|
263
|
+
(l) => l.includes(`"id":${id}`) || l.includes(`"id": ${id}`)
|
|
264
|
+
).pop() ?? "{}";
|
|
265
|
+
const msg = JSON.parse(body);
|
|
266
|
+
if (msg.error)
|
|
267
|
+
throw new Error(
|
|
268
|
+
`${this.name}: ${JSON.stringify(msg.error).slice(0, 500)}`
|
|
269
|
+
);
|
|
270
|
+
return msg.result ?? {};
|
|
271
|
+
} catch (e) {
|
|
272
|
+
this.ok = !(e instanceof TypeError);
|
|
273
|
+
throw e instanceof Error && e.name === "AbortError" ? new Error(
|
|
274
|
+
`${this.name}: ${Math.round(timeoutMs / 1e3)}\uCD08 \uC548\uC5D0 \uB2F5\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4`
|
|
275
|
+
) : e;
|
|
276
|
+
} finally {
|
|
277
|
+
clearTimeout(t);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
notifyInitialized() {
|
|
281
|
+
const headers = {
|
|
282
|
+
"Content-Type": "application/json",
|
|
283
|
+
...this.def.headers ?? {}
|
|
284
|
+
};
|
|
285
|
+
if (this.session) headers["Mcp-Session-Id"] = this.session;
|
|
286
|
+
void fetch(this.def.url, {
|
|
287
|
+
method: "POST",
|
|
288
|
+
headers,
|
|
289
|
+
body: JSON.stringify({
|
|
290
|
+
jsonrpc: "2.0",
|
|
291
|
+
method: "notifications/initialized"
|
|
292
|
+
})
|
|
293
|
+
}).catch(() => {
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
close() {
|
|
297
|
+
this.ok = false;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
var LocalMcpHub = class {
|
|
301
|
+
constructor(dir, env, log2, reserved, onChange) {
|
|
302
|
+
this.dir = dir;
|
|
303
|
+
this.env = env;
|
|
304
|
+
this.log = log2;
|
|
305
|
+
this.reserved = reserved;
|
|
306
|
+
this.onChange = onChange;
|
|
307
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
308
|
+
this.exposed = [];
|
|
309
|
+
}
|
|
310
|
+
/** 정의 파일을 읽어 모두 (다시) 띄운다. */
|
|
311
|
+
async reload() {
|
|
312
|
+
for (const e of this.entries.values()) e.client?.close();
|
|
313
|
+
this.entries.clear();
|
|
314
|
+
let cfg;
|
|
315
|
+
try {
|
|
316
|
+
cfg = loadLocalConfig(this.dir);
|
|
317
|
+
} catch (e) {
|
|
318
|
+
this.log(
|
|
319
|
+
`${LOCAL_CONFIG_FILE} \uB97C \uC77D\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${e instanceof Error ? e.message : e}`
|
|
320
|
+
);
|
|
321
|
+
cfg = { mcpServers: {} };
|
|
322
|
+
}
|
|
323
|
+
await Promise.all(
|
|
324
|
+
Object.entries(cfg.mcpServers).filter(([, d]) => d.enabled !== false).map(([name, def]) => this.startOne(name, def))
|
|
325
|
+
);
|
|
326
|
+
this.rebuild();
|
|
327
|
+
this.onChange();
|
|
328
|
+
}
|
|
329
|
+
async startOne(name, def) {
|
|
330
|
+
const e = { name, def, tools: [] };
|
|
331
|
+
this.entries.set(name, e);
|
|
332
|
+
if (!def.command && !def.url) {
|
|
333
|
+
e.error = "command \uB098 url \uC774 \uC5C6\uC2B5\uB2C8\uB2E4";
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const client = def.url ? new HttpClient(name, def) : new StdioClient(name, def, this.env(), this.dir);
|
|
337
|
+
e.client = client;
|
|
338
|
+
try {
|
|
339
|
+
await client.start();
|
|
340
|
+
await client.request(
|
|
341
|
+
"initialize",
|
|
342
|
+
{
|
|
343
|
+
protocolVersion: "2025-06-18",
|
|
344
|
+
capabilities: {},
|
|
345
|
+
clientInfo: { name: "connectbase-local", version: "1.0.0" }
|
|
346
|
+
},
|
|
347
|
+
START_TIMEOUT_MS
|
|
348
|
+
);
|
|
349
|
+
if (client instanceof StdioClient)
|
|
350
|
+
client.notify("notifications/initialized");
|
|
351
|
+
else client.notifyInitialized();
|
|
352
|
+
const tools = [];
|
|
353
|
+
let cursor;
|
|
354
|
+
do {
|
|
355
|
+
const r = await client.request(
|
|
356
|
+
"tools/list",
|
|
357
|
+
cursor ? { cursor } : {},
|
|
358
|
+
START_TIMEOUT_MS
|
|
359
|
+
);
|
|
360
|
+
for (const t of r.tools ?? [])
|
|
361
|
+
tools.push({
|
|
362
|
+
name: String(t.name),
|
|
363
|
+
description: String(t.description ?? ""),
|
|
364
|
+
inputSchema: t.inputSchema ?? { type: "object" }
|
|
365
|
+
});
|
|
366
|
+
cursor = r.nextCursor;
|
|
367
|
+
} while (cursor);
|
|
368
|
+
e.tools = tools;
|
|
369
|
+
this.log(`MCP ${name}: \uB3C4\uAD6C ${tools.length}\uAC1C`);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
e.error = err instanceof Error ? err.message : String(err);
|
|
372
|
+
this.log(`MCP ${name} \uC5F0\uACB0 \uC2E4\uD328: ${e.error.split("\n")[0]}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
rebuild() {
|
|
376
|
+
const reserved = this.reserved();
|
|
377
|
+
const count = /* @__PURE__ */ new Map();
|
|
378
|
+
for (const e of this.entries.values())
|
|
379
|
+
for (const t of e.tools) count.set(t.name, (count.get(t.name) ?? 0) + 1);
|
|
380
|
+
this.exposed = [];
|
|
381
|
+
for (const e of this.entries.values())
|
|
382
|
+
for (const t of e.tools) {
|
|
383
|
+
const clash = reserved.has(t.name) || (count.get(t.name) ?? 0) > 1;
|
|
384
|
+
this.exposed.push({
|
|
385
|
+
server: e.name,
|
|
386
|
+
name: t.name,
|
|
387
|
+
exposed: clash ? `${e.name}__${t.name}` : t.name,
|
|
388
|
+
description: `[\uB0B4 PC MCP: ${e.name}] ${t.description}`,
|
|
389
|
+
inputSchema: t.inputSchema
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
tools() {
|
|
394
|
+
return this.exposed;
|
|
395
|
+
}
|
|
396
|
+
has(exposed) {
|
|
397
|
+
return this.exposed.some((t) => t.exposed === exposed);
|
|
398
|
+
}
|
|
399
|
+
/** 원래 이름으로 이 서버들 중 누가 그 도구를 갖고 있는가 (내장 BlenderMCP 대신 쓸지 정할 때). */
|
|
400
|
+
providesOriginal(name) {
|
|
401
|
+
return this.exposed.some((t) => t.name === name);
|
|
402
|
+
}
|
|
403
|
+
status() {
|
|
404
|
+
return [...this.entries.values()].map((e) => ({
|
|
405
|
+
name: e.name,
|
|
406
|
+
kind: e.def.url ? `http ${e.def.url}` : `${e.def.command} ${(e.def.args ?? []).join(" ")}`.trim(),
|
|
407
|
+
ok: !e.error && !!e.client?.alive(),
|
|
408
|
+
tools: e.tools.length,
|
|
409
|
+
...e.error ? { error: e.error.slice(0, 400) } : {}
|
|
410
|
+
}));
|
|
411
|
+
}
|
|
412
|
+
async call(exposed, args) {
|
|
413
|
+
const t = this.exposed.find((x) => x.exposed === exposed);
|
|
414
|
+
if (!t) throw new Error(`\uC5C6\uB294 \uB3C4\uAD6C: ${exposed}`);
|
|
415
|
+
const e = this.entries.get(t.server);
|
|
416
|
+
if (!e?.client) throw new Error(`${t.server}: \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4`);
|
|
417
|
+
if (!e.client.alive()) {
|
|
418
|
+
await this.startOne(e.name, e.def);
|
|
419
|
+
this.rebuild();
|
|
420
|
+
}
|
|
421
|
+
const c = this.entries.get(t.server)?.client;
|
|
422
|
+
if (!c) throw new Error(`${t.server}: \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4`);
|
|
423
|
+
return c.request("tools/call", { name: t.name, arguments: args });
|
|
424
|
+
}
|
|
425
|
+
close() {
|
|
426
|
+
for (const e of this.entries.values()) e.client?.close();
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
// src/local-runner.ts
|
|
431
|
+
var import_node_child_process2 = require("child_process");
|
|
432
|
+
var fs2 = __toESM(require("fs"));
|
|
87
433
|
var http = __toESM(require("http"));
|
|
88
434
|
var net = __toESM(require("net"));
|
|
89
435
|
var os = __toESM(require("os"));
|
|
90
|
-
var
|
|
436
|
+
var path2 = __toESM(require("path"));
|
|
91
437
|
var MAX_OUT = 24e3;
|
|
92
438
|
var MAX_READ = 2e5;
|
|
93
439
|
var MAX_IMAGE = 8 * 1024 * 1024;
|
|
440
|
+
var BLENDER_MCP_TOOLS = /* @__PURE__ */ new Set([
|
|
441
|
+
"execute_blender_code",
|
|
442
|
+
"get_scene_info",
|
|
443
|
+
"get_object_info",
|
|
444
|
+
"get_viewport_screenshot"
|
|
445
|
+
]);
|
|
94
446
|
var PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
95
447
|
var text = (t, isError = false) => ({
|
|
96
448
|
content: [{ type: "text", text: t }],
|
|
@@ -101,7 +453,7 @@ ${s.slice(-n)}` : s;
|
|
|
101
453
|
var str = (v, d = "") => typeof v === "string" ? v : d;
|
|
102
454
|
var num = (v, d) => typeof v === "number" && Number.isFinite(v) ? v : d;
|
|
103
455
|
function imageMime(p) {
|
|
104
|
-
const ext =
|
|
456
|
+
const ext = path2.extname(p).toLowerCase();
|
|
105
457
|
return {
|
|
106
458
|
".png": "image/png",
|
|
107
459
|
".jpg": "image/jpeg",
|
|
@@ -112,22 +464,22 @@ function imageMime(p) {
|
|
|
112
464
|
}
|
|
113
465
|
function findPrograms() {
|
|
114
466
|
const which = (names, extra = []) => {
|
|
115
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
467
|
+
const dirs = (process.env.PATH ?? "").split(path2.delimiter).filter(Boolean);
|
|
116
468
|
const exts = process.platform === "win32" ? ["", ".exe", ".cmd", ".bat"] : [""];
|
|
117
469
|
for (const n of names) {
|
|
118
|
-
if (
|
|
470
|
+
if (path2.isAbsolute(n) && fs2.existsSync(n)) return n;
|
|
119
471
|
for (const d of dirs)
|
|
120
472
|
for (const e of exts) {
|
|
121
|
-
const p =
|
|
122
|
-
if (
|
|
473
|
+
const p = path2.join(d, n + e);
|
|
474
|
+
if (fs2.existsSync(p)) return p;
|
|
123
475
|
}
|
|
124
476
|
}
|
|
125
|
-
for (const p of extra) if (
|
|
477
|
+
for (const p of extra) if (fs2.existsSync(p)) return p;
|
|
126
478
|
return null;
|
|
127
479
|
};
|
|
128
480
|
const globDirs = (root, pattern, sub) => {
|
|
129
481
|
try {
|
|
130
|
-
return
|
|
482
|
+
return fs2.readdirSync(root).filter((n) => pattern.test(n)).sort().reverse().map((n) => path2.join(root, n, sub));
|
|
131
483
|
} catch {
|
|
132
484
|
return [];
|
|
133
485
|
}
|
|
@@ -147,7 +499,7 @@ function findPrograms() {
|
|
|
147
499
|
"ZBrush.app/Contents/MacOS/ZBrush"
|
|
148
500
|
) : process.platform === "win32" ? globDirs("C:\\Program Files", /^Maxon ZBrush/, "ZBrush.exe") : [];
|
|
149
501
|
return {
|
|
150
|
-
blender: process.env.BLENDER_BIN &&
|
|
502
|
+
blender: process.env.BLENDER_BIN && fs2.existsSync(process.env.BLENDER_BIN) ? process.env.BLENDER_BIN : which(["blender"], blenderExtra),
|
|
151
503
|
zbrush: which([], zbrushExtra),
|
|
152
504
|
python: which(
|
|
153
505
|
process.platform === "win32" ? ["python", "py"] : ["python3", "python"]
|
|
@@ -155,13 +507,13 @@ function findPrograms() {
|
|
|
155
507
|
uv: which(
|
|
156
508
|
["uv"],
|
|
157
509
|
[
|
|
158
|
-
|
|
510
|
+
path2.join(
|
|
159
511
|
os.homedir(),
|
|
160
512
|
".local",
|
|
161
513
|
"bin",
|
|
162
514
|
process.platform === "win32" ? "uv.exe" : "uv"
|
|
163
515
|
),
|
|
164
|
-
|
|
516
|
+
path2.join(os.homedir(), ".cargo", "bin", "uv")
|
|
165
517
|
]
|
|
166
518
|
),
|
|
167
519
|
node: process.execPath,
|
|
@@ -176,23 +528,53 @@ var LocalRunner = class {
|
|
|
176
528
|
this.jobs = /* @__PURE__ */ new Map();
|
|
177
529
|
this.jobSeq = 0;
|
|
178
530
|
this.opts = opts;
|
|
179
|
-
this.dir =
|
|
180
|
-
this.skillsDir =
|
|
181
|
-
|
|
531
|
+
this.dir = path2.resolve(opts.dir);
|
|
532
|
+
this.skillsDir = path2.join(this.dir, "skills");
|
|
533
|
+
fs2.mkdirSync(this.skillsDir, { recursive: true });
|
|
182
534
|
this.programs = findPrograms();
|
|
183
535
|
this.tools = this.defineTools();
|
|
536
|
+
this.hub = new LocalMcpHub(
|
|
537
|
+
this.dir,
|
|
538
|
+
() => this.env(),
|
|
539
|
+
(l) => this.log(l),
|
|
540
|
+
() => new Set(
|
|
541
|
+
this.tools.map((t) => t.name).filter((n) => !BLENDER_MCP_TOOLS.has(n))
|
|
542
|
+
),
|
|
543
|
+
() => this.opts.onSkillsChanged?.()
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
/** connectbase-local.json 의 MCP 서버를 띄운다. */
|
|
547
|
+
startMcp() {
|
|
548
|
+
return this.hub.reload();
|
|
549
|
+
}
|
|
550
|
+
/** AI 에게 보이는 도구: 내장 + PC 의 MCP. PC 에 BlenderMCP 를 정의했으면 내장 대신 그것을 쓴다. */
|
|
551
|
+
visibleTools() {
|
|
552
|
+
const own = this.tools.filter(
|
|
553
|
+
(t) => !(BLENDER_MCP_TOOLS.has(t.name) && this.hub.providesOriginal(t.name))
|
|
554
|
+
).map(({ name, description, inputSchema, annotations }) => ({
|
|
555
|
+
name,
|
|
556
|
+
description: name === "read_skill" ? this.skillIndexText() : description,
|
|
557
|
+
inputSchema,
|
|
558
|
+
...annotations ? { annotations } : {}
|
|
559
|
+
}));
|
|
560
|
+
const fromHub = this.hub.tools().map((t) => ({
|
|
561
|
+
name: t.exposed,
|
|
562
|
+
description: t.description,
|
|
563
|
+
inputSchema: t.inputSchema
|
|
564
|
+
}));
|
|
565
|
+
return [...own, ...fromHub];
|
|
184
566
|
}
|
|
185
567
|
log(line) {
|
|
186
568
|
(this.opts.log ?? console.log)(line);
|
|
187
569
|
}
|
|
188
570
|
/** 작업 폴더 안의 경로로 푼다. 절대 경로도 작업 폴더 안이어야 한다. */
|
|
189
571
|
inDir(p) {
|
|
190
|
-
const abs =
|
|
572
|
+
const abs = path2.resolve(
|
|
191
573
|
this.dir,
|
|
192
574
|
p.replace(/^~(?=$|[\\/])/, os.homedir())
|
|
193
575
|
);
|
|
194
|
-
const rel =
|
|
195
|
-
if (rel.startsWith("..") ||
|
|
576
|
+
const rel = path2.relative(this.dir, abs);
|
|
577
|
+
if (rel.startsWith("..") || path2.isAbsolute(rel))
|
|
196
578
|
throw new Error(
|
|
197
579
|
`\uC791\uC5C5 \uD3F4\uB354(${this.dir}) \uBC16\uC758 \uACBD\uB85C\uB294 \uC4F8 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${p}`
|
|
198
580
|
);
|
|
@@ -228,6 +610,8 @@ var LocalRunner = class {
|
|
|
228
610
|
work_dir: this.dir,
|
|
229
611
|
skills_dir: this.skillsDir,
|
|
230
612
|
installed_skills: this.listSkills().map((k) => k.name),
|
|
613
|
+
mcp_config: path2.join(this.dir, LOCAL_CONFIG_FILE),
|
|
614
|
+
mcp_servers: this.hub.status(),
|
|
231
615
|
programs: this.programs,
|
|
232
616
|
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
617
|
notes: [
|
|
@@ -261,10 +645,10 @@ var LocalRunner = class {
|
|
|
261
645
|
${this.skillIndexText()}`,
|
|
262
646
|
true
|
|
263
647
|
);
|
|
264
|
-
const body =
|
|
648
|
+
const body = fs2.readFileSync(path2.join(k.dir, "SKILL.md"), "utf-8").split("{{SKILL_DIR}}").join(k.dir);
|
|
265
649
|
const head = `> \uC2A4\uD0AC \uD3F4\uB354(skill_dir): ${k.dir}
|
|
266
650
|
> \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.
|
|
651
|
+
> \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. \uC2A4\uD0AC\uC774 \uC5B4\uB5A4 MCP \uC758 \uB3C4\uAD6C\uB97C \uC4F0\uB77C\uACE0 \uD558\uBA74 \uC774 PC \uC5D0 \uC815\uC758\uB41C MCP \uB3C4\uAD6C([\uB0B4 PC MCP: \uC774\uB984])\uB97C \uADF8 \uC774\uB984\uC73C\uB85C \uBD80\uB974\uACE0, \uC5C6\uC73C\uBA74 local_info \uB85C \uD655\uC778\uD55C \uB4A4 \uC0AC\uC6A9\uC790\uC5D0\uAC8C \uADF8 MCP \uB97C connectbase-local.json \uC5D0 \uB123\uC790\uACE0 \uC548\uB0B4\uD55C\uB2E4(mcp_reload).
|
|
268
652
|
> \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
653
|
|
|
270
654
|
`;
|
|
@@ -300,15 +684,15 @@ ${this.skillIndexText()}`,
|
|
|
300
684
|
const depth = Math.min(num(a.depth, 1), 4);
|
|
301
685
|
const lines = [];
|
|
302
686
|
const walk = (d, lvl) => {
|
|
303
|
-
for (const n of
|
|
687
|
+
for (const n of fs2.readdirSync(d, { withFileTypes: true }).sort((x, y) => x.name.localeCompare(y.name))) {
|
|
304
688
|
if (n.name === "node_modules" || n.name === ".git" || n.name === "__pycache__")
|
|
305
689
|
continue;
|
|
306
|
-
const p =
|
|
307
|
-
const rel =
|
|
690
|
+
const p = path2.join(d, n.name);
|
|
691
|
+
const rel = path2.relative(this.dir, p);
|
|
308
692
|
if (n.isDirectory()) {
|
|
309
693
|
lines.push(`${rel}/`);
|
|
310
694
|
if (lvl < depth) walk(p, lvl + 1);
|
|
311
|
-
} else lines.push(`${rel} ${
|
|
695
|
+
} else lines.push(`${rel} ${fs2.statSync(p).size}B`);
|
|
312
696
|
if (lines.length > 2e3) return;
|
|
313
697
|
}
|
|
314
698
|
};
|
|
@@ -330,7 +714,7 @@ ${this.skillIndexText()}`,
|
|
|
330
714
|
annotations: ro,
|
|
331
715
|
run: async (a) => {
|
|
332
716
|
const p = this.inDir(str(a.path));
|
|
333
|
-
const all =
|
|
717
|
+
const all = fs2.readFileSync(p, "utf-8").split("{{SKILL_DIR}}").join(this.skillDirOf(p) ?? "{{SKILL_DIR}}");
|
|
334
718
|
const off = Math.max(0, num(a.offset, 0));
|
|
335
719
|
const part = all.slice(off, off + MAX_READ);
|
|
336
720
|
const more = off + MAX_READ < all.length ? `
|
|
@@ -349,8 +733,8 @@ ${this.skillIndexText()}`,
|
|
|
349
733
|
},
|
|
350
734
|
run: async (a) => {
|
|
351
735
|
const p = this.inDir(str(a.path));
|
|
352
|
-
|
|
353
|
-
|
|
736
|
+
fs2.mkdirSync(path2.dirname(p), { recursive: true });
|
|
737
|
+
fs2.writeFileSync(p, str(a.content));
|
|
354
738
|
return text(`\uC37C\uC2B5\uB2C8\uB2E4: ${p} (${Buffer.byteLength(str(a.content))}B)`);
|
|
355
739
|
}
|
|
356
740
|
},
|
|
@@ -393,6 +777,24 @@ ${this.skillIndexText()}`,
|
|
|
393
777
|
annotations: ro,
|
|
394
778
|
run: async (a) => this.jobStatus(str(a.id), num(a.wait, 0))
|
|
395
779
|
},
|
|
780
|
+
{
|
|
781
|
+
name: "mcp_reload",
|
|
782
|
+
description: "\uC774 PC \uC758 MCP \uC11C\uBC84 \uC815\uC758(\uC791\uC5C5 \uD3F4\uB354\uC758 connectbase-local.json, mcpServers \uD615\uC2DD \u2014 Claude Desktop/Claude Code \uC640 \uAC19\uB2E4)\uB97C \uB2E4\uC2DC \uC77D\uACE0 \uB744\uC6B4\uB2E4. \uC2A4\uD0AC\uC774 \uC5B4\uB5A4 MCP \uC758 \uB3C4\uAD6C\uB97C \uC4F0\uB77C\uACE0 \uD558\uB294\uB370 \uADF8 \uB3C4\uAD6C\uAC00 \uC5C6\uC73C\uBA74, \uC0AC\uC6A9\uC790 \uD5C8\uB77D\uC744 \uBC1B\uC544 \uADF8 MCP \uC124\uC815\uC744 \uC774 \uD30C\uC77C\uC5D0 write_file \uB85C \uB123\uACE0 \uC774\uAC78 \uBD80\uB978\uB2E4. \uACB0\uACFC\uB85C \uC11C\uBC84\uBCC4 \uC0C1\uD0DC\uC640 \uB3C4\uAD6C \uC218\uB97C \uB3CC\uB824\uC900\uB2E4.",
|
|
783
|
+
inputSchema: { type: "object", properties: {} },
|
|
784
|
+
run: async () => {
|
|
785
|
+
await this.hub.reload();
|
|
786
|
+
return text(
|
|
787
|
+
JSON.stringify(
|
|
788
|
+
{
|
|
789
|
+
config: path2.join(this.dir, LOCAL_CONFIG_FILE),
|
|
790
|
+
servers: this.hub.status()
|
|
791
|
+
},
|
|
792
|
+
null,
|
|
793
|
+
2
|
|
794
|
+
)
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
},
|
|
396
798
|
{
|
|
397
799
|
name: "job_stop",
|
|
398
800
|
description: "background \uC791\uC5C5\uC744 \uBA48\uCD98\uB2E4.",
|
|
@@ -425,7 +827,7 @@ ${this.skillIndexText()}`,
|
|
|
425
827
|
"\uADF8\uB9BC \uD30C\uC77C(png, jpg, webp, gif)\uB9CC \uBCFC \uC218 \uC788\uC2B5\uB2C8\uB2E4",
|
|
426
828
|
true
|
|
427
829
|
);
|
|
428
|
-
const buf =
|
|
830
|
+
const buf = fs2.readFileSync(p);
|
|
429
831
|
if (buf.length > MAX_IMAGE)
|
|
430
832
|
return text(
|
|
431
833
|
`\uADF8\uB9BC\uC774 \uB108\uBB34 \uD07D\uB2C8\uB2E4 (${buf.length}B). \uB354 \uC791\uAC8C \uB80C\uB354\uD574 \uC8FC\uC138\uC694`,
|
|
@@ -455,8 +857,8 @@ ${this.skillIndexText()}`,
|
|
|
455
857
|
const r = await fetch(url, { redirect: "follow" });
|
|
456
858
|
if (!r.ok) return text(`\uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: HTTP ${r.status}`, true);
|
|
457
859
|
const buf = Buffer.from(await r.arrayBuffer());
|
|
458
|
-
|
|
459
|
-
|
|
860
|
+
fs2.mkdirSync(path2.dirname(p), { recursive: true });
|
|
861
|
+
fs2.writeFileSync(p, buf);
|
|
460
862
|
return text(`\uBC1B\uC558\uC2B5\uB2C8\uB2E4: ${p} (${buf.length}B)`);
|
|
461
863
|
}
|
|
462
864
|
},
|
|
@@ -537,7 +939,7 @@ ${this.skillIndexText()}`,
|
|
|
537
939
|
},
|
|
538
940
|
annotations: ro,
|
|
539
941
|
run: async (a) => {
|
|
540
|
-
const tmp =
|
|
942
|
+
const tmp = path2.join(
|
|
541
943
|
os.tmpdir(),
|
|
542
944
|
`cb_blender_shot_${process.pid}_${Date.now()}.png`
|
|
543
945
|
);
|
|
@@ -547,31 +949,31 @@ ${this.skillIndexText()}`,
|
|
|
547
949
|
format: "png"
|
|
548
950
|
});
|
|
549
951
|
if (r.isError) return r;
|
|
550
|
-
if (!
|
|
952
|
+
if (!fs2.existsSync(tmp))
|
|
551
953
|
return text("Blender \uAC00 \uD654\uBA74\uC744 \uC800\uC7A5\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4", true);
|
|
552
|
-
const data =
|
|
553
|
-
|
|
954
|
+
const data = fs2.readFileSync(tmp).toString("base64");
|
|
955
|
+
fs2.rmSync(tmp, { force: true });
|
|
554
956
|
return { content: [{ type: "image", data, mimeType: "image/png" }] };
|
|
555
957
|
}
|
|
556
958
|
}
|
|
557
959
|
];
|
|
558
960
|
}
|
|
559
961
|
skillDirOf(p) {
|
|
560
|
-
const rel =
|
|
561
|
-
if (rel.startsWith("..") ||
|
|
562
|
-
return
|
|
962
|
+
const rel = path2.relative(this.skillsDir, p);
|
|
963
|
+
if (rel.startsWith("..") || path2.isAbsolute(rel)) return null;
|
|
964
|
+
return path2.join(this.skillsDir, rel.split(path2.sep)[0]);
|
|
563
965
|
}
|
|
564
966
|
/** 설치된 스킬 (skills/<이름>/SKILL.md 의 머리말 name, description). */
|
|
565
967
|
listSkills() {
|
|
566
|
-
if (!
|
|
968
|
+
if (!fs2.existsSync(this.skillsDir)) return [];
|
|
567
969
|
const out = [];
|
|
568
|
-
for (const d of
|
|
970
|
+
for (const d of fs2.readdirSync(this.skillsDir, { withFileTypes: true })) {
|
|
569
971
|
if (!d.isDirectory()) continue;
|
|
570
|
-
const dir =
|
|
571
|
-
const md =
|
|
572
|
-
if (!
|
|
972
|
+
const dir = path2.join(this.skillsDir, d.name);
|
|
973
|
+
const md = path2.join(dir, "SKILL.md");
|
|
974
|
+
if (!fs2.existsSync(md)) continue;
|
|
573
975
|
const head = /^---\r?\n([\s\S]*?)\r?\n---/.exec(
|
|
574
|
-
|
|
976
|
+
fs2.readFileSync(md, "utf-8")
|
|
575
977
|
);
|
|
576
978
|
const field = (k) => {
|
|
577
979
|
if (!head) return "";
|
|
@@ -619,8 +1021,8 @@ ${this.skillIndexText()}`,
|
|
|
619
1021
|
*/
|
|
620
1022
|
async installSkills(source, update2 = false) {
|
|
621
1023
|
const src0 = source.trim();
|
|
622
|
-
const localPath =
|
|
623
|
-
if (/^[.~/\\]|^[A-Za-z]:[\\/]/.test(src0) &&
|
|
1024
|
+
const localPath = path2.resolve(src0.replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
1025
|
+
if (/^[.~/\\]|^[A-Za-z]:[\\/]/.test(src0) && fs2.existsSync(localPath)) {
|
|
624
1026
|
return this.copySkills(localPath, `${localPath}`, update2);
|
|
625
1027
|
}
|
|
626
1028
|
let s = src0.replace(/^https:\/\/github\.com\//, "").replace(/\.git$/, "");
|
|
@@ -653,17 +1055,17 @@ ${this.skillIndexText()}`,
|
|
|
653
1055
|
throw new Error(
|
|
654
1056
|
`GitHub \uC5D0\uC11C \uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: HTTP ${r.status} (${owner}/${repo}@${ref})`
|
|
655
1057
|
);
|
|
656
|
-
const tmp =
|
|
1058
|
+
const tmp = fs2.mkdtempSync(path2.join(os.tmpdir(), "cb_skill_"));
|
|
657
1059
|
try {
|
|
658
|
-
|
|
659
|
-
|
|
1060
|
+
fs2.writeFileSync(
|
|
1061
|
+
path2.join(tmp, "src.tgz"),
|
|
660
1062
|
Buffer.from(await r.arrayBuffer())
|
|
661
1063
|
);
|
|
662
1064
|
const x = await this.exec(`"${tarBin}" -xzf src.tgz`, tmp, 120);
|
|
663
1065
|
if (x.code !== 0) throw new Error(`\uC555\uCD95\uC744 \uD480\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${x.out}`);
|
|
664
|
-
const top =
|
|
665
|
-
const root = top ?
|
|
666
|
-
if (!root || !
|
|
1066
|
+
const top = fs2.readdirSync(tmp).find((n) => n !== "src.tgz");
|
|
1067
|
+
const root = top ? path2.join(tmp, top, ...sub.split("/").filter(Boolean)) : "";
|
|
1068
|
+
if (!root || !fs2.existsSync(root))
|
|
667
1069
|
throw new Error(`\uADF8 \uACBD\uB85C\uAC00 \uC800\uC7A5\uC18C\uC5D0 \uC5C6\uC2B5\uB2C8\uB2E4: ${sub || "(\uB9E8 \uC704)"}`);
|
|
668
1070
|
return this.copySkills(
|
|
669
1071
|
root,
|
|
@@ -671,20 +1073,20 @@ ${this.skillIndexText()}`,
|
|
|
671
1073
|
update2
|
|
672
1074
|
);
|
|
673
1075
|
} finally {
|
|
674
|
-
|
|
1076
|
+
fs2.rmSync(tmp, { recursive: true, force: true });
|
|
675
1077
|
}
|
|
676
1078
|
}
|
|
677
1079
|
copySkills(root, origin, update2) {
|
|
678
1080
|
const found = [];
|
|
679
1081
|
const walk = (d, depth) => {
|
|
680
|
-
if (
|
|
1082
|
+
if (fs2.existsSync(path2.join(d, "SKILL.md"))) {
|
|
681
1083
|
found.push(d);
|
|
682
1084
|
return;
|
|
683
1085
|
}
|
|
684
1086
|
if (depth >= 4) return;
|
|
685
|
-
for (const n of
|
|
1087
|
+
for (const n of fs2.readdirSync(d, { withFileTypes: true }))
|
|
686
1088
|
if (n.isDirectory() && !n.name.startsWith(".") && n.name !== "node_modules")
|
|
687
|
-
walk(
|
|
1089
|
+
walk(path2.join(d, n.name), depth + 1);
|
|
688
1090
|
};
|
|
689
1091
|
walk(root, 0);
|
|
690
1092
|
if (!found.length)
|
|
@@ -692,17 +1094,17 @@ ${this.skillIndexText()}`,
|
|
|
692
1094
|
const installed = [];
|
|
693
1095
|
const skipped = [];
|
|
694
1096
|
for (const dir of found) {
|
|
695
|
-
const name =
|
|
696
|
-
const dest =
|
|
697
|
-
if (
|
|
1097
|
+
const name = path2.basename(dir);
|
|
1098
|
+
const dest = path2.join(this.skillsDir, name);
|
|
1099
|
+
if (fs2.existsSync(path2.join(dest, "SKILL.md")) && !update2) {
|
|
698
1100
|
skipped.push(name);
|
|
699
1101
|
continue;
|
|
700
1102
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
const rel =
|
|
704
|
-
|
|
705
|
-
|
|
1103
|
+
fs2.rmSync(dest, { recursive: true, force: true });
|
|
1104
|
+
fs2.cpSync(dir, dest, { recursive: true });
|
|
1105
|
+
const rel = path2.relative(root, dir).split(path2.sep).join("/");
|
|
1106
|
+
fs2.writeFileSync(
|
|
1107
|
+
path2.join(dest, ".source"),
|
|
706
1108
|
`${origin}${rel ? ` (${rel})` : ""}
|
|
707
1109
|
`
|
|
708
1110
|
);
|
|
@@ -717,15 +1119,15 @@ ${this.skillIndexText()}`,
|
|
|
717
1119
|
async updateSkills() {
|
|
718
1120
|
const sources = /* @__PURE__ */ new Set();
|
|
719
1121
|
for (const k of this.listSkills()) {
|
|
720
|
-
const f =
|
|
721
|
-
if (!
|
|
722
|
-
const line =
|
|
1122
|
+
const f = path2.join(k.dir, ".source");
|
|
1123
|
+
if (!fs2.existsSync(f)) continue;
|
|
1124
|
+
const line = fs2.readFileSync(f, "utf-8").trim();
|
|
723
1125
|
const origin = line.replace(/ \(.*\)$/, "");
|
|
724
1126
|
const rel = /\((.*)\)$/.exec(line)?.[1];
|
|
725
1127
|
const [base, ref] = origin.split("@");
|
|
726
1128
|
if (ref && /^[0-9a-f]{40}$/.test(ref)) continue;
|
|
727
1129
|
sources.add(
|
|
728
|
-
rel && !
|
|
1130
|
+
rel && !path2.isAbsolute(base) ? `${base}/${rel}@${ref ?? "HEAD"}` : origin
|
|
729
1131
|
);
|
|
730
1132
|
}
|
|
731
1133
|
const done = [];
|
|
@@ -737,7 +1139,7 @@ ${this.skillIndexText()}`,
|
|
|
737
1139
|
try {
|
|
738
1140
|
const r = await this.installSkills(source, update2);
|
|
739
1141
|
const names = [...r.installed, ...r.skipped];
|
|
740
|
-
const dirs = names.map((n) =>
|
|
1142
|
+
const dirs = names.map((n) => path2.join(this.skillsDir, n));
|
|
741
1143
|
return text(
|
|
742
1144
|
`${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
1145
|
|
|
@@ -750,10 +1152,10 @@ ${this.skillIndexText()}`,
|
|
|
750
1152
|
describeSkill(dest, head) {
|
|
751
1153
|
const files = [];
|
|
752
1154
|
const walk = (d) => {
|
|
753
|
-
for (const n of
|
|
754
|
-
const p =
|
|
1155
|
+
for (const n of fs2.readdirSync(d, { withFileTypes: true })) {
|
|
1156
|
+
const p = path2.join(d, n.name);
|
|
755
1157
|
if (n.isDirectory()) walk(p);
|
|
756
|
-
else files.push(
|
|
1158
|
+
else files.push(path2.relative(dest, p));
|
|
757
1159
|
}
|
|
758
1160
|
};
|
|
759
1161
|
walk(dest);
|
|
@@ -761,7 +1163,7 @@ ${this.skillIndexText()}`,
|
|
|
761
1163
|
"requirements.txt",
|
|
762
1164
|
"tools/package.json",
|
|
763
1165
|
"package.json"
|
|
764
|
-
].filter((f) =>
|
|
1166
|
+
].filter((f) => fs2.existsSync(path2.join(dest, f)));
|
|
765
1167
|
return JSON.stringify(
|
|
766
1168
|
{
|
|
767
1169
|
result: head,
|
|
@@ -775,8 +1177,8 @@ ${this.skillIndexText()}`,
|
|
|
775
1177
|
);
|
|
776
1178
|
}
|
|
777
1179
|
exec(command, cwd, timeoutSec) {
|
|
778
|
-
return new Promise((
|
|
779
|
-
const child = (0,
|
|
1180
|
+
return new Promise((resolve5) => {
|
|
1181
|
+
const child = (0, import_node_child_process2.spawn)(command, {
|
|
780
1182
|
cwd,
|
|
781
1183
|
shell: true,
|
|
782
1184
|
env: this.env(),
|
|
@@ -796,24 +1198,24 @@ ${this.skillIndexText()}`,
|
|
|
796
1198
|
}, timeoutSec * 1e3);
|
|
797
1199
|
child.on("close", (code) => {
|
|
798
1200
|
clearTimeout(t);
|
|
799
|
-
|
|
1201
|
+
resolve5({ code, out, timedOut });
|
|
800
1202
|
});
|
|
801
1203
|
child.on("error", (e) => {
|
|
802
1204
|
clearTimeout(t);
|
|
803
|
-
|
|
1205
|
+
resolve5({ code: -1, out: out + String(e), timedOut });
|
|
804
1206
|
});
|
|
805
1207
|
});
|
|
806
1208
|
}
|
|
807
1209
|
async run(command, cwd, timeout, background) {
|
|
808
1210
|
if (!command.trim()) return text("command \uAC00 \uBE44\uC5C8\uC2B5\uB2C8\uB2E4", true);
|
|
809
1211
|
const dir = this.inDir(cwd || ".");
|
|
810
|
-
|
|
1212
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
811
1213
|
this.log(
|
|
812
|
-
`\uC2E4\uD589${background ? " (\uBC31\uADF8\uB77C\uC6B4\uB4DC)" : ""}: ${command} [${
|
|
1214
|
+
`\uC2E4\uD589${background ? " (\uBC31\uADF8\uB77C\uC6B4\uB4DC)" : ""}: ${command} [${path2.relative(this.dir, dir) || "."}]`
|
|
813
1215
|
);
|
|
814
1216
|
if (background) {
|
|
815
1217
|
const id = `job${++this.jobSeq}`;
|
|
816
|
-
const child = (0,
|
|
1218
|
+
const child = (0, import_node_child_process2.spawn)(command, {
|
|
817
1219
|
cwd: dir,
|
|
818
1220
|
shell: true,
|
|
819
1221
|
env: this.env(),
|
|
@@ -883,7 +1285,7 @@ ${tail(j.out)}`,
|
|
|
883
1285
|
return this.opts.blenderMcpPort ?? (Number(process.env.BLENDER_MCP_PORT) || 9876);
|
|
884
1286
|
}
|
|
885
1287
|
blenderSend(type, params, timeoutMs = 18e4) {
|
|
886
|
-
return new Promise((
|
|
1288
|
+
return new Promise((resolve5, reject) => {
|
|
887
1289
|
const sock = net.createConnection({
|
|
888
1290
|
host: "127.0.0.1",
|
|
889
1291
|
port: this.blenderPort
|
|
@@ -904,7 +1306,7 @@ ${tail(j.out)}`,
|
|
|
904
1306
|
const obj = JSON.parse(buf.toString("utf-8"));
|
|
905
1307
|
clearTimeout(timer);
|
|
906
1308
|
sock.end();
|
|
907
|
-
|
|
1309
|
+
resolve5(obj);
|
|
908
1310
|
} catch {
|
|
909
1311
|
}
|
|
910
1312
|
});
|
|
@@ -939,12 +1341,12 @@ Blender \uC5D0 BlenderMCP \uC560\uB4DC\uC628(github.com/ahujasid/blender-mcp \uC
|
|
|
939
1341
|
}
|
|
940
1342
|
async uploadToStorage(p, folder) {
|
|
941
1343
|
const abs = this.inDir(p);
|
|
942
|
-
if (!
|
|
1344
|
+
if (!fs2.existsSync(abs)) return text(`\uD30C\uC77C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${p}`, true);
|
|
943
1345
|
try {
|
|
944
1346
|
const url = await uploadFile(this.opts, abs, folder);
|
|
945
|
-
this.log(`\uC62C\uB9BC: ${
|
|
1347
|
+
this.log(`\uC62C\uB9BC: ${path2.basename(abs)} \u2192 ${url}`);
|
|
946
1348
|
return text(
|
|
947
|
-
JSON.stringify({ uploaded:
|
|
1349
|
+
JSON.stringify({ uploaded: path2.basename(abs), url }, null, 2)
|
|
948
1350
|
);
|
|
949
1351
|
} catch (e) {
|
|
950
1352
|
return text(e instanceof Error ? e.message : String(e), true);
|
|
@@ -959,7 +1361,7 @@ Blender \uC5D0 BlenderMCP \uC560\uB4DC\uC628(github.com/ahujasid/blender-mcp \uC
|
|
|
959
1361
|
parts.push({
|
|
960
1362
|
type: "image_url",
|
|
961
1363
|
image_url: {
|
|
962
|
-
url: `data:${mime};base64,${
|
|
1364
|
+
url: `data:${mime};base64,${fs2.readFileSync(abs).toString("base64")}`
|
|
963
1365
|
}
|
|
964
1366
|
});
|
|
965
1367
|
}
|
|
@@ -998,8 +1400,8 @@ Blender \uC5D0 BlenderMCP \uC560\uB4DC\uC628(github.com/ahujasid/blender-mcp \uC
|
|
|
998
1400
|
);
|
|
999
1401
|
const src = str(images[0].url);
|
|
1000
1402
|
const buf = src.startsWith("data:") ? Buffer.from(src.split(",", 2)[1], "base64") : Buffer.from(await (await fetch(src)).arrayBuffer());
|
|
1001
|
-
|
|
1002
|
-
|
|
1403
|
+
fs2.mkdirSync(path2.dirname(out), { recursive: true });
|
|
1404
|
+
fs2.writeFileSync(out, buf);
|
|
1003
1405
|
return text(
|
|
1004
1406
|
`\uC800\uC7A5\uD588\uC2B5\uB2C8\uB2E4: ${out} (${buf.length}B). view_image \uB85C \uD655\uC778\uD558\uC138\uC694.`
|
|
1005
1407
|
);
|
|
@@ -1025,24 +1427,33 @@ Blender \uC5D0 BlenderMCP \uC560\uB4DC\uC628(github.com/ahujasid/blender-mcp \uC
|
|
|
1025
1427
|
protocolVersion: PROTOCOL_VERSIONS.includes(want) ? want : PROTOCOL_VERSIONS[0],
|
|
1026
1428
|
capabilities: { tools: { listChanged: false } },
|
|
1027
1429
|
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,
|
|
1430
|
+
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, \uC774 PC \uC5D0 \uC815\uC758\uB41C MCP \uC11C\uBC84\uC758 \uB3C4\uAD6C(\uC124\uBA85\uC774 [\uB0B4 PC MCP: \uC774\uB984] \uC73C\uB85C \uC2DC\uC791), \uADF8\uB9BC \uBCF4\uAE30\uB97C \uC5EC\uAE30\uC11C \uD55C\uB2E4. \uD504\uB85C\uADF8\uB7A8\uACFC MCP \uC0C1\uD0DC \uD655\uC778\uC740 local_info."
|
|
1029
1431
|
});
|
|
1030
1432
|
}
|
|
1031
1433
|
case "ping":
|
|
1032
1434
|
return ok({});
|
|
1033
1435
|
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
|
-
});
|
|
1436
|
+
return ok({ tools: this.visibleTools() });
|
|
1044
1437
|
case "tools/call": {
|
|
1045
1438
|
const p = msg.params ?? {};
|
|
1439
|
+
if (this.hub.has(str(p.name))) {
|
|
1440
|
+
this.log(`MCP \uB3C4\uAD6C: ${str(p.name)}`);
|
|
1441
|
+
try {
|
|
1442
|
+
const r = await this.hub.call(
|
|
1443
|
+
str(p.name),
|
|
1444
|
+
p.arguments ?? {}
|
|
1445
|
+
);
|
|
1446
|
+
const content = (r.content ?? []).map(
|
|
1447
|
+
(c) => c.type === "text" || c.type === "image" ? c : { type: "text", text: JSON.stringify(c).slice(0, 2e4) }
|
|
1448
|
+
);
|
|
1449
|
+
return ok({
|
|
1450
|
+
content: content.length ? content : [{ type: "text", text: "(\uBE48 \uACB0\uACFC)" }],
|
|
1451
|
+
...r.isError ? { isError: true } : {}
|
|
1452
|
+
});
|
|
1453
|
+
} catch (e) {
|
|
1454
|
+
return ok(text(e instanceof Error ? e.message : String(e), true));
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1046
1457
|
const tool = this.tools.find((t) => t.name === p.name);
|
|
1047
1458
|
if (!tool) return fail(-32602, `\uC5C6\uB294 \uB3C4\uAD6C: ${str(p.name)}`);
|
|
1048
1459
|
try {
|
|
@@ -1093,9 +1504,9 @@ Blender \uC5D0 BlenderMCP \uC560\uB4DC\uC628(github.com/ahujasid/blender-mcp \uC
|
|
|
1093
1504
|
"Mcp-Session-Id": "local"
|
|
1094
1505
|
}).end(out);
|
|
1095
1506
|
});
|
|
1096
|
-
return new Promise((
|
|
1507
|
+
return new Promise((resolve5, reject) => {
|
|
1097
1508
|
server.once("error", reject);
|
|
1098
|
-
server.listen(this.opts.port, "127.0.0.1", () =>
|
|
1509
|
+
server.listen(this.opts.port, "127.0.0.1", () => resolve5(server));
|
|
1099
1510
|
});
|
|
1100
1511
|
}
|
|
1101
1512
|
};
|
|
@@ -1103,7 +1514,7 @@ function killTree(pid) {
|
|
|
1103
1514
|
if (!pid) return;
|
|
1104
1515
|
try {
|
|
1105
1516
|
if (process.platform === "win32")
|
|
1106
|
-
(0,
|
|
1517
|
+
(0, import_node_child_process2.spawn)("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
1107
1518
|
windowsHide: true
|
|
1108
1519
|
});
|
|
1109
1520
|
else process.kill(pid, "SIGTERM");
|
|
@@ -1119,18 +1530,18 @@ function setUploader(fn) {
|
|
|
1119
1530
|
|
|
1120
1531
|
// src/local-command.ts
|
|
1121
1532
|
var LOCAL_SERVER_NAME = "\uB0B4 \uCEF4\uD4E8\uD130 (\uB85C\uCEEC \uC2E4\uD589\uAE30)";
|
|
1122
|
-
var STATE_PATH =
|
|
1533
|
+
var STATE_PATH = path3.join(os2.homedir(), ".connectbase", "local-runner.json");
|
|
1123
1534
|
function loadState() {
|
|
1124
1535
|
try {
|
|
1125
|
-
const s = JSON.parse(
|
|
1536
|
+
const s = JSON.parse(fs3.readFileSync(STATE_PATH, "utf-8"));
|
|
1126
1537
|
return { apps: s.apps ?? {}, token: s.token };
|
|
1127
1538
|
} catch {
|
|
1128
1539
|
return { apps: {} };
|
|
1129
1540
|
}
|
|
1130
1541
|
}
|
|
1131
1542
|
function saveState(s) {
|
|
1132
|
-
|
|
1133
|
-
|
|
1543
|
+
fs3.mkdirSync(path3.dirname(STATE_PATH), { recursive: true });
|
|
1544
|
+
fs3.writeFileSync(STATE_PATH, `${JSON.stringify(s, null, 2)}
|
|
1134
1545
|
`, {
|
|
1135
1546
|
mode: 384
|
|
1136
1547
|
});
|
|
@@ -1299,8 +1710,8 @@ function makeUploader(mcpUrl, getSt, save) {
|
|
|
1299
1710
|
}
|
|
1300
1711
|
save();
|
|
1301
1712
|
}
|
|
1302
|
-
const buf =
|
|
1303
|
-
const name =
|
|
1713
|
+
const buf = fs3.readFileSync(abs);
|
|
1714
|
+
const name = path3.basename(abs);
|
|
1304
1715
|
const mime = {
|
|
1305
1716
|
".glb": "model/gltf-binary",
|
|
1306
1717
|
".gltf": "model/gltf+json",
|
|
@@ -1312,7 +1723,7 @@ function makeUploader(mcpUrl, getSt, save) {
|
|
|
1312
1723
|
".fbx": "application/octet-stream",
|
|
1313
1724
|
".obj": "text/plain",
|
|
1314
1725
|
".json": "application/json"
|
|
1315
|
-
}[
|
|
1726
|
+
}[path3.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
1316
1727
|
const base = `${o.baseUrl}/v1/public/storages/files/${st.storageId}`;
|
|
1317
1728
|
const presign = () => fetch(
|
|
1318
1729
|
`${base}/presigned-url/path/${encodeURIComponent(folder)}/${encodeURIComponent(name)}`,
|
|
@@ -1360,8 +1771,8 @@ function makeUploader(mcpUrl, getSt, save) {
|
|
|
1360
1771
|
};
|
|
1361
1772
|
}
|
|
1362
1773
|
async function runLocal(config, opts, startTunnel2, out) {
|
|
1363
|
-
const dir =
|
|
1364
|
-
opts.dir ||
|
|
1774
|
+
const dir = path3.resolve(
|
|
1775
|
+
opts.dir || path3.join(os2.homedir(), "ConnectBaseLocal")
|
|
1365
1776
|
);
|
|
1366
1777
|
const port = opts.port || 47800;
|
|
1367
1778
|
let syncTools = () => {
|
|
@@ -1393,6 +1804,22 @@ async function runLocal(config, opts, startTunnel2, out) {
|
|
|
1393
1804
|
out.warn(`\uC2A4\uD0AC \uAC31\uC2E0 \uC2E4\uD328: ${e instanceof Error ? e.message : e}`);
|
|
1394
1805
|
}
|
|
1395
1806
|
}
|
|
1807
|
+
for (const flag of (opts.mcp ?? "").split("\0").filter(Boolean)) {
|
|
1808
|
+
try {
|
|
1809
|
+
const { name, def } = parseMcpFlag(flag);
|
|
1810
|
+
const cfg = loadLocalConfig(dir);
|
|
1811
|
+
cfg.mcpServers[name] = def;
|
|
1812
|
+
saveLocalConfig(dir, cfg);
|
|
1813
|
+
out.success(`MCP ${name} \uB97C ${LOCAL_CONFIG_FILE} \uC5D0 \uB123\uC5C8\uC2B5\uB2C8\uB2E4`);
|
|
1814
|
+
} catch (e) {
|
|
1815
|
+
out.warn(e instanceof Error ? e.message : String(e));
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
await runner.startMcp();
|
|
1819
|
+
const mcp = runner.hub.status();
|
|
1820
|
+
out.info(
|
|
1821
|
+
mcp.length ? `\uC774 PC \uC758 MCP ${mcp.length}\uAC1C: ${mcp.map((m) => `${m.name}(${m.ok ? `\uB3C4\uAD6C ${m.tools}\uAC1C` : "\uC5F0\uACB0 \uC2E4\uD328"})`).join(", ")}` : `\uC774 PC \uC758 MCP \uC5C6\uC74C (\uC2A4\uD0AC\uC774 MCP \uB97C \uC4F0\uBA74: --mcp \uC774\uB984="\uBA85\uB839" \uB610\uB294 ${path3.join(dir, LOCAL_CONFIG_FILE)} \uC5D0 mcpServers)`
|
|
1822
|
+
);
|
|
1396
1823
|
await runner.listen();
|
|
1397
1824
|
const skills = runner.listSkills().map((k) => k.name);
|
|
1398
1825
|
out.info(
|
|
@@ -1478,13 +1905,13 @@ async function runLocal(config, opts, startTunnel2, out) {
|
|
|
1478
1905
|
}
|
|
1479
1906
|
|
|
1480
1907
|
// src/tunnel-utils.ts
|
|
1481
|
-
var
|
|
1908
|
+
var fs4 = __toESM(require("fs"));
|
|
1482
1909
|
var os3 = __toESM(require("os"));
|
|
1483
|
-
var
|
|
1910
|
+
var path4 = __toESM(require("path"));
|
|
1484
1911
|
function getTunnelLockDir() {
|
|
1485
1912
|
const platform2 = os3.platform();
|
|
1486
1913
|
if (platform2 === "darwin") {
|
|
1487
|
-
return
|
|
1914
|
+
return path4.join(
|
|
1488
1915
|
os3.homedir(),
|
|
1489
1916
|
"Library",
|
|
1490
1917
|
"Application Support",
|
|
@@ -1492,14 +1919,14 @@ function getTunnelLockDir() {
|
|
|
1492
1919
|
"tunnel-locks"
|
|
1493
1920
|
);
|
|
1494
1921
|
} else if (platform2 === "win32") {
|
|
1495
|
-
return
|
|
1496
|
-
process.env.LOCALAPPDATA ||
|
|
1922
|
+
return path4.join(
|
|
1923
|
+
process.env.LOCALAPPDATA || path4.join(os3.homedir(), "AppData", "Local"),
|
|
1497
1924
|
"connectbase",
|
|
1498
1925
|
"tunnel-locks"
|
|
1499
1926
|
);
|
|
1500
1927
|
}
|
|
1501
|
-
const stateHome = process.env.XDG_STATE_HOME ||
|
|
1502
|
-
return
|
|
1928
|
+
const stateHome = process.env.XDG_STATE_HOME || path4.join(os3.homedir(), ".local", "state");
|
|
1929
|
+
return path4.join(stateHome, "connectbase", "tunnel-locks");
|
|
1503
1930
|
}
|
|
1504
1931
|
function isProcessAlive(pid) {
|
|
1505
1932
|
try {
|
|
@@ -1511,8 +1938,8 @@ function isProcessAlive(pid) {
|
|
|
1511
1938
|
}
|
|
1512
1939
|
function acquireTunnelLock(appID, port, force, version) {
|
|
1513
1940
|
const lockDir = getTunnelLockDir();
|
|
1514
|
-
|
|
1515
|
-
const lockPath =
|
|
1941
|
+
fs4.mkdirSync(lockDir, { recursive: true });
|
|
1942
|
+
const lockPath = path4.join(lockDir, `${appID}-${port}.lock`);
|
|
1516
1943
|
const lockData = {
|
|
1517
1944
|
pid: process.pid,
|
|
1518
1945
|
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1523,9 +1950,9 @@ function acquireTunnelLock(appID, port, force, version) {
|
|
|
1523
1950
|
};
|
|
1524
1951
|
if (!force) {
|
|
1525
1952
|
try {
|
|
1526
|
-
const fd =
|
|
1527
|
-
|
|
1528
|
-
|
|
1953
|
+
const fd = fs4.openSync(lockPath, "wx");
|
|
1954
|
+
fs4.writeSync(fd, JSON.stringify(lockData, null, 2));
|
|
1955
|
+
fs4.closeSync(fd);
|
|
1529
1956
|
return lockPath;
|
|
1530
1957
|
} catch (e) {
|
|
1531
1958
|
if (e.code !== "EEXIST") {
|
|
@@ -1534,7 +1961,7 @@ function acquireTunnelLock(appID, port, force, version) {
|
|
|
1534
1961
|
}
|
|
1535
1962
|
try {
|
|
1536
1963
|
const existing = JSON.parse(
|
|
1537
|
-
|
|
1964
|
+
fs4.readFileSync(lockPath, "utf-8")
|
|
1538
1965
|
);
|
|
1539
1966
|
if (isProcessAlive(existing.pid)) {
|
|
1540
1967
|
return `LOCKED:${existing.pid}:${existing.startedAt}:${existing.host}`;
|
|
@@ -1542,12 +1969,12 @@ function acquireTunnelLock(appID, port, force, version) {
|
|
|
1542
1969
|
} catch {
|
|
1543
1970
|
}
|
|
1544
1971
|
}
|
|
1545
|
-
|
|
1972
|
+
fs4.writeFileSync(lockPath, JSON.stringify(lockData, null, 2));
|
|
1546
1973
|
return lockPath;
|
|
1547
1974
|
}
|
|
1548
1975
|
function releaseTunnelLock(lockPath) {
|
|
1549
1976
|
try {
|
|
1550
|
-
|
|
1977
|
+
fs4.unlinkSync(lockPath);
|
|
1551
1978
|
} catch {
|
|
1552
1979
|
}
|
|
1553
1980
|
}
|
|
@@ -1578,7 +2005,7 @@ function handleTunnelError(msg, appId, localPort) {
|
|
|
1578
2005
|
}
|
|
1579
2006
|
|
|
1580
2007
|
// src/cli.ts
|
|
1581
|
-
var VERSION = "6.
|
|
2008
|
+
var VERSION = "6.24.0" ? "6.24.0" : getPackageVersion();
|
|
1582
2009
|
var DEFAULT_BASE_URL = "https://api.connectbase.world";
|
|
1583
2010
|
var colors = {
|
|
1584
2011
|
reset: "\x1B[0m",
|
|
@@ -1717,23 +2144,23 @@ var MIME_BY_EXT = {
|
|
|
1717
2144
|
".safetensors": "application/octet-stream"
|
|
1718
2145
|
};
|
|
1719
2146
|
function guessMimeType(filePath) {
|
|
1720
|
-
if (ALLOWED_EXTENSIONLESS_FILES.has(
|
|
2147
|
+
if (ALLOWED_EXTENSIONLESS_FILES.has(path5.basename(filePath))) {
|
|
1721
2148
|
return "text/plain; charset=utf-8";
|
|
1722
2149
|
}
|
|
1723
|
-
return MIME_BY_EXT[
|
|
2150
|
+
return MIME_BY_EXT[path5.extname(filePath).toLowerCase()] || "application/octet-stream";
|
|
1724
2151
|
}
|
|
1725
2152
|
function isAllowedDeployExt(filePath) {
|
|
1726
|
-
if (ALLOWED_EXTENSIONLESS_FILES.has(
|
|
2153
|
+
if (ALLOWED_EXTENSIONLESS_FILES.has(path5.basename(filePath))) {
|
|
1727
2154
|
return true;
|
|
1728
2155
|
}
|
|
1729
|
-
return ALLOWED_EXTENSIONS.has(
|
|
2156
|
+
return ALLOWED_EXTENSIONS.has(path5.extname(filePath).toLowerCase());
|
|
1730
2157
|
}
|
|
1731
2158
|
function isBinaryDeployExt(filePath) {
|
|
1732
|
-
return BINARY_EXTENSIONS.has(
|
|
2159
|
+
return BINARY_EXTENSIONS.has(path5.extname(filePath).toLowerCase());
|
|
1733
2160
|
}
|
|
1734
2161
|
function isExtensionlessDataFile(filePath) {
|
|
1735
|
-
const base =
|
|
1736
|
-
return
|
|
2162
|
+
const base = path5.basename(filePath);
|
|
2163
|
+
return path5.extname(base) === "" && !ALLOWED_EXTENSIONLESS_FILES.has(base);
|
|
1737
2164
|
}
|
|
1738
2165
|
var WEB_FILE_MAX_STORED_BYTES = 6 * 1024 * 1024 - 64 * 1024;
|
|
1739
2166
|
var DEPLOY_REQUEST_BUDGET_BYTES = 96 * 1024 * 1024;
|
|
@@ -1814,10 +2241,10 @@ function loadConfig() {
|
|
|
1814
2241
|
baseUrl: envBaseUrl || DEFAULT_BASE_URL,
|
|
1815
2242
|
baseUrlFromRepo: false
|
|
1816
2243
|
};
|
|
1817
|
-
const rcPath =
|
|
1818
|
-
if (
|
|
2244
|
+
const rcPath = path5.join(process.cwd(), ".connectbaserc");
|
|
2245
|
+
if (fs5.existsSync(rcPath)) {
|
|
1819
2246
|
try {
|
|
1820
|
-
const rcContent = JSON.parse(
|
|
2247
|
+
const rcContent = JSON.parse(fs5.readFileSync(rcPath, "utf-8"));
|
|
1821
2248
|
if (rcContent.publicKey) config.publicKey = rcContent.publicKey;
|
|
1822
2249
|
if (rcContent.secretKey) config.secretKey = rcContent.secretKey;
|
|
1823
2250
|
if (rcContent.storageId) config.storageId = rcContent.storageId;
|
|
@@ -1842,16 +2269,16 @@ function collectDeployFiles(dir, options = {}) {
|
|
|
1842
2269
|
}
|
|
1843
2270
|
function collectFiles(dir, baseDir, skipped, options) {
|
|
1844
2271
|
const files = [];
|
|
1845
|
-
const entries =
|
|
2272
|
+
const entries = fs5.readdirSync(dir, { withFileTypes: true });
|
|
1846
2273
|
for (const entry of entries) {
|
|
1847
|
-
const fullPath =
|
|
1848
|
-
const relativePath =
|
|
2274
|
+
const fullPath = path5.join(dir, entry.name);
|
|
2275
|
+
const relativePath = path5.relative(baseDir, fullPath);
|
|
1849
2276
|
if (entry.isDirectory()) {
|
|
1850
2277
|
if (!entry.name.startsWith(".")) {
|
|
1851
2278
|
files.push(...collectFiles(fullPath, baseDir, skipped, options));
|
|
1852
2279
|
}
|
|
1853
2280
|
} else if (entry.isFile()) {
|
|
1854
|
-
const ext =
|
|
2281
|
+
const ext = path5.extname(entry.name).toLowerCase();
|
|
1855
2282
|
if (entry.name.startsWith(".")) {
|
|
1856
2283
|
continue;
|
|
1857
2284
|
}
|
|
@@ -1863,9 +2290,9 @@ function collectFiles(dir, baseDir, skipped, options) {
|
|
|
1863
2290
|
const isBinary = extensionlessData || BINARY_EXTENSIONS.has(ext);
|
|
1864
2291
|
let content;
|
|
1865
2292
|
if (isBinary) {
|
|
1866
|
-
content =
|
|
2293
|
+
content = fs5.readFileSync(fullPath).toString("base64");
|
|
1867
2294
|
} else {
|
|
1868
|
-
content =
|
|
2295
|
+
content = fs5.readFileSync(fullPath, "utf-8");
|
|
1869
2296
|
}
|
|
1870
2297
|
const normalized = normalizeRelativePath(relativePath);
|
|
1871
2298
|
files.push({
|
|
@@ -1891,7 +2318,7 @@ function formatSkippedFilesReport(skipped, limit = SKIPPED_FILES_LIST_LIMIT) {
|
|
|
1891
2318
|
}
|
|
1892
2319
|
const byExt = /* @__PURE__ */ new Map();
|
|
1893
2320
|
for (const p of skipped) {
|
|
1894
|
-
const ext =
|
|
2321
|
+
const ext = path5.extname(p).toLowerCase() || "(\uD655\uC7A5\uC790 \uC5C6\uC74C)";
|
|
1895
2322
|
byExt.set(ext, (byExt.get(ext) ?? 0) + 1);
|
|
1896
2323
|
}
|
|
1897
2324
|
const extSummary = [...byExt.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([ext, n]) => `${ext} ${n}\uAC1C`).join(", ");
|
|
@@ -1971,7 +2398,7 @@ async function requestDeployPresign(baseStorageUrl, headers, files, timeoutMs) {
|
|
|
1971
2398
|
return parsed?.urls ?? [];
|
|
1972
2399
|
}
|
|
1973
2400
|
function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
|
|
1974
|
-
return new Promise((
|
|
2401
|
+
return new Promise((resolve5, reject) => {
|
|
1975
2402
|
let parsed;
|
|
1976
2403
|
try {
|
|
1977
2404
|
parsed = new URL(uploadUrl);
|
|
@@ -2002,7 +2429,7 @@ function putToPresignedUrl(uploadUrl, body, contentType, timeoutMs) {
|
|
|
2002
2429
|
res.on("end", () => {
|
|
2003
2430
|
const status = res.statusCode || 0;
|
|
2004
2431
|
if (status >= 200 && status < 300) {
|
|
2005
|
-
|
|
2432
|
+
resolve5();
|
|
2006
2433
|
return;
|
|
2007
2434
|
}
|
|
2008
2435
|
reject(
|
|
@@ -2154,7 +2581,7 @@ function apiErrorMessage(data, status) {
|
|
|
2154
2581
|
return suggestion ? `${message} (${suggestion})` : message;
|
|
2155
2582
|
}
|
|
2156
2583
|
async function makeRequest(url, method, headers, body, reqOpts = {}) {
|
|
2157
|
-
return new Promise((
|
|
2584
|
+
return new Promise((resolve5, reject) => {
|
|
2158
2585
|
const parsedUrl = new URL(url);
|
|
2159
2586
|
const isHttps = parsedUrl.protocol === "https:";
|
|
2160
2587
|
const lib = isHttps ? https : http2;
|
|
@@ -2180,12 +2607,12 @@ async function makeRequest(url, method, headers, body, reqOpts = {}) {
|
|
|
2180
2607
|
res.on("end", () => {
|
|
2181
2608
|
const data = Buffer.concat(chunks).toString("utf8");
|
|
2182
2609
|
try {
|
|
2183
|
-
|
|
2610
|
+
resolve5({
|
|
2184
2611
|
status: res.statusCode || 0,
|
|
2185
2612
|
data: data ? JSON.parse(data) : null
|
|
2186
2613
|
});
|
|
2187
2614
|
} catch {
|
|
2188
|
-
|
|
2615
|
+
resolve5({ status: res.statusCode || 0, data });
|
|
2189
2616
|
}
|
|
2190
2617
|
});
|
|
2191
2618
|
});
|
|
@@ -2218,27 +2645,27 @@ function computeDeployTimeout(totalBytes, override) {
|
|
|
2218
2645
|
return Math.max(DEPLOY_TIMEOUT_MIN_MS, DEPLOY_TIMEOUT_BASE_MS + sizeBased);
|
|
2219
2646
|
}
|
|
2220
2647
|
async function deploy(directory, config, isDev = false, deployOpts = {}) {
|
|
2221
|
-
const dir =
|
|
2222
|
-
if (!
|
|
2648
|
+
const dir = path5.resolve(directory);
|
|
2649
|
+
if (!fs5.existsSync(dir)) {
|
|
2223
2650
|
error(`\uB514\uB809\uD1A0\uB9AC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${dir}`);
|
|
2224
2651
|
process.exit(1);
|
|
2225
2652
|
}
|
|
2226
|
-
const pkgPath =
|
|
2227
|
-
if (
|
|
2653
|
+
const pkgPath = path5.join(process.cwd(), "package.json");
|
|
2654
|
+
if (fs5.existsSync(pkgPath)) {
|
|
2228
2655
|
try {
|
|
2229
|
-
const pkg = JSON.parse(
|
|
2656
|
+
const pkg = JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
2230
2657
|
const pm = packageManagerCommands(detectPackageManager(process.cwd()));
|
|
2231
2658
|
const inside = runningInsidePackageScript(pkg.scripts ?? {});
|
|
2232
2659
|
for (const line of buildFirstHint(pkg, pm, inside)) warn(line);
|
|
2233
2660
|
} catch {
|
|
2234
2661
|
}
|
|
2235
2662
|
}
|
|
2236
|
-
if (!
|
|
2663
|
+
if (!fs5.statSync(dir).isDirectory()) {
|
|
2237
2664
|
error(`${dir}\uB294 \uB514\uB809\uD1A0\uB9AC\uAC00 \uC544\uB2D9\uB2C8\uB2E4`);
|
|
2238
2665
|
process.exit(1);
|
|
2239
2666
|
}
|
|
2240
|
-
const indexPath =
|
|
2241
|
-
if (!
|
|
2667
|
+
const indexPath = path5.join(dir, "index.html");
|
|
2668
|
+
if (!fs5.existsSync(indexPath)) {
|
|
2242
2669
|
error("index.html \uD30C\uC77C\uC774 \uD544\uC694\uD569\uB2C8\uB2E4");
|
|
2243
2670
|
process.exit(1);
|
|
2244
2671
|
}
|
|
@@ -2597,15 +3024,15 @@ function prompt(question) {
|
|
|
2597
3024
|
input: process.stdin,
|
|
2598
3025
|
output: process.stdout
|
|
2599
3026
|
});
|
|
2600
|
-
return new Promise((
|
|
3027
|
+
return new Promise((resolve5) => {
|
|
2601
3028
|
rl.question(question, (answer) => {
|
|
2602
3029
|
rl.close();
|
|
2603
|
-
|
|
3030
|
+
resolve5(answer.trim());
|
|
2604
3031
|
});
|
|
2605
3032
|
});
|
|
2606
3033
|
}
|
|
2607
3034
|
function promptSecret(question) {
|
|
2608
|
-
return new Promise((
|
|
3035
|
+
return new Promise((resolve5) => {
|
|
2609
3036
|
process.stdout.write(question);
|
|
2610
3037
|
const input = [];
|
|
2611
3038
|
if (!process.stdin.isTTY) {
|
|
@@ -2615,7 +3042,7 @@ function promptSecret(question) {
|
|
|
2615
3042
|
});
|
|
2616
3043
|
rl.question("", (answer) => {
|
|
2617
3044
|
rl.close();
|
|
2618
|
-
|
|
3045
|
+
resolve5(answer.trim());
|
|
2619
3046
|
});
|
|
2620
3047
|
return;
|
|
2621
3048
|
}
|
|
@@ -2630,7 +3057,7 @@ function promptSecret(question) {
|
|
|
2630
3057
|
process.stdin.pause();
|
|
2631
3058
|
process.stdin.removeListener("data", onData);
|
|
2632
3059
|
process.stdout.write("\n");
|
|
2633
|
-
|
|
3060
|
+
resolve5(input.join("").trim());
|
|
2634
3061
|
return;
|
|
2635
3062
|
} else if (code === 3) {
|
|
2636
3063
|
process.stdin.setRawMode(false);
|
|
@@ -2681,8 +3108,8 @@ function browserOpenCommand(url, platform2 = process.platform) {
|
|
|
2681
3108
|
function openBrowser(url) {
|
|
2682
3109
|
const opener = browserOpenCommand(url);
|
|
2683
3110
|
if (!opener) return;
|
|
2684
|
-
const { spawn:
|
|
2685
|
-
const child =
|
|
3111
|
+
const { spawn: spawn3 } = require("child_process");
|
|
3112
|
+
const child = spawn3(opener.command, opener.args, {
|
|
2686
3113
|
stdio: "ignore",
|
|
2687
3114
|
detached: true
|
|
2688
3115
|
});
|
|
@@ -2749,7 +3176,7 @@ ${colors.cyan}\uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uB85C\uADF8\uC778\uD558\uC13
|
|
|
2749
3176
|
process.stdout.write(
|
|
2750
3177
|
`\r${colors.blue}${frame}${colors.reset} \uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uC2B9\uC778 \uB300\uAE30 \uC911...`
|
|
2751
3178
|
);
|
|
2752
|
-
await new Promise((
|
|
3179
|
+
await new Promise((resolve5) => setTimeout(resolve5, pollInterval));
|
|
2753
3180
|
try {
|
|
2754
3181
|
const pollRes = await makeRequest(
|
|
2755
3182
|
`${baseUrl}/v1/public/cli-auth/poll/${session_id}`,
|
|
@@ -2844,11 +3271,11 @@ ${colors.dim}\uC778\uC99D \uBC29\uC2DD\uC744 \uC120\uD0DD\uD558\uC138\uC694:${co
|
|
|
2844
3271
|
return entered;
|
|
2845
3272
|
}
|
|
2846
3273
|
function saveSecretKeyToRc(secretKey, dir = process.cwd()) {
|
|
2847
|
-
const rcPath =
|
|
3274
|
+
const rcPath = path5.join(dir, ".connectbaserc");
|
|
2848
3275
|
let rcData = {};
|
|
2849
|
-
if (
|
|
3276
|
+
if (fs5.existsSync(rcPath)) {
|
|
2850
3277
|
try {
|
|
2851
|
-
rcData = JSON.parse(
|
|
3278
|
+
rcData = JSON.parse(fs5.readFileSync(rcPath, "utf-8"));
|
|
2852
3279
|
} catch {
|
|
2853
3280
|
}
|
|
2854
3281
|
}
|
|
@@ -2886,11 +3313,11 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
|
|
|
2886
3313
|
);
|
|
2887
3314
|
process.exit(1);
|
|
2888
3315
|
}
|
|
2889
|
-
const rcPath =
|
|
3316
|
+
const rcPath = path5.join(cwd, ".connectbaserc");
|
|
2890
3317
|
let existingRc = {};
|
|
2891
|
-
if (
|
|
3318
|
+
if (fs5.existsSync(rcPath)) {
|
|
2892
3319
|
try {
|
|
2893
|
-
existingRc = JSON.parse(
|
|
3320
|
+
existingRc = JSON.parse(fs5.readFileSync(rcPath, "utf-8"));
|
|
2894
3321
|
} catch {
|
|
2895
3322
|
}
|
|
2896
3323
|
if (nonInteractive) {
|
|
@@ -2933,7 +3360,7 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
|
|
|
2933
3360
|
}
|
|
2934
3361
|
let appId = "";
|
|
2935
3362
|
let publicKey = "";
|
|
2936
|
-
const projectName =
|
|
3363
|
+
const projectName = path5.basename(cwd);
|
|
2937
3364
|
const reuseKeyIfSameApp = (selectedAppId) => {
|
|
2938
3365
|
if (existingRc.appId === selectedAppId && existingRc.publicKey?.startsWith("cb_pk_")) {
|
|
2939
3366
|
publicKey = existingRc.publicKey;
|
|
@@ -3208,17 +3635,17 @@ ${colors.dim}Claude Code\uC5D0\uC11C MCP\uAC00 \uC790\uB3D9 \uC5F0\uACB0\uB429\u
|
|
|
3208
3635
|
`);
|
|
3209
3636
|
}
|
|
3210
3637
|
function detectBuildDir() {
|
|
3211
|
-
if (
|
|
3212
|
-
if (
|
|
3213
|
-
if (
|
|
3214
|
-
const nextConfig = ["next.config.js", "next.config.mjs", "next.config.ts"].map((f) =>
|
|
3215
|
-
if (nextConfig ||
|
|
3638
|
+
if (fs5.existsSync(path5.join(process.cwd(), "dist"))) return "./dist";
|
|
3639
|
+
if (fs5.existsSync(path5.join(process.cwd(), "build"))) return "./build";
|
|
3640
|
+
if (fs5.existsSync(path5.join(process.cwd(), "out"))) return "./out";
|
|
3641
|
+
const nextConfig = ["next.config.js", "next.config.mjs", "next.config.ts"].map((f) => path5.join(process.cwd(), f)).find((f) => fs5.existsSync(f));
|
|
3642
|
+
if (nextConfig || fs5.existsSync(path5.join(process.cwd(), ".next"))) {
|
|
3216
3643
|
if (nextConfig) {
|
|
3217
3644
|
try {
|
|
3218
|
-
const src =
|
|
3645
|
+
const src = fs5.readFileSync(nextConfig, "utf-8");
|
|
3219
3646
|
if (!/output\s*:\s*['"]export['"]/.test(src)) {
|
|
3220
3647
|
warn(
|
|
3221
|
-
`Next.js \uAC10\uC9C0: \uC815\uC801 \uBC30\uD3EC\uD558\uB824\uBA74 ${
|
|
3648
|
+
`Next.js \uAC10\uC9C0: \uC815\uC801 \uBC30\uD3EC\uD558\uB824\uBA74 ${path5.basename(nextConfig)}\uC5D0 output: 'export' \uC124\uC815\uC774 \uD544\uC694\uD569\uB2C8\uB2E4`
|
|
3222
3649
|
);
|
|
3223
3650
|
}
|
|
3224
3651
|
} catch {
|
|
@@ -3226,25 +3653,25 @@ function detectBuildDir() {
|
|
|
3226
3653
|
}
|
|
3227
3654
|
return "./out";
|
|
3228
3655
|
}
|
|
3229
|
-
if (
|
|
3656
|
+
if (fs5.existsSync(path5.join(process.cwd(), "vite.config.ts")) || fs5.existsSync(path5.join(process.cwd(), "vite.config.js")))
|
|
3230
3657
|
return "./dist";
|
|
3231
3658
|
return "./dist";
|
|
3232
3659
|
}
|
|
3233
3660
|
function writeSecretFile(filePath, content) {
|
|
3234
3661
|
try {
|
|
3235
|
-
if (
|
|
3662
|
+
if (fs5.existsSync(filePath)) fs5.chmodSync(filePath, 384);
|
|
3236
3663
|
} catch {
|
|
3237
3664
|
}
|
|
3238
|
-
|
|
3665
|
+
fs5.writeFileSync(filePath, content, { mode: 384 });
|
|
3239
3666
|
}
|
|
3240
3667
|
function addToGitignore(entry, basePath) {
|
|
3241
3668
|
const dir = basePath || process.cwd();
|
|
3242
|
-
const gitignorePath =
|
|
3243
|
-
if (
|
|
3244
|
-
const content =
|
|
3669
|
+
const gitignorePath = path5.join(dir, ".gitignore");
|
|
3670
|
+
if (fs5.existsSync(gitignorePath)) {
|
|
3671
|
+
const content = fs5.readFileSync(gitignorePath, "utf-8");
|
|
3245
3672
|
const lines = content.split(/\r?\n/).map((l) => l.trim());
|
|
3246
3673
|
if (!lines.includes(entry)) {
|
|
3247
|
-
|
|
3674
|
+
fs5.appendFileSync(gitignorePath, `
|
|
3248
3675
|
# Connect Base
|
|
3249
3676
|
${entry}
|
|
3250
3677
|
`);
|
|
@@ -3253,7 +3680,7 @@ ${entry}
|
|
|
3253
3680
|
info(`.gitignore\uC5D0 \uC774\uBBF8 ${entry}\uAC00 \uD3EC\uD568\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4`);
|
|
3254
3681
|
}
|
|
3255
3682
|
} else {
|
|
3256
|
-
|
|
3683
|
+
fs5.writeFileSync(gitignorePath, `# Connect Base
|
|
3257
3684
|
${entry}
|
|
3258
3685
|
`);
|
|
3259
3686
|
success(".gitignore \uC0DD\uC131 \uC644\uB8CC");
|
|
@@ -3284,8 +3711,8 @@ function ancestorCommandLines(maxDepth = 8) {
|
|
|
3284
3711
|
let ppid = 0;
|
|
3285
3712
|
try {
|
|
3286
3713
|
if (process.platform === "linux") {
|
|
3287
|
-
cmd =
|
|
3288
|
-
const stat =
|
|
3714
|
+
cmd = fs5.readFileSync(`/proc/${pid}/cmdline`).toString("utf8").replace(/\0/g, " ").trim();
|
|
3715
|
+
const stat = fs5.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
3289
3716
|
ppid = parseInt(
|
|
3290
3717
|
stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1],
|
|
3291
3718
|
10
|
|
@@ -3329,7 +3756,7 @@ function buildFirstHint(pkg, pm, insideScript) {
|
|
|
3329
3756
|
function detectPackageManager(startDir = process.cwd()) {
|
|
3330
3757
|
try {
|
|
3331
3758
|
const pkg = JSON.parse(
|
|
3332
|
-
|
|
3759
|
+
fs5.readFileSync(path5.join(startDir, "package.json"), "utf-8")
|
|
3333
3760
|
);
|
|
3334
3761
|
const declared = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : "";
|
|
3335
3762
|
if (declared === "npm" || declared === "pnpm" || declared === "yarn" || declared === "bun") {
|
|
@@ -3345,13 +3772,13 @@ function detectPackageManager(startDir = process.cwd()) {
|
|
|
3345
3772
|
["package-lock.json", "npm"],
|
|
3346
3773
|
["npm-shrinkwrap.json", "npm"]
|
|
3347
3774
|
];
|
|
3348
|
-
let dir =
|
|
3775
|
+
let dir = path5.resolve(startDir);
|
|
3349
3776
|
for (; ; ) {
|
|
3350
3777
|
for (const [file, pm] of lockfiles) {
|
|
3351
|
-
if (
|
|
3778
|
+
if (fs5.existsSync(path5.join(dir, file))) return pm;
|
|
3352
3779
|
}
|
|
3353
|
-
if (
|
|
3354
|
-
const parent =
|
|
3780
|
+
if (fs5.existsSync(path5.join(dir, ".git"))) break;
|
|
3781
|
+
const parent = path5.dirname(dir);
|
|
3355
3782
|
if (parent === dir) break;
|
|
3356
3783
|
dir = parent;
|
|
3357
3784
|
}
|
|
@@ -3365,13 +3792,13 @@ function packageManagerCommands(pm) {
|
|
|
3365
3792
|
};
|
|
3366
3793
|
}
|
|
3367
3794
|
function addDeployScript(deployDir, pm) {
|
|
3368
|
-
const pkgPath =
|
|
3369
|
-
if (!
|
|
3795
|
+
const pkgPath = path5.join(process.cwd(), "package.json");
|
|
3796
|
+
if (!fs5.existsSync(pkgPath)) {
|
|
3370
3797
|
warn("package.json\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC5B4 deploy \uC2A4\uD06C\uB9BD\uD2B8\uB97C \uCD94\uAC00\uD558\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4");
|
|
3371
3798
|
return { needsInstall: false };
|
|
3372
3799
|
}
|
|
3373
3800
|
try {
|
|
3374
|
-
const pkg = JSON.parse(
|
|
3801
|
+
const pkg = JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
3375
3802
|
if (!pkg.scripts) pkg.scripts = {};
|
|
3376
3803
|
const declared = (name) => Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
3377
3804
|
let needsInstall = false;
|
|
@@ -3389,7 +3816,7 @@ function addDeployScript(deployDir, pm) {
|
|
|
3389
3816
|
pkg.scripts.deploy = pkg.scripts.build ? `${pm.run("build")} && ${deployCmd}` : deployCmd;
|
|
3390
3817
|
success("package.json\uC5D0 deploy \uC2A4\uD06C\uB9BD\uD2B8 \uCD94\uAC00 \uC644\uB8CC");
|
|
3391
3818
|
}
|
|
3392
|
-
|
|
3819
|
+
fs5.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
3393
3820
|
`);
|
|
3394
3821
|
if (needsInstall) {
|
|
3395
3822
|
success(
|
|
@@ -3420,32 +3847,32 @@ function detectMonorepo(gitRoot) {
|
|
|
3420
3847
|
root: gitRoot,
|
|
3421
3848
|
isSubPackage: false
|
|
3422
3849
|
};
|
|
3423
|
-
if (
|
|
3850
|
+
if (fs5.existsSync(path5.join(gitRoot, "pnpm-workspace.yaml"))) {
|
|
3424
3851
|
result.type = "pnpm";
|
|
3425
|
-
} else if (
|
|
3852
|
+
} else if (fs5.existsSync(path5.join(gitRoot, "turbo.json"))) {
|
|
3426
3853
|
result.type = "turborepo";
|
|
3427
|
-
} else if (
|
|
3854
|
+
} else if (fs5.existsSync(path5.join(gitRoot, "nx.json"))) {
|
|
3428
3855
|
result.type = "nx";
|
|
3429
|
-
} else if (
|
|
3856
|
+
} else if (fs5.existsSync(path5.join(gitRoot, "lerna.json"))) {
|
|
3430
3857
|
result.type = "lerna";
|
|
3431
3858
|
} else {
|
|
3432
|
-
const rootPkgPath =
|
|
3433
|
-
if (
|
|
3859
|
+
const rootPkgPath = path5.join(gitRoot, "package.json");
|
|
3860
|
+
if (fs5.existsSync(rootPkgPath)) {
|
|
3434
3861
|
try {
|
|
3435
|
-
const pkg = JSON.parse(
|
|
3862
|
+
const pkg = JSON.parse(fs5.readFileSync(rootPkgPath, "utf-8"));
|
|
3436
3863
|
if (pkg.workspaces) {
|
|
3437
|
-
result.type =
|
|
3864
|
+
result.type = fs5.existsSync(path5.join(gitRoot, "yarn.lock")) ? "yarn" : "npm";
|
|
3438
3865
|
}
|
|
3439
3866
|
} catch {
|
|
3440
3867
|
}
|
|
3441
3868
|
}
|
|
3442
3869
|
}
|
|
3443
3870
|
if (result.type !== "none" && cwd !== gitRoot) {
|
|
3444
|
-
const cwdPkgPath =
|
|
3445
|
-
if (
|
|
3871
|
+
const cwdPkgPath = path5.join(cwd, "package.json");
|
|
3872
|
+
if (fs5.existsSync(cwdPkgPath)) {
|
|
3446
3873
|
result.isSubPackage = true;
|
|
3447
3874
|
try {
|
|
3448
|
-
const pkg = JSON.parse(
|
|
3875
|
+
const pkg = JSON.parse(fs5.readFileSync(cwdPkgPath, "utf-8"));
|
|
3449
3876
|
result.subPackageName = pkg.name;
|
|
3450
3877
|
} catch {
|
|
3451
3878
|
}
|
|
@@ -3457,7 +3884,7 @@ var DOCS_MANIFEST_FILE = ".connectbase-manifest.json";
|
|
|
3457
3884
|
function readDocsManifest(docsDir) {
|
|
3458
3885
|
try {
|
|
3459
3886
|
const parsed = JSON.parse(
|
|
3460
|
-
|
|
3887
|
+
fs5.readFileSync(path5.join(docsDir, DOCS_MANIFEST_FILE), "utf-8")
|
|
3461
3888
|
);
|
|
3462
3889
|
if (parsed && Array.isArray(parsed.files)) return parsed;
|
|
3463
3890
|
} catch {
|
|
@@ -3519,14 +3946,14 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
3519
3946
|
info(`\uBAA8\uB178\uB808\uD3EC \uAC10\uC9C0: ${monorepo.type} (\uB8E8\uD2B8: ${gitRoot})`);
|
|
3520
3947
|
if (monorepo.isSubPackage) {
|
|
3521
3948
|
info(
|
|
3522
|
-
`\uD604\uC7AC \uC11C\uBE0C \uD328\uD0A4\uC9C0: ${monorepo.subPackageName ||
|
|
3949
|
+
`\uD604\uC7AC \uC11C\uBE0C \uD328\uD0A4\uC9C0: ${monorepo.subPackageName || path5.basename(process.cwd())}`
|
|
3523
3950
|
);
|
|
3524
3951
|
}
|
|
3525
3952
|
}
|
|
3526
|
-
const docsDir =
|
|
3527
|
-
const rootClaudeMd =
|
|
3528
|
-
if (!
|
|
3529
|
-
|
|
3953
|
+
const docsDir = path5.join(gitRoot, ".claude", "docs");
|
|
3954
|
+
const rootClaudeMd = path5.join(gitRoot, "CLAUDE.md");
|
|
3955
|
+
if (!fs5.existsSync(docsDir)) {
|
|
3956
|
+
fs5.mkdirSync(docsDir, { recursive: true });
|
|
3530
3957
|
}
|
|
3531
3958
|
if (!quiet) info("SDK \uAC1C\uBC1C \uAC00\uC774\uB4DC \uB2E4\uC6B4\uB85C\uB4DC \uC911...");
|
|
3532
3959
|
try {
|
|
@@ -3543,21 +3970,21 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
3543
3970
|
const hasher = crypto.createHash("sha256");
|
|
3544
3971
|
const newFiles = [];
|
|
3545
3972
|
for (const section of sections) {
|
|
3546
|
-
const safeName =
|
|
3973
|
+
const safeName = path5.basename(section.filename);
|
|
3547
3974
|
newFiles.push(safeName);
|
|
3548
3975
|
hasher.update(safeName).update("\0").update(section.content).update("\0");
|
|
3549
3976
|
}
|
|
3550
3977
|
const contentHash = hasher.digest("hex");
|
|
3551
3978
|
const prevManifest = readDocsManifest(docsDir);
|
|
3552
3979
|
const allPresent = newFiles.every(
|
|
3553
|
-
(f) =>
|
|
3980
|
+
(f) => fs5.existsSync(path5.join(docsDir, f))
|
|
3554
3981
|
);
|
|
3555
3982
|
if (prevManifest && prevManifest.contentHash === contentHash && allPresent) {
|
|
3556
3983
|
if (!quiet) success("SDK \uBB38\uC11C\uAC00 \uC774\uBBF8 \uCD5C\uC2E0\uC785\uB2C8\uB2E4");
|
|
3557
3984
|
updateRootClaudeMd(rootClaudeMd, quiet);
|
|
3558
3985
|
if (monorepo.isSubPackage) {
|
|
3559
3986
|
createSubPackageClaudeMd(
|
|
3560
|
-
|
|
3987
|
+
path5.join(process.cwd(), "CLAUDE.md"),
|
|
3561
3988
|
gitRoot,
|
|
3562
3989
|
quiet
|
|
3563
3990
|
);
|
|
@@ -3568,16 +3995,16 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
3568
3995
|
|
|
3569
3996
|
`;
|
|
3570
3997
|
for (const section of sections) {
|
|
3571
|
-
const safeName =
|
|
3572
|
-
|
|
3998
|
+
const safeName = path5.basename(section.filename);
|
|
3999
|
+
fs5.writeFileSync(path5.join(docsDir, safeName), stamp + section.content);
|
|
3573
4000
|
}
|
|
3574
|
-
const staleCandidates = prevManifest ? prevManifest.files.map((f) =>
|
|
4001
|
+
const staleCandidates = prevManifest ? prevManifest.files.map((f) => path5.basename(f)) : LEGACY_DOC_FILES;
|
|
3575
4002
|
for (const old of staleCandidates) {
|
|
3576
4003
|
if (newFiles.includes(old)) continue;
|
|
3577
|
-
const oldPath =
|
|
3578
|
-
if (
|
|
4004
|
+
const oldPath = path5.join(docsDir, old);
|
|
4005
|
+
if (fs5.existsSync(oldPath)) {
|
|
3579
4006
|
try {
|
|
3580
|
-
|
|
4007
|
+
fs5.unlinkSync(oldPath);
|
|
3581
4008
|
if (!quiet) info(`\uC2A4\uD14C\uC77C \uBB38\uC11C \uC0AD\uC81C: ${old}`);
|
|
3582
4009
|
} catch {
|
|
3583
4010
|
}
|
|
@@ -3589,8 +4016,8 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
3589
4016
|
contentHash,
|
|
3590
4017
|
files: newFiles
|
|
3591
4018
|
};
|
|
3592
|
-
|
|
3593
|
-
|
|
4019
|
+
fs5.writeFileSync(
|
|
4020
|
+
path5.join(docsDir, DOCS_MANIFEST_FILE),
|
|
3594
4021
|
`${JSON.stringify(manifest, null, 2)}
|
|
3595
4022
|
`
|
|
3596
4023
|
);
|
|
@@ -3601,7 +4028,7 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
3601
4028
|
updateRootClaudeMd(rootClaudeMd, quiet);
|
|
3602
4029
|
if (monorepo.isSubPackage) {
|
|
3603
4030
|
createSubPackageClaudeMd(
|
|
3604
|
-
|
|
4031
|
+
path5.join(process.cwd(), "CLAUDE.md"),
|
|
3605
4032
|
gitRoot,
|
|
3606
4033
|
quiet
|
|
3607
4034
|
);
|
|
@@ -3620,10 +4047,10 @@ async function downloadDocs(baseDir, opts = {}) {
|
|
|
3620
4047
|
|
|
3621
4048
|
\uC0C1\uC138 \uAD6C\uD604\uBC95\uC740 MCP \`search_sdk_docs\` \uB3C4\uAD6C\uB85C \uAC80\uC0C9\uD558\uC138\uC694.
|
|
3622
4049
|
`;
|
|
3623
|
-
|
|
4050
|
+
fs5.writeFileSync(path5.join(docsDir, "project-rules.md"), fallbackContent);
|
|
3624
4051
|
updateRootClaudeMd(rootClaudeMd);
|
|
3625
4052
|
if (monorepo.isSubPackage) {
|
|
3626
|
-
const subClaudeMd =
|
|
4053
|
+
const subClaudeMd = path5.join(process.cwd(), "CLAUDE.md");
|
|
3627
4054
|
createSubPackageClaudeMd(subClaudeMd, gitRoot);
|
|
3628
4055
|
}
|
|
3629
4056
|
success(`.claude/docs/ \uC0DD\uC131 \uC644\uB8CC (\uAE30\uBCF8)`);
|
|
@@ -3646,8 +4073,8 @@ function updateRootClaudeMd(claudeMdPath, quiet = false) {
|
|
|
3646
4073
|
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
|
|
3647
4074
|
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)
|
|
3648
4075
|
${endMarker}`;
|
|
3649
|
-
if (
|
|
3650
|
-
let content =
|
|
4076
|
+
if (fs5.existsSync(claudeMdPath)) {
|
|
4077
|
+
let content = fs5.readFileSync(claudeMdPath, "utf-8");
|
|
3651
4078
|
const startIdx = content.indexOf(startMarker);
|
|
3652
4079
|
const endIdx = content.indexOf(endMarker);
|
|
3653
4080
|
if (startIdx !== -1 && endIdx !== -1) {
|
|
@@ -3657,10 +4084,10 @@ ${endMarker}`;
|
|
|
3657
4084
|
|
|
3658
4085
|
${content.trimStart()}`;
|
|
3659
4086
|
}
|
|
3660
|
-
|
|
4087
|
+
fs5.writeFileSync(claudeMdPath, content);
|
|
3661
4088
|
if (!quiet) info("CLAUDE.md\uC5D0 ConnectBase \uCC38\uC870 \uC5C5\uB370\uC774\uD2B8 \uC644\uB8CC");
|
|
3662
4089
|
} else {
|
|
3663
|
-
|
|
4090
|
+
fs5.writeFileSync(claudeMdPath, `# \uD504\uB85C\uC81D\uD2B8
|
|
3664
4091
|
|
|
3665
4092
|
${sdkBlock}
|
|
3666
4093
|
`);
|
|
@@ -3670,7 +4097,7 @@ ${sdkBlock}
|
|
|
3670
4097
|
function createSubPackageClaudeMd(subClaudeMdPath, gitRoot, quiet = false) {
|
|
3671
4098
|
const startMarker = "<!-- CONNECTBASE_SUB_START -->";
|
|
3672
4099
|
const endMarker = "<!-- CONNECTBASE_SUB_END -->";
|
|
3673
|
-
const relPath =
|
|
4100
|
+
const relPath = path5.relative(path5.dirname(subClaudeMdPath), gitRoot);
|
|
3674
4101
|
const subBlock = `${startMarker}
|
|
3675
4102
|
## ConnectBase SDK
|
|
3676
4103
|
|
|
@@ -3682,8 +4109,8 @@ function createSubPackageClaudeMd(subClaudeMdPath, gitRoot, quiet = false) {
|
|
|
3682
4109
|
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
|
|
3683
4110
|
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
|
|
3684
4111
|
${endMarker}`;
|
|
3685
|
-
if (
|
|
3686
|
-
let content =
|
|
4112
|
+
if (fs5.existsSync(subClaudeMdPath)) {
|
|
4113
|
+
let content = fs5.readFileSync(subClaudeMdPath, "utf-8");
|
|
3687
4114
|
const startIdx = content.indexOf(startMarker);
|
|
3688
4115
|
const endIdx = content.indexOf(endMarker);
|
|
3689
4116
|
if (startIdx !== -1 && endIdx !== -1) {
|
|
@@ -3696,11 +4123,11 @@ ${subBlock}
|
|
|
3696
4123
|
} else {
|
|
3697
4124
|
return;
|
|
3698
4125
|
}
|
|
3699
|
-
|
|
4126
|
+
fs5.writeFileSync(subClaudeMdPath, content);
|
|
3700
4127
|
} else {
|
|
3701
|
-
|
|
4128
|
+
fs5.writeFileSync(
|
|
3702
4129
|
subClaudeMdPath,
|
|
3703
|
-
`# ${
|
|
4130
|
+
`# ${path5.basename(path5.dirname(subClaudeMdPath))}
|
|
3704
4131
|
|
|
3705
4132
|
${subBlock}
|
|
3706
4133
|
`
|
|
@@ -3718,7 +4145,7 @@ async function setupMcp(secretKey, baseUrl = DEFAULT_BASE_URL) {
|
|
|
3718
4145
|
info(`MCP \uC124\uC815\uC740 \uD504\uB85C\uC81D\uD2B8 \uB8E8\uD2B8(${root})\uC5D0 \uC0DD\uC131\uB429\uB2C8\uB2E4`);
|
|
3719
4146
|
}
|
|
3720
4147
|
}
|
|
3721
|
-
const mcpConfigPath =
|
|
4148
|
+
const mcpConfigPath = path5.join(root, ".mcp.json");
|
|
3722
4149
|
if (secretKey) {
|
|
3723
4150
|
const check = await fetchAppsWithSecretKey(baseUrl, secretKey).catch(
|
|
3724
4151
|
() => null
|
|
@@ -3753,17 +4180,17 @@ async function setupMcp(secretKey, baseUrl = DEFAULT_BASE_URL) {
|
|
|
3753
4180
|
}
|
|
3754
4181
|
};
|
|
3755
4182
|
let mcpConfig = { mcpServers: {} };
|
|
3756
|
-
if (
|
|
4183
|
+
if (fs5.existsSync(mcpConfigPath)) {
|
|
3757
4184
|
try {
|
|
3758
|
-
mcpConfig = JSON.parse(
|
|
4185
|
+
mcpConfig = JSON.parse(fs5.readFileSync(mcpConfigPath, "utf-8"));
|
|
3759
4186
|
if (!mcpConfig.mcpServers || typeof mcpConfig.mcpServers !== "object") {
|
|
3760
4187
|
mcpConfig.mcpServers = {};
|
|
3761
4188
|
}
|
|
3762
4189
|
} catch {
|
|
3763
4190
|
const backupPath = `${mcpConfigPath}.backup`;
|
|
3764
|
-
|
|
4191
|
+
fs5.copyFileSync(mcpConfigPath, backupPath);
|
|
3765
4192
|
try {
|
|
3766
|
-
|
|
4193
|
+
fs5.chmodSync(backupPath, 384);
|
|
3767
4194
|
} catch {
|
|
3768
4195
|
}
|
|
3769
4196
|
warn(`.mcp.json \uD30C\uC2F1 \uC2E4\uD328, \uBC31\uC5C5 \uC0DD\uC131: ${backupPath}`);
|
|
@@ -3824,14 +4251,14 @@ function findSubPackagesWithConfig(gitRoot) {
|
|
|
3824
4251
|
const results = [];
|
|
3825
4252
|
const candidates = ["apps", "packages", "projects", "services", "libs"];
|
|
3826
4253
|
for (const candidate of candidates) {
|
|
3827
|
-
const dir =
|
|
3828
|
-
if (!
|
|
4254
|
+
const dir = path5.join(gitRoot, candidate);
|
|
4255
|
+
if (!fs5.existsSync(dir)) continue;
|
|
3829
4256
|
try {
|
|
3830
|
-
const entries =
|
|
4257
|
+
const entries = fs5.readdirSync(dir, { withFileTypes: true });
|
|
3831
4258
|
for (const entry of entries) {
|
|
3832
4259
|
if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
|
|
3833
|
-
const subDir =
|
|
3834
|
-
if (
|
|
4260
|
+
const subDir = path5.join(dir, entry.name);
|
|
4261
|
+
if (fs5.existsSync(path5.join(subDir, ".connectbaserc"))) {
|
|
3835
4262
|
results.push(subDir);
|
|
3836
4263
|
}
|
|
3837
4264
|
}
|
|
@@ -3839,13 +4266,13 @@ function findSubPackagesWithConfig(gitRoot) {
|
|
|
3839
4266
|
}
|
|
3840
4267
|
}
|
|
3841
4268
|
try {
|
|
3842
|
-
const entries =
|
|
4269
|
+
const entries = fs5.readdirSync(gitRoot, { withFileTypes: true });
|
|
3843
4270
|
for (const entry of entries) {
|
|
3844
4271
|
if (!entry.isDirectory() || entry.name.startsWith(".") || candidates.includes(entry.name))
|
|
3845
4272
|
continue;
|
|
3846
4273
|
if (entry.name === "node_modules") continue;
|
|
3847
|
-
const subDir =
|
|
3848
|
-
if (
|
|
4274
|
+
const subDir = path5.join(gitRoot, entry.name);
|
|
4275
|
+
if (fs5.existsSync(path5.join(subDir, ".connectbaserc")) && !results.includes(subDir)) {
|
|
3849
4276
|
results.push(subDir);
|
|
3850
4277
|
}
|
|
3851
4278
|
}
|
|
@@ -3889,7 +4316,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
3889
4316
|
info(`ConnectBase\uB97C \uC0AC\uC6A9\uD558\uB294 \uC11C\uBE0C \uD328\uD0A4\uC9C0 ${subPackages.length}\uAC1C \uBC1C\uACAC:`);
|
|
3890
4317
|
for (const sp of subPackages) {
|
|
3891
4318
|
log(
|
|
3892
|
-
` ${colors.dim}\u2022 ${
|
|
4319
|
+
` ${colors.dim}\u2022 ${path5.relative(projectRoot, sp)}${colors.reset}`
|
|
3893
4320
|
);
|
|
3894
4321
|
}
|
|
3895
4322
|
}
|
|
@@ -3901,14 +4328,14 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
3901
4328
|
}
|
|
3902
4329
|
if (!opts.skipMcp) {
|
|
3903
4330
|
log("");
|
|
3904
|
-
const mcpConfigPath =
|
|
3905
|
-
if (
|
|
4331
|
+
const mcpConfigPath = path5.join(projectRoot, ".mcp.json");
|
|
4332
|
+
if (fs5.existsSync(mcpConfigPath)) {
|
|
3906
4333
|
let secretKey = config.secretKey;
|
|
3907
4334
|
if (!secretKey) {
|
|
3908
|
-
const rootRcPath =
|
|
3909
|
-
if (
|
|
4335
|
+
const rootRcPath = path5.join(projectRoot, ".connectbaserc");
|
|
4336
|
+
if (fs5.existsSync(rootRcPath)) {
|
|
3910
4337
|
try {
|
|
3911
|
-
const rc = JSON.parse(
|
|
4338
|
+
const rc = JSON.parse(fs5.readFileSync(rootRcPath, "utf-8"));
|
|
3912
4339
|
secretKey = rc.secretKey;
|
|
3913
4340
|
} catch {
|
|
3914
4341
|
}
|
|
@@ -3919,7 +4346,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
3919
4346
|
for (const sp of subPackages) {
|
|
3920
4347
|
try {
|
|
3921
4348
|
const rc = JSON.parse(
|
|
3922
|
-
|
|
4349
|
+
fs5.readFileSync(path5.join(sp, ".connectbaserc"), "utf-8")
|
|
3923
4350
|
);
|
|
3924
4351
|
if (rc.secretKey) {
|
|
3925
4352
|
secretKey = rc.secretKey;
|
|
@@ -3931,7 +4358,7 @@ ${colors.cyan}ConnectBase Update${colors.reset}
|
|
|
3931
4358
|
}
|
|
3932
4359
|
if (secretKey) {
|
|
3933
4360
|
try {
|
|
3934
|
-
const mcpConfig = JSON.parse(
|
|
4361
|
+
const mcpConfig = JSON.parse(fs5.readFileSync(mcpConfigPath, "utf-8"));
|
|
3935
4362
|
const servers = mcpConfig.mcpServers || {};
|
|
3936
4363
|
if (servers["connect-base"]) {
|
|
3937
4364
|
servers["connect-base"] = {
|
|
@@ -3970,15 +4397,15 @@ ${colors.green}\uC5C5\uB370\uC774\uD2B8 \uC644\uB8CC!${colors.reset}
|
|
|
3970
4397
|
`);
|
|
3971
4398
|
}
|
|
3972
4399
|
function setupMonorepoRoot(projectRoot, monorepo) {
|
|
3973
|
-
const rootPkgPath =
|
|
3974
|
-
if (!
|
|
4400
|
+
const rootPkgPath = path5.join(projectRoot, "package.json");
|
|
4401
|
+
if (!fs5.existsSync(rootPkgPath)) {
|
|
3975
4402
|
warn(
|
|
3976
4403
|
"\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"
|
|
3977
4404
|
);
|
|
3978
4405
|
return;
|
|
3979
4406
|
}
|
|
3980
4407
|
try {
|
|
3981
|
-
const pkg = JSON.parse(
|
|
4408
|
+
const pkg = JSON.parse(fs5.readFileSync(rootPkgPath, "utf-8"));
|
|
3982
4409
|
if (!pkg.scripts) pkg.scripts = {};
|
|
3983
4410
|
let changed = false;
|
|
3984
4411
|
if (!pkg.scripts["cb:update"]) {
|
|
@@ -3994,7 +4421,7 @@ function setupMonorepoRoot(projectRoot, monorepo) {
|
|
|
3994
4421
|
changed = true;
|
|
3995
4422
|
}
|
|
3996
4423
|
if (changed) {
|
|
3997
|
-
|
|
4424
|
+
fs5.writeFileSync(rootPkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
3998
4425
|
`);
|
|
3999
4426
|
success("\uBAA8\uB178\uB808\uD3EC \uB8E8\uD2B8\uC5D0 \uD3B8\uC758 \uC2A4\uD06C\uB9BD\uD2B8 \uCD94\uAC00 \uC644\uB8CC");
|
|
4000
4427
|
log(` ${colors.dim}\uC0AC\uC6A9\uBC95:${colors.reset}`);
|
|
@@ -4399,7 +4826,7 @@ ${colors.blue}?${colors.reset} \uC571 \uC120\uD0DD (\uBC88\uD638): `
|
|
|
4399
4826
|
success(`\uC120\uD0DD\uB428: ${apps[num2 - 1].name}`);
|
|
4400
4827
|
return { appId: apps[num2 - 1].id };
|
|
4401
4828
|
}
|
|
4402
|
-
const projectName =
|
|
4829
|
+
const projectName = path5.basename(process.cwd());
|
|
4403
4830
|
const appName = await prompt(
|
|
4404
4831
|
`${colors.blue}?${colors.reset} \uC571 \uC774\uB984 (${projectName}): `
|
|
4405
4832
|
) || projectName;
|
|
@@ -4482,11 +4909,11 @@ async function startTunnel(port, config, tunnelOpts) {
|
|
|
4482
4909
|
info("Secret Key\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4. \uBE0C\uB77C\uC6B0\uC800 \uB85C\uADF8\uC778\uC73C\uB85C \uBC1C\uAE09\uD569\uB2C8\uB2E4...");
|
|
4483
4910
|
try {
|
|
4484
4911
|
const sk = await browserAuthFlow();
|
|
4485
|
-
const rcPath2 =
|
|
4912
|
+
const rcPath2 = path5.join(process.cwd(), ".connectbaserc");
|
|
4486
4913
|
let rcData = {};
|
|
4487
|
-
if (
|
|
4914
|
+
if (fs5.existsSync(rcPath2)) {
|
|
4488
4915
|
try {
|
|
4489
|
-
rcData = JSON.parse(
|
|
4916
|
+
rcData = JSON.parse(fs5.readFileSync(rcPath2, "utf-8"));
|
|
4490
4917
|
} catch {
|
|
4491
4918
|
}
|
|
4492
4919
|
}
|
|
@@ -4505,11 +4932,11 @@ async function startTunnel(port, config, tunnelOpts) {
|
|
|
4505
4932
|
} else {
|
|
4506
4933
|
config.secretKey = tunnelKey;
|
|
4507
4934
|
}
|
|
4508
|
-
const rcPath =
|
|
4935
|
+
const rcPath = path5.join(process.cwd(), ".connectbaserc");
|
|
4509
4936
|
let savedAppId = tunnelOpts?.appId || "";
|
|
4510
4937
|
if (!savedAppId) {
|
|
4511
4938
|
try {
|
|
4512
|
-
const rc = JSON.parse(
|
|
4939
|
+
const rc = JSON.parse(fs5.readFileSync(rcPath, "utf-8"));
|
|
4513
4940
|
if (rc.tunnelAppId) savedAppId = rc.tunnelAppId;
|
|
4514
4941
|
} catch {
|
|
4515
4942
|
}
|
|
@@ -4517,9 +4944,9 @@ async function startTunnel(port, config, tunnelOpts) {
|
|
|
4517
4944
|
const { appId } = await resolveApp(tunnelKey, config.baseUrl, savedAppId);
|
|
4518
4945
|
try {
|
|
4519
4946
|
let rcData = {};
|
|
4520
|
-
if (
|
|
4947
|
+
if (fs5.existsSync(rcPath)) {
|
|
4521
4948
|
try {
|
|
4522
|
-
rcData = JSON.parse(
|
|
4949
|
+
rcData = JSON.parse(fs5.readFileSync(rcPath, "utf-8"));
|
|
4523
4950
|
} catch {
|
|
4524
4951
|
}
|
|
4525
4952
|
}
|
|
@@ -5278,6 +5705,8 @@ ${colors.yellow}\uBA85\uB839\uC5B4:${colors.reset}
|
|
|
5278
5705
|
tunnel <port> \uB85C\uCEEC \uC11C\uBE44\uC2A4\uB97C \uC778\uD130\uB137\uC5D0 \uB178\uCD9C
|
|
5279
5706
|
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
5707
|
--add <GitHub owner/repo[/\uD3F4\uB354][@ref] | \uC8FC\uC18C | \uD3F4\uB354> \uC2A4\uD0AC \uC124\uCE58 (\uC5EC\uB7EC \uBC88 \uAC00\uB2A5)
|
|
5708
|
+
--mcp <\uC774\uB984>="<\uBA85\uB839>" | <\uC774\uB984>=<http \uC8FC\uC18C> \uC2A4\uD0AC\uC774 \uC4F0\uB294 PC \uC758 MCP \uC11C\uBC84 \uCD94\uAC00 (\uC5EC\uB7EC \uBC88 \uAC00\uB2A5,
|
|
5709
|
+
\uC791\uC5C5 \uD3F4\uB354\uC758 connectbase-local.json mcpServers \uC5D0 \uC800\uC7A5. Claude Desktop \uACFC \uAC19\uC740 \uD615\uC2DD)
|
|
5281
5710
|
--update \uC124\uCE58\uB41C \uC2A4\uD0AC \uB2E4\uC2DC \uBC1B\uAE30 --dir <\uD3F4\uB354> \uC791\uC5C5 \uD3F4\uB354 (\uAE30\uBCF8 ~/ConnectBaseLocal)
|
|
5282
5711
|
\uC608: npx connectbase-client local --add yorusd1/yoruskills
|
|
5283
5712
|
|
|
@@ -5421,8 +5850,8 @@ async function enforceBaseUrlPolicy(baseUrl, opts) {
|
|
|
5421
5850
|
process.exit(1);
|
|
5422
5851
|
}
|
|
5423
5852
|
function isOutsideProject(dir, root) {
|
|
5424
|
-
const relative3 =
|
|
5425
|
-
return relative3 === ".." || relative3.startsWith(`..${
|
|
5853
|
+
const relative3 = path5.relative(path5.resolve(root), path5.resolve(root, dir));
|
|
5854
|
+
return relative3 === ".." || relative3.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative3);
|
|
5426
5855
|
}
|
|
5427
5856
|
function parseArgs(args) {
|
|
5428
5857
|
const result = {
|
|
@@ -5462,6 +5891,8 @@ function parseArgs(args) {
|
|
|
5462
5891
|
result.options.add = result.options.add ? `${result.options.add},${args[++i]}` : args[++i];
|
|
5463
5892
|
} else if (arg === "--update") {
|
|
5464
5893
|
result.options.update = "true";
|
|
5894
|
+
} else if (arg === "--mcp") {
|
|
5895
|
+
result.options.mcp = result.options.mcp ? `${result.options.mcp}\0${args[++i]}` : args[++i];
|
|
5465
5896
|
} else if (arg === "--force") {
|
|
5466
5897
|
result.options.force = "true";
|
|
5467
5898
|
} else if (arg === "-y" || arg === "--yes") {
|
|
@@ -5576,8 +6007,8 @@ async function main() {
|
|
|
5576
6007
|
if (parsed.options.skipDocs !== "true") {
|
|
5577
6008
|
try {
|
|
5578
6009
|
const docsRoot = getGitRoot() || getProjectRoot();
|
|
5579
|
-
if (
|
|
5580
|
-
|
|
6010
|
+
if (fs5.existsSync(
|
|
6011
|
+
path5.join(docsRoot, ".claude", "docs", DOCS_MANIFEST_FILE)
|
|
5581
6012
|
)) {
|
|
5582
6013
|
const refreshed = await downloadDocs(docsRoot, {
|
|
5583
6014
|
quiet: true,
|
|
@@ -5622,7 +6053,8 @@ async function main() {
|
|
|
5622
6053
|
appId: parsed.options.appId,
|
|
5623
6054
|
force: parsed.options.force === "true",
|
|
5624
6055
|
add: parsed.options.add,
|
|
5625
|
-
update: parsed.options.update === "true"
|
|
6056
|
+
update: parsed.options.update === "true",
|
|
6057
|
+
mcp: parsed.options.mcp
|
|
5626
6058
|
},
|
|
5627
6059
|
(p, c, o) => startTunnel(p, c, o),
|
|
5628
6060
|
{ info, success, warn }
|