memshell-party-cli 0.2.2 → 0.3.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/index.d.ts CHANGED
@@ -263,6 +263,55 @@ 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";
267
+ interface OpLogEntry {
268
+ /** ISO timestamp. */
269
+ ts: string;
270
+ category: OpCategory;
271
+ /** What happened: "gen" | "probe" | "connect" | "exec" | "save" | "note" | "remove". */
272
+ action: string;
273
+ /** Saved `project/shell` reference, when the operation used one. */
274
+ targetName?: string;
275
+ url?: string;
276
+ tool?: string;
277
+ ok: boolean;
278
+ durationMs?: number;
279
+ /** Short human-readable success detail. */
280
+ detail?: string;
281
+ error?: string;
282
+ /** exec only: the command line. */
283
+ command?: string;
284
+ /** exec only: remote output, truncated to OUTPUT_LIMIT. */
285
+ output?: string;
286
+ outputTruncated?: boolean;
287
+ /** Extra structured fields (target meta, gen params — never credentials). */
288
+ meta?: Record<string, unknown>;
289
+ }
290
+ /** exec output is truncated to this many characters in the log. */
291
+ declare const OUTPUT_LIMIT = 2000;
292
+ declare function opLogPath(): string;
293
+ /** Append one entry. Never throws. */
294
+ declare function logOp(entry: Omit<OpLogEntry, "ts">): void;
295
+ interface OpFilter {
296
+ category?: OpCategory;
297
+ /**
298
+ * Match by saved target reference ("hw222" also matches "hw222/bh9060")
299
+ * or by a substring of the URL (e.g. a host).
300
+ */
301
+ target?: string;
302
+ /** Max entries returned (default 50). */
303
+ limit?: number;
304
+ }
305
+ /** Read entries matching the filter, newest first. */
306
+ declare function readOps(filter?: OpFilter): OpLogEntry[];
307
+ /** Truncate exec output for the log. */
308
+ declare function truncateOutput(output: string): {
309
+ output: string;
310
+ truncated: boolean;
311
+ };
312
+ /** One-line rendering for `memparty log`. */
313
+ declare function formatOp(e: OpLogEntry): string;
314
+
266
315
  declare function createMcpServer(client: MemPartyClient): McpServer;
267
316
  /** Start the MCP server over stdio. */
268
317
  declare function startMcpStdio(client: MemPartyClient): Promise<void>;
@@ -279,6 +328,18 @@ interface ConnectTestResult {
279
328
  error?: string;
280
329
  durationMs: number;
281
330
  }
