@neuroverseos/governance 0.4.3 → 0.5.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 (68) hide show
  1. package/README.md +189 -0
  2. package/dist/adapters/autoresearch.js +2 -2
  3. package/dist/adapters/deep-agents.js +2 -2
  4. package/dist/adapters/express.js +2 -2
  5. package/dist/adapters/github.js +2 -2
  6. package/dist/adapters/index.js +23 -21
  7. package/dist/adapters/langchain.js +2 -2
  8. package/dist/adapters/mentraos.js +8 -6
  9. package/dist/adapters/openai.js +2 -2
  10. package/dist/adapters/openclaw.js +2 -2
  11. package/dist/{add-XSANI3FK.js → add-JP7TC2K3.js} +1 -1
  12. package/dist/admin/index.cjs +2214 -0
  13. package/dist/admin/index.d.cts +362 -0
  14. package/dist/admin/index.d.ts +362 -0
  15. package/dist/admin/index.js +703 -0
  16. package/dist/{build-EGBGZFIJ.js → build-THUEYMVT.js} +5 -5
  17. package/dist/{chunk-YJ34R5NB.js → chunk-5RAQ5DZW.js} +3 -3
  18. package/dist/{chunk-RDA7ISWC.js → chunk-6UPEUMJ2.js} +3 -3
  19. package/dist/chunk-7UU7V3AD.js +447 -0
  20. package/dist/{chunk-ZEIT2QLM.js → chunk-EK77AJAH.js} +22 -4
  21. package/dist/{chunk-3S5AD4AB.js → chunk-FGOSKQDE.js} +3 -3
  22. package/dist/{chunk-GTPV2XGO.js → chunk-GJ6LM4JZ.js} +1 -441
  23. package/dist/chunk-H3REGQRI.js +107 -0
  24. package/dist/{chunk-J2IZBHXJ.js → chunk-LAKUB76X.js} +3 -3
  25. package/dist/{chunk-FVOGUCB6.js → chunk-R23T5SZG.js} +3 -3
  26. package/dist/{chunk-A7SHG75T.js → chunk-RF2L5SYG.js} +3 -3
  27. package/dist/{chunk-QMVQ6KPL.js → chunk-TL4DLMMW.js} +3 -3
  28. package/dist/{chunk-AV7XJJWK.js → chunk-TZBERHFM.js} +3 -3
  29. package/dist/{chunk-3AYKQHYI.js → chunk-UZBW44KD.js} +3 -3
  30. package/dist/{chunk-FS2UUJJO.js → chunk-XPMZB46F.js} +3 -3
  31. package/dist/cli/neuroverse.cjs +962 -284
  32. package/dist/cli/neuroverse.js +46 -22
  33. package/dist/cli/plan.js +1 -1
  34. package/dist/cli/run.cjs +242 -139
  35. package/dist/cli/run.js +23 -3
  36. package/dist/{demo-6OQYWRR6.js → demo-N5K4VXJW.js} +3 -3
  37. package/dist/{derive-7Y7YWVLU.js → derive-5LOMN7GO.js} +4 -4
  38. package/dist/{equity-penalties-NVBAB5WL.js → equity-penalties-PYCJ3Q4U.js} +6 -6
  39. package/dist/{explain-HDFN4ION.js → explain-42TVC3QD.js} +1 -1
  40. package/dist/{guard-6KSCWT2W.js → guard-TPYDFG6V.js} +16 -4
  41. package/dist/{improve-2PWGGO5B.js → improve-HLZGJ54Z.js} +3 -3
  42. package/dist/index.cjs +19 -1
  43. package/dist/index.d.cts +2 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +27 -27
  46. package/dist/keygen-BSZH3NM2.js +77 -0
  47. package/dist/{lens-MHMUDCMQ.js → lens-NFGZHD76.js} +1 -1
  48. package/dist/{mcp-server-TNIWZ7B5.js → mcp-server-5XXNG6VC.js} +2 -2
  49. package/dist/migrate-NH5PVMX4.js +221 -0
  50. package/dist/{playground-3FLDGBET.js → playground-2EU5CFIH.js} +4 -4
  51. package/dist/{redteam-HV6LMKEH.js → redteam-VK6OVHAE.js} +3 -3
  52. package/dist/{session-XZP2754M.js → session-NGA4DUPL.js} +2 -2
  53. package/dist/sign-RRELHKWM.js +11 -0
  54. package/dist/{simulate-VT437EEL.js → simulate-4YNOBMES.js} +1 -1
  55. package/dist/{test-4WTX6RKQ.js → test-HDBPMQTG.js} +3 -3
  56. package/dist/{validate-M52DX22Y.js → validate-6MFQZ2EG.js} +1 -1
  57. package/dist/verify-6AVTWX75.js +151 -0
  58. package/dist/{world-O4HTQPDP.js → world-H5WVURKU.js} +1 -1
  59. package/dist/{world-loader-YTYFOP7D.js → world-loader-J47PCPDZ.js} +1 -1
  60. package/package.json +22 -10
  61. package/dist/{behavioral-SLW7ALEK.js → behavioral-SPWPGYXL.js} +3 -3
  62. package/dist/{bootstrap-2OW5ZLBL.js → bootstrap-IP5QMC3Q.js} +3 -3
  63. package/dist/{chunk-I4RTIMLX.js → chunk-EQUAWNXW.js} +0 -0
  64. package/dist/{chunk-DA5MHFRR.js → chunk-NTHXZAW4.js} +3 -3
  65. package/dist/{chunk-FHXXD2TI.js → chunk-QZ666FCV.js} +6 -6
  66. package/dist/{configure-ai-LL3VAPQW.js → configure-ai-5MP5DWTT.js} +3 -3
  67. package/dist/{decision-flow-3K4D72G4.js → decision-flow-IJPNMVQK.js} +3 -3
  68. /package/dist/{doctor-EC5OYTI3.js → doctor-Q5APJOTS.js} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  handleListPresets,
