openmatrix 0.1.88 → 0.1.90

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.
@@ -39,6 +39,7 @@ const child_process_1 = require("child_process");
39
39
  const util_1 = require("util");
40
40
  const path = __importStar(require("path"));
41
41
  const fs = __importStar(require("fs/promises"));
42
+ const gitignore_js_1 = require("../utils/gitignore.js");
42
43
  const execAsync = (0, util_1.promisify)(child_process_1.exec);
43
44
  /**
44
45
  * GitCommitManager - Git 自动提交管理器
@@ -242,19 +243,7 @@ class GitCommitManager {
242
243
  this.gitRoot = this.repoPath; // 刚初始化的仓库,根目录就是 repoPath
243
244
  }
244
245
  // 确保 .gitignore 中包含 .openmatrix(写入到 git 根目录)
245
- const gitRoot = await this.getGitRoot();
246
- const gitignorePath = path.join(gitRoot, '.gitignore');
247
- let gitignoreContent = '';
248
- try {
249
- gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');
250
- }
251
- catch {
252
- // 文件不存在
253
- }
254
- if (!gitignoreContent.includes('.openmatrix')) {
255
- const addition = (gitignoreContent && !gitignoreContent.endsWith('\n') ? '\n' : '') + '.openmatrix/\n';
256
- await fs.writeFile(gitignorePath, gitignoreContent + addition, 'utf-8');
257
- }
246
+ await (0, gitignore_js_1.ensureOpenmatrixGitignore)(this.repoPath);
258
247
  // 获取未提交的文件
259
248
  const files = await this.getUncommittedFiles();
260
249
  if (files.length === 0) {
@@ -283,7 +272,7 @@ class GitCommitManager {
283
272
  };
284
273
  }
285
274
  // 使用临时文件传递 commit message(避免 Windows 下多行消息转义问题)
286
- const tmpFile = path.join(gitRoot, '.git', 'COMMIT_MSG_TMP');
275
+ const tmpFile = path.join(await this.getGitRoot(), '.git', 'COMMIT_MSG_TMP');
287
276
  await fs.writeFile(tmpFile, commitMessage, 'utf-8');
288
277
  try {
289
278
  const { stdout } = await execAsync(`git commit -F "${tmpFile}"`, { cwd: this.repoPath });
@@ -46,8 +46,9 @@ class TaskPlanner {
46
46
  // 构建全局上下文块(注入到每个子任务描述中,供 agent 参考)
47
47
  const globalContext = this.buildGlobalContext(parsedTask, userContext, plan);
48
48
  // 0. 设计阶段任务 (根据复杂度判断)
49
+ // 如果 AI 已提供 plan,跳过设计阶段(plan 中已包含架构设计)
49
50
  let designTaskId;
50
- if (this.needsDesignPhase(parsedTask)) {
51
+ if (!plan && this.needsDesignPhase(parsedTask)) {
51
52
  designTaskId = this.generateTaskId();
52
53
  breakdowns.push({
53
54
  taskId: designTaskId,
@@ -53,39 +53,59 @@ async function getGitRoot(basePath) {
53
53
  return basePath;
54
54
  }
55
55
  }
56
+ /**
57
+ * 需要确保被忽略的条目列表
58
+ */
59
+ const REQUIRED_IGNORE_ENTRIES = [
60
+ '.openmatrix/',
61
+ 'node_modules/',
62
+ 'dist/',
63
+ ];
64
+ /**
65
+ * 检查 gitignore 内容中是否已包含指定模式
66
+ */
67
+ function hasGitignoreEntry(content, pattern) {
68
+ const patternBase = pattern.replace(/\/$/, '');
69
+ return content.split('\n').some(line => {
70
+ const trimmed = line.trim();
71
+ return trimmed === patternBase ||
72
+ trimmed === `${patternBase}/` ||
73
+ trimmed === `/${patternBase}` ||
74
+ trimmed === `/${patternBase}/`;
75
+ });
76
+ }
56
77
  /**
57
78
  * 确保指定目录被 git 忽略
58
79
  * @param basePath 项目目录(可以是 git 仓库的子目录)
59
80
  * @param ignorePattern 要忽略的模式 (默认 .openmatrix/)
60
81
  */
61
82
  async function ensureGitignore(basePath, ignorePattern = '.openmatrix/') {
62
- // 写入到 git 根目录的 .gitignore
63
83
  const gitRoot = await getGitRoot(basePath);
64
84
  const gitignorePath = path.join(gitRoot, '.gitignore');
85
+ let content = '';
65
86
  try {
66
- const content = await fs.readFile(gitignorePath, 'utf-8');
67
- // 检查是否已经包含该模式
68
- const lines = content.split('\n');
69
- const patternBase = ignorePattern.replace(/\/$/, '');
70
- const hasPattern = lines.some(line => {
71
- const trimmed = line.trim();
72
- return trimmed === patternBase ||
73
- trimmed === `${patternBase}/` ||
74
- trimmed === `/${patternBase}` ||
75
- trimmed === `/${patternBase}/`;
76
- });
77
- if (!hasPattern) {
78
- // 添加模式到 .gitignore
79
- const newContent = content.endsWith('\n')
80
- ? `${content}${ignorePattern}\n`
81
- : `${content}\n\n# Auto-added by OpenMatrix\n${ignorePattern}\n`;
82
- await fs.writeFile(gitignorePath, newContent);
83
- }
87
+ content = await fs.readFile(gitignorePath, 'utf-8');
84
88
  }
85
89
  catch {
86
- // .gitignore 不存在,创建一个新的
87
- await fs.writeFile(gitignorePath, `# OpenMatrix state\n${ignorePattern}\n`);
90
+ // 文件不存在
91
+ }
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
+ }
88
101
  }
102
+ if (missingEntries.length === 0)
103
+ return;
104
+ // 追加缺失的条目
105
+ const addition = (content && !content.endsWith('\n') ? '\n' : '') +
106
+ '\n# Auto-added by OpenMatrix\n' +
107
+ missingEntries.join('\n') + '\n';
108
+ await fs.writeFile(gitignorePath, content + addition, 'utf-8');
89
109
  }
90
110
  /**
91
111
  * 确保 .openmatrix 目录被 git 忽略
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmatrix",
3
- "version": "0.1.88",
3
+ "version": "0.1.90",
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",