pi-remote-call 0.3.0 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1 - 2026-11-28
4
+
5
+ ### Changed
6
+
7
+ - Python helper requests now use exclusive direct writes (`wx`, mode `0600`), removing redundant request-file stat and rename round trips.
8
+ - Successful helper commands clean up their request file in the same remote command while preserving the helper exit status. Interrupted setup or execution retains best-effort SFTP cleanup.
9
+
10
+ ### Performance
11
+
12
+ - Real SSH benchmarks measured 25–34% lower small-file cached-read p50 latency and 28–38% lower large-file ranged-read p50 latency.
13
+
3
14
  ## 0.3.0 - 2026-11-28
4
15
 
5
16
  ### Added
package/README.md CHANGED
@@ -25,13 +25,13 @@ Remote machine:
25
25
  ### npm
26
26
 
27
27
  ```sh
28
- pi install npm:pi-remote-call@0.3.0
28
+ pi install npm:pi-remote-call@0.3.1
29
29
  ```
30
30
 
31
31
  ### GitHub
32
32
 
33
33
  ```sh
34
- pi install git:github.com/therainisme/pi-remote-call@v0.3.0
34
+ pi install git:github.com/therainisme/pi-remote-call@v0.3.1
35
35
  ```
36
36
 
37
37
  ### Local directory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-remote-call",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Call shell and file tools on SSH hosts from one local Pi, with zero remote installation.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/sftp.ts CHANGED
@@ -80,6 +80,22 @@ async function sftpFsyncFile(sftp: SFTPWrapper, path: string): Promise<void> {
80
80
  }
81
81
  }
82
82
 
83
+ export async function sftpWriteNewFile(sftp: SFTPWrapper, path: string, content: string): Promise<void> {
84
+ let created = false;
85
+ try {
86
+ await new Promise<void>((resolve, reject) => {
87
+ const stream = sftp.createWriteStream(path, { flags: "wx", mode: 0o600 });
88
+ stream.once("open", () => (created = true));
89
+ stream.once("error", reject);
90
+ stream.once("close", resolve);
91
+ stream.end(content, "utf8");
92
+ });
93
+ } catch (error) {
94
+ if (created) await sftpUnlink(sftp, path).catch(() => undefined);
95
+ throw error;
96
+ }
97
+ }
98
+
83
99
  export async function sftpWriteFileAtomic(sftp: SFTPWrapper, path: string, content: string, durable = false): Promise<void> {
84
100
  const stats = await sftpStat(sftp, path).catch(() => undefined);
85
101
  const temporary = posix.join(
package/src/transport.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  sftpSetStat,
21
21
  sftpUnlink,
22
22
  sftpWriteFileAtomic,
23
+ sftpWriteNewFile,
23
24
  } from "./sftp.ts";
24
25
 
25
26
  export interface RemoteHostFacts {
@@ -363,19 +364,24 @@ export class SshConnection {
363
364
  if (signal?.aborted) throw new Error("Operation aborted");
364
365
  const helperPath = await this.preparePythonHelper();
365
366
  const requestPath = posix.join("/tmp", `pi-remote-call-${process.pid}-${randomBytes(12).toString("hex")}.json`);
367
+ let requestCreated = false;
368
+ let remoteCleanup = false;
366
369
  try {
367
- await sftpWriteFileAtomic(this.sftp, requestPath, JSON.stringify(request));
370
+ await sftpWriteNewFile(this.sftp, requestPath, JSON.stringify(request));
371
+ requestCreated = true;
368
372
  if (signal?.aborted) throw new Error("Operation aborted");
369
373
  const stdoutChunks: Buffer[] = [];
370
374
  const stderrChunks: Buffer[] = [];
371
- const command = helperPath
375
+ const helperCommand = helperPath
372
376
  ? `${shellQuote(python.path)} ${shellQuote(helperPath)} ${shellQuote(requestPath)}`
373
377
  : `${shellQuote(python.path)} -c ${shellQuote(PYTHON_HELPER_SOURCE)} ${shellQuote(requestPath)}`;
378
+ const command = `${helperCommand}; helper_status=$?; rm -f -- ${shellQuote(requestPath)}; exit "$helper_status"`;
374
379
  const { exitCode } = await this.exec(command, this.facts.home, {
375
380
  onData: (data) => stdoutChunks.push(Buffer.from(data)),
376
381
  onStderr: (data) => stderrChunks.push(Buffer.from(data)),
377
382
  signal,
378
383
  });
384
+ remoteCleanup = true;
379
385
  return parsePythonHelperResponse(
380
386
  this.facts.alias,
381
387
  Buffer.concat(stdoutChunks).toString("utf8"),
@@ -383,7 +389,7 @@ export class SshConnection {
383
389
  exitCode,
384
390
  );
385
391
  } finally {
386
- await sftpUnlink(this.sftp, requestPath).catch(() => undefined);
392
+ if (requestCreated && !remoteCleanup) await sftpUnlink(this.sftp, requestPath).catch(() => undefined);
387
393
  }
388
394
  }
389
395