@tolmete/cli 0.2.7 → 0.2.8
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/install.mjs +110 -49
- package/package.json +2 -2
package/install.mjs
CHANGED
|
@@ -1,41 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// `npx @tolmete/cli
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// `npx @tolmete/cli <tool>`: installs the Tolmete plugin without access to the (private) repository.
|
|
3
|
+
// Claude Code gets it from the catalog on plugins.tolmete.com, so its auto-update keeps working.
|
|
4
|
+
// Codex only takes git or a local folder, so scripts/release.mjs puts its plugin in this package,
|
|
5
|
+
// as `codex/` beside this file.
|
|
5
6
|
import { spawnSync } from "node:child_process";
|
|
6
7
|
import { cpSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
7
8
|
import { homedir } from "node:os";
|
|
8
9
|
import { join } from "node:path";
|
|
9
10
|
import { fileURLToPath } from "node:url";
|
|
10
11
|
|
|
12
|
+
const CLAUDE_CATALOG = "https://plugins.tolmete.com/marketplace.json";
|
|
13
|
+
const PLUGIN = "tolmete@tolmete";
|
|
14
|
+
|
|
11
15
|
const USAGE = [
|
|
12
|
-
"npx @tolmete/cli
|
|
13
|
-
"npx @tolmete/cli codex
|
|
14
|
-
"
|
|
16
|
+
"npx @tolmete/cli claude install or update the Tolmete plugin in Claude Code",
|
|
17
|
+
"npx @tolmete/cli codex install or update the Tolmete plugin in Codex CLI",
|
|
18
|
+
" --no-login do not open the sign-in",
|
|
19
|
+
" --remove remove the plugin from that tool",
|
|
15
20
|
].join("\n");
|
|
16
21
|
|
|
17
22
|
const say = (line) => process.stdout.write(`${line}\n`);
|
|
18
23
|
const windows = process.platform === "win32";
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
|
-
* `
|
|
22
|
-
* `errors: false` hides the complaint of a command that is allowed to fail.
|
|
26
|
+
* Runs `claude` or `codex`. On Windows they can be .cmd files, which only a shell runs: one command
|
|
27
|
+
* line, arguments quoted. `errors: false` hides the complaint of a command that is allowed to fail.
|
|
23
28
|
*/
|
|
24
|
-
const
|
|
29
|
+
const run = (tool, args, { capture = false, errors = true } = {}) => {
|
|
25
30
|
const options = {
|
|
26
31
|
encoding: "utf8",
|
|
27
32
|
stdio: ["ignore", capture ? "pipe" : "ignore", errors ? "inherit" : "ignore"],
|
|
28
33
|
};
|
|
29
34
|
return windows
|
|
30
|
-
? spawnSync([
|
|
31
|
-
: spawnSync(
|
|
35
|
+
? spawnSync([tool, ...args.map((a) => `"${a}"`)].join(" "), { ...options, shell: true })
|
|
36
|
+
: spawnSync(tool, args, options);
|
|
32
37
|
};
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const works = (tool, args, options) => run(tool, args, options).status === 0;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The first `key` anywhere in a command's JSON, in an entry that names `about` when one is given.
|
|
43
|
+
* A warning line may come before the JSON.
|
|
44
|
+
*/
|
|
45
|
+
const findInJson = (output, key, about) => {
|
|
36
46
|
const find = (value) => {
|
|
37
47
|
if (!value || typeof value !== "object") return undefined;
|
|
38
|
-
if (typeof value
|
|
48
|
+
if (typeof value[key] === "string" && (!about || JSON.stringify(value).includes(about))) {
|
|
49
|
+
return value[key];
|
|
50
|
+
}
|
|
39
51
|
return Object.values(value).map(find).find(Boolean);
|
|
40
52
|
};
|
|
41
53
|
try {
|
|
@@ -45,11 +57,54 @@ const installedPath = (output) => {
|
|
|
45
57
|
}
|
|
46
58
|
};
|
|
47
59
|
|
|
60
|
+
const runtimeOf = (path) => {
|
|
61
|
+
const runtime = path && join(path, "runtime", "tolmete.mjs");
|
|
62
|
+
return runtime && existsSync(runtime) ? runtime : null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const withNode = (runtime, command) =>
|
|
66
|
+
spawnSync(process.execPath, [runtime, command], { stdio: "inherit" }).status ?? 1;
|
|
67
|
+
|
|
68
|
+
const signIn = (runtime, login) => {
|
|
69
|
+
if (!login) return 0;
|
|
70
|
+
say("Starting the sign-in ...");
|
|
71
|
+
return withNode(runtime, "login");
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const claude = {
|
|
75
|
+
name: "Claude Code",
|
|
76
|
+
install: (login) => {
|
|
77
|
+
// A `tolmete` marketplace from another place (the GitHub repository) is in the way of the add.
|
|
78
|
+
if (!works("claude", ["plugin", "marketplace", "add", CLAUDE_CATALOG], { errors: false })) {
|
|
79
|
+
run("claude", ["plugin", "marketplace", "remove", "tolmete"], { errors: false });
|
|
80
|
+
if (!works("claude", ["plugin", "marketplace", "add", CLAUDE_CATALOG])) return 1;
|
|
81
|
+
}
|
|
82
|
+
// `add` and `install` leave what is already there as it is: the updates make a second run one.
|
|
83
|
+
run("claude", ["plugin", "marketplace", "update", "tolmete"], { errors: false });
|
|
84
|
+
run("claude", ["plugin", "install", PLUGIN]);
|
|
85
|
+
run("claude", ["plugin", "update", PLUGIN], { errors: false });
|
|
86
|
+
const listed = run("claude", ["plugin", "list", "--json"], { capture: true });
|
|
87
|
+
const runtime = runtimeOf(findInJson(listed.stdout ?? "", "installPath", PLUGIN));
|
|
88
|
+
if (!runtime) {
|
|
89
|
+
say("The plugin did not install. Run /plugin in Claude Code.");
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
say("Installed for Claude Code. Close it and open it again.");
|
|
93
|
+
withNode(runtime, "auto-update");
|
|
94
|
+
return signIn(runtime, login);
|
|
95
|
+
},
|
|
96
|
+
remove: () => {
|
|
97
|
+
const removed = works("claude", ["plugin", "uninstall", PLUGIN]);
|
|
98
|
+
run("claude", ["plugin", "marketplace", "remove", "tolmete"], { errors: false });
|
|
99
|
+
return removed;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
48
103
|
// Not under ~/.tolmete: signing out deletes the data there.
|
|
49
|
-
const
|
|
104
|
+
const codexMarketplace = () =>
|
|
50
105
|
join(process.env.CODEX_HOME || join(homedir(), ".codex"), "tolmete-marketplace");
|
|
51
106
|
|
|
52
|
-
const
|
|
107
|
+
const writeCodexMarketplace = (dir) => {
|
|
53
108
|
const plugin = fileURLToPath(new URL("./codex", import.meta.url));
|
|
54
109
|
mkdirSync(join(dir, ".agents", "plugins"), { recursive: true });
|
|
55
110
|
cpSync(plugin, join(dir, "plugins", "tolmete"), { recursive: true });
|
|
@@ -71,42 +126,48 @@ const writeMarketplace = (dir) => {
|
|
|
71
126
|
);
|
|
72
127
|
};
|
|
73
128
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
129
|
+
const codex = {
|
|
130
|
+
name: "Codex CLI",
|
|
131
|
+
install: (login) => {
|
|
132
|
+
const dir = codexMarketplace();
|
|
133
|
+
writeCodexMarketplace(dir);
|
|
134
|
+
// A marketplace of this name from another place (the GitHub repository) is replaced.
|
|
135
|
+
run("codex", ["plugin", "marketplace", "remove", "tolmete"], { errors: false });
|
|
136
|
+
if (!works("codex", ["plugin", "marketplace", "add", dir])) return 1;
|
|
137
|
+
const added = run("codex", ["plugin", "add", PLUGIN, "--json"], { capture: true });
|
|
138
|
+
const runtime = runtimeOf(findInJson(added.stdout ?? "", "installedPath"));
|
|
139
|
+
if (!runtime) {
|
|
140
|
+
say(`The plugin did not install. Run: codex plugin add ${PLUGIN}`);
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
say("Installed for Codex CLI. Open Codex, run /hooks and trust the Tolmete hooks.");
|
|
144
|
+
say("Nothing is collected until you do. Codex asks again after each update.");
|
|
145
|
+
say("To update, run this command again.");
|
|
146
|
+
return signIn(runtime, login);
|
|
147
|
+
},
|
|
148
|
+
remove: () => {
|
|
149
|
+
const removed = works("codex", ["plugin", "remove", PLUGIN]);
|
|
150
|
+
run("codex", ["plugin", "marketplace", "remove", "tolmete"], { errors: false });
|
|
151
|
+
return removed;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const TOOLS = { claude, codex };
|
|
156
|
+
|
|
157
|
+
const main = ([command, ...flags]) => {
|
|
158
|
+
if (!Object.hasOwn(TOOLS, command ?? "")) {
|
|
159
|
+
say(USAGE);
|
|
160
|
+
return command === undefined || command === "--help" ? 0 : 2;
|
|
78
161
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
codex(["plugin", "marketplace", "remove", "tolmete"], { errors: false });
|
|
83
|
-
if (codex(["plugin", "marketplace", "add", dir]).status !== 0) return 1;
|
|
84
|
-
const added = codex(["plugin", "add", "tolmete@tolmete", "--json"], { capture: true });
|
|
85
|
-
const path = installedPath(added.stdout ?? "");
|
|
86
|
-
const runtime = path && join(path, "runtime", "tolmete.mjs");
|
|
87
|
-
if (!runtime || !existsSync(runtime)) {
|
|
88
|
-
say("The plugin did not install. Run: codex plugin add tolmete@tolmete");
|
|
162
|
+
const tool = TOOLS[command];
|
|
163
|
+
if (!works(command, ["--version"], { errors: false })) {
|
|
164
|
+
say(`${tool.name} was not found. Install it first, then run this again.`);
|
|
89
165
|
return 1;
|
|
90
166
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
say("
|
|
94
|
-
if (!login) return 0;
|
|
95
|
-
say("Starting the sign-in ...");
|
|
96
|
-
return spawnSync(process.execPath, [runtime, "login"], { stdio: "inherit" }).status ?? 1;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const remove = () => {
|
|
100
|
-
const removed = codex(["plugin", "remove", "tolmete@tolmete"]).status === 0;
|
|
101
|
-
codex(["plugin", "marketplace", "remove", "tolmete"], { errors: false });
|
|
102
|
-
say(removed ? "Removed from Codex CLI." : "The Tolmete plugin could not be removed.");
|
|
167
|
+
if (!flags.includes("--remove")) return tool.install(!flags.includes("--no-login"));
|
|
168
|
+
const removed = tool.remove();
|
|
169
|
+
say(removed ? `Removed from ${tool.name}.` : "The Tolmete plugin could not be removed.");
|
|
103
170
|
return removed ? 0 : 1;
|
|
104
171
|
};
|
|
105
172
|
|
|
106
|
-
|
|
107
|
-
if (command !== "codex") {
|
|
108
|
-
say(USAGE);
|
|
109
|
-
process.exitCode = command === undefined || command === "--help" ? 0 : 2;
|
|
110
|
-
} else {
|
|
111
|
-
process.exitCode = flags.includes("--remove") ? remove() : install(!flags.includes("--no-login"));
|
|
112
|
-
}
|
|
173
|
+
process.exitCode = main(process.argv.slice(2));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolmete/cli",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Installs the Tolmete plugin into Codex CLI. Never sends prompt text.",
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"description": "Installs the Tolmete plugin into Claude Code and Codex CLI. Never sends prompt text.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|