opencodekit 0.17.12 → 0.17.13
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/{index.mjs → index.js} +47 -10
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region package.json
|
|
21
|
-
var version = "0.17.
|
|
21
|
+
var version = "0.17.13";
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/utils/errors.ts
|
|
@@ -2578,6 +2578,7 @@ const EXCLUDED_FILES = [
|
|
|
2578
2578
|
"yarn.lock",
|
|
2579
2579
|
"pnpm-lock.yaml"
|
|
2580
2580
|
];
|
|
2581
|
+
const PRESERVE_USER_DIRS = ["memory/project"];
|
|
2581
2582
|
/**
|
|
2582
2583
|
* Get the global OpenCode config directory based on OS.
|
|
2583
2584
|
* - macOS/Linux: ~/.config/opencode/ (respects XDG_CONFIG_HOME)
|
|
@@ -2772,6 +2773,36 @@ async function autoSavePatchesForOrphans(targetDir, templateRoot, orphans) {
|
|
|
2772
2773
|
trueOrphans
|
|
2773
2774
|
};
|
|
2774
2775
|
}
|
|
2776
|
+
/**
|
|
2777
|
+
* Save existing user files from preserve directories before reinit.
|
|
2778
|
+
* Returns a map of relative paths to file contents.
|
|
2779
|
+
*/
|
|
2780
|
+
function preserveUserFiles(targetDir) {
|
|
2781
|
+
const opencodeDir = join(targetDir, ".opencode");
|
|
2782
|
+
const preserved = /* @__PURE__ */ new Map();
|
|
2783
|
+
for (const relDir of PRESERVE_USER_DIRS) {
|
|
2784
|
+
const dirPath = join(opencodeDir, relDir);
|
|
2785
|
+
if (!existsSync(dirPath)) continue;
|
|
2786
|
+
for (const entry of readdirSync(dirPath, { withFileTypes: true })) {
|
|
2787
|
+
if (!entry.isFile()) continue;
|
|
2788
|
+
const filePath = join(dirPath, entry.name);
|
|
2789
|
+
const relativePath = join(relDir, entry.name);
|
|
2790
|
+
preserved.set(relativePath, readFileSync(filePath, "utf-8"));
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
return preserved;
|
|
2794
|
+
}
|
|
2795
|
+
/**
|
|
2796
|
+
* Restore preserved user files after fresh template copy.
|
|
2797
|
+
*/
|
|
2798
|
+
function restoreUserFiles(targetDir, preserved) {
|
|
2799
|
+
const opencodeDir = join(targetDir, ".opencode");
|
|
2800
|
+
for (const [relativePath, content] of preserved) {
|
|
2801
|
+
const filePath = join(opencodeDir, relativePath);
|
|
2802
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
2803
|
+
writeFileSync(filePath, content);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2775
2806
|
async function initCommand(rawOptions = {}) {
|
|
2776
2807
|
const options = parseOptions(InitOptionsSchema, rawOptions);
|
|
2777
2808
|
if (process.argv.includes("--quiet")) return;
|
|
@@ -2817,6 +2848,7 @@ async function initCommand(rawOptions = {}) {
|
|
|
2817
2848
|
p.outro("Nothing to do");
|
|
2818
2849
|
return;
|
|
2819
2850
|
}
|
|
2851
|
+
let preservedFiles;
|
|
2820
2852
|
if (mode === "already-initialized" && options.force) {
|
|
2821
2853
|
const affected = getAffectedFiles(join(targetDir, ".opencode"));
|
|
2822
2854
|
if (affected.length > 0 && !options.yes) {
|
|
@@ -2845,9 +2877,10 @@ async function initCommand(rawOptions = {}) {
|
|
|
2845
2877
|
}
|
|
2846
2878
|
}
|
|
2847
2879
|
if (options.backup) {
|
|
2880
|
+
preservedFiles = preserveUserFiles(targetDir);
|
|
2848
2881
|
const backupPath = backupOpenCode(targetDir);
|
|
2849
2882
|
if (backupPath) p.log.info(`Backed up to ${color.cyan(basename(backupPath))}`);
|
|
2850
|
-
}
|
|
2883
|
+
} else preservedFiles = preserveUserFiles(targetDir);
|
|
2851
2884
|
}
|
|
2852
2885
|
const templateRoot = getTemplateRoot$1();
|
|
2853
2886
|
if (!templateRoot) {
|
|
@@ -2880,6 +2913,10 @@ async function initCommand(rawOptions = {}) {
|
|
|
2880
2913
|
process.exit(1);
|
|
2881
2914
|
}
|
|
2882
2915
|
s.stop("Done");
|
|
2916
|
+
if (preservedFiles && preservedFiles.size > 0) {
|
|
2917
|
+
restoreUserFiles(targetDir, preservedFiles);
|
|
2918
|
+
p.log.info(`Preserved ${preservedFiles.size} user memory files (memory/project/)`);
|
|
2919
|
+
}
|
|
2883
2920
|
if (options.free) {
|
|
2884
2921
|
applyModelPreset(targetDir, "free");
|
|
2885
2922
|
p.log.info("Applied free model preset");
|
|
@@ -2950,13 +2987,13 @@ async function initCommand(rawOptions = {}) {
|
|
|
2950
2987
|
const installSpinner = p.spinner();
|
|
2951
2988
|
installSpinner.start("Installing dependencies");
|
|
2952
2989
|
try {
|
|
2953
|
-
execSync("
|
|
2990
|
+
execSync("npm install --no-fund --no-audit", {
|
|
2954
2991
|
cwd: opencodeDir,
|
|
2955
2992
|
stdio: "ignore"
|
|
2956
2993
|
});
|
|
2957
2994
|
installSpinner.stop("Dependencies installed");
|
|
2958
2995
|
} catch {
|
|
2959
|
-
installSpinner.stop("Failed to install (run manually: cd .opencode &&
|
|
2996
|
+
installSpinner.stop("Failed to install (run manually: cd .opencode && npm install)");
|
|
2960
2997
|
}
|
|
2961
2998
|
}
|
|
2962
2999
|
if (mode === "already-initialized" && options.force && !options.backup) {
|
|
@@ -3389,12 +3426,12 @@ function copyDirPreserveExisting(src, dest) {
|
|
|
3389
3426
|
for (const entry of entries) {
|
|
3390
3427
|
const srcPath = join(src, entry.name);
|
|
3391
3428
|
const destPath = join(dest, entry.name);
|
|
3392
|
-
if (entry.isDirectory())
|
|
3393
|
-
mkdirSync(destPath, { recursive: true });
|
|
3429
|
+
if (entry.isDirectory()) {
|
|
3430
|
+
if (!existsSync(destPath)) mkdirSync(destPath, { recursive: true });
|
|
3394
3431
|
const subResult = copyDirPreserveExisting(srcPath, destPath);
|
|
3395
3432
|
updated.push(...subResult.updated);
|
|
3396
|
-
|
|
3397
|
-
else if (!existsSync(destPath)) {
|
|
3433
|
+
preserved.push(...subResult.preserved);
|
|
3434
|
+
} else if (!existsSync(destPath)) {
|
|
3398
3435
|
copyFileSync(srcPath, destPath);
|
|
3399
3436
|
updated.push(entry.name);
|
|
3400
3437
|
} else preserved.push(entry.name);
|
|
@@ -3520,13 +3557,13 @@ async function upgradeCommand(rawOptions = {}) {
|
|
|
3520
3557
|
installSpinner.start("Installing dependencies");
|
|
3521
3558
|
try {
|
|
3522
3559
|
const { execSync } = await import("node:child_process");
|
|
3523
|
-
execSync("
|
|
3560
|
+
execSync("npm install --no-fund --no-audit", {
|
|
3524
3561
|
cwd: opencodeDir,
|
|
3525
3562
|
stdio: "ignore"
|
|
3526
3563
|
});
|
|
3527
3564
|
installSpinner.stop("Dependencies installed");
|
|
3528
3565
|
} catch {
|
|
3529
|
-
installSpinner.stop("Failed to install (run manually: cd .opencode &&
|
|
3566
|
+
installSpinner.stop("Failed to install (run manually: cd .opencode && npm install)");
|
|
3530
3567
|
}
|
|
3531
3568
|
}
|
|
3532
3569
|
p.outro(color.green(`Upgraded to ${versionInfo.latest}`));
|
package/package.json
CHANGED