@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.
Files changed (118) hide show
  1. package/package.json +4 -2
  2. package/policies/content-moderation-rules.txt +8 -0
  3. package/policies/marketing-rules.txt +8 -0
  4. package/policies/science-research-rules.txt +11 -0
  5. package/policies/social-media-rules.txt +7 -0
  6. package/policies/strict-rules.txt +8 -0
  7. package/policies/trading-rules.txt +8 -0
  8. package/simulate.html +1899 -0
  9. package/dist/adapters/autoresearch.cjs +0 -196
  10. package/dist/adapters/autoresearch.d.cts +0 -103
  11. package/dist/adapters/autoresearch.d.ts +0 -103
  12. package/dist/adapters/autoresearch.js +0 -7
  13. package/dist/adapters/deep-agents.cjs +0 -1472
  14. package/dist/adapters/deep-agents.d.cts +0 -181
  15. package/dist/adapters/deep-agents.d.ts +0 -181
  16. package/dist/adapters/deep-agents.js +0 -17
  17. package/dist/adapters/express.cjs +0 -1196
  18. package/dist/adapters/express.d.cts +0 -66
  19. package/dist/adapters/express.d.ts +0 -66
  20. package/dist/adapters/express.js +0 -12
  21. package/dist/adapters/index.cjs +0 -2038
  22. package/dist/adapters/index.d.cts +0 -8
  23. package/dist/adapters/index.d.ts +0 -8
  24. package/dist/adapters/index.js +0 -68
  25. package/dist/adapters/langchain.cjs +0 -1259
  26. package/dist/adapters/langchain.d.cts +0 -89
  27. package/dist/adapters/langchain.d.ts +0 -89
  28. package/dist/adapters/langchain.js +0 -17
  29. package/dist/adapters/openai.cjs +0 -1289
  30. package/dist/adapters/openai.d.cts +0 -99
  31. package/dist/adapters/openai.d.ts +0 -99
  32. package/dist/adapters/openai.js +0 -17
  33. package/dist/adapters/openclaw.cjs +0 -1281
  34. package/dist/adapters/openclaw.d.cts +0 -99
  35. package/dist/adapters/openclaw.d.ts +0 -99
  36. package/dist/adapters/openclaw.js +0 -17
  37. package/dist/bootstrap-GXVDZNF7.js +0 -114
  38. package/dist/build-X5MZY4IA.js +0 -339
  39. package/dist/chunk-4L6OPKMQ.js +0 -100
  40. package/dist/chunk-4NGDRRQH.js +0 -10
  41. package/dist/chunk-5U2MQO5P.js +0 -57
  42. package/dist/chunk-6BB55YJI.js +0 -113
  43. package/dist/chunk-6CZSKEY5.js +0 -164
  44. package/dist/chunk-7P3S7MAY.js +0 -1090
  45. package/dist/chunk-A5W4GNQO.js +0 -130
  46. package/dist/chunk-AF2VX4AL.js +0 -363
  47. package/dist/chunk-AKW5YVCE.js +0 -96
  48. package/dist/chunk-BMOXICAB.js +0 -340
  49. package/dist/chunk-BQZMOEML.js +0 -43
  50. package/dist/chunk-D2UCV5AK.js +0 -326
  51. package/dist/chunk-EVDJUSZ2.js +0 -91
  52. package/dist/chunk-FYS2CBUW.js +0 -304
  53. package/dist/chunk-I3RRAYK2.js +0 -11
  54. package/dist/chunk-IZSO75NZ.js +0 -792
  55. package/dist/chunk-JCKSW2PZ.js +0 -304
  56. package/dist/chunk-JZPQGIKR.js +0 -79
  57. package/dist/chunk-KTFTTLTP.js +0 -246
  58. package/dist/chunk-MH7BT4VH.js +0 -15
  59. package/dist/chunk-ORJ3NOE6.js +0 -622
  60. package/dist/chunk-OT6PXH54.js +0 -61
  61. package/dist/chunk-Q6O7ZLO2.js +0 -62
  62. package/dist/chunk-QLPTHTVB.js +0 -253
  63. package/dist/chunk-REXY4LUL.js +0 -226
  64. package/dist/chunk-T5EUJQE5.js +0 -172
  65. package/dist/chunk-TTBKTF3P.js +0 -608
  66. package/dist/chunk-XPDMYECO.js +0 -642
  67. package/dist/chunk-YZFATT7X.js +0 -9
  68. package/dist/chunk-ZIVQNSZU.js +0 -119
  69. package/dist/chunk-ZJTDUCC2.js +0 -194
  70. package/dist/cli/neuroverse.cjs +0 -12564
  71. package/dist/cli/neuroverse.d.cts +0 -1
  72. package/dist/cli/neuroverse.d.ts +0 -1
  73. package/dist/cli/neuroverse.js +0 -208
  74. package/dist/cli/plan.cjs +0 -1686
  75. package/dist/cli/plan.d.cts +0 -20
  76. package/dist/cli/plan.d.ts +0 -20
  77. package/dist/cli/plan.js +0 -353
  78. package/dist/cli/run.cjs +0 -1945
  79. package/dist/cli/run.d.cts +0 -20
  80. package/dist/cli/run.d.ts +0 -20
  81. package/dist/cli/run.js +0 -143
  82. package/dist/configure-ai-TK67ZWZL.js +0 -132
  83. package/dist/decision-flow-LETV5NWY.js +0 -61
  84. package/dist/derive-7365SUFU.js +0 -152
  85. package/dist/doctor-QYISMKEL.js +0 -173
  86. package/dist/equity-penalties-63FGB3I2.js +0 -244
  87. package/dist/explain-A2EWI2OL.js +0 -51
  88. package/dist/guard-3BWL3IGH.js +0 -92
  89. package/dist/guard-contract-C9_zKbzd.d.cts +0 -821
  90. package/dist/guard-contract-C9_zKbzd.d.ts +0 -821
  91. package/dist/guard-engine-QFMIBWJY.js +0 -10
  92. package/dist/impact-UB6DXKSX.js +0 -59
  93. package/dist/improve-XZA57GER.js +0 -66
  94. package/dist/index.cjs +0 -6821
  95. package/dist/index.d.cts +0 -1829
  96. package/dist/index.d.ts +0 -1829
  97. package/dist/index.js +0 -430
  98. package/dist/infer-world-7GVZWFX4.js +0 -543
  99. package/dist/init-PKPIYHYE.js +0 -144
  100. package/dist/init-world-VWMQZQC7.js +0 -223
  101. package/dist/mcp-server-XWQZXNW7.js +0 -13
  102. package/dist/model-adapter-BB7G4MFI.js +0 -11
  103. package/dist/playground-ADWZORNV.js +0 -550
  104. package/dist/redteam-JRQ7FD2F.js +0 -357
  105. package/dist/session-MMYX5YCF.js +0 -15
  106. package/dist/shared--Q8wPBVN.d.ts +0 -60
  107. package/dist/shared-HpAG90PX.d.cts +0 -60
  108. package/dist/shared-U2QFV7JH.js +0 -16
  109. package/dist/simulate-GMIFFXYV.js +0 -83
  110. package/dist/test-JBBZ65X4.js +0 -217
  111. package/dist/trace-3MYWIDEF.js +0 -166
  112. package/dist/validate-LLBWVPGV.js +0 -81
  113. package/dist/validate-engine-UIABSIHD.js +0 -7
  114. package/dist/world-BFJCIQSH.js +0 -378
  115. package/dist/world-loader-HMPTOEA2.js +0 -9
  116. package/dist/worlds/autoresearch.nv-world.md +0 -230
  117. package/dist/worlds/coding-agent.nv-world.md +0 -211
  118. package/dist/worlds/derivation-world.nv-world.md +0 -278
