@sdotwinter/openclaw-deterministic 0.17.1 → 0.17.2
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/bin/cli.js +6 -1
- package/bin/upgrade.js +84 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -30,11 +30,15 @@ switch (command) {
|
|
|
30
30
|
case "revert":
|
|
31
31
|
require(path.join(__dirname, "revert"));
|
|
32
32
|
break;
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
case "audit":
|
|
35
35
|
require(path.join(__dirname, "audit"));
|
|
36
36
|
break;
|
|
37
37
|
|
|
38
|
+
case "upgrade":
|
|
39
|
+
require(path.join(__dirname, "upgrade"));
|
|
40
|
+
break;
|
|
41
|
+
|
|
38
42
|
case "--version":
|
|
39
43
|
case "-v":
|
|
40
44
|
console.log(`openclaw-deterministic v${pkg.version}`);
|
|
@@ -59,6 +63,7 @@ function showHelp() {
|
|
|
59
63
|
console.log(" oc-deterministic init");
|
|
60
64
|
console.log(" oc-deterministic doctor");
|
|
61
65
|
console.log(" oc-deterministic install");
|
|
66
|
+
console.log(" oc-deterministic upgrade");
|
|
62
67
|
console.log(" oc-deterministic enable");
|
|
63
68
|
console.log(" oc-deterministic revert");
|
|
64
69
|
console.log(" oc-deterministic audit");
|
package/bin/upgrade.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const DRY_RUN = args.includes("--dry-run");
|
|
9
|
+
|
|
10
|
+
const pkg = require(path.join(__dirname, "..", "package.json"));
|
|
11
|
+
const CLI_VERSION = pkg.version;
|
|
12
|
+
|
|
13
|
+
const home = os.homedir();
|
|
14
|
+
const openclawRoot = path.join(home, ".openclaw");
|
|
15
|
+
const workspace = path.join(openclawRoot, "workspace");
|
|
16
|
+
|
|
17
|
+
const VERSION_REGEX = /Installed by openclaw-deterministic v([0-9.]+)/;
|
|
18
|
+
|
|
19
|
+
const files = [
|
|
20
|
+
"OPERATING_RULES.md",
|
|
21
|
+
"SOUL.deterministic.md",
|
|
22
|
+
"skills/memory-compactor/SKILL.md",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function exists(p) {
|
|
26
|
+
try {
|
|
27
|
+
fs.accessSync(p);
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function read(p) {
|
|
35
|
+
return fs.readFileSync(p, "utf8");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function write(p, content) {
|
|
39
|
+
if (DRY_RUN) {
|
|
40
|
+
console.log(`[DRY-RUN] Would write: ${p}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
fs.writeFileSync(p, content, "utf8");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getInstalledVersion(content) {
|
|
47
|
+
const match = content.match(VERSION_REGEX);
|
|
48
|
+
return match ? match[1] : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function upgradeFile(relPath) {
|
|
52
|
+
const targetPath = path.join(workspace, relPath);
|
|
53
|
+
const templatePath = path.join(__dirname, "..", "templates", relPath);
|
|
54
|
+
|
|
55
|
+
if (!exists(targetPath)) return;
|
|
56
|
+
|
|
57
|
+
const installed = read(targetPath);
|
|
58
|
+
const template = read(templatePath);
|
|
59
|
+
|
|
60
|
+
const installedVersion = getInstalledVersion(installed);
|
|
61
|
+
|
|
62
|
+
if (installedVersion === CLI_VERSION) {
|
|
63
|
+
console.log(`✓ ${relPath} already up to date.`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`Upgrading ${relPath} from v${installedVersion} → v${CLI_VERSION}`);
|
|
68
|
+
|
|
69
|
+
const stamped = `<!-- Installed by openclaw-deterministic v${CLI_VERSION} -->\n${template}`;
|
|
70
|
+
|
|
71
|
+
write(targetPath, stamped);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!exists(openclawRoot) || !exists(workspace)) {
|
|
75
|
+
console.error("OpenClaw workspace not found.");
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log(`Running deterministic upgrade → CLI v${CLI_VERSION}\n`);
|
|
80
|
+
|
|
81
|
+
files.forEach(upgradeFile);
|
|
82
|
+
|
|
83
|
+
console.log("\nUpgrade complete.\n");
|
|
84
|
+
process.exit(0);
|