@binary-balance/seshat 0.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gaelian Ditchburn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Seshat
2
+
3
+ This package installs the Seshat command and selects the native payload for
4
+ the current Node platform. The native payload packages are optional so npm can
5
+ skip the four platforms that do not match the consumer.
6
+
7
+ Seshat needs Node 24.20.0. Run `seshat check`, `seshat crap`, or `seshat mutate`
8
+ with a project `seshat.json`. Add `--json` for the versioned report.
package/bin/seshat.mjs ADDED
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {spawn} from 'node:child_process';
4
+ import {createRequire} from 'node:module';
5
+ import {existsSync, readFileSync, statSync} from 'node:fs';
6
+ import {basename, dirname, join} from 'node:path';
7
+ import {fileURLToPath} from 'node:url';
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
11
+ const packageManifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'));
12
+ const version = packageManifest.version;
13
+ const args = process.argv.slice(2);
14
+ const jsonRequested = args.includes('--json');
15
+ const commands = new Set(['check', 'crap', 'mutate']);
16
+ const started = performance.now();
17
+
18
+ const targets = {
19
+ 'linux-x64': {name: '@binary-balance/seshat-linux-x64', executable: 'seshat'},
20
+ 'linux-arm64': {name: '@binary-balance/seshat-linux-arm64', executable: 'seshat'},
21
+ 'darwin-x64': {name: '@binary-balance/seshat-darwin-x64', executable: 'seshat'},
22
+ 'darwin-arm64': {name: '@binary-balance/seshat-darwin-arm64', executable: 'seshat'},
23
+ 'win32-x64': {name: '@binary-balance/seshat-win32-x64', executable: 'seshat.exe'},
24
+ };
25
+
26
+ function report(error) {
27
+ return {
28
+ schemaVersion: 1,
29
+ toolVersion: version,
30
+ command: commands.has(args[0]) ? args[0] : null,
31
+ complete: false,
32
+ cancelled: false,
33
+ signal: null,
34
+ scope: null,
35
+ timings: {wallMs: performance.now() - started, captureMs: null, executionMs: null},
36
+ quality: null,
37
+ result: {complete: false, error},
38
+ };
39
+ }
40
+
41
+ function fail(error) {
42
+ if (jsonRequested) {
43
+ process.stdout.write(`${JSON.stringify(report(error))}\n`);
44
+ } else {
45
+ process.stderr.write(`seshat: ${error}\n`);
46
+ }
47
+ process.exitCode = 2;
48
+ }
49
+
50
+ function targetForHost() {
51
+ const key = `${process.platform}-${process.arch}`;
52
+ const target = targets[key];
53
+ if (!target) return {error: `unsupported platform ${process.platform}/${process.arch}`};
54
+ if (process.platform === 'linux') {
55
+ let glibc;
56
+ try {
57
+ glibc = process.report?.getReport?.().header?.glibcVersionRuntime;
58
+ } catch {
59
+ glibc = undefined;
60
+ }
61
+ if (!glibc) return {error: `unsupported platform ${key}: glibc is required`};
62
+ }
63
+ return {target, key};
64
+ }
65
+
66
+ function payloadExecutable(target) {
67
+ let manifestPath;
68
+ try {
69
+ manifestPath = require.resolve(`${target.name}/package.json`);
70
+ } catch (error) {
71
+ if (error?.code === 'MODULE_NOT_FOUND') {
72
+ throw new Error(`${target.name}@${version} is missing or was omitted for this platform`);
73
+ }
74
+ throw error;
75
+ }
76
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
77
+ if (manifest.name !== target.name) {
78
+ throw new Error(`native payload name mismatch: expected ${target.name}, found ${manifest.name ?? 'unknown'}`);
79
+ }
80
+ if (manifest.version !== version) {
81
+ throw new Error(`native payload version mismatch: expected ${version}, found ${manifest.version ?? 'unknown'}`);
82
+ }
83
+ const executable = join(dirname(manifestPath), 'bin', target.executable);
84
+ if (!existsSync(executable) || !statSync(executable).isFile()) {
85
+ throw new Error(`${target.name}@${version} has no ${basename(executable)} executable`);
86
+ }
87
+ return executable;
88
+ }
89
+
90
+ function signalNumber(signal) {
91
+ return {SIGINT: 2, SIGTERM: 15}[signal] ?? 1;
92
+ }
93
+
94
+ const host = targetForHost();
95
+ if (host.error) {
96
+ fail(host.error);
97
+ } else {
98
+ let executable;
99
+ try {
100
+ executable = payloadExecutable(host.target);
101
+ } catch (error) {
102
+ fail(error instanceof Error ? error.message : String(error));
103
+ }
104
+ if (executable) {
105
+ const child = spawn(executable, args, {
106
+ cwd: process.cwd(),
107
+ env: {...process.env},
108
+ shell: false,
109
+ windowsHide: false,
110
+ stdio: 'inherit',
111
+ });
112
+ let spawnFailed = false;
113
+ const forward = signal => {
114
+ if (child.exitCode === null) child.kill(signal);
115
+ };
116
+ // A CTRL_BREAK_EVENT is broadcast to the console process group. Keep the
117
+ // launcher alive on Windows so the native child can handle that event and
118
+ // return its cancellation report through inherited stdio.
119
+ const preserveConsole = () => {};
120
+ process.on('SIGINT', forward);
121
+ process.on('SIGTERM', forward);
122
+ if (process.platform === 'win32') process.on('SIGBREAK', preserveConsole);
123
+ const cleanup = () => {
124
+ process.removeListener('SIGINT', forward);
125
+ process.removeListener('SIGTERM', forward);
126
+ if (process.platform === 'win32') process.removeListener('SIGBREAK', preserveConsole);
127
+ };
128
+ child.once('error', error => {
129
+ spawnFailed = true;
130
+ cleanup();
131
+ fail(`cannot start native payload: ${error.message}`);
132
+ });
133
+ child.once('close', (code, signal) => {
134
+ cleanup();
135
+ if (!spawnFailed) process.exitCode = signal ? 128 + signalNumber(signal) : code ?? 1;
136
+ });
137
+ }
138
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@binary-balance/seshat",
3
+ "version": "0.1.0-rc.1",
4
+ "description": "Native TypeScript code assurance",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": "24.20.0"
9
+ },
10
+ "bin": {
11
+ "seshat": "bin/seshat.mjs"
12
+ },
13
+ "files": [
14
+ "bin/seshat.mjs",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "optionalDependencies": {
19
+ "@binary-balance/seshat-linux-x64": "0.1.0-rc.1",
20
+ "@binary-balance/seshat-linux-arm64": "0.1.0-rc.1",
21
+ "@binary-balance/seshat-darwin-x64": "0.1.0-rc.1",
22
+ "@binary-balance/seshat-darwin-arm64": "0.1.0-rc.1",
23
+ "@binary-balance/seshat-win32-x64": "0.1.0-rc.1"
24
+ }
25
+ }