@zabuti/tools 0.1.8 → 0.1.10

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
@@ -1,46 +1,53 @@
1
- # @zabuti/tools
2
-
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).
6
-
7
- ```
8
- npx @zabuti/tools login zct_…
9
- npx @zabuti/tools add logic-map
10
- npx @zabuti/tools add logic-optimizer
11
- npx @zabuti/tools add deadlock-map # beta
12
- npx @zabuti/tools add resource-drain-map # beta
13
- ```
14
-
15
- ## Updates
16
-
17
- ```
18
- npx @zabuti/tools status # what is installed, and whether updates exist
19
- npx @zabuti/tools update # update every installed skill that has a newer version
20
- npx @zabuti/tools rollback logic-map # switch back to the copy the last update replaced
21
- ```
22
-
23
- An update keeps the copy it replaces in `~/.zabuti/previous/<name>/`, outside the skills
24
- folder so Claude Code doesn't load it as a second skill. Running `rollback` again swaps back.
25
- Re-running `add` or `update` when nothing changed leaves the kept copy alone.
26
-
27
- The skill is written to `~/.claude/skills/<name>/`. The server checks your token and your
28
- organization's license on every download. Nothing from your project is sent. The free
29
- `zabuti` CLI (components and icons) is a separate package and makes no network calls.
30
-
31
- ## Behind a corporate network
32
-
33
- If `add` says it couldn't reach zabuti.com and the cause is a certificate error
34
- (`UNABLE_TO_GET_ISSUER_CERT_LOCALLY`, `SELF_SIGNED_CERT_IN_CHAIN`, `CERT_HAS_EXPIRED`), your
35
- network is probably re-signing secure traffic with a company certificate. The browser trusts it
36
- because the operating system does; Node keeps its own list. Tell Node to use the system's
37
- certificates (Node 22.15 or later), then run the command again:
38
-
39
- ```
40
- $env:NODE_OPTIONS = "--use-system-ca" # PowerShell, this window only
41
- npx @zabuti/tools add logic-map
42
- ```
43
-
44
- Make it permanent with `setx NODE_OPTIONS "--use-system-ca"`. On older Node, set
45
- `NODE_EXTRA_CA_CERTS` to your company's root certificate file instead. Please don't use
46
- `NODE_TLS_REJECT_UNAUTHORIZED=0`: it turns certificate checks off entirely.
1
+ # @zabuti/tools
2
+
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).
6
+
7
+ ```
8
+ npx @zabuti/tools login zct_…
9
+ npx @zabuti/tools add logic-map
10
+ npx @zabuti/tools add logic-optimizer
11
+ npx @zabuti/tools add deadlock-map # beta
12
+ npx @zabuti/tools add resource-drain-map # beta
13
+ ```
14
+
15
+ ## Updates
16
+
17
+ ```
18
+ npx @zabuti/tools status # what is installed, and whether updates exist
19
+ npx @zabuti/tools update # update every installed skill that has a newer version
20
+ npx @zabuti/tools rollback logic-map # switch back to the copy the last update replaced
21
+ ```
22
+
23
+ An update keeps the copy it replaces in `~/.zabuti/previous/<name>/`, outside the skills
24
+ folder so Claude Code doesn't load it as a second skill. Running `rollback` again swaps back.
25
+ Re-running `add` or `update` when nothing changed leaves the kept copy alone.
26
+
27
+ Updates keep the changes you make to a skill. A file you never changed gets the new
28
+ version. A file you changed is kept. When the update changes it too, the new version and the
29
+ one yours started from wait in `~/.zabuti/updates/<name>/` (`.new` and `.original`), and the
30
+ installer prints a prompt to paste into Claude Code to merge them. Files you add to the skill
31
+ folder are never touched. `--overwrite` takes the new versions anyway (the replaced copy is
32
+ still kept for `rollback`).
33
+
34
+ The skill is written to `~/.claude/skills/<name>/`. The server checks your token and your
35
+ organization's license on every download. Nothing from your project is sent. The free
36
+ `zabuti` CLI (components and icons) is a separate package and makes no network calls.
37
+
38
+ ## Behind a corporate network
39
+
40
+ If `add` says it couldn't reach zabuti.com and the cause is a certificate error
41
+ (`UNABLE_TO_GET_ISSUER_CERT_LOCALLY`, `SELF_SIGNED_CERT_IN_CHAIN`, `CERT_HAS_EXPIRED`), your
42
+ network is probably re-signing secure traffic with a company certificate. The browser trusts it
43
+ because the operating system does; Node keeps its own list. Tell Node to use the system's
44
+ certificates (Node 22.15 or later), then run the command again:
45
+
46
+ ```
47
+ $env:NODE_OPTIONS = "--use-system-ca" # PowerShell, this window only
48
+ npx @zabuti/tools add logic-map
49
+ ```
50
+
51
+ Make it permanent with `setx NODE_OPTIONS "--use-system-ca"`. On older Node, set
52
+ `NODE_EXTRA_CA_CERTS` to your company's root certificate file instead. Please don't use
53
+ `NODE_TLS_REJECT_UNAUTHORIZED=0`: it turns certificate checks off entirely.
@@ -5,18 +5,25 @@
5
5
  */
