@tolmete/cli 0.0.0-stage → 0.2.7
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 +112 -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,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `npx @tolmete/cli codex`: installs the Tolmete plugin into Codex CLI from this npm package, so
|
|
3
|
+
// no access to the (private) repository is needed. scripts/release.mjs puts it in the package
|
|
4
|
+
// beside `codex/`, the Codex plugin. Codex takes a local folder as a marketplace.
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { cpSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
const USAGE = [
|
|
12
|
+
"npx @tolmete/cli codex install or update the Tolmete plugin in Codex CLI",
|
|
13
|
+
"npx @tolmete/cli codex --no-login the same, without opening the sign-in",
|
|
14
|
+
"npx @tolmete/cli codex --remove remove it from Codex CLI",
|
|
15
|
+
].join("\n");
|
|
16
|
+
|
|
17
|
+
const say = (line) => process.stdout.write(`${line}\n`);
|
|
18
|
+
const windows = process.platform === "win32";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `codex` is a .cmd file on Windows, which only a shell runs: one command line, arguments quoted.
|
|
22
|
+
* `errors: false` hides the complaint of a command that is allowed to fail.
|
|
23
|
+
*/
|
|
24
|
+
const codex = (args, { capture = false, errors = true } = {}) => {
|
|
25
|
+
const options = {
|
|
26
|
+
encoding: "utf8",
|
|
27
|
+
stdio: ["ignore", capture ? "pipe" : "ignore", errors ? "inherit" : "ignore"],
|
|
28
|
+
};
|
|
29
|
+
return windows
|
|
30
|
+
? spawnSync(["codex", ...args.map((a) => `"${a}"`)].join(" "), { ...options, shell: true })
|
|
31
|
+
: spawnSync("codex", args, options);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** The `installedPath` anywhere in `codex plugin add --json`; a warning may come before it. */
|
|
35
|
+
const installedPath = (output) => {
|
|
36
|
+
const find = (value) => {
|
|
37
|
+
if (!value || typeof value !== "object") return undefined;
|
|
38
|
+
if (typeof value.installedPath === "string") return value.installedPath;
|
|
39
|
+
return Object.values(value).map(find).find(Boolean);
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
return find(JSON.parse(output.slice(Math.max(0, output.search(/^[{[]/m)))));
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Not under ~/.tolmete: signing out deletes the data there.
|
|
49
|
+
const marketplaceDir = () =>
|
|
50
|
+
join(process.env.CODEX_HOME || join(homedir(), ".codex"), "tolmete-marketplace");
|
|
51
|
+
|
|
52
|
+
const writeMarketplace = (dir) => {
|
|
53
|
+
const plugin = fileURLToPath(new URL("./codex", import.meta.url));
|
|
54
|
+
mkdirSync(join(dir, ".agents", "plugins"), { recursive: true });
|
|
55
|
+
cpSync(plugin, join(dir, "plugins", "tolmete"), { recursive: true });
|
|
56
|
+
const marketplace = {
|
|
57
|
+
name: "tolmete",
|
|
58
|
+
interface: { displayName: "Tolmete" },
|
|
59
|
+
plugins: [
|
|
60
|
+
{
|
|
61
|
+
name: "tolmete",
|
|
62
|
+
source: { source: "local", path: "./plugins/tolmete" },
|
|
63
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
64
|
+
category: "Productivity",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
writeFileSync(
|
|
69
|
+
join(dir, ".agents", "plugins", "marketplace.json"),
|
|
70
|
+
`${JSON.stringify(marketplace, null, 2)}\n`,
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const install = (login) => {
|
|
75
|
+
if (codex(["--version"], { errors: false }).status !== 0) {
|
|
76
|
+
say("Codex CLI was not found. Install it first, then run this again.");
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
const dir = marketplaceDir();
|
|
80
|
+
writeMarketplace(dir);
|
|
81
|
+
// A marketplace of this name from another place (the GitHub repository) is replaced.
|
|
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");
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
say("Installed for Codex CLI. Open Codex, run /hooks and trust the Tolmete hooks.");
|
|
92
|
+
say("Nothing is collected until you do. Codex asks again after each update.");
|
|
93
|
+
say("To update, run this command again.");
|
|
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.");
|
|
103
|
+
return removed ? 0 : 1;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const [command, ...flags] = process.argv.slice(2);
|
|
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
|
+
}
|
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.7",
|
|
4
|
+
"description": "Installs the Tolmete plugin into 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