skillreg 1.6.5

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 skillreg contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # skillreg
2
+
3
+ Local AI agent skill manager distributed through npm
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install --global skillreg
9
+ skillreg workspace create ~/my-skills
10
+ skillreg dashboard open
11
+ ```
12
+
13
+ The npm launcher runs the matching Python `skillreg` package in an isolated
14
+ environment. It uses `uv` when available. Otherwise, it creates a private
15
+ virtual environment with Python 3.9 or newer on first use
16
+
17
+ The first invocation needs network access to download the Python package and
18
+ its dependencies from PyPI
19
+
20
+ Optional environment variables:
21
+
22
+ - `SKILLREG_UV`: path to the `uv` executable
23
+ - `SKILLREG_PYTHON`: path to a Python 3.9+ executable
24
+ - `SKILLREG_NPM_CACHE_DIR`: directory for the npm launcher's Python environment
25
+
26
+ Project documentation: <https://github.com/fcraft/skillreg>
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { runSkillreg } from "../lib/launcher.js"
4
+
5
+ process.exitCode = runSkillreg(process.argv.slice(2))
@@ -0,0 +1,215 @@
1
+ import { spawnSync } from "node:child_process"
2
+ import {
3
+ closeSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ openSync,
7
+ readFileSync,
8
+ rmSync,
9
+ statSync,
10
+ unlinkSync,
11
+ writeFileSync,
12
+ } from "node:fs"
13
+ import os from "node:os"
14
+ import path from "node:path"
15
+ import { fileURLToPath } from "node:url"
16
+
17
+ const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url))
18
+ const PACKAGE_JSON = JSON.parse(readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8"))
19
+ const PACKAGE_SPEC = `skillreg==${PACKAGE_JSON.version}`
20
+ const MINIMUM_PYTHON = [3, 9]
21
+ const BOOTSTRAP_LOCK_TIMEOUT_MS = 180_000
22
+ const STALE_LOCK_MS = 600_000
23
+ const sleepSignal = new Int32Array(new SharedArrayBuffer(4))
24
+
25
+ function spawn(command, args, options = {}) {
26
+ return spawnSync(command, args, {
27
+ windowsHide: true,
28
+ ...options,
29
+ })
30
+ }
31
+
32
+ function commandWorks(command, args) {
33
+ const result = spawn(command, args, { stdio: "ignore" })
34
+ return !result.error && result.status === 0
35
+ }
36
+
37
+ export function buildUvArgs(cliArgs, version = PACKAGE_JSON.version) {
38
+ return ["tool", "run", "--from", `skillreg==${version}`, "skillreg", ...cliArgs]
39
+ }
40
+
41
+ export function parsePythonVersion(value) {
42
+ const match = String(value).trim().match(/^(\d+)\.(\d+)$/)
43
+ return match ? [Number(match[1]), Number(match[2])] : null
44
+ }
45
+
46
+ export function supportsPython(version) {
47
+ if (!version) return false
48
+ return version[0] > MINIMUM_PYTHON[0]
49
+ || (version[0] === MINIMUM_PYTHON[0] && version[1] >= MINIMUM_PYTHON[1])
50
+ }
51
+
52
+ export function cacheRoot(env = process.env, platform = process.platform, home = os.homedir()) {
53
+ if (env.SKILLREG_NPM_CACHE_DIR) return path.resolve(env.SKILLREG_NPM_CACHE_DIR)
54
+ if (platform === "win32" && env.LOCALAPPDATA) {
55
+ return path.join(env.LOCALAPPDATA, "skillreg", "npm")
56
+ }
57
+ if (platform === "darwin") return path.join(home, "Library", "Caches", "skillreg", "npm")
58
+ if (env.XDG_CACHE_HOME) return path.join(env.XDG_CACHE_HOME, "skillreg", "npm")
59
+ return path.join(home, ".cache", "skillreg", "npm")
60
+ }
61
+
62
+ export function venvPython(venv, platform = process.platform) {
63
+ return platform === "win32"
64
+ ? path.join(venv, "Scripts", "python.exe")
65
+ : path.join(venv, "bin", "python")
66
+ }
67
+
68
+ function findUv(env) {
69
+ if (env.SKILLREG_UV) return env.SKILLREG_UV
70
+ return commandWorks("uv", ["--version"]) ? "uv" : null
71
+ }
72
+
73
+ function pythonCandidates(env, platform) {
74
+ if (env.SKILLREG_PYTHON) return [{ command: env.SKILLREG_PYTHON, prefix: [] }]
75
+ const candidates = [
76
+ { command: "python3", prefix: [] },
77
+ { command: "python", prefix: [] },
78
+ ]
79
+ if (platform === "win32") candidates.unshift({ command: "py", prefix: ["-3"] })
80
+ return candidates
81
+ }
82
+
83
+ function findPython(env, platform) {
84
+ for (const candidate of pythonCandidates(env, platform)) {
85
+ const result = spawn(
86
+ candidate.command,
87
+ [...candidate.prefix, "-c", "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"],
88
+ { encoding: "utf8" },
89
+ )
90
+ if (!result.error && result.status === 0 && supportsPython(parsePythonVersion(result.stdout))) {
91
+ return candidate
92
+ }
93
+ }
94
+ return null
95
+ }
96
+
97
+ function runInherited(command, args) {
98
+ const result = spawn(command, args, { stdio: "inherit" })
99
+ if (result.error) {
100
+ console.error(`无法启动 ${command}: ${result.error.message}`)
101
+ return 1
102
+ }
103
+ return result.status ?? 1
104
+ }
105
+
106
+ function environmentReady(executable, marker) {
107
+ if (!existsSync(executable) || !existsSync(marker)) return false
108
+ return readFileSync(marker, "utf8").trim() === PACKAGE_SPEC
109
+ }
110
+
111
+ function lockOwnerIsRunning(lock) {
112
+ try {
113
+ const pid = Number(readFileSync(lock, "utf8").trim())
114
+ if (!Number.isInteger(pid) || pid <= 0) return true
115
+ process.kill(pid, 0)
116
+ return true
117
+ } catch (error) {
118
+ return error?.code === "EPERM"
119
+ }
120
+ }
121
+
122
+ function acquireBootstrapLock(lock) {
123
+ const deadline = Date.now() + BOOTSTRAP_LOCK_TIMEOUT_MS
124
+ while (Date.now() < deadline) {
125
+ try {
126
+ const descriptor = openSync(lock, "wx")
127
+ writeFileSync(descriptor, `${process.pid}\n`, "utf8")
128
+ return descriptor
129
+ } catch (error) {
130
+ if (error?.code !== "EEXIST") throw error
131
+ let stale = false
132
+ try {
133
+ stale = Date.now() - statSync(lock).mtimeMs > STALE_LOCK_MS
134
+ } catch (statError) {
135
+ if (statError?.code === "ENOENT") continue
136
+ throw statError
137
+ }
138
+ if (stale || !lockOwnerIsRunning(lock)) {
139
+ try {
140
+ unlinkSync(lock)
141
+ } catch (unlinkError) {
142
+ if (unlinkError?.code !== "ENOENT") throw unlinkError
143
+ }
144
+ continue
145
+ }
146
+ Atomics.wait(sleepSignal, 0, 0, 250)
147
+ }
148
+ }
149
+ return null
150
+ }
151
+
152
+ function ensurePythonEnvironment(python, env) {
153
+ const environment = path.join(cacheRoot(env), "python", PACKAGE_JSON.version)
154
+ const executable = venvPython(environment)
155
+ const marker = path.join(environment, ".skillreg-package")
156
+ const lock = `${environment}.lock`
157
+
158
+ if (environmentReady(executable, marker)) return executable
159
+
160
+ mkdirSync(path.dirname(environment), { recursive: true })
161
+ const lockDescriptor = acquireBootstrapLock(lock)
162
+ if (lockDescriptor === null) {
163
+ console.error("等待 skillreg 隔离环境安装超时,请稍后重试")
164
+ return null
165
+ }
166
+
167
+ try {
168
+ if (environmentReady(executable, marker)) return executable
169
+
170
+ console.error(`首次运行,正在安装 ${PACKAGE_SPEC}`)
171
+ rmSync(environment, { recursive: true, force: true })
172
+
173
+ const createResult = spawn(
174
+ python.command,
175
+ [...python.prefix, "-m", "venv", environment],
176
+ { stdio: "inherit" },
177
+ )
178
+ if (createResult.error || createResult.status !== 0) {
179
+ console.error("无法创建 Python 隔离环境,请安装 uv 或完整的 Python 3.9+")
180
+ return null
181
+ }
182
+
183
+ const installResult = spawn(
184
+ executable,
185
+ ["-m", "pip", "install", "--disable-pip-version-check", PACKAGE_SPEC],
186
+ { stdio: "inherit" },
187
+ )
188
+ if (installResult.error || installResult.status !== 0) {
189
+ console.error(`无法从 PyPI 安装 ${PACKAGE_SPEC}`)
190
+ return null
191
+ }
192
+
193
+ writeFileSync(marker, `${PACKAGE_SPEC}\n`, "utf8")
194
+ return executable
195
+ } finally {
196
+ closeSync(lockDescriptor)
197
+ unlinkSync(lock)
198
+ }
199
+ }
200
+
201
+ export function runSkillreg(cliArgs, env = process.env) {
202
+ const uv = findUv(env)
203
+ if (uv) return runInherited(uv, buildUvArgs(cliArgs))
204
+
205
+ const python = findPython(env, process.platform)
206
+ if (!python) {
207
+ console.error("skillreg 需要 uv,或 Python 3.9 及以上版本")
208
+ console.error("安装 uv: https://docs.astral.sh/uv/getting-started/installation/")
209
+ return 1
210
+ }
211
+
212
+ const executable = ensurePythonEnvironment(python, env)
213
+ if (!executable) return 1
214
+ return runInherited(executable, ["-m", "skillreg.cli", ...cliArgs])
215
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "skillreg",
3
+ "version": "1.6.5",
4
+ "description": "Local AI agent skill manager CLI",
5
+ "type": "module",
6
+ "bin": {
7
+ "skillreg": "bin/skillreg.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "lib",
12
+ "LICENSE",
13
+ "README.md"
14
+ ],
15
+ "scripts": {
16
+ "test": "node --test",
17
+ "pack:check": "npm pack --dry-run"
18
+ },
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/fcraft/skillreg.git",
25
+ "directory": "npm"
26
+ },
27
+ "homepage": "https://github.com/fcraft/skillreg",
28
+ "bugs": {
29
+ "url": "https://github.com/fcraft/skillreg/issues"
30
+ },
31
+ "keywords": [
32
+ "ai",
33
+ "agent",
34
+ "skill",
35
+ "registry",
36
+ "cli"
37
+ ],
38
+ "author": "HJH201314 <fcraft@qq.com>",
39
+ "license": "MIT",
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "registry": "https://registry.npmjs.org/"
43
+ }
44
+ }