@alessandroraffa/tangyr 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/dist/index.js +47 -38
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16052,22 +16052,53 @@ function isArtifactManifestPath(relativePath) {
16052
16052
  const [tool] = relativePath.split("/");
16053
16053
  return artifactManifestPrefixes.has(tool);
16054
16054
  }
16055
- function backupFile(originalPath, manifest) {
16056
- const priorSuffixes = manifest.backups.filter((b) => b.originalPath === originalPath).map((b) => b.integerSuffix);
16057
- const suffix = priorSuffixes.length > 0 ? Math.max(...priorSuffixes) + 1 : 1;
16058
- const backupPath = `${originalPath}.bak.${suffix}`;
16055
+ function resolveBackupPath(originalPath, scopePath) {
16056
+ const ts2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/gu, "").replace(/\.\d+Z$/u, "Z");
16057
+ const scopeRoot = path6.dirname(scopePath);
16058
+ let relativeToRoot = path6.relative(scopeRoot, originalPath);
16059
+ if (relativeToRoot.startsWith("..") || path6.isAbsolute(relativeToRoot)) {
16060
+ const digest = crypto2.createHash("sha256").update(path6.dirname(originalPath)).digest("hex").slice(0, 12);
16061
+ relativeToRoot = path6.join(
16062
+ `_outside-${digest}`,
16063
+ path6.basename(originalPath)
16064
+ );
16065
+ }
16066
+ const base = path6.join(scopePath, "backups", ts2, relativeToRoot);
16067
+ let candidate = base;
16068
+ for (let n7 = 2; fs6.existsSync(candidate) || isPresentLink(candidate); n7++) {
16069
+ candidate = `${base}-${String(n7)}`;
16070
+ }
16071
+ return candidate;
16072
+ }
16073
+ function isPresentLink(p) {
16074
+ try {
16075
+ return fs6.lstatSync(p).isSymbolicLink();
16076
+ } catch {
16077
+ return false;
16078
+ }
16079
+ }
16080
+ function copyForBackup(originalPath, backupPath) {
16081
+ fs6.mkdirSync(path6.dirname(backupPath), { recursive: true });
16059
16082
  const stat = fs6.lstatSync(originalPath);
16060
16083
  if (stat.isSymbolicLink()) {
16061
16084
  fs6.symlinkSync(fs6.readlinkSync(originalPath), backupPath);
16062
16085
  } else if (stat.isDirectory()) {
16063
16086
  fs6.cpSync(originalPath, backupPath, {
16064
16087
  recursive: true,
16088
+ // Preserve links as links: following them would copy the kit into the
16089
+ // backup and, worse, make the backup look like the operator's content.
16065
16090
  dereference: false,
16066
16091
  verbatimSymlinks: true
16067
16092
  });
16068
16093
  } else {
16069
16094
  fs6.copyFileSync(originalPath, backupPath);
16070
16095
  }
16096
+ }
16097
+ function backupFile(originalPath, manifest, scopePath) {
16098
+ const priorSuffixes = manifest.backups.filter((b) => b.originalPath === originalPath).map((b) => b.integerSuffix);
16099
+ const suffix = priorSuffixes.length > 0 ? Math.max(...priorSuffixes) + 1 : 1;
16100
+ const backupPath = resolveBackupPath(originalPath, scopePath);
16101
+ copyForBackup(originalPath, backupPath);
16071
16102
  manifest.backups.push({
16072
16103
  originalPath,
16073
16104
  backupLocation: backupPath,
@@ -25091,7 +25122,6 @@ function toConflictPolicy2(value) {
25091
25122
  }
25092
25123
 
25093
25124
  // src/commands/install.ts
25094
- import crypto11 from "crypto";
25095
25125
  import fs43 from "fs";
25096
25126
  import path43 from "path";
25097
25127
 
@@ -26487,7 +26517,7 @@ function applyClaudeCodeShimUpgrade(shimPath, agentsMdPath, manifest, scopePath,
26487
26517
  const shimContent = buildAgentsMdShim(shimPath, agentsMdPath, "claude-code");
26488
26518
  const shimLink = lstatOrNull(shimPath);
26489
26519
  if (shimLink?.isSymbolicLink()) {
26490
- backupFile(shimPath, manifest);
26520
+ backupFile(shimPath, manifest, scopePath);
26491
26521
  writeManifest(scopePath, manifest);
26492
26522
  fs36.unlinkSync(shimPath);
26493
26523
  logger?.verbose(
@@ -26522,7 +26552,7 @@ function applyClaudeCodeShimUpgrade(shimPath, agentsMdPath, manifest, scopePath,
26522
26552
  );
26523
26553
  return;
26524
26554
  }
26525
- backupFile(shimPath, manifest);
26555
+ backupFile(shimPath, manifest, scopePath);
26526
26556
  writeManifest(scopePath, manifest);
26527
26557
  fs36.writeFileSync(shimPath, shimContent);
26528
26558
  addArtifactToManifest(manifest, {
@@ -26710,7 +26740,7 @@ function handleConflict(destination, config, options, logger, manifest, scopePat
26710
26740
  }
26711
26741
  if (config.onConflict === "backup") {
26712
26742
  if (manifest && scopePath) {
26713
- backupFile(destination, manifest);
26743
+ backupFile(destination, manifest, scopePath);
26714
26744
  writeManifest(scopePath, manifest);
26715
26745
  fs36.rmSync(destination, { recursive: true, force: true });
26716
26746
  } else {
@@ -28606,7 +28636,7 @@ function handleConflict2(destination, config, options, logger, manifest, scopePa
28606
28636
  }
28607
28637
  if (config.onConflict === "backup") {
28608
28638
  if (manifest && scopePath) {
28609
- backupFile(destination, manifest);
28639
+ backupFile(destination, manifest, scopePath);
28610
28640
  writeManifest(scopePath, manifest);
28611
28641
  fs38.rmSync(destination, { recursive: true, force: true });
28612
28642
  } else {
@@ -29187,7 +29217,7 @@ function handleConflict3(destination, config, options, logger, manifest, scopePa
29187
29217
  }
29188
29218
  if (config.onConflict === "backup") {
29189
29219
  if (manifest && scopePath) {
29190
- backupFile(destination, manifest);
29220
+ backupFile(destination, manifest, scopePath);
29191
29221
  writeManifest(scopePath, manifest);
29192
29222
  fs39.rmSync(destination, { recursive: true, force: true });
29193
29223
  } else {
@@ -29813,7 +29843,7 @@ function handleConflict4(destination, config, options, logger, manifest, scopePa
29813
29843
  }
29814
29844
  if (config.onConflict === "backup") {
29815
29845
  if (manifest && scopePath) {
29816
- backupFile(destination, manifest);
29846
+ backupFile(destination, manifest, scopePath);
29817
29847
  writeManifest(scopePath, manifest);
29818
29848
  fs40.rmSync(destination, { recursive: true, force: true });
29819
29849
  } else {
@@ -30288,7 +30318,7 @@ function handleConflict5(destination, config, options, logger, manifest, scopePa
30288
30318
  }
30289
30319
  if (config.onConflict === "backup") {
30290
30320
  if (manifest && scopePath) {
30291
- backupFile(destination, manifest);
30321
+ backupFile(destination, manifest, scopePath);
30292
30322
  writeManifest(scopePath, manifest);
30293
30323
  fs41.rmSync(destination, { recursive: true, force: true });
30294
30324
  } else {
@@ -30781,7 +30811,7 @@ function handleConflict6(destination, config, options, logger, manifest, scopePa
30781
30811
  }
30782
30812
  if (config.onConflict === "backup") {
30783
30813
  if (manifest && scopePath) {
30784
- backupFile(destination, manifest);
30814
+ backupFile(destination, manifest, scopePath);
30785
30815
  writeManifest(scopePath, manifest);
30786
30816
  fs42.rmSync(destination, { recursive: true, force: true });
30787
30817
  } else {
@@ -30849,29 +30879,8 @@ function isBackupablePath(targetPath) {
30849
30879
  }
30850
30880
  }
30851
30881
  function backupConflictingTarget(targetPath, scopePath) {
30852
- const ts2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/gu, "").replace("T", "T").replace(/\.\d+Z$/u, "Z");
30853
- const scopeRoot = path43.dirname(scopePath);
30854
- let relativeToRoot = path43.relative(scopeRoot, targetPath);
30855
- if (relativeToRoot.startsWith("..") || path43.isAbsolute(relativeToRoot)) {
30856
- const digest = crypto11.createHash("sha256").update(path43.dirname(targetPath)).digest("hex").slice(0, 12);
30857
- relativeToRoot = path43.join(`_outside-${digest}`, path43.basename(targetPath));
30858
- }
30859
- const backupPath = path43.join(scopePath, "backups", ts2, relativeToRoot);
30860
- fs43.mkdirSync(path43.dirname(backupPath), { recursive: true });
30861
- const stat = fs43.lstatSync(targetPath);
30862
- if (stat.isSymbolicLink()) {
30863
- fs43.symlinkSync(fs43.readlinkSync(targetPath), backupPath);
30864
- } else if (stat.isDirectory()) {
30865
- fs43.cpSync(targetPath, backupPath, {
30866
- recursive: true,
30867
- // Preserve links as links: following them would copy the kit into the
30868
- // backup and, worse, make the backup look like the user's own content.
30869
- dereference: false,
30870
- verbatimSymlinks: true
30871
- });
30872
- } else {
30873
- fs43.copyFileSync(targetPath, backupPath);
30874
- }
30882
+ const backupPath = resolveBackupPath(targetPath, scopePath);
30883
+ copyForBackup(targetPath, backupPath);
30875
30884
  return backupPath;
30876
30885
  }
30877
30886
  async function runInstallCommand(options, logger) {
@@ -32488,7 +32497,7 @@ function commandProbeRows(target, key, command, args) {
32488
32497
  }
32489
32498
 
32490
32499
  // src/commands/status.ts
32491
- import crypto12 from "crypto";
32500
+ import crypto11 from "crypto";
32492
32501
  import fs45 from "fs";
32493
32502
  import path46 from "path";
32494
32503
  function runStatusCommand(options, logger) {
@@ -33612,7 +33621,7 @@ function containsTangyrSource(value) {
33612
33621
  return typeof value._tangyr_source === "string" || typeof value._proteus_source === "string" || Object.values(value).some((entry) => containsTangyrSource(entry));
33613
33622
  }
33614
33623
  function hashString6(value) {
33615
- return `sha256:${crypto12.createHash("sha256").update(value).digest("hex")}`;
33624
+ return `sha256:${crypto11.createHash("sha256").update(value).digest("hex")}`;
33616
33625
  }
33617
33626
 
33618
33627
  // src/commands/sync.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessandroraffa/tangyr",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CLI for the Tangyr discipline — install and manage operating kits for AI coding tools",
5
5
  "license": "MIT",
6
6
  "engines": {