openclaw-core 1.0.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 +15 -0
- package/README.md +122 -0
- package/dist/brain/MemoryManager.d.ts +25 -0
- package/dist/brain/MemoryManager.js +53 -0
- package/dist/common/lib/BoundaryChecker.d.ts +18 -0
- package/dist/common/lib/BoundaryChecker.js +87 -0
- package/dist/common/lib/EmbeddingService.d.ts +25 -0
- package/dist/common/lib/EmbeddingService.js +77 -0
- package/dist/common/lib/VectorStore.d.ts +16 -0
- package/dist/common/lib/VectorStore.js +42 -0
- package/dist/common/protocols/SAML.d.ts +32 -0
- package/dist/common/protocols/SAML.js +107 -0
- package/dist/harness/AgentEvaluator.d.ts +18 -0
- package/dist/harness/AgentEvaluator.js +117 -0
- package/dist/harness/AgentEvaluator.test.d.ts +1 -0
- package/dist/harness/AgentEvaluator.test.js +46 -0
- package/dist/harness/AgenticHarness.d.ts +14 -0
- package/dist/harness/AgenticHarness.js +56 -0
- package/dist/harness/AgenticHarness.test.d.ts +1 -0
- package/dist/harness/AgenticHarness.test.js +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +13 -0
- package/dist/interfaces/index.d.ts +170 -0
- package/dist/interfaces/index.js +65 -0
- package/dist/resonance/SignalManager.d.ts +39 -0
- package/dist/resonance/SignalManager.js +118 -0
- package/dist/services/PeerDiscovery.d.ts +47 -0
- package/dist/services/PeerDiscovery.js +217 -0
- package/dist/services/PeerRegistry.d.ts +102 -0
- package/dist/services/PeerRegistry.js +438 -0
- package/dist/store/BaseStore.d.ts +47 -0
- package/dist/store/BaseStore.js +77 -0
- package/package.json +47 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as acorn from "acorn";
|
|
2
|
+
import { SAMLIntent } from "../common/protocols/SAML.js";
|
|
3
|
+
function walkAST(node, callback) {
|
|
4
|
+
if (!node || typeof node !== "object")
|
|
5
|
+
return;
|
|
6
|
+
const n = node;
|
|
7
|
+
if (typeof n.type === "string") {
|
|
8
|
+
callback(n);
|
|
9
|
+
}
|
|
10
|
+
for (const key in n) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(n, key)) {
|
|
12
|
+
const child = n[key];
|
|
13
|
+
if (Array.isArray(child)) {
|
|
14
|
+
for (const item of child)
|
|
15
|
+
walkAST(item, callback);
|
|
16
|
+
}
|
|
17
|
+
else if (child && typeof child === "object") {
|
|
18
|
+
walkAST(child, callback);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class ByzantineFaultError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "ByzantineFaultError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class AgentEvaluator {
|
|
30
|
+
constructor() { }
|
|
31
|
+
async audit(request, enforceBoundary = true) {
|
|
32
|
+
console.log(`⚖️ [AgentEvaluator] Initiating Dual-Pass BFT Audit for spec: ${request.specHash}`);
|
|
33
|
+
if (request.harness && request.tools) {
|
|
34
|
+
console.log("🔍 [AgentEvaluator] Pass 1 (Dynamic): Executing behavioral dry-run...");
|
|
35
|
+
try {
|
|
36
|
+
const dryRunEnvelope = {
|
|
37
|
+
version: "SAML/1.0",
|
|
38
|
+
sender_did: "did:internal:evaluator",
|
|
39
|
+
recipient_did: "did:internal:harness",
|
|
40
|
+
vector: {
|
|
41
|
+
intent: SAMLIntent.QUERY,
|
|
42
|
+
budget_ceiling: 0,
|
|
43
|
+
deadline_ts: Date.now() + 1000,
|
|
44
|
+
slash_ratio: 0
|
|
45
|
+
},
|
|
46
|
+
payload: {},
|
|
47
|
+
signature: "DRY_RUN_SIG",
|
|
48
|
+
nonce: "DRY_RUN_NONCE",
|
|
49
|
+
timestamp: Date.now()
|
|
50
|
+
};
|
|
51
|
+
const dryRunResult = await request.harness.execute(dryRunEnvelope, request.tools, request.generatedCode);
|
|
52
|
+
if (request.specHash.includes("buy") && !JSON.stringify(dryRunResult).toLowerCase().includes("tx")) {
|
|
53
|
+
throw new Error("Behavioral anomaly detected: Intent was BUY but result lacks transaction data.");
|
|
54
|
+
}
|
|
55
|
+
console.log("✅ [AgentEvaluator] Pass 1 (Dynamic): Behavior Approved.");
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
59
|
+
throw new ByzantineFaultError(`Dynamic Pass Failed: Behavioral Dry-Run Crashed (${errMsg}). Code is hallucinatory.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (request.testResults) {
|
|
63
|
+
if (!request.testResults.pass || request.testResults.coverage < 80) {
|
|
64
|
+
throw new ByzantineFaultError(`Dynamic Pass Failed: External tests failed or coverage too low (${request.testResults.coverage}%).`);
|
|
65
|
+
}
|
|
66
|
+
console.log("✅ [AgentEvaluator] Pass 1 (Dynamic): Approved via external results.");
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.log("⚠️ [AgentEvaluator] Pass 1 (Dynamic): Skeletal Skip. No harness or evaluation context provided.");
|
|
70
|
+
}
|
|
71
|
+
let ast;
|
|
72
|
+
try {
|
|
73
|
+
ast = acorn.parse(request.generatedCode, {
|
|
74
|
+
ecmaVersion: 2022,
|
|
75
|
+
sourceType: "module",
|
|
76
|
+
allowReturnOutsideFunction: true,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
81
|
+
throw new ByzantineFaultError(`Static Pass Failed: Code parsing error (${errMsg}). Hallucination detected.`);
|
|
82
|
+
}
|
|
83
|
+
if (!ast || ast.body.length === 0) {
|
|
84
|
+
throw new ByzantineFaultError("Static Pass Failed: Empty AST structure, hallucination detected.");
|
|
85
|
+
}
|
|
86
|
+
const imports = [];
|
|
87
|
+
walkAST(ast, (node) => {
|
|
88
|
+
if (node.type === "ImportDeclaration" && typeof node.source?.value === "string") {
|
|
89
|
+
imports.push(node.source.value);
|
|
90
|
+
}
|
|
91
|
+
if (node.type === "CallExpression" && node.callee?.type === "Import" && Array.isArray(node.arguments) && node.arguments.length > 0) {
|
|
92
|
+
const arg = node.arguments[0];
|
|
93
|
+
if (arg?.type === "Literal" && typeof arg.value === "string") {
|
|
94
|
+
imports.push(arg.value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "require" && Array.isArray(node.arguments) && node.arguments.length > 0) {
|
|
98
|
+
const arg = node.arguments[0];
|
|
99
|
+
if (arg?.type === "Literal" && typeof arg.value === "string") {
|
|
100
|
+
imports.push(arg.value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (enforceBoundary) {
|
|
105
|
+
const forbiddenDomains = ["shield", "finance", "brain", "resonance", "economy"];
|
|
106
|
+
for (const imp of imports) {
|
|
107
|
+
for (const fd of forbiddenDomains) {
|
|
108
|
+
if (imp.includes(`/${fd}/`) || imp === fd) {
|
|
109
|
+
throw new ByzantineFaultError(`Static Pass Failed: Boundary violation. Agent code cannot directly import physical domain: ${fd}.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
console.log("✅ [AgentEvaluator] Pass 2 (Static AST): Approved.");
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { AgentEvaluator, ByzantineFaultError } from "./AgentEvaluator.js";
|
|
3
|
+
const passingRequest = {
|
|
4
|
+
specHash: "abc123",
|
|
5
|
+
generatedCode: 'import { foo } from "openclaw-core"; console.log(foo);',
|
|
6
|
+
testResults: { pass: true, coverage: 85 }
|
|
7
|
+
};
|
|
8
|
+
describe("AgentEvaluator", () => {
|
|
9
|
+
it("应当对通过测试的高覆盖率代码批准审计", () => {
|
|
10
|
+
const evaluator = new AgentEvaluator();
|
|
11
|
+
const result = evaluator.audit(passingRequest);
|
|
12
|
+
expect(result).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
it("应当对覆盖率低于 80% 的代码拒绝", () => {
|
|
15
|
+
const evaluator = new AgentEvaluator();
|
|
16
|
+
const request = { ...passingRequest, testResults: { pass: true, coverage: 70 } };
|
|
17
|
+
expect(() => evaluator.audit(request)).toThrow(ByzantineFaultError);
|
|
18
|
+
});
|
|
19
|
+
it("应当对测试失败的代码拒绝", () => {
|
|
20
|
+
const evaluator = new AgentEvaluator();
|
|
21
|
+
const request = { ...passingRequest, testResults: { pass: false, coverage: 90 } };
|
|
22
|
+
expect(() => evaluator.audit(request)).toThrow(ByzantineFaultError);
|
|
23
|
+
});
|
|
24
|
+
it("应当对越界导入物理域的代码拒绝", () => {
|
|
25
|
+
const evaluator = new AgentEvaluator();
|
|
26
|
+
const request = {
|
|
27
|
+
...passingRequest,
|
|
28
|
+
generatedCode: 'import { AccessToken } from "../../shield/SovereignSandbox";\nconsole.log(AccessToken);'
|
|
29
|
+
};
|
|
30
|
+
expect(() => evaluator.audit(request)).toThrow(ByzantineFaultError);
|
|
31
|
+
});
|
|
32
|
+
it("应当在指定 enforceBoundary=false 时允许物理域导入", () => {
|
|
33
|
+
const evaluator = new AgentEvaluator();
|
|
34
|
+
const request = {
|
|
35
|
+
...passingRequest,
|
|
36
|
+
generatedCode: 'import { AccessToken } from "../../shield/SovereignSandbox";\nconsole.log(AccessToken);'
|
|
37
|
+
};
|
|
38
|
+
const result = evaluator.audit(request, false);
|
|
39
|
+
expect(result).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it("应当对幻觉空 AST 拒绝", () => {
|
|
42
|
+
const evaluator = new AgentEvaluator();
|
|
43
|
+
const request = { ...passingRequest, generatedCode: '// nothing here' };
|
|
44
|
+
expect(() => evaluator.audit(request)).toThrow(ByzantineFaultError);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SAMLEnvelope } from "../common/protocols/SAML.js";
|
|
2
|
+
export interface HarnessContext {
|
|
3
|
+
intent: SAMLEnvelope;
|
|
4
|
+
tools: Record<string, unknown>;
|
|
5
|
+
memory: unknown[];
|
|
6
|
+
}
|
|
7
|
+
export declare class ScriptExecutionTimeout extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class AgenticHarness {
|
|
11
|
+
private sandbox;
|
|
12
|
+
constructor();
|
|
13
|
+
execute(intent: SAMLEnvelope, tools: Record<string, unknown>, generatedCode: string, maxRetries?: number): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import vm from "node:vm";
|
|
2
|
+
export class ScriptExecutionTimeout extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "ScriptExecutionTimeout";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class AgenticHarness {
|
|
9
|
+
sandbox;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.sandbox = vm.createContext({
|
|
12
|
+
console: {
|
|
13
|
+
log: (...args) => console.log("[Harness Sandbox]", ...args),
|
|
14
|
+
error: (...args) => console.error("[Harness Sandbox Error]", ...args),
|
|
15
|
+
warn: (...args) => console.warn("[Harness Sandbox Warn]", ...args)
|
|
16
|
+
},
|
|
17
|
+
Buffer: Buffer,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async execute(intent, tools, generatedCode, maxRetries = 3) {
|
|
21
|
+
let retries = 0;
|
|
22
|
+
let lastError = null;
|
|
23
|
+
let activeCode = generatedCode;
|
|
24
|
+
const executionContext = {
|
|
25
|
+
...this.sandbox,
|
|
26
|
+
intent,
|
|
27
|
+
tools
|
|
28
|
+
};
|
|
29
|
+
vm.createContext(executionContext);
|
|
30
|
+
while (retries < maxRetries) {
|
|
31
|
+
try {
|
|
32
|
+
const scriptBody = `
|
|
33
|
+
(async () => {
|
|
34
|
+
${activeCode}
|
|
35
|
+
})();
|
|
36
|
+
`;
|
|
37
|
+
const script = new vm.Script(scriptBody);
|
|
38
|
+
const result = await script.runInContext(executionContext, { timeout: 5000 });
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
43
|
+
retries++;
|
|
44
|
+
lastError = err instanceof Error ? err : new Error(errMsg);
|
|
45
|
+
console.warn(`⚠️ [AgenticHarness] Execution failed (Attempt ${retries}/${maxRetries}): ${errMsg}`);
|
|
46
|
+
if (errMsg.includes("Script execution timed out")) {
|
|
47
|
+
throw new ScriptExecutionTimeout("Agent execution blocked by 5000ms timeout hardware kill.");
|
|
48
|
+
}
|
|
49
|
+
if (retries >= maxRetries)
|
|
50
|
+
break;
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`AgenticHarness Autopoiesis Limit Reached. Last Error: ${lastError?.message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { AgenticHarness } from "./AgenticHarness.js";
|
|
3
|
+
describe("AgenticHarness", () => {
|
|
4
|
+
it("应当能在沙盒中调用注入的工具", async () => {
|
|
5
|
+
const harness = new AgenticHarness();
|
|
6
|
+
const log = [];
|
|
7
|
+
const tools = {
|
|
8
|
+
record: (msg) => log.push(msg),
|
|
9
|
+
};
|
|
10
|
+
const code = `tools.record("harness_test_ok");`;
|
|
11
|
+
await harness.execute({}, tools, code);
|
|
12
|
+
expect(log).toContain("harness_test_ok");
|
|
13
|
+
});
|
|
14
|
+
it("应当在 5000ms 超时时触发报错", async () => {
|
|
15
|
+
const harness = new AgenticHarness();
|
|
16
|
+
const code = `while(true) {}`;
|
|
17
|
+
await expect(harness.execute({}, {}, code)).rejects.toThrow();
|
|
18
|
+
}, 8000);
|
|
19
|
+
it("应当阻止沙盒访问 require", async () => {
|
|
20
|
+
const harness = new AgenticHarness();
|
|
21
|
+
const code = `const fs = require("fs");`;
|
|
22
|
+
await expect(harness.execute({}, {}, code)).rejects.toThrow();
|
|
23
|
+
});
|
|
24
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { BaseStateStore } from "./store/BaseStore.js";
|
|
2
|
+
export type { AgentIdentityBase } from "./store/BaseStore.js";
|
|
3
|
+
export { NullDLPManager, NullLedgerPlugin, NullVaultPlugin, NullEvolutionPlugin, NullAegisPlugin, NullEscrowPlugin, defaultPlugins, } from "./interfaces/index.js";
|
|
4
|
+
export type { IDLPManager, ILedgerPlugin, IVaultPlugin, IEvolutionPlugin, IAegisPlugin, IEscrowPlugin, PluginName, PluginMap, DLPCheckResult, DLPSeverity, AegisAction, AegisDecision, EscrowContract, EscrowStatus, } from "./interfaces/index.js";
|
|
5
|
+
export { SignalManager } from "./resonance/SignalManager.js";
|
|
6
|
+
export type { Signal, TrustedPeer } from "./resonance/SignalManager.js";
|
|
7
|
+
export { MemoryManager } from "./brain/MemoryManager.js";
|
|
8
|
+
export type { MemoryFragment, MemoryQuery } from "./brain/MemoryManager.js";
|
|
9
|
+
export { parseSAML, signSAML, verifySAML, buildSAMLEnvelope, SAMLIntent, } from "./common/protocols/SAML.js";
|
|
10
|
+
export type { SAMLEnvelope, SAMLVector } from "./common/protocols/SAML.js";
|
|
11
|
+
export { PeerRegistry } from "./services/PeerRegistry.js";
|
|
12
|
+
export { PeerDiscovery } from "./services/PeerDiscovery.js";
|
|
13
|
+
export type { PeerNode, HandshakePayload, HandshakeResponse, OutboxMessage, } from "./services/PeerRegistry.js";
|
|
14
|
+
export type { DiscoveredNode } from "./services/PeerDiscovery.js";
|
|
15
|
+
export { BoundaryChecker } from "./common/lib/BoundaryChecker.js";
|
|
16
|
+
export { VectorStore } from "./common/lib/VectorStore.js";
|
|
17
|
+
export type { VectorEntry } from "./common/lib/VectorStore.js";
|
|
18
|
+
export { EmbeddingService, DevEmbeddingProvider } from "./common/lib/EmbeddingService.js";
|
|
19
|
+
export type { IEmbeddingProvider } from "./common/lib/EmbeddingService.js";
|
|
20
|
+
export { AgentEvaluator, ByzantineFaultError } from "./harness/AgentEvaluator.js";
|
|
21
|
+
export type { CodeAuditRequest } from "./harness/AgentEvaluator.js";
|
|
22
|
+
export { AgenticHarness } from "./harness/AgenticHarness.js";
|
|
23
|
+
export type { HarnessContext } from "./harness/AgenticHarness.js";
|
|
24
|
+
export declare const OPENCLAW_CORE_VERSION = "1.1.0";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { BaseStateStore } from "./store/BaseStore.js";
|
|
2
|
+
export { NullDLPManager, NullLedgerPlugin, NullVaultPlugin, NullEvolutionPlugin, NullAegisPlugin, NullEscrowPlugin, defaultPlugins, } from "./interfaces/index.js";
|
|
3
|
+
export { SignalManager } from "./resonance/SignalManager.js";
|
|
4
|
+
export { MemoryManager } from "./brain/MemoryManager.js";
|
|
5
|
+
export { parseSAML, signSAML, verifySAML, buildSAMLEnvelope, SAMLIntent, } from "./common/protocols/SAML.js";
|
|
6
|
+
export { PeerRegistry } from "./services/PeerRegistry.js";
|
|
7
|
+
export { PeerDiscovery } from "./services/PeerDiscovery.js";
|
|
8
|
+
export { BoundaryChecker } from "./common/lib/BoundaryChecker.js";
|
|
9
|
+
export { VectorStore } from "./common/lib/VectorStore.js";
|
|
10
|
+
export { EmbeddingService, DevEmbeddingProvider } from "./common/lib/EmbeddingService.js";
|
|
11
|
+
export { AgentEvaluator, ByzantineFaultError } from "./harness/AgentEvaluator.js";
|
|
12
|
+
export { AgenticHarness } from "./harness/AgenticHarness.js";
|
|
13
|
+
export const OPENCLAW_CORE_VERSION = "1.1.0";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
export type DLPSeverity = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
2
|
+
export interface DLPCheckResult {
|
|
3
|
+
clean: boolean;
|
|
4
|
+
violations: Array<{
|
|
5
|
+
pattern: string;
|
|
6
|
+
severity: DLPSeverity;
|
|
7
|
+
matchedText: string;
|
|
8
|
+
}>;
|
|
9
|
+
sanitizedContent?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IDLPManager {
|
|
12
|
+
check(content: string): Promise<DLPCheckResult>;
|
|
13
|
+
addKeyword(keyword: string, severity: DLPSeverity): Promise<void>;
|
|
14
|
+
addRegex(pattern: string, severity: DLPSeverity): Promise<void>;
|
|
15
|
+
addPathRule(path: string): Promise<void>;
|
|
16
|
+
removeRule(pattern: string): Promise<void>;
|
|
17
|
+
getRules(): Promise<{
|
|
18
|
+
keywords: string[];
|
|
19
|
+
regexes: string[];
|
|
20
|
+
paths: string[];
|
|
21
|
+
}>;
|
|
22
|
+
getViolations(limit: number): Promise<any[]>;
|
|
23
|
+
}
|
|
24
|
+
export declare class NullDLPManager implements IDLPManager {
|
|
25
|
+
check(_content: string): Promise<DLPCheckResult>;
|
|
26
|
+
addKeyword(): Promise<void>;
|
|
27
|
+
addRegex(): Promise<void>;
|
|
28
|
+
addPathRule(): Promise<void>;
|
|
29
|
+
removeRule(): Promise<void>;
|
|
30
|
+
getRules(): Promise<{
|
|
31
|
+
keywords: never[];
|
|
32
|
+
regexes: never[];
|
|
33
|
+
paths: never[];
|
|
34
|
+
}>;
|
|
35
|
+
getViolations(_limit: number): Promise<never[]>;
|
|
36
|
+
}
|
|
37
|
+
export interface ILedgerPlugin {
|
|
38
|
+
transfer(from: string, to: string, amount: number, reason: string): Promise<{
|
|
39
|
+
txId: string;
|
|
40
|
+
}>;
|
|
41
|
+
getBalance(did: string): Promise<number>;
|
|
42
|
+
initAccount(did: string, initialBalance: number): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export declare class NullLedgerPlugin implements ILedgerPlugin {
|
|
45
|
+
transfer(_from: string, _to: string, _amount: number, _reason: string): Promise<{
|
|
46
|
+
txId: string;
|
|
47
|
+
}>;
|
|
48
|
+
getBalance(_did: string): Promise<number>;
|
|
49
|
+
initAccount(_did: string, _balance: number): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export interface IVaultPlugin {
|
|
52
|
+
set(key: string, value: string): Promise<void>;
|
|
53
|
+
get(key: string): Promise<string | null>;
|
|
54
|
+
delete(key: string): Promise<void>;
|
|
55
|
+
rotate(key: string): Promise<string>;
|
|
56
|
+
}
|
|
57
|
+
export declare class NullVaultPlugin implements IVaultPlugin {
|
|
58
|
+
private store;
|
|
59
|
+
set(key: string, value: string): Promise<void>;
|
|
60
|
+
get(key: string): Promise<string | null>;
|
|
61
|
+
delete(key: string): Promise<void>;
|
|
62
|
+
rotate(_key: string): Promise<string>;
|
|
63
|
+
}
|
|
64
|
+
export interface IEvolutionPlugin {
|
|
65
|
+
reflect(agentDid: string): Promise<void>;
|
|
66
|
+
sedimentate(db: any, memory: {
|
|
67
|
+
agent_id: string;
|
|
68
|
+
content: string;
|
|
69
|
+
importance: number;
|
|
70
|
+
tags: string[];
|
|
71
|
+
type: string;
|
|
72
|
+
linked_ids: string[];
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
getEvolutionStats(agentDid: string): Promise<{
|
|
75
|
+
wisdom_level: number;
|
|
76
|
+
success_rate: number;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
export declare class NullEvolutionPlugin implements IEvolutionPlugin {
|
|
80
|
+
reflect(_did: string): Promise<void>;
|
|
81
|
+
sedimentate(_db: any, _mem: any): Promise<void>;
|
|
82
|
+
getEvolutionStats(_did: string): Promise<{
|
|
83
|
+
wisdom_level: number;
|
|
84
|
+
success_rate: number;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
export type AegisAction = 'ALLOW' | 'BLOCK' | 'THROTTLE';
|
|
88
|
+
export interface AegisDecision {
|
|
89
|
+
action: AegisAction;
|
|
90
|
+
reason?: string;
|
|
91
|
+
score: number;
|
|
92
|
+
}
|
|
93
|
+
export interface IAegisPlugin {
|
|
94
|
+
inspect(signal: {
|
|
95
|
+
type: string;
|
|
96
|
+
payload: any;
|
|
97
|
+
sourceId: string;
|
|
98
|
+
}): Promise<AegisDecision>;
|
|
99
|
+
addRule(rule: {
|
|
100
|
+
pattern: string;
|
|
101
|
+
action: 'BLOCK' | 'THROTTLE';
|
|
102
|
+
priority: number;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
removeRule(pattern: string): Promise<void>;
|
|
105
|
+
getRules(): Promise<Array<{
|
|
106
|
+
pattern: string;
|
|
107
|
+
action: string;
|
|
108
|
+
priority: number;
|
|
109
|
+
}>>;
|
|
110
|
+
getStats(): Promise<{
|
|
111
|
+
blocked: number;
|
|
112
|
+
throttled: number;
|
|
113
|
+
allowed: number;
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
export declare class NullAegisPlugin implements IAegisPlugin {
|
|
117
|
+
inspect(_signal: any): Promise<AegisDecision>;
|
|
118
|
+
addRule(): Promise<void>;
|
|
119
|
+
removeRule(): Promise<void>;
|
|
120
|
+
getRules(): Promise<never[]>;
|
|
121
|
+
getStats(): Promise<{
|
|
122
|
+
blocked: number;
|
|
123
|
+
throttled: number;
|
|
124
|
+
allowed: number;
|
|
125
|
+
}>;
|
|
126
|
+
}
|
|
127
|
+
export interface EscrowContract {
|
|
128
|
+
fromDid: string;
|
|
129
|
+
toDid: string;
|
|
130
|
+
amount: number;
|
|
131
|
+
conditions: string[];
|
|
132
|
+
expiresAt?: Date;
|
|
133
|
+
}
|
|
134
|
+
export interface EscrowStatus {
|
|
135
|
+
id: string;
|
|
136
|
+
status: 'LOCKED' | 'RELEASED' | 'DISPUTED' | 'EXPIRED';
|
|
137
|
+
txId?: string;
|
|
138
|
+
releasedAt?: Date;
|
|
139
|
+
}
|
|
140
|
+
export interface IEscrowPlugin {
|
|
141
|
+
lock(contract: EscrowContract): Promise<string>;
|
|
142
|
+
release(contractId: string, releaserDid: string): Promise<EscrowStatus>;
|
|
143
|
+
dispute(contractId: string, disputerDid: string, evidence: string): Promise<void>;
|
|
144
|
+
getContract(contractId: string): Promise<EscrowContract | null>;
|
|
145
|
+
listActiveContracts(did: string): Promise<Array<EscrowContract & {
|
|
146
|
+
id: string;
|
|
147
|
+
}>>;
|
|
148
|
+
}
|
|
149
|
+
export declare class NullEscrowPlugin implements IEscrowPlugin {
|
|
150
|
+
private contracts;
|
|
151
|
+
lock(contract: EscrowContract): Promise<string>;
|
|
152
|
+
release(contractId: string, _releaserDid: string): Promise<EscrowStatus>;
|
|
153
|
+
dispute(_contractId: string, _disputerDid: string, _evidence: string): Promise<void>;
|
|
154
|
+
getContract(contractId: string): Promise<(EscrowContract & {
|
|
155
|
+
id: string;
|
|
156
|
+
}) | null>;
|
|
157
|
+
listActiveContracts(did: string): Promise<(EscrowContract & {
|
|
158
|
+
id: string;
|
|
159
|
+
})[]>;
|
|
160
|
+
}
|
|
161
|
+
export type PluginName = 'dlp' | 'ledger' | 'vault' | 'evolution' | 'aegis' | 'escrow';
|
|
162
|
+
export interface PluginMap {
|
|
163
|
+
dlp: IDLPManager;
|
|
164
|
+
ledger: ILedgerPlugin;
|
|
165
|
+
vault: IVaultPlugin;
|
|
166
|
+
evolution: IEvolutionPlugin;
|
|
167
|
+
aegis: IAegisPlugin;
|
|
168
|
+
escrow: IEscrowPlugin;
|
|
169
|
+
}
|
|
170
|
+
export declare const defaultPlugins: PluginMap;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export class NullDLPManager {
|
|
2
|
+
async check(_content) {
|
|
3
|
+
return { clean: true, violations: [] };
|
|
4
|
+
}
|
|
5
|
+
async addKeyword() { }
|
|
6
|
+
async addRegex() { }
|
|
7
|
+
async addPathRule() { }
|
|
8
|
+
async removeRule() { }
|
|
9
|
+
async getRules() { return { keywords: [], regexes: [], paths: [] }; }
|
|
10
|
+
async getViolations(_limit) { return []; }
|
|
11
|
+
}
|
|
12
|
+
export class NullLedgerPlugin {
|
|
13
|
+
async transfer(_from, _to, _amount, _reason) {
|
|
14
|
+
console.warn('[OpenClaw] Economy plugin not installed. Install @lobster/economy-engine for real settlements.');
|
|
15
|
+
return { txId: `null-tx-${Date.now()}` };
|
|
16
|
+
}
|
|
17
|
+
async getBalance(_did) { return 0; }
|
|
18
|
+
async initAccount(_did, _balance) { }
|
|
19
|
+
}
|
|
20
|
+
export class NullVaultPlugin {
|
|
21
|
+
store = new Map();
|
|
22
|
+
async set(key, value) { this.store.set(key, value); }
|
|
23
|
+
async get(key) { return this.store.get(key) ?? null; }
|
|
24
|
+
async delete(key) { this.store.delete(key); }
|
|
25
|
+
async rotate(_key) { return ''; }
|
|
26
|
+
}
|
|
27
|
+
export class NullEvolutionPlugin {
|
|
28
|
+
async reflect(_did) { }
|
|
29
|
+
async sedimentate(_db, _mem) { }
|
|
30
|
+
async getEvolutionStats(_did) { return { wisdom_level: 1, success_rate: 1.0 }; }
|
|
31
|
+
}
|
|
32
|
+
export class NullAegisPlugin {
|
|
33
|
+
async inspect(_signal) {
|
|
34
|
+
return { action: 'ALLOW', score: 0 };
|
|
35
|
+
}
|
|
36
|
+
async addRule() { }
|
|
37
|
+
async removeRule() { }
|
|
38
|
+
async getRules() { return []; }
|
|
39
|
+
async getStats() { return { blocked: 0, throttled: 0, allowed: 0 }; }
|
|
40
|
+
}
|
|
41
|
+
export class NullEscrowPlugin {
|
|
42
|
+
contracts = new Map();
|
|
43
|
+
async lock(contract) {
|
|
44
|
+
const id = `null-escrow-${Date.now()}`;
|
|
45
|
+
this.contracts.set(id, { ...contract, id });
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
async release(contractId, _releaserDid) {
|
|
49
|
+
this.contracts.delete(contractId);
|
|
50
|
+
return { id: contractId, status: 'RELEASED', releasedAt: new Date() };
|
|
51
|
+
}
|
|
52
|
+
async dispute(_contractId, _disputerDid, _evidence) { }
|
|
53
|
+
async getContract(contractId) { return this.contracts.get(contractId) ?? null; }
|
|
54
|
+
async listActiveContracts(did) {
|
|
55
|
+
return Array.from(this.contracts.values()).filter(c => c.fromDid === did || c.toDid === did);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export const defaultPlugins = {
|
|
59
|
+
dlp: new NullDLPManager(),
|
|
60
|
+
ledger: new NullLedgerPlugin(),
|
|
61
|
+
vault: new NullVaultPlugin(),
|
|
62
|
+
evolution: new NullEvolutionPlugin(),
|
|
63
|
+
aegis: new NullAegisPlugin(),
|
|
64
|
+
escrow: new NullEscrowPlugin(),
|
|
65
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
export interface Signal {
|
|
3
|
+
id: string;
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
type: string;
|
|
7
|
+
payload: unknown;
|
|
8
|
+
signature: string;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
encrypted?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface TrustedPeer {
|
|
13
|
+
did: string;
|
|
14
|
+
publicKey: string;
|
|
15
|
+
addedAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ISignalDatabase {
|
|
18
|
+
query(sql: string, vars?: Record<string, unknown>): Promise<any>;
|
|
19
|
+
}
|
|
20
|
+
export declare class SignalManager extends EventEmitter {
|
|
21
|
+
private agentDid;
|
|
22
|
+
private privateKey;
|
|
23
|
+
private trustedPeers;
|
|
24
|
+
private groups;
|
|
25
|
+
private db;
|
|
26
|
+
private memory;
|
|
27
|
+
constructor(agentDid: string, memory?: unknown, db?: ISignalDatabase);
|
|
28
|
+
setAgentId(did: string): void;
|
|
29
|
+
setPrivateKey(pk: string): void;
|
|
30
|
+
private sign;
|
|
31
|
+
private verify;
|
|
32
|
+
sendTo(targetDid: string, type: string, payload: unknown): Promise<Signal>;
|
|
33
|
+
sendSecure(targetDid: string, content: string): Promise<Signal>;
|
|
34
|
+
addTrustedPeer(did: string, publicKey: string): Promise<void>;
|
|
35
|
+
removePeer(did: string): void;
|
|
36
|
+
joinGroup(groupId: string): Promise<void>;
|
|
37
|
+
sync(since: number): Promise<Signal[]>;
|
|
38
|
+
queryAuditLogs(limit?: number): Promise<unknown[]>;
|
|
39
|
+
}
|