@zabuti/tools 0.1.4 → 0.1.6

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
@@ -11,6 +11,18 @@ npx @zabuti/tools add logic-optimizer
11
11
  npx @zabuti/tools add deadlock-map # beta
12
12
  ```
13
13
 
14
+ ## Updates
15
+
16
+ ```
17
+ npx @zabuti/tools status # what is installed, and whether updates exist
18
+ npx @zabuti/tools update # update every installed skill that has a newer version
19
+ npx @zabuti/tools rollback logic-map # switch back to the copy the last update replaced
20
+ ```
21
+
22
+ An update keeps the copy it replaces in `~/.zabuti/previous/<name>/`, outside the skills
23
+ folder so Claude Code doesn't load it as a second skill. Running `rollback` again swaps back.
24
+ Re-running `add` or `update` when nothing changed leaves the kept copy alone.
25
+
14
26
  The skill is written to `~/.claude/skills/<name>/`. The server checks your token and your
15
27
  organization's license on every download. Nothing from your project is sent. The free
16
28
  `zabuti` CLI (components and icons) is a separate package and makes no network calls.
@@ -4,14 +4,16 @@
4
4
  * Kept separate from the free `zabuti` CLI so that one never touches the network.
5
5
  */
6
6
  import { readFileSync } from "node:fs";
7
- import { cmdAddSkill, cmdLogin, cmdStatus, SKILL_NAMES } from "./skills.js";
7
+ import { cmdAddSkill, cmdLogin, cmdRollback, cmdStatus, cmdUpdate, SKILL_NAMES } from "./skills.js";
8
8
  const USAGE = `zabuti-tools: install the licensed Zabuti developer tools
9
9
 
10
10
  zabuti-tools login <token> save your download token (make one at zabuti.com/account)
11
11
  zabuti-tools add <skill> install a skill into ~/.claude/skills/
12
12
  skills: ${SKILL_NAMES.join(", ")}
13
+ zabuti-tools update [skill] update installed skills that have a newer version
14
+ zabuti-tools rollback <skill> switch back to the copy the last update replaced
13
15
 
14
- zabuti-tools status show what is installed
16
+ zabuti-tools status show what is installed and whether updates exist
15
17
  zabuti-tools --version
16
18
 
17
19
  Options: --dry-run (list the files without writing), --out=<folder> (install there instead)`;
@@ -35,6 +37,18 @@ try {
35
37
  }
36
38
  await cmdAddSkill(name, flags.has("--dry-run"), outDir);
37
39
  break;
40
+ case "update":
41
+ if ((name && !SKILL_NAMES.includes(name)) || positionals.length > 2) {
42
+ die(`update: name one skill (${SKILL_NAMES.join(" or ")}) or none to update all installed ones.`);
43
+ }
44
+ await cmdUpdate(name);
45
+ break;
46
+ case "rollback":
47
+ if (!name || !SKILL_NAMES.includes(name) || positionals.length > 2) {
48
+ die(`rollback: name one skill (${SKILL_NAMES.join(" or ")}), e.g. \`zabuti-tools rollback logic-map\`.`);
49
+ }
50
+ cmdRollback(name);
51
+ break;
38
52
  case "status":
39
53
  await cmdStatus();
40
54
  break;
@@ -5,9 +5,9 @@
5
5
  * the account's license on every download. Nothing else is sent: no project files.
6
6
  */
7
7
  import { createHash } from "node:crypto";
