@sdotwinter/openclaw-deterministic 0.17.0 → 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/install.js +4 -10
- 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/install.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const os = require("os");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const crypto = require("crypto");
|
|
7
6
|
|
|
8
7
|
// -----------------------------
|
|
9
8
|
// Args
|
|
@@ -91,10 +90,6 @@ function timestamp() {
|
|
|
91
90
|
return new Date().toISOString().replace(/:/g, "-");
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
function sha256(content) {
|
|
95
|
-
return crypto.createHash("sha256").update(content).digest("hex");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
93
|
function backupSnapshot(pathsToBackup) {
|
|
99
94
|
if (DRY_RUN) {
|
|
100
95
|
console.log("[DRY-RUN] Would create backup snapshot.");
|
|
@@ -124,12 +119,11 @@ function backupSnapshot(pathsToBackup) {
|
|
|
124
119
|
function copyWithVersionStamp(src, dest) {
|
|
125
120
|
const raw = readFile(src);
|
|
126
121
|
const clean = raw.replace(/^\uFEFF/, "");
|
|
127
|
-
const hash = sha256(clean);
|
|
128
|
-
|
|
129
|
-
const stamped = `${VERSION_STAMP}
|
|
130
|
-
<!-- Canonical-Hash: SHA256:${hash} -->
|
|
131
122
|
|
|
132
|
-
|
|
123
|
+
// IMPORTANT:
|
|
124
|
+
// Do NOT generate or modify canonical hash.
|
|
125
|
+
// Template already contains canonical hash header.
|
|
126
|
+
const stamped = `${VERSION_STAMP}\n${clean}`;
|
|
133
127
|
|
|
134
128
|
writeFile(dest, stamped);
|
|
135
129
|
|
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);
|