@whyvix/remote 0.3.15 → 0.3.16

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": "@whyvix/remote",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [
@@ -104,8 +104,14 @@ export class ProcessManager {
104
104
  spawnCommand=selected;
105
105
  }
106
106
  if(this.platform==="win32"&&(executable.name==="npm"||executable.name==="npx")) {
107
- const cli=path.join(path.dirname(this.nodeExecPath),"node_modules","npm","bin",executable.name==="npm"?"npm-cli.js":"npx-cli.js");
108
- spawnCommand=this.nodeExecPath; args=[cli,...args];
107
+ const selectedDir=executableMatch!=null?path.dirname(spawnCommand):path.dirname(this.nodeExecPath);
108
+ const selectedNode=path.join(selectedDir,"node.exe");
109
+ const selectedCli=path.join(selectedDir,"node_modules","npm","bin",executable.name==="npm"?"npm-cli.js":"npx-cli.js");
110
+ const fallbackCli=path.join(path.dirname(this.nodeExecPath),"node_modules","npm","bin",executable.name==="npm"?"npm-cli.js":"npx-cli.js");
111
+ if(executableMatch!=null){
112
+ try{if(!fs.statSync(selectedNode).isFile()||!fs.statSync(selectedCli).isFile())fail("LOCAL_EXEC_NOT_ALLOWED","Selected Windows command shim does not have an approved adjacent Node launcher");}catch(error){if(error?.code==="LOCAL_EXEC_NOT_ALLOWED")throw error;fail("LOCAL_EXEC_NOT_ALLOWED","Selected Windows command shim does not have an approved adjacent Node launcher");}
113
+ spawnCommand=selectedNode;args=[selectedCli,...args];
114
+ }else{spawnCommand=this.nodeExecPath;args=[fallbackCli,...args];}
109
115
  }
110
116
  if([...this.processes.values()].filter(x=>x.running).length>=this.maxRunningJobs)fail("LOCAL_JOB_LIMIT","Local running job limit reached");
111
117
  const id=String(this.nextId++);let child;
@@ -122,6 +128,7 @@ export class ProcessManager {
122
128
 
123
129
  #owned(id,ownerId){this.#cleanup();const s=this.processes.get(String(id));if(!s)fail("LOCAL_JOB_NOT_FOUND","Local job not found");if(s.ownerId!=null&&String(ownerId||"")!==s.ownerId)fail("LOCAL_JOB_NOT_FOUND","Local job not found");return s;}
124
130
  output({id,ownerId}={}){const s=this.#owned(id,ownerId);return{id:s.id,stdout:s.stdout,stderr:s.stderr,running:s.running,exitCode:s.exitCode,errorCode:s.errorCode,truncated:s.truncated,timedOut:s.timedOut};}
131
+ async wait({id,ownerId,waitMs=30000}={}){const s=this.#owned(id,ownerId),bounded=Math.max(0,Math.min(Number(waitMs)||0,30000));if(!s.running||bounded===0)return this.output({id,ownerId});await new Promise(resolve=>{let settled=false;const done=()=>{if(settled)return;settled=true;clearTimeout(timer);s.child.off?.("close",done);s.child.off?.("error",done);resolve();};const timer=setTimeout(done,bounded);s.child.once?.("close",done);s.child.once?.("error",done);if(!s.running)done();});return this.output({id,ownerId});}
125
132
  input({id,ownerId,data,end=false}={}){const s=this.#owned(id,ownerId);if(!s.running)fail("LOCAL_JOB_NOT_RUNNING","Local job is not running");if(typeof data!=="string")fail("INVALID_ARGUMENT","data must be a string");if(Buffer.byteLength(data,"utf8")>65536)fail("CONTENT_TOO_LARGE","stdin data exceeds 65536 UTF-8 bytes");if(!s.child.stdin||typeof s.child.stdin.write!=="function")fail("LOCAL_STDIN_UNAVAILABLE","Local process stdin is unavailable");if(data.length)s.child.stdin.write(data);if(end){if(typeof s.child.stdin.end!=="function")fail("LOCAL_STDIN_UNAVAILABLE","Local process stdin cannot be closed");s.child.stdin.end();}this.audit({event:"process.input",id,bytes:Buffer.byteLength(data,"utf8"),end:Boolean(end)});return{id:s.id,writtenBytes:Buffer.byteLength(data,"utf8"),ended:Boolean(end)};}
126
133
  stop({id,ownerId}={}){const s=this.#owned(id,ownerId);if(s.running)s.child.kill();return{id:s.id,stopping:s.running};}
127
134
  }
@@ -129,7 +129,8 @@ export function createToolExecutor({ security, processManager, remoteExecutionMa
129
129
  if(tool==="remote.stop"){if(!remoteExecutionManager)throw Object.assign(new Error("Remote execution is not configured"),{code:"REMOTE_JOB_NOT_FOUND"});return remoteExecutionManager.stop(args);}
130
130
  if(tool==="process.discover")return processManager.discover(args);
131
131
  if(tool==="process.start"){const cwd=security.resolveFilesystemPath(args.cwd);return processManager.start({...args,cwd});}
132
- if(tool==="process.output")return processManager.output(args);
132
+ if(tool==="process.output")return processManager.output(args);
133
+ if(tool==="process.wait")return processManager.wait(args);
133
134
  if(tool==="process.input")return processManager.input(args);
134
135
  if(tool==="process.stop")return processManager.stop(args);
135
136
  if(tool==="git.status"||tool==="git.diff"||tool==="git.log"){const cwd=security.resolveFilesystemPath(args.cwd);const gitArgs=tool==="git.status"?["status","--porcelain=v1","--branch"]:tool==="git.diff"?["diff","--",...(args.paths||[])]:["log","--oneline","-n",String(Math.min(Number(args.limit||10),50))];const {stdout,stderr}=await execFileAsync("git",gitArgs,{cwd,windowsHide:true,maxBuffer:1024*1024});return{stdout,stderr};}