@tolmete/cli 0.0.0-stage → 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/codex/.codex-plugin/plugin.json +11 -0
- package/codex/hooks/hooks.json +66 -0
- package/codex/runtime/bootstrap.ps1 +91 -0
- package/codex/runtime/bootstrap.sh +147 -0
- package/codex/runtime/tolmete.mjs +1866 -0
- package/codex/runtime/tolmete.ps1 +66 -0
- package/codex/runtime/tolmete.sh +95 -0
- package/install.mjs +173 -0
- package/package.json +11 -4
- package/README.md +0 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Runs the bundled Tolmete program with Node 22 or newer. Windows PowerShell 5.1, no Git Bash.
|
|
2
|
+
# tolmete.ps1 hook called by Codex: exits 0 whatever happens (Cursor's hooks use tolmete.sh)
|
|
3
|
+
# tolmete.ps1 <command> status, login, logout (people)
|
|
4
|
+
# Node comes from ~\.tolmete\node (a portable copy bootstrap.ps1 downloads) or from PATH. When
|
|
5
|
+
# neither is usable, bootstrap.ps1 is started in the background and this exits 0 at once.
|
|
6
|
+
# ASCII only: PowerShell 5.1 reads a script without a byte order mark in the ANSI code page.
|
|
7
|
+
#
|
|
8
|
+
# Node is run as the last command, with no pipeline and no redirection: that way it inherits
|
|
9
|
+
# the hook's stdin and stdout as they are, and the JSON reaches it as the UTF-8 bytes Codex wrote.
|
|
10
|
+
|
|
11
|
+
$ErrorActionPreference = 'Continue'
|
|
12
|
+
|
|
13
|
+
# The Node.js bootstrap.ps1 installs; a test keeps this equal to its version.
|
|
14
|
+
$pinned = '22.23.5'
|
|
15
|
+
|
|
16
|
+
$runtime = $PSScriptRoot
|
|
17
|
+
$bundle = Join-Path $runtime 'tolmete.mjs'
|
|
18
|
+
$root = Join-Path $env:USERPROFILE '.tolmete\node'
|
|
19
|
+
|
|
20
|
+
function Start-Bootstrap {
|
|
21
|
+
# The same rules as bootstrap.ps1: no new attempt for 6 hours after a failure, none while a
|
|
22
|
+
# download holds the lock (30 minutes). Without this every prompt would start a PowerShell
|
|
23
|
+
# when nodejs.org is blocked.
|
|
24
|
+
foreach ($stamp in @(@('.failed', 360), @('.lock', 30))) {
|
|
25
|
+
$item = Get-Item -LiteralPath (Join-Path $root $stamp[0]) -Force -ErrorAction SilentlyContinue
|
|
26
|
+
if ($item -and ((Get-Date) - $item.LastWriteTime).TotalMinutes -lt $stamp[1]) { return }
|
|
27
|
+
}
|
|
28
|
+
# ShellExecute under the hood: the child inherits no pipe, so Codex does not wait for it. It
|
|
29
|
+
# runs in the Windows folder, so it does not hold the repository folder open. Not the profile
|
|
30
|
+
# folder: Start-Process refuses a -WorkingDirectory with [ ] in its name.
|
|
31
|
+
$script = Join-Path $runtime 'bootstrap.ps1'
|
|
32
|
+
try {
|
|
33
|
+
Start-Process -FilePath (Join-Path $PSHOME 'powershell.exe') -WorkingDirectory $env:SystemRoot -WindowStyle Hidden -ArgumentList "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$script`""
|
|
34
|
+
} catch { }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function Find-Portable($filter) {
|
|
38
|
+
Get-ChildItem -LiteralPath $root -Directory -Filter $filter -ErrorAction SilentlyContinue |
|
|
39
|
+
ForEach-Object { Join-Path $_.FullName 'node.exe' } |
|
|
40
|
+
Where-Object { Test-Path -LiteralPath $_ } |
|
|
41
|
+
Select-Object -First 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# The pinned portable Node first. An older one still runs, while the pinned one is fetched.
|
|
45
|
+
$node = Find-Portable "v$pinned-*"
|
|
46
|
+
if (-not $node) {
|
|
47
|
+
$node = Find-Portable 'v22*'
|
|
48
|
+
if ($node) { Start-Bootstrap }
|
|
49
|
+
}
|
|
50
|
+
if (-not $node) {
|
|
51
|
+
$found = Get-Command node.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
52
|
+
if ($found) { $node = $found.Source }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
$hook = ($args.Count -gt 0 -and $args[0] -eq 'hook')
|
|
56
|
+
|
|
57
|
+
if ($node) {
|
|
58
|
+
& $node $bundle @args
|
|
59
|
+
$status = $LASTEXITCODE
|
|
60
|
+
# 64: this Node is older than 22; the program starts nothing else that fails a hook. No status
|
|
61
|
+
# at all: a node.exe that could not start, which is no answer either.
|
|
62
|
+
if ($null -ne $status -and $status -ne 64) { if ($hook) { exit 0 } else { exit $status } }
|
|
63
|
+
}
|
|
64
|
+
Start-Bootstrap
|
|
65
|
+
if (-not $hook) { Write-Output 'Tolmete is preparing the Node.js it needs (about 30 MB, once). Run this again in a minute.' }
|
|
66
|
+
exit 0
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Runs the bundled Tolmete program with Node 22 or newer.
|
|
3
|
+
# tolmete.sh hook called by a hook (Claude Code, Codex or Cursor): never fails, never prints
|
|
4
|
+
# tolmete.sh <command> status, login, logout (skills and people)
|
|
5
|
+
# Node comes from ~/.tolmete/node (a portable copy bootstrap.sh downloads) or from PATH. When
|
|
6
|
+
# neither is usable, bootstrap.sh is started in the background and this exits 0 at once.
|
|
7
|
+
#
|
|
8
|
+
# On Windows every child process of Git Bash costs tens of milliseconds, so the start-up below
|
|
9
|
+
# uses shell built-ins only: no tr, no command substitution unless the path needs converting.
|
|
10
|
+
|
|
11
|
+
# Backslashes to slashes, built-ins only. The result is in $r.
|
|
12
|
+
forward() {
|
|
13
|
+
r=$1
|
|
14
|
+
while :; do
|
|
15
|
+
case $r in
|
|
16
|
+
*\\*) r=${r%%\\*}/${r#*\\} ;;
|
|
17
|
+
*) break ;;
|
|
18
|
+
esac
|
|
19
|
+
done
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# The Node.js bootstrap.sh installs; a test keeps this equal to its VERSION.
|
|
23
|
+
pinned=22.23.5
|
|
24
|
+
|
|
25
|
+
forward "$0"
|
|
26
|
+
self=$r
|
|
27
|
+
base=${USERPROFILE:-$HOME}
|
|
28
|
+
# WSL can pass USERPROFILE through WSLENV, but Node there looks in HOME.
|
|
29
|
+
[ -n "$WSL_DISTRO_NAME" ] && base=$HOME
|
|
30
|
+
forward "$base"
|
|
31
|
+
home=$r
|
|
32
|
+
|
|
33
|
+
# The bundle path goes to node, which is not an MSYS program: it needs C:/..., not /c/..., and
|
|
34
|
+
# MSYS_NO_PATHCONV=1 (common with Docker) turns off the automatic conversion.
|
|
35
|
+
case $self in
|
|
36
|
+
[A-Za-z]:/*) dir=${self%/*} ;;
|
|
37
|
+
*/*) dir=$(cd "${self%/*}" 2>/dev/null && { pwd -W 2>/dev/null || pwd; }) || exit 0 ;;
|
|
38
|
+
*) dir=$(pwd -W 2>/dev/null || pwd) ;;
|
|
39
|
+
esac
|
|
40
|
+
bundle="$dir/tolmete.mjs"
|
|
41
|
+
|
|
42
|
+
bootstrap() {
|
|
43
|
+
if command -v nohup >/dev/null 2>&1; then
|
|
44
|
+
nohup sh "$dir/bootstrap.sh" </dev/null >/dev/null 2>&1 &
|
|
45
|
+
else
|
|
46
|
+
sh "$dir/bootstrap.sh" </dev/null >/dev/null 2>&1 &
|
|
47
|
+
fi
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# The pinned portable Node first. An older one still runs, while the pinned one is fetched.
|
|
51
|
+
portable=
|
|
52
|
+
older=
|
|
53
|
+
for candidate in "$home"/.tolmete/node/v"$pinned"-*/bin/node "$home"/.tolmete/node/v"$pinned"-*/node.exe; do
|
|
54
|
+
if [ -f "$candidate" ]; then
|
|
55
|
+
portable=$candidate
|
|
56
|
+
break
|
|
57
|
+
fi
|
|
58
|
+
done
|
|
59
|
+
if [ -z "$portable" ]; then
|
|
60
|
+
for candidate in "$home"/.tolmete/node/v22*/bin/node "$home"/.tolmete/node/v22*/node.exe; do
|
|
61
|
+
if [ -f "$candidate" ]; then
|
|
62
|
+
portable=$candidate
|
|
63
|
+
older=1
|
|
64
|
+
break
|
|
65
|
+
fi
|
|
66
|
+
done
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
if [ "$1" = "hook" ]; then
|
|
70
|
+
if [ -n "$portable" ]; then
|
|
71
|
+
[ -n "$older" ] && bootstrap
|
|
72
|
+
exec "$portable" "$bundle" "$@" 2>/dev/null
|
|
73
|
+
fi
|
|
74
|
+
if command -v node >/dev/null 2>&1; then
|
|
75
|
+
node "$bundle" "$@" 2>/dev/null && exit 0
|
|
76
|
+
fi
|
|
77
|
+
# No Node, or one older than 22 (the bundle exits 64): fetch the portable one, once.
|
|
78
|
+
bootstrap
|
|
79
|
+
exit 0
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
if [ -n "$portable" ]; then
|
|
83
|
+
[ -n "$older" ] && bootstrap
|
|
84
|
+
exec "$portable" "$bundle" "$@"
|
|
85
|
+
fi
|
|
86
|
+
if command -v node >/dev/null 2>&1; then
|
|
87
|
+
node "$bundle" "$@"
|
|
88
|
+
status=$?
|
|
89
|
+
if [ "$status" -ne 64 ] && [ "$status" -ne 127 ]; then
|
|
90
|
+
exit "$status"
|
|
91
|
+
fi
|
|
92
|
+
fi
|
|
93
|
+
bootstrap
|
|
94
|
+
echo "Tolmete is preparing the Node.js it needs (about 30 MB, once). Run this again in a minute."
|
|
95
|
+
exit 0
|
package/install.mjs
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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.
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { cpSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const CLAUDE_CATALOG = "https://plugins.tolmete.com/marketplace.json";
|
|
13
|
+
const PLUGIN = "tolmete@tolmete";
|
|
14
|
+
|
|
15
|
+
const USAGE = [
|
|
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",
|
|
20
|
+
].join("\n");
|
|
21
|
+
|
|
22
|
+
const say = (line) => process.stdout.write(`${line}\n`);
|
|
23
|
+
const windows = process.platform === "win32";
|
|
24
|
+
|
|
25
|
+
/**
|
|
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.
|
|
28
|
+
*/
|
|
29
|
+
const run = (tool, args, { capture = false, errors = true } = {}) => {
|
|
30
|
+
const options = {
|
|
31
|
+
encoding: "utf8",
|
|
32
|
+
stdio: ["ignore", capture ? "pipe" : "ignore", errors ? "inherit" : "ignore"],
|
|
33
|
+
};
|
|
34
|
+
return windows
|
|
35
|
+
? spawnSync([tool, ...args.map((a) => `"${a}"`)].join(" "), { ...options, shell: true })
|
|
36
|
+
: spawnSync(tool, args, options);
|
|
37
|
+
};
|
|
38
|
+
|
|
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) => {
|
|
46
|
+
const find = (value) => {
|
|
47
|
+
if (!value || typeof value !== "object") return undefined;
|
|
48
|
+
if (typeof value[key] === "string" && (!about || JSON.stringify(value).includes(about))) {
|
|
49
|
+
return value[key];
|
|
50
|
+
}
|
|
51
|
+
return Object.values(value).map(find).find(Boolean);
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
return find(JSON.parse(output.slice(Math.max(0, output.search(/^[{[]/m)))));
|
|
55
|
+
} catch {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
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
|
+
|
|
103
|
+
// Not under ~/.tolmete: signing out deletes the data there.
|
|
104
|
+
const codexMarketplace = () =>
|
|
105
|
+
join(process.env.CODEX_HOME || join(homedir(), ".codex"), "tolmete-marketplace");
|
|
106
|
+
|
|
107
|
+
const writeCodexMarketplace = (dir) => {
|
|
108
|
+
const plugin = fileURLToPath(new URL("./codex", import.meta.url));
|
|
109
|
+
mkdirSync(join(dir, ".agents", "plugins"), { recursive: true });
|
|
110
|
+
cpSync(plugin, join(dir, "plugins", "tolmete"), { recursive: true });
|
|
111
|
+
const marketplace = {
|
|
112
|
+
name: "tolmete",
|
|
113
|
+
interface: { displayName: "Tolmete" },
|
|
114
|
+
plugins: [
|
|
115
|
+
{
|
|
116
|
+
name: "tolmete",
|
|
117
|
+
source: { source: "local", path: "./plugins/tolmete" },
|
|
118
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
119
|
+
category: "Productivity",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
};
|
|
123
|
+
writeFileSync(
|
|
124
|
+
join(dir, ".agents", "plugins", "marketplace.json"),
|
|
125
|
+
`${JSON.stringify(marketplace, null, 2)}\n`,
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
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;
|
|
161
|
+
}
|
|
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.`);
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
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.");
|
|
170
|
+
return removed ? 0 : 1;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
process.exitCode = main(process.argv.slice(2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolmete/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"description": "Installs the Tolmete plugin into Claude Code and Codex CLI. Never sends prompt text.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"tolmete": "install.mjs"
|
|
12
|
+
}
|
|
13
|
+
}
|
package/README.md
DELETED