@docyrus/docyrus 0.0.57 → 0.0.59

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.59",
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
@@ -45696,6 +45709,7 @@ async function createAgentServer(params) {
45696
45709
  let devProcess = null;
45697
45710
  let devUrl = null;
45698
45711
  const DEV_URL_PATTERN = /https?:\/\/(?:localhost|127\.0\.0\.1):\d+/;
45712
+ const ANSI_ESCAPE_PATTERN = /\x1b\[[0-9;]*[a-zA-Z]/g;
45699
45713
  const DEV_STARTUP_TIMEOUT_MS = 3e4;
45700
45714
  const DEV_PROBE_TIMEOUT_MS = 3e3;
45701
45715
  async function probeUrl(url2) {
@@ -45858,9 +45872,19 @@ async function createAgentServer(params) {
45858
45872
  }
45859
45873
  return c.json({ status: "stopped", url: null, managed: false, project, env, docyrusCliVersion });
45860
45874
  });
45861
- app.post("/api/env/serve", (c) => {
45875
+ app.post("/api/env/serve", async (c) => {
45862
45876
  if (devProcess && devProcess.exitCode === null) {
45863
- return c.json({ status: "running", url: devUrl });
45877
+ if (!devUrl) {
45878
+ const detected = await detectDevPort(context.cwd);
45879
+ if (detected) {
45880
+ const probeTarget = `http://localhost:${detected}`;
45881
+ const httpStatus = await probeUrl(probeTarget);
45882
+ if (httpStatus !== null) {
45883
+ devUrl = probeTarget;
45884
+ }
45885
+ }
45886
+ }
45887
+ return c.json({ status: devUrl ? "running" : "starting", url: devUrl });
45864
45888
  }
45865
45889
  devUrl = null;
45866
45890
  const proc = (0, import_node_child_process3.spawn)("pnpm", ["dev"], {
@@ -45880,7 +45904,8 @@ async function createAgentServer(params) {
45880
45904
  resolveResponse(response);
45881
45905
  }
45882
45906
  function checkOutput(text3) {
45883
- const match2 = text3.match(DEV_URL_PATTERN);
45907
+ const clean = text3.replace(ANSI_ESCAPE_PATTERN, "");
45908
+ const match2 = clean.match(DEV_URL_PATTERN);
45884
45909
  if (match2) {
45885
45910
  devUrl = match2[0];
45886
45911
  settle(c.json({ status: "running", url: devUrl }));
@@ -45898,7 +45923,20 @@ async function createAgentServer(params) {
45898
45923
  proc.on("error", (err2) => {
45899
45924
  settle(c.json({ status: "error", error: err2.message }, 500));
45900
45925
  });
45901
- setTimeout(() => {
45926
+ setTimeout(async () => {
45927
+ if (resolved) {
45928
+ return;
45929
+ }
45930
+ const detected = await detectDevPort(context.cwd);
45931
+ if (detected) {
45932
+ const probeTarget = `http://localhost:${detected}`;
45933
+ const httpStatus = await probeUrl(probeTarget);
45934
+ if (httpStatus !== null) {
45935
+ devUrl = probeTarget;
45936
+ settle(c.json({ status: "running", url: devUrl }));
45937
+ return;
45938
+ }
45939
+ }
45902
45940
  settle(c.json({ status: "error", error: stderr || "Timed out waiting for dev server URL" }, 500));
45903
45941
  }, DEV_STARTUP_TIMEOUT_MS);
45904
45942
  });
@@ -46313,8 +46351,7 @@ async function createAgentServer(params) {
46313
46351
  }
46314
46352
  const cliArgs = buildCliArgs(pathSegments, query, body2);
46315
46353
  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], {
46354
+ const proc = (0, import_node_child_process3.spawn)("docyrus", [...CLI_GLOBAL ? ["-g"] : [], ...cliArgs], {
46318
46355
  cwd: context.cwd,
46319
46356
  stdio: ["ignore", "pipe", "pipe"],
46320
46357
  timeout: CLI_TIMEOUT_MS
@@ -46329,10 +46366,16 @@ async function createAgentServer(params) {
46329
46366
  });
46330
46367
  proc.on("close", (code) => {
46331
46368
  if (code !== 0) {
46369
+ let parsedStdout;
46370
+ try {
46371
+ parsedStdout = JSON.parse(stdout);
46372
+ } catch {
46373
+ }
46332
46374
  resolveResponse(c.json({
46333
46375
  error: stderr.trim() || `Command exited with code ${code}`,
46334
46376
  command: `docyrus ${cliArgs.join(" ")}`,
46335
- exitCode: code
46377
+ exitCode: code,
46378
+ ...parsedStdout !== void 0 ? { detail: parsedStdout } : stdout.trim() ? { output: stdout.trim() } : {}
46336
46379
  }, 500));
46337
46380
  return;
46338
46381
  }