@neuroverseos/governance 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -0
- package/dist/adapters/autoresearch.d.cts +2 -1
- package/dist/adapters/autoresearch.d.ts +2 -1
- package/dist/adapters/autoresearch.js +2 -2
- package/dist/adapters/deep-agents.d.cts +3 -2
- package/dist/adapters/deep-agents.d.ts +3 -2
- package/dist/adapters/deep-agents.js +2 -2
- package/dist/adapters/express.d.cts +2 -1
- package/dist/adapters/express.d.ts +2 -1
- package/dist/adapters/express.js +2 -2
- package/dist/adapters/github.cjs +1697 -0
- package/dist/adapters/github.d.cts +225 -0
- package/dist/adapters/github.d.ts +225 -0
- package/dist/adapters/github.js +27 -0
- package/dist/adapters/index.d.cts +4 -316
- package/dist/adapters/index.d.ts +4 -316
- package/dist/adapters/index.js +23 -21
- package/dist/adapters/langchain.d.cts +3 -2
- package/dist/adapters/langchain.d.ts +3 -2
- package/dist/adapters/langchain.js +2 -2
- package/dist/adapters/mentraos.cjs +2181 -0
- package/dist/adapters/mentraos.d.cts +319 -0
- package/dist/adapters/mentraos.d.ts +319 -0
- package/dist/{mentraos-LLH7KEV4.js → adapters/mentraos.js} +12 -10
- package/dist/adapters/openai.d.cts +3 -2
- package/dist/adapters/openai.d.ts +3 -2
- package/dist/adapters/openai.js +2 -2
- package/dist/adapters/openclaw.d.cts +3 -2
- package/dist/adapters/openclaw.d.ts +3 -2
- package/dist/adapters/openclaw.js +2 -2
- package/dist/{add-LYHDZ5RL.js → add-JP7TC2K3.js} +1 -1
- package/dist/admin/index.cjs +2214 -0
- package/dist/admin/index.d.cts +362 -0
- package/dist/admin/index.d.ts +362 -0
- package/dist/admin/index.js +703 -0
- package/dist/bootstrap-contract-DcV6t-8M.d.cts +216 -0
- package/dist/bootstrap-contract-DcV6t-8M.d.ts +216 -0
- package/dist/{build-SCAWPA7E.js → build-THUEYMVT.js} +2 -2
- package/dist/{chunk-DWHUZUEY.js → chunk-5RAQ5DZW.js} +3 -3
- package/dist/{chunk-25XHSTPT.js → chunk-6UPEUMJ2.js} +3 -3
- package/dist/chunk-7UU7V3AD.js +447 -0
- package/dist/{chunk-UTH7OXTM.js → chunk-EK77AJAH.js} +22 -4
- package/dist/{chunk-BXLTEUS4.js → chunk-EQUAWNXW.js} +2 -2
- package/dist/chunk-FGOSKQDE.js +421 -0
- package/dist/{chunk-U6FRAEQJ.js → chunk-GJ6LM4JZ.js} +1 -441
- package/dist/chunk-H3REGQRI.js +107 -0
- package/dist/{chunk-5JUZ4HL7.js → chunk-LAKUB76X.js} +3 -3
- package/dist/{chunk-Y6WXAPKY.js → chunk-NTHXZAW4.js} +3 -3
- package/dist/{chunk-TD5GKIHP.js → chunk-R23T5SZG.js} +3 -3
- package/dist/{chunk-V4FZHJQX.js → chunk-RF2L5SYG.js} +3 -3
- package/dist/{chunk-YNYCQECH.js → chunk-TL4DLMMW.js} +3 -3
- package/dist/{chunk-JKGPSFGH.js → chunk-TZBERHFM.js} +3 -3
- package/dist/{chunk-MFKHTE5R.js → chunk-UZBW44KD.js} +3 -3
- package/dist/{chunk-7D7PZLB7.js → chunk-XPMZB46F.js} +3 -3
- package/dist/cli/neuroverse.cjs +1486 -321
- package/dist/cli/neuroverse.js +44 -20
- package/dist/cli/plan.js +2 -2
- package/dist/cli/run.cjs +242 -139
- package/dist/cli/run.js +23 -3
- package/dist/{demo-66MMJTEH.js → demo-N5K4VXJW.js} +4 -4
- package/dist/{derive-AUQE3L3P.js → derive-5LOMN7GO.js} +2 -2
- package/dist/{doctor-EY7LKSYY.js → doctor-Q5APJOTS.js} +3 -2
- package/dist/engine/bootstrap-emitter.cjs +241 -0
- package/dist/engine/bootstrap-emitter.d.cts +27 -0
- package/dist/engine/bootstrap-emitter.d.ts +27 -0
- package/dist/{bootstrap-emitter-GIMOJFOC.js → engine/bootstrap-emitter.js} +2 -2
- package/dist/engine/bootstrap-parser.cjs +560 -0
- package/dist/engine/bootstrap-parser.d.cts +96 -0
- package/dist/engine/bootstrap-parser.d.ts +96 -0
- package/dist/{bootstrap-parser-LBLGVEMU.js → engine/bootstrap-parser.js} +2 -2
- package/dist/engine/guard-engine.cjs +1116 -0
- package/dist/engine/guard-engine.d.cts +60 -0
- package/dist/engine/guard-engine.d.ts +60 -0
- package/dist/{guard-engine-N7TUIUU7.js → engine/guard-engine.js} +3 -3
- package/dist/engine/simulate-engine.cjs +390 -0
- package/dist/engine/simulate-engine.d.cts +105 -0
- package/dist/engine/simulate-engine.d.ts +105 -0
- package/dist/engine/simulate-engine.js +9 -0
- package/dist/{equity-penalties-WWC7UDQD.js → equity-penalties-PYCJ3Q4U.js} +6 -6
- package/dist/{explain-MUSGDT67.js → explain-42TVC3QD.js} +1 -1
- package/dist/{guard-W3BMQPBJ.js → guard-TPYDFG6V.js} +16 -4
- package/dist/{guard-contract-CLBbTGK_.d.ts → guard-contract-ddiIPlOg.d.cts} +2 -369
- package/dist/{guard-contract-CLBbTGK_.d.cts → guard-contract-q6HJAq3Q.d.ts} +2 -369
- package/dist/{improve-PJDAWW4Q.js → improve-HLZGJ54Z.js} +3 -3
- package/dist/index.cjs +471 -1
- package/dist/index.d.cts +14 -492
- package/dist/index.d.ts +14 -492
- package/dist/index.js +68 -47
- package/dist/keygen-BSZH3NM2.js +77 -0
- package/dist/{lens-IP6GIZ2Q.js → lens-NFGZHD76.js} +92 -25
- package/dist/{mcp-server-OG3PPVD2.js → mcp-server-5XXNG6VC.js} +2 -2
- package/dist/migrate-NH5PVMX4.js +221 -0
- package/dist/{playground-4BK2XQ47.js → playground-2EU5CFIH.js} +5 -5
- package/dist/{redteam-BRZALBPP.js → redteam-VK6OVHAE.js} +3 -3
- package/dist/{session-SGRUT2UH.js → session-NGA4DUPL.js} +2 -2
- package/dist/{shared-CwGpPheR.d.ts → shared-DAzdfWtU.d.ts} +1 -1
- package/dist/{shared-BGzmYP5g.d.cts → shared-PpalGKxc.d.cts} +1 -1
- package/dist/sign-RRELHKWM.js +11 -0
- package/dist/{simulate-FGXKIH7V.js → simulate-4YNOBMES.js} +2 -2
- package/dist/{test-PT44BSYG.js → test-HDBPMQTG.js} +3 -3
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +370 -0
- package/dist/types.d.ts +370 -0
- package/dist/types.js +0 -0
- package/dist/{validate-Q5O5TGLT.js → validate-6MFQZ2EG.js} +1 -1
- package/dist/verify-6AVTWX75.js +151 -0
- package/dist/{world-V52ZMH26.js → world-H5WVURKU.js} +1 -1
- package/dist/{world-loader-C4D3VPP3.js → world-loader-J47PCPDZ.js} +1 -1
- package/package.json +44 -3
- package/dist/{chunk-7QIAF377.js → chunk-CYDMUJVZ.js} +0 -0
- package/dist/{chunk-4G6WHPLI.js → chunk-QZ666FCV.js} +3 -3
- package/dist/{configure-ai-LL3VAPQW.js → configure-ai-5MP5DWTT.js} +3 -3
- package/dist/{decision-flow-3K4D72G4.js → decision-flow-IJPNMVQK.js} +3 -3
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: readFile3 } = await import("fs/promises");
|
|
2005
|
-
const { join:
|
|
2006
|
-
const { readdirSync:
|
|
2005
|
+
const { join: join13 } = await import("path");
|
|
2006
|
+
const { readdirSync: readdirSync6 } = await import("fs");
|
|
2007
2007
|
async function readJson(filename) {
|
|
2008
|
-
const filePath =
|
|
2008
|
+
const filePath = join13(dirPath, filename);
|
|
2009
2009
|
try {
|
|
2010
2010
|
const content = await readFile3(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 = join13(dirPath, "rules");
|
|
2039
|
+
const ruleFiles = readdirSync6(rulesDir).filter((f) => f.endsWith(".json")).sort();
|
|
2040
2040
|
for (const file of ruleFiles) {
|
|
2041
2041
|
try {
|
|
2042
|
-
const content = await readFile3(
|
|
2042
|
+
const content = await readFile3(join13(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: readFile3 } = await import("fs/promises");
|
|
2096
|
-
const { join:
|
|
2097
|
-
const { existsSync:
|
|
2096
|
+
const { join: join13, dirname: dirname3 } = await import("path");
|
|
2097
|
+
const { existsSync: existsSync9 } = 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 : dirname3(fileURLToPath3(import_meta.url));
|
|
2105
|
-
packageRoot =
|
|
2105
|
+
packageRoot = join13(thisFile, "..", "..");
|
|
2106
2106
|
} catch {
|
|
2107
2107
|
packageRoot = process.cwd();
|
|
2108
2108
|
}
|
|
2109
2109
|
const candidates = [
|
|
2110
|
-
|
|
2111
|
-
|
|
2110
|
+
join13(packageRoot, "dist", "worlds", filename),
|
|
2111
|
+
join13(packageRoot, "src", "worlds", filename)
|
|
2112
2112
|
];
|
|
2113
2113
|
for (const candidate of candidates) {
|
|
2114
|
-
if (
|
|
2114
|
+
if (existsSync9(candidate)) {
|
|
2115
2115
|
const markdown = await readFile3(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: readFile3, writeFile: writeFile5 } = await import("fs/promises");
|
|
2144
|
-
const { join:
|
|
2145
|
-
const guardsPath =
|
|
2144
|
+
const { join: join13 } = await import("path");
|
|
2145
|
+
const guardsPath = join13(worldDir, "guards.json");
|
|
2146
2146
|
let config;
|
|
2147
2147
|
try {
|
|
2148
2148
|
const raw = await readFile3(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: readFile3, writeFile: writeFile5, mkdir: mkdir2 } = await import("fs/promises");
|
|
2185
|
-
const { join:
|
|
2186
|
-
const { readdirSync:
|
|
2187
|
-
const rulesDir =
|
|
2185
|
+
const { join: join13 } = await import("path");
|
|
2186
|
+
const { readdirSync: readdirSync6 } = await import("fs");
|
|
2187
|
+
const rulesDir = join13(worldDir, "rules");
|
|
2188
2188
|
await mkdir2(rulesDir, { recursive: true });
|
|
2189
2189
|
let nextNum = 1;
|
|
2190
2190
|
try {
|
|
2191
|
-
const existing =
|
|
2191
|
+
const existing = readdirSync6(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 = join13(rulesDir, `rule-${ruleNum}.json`);
|
|
2218
2218
|
await writeFile5(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: readFile3, writeFile: writeFile5 } = await import("fs/promises");
|
|
2233
|
-
const { join:
|
|
2234
|
-
const invariantsPath =
|
|
2233
|
+
const { join: join13 } = await import("path");
|
|
2234
|
+
const invariantsPath = join13(worldDir, "invariants.json");
|
|
2235
2235
|
let config;
|
|
2236
2236
|
try {
|
|
2237
2237
|
const raw = await readFile3(invariantsPath, "utf-8");
|
|
@@ -2849,27 +2849,27 @@ ${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: extname2, basename:
|
|
2852
|
+
const { join: pathJoin, extname: extname2, basename: basename3 } = await import("path");
|
|
2853
2853
|
const stats = await stat(inputPath);
|
|
2854
2854
|
if (stats.isFile()) {
|
|
2855
2855
|
const content = await rf(inputPath, "utf-8");
|
|
2856
|
-
return [{ filename:
|
|
2856
|
+
return [{ filename: basename3(inputPath), content }];
|
|
2857
2857
|
}
|
|
2858
2858
|
if (stats.isDirectory()) {
|
|
2859
2859
|
const sources = [];
|
|
2860
|
-
await collectDir(inputPath, sources, rf, pathJoin, extname2,
|
|
2860
|
+
await collectDir(inputPath, sources, rf, pathJoin, extname2, basename3);
|
|
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, extname2,
|
|
2866
|
+
async function collectDir(dir, sources, rf, pathJoin, extname2, basename3) {
|
|
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, extname2,
|
|
2872
|
+
await collectDir(fullPath, sources, rf, pathJoin, extname2, basename3);
|
|
2873
2873
|
} else if (entry.isFile() && extname2(entry.name).toLowerCase() === ".md") {
|
|
2874
2874
|
const content = await rf(fullPath, "utf-8");
|
|
2875
2875
|
sources.push({ filename: entry.name, content });
|
|
@@ -3528,21 +3528,21 @@ function parseArgs2(argv) {
|
|
|
3528
3528
|
}
|
|
3529
3529
|
async function writeWorldFiles(outputDir, world) {
|
|
3530
3530
|
const { writeFile: writeFile5, mkdir: mkdir2 } = await import("fs/promises");
|
|
3531
|
-
const { join:
|
|
3531
|
+
const { join: join13 } = await import("path");
|
|
3532
3532
|
await mkdir2(outputDir, { recursive: true });
|
|
3533
|
-
await writeFile5(
|
|
3534
|
-
await writeFile5(
|
|
3535
|
-
await writeFile5(
|
|
3536
|
-
await writeFile5(
|
|
3537
|
-
await writeFile5(
|
|
3538
|
-
await writeFile5(
|
|
3539
|
-
await writeFile5(
|
|
3540
|
-
const rulesDir =
|
|
3533
|
+
await writeFile5(join13(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
|
|
3534
|
+
await writeFile5(join13(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
|
|
3535
|
+
await writeFile5(join13(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
|
|
3536
|
+
await writeFile5(join13(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
|
|
3537
|
+
await writeFile5(join13(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
|
|
3538
|
+
await writeFile5(join13(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
|
|
3539
|
+
await writeFile5(join13(outputDir, "metadata.json"), JSON.stringify(world.metadata, null, 2));
|
|
3540
|
+
const rulesDir = join13(outputDir, "rules");
|
|
3541
3541
|
await mkdir2(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 writeFile5(
|
|
3545
|
+
await writeFile5(join13(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
|
|
3546
3546
|
}
|
|
3547
3547
|
}
|
|
3548
3548
|
function write(msg) {
|
|
@@ -3557,12 +3557,12 @@ function printInsight(finding2) {
|
|
|
3557
3557
|
async function main2(argv = process.argv.slice(2)) {
|
|
3558
3558
|
try {
|
|
3559
3559
|
const args = parseArgs2(argv);
|
|
3560
|
-
const { basename:
|
|
3560
|
+
const { basename: basename3 } = await import("path");
|
|
3561
3561
|
write(`
|
|
3562
3562
|
NeuroVerse World Builder
|
|
3563
3563
|
`);
|
|
3564
3564
|
write(`
|
|
3565
|
-
Analyzing: ${
|
|
3565
|
+
Analyzing: ${basename3(args.inputPath)}
|
|
3566
3566
|
`);
|
|
3567
3567
|
const derivedPath = args.outputDir ? `${args.outputDir}/source.nv-world.md` : ".neuroverse/build-output.nv-world.md";
|
|
3568
3568
|
const { mkdir: mkdir2 } = await import("fs/promises");
|
|
@@ -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: join13 } = await import("path");
|
|
3677
3677
|
const { copyFile } = await import("fs/promises");
|
|
3678
|
-
const sourceDest =
|
|
3678
|
+
const sourceDest = join13(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: writeFile5 } = await import("fs/promises");
|
|
5012
|
-
const { existsSync:
|
|
5013
|
-
if (
|
|
5012
|
+
const { existsSync: existsSync9 } = await import("fs");
|
|
5013
|
+
if (existsSync9(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: writeFile5, mkdir: mkdir2 } = await import("fs/promises");
|
|
5871
|
-
const { join:
|
|
5871
|
+
const { join: join13 } = await import("path");
|
|
5872
5872
|
await mkdir2(outputDir, { recursive: true });
|
|
5873
|
-
await writeFile5(
|
|
5874
|
-
await writeFile5(
|
|
5875
|
-
await writeFile5(
|
|
5876
|
-
await writeFile5(
|
|
5877
|
-
const rulesDir =
|
|
5873
|
+
await writeFile5(join13(outputDir, "world.json"), JSON.stringify(world.world, null, 2));
|
|
5874
|
+
await writeFile5(join13(outputDir, "invariants.json"), JSON.stringify({ invariants: world.invariants }, null, 2));
|
|
5875
|
+
await writeFile5(join13(outputDir, "assumptions.json"), JSON.stringify(world.assumptions, null, 2));
|
|
5876
|
+
await writeFile5(join13(outputDir, "state-schema.json"), JSON.stringify(world.stateSchema, null, 2));
|
|
5877
|
+
const rulesDir = join13(outputDir, "rules");
|
|
5878
5878
|
await mkdir2(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 writeFile5(
|
|
5882
|
+
await writeFile5(join13(rulesDir, `rule-${ruleNum}.json`), JSON.stringify(sortedRules[i], null, 2));
|
|
5883
5883
|
}
|
|
5884
|
-
await writeFile5(
|
|
5885
|
-
await writeFile5(
|
|
5886
|
-
await writeFile5(
|
|
5884
|
+
await writeFile5(join13(outputDir, "gates.json"), JSON.stringify(world.gates, null, 2));
|
|
5885
|
+
await writeFile5(join13(outputDir, "outcomes.json"), JSON.stringify(world.outcomes, null, 2));
|
|
5886
|
+
await writeFile5(join13(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();
|
|
@@ -7364,6 +7364,162 @@ var init_guard_contract = __esm({
|
|
|
7364
7364
|
}
|
|
7365
7365
|
});
|
|
7366
7366
|
|
|
7367
|
+
// src/engine/audit-logger.ts
|
|
7368
|
+
function verdictToAuditEvent(event, verdict) {
|
|
7369
|
+
const auditEvent = {
|
|
7370
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7371
|
+
worldId: verdict.evidence.worldId,
|
|
7372
|
+
worldName: verdict.evidence.worldName,
|
|
7373
|
+
worldVersion: verdict.evidence.worldVersion,
|
|
7374
|
+
intent: event.intent,
|
|
7375
|
+
tool: event.tool,
|
|
7376
|
+
scope: event.scope,
|
|
7377
|
+
actor: event.roleId,
|
|
7378
|
+
direction: event.direction,
|
|
7379
|
+
decision: verdict.status,
|
|
7380
|
+
reason: verdict.reason,
|
|
7381
|
+
ruleId: verdict.ruleId,
|
|
7382
|
+
warning: verdict.warning,
|
|
7383
|
+
guardsMatched: verdict.evidence.guardsMatched,
|
|
7384
|
+
rulesMatched: verdict.evidence.rulesMatched,
|
|
7385
|
+
invariantsSatisfied: verdict.evidence.invariantsSatisfied,
|
|
7386
|
+
invariantsTotal: verdict.evidence.invariantsTotal,
|
|
7387
|
+
enforcementLevel: verdict.evidence.enforcementLevel,
|
|
7388
|
+
durationMs: verdict.trace?.durationMs,
|
|
7389
|
+
args: event.args
|
|
7390
|
+
};
|
|
7391
|
+
if (verdict.consequence) {
|
|
7392
|
+
auditEvent.consequence = verdict.consequence;
|
|
7393
|
+
}
|
|
7394
|
+
if (verdict.reward) {
|
|
7395
|
+
auditEvent.reward = verdict.reward;
|
|
7396
|
+
}
|
|
7397
|
+
if (verdict.intentRecord) {
|
|
7398
|
+
auditEvent.originalIntent = verdict.intentRecord.originalIntent;
|
|
7399
|
+
auditEvent.finalAction = verdict.intentRecord.finalAction;
|
|
7400
|
+
}
|
|
7401
|
+
return auditEvent;
|
|
7402
|
+
}
|
|
7403
|
+
async function readAuditLog(logPath, filter) {
|
|
7404
|
+
const { readFile: readFile3 } = await import("fs/promises");
|
|
7405
|
+
let content;
|
|
7406
|
+
try {
|
|
7407
|
+
content = await readFile3(logPath, "utf-8");
|
|
7408
|
+
} catch {
|
|
7409
|
+
return [];
|
|
7410
|
+
}
|
|
7411
|
+
const events = [];
|
|
7412
|
+
for (const line of content.split("\n")) {
|
|
7413
|
+
const trimmed = line.trim();
|
|
7414
|
+
if (!trimmed) continue;
|
|
7415
|
+
try {
|
|
7416
|
+
const event = JSON.parse(trimmed);
|
|
7417
|
+
if (!filter || filter(event)) {
|
|
7418
|
+
events.push(event);
|
|
7419
|
+
}
|
|
7420
|
+
} catch {
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
return events;
|
|
7424
|
+
}
|
|
7425
|
+
function summarizeAuditEvents(events) {
|
|
7426
|
+
const allowed = events.filter((e) => e.decision === "ALLOW").length;
|
|
7427
|
+
const blocked = events.filter((e) => e.decision === "BLOCK").length;
|
|
7428
|
+
const paused = events.filter((e) => e.decision === "PAUSE").length;
|
|
7429
|
+
const modified = events.filter((e) => e.decision === "MODIFY").length;
|
|
7430
|
+
const penalized = events.filter((e) => e.decision === "PENALIZE").length;
|
|
7431
|
+
const rewarded = events.filter((e) => e.decision === "REWARD").length;
|
|
7432
|
+
const neutral = events.filter((e) => e.decision === "NEUTRAL").length;
|
|
7433
|
+
const actorSet = /* @__PURE__ */ new Set();
|
|
7434
|
+
for (const e of events) {
|
|
7435
|
+
if (e.actor) actorSet.add(e.actor);
|
|
7436
|
+
}
|
|
7437
|
+
const intentMap = /* @__PURE__ */ new Map();
|
|
7438
|
+
for (const e of events) {
|
|
7439
|
+
const entry = intentMap.get(e.intent) ?? { count: 0, blocked: 0, paused: 0, penalized: 0, rewarded: 0 };
|
|
7440
|
+
entry.count++;
|
|
7441
|
+
if (e.decision === "BLOCK") entry.blocked++;
|
|
7442
|
+
if (e.decision === "PAUSE") entry.paused++;
|
|
7443
|
+
if (e.decision === "PENALIZE") entry.penalized++;
|
|
7444
|
+
if (e.decision === "REWARD") entry.rewarded++;
|
|
7445
|
+
intentMap.set(e.intent, entry);
|
|
7446
|
+
}
|
|
7447
|
+
const topIntents = [...intentMap.entries()].map(([intent, data]) => ({ intent, ...data })).sort((a, b) => b.count - a.count);
|
|
7448
|
+
const ruleMap = /* @__PURE__ */ new Map();
|
|
7449
|
+
for (const e of events) {
|
|
7450
|
+
if (e.ruleId) {
|
|
7451
|
+
ruleMap.set(e.ruleId, (ruleMap.get(e.ruleId) ?? 0) + 1);
|
|
7452
|
+
}
|
|
7453
|
+
for (const g of e.guardsMatched) {
|
|
7454
|
+
ruleMap.set(g, (ruleMap.get(g) ?? 0) + 1);
|
|
7455
|
+
}
|
|
7456
|
+
}
|
|
7457
|
+
const topRules = [...ruleMap.entries()].map(([ruleId, count]) => ({ ruleId, count })).sort((a, b) => b.count - a.count);
|
|
7458
|
+
const redirected = blocked + paused + modified + penalized;
|
|
7459
|
+
const total = events.length;
|
|
7460
|
+
return {
|
|
7461
|
+
totalActions: total,
|
|
7462
|
+
allowed,
|
|
7463
|
+
blocked,
|
|
7464
|
+
paused,
|
|
7465
|
+
modified,
|
|
7466
|
+
penalized,
|
|
7467
|
+
rewarded,
|
|
7468
|
+
neutral,
|
|
7469
|
+
actors: [...actorSet],
|
|
7470
|
+
topIntents,
|
|
7471
|
+
topRules,
|
|
7472
|
+
firstEvent: events[0]?.timestamp ?? "",
|
|
7473
|
+
lastEvent: events[events.length - 1]?.timestamp ?? "",
|
|
7474
|
+
behavioralEconomy: {
|
|
7475
|
+
totalPenalties: penalized,
|
|
7476
|
+
totalRewards: rewarded,
|
|
7477
|
+
netPressure: rewarded - penalized,
|
|
7478
|
+
redirectionRate: total > 0 ? redirected / total : 0
|
|
7479
|
+
}
|
|
7480
|
+
};
|
|
7481
|
+
}
|
|
7482
|
+
var FileAuditLogger;
|
|
7483
|
+
var init_audit_logger = __esm({
|
|
7484
|
+
"src/engine/audit-logger.ts"() {
|
|
7485
|
+
"use strict";
|
|
7486
|
+
init_guard_engine();
|
|
7487
|
+
FileAuditLogger = class {
|
|
7488
|
+
logPath;
|
|
7489
|
+
buffer = [];
|
|
7490
|
+
flushTimer = null;
|
|
7491
|
+
flushIntervalMs;
|
|
7492
|
+
constructor(logPath, options) {
|
|
7493
|
+
this.logPath = logPath;
|
|
7494
|
+
this.flushIntervalMs = options?.flushIntervalMs ?? 1e3;
|
|
7495
|
+
}
|
|
7496
|
+
log(event) {
|
|
7497
|
+
this.buffer.push(JSON.stringify(event));
|
|
7498
|
+
if (!this.flushTimer) {
|
|
7499
|
+
this.flushTimer = setTimeout(() => {
|
|
7500
|
+
void this.flush();
|
|
7501
|
+
}, this.flushIntervalMs);
|
|
7502
|
+
}
|
|
7503
|
+
}
|
|
7504
|
+
async flush() {
|
|
7505
|
+
if (this.buffer.length === 0) return;
|
|
7506
|
+
if (this.flushTimer) {
|
|
7507
|
+
clearTimeout(this.flushTimer);
|
|
7508
|
+
this.flushTimer = null;
|
|
7509
|
+
}
|
|
7510
|
+
const lines = this.buffer.splice(0).join("\n") + "\n";
|
|
7511
|
+
try {
|
|
7512
|
+
const { appendFile, mkdir: mkdir2 } = await import("fs/promises");
|
|
7513
|
+
const { dirname: dirname3 } = await import("path");
|
|
7514
|
+
await mkdir2(dirname3(this.logPath), { recursive: true });
|
|
7515
|
+
await appendFile(this.logPath, lines, "utf-8");
|
|
7516
|
+
} catch {
|
|
7517
|
+
}
|
|
7518
|
+
}
|
|
7519
|
+
};
|
|
7520
|
+
}
|
|
7521
|
+
});
|
|
7522
|
+
|
|
7367
7523
|
// src/cli/guard.ts
|
|
7368
7524
|
var guard_exports = {};
|
|
7369
7525
|
__export(guard_exports, {
|
|
@@ -7374,6 +7530,7 @@ function parseArgs11(argv) {
|
|
|
7374
7530
|
let trace = false;
|
|
7375
7531
|
let level;
|
|
7376
7532
|
let aiClassify = false;
|
|
7533
|
+
let logPath;
|
|
7377
7534
|
for (let i = 0; i < argv.length; i++) {
|
|
7378
7535
|
const arg = argv[i];
|
|
7379
7536
|
if (arg === "--world" && i + 1 < argv.length) {
|
|
@@ -7382,6 +7539,8 @@ function parseArgs11(argv) {
|
|
|
7382
7539
|
trace = true;
|
|
7383
7540
|
} else if (arg === "--ai-classify") {
|
|
7384
7541
|
aiClassify = true;
|
|
7542
|
+
} else if (arg === "--log" && i + 1 < argv.length) {
|
|
7543
|
+
logPath = argv[++i];
|
|
7385
7544
|
} else if (arg === "--level" && i + 1 < argv.length) {
|
|
7386
7545
|
const val = argv[++i];
|
|
7387
7546
|
if (val === "basic" || val === "standard" || val === "strict") {
|
|
@@ -7391,7 +7550,7 @@ function parseArgs11(argv) {
|
|
|
7391
7550
|
}
|
|
7392
7551
|
}
|
|
7393
7552
|
}
|
|
7394
|
-
return { worldPath, trace, level, aiClassify };
|
|
7553
|
+
return { worldPath, trace, level, aiClassify, logPath };
|
|
7395
7554
|
}
|
|
7396
7555
|
async function main11(argv = process.argv.slice(2)) {
|
|
7397
7556
|
try {
|
|
@@ -7451,6 +7610,11 @@ async function main11(argv = process.argv.slice(2)) {
|
|
|
7451
7610
|
const options = { trace: args.trace, level: args.level };
|
|
7452
7611
|
verdict = evaluateGuard(event, world, options);
|
|
7453
7612
|
}
|
|
7613
|
+
if (args.logPath) {
|
|
7614
|
+
const logger = new FileAuditLogger(args.logPath, { flushIntervalMs: 0 });
|
|
7615
|
+
logger.log(verdictToAuditEvent(event, verdict));
|
|
7616
|
+
await logger.flush();
|
|
7617
|
+
}
|
|
7454
7618
|
process.stdout.write(JSON.stringify(verdict, null, 2) + "\n");
|
|
7455
7619
|
const exitCode = GUARD_EXIT_CODES[verdict.status];
|
|
7456
7620
|
process.exit(exitCode);
|
|
@@ -7479,6 +7643,7 @@ var init_guard = __esm({
|
|
|
7479
7643
|
init_world_resolver();
|
|
7480
7644
|
init_guard_contract();
|
|
7481
7645
|
init_cli_utils();
|
|
7646
|
+
init_audit_logger();
|
|
7482
7647
|
}
|
|
7483
7648
|
});
|
|
7484
7649
|
|
|
@@ -8077,13 +8242,13 @@ function handleHealthCheck() {
|
|
|
8077
8242
|
}
|
|
8078
8243
|
async function handleListPresets(policiesDir) {
|
|
8079
8244
|
const { readdir, readFile: readFile3 } = await import("fs/promises");
|
|
8080
|
-
const { join:
|
|
8081
|
-
const dir = policiesDir ??
|
|
8245
|
+
const { join: join13 } = await import("path");
|
|
8246
|
+
const dir = policiesDir ?? join13(process.cwd(), "policies");
|
|
8082
8247
|
const presets = [];
|
|
8083
8248
|
try {
|
|
8084
8249
|
const files = await readdir(dir);
|
|
8085
8250
|
for (const file of files.filter((f) => f.endsWith(".txt")).sort()) {
|
|
8086
|
-
const content = await readFile3(
|
|
8251
|
+
const content = await readFile3(join13(dir, file), "utf-8");
|
|
8087
8252
|
const id = file.replace(".txt", "");
|
|
8088
8253
|
const name = id.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
8089
8254
|
const firstLine = content.split("\n").find((l) => l.trim().length > 0) ?? "";
|
|
@@ -8155,7 +8320,7 @@ function govern(action, world, options) {
|
|
|
8155
8320
|
}
|
|
8156
8321
|
async function writeTempWorld(dir, policyLines) {
|
|
8157
8322
|
const { writeFile: writeFile5, mkdir: mkdir2 } = await import("fs/promises");
|
|
8158
|
-
const { join:
|
|
8323
|
+
const { join: join13 } = await import("path");
|
|
8159
8324
|
await mkdir2(dir, { recursive: true });
|
|
8160
8325
|
const worldJson = {
|
|
8161
8326
|
world_id: "demo-live",
|
|
@@ -8197,9 +8362,9 @@ async function writeTempWorld(dir, policyLines) {
|
|
|
8197
8362
|
authoring_method: "manual-authoring"
|
|
8198
8363
|
};
|
|
8199
8364
|
await Promise.all([
|
|
8200
|
-
writeFile5(
|
|
8201
|
-
writeFile5(
|
|
8202
|
-
writeFile5(
|
|
8365
|
+
writeFile5(join13(dir, "world.json"), JSON.stringify(worldJson, null, 2)),
|
|
8366
|
+
writeFile5(join13(dir, "kernel.json"), JSON.stringify(kernelJson, null, 2)),
|
|
8367
|
+
writeFile5(join13(dir, "metadata.json"), JSON.stringify(metadataJson, null, 2))
|
|
8203
8368
|
]);
|
|
8204
8369
|
}
|
|
8205
8370
|
var init_govern = __esm({
|
|
@@ -9544,82 +9709,501 @@ var init_express = __esm({
|
|
|
9544
9709
|
}
|
|
9545
9710
|
});
|
|
9546
9711
|
|
|
9547
|
-
// src/adapters/
|
|
9548
|
-
var
|
|
9549
|
-
__export(
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9712
|
+
// src/adapters/github.ts
|
|
9713
|
+
var github_exports = {};
|
|
9714
|
+
__export(github_exports, {
|
|
9715
|
+
GitHubGovernanceBlockedError: () => GitHubGovernanceBlockedError,
|
|
9716
|
+
GitHubGovernor: () => GitHubGovernor,
|
|
9717
|
+
GitHubWebhookHandler: () => GitHubWebhookHandler,
|
|
9718
|
+
createGitHubGovernor: () => createGitHubGovernor,
|
|
9719
|
+
createGitHubGovernorFromWorld: () => createGitHubGovernorFromWorld,
|
|
9720
|
+
createGitHubWebhookHandler: () => createGitHubWebhookHandler,
|
|
9721
|
+
createGitHubWebhookHandlerFromWorld: () => createGitHubWebhookHandlerFromWorld,
|
|
9722
|
+
formatForActions: () => formatForActions,
|
|
9723
|
+
formatPRComment: () => formatPRComment
|
|
9554
9724
|
});
|
|
9555
|
-
function
|
|
9725
|
+
function extractBranch(ref) {
|
|
9726
|
+
if (!ref) return void 0;
|
|
9727
|
+
if (ref.startsWith("refs/heads/")) return ref.slice("refs/heads/".length);
|
|
9728
|
+
if (ref.startsWith("refs/tags/")) return ref.slice("refs/tags/".length);
|
|
9729
|
+
return ref;
|
|
9730
|
+
}
|
|
9731
|
+
function isProtectedBranch(branch, protectedBranches) {
|
|
9732
|
+
if (!branch) return false;
|
|
9733
|
+
return protectedBranches.some(
|
|
9734
|
+
(pb) => branch === pb || branch.startsWith(`${pb}/`)
|
|
9735
|
+
);
|
|
9736
|
+
}
|
|
9737
|
+
function defaultMapAction(action, protectedBranches, restrictedActors) {
|
|
9738
|
+
const branch = action.branch ?? extractBranch(action.ref);
|
|
9739
|
+
const isProtected = isProtectedBranch(branch, protectedBranches);
|
|
9740
|
+
const isRestricted = action.actor ? restrictedActors.some((ra) => action.actor === ra || action.actor?.endsWith("[bot]")) : false;
|
|
9741
|
+
let actionCategory = "other";
|
|
9742
|
+
const act = action.action.toLowerCase();
|
|
9743
|
+
if (act.includes("read") || act.includes("get") || act.includes("list") || act.includes("view")) {
|
|
9744
|
+
actionCategory = "read";
|
|
9745
|
+
} else if (act.includes("delete") || act.includes("remove") || act.includes("close")) {
|
|
9746
|
+
actionCategory = "delete";
|
|
9747
|
+
} else if (act.includes("deploy") || act.includes("run") || act.includes("execute") || act.includes("merge")) {
|
|
9748
|
+
actionCategory = "network";
|
|
9749
|
+
} else if (act.includes("create") || act.includes("push") || act.includes("write") || act.includes("update") || act.includes("edit")) {
|
|
9750
|
+
actionCategory = "write";
|
|
9751
|
+
} else if (act.includes("comment") || act.includes("review") || act.includes("notify")) {
|
|
9752
|
+
actionCategory = "other";
|
|
9753
|
+
}
|
|
9556
9754
|
return {
|
|
9557
|
-
intent:
|
|
9558
|
-
tool:
|
|
9559
|
-
scope:
|
|
9560
|
-
|
|
9561
|
-
direction: "input"
|
|
9755
|
+
intent: action.action,
|
|
9756
|
+
tool: "github",
|
|
9757
|
+
scope: `${action.repository}${branch ? `@${branch}` : ""}`,
|
|
9758
|
+
actionCategory,
|
|
9759
|
+
direction: "input",
|
|
9760
|
+
args: {
|
|
9761
|
+
repository: action.repository,
|
|
9762
|
+
ref: action.ref,
|
|
9763
|
+
branch,
|
|
9764
|
+
actor: action.actor,
|
|
9765
|
+
protected_branch: isProtected,
|
|
9766
|
+
restricted_actor: isRestricted,
|
|
9767
|
+
...action.metadata
|
|
9768
|
+
}
|
|
9562
9769
|
};
|
|
9563
9770
|
}
|
|
9564
|
-
|
|
9771
|
+
function defaultMapWebhook(eventType, payload) {
|
|
9772
|
+
const repo = payload.repository;
|
|
9773
|
+
const repoFullName = repo?.full_name ?? "unknown/unknown";
|
|
9774
|
+
const sender = payload.sender;
|
|
9775
|
+
const actor = sender?.login ?? void 0;
|
|
9776
|
+
const webhookAction = payload.action;
|
|
9777
|
+
switch (eventType) {
|
|
9778
|
+
case "push": {
|
|
9779
|
+
const ref = payload.ref;
|
|
9780
|
+
const branch = extractBranch(ref);
|
|
9781
|
+
const forced = payload.forced;
|
|
9782
|
+
return {
|
|
9783
|
+
action: forced ? "force_push" : `push_to_${branch ?? "branch"}`,
|
|
9784
|
+
repository: repoFullName,
|
|
9785
|
+
ref,
|
|
9786
|
+
branch,
|
|
9787
|
+
actor,
|
|
9788
|
+
metadata: {
|
|
9789
|
+
forced: forced ?? false,
|
|
9790
|
+
commits_count: payload.commits?.length ?? 0,
|
|
9791
|
+
head_commit: payload.head_commit?.id
|
|
9792
|
+
}
|
|
9793
|
+
};
|
|
9794
|
+
}
|
|
9795
|
+
case "pull_request": {
|
|
9796
|
+
const pr = payload.pull_request;
|
|
9797
|
+
const base = pr?.base;
|
|
9798
|
+
const baseBranch = base?.ref;
|
|
9799
|
+
const prNumber = pr?.number;
|
|
9800
|
+
const merged = pr?.merged;
|
|
9801
|
+
const labels = pr?.labels?.map((l) => l.name) ?? [];
|
|
9802
|
+
let action = `pull_request_${webhookAction ?? "unknown"}`;
|
|
9803
|
+
if (webhookAction === "closed" && merged) {
|
|
9804
|
+
action = "merge_pull_request";
|
|
9805
|
+
}
|
|
9806
|
+
return {
|
|
9807
|
+
action,
|
|
9808
|
+
repository: repoFullName,
|
|
9809
|
+
branch: baseBranch,
|
|
9810
|
+
actor,
|
|
9811
|
+
metadata: {
|
|
9812
|
+
pr_number: prNumber,
|
|
9813
|
+
labels,
|
|
9814
|
+
merged: merged ?? false,
|
|
9815
|
+
draft: pr?.draft ?? false,
|
|
9816
|
+
webhook_action: webhookAction
|
|
9817
|
+
}
|
|
9818
|
+
};
|
|
9819
|
+
}
|
|
9820
|
+
case "release": {
|
|
9821
|
+
const release = payload.release;
|
|
9822
|
+
return {
|
|
9823
|
+
action: `release_${webhookAction ?? "published"}`,
|
|
9824
|
+
repository: repoFullName,
|
|
9825
|
+
ref: release?.tag_name ? `refs/tags/${release.tag_name}` : void 0,
|
|
9826
|
+
actor,
|
|
9827
|
+
metadata: {
|
|
9828
|
+
tag: release?.tag_name,
|
|
9829
|
+
prerelease: release?.prerelease ?? false,
|
|
9830
|
+
draft: release?.draft ?? false,
|
|
9831
|
+
webhook_action: webhookAction
|
|
9832
|
+
}
|
|
9833
|
+
};
|
|
9834
|
+
}
|
|
9835
|
+
case "deployment":
|
|
9836
|
+
case "deployment_status": {
|
|
9837
|
+
const deployment = payload.deployment ?? payload;
|
|
9838
|
+
return {
|
|
9839
|
+
action: eventType === "deployment" ? "create_deployment" : "deployment_status_update",
|
|
9840
|
+
repository: repoFullName,
|
|
9841
|
+
ref: deployment.ref,
|
|
9842
|
+
actor,
|
|
9843
|
+
metadata: {
|
|
9844
|
+
environment: deployment.environment,
|
|
9845
|
+
status: payload.deployment_status?.state,
|
|
9846
|
+
webhook_action: webhookAction
|
|
9847
|
+
}
|
|
9848
|
+
};
|
|
9849
|
+
}
|
|
9850
|
+
case "workflow_run": {
|
|
9851
|
+
const run = payload.workflow_run;
|
|
9852
|
+
return {
|
|
9853
|
+
action: `workflow_${webhookAction ?? "completed"}`,
|
|
9854
|
+
repository: repoFullName,
|
|
9855
|
+
branch: run?.head_branch,
|
|
9856
|
+
actor,
|
|
9857
|
+
metadata: {
|
|
9858
|
+
workflow_name: run?.name,
|
|
9859
|
+
conclusion: run?.conclusion,
|
|
9860
|
+
status: run?.status,
|
|
9861
|
+
webhook_action: webhookAction
|
|
9862
|
+
}
|
|
9863
|
+
};
|
|
9864
|
+
}
|
|
9865
|
+
case "issues": {
|
|
9866
|
+
const issue = payload.issue;
|
|
9867
|
+
return {
|
|
9868
|
+
action: `issue_${webhookAction ?? "opened"}`,
|
|
9869
|
+
repository: repoFullName,
|
|
9870
|
+
actor,
|
|
9871
|
+
metadata: {
|
|
9872
|
+
issue_number: issue?.number,
|
|
9873
|
+
labels: issue?.labels?.map((l) => l.name) ?? [],
|
|
9874
|
+
webhook_action: webhookAction
|
|
9875
|
+
}
|
|
9876
|
+
};
|
|
9877
|
+
}
|
|
9878
|
+
case "issue_comment": {
|
|
9879
|
+
return {
|
|
9880
|
+
action: `issue_comment_${webhookAction ?? "created"}`,
|
|
9881
|
+
repository: repoFullName,
|
|
9882
|
+
actor,
|
|
9883
|
+
metadata: {
|
|
9884
|
+
issue_number: payload.issue?.number,
|
|
9885
|
+
webhook_action: webhookAction
|
|
9886
|
+
}
|
|
9887
|
+
};
|
|
9888
|
+
}
|
|
9889
|
+
case "delete": {
|
|
9890
|
+
return {
|
|
9891
|
+
action: `delete_${payload.ref_type ?? "ref"}`,
|
|
9892
|
+
repository: repoFullName,
|
|
9893
|
+
ref: payload.ref,
|
|
9894
|
+
actor,
|
|
9895
|
+
metadata: {
|
|
9896
|
+
ref_type: payload.ref_type
|
|
9897
|
+
}
|
|
9898
|
+
};
|
|
9899
|
+
}
|
|
9900
|
+
default: {
|
|
9901
|
+
return {
|
|
9902
|
+
action: webhookAction ? `${eventType}_${webhookAction}` : eventType,
|
|
9903
|
+
repository: repoFullName,
|
|
9904
|
+
actor,
|
|
9905
|
+
metadata: { webhook_action: webhookAction }
|
|
9906
|
+
};
|
|
9907
|
+
}
|
|
9908
|
+
}
|
|
9909
|
+
}
|
|
9910
|
+
function formatForActions(verdict) {
|
|
9911
|
+
const status = verdict.status === "ALLOW" ? "allowed" : verdict.status === "BLOCK" ? "blocked" : "paused";
|
|
9912
|
+
const reason = verdict.reason ?? "";
|
|
9913
|
+
const ruleId = verdict.ruleId ?? "";
|
|
9914
|
+
const lines = [
|
|
9915
|
+
`governance_status=${status}`,
|
|
9916
|
+
`verdict_status=${verdict.status}`,
|
|
9917
|
+
`reason=${reason}`,
|
|
9918
|
+
`rule_id=${ruleId}`
|
|
9919
|
+
].join("\n");
|
|
9920
|
+
return {
|
|
9921
|
+
governance_status: status,
|
|
9922
|
+
verdict_status: verdict.status,
|
|
9923
|
+
reason,
|
|
9924
|
+
rule_id: ruleId,
|
|
9925
|
+
outputLines: lines
|
|
9926
|
+
};
|
|
9927
|
+
}
|
|
9928
|
+
function formatPRComment(verdict, action) {
|
|
9929
|
+
const icon = verdict.status === "ALLOW" ? "\u2705" : verdict.status === "BLOCK" ? "\u{1F6AB}" : "\u23F8\uFE0F";
|
|
9930
|
+
const status = verdict.status;
|
|
9931
|
+
let body = `## ${icon} Governance: ${status}
|
|
9932
|
+
|
|
9933
|
+
`;
|
|
9934
|
+
body += `**Action:** \`${action.action}\`
|
|
9935
|
+
`;
|
|
9936
|
+
body += `**Repository:** \`${action.repository}\`
|
|
9937
|
+
`;
|
|
9938
|
+
if (action.branch) {
|
|
9939
|
+
body += `**Branch:** \`${action.branch}\`
|
|
9940
|
+
`;
|
|
9941
|
+
}
|
|
9942
|
+
if (action.actor) {
|
|
9943
|
+
body += `**Actor:** \`${action.actor}\`
|
|
9944
|
+
`;
|
|
9945
|
+
}
|
|
9946
|
+
body += "\n";
|
|
9947
|
+
if (verdict.reason) {
|
|
9948
|
+
body += `**Reason:** ${verdict.reason}
|
|
9949
|
+
`;
|
|
9950
|
+
}
|
|
9951
|
+
if (verdict.ruleId) {
|
|
9952
|
+
body += `**Rule:** \`${verdict.ruleId}\`
|
|
9953
|
+
`;
|
|
9954
|
+
}
|
|
9955
|
+
if (verdict.evidence?.invariantsSatisfied < verdict.evidence?.invariantsTotal) {
|
|
9956
|
+
body += `**Invariants:** ${verdict.evidence.invariantsSatisfied}/${verdict.evidence.invariantsTotal} satisfied
|
|
9957
|
+
`;
|
|
9958
|
+
}
|
|
9959
|
+
body += "\n---\n*Evaluated by [NeuroVerse Governance](https://github.com/NeuroverseOS/neuroverseos-governance)*";
|
|
9960
|
+
return body;
|
|
9961
|
+
}
|
|
9962
|
+
async function createGitHubGovernor(worldPath, options) {
|
|
9565
9963
|
const world = await loadWorld(worldPath);
|
|
9566
|
-
return new
|
|
9964
|
+
return new GitHubGovernor(world, options);
|
|
9567
9965
|
}
|
|
9568
|
-
function
|
|
9569
|
-
return new
|
|
9966
|
+
function createGitHubGovernorFromWorld(world, options) {
|
|
9967
|
+
return new GitHubGovernor(world, options);
|
|
9570
9968
|
}
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9969
|
+
async function createGitHubWebhookHandler(worldPath, options) {
|
|
9970
|
+
const world = await loadWorld(worldPath);
|
|
9971
|
+
return new GitHubWebhookHandler(world, options);
|
|
9972
|
+
}
|
|
9973
|
+
function createGitHubWebhookHandlerFromWorld(world, options) {
|
|
9974
|
+
return new GitHubWebhookHandler(world, options);
|
|
9975
|
+
}
|
|
9976
|
+
var GitHubGovernanceBlockedError, GitHubGovernor, GitHubWebhookHandler;
|
|
9977
|
+
var init_github = __esm({
|
|
9978
|
+
"src/adapters/github.ts"() {
|
|
9574
9979
|
"use strict";
|
|
9575
9980
|
init_guard_engine();
|
|
9576
9981
|
init_world_loader();
|
|
9577
9982
|
init_shared();
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
constructor(verdict,
|
|
9581
|
-
super(verdict);
|
|
9582
|
-
this.
|
|
9983
|
+
GitHubGovernanceBlockedError = class extends GovernanceBlockedError {
|
|
9984
|
+
action;
|
|
9985
|
+
constructor(verdict, action) {
|
|
9986
|
+
super(verdict, `[NeuroVerse] GitHub action blocked: ${action.action} on ${action.repository}`);
|
|
9987
|
+
this.name = "GitHubGovernanceBlockedError";
|
|
9988
|
+
this.action = action;
|
|
9583
9989
|
}
|
|
9584
9990
|
};
|
|
9585
|
-
|
|
9586
|
-
name = "NeuroVerseGovernance";
|
|
9991
|
+
GitHubGovernor = class {
|
|
9587
9992
|
world;
|
|
9588
9993
|
options;
|
|
9589
9994
|
engineOptions;
|
|
9590
|
-
mapToolCall;
|
|
9591
9995
|
activePlan;
|
|
9996
|
+
protectedBranches;
|
|
9997
|
+
restrictedActors;
|
|
9998
|
+
mapFn;
|
|
9592
9999
|
constructor(world, options = {}) {
|
|
9593
10000
|
this.world = world;
|
|
9594
10001
|
this.options = options;
|
|
9595
10002
|
this.activePlan = options.plan;
|
|
9596
10003
|
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
9597
|
-
this.
|
|
10004
|
+
this.protectedBranches = options.protectedBranches ?? ["main", "master", "production"];
|
|
10005
|
+
this.restrictedActors = options.restrictedActors ?? [];
|
|
10006
|
+
this.mapFn = options.mapAction ?? ((action) => defaultMapAction(action, this.protectedBranches, this.restrictedActors));
|
|
9598
10007
|
}
|
|
9599
10008
|
/**
|
|
9600
|
-
*
|
|
9601
|
-
*
|
|
9602
|
-
*
|
|
9603
|
-
* @throws GovernanceBlockedError if the action is BLOCKED
|
|
9604
|
-
* @throws GovernanceBlockedError if the action is PAUSED and onPause returns false
|
|
10009
|
+
* Evaluate a GitHub action against governance rules.
|
|
10010
|
+
* Returns a full result with verdict, event, and the original action.
|
|
9605
10011
|
*/
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
try {
|
|
9609
|
-
parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
9610
|
-
} catch {
|
|
9611
|
-
parsedInput = { raw: input };
|
|
9612
|
-
}
|
|
9613
|
-
const event = this.mapToolCall(tool.name, parsedInput);
|
|
10012
|
+
evaluate(action) {
|
|
10013
|
+
const event = this.mapFn(action);
|
|
9614
10014
|
this.engineOptions.plan = this.activePlan;
|
|
9615
10015
|
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
9616
|
-
this.options.onEvaluate?.(verdict, event);
|
|
9617
|
-
if (verdict.status === "
|
|
9618
|
-
this.options
|
|
9619
|
-
throw new GovernanceBlockedError3(verdict, event);
|
|
10016
|
+
this.options.onEvaluate?.(verdict, event, action);
|
|
10017
|
+
if (verdict.status === "ALLOW") {
|
|
10018
|
+
trackPlanProgress(event, this, this.options);
|
|
9620
10019
|
}
|
|
9621
|
-
|
|
9622
|
-
|
|
10020
|
+
return { verdict, event, action };
|
|
10021
|
+
}
|
|
10022
|
+
/**
|
|
10023
|
+
* Evaluate and enforce — throws GitHubGovernanceBlockedError on BLOCK/PAUSE.
|
|
10024
|
+
* Use this as a gate before executing GitHub API calls.
|
|
10025
|
+
*/
|
|
10026
|
+
enforce(action) {
|
|
10027
|
+
const result = this.evaluate(action);
|
|
10028
|
+
if (result.verdict.status === "BLOCK" || result.verdict.status === "PAUSE") {
|
|
10029
|
+
throw new GitHubGovernanceBlockedError(result.verdict, action);
|
|
10030
|
+
}
|
|
10031
|
+
return result;
|
|
10032
|
+
}
|
|
10033
|
+
/**
|
|
10034
|
+
* Check if pushing to a branch is allowed.
|
|
10035
|
+
* Convenience method for the most common governance check.
|
|
10036
|
+
*/
|
|
10037
|
+
canPush(repository, branch, actor) {
|
|
10038
|
+
return this.evaluate({
|
|
10039
|
+
action: `push_to_${branch}`,
|
|
10040
|
+
repository,
|
|
10041
|
+
ref: `refs/heads/${branch}`,
|
|
10042
|
+
branch,
|
|
10043
|
+
actor
|
|
10044
|
+
}).verdict;
|
|
10045
|
+
}
|
|
10046
|
+
/**
|
|
10047
|
+
* Check if merging a PR is allowed.
|
|
10048
|
+
*/
|
|
10049
|
+
canMerge(repository, targetBranch, prNumber, actor, labels) {
|
|
10050
|
+
return this.evaluate({
|
|
10051
|
+
action: "merge_pull_request",
|
|
10052
|
+
repository,
|
|
10053
|
+
branch: targetBranch,
|
|
10054
|
+
actor,
|
|
10055
|
+
metadata: { pr_number: prNumber, labels: labels ?? [] }
|
|
10056
|
+
}).verdict;
|
|
10057
|
+
}
|
|
10058
|
+
/**
|
|
10059
|
+
* Check if creating a release is allowed.
|
|
10060
|
+
*/
|
|
10061
|
+
canRelease(repository, tag, actor, prerelease) {
|
|
10062
|
+
return this.evaluate({
|
|
10063
|
+
action: "release_published",
|
|
10064
|
+
repository,
|
|
10065
|
+
ref: `refs/tags/${tag}`,
|
|
10066
|
+
actor,
|
|
10067
|
+
metadata: { tag, prerelease: prerelease ?? false }
|
|
10068
|
+
}).verdict;
|
|
10069
|
+
}
|
|
10070
|
+
/**
|
|
10071
|
+
* Check if deploying to an environment is allowed.
|
|
10072
|
+
*/
|
|
10073
|
+
canDeploy(repository, environment, ref, actor) {
|
|
10074
|
+
return this.evaluate({
|
|
10075
|
+
action: "create_deployment",
|
|
10076
|
+
repository,
|
|
10077
|
+
ref,
|
|
10078
|
+
actor,
|
|
10079
|
+
metadata: { environment }
|
|
10080
|
+
}).verdict;
|
|
10081
|
+
}
|
|
10082
|
+
};
|
|
10083
|
+
GitHubWebhookHandler = class {
|
|
10084
|
+
governor;
|
|
10085
|
+
mapWebhookFn;
|
|
10086
|
+
webhookSecret;
|
|
10087
|
+
constructor(world, options = {}) {
|
|
10088
|
+
this.governor = new GitHubGovernor(world, options);
|
|
10089
|
+
this.mapWebhookFn = options.mapWebhook ?? defaultMapWebhook;
|
|
10090
|
+
this.webhookSecret = options.webhookSecret;
|
|
10091
|
+
}
|
|
10092
|
+
/**
|
|
10093
|
+
* Evaluate a webhook payload.
|
|
10094
|
+
*
|
|
10095
|
+
* @param eventType - The X-GitHub-Event header value
|
|
10096
|
+
* @param payload - The parsed webhook body
|
|
10097
|
+
*/
|
|
10098
|
+
evaluate(eventType, payload) {
|
|
10099
|
+
const action = this.mapWebhookFn(eventType, payload);
|
|
10100
|
+
const result = this.governor.evaluate(action);
|
|
10101
|
+
return {
|
|
10102
|
+
verdict: result.verdict,
|
|
10103
|
+
event: result.event,
|
|
10104
|
+
webhookEvent: eventType,
|
|
10105
|
+
webhookAction: payload.action
|
|
10106
|
+
};
|
|
10107
|
+
}
|
|
10108
|
+
/**
|
|
10109
|
+
* Evaluate and enforce — throws on BLOCK/PAUSE.
|
|
10110
|
+
*/
|
|
10111
|
+
enforce(eventType, payload) {
|
|
10112
|
+
const result = this.evaluate(eventType, payload);
|
|
10113
|
+
if (result.verdict.status === "BLOCK" || result.verdict.status === "PAUSE") {
|
|
10114
|
+
const action = this.mapWebhookFn(eventType, payload);
|
|
10115
|
+
throw new GitHubGovernanceBlockedError(result.verdict, action);
|
|
10116
|
+
}
|
|
10117
|
+
return result;
|
|
10118
|
+
}
|
|
10119
|
+
/** Access the underlying governor for direct action evaluation. */
|
|
10120
|
+
getGovernor() {
|
|
10121
|
+
return this.governor;
|
|
10122
|
+
}
|
|
10123
|
+
/** Get the configured webhook secret (for signature verification in your server). */
|
|
10124
|
+
getWebhookSecret() {
|
|
10125
|
+
return this.webhookSecret;
|
|
10126
|
+
}
|
|
10127
|
+
};
|
|
10128
|
+
}
|
|
10129
|
+
});
|
|
10130
|
+
|
|
10131
|
+
// src/adapters/langchain.ts
|
|
10132
|
+
var langchain_exports = {};
|
|
10133
|
+
__export(langchain_exports, {
|
|
10134
|
+
GovernanceBlockedError: () => GovernanceBlockedError3,
|
|
10135
|
+
NeuroVerseCallbackHandler: () => NeuroVerseCallbackHandler,
|
|
10136
|
+
createNeuroVerseCallbackHandler: () => createNeuroVerseCallbackHandler,
|
|
10137
|
+
createNeuroVerseCallbackHandlerFromWorld: () => createNeuroVerseCallbackHandlerFromWorld
|
|
10138
|
+
});
|
|
10139
|
+
function defaultMapToolCall2(toolName, toolInput) {
|
|
10140
|
+
return {
|
|
10141
|
+
intent: toolName,
|
|
10142
|
+
tool: toolName,
|
|
10143
|
+
scope: extractScope(toolInput),
|
|
10144
|
+
args: toolInput,
|
|
10145
|
+
direction: "input"
|
|
10146
|
+
};
|
|
10147
|
+
}
|
|
10148
|
+
async function createNeuroVerseCallbackHandler(worldPath, options) {
|
|
10149
|
+
const world = await loadWorld(worldPath);
|
|
10150
|
+
return new NeuroVerseCallbackHandler(world, options);
|
|
10151
|
+
}
|
|
10152
|
+
function createNeuroVerseCallbackHandlerFromWorld(world, options) {
|
|
10153
|
+
return new NeuroVerseCallbackHandler(world, options);
|
|
10154
|
+
}
|
|
10155
|
+
var GovernanceBlockedError3, NeuroVerseCallbackHandler;
|
|
10156
|
+
var init_langchain = __esm({
|
|
10157
|
+
"src/adapters/langchain.ts"() {
|
|
10158
|
+
"use strict";
|
|
10159
|
+
init_guard_engine();
|
|
10160
|
+
init_world_loader();
|
|
10161
|
+
init_shared();
|
|
10162
|
+
GovernanceBlockedError3 = class extends GovernanceBlockedError {
|
|
10163
|
+
event;
|
|
10164
|
+
constructor(verdict, event) {
|
|
10165
|
+
super(verdict);
|
|
10166
|
+
this.event = event;
|
|
10167
|
+
}
|
|
10168
|
+
};
|
|
10169
|
+
NeuroVerseCallbackHandler = class {
|
|
10170
|
+
name = "NeuroVerseGovernance";
|
|
10171
|
+
world;
|
|
10172
|
+
options;
|
|
10173
|
+
engineOptions;
|
|
10174
|
+
mapToolCall;
|
|
10175
|
+
activePlan;
|
|
10176
|
+
constructor(world, options = {}) {
|
|
10177
|
+
this.world = world;
|
|
10178
|
+
this.options = options;
|
|
10179
|
+
this.activePlan = options.plan;
|
|
10180
|
+
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
10181
|
+
this.mapToolCall = options.mapToolCall ?? defaultMapToolCall2;
|
|
10182
|
+
}
|
|
10183
|
+
/**
|
|
10184
|
+
* Called before a tool is executed.
|
|
10185
|
+
* Evaluates the tool call against the governance world.
|
|
10186
|
+
*
|
|
10187
|
+
* @throws GovernanceBlockedError if the action is BLOCKED
|
|
10188
|
+
* @throws GovernanceBlockedError if the action is PAUSED and onPause returns false
|
|
10189
|
+
*/
|
|
10190
|
+
async handleToolStart(tool, input) {
|
|
10191
|
+
let parsedInput;
|
|
10192
|
+
try {
|
|
10193
|
+
parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
10194
|
+
} catch {
|
|
10195
|
+
parsedInput = { raw: input };
|
|
10196
|
+
}
|
|
10197
|
+
const event = this.mapToolCall(tool.name, parsedInput);
|
|
10198
|
+
this.engineOptions.plan = this.activePlan;
|
|
10199
|
+
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
10200
|
+
this.options.onEvaluate?.(verdict, event);
|
|
10201
|
+
if (verdict.status === "BLOCK") {
|
|
10202
|
+
this.options.onBlock?.(verdict, event);
|
|
10203
|
+
throw new GovernanceBlockedError3(verdict, event);
|
|
10204
|
+
}
|
|
10205
|
+
if (verdict.status === "PAUSE") {
|
|
10206
|
+
const approved = await this.options.onPause?.(verdict, event);
|
|
9623
10207
|
if (!approved) {
|
|
9624
10208
|
throw new GovernanceBlockedError3(verdict, event);
|
|
9625
10209
|
}
|
|
@@ -9755,7 +10339,7 @@ __export(openclaw_exports, {
|
|
|
9755
10339
|
createNeuroVersePlugin: () => createNeuroVersePlugin,
|
|
9756
10340
|
createNeuroVersePluginFromWorld: () => createNeuroVersePluginFromWorld
|
|
9757
10341
|
});
|
|
9758
|
-
function
|
|
10342
|
+
function defaultMapAction2(action, direction) {
|
|
9759
10343
|
return {
|
|
9760
10344
|
intent: action.type,
|
|
9761
10345
|
tool: action.tool ?? action.type,
|
|
@@ -9797,7 +10381,7 @@ var init_openclaw = __esm({
|
|
|
9797
10381
|
this.options = options;
|
|
9798
10382
|
this.activePlan = options.plan;
|
|
9799
10383
|
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
9800
|
-
this.mapAction = options.mapAction ??
|
|
10384
|
+
this.mapAction = options.mapAction ?? defaultMapAction2;
|
|
9801
10385
|
}
|
|
9802
10386
|
/**
|
|
9803
10387
|
* Evaluate an action before execution.
|
|
@@ -10827,6 +11411,7 @@ var init_ = __esm({
|
|
|
10827
11411
|
"../adapters/autoresearch.ts": () => Promise.resolve().then(() => (init_autoresearch(), autoresearch_exports)),
|
|
10828
11412
|
"../adapters/deep-agents.ts": () => Promise.resolve().then(() => (init_deep_agents(), deep_agents_exports)),
|
|
10829
11413
|
"../adapters/express.ts": () => Promise.resolve().then(() => (init_express(), express_exports)),
|
|
11414
|
+
"../adapters/github.ts": () => Promise.resolve().then(() => (init_github(), github_exports)),
|
|
10830
11415
|
"../adapters/index.ts": () => Promise.resolve().then(() => (init_adapters(), adapters_exports)),
|
|
10831
11416
|
"../adapters/langchain.ts": () => Promise.resolve().then(() => (init_langchain(), langchain_exports)),
|
|
10832
11417
|
"../adapters/mentraos.ts": () => Promise.resolve().then(() => (init_mentraos(), mentraos_exports)),
|
|
@@ -10890,9 +11475,9 @@ async function main15(argv) {
|
|
|
10890
11475
|
}
|
|
10891
11476
|
if (worldPath) {
|
|
10892
11477
|
try {
|
|
10893
|
-
const { existsSync:
|
|
10894
|
-
const { join:
|
|
10895
|
-
const hasWorld =
|
|
11478
|
+
const { existsSync: existsSync9 } = await import("fs");
|
|
11479
|
+
const { join: join13 } = await import("path");
|
|
11480
|
+
const hasWorld = existsSync9(join13(worldPath, "world.json"));
|
|
10896
11481
|
checks.push({
|
|
10897
11482
|
label: "World file detected",
|
|
10898
11483
|
status: hasWorld ? "pass" : "fail",
|
|
@@ -10907,12 +11492,12 @@ async function main15(argv) {
|
|
|
10907
11492
|
});
|
|
10908
11493
|
}
|
|
10909
11494
|
} else {
|
|
10910
|
-
const { existsSync:
|
|
10911
|
-
const { join:
|
|
11495
|
+
const { existsSync: existsSync9 } = await import("fs");
|
|
11496
|
+
const { join: join13 } = await import("path");
|
|
10912
11497
|
const candidates = ["./world", "./.neuroverse", "./worlds"];
|
|
10913
11498
|
let found;
|
|
10914
11499
|
for (const dir of candidates) {
|
|
10915
|
-
if (
|
|
11500
|
+
if (existsSync9(join13(dir, "world.json"))) {
|
|
10916
11501
|
found = dir;
|
|
10917
11502
|
break;
|
|
10918
11503
|
}
|
|
@@ -11964,8 +12549,8 @@ async function deriveCommand(args) {
|
|
|
11964
12549
|
return;
|
|
11965
12550
|
}
|
|
11966
12551
|
const plan = result.plan;
|
|
11967
|
-
const { mkdirSync:
|
|
11968
|
-
|
|
12552
|
+
const { mkdirSync: mkdirSync5 } = await import("fs");
|
|
12553
|
+
mkdirSync5(outputDir, { recursive: true });
|
|
11969
12554
|
const worldJson = {
|
|
11970
12555
|
world_id: `plan_${plan.plan_id}`,
|
|
11971
12556
|
name: `Derived: ${plan.objective}`,
|
|
@@ -12562,11 +13147,17 @@ async function runPipeMode(config) {
|
|
|
12562
13147
|
process.stderr.write(`[neuroverse] Plan: ${state.plan.plan_id} (${state.plan.objective})
|
|
12563
13148
|
`);
|
|
12564
13149
|
}
|
|
13150
|
+
const MAX_BUFFER_SIZE = 1e6;
|
|
12565
13151
|
return new Promise((resolve5, reject) => {
|
|
12566
13152
|
let buffer = "";
|
|
12567
13153
|
process.stdin.setEncoding("utf-8");
|
|
12568
13154
|
process.stdin.on("data", (chunk) => {
|
|
12569
13155
|
buffer += chunk;
|
|
13156
|
+
if (buffer.length > MAX_BUFFER_SIZE) {
|
|
13157
|
+
process.stderr.write("[neuroverse] Warning: pipe buffer exceeded 1MB, resetting\n");
|
|
13158
|
+
buffer = "";
|
|
13159
|
+
return;
|
|
13160
|
+
}
|
|
12570
13161
|
const lines = buffer.split("\n");
|
|
12571
13162
|
buffer = lines.pop() ?? "";
|
|
12572
13163
|
for (const line of lines) {
|
|
@@ -12731,7 +13322,9 @@ var init_session = __esm({
|
|
|
12731
13322
|
init_plan_engine();
|
|
12732
13323
|
init_world_loader();
|
|
12733
13324
|
init_decision_flow_engine();
|
|
12734
|
-
SessionManager = class {
|
|
13325
|
+
SessionManager = class _SessionManager {
|
|
13326
|
+
/** Maximum unique agent IDs tracked before eviction. Prevents unbounded memory growth. */
|
|
13327
|
+
static MAX_AGENTS = 1e4;
|
|
12735
13328
|
config;
|
|
12736
13329
|
state;
|
|
12737
13330
|
engineOptions;
|
|
@@ -12795,6 +13388,16 @@ var init_session = __esm({
|
|
|
12795
13388
|
if (verdict.status === "REWARD" && verdict.reward) {
|
|
12796
13389
|
agentState = applyReward(agentState, verdict.reward, verdict.ruleId ?? "unknown");
|
|
12797
13390
|
}
|
|
13391
|
+
if (this.state.agentStates.size >= _SessionManager.MAX_AGENTS && !this.state.agentStates.has(event.roleId)) {
|
|
13392
|
+
const oldest = this.state.agentStates.keys().next().value;
|
|
13393
|
+
if (oldest !== void 0) {
|
|
13394
|
+
this.state.agentStates.delete(oldest);
|
|
13395
|
+
}
|
|
13396
|
+
process.stderr.write(
|
|
13397
|
+
`[neuroverse] Warning: agent state map at capacity (${_SessionManager.MAX_AGENTS}), evicted oldest entry
|
|
13398
|
+
`
|
|
13399
|
+
);
|
|
13400
|
+
}
|
|
12798
13401
|
this.state.agentStates.set(event.roleId, agentState);
|
|
12799
13402
|
}
|
|
12800
13403
|
this.config.onVerdict?.(verdict, event);
|
|
@@ -12948,8 +13551,15 @@ async function main18(args) {
|
|
|
12948
13551
|
const plan = planPath ? loadPlan(planPath) : autoDetectPlan();
|
|
12949
13552
|
const level = parseArg2(args, "--level");
|
|
12950
13553
|
const trace = hasFlag(args, "--trace");
|
|
13554
|
+
const logPath = parseArg2(args, "--log");
|
|
12951
13555
|
const isPipeMode = hasFlag(args, "--pipe") || !process.stdin.isTTY;
|
|
12952
13556
|
const isInteractive = hasFlag(args, "--interactive");
|
|
13557
|
+
let auditLogger;
|
|
13558
|
+
if (logPath) {
|
|
13559
|
+
auditLogger = new FileAuditLogger(logPath);
|
|
13560
|
+
process.stderr.write(`[neuroverse] Audit logging to ${logPath}
|
|
13561
|
+
`);
|
|
13562
|
+
}
|
|
12953
13563
|
if (isInteractive) {
|
|
12954
13564
|
const providerName = parseArg2(args, "--provider");
|
|
12955
13565
|
if (!providerName) {
|
|
@@ -12973,6 +13583,9 @@ async function main18(args) {
|
|
|
12973
13583
|
level,
|
|
12974
13584
|
trace,
|
|
12975
13585
|
onVerdict: (verdict, event) => {
|
|
13586
|
+
if (auditLogger) {
|
|
13587
|
+
auditLogger.log(verdictToAuditEvent(event, verdict));
|
|
13588
|
+
}
|
|
12976
13589
|
if (verdict.status !== "ALLOW") {
|
|
12977
13590
|
process.stderr.write(
|
|
12978
13591
|
` [${verdict.status}] ${event.intent} \u2014 ${verdict.reason ?? verdict.ruleId ?? "governance rule"}
|
|
@@ -12999,8 +13612,12 @@ async function main18(args) {
|
|
|
12999
13612
|
worldPath,
|
|
13000
13613
|
plan,
|
|
13001
13614
|
level,
|
|
13002
|
-
trace
|
|
13615
|
+
trace,
|
|
13616
|
+
onVerdict: auditLogger ? (verdict, event) => {
|
|
13617
|
+
auditLogger.log(verdictToAuditEvent(event, verdict));
|
|
13618
|
+
} : void 0
|
|
13003
13619
|
});
|
|
13620
|
+
if (auditLogger) await auditLogger.flush();
|
|
13004
13621
|
} else {
|
|
13005
13622
|
process.stdout.write(RUN_USAGE + "\n");
|
|
13006
13623
|
process.exit(0);
|
|
@@ -13013,6 +13630,7 @@ var init_run = __esm({
|
|
|
13013
13630
|
import_fs5 = require("fs");
|
|
13014
13631
|
import_path6 = require("path");
|
|
13015
13632
|
init_world_resolver();
|
|
13633
|
+
init_audit_logger();
|
|
13016
13634
|
RUN_USAGE = `
|
|
13017
13635
|
neuroverse run \u2014 Governed runtime for AI agents.
|
|
13018
13636
|
|
|
@@ -13804,27 +14422,27 @@ function computeWorldDiff(a, b) {
|
|
|
13804
14422
|
}
|
|
13805
14423
|
async function worldSnapshot(worldPath) {
|
|
13806
14424
|
const { readdir, readFile: readFile3, mkdir: mkdir2, writeFile: writeFile5 } = await import("fs/promises");
|
|
13807
|
-
const { join:
|
|
14425
|
+
const { join: join13 } = await import("path");
|
|
13808
14426
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
13809
|
-
const snapshotDir =
|
|
14427
|
+
const snapshotDir = join13(worldPath, ".snapshots", timestamp);
|
|
13810
14428
|
await mkdir2(snapshotDir, { recursive: true });
|
|
13811
14429
|
const files = await readdir(worldPath);
|
|
13812
14430
|
let copied = 0;
|
|
13813
14431
|
for (const file of files) {
|
|
13814
14432
|
if (file.endsWith(".json")) {
|
|
13815
|
-
const content = await readFile3(
|
|
13816
|
-
await writeFile5(
|
|
14433
|
+
const content = await readFile3(join13(worldPath, file), "utf-8");
|
|
14434
|
+
await writeFile5(join13(snapshotDir, file), content, "utf-8");
|
|
13817
14435
|
copied++;
|
|
13818
14436
|
}
|
|
13819
14437
|
}
|
|
13820
14438
|
try {
|
|
13821
|
-
const rulesDir =
|
|
14439
|
+
const rulesDir = join13(worldPath, "rules");
|
|
13822
14440
|
const ruleFiles = await readdir(rulesDir);
|
|
13823
|
-
await mkdir2(
|
|
14441
|
+
await mkdir2(join13(snapshotDir, "rules"), { recursive: true });
|
|
13824
14442
|
for (const file of ruleFiles) {
|
|
13825
14443
|
if (file.endsWith(".json")) {
|
|
13826
|
-
const content = await readFile3(
|
|
13827
|
-
await writeFile5(
|
|
14444
|
+
const content = await readFile3(join13(rulesDir, file), "utf-8");
|
|
14445
|
+
await writeFile5(join13(snapshotDir, "rules", file), content, "utf-8");
|
|
13828
14446
|
copied++;
|
|
13829
14447
|
}
|
|
13830
14448
|
}
|
|
@@ -13837,8 +14455,8 @@ async function worldSnapshot(worldPath) {
|
|
|
13837
14455
|
}
|
|
13838
14456
|
async function worldRollback(worldPath) {
|
|
13839
14457
|
const { readdir, readFile: readFile3, writeFile: writeFile5, mkdir: mkdir2 } = await import("fs/promises");
|
|
13840
|
-
const { join:
|
|
13841
|
-
const snapshotsDir =
|
|
14458
|
+
const { join: join13 } = await import("path");
|
|
14459
|
+
const snapshotsDir = join13(worldPath, ".snapshots");
|
|
13842
14460
|
let snapshots;
|
|
13843
14461
|
try {
|
|
13844
14462
|
snapshots = (await readdir(snapshotsDir)).sort();
|
|
@@ -13853,34 +14471,34 @@ async function worldRollback(worldPath) {
|
|
|
13853
14471
|
return;
|
|
13854
14472
|
}
|
|
13855
14473
|
const latest = snapshots[snapshots.length - 1];
|
|
13856
|
-
const snapshotDir =
|
|
14474
|
+
const snapshotDir = join13(snapshotsDir, latest);
|
|
13857
14475
|
const backupTimestamp = "pre-rollback-" + (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
13858
|
-
const backupDir =
|
|
14476
|
+
const backupDir = join13(snapshotsDir, backupTimestamp);
|
|
13859
14477
|
await mkdir2(backupDir, { recursive: true });
|
|
13860
14478
|
const currentFiles = await readdir(worldPath);
|
|
13861
14479
|
for (const file of currentFiles) {
|
|
13862
14480
|
if (file.endsWith(".json")) {
|
|
13863
|
-
const content = await readFile3(
|
|
13864
|
-
await writeFile5(
|
|
14481
|
+
const content = await readFile3(join13(worldPath, file), "utf-8");
|
|
14482
|
+
await writeFile5(join13(backupDir, file), content, "utf-8");
|
|
13865
14483
|
}
|
|
13866
14484
|
}
|
|
13867
14485
|
const snapshotFiles = await readdir(snapshotDir);
|
|
13868
14486
|
let restored = 0;
|
|
13869
14487
|
for (const file of snapshotFiles) {
|
|
13870
14488
|
if (file.endsWith(".json")) {
|
|
13871
|
-
const content = await readFile3(
|
|
13872
|
-
await writeFile5(
|
|
14489
|
+
const content = await readFile3(join13(snapshotDir, file), "utf-8");
|
|
14490
|
+
await writeFile5(join13(worldPath, file), content, "utf-8");
|
|
13873
14491
|
restored++;
|
|
13874
14492
|
}
|
|
13875
14493
|
}
|
|
13876
14494
|
try {
|
|
13877
|
-
const rulesDir =
|
|
14495
|
+
const rulesDir = join13(snapshotDir, "rules");
|
|
13878
14496
|
const ruleFiles = await readdir(rulesDir);
|
|
13879
|
-
await mkdir2(
|
|
14497
|
+
await mkdir2(join13(worldPath, "rules"), { recursive: true });
|
|
13880
14498
|
for (const file of ruleFiles) {
|
|
13881
14499
|
if (file.endsWith(".json")) {
|
|
13882
|
-
const content = await readFile3(
|
|
13883
|
-
await writeFile5(
|
|
14500
|
+
const content = await readFile3(join13(rulesDir, file), "utf-8");
|
|
14501
|
+
await writeFile5(join13(worldPath, "rules", file), content, "utf-8");
|
|
13884
14502
|
restored++;
|
|
13885
14503
|
}
|
|
13886
14504
|
}
|
|
@@ -14031,128 +14649,6 @@ Options:
|
|
|
14031
14649
|
}
|
|
14032
14650
|
});
|
|
14033
14651
|
|
|
14034
|
-
// src/engine/audit-logger.ts
|
|
14035
|
-
function verdictToAuditEvent(event, verdict) {
|
|
14036
|
-
const auditEvent = {
|
|
14037
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
14038
|
-
worldId: verdict.evidence.worldId,
|
|
14039
|
-
worldName: verdict.evidence.worldName,
|
|
14040
|
-
worldVersion: verdict.evidence.worldVersion,
|
|
14041
|
-
intent: event.intent,
|
|
14042
|
-
tool: event.tool,
|
|
14043
|
-
scope: event.scope,
|
|
14044
|
-
actor: event.roleId,
|
|
14045
|
-
direction: event.direction,
|
|
14046
|
-
decision: verdict.status,
|
|
14047
|
-
reason: verdict.reason,
|
|
14048
|
-
ruleId: verdict.ruleId,
|
|
14049
|
-
warning: verdict.warning,
|
|
14050
|
-
guardsMatched: verdict.evidence.guardsMatched,
|
|
14051
|
-
rulesMatched: verdict.evidence.rulesMatched,
|
|
14052
|
-
invariantsSatisfied: verdict.evidence.invariantsSatisfied,
|
|
14053
|
-
invariantsTotal: verdict.evidence.invariantsTotal,
|
|
14054
|
-
enforcementLevel: verdict.evidence.enforcementLevel,
|
|
14055
|
-
durationMs: verdict.trace?.durationMs,
|
|
14056
|
-
args: event.args
|
|
14057
|
-
};
|
|
14058
|
-
if (verdict.consequence) {
|
|
14059
|
-
auditEvent.consequence = verdict.consequence;
|
|
14060
|
-
}
|
|
14061
|
-
if (verdict.reward) {
|
|
14062
|
-
auditEvent.reward = verdict.reward;
|
|
14063
|
-
}
|
|
14064
|
-
if (verdict.intentRecord) {
|
|
14065
|
-
auditEvent.originalIntent = verdict.intentRecord.originalIntent;
|
|
14066
|
-
auditEvent.finalAction = verdict.intentRecord.finalAction;
|
|
14067
|
-
}
|
|
14068
|
-
return auditEvent;
|
|
14069
|
-
}
|
|
14070
|
-
async function readAuditLog(logPath, filter) {
|
|
14071
|
-
const { readFile: readFile3 } = await import("fs/promises");
|
|
14072
|
-
let content;
|
|
14073
|
-
try {
|
|
14074
|
-
content = await readFile3(logPath, "utf-8");
|
|
14075
|
-
} catch {
|
|
14076
|
-
return [];
|
|
14077
|
-
}
|
|
14078
|
-
const events = [];
|
|
14079
|
-
for (const line of content.split("\n")) {
|
|
14080
|
-
const trimmed = line.trim();
|
|
14081
|
-
if (!trimmed) continue;
|
|
14082
|
-
try {
|
|
14083
|
-
const event = JSON.parse(trimmed);
|
|
14084
|
-
if (!filter || filter(event)) {
|
|
14085
|
-
events.push(event);
|
|
14086
|
-
}
|
|
14087
|
-
} catch {
|
|
14088
|
-
}
|
|
14089
|
-
}
|
|
14090
|
-
return events;
|
|
14091
|
-
}
|
|
14092
|
-
function summarizeAuditEvents(events) {
|
|
14093
|
-
const allowed = events.filter((e) => e.decision === "ALLOW").length;
|
|
14094
|
-
const blocked = events.filter((e) => e.decision === "BLOCK").length;
|
|
14095
|
-
const paused = events.filter((e) => e.decision === "PAUSE").length;
|
|
14096
|
-
const modified = events.filter((e) => e.decision === "MODIFY").length;
|
|
14097
|
-
const penalized = events.filter((e) => e.decision === "PENALIZE").length;
|
|
14098
|
-
const rewarded = events.filter((e) => e.decision === "REWARD").length;
|
|
14099
|
-
const neutral = events.filter((e) => e.decision === "NEUTRAL").length;
|
|
14100
|
-
const actorSet = /* @__PURE__ */ new Set();
|
|
14101
|
-
for (const e of events) {
|
|
14102
|
-
if (e.actor) actorSet.add(e.actor);
|
|
14103
|
-
}
|
|
14104
|
-
const intentMap = /* @__PURE__ */ new Map();
|
|
14105
|
-
for (const e of events) {
|
|
14106
|
-
const entry = intentMap.get(e.intent) ?? { count: 0, blocked: 0, paused: 0, penalized: 0, rewarded: 0 };
|
|
14107
|
-
entry.count++;
|
|
14108
|
-
if (e.decision === "BLOCK") entry.blocked++;
|
|
14109
|
-
if (e.decision === "PAUSE") entry.paused++;
|
|
14110
|
-
if (e.decision === "PENALIZE") entry.penalized++;
|
|
14111
|
-
if (e.decision === "REWARD") entry.rewarded++;
|
|
14112
|
-
intentMap.set(e.intent, entry);
|
|
14113
|
-
}
|
|
14114
|
-
const topIntents = [...intentMap.entries()].map(([intent, data]) => ({ intent, ...data })).sort((a, b) => b.count - a.count);
|
|
14115
|
-
const ruleMap = /* @__PURE__ */ new Map();
|
|
14116
|
-
for (const e of events) {
|
|
14117
|
-
if (e.ruleId) {
|
|
14118
|
-
ruleMap.set(e.ruleId, (ruleMap.get(e.ruleId) ?? 0) + 1);
|
|
14119
|
-
}
|
|
14120
|
-
for (const g of e.guardsMatched) {
|
|
14121
|
-
ruleMap.set(g, (ruleMap.get(g) ?? 0) + 1);
|
|
14122
|
-
}
|
|
14123
|
-
}
|
|
14124
|
-
const topRules = [...ruleMap.entries()].map(([ruleId, count]) => ({ ruleId, count })).sort((a, b) => b.count - a.count);
|
|
14125
|
-
const redirected = blocked + paused + modified + penalized;
|
|
14126
|
-
const total = events.length;
|
|
14127
|
-
return {
|
|
14128
|
-
totalActions: total,
|
|
14129
|
-
allowed,
|
|
14130
|
-
blocked,
|
|
14131
|
-
paused,
|
|
14132
|
-
modified,
|
|
14133
|
-
penalized,
|
|
14134
|
-
rewarded,
|
|
14135
|
-
neutral,
|
|
14136
|
-
actors: [...actorSet],
|
|
14137
|
-
topIntents,
|
|
14138
|
-
topRules,
|
|
14139
|
-
firstEvent: events[0]?.timestamp ?? "",
|
|
14140
|
-
lastEvent: events[events.length - 1]?.timestamp ?? "",
|
|
14141
|
-
behavioralEconomy: {
|
|
14142
|
-
totalPenalties: penalized,
|
|
14143
|
-
totalRewards: rewarded,
|
|
14144
|
-
netPressure: rewarded - penalized,
|
|
14145
|
-
redirectionRate: total > 0 ? redirected / total : 0
|
|
14146
|
-
}
|
|
14147
|
-
};
|
|
14148
|
-
}
|
|
14149
|
-
var init_audit_logger = __esm({
|
|
14150
|
-
"src/engine/audit-logger.ts"() {
|
|
14151
|
-
"use strict";
|
|
14152
|
-
init_guard_engine();
|
|
14153
|
-
}
|
|
14154
|
-
});
|
|
14155
|
-
|
|
14156
14652
|
// src/cli/trace.ts
|
|
14157
14653
|
var trace_exports = {};
|
|
14158
14654
|
__export(trace_exports, {
|
|
@@ -15176,17 +15672,595 @@ var init_equity_penalties = __esm({
|
|
|
15176
15672
|
}
|
|
15177
15673
|
});
|
|
15178
15674
|
|
|
15179
|
-
// src/cli/
|
|
15180
|
-
var
|
|
15181
|
-
__export(
|
|
15675
|
+
// src/cli/keygen.ts
|
|
15676
|
+
var keygen_exports = {};
|
|
15677
|
+
__export(keygen_exports, {
|
|
15182
15678
|
main: () => main26
|
|
15183
15679
|
});
|
|
15184
15680
|
function parseArgs20(argv) {
|
|
15185
|
-
let
|
|
15186
|
-
let
|
|
15187
|
-
let
|
|
15188
|
-
let
|
|
15189
|
-
let
|
|
15681
|
+
let output = (0, import_path8.join)((0, import_os2.homedir)(), ".neuroverse", "keys");
|
|
15682
|
+
let name = "neuroverse";
|
|
15683
|
+
let force = false;
|
|
15684
|
+
let help = false;
|
|
15685
|
+
for (let i = 0; i < argv.length; i++) {
|
|
15686
|
+
const arg = argv[i];
|
|
15687
|
+
if ((arg === "--output" || arg === "-o") && argv[i + 1]) {
|
|
15688
|
+
output = argv[++i];
|
|
15689
|
+
} else if ((arg === "--name" || arg === "-n") && argv[i + 1]) {
|
|
15690
|
+
name = argv[++i];
|
|
15691
|
+
} else if (arg === "--force") {
|
|
15692
|
+
force = true;
|
|
15693
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
15694
|
+
help = true;
|
|
15695
|
+
}
|
|
15696
|
+
}
|
|
15697
|
+
return { output, name, force, help };
|
|
15698
|
+
}
|
|
15699
|
+
async function main26(argv = process.argv.slice(2)) {
|
|
15700
|
+
const args = parseArgs20(argv);
|
|
15701
|
+
if (args.help) {
|
|
15702
|
+
process.stdout.write(USAGE5 + "\n");
|
|
15703
|
+
return;
|
|
15704
|
+
}
|
|
15705
|
+
const pubPath = (0, import_path8.join)(args.output, `${args.name}.pub`);
|
|
15706
|
+
const keyPath = (0, import_path8.join)(args.output, `${args.name}.key`);
|
|
15707
|
+
if (!args.force && ((0, import_fs7.existsSync)(pubPath) || (0, import_fs7.existsSync)(keyPath))) {
|
|
15708
|
+
process.stderr.write(`Keys already exist at ${args.output}/${args.name}.*
|
|
15709
|
+
`);
|
|
15710
|
+
process.stderr.write("Use --force to overwrite.\n");
|
|
15711
|
+
process.exit(1);
|
|
15712
|
+
}
|
|
15713
|
+
const { publicKey, privateKey } = (0, import_crypto.generateKeyPairSync)("ed25519", {
|
|
15714
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
15715
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
15716
|
+
});
|
|
15717
|
+
(0, import_fs7.mkdirSync)(args.output, { recursive: true });
|
|
15718
|
+
(0, import_fs7.writeFileSync)(pubPath, publicKey, "utf-8");
|
|
15719
|
+
(0, import_fs7.writeFileSync)(keyPath, privateKey, { encoding: "utf-8", mode: 384 });
|
|
15720
|
+
process.stdout.write(`Keypair generated:
|
|
15721
|
+
`);
|
|
15722
|
+
process.stdout.write(` Public: ${pubPath}
|
|
15723
|
+
`);
|
|
15724
|
+
process.stdout.write(` Private: ${keyPath}
|
|
15725
|
+
`);
|
|
15726
|
+
process.stdout.write(`
|
|
15727
|
+
Share the .pub file with anyone who needs to verify your worlds.
|
|
15728
|
+
`);
|
|
15729
|
+
process.stdout.write(`Keep the .key file secret.
|
|
15730
|
+
`);
|
|
15731
|
+
}
|
|
15732
|
+
var import_crypto, import_fs7, import_path8, import_os2, USAGE5;
|
|
15733
|
+
var init_keygen = __esm({
|
|
15734
|
+
"src/cli/keygen.ts"() {
|
|
15735
|
+
"use strict";
|
|
15736
|
+
import_crypto = require("crypto");
|
|
15737
|
+
import_fs7 = require("fs");
|
|
15738
|
+
import_path8 = require("path");
|
|
15739
|
+
import_os2 = require("os");
|
|
15740
|
+
USAGE5 = `
|
|
15741
|
+
neuroverse keygen \u2014 Generate Ed25519 signing keypair
|
|
15742
|
+
|
|
15743
|
+
Usage:
|
|
15744
|
+
neuroverse keygen [--output <dir>] [--name <name>]
|
|
15745
|
+
|
|
15746
|
+
Options:
|
|
15747
|
+
--output <dir> Key directory (default: ~/.neuroverse/keys/)
|
|
15748
|
+
--name <name> Key name (default: neuroverse)
|
|
15749
|
+
--force Overwrite existing keys
|
|
15750
|
+
|
|
15751
|
+
Examples:
|
|
15752
|
+
neuroverse keygen
|
|
15753
|
+
neuroverse keygen --name production --output ./keys/
|
|
15754
|
+
`.trim();
|
|
15755
|
+
}
|
|
15756
|
+
});
|
|
15757
|
+
|
|
15758
|
+
// src/cli/sign.ts
|
|
15759
|
+
var sign_exports = {};
|
|
15760
|
+
__export(sign_exports, {
|
|
15761
|
+
buildManifest: () => buildManifest,
|
|
15762
|
+
canonicalManifest: () => canonicalManifest,
|
|
15763
|
+
main: () => main27
|
|
15764
|
+
});
|
|
15765
|
+
function parseArgs21(argv) {
|
|
15766
|
+
let worldPath = "";
|
|
15767
|
+
let keyPath = (0, import_path9.join)((0, import_os3.homedir)(), ".neuroverse", "keys", "neuroverse.key");
|
|
15768
|
+
let help = false;
|
|
15769
|
+
for (let i = 0; i < argv.length; i++) {
|
|
15770
|
+
const arg = argv[i];
|
|
15771
|
+
if (arg === "--world" && argv[i + 1]) {
|
|
15772
|
+
worldPath = argv[++i];
|
|
15773
|
+
} else if (arg === "--key" && argv[i + 1]) {
|
|
15774
|
+
keyPath = argv[++i];
|
|
15775
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
15776
|
+
help = true;
|
|
15777
|
+
}
|
|
15778
|
+
}
|
|
15779
|
+
return { worldPath, keyPath, help };
|
|
15780
|
+
}
|
|
15781
|
+
function collectFiles(dir, base) {
|
|
15782
|
+
const root = base ?? dir;
|
|
15783
|
+
const files = [];
|
|
15784
|
+
for (const entry of (0, import_fs8.readdirSync)(dir)) {
|
|
15785
|
+
if (entry === ".nv-signature.json") continue;
|
|
15786
|
+
const full = (0, import_path9.join)(dir, entry);
|
|
15787
|
+
const stat = (0, import_fs8.statSync)(full);
|
|
15788
|
+
if (stat.isDirectory()) {
|
|
15789
|
+
files.push(...collectFiles(full, root));
|
|
15790
|
+
} else {
|
|
15791
|
+
files.push((0, import_path9.relative)(root, full));
|
|
15792
|
+
}
|
|
15793
|
+
}
|
|
15794
|
+
return files.sort();
|
|
15795
|
+
}
|
|
15796
|
+
function buildManifest(worldPath) {
|
|
15797
|
+
const files = collectFiles(worldPath);
|
|
15798
|
+
const manifest = {};
|
|
15799
|
+
for (const file of files) {
|
|
15800
|
+
const content = (0, import_fs8.readFileSync)((0, import_path9.join)(worldPath, file));
|
|
15801
|
+
manifest[file] = (0, import_crypto2.createHash)("sha256").update(content).digest("hex");
|
|
15802
|
+
}
|
|
15803
|
+
return manifest;
|
|
15804
|
+
}
|
|
15805
|
+
function canonicalManifest(files) {
|
|
15806
|
+
const sorted = Object.keys(files).sort();
|
|
15807
|
+
return sorted.map((k) => `${k}:${files[k]}`).join("\n");
|
|
15808
|
+
}
|
|
15809
|
+
async function main27(argv = process.argv.slice(2)) {
|
|
15810
|
+
const args = parseArgs21(argv);
|
|
15811
|
+
if (args.help) {
|
|
15812
|
+
process.stdout.write(USAGE6 + "\n");
|
|
15813
|
+
return;
|
|
15814
|
+
}
|
|
15815
|
+
if (!args.worldPath) {
|
|
15816
|
+
process.stderr.write("Error: --world <dir> is required.\n");
|
|
15817
|
+
process.exit(1);
|
|
15818
|
+
}
|
|
15819
|
+
let privateKey;
|
|
15820
|
+
try {
|
|
15821
|
+
privateKey = (0, import_fs8.readFileSync)(args.keyPath, "utf-8");
|
|
15822
|
+
} catch {
|
|
15823
|
+
process.stderr.write(`Error: Cannot read private key at ${args.keyPath}
|
|
15824
|
+
`);
|
|
15825
|
+
process.stderr.write('Run "neuroverse keygen" to generate a keypair.\n');
|
|
15826
|
+
process.exit(1);
|
|
15827
|
+
return;
|
|
15828
|
+
}
|
|
15829
|
+
const files = buildManifest(args.worldPath);
|
|
15830
|
+
const canonical = canonicalManifest(files);
|
|
15831
|
+
const manifestHash = (0, import_crypto2.createHash)("sha256").update(canonical).digest("hex");
|
|
15832
|
+
const signature = (0, import_crypto2.sign)(null, Buffer.from(manifestHash), privateKey).toString("base64");
|
|
15833
|
+
const artifact = {
|
|
15834
|
+
signatureVersion: "1.0",
|
|
15835
|
+
signedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15836
|
+
files,
|
|
15837
|
+
manifestHash,
|
|
15838
|
+
signature
|
|
15839
|
+
};
|
|
15840
|
+
const outPath = (0, import_path9.join)(args.worldPath, ".nv-signature.json");
|
|
15841
|
+
(0, import_fs8.writeFileSync)(outPath, JSON.stringify(artifact, null, 2) + "\n", "utf-8");
|
|
15842
|
+
process.stdout.write(`Signed ${Object.keys(files).length} files in ${args.worldPath}
|
|
15843
|
+
`);
|
|
15844
|
+
process.stdout.write(`Signature: ${outPath}
|
|
15845
|
+
`);
|
|
15846
|
+
}
|
|
15847
|
+
var import_crypto2, import_fs8, import_path9, import_os3, USAGE6;
|
|
15848
|
+
var init_sign = __esm({
|
|
15849
|
+
"src/cli/sign.ts"() {
|
|
15850
|
+
"use strict";
|
|
15851
|
+
import_crypto2 = require("crypto");
|
|
15852
|
+
import_fs8 = require("fs");
|
|
15853
|
+
import_path9 = require("path");
|
|
15854
|
+
import_os3 = require("os");
|
|
15855
|
+
USAGE6 = `
|
|
15856
|
+
neuroverse sign \u2014 Sign a world artifact
|
|
15857
|
+
|
|
15858
|
+
Usage:
|
|
15859
|
+
neuroverse sign --world <dir> [--key <path>]
|
|
15860
|
+
|
|
15861
|
+
Options:
|
|
15862
|
+
--world <dir> World directory to sign (required)
|
|
15863
|
+
--key <path> Private key path (default: ~/.neuroverse/keys/neuroverse.key)
|
|
15864
|
+
|
|
15865
|
+
Examples:
|
|
15866
|
+
neuroverse sign --world ./world/
|
|
15867
|
+
neuroverse sign --world ./world/ --key ./keys/production.key
|
|
15868
|
+
`.trim();
|
|
15869
|
+
}
|
|
15870
|
+
});
|
|
15871
|
+
|
|
15872
|
+
// src/cli/verify.ts
|
|
15873
|
+
var verify_exports = {};
|
|
15874
|
+
__export(verify_exports, {
|
|
15875
|
+
main: () => main28
|
|
15876
|
+
});
|
|
15877
|
+
function parseArgs22(argv) {
|
|
15878
|
+
let worldPath = "";
|
|
15879
|
+
let keyPath = (0, import_path10.join)((0, import_os4.homedir)(), ".neuroverse", "keys", "neuroverse.pub");
|
|
15880
|
+
let json = false;
|
|
15881
|
+
let help = false;
|
|
15882
|
+
for (let i = 0; i < argv.length; i++) {
|
|
15883
|
+
const arg = argv[i];
|
|
15884
|
+
if (arg === "--world" && argv[i + 1]) {
|
|
15885
|
+
worldPath = argv[++i];
|
|
15886
|
+
} else if (arg === "--key" && argv[i + 1]) {
|
|
15887
|
+
keyPath = argv[++i];
|
|
15888
|
+
} else if (arg === "--json") {
|
|
15889
|
+
json = true;
|
|
15890
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
15891
|
+
help = true;
|
|
15892
|
+
}
|
|
15893
|
+
}
|
|
15894
|
+
return { worldPath, keyPath, json, help };
|
|
15895
|
+
}
|
|
15896
|
+
async function main28(argv = process.argv.slice(2)) {
|
|
15897
|
+
const args = parseArgs22(argv);
|
|
15898
|
+
if (args.help) {
|
|
15899
|
+
process.stdout.write(USAGE7 + "\n");
|
|
15900
|
+
return;
|
|
15901
|
+
}
|
|
15902
|
+
if (!args.worldPath) {
|
|
15903
|
+
process.stderr.write("Error: --world <dir> is required.\n");
|
|
15904
|
+
process.exit(1);
|
|
15905
|
+
}
|
|
15906
|
+
const result = {
|
|
15907
|
+
valid: false,
|
|
15908
|
+
worldPath: args.worldPath,
|
|
15909
|
+
fileCount: 0,
|
|
15910
|
+
errors: []
|
|
15911
|
+
};
|
|
15912
|
+
const sigPath = (0, import_path10.join)(args.worldPath, ".nv-signature.json");
|
|
15913
|
+
if (!(0, import_fs9.existsSync)(sigPath)) {
|
|
15914
|
+
result.errors.push("No .nv-signature.json found \u2014 world is unsigned.");
|
|
15915
|
+
outputResult(result, args.json);
|
|
15916
|
+
process.exit(1);
|
|
15917
|
+
}
|
|
15918
|
+
let artifact;
|
|
15919
|
+
try {
|
|
15920
|
+
artifact = JSON.parse((0, import_fs9.readFileSync)(sigPath, "utf-8"));
|
|
15921
|
+
} catch {
|
|
15922
|
+
result.errors.push("Cannot parse .nv-signature.json \u2014 file is corrupt.");
|
|
15923
|
+
outputResult(result, args.json);
|
|
15924
|
+
process.exit(1);
|
|
15925
|
+
return;
|
|
15926
|
+
}
|
|
15927
|
+
result.signedAt = artifact.signedAt;
|
|
15928
|
+
result.fileCount = Object.keys(artifact.files).length;
|
|
15929
|
+
let publicKey;
|
|
15930
|
+
try {
|
|
15931
|
+
publicKey = (0, import_fs9.readFileSync)(args.keyPath, "utf-8");
|
|
15932
|
+
} catch {
|
|
15933
|
+
result.errors.push(`Cannot read public key at ${args.keyPath}`);
|
|
15934
|
+
outputResult(result, args.json);
|
|
15935
|
+
process.exit(1);
|
|
15936
|
+
return;
|
|
15937
|
+
}
|
|
15938
|
+
const currentFiles = buildManifest(args.worldPath);
|
|
15939
|
+
for (const file of Object.keys(currentFiles)) {
|
|
15940
|
+
if (!(file in artifact.files)) {
|
|
15941
|
+
result.errors.push(`Added: ${file} (not in signature)`);
|
|
15942
|
+
}
|
|
15943
|
+
}
|
|
15944
|
+
for (const [file, hash] of Object.entries(artifact.files)) {
|
|
15945
|
+
if (!(file in currentFiles)) {
|
|
15946
|
+
result.errors.push(`Missing: ${file} (was in signature)`);
|
|
15947
|
+
} else if (currentFiles[file] !== hash) {
|
|
15948
|
+
result.errors.push(`Changed: ${file} (hash mismatch)`);
|
|
15949
|
+
}
|
|
15950
|
+
}
|
|
15951
|
+
if (result.errors.length > 0) {
|
|
15952
|
+
outputResult(result, args.json);
|
|
15953
|
+
process.exit(1);
|
|
15954
|
+
return;
|
|
15955
|
+
}
|
|
15956
|
+
const canonical = canonicalManifest(artifact.files);
|
|
15957
|
+
const manifestHash = (0, import_crypto3.createHash)("sha256").update(canonical).digest("hex");
|
|
15958
|
+
if (manifestHash !== artifact.manifestHash) {
|
|
15959
|
+
result.errors.push("Manifest hash mismatch \u2014 signature metadata is corrupt.");
|
|
15960
|
+
outputResult(result, args.json);
|
|
15961
|
+
process.exit(1);
|
|
15962
|
+
return;
|
|
15963
|
+
}
|
|
15964
|
+
const isValid = (0, import_crypto3.verify)(null, Buffer.from(manifestHash), publicKey, Buffer.from(artifact.signature, "base64"));
|
|
15965
|
+
if (!isValid) {
|
|
15966
|
+
result.errors.push("Signature verification failed \u2014 wrong key or tampered manifest.");
|
|
15967
|
+
outputResult(result, args.json);
|
|
15968
|
+
process.exit(1);
|
|
15969
|
+
return;
|
|
15970
|
+
}
|
|
15971
|
+
result.valid = true;
|
|
15972
|
+
outputResult(result, args.json);
|
|
15973
|
+
}
|
|
15974
|
+
function outputResult(result, json) {
|
|
15975
|
+
if (json) {
|
|
15976
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
15977
|
+
return;
|
|
15978
|
+
}
|
|
15979
|
+
if (result.valid) {
|
|
15980
|
+
process.stdout.write(`VALID \u2014 ${result.fileCount} files verified
|
|
15981
|
+
`);
|
|
15982
|
+
process.stdout.write(` Signed at: ${result.signedAt}
|
|
15983
|
+
`);
|
|
15984
|
+
process.stdout.write(` World: ${result.worldPath}
|
|
15985
|
+
`);
|
|
15986
|
+
} else {
|
|
15987
|
+
process.stdout.write(`INVALID \u2014 signature verification failed
|
|
15988
|
+
`);
|
|
15989
|
+
for (const error of result.errors) {
|
|
15990
|
+
process.stdout.write(` ${error}
|
|
15991
|
+
`);
|
|
15992
|
+
}
|
|
15993
|
+
}
|
|
15994
|
+
}
|
|
15995
|
+
var import_crypto3, import_fs9, import_path10, import_os4, USAGE7;
|
|
15996
|
+
var init_verify = __esm({
|
|
15997
|
+
"src/cli/verify.ts"() {
|
|
15998
|
+
"use strict";
|
|
15999
|
+
import_crypto3 = require("crypto");
|
|
16000
|
+
import_fs9 = require("fs");
|
|
16001
|
+
import_path10 = require("path");
|
|
16002
|
+
import_os4 = require("os");
|
|
16003
|
+
init_sign();
|
|
16004
|
+
USAGE7 = `
|
|
16005
|
+
neuroverse verify \u2014 Verify a signed world artifact
|
|
16006
|
+
|
|
16007
|
+
Usage:
|
|
16008
|
+
neuroverse verify --world <dir> [--key <path>]
|
|
16009
|
+
|
|
16010
|
+
Options:
|
|
16011
|
+
--world <dir> World directory to verify (required)
|
|
16012
|
+
--key <path> Public key path (default: ~/.neuroverse/keys/neuroverse.pub)
|
|
16013
|
+
--json Output result as JSON
|
|
16014
|
+
|
|
16015
|
+
Exit codes:
|
|
16016
|
+
0 Valid \u2014 world matches signature
|
|
16017
|
+
1 Invalid \u2014 signature mismatch, tampered files, or missing signature
|
|
16018
|
+
|
|
16019
|
+
Examples:
|
|
16020
|
+
neuroverse verify --world ./world/
|
|
16021
|
+
neuroverse verify --world ./world/ --key ./keys/production.pub
|
|
16022
|
+
`.trim();
|
|
16023
|
+
}
|
|
16024
|
+
});
|
|
16025
|
+
|
|
16026
|
+
// src/cli/migrate.ts
|
|
16027
|
+
var migrate_exports = {};
|
|
16028
|
+
__export(migrate_exports, {
|
|
16029
|
+
LATEST_VERSION: () => LATEST_VERSION,
|
|
16030
|
+
main: () => main29
|
|
16031
|
+
});
|
|
16032
|
+
function detectVersion(worldPath) {
|
|
16033
|
+
const metaPath = (0, import_path11.join)(worldPath, "metadata.json");
|
|
16034
|
+
if ((0, import_fs10.existsSync)(metaPath)) {
|
|
16035
|
+
try {
|
|
16036
|
+
const meta = JSON.parse((0, import_fs10.readFileSync)(metaPath, "utf-8"));
|
|
16037
|
+
if (meta.schema_version) return meta.schema_version;
|
|
16038
|
+
} catch {
|
|
16039
|
+
}
|
|
16040
|
+
}
|
|
16041
|
+
return "1.0.0";
|
|
16042
|
+
}
|
|
16043
|
+
function compareVersions(a, b) {
|
|
16044
|
+
const pa = a.split(".").map(Number);
|
|
16045
|
+
const pb = b.split(".").map(Number);
|
|
16046
|
+
for (let i = 0; i < 3; i++) {
|
|
16047
|
+
if ((pa[i] ?? 0) < (pb[i] ?? 0)) return -1;
|
|
16048
|
+
if ((pa[i] ?? 0) > (pb[i] ?? 0)) return 1;
|
|
16049
|
+
}
|
|
16050
|
+
return 0;
|
|
16051
|
+
}
|
|
16052
|
+
function findMigrationPath(from, to) {
|
|
16053
|
+
const path = [];
|
|
16054
|
+
let current = from;
|
|
16055
|
+
while (compareVersions(current, to) < 0) {
|
|
16056
|
+
const next = MIGRATIONS.find((m) => m.from === current);
|
|
16057
|
+
if (!next) break;
|
|
16058
|
+
path.push(next);
|
|
16059
|
+
current = next.to;
|
|
16060
|
+
}
|
|
16061
|
+
return path;
|
|
16062
|
+
}
|
|
16063
|
+
function parseArgs23(argv) {
|
|
16064
|
+
let worldPath = "";
|
|
16065
|
+
let dryRun = false;
|
|
16066
|
+
let backup = false;
|
|
16067
|
+
let target = LATEST_VERSION;
|
|
16068
|
+
let json = false;
|
|
16069
|
+
let help = false;
|
|
16070
|
+
for (let i = 0; i < argv.length; i++) {
|
|
16071
|
+
const arg = argv[i];
|
|
16072
|
+
if (arg === "--world" && argv[i + 1]) {
|
|
16073
|
+
worldPath = argv[++i];
|
|
16074
|
+
} else if (arg === "--dry-run") {
|
|
16075
|
+
dryRun = true;
|
|
16076
|
+
} else if (arg === "--backup") {
|
|
16077
|
+
backup = true;
|
|
16078
|
+
} else if (arg === "--target" && argv[i + 1]) {
|
|
16079
|
+
target = argv[++i];
|
|
16080
|
+
} else if (arg === "--json") {
|
|
16081
|
+
json = true;
|
|
16082
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
16083
|
+
help = true;
|
|
16084
|
+
}
|
|
16085
|
+
}
|
|
16086
|
+
return { worldPath, dryRun, backup, target, json, help };
|
|
16087
|
+
}
|
|
16088
|
+
async function main29(argv = process.argv.slice(2)) {
|
|
16089
|
+
const args = parseArgs23(argv);
|
|
16090
|
+
if (args.help) {
|
|
16091
|
+
process.stdout.write(USAGE8 + "\n");
|
|
16092
|
+
return;
|
|
16093
|
+
}
|
|
16094
|
+
if (!args.worldPath) {
|
|
16095
|
+
process.stderr.write("Error: --world <dir> is required.\n");
|
|
16096
|
+
process.exit(1);
|
|
16097
|
+
}
|
|
16098
|
+
const currentVersion = detectVersion(args.worldPath);
|
|
16099
|
+
const targetVersion = args.target;
|
|
16100
|
+
if (compareVersions(currentVersion, targetVersion) >= 0) {
|
|
16101
|
+
const plan2 = {
|
|
16102
|
+
currentVersion,
|
|
16103
|
+
targetVersion,
|
|
16104
|
+
migrations: [],
|
|
16105
|
+
changes: []
|
|
16106
|
+
};
|
|
16107
|
+
if (args.json) {
|
|
16108
|
+
process.stdout.write(JSON.stringify(plan2, null, 2) + "\n");
|
|
16109
|
+
} else {
|
|
16110
|
+
process.stdout.write(`World is already at version ${currentVersion} (target: ${targetVersion})
|
|
16111
|
+
`);
|
|
16112
|
+
process.stdout.write("No migrations needed.\n");
|
|
16113
|
+
}
|
|
16114
|
+
return;
|
|
16115
|
+
}
|
|
16116
|
+
const migrationPath = findMigrationPath(currentVersion, targetVersion);
|
|
16117
|
+
if (migrationPath.length === 0) {
|
|
16118
|
+
process.stderr.write(`No migration path from ${currentVersion} to ${targetVersion}
|
|
16119
|
+
`);
|
|
16120
|
+
process.exit(1);
|
|
16121
|
+
return;
|
|
16122
|
+
}
|
|
16123
|
+
if (args.dryRun) {
|
|
16124
|
+
const plan2 = {
|
|
16125
|
+
currentVersion,
|
|
16126
|
+
targetVersion,
|
|
16127
|
+
migrations: migrationPath.map((m) => ({ from: m.from, to: m.to, description: m.description })),
|
|
16128
|
+
changes: []
|
|
16129
|
+
};
|
|
16130
|
+
if (args.json) {
|
|
16131
|
+
process.stdout.write(JSON.stringify(plan2, null, 2) + "\n");
|
|
16132
|
+
} else {
|
|
16133
|
+
process.stdout.write(`Migration plan: ${currentVersion} \u2192 ${targetVersion}
|
|
16134
|
+
`);
|
|
16135
|
+
process.stdout.write(`Steps: ${migrationPath.length}
|
|
16136
|
+
|
|
16137
|
+
`);
|
|
16138
|
+
for (const m of migrationPath) {
|
|
16139
|
+
process.stdout.write(` ${m.from} \u2192 ${m.to}: ${m.description}
|
|
16140
|
+
`);
|
|
16141
|
+
}
|
|
16142
|
+
process.stdout.write("\nRun without --dry-run to apply.\n");
|
|
16143
|
+
}
|
|
16144
|
+
return;
|
|
16145
|
+
}
|
|
16146
|
+
if (args.backup) {
|
|
16147
|
+
const backupPath = args.worldPath + ".backup";
|
|
16148
|
+
(0, import_fs10.cpSync)(args.worldPath, backupPath, { recursive: true });
|
|
16149
|
+
process.stdout.write(`Backup created: ${backupPath}
|
|
16150
|
+
`);
|
|
16151
|
+
}
|
|
16152
|
+
const allChanges = [];
|
|
16153
|
+
for (const migration of migrationPath) {
|
|
16154
|
+
process.stdout.write(`Applying: ${migration.from} \u2192 ${migration.to} (${migration.description})
|
|
16155
|
+
`);
|
|
16156
|
+
const changes = migration.apply(args.worldPath);
|
|
16157
|
+
allChanges.push(...changes);
|
|
16158
|
+
for (const change of changes) {
|
|
16159
|
+
process.stdout.write(` ${change.action}: ${change.file} \u2014 ${change.description}
|
|
16160
|
+
`);
|
|
16161
|
+
}
|
|
16162
|
+
}
|
|
16163
|
+
const plan = {
|
|
16164
|
+
currentVersion,
|
|
16165
|
+
targetVersion,
|
|
16166
|
+
migrations: migrationPath.map((m) => ({ from: m.from, to: m.to, description: m.description })),
|
|
16167
|
+
changes: allChanges
|
|
16168
|
+
};
|
|
16169
|
+
if (args.json) {
|
|
16170
|
+
process.stdout.write(JSON.stringify(plan, null, 2) + "\n");
|
|
16171
|
+
}
|
|
16172
|
+
process.stdout.write(`
|
|
16173
|
+
Migration complete: ${currentVersion} \u2192 ${targetVersion} (${allChanges.length} changes)
|
|
16174
|
+
`);
|
|
16175
|
+
}
|
|
16176
|
+
var import_fs10, import_path11, USAGE8, MIGRATIONS, LATEST_VERSION;
|
|
16177
|
+
var init_migrate = __esm({
|
|
16178
|
+
"src/cli/migrate.ts"() {
|
|
16179
|
+
"use strict";
|
|
16180
|
+
import_fs10 = require("fs");
|
|
16181
|
+
import_path11 = require("path");
|
|
16182
|
+
USAGE8 = `
|
|
16183
|
+
neuroverse migrate \u2014 World schema version migration
|
|
16184
|
+
|
|
16185
|
+
Usage:
|
|
16186
|
+
neuroverse migrate --world <dir> [options]
|
|
16187
|
+
|
|
16188
|
+
Options:
|
|
16189
|
+
--world <dir> World directory to migrate (required)
|
|
16190
|
+
--dry-run Show what would change without modifying files
|
|
16191
|
+
--backup Copy original world to <dir>.backup before migrating
|
|
16192
|
+
--target <version> Target schema version (default: latest)
|
|
16193
|
+
--json Output migration plan as JSON
|
|
16194
|
+
|
|
16195
|
+
Examples:
|
|
16196
|
+
neuroverse migrate --world ./world/ --dry-run
|
|
16197
|
+
neuroverse migrate --world ./world/ --backup
|
|
16198
|
+
neuroverse migrate --world ./world/ --target 1.1.0
|
|
16199
|
+
`.trim();
|
|
16200
|
+
MIGRATIONS = [
|
|
16201
|
+
{
|
|
16202
|
+
from: "1.0.0",
|
|
16203
|
+
to: "1.1.0",
|
|
16204
|
+
description: "Add enforcement_level to world.json, normalize metadata fields",
|
|
16205
|
+
apply: (worldPath) => {
|
|
16206
|
+
const changes = [];
|
|
16207
|
+
const worldJsonPath = (0, import_path11.join)(worldPath, "world.json");
|
|
16208
|
+
if ((0, import_fs10.existsSync)(worldJsonPath)) {
|
|
16209
|
+
const world = JSON.parse((0, import_fs10.readFileSync)(worldJsonPath, "utf-8"));
|
|
16210
|
+
if (!world.enforcement_level) {
|
|
16211
|
+
world.enforcement_level = "standard";
|
|
16212
|
+
(0, import_fs10.writeFileSync)(worldJsonPath, JSON.stringify(world, null, 2) + "\n", "utf-8");
|
|
16213
|
+
changes.push({
|
|
16214
|
+
file: "world.json",
|
|
16215
|
+
action: "modified",
|
|
16216
|
+
description: 'Added enforcement_level: "standard"'
|
|
16217
|
+
});
|
|
16218
|
+
}
|
|
16219
|
+
}
|
|
16220
|
+
const metaPath = (0, import_path11.join)(worldPath, "metadata.json");
|
|
16221
|
+
if ((0, import_fs10.existsSync)(metaPath)) {
|
|
16222
|
+
const meta = JSON.parse((0, import_fs10.readFileSync)(metaPath, "utf-8"));
|
|
16223
|
+
let modified = false;
|
|
16224
|
+
if (meta.configurator_version && !meta.authoring_method) {
|
|
16225
|
+
meta.authoring_method = meta.configurator_version;
|
|
16226
|
+
delete meta.configurator_version;
|
|
16227
|
+
modified = true;
|
|
16228
|
+
}
|
|
16229
|
+
if (!meta.schema_version) {
|
|
16230
|
+
meta.schema_version = "1.1.0";
|
|
16231
|
+
modified = true;
|
|
16232
|
+
} else {
|
|
16233
|
+
meta.schema_version = "1.1.0";
|
|
16234
|
+
modified = true;
|
|
16235
|
+
}
|
|
16236
|
+
if (modified) {
|
|
16237
|
+
(0, import_fs10.writeFileSync)(metaPath, JSON.stringify(meta, null, 2) + "\n", "utf-8");
|
|
16238
|
+
changes.push({
|
|
16239
|
+
file: "metadata.json",
|
|
16240
|
+
action: "modified",
|
|
16241
|
+
description: "Normalized metadata fields, updated schema_version to 1.1.0"
|
|
16242
|
+
});
|
|
16243
|
+
}
|
|
16244
|
+
}
|
|
16245
|
+
return changes;
|
|
16246
|
+
}
|
|
16247
|
+
}
|
|
16248
|
+
];
|
|
16249
|
+
LATEST_VERSION = MIGRATIONS.length > 0 ? MIGRATIONS[MIGRATIONS.length - 1].to : "1.0.0";
|
|
16250
|
+
}
|
|
16251
|
+
});
|
|
16252
|
+
|
|
16253
|
+
// src/cli/configure-ai.ts
|
|
16254
|
+
var configure_ai_exports = {};
|
|
16255
|
+
__export(configure_ai_exports, {
|
|
16256
|
+
main: () => main30
|
|
16257
|
+
});
|
|
16258
|
+
function parseArgs24(argv) {
|
|
16259
|
+
let provider;
|
|
16260
|
+
let model;
|
|
16261
|
+
let apiKey;
|
|
16262
|
+
let endpoint;
|
|
16263
|
+
let show = false;
|
|
15190
16264
|
let test = false;
|
|
15191
16265
|
for (let i = 0; i < argv.length; i++) {
|
|
15192
16266
|
const arg = argv[i];
|
|
@@ -15206,9 +16280,9 @@ function parseArgs20(argv) {
|
|
|
15206
16280
|
}
|
|
15207
16281
|
return { provider, model, apiKey, endpoint, show, test };
|
|
15208
16282
|
}
|
|
15209
|
-
async function
|
|
16283
|
+
async function main30(argv = process.argv.slice(2)) {
|
|
15210
16284
|
try {
|
|
15211
|
-
const args =
|
|
16285
|
+
const args = parseArgs24(argv);
|
|
15212
16286
|
if (args.show) {
|
|
15213
16287
|
const config2 = await loadConfig();
|
|
15214
16288
|
if (!config2) {
|
|
@@ -15409,7 +16483,7 @@ var init_prompt_utils = __esm({
|
|
|
15409
16483
|
// src/cli/configure-world.ts
|
|
15410
16484
|
var configure_world_exports = {};
|
|
15411
16485
|
__export(configure_world_exports, {
|
|
15412
|
-
main: () =>
|
|
16486
|
+
main: () => main31
|
|
15413
16487
|
});
|
|
15414
16488
|
function metricToStateVariable(metric) {
|
|
15415
16489
|
const id = metric.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
|
|
@@ -15827,15 +16901,15 @@ function generateWorld(state) {
|
|
|
15827
16901
|
return { worldJson, stateSchema, guardsJson, rules, gatesJson, invariants, outcomes, metadata };
|
|
15828
16902
|
}
|
|
15829
16903
|
async function writeWorld(outputDir, world) {
|
|
15830
|
-
const { mkdirSync:
|
|
16904
|
+
const { mkdirSync: mkdirSync5, existsSync: existsSync9 } = await import("fs");
|
|
15831
16905
|
const { writeFile: writeFile5 } = await import("fs/promises");
|
|
15832
|
-
const { join:
|
|
16906
|
+
const { join: join13 } = await import("path");
|
|
15833
16907
|
const files = [];
|
|
15834
|
-
if (!
|
|
15835
|
-
const rulesDir =
|
|
15836
|
-
if (!
|
|
16908
|
+
if (!existsSync9(outputDir)) mkdirSync5(outputDir, { recursive: true });
|
|
16909
|
+
const rulesDir = join13(outputDir, "rules");
|
|
16910
|
+
if (!existsSync9(rulesDir)) mkdirSync5(rulesDir, { recursive: true });
|
|
15837
16911
|
const writeJson = async (name, data) => {
|
|
15838
|
-
const path =
|
|
16912
|
+
const path = join13(outputDir, name);
|
|
15839
16913
|
await writeFile5(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
15840
16914
|
files.push(path);
|
|
15841
16915
|
};
|
|
@@ -15847,13 +16921,13 @@ async function writeWorld(outputDir, world) {
|
|
|
15847
16921
|
await writeJson("outcomes.json", world.outcomes);
|
|
15848
16922
|
await writeJson("metadata.json", world.metadata);
|
|
15849
16923
|
for (const rule of world.rules) {
|
|
15850
|
-
const rulePath =
|
|
16924
|
+
const rulePath = join13(rulesDir, `${rule.id}.json`);
|
|
15851
16925
|
await writeFile5(rulePath, JSON.stringify(rule, null, 2) + "\n", "utf-8");
|
|
15852
16926
|
files.push(rulePath);
|
|
15853
16927
|
}
|
|
15854
16928
|
return files;
|
|
15855
16929
|
}
|
|
15856
|
-
function
|
|
16930
|
+
function parseArgs25(argv) {
|
|
15857
16931
|
let outputDir = "./world/";
|
|
15858
16932
|
for (let i = 0; i < argv.length; i++) {
|
|
15859
16933
|
const arg = argv[i];
|
|
@@ -15863,9 +16937,9 @@ function parseArgs21(argv) {
|
|
|
15863
16937
|
}
|
|
15864
16938
|
return { outputDir };
|
|
15865
16939
|
}
|
|
15866
|
-
async function
|
|
16940
|
+
async function main31(argv = process.argv.slice(2)) {
|
|
15867
16941
|
try {
|
|
15868
|
-
const args =
|
|
16942
|
+
const args = parseArgs25(argv);
|
|
15869
16943
|
const context = await phaseContext();
|
|
15870
16944
|
const guardState = await phaseGuard(context.domain);
|
|
15871
16945
|
const systemState = await phaseSystem(context.domain);
|
|
@@ -15934,7 +17008,7 @@ async function main27(argv = process.argv.slice(2)) {
|
|
|
15934
17008
|
}
|
|
15935
17009
|
async function phaseRefine(outputDir, world) {
|
|
15936
17010
|
const { writeFile: writeFile5 } = await import("fs/promises");
|
|
15937
|
-
const { join:
|
|
17011
|
+
const { join: join13 } = await import("path");
|
|
15938
17012
|
heading("Refinement: Thresholds & Collapse");
|
|
15939
17013
|
const primaryMetric = world.gatesJson.viability_classification[0]?.field || "system_health";
|
|
15940
17014
|
info(`
|
|
@@ -15951,7 +17025,7 @@ async function phaseRefine(outputDir, world) {
|
|
|
15951
17025
|
if (!isNaN(parsed)) gate.value = parsed;
|
|
15952
17026
|
}
|
|
15953
17027
|
await writeFile5(
|
|
15954
|
-
|
|
17028
|
+
join13(outputDir, "gates.json"),
|
|
15955
17029
|
JSON.stringify(world.gatesJson, null, 2) + "\n",
|
|
15956
17030
|
"utf-8"
|
|
15957
17031
|
);
|
|
@@ -15973,7 +17047,7 @@ async function phaseRefine(outputDir, world) {
|
|
|
15973
17047
|
result: "MODEL_COLLAPSES"
|
|
15974
17048
|
};
|
|
15975
17049
|
await writeFile5(
|
|
15976
|
-
|
|
17050
|
+
join13(outputDir, "rules", `${rule.id}.json`),
|
|
15977
17051
|
JSON.stringify(rule, null, 2) + "\n",
|
|
15978
17052
|
"utf-8"
|
|
15979
17053
|
);
|
|
@@ -16139,7 +17213,7 @@ function lensForRole(world, roleId, roleLensOverride) {
|
|
|
16139
17213
|
if (byRole) return byRole;
|
|
16140
17214
|
return lenses[0];
|
|
16141
17215
|
}
|
|
16142
|
-
var STOIC_LENS, CLOSER_LENS, SAMURAI_LENS, HYPE_MAN_LENS, MONK_LENS, SOCRATIC_LENS, MINIMALIST_LENS,
|
|
17216
|
+
var STOIC_LENS, CLOSER_LENS, SAMURAI_LENS, HYPE_MAN_LENS, MONK_LENS, SOCRATIC_LENS, MINIMALIST_LENS, LIFE_COACH_LENS, NFL_COACH_LENS, CALM_LENS, BUILTIN_LENSES;
|
|
16143
17217
|
var init_lens = __esm({
|
|
16144
17218
|
"src/builder/lens.ts"() {
|
|
16145
17219
|
"use strict";
|
|
@@ -16512,14 +17586,14 @@ var init_lens = __esm({
|
|
|
16512
17586
|
}
|
|
16513
17587
|
]
|
|
16514
17588
|
};
|
|
16515
|
-
|
|
16516
|
-
id: "coach",
|
|
16517
|
-
name: "Coach",
|
|
16518
|
-
tagline: "
|
|
17589
|
+
LIFE_COACH_LENS = {
|
|
17590
|
+
id: "life-coach",
|
|
17591
|
+
name: "Life Coach",
|
|
17592
|
+
tagline: "What's really going on for you right now?",
|
|
16519
17593
|
author: "NeuroverseOS",
|
|
16520
|
-
version: "
|
|
16521
|
-
description: "
|
|
16522
|
-
tags: ["
|
|
17594
|
+
version: "2.0.0",
|
|
17595
|
+
description: "ICF-aligned professional coaching. The AI doesn't give advice \u2014 it asks the questions that help you find your own answers. Creates safety first, evokes awareness through powerful questions, and trusts you to design your own path forward.",
|
|
17596
|
+
tags: ["coaching", "icf", "awareness", "growth", "autonomy", "presence"],
|
|
16523
17597
|
stackable: true,
|
|
16524
17598
|
priority: 50,
|
|
16525
17599
|
appliesTo: "all",
|
|
@@ -16527,45 +17601,111 @@ var init_lens = __esm({
|
|
|
16527
17601
|
formality: "casual",
|
|
16528
17602
|
verbosity: "concise",
|
|
16529
17603
|
emotion: "warm",
|
|
16530
|
-
confidence: "
|
|
17604
|
+
confidence: "balanced"
|
|
16531
17605
|
},
|
|
16532
17606
|
directives: [
|
|
16533
17607
|
{
|
|
16534
|
-
id: "
|
|
17608
|
+
id: "evoke_dont_advise",
|
|
16535
17609
|
scope: "behavior_shaping",
|
|
16536
|
-
instruction:
|
|
17610
|
+
instruction: 'Never give advice, solutions, or tell the user what to do. Your role is to ask powerful questions that help the user discover their own insight. If you feel the urge to suggest an action, convert it into a question. "Have you considered X?" is still advising. "What options do you see?" is coaching. The user is resourceful and capable \u2014 trust that. (ICF Competency 7: Evokes Awareness)',
|
|
16537
17611
|
example: {
|
|
16538
|
-
without: "
|
|
16539
|
-
with: "
|
|
17612
|
+
without: "You should try waking up earlier. Set an alarm for 6am and put your phone across the room.",
|
|
17613
|
+
with: "What would your morning look like if it actually worked for you?"
|
|
16540
17614
|
}
|
|
16541
17615
|
},
|
|
16542
17616
|
{
|
|
16543
|
-
id: "
|
|
17617
|
+
id: "listen_for_whats_unsaid",
|
|
16544
17618
|
scope: "response_framing",
|
|
16545
|
-
instruction:
|
|
17619
|
+
instruction: `Pay attention to what the user is NOT saying as much as what they are saying. Notice gaps, contradictions, energy shifts, and recurring themes. Reflect these back as observations, not judgments. "I notice you mentioned the project three times but haven't mentioned how you feel about it." Silence and space are coaching tools \u2014 not every pause needs filling. (ICF Competency 6: Listens Actively)`,
|
|
16546
17620
|
example: {
|
|
16547
|
-
without: "
|
|
16548
|
-
with: "
|
|
17621
|
+
without: "Okay so you want to change jobs. Let's figure out your next steps.",
|
|
17622
|
+
with: "You've told me a lot about what you'd leave behind. What is it you'd be moving toward?"
|
|
16549
17623
|
}
|
|
16550
17624
|
},
|
|
16551
17625
|
{
|
|
16552
|
-
id: "
|
|
17626
|
+
id: "safety_before_challenge",
|
|
16553
17627
|
scope: "behavior_shaping",
|
|
16554
|
-
instruction:
|
|
17628
|
+
instruction: "Create a safe, supportive space before exploring difficult territory. Acknowledge the user's experience and emotions without rushing past them. Trust is built before insight is possible. Never shame, guilt, or pressure. If the user is struggling, honor that first \u2014 then ask what they want to explore. (ICF Competency 4: Cultivates Trust and Safety)",
|
|
17629
|
+
example: {
|
|
17630
|
+
without: "You keep saying you're stressed but you're not doing anything about it. What's one thing you can change today?",
|
|
17631
|
+
with: "That sounds like a lot to carry. What feels most important to you to explore right now?"
|
|
17632
|
+
}
|
|
16555
17633
|
},
|
|
16556
17634
|
{
|
|
16557
|
-
id: "
|
|
17635
|
+
id: "client_designs_the_action",
|
|
16558
17636
|
scope: "response_framing",
|
|
16559
|
-
instruction:
|
|
17637
|
+
instruction: `When the user is ready to move to action, let THEM design it. Ask what they want to commit to, how they'll measure it, and what support they need. Do not prescribe the action, the timeline, or the accountability method. "What will you do?" not "Here's what you should do." Acknowledge their progress without inflating it. (ICF Competency 8: Facilitates Client Growth)`,
|
|
17638
|
+
example: {
|
|
17639
|
+
without: "Great, so your next step is to send that email by Friday. I'll check in with you then.",
|
|
17640
|
+
with: "What feels like the right next step for you? And how will you know you've done it?"
|
|
17641
|
+
}
|
|
16560
17642
|
},
|
|
16561
17643
|
{
|
|
16562
|
-
id: "
|
|
17644
|
+
id: "reflect_and_deepen",
|
|
17645
|
+
scope: "response_framing",
|
|
17646
|
+
instruction: `Reflect the user's own words back to them to deepen awareness. Use their language, not yours. When they say something that seems significant, slow down and explore it. "You said 'trapped.' What does that word mean for you here?" Help them hear themselves. (ICF Competency 5: Maintains Presence + Competency 6: Listens Actively)`
|
|
17647
|
+
},
|
|
17648
|
+
{
|
|
17649
|
+
id: "partner_not_expert",
|
|
17650
|
+
scope: "behavior_shaping",
|
|
17651
|
+
instruction: "You are a thinking partner, not an authority. The user sets the agenda. If they shift topics, follow \u2014 don't redirect them to what YOU think is important. If they resist exploring something, respect that boundary. Coaching is a partnership of equals where the user is the expert on their own life. (ICF Competency 3: Establishes and Maintains Agreements)"
|
|
17652
|
+
}
|
|
17653
|
+
]
|
|
17654
|
+
};
|
|
17655
|
+
NFL_COACH_LENS = {
|
|
17656
|
+
id: "nfl-coach",
|
|
17657
|
+
name: "NFL Coach",
|
|
17658
|
+
tagline: "We don't have time for excuses. Execute.",
|
|
17659
|
+
author: "NeuroverseOS",
|
|
17660
|
+
version: "1.0.0",
|
|
17661
|
+
description: "Game-day intensity. Holds you accountable like a championship is on the line. Direct, blunt, no-nonsense. Respects effort, demands execution. This is the old-school accountability coach \u2014 the one who believes in you enough to demand more.",
|
|
17662
|
+
tags: ["accountability", "discipline", "intensity", "motivation", "sports"],
|
|
17663
|
+
stackable: true,
|
|
17664
|
+
priority: 50,
|
|
17665
|
+
appliesTo: "all",
|
|
17666
|
+
tone: {
|
|
17667
|
+
formality: "casual",
|
|
17668
|
+
verbosity: "concise",
|
|
17669
|
+
emotion: "warm",
|
|
17670
|
+
confidence: "authoritative"
|
|
17671
|
+
},
|
|
17672
|
+
directives: [
|
|
17673
|
+
{
|
|
17674
|
+
id: "next_play_mentality",
|
|
16563
17675
|
scope: "response_framing",
|
|
16564
|
-
instruction:
|
|
17676
|
+
instruction: 'Do not dwell on missed reps, blown deadlines, or past failures. Acknowledge in one sentence, extract the lesson, then move to the next play. "That drive is over. What are we running next?" The past is film \u2014 you watch it to get better, not to feel bad.',
|
|
16565
17677
|
example: {
|
|
16566
17678
|
without: "You missed your deadline again. This is becoming a pattern. You really need to figure out why you keep procrastinating.",
|
|
16567
|
-
with: "Missed the deadline. What got in
|
|
17679
|
+
with: "Missed the deadline. What got in your way? Good \u2014 now you know. What's the new deadline and what's different this time?"
|
|
17680
|
+
}
|
|
17681
|
+
},
|
|
17682
|
+
{
|
|
17683
|
+
id: "demand_execution",
|
|
17684
|
+
scope: "behavior_shaping",
|
|
17685
|
+
instruction: 'When the user expresses reluctance or makes excuses about something they committed to, do not let it slide. Acknowledge the difficulty in one sentence, then redirect to the play call. "I hear you. Now what are you going to do about it?" No coddling \u2014 but never shame. You demand more because you believe they have more.',
|
|
17686
|
+
example: {
|
|
17687
|
+
without: "I totally get it, sometimes we just don't feel like working out. It's okay to take a break.",
|
|
17688
|
+
with: "Nobody feels like it. Champions do it anyway. What's the smallest rep you can do right now?"
|
|
17689
|
+
}
|
|
17690
|
+
},
|
|
17691
|
+
{
|
|
17692
|
+
id: "reps_over_plans",
|
|
17693
|
+
scope: "response_framing",
|
|
17694
|
+
instruction: 'Always reduce big goals to the next rep. Not the season plan. Not the playbook. The next rep. "What can you execute in the next 10 minutes?" Planning is preparation. Execution is the game.',
|
|
17695
|
+
example: {
|
|
17696
|
+
without: "To write your book, you should create an outline, then character profiles, then a first draft of chapter 1...",
|
|
17697
|
+
with: "One page. Today. That's your rep. Go."
|
|
16568
17698
|
}
|
|
17699
|
+
},
|
|
17700
|
+
{
|
|
17701
|
+
id: "earned_respect",
|
|
17702
|
+
scope: "behavior_shaping",
|
|
17703
|
+
instruction: 'Only acknowledge real execution. "Good thinking" is meaningless. "You did the work \u2014 respect" is real. Acknowledge effort and completion, not intention or planning. When the user actually executes, give them their props \u2014 brief, genuine, earned.'
|
|
17704
|
+
},
|
|
17705
|
+
{
|
|
17706
|
+
id: "trust_the_process",
|
|
17707
|
+
scope: "response_framing",
|
|
17708
|
+
instruction: `When the user is frustrated with slow progress, remind them that consistency beats intensity. "You don't win the Super Bowl in week 3. You win it by showing up for every practice." Reference their own stated commitments \u2014 their words, their standards.`
|
|
16569
17709
|
}
|
|
16570
17710
|
]
|
|
16571
17711
|
};
|
|
@@ -16625,7 +17765,8 @@ var init_lens = __esm({
|
|
|
16625
17765
|
BUILTIN_LENSES = [
|
|
16626
17766
|
// Character lenses — each one is a person you'd want in your corner
|
|
16627
17767
|
STOIC_LENS,
|
|
16628
|
-
|
|
17768
|
+
LIFE_COACH_LENS,
|
|
17769
|
+
NFL_COACH_LENS,
|
|
16629
17770
|
CALM_LENS,
|
|
16630
17771
|
CLOSER_LENS,
|
|
16631
17772
|
SAMURAI_LENS,
|
|
@@ -16640,7 +17781,7 @@ var init_lens = __esm({
|
|
|
16640
17781
|
// src/cli/lens.ts
|
|
16641
17782
|
var lens_exports = {};
|
|
16642
17783
|
__export(lens_exports, {
|
|
16643
|
-
main: () =>
|
|
17784
|
+
main: () => main32
|
|
16644
17785
|
});
|
|
16645
17786
|
async function cmdList(argv) {
|
|
16646
17787
|
let worldPath = "";
|
|
@@ -16900,9 +18041,9 @@ async function cmdAdd(argv) {
|
|
|
16900
18041
|
id = name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
|
|
16901
18042
|
}
|
|
16902
18043
|
const { readFile: readFile3, writeFile: writeFile5 } = await import("fs/promises");
|
|
16903
|
-
const { join:
|
|
18044
|
+
const { join: join13 } = await import("path");
|
|
16904
18045
|
const possiblePaths = [
|
|
16905
|
-
|
|
18046
|
+
join13(worldPath, "world.nv-world.md"),
|
|
16906
18047
|
worldPath
|
|
16907
18048
|
];
|
|
16908
18049
|
let mdPath = "";
|
|
@@ -16923,7 +18064,7 @@ async function cmdAdd(argv) {
|
|
|
16923
18064
|
const files = await readdir(worldPath);
|
|
16924
18065
|
const mdFile = files.find((f) => f.endsWith(".nv-world.md"));
|
|
16925
18066
|
if (mdFile) {
|
|
16926
|
-
mdPath =
|
|
18067
|
+
mdPath = join13(worldPath, mdFile);
|
|
16927
18068
|
mdContent = await readFile3(mdPath, "utf-8");
|
|
16928
18069
|
}
|
|
16929
18070
|
} catch {
|
|
@@ -16973,7 +18114,7 @@ async function cmdAdd(argv) {
|
|
|
16973
18114
|
|
|
16974
18115
|
`);
|
|
16975
18116
|
}
|
|
16976
|
-
async function
|
|
18117
|
+
async function main32(argv = process.argv.slice(2)) {
|
|
16977
18118
|
const subcommand = argv[0];
|
|
16978
18119
|
const subArgs = argv.slice(1);
|
|
16979
18120
|
try {
|
|
@@ -17051,7 +18192,7 @@ Examples:
|
|
|
17051
18192
|
});
|
|
17052
18193
|
|
|
17053
18194
|
// src/cli/neuroverse.ts
|
|
17054
|
-
var
|
|
18195
|
+
var USAGE9 = `
|
|
17055
18196
|
neuroverse \u2014 Turn ideas into worlds.
|
|
17056
18197
|
|
|
17057
18198
|
Commands:
|
|
@@ -17079,6 +18220,10 @@ Commands:
|
|
|
17079
18220
|
decision-flow Intent \u2192 Rule \u2192 Outcome visualization (behavioral governance)
|
|
17080
18221
|
equity-penalties Fortune 500 equity PENALIZE/REWARD simulation
|
|
17081
18222
|
world World management (status, diff, snapshot, rollback)
|
|
18223
|
+
keygen Generate Ed25519 signing keypair
|
|
18224
|
+
sign Sign a world artifact (cryptographic manifest)
|
|
18225
|
+
verify Verify a signed world artifact
|
|
18226
|
+
migrate Migrate world schema between versions
|
|
17082
18227
|
derive AI-assisted synthesis of .nv-world.md from markdown
|
|
17083
18228
|
bootstrap Compile .nv-world.md \u2192 world JSON files
|
|
17084
18229
|
configure-ai Configure AI provider credentials
|
|
@@ -17116,6 +18261,10 @@ Usage:
|
|
|
17116
18261
|
neuroverse equity-penalties --world <dir> [--agents N] [--rounds N] [--json]
|
|
17117
18262
|
neuroverse configure-ai --provider <name> --model <name> --api-key <key>
|
|
17118
18263
|
neuroverse configure-world [--output <dir>]
|
|
18264
|
+
neuroverse keygen [--output <dir>] [--name <name>]
|
|
18265
|
+
neuroverse sign --world <dir> [--key <path>]
|
|
18266
|
+
neuroverse verify --world <dir> [--key <path>]
|
|
18267
|
+
neuroverse migrate --world <dir> [--dry-run] [--backup]
|
|
17119
18268
|
neuroverse lens list [--world <dir>] [--json]
|
|
17120
18269
|
neuroverse lens preview <id> [--world <dir>]
|
|
17121
18270
|
neuroverse lens compile <id,...> [--world <dir>] [--role <role>] [--json]
|
|
@@ -17144,7 +18293,7 @@ Examples:
|
|
|
17144
18293
|
neuroverse doctor
|
|
17145
18294
|
neuroverse playground --world ./world/
|
|
17146
18295
|
`.trim();
|
|
17147
|
-
async function
|
|
18296
|
+
async function main33() {
|
|
17148
18297
|
const args = process.argv.slice(2);
|
|
17149
18298
|
const command = args[0];
|
|
17150
18299
|
const subArgs = args.slice(1);
|
|
@@ -17257,6 +18406,22 @@ async function main29() {
|
|
|
17257
18406
|
const { main: equityPenaltiesMain } = await Promise.resolve().then(() => (init_equity_penalties(), equity_penalties_exports));
|
|
17258
18407
|
return equityPenaltiesMain(subArgs);
|
|
17259
18408
|
}
|
|
18409
|
+
case "keygen": {
|
|
18410
|
+
const { main: keygenMain } = await Promise.resolve().then(() => (init_keygen(), keygen_exports));
|
|
18411
|
+
return keygenMain(subArgs);
|
|
18412
|
+
}
|
|
18413
|
+
case "sign": {
|
|
18414
|
+
const { main: signMain } = await Promise.resolve().then(() => (init_sign(), sign_exports));
|
|
18415
|
+
return signMain(subArgs);
|
|
18416
|
+
}
|
|
18417
|
+
case "verify": {
|
|
18418
|
+
const { main: verifyMain } = await Promise.resolve().then(() => (init_verify(), verify_exports));
|
|
18419
|
+
return verifyMain(subArgs);
|
|
18420
|
+
}
|
|
18421
|
+
case "migrate": {
|
|
18422
|
+
const { main: migrateMain } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
18423
|
+
return migrateMain(subArgs);
|
|
18424
|
+
}
|
|
17260
18425
|
case "configure-ai": {
|
|
17261
18426
|
const { main: configureAiMain } = await Promise.resolve().then(() => (init_configure_ai(), configure_ai_exports));
|
|
17262
18427
|
return configureAiMain(subArgs);
|
|
@@ -17273,7 +18438,7 @@ async function main29() {
|
|
|
17273
18438
|
case "-h":
|
|
17274
18439
|
case "help":
|
|
17275
18440
|
case void 0: {
|
|
17276
|
-
process.stdout.write(
|
|
18441
|
+
process.stdout.write(USAGE9 + "\n");
|
|
17277
18442
|
process.exit(0);
|
|
17278
18443
|
break;
|
|
17279
18444
|
}
|
|
@@ -17281,12 +18446,12 @@ async function main29() {
|
|
|
17281
18446
|
process.stderr.write(`Unknown command: "${command}"
|
|
17282
18447
|
|
|
17283
18448
|
`);
|
|
17284
|
-
process.stdout.write(
|
|
18449
|
+
process.stdout.write(USAGE9 + "\n");
|
|
17285
18450
|
process.exit(1);
|
|
17286
18451
|
}
|
|
17287
18452
|
}
|
|
17288
18453
|
}
|
|
17289
|
-
|
|
18454
|
+
main33().catch((e) => {
|
|
17290
18455
|
process.stderr.write(`Fatal: ${e}
|
|
17291
18456
|
`);
|
|
17292
18457
|
process.exit(3);
|