agent-relay 4.0.31 → 4.0.33
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/bin/agent-relay-broker-darwin-arm64 +0 -0
- package/bin/agent-relay-broker-darwin-x64 +0 -0
- package/bin/agent-relay-broker-linux-arm64 +0 -0
- package/bin/agent-relay-broker-linux-x64 +0 -0
- package/dist/index.cjs +210 -75
- package/dist/src/cli/commands/on/start.d.ts.map +1 -1
- package/dist/src/cli/commands/on/start.js +149 -111
- package/dist/src/cli/commands/on/start.js.map +1 -1
- package/node_modules/@agent-relay/cloud/package.json +2 -2
- package/node_modules/@agent-relay/config/package.json +1 -1
- package/node_modules/@agent-relay/hooks/package.json +4 -4
- package/node_modules/@agent-relay/sdk/README.md +3 -0
- package/node_modules/@agent-relay/sdk/dist/relay.d.ts +16 -0
- package/node_modules/@agent-relay/sdk/dist/relay.d.ts.map +1 -1
- package/node_modules/@agent-relay/sdk/dist/relay.js +83 -0
- package/node_modules/@agent-relay/sdk/dist/relay.js.map +1 -1
- package/node_modules/@agent-relay/sdk/package.json +2 -2
- package/node_modules/@agent-relay/telemetry/package.json +1 -1
- package/node_modules/@agent-relay/trajectory/package.json +2 -2
- package/node_modules/@agent-relay/user-directory/package.json +2 -2
- package/node_modules/@agent-relay/utils/package.json +2 -2
- package/node_modules/@relayfile/local-mount/README.md +215 -0
- package/node_modules/@relayfile/local-mount/dist/auto-sync.d.ts +31 -0
- package/node_modules/@relayfile/local-mount/dist/auto-sync.js +466 -0
- package/node_modules/@relayfile/local-mount/dist/dotfiles.d.ts +18 -0
- package/node_modules/@relayfile/local-mount/dist/dotfiles.js +43 -0
- package/node_modules/@relayfile/local-mount/dist/index.d.ts +4 -0
- package/node_modules/@relayfile/local-mount/dist/index.js +3 -0
- package/node_modules/@relayfile/local-mount/dist/launch.d.ts +50 -0
- package/node_modules/@relayfile/local-mount/dist/launch.js +129 -0
- package/node_modules/@relayfile/local-mount/dist/symlink-mount.d.ts +23 -0
- package/{dist/src/cli/commands/on → node_modules/@relayfile/local-mount/dist}/symlink-mount.js +88 -20
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/LICENSE +21 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/README.md +305 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/handler.d.ts +90 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/handler.js +629 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/index.d.ts +215 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/index.js +798 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/esm/package.json +1 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/handler.d.ts +90 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/handler.js +635 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/index.d.ts +215 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/index.js +804 -0
- package/node_modules/@relayfile/local-mount/node_modules/chokidar/package.json +69 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/LICENSE +21 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/README.md +120 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/esm/index.d.ts +108 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/esm/index.js +257 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/esm/package.json +1 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/index.d.ts +108 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/index.js +263 -0
- package/node_modules/@relayfile/local-mount/node_modules/readdirp/package.json +70 -0
- package/node_modules/@relayfile/local-mount/package.json +47 -0
- package/node_modules/@smithy/config-resolver/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/index.js +2 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +32 -14
- package/node_modules/@smithy/core/dist-cjs/submodules/endpoints/index.js +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +16 -8
- package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +17 -10
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +6 -1
- package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.js +6 -3
- package/node_modules/@smithy/core/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +2 -1
- package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +23 -11
- package/node_modules/@smithy/core/dist-es/submodules/cbor/parseCborBody.js +9 -3
- package/node_modules/@smithy/core/dist-es/submodules/endpoints/toEndpointV1.js +2 -2
- package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +16 -8
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +9 -4
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +8 -6
- package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +6 -1
- package/node_modules/@smithy/core/dist-es/submodules/serde/parse-utils.js +6 -3
- package/node_modules/@smithy/core/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +2 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/TypeRegistry.d.ts +1 -1
- package/node_modules/@smithy/core/package.json +2 -2
- package/node_modules/@smithy/middleware-endpoint/package.json +3 -3
- package/node_modules/@smithy/middleware-retry/package.json +5 -5
- package/node_modules/@smithy/middleware-serde/package.json +2 -2
- package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +188 -93
- package/node_modules/@smithy/node-http-handler/dist-es/http2/ClientHttp2SessionRef.js +45 -0
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +71 -35
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +32 -18
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +41 -40
- package/node_modules/@smithy/node-http-handler/dist-types/http2/ClientHttp2SessionRef.d.ts +42 -0
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-manager.d.ts +34 -14
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-pool.d.ts +32 -8
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +0 -5
- package/node_modules/@smithy/node-http-handler/package.json +1 -1
- package/node_modules/@smithy/service-error-classification/dist-cjs/index.js +5 -0
- package/node_modules/@smithy/service-error-classification/dist-es/index.js +4 -0
- package/node_modules/@smithy/service-error-classification/dist-types/index.d.ts +6 -0
- package/node_modules/@smithy/service-error-classification/package.json +1 -1
- package/node_modules/@smithy/smithy-client/package.json +4 -4
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +3 -3
- package/node_modules/@smithy/util-endpoints/dist-cjs/index.js +65 -53
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateCondition.js +9 -7
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateConditions.js +12 -8
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateEndpointRule.js +14 -13
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateErrorRule.js +7 -4
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateExpression.js +10 -8
- package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateRules.js +4 -4
- package/node_modules/@smithy/util-endpoints/dist-es/utils/getEndpointHeaders.js +5 -5
- package/node_modules/@smithy/util-endpoints/dist-es/utils/getEndpointProperties.js +4 -4
- package/node_modules/@smithy/util-endpoints/dist-types/types/shared.d.ts +3 -3
- package/node_modules/@smithy/util-endpoints/dist-types/utils/endpointFunctions.d.ts +2 -15
- package/node_modules/@smithy/util-endpoints/dist-types/utils/evaluateCondition.d.ts +6 -3
- package/node_modules/@smithy/util-endpoints/dist-types/utils/evaluateConditions.d.ts +3 -3
- package/node_modules/@smithy/util-endpoints/dist-types/utils/getEndpointHeaders.d.ts +1 -1
- package/node_modules/@smithy/util-endpoints/dist-types/utils/getEndpointProperties.d.ts +2 -2
- package/node_modules/@smithy/util-endpoints/dist-types/utils/getReferenceValue.d.ts +2 -2
- package/node_modules/@smithy/util-endpoints/package.json +1 -1
- package/node_modules/@smithy/util-retry/package.json +2 -2
- package/node_modules/@smithy/util-stream/package.json +2 -2
- package/node_modules/agent-trajectories/dist/{chunk-2XT3DOJC.js → chunk-27AQPWHK.js} +136 -72
- package/node_modules/agent-trajectories/dist/chunk-27AQPWHK.js.map +1 -0
- package/node_modules/agent-trajectories/dist/cli/index.js +135 -71
- package/node_modules/agent-trajectories/dist/cli/index.js.map +1 -1
- package/node_modules/agent-trajectories/dist/{index-thTh5iI8.d.ts → index-C7XhwsoN.d.ts} +24 -0
- package/node_modules/agent-trajectories/dist/index.d.ts +2 -2
- package/node_modules/agent-trajectories/dist/index.js +1 -1
- package/node_modules/agent-trajectories/dist/sdk/index.d.ts +1 -1
- package/node_modules/agent-trajectories/dist/sdk/index.js +1 -1
- package/node_modules/agent-trajectories/package.json +1 -1
- package/package.json +25 -11
- package/packages/cloud/package.json +2 -2
- package/packages/config/package.json +1 -1
- package/packages/hooks/package.json +4 -4
- package/packages/sdk/README.md +3 -0
- package/packages/sdk/dist/relay.d.ts +16 -0
- package/packages/sdk/dist/relay.d.ts.map +1 -1
- package/packages/sdk/dist/relay.js +83 -0
- package/packages/sdk/dist/relay.js.map +1 -1
- package/packages/sdk/package.json +2 -2
- package/packages/telemetry/package.json +1 -1
- package/packages/trajectory/package.json +2 -2
- package/packages/user-directory/package.json +2 -2
- package/packages/utils/package.json +2 -2
- package/dist/src/cli/commands/on/symlink-mount.d.ts +0 -12
- package/dist/src/cli/commands/on/symlink-mount.d.ts.map +0 -1
- package/dist/src/cli/commands/on/symlink-mount.js.map +0 -1
- package/node_modules/agent-trajectories/dist/chunk-2XT3DOJC.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ReadAgentDotfilesOptions {
|
|
2
|
+
/**
|
|
3
|
+
* If provided, also reads `.{agentName}.agentignore` and `.{agentName}.agentreadonly`
|
|
4
|
+
* from the project directory and merges the resulting patterns.
|
|
5
|
+
*/
|
|
6
|
+
agentName?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentDotfilePatterns {
|
|
9
|
+
ignoredPatterns: string[];
|
|
10
|
+
readonlyPatterns: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Read `.agentignore` and `.agentreadonly` dotfiles from a project directory
|
|
14
|
+
* and return the compiled pattern lists. If `agentName` is supplied, also
|
|
15
|
+
* reads `.{agentName}.agentignore` and `.{agentName}.agentreadonly` and
|
|
16
|
+
* appends their patterns.
|
|
17
|
+
*/
|
|
18
|
+
export declare function readAgentDotfiles(projectDir: string, options?: ReadAgentDotfilesOptions): AgentDotfilePatterns;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
function cleanPatterns(content) {
|
|
4
|
+
return content
|
|
5
|
+
.split(/\r?\n/)
|
|
6
|
+
.map((line) => line.trim())
|
|
7
|
+
.filter((line) => line !== '' && !line.startsWith('#'));
|
|
8
|
+
}
|
|
9
|
+
function loadPatternsFromFile(filePath) {
|
|
10
|
+
if (!existsSync(filePath)) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const content = readFileSync(filePath, 'utf8');
|
|
14
|
+
return cleanPatterns(content);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Read `.agentignore` and `.agentreadonly` dotfiles from a project directory
|
|
18
|
+
* and return the compiled pattern lists. If `agentName` is supplied, also
|
|
19
|
+
* reads `.{agentName}.agentignore` and `.{agentName}.agentreadonly` and
|
|
20
|
+
* appends their patterns.
|
|
21
|
+
*/
|
|
22
|
+
export function readAgentDotfiles(projectDir, options = {}) {
|
|
23
|
+
const resolvedProjectDir = path.resolve(projectDir);
|
|
24
|
+
const ignoredPatterns = [
|
|
25
|
+
...loadPatternsFromFile(path.join(resolvedProjectDir, '.agentignore')),
|
|
26
|
+
];
|
|
27
|
+
const readonlyPatterns = [
|
|
28
|
+
...loadPatternsFromFile(path.join(resolvedProjectDir, '.agentreadonly')),
|
|
29
|
+
];
|
|
30
|
+
if (options.agentName) {
|
|
31
|
+
const safeAgentName = sanitizeAgentName(options.agentName);
|
|
32
|
+
ignoredPatterns.push(...loadPatternsFromFile(path.join(resolvedProjectDir, `.${safeAgentName}.agentignore`)));
|
|
33
|
+
readonlyPatterns.push(...loadPatternsFromFile(path.join(resolvedProjectDir, `.${safeAgentName}.agentreadonly`)));
|
|
34
|
+
}
|
|
35
|
+
return { ignoredPatterns, readonlyPatterns };
|
|
36
|
+
}
|
|
37
|
+
const AGENT_NAME_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
38
|
+
function sanitizeAgentName(agentName) {
|
|
39
|
+
if (!AGENT_NAME_PATTERN.test(agentName) || path.basename(agentName) !== agentName) {
|
|
40
|
+
throw new Error(`Invalid agentName ${JSON.stringify(agentName)}: only [A-Za-z0-9_-] are allowed`);
|
|
41
|
+
}
|
|
42
|
+
return agentName;
|
|
43
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createSymlinkMount, type SymlinkMountOptions, type SymlinkMountHandle, } from './symlink-mount.js';
|
|
2
|
+
export { type AutoSyncOptions, type AutoSyncHandle, } from './auto-sync.js';
|
|
3
|
+
export { readAgentDotfiles, type ReadAgentDotfilesOptions, type AgentDotfilePatterns, } from './dotfiles.js';
|
|
4
|
+
export { launchOnMount, type LaunchOnMountOptions, type LaunchOnMountResult, } from './launch.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AutoSyncOptions } from './auto-sync.js';
|
|
2
|
+
export interface LaunchOnMountOptions {
|
|
3
|
+
/** Binary name or absolute path to the CLI to spawn, e.g. 'claude'. */
|
|
4
|
+
cli: string;
|
|
5
|
+
/** The real project directory to mirror. */
|
|
6
|
+
projectDir: string;
|
|
7
|
+
/** Where to create the mount. Must differ from projectDir. */
|
|
8
|
+
mountDir: string;
|
|
9
|
+
/** Argv to pass to the CLI after its binary name. */
|
|
10
|
+
args: string[];
|
|
11
|
+
/** Glob-style ignore patterns (files excluded entirely from the mount). */
|
|
12
|
+
ignoredPatterns?: string[];
|
|
13
|
+
/** Glob-style readonly patterns (files copied with mode 0o444). */
|
|
14
|
+
readonlyPatterns?: string[];
|
|
15
|
+
/** Extra directory names to exclude from the mount on top of defaults. */
|
|
16
|
+
excludeDirs?: string[];
|
|
17
|
+
/** Extra env vars merged on top of `process.env`. */
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
/** Optional agent name, used in the _MOUNT_README.md "Agent:" line. */
|
|
20
|
+
agentName?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Invoked after the mount is created but before the CLI is spawned.
|
|
23
|
+
* Useful for writing additional files into the mount (overrides, extra docs).
|
|
24
|
+
*/
|
|
25
|
+
onBeforeLaunch?: (mountDir: string) => void | Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Invoked after sync-back completes, before cleanup. Receives the total
|
|
28
|
+
* number of file changes propagated during the run — the sum of autosync
|
|
29
|
+
* activity in both directions (including deletes) and the final mount→
|
|
30
|
+
* project syncBack. Use this as an "anything changed?" signal rather than
|
|
31
|
+
* a strict mount→project count.
|
|
32
|
+
*/
|
|
33
|
+
onAfterSync?: (syncedFileCount: number) => void | Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Auto-sync behavior. By default, bidirectional auto-sync runs during the
|
|
36
|
+
* lifetime of the spawned CLI. Pass `false` to disable, or an options object
|
|
37
|
+
* to tune the scan interval / write-finish debounce.
|
|
38
|
+
*/
|
|
39
|
+
autoSync?: boolean | AutoSyncOptions;
|
|
40
|
+
}
|
|
41
|
+
export interface LaunchOnMountResult {
|
|
42
|
+
exitCode: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a mount of `projectDir` at `mountDir`, spawn `cli` with `args` using
|
|
46
|
+
* the mount as its cwd, forward SIGINT/SIGTERM to the child, sync writable
|
|
47
|
+
* changes back on exit, then clean up the mount. Resolves with the child's
|
|
48
|
+
* exit code.
|
|
49
|
+
*/
|
|
50
|
+
export declare function launchOnMount(opts: LaunchOnMountOptions): Promise<LaunchOnMountResult>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createSymlinkMount } from './symlink-mount.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a mount of `projectDir` at `mountDir`, spawn `cli` with `args` using
|
|
5
|
+
* the mount as its cwd, forward SIGINT/SIGTERM to the child, sync writable
|
|
6
|
+
* changes back on exit, then clean up the mount. Resolves with the child's
|
|
7
|
+
* exit code.
|
|
8
|
+
*/
|
|
9
|
+
export async function launchOnMount(opts) {
|
|
10
|
+
const handle = createSymlinkMount(opts.projectDir, opts.mountDir, {
|
|
11
|
+
ignoredPatterns: opts.ignoredPatterns ?? [],
|
|
12
|
+
readonlyPatterns: opts.readonlyPatterns ?? [],
|
|
13
|
+
excludeDirs: opts.excludeDirs ?? [],
|
|
14
|
+
agentName: opts.agentName,
|
|
15
|
+
});
|
|
16
|
+
let syncedCount = 0;
|
|
17
|
+
let finalized = false;
|
|
18
|
+
let autoSync;
|
|
19
|
+
const finalize = async () => {
|
|
20
|
+
if (finalized)
|
|
21
|
+
return;
|
|
22
|
+
finalized = true;
|
|
23
|
+
try {
|
|
24
|
+
let autoSyncChanges = 0;
|
|
25
|
+
if (autoSync) {
|
|
26
|
+
await autoSync.stop();
|
|
27
|
+
autoSyncChanges = autoSync.totalChanges();
|
|
28
|
+
autoSync = undefined;
|
|
29
|
+
}
|
|
30
|
+
const finalSynced = await handle.syncBack();
|
|
31
|
+
syncedCount = autoSyncChanges + finalSynced;
|
|
32
|
+
if (opts.onAfterSync) {
|
|
33
|
+
await opts.onAfterSync(syncedCount);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
handle.cleanup();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
if (opts.onBeforeLaunch) {
|
|
42
|
+
await opts.onBeforeLaunch(handle.mountDir);
|
|
43
|
+
}
|
|
44
|
+
if (opts.autoSync !== false) {
|
|
45
|
+
const autoSyncOpts = typeof opts.autoSync === 'object' ? opts.autoSync : undefined;
|
|
46
|
+
autoSync = handle.startAutoSync(autoSyncOpts);
|
|
47
|
+
}
|
|
48
|
+
const envVars = {
|
|
49
|
+
...process.env,
|
|
50
|
+
...(opts.env ?? {}),
|
|
51
|
+
};
|
|
52
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
53
|
+
const child = spawn(opts.cli, opts.args, {
|
|
54
|
+
cwd: handle.mountDir,
|
|
55
|
+
stdio: 'inherit',
|
|
56
|
+
env: envVars,
|
|
57
|
+
});
|
|
58
|
+
let resolvedExit = 0;
|
|
59
|
+
let cleanupInProgress;
|
|
60
|
+
const forwardAndCleanup = (signal) => {
|
|
61
|
+
if (!child.killed && child.exitCode === null) {
|
|
62
|
+
try {
|
|
63
|
+
child.kill(signal);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// ignore; we'll rely on 'close' handler
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!cleanupInProgress) {
|
|
70
|
+
cleanupInProgress = new Promise((r) => {
|
|
71
|
+
if (child.exitCode !== null) {
|
|
72
|
+
r();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const t = setTimeout(r, 2000);
|
|
76
|
+
child.once('close', () => {
|
|
77
|
+
clearTimeout(t);
|
|
78
|
+
r();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const onSigint = () => forwardAndCleanup('SIGINT');
|
|
84
|
+
const onSigterm = () => forwardAndCleanup('SIGTERM');
|
|
85
|
+
process.once('SIGINT', onSigint);
|
|
86
|
+
process.once('SIGTERM', onSigterm);
|
|
87
|
+
child.on('error', (err) => {
|
|
88
|
+
process.removeListener('SIGINT', onSigint);
|
|
89
|
+
process.removeListener('SIGTERM', onSigterm);
|
|
90
|
+
reject(err);
|
|
91
|
+
});
|
|
92
|
+
child.on('close', (code, signal) => {
|
|
93
|
+
process.removeListener('SIGINT', onSigint);
|
|
94
|
+
process.removeListener('SIGTERM', onSigterm);
|
|
95
|
+
if (typeof code === 'number') {
|
|
96
|
+
resolvedExit = code;
|
|
97
|
+
}
|
|
98
|
+
else if (signal === 'SIGINT') {
|
|
99
|
+
resolvedExit = 130;
|
|
100
|
+
}
|
|
101
|
+
else if (signal === 'SIGTERM') {
|
|
102
|
+
resolvedExit = 143;
|
|
103
|
+
}
|
|
104
|
+
else if (typeof signal === 'string') {
|
|
105
|
+
// Conventional mapping: 128 + signal number. We don't have the
|
|
106
|
+
// numeric signal handy, so fall back to 1 for unknown signals.
|
|
107
|
+
resolvedExit = 1;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
resolvedExit = 1;
|
|
111
|
+
}
|
|
112
|
+
if (cleanupInProgress) {
|
|
113
|
+
cleanupInProgress.then(() => resolve(resolvedExit));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
resolve(resolvedExit);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
await finalize();
|
|
121
|
+
return { exitCode };
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
await finalize().catch(() => {
|
|
125
|
+
// Already errored; swallow cleanup failure so the original error surfaces.
|
|
126
|
+
});
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AutoSyncHandle, type AutoSyncOptions } from './auto-sync.js';
|
|
2
|
+
export interface SymlinkMountOptions {
|
|
3
|
+
ignoredPatterns: string[];
|
|
4
|
+
readonlyPatterns: string[];
|
|
5
|
+
excludeDirs: string[];
|
|
6
|
+
/**
|
|
7
|
+
* Optional agent name used in the _MOUNT_README.md "Agent:" line.
|
|
8
|
+
* If omitted, the doc uses a generic "agent" value.
|
|
9
|
+
*/
|
|
10
|
+
agentName?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SymlinkMountHandle {
|
|
13
|
+
mountDir: string;
|
|
14
|
+
syncBack(): Promise<number>;
|
|
15
|
+
/**
|
|
16
|
+
* Start bidirectional auto-sync: watches both the mount and project trees
|
|
17
|
+
* with chokidar and runs a full reconcile every `scanIntervalMs` as a
|
|
18
|
+
* safety net. Returns a handle you must `stop()` before teardown.
|
|
19
|
+
*/
|
|
20
|
+
startAutoSync(opts?: AutoSyncOptions): AutoSyncHandle;
|
|
21
|
+
cleanup(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function createSymlinkMount(projectDir: string, mountDir: string, options: SymlinkMountOptions): SymlinkMountHandle;
|
package/{dist/src/cli/commands/on → node_modules/@relayfile/local-mount/dist}/symlink-mount.js
RENAMED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
2
2
|
import ignore from 'ignore';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
import { startAutoSync, } from './auto-sync.js';
|
|
5
|
+
const DEFAULT_EXCLUDED_DIRS = ['.git', 'node_modules'];
|
|
6
|
+
const MOUNT_README_FILENAME = '_MOUNT_README.md';
|
|
7
|
+
const MOUNT_MARKER_FILENAME = '.relayfile-local-mount';
|
|
8
|
+
const MOUNT_MARKER_CONTENT = 'This directory is managed by @relayfile/local-mount. Do not place unrelated files here; the directory will be deleted when the mount is torn down.\n';
|
|
6
9
|
export function createSymlinkMount(projectDir, mountDir, options) {
|
|
7
10
|
const resolvedProjectDir = realpathSync(projectDir);
|
|
8
11
|
const resolvedMountDir = path.resolve(mountDir);
|
|
@@ -13,18 +16,34 @@ export function createSymlinkMount(projectDir, mountDir, options) {
|
|
|
13
16
|
const excludeSet = new Set([...DEFAULT_EXCLUDED_DIRS, ...options.excludeDirs]
|
|
14
17
|
.map((entry) => normalizeRelativePosix(entry).replace(/^\/+|\/+$/g, ''))
|
|
15
18
|
.filter(Boolean));
|
|
16
|
-
|
|
19
|
+
// Guard against mountDir === projectDir. We compare both the realpath'd
|
|
20
|
+
// project dir and the plain resolved project dir so callers that pass the
|
|
21
|
+
// same argument for both are caught even when the path is a symlink (e.g.
|
|
22
|
+
// /tmp → /private/tmp on macOS). The mountDir itself may not yet exist,
|
|
23
|
+
// so we cannot realpath it.
|
|
24
|
+
if (resolvedMountDir === resolvedProjectDir ||
|
|
25
|
+
resolvedMountDir === path.resolve(projectDir)) {
|
|
17
26
|
throw new Error('mountDir must be different from projectDir');
|
|
18
27
|
}
|
|
28
|
+
assertMountDirSafeToRemove(resolvedMountDir, resolvedProjectDir);
|
|
19
29
|
removeMountDir(resolvedMountDir);
|
|
20
30
|
mkdirSync(resolvedMountDir, { recursive: true });
|
|
21
31
|
const realMountDir = realpathSync(resolvedMountDir);
|
|
32
|
+
writeFileSync(path.join(realMountDir, MOUNT_MARKER_FILENAME), MOUNT_MARKER_CONTENT, 'utf8');
|
|
22
33
|
walkProjectTree(resolvedProjectDir, resolvedProjectDir, realMountDir, excludeSet, readonlyMatcher, ignoredMatcher);
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
25
|
-
throw new Error('Failed to create
|
|
34
|
+
const readmePath = resolveSafeCopyTarget(realMountDir, path.join(realMountDir, MOUNT_README_FILENAME));
|
|
35
|
+
if (!readmePath) {
|
|
36
|
+
throw new Error('Failed to create mount readme inside mountDir');
|
|
26
37
|
}
|
|
27
|
-
writeFileSync(
|
|
38
|
+
writeFileSync(readmePath, buildMountReadme(options.agentName, readonlyPatterns, ignoredPatterns), 'utf8');
|
|
39
|
+
const autoSyncContext = {
|
|
40
|
+
realMountDir,
|
|
41
|
+
realProjectDir: resolvedProjectDir,
|
|
42
|
+
isExcluded: (relPosix) => isExcludedPath(relPosix, excludeSet),
|
|
43
|
+
isIgnored: (relPosix, isDir) => isPathMatched(relPosix, ignoredMatcher, isDir),
|
|
44
|
+
isReadonly: (relPosix) => isPathMatched(relPosix, readonlyMatcher),
|
|
45
|
+
isReservedFile: (relPosix) => relPosix === MOUNT_README_FILENAME || relPosix === MOUNT_MARKER_FILENAME,
|
|
46
|
+
};
|
|
28
47
|
return {
|
|
29
48
|
mountDir: resolvedMountDir,
|
|
30
49
|
async syncBack() {
|
|
@@ -37,11 +56,52 @@ export function createSymlinkMount(projectDir, mountDir, options) {
|
|
|
37
56
|
}
|
|
38
57
|
return synced;
|
|
39
58
|
},
|
|
59
|
+
startAutoSync(opts) {
|
|
60
|
+
return startAutoSync(autoSyncContext, opts);
|
|
61
|
+
},
|
|
40
62
|
cleanup() {
|
|
41
63
|
removeMountDir(resolvedMountDir);
|
|
42
64
|
},
|
|
43
65
|
};
|
|
44
66
|
}
|
|
67
|
+
function assertMountDirSafeToRemove(mountDir, projectDir) {
|
|
68
|
+
const resolved = path.resolve(mountDir);
|
|
69
|
+
const parsed = path.parse(resolved);
|
|
70
|
+
// Refuse filesystem roots (posix '/' or a Windows drive root like 'C:\').
|
|
71
|
+
if (resolved === parsed.root) {
|
|
72
|
+
throw new Error(`Refusing to use filesystem root as mountDir: ${resolved}`);
|
|
73
|
+
}
|
|
74
|
+
// Refuse anything that would overlap the project directory (destroying the
|
|
75
|
+
// project would be catastrophic). `path.resolve(projectDir)` avoids following
|
|
76
|
+
// symlinks so both the symlink-target and the literal argument are rejected.
|
|
77
|
+
const resolvedProject = path.resolve(projectDir);
|
|
78
|
+
if (resolved === resolvedProject ||
|
|
79
|
+
resolved.startsWith(`${resolvedProject}${path.sep}`) ||
|
|
80
|
+
resolvedProject.startsWith(`${resolved}${path.sep}`)) {
|
|
81
|
+
throw new Error(`mountDir ${resolved} overlaps projectDir ${resolvedProject}`);
|
|
82
|
+
}
|
|
83
|
+
// If the directory already exists, require it to be a directory we created
|
|
84
|
+
// previously (identified by the mount marker file). Otherwise the caller
|
|
85
|
+
// pointed us at an unrelated directory and removing it would destroy data.
|
|
86
|
+
if (!existsSync(resolved)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let stat;
|
|
90
|
+
try {
|
|
91
|
+
stat = lstatSync(resolved);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
throw new Error(`Failed to stat mountDir ${resolved}: ${err.message}`);
|
|
95
|
+
}
|
|
96
|
+
if (!stat.isDirectory()) {
|
|
97
|
+
throw new Error(`mountDir ${resolved} exists and is not a directory`);
|
|
98
|
+
}
|
|
99
|
+
const markerPath = path.join(resolved, MOUNT_MARKER_FILENAME);
|
|
100
|
+
if (!existsSync(markerPath)) {
|
|
101
|
+
throw new Error(`Refusing to remove ${resolved}: missing ${MOUNT_MARKER_FILENAME} marker. ` +
|
|
102
|
+
`Only directories previously created by createSymlinkMount can be reused as mountDir.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
45
105
|
function walkProjectTree(projectDir, currentDir, mountDir, excludeSet, readonlyMatcher, ignoredMatcher) {
|
|
46
106
|
const entries = readdirSync(currentDir, { withFileTypes: true });
|
|
47
107
|
for (const entry of entries) {
|
|
@@ -134,8 +194,6 @@ function listFiles(baseDir) {
|
|
|
134
194
|
continue;
|
|
135
195
|
const entries = readdirSync(current, { withFileTypes: true });
|
|
136
196
|
for (const entry of entries) {
|
|
137
|
-
if (entry.name === '.relay')
|
|
138
|
-
continue;
|
|
139
197
|
const entryPath = path.join(current, entry.name);
|
|
140
198
|
if (entry.isDirectory()) {
|
|
141
199
|
stack.push(entryPath);
|
|
@@ -159,6 +217,15 @@ function isPathMatched(relPath, matcher, isDirectory = false) {
|
|
|
159
217
|
}
|
|
160
218
|
function hasSameContent(left, right) {
|
|
161
219
|
try {
|
|
220
|
+
const leftStat = statSync(left);
|
|
221
|
+
const rightStat = statSync(right);
|
|
222
|
+
if (leftStat.size !== rightStat.size) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
// Same size: fall back to a full byte comparison. Buffer.equals short-
|
|
226
|
+
// circuits internally but we still read both files; for very large files
|
|
227
|
+
// callers may want a streaming approach, though in practice mounts are
|
|
228
|
+
// dominated by source code where this is cheap.
|
|
162
229
|
const leftContent = readFileSync(left);
|
|
163
230
|
const rightContent = readFileSync(right);
|
|
164
231
|
return leftContent.equals(rightContent);
|
|
@@ -184,7 +251,10 @@ function resolveSyncRelativePath(sourceFile, mountDir, readonlyMatcher, ignoredM
|
|
|
184
251
|
const relative = path.relative(mountDir, sourceFile);
|
|
185
252
|
if (relative === '' || relative.startsWith('..'))
|
|
186
253
|
return null;
|
|
187
|
-
|
|
254
|
+
const relativePosix = normalizeRelativePosix(relative);
|
|
255
|
+
if (relativePosix === MOUNT_README_FILENAME)
|
|
256
|
+
return null;
|
|
257
|
+
if (relativePosix === MOUNT_MARKER_FILENAME)
|
|
188
258
|
return null;
|
|
189
259
|
if (isPathMatched(relative, readonlyMatcher) || isPathMatched(relative, ignoredMatcher))
|
|
190
260
|
return null;
|
|
@@ -277,28 +347,26 @@ function removeMountDir(mountDir) {
|
|
|
277
347
|
// Best-effort cleanup.
|
|
278
348
|
}
|
|
279
349
|
}
|
|
280
|
-
function
|
|
350
|
+
function buildMountReadme(agentName, readonlyPatterns, ignoredPatterns) {
|
|
281
351
|
const readonlyList = readonlyPatterns.length > 0 ? readonlyPatterns.join('\n') : '(none)';
|
|
282
352
|
const ignoredList = ignoredPatterns.length > 0 ? ignoredPatterns.join('\n') : '(none)';
|
|
353
|
+
const agentLine = agentName ? `\nAgent: ${agentName}\n` : '';
|
|
283
354
|
return `# Workspace Permissions
|
|
284
355
|
|
|
285
|
-
This workspace is
|
|
356
|
+
This workspace is a mounted mirror of the project directory.
|
|
286
357
|
File access is controlled by project-local .agentignore and .agentreadonly.
|
|
287
358
|
|
|
288
359
|
## Read-only files (cannot be modified)
|
|
289
|
-
${readonlyList
|
|
360
|
+
${readonlyList}
|
|
290
361
|
|
|
291
362
|
## Hidden files (not available in this workspace)
|
|
292
|
-
${ignoredList
|
|
363
|
+
${ignoredList}
|
|
293
364
|
|
|
294
365
|
## Writable files
|
|
295
366
|
All other files can be read and modified freely.
|
|
296
367
|
|
|
297
368
|
If you get "permission denied", the file is read-only.
|
|
298
|
-
Changes to read-only files
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
Agent: ${agentName}
|
|
302
|
-
`;
|
|
369
|
+
Changes to read-only files are not synced back to the source project.
|
|
370
|
+
Edits or permission changes to read-only files inside this mount may be discarded or overwritten when the mount is recreated.
|
|
371
|
+
${agentLine}`;
|
|
303
372
|
}
|
|
304
|
-
//# sourceMappingURL=symlink-mount.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012 Paul Miller (https://paulmillr.com), Elan Shanker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|