6
6
  import { readFileSync } from "node:fs";
7
7
  import { cmdAddSkill, cmdLogin, cmdRollback, cmdStatus, cmdUpdate, SKILL_NAMES } from "./skills.js";
8
- const USAGE = `zabuti-tools: install the licensed Zabuti developer tools
9
-
10
- zabuti-tools login <token> save your download token (make one at zabuti.com/account)
11
- zabuti-tools add <skill> install a skill into ~/.claude/skills/
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
15
-
16
- zabuti-tools status show what is installed and whether updates exist
17
- zabuti-tools --version
18
-
19
- Options: --dry-run (list the files without writing), --out=<folder> (install there instead)`;
8
+ const USAGE = `zabuti-tools: install the licensed Zabuti developer tools
9
+
10
+ zabuti-tools login <token> save your download token (make one at zabuti.com/account)
11
+ zabuti-tools add <skill> install a skill into ~/.claude/skills/
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
15
+
16
+ zabuti-tools status show what is installed and whether updates exist
17
+ zabuti-tools --version
18
+
19
+ Files you have changed are never overwritten: an update keeps yours and saves the new
20
+ version to ~/.zabuti/updates/<skill>/ with a prompt for Claude Code to merge it.
21
+
22
+ Options: --dry-run (add/update: show what would change, write nothing)
23
+ --out=<folder> (add: install there instead)
24
+ --overwrite (add/update: take the new versions even where you changed a file;
25
+ the copy it replaces is kept for rollback)
26
+ An option a command doesn't take stops it before anything is written.`;
20
27
  function die(msg) {
21
28
  console.error(`zabuti-tools: ${msg}`);
22
29
  process.exit(1);
@@ -26,6 +33,25 @@ const flags = new Set(args.filter((a) => a.startsWith("--")));
26
33
  const outDir = args.find((a) => a.startsWith("--out="))?.slice(6);
27
34
  const positionals = args.filter((a) => !a.startsWith("--"));
28
35
  const [command, name] = positionals;
36
+ // Flags each command understands. Anything else stops the run, so a misspelled or
37
+ // unsupported flag (say --dry-run where it isn't supported) never goes ignored while
38
+ // the command writes.
39
+ const ALLOWED = {
40
+ login: [],
41
+ add: ["--dry-run", "--out=", "--overwrite"],
42
+ update: ["--dry-run", "--overwrite"],
43
+ rollback: [],
44
+ status: [],
45
+ help: [],
46
+ };
47
+ const known = command === undefined ? ["--version", "--help"] : ALLOWED[command];
48
+ if (known) {
49
+ const bad = args.filter((a) => a.startsWith("--") && !known.some((k) => (k.endsWith("=") ? a.startsWith(k) && a.length > k.length : a === k)));
50
+ if (bad.length) {
51
+ const label = command ?? "zabuti-tools";
52
+ die(`${label}: ${bad.map((b) => `"${b}"`).join(", ")} ${bad.length > 1 ? "aren't options" : "isn't an option"} here; nothing was changed.${known.length ? ` ${label} takes: ${known.map((k) => (k.endsWith("=") ? `${k}<folder>` : k)).join(", ")}.` : ""}`);
53
+ }
54
+ }
29
55
  try {
30
56
  switch (command) {
31
57
  case "login":
@@ -35,13 +61,13 @@ try {
35
61
  if (!name || !SKILL_NAMES.includes(name) || positionals.length > 2) {
36
62
  die(`add: name one skill (${SKILL_NAMES.join(" or ")}), e.g. \`zabuti-tools add logic-map\`.`);
37
63
  }
38
- await cmdAddSkill(name, flags.has("--dry-run"), outDir);
64
+ await cmdAddSkill(name, flags.has("--dry-run"), outDir, flags.has("--overwrite"));
39
65
  break;
40
66
  case "update":
41
67
  if ((name && !SKILL_NAMES.includes(name)) || positionals.length > 2) {
42
68
  die(`update: name one skill (${SKILL_NAMES.join(" or ")}) or none to update all installed ones.`);
43
69
  }
44
- await cmdUpdate(name);
70
+ await cmdUpdate(name, flags.has("--overwrite"), flags.has("--dry-run"));
45
71
  break;
46
72
  case "rollback":
47
73
  if (!name || !SKILL_NAMES.includes(name) || positionals.length > 2) {
@@ -4,10 +4,10 @@
4
4
  * the site and writes it to ~/.claude/skills/<name>/. The server checks the token and
5
5
  * the account's license on every download. Nothing else is sent: no project files.
6
6
  */
7
- import { createHash } from "node:crypto";
8
7
  import { chmodSync, cpSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
9
8
  import { homedir } from "node:os";
10
9
  import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
10
+ import { applyPlan, forgetOriginal, pendingFiles, planFiles, printMergeHelp, printPlan, sha256 } from "../../shared/keep-local-edits.js";
11
11
  export const SKILL_NAMES = ["logic-map", "logic-optimizer", "deadlock-map", "resource-drain-map"];
12
12
  const BASE_URL = (process.env.ZABUTI_URL ?? "https://zabuti.com").replace(/\/+$/, "");
13
13
  const CONFIG_DIR = join(homedir(), ".zabuti");
@@ -72,7 +72,7 @@ function unreachableMessage(e) {
72
72
  }
73
73
  return msg;
74
74
  }
75
- export async function cmdAddSkill(name, dryRun, outDir) {
75
+ export async function cmdAddSkill(name, dryRun, outDir, overwrite = false) {
76
76
  const token = storedToken();
77
77
  if (!token)
78
78
  throw new Error("not signed in. Make a token at zabuti.com/account, then run `zabuti-tools login <token>`.");
@@ -89,56 +89,95 @@ export async function cmdAddSkill(name, dryRun, outDir) {
89
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
- if (f.sha256 && createHash("sha256").update(f.content, "utf8").digest("hex") !== f.sha256) {
92
+ if (f.sha256 && sha256(f.content) !== f.sha256) {
93
93
  throw new Error(`${f.rel} did not match its checksum; nothing was written. Run the command again.`);
94
94
  }
95
95
  }
96
- if (dryRun) {
97
- console.log(`Would write ${files.length} files to ${root}:`);
98
- for (const f of files)
99
- console.log(` ${f.rel}`);
100
- return;
101
- }
102
96
  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}`);
97
+ if (!dryRun)
98
+ migrateLegacyBackup(root, previous);
99
+ const manifest = readManifest(root);
100
+ const installed = manifest?.files ? new Map(manifest.files.map((f) => [f.path, f.sha256])) : null;
101
+ const plan = planFiles(files, installed, overwrite);
102
+ // Files a newer version no longer ships: removed only if the user never changed them.
103
+ const incoming = new Set(files.map((f) => f.rel));
104
+ const dropped = (manifest?.files ?? [])
105
+ .filter((f) => !incoming.has(f.path))
106
+ .map((f) => {
107
+ const full = safeJoin(root, f.path);
108
+ const disk = existsSync(full) ? sha256(readFileSync(full, "utf8")) : null;
109
+ return { rel: f.path, full, remove: disk !== null && (disk === f.sha256 || overwrite), gone: disk === null };
110
+ });
111
+ const removing = dropped.filter((d) => d.remove);
112
+ const keptDropped = dropped.filter((d) => !d.remove && !d.gone);
113
+ const store = editStore(root, name);
114
+ const show = (f) => f.rel;
115
+ if (dryRun) {
116
+ console.log(`${name} → ${root}`);
117
+ printPlan(plan, show, true);
118
+ for (const d of removing)
119
+ console.log(` - ${d.rel} (no longer part of ${name}; would be removed)`);
120
+ for (const d of keptDropped)
121
+ console.log(` · ${d.rel} (no longer part of ${name}; yours would be kept)`);
122
+ if (!plan.some((f) => f.action !== "same") && !removing.length)
123
+ console.log("Nothing would change.");
112
124
  return;
113
125
  }
126
+ const changesFolder = plan.some((f) => f.action === "write") || removing.length > 0;
114
127
  // 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.
116
- if (existsSync(root)) {
128
+ // the skills folder: Claude Code loads every folder there as a skill. An update
129
+ // that changes nothing leaves it alone, so it stays a real older version.
130
+ if (changesFolder && existsSync(root)) {
117
131
  rmSync(previous, { recursive: true, force: true });
118
132
  mkdirSync(dirname(previous), { recursive: true });
119
- moveDir(root, previous);
133
+ cpSync(root, previous, { recursive: true });
120
134
  }
121
- for (const f of files) {
122
- mkdirSync(dirname(f.full), { recursive: true });
123
- writeFileSync(f.full, f.content);
135
+ applyPlan(plan, store);
136
+ for (const d of removing) {
137
+ rmSync(d.full, { force: true });
138
+ forgetOriginal(store, d.rel);
124
139
  }
125
140
  writeManifest(root, name, files);
126
- console.log(`✓ Installed ${name} (${files.length} files) → ${root}`);
127
- if (existsSync(previous))
141
+ const held = plan.filter((f) => f.action === "hold");
142
+ if (!changesFolder && !held.length) {
143
+ const kept = plan.filter((f) => f.action === "keep").length;
144
+ console.log(`✓ ${name} is already up to date at ${root}${kept ? ` (your changes to ${kept} file(s) kept)` : ""}`);
145
+ return;
146
+ }
147
+ console.log(`✓ ${manifest ? "Updated" : "Installed"} ${name} → ${root}`);
148
+ printPlan(plan, show);
149
+ for (const d of removing)
150
+ console.log(` - ${d.rel} (no longer part of ${name}; removed)`);
151
+ for (const d of keptDropped)
152
+ console.log(` · ${d.rel} (no longer part of ${name}; you changed it, so it was kept)`);
153
+ if (changesFolder && existsSync(previous))
128
154
  console.log(` Previous copy kept at ${previous} (undo with \`zabuti-tools rollback ${name}\`)`);
129
- console.log(" Open Claude Code in your project and ask it to use the skill.");
155
+ printMergeHelp(store, held, `zabuti-tools add ${name} --overwrite (your current copy is kept for rollback)`);
156
+ if (!manifest)
157
+ console.log(" Open Claude Code in your project and ask it to use the skill.");
130
158
  }
131
- const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
132
159
  const MANIFEST = ".zabuti-install.json";
133
160
  function writeManifest(root, name, files) {
134
161
  const manifest = { name, installedAt: new Date().toISOString(), source: BASE_URL, files: files.map((f) => ({ path: f.rel, sha256: sha256(f.content) })) };
135
162
  writeFileSync(join(root, MANIFEST), JSON.stringify(manifest, null, 2));
136
163
  }
137
164
  const skillRoot = (name) => join(homedir(), ".claude", "skills", name);
165
+ /** One folder name per install location: the skill name, or name-plus-hash for --out installs. */
166
+ function storeKey(root, name) {
167
+ return resolve(root) === resolve(skillRoot(name)) ? name : `${basename(root)}-${sha256(resolve(root)).slice(0, 8)}`;
168
+ }
138
169
  /** 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)}`);
170
+ const previousDir = (root, name) => join(CONFIG_DIR, "previous", storeKey(root, name));
171
+ /** As-installed copies and waiting merges: outside the skills folder too. */
172
+ const editStore = (root, name) => ({
173
+ originals: join(CONFIG_DIR, "original", storeKey(root, name)),
174
+ pending: join(CONFIG_DIR, "updates", storeKey(root, name)),
175
+ });
176
+ /** " N changed file(s) have an update waiting…" when an earlier update held any back. */
177
+ function waitingNote(root, name) {
178
+ const store = editStore(root, name);
179
+ const n = pendingFiles(store).length;
180
+ return n ? ` ${n} changed file(s) have an update waiting to be merged: ${store.pending}` : "";
142
181
  }
143
182
  /** rename, falling back to copy + delete across drives (--out on another volume). */
144
183
  function moveDir(from, to) {
@@ -189,7 +228,7 @@ async function updateAvailable(name, m, token) {
189
228
  }
190
229
  }
191
230
  /** Update the named skill, or every installed one, only where zabuti.com has a newer copy. */
192
- export async function cmdUpdate(name) {
231
+ export async function cmdUpdate(name, overwrite = false, dryRun = false) {
193
232
  const token = storedToken();
194
233
  if (!token)
195
234
  throw new Error("not signed in. Make a token at zabuti.com/account, then run `zabuti-tools login <token>`.");
@@ -198,18 +237,23 @@ export async function cmdUpdate(name) {
198
237
  console.log("No Zabuti skills are installed. Install one with `zabuti-tools add <skill>`.");
199
238
  return;
200
239
  }
240
+ if (dryRun)
241
+ console.log("Dry run: nothing will be written.");
201
242
  for (const n of names) {
202
243
  const root = skillRoot(n);
203
- migrateLegacyBackup(root, previousDir(root, n));
244
+ if (!dryRun)
245
+ migrateLegacyBackup(root, previousDir(root, n));
204
246
  const m = readManifest(root);
205
247
  const avail = m ? await updateAvailable(n, m, token) : true;
206
248
  if (avail === false)
207
- console.log(`${n}: up to date.`);
249
+ console.log(`${n}: up to date.${waitingNote(root, n)}`);
208
250
  else if (typeof avail === "string")
209
251
  console.log(`${n}: skipped (${avail}).`);
210
252
  else
211
- await cmdAddSkill(n, false);
253
+ await cmdAddSkill(n, dryRun, undefined, overwrite);
212
254
  }
255
+ if (dryRun)
256
+ console.log("Dry run: nothing was written. Run the same command without --dry-run to apply it.");
213
257
  }
214
258
  /** Swap the installed copy with the kept previous one. Running it again swaps back. */
215
259
  export function cmdRollback(name) {
@@ -254,6 +298,9 @@ export async function cmdStatus() {
254
298
  if (typeof avail === "string")
255
299
  console.log(` Update check skipped (${avail}).`);
256
300
  else
257
- console.log(avail ? ` Update available: run \`zabuti-tools update\`.` : " Up to date.");
301
+ console.log(avail ? ` Update available: run \`zabuti-tools update\` (files you changed are kept).` : " Up to date.");
302
+ const waiting = waitingNote(root, name);
303
+ if (waiting)
304
+ console.log(` ${waiting}`);
258
305
  }
259
306
  }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Updates that keep the user's own changes. Shared by `zabuti add` (components in a
3
+ * project) and `zabuti-tools add/update` (skills in ~/.claude/skills).
4
+ *
5
+ * Every install records the sha256 of each file as Zabuti wrote it. On the next
6
+ * install, each incoming file is compared three ways (on disk, as installed, new):
7
+ * same the file on disk already is the new version
8
+ * write the user never touched it (or it is new): take the new version
9
+ * keep the user changed it but this update doesn't: leave theirs alone
10
+ * hold both changed (or it can't tell): leave theirs alone and put the new
11
+ * version, with the version theirs started from, in a merge folder
12
+ * Nothing the user changed is ever overwritten unless they pass --overwrite.
13
+ */
14
+ import { createHash } from "node:crypto";
15
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync, writeFileSync } from "node:fs";
16
+ import { dirname, join, relative, sep } from "node:path";
17
+ export const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
18
+ function readText(path) {
19
+ try {
20
+ return readFileSync(path, "utf8");
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ /**
27
+ * `installed` is rel -> sha256 from the last install, or null when there is no record
28
+ * (installed before Zabuti tracked changes).
29
+ */
30
+ export function planFiles(files, installed, overwrite) {
31
+ return files.map((f) => {
32
+ const disk = readText(f.full);
33
+ const next = sha256(f.content);
34
+ const was = installed?.get(f.rel);
35
+ const p = (action, note) => ({ ...f, action, note });
36
+ if (disk !== null && sha256(disk) === next)
37
+ return p("same", "");
38
+ if (disk === null) {
39
+ if (was === undefined || overwrite)
40
+ return p("write", "new file");
41
+ return was === next ? p("keep", "you deleted it; this update doesn't change it") : p("hold", "you deleted it; this update changes it");
42
+ }
43
+ if (overwrite)
44
+ return p("write", "replaced (--overwrite)");
45
+ if (was === undefined) {
46
+ return p("hold", installed ? "a file of yours has the same name" : "it differs, and it was added before Zabuti tracked changes");
47
+ }
48
+ if (sha256(disk) === was)
49
+ return p("write", "updated");
50
+ if (was === next)
51
+ return p("keep", "your changes kept; this update doesn't change it");
52
+ return p("hold", "you changed it and this update changes it too");
53
+ });
54
+ }
55
+ const originalPath = (store, rel) => join(store.originals, `${rel}.original`);
56
+ const pendingNew = (store, rel) => join(store.pending, `${rel}.new`);
57
+ const pendingOriginal = (store, rel) => join(store.pending, `${rel}.original`);
58
+ function put(path, content) {
59
+ mkdirSync(dirname(path), { recursive: true });
60
+ writeFileSync(path, content);
61
+ }
62
+ /** Write the plan. `held` files get a `.new` (and `.original` when known) in the merge folder. */
63
+ export function applyPlan(plan, store) {
64
+ for (const f of plan) {
65
+ if (f.action === "write")
66
+ put(f.full, f.content);
67
+ if (f.action === "hold") {
68
+ put(pendingNew(store, f.rel), f.content);
69
+ // Keep the oldest original: it is what the user's edits actually started from.
70
+ const known = readText(originalPath(store, f.rel));
71
+ if (!existsSync(pendingOriginal(store, f.rel)) && known !== null)
72
+ put(pendingOriginal(store, f.rel), known);
73
+ }
74
+ else {
75
+ // On disk matches (or the user keeps theirs on purpose): nothing left to merge.
76
+ if (f.action !== "keep")
77
+ clearPending(store, f.rel);
78
+ }
79
+ put(originalPath(store, f.rel), f.content);
80
+ }
81
+ pruneEmpty(store.pending);
82
+ }
83
+ export function clearPending(store, rel) {
84
+ rmSync(pendingNew(store, rel), { force: true });
85
+ rmSync(pendingOriginal(store, rel), { force: true });
86
+ }
87
+ export function forgetOriginal(store, rel) {
88
+ rmSync(originalPath(store, rel), { force: true });
89
+ }
90
+ /** rel paths with an update waiting to be merged. */
91
+ export function pendingFiles(store) {
92
+ const out = [];
93
+ const walk = (dir) => {
94
+ let names;
95
+ try {
96
+ names = readdirSync(dir);
97
+ }
98
+ catch {
99
+ return;
100
+ }
101
+ for (const n of names) {
102
+ const full = join(dir, n);
103
+ if (statSync(full).isDirectory())
104
+ walk(full);
105
+ else if (n.endsWith(".new"))
106
+ out.push(relative(store.pending, full).slice(0, -4).split(sep).join("/"));
107
+ }
108
+ };
109
+ walk(store.pending);
110
+ return out.sort();
111
+ }
112
+ function pruneEmpty(dir) {
113
+ if (!existsSync(dir))
114
+ return;
115
+ for (const n of readdirSync(dir)) {
116
+ const full = join(dir, n);
117
+ if (statSync(full).isDirectory())
118
+ pruneEmpty(full);
119
+ }
120
+ if (readdirSync(dir).length === 0)
121
+ rmdirSync(dir);
122
+ }
123
+ /** One line per file that changed or was left alone. */
124
+ export function printPlan(plan, show, dryRun = false) {
125
+ const label = dryRun
126
+ ? { write: "would write", keep: "would keep yours", hold: "would keep yours, new version saved to merge" }
127
+ : { write: "written", keep: "kept yours", hold: "kept yours, new version saved to merge" };
128
+ for (const action of ["write", "keep", "hold"]) {
129
+ const fs = plan.filter((f) => f.action === action);
130
+ if (!fs.length)
131
+ continue;
132
+ console.log(`${label[action]} (${fs.length}):`);
133
+ for (const f of fs)
134
+ console.log(` ${action === "write" ? "+" : action === "keep" ? "·" : "!"} ${show(f)}${f.note && f.note !== "updated" && f.note !== "new file" ? ` (${f.note})` : ""}`);
135
+ }
136
+ }
137
+ /** The steps for merging, plus a prompt to paste into Claude Code. */
138
+ export function printMergeHelp(store, held, overwriteHint) {
139
+ if (!held.length)
140
+ return;
141
+ const lines = held.map((f) => {
142
+ const hasOriginal = existsSync(pendingOriginal(store, f.rel));
143
+ return `- ${f.full}\n new Zabuti version: ${pendingNew(store, f.rel)}` + (hasOriginal ? `\n version yours started from: ${pendingOriginal(store, f.rel)}` : "\n (the version yours started from wasn't recorded: compare yours with the new one)");
144
+ });
145
+ console.log(`\nYour changes to ${held.length} file(s) were kept. The updates for them are waiting in:\n ${store.pending}`);
146
+ console.log("To merge them, paste this into Claude Code:\n");
147
+ console.log([
148
+ "Merge a Zabuti update into files I've changed. For each file below, keep my changes and bring in",
149
+ "what changed between the version mine started from and the new Zabuti version. Show me anything",
150
+ "where the two clash before deciding. When a file is merged, delete its .new and .original files.",
151
+ "",
152
+ ...lines,
153
+ ]
154
+ .map((l) => ` ${l}`)
155
+ .join("\n"));
156
+ console.log(`\nOr to drop your changes and take the new versions instead: ${overwriteHint}`);
157
+ }
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
- {
2
- "name": "@zabuti/tools",
3
- "version": "0.1.8",
4
- "description": "Installs the licensed Zabuti developer tools (Logic Map, Logic Optimizer, Deadlock Map, Resource Drain Map) as Claude Code skills. Needs a license and a download token from zabuti.com.",
5
- "homepage": "https://zabuti.com",
6
- "license": "MIT",
7
- "type": "module",
8
- "bin": {
9
- "zabuti-tools": "dist/installer/src/index.js"
10
- },
11
- "files": [
12
- "dist",
13
- "README.md"
14
- ],
15
- "engines": {
16
- "node": ">=20"
17
- },
18
- "keywords": [
19
- "claude-code",
20
- "skills",
21
- "zabuti"
22
- ],
23
- "scripts": {
24
- "build": "tsc -p tsconfig.json",
25
- "check": "tsc -p tsconfig.json --noEmit",
26
- "smoke": "node scripts/smoke.mjs",
27
- "prepack": "npm run build"
28
- },
29
- "devDependencies": {
30
- "@types/node": "^22.0.0",
31
- "typescript": "^5.6.0"
32
- }
33
- }
1
+ {
2
+ "name": "@zabuti/tools",
3
+ "version": "0.1.10",
4
+ "description": "Installs the licensed Zabuti developer tools (Logic Map, Logic Optimizer, Deadlock Map, Resource Drain Map) as Claude Code skills. Needs a license and a download token from zabuti.com.",
5
+ "homepage": "https://zabuti.com",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "bin": {
9
+ "zabuti-tools": "dist/installer/src/index.js"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "keywords": [
19
+ "claude-code",
20
+ "skills",
21
+ "zabuti"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.json",
25
+ "check": "tsc -p tsconfig.json --noEmit",
26
+ "smoke": "node scripts/smoke.mjs",
27
+ "prepack": "npm run build"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.0.0",
31
+ "typescript": "^5.6.0"
32
+ }
33
+ }