@zabuti/tools 0.1.3 → 0.1.5
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 +16 -2
- package/dist/installer/src/index.js +16 -2
- package/dist/installer/src/skills.js +128 -29
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
# @zabuti/tools
|
|
2
2
|
|
|
3
|
-
Installs the licensed Zabuti developer tools (Logic Map, Logic Optimizer) as
|
|
4
|
-
skills. Needs a Zabuti license and a download token from zabuti.com/account (CLI
|
|
3
|
+
Installs the licensed Zabuti developer tools (Logic Map, Logic Optimizer, Deadlock Map) as
|
|
4
|
+
Claude Code skills. Needs a Zabuti license and a download token from zabuti.com/account (CLI
|
|
5
|
+
access).
|
|
5
6
|
|
|
6
7
|
```
|
|
7
8
|
npx @zabuti/tools login zct_…
|
|
8
9
|
npx @zabuti/tools add logic-map
|
|
9
10
|
npx @zabuti/tools add logic-optimizer
|
|
11
|
+
npx @zabuti/tools add deadlock-map # beta
|
|
10
12
|
```
|
|
11
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
|
+
|
|
12
26
|
The skill is written to `~/.claude/skills/<name>/`. The server checks your token and your
|
|
13
27
|
organization's license on every download. Nothing from your project is sent. The free
|
|
14
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,10 +5,10 @@
|
|
|
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";
|
|
11
|
-
export const SKILL_NAMES = ["logic-map", "logic-optimizer"];
|
|
10
|
+
import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
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");
|
|
14
14
|
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
@@ -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) :
|
|
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,153 @@ export async function cmdAddSkill(name, dryRun, outDir) {
|
|
|
99
99
|
console.log(` ${f.rel}`);
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
console.log(`✓ ${name} is already up to date at ${root}`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Keep one previous copy so a bad update can be rolled back. It lives OUTSIDE
|
|
111
|
+
// the skills folder: Claude Code loads every folder there as a skill.
|
|
104
112
|
if (existsSync(root)) {
|
|
105
113
|
rmSync(previous, { recursive: true, force: true });
|
|
106
|
-
|
|
114
|
+
mkdirSync(dirname(previous), { recursive: true });
|
|
115
|
+
moveDir(root, previous);
|
|
107
116
|
}
|
|
108
117
|
for (const f of files) {
|
|
109
118
|
mkdirSync(dirname(f.full), { recursive: true });
|
|
110
119
|
writeFileSync(f.full, f.content);
|
|
111
120
|
}
|
|
112
|
-
const manifest = { name, installedAt: new Date().toISOString(), source: BASE_URL, files: files.map((f) => ({ path: f.rel, sha256:
|
|
121
|
+
const manifest = { name, installedAt: new Date().toISOString(), source: BASE_URL, files: files.map((f) => ({ path: f.rel, sha256: sha256(f.content) })) };
|
|
113
122
|
writeFileSync(join(root, ".zabuti-install.json"), JSON.stringify(manifest, null, 2));
|
|
114
123
|
console.log(`✓ Installed ${name} (${files.length} files) → ${root}`);
|
|
115
124
|
if (existsSync(previous))
|
|
116
|
-
console.log(` Previous copy kept at ${previous}`);
|
|
125
|
+
console.log(` Previous copy kept at ${previous} (undo with \`zabuti-tools rollback ${name}\`)`);
|
|
117
126
|
console.log(" Open Claude Code in your project and ask it to use the skill.");
|
|
118
127
|
}
|
|
128
|
+
const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
|
|
129
|
+
const skillRoot = (name) => join(homedir(), ".claude", "skills", name);
|
|
130
|
+
/** Where the replaced copy goes: never inside a skills folder. */
|
|
131
|
+
function previousDir(root, name) {
|
|
132
|
+
const base = join(CONFIG_DIR, "previous");
|
|
133
|
+
return resolve(root) === resolve(skillRoot(name)) ? join(base, name) : join(base, `${basename(root)}-${sha256(resolve(root)).slice(0, 8)}`);
|
|
134
|
+
}
|
|
135
|
+
/** rename, falling back to copy + delete across drives (--out on another volume). */
|
|
136
|
+
function moveDir(from, to) {
|
|
137
|
+
try {
|
|
138
|
+
renameSync(from, to);
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
if (e.code !== "EXDEV")
|
|
142
|
+
throw e;
|
|
143
|
+
cpSync(from, to, { recursive: true });
|
|
144
|
+
rmSync(from, { recursive: true, force: true });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** 0.1.3/0.1.4 kept `<skill>.previous` beside the skill, where Claude Code loaded it as a second skill. */
|
|
148
|
+
function migrateLegacyBackup(root, previous) {
|
|
149
|
+
const legacy = `${root}.previous`;
|
|
150
|
+
if (!existsSync(legacy))
|
|
151
|
+
return;
|
|
152
|
+
if (existsSync(previous)) {
|
|
153
|
+
rmSync(legacy, { recursive: true, force: true });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
mkdirSync(dirname(previous), { recursive: true });
|
|
157
|
+
moveDir(legacy, previous);
|
|
158
|
+
}
|
|
159
|
+
console.log(` Moved the old backup out of the skills folder: ${legacy} → ${previous}`);
|
|
160
|
+
}
|
|
161
|
+
function readManifest(root) {
|
|
162
|
+
try {
|
|
163
|
+
return JSON.parse(readFileSync(join(root, ".zabuti-install.json"), "utf8"));
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** true = zabuti.com has different files, false = same, string = why it couldn't tell. */
|
|
170
|
+
async function updateAvailable(name, m, token) {
|
|
171
|
+
try {
|
|
172
|
+
const res = await fetch(`${BASE_URL}/api/cli/skills/${encodeURIComponent(name)}?check=1`, { headers: { authorization: `Bearer ${token}` } });
|
|
173
|
+
const body = (await res.json().catch(() => null));
|
|
174
|
+
if (!res.ok || !body?.files)
|
|
175
|
+
return `the server answered ${res.status}`;
|
|
176
|
+
const have = new Map((m.files ?? []).map((f) => [f.path, f.sha256]));
|
|
177
|
+
return !(body.files.length === have.size && body.files.every((f) => have.get(f.path) === f.sha256));
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return "couldn't reach the server";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Update the named skill, or every installed one, only where zabuti.com has a newer copy. */
|
|
184
|
+
export async function cmdUpdate(name) {
|
|
185
|
+
const token = storedToken();
|
|
186
|
+
if (!token)
|
|
187
|
+
throw new Error("not signed in. Make a token at zabuti.com/account, then run `zabuti-tools login <token>`.");
|
|
188
|
+
const names = name ? [name] : SKILL_NAMES.filter((n) => existsSync(skillRoot(n)));
|
|
189
|
+
if (!names.length) {
|
|
190
|
+
console.log("No Zabuti skills are installed. Install one with `zabuti-tools add <skill>`.");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (const n of names) {
|
|
194
|
+
const root = skillRoot(n);
|
|
195
|
+
migrateLegacyBackup(root, previousDir(root, n));
|
|
196
|
+
const m = readManifest(root);
|
|
197
|
+
const avail = m ? await updateAvailable(n, m, token) : true;
|
|
198
|
+
if (avail === false)
|
|
199
|
+
console.log(`${n}: up to date.`);
|
|
200
|
+
else if (typeof avail === "string")
|
|
201
|
+
console.log(`${n}: skipped (${avail}).`);
|
|
202
|
+
else
|
|
203
|
+
await cmdAddSkill(n, false);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Swap the installed copy with the kept previous one. Running it again swaps back. */
|
|
207
|
+
export function cmdRollback(name) {
|
|
208
|
+
const root = skillRoot(name);
|
|
209
|
+
const previous = previousDir(root, name);
|
|
210
|
+
migrateLegacyBackup(root, previous);
|
|
211
|
+
if (!existsSync(previous))
|
|
212
|
+
throw new Error(`rollback: no previous copy of ${name} is kept (one is saved when an update replaces it).`);
|
|
213
|
+
if (existsSync(root)) {
|
|
214
|
+
const swap = `${previous}.swap`;
|
|
215
|
+
rmSync(swap, { recursive: true, force: true });
|
|
216
|
+
moveDir(root, swap);
|
|
217
|
+
moveDir(previous, root);
|
|
218
|
+
moveDir(swap, previous);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
moveDir(previous, root);
|
|
222
|
+
}
|
|
223
|
+
console.log(`✓ Rolled ${name} back to the copy installed ${readManifest(root)?.installedAt ?? "earlier"} → ${root}`);
|
|
224
|
+
if (existsSync(previous))
|
|
225
|
+
console.log(` The copy it replaced is kept at ${previous}; run rollback again to return to it.`);
|
|
226
|
+
}
|
|
119
227
|
/** What is installed, from the manifest written at install time. */
|
|
120
228
|
export async function cmdStatus() {
|
|
121
229
|
const token = storedToken();
|
|
122
230
|
for (const name of SKILL_NAMES) {
|
|
123
|
-
const root =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
231
|
+
const root = skillRoot(name);
|
|
232
|
+
migrateLegacyBackup(root, previousDir(root, name));
|
|
233
|
+
const m = readManifest(root);
|
|
234
|
+
if (!m) {
|
|
129
235
|
console.log(`${name}: ${existsSync(root) ? "installed (no manifest; reinstall to add one)" : "not installed"}`);
|
|
130
236
|
continue;
|
|
131
237
|
}
|
|
132
238
|
console.log(`${name}: installed ${m.installedAt ?? "?"} from ${m.source ?? "?"} (${m.files?.length ?? "?"} files) at ${root}`);
|
|
239
|
+
if (existsSync(previousDir(root, name)))
|
|
240
|
+
console.log(` Previous copy kept (\`zabuti-tools rollback ${name}\` to switch back).`);
|
|
133
241
|
if (!token) {
|
|
134
242
|
console.log(" Update check skipped (not signed in).");
|
|
135
243
|
continue;
|
|
136
244
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
}
|
|
245
|
+
const avail = await updateAvailable(name, m, token);
|
|
246
|
+
if (typeof avail === "string")
|
|
247
|
+
console.log(` Update check skipped (${avail}).`);
|
|
248
|
+
else
|
|
249
|
+
console.log(avail ? ` Update available: run \`zabuti-tools update\`.` : " Up to date.");
|
|
151
250
|
}
|
|
152
251
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zabuti/tools",
|
|
3
|
-
"version": "0.1.
|
|
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.5",
|
|
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",
|