left-skills 0.1.7 → 0.1.9
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/dist/cli.js +119 -25
- package/package.json +6 -4
package/dist/cli.js
CHANGED
|
@@ -3047,22 +3047,26 @@ var {
|
|
|
3047
3047
|
var import_node_fs = require("fs");
|
|
3048
3048
|
var import_node_path = require("path");
|
|
3049
3049
|
var import_node_os = require("os");
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3050
|
+
function getStorePath() {
|
|
3051
|
+
return process.env.LEFT_SKILLS_STORE || (0, import_node_path.join)((0, import_node_os.homedir)(), ".left-skills", "usage.json");
|
|
3052
|
+
}
|
|
3053
|
+
function ensureStore(path) {
|
|
3054
|
+
const dir = (0, import_node_path.dirname)(path);
|
|
3053
3055
|
if (!(0, import_node_fs.existsSync)(dir)) (0, import_node_fs.mkdirSync)(dir, { recursive: true });
|
|
3054
|
-
if (!(0, import_node_fs.existsSync)(
|
|
3056
|
+
if (!(0, import_node_fs.existsSync)(path)) (0, import_node_fs.writeFileSync)(path, "[]", "utf-8");
|
|
3055
3057
|
}
|
|
3056
3058
|
function appendRecord(record) {
|
|
3057
|
-
|
|
3059
|
+
const path = getStorePath();
|
|
3060
|
+
ensureStore(path);
|
|
3058
3061
|
const records = readRecords();
|
|
3059
3062
|
records.push(record);
|
|
3060
|
-
(0, import_node_fs.writeFileSync)(
|
|
3063
|
+
(0, import_node_fs.writeFileSync)(path, JSON.stringify(records, null, 2), "utf-8");
|
|
3061
3064
|
}
|
|
3062
3065
|
function readRecords() {
|
|
3063
|
-
|
|
3066
|
+
const path = getStorePath();
|
|
3067
|
+
ensureStore(path);
|
|
3064
3068
|
try {
|
|
3065
|
-
return JSON.parse((0, import_node_fs.readFileSync)(
|
|
3069
|
+
return JSON.parse((0, import_node_fs.readFileSync)(path, "utf-8"));
|
|
3066
3070
|
} catch {
|
|
3067
3071
|
return [];
|
|
3068
3072
|
}
|
|
@@ -3198,9 +3202,104 @@ function relativeTime(iso) {
|
|
|
3198
3202
|
return `${days} \u5929\u524D`;
|
|
3199
3203
|
}
|
|
3200
3204
|
|
|
3205
|
+
// src/install.ts
|
|
3206
|
+
var import_node_fs3 = require("fs");
|
|
3207
|
+
var import_node_os3 = require("os");
|
|
3208
|
+
var import_node_path3 = require("path");
|
|
3209
|
+
function hookSnippet() {
|
|
3210
|
+
const cmd = "left-skills hook";
|
|
3211
|
+
return {
|
|
3212
|
+
hooks: {
|
|
3213
|
+
UserPromptExpansion: [
|
|
3214
|
+
{ matcher: ".*", hooks: [{ type: "command", command: `${cmd} UserPromptExpansion` }] }
|
|
3215
|
+
],
|
|
3216
|
+
PreToolUse: [
|
|
3217
|
+
{ matcher: "Skill", hooks: [{ type: "command", command: `${cmd} PreToolUse` }] }
|
|
3218
|
+
],
|
|
3219
|
+
UserPromptSubmit: [
|
|
3220
|
+
{ hooks: [{ type: "command", command: `${cmd} UserPromptSubmit` }] }
|
|
3221
|
+
]
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
function writeHooksToSettings(settingsPath) {
|
|
3226
|
+
if ((0, import_node_fs3.existsSync)(settingsPath)) {
|
|
3227
|
+
(0, import_node_fs3.copyFileSync)(settingsPath, settingsPath + ".bak");
|
|
3228
|
+
}
|
|
3229
|
+
let settings = {};
|
|
3230
|
+
if ((0, import_node_fs3.existsSync)(settingsPath)) {
|
|
3231
|
+
try {
|
|
3232
|
+
settings = JSON.parse((0, import_node_fs3.readFileSync)(settingsPath, "utf-8"));
|
|
3233
|
+
} catch {
|
|
3234
|
+
settings = {};
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
const snippet = hookSnippet();
|
|
3238
|
+
if (!settings.hooks) settings.hooks = {};
|
|
3239
|
+
for (const [event, entries] of Object.entries(snippet.hooks)) {
|
|
3240
|
+
if (!settings.hooks[event]) {
|
|
3241
|
+
settings.hooks[event] = entries;
|
|
3242
|
+
} else {
|
|
3243
|
+
for (const entry of entries) {
|
|
3244
|
+
const exists = settings.hooks[event].some((e) => JSON.stringify(e) === JSON.stringify(entry));
|
|
3245
|
+
if (!exists) settings.hooks[event].push(entry);
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
(0, import_node_fs3.writeFileSync)(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
3250
|
+
}
|
|
3251
|
+
function globalSettingsPath() {
|
|
3252
|
+
return (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".claude", "settings.json");
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
// package.json
|
|
3256
|
+
var package_default = {
|
|
3257
|
+
name: "left-skills",
|
|
3258
|
+
version: "0.1.9",
|
|
3259
|
+
description: "\u7ED9 AI \u7528\u7684 skill \u751F\u547D\u5468\u671F\u7BA1\u7406\u5DE5\u5177 \u2014 MVP: skill \u8C03\u7528\u4F7F\u7528\u7EDF\u8BA1",
|
|
3260
|
+
bin: {
|
|
3261
|
+
"left-skills": "./dist/cli.js"
|
|
3262
|
+
},
|
|
3263
|
+
scripts: {
|
|
3264
|
+
build: "tsup",
|
|
3265
|
+
dev: "tsup --watch",
|
|
3266
|
+
test: "node --import tsx --test test/**/*.test.ts"
|
|
3267
|
+
},
|
|
3268
|
+
dependencies: {
|
|
3269
|
+
commander: "^12.0.0",
|
|
3270
|
+
"gray-matter": "^4.0.3"
|
|
3271
|
+
},
|
|
3272
|
+
devDependencies: {
|
|
3273
|
+
"@types/node": "^20.0.0",
|
|
3274
|
+
tsup: "^8.0.0",
|
|
3275
|
+
tsx: "^4.22.4",
|
|
3276
|
+
typescript: "^5.4.0"
|
|
3277
|
+
},
|
|
3278
|
+
author: "cuikexi",
|
|
3279
|
+
license: "MIT",
|
|
3280
|
+
repository: {
|
|
3281
|
+
type: "git",
|
|
3282
|
+
url: "git+https://github.com/cuikexi/left-skills.git"
|
|
3283
|
+
},
|
|
3284
|
+
keywords: [
|
|
3285
|
+
"claude-code",
|
|
3286
|
+
"skill",
|
|
3287
|
+
"agent-skills",
|
|
3288
|
+
"usage",
|
|
3289
|
+
"cli",
|
|
3290
|
+
"shift-left"
|
|
3291
|
+
],
|
|
3292
|
+
files: [
|
|
3293
|
+
"dist"
|
|
3294
|
+
],
|
|
3295
|
+
engines: {
|
|
3296
|
+
node: ">=18"
|
|
3297
|
+
}
|
|
3298
|
+
};
|
|
3299
|
+
|
|
3201
3300
|
// src/cli.ts
|
|
3202
3301
|
var program2 = new Command();
|
|
3203
|
-
program2.name("left-skills").description("\u7ED9 AI \u7528\u7684 skill \u751F\u547D\u5468\u671F\u7BA1\u7406\u5DE5\u5177 \u2014 MVP: skill \u8C03\u7528\u4F7F\u7528\u7EDF\u8BA1").version(
|
|
3302
|
+
program2.name("left-skills").description("\u7ED9 AI \u7528\u7684 skill \u751F\u547D\u5468\u671F\u7BA1\u7406\u5DE5\u5177 \u2014 MVP: skill \u8C03\u7528\u4F7F\u7528\u7EDF\u8BA1").version(package_default.version);
|
|
3204
3303
|
program2.command("usage").description("skill \u8C03\u7528\u4F7F\u7528\u62A5\u544A").option("--json", "\u8F93\u51FA JSON(AI \u7528)").option("--since <days>", "\u65F6\u95F4\u7A97\u53E3(\u5929,\u9ED8\u8BA4 30)", "30").action((opts) => {
|
|
3205
3304
|
const since = parseInt(opts.since, 10) || 30;
|
|
3206
3305
|
const report = buildReport(since);
|
|
@@ -3210,6 +3309,17 @@ program2.command("usage").description("skill \u8C03\u7528\u4F7F\u7528\u62A5\u544
|
|
|
3210
3309
|
console.log(formatHuman(report));
|
|
3211
3310
|
}
|
|
3212
3311
|
});
|
|
3312
|
+
program2.command("install").description("\u8F93\u51FA hook \u914D\u7F6E\u7247\u6BB5(\u9ED8\u8BA4)\u6216 --write \u81EA\u52A8\u5199\u8FDB ~/.claude/settings.json(\u5408\u5E76+\u5907\u4EFD .bak)").option("--write", "\u81EA\u52A8\u5199 hook \u5230 settings.json(\u5408\u5E76\u53BB\u91CD + \u5907\u4EFD .bak)", false).action((opts) => {
|
|
3313
|
+
if (opts.write) {
|
|
3314
|
+
const path = globalSettingsPath();
|
|
3315
|
+
writeHooksToSettings(path);
|
|
3316
|
+
console.log(`\u2713 hook \u5DF2\u5199\u5165 ${path}(\u5DF2\u5907\u4EFD .bak)`);
|
|
3317
|
+
console.log(" \u6253 /skill \u6216 AI \u8C03 skill \u4F1A\u81EA\u52A8\u8BB0\u5F55,\u8DD1 left-skills usage \u770B\u62A5\u544A");
|
|
3318
|
+
} else {
|
|
3319
|
+
console.log(JSON.stringify(hookSnippet(), null, 2));
|
|
3320
|
+
console.log("\n# \u628A\u4E0A\u9762\u7247\u6BB5\u52A0\u8FDB ~/.claude/settings.json \u7684 hooks \u5B57\u6BB5,\u6216\u8DD1 left-skills install --write \u81EA\u52A8\u5199");
|
|
3321
|
+
}
|
|
3322
|
+
});
|
|
3213
3323
|
program2.command("hook <event>").description("hook \u5165\u53E3(\u8BFB stdin payload)").action(async (event) => {
|
|
3214
3324
|
const payload = await readStdinPayload();
|
|
3215
3325
|
if (!payload) return;
|
|
@@ -3227,20 +3337,4 @@ program2.command("hook <event>").description("hook \u5165\u53E3(\u8BFB stdin pay
|
|
|
3227
3337
|
break;
|
|
3228
3338
|
}
|
|
3229
3339
|
});
|
|
3230
|
-
program2.command("install").description("\u8F93\u51FA hook \u914D\u7F6E\u7247\u6BB5(\u52A0\u8FDB ~/.claude/settings.json \u7684 hooks \u5B57\u6BB5)").action(() => {
|
|
3231
|
-
const cmd = "left-skills hook";
|
|
3232
|
-
console.log(JSON.stringify({
|
|
3233
|
-
hooks: {
|
|
3234
|
-
UserPromptExpansion: [
|
|
3235
|
-
{ matcher: ".*", hooks: [{ type: "command", command: `${cmd} UserPromptExpansion` }] }
|
|
3236
|
-
],
|
|
3237
|
-
PreToolUse: [
|
|
3238
|
-
{ matcher: "Skill", hooks: [{ type: "command", command: `${cmd} PreToolUse` }] }
|
|
3239
|
-
],
|
|
3240
|
-
UserPromptSubmit: [
|
|
3241
|
-
{ hooks: [{ type: "command", command: `${cmd} UserPromptSubmit` }] }
|
|
3242
|
-
]
|
|
3243
|
-
}
|
|
3244
|
-
}, null, 2));
|
|
3245
|
-
});
|
|
3246
3340
|
program2.parse();
|
package/package.json
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "left-skills",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "给 AI 用的 skill 生命周期管理工具 — MVP: skill 调用使用统计",
|
|
5
5
|
"bin": {
|
|
6
6
|
"left-skills": "./dist/cli.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup",
|
|
10
|
-
"dev": "tsup --watch"
|
|
10
|
+
"dev": "tsup --watch",
|
|
11
|
+
"test": "node --import tsx --test test/**/*.test.ts"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"commander": "^12.0.0",
|
|
14
15
|
"gray-matter": "^4.0.3"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
|
-
"
|
|
18
|
+
"@types/node": "^20.0.0",
|
|
18
19
|
"tsup": "^8.0.0",
|
|
19
|
-
"
|
|
20
|
+
"tsx": "^4.22.4",
|
|
21
|
+
"typescript": "^5.4.0"
|
|
20
22
|
},
|
|
21
23
|
"author": "cuikexi",
|
|
22
24
|
"license": "MIT",
|