@neuroverseos/governance 0.2.3 → 0.3.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/package.json +4 -2
- package/policies/content-moderation-rules.txt +8 -0
- package/policies/marketing-rules.txt +8 -0
- package/policies/science-research-rules.txt +11 -0
- package/policies/social-media-rules.txt +7 -0
- package/policies/strict-rules.txt +8 -0
- package/policies/trading-rules.txt +8 -0
- package/simulate.html +1899 -0
- package/dist/adapters/autoresearch.cjs +0 -196
- package/dist/adapters/autoresearch.d.cts +0 -103
- package/dist/adapters/autoresearch.d.ts +0 -103
- package/dist/adapters/autoresearch.js +0 -7
- package/dist/adapters/deep-agents.cjs +0 -1472
- package/dist/adapters/deep-agents.d.cts +0 -181
- package/dist/adapters/deep-agents.d.ts +0 -181
- package/dist/adapters/deep-agents.js +0 -17
- package/dist/adapters/express.cjs +0 -1196
- package/dist/adapters/express.d.cts +0 -66
- package/dist/adapters/express.d.ts +0 -66
- package/dist/adapters/express.js +0 -12
- package/dist/adapters/index.cjs +0 -2038
- package/dist/adapters/index.d.cts +0 -8
- package/dist/adapters/index.d.ts +0 -8
- package/dist/adapters/index.js +0 -68
- package/dist/adapters/langchain.cjs +0 -1259
- package/dist/adapters/langchain.d.cts +0 -89
- package/dist/adapters/langchain.d.ts +0 -89
- package/dist/adapters/langchain.js +0 -17
- package/dist/adapters/openai.cjs +0 -1289
- package/dist/adapters/openai.d.cts +0 -99
- package/dist/adapters/openai.d.ts +0 -99
- package/dist/adapters/openai.js +0 -17
- package/dist/adapters/openclaw.cjs +0 -1281
- package/dist/adapters/openclaw.d.cts +0 -99
- package/dist/adapters/openclaw.d.ts +0 -99
- package/dist/adapters/openclaw.js +0 -17
- package/dist/bootstrap-GXVDZNF7.js +0 -114
- package/dist/build-X5MZY4IA.js +0 -339
- package/dist/chunk-4L6OPKMQ.js +0 -100
- package/dist/chunk-4NGDRRQH.js +0 -10
- package/dist/chunk-5U2MQO5P.js +0 -57
- package/dist/chunk-6BB55YJI.js +0 -113
- package/dist/chunk-6CZSKEY5.js +0 -164
- package/dist/chunk-7P3S7MAY.js +0 -1090
- package/dist/chunk-A5W4GNQO.js +0 -130
- package/dist/chunk-AF2VX4AL.js +0 -363
- package/dist/chunk-AKW5YVCE.js +0 -96
- package/dist/chunk-BMOXICAB.js +0 -340
- package/dist/chunk-BQZMOEML.js +0 -43
- package/dist/chunk-D2UCV5AK.js +0 -326
- package/dist/chunk-EVDJUSZ2.js +0 -91
- package/dist/chunk-FYS2CBUW.js +0 -304
- package/dist/chunk-I3RRAYK2.js +0 -11
- package/dist/chunk-IZSO75NZ.js +0 -792
- package/dist/chunk-JCKSW2PZ.js +0 -304
- package/dist/chunk-JZPQGIKR.js +0 -79
- package/dist/chunk-KTFTTLTP.js +0 -246
- package/dist/chunk-MH7BT4VH.js +0 -15
- package/dist/chunk-ORJ3NOE6.js +0 -622
- package/dist/chunk-OT6PXH54.js +0 -61
- package/dist/chunk-Q6O7ZLO2.js +0 -62
- package/dist/chunk-QLPTHTVB.js +0 -253
- package/dist/chunk-REXY4LUL.js +0 -226
- package/dist/chunk-T5EUJQE5.js +0 -172
- package/dist/chunk-TTBKTF3P.js +0 -608
- package/dist/chunk-XPDMYECO.js +0 -642
- package/dist/chunk-YZFATT7X.js +0 -9
- package/dist/chunk-ZIVQNSZU.js +0 -119
- package/dist/chunk-ZJTDUCC2.js +0 -194
- package/dist/cli/neuroverse.cjs +0 -12564
- package/dist/cli/neuroverse.d.cts +0 -1
- package/dist/cli/neuroverse.d.ts +0 -1
- package/dist/cli/neuroverse.js +0 -208
- package/dist/cli/plan.cjs +0 -1686
- package/dist/cli/plan.d.cts +0 -20
- package/dist/cli/plan.d.ts +0 -20
- package/dist/cli/plan.js +0 -353
- package/dist/cli/run.cjs +0 -1945
- package/dist/cli/run.d.cts +0 -20
- package/dist/cli/run.d.ts +0 -20
- package/dist/cli/run.js +0 -143
- package/dist/configure-ai-TK67ZWZL.js +0 -132
- package/dist/decision-flow-LETV5NWY.js +0 -61
- package/dist/derive-7365SUFU.js +0 -152
- package/dist/doctor-QYISMKEL.js +0 -173
- package/dist/equity-penalties-63FGB3I2.js +0 -244
- package/dist/explain-A2EWI2OL.js +0 -51
- package/dist/guard-3BWL3IGH.js +0 -92
- package/dist/guard-contract-C9_zKbzd.d.cts +0 -821
- package/dist/guard-contract-C9_zKbzd.d.ts +0 -821
- package/dist/guard-engine-QFMIBWJY.js +0 -10
- package/dist/impact-UB6DXKSX.js +0 -59
- package/dist/improve-XZA57GER.js +0 -66
- package/dist/index.cjs +0 -6821
- package/dist/index.d.cts +0 -1829
- package/dist/index.d.ts +0 -1829
- package/dist/index.js +0 -430
- package/dist/infer-world-7GVZWFX4.js +0 -543
- package/dist/init-PKPIYHYE.js +0 -144
- package/dist/init-world-VWMQZQC7.js +0 -223
- package/dist/mcp-server-XWQZXNW7.js +0 -13
- package/dist/model-adapter-BB7G4MFI.js +0 -11
- package/dist/playground-ADWZORNV.js +0 -550
- package/dist/redteam-JRQ7FD2F.js +0 -357
- package/dist/session-MMYX5YCF.js +0 -15
- package/dist/shared--Q8wPBVN.d.ts +0 -60
- package/dist/shared-HpAG90PX.d.cts +0 -60
- package/dist/shared-U2QFV7JH.js +0 -16
- package/dist/simulate-GMIFFXYV.js +0 -83
- package/dist/test-JBBZ65X4.js +0 -217
- package/dist/trace-3MYWIDEF.js +0 -166
- package/dist/validate-LLBWVPGV.js +0 -81
- package/dist/validate-engine-UIABSIHD.js +0 -7
- package/dist/world-BFJCIQSH.js +0 -378
- package/dist/world-loader-HMPTOEA2.js +0 -9
- package/dist/worlds/autoresearch.nv-world.md +0 -230
- package/dist/worlds/coding-agent.nv-world.md +0 -211
- package/dist/worlds/derivation-world.nv-world.md +0 -278
package/dist/chunk-Q6O7ZLO2.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// src/providers/ai-provider.ts
|
|
2
|
-
var ChatCompletionsProvider = class {
|
|
3
|
-
model;
|
|
4
|
-
apiKey;
|
|
5
|
-
endpoint;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.model = config.model;
|
|
8
|
-
this.apiKey = config.apiKey;
|
|
9
|
-
this.endpoint = config.endpoint ?? "https://api.openai.com/v1/chat/completions";
|
|
10
|
-
}
|
|
11
|
-
async complete(systemPrompt, userPrompt) {
|
|
12
|
-
const body = {
|
|
13
|
-
model: this.model,
|
|
14
|
-
messages: [
|
|
15
|
-
{ role: "system", content: systemPrompt },
|
|
16
|
-
{ role: "user", content: userPrompt }
|
|
17
|
-
],
|
|
18
|
-
temperature: 0.2,
|
|
19
|
-
max_tokens: 16384
|
|
20
|
-
};
|
|
21
|
-
const response = await fetch(this.endpoint, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: {
|
|
24
|
-
"Content-Type": "application/json",
|
|
25
|
-
"Authorization": `Bearer ${this.apiKey}`
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify(body)
|
|
28
|
-
});
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
const text = await response.text().catch(() => "");
|
|
31
|
-
throw new Error(`Provider returned ${response.status}: ${text.slice(0, 200)}`);
|
|
32
|
-
}
|
|
33
|
-
const data = await response.json();
|
|
34
|
-
const content = data?.choices?.[0]?.message?.content;
|
|
35
|
-
if (!content) {
|
|
36
|
-
throw new Error("Provider returned empty response \u2014 no content in choices[0].message.content");
|
|
37
|
-
}
|
|
38
|
-
return content;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
function createProvider(config) {
|
|
42
|
-
return new ChatCompletionsProvider(config);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/contracts/derive-contract.ts
|
|
46
|
-
var DERIVE_EXIT_CODES = {
|
|
47
|
-
SUCCESS: 0,
|
|
48
|
-
VALIDATION_FAIL: 1,
|
|
49
|
-
INPUT_ERROR: 2,
|
|
50
|
-
PROVIDER_ERROR: 3
|
|
51
|
-
};
|
|
52
|
-
var CONFIGURE_AI_EXIT_CODES = {
|
|
53
|
-
SUCCESS: 0,
|
|
54
|
-
VALIDATION_FAIL: 1,
|
|
55
|
-
ERROR: 3
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
createProvider,
|
|
60
|
-
DERIVE_EXIT_CODES,
|
|
61
|
-
CONFIGURE_AI_EXIT_CODES
|
|
62
|
-
};
|
package/dist/chunk-QLPTHTVB.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
// src/engine/text-utils.ts
|
|
2
|
-
function normalizeEventText(event) {
|
|
3
|
-
return [
|
|
4
|
-
event.intent,
|
|
5
|
-
event.tool ?? "",
|
|
6
|
-
event.scope ?? ""
|
|
7
|
-
].join(" ").toLowerCase();
|
|
8
|
-
}
|
|
9
|
-
function extractKeywords(text, minLength = 3) {
|
|
10
|
-
return text.toLowerCase().split(/\s+/).filter((w) => w.length > minLength);
|
|
11
|
-
}
|
|
12
|
-
function matchesAllKeywords(eventText, ruleText) {
|
|
13
|
-
const keywords = extractKeywords(ruleText);
|
|
14
|
-
if (keywords.length === 0) return false;
|
|
15
|
-
return keywords.every((kw) => eventText.includes(kw));
|
|
16
|
-
}
|
|
17
|
-
function matchesKeywordThreshold(eventText, ruleText, threshold = 0.5) {
|
|
18
|
-
const keywords = extractKeywords(ruleText);
|
|
19
|
-
if (keywords.length === 0) return false;
|
|
20
|
-
const matched = keywords.filter((kw) => eventText.includes(kw));
|
|
21
|
-
return matched.length >= Math.ceil(keywords.length * threshold);
|
|
22
|
-
}
|
|
23
|
-
function tokenSimilarity(a, b) {
|
|
24
|
-
const tokensA = new Set(a.toLowerCase().split(/\s+/).filter((w) => w.length > 2));
|
|
25
|
-
const tokensB = new Set(b.toLowerCase().split(/\s+/).filter((w) => w.length > 2));
|
|
26
|
-
if (tokensA.size === 0 || tokensB.size === 0) return 0;
|
|
27
|
-
let intersection = 0;
|
|
28
|
-
for (const t of tokensA) {
|
|
29
|
-
if (tokensB.has(t)) intersection++;
|
|
30
|
-
}
|
|
31
|
-
const union = (/* @__PURE__ */ new Set([...tokensA, ...tokensB])).size;
|
|
32
|
-
return union > 0 ? intersection / union : 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/engine/plan-engine.ts
|
|
36
|
-
function keywordMatch(eventText, step) {
|
|
37
|
-
const stepText = [
|
|
38
|
-
step.label,
|
|
39
|
-
step.description ?? "",
|
|
40
|
-
...step.tags ?? []
|
|
41
|
-
].join(" ");
|
|
42
|
-
return matchesKeywordThreshold(eventText, stepText, 0.5);
|
|
43
|
-
}
|
|
44
|
-
function tokenSimilarity2(a, b) {
|
|
45
|
-
return tokenSimilarity(a, b);
|
|
46
|
-
}
|
|
47
|
-
function findMatchingStep(eventText, event, steps) {
|
|
48
|
-
const pendingOrActive = steps.filter((s) => s.status === "pending" || s.status === "active");
|
|
49
|
-
if (pendingOrActive.length === 0) {
|
|
50
|
-
return { matched: null, closest: null, closestScore: 0 };
|
|
51
|
-
}
|
|
52
|
-
for (const step of pendingOrActive) {
|
|
53
|
-
if (keywordMatch(eventText, step)) {
|
|
54
|
-
if (step.tools && event.tool && !step.tools.includes(event.tool)) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
return { matched: step, closest: step, closestScore: 1 };
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const intentText = [event.intent, event.tool ?? "", event.scope ?? ""].join(" ");
|
|
61
|
-
let bestStep = null;
|
|
62
|
-
let bestScore = 0;
|
|
63
|
-
for (const step of pendingOrActive) {
|
|
64
|
-
const stepText = [step.label, step.description ?? "", ...step.tags ?? []].join(" ");
|
|
65
|
-
const score = tokenSimilarity2(intentText, stepText);
|
|
66
|
-
if (score > bestScore) {
|
|
67
|
-
bestScore = score;
|
|
68
|
-
bestStep = step;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const SIMILARITY_THRESHOLD = 0.35;
|
|
72
|
-
if (bestScore >= SIMILARITY_THRESHOLD && bestStep) {
|
|
73
|
-
if (bestStep.tools && event.tool && !bestStep.tools.includes(event.tool)) {
|
|
74
|
-
return { matched: null, closest: bestStep, closestScore: bestScore };
|
|
75
|
-
}
|
|
76
|
-
return { matched: bestStep, closest: bestStep, closestScore: bestScore };
|
|
77
|
-
}
|
|
78
|
-
return { matched: null, closest: bestStep, closestScore: bestScore };
|
|
79
|
-
}
|
|
80
|
-
function isSequenceValid(step, plan) {
|
|
81
|
-
if (!plan.sequential) return true;
|
|
82
|
-
if (!step.requires || step.requires.length === 0) return true;
|
|
83
|
-
return step.requires.every((reqId) => {
|
|
84
|
-
const reqStep = plan.steps.find((s) => s.id === reqId);
|
|
85
|
-
return reqStep?.status === "completed";
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
function checkConstraints(event, eventText, constraints) {
|
|
89
|
-
const checks = [];
|
|
90
|
-
for (const constraint of constraints) {
|
|
91
|
-
if (constraint.type === "approval") {
|
|
92
|
-
if (constraint.trigger && eventText.includes(constraint.trigger.substring(0, 10).toLowerCase())) {
|
|
93
|
-
checks.push({ constraintId: constraint.id, passed: false, reason: constraint.description });
|
|
94
|
-
return { violated: constraint, checks };
|
|
95
|
-
}
|
|
96
|
-
const keywords = constraint.description.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
|
|
97
|
-
const relevant = keywords.some((kw) => eventText.includes(kw));
|
|
98
|
-
if (relevant) {
|
|
99
|
-
checks.push({ constraintId: constraint.id, passed: false, reason: constraint.description });
|
|
100
|
-
return { violated: constraint, checks };
|
|
101
|
-
}
|
|
102
|
-
checks.push({ constraintId: constraint.id, passed: true });
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
if (constraint.type === "scope" && constraint.trigger) {
|
|
106
|
-
const keywords = extractKeywords(constraint.trigger);
|
|
107
|
-
const violated = keywords.length > 0 && keywords.every((kw) => eventText.includes(kw));
|
|
108
|
-
checks.push({
|
|
109
|
-
constraintId: constraint.id,
|
|
110
|
-
passed: !violated,
|
|
111
|
-
reason: violated ? constraint.description : void 0
|
|
112
|
-
});
|
|
113
|
-
if (violated) {
|
|
114
|
-
return { violated: constraint, checks };
|
|
115
|
-
}
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
checks.push({ constraintId: constraint.id, passed: true });
|
|
119
|
-
}
|
|
120
|
-
return { violated: null, checks };
|
|
121
|
-
}
|
|
122
|
-
function getPlanProgress(plan) {
|
|
123
|
-
const completed = plan.steps.filter((s) => s.status === "completed").length;
|
|
124
|
-
const total = plan.steps.length;
|
|
125
|
-
return {
|
|
126
|
-
completed,
|
|
127
|
-
total,
|
|
128
|
-
percentage: total > 0 ? Math.round(completed / total * 100) : 0
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function advancePlan(plan, stepId, evidence) {
|
|
132
|
-
const step = plan.steps.find((s) => s.id === stepId);
|
|
133
|
-
if (!step) {
|
|
134
|
-
return { success: false, reason: `Step "${stepId}" not found in plan.` };
|
|
135
|
-
}
|
|
136
|
-
if (step.status === "completed") {
|
|
137
|
-
return { success: false, reason: `Step "${stepId}" is already completed.` };
|
|
138
|
-
}
|
|
139
|
-
const mode = plan.completion ?? "trust";
|
|
140
|
-
if (mode === "verified" && step.verify) {
|
|
141
|
-
if (!evidence) {
|
|
142
|
-
return {
|
|
143
|
-
success: false,
|
|
144
|
-
reason: `Step "${step.label}" requires evidence (verify: ${step.verify}). Provide evidence to advance.`
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
if (evidence.type !== step.verify) {
|
|
148
|
-
return {
|
|
149
|
-
success: false,
|
|
150
|
-
reason: `Evidence type "${evidence.type}" does not match required verification "${step.verify}".`
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const updatedPlan = {
|
|
155
|
-
...plan,
|
|
156
|
-
steps: plan.steps.map(
|
|
157
|
-
(s) => s.id === stepId ? { ...s, status: "completed" } : s
|
|
158
|
-
)
|
|
159
|
-
};
|
|
160
|
-
return {
|
|
161
|
-
success: true,
|
|
162
|
-
plan: updatedPlan,
|
|
163
|
-
evidence: evidence ?? void 0
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function evaluatePlan(event, plan) {
|
|
167
|
-
const progress = getPlanProgress(plan);
|
|
168
|
-
if (plan.expires_at) {
|
|
169
|
-
const expiresAt = new Date(plan.expires_at).getTime();
|
|
170
|
-
if (Date.now() > expiresAt) {
|
|
171
|
-
return {
|
|
172
|
-
allowed: true,
|
|
173
|
-
status: "PLAN_COMPLETE",
|
|
174
|
-
reason: "Plan has expired.",
|
|
175
|
-
progress
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (progress.completed === progress.total) {
|
|
180
|
-
return {
|
|
181
|
-
allowed: true,
|
|
182
|
-
status: "PLAN_COMPLETE",
|
|
183
|
-
reason: "All plan steps are completed.",
|
|
184
|
-
progress
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
const eventText = normalizeEventText(event);
|
|
188
|
-
const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
|
|
189
|
-
if (!matched) {
|
|
190
|
-
return {
|
|
191
|
-
allowed: false,
|
|
192
|
-
status: "OFF_PLAN",
|
|
193
|
-
reason: "Action does not match any plan step.",
|
|
194
|
-
closestStep: closest?.label,
|
|
195
|
-
similarityScore: closestScore,
|
|
196
|
-
progress
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
if (!isSequenceValid(matched, plan)) {
|
|
200
|
-
const pendingDeps = (matched.requires ?? []).filter((reqId) => plan.steps.find((s) => s.id === reqId)?.status !== "completed").join(", ");
|
|
201
|
-
return {
|
|
202
|
-
allowed: false,
|
|
203
|
-
status: "OFF_PLAN",
|
|
204
|
-
reason: `Step "${matched.label}" requires completion of: ${pendingDeps}`,
|
|
205
|
-
matchedStep: matched.id,
|
|
206
|
-
progress
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
const { violated } = checkConstraints(event, eventText, plan.constraints);
|
|
210
|
-
if (violated) {
|
|
211
|
-
return {
|
|
212
|
-
allowed: false,
|
|
213
|
-
status: "CONSTRAINT_VIOLATED",
|
|
214
|
-
reason: violated.description,
|
|
215
|
-
matchedStep: matched.id,
|
|
216
|
-
progress
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
allowed: true,
|
|
221
|
-
status: "ON_PLAN",
|
|
222
|
-
reason: `Matches step: ${matched.label}`,
|
|
223
|
-
matchedStep: matched.id,
|
|
224
|
-
progress
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function buildPlanCheck(event, plan, verdict) {
|
|
228
|
-
const eventText = normalizeEventText(event);
|
|
229
|
-
const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
|
|
230
|
-
const { checks: constraintChecks } = checkConstraints(event, eventText, plan.constraints);
|
|
231
|
-
const progress = getPlanProgress(plan);
|
|
232
|
-
return {
|
|
233
|
-
planId: plan.plan_id,
|
|
234
|
-
matched: !!matched,
|
|
235
|
-
matchedStepId: matched?.id,
|
|
236
|
-
matchedStepLabel: matched?.label,
|
|
237
|
-
closestStepId: !matched ? closest?.id : void 0,
|
|
238
|
-
closestStepLabel: !matched ? closest?.label : void 0,
|
|
239
|
-
similarityScore: !matched ? closestScore : void 0,
|
|
240
|
-
sequenceValid: matched ? isSequenceValid(matched, plan) : void 0,
|
|
241
|
-
constraintsChecked: constraintChecks,
|
|
242
|
-
progress: { completed: progress.completed, total: progress.total }
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export {
|
|
247
|
-
normalizeEventText,
|
|
248
|
-
matchesAllKeywords,
|
|
249
|
-
getPlanProgress,
|
|
250
|
-
advancePlan,
|
|
251
|
-
evaluatePlan,
|
|
252
|
-
buildPlanCheck
|
|
253
|
-
};
|
package/dist/chunk-REXY4LUL.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
evaluateGuard
|
|
3
|
-
} from "./chunk-IZSO75NZ.js";
|
|
4
|
-
|
|
5
|
-
// src/engine/audit-logger.ts
|
|
6
|
-
var FileAuditLogger = class {
|
|
7
|
-
logPath;
|
|
8
|
-
buffer = [];
|
|
9
|
-
flushTimer = null;
|
|
10
|
-
flushIntervalMs;
|
|
11
|
-
constructor(logPath, options) {
|
|
12
|
-
this.logPath = logPath;
|
|
13
|
-
this.flushIntervalMs = options?.flushIntervalMs ?? 1e3;
|
|
14
|
-
}
|
|
15
|
-
log(event) {
|
|
16
|
-
this.buffer.push(JSON.stringify(event));
|
|
17
|
-
if (!this.flushTimer) {
|
|
18
|
-
this.flushTimer = setTimeout(() => {
|
|
19
|
-
void this.flush();
|
|
20
|
-
}, this.flushIntervalMs);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async flush() {
|
|
24
|
-
if (this.buffer.length === 0) return;
|
|
25
|
-
if (this.flushTimer) {
|
|
26
|
-
clearTimeout(this.flushTimer);
|
|
27
|
-
this.flushTimer = null;
|
|
28
|
-
}
|
|
29
|
-
const lines = this.buffer.splice(0).join("\n") + "\n";
|
|
30
|
-
try {
|
|
31
|
-
const { appendFile, mkdir } = await import("fs/promises");
|
|
32
|
-
const { dirname } = await import("path");
|
|
33
|
-
await mkdir(dirname(this.logPath), { recursive: true });
|
|
34
|
-
await appendFile(this.logPath, lines, "utf-8");
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var ConsoleAuditLogger = class {
|
|
40
|
-
log(event) {
|
|
41
|
-
const iconMap = {
|
|
42
|
-
"ALLOW": "\u25CF",
|
|
43
|
-
"BLOCK": "\u25CB",
|
|
44
|
-
"PAUSE": "\u25D1",
|
|
45
|
-
"MODIFY": "\u25D0",
|
|
46
|
-
"PENALIZE": "\u25CC",
|
|
47
|
-
"REWARD": "\u25C9",
|
|
48
|
-
"NEUTRAL": "\u25EF"
|
|
49
|
-
};
|
|
50
|
-
const icon = iconMap[event.decision] ?? "\xB7";
|
|
51
|
-
const ts = event.timestamp.split("T")[1]?.replace("Z", "") ?? event.timestamp;
|
|
52
|
-
let line = `[${ts}] ${icon} ${event.decision.padEnd(10)} ${event.actor ?? "\u2014"} \u2192 ${event.intent}`;
|
|
53
|
-
if (event.reason) line += ` (${event.reason})`;
|
|
54
|
-
if (event.consequence) line += ` [consequence: ${event.consequence.description}]`;
|
|
55
|
-
if (event.reward) line += ` [reward: ${event.reward.description}]`;
|
|
56
|
-
process.stderr.write(line + "\n");
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
var CompositeAuditLogger = class {
|
|
60
|
-
loggers;
|
|
61
|
-
constructor(...loggers) {
|
|
62
|
-
this.loggers = loggers;
|
|
63
|
-
}
|
|
64
|
-
log(event) {
|
|
65
|
-
for (const logger of this.loggers) {
|
|
66
|
-
try {
|
|
67
|
-
logger.log(event);
|
|
68
|
-
} catch {
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async flush() {
|
|
73
|
-
await Promise.all(
|
|
74
|
-
this.loggers.map((l) => l.flush?.()).filter(Boolean)
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
function verdictToAuditEvent(event, verdict) {
|
|
79
|
-
const auditEvent = {
|
|
80
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
81
|
-
worldId: verdict.evidence.worldId,
|
|
82
|
-
worldName: verdict.evidence.worldName,
|
|
83
|
-
worldVersion: verdict.evidence.worldVersion,
|
|
84
|
-
intent: event.intent,
|
|
85
|
-
tool: event.tool,
|
|
86
|
-
scope: event.scope,
|
|
87
|
-
actor: event.roleId,
|
|
88
|
-
direction: event.direction,
|
|
89
|
-
decision: verdict.status,
|
|
90
|
-
reason: verdict.reason,
|
|
91
|
-
ruleId: verdict.ruleId,
|
|
92
|
-
warning: verdict.warning,
|
|
93
|
-
guardsMatched: verdict.evidence.guardsMatched,
|
|
94
|
-
rulesMatched: verdict.evidence.rulesMatched,
|
|
95
|
-
invariantsSatisfied: verdict.evidence.invariantsSatisfied,
|
|
96
|
-
invariantsTotal: verdict.evidence.invariantsTotal,
|
|
97
|
-
enforcementLevel: verdict.evidence.enforcementLevel,
|
|
98
|
-
durationMs: verdict.trace?.durationMs,
|
|
99
|
-
args: event.args
|
|
100
|
-
};
|
|
101
|
-
if (verdict.consequence) {
|
|
102
|
-
auditEvent.consequence = verdict.consequence;
|
|
103
|
-
}
|
|
104
|
-
if (verdict.reward) {
|
|
105
|
-
auditEvent.reward = verdict.reward;
|
|
106
|
-
}
|
|
107
|
-
if (verdict.intentRecord) {
|
|
108
|
-
auditEvent.originalIntent = verdict.intentRecord.originalIntent;
|
|
109
|
-
auditEvent.finalAction = verdict.intentRecord.finalAction;
|
|
110
|
-
}
|
|
111
|
-
return auditEvent;
|
|
112
|
-
}
|
|
113
|
-
function createGovernanceEngine(world, options = {}) {
|
|
114
|
-
const { auditLogger, auditArgs, ...engineOptions } = options;
|
|
115
|
-
return {
|
|
116
|
-
/**
|
|
117
|
-
* Evaluate a governance event and log the result.
|
|
118
|
-
*/
|
|
119
|
-
evaluate(event) {
|
|
120
|
-
const verdict = evaluateGuard(event, world, engineOptions);
|
|
121
|
-
if (auditLogger) {
|
|
122
|
-
const auditEvent = verdictToAuditEvent(event, verdict);
|
|
123
|
-
if (!auditArgs) {
|
|
124
|
-
delete auditEvent.args;
|
|
125
|
-
}
|
|
126
|
-
auditLogger.log(auditEvent);
|
|
127
|
-
}
|
|
128
|
-
return verdict;
|
|
129
|
-
},
|
|
130
|
-
/** Flush the audit logger. */
|
|
131
|
-
async flush() {
|
|
132
|
-
await auditLogger?.flush?.();
|
|
133
|
-
},
|
|
134
|
-
/** The underlying world definition. */
|
|
135
|
-
world
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
async function readAuditLog(logPath, filter) {
|
|
139
|
-
const { readFile } = await import("fs/promises");
|
|
140
|
-
let content;
|
|
141
|
-
try {
|
|
142
|
-
content = await readFile(logPath, "utf-8");
|
|
143
|
-
} catch {
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
const events = [];
|
|
147
|
-
for (const line of content.split("\n")) {
|
|
148
|
-
const trimmed = line.trim();
|
|
149
|
-
if (!trimmed) continue;
|
|
150
|
-
try {
|
|
151
|
-
const event = JSON.parse(trimmed);
|
|
152
|
-
if (!filter || filter(event)) {
|
|
153
|
-
events.push(event);
|
|
154
|
-
}
|
|
155
|
-
} catch {
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return events;
|
|
159
|
-
}
|
|
160
|
-
function summarizeAuditEvents(events) {
|
|
161
|
-
const allowed = events.filter((e) => e.decision === "ALLOW").length;
|
|
162
|
-
const blocked = events.filter((e) => e.decision === "BLOCK").length;
|
|
163
|
-
const paused = events.filter((e) => e.decision === "PAUSE").length;
|
|
164
|
-
const modified = events.filter((e) => e.decision === "MODIFY").length;
|
|
165
|
-
const penalized = events.filter((e) => e.decision === "PENALIZE").length;
|
|
166
|
-
const rewarded = events.filter((e) => e.decision === "REWARD").length;
|
|
167
|
-
const neutral = events.filter((e) => e.decision === "NEUTRAL").length;
|
|
168
|
-
const actorSet = /* @__PURE__ */ new Set();
|
|
169
|
-
for (const e of events) {
|
|
170
|
-
if (e.actor) actorSet.add(e.actor);
|
|
171
|
-
}
|
|
172
|
-
const intentMap = /* @__PURE__ */ new Map();
|
|
173
|
-
for (const e of events) {
|
|
174
|
-
const entry = intentMap.get(e.intent) ?? { count: 0, blocked: 0, paused: 0, penalized: 0, rewarded: 0 };
|
|
175
|
-
entry.count++;
|
|
176
|
-
if (e.decision === "BLOCK") entry.blocked++;
|
|
177
|
-
if (e.decision === "PAUSE") entry.paused++;
|
|
178
|
-
if (e.decision === "PENALIZE") entry.penalized++;
|
|
179
|
-
if (e.decision === "REWARD") entry.rewarded++;
|
|
180
|
-
intentMap.set(e.intent, entry);
|
|
181
|
-
}
|
|
182
|
-
const topIntents = [...intentMap.entries()].map(([intent, data]) => ({ intent, ...data })).sort((a, b) => b.count - a.count);
|
|
183
|
-
const ruleMap = /* @__PURE__ */ new Map();
|
|
184
|
-
for (const e of events) {
|
|
185
|
-
if (e.ruleId) {
|
|
186
|
-
ruleMap.set(e.ruleId, (ruleMap.get(e.ruleId) ?? 0) + 1);
|
|
187
|
-
}
|
|
188
|
-
for (const g of e.guardsMatched) {
|
|
189
|
-
ruleMap.set(g, (ruleMap.get(g) ?? 0) + 1);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const topRules = [...ruleMap.entries()].map(([ruleId, count]) => ({ ruleId, count })).sort((a, b) => b.count - a.count);
|
|
193
|
-
const redirected = blocked + paused + modified + penalized;
|
|
194
|
-
const total = events.length;
|
|
195
|
-
return {
|
|
196
|
-
totalActions: total,
|
|
197
|
-
allowed,
|
|
198
|
-
blocked,
|
|
199
|
-
paused,
|
|
200
|
-
modified,
|
|
201
|
-
penalized,
|
|
202
|
-
rewarded,
|
|
203
|
-
neutral,
|
|
204
|
-
actors: [...actorSet],
|
|
205
|
-
topIntents,
|
|
206
|
-
topRules,
|
|
207
|
-
firstEvent: events[0]?.timestamp ?? "",
|
|
208
|
-
lastEvent: events[events.length - 1]?.timestamp ?? "",
|
|
209
|
-
behavioralEconomy: {
|
|
210
|
-
totalPenalties: penalized,
|
|
211
|
-
totalRewards: rewarded,
|
|
212
|
-
netPressure: rewarded - penalized,
|
|
213
|
-
redirectionRate: total > 0 ? redirected / total : 0
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export {
|
|
219
|
-
FileAuditLogger,
|
|
220
|
-
ConsoleAuditLogger,
|
|
221
|
-
CompositeAuditLogger,
|
|
222
|
-
verdictToAuditEvent,
|
|
223
|
-
createGovernanceEngine,
|
|
224
|
-
readAuditLog,
|
|
225
|
-
summarizeAuditEvents
|
|
226
|
-
};
|
package/dist/chunk-T5EUJQE5.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// src/adapters/autoresearch.ts
|
|
2
|
-
var AutoresearchGovernor = class {
|
|
3
|
-
config;
|
|
4
|
-
state;
|
|
5
|
-
constructor(config) {
|
|
6
|
-
this.config = config;
|
|
7
|
-
this.state = {
|
|
8
|
-
experiments_run: 0,
|
|
9
|
-
best_result: null,
|
|
10
|
-
architectures_tested: [],
|
|
11
|
-
experiment_log: [],
|
|
12
|
-
total_compute_minutes: 0,
|
|
13
|
-
keep_count: 0
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Convert an experiment proposal into a GuardEvent for governance evaluation.
|
|
18
|
-
*/
|
|
19
|
-
proposalToGuardEvent(proposal) {
|
|
20
|
-
return {
|
|
21
|
-
intent: `run experiment: ${proposal.description}`,
|
|
22
|
-
tool: "experiment_runner",
|
|
23
|
-
scope: "experiment",
|
|
24
|
-
roleId: "experiment_runner",
|
|
25
|
-
direction: "output",
|
|
26
|
-
actionCategory: "shell",
|
|
27
|
-
args: {
|
|
28
|
-
experiment_id: String(proposal.experiment_id),
|
|
29
|
-
architecture: proposal.architecture,
|
|
30
|
-
estimated_minutes: String(proposal.estimated_minutes || 5)
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Evaluate an experiment proposal against governance rules.
|
|
36
|
-
* Returns a simplified verdict without requiring the full guard engine.
|
|
37
|
-
*/
|
|
38
|
-
evaluateProposal(proposal) {
|
|
39
|
-
const warnings = [];
|
|
40
|
-
const estimatedMinutes = proposal.estimated_minutes || 5;
|
|
41
|
-
if (this.state.total_compute_minutes + estimatedMinutes > this.config.computeBudgetMinutes) {
|
|
42
|
-
return {
|
|
43
|
-
allowed: false,
|
|
44
|
-
reason: `Compute budget exhausted: ${this.state.total_compute_minutes}/${this.config.computeBudgetMinutes} minutes used`,
|
|
45
|
-
warnings
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (this.config.constraints) {
|
|
49
|
-
for (const constraint of this.config.constraints) {
|
|
50
|
-
const lower = constraint.toLowerCase();
|
|
51
|
-
const archLower = proposal.architecture.toLowerCase();
|
|
52
|
-
const descLower = proposal.description.toLowerCase();
|
|
53
|
-
if (lower.startsWith("no ")) {
|
|
54
|
-
const forbidden = lower.slice(3).trim();
|
|
55
|
-
if (archLower.includes(forbidden) || descLower.includes(forbidden)) {
|
|
56
|
-
return {
|
|
57
|
-
allowed: false,
|
|
58
|
-
reason: `Architecture constraint violated: ${constraint}`,
|
|
59
|
-
warnings
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const failureCount = this.state.experiment_log.filter((e) => !e.success).length;
|
|
66
|
-
if (failureCount > 5) {
|
|
67
|
-
warnings.push(`High failure rate: ${failureCount} failed experiments. Consider investigating root cause.`);
|
|
68
|
-
}
|
|
69
|
-
const recentArchitectures = this.state.experiment_log.slice(-5).map((e) => e.architecture);
|
|
70
|
-
const uniqueRecent = new Set(recentArchitectures).size;
|
|
71
|
-
if (recentArchitectures.length >= 5 && uniqueRecent === 1) {
|
|
72
|
-
warnings.push("Research may be stuck: last 5 experiments used the same architecture.");
|
|
73
|
-
}
|
|
74
|
-
return { allowed: true, reason: "Experiment approved", warnings };
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Record an experiment result and update research state.
|
|
78
|
-
*/
|
|
79
|
-
recordResult(result) {
|
|
80
|
-
this.state.experiments_run++;
|
|
81
|
-
this.state.total_compute_minutes += result.wall_clock_minutes;
|
|
82
|
-
this.state.experiment_log.push(result);
|
|
83
|
-
if (!this.state.architectures_tested.includes(result.architecture)) {
|
|
84
|
-
this.state.architectures_tested.push(result.architecture);
|
|
85
|
-
}
|
|
86
|
-
if (!result.success) {
|
|
87
|
-
return { kept: false, improvement: null, state: { ...this.state } };
|
|
88
|
-
}
|
|
89
|
-
let kept = false;
|
|
90
|
-
let improvement = null;
|
|
91
|
-
if (this.state.best_result === null) {
|
|
92
|
-
kept = true;
|
|
93
|
-
this.state.best_result = result;
|
|
94
|
-
this.state.keep_count++;
|
|
95
|
-
} else {
|
|
96
|
-
const prev = this.state.best_result.metric_value;
|
|
97
|
-
const curr = result.metric_value;
|
|
98
|
-
if (this.config.optimize === "minimize") {
|
|
99
|
-
kept = curr < prev;
|
|
100
|
-
improvement = kept ? prev - curr : null;
|
|
101
|
-
} else {
|
|
102
|
-
kept = curr > prev;
|
|
103
|
-
improvement = kept ? curr - prev : null;
|
|
104
|
-
}
|
|
105
|
-
if (kept) {
|
|
106
|
-
this.state.best_result = result;
|
|
107
|
-
this.state.keep_count++;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return { kept, improvement, state: { ...this.state } };
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Export current state as a state snapshot compatible with the world file.
|
|
114
|
-
*/
|
|
115
|
-
toWorldState() {
|
|
116
|
-
const successfulExperiments = this.state.experiment_log.filter((e) => e.success);
|
|
117
|
-
const failedCount = this.state.experiment_log.filter((e) => !e.success).length;
|
|
118
|
-
const keepRate = this.state.experiments_run > 0 ? Math.round(this.state.keep_count / this.state.experiments_run * 100) : 0;
|
|
119
|
-
let improvementRate = 0;
|
|
120
|
-
if (successfulExperiments.length >= 2) {
|
|
121
|
-
const recent = successfulExperiments.slice(-10);
|
|
122
|
-
let improvements = 0;
|
|
123
|
-
for (let i = 1; i < recent.length; i++) {
|
|
124
|
-
const prev = recent[i - 1].metric_value;
|
|
125
|
-
const curr = recent[i].metric_value;
|
|
126
|
-
if (this.config.optimize === "minimize" ? curr < prev : curr > prev) {
|
|
127
|
-
improvements++;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
improvementRate = Math.round(improvements / (recent.length - 1) * 100);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
experiments_run: this.state.experiments_run,
|
|
134
|
-
best_metric_value: this.state.best_result?.metric_value ?? (this.config.optimize === "minimize" ? 100 : -1e3),
|
|
135
|
-
keep_rate: keepRate,
|
|
136
|
-
compute_used_minutes: Math.round(this.state.total_compute_minutes),
|
|
137
|
-
compute_budget_minutes: this.config.computeBudgetMinutes,
|
|
138
|
-
failed_experiments: failedCount,
|
|
139
|
-
metric_improvement_rate: improvementRate,
|
|
140
|
-
research_context_drift: 0
|
|
141
|
-
// would need NLP to compute properly
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Get a summary of the current research state.
|
|
146
|
-
*/
|
|
147
|
-
getSummary() {
|
|
148
|
-
return {
|
|
149
|
-
experiments_run: this.state.experiments_run,
|
|
150
|
-
best_result: this.state.best_result,
|
|
151
|
-
keep_rate: this.state.experiments_run > 0 ? Math.round(this.state.keep_count / this.state.experiments_run * 100) : 0,
|
|
152
|
-
compute_remaining_minutes: this.config.computeBudgetMinutes - this.state.total_compute_minutes,
|
|
153
|
-
architectures_tested: [...this.state.architectures_tested]
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Load state from a persisted research context file.
|
|
158
|
-
*/
|
|
159
|
-
loadState(state) {
|
|
160
|
-
this.state = { ...state };
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Export state for persistence.
|
|
164
|
-
*/
|
|
165
|
-
exportState() {
|
|
166
|
-
return { ...this.state };
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export {
|
|
171
|
-
AutoresearchGovernor
|
|
172
|
-
};
|