@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,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tolmete",
|
|
3
|
+
"displayName": "Tolmete",
|
|
4
|
+
"version": "0.2.2",
|
|
5
|
+
"description": "Connects Codex CLI to Tolmete and sends AI usage statistics, never prompt text.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Tolmete"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": "https://github.com/Tolmete/tolmete-plugin"
|
|
11
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "sh \"${PLUGIN_ROOT}/runtime/tolmete.sh\" hook; exit 0",
|
|
9
|
+
"commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"${PLUGIN_ROOT}/runtime/tolmete.ps1\" hook",
|
|
10
|
+
"timeout": 10
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"UserPromptSubmit": [
|
|
16
|
+
{
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "sh \"${PLUGIN_ROOT}/runtime/tolmete.sh\" hook; exit 0",
|
|
21
|
+
"commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"${PLUGIN_ROOT}/runtime/tolmete.ps1\" hook",
|
|
22
|
+
"timeout": 10,
|
|
23
|
+
"async": true
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"PostModelRequest": [
|
|
29
|
+
{
|
|
30
|
+
"hooks": [
|
|
31
|
+
{
|
|
32
|
+
"type": "command",
|
|
33
|
+
"command": "sh \"${PLUGIN_ROOT}/runtime/tolmete.sh\" hook; exit 0",
|
|
34
|
+
"commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"${PLUGIN_ROOT}/runtime/tolmete.ps1\" hook",
|
|
35
|
+
"timeout": 10,
|
|
36
|
+
"async": true
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"Stop": [
|
|
42
|
+
{
|
|
43
|
+
"hooks": [
|
|
44
|
+
{
|
|
45
|
+
"type": "command",
|
|
46
|
+
"command": "sh \"${PLUGIN_ROOT}/runtime/tolmete.sh\" hook; exit 0",
|
|
47
|
+
"commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"${PLUGIN_ROOT}/runtime/tolmete.ps1\" hook",
|
|
48
|
+
"timeout": 10
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"SessionEnd": [
|
|
54
|
+
{
|
|
55
|
+
"hooks": [
|
|
56
|
+
{
|
|
57
|
+
"type": "command",
|
|
58
|
+
"command": "sh \"${PLUGIN_ROOT}/runtime/tolmete.sh\" hook; exit 0",
|
|
59
|
+
"commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"${PLUGIN_ROOT}/runtime/tolmete.ps1\" hook",
|
|
60
|
+
"timeout": 3
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Downloads the pinned portable Node.js into ~\.tolmete\node and checks its SHA-256.
|
|
2
|
+
# Windows PowerShell 5.1, no Git Bash. No admin rights, no PATH change, nothing printed. Started
|
|
3
|
+
# in the background by tolmete.ps1 when no Node 22 is found; a lock and a failure stamp keep it
|
|
4
|
+
# from running over and over. It is the PowerShell twin of bootstrap.sh and shares its names
|
|
5
|
+
# (.lock, .failed, .tmp-*), so the two exclude each other.
|
|
6
|
+
# The version and the two hashes also sit in bootstrap.sh and scripts/install.ps1; a test keeps
|
|
7
|
+
# them in step. The hashes come from https://nodejs.org/dist/v22.23.5/SHASUMS256.txt
|
|
8
|
+
# ASCII only: PowerShell 5.1 reads a script without a byte order mark in the ANSI code page.
|
|
9
|
+
|
|
10
|
+
$ErrorActionPreference = 'Stop'
|
|
11
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
12
|
+
# Started from pwsh 7, this process inherits a module path that lists the PowerShell 7 modules first,
|
|
13
|
+
# and their Utility manifest hides Get-FileHash and Expand-Archive. The process is ours: reset it.
|
|
14
|
+
$env:PSModulePath = Join-Path $PSHOME 'Modules'
|
|
15
|
+
|
|
16
|
+
$version = '22.23.5'
|
|
17
|
+
$hashes = @{
|
|
18
|
+
'win-x64' = '4a191082e9706866830379d577d2cc8a50c776fcd9436a8d061b063ed0d9a0e3'
|
|
19
|
+
'win-arm64' = 'c1856817f611738c77534efbff8a5a17990593eab24046bc8d2c23a77a160d13'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function Get-Age($path) {
|
|
23
|
+
((Get-Date) - (Get-Item -LiteralPath $path -Force).LastWriteTime).TotalMinutes
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
28
|
+
$arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
|
|
29
|
+
$platform = if ($arch -eq 'ARM64') { 'win-arm64' } else { 'win-x64' }
|
|
30
|
+
$name = "node-v$version-$platform"
|
|
31
|
+
$root = Join-Path $env:USERPROFILE '.tolmete\node'
|
|
32
|
+
$final = Join-Path $root "v$version-$platform"
|
|
33
|
+
$lock = Join-Path $root '.lock'
|
|
34
|
+
$failed = Join-Path $root '.failed'
|
|
35
|
+
New-Item -ItemType Directory -Force -Path $root | Out-Null
|
|
36
|
+
|
|
37
|
+
# Older copies are of no use once the pinned one is there. One that is still running cannot
|
|
38
|
+
# be deleted; that is left for the next run.
|
|
39
|
+
function Remove-Older {
|
|
40
|
+
Get-ChildItem -LiteralPath $root -Directory -Filter 'v22*' | Where-Object { $_.FullName -ne $final } |
|
|
41
|
+
ForEach-Object { Remove-Item -Recurse -Force -LiteralPath $_.FullName -ErrorAction SilentlyContinue }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# A download that was killed leaves its folder behind.
|
|
45
|
+
Get-ChildItem -LiteralPath $root -Directory -Filter '.tmp-*' | Where-Object { (Get-Age $_.FullName) -gt 60 } |
|
|
46
|
+
ForEach-Object { Remove-Item -Recurse -Force -LiteralPath $_.FullName -ErrorAction SilentlyContinue }
|
|
47
|
+
|
|
48
|
+
if (Test-Path -LiteralPath (Join-Path $final 'node.exe')) { Remove-Older; exit 0 }
|
|
49
|
+
|
|
50
|
+
# No new attempt for 6 hours after a failure.
|
|
51
|
+
if ((Test-Path -LiteralPath $failed) -and (Get-Age $failed) -lt 360) { exit 0 }
|
|
52
|
+
|
|
53
|
+
# One download at a time; a lock older than 30 minutes belongs to a dead process.
|
|
54
|
+
if ((Test-Path -LiteralPath $lock) -and (Get-Age $lock) -gt 30) { Remove-Item -Recurse -Force -LiteralPath $lock -ErrorAction SilentlyContinue }
|
|
55
|
+
try { New-Item -ItemType Directory -Path $lock -ErrorAction Stop | Out-Null } catch { exit 0 }
|
|
56
|
+
|
|
57
|
+
$temp = Join-Path $root ".tmp-$PID"
|
|
58
|
+
try {
|
|
59
|
+
New-Item -ItemType Directory -Force -Path $temp | Out-Null
|
|
60
|
+
$zip = Join-Path $temp "$name.zip"
|
|
61
|
+
Invoke-WebRequest -UseBasicParsing -TimeoutSec 900 -Uri "https://nodejs.org/dist/v$version/$name.zip" -OutFile $zip
|
|
62
|
+
if ((Get-FileHash -Algorithm SHA256 -LiteralPath $zip).Hash.ToLowerInvariant() -ne $hashes[$platform]) { throw 'checksum' }
|
|
63
|
+
Expand-Archive -LiteralPath $zip -DestinationPath (Join-Path $temp 'unpacked')
|
|
64
|
+
# It must run here: a Node that unpacks and never starts would be preferred to a working
|
|
65
|
+
# one on PATH forever.
|
|
66
|
+
$unpacked = Join-Path $temp "unpacked\$name"
|
|
67
|
+
& (Join-Path $unpacked 'node.exe') -v | Out-Null
|
|
68
|
+
if ($LASTEXITCODE -ne 0) { throw 'does not run' }
|
|
69
|
+
# An installer may have finished first: that Node can be in use, leave it. A folder
|
|
70
|
+
# without a node (an antivirus took it) is removed, or the move would nest inside it.
|
|
71
|
+
if (Test-Path -LiteralPath (Join-Path $final 'node.exe')) { return }
|
|
72
|
+
if (Test-Path -LiteralPath $final) { Remove-Item -Recurse -Force -LiteralPath $final }
|
|
73
|
+
# One rename makes the finished folder appear: a half-unpacked Node is never picked up.
|
|
74
|
+
# An antivirus scanner can hold the folder for a moment: a few tries.
|
|
75
|
+
for ($i = 1; ; $i++) {
|
|
76
|
+
try { Move-Item -LiteralPath $unpacked -Destination $final; break }
|
|
77
|
+
catch { if ($i -ge 5) { throw }; Start-Sleep -Milliseconds 500 }
|
|
78
|
+
}
|
|
79
|
+
Remove-Item -Force -LiteralPath $failed -ErrorAction SilentlyContinue
|
|
80
|
+
Remove-Older
|
|
81
|
+
} catch {
|
|
82
|
+
New-Item -ItemType File -Force -Path $failed | Out-Null
|
|
83
|
+
} finally {
|
|
84
|
+
Remove-Item -Recurse -Force -LiteralPath $temp -ErrorAction SilentlyContinue
|
|
85
|
+
Remove-Item -Recurse -Force -LiteralPath $lock -ErrorAction SilentlyContinue
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
# Nothing is printed. The stamp keeps the launcher from starting this on every prompt.
|
|
89
|
+
try { New-Item -ItemType File -Force -Path (Join-Path $env:USERPROFILE '.tolmete\node\.failed') | Out-Null } catch { }
|
|
90
|
+
}
|
|
91
|
+
exit 0
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Downloads the pinned portable Node.js into ~/.tolmete/node and checks its SHA-256.
|
|
3
|
+
# No admin rights, no PATH change, nothing printed. Started in the background by tolmete.sh
|
|
4
|
+
# when no Node 22 is found; a lock and a failure stamp keep it from running over and over.
|
|
5
|
+
# The version and the six hashes also sit in scripts/install.sh, scripts/install.ps1 and (the two
|
|
6
|
+
# Windows ones) the Codex plugin's bootstrap.ps1; a test keeps them in step. The hashes come from https://nodejs.org/dist/v22.23.5/SHASUMS256.txt
|
|
7
|
+
|
|
8
|
+
VERSION=22.23.5
|
|
9
|
+
|
|
10
|
+
base=${USERPROFILE:-$HOME}
|
|
11
|
+
# WSL can pass USERPROFILE through WSLENV, but Node there looks in HOME.
|
|
12
|
+
[ -n "$WSL_DISTRO_NAME" ] && base=$HOME
|
|
13
|
+
home=$(printf '%s' "$base" | tr '\\' '/')
|
|
14
|
+
root="$home/.tolmete/node"
|
|
15
|
+
|
|
16
|
+
case "$(uname -s)" in
|
|
17
|
+
Linux) os=linux; ext=tar.gz ;;
|
|
18
|
+
Darwin) os=darwin; ext=tar.gz ;;
|
|
19
|
+
MINGW* | MSYS* | CYGWIN*) os=win; ext=zip ;;
|
|
20
|
+
*) exit 0 ;;
|
|
21
|
+
esac
|
|
22
|
+
|
|
23
|
+
if [ "$os" = win ]; then
|
|
24
|
+
case "${PROCESSOR_ARCHITEW6432:-$PROCESSOR_ARCHITECTURE}" in
|
|
25
|
+
ARM64) arch=arm64 ;;
|
|
26
|
+
*) arch=x64 ;;
|
|
27
|
+
esac
|
|
28
|
+
else
|
|
29
|
+
case "$(uname -m)" in
|
|
30
|
+
x86_64 | amd64) arch=x64 ;;
|
|
31
|
+
aarch64 | arm64) arch=arm64 ;;
|
|
32
|
+
*) exit 0 ;;
|
|
33
|
+
esac
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
platform="$os-$arch"
|
|
37
|
+
case "$platform" in
|
|
38
|
+
win-x64) sha=4a191082e9706866830379d577d2cc8a50c776fcd9436a8d061b063ed0d9a0e3 ;;
|
|
39
|
+
win-arm64) sha=c1856817f611738c77534efbff8a5a17990593eab24046bc8d2c23a77a160d13 ;;
|
|
40
|
+
darwin-x64) sha=c53383238206b9ae4db23c5d8a63645e2e753bec8ab51a49cc81939aa64e9422 ;;
|
|
41
|
+
darwin-arm64) sha=e7131995759b61a0170b646010d2ad35a5d37b4cb0d471f3e8317eac6f742f3d ;;
|
|
42
|
+
linux-x64) sha=c54118104acc524633b5abe106bbf44a53126ec8b4e5fa105cb92b5d7de8a1a1 ;;
|
|
43
|
+
linux-arm64) sha=8bd3dc69eee8f3f226315a80d7d1d4faccf217a4c8fae500168ac2e38f3bdba3 ;;
|
|
44
|
+
*) exit 0 ;;
|
|
45
|
+
esac
|
|
46
|
+
|
|
47
|
+
name="node-v$VERSION-$platform"
|
|
48
|
+
final="$root/v$VERSION-$platform"
|
|
49
|
+
archive="$name.$ext"
|
|
50
|
+
|
|
51
|
+
mkdir -p "$root" || exit 0
|
|
52
|
+
chmod 700 "$home/.tolmete" 2>/dev/null
|
|
53
|
+
|
|
54
|
+
# Older copies are of no use once the pinned one is there. One that is still running on Windows
|
|
55
|
+
# cannot be deleted; that is left for the next run.
|
|
56
|
+
remove_older() {
|
|
57
|
+
for older in "$root"/v22*; do
|
|
58
|
+
[ -d "$older" ] && [ "$older" != "$final" ] && rm -rf "$older" 2>/dev/null
|
|
59
|
+
done
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# A download that was killed leaves its folder behind (the exit trap does not run on SIGKILL).
|
|
63
|
+
for leftover in "$root"/.tmp-*; do
|
|
64
|
+
if [ -d "$leftover" ] && [ -n "$(find "$leftover" -maxdepth 0 -mmin +60 2>/dev/null)" ]; then
|
|
65
|
+
rm -rf "$leftover"
|
|
66
|
+
fi
|
|
67
|
+
done
|
|
68
|
+
|
|
69
|
+
if [ -f "$final/bin/node" ] || [ -f "$final/node.exe" ]; then
|
|
70
|
+
remove_older
|
|
71
|
+
exit 0
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
# No new attempt for 6 hours after a failure.
|
|
75
|
+
if [ -f "$root/.failed" ] && [ -n "$(find "$root/.failed" -mmin -360 2>/dev/null)" ]; then
|
|
76
|
+
exit 0
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
# One download at a time; a lock older than 30 minutes belongs to a dead process.
|
|
80
|
+
if [ -d "$root/.lock" ] && [ -n "$(find "$root/.lock" -maxdepth 0 -mmin +30 2>/dev/null)" ]; then
|
|
81
|
+
rmdir "$root/.lock" 2>/dev/null
|
|
82
|
+
fi
|
|
83
|
+
mkdir "$root/.lock" 2>/dev/null || exit 0
|
|
84
|
+
|
|
85
|
+
tmp="$root/.tmp-$$"
|
|
86
|
+
cleanup() {
|
|
87
|
+
rm -rf "$tmp"
|
|
88
|
+
rmdir "$root/.lock" 2>/dev/null
|
|
89
|
+
}
|
|
90
|
+
trap cleanup EXIT
|
|
91
|
+
|
|
92
|
+
fail() {
|
|
93
|
+
: >"$root/.failed"
|
|
94
|
+
exit 0
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
mkdir -p "$tmp/unpacked" || fail
|
|
98
|
+
url="https://nodejs.org/dist/v$VERSION/$archive"
|
|
99
|
+
if command -v curl >/dev/null 2>&1; then
|
|
100
|
+
curl -fsSL --max-time 900 -o "$tmp/$archive" "$url" || fail
|
|
101
|
+
elif command -v wget >/dev/null 2>&1; then
|
|
102
|
+
wget -q -T 60 -O "$tmp/$archive" "$url" || fail
|
|
103
|
+
else
|
|
104
|
+
fail
|
|
105
|
+
fi
|
|
106
|
+
|
|
107
|
+
if command -v sha256sum >/dev/null 2>&1; then
|
|
108
|
+
actual=$(sha256sum "$tmp/$archive" | cut -d' ' -f1)
|
|
109
|
+
elif command -v shasum >/dev/null 2>&1; then
|
|
110
|
+
actual=$(shasum -a 256 "$tmp/$archive" | cut -d' ' -f1)
|
|
111
|
+
else
|
|
112
|
+
fail
|
|
113
|
+
fi
|
|
114
|
+
[ "$actual" = "$sha" ] || fail
|
|
115
|
+
|
|
116
|
+
if [ "$ext" = zip ]; then
|
|
117
|
+
if command -v unzip >/dev/null 2>&1; then
|
|
118
|
+
unzip -q "$tmp/$archive" -d "$tmp/unpacked" || fail
|
|
119
|
+
else
|
|
120
|
+
"${SYSTEMROOT:-C:/Windows}/System32/tar.exe" -xf "$tmp/$archive" -C "$tmp/unpacked" || fail
|
|
121
|
+
fi
|
|
122
|
+
else
|
|
123
|
+
tar -xzf "$tmp/$archive" -C "$tmp/unpacked" || fail
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
# It must run here: a glibc build on musl (Alpine) unpacks fine and never starts, and the
|
|
127
|
+
# launcher would prefer it to a working Node on PATH forever.
|
|
128
|
+
unpacked="$tmp/unpacked/$name"
|
|
129
|
+
if [ -f "$unpacked/bin/node" ]; then
|
|
130
|
+
"$unpacked/bin/node" -v >/dev/null 2>&1 || fail
|
|
131
|
+
elif [ -f "$unpacked/node.exe" ]; then
|
|
132
|
+
"$unpacked/node.exe" -v >/dev/null 2>&1 || fail
|
|
133
|
+
else
|
|
134
|
+
fail
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# An installer may have finished first: that Node can be in use, leave it. A folder without a
|
|
138
|
+
# node (an antivirus took it) is removed, or the move would nest inside it and never be done.
|
|
139
|
+
if [ -f "$final/bin/node" ] || [ -f "$final/node.exe" ]; then
|
|
140
|
+
exit 0
|
|
141
|
+
fi
|
|
142
|
+
rm -rf "$final" || fail
|
|
143
|
+
# One rename makes the finished folder appear: a half-unpacked Node is never picked up.
|
|
144
|
+
mv "$unpacked" "$final" || fail
|
|
145
|
+
rm -f "$root/.failed"
|
|
146
|
+
remove_older
|
|
147
|
+
exit 0
|