velaris-lang 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # velaris-lang
2
+
3
+ Run code you did not write.
4
+
5
+ ```
6
+ npx velaris-lang script.vel --allow io
7
+ ```
8
+
9
+ That program cannot read a file, reach the network or call Python -
10
+ whatever its source says about itself - and a refusal cannot be caught
11
+ and carried past.
12
+
13
+ ```javascript
14
+ import { audit, run } from "velaris-lang";
15
+
16
+ const report = await audit(source);
17
+ console.log(report.effects); // ['fs', 'net']
18
+ console.log(report.proven_share); // 66.7
19
+
20
+ const result = await run(source, { allow: ["io"] });
21
+ console.log(result.ok, result.output, result.refusedEffect);
22
+ ```
23
+
24
+ Velaris is a language where a function's signature declares its types,
25
+ the effects it may perform, whether it can fail, and promises a theorem
26
+ prover checks before the program runs. This package is a thin wrapper:
27
+ the compiler is a Python package, so `pip install velaris-lang` once.
28
+
29
+ Not a security boundary - allowing `ffi` grants everything Python can
30
+ do. It is a real guard for running a script a model wrote.
31
+
32
+ [Documentation](https://gowrishankar-infra.github.io/velaris-lang/) ·
33
+ [Playground](https://gowrishankar-infra.github.io/velaris-lang/playground.html) ·
34
+ [Source](https://github.com/gowrishankar-infra/velaris-lang)
package/bin/velaris.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ // npx velaris hello.vel
3
+ //
4
+ // Velaris's compiler is one Python file. This hands your arguments to
5
+ // it, and if it is not installed, says exactly how to fix that rather
6
+ // than failing with a confusing spawn error.
7
+
8
+ import { spawn, spawnSync } from "node:child_process";
9
+
10
+ function pythons() {
11
+ return process.platform === "win32"
12
+ ? ["py", "python", "python3"]
13
+ : ["python3", "python"];
14
+ }
15
+
16
+ function findVelaris() {
17
+ for (const exe of pythons()) {
18
+ const probe = spawnSync(exe, ["-c", "import velaris"], {
19
+ stdio: "ignore",
20
+ });
21
+ if (probe.status === 0) return exe;
22
+ }
23
+ return null;
24
+ }
25
+
26
+ const exe = findVelaris();
27
+ if (!exe) {
28
+ console.error(
29
+ "Velaris needs its compiler, which is a Python package:\n" +
30
+ "\n pip install velaris-lang\n" +
31
+ "\nOr try it with nothing installed:\n" +
32
+ " https://gowrishankar-infra.github.io/velaris-lang/playground.html"
33
+ );
34
+ process.exit(127);
35
+ }
36
+
37
+ const child = spawn(exe, ["-m", "velaris", ...process.argv.slice(2)], {
38
+ stdio: "inherit",
39
+ });
40
+ child.on("exit", (code, signal) => {
41
+ if (signal) process.kill(process.pid, signal);
42
+ else process.exit(code ?? 0);
43
+ });
package/index.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ export type Effect = "io" | "fs" | "net" | "clock" | "rand" | "ffi";
2
+
3
+ export interface Problem {
4
+ code: string;
5
+ message: string;
6
+ line: number;
7
+ file: string | null;
8
+ fixes: string[];
9
+ }
10
+
11
+ export interface CheckResult {
12
+ ok: boolean;
13
+ problems: Problem[];
14
+ proven: string[];
15
+ runtime_checked: string[];
16
+ }
17
+
18
+ export interface AuditFunction {
19
+ name: string;
20
+ effects: Effect[];
21
+ can_fail: boolean;
22
+ requires: string[];
23
+ ensures: string[];
24
+ status: string;
25
+ }
26
+
27
+ export interface AuditResult {
28
+ schema: "velaris.audit/1";
29
+ velaris_version: string;
30
+ ok: boolean;
31
+ problems: Problem[];
32
+ effects: Effect[];
33
+ functions: AuditFunction[];
34
+ proven_share: number | null;
35
+ safe_command: string;
36
+ warnings: string[];
37
+ }
38
+
39
+ export interface RunResult {
40
+ ok: boolean;
41
+ output: string;
42
+ logs: string;
43
+ problems: Problem[];
44
+ refusedEffect: Effect | null;
45
+ exitCode: number;
46
+ }
47
+
48
+ export interface RunOptions {
49
+ allow?: Effect[];
50
+ stdin?: string;
51
+ args?: string[];
52
+ }
53
+
54
+ export function check(source: string): Promise<CheckResult>;
55
+ export function audit(source: string): Promise<AuditResult>;
56
+ export function run(source: string, options?: RunOptions): Promise<RunResult>;
57
+ export function card(): Promise<string>;
package/index.js ADDED
@@ -0,0 +1,120 @@
1
+ // Velaris from Node: check what a program does, audit what it may
2
+ // touch, and run it under an effect budget.
3
+ //
4
+ // import { check, audit, run } from "velaris-lang";
5
+ //
6
+ // const report = await audit(source);
7
+ // console.log(report.effects); // ['fs', 'net']
8
+ //
9
+ // const result = await run(source, { allow: ["io"] });
10
+ // console.log(result.ok, result.output, result.refusedEffect);
11
+ //
12
+ // Every call goes to the same compiler the command line uses, so the
13
+ // guarantees are the same: an effect outside the budget is refused
14
+ // while the program runs, whatever its source claims, and a refusal
15
+ // cannot be caught by the program.
16
+
17
+ import { spawn, spawnSync } from "node:child_process";
18
+
19
+ let cachedPython = null;
20
+
21
+ function findPython() {
22
+ if (cachedPython) return cachedPython;
23
+ const candidates =
24
+ process.platform === "win32"
25
+ ? ["py", "python", "python3"]
26
+ : ["python3", "python"];
27
+ for (const exe of candidates) {
28
+ const probe = spawnSync(exe, ["-c", "import velaris"], {
29
+ stdio: "ignore",
30
+ });
31
+ if (probe.status === 0) return (cachedPython = exe);
32
+ }
33
+ throw new Error(
34
+ "velaris is not installed: pip install velaris-lang"
35
+ );
36
+ }
37
+
38
+ function callPython(script, payload) {
39
+ const exe = findPython();
40
+ return new Promise((resolve, reject) => {
41
+ const child = spawn(exe, ["-c", script], {
42
+ stdio: ["pipe", "pipe", "pipe"],
43
+ });
44
+ let out = "";
45
+ let err = "";
46
+ child.stdout.on("data", (d) => (out += d));
47
+ child.stderr.on("data", (d) => (err += d));
48
+ child.on("error", reject);
49
+ child.on("close", () => {
50
+ try {
51
+ resolve(JSON.parse(out));
52
+ } catch {
53
+ reject(new Error(err.trim() || "velaris gave no answer"));
54
+ }
55
+ });
56
+ child.stdin.end(JSON.stringify(payload));
57
+ });
58
+ }
59
+
60
+ const BRIDGE = `
61
+ import json, sys
62
+ import velaris
63
+ ask = json.load(sys.stdin)
64
+ what = ask["what"]
65
+ source = ask["source"]
66
+ if what == "check":
67
+ print(json.dumps(velaris.check(source).as_dict()))
68
+ elif what == "audit":
69
+ print(json.dumps(velaris.audit(source).as_dict()))
70
+ elif what == "card":
71
+ print(json.dumps({"card": velaris.card()}))
72
+ else:
73
+ out = velaris.run(source, allow=set(ask.get("allow") or ["io"]),
74
+ stdin=ask.get("stdin", ""),
75
+ args=ask.get("args") or [])
76
+ print(json.dumps(out.as_dict()))
77
+ `;
78
+
79
+ /** Compile without running. Problems, and what was proven. */
80
+ export async function check(source) {
81
+ return callPython(BRIDGE, { what: "check", source });
82
+ }
83
+
84
+ /** What a program can touch, promise and fail at - before running. */
85
+ export async function audit(source) {
86
+ return callPython(BRIDGE, { what: "audit", source });
87
+ }
88
+
89
+ /** The language, small enough to paste into a model. */
90
+ export async function card() {
91
+ const answer = await callPython(BRIDGE, { what: "card", source: "x" });
92
+ return answer.card;
93
+ }
94
+
95
+ /**
96
+ * Run under an effect budget.
97
+ *
98
+ * allow: ["io"] means it cannot read files, reach the network, call
99
+ * Python, ask the clock or use randomness - whatever the source says.
100
+ * Not a security boundary: allowing "ffi" grants everything Python can.
101
+ */
102
+ export async function run(source, options = {}) {
103
+ const answer = await callPython(BRIDGE, {
104
+ what: "run",
105
+ source,
106
+ allow: options.allow ?? ["io"],
107
+ stdin: options.stdin ?? "",
108
+ args: options.args ?? [],
109
+ });
110
+ return {
111
+ ok: answer.ok,
112
+ output: answer.output,
113
+ logs: answer.logs,
114
+ problems: answer.problems,
115
+ refusedEffect: answer.refused_effect,
116
+ exitCode: answer.exit_code,
117
+ };
118
+ }
119
+
120
+ export default { check, audit, run, card };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "velaris-lang",
3
+ "version": "4.3.0",
4
+ "description": "Run code you did not write. A language where a signature declares its effects and promises, and the runtime refuses anything you did not allow.",
5
+ "keywords": [
6
+ "velaris",
7
+ "sandbox",
8
+ "effects",
9
+ "verification",
10
+ "ai-generated-code",
11
+ "agent",
12
+ "mcp",
13
+ "prover"
14
+ ],
15
+ "homepage": "https://gowrishankar-infra.github.io/velaris-lang/",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/gowrishankar-infra/velaris-lang.git"
19
+ },
20
+ "bugs": "https://github.com/gowrishankar-infra/velaris-lang/issues",
21
+ "license": "MIT",
22
+ "author": "Palakurthi Gowri Shankar <gowrishankar@gowrishankar.dev>",
23
+ "type": "module",
24
+ "main": "index.js",
25
+ "types": "index.d.ts",
26
+ "bin": {
27
+ "velaris": "bin/velaris.js"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "bin/",
33
+ "README.md"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ }
38
+ }