@pixelfactoryio/theway 0.5.2 → 0.5.3

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/dist/theway.js CHANGED
@@ -2363,25 +2363,114 @@ import {
2363
2363
  chmodSync,
2364
2364
  constants,
2365
2365
  copyFileSync as copyFileSync2,
2366
- cpSync as cpSync2,
2366
+ cpSync,
2367
2367
  existsSync as existsSync3,
2368
2368
  lstatSync,
2369
2369
  mkdirSync as mkdirSync3,
2370
- readFileSync as readFileSync4,
2370
+ readFileSync as readFileSync5,
2371
2371
  readlinkSync,
2372
2372
  realpathSync,
2373
- renameSync as renameSync2,
2373
+ renameSync as renameSync3,
2374
2374
  rmdirSync,
2375
- rmSync,
2375
+ rmSync as rmSync2,
2376
2376
  statSync as statSync2,
2377
- writeFileSync
2377
+ writeFileSync as writeFileSync2
2378
2378
  } from "node:fs";
2379
2379
  import { homedir as homedir2 } from "node:os";
2380
2380
  import { delimiter, dirname, join as join3, resolve as resolve3, sep } from "node:path";
2381
2381
  import { fileURLToPath } from "node:url";
2382
2382
 
2383
2383
  // src/core/init.ts
