@jcorpac/skill-vault 1.2.0 → 1.4.0

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
@@ -85,10 +85,12 @@ python scripts/skill_vault.py verify
85
85
  | `skill-vault status` | Fast summary of skill counts and category breakdown. |
86
86
  | `skill-vault list --active` | List only active skills currently loaded in context memory. |
87
87
  | `skill-vault list --archived` | List only cold-storage skills grouped by category. |
88
- | `skill-vault archive <name> --category "<Cat>"` | Move active skill to archive with category metadata. |
88
+ | `skill-vault archive <name> --category "<Cat>"` | Move active skill to archive with category metadata (preserves newer L2 copies). |
89
+ | `skill-vault archive <name> --force` | Force archive overwrite regardless of archive recency. |
89
90
  | `skill-vault archive --pattern "gcp-*"` | Archive multiple matching skills via glob pattern. |
90
91
  | `skill-vault recategorize <name> "<New Cat>"` | Reorganize skill category without modifying `SKILL.md`. |
91
- | `skill-vault restore <name>` | Restore an archived skill back to active availability. |
92
+ | `skill-vault restore <name>` | Restore an archived skill back to active availability (auto-upgrades if L2 is newer). |
93
+ | `skill-vault restore <name> --force` | Force restore overwrite regardless of active recency. |
92
94
  | `skill-vault restore --category "<Cat>"` | Restore all skills in a specific category. |
93
95
  | `skill-vault search "<query>"` | Search skills across names, descriptions, and categories. |
94
96
  | `skill-vault reindex` | Regenerate `INDEX.md` and sync `backup_manifest.json`. |
@@ -103,6 +105,7 @@ python scripts/skill_vault.py verify
103
105
  2. **Environment Agnostic**: Dynamically resolves workspace roots via CLI flags (`--base-dir`), environment variables (`$SKILL_VAULT_BASE`), script parents, or working directories.
104
106
  3. **Zero Runtime Dependencies**: The core engine requires only Python 3 standard library (`os`, `sys`, `json`, `re`, `shutil`, `hashlib`, `argparse`, `pathlib`).
105
107
  4. **Self-Healing Integrity**: Detects orphaned folders, phantom manifest entries, broken markdown links, and duplicate aliases.
108
+ 5. **Recency & Version Prioritization**: Automatically protects newer versions when archiving, restoring, or optimizing by evaluating semantic version tags (`version:`) with filesystem timestamp (`mtime`) fallbacks. Use `--force` to override.
106
109
 
107
110
  ---
108
111
 
package/SKILL.md CHANGED
@@ -1,6 +1,17 @@
1
1
  ---
2
2
  name: skill-vault
3
- description: Universal agent-agnostic and OS-agnostic skill router, tiered storage manager, and lifecycle auditor. Solves context bloat and skill bleed by managing active skills vs archived cold storage across environments (Google Antigravity, Claude Code, Cursor, CI/CD).
3
+ description: >-
4
+ Universal agent-agnostic skill router and tiered storage manager for 210+ specialized domain skills in cold storage.
5
+ ALWAYS use this skill whenever the task involves domains or tools not in active memory, including:
6
+ (1) AlloyDB (Omni, replication, vector, tuning),
7
+ (2) Cloud SQL (Postgres, MySQL, backup/DR, performance),
8
+ (3) BigQuery & Data Warehouse (dbt, Dataform, optimization),
9
+ (4) GCP & Data Engineering (Airflow/Composer, Spanner, Dataproc, GCS),
10
+ (5) Gemini API & AI Agents (ADK, Live API, Omni Flash, evals),
11
+ (6) Science & Biomedicine (AlphaFold, AlphaGenome, Foldseek, ChEMBL, PDB, PyMOL, PubMed, variant analysis),
12
+ (7) Android Development, or
13
+ (8) General Utilities.
14
+ Search or restore skills on demand via 'python scripts/skill_vault.py search "<keyword>"', view 'skill_archive/INDEX.md', or run 'restore <name>'.
4
15
  ---
5
16
 
6
17
  # Skill Vault: Universal Agent Skill Lifecycle & Storage Manager
@@ -129,6 +140,16 @@ python scripts/skill_vault.py optimize --dry-run
129
140
  python scripts/skill_vault.py optimize --workspace "C:\Projects\my-repo" --protect my-custom-skill
