principles-disciple 1.39.0 → 1.41.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/esbuild.config.js +32 -3
- package/openclaw.plugin.json +1 -1
- package/package.json +6 -5
- package/scripts/compile-principles.mjs +94 -0
- package/scripts/sync-plugin.mjs +121 -261
- package/src/core/principle-compiler/code-validator.ts +120 -0
- package/src/core/principle-compiler/compiler.ts +242 -0
- package/src/core/principle-compiler/index.ts +10 -0
- package/src/core/principle-compiler/ledger-registrar.ts +107 -0
- package/src/core/principle-compiler/template-generator.ts +108 -0
- package/src/core/reflection/reflection-context.ts +228 -0
- package/src/service/central-database.ts +10 -0
- package/tests/core/code-validator.test.ts +197 -0
- package/tests/core/event-log.test.ts +2 -1
- package/tests/core/ledger-registrar.test.ts +232 -0
- package/tests/core/pain-score.property.test.ts +10 -196
- package/tests/core/principle-compiler.test.ts +348 -0
- package/tests/core/reflection-context.test.ts +356 -0
- package/tests/core/template-generator.test.ts +101 -0
- package/tests/globalSetup.ts +38 -0
- package/tests/hooks/pain.test.ts +2 -1
- package/tests/hooks/subagent.test.ts +3 -1
- package/tests/integration/principle-compiler-e2e.test.ts +335 -0
- package/tests/service/evolution-worker.nocturnal.test.ts +2 -1
- package/tests/service/evolution-worker.timeout.test.ts +4 -3
- package/tests/service/nocturnal-runtime.test.ts +6 -3
- package/vitest.config.ts +3 -23
package/esbuild.config.js
CHANGED
|
@@ -25,6 +25,7 @@ function copyRecursive(src, dest) {
|
|
|
25
25
|
|
|
26
26
|
async function bundlePlugin() {
|
|
27
27
|
try {
|
|
28
|
+
// 1. Build the main bundle for OpenClaw
|
|
28
29
|
await build({
|
|
29
30
|
entryPoints: ['src/index.ts'],
|
|
30
31
|
outfile: 'dist/bundle.js',
|
|
@@ -44,7 +45,35 @@ async function bundlePlugin() {
|
|
|
44
45
|
metafile: true,
|
|
45
46
|
});
|
|
46
47
|
|
|
47
|
-
console.log('
|
|
48
|
+
console.log('Main bundle created: dist/bundle.js');
|
|
49
|
+
|
|
50
|
+
// 2. Build core tools for CLI usage (bootstrap-rules, etc)
|
|
51
|
+
// We keep these separate and un-minified for easier debugging and CLI importing
|
|
52
|
+
await build({
|
|
53
|
+
entryPoints: {
|
|
54
|
+
'core/bootstrap-rules': 'src/core/bootstrap-rules.ts',
|
|
55
|
+
'core/principle-tree-ledger': 'src/core/principle-tree-ledger.ts',
|
|
56
|
+
'core/principle-training-state': 'src/core/principle-training-state.ts',
|
|
57
|
+
'core/principle-compiler/index': 'src/core/principle-compiler/index.ts',
|
|
58
|
+
'core/trajectory/index': 'src/core/trajectory.ts',
|
|
59
|
+
},
|
|
60
|
+
outdir: 'dist',
|
|
61
|
+
bundle: true,
|
|
62
|
+
platform: 'node',
|
|
63
|
+
target: 'node20',
|
|
64
|
+
format: 'esm',
|
|
65
|
+
outbase: 'src',
|
|
66
|
+
external: [
|
|
67
|
+
'openclaw',
|
|
68
|
+
'@openclaw/sdk',
|
|
69
|
+
'@openclaw/plugin-kit',
|
|
70
|
+
'better-sqlite3',
|
|
71
|
+
],
|
|
72
|
+
sourcemap: false,
|
|
73
|
+
minify: false,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log('Core CLI tools built in dist/core/');
|
|
48
77
|
|
|
49
78
|
const staticFiles = ['templates', 'openclaw.plugin.json'];
|
|
50
79
|
const distDir = 'dist';
|
|
@@ -65,9 +94,9 @@ async function bundlePlugin() {
|
|
|
65
94
|
console.log(`Copied: ${file} -> dist/${file}`);
|
|
66
95
|
}
|
|
67
96
|
|
|
68
|
-
console.log('\nPlugin
|
|
97
|
+
console.log('\nPlugin build ready for distribution.');
|
|
69
98
|
} catch (error) {
|
|
70
|
-
console.error('
|
|
99
|
+
console.error('Build failed:', error);
|
|
71
100
|
process.exit(1);
|
|
72
101
|
}
|
|
73
102
|
}
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "principles-disciple",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "Native OpenClaw plugin for Principles Disciple",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/bundle.js",
|
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
"build:web": "node scripts/build-web.mjs",
|
|
31
31
|
"build:bundle": "node esbuild.config.js && node scripts/build-web.mjs",
|
|
32
32
|
"build:production": "node esbuild.config.js --production && node scripts/build-web.mjs --production && node scripts/verify-build.mjs",
|
|
33
|
-
"test": "vitest run
|
|
34
|
-
"test:unit": "vitest run --
|
|
35
|
-
"test:integration": "vitest run
|
|
36
|
-
"test:coverage": "vitest run --
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:unit": "vitest run tests/core tests/service tests/hooks tests/commands tests/utils tests/scripts --exclude tests/commands/evolver.test.ts",
|
|
35
|
+
"test:integration": "vitest run tests/integration/",
|
|
36
|
+
"test:coverage": "vitest run --coverage",
|
|
37
37
|
"test:all": "vitest run",
|
|
38
38
|
"lint": "eslint src/",
|
|
39
39
|
"bootstrap-rules": "node scripts/bootstrap-rules.mjs",
|
|
40
|
+
"compile-principles": "node scripts/compile-principles.mjs",
|
|
40
41
|
"validate-live-path": "tsx scripts/validate-live-path.ts"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Principle Compiler CLI
|
|
5
|
+
*
|
|
6
|
+
* Compiles eligible principles (those derived from pain events) into
|
|
7
|
+
* auto-generated rules via the PrincipleCompiler pipeline.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* npm run compile-principles
|
|
11
|
+
* WORKSPACE_DIR=/path/to/workspace npm run compile-principles
|
|
12
|
+
* node scripts/compile-principles.mjs /path/to/workspace
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { join, dirname } from 'path';
|
|
16
|
+
import { fileURLToPath } from 'url';
|
|
17
|
+
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = dirname(__filename);
|
|
20
|
+
|
|
21
|
+
// Resolve workspace directory: CLI arg > env var > default
|
|
22
|
+
const WORKSPACE_DIR = process.argv[2]
|
|
23
|
+
|| process.env.WORKSPACE_DIR
|
|
24
|
+
|| join(process.env.HOME, '.openclaw', 'workspace-main');
|
|
25
|
+
|
|
26
|
+
const STATE_DIR = join(WORKSPACE_DIR, '.state');
|
|
27
|
+
|
|
28
|
+
async function run() {
|
|
29
|
+
console.log('Principle Compiler CLI');
|
|
30
|
+
console.log(` Workspace: ${WORKSPACE_DIR}`);
|
|
31
|
+
console.log(` State dir: ${STATE_DIR}`);
|
|
32
|
+
|
|
33
|
+
let compilerModule, trajectoryModule;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
compilerModule = await import('../dist/core/principle-compiler/index.js');
|
|
37
|
+
} catch {
|
|
38
|
+
console.error('PrincipleCompiler module not found in dist/. Build first: node esbuild.config.js');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
trajectoryModule = await import('../dist/core/trajectory/index.js');
|
|
44
|
+
} catch {
|
|
45
|
+
console.error('TrajectoryDatabase module not found in dist/. Build first: node esbuild.config.js');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const { PrincipleCompiler } = compilerModule;
|
|
50
|
+
const { TrajectoryDatabase } = trajectoryModule;
|
|
51
|
+
|
|
52
|
+
let trajectory;
|
|
53
|
+
try {
|
|
54
|
+
trajectory = new TrajectoryDatabase({ workspaceDir: WORKSPACE_DIR });
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.error(`Failed to open trajectory database: ${err.message}`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const compiler = new PrincipleCompiler(STATE_DIR, trajectory);
|
|
62
|
+
|
|
63
|
+
console.log('\nCompiling eligible principles...');
|
|
64
|
+
const results = compiler.compileAll();
|
|
65
|
+
|
|
66
|
+
const succeeded = results.filter(r => r.success);
|
|
67
|
+
const failed = results.filter(r => !r.success);
|
|
68
|
+
|
|
69
|
+
console.log(`\nResults: ${succeeded.length} succeeded, ${failed.length} failed`);
|
|
70
|
+
|
|
71
|
+
for (const r of succeeded) {
|
|
72
|
+
console.log(` + ${r.principleId} -> rule ${r.ruleId} (impl: ${r.implementationId})`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const r of failed) {
|
|
76
|
+
console.log(` x ${r.principleId}: ${r.reason}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (results.length === 0) {
|
|
80
|
+
console.log(' No eligible principles found for compilation.');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (failed.length > 0) {
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
86
|
+
} finally {
|
|
87
|
+
trajectory.dispose();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
run().catch((err) => {
|
|
92
|
+
console.error(`Fatal: ${err.message}`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|