@xmtp/convos-cli 0.1.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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +572 -0
  3. package/bin/dev.js +4 -0
  4. package/bin/run.js +4 -0
  5. package/dist/baseCommand.d.ts +46 -0
  6. package/dist/baseCommand.js +171 -0
  7. package/dist/commands/agent/serve.d.ts +67 -0
  8. package/dist/commands/agent/serve.js +662 -0
  9. package/dist/commands/conversation/add-members.d.ts +19 -0
  10. package/dist/commands/conversation/add-members.js +39 -0
  11. package/dist/commands/conversation/consent-state.d.ts +18 -0
  12. package/dist/commands/conversation/consent-state.js +24 -0
  13. package/dist/commands/conversation/download-attachment.d.ts +28 -0
  14. package/dist/commands/conversation/download-attachment.js +164 -0
  15. package/dist/commands/conversation/explode.d.ts +24 -0
  16. package/dist/commands/conversation/explode.js +156 -0
  17. package/dist/commands/conversation/info.d.ts +22 -0
  18. package/dist/commands/conversation/info.js +79 -0
  19. package/dist/commands/conversation/invite.d.ts +26 -0
  20. package/dist/commands/conversation/invite.js +137 -0
  21. package/dist/commands/conversation/lock.d.ts +24 -0
  22. package/dist/commands/conversation/lock.js +98 -0
  23. package/dist/commands/conversation/members.d.ts +22 -0
  24. package/dist/commands/conversation/members.js +39 -0
  25. package/dist/commands/conversation/messages.d.ts +31 -0
  26. package/dist/commands/conversation/messages.js +141 -0
  27. package/dist/commands/conversation/permissions.d.ts +18 -0
  28. package/dist/commands/conversation/permissions.js +33 -0
  29. package/dist/commands/conversation/profiles.d.ts +22 -0
  30. package/dist/commands/conversation/profiles.js +80 -0
  31. package/dist/commands/conversation/remove-members.d.ts +19 -0
  32. package/dist/commands/conversation/remove-members.js +36 -0
  33. package/dist/commands/conversation/send-attachment.d.ts +30 -0
  34. package/dist/commands/conversation/send-attachment.js +187 -0
  35. package/dist/commands/conversation/send-reaction.d.ts +21 -0
  36. package/dist/commands/conversation/send-reaction.js +38 -0
  37. package/dist/commands/conversation/send-remote-attachment.d.ts +30 -0
  38. package/dist/commands/conversation/send-remote-attachment.js +96 -0
  39. package/dist/commands/conversation/send-reply.d.ts +32 -0
  40. package/dist/commands/conversation/send-reply.js +170 -0
  41. package/dist/commands/conversation/send-text.d.ts +24 -0
  42. package/dist/commands/conversation/send-text.js +64 -0
  43. package/dist/commands/conversation/stream.d.ts +24 -0
  44. package/dist/commands/conversation/stream.js +81 -0
  45. package/dist/commands/conversation/sync.d.ts +18 -0
  46. package/dist/commands/conversation/sync.js +25 -0
  47. package/dist/commands/conversation/update-consent.d.ts +19 -0
  48. package/dist/commands/conversation/update-consent.js +35 -0
  49. package/dist/commands/conversation/update-description.d.ts +19 -0
  50. package/dist/commands/conversation/update-description.js +28 -0
  51. package/dist/commands/conversation/update-name.d.ts +19 -0
  52. package/dist/commands/conversation/update-name.js +29 -0
  53. package/dist/commands/conversation/update-profile.d.ts +24 -0
  54. package/dist/commands/conversation/update-profile.js +97 -0
  55. package/dist/commands/conversations/create.d.ts +26 -0
  56. package/dist/commands/conversations/create.js +165 -0
  57. package/dist/commands/conversations/join.d.ts +27 -0
  58. package/dist/commands/conversations/join.js +232 -0
  59. package/dist/commands/conversations/list.d.ts +20 -0
  60. package/dist/commands/conversations/list.js +109 -0
  61. package/dist/commands/conversations/process-join-requests.d.ts +26 -0
  62. package/dist/commands/conversations/process-join-requests.js +261 -0
  63. package/dist/commands/conversations/sync.d.ts +19 -0
  64. package/dist/commands/conversations/sync.js +50 -0
  65. package/dist/commands/identity/create.d.ts +21 -0
  66. package/dist/commands/identity/create.js +56 -0
  67. package/dist/commands/identity/info.d.ts +22 -0
  68. package/dist/commands/identity/info.js +63 -0
  69. package/dist/commands/identity/list.d.ts +19 -0
  70. package/dist/commands/identity/list.js +59 -0
  71. package/dist/commands/identity/remove.d.ts +23 -0
  72. package/dist/commands/identity/remove.js +51 -0
  73. package/dist/commands/init.d.ts +16 -0
  74. package/dist/commands/init.js +91 -0
  75. package/dist/commands/reset.d.ts +17 -0
  76. package/dist/commands/reset.js +93 -0
  77. package/dist/help.d.ts +4 -0
  78. package/dist/help.js +31 -0
  79. package/dist/index.d.ts +9 -0
  80. package/dist/index.js +15 -0
  81. package/dist/utils/client.d.ts +8 -0
  82. package/dist/utils/client.js +58 -0
  83. package/dist/utils/config.d.ts +15 -0
  84. package/dist/utils/config.js +1 -0
  85. package/dist/utils/identities.d.ts +49 -0
  86. package/dist/utils/identities.js +92 -0
  87. package/dist/utils/invite.d.ts +70 -0
  88. package/dist/utils/invite.js +339 -0
  89. package/dist/utils/metadata.d.ts +39 -0
  90. package/dist/utils/metadata.js +180 -0
  91. package/dist/utils/mime.d.ts +2 -0
  92. package/dist/utils/mime.js +42 -0
  93. package/dist/utils/random.d.ts +5 -0
  94. package/dist/utils/random.js +19 -0
  95. package/dist/utils/upload.d.ts +14 -0
  96. package/dist/utils/upload.js +51 -0
  97. package/dist/utils/xmtp.d.ts +45 -0
  98. package/dist/utils/xmtp.js +298 -0
  99. package/oclif.manifest.json +5562 -0
  100. package/package.json +124 -0
  101. package/skills/convos-cli/SKILL.md +588 -0
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Base command for Convos CLI.
3
+ *
4
+ * Provides:
5
+ * - Common flags (--env, --json, --log-level, etc.)
6
+ * - output() and streamOutput() helpers
7
+ * - Config loading from .env files
8
+ *
9
+ * Convos adds: per-conversation identity resolution. Instead of a
10
+ * single wallet key, each conversation has its own identity with
11
+ * its own keys. Commands use getConvosConfig() + the identity store.
12
+ */
13
+ import { env } from "node:process";
14
+ import { createInterface } from "node:readline";
15
+ import { Command, Errors, Flags } from "@oclif/core";
16
+ import { formatHuman, isTTY, jsonStringify, VALID_ENVS, } from "./utils/xmtp.js";
17
+ export class ConvosBaseCommand extends Command {
18
+ /** Flags shared by all commands. */
19
+ static commonFlags = {
20
+ "env-file": Flags.string({
21
+ description: "Path to .env file",
22
+ helpValue: "<path>",
23
+ }),
24
+ env: Flags.option({
25
+ options: [...VALID_ENVS],
26
+ description: "XMTP environment",
27
+ })(),
28
+ "gateway-host": Flags.string({
29
+ description: "Custom gateway URL",
30
+ helpValue: "<url>",
31
+ }),
32
+ json: Flags.boolean({
33
+ description: "Format output as JSON",
34
+ }),
35
+ verbose: Flags.boolean({
36
+ description: "Show additional diagnostic information",
37
+ default: false,
38
+ }),
39
+ };
40
+ /** Full flag set for commands that create a client. */
41
+ static baseFlags = {
42
+ ...ConvosBaseCommand.commonFlags,
43
+ "log-level": Flags.option({
44
+ options: ["off", "error", "warn", "info", "debug", "trace"],
45
+ description: "Logging level",
46
+ })(),
47
+ "structured-logging": Flags.boolean({
48
+ description: "Enable structured JSON logging",
49
+ }),
50
+ "app-version": Flags.string({
51
+ description: "App version string",
52
+ helpValue: "<version>",
53
+ }),
54
+ };
55
+ #config = {};
56
+ jsonOutput = false;
57
+ verbose = false;
58
+ async init() {
59
+ await super.init();
60
+ const { flags } = await this.parse(this.constructor);
61
+ // Load config from .env file
62
+ // Priority: explicit --env-file > .env in cwd > ~/.convos/.env
63
+ const envFile = flags["env-file"];
64
+ if (envFile) {
65
+ try {
66
+ const { loadEnvFile } = await import("node:process");
67
+ const { resolve } = await import("node:path");
68
+ loadEnvFile(resolve(envFile));
69
+ }
70
+ catch (error) {
71
+ throw new Error(`Failed to load env file: ${envFile}`, {
72
+ cause: error,
73
+ });
74
+ }
75
+ }
76
+ else {
77
+ const { loadEnvFile } = await import("node:process");
78
+ const { resolve, join } = await import("node:path");
79
+ const { homedir } = await import("node:os");
80
+ try {
81
+ loadEnvFile(resolve(process.cwd(), ".env"));
82
+ }
83
+ catch {
84
+ try {
85
+ loadEnvFile(join(homedir(), ".convos", ".env"));
86
+ }
87
+ catch {
88
+ // Silently ignore if neither file exists
89
+ }
90
+ }
91
+ }
92
+ // Merge env vars with CLI flags (CLI flags take precedence)
93
+ this.#config = {
94
+ env: flags.env ??
95
+ (VALID_ENVS.includes(env.CONVOS_ENV)
96
+ ? env.CONVOS_ENV
97
+ : undefined) ??
98
+ "dev",
99
+ logLevel: flags["log-level"] ?? env.XMTP_LOG_LEVEL,
100
+ structuredLogging: flags["structured-logging"] ??
101
+ (env.XMTP_STRUCTURED_LOGGING === "true" ? true : undefined),
102
+ gatewayHost: flags["gateway-host"] ?? env.XMTP_GATEWAY_HOST,
103
+ appVersion: flags["app-version"] ?? env.XMTP_APP_VERSION,
104
+ uploadProvider: env.CONVOS_UPLOAD_PROVIDER,
105
+ uploadProviderToken: env.CONVOS_UPLOAD_PROVIDER_TOKEN,
106
+ uploadProviderGateway: env.CONVOS_UPLOAD_PROVIDER_GATEWAY,
107
+ };
108
+ this.jsonOutput = flags.json || env.CONVOS_JSON_OUTPUT === "true";
109
+ this.verbose = flags.verbose || env.CONVOS_VERBOSE === "true";
110
+ }
111
+ output(data) {
112
+ if (this.jsonOutput) {
113
+ this.log(jsonStringify(data, true));
114
+ }
115
+ else {
116
+ this.log(formatHuman(data));
117
+ }
118
+ }
119
+ streamOutput(data) {
120
+ if (this.jsonOutput) {
121
+ this.log(jsonStringify(data));
122
+ }
123
+ else {
124
+ this.log(formatHuman(data));
125
+ }
126
+ }
127
+ parseBigInt(value, flagName) {
128
+ if (value === undefined)
129
+ return undefined;
130
+ try {
131
+ return BigInt(value);
132
+ }
133
+ catch {
134
+ this.error(`Invalid value for --${flagName}: must be a numeric string`);
135
+ }
136
+ }
137
+ async confirmAction(message, force) {
138
+ if (force)
139
+ return;
140
+ if (!isTTY()) {
141
+ this.error("Cannot confirm in non-interactive terminal. Use --force to skip confirmation.");
142
+ }
143
+ const rl = createInterface({
144
+ input: process.stdin,
145
+ output: process.stderr,
146
+ });
147
+ const answer = await new Promise((resolve) => {
148
+ rl.question(`WARNING: ${message}\nAre you sure? (y/N) `, resolve);
149
+ });
150
+ rl.close();
151
+ if (answer.toLowerCase() !== "y") {
152
+ this.error("Operation cancelled");
153
+ }
154
+ }
155
+ getConvosConfig() {
156
+ return this.#config;
157
+ }
158
+ async run() {
159
+ // Override in subclasses
160
+ }
161
+ catch(error) {
162
+ if (error instanceof Errors.CLIError) {
163
+ error.showHelp = false;
164
+ throw error;
165
+ }
166
+ const cliError = new Errors.CLIError(error.message);
167
+ cliError.showHelp = true;
168
+ cliError.parse = { input: { argv: this.argv } };
169
+ throw cliError;
170
+ }
171
+ }
@@ -0,0 +1,67 @@
1
+ import { ConvosBaseCommand } from "../../baseCommand.js";
2
+ export default class AgentServe extends ConvosBaseCommand {
3
+ static description: string;
4
+ static examples: {
5
+ command: string;
6
+ description: string;
7
+ }[];
8
+ static args: {
9
+ id: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
10
+ };
11
+ static flags: {
12
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ permissions: import("@oclif/core/interfaces").OptionFlag<"all-members" | "admin-only", import("@oclif/core/interfaces").CustomOptions>;
15
+ "profile-name": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ identity: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ "no-invite": import("@oclif/core/interfaces").BooleanFlag<boolean>;
19
+ "log-level": import("@oclif/core/interfaces").OptionFlag<"off" | "error" | "warn" | "info" | "debug" | "trace" | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ "structured-logging": import("@oclif/core/interfaces").BooleanFlag<boolean>;
21
+ "app-version": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ "env-file": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
23
+ env: import("@oclif/core/interfaces").OptionFlag<"local" | "dev" | "production" | undefined, import("@oclif/core/interfaces").CustomOptions>;
24
+ "gateway-host": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
25
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
26
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
27
+ };
28
+ private streams;
29
+ private shutdownResolve?;
30
+ /**
31
+ * Emit a JSON event to stdout (one line).
32
+ */
33
+ private emit;
34
+ /**
35
+ * Emit an error event.
36
+ */
37
+ private emitError;
38
+ /**
39
+ * Process a single DM message as a potential join request.
40
+ */
41
+ private processJoinMessage;
42
+ /**
43
+ * Process any pending DM join requests (batch, on startup).
44
+ */
45
+ private processPendingJoinRequests;
46
+ /**
47
+ * Start streaming DM messages for join request processing.
48
+ */
49
+ private startJoinRequestStream;
50
+ /**
51
+ * Start streaming conversation messages.
52
+ */
53
+ private startMessageStream;
54
+ /**
55
+ * Read and process stdin commands.
56
+ */
57
+ private startStdinReader;
58
+ /**
59
+ * Handle a parsed stdin command.
60
+ */
61
+ private handleCommand;
62
+ /**
63
+ * Trigger graceful shutdown.
64
+ */
65
+ private shutdown;
66
+ run(): Promise<void>;
67
+ }