@oxvm/cli 0.0.0-stage → 0.0.29
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/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +27 -2
- package/THIRD_PARTY_NOTICES.txt +52056 -0
- package/dist/arguments.d.ts +162 -0
- package/dist/arguments.js +1 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +2 -0
- package/dist/contracts.d.ts +98 -0
- package/dist/contracts.js +0 -0
- package/dist/environment.d.ts +4 -0
- package/dist/environment.js +1 -0
- package/dist/failure.d.ts +5 -0
- package/dist/failure.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/project-files.d.ts +2 -0
- package/dist/project-files.js +1 -0
- package/dist/project-lock.d.ts +13 -0
- package/dist/project-lock.js +4 -0
- package/dist/report.d.ts +3 -0
- package/dist/report.js +1 -0
- package/dist/run.d.ts +17 -0
- package/dist/run.js +36 -0
- package/dist/snapshot-commands.d.ts +7 -0
- package/dist/snapshot-commands.js +3 -0
- package/dist/snapshot-errors.d.ts +4 -0
- package/dist/snapshot-errors.js +2 -0
- package/dist/snapshot-help.d.ts +3 -0
- package/dist/snapshot-help.js +14 -0
- package/dist/snapshot-templates.d.ts +16 -0
- package/dist/snapshot-templates.js +58 -0
- package/dist/start-application.d.ts +2 -0
- package/dist/start-application.js +3 -0
- package/dist/starter-inputs.d.ts +13 -0
- package/dist/starter-inputs.js +1 -0
- package/dist/starter-release.d.ts +29 -0
- package/dist/starter-release.js +1 -0
- package/dist/starter-template.d.ts +9 -0
- package/dist/starter-template.js +2 -0
- package/dist/starter.generated.d.ts +1 -0
- package/dist/starter.generated.js +1 -0
- package/dist/starter.json +1 -0
- package/dist/template-files.d.ts +2 -0
- package/dist/template-files.js +1 -0
- package/dist/templates.d.ts +27 -0
- package/dist/templates.js +115 -0
- package/dist/validation.d.ts +5 -0
- package/dist/validation.js +1 -0
- package/dist/wasm-commands.d.ts +7 -0
- package/dist/wasm-commands.js +1 -0
- package/dist/wasm-errors.d.ts +2 -0
- package/dist/wasm-errors.js +1 -0
- package/dist/wasm-help.d.ts +3 -0
- package/dist/wasm-help.js +37 -0
- package/dist/wasm-release.d.ts +15 -0
- package/dist/wasm-release.js +8 -0
- package/dist/wasm-template-files.d.ts +50 -0
- package/dist/wasm-template-files.js +350 -0
- package/dist/wasm-template-network.d.ts +15 -0
- package/dist/wasm-template-network.js +91 -0
- package/dist/wasm-templates.d.ts +16 -0
- package/dist/wasm-templates.js +91 -0
- package/dist/wasm-text.d.ts +23 -0
- package/dist/wasm-text.js +40 -0
- package/package.json +56 -3
- package/sbom.cdx.json +8537 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
var m=Object.defineProperty;var n=(t,e)=>m(t,"name",{value:e,configurable:!0});import{NETWORK_RULES as p,networkSection as h,reachToken as d}from"./wasm-template-network.js";const o="oxidevm";function b(t){return t.startsWith(o)?void 0:t}n(b,"commandFor");function a(t){return t.replace(/-([a-z0-9])/gu,(e,s)=>s.toUpperCase())}n(a,"handleName");const x=Uint8Array.from([0,97,115,109,1,0,0,0,1,7,1,96,2,127,127,1,127,3,2,1,0,7,7,1,3,97,100,100,0,0,10,9,1,7,0,32,0,32,1,106,11]),v=`/** Reads exactly two 32-bit signed integers from text; \`undefined\` when there are not exactly two valid ones. */
|
|
2
|
+
export function parseOperands(args: readonly string[]): readonly [number, number] | undefined {
|
|
3
|
+
const [left, right, ...rest] = args;
|
|
4
|
+
if (left === undefined || right === undefined || rest.length > 0) return undefined;
|
|
5
|
+
const first = parseInteger(left), second = parseInteger(right);
|
|
6
|
+
return first === undefined || second === undefined ? undefined : [first, second];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function parseInteger(text: string): number | undefined {
|
|
10
|
+
if (!/^-?\\d{1,10}$/u.test(text)) return undefined;
|
|
11
|
+
const value = Number(text);
|
|
12
|
+
return value >= -2147483648 && value <= 2147483647 ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
`,k=`import { describe, expect, it } from "vitest";
|
|
15
|
+
import { parseOperands } from "../src/operands.ts";
|
|
16
|
+
|
|
17
|
+
describe("parseOperands", () => {
|
|
18
|
+
it("reads two 32-bit integers", () => {
|
|
19
|
+
expect(parseOperands(["2", "-3"])).toEqual([2, -3]);
|
|
20
|
+
expect(parseOperands(["2147483647", "-2147483648"])).toEqual([2147483647, -2147483648]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("refuses anything else", () => {
|
|
24
|
+
for (const args of [[], ["1"], ["1", "2", "3"], ["1", "x"], ["1.5", "2"], ["2147483648", "1"], ["", "1"], ["1e3", "1"]]) {
|
|
25
|
+
expect(parseOperands(args)).toBeUndefined();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
`,u="<a> <b> (two 32-bit integers)",i=n(t=>`usage: ${t} ${u}`,"usage");function $(t,e){const s=e===void 0?` * \`${t} <a> <b>\` prints the sum of two 32-bit integers.
|
|
30
|
+
*
|
|
31
|
+
* The application starts it with \`spawnModule\`. The module declares no commands, because command names that start with
|
|
32
|
+
* "${o}" are reserved, so no program in the VM runs it by name.`:` * \`${e} <a> <b>\` prints the sum of two 32-bit integers.
|
|
33
|
+
*
|
|
34
|
+
* The application starts it with \`spawnModule\`, and once it turns the module's commands on, any program in the VM runs
|
|
35
|
+
* it as \`/usr/local/bin/${e}\`.`,r=e===void 0?` // Only the application starts this module, so a usage line names the module.
|
|
36
|
+
const name = ${JSON.stringify(t)};`:` // Name the command as the caller typed it (perhaps a path, or a link to it); io.args never holds argv[0].
|
|
37
|
+
const name = io.invocation.kind === "command" ? io.invocation.argv0 : ${JSON.stringify(t)};`;return`import type { BaseHost, CommandHooks, Host } from "@oxvm/sdk/wasm";
|
|
38
|
+
import { parseOperands } from "./operands.ts";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The host members the command uses. Asking for only these keeps it testable with a small stand-in instead of a whole
|
|
42
|
+
* host, whose members grow with the SDK.
|
|
43
|
+
*/
|
|
44
|
+
export type AddHost = Pick<BaseHost, "fail"> & { readonly fs: Pick<Host<"files.sync">["fs"], "writeAll"> };
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
${s}
|
|
48
|
+
*/
|
|
49
|
+
export function addCommand(host: AddHost, add: (left: number, right: number) => unknown): ${e===void 0?"CommandHooks":`CommandHooks<${JSON.stringify(e)}>`} {
|
|
50
|
+
return {
|
|
51
|
+
main(io) {
|
|
52
|
+
${r}
|
|
53
|
+
const operands = parseOperands(io.args);
|
|
54
|
+
if (operands === undefined) return host.fail(2, \`usage: \${name} ${u}\`);
|
|
55
|
+
// writeAll writes every byte: a pipe may take only part of one write.
|
|
56
|
+
host.fs.writeAll(io.stdout, new TextEncoder().encode(\`\${String(add(...operands))}\\n\`));
|
|
57
|
+
return 0;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
`}n($,"addCommandSource");function S(t,e){return`import { readFile } from "node:fs/promises";
|
|
62
|
+
import { describe, expect, it } from "vitest";
|
|
63
|
+
import { testHost, type TestHostInputs } from "@oxvm/sdk/wasm/testing";
|
|
64
|
+
import definition from "../module.ts";
|
|
65
|
+
|
|
66
|
+
type Invocation = NonNullable<TestHostInputs["invocation"]>;
|
|
67
|
+
|
|
68
|
+
/** The artifact the release pins, read from this repository. */
|
|
69
|
+
const artifacts = { "add.wasm": new Uint8Array(await readFile(new URL("../upstream/add.wasm", import.meta.url))) };
|
|
70
|
+
|
|
71
|
+
/** Runs the module once through the SDK's runner, as the browser would, and returns what it wrote. */
|
|
72
|
+
async function run(args: readonly string[], invocation?: Invocation): Promise<{ status: number; stdout: string; stderr: string }> {
|
|
73
|
+
const { status, stdout, stderr } = await testHost(definition, { args, artifacts, ...(invocation === undefined ? {} : { invocation }) }).run();
|
|
74
|
+
return { status, stdout, stderr };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
${e===void 0?`describe(${JSON.stringify(`the ${t} command`)}, () => {
|
|
78
|
+
it("prints the sum of its two arguments", async () => {
|
|
79
|
+
expect(await run(["2", "3"])).toEqual({ status: 0, stdout: "5\\n", stderr: "" });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("answers bad input with status 2 and a usage line", async () => {
|
|
83
|
+
expect(await run(["2"])).toEqual({ status: 2, stdout: "", stderr: ${JSON.stringify(`${i(t)}
|
|
84
|
+
`)} });
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
`:`/** How the runner describes a run that a program in the VM started by typing \`argv0\`. */
|
|
88
|
+
const fromVM = (argv0: string): Invocation => ({ kind: "command", name: ${JSON.stringify(e)}, argv0 });
|
|
89
|
+
|
|
90
|
+
describe(${JSON.stringify(`the ${e} command`)}, () => {
|
|
91
|
+
it("prints the sum when the application starts the module", async () => {
|
|
92
|
+
expect(await run(["2", "3"])).toEqual({ status: 0, stdout: "5\\n", stderr: "" });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("prints the sum when a program in the VM runs it", async () => {
|
|
96
|
+
expect(await run(["2", "3"], fromVM(${JSON.stringify(e)}))).toEqual({ status: 0, stdout: "5\\n", stderr: "" });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("answers bad input with status 2 and a usage line that names the command as it was typed", async () => {
|
|
100
|
+
expect(await run(["2"], fromVM(${JSON.stringify(e)}))).toEqual({ status: 2, stdout: "", stderr: ${JSON.stringify(`${i(e)}
|
|
101
|
+
`)} });
|
|
102
|
+
expect(await run(["two", "3"], fromVM(${JSON.stringify(`/usr/local/bin/${e}`)}))).toEqual({ status: 2, stdout: "", stderr: ${JSON.stringify(`${i(`/usr/local/bin/${e}`)}
|
|
103
|
+
`)} });
|
|
104
|
+
expect(await run([])).toEqual({ status: 2, stdout: "", stderr: ${JSON.stringify(`${i(t)}
|
|
105
|
+
`)} });
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
`}`}n(S,"addCommandTest");const A=`{
|
|
109
|
+
"compilerOptions": {
|
|
110
|
+
"allowImportingTsExtensions": true,
|
|
111
|
+
"exactOptionalPropertyTypes": true,
|
|
112
|
+
"forceConsistentCasingInFileNames": true,
|
|
113
|
+
"isolatedModules": true,
|
|
114
|
+
"lib": ["ES2024", "DOM"],
|
|
115
|
+
"module": "ESNext",
|
|
116
|
+
"moduleResolution": "Bundler",
|
|
117
|
+
"noEmit": true,
|
|
118
|
+
"noFallthroughCasesInSwitch": true,
|
|
119
|
+
"noImplicitOverride": true,
|
|
120
|
+
"noImplicitReturns": true,
|
|
121
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
122
|
+
"noUncheckedIndexedAccess": true,
|
|
123
|
+
"noUncheckedSideEffectImports": true,
|
|
124
|
+
"noUnusedLocals": true,
|
|
125
|
+
"noUnusedParameters": true,
|
|
126
|
+
"skipLibCheck": false,
|
|
127
|
+
"strict": true,
|
|
128
|
+
"target": "ES2024",
|
|
129
|
+
"types": [],
|
|
130
|
+
"useUnknownInCatchVariables": true,
|
|
131
|
+
"verbatimModuleSyntax": true
|
|
132
|
+
},
|
|
133
|
+
"include": ["module.ts", "src"]
|
|
134
|
+
}
|
|
135
|
+
`,E=`{
|
|
136
|
+
"extends": "../tsconfig.json",
|
|
137
|
+
"compilerOptions": { "types": ["node"] },
|
|
138
|
+
"include": ["./**/*.ts", "../module.ts", "../src/**/*.ts"]
|
|
139
|
+
}
|
|
140
|
+
`;function T(t,e,s){const r=e.kind==="service"?"":e.command===void 0?` // Command names that start with "${o}" are reserved, so this module declares none.
|
|
141
|
+
expect("commands" in definition.manifest).toBe(false);
|
|
142
|
+
`:` expect(definition.manifest.commands).toEqual([${JSON.stringify(e.command)}]);
|
|
143
|
+
`;return`import { describe, expect, it } from "vitest";
|
|
144
|
+
import definition from "../module.ts";
|
|
145
|
+
|
|
146
|
+
describe("module definition", () => {
|
|
147
|
+
it("declares what the build and the consumer read", () => {
|
|
148
|
+
expect(definition.manifest.id).toBe(${JSON.stringify(t)});
|
|
149
|
+
expect(definition.manifest.process.kind).toBe(${JSON.stringify(e.kind)});
|
|
150
|
+
${r} // The module's network reach (engine ADR 0029): Rust holds every process of the module to it.
|
|
151
|
+
const host: readonly string[] = definition.manifest.requires.host;
|
|
152
|
+
expect(host.filter(token => token.startsWith("net."))).toEqual(${JSON.stringify(d(s)===void 0?[]:[d(s)])});
|
|
153
|
+
expect(typeof definition.adapter).toBe("function");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
`}n(T,"moduleTest");const O=`import eslint from "@eslint/js";
|
|
157
|
+
import { defineConfig } from "eslint/config";
|
|
158
|
+
import tseslint from "typescript-eslint";
|
|
159
|
+
|
|
160
|
+
export default defineConfig(
|
|
161
|
+
{ ignores: ["dist/**", "node_modules/**", "eslint.config.js"] },
|
|
162
|
+
eslint.configs.recommended,
|
|
163
|
+
...tseslint.configs.strictTypeChecked,
|
|
164
|
+
{
|
|
165
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
166
|
+
rules: {
|
|
167
|
+
"@typescript-eslint/ban-ts-comment": "error",
|
|
168
|
+
"@typescript-eslint/consistent-type-imports": "error",
|
|
169
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
170
|
+
"@typescript-eslint/no-floating-promises": "error",
|
|
171
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
172
|
+
"@typescript-eslint/no-unsafe-type-assertion": "error",
|
|
173
|
+
"@typescript-eslint/strict-boolean-expressions": "error",
|
|
174
|
+
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
`,N=`node_modules/
|
|
179
|
+
dist/
|
|
180
|
+
*.log
|
|
181
|
+
`,l=`# This workflow starts on request only. The @oxvm packages of the CLI that generated this project are on a private registry
|
|
182
|
+
# that GitHub's runners cannot reach, so an automatic run would fail on every push. Give it the push (and pull_request, or tag)
|
|
183
|
+
# trigger of the public template once the packages install from a registry the runner can reach.
|
|
184
|
+
`,c=`on:
|
|
185
|
+
workflow_dispatch:
|
|
186
|
+
`,M="1.64.0";function I(t){return`${t?l:""}name: ci
|
|
187
|
+
${t?c:`on:
|
|
188
|
+
push:
|
|
189
|
+
branches: [main]
|
|
190
|
+
pull_request:
|
|
191
|
+
`}permissions:
|
|
192
|
+
contents: read
|
|
193
|
+
jobs:
|
|
194
|
+
check:
|
|
195
|
+
runs-on: ubuntu-latest
|
|
196
|
+
steps:
|
|
197
|
+
- uses: actions/checkout@v4
|
|
198
|
+
with:
|
|
199
|
+
persist-credentials: false
|
|
200
|
+
- uses: actions/setup-node@v4
|
|
201
|
+
with:
|
|
202
|
+
node-version: 24
|
|
203
|
+
- run: corepack enable
|
|
204
|
+
- run: pnpm install --frozen-lockfile
|
|
205
|
+
- run: pnpm run check
|
|
206
|
+
- run: pnpm test
|
|
207
|
+
- run: pnpm exec playwright install --with-deps chromium
|
|
208
|
+
- run: pnpm run test:conformance
|
|
209
|
+
`}n(I,"ciWorkflow");function R(t){const e=t?c:`on:
|
|
210
|
+
push:
|
|
211
|
+
tags: ["v*"]
|
|
212
|
+
`;return`# Publishing is the only step that changes what other people install, so it goes draft, verify, publish:
|
|
213
|
+
# the draft is downloaded again and checked against its own SHA256SUMS before it becomes visible.
|
|
214
|
+
# Dependencies install and build in a job that can only read; the job that may write to the repository runs
|
|
215
|
+
# nothing but the gh commands, so no install script or dependency code ever sees its token.
|
|
216
|
+
${t?`${l}# Start it from a tag: pick the tag, not a branch, in the Run workflow dialog, because the first check compares the tag with the version.
|
|
217
|
+
`:""}name: release
|
|
218
|
+
${e}permissions:
|
|
219
|
+
contents: read
|
|
220
|
+
jobs:
|
|
221
|
+
build:
|
|
222
|
+
runs-on: ubuntu-latest
|
|
223
|
+
steps:
|
|
224
|
+
- uses: actions/checkout@v4
|
|
225
|
+
with:
|
|
226
|
+
persist-credentials: false
|
|
227
|
+
- uses: actions/setup-node@v4
|
|
228
|
+
with:
|
|
229
|
+
node-version: 24
|
|
230
|
+
- run: corepack enable
|
|
231
|
+
- run: pnpm install --frozen-lockfile
|
|
232
|
+
- run: pnpm run build
|
|
233
|
+
- name: The tag must name the version in module.json
|
|
234
|
+
run: test "v$(node -p "JSON.parse(require('node:fs').readFileSync('dist/module.json', 'utf8')).version")" = "$GITHUB_REF_NAME"
|
|
235
|
+
- uses: actions/upload-artifact@v4
|
|
236
|
+
with:
|
|
237
|
+
name: release-files
|
|
238
|
+
path: dist/*
|
|
239
|
+
if-no-files-found: error
|
|
240
|
+
release:
|
|
241
|
+
needs: build
|
|
242
|
+
runs-on: ubuntu-latest
|
|
243
|
+
permissions:
|
|
244
|
+
contents: write
|
|
245
|
+
env:
|
|
246
|
+
GH_TOKEN: \${{ github.token }}
|
|
247
|
+
GH_REPO: \${{ github.repository }}
|
|
248
|
+
steps:
|
|
249
|
+
- uses: actions/download-artifact@v4
|
|
250
|
+
with:
|
|
251
|
+
name: release-files
|
|
252
|
+
path: dist
|
|
253
|
+
- name: Draft the release
|
|
254
|
+
run: gh release create "$GITHUB_REF_NAME" dist/* --draft --verify-tag --title "$GITHUB_REF_NAME" --generate-notes
|
|
255
|
+
- name: Verify the draft
|
|
256
|
+
run: |
|
|
257
|
+
mkdir verify
|
|
258
|
+
gh release download "$GITHUB_REF_NAME" --dir verify
|
|
259
|
+
cd verify
|
|
260
|
+
sha256sum --check SHA256SUMS
|
|
261
|
+
- name: Publish
|
|
262
|
+
run: gh release edit "$GITHUB_REF_NAME" --draft=false
|
|
263
|
+
`}n(R,"releaseWorkflow");function C(t){return`${t}
|
|
264
|
+
Copyright (c) <year> <copyright holder>
|
|
265
|
+
|
|
266
|
+
A OXVM WebAssembly module. Replace this file with the copyright and attribution notices of this module and of every program
|
|
267
|
+
or library whose code or binaries it ships; the Apache License asks a redistributor to keep the NOTICE files of the works it
|
|
268
|
+
redistributes. Keep the license texts of shipped binaries in this repository too, and name the files in license.notices.
|
|
269
|
+
`}n(C,"noticeFile");const f="\n## Commands that programs in the VM run\n\nEach name in `commands` becomes a program: once an application turns it on for a VM (`enableModuleCommands`), any program there runs the module as `/usr/local/bin/<name>`, in a fresh process with the caller's arguments, environment, directory and standard streams.\n\n- Name the command with `io.invocation.argv0` in usage lines and errors; the caller may have typed a path or a link. `io.args` never contains argv[0].\n- Standard input may be a terminal, a pipe, a file or empty. Read it only when the command's interface says so, and until a read returns no bytes.\n- Use colour or prompts only when `io.terminals` says that descriptor is a terminal.\n- Return 0-119 from `main`, and 2 for a usage error. Never throw for a user's mistake: a throw ends the run with status 123.\n- A signal kills the process at once and `close()` does not run, unless the module declares `process.signals`. If you trap a signal, finish quickly, then `untrap()` and `raise()` it, so the caller sees the process killed by that signal and a shell loop stops.\n- Write results atomically (a temporary file, then a rename), so an interrupted run never leaves half a file.\n- Choose names that do not shadow image programs unless you mean to: `/usr/local/bin` comes before `/usr/bin` on PATH. Adding a name in a later release makes every application consent again.\n- Never list your own command (`/usr/local/bin/<name>`) in `requires.guest.executables`, and never start your own command through PATH.\n- Keep start-up cheap: every run starts a fresh process, which runs the adapter factory again.\n";function H(t,e){return`# ${t}: instructions for coding agents
|
|
270
|
+
|
|
271
|
+
This repository is a OXVM WebAssembly module. \`module.ts\` holds the whole definition: a literal \`manifest\` and the \`adapter\` that runs the WebAssembly inside a Userspace JS process.
|
|
272
|
+
|
|
273
|
+
- Edit \`module.ts\`, \`src/\` and \`test/\`. Never edit \`dist/\`; \`pnpm run build\` writes it.
|
|
274
|
+
- Keep the manifest a literal. The build reads it without running code, so it cannot call functions or use variables.
|
|
275
|
+
- Declare in \`requires.host\` only what the adapter uses. The adapter's \`host\` has exactly those members, and the type checker enforces it.
|
|
276
|
+
- Import types from \`@oxvm/sdk/wasm\` with \`import type\`; the only value import is \`defineModule\`. The adapter ships as one self-contained file.
|
|
277
|
+
- No \`any\`, no \`@ts-ignore\`, no non-null assertions. Treat everything from outside (arguments, bytes, WebAssembly exports) as \`unknown\` and check it.
|
|
278
|
+
- Artifacts are files in this repository named by \`from\`. Pin upstream binaries by hash where they come from, and keep their licenses and notices in this repository.
|
|
279
|
+
- Verify with \`pnpm run check\` (types, lint, and \`oxvm wasm build --check\`), then \`pnpm test\`, then \`pnpm run test:conformance\` (\`oxvm wasm test\` in a real browser).
|
|
280
|
+
- Release by tag: \`pnpm run release\` prints the steps.
|
|
281
|
+
${e.kind==="command"?f:""}${p}`}n(H,"agentsFile");function g(t,e,s){return e===void 0?`
|
|
282
|
+
## Run it from a shell
|
|
283
|
+
|
|
284
|
+
The module declares no commands: command names that start with \`${o}\` are reserved. To let programs in a VM run it, add \`commands: ["<name>"]\` after \`process\` in \`module.ts\` with a name of your own; an application then turns it on with \`enableModuleCommands(vm, ${a(t)})\`, and programs run it as \`/usr/local/bin/<name>\`.
|
|
285
|
+
`:`
|
|
286
|
+
## Run it from a shell
|
|
287
|
+
|
|
288
|
+
The module declares the command \`${e}\`. An application that installed it turns the command on for one Userspace VM, and from then on any program in that VM can run it:
|
|
289
|
+
|
|
290
|
+
\`\`\`ts
|
|
291
|
+
import { enableModuleCommands } from "@oxvm/sdk/wasm";
|
|
292
|
+
import { ${a(t)} } from "./oxvm.modules.generated";
|
|
293
|
+
|
|
294
|
+
const commands = await enableModuleCommands(vm, ${a(t)});
|
|
295
|
+
// A terminal in the VM now runs \`${s?e:`${e} 2 3`}\`${s?" like any other program":", which prints 5"}.
|
|
296
|
+
await commands.disable();
|
|
297
|
+
\`\`\`
|
|
298
|
+
|
|
299
|
+
A third argument turns on only some of a module's commands (\`commands\`), sets its \`options\`, and bounds how many runs may be active at once (\`concurrency\`, 4 by default).
|
|
300
|
+
|
|
301
|
+
Turning the command on places a stub at \`/usr/local/bin/${e}\`. A shell finds it when its \`PATH\` lists \`/usr/local/bin\` before \`/usr/bin\`, and then the command takes the place of an image program with the same name. It runs as the guest user, with the caller's arguments, environment, working directory and standard streams. A shell sees these exit statuses:
|
|
302
|
+
|
|
303
|
+
| Status | Meaning |
|
|
304
|
+
| --- | --- |
|
|
305
|
+
| 0-119 | the module's own status |
|
|
306
|
+
| 120 | the module could not be launched |
|
|
307
|
+
| 122 | a prerequisite is missing |
|
|
308
|
+
| 123 | the adapter failed: it threw, or returned an invalid status |
|
|
309
|
+
| 125 | the engine failed |
|
|
310
|
+
| 126 | the stub ran as an ordinary program: the command is not turned on in this VM, or more runs are active than \`concurrency\` allows |
|
|
311
|
+
| 127 | the command is not on \`PATH\` |
|
|
312
|
+
| 128+n | the process was killed by signal n (130 for Ctrl+C) |
|
|
313
|
+
`}n(g,"shellSection");function _(t,e,s){const r=e.kind==="command"?'A command module runs once per start, like a program: `spawnModule(vm, handle, { args: ["2", "3"] })`.':"A service module listens on the sockets its manifest declares and serves clients until it is stopped.";return`# ${t}
|
|
314
|
+
|
|
315
|
+
A [OXVM](https://oxvm.dev) WebAssembly module (${e.kind}). ${r}
|
|
316
|
+
|
|
317
|
+
## Use it
|
|
318
|
+
|
|
319
|
+
In a OXVM application:
|
|
320
|
+
|
|
321
|
+
\`\`\`sh
|
|
322
|
+
oxvm wasm add github:OWNER/REPO@v0.1.0
|
|
323
|
+
\`\`\`
|
|
324
|
+
|
|
325
|
+
The command shows what the module declares and asks before installing it.
|
|
326
|
+
${e.kind==="command"?g(t,e.command,e.skeleton):""}${h(s)}
|
|
327
|
+
## Develop it
|
|
328
|
+
|
|
329
|
+
\`\`\`sh
|
|
330
|
+
pnpm install
|
|
331
|
+
pnpm run check # types, lint, and the same checks the build makes
|
|
332
|
+
pnpm test # unit tests of your own code
|
|
333
|
+
pnpm run test:conformance # oxvm wasm test: the runner's contract, in Chromium
|
|
334
|
+
pnpm run build # writes dist/: module.json, adapter.mjs, your artifacts and SHA256SUMS
|
|
335
|
+
\`\`\`
|
|
336
|
+
|
|
337
|
+
\`module.ts\` is the whole definition. \`upstream/\` holds the WebAssembly files the module wraps.
|
|
338
|
+
|
|
339
|
+
## Release it
|
|
340
|
+
|
|
341
|
+
\`\`\`sh
|
|
342
|
+
git tag v0.1.0 && git push origin v0.1.0
|
|
343
|
+
\`\`\`
|
|
344
|
+
|
|
345
|
+
The tag must name the version in \`module.ts\`. The \`release\` workflow builds, drafts a GitHub release with every file in \`dist/\`, downloads it again to verify its \`SHA256SUMS\`, and publishes it. \`pnpm run release\` prints the same steps for doing it by hand.
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
Apache-2.0 (see \`LICENSE\`). Change the license in \`module.ts\` and this repository to match the code you wrap, and keep the notices of anything you bundle.
|
|
350
|
+
`}n(_,"readmeFile");export{x as ADD_WASM,O as ESLINT_CONFIG,N as GITIGNORE,v as OPERANDS_SOURCE,k as OPERANDS_TEST,o as RESERVED_COMMAND_PREFIX,M as TEMPLATE_PLAYWRIGHT,E as TEST_TSCONFIG,A as TSCONFIG,$ as addCommandSource,S as addCommandTest,H as agentsFile,I as ciWorkflow,b as commandFor,a as handleName,T as moduleTest,C as noticeFile,_ as readmeFile,R as releaseWorkflow};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** How far a generated module reaches on the network; `oxvm wasm init --network`. */
|
|
2
|
+
export type TemplateReach = "none" | "vm" | "internet";
|
|
3
|
+
export declare const TEMPLATE_REACHES: readonly TemplateReach[];
|
|
4
|
+
/** The `requires.host` token of a reach, or none. */
|
|
5
|
+
export declare function reachToken(reach: TemplateReach): "net.vm" | "net.internet" | undefined;
|
|
6
|
+
/** The disclosure an internet module starts with (N-2): shown at install and by `oxvm wasm doctor`, never enforced. */
|
|
7
|
+
export declare const NETWORK_DISCLOSURE = " network: { purpose: \"Describe in one sentence what this module contacts on the internet, and why.\" },\n";
|
|
8
|
+
/** `src/net.ts` of a module with a reach: one bounded request, cancelled with the module, that throws on failure. */
|
|
9
|
+
export declare const NET_SOURCE = "import type { BaseHost } from \"@oxvm/sdk/wasm\";\n\n/** How long one request may take before it is abandoned. */\nexport const REQUEST_TIMEOUT_MS = 10_000;\n/** The most bytes one answer may have. */\nexport const MAX_ANSWER_BYTES = 1024 * 1024;\n\n/**\n * Fetches `url` as text through the module's VM network (the runner's `fetch`), cancelled with the module\n * (`host.signal`) or after REQUEST_TIMEOUT_MS, and bounded to MAX_ANSWER_BYTES. It throws on failure: a command prints\n * `host.kit.net.describe(error, argv0)` and returns `MODULE_EXIT.unavailable` (69); a service fails only that request.\n */\nexport async function fetchText(host: Pick<BaseHost, \"signal\">, url: string): Promise<string> {\n const response = await fetch(url, { signal: AbortSignal.any([host.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]) });\n if (!response.ok) throw new Error(`${url} answered HTTP ${String(response.status)}`);\n const body = response.body;\n if (body === null) return \"\";\n const reader = body.getReader(), decoder = new TextDecoder();\n let text = \"\", total = 0;\n for (let part = await reader.read(); !part.done; part = await reader.read()) {\n total += part.value.byteLength;\n if (total > MAX_ANSWER_BYTES) {\n await reader.cancel();\n throw new Error(`${url} answered more than ${String(MAX_ANSWER_BYTES)} bytes`);\n }\n text += decoder.decode(part.value, { stream: true });\n }\n return text + decoder.decode();\n}\n";
|
|
10
|
+
/** `test/net.test.ts`: the helper through the SDK's real runner and fake network (\`testHost\`). */
|
|
11
|
+
export declare function netTest(reach: "vm" | "internet"): string;
|
|
12
|
+
/** The README's "Network" section (N-10): the reach, the disclosure, and what happens offline. */
|
|
13
|
+
export declare function networkSection(reach: TemplateReach): string;
|
|
14
|
+
/** AGENTS.md "Networking rules": ADR 0029, N-1 to N-10, condensed. */
|
|
15
|
+
export declare const NETWORK_RULES = "\n## Networking rules\n\nThe module networking standard (OXVM engine ADR 0029; the SDK's `docs/wasm-modules.md`, \"Networking\"):\n\n1. Declare one reach in `requires.host`: none, `net.vm` or `net.internet`. Rust enforces it for every process of the module.\n2. With `net.internet`, disclose default hosts and the purpose in `network`; it is shown at install and never an allowlist.\n3. Use only the host's network: `fetch`, `WebSocket`, `host.net`. `XMLHttpRequest`, `EventSource`, `sendBeacon`, WebRTC, WebTransport and remote `import()` or `importScripts` do not exist in module workers.\n4. Adapt a runtime's own network layer with `host.kit.emscripten.network` or `host.kit.tls`; never bypass the host.\n5. Offline or revoked, a command prints one line from `host.kit.net.describe(error, argv0)` and returns `MODULE_EXIT.unavailable` (69); a service fails only the affected request. Never retry in a loop.\n6. Every request carries `host.signal` (or a signal derived from it) and a timeout; read bodies as streams or bounded.\n7. TLS always verifies against the VM's `/etc/ssl/cert.pem`. Credentials come only from options or guest files.\n8. Internet means TCP 80 and 443 plus DNS; nothing connects in. Programs started with `process.spawn` follow the VM's own policy.\n9. Test with `testHost` from `@oxvm/sdk/wasm/testing` (local-only by default); `oxvm wasm test` checks `network-direct`, `network-declared` and `network-offline`.\n10. Keep the README's \"Network\" section true: reach, disclosed hosts, purpose, and behaviour offline.\n";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var r=Object.defineProperty;var n=(e,t)=>r(e,"name",{value:t,configurable:!0});const c=["none","vm","internet"];function a(e){return e==="vm"?"net.vm":e==="internet"?"net.internet":void 0}n(a,"reachToken");const l=` network: { purpose: "Describe in one sentence what this module contacts on the internet, and why." },
|
|
2
|
+
`,d=`import type { BaseHost } from "@oxvm/sdk/wasm";
|
|
3
|
+
|
|
4
|
+
/** How long one request may take before it is abandoned. */
|
|
5
|
+
export const REQUEST_TIMEOUT_MS = 10_000;
|
|
6
|
+
/** The most bytes one answer may have. */
|
|
7
|
+
export const MAX_ANSWER_BYTES = 1024 * 1024;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fetches \`url\` as text through the module's VM network (the runner's \`fetch\`), cancelled with the module
|
|
11
|
+
* (\`host.signal\`) or after REQUEST_TIMEOUT_MS, and bounded to MAX_ANSWER_BYTES. It throws on failure: a command prints
|
|
12
|
+
* \`host.kit.net.describe(error, argv0)\` and returns \`MODULE_EXIT.unavailable\` (69); a service fails only that request.
|
|
13
|
+
*/
|
|
14
|
+
export async function fetchText(host: Pick<BaseHost, "signal">, url: string): Promise<string> {
|
|
15
|
+
const response = await fetch(url, { signal: AbortSignal.any([host.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]) });
|
|
16
|
+
if (!response.ok) throw new Error(\`\${url} answered HTTP \${String(response.status)}\`);
|
|
17
|
+
const body = response.body;
|
|
18
|
+
if (body === null) return "";
|
|
19
|
+
const reader = body.getReader(), decoder = new TextDecoder();
|
|
20
|
+
let text = "", total = 0;
|
|
21
|
+
for (let part = await reader.read(); !part.done; part = await reader.read()) {
|
|
22
|
+
total += part.value.byteLength;
|
|
23
|
+
if (total > MAX_ANSWER_BYTES) {
|
|
24
|
+
await reader.cancel();
|
|
25
|
+
throw new Error(\`\${url} answered more than \${String(MAX_ANSWER_BYTES)} bytes\`);
|
|
26
|
+
}
|
|
27
|
+
text += decoder.decode(part.value, { stream: true });
|
|
28
|
+
}
|
|
29
|
+
return text + decoder.decode();
|
|
30
|
+
}
|
|
31
|
+
`;function h(e){const t=a(e)??"net.vm",o=e==="internet"?` it("answers through the VM's connection", async () => {
|
|
32
|
+
const result = await testHost(probe, { args: ["https://api.example.com/hello"], net: { connected: true, http: { "https://api.example.com": request => new Response(\`hello from \${new URL(request.url).pathname}\`) } } }).run();
|
|
33
|
+
expect(result).toMatchObject({ status: 0, stderr: "hello from /hello\\n" });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("fails with one line and status 69 while the VM is not connected", async () => {
|
|
37
|
+
const result = await testHost(probe, { args: ["https://api.example.com/hello"] }).run();
|
|
38
|
+
expect(result).toMatchObject({ status: MODULE_EXIT.unavailable, stderr: "net-probe: network unavailable: this VM is not connected to the internet\\n" });
|
|
39
|
+
});
|
|
40
|
+
`:` it("reaches a program in this VM, also while the VM is not connected to the internet", async () => {
|
|
41
|
+
const result = await testHost(probe, { args: ["http://vm:8080/hello"], net: { vm: { 8080: request => new Response(\`hello from \${new URL(request.url).pathname}\`) } } }).run();
|
|
42
|
+
expect(result).toMatchObject({ status: 0, stderr: "hello from /hello\\n" });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("is refused beyond the VM, with one line and status 69", async () => {
|
|
46
|
+
const result = await testHost(probe, { args: ["https://93.184.216.34/"], net: { connected: true } }).run();
|
|
47
|
+
expect(result.status).toBe(MODULE_EXIT.unavailable);
|
|
48
|
+
expect(result.stderr).toContain("net-probe: network refused: 93.184.216.34 is beyond this module's declared network reach\\n");
|
|
49
|
+
});
|
|
50
|
+
`,s=e==="internet"?`
|
|
51
|
+
it("a module that declares only net.vm is refused beyond the VM", async () => {
|
|
52
|
+
const vmOnly = defineModule({ manifest: { ...probe.manifest, id: "net-probe-vm", requires: { host: ["net.vm"] } }, adapter: probe.adapter });
|
|
53
|
+
const result = await testHost(vmOnly, { args: ["https://93.184.216.34/"], net: { connected: true } }).run();
|
|
54
|
+
expect(result.status).toBe(MODULE_EXIT.unavailable);
|
|
55
|
+
expect(result.stderr).toContain("network refused: 93.184.216.34 is beyond this module's declared network reach");
|
|
56
|
+
});
|
|
57
|
+
`:"";return`import { describe, expect, it } from "vitest";
|
|
58
|
+
import { defineModule, MODULE_EXIT } from "@oxvm/sdk/wasm";
|
|
59
|
+
import { testHost } from "@oxvm/sdk/wasm/testing";
|
|
60
|
+
import { fetchText } from "../src/net.ts";
|
|
61
|
+
|
|
62
|
+
/** A command that prints what fetchText answers for its argument, the way the module's own code uses it. */
|
|
63
|
+
const probe = defineModule({
|
|
64
|
+
manifest: {
|
|
65
|
+
id: "net-probe", version: "0.1.0", abi: "raw", artifacts: [], process: { kind: "command" },
|
|
66
|
+
requires: { host: [${JSON.stringify(t)}] }, license: { spdx: "Apache-2.0" },
|
|
67
|
+
},
|
|
68
|
+
adapter: host => ({
|
|
69
|
+
main: async io => {
|
|
70
|
+
try {
|
|
71
|
+
host.log(await fetchText(host, io.args[0] ?? ""));
|
|
72
|
+
return 0;
|
|
73
|
+
} catch (error: unknown) {
|
|
74
|
+
host.log(host.kit.net.describe(error, "net-probe"));
|
|
75
|
+
return MODULE_EXIT.unavailable;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("fetchText", () => {
|
|
82
|
+
${o}${s}
|
|
83
|
+
it("is cancelled with the module", async () => {
|
|
84
|
+
await expect(fetchText({ signal: AbortSignal.abort() }, "https://api.example.com/")).rejects.toMatchObject({ name: "AbortError" });
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
`}n(h,"netTest");function u(e){return`
|
|
88
|
+
## Network
|
|
89
|
+
|
|
90
|
+
${e==="none"?'This module declares no network reach: it opens no connections of its own\nand its `fetch` fails with "network not declared". A service still serves programs in the VM through `expose`.':e==="vm"?"This module reaches programs in its own VM only (`net.vm`): loopback, Unix sockets and the VM's own addresses, with names from the VM's `/etc/hosts`. It works the same whether or not the VM is connected to the internet. A connection beyond the VM fails with `EACCES`.":"This module reaches the internet through the VM's connection (`net.internet`): public hosts on TCP 80 and 443, with DNS through the VM's resolver and TLS verified against the VM's `/etc/ssl/cert.pem`.\n\n- Hosts it contacts by default, and why: see `network` in `module.ts` (shown at install; not an allowlist).\n- Until the application connects the VM (`vm.network.connect`), and after the user revokes it, a request fails. A command then prints one line (`network unavailable: this VM is not connected to the internet`) and exits 69; a service fails only that request and stays ready."}
|
|
91
|
+
`}n(u,"networkSection");const m="\n## Networking rules\n\nThe module networking standard (OXVM engine ADR 0029; the SDK's `docs/wasm-modules.md`, \"Networking\"):\n\n1. Declare one reach in `requires.host`: none, `net.vm` or `net.internet`. Rust enforces it for every process of the module.\n2. With `net.internet`, disclose default hosts and the purpose in `network`; it is shown at install and never an allowlist.\n3. Use only the host's network: `fetch`, `WebSocket`, `host.net`. `XMLHttpRequest`, `EventSource`, `sendBeacon`, WebRTC, WebTransport and remote `import()` or `importScripts` do not exist in module workers.\n4. Adapt a runtime's own network layer with `host.kit.emscripten.network` or `host.kit.tls`; never bypass the host.\n5. Offline or revoked, a command prints one line from `host.kit.net.describe(error, argv0)` and returns `MODULE_EXIT.unavailable` (69); a service fails only the affected request. Never retry in a loop.\n6. Every request carries `host.signal` (or a signal derived from it) and a timeout; read bodies as streams or bounded.\n7. TLS always verifies against the VM's `/etc/ssl/cert.pem`. Credentials come only from options or guest files.\n8. Internet means TCP 80 and 443 plus DNS; nothing connects in. Programs started with `process.spawn` follow the VM's own policy.\n9. Test with `testHost` from `@oxvm/sdk/wasm/testing` (local-only by default); `oxvm wasm test` checks `network-direct`, `network-declared` and `network-offline`.\n10. Keep the README's \"Network\" section true: reach, disclosed hosts, purpose, and behaviour offline.\n";export{l as NETWORK_DISCLOSURE,m as NETWORK_RULES,d as NET_SOURCE,c as TEMPLATE_REACHES,h as netTest,u as networkSection,a as reachToken};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WasmInitResult } from "./contracts.js";
|
|
2
|
+
import { type TemplateReach } from "./wasm-template-network.js";
|
|
3
|
+
export type ModuleKind = "command" | "service";
|
|
4
|
+
/** A module id from a directory name: lowercase letters, digits and hyphens, starting with a letter. */
|
|
5
|
+
export declare function moduleIdFor(directory: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a module project that builds and passes its own checks as generated. The module definition is read back
|
|
8
|
+
* through the same extractor the build uses before anything is written, so an id or file name that would make an
|
|
9
|
+
* invalid manifest fails here, not later.
|
|
10
|
+
*/
|
|
11
|
+
export declare function initializeModule(directory: string, options: {
|
|
12
|
+
readonly kind: ModuleKind;
|
|
13
|
+
readonly id?: string;
|
|
14
|
+
readonly from?: string;
|
|
15
|
+
readonly network?: TemplateReach;
|
|
16
|
+
}): Promise<WasmInitResult>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var h=Object.defineProperty;var r=(t,e)=>h(t,"name",{value:e,configurable:!0});import{mkdir as g,readFile as p}from"node:fs/promises";import{basename as u,join as y}from"node:path";import{VMError as c}from"@oxvm/sdk";import{WasmBuildFailure as k,extractManifest as N,getSDKRelease as x,inspectWasm as E}from"@oxvm/sdk/image-builder";import{file as S,newDirectory as A}from"./template-files.js";import{registryConfig as $}from"./templates.js";import{ADD_WASM as O,ESLINT_CONFIG as b,GITIGNORE as T,TEMPLATE_PLAYWRIGHT as v,OPERANDS_SOURCE as I,OPERANDS_TEST as M,TEST_TSCONFIG as R,TSCONFIG as _,addCommandSource as C,addCommandTest as J,agentsFile as D,ciWorkflow as L,commandFor as F,moduleTest as G,noticeFile as W,readmeFile as U,releaseWorkflow as V}from"./wasm-template-files.js";import{NET_SOURCE as z,NETWORK_DISCLOSURE as P,netTest as q,reachToken as B}from"./wasm-template-network.js";const X=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u,H=512*1024**2;function K(t){const e=u(t).toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,63);return e===""?"my-module":/^[a-z]/u.test(e)?e:`module-${e}`.slice(0,63)}r(K,"moduleIdFor");async function Y(t,e){if(t===void 0)return{artifact:"add.wasm",abi:"raw",bytes:O,skeleton:!1};const n=u(t);if(!X.test(n)||!n.endsWith(".wasm"))throw new c("INVALID_ARGUMENT",`--from must name a .wasm file whose name is letters, digits, dots, hyphens or underscores, not ${JSON.stringify(n)}`);const s=new Uint8Array(await p(t).catch(()=>{throw new c("INVALID_ARGUMENT",`--from ${JSON.stringify(t)} cannot be read`)}));if(s.byteLength>H)throw new c("INVALID_ARGUMENT","--from is larger than a release can pin");const i=await E(s).catch(o=>{throw o instanceof c?o:new c("INVALID_ARGUMENT",`--from ${JSON.stringify(t)} is not a WebAssembly binary`)});return{artifact:n,abi:i.abi,bytes:s,skeleton:!0}}r(Y,"subjectFor");const f=r((t,e,n,s,i,o)=>` id: ${JSON.stringify(t)},
|
|
2
|
+
version: "0.1.0",
|
|
3
|
+
abi: ${JSON.stringify(e.abi)},
|
|
4
|
+
artifacts: [{ name: ${JSON.stringify(e.artifact)}, from: ${JSON.stringify(`upstream/${e.artifact}`)} }],
|
|
5
|
+
process: { kind: ${JSON.stringify(n)} },
|
|
6
|
+
${o===void 0?"":` commands: [${JSON.stringify(o)}],
|
|
7
|
+
`}${n==="service"?` expose: { main: { kind: "unix", path: ${JSON.stringify(`/workspace/_oxidevm/${t}.sock`)}, protocol: ${JSON.stringify(`${t}/1`)} } },
|
|
8
|
+
`:""} requires: { host: [${Z(s,i)}] },
|
|
9
|
+
${i==="internet"?P:""} license: { spdx: "Apache-2.0" },`,"MANIFEST_HEAD");function Z(t,e){const n=B(e);return n===void 0?t:t===""?JSON.stringify(n):`${t}, ${JSON.stringify(n)}`}r(Z,"withReach");function Q(t,e,n,s){return e.skeleton?`import { defineModule } from "@oxvm/sdk/wasm";
|
|
10
|
+
|
|
11
|
+
export default defineModule({
|
|
12
|
+
manifest: {
|
|
13
|
+
${f(t,e,"command","",s,n)}
|
|
14
|
+
},
|
|
15
|
+
adapter: async host => {
|
|
16
|
+
// Compile the artifact once, at start. Instantiate it here with the imports its ABI needs;
|
|
17
|
+
// \`oxvm wasm inspect upstream/${e.artifact}\` lists them. Declare what the adapter uses in requires.host.
|
|
18
|
+
await host.artifacts.compile(${JSON.stringify(e.artifact)});
|
|
19
|
+
return { main: () => host.fail(2, ${JSON.stringify(`${t} has no behavior yet: edit module.ts`)}) };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
`:`import { defineModule } from "@oxvm/sdk/wasm";
|
|
23
|
+
import { addCommand } from "./src/command.ts";
|
|
24
|
+
|
|
25
|
+
export default defineModule({
|
|
26
|
+
manifest: {
|
|
27
|
+
${f(t,e,"command",'"files.sync"',s,n)}
|
|
28
|
+
},
|
|
29
|
+
adapter: async host => {
|
|
30
|
+
const instance = await WebAssembly.instantiate(await host.artifacts.compile("add.wasm"));
|
|
31
|
+
const exported = instance.exports["add"];
|
|
32
|
+
if (typeof exported !== "function") throw new Error("add.wasm does not export add");
|
|
33
|
+
// WebAssembly hands back an untyped function; the command calls it with two 32-bit integers.
|
|
34
|
+
const add = (left: number, right: number): unknown => Reflect.apply(exported, undefined, [left, right]);
|
|
35
|
+
return addCommand(host, add);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
`}r(Q,"commandSource");function j(t,e,n){return e.skeleton?`import { defineModule } from "@oxvm/sdk/wasm";
|
|
39
|
+
|
|
40
|
+
export default defineModule({
|
|
41
|
+
manifest: {
|
|
42
|
+
${f(t,e,"service","",n)}
|
|
43
|
+
},
|
|
44
|
+
adapter: async host => {
|
|
45
|
+
// Compile the artifact once, at start, and keep what you build from it in this closure.
|
|
46
|
+
await host.artifacts.compile(${JSON.stringify(e.artifact)});
|
|
47
|
+
return {
|
|
48
|
+
protocols: {
|
|
49
|
+
main: async connection => { await connection.write(new TextEncoder().encode("not implemented\\n")); },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
`:`import { defineModule } from "@oxvm/sdk/wasm";
|
|
55
|
+
import { parseOperands } from "./src/operands.ts";
|
|
56
|
+
|
|
57
|
+
// One request per line, "<a> <b>", answered with "<sum>" or "error". A line longer than this closes the connection.
|
|
58
|
+
const MAX_LINE = 1024;
|
|
59
|
+
|
|
60
|
+
export default defineModule({
|
|
61
|
+
manifest: {
|
|
62
|
+
${f(t,e,"service","",n).replace("expose: { main:","expose: { add:")}
|
|
63
|
+
},
|
|
64
|
+
adapter: async host => {
|
|
65
|
+
const instance = await WebAssembly.instantiate(await host.artifacts.compile("add.wasm"));
|
|
66
|
+
const add = instance.exports["add"];
|
|
67
|
+
if (typeof add !== "function") throw new Error("add.wasm does not export add");
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
return {
|
|
70
|
+
protocols: {
|
|
71
|
+
add: async connection => {
|
|
72
|
+
const decoder = new TextDecoder();
|
|
73
|
+
let pending = "";
|
|
74
|
+
for (;;) {
|
|
75
|
+
const chunk = await connection.read(4096);
|
|
76
|
+
if (chunk.length === 0) return;
|
|
77
|
+
pending += decoder.decode(chunk, { stream: true });
|
|
78
|
+
for (let end = pending.indexOf("\\n"); end !== -1; end = pending.indexOf("\\n")) {
|
|
79
|
+
const operands = parseOperands(pending.slice(0, end).split(" "));
|
|
80
|
+
pending = pending.slice(end + 1);
|
|
81
|
+
await connection.write(encoder.encode(operands === undefined ? "error\\n" : \`\${String(Reflect.apply(add, undefined, operands))}\\n\`));
|
|
82
|
+
}
|
|
83
|
+
if (pending.length > MAX_LINE) return;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
`}r(j,"serviceSource");function ee(t,e){const n=x().sdkVersion;return`${JSON.stringify({name:t,private:!0,license:"Apache-2.0",type:"module",scripts:{build:"oxvm wasm build",check:"tsc --noEmit && tsc --noEmit -p test && eslint . --max-warnings 0 && oxvm wasm build --check",release:"oxvm wasm release",test:"vitest run","test:conformance":e==="command"?"oxvm wasm build && oxvm wasm test --arg 2 --arg 3":"oxvm wasm build && oxvm wasm test"},devDependencies:{"@eslint/js":"10.0.1","@oxvm/cli":n,"@oxvm/sdk":n,"@types/node":"24.13.3",eslint:"10.7.0",playwright:v,typescript:"6.0.3","typescript-eslint":"8.65.0",vitest:"5.1.0"}},null,2)}
|
|
91
|
+
`}r(ee,"packageJson");async function me(t,e){const n=e.network??"none",s=e.id??K(t),i=await Y(e.from,t),o=e.kind==="command"?{kind:"command",command:F(s),skeleton:i.skeleton}:{kind:"service"},l=o.kind==="command"?Q(s,i,o.command,n):j(s,i,n);try{N(l,"module.ts")}catch(d){throw d instanceof k?new c("INVALID_ARGUMENT",`the module cannot be created: ${d.findings[0]?.message??"invalid manifest"}`):d}const m=await $();await A(t);for(const d of["src","test","upstream",".github/workflows"])await g(y(t,d),{recursive:!0});const a=new Map([["module.ts",l],[`upstream/${i.artifact}`,i.bytes],["package.json",ee(s,e.kind)],["tsconfig.json",_],["test/tsconfig.json",R],["test/module.test.ts",G(s,o,n)],["eslint.config.js",b],[".gitignore",T],["README.md",U(s,o,n)],["AGENTS.md",D(s,o)],["LICENSE",await p(new URL("../LICENSE",import.meta.url),"utf8")],["NOTICE",W(s)],[".github/workflows/ci.yml",L(m!==void 0)],[".github/workflows/release.yml",V(m!==void 0)]]);i.skeleton||(a.set("src/operands.ts",I),a.set("test/operands.test.ts",M)),!i.skeleton&&o.kind==="command"&&(a.set("src/command.ts",C(s,o.command)),a.set("test/command.test.ts",J(s,o.command))),n!=="none"&&(a.set("src/net.ts",z),a.set("test/net.test.ts",q(n))),m!==void 0&&a.set(".npmrc",m);for(const[d,w]of a)await S(t,d,w);return{directory:t,id:s,kind:e.kind,abi:i.abi,network:n,files:[...a.keys()].sort(),...o.kind==="command"?{commands:o.command===void 0?[]:[o.command]}:{}}}r(me,"initializeModule");export{me as initializeModule,K as moduleIdFor};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AddPreview, WasmAddResult, WasmBuildResult, WasmDoctorReport, WasmInspectResult, WasmStageResult, WasmTestReport } from "@oxvm/sdk/image-builder";
|
|
2
|
+
import type { WasmInitResult, WasmReleaseResult } from "./contracts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Escapes what a terminal acts on or a reader cannot see (control, bidi, zero-width and separator characters) as its code
|
|
5
|
+
* point, and keeps line breaks. For whole outputs that may hold text from a module, a file or a Wasm binary.
|
|
6
|
+
*/
|
|
7
|
+
export declare const printable: (text: string) => string;
|
|
8
|
+
/** The same escaping for one value placed inside a line, line breaks included, so a value cannot start a line of its own. */
|
|
9
|
+
export declare const field: (text: string) => string;
|
|
10
|
+
/** What the card needs of a preview: the release's declarations and how it differs from what is installed. */
|
|
11
|
+
export type ConsentView = Pick<AddPreview, "card" | "status" | "added" | "removed"> & {
|
|
12
|
+
readonly consent: Pick<AddPreview["consent"], "reasons">;
|
|
13
|
+
};
|
|
14
|
+
/** What the person is asked to accept, as plain lines. The wording says "declares": a module is code, not a sandbox. */
|
|
15
|
+
export declare function consentText(preview: ConsentView): string;
|
|
16
|
+
export declare function addText(result: WasmAddResult): string;
|
|
17
|
+
export declare function stageText(result: WasmStageResult): string;
|
|
18
|
+
export declare function doctorText(report: WasmDoctorReport): string;
|
|
19
|
+
export declare function inspectText(result: WasmInspectResult): string;
|
|
20
|
+
export declare function buildText(result: WasmBuildResult): string;
|
|
21
|
+
export declare function releaseText(result: WasmReleaseResult): string;
|
|
22
|
+
export declare function initText(result: WasmInitResult): string;
|
|
23
|
+
export declare function testText(report: WasmTestReport): string;
|