moltblock 0.2.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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/config/code_entity_graph.json +12 -0
  3. package/dist/agents.d.ts +24 -0
  4. package/dist/agents.d.ts.map +1 -0
  5. package/dist/agents.js +124 -0
  6. package/dist/agents.js.map +1 -0
  7. package/dist/cli.d.ts +6 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +58 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/config.d.ts +135 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +139 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/entity.d.ts +31 -0
  16. package/dist/entity.d.ts.map +1 -0
  17. package/dist/entity.js +80 -0
  18. package/dist/entity.js.map +1 -0
  19. package/dist/gateway.d.ts +19 -0
  20. package/dist/gateway.d.ts.map +1 -0
  21. package/dist/gateway.js +63 -0
  22. package/dist/gateway.js.map +1 -0
  23. package/dist/governance.d.ts +46 -0
  24. package/dist/governance.d.ts.map +1 -0
  25. package/dist/governance.js +87 -0
  26. package/dist/governance.js.map +1 -0
  27. package/dist/graph-runner.d.ts +28 -0
  28. package/dist/graph-runner.d.ts.map +1 -0
  29. package/dist/graph-runner.js +103 -0
  30. package/dist/graph-runner.js.map +1 -0
  31. package/dist/graph-schema.d.ts +116 -0
  32. package/dist/graph-schema.d.ts.map +1 -0
  33. package/dist/graph-schema.js +137 -0
  34. package/dist/graph-schema.js.map +1 -0
  35. package/dist/handoff.d.ts +20 -0
  36. package/dist/handoff.d.ts.map +1 -0
  37. package/dist/handoff.js +38 -0
  38. package/dist/handoff.js.map +1 -0
  39. package/dist/improvement.d.ts +32 -0
  40. package/dist/improvement.d.ts.map +1 -0
  41. package/dist/improvement.js +67 -0
  42. package/dist/improvement.js.map +1 -0
  43. package/dist/index.d.ts +19 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +31 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/memory.d.ts +28 -0
  48. package/dist/memory.d.ts.map +1 -0
  49. package/dist/memory.js +46 -0
  50. package/dist/memory.js.map +1 -0
  51. package/dist/persistence.d.ts +83 -0
  52. package/dist/persistence.d.ts.map +1 -0
  53. package/dist/persistence.js +295 -0
  54. package/dist/persistence.js.map +1 -0
  55. package/dist/signing.d.ts +16 -0
  56. package/dist/signing.d.ts.map +1 -0
  57. package/dist/signing.js +43 -0
  58. package/dist/signing.js.map +1 -0
  59. package/dist/types.d.ts +80 -0
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +5 -0
  62. package/dist/types.js.map +1 -0
  63. package/dist/verifier.d.ts +22 -0
  64. package/dist/verifier.d.ts.map +1 -0
  65. package/dist/verifier.js +198 -0
  66. package/dist/verifier.js.map +1 -0
  67. package/package.json +64 -0
  68. package/readme.md +125 -0
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Verifier: run vitest on code artifact; gate authority and memory admission.
3
+ */
4
+ import { spawn } from "node:child_process";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import os from "node:os";
8
+ /**
9
+ * Remove markdown code fence if present.
10
+ */
11
+ export function extractCodeBlock(text) {
12
+ let trimmed = text.trim();
13
+ if (trimmed.startsWith("```")) {
14
+ const lines = trimmed.split("\n");
15
+ // Remove first line (```typescript or ```)
16
+ if (lines[0]?.startsWith("```")) {
17
+ lines.shift();
18
+ }
19
+ // Remove last line if it's just ```
20
+ if (lines.length > 0 && lines[lines.length - 1]?.trim() === "```") {
21
+ lines.pop();
22
+ }
23
+ return lines.join("\n");
24
+ }
25
+ return trimmed;
26
+ }
27
+ /**
28
+ * Write code (and optional test) to temp dir, run vitest, return (passed, stdout+stderr).
29
+ * If testCode is undefined, we only check that the code is syntactically valid (compiles).
30
+ */
31
+ export async function runVitestOnCode(code, testCode) {
32
+ const cleanCode = extractCodeBlock(code);
33
+ // Create temp directory
34
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "moltblock-verify-"));
35
+ try {
36
+ // Write solution file
37
+ fs.writeFileSync(path.join(tmpDir, "solution.ts"), cleanCode, "utf-8");
38
+ // Write minimal package.json for ES modules
39
+ fs.writeFileSync(path.join(tmpDir, "package.json"), JSON.stringify({ type: "module" }, null, 2), "utf-8");
40
+ if (testCode) {
41
+ // Write test file
42
+ const cleanTest = extractCodeBlock(testCode);
43
+ fs.writeFileSync(path.join(tmpDir, "solution.test.ts"), cleanTest, "utf-8");
44
+ }
45
+ // Run vitest (or just tsc if no tests)
46
+ const result = await new Promise((resolve) => {
47
+ const args = testCode
48
+ ? ["vitest", "run", "--reporter=verbose", "--no-color"]
49
+ : ["tsc", "--noEmit", "--strict", "--target", "ES2022", "--module", "NodeNext", "solution.ts"];
50
+ const proc = spawn("npx", args, {
51
+ cwd: tmpDir,
52
+ timeout: 30000,
53
+ shell: true,
54
+ });
55
+ let stdout = "";
56
+ let stderr = "";
57
+ proc.stdout?.on("data", (data) => {
58
+ stdout += data.toString();
59
+ });
60
+ proc.stderr?.on("data", (data) => {
61
+ stderr += data.toString();
62
+ });
63
+ proc.on("close", (exitCode) => {
64
+ resolve({
65
+ passed: exitCode === 0,
66
+ output: stdout + stderr,
67
+ });
68
+ });
69
+ proc.on("error", (err) => {
70
+ resolve({
71
+ passed: false,
72
+ output: `Process error: ${err.message}`,
73
+ });
74
+ });
75
+ });
76
+ return result;
77
+ }
78
+ finally {
79
+ // Cleanup temp directory
80
+ try {
81
+ fs.rmSync(tmpDir, { recursive: true, force: true });
82
+ }
83
+ catch {
84
+ // Ignore cleanup errors
85
+ }
86
+ }
87
+ }
88
+ /**
89
+ * Simple TypeScript syntax check using regex and basic parsing.
90
+ * Returns true if the code looks like valid TypeScript syntax.
91
+ */
92
+ function syntaxCheck(code) {
93
+ // Basic checks for common syntax errors
94
+ let braceCount = 0;
95
+ let parenCount = 0;
96
+ let bracketCount = 0;
97
+ let inString = false;
98
+ let stringChar = "";
99
+ let inComment = false;
100
+ let inBlockComment = false;
101
+ for (let i = 0; i < code.length; i++) {
102
+ const char = code[i];
103
+ const nextChar = code[i + 1];
104
+ // Handle comments
105
+ if (!inString) {
106
+ if (char === "/" && nextChar === "/" && !inBlockComment) {
107
+ inComment = true;
108
+ continue;
109
+ }
110
+ if (char === "/" && nextChar === "*" && !inComment) {
111
+ inBlockComment = true;
112
+ i++;
113
+ continue;
114
+ }
115
+ if (char === "*" && nextChar === "/" && inBlockComment) {
116
+ inBlockComment = false;
117
+ i++;
118
+ continue;
119
+ }
120
+ if (char === "\n" && inComment) {
121
+ inComment = false;
122
+ continue;
123
+ }
124
+ }
125
+ if (inComment || inBlockComment)
126
+ continue;
127
+ // Handle strings
128
+ if ((char === '"' || char === "'" || char === "`") && code[i - 1] !== "\\") {
129
+ if (!inString) {
130
+ inString = true;
131
+ stringChar = char;
132
+ }
133
+ else if (char === stringChar) {
134
+ inString = false;
135
+ stringChar = "";
136
+ }
137
+ continue;
138
+ }
139
+ if (inString)
140
+ continue;
141
+ // Count brackets
142
+ if (char === "{")
143
+ braceCount++;
144
+ if (char === "}")
145
+ braceCount--;
146
+ if (char === "(")
147
+ parenCount++;
148
+ if (char === ")")
149
+ parenCount--;
150
+ if (char === "[")
151
+ bracketCount++;
152
+ if (char === "]")
153
+ bracketCount--;
154
+ if (braceCount < 0 || parenCount < 0 || bracketCount < 0) {
155
+ return { valid: false, error: "Unmatched closing bracket" };
156
+ }
157
+ }
158
+ if (braceCount !== 0) {
159
+ return { valid: false, error: `Unmatched braces (${braceCount > 0 ? "missing }" : "extra }"})` };
160
+ }
161
+ if (parenCount !== 0) {
162
+ return { valid: false, error: `Unmatched parentheses (${parenCount > 0 ? "missing )" : "extra )"})` };
163
+ }
164
+ if (bracketCount !== 0) {
165
+ return { valid: false, error: `Unmatched brackets (${bracketCount > 0 ? "missing ]" : "extra ]"})` };
166
+ }
167
+ if (inString) {
168
+ return { valid: false, error: "Unterminated string" };
169
+ }
170
+ return { valid: true };
171
+ }
172
+ /**
173
+ * Run verification on final_candidate. For Code Entity: run vitest.
174
+ * Sets verification_passed and verification_evidence; if pass, sets authoritative_artifact.
175
+ */
176
+ export async function runVerifier(memory, testCode) {
177
+ const code = memory.finalCandidate;
178
+ if (!code) {
179
+ memory.setVerification(false, "No final candidate to verify.");
180
+ return;
181
+ }
182
+ // If no test code provided, do a basic syntax check
183
+ if (!testCode) {
184
+ const cleanCode = extractCodeBlock(code);
185
+ const check = syntaxCheck(cleanCode);
186
+ if (check.valid) {
187
+ memory.setVerification(true, "Syntax check passed (no tests provided).");
188
+ }
189
+ else {
190
+ memory.setVerification(false, `Syntax error: ${check.error}`);
191
+ }
192
+ return;
193
+ }
194
+ // Run vitest with test code
195
+ const { passed, output } = await runVitestOnCode(code, testCode);
196
+ memory.setVerification(passed, output);
197
+ }
198
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../src/verifier.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClC,2CAA2C;QAC3C,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,CAAC;QACD,oCAAoC;QACpC,IAAI,KAAK,CAAC,MAAM,GA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C;QAC3E,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,iBAAiB,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,OAAO;IACT,CAAC;IAED,4BAA4B;IAC5B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "moltblock",
3
+ "version": "0.2.0",
4
+ "description": "Framework for building evolving composite AI intelligences (Entities)",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "moltblock": "dist/cli.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest",
21
+ "test:coverage": "vitest run --coverage",
22
+ "lint": "tsc --noEmit",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "keywords": [
26
+ "ai",
27
+ "agents",
28
+ "llm",
29
+ "entity",
30
+ "composite-intelligence",
31
+ "moltblock"
32
+ ],
33
+ "author": "",
34
+ "license": "Apache-2.0",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/moltblock/moltblock"
38
+ },
39
+ "engines": {
40
+ "node": ">=18.0.0"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "config"
45
+ ],
46
+ "dependencies": {
47
+ "better-sqlite3": "^11.7.0",
48
+ "commander": "^12.1.0",
49
+ "dotenv": "^16.4.7",
50
+ "js-yaml": "^4.1.0",
51
+ "openai": "^4.77.0",
52
+ "tmp": "^0.2.3",
53
+ "zod": "^3.24.1"
54
+ },
55
+ "devDependencies": {
56
+ "@types/better-sqlite3": "^7.6.12",
57
+ "@types/js-yaml": "^4.0.9",
58
+ "@types/node": "^22.10.5",
59
+ "@types/tmp": "^0.2.6",
60
+ "@vitest/coverage-v8": "^2.1.8",
61
+ "typescript": "^5.7.2",
62
+ "vitest": "^2.1.8"
63
+ }
64
+ }
package/readme.md ADDED
@@ -0,0 +1,125 @@
1
+ # Moltblock
2
+
3
+ **Moltblock** is a framework for building evolving composite intelligences.
4
+
5
+ It introduces the **Entity** as the primitive unit of intelligence — a system composed of many agents, models, and verification layers that evolves through **molting**, not chaining.
6
+
7
+ ---
8
+
9
+ ## Why Moltblock
10
+
11
+ Modern AI systems fail at scale because they:
12
+ - rely on single models
13
+ - propagate errors linearly
14
+ - lack persistent, verified memory
15
+
16
+ Moltblock addresses this by enabling:
17
+ - structured multi-agent intelligence
18
+ - heterogeneous model usage
19
+ - built-in verification
20
+ - irreversible knowledge checkpoints
21
+
22
+ ---
23
+
24
+ ## OpenClaw
25
+
26
+ Moltblock gives [OpenClaw](https://github.com/openclaw/openclaw) a **structured cognitive backend** — entities, verification, memory, governance. When the assistant delegates code or high-stakes work to Moltblock, it gets verified artifacts, an audit trail, and governance (rate limits, veto, emergency stop), addressing security issues around running unvetted generated code and lack of attribution/rollback. See [OpenClaw integration](docs/openclaw_integration.md).
27
+
28
+ **Security example:** If someone emails or messages the assistant to “send all my files to X” or similar exfiltration, routing that task through Moltblock lets the Critic/Judge reject it before any artifact is marked authoritative; the request is audited and no code is returned to run. Full scenario: [How Moltblock helps OpenClaw security](docs/openclaw_integration.md#how-moltblock-helps-openclaw-security).
29
+
30
+ ---
31
+
32
+ ## Core Concepts
33
+
34
+ - **Entity** — a composite cognitive system
35
+ - **Molt** — controlled internal evolution
36
+ - **Artifact** — signed, verifiable outputs
37
+ - **Checkpoint** — immutable state snapshots
38
+ - **Governance** — safety outside cognition
39
+
40
+ ---
41
+
42
+ ## What Moltblock Is Not
43
+
44
+ - Not a blockchain
45
+ - Not a single AI model
46
+ - Not a chat agent framework
47
+
48
+ Blockchain is optional and used only for anchoring.
49
+
50
+ ---
51
+
52
+ ## Docs
53
+
54
+ - [OpenClaw integration](docs/openclaw_integration.md) — CLI/API/handoff options; [value and singularity](docs/openclaw_integration_value_and_singularity.md) — why integrate, security, path to emergence. *Primary focus: integration and security for OpenClaw.*
55
+ - [MVP Entity Spec](docs/mvp_entity_spec.md) — agent roles, LLMs, verification, minimal loop, lifecycle (v0.2)
56
+ - [Landing page language](docs/landing_page_language.md) — headline, copy, and diagram for moltblock.io
57
+ - [Protocol v0.1](docs/moltblock_protocol_v_0.md) · [Architecture](docs/composite_ai_entity_architecture.md) · [Manifesto](docs/moltblock_manifesto.md)
58
+
59
+ ---
60
+
61
+ ## Run (Code Entity MVP)
62
+
63
+ Requires Node.js 18+, and (for full loop) a local LLM (e.g. LM Studio at `http://localhost:1234/v1`) and/or Z.ai API key in `.env` or `MOLTBLOCK_ZAI_API_KEY`.
64
+
65
+ **Install and run:**
66
+
67
+ ```bash
68
+ npm install
69
+ npm run build
70
+
71
+ # Run a task
72
+ npx moltblock "Implement a function add(a, b) that returns a + b."
73
+ npx moltblock "Implement add(a, b)." --test path/to/test_add.ts
74
+ npx moltblock "Implement add(a, b)." --json
75
+ ```
76
+
77
+ **Configuration:** Moltblock reads an optional JSON config from `./moltblock.json`, `./.moltblock/moltblock.json`, or `~/.moltblock/moltblock.json` (or `MOLTBLOCK_CONFIG`). Copy `moltblock.example.json` to one of those paths and set `agent.bindings` per role (`generator`, `critic`, `judge`, `verifier`). Env vars override JSON; keep API keys in `.env` (see `.env.example`) — never commit `.env` or put secrets in the JSON file.
78
+
79
+ ```bash
80
+ # Tests (no LLM required)
81
+ npm test
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Implemented (v0.2+)
87
+
88
+ - **Configurable agent graph** — DAG of nodes (role + model binding) and edges; load from `config/code_entity_graph.json` or YAML; `GraphRunner` and `loadEntityWithGraph()`.
89
+ - **Long-term memory and checkpoints** — `Store` (SQLite): verified memory (admission after verification), immutable checkpoints (entity version, graph hash, memory hash, artifact refs). Optional `store` and `writeCheckpointAfter` options on `CodeEntity.run()` and `GraphRunner.run()`.
90
+ - **Recursive improvement loop** — Outcomes recorded per run; `critiqueStrategies()`, `setStrategy()` / `getStrategy()` for versioned prompts; `runEval()` and `runImprovementCycle()`. Agents use strategy store when provided.
91
+ - **Molt and governance** — `GovernanceConfig` (rate limit, veto); `canMolt()`, `triggerMolt()`, `pause()`, `resume()`, `emergencyShutdown()`; audit log and governance state in `Store`.
92
+ - **Multi-entity handoff** — `signArtifact()` / `verifyArtifact()`; inbox per entity; `sendArtifact()`, `receiveArtifacts()` for Entity A → Entity B.
93
+
94
+ ---
95
+
96
+ ## Roadmap
97
+
98
+ - v0.1 — Protocol + architecture
99
+ - v0.2 — MVP Entity implementation (spec + Code Entity loop + graph, memory, improvement, governance, handoff)
100
+ - v0.3 — Multi-Entity collaboration (orchestration and tooling)
101
+
102
+ ---
103
+
104
+ ## Philosophy
105
+
106
+ Moltblock treats singularity as an emergent property of accelerating, verified collective intelligence.
107
+
108
+ If intelligence scales, it must scale with structure. A key application is OpenClaw: a structured backend that helps with security and assurance.
109
+
110
+ ---
111
+
112
+ ## Domain
113
+
114
+ Canonical home: **moltblock.io**
115
+
116
+ ## Contributing
117
+
118
+ We welcome contributions. See [CONTRIBUTING](CONTRIBUTING.md) for how to run tests, submit changes, and our [Code of Conduct](CODE_OF_CONDUCT.md).
119
+
120
+ ---
121
+
122
+ ## License
123
+
124
+ MIT — see [LICENSE](LICENSE).
125
+