2384
- import { copyFileSync, cpSync, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "node:fs";
2384
+ import { createHash } from "node:crypto";
2385
+ import {
2386
+ copyFileSync,
2387
+ existsSync as existsSync2,
2388
+ mkdirSync as mkdirSync2,
2389
+ readdirSync as readdirSync2,
2390
+ readFileSync as readFileSync4,
2391
+ renameSync as renameSync2,
2392
+ rmSync,
2393
+ writeFileSync
2394
+ } from "node:fs";
2395
+ var SHIPPED_DIRS = ["data/standards", "templates"];
2396
+ var MANIFEST = ".shipped.json";
2397
+ var sha256 = (data) => createHash("sha256").update(data).digest("hex");
2398
+ function readManifest(home) {
2399
+ try {
2400
+ const parsed = JSON.parse(readFileSync4(`${home}/${MANIFEST}`, "utf-8"));
2401
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
2402
+ return;
2403
+ return parsed;
2404
+ } catch {
2405
+ return;
2406
+ }
2407
+ }
2408
+ function writeAtomic(target, data) {
2409
+ const tmp = `${target}.tmp-${process.pid}`;
2410
+ try {
2411
+ writeFileSync(tmp, data);
2412
+ renameSync2(tmp, target);
2413
+ } finally {
2414
+ rmSync(tmp, { force: true });
2415
+ }
2416
+ }
2417
+ function writeManifest(home, manifest) {
2418
+ writeAtomic(`${home}/${MANIFEST}`, `${JSON.stringify(manifest, null, 2)}
2419
+ `);
2420
+ }
2421
+ function backupPath(home, rel, current) {
2422
+ const bak = `${rel}.bak`;
2423
+ if (!existsSync2(`${home}/${bak}`) || readFileSync4(`${home}/${bak}`).equals(current))
2424
+ return bak;
2425
+ for (let n = 1;; n++) {
2426
+ if (!existsSync2(`${home}/${bak}.${n}`))
2427
+ return `${bak}.${n}`;
2428
+ }
2429
+ }
2430
+ function copyShipped(src, home) {
2431
+ const previous = readManifest(home);
2432
+ const manifest = {};
2433
+ for (const dir of SHIPPED_DIRS) {
2434
+ mkdirSync2(`${home}/${dir}`, { recursive: true });
2435
+ const names = readdirSync2(`${src}/${dir}`, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name).sort();
2436
+ for (const name of names) {
2437
+ const rel = `${dir}/${name}`;
2438
+ const dst = `${home}/${rel}`;
2439
+ const shipped = readFileSync4(`${src}/${rel}`);
2440
+ const old = previous?.[rel];
2441
+ const sibling = `${dir}/${name.slice(0, -".md".length)}.default.md`;
2442
+ let removeSibling = true;
2443
+ if (!existsSync2(dst)) {
2444
+ writeAtomic(dst, shipped);
2445
+ } else {
2446
+ const current = readFileSync4(dst);
2447
+ if (!current.equals(shipped)) {
2448
+ if (typeof old === "string") {
2449
+ if (sha256(current) === old) {
2450
+ writeAtomic(dst, shipped);
2451
+ } else {
2452
+ removeSibling = false;
2453
+ writeAtomic(`${home}/${sibling}`, shipped);
2454
+ process.stdout.write(`Kept your edited ${rel} (shipped version: ${sibling})
2455
+ `);
2456
+ }
2457
+ } else {
2458
+ removeSibling = false;
2459
+ const bak = backupPath(home, rel, current);
2460
+ copyFileSync(dst, `${home}/${bak}`);
2461
+ writeAtomic(dst, shipped);
2462
+ process.stdout.write(`Replaced ${rel}; your previous version is in ${bak}
2463
+ `);
2464
+ }
2465
+ }
2466
+ }
2467
+ if (removeSibling)
2468
+ rmSync(`${home}/${sibling}`, { force: true });
2469
+ manifest[rel] = sha256(shipped);
2470
+ }
2471
+ }
2472
+ writeManifest(home, manifest);
2473
+ }
2385
2474
  function init(src, home) {
2386
2475
  try {
2387
2476
  mkdirSync2(home, { recursive: true });
@@ -2392,8 +2481,7 @@ function init(src, home) {
2392
2481
  } else {
2393
2482
  copyFileSync(`${src}/config.yaml`, `${home}/config.yaml`);
2394
2483
  }
2395
- cpSync(`${src}/data/standards`, `${home}/data/standards`, { recursive: true });
2396
- cpSync(`${src}/templates`, `${home}/templates`, { recursive: true });
2484
+ copyShipped(src, home);
2397
2485
  } catch (e) {
2398
2486
  process.stderr.write(`theway: ${e.message}
2399
2487
  `);
@@ -2454,7 +2542,7 @@ function readSettings(path2) {
2454
2542
  return {};
2455
2543
  let data;
2456
2544
  try {
2457
- data = JSON.parse(readFileSync4(path2, "utf-8"));
2545
+ data = JSON.parse(readFileSync5(path2, "utf-8"));
2458
2546
  } catch {
2459
2547
  return null;
2460
2548
  }
@@ -2504,12 +2592,12 @@ function writeSettings(target, settings) {
2504
2592
  const mode = existsSync3(target) ? statSync2(target).mode & 511 : 384;
2505
2593
  const tmp = `${target}.tmp-${process.pid}`;
2506
2594
  try {
2507
- writeFileSync(tmp, `${JSON.stringify(settings, null, 2)}
2595
+ writeFileSync2(tmp, `${JSON.stringify(settings, null, 2)}
2508
2596
  `, { mode });
2509
2597
  chmodSync(tmp, mode);
2510
- renameSync2(tmp, target);
2598
+ renameSync3(tmp, target);
2511
2599
  } finally {
2512
- rmSync(tmp, { force: true });
2600
+ rmSync2(tmp, { force: true });
2513
2601
  }
2514
2602
  }
2515
2603
  function invalidSettings(path2) {
@@ -2519,19 +2607,19 @@ function copyPlugin(home) {
2519
2607
  const tmp = join3(home, `.theway-install-${process.pid}`);
2520
2608
  const old = join3(home, `.theway-old-${process.pid}`);
2521
2609
  const dest = join3(home, "skills", "theway");
2522
- rmSync(tmp, { recursive: true, force: true });
2610
+ rmSync2(tmp, { recursive: true, force: true });
2523
2611
  try {
2524
2612
  for (const dir of PLUGIN_DIRS) {
2525
- cpSync2(join3(plugin, dir), join3(tmp, dir), { recursive: true });
2613
+ cpSync(join3(plugin, dir), join3(tmp, dir), { recursive: true });
2526
2614
  }
2527
2615
  mkdirSync3(join3(home, "skills"), { recursive: true });
2528
2616
  if (existsSync3(dest))
2529
- renameSync2(dest, old);
2530
- renameSync2(tmp, dest);
2617
+ renameSync3(dest, old);
2618
+ renameSync3(tmp, dest);
2531
2619
  } finally {
2532
- rmSync(tmp, { recursive: true, force: true });
2620
+ rmSync2(tmp, { recursive: true, force: true });
2533
2621
  }
2534
- rmSync(old, { recursive: true, force: true });
2622
+ rmSync2(old, { recursive: true, force: true });
2535
2623
  return dest;
2536
2624
  }
2537
2625
  function removeIfEmpty(dir) {
@@ -2541,7 +2629,7 @@ function removeIfEmpty(dir) {
2541
2629
  }
2542
2630
  function legacyText(path2, match) {
2543
2631
  try {
2544
- return lstatSync(path2).isFile() && match(readFileSync4(path2, "utf-8"));
2632
+ return lstatSync(path2).isFile() && match(readFileSync5(path2, "utf-8"));
2545
2633
  } catch {
2546
2634
  return false;
2547
2635
  }
@@ -2552,11 +2640,11 @@ function removeLegacyBin(home) {
2552
2640
  if (legacyText(join3(bin, "theway"), (t) => t.startsWith(`#!/bin/sh
2553
2641
  exec node `) && t.endsWith(`theway.js' "$@"
2554
2642
  `))) {
2555
- rmSync(join3(bin, "theway"), { force: true });
2643
+ rmSync2(join3(bin, "theway"), { force: true });
2556
2644
  }
2557
2645
  if (legacyText(join3(bin, "theway.js"), (t) => t.startsWith(`#!/usr/bin/env node
2558
2646
  `))) {
2559
- rmSync(join3(bin, "theway.js"), { force: true });
2647
+ rmSync2(join3(bin, "theway.js"), { force: true });
2560
2648
  }
2561
2649
  removeIfEmpty(bin);
2562
2650
  }
@@ -2568,9 +2656,9 @@ function writeBinary(dir) {
2568
2656
  try {
2569
2657
  copyFileSync2(self, tmp);
2570
2658
  chmodSync(tmp, 493);
2571
- renameSync2(tmp, dest);
2659
+ renameSync3(tmp, dest);
2572
2660
  } finally {
2573
- rmSync(tmp, { force: true });
2661
+ rmSync2(tmp, { force: true });
2574
2662
  }
2575
2663
  return dest;
2576
2664
  }
@@ -2586,7 +2674,7 @@ function isThewayBinary(path2) {
2586
2674
  if (!isFile(path2))
2587
2675
  return false;
2588
2676
  try {
2589
- const text = readFileSync4(path2, "utf-8");
2677
+ const text = readFileSync5(path2, "utf-8");
2590
2678
  return text.startsWith("#!/usr/bin/env node") && text.includes(BINARY_MARKER);
2591
2679
  } catch {
2592
2680
  return false;
@@ -2596,10 +2684,10 @@ function writePointer(home, custom) {
2596
2684
  const path2 = pointerPath();
2597
2685
  if (custom) {
2598
2686
  mkdirSync3(dirname(path2), { recursive: true });
2599
- writeFileSync(path2, `${home}
2687
+ writeFileSync2(path2, `${home}
2600
2688
  `);
2601
2689
  } else {
2602
- rmSync(path2, { force: true });
2690
+ rmSync2(path2, { force: true });
2603
2691
  }
2604
2692
  }
2605
2693
  function realpathOr(path2) {
@@ -2712,7 +2800,7 @@ function install() {
2712
2800
  writeSettings(resolved.target, settings);
2713
2801
  }
2714
2802
  checkPath(dir, binary);
2715
- const version = JSON.parse(readFileSync4(join3(pkgRoot, "package.json"), "utf-8")).version;
2803
+ const version = JSON.parse(readFileSync5(join3(pkgRoot, "package.json"), "utf-8")).version;
2716
2804
  process.stdout.write(`Installed theway ${version} to ${dest} (theway@skills-dir), ${binary} and ${tHome}. Start a new Claude Code session or run /reload-plugins.
2717
2805
  `);
2718
2806
  return 0;
@@ -2729,12 +2817,12 @@ function uninstall() {
2729
2817
  return unwritableSettings(settingsPath, resolved.error);
2730
2818
  settingsFile = resolved.target;
2731
2819
  }
2732
- rmSync(join3(cHome, "skills", "theway"), { recursive: true, force: true });
2820
+ rmSync2(join3(cHome, "skills", "theway"), { recursive: true, force: true });
2733
2821
  const binary = join3(installDir(), "theway");
2734
2822
  const removed = isThewayBinary(binary);
2735
2823
  if (removed)
2736
- rmSync(binary, { force: true });
2737
- rmSync(pointerPath(), { force: true });
2824
+ rmSync2(binary, { force: true });
2825
+ rmSync2(pointerPath(), { force: true });
2738
2826
  removeIfEmpty(dirname(pointerPath()));
2739
2827
  if (existsSync3(settingsPath)) {
2740
2828
  const settings = readSettings(settingsFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixelfactoryio/theway",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "A spec-first workflow for Claude Code",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "theway",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "theway writes a spec and a numbered task list before any code, then implements the tasks in your session or through agents that open a reviewed, CI-green pull request.",
5
5
  "author": {
6
6
  "name": "Amine",
@@ -2,7 +2,7 @@
2
2
  description: Install or update theway from a Claude Code session
3
3
  author: Amine
4
4
  # x-release-please-start-version
5
- allowed-tools: Bash(npx --yes @pixelfactoryio/theway@0.5.2 install)
5
+ allowed-tools: Bash(npx --yes @pixelfactoryio/theway@0.5.3 install)
6
6
  # x-release-please-end
7
7
  ---
8
8
 
@@ -16,7 +16,7 @@ One-time setup: installs the `theway` CLI on your `PATH` and initializes the the
16
16
 
17
17
  <!-- x-release-please-start-version -->
18
18
  ```bash
19
- npx --yes @pixelfactoryio/theway@0.5.2 install
19
+ npx --yes @pixelfactoryio/theway@0.5.3 install
20
20
  ```
21
21
  <!-- x-release-please-end -->
22
22