aicomputer 0.1.14 → 0.1.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.
@@ -0,0 +1,184 @@
1
+ // src/lib/mount-config.ts
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ readFileSync,
6
+ renameSync,
7
+ rmSync,
8
+ writeFileSync
9
+ } from "fs";
10
+ import { homedir } from "os";
11
+ import { join } from "path";
12
+ var MOUNT_SERVICE_LABEL = "ai.agentcomputer.mount";
13
+ function getDefaultMountRoot() {
14
+ return join(homedir(), "agentcomputer");
15
+ }
16
+ function getMountStateDir() {
17
+ return join(homedir(), ".computer", "mount");
18
+ }
19
+ function getMountPaths(rootPath = getDefaultMountRoot()) {
20
+ const stateDir = getMountStateDir();
21
+ return {
22
+ stateDir,
23
+ rootPath,
24
+ configPath: join(stateDir, "config.json"),
25
+ statusPath: join(stateDir, "status.json"),
26
+ socketPath: join(stateDir, "control.sock"),
27
+ controllerLockPath: join(stateDir, "controller.lock.json"),
28
+ handlesDir: join(stateDir, "handles"),
29
+ sshToolsDir: join(stateDir, "ssh-tools"),
30
+ staleDir: join(stateDir, "stale")
31
+ };
32
+ }
33
+ function getMountHandlePaths(handle, rootPath = getDefaultMountRoot()) {
34
+ const paths = getMountPaths(rootPath);
35
+ const stateDir = join(paths.handlesDir, handle);
36
+ return {
37
+ stateDir,
38
+ metaPath: join(stateDir, "meta.json"),
39
+ sshToolsDir: join(stateDir, "ssh-tools")
40
+ };
41
+ }
42
+ function defaultMountServiceConfig() {
43
+ return {
44
+ alias: "agentcomputer.ai",
45
+ host: "ssh.agentcomputer.ai",
46
+ port: 443,
47
+ rootPath: getDefaultMountRoot(),
48
+ pollIntervalMs: 5e3,
49
+ connectTimeoutSeconds: 5
50
+ };
51
+ }
52
+ function ensureMountDirectories(paths) {
53
+ for (const directory of [
54
+ paths.stateDir,
55
+ paths.handlesDir,
56
+ paths.sshToolsDir,
57
+ paths.staleDir
58
+ ]) {
59
+ if (!existsSync(directory)) {
60
+ mkdirSync(directory, { recursive: true, mode: 448 });
61
+ }
62
+ }
63
+ }
64
+ function ensureHandleDirectories(handle, rootPath) {
65
+ const handlePaths = getMountHandlePaths(handle, rootPath);
66
+ for (const directory of [handlePaths.stateDir, handlePaths.sshToolsDir]) {
67
+ if (!existsSync(directory)) {
68
+ mkdirSync(directory, { recursive: true, mode: 448 });
69
+ }
70
+ }
71
+ return handlePaths;
72
+ }
73
+ function readMountConfig() {
74
+ const defaults = defaultMountServiceConfig();
75
+ const paths = getMountPaths(defaults.rootPath);
76
+ if (!existsSync(paths.configPath)) {
77
+ return null;
78
+ }
79
+ try {
80
+ const raw = JSON.parse(readFileSync(paths.configPath, "utf8"));
81
+ return {
82
+ alias: typeof raw.alias === "string" && raw.alias.trim() ? raw.alias.trim() : defaults.alias,
83
+ host: typeof raw.host === "string" && raw.host.trim() ? raw.host.trim() : defaults.host,
84
+ port: typeof raw.port === "number" ? raw.port : defaults.port,
85
+ rootPath: typeof raw.rootPath === "string" && raw.rootPath.trim() ? raw.rootPath.trim() : defaults.rootPath,
86
+ pollIntervalMs: typeof raw.pollIntervalMs === "number" && raw.pollIntervalMs > 0 ? raw.pollIntervalMs : defaults.pollIntervalMs,
87
+ connectTimeoutSeconds: typeof raw.connectTimeoutSeconds === "number" && raw.connectTimeoutSeconds > 0 ? raw.connectTimeoutSeconds : defaults.connectTimeoutSeconds
88
+ };
89
+ } catch {
90
+ return null;
91
+ }
92
+ }
93
+ function writeMountConfig(config) {
94
+ const paths = getMountPaths(config.rootPath);
95
+ ensureMountDirectories(paths);
96
+ writeJSONFile(paths.configPath, config);
97
+ }
98
+ function readMountStatusSnapshot(rootPath = getDefaultMountRoot()) {
99
+ const paths = getMountPaths(rootPath);
100
+ if (!existsSync(paths.statusPath)) {
101
+ return null;
102
+ }
103
+ try {
104
+ return JSON.parse(readFileSync(paths.statusPath, "utf8"));
105
+ } catch {
106
+ return null;
107
+ }
108
+ }
109
+ function writeMountStatusSnapshot(snapshot, rootPath = getDefaultMountRoot()) {
110
+ const paths = getMountPaths(rootPath);
111
+ ensureMountDirectories(paths);
112
+ writeJSONFile(paths.statusPath, snapshot);
113
+ }
114
+ function readMountControllerLock(rootPath = getDefaultMountRoot()) {
115
+ const paths = getMountPaths(rootPath);
116
+ if (!existsSync(paths.controllerLockPath)) {
117
+ return null;
118
+ }
119
+ try {
120
+ return JSON.parse(readFileSync(paths.controllerLockPath, "utf8"));
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+ function writeMountControllerLock(lock, rootPath = getDefaultMountRoot()) {
126
+ const paths = getMountPaths(rootPath);
127
+ ensureMountDirectories(paths);
128
+ writeJSONFile(paths.controllerLockPath, lock);
129
+ }
130
+ function removeMountControllerLock(rootPath = getDefaultMountRoot()) {
131
+ const paths = getMountPaths(rootPath);
132
+ try {
133
+ rmSync(paths.controllerLockPath, { force: true });
134
+ } catch {
135
+ }
136
+ }
137
+ function readMountHandleMeta(handle, rootPath = getDefaultMountRoot()) {
138
+ const paths = getMountHandlePaths(handle, rootPath);
139
+ if (!existsSync(paths.metaPath)) {
140
+ return null;
141
+ }
142
+ try {
143
+ return JSON.parse(readFileSync(paths.metaPath, "utf8"));
144
+ } catch {
145
+ return null;
146
+ }
147
+ }
148
+ function writeMountHandleMeta(handle, meta, rootPath = getDefaultMountRoot()) {
149
+ const paths = ensureHandleDirectories(handle, rootPath);
150
+ writeJSONFile(paths.metaPath, meta);
151
+ }
152
+ function removeMountHandleState(handle, rootPath = getDefaultMountRoot()) {
153
+ const paths = getMountHandlePaths(handle, rootPath);
154
+ try {
155
+ rmSync(paths.stateDir, { recursive: true, force: true });
156
+ } catch {
157
+ }
158
+ }
159
+ function writeJSONFile(path, value) {
160
+ const tempFile = `${path}.${process.pid}.tmp`;
161
+ writeFileSync(tempFile, JSON.stringify(value, null, 2), { mode: 384 });
162
+ renameSync(tempFile, path);
163
+ }
164
+
165
+ export {
166
+ MOUNT_SERVICE_LABEL,
167
+ getDefaultMountRoot,
168
+ getMountStateDir,
169
+ getMountPaths,
170
+ getMountHandlePaths,
171
+ defaultMountServiceConfig,
172
+ ensureMountDirectories,
173
+ ensureHandleDirectories,
174
+ readMountConfig,
175
+ writeMountConfig,
176
+ readMountStatusSnapshot,
177
+ writeMountStatusSnapshot,
178
+ readMountControllerLock,
179
+ writeMountControllerLock,
180
+ removeMountControllerLock,
181
+ readMountHandleMeta,
182
+ writeMountHandleMeta,
183
+ removeMountHandleState
184
+ };
@@ -0,0 +1,70 @@
1
+ // src/lib/mount-host.ts
2
+ import { spawnSync } from "child_process";
3
+ function getMountHostValidationIssues() {
4
+ return evaluateMountHostValidation({
5
+ platform: process.platform,
6
+ hasMutagen: hasCommand("mutagen"),
7
+ hasSsh: hasCommand("ssh"),
8
+ hasScp: hasCommand("scp")
9
+ });
10
+ }
11
+ function formatMountHostInstallGuidance(issues) {
12
+ const lines = [];
13
+ for (const issue of issues) {
14
+ switch (issue.code) {
15
+ case "unsupported-platform":
16
+ lines.push("Supported today: macOS and Linux terminals with Mutagen and OpenSSH installed.");
17
+ break;
18
+ case "missing-mutagen":
19
+ lines.push("Install Mutagen, then rerun `computer mount`.");
20
+ break;
21
+ case "missing-ssh":
22
+ case "missing-scp":
23
+ lines.push("Install OpenSSH client tools so both `ssh` and `scp` are available on PATH.");
24
+ break;
25
+ default:
26
+ lines.push(issue.message);
27
+ break;
28
+ }
29
+ }
30
+ return lines;
31
+ }
32
+ function evaluateMountHostValidation(input) {
33
+ const issues = [];
34
+ if (!["darwin", "linux"].includes(input.platform)) {
35
+ issues.push({
36
+ code: "unsupported-platform",
37
+ message: "computer mount currently supports macOS and Linux terminals only"
38
+ });
39
+ return issues;
40
+ }
41
+ if (!input.hasMutagen) {
42
+ issues.push({
43
+ code: "missing-mutagen",
44
+ message: "mutagen is not installed. Install Mutagen before using computer mount."
45
+ });
46
+ }
47
+ if (!input.hasSsh) {
48
+ issues.push({
49
+ code: "missing-ssh",
50
+ message: "`ssh` is not installed or not available on PATH."
51
+ });
52
+ }
53
+ if (!input.hasScp) {
54
+ issues.push({
55
+ code: "missing-scp",
56
+ message: "`scp` is not installed or not available on PATH."
57
+ });
58
+ }
59
+ return issues;
60
+ }
61
+ function hasCommand(command) {
62
+ const result = spawnSync("which", [command], { stdio: "ignore" });
63
+ return result.status === 0;
64
+ }
65
+
66
+ export {
67
+ getMountHostValidationIssues,
68
+ formatMountHostInstallGuidance,
69
+ evaluateMountHostValidation
70
+ };