@xuxiao-dev/ai-dev-kit 0.1.0

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/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # ai-dev-kit
2
+
3
+ `@xuxiao-dev/ai-dev-kit` is an npm CLI toolkit for installing AI development helper resources into a project.
4
+
5
+ The first version focuses on Cursor resources:
6
+
7
+ - Cursor rules: installed to `.cursor/rules`
8
+ - Cursor commands: installed to `.cursor/commands`
9
+
10
+ ## Installation
11
+
12
+ Use it directly with `npx`:
13
+
14
+ ```bash
15
+ npx @xuxiao-dev/ai-dev-kit cursor list
16
+ ```
17
+
18
+ Or install it in a project:
19
+
20
+ ```bash
21
+ pnpm add -D @xuxiao-dev/ai-dev-kit
22
+ pnpm ai-dev-kit cursor list
23
+ ```
24
+
25
+ ## Commands
26
+
27
+ List built-in Cursor resources:
28
+
29
+ ```bash
30
+ ai-dev-kit cursor list
31
+ ```
32
+
33
+ Install one rule:
34
+
35
+ ```bash
36
+ ai-dev-kit cursor add rule vue3-typescript
37
+ ```
38
+
39
+ Install one command:
40
+
41
+ ```bash
42
+ ai-dev-kit cursor add command generate-readme
43
+ ```
44
+
45
+ Install all Cursor resources:
46
+
47
+ ```bash
48
+ ai-dev-kit cursor add --all
49
+ ```
50
+
51
+ Overwrite existing files:
52
+
53
+ ```bash
54
+ ai-dev-kit cursor add rule vue3-typescript --force
55
+ ai-dev-kit cursor add --all --force
56
+ ```
57
+
58
+ By default, existing files are skipped.
59
+
60
+ ## Built-in Resources
61
+
62
+ Cursor rules:
63
+
64
+ - `vue3-typescript`
65
+ - `h5-mobile-layout`
66
+ - `ui-review`
67
+
68
+ Cursor commands:
69
+
70
+ - `generate-readme`
71
+ - `review-ui`
72
+ - `create-mini-game-doc`
73
+
74
+ ## Directory Structure
75
+
76
+ Source resources live in this package:
77
+
78
+ ```text
79
+ cursor/
80
+ ├── rules/
81
+ │ ├── vue3-typescript.mdc
82
+ │ ├── h5-mobile-layout.mdc
83
+ │ └── ui-review.mdc
84
+ └── commands/
85
+ ├── generate-readme.md
86
+ ├── review-ui.md
87
+ └── create-mini-game-doc.md
88
+ ```
89
+
90
+ When installed into a business project, resources are copied to:
91
+
92
+ ```text
93
+ .cursor/
94
+ ├── rules/
95
+ │ └── xxx.mdc
96
+ └── commands/
97
+ └── xxx.md
98
+ ```
99
+
100
+ ## Development
101
+
102
+ ```bash
103
+ pnpm install
104
+ pnpm build
105
+ node bin/ai-dev-kit.js cursor list
106
+ node bin/ai-dev-kit.js cursor add --all
107
+ ```
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { Command as Command2 } from "commander";
5
+ import pc2 from "picocolors";
6
+
7
+ // src/commands/cursor.ts
8
+ import path2 from "path";
9
+ import { Command } from "commander";
10
+ import pc from "picocolors";
11
+
12
+ // src/utils/file.ts
13
+ import path from "path";
14
+ import fs from "fs-extra";
15
+ async function listResourceNames(directory, extension) {
16
+ if (!await fs.pathExists(directory)) {
17
+ return [];
18
+ }
19
+ const entries = await fs.readdir(directory);
20
+ return entries.filter((entry) => entry.endsWith(extension)).map((entry) => path.basename(entry, extension)).sort((a, b) => a.localeCompare(b));
21
+ }
22
+ async function copyFileWithMode(source, target, mode) {
23
+ await fs.ensureDir(path.dirname(target));
24
+ const exists = await fs.pathExists(target);
25
+ if (exists && mode === "skip") {
26
+ return "skipped";
27
+ }
28
+ await fs.copy(source, target, {
29
+ overwrite: true,
30
+ errorOnExist: false
31
+ });
32
+ return exists ? "overwritten" : "installed";
33
+ }
34
+
35
+ // src/commands/cursor.ts
36
+ var RESOURCE_CONFIG = {
37
+ rule: {
38
+ label: "rule",
39
+ sourceDir: path2.join("cursor", "rules"),
40
+ targetDir: path2.join(".cursor", "rules"),
41
+ extension: ".mdc"
42
+ },
43
+ command: {
44
+ label: "command",
45
+ sourceDir: path2.join("cursor", "commands"),
46
+ targetDir: path2.join(".cursor", "commands"),
47
+ extension: ".md"
48
+ }
49
+ };
50
+ var RESOURCE_ORDER = {
51
+ rule: ["vue3-typescript", "h5-mobile-layout", "ui-review"],
52
+ command: ["generate-readme", "review-ui", "create-mini-game-doc"]
53
+ };
54
+ function createCursorCommand(context) {
55
+ const cursor = new Command("cursor").description("Manage Cursor rules and commands.");
56
+ cursor.command("list").description("List built-in Cursor resources.").action(async () => {
57
+ const resources = await getCursorResources(context.packageRoot);
58
+ console.log(pc.bold("Cursor Rules:"));
59
+ printResourceList(resources.rule);
60
+ console.log(pc.bold("Cursor Commands:"));
61
+ printResourceList(resources.command);
62
+ });
63
+ cursor.command("add").description("Install Cursor resources into the current project.").argument("[type]", "Resource type: rule or command").argument("[name]", "Resource name to install").option("--all", "Install all Cursor rules and commands").option("--force", "Overwrite existing files").action(async (type, name, options) => {
64
+ await handleAdd(context.packageRoot, type, name, options);
65
+ });
66
+ return cursor;
67
+ }
68
+ async function handleAdd(packageRoot2, rawType, name, options) {
69
+ const projectRoot = process.cwd();
70
+ const mode = options.force ? "overwrite" : "skip";
71
+ if (options.all) {
72
+ if (rawType || name) {
73
+ throw new Error('Use either "cursor add --all" or "cursor add <rule|command> <name>", not both.');
74
+ }
75
+ const resources2 = await getCursorResources(packageRoot2);
76
+ await installMany(packageRoot2, projectRoot, "rule", resources2.rule, mode);
77
+ await installMany(packageRoot2, projectRoot, "command", resources2.command, mode);
78
+ return;
79
+ }
80
+ const type = normalizeResourceType(rawType);
81
+ if (!type || !name) {
82
+ throw new Error("Missing arguments. Usage: ai-dev-kit cursor add <rule|command> <name> or ai-dev-kit cursor add --all");
83
+ }
84
+ const resources = await getCursorResources(packageRoot2);
85
+ const available = resources[type];
86
+ if (!available.includes(name)) {
87
+ throw new Error(
88
+ [
89
+ `Unknown Cursor ${RESOURCE_CONFIG[type].label}: ${name}`,
90
+ `Available ${RESOURCE_CONFIG[type].label}s: ${formatAvailable(available)}`
91
+ ].join("\n")
92
+ );
93
+ }
94
+ await installOne(packageRoot2, projectRoot, type, name, mode);
95
+ }
96
+ async function installMany(packageRoot2, projectRoot, type, names, mode) {
97
+ for (const name of names) {
98
+ await installOne(packageRoot2, projectRoot, type, name, mode);
99
+ }
100
+ }
101
+ async function installOne(packageRoot2, projectRoot, type, name, mode) {
102
+ const config = RESOURCE_CONFIG[type];
103
+ const source = path2.join(packageRoot2, config.sourceDir, `${name}${config.extension}`);
104
+ const target = path2.join(projectRoot, config.targetDir, `${name}${config.extension}`);
105
+ const displayPath = path2.join(config.targetDir, `${name}${config.extension}`);
106
+ const result = await copyFileWithMode(source, target, mode);
107
+ if (result === "skipped") {
108
+ console.log(pc.yellow(`Skipped existing file: ${displayPath}`));
109
+ return;
110
+ }
111
+ if (result === "overwritten") {
112
+ console.log(pc.green(`Overwritten: ${displayPath}`));
113
+ return;
114
+ }
115
+ console.log(pc.green(`Installed: ${displayPath}`));
116
+ }
117
+ async function getCursorResources(packageRoot2) {
118
+ const [rules, commands] = await Promise.all([
119
+ listResourceNames(path2.join(packageRoot2, RESOURCE_CONFIG.rule.sourceDir), RESOURCE_CONFIG.rule.extension),
120
+ listResourceNames(path2.join(packageRoot2, RESOURCE_CONFIG.command.sourceDir), RESOURCE_CONFIG.command.extension)
121
+ ]);
122
+ return {
123
+ rule: sortByPreferredOrder(rules, RESOURCE_ORDER.rule),
124
+ command: sortByPreferredOrder(commands, RESOURCE_ORDER.command)
125
+ };
126
+ }
127
+ function normalizeResourceType(type) {
128
+ if (type === "rule" || type === "command") {
129
+ return type;
130
+ }
131
+ if (type) {
132
+ throw new Error('Invalid resource type. Use "rule" or "command".');
133
+ }
134
+ return void 0;
135
+ }
136
+ function printResourceList(names) {
137
+ if (names.length === 0) {
138
+ console.log(pc.dim("- none"));
139
+ return;
140
+ }
141
+ for (const name of names) {
142
+ console.log(`- ${name}`);
143
+ }
144
+ }
145
+ function formatAvailable(names) {
146
+ return names.length > 0 ? names.join(", ") : "none";
147
+ }
148
+ function sortByPreferredOrder(names, preferredOrder) {
149
+ const preferred = names.filter((name) => preferredOrder.includes(name));
150
+ const extra = names.filter((name) => !preferredOrder.includes(name));
151
+ return [
152
+ ...preferredOrder.filter((name) => preferred.includes(name)),
153
+ ...extra
154
+ ];
155
+ }
156
+
157
+ // src/utils/path.ts
158
+ import path3 from "path";
159
+ import { fileURLToPath } from "url";
160
+ function getPackageRoot(cliImportMetaUrl) {
161
+ const cliFile = fileURLToPath(cliImportMetaUrl);
162
+ return path3.resolve(path3.dirname(cliFile), "..");
163
+ }
164
+
165
+ // src/cli.ts
166
+ var program = new Command2();
167
+ var packageRoot = getPackageRoot(import.meta.url);
168
+ program.name("ai-dev-kit").description("Install AI development helper resources into your project.").version("0.1.0").showHelpAfterError().showSuggestionAfterError();
169
+ program.addCommand(createCursorCommand({ packageRoot }));
170
+ program.exitOverride();
171
+ try {
172
+ await program.parseAsync(process.argv);
173
+ } catch (error) {
174
+ if (error instanceof Error) {
175
+ console.error(pc2.red(error.message));
176
+ }
177
+ process.exit(1);
178
+ }
@@ -0,0 +1,164 @@
1
+ # 生成 Git Commit Message
2
+
3
+ 请根据当前 Git 暂存区变更生成符合 Conventional Commits 规范的 commit message,并在生成后自动执行 `git commit` 完成提交(省去复制命令步骤)。
4
+
5
+ 要求:
6
+
7
+ - 只分析已经 `git add` 的暂存区内容
8
+ - 优先执行并分析:
9
+
10
+ ```bash
11
+ git diff --cached
12
+ ```
13
+
14
+ - 不要分析未暂存内容
15
+ - 需要自动执行 `git commit`(提交内容来自暂存区)
16
+ - 不要在 commit message 中添加任何共同作者标记(例如 `Co-authored-by:` / `Co-Authored-By:` / `Co-authored-by: Cursor <cursoragent@cursor.com>` 等)
17
+ - 不要 `git push`
18
+ - 不要跳过 hooks(不要使用 `--no-verify` 等)
19
+ - 不要改写历史(不要使用 `--amend`、rebase、force push 等)
20
+ - 如果提交失败(例如 hook 拦截),只需要输出失败原因与下一步建议,不要重复多次尝试提交
21
+
22
+ 如果暂存区没有变更,请提示:
23
+
24
+ ```text
25
+ 当前暂存区没有变更,请先执行 git add 后再生成 commit message。
26
+ ```
27
+
28
+ ---
29
+
30
+ ## Commit 格式
31
+
32
+ 优先使用:
33
+
34
+ ```text
35
+ <type>(<scope>): <subject>
36
+ ```
37
+
38
+ 如果无法判断明确 scope,可以省略:
39
+
40
+ ```text
41
+ <type>: <subject>
42
+ ```
43
+
44
+ 如果变更多、单行说不清,可以补充 body:
45
+
46
+ ```text
47
+ <type>(<scope>): <subject>
48
+
49
+ - 变更点 1
50
+ - 变更点 2
51
+ - 变更点 3
52
+ ```
53
+
54
+ ---
55
+
56
+ ## type 选择规则
57
+
58
+ 根据暂存区变更选择最合适的 type:
59
+
60
+ - `feat`:新增功能
61
+ - `fix`:修复 bug、异常、错误逻辑
62
+ - `docs`:文档、注释、README、Cursor Rules、Cursor Commands
63
+ - `style`:格式调整,不影响逻辑
64
+ - `refactor`:重构,不新增功能也不修复 bug
65
+ - `perf`:性能优化
66
+ - `test`:测试相关
67
+ - `build`:依赖、构建配置、包管理、tsconfig、vite、webpack 等
68
+ - `ci`:CI/CD 配置
69
+ - `chore`:杂项维护、目录调整、工具配置
70
+ - `revert`:回滚提交
71
+
72
+ 如果同时包含多类变更,选择最核心的 type。
73
+
74
+ ---
75
+
76
+ ## scope 规则
77
+
78
+ scope 表示影响范围,使用英文小写。
79
+
80
+ 可根据文件路径、业务模块或技术模块判断,例如:
81
+
82
+ `upload`、`auth`、`router`、`api`、`store`、`components`、`docs`、`config`、`deps`、`cursor`、`command`
83
+
84
+ 无法明确判断时,不要强行编造 scope。
85
+
86
+ ---
87
+
88
+ ## subject 规则
89
+
90
+ subject 使用中文,要求:
91
+
92
+ - 简短明确
93
+ - 使用动宾结构
94
+ - 描述“做了什么”
95
+ - 不超过 50 个中文字符
96
+ - 不以句号结尾
97
+ - 不要写“修改代码”“更新文件”“优化一下”这类模糊描述
98
+
99
+ ---
100
+
101
+ ## 输出格式
102
+
103
+ 请严格按下面格式输出:
104
+
105
+ ### 推荐 commit message
106
+
107
+ ```text
108
+ <type>(<scope>): <subject>
109
+ ```
110
+
111
+ 如果需要 body:
112
+
113
+ ```text
114
+ <type>(<scope>): <subject>
115
+
116
+ - 变更点 1
117
+ - 变更点 2
118
+ - 变更点 3
119
+ ```
120
+
121
+ ### 自动提交(你需要实际执行)
122
+
123
+ 在生成 commit message 后,直接执行提交命令(不要让我复制粘贴)。
124
+
125
+ ```bash
126
+ git commit -m "<type>(<scope>): <subject>"
127
+ ```
128
+
129
+ 带 body:
130
+
131
+ ```bash
132
+ git commit -m "<type>(<scope>): <subject>" \
133
+ -m "- 变更点 1
134
+ - 变更点 2
135
+ - 变更点 3"
136
+ ```
137
+
138
+ ### 执行结果
139
+
140
+ 输出 `git commit` 的关键结果即可:
141
+
142
+ - 成功:展示新 commit 的摘要(hash、subject、变更文件数/行数等的简要信息)
143
+ - 失败:展示报错关键信息,并给出 1-2 条下一步建议(例如先修复 lint / 补充暂存 / 调整 message)
144
+
145
+ 并在成功后做一次自检,确保提交信息里没有共同作者标记:
146
+
147
+ ```bash
148
+ git show -s --format=%B HEAD
149
+ ```
150
+
151
+ 如果发现包含任何 `Co-authored-by:`(大小写不敏感),需要立刻执行一次仅修改提交信息的 `--amend` 去掉这些行,然后再次自检;如果该提交已经推到远端,提示需要使用 `git push --force-with-lease` 才能同步远端历史(但不要自动推送)。
152
+
153
+ ### 简短理由
154
+
155
+ 用一句话说明为什么选择这个 type 和 scope。
156
+
157
+ ---
158
+
159
+ ## 限制
160
+
161
+ - 不要输出完整 diff
162
+ - 不要输出冗长分析
163
+ - 不要输出多个无关候选
164
+ - 不要编造暂存区之外的信息