@sdotwinter/openclaw-deterministic 0.5.0 → 0.5.1
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/doctor.js +56 -35
- package/bin/install.js +79 -55
- package/package.json +1 -1
- package/templates/SOUL.deterministic.md +1 -1
package/bin/doctor.js
CHANGED
|
@@ -6,15 +6,19 @@ const path = require("path");
|
|
|
6
6
|
const HOME = process.env.HOME;
|
|
7
7
|
const workspace = path.join(HOME, ".openclaw", "workspace");
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const paths = {
|
|
10
10
|
operating: path.join(workspace, "OPERATING_RULES.md"),
|
|
11
11
|
soul: path.join(workspace, "SOUL.md"),
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
detSoul: path.join(workspace, "SOUL.deterministic.md"),
|
|
13
|
+
compactor: path.join(workspace, "skills", "memory-compactor", "SKILL.md"),
|
|
14
14
|
semantic: path.join(workspace, "memory", "semantic", "openclaw.md"),
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const MARKER_OVERLAY = "## Deterministic Governance Overlay";
|
|
18
|
+
const MARKER_OPERATING_CANON = "Deterministic Execution Contract — Hardened Overlay";
|
|
19
|
+
const MARKER_DETSOUL_CANON = "Deterministic Governance Overlay — Canonical";
|
|
20
|
+
const MARKER_COMPACTOR_CANON = "## Hybrid Trigger Model";
|
|
21
|
+
|
|
18
22
|
const HARD_LIMIT = 1200;
|
|
19
23
|
const RISK_THRESHOLD = 1020;
|
|
20
24
|
|
|
@@ -27,56 +31,73 @@ function exists(p) {
|
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
function read(p) {
|
|
35
|
+
return fs.readFileSync(p, "utf8");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// cheap, consistent estimate (good enough for thresholds)
|
|
30
39
|
function tokenEstimate(text) {
|
|
31
40
|
if (!text) return 0;
|
|
32
|
-
|
|
41
|
+
const words = text.trim().split(/\s+/).filter(Boolean).length;
|
|
42
|
+
return Math.ceil(words * 1.3);
|
|
33
43
|
}
|
|
34
44
|
|
|
45
|
+
function ok(msg) { console.log(`✅ ${msg}`); }
|
|
46
|
+
function warn(msg) { console.log(`⚠ ${msg}`); }
|
|
47
|
+
function fail(msg) { console.log(`❌ ${msg}`); }
|
|
48
|
+
|
|
35
49
|
console.log("\nRunning deterministic doctor...\n");
|
|
36
50
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
// --- Presence checks
|
|
52
|
+
exists(paths.operating) ? ok("OPERATING_RULES.md present.") : fail("OPERATING_RULES.md missing.");
|
|
53
|
+
exists(paths.detSoul) ? ok("SOUL.deterministic.md present.") : fail("SOUL.deterministic.md missing.");
|
|
54
|
+
exists(paths.compactor) ? ok("memory-compactor SKILL.md present.") : fail("memory-compactor SKILL.md missing.");
|
|
55
|
+
exists(paths.soul) ? ok("SOUL.md present.") : fail("SOUL.md missing.");
|
|
41
56
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
// If core files are missing, stop early (still exit cleanly)
|
|
58
|
+
if (!exists(paths.operating) || !exists(paths.detSoul) || !exists(paths.compactor) || !exists(paths.soul)) {
|
|
59
|
+
console.log("\nDoctor complete (incomplete install).\n");
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
45
62
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
// --- Activation checks
|
|
64
|
+
const soul = read(paths.soul);
|
|
65
|
+
if (soul.includes(MARKER_OVERLAY)) ok("Deterministic overlay ENABLED in SOUL.md.");
|
|
66
|
+
else warn("Deterministic overlay installed but NOT enabled (run: oc-deterministic enable).");
|
|
49
67
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
console.log("❌ SOUL.md missing.");
|
|
60
|
-
}
|
|
68
|
+
// --- Integrity checks (cross-file coherence)
|
|
69
|
+
const operating = read(paths.operating);
|
|
70
|
+
if (operating.includes(MARKER_OPERATING_CANON)) ok("OPERATING_RULES.md matches canonical marker.");
|
|
71
|
+
else warn("OPERATING_RULES.md marker missing (file may be customized or outdated).");
|
|
72
|
+
|
|
73
|
+
if (operating.includes("SOUL.deterministic.md")) ok("OPERATING_RULES.md references SOUL.deterministic.md.");
|
|
74
|
+
else warn("OPERATING_RULES.md does not reference SOUL.deterministic.md (recommended).");
|
|
61
75
|
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
const detSoul = read(paths.detSoul);
|
|
77
|
+
if (detSoul.includes(MARKER_DETSOUL_CANON)) ok("SOUL.deterministic.md matches canonical marker.");
|
|
78
|
+
else warn("SOUL.deterministic.md marker missing (file may be customized or outdated).");
|
|
79
|
+
|
|
80
|
+
const compactor = read(paths.compactor);
|
|
81
|
+
if (compactor.includes(MARKER_COMPACTOR_CANON)) ok("memory-compactor includes Hybrid Trigger Model.");
|
|
82
|
+
else warn("memory-compactor missing Hybrid Trigger Model marker (skill may be outdated).");
|
|
83
|
+
|
|
84
|
+
// --- Semantic health
|
|
85
|
+
if (exists(paths.semantic)) {
|
|
86
|
+
const semantic = read(paths.semantic);
|
|
87
|
+
const tokens = tokenEstimate(semantic);
|
|
66
88
|
|
|
67
89
|
console.log(`\nSemantic memory tokens (est): ${tokens}`);
|
|
68
90
|
|
|
69
91
|
if (tokens > HARD_LIMIT) {
|
|
70
|
-
|
|
92
|
+
warn("ABOVE HARD LIMIT (Tier C enforced for semantic operations).");
|
|
71
93
|
} else if (tokens > RISK_THRESHOLD) {
|
|
72
|
-
|
|
94
|
+
warn("Near risk threshold (85%). Semantic appends should behave as Tier C per compactor rules.");
|
|
73
95
|
} else {
|
|
74
|
-
|
|
96
|
+
ok("Semantic memory within safe bounds.");
|
|
75
97
|
}
|
|
76
98
|
} else {
|
|
77
|
-
console.log("\nℹ No semantic memory file detected.");
|
|
99
|
+
console.log("\nℹ No semantic memory file detected (ok).");
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
console.log("\nDoctor complete.\n");
|
|
81
|
-
|
|
82
103
|
process.exit(0);
|
package/bin/install.js
CHANGED
|
@@ -2,85 +2,109 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const os = require("os");
|
|
6
5
|
|
|
7
|
-
const
|
|
6
|
+
const HOME = process.env.HOME;
|
|
7
|
+
const openclawRoot = path.join(HOME, ".openclaw");
|
|
8
|
+
const workspace = path.join(openclawRoot, "workspace");
|
|
9
|
+
const backupsRoot = path.join(openclawRoot, "backups", "deterministic");
|
|
8
10
|
|
|
9
|
-
const
|
|
10
|
-
const WORKSPACE_DIR = path.join(OPENCLAW_DIR, "workspace");
|
|
11
|
-
const BACKUP_ROOT = path.join(OPENCLAW_DIR, "backups", "deterministic");
|
|
11
|
+
const tpl = (name) => path.join(__dirname, "..", "templates", name);
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const target = {
|
|
14
|
+
operating: path.join(workspace, "OPERATING_RULES.md"),
|
|
15
|
+
detSoul: path.join(workspace, "SOUL.deterministic.md"),
|
|
16
|
+
soul: path.join(workspace, "SOUL.md"),
|
|
17
|
+
compactor: path.join(workspace, "skills", "memory-compactor", "SKILL.md"),
|
|
18
|
+
};
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const OVERLAY_BLOCK = `
|
|
21
|
+
## Deterministic Governance Overlay
|
|
22
|
+
|
|
23
|
+
This system loads and adheres to SOUL.deterministic.md as a governing philosophical constraint.
|
|
24
|
+
`;
|
|
20
25
|
|
|
21
|
-
function
|
|
22
|
-
|
|
26
|
+
function exists(p) {
|
|
27
|
+
try { fs.accessSync(p); return true; } catch { return false; }
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
`# Installed by openclaw-deterministic v${pkg.version}\n` +
|
|
28
|
-
`# Installed at: ${new Date().toISOString()}\n\n` +
|
|
29
|
-
content
|
|
30
|
-
);
|
|
30
|
+
function ensureDir(p) {
|
|
31
|
+
fs.mkdirSync(p, { recursive: true });
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function
|
|
34
|
-
|
|
34
|
+
function read(p) {
|
|
35
|
+
return fs.readFileSync(p, "utf8");
|
|
36
|
+
}
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
function write(p, content) {
|
|
39
|
+
ensureDir(path.dirname(p));
|
|
40
|
+
fs.writeFileSync(p, content);
|
|
41
|
+
}
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
function copyFile(src, dst) {
|
|
44
|
+
ensureDir(path.dirname(dst));
|
|
45
|
+
fs.copyFileSync(src, dst);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
function stamp() {
|
|
49
|
+
return new Date().toISOString().replaceAll(":", "-");
|
|
50
|
+
}
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
function backupSnapshot(pathsToBackup) {
|
|
53
|
+
ensureDir(backupsRoot);
|
|
54
|
+
const snap = path.join(backupsRoot, stamp());
|
|
55
|
+
ensureDir(snap);
|
|
56
|
+
|
|
57
|
+
for (const p of pathsToBackup) {
|
|
58
|
+
if (!exists(p)) continue;
|
|
59
|
+
const rel = path.relative(openclawRoot, p); // keep structure
|
|
60
|
+
const dst = path.join(snap, rel);
|
|
61
|
+
ensureDir(path.dirname(dst));
|
|
62
|
+
fs.copyFileSync(p, dst);
|
|
63
|
+
}
|
|
48
64
|
|
|
49
|
-
|
|
65
|
+
return snap;
|
|
66
|
+
}
|
|
50
67
|
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
function installTemplates() {
|
|
69
|
+
copyFile(tpl("OPERATING_RULES.md"), target.operating);
|
|
70
|
+
console.log("Installed: OPERATING_RULES.md");
|
|
53
71
|
|
|
54
|
-
|
|
72
|
+
copyFile(tpl("SOUL.deterministic.md"), target.detSoul);
|
|
73
|
+
console.log("Installed: SOUL.deterministic.md");
|
|
55
74
|
|
|
56
|
-
|
|
75
|
+
copyFile(tpl("memory-compactor.SKILL.md"), target.compactor);
|
|
76
|
+
console.log("Installed: skills/memory-compactor/SKILL.md");
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
function
|
|
60
|
-
if (
|
|
61
|
-
console.
|
|
62
|
-
|
|
79
|
+
function bootstrapSoulIfMissing() {
|
|
80
|
+
if (exists(target.soul)) {
|
|
81
|
+
console.log("User SOUL.md exists — NOT modified.");
|
|
82
|
+
return;
|
|
63
83
|
}
|
|
64
84
|
|
|
65
|
-
|
|
66
|
-
|
|
85
|
+
console.log("No SOUL.md detected — bootstrapping fresh SOUL.md with deterministic overlay.");
|
|
86
|
+
write(target.soul, OVERLAY_BLOCK.trim() + "\n");
|
|
87
|
+
console.log("Created: SOUL.md (deterministic overlay enabled by default)");
|
|
88
|
+
}
|
|
67
89
|
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
if (!exists(openclawRoot)) {
|
|
91
|
+
console.error("OpenClaw not found at ~/.openclaw");
|
|
92
|
+
console.error("Install OpenClaw first, then rerun oc-deterministic install.");
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
70
95
|
|
|
71
|
-
|
|
72
|
-
console.
|
|
96
|
+
if (!exists(workspace)) {
|
|
97
|
+
console.error("OpenClaw workspace missing at ~/.openclaw/workspace");
|
|
98
|
+
console.error("OpenClaw may not be fully initialized. Run `openclaw onboard` then retry.");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
73
101
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"memory-compactor.SKILL.md",
|
|
78
|
-
path.join("skills", "memory-compactor", "SKILL.md"),
|
|
79
|
-
backupDir
|
|
80
|
-
);
|
|
102
|
+
console.log("Creating deterministic backup snapshot...");
|
|
103
|
+
const snap = backupSnapshot([target.operating, target.detSoul, target.soul, target.compactor]);
|
|
104
|
+
console.log(`Backup location: ${snap}`);
|
|
81
105
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
106
|
+
installTemplates();
|
|
107
|
+
bootstrapSoulIfMissing();
|
|
85
108
|
|
|
86
|
-
|
|
109
|
+
console.log("\nDeterministic governance installed successfully.");
|
|
110
|
+
process.exit(0);
|
package/package.json
CHANGED