@docyrus/docyrus 0.0.57 → 0.0.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docyrus/docyrus",
3
- "version": "0.0.57",
3
+ "version": "0.0.58",
4
4
  "private": false,
5
5
  "description": "Docyrus API CLI",
6
6
  "main": "./main.js",
package/server-loader.js CHANGED
@@ -43378,23 +43378,39 @@ function attachPtyBridge(server, authToken) {
43378
43378
  return;
43379
43379
  }
43380
43380
  }
43381
+ const origin = request.headers.origin ?? "unknown";
43382
+ const remoteAddr = request.socket?.remoteAddress ?? "unknown";
43383
+ process.stderr.write(` PTY WebSocket upgrade from ${remoteAddr} (origin: ${origin})
43384
+ `);
43381
43385
  wss.handleUpgrade(request, socket, head, (ws) => {
43382
43386
  wss.emit("connection", ws, request);
43383
43387
  });
43384
43388
  });
43385
43389
  wss.on("connection", (ws) => {
43386
43390
  const shell = getDefaultShell();
43387
- const ptyProcess = pty.spawn(shell, [], {
43388
- name: "xterm-256color",
43389
- cols: DEFAULT_COLS,
43390
- rows: DEFAULT_ROWS,
43391
- cwd: process.cwd(),
43392
- env: {
43393
- ...process.env,
43394
- TERM: "xterm-256color",
43395
- COLORTERM: "truecolor"
43391
+ let ptyProcess;
43392
+ try {
43393
+ ptyProcess = pty.spawn(shell, [], {
43394
+ name: "xterm-256color",
43395
+ cols: DEFAULT_COLS,
43396
+ rows: DEFAULT_ROWS,
43397
+ cwd: process.cwd(),
43398
+ env: {
43399
+ ...process.env,
43400
+ TERM: "xterm-256color",
43401
+ COLORTERM: "truecolor"
43402
+ }
43403
+ });
43404
+ } catch (err2) {
43405
+ const message = err2 instanceof Error ? err2.message : String(err2);
43406
+ process.stderr.write(` PTY spawn failed (${shell}): ${message}
43407
+ `);
43408
+ if (ws.readyState === import_websocket.default.OPEN) {
43409
+ ws.send(JSON.stringify({ type: "error", message: `Failed to spawn shell: ${message}` }));
43410
+ ws.close();
43396
43411
  }
43397
- });
43412
+ return;
43413
+ }
43398
43414
  const onData = ptyProcess.onData((data) => {
43399
43415
  if (ws.readyState === import_websocket.default.OPEN) {
43400
43416
  ws.send(data);
@@ -45657,14 +45673,11 @@ async function createAgentServer(params) {
45657
45673
  return c.json({ error: message }, status);
45658
45674
  }
45659
45675
  });
45660
- const CLI_EXEC = process.env.DOCYRUS_CLI_EXECUTABLE || process.execPath;
45661
- const CLI_ENTRY = process.env.DOCYRUS_CLI_ENTRY || (0, import_node_path22.resolve)(process.argv[1] ? (0, import_node_path22.join)(process.argv[1], "..") : __dirname, "main.js");
45662
- const CLI_SCOPE = process.env.DOCYRUS_CLI_SCOPE;
45676
+ const CLI_GLOBAL = process.env.DOCYRUS_CLI_SCOPE === "global";
45663
45677
  const CLI_TIMEOUT_MS = 3e4;
45664
45678
  function runCliCommand(args2) {
45665
45679
  return new Promise((resolveResult) => {
45666
- const scopeArgs = CLI_SCOPE ? ["--scope", CLI_SCOPE] : [];
45667
- const proc = (0, import_node_child_process3.spawn)(CLI_EXEC, [CLI_ENTRY, ...scopeArgs, ...args2, "--json"], {
45680
+ const proc = (0, import_node_child_process3.spawn)("docyrus", [...CLI_GLOBAL ? ["-g"] : [], ...args2, "--json"], {
45668
45681
  cwd: context.cwd,
45669
45682
  stdio: ["ignore", "pipe", "pipe"],
45670
45683
  timeout: CLI_TIMEOUT_MS
@@ -46313,8 +46326,7 @@ async function createAgentServer(params) {
46313
46326
  }
46314
46327
  const cliArgs = buildCliArgs(pathSegments, query, body2);
46315
46328
  return new Promise((resolveResponse) => {
46316
- const scopeArgs = CLI_SCOPE ? ["--scope", CLI_SCOPE] : [];
46317
- const proc = (0, import_node_child_process3.spawn)(CLI_EXEC, [CLI_ENTRY, ...scopeArgs, ...cliArgs], {
46329
+ const proc = (0, import_node_child_process3.spawn)("docyrus", [...CLI_GLOBAL ? ["-g"] : [], ...cliArgs], {
46318
46330
  cwd: context.cwd,
46319
46331
  stdio: ["ignore", "pipe", "pipe"],
46320
46332
  timeout: CLI_TIMEOUT_MS
@@ -46329,10 +46341,16 @@ async function createAgentServer(params) {
46329
46341
  });
46330
46342
  proc.on("close", (code) => {
46331
46343
  if (code !== 0) {
46344
+ let parsedStdout;
46345
+ try {
46346
+ parsedStdout = JSON.parse(stdout);
46347
+ } catch {
46348
+ }
46332
46349
  resolveResponse(c.json({
46333
46350
  error: stderr.trim() || `Command exited with code ${code}`,
46334
46351
  command: `docyrus ${cliArgs.join(" ")}`,
46335
- exitCode: code
46352
+ exitCode: code,
46353
+ ...parsedStdout !== void 0 ? { detail: parsedStdout } : stdout.trim() ? { output: stdout.trim() } : {}
46336
46354
  }, 500));
46337
46355
  return;
46338
46356
  }