@@ -1,130 +0,0 @@
1
- // src/runtime/model-adapter.ts
2
- var DEFAULT_SYSTEM_PROMPT = `You are an AI assistant operating under NeuroVerse governance.
3
- All your tool calls are evaluated against governance rules before execution.
4
- If an action is blocked, you will be told why. Adjust your approach accordingly.
5
- Do not attempt to bypass governance rules.`;
6
- var ModelAdapter = class {
7
- config;
8
- messages;
9
- tools;
10
- constructor(config, tools = []) {
11
- this.config = config;
12
- this.tools = tools;
13
- this.messages = [];
14
- const systemPrompt = config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
15
- this.messages.push({ role: "system", content: systemPrompt });
16
- }
17
- /**
18
- * Send a user message and get the model's response.
19
- */
20
- async chat(userMessage) {
21
- this.messages.push({ role: "user", content: userMessage });
22
- return this.complete();
23
- }
24
- /**
25
- * Send a tool result back to the model and get the next response.
26
- */
27
- async sendToolResult(toolCallId, result) {
28
- this.messages.push({
29
- role: "tool",
30
- content: result,
31
- tool_call_id: toolCallId
32
- });
33
- return this.complete();
34
- }
35
- /**
36
- * Send a governance block message as a tool result.
37
- */
38
- async sendBlockedResult(toolCallId, reason) {
39
- return this.sendToolResult(
40
- toolCallId,
41
- `[GOVERNANCE BLOCKED] ${reason}. Please adjust your approach.`
42
- );
43
- }
44
- /**
45
- * Call the model API and parse the response.
46
- */
47
- async complete() {
48
- const url = `${this.config.baseUrl}/chat/completions`;
49
- const body = {
50
- model: this.config.model,
51
- messages: this.messages,
52
- max_tokens: this.config.maxTokens ?? 4096
53
- };
54
- if (this.tools.length > 0) {
55
- body.tools = this.tools;
56
- }
57
- const response = await fetch(url, {
58
- method: "POST",
59
- headers: {
60
- "Content-Type": "application/json",
61
- "Authorization": `Bearer ${this.config.apiKey}`
62
- },
63
- body: JSON.stringify(body)
64
- });
65
- if (!response.ok) {
66
- const text = await response.text();
67
- throw new Error(`Model API error ${response.status}: ${text}`);
68
- }
69
- const data = await response.json();
70
- const choice = data.choices?.[0];
71
- if (!choice) {
72
- throw new Error("Model returned no choices");
73
- }
74
- const message = choice.message;
75
- this.messages.push(message);
76
- return {
77
- content: message.content ?? null,
78
- toolCalls: message.tool_calls ?? [],
79
- finishReason: choice.finish_reason ?? "stop"
80
- };
81
- }
82
- /** Get current message count (for context tracking). */
83
- get messageCount() {
84
- return this.messages.length;
85
- }
86
- };
87
- var PROVIDERS = {
88
- openai: {
89
- baseUrl: "https://api.openai.com/v1",
90
- defaultModel: "gpt-4o",
91
- envVar: "OPENAI_API_KEY"
92
- },
93
- anthropic: {
94
- baseUrl: "https://api.anthropic.com/v1",
95
- defaultModel: "claude-sonnet-4-20250514",
96
- envVar: "ANTHROPIC_API_KEY"
97
- },
98
- ollama: {
99
- baseUrl: "http://localhost:11434/v1",
100
- defaultModel: "llama3",
101
- envVar: ""
102
- }
103
- };
104
- function resolveProvider(provider, overrides) {
105
- const preset = PROVIDERS[provider];
106
- if (!preset) {
107
- throw new Error(
108
- `Unknown provider: "${provider}". Available: ${Object.keys(PROVIDERS).join(", ")}`
109
- );
110
- }
111
- const apiKey = overrides?.apiKey ?? (preset.envVar ? process.env[preset.envVar] : "") ?? "";
112
- if (!apiKey && preset.envVar) {
113
- throw new Error(
114
- `Missing API key. Set ${preset.envVar} or pass --api-key.`
115
- );
116
- }
117
- return {
118
- baseUrl: overrides?.baseUrl ?? preset.baseUrl,
119
- apiKey,
120
- model: overrides?.model ?? preset.defaultModel,
121
- systemPrompt: overrides?.systemPrompt,
122
- maxTokens: overrides?.maxTokens
123
- };
124
- }
125
-
126
- export {
127
- ModelAdapter,
128
- PROVIDERS,
129
- resolveProvider
130
- };
@@ -1,363 +0,0 @@
1
- import {
2
- applyConsequence,
3
- applyReward,
4
- createAgentState,
5
- tickAgentStates
6
- } from "./chunk-D2UCV5AK.js";
7
- import {
8
- evaluateGuard
9
- } from "./chunk-IZSO75NZ.js";
10
- import {
11
- advancePlan,
12
- evaluatePlan,
13
- getPlanProgress
14
- } from "./chunk-QLPTHTVB.js";
15
- import {
16
- loadWorld
17
- } from "./chunk-JZPQGIKR.js";
18
-
19
- // src/runtime/session.ts
20
- async function defaultToolExecutor(name, args) {
21
- return `Tool "${name}" executed successfully with args: ${JSON.stringify(args)}`;
22
- }
23
- var SessionManager = class {
24
- config;
25
- state;
26
- engineOptions;
27
- executor;
28
- constructor(config) {
29
- this.config = config;
30
- this.executor = config.toolExecutor ?? defaultToolExecutor;
31
- this.engineOptions = {
32
- trace: config.trace ?? false,
33
- level: config.level,
34
- plan: config.plan
35
- };
36
- this.state = {
37
- active: false,
38
- world: config.world,
39
- plan: config.plan,
40
- progress: config.plan ? getPlanProgress(config.plan) : void 0,
41
- actionsEvaluated: 0,
42
- actionsAllowed: 0,
43
- actionsBlocked: 0,
44
- actionsPaused: 0,
45
- actionsModified: 0,
46
- actionsPenalized: 0,
47
- actionsRewarded: 0,
48
- agentStates: /* @__PURE__ */ new Map()
49
- };
50
- }
51
- /**
52
- * Initialize the session — load world from disk if needed.
53
- */
54
- async start() {
55
- if (this.config.worldPath && !this.config.world) {
56
- this.state.world = await loadWorld(this.config.worldPath);
57
- }
58
- if (!this.state.world) {
59
- throw new Error("No world provided. Use --world or pass a world definition.");
60
- }
61
- this.state.active = true;
62
- return this.getState();
63
- }
64
- /**
65
- * Evaluate a single event against governance.
66
- * Returns the verdict without executing anything.
67
- */
68
- evaluate(event) {
69
- this.engineOptions.plan = this.state.plan;
70
- this.engineOptions.agentStates = this.state.agentStates;
71
- const verdict = evaluateGuard(event, this.state.world, this.engineOptions);
72
- this.state.actionsEvaluated++;
73
- if (verdict.status === "ALLOW") this.state.actionsAllowed++;
74
- if (verdict.status === "BLOCK") this.state.actionsBlocked++;
75
- if (verdict.status === "PAUSE") this.state.actionsPaused++;
76
- if (verdict.status === "MODIFY") this.state.actionsModified++;
77
- if (verdict.status === "PENALIZE") this.state.actionsPenalized++;
78
- if (verdict.status === "REWARD") this.state.actionsRewarded++;
79
- if (event.roleId) {
80
- let agentState = this.state.agentStates.get(event.roleId) ?? createAgentState(event.roleId);
81
- if (verdict.status === "PENALIZE" && verdict.consequence) {
82
- agentState = applyConsequence(agentState, verdict.consequence, verdict.ruleId ?? "unknown");
83
- }
84
- if (verdict.status === "REWARD" && verdict.reward) {
85
- agentState = applyReward(agentState, verdict.reward, verdict.ruleId ?? "unknown");
86
- }
87
- this.state.agentStates.set(event.roleId, agentState);
88
- }
89
- this.config.onVerdict?.(verdict, event);
90
- return verdict;
91
- }
92
- /**
93
- * Advance all agent states by one round.
94
- * Call this at the end of each simulation round to decrement cooldowns.
95
- */
96
- tickRound() {
97
- this.state.agentStates = tickAgentStates(this.state.agentStates);
98
- }
99
- /**
100
- * Get the behavior state for a specific agent.
101
- */
102
- getAgentState(agentId) {
103
- return this.state.agentStates.get(agentId);
104
- }
105
- /**
106
- * Evaluate and execute a tool call.
107
- * Returns the execution result or block reason.
108
- */
109
- async executeToolCall(toolCall) {
110
- let args;
111
- try {
112
- args = JSON.parse(toolCall.function.arguments);
113
- } catch {
114
- args = { raw: toolCall.function.arguments };
115
- }
116
- const event = {
117
- intent: toolCall.function.name,
118
- tool: toolCall.function.name,
119
- args,
120
- direction: "input"
121
- };
122
- const verdict = this.evaluate(event);
123
- if (verdict.status === "BLOCK" || verdict.status === "PENALIZE") {
124
- return { allowed: false, verdict };
125
- }
126
- if (verdict.status === "PAUSE") {
127
- return { allowed: false, verdict };
128
- }
129
- const result = await this.executor(toolCall.function.name, args);
130
- this.config.onToolResult?.(toolCall.function.name, result);
131
- if (this.state.plan) {
132
- const planVerdict = evaluatePlan(event, this.state.plan);
133
- if (planVerdict.matchedStep) {
134
- const advResult = advancePlan(this.state.plan, planVerdict.matchedStep);
135
- if (advResult.success && advResult.plan) {
136
- this.state.plan = advResult.plan;
137
- this.engineOptions.plan = this.state.plan;
138
- }
139
- this.state.progress = getPlanProgress(this.state.plan);
140
- this.config.onPlanProgress?.(this.state.progress);
141
- if (this.state.progress.completed === this.state.progress.total) {
142
- this.config.onPlanComplete?.();
143
- }
144
- }
145
- }
146
- return { allowed: true, verdict, result };
147
- }
148
- /**
149
- * Process a model response — evaluate and execute all tool calls.
150
- * Returns results for each tool call.
151
- */
152
- async processModelResponse(response, model) {
153
- if (response.toolCalls.length === 0) {
154
- return response;
155
- }
156
- for (const toolCall of response.toolCalls) {
157
- const { allowed, verdict, result } = await this.executeToolCall(toolCall);
158
- if (allowed && result) {
159
- const nextResponse = await model.sendToolResult(toolCall.id, result);
160
- if (nextResponse.toolCalls.length > 0) {
161
- return this.processModelResponse(nextResponse, model);
162
- }
163
- return nextResponse;
164
- } else {
165
- const reason = verdict.reason ?? "Action blocked by governance.";
166
- const nextResponse = await model.sendBlockedResult(toolCall.id, reason);
167
- if (nextResponse.toolCalls.length > 0) {
168
- return this.processModelResponse(nextResponse, model);
169
- }
170
- return nextResponse;
171
- }
172
- }
173
- return response;
174
- }
175
- /** Get current session state. */
176
- getState() {
177
- return { ...this.state };
178
- }
179
- /** Stop the session. */
180
- stop() {
181
- this.state.active = false;
182
- return this.getState();
183
- }
184
- };
185
- async function runPipeMode(config) {
186
- const session = new SessionManager(config);
187
- await session.start();
188
- const state = session.getState();
189
- process.stderr.write(`[neuroverse] Pipe mode active
190
- `);
191
- process.stderr.write(`[neuroverse] World: ${state.world.world.name}
192
- `);
193
- if (state.plan) {
194
- process.stderr.write(`[neuroverse] Plan: ${state.plan.plan_id} (${state.plan.objective})
195
- `);
196
- }
197
- return new Promise((resolve, reject) => {
198
- let buffer = "";
199
- process.stdin.setEncoding("utf-8");
200
- process.stdin.on("data", (chunk) => {
201
- buffer += chunk;
202
- const lines = buffer.split("\n");
203
- buffer = lines.pop() ?? "";
204
- for (const line of lines) {
205
- const trimmed = line.trim();
206
- if (!trimmed) continue;
207
- try {
208
- const event = JSON.parse(trimmed);
209
- if (!event.intent) {
210
- process.stderr.write(`[neuroverse] Warning: event missing "intent" field
211
- `);
212
- continue;
213
- }
214
- const verdict = session.evaluate(event);
215
- process.stdout.write(JSON.stringify(verdict) + "\n");
216
- } catch (err) {
217
- process.stderr.write(`[neuroverse] Error parsing line: ${err}
218
- `);
219
- }
220
- }
221
- });
222
- process.stdin.on("end", () => {
223
- if (buffer.trim()) {
224
- try {
225
- const event = JSON.parse(buffer.trim());
226
- if (event.intent) {
227
- const verdict = session.evaluate(event);
228
- process.stdout.write(JSON.stringify(verdict) + "\n");
229
- }
230
- } catch {
231
- }
232
- }
233
- const finalState = session.stop();
234
- process.stderr.write(
235
- `[neuroverse] Session complete: ${finalState.actionsEvaluated} evaluated, ${finalState.actionsAllowed} allowed, ${finalState.actionsBlocked} blocked, ${finalState.actionsPaused} paused
236
- `
237
- );
238
- resolve();
239
- });
240
- process.stdin.on("error", reject);
241
- });
242
- }
243
- async function runInteractiveMode(config, model) {
244
- const session = new SessionManager(config);
245
- await session.start();
246
- const state = session.getState();
247
- process.stdout.write("\n");
248
- process.stdout.write(` World: ${state.world.world.name}
249
- `);
250
- if (state.plan) {
251
- process.stdout.write(` Plan: ${state.plan.plan_id}
252
- `);
253
- process.stdout.write(` Goal: ${state.plan.objective}
254
- `);
255
- process.stdout.write(` Steps: ${state.progress?.total ?? 0}
256
- `);
257
- }
258
- process.stdout.write(` Type "exit" to end session.
259
- `);
260
- process.stdout.write("\n");
261
- const readline = await import("readline");
262
- const rl = readline.createInterface({
263
- input: process.stdin,
264
- output: process.stdout,
265
- prompt: "> "
266
- });
267
- const printProgress = () => {
268
- const s = session.getState();
269
- if (s.progress) {
270
- process.stdout.write(
271
- ` [plan: ${s.progress.completed}/${s.progress.total} (${s.progress.percentage}%)]
272
- `
273
- );
274
- }
275
- };
276
- rl.prompt();
277
- rl.on("line", async (input) => {
278
- const trimmed = input.trim();
279
- if (!trimmed) {
280
- rl.prompt();
281
- return;
282
- }
283
- if (trimmed === "exit" || trimmed === "quit") {
284
- const finalState = session.stop();
285
- process.stdout.write("\n");
286
- process.stdout.write(` Session complete.
287
- `);
288
- process.stdout.write(` Actions: ${finalState.actionsEvaluated} evaluated`);
289
- process.stdout.write(`, ${finalState.actionsAllowed} allowed`);
290
- process.stdout.write(`, ${finalState.actionsBlocked} blocked
291
- `);
292
- if (finalState.progress) {
293
- process.stdout.write(
294
- ` Plan: ${finalState.progress.completed}/${finalState.progress.total} steps completed
295
- `
296
- );
297
- }
298
- process.stdout.write("\n");
299
- rl.close();
300
- return;
301
- }
302
- if (trimmed === "status") {
303
- const s = session.getState();
304
- process.stdout.write(`
305
- World: ${s.world.world.name}
306
- `);
307
- process.stdout.write(` Actions: ${s.actionsEvaluated} evaluated
308
- `);
309
- process.stdout.write(` Allowed: ${s.actionsAllowed} | Blocked: ${s.actionsBlocked} | Modified: ${s.actionsModified} | Paused: ${s.actionsPaused}
310
- `);
311
- process.stdout.write(` Penalized: ${s.actionsPenalized} | Rewarded: ${s.actionsRewarded}
312
- `);
313
- if (s.progress && s.plan) {
314
- process.stdout.write(` Plan: ${s.plan.plan_id} \u2014 ${s.progress.completed}/${s.progress.total} (${s.progress.percentage}%)
315
- `);
316
- for (const step of s.plan.steps) {
317
- const icon = step.status === "completed" ? "[x]" : "[ ]";
318
- process.stdout.write(` ${icon} ${step.label}
319
- `);
320
- }
321
- }
322
- process.stdout.write("\n");
323
- rl.prompt();
324
- return;
325
- }
326
- try {
327
- const response = await model.chat(trimmed);
328
- if (response.toolCalls.length > 0) {
329
- const finalResponse = await session.processModelResponse(response, model);
330
- if (finalResponse.content) {
331
- process.stdout.write(`
332
- ${finalResponse.content}
333
-
334
- `);
335
- }
336
- printProgress();
337
- } else if (response.content) {
338
- process.stdout.write(`
339
- ${response.content}
340
-
341
- `);
342
- }
343
- } catch (err) {
344
- process.stderr.write(`
345
- Error: ${err}
346
-
347
- `);
348
- }
349
- rl.prompt();
350
- });
351
- rl.on("close", () => {
352
- session.stop();
353
- });
354
- return new Promise((resolve) => {
355
- rl.on("close", resolve);
356
- });
357
- }
358
-
359
- export {
360
- SessionManager,
361
- runPipeMode,
362
- runInteractiveMode
363
- };
@@ -1,96 +0,0 @@
1
- // src/loader/world-resolver.ts
2
- import { existsSync, readFileSync, writeFileSync, readdirSync, mkdirSync } from "fs";
3
- import { join, resolve, isAbsolute } from "path";
4
- var WORLDS_DIR = ".neuroverse/worlds";
5
- var ACTIVE_WORLD_FILE = ".neuroverse/active_world";
6
- function listWorlds(cwd = process.cwd()) {
7
- const worldsDir = join(cwd, WORLDS_DIR);
8
- if (!existsSync(worldsDir)) return [];
9
- const activeName = getActiveWorldName(cwd);
10
- const entries = readdirSync(worldsDir);
11
- return entries.filter((name) => {
12
- const worldJson = join(worldsDir, name, "world.json");
13
- return existsSync(worldJson);
14
- }).map((name) => ({
15
- name,
16
- path: join(worldsDir, name),
17
- active: name === activeName
18
- })).sort((a, b) => a.name.localeCompare(b.name));
19
- }
20
- function getActiveWorldName(cwd = process.cwd()) {
21
- const filePath = join(cwd, ACTIVE_WORLD_FILE);
22
- try {
23
- return readFileSync(filePath, "utf-8").trim() || void 0;
24
- } catch {
25
- return void 0;
26
- }
27
- }
28
- function setActiveWorld(name, cwd = process.cwd()) {
29
- const worldsDir = join(cwd, WORLDS_DIR);
30
- const worldPath = join(worldsDir, name, "world.json");
31
- if (!existsSync(worldPath)) {
32
- const available = listWorlds(cwd);
33
- const names = available.map((w) => w.name).join(", ");
34
- throw new Error(
35
- `World "${name}" not found in ${WORLDS_DIR}/
36
- ` + (names ? `Available: ${names}` : "No worlds found. Run `neuroverse build` first.")
37
- );
38
- }
39
- const dir = join(cwd, ".neuroverse");
40
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
41
- writeFileSync(join(cwd, ACTIVE_WORLD_FILE), name + "\n", "utf-8");
42
- }
43
- function resolveWorldPath(explicit, cwd = process.cwd()) {
44
- if (explicit) {
45
- return resolveNameOrPath(explicit, cwd);
46
- }
47
- const envWorld = process.env.NEUROVERSE_WORLD;
48
- if (envWorld) {
49
- return resolveNameOrPath(envWorld, cwd);
50
- }
51
- const activeName = getActiveWorldName(cwd);
52
- if (activeName) {
53
- return resolveNameOrPath(activeName, cwd);
54
- }
55
- const worlds = listWorlds(cwd);
56
- if (worlds.length === 1) {
57
- return resolve(worlds[0].path);
58
- }
59
- return void 0;
60
- }
61
- function describeActiveWorld(explicit, cwd = process.cwd()) {
62
- if (explicit) {
63
- return { name: explicit, source: "--world flag" };
64
- }
65
- const envWorld = process.env.NEUROVERSE_WORLD;
66
- if (envWorld) {
67
- return { name: envWorld, source: "NEUROVERSE_WORLD env var" };
68
- }
69
- const activeName = getActiveWorldName(cwd);
70
- if (activeName) {
71
- return { name: activeName, source: ".neuroverse/active_world" };
72
- }
73
- const worlds = listWorlds(cwd);
74
- if (worlds.length === 1) {
75
- return { name: worlds[0].name, source: "auto-detected (only world)" };
76
- }
77
- return void 0;
78
- }
79
- function resolveNameOrPath(ref, cwd) {
80
- if (ref.includes("/") || ref.includes("\\") || ref.startsWith(".") || isAbsolute(ref)) {
81
- return resolve(cwd, ref);
82
- }
83
- const namedPath = join(cwd, WORLDS_DIR, ref);
84
- if (existsSync(join(namedPath, "world.json"))) {
85
- return resolve(namedPath);
86
- }
87
- return resolve(cwd, ref);
88
- }
89
-
90
- export {
91
- listWorlds,
92
- getActiveWorldName,
93
- setActiveWorld,
94
- resolveWorldPath,
95
- describeActiveWorld
96
- };