@trawlme/cli 4.0.6 → 4.0.7

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
@@ -149,7 +149,7 @@ trawl skills update [<skill>] [--local] [--force] [--json] Reinstall (force
149
149
 
150
150
  `--json` prints a structured result (`{"version","skills":[...]}` for `list`; `{"installed"/"uninstalled"/"updated":[{"name","scope","dest"}]}` for the others) instead of the `✓`-prefixed lines — the orphan-sweep/re-sync stderr lines are unaffected either way (stdout stays pure).
151
151
 
152
- Skills auto-update when you upgrade the CLI — no need to re-install manually — but it is not silent: it prints an honest `trawl: re-synced skill "<name>" (<scope>) <old> → <new>` line to stderr whenever it rewrites a skill dir, so a rewrite is never invisible. If a bundled skill is renamed or dropped between CLI versions, the old install is swept too — a `trawl: removed orphaned skill "<name>" (<scope>) — no longer bundled with this CLI version` line to stderr, so a stale skill teaching outdated CLI usage never lingers silently. Only marker-owned dirs (installed by trawl itself) are ever touched by either line. Opt out with `TRAWL_SKILLS_SYNC=0`.
152
+ Skills auto-update when you upgrade the CLI — no need to re-install manually; an auto-update only moves to a newer version, never downgrades — but it is not silent: it prints an honest `trawl: re-synced skill "<name>" (<scope>) <old> → <new>` line to stderr whenever it rewrites a skill dir, so a rewrite is never invisible. If a bundled skill is renamed or dropped between CLI versions, the old install is swept too — a `trawl: removed orphaned skill "<name>" (<scope>) — no longer bundled with this CLI version` line to stderr, so a stale skill teaching outdated CLI usage never lingers silently. Only marker-owned dirs (installed by trawl itself) are ever touched by either line. Opt out with `TRAWL_SKILLS_SYNC=0`.
153
153
 
154
154
  A pre-existing skill directory that trawl did not install itself (no `.version` marker) is never touched — `install`/`update` refuse to overwrite it and require `--force` to proceed. This applies to the CLI-upgrade auto-sync too (it silently skips marker-less dirs rather than refusing, since there is no interactive user to show a refusal to).
155
155
 
@@ -1,4 +1,4 @@
1
- import { mkdirSync, existsSync, rmSync, readFileSync, writeFileSync, readdirSync, statSync, cpSync } from 'node:fs';
1
+ import { mkdirSync, existsSync, rmSync, readFileSync, writeFileSync, readdirSync, statSync, cpSync, renameSync } from 'node:fs';
2
2
  import { join, dirname } from 'node:path';
3
3
  import { homedir } from 'node:os';
4
4
  import { createRequire } from 'node:module';
@@ -51,13 +51,47 @@ export function installSkill(name, scope, opts = {}) {
51
51
  if (!owned && !opts.force) {
52
52
  throw new SkillOwnershipRefusalError(dest);
53
53
  }
54
- rmSync(dest, { recursive: true, force: true });
55
54
  }
56
- mkdirSync(dest, { recursive: true });
57
- cpSync(src, dest, { recursive: true });
58
- writeFileSync(join(dest, '.version'), getBundledSkillsVersion(), 'utf8');
55
+ const staging = join(getSkillsBase(scope), '.trawl-staging');
56
+ const tmp = join(staging, `${name}-${process.pid}`);
57
+ const old = join(staging, `${name}-${process.pid}.old`);
58
+ rmSync(tmp, { recursive: true, force: true });
59
+ rmSync(old, { recursive: true, force: true });
60
+ mkdirSync(staging, { recursive: true });
61
+ cpSync(src, tmp, { recursive: true });
62
+ writeFileSync(join(tmp, '.version'), getBundledSkillsVersion(), 'utf8');
63
+ let movedOld = false;
64
+ try {
65
+ if (existsSync(dest)) {
66
+ renameSync(dest, old);
67
+ movedOld = true;
68
+ }
69
+ renameSync(tmp, dest);
70
+ }
71
+ catch (err) {
72
+ if (movedOld && !existsSync(dest))
73
+ renameSync(old, dest);
74
+ rmSync(tmp, { recursive: true, force: true });
75
+ rmSync(old, { recursive: true, force: true });
76
+ throw err;
77
+ }
78
+ rmSync(old, { recursive: true, force: true });
59
79
  return dest;
60
80
  }
81
+ function isNewerVersion(a, b) {
82
+ const parse = (v) => /^v?(\d+)\.(\d+)\.(\d+)/.exec(v)?.slice(1).map(Number) ?? null;
83
+ const pa = parse(a);
84
+ const pb = parse(b);
85
+ if (!pa)
86
+ return false;
87
+ if (!pb)
88
+ return true;
89
+ for (let i = 0; i < 3; i++) {
90
+ if (pa[i] !== pb[i])
91
+ return pa[i] > pb[i];
92
+ }
93
+ return false;
94
+ }
61
95
  export function uninstallSkill(name, scope) {
62
96
  const dest = join(getSkillsBase(scope), name);
63
97
  if (!existsSync(dest))
@@ -124,9 +158,14 @@ export function autoUpdateInstalledSkills() {
124
158
  }
125
159
  if (installed === null)
126
160
  continue;
127
- if (installed === bundledVersion)
161
+ if (!isNewerVersion(bundledVersion, installed))
128
162
  continue;
129
- installSkill(name, scope);
163
+ try {
164
+ installSkill(name, scope);
165
+ }
166
+ catch {
167
+ continue;
168
+ }
130
169
  process.stderr.write(`trawl: re-synced skill "${name}" (${scope}) ${installed} → ${bundledVersion}\n`);
131
170
  }
132
171
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {