@neuroverseos/governance 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE.md +190 -0
  2. package/README.md +472 -115
  3. package/dist/adapters/express.cjs +874 -0
  4. package/dist/adapters/express.d.cts +66 -0
  5. package/dist/adapters/express.d.ts +66 -0
  6. package/dist/adapters/express.js +10 -0
  7. package/dist/adapters/index.cjs +1166 -0
  8. package/dist/adapters/index.d.cts +5 -0
  9. package/dist/adapters/index.d.ts +5 -0
  10. package/dist/adapters/index.js +40 -0
  11. package/dist/adapters/langchain.cjs +861 -0
  12. package/dist/adapters/langchain.d.cts +82 -0
  13. package/dist/adapters/langchain.d.ts +82 -0
  14. package/dist/adapters/langchain.js +14 -0
  15. package/dist/adapters/openai.cjs +891 -0
  16. package/dist/adapters/openai.d.cts +92 -0
  17. package/dist/adapters/openai.d.ts +92 -0
  18. package/dist/adapters/openai.js +14 -0
  19. package/dist/adapters/openclaw.cjs +883 -0
  20. package/dist/adapters/openclaw.d.cts +92 -0
  21. package/dist/adapters/openclaw.d.ts +92 -0
  22. package/dist/adapters/openclaw.js +14 -0
  23. package/dist/bootstrap-H4HHKQ5G.js +113 -0
  24. package/dist/build-73KAVHEY.js +308 -0
  25. package/dist/chunk-4NGDRRQH.js +10 -0
  26. package/dist/chunk-B4NF3OLW.js +673 -0
  27. package/dist/chunk-BUWWN2NX.js +192 -0
  28. package/dist/chunk-CROPZ75A.js +107 -0
  29. package/dist/chunk-D7BGWV2J.js +620 -0
  30. package/dist/chunk-EIUHJXBB.js +340 -0
  31. package/dist/chunk-EQXFOKH2.js +85 -0
  32. package/dist/chunk-FYPYZFV5.js +187 -0
  33. package/dist/chunk-FYS2CBUW.js +304 -0
  34. package/dist/chunk-FZQCRGUU.js +115 -0
  35. package/dist/chunk-I3RRAYK2.js +11 -0
  36. package/dist/chunk-ITJ3LCPG.js +225 -0
  37. package/dist/chunk-M3TZFGHO.js +79 -0
  38. package/dist/chunk-MWDQ4MJB.js +11 -0
  39. package/dist/chunk-O5OMJMIE.js +590 -0
  40. package/dist/chunk-T4X42QXC.js +121 -0
  41. package/dist/chunk-XPDMYECO.js +642 -0
  42. package/dist/chunk-Z2S2HIV5.js +100 -0
  43. package/dist/cli/neuroverse.cjs +5864 -0
  44. package/dist/cli/neuroverse.d.cts +1 -0
  45. package/dist/cli/neuroverse.d.ts +1 -0
  46. package/dist/cli/neuroverse.js +128 -0
  47. package/dist/configure-ai-46JVG56I.js +129 -0
  48. package/dist/derive-6NAEWLM5.js +150 -0
  49. package/dist/explain-3B3VB6TL.js +69 -0
  50. package/dist/guard-67Y66P3I.js +82 -0
  51. package/dist/guard-contract-D_RQz9kt.d.cts +529 -0
  52. package/dist/guard-contract-D_RQz9kt.d.ts +529 -0
  53. package/dist/impact-CHERK3O6.js +57 -0
  54. package/dist/improve-YG6I6ERG.js +84 -0
  55. package/dist/index.cjs +4227 -0
  56. package/dist/index.d.cts +1147 -0
  57. package/dist/index.d.ts +1139 -25
  58. package/dist/index.js +318 -1159
  59. package/dist/init-Z66T6TDI.js +142 -0
  60. package/dist/simulate-ETHHINZ4.js +107 -0
  61. package/dist/trace-3YODSSIP.js +164 -0
  62. package/dist/validate-UVE6GKQU.js +72 -0
  63. package/dist/validate-engine-657D75OG.js +6 -0
  64. package/dist/world-WLNHL5XC.js +298 -0
  65. package/dist/worlds/derivation-world.nv-world.md +278 -0
  66. package/package.json +74 -26
  67. package/LICENSE +0 -21
  68. package/dist/audit-logger.d.ts +0 -38
  69. package/dist/audit-logger.d.ts.map +0 -1
  70. package/dist/audit-logger.js +0 -100
  71. package/dist/audit-logger.js.map +0 -1
  72. package/dist/condition-engine.d.ts +0 -16
  73. package/dist/condition-engine.d.ts.map +0 -1
  74. package/dist/condition-engine.js +0 -186
  75. package/dist/condition-engine.js.map +0 -1
  76. package/dist/drift-monitor.d.ts +0 -81
  77. package/dist/drift-monitor.d.ts.map +0 -1
  78. package/dist/drift-monitor.js +0 -228
  79. package/dist/drift-monitor.js.map +0 -1
  80. package/dist/governance-engine.d.ts +0 -131
  81. package/dist/governance-engine.d.ts.map +0 -1
  82. package/dist/governance-engine.js +0 -660
  83. package/dist/governance-engine.js.map +0 -1
  84. package/dist/index.d.ts.map +0 -1
  85. package/dist/index.js.map +0 -1
  86. package/dist/types.d.ts +0 -196
  87. package/dist/types.d.ts.map +0 -1
  88. package/dist/types.js +0 -9
  89. package/dist/types.js.map +0 -1
  90. package/dist/world-bootstrap.d.ts +0 -31
  91. package/dist/world-bootstrap.d.ts.map +0 -1
  92. package/dist/world-bootstrap.js +0 -415
  93. package/dist/world-bootstrap.js.map +0 -1
  94. package/openclaw.plugin.json +0 -59
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli/neuroverse.ts
4
+ var USAGE = `
5
+ neuroverse \u2014 Turn ideas into worlds.
6
+
7
+ Commands:
8
+ build Build a world from markdown (derive + compile in one step)
9
+ explain Human-readable summary of a compiled world
10
+ simulate Step-by-step state evolution
11
+ improve Actionable suggestions for strengthening a world
12
+ init Scaffold a new .nv-world.md template
13
+ validate Static analysis on world files
14
+ guard Runtime governance evaluation (stdin \u2192 stdout)
15
+ trace Runtime action audit log
16
+ impact Counterfactual governance impact report
17
+ world World management (status, diff, snapshot, rollback)
18
+ derive AI-assisted synthesis of .nv-world.md from markdown
19
+ bootstrap Compile .nv-world.md \u2192 world JSON files
20
+ configure-ai Configure AI provider credentials
21
+
22
+ Usage:
23
+ neuroverse build <input.md> [--output <dir>]
24
+ neuroverse explain <world-path-or-id> [--json]
25
+ neuroverse simulate <world-path-or-id> [--steps N] [--set key=value] [--profile name]
26
+ neuroverse improve <world-path-or-id> [--json]
27
+ neuroverse init [--name "World Name"] [--output path]
28
+ neuroverse validate --world <dir> [--format full|summary|findings]
29
+ neuroverse guard --world <dir> [--trace] [--level basic|standard|strict]
30
+ neuroverse trace [--log <path>] [--summary] [--filter BLOCK] [--last 20]
31
+ neuroverse impact [--log <path>] [--json]
32
+ neuroverse world status <path>
33
+ neuroverse world diff <path1> <path2>
34
+ neuroverse world snapshot <path>
35
+ neuroverse world rollback <path>
36
+ neuroverse derive --input <path> [--output <path>] [--dry-run]
37
+ neuroverse bootstrap --input <.md> --output <dir> [--validate]
38
+ neuroverse configure-ai --provider <name> --model <name> --api-key <key>
39
+
40
+ Examples:
41
+ neuroverse build horror-notes.md
42
+ neuroverse explain inherited_silence
43
+ neuroverse simulate inherited_silence --steps 5
44
+ neuroverse improve inherited_silence
45
+ neuroverse build ./docs/ --output ./my-world/
46
+ neuroverse init --name "Customer Service Governance"
47
+ neuroverse validate --world ./world/ --format summary
48
+ echo '{"intent":"delete user data"}' | neuroverse guard --world ./world/ --trace
49
+ `.trim();
50
+ async function main() {
51
+ const args = process.argv.slice(2);
52
+ const command = args[0];
53
+ const subArgs = args.slice(1);
54
+ switch (command) {
55
+ case "build": {
56
+ const { main: buildMain } = await import("../build-73KAVHEY.js");
57
+ return buildMain(subArgs);
58
+ }
59
+ case "explain": {
60
+ const { main: explainMain } = await import("../explain-3B3VB6TL.js");
61
+ return explainMain(subArgs);
62
+ }
63
+ case "simulate": {
64
+ const { main: simulateMain } = await import("../simulate-ETHHINZ4.js");
65
+ return simulateMain(subArgs);
66
+ }
67
+ case "improve": {
68
+ const { main: improveMain } = await import("../improve-YG6I6ERG.js");
69
+ return improveMain(subArgs);
70
+ }
71
+ case "init": {
72
+ const { main: initMain } = await import("../init-Z66T6TDI.js");
73
+ return initMain(subArgs);
74
+ }
75
+ case "bootstrap": {
76
+ const { main: bootstrapMain } = await import("../bootstrap-H4HHKQ5G.js");
77
+ return bootstrapMain(subArgs);
78
+ }
79
+ case "validate": {
80
+ const { main: validateMain } = await import("../validate-UVE6GKQU.js");
81
+ return validateMain(subArgs);
82
+ }
83
+ case "guard": {
84
+ const { main: guardMain } = await import("../guard-67Y66P3I.js");
85
+ return guardMain(subArgs);
86
+ }
87
+ case "trace": {
88
+ const { main: traceMain } = await import("../trace-3YODSSIP.js");
89
+ return traceMain(subArgs);
90
+ }
91
+ case "impact": {
92
+ const { main: impactMain } = await import("../impact-CHERK3O6.js");
93
+ return impactMain(subArgs);
94
+ }
95
+ case "world": {
96
+ const { main: worldMain } = await import("../world-WLNHL5XC.js");
97
+ return worldMain(subArgs);
98
+ }
99
+ case "derive": {
100
+ const { main: deriveMain } = await import("../derive-6NAEWLM5.js");
101
+ return deriveMain(subArgs);
102
+ }
103
+ case "configure-ai": {
104
+ const { main: configureAiMain } = await import("../configure-ai-46JVG56I.js");
105
+ return configureAiMain(subArgs);
106
+ }
107
+ case "--help":
108
+ case "-h":
109
+ case "help":
110
+ case void 0: {
111
+ process.stdout.write(USAGE + "\n");
112
+ process.exit(0);
113
+ break;
114
+ }
115
+ default: {
116
+ process.stderr.write(`Unknown command: "${command}"
117
+
118
+ `);
119
+ process.stdout.write(USAGE + "\n");
120
+ process.exit(1);
121
+ }
122
+ }
123
+ }
124
+ main().catch((e) => {
125
+ process.stderr.write(`Fatal: ${e}
126
+ `);
127
+ process.exit(3);
128
+ });
@@ -0,0 +1,129 @@
1
+ import {
2
+ CONFIGURE_AI_EXIT_CODES,
3
+ createProvider,
4
+ getConfigPath,
5
+ loadConfig,
6
+ redactConfig,
7
+ saveConfig
8
+ } from "./chunk-T4X42QXC.js";
9
+
10
+ // src/cli/configure-ai.ts
11
+ function parseArgs(argv) {
12
+ let provider;
13
+ let model;
14
+ let apiKey;
15
+ let endpoint;
16
+ let show = false;
17
+ let test = false;
18
+ for (let i = 0; i < argv.length; i++) {
19
+ const arg = argv[i];
20
+ if (arg === "--provider" && i + 1 < argv.length) {
21
+ provider = argv[++i];
22
+ } else if (arg === "--model" && i + 1 < argv.length) {
23
+ model = argv[++i];
24
+ } else if (arg === "--api-key" && i + 1 < argv.length) {
25
+ apiKey = argv[++i];
26
+ } else if (arg === "--endpoint" && i + 1 < argv.length) {
27
+ endpoint = argv[++i];
28
+ } else if (arg === "--show") {
29
+ show = true;
30
+ } else if (arg === "--test") {
31
+ test = true;
32
+ }
33
+ }
34
+ return { provider, model, apiKey, endpoint, show, test };
35
+ }
36
+ async function main(argv = process.argv.slice(2)) {
37
+ try {
38
+ const args = parseArgs(argv);
39
+ if (args.show) {
40
+ const config2 = await loadConfig();
41
+ if (!config2) {
42
+ process.stdout.write(JSON.stringify({
43
+ configured: false,
44
+ configPath: getConfigPath()
45
+ }, null, 2) + "\n");
46
+ } else {
47
+ process.stdout.write(JSON.stringify({
48
+ configured: true,
49
+ configPath: getConfigPath(),
50
+ ...redactConfig(config2)
51
+ }, null, 2) + "\n");
52
+ }
53
+ process.exit(CONFIGURE_AI_EXIT_CODES.SUCCESS);
54
+ return;
55
+ }
56
+ if (args.test) {
57
+ const config2 = await loadConfig();
58
+ if (!config2) {
59
+ process.stderr.write(JSON.stringify({
60
+ error: "No configuration found. Run: neuroverse configure-ai --provider ... --model ... --api-key ..."
61
+ }, null, 2) + "\n");
62
+ process.exit(CONFIGURE_AI_EXIT_CODES.VALIDATION_FAIL);
63
+ return;
64
+ }
65
+ try {
66
+ const provider = createProvider(config2);
67
+ await provider.complete("You are a test. Respond with only: OK", "Test connection.");
68
+ process.stdout.write(JSON.stringify({
69
+ success: true,
70
+ message: "Connection test passed",
71
+ ...redactConfig(config2)
72
+ }, null, 2) + "\n");
73
+ process.exit(CONFIGURE_AI_EXIT_CODES.SUCCESS);
74
+ } catch (e) {
75
+ process.stderr.write(JSON.stringify({
76
+ success: false,
77
+ error: `Connection test failed: ${e instanceof Error ? e.message : String(e)}`
78
+ }, null, 2) + "\n");
79
+ process.exit(CONFIGURE_AI_EXIT_CODES.VALIDATION_FAIL);
80
+ }
81
+ return;
82
+ }
83
+ if (!args.provider && !args.model && !args.apiKey && !args.endpoint) {
84
+ process.stderr.write(JSON.stringify({
85
+ error: "Provide at least one of: --provider, --model, --api-key, --endpoint",
86
+ usage: "neuroverse configure-ai --provider openai --model gpt-4.1-mini --api-key sk-..."
87
+ }, null, 2) + "\n");
88
+ process.exit(CONFIGURE_AI_EXIT_CODES.VALIDATION_FAIL);
89
+ return;
90
+ }
91
+ const existing = await loadConfig();
92
+ const config = {
93
+ provider: args.provider ?? existing?.provider ?? "openai",
94
+ model: args.model ?? existing?.model ?? "",
95
+ apiKey: args.apiKey ?? existing?.apiKey ?? "",
96
+ endpoint: args.endpoint ?? existing?.endpoint ?? null
97
+ };
98
+ if (!config.model) {
99
+ process.stderr.write(JSON.stringify({
100
+ error: "Model is required. Use --model <name>"
101
+ }, null, 2) + "\n");
102
+ process.exit(CONFIGURE_AI_EXIT_CODES.VALIDATION_FAIL);
103
+ return;
104
+ }
105
+ if (!config.apiKey) {
106
+ process.stderr.write(JSON.stringify({
107
+ error: "API key is required. Use --api-key <key>"
108
+ }, null, 2) + "\n");
109
+ process.exit(CONFIGURE_AI_EXIT_CODES.VALIDATION_FAIL);
110
+ return;
111
+ }
112
+ await saveConfig(config);
113
+ process.stdout.write(JSON.stringify({
114
+ success: true,
115
+ configPath: getConfigPath(),
116
+ ...redactConfig(config)
117
+ }, null, 2) + "\n");
118
+ process.exit(CONFIGURE_AI_EXIT_CODES.SUCCESS);
119
+ } catch (e) {
120
+ process.stderr.write(JSON.stringify({
121
+ error: "Configuration failed",
122
+ detail: e instanceof Error ? e.message : String(e)
123
+ }, null, 2) + "\n");
124
+ process.exit(CONFIGURE_AI_EXIT_CODES.ERROR);
125
+ }
126
+ }
127
+ export {
128
+ main
129
+ };
@@ -0,0 +1,150 @@
1
+ import {
2
+ DeriveInputError,
3
+ DeriveProviderError,
4
+ deriveWorld
5
+ } from "./chunk-D7BGWV2J.js";
6
+ import {
7
+ DERIVE_EXIT_CODES
8
+ } from "./chunk-T4X42QXC.js";
9
+ import "./chunk-XPDMYECO.js";
10
+ import "./chunk-O5OMJMIE.js";
11
+
12
+ // src/cli/derive.ts
13
+ function parseArgs(argv) {
14
+ let inputPath = "";
15
+ let outputPath = "./derived.nv-world.md";
16
+ let validate = true;
17
+ let dryRun = false;
18
+ let bootstrapDir;
19
+ let provider;
20
+ let model;
21
+ let endpoint;
22
+ for (let i = 0; i < argv.length; i++) {
23
+ const arg = argv[i];
24
+ if (arg === "--input" && i + 1 < argv.length) {
25
+ inputPath = argv[++i];
26
+ } else if (arg === "--output" && i + 1 < argv.length) {
27
+ outputPath = argv[++i];
28
+ } else if (arg === "--validate") {
29
+ validate = true;
30
+ } else if (arg === "--no-validate") {
31
+ validate = false;
32
+ } else if (arg === "--dry-run") {
33
+ dryRun = true;
34
+ } else if (arg === "--bootstrap" && i + 1 < argv.length) {
35
+ bootstrapDir = argv[++i];
36
+ } else if (arg === "--provider" && i + 1 < argv.length) {
37
+ provider = argv[++i];
38
+ } else if (arg === "--model" && i + 1 < argv.length) {
39
+ model = argv[++i];
40
+ } else if (arg === "--endpoint" && i + 1 < argv.length) {
41
+ endpoint = argv[++i];
42
+ }
43
+ }
44
+ if (!inputPath) throw new DeriveInputError("--input <path> is required");
45
+ return { inputPath, outputPath, validate, dryRun, bootstrapDir, provider, model, endpoint };
46
+ }
47
+ async function main(argv = process.argv.slice(2)) {
48
+ try {
49
+ const args = parseArgs(argv);
50
+ const { result, exitCode, dryRunOutput } = await deriveWorld({
51
+ inputPath: args.inputPath,
52
+ outputPath: args.outputPath,
53
+ validate: args.validate,
54
+ dryRun: args.dryRun,
55
+ providerOverride: args.provider || args.model || args.endpoint ? {
56
+ provider: args.provider,
57
+ model: args.model,
58
+ endpoint: args.endpoint
59
+ } : void 0
60
+ });
61
+ if (dryRunOutput) {
62
+ process.stdout.write(JSON.stringify({
63
+ dryRun: true,
64
+ systemPrompt: dryRunOutput.systemPrompt,
65
+ userPrompt: dryRunOutput.userPrompt,
66
+ durationMs: result.durationMs
67
+ }, null, 2) + "\n");
68
+ process.exit(DERIVE_EXIT_CODES.SUCCESS);
69
+ return;
70
+ }
71
+ process.stderr.write(`
72
+ Derived world written to: ${result.outputPath}
73
+ `);
74
+ process.stderr.write(`Derivation Gate: ${result.gate}
75
+ `);
76
+ if (result.normalization) {
77
+ const n = result.normalization;
78
+ const details = [];
79
+ if (n.invariantIds > 0) details.push(`${n.invariantIds} invariant ID(s) wrapped`);
80
+ if (n.gateThresholds > 0) details.push(`${n.gateThresholds} gate threshold(s) converted`);
81
+ if (n.triggerTags > 0) details.push(`${n.triggerTags} trigger(s) tagged with [state]`);
82
+ process.stderr.write(`
83
+ Normalization: ${n.fixCount} fix(es) applied
84
+ `);
85
+ for (const d of details) process.stderr.write(` - ${d}
86
+ `);
87
+ }
88
+ if (result.findings.length > 0) {
89
+ process.stderr.write(`
90
+ `);
91
+ const errs = result.findings.filter((f) => f.severity === "error");
92
+ const warns = result.findings.filter((f) => f.severity === "warning");
93
+ if (errs.length > 0) {
94
+ process.stderr.write(`Errors (${errs.length}):
95
+ `);
96
+ for (const f of errs) {
97
+ process.stderr.write(` ERROR [${f.section}]: ${f.message}
98
+ `);
99
+ }
100
+ }
101
+ if (warns.length > 0) {
102
+ process.stderr.write(`Warnings (${warns.length}):
103
+ `);
104
+ for (const f of warns) {
105
+ process.stderr.write(` WARN [${f.section}]: ${f.message}
106
+ `);
107
+ }
108
+ }
109
+ process.stderr.write(`
110
+ `);
111
+ }
112
+ if (result.gate === "SUSPECT" || result.gate === "DERIVATION_REJECTED") {
113
+ process.stderr.write(`The file has been written. Open ${result.outputPath} to review and fix.
114
+ `);
115
+ }
116
+ if (args.bootstrapDir && exitCode === 0) {
117
+ process.stderr.write(`
118
+ Bootstrapping to ${args.bootstrapDir}...
119
+ `);
120
+ const { main: bootstrapMain } = await import("./bootstrap-H4HHKQ5G.js");
121
+ await bootstrapMain([
122
+ "--input",
123
+ result.outputPath,
124
+ "--output",
125
+ args.bootstrapDir,
126
+ ...args.validate ? ["--validate"] : []
127
+ ]);
128
+ return;
129
+ }
130
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
131
+ process.exit(exitCode);
132
+ } catch (e) {
133
+ if (e instanceof DeriveInputError) {
134
+ process.stderr.write(JSON.stringify({ error: e.message }, null, 2) + "\n");
135
+ process.exit(DERIVE_EXIT_CODES.INPUT_ERROR);
136
+ } else if (e instanceof DeriveProviderError) {
137
+ process.stderr.write(JSON.stringify({ error: e.message }, null, 2) + "\n");
138
+ process.exit(DERIVE_EXIT_CODES.PROVIDER_ERROR);
139
+ } else {
140
+ process.stderr.write(JSON.stringify({
141
+ error: "Derive failed",
142
+ detail: e instanceof Error ? e.message : String(e)
143
+ }, null, 2) + "\n");
144
+ process.exit(DERIVE_EXIT_CODES.PROVIDER_ERROR);
145
+ }
146
+ }
147
+ }
148
+ export {
149
+ main
150
+ };
@@ -0,0 +1,69 @@
1
+ import {
2
+ explainWorld,
3
+ renderExplainText
4
+ } from "./chunk-BUWWN2NX.js";
5
+ import {
6
+ loadWorld
7
+ } from "./chunk-M3TZFGHO.js";
8
+
9
+ // src/cli/explain.ts
10
+ function parseArgs(argv) {
11
+ let worldPath = "";
12
+ let json = false;
13
+ for (let i = 0; i < argv.length; i++) {
14
+ const arg = argv[i];
15
+ if (arg === "--json") {
16
+ json = true;
17
+ } else if (!arg.startsWith("--") && !worldPath) {
18
+ worldPath = arg;
19
+ }
20
+ }
21
+ if (!worldPath) {
22
+ throw new Error("Usage: neuroverse explain <world-path-or-id>");
23
+ }
24
+ return { worldPath, json };
25
+ }
26
+ async function resolveWorldPath(input) {
27
+ const { stat } = await import("fs/promises");
28
+ try {
29
+ const info = await stat(input);
30
+ if (info.isDirectory()) return input;
31
+ } catch {
32
+ }
33
+ const neuroversePath = `.neuroverse/worlds/${input}`;
34
+ try {
35
+ const info = await stat(neuroversePath);
36
+ if (info.isDirectory()) return neuroversePath;
37
+ } catch {
38
+ }
39
+ throw new Error(
40
+ `World not found: "${input}"
41
+ Tried:
42
+ ${input}
43
+ ${neuroversePath}
44
+
45
+ Build a world first: neuroverse build <input.md>`
46
+ );
47
+ }
48
+ async function main(argv = process.argv.slice(2)) {
49
+ try {
50
+ const args = parseArgs(argv);
51
+ const resolvedPath = await resolveWorldPath(args.worldPath);
52
+ const world = await loadWorld(resolvedPath);
53
+ const explanation = explainWorld(world);
54
+ if (args.json) {
55
+ process.stdout.write(JSON.stringify(explanation, null, 2) + "\n");
56
+ } else {
57
+ process.stderr.write("\n");
58
+ process.stderr.write(renderExplainText(explanation));
59
+ }
60
+ process.exit(0);
61
+ } catch (e) {
62
+ process.stderr.write(`${e instanceof Error ? e.message : String(e)}
63
+ `);
64
+ process.exit(1);
65
+ }
66
+ }
67
+ export {
68
+ main
69
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ GUARD_EXIT_CODES
3
+ } from "./chunk-MWDQ4MJB.js";
4
+ import {
5
+ evaluateGuard
6
+ } from "./chunk-B4NF3OLW.js";
7
+ import {
8
+ loadWorld
9
+ } from "./chunk-M3TZFGHO.js";
10
+
11
+ // src/cli/guard.ts
12
+ function parseArgs(argv) {
13
+ let worldPath = "";
14
+ let trace = false;
15
+ let level;
16
+ for (let i = 0; i < argv.length; i++) {
17
+ const arg = argv[i];
18
+ if (arg === "--world" && i + 1 < argv.length) {
19
+ worldPath = argv[++i];
20
+ } else if (arg === "--trace") {
21
+ trace = true;
22
+ } else if (arg === "--level" && i + 1 < argv.length) {
23
+ const val = argv[++i];
24
+ if (val === "basic" || val === "standard" || val === "strict") {
25
+ level = val;
26
+ } else {
27
+ throw new Error(`Invalid level: "${val}". Must be basic, standard, or strict.`);
28
+ }
29
+ }
30
+ }
31
+ if (!worldPath) {
32
+ throw new Error("--world <path> is required");
33
+ }
34
+ return { worldPath, trace, level };
35
+ }
36
+ async function readStdin() {
37
+ const chunks = [];
38
+ for await (const chunk of process.stdin) {
39
+ chunks.push(chunk);
40
+ }
41
+ return Buffer.concat(chunks).toString("utf-8");
42
+ }
43
+ async function main(argv = process.argv.slice(2)) {
44
+ try {
45
+ const args = parseArgs(argv);
46
+ const input = await readStdin();
47
+ if (!input.trim()) {
48
+ const errorResult = {
49
+ error: "No input on stdin. Pipe a JSON GuardEvent.",
50
+ usage: `echo '{"intent":"..."}' | neuroverse guard --world <path>`
51
+ };
52
+ process.stdout.write(JSON.stringify(errorResult, null, 2) + "\n");
53
+ process.exit(GUARD_EXIT_CODES.ERROR);
54
+ }
55
+ let event;
56
+ try {
57
+ event = JSON.parse(input);
58
+ } catch (e) {
59
+ const errorResult = { error: "Invalid JSON on stdin", detail: String(e) };
60
+ process.stdout.write(JSON.stringify(errorResult, null, 2) + "\n");
61
+ process.exit(GUARD_EXIT_CODES.ERROR);
62
+ }
63
+ if (!event.intent) {
64
+ const errorResult = { error: 'GuardEvent must have an "intent" field' };
65
+ process.stdout.write(JSON.stringify(errorResult, null, 2) + "\n");
66
+ process.exit(GUARD_EXIT_CODES.ERROR);
67
+ }
68
+ const world = await loadWorld(args.worldPath);
69
+ const options = { trace: args.trace, level: args.level };
70
+ const verdict = evaluateGuard(event, world, options);
71
+ process.stdout.write(JSON.stringify(verdict, null, 2) + "\n");
72
+ const exitCode = GUARD_EXIT_CODES[verdict.status];
73
+ process.exit(exitCode);
74
+ } catch (e) {
75
+ const errorResult = { error: "Guard evaluation failed", detail: String(e) };
76
+ process.stderr.write(JSON.stringify(errorResult, null, 2) + "\n");
77
+ process.exit(GUARD_EXIT_CODES.ERROR);
78
+ }
79
+ }
80
+ export {
81
+ main
82
+ };