From 89fa958a4cc1a9f06444eeb0b7fa76f1e9202a8f Mon Sep 17 00:00:00 2001 From: Zen0space Date: Thu, 12 Mar 2026 04:45:27 +0800 Subject: [PATCH] fix: agent and skill files now smart merged instead of conflicting on update Two bugs in merge.js: SKILL category missing from SMART_MERGE_CATEGORIES, and path matching required a leading slash that relative paths never have. Agents and skills now correctly update their content from template on every npx ocs-stats update. --- README.md | 4 ++-- package.json | 2 +- src/merge.js | 28 +++++++++++++++++++++++++--- templates/.ocs-version | 1 + 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index df94abb..2598a54 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ All agents share these rules that cannot be overridden: ``` opencode-skills/ -├── package.json # npm package config (v1.3.4) +├── package.json # npm package config (v1.3.5) ├── bin/cli.js # CLI entry point ├── src/ # Source files │ ├── init.js @@ -392,7 +392,7 @@ Usage: ### Stats showing zeros or MAX LEVEL incorrectly -Make sure you're on v1.3.4 or later: +Make sure you're on v1.3.5 or later: ```bash npx ocs-stats update ``` diff --git a/package.json b/package.json index 0e53711..7f84fde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ocs-stats", - "version": "1.3.4", + "version": "1.3.5", "description": "OpenCode Skills - One-click installer with gamified XP stats", "type": "module", "bin": { diff --git a/src/merge.js b/src/merge.js index 03b7b55..772658d 100644 --- a/src/merge.js +++ b/src/merge.js @@ -24,7 +24,7 @@ export const FILE_CATEGORY = { }; const PROTECTED_CATEGORIES = [FILE_CATEGORY.XP_DATA, FILE_CATEGORY.MEMORIES]; -const SMART_MERGE_CATEGORIES = [FILE_CATEGORY.XP_DATA, FILE_CATEGORY.MEMORIES, FILE_CATEGORY.KNOWLEDGE, FILE_CATEGORY.AGENT]; +const SMART_MERGE_CATEGORIES = [FILE_CATEGORY.XP_DATA, FILE_CATEGORY.MEMORIES, FILE_CATEGORY.KNOWLEDGE, FILE_CATEGORY.AGENT, FILE_CATEGORY.SKILL]; const USER_PRESERVE_FIELDS = ['mode', 'tools', 'model', 'temperature', 'permission', 'hidden', 'color']; @@ -145,10 +145,10 @@ function getCategory(relativePath) { if (pathLower.includes('/knowledge.md')) { return FILE_CATEGORY.KNOWLEDGE; } - if (pathLower.includes('/skills/')) { + if (pathLower.includes('/skills/') || pathLower.startsWith('skills/')) { return FILE_CATEGORY.SKILL; } - if (pathLower.includes('/agents/')) { + if (pathLower.includes('/agents/') || pathLower.startsWith('agents/')) { return FILE_CATEGORY.AGENT; } return FILE_CATEGORY.SKILL; @@ -561,6 +561,28 @@ export async function performUpdate(targetDir, options = {}) { }); continue; } + + if (category === FILE_CATEGORY.SKILL) { + const userContent = fs.readFileSync(targetPath, 'utf-8'); + const templateContent = fs.readFileSync(templatePath, 'utf-8'); + + const mergeResult = smartMergeAgent(userContent, templateContent); + + if (!checkOnly) { + fs.writeFileSync(targetPath, mergeResult.content, 'utf-8'); + } + + const preserveInfo = mergeResult.preservedFields.length > 0 + ? `${mergeResult.preservedFields.join(', ')} preserved` + : 'updated'; + + results.merged.push({ + path: relativePath, + action: 'smart-merged', + preserveInfo + }); + continue; + } } if (PROTECTED_CATEGORIES.includes(category)) { diff --git a/templates/.ocs-version b/templates/.ocs-version index 8327341..30374d9 100644 --- a/templates/.ocs-version +++ b/templates/.ocs-version @@ -1,3 +1,4 @@ +1.3.5: Fix agent and skill files showing as conflicts instead of being smart merged on update 1.3.4: Re-release to trigger npm publish pipeline 1.3.3: Fix mandatory level-up reset and XP carry-over rule missing from all agents and skills 1.3.2: Fix stats display and smart merge to use correct xp.json field names