Commit b524fa2288d2d8b5babaaed7838f5681e1cccb8f

Authored by yibo
1 parent b43106fc

fix(company): _registry.json 写入补末尾换行,消除每次写入的伪 diff

四处写 _registry.json 的地方都用 JSON.stringify(registry, null, 2) 直接落盘,
不带末尾换行。文件在仓库里是带换行的,导致任何一次 hire()/depositTemplate()/
模板增删改之后,git diff 都会多出一行 "\ No newline at end of file" 的噪音,
把真实的数据变更淹掉。

写入点:
- company-service.js:374  depositTemplate()
- company-service.js:824  _updateTemplateUsedCount()
- routes/company.js:86    PATCH /templates/:templateId
- routes/company.js:120   DELETE /templates/:templateId

同时提交一次真实的运行时数据变更:qa-judge usedCount 7 → 8。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
server/routes/company.js
... ... @@ -83,7 +83,7 @@ router.patch(&#39;/templates/:templateId&#39;, (req, res) =&gt; {
83 83 if (name !== undefined) entry.name = name.trim();
84 84 if (type !== undefined) entry.type = type.trim();
85 85 if (description !== undefined) entry.description = description.trim();
86   - fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2), 'utf-8');
  86 + fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2) + '\n', 'utf-8');
87 87 }
88 88 } catch {}
89 89 }
... ... @@ -117,7 +117,7 @@ router.delete(&#39;/templates/:templateId&#39;, (req, res) =&gt; {
117 117 try {
118 118 let registry = JSON.parse(fs.readFileSync(registryPath, 'utf-8'));
119 119 registry = registry.filter(t => t.id !== templateId);
120   - fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2), 'utf-8');
  120 + fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2) + '\n', 'utf-8');
121 121 } catch {}
122 122 }
123 123  
... ...
server/services/company-service.js
... ... @@ -371,7 +371,7 @@ class CompanyService {
371 371 trainedAt: new Date().toISOString().slice(0, 10),
372 372 usedCount: 0,
373 373 });
374   - fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2), 'utf-8');
  374 + fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2) + '\n', 'utf-8');
375 375  
376 376 // 将 Agent 状态从 training → active
377 377 const configPath = path.join(agentDir, 'config.json');
... ... @@ -821,7 +821,7 @@ class CompanyService {
821 821 const entry = registry.find(t => t.id === templateId);
822 822 if (entry) {
823 823 entry.usedCount = (entry.usedCount || 0) + 1;
824   - fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2), 'utf-8');
  824 + fs.writeFileSync(registryPath, JSON.stringify(registry, null, 2) + '\n', 'utf-8');
825 825 }
826 826 } catch (err) {
827 827 console.warn(`[Company] ⚠️ 更新模板使用次数失败: ${err.message}`);
... ...
system/templates/_registry.json
... ... @@ -15,7 +15,7 @@
15 15 "description": "质量验收、OKR 进度审查、标准化仲裁",
16 16 "benchmarkScore": 95,
17 17 "trainedAt": "2026-03-25",
18   - "usedCount": 7
  18 + "usedCount": 8
19 19 },
20 20 {
21 21 "id": "base",
... ...