Preface¶
When using JSON as a content source for knowledge base sites, static CMS, or lightweight backends, a common mistake during data updates is treating an incoming file containing only a few new drafts as a full package, leading to a direct overwrite of the authoritative data source and the instant loss of historical articles. Manually diffing large JSON files is costly, and a merge script may not already exist in the project. The following introduces the SkillHub community Skill “Knowledge Safe Merge” (知识库安全合并), which uses a fixed SOP and optional scripts to string together a reproducible workflow: “Identify Data Source → Dry-run → Backup → Merge → Validate”.
What is this¶
Knowledge Safe Merge (Coordinate @user_87a42d61/knowledge-safe-merge, Version 1.0.0) is a knowledge-management Agent Skill published on SkillHub by community publisher user_87a42d61. The SkillHub page description reads: Safely merge knowledge base/content library JSON data, preserve historical articles, and avoid full-package overwrites. The tag is requires_api_key=false, indicating no dependency on external API Keys.
It targets data with a root object of { "categories": [], "articles": [] } (articles is core, categories is optional). It guides the Agent to distinguish between authoritative data sources, mirrors, and incoming files. By default, it assumes the incoming file may be incremental rather than full, and prohibits overwrite writes without rehearsal (dry-run) and backup.
Official entries:
- SkillHub Display Page: https://www.skillhub.cn/skills/user_87a42d61/knowledge-safe-merge
- API Coordinate Page: https://api.skillhub.cn/user_87a42d61/knowledge-safe-merge
(SkillHub Statistics: Rating 100000, Downloads 857, Installs 32.)
Core Features¶
Based on the SKILL.md and scripts/merge_knowledge_json.py inside the Skill package, the verified capabilities include:
- Workflow Constraints: Identify the authoritative formal data source first; treat incoming data as incremental by default; perform a dry-run first to view additions/updates/unchanged/total count after merge; backup before formal write; validate JSON and the page (if deployment is involved) after merging.
- Merge Rules: Prioritize matching by article
id; ifidis inconsistent, match by “title + date”; unmatched items are appended as new articles; results are sorted by date descending, then byid. - Built-in Script: When no existing project pipeline is available, use
merge_knowledge_json.pyto perform rehearsal or disk writing for--currentand--incoming; supports--backup-dir,--mirror,--output. - Output Manifest: Upon completion, report the data source path, incoming path, statistics items, whether backup/mirror sync was performed, and whether online validation was completed.
If the repository already has stable merge or import logic, the Skill requires prioritizing the reuse of the project’s solution before considering the built-in script.
Installation and Enablement¶
Via SkillHub CLI (Common for Cursor, Claude Code, Codex, etc.)¶
First, confirm if the CLI is installed:
command -v skillhub && skillhub --version
If not installed, follow the SkillHub installation documentation for the full installation (Documentation URL: https://skillhub.cn/install/skillhub.md):
curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash
When installing the Skill, you must use --dir to point to the current Agent’s skills directory; otherwise, it defaults to ./skills/ and may not be recognized. Community coordinates require the namespace:
skillhub install knowledge-safe-merge --namespace user_87a42d61 --dir <your skills directory>
Common paths (from SkillHub installation docs) examples:
- Cursor:
~/.cursor/skills/ - Claude Code:
~/.claude/skills/ - Codex:
~/.codex/skills/or.agents/skills/under the project
You can also provide the following prompt to an AI to have it complete the installation based on the documentation:
Please install `@user_87a42d61/knowledge-safe-merge` based on https://skillhub.cn/install/skillhub.md.
Manual Directory Installation (WorkBuddy Series)¶
The Skill package README.md also provides a folder copy method:
- Project Level:
ProjectDirectory/.workbuddy/skills/knowledge-safe-merge/ - User Level:
~/.workbuddy/skills/knowledge-safe-merge/
The complete directory should include SKILL.md, README.md, references/, scripts/, etc. It is not recommended to copy only SKILL.md.
Typical Usage¶
In the Skill directory, first perform a rehearsal (--dry-run only outputs statistics, does not write files) for the authoritative data source and incoming data:
py -3 scripts/merge_knowledge_json.py --current "authoritative-data.json" --incoming "new-data.json" --dry-run
After confirming the statistics meet expectations, proceed with the formal merge and overwrite the authoritative file; if --backup-dir is not specified, backups will be written to .knowledge-backups/ at the same level as the authoritative file:
py -3 scripts/merge_knowledge_json.py --current "public/knowledge-data.json" --incoming "incoming.json"
If the site maintains a mirror JSON simultaneously, you can write to the authoritative source and sync the mirror in a single command:
py -3 scripts/merge_knowledge_json.py --current "public/knowledge-data.json" --incoming "incoming.json" --mirror "knowledge-data.json"
If you need to preserve the original file and write the result to a new path:
py -3 scripts/merge_knowledge_json.py --current "current.json" --incoming "incoming.json" --output "merged.json"
In Agent conversations, when expressions like “merge knowledge base JSON”, “import new articles but keep history”, “migrate content library”, or “rehearse first then write to disk” appear, this Skill’s workflow should be triggered, rather than directly using cp or full-file overwrites.
Applicable Scenarios & Notes¶
Suitable for: Knowledge base sites, content aggregation sites, static JSON-driven sites, simple content backends; scenarios where articles arrays are periodically received from exports or external systems.
Limitations & Pitfalls:
- If the data structure differs significantly from
{ categories, articles }, adaptation is required first; forced merging is not recommended. - Each article should have at least identifiable
titleandcontent; ifidis unstable, matching degrades to “title + date”, so you must evaluate collision risks yourself. - The Skill explicitly prohibits: skipping dry-run to overwrite production data, writing to disk without backup, mistaking mirrors or test files for authoritative sources, and verifying only new articles without checking if old articles remain.
- The merge script examples use
py -3; on Linux, this can be changed topython3, and paths need to be replaced with real files in your project.
Conclusion¶
Knowledge Safe Merge transforms JSON content updates from “full-package overwrite” to “auditable incremental merging”: rules are written in the Skill, and execution can be handed over to the Agent and merge_knowledge_json.py. To install or view instructions, open the SkillHub page https://www.skillhub.cn/skills/user_87a42d61/knowledge-safe-merge , or use the CLI with the coordinate @user_87a42d61/knowledge-safe-merge to install it to the current Agent’s skills directory.