@ainecto/cli 0.14.0-next.9.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/mcp.js CHANGED
@@ -139,7 +139,7 @@ function tokenKey(endpoint) {
139
139
  }
140
140
 
141
141
  // src/core/auth/oauth.ts
142
- import { createHash as createHash2, randomBytes } from "crypto";
142
+ import { createHash as createHash3, randomBytes } from "crypto";
143
143
  import { createServer } from "http";
144
144
  import { spawn } from "child_process";
145
145
  import { URLSearchParams } from "url";
@@ -220,19 +220,128 @@ function legacyRoleInput(flag, envVars = process.env) {
220
220
  }
221
221
 
222
222
  // src/core/version.ts
223
- var CLI_VERSION = true ? "0.14.0-next.9.1" : UNBUNDLED_VERSION;
224
- var CLI_BUILD = true ? "b1e1dea" : void 0;
223
+ var CLI_VERSION = true ? "0.15.0" : UNBUNDLED_VERSION;
224
+ var CLI_BUILD = true ? "809aaf7" : void 0;
225
225
  function cliVersionLabel(version, build, release) {
226
226
  return release || build === void 0 ? version : `${version}-dev+${build}`;
227
227
  }
228
- var CLI_VERSION_LABEL = cliVersionLabel(
229
- CLI_VERSION,
230
- CLI_BUILD,
231
- true
232
- );
228
+ var CLI_RELEASE = true;
229
+ var CLI_VERSION_LABEL = cliVersionLabel(CLI_VERSION, CLI_BUILD, CLI_RELEASE);
233
230
  var PACKAGE_NAME = "@ainecto/mcp";
234
231
  var CLI_USER_AGENT = `${PACKAGE_NAME} ${CLI_VERSION}`;
235
232
 
233
+ // src/core/catalog/generator.ts
234
+ import { createHash as createHash2 } from "crypto";
235
+ var LEGACY_PREFIX = "mcp__ainecto__";
236
+ function bareToolName(name) {
237
+ return name.startsWith(LEGACY_PREFIX) ? name.slice(LEGACY_PREFIX.length) : name;
238
+ }
239
+
240
+ // src/core/mcp/toolPayload.ts
241
+ function unwrapMcpToolPayload(value) {
242
+ if (!isRecord3(value) || !Array.isArray(value.content)) {
243
+ return value;
244
+ }
245
+ const text = value.content.map((item) => isRecord3(item) && typeof item.text === "string" ? item.text : "").find((itemText) => itemText.trim().startsWith("{"));
246
+ if (!text) {
247
+ return value;
248
+ }
249
+ try {
250
+ return JSON.parse(text);
251
+ } catch {
252
+ return value;
253
+ }
254
+ }
255
+ function toolErrorText(value) {
256
+ if (!isRecord3(value) || !Array.isArray(value.content)) {
257
+ return "The tool returned an error.";
258
+ }
259
+ const text = value.content.map((item) => isRecord3(item) && typeof item.text === "string" ? item.text : "").filter(Boolean).join("\n");
260
+ return text || "The tool returned an error.";
261
+ }
262
+ function isRecord3(value) {
263
+ return typeof value === "object" && value !== null && !Array.isArray(value);
264
+ }
265
+
266
+ // src/core/mcp/operations.ts
267
+ var SEARCH_TOOL = "search";
268
+ var OperationError = class extends Error {
269
+ constructor(message, code, operation, details) {
270
+ super(message);
271
+ this.code = code;
272
+ this.operation = operation;
273
+ this.details = details;
274
+ this.name = "OperationError";
275
+ }
276
+ code;
277
+ operation;
278
+ details;
279
+ };
280
+ function searchPayload(asked, operation, result) {
281
+ if (isRecord4(result) && result.isError === true) throw toolRefusal(asked, operation, result);
282
+ return unwrapMcpToolPayload(result);
283
+ }
284
+ function parseOperationDetail(operation, result) {
285
+ const payload = searchPayload(`the detail of ${operation}`, operation, result);
286
+ if (!isRecord4(payload) || payload.operation !== operation) {
287
+ throw new OperationError(`search did not return the detail of ${operation}.`, "MCP_PROTOCOL_ERROR", operation);
288
+ }
289
+ const executor = payload.executor;
290
+ if (typeof executor !== "string" || executor.trim() === "") {
291
+ throw new OperationError(
292
+ `search detail of ${operation} has no valid executor (${JSON.stringify(executor)}).`,
293
+ "MCP_PROTOCOL_ERROR",
294
+ operation
295
+ );
296
+ }
297
+ const hints = isRecord4(payload.annotations) ? payload.annotations : {};
298
+ return {
299
+ operation,
300
+ summary: typeof payload.summary === "string" ? payload.summary : "",
301
+ executor,
302
+ annotations: {
303
+ ...typeof hints.readOnlyHint === "boolean" ? { readOnlyHint: hints.readOnlyHint } : {},
304
+ ...typeof hints.destructiveHint === "boolean" ? { destructiveHint: hints.destructiveHint } : {},
305
+ ...typeof hints.idempotentHint === "boolean" ? { idempotentHint: hints.idempotentHint } : {},
306
+ ...typeof hints.openWorldHint === "boolean" ? { openWorldHint: hints.openWorldHint } : {}
307
+ },
308
+ inputSchema: isRecord4(payload.inputSchema) ? payload.inputSchema : { type: "object", properties: {} }
309
+ };
310
+ }
311
+ var OperationCaller = class {
312
+ constructor(callPublic) {
313
+ this.callPublic = callPublic;
314
+ }
315
+ callPublic;
316
+ details = /* @__PURE__ */ new Map();
317
+ detail(operation) {
318
+ let found = this.details.get(operation);
319
+ if (!found) {
320
+ found = this.callPublic(SEARCH_TOOL, { operation }).then((result) => parseOperationDetail(operation, result));
321
+ found.catch(() => this.details.delete(operation));
322
+ this.details.set(operation, found);
323
+ }
324
+ return found;
325
+ }
326
+ async call(operation, args) {
327
+ const detail = await this.detail(operation);
328
+ return this.callPublic(detail.executor, { operation, args });
329
+ }
330
+ };
331
+ function toolRefusal(asked, operation, result) {
332
+ const text = toolErrorText(result);
333
+ let code = "MCP_TOOL_ERROR";
334
+ try {
335
+ const parsed = JSON.parse(text);
336
+ if (isRecord4(parsed) && typeof parsed.code === "string" && parsed.code) code = parsed.code;
337
+ } catch {
338
+ }
339
+ return new OperationError(`search refused ${asked}: ${text}`, code, operation, result);
340
+ }
341
+ function isRecord4(value) {
342
+ return typeof value === "object" && value !== null && !Array.isArray(value);
343
+ }
344
+
236
345
  // src/core/mcp/rpcClient.ts
