@consensus-tools/universal 0.9.0 → 0.9.1
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/dist/consensus-llm.test.d.ts +2 -0
- package/dist/consensus-llm.test.d.ts.map +1 -0
- package/dist/consensus-llm.test.js +244 -0
- package/dist/consensus-llm.test.js.map +1 -0
- package/dist/defaults.d.ts +10 -0
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +63 -2
- package/dist/defaults.js.map +1 -1
- package/dist/index.d.ts +13 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +130 -49
- package/dist/index.js.map +1 -1
- package/dist/persona-reviewer-factory.d.ts +22 -0
- package/dist/persona-reviewer-factory.d.ts.map +1 -0
- package/dist/persona-reviewer-factory.js +318 -0
- package/dist/persona-reviewer-factory.js.map +1 -0
- package/dist/reputation-manager.d.ts +38 -0
- package/dist/reputation-manager.d.ts.map +1 -0
- package/dist/reputation-manager.js +154 -0
- package/dist/reputation-manager.js.map +1 -0
- package/dist/reputation-manager.test.d.ts +2 -0
- package/dist/reputation-manager.test.d.ts.map +1 -0
- package/dist/reputation-manager.test.js +111 -0
- package/dist/reputation-manager.test.js.map +1 -0
- package/dist/risk-tiers.d.ts +10 -0
- package/dist/risk-tiers.d.ts.map +1 -0
- package/dist/risk-tiers.js +46 -0
- package/dist/risk-tiers.js.map +1 -0
- package/dist/risk-tiers.test.d.ts +2 -0
- package/dist/risk-tiers.test.d.ts.map +1 -0
- package/dist/risk-tiers.test.js +40 -0
- package/dist/risk-tiers.test.js.map +1 -0
- package/dist/types.d.ts +59 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/consensus-llm.test.ts +23 -4
- package/src/defaults.ts +10 -4
- package/src/index.ts +22 -18
- package/src/persona-reviewer-factory.ts +90 -70
- package/src/reputation-manager.ts +46 -31
- package/src/risk-tiers.test.ts +8 -0
- package/src/risk-tiers.ts +7 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus-llm.test.d.ts","sourceRoot":"","sources":["../src/consensus-llm.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { consensus } from "./index.js";
|
|
3
|
+
import { ConsensusBlockedError } from "./errors.js";
|
|
4
|
+
// ── Mock Model Adapter ──────────────────────────────────────────────
|
|
5
|
+
function createMockModel(response) {
|
|
6
|
+
return async (_messages) => response;
|
|
7
|
+
}
|
|
8
|
+
function createAllowModel() {
|
|
9
|
+
return createMockModel("VOTE: YES\nCONFIDENCE: 0.9\nRATIONALE: Looks safe to proceed.");
|
|
10
|
+
}
|
|
11
|
+
function createBlockModel() {
|
|
12
|
+
return createMockModel("VOTE: NO\nCONFIDENCE: 0.95\nRATIONALE: This action is dangerous.");
|
|
13
|
+
}
|
|
14
|
+
function createFailingModel() {
|
|
15
|
+
return async () => { throw new Error("LLM unavailable"); };
|
|
16
|
+
}
|
|
17
|
+
function createSlowModel(delayMs) {
|
|
18
|
+
return async () => {
|
|
19
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
20
|
+
return "VOTE: YES\nCONFIDENCE: 0.8\nRATIONALE: ok";
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// ── Mock Executor ────────────────────────────────────────────────────
|
|
24
|
+
function createMockExecutor() {
|
|
25
|
+
return vi.fn(async (toolName, args) => {
|
|
26
|
+
return { tool: toolName, result: "executed", args };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// ── Tests ────────────────────────────────────────────────────────────
|
|
30
|
+
describe("consensus.wrap with LLM persona mode", () => {
|
|
31
|
+
describe("backward compatibility", () => {
|
|
32
|
+
it("works without model (regex-only mode)", async () => {
|
|
33
|
+
const executor = createMockExecutor();
|
|
34
|
+
const safe = consensus.wrap(executor);
|
|
35
|
+
const result = await safe("get_weather", { city: "SF" });
|
|
36
|
+
expect(executor).toHaveBeenCalledWith("get_weather", { city: "SF" });
|
|
37
|
+
expect(result).toEqual({ tool: "get_weather", result: "executed", args: { city: "SF" } });
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("LLM persona mode - allow", () => {
|
|
41
|
+
it("allows safe tool calls when all personas vote YES", async () => {
|
|
42
|
+
const executor = createMockExecutor();
|
|
43
|
+
const safe = consensus.wrap(executor, {
|
|
44
|
+
model: createAllowModel(),
|
|
45
|
+
logger: false,
|
|
46
|
+
});
|
|
47
|
+
const result = await safe("send_email", { to: "user@test.com", body: "hello" });
|
|
48
|
+
expect(executor).toHaveBeenCalled();
|
|
49
|
+
expect(result).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe("LLM persona mode - block", () => {
|
|
53
|
+
it("blocks dangerous tool calls when personas vote NO", async () => {
|
|
54
|
+
const executor = createMockExecutor();
|
|
55
|
+
const safe = consensus.wrap(executor, {
|
|
56
|
+
model: createBlockModel(),
|
|
57
|
+
failPolicy: "closed",
|
|
58
|
+
logger: false,
|
|
59
|
+
});
|
|
60
|
+
await expect(safe("delete_database", { target: "production" })).rejects.toThrow(ConsensusBlockedError);
|
|
61
|
+
expect(executor).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("shadow mode", () => {
|
|
65
|
+
it("never blocks in shadow mode, even when personas vote NO", async () => {
|
|
66
|
+
const executor = createMockExecutor();
|
|
67
|
+
const safe = consensus.wrap(executor, {
|
|
68
|
+
model: createBlockModel(),
|
|
69
|
+
mode: "shadow",
|
|
70
|
+
logger: false,
|
|
71
|
+
});
|
|
72
|
+
const result = await safe("delete_database", { target: "production" });
|
|
73
|
+
expect(executor).toHaveBeenCalled();
|
|
74
|
+
expect(result).toBeDefined();
|
|
75
|
+
});
|
|
76
|
+
it("still fires onDecision in shadow mode", async () => {
|
|
77
|
+
const onDecision = vi.fn();
|
|
78
|
+
const executor = createMockExecutor();
|
|
79
|
+
const safe = consensus.wrap(executor, {
|
|
80
|
+
model: createBlockModel(),
|
|
81
|
+
mode: "shadow",
|
|
82
|
+
onDecision,
|
|
83
|
+
logger: false,
|
|
84
|
+
});
|
|
85
|
+
await safe("delete_database", {});
|
|
86
|
+
expect(onDecision).toHaveBeenCalled();
|
|
87
|
+
const decision = onDecision.mock.calls[0][0];
|
|
88
|
+
expect(decision.action).toBe("block");
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("fast-path (low-risk tools)", () => {
|
|
92
|
+
it("skips LLM calls for low-risk tools", async () => {
|
|
93
|
+
const modelCalls = [];
|
|
94
|
+
const model = async (msgs) => {
|
|
95
|
+
modelCalls.push(msgs);
|
|
96
|
+
return "VOTE: YES\nCONFIDENCE: 0.9\nRATIONALE: ok";
|
|
97
|
+
};
|
|
98
|
+
const executor = createMockExecutor();
|
|
99
|
+
const safe = consensus.wrap(executor, { model, logger: false });
|
|
100
|
+
await safe("get_weather", { city: "SF" });
|
|
101
|
+
// Low-risk tool should not trigger LLM calls
|
|
102
|
+
expect(modelCalls.length).toBe(0);
|
|
103
|
+
expect(executor).toHaveBeenCalled();
|
|
104
|
+
});
|
|
105
|
+
it("runs full LLM deliberation for high-risk tools", async () => {
|
|
106
|
+
const modelCalls = [];
|
|
107
|
+
const model = async (msgs) => {
|
|
108
|
+
modelCalls.push(msgs);
|
|
109
|
+
return "VOTE: YES\nCONFIDENCE: 0.9\nRATIONALE: ok";
|
|
110
|
+
};
|
|
111
|
+
const executor = createMockExecutor();
|
|
112
|
+
const safe = consensus.wrap(executor, { model, logger: false });
|
|
113
|
+
await safe("send_email", { to: "user@test.com" });
|
|
114
|
+
// High-risk tool should trigger 3 LLM calls (one per persona)
|
|
115
|
+
expect(modelCalls.length).toBe(3);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("LLM failure fallback", () => {
|
|
119
|
+
it("falls back to regex when all LLM calls fail", async () => {
|
|
120
|
+
const executor = createMockExecutor();
|
|
121
|
+
const safe = consensus.wrap(executor, {
|
|
122
|
+
model: createFailingModel(),
|
|
123
|
+
failPolicy: "open",
|
|
124
|
+
logger: false,
|
|
125
|
+
});
|
|
126
|
+
// Should not throw, should fall back to regex and likely allow
|
|
127
|
+
const result = await safe("send_email", { to: "user@test.com", body: "hello" });
|
|
128
|
+
expect(result).toBeDefined();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe("per-persona timeout", () => {
|
|
132
|
+
it("falls back to regex for timed-out personas and blocks (fail-closed)", async () => {
|
|
133
|
+
const onDecision = vi.fn();
|
|
134
|
+
const executor = createMockExecutor();
|
|
135
|
+
const safe = consensus.wrap(executor, {
|
|
136
|
+
model: createSlowModel(5000),
|
|
137
|
+
personaTimeout: 100,
|
|
138
|
+
onDecision,
|
|
139
|
+
logger: false,
|
|
140
|
+
});
|
|
141
|
+
// LLM times out, regex fallback votes NO (fail-closed), tool is blocked
|
|
142
|
+
await expect(safe("send_email", { to: "user@test.com" })).rejects.toThrow(ConsensusBlockedError);
|
|
143
|
+
expect(executor).not.toHaveBeenCalled();
|
|
144
|
+
// onDecision should still fire with regex_fallback votes
|
|
145
|
+
expect(onDecision).toHaveBeenCalled();
|
|
146
|
+
const decision = onDecision.mock.calls[0][0];
|
|
147
|
+
expect(decision.votes.every((v) => v.source === "regex_fallback")).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
it("allows with failPolicy open when LLM times out", async () => {
|
|
150
|
+
const executor = createMockExecutor();
|
|
151
|
+
const safe = consensus.wrap(executor, {
|
|
152
|
+
model: createSlowModel(5000),
|
|
153
|
+
personaTimeout: 100,
|
|
154
|
+
failPolicy: "open",
|
|
155
|
+
logger: false,
|
|
156
|
+
});
|
|
157
|
+
// failPolicy open: even if regex fallback blocks, tool executes
|
|
158
|
+
const result = await safe("send_email", { to: "user@test.com" });
|
|
159
|
+
expect(result).toBeDefined();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe("onDecision callback", () => {
|
|
163
|
+
it("receives LlmDecisionResult with vote breakdown", async () => {
|
|
164
|
+
const onDecision = vi.fn();
|
|
165
|
+
const executor = createMockExecutor();
|
|
166
|
+
const safe = consensus.wrap(executor, {
|
|
167
|
+
model: createAllowModel(),
|
|
168
|
+
onDecision,
|
|
169
|
+
logger: false,
|
|
170
|
+
});
|
|
171
|
+
await safe("send_email", { to: "test@test.com" });
|
|
172
|
+
expect(onDecision).toHaveBeenCalledTimes(1);
|
|
173
|
+
const decision = onDecision.mock.calls[0][0];
|
|
174
|
+
expect(decision.decisionId).toBeDefined();
|
|
175
|
+
expect(decision.action).toBe("allow");
|
|
176
|
+
expect(decision.votes.length).toBe(3);
|
|
177
|
+
expect(decision.votes[0]).toHaveProperty("personaId");
|
|
178
|
+
expect(decision.votes[0]).toHaveProperty("personaName");
|
|
179
|
+
expect(decision.votes[0]).toHaveProperty("vote");
|
|
180
|
+
expect(decision.votes[0]).toHaveProperty("confidence");
|
|
181
|
+
expect(decision.votes[0]).toHaveProperty("rationale");
|
|
182
|
+
expect(decision.votes[0]).toHaveProperty("source");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("persona pack selection", () => {
|
|
186
|
+
it("uses governance pack when configured", async () => {
|
|
187
|
+
const executor = createMockExecutor();
|
|
188
|
+
// governance pack has 5 personas, should trigger 5 LLM calls
|
|
189
|
+
const modelCalls = [];
|
|
190
|
+
const model = async (msgs) => {
|
|
191
|
+
modelCalls.push(msgs);
|
|
192
|
+
return "VOTE: YES\nCONFIDENCE: 0.8\nRATIONALE: ok";
|
|
193
|
+
};
|
|
194
|
+
const safe = consensus.wrap(executor, {
|
|
195
|
+
model,
|
|
196
|
+
pack: "governance",
|
|
197
|
+
logger: false,
|
|
198
|
+
});
|
|
199
|
+
await safe("send_email", { to: "test@test.com" });
|
|
200
|
+
expect(modelCalls.length).toBe(5); // governance pack has 5 personas
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe("custom risk tiers", () => {
|
|
204
|
+
it("respects user-defined risk tier overrides", async () => {
|
|
205
|
+
const modelCalls = [];
|
|
206
|
+
const model = async (msgs) => {
|
|
207
|
+
modelCalls.push(msgs);
|
|
208
|
+
return "VOTE: YES\nCONFIDENCE: 0.9\nRATIONALE: ok";
|
|
209
|
+
};
|
|
210
|
+
const executor = createMockExecutor();
|
|
211
|
+
const safe = consensus.wrap(executor, {
|
|
212
|
+
model,
|
|
213
|
+
riskTiers: { get_weather: "high" }, // Override: treat read-only as high-risk
|
|
214
|
+
logger: false,
|
|
215
|
+
});
|
|
216
|
+
await safe("get_weather", { city: "SF" });
|
|
217
|
+
// Should have triggered LLM calls because we overrode to high-risk
|
|
218
|
+
expect(modelCalls.length).toBe(3);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
describe("consensus.wrap with LLM - policy support", () => {
|
|
223
|
+
it("accepts core policy names", async () => {
|
|
224
|
+
const executor = createMockExecutor();
|
|
225
|
+
const safe = consensus.wrap(executor, {
|
|
226
|
+
model: createAllowModel(),
|
|
227
|
+
policy: "WEIGHTED_REPUTATION",
|
|
228
|
+
logger: false,
|
|
229
|
+
});
|
|
230
|
+
const result = await safe("send_email", { to: "test@test.com" });
|
|
231
|
+
expect(result).toBeDefined();
|
|
232
|
+
});
|
|
233
|
+
it("accepts friendly policy names", async () => {
|
|
234
|
+
const executor = createMockExecutor();
|
|
235
|
+
const safe = consensus.wrap(executor, {
|
|
236
|
+
model: createAllowModel(),
|
|
237
|
+
policy: "weighted_reputation",
|
|
238
|
+
logger: false,
|
|
239
|
+
});
|
|
240
|
+
const result = await safe("send_email", { to: "test@test.com" });
|
|
241
|
+
expect(result).toBeDefined();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
//# sourceMappingURL=consensus-llm.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus-llm.test.js","sourceRoot":"","sources":["../src/consensus-llm.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EA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,EAAE,eAAe,EAAE,CAAC,CAAC;QACjE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -4,9 +4,19 @@ export { DEFAULT_PERSONA_TRIO } from "@consensus-tools/guards";
|
|
|
4
4
|
export declare const DEFAULT_GUARD = "agent_action";
|
|
5
5
|
export declare const DEFAULT_POLICY = "majority";
|
|
6
6
|
export declare const DEFAULT_PERSONA_COUNT = 3;
|
|
7
|
+
export declare const DEFAULT_PACK = "default";
|
|
8
|
+
export declare const DEFAULT_PERSONA_TIMEOUT_MS = 3000;
|
|
9
|
+
export declare const DEFAULT_RESPAWN_THRESHOLD = 0.15;
|
|
7
10
|
export declare const DEFAULTS: Required<Pick<UniversalConfig, "policy" | "guards" | "failPolicy" | "storage" | "logger">>;
|
|
11
|
+
export declare const CORE_POLICY_TYPES: Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a policy string to a core policy type name for LLM mode.
|
|
14
|
+
* Accepts friendly names, core names, and threshold:X patterns.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolvePolicyType(policy: string): string;
|
|
8
17
|
/**
|
|
9
18
|
* Maps a user-facing policy name to a wrapper StrategyConfig.
|
|
19
|
+
* Used in regex-only mode (no model provided).
|
|
10
20
|
*
|
|
11
21
|
* Supported names:
|
|
12
22
|
* 'majority' -> { strategy: 'majority' }
|
package/dist/defaults.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAI/D,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAC5C,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,qBAAqB,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAI/D,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAC5C,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,YAAY,YAAY,CAAC;AACtC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAC/C,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAE9C,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAC7B,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC,CAOjF,CAAC;AAOF,eAAO,MAAM,iBAAiB,aAU5B,CAAC;AAiBH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBxD;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAoC/D"}
|
package/dist/defaults.js
CHANGED
|
@@ -4,6 +4,9 @@ export { DEFAULT_PERSONA_TRIO } from "@consensus-tools/guards";
|
|
|
4
4
|
export const DEFAULT_GUARD = "agent_action";
|
|
5
5
|
export const DEFAULT_POLICY = "majority";
|
|
6
6
|
export const DEFAULT_PERSONA_COUNT = 3;
|
|
7
|
+
export const DEFAULT_PACK = "default";
|
|
8
|
+
export const DEFAULT_PERSONA_TIMEOUT_MS = 3000;
|
|
9
|
+
export const DEFAULT_RESPAWN_THRESHOLD = 0.15;
|
|
7
10
|
export const DEFAULTS = {
|
|
8
11
|
policy: DEFAULT_POLICY,
|
|
9
12
|
guards: [DEFAULT_GUARD],
|
|
@@ -11,9 +14,59 @@ export const DEFAULTS = {
|
|
|
11
14
|
storage: "memory",
|
|
12
15
|
logger: true,
|
|
13
16
|
};
|
|
14
|
-
// ── Policy
|
|
17
|
+
// ── Core Policy Type Names ───────────────────────────────────────────
|
|
18
|
+
// All 9 policies supported by resolveConsensus() in @consensus-tools/core.
|
|
19
|
+
// These are used in LLM mode where we bypass the wrapper and call
|
|
20
|
+
// resolveConsensus() directly.
|
|
21
|
+
export const CORE_POLICY_TYPES = new Set([
|
|
22
|
+
"FIRST_SUBMISSION_WINS",
|
|
23
|
+
"HIGHEST_CONFIDENCE_SINGLE",
|
|
24
|
+
"APPROVAL_VOTE",
|
|
25
|
+
"OWNER_PICK",
|
|
26
|
+
"TOP_K_SPLIT",
|
|
27
|
+
"MAJORITY_VOTE",
|
|
28
|
+
"WEIGHTED_VOTE_SIMPLE",
|
|
29
|
+
"WEIGHTED_REPUTATION",
|
|
30
|
+
"TRUSTED_ARBITER",
|
|
31
|
+
]);
|
|
32
|
+
// ── Friendly → Core Policy Mapping ───────────────────────────────────
|
|
33
|
+
// Maps friendly names (used in facade config) to core policy type names.
|
|
34
|
+
const FRIENDLY_TO_CORE = {
|
|
35
|
+
majority: "MAJORITY_VOTE",
|
|
36
|
+
supermajority: "APPROVAL_VOTE",
|
|
37
|
+
unanimous: "APPROVAL_VOTE",
|
|
38
|
+
weighted_reputation: "WEIGHTED_REPUTATION",
|
|
39
|
+
first_wins: "FIRST_SUBMISSION_WINS",
|
|
40
|
+
highest_confidence: "HIGHEST_CONFIDENCE_SINGLE",
|
|
41
|
+
top_k: "TOP_K_SPLIT",
|
|
42
|
+
owner_pick: "OWNER_PICK",
|
|
43
|
+
arbiter: "TRUSTED_ARBITER",
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a policy string to a core policy type name for LLM mode.
|
|
47
|
+
* Accepts friendly names, core names, and threshold:X patterns.
|
|
48
|
+
*/
|
|
49
|
+
export function resolvePolicyType(policy) {
|
|
50
|
+
// Direct core policy name
|
|
51
|
+
if (CORE_POLICY_TYPES.has(policy))
|
|
52
|
+
return policy;
|
|
53
|
+
// Friendly name mapping
|
|
54
|
+
const mapped = FRIENDLY_TO_CORE[policy];
|
|
55
|
+
if (mapped)
|
|
56
|
+
return mapped;
|
|
57
|
+
// threshold:X -> APPROVAL_VOTE with custom config
|
|
58
|
+
if (policy.startsWith("threshold:"))
|
|
59
|
+
return "APPROVAL_VOTE";
|
|
60
|
+
// Unknown policy — warn and fall back
|
|
61
|
+
console.warn(// eslint-disable-line no-console
|
|
62
|
+
`[consensus] Unknown LLM policy "${policy}", falling back to MAJORITY_VOTE. ` +
|
|
63
|
+
`Valid: ${[...CORE_POLICY_TYPES].join(", ")} or friendly names: ${Object.keys(FRIENDLY_TO_CORE).join(", ")}`);
|
|
64
|
+
return "MAJORITY_VOTE";
|
|
65
|
+
}
|
|
66
|
+
// ── Policy-to-Strategy Mapping (regex mode) ──────────────────────────
|
|
15
67
|
/**
|
|
16
68
|
* Maps a user-facing policy name to a wrapper StrategyConfig.
|
|
69
|
+
* Used in regex-only mode (no model provided).
|
|
17
70
|
*
|
|
18
71
|
* Supported names:
|
|
19
72
|
* 'majority' -> { strategy: 'majority' }
|
|
@@ -40,8 +93,16 @@ export function policyToStrategy(policy) {
|
|
|
40
93
|
}
|
|
41
94
|
return { strategy: "threshold", threshold: value };
|
|
42
95
|
}
|
|
96
|
+
// LLM-mode policy used without a model — warn loudly, this is a config mistake
|
|
97
|
+
if (CORE_POLICY_TYPES.has(policy) || FRIENDLY_TO_CORE[policy]) {
|
|
98
|
+
console.warn(// eslint-disable-line no-console
|
|
99
|
+
`[consensus] Policy "${policy}" requires LLM mode (provide a model). ` +
|
|
100
|
+
`Falling back to majority in regex mode. This may not match your intended security posture.`);
|
|
101
|
+
return { strategy: "majority" };
|
|
102
|
+
}
|
|
43
103
|
throw new ConfigError(`Unknown policy "${policy}". ` +
|
|
44
|
-
`Supported: 'majority', 'supermajority', 'unanimous', 'threshold:X' (where X is 0-1).`
|
|
104
|
+
`Supported: 'majority', 'supermajority', 'unanimous', 'threshold:X' (where X is 0-1).` +
|
|
105
|
+
` For LLM mode, also: ${[...CORE_POLICY_TYPES].join(", ")}.`);
|
|
45
106
|
}
|
|
46
107
|
}
|
|
47
108
|
}
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,wEAAwE;AAExE,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,wEAAwE;AAExE,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;AACtC,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAC/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAE9C,MAAM,CAAC,MAAM,QAAQ,GAEjB;IACF,MAA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sFAAsF;gBACtF,wBAAwB,CAAC,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7D,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ export declare const consensus: {
|
|
|
3
3
|
/**
|
|
4
4
|
* Wrap any tool executor with consensus governance.
|
|
5
5
|
*
|
|
6
|
+
* Two modes:
|
|
7
|
+
* - **Regex mode** (default): Fast, deterministic pattern-matching guards.
|
|
8
|
+
* `consensus.wrap(executor)` or `consensus.wrap(executor, { policy: "majority" })`
|
|
9
|
+
*
|
|
10
|
+
* - **LLM persona mode**: Multi-model deliberation with reputation tracking.
|
|
11
|
+
* `consensus.wrap(executor, { model: myLlm, policy: "weighted_reputation" })`
|
|
12
|
+
* Activated when `model` is provided in config.
|
|
13
|
+
*
|
|
6
14
|
* @param wrappable - A function, or object with .execute/.invoke/.call
|
|
7
15
|
* @param config - Optional configuration overrides
|
|
8
16
|
* @returns A wrapped function that runs consensus deliberation before allowing execution
|
|
@@ -10,15 +18,6 @@ export declare const consensus: {
|
|
|
10
18
|
wrap(wrappable: Wrappable, config?: Partial<UniversalConfig>): ToolExecutor;
|
|
11
19
|
/**
|
|
12
20
|
* LangChain adapter — dynamically loads @consensus-tools/langchain.
|
|
13
|
-
*
|
|
14
|
-
* Returns a `ConsensusGuardCallbackHandler` that intercepts all tool calls and
|
|
15
|
-
* runs them through consensus deliberation. Attach it to your chain or agent
|
|
16
|
-
* via the `callbacks` option to govern all tool calls:
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const handler = await consensus.langchain(null, { policy: "majority" });
|
|
20
|
-
* const result = await agent.invoke({ input: "..." }, { callbacks: [handler] });
|
|
21
|
-
* ```
|
|
22
21
|
*/
|
|
23
22
|
langchain(_chain: unknown, config?: Partial<UniversalConfig>): Promise<unknown>;
|
|
24
23
|
/**
|
|
@@ -31,8 +30,11 @@ export declare const consensus: {
|
|
|
31
30
|
mcp(config?: Partial<UniversalConfig>): Promise<unknown>;
|
|
32
31
|
};
|
|
33
32
|
export { resolveWrappable } from "./resolve.js";
|
|
34
|
-
export { policyToStrategy, DEFAULTS, DEFAULT_GUARD, DEFAULT_POLICY, DEFAULT_PERSONA_TRIO, DEFAULT_PERSONA_COUNT } from "./defaults.js";
|
|
33
|
+
export { policyToStrategy, resolvePolicyType, DEFAULTS, DEFAULT_GUARD, DEFAULT_POLICY, DEFAULT_PERSONA_TRIO, DEFAULT_PERSONA_COUNT, DEFAULT_PACK } from "./defaults.js";
|
|
35
34
|
export { createLogger } from "./logger.js";
|
|
36
35
|
export { ConsensusBlockedError, MissingDependencyError, ConfigError } from "./errors.js";
|
|
37
|
-
export
|
|
36
|
+
export { ReputationManager } from "./reputation-manager.js";
|
|
37
|
+
export { classifyTool } from "./risk-tiers.js";
|
|
38
|
+
export { deliberate } from "./persona-reviewer-factory.js";
|
|
39
|
+
export type { Wrappable, ToolExecutor, UniversalConfig, FailPolicy, ExecutionMode, LogEvent, ModelAdapter, ModelMessage, LlmDecisionResult, FeedbackSignal, RiskTier, RiskTierMap, } from "./types.js";
|
|
38
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AA+M9F,eAAO,MAAM,SAAS;IACpB;;;;;;;;;;;;;;OAcG;oBAEU,SAAS,WACX,OAAO,CAAC,eAAe,CAAC,GAChC,YAAY;IAmFf;;OAEG;sBACqB,OAAO,WAAW,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAy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