130
141
  ```
131
142
 
143
+ ### I. Recency & Version Prioritization Protocol
144
+ Skill Vault automatically protects newer skills and prevents regressions when archiving, restoring, or optimizing:
145
+ 1. **Semantic Version Check**: Compares `version:` headers in `SKILL.md` frontmatter (e.g., `v2` > `v1`, `1.2.0` > `1.1.0`).
146
+ 2. **Timestamp Recency Fallback**: If versions match or are unversioned, compares the newest file modification timestamp (`mtime`).
147
+ 3. **Tier Behavior**:
148
+ - **`archive`**: When L1 is newer or equal to L2, updates L2 with the active version. If L2 is strictly newer, preserves L2 to avoid overwriting with stale files.
149
+ - **`restore`**: When L2 is strictly newer than L1, upgrades active L1 with the newer vault copy. If L1 is newer or equal, preserves L1.
150
+ - **`optimize`**: Automatically detects and upgrades active L1 skills if newer versions exist in the vault, while archiving unneeded skills safely.
151
+ - **`--force`**: Bypasses recency checks on `archive`, `restore`, or `optimize` when an intentional overwrite is required.
152
+
132
153
  ---
133
154
 
134
155
  ## 3. Environment & OS Compatibility Guidelines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcorpac/skill-vault",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Universal Agent Skill Router, Lifecycle Manager, and Tiered Storage Engine for AI Coding Agents.",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {
@@ -68,6 +68,69 @@ WORKSPACE_FINGERPRINTS = {
68
68
  }
69
69
 
70
70
 
71
+ def parse_version_tuple(ver_str):
72
+ """Parse version string into a comparable numeric tuple, e.g. 'v20' -> (20,), '1.1.5' -> (1, 1, 5)."""
73
+ if not ver_str:
74
+ return None
75
+ cleaned = str(ver_str).strip().strip("'\"").lstrip("vV")
76
+ nums = re.findall(r"\d+", cleaned)
77
+ if nums:
78
+ return tuple(int(n) for n in nums)
79
+ return None
80
+
81
+
82
+ def get_skill_metadata(skill_dir):
83
+ """Extract parsed version and latest modification timestamp for a skill directory."""
84
+ skill_dir = Path(skill_dir)
85
+ skill_md = skill_dir / "SKILL.md"
86
+
87
+ ver_tuple = None
88
+ if skill_md.exists():
89
+ try:
90
+ content = skill_md.read_text(encoding="utf-8", errors="ignore")
91
+ fm_match = re.search(r"^---\s*\n(.*?)\n---", content, re.DOTALL)
92
+ if fm_match:
93
+ v_match = re.search(r"version:\s*([^\n]+)", fm_match.group(1), re.IGNORECASE)
94
+ if v_match:
95
+ ver_tuple = parse_version_tuple(v_match.group(1))
96
+ except Exception:
97
+ pass
98
+
99
+ latest_mtime = 0.0
100
+ try:
101
+ files = [f for f in skill_dir.rglob("*") if f.is_file()]
102
+ if files:
103
+ latest_mtime = max(f.stat().st_mtime for f in files)
104
+ elif skill_dir.exists():
105
+ latest_mtime = skill_dir.stat().st_mtime
106
+ except Exception:
107
+ pass
108
+
109
+ return ver_tuple, latest_mtime
110
+
111
+
112
+ def compare_skill_recency(dir_a, dir_b):
113
+ """Compare two skill directories to determine which is newer.
114
+
115
+ Returns:
116
+ 1 if dir_a is newer than dir_b
117
+ -1 if dir_b is newer than dir_a
118
+ 0 if they are equivalent in version and recency
119
+ """
120
+ ver_a, mtime_a = get_skill_metadata(dir_a)
121
+ ver_b, mtime_b = get_skill_metadata(dir_b)
122
+
123
+ # 1. Compare semantic/numeric versions if both exist and differ
124
+ if ver_a is not None and ver_b is not None and ver_a != ver_b:
125
+ return 1 if ver_a > ver_b else -1
126
+
127
+ # 2. Compare file modification timestamps (allowing a 1-second margin for filesystem granularity)
128
+ if abs(mtime_a - mtime_b) > 1.0:
129
+ return 1 if mtime_a > mtime_b else -1
130
+
131
+ return 0
132
+
133
+
71
134
  def resolve_base_dir(cli_base=None):
72
135
  """Dynamically resolve the base directory for skills and archives."""
73
136
  if cli_base:
@@ -134,9 +197,17 @@ class SkillVault:
134
197
 
135
198
  for sub in [".agents/skills", ".claude/skills"]:
136
199
  p = self.base_dir / sub
137
- if p.exists():
200
+ if p.exists() and p not in dirs:
138
201
  dirs.append(p)
139
202
 
203
+ # Also search active working directory and its skill locations if distinct from base_dir
204
+ cwd = Path.cwd().resolve()
205
+ if cwd != self.base_dir:
206
+ for sub in ["skills", ".agents/skills", ".claude/skills"]:
207
+ p = cwd / sub
208
+ if p.exists() and p not in dirs:
209
+ dirs.append(p)
210
+
140
211
  plugins_dir = self.base_dir / "plugins"
141
212
  if plugins_dir.exists():
142
213
  for p in plugins_dir.iterdir():
@@ -303,10 +374,11 @@ class SkillVault:
303
374
 
304
375
  return matched
305
376
 
306
- def optimize(self, workspace_path=None, protected_skills=None, dry_run=False):
377
+ def optimize(self, workspace_path=None, protected_skills=None, dry_run=False, force=False):
307
378
  """Automatically minimize active skills to essential Core + workspace-relevant skills.
308
379
 
309
- Archives unneeded active skills into cold storage and mounts matching domain skills.
380
+ Archives unneeded active skills into cold storage and mounts matching domain skills,
381
+ prioritizing newer versions when versions overlap.
310
382
  """
311
383
  target_ws = Path(workspace_path).resolve() if workspace_path else Path.cwd().resolve()
312
384
  core_set = set(DEFAULT_CORE_SKILLS)
@@ -346,6 +418,17 @@ class SkillVault:
346
418
  else:
347
419
  to_archive.append((name, skill_cat))
348
420
 
421
+ # Check if any kept active skill has a newer version in the archive
422
+ to_upgrade = []
423
+ for name, reason in to_keep:
424
+ if name in manifest_by_name:
425
+ item = manifest_by_name[name]
426
+ archived_path = self.resolve_portable_path(item.get("archived_path", ""))
427
+ active_path = self.find_active_skill(name)
428
+ if archived_path.exists() and active_path and active_path.exists():
429
+ if compare_skill_recency(archived_path, active_path) > 0:
430
+ to_upgrade.append((name, reason))
431
+
349
432
  # 3. Determine skills in vault that should be mounted
350
433
  to_mount = []
351
434
  for cat in detected_categories.keys():
@@ -359,6 +442,11 @@ class SkillVault:
359
442
  for name, reason in to_keep:
360
443
  print(f" [KEEP] {name} - {reason}")
361
444
 
445
+ if to_upgrade:
446
+ print(f"\n * Upgrading Active Skills with Newer Vault Versions ({len(to_upgrade)} skills):")
447
+ for name, reason in to_upgrade:
448
+ print(f" [UPGRADE] {name} (Newer version found in Vault)")
449
+
362
450
  if to_archive:
363
451
  print(f"\n * Evicting to Cold Storage Archive ({len(to_archive)} skills):")
364
452
  for name, cat in to_archive:
@@ -375,17 +463,23 @@ class SkillVault:
375
463
  print("\n[Dry Run] Optimization preview complete. No files were moved.")
376
464
  return
377
465
 
466
+ # Execute Upgrades
467
+ if to_upgrade:
468
+ print("\nExecuting Auto-Upgrades from Newer Vault Copies...")
469
+ for name, _ in to_upgrade:
470
+ self.restore(name=name, force=True)
471
+
378
472
  # Execute Evictions (Archive)
379
473
  if to_archive:
380
474
  print("\nExecuting Auto-Archival...")
381
475
  for name, cat in to_archive:
382
- self.archive(name=name, category=cat, keep_active=False)
476
+ self.archive(name=name, category=cat, keep_active=False, force=force)
383
477
 
384
478
  # Execute Mounts (Restore)
385
479
  if to_mount:
386
480
  print("\nExecuting Auto-Mounts...")
387
481
  for name, cat in to_mount:
388
- self.restore(name=name)
482
+ self.restore(name=name, force=force)
389
483
 
390
484
  print("\n[OK] Optimization complete! Active context surface is at absolute minimum.")
391
485
 
@@ -476,8 +570,8 @@ class SkillVault:
476
570
  print(f" * {s['name']}: {desc_snippet}")
477
571
  print("")
478
572
 
479
- def archive(self, name=None, pattern=None, category=None, keep_active=False):
480
- """Archive active skills with an assigned category."""
573
+ def archive(self, name=None, pattern=None, category=None, keep_active=False, force=False):
574
+ """Archive active skills with an assigned category, prioritizing newer versions."""
481
575
  manifest = self.load_manifest()
482
576
  manifest_map = {item["name"]: item for item in manifest}
483
577
 
@@ -507,9 +601,23 @@ class SkillVault:
507
601
  dest_dir.parent.mkdir(parents=True, exist_ok=True)
508
602
 
509
603
  if dest_dir.exists():
510
- shutil.rmtree(dest_dir)
604
+ recency = compare_skill_recency(active_path, dest_dir)
605
+ if recency < 0 and not force:
606
+ print(f"[Skip] L2 archive '{skill_name}' is newer than active L1 version. Preserving newer archive (use --force to overwrite).")
607
+ if not keep_active:
608
+ shutil.rmtree(active_path)
609
+ print(f"[Cleaned] Removed older active directory: {active_path}")
610
+ continue
611
+ elif recency > 0:
612
+ print(f"[Archived] Overwriting older L2 archive with newer active L1 version: {active_path} -> {dest_dir}")
613
+ shutil.rmtree(dest_dir)
614
+ else:
615
+ shutil.rmtree(dest_dir)
616
+ print(f"[Archived] {active_path} -> {dest_dir}")
617
+ else:
618
+ print(f"[Archived] {active_path} -> {dest_dir}")
619
+
511
620
  shutil.copytree(active_path, dest_dir)
512
- print(f"[Archived] {active_path} -> {dest_dir}")
513
621
 
514
622
  existing_cat = manifest_map.get(skill_name, {}).get("category")
515
623
  assigned_cat = category_name or existing_cat or "General & Utility Skills"
@@ -576,10 +684,14 @@ class SkillVault:
576
684
 
577
685
  original_path.parent.mkdir(parents=True, exist_ok=True)
578
686
  if original_path.exists():
579
- if force:
687
+ recency = compare_skill_recency(archived_path, original_path)
688
+ if recency > 0 or force:
580
689
  shutil.rmtree(original_path)
690
+ shutil.copytree(archived_path, original_path)
691
+ print(f"[Restored] Updated L1 with newer L2 version: {item['name']} -> {original_path}")
692
+ continue
581
693
  else:
582
- print(f"[Skip] Target exists: {original_path} (use --force to overwrite)")
694
+ print(f"[Skip] Target L1 skill '{item['name']}' is already newer than or equal to L2 archive (use --force to overwrite)")
583
695
  continue
584
696
 
585
697
  shutil.copytree(archived_path, original_path)
@@ -795,6 +907,7 @@ def main():
795
907
  p_opt.add_argument("--workspace", help="Path to workspace directory to inspect")
796
908
  p_opt.add_argument("--protect", nargs="*", help="Additional skill names to protect from auto-archiving")
797
909
  p_opt.add_argument("--dry-run", action="store_true", help="Preview optimization changes without moving files")
910
+ p_opt.add_argument("--force", action="store_true", help="Force overwrite during optimization regardless of recency")
798
911
 
799
912
  # List / Overview
800
913
  p_list = subparsers.add_parser("list", help="Present active and archived skills")
@@ -814,6 +927,7 @@ def main():
814
927
  p_arch.add_argument("--pattern", help="Glob pattern (e.g. 'gcp-*')")
815
928
  p_arch.add_argument("--category", help="Category name (e.g. 'Cloud Architecture')")
816
929
  p_arch.add_argument("--keep-active", action="store_true", help="Do not delete source folder")
930
+ p_arch.add_argument("--force", action="store_true", help="Force overwrite in archive regardless of recency")
817
931
 
818
932
  # Recategorize
819
933
  p_rec = subparsers.add_parser("recategorize", help="Recategorize an archived skill in metadata")
@@ -845,7 +959,7 @@ def main():
845
959
  if args.command == "init":
846
960
  mgr.init()
847
961
  elif args.command == "optimize":
848
- mgr.optimize(workspace_path=args.workspace, protected_skills=args.protect, dry_run=args.dry_run)
962
+ mgr.optimize(workspace_path=args.workspace, protected_skills=args.protect, dry_run=args.dry_run, force=args.force)
849
963
  elif args.command == "list":
850
964
  show_active = not args.archived or args.active
851
965
  show_archived = not args.active or args.archived
@@ -864,7 +978,7 @@ def main():
864
978
  summary_only=True,
865
979
  )
866
980
  elif args.command == "archive":
867
- mgr.archive(name=args.name, pattern=args.pattern, category=args.category, keep_active=args.keep_active)
981
+ mgr.archive(name=args.name, pattern=args.pattern, category=args.category, keep_active=args.keep_active, force=args.force)
868
982
  elif args.command == "recategorize":
869
983
  mgr.recategorize(name=args.name, new_category=args.category)
870
984
  elif args.command == "restore":