@sdotwinter/openclaw-deterministic 0.5.1 → 0.6.0
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/audit.js +86 -0
- package/bin/cli.js +5 -0
- package/package.json +1 -1
package/bin/audit.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const HOME = process.env.HOME;
|
|
8
|
+
const workspace = path.join(HOME, ".openclaw", "workspace");
|
|
9
|
+
|
|
10
|
+
const files = [
|
|
11
|
+
{
|
|
12
|
+
name: "OPERATING_RULES.md",
|
|
13
|
+
installed: path.join(workspace, "OPERATING_RULES.md"),
|
|
14
|
+
template: path.join(__dirname, "..", "templates", "OPERATING_RULES.md"),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "SOUL.deterministic.md",
|
|
18
|
+
installed: path.join(workspace, "SOUL.deterministic.md"),
|
|
19
|
+
template: path.join(__dirname, "..", "templates", "SOUL.deterministic.md"),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "memory-compactor SKILL.md",
|
|
23
|
+
installed: path.join(workspace, "skills", "memory-compactor", "SKILL.md"),
|
|
24
|
+
template: path.join(__dirname, "..", "templates", "memory-compactor.SKILL.md"),
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function exists(p) {
|
|
29
|
+
try {
|
|
30
|
+
fs.accessSync(p);
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log("\nRunning deterministic audit...\n");
|
|
38
|
+
|
|
39
|
+
let driftFound = false;
|
|
40
|
+
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
if (!exists(file.installed)) {
|
|
43
|
+
console.log(`❌ ${file.name} missing in workspace.`);
|
|
44
|
+
driftFound = true;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!exists(file.template)) {
|
|
49
|
+
console.log(`❌ Template missing for ${file.name}.`);
|
|
50
|
+
driftFound = true;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const diff = execSync(
|
|
56
|
+
`diff -u "${file.template}" "${file.installed}"`,
|
|
57
|
+
{ stdio: "pipe" }
|
|
58
|
+
).toString();
|
|
59
|
+
|
|
60
|
+
if (diff.trim().length === 0) {
|
|
61
|
+
console.log(`✅ ${file.name} matches template.`);
|
|
62
|
+
} else {
|
|
63
|
+
console.log(`⚠ Drift detected in ${file.name}:\n`);
|
|
64
|
+
console.log(diff);
|
|
65
|
+
driftFound = true;
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
if (err.status === 1) {
|
|
69
|
+
console.log(`⚠ Drift detected in ${file.name}:\n`);
|
|
70
|
+
console.log(err.stdout.toString());
|
|
71
|
+
driftFound = true;
|
|
72
|
+
} else {
|
|
73
|
+
console.log(`❌ Error auditing ${file.name}`);
|
|
74
|
+
driftFound = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!driftFound) {
|
|
80
|
+
console.log("\nNo drift detected. Files match canonical templates.");
|
|
81
|
+
} else {
|
|
82
|
+
console.log("\nAudit complete. Drift detected.");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log("");
|
|
86
|
+
process.exit(0);
|
package/bin/cli.js
CHANGED
|
@@ -30,6 +30,10 @@ switch (command) {
|
|
|
30
30
|
case "revert":
|
|
31
31
|
require(path.join(__dirname, "revert"));
|
|
32
32
|
break;
|
|
33
|
+
|
|
34
|
+
case "audit":
|
|
35
|
+
require(path.join(__dirname, "audit"));
|
|
36
|
+
break;
|
|
33
37
|
|
|
34
38
|
case "--version":
|
|
35
39
|
case "-v":
|
|
@@ -57,6 +61,7 @@ function showHelp() {
|
|
|
57
61
|
console.log(" oc-deterministic install");
|
|
58
62
|
console.log(" oc-deterministic enable");
|
|
59
63
|
console.log(" oc-deterministic revert");
|
|
64
|
+
console.log(" oc-deterministic audit");
|
|
60
65
|
console.log(" oc-deterministic --version");
|
|
61
66
|
console.log(" oc-deterministic --help\n");
|
|
62
67
|
}
|