@neuroverseos/governance 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2002,10 +2002,10 @@ __export(world_loader_exports, {
2002
2002
  });
2003
2003
  async function loadWorldFromDirectory(dirPath) {
2004
2004
  const { readFile: readFile4 } = await import("fs/promises");
2005
- const { join: join19 } = await import("path");
2005
+ const { join: join21 } = await import("path");
2006
2006
  const { readdirSync: readdirSync11 } = await import("fs");
2007
2007
  async function readJson(filename) {
2008
- const filePath = join19(dirPath, filename);
2008
+ const filePath = join21(dirPath, filename);
2009
2009
  try {
2010
2010
  const content = await readFile4(filePath, "utf-8");
2011
2011
  return JSON.parse(content);
@@ -2035,11 +2035,11 @@ async function loadWorldFromDirectory(dirPath) {
2035
2035
  const metadataJson = await readJson("metadata.json");
2036
2036
  const rules = [];
2037
2037
  try {
2038
- const rulesDir = join19(dirPath, "rules");
2038
+ const rulesDir = join21(dirPath, "rules");
2039
2039
  const ruleFiles = readdirSync11(rulesDir).filter((f) => f.endsWith(".json")).sort();
2040
2040
  for (const file of ruleFiles) {
2041
2041
  try {
2042
- const content = await readFile4(join19(rulesDir, file), "utf-8");
2042
+ const content = await readFile4(join21(rulesDir, file), "utf-8");
2043
2043
  rules.push(JSON.parse(content));
2044
2044
  } catch (err) {
2045
2045
  process.stderr.write(
@@ -2093,8 +2093,8 @@ async function loadWorld(worldPath) {
2093
2093
  }
2094
2094
  async function loadBundledWorld(name = DEFAULT_BUNDLED_WORLD) {
2095
2095
  const { readFile: readFile4 } = await import("fs/promises");
2096
- const { join: join19, dirname: dirname4 } = await import("path");
2097
- const { existsSync: existsSync15 } = await import("fs");
2096
+ const { join: join21, dirname: dirname4 } = await import("path");
2097
+ const { existsSync: existsSync17 } = await import("fs");
2098
2098
  const { fileURLToPath: fileURLToPath3 } = await import("url");
2099
2099
  const { parseWorldMarkdown: parseWorldMarkdown2 } = await Promise.resolve().then(() => (init_bootstrap_parser(), bootstrap_parser_exports));
2100
2100
  const { emitWorldDefinition: emitWorldDefinition2 } = await Promise.resolve().then(() => (init_bootstrap_emitter(), bootstrap_emitter_exports));
@@ -2102,16 +2102,16 @@ async function loadBundledWorld(name = DEFAULT_BUNDLED_WORLD) {
2102
2102
  let packageRoot;
2103
2103
  try {
2104
2104
  const thisFile = typeof __dirname !== "undefined" ? __dirname : dirname4(fileURLToPath3(import_meta.url));
2105
- packageRoot = join19(thisFile, "..", "..");
2105
+ packageRoot = join21(thisFile, "..", "..");
2106
2106
  } catch {
2107
2107
  packageRoot = process.cwd();
2108
2108
  }
2109
2109
  const candidates = [
2110
- join19(packageRoot, "dist", "worlds", filename),
2111
- join19(packageRoot, "src", "worlds", filename)
2110
+ join21(packageRoot, "dist", "worlds", filename),
2111
+ join21(packageRoot, "src", "worlds", filename)
2112
2112
  ];
2113
2113
  for (const candidate of candidates) {
2114
- if (existsSync15(candidate)) {
2114
+ if (existsSync17(candidate)) {
2115
2115
  const markdown = await readFile4(candidate, "utf-8");
2116
2116
  const parsed = parseWorldMarkdown2(markdown);
2117
2117
  if (!parsed.world) {
@@ -2141,8 +2141,8 @@ function slugify(text) {
2141
2141
  }
2142
2142
  async function addGuard(worldDir, input) {
2143
2143
  const { readFile: readFile4, writeFile: writeFile6 } = await import("fs/promises");
2144
- const { join: join19 } = await import("path");
2145
- const guardsPath = join19(worldDir, "guards.json");
2144
+ const { join: join21 } = await import("path");
2145
+ const guardsPath = join21(worldDir, "guards.json");
2146
2146
  let config;
2147
2147
  try {
2148
2148
  const raw = await readFile4(guardsPath, "utf-8");
@@ -2182,9 +2182,9 @@ async function addGuard(worldDir, input) {
2182
2182
  }
2183
2183
  async function addRule(worldDir, input) {
2184
2184
  const { readFile: readFile4, writeFile: writeFile6, mkdir: mkdir3 } = await import("fs/promises");
2185
- const { join: join19 } = await import("path");
2185
+ const { join: join21 } = await import("path");
2186
2186
  const { readdirSync: readdirSync11 } = await import("fs");
2187
- const rulesDir = join19(worldDir, "rules");
2187
+ const rulesDir = join21(worldDir, "rules");
2188
2188
  await mkdir3(rulesDir, { recursive: true });
2189
2189
  let nextNum = 1;
2190
2190
  try {
@@ -2214,7 +2214,7 @@ async function addRule(worldDir, input) {
2214
2214
  effect_text: input.effects ? input.effects.map((e) => `${e.target} ${e.operation} ${e.value}`).join(", ") : "No direct effects"
2215
2215
  }
2216
2216
  };
2217
- const rulePath = join19(rulesDir, `rule-${ruleNum}.json`);
2217
+ const rulePath = join21(rulesDir, `rule-${ruleNum}.json`);
2218
2218
  await writeFile6(rulePath, JSON.stringify(rule, null, 2) + "\n");
2219
2219
  const { loadWorldFromDirectory: loadWorldFromDirectory3 } = await Promise.resolve().then(() => (init_world_loader(), world_loader_exports));
2220
2220
  const world = await loadWorldFromDirectory3(worldDir);
@@ -2230,8 +2230,8 @@ async function addRule(worldDir, input) {
2230
2230
  }
2231
2231
  async function addInvariant(worldDir, input) {
2232
2232
  const { readFile: readFile4, writeFile: writeFile6 } = await import("fs/promises");
2233
- const { join: join19 } = await import("path");
2234
- const invariantsPath = join19(worldDir, "invariants.json");
2233
+ const { join: join21 } = await import("path");
2234
+ const invariantsPath = join21(worldDir, "invariants.json");
2235
2235
  let config;
2236
2236
  try {
2237
2237
  const raw = await readFile4(invariantsPath, "utf-8");
@@ -3528,21 +3528,21 @@ function parseArgs2(argv) {
3528
3528
  }
3529
3529
  async function writeWorldFiles(outputDir, world) {
3530
3530
  const { writeFile: writeFile6, mkdir: mkdir3 } = await import("fs/promises");
3531
- const { join: join19 } = await import("path");
3531
+ const { join: join21 } = await import("path");
3532
3532
  await mkdir3(outputDir, { recursive: true });
3533
- await writeFile6(join19(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
3534
- await writeFile6(join19(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
3535
- await writeFile6(join19(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
3536
- await writeFile6(join19(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
3537
- await writeFile6(join19(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
3538
- await writeFile6(join19(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
3539
- await writeFile6(join19(outputDir, "metadata.json"), JSON.stringify(world.metadata, null, 2));
3540
- const rulesDir = join19(outputDir, "rules");
3533
+ await writeFile6(join21(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
3534
+ await writeFile6(join21(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
3535
+ await writeFile6(join21(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
3536
+ await writeFile6(join21(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
3537
+ await writeFile6(join21(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
3538
+ await writeFile6(join21(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
3539
+ await writeFile6(join21(outputDir, "metadata.json"), JSON.stringify(world.metadata, null, 2));
3540
+ const rulesDir = join21(outputDir, "rules");
3541
3541
  await mkdir3(rulesDir, { recursive: true });
3542
3542
  const sortedRules = [...world.rules].sort((a, b) => a.order - b.order);
3543
3543
  for (let i = 0; i < sortedRules.length; i++) {
3544
3544
  const ruleNum = String(i + 1).padStart(3, "0");
3545
- await writeFile6(join19(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
3545
+ await writeFile6(join21(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
3546
3546
  }
3547
3547
  }
3548
3548
  function write(msg) {
@@ -3673,9 +3673,9 @@ World source written to: ${derivedPath}
3673
3673
  try {
3674
3674
  const emitResult = emitWorldDefinition(parseResult.world);
3675
3675
  await writeWorldFiles(outputDir, emitResult.world);
3676
- const { join: join19 } = await import("path");
3676
+ const { join: join21 } = await import("path");
3677
3677
  const { copyFile } = await import("fs/promises");
3678
- const sourceDest = join19(outputDir, "source.nv-world.md");
3678
+ const sourceDest = join21(outputDir, "source.nv-world.md");
3679
3679
  if (derivedPath !== sourceDest) {
3680
3680
  await copyFile(derivedPath, sourceDest);
3681
3681
  }
@@ -5009,8 +5009,8 @@ async function main6(argv = process.argv.slice(2)) {
5009
5009
  try {
5010
5010
  const args = parseArgs6(argv);
5011
5011
  const { writeFile: writeFile6 } = await import("fs/promises");
5012
- const { existsSync: existsSync15 } = await import("fs");
5013
- if (existsSync15(args.outputPath)) {
5012
+ const { existsSync: existsSync17 } = await import("fs");
5013
+ if (existsSync17(args.outputPath)) {
5014
5014
  process.stderr.write(`File already exists: ${args.outputPath}
5015
5015
  `);
5016
5016
  process.stderr.write("Use a different --output path or remove the existing file.\n");
@@ -5868,22 +5868,22 @@ function parseArgs9(argv) {
5868
5868
  }
5869
5869
  async function writeWorldFiles2(outputDir, world) {
5870
5870
  const { writeFile: writeFile6, mkdir: mkdir3 } = await import("fs/promises");
5871
- const { join: join19 } = await import("path");
5871
+ const { join: join21 } = await import("path");
5872
5872
  await mkdir3(outputDir, { recursive: true });
5873
- await writeFile6(join19(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
5874
- await writeFile6(join19(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
5875
- await writeFile6(join19(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
5876
- await writeFile6(join19(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
5877
- const rulesDir = join19(outputDir, "rules");
5873
+ await writeFile6(join21(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
5874
+ await writeFile6(join21(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
5875
+ await writeFile6(join21(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
5876
+ await writeFile6(join21(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
5877
+ const rulesDir = join21(outputDir, "rules");
5878
5878
  await mkdir3(rulesDir, { recursive: true });
5879
5879
  const sortedRules = [...world.rules].sort((a, b) => a.order - b.order);
5880
5880
  for (let i = 0; i < sortedRules.length; i++) {
5881
5881
  const ruleNum = String(i + 1).padStart(3, "0");
5882
- await writeFile6(join19(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
5882
+ await writeFile6(join21(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
5883
5883
  }
5884
- await writeFile6(join19(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
5885
- await writeFile6(join19(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
5886
- await writeFile6(join19(outputDir, "metadata.json"), JSON.stringify(world.metadata, null, 2));
5884
+ await writeFile6(join21(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
5885
+ await writeFile6(join21(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
5886
+ await writeFile6(join21(outputDir, "metadata.json"), JSON.stringify(world.metadata, null, 2));
5887
5887
  }
5888
5888
  async function main9(argv = process.argv.slice(2)) {
5889
5889
  const startTime = performance.now();
@@ -8242,13 +8242,13 @@ function handleHealthCheck() {
8242
8242
  }
8243
8243
  async function handleListPresets(policiesDir) {
8244
8244
  const { readdir, readFile: readFile4 } = await import("fs/promises");
8245
- const { join: join19 } = await import("path");
8246
- const dir = policiesDir ?? join19(process.cwd(), "policies");
8245
+ const { join: join21 } = await import("path");
8246
+ const dir = policiesDir ?? join21(process.cwd(), "policies");
8247
8247
  const presets = [];
8248
8248
  try {
8249
8249
  const files = await readdir(dir);
8250
8250
  for (const file of files.filter((f) => f.endsWith(".txt")).sort()) {
8251
- const content = await readFile4(join19(dir, file), "utf-8");
8251
+ const content = await readFile4(join21(dir, file), "utf-8");
8252
8252
  const id = file.replace(".txt", "");
8253
8253
  const name = id.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
8254
8254
  const firstLine = content.split("\n").find((l) => l.trim().length > 0) ?? "";
@@ -8320,7 +8320,7 @@ function govern(action, world, options) {
8320
8320
  }
8321
8321
  async function writeTempWorld(dir, policyLines) {
8322
8322
  const { writeFile: writeFile6, mkdir: mkdir3 } = await import("fs/promises");
8323
- const { join: join19 } = await import("path");
8323
+ const { join: join21 } = await import("path");
8324
8324
  await mkdir3(dir, { recursive: true });
8325
8325
  const worldJson = {
8326
8326
  world_id: "demo-live",
@@ -8362,9 +8362,9 @@ async function writeTempWorld(dir, policyLines) {
8362
8362
  authoring_method: "manual-authoring"
8363
8363
  };
8364
8364
  await Promise.all([
8365
- writeFile6(join19(dir, "world.json"), JSON.stringify(worldJson, null, 2)),
8366
- writeFile6(join19(dir, "kernel.json"), JSON.stringify(kernelJson, null, 2)),
8367
- writeFile6(join19(dir, "metadata.json"), JSON.stringify(metadataJson, null, 2))
8365
+ writeFile6(join21(dir, "world.json"), JSON.stringify(worldJson, null, 2)),
8366
+ writeFile6(join21(dir, "kernel.json"), JSON.stringify(kernelJson, null, 2)),
8367
+ writeFile6(join21(dir, "metadata.json"), JSON.stringify(metadataJson, null, 2))
8368
8368
  ]);
8369
8369
  }
8370
8370
  var init_govern = __esm({
@@ -8708,10 +8708,10 @@ data: ${data}
8708
8708
  res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
8709
8709
  }
8710
8710
  function readBody(req) {
8711
- return new Promise((resolve12, reject) => {
8711
+ return new Promise((resolve14, reject) => {
8712
8712
  const chunks = [];
8713
8713
  req.on("data", (chunk) => chunks.push(chunk));
8714
- req.on("end", () => resolve12(Buffer.concat(chunks).toString("utf-8")));
8714
+ req.on("end", () => resolve14(Buffer.concat(chunks).toString("utf-8")));
8715
8715
  req.on("error", reject);
8716
8716
  });
8717
8717
  }
@@ -11475,9 +11475,9 @@ async function main15(argv) {
11475
11475
  }
11476
11476
  if (worldPath) {
11477
11477
  try {
11478
- const { existsSync: existsSync15 } = await import("fs");
11479
- const { join: join19 } = await import("path");
11480
- const hasWorld = existsSync15(join19(worldPath, "world.json"));
11478
+ const { existsSync: existsSync17 } = await import("fs");
11479
+ const { join: join21 } = await import("path");
11480
+ const hasWorld = existsSync17(join21(worldPath, "world.json"));
11481
11481
  checks.push({
11482
11482
  label: "World file detected",
11483
11483
  status: hasWorld ? "pass" : "fail",
@@ -11492,12 +11492,12 @@ async function main15(argv) {
11492
11492
  });
11493
11493
  }
11494
11494
  } else {
11495
- const { existsSync: existsSync15 } = await import("fs");
11496
- const { join: join19 } = await import("path");
11495
+ const { existsSync: existsSync17 } = await import("fs");
11496
+ const { join: join21 } = await import("path");
11497
11497
  const candidates = ["./world", "./.neuroverse", "./worlds"];
11498
11498
  let found;
11499
11499
  for (const dir of candidates) {
11500
- if (existsSync15(join19(dir, "world.json"))) {
11500
+ if (existsSync17(join21(dir, "world.json"))) {
11501
11501
  found = dir;
11502
11502
  break;
11503
11503
  }
@@ -12549,8 +12549,8 @@ async function deriveCommand(args) {
12549
12549
  return;
12550
12550
  }
12551
12551
  const plan = result.plan;
12552
- const { mkdirSync: mkdirSync6 } = await import("fs");
12553
- mkdirSync6(outputDir, { recursive: true });
12552
+ const { mkdirSync: mkdirSync7 } = await import("fs");
12553
+ mkdirSync7(outputDir, { recursive: true });
12554
12554
  const worldJson = {
12555
12555
  world_id: `plan_${plan.plan_id}`,
12556
12556
  name: `Derived: ${plan.objective}`,
@@ -13148,7 +13148,7 @@ async function runPipeMode(config) {
13148
13148
  `);
13149
13149
  }
13150
13150
  const MAX_BUFFER_SIZE = 1e6;
13151
- return new Promise((resolve12, reject) => {
13151
+ return new Promise((resolve14, reject) => {
13152
13152
  let buffer = "";
13153
13153
  process.stdin.setEncoding("utf-8");
13154
13154
  process.stdin.on("data", (chunk) => {
@@ -13194,7 +13194,7 @@ async function runPipeMode(config) {
13194
13194
  `[neuroverse] Session complete: ${finalState.actionsEvaluated} evaluated, ${finalState.actionsAllowed} allowed, ${finalState.actionsBlocked} blocked, ${finalState.actionsPaused} paused
13195
13195
  `
13196
13196
  );
13197
- resolve12();
13197
+ resolve14();
13198
13198
  });
13199
13199
  process.stdin.on("error", reject);
13200
13200
  });
@@ -13310,8 +13310,8 @@ ${response.content}
13310
13310
  rl2.on("close", () => {
13311
13311
  session.stop();
13312
13312
  });
13313
- return new Promise((resolve12) => {
13314
- rl2.on("close", resolve12);
13313
+ return new Promise((resolve14) => {
13314
+ rl2.on("close", resolve14);
13315
13315
  });
13316
13316
  }
13317
13317
  var SessionManager;
@@ -14422,27 +14422,27 @@ function computeWorldDiff(a, b) {
14422
14422
  }
14423
14423
  async function worldSnapshot(worldPath) {
14424
14424
  const { readdir, readFile: readFile4, mkdir: mkdir3, writeFile: writeFile6 } = await import("fs/promises");
14425
- const { join: join19 } = await import("path");
14425
+ const { join: join21 } = await import("path");
14426
14426
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
14427
- const snapshotDir = join19(worldPath, ".snapshots", timestamp);
14427
+ const snapshotDir = join21(worldPath, ".snapshots", timestamp);
14428
14428
  await mkdir3(snapshotDir, { recursive: true });
14429
14429
  const files = await readdir(worldPath);
14430
14430
  let copied = 0;
14431
14431
  for (const file of files) {
14432
14432
  if (file.endsWith(".json")) {
14433
- const content = await readFile4(join19(worldPath, file), "utf-8");
14434
- await writeFile6(join19(snapshotDir, file), content, "utf-8");
14433
+ const content = await readFile4(join21(worldPath, file), "utf-8");
14434
+ await writeFile6(join21(snapshotDir, file), content, "utf-8");
14435
14435
  copied++;
14436
14436
  }
14437
14437
  }
14438
14438
  try {
14439
- const rulesDir = join19(worldPath, "rules");
14439
+ const rulesDir = join21(worldPath, "rules");
14440
14440
  const ruleFiles = await readdir(rulesDir);
14441
- await mkdir3(join19(snapshotDir, "rules"), { recursive: true });
14441
+ await mkdir3(join21(snapshotDir, "rules"), { recursive: true });
14442
14442
  for (const file of ruleFiles) {
14443
14443
  if (file.endsWith(".json")) {
14444
- const content = await readFile4(join19(rulesDir, file), "utf-8");
14445
- await writeFile6(join19(snapshotDir, "rules", file), content, "utf-8");
14444
+ const content = await readFile4(join21(rulesDir, file), "utf-8");
14445
+ await writeFile6(join21(snapshotDir, "rules", file), content, "utf-8");
14446
14446
  copied++;
14447
14447
  }
14448
14448
  }
@@ -14455,8 +14455,8 @@ async function worldSnapshot(worldPath) {
14455
14455
  }
14456
14456
  async function worldRollback(worldPath) {
14457
14457
  const { readdir, readFile: readFile4, writeFile: writeFile6, mkdir: mkdir3 } = await import("fs/promises");
14458
- const { join: join19 } = await import("path");
14459
- const snapshotsDir = join19(worldPath, ".snapshots");
14458
+ const { join: join21 } = await import("path");
14459
+ const snapshotsDir = join21(worldPath, ".snapshots");
14460
14460
  let snapshots;
14461
14461
  try {
14462
14462
  snapshots = (await readdir(snapshotsDir)).sort();
@@ -14471,34 +14471,34 @@ async function worldRollback(worldPath) {
14471
14471
  return;
14472
14472
  }
14473
14473
  const latest = snapshots[snapshots.length - 1];
14474
- const snapshotDir = join19(snapshotsDir, latest);
14474
+ const snapshotDir = join21(snapshotsDir, latest);
14475
14475
  const backupTimestamp = "pre-rollback-" + (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
14476
- const backupDir = join19(snapshotsDir, backupTimestamp);
14476
+ const backupDir = join21(snapshotsDir, backupTimestamp);
14477
14477
  await mkdir3(backupDir, { recursive: true });
14478
14478
  const currentFiles = await readdir(worldPath);
14479
14479
  for (const file of currentFiles) {
14480
14480
  if (file.endsWith(".json")) {
14481
- const content = await readFile4(join19(worldPath, file), "utf-8");
14482
- await writeFile6(join19(backupDir, file), content, "utf-8");
14481
+ const content = await readFile4(join21(worldPath, file), "utf-8");
14482
+ await writeFile6(join21(backupDir, file), content, "utf-8");
14483
14483
  }
14484
14484
  }
14485
14485
  const snapshotFiles = await readdir(snapshotDir);
14486
14486
  let restored = 0;
14487
14487
  for (const file of snapshotFiles) {
14488
14488
  if (file.endsWith(".json")) {
14489
- const content = await readFile4(join19(snapshotDir, file), "utf-8");
14490
- await writeFile6(join19(worldPath, file), content, "utf-8");
14489
+ const content = await readFile4(join21(snapshotDir, file), "utf-8");
14490
+ await writeFile6(join21(worldPath, file), content, "utf-8");
14491
14491
  restored++;
14492
14492
  }
14493
14493
  }
14494
14494
  try {
14495
- const rulesDir = join19(snapshotDir, "rules");
14495
+ const rulesDir = join21(snapshotDir, "rules");
14496
14496
  const ruleFiles = await readdir(rulesDir);
14497
- await mkdir3(join19(worldPath, "rules"), { recursive: true });
14497
+ await mkdir3(join21(worldPath, "rules"), { recursive: true });
14498
14498
  for (const file of ruleFiles) {
14499
14499
  if (file.endsWith(".json")) {
14500
- const content = await readFile4(join19(rulesDir, file), "utf-8");
14501
- await writeFile6(join19(worldPath, "rules", file), content, "utf-8");
14500
+ const content = await readFile4(join21(rulesDir, file), "utf-8");
14501
+ await writeFile6(join21(worldPath, "rules", file), content, "utf-8");
14502
14502
  restored++;
14503
14503
  }
14504
14504
  }
@@ -16400,27 +16400,27 @@ function closePrompts() {
16400
16400
  }
16401
16401
  function ask(question, defaultValue) {
16402
16402
  const suffix = defaultValue ? ` [${defaultValue}]` : "";
16403
- return new Promise((resolve12) => {
16403
+ return new Promise((resolve14) => {
16404
16404
  getRL().question(`
16405
16405
  ${question}${suffix}: `, (answer) => {
16406
16406
  const val = answer.trim();
16407
- resolve12(val || defaultValue || "");
16407
+ resolve14(val || defaultValue || "");
16408
16408
  });
16409
16409
  });
16410
16410
  }
16411
16411
  function confirm(question, defaultYes = true) {
16412
16412
  const hint = defaultYes ? "[Y/n]" : "[y/N]";
16413
- return new Promise((resolve12) => {
16413
+ return new Promise((resolve14) => {
16414
16414
  getRL().question(`
16415
16415
  ${question} ${hint}: `, (answer) => {
16416
16416
  const val = answer.trim().toLowerCase();
16417
- if (val === "") resolve12(defaultYes);
16418
- else resolve12(val === "y" || val === "yes");
16417
+ if (val === "") resolve14(defaultYes);
16418
+ else resolve14(val === "y" || val === "yes");
16419
16419
  });
16420
16420
  });
16421
16421
  }
16422
16422
  function choose(question, options) {
16423
- return new Promise((resolve12) => {
16423
+ return new Promise((resolve14) => {
16424
16424
  const r = getRL();
16425
16425
  r.write(`
16426
16426
  ${question}
@@ -16430,9 +16430,9 @@ function choose(question, options) {
16430
16430
  r.question(` Choice [1-${options.length}]: `, (answer) => {
16431
16431
  const idx = parseInt(answer.trim(), 10) - 1;
16432
16432
  if (idx >= 0 && idx < options.length) {
16433
- resolve12(options[idx]);
16433
+ resolve14(options[idx]);
16434
16434
  } else {
16435
- resolve12(options[0]);
16435
+ resolve14(options[0]);
16436
16436
  }
16437
16437
  });
16438
16438
  });
@@ -16901,15 +16901,15 @@ function generateWorld(state) {
16901
16901
  return { worldJson, stateSchema, guardsJson, rules, gatesJson, invariants, outcomes, metadata };
16902
16902
  }
16903
16903
  async function writeWorld(outputDir, world) {
16904
- const { mkdirSync: mkdirSync6, existsSync: existsSync15 } = await import("fs");
16904
+ const { mkdirSync: mkdirSync7, existsSync: existsSync17 } = await import("fs");
16905
16905
  const { writeFile: writeFile6 } = await import("fs/promises");
16906
- const { join: join19 } = await import("path");
16906
+ const { join: join21 } = await import("path");
16907
16907
  const files = [];
16908
- if (!existsSync15(outputDir)) mkdirSync6(outputDir, { recursive: true });
16909
- const rulesDir = join19(outputDir, "rules");
16910
- if (!existsSync15(rulesDir)) mkdirSync6(rulesDir, { recursive: true });
16908
+ if (!existsSync17(outputDir)) mkdirSync7(outputDir, { recursive: true });
16909
+ const rulesDir = join21(outputDir, "rules");
16910
+ if (!existsSync17(rulesDir)) mkdirSync7(rulesDir, { recursive: true });
16911
16911
  const writeJson = async (name, data) => {
16912
- const path = join19(outputDir, name);
16912
+ const path = join21(outputDir, name);
16913
16913
  await writeFile6(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
16914
16914
  files.push(path);
16915
16915
  };
@@ -16921,7 +16921,7 @@ async function writeWorld(outputDir, world) {
16921
16921
  await writeJson("outcomes.json", world.outcomes);
16922
16922
  await writeJson("metadata.json", world.metadata);
16923
16923
  for (const rule of world.rules) {
16924
- const rulePath = join19(rulesDir, `${rule.id}.json`);
16924
+ const rulePath = join21(rulesDir, `${rule.id}.json`);
16925
16925
  await writeFile6(rulePath, JSON.stringify(rule, null, 2) + "\n", "utf-8");
16926
16926
  files.push(rulePath);
16927
16927
  }
@@ -17008,7 +17008,7 @@ async function main31(argv = process.argv.slice(2)) {
17008
17008
  }
17009
17009
  async function phaseRefine(outputDir, world) {
17010
17010
  const { writeFile: writeFile6 } = await import("fs/promises");
17011
- const { join: join19 } = await import("path");
17011
+ const { join: join21 } = await import("path");
17012
17012
  heading("Refinement: Thresholds & Collapse");
17013
17013
  const primaryMetric = world.gatesJson.viability_classification[0]?.field || "system_health";
17014
17014
  info(`
@@ -17025,7 +17025,7 @@ async function phaseRefine(outputDir, world) {
17025
17025
  if (!isNaN(parsed)) gate.value = parsed;
17026
17026
  }
17027
17027
  await writeFile6(
17028
- join19(outputDir, "gates.json"),
17028
+ join21(outputDir, "gates.json"),
17029
17029
  JSON.stringify(world.gatesJson, null, 2) + "\n",
17030
17030
  "utf-8"
17031
17031
  );
@@ -17047,7 +17047,7 @@ async function phaseRefine(outputDir, world) {
17047
17047
  result: "MODEL_COLLAPSES"
17048
17048
  };
17049
17049
  await writeFile6(
17050
- join19(outputDir, "rules", `${rule.id}.json`),
17050
+ join21(outputDir, "rules", `${rule.id}.json`),
17051
17051
  JSON.stringify(rule, null, 2) + "\n",
17052
17052
  "utf-8"
17053
17053
  );
@@ -18100,9 +18100,9 @@ async function cmdAdd(argv) {
18100
18100
  id = name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
18101
18101
  }
18102
18102
  const { readFile: readFile4, writeFile: writeFile6 } = await import("fs/promises");
18103
- const { join: join19 } = await import("path");
18103
+ const { join: join21 } = await import("path");
18104
18104
  const possiblePaths = [
18105
- join19(worldPath, "world.nv-world.md"),
18105
+ join21(worldPath, "world.nv-world.md"),
18106
18106
  worldPath
18107
18107
  ];
18108
18108
  let mdPath = "";
@@ -18123,7 +18123,7 @@ async function cmdAdd(argv) {
18123
18123
  const files = await readdir(worldPath);
18124
18124
  const mdFile = files.find((f) => f.endsWith(".nv-world.md"));
18125
18125
  if (mdFile) {
18126
- mdPath = join19(worldPath, mdFile);
18126
+ mdPath = join21(worldPath, mdFile);
18127
18127
  mdContent = await readFile4(mdPath, "utf-8");
18128
18128
  }
18129
18129
  } catch {
@@ -18795,6 +18795,15 @@ var init_worldmodel_parser = __esm({
18795
18795
  });
18796
18796
 
18797
18797
  // src/engine/worldmodel-compiler.ts
18798
+ var worldmodel_compiler_exports = {};
18799
+ __export(worldmodel_compiler_exports, {
18800
+ compileWorldModel: () => compileWorldModel,
18801
+ emitContextsConfig: () => emitContextsConfig,
18802
+ emitLensSuggestions: () => emitLensSuggestions,
18803
+ emitOverlapMap: () => emitOverlapMap,
18804
+ emitSignalSchema: () => emitSignalSchema,
18805
+ emitWorldMarkdown: () => emitWorldMarkdown
18806
+ });
18798
18807
  function toSnakeCase(text) {
18799
18808
  return text.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
18800
18809
  }
@@ -19151,14 +19160,14 @@ async function askQuestions() {
19151
19160
  process.stderr.write(" There are no wrong answers \u2014 just say what you mean.\n");
19152
19161
  process.stderr.write(" The AI will structure your answers into a worldmodel.\n\n");
19153
19162
  for (const q of QUESTIONS) {
19154
- const answer = await new Promise((resolve12) => {
19163
+ const answer = await new Promise((resolve14) => {
19155
19164
  process.stderr.write(` \x1B[1m${q.question}\x1B[0m
19156
19165
  `);
19157
19166
  process.stderr.write(` \x1B[2m${q.placeholder}\x1B[0m
19158
19167
  `);
19159
19168
  rl2.question(" > ", (ans) => {
19160
19169
  process.stderr.write("\n");
19161
- resolve12(ans.trim());
19170
+ resolve14(ans.trim());
19162
19171
  });
19163
19172
  });
19164
19173
  answers[q.id] = answer;
@@ -19450,6 +19459,46 @@ ${YELLOW2}Validation found ${errors.length} issue${errors.length > 1 ? "s" : ""}
19450
19459
  } else {
19451
19460
  process.stderr.write(`${GREEN2}Validates cleanly!${RESET2}
19452
19461
  `);
19462
+ try {
19463
+ if (!validateResult.model) throw new Error("no model");
19464
+ const { compileWorldModel: compileWorldModel2 } = await Promise.resolve().then(() => (init_worldmodel_compiler(), worldmodel_compiler_exports));
19465
+ const compiled = compileWorldModel2(validateResult.model);
19466
+ const outDir = (0, import_path13.dirname)(outputPath);
19467
+ const baseName = (0, import_path13.basename)(outputPath).replace(/\.worldmodel\.md$/, "");
19468
+ const worldPath = (0, import_path13.join)(outDir, `${baseName}.nv-world.md`);
19469
+ await (0, import_promises6.writeFile)(worldPath, compiled.worldMarkdown, "utf-8");
19470
+ const signalsPath = (0, import_path13.join)(outDir, "signals.json");
19471
+ await (0, import_promises6.writeFile)(signalsPath, JSON.stringify(compiled.signalSchema, null, 2), "utf-8");
19472
+ const overlapsPath = (0, import_path13.join)(outDir, "overlaps.json");
19473
+ await (0, import_promises6.writeFile)(overlapsPath, JSON.stringify(compiled.overlapMap, null, 2), "utf-8");
19474
+ const contextsPath = (0, import_path13.join)(outDir, "contexts.json");
19475
+ await (0, import_promises6.writeFile)(contextsPath, JSON.stringify(compiled.contextsConfig, null, 2), "utf-8");
19476
+ const lensesPath = (0, import_path13.join)(outDir, "lenses.json");
19477
+ await (0, import_promises6.writeFile)(lensesPath, JSON.stringify(compiled.lensSuggestions, null, 2), "utf-8");
19478
+ process.stderr.write(`
19479
+ ${GREEN2}Compiled!${RESET2} Token-optimized artifacts:
19480
+ `);
19481
+ process.stderr.write(`${DIM2} ${worldPath}${RESET2}
19482
+ `);
19483
+ process.stderr.write(`${DIM2} ${signalsPath}${RESET2}
19484
+ `);
19485
+ process.stderr.write(`${DIM2} ${overlapsPath}${RESET2}
19486
+ `);
19487
+ process.stderr.write(`${DIM2} ${contextsPath}${RESET2}
19488
+ `);
19489
+ process.stderr.write(`${DIM2} ${lensesPath}${RESET2}
19490
+ `);
19491
+ process.stderr.write(`
19492
+ ${DIM2}Source: ${outputPath} (readable, editable)${RESET2}
19493
+ `);
19494
+ process.stderr.write(`${DIM2}Compiled: ready for Radiant \u2014 token-optimized, no prose overhead.${RESET2}
19495
+ `);
19496
+ } catch {
19497
+ process.stderr.write(
19498
+ `${DIM2}Auto-compile skipped \u2014 run 'neuroverse worldmodel build ${(0, import_path13.basename)(outputPath)}' manually.${RESET2}
19499
+ `
19500
+ );
19501
+ }
19453
19502
  }
19454
19503
  } catch {
19455
19504
  }
@@ -20590,7 +20639,7 @@ function sovereignConduitRewrite(pattern) {
20590
20639
  return {
20591
20640
  ...pattern,
20592
20641
  framing: "what this means for the people in the system",
20593
- emphasis: "humanity + sovereignty + learning",
20642
+ emphasis: "humanity + agency + learning",
20594
20643
  compress: false
20595
20644
  };
20596
20645
  }
@@ -20601,17 +20650,17 @@ var init_sovereign_conduit = __esm({
20601
20650
  SOVEREIGN_CONDUIT_FRAME = {
20602
20651
  domains: [
20603
20652
  "stewardship",
20604
- "sovereignty",
20653
+ "agency",
20605
20654
  "integration"
20606
20655
  ],
20607
20656
  overlaps: [
20608
20657
  {
20609
- domains: ["stewardship", "sovereignty"],
20658
+ domains: ["stewardship", "agency"],
20610
20659
  emergent_state: "Trust",
20611
20660
  description: "I am safe to be myself. When the system protects AND preserves individual authority, trust emerges \u2014 the feeling that you can think freely because someone is watching the boundaries."
20612
20661
  },
20613
20662
  {
20614
- domains: ["sovereignty", "integration"],
20663
+ domains: ["agency", "integration"],
20615
20664
  emergent_state: "Possibility",
20616
20665
  description: "My thinking can expand. When individual authority is preserved AND AI extends cognitive capability, possibility opens \u2014 the feeling that you can reach further without losing yourself."
20617
20666
  },
@@ -20642,7 +20691,7 @@ var init_sovereign_conduit = __esm({
20642
20691
  "harm detection",
20643
20692
  "constraint design"
20644
20693
  ],
20645
- "sovereignty": [
20694
+ "agency": [
20646
20695
  "independent thinking",
20647
20696
  "decision ownership",
20648
20697
  "self-trust",
@@ -20666,7 +20715,7 @@ var init_sovereign_conduit = __esm({
20666
20715
  output_translation: {
20667
20716
  never_surface_in_output: [
20668
20717
  "Stewardship",
20669
- "Sovereignty",
20718
+ "Agency",
20670
20719
  "Integration"
20671
20720
  ],
20672
20721
  surface_freely: [
@@ -20681,7 +20730,7 @@ var init_sovereign_conduit = __esm({
20681
20730
  external_expression: "the boundaries are clear and the system feels safe to operate inside"
20682
20731
  },
20683
20732
  {
20684
- internal_reasoning: "Sovereignty is weakening",
20733
+ internal_reasoning: "Agency is weakening",
20685
20734
  external_expression: "decision ownership is quietly shifting \u2014 the human is accepting AI output without engaging with it"
20686
20735
  },
20687
20736
  {
@@ -20764,12 +20813,12 @@ var init_sovereign_conduit = __esm({
20764
20813
  close_with_strategic_frame: "preferred",
20765
20814
  punchline_move: "sparing",
20766
20815
  honesty_about_failure: "required",
20767
- output_translation: `Reason internally through the three-domain frame (Stewardship, Sovereignty, Integration). Express externally through the skills inside each domain and the overlap feelings (Trust, Possibility, Responsibility). Do NOT surface the bucket names as labels. Readers understand "the boundaries feel safe" not "Stewardship is strong." Use everyday analogies \u2014 mom rules, friend's house rules, idea calculator. Name the emotion before the mechanism.`
20816
+ output_translation: `Reason internally through the three-domain frame (Stewardship, Agency, Integration). Express externally through the skills inside each domain and the overlap feelings (Trust, Possibility, Responsibility). Do NOT surface the bucket names as labels. Readers understand "the boundaries feel safe" not "Stewardship is strong." Use everyday analogies \u2014 mom rules, friend's house rules, idea calculator. Name the emotion before the mechanism.`
20768
20817
  };
20769
20818
  SOVEREIGN_CONDUIT_FORBIDDEN = Object.freeze([
20770
20819
  // Bucket names as labels
20771
20820
  "stewardship is",
20772
- "sovereignty is",
20821
+ "agency is",
20773
20822
  "integration is",
20774
20823
  // AI-assistant hedging
20775
20824
  "it may be beneficial to consider",
@@ -20805,7 +20854,7 @@ var init_sovereign_conduit = __esm({
20805
20854
  "Here's what's actually happening: [plain explanation].",
20806
20855
  "The question to ask yourself: [question].",
20807
20856
  "The difference between [A] and [B] matters here: [why].",
20808
- // Sovereignty checks
20857
+ // Agency checks
20809
20858
  "Are you still the author of this decision, or did the AI make it for you?",
20810
20859
  "The AI extended your thinking here. That's working.",
20811
20860
  "The AI replaced your thinking here. That's the drift to watch.",
@@ -20816,7 +20865,7 @@ var init_sovereign_conduit = __esm({
20816
20865
  ]);
20817
20866
  SOVEREIGN_CONDUIT_STRATEGIC = Object.freeze([
20818
20867
  "Safety before expansion \u2014 always. No exception.",
20819
- "Sovereignty before convenience \u2014 the right to think for yourself is not a feature to optimize away.",
20868
+ "Agency before convenience \u2014 the right to think for yourself is not a feature to optimize away.",
20820
20869
  "Extension, not replacement \u2014 AI should make your thinking bigger, not do your thinking for you.",
20821
20870
  "Diversity over uniformity \u2014 different thinkers produce different ideas, and that's the engine of progress.",
20822
20871
  "The rules should be visible \u2014 like a good house, you know the rules before you walk in.",
@@ -20826,16 +20875,16 @@ var init_sovereign_conduit = __esm({
20826
20875
  ]);
20827
20876
  SOVEREIGN_CONDUIT_EXEMPLARS = Object.freeze([
20828
20877
  {
20829
- path: "neuroverseos-sovereign-conduit.worldmodel.md",
20878
+ path: "src/radiant/examples/neuroverse-base/neuroverseos-sovereign-conduit.worldmodel.md",
20830
20879
  title: "The Sovereign Conduit Worldmodel",
20831
- exhibits: ["stewardship", "sovereignty", "integration"],
20880
+ exhibits: ["stewardship", "agency", "integration"],
20832
20881
  integration_quality: "full \u2014 all three domains defined, overlaps named, center identity declared",
20833
20882
  notes: 'The source worldmodel. The tagline "Humanity first. In constant learning. In shared teaching." is the voice compressed to its essence. Use this as the north star for tone calibration.'
20834
20883
  }
20835
20884
  ]);
20836
20885
  sovereignConduitLens = {
20837
20886
  name: "sovereign-conduit",
20838
- description: "The NeuroVerseOS base lens. Warm, accessible, teaching. Evaluates activity through Stewardship (safety), Sovereignty (authority over thinking), and Integration (AI as cognitive extension). Uses everyday analogies \u2014 mom rules, friend's house, idea calculator. Names emotions before mechanisms. If a non-technical person can't understand the output, the voice is wrong. Humanity first. In constant learning. In shared teaching.",
20887
+ description: "The NeuroVerseOS base lens. Warm, accessible, teaching. Evaluates activity through Stewardship (safety), Agency (authority over thinking), and Integration (AI as cognitive extension). Uses everyday analogies \u2014 mom rules, friend's house, idea calculator. Names emotions before mechanisms. If a non-technical person can't understand the output, the voice is wrong. Humanity first. In constant learning. In shared teaching.",
20839
20888
  primary_frame: {
20840
20889
  domains: SOVEREIGN_CONDUIT_FRAME.domains,
20841
20890
  overlaps: SOVEREIGN_CONDUIT_FRAME.overlaps,
@@ -21783,82 +21832,382 @@ var init_notion = __esm({
21783
21832
  }
21784
21833
  });
21785
21834
 
21835
+ // src/radiant/core/git-remote.ts
21836
+ function resolveGitConfigPath(repoDir) {
21837
+ const dotGit = (0, import_path14.join)(repoDir, ".git");
21838
+ if (!(0, import_fs13.existsSync)(dotGit)) return null;
21839
+ try {
21840
+ const stat = (0, import_fs13.statSync)(dotGit);
21841
+ if (stat.isDirectory()) {
21842
+ return (0, import_path14.join)(dotGit, "config");
21843
+ }
21844
+ if (stat.isFile()) {
21845
+ const content = (0, import_fs13.readFileSync)(dotGit, "utf-8");
21846
+ const match = /^gitdir:\s*(.+)$/m.exec(content);
21847
+ if (!match) return null;
21848
+ const gitDir = (0, import_path14.resolve)(repoDir, match[1].trim());
21849
+ const configPath = (0, import_path14.join)(gitDir, "config");
21850
+ return (0, import_fs13.existsSync)(configPath) ? configPath : null;
21851
+ }
21852
+ } catch {
21853
+ return null;
21854
+ }
21855
+ return null;
21856
+ }
21857
+ function readOriginRemote(repoDir) {
21858
+ const configPath = resolveGitConfigPath(repoDir);
21859
+ if (!configPath) return null;
21860
+ try {
21861
+ const raw = (0, import_fs13.readFileSync)(configPath, "utf-8");
21862
+ const sectionRe = /\[remote "origin"\]\s*\n((?:(?!\[)[^\n]*\n?)*)/;
21863
+ const section = sectionRe.exec(raw);
21864
+ if (!section) return null;
21865
+ const urlRe = /^\s*url\s*=\s*(.+?)\s*$/m;
21866
+ const url = urlRe.exec(section[1]);
21867
+ return url ? url[1] : null;
21868
+ } catch {
21869
+ return null;
21870
+ }
21871
+ }
21872
+ function parseRemoteUrl(url) {
21873
+ const trimmed = url.trim();
21874
+ if (!trimmed) return null;
21875
+ const ssh = /^git@([^:]+):([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(trimmed);
21876
+ if (ssh) return { host: ssh[1], owner: ssh[2], repo: ssh[3] };
21877
+ const sshProto = /^ssh:\/\/git@([^/]+)\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(trimmed);
21878
+ if (sshProto) return { host: sshProto[1], owner: sshProto[2], repo: sshProto[3] };
21879
+ const https = /^https?:\/\/(?:[^@/]+@)?([^/]+)\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(trimmed);
21880
+ if (https) return { host: https[1], owner: https[2], repo: https[3] };
21881
+ return null;
21882
+ }
21883
+ function getRepoOrigin(repoDir) {
21884
+ const url = readOriginRemote(repoDir);
21885
+ if (!url) return null;
21886
+ return parseRemoteUrl(url);
21887
+ }
21888
+ var import_fs13, import_path14;
21889
+ var init_git_remote = __esm({
21890
+ "src/radiant/core/git-remote.ts"() {
21891
+ "use strict";
21892
+ import_fs13 = require("fs");
21893
+ import_path14 = require("path");
21894
+ }
21895
+ });
21896
+
21897
+ // src/radiant/core/extends.ts
21898
+ function loadExtendsConfig(repoDir) {
21899
+ const configPath = (0, import_path15.join)(repoDir, ".neuroverse", "config.json");
21900
+ if (!(0, import_fs14.existsSync)(configPath)) return null;
21901
+ try {
21902
+ const raw = (0, import_fs14.readFileSync)(configPath, "utf-8");
21903
+ const parsed = JSON.parse(raw);
21904
+ return parsed;
21905
+ } catch {
21906
+ return null;
21907
+ }
21908
+ }
21909
+ function parseExtendsSpec(raw) {
21910
+ const trimmed = raw.trim();
21911
+ if (!trimmed) return null;
21912
+ if (trimmed.startsWith("github:")) {
21913
+ const rest = trimmed.slice("github:".length);
21914
+ const match = /^([^/]+)\/([^@:]+)(?:@([^:]+))?(?::(.+))?$/.exec(rest);
21915
+ if (!match) return null;
21916
+ return {
21917
+ raw: trimmed,
21918
+ kind: "github",
21919
+ owner: match[1],
21920
+ repo: match[2],
21921
+ ref: match[3] ?? "HEAD",
21922
+ subpath: match[4] ?? ""
21923
+ };
21924
+ }
21925
+ if (trimmed.startsWith("./") || trimmed.startsWith("../") || (0, import_path15.isAbsolute)(trimmed)) {
21926
+ return { raw: trimmed, kind: "local", path: trimmed };
21927
+ }
21928
+ return null;
21929
+ }
21930
+ function getCacheDir(spec, baseCacheDir) {
21931
+ const root = baseCacheDir ?? (0, import_path15.join)((0, import_os5.homedir)(), ".neuroverse", "cache", "extends");
21932
+ const key = (0, import_crypto4.createHash)("sha256").update(spec.raw).digest("hex").slice(0, 16);
21933
+ return (0, import_path15.join)(root, key);
21934
+ }
21935
+ function isCacheFresh(cacheDir, ttlMs) {
21936
+ const stampPath = (0, import_path15.join)(cacheDir, ".neuroverse-fetched");
21937
+ if (!(0, import_fs14.existsSync)(stampPath)) return false;
21938
+ try {
21939
+ const stamp = (0, import_fs14.statSync)(stampPath);
21940
+ return Date.now() - stamp.mtimeMs < ttlMs;
21941
+ } catch {
21942
+ return false;
21943
+ }
21944
+ }
21945
+ function markCacheFresh(cacheDir) {
21946
+ const stampPath = (0, import_path15.join)(cacheDir, ".neuroverse-fetched");
21947
+ try {
21948
+ (0, import_fs14.mkdirSync)(cacheDir, { recursive: true });
21949
+ (0, import_fs14.writeFileSync)(stampPath, (/* @__PURE__ */ new Date()).toISOString());
21950
+ } catch {
21951
+ }
21952
+ }
21953
+ function resolveExtendsSpec(spec, repoDir, options) {
21954
+ if (spec.kind === "local") {
21955
+ const full = (0, import_path15.isAbsolute)(spec.path) ? spec.path : (0, import_path15.resolve)(repoDir, spec.path);
21956
+ if (!(0, import_fs14.existsSync)(full)) {
21957
+ return { spec, dir: null, warning: `local extends path not found: ${full}` };
21958
+ }
21959
+ return { spec, dir: full };
21960
+ }
21961
+ const cacheRoot = options?.cacheDir;
21962
+ const ttl = options?.ttlMs ?? DEFAULT_TTL_MS;
21963
+ const cacheDir = getCacheDir(spec, cacheRoot);
21964
+ const fresh = isCacheFresh(cacheDir, ttl);
21965
+ const needsFetch = options?.forceRefresh || !fresh || !(0, import_fs14.existsSync)(cacheDir);
21966
+ if (needsFetch && options?.noFetch) {
21967
+ if ((0, import_fs14.existsSync)(cacheDir) && (0, import_fs14.existsSync)((0, import_path15.join)(cacheDir, ".neuroverse-fetched"))) {
21968
+ return resolveSubpath(spec, cacheDir);
21969
+ }
21970
+ return options?.silentOnMissing ? { spec, dir: null } : { spec, dir: null, warning: `NEUROVERSE_NO_FETCH set and no cache for ${spec.raw}` };
21971
+ }
21972
+ if (needsFetch) {
21973
+ const fetcher = options?.fetcher ?? defaultGitFetcher;
21974
+ try {
21975
+ fetcher(spec, cacheDir);
21976
+ markCacheFresh(cacheDir);
21977
+ } catch (err) {
21978
+ if ((0, import_fs14.existsSync)(cacheDir) && (0, import_fs14.existsSync)((0, import_path15.join)(cacheDir, ".neuroverse-fetched"))) {
21979
+ const result = resolveSubpath(spec, cacheDir);
21980
+ return options?.silentOnMissing ? result : { ...result, warning: `fetch failed for ${spec.raw}, using stale cache: ${err.message}` };
21981
+ }
21982
+ return options?.silentOnMissing ? { spec, dir: null } : { spec, dir: null, warning: `fetch failed for ${spec.raw}: ${err.message}` };
21983
+ }
21984
+ }
21985
+ return resolveSubpath(spec, cacheDir);
21986
+ }
21987
+ function resolveSubpath(spec, cacheDir) {
21988
+ const target = spec.subpath ? (0, import_path15.join)(cacheDir, spec.subpath) : cacheDir;
21989
+ if (!(0, import_fs14.existsSync)(target)) {
21990
+ return { spec, dir: null, warning: `subpath not found in ${spec.raw}: ${spec.subpath}` };
21991
+ }
21992
+ if (!spec.subpath) {
21993
+ const candidates = [
21994
+ (0, import_path15.join)(target, "worlds"),
21995
+ (0, import_path15.join)(target, ".neuroverse", "worlds")
21996
+ ];
21997
+ for (const c of candidates) {
21998
+ if ((0, import_fs14.existsSync)(c)) return { spec, dir: c };
21999
+ }
22000
+ }
22001
+ return { spec, dir: target };
22002
+ }
22003
+ function detectOrgExtendsSpec(repoDir) {
22004
+ const origin = getRepoOrigin(repoDir);
22005
+ if (!origin) return null;
22006
+ if (origin.host !== "github.com") return null;
22007
+ if (origin.repo === "worlds") return null;
22008
+ return {
22009
+ raw: `github:${origin.owner}/worlds`,
22010
+ kind: "github",
22011
+ owner: origin.owner,
22012
+ repo: "worlds",
22013
+ ref: "HEAD",
22014
+ subpath: ""
22015
+ };
22016
+ }
22017
+ function resolveAllExtends(repoDir, options) {
22018
+ const config = options?.config !== void 0 ? options.config : loadExtendsConfig(repoDir);
22019
+ if (!config?.extends || config.extends.length === 0) return [];
22020
+ const results = [];
22021
+ for (const raw of config.extends) {
22022
+ const spec = parseExtendsSpec(raw);
22023
+ if (!spec) {
22024
+ results.push({
22025
+ spec: { raw, kind: "local" },
22026
+ dir: null,
22027
+ warning: `unparseable extends spec: ${raw}`
22028
+ });
22029
+ continue;
22030
+ }
22031
+ results.push(resolveExtendsSpec(spec, repoDir, options));
22032
+ }
22033
+ return results;
22034
+ }
22035
+ var import_fs14, import_path15, import_os5, import_crypto4, import_child_process2, DEFAULT_TTL_MS, defaultGitFetcher;
22036
+ var init_extends = __esm({
22037
+ "src/radiant/core/extends.ts"() {
22038
+ "use strict";
22039
+ import_fs14 = require("fs");
22040
+ import_path15 = require("path");
22041
+ import_os5 = require("os");
22042
+ import_crypto4 = require("crypto");
22043
+ import_child_process2 = require("child_process");
22044
+ init_git_remote();
22045
+ DEFAULT_TTL_MS = 60 * 60 * 1e3;
22046
+ defaultGitFetcher = (spec, destDir) => {
22047
+ if (spec.kind !== "github") return;
22048
+ const url = `https://github.com/${spec.owner}/${spec.repo}.git`;
22049
+ const parent = (0, import_path15.resolve)(destDir, "..");
22050
+ (0, import_fs14.mkdirSync)(parent, { recursive: true });
22051
+ if ((0, import_fs14.existsSync)(destDir)) {
22052
+ (0, import_fs14.rmSync)(destDir, { recursive: true, force: true });
22053
+ }
22054
+ const args = ["clone", "--depth", "1", "--filter=blob:none"];
22055
+ if (spec.ref && spec.ref !== "HEAD") {
22056
+ args.push("--branch", spec.ref);
22057
+ }
22058
+ args.push(url, destDir);
22059
+ (0, import_child_process2.execFileSync)("git", args, { stdio: "pipe" });
22060
+ };
22061
+ }
22062
+ });
22063
+
21786
22064
  // src/radiant/core/discovery.ts
21787
22065
  function discoverWorlds(options) {
21788
22066
  const worlds = [];
21789
- const userDir = options?.userWorldsDir ?? (0, import_path14.join)((0, import_os5.homedir)(), ".neuroverse", "worlds");
21790
- if ((0, import_fs13.existsSync)(userDir)) {
22067
+ const warnings = [];
22068
+ const forceRefresh = process.env.NEUROVERSE_REFRESH === "1";
22069
+ const noFetch = process.env.NEUROVERSE_NO_FETCH === "1";
22070
+ const noOrg = options?.disableOrg || process.env.NEUROVERSE_NO_ORG === "1";
22071
+ const userDir = options?.userWorldsDir ?? (0, import_path16.join)((0, import_os6.homedir)(), ".neuroverse", "worlds");
22072
+ if ((0, import_fs15.existsSync)(userDir)) {
21791
22073
  worlds.push(...loadWorldsFromDir(userDir, "user"));
21792
22074
  }
22075
+ if (!noOrg && !options?.explicitWorldsDir) {
22076
+ const specs = [];
22077
+ if (options?.repoDir) {
22078
+ const fromGit = detectOrgExtendsSpec(options.repoDir);
22079
+ if (fromGit) specs.push(fromGit);
22080
+ }
22081
+ if (options?.scopeOwner) {
22082
+ const already = specs.some(
22083
+ (s) => s.owner?.toLowerCase() === options.scopeOwner.toLowerCase()
22084
+ );
22085
+ if (!already) {
22086
+ specs.push({
22087
+ raw: `github:${options.scopeOwner}/worlds`,
22088
+ kind: "github",
22089
+ owner: options.scopeOwner,
22090
+ repo: "worlds"
22091
+ });
22092
+ }
22093
+ }
22094
+ const baseDir = options?.repoDir ?? process.cwd();
22095
+ for (const spec of specs) {
22096
+ const result = resolveExtendsSpec(spec, baseDir, {
22097
+ cacheDir: options?.extendsCacheDir,
22098
+ fetcher: options?.extendsFetcher,
22099
+ ttlMs: options?.extendsTtlMs,
22100
+ forceRefresh,
22101
+ noFetch,
22102
+ silentOnMissing: true
22103
+ });
22104
+ worlds.push(...loadExtendsWorlds(result, "org"));
22105
+ }
22106
+ }
22107
+ if (options?.repoDir && !options.disableExtends && !options.explicitWorldsDir) {
22108
+ const results = resolveAllExtends(options.repoDir, {
22109
+ cacheDir: options.extendsCacheDir,
22110
+ fetcher: options.extendsFetcher,
22111
+ ttlMs: options.extendsTtlMs,
22112
+ forceRefresh,
22113
+ noFetch
22114
+ });
22115
+ for (const result of results) {
22116
+ worlds.push(...loadExtendsWorlds(result, "extends"));
22117
+ if (result.warning) warnings.push(result.warning);
22118
+ }
22119
+ }
21793
22120
  if (options?.explicitWorldsDir) {
21794
22121
  worlds.push(...loadWorldsFromDir(options.explicitWorldsDir, "repo"));
21795
22122
  } else if (options?.repoDir) {
21796
22123
  const repoPaths = [
21797
- (0, import_path14.join)(options.repoDir, "worlds"),
21798
- (0, import_path14.join)(options.repoDir, ".neuroverse", "worlds")
22124
+ (0, import_path16.join)(options.repoDir, "worlds"),
22125
+ (0, import_path16.join)(options.repoDir, ".neuroverse", "worlds")
21799
22126
  ];
21800
22127
  for (const p of repoPaths) {
21801
- if ((0, import_fs13.existsSync)(p)) {
22128
+ if ((0, import_fs15.existsSync)(p)) {
21802
22129
  worlds.push(...loadWorldsFromDir(p, "repo"));
21803
22130
  break;
21804
22131
  }
21805
22132
  }
21806
22133
  }
21807
- const combinedContent = worlds.map((w) => `<!-- world: ${w.name} (${w.source}) -->
21808
- ${w.content}`).join("\n\n---\n\n");
22134
+ const combinedContent = worlds.map((w) => {
22135
+ const tag = w.extendsFrom ? `<!-- world: ${w.name} (${w.source} ${w.extendsFrom}) -->` : `<!-- world: ${w.name} (${w.source}) -->`;
22136
+ return `${tag}
22137
+ ${w.content}`;
22138
+ }).join("\n\n---\n\n");
21809
22139
  const summary2 = worlds.length === 0 ? "no worlds discovered" : worlds.map((w) => `${w.name} (${w.source})`).join(", ");
21810
- return { worlds, combinedContent, summary: summary2 };
22140
+ return { worlds, combinedContent, summary: summary2, warnings };
22141
+ }
22142
+ function formatActiveWorlds(stack) {
22143
+ if (stack.worlds.length === 0) return "No worlds loaded.";
22144
+ const lines = ["ACTIVE WORLDS", ""];
22145
+ for (const w of stack.worlds) {
22146
+ const sourceLabel = w.source === "base" ? "universal" : w.source === "user" ? "personal" : w.source === "org" ? `org (${w.extendsFrom ?? "auto"})` : w.source === "extends" ? `shared (${w.extendsFrom ?? "extends"})` : "this repo";
22147
+ lines.push(` ${w.name} (${sourceLabel})`);
22148
+ }
22149
+ if (stack.warnings.length > 0) {
22150
+ lines.push("", "WARNINGS");
22151
+ for (const w of stack.warnings) lines.push(` ${w}`);
22152
+ }
22153
+ return lines.join("\n");
22154
+ }
22155
+ function loadExtendsWorlds(result, source) {
22156
+ if (!result.dir) return [];
22157
+ const loaded = loadWorldsFromDir(result.dir, source);
22158
+ return loaded.map((w) => ({ ...w, extendsFrom: result.spec.raw }));
21811
22159
  }
21812
22160
  function loadWorldsFromDir(dirPath, source) {
21813
- const dir = (0, import_path14.resolve)(dirPath);
21814
- if (!(0, import_fs13.existsSync)(dir)) return [];
21815
- const stat = (0, import_fs13.statSync)(dir);
22161
+ const dir = (0, import_path16.resolve)(dirPath);
22162
+ if (!(0, import_fs15.existsSync)(dir)) return [];
22163
+ const stat = (0, import_fs15.statSync)(dir);
21816
22164
  if (stat.isFile() && dir.endsWith(".md")) {
21817
22165
  try {
21818
22166
  return [{
21819
- name: (0, import_path14.basename)(dir).replace(/\.worldmodel\.md$/, "").replace(/\.nv-world\.md$/, ""),
22167
+ name: (0, import_path16.basename)(dir).replace(/\.worldmodel\.md$/, "").replace(/\.nv-world\.md$/, ""),
21820
22168
  source,
21821
22169
  path: dir,
21822
- content: (0, import_fs13.readFileSync)(dir, "utf-8")
22170
+ content: (0, import_fs15.readFileSync)(dir, "utf-8")
21823
22171
  }];
21824
22172
  } catch {
21825
22173
  return [];
21826
22174
  }
21827
22175
  }
21828
22176
  if (!stat.isDirectory()) return [];
21829
- const files = (0, import_fs13.readdirSync)(dir).filter(
22177
+ const files = (0, import_fs15.readdirSync)(dir).filter(
21830
22178
  (f) => f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md")
21831
22179
  ).sort();
21832
22180
  return files.map((f) => {
21833
- const fullPath = (0, import_path14.join)(dir, f);
22181
+ const fullPath = (0, import_path16.join)(dir, f);
21834
22182
  return {
21835
22183
  name: f.replace(/\.worldmodel\.md$/, "").replace(/\.nv-world\.md$/, ""),
21836
22184
  source,
21837
22185
  path: fullPath,
21838
- content: (0, import_fs13.readFileSync)(fullPath, "utf-8")
22186
+ content: (0, import_fs15.readFileSync)(fullPath, "utf-8")
21839
22187
  };
21840
22188
  });
21841
22189
  }
21842
- var import_fs13, import_path14, import_os5;
22190
+ var import_fs15, import_path16, import_os6;
21843
22191
  var init_discovery = __esm({
21844
22192
  "src/radiant/core/discovery.ts"() {
21845
22193
  "use strict";
21846
- import_fs13 = require("fs");
21847
- import_path14 = require("path");
21848
- import_os5 = require("os");
22194
+ import_fs15 = require("fs");
22195
+ import_path16 = require("path");
22196
+ import_os6 = require("os");
22197
+ init_extends();
21849
22198
  }
21850
22199
  });
21851
22200
 
21852
22201
  // src/radiant/adapters/exocortex.ts
21853
22202
  function readExocortex(dirPath, repoName) {
21854
- const dir = (0, import_path15.resolve)(dirPath);
22203
+ const dir = (0, import_path17.resolve)(dirPath);
21855
22204
  let filesLoaded = 0;
21856
22205
  function tryRead(...paths) {
21857
22206
  for (const p of paths) {
21858
- const full = (0, import_path15.join)(dir, p);
21859
- if ((0, import_fs14.existsSync)(full)) {
22207
+ const full = (0, import_path17.join)(dir, p);
22208
+ if ((0, import_fs16.existsSync)(full)) {
21860
22209
  try {
21861
- const content = (0, import_fs14.readFileSync)(full, "utf-8").trim();
22210
+ const content = (0, import_fs16.readFileSync)(full, "utf-8").trim();
21862
22211
  if (content) {
21863
22212
  filesLoaded++;
21864
22213
  return content;
@@ -21940,33 +22289,33 @@ function summarizeExocortex(ctx) {
21940
22289
  if (ctx.methods) loaded.push("methods");
21941
22290
  return `${loaded.join(", ")} (${ctx.filesLoaded} files)`;
21942
22291
  }
21943
- var import_fs14, import_path15;
22292
+ var import_fs16, import_path17;
21944
22293
  var init_exocortex = __esm({
21945
22294
  "src/radiant/adapters/exocortex.ts"() {
21946
22295
  "use strict";
21947
- import_fs14 = require("fs");
21948
- import_path15 = require("path");
22296
+ import_fs16 = require("fs");
22297
+ import_path17 = require("path");
21949
22298
  }
21950
22299
  });
21951
22300
 
21952
22301
  // src/radiant/memory/palace.ts
21953
22302
  function writeRead(exocortexDir, frontmatter, text) {
21954
- const dir = (0, import_path16.resolve)(exocortexDir, "radiant", "reads");
21955
- (0, import_fs15.mkdirSync)(dir, { recursive: true });
22303
+ const dir = (0, import_path18.resolve)(exocortexDir, "radiant", "reads");
22304
+ (0, import_fs17.mkdirSync)(dir, { recursive: true });
21956
22305
  const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
21957
22306
  const filename = `${date}.md`;
21958
- const filepath = (0, import_path16.join)(dir, filename);
22307
+ const filepath = (0, import_path18.join)(dir, filename);
21959
22308
  const content = `${frontmatter}
21960
22309
 
21961
22310
  ${text}
21962
22311
  `;
21963
- (0, import_fs15.writeFileSync)(filepath, content, "utf-8");
22312
+ (0, import_fs17.writeFileSync)(filepath, content, "utf-8");
21964
22313
  return filepath;
21965
22314
  }
21966
22315
  function updateKnowledge(exocortexDir, persistence, options) {
21967
- const dir = (0, import_path16.resolve)(exocortexDir, "radiant");
21968
- (0, import_fs15.mkdirSync)(dir, { recursive: true });
21969
- const filepath = (0, import_path16.join)(dir, "knowledge.md");
22316
+ const dir = (0, import_path18.resolve)(exocortexDir, "radiant");
22317
+ (0, import_fs17.mkdirSync)(dir, { recursive: true });
22318
+ const filepath = (0, import_path18.join)(dir, "knowledge.md");
21970
22319
  const totalReads = options?.totalReads ?? 0;
21971
22320
  const existingUntriggered = loadUntriggeredCounts(filepath);
21972
22321
  const lines = [
@@ -22053,14 +22402,14 @@ function updateKnowledge(exocortexDir, persistence, options) {
22053
22402
  lines.push(`${name}=${count}`);
22054
22403
  }
22055
22404
  lines.push("-->");
22056
- (0, import_fs15.writeFileSync)(filepath, lines.join("\n"), "utf-8");
22405
+ (0, import_fs17.writeFileSync)(filepath, lines.join("\n"), "utf-8");
22057
22406
  return filepath;
22058
22407
  }
22059
22408
  function loadUntriggeredCounts(filepath) {
22060
22409
  const counts = /* @__PURE__ */ new Map();
22061
- if (!(0, import_fs15.existsSync)(filepath)) return counts;
22410
+ if (!(0, import_fs17.existsSync)(filepath)) return counts;
22062
22411
  try {
22063
- const content = (0, import_fs15.readFileSync)(filepath, "utf-8");
22412
+ const content = (0, import_fs17.readFileSync)(filepath, "utf-8");
22064
22413
  const match = content.match(
22065
22414
  /<!-- untriggered_counts[\s\S]*?-->/
22066
22415
  );
@@ -22078,13 +22427,13 @@ function loadUntriggeredCounts(filepath) {
22078
22427
  return counts;
22079
22428
  }
22080
22429
  function loadPriorReads(exocortexDir) {
22081
- const dir = (0, import_path16.resolve)(exocortexDir, "radiant", "reads");
22082
- if (!(0, import_fs15.existsSync)(dir)) return [];
22083
- const files = (0, import_fs15.readdirSync)(dir).filter((f) => f.endsWith(".md")).sort();
22430
+ const dir = (0, import_path18.resolve)(exocortexDir, "radiant", "reads");
22431
+ if (!(0, import_fs17.existsSync)(dir)) return [];
22432
+ const files = (0, import_fs17.readdirSync)(dir).filter((f) => f.endsWith(".md")).sort();
22084
22433
  const reads = [];
22085
22434
  for (const filename of files) {
22086
- const filepath = (0, import_path16.join)(dir, filename);
22087
- const content = (0, import_fs15.readFileSync)(filepath, "utf-8");
22435
+ const filepath = (0, import_path18.join)(dir, filename);
22436
+ const content = (0, import_fs17.readFileSync)(filepath, "utf-8");
22088
22437
  const date = filename.replace(".md", "");
22089
22438
  const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
22090
22439
  const frontmatter = fmMatch ? fmMatch[1] : "";
@@ -22118,12 +22467,12 @@ function computePersistence(priorReads, currentPatternNames) {
22118
22467
  dates: dates.sort()
22119
22468
  })).sort((a, b) => b.occurrences - a.occurrences);
22120
22469
  }
22121
- var import_fs15, import_path16;
22470
+ var import_fs17, import_path18;
22122
22471
  var init_palace = __esm({
22123
22472
  "src/radiant/memory/palace.ts"() {
22124
22473
  "use strict";
22125
- import_fs15 = require("fs");
22126
- import_path16 = require("path");
22474
+ import_fs17 = require("fs");
22475
+ import_path18 = require("path");
22127
22476
  }
22128
22477
  });
22129
22478
 
@@ -23164,22 +23513,22 @@ __export(server_exports, {
23164
23513
  startRadiantMcp: () => startRadiantMcp
23165
23514
  });
23166
23515
  function loadWorldmodelContent(worldsPath) {
23167
- const resolved = (0, import_path17.resolve)(worldsPath);
23168
- if (!(0, import_fs16.existsSync)(resolved)) {
23516
+ const resolved = (0, import_path19.resolve)(worldsPath);
23517
+ if (!(0, import_fs18.existsSync)(resolved)) {
23169
23518
  throw new Error(`Worlds path not found: ${resolved}`);
23170
23519
  }
23171
- const stat = (0, import_fs16.statSync)(resolved);
23520
+ const stat = (0, import_fs18.statSync)(resolved);
23172
23521
  if (stat.isFile()) {
23173
- return (0, import_fs16.readFileSync)(resolved, "utf-8");
23522
+ return (0, import_fs18.readFileSync)(resolved, "utf-8");
23174
23523
  }
23175
23524
  if (stat.isDirectory()) {
23176
- const files = (0, import_fs16.readdirSync)(resolved).filter(
23177
- (f) => (0, import_path17.extname)(f) === ".md" && (f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md"))
23525
+ const files = (0, import_fs18.readdirSync)(resolved).filter(
23526
+ (f) => (0, import_path19.extname)(f) === ".md" && (f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md"))
23178
23527
  ).sort();
23179
23528
  if (files.length === 0) {
23180
23529
  throw new Error(`No worldmodel files found in ${resolved}`);
23181
23530
  }
23182
- return files.map((f) => (0, import_fs16.readFileSync)((0, import_path17.join)(resolved, f), "utf-8")).join("\n\n---\n\n");
23531
+ return files.map((f) => (0, import_fs18.readFileSync)((0, import_path19.join)(resolved, f), "utf-8")).join("\n\n---\n\n");
23183
23532
  }
23184
23533
  throw new Error(`Worlds path is neither a file nor directory: ${resolved}`);
23185
23534
  }
@@ -23198,12 +23547,12 @@ async function startRadiantMcp(args) {
23198
23547
  const server = new RadiantMcpServer({ worldsPath, lensId, model });
23199
23548
  await server.start();
23200
23549
  }
23201
- var import_fs16, import_path17, TOOLS, RadiantMcpServer;
23550
+ var import_fs18, import_path19, TOOLS, RadiantMcpServer;
23202
23551
  var init_server = __esm({
23203
23552
  "src/radiant/mcp/server.ts"() {
23204
23553
  "use strict";
23205
- import_fs16 = require("fs");
23206
- import_path17 = require("path");
23554
+ import_fs18 = require("fs");
23555
+ import_path19 = require("path");
23207
23556
  init_think();
23208
23557
  init_emergent();
23209
23558
  init_ai();
@@ -23492,17 +23841,17 @@ function parseArgs27(argv) {
23492
23841
  return result;
23493
23842
  }
23494
23843
  function loadWorldmodelContent2(worldsPath) {
23495
- const resolved = (0, import_path18.resolve)(worldsPath);
23496
- if (!(0, import_fs17.existsSync)(resolved)) {
23844
+ const resolved = (0, import_path20.resolve)(worldsPath);
23845
+ if (!(0, import_fs19.existsSync)(resolved)) {
23497
23846
  throw new Error(`Worlds path not found: ${resolved}`);
23498
23847
  }
23499
- const stat = (0, import_fs17.statSync)(resolved);
23848
+ const stat = (0, import_fs19.statSync)(resolved);
23500
23849
  if (stat.isFile()) {
23501
- return (0, import_fs17.readFileSync)(resolved, "utf-8");
23850
+ return (0, import_fs19.readFileSync)(resolved, "utf-8");
23502
23851
  }
23503
23852
  if (stat.isDirectory()) {
23504
- const files = (0, import_fs17.readdirSync)(resolved).filter(
23505
- (f) => (0, import_path18.extname)(f) === ".md" && (f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md"))
23853
+ const files = (0, import_fs19.readdirSync)(resolved).filter(
23854
+ (f) => (0, import_path20.extname)(f) === ".md" && (f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md"))
23506
23855
  ).sort();
23507
23856
  if (files.length === 0) {
23508
23857
  throw new Error(
@@ -23510,27 +23859,55 @@ function loadWorldmodelContent2(worldsPath) {
23510
23859
  );
23511
23860
  }
23512
23861
  return files.map((f) => {
23513
- const content = (0, import_fs17.readFileSync)((0, import_path18.join)(resolved, f), "utf-8");
23862
+ const content = (0, import_fs19.readFileSync)((0, import_path20.join)(resolved, f), "utf-8");
23514
23863
  return `<!-- worldmodel: ${f} -->
23515
23864
  ${content}`;
23516
23865
  }).join("\n\n---\n\n");
23517
23866
  }
23518
23867
  throw new Error(`Worlds path is neither a file nor a directory: ${resolved}`);
23519
23868
  }
23520
- async function cmdThink(args) {
23521
- const lensId = args.lens ?? process.env.RADIANT_LENS;
23522
- if (!lensId) {
23869
+ function resolveWorldmodelContent(explicitPath, scopeOwner) {
23870
+ if (explicitPath) {
23871
+ return loadWorldmodelContent2(explicitPath);
23872
+ }
23873
+ const stack = discoverWorlds({
23874
+ repoDir: process.cwd(),
23875
+ scopeOwner
23876
+ });
23877
+ if (stack.worlds.length === 0) {
23878
+ const scopeLine = scopeOwner ? ` 3. github:${scopeOwner}/worlds (from scope arg)
23879
+ ` : "";
23880
+ const ext = scopeOwner ? 4 : 3;
23881
+ const repo = scopeOwner ? 5 : 4;
23523
23882
  process.stderr.write(
23524
- `${RED2}Error:${RESET3} --lens <id> or RADIANT_LENS required.
23525
- ${DIM3}Available lenses: ${listLenses().join(", ")}${RESET3}
23883
+ `${RED2}Error:${RESET3} No worldmodel found.
23884
+ ${DIM3}Tried (in order):
23885
+ 1. ~/.neuroverse/worlds/ (user tier)
23886
+ 2. github:<owner>/worlds (org auto-detect from git remote)
23887
+ ` + scopeLine + ` ${ext}. .neuroverse/config.json extends (explicit shared worlds)
23888
+ ${repo}. ./worlds/ or ./.neuroverse/worlds/ (repo tier)
23889
+
23890
+ Pass --worlds <dir> or set RADIANT_WORLDS to specify explicitly.
23891
+ Or run against a <scope>/ where github.com/<scope>/worlds exists.${RESET3}
23526
23892
  `
23527
23893
  );
23528
23894
  process.exit(1);
23529
23895
  }
23530
- const worldsPath = args.worlds ?? process.env.RADIANT_WORLDS;
23531
- if (!worldsPath) {
23896
+ process.stderr.write(`${DIM3}${formatActiveWorlds(stack)}${RESET3}
23897
+
23898
+ `);
23899
+ for (const warning of stack.warnings) {
23900
+ process.stderr.write(`${YELLOW3}\u26A0${RESET3} ${warning}
23901
+ `);
23902
+ }
23903
+ return stack.combinedContent;
23904
+ }
23905
+ async function cmdThink(args) {
23906
+ const lensId = args.lens ?? process.env.RADIANT_LENS;
23907
+ if (!lensId) {
23532
23908
  process.stderr.write(
23533
- `${RED2}Error:${RESET3} --worlds <dir> or RADIANT_WORLDS required.
23909
+ `${RED2}Error:${RESET3} --lens <id> or RADIANT_LENS required.
23910
+ ${DIM3}Available lenses: ${listLenses().join(", ")}${RESET3}
23534
23911
  `
23535
23912
  );
23536
23913
  process.exit(1);
@@ -23549,7 +23926,7 @@ ${DIM3}Set it to your Anthropic API key to use Radiant's AI features.${RESET3}
23549
23926
  query = args.rest.join(" ");
23550
23927
  }
23551
23928
  if (!query && !process.stdin.isTTY) {
23552
- query = (0, import_fs17.readFileSync)(0, "utf-8").trim();
23929
+ query = (0, import_fs19.readFileSync)(0, "utf-8").trim();
23553
23930
  }
23554
23931
  if (!query) {
23555
23932
  process.stderr.write(
@@ -23559,12 +23936,12 @@ ${DIM3}Use --query "...", pass as trailing args, or pipe via stdin.${RESET3}
23559
23936
  );
23560
23937
  process.exit(1);
23561
23938
  }
23562
- const worldmodelContent = loadWorldmodelContent2(worldsPath);
23939
+ const explicitWorldsPath = args.worlds ?? process.env.RADIANT_WORLDS;
23940
+ const worldmodelContent = resolveWorldmodelContent(explicitWorldsPath);
23563
23941
  const model = args.model ?? process.env.RADIANT_MODEL;
23564
23942
  const ai = createAnthropicAI(apiKey, model || void 0);
23565
23943
  process.stderr.write(
23566
- `${DIM3}Worlds: ${worldsPath}${RESET3}
23567
- ${DIM3}Lens: ${lensId}${RESET3}
23944
+ `${DIM3}Lens: ${lensId}${RESET3}
23568
23945
  ${DIM3}Model: ${model ?? "claude-sonnet-4-20250514 (default)"}${RESET3}
23569
23946
 
23570
23947
  `
@@ -23623,14 +24000,6 @@ async function cmdEmergent(args) {
23623
24000
  process.stderr.write(
23624
24001
  `${RED2}Error:${RESET3} --lens <id> or RADIANT_LENS required.
23625
24002
  ${DIM3}Available lenses: ${listLenses().join(", ")}${RESET3}
23626
- `
23627
- );
23628
- process.exit(1);
23629
- }
23630
- const worldsPath = args.worlds ?? process.env.RADIANT_WORLDS;
23631
- if (!worldsPath) {
23632
- process.stderr.write(
23633
- `${RED2}Error:${RESET3} --worlds <dir> or RADIANT_WORLDS required.
23634
24003
  `
23635
24004
  );
23636
24005
  process.exit(1);
@@ -23652,7 +24021,11 @@ ${DIM3}Set it to a GitHub PAT with repo read access.${RESET3}
23652
24021
  );
23653
24022
  process.exit(1);
23654
24023
  }
23655
- const worldmodelContent = loadWorldmodelContent2(worldsPath);
24024
+ const explicitWorldsPath = args.worlds ?? process.env.RADIANT_WORLDS;
24025
+ const worldmodelContent = resolveWorldmodelContent(
24026
+ explicitWorldsPath,
24027
+ scope.owner
24028
+ );
23656
24029
  const model = args.model ?? process.env.RADIANT_MODEL;
23657
24030
  const ai = createAnthropicAI(anthropicKey, model || void 0);
23658
24031
  const view = args.view ?? process.env.RADIANT_VIEW ?? "community";
@@ -23826,18 +24199,19 @@ async function main34(argv) {
23826
24199
  process.exit(1);
23827
24200
  }
23828
24201
  }
23829
- var import_fs17, import_path18, RED2, DIM3, BOLD3, YELLOW3, RESET3, USAGE10;
24202
+ var import_fs19, import_path20, RED2, DIM3, BOLD3, YELLOW3, RESET3, USAGE10;
23830
24203
  var init_radiant = __esm({
23831
24204
  "src/cli/radiant.ts"() {
23832
24205
  "use strict";
23833
- import_fs17 = require("fs");
23834
- import_path18 = require("path");
24206
+ import_fs19 = require("fs");
24207
+ import_path20 = require("path");
23835
24208
  init_think();
23836
24209
  init_emergent();
23837
24210
  init_ai();
23838
24211
  init_scopes();
23839
24212
  init_exocortex();
23840
24213
  init_lenses();
24214
+ init_discovery();
23841
24215
  RED2 = "\x1B[31m";
23842
24216
  DIM3 = "\x1B[2m";
23843
24217
  BOLD3 = "\x1B[1m";
@@ -23863,6 +24237,18 @@ ${BOLD3}Usage:${RESET3}
23863
24237
  neuroverse radiant lenses list
23864
24238
  neuroverse radiant lenses describe auki-builder
23865
24239
 
24240
+ ${BOLD3}Auto-discovery:${RESET3}
24241
+ You do not need to clone the target repo.
24242
+
24243
+ radiant emergent NeuroverseOS/ \u2192 probes github.com/NeuroverseOS/worlds
24244
+ radiant emergent aukiverse/posemesh \u2192 probes github.com/aukiverse/worlds
24245
+
24246
+ The scope argument itself is enough. Discovery also picks up
24247
+ ~/.neuroverse/worlds/ (personal), the org from your current clone's
24248
+ .git/config (if any), and ./worlds/ (this repo).
24249
+
24250
+ Set NEUROVERSE_NO_ORG=1 to disable org probing for a single run.
24251
+
23866
24252
  ${BOLD3}Environment:${RESET3}
23867
24253
  ANTHROPIC_API_KEY Required for AI commands (think, emergent, decision)
23868
24254
  RADIANT_WORLDS Default worlds directory (overridden by --worlds)