openmatrix 0.1.90 → 0.1.92

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 CHANGED
@@ -493,6 +493,10 @@ cd openmatrix && npm install && npm run build && npm test
493
493
  - [x] `/om:research` AI 驱动领域调研
494
494
  - [x] Git 自动提交 (任务完成后自动 commit)
495
495
  - [x] Brainstorm/Start 智能状态检测
496
+ - [x] AI 目标类型标注 (智能识别开发/测试/文档任务)
497
+ - [x] 系统集成任务 (多模块自动组装)
498
+ - [x] 智能项目检测 (gitignore 根据技术栈自动写入)
499
+ - [x] Git 父级目录支持 (子目录中正常执行 git 操作)
496
500
  - [ ] VSCode 扩展
497
501
  - [ ] CI/CD 集成
498
502
 
@@ -1,10 +1,9 @@
1
1
  /**
2
- * 确保指定目录被 git 忽略
2
+ * 确保 .gitignore 包含当前项目需要的所有忽略条目
3
+ *
4
+ * 自动检测项目类型(Node.js/Python/Java/Go/Rust/.NET/Vue/React),
5
+ * 补充对应的 node_modules、dist、.venv、target 等忽略规则。
6
+ *
3
7
  * @param basePath 项目目录(可以是 git 仓库的子目录)
4
- * @param ignorePattern 要忽略的模式 (默认 .openmatrix/)
5
- */
6
- export declare function ensureGitignore(basePath: string, ignorePattern?: string): Promise<void>;
7
- /**
8
- * 确保 .openmatrix 目录被 git 忽略
9
8
  */
10
9
  export declare function ensureOpenmatrixGitignore(basePath: string): Promise<void>;
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ensureGitignore = ensureGitignore;
37
36
  exports.ensureOpenmatrixGitignore = ensureOpenmatrixGitignore;
38
37
  // src/utils/gitignore.ts
39
38
  const fs = __importStar(require("fs/promises"));
@@ -53,14 +52,148 @@ async function getGitRoot(basePath) {
53
52
  return basePath;
54
53
  }
55
54
  }
55
+ // ============ 项目类型检测 ============
56
56
  /**
57
- * 需要确保被忽略的条目列表
57
+ * 项目类型对应的 gitignore 条目
58
58
  */
