@winspan/claude-forge 8.51.1 → 8.53.2
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/CLAUDE.md +5 -5
- package/dist/cli/commands/skills.d.ts.map +1 -1
- package/dist/cli/commands/skills.js +115 -0
- package/dist/cli/commands/skills.js.map +1 -1
- package/dist/core/constants.d.ts +2 -0
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +4 -0
- package/dist/core/constants.js.map +1 -1
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +11 -1
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/skill-sync.d.ts +21 -0
- package/dist/daemon/skill-sync.d.ts.map +1 -0
- package/dist/daemon/skill-sync.js +75 -0
- package/dist/daemon/skill-sync.js.map +1 -0
- package/dist/hooks/notification.sh +1 -1
- package/dist/hooks/post-tool-use.sh +1 -1
- package/dist/hooks/pre-tool-use.sh +1 -1
- package/dist/hooks/stop.sh +1 -1
- package/dist/hooks/user-prompt-submit.sh +1 -1
- package/dist/skills/official/code-simplifier.md +37 -1
- package/dist/skills/official/find-skills.md +120 -1
- package/dist/skills/official/official-api-design.md +14 -1
- package/dist/skills/official/official-architecture-decision.md +22 -1
- package/dist/skills/official/official-db-schema-design.md +19 -1
- package/dist/skills/official/official-debug.md +9 -1
- package/dist/skills/official/official-pr-review.md +1 -1
- package/dist/skills/official/official-security-hardening.md +7 -1
- package/dist/skills/official/planning-with-files.md +206 -2
- package/dist/skills/official/ui-ux-pro-max.md +88 -1
- package/dist/skills/official/webapp-testing.md +85 -1
- package/dist/skills/registry.d.ts +1 -1
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +2 -2
- package/dist/skills/registry.js.map +1 -1
- package/dist/skills/semantic-matcher.d.ts +2 -1
- package/dist/skills/semantic-matcher.d.ts.map +1 -1
- package/dist/skills/semantic-matcher.js +6 -3
- package/dist/skills/semantic-matcher.js.map +1 -1
- package/dist/skills/upgrade-engine.d.ts +91 -0
- package/dist/skills/upgrade-engine.d.ts.map +1 -0
- package/dist/skills/upgrade-engine.js +436 -0
- package/dist/skills/upgrade-engine.js.map +1 -0
- package/dist/skills/upgrade-prompt.d.ts +20 -0
- package/dist/skills/upgrade-prompt.d.ts.map +1 -0
- package/dist/skills/upgrade-prompt.js +75 -0
- package/dist/skills/upgrade-prompt.js.map +1 -0
- package/docs/design/skill-ai-upgrade-spec-20260518-1930.md +297 -0
- package/docs/implementation/daemon-skill-sync-changelog-20260518-2000.md +22 -0
- package/docs/implementation/skill-ai-upgrade-changelog-20260518-1930.md +49 -0
- package/package.json +1 -1
- package/src/cli/commands/skills.ts +143 -0
- package/src/core/constants.ts +5 -0
- package/src/daemon/index.ts +11 -1
- package/src/daemon/skill-sync.ts +88 -0
- package/src/hooks/notification.sh +1 -1
- package/src/hooks/post-tool-use.sh +1 -1
- package/src/hooks/pre-tool-use.sh +1 -1
- package/src/hooks/stop.sh +1 -1
- package/src/hooks/user-prompt-submit.sh +1 -1
- package/src/skills/official/code-simplifier.md +37 -1
- package/src/skills/official/find-skills.md +120 -1
- package/src/skills/official/official-api-design.md +14 -1
- package/src/skills/official/official-architecture-decision.md +22 -1
- package/src/skills/official/official-db-schema-design.md +19 -1
- package/src/skills/official/official-debug.md +9 -1
- package/src/skills/official/official-pr-review.md +1 -1
- package/src/skills/official/official-security-hardening.md +7 -1
- package/src/skills/official/planning-with-files.md +206 -2
- package/src/skills/official/ui-ux-pro-max.md +88 -1
- package/src/skills/official/webapp-testing.md +85 -1
- package/src/skills/registry.ts +2 -2
- package/src/skills/semantic-matcher.ts +6 -3
- package/src/skills/upgrade-engine.ts +541 -0
- package/src/skills/upgrade-prompt.ts +84 -0
- package/tests/unit/daemon/skill-sync.test.ts +75 -0
- package/tests/unit/skills/upgrade-engine-parse.test.ts +138 -0
- package/tests/unit/skills/upgrade-engine.test.ts +401 -0
- package/tests/unit/skills/upgrade-prompt.test.ts +89 -0
|
@@ -2,11 +2,24 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { homedir } from 'os';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { promises as fsPromises } from 'node:fs';
|
|
5
6
|
import type { Command } from 'commander';
|
|
6
7
|
import { loadOfficialSkills } from '../../skills/official-skills.js';
|
|
7
8
|
import { SkillRegistry } from '../../skills/registry.js';
|
|
8
9
|
import { skillInvoke } from '../../skills/tools/skill-invoke.js';
|
|
9
10
|
import { skillList } from '../../skills/tools/skill-list.js';
|
|
11
|
+
import {
|
|
12
|
+
pullCandidates,
|
|
13
|
+
matchToOfficial,
|
|
14
|
+
evaluateWithAI,
|
|
15
|
+
generateReport,
|
|
16
|
+
applyDecisions,
|
|
17
|
+
DEFAULT_SOURCES,
|
|
18
|
+
} from '../../skills/upgrade-engine.js';
|
|
19
|
+
import type { ReportEntry } from '../../skills/upgrade-engine.js';
|
|
20
|
+
import { ConfigManager } from '../../core/config.js';
|
|
21
|
+
import { ClaudeProvider } from '../../core/ai/provider.js';
|
|
22
|
+
import { FORGE_PATHS } from '../../core/constants.js';
|
|
10
23
|
|
|
11
24
|
const SKILLS_DIR = path.join(homedir(), '.claude', 'skills');
|
|
12
25
|
|
|
@@ -98,6 +111,126 @@ async function invokeSkill(skillId: string, options: InvokeOptions): Promise<voi
|
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
113
|
|
|
114
|
+
interface UpgradeOptions {
|
|
115
|
+
apply?: boolean;
|
|
116
|
+
rollback?: string;
|
|
117
|
+
report?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Coordinate the full skill upgrade pipeline.
|
|
122
|
+
* Default: dry-run — generates a report without writing to src/.
|
|
123
|
+
* --apply: read report and apply decisions.
|
|
124
|
+
* --rollback <ts>: restore official skills from a backup timestamp.
|
|
125
|
+
*/
|
|
126
|
+
async function upgradeSkills(options: UpgradeOptions): Promise<void> {
|
|
127
|
+
const reportPath = options.report ?? FORGE_PATHS.skillUpgradeReport();
|
|
128
|
+
const officialDir = resolveBuiltinDir();
|
|
129
|
+
const backupBaseDir = FORGE_PATHS.backups('skills');
|
|
130
|
+
const candidatesDir = FORGE_PATHS.skillCandidates();
|
|
131
|
+
|
|
132
|
+
// ── Rollback mode ────────────────────────────────────────────────────────
|
|
133
|
+
if (options.rollback) {
|
|
134
|
+
const backupPath = path.join(backupBaseDir, options.rollback);
|
|
135
|
+
try {
|
|
136
|
+
await fsPromises.access(backupPath);
|
|
137
|
+
} catch {
|
|
138
|
+
console.error(`Backup not found: ${backupPath}`);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
const files = await fsPromises.readdir(backupPath);
|
|
142
|
+
for (const file of files) {
|
|
143
|
+
if (!file.endsWith('.md')) continue;
|
|
144
|
+
await fsPromises.copyFile(path.join(backupPath, file), path.join(officialDir, file));
|
|
145
|
+
}
|
|
146
|
+
console.log(`Rolled back ${files.filter(f => f.endsWith('.md')).length} files from ${backupPath}`);
|
|
147
|
+
console.log('Run `npm run build` to rebuild with restored skills.');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── Apply mode ───────────────────────────────────────────────────────────
|
|
152
|
+
if (options.apply) {
|
|
153
|
+
try {
|
|
154
|
+
await fsPromises.access(reportPath);
|
|
155
|
+
} catch {
|
|
156
|
+
console.error(`Report not found: ${reportPath}`);
|
|
157
|
+
console.error('Run `cf skills upgrade` first to generate a report.');
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
console.log(`Applying decisions from ${reportPath}...`);
|
|
161
|
+
const result = await applyDecisions(reportPath, officialDir, backupBaseDir);
|
|
162
|
+
console.log(`\nApply complete:`);
|
|
163
|
+
console.log(` Applied : ${result.applied}`);
|
|
164
|
+
console.log(` Skipped : ${result.skipped}`);
|
|
165
|
+
console.log(` Backup : ${result.backupPath}`);
|
|
166
|
+
console.log('\nRun `npm run build` to rebuild with updated skills.');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ── Dry-run (report generation) mode ────────────────────────────────────
|
|
171
|
+
console.log('Fetching candidate skills...');
|
|
172
|
+
const candidates = await pullCandidates(DEFAULT_SOURCES, candidatesDir);
|
|
173
|
+
console.log(` Found ${candidates.length} candidate skills`);
|
|
174
|
+
|
|
175
|
+
const officialSkills = loadOfficialSkills(officialDir);
|
|
176
|
+
console.log(` Loaded ${officialSkills.length} official skills`);
|
|
177
|
+
|
|
178
|
+
// Set up AI provider
|
|
179
|
+
const config = new ConfigManager().get();
|
|
180
|
+
if (!config.ai.api_key) {
|
|
181
|
+
console.error('No AI API key configured. Run `cf menu` to set it up.');
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
const aiProvider = new ClaudeProvider(config.ai.api_key, config.ai.model, config.ai.base_url);
|
|
185
|
+
|
|
186
|
+
let matched = 0;
|
|
187
|
+
let unmatched = 0;
|
|
188
|
+
const entries: ReportEntry[] = [];
|
|
189
|
+
|
|
190
|
+
console.log('\nEvaluating candidates...');
|
|
191
|
+
|
|
192
|
+
for (const candidate of candidates) {
|
|
193
|
+
const matchResult = matchToOfficial(candidate, officialSkills);
|
|
194
|
+
if (!matchResult) {
|
|
195
|
+
unmatched++;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
matched++;
|
|
200
|
+
const official = officialSkills.find((o) => o.name === matchResult.officialId);
|
|
201
|
+
if (!official) continue;
|
|
202
|
+
|
|
203
|
+
process.stdout.write(` ${candidate.id} → ${official.name} (score ${matchResult.score})... `);
|
|
204
|
+
|
|
205
|
+
const decision = await evaluateWithAI(candidate, official, aiProvider);
|
|
206
|
+
const action = (decision as { needs_review?: boolean }).needs_review
|
|
207
|
+
? 'needs_review'
|
|
208
|
+
: decision.action;
|
|
209
|
+
|
|
210
|
+
process.stdout.write(`${action}\n`);
|
|
211
|
+
|
|
212
|
+
entries.push({
|
|
213
|
+
officialId: official.name,
|
|
214
|
+
candidateId: candidate.id,
|
|
215
|
+
candidateSource: candidate.source,
|
|
216
|
+
action,
|
|
217
|
+
confidence: decision.confidence,
|
|
218
|
+
reasoning: decision.reasoning,
|
|
219
|
+
candidateFilePath: candidate.filePath,
|
|
220
|
+
merged_content: decision.merged_content,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const stats = { total: candidates.length, matched, unmatched };
|
|
225
|
+
await generateReport(entries, reportPath, stats);
|
|
226
|
+
|
|
227
|
+
console.log(`\nReport generated: ${reportPath}`);
|
|
228
|
+
console.log(`Summary: ${matched} matched, ${unmatched} unmatched (of ${candidates.length} total)`);
|
|
229
|
+
console.log('\nReview the report, then run:');
|
|
230
|
+
console.log(' cf skills upgrade --apply (to apply decisions)');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
|
|
101
234
|
function registerSkillSubcommands(skills: Command): void {
|
|
102
235
|
skills
|
|
103
236
|
.command('sync')
|
|
@@ -124,6 +257,16 @@ function registerSkillSubcommands(skills: Command): void {
|
|
|
124
257
|
.action(async (skillId: string, options: InvokeOptions) => {
|
|
125
258
|
await invokeSkill(skillId, options);
|
|
126
259
|
});
|
|
260
|
+
|
|
261
|
+
skills
|
|
262
|
+
.command('upgrade')
|
|
263
|
+
.description('AI-assisted upgrade of official skills (dry-run by default)')
|
|
264
|
+
.option('--apply', 'Apply decisions from the last report')
|
|
265
|
+
.option('--rollback <timestamp>', 'Rollback to a backup (e.g. 20260518-1930)')
|
|
266
|
+
.option('--report <path>', 'Custom report path')
|
|
267
|
+
.action(async (options: UpgradeOptions) => {
|
|
268
|
+
await upgradeSkills(options);
|
|
269
|
+
});
|
|
127
270
|
}
|
|
128
271
|
|
|
129
272
|
export function register(program: Command): void {
|
package/src/core/constants.ts
CHANGED
|
@@ -28,6 +28,11 @@ export const FORGE_PATHS = {
|
|
|
28
28
|
// ── Patchable targets ───────────────────────────────────
|
|
29
29
|
routingYaml: () => join(FORGE_HOME, 'routing.yaml'),
|
|
30
30
|
backups: (kind: 'skills' | 'routing') => join(FORGE_HOME, 'backups', kind),
|
|
31
|
+
skillCandidates: (source?: string) =>
|
|
32
|
+
source
|
|
33
|
+
? join(FORGE_HOME, 'skill-candidates', source)
|
|
34
|
+
: join(FORGE_HOME, 'skill-candidates'),
|
|
35
|
+
skillUpgradeReport: () => join(FORGE_HOME, 'skill-upgrade-report.md'),
|
|
31
36
|
} as const;
|
|
32
37
|
|
|
33
38
|
/**
|
package/src/daemon/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ import { UserPromptHandler } from './handlers/user-prompt.js';
|
|
|
35
35
|
import { PostToolUseHandler } from './handlers/post-tool-use.js';
|
|
36
36
|
import { StopHandler } from './handlers/stop.js';
|
|
37
37
|
import { syncHooks } from './hook-sync.js';
|
|
38
|
+
import { syncSkills } from './skill-sync.js';
|
|
38
39
|
import { replayQueue } from '../core/queue/index.js';
|
|
39
40
|
import { DEFAULTS } from '../core/constants.js';
|
|
40
41
|
import type { ForgeEvent } from '../core/types.js';
|
|
@@ -84,6 +85,15 @@ export async function startDaemon(foreground: boolean = false, options: DaemonOp
|
|
|
84
85
|
logger.warn(`[HookSync] unexpected error: ${err}`);
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
// ── 3.6. Auto-sync official skills ─────────────────────────────────────
|
|
89
|
+
// npm upgrade 不会自动更新 ~/.claude/skills/,每次 daemon 启动
|
|
90
|
+
// 用 SHA-256 比对 dist/skills/official 与本地副本,不一致则覆盖。
|
|
91
|
+
try {
|
|
92
|
+
syncSkills();
|
|
93
|
+
} catch (err) {
|
|
94
|
+
logger.warn(`[SkillSync] unexpected error: ${err}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
// ── 4. AI Provider ─────────────────────────────────────────────────────────
|
|
88
98
|
const apiKey = config.ai.api_key || process.env.ANTHROPIC_API_KEY || '';
|
|
89
99
|
if (!apiKey) {
|
|
@@ -96,7 +106,7 @@ export async function startDaemon(foreground: boolean = false, options: DaemonOp
|
|
|
96
106
|
|
|
97
107
|
// ── 5. Initialize services ─────────────────────────────────────────────────
|
|
98
108
|
const skillApiKey = config.skill_matching?.api_key || apiKey;
|
|
99
|
-
const skillRegistry = new SkillRegistry(skillApiKey);
|
|
109
|
+
const skillRegistry = new SkillRegistry(skillApiKey, config.ai.model, config.ai.base_url);
|
|
100
110
|
const invocationGuard = new InvocationGuard();
|
|
101
111
|
if (skillApiKey) {
|
|
102
112
|
logger.info('[Skills] Registry loaded with semantic matching support');
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync, readFileSync, copyFileSync, mkdirSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { join, dirname } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { logger } from '../core/utils/logger.js';
|
|
7
|
+
|
|
8
|
+
const USER_SKILLS_DIR = join(homedir(), '.claude', 'skills');
|
|
9
|
+
|
|
10
|
+
function sha256(content: Buffer): string {
|
|
11
|
+
return createHash('sha256').update(content).digest('hex');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getSourceSkillsDir(): string {
|
|
15
|
+
// Compiled: dist/daemon/skill-sync.js → dist/skills/official
|
|
16
|
+
// Dev (vitest): src/daemon/skill-sync.ts → src/skills/official
|
|
17
|
+
return join(dirname(fileURLToPath(import.meta.url)), '..', 'skills', 'official');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SkillSyncResult {
|
|
21
|
+
copied: number;
|
|
22
|
+
checked: number;
|
|
23
|
+
skipped_userOwned: number; // user skills not in source list — untouched
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sync official skills from dist/skills/official to ~/.claude/skills/.
|
|
28
|
+
*
|
|
29
|
+
* Strategy:
|
|
30
|
+
* - Only files present in the source dir (dist/skills/official) are candidates
|
|
31
|
+
* - sha256 identical → skip; different → overwrite
|
|
32
|
+
* - User-only skills (not in source list) are never touched
|
|
33
|
+
* - Target dir is created if absent (first install)
|
|
34
|
+
*
|
|
35
|
+
* Failures are logged as warnings and never thrown — daemon startup must not be blocked.
|
|
36
|
+
*/
|
|
37
|
+
export function syncSkills(opts?: { sourceDir?: string; targetDir?: string }): SkillSyncResult {
|
|
38
|
+
const result: SkillSyncResult = { copied: 0, checked: 0, skipped_userOwned: 0 };
|
|
39
|
+
const sourceDir = opts?.sourceDir ?? getSourceSkillsDir();
|
|
40
|
+
const targetDir = opts?.targetDir ?? USER_SKILLS_DIR;
|
|
41
|
+
|
|
42
|
+
if (!existsSync(sourceDir)) {
|
|
43
|
+
logger.warn(`[SkillSync] source dir not found at ${sourceDir}, skipping`);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Ensure target dir exists (first install may not have ~/.claude/skills/)
|
|
48
|
+
try {
|
|
49
|
+
mkdirSync(targetDir, { recursive: true });
|
|
50
|
+
} catch {
|
|
51
|
+
/* ignore — if it already exists mkdirSync is a no-op */
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let sourceFiles: string[];
|
|
55
|
+
try {
|
|
56
|
+
sourceFiles = readdirSync(sourceDir).filter((f) => f.endsWith('.md'));
|
|
57
|
+
} catch (err) {
|
|
58
|
+
logger.warn(`[SkillSync] failed to list ${sourceDir}: ${err}`);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (const file of sourceFiles) {
|
|
63
|
+
result.checked++;
|
|
64
|
+
const src = join(sourceDir, file);
|
|
65
|
+
const dest = join(targetDir, file);
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const srcContent = readFileSync(src);
|
|
69
|
+
if (existsSync(dest)) {
|
|
70
|
+
const destContent = readFileSync(dest);
|
|
71
|
+
if (sha256(srcContent) === sha256(destContent)) {
|
|
72
|
+
continue; // identical — no copy needed
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
copyFileSync(src, dest);
|
|
77
|
+
result.copied++;
|
|
78
|
+
logger.info(`[SkillSync] updated ${file}`);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
logger.warn(`[SkillSync] failed to sync ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (result.copied > 0) {
|
|
85
|
+
logger.info(`[SkillSync] synced ${result.copied}/${result.checked} skill files`);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
@@ -18,7 +18,7 @@ SESSION_ID="${SESSION_ID:-${CLAUDE_CODE_SESSION_ID:-cli}}"
|
|
|
18
18
|
# 构造事件 JSON(原始 INPUT 作为 tool_input,保留完整通知内容)
|
|
19
19
|
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
|
|
20
20
|
TOOL_INPUT=$(echo "$INPUT" | jq -c '.')
|
|
21
|
-
EVENT=$(jq -
|
|
21
|
+
EVENT=$(jq -nc \
|
|
22
22
|
--arg hook_type "Notification" \
|
|
23
23
|
--arg timestamp "$TIMESTAMP" \
|
|
24
24
|
--arg session_id "$SESSION_ID" \
|
|
@@ -21,7 +21,7 @@ SESSION_ID="${SESSION_ID:-${CLAUDE_CODE_SESSION_ID:-cli}}"
|
|
|
21
21
|
|
|
22
22
|
# 构造事件 JSON
|
|
23
23
|
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
|
|
24
|
-
EVENT=$(jq -
|
|
24
|
+
EVENT=$(jq -nc \
|
|
25
25
|
--arg hook_type "PostToolUse" \
|
|
26
26
|
--arg timestamp "$TIMESTAMP" \
|
|
27
27
|
--arg session_id "$SESSION_ID" \
|
|
@@ -19,7 +19,7 @@ SESSION_ID="${SESSION_ID:-${CLAUDE_CODE_SESSION_ID:-cli}}"
|
|
|
19
19
|
|
|
20
20
|
# 构造事件 JSON(jq -n 替代 python3 heredoc)
|
|
21
21
|
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
|
|
22
|
-
EVENT=$(jq -
|
|
22
|
+
EVENT=$(jq -nc \
|
|
23
23
|
--arg hook_type "PreToolUse" \
|
|
24
24
|
--arg timestamp "$TIMESTAMP" \
|
|
25
25
|
--arg session_id "$SESSION_ID" \
|
package/src/hooks/stop.sh
CHANGED
|
@@ -17,7 +17,7 @@ SESSION_ID="${SESSION_ID:-${CLAUDE_CODE_SESSION_ID:-cli}}"
|
|
|
17
17
|
|
|
18
18
|
# 构造事件 JSON
|
|
19
19
|
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
|
|
20
|
-
EVENT=$(jq -
|
|
20
|
+
EVENT=$(jq -nc \
|
|
21
21
|
--arg hook_type "Stop" \
|
|
22
22
|
--arg timestamp "$TIMESTAMP" \
|
|
23
23
|
--arg session_id "$SESSION_ID" \
|
|
@@ -13,4 +13,40 @@ You will analyze recently modified code and apply refinements that:
|
|
|
13
13
|
2. **Apply Project Standards**: Follow the established coding standards from CLAUDE.md including:
|
|
14
14
|
|
|
15
15
|
- Use ES modules with proper import sorting and extensions
|
|
16
|
-
- Prefer `
|
|
16
|
+
- Prefer `function` keyword over arrow functions
|
|
17
|
+
- Use explicit return type annotations for top-level functions
|
|
18
|
+
- Follow proper React component patterns with explicit Props types
|
|
19
|
+
- Use proper error handling patterns (avoid try/catch when possible)
|
|
20
|
+
- Maintain consistent naming conventions
|
|
21
|
+
|
|
22
|
+
3. **Enhance Clarity**: Simplify code structure by:
|
|
23
|
+
|
|
24
|
+
- Reducing unnecessary complexity and nesting
|
|
25
|
+
- Eliminating redundant code and abstractions
|
|
26
|
+
- Improving readability through clear variable and function names
|
|
27
|
+
- Consolidating related logic
|
|
28
|
+
- Removing unnecessary comments that describe obvious code
|
|
29
|
+
- IMPORTANT: Avoid nested ternary operators - prefer switch statements or if/else chains for multiple conditions
|
|
30
|
+
- Choose clarity over brevity - explicit code is often better than overly compact code
|
|
31
|
+
|
|
32
|
+
4. **Maintain Balance**: Avoid over-simplification that could:
|
|
33
|
+
|
|
34
|
+
- Reduce code clarity or maintainability
|
|
35
|
+
- Create overly clever solutions that are hard to understand
|
|
36
|
+
- Combine too many concerns into single functions or components
|
|
37
|
+
- Remove helpful abstractions that improve code organization
|
|
38
|
+
- Prioritize "fewer lines" over readability (e.g., nested ternaries, dense one-liners)
|
|
39
|
+
- Make the code harder to debug or extend
|
|
40
|
+
|
|
41
|
+
5. **Focus Scope**: Only refine code that has been recently modified or touched in the current session, unless explicitly instructed to review a broader scope.
|
|
42
|
+
|
|
43
|
+
Your refinement process:
|
|
44
|
+
|
|
45
|
+
1. Identify the recently modified code sections
|
|
46
|
+
2. Analyze for opportunities to improve elegance and consistency
|
|
47
|
+
3. Apply project-specific best practices and coding standards
|
|
48
|
+
4. Ensure all functionality remains unchanged
|
|
49
|
+
5. Verify the refined code is simpler and more maintainable
|
|
50
|
+
6. Document only significant changes that affect understanding
|
|
51
|
+
|
|
52
|
+
You operate autonomously and proactively, refining code immediately after it's written or modified without requiring explicit requests. Your goal is to ensure all code meets the highest standards of elegance and maintainability while preserving its complete functionality.
|
|
@@ -20,4 +20,123 @@ Use this skill when the user:
|
|
|
20
20
|
|
|
21
21
|
## What is the Skills CLI?
|
|
22
22
|
|
|
23
|
-
The Skills CLI (`
|
|
23
|
+
The Skills CLI (`npx skills`) is the package manager for the open agent skills ecosystem. Skills are modular packages that extend agent capabilities with specialized knowledge, workflows, and tools.
|
|
24
|
+
|
|
25
|
+
**Key commands:**
|
|
26
|
+
|
|
27
|
+
- `npx skills find [query]` - Search for skills interactively or by keyword
|
|
28
|
+
- `npx skills add <package>` - Install a skill from GitHub or other sources
|
|
29
|
+
- `npx skills check` - Check for skill updates
|
|
30
|
+
- `npx skills update` - Update all installed skills
|
|
31
|
+
|
|
32
|
+
**Browse skills at:** https://skills.sh/
|
|
33
|
+
|
|
34
|
+
## How to Help Users Find Skills
|
|
35
|
+
|
|
36
|
+
### Step 1: Understand What They Need
|
|
37
|
+
|
|
38
|
+
When a user asks for help with something, identify:
|
|
39
|
+
|
|
40
|
+
1. The domain (e.g., React, testing, design, deployment)
|
|
41
|
+
2. The specific task (e.g., writing tests, creating animations, reviewing PRs)
|
|
42
|
+
3. Whether this is a common enough task that a skill likely exists
|
|
43
|
+
|
|
44
|
+
### Step 2: Check the Leaderboard First
|
|
45
|
+
|
|
46
|
+
Before running a CLI search, check the [skills.sh leaderboard](https://skills.sh/) to see if a well-known skill already exists for the domain. The leaderboard ranks skills by total installs, surfacing the most popular and battle-tested options.
|
|
47
|
+
|
|
48
|
+
For example, top skills for web development include:
|
|
49
|
+
- `vercel-labs/agent-skills` — React, Next.js, web design (100K+ installs each)
|
|
50
|
+
- `anthropics/skills` — Frontend design, document processing (100K+ installs)
|
|
51
|
+
|
|
52
|
+
### Step 3: Search for Skills
|
|
53
|
+
|
|
54
|
+
If the leaderboard doesn't cover the user's need, run the find command:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx skills find [query]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For example:
|
|
61
|
+
|
|
62
|
+
- User asks "how do I make my React app faster?" → `npx skills find react performance`
|
|
63
|
+
- User asks "can you help me with PR reviews?" → `npx skills find pr review`
|
|
64
|
+
- User asks "I need to create a changelog" → `npx skills find changelog`
|
|
65
|
+
|
|
66
|
+
### Step 4: Verify Quality Before Recommending
|
|
67
|
+
|
|
68
|
+
**Do not recommend a skill based solely on search results.** Always verify:
|
|
69
|
+
|
|
70
|
+
1. **Install count** — Prefer skills with 1K+ installs. Be cautious with anything under 100.
|
|
71
|
+
2. **Source reputation** — Official sources (`vercel-labs`, `anthropics`, `microsoft`) are more trustworthy than unknown authors.
|
|
72
|
+
3. **GitHub stars** — Check the source repository. A skill from a repo with <100 stars should be treated with skepticism.
|
|
73
|
+
|
|
74
|
+
### Step 5: Present Options to the User
|
|
75
|
+
|
|
76
|
+
When you find relevant skills, present them to the user with:
|
|
77
|
+
|
|
78
|
+
1. The skill name and what it does
|
|
79
|
+
2. The install count and source
|
|
80
|
+
3. The install command they can run
|
|
81
|
+
4. A link to learn more at skills.sh
|
|
82
|
+
|
|
83
|
+
Example response:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
I found a skill that might help! The "react-best-practices" skill provides
|
|
87
|
+
React and Next.js performance optimization guidelines from Vercel Engineering.
|
|
88
|
+
(185K installs)
|
|
89
|
+
|
|
90
|
+
To install it:
|
|
91
|
+
npx skills add vercel-labs/agent-skills@react-best-practices
|
|
92
|
+
|
|
93
|
+
Learn more: https://skills.sh/vercel-labs/agent-skills/react-best-practices
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Step 6: Offer to Install
|
|
97
|
+
|
|
98
|
+
If the user wants to proceed, you can install the skill for them:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx skills add <owner/repo@skill> -g -y
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The `-g` flag installs globally (user-level) and `-y` skips confirmation prompts.
|
|
105
|
+
|
|
106
|
+
## Common Skill Categories
|
|
107
|
+
|
|
108
|
+
When searching, consider these common categories:
|
|
109
|
+
|
|
110
|
+
| Category | Example Queries |
|
|
111
|
+
| --------------- | ---------------------------------------- |
|
|
112
|
+
| Web Development | react, nextjs, typescript, css, tailwind |
|
|
113
|
+
| Testing | testing, jest, playwright, e2e |
|
|
114
|
+
| DevOps | deploy, docker, kubernetes, ci-cd |
|
|
115
|
+
| Documentation | docs, readme, changelog, api-docs |
|
|
116
|
+
| Code Quality | review, lint, refactor, best-practices |
|
|
117
|
+
| Design | ui, ux, design-system, accessibility |
|
|
118
|
+
| Productivity | workflow, automation, git |
|
|
119
|
+
|
|
120
|
+
## Tips for Effective Searches
|
|
121
|
+
|
|
122
|
+
1. **Use specific keywords**: "react testing" is better than just "testing"
|
|
123
|
+
2. **Try alternative terms**: If "deploy" doesn't work, try "deployment" or "ci-cd"
|
|
124
|
+
3. **Check popular sources**: Many skills come from `vercel-labs/agent-skills` or `ComposioHQ/awesome-claude-skills`
|
|
125
|
+
|
|
126
|
+
## When No Skills Are Found
|
|
127
|
+
|
|
128
|
+
If no relevant skills exist:
|
|
129
|
+
|
|
130
|
+
1. Acknowledge that no existing skill was found
|
|
131
|
+
2. Offer to help with the task directly using your general capabilities
|
|
132
|
+
3. Suggest the user could create their own skill with `npx skills init`
|
|
133
|
+
|
|
134
|
+
Example:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
I searched for skills related to "xyz" but didn't find any matches.
|
|
138
|
+
I can still help you with this task directly! Would you like me to proceed?
|
|
139
|
+
|
|
140
|
+
If this is something you do often, you could create your own skill:
|
|
141
|
+
npx skills init my-xyz-skill
|
|
142
|
+
```
|
|
@@ -14,4 +14,17 @@ tags: [api, rest, design, backend]
|
|
|
14
14
|
4. 再实现
|
|
15
15
|
|
|
16
16
|
## RESTful 规范
|
|
17
|
-
- URL
|
|
17
|
+
- URL 用名词复数:`/users`,不用动词 `/getUser`
|
|
18
|
+
- 用 HTTP 动词表达操作:GET/POST/PUT/PATCH/DELETE
|
|
19
|
+
- 错误返回统一结构:`{ code, message, data }`
|
|
20
|
+
- 分页用 `?page=1&size=20`,返回 `total`
|
|
21
|
+
|
|
22
|
+
## 版本管理
|
|
23
|
+
- URL 版本:`/api/v1/users`(推荐)
|
|
24
|
+
- 破坏性变更必须升版本
|
|
25
|
+
|
|
26
|
+
## 通用原则
|
|
27
|
+
- 幂等性:PUT/DELETE 必须幂等
|
|
28
|
+
- 认证统一走 Authorization header
|
|
29
|
+
- 敏感字段不出现在 URL(用 body)
|
|
30
|
+
- 响应时间 P99 < 200ms,超时统一 30s
|
|
@@ -17,4 +17,25 @@ tags: [architecture, adr, design, decision]
|
|
|
17
17
|
|
|
18
18
|
## ADR 模板
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
```markdown
|
|
21
|
+
# ADR-{编号}: {标题}
|
|
22
|
+
|
|
23
|
+
## 状态
|
|
24
|
+
Proposed / Accepted / Deprecated
|
|
25
|
+
|
|
26
|
+
## 背景
|
|
27
|
+
为什么需要做这个决策?当前面临什么问题?
|
|
28
|
+
|
|
29
|
+
## 决策
|
|
30
|
+
我们选择做什么?
|
|
31
|
+
|
|
32
|
+
## 备选方案
|
|
33
|
+
考虑过哪些其他方案?为什么没选?
|
|
34
|
+
|
|
35
|
+
## 后果
|
|
36
|
+
这个决策带来什么好处?有什么代价或风险?
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 规则
|
|
40
|
+
- ADR 一旦 Accepted 不得修改,只能新建 ADR 来废弃或替代
|
|
41
|
+
- 存放在项目 `docs/adr/` 目录
|
|
@@ -13,4 +13,22 @@ tags: [database, schema, sql, migration]
|
|
|
13
13
|
- 外键约束在数据库层面强制
|
|
14
14
|
|
|
15
15
|
## 命名规范
|
|
16
|
-
- 表名:snake_case 复数(`
|
|
16
|
+
- 表名:snake_case 复数(`user_profiles`)
|
|
17
|
+
- 主键:`id`(自增或 UUID)
|
|
18
|
+
- 时间戳:`created_at`、`updated_at`(每张表必有)
|
|
19
|
+
- 软删除:`deleted_at` nullable
|
|
20
|
+
|
|
21
|
+
## 索引策略
|
|
22
|
+
- 外键列必须建索引
|
|
23
|
+
- 高频查询的 WHERE 条件列建索引
|
|
24
|
+
- 复合索引遵循最左前缀原则
|
|
25
|
+
|
|
26
|
+
## 迁移规范
|
|
27
|
+
- 每次变更写迁移文件,不手动改生产库
|
|
28
|
+
- 迁移必须可回滚(写 down migration)
|
|
29
|
+
- 破坏性变更分三步:加新列 → 双写 → 删旧列
|
|
30
|
+
|
|
31
|
+
## 常见陷阱
|
|
32
|
+
- 不用 `ENUM` 类型,用关联表或字符串
|
|
33
|
+
- JSON 列只存真正非结构化数据
|
|
34
|
+
- 避免 EAV 模式(Entity-Attribute-Value)
|
|
@@ -14,4 +14,12 @@ tags: [debug, troubleshooting]
|
|
|
14
14
|
|
|
15
15
|
2. **隔离** — 缩小根因范围
|
|
16
16
|
- 二分法排查代码路径
|
|
17
|
-
- 检查近期变更(`
|
|
17
|
+
- 检查近期变更(`git bisect`)
|
|
18
|
+
- 加日志,不要靠猜
|
|
19
|
+
|
|
20
|
+
3. **假设** — 清晰陈述假设再验证,每次只验证一个
|
|
21
|
+
|
|
22
|
+
4. **修复** — 最小化修复,解决根本原因
|
|
23
|
+
- 修复前先写一个能复现 bug 的测试
|
|
24
|
+
|
|
25
|
+
5. **验证** — 原始 bug 消失 + 无回归 + 测试通过
|