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
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent graph schema: DAG of nodes (role + model_binding) and edges (data flow).
|
|
3
|
+
*/
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
export const GraphNodeSchema = z.object({
|
|
8
|
+
id: z.string().describe("Unique node id (e.g. generator, critic, judge)"),
|
|
9
|
+
role: z.string().describe("Role name: generator, critic, judge, router, etc."),
|
|
10
|
+
binding: z.string().describe("Key into bindings dict (e.g. generator, critic)"),
|
|
11
|
+
});
|
|
12
|
+
export const GraphEdgeSchema = z.object({
|
|
13
|
+
from: z.string().describe("Source node id"),
|
|
14
|
+
to: z.string().describe("Target node id"),
|
|
15
|
+
});
|
|
16
|
+
export const AgentGraphSchema = z.object({
|
|
17
|
+
nodes: z.array(GraphNodeSchema).default([]),
|
|
18
|
+
edges: z.array(GraphEdgeSchema).default([]),
|
|
19
|
+
final_node: z
|
|
20
|
+
.string()
|
|
21
|
+
.nullable()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("Node whose output is the final candidate for verification (default: node with no outgoing edges)"),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Declarative agent graph: nodes and edges. Verifier runs on final node(s) output.
|
|
27
|
+
*/
|
|
28
|
+
export class AgentGraph {
|
|
29
|
+
nodes;
|
|
30
|
+
edges;
|
|
31
|
+
finalNode;
|
|
32
|
+
constructor(data) {
|
|
33
|
+
this.nodes = data.nodes;
|
|
34
|
+
this.edges = data.edges;
|
|
35
|
+
this.finalNode = data.final_node ?? null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Return list of node ids that have an edge into nodeId.
|
|
39
|
+
*/
|
|
40
|
+
predecessors(nodeId) {
|
|
41
|
+
return this.edges.filter((e) => e.to === nodeId).map((e) => e.from);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Return list of node ids that nodeId has an edge to.
|
|
45
|
+
*/
|
|
46
|
+
successors(nodeId) {
|
|
47
|
+
return this.edges.filter((e) => e.from === nodeId).map((e) => e.to);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Return node ids in topological order (inputs before outputs).
|
|
51
|
+
*/
|
|
52
|
+
topologicalOrder() {
|
|
53
|
+
const nodeIds = new Set(this.nodes.map((n) => n.id));
|
|
54
|
+
const inDegree = {};
|
|
55
|
+
for (const nid of nodeIds) {
|
|
56
|
+
inDegree[nid] = 0;
|
|
57
|
+
}
|
|
58
|
+
for (const e of this.edges) {
|
|
59
|
+
if (nodeIds.has(e.to)) {
|
|
60
|
+
inDegree[e.to] = (inDegree[e.to] ?? 0) + 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const order = [];
|
|
64
|
+
while (order.length < nodeIds.size) {
|
|
65
|
+
const ready = [...nodeIds].filter((nid) => !order.includes(nid) && inDegree[nid] === 0);
|
|
66
|
+
if (ready.length === 0) {
|
|
67
|
+
break; // cycle or done
|
|
68
|
+
}
|
|
69
|
+
order.push(...ready);
|
|
70
|
+
for (const nid of ready) {
|
|
71
|
+
for (const s of this.successors(nid)) {
|
|
72
|
+
if (inDegree[s] !== undefined) {
|
|
73
|
+
inDegree[s]--;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return order;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Node whose output goes to verifier. Explicit final_node or single node with no outgoing edges.
|
|
82
|
+
*/
|
|
83
|
+
getFinalNodeId() {
|
|
84
|
+
if (this.finalNode) {
|
|
85
|
+
return this.finalNode;
|
|
86
|
+
}
|
|
87
|
+
const candidates = this.nodes
|
|
88
|
+
.filter((n) => this.successors(n.id).length === 0)
|
|
89
|
+
.map((n) => n.id);
|
|
90
|
+
return candidates.length === 1 ? (candidates[0] ?? null) : null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Serialize to JSON string.
|
|
94
|
+
*/
|
|
95
|
+
toJSON() {
|
|
96
|
+
return JSON.stringify({
|
|
97
|
+
nodes: this.nodes,
|
|
98
|
+
edges: this.edges,
|
|
99
|
+
final_node: this.finalNode,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Load graph from JSON or YAML file.
|
|
104
|
+
*/
|
|
105
|
+
static load(filePath) {
|
|
106
|
+
const resolved = path.resolve(filePath);
|
|
107
|
+
if (!fs.existsSync(resolved)) {
|
|
108
|
+
throw new Error(`Graph file not found: ${resolved}`);
|
|
109
|
+
}
|
|
110
|
+
const raw = fs.readFileSync(resolved, "utf-8");
|
|
111
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
112
|
+
let data;
|
|
113
|
+
if (ext === ".yaml" || ext === ".yml") {
|
|
114
|
+
// Dynamic import for yaml
|
|
115
|
+
try {
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
117
|
+
const yaml = require("js-yaml");
|
|
118
|
+
data = yaml.load(raw);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new Error("js-yaml required for YAML graphs: npm install js-yaml");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
data = JSON.parse(raw);
|
|
126
|
+
}
|
|
127
|
+
const parsed = AgentGraphSchema.parse(data);
|
|
128
|
+
return new AgentGraph(parsed);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create graph from data object.
|
|
132
|
+
*/
|
|
133
|
+
static fromData(data) {
|
|
134
|
+
return new AgentGraph(AgentGraphSchema.parse(data));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=graph-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-schema.js","sourceRoot":"","sources":["../src/graph-schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;IACzE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;IAC9E,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;CAChF,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAC3C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;CAC1C,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3C,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,OAAO,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C,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;QAED,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAoB;QAClC,OAAO,IAAI,UAAU,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-entity handoff: Entity A produces signed artifact -> Entity B consumes as input.
|
|
3
|
+
*/
|
|
4
|
+
import { Store } from "./persistence.js";
|
|
5
|
+
import type { ReceivedArtifact } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Sign artifact and deliver to recipient's inbox. Returns artifact_ref.
|
|
8
|
+
* recipientStore is the recipient entity's Store (entity_id = recipient).
|
|
9
|
+
*/
|
|
10
|
+
export declare function sendArtifact(senderEntityId: string, recipientStore: Store, artifactContent: string, artifactRef?: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get inbox artifacts for this entity. If verify=true, only return entries
|
|
13
|
+
* where the signature is valid for the sender. Each entry includes
|
|
14
|
+
* from_entity_id, artifact_ref, payload_text, verified.
|
|
15
|
+
*/
|
|
16
|
+
export declare function receiveArtifacts(store: Store, options?: {
|
|
17
|
+
limit?: number;
|
|
18
|
+
verify?: boolean;
|
|
19
|
+
}): ReceivedArtifact[];
|
|
20
|
+
//# sourceMappingURL=handoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAsB,MAAM,kBAAkB,CAAC;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,KAAK,EACrB,eAAe,EAAE,MAAM,EACvB,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAeR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjD,gBAAgB,EAAE,CAgBpB"}
|
package/dist/handoff.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-entity handoff: Entity A produces signed artifact -> Entity B consumes as input.
|
|
3
|
+
*/
|
|
4
|
+
import { getInbox, putInbox } from "./persistence.js";
|
|
5
|
+
import { artifactHash, signArtifact, verifyArtifact } from "./signing.js";
|
|
6
|
+
/**
|
|
7
|
+
* Sign artifact and deliver to recipient's inbox. Returns artifact_ref.
|
|
8
|
+
* recipientStore is the recipient entity's Store (entity_id = recipient).
|
|
9
|
+
*/
|
|
10
|
+
export function sendArtifact(senderEntityId, recipientStore, artifactContent, artifactRef) {
|
|
11
|
+
const ref = artifactRef ?? `artifact_${senderEntityId}_${Date.now()}`;
|
|
12
|
+
const payloadHash = artifactHash(artifactContent);
|
|
13
|
+
const signature = signArtifact(senderEntityId, artifactContent);
|
|
14
|
+
putInbox(recipientStore, senderEntityId, ref, payloadHash, signature, artifactContent.slice(0, 100_000));
|
|
15
|
+
return ref;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get inbox artifacts for this entity. If verify=true, only return entries
|
|
19
|
+
* where the signature is valid for the sender. Each entry includes
|
|
20
|
+
* from_entity_id, artifact_ref, payload_text, verified.
|
|
21
|
+
*/
|
|
22
|
+
export function receiveArtifacts(store, options = {}) {
|
|
23
|
+
const { limit = 20, verify = true } = options;
|
|
24
|
+
const entries = getInbox(store, limit);
|
|
25
|
+
return entries.map((e) => {
|
|
26
|
+
let ok = true;
|
|
27
|
+
if (verify && e.payload_text && e.signature) {
|
|
28
|
+
ok = verifyArtifact(e.from_entity_id, e.payload_text, e.signature);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
from_entity_id: e.from_entity_id,
|
|
32
|
+
artifact_ref: e.artifact_ref,
|
|
33
|
+
payload_text: e.payload_text ?? "",
|
|
34
|
+
verified: ok,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=handoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAS,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG1E;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,cAAsB,EACtB,cAAqB,EACrB,eAAuB,EACvB,WAAoB;IAEpB,MAAM,GAAG,GAAG,WAAW,IAAI,YAAY,cAAc,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IACtE,MAAM,WAAW,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,YAAY,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAEhE,QAAQ,CACN,cAAc,EACd,cAAc,EACd,GAAG,EACH,WAAW,EACX,SAAS,EACT,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAClC,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAY,EACZ,UAAgD,EAAE;IAElD,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAEvC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,IAAI,EAAE,GAAG,IAAI,CAAC;QACd,IAAI,MAAM,IAAI,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;YAC5C,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;QACrE,CAAC;QACD,OAAO;YACL,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,EAAE;YAClC,QAAQ,EAAE,EAAE;SACb,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive improvement loop: measure outcomes, critique strategies, update prompts, re-evaluate.
|
|
3
|
+
*/
|
|
4
|
+
import { Store } from "./persistence.js";
|
|
5
|
+
import type { StrategySuggestion } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Review recent outcomes and return suggested strategy updates (rule-based for MVP).
|
|
8
|
+
* Returns list of { role, suggestion } for human or governance to apply.
|
|
9
|
+
*/
|
|
10
|
+
export declare function critiqueStrategies(store: Store, recentCount?: number): StrategySuggestion[];
|
|
11
|
+
/**
|
|
12
|
+
* Apply a new prompt for role (strategy update). Under governance, this would require approval.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applySuggestion(store: Store, role: string, newPrompt: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Run eval_tasks through runTask (which returns verification_passed).
|
|
17
|
+
* If store is provided, record each outcome. Returns { passed, total }.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runEval(runTask: (task: string) => Promise<boolean>, evalTasks: string[], store?: Store): Promise<{
|
|
20
|
+
passed: number;
|
|
21
|
+
total: number;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* One improvement cycle: run eval, critique, optionally apply suggestions.
|
|
25
|
+
* Returns { passed, total, suggestions }.
|
|
26
|
+
*/
|
|
27
|
+
export declare function runImprovementCycle(store: Store, runTask: (task: string) => Promise<boolean>, evalTasks: string[], applySuggestions?: boolean): Promise<{
|
|
28
|
+
passed: number;
|
|
29
|
+
total: number;
|
|
30
|
+
suggestions: StrategySuggestion[];
|
|
31
|
+
}>;
|
|
32
|
+
//# sourceMappingURL=improvement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"improvement.d.ts","sourceRoot":"","sources":["../src/improvement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,KAAK,EAIN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,KAAK,EACZ,WAAW,SAAK,GACf,kBAAkB,EAAE,CA0BtB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAC3C,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,CAAC,EAAE,KAAK,GACZ,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAkB5C;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAC3C,SAAS,EAAE,MAAM,EAAE,EACnB,gBAAgB,UAAQ,GACvB,OAAO,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,CAAC,CAUD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive improvement loop: measure outcomes, critique strategies, update prompts, re-evaluate.
|
|
3
|
+
*/
|
|
4
|
+
import { getRecentOutcomes, recordOutcome, setStrategy, } from "./persistence.js";
|
|
5
|
+
/**
|
|
6
|
+
* Review recent outcomes and return suggested strategy updates (rule-based for MVP).
|
|
7
|
+
* Returns list of { role, suggestion } for human or governance to apply.
|
|
8
|
+
*/
|
|
9
|
+
export function critiqueStrategies(store, recentCount = 10) {
|
|
10
|
+
const outcomes = getRecentOutcomes(store, recentCount);
|
|
11
|
+
if (outcomes.length < 3) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const passed = outcomes.filter((o) => o.verification_passed).length;
|
|
15
|
+
const failRate = 1.0 - passed / outcomes.length;
|
|
16
|
+
const suggestions = [];
|
|
17
|
+
if (failRate >= 0.5) {
|
|
18
|
+
suggestions.push({
|
|
19
|
+
role: "generator",
|
|
20
|
+
suggestion: "Add explicit instruction: output only valid TypeScript with no markdown fences or commentary.",
|
|
21
|
+
});
|
|
22
|
+
suggestions.push({
|
|
23
|
+
role: "judge",
|
|
24
|
+
suggestion: "Ensure Judge incorporates all critic feedback and outputs runnable code only.",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return suggestions;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Apply a new prompt for role (strategy update). Under governance, this would require approval.
|
|
31
|
+
*/
|
|
32
|
+
export function applySuggestion(store, role, newPrompt) {
|
|
33
|
+
setStrategy(store, role, newPrompt);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Run eval_tasks through runTask (which returns verification_passed).
|
|
37
|
+
* If store is provided, record each outcome. Returns { passed, total }.
|
|
38
|
+
*/
|
|
39
|
+
export async function runEval(runTask, evalTasks, store) {
|
|
40
|
+
let passed = 0;
|
|
41
|
+
for (const task of evalTasks) {
|
|
42
|
+
const t0 = performance.now();
|
|
43
|
+
const ok = await runTask(task);
|
|
44
|
+
const latency = (performance.now() - t0) / 1000;
|
|
45
|
+
if (store) {
|
|
46
|
+
recordOutcome(store, ok, latency, task.slice(0, 100));
|
|
47
|
+
}
|
|
48
|
+
if (ok) {
|
|
49
|
+
passed++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { passed, total: evalTasks.length };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One improvement cycle: run eval, critique, optionally apply suggestions.
|
|
56
|
+
* Returns { passed, total, suggestions }.
|
|
57
|
+
*/
|
|
58
|
+
export async function runImprovementCycle(store, runTask, evalTasks, applySuggestions = false) {
|
|
59
|
+
const { passed, total } = await runEval(runTask, evalTasks, store);
|
|
60
|
+
const suggestions = critiqueStrategies(store, total);
|
|
61
|
+
if (applySuggestions && suggestions.length > 0) {
|
|
62
|
+
// Only apply if we have a concrete new prompt; suggestion text could be used by a meta-agent to generate one
|
|
63
|
+
// For now, this is a no-op placeholder
|
|
64
|
+
}
|
|
65
|
+
return { passed, total, suggestions };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=improvement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"improvement.js","sourceRoot":"","sources":["../src/improvement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,iBAAiB,EACjB,aAAa,EACb,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B;;;GAGG;AACH,MAAM,UAAU,kBAAkB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,IAAI,CAAC;QAEhD,IAAI,KAAK,EAAE,CAAC;YACV,aAAa,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,EAAE,EAAE,CAAC;YACP,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,KAAY,EACZ,OAA2C,EAC3C,SAAmB,EACnB,gBAAgB,GAAG,KAAK;IAMxB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACnE,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAErD,IAAI,gBAAgB,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,6GAA6G;QAC7G,uCAAuC;IACzC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AACxC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moltblock — framework for evolving composite intelligences (Entities).
|
|
3
|
+
*/
|
|
4
|
+
export declare const VERSION = "0.2.0";
|
|
5
|
+
export type { ModelBinding, BindingEntry, AgentConfig, MoltblockConfig, ChatMessage, VerifiedMemoryEntry, CheckpointEntry, OutcomeEntry, InboxEntry, StrategySuggestion, ReceivedArtifact, GovernanceConfig, } from "./types.js";
|
|
6
|
+
export { WorkingMemory } from "./memory.js";
|
|
7
|
+
export { signArtifact, verifyArtifact, artifactHash } from "./signing.js";
|
|
8
|
+
export { loadMoltblockConfig, defaultCodeEntityBindings, BindingEntrySchema, AgentConfigSchema, MoltblockConfigSchema, ModelBindingSchema, } from "./config.js";
|
|
9
|
+
export { Store, hashGraph, hashMemory, auditLog, getGovernanceValue, setGovernanceValue, putInbox, getInbox, recordOutcome, getRecentOutcomes, getStrategy, setStrategy, } from "./persistence.js";
|
|
10
|
+
export { LLMGateway } from "./gateway.js";
|
|
11
|
+
export { runGenerator, runCritic, runJudge, runRole, } from "./agents.js";
|
|
12
|
+
export { AgentGraph, GraphNodeSchema, GraphEdgeSchema, AgentGraphSchema, type GraphNode, type GraphEdge, type AgentGraphData, } from "./graph-schema.js";
|
|
13
|
+
export { GraphRunner } from "./graph-runner.js";
|
|
14
|
+
export { extractCodeBlock, runVitestOnCode, runVerifier } from "./verifier.js";
|
|
15
|
+
export { createGovernanceConfig, canMolt, triggerMolt, pause, resume, isPaused, emergencyShutdown, } from "./governance.js";
|
|
16
|
+
export { sendArtifact, receiveArtifacts } from "./handoff.js";
|
|
17
|
+
export { critiqueStrategies, applySuggestion, runEval, runImprovementCycle, } from "./improvement.js";
|
|
18
|
+
export { CodeEntity, loadEntityWithGraph } from "./entity.js";
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EACL,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,OAAO,GACR,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,UAAU,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG/E,OAAO,EACL,sBAAsB,EACtB,OAAO,EACP,WAAW,EACX,KAAK,EACL,MAAM,EACN,QAAQ,EACR,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,OAAO,EACP,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moltblock — framework for evolving composite intelligences (Entities).
|
|
3
|
+
*/
|
|
4
|
+
export const VERSION = "0.2.0";
|
|
5
|
+
// Memory
|
|
6
|
+
export { WorkingMemory } from "./memory.js";
|
|
7
|
+
// Signing
|
|
8
|
+
export { signArtifact, verifyArtifact, artifactHash } from "./signing.js";
|
|
9
|
+
// Config
|
|
10
|
+
export { loadMoltblockConfig, defaultCodeEntityBindings, BindingEntrySchema, AgentConfigSchema, MoltblockConfigSchema, ModelBindingSchema, } from "./config.js";
|
|
11
|
+
// Persistence
|
|
12
|
+
export { Store, hashGraph, hashMemory, auditLog, getGovernanceValue, setGovernanceValue, putInbox, getInbox, recordOutcome, getRecentOutcomes, getStrategy, setStrategy, } from "./persistence.js";
|
|
13
|
+
// Gateway
|
|
14
|
+
export { LLMGateway } from "./gateway.js";
|
|
15
|
+
// Agents
|
|
16
|
+
export { runGenerator, runCritic, runJudge, runRole, } from "./agents.js";
|
|
17
|
+
// Graph
|
|
18
|
+
export { AgentGraph, GraphNodeSchema, GraphEdgeSchema, AgentGraphSchema, } from "./graph-schema.js";
|
|
19
|
+
// Graph Runner
|
|
20
|
+
export { GraphRunner } from "./graph-runner.js";
|
|
21
|
+
// Verifier
|
|
22
|
+
export { extractCodeBlock, runVitestOnCode, runVerifier } from "./verifier.js";
|
|
23
|
+
// Governance
|
|
24
|
+
export { createGovernanceConfig, canMolt, triggerMolt, pause, resume, isPaused, emergencyShutdown, } from "./governance.js";
|
|
25
|
+
// Handoff
|
|
26
|
+
export { sendArtifact, receiveArtifacts } from "./handoff.js";
|
|
27
|
+
// Improvement
|
|
28
|
+
export { critiqueStrategies, applySuggestion, runEval, runImprovementCycle, } from "./improvement.js";
|
|
29
|
+
// Entity
|
|
30
|
+
export { CodeEntity, loadEntityWithGraph } from "./entity.js";
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAkB/B,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,UAAU;AACV,OAAO,EAA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|
|
2
|
+
* Working memory: shared state for one task (drafts, critique, final artifact, verification result).
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* In-memory scratchpad for a single run of the agent graph.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WorkingMemory {
|
|
8
|
+
task: string;
|
|
9
|
+
draft: string;
|
|
10
|
+
critique: string;
|
|
11
|
+
finalCandidate: string;
|
|
12
|
+
verificationPassed: boolean;
|
|
13
|
+
verificationEvidence: string;
|
|
14
|
+
authoritativeArtifact: string;
|
|
15
|
+
meta: Record<string, unknown>;
|
|
16
|
+
/** Graph runner: node_id -> output (filled by graph execution) */
|
|
17
|
+
slots: Record<string, string>;
|
|
18
|
+
/** Injected from long-term memory for agent context (read-only) */
|
|
19
|
+
longTermContext: string;
|
|
20
|
+
setTask(task: string): void;
|
|
21
|
+
setDraft(draft: string): void;
|
|
22
|
+
setCritique(critique: string): void;
|
|
23
|
+
setFinalCandidate(candidate: string): void;
|
|
24
|
+
setVerification(passed: boolean, evidence?: string): void;
|
|
25
|
+
setSlot(nodeId: string, content: string): void;
|
|
26
|
+
getSlot(nodeId: string): string;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,aAAa;IACxB,IAAI,SAAM;IACV,KAAK,SAAM;IACX,QAAQ,SAAM;IACd,cAAc,SAAM;IACpB,kBAAkB,UAAS;IAC3B,oBAAoB,SAAM;IAC1B,qBAAqB,SAAM;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IACnC,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACnC,mEAAmE;IACnE,eAAe,SAAM;IAErB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAInC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI1C,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,SAAK,GAAG,IAAI;IAQrD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAI9C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAGhC"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Working memory: shared state for one task (drafts, critique, final artifact, verification result).
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* In-memory scratchpad for a single run of the agent graph.
|
|
6
|
+
*/
|
|
7
|
+
export class WorkingMemory {
|
|
8
|
+
task = "";
|
|
9
|
+
draft = "";
|
|
10
|
+
critique = "";
|
|
11
|
+
finalCandidate = "";
|
|
12
|
+
verificationPassed = false;
|
|
13
|
+
verificationEvidence = "";
|
|
14
|
+
authoritativeArtifact = "";
|
|
15
|
+
meta = {};
|
|
16
|
+
/** Graph runner: node_id -> output (filled by graph execution) */
|
|
17
|
+
slots = {};
|
|
18
|
+
/** Injected from long-term memory for agent context (read-only) */
|
|
19
|
+
longTermContext = "";
|
|
20
|
+
setTask(task) {
|
|
21
|
+
this.task = task;
|
|
22
|
+
}
|
|
23
|
+
setDraft(draft) {
|
|
24
|
+
this.draft = draft;
|
|
25
|
+
}
|
|
26
|
+
setCritique(critique) {
|
|
27
|
+
this.critique = critique;
|
|
28
|
+
}
|
|
29
|
+
setFinalCandidate(candidate) {
|
|
30
|
+
this.finalCandidate = candidate;
|
|
31
|
+
}
|
|
32
|
+
setVerification(passed, evidence = "") {
|
|
33
|
+
this.verificationPassed = passed;
|
|
34
|
+
this.verificationEvidence = evidence;
|
|
35
|
+
if (passed) {
|
|
36
|
+
this.authoritativeArtifact = this.finalCandidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
setSlot(nodeId, content) {
|
|
40
|
+
this.slots[nodeId] = content;
|
|
41
|
+
}
|
|
42
|
+
getSlot(nodeId) {
|
|
43
|
+
return this.slots[nodeId] ?? "";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,QAAQ,GAAG,EAAE,CAAC;IACd,cAAc,GAAG,EAAE,CAAC;IACpB,kBAAkB,GAAG,KAAK,CAAC;IAC3B,oBAAoB,GAAG,EAAE,CAAC;IAC1B,qBAAqB,GAAG,EAAE,CAAC;IAC3B,IAAI,GAA4B,EAAE,CAAC;IACnC,kEAAkE;IAClE,KAAK,GAA2B,EAAE,CAAC;IACnC,mEAAmE;IACnE,eAAe,GAAG,EAAE,CAAC;IAErB,OAAO,CAAC,IAAY;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,WAAW,CAAC,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,iBAAiB,CAAC,SAAiB;QACjC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IAClC,CAAC;IAED,eAAe,CAAC,MAAe,EAAE,QAAQ,GAAG,EAAE;QAC5C,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC;QACjC,IAAI,CAAC,oBAAoB,GAAG,QAAQ,CAAC;QACrC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,cAAc,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,OAAe;QACrC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;IAC/B,CAAC;IAED,OAAO,CAAC,MAAc;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Long-term verified memory and checkpoints (SQLite persistence).
|
|
3
|
+
*/
|
|
4
|
+
import Database from "better-sqlite3";
|
|
5
|
+
import type { CheckpointEntry, InboxEntry, OutcomeEntry, VerifiedMemoryEntry } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Persistence for verified memory (admission only after verification) and
|
|
8
|
+
* immutable checkpoints (entity version, graph hash, memory hash, artifact refs).
|
|
9
|
+
*/
|
|
10
|
+
export declare class Store {
|
|
11
|
+
readonly entityId: string;
|
|
12
|
+
readonly path: string;
|
|
13
|
+
private db;
|
|
14
|
+
constructor(options?: {
|
|
15
|
+
path?: string;
|
|
16
|
+
entityId?: string;
|
|
17
|
+
});
|
|
18
|
+
private initSchema;
|
|
19
|
+
/**
|
|
20
|
+
* Admit a verified artifact into long-term memory (call only after verification pass).
|
|
21
|
+
*/
|
|
22
|
+
addVerified(artifactRef: string, summary?: string, contentPreview?: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Return the k most recent verified entries for this entity (for agent context).
|
|
25
|
+
*/
|
|
26
|
+
getRecentVerified(k?: number): VerifiedMemoryEntry[];
|
|
27
|
+
/**
|
|
28
|
+
* Append an immutable checkpoint.
|
|
29
|
+
*/
|
|
30
|
+
writeCheckpoint(entityVersion: string, graphHash: string, memoryHash: string, artifactRefs: string[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* List recent checkpoints for this entity.
|
|
33
|
+
*/
|
|
34
|
+
listCheckpoints(limit?: number): CheckpointEntry[];
|
|
35
|
+
/** Get internal db for helper functions */
|
|
36
|
+
getDb(): Database.Database;
|
|
37
|
+
close(): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Stable hash for graph config (for checkpoint).
|
|
41
|
+
*/
|
|
42
|
+
export declare function hashGraph(graphConfig: string | Buffer): string;
|
|
43
|
+
/**
|
|
44
|
+
* Stable hash for memory state (e.g. last N artifact refs).
|
|
45
|
+
*/
|
|
46
|
+
export declare function hashMemory(verifiedRefs: string[]): string;
|
|
47
|
+
/**
|
|
48
|
+
* Append an audit log entry (molt, veto, shutdown, etc.).
|
|
49
|
+
*/
|
|
50
|
+
export declare function auditLog(store: Store, eventType: string, detail?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get a governance state value (e.g. last_molt_at, paused).
|
|
53
|
+
*/
|
|
54
|
+
export declare function getGovernanceValue(store: Store, key: string): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Set a governance state value.
|
|
57
|
+
*/
|
|
58
|
+
export declare function setGovernanceValue(store: Store, key: string, value: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Add a signed artifact to this entity's inbox (store is the recipient).
|
|
61
|
+
*/
|
|
62
|
+
export declare function putInbox(store: Store, fromEntityId: string, artifactRef: string, payloadHash: string, signature: string, payloadText?: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Return recent inbox entries for this entity (recipient).
|
|
65
|
+
*/
|
|
66
|
+
export declare function getInbox(store: Store, limit?: number): InboxEntry[];
|
|
67
|
+
/**
|
|
68
|
+
* Record one task outcome for measurement.
|
|
69
|
+
*/
|
|
70
|
+
export declare function recordOutcome(store: Store, verificationPassed: boolean, latencySec?: number, taskRef?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Return the k most recent outcomes for this entity.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getRecentOutcomes(store: Store, k?: number): OutcomeEntry[];
|
|
75
|
+
/**
|
|
76
|
+
* Return current strategy (prompt) for role, or null if not set.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getStrategy(store: Store, role: string): string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Set strategy (prompt) for role; inserts new version.
|
|
81
|
+
*/
|
|
82
|
+
export declare function setStrategy(store: Store, role: string, content: string): void;
|
|
83
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,CAAoB;gBAElB,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;IAgB9D,OAAO,CAAC,UAAU;IAsFlB;;OAEG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI;IAcjF;;OAEG;IACH,iBAAiB,CAAC,CAAC,SAAI,GAAG,mBAAmB,EAAE;IAmB/C;;OAEG;IACH,eAAe,CACb,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,GACrB,IAAI;IAeP;;OAEG;IACH,eAAe,CAAC,KAAK,SAAK,GAAG,eAAe,EAAE;IAqB9C,2CAA2C;IAC3C,KAAK,IAAI,QAAQ,CAAC,QAAQ;IAI1B,KAAK,IAAI,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