noninteractive 0.3.24 → 0.3.26

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.
@@ -194,8 +194,10 @@ function runDaemon(sessionName, executable, args) {
194
194
  }
195
195
  const binDir = sessionBinDir2(sessionName);
196
196
  const ptyBridge = getPtyBridge();
197
+ const spawnCwd = process.env.NI_CWD || process.cwd();
197
198
  const proc = spawn(ptyBridge, [executable, ...args], {
198
199
  stdio: ["pipe", "pipe", "pipe"],
200
+ cwd: spawnCwd,
199
201
  env: {
200
202
  ...process.env,
201
203
  TERM: "xterm-256color",
@@ -377,7 +379,7 @@ var init_daemon = __esm(() => {
377
379
  var require_package = __commonJS((exports, module) => {
378
380
  module.exports = {
379
381
  name: "noninteractive",
380
- version: "0.3.24",
382
+ version: "0.3.26",
381
383
  type: "module",
382
384
  bin: {
383
385
  noninteractive: "./bin/noninteractive.js"
@@ -477,15 +479,18 @@ commands:
477
479
  read <session> [--wait] [--timeout N] read terminal output (--wait blocks until new output)
478
480
  stop <session> stop a session
479
481
  list show active sessions
480
- start <cmd> [args...] explicit start (for non-npx commands)
482
+ start [--name N] [--cwd D] <cmd> [args...] explicit start (for non-npx commands)
481
483
 
482
484
  flags:
485
+ --name <session> set session name (default: auto-derived from tool name)
486
+ --cwd <dir> set working directory for the command
483
487
  --no-wait fire-and-forget mode for send (don't wait for output)
484
488
  --wait, -w block until new output appears (for read)
485
489
  --timeout <ms> max wait time in ms (default: 30000)
486
490
  --no-open don't auto-open URLs in browser (still shown in output)
487
491
 
488
492
  the session name is auto-derived from the tool (e.g. "workos" \u2192 session "workos").
493
+ use --name to override, --cwd to set the working directory.
489
494
 
490
495
  text is sent raw \u2014 no auto-appended enter. escape sequences are parsed:
491
496
  \\r = Enter, \\n = newline, \\t = tab, \\x1b = escape (for arrow keys)
@@ -644,10 +649,10 @@ function deriveSessionName(cmd, args) {
644
649
  const stripped = name.replace(/(?<=.)@[^/].*$/, "");
645
650
  return (stripped || name).replace(/^@[^/]+\//, "").replace(/[^a-zA-Z0-9_-]/g, "");
646
651
  }
647
- async function start(cmdArgs, noOpen = false) {
652
+ async function start(cmdArgs, noOpen = false, sessionName, cwd) {
648
653
  const executable = cmdArgs[0];
649
654
  const args = cmdArgs.slice(1);
650
- const baseName = deriveSessionName(executable, args);
655
+ const baseName = sessionName || deriveSessionName(executable, args);
651
656
  let name = baseName;
652
657
  let suffix = 1;
653
658
  while (true) {
@@ -677,7 +682,8 @@ async function start(cmdArgs, noOpen = false) {
677
682
  const self = getSelfCommand();
678
683
  const child = spawn2(self[0], [...self.slice(1), "__daemon__", name, executable, ...args], {
679
684
  detached: true,
680
- stdio: "ignore"
685
+ stdio: "ignore",
686
+ ...cwd ? { env: { ...process.env, NI_CWD: cwd } } : {}
681
687
  });
682
688
  child.unref();
683
689
  for (let i = 0;i < 50; i++) {
@@ -828,15 +834,30 @@ async function main() {
828
834
  const cmd = args[0];
829
835
  switch (cmd) {
830
836
  case "start": {
831
- const startArgs = args.slice(1).filter((a) => a !== "--no-open");
832
- const noOpen = args.includes("--no-open");
833
- if (startArgs.length < 1) {
834
- console.error(`usage: noninteractive start <cmd> [args...]
837
+ const startArgs = args.slice(1);
838
+ const noOpen = startArgs.includes("--no-open");
839
+ let sessionName;
840
+ let cwd;
841
+ const nameIdx = startArgs.indexOf("--name");
842
+ if (nameIdx !== -1) {
843
+ sessionName = startArgs[nameIdx + 1];
844
+ startArgs.splice(nameIdx, 2);
845
+ }
846
+ const cwdIdx = startArgs.indexOf("--cwd");
847
+ if (cwdIdx !== -1) {
848
+ cwd = startArgs[cwdIdx + 1];
849
+ startArgs.splice(cwdIdx, 2);
850
+ }
851
+ const filtered = startArgs.filter((a) => a !== "--no-open");
852
+ if (filtered.length < 1) {
853
+ console.error(`usage: noninteractive start [--name <session>] [--cwd <dir>] <cmd> [args...]
835
854
 
836
- example: npx noninteractive start npx vercel`);
855
+ examples:
856
+ npx noninteractive start npx eslint --init
857
+ npx noninteractive start --name myeslint --cwd /tmp/project npx eslint --init`);
837
858
  process.exit(1);
838
859
  }
839
- return start(startArgs, noOpen);
860
+ return start(filtered, noOpen, sessionName, cwd);
840
861
  }
841
862
  case "read": {
842
863
  const readArgs = args.slice(1);
@@ -899,10 +920,33 @@ example: npx noninteractive stop vercel`);
899
920
  console.log(HELP);
900
921
  break;
901
922
  default: {
902
- const noOpen = args.includes("--no-open");
903
- const filteredArgs = args.filter((a) => a !== "--no-open");
923
+ let sessionName;
924
+ let cwd;
925
+ const mutableArgs = [...args];
926
+ const nameIdx = mutableArgs.indexOf("--name");
927
+ if (nameIdx !== -1) {
928
+ sessionName = mutableArgs[nameIdx + 1];
929
+ mutableArgs.splice(nameIdx, 2);
930
+ }
931
+ const cwdIdx = mutableArgs.indexOf("--cwd");
932
+ if (cwdIdx !== -1) {
933
+ cwd = mutableArgs[cwdIdx + 1];
934
+ mutableArgs.splice(cwdIdx, 2);
935
+ }
936
+ const wrongFlags = ["--dir", "--session"];
937
+ const firstPositional = mutableArgs.findIndex((a) => !a.startsWith("-") && a !== "--");
938
+ const flagsBefore = firstPositional === -1 ? mutableArgs : mutableArgs.slice(0, firstPositional);
939
+ const wrongFlag = flagsBefore.find((a) => wrongFlags.includes(a.split("=")[0]));
940
+ if (wrongFlag) {
941
+ console.error(`unknown flag: ${wrongFlag}
942
+
943
+ hint: use --name for session name, --cwd for working directory.`);
944
+ process.exit(1);
945
+ }
946
+ const noOpen = mutableArgs.includes("--no-open");
947
+ const filteredArgs = mutableArgs.filter((a) => a !== "--no-open");
904
948
  console.log(`[installing and running: npx ${filteredArgs.join(" ")}]`);
905
- return start(["npx", "--yes", ...filteredArgs], noOpen);
949
+ return start(["npx", "--yes", ...filteredArgs], noOpen, sessionName, cwd);
906
950
  }
907
951
  }
908
952
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noninteractive",
3
- "version": "0.3.24",
3
+ "version": "0.3.26",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "noninteractive": "./bin/noninteractive.js"