59
- const REQUIRED_IGNORE_ENTRIES = [
60
- '.openmatrix/',
61
- 'node_modules/',
62
- 'dist/',
63
- ];
59
+ const GITIGNORE_TEMPLATES = {
60
+ nodejs: [
61
+ 'node_modules/',
62
+ 'dist/',
63
+ 'build/',
64
+ '.npm/',
65
+ '*.log',
66
+ 'npm-debug.log*',
67
+ 'yarn-debug.log*',
68
+ 'yarn-error.log*',
69
+ ],
70
+ typescript: [
71
+ '*.tsbuildinfo',
72
+ ],
73
+ python: [
74
+ '__pycache__/',
75
+ '*.py[cod]',
76
+ '.venv/',
77
+ 'venv/',
78
+ '.pytest_cache/',
79
+ '.mypy_cache/',
80
+ '*.egg-info/',
81
+ ],
82
+ java: [
83
+ 'target/',
84
+ '.gradle/',
85
+ '*.class',
86
+ '*.jar',
87
+ ],
88
+ go: [
89
+ 'vendor/',
90
+ 'bin/',
91
+ '*.exe',
92
+ '*.dll',
93
+ '*.so',
94
+ '*.dylib',
95
+ ],
96
+ rust: [
97
+ 'target/',
98
+ 'Cargo.lock',
99
+ ],
100
+ dotnet: [
101
+ 'bin/',
102
+ 'obj/',
103
+ '*.nupkg',
104
+ ],
105
+ vue: [
106
+ '.nuxt/',
107
+ '.output/',
108
+ '.vite/',
109
+ ],
110
+ react: [
111
+ '.next/',
112
+ ],
113
+ common: [
114
+ '.env',
115
+ '.env.local',
116
+ '.env.*.local',
117
+ '.DS_Store',
118
+ 'Thumbs.db',
119
+ '*.swp',
120
+ '*~',
121
+ '.idea/',
122
+ '.vscode/',
123
+ '*.iml',
124
+ ],
125
+ openmatrix: [
126
+ '.openmatrix/',
127
+ ],
128
+ };
129
+ /**
130
+ * 根据项目文件检测项目类型
131
+ */
132
+ async function detectProjectTypes(projectRoot) {
133
+ const types = [];
134
+ // 检查 package.json → nodejs + 可能的框架
135
+ try {
136
+ const content = await fs.readFile(path.join(projectRoot, 'package.json'), 'utf-8');
137
+ const pkg = JSON.parse(content);
138
+ types.push('nodejs');
139
+ if (pkg.devDependencies?.typescript || pkg.dependencies?.typescript) {
140
+ types.push('typescript');
141
+ }
142
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
143
+ if (allDeps['nuxt'] || allDeps['@nuxt/content'])
144
+ types.push('vue');
145
+ if (allDeps['next'] || allDeps['@next/react'])
146
+ types.push('react');
147
+ }
148
+ catch { /* not node */ }
149
+ // 检查 Python
150
+ try {
151
+ await fs.access(path.join(projectRoot, 'pyproject.toml'));
152
+ types.push('python');
153
+ }
154
+ catch { }
155
+ try {
156
+ await fs.access(path.join(projectRoot, 'requirements.txt'));
157
+ if (!types.includes('python'))
158
+ types.push('python');
159
+ }
160
+ catch { }
161
+ // 检查 Java
162
+ try {
163
+ await fs.access(path.join(projectRoot, 'pom.xml'));
164
+ types.push('java');
165
+ }
166
+ catch { }
167
+ try {
168
+ await fs.access(path.join(projectRoot, 'build.gradle'));
169
+ if (!types.includes('java'))
170
+ types.push('java');
171
+ }
172
+ catch { }
173
+ // 检查 Go
174
+ try {
175
+ await fs.access(path.join(projectRoot, 'go.mod'));
176
+ types.push('go');
177
+ }
178
+ catch { }
179
+ // 检查 Rust
180
+ try {
181
+ await fs.access(path.join(projectRoot, 'Cargo.toml'));
182
+ types.push('rust');
183
+ }
184
+ catch { }
185
+ // 检查 .NET
186
+ try {
187
+ const files = await fs.readdir(projectRoot);
188
+ if (files.some(f => f.endsWith('.sln') || f.endsWith('.csproj')))
189
+ types.push('dotnet');
190
+ }
191
+ catch { }
192
+ types.push('common');
193
+ types.push('openmatrix');
194
+ return types;
195
+ }
196
+ // ============ Gitignore 操作 ============
64
197
  /**
65
198
  * 检查 gitignore 内容中是否已包含指定模式
66
199
  */
@@ -75,13 +208,36 @@ function hasGitignoreEntry(content, pattern) {
75
208
  });
76
209
  }
77
210
  /**
78
- * 确保指定目录被 git 忽略
211
+ * 根据项目类型收集所有需要的 gitignore 条目
212
+ */
213
+ function collectRequiredEntries(projectTypes) {
214
+ const seen = new Set();
215
+ const entries = [];
216
+ for (const type of projectTypes) {
217
+ const template = GITIGNORE_TEMPLATES[type];
218
+ if (template) {
219
+ for (const entry of template) {
220
+ if (!seen.has(entry)) {
221
+ seen.add(entry);
222
+ entries.push(entry);
223
+ }
224
+ }
225
+ }
226
+ }
227
+ return entries;
228
+ }
229
+ /**
230
+ * 确保 .gitignore 包含当前项目需要的所有忽略条目
231
+ *
232
+ * 自动检测项目类型(Node.js/Python/Java/Go/Rust/.NET/Vue/React),
233
+ * 补充对应的 node_modules、dist、.venv、target 等忽略规则。
234
+ *
79
235
  * @param basePath 项目目录(可以是 git 仓库的子目录)
80
- * @param ignorePattern 要忽略的模式 (默认 .openmatrix/)
81
236
  */
