@alessandroraffa/tangyr 1.0.2 → 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 +64 -45
  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
 
@@ -26232,7 +26262,11 @@ function resolveInstructionsSource(kitRoot, config) {
26232
26262
  "source.instructions in tangyr.config.yaml"
26233
26263
  );
26234
26264
  }
26235
- return { file, label: normalizeLabel(kitRoot, file), origin: "config-override" };
26265
+ return {
26266
+ file,
26267
+ label: normalizeLabel(kitRoot, file),
26268
+ origin: "config-override"
26269
+ };
26236
26270
  }
26237
26271
  const declared = resolveKitEntrypointName(kitRoot);
26238
26272
  if (declared !== void 0) {
@@ -26244,7 +26278,11 @@ function resolveInstructionsSource(kitRoot, config) {
26244
26278
  "entrypoint in tangyr-kit.yaml"
26245
26279
  );
26246
26280
  }
26247
- return { file, label: normalizeLabel(kitRoot, file), origin: "manifest-entrypoint" };
26281
+ return {
26282
+ file,
26283
+ label: normalizeLabel(kitRoot, file),
26284
+ origin: "manifest-entrypoint"
26285
+ };
26248
26286
  }
26249
26287
  for (const name of [DEFAULT_ENTRYPOINT, PORTABLE_INSTRUCTIONS_NAME]) {
26250
26288
  const file = path33.resolve(kitRoot, name);
@@ -26479,7 +26517,7 @@ function applyClaudeCodeShimUpgrade(shimPath, agentsMdPath, manifest, scopePath,
26479
26517
  const shimContent = buildAgentsMdShim(shimPath, agentsMdPath, "claude-code");
26480
26518
  const shimLink = lstatOrNull(shimPath);
26481
26519
  if (shimLink?.isSymbolicLink()) {
26482
- backupFile(shimPath, manifest);
26520
+ backupFile(shimPath, manifest, scopePath);
26483
26521
  writeManifest(scopePath, manifest);
26484
26522
  fs36.unlinkSync(shimPath);
26485
26523
  logger?.verbose(
@@ -26514,7 +26552,7 @@ function applyClaudeCodeShimUpgrade(shimPath, agentsMdPath, manifest, scopePath,
26514
26552
  );
26515
26553
  return;
26516
26554
  }
26517
- backupFile(shimPath, manifest);
26555
+ backupFile(shimPath, manifest, scopePath);
26518
26556
  writeManifest(scopePath, manifest);
26519
26557
  fs36.writeFileSync(shimPath, shimContent);
26520
26558
  addArtifactToManifest(manifest, {
@@ -26702,7 +26740,7 @@ function handleConflict(destination, config, options, logger, manifest, scopePat
26702
26740
  }
26703
26741
  if (config.onConflict === "backup") {
26704
26742
  if (manifest && scopePath) {
26705
- backupFile(destination, manifest);
26743
+ backupFile(destination, manifest, scopePath);
26706
26744
  writeManifest(scopePath, manifest);
26707
26745
  fs36.rmSync(destination, { recursive: true, force: true });
26708
26746
  } else {
@@ -28598,7 +28636,7 @@ function handleConflict2(destination, config, options, logger, manifest, scopePa
28598
28636
  }
28599
28637
  if (config.onConflict === "backup") {
28600
28638
  if (manifest && scopePath) {
28601
- backupFile(destination, manifest);
28639
+ backupFile(destination, manifest, scopePath);
28602
28640
  writeManifest(scopePath, manifest);
28603
28641
  fs38.rmSync(destination, { recursive: true, force: true });
28604
28642
  } else {
@@ -29179,7 +29217,7 @@ function handleConflict3(destination, config, options, logger, manifest, scopePa
29179
29217
  }
29180
29218
  if (config.onConflict === "backup") {
29181
29219
  if (manifest && scopePath) {
29182
- backupFile(destination, manifest);
29220
+ backupFile(destination, manifest, scopePath);
29183
29221
  writeManifest(scopePath, manifest);
29184
29222
  fs39.rmSync(destination, { recursive: true, force: true });
29185
29223
  } else {
@@ -29805,7 +29843,7 @@ function handleConflict4(destination, config, options, logger, manifest, scopePa
29805
29843
  }
29806
29844
  if (config.onConflict === "backup") {
29807
29845
  if (manifest && scopePath) {
29808
- backupFile(destination, manifest);
29846
+ backupFile(destination, manifest, scopePath);
29809
29847
  writeManifest(scopePath, manifest);
29810
29848
  fs40.rmSync(destination, { recursive: true, force: true });
29811
29849
  } else {
@@ -30280,7 +30318,7 @@ function handleConflict5(destination, config, options, logger, manifest, scopePa
30280
30318
  }
30281
30319
  if (config.onConflict === "backup") {
30282
30320
  if (manifest && scopePath) {
30283
- backupFile(destination, manifest);
30321
+ backupFile(destination, manifest, scopePath);
30284
30322
  writeManifest(scopePath, manifest);
30285
30323
  fs41.rmSync(destination, { recursive: true, force: true });
30286
30324
  } else {
@@ -30773,7 +30811,7 @@ function handleConflict6(destination, config, options, logger, manifest, scopePa
30773
30811
  }
30774
30812
  if (config.onConflict === "backup") {
30775
30813
  if (manifest && scopePath) {
30776
- backupFile(destination, manifest);
30814
+ backupFile(destination, manifest, scopePath);
30777
30815
  writeManifest(scopePath, manifest);
30778
30816
  fs42.rmSync(destination, { recursive: true, force: true });
30779
30817
  } else {
@@ -30841,29 +30879,8 @@ function isBackupablePath(targetPath) {
30841
30879
  }
30842
30880
  }
30843
30881
  function backupConflictingTarget(targetPath, scopePath) {
30844
- const ts2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/gu, "").replace("T", "T").replace(/\.\d+Z$/u, "Z");
30845
- const scopeRoot = path43.dirname(scopePath);
30846
- let relativeToRoot = path43.relative(scopeRoot, targetPath);
30847
- if (relativeToRoot.startsWith("..") || path43.isAbsolute(relativeToRoot)) {
30848
- const digest = crypto11.createHash("sha256").update(path43.dirname(targetPath)).digest("hex").slice(0, 12);
30849
- relativeToRoot = path43.join(`_outside-${digest}`, path43.basename(targetPath));
30850
- }
30851
- const backupPath = path43.join(scopePath, "backups", ts2, relativeToRoot);
30852
- fs43.mkdirSync(path43.dirname(backupPath), { recursive: true });
30853
- const stat = fs43.lstatSync(targetPath);
30854
- if (stat.isSymbolicLink()) {
30855
- fs43.symlinkSync(fs43.readlinkSync(targetPath), backupPath);
30856
- } else if (stat.isDirectory()) {
30857
- fs43.cpSync(targetPath, backupPath, {
30858
- recursive: true,
30859
- // Preserve links as links: following them would copy the kit into the
30860
- // backup and, worse, make the backup look like the user's own content.
30861
- dereference: false,
30862
- verbatimSymlinks: true
30863
- });
30864
- } else {
30865
- fs43.copyFileSync(targetPath, backupPath);
30866
- }
30882
+ const backupPath = resolveBackupPath(targetPath, scopePath);
30883
+ copyForBackup(targetPath, backupPath);
30867
30884
  return backupPath;
30868
30885
  }
30869
30886
  async function runInstallCommand(options, logger) {
@@ -31557,7 +31574,12 @@ function installClaudeCodeAdapterSlots(args) {
31557
31574
  if (outcome.status !== "success" && outcome.status !== "skipped-current") {
31558
31575
  continue;
31559
31576
  }
31560
- const key = claudeCodeOutcomeToManifestKey(profile, outcome, scope, projectRoot);
31577
+ const key = claudeCodeOutcomeToManifestKey(
31578
+ profile,
31579
+ outcome,
31580
+ scope,
31581
+ projectRoot
31582
+ );
31561
31583
  if (!key) {
31562
31584
  continue;
31563
31585
  }
@@ -32475,7 +32497,7 @@ function commandProbeRows(target, key, command, args) {
32475
32497
  }
32476
32498
 
32477
32499
  // src/commands/status.ts
32478
- import crypto12 from "crypto";
32500
+ import crypto11 from "crypto";
32479
32501
  import fs45 from "fs";
32480
32502
  import path46 from "path";
32481
32503
  function runStatusCommand(options, logger) {
@@ -33599,7 +33621,7 @@ function containsTangyrSource(value) {
33599
33621
  return typeof value._tangyr_source === "string" || typeof value._proteus_source === "string" || Object.values(value).some((entry) => containsTangyrSource(entry));
33600
33622
  }
33601
33623
  function hashString6(value) {
33602
- return `sha256:${crypto12.createHash("sha256").update(value).digest("hex")}`;
33624
+ return `sha256:${crypto11.createHash("sha256").update(value).digest("hex")}`;
33603
33625
  }
33604
33626
 
33605
33627
  // src/commands/sync.ts
@@ -34137,10 +34159,7 @@ async function runSyncCommand(options, logger) {
34137
34159
  }
34138
34160
  options.kitPath = kitPathOverride;
34139
34161
  options.kit = kitName;
34140
- const { config, configDir, configSource, sourceRoot, kitInfo } = resolveRuntime(
34141
- options,
34142
- import.meta.url
34143
- );
34162
+ const { config, configDir, configSource, sourceRoot, kitInfo } = resolveRuntime(options, import.meta.url);
34144
34163
  const syncOptions = toSyncOptions(options, config, configDir, configSource);
34145
34164
  const targets = activeTargets(config, options.target);
34146
34165
  const results = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alessandroraffa/tangyr",
3
- "version": "1.0.2",
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": {