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.
- package/LICENSE +21 -0
- package/config/code_entity_graph.json +12 -0
- package/dist/agents.d.ts +24 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +124 -0
- package/dist/agents.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +58 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +135 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +139 -0
- package/dist/config.js.map +1 -0
- package/dist/entity.d.ts +31 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +80 -0
- package/dist/entity.js.map +1 -0
- package/dist/gateway.d.ts +19 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +63 -0
- package/dist/gateway.js.map +1 -0
- package/dist/governance.d.ts +46 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +87 -0
- package/dist/governance.js.map +1 -0
- package/dist/graph-runner.d.ts +28 -0
- package/dist/graph-runner.d.ts.map +1 -0
- package/dist/graph-runner.js +103 -0
- package/dist/graph-runner.js.map +1 -0
- package/dist/graph-schema.d.ts +116 -0
- package/dist/graph-schema.d.ts.map +1 -0
- package/dist/graph-schema.js +137 -0
- package/dist/graph-schema.js.map +1 -0
- package/dist/handoff.d.ts +20 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +38 -0
- package/dist/handoff.js.map +1 -0
- package/dist/improvement.d.ts +32 -0
- package/dist/improvement.d.ts.map +1 -0
- package/dist/improvement.js +67 -0
- package/dist/improvement.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +28 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +46 -0
- package/dist/memory.js.map +1 -0
- package/dist/persistence.d.ts +83 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +295 -0
- package/dist/persistence.js.map +1 -0
- package/dist/signing.d.ts +16 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +43 -0
- package/dist/signing.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/verifier.d.ts +22 -0
- package/dist/verifier.d.ts.map +1 -0
- package/dist/verifier.js +198 -0
- package/dist/verifier.js.map +1 -0
- package/package.json +64 -0
- package/readme.md +125 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Henrique Veiga
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nodes": [
|
|
3
|
+
{"id": "generator", "role": "generator", "binding": "generator"},
|
|
4
|
+
{"id": "critic", "role": "critic", "binding": "critic"},
|
|
5
|
+
{"id": "judge", "role": "judge", "binding": "judge"}
|
|
6
|
+
],
|
|
7
|
+
"edges": [
|
|
8
|
+
{"from": "generator", "to": "critic"},
|
|
9
|
+
{"from": "critic", "to": "judge"}
|
|
10
|
+
],
|
|
11
|
+
"final_node": "judge"
|
|
12
|
+
}
|
package/dist/agents.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents: Generator, Critic, Judge. Each uses LLMGateway and reads/writes WorkingMemory.
|
|
3
|
+
*/
|
|
4
|
+
import { LLMGateway } from "./gateway.js";
|
|
5
|
+
import { WorkingMemory } from "./memory.js";
|
|
6
|
+
import { Store } from "./persistence.js";
|
|
7
|
+
/**
|
|
8
|
+
* Generator: task -> draft artifact (code).
|
|
9
|
+
*/
|
|
10
|
+
export declare function runGenerator(gateway: LLMGateway, memory: WorkingMemory, store?: Store | null): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Critic: draft + task -> critique.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runCritic(gateway: LLMGateway, memory: WorkingMemory, store?: Store | null): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Judge: task + draft + critique -> final candidate artifact.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runJudge(gateway: LLMGateway, memory: WorkingMemory, store?: Store | null): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Run a single role with task and inputs (node_id -> content from predecessors).
|
|
21
|
+
* Returns the role's output string. Used by the graph runner.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runRole(role: string, gateway: LLMGateway, task: string, inputs: Record<string, string>, longTermContext?: string, store?: Store | null): Promise<string>;
|
|
24
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAe,MAAM,kBAAkB,CAAC;AA0BtD;;GAEG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,EACrB,KAAK,GAAE,KAAK,GAAG,IAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,EACrB,KAAK,GAAE,KAAK,GAAG,IAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,EACrB,KAAK,GAAE,KAAK,GAAG,IAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,eAAe,SAAK,EACpB,KAAK,GAAE,KAAK,GAAG,IAAW,GACzB,OAAO,CAAC,MAAM,CAAC,CA0DjB"}
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents: Generator, Critic, Judge. Each uses LLMGateway and reads/writes WorkingMemory.
|
|
3
|
+
*/
|
|
4
|
+
import { getStrategy } from "./persistence.js";
|
|
5
|
+
// Default prompts; can be overridden by strategy store (recursive improvement)
|
|
6
|
+
// Note: Prompts updated to produce TypeScript instead of Python
|
|
7
|
+
const CODE_GENERATOR_SYSTEM = `You are the Generator for a Code Entity. You produce a single TypeScript implementation that satisfies the user's task. Output only valid TypeScript code, no markdown fences or extra commentary. The code will be reviewed by a Critic and then verified by running tests.`;
|
|
8
|
+
const CODE_CRITIC_SYSTEM = `You are the Critic. Review the draft code for bugs, edge cases, and style. Be concise. List specific issues and suggestions. Do not rewrite the code; only critique.`;
|
|
9
|
+
const CODE_JUDGE_SYSTEM = `You are the Judge. Given the task, the draft code, and the critique, produce the final single TypeScript implementation. Output only valid TypeScript code, no markdown fences or extra commentary. Incorporate the critic's feedback. The result will be run through vitest.`;
|
|
10
|
+
function systemPrompt(role, store) {
|
|
11
|
+
if (store) {
|
|
12
|
+
const s = getStrategy(store, role);
|
|
13
|
+
if (s) {
|
|
14
|
+
return s;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const defaults = {
|
|
18
|
+
generator: CODE_GENERATOR_SYSTEM,
|
|
19
|
+
critic: CODE_CRITIC_SYSTEM,
|
|
20
|
+
judge: CODE_JUDGE_SYSTEM,
|
|
21
|
+
};
|
|
22
|
+
return defaults[role] ?? CODE_GENERATOR_SYSTEM;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generator: task -> draft artifact (code).
|
|
26
|
+
*/
|
|
27
|
+
export async function runGenerator(gateway, memory, store = null) {
|
|
28
|
+
let userContent = memory.task;
|
|
29
|
+
if (memory.longTermContext) {
|
|
30
|
+
userContent = userContent + "\n\nRelevant verified knowledge:\n" + memory.longTermContext;
|
|
31
|
+
}
|
|
32
|
+
const system = systemPrompt("generator", store);
|
|
33
|
+
const messages = [
|
|
34
|
+
{ role: "system", content: system },
|
|
35
|
+
{ role: "user", content: userContent },
|
|
36
|
+
];
|
|
37
|
+
const draft = await gateway.complete(messages);
|
|
38
|
+
memory.setDraft(draft.trim());
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Critic: draft + task -> critique.
|
|
42
|
+
*/
|
|
43
|
+
export async function runCritic(gateway, memory, store = null) {
|
|
44
|
+
const system = systemPrompt("critic", store);
|
|
45
|
+
const messages = [
|
|
46
|
+
{ role: "system", content: system },
|
|
47
|
+
{ role: "user", content: `Task:\n${memory.task}\n\nDraft code:\n${memory.draft}` },
|
|
48
|
+
];
|
|
49
|
+
const critique = await gateway.complete(messages);
|
|
50
|
+
memory.setCritique(critique.trim());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Judge: task + draft + critique -> final candidate artifact.
|
|
54
|
+
*/
|
|
55
|
+
export async function runJudge(gateway, memory, store = null) {
|
|
56
|
+
const system = systemPrompt("judge", store);
|
|
57
|
+
const messages = [
|
|
58
|
+
{ role: "system", content: system },
|
|
59
|
+
{
|
|
60
|
+
role: "user",
|
|
61
|
+
content: `Task:\n${memory.task}\n\nDraft:\n${memory.draft}\n\nCritique:\n${memory.critique}`,
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
const final = await gateway.complete(messages);
|
|
65
|
+
memory.setFinalCandidate(final.trim());
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run a single role with task and inputs (node_id -> content from predecessors).
|
|
69
|
+
* Returns the role's output string. Used by the graph runner.
|
|
70
|
+
*/
|
|
71
|
+
export async function runRole(role, gateway, task, inputs, longTermContext = "", store = null) {
|
|
72
|
+
let userContent = task;
|
|
73
|
+
if (longTermContext) {
|
|
74
|
+
userContent = task + "\n\nRelevant verified knowledge:\n" + longTermContext;
|
|
75
|
+
}
|
|
76
|
+
if (role === "generator") {
|
|
77
|
+
const system = systemPrompt("generator", store);
|
|
78
|
+
const messages = [
|
|
79
|
+
{ role: "system", content: system },
|
|
80
|
+
{ role: "user", content: userContent },
|
|
81
|
+
];
|
|
82
|
+
return (await gateway.complete(messages)).trim();
|
|
83
|
+
}
|
|
84
|
+
if (role === "critic") {
|
|
85
|
+
const draft = inputs["generator"] ?? "";
|
|
86
|
+
let content = `Task:\n${task}\n\nDraft code:\n${draft}`;
|
|
87
|
+
if (longTermContext) {
|
|
88
|
+
content = content + "\n\nRelevant verified knowledge:\n" + longTermContext;
|
|
89
|
+
}
|
|
90
|
+
const system = systemPrompt("critic", store);
|
|
91
|
+
const messages = [
|
|
92
|
+
{ role: "system", content: system },
|
|
93
|
+
{ role: "user", content: content },
|
|
94
|
+
];
|
|
95
|
+
return (await gateway.complete(messages)).trim();
|
|
96
|
+
}
|
|
97
|
+
if (role === "judge") {
|
|
98
|
+
const draft = inputs["generator"] ?? "";
|
|
99
|
+
const critique = inputs["critic"] ?? "";
|
|
100
|
+
let content = `Task:\n${task}\n\nDraft:\n${draft}\n\nCritique:\n${critique}`;
|
|
101
|
+
if (longTermContext) {
|
|
102
|
+
content = content + "\n\nRelevant verified knowledge:\n" + longTermContext;
|
|
103
|
+
}
|
|
104
|
+
const system = systemPrompt("judge", store);
|
|
105
|
+
const messages = [
|
|
106
|
+
{ role: "system", content: system },
|
|
107
|
+
{ role: "user", content: content },
|
|
108
|
+
];
|
|
109
|
+
return (await gateway.complete(messages)).trim();
|
|
110
|
+
}
|
|
111
|
+
if (role === "router") {
|
|
112
|
+
// Passthrough: route to first pipeline (single pipeline = no-op)
|
|
113
|
+
const messages = [
|
|
114
|
+
{
|
|
115
|
+
role: "system",
|
|
116
|
+
content: "You are a Router. Classify the task in one word: code, research, or other. Reply with only that word.",
|
|
117
|
+
},
|
|
118
|
+
{ role: "user", content: task },
|
|
119
|
+
];
|
|
120
|
+
return (await gateway.complete(messages)).trim();
|
|
121
|
+
}
|
|
122
|
+
throw new Error(`Unknown role for graph: ${role}`);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAS,WAAW,EAAE,MAAM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AAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,OAAO,GAAG,UAAU,IAAI,eAAe,KAAK,kBAAkB,QAAQ,EAAE,CAAC;QAC7E,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,GAAG,OAAO,GAAG,oCAAoC,GAAG,eAAe,CAAC;QAC7E,CAAC;QACD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAkB;YAC9B,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE;YACnC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE;SACnC,CAAC;QACF,OAAO,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,CAAC;IAED,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,iEAAiE;QACjE,MAAM,QAAQ,GAAkB;YAC9B;gBACE,IAAI,EAAE,QAAQ;gBACd,OAAO,EACL,uGAAuG;aAC1G;YACD,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;SAChC,CAAC;QACF,OAAO,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI: run one Code Entity task.
|
|
4
|
+
*/
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { program } from "commander";
|
|
7
|
+
import { CodeEntity } from "./entity.js";
|
|
8
|
+
import { defaultCodeEntityBindings } from "./config.js";
|
|
9
|
+
async function main() {
|
|
10
|
+
program
|
|
11
|
+
.name("moltblock")
|
|
12
|
+
.description("Moltblock Code Entity — one task through the loop.")
|
|
13
|
+
.argument("<task>", "Task description (e.g. 'Implement a function add(a,b) that returns a+b.')")
|
|
14
|
+
.option("-t, --test <path>", "Path to file containing test code (e.g. vitest test module). If omitted, only syntax check.")
|
|
15
|
+
.option("--json", "Output result as JSON (draft, critique, final, verification_passed, authoritative_artifact).")
|
|
16
|
+
.action(async (task, options) => {
|
|
17
|
+
let testCode;
|
|
18
|
+
if (options.test && fs.existsSync(options.test)) {
|
|
19
|
+
testCode = fs.readFileSync(options.test, "utf-8");
|
|
20
|
+
}
|
|
21
|
+
const entity = new CodeEntity(defaultCodeEntityBindings());
|
|
22
|
+
const memory = await entity.run(task, { testCode });
|
|
23
|
+
if (options.json) {
|
|
24
|
+
const out = {
|
|
25
|
+
verification_passed: memory.verificationPassed,
|
|
26
|
+
verification_evidence: memory.verificationEvidence,
|
|
27
|
+
authoritative_artifact: memory.verificationPassed
|
|
28
|
+
? memory.authoritativeArtifact
|
|
29
|
+
: null,
|
|
30
|
+
draft: memory.draft,
|
|
31
|
+
critique: memory.critique,
|
|
32
|
+
final_candidate: memory.finalCandidate,
|
|
33
|
+
};
|
|
34
|
+
console.log(JSON.stringify(out, null, 2));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log("=== Draft ===");
|
|
38
|
+
console.log(memory.draft);
|
|
39
|
+
console.log("\n=== Critique ===");
|
|
40
|
+
console.log(memory.critique);
|
|
41
|
+
console.log("\n=== Final candidate ===");
|
|
42
|
+
console.log(memory.finalCandidate);
|
|
43
|
+
console.log("\n=== Verification ===");
|
|
44
|
+
console.log(memory.verificationPassed ? "Passed:" : "Failed:", memory.verificationPassed);
|
|
45
|
+
console.log(memory.verificationEvidence);
|
|
46
|
+
if (memory.verificationPassed && memory.authoritativeArtifact) {
|
|
47
|
+
console.log("\n=== Authoritative artifact ===");
|
|
48
|
+
console.log(memory.authoritativeArtifact);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
await program.parseAsync(process.argv);
|
|
53
|
+
}
|
|
54
|
+
main().catch((err) => {
|
|
55
|
+
console.error(err);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,KAAK,UAAU,IAAI;IACjB,OAAO;SACJ,IAAI,CAAC,WAAW,CAAC;SACjB,WAAW,CAAC,oDAAoD,CAAC;SACjE,QAAQ,CAAC,QAAQ,EAAE,2EAA2E,CAAC;SAC/F,MAAM,CACL,mBAAmB,EACnB,6FAA6F,CAC9F;SACA,MAAM,CACL,QAAQ,EACR,8FAA8F,CAC/F;SACA,MAAM,CAAC,KAAK,EAAE,IAAY,EAAE,OAA0C,EAAE,EAAE;QACzE,IAAI,QAA4B,CAAC;QAEjC,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,yBAAyB,EAAE,CAAC,CAAC;QAC3D,M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AC,qBAAqB,EAAE,CAAC;gBAC9D,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;gBAChD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM gateway config: per-role model binding.
|
|
3
|
+
* Load from JSON (moltblock.json), with env overrides.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
export declare const BindingEntrySchema: z.ZodObject<{
|
|
7
|
+
backend: z.ZodString;
|
|
8
|
+
base_url: z.ZodString;
|
|
9
|
+
model: z.ZodDefault<z.ZodString>;
|
|
10
|
+
api_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
model: string;
|
|
13
|
+
backend: string;
|
|
14
|
+
base_url: string;
|
|
15
|
+
api_key?: string | null | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
backend: string;
|
|
18
|
+
base_url: string;
|
|
19
|
+
model?: string | undefined;
|
|
20
|
+
api_key?: string | null | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export type BindingEntry = z.infer<typeof BindingEntrySchema>;
|
|
23
|
+
export declare const AgentConfigSchema: z.ZodObject<{
|
|
24
|
+
bindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
25
|
+
backend: z.ZodString;
|
|
26
|
+
base_url: z.ZodString;
|
|
27
|
+
model: z.ZodDefault<z.ZodString>;
|
|
28
|
+
api_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
model: string;
|
|
31
|
+
backend: string;
|
|
32
|
+
base_url: string;
|
|
33
|
+
api_key?: string | null | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
backend: string;
|
|
36
|
+
base_url: string;
|
|
37
|
+
model?: string | undefined;
|
|
38
|
+
api_key?: string | null | undefined;
|
|
39
|
+
}>>>;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
bindings?: Record<string, {
|
|
42
|
+
model: string;
|
|
43
|
+
backend: string;
|
|
44
|
+
base_url: string;
|
|
45
|
+
api_key?: string | null | undefined;
|
|
46
|
+
}> | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
bindings?: Record<string, {
|
|
49
|
+
backend: string;
|
|
50
|
+
base_url: string;
|
|
51
|
+
model?: string | undefined;
|
|
52
|
+
api_key?: string | null | undefined;
|
|
53
|
+
}> | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
export type AgentConfig = z.infer<typeof AgentConfigSchema>;
|
|
56
|
+
export declare const MoltblockConfigSchema: z.ZodObject<{
|
|
57
|
+
agent: z.ZodOptional<z.ZodObject<{
|
|
58
|
+
bindings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
59
|
+
backend: z.ZodString;
|
|
60
|
+
base_url: z.ZodString;
|
|
61
|
+
model: z.ZodDefault<z.ZodString>;
|
|
62
|
+
api_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
|
64
|
+
model: string;
|
|
65
|
+
backend: string;
|
|
66
|
+
base_url: string;
|
|
67
|
+
api_key?: string | null | undefined;
|
|
68
|
+
}, {
|
|
69
|
+
backend: string;
|
|
70
|
+
base_url: string;
|
|
71
|
+
model?: string | undefined;
|
|
72
|
+
api_key?: string | null | undefined;
|
|
73
|
+
}>>>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
bindings?: Record<string, {
|
|
76
|
+
model: string;
|
|
77
|
+
backend: string;
|
|
78
|
+
base_url: string;
|
|
79
|
+
api_key?: string | null | undefined;
|
|
80
|
+
}> | undefined;
|
|
81
|
+
}, {
|
|
82
|
+
bindings?: Record<string, {
|
|
83
|
+
backend: string;
|
|
84
|
+
base_url: string;
|
|
85
|
+
model?: string | undefined;
|
|
86
|
+
api_key?: string | null | undefined;
|
|
87
|
+
}> | undefined;
|
|
88
|
+
}>>;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
agent?: {
|
|
91
|
+
bindings?: Record<string, {
|
|
92
|
+
model: string;
|
|
93
|
+
backend: string;
|
|
94
|
+
base_url: string;
|
|
95
|
+
api_key?: string | null | undefined;
|
|
96
|
+
}> | undefined;
|
|
97
|
+
} | undefined;
|
|
98
|
+
}, {
|
|
99
|
+
agent?: {
|
|
100
|
+
bindings?: Record<string, {
|
|
101
|
+
backend: string;
|
|
102
|
+
base_url: string;
|
|
103
|
+
model?: string | undefined;
|
|
104
|
+
api_key?: string | null | undefined;
|
|
105
|
+
}> | undefined;
|
|
106
|
+
} | undefined;
|
|
107
|
+
}>;
|
|
108
|
+
export type MoltblockConfig = z.infer<typeof MoltblockConfigSchema>;
|
|
109
|
+
export declare const ModelBindingSchema: z.ZodObject<{
|
|
110
|
+
backend: z.ZodString;
|
|
111
|
+
baseUrl: z.ZodString;
|
|
112
|
+
apiKey: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
113
|
+
model: z.ZodDefault<z.ZodString>;
|
|
114
|
+
}, "strip", z.ZodTypeAny, {
|
|
115
|
+
model: string;
|
|
116
|
+
backend: string;
|
|
117
|
+
baseUrl: string;
|
|
118
|
+
apiKey: string | null;
|
|
119
|
+
}, {
|
|
120
|
+
backend: string;
|
|
121
|
+
baseUrl: string;
|
|
122
|
+
model?: string | undefined;
|
|
123
|
+
apiKey?: string | null | undefined;
|
|
124
|
+
}>;
|
|
125
|
+
export type ModelBinding = z.infer<typeof ModelBindingSchema>;
|
|
126
|
+
/**
|
|
127
|
+
* Load and parse moltblock.json if present. Returns null if no file or parse error.
|
|
128
|
+
*/
|
|
129
|
+
export declare function loadMoltblockConfig(): MoltblockConfig | null;
|
|
130
|
+
/**
|
|
131
|
+
* Model bindings for Code Entity. Load from moltblock.json if present, then env overrides.
|
|
132
|
+
* If no JSON, uses env/.env only (backward compatible). API keys from env win over JSON.
|
|
133
|
+
*/
|
|
134
|
+
export declare function defaultCodeEntityBindings(): Record<string, ModelBinding>;
|
|
135
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;EAK7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;EAK7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAwB9D;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,GAAG,IAAI,CAY5D;AAMD;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CA0ExE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM gateway config: per-role model binding.
|
|
3
|
+
* Load from JSON (moltblock.json), with env overrides.
|
|
4
|
+
*/
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// Load .env so MOLTBLOCK_ZAI_API_KEY etc. can be set there
|
|
10
|
+
try {
|
|
11
|
+
const dotenv = await import("dotenv");
|
|
12
|
+
dotenv.config();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// dotenv not required
|
|
16
|
+
}
|
|
17
|
+
// --- Zod schemas (OpenClaw-style config) ---
|
|
18
|
+
export const BindingEntrySchema = z.object({
|
|
19
|
+
backend: z.string().describe("e.g. 'local' or 'zai' or 'openai'"),
|
|
20
|
+
base_url: z.string().describe("API base URL"),
|
|
21
|
+
model: z.string().default("default").describe("Model id for chat completion"),
|
|
22
|
+
api_key: z.string().nullable().optional().describe("Bearer token; null for local. Prefer env."),
|
|
23
|
+
});
|
|
24
|
+
export const AgentConfigSchema = z.object({
|
|
25
|
+
bindings: z.record(BindingEntrySchema).optional().describe("Per-role model bindings"),
|
|
26
|
+
});
|
|
27
|
+
export const MoltblockConfigSchema = z.object({
|
|
28
|
+
agent: AgentConfigSchema.optional().describe("Agent defaults and bindings"),
|
|
29
|
+
});
|
|
30
|
+
export const ModelBindingSchema = z.object({
|
|
31
|
+
backend: z.string().describe("e.g. 'local' or 'zai' or 'openai'"),
|
|
32
|
+
baseUrl: z.string().describe("API base URL"),
|
|
33
|
+
apiKey: z.string().nullable().default(null).describe("Bearer token; null for local"),
|
|
34
|
+
model: z.string().default("default").describe("Model name for chat completion"),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Resolve config file: MOLTBLOCK_CONFIG env, then ./moltblock.json, ./.moltblock/moltblock.json, ~/.moltblock/moltblock.json.
|
|
38
|
+
*/
|
|
39
|
+
function configPath() {
|
|
40
|
+
const envPath = (process.env["MOLTBLOCK_CONFIG"] ?? "").trim();
|
|
41
|
+
if (envPath && fs.existsSync(envPath)) {
|
|
42
|
+
return envPath;
|
|
43
|
+
}
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
const candidates = [
|
|
46
|
+
path.join(cwd, "moltblock.json"),
|
|
47
|
+
path.join(cwd, ".moltblock", "moltblock.json"),
|
|
48
|
+
path.join(os.homedir(), ".moltblock", "moltblock.json"),
|
|
49
|
+
];
|
|
50
|
+
for (const candidate of candidates) {
|
|
51
|
+
if (fs.existsSync(candidate)) {
|
|
52
|
+
return candidate;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Load and parse moltblock.json if present. Returns null if no file or parse error.
|
|
59
|
+
*/
|
|
60
|
+
export function loadMoltblockConfig() {
|
|
61
|
+
const configFile = configPath();
|
|
62
|
+
if (!configFile) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const raw = fs.readFileSync(configFile, "utf-8");
|
|
67
|
+
const data = JSON.parse(raw);
|
|
68
|
+
return MoltblockConfigSchema.parse(data);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function env(key, defaultValue = "") {
|
|
75
|
+
return (process.env[key] ?? defaultValue).trim();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Model bindings for Code Entity. Load from moltblock.json if present, then env overrides.
|
|
79
|
+
* If no JSON, uses env/.env only (backward compatible). API keys from env win over JSON.
|
|
80
|
+
*/
|
|
81
|
+
export function defaultCodeEntityBindings() {
|
|
82
|
+
const cfg = loadMoltblockConfig();
|
|
83
|
+
const zaiKey = env("MOLTBLOCK_ZAI_API_KEY");
|
|
84
|
+
const localUrl = env("MOLTBLOCK_GENERATOR_BASE_URL") || "http://localhost:1234/v1";
|
|
85
|
+
const localModel = env("MOLTBLOCK_GENERATOR_MODEL") || "local";
|
|
86
|
+
const envUrl = (key, fallback) => env(key) || fallback;
|
|
87
|
+
const envModel = (key, fallback) => env(key) || fallback;
|
|
88
|
+
const bindingsFromJson = cfg?.agent?.bindings ?? {};
|
|
89
|
+
function bindingFor(role, defaultBackend, defaultBase, defaultModel, defaultApiKey) {
|
|
90
|
+
const entry = bindingsFromJson[role];
|
|
91
|
+
if (entry) {
|
|
92
|
+
const baseUrl = envUrl(`MOLTBLOCK_${role.toUpperCase()}_BASE_URL`, entry.base_url);
|
|
93
|
+
const model = envModel(`MOLTBLOCK_${role.toUpperCase()}_MODEL`, entry.model ?? "default");
|
|
94
|
+
const apiKey = env(`MOLTBLOCK_${role.toUpperCase()}_API_KEY`) ||
|
|
95
|
+
entry.api_key ||
|
|
96
|
+
(entry.backend === "zai" ? zaiKey : null) ||
|
|
97
|
+
null;
|
|
98
|
+
return { backend: entry.backend, baseUrl, apiKey, model };
|
|
99
|
+
}
|
|
100
|
+
// No JSON: legacy env-only behavior
|
|
101
|
+
if (role === "generator") {
|
|
102
|
+
return { backend: "local", baseUrl: localUrl, apiKey: null, model: localModel };
|
|
103
|
+
}
|
|
104
|
+
if (role === "critic") {
|
|
105
|
+
const useZai = Boolean(zaiKey);
|
|
106
|
+
return {
|
|
107
|
+
backend: useZai ? "zai" : "local",
|
|
108
|
+
baseUrl: envUrl("MOLTBLOCK_CRITIC_BASE_URL", useZai ? "https://api.z.ai/api/paas/v4" : localUrl),
|
|
109
|
+
apiKey: useZai ? zaiKey : null,
|
|
110
|
+
model: envModel("MOLTBLOCK_CRITIC_MODEL", useZai ? "glm-4.7-flash" : localModel),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (role === "judge") {
|
|
114
|
+
const useZai = Boolean(zaiKey);
|
|
115
|
+
return {
|
|
116
|
+
backend: useZai ? "zai" : "local",
|
|
117
|
+
baseUrl: envUrl("MOLTBLOCK_JUDGE_BASE_URL", useZai ? "https://api.z.ai/api/paas/v4" : localUrl),
|
|
118
|
+
apiKey: useZai ? zaiKey : null,
|
|
119
|
+
model: envModel("MOLTBLOCK_JUDGE_MODEL", useZai ? "glm-4.7-flash" : localModel),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (role === "verifier") {
|
|
123
|
+
return {
|
|
124
|
+
backend: "local",
|
|
125
|
+
baseUrl: envUrl("MOLTBLOCK_VERIFIER_BASE_URL", localUrl),
|
|
126
|
+
apiKey: null,
|
|
127
|
+
model: envModel("MOLTBLOCK_VERIFIER_MODEL", localModel),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { backend: defaultBackend, baseUrl: defaultBase, apiKey: defaultApiKey, model: defaultModel };
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
generator: bindingFor("generator", "local", localUrl, localModel, null),
|
|
134
|
+
critic: bindingFor("critic", zaiKey ? "zai" : "local", localUrl, localModel, zaiKey || null),
|
|
135
|
+
judge: bindingFor("judge", zaiKey ? "zai" : "local", localUrl, localModel, zaiKey || null),
|
|
136
|
+
verifier: bindingFor("verifier", "local", localUrl, localModel, null),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;A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,UAAU,EAAE,IAAI,CAAC;KACtE,CAAC;AACJ,CAAC"}
|
package/dist/entity.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity: minimal runnable loop — task in -> graph (Generator/Critic/Judge) -> Verifier -> artifact out.
|
|
3
|
+
*/
|
|
4
|
+
import { type ModelBinding } from "./config.js";
|
|
5
|
+
import { GraphRunner } from "./graph-runner.js";
|
|
6
|
+
import { WorkingMemory } from "./memory.js";
|
|
7
|
+
import { Store } from "./persistence.js";
|
|
8
|
+
/**
|
|
9
|
+
* Code Entity: Generator -> Critic -> Judge -> Verifier.
|
|
10
|
+
* Uses working memory and per-role LLM gateways.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CodeEntity {
|
|
13
|
+
private gateways;
|
|
14
|
+
constructor(bindings?: Record<string, ModelBinding>);
|
|
15
|
+
/**
|
|
16
|
+
* One full loop: task in -> Generator -> Critic -> Judge -> Verifier -> gating.
|
|
17
|
+
* If store is provided and verification passed: admit to verified memory; optionally write checkpoint.
|
|
18
|
+
* Returns working memory with authoritative_artifact set only if verification passed.
|
|
19
|
+
*/
|
|
20
|
+
run(task: string, options?: {
|
|
21
|
+
testCode?: string;
|
|
22
|
+
store?: Store;
|
|
23
|
+
entityVersion?: string;
|
|
24
|
+
writeCheckpointAfter?: boolean;
|
|
25
|
+
}): Promise<WorkingMemory>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Load an Entity from a declarative graph (JSON/YAML). Returns a GraphRunner.
|
|
29
|
+
*/
|
|
30
|
+
export declare function loadEntityWithGraph(graphPath: string, bindings?: Record<string, ModelBinding>): GraphRunner;
|
|
31
|
+
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAA6B,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAA6B,MAAM,kBAAkB,CAAC;AAGpE;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAA6B;gBAEjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IASnD;;;;OAIG;IACG,GAAG,CACP,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,oBAAoB,CAAC,EAAE,OAAO,CAAC;KAC3B,GACL,OAAO,CAAC,aAAa,CAAC;CAwD1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GACtC,WAAW,CAGb"}
|