noninteractive 0.3.15 → 0.3.17

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.
@@ -347,7 +347,7 @@ var init_daemon = __esm(() => {
347
347
  var require_package = __commonJS((exports, module) => {
348
348
  module.exports = {
349
349
  name: "noninteractive",
350
- version: "0.3.15",
350
+ version: "0.3.17",
351
351
  type: "module",
352
352
  bin: {
353
353
  noninteractive: "./bin/noninteractive.js"
@@ -512,10 +512,21 @@ function getSelfCommand() {
512
512
  function deriveSessionName(cmd, args) {
513
513
  const parts = [cmd, ...args];
514
514
  let i = 0;
515
- if (parts[i] === "npx" || parts[i] === "bunx")
516
- i++;
517
- while (i < parts.length && parts[i].startsWith("-"))
518
- i++;
515
+ while (i < parts.length) {
516
+ if (parts[i] === "npx" || parts[i] === "bunx") {
517
+ i++;
518
+ continue;
519
+ }
520
+ if (parts[i] === "--") {
521
+ i++;
522
+ continue;
523
+ }
524
+ if (parts[i].startsWith("-")) {
525
+ i++;
526
+ continue;
527
+ }
528
+ break;
529
+ }
519
530
  const name = parts[i] || cmd;
520
531
  const stripped = name.replace(/(?<=.)@[^/].*$/, "");
521
532
  return (stripped || name).replace(/^@[^/]+\//, "").replace(/[^a-zA-Z0-9_-]/g, "");
@@ -523,29 +534,28 @@ function deriveSessionName(cmd, args) {
523
534
  async function start(cmdArgs, noOpen = false) {
524
535
  const executable = cmdArgs[0];
525
536
  const args = cmdArgs.slice(1);
526
- const name = deriveSessionName(executable, args);
527
- const sock = socketPath(name);
528
- try {
529
- const res = await sendMessage(sock, { action: "read" });
530
- if (res.ok) {
531
- process.stdout.write(stripAnsi(res.output ?? ""));
532
- handleUrls(res, noOpen);
533
- if (res.exited) {
534
- console.log(`
535
- [session '${name}' already exists but exited ${res.exitCode} \u2014 stopping it]`);
536
- try {
537
- await sendMessage(sock, { action: "stop" });
538
- } catch {}
539
- } else {
540
- console.log(`
541
- [session '${name}' already running \u2014 read the output above, then use:]`);
542
- console.log(` npx noninteractive send ${name} "<text>" --wait # send and wait for response`);
543
- console.log(` npx noninteractive read ${name} --wait # wait for new output`);
544
- console.log(` npx noninteractive stop ${name} # stop the session`);
545
- return;
537
+ const baseName = deriveSessionName(executable, args);
538
+ let name = baseName;
539
+ let suffix = 1;
540
+ while (true) {
541
+ const sock2 = socketPath(name);
542
+ try {
543
+ const res = await sendMessage(sock2, { action: "read" });
544
+ if (res.ok) {
545
+ if (res.exited) {
546
+ try {
547
+ await sendMessage(sock2, { action: "stop" });
548
+ } catch {}
549
+ break;
550
+ }
551
+ suffix++;
552
+ name = `${baseName}-${suffix}`;
553
+ continue;
546
554
  }
547
- }
548
- } catch {}
555
+ } catch {}
556
+ break;
557
+ }
558
+ const sock = socketPath(name);
549
559
  ensureSessionsDir();
550
560
  try {
551
561
  const { unlinkSync: unlinkSync2 } = await import("fs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noninteractive",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "noninteractive": "./bin/noninteractive.js"