memshell-party-cli 0.3.0 → 0.3.2

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/index.d.ts CHANGED
@@ -263,7 +263,7 @@ declare const JDK_VERSIONS: Record<string, number>;
263
263
  */
264
264
  declare function resolveJreVersion(input: string | number | undefined): number | undefined;
265
265
 
266
- type OpCategory = "gen" | "probe" | "connect" | "exec" | "target";
266
+ type OpCategory = "gen" | "probe" | "connect" | "exec" | "save" | "note" | "remove";
267
267
  interface OpLogEntry {
268
268
  /** ISO timestamp. */
269
269
  ts: string;
@@ -419,6 +419,12 @@ interface ResolvedConnection {
419
419
  /** Canonical `project/shell` reference, when resolved from the store. */
420
420
  targetName?: string;
421
421
  }
422
+ /**
423
+ * Auto-save a verified connection under a derived `<host>/<tool>` name and
424
+ * return the canonical reference. A slot already pointing at the same URL is
425
+ * overwritten; a name taken by a different URL gets a numeric/port suffix.
426
+ */
427
+ declare function autoSaveShell(conn: ResolvedConnection): string;
422
428
  /**
423
429
  * Merge an optional saved shell reference (`<project>/<shell>` or a bare
424
430
  * project holding exactly one shell) with explicit flags.
@@ -480,4 +486,4 @@ declare function testSuo5(url: string, options?: Suo5ConnectOptions): Promise<Co
480
486
 
481
487
  declare const CLI_VERSION: string;
482
488
 
483
- export { ApiError, type ApiErrorResponse, type BehinderConnectOptions, CLI_VERSION, type CommandConfigVO, type CommonConnectOptions, type ConnectTestResult, type ConnectTool, type ConnectionFlags, DEFAULT_API_URL, ENV_VAR, type ExecResult, type FetchLike, type GodzillaExecOptions, type InjectorConfig, JDK_VERSIONS, type MainConfig, MemPartyClient, type MemPartyClientOptions, type MemShellGenerateRequest, type MemShellGenerateResponse, type MemShellOptions, type MemShellResult, OUTPUT_LIMIT, type OpCategory, type OpFilter, type OpLogEntry, type OutputOptions, type OutputResult, type PackerOption, type PackerTree, type ProbeConfig, type ProbeContent, type ProbeContentConfig, type ProbeMethod, type ProbeOptions, type ProbeShellGenerateRequest, type ProbeShellGenerateResponse, type ProbeShellResult, type ResolvedConnection, type ServerConfig, type ShellConfig, type ShellInput, type ShellToolConfig, type StoredProject, type StoredShell, type Suo5ConnectOptions, type Suo5Mode, type VersionInfo, buildMemShellRequest, buildProbeRequest, createMcpServer, emitPayload, execBehinder, execGodzilla, formatOp, getProject, listProjects, logOp, marshalFrameBase64, marshalSuo5Map, opLogPath, readOps, removeProject, removeShell, resolveApiUrl, resolveConnection, resolveJreVersion, saveProjectMeta, saveShell, saveShellMeta, shouldDecode, startMcpStdio, targetStorePath, testBehinder, testGodzilla, testSuo5, truncateOutput, unmarshalFrameBase64, unmarshalSuo5Map };
489
+ export { ApiError, type ApiErrorResponse, type BehinderConnectOptions, CLI_VERSION, type CommandConfigVO, type CommonConnectOptions, type ConnectTestResult, type ConnectTool, type ConnectionFlags, DEFAULT_API_URL, ENV_VAR, type ExecResult, type FetchLike, type GodzillaExecOptions, type InjectorConfig, JDK_VERSIONS, type MainConfig, MemPartyClient, type MemPartyClientOptions, type MemShellGenerateRequest, type MemShellGenerateResponse, type MemShellOptions, type MemShellResult, OUTPUT_LIMIT, type OpCategory, type OpFilter, type OpLogEntry, type OutputOptions, type OutputResult, type PackerOption, type PackerTree, type ProbeConfig, type ProbeContent, type ProbeContentConfig, type ProbeMethod, type ProbeOptions, type ProbeShellGenerateRequest, type ProbeShellGenerateResponse, type ProbeShellResult, type ResolvedConnection, type ServerConfig, type ShellConfig, type ShellInput, type ShellToolConfig, type StoredProject, type StoredShell, type Suo5ConnectOptions, type Suo5Mode, type VersionInfo, autoSaveShell, buildMemShellRequest, buildProbeRequest, createMcpServer, emitPayload, execBehinder, execGodzilla, formatOp, getProject, listProjects, logOp, marshalFrameBase64, marshalSuo5Map, opLogPath, readOps, removeProject, removeShell, resolveApiUrl, resolveConnection, resolveJreVersion, saveProjectMeta, saveShell, saveShellMeta, shouldDecode, startMcpStdio, targetStorePath, testBehinder, testGodzilla, testSuo5, truncateOutput, unmarshalFrameBase64, unmarshalSuo5Map };
package/dist/index.js CHANGED
@@ -1260,6 +1260,42 @@ function saveShellMeta(projectName, shellName, meta) {
1260
1260
  writeProjects(projects);
1261
1261
  return shell;
1262
1262
  }
1263
+ function sanitizeName(name) {
1264
+ const s = name.replace(/[^A-Za-z0-9._-]/g, "_");
1265
+ return /^[A-Za-z0-9]/.test(s) ? s : `x${s}`;
1266
+ }
1267
+ function autoSaveShell(conn) {
1268
+ let host = "target";
1269
+ let port = "";
1270
+ try {
1271
+ const u = new URL(conn.url);
1272
+ host = u.hostname || host;
1273
+ port = u.port;
1274
+ } catch {
1275
+ }
1276
+ const projectName = sanitizeName(host) || "target";
1277
+ const existing = getProject(projectName)?.shells ?? {};
1278
+ let shellName = Object.keys(existing).find(
1279
+ (n) => existing[n].url === conn.url && existing[n].tool === conn.tool
1280
+ );
1281
+ if (!shellName) {
1282
+ const base = sanitizeName(conn.tool) || "shell";
1283
+ shellName = base;
1284
+ if (existing[shellName]) shellName = port ? `${base}-${port}` : `${base}-2`;
1285
+ for (let i = 2; existing[shellName]; i++) shellName = `${base}-${i}`;
1286
+ }
1287
+ saveShell(projectName, shellName, {
1288
+ url: conn.url,
1289
+ tool: conn.tool,
1290
+ pass: conn.pass,
1291
+ key: conn.key,
1292
+ headerName: conn.headerName,
1293
+ headerValue: conn.headerValue,
1294
+ extraHeaders: Object.keys(conn.extraHeaders).length > 0 ? conn.extraHeaders : void 0,
1295
+ insecure: conn.insecure
1296
+ });
1297
+ return `${projectName}/${shellName}`;
1298
+ }
1263
1299
  function resolveConnection(ref, flags) {
1264
1300
  let stored;
1265
1301
  let targetName;
@@ -1269,7 +1305,7 @@ function resolveConnection(ref, flags) {
1269
1305
  let shellName = slash === -1 ? void 0 : ref.slice(slash + 1);
1270
1306
  const project = getProject(projectName);
1271
1307
  if (!project) {
1272
- throw new Error(`unknown project ${JSON.stringify(projectName)} \u2014 see 'memparty target list'`);
1308
+ throw new Error(`unknown project ${JSON.stringify(projectName)} \u2014 see 'memparty list'`);
1273
1309
  }
1274
1310
  if (!shellName) {
1275
1311
  const names = Object.keys(project.shells);
@@ -1582,7 +1618,7 @@ function createMcpServer(client) {
1582
1618
  "connect_test",
1583
1619
  {
1584
1620
  title: "Test shell connection",
1585
- description: "Test whether a deployed Godzilla / Behinder / suo5 shell is alive and the credentials work, by performing the tool's real protocol handshake. Pass a saved target `name`, or url+tool with the gate header (headerName/headerValue) from generate_memshell output for MemShellParty shells.",
1621
+ description: "Test whether a deployed Godzilla / Behinder / suo5 shell is alive and the credentials work, by performing the tool's real protocol handshake. Pass a saved target `name`, or url+tool with the gate header (headerName/headerValue) from generate_memshell output for MemShellParty shells. On success the profile is auto-saved and the canonical name returned as `savedAs` \u2014 reuse it as `name` in later calls.",
1586
1622
  inputSchema: connectInput
1587
1623
  },
1588
1624
  async (args) => {
@@ -1617,6 +1653,11 @@ function createMcpServer(client) {
1617
1653
  default:
1618
1654
  throw new Error(`unknown tool ${String(conn.tool)}`);
1619
1655
  }
1656
+ let savedAs;
1657
+ if (result.ok && conn.targetName === void 0) {
1658
+ savedAs = autoSaveShell(conn);
1659
+ conn.targetName = savedAs;
1660
+ }
1620
1661
  logOp({
1621
1662
  category: "connect",
1622
1663
  action: "connect",
@@ -1628,7 +1669,7 @@ function createMcpServer(client) {
1628
1669
  detail: result.detail,
1629
1670
  error: result.error
1630
1671
  });
1631
- return jsonContent(result);
1672
+ return jsonContent(savedAs !== void 0 ? { ...result, savedAs } : result);
1632
1673
  } catch (err) {
1633
1674
  return errorContent(err);
1634
1675
  }
@@ -1638,7 +1679,7 @@ function createMcpServer(client) {
1638
1679
  "exec_command",
1639
1680
  {
1640
1681
  title: "Execute command on shell",
1641
- description: "Execute a command line on a deployed Godzilla / Behinder shell and return its stdout+stderr. Uses the tool's real protocol (Godzilla execCommand method / Behinder Cmd payload). Run connect_test first to verify credentials; pass a saved target `name`, or url+tool with the same gate header (headerName/headerValue) for MemShellParty shells.",
1682
+ description: "Execute a command line on a deployed Godzilla / Behinder shell and return its stdout+stderr. Uses the tool's real protocol (Godzilla execCommand method / Behinder Cmd payload). Run connect_test first to verify credentials; pass a saved target `name`, or url+tool with the same gate header (headerName/headerValue) for MemShellParty shells. On success the profile is auto-saved and the canonical name returned as `savedAs`.",
1642
1683
  inputSchema: execInput
1643
1684
  },
1644
1685
  async (args) => {
@@ -1676,6 +1717,11 @@ function createMcpServer(client) {
1676
1717
  default:
1677
1718
  throw new Error(`exec supports godzilla | behinder (got ${String(conn.tool)})`);
1678
1719
  }
1720
+ let savedAs;
1721
+ if (result.ok && conn.targetName === void 0) {
1722
+ savedAs = autoSaveShell(conn);
1723
+ conn.targetName = savedAs;
1724
+ }
1679
1725
  const truncated = result.output !== void 0 ? truncateOutput(result.output) : null;
1680
1726
  logOp({
1681
1727
  category: "exec",
@@ -1690,7 +1736,7 @@ function createMcpServer(client) {
1690
1736
  outputTruncated: truncated?.truncated || void 0,
1691
1737
  error: result.error
1692
1738
  });
1693
- return jsonContent(result);
1739
+ return jsonContent(savedAs !== void 0 ? { ...result, savedAs } : result);
1694
1740
  } catch (err) {
1695
1741
  return errorContent(err);
1696
1742
  }
@@ -1722,7 +1768,7 @@ function createMcpServer(client) {
1722
1768
  remark: args.shellRemark
1723
1769
  });
1724
1770
  logOp({
1725
- category: "target",
1771
+ category: "save",
1726
1772
  action: "save",
1727
1773
  targetName: `${args.project}/${args.shell}`,
1728
1774
  url: args.url,
@@ -1761,7 +1807,7 @@ function createMcpServer(client) {
1761
1807
  }
1762
1808
  const updated2 = saveShellMeta(args.project, args.shell, { remark: args.remark });
1763
1809
  logOp({
1764
- category: "target",
1810
+ category: "note",
1765
1811
  action: "note",
1766
1812
  targetName: `${args.project}/${args.shell}`,
1767
1813
  ok: true,
@@ -1778,7 +1824,7 @@ function createMcpServer(client) {
1778
1824
  category: args.category
1779
1825
  });
1780
1826
  logOp({
1781
- category: "target",
1827
+ category: "note",
1782
1828
  action: "note",
1783
1829
  targetName: args.project,
1784
1830
  ok: true,
@@ -1828,7 +1874,7 @@ function createMcpServer(client) {
1828
1874
  const removed = args.shell ? removeShell(args.project, args.shell) : removeProject(args.project);
1829
1875
  if (!removed) throw new Error(`unknown target ${args.project}/${args.shell ?? ""}`);
1830
1876
  logOp({
1831
- category: "target",
1877
+ category: "remove",
1832
1878
  action: "remove",
1833
1879
  targetName: args.shell ? `${args.project}/${args.shell}` : args.project,
1834
1880
  ok: true,
@@ -1844,9 +1890,9 @@ function createMcpServer(client) {
1844
1890
  "log_list",
1845
1891
  {
1846
1892
  title: "List operation log",
1847
- description: "Read the global operation log (every gen/probe/connect/exec/target op), newest first. Filter by category and/or target.",
1893
+ description: "Read the global operation log (every gen/probe/connect/exec/save/note/remove op), newest first. Filter by category and/or target.",
1848
1894
  inputSchema: {
1849
- category: z.enum(["gen", "probe", "connect", "exec", "target"]).optional().describe("operation category"),
1895
+ category: z.enum(["gen", "probe", "connect", "exec", "save", "note", "remove"]).optional().describe("operation category"),
1850
1896
  target: z.string().optional().describe("project name, project/shell, or a URL substring (e.g. host)"),
1851
1897
  limit: z.number().optional().describe("max entries (default 50)")
1852
1898
  }
@@ -1879,6 +1925,7 @@ export {
1879
1925
  JDK_VERSIONS,
1880
1926
  MemPartyClient,
1881
1927
  OUTPUT_LIMIT,
1928
+ autoSaveShell,
1882
1929
  buildMemShellRequest,
1883
1930
  buildProbeRequest,
1884
1931
  createMcpServer,