237
346
  var CHANNEL_HEADER = "X-AiNecto-Channel";
238
347
  var AGENT_HEADER = "X-AiNecto-Agent";
@@ -259,11 +368,16 @@ var McpRpcClient = class {
259
368
  constructor(options) {
260
369
  this.options = options;
261
370
  this.fetchImpl = options.fetchImpl ?? fetch;
371
+ this.operations = new OperationCaller((tool, args) => this.request("tools/call", { name: tool, arguments: args }));
262
372
  }
263
373
  options;
264
374
  fetchImpl;
265
375
  nextId = 1;
266
376
  agent;
377
+ /** operation → 실행 도구 — 상세(executor)는 이 연결에서 한 번만 묻는다. */
378
+ operations;
379
+ /** 서버가 공개한 도구 이름 — 진실원은 tools/list. 연결당 한 번(실패는 기억하지 않는다). */
380
+ publicTools;
267
381
  /**
268
382
  * 브리지 전용 — 호스트 에이전트가 보낸 {@code initialize} 의 {@code clientInfo.name}(프로그램 고정 이름).
269
383
  * 이후 모든 요청의 {@code X-AiNecto-Agent} 헤더로 싣는다. 직접 명령은 부르지 않는다(누가 셸을 돌렸는지 모른다).
@@ -280,13 +394,41 @@ var McpRpcClient = class {
280
394
  }
281
395
  async toolsList() {
282
396
  const result = await this.request("tools/list", {});
283
- if (!isRecord3(result) || !Array.isArray(result.tools)) {
397
+ if (!isRecord5(result) || !Array.isArray(result.tools)) {
284
398
  throw new McpRpcError("tools/list response did not include a tools array.", "MCP_PROTOCOL_ERROR", result);
285
399
  }
400
+ this.publicTools = Promise.resolve(toolNames(result.tools));
286
401
  return result.tools;
287
402
  }
403
+ /** 공개 도구 이름 — 이 연결에서 아직 모르면 tools/list 를 한 번 부른다. */
404
+ publicToolNames() {
405
+ if (!this.publicTools) {
406
+ const pending = this.toolsList().then(toolNames);
407
+ pending.catch(() => {
408
+ if (this.publicTools === pending) this.publicTools = void 0;
409
+ });
410
+ this.publicTools = pending;
411
+ }
412
+ return this.publicTools;
413
+ }
414
+ /**
415
+ * ★CLI 안의 모든 도구 호출이 지나는 한 입구. 서버 tools/list 에 있는 공개 도구(search·execute_*·open_ainecto_panel)는
416
+ * 자기 이름으로 한 번만, 그 밖의 이름은 operation 으로 보고 {@code <executor> {operation, args}} 로 바꿔 부른다(operations.ts)
417
+ * — 서버는 옛 108개 이름을 거절한다. 공개 이름의 사본은 두지 않는다(리뷰 r1 P1-3).
418
+ * 옛 {@code mcp__ainecto__} 앞머리는 뗀다. 브리지(sendRaw)는 이 길을 지나지 않는다 — 호스트가 고른 도구 그대로 간다.
419
+ */
288
420
  async toolsCall(name, args) {
289
- return this.request("tools/call", { name, arguments: args ?? {} });
421
+ const bare = bareToolName(name);
422
+ const payload = isRecord5(args) ? args : {};
423
+ return (await this.publicToolNames()).has(bare) ? this.request("tools/call", { name: bare, arguments: payload }) : this.operations.call(bare, payload);
424
+ }
425
+ /**
426
+ * {@link toolsCall} 가 이 이름을 부를 때 쓸 상세 — 공개 도구 이름이면 undefined(자기 이름으로 바로 간다).
427
+ * 같은 연결의 상세라 뒤이은 toolsCall 이 똑같은 것을 쓴다(실행 전 판단과 실행이 같은 사실을 본다).
428
+ */
429
+ async operationDetailFor(name) {
430
+ const bare = bareToolName(name);
431
+ return (await this.publicToolNames()).has(bare) ? void 0 : this.operations.detail(bare);
290
432
  }
291
433
  async request(method, params) {
292
434
  const response = await this.sendRaw({
@@ -373,7 +515,7 @@ var McpRpcClient = class {
373
515
  function rateLimitedResponse(text, retryAfter) {
374
516
  const envelope = rpcErrorEnvelope(text);
375
517
  if (envelope) {
376
- const data = isRecord3(envelope.error.data) ? envelope.error.data : {};
518
+ const data = isRecord5(envelope.error.data) ? envelope.error.data : {};
377
519
  const seconds = parseRetryAfter(retryAfter);
378
520
  if (data.retryAfterSeconds === void 0 && seconds !== void 0) {
379
521
  envelope.error.data = { ...data, retryAfterSeconds: seconds };
@@ -385,7 +527,7 @@ function rateLimitedResponse(text, retryAfter) {
385
527
  }
386
528
  function rpcErrorEnvelope(text) {
387
529
  const parsed = parseJsonOrUndefined(text);
388
- return isJsonRpcResponse(parsed) && "error" in parsed && isRecord3(parsed.error) ? parsed : void 0;
530
+ return isJsonRpcResponse(parsed) && "error" in parsed && isRecord5(parsed.error) ? parsed : void 0;
389
531
  }
390
532
  function parseJsonOrUndefined(text) {
391
533
  try {
@@ -395,8 +537,8 @@ function parseJsonOrUndefined(text) {
395
537
  }
396
538
  }
397
539
  function describeRpcError(error) {
398
- const data = isRecord3(error.data) ? error.data : {};
399
- const messages = isRecord3(data.messages) ? data.messages : {};
540
+ const data = isRecord5(error.data) ? error.data : {};
541
+ const messages = isRecord5(data.messages) ? data.messages : {};
400
542
  const sentence = [error.message, data.message, messages.en, messages.ko].find((value) => typeof value === "string" && value.trim() !== "");
401
543
  const code = typeof data.code === "string" && data.code.trim() ? data.code.trim() : void 0;
402
544
  if (!code) {
@@ -421,7 +563,7 @@ function parseServerError(body) {
421
563
  } catch {
422
564
  return void 0;
423
565
  }
424
- if (!isRecord3(parsed) || typeof parsed.error !== "string" || !parsed.error.trim()) {
566
+ if (!isRecord5(parsed) || typeof parsed.error !== "string" || !parsed.error.trim()) {
425
567
  return void 0;
426
568
  }
427
569
  return {
@@ -434,9 +576,12 @@ function describeServerError(serverError) {
434
576
  return line.replace(/\s+/g, " ").trim();
435
577
  }
436
578
  function isJsonRpcResponse(value) {
437
- return isRecord3(value) && value.jsonrpc === "2.0" && ("result" in value || "error" in value);
579
+ return isRecord5(value) && value.jsonrpc === "2.0" && ("result" in value || "error" in value);
438
580
  }
439
- function isRecord3(value) {
581
+ function toolNames(tools) {
582
+ return new Set(tools.flatMap((tool) => isRecord5(tool) && typeof tool.name === "string" ? [tool.name] : []));
583
+ }
584
+ function isRecord5(value) {
440
585
  return typeof value === "object" && value !== null && !Array.isArray(value);
441
586
  }
442
587
  function httpErrorDetails(status, body, envVars) {
@@ -567,7 +712,7 @@ var OAuthClient = class {
567
712
  };
568
713
  function generatePkcePair() {
569
714
  const codeVerifier = randomBytes(32).toString("base64url");
570
- const codeChallenge = createHash2("sha256").update(codeVerifier).digest("base64url");
715
+ const codeChallenge = createHash3("sha256").update(codeVerifier).digest("base64url");
571
716
  return { codeVerifier, codeChallenge };
572
717
  }
573
718
  function generateOAuthState() {
@@ -781,7 +926,7 @@ function getBrowserOpenCommand(url, platform = process.platform) {
781
926
  return { command: "open", args: [url] };
782
927
  }
783
928
  if (platform === "win32") {
784
- return { command: "explorer.exe", args: [url] };
929
+ return { command: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url] };
785
930
  }
786
931
  return { command: "xdg-open", args: [url] };
787
932
  }
@@ -867,7 +1012,7 @@ var INVALID_REQUEST = -32600;
867
1012
  var INTERNAL_ERROR = -32603;
868
1013
  var RATE_LIMITED_CODE = 429;
869
1014
  function failure(id, code, error) {
870
- const data = error instanceof McpRpcError ? { code: error.code, ...isRecord4(error.details) ? error.details : {} } : void 0;
1015
+ const data = error instanceof McpRpcError ? { code: error.code, ...isRecord6(error.details) ? error.details : {} } : void 0;
871
1016
  return {
872
1017
  jsonrpc: "2.0",
873
1018
  id,
@@ -883,7 +1028,7 @@ function writeLine(output, message) {
883
1028
  }
884
1029
  function parseJsonRpcRequest(line) {
885
1030
  const parsed = JSON.parse(line);
886
- if (!isRecord4(parsed) || parsed.jsonrpc !== "2.0" || typeof parsed.method !== "string") {
1031
+ if (!isRecord6(parsed) || parsed.jsonrpc !== "2.0" || typeof parsed.method !== "string") {
887
1032
  throw new Error("Invalid JSON-RPC request.");
888
1033
  }
889
1034
  return {
@@ -894,9 +1039,9 @@ function parseJsonRpcRequest(line) {
894
1039
  };
895
1040
  }
896
1041
  function clientInfoName(params) {
897
- return isRecord4(params) && isRecord4(params.clientInfo) ? params.clientInfo.name : void 0;
1042
+ return isRecord6(params) && isRecord6(params.clientInfo) ? params.clientInfo.name : void 0;
898
1043
  }
899
- function isRecord4(value) {
1044
+ function isRecord6(value) {
900
1045
  return typeof value === "object" && value !== null && !Array.isArray(value);
901
1046
  }
902
1047
 
@@ -906,7 +1051,8 @@ var SERVER_NAME = "ainecto";
906
1051
  var REMOTE_SIGN_IN = {
907
1052
  "claude-code": `Claude Code \u2014 in a session, run /mcp, pick "${SERVER_NAME}" and sign in`,
908
1053
  cursor: `Cursor \u2014 sign in when "${SERVER_NAME}" asks for it in Cursor's MCP settings`,
909
- codex: `Codex \u2014 signs in while setup connects it (its sign-in link is printed above); if that did not finish, run \`codex mcp login ${SERVER_NAME}\``
1054
+ codex: `Codex \u2014 signs in while setup connects it (its sign-in link is printed above); if that did not finish, run \`codex mcp login ${SERVER_NAME}\``,
1055
+ antigravity: `Antigravity \u2014 open Customizations \u203A Installed \u203A MCP Servers, choose Authenticate for "${SERVER_NAME}" and sign in`
910
1056
  };
911
1057
 
912
1058
  // src/core/harness/harnessDoc.ts