@push.rocks/smartrust 1.3.0 → 1.3.2
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 +17 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.rustbinarylocator.d.ts +1 -0
- package/dist_ts/classes.rustbinarylocator.js +15 -1
- package/package.json +1 -1
- package/readme.md +158 -16
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.rustbinarylocator.ts +15 -0
package/changelog.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026-03-14 - 1.3.2 - fix(rustbinarylocator)
|
|
4
|
+
support resolving platform-suffixed local Rust binaries
|
|
5
|
+
|
|
6
|
+
- Checks local Rust build paths for binaries with platform suffixes such as _linux_amd64 in addition to unsuffixed names
|
|
7
|
+
- Adds platform and architecture suffix mapping for linux, darwin, windows, x64, and arm64
|
|
8
|
+
|
|
9
|
+
## 2026-02-26 - 1.3.1 - fix(readme)
|
|
10
|
+
document socket transport and clarify stdio/socket differences in README
|
|
11
|
+
|
|
12
|
+
- Add 'Two Transport Modes' section documenting stdio (spawn) and socket (connect) modes
|
|
13
|
+
- Add examples for connect(), socket usage, and auto-reconnect with exponential backoff
|
|
14
|
+
- Clarify protocol is transport-agnostic and update ready/stream/event descriptions
|
|
15
|
+
- Update event docs: mark stderr as stdio-only and add 'reconnected' event for socket transports
|
|
16
|
+
- Clarify kill() behavior for both stdio and socket transports
|
|
17
|
+
- Add API reference entries for SocketTransport, StdioTransport, ISocketConnectOptions, IRustTransport, and LineScanner
|
|
18
|
+
- Add platform notes, architecture diagram, and minimal Rust/socket usage guidance
|
|
19
|
+
|
|
3
20
|
## 2026-02-26 - 1.3.0 - feat(transport)
|
|
4
21
|
introduce transport abstraction and socket-mode support for RustBridge
|
|
5
22
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartrust',
|
|
6
|
-
version: '1.3.
|
|
6
|
+
version: '1.3.2',
|
|
7
7
|
description: 'a bridge between JS engines and rust'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx1QkFBdUI7SUFDN0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHNDQUFzQztDQUNwRCxDQUFBIn0=
|
|
@@ -70,11 +70,18 @@ export class RustBinaryLocator {
|
|
|
70
70
|
plugins.path.resolve(process.cwd(), `rust/target/release/${binaryName}`),
|
|
71
71
|
plugins.path.resolve(process.cwd(), `rust/target/debug/${binaryName}`),
|
|
72
72
|
];
|
|
73
|
+
const platformSuffix = this.getPlatformSuffix();
|
|
73
74
|
for (const localPath of localPaths) {
|
|
74
75
|
if (await this.isExecutable(localPath)) {
|
|
75
76
|
this.logger.log('info', `Binary found at local path: ${localPath}`);
|
|
76
77
|
return localPath;
|
|
77
78
|
}
|
|
79
|
+
// Also try with platform suffix (tsrust convention: binaryName_linux_amd64)
|
|
80
|
+
const suffixedPath = `${localPath}_${platformSuffix}`;
|
|
81
|
+
if (await this.isExecutable(suffixedPath)) {
|
|
82
|
+
this.logger.log('info', `Binary found at local path (platform-suffixed): ${suffixedPath}`);
|
|
83
|
+
return suffixedPath;
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
// 5. System PATH
|
|
80
87
|
if (this.options.searchSystemPath !== false) {
|
|
@@ -123,6 +130,13 @@ export class RustBinaryLocator {
|
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
}
|
|
133
|
+
getPlatformSuffix() {
|
|
134
|
+
const archMap = { x64: 'amd64', arm64: 'arm64' };
|
|
135
|
+
const platformMap = { linux: 'linux', darwin: 'darwin', win32: 'windows' };
|
|
136
|
+
const platform = platformMap[process.platform] || process.platform;
|
|
137
|
+
const arch = archMap[process.arch] || process.arch;
|
|
138
|
+
return `${platform}_${arch}`;
|
|
139
|
+
}
|
|
126
140
|
async findInPath(binaryName) {
|
|
127
141
|
const pathDirs = (process.env.PATH || '').split(plugins.path.delimiter);
|
|
128
142
|
for (const dir of pathDirs) {
|
|
@@ -134,4 +148,4 @@ export class RustBinaryLocator {
|
|
|
134
148
|
return null;
|
|
135
149
|
}
|
|
136
150
|
}
|
|
137
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
151
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5ydXN0YmluYXJ5bG9jYXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NsYXNzZXMucnVzdGJpbmFyeWxvY2F0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxjQUFjLENBQUM7QUFHeEMsTUFBTSxhQUFhLEdBQXNCO0lBQ3ZDLEdBQUcsS0FBSSxDQUFDO0NBQ1QsQ0FBQztBQUVGOzs7Ozs7O0dBT0c7QUFDSCxNQUFNLE9BQU8saUJBQWlCO0lBQ3BCLE9BQU8sQ0FBd0I7SUFDL0IsTUFBTSxDQUFvQjtJQUMxQixVQUFVLEdBQWtCLElBQUksQ0FBQztJQUV6QyxZQUFZLE9BQThCLEVBQUUsTUFBMEI7UUFDcEUsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUM7UUFDdkIsSUFBSSxDQUFDLE1BQU0sR0FBRyxNQUFNL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RLEVBQUUsS0FBSyxFQUFFLFNBQVMsRUFBRSxDQUFDO1FBQ25HLE1BQU0sUUFBUSxHQUFHLFdBQVcsQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQztRQUNuRSxNQUFNLElBQUksR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUM7UUFDbkQsT0FBTyxHQUFHLFFBQVEsSUFBSSxJQUFJLEVBQUUsQ0FBQztJQUMvQixDQUFDO0lBRU8sS0FBSyxDQUFDLFVBQVUsQ0FBQyxVQUFrQjtRQUN6QyxNQUFNLFFBQVEsR0FBRyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxJQUFJLEVBQUUsQ0FBQyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQ3hFLEtBQUssTUFBTSxHQUFHLElBQUksUUFBUSxFQUFFLENBQUM7WUFDM0IsTUFBTSxRQUFRLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsR0FBRyxFQUFFLFVBQVUsQ0FBQyxDQUFDO1lBQ3BELElBQUksTUFBTSxJQUFJLENBQUMsWUFBWSxDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUM7Z0JBQ3RDLE9BQU8sUUFBUSxDQUFDO1lBQ2xCLENBQUM7UUFDSCxDQUFDO1FBQ0QsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0NBQ0YifQ==
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @push.rocks/smartrust
|
|
2
2
|
|
|
3
|
-
A type-safe, production-ready bridge between TypeScript and Rust binaries
|
|
3
|
+
A type-safe, production-ready bridge between TypeScript and Rust binaries — with support for **stdio** (child process) and **socket** (Unix socket / Windows named pipe) transports, request/response, streaming, and event patterns.
|
|
4
4
|
|
|
5
5
|
## Issue Reporting and Security
|
|
6
6
|
|
|
@@ -16,25 +16,34 @@ pnpm install @push.rocks/smartrust
|
|
|
16
16
|
|
|
17
17
|
## Overview 🔭
|
|
18
18
|
|
|
19
|
-
`@push.rocks/smartrust` provides a complete bridge for TypeScript applications that need to communicate with Rust binaries. It handles the entire lifecycle — binary discovery, process spawning
|
|
19
|
+
`@push.rocks/smartrust` provides a complete bridge for TypeScript applications that need to communicate with Rust binaries. It handles the entire lifecycle — binary discovery, process spawning **or socket connection**, request/response correlation, **streaming responses**, event pub/sub, and graceful shutdown — so you can focus on your command definitions instead of IPC plumbing.
|
|
20
|
+
|
|
21
|
+
### Two Transport Modes 🔌
|
|
22
|
+
|
|
23
|
+
| Mode | Method | Use Case |
|
|
24
|
+
|------|--------|----------|
|
|
25
|
+
| **Stdio** | `bridge.spawn()` | Spawn the Rust binary as a child process. Communicate via stdin/stdout. |
|
|
26
|
+
| **Socket** | `bridge.connect(path)` | Connect to an **already-running** Rust daemon via Unix socket or Windows named pipe. |
|
|
27
|
+
|
|
28
|
+
The JSON protocol is identical in both modes — only the transport layer changes. Socket mode enables use cases where the Rust binary runs as a **privileged system service** (e.g., a VPN daemon needing root for TUN devices, a network proxy binding to privileged ports) while the TypeScript app connects to it unprivileged.
|
|
20
29
|
|
|
21
30
|
### Why? 🤔
|
|
22
31
|
|
|
23
32
|
If you're integrating Rust into a Node.js project, you'll inevitably need:
|
|
24
33
|
- A way to **find** the compiled Rust binary across different environments (dev, CI, production, platform packages)
|
|
25
|
-
- A way to **spawn** it and establish reliable two-way communication
|
|
34
|
+
- A way to **spawn it** or **connect to it** and establish reliable two-way communication
|
|
26
35
|
- **Type-safe** request/response patterns with proper error handling
|
|
27
36
|
- **Streaming responses** for progressive data processing, log tailing, or chunked transfers
|
|
28
37
|
- **Event streaming** from Rust to TypeScript
|
|
29
|
-
- **Graceful lifecycle management** (ready detection, clean shutdown,
|
|
38
|
+
- **Graceful lifecycle management** (ready detection, clean shutdown, auto-reconnection)
|
|
30
39
|
|
|
31
|
-
`smartrust` wraps all of this into
|
|
40
|
+
`smartrust` wraps all of this into a clean API: `RustBridge`, `RustBinaryLocator`, `StreamingResponse`, and pluggable transports.
|
|
32
41
|
|
|
33
42
|
## Usage 🚀
|
|
34
43
|
|
|
35
44
|
### The IPC Protocol
|
|
36
45
|
|
|
37
|
-
`smartrust` uses a simple, newline-delimited JSON protocol
|
|
46
|
+
`smartrust` uses a simple, newline-delimited JSON protocol:
|
|
38
47
|
|
|
39
48
|
| Direction | Format | Description |
|
|
40
49
|
|-----------|--------|-------------|
|
|
@@ -44,7 +53,7 @@ If you're integrating Rust into a Node.js project, you'll inevitably need:
|
|
|
44
53
|
| **Rust → TS** (Stream Chunk) | `{"id": "req_1", "stream": true, "data": {...}}` | Intermediate chunk (zero or more) |
|
|
45
54
|
| **Rust → TS** (Event) | `{"event": "ready", "data": {...}}` | Unsolicited event (no ID) |
|
|
46
55
|
|
|
47
|
-
Your Rust binary reads JSON lines from
|
|
56
|
+
This protocol works identically over stdio and socket transports. Your Rust binary reads JSON lines from one end and writes JSON lines to the other. That's it.
|
|
48
57
|
|
|
49
58
|
### Defining Your Commands
|
|
50
59
|
|
|
@@ -62,7 +71,9 @@ type TMyCommands = {
|
|
|
62
71
|
};
|
|
63
72
|
```
|
|
64
73
|
|
|
65
|
-
###
|
|
74
|
+
### Stdio Mode — Spawn a Child Process
|
|
75
|
+
|
|
76
|
+
This is the classic mode. The bridge spawns the Rust binary and communicates via stdin/stdout:
|
|
66
77
|
|
|
67
78
|
```typescript
|
|
68
79
|
const bridge = new RustBridge<TMyCommands>({
|
|
@@ -90,10 +101,62 @@ bridge.on('management:configChanged', (data) => {
|
|
|
90
101
|
console.log('Config was changed:', data);
|
|
91
102
|
});
|
|
92
103
|
|
|
93
|
-
// Clean shutdown
|
|
104
|
+
// Clean shutdown (SIGTERM → SIGKILL after 5s)
|
|
105
|
+
bridge.kill();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Socket Mode — Connect to a Running Daemon 🔗
|
|
109
|
+
|
|
110
|
+
When the Rust binary runs as a system service (e.g., via `systemd`, `launchd`, or a Windows Service), use `connect()` to talk to it over a Unix socket or named pipe:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const bridge = new RustBridge<TMyCommands>({
|
|
114
|
+
binaryName: 'my-daemon', // used for logging / error messages
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Connect to the daemon's management socket
|
|
118
|
+
const ok = await bridge.connect('/var/run/my-daemon.sock');
|
|
119
|
+
if (!ok) {
|
|
120
|
+
console.error('Failed to connect to daemon');
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Same API as stdio mode — completely transparent!
|
|
125
|
+
const { pid } = await bridge.sendCommand('start', { port: 8080, host: '0.0.0.0' });
|
|
126
|
+
const metrics = await bridge.sendCommand('getMetrics', {});
|
|
127
|
+
|
|
128
|
+
// kill() closes the socket — it does NOT kill the daemon
|
|
94
129
|
bridge.kill();
|
|
95
130
|
```
|
|
96
131
|
|
|
132
|
+
#### Auto-Reconnect
|
|
133
|
+
|
|
134
|
+
For long-running applications, enable automatic reconnection with exponential backoff:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const ok = await bridge.connect('/var/run/my-daemon.sock', {
|
|
138
|
+
autoReconnect: true, // reconnect on unexpected disconnect
|
|
139
|
+
reconnectBaseDelayMs: 100, // initial retry delay (doubles each attempt)
|
|
140
|
+
reconnectMaxDelayMs: 30000, // max retry delay cap
|
|
141
|
+
maxReconnectAttempts: 10, // give up after 10 attempts
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Listen for reconnection events
|
|
145
|
+
bridge.on('reconnected', () => {
|
|
146
|
+
console.log('Reconnected to daemon!');
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Platform Notes
|
|
151
|
+
|
|
152
|
+
| Platform | Socket Path Format | Example |
|
|
153
|
+
|----------|-------------------|---------|
|
|
154
|
+
| **Linux** | `/var/run/<name>.sock` or `$XDG_RUNTIME_DIR/<name>.sock` | `/var/run/my-daemon.sock` |
|
|
155
|
+
| **macOS** | `/var/run/<name>.sock` | `/var/run/my-daemon.sock` |
|
|
156
|
+
| **Windows** | `\\.\pipe\<name>` | `\\.\pipe\my-daemon` |
|
|
157
|
+
|
|
158
|
+
Node.js `net.connect()` handles all formats transparently — no platform-specific code needed.
|
|
159
|
+
|
|
97
160
|
### Streaming Commands 🌊
|
|
98
161
|
|
|
99
162
|
For commands where the Rust binary sends a series of chunks before a final result, use `sendCommandStreaming`. This is perfect for progressive data processing, log tailing, search results, or any scenario where you want incremental output.
|
|
@@ -231,6 +294,17 @@ const bridge = new RustBridge<TMyCommands>({
|
|
|
231
294
|
});
|
|
232
295
|
```
|
|
233
296
|
|
|
297
|
+
Socket connection options (passed to `bridge.connect()`):
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
interface ISocketConnectOptions {
|
|
301
|
+
autoReconnect?: boolean; // default: false
|
|
302
|
+
reconnectBaseDelayMs?: number; // default: 100
|
|
303
|
+
reconnectMaxDelayMs?: number; // default: 30000
|
|
304
|
+
maxReconnectAttempts?: number; // default: 10
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
234
308
|
### Events 📡
|
|
235
309
|
|
|
236
310
|
`RustBridge` extends `EventEmitter` and emits the following events:
|
|
@@ -238,8 +312,9 @@ const bridge = new RustBridge<TMyCommands>({
|
|
|
238
312
|
| Event | Payload | Description |
|
|
239
313
|
|-------|---------|-------------|
|
|
240
314
|
| `ready` | — | Bridge connected and binary reported ready |
|
|
241
|
-
| `exit` | `(code, signal)` |
|
|
242
|
-
| `stderr` | `string` | A line from the binary's stderr |
|
|
315
|
+
| `exit` | `(code, signal)` | Transport closed (process exited or socket disconnected) |
|
|
316
|
+
| `stderr` | `string` | A line from the binary's stderr (stdio mode only) |
|
|
317
|
+
| `reconnected` | — | Socket transport reconnected after unexpected disconnect |
|
|
243
318
|
| `management:<name>` | `any` | Custom event from Rust (e.g. `management:configChanged`) |
|
|
244
319
|
|
|
245
320
|
### Custom Logger 📝
|
|
@@ -263,7 +338,9 @@ const bridge = new RustBridge<TMyCommands>({
|
|
|
263
338
|
|
|
264
339
|
### Writing the Rust Side 🦀
|
|
265
340
|
|
|
266
|
-
Your Rust binary needs to implement a simple protocol
|
|
341
|
+
Your Rust binary needs to implement a simple protocol. The transport (stdio or socket) doesn't change the message format — only how connections are established.
|
|
342
|
+
|
|
343
|
+
#### Stdio Mode (Child Process)
|
|
267
344
|
|
|
268
345
|
1. **On startup**, write a ready event to stdout:
|
|
269
346
|
```
|
|
@@ -280,7 +357,14 @@ Your Rust binary needs to implement a simple protocol:
|
|
|
280
357
|
|
|
281
358
|
6. **Use stderr** for logging — it won't interfere with the IPC protocol
|
|
282
359
|
|
|
283
|
-
|
|
360
|
+
#### Socket Mode (Daemon)
|
|
361
|
+
|
|
362
|
+
1. **Listen** on a Unix socket (e.g., `/var/run/my-daemon.sock`) or Windows named pipe
|
|
363
|
+
2. **On each new client connection**, send the `{"event":"ready","data":{...}}\n` event
|
|
364
|
+
3. Read/write JSON lines on the socket (same protocol as stdio)
|
|
365
|
+
4. Support multiple concurrent clients — each connection is independent
|
|
366
|
+
|
|
367
|
+
Here's a minimal Rust skeleton (stdio mode):
|
|
284
368
|
|
|
285
369
|
```rust
|
|
286
370
|
use serde::{Deserialize, Serialize};
|
|
@@ -368,6 +452,33 @@ fn main() {
|
|
|
368
452
|
}
|
|
369
453
|
```
|
|
370
454
|
|
|
455
|
+
## Architecture 🏗️
|
|
456
|
+
|
|
457
|
+
```
|
|
458
|
+
┌──────────────────────────────────────────────────────┐
|
|
459
|
+
│ RustBridge<T> │
|
|
460
|
+
│ (protocol layer: handleLine, sendCommand, events) │
|
|
461
|
+
├──────────────┬───────────────────────────────────────┤
|
|
462
|
+
│ StdioTransport │ SocketTransport │
|
|
463
|
+
│ spawn() + │ net.connect() + auto-reconnect │
|
|
464
|
+
│ stdin/stdout │ Unix socket / named pipe │
|
|
465
|
+
├──────────────┴───────────────────────────────────────┤
|
|
466
|
+
│ IRustTransport interface │
|
|
467
|
+
│ connect() / write() / disconnect() │
|
|
468
|
+
├──────────────────────────────────────────────────────┤
|
|
469
|
+
│ LineScanner (shared newline scanner) │
|
|
470
|
+
├──────────────────────────────────────────────────────┤
|
|
471
|
+
│ RustBinaryLocator │
|
|
472
|
+
│ (binary search — stdio mode only) │
|
|
473
|
+
└──────────────────────────────────────────────────────┘
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
- **`RustBridge`** — The main class. Protocol-level logic (JSON parsing, request correlation, streaming, events) is transport-agnostic.
|
|
477
|
+
- **`StdioTransport`** — Spawns a child process, manages stdin/stdout/stderr, handles SIGTERM/SIGKILL.
|
|
478
|
+
- **`SocketTransport`** — Connects to an existing Unix socket or named pipe, with optional auto-reconnect and exponential backoff.
|
|
479
|
+
- **`LineScanner`** — Shared buffer-based newline scanner used by both transports for efficient message framing.
|
|
480
|
+
- **`RustBinaryLocator`** — Priority-ordered binary search (used by stdio mode only).
|
|
481
|
+
|
|
371
482
|
## API Reference 📖
|
|
372
483
|
|
|
373
484
|
### `RustBridge<TCommands>`
|
|
@@ -375,11 +486,12 @@ fn main() {
|
|
|
375
486
|
| Method / Property | Signature | Description |
|
|
376
487
|
|---|---|---|
|
|
377
488
|
| `constructor` | `new RustBridge<T>(options: IRustBridgeOptions)` | Create a new bridge instance |
|
|
378
|
-
| `spawn()` | `Promise<boolean>` | Spawn the binary and wait for ready; returns `false` on failure |
|
|
489
|
+
| `spawn()` | `Promise<boolean>` | **Stdio mode**: Spawn the binary and wait for ready; returns `false` on failure |
|
|
490
|
+
| `connect(socketPath, options?)` | `Promise<boolean>` | **Socket mode**: Connect to a running daemon; returns `false` on failure |
|
|
379
491
|
| `sendCommand(method, params)` | `Promise<TCommands[K]['result']>` | Send a typed command and await the response |
|
|
380
492
|
| `sendCommandStreaming(method, params)` | `StreamingResponse<TChunk, TResult>` | Send a streaming command; returns immediately |
|
|
381
|
-
| `kill()` | `void` | SIGTERM the process,
|
|
382
|
-
| `running` | `boolean` | Whether the bridge is currently connected |
|
|
493
|
+
| `kill()` | `void` | Stdio: SIGTERM the process, SIGKILL after 5s. Socket: close the connection (daemon stays alive) |
|
|
494
|
+
| `running` | `boolean` | Whether the bridge is currently connected and ready |
|
|
383
495
|
|
|
384
496
|
### `StreamingResponse<TChunk, TResult>`
|
|
385
497
|
|
|
@@ -396,13 +508,43 @@ fn main() {
|
|
|
396
508
|
| `findBinary()` | `Promise<string \| null>` | Find the binary using the priority search; result is cached |
|
|
397
509
|
| `clearCache()` | `void` | Clear the cached path to force a fresh search |
|
|
398
510
|
|
|
511
|
+
### `StdioTransport`
|
|
512
|
+
|
|
513
|
+
| Method / Property | Signature | Description |
|
|
514
|
+
|---|---|---|
|
|
515
|
+
| `constructor` | `new StdioTransport(options: IStdioTransportOptions)` | Create a stdio transport |
|
|
516
|
+
| `connect()` | `Promise<void>` | Spawn the child process |
|
|
517
|
+
| `write(data)` | `Promise<void>` | Write to stdin with backpressure handling |
|
|
518
|
+
| `disconnect()` | `void` | Kill the process (SIGTERM → SIGKILL after 5s) |
|
|
519
|
+
| `connected` | `boolean` | Whether the process is running |
|
|
520
|
+
|
|
521
|
+
### `SocketTransport`
|
|
522
|
+
|
|
523
|
+
| Method / Property | Signature | Description |
|
|
524
|
+
|---|---|---|
|
|
525
|
+
| `constructor` | `new SocketTransport(options: ISocketTransportOptions)` | Create a socket transport |
|
|
526
|
+
| `connect()` | `Promise<void>` | Connect to the Unix socket / named pipe |
|
|
527
|
+
| `write(data)` | `Promise<void>` | Write to socket with backpressure handling |
|
|
528
|
+
| `disconnect()` | `void` | Close the socket (does not kill the daemon) |
|
|
529
|
+
| `connected` | `boolean` | Whether the socket is connected |
|
|
530
|
+
|
|
531
|
+
### `LineScanner`
|
|
532
|
+
|
|
533
|
+
| Method / Property | Signature | Description |
|
|
534
|
+
|---|---|---|
|
|
535
|
+
| `constructor` | `new LineScanner(maxPayloadSize, logger)` | Create a line scanner |
|
|
536
|
+
| `push(chunk, onLine)` | `void` | Feed a `Buffer` chunk; calls `onLine` for each complete line |
|
|
537
|
+
| `clear()` | `void` | Reset the internal buffer |
|
|
538
|
+
|
|
399
539
|
### Exported Interfaces & Types
|
|
400
540
|
|
|
401
541
|
| Interface / Type | Description |
|
|
402
542
|
|---|---|
|
|
403
543
|
| `IRustBridgeOptions` | Full configuration for `RustBridge` |
|
|
404
544
|
| `IBinaryLocatorOptions` | Configuration for `RustBinaryLocator` |
|
|
545
|
+
| `ISocketConnectOptions` | Socket connection options (reconnect settings) |
|
|
405
546
|
| `IRustBridgeLogger` | Logger interface: `{ log(level, message, data?) }` |
|
|
547
|
+
| `IRustTransport` | Transport interface (extends `EventEmitter`) |
|
|
406
548
|
| `IManagementRequest` | IPC request shape: `{ id, method, params }` |
|
|
407
549
|
| `IManagementResponse` | IPC response shape: `{ id, success, result?, error? }` |
|
|
408
550
|
| `IManagementEvent` | IPC event shape: `{ event, data }` |
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -81,11 +81,18 @@ export class RustBinaryLocator {
|
|
|
81
81
|
plugins.path.resolve(process.cwd(), `rust/target/release/${binaryName}`),
|
|
82
82
|
plugins.path.resolve(process.cwd(), `rust/target/debug/${binaryName}`),
|
|
83
83
|
];
|
|
84
|
+
const platformSuffix = this.getPlatformSuffix();
|
|
84
85
|
for (const localPath of localPaths) {
|
|
85
86
|
if (await this.isExecutable(localPath)) {
|
|
86
87
|
this.logger.log('info', `Binary found at local path: ${localPath}`);
|
|
87
88
|
return localPath;
|
|
88
89
|
}
|
|
90
|
+
// Also try with platform suffix (tsrust convention: binaryName_linux_amd64)
|
|
91
|
+
const suffixedPath = `${localPath}_${platformSuffix}`;
|
|
92
|
+
if (await this.isExecutable(suffixedPath)) {
|
|
93
|
+
this.logger.log('info', `Binary found at local path (platform-suffixed): ${suffixedPath}`);
|
|
94
|
+
return suffixedPath;
|
|
95
|
+
}
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
// 5. System PATH
|
|
@@ -137,6 +144,14 @@ export class RustBinaryLocator {
|
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
146
|
|
|
147
|
+
private getPlatformSuffix(): string {
|
|
148
|
+
const archMap: Record<string, string> = { x64: 'amd64', arm64: 'arm64' };
|
|
149
|
+
const platformMap: Record<string, string> = { linux: 'linux', darwin: 'darwin', win32: 'windows' };
|
|
150
|
+
const platform = platformMap[process.platform] || process.platform;
|
|
151
|
+
const arch = archMap[process.arch] || process.arch;
|
|
152
|
+
return `${platform}_${arch}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
140
155
|
private async findInPath(binaryName: string): Promise<string | null> {
|
|
141
156
|
const pathDirs = (process.env.PATH || '').split(plugins.path.delimiter);
|
|
142
157
|
for (const dir of pathDirs) {
|