8
- import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
8
+ import { chmodSync, cpSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
9
9
  import { homedir } from "node:os";
10
- import { dirname, isAbsolute, join, resolve, sep } from "node:path";
10
+ import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
11
11
  export const SKILL_NAMES = ["logic-map", "logic-optimizer", "deadlock-map"];
12
12
  const BASE_URL = (process.env.ZABUTI_URL ?? "https://zabuti.com").replace(/\/+$/, "");
13
13
  const CONFIG_DIR = join(homedir(), ".zabuti");
@@ -86,7 +86,7 @@ export async function cmdAddSkill(name, dryRun, outDir) {
86
86
  const body = (await res.json().catch(() => null));
87
87
  if (!res.ok || !body?.files)
88
88
  throw new Error(body?.error ?? `the server answered ${res.status}.`);
89
- const root = outDir ? resolve(outDir) : join(homedir(), ".claude", "skills", name);
89
+ const root = outDir ? resolve(outDir) : skillRoot(name);
90
90
  const files = body.files.map((f) => ({ full: safeJoin(root, f.path), rel: f.path, content: f.content, sha256: f.sha256 }));
91
91
  for (const f of files) {
92
92
  if (f.sha256 && createHash("sha256").update(f.content, "utf8").digest("hex") !== f.sha256) {
@@ -99,54 +99,161 @@ export async function cmdAddSkill(name, dryRun, outDir) {
99
99
  console.log(` ${f.rel}`);
100
100
  return;
101
101
  }
102
- // Keep one previous copy so a bad update can be rolled back.
103
- const previous = `${root}.previous`;
102
+ const previous = previousDir(root, name);
103
+ migrateLegacyBackup(root, previous);
104
+ // Same files already on disk: leave everything alone, so the one kept backup
105
+ // stays a real older version instead of being replaced by an identical copy.
106
+ if (files.every((f) => existsSync(f.full) && sha256(readFileSync(f.full, "utf8")) === sha256(f.content))) {
107
+ // Installs from before manifests existed: record this one so status stops
108
+ // asking for a reinstall that would land here again.
109
+ if (!existsSync(join(root, MANIFEST)))
110
+ writeManifest(root, name, files);
111
+ console.log(`✓ ${name} is already up to date at ${root}`);
112
+ return;
113
+ }
114
+ // Keep one previous copy so a bad update can be rolled back. It lives OUTSIDE
115
+ // the skills folder: Claude Code loads every folder there as a skill.
104
116
  if (existsSync(root)) {
105
117
  rmSync(previous, { recursive: true, force: true });
106
- renameSync(root, previous);
118
+ mkdirSync(dirname(previous), { recursive: true });
119
+ moveDir(root, previous);
107
120
  }
108
121
  for (const f of files) {
109
122
  mkdirSync(dirname(f.full), { recursive: true });
110
123
  writeFileSync(f.full, f.content);
111
124
  }
112
- const manifest = { name, installedAt: new Date().toISOString(), source: BASE_URL, files: files.map((f) => ({ path: f.rel, sha256: createHash("sha256").update(f.content, "utf8").digest("hex") })) };
113
- writeFileSync(join(root, ".zabuti-install.json"), JSON.stringify(manifest, null, 2));
125
+ writeManifest(root, name, files);
114
126
  console.log(`✓ Installed ${name} (${files.length} files) → ${root}`);
115
127
  if (existsSync(previous))
116
- console.log(` Previous copy kept at ${previous}`);
128
+ console.log(` Previous copy kept at ${previous} (undo with \`zabuti-tools rollback ${name}\`)`);
117
129
  console.log(" Open Claude Code in your project and ask it to use the skill.");
118
130
  }
131
+ const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
132
+ const MANIFEST = ".zabuti-install.json";
133
+ function writeManifest(root, name, files) {
134
+ const manifest = { name, installedAt: new Date().toISOString(), source: BASE_URL, files: files.map((f) => ({ path: f.rel, sha256: sha256(f.content) })) };
135
+ writeFileSync(join(root, MANIFEST), JSON.stringify(manifest, null, 2));
136
+ }
137
+ const skillRoot = (name) => join(homedir(), ".claude", "skills", name);
138
+ /** Where the replaced copy goes: never inside a skills folder. */
139
+ function previousDir(root, name) {
140
+ const base = join(CONFIG_DIR, "previous");
141
+ return resolve(root) === resolve(skillRoot(name)) ? join(base, name) : join(base, `${basename(root)}-${sha256(resolve(root)).slice(0, 8)}`);
142
+ }
143
+ /** rename, falling back to copy + delete across drives (--out on another volume). */
144
+ function moveDir(from, to) {
145
+ try {
146
+ renameSync(from, to);
147
+ }
148
+ catch (e) {
149
+ if (e.code !== "EXDEV")
150
+ throw e;
151
+ cpSync(from, to, { recursive: true });
152
+ rmSync(from, { recursive: true, force: true });
153
+ }
154
+ }
155
+ /** 0.1.3/0.1.4 kept `<skill>.previous` beside the skill, where Claude Code loaded it as a second skill. */
156
+ function migrateLegacyBackup(root, previous) {
157
+ const legacy = `${root}.previous`;
158
+ if (!existsSync(legacy))
159
+ return;
160
+ if (existsSync(previous)) {
161
+ rmSync(legacy, { recursive: true, force: true });
162
+ }
163
+ else {
164
+ mkdirSync(dirname(previous), { recursive: true });
165
+ moveDir(legacy, previous);
166
+ }
167
+ console.log(` Moved the old backup out of the skills folder: ${legacy} → ${previous}`);
168
+ }
169
+ function readManifest(root) {
170
+ try {
171
+ return JSON.parse(readFileSync(join(root, ".zabuti-install.json"), "utf8"));
172
+ }
173
+ catch {
174
+ return null;
175
+ }
176
+ }
177
+ /** true = zabuti.com has different files, false = same, string = why it couldn't tell. */
178
+ async function updateAvailable(name, m, token) {
179
+ try {
180
+ const res = await fetch(`${BASE_URL}/api/cli/skills/${encodeURIComponent(name)}?check=1`, { headers: { authorization: `Bearer ${token}` } });
181
+ const body = (await res.json().catch(() => null));
182
+ if (!res.ok || !body?.files)
183
+ return `the server answered ${res.status}`;
184
+ const have = new Map((m.files ?? []).map((f) => [f.path, f.sha256]));
185
+ return !(body.files.length === have.size && body.files.every((f) => have.get(f.path) === f.sha256));
186
+ }
187
+ catch {
188
+ return "couldn't reach the server";
189
+ }
190
+ }
191
+ /** Update the named skill, or every installed one, only where zabuti.com has a newer copy. */
192
+ export async function cmdUpdate(name) {
193
+ const token = storedToken();
194
+ if (!token)
195
+ throw new Error("not signed in. Make a token at zabuti.com/account, then run `zabuti-tools login <token>`.");
196
+ const names = name ? [name] : SKILL_NAMES.filter((n) => existsSync(skillRoot(n)));
197
+ if (!names.length) {
198
+ console.log("No Zabuti skills are installed. Install one with `zabuti-tools add <skill>`.");
199
+ return;
200
+ }
201
+ for (const n of names) {
202
+ const root = skillRoot(n);
203
+ migrateLegacyBackup(root, previousDir(root, n));
204
+ const m = readManifest(root);
205
+ const avail = m ? await updateAvailable(n, m, token) : true;
206
+ if (avail === false)
207
+ console.log(`${n}: up to date.`);
208
+ else if (typeof avail === "string")
209
+ console.log(`${n}: skipped (${avail}).`);
210
+ else
211
+ await cmdAddSkill(n, false);
212
+ }
213
+ }
214
+ /** Swap the installed copy with the kept previous one. Running it again swaps back. */
215
+ export function cmdRollback(name) {
216
+ const root = skillRoot(name);
217
+ const previous = previousDir(root, name);
218
+ migrateLegacyBackup(root, previous);
219
+ if (!existsSync(previous))
220
+ throw new Error(`rollback: no previous copy of ${name} is kept (one is saved when an update replaces it).`);
221
+ if (existsSync(root)) {
222
+ const swap = `${previous}.swap`;
223
+ rmSync(swap, { recursive: true, force: true });
224
+ moveDir(root, swap);
225
+ moveDir(previous, root);
226
+ moveDir(swap, previous);
227
+ }
228
+ else {
229
+ moveDir(previous, root);
230
+ }
231
+ console.log(`✓ Rolled ${name} back to the copy installed ${readManifest(root)?.installedAt ?? "earlier"} → ${root}`);
232
+ if (existsSync(previous))
233
+ console.log(` The copy it replaced is kept at ${previous}; run rollback again to return to it.`);
234
+ }
119
235
  /** What is installed, from the manifest written at install time. */
120
236
  export async function cmdStatus() {
121
237
  const token = storedToken();
122
238
  for (const name of SKILL_NAMES) {
123
- const root = join(homedir(), ".claude", "skills", name);
124
- let m;
125
- try {
126
- m = JSON.parse(readFileSync(join(root, ".zabuti-install.json"), "utf8"));
127
- }
128
- catch {
239
+ const root = skillRoot(name);
240
+ migrateLegacyBackup(root, previousDir(root, name));
241
+ const m = readManifest(root);
242
+ if (!m) {
129
243
  console.log(`${name}: ${existsSync(root) ? "installed (no manifest; reinstall to add one)" : "not installed"}`);
130
244
  continue;
131
245
  }
132
246
  console.log(`${name}: installed ${m.installedAt ?? "?"} from ${m.source ?? "?"} (${m.files?.length ?? "?"} files) at ${root}`);
247
+ if (existsSync(previousDir(root, name)))
248
+ console.log(` Previous copy kept (\`zabuti-tools rollback ${name}\` to switch back).`);
133
249
  if (!token) {
134
250
  console.log(" Update check skipped (not signed in).");
135
251
  continue;
136
252
  }
137
- try {
138
- const res = await fetch(`${BASE_URL}/api/cli/skills/${encodeURIComponent(name)}?check=1`, { headers: { authorization: `Bearer ${token}` } });
139
- const body = (await res.json().catch(() => null));
140
- if (!res.ok || !body?.files) {
141
- console.log(` Update check skipped (the server answered ${res.status}).`);
142
- continue;
143
- }
144
- const have = new Map((m.files ?? []).map((f) => [f.path, f.sha256]));
145
- const same = body.files.length === have.size && body.files.every((f) => have.get(f.path) === f.sha256);
146
- console.log(same ? " Up to date." : ` Update available: run \`zabuti-tools add ${name}\` (your current copy is kept as ${name}.previous).`);
147
- }
148
- catch {
149
- console.log(" Update check skipped (couldn't reach the server).");
150
- }
253
+ const avail = await updateAvailable(name, m, token);
254
+ if (typeof avail === "string")
255
+ console.log(` Update check skipped (${avail}).`);
256
+ else
257
+ console.log(avail ? ` Update available: run \`zabuti-tools update\`.` : " Up to date.");
151
258
  }
152
259
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zabuti/tools",
3
- "version": "0.1.4",
4
- "description": "Installs the licensed Zabuti developer tools (Logic Map, Logic Optimizer) as Claude Code skills. Needs a license and a download token from zabuti.com.",
3
+ "version": "0.1.6",
4
+ "description": "Installs the licensed Zabuti developer tools (Logic Map, Logic Optimizer, Deadlock Map) as Claude Code skills. Needs a license and a download token from zabuti.com.",
5
5
  "homepage": "https://zabuti.com",
6
6
  "license": "MIT",
7
7
  "type": "module",