@rynx-ai/cli 0.1.11-beta.14 → 0.1.11-beta.15

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.
@@ -1,14 +1,25 @@
1
1
  import { createInterface } from "node:readline/promises";
2
- import { cancelResidentPluginInstallation, commitResidentPluginInstallation, invokeResidentPluginCommand, listResidentPlugins, prepareResidentPluginInstallation, setResidentPluginEnabled, uninstallResidentPlugin, } from "../control-client.js";
2
+ import { cancelResidentPluginInstallation, commitResidentPluginInstallation, prepareResidentPluginInstallation, setResidentPluginEnabled, uninstallResidentPlugin, } from "../control-client.js";
3
3
  import { fail } from "./errors.js";
4
- const PLUGIN_STDIN_MAX_BYTES = 256 * 1024;
5
4
  const PLUGIN_DIGEST_PATTERN = /^sha256-[A-Za-z0-9+/]{43}={0,2}$/;
6
5
  const CANONICAL_PLUGIN_ID_PATTERN = /^[a-z][a-z0-9-]{0,62}@[a-z0-9][a-z0-9-]{0,62}(?:\/[a-z0-9][a-z0-9._-]{0,99})?$/;
6
+ const PLUGIN_USAGE = `Usage: rynx plugin <command|plugin-id>
7
+
8
+ Management:
9
+ list
10
+ install <source|plugin@market> [--force] [--expect-digest <sha256-...>]
11
+ update <plugin@market> [--expect-digest <sha256-...>]
12
+ enable|disable|uninstall <plugin@market>
13
+
14
+ Plugin commands:
15
+ <plugin-id> <command> [args...]
16
+ <plugin-id> --help`;
7
17
  export async function runPluginManageCommand(args, options = {}) {
8
18
  const [subcommand, pluginId] = args;
9
19
  switch (subcommand) {
10
20
  case "list": {
11
- const plugins = await listResidentPlugins();
21
+ const { listInstalledPlugins } = await import("@rynx-ai/daemon/plugin-cli");
22
+ const plugins = listInstalledPlugins();
12
23
  console.log("Plugins");
13
24
  if (plugins.length === 0) {
14
25
  console.log(" (none)");
@@ -126,23 +137,50 @@ export async function runPluginCommand(args) {
126
137
  const [pluginId, command] = args;
127
138
  if (!pluginId)
128
139
  fail("plugin: missing plugin id");
140
+ if (pluginId === "--help" || pluginId === "-h" || pluginId === "help") {
141
+ console.log(PLUGIN_USAGE);
142
+ return 0;
143
+ }
129
144
  if (["list", "install", "update", "uninstall", "enable", "disable"].includes(pluginId)) {
130
145
  return runPluginManageCommand(args);
131
146
  }
132
147
  if (!command)
133
148
  fail(`plugin ${pluginId}: missing command`);
134
- const stdin = process.stdin.isTTY
135
- ? undefined
136
- : await readStdinBounded(PLUGIN_STDIN_MAX_BYTES);
137
- const result = await invokeResidentPluginCommand(pluginId, args.slice(1), stdin === undefined ? {} : { stdin });
138
- if (result.stdout)
139
- process.stdout.write(result.stdout);
140
- if (result.stderr)
141
- process.stderr.write(result.stderr);
142
- if (result.truncated) {
143
- process.stderr.write("rynx: plugin command output was truncated by the daemon\n");
149
+ const pluginCli = await import("@rynx-ai/daemon/plugin-cli");
150
+ if (command === "--help" || command === "-h") {
151
+ console.log(pluginCli.installedPluginCommandUsage(pluginId));
152
+ return 0;
153
+ }
154
+ return runPluginCliWithForwardedSignals((signal) => pluginCli.runPluginCliCommand(pluginId, args.slice(1), {
155
+ stdio: "inherit",
156
+ signal,
157
+ }));
158
+ }
159
+ async function runPluginCliWithForwardedSignals(run) {
160
+ const controller = new AbortController();
161
+ let interruptedBy;
162
+ const interrupt = (signal) => {
163
+ interruptedBy ??= signal;
164
+ if (!controller.signal.aborted) {
165
+ controller.abort(new Error(`plugin command interrupted by ${signal}`));
166
+ }
167
+ };
168
+ const onSigint = () => interrupt("SIGINT");
169
+ const onSigterm = () => interrupt("SIGTERM");
170
+ process.on("SIGINT", onSigint);
171
+ process.on("SIGTERM", onSigterm);
172
+ try {
173
+ return (await run(controller.signal)).code;
174
+ }
175
+ catch (error) {
176
+ if (interruptedBy)
177
+ return interruptedBy === "SIGINT" ? 130 : 143;
178
+ throw error;
179
+ }
180
+ finally {
181
+ process.off("SIGINT", onSigint);
182
+ process.off("SIGTERM", onSigterm);
144
183
  }
145
- return result.code;
146
184
  }
147
185
  function parseInstallationArgs(operation, args) {
148
186
  const target = args[0];
@@ -219,15 +257,3 @@ async function confirmInTerminal(message) {
219
257
  prompt.close();
220
258
  }
221
259
  }
222
- async function readStdinBounded(maxBytes) {
223
- const chunks = [];
224
- let bytes = 0;
225
- for await (const chunk of process.stdin) {
226
- const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
227
- bytes += value.byteLength;
228
- if (bytes > maxBytes)
229
- fail(`plugin stdin exceeds ${maxBytes} bytes`);
230
- chunks.push(value);
231
- }
232
- return Buffer.concat(chunks, bytes).toString("utf8");
233
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rynx-ai/cli",
3
- "version": "0.1.11-beta.14",
3
+ "version": "0.1.11-beta.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/rynx-ai/rynx.git",
@@ -51,11 +51,11 @@
51
51
  "dependencies": {
52
52
  "@clack/prompts": "^1.6.0",
53
53
  "ws": "^8.21.0",
54
- "@rynx-ai/browser-cdp": "0.1.11-beta.14",
55
- "@rynx-ai/daemon": "0.1.11-beta.14",
56
- "@rynx-ai/core": "0.1.11-beta.14",
57
- "@rynx-ai/emulator": "0.1.11-beta.14",
58
- "@rynx-ai/protocol": "0.1.11-beta.14"
54
+ "@rynx-ai/browser-cdp": "0.1.11-beta.15",
55
+ "@rynx-ai/core": "0.1.11-beta.15",
56
+ "@rynx-ai/daemon": "0.1.11-beta.15",
57
+ "@rynx-ai/emulator": "0.1.11-beta.15",
58
+ "@rynx-ai/protocol": "0.1.11-beta.15"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/ws": "^8.18.1"