@neuroverseos/governance 0.6.1 → 0.7.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.
- package/README.md +0 -3
- package/dist/{chunk-AEVT7DSZ.js → chunk-T6EQ7ZBG.js} +366 -3
- package/dist/cli/neuroverse.cjs +770 -129
- package/dist/cli/radiant.cjs +2078 -139
- package/dist/cli/radiant.js +8 -1
- package/dist/radiant/index.cjs +1554 -5
- package/dist/radiant/index.d.cts +146 -8
- package/dist/radiant/index.d.ts +146 -8
- package/dist/radiant/index.js +18 -3
- package/dist/server-BXMC5NOE.js +271 -0
- package/package.json +1 -1
package/dist/cli/neuroverse.cjs
CHANGED
|
@@ -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:
|
|
2006
|
-
const { readdirSync:
|
|
2005
|
+
const { join: join18 } = await import("path");
|
|
2006
|
+
const { readdirSync: readdirSync9 } = await import("fs");
|
|
2007
2007
|
async function readJson(filename) {
|
|
2008
|
-
const filePath =
|
|
2008
|
+
const filePath = join18(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 =
|
|
2039
|
-
const ruleFiles =
|
|
2038
|
+
const rulesDir = join18(dirPath, "rules");
|
|
2039
|
+
const ruleFiles = readdirSync9(rulesDir).filter((f) => f.endsWith(".json")).sort();
|
|
2040
2040
|
for (const file of ruleFiles) {
|
|
2041
2041
|
try {
|
|
2042
|
-
const content = await readFile4(
|
|
2042
|
+
const content = await readFile4(join18(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:
|
|
2097
|
-
const { existsSync:
|
|
2096
|
+
const { join: join18, dirname: dirname4 } = await import("path");
|
|
2097
|
+
const { existsSync: existsSync14 } = 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 =
|
|
2105
|
+
packageRoot = join18(thisFile, "..", "..");
|
|
2106
2106
|
} catch {
|
|
2107
2107
|
packageRoot = process.cwd();
|
|
2108
2108
|
}
|
|
2109
2109
|
const candidates = [
|
|
2110
|
-
|
|
2111
|
-
|
|
2110
|
+
join18(packageRoot, "dist", "worlds", filename),
|
|
2111
|
+
join18(packageRoot, "src", "worlds", filename)
|
|
2112
2112
|
];
|
|
2113
2113
|
for (const candidate of candidates) {
|
|
2114
|
-
if (
|
|
2114
|
+
if (existsSync14(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:
|
|
2145
|
-
const guardsPath =
|
|
2144
|
+
const { join: join18 } = await import("path");
|
|
2145
|
+
const guardsPath = join18(worldDir, "guards.json");
|
|
2146
2146
|
let config;
|
|
2147
2147
|
try {
|
|
2148
2148
|
const raw = await readFile4(guardsPath, "utf-8");
|
|
@@ -2182,13 +2182,13 @@ 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:
|
|
2186
|
-
const { readdirSync:
|
|
2187
|
-
const rulesDir =
|
|
2185
|
+
const { join: join18 } = await import("path");
|
|
2186
|
+
const { readdirSync: readdirSync9 } = await import("fs");
|
|
2187
|
+
const rulesDir = join18(worldDir, "rules");
|
|
2188
2188
|
await mkdir3(rulesDir, { recursive: true });
|
|
2189
2189
|
let nextNum = 1;
|
|
2190
2190
|
try {
|
|
2191
|
-
const existing =
|
|
2191
|
+
const existing = readdirSync9(rulesDir).filter((f) => f.match(/^rule-\d+\.json$/)).sort();
|
|
2192
2192
|
if (existing.length > 0) {
|
|
2193
2193
|
const lastFile = existing[existing.length - 1];
|
|
2194
2194
|
const match = lastFile.match(/rule-(\d+)\.json/);
|
|
@@ -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 =
|
|
2217
|
+
const rulePath = join18(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:
|
|
2234
|
-
const invariantsPath =
|
|
2233
|
+
const { join: join18 } = await import("path");
|
|
2234
|
+
const invariantsPath = join18(worldDir, "invariants.json");
|
|
2235
2235
|
let config;
|
|
2236
2236
|
try {
|
|
2237
2237
|
const raw = await readFile4(invariantsPath, "utf-8");
|
|
@@ -2849,7 +2849,7 @@ ${candidates.map((c) => ` - ${c}`).join("\n")}`
|
|
|
2849
2849
|
}
|
|
2850
2850
|
async function collectMarkdownSources(inputPath) {
|
|
2851
2851
|
const { stat, readFile: rf, readdir } = await import("fs/promises");
|
|
2852
|
-
const { join: pathJoin, extname:
|
|
2852
|
+
const { join: pathJoin, extname: extname4, basename: basename4 } = await import("path");
|
|
2853
2853
|
const stats = await stat(inputPath);
|
|
2854
2854
|
if (stats.isFile()) {
|
|
2855
2855
|
const content = await rf(inputPath, "utf-8");
|
|
@@ -2857,20 +2857,20 @@ async function collectMarkdownSources(inputPath) {
|
|
|
2857
2857
|
}
|
|
2858
2858
|
if (stats.isDirectory()) {
|
|
2859
2859
|
const sources = [];
|
|
2860
|
-
await collectDir(inputPath, sources, rf, pathJoin,
|
|
2860
|
+
await collectDir(inputPath, sources, rf, pathJoin, extname4, basename4);
|
|
2861
2861
|
sources.sort((a, b) => a.filename.localeCompare(b.filename));
|
|
2862
2862
|
return sources;
|
|
2863
2863
|
}
|
|
2864
2864
|
throw new Error(`Input path is neither a file nor a directory: ${inputPath}`);
|
|
2865
2865
|
}
|
|
2866
|
-
async function collectDir(dir, sources, rf, pathJoin,
|
|
2866
|
+
async function collectDir(dir, sources, rf, pathJoin, extname4, basename4) {
|
|
2867
2867
|
const { readdir } = await import("fs/promises");
|
|
2868
2868
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
2869
2869
|
for (const entry of entries) {
|
|
2870
2870
|
const fullPath = pathJoin(dir, entry.name);
|
|
2871
2871
|
if (entry.isDirectory()) {
|
|
2872
|
-
await collectDir(fullPath, sources, rf, pathJoin,
|
|
2873
|
-
} else if (entry.isFile() &&
|
|
2872
|
+
await collectDir(fullPath, sources, rf, pathJoin, extname4, basename4);
|
|
2873
|
+
} else if (entry.isFile() && extname4(entry.name).toLowerCase() === ".md") {
|
|
2874
2874
|
const content = await rf(fullPath, "utf-8");
|
|
2875
2875
|
sources.push({ filename: entry.name, content });
|
|
2876
2876
|
}
|
|
@@ -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:
|
|
3531
|
+
const { join: join18 } = await import("path");
|
|
3532
3532
|
await mkdir3(outputDir, { recursive: true });
|
|
3533
|
-
await writeFile6(
|
|
3534
|
-
await writeFile6(
|
|
3535
|
-
await writeFile6(
|
|
3536
|
-
await writeFile6(
|
|
3537
|
-
await writeFile6(
|
|
3538
|
-
await writeFile6(
|
|
3539
|
-
await writeFile6(
|
|
3540
|
-
const rulesDir =
|
|
3533
|
+
await writeFile6(join18(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
|
|
3534
|
+
await writeFile6(join18(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
|
|
3535
|
+
await writeFile6(join18(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
|
|
3536
|
+
await writeFile6(join18(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
|
|
3537
|
+
await writeFile6(join18(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
|
|
3538
|
+
await writeFile6(join18(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
|
|
3539
|
+
await writeFile6(join18(outputDir, "metadata.json"), JSON.stringify(world.metadata, null, 2));
|
|
3540
|
+
const rulesDir = join18(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(
|
|
3545
|
+
await writeFile6(join18(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:
|
|
3676
|
+
const { join: join18 } = await import("path");
|
|
3677
3677
|
const { copyFile } = await import("fs/promises");
|
|
3678
|
-
const sourceDest =
|
|
3678
|
+
const sourceDest = join18(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:
|
|
5013
|
-
if (
|
|
5012
|
+
const { existsSync: existsSync14 } = await import("fs");
|
|
5013
|
+
if (existsSync14(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:
|
|
5871
|
+
const { join: join18 } = await import("path");
|
|
5872
5872
|
await mkdir3(outputDir, { recursive: true });
|
|
5873
|
-
await writeFile6(
|
|
5874
|
-
await writeFile6(
|
|
5875
|
-
await writeFile6(
|
|
5876
|
-
await writeFile6(
|
|
5877
|
-
const rulesDir =
|
|
5873
|
+
await writeFile6(join18(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
|
|
5874
|
+
await writeFile6(join18(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
|
|
5875
|
+
await writeFile6(join18(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
|
|
5876
|
+
await writeFile6(join18(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
|
|
5877
|
+
const rulesDir = join18(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(
|
|
5882
|
+
await writeFile6(join18(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
|
|
5883
5883
|
}
|
|
5884
|
-
await writeFile6(
|
|
5885
|
-
await writeFile6(
|
|
5886
|
-
await writeFile6(
|
|
5884
|
+
await writeFile6(join18(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
|
|
5885
|
+
await writeFile6(join18(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
|
|
5886
|
+
await writeFile6(join18(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:
|
|
8246
|
-
const dir = policiesDir ??
|
|
8245
|
+
const { join: join18 } = await import("path");
|
|
8246
|
+
const dir = policiesDir ?? join18(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(
|
|
8251
|
+
const content = await readFile4(join18(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:
|
|
8323
|
+
const { join: join18 } = 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(
|
|
8366
|
-
writeFile6(
|
|
8367
|
-
writeFile6(
|
|
8365
|
+
writeFile6(join18(dir, "world.json"), JSON.stringify(worldJson, null, 2)),
|
|
8366
|
+
writeFile6(join18(dir, "kernel.json"), JSON.stringify(kernelJson, null, 2)),
|
|
8367
|
+
writeFile6(join18(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((
|
|
8711
|
+
return new Promise((resolve10, reject) => {
|
|
8712
8712
|
const chunks = [];
|
|
8713
8713
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
8714
|
-
req.on("end", () =>
|
|
8714
|
+
req.on("end", () => resolve10(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:
|
|
11479
|
-
const { join:
|
|
11480
|
-
const hasWorld =
|
|
11478
|
+
const { existsSync: existsSync14 } = await import("fs");
|
|
11479
|
+
const { join: join18 } = await import("path");
|
|
11480
|
+
const hasWorld = existsSync14(join18(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:
|
|
11496
|
-
const { join:
|
|
11495
|
+
const { existsSync: existsSync14 } = await import("fs");
|
|
11496
|
+
const { join: join18 } = await import("path");
|
|
11497
11497
|
const candidates = ["./world", "./.neuroverse", "./worlds"];
|
|
11498
11498
|
let found;
|
|
11499
11499
|
for (const dir of candidates) {
|
|
11500
|
-
if (
|
|
11500
|
+
if (existsSync14(join18(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:
|
|
12553
|
-
|
|
12552
|
+
const { mkdirSync: mkdirSync6 } = await import("fs");
|
|
12553
|
+
mkdirSync6(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((
|
|
13151
|
+
return new Promise((resolve10, 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
|
-
|
|
13197
|
+
resolve10();
|
|
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((
|
|
13314
|
-
rl2.on("close",
|
|
13313
|
+
return new Promise((resolve10) => {
|
|
13314
|
+
rl2.on("close", resolve10);
|
|
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:
|
|
14425
|
+
const { join: join18 } = await import("path");
|
|
14426
14426
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
14427
|
-
const snapshotDir =
|
|
14427
|
+
const snapshotDir = join18(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(
|
|
14434
|
-
await writeFile6(
|
|
14433
|
+
const content = await readFile4(join18(worldPath, file), "utf-8");
|
|
14434
|
+
await writeFile6(join18(snapshotDir, file), content, "utf-8");
|
|
14435
14435
|
copied++;
|
|
14436
14436
|
}
|
|
14437
14437
|
}
|
|
14438
14438
|
try {
|
|
14439
|
-
const rulesDir =
|
|
14439
|
+
const rulesDir = join18(worldPath, "rules");
|
|
14440
14440
|
const ruleFiles = await readdir(rulesDir);
|
|
14441
|
-
await mkdir3(
|
|
14441
|
+
await mkdir3(join18(snapshotDir, "rules"), { recursive: true });
|
|
14442
14442
|
for (const file of ruleFiles) {
|
|
14443
14443
|
if (file.endsWith(".json")) {
|
|
14444
|
-
const content = await readFile4(
|
|
14445
|
-
await writeFile6(
|
|
14444
|
+
const content = await readFile4(join18(rulesDir, file), "utf-8");
|
|
14445
|
+
await writeFile6(join18(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:
|
|
14459
|
-
const snapshotsDir =
|
|
14458
|
+
const { join: join18 } = await import("path");
|
|
14459
|
+
const snapshotsDir = join18(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 =
|
|
14474
|
+
const snapshotDir = join18(snapshotsDir, latest);
|
|
14475
14475
|
const backupTimestamp = "pre-rollback-" + (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
14476
|
-
const backupDir =
|
|
14476
|
+
const backupDir = join18(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(
|
|
14482
|
-
await writeFile6(
|
|
14481
|
+
const content = await readFile4(join18(worldPath, file), "utf-8");
|
|
14482
|
+
await writeFile6(join18(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(
|
|
14490
|
-
await writeFile6(
|
|
14489
|
+
const content = await readFile4(join18(snapshotDir, file), "utf-8");
|
|
14490
|
+
await writeFile6(join18(worldPath, file), content, "utf-8");
|
|
14491
14491
|
restored++;
|
|
14492
14492
|
}
|
|
14493
14493
|
}
|
|
14494
14494
|
try {
|
|
14495
|
-
const rulesDir =
|
|
14495
|
+
const rulesDir = join18(snapshotDir, "rules");
|
|
14496
14496
|
const ruleFiles = await readdir(rulesDir);
|
|
14497
|
-
await mkdir3(
|
|
14497
|
+
await mkdir3(join18(worldPath, "rules"), { recursive: true });
|
|
14498
14498
|
for (const file of ruleFiles) {
|
|
14499
14499
|
if (file.endsWith(".json")) {
|
|
14500
|
-
const content = await readFile4(
|
|
14501
|
-
await writeFile6(
|
|
14500
|
+
const content = await readFile4(join18(rulesDir, file), "utf-8");
|
|
14501
|
+
await writeFile6(join18(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((
|
|
16403
|
+
return new Promise((resolve10) => {
|
|
16404
16404
|
getRL().question(`
|
|
16405
16405
|
${question}${suffix}: `, (answer) => {
|
|
16406
16406
|
const val = answer.trim();
|
|
16407
|
-
|
|
16407
|
+
resolve10(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((
|
|
16413
|
+
return new Promise((resolve10) => {
|
|
16414
16414
|
getRL().question(`
|
|
16415
16415
|
${question} ${hint}: `, (answer) => {
|
|
16416
16416
|
const val = answer.trim().toLowerCase();
|
|
16417
|
-
if (val === "")
|
|
16418
|
-
else
|
|
16417
|
+
if (val === "") resolve10(defaultYes);
|
|
16418
|
+
else resolve10(val === "y" || val === "yes");
|
|
16419
16419
|
});
|
|
16420
16420
|
});
|
|
16421
16421
|
}
|
|
16422
16422
|
function choose(question, options) {
|
|
16423
|
-
return new Promise((
|
|
16423
|
+
return new Promise((resolve10) => {
|
|
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
|
-
|
|
16433
|
+
resolve10(options[idx]);
|
|
16434
16434
|
} else {
|
|
16435
|
-
|
|
16435
|
+
resolve10(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:
|
|
16904
|
+
const { mkdirSync: mkdirSync6, existsSync: existsSync14 } = await import("fs");
|
|
16905
16905
|
const { writeFile: writeFile6 } = await import("fs/promises");
|
|
16906
|
-
const { join:
|
|
16906
|
+
const { join: join18 } = await import("path");
|
|
16907
16907
|
const files = [];
|
|
16908
|
-
if (!
|
|
16909
|
-
const rulesDir =
|
|
16910
|
-
if (!
|
|
16908
|
+
if (!existsSync14(outputDir)) mkdirSync6(outputDir, { recursive: true });
|
|
16909
|
+
const rulesDir = join18(outputDir, "rules");
|
|
16910
|
+
if (!existsSync14(rulesDir)) mkdirSync6(rulesDir, { recursive: true });
|
|
16911
16911
|
const writeJson = async (name, data) => {
|
|
16912
|
-
const path =
|
|
16912
|
+
const path = join18(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 =
|
|
16924
|
+
const rulePath = join18(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:
|
|
17011
|
+
const { join: join18 } = 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
|
-
|
|
17028
|
+
join18(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
|
-
|
|
17050
|
+
join18(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:
|
|
18103
|
+
const { join: join18 } = await import("path");
|
|
18104
18104
|
const possiblePaths = [
|
|
18105
|
-
|
|
18105
|
+
join18(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 =
|
|
18126
|
+
mdPath = join18(worldPath, mdFile);
|
|
18127
18127
|
mdContent = await readFile4(mdPath, "utf-8");
|
|
18128
18128
|
}
|
|
18129
18129
|
} catch {
|
|
@@ -20770,6 +20770,318 @@ var init_exocortex = __esm({
|
|
|
20770
20770
|
}
|
|
20771
20771
|
});
|
|
20772
20772
|
|
|
20773
|
+
// src/radiant/memory/palace.ts
|
|
20774
|
+
function writeRead(exocortexDir, frontmatter, text) {
|
|
20775
|
+
const dir = (0, import_path14.resolve)(exocortexDir, "radiant", "reads");
|
|
20776
|
+
(0, import_fs13.mkdirSync)(dir, { recursive: true });
|
|
20777
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
20778
|
+
const filename = `${date}.md`;
|
|
20779
|
+
const filepath = (0, import_path14.join)(dir, filename);
|
|
20780
|
+
const content = `${frontmatter}
|
|
20781
|
+
|
|
20782
|
+
${text}
|
|
20783
|
+
`;
|
|
20784
|
+
(0, import_fs13.writeFileSync)(filepath, content, "utf-8");
|
|
20785
|
+
return filepath;
|
|
20786
|
+
}
|
|
20787
|
+
function updateKnowledge(exocortexDir, persistence, options) {
|
|
20788
|
+
const dir = (0, import_path14.resolve)(exocortexDir, "radiant");
|
|
20789
|
+
(0, import_fs13.mkdirSync)(dir, { recursive: true });
|
|
20790
|
+
const filepath = (0, import_path14.join)(dir, "knowledge.md");
|
|
20791
|
+
const totalReads = options?.totalReads ?? 0;
|
|
20792
|
+
const existingUntriggered = loadUntriggeredCounts(filepath);
|
|
20793
|
+
const lines = [
|
|
20794
|
+
"# Radiant \u2014 Accumulated Behavioral Knowledge",
|
|
20795
|
+
"",
|
|
20796
|
+
`Last updated: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`,
|
|
20797
|
+
`Total reads: ${totalReads}`,
|
|
20798
|
+
"",
|
|
20799
|
+
"---",
|
|
20800
|
+
"",
|
|
20801
|
+
"## Evolution proposals",
|
|
20802
|
+
""
|
|
20803
|
+
];
|
|
20804
|
+
const addCandidates = persistence.filter((p) => p.occurrences >= 3);
|
|
20805
|
+
if (addCandidates.length > 0) {
|
|
20806
|
+
lines.push("### Consider adding");
|
|
20807
|
+
lines.push("");
|
|
20808
|
+
lines.push("These candidate patterns keep recurring. They are not yet in the worldmodel.");
|
|
20809
|
+
lines.push("If they represent real behavioral patterns worth tracking, add them.");
|
|
20810
|
+
lines.push("If they were temporary, dismiss them.");
|
|
20811
|
+
lines.push("");
|
|
20812
|
+
for (const p of addCandidates) {
|
|
20813
|
+
lines.push(
|
|
20814
|
+
`- **${p.name}** \u2014 observed ${p.occurrences} times (${p.dates.join(", ")}). Add to auki-strategy.worldmodel.md \u2192 Evolution Layer \u2192 Drift Behaviors (if concerning) or Aligned Behaviors (if healthy).`
|
|
20815
|
+
);
|
|
20816
|
+
}
|
|
20817
|
+
lines.push("");
|
|
20818
|
+
}
|
|
20819
|
+
if (options?.declaredItems && options.declaredItems.length > 0) {
|
|
20820
|
+
const triggered = new Set(options.triggeredItems ?? []);
|
|
20821
|
+
const removeCandidates = [];
|
|
20822
|
+
for (const item of options.declaredItems) {
|
|
20823
|
+
if (!triggered.has(item.name)) {
|
|
20824
|
+
const prior = existingUntriggered.get(item.name) ?? 0;
|
|
20825
|
+
const count = prior + 1;
|
|
20826
|
+
existingUntriggered.set(item.name, count);
|
|
20827
|
+
if (count >= 4) {
|
|
20828
|
+
removeCandidates.push({ item, weeksSilent: count });
|
|
20829
|
+
}
|
|
20830
|
+
} else {
|
|
20831
|
+
existingUntriggered.set(item.name, 0);
|
|
20832
|
+
}
|
|
20833
|
+
}
|
|
20834
|
+
if (removeCandidates.length > 0) {
|
|
20835
|
+
lines.push("### Consider removing");
|
|
20836
|
+
lines.push("");
|
|
20837
|
+
lines.push("These items are declared in the worldmodel but haven't triggered in multiple reads.");
|
|
20838
|
+
lines.push("Either the team has internalized them (the rule is redundant) or they haven't been tested.");
|
|
20839
|
+
lines.push("A lean worldmodel with 5 sharp invariants is stronger than a bloated one with 20.");
|
|
20840
|
+
lines.push("");
|
|
20841
|
+
for (const { item, weeksSilent } of removeCandidates) {
|
|
20842
|
+
lines.push(
|
|
20843
|
+
`- **${item.name}** (${item.type}) \u2014 hasn't triggered in ${weeksSilent} reads. Internalized or untested? Review whether it still earns its place.`
|
|
20844
|
+
);
|
|
20845
|
+
}
|
|
20846
|
+
lines.push("");
|
|
20847
|
+
}
|
|
20848
|
+
}
|
|
20849
|
+
if (options?.triggeredItems && options.triggeredItems.length > 0) {
|
|
20850
|
+
lines.push("### Keep (recently active)");
|
|
20851
|
+
lines.push("");
|
|
20852
|
+
lines.push("These worldmodel items triggered governance in the most recent read. They're earning their place.");
|
|
20853
|
+
lines.push("");
|
|
20854
|
+
for (const name of options.triggeredItems) {
|
|
20855
|
+
lines.push(`- **${name}** \u2014 triggered this read. Holding.`);
|
|
20856
|
+
}
|
|
20857
|
+
lines.push("");
|
|
20858
|
+
}
|
|
20859
|
+
lines.push("---");
|
|
20860
|
+
lines.push("");
|
|
20861
|
+
lines.push("## Pattern persistence (all observed)");
|
|
20862
|
+
lines.push("");
|
|
20863
|
+
for (const p of persistence) {
|
|
20864
|
+
const status = p.occurrences >= 4 ? "**persistent**" : p.occurrences >= 2 ? "recurring" : "observed once";
|
|
20865
|
+
lines.push(`### ${p.name}`);
|
|
20866
|
+
lines.push(`- Status: ${status}`);
|
|
20867
|
+
lines.push(`- Observed ${p.occurrences} time${p.occurrences > 1 ? "s" : ""}: ${p.dates.join(", ")}`);
|
|
20868
|
+
lines.push("");
|
|
20869
|
+
}
|
|
20870
|
+
lines.push("---");
|
|
20871
|
+
lines.push("");
|
|
20872
|
+
lines.push("<!-- untriggered_counts (machine-readable, do not edit)");
|
|
20873
|
+
for (const [name, count] of existingUntriggered.entries()) {
|
|
20874
|
+
lines.push(`${name}=${count}`);
|
|
20875
|
+
}
|
|
20876
|
+
lines.push("-->");
|
|
20877
|
+
(0, import_fs13.writeFileSync)(filepath, lines.join("\n"), "utf-8");
|
|
20878
|
+
return filepath;
|
|
20879
|
+
}
|
|
20880
|
+
function loadUntriggeredCounts(filepath) {
|
|
20881
|
+
const counts = /* @__PURE__ */ new Map();
|
|
20882
|
+
if (!(0, import_fs13.existsSync)(filepath)) return counts;
|
|
20883
|
+
try {
|
|
20884
|
+
const content = (0, import_fs13.readFileSync)(filepath, "utf-8");
|
|
20885
|
+
const match = content.match(
|
|
20886
|
+
/<!-- untriggered_counts[\s\S]*?-->/
|
|
20887
|
+
);
|
|
20888
|
+
if (match) {
|
|
20889
|
+
const lines = match[0].split("\n");
|
|
20890
|
+
for (const line of lines) {
|
|
20891
|
+
const eq = line.match(/^([^=]+)=(\d+)$/);
|
|
20892
|
+
if (eq) {
|
|
20893
|
+
counts.set(eq[1], parseInt(eq[2], 10));
|
|
20894
|
+
}
|
|
20895
|
+
}
|
|
20896
|
+
}
|
|
20897
|
+
} catch {
|
|
20898
|
+
}
|
|
20899
|
+
return counts;
|
|
20900
|
+
}
|
|
20901
|
+
function loadPriorReads(exocortexDir) {
|
|
20902
|
+
const dir = (0, import_path14.resolve)(exocortexDir, "radiant", "reads");
|
|
20903
|
+
if (!(0, import_fs13.existsSync)(dir)) return [];
|
|
20904
|
+
const files = (0, import_fs13.readdirSync)(dir).filter((f) => f.endsWith(".md")).sort();
|
|
20905
|
+
const reads = [];
|
|
20906
|
+
for (const filename of files) {
|
|
20907
|
+
const filepath = (0, import_path14.join)(dir, filename);
|
|
20908
|
+
const content = (0, import_fs13.readFileSync)(filepath, "utf-8");
|
|
20909
|
+
const date = filename.replace(".md", "");
|
|
20910
|
+
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
20911
|
+
const frontmatter = fmMatch ? fmMatch[1] : "";
|
|
20912
|
+
const patternNames = [];
|
|
20913
|
+
const nameMatches = frontmatter.matchAll(/- name: ["']?([^"'\n]+)["']?/g);
|
|
20914
|
+
for (const m of nameMatches) {
|
|
20915
|
+
patternNames.push(m[1].trim());
|
|
20916
|
+
}
|
|
20917
|
+
reads.push({ date, filename, patternNames, frontmatter });
|
|
20918
|
+
}
|
|
20919
|
+
return reads;
|
|
20920
|
+
}
|
|
20921
|
+
function computePersistence(priorReads, currentPatternNames) {
|
|
20922
|
+
const allPatterns = /* @__PURE__ */ new Map();
|
|
20923
|
+
for (const read of priorReads) {
|
|
20924
|
+
for (const name of read.patternNames) {
|
|
20925
|
+
const dates = allPatterns.get(name) ?? [];
|
|
20926
|
+
if (!dates.includes(read.date)) dates.push(read.date);
|
|
20927
|
+
allPatterns.set(name, dates);
|
|
20928
|
+
}
|
|
20929
|
+
}
|
|
20930
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
20931
|
+
for (const name of currentPatternNames) {
|
|
20932
|
+
const dates = allPatterns.get(name) ?? [];
|
|
20933
|
+
if (!dates.includes(today)) dates.push(today);
|
|
20934
|
+
allPatterns.set(name, dates);
|
|
20935
|
+
}
|
|
20936
|
+
return Array.from(allPatterns.entries()).map(([name, dates]) => ({
|
|
20937
|
+
name,
|
|
20938
|
+
occurrences: dates.length,
|
|
20939
|
+
dates: dates.sort()
|
|
20940
|
+
})).sort((a, b) => b.occurrences - a.occurrences);
|
|
20941
|
+
}
|
|
20942
|
+
function formatPriorReadsForPrompt(priorReads) {
|
|
20943
|
+
if (priorReads.length === 0) return "";
|
|
20944
|
+
const lines = [
|
|
20945
|
+
"## Prior Radiant reads (history)",
|
|
20946
|
+
"",
|
|
20947
|
+
`Radiant has run ${priorReads.length} time${priorReads.length > 1 ? "s" : ""} before on this scope.`,
|
|
20948
|
+
"If you see patterns that appeared in prior reads, note their persistence.",
|
|
20949
|
+
"Patterns that recur across 3+ reads are strong candidates for declaration in the strategy file.",
|
|
20950
|
+
""
|
|
20951
|
+
];
|
|
20952
|
+
for (const read of priorReads.slice(-4)) {
|
|
20953
|
+
lines.push(`### Read from ${read.date}`);
|
|
20954
|
+
if (read.patternNames.length > 0) {
|
|
20955
|
+
lines.push(`Patterns observed: ${read.patternNames.join(", ")}`);
|
|
20956
|
+
} else {
|
|
20957
|
+
lines.push("No patterns extracted from frontmatter.");
|
|
20958
|
+
}
|
|
20959
|
+
lines.push("");
|
|
20960
|
+
}
|
|
20961
|
+
return lines.join("\n");
|
|
20962
|
+
}
|
|
20963
|
+
var import_fs13, import_path14;
|
|
20964
|
+
var init_palace = __esm({
|
|
20965
|
+
"src/radiant/memory/palace.ts"() {
|
|
20966
|
+
"use strict";
|
|
20967
|
+
import_fs13 = require("fs");
|
|
20968
|
+
import_path14 = require("path");
|
|
20969
|
+
}
|
|
20970
|
+
});
|
|
20971
|
+
|
|
20972
|
+
// src/radiant/core/governance.ts
|
|
20973
|
+
async function auditGovernance(events, worldPath) {
|
|
20974
|
+
let world;
|
|
20975
|
+
try {
|
|
20976
|
+
world = await loadWorld(worldPath);
|
|
20977
|
+
} catch {
|
|
20978
|
+
return emptyAudit(events.length, "Could not load compiled worldmodel for governance audit.");
|
|
20979
|
+
}
|
|
20980
|
+
const verdicts = [];
|
|
20981
|
+
for (const ce of events) {
|
|
20982
|
+
const intent = ce.event.content?.slice(0, 500) || ce.event.kind || "activity";
|
|
20983
|
+
const scope = ce.event.metadata?.scope || void 0;
|
|
20984
|
+
try {
|
|
20985
|
+
const result = evaluateGuard(
|
|
20986
|
+
{
|
|
20987
|
+
intent,
|
|
20988
|
+
scope,
|
|
20989
|
+
actionCategory: mapKindToCategory(ce.event.kind)
|
|
20990
|
+
},
|
|
20991
|
+
world
|
|
20992
|
+
);
|
|
20993
|
+
verdicts.push({
|
|
20994
|
+
eventId: ce.event.id,
|
|
20995
|
+
domain: ce.domain,
|
|
20996
|
+
status: result.status,
|
|
20997
|
+
reason: result.reason,
|
|
20998
|
+
ruleId: result.ruleId,
|
|
20999
|
+
warning: result.warning
|
|
21000
|
+
});
|
|
21001
|
+
} catch {
|
|
21002
|
+
verdicts.push({
|
|
21003
|
+
eventId: ce.event.id,
|
|
21004
|
+
domain: ce.domain,
|
|
21005
|
+
status: "ALLOW",
|
|
21006
|
+
reason: "guard evaluation skipped (error)"
|
|
21007
|
+
});
|
|
21008
|
+
}
|
|
21009
|
+
}
|
|
21010
|
+
const human = bucketVerdicts(verdicts.filter((v) => v.domain === "life"));
|
|
21011
|
+
const cyber = bucketVerdicts(verdicts.filter((v) => v.domain === "cyber"));
|
|
21012
|
+
const joint = bucketVerdicts(verdicts.filter((v) => v.domain === "joint"));
|
|
21013
|
+
const summary2 = buildSummary(human, cyber, joint, events.length);
|
|
21014
|
+
return {
|
|
21015
|
+
totalEvents: events.length,
|
|
21016
|
+
human,
|
|
21017
|
+
cyber,
|
|
21018
|
+
joint,
|
|
21019
|
+
summary: summary2
|
|
21020
|
+
};
|
|
21021
|
+
}
|
|
21022
|
+
function bucketVerdicts(verdicts) {
|
|
21023
|
+
const nonAllow = verdicts.filter((v) => v.status !== "ALLOW");
|
|
21024
|
+
return {
|
|
21025
|
+
allow: verdicts.filter((v) => v.status === "ALLOW").length,
|
|
21026
|
+
modify: verdicts.filter((v) => v.status === "MODIFY").length,
|
|
21027
|
+
block: verdicts.filter((v) => v.status === "BLOCK").length,
|
|
21028
|
+
details: nonAllow
|
|
21029
|
+
};
|
|
21030
|
+
}
|
|
21031
|
+
function buildSummary(human, cyber, joint, total) {
|
|
21032
|
+
const humanTriggered = human.modify + human.block;
|
|
21033
|
+
const cyberTriggered = cyber.modify + cyber.block;
|
|
21034
|
+
const jointTriggered = joint.modify + joint.block;
|
|
21035
|
+
const totalTriggered = humanTriggered + cyberTriggered + jointTriggered;
|
|
21036
|
+
if (totalTriggered === 0) {
|
|
21037
|
+
return `${total} events evaluated. All passed. The cocoon held \u2014 no governance triggered.`;
|
|
21038
|
+
}
|
|
21039
|
+
const parts = [];
|
|
21040
|
+
parts.push(`${total} events evaluated. ${totalTriggered} triggered governance.`);
|
|
21041
|
+
if (humanTriggered > 0) {
|
|
21042
|
+
parts.push(`Human side: ${humanTriggered} (${human.block} blocked, ${human.modify} modified).`);
|
|
21043
|
+
}
|
|
21044
|
+
if (cyberTriggered > 0) {
|
|
21045
|
+
parts.push(`AI side: ${cyberTriggered} (${cyber.block} blocked, ${cyber.modify} modified).`);
|
|
21046
|
+
}
|
|
21047
|
+
if (jointTriggered > 0) {
|
|
21048
|
+
parts.push(`Joint work: ${jointTriggered} (${joint.block} blocked, ${joint.modify} modified).`);
|
|
21049
|
+
}
|
|
21050
|
+
if (humanTriggered > 0 && cyberTriggered > 0) {
|
|
21051
|
+
const ratio = humanTriggered / cyberTriggered;
|
|
21052
|
+
if (ratio > 2) {
|
|
21053
|
+
parts.push("Human side is testing the frame more than AI. Either the worldmodel needs calibrating for human workflows, or humans are genuinely drifting.");
|
|
21054
|
+
} else if (ratio < 0.5) {
|
|
21055
|
+
parts.push("AI side is testing the frame more than humans. Check whether the AI's output patterns match the declared invariants.");
|
|
21056
|
+
} else {
|
|
21057
|
+
parts.push("Roughly balanced between human and AI \u2014 both sides are testing the frame.");
|
|
21058
|
+
}
|
|
21059
|
+
}
|
|
21060
|
+
return parts.join(" ");
|
|
21061
|
+
}
|
|
21062
|
+
function mapKindToCategory(kind) {
|
|
21063
|
+
if (!kind) return "other";
|
|
21064
|
+
if (kind.includes("commit") || kind.includes("merge")) return "write";
|
|
21065
|
+
if (kind.includes("review") || kind.includes("comment")) return "read";
|
|
21066
|
+
return "other";
|
|
21067
|
+
}
|
|
21068
|
+
function emptyAudit(total, reason) {
|
|
21069
|
+
return {
|
|
21070
|
+
totalEvents: total,
|
|
21071
|
+
human: { allow: 0, modify: 0, block: 0, details: [] },
|
|
21072
|
+
cyber: { allow: 0, modify: 0, block: 0, details: [] },
|
|
21073
|
+
joint: { allow: 0, modify: 0, block: 0, details: [] },
|
|
21074
|
+
summary: reason
|
|
21075
|
+
};
|
|
21076
|
+
}
|
|
21077
|
+
var init_governance = __esm({
|
|
21078
|
+
"src/radiant/core/governance.ts"() {
|
|
21079
|
+
"use strict";
|
|
21080
|
+
init_guard_engine();
|
|
21081
|
+
init_world_loader();
|
|
21082
|
+
}
|
|
21083
|
+
});
|
|
21084
|
+
|
|
20773
21085
|
// src/radiant/core/domain.ts
|
|
20774
21086
|
function isLifeSide(k) {
|
|
20775
21087
|
return k === "human" || k === "unknown";
|
|
@@ -21088,7 +21400,7 @@ Only recommend a move when the evidence actually calls for one.
|
|
|
21088
21400
|
}
|
|
21089
21401
|
],
|
|
21090
21402
|
"meaning": "3-5 sentences. Weave the patterns into ONE strategic thesis. Compress. The reader should finish this paragraph and understand the one thing that matters most in this read. Plain English \u2014 no system jargon.",
|
|
21091
|
-
"move": "1-3 direct imperatives, OR explicit 'nothing to act on' if the read is healthy. Do not fabricate urgency.
|
|
21403
|
+
"move": "1-3 direct imperatives, OR explicit 'nothing to act on' if the read is healthy. Do not fabricate urgency. When a candidate pattern has high confidence (>0.6), tell the reader EXACTLY where to declare it: 'If you want Radiant to track [pattern_name] over time, add it to auki-strategy.worldmodel.md under Evolution Layer \u2192 Drift Behaviors (or Aligned Behaviors if it is positive). If you don't, Radiant will rediscover it from scratch next run.' Be specific about the file and section \u2014 don't make them guess."
|
|
21092
21404
|
}
|
|
21093
21405
|
\`\`\`
|
|
21094
21406
|
|
|
@@ -21249,6 +21561,27 @@ Lens: ${input.lens.name}`
|
|
|
21249
21561
|
` Composite: ${formatScore(input.scores.R)}`
|
|
21250
21562
|
].join("\n");
|
|
21251
21563
|
sections.push(alignBlock);
|
|
21564
|
+
if (input.governance && input.governance.totalEvents > 0) {
|
|
21565
|
+
const gov = input.governance;
|
|
21566
|
+
const govLines = ["GOVERNANCE", "", ` ${gov.summary}`];
|
|
21567
|
+
const showSide = (label, side) => {
|
|
21568
|
+
if (side.allow + side.modify + side.block === 0) return;
|
|
21569
|
+
govLines.push("");
|
|
21570
|
+
govLines.push(` ${label}:`);
|
|
21571
|
+
govLines.push(` ${side.allow} ALLOW \xB7 ${side.modify} MODIFY \xB7 ${side.block} BLOCK`);
|
|
21572
|
+
for (const d of side.details.slice(0, 3)) {
|
|
21573
|
+
const reason = d.reason ? ` \u2192 ${d.reason}` : "";
|
|
21574
|
+
govLines.push(` ${d.status}: ${d.eventId}${reason}`);
|
|
21575
|
+
}
|
|
21576
|
+
if (side.details.length > 3) {
|
|
21577
|
+
govLines.push(` ... and ${side.details.length - 3} more`);
|
|
21578
|
+
}
|
|
21579
|
+
};
|
|
21580
|
+
showSide("Human side", gov.human);
|
|
21581
|
+
showSide("AI side", gov.cyber);
|
|
21582
|
+
showSide("Human\u2013AI joint", gov.joint);
|
|
21583
|
+
sections.push(govLines.join("\n"));
|
|
21584
|
+
}
|
|
21252
21585
|
sections.push(renderDepth(input.priorReadCount ?? 0, input.windowDays));
|
|
21253
21586
|
return sections.join("\n\n");
|
|
21254
21587
|
}
|
|
@@ -21425,10 +21758,15 @@ async function emergent(input) {
|
|
|
21425
21758
|
const windowDays = input.windowDays ?? 14;
|
|
21426
21759
|
let statedIntent;
|
|
21427
21760
|
let exocortexContext;
|
|
21761
|
+
let priorReadContext = "";
|
|
21428
21762
|
if (input.exocortexPath) {
|
|
21429
21763
|
exocortexContext = readExocortex(input.exocortexPath);
|
|
21430
21764
|
const formatted = formatExocortexForPrompt(exocortexContext);
|
|
21431
21765
|
if (formatted) statedIntent = formatted;
|
|
21766
|
+
const priorReads = loadPriorReads(input.exocortexPath);
|
|
21767
|
+
if (priorReads.length > 0) {
|
|
21768
|
+
priorReadContext = formatPriorReadsForPrompt(priorReads);
|
|
21769
|
+
}
|
|
21432
21770
|
}
|
|
21433
21771
|
const events = await fetchGitHubActivity(input.scope, input.githubToken, {
|
|
21434
21772
|
windowDays
|
|
@@ -21443,11 +21781,18 @@ async function emergent(input) {
|
|
|
21443
21781
|
lens,
|
|
21444
21782
|
ai: input.ai,
|
|
21445
21783
|
canonicalPatterns: input.canonicalPatterns,
|
|
21446
|
-
statedIntent
|
|
21784
|
+
statedIntent: statedIntent ? statedIntent + (priorReadContext ? "\n\n" + priorReadContext : "") : priorReadContext || void 0
|
|
21447
21785
|
});
|
|
21448
21786
|
const rewrittenPatterns = patterns.map((p) => lens.rewrite(p));
|
|
21449
21787
|
const allDescriptions = rewrittenPatterns.map((p) => p.description).join("\n");
|
|
21450
21788
|
const voiceViolations = checkForbiddenPhrases(lens, allDescriptions);
|
|
21789
|
+
let governance;
|
|
21790
|
+
if (input.worldPath) {
|
|
21791
|
+
try {
|
|
21792
|
+
governance = await auditGovernance(classified, input.worldPath);
|
|
21793
|
+
} catch {
|
|
21794
|
+
}
|
|
21795
|
+
}
|
|
21451
21796
|
const rendered = render({
|
|
21452
21797
|
scope: input.scope,
|
|
21453
21798
|
windowDays,
|
|
@@ -21457,8 +21802,27 @@ async function emergent(input) {
|
|
|
21457
21802
|
scores,
|
|
21458
21803
|
lens,
|
|
21459
21804
|
meaning: meaning || void 0,
|
|
21460
|
-
move: move || void 0
|
|
21805
|
+
move: move || void 0,
|
|
21806
|
+
governance
|
|
21461
21807
|
});
|
|
21808
|
+
if (input.exocortexPath) {
|
|
21809
|
+
try {
|
|
21810
|
+
const readPath = writeRead(input.exocortexPath, rendered.frontmatter, rendered.text);
|
|
21811
|
+
const priorReads = loadPriorReads(input.exocortexPath);
|
|
21812
|
+
const currentPatternNames = rewrittenPatterns.map((p) => p.name);
|
|
21813
|
+
const persistence = computePersistence(priorReads, currentPatternNames);
|
|
21814
|
+
const triggeredItems = governance ? [
|
|
21815
|
+
...governance.human.details.map((d) => d.ruleId).filter(Boolean),
|
|
21816
|
+
...governance.cyber.details.map((d) => d.ruleId).filter(Boolean),
|
|
21817
|
+
...governance.joint.details.map((d) => d.ruleId).filter(Boolean)
|
|
21818
|
+
] : [];
|
|
21819
|
+
updateKnowledge(input.exocortexPath, persistence, {
|
|
21820
|
+
triggeredItems,
|
|
21821
|
+
totalReads: priorReads.length + 1
|
|
21822
|
+
});
|
|
21823
|
+
} catch {
|
|
21824
|
+
}
|
|
21825
|
+
}
|
|
21462
21826
|
return {
|
|
21463
21827
|
text: rendered.text,
|
|
21464
21828
|
frontmatter: rendered.frontmatter,
|
|
@@ -21522,6 +21886,8 @@ var init_emergent = __esm({
|
|
|
21522
21886
|
init_lenses();
|
|
21523
21887
|
init_github2();
|
|
21524
21888
|
init_exocortex();
|
|
21889
|
+
init_palace();
|
|
21890
|
+
init_governance();
|
|
21525
21891
|
init_signals();
|
|
21526
21892
|
init_math();
|
|
21527
21893
|
init_patterns();
|
|
@@ -21570,6 +21936,277 @@ var init_ai = __esm({
|
|
|
21570
21936
|
}
|
|
21571
21937
|
});
|
|
21572
21938
|
|
|
21939
|
+
// src/radiant/mcp/server.ts
|
|
21940
|
+
var server_exports = {};
|
|
21941
|
+
__export(server_exports, {
|
|
21942
|
+
RadiantMcpServer: () => RadiantMcpServer,
|
|
21943
|
+
startRadiantMcp: () => startRadiantMcp
|
|
21944
|
+
});
|
|
21945
|
+
function loadWorldmodelContent(worldsPath) {
|
|
21946
|
+
const resolved = (0, import_path15.resolve)(worldsPath);
|
|
21947
|
+
if (!(0, import_fs14.existsSync)(resolved)) {
|
|
21948
|
+
throw new Error(`Worlds path not found: ${resolved}`);
|
|
21949
|
+
}
|
|
21950
|
+
const stat = (0, import_fs14.statSync)(resolved);
|
|
21951
|
+
if (stat.isFile()) {
|
|
21952
|
+
return (0, import_fs14.readFileSync)(resolved, "utf-8");
|
|
21953
|
+
}
|
|
21954
|
+
if (stat.isDirectory()) {
|
|
21955
|
+
const files = (0, import_fs14.readdirSync)(resolved).filter(
|
|
21956
|
+
(f) => (0, import_path15.extname)(f) === ".md" && (f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md"))
|
|
21957
|
+
).sort();
|
|
21958
|
+
if (files.length === 0) {
|
|
21959
|
+
throw new Error(`No worldmodel files found in ${resolved}`);
|
|
21960
|
+
}
|
|
21961
|
+
return files.map((f) => (0, import_fs14.readFileSync)((0, import_path15.join)(resolved, f), "utf-8")).join("\n\n---\n\n");
|
|
21962
|
+
}
|
|
21963
|
+
throw new Error(`Worlds path is neither a file nor directory: ${resolved}`);
|
|
21964
|
+
}
|
|
21965
|
+
async function startRadiantMcp(args) {
|
|
21966
|
+
function parseArg3(flag) {
|
|
21967
|
+
const idx = args.indexOf(flag);
|
|
21968
|
+
return idx >= 0 && idx + 1 < args.length ? args[idx + 1] : void 0;
|
|
21969
|
+
}
|
|
21970
|
+
const worldsPath = parseArg3("--worlds") ?? process.env.RADIANT_WORLDS;
|
|
21971
|
+
const lensId = parseArg3("--lens") ?? process.env.RADIANT_LENS ?? "auki-builder";
|
|
21972
|
+
const model = parseArg3("--model") ?? process.env.RADIANT_MODEL;
|
|
21973
|
+
if (!worldsPath) {
|
|
21974
|
+
process.stderr.write("Error: --worlds <dir> or RADIANT_WORLDS required.\n");
|
|
21975
|
+
process.exit(1);
|
|
21976
|
+
}
|
|
21977
|
+
const server = new RadiantMcpServer({ worldsPath, lensId, model });
|
|
21978
|
+
await server.start();
|
|
21979
|
+
}
|
|
21980
|
+
var import_fs14, import_path15, TOOLS, RadiantMcpServer;
|
|
21981
|
+
var init_server = __esm({
|
|
21982
|
+
"src/radiant/mcp/server.ts"() {
|
|
21983
|
+
"use strict";
|
|
21984
|
+
import_fs14 = require("fs");
|
|
21985
|
+
import_path15 = require("path");
|
|
21986
|
+
init_think();
|
|
21987
|
+
init_emergent();
|
|
21988
|
+
init_ai();
|
|
21989
|
+
init_scopes();
|
|
21990
|
+
TOOLS = [
|
|
21991
|
+
{
|
|
21992
|
+
name: "radiant_think",
|
|
21993
|
+
description: "Send a query through the loaded worldmodel + rendering lens and get an Auki-framed response. Use this for strategic questions, decision evaluation, or any question that should be interpreted through the organization's behavioral model.",
|
|
21994
|
+
inputSchema: {
|
|
21995
|
+
type: "object",
|
|
21996
|
+
properties: {
|
|
21997
|
+
query: {
|
|
21998
|
+
type: "string",
|
|
21999
|
+
description: "The question or prompt to interpret through the worldmodel + lens."
|
|
22000
|
+
}
|
|
22001
|
+
},
|
|
22002
|
+
required: ["query"]
|
|
22003
|
+
}
|
|
22004
|
+
},
|
|
22005
|
+
{
|
|
22006
|
+
name: "radiant_emergent",
|
|
22007
|
+
description: "Run a behavioral read on a GitHub repository. Fetches recent activity, classifies events, extracts signals, identifies patterns, computes alignment scores, and produces the EMERGENT / MEANING / MOVE / ALIGNMENT output. Use this when asked about team activity, coordination patterns, or alignment with the worldmodel.",
|
|
22008
|
+
inputSchema: {
|
|
22009
|
+
type: "object",
|
|
22010
|
+
properties: {
|
|
22011
|
+
scope: {
|
|
22012
|
+
type: "string",
|
|
22013
|
+
description: 'GitHub repository in "owner/repo" format (e.g. "aukiverse/posemesh").'
|
|
22014
|
+
},
|
|
22015
|
+
exocortex_dir: {
|
|
22016
|
+
type: "string",
|
|
22017
|
+
description: "Optional path to an exocortex directory for stated-intent-vs-observed-behavior comparison."
|
|
22018
|
+
}
|
|
22019
|
+
},
|
|
22020
|
+
required: ["scope"]
|
|
22021
|
+
}
|
|
22022
|
+
}
|
|
22023
|
+
];
|
|
22024
|
+
RadiantMcpServer = class {
|
|
22025
|
+
config;
|
|
22026
|
+
worldmodelContent;
|
|
22027
|
+
buffer = "";
|
|
22028
|
+
constructor(config) {
|
|
22029
|
+
this.config = config;
|
|
22030
|
+
this.worldmodelContent = loadWorldmodelContent(config.worldsPath);
|
|
22031
|
+
}
|
|
22032
|
+
async start() {
|
|
22033
|
+
process.stderr.write(
|
|
22034
|
+
`Radiant MCP server starting
|
|
22035
|
+
Worlds: ${this.config.worldsPath}
|
|
22036
|
+
Lens: ${this.config.lensId}
|
|
22037
|
+
Tools: radiant_think, radiant_emergent
|
|
22038
|
+
`
|
|
22039
|
+
);
|
|
22040
|
+
process.stdin.setEncoding("utf-8");
|
|
22041
|
+
process.stdin.on("data", (chunk) => {
|
|
22042
|
+
this.buffer += chunk;
|
|
22043
|
+
this.processBuffer();
|
|
22044
|
+
});
|
|
22045
|
+
process.stdin.on("end", () => {
|
|
22046
|
+
process.exit(0);
|
|
22047
|
+
});
|
|
22048
|
+
}
|
|
22049
|
+
processBuffer() {
|
|
22050
|
+
const lines = this.buffer.split("\n");
|
|
22051
|
+
this.buffer = lines.pop() ?? "";
|
|
22052
|
+
for (const line of lines) {
|
|
22053
|
+
const trimmed = line.trim();
|
|
22054
|
+
if (!trimmed) continue;
|
|
22055
|
+
try {
|
|
22056
|
+
const request = JSON.parse(trimmed);
|
|
22057
|
+
this.handleRequest(request).catch((err) => {
|
|
22058
|
+
this.sendError(request.id, -32603, String(err));
|
|
22059
|
+
});
|
|
22060
|
+
} catch {
|
|
22061
|
+
}
|
|
22062
|
+
}
|
|
22063
|
+
}
|
|
22064
|
+
async handleRequest(req) {
|
|
22065
|
+
switch (req.method) {
|
|
22066
|
+
case "initialize":
|
|
22067
|
+
this.sendResult(req.id, {
|
|
22068
|
+
protocolVersion: "2024-11-05",
|
|
22069
|
+
capabilities: { tools: {} },
|
|
22070
|
+
serverInfo: {
|
|
22071
|
+
name: "radiant",
|
|
22072
|
+
version: "0.6.1"
|
|
22073
|
+
}
|
|
22074
|
+
});
|
|
22075
|
+
break;
|
|
22076
|
+
case "notifications/initialized":
|
|
22077
|
+
break;
|
|
22078
|
+
case "tools/list":
|
|
22079
|
+
this.sendResult(req.id, { tools: TOOLS });
|
|
22080
|
+
break;
|
|
22081
|
+
case "tools/call":
|
|
22082
|
+
await this.handleToolCall(req);
|
|
22083
|
+
break;
|
|
22084
|
+
default:
|
|
22085
|
+
this.sendError(req.id, -32601, `Unknown method: ${req.method}`);
|
|
22086
|
+
}
|
|
22087
|
+
}
|
|
22088
|
+
async handleToolCall(req) {
|
|
22089
|
+
const params = req.params;
|
|
22090
|
+
if (!params?.name) {
|
|
22091
|
+
this.sendError(req.id, -32602, "Missing tool name");
|
|
22092
|
+
return;
|
|
22093
|
+
}
|
|
22094
|
+
const args = params.arguments ?? {};
|
|
22095
|
+
try {
|
|
22096
|
+
switch (params.name) {
|
|
22097
|
+
case "radiant_think":
|
|
22098
|
+
await this.handleThink(req.id, args);
|
|
22099
|
+
break;
|
|
22100
|
+
case "radiant_emergent":
|
|
22101
|
+
await this.handleEmergent(req.id, args);
|
|
22102
|
+
break;
|
|
22103
|
+
default:
|
|
22104
|
+
this.sendError(req.id, -32602, `Unknown tool: ${params.name}`);
|
|
22105
|
+
}
|
|
22106
|
+
} catch (err) {
|
|
22107
|
+
this.sendResult(req.id, {
|
|
22108
|
+
content: [{ type: "text", text: `Error: ${err}` }],
|
|
22109
|
+
isError: true
|
|
22110
|
+
});
|
|
22111
|
+
}
|
|
22112
|
+
}
|
|
22113
|
+
async handleThink(id, args) {
|
|
22114
|
+
const query = String(args.query ?? "");
|
|
22115
|
+
if (!query) {
|
|
22116
|
+
this.sendResult(id, {
|
|
22117
|
+
content: [{ type: "text", text: "Error: query is required" }],
|
|
22118
|
+
isError: true
|
|
22119
|
+
});
|
|
22120
|
+
return;
|
|
22121
|
+
}
|
|
22122
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
22123
|
+
if (!apiKey) {
|
|
22124
|
+
this.sendResult(id, {
|
|
22125
|
+
content: [{ type: "text", text: "Error: ANTHROPIC_API_KEY not set" }],
|
|
22126
|
+
isError: true
|
|
22127
|
+
});
|
|
22128
|
+
return;
|
|
22129
|
+
}
|
|
22130
|
+
const ai = createAnthropicAI(apiKey, this.config.model || void 0);
|
|
22131
|
+
const result = await think({
|
|
22132
|
+
worldmodelContent: this.worldmodelContent,
|
|
22133
|
+
lensId: this.config.lensId,
|
|
22134
|
+
query,
|
|
22135
|
+
ai
|
|
22136
|
+
});
|
|
22137
|
+
let text = result.response;
|
|
22138
|
+
if (!result.voiceClean) {
|
|
22139
|
+
text += `
|
|
22140
|
+
|
|
22141
|
+
\u26A0 Voice violations detected: ${result.voiceViolations.map((v) => v.phrase).join(", ")}`;
|
|
22142
|
+
}
|
|
22143
|
+
this.sendResult(id, {
|
|
22144
|
+
content: [{ type: "text", text }]
|
|
22145
|
+
});
|
|
22146
|
+
}
|
|
22147
|
+
async handleEmergent(id, args) {
|
|
22148
|
+
const scopeStr = String(args.scope ?? "");
|
|
22149
|
+
if (!scopeStr) {
|
|
22150
|
+
this.sendResult(id, {
|
|
22151
|
+
content: [{ type: "text", text: 'Error: scope is required (e.g. "aukiverse/posemesh")' }],
|
|
22152
|
+
isError: true
|
|
22153
|
+
});
|
|
22154
|
+
return;
|
|
22155
|
+
}
|
|
22156
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
22157
|
+
const githubToken = process.env.GITHUB_TOKEN;
|
|
22158
|
+
if (!apiKey) {
|
|
22159
|
+
this.sendResult(id, {
|
|
22160
|
+
content: [{ type: "text", text: "Error: ANTHROPIC_API_KEY not set" }],
|
|
22161
|
+
isError: true
|
|
22162
|
+
});
|
|
22163
|
+
return;
|
|
22164
|
+
}
|
|
22165
|
+
if (!githubToken) {
|
|
22166
|
+
this.sendResult(id, {
|
|
22167
|
+
content: [{ type: "text", text: "Error: GITHUB_TOKEN not set" }],
|
|
22168
|
+
isError: true
|
|
22169
|
+
});
|
|
22170
|
+
return;
|
|
22171
|
+
}
|
|
22172
|
+
const scope = parseRepoScope(scopeStr);
|
|
22173
|
+
const ai = createAnthropicAI(apiKey, this.config.model || void 0);
|
|
22174
|
+
const exocortexPath = args.exocortex_dir ? String(args.exocortex_dir) : void 0;
|
|
22175
|
+
const result = await emergent({
|
|
22176
|
+
scope,
|
|
22177
|
+
githubToken,
|
|
22178
|
+
worldmodelContent: this.worldmodelContent,
|
|
22179
|
+
lensId: this.config.lensId,
|
|
22180
|
+
ai,
|
|
22181
|
+
windowDays: 14,
|
|
22182
|
+
exocortexPath
|
|
22183
|
+
});
|
|
22184
|
+
let text = result.text;
|
|
22185
|
+
if (!result.voiceClean) {
|
|
22186
|
+
text += `
|
|
22187
|
+
|
|
22188
|
+
\u26A0 Voice violations: ${result.voiceViolations.map((v) => v.phrase).join(", ")}`;
|
|
22189
|
+
}
|
|
22190
|
+
this.sendResult(id, {
|
|
22191
|
+
content: [{ type: "text", text }]
|
|
22192
|
+
});
|
|
22193
|
+
}
|
|
22194
|
+
sendResult(id, result) {
|
|
22195
|
+
const response = { jsonrpc: "2.0", id, result };
|
|
22196
|
+
process.stdout.write(JSON.stringify(response) + "\n");
|
|
22197
|
+
}
|
|
22198
|
+
sendError(id, code, message) {
|
|
22199
|
+
const response = {
|
|
22200
|
+
jsonrpc: "2.0",
|
|
22201
|
+
id: id ?? null,
|
|
22202
|
+
error: { code, message }
|
|
22203
|
+
};
|
|
22204
|
+
process.stdout.write(JSON.stringify(response) + "\n");
|
|
22205
|
+
}
|
|
22206
|
+
};
|
|
22207
|
+
}
|
|
22208
|
+
});
|
|
22209
|
+
|
|
21573
22210
|
// src/cli/radiant.ts
|
|
21574
22211
|
var radiant_exports = {};
|
|
21575
22212
|
__export(radiant_exports, {
|
|
@@ -21625,18 +22262,18 @@ function parseArgs27(argv) {
|
|
|
21625
22262
|
}
|
|
21626
22263
|
return result;
|
|
21627
22264
|
}
|
|
21628
|
-
function
|
|
21629
|
-
const resolved = (0,
|
|
21630
|
-
if (!(0,
|
|
22265
|
+
function loadWorldmodelContent2(worldsPath) {
|
|
22266
|
+
const resolved = (0, import_path16.resolve)(worldsPath);
|
|
22267
|
+
if (!(0, import_fs15.existsSync)(resolved)) {
|
|
21631
22268
|
throw new Error(`Worlds path not found: ${resolved}`);
|
|
21632
22269
|
}
|
|
21633
|
-
const stat = (0,
|
|
22270
|
+
const stat = (0, import_fs15.statSync)(resolved);
|
|
21634
22271
|
if (stat.isFile()) {
|
|
21635
|
-
return (0,
|
|
22272
|
+
return (0, import_fs15.readFileSync)(resolved, "utf-8");
|
|
21636
22273
|
}
|
|
21637
22274
|
if (stat.isDirectory()) {
|
|
21638
|
-
const files = (0,
|
|
21639
|
-
(f) => (0,
|
|
22275
|
+
const files = (0, import_fs15.readdirSync)(resolved).filter(
|
|
22276
|
+
(f) => (0, import_path16.extname)(f) === ".md" && (f.endsWith(".worldmodel.md") || f.endsWith(".nv-world.md"))
|
|
21640
22277
|
).sort();
|
|
21641
22278
|
if (files.length === 0) {
|
|
21642
22279
|
throw new Error(
|
|
@@ -21644,7 +22281,7 @@ function loadWorldmodelContent(worldsPath) {
|
|
|
21644
22281
|
);
|
|
21645
22282
|
}
|
|
21646
22283
|
return files.map((f) => {
|
|
21647
|
-
const content = (0,
|
|
22284
|
+
const content = (0, import_fs15.readFileSync)((0, import_path16.join)(resolved, f), "utf-8");
|
|
21648
22285
|
return `<!-- worldmodel: ${f} -->
|
|
21649
22286
|
${content}`;
|
|
21650
22287
|
}).join("\n\n---\n\n");
|
|
@@ -21683,7 +22320,7 @@ ${DIM3}Set it to your Anthropic API key to use Radiant's AI features.${RESET3}
|
|
|
21683
22320
|
query = args.rest.join(" ");
|
|
21684
22321
|
}
|
|
21685
22322
|
if (!query && !process.stdin.isTTY) {
|
|
21686
|
-
query = (0,
|
|
22323
|
+
query = (0, import_fs15.readFileSync)(0, "utf-8").trim();
|
|
21687
22324
|
}
|
|
21688
22325
|
if (!query) {
|
|
21689
22326
|
process.stderr.write(
|
|
@@ -21693,7 +22330,7 @@ ${DIM3}Use --query "...", pass as trailing args, or pipe via stdin.${RESET3}
|
|
|
21693
22330
|
);
|
|
21694
22331
|
process.exit(1);
|
|
21695
22332
|
}
|
|
21696
|
-
const worldmodelContent =
|
|
22333
|
+
const worldmodelContent = loadWorldmodelContent2(worldsPath);
|
|
21697
22334
|
const model = args.model ?? process.env.RADIANT_MODEL;
|
|
21698
22335
|
const ai = createAnthropicAI(apiKey, model || void 0);
|
|
21699
22336
|
process.stderr.write(
|
|
@@ -21786,7 +22423,7 @@ ${DIM3}Set it to a GitHub PAT with repo read access.${RESET3}
|
|
|
21786
22423
|
);
|
|
21787
22424
|
process.exit(1);
|
|
21788
22425
|
}
|
|
21789
|
-
const worldmodelContent =
|
|
22426
|
+
const worldmodelContent = loadWorldmodelContent2(worldsPath);
|
|
21790
22427
|
const model = args.model ?? process.env.RADIANT_MODEL;
|
|
21791
22428
|
const ai = createAnthropicAI(anthropicKey, model || void 0);
|
|
21792
22429
|
const exocortexPath = args.exocortex ?? process.env.RADIANT_EXOCORTEX;
|
|
@@ -21926,6 +22563,10 @@ async function main34(argv) {
|
|
|
21926
22563
|
return cmdLenses(args);
|
|
21927
22564
|
case "emergent":
|
|
21928
22565
|
return cmdEmergent(args);
|
|
22566
|
+
case "mcp": {
|
|
22567
|
+
const { startRadiantMcp: startRadiantMcp2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
22568
|
+
return startRadiantMcp2(argv);
|
|
22569
|
+
}
|
|
21929
22570
|
case "decision":
|
|
21930
22571
|
case "signals":
|
|
21931
22572
|
case "drift":
|
|
@@ -21946,12 +22587,12 @@ async function main34(argv) {
|
|
|
21946
22587
|
process.exit(1);
|
|
21947
22588
|
}
|
|
21948
22589
|
}
|
|
21949
|
-
var
|
|
22590
|
+
var import_fs15, import_path16, RED2, DIM3, BOLD3, YELLOW3, RESET3, USAGE10;
|
|
21950
22591
|
var init_radiant = __esm({
|
|
21951
22592
|
"src/cli/radiant.ts"() {
|
|
21952
22593
|
"use strict";
|
|
21953
|
-
|
|
21954
|
-
|
|
22594
|
+
import_fs15 = require("fs");
|
|
22595
|
+
import_path16 = require("path");
|
|
21955
22596
|
init_think();
|
|
21956
22597
|
init_emergent();
|
|
21957
22598
|
init_ai();
|