82
- async function ensureGitignore(basePath, ignorePattern = '.openmatrix/') {
237
+ async function ensureOpenmatrixGitignore(basePath) {
83
238
  const gitRoot = await getGitRoot(basePath);
84
239
  const gitignorePath = path.join(gitRoot, '.gitignore');
240
+ // 读取现有内容
85
241
  let content = '';
86
242
  try {
87
243
  content = await fs.readFile(gitignorePath, 'utf-8');
@@ -89,27 +245,54 @@ async function ensureGitignore(basePath, ignorePattern = '.openmatrix/') {
89
245
  catch {
90
246
  // 文件不存在
91
247
  }
92
- // 收集所有缺失的条目
93
- const missingEntries = [];
94
- const entriesToCheck = ignorePattern === '.openmatrix/'
95
- ? REQUIRED_IGNORE_ENTRIES // ensureOpenmatrixGitignore 时检查所有必要条目
96
- : [ignorePattern]; // 其他情况只检查指定的
97
- for (const entry of entriesToCheck) {
98
- if (!hasGitignoreEntry(content, entry)) {
99
- missingEntries.push(entry);
100
- }
101
- }
248
+ // 检测项目类型并收集需要的条目
249
+ const projectTypes = await detectProjectTypes(gitRoot);
250
+ const requiredEntries = collectRequiredEntries(projectTypes);
251
+ // 筛选缺失的条目
252
+ const missingEntries = requiredEntries.filter(e => !hasGitignoreEntry(content, e));
102
253
  if (missingEntries.length === 0)
103
254
  return;
104
- // 追加缺失的条目
105
- const addition = (content && !content.endsWith('\n') ? '\n' : '') +
106
- '\n# Auto-added by OpenMatrix\n' +
107
- missingEntries.join('\n') + '\n';
255
+ // 按类型分组追加
256
+ const timestamp = new Date().toISOString().split('T')[0];
257
+ const groups = {
258
+ 'Dependencies': [],
259
+ 'Build Output': [],
260
+ 'Environment': [],
261
+ 'IDE / Editor': [],
262
+ 'OS Files': [],
263
+ 'OpenMatrix': [],
264
+ 'Other': [],
265
+ };
266
+ for (const entry of missingEntries) {
267
+ if (entry.includes('node_modules') || entry.includes('vendor') || entry.includes('.venv') || entry.includes('packages')) {
268
+ groups['Dependencies'].push(entry);
269
+ }
270
+ else if (entry.includes('dist') || entry.includes('build') || entry.includes('target') || entry.includes('bin') || entry.includes('obj') || entry.includes('.output') || entry.includes('.next') || entry.includes('.nuxt')) {
271
+ groups['Build Output'].push(entry);
272
+ }
273
+ else if (entry.includes('.env')) {
274
+ groups['Environment'].push(entry);
275
+ }
276
+ else if (entry.includes('.idea') || entry.includes('.vscode') || entry.includes('.vite') || entry.includes('.iml')) {
277
+ groups['IDE / Editor'].push(entry);
278
+ }
279
+ else if (entry.includes('.openmatrix')) {
280
+ groups['OpenMatrix'].push(entry);
281
+ }
282
+ else if (entry.includes('.DS_Store') || entry.includes('Thumbs.db')) {
283
+ groups['OS Files'].push(entry);
284
+ }
285
+ else {
286
+ groups['Other'].push(entry);
287
+ }
288
+ }
289
+ let addition = (content && !content.endsWith('\n') ? '\n' : '') +
290
+ `\n# Auto-generated by OpenMatrix (${timestamp})\n`;
291
+ for (const [group, items] of Object.entries(groups)) {
292
+ if (items.length > 0) {
293
+ addition += `\n# ${group}\n`;
294
+ addition += items.join('\n') + '\n';
295
+ }
296
+ }
108
297
  await fs.writeFile(gitignorePath, content + addition, 'utf-8');
109
298
  }
110
- /**
111
- * 确保 .openmatrix 目录被 git 忽略
112
- */
113
- async function ensureOpenmatrixGitignore(basePath) {
114
- await ensureGitignore(basePath, '.openmatrix/');
115
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmatrix",
3
- "version": "0.1.90",
3
+ "version": "0.1.92",
4
4
  "description": "AI Agent task orchestration system with Claude Code Skills integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",