jen-ai 0.0.0 → 0.1.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.
- package/LICENSE +23 -0
- package/README.md +45 -1
- package/cli/api.js +144 -0
- package/cli/browser.js +37 -0
- package/cli/docker.js +172 -0
- package/cli/follow.js +156 -0
- package/cli/jen.js +13 -0
- package/cli/main.js +200 -0
- package/cli/release.js +2 -0
- package/cli/roots.js +61 -0
- package/cli/runtime.js +234 -0
- package/cli/settings.js +128 -0
- package/cli/uninstall.js +104 -0
- package/package.json +13 -4
package/cli/uninstall.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// jen uninstall: deletes everything jen ever made in Docker, then the
|
|
2
|
+
// command's npm package when it was installed globally with npm, since npm
|
|
3
|
+
// runs no script of a package as it's uninstalled. It goes through no
|
|
4
|
+
// runtime, which is removed too, so it works when one can't start.
|
|
5
|
+
import { realpathSync } from "node:fs";
|
|
6
|
+
import { join, sep } from "node:path";
|
|
7
|
+
import { IMAGE_KEYS, Refusal, REGISTRY, registryRepository, runtimeContainer } from "./settings.js";
|
|
8
|
+
export const QUESTION = "this deletes every agent's conversation and files, and can't be undone. Continue? [y/N] ";
|
|
9
|
+
// The package's name on npm.
|
|
10
|
+
const PACKAGE = "jen-ai";
|
|
11
|
+
// The exit code: 0 once everything is removed, 1 when the user declined or a
|
|
12
|
+
// step failed.
|
|
13
|
+
export async function uninstall(ctx, { mainPath, npm }) {
|
|
14
|
+
const { docker, names } = ctx;
|
|
15
|
+
if (!ctx.terminal.interactive)
|
|
16
|
+
throw new Refusal("jen uninstall asks before it deletes anything, so it needs a terminal.");
|
|
17
|
+
const answer = (await ctx.terminal.ask(QUESTION)).trim();
|
|
18
|
+
// A blank line between the answer and what follows.
|
|
19
|
+
ctx.say("");
|
|
20
|
+
if (answer !== "y") {
|
|
21
|
+
ctx.print("nothing was removed.");
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
const failures = [];
|
|
25
|
+
const step = async (what, act) => {
|
|
26
|
+
try {
|
|
27
|
+
await act();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
failures.push(`${what}: ${error instanceof Error ? error.message : String(error)}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const label = `jen.runtime=${names.name}`;
|
|
34
|
+
let agents = 0;
|
|
35
|
+
await step("counting the agents", async () => void (agents = (await docker.volumes([label, "jen.agent"])).length));
|
|
36
|
+
// The runtime first, so none watches its agents go. By name, which also
|
|
37
|
+
// finds one started by hand without the label.
|
|
38
|
+
await step(`removing ${runtimeContainer(names.name)}`, () => docker.remove(runtimeContainer(names.name)));
|
|
39
|
+
await step("listing jen's containers", async () => {
|
|
40
|
+
for (const c of await docker.containers([label]))
|
|
41
|
+
await step(`removing container ${c.name}`, () => docker.remove(c.id));
|
|
42
|
+
});
|
|
43
|
+
// Volumes after containers, since Docker won't remove one in use.
|
|
44
|
+
await step("listing jen's volumes", async () => {
|
|
45
|
+
for (const v of await docker.volumes([label]))
|
|
46
|
+
await step(`removing volume ${v}`, () => docker.removeVolume(v));
|
|
47
|
+
});
|
|
48
|
+
await step(`removing network ${names.name}`, () => docker.removeNetwork(names.name));
|
|
49
|
+
// The images by their current names, and every version of the registry's
|
|
50
|
+
// that the environment doesn't name others in place of, such as one an
|
|
51
|
+
// earlier version left.
|
|
52
|
+
const named = IMAGE_KEYS.map((key) => names[key]);
|
|
53
|
+
const registry = IMAGE_KEYS.filter((key) => !names.overridden.includes(key)).map(registryRepository);
|
|
54
|
+
await step("listing jen's images", async () => {
|
|
55
|
+
if (registry.length === 0)
|
|
56
|
+
return;
|
|
57
|
+
for (const listed of await docker.listImages(`${REGISTRY}/jen-*`)) {
|
|
58
|
+
if (registry.some((repository) => listed.startsWith(`${repository}:`)) && !named.includes(listed))
|
|
59
|
+
named.push(listed);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const images = [];
|
|
63
|
+
for (const image of named) {
|
|
64
|
+
await step(`removing image ${image}`, async () => {
|
|
65
|
+
if ((await docker.imageId(image)) === undefined)
|
|
66
|
+
return;
|
|
67
|
+
await docker.removeImage(image);
|
|
68
|
+
images.push(image);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
ctx.print(`removed ${agents === 1 ? "1 agent" : `${agents} agents`} with their conversations and files, the runtime, the settings${images.length ? ` and the images ${images.join(", ")}` : ""}.`);
|
|
72
|
+
if (failures.length > 0) {
|
|
73
|
+
for (const failure of failures)
|
|
74
|
+
ctx.say(`jen: ${failure}`);
|
|
75
|
+
ctx.say("some of jen is left in Docker, and so is the command, to remove it with. Run jen uninstall again once that's fixed.");
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
if (await installedWithNpm(mainPath, npm)) {
|
|
79
|
+
const output = await npm("npm", ["uninstall", "-g", PACKAGE]);
|
|
80
|
+
if (output.code !== 0) {
|
|
81
|
+
ctx.say(`jen: npm uninstall -g ${PACKAGE} failed: ${output.stderr.trim()}`);
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
ctx.print(`uninstalled the ${PACKAGE} package. jen is gone.`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
ctx.print("the jen command itself wasn't installed with npm install -g, so remove it the way it was installed. From a checkout linked with npm link, that's: npm unlink -g jen");
|
|
88
|
+
}
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
// Whether the running main.ts, or the package's main.js, is inside the
|
|
92
|
+
// global npm folder's package.
|
|
93
|
+
async function installedWithNpm(mainPath, npm) {
|
|
94
|
+
const output = await npm("npm", ["root", "-g"]);
|
|
95
|
+
if (output.code !== 0)
|
|
96
|
+
return false;
|
|
97
|
+
try {
|
|
98
|
+
const root = realpathSync(output.stdout.trim());
|
|
99
|
+
return realpathSync(mainPath).startsWith(join(root, PACKAGE) + sep);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jen-ai",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"jen": "cli/jen.js"
|
|
7
|
+
},
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=26"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/reveer-ai/jen.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "SEE LICENSE IN LICENSE"
|
|
7
16
|
}
|