aicomputer 0.1.22 → 0.2.0

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.
@@ -1,75 +0,0 @@
1
- import {
2
- getSSHResilienceConfigLines
3
- } from "./chunk-LGJN26BQ.js";
4
-
5
- // src/lib/ssh-config.ts
6
- import { homedir } from "os";
7
- import { join } from "path";
8
- import { mkdir, readFile, writeFile } from "fs/promises";
9
- var MANAGED_BLOCK_START = "# >>> agentcomputer ssh setup >>>";
10
- var MANAGED_BLOCK_END = "# <<< agentcomputer ssh setup <<<";
11
- async function ensureSSHAliasConfig(options) {
12
- const sshDir = join(homedir(), ".ssh");
13
- const configPath = join(sshDir, "config");
14
- await mkdir(sshDir, { recursive: true, mode: 448 });
15
- let existing = "";
16
- try {
17
- existing = await readFile(configPath, "utf8");
18
- } catch (error) {
19
- if (error.code !== "ENOENT") {
20
- throw error;
21
- }
22
- }
23
- const nextBlock = renderManagedBlock(options);
24
- const managedBlockPattern = new RegExp(
25
- `${escapeRegex(MANAGED_BLOCK_START)}[\\s\\S]*?${escapeRegex(MANAGED_BLOCK_END)}\\n?`,
26
- "m"
27
- );
28
- let nextContents;
29
- if (managedBlockPattern.test(existing)) {
30
- nextContents = existing.replace(managedBlockPattern, nextBlock);
31
- } else {
32
- const normalized = existing.length === 0 ? "" : existing.endsWith("\n") ? existing : `${existing}
33
- `;
34
- nextContents = normalized.length === 0 ? nextBlock : `${normalized}
35
- ${nextBlock}`;
36
- }
37
- const changed = nextContents !== existing;
38
- if (changed) {
39
- await writeFile(configPath, nextContents, { mode: 384 });
40
- }
41
- return {
42
- configPath,
43
- changed
44
- };
45
- }
46
- function renderManagedBlock(options) {
47
- const user = options.user?.trim() || "agentcomputer";
48
- const identityFile = formatIdentityFilePath(options.identityFilePath);
49
- const resilienceLines = getSSHResilienceConfigLines().map((line) => ` ${line}`).join("\n");
50
- return `${MANAGED_BLOCK_START}
51
- Host ${options.alias}
52
- HostName ${options.host}
53
- Port ${options.port}
54
- User ${user}
55
- IdentityFile ${identityFile}
56
- IdentitiesOnly yes
57
- ${resilienceLines}
58
- ${MANAGED_BLOCK_END}
59
- `;
60
- }
61
- function formatIdentityFilePath(path) {
62
- const normalized = path.trim();
63
- const homePath = `${homedir()}/`;
64
- if (normalized.startsWith(homePath)) {
65
- return `~/${normalized.slice(homePath.length)}`;
66
- }
67
- return normalized.replaceAll(" ", "\\ ");
68
- }
69
- function escapeRegex(value) {
70
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
71
- }
72
-
73
- export {
74
- ensureSSHAliasConfig
75
- };
@@ -1,183 +0,0 @@
1
- import {
2
- resolveSystemCommandPath
3
- } from "./chunk-5Y2NWK5I.js";
4
-
5
- // src/lib/mutagen-runtime.ts
6
- import { spawnSync } from "child_process";
7
- import {
8
- chmodSync,
9
- existsSync,
10
- mkdirSync,
11
- renameSync,
12
- rmSync
13
- } from "fs";
14
- import { writeFile } from "fs/promises";
15
- import { homedir } from "os";
16
- import { dirname, join } from "path";
17
- var BUNDLED_MUTAGEN_VERSION = "0.18.1";
18
- var BUNDLED_MUTAGEN_DOWNLOAD_BASE = `https://github.com/mutagen-io/mutagen/releases/download/v${BUNDLED_MUTAGEN_VERSION}`;
19
- var AGENTCOMPUTER_MUTAGEN_PATH_ENV = "AGENTCOMPUTER_MUTAGEN_PATH";
20
- function getBundledMutagenAsset(platform = process.platform, arch = process.arch, homeDirectory = homedir()) {
21
- if (!isSupportedPlatform(platform)) {
22
- return null;
23
- }
24
- const assetArch = resolveMutagenAssetArch(arch);
25
- if (!assetArch) {
26
- return null;
27
- }
28
- const assetName = `mutagen_${platform}_${assetArch}_v${BUNDLED_MUTAGEN_VERSION}.tar.gz`;
29
- const installDir = join(
30
- homeDirectory,
31
- ".agentcomputer",
32
- "tools",
33
- "mutagen",
34
- `v${BUNDLED_MUTAGEN_VERSION}`,
35
- `${platform}-${assetArch}`
36
- );
37
- return {
38
- platform,
39
- arch: assetArch,
40
- version: BUNDLED_MUTAGEN_VERSION,
41
- assetName,
42
- downloadUrl: `${BUNDLED_MUTAGEN_DOWNLOAD_BASE}/${assetName}`,
43
- installDir,
44
- executablePath: join(installDir, "mutagen")
45
- };
46
- }
47
- function hasBundledMutagen() {
48
- const asset = getBundledMutagenAsset();
49
- return asset ? existsSync(asset.executablePath) : false;
50
- }
51
- async function ensureMutagenCommandPath() {
52
- const asset = getBundledMutagenAsset();
53
- if (asset && existsSync(asset.executablePath)) {
54
- return asset.executablePath;
55
- }
56
- const systemPath = resolveSystemCommandPath("mutagen");
57
- if (!asset) {
58
- if (systemPath) {
59
- return systemPath;
60
- }
61
- throw new Error(
62
- `Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}. Install Mutagen manually and rerun \`computer mount\`.`
63
- );
64
- }
65
- try {
66
- return await installBundledMutagen(asset);
67
- } catch (error) {
68
- if (systemPath) {
69
- return systemPath;
70
- }
71
- const reason = error instanceof Error ? error.message : "unknown Mutagen install failure";
72
- throw new Error(
73
- `Failed to install Agent Computer's bundled Mutagen (${reason}). Check your network connection and rerun \`computer mount\`.`
74
- );
75
- }
76
- }
77
- async function ensureBundledMutagenInstalled() {
78
- const asset = getBundledMutagenAsset();
79
- if (!asset) {
80
- throw new Error(
81
- `Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}.`
82
- );
83
- }
84
- return installBundledMutagen(asset);
85
- }
86
- function resolveMutagenCommandPath() {
87
- const overridden = process.env[AGENTCOMPUTER_MUTAGEN_PATH_ENV]?.trim();
88
- if (overridden) {
89
- return overridden;
90
- }
91
- const asset = getBundledMutagenAsset();
92
- if (asset && existsSync(asset.executablePath)) {
93
- return asset.executablePath;
94
- }
95
- const systemPath = resolveSystemCommandPath("mutagen");
96
- if (systemPath) {
97
- return systemPath;
98
- }
99
- if (!asset) {
100
- throw new Error(
101
- `Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}. Install Mutagen manually and rerun \`computer mount\`.`
102
- );
103
- }
104
- throw new Error(
105
- "Mutagen is not installed yet. Re-run `computer mount` and Agent Computer will install its bundled copy."
106
- );
107
- }
108
- async function installBundledMutagen(asset) {
109
- if (existsSync(asset.executablePath)) {
110
- return asset.executablePath;
111
- }
112
- mkdirSync(dirname(asset.installDir), { recursive: true });
113
- const stagingDir = `${asset.installDir}.staging-${process.pid}-${Date.now()}`;
114
- const archivePath = join(stagingDir, asset.assetName);
115
- rmSync(stagingDir, { recursive: true, force: true });
116
- if (existsSync(asset.installDir) && !existsSync(asset.executablePath)) {
117
- rmSync(asset.installDir, { recursive: true, force: true });
118
- }
119
- mkdirSync(stagingDir, { recursive: true });
120
- try {
121
- const response = await fetch(asset.downloadUrl, {
122
- headers: {
123
- "User-Agent": "aicomputer-cli"
124
- }
125
- });
126
- if (!response.ok || !response.body) {
127
- throw new Error(`download failed with status ${response.status}`);
128
- }
129
- await writeFile(archivePath, Buffer.from(await response.arrayBuffer()), {
130
- mode: 384
131
- });
132
- const extract = spawnSync("tar", ["-xzf", archivePath, "-C", stagingDir], {
133
- encoding: "utf8"
134
- });
135
- if (extract.status !== 0) {
136
- throw new Error(
137
- extract.stderr.trim() || extract.stdout.trim() || `failed to extract ${asset.assetName}`
138
- );
139
- }
140
- if (!existsSync(join(stagingDir, "mutagen"))) {
141
- throw new Error("archive did not contain the Mutagen executable");
142
- }
143
- chmodSync(join(stagingDir, "mutagen"), 493);
144
- rmSync(archivePath, { force: true });
145
- try {
146
- renameSync(stagingDir, asset.installDir);
147
- } catch (error) {
148
- if (!existsSync(asset.executablePath)) {
149
- throw error;
150
- }
151
- rmSync(stagingDir, { recursive: true, force: true });
152
- }
153
- return asset.executablePath;
154
- } catch (error) {
155
- rmSync(stagingDir, { recursive: true, force: true });
156
- throw error;
157
- }
158
- }
159
- function isSupportedPlatform(platform) {
160
- return platform === "darwin" || platform === "linux";
161
- }
162
- function resolveMutagenAssetArch(arch) {
163
- if (!isSupportedNodeArch(arch)) {
164
- return null;
165
- }
166
- if (arch === "x64") {
167
- return "amd64";
168
- }
169
- return arch;
170
- }
171
- function isSupportedNodeArch(arch) {
172
- return arch === "arm64" || arch === "x64";
173
- }
174
-
175
- export {
176
- AGENTCOMPUTER_MUTAGEN_PATH_ENV,
177
- getBundledMutagenAsset,
178
- hasBundledMutagen,
179
- ensureMutagenCommandPath,
180
- ensureBundledMutagenInstalled,
181
- resolveMutagenCommandPath,
182
- resolveMutagenAssetArch
183
- };
@@ -1,32 +0,0 @@
1
- // src/lib/upgrade-version.ts
2
- function normalizeVersion(version) {
3
- return version.split("-")[0].split(".").map((part) => Number.parseInt(part, 10)).map((part) => Number.isNaN(part) ? 0 : part);
4
- }
5
- function compareVersions(a, b) {
6
- const left = normalizeVersion(a);
7
- const right = normalizeVersion(b);
8
- const size = Math.max(left.length, right.length);
9
- for (let index = 0; index < size; index += 1) {
10
- const diff = (left[index] ?? 0) - (right[index] ?? 0);
11
- if (diff !== 0) {
12
- return diff;
13
- }
14
- }
15
- return 0;
16
- }
17
- function resolveLatestPublishedVersion(packument) {
18
- const versions = Object.keys(packument.versions ?? {});
19
- if (versions.length === 0) {
20
- throw new Error("Registry response missing published versions");
21
- }
22
- const taggedLatest = packument["dist-tags"]?.latest;
23
- if (taggedLatest && versions.includes(taggedLatest)) {
24
- return taggedLatest;
25
- }
26
- return versions.sort((left, right) => compareVersions(right, left))[0];
27
- }
28
-
29
- export {
30
- compareVersions,
31
- resolveLatestPublishedVersion
32
- };