7
7
  handleReasonRequest,
8
8
  writeTempWorld
9
- } from "./chunk-AV7XJJWK.js";
9
+ } from "./chunk-TZBERHFM.js";
10
10
  import {
11
11
  adaptationFromVerdict,
12
12
  detectBehavioralPatterns,
@@ -15,12 +15,12 @@ import {
15
15
  import {
16
16
  resolveWorldPath
17
17
  } from "./chunk-AKW5YVCE.js";
18
- import "./chunk-ZAF6JH23.js";
19
18
  import {
20
19
  DEFAULT_BUNDLED_WORLD,
21
20
  loadBundledWorld,
22
21
  loadWorld
23
- } from "./chunk-I4RTIMLX.js";
22
+ } from "./chunk-EQUAWNXW.js";
23
+ import "./chunk-ZAF6JH23.js";
24
24
  import "./chunk-QLPTHTVB.js";
25
25
  import {
26
26
  __require
@@ -2,15 +2,15 @@ import {
2
2
  DeriveInputError,
3
3
  DeriveProviderError,
4
4
  deriveWorld
5
- } from "./chunk-FHXXD2TI.js";
5
+ } from "./chunk-QZ666FCV.js";
6
6
  import {
7
7
  DERIVE_EXIT_CODES
8
8
  } from "./chunk-FMSTRBBS.js";
9
- import "./chunk-INWQHLPS.js";
10
9
  import "./chunk-OT6PXH54.js";
10
+ import "./chunk-INWQHLPS.js";
11
11
  import "./chunk-7P3S7MAY.js";
12
- import "./chunk-YPCVY4GS.js";
13
12
  import "./chunk-3NZMMSOW.js";
13
+ import "./chunk-YPCVY4GS.js";
14
14
  import "./chunk-QWGCMQQD.js";
15
15
 
16
16
  // src/cli/derive.ts
@@ -121,7 +121,7 @@ Normalization: ${n.fixCount} fix(es) applied
121
121
  process.stderr.write(`
122
122
  Bootstrapping to ${args.bootstrapDir}...
123
123
  `);
124
- const { main: bootstrapMain } = await import("./bootstrap-2OW5ZLBL.js");
124
+ const { main: bootstrapMain } = await import("./bootstrap-IP5QMC3Q.js");
125
125
  await bootstrapMain([
126
126
  "--input",
127
127
  result.outputPath,
@@ -1,6 +1,3 @@
1
- import {
2
- verdictToAuditEvent
3
- } from "./chunk-2VAWP6FI.js";
4
1
  import {
5
2
  applyConsequence,
6
3
  applyReward,
@@ -10,11 +7,14 @@ import {
10
7
  tickAgentStates
11
8
  } from "./chunk-D2UCV5AK.js";
12
9
  import {
13
- evaluateGuard
14
- } from "./chunk-ZAF6JH23.js";
10
+ verdictToAuditEvent
11
+ } from "./chunk-2VAWP6FI.js";
15
12
  import {
16
13
  loadWorld
17
- } from "./chunk-I4RTIMLX.js";
14
+ } from "./chunk-EQUAWNXW.js";
15
+ import {
16
+ evaluateGuard
17
+ } from "./chunk-ZAF6JH23.js";
18
18
  import "./chunk-QLPTHTVB.js";
19
19
  import "./chunk-QWGCMQQD.js";
20
20
 
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-ZJTDUCC2.js";
8
8
  import {
9
9
  loadWorld
10
- } from "./chunk-I4RTIMLX.js";
10
+ } from "./chunk-EQUAWNXW.js";
11
11
  import "./chunk-QWGCMQQD.js";
12
12
 
13
13
  // src/cli/explain.ts
@@ -6,16 +6,20 @@ import {
6
6
  evaluateGuardWithAI
7
7
  } from "./chunk-6CV4XG3J.js";
8
8
  import "./chunk-INWQHLPS.js";
9
+ import {
10
+ FileAuditLogger,
11
+ verdictToAuditEvent
12
+ } from "./chunk-2VAWP6FI.js";
9
13
  import {
10
14
  describeActiveWorld,
11
15
  resolveWorldPath
12
16
  } from "./chunk-AKW5YVCE.js";
17
+ import {
18
+ loadWorld
19
+ } from "./chunk-EQUAWNXW.js";
13
20
  import {
14
21
  evaluateGuard
15
22
  } from "./chunk-ZAF6JH23.js";
16
- import {
17
- loadWorld
18
- } from "./chunk-I4RTIMLX.js";
19
23
  import "./chunk-QLPTHTVB.js";
20
24
  import "./chunk-QWGCMQQD.js";
21
25
 
@@ -25,6 +29,7 @@ function parseArgs(argv) {
25
29
  let trace = false;
26
30
  let level;
27
31
  let aiClassify = false;
32
+ let logPath;
28
33
  for (let i = 0; i < argv.length; i++) {
29
34
  const arg = argv[i];
30
35
  if (arg === "--world" && i + 1 < argv.length) {
@@ -33,6 +38,8 @@ function parseArgs(argv) {
33
38
  trace = true;
34
39
  } else if (arg === "--ai-classify") {
35
40
  aiClassify = true;
41
+ } else if (arg === "--log" && i + 1 < argv.length) {
42
+ logPath = argv[++i];
36
43
  } else if (arg === "--level" && i + 1 < argv.length) {
37
44
  const val = argv[++i];
38
45
  if (val === "basic" || val === "standard" || val === "strict") {
@@ -42,7 +49,7 @@ function parseArgs(argv) {
42
49
  }
43
50
  }
44
51
  }
45
- return { worldPath, trace, level, aiClassify };
52
+ return { worldPath, trace, level, aiClassify, logPath };
46
53
  }
47
54
  async function main(argv = process.argv.slice(2)) {
48
55
  try {
@@ -102,6 +109,11 @@ async function main(argv = process.argv.slice(2)) {
102
109
  const options = { trace: args.trace, level: args.level };
103
110
  verdict = evaluateGuard(event, world, options);
104
111
  }
112
+ if (args.logPath) {
113
+ const logger = new FileAuditLogger(args.logPath, { flushIntervalMs: 0 });
114
+ logger.log(verdictToAuditEvent(event, verdict));
115
+ await logger.flush();
116
+ }
105
117
  process.stdout.write(JSON.stringify(verdict, null, 2) + "\n");
106
118
  const exitCode = GUARD_EXIT_CODES[verdict.status];
107
119
  process.exit(exitCode);
@@ -4,12 +4,12 @@ import {
4
4
  import {
5
5
  improveWorld,
6
6
  renderImproveText
7
- } from "./chunk-DA5MHFRR.js";
8
- import "./chunk-CYDMUJVZ.js";
7
+ } from "./chunk-NTHXZAW4.js";
9
8
  import "./chunk-7P3S7MAY.js";
9
+ import "./chunk-CYDMUJVZ.js";
10
10
  import {
11
11
  loadWorld
12
- } from "./chunk-I4RTIMLX.js";
12
+ } from "./chunk-EQUAWNXW.js";
13
13
  import "./chunk-QWGCMQQD.js";
14
14
 
15
15
  // src/cli/improve.ts
package/dist/index.cjs CHANGED
@@ -2833,7 +2833,9 @@ function emptyFlow() {
2833
2833
  async function defaultToolExecutor(name, args) {
2834
2834
  return `Tool "${name}" executed successfully with args: ${JSON.stringify(args)}`;
2835
2835
  }
2836
- var SessionManager = class {
2836
+ var SessionManager = class _SessionManager {
2837
+ /** Maximum unique agent IDs tracked before eviction. Prevents unbounded memory growth. */
2838
+ static MAX_AGENTS = 1e4;
2837
2839
  config;
2838
2840
  state;
2839
2841
  engineOptions;
@@ -2897,6 +2899,16 @@ var SessionManager = class {
2897
2899
  if (verdict.status === "REWARD" && verdict.reward) {
2898
2900
  agentState = applyReward(agentState, verdict.reward, verdict.ruleId ?? "unknown");
2899
2901
  }
2902
+ if (this.state.agentStates.size >= _SessionManager.MAX_AGENTS && !this.state.agentStates.has(event.roleId)) {
2903
+ const oldest = this.state.agentStates.keys().next().value;
2904
+ if (oldest !== void 0) {
2905
+ this.state.agentStates.delete(oldest);
2906
+ }
2907
+ process.stderr.write(
2908
+ `[neuroverse] Warning: agent state map at capacity (${_SessionManager.MAX_AGENTS}), evicted oldest entry
2909
+ `
2910
+ );
2911
+ }
2900
2912
  this.state.agentStates.set(event.roleId, agentState);
2901
2913
  }
2902
2914
  this.config.onVerdict?.(verdict, event);
@@ -3007,11 +3019,17 @@ async function runPipeMode(config) {
3007
3019
  process.stderr.write(`[neuroverse] Plan: ${state.plan.plan_id} (${state.plan.objective})
3008
3020
  `);
3009
3021
  }
3022
+ const MAX_BUFFER_SIZE = 1e6;
3010
3023
  return new Promise((resolve3, reject) => {
3011
3024
  let buffer = "";
3012
3025
  process.stdin.setEncoding("utf-8");
3013
3026
  process.stdin.on("data", (chunk) => {
3014
3027
  buffer += chunk;
3028
+ if (buffer.length > MAX_BUFFER_SIZE) {
3029
+ process.stderr.write("[neuroverse] Warning: pipe buffer exceeded 1MB, resetting\n");
3030
+ buffer = "";
3031
+ return;
3032
+ }
3015
3033
  const lines = buffer.split("\n");
3016
3034
  buffer = lines.pop() ?? "";
3017
3035
  for (const line of lines) {
package/dist/index.d.cts CHANGED
@@ -479,6 +479,8 @@ interface SessionState {
479
479
  agentStates: Map<string, AgentBehaviorState>;
480
480
  }
481
481
  declare class SessionManager {
482
+ /** Maximum unique agent IDs tracked before eviction. Prevents unbounded memory growth. */
483
+ private static readonly MAX_AGENTS;
482
484
  private config;
483
485
  private state;
484
486
  private engineOptions;
package/dist/index.d.ts CHANGED
@@ -479,6 +479,8 @@ interface SessionState {
479
479
  agentStates: Map<string, AgentBehaviorState>;
480
480
  }
481
481
  declare class SessionManager {
482
+ /** Maximum unique agent IDs tracked before eviction. Prevents unbounded memory growth. */
483
+ private static readonly MAX_AGENTS;
482
484
  private config;
483
485
  private state;
484
486
  private engineOptions;
package/dist/index.js CHANGED
@@ -3,15 +3,6 @@ import {
3
3
  generateImpactReportFromFile,
4
4
  renderImpactReport
5
5
  } from "./chunk-OQU65525.js";
6
- import {
7
- CompositeAuditLogger,
8
- ConsoleAuditLogger,
9
- FileAuditLogger,
10
- createGovernanceEngine,
11
- readAuditLog,
12
- summarizeAuditEvents,
13
- verdictToAuditEvent
14
- } from "./chunk-2VAWP6FI.js";
15
6
  import {
16
7
  BOOTSTRAP_EXIT_CODES
17
8
  } from "./chunk-4NGDRRQH.js";
@@ -33,7 +24,7 @@ import {
33
24
  handleListPresets,
34
25
  handleReasonRequest,
35
26
  writeTempWorld
36
- } from "./chunk-AV7XJJWK.js";
27
+ } from "./chunk-TZBERHFM.js";
37
28
  import {
38
29
  adaptationFromVerdict,
39
30
  classifyAdaptation,
@@ -46,18 +37,18 @@ import {
46
37
  addRule,
47
38
  classifyIntent,
48
39
  parseGuardDescription
49
- } from "./chunk-FS2UUJJO.js";
40
+ } from "./chunk-XPMZB46F.js";
50
41
  import {
51
42
  deriveWorld,
52
43
  extractWorldMarkdown,
53
44
  normalizeWorldMarkdown
54
- } from "./chunk-FHXXD2TI.js";
45
+ } from "./chunk-QZ666FCV.js";
55
46
  import {
56
47
  CONFIGURE_AI_EXIT_CODES,
57
48
  DERIVE_EXIT_CODES
58
49
  } from "./chunk-FMSTRBBS.js";
59
- import "./chunk-INWQHLPS.js";
60
50
  import "./chunk-OT6PXH54.js";
51
+ import "./chunk-INWQHLPS.js";
61
52
  import {
62
53
  explainWorld,
63
54
  renderExplainText
@@ -65,7 +56,13 @@ import {
65
56
  import {
66
57
  improveWorld,
67
58
  renderImproveText
68
- } from "./chunk-DA5MHFRR.js";
59
+ } from "./chunk-NTHXZAW4.js";
60
+ import {
61
+ validateWorld
62
+ } from "./chunk-7P3S7MAY.js";
63
+ import {
64
+ parseWorldMarkdown
65
+ } from "./chunk-3NZMMSOW.js";
69
66
  import {
70
67
  renderSimulateText,
71
68
  simulateWorld
@@ -74,7 +71,7 @@ import {
74
71
  SessionManager,
75
72
  runInteractiveMode,
76
73
  runPipeMode
77
- } from "./chunk-ZEIT2QLM.js";
74
+ } from "./chunk-EK77AJAH.js";
78
75
  import {
79
76
  applyConsequence,
80
77
  applyReward,
@@ -90,14 +87,20 @@ import {
90
87
  } from "./chunk-A5W4GNQO.js";
91
88
  import {
92
89
  McpGovernanceServer
93
- } from "./chunk-J2IZBHXJ.js";
94
- import {
95
- validateWorld
96
- } from "./chunk-7P3S7MAY.js";
90
+ } from "./chunk-LAKUB76X.js";
97
91
  import {
98
92
  PLAN_EXIT_CODES,
99
93
  parsePlanMarkdown
100
94
  } from "./chunk-6CZSKEY5.js";
95
+ import {
96
+ CompositeAuditLogger,
97
+ ConsoleAuditLogger,
98
+ FileAuditLogger,
99
+ createGovernanceEngine,
100
+ readAuditLog,
101
+ summarizeAuditEvents,
102
+ verdictToAuditEvent
103
+ } from "./chunk-2VAWP6FI.js";
101
104
  import {
102
105
  describeActiveWorld,
103
106
  getActiveWorldName,
@@ -108,9 +111,6 @@ import {
108
111
  import {
109
112
  emitWorldDefinition
110
113
  } from "./chunk-YPCVY4GS.js";
111
- import {
112
- parseWorldMarkdown
113
- } from "./chunk-3NZMMSOW.js";
114
114
  import {
115
115
  GitHubGovernanceBlockedError,
116
116
  GitHubGovernor,
@@ -121,17 +121,17 @@ import {
121
121
  createGitHubWebhookHandlerFromWorld,
122
122
  formatForActions,
123
123
  formatPRComment
124
- } from "./chunk-3S5AD4AB.js";
124
+ } from "./chunk-FGOSKQDE.js";
125
125
  import "./chunk-5U2MQO5P.js";
126
+ import {
127
+ loadWorld,
128
+ loadWorldFromDirectory
129
+ } from "./chunk-EQUAWNXW.js";
126
130
  import {
127
131
  evaluateGuard,
128
132
  eventToAllowlistKey,
129
133
  verdictToEvent
130
134
  } from "./chunk-ZAF6JH23.js";
131
- import {
132
- loadWorld,
133
- loadWorldFromDirectory
134
- } from "./chunk-I4RTIMLX.js";
135
135
  import {
136
136
  advancePlan,
137
137
  buildPlanCheck,
@@ -0,0 +1,77 @@
1
+ import "./chunk-QWGCMQQD.js";
2
+
3
+ // src/cli/keygen.ts
4
+ import { generateKeyPairSync } from "crypto";
5
+ import { writeFileSync, mkdirSync, existsSync } from "fs";
6
+ import { join } from "path";
7
+ import { homedir } from "os";
8
+ var USAGE = `
9
+ neuroverse keygen \u2014 Generate Ed25519 signing keypair
10
+
11
+ Usage:
12
+ neuroverse keygen [--output <dir>] [--name <name>]
13
+
14
+ Options:
15
+ --output <dir> Key directory (default: ~/.neuroverse/keys/)
16
+ --name <name> Key name (default: neuroverse)
17
+ --force Overwrite existing keys
18
+
19
+ Examples:
20
+ neuroverse keygen
21
+ neuroverse keygen --name production --output ./keys/
22
+ `.trim();
23
+ function parseArgs(argv) {
24
+ let output = join(homedir(), ".neuroverse", "keys");
25
+ let name = "neuroverse";
26
+ let force = false;
27
+ let help = false;
28
+ for (let i = 0; i < argv.length; i++) {
29
+ const arg = argv[i];
30
+ if ((arg === "--output" || arg === "-o") && argv[i + 1]) {
31
+ output = argv[++i];
32
+ } else if ((arg === "--name" || arg === "-n") && argv[i + 1]) {
33
+ name = argv[++i];
34
+ } else if (arg === "--force") {
35
+ force = true;
36
+ } else if (arg === "--help" || arg === "-h") {
37
+ help = true;
38
+ }
39
+ }
40
+ return { output, name, force, help };
41
+ }
42
+ async function main(argv = process.argv.slice(2)) {
43
+ const args = parseArgs(argv);
44
+ if (args.help) {
45
+ process.stdout.write(USAGE + "\n");
46
+ return;
47
+ }
48
+ const pubPath = join(args.output, `${args.name}.pub`);
49
+ const keyPath = join(args.output, `${args.name}.key`);
50
+ if (!args.force && (existsSync(pubPath) || existsSync(keyPath))) {
51
+ process.stderr.write(`Keys already exist at ${args.output}/${args.name}.*
52
+ `);
53
+ process.stderr.write("Use --force to overwrite.\n");
54
+ process.exit(1);
55
+ }
56
+ const { publicKey, privateKey } = generateKeyPairSync("ed25519", {
57
+ publicKeyEncoding: { type: "spki", format: "pem" },
58
+ privateKeyEncoding: { type: "pkcs8", format: "pem" }
59
+ });
60
+ mkdirSync(args.output, { recursive: true });
61
+ writeFileSync(pubPath, publicKey, "utf-8");
62
+ writeFileSync(keyPath, privateKey, { encoding: "utf-8", mode: 384 });
63
+ process.stdout.write(`Keypair generated:
64
+ `);
65
+ process.stdout.write(` Public: ${pubPath}
66
+ `);
67
+ process.stdout.write(` Private: ${keyPath}
68
+ `);
69
+ process.stdout.write(`
70
+ Share the .pub file with anyone who needs to verify your worlds.
71
+ `);
72
+ process.stdout.write(`Keep the .key file secret.
73
+ `);
74
+ }
75
+ export {
76
+ main
77
+ };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-BQZMOEML.js";
4
4
  import {
5
5
  loadWorld
6
- } from "./chunk-I4RTIMLX.js";
6
+ } from "./chunk-EQUAWNXW.js";
7
7
  import "./chunk-QWGCMQQD.js";
8
8
 
9
9
  // src/builder/lens.ts
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  McpGovernanceServer,
3
3
  startMcpServer
4
- } from "./chunk-J2IZBHXJ.js";
4
+ } from "./chunk-LAKUB76X.js";
5
5
  import "./chunk-AKW5YVCE.js";
6
+ import "./chunk-EQUAWNXW.js";
6
7
  import "./chunk-ZAF6JH23.js";
7
- import "./chunk-I4RTIMLX.js";
8
8
  import "./chunk-QLPTHTVB.js";
9
9
  import "./chunk-QWGCMQQD.js";
10
10
  export {
@@ -0,0 +1,221 @@
1
+ import "./chunk-QWGCMQQD.js";
2
+
3
+ // src/cli/migrate.ts
4
+ import { readFileSync, writeFileSync, cpSync, existsSync } from "fs";
5
+ import { join } from "path";
6
+ var USAGE = `
7
+ neuroverse migrate \u2014 World schema version migration
8
+
9
+ Usage:
10
+ neuroverse migrate --world <dir> [options]
11
+
12
+ Options:
13
+ --world <dir> World directory to migrate (required)
14
+ --dry-run Show what would change without modifying files
15
+ --backup Copy original world to <dir>.backup before migrating
16
+ --target <version> Target schema version (default: latest)
17
+ --json Output migration plan as JSON
18
+
19
+ Examples:
20
+ neuroverse migrate --world ./world/ --dry-run
21
+ neuroverse migrate --world ./world/ --backup
22
+ neuroverse migrate --world ./world/ --target 1.1.0
23
+ `.trim();
24
+ var MIGRATIONS = [
25
+ {
26
+ from: "1.0.0",
27
+ to: "1.1.0",
28
+ description: "Add enforcement_level to world.json, normalize metadata fields",
29
+ apply: (worldPath) => {
30
+ const changes = [];
31
+ const worldJsonPath = join(worldPath, "world.json");
32
+ if (existsSync(worldJsonPath)) {
33
+ const world = JSON.parse(readFileSync(worldJsonPath, "utf-8"));
34
+ if (!world.enforcement_level) {
35
+ world.enforcement_level = "standard";
36
+ writeFileSync(worldJsonPath, JSON.stringify(world, null, 2) + "\n", "utf-8");
37
+ changes.push({
38
+ file: "world.json",
39
+ action: "modified",
40
+ description: 'Added enforcement_level: "standard"'
41
+ });
42
+ }
43
+ }
44
+ const metaPath = join(worldPath, "metadata.json");
45
+ if (existsSync(metaPath)) {
46
+ const meta = JSON.parse(readFileSync(metaPath, "utf-8"));
47
+ let modified = false;
48
+ if (meta.configurator_version && !meta.authoring_method) {
49
+ meta.authoring_method = meta.configurator_version;
50
+ delete meta.configurator_version;
51
+ modified = true;
52
+ }
53
+ if (!meta.schema_version) {
54
+ meta.schema_version = "1.1.0";
55
+ modified = true;
56
+ } else {
57
+ meta.schema_version = "1.1.0";
58
+ modified = true;
59
+ }
60
+ if (modified) {
61
+ writeFileSync(metaPath, JSON.stringify(meta, null, 2) + "\n", "utf-8");
62
+ changes.push({
63
+ file: "metadata.json",
64
+ action: "modified",
65
+ description: "Normalized metadata fields, updated schema_version to 1.1.0"
66
+ });
67
+ }
68
+ }
69
+ return changes;
70
+ }
71
+ }
72
+ ];
73
+ var LATEST_VERSION = MIGRATIONS.length > 0 ? MIGRATIONS[MIGRATIONS.length - 1].to : "1.0.0";
74
+ function detectVersion(worldPath) {
75
+ const metaPath = join(worldPath, "metadata.json");
76
+ if (existsSync(metaPath)) {
77
+ try {
78
+ const meta = JSON.parse(readFileSync(metaPath, "utf-8"));
79
+ if (meta.schema_version) return meta.schema_version;
80
+ } catch {
81
+ }
82
+ }
83
+ return "1.0.0";
84
+ }
85
+ function compareVersions(a, b) {
86
+ const pa = a.split(".").map(Number);
87
+ const pb = b.split(".").map(Number);
88
+ for (let i = 0; i < 3; i++) {
89
+ if ((pa[i] ?? 0) < (pb[i] ?? 0)) return -1;
90
+ if ((pa[i] ?? 0) > (pb[i] ?? 0)) return 1;
91
+ }
92
+ return 0;
93
+ }
94
+ function findMigrationPath(from, to) {
95
+ const path = [];
96
+ let current = from;
97
+ while (compareVersions(current, to) < 0) {
98
+ const next = MIGRATIONS.find((m) => m.from === current);
99
+ if (!next) break;
100
+ path.push(next);
101
+ current = next.to;
102
+ }
103
+ return path;
104
+ }
105
+ function parseArgs(argv) {
106
+ let worldPath = "";
107
+ let dryRun = false;
108
+ let backup = false;
109
+ let target = LATEST_VERSION;
110
+ let json = false;
111
+ let help = false;
112
+ for (let i = 0; i < argv.length; i++) {
113
+ const arg = argv[i];
114
+ if (arg === "--world" && argv[i + 1]) {
115
+ worldPath = argv[++i];
116
+ } else if (arg === "--dry-run") {
117
+ dryRun = true;
118
+ } else if (arg === "--backup") {
119
+ backup = true;
120
+ } else if (arg === "--target" && argv[i + 1]) {
121
+ target = argv[++i];
122
+ } else if (arg === "--json") {
123
+ json = true;
124
+ } else if (arg === "--help" || arg === "-h") {
125
+ help = true;
126
+ }
127
+ }
128
+ return { worldPath, dryRun, backup, target, json, help };
129
+ }
130
+ async function main(argv = process.argv.slice(2)) {
131
+ const args = parseArgs(argv);
132
+ if (args.help) {
133
+ process.stdout.write(USAGE + "\n");
134
+ return;
135
+ }
136
+ if (!args.worldPath) {
137
+ process.stderr.write("Error: --world <dir> is required.\n");
138
+ process.exit(1);
139
+ }
140
+ const currentVersion = detectVersion(args.worldPath);
141
+ const targetVersion = args.target;
142
+ if (compareVersions(currentVersion, targetVersion) >= 0) {
143
+ const plan2 = {
144
+ currentVersion,
145
+ targetVersion,
146
+ migrations: [],
147
+ changes: []
148
+ };
149
+ if (args.json) {
150
+ process.stdout.write(JSON.stringify(plan2, null, 2) + "\n");
151
+ } else {
152
+ process.stdout.write(`World is already at version ${currentVersion} (target: ${targetVersion})
153
+ `);
154
+ process.stdout.write("No migrations needed.\n");
155
+ }
156
+ return;
157
+ }
158
+ const migrationPath = findMigrationPath(currentVersion, targetVersion);
159
+ if (migrationPath.length === 0) {
160
+ process.stderr.write(`No migration path from ${currentVersion} to ${targetVersion}
161
+ `);
162
+ process.exit(1);
163
+ return;
164
+ }
165
+ if (args.dryRun) {
166
+ const plan2 = {
167
+ currentVersion,
168
+ targetVersion,
169
+ migrations: migrationPath.map((m) => ({ from: m.from, to: m.to, description: m.description })),
170
+ changes: []
171
+ };
172
+ if (args.json) {
173
+ process.stdout.write(JSON.stringify(plan2, null, 2) + "\n");
174
+ } else {
175
+ process.stdout.write(`Migration plan: ${currentVersion} \u2192 ${targetVersion}
176
+ `);
177
+ process.stdout.write(`Steps: ${migrationPath.length}
178
+
179
+ `);
180
+ for (const m of migrationPath) {
181
+ process.stdout.write(` ${m.from} \u2192 ${m.to}: ${m.description}
182
+ `);
183
+ }
184
+ process.stdout.write("\nRun without --dry-run to apply.\n");
185
+ }
186
+ return;
187
+ }
188
+ if (args.backup) {
189
+ const backupPath = args.worldPath + ".backup";
190
+ cpSync(args.worldPath, backupPath, { recursive: true });
191
+ process.stdout.write(`Backup created: ${backupPath}
192
+ `);
193
+ }
194
+ const allChanges = [];
195
+ for (const migration of migrationPath) {
196
+ process.stdout.write(`Applying: ${migration.from} \u2192 ${migration.to} (${migration.description})
197
+ `);
198
+ const changes = migration.apply(args.worldPath);
199
+ allChanges.push(...changes);
200
+ for (const change of changes) {
201
+ process.stdout.write(` ${change.action}: ${change.file} \u2014 ${change.description}
202
+ `);
203
+ }
204
+ }
205
+ const plan = {
206
+ currentVersion,
207
+ targetVersion,
208
+ migrations: migrationPath.map((m) => ({ from: m.from, to: m.to, description: m.description })),
209
+ changes: allChanges
210
+ };
211
+ if (args.json) {
212
+ process.stdout.write(JSON.stringify(plan, null, 2) + "\n");
213
+ }
214
+ process.stdout.write(`
215
+ Migration complete: ${currentVersion} \u2192 ${targetVersion} (${allChanges.length} changes)
216
+ `);
217
+ }
218
+ export {
219
+ LATEST_VERSION,
220
+ main
221
+ };