331
+ interface ExecResult {
332
+ ok: boolean;
333
+ tool: ConnectTool;
334
+ url: string;
335
+ /** The command line as executed remotely. */
336
+ command: string;
337
+ /** Decoded remote stdout+stderr (present on success). */
338
+ output?: string;
339
+ /** Human-readable failure reason. */
340
+ error?: string;
341
+ durationMs: number;
342
+ }
282
343
  interface CommonConnectOptions {
283
344
  /**
284
345
  * MemShellParty shells are gated by a header check:
@@ -293,13 +354,111 @@ interface CommonConnectOptions {
293
354
  insecure?: boolean;
294
355
  }
295
356
 
357
+ /** A saved shell connection profile, stored inside a project. */
358
+ interface StoredShell {
359
+ url: string;
360
+ tool: ConnectTool;
361
+ pass?: string;
362
+ key?: string;
363
+ headerName?: string;
364
+ headerValue?: string;
365
+ extraHeaders?: Record<string, string>;
366
+ insecure?: boolean;
367
+ /** Free-form note for this shell (e.g. "DMZ 跳板机"). */
368
+ remark?: string;
369
+ createdAt: string;
370
+ updatedAt: string;
371
+ }
372
+ type ShellInput = Omit<StoredShell, "createdAt" | "updatedAt">;
373
+ /** A named group of shells with a remark and a category. */
374
+ interface StoredProject {
375
+ remark?: string;
376
+ category?: string;
377
+ createdAt: string;
378
+ updatedAt: string;
379
+ shells: Record<string, StoredShell>;
380
+ }
381
+ declare function targetStorePath(): string;
382
+ declare function listProjects(): Record<string, StoredProject>;
383
+ declare function getProject(name: string): StoredProject | null;
384
+ /** Create a project or update its remark/category (only given fields change). */
385
+ declare function saveProjectMeta(name: string, meta: {
386
+ remark?: string;
387
+ category?: string;
388
+ }): StoredProject;
389
+ /** Save a shell under `<project>/<shell>`; creates the project if needed. */
390
+ declare function saveShell(projectName: string, shellName: string, input: ShellInput): StoredShell;
391
+ /** Remove a whole project. Returns false when it did not exist. */
392
+ declare function removeProject(name: string): boolean;
393
+ /** Remove one shell from a project. Returns false when it did not exist. */
394
+ declare function removeShell(projectName: string, shellName: string): boolean;
395
+ /** Set or clear (empty string) a shell's remark. */
396
+ declare function saveShellMeta(projectName: string, shellName: string, meta: {
397
+ remark?: string;
398
+ }): StoredShell;
399
+ /** CLI/MCP flags that can override a stored shell's values. */
400
+ interface ConnectionFlags {
401
+ url?: string;
402
+ tool?: string;
403
+ pass?: string;
404
+ key?: string;
405
+ headerName?: string;
406
+ headerValue?: string;
407
+ extraHeaders?: Record<string, string>;
408
+ insecure?: boolean;
409
+ }
410
+ interface ResolvedConnection {
411
+ url: string;
412
+ tool: ConnectTool;
413
+ pass?: string;
414
+ key?: string;
415
+ headerName?: string;
416
+ headerValue?: string;
417
+ extraHeaders: Record<string, string>;
418
+ insecure?: boolean;
419
+ /** Canonical `project/shell` reference, when resolved from the store. */
420
+ targetName?: string;
421
+ }
422
+ /**
423
+ * Merge an optional saved shell reference (`<project>/<shell>` or a bare
424
+ * project holding exactly one shell) with explicit flags.
425
+ * Priority: explicit flag > stored value.
426
+ */
427
+ declare function resolveConnection(ref: string | undefined, flags: ConnectionFlags): ResolvedConnection;
428
+
296
429
  interface BehinderConnectOptions extends CommonConnectOptions {
297
430
  /** Request body encoding. Default: try base64, then raw AES bytes. */
298
431
  requestEncoding?: "base64" | "raw";
299
432
  }
300
433
  declare function testBehinder(url: string, pass: string, options?: BehinderConnectOptions): Promise<ConnectTestResult>;
434
+ /**
435
+ * Behinder command execution — uploads the `Cmd` payload class with its
436
+ * static `cmd` field filled in (same `Params.getParamedClass` mechanism as
437
+ * the Echo payload). The payload picks `cmd.exe /c` or `/bin/sh -c` itself
438
+ * based on `os.name`, so no OS detection is needed here.
439
+ * The response is the usual Behinder envelope: base64(AES({status, msg})),
440
+ * where `msg` is the base64-encoded command output (stdout then stderr).
441
+ */
442
+ declare function execBehinder(url: string, pass: string, command: string, options?: BehinderConnectOptions): Promise<ExecResult>;
301
443
 
302
444
  declare function testGodzilla(url: string, pass: string, key: string, options?: CommonConnectOptions): Promise<ConnectTestResult>;
445
+ interface GodzillaExecOptions extends CommonConnectOptions {
446
+ /**
447
+ * Remote OS family, used to pick the shell wrapper (`cmd.exe /c` vs
448
+ * `/bin/sh -c`). "auto" (default) asks the payload's `getBasicsInfo`
449
+ * first — one extra request per exec.
450
+ */
451
+ os?: "auto" | "windows" | "linux";
452
+ }
453
+ /**
454
+ * Godzilla command execution — invokes the payload's `execCommand` method.
455
+ *
456
+ * Same transport as the connect test (payload upload + cookie relay), then:
457
+ * methodName=execCommand, argsCount=N, arg-0..arg-(N-1) = argv
458
+ * The payload runs `Runtime.exec(argv)` (no shell of its own), so the
459
+ * command line is wrapped in `cmd.exe /c` or `/bin/sh -c` here.
460
+ */
461
+ declare function execGodzilla(url: string, pass: string, key: string, command: string, options?: GodzillaExecOptions): Promise<ExecResult>;
303
462
 
304
463
  type Suo5Mode = "auto" | "v2" | "v1";
305
464
  interface Suo5ConnectOptions extends CommonConnectOptions {
@@ -321,4 +480,4 @@ declare function testSuo5(url: string, options?: Suo5ConnectOptions): Promise<Co
321
480
 
322
481
  declare const CLI_VERSION: string;
323
482
 
324
- export { ApiError, type ApiErrorResponse, type BehinderConnectOptions, CLI_VERSION, type CommandConfigVO, type CommonConnectOptions, type ConnectTestResult, type ConnectTool, DEFAULT_API_URL, ENV_VAR, type FetchLike, type InjectorConfig, JDK_VERSIONS, type MainConfig, MemPartyClient, type MemPartyClientOptions, type MemShellGenerateRequest, type MemShellGenerateResponse, type MemShellOptions, type MemShellResult, 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 ServerConfig, type ShellConfig, type ShellToolConfig, type Suo5ConnectOptions, type Suo5Mode, type VersionInfo, buildMemShellRequest, buildProbeRequest, createMcpServer, emitPayload, marshalFrameBase64, marshalSuo5Map, resolveApiUrl, resolveJreVersion, shouldDecode, startMcpStdio, testBehinder, testGodzilla, testSuo5, unmarshalFrameBase64, unmarshalSuo5Map };
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 };