@zebeqo/vendy 2.0.0-beta.2 → 2.0.0-beta.3

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.
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Zebeqo
3
+ Copyright (c) 2025 opencode
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/bin/vendy.exe ADDED
@@ -0,0 +1,5 @@
1
+ echo "Error: @zebeqo/vendy's postinstall script was not run." >&2
2
+ echo "" >&2
3
+ echo "This occurs when installation scripts are disabled." >&2
4
+ echo "Run the package postinstall script or reinstall with scripts enabled." >&2
5
+ exit 1
package/package.json CHANGED
@@ -1,50 +1,38 @@
1
1
  {
2
2
  "name": "@zebeqo/vendy",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Zebeqo/vendy.git",
7
7
  "directory": "packages/vendy"
8
8
  },
9
9
  "bin": {
10
- "vendy": "./dist/index.mjs"
10
+ "vendy": "./bin/vendy.exe"
11
11
  },
12
- "files": [
13
- "dist"
12
+ "os": [
13
+ "darwin",
14
+ "linux",
15
+ "win32"
16
+ ],
17
+ "cpu": [
18
+ "arm64",
19
+ "x64"
14
20
  ],
15
- "type": "module",
16
- "publishConfig": {
17
- "access": "public"
18
- },
19
- "devDependencies": {
20
- "@effect/atom-react": "4.0.0-rc.112",
21
- "@effect/platform-node": "4.0.0-rc.112",
22
- "@effect/vitest": "4.0.0-rc.112",
23
- "@opentui-ui/toast": "^0.0.5",
24
- "@opentui/core": "^0.5.4",
25
- "@opentui/react": "^0.5.4",
26
- "@tanstack/react-router": "1.170.16",
27
- "@tanstack/router-cli": "^1.167.23",
28
- "@tuiparts/react": "^0.0.6",
29
- "@types/bun": "^1.4.0",
30
- "@types/react": "^19.2.18",
31
- "diff": "^9.0.0",
32
- "effect": "4.0.0-rc.112",
33
- "react": "^19.2.6",
34
- "string-width": "^7.2.0"
35
- },
36
21
  "optionalDependencies": {
37
- "@zebeqo/vendy-darwin-arm64": "2.0.0-beta.2",
38
- "@zebeqo/vendy-darwin-x64": "2.0.0-beta.2",
39
- "@zebeqo/vendy-linux-arm64": "2.0.0-beta.2",
40
- "@zebeqo/vendy-linux-x64": "2.0.0-beta.2",
41
- "@zebeqo/vendy-win32-arm64": "2.0.0-beta.2",
42
- "@zebeqo/vendy-win32-x64": "2.0.0-beta.2"
22
+ "@zebeqo/vendy-darwin-arm64": "2.0.0-beta.3",
23
+ "@zebeqo/vendy-darwin-x64": "2.0.0-beta.3",
24
+ "@zebeqo/vendy-darwin-x64-baseline": "2.0.0-beta.3",
25
+ "@zebeqo/vendy-linux-arm64": "2.0.0-beta.3",
26
+ "@zebeqo/vendy-linux-arm64-musl": "2.0.0-beta.3",
27
+ "@zebeqo/vendy-linux-x64": "2.0.0-beta.3",
28
+ "@zebeqo/vendy-linux-x64-baseline": "2.0.0-beta.3",
29
+ "@zebeqo/vendy-linux-x64-baseline-musl": "2.0.0-beta.3",
30
+ "@zebeqo/vendy-linux-x64-musl": "2.0.0-beta.3",
31
+ "@zebeqo/vendy-windows-arm64": "2.0.0-beta.3",
32
+ "@zebeqo/vendy-windows-x64": "2.0.0-beta.3",
33
+ "@zebeqo/vendy-windows-x64-baseline": "2.0.0-beta.3"
43
34
  },
44
35
  "scripts": {
45
- "generate-routes": "tsr generate",
46
- "watch-routes": "tsr watch",
47
- "vendy": "node scripts/generate-skills.mts && tsr generate && bun run src/main.ts",
48
- "generate-skills": "node scripts/generate-skills.mts"
36
+ "postinstall": "node ./postinstall.mjs"
49
37
  }
50
38
  }
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ // Adapted from OpenCode (MIT); see LICENSE.opencode.
3
+
4
+ import childProcess from "node:child_process";
5
+ import fs from "node:fs";
6
+ import { createRequire } from "node:module";
7
+ import os from "node:os";
8
+ import path from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ const directory = path.dirname(fileURLToPath(import.meta.url));
12
+ const require = createRequire(import.meta.url);
13
+ const packageJson = JSON.parse(fs.readFileSync(path.join(directory, "package.json"), "utf8"));
14
+ const command = Object.keys(packageJson.bin ?? {})[0];
15
+ if (!command) throw new Error("vendy package does not declare a binary");
16
+ const sourceCommand = command;
17
+
18
+ const platform =
19
+ { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] ?? os.platform();
20
+ const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] ?? os.arch();
21
+ const sourceBinary = platform === "windows" ? `${sourceCommand}.exe` : sourceCommand;
22
+ const targetBinary = path.resolve(directory, packageJson.bin[command]);
23
+ const dependencies = packageJson.optionalDependencies ?? {};
24
+ const base = Object.keys(dependencies).find((name) => name.endsWith(`-${platform}-${arch}`));
25
+ if (!base) throw new Error(`vendy does not provide a binary for ${platform}-${arch}`);
26
+
27
+ function supportsAvx2() {
28
+ if (arch !== "x64") return false;
29
+ if (platform === "linux") {
30
+ try {
31
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"));
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+ if (platform === "darwin") {
37
+ try {
38
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
39
+ encoding: "utf8",
40
+ timeout: 1500,
41
+ });
42
+ return result.status === 0 && (result.stdout || "").trim() === "1";
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ if (platform === "windows") {
48
+ const script =
49
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)';
50
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
51
+ try {
52
+ const result = childProcess.spawnSync(
53
+ executable,
54
+ ["-NoProfile", "-NonInteractive", "-Command", script],
55
+ {
56
+ encoding: "utf8",
57
+ timeout: 3000,
58
+ windowsHide: true,
59
+ },
60
+ );
61
+ if (result.status !== 0) continue;
62
+ const output = (result.stdout || "").trim().toLowerCase();
63
+ if (output === "true" || output === "1") return true;
64
+ if (output === "false" || output === "0") return false;
65
+ } catch {
66
+ continue;
67
+ }
68
+ }
69
+ }
70
+ return false;
71
+ }
72
+
73
+ function isMusl() {
74
+ if (platform !== "linux") return false;
75
+ try {
76
+ if (fs.existsSync("/etc/alpine-release")) return true;
77
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" });
78
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl");
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
84
+ function packageNames() {
85
+ const tiers = arch === "x64" ? ["", "-baseline"] : [""];
86
+ if (arch === "x64" && !supportsAvx2()) tiers.reverse();
87
+ const libcs = platform === "linux" ? ["", "-musl"] : [""];
88
+ if (isMusl()) libcs.reverse();
89
+ const names = libcs.flatMap((libc) => tiers.map((tier) => `${base}${tier}${libc}`));
90
+ return names.filter((name) => dependencies[name]);
91
+ }
92
+
93
+ function copyBinary(source) {
94
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`);
95
+ fs.mkdirSync(path.dirname(targetBinary), { recursive: true });
96
+ if (fs.existsSync(targetBinary)) {
97
+ try {
98
+ fs.unlinkSync(targetBinary);
99
+ } catch {}
100
+ }
101
+ try {
102
+ fs.linkSync(source, targetBinary);
103
+ } catch {
104
+ fs.copyFileSync(source, targetBinary);
105
+ }
106
+ fs.chmodSync(targetBinary, 0o755);
107
+ }
108
+
109
+ function resolveBinary(name) {
110
+ const packagePath = require.resolve(`${name}/package.json`);
111
+ return path.join(path.dirname(packagePath), "bin", sourceBinary);
112
+ }
113
+
114
+ function installPackage(name) {
115
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "vendy-install-"));
116
+ try {
117
+ const result = childProcess.spawnSync(
118
+ "npm",
119
+ [
120
+ "install",
121
+ "--ignore-scripts",
122
+ "--no-save",
123
+ "--loglevel=error",
124
+ "--prefix",
125
+ temp,
126
+ `${name}@${dependencies[name]}`,
127
+ ],
128
+ { stdio: "inherit", windowsHide: true },
129
+ );
130
+ if (result.status !== 0) return false;
131
+ copyBinary(path.join(temp, "node_modules", name, "bin", sourceBinary));
132
+ return true;
133
+ } finally {
134
+ fs.rmSync(temp, { recursive: true, force: true });
135
+ }
136
+ }
137
+
138
+ function verifyBinary() {
139
+ return (
140
+ childProcess.spawnSync(targetBinary, ["--version"], {
141
+ stdio: "ignore",
142
+ windowsHide: true,
143
+ }).status === 0
144
+ );
145
+ }
146
+
147
+ function main() {
148
+ const names = packageNames();
149
+ for (const name of names) {
150
+ try {
151
+ copyBinary(resolveBinary(name));
152
+ if (verifyBinary()) return;
153
+ } catch {
154
+ if (installPackage(name) && verifyBinary()) return;
155
+ }
156
+ }
157
+
158
+ throw new Error(
159
+ `Failed to install vendy. Try manually installing ${names.map((name) => JSON.stringify(name)).join(" or ")}.`,
160
+ );
161
+ }
162
+
163
+ try {
164
+ main();
165
+ } catch (error) {
166
+ console.error(error instanceof Error ? error.message : String(error));
167
+ process.exit(1);
168
+ }
package/dist/index.mjs DELETED
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from "node:module";
3
- import { spawnSync } from "node:child_process";
4
- import process from "node:process";
5
- import { constants } from "node:os";
6
- //#region src/Target.ts
7
- /**
8
- * The platform executable, and the words for when there is none.
9
- *
10
- * This module is pure and has no dependencies on purpose. It runs on Node,
11
- * inside the published bin — the one file every user reaches, whatever their
12
- * machine — so everything it decides is a function of three environment fields.
13
- * That keeps it testable with no executable to resolve and none to spawn.
14
- *
15
- * It holds no list of supported targets. The package manager already made that
16
- * decision when it installed the one platform package whose `os` and `cpu`
17
- * match, or installed none: resolution is the check, and a second list here
18
- * could only disagree with it.
19
- */
20
- /** Installs the vendy agent skill: the second human path, and the only one left when nothing resolves. */
21
- const agentSkill = "npx skills add https://github.com/Zebeqo/vendy --skill vendy";
22
- /** `platform-arch`: the pair that names a build, its npm package, and the failure. */
23
- const name = (environment) => `${environment.platform}-${environment.arch}`;
24
- /**
25
- * The npm package carrying the executable for this environment.
26
- *
27
- * The family is scoped because npm refused two of the unscoped names —
28
- * `vendy-win32-x64` and its arm64 sibling — as spam, `win32` being a string
29
- * typosquatters abuse. One scope keeps one vocabulary, rather than a Windows
30
- * exception in the middle of the six.
31
- */
32
- const packageName = (environment) => `@zebeqo/vendy-${name(environment)}`;
33
- /**
34
- * The specifier the launcher resolves.
35
- *
36
- * A subpath rather than the package itself: a platform package holds one
37
- * executable and no JavaScript, so there is no entry point to import and
38
- * nothing an `exports` map would have to describe.
39
- */
40
- const executable = (environment) => `${packageName(environment)}/bin/vendy${environment.platform === "win32" ? ".exe" : ""}`;
41
- /**
42
- * musl is a supported `platform-arch` pair with an unsupported C library, so
43
- * this names the reason rather than the pair. The two Linux packages declare
44
- * `libc: "glibc"` so that nothing installs here and the user reads this instead
45
- * of a dynamic linker error from an executable that could never have run.
46
- *
47
- * It says nothing about what did or did not install, because an installer that
48
- * ignores `libc` puts the same user in front of the same wall one step later.
49
- */
50
- const wrongLibc = (environment) => `vendy has no executable for ${name(environment)} with musl. The published Linux executables link against glibc, and none of them runs here.
51
-
52
- You can still let your coding agent run vendy for you:
53
- ${agentSkill}`;
54
- /**
55
- * Two causes, one message, because the launcher cannot tell them apart: a
56
- * platform nobody built for, and an install that left optional dependencies
57
- * out. Both leave the same hole, and both recoveries are one line.
58
- */
59
- const missing = (environment) => `vendy has no executable to run. Its platform package ${packageName(environment)} did not install: either vendy publishes no build for ${name(environment)}, or this install left optional dependencies out.
60
-
61
- Install vendy again with optional dependencies included, or let your coding agent run vendy for you:
62
- ${agentSkill}`;
63
- /**
64
- * Read when the platform package does not resolve.
65
- *
66
- * That is now the only way vendy fails to launch, so this text carries
67
- * everything: what is missing, why it is missing, and what the user does next.
68
- */
69
- const unavailable = (environment) => environment.libc === "musl" ? wrongLibc(environment) : missing(environment);
70
- //#endregion
71
- //#region src/Launch.ts
72
- /**
73
- * The exit code to leave behind for a child that has finished.
74
- *
75
- * A child killed by a signal reports no status. Shells report those as
76
- * `128 + signal` and vendy does the same, so a renderer that segfaults is
77
- * never mistaken for a clean quit. A platform that does not name the signal
78
- * still gets a failure code, never a zero.
79
- */
80
- const exitCode = (completion) => {
81
- if (completion.signal === null) return completion.status ?? 1;
82
- const number = constants.signals[completion.signal];
83
- return Number.isInteger(number) ? 128 + number : 1;
84
- };
85
- /** Reads the `code` Node puts on the errors both edges throw, without asserting a type over them. */
86
- const hasCode = (error, code) => error instanceof Error && "code" in error && error.code === code;
87
- /**
88
- * Runs the executable for this machine and reports how that ended.
89
- *
90
- * Resolution is what decides whether vendy can run at all. It answers the
91
- * question the package manager already answered on install — one platform
92
- * package by `os` and `cpu`, or none — so the launcher never repeats that
93
- * judgement and never disagrees with it.
94
- */
95
- const run = (options) => {
96
- let executable$1;
97
- try {
98
- executable$1 = options.resolve(executable(options.environment));
99
- } catch (error) {
100
- if (hasCode(error, "MODULE_NOT_FOUND")) return {
101
- _tag: "Blocked",
102
- message: unavailable(options.environment)
103
- };
104
- throw error;
105
- }
106
- const completion = options.spawn(executable$1, options.args);
107
- if (completion.error !== void 0) {
108
- if (options.environment.libc === "musl" && hasCode(completion.error, "ENOENT")) return {
109
- _tag: "Blocked",
110
- message: unavailable(options.environment)
111
- };
112
- throw completion.error;
113
- }
114
- return {
115
- _tag: "Exited",
116
- code: exitCode(completion)
117
- };
118
- };
119
- //#endregion
120
- //#region src/index.ts
121
- /**
122
- * The published bin, and the only entry point: a trampoline to the executable
123
- * for this machine.
124
- *
125
- * The app itself is compiled, with its runtime inside it, and lives in one of
126
- * six platform packages. Nothing here loads it, and nothing here needs a
127
- * capable runtime — this file runs on whatever `npx` or `bunx` starts it with,
128
- * hands the terminal to a child, and reports how that child ended.
129
- */
130
- /**
131
- * Reports a launch failure: one message on stderr, nothing on stdout, and a
132
- * non-zero exit.
133
- *
134
- * The code is set rather than forced. `process.exit` can truncate a pending
135
- * write when stderr is a pipe, which is exactly how the message reaches a user
136
- * who redirected it; setting the code lets Node flush and leave on its own.
137
- */
138
- const fail = (message) => {
139
- process.stderr.write(`${message}\n`);
140
- process.exitCode = 1;
141
- };
142
- /**
143
- * Which C library this machine links against.
144
- *
145
- * A glibc runtime version in the diagnostic report is what separates the two:
146
- * musl leaves the field absent. The question is only asked on Linux, and a
147
- * runtime that reports nothing leaves it unanswered rather than guessed —
148
- * `undefined` costs the user a less specific message, a wrong answer costs them
149
- * a wrong one.
150
- */
151
- const libc = () => {
152
- if (process.platform !== "linux" || typeof process.report?.getReport !== "function") return;
153
- return process.report.getReport().header?.glibcVersionRuntime === void 0 ? "musl" : "glibc";
154
- };
155
- process.on("SIGINT", () => {});
156
- const require = createRequire(import.meta.url);
157
- const result = run({
158
- args: process.argv.slice(2),
159
- environment: {
160
- arch: process.arch,
161
- libc: libc(),
162
- platform: process.platform
163
- },
164
- resolve: (specifier) => require.resolve(specifier),
165
- spawn: (command, args) => spawnSync(command, [...args], { stdio: "inherit" })
166
- });
167
- if (result._tag === "Blocked") fail(result.message);
168
- else process.exitCode = result.code;
169
- //#endregion
170
- export {};