@agent-relay/utils 2.0.11 → 2.0.12

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/dist/index.d.ts CHANGED
@@ -6,4 +6,5 @@ export * from './git-remote.js';
6
6
  export * from './update-checker.js';
7
7
  export * from './error-tracking.js';
8
8
  export * from './model-mapping.js';
9
+ export * from './relay-pty-path.js';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@ export * from './git-remote.js';
6
6
  export * from './update-checker.js';
7
7
  export * from './error-tracking.js';
8
8
  export * from './model-mapping.js';
9
+ export * from './relay-pty-path.js';
9
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Shared utility for finding the relay-pty binary path.
3
+ *
4
+ * This is used by both:
5
+ * - packages/bridge/src/spawner.ts (AgentSpawner)
6
+ * - packages/wrapper/src/relay-pty-orchestrator.ts (RelayPtyOrchestrator)
7
+ *
8
+ * The search order handles multiple installation scenarios:
9
+ * 1. Development (local Rust build)
10
+ * 2. Local npm install (node_modules/agent-relay)
11
+ * 3. Global npm install via nvm
12
+ * 4. System-wide installs (/usr/local/bin)
13
+ */
14
+ /**
15
+ * Find the relay-pty binary.
16
+ *
17
+ * Search order:
18
+ * 1. bin/relay-pty in package root (installed by postinstall)
19
+ * 2. relay-pty/target/release/relay-pty (local Rust build)
20
+ * 3. /usr/local/bin/relay-pty (global install)
21
+ * 4. In node_modules when installed as dependency
22
+ * 5. Global npm installs (nvm) - both scoped and root packages
23
+ *
24
+ * @param callerDirname - The __dirname of the calling module (needed to resolve relative paths)
25
+ * @returns Path to relay-pty binary, or null if not found
26
+ */
27
+ export declare function findRelayPtyBinary(callerDirname: string): string | null;
28
+ /**
29
+ * Check if relay-pty binary is available (cached).
30
+ * Returns true if the binary exists, false otherwise.
31
+ *
32
+ * @param callerDirname - The __dirname of the calling module
33
+ */
34
+ export declare function hasRelayPtyBinary(callerDirname: string): boolean;
35
+ /**
36
+ * Get the cached relay-pty binary path.
37
+ * Must call hasRelayPtyBinary() or findRelayPtyBinary() first.
38
+ */
39
+ export declare function getCachedRelayPtyPath(): string | null | undefined;
40
+ /**
41
+ * Clear the cached binary path (for testing).
42
+ */
43
+ export declare function clearBinaryCache(): void;
44
+ //# sourceMappingURL=relay-pty-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-pty-path.d.ts","sourceRoot":"","sources":["../src/relay-pty-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwEvE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAMhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS,CAEjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Shared utility for finding the relay-pty binary path.
3
+ *
4
+ * This is used by both:
5
+ * - packages/bridge/src/spawner.ts (AgentSpawner)
6
+ * - packages/wrapper/src/relay-pty-orchestrator.ts (RelayPtyOrchestrator)
7
+ *
8
+ * The search order handles multiple installation scenarios:
9
+ * 1. Development (local Rust build)
10
+ * 2. Local npm install (node_modules/agent-relay)
11
+ * 3. Global npm install via nvm
12
+ * 4. System-wide installs (/usr/local/bin)
13
+ */
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ /** Cached result of relay-pty binary check */
17
+ let cachedBinaryPath;
18
+ let cacheChecked = false;
19
+ /**
20
+ * Find the relay-pty binary.
21
+ *
22
+ * Search order:
23
+ * 1. bin/relay-pty in package root (installed by postinstall)
24
+ * 2. relay-pty/target/release/relay-pty (local Rust build)
25
+ * 3. /usr/local/bin/relay-pty (global install)
26
+ * 4. In node_modules when installed as dependency
27
+ * 5. Global npm installs (nvm) - both scoped and root packages
28
+ *
29
+ * @param callerDirname - The __dirname of the calling module (needed to resolve relative paths)
30
+ * @returns Path to relay-pty binary, or null if not found
31
+ */
32
+ export function findRelayPtyBinary(callerDirname) {
33
+ // Determine the agent-relay package root
34
+ // This code runs from either:
35
+ // - packages/{package}/dist/ (development/workspace)
36
+ // - node_modules/@agent-relay/{package}/dist/ (npm install)
37
+ //
38
+ // We need to find the agent-relay package root where bin/relay-pty lives
39
+ let packageRoot;
40
+ // Check if we're inside node_modules/@agent-relay/*/
41
+ if (callerDirname.includes('node_modules/@agent-relay/')) {
42
+ // Go from node_modules/@agent-relay/{package}/dist/ to agent-relay/
43
+ // dist/ -> {package}/ -> @agent-relay/ -> node_modules/ -> agent-relay/
44
+ packageRoot = path.join(callerDirname, '..', '..', '..', '..');
45
+ }
46
+ else if (callerDirname.includes('node_modules/agent-relay')) {
47
+ // Direct dependency: node_modules/agent-relay/packages/{package}/dist/
48
+ // dist/ -> {package}/ -> packages/ -> agent-relay/
49
+ packageRoot = path.join(callerDirname, '..', '..', '..');
50
+ }
51
+ else {
52
+ // Development: packages/{package}/dist/ -> packages/ -> project root
53
+ packageRoot = path.join(callerDirname, '..', '..', '..');
54
+ }
55
+ // Find the node_modules root for global installs
56
+ // When running from node_modules/@agent-relay/dashboard/node_modules/@agent-relay/wrapper/dist/
57
+ // we need to look for agent-relay at node_modules/agent-relay
58
+ // Use non-greedy match (.+?) to get the FIRST node_modules, not the last
59
+ let nodeModulesRoot = null;
60
+ const nodeModulesMatch = callerDirname.match(/^(.+?\/node_modules)\/@agent-relay\//);
61
+ if (nodeModulesMatch) {
62
+ nodeModulesRoot = nodeModulesMatch[1];
63
+ }
64
+ const candidates = [
65
+ // Primary: installed by postinstall from platform-specific binary
66
+ path.join(packageRoot, 'bin', 'relay-pty'),
67
+ // Development: local Rust build
68
+ path.join(packageRoot, 'relay-pty', 'target', 'release', 'relay-pty'),
69
+ path.join(packageRoot, 'relay-pty', 'target', 'debug', 'relay-pty'),
70
+ // Local build in cwd (for development)
71
+ path.join(process.cwd(), 'relay-pty', 'target', 'release', 'relay-pty'),
72
+ // Docker container (CI tests)
73
+ '/app/bin/relay-pty',
74
+ // Installed globally
75
+ '/usr/local/bin/relay-pty',
76
+ // In node_modules (when installed as local dependency)
77
+ path.join(process.cwd(), 'node_modules', 'agent-relay', 'bin', 'relay-pty'),
78
+ // Global npm install (nvm) - root package
79
+ path.join(process.env.HOME || '', '.nvm', 'versions', 'node', process.version, 'lib', 'node_modules', 'agent-relay', 'bin', 'relay-pty'),
80
+ ];
81
+ // Add candidate for root agent-relay package when running from scoped @agent-relay/* packages
82
+ if (nodeModulesRoot) {
83
+ candidates.push(path.join(nodeModulesRoot, 'agent-relay', 'bin', 'relay-pty'));
84
+ }
85
+ // Try common global npm paths
86
+ if (process.env.HOME) {
87
+ // Homebrew npm (macOS)
88
+ candidates.push(path.join('/usr/local/lib/node_modules', 'agent-relay', 'bin', 'relay-pty'));
89
+ candidates.push(path.join('/opt/homebrew/lib/node_modules', 'agent-relay', 'bin', 'relay-pty'));
90
+ // pnpm global
91
+ candidates.push(path.join(process.env.HOME, '.local', 'share', 'pnpm', 'global', 'node_modules', 'agent-relay', 'bin', 'relay-pty'));
92
+ }
93
+ for (const candidate of candidates) {
94
+ if (fs.existsSync(candidate)) {
95
+ return candidate;
96
+ }
97
+ }
98
+ return null;
99
+ }
100
+ /**
101
+ * Check if relay-pty binary is available (cached).
102
+ * Returns true if the binary exists, false otherwise.
103
+ *
104
+ * @param callerDirname - The __dirname of the calling module
105
+ */
106
+ export function hasRelayPtyBinary(callerDirname) {
107
+ if (!cacheChecked) {
108
+ cachedBinaryPath = findRelayPtyBinary(callerDirname);
109
+ cacheChecked = true;
110
+ }
111
+ return cachedBinaryPath !== null;
112
+ }
113
+ /**
114
+ * Get the cached relay-pty binary path.
115
+ * Must call hasRelayPtyBinary() or findRelayPtyBinary() first.
116
+ */
117
+ export function getCachedRelayPtyPath() {
118
+ return cachedBinaryPath;
119
+ }
120
+ /**
121
+ * Clear the cached binary path (for testing).
122
+ */
123
+ export function clearBinaryCache() {
124
+ cachedBinaryPath = undefined;
125
+ cacheChecked = false;
126
+ }
127
+ //# sourceMappingURL=relay-pty-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-pty-path.js","sourceRoot":"","sources":["../src/relay-pty-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,8CAA8C;AAC9C,IAAI,gBAA2C,CAAC;AAChD,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,aAAqB;IACtD,yCAAyC;IACzC,8BAA8B;IAC9B,qDAAqD;IACrD,4DAA4D;IAC5D,EAAE;IACF,yEAAyE;IACzE,IAAI,WAAmB,CAAC;IAExB,qDAAqD;IACrD,IAAI,aAAa,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,CAAC;QACzD,oEAAoE;QACpE,wEAAwE;QACxE,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;SAAM,IAAI,aAAa,CAAC,QAAQ,CAAC,0BAA0B,CAAC,EAAE,CAAC;QAC9D,uEAAuE;QACvE,mDAAmD;QACnD,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACN,qEAAqE;QACrE,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED,iDAAiD;IACjD,gGAAgG;IAChG,8DAA8D;IAC9D,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
+ "version": "2.0.12",
4
4
  "description": "Shared utilities for agent-relay: logging, name generation, command resolution, update checking",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -49,6 +49,11 @@
49
49
  "types": "./dist/model-mapping.d.ts",
50
50
  "import": "./dist/model-mapping.js",
51
51
  "default": "./dist/model-mapping.js"
52
+ },
53
+ "./relay-pty-path": {
54
+ "types": "./dist/relay-pty-path.d.ts",
55
+ "import": "./dist/relay-pty-path.js",
56
+ "default": "./dist/relay-pty-path.js"
52
57
  }
53
58
  },
54
59
  "files": [