sphere-cli 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.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # SPHERE CLI
2
+
3
+ Command-line interface for **SPHERE** — synthetic data generation, evaluation, and certification. Designed for business workflows, data pipelines, and HPC environments.
4
+
5
+ > For the desktop application (individual users), see [SPHERE App](https://github.com/statzihuai/SPHERE).
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ **npm (recommended):**
12
+
13
+ ```sh
14
+ npm install -g sphere-cli
15
+ ```
16
+
17
+ No Python, no curl, no PATH editing. Requires Node.js ≥ 16.
18
+
19
+ **curl (no Node.js required):**
20
+
21
+ ```sh
22
+ curl -fsSL https://github.com/statzihuai/sphere-cli/releases/latest/download/install.sh | sh
23
+ ```
24
+
25
+ For HPC / cloud with no sudo:
26
+
27
+ ```sh
28
+ curl -fsSL https://github.com/statzihuai/sphere-cli/releases/latest/download/install.sh | sh -s -- --prefix ~/.local
29
+ # then add to ~/.bashrc or ~/.zshrc:
30
+ export PATH="$HOME/.local/bin:$PATH"
31
+ ```
32
+
33
+ **Uninstall:**
34
+
35
+ ```sh
36
+ sh install.sh --uninstall
37
+ ```
38
+
39
+ ### Supported platforms
40
+
41
+ | Platform | Architecture |
42
+ |---|---|
43
+ | macOS | Apple Silicon (arm64) |
44
+ | Linux | x86\_64 |
45
+ | Linux | arm64 (AWS Graviton, etc.) |
46
+
47
+ ---
48
+
49
+ ## Quick start
50
+
51
+ ```sh
52
+ # Generate synthetic data
53
+ sphere generate real.csv -o synth.csv
54
+
55
+ # Evaluate fidelity and privacy
56
+ sphere evaluate real.csv synth.csv
57
+
58
+ # Generate a certification report (HTML)
59
+ sphere certify real.csv synth.csv -o report.html
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Commands
65
+
66
+ ### `sphere generate`
67
+
68
+ ```
69
+ sphere generate <real.csv> [options]
70
+
71
+ Options:
72
+ -o, --output PATH Output CSV path (default: <input>_sphere.csv)
73
+ -n, --rows INT Number of synthetic rows (default: same as input)
74
+ -k INT SPHERE rotations (default: 2)
75
+ --seed INT Random seed for reproducibility
76
+ --mix-prob FLOAT Mixture probability 0–1 (default: 0.75)
77
+ --json Machine-readable JSON output
78
+ ```
79
+
80
+ A `.sphere.json` provenance file is written alongside every output CSV and is automatically read by `sphere certify`.
81
+
82
+ ### `sphere evaluate`
83
+
84
+ ```
85
+ sphere evaluate <real.csv> <synth.csv> [options]
86
+
87
+ Options:
88
+ --skip-privacy Skip privacy metrics (faster)
89
+ --json Machine-readable JSON output
90
+ ```
91
+
92
+ ### `sphere certify`
93
+
94
+ ```
95
+ sphere certify <real.csv> <synth.csv> [options]
96
+
97
+ Options:
98
+ -o, --output PATH Output HTML report path (default: cert.html)
99
+ --json Machine-readable JSON output
100
+ ```
101
+
102
+ Generation parameters (`k`, `seed`, `theta`, etc.) are loaded automatically from the `.sphere.json` sidecar. Pass flags explicitly to override.
103
+
104
+ ---
105
+
106
+ ## Machine-readable output
107
+
108
+ Every command supports `--json` for pipeline integration:
109
+
110
+ ```sh
111
+ sphere generate real.csv -o synth.csv --json | jq .fidelity
112
+ sphere evaluate real.csv synth.csv --json > metrics.json
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Environment variables
118
+
119
+ | Variable | Description |
120
+ |---|---|
121
+ | `SPHERE_PREFIX` | Override install prefix |
122
+ | `SPHERE_VERSION` | Pin a release tag, e.g. `v0.1.0` |
123
+ | `SPHERE_BUNDLE_URL` | Full URL to a `sphere-cli-*.tar.gz` (skip auto-detect) |
124
+ | `SPHERE_GITHUB_REPO` | Override GitHub repo for downloads |
125
+
126
+ ---
127
+
128
+ ## License
129
+
130
+ Proprietary — see [LICENSE](LICENSE).
package/bin/sphere.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { spawnSync } = require('child_process');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+
8
+ const binaryPath = path.join(__dirname, '..', 'native', 'sphere-cli', 'sphere');
9
+
10
+ if (!fs.existsSync(binaryPath)) {
11
+ console.error(
12
+ 'SPHERE CLI binary not found.\n' +
13
+ 'This usually means the postinstall step failed or was skipped.\n' +
14
+ 'Try reinstalling: npm install -g sphere-cli'
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
20
+ stdio: 'inherit',
21
+ env: process.env,
22
+ });
23
+
24
+ process.exit(result.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "sphere-cli",
3
+ "version": "0.1.2",
4
+ "description": "SPHERE CLI — synthetic data generation, evaluation, and certification",
5
+ "keywords": ["synthetic-data", "privacy", "cli", "data-science"],
6
+ "homepage": "https://github.com/statzihuai/sphere-cli",
7
+ "bugs": "https://github.com/statzihuai/sphere-cli/issues",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/statzihuai/sphere-cli.git"
11
+ },
12
+ "license": "SEE LICENSE IN LICENSE",
13
+ "bin": {
14
+ "sphere": "./bin/sphere.js"
15
+ },
16
+ "scripts": {
17
+ "postinstall": "node scripts/postinstall.js"
18
+ },
19
+ "files": [
20
+ "bin/",
21
+ "scripts/"
22
+ ],
23
+ "engines": {
24
+ "node": ">=16"
25
+ },
26
+ "os": ["darwin", "linux"],
27
+ "cpu": ["arm64", "x64"]
28
+ }
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Downloads the correct platform-specific SPHERE CLI binary from GitHub
5
+ * Releases and extracts it to native/ inside the npm package directory.
6
+ *
7
+ * Tarball structure (built by CI):
8
+ * sphere-cli/ ← PyInstaller onedir bundle
9
+ * sphere ← the executable
10
+ * _internal/ ← Python runtime + deps
11
+ * install.sh
12
+ *
13
+ * After extraction, bin/sphere.js invokes native/sphere-cli/sphere.
14
+ */
15
+
16
+ const https = require('https');
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+ const os = require('os');
20
+ const { execFileSync } = require('child_process');
21
+
22
+ const REPO = 'statzihuai/sphere-cli';
23
+ const VERSION = require('../package.json').version;
24
+ const PKG_DIR = path.join(__dirname, '..');
25
+
26
+ // ── Map Node.js platform/arch to our release tarball names ───────────────────
27
+ function getPlatformKey() {
28
+ const p = process.platform;
29
+ const a = process.arch;
30
+ if (p === 'darwin' && a === 'arm64') return 'macos-arm64';
31
+ if (p === 'linux' && a === 'x64') return 'linux-x86_64';
32
+ if (p === 'linux' && a === 'arm64') return 'linux-arm64';
33
+ throw new Error(
34
+ `Unsupported platform: ${p}-${a}\n` +
35
+ 'Supported: macOS arm64, Linux x86_64, Linux arm64.\n' +
36
+ 'Use the curl installer instead: https://github.com/statzihuai/sphere-cli#install'
37
+ );
38
+ }
39
+
40
+ // ── HTTPS GET with redirect following ────────────────────────────────────────
41
+ function download(url, destPath) {
42
+ return new Promise((resolve, reject) => {
43
+ function get(url, redirects) {
44
+ if (redirects > 5) { reject(new Error('Too many redirects')); return; }
45
+ https.get(url, { headers: { 'User-Agent': 'sphere-cli-npm-installer' } }, res => {
46
+ if (res.statusCode === 301 || res.statusCode === 302) {
47
+ get(res.headers.location, redirects + 1);
48
+ return;
49
+ }
50
+ if (res.statusCode !== 200) {
51
+ reject(new Error(`HTTP ${res.statusCode} downloading ${url}`));
52
+ res.resume();
53
+ return;
54
+ }
55
+ const out = fs.createWriteStream(destPath);
56
+ res.pipe(out);
57
+ out.on('finish', () => out.close(resolve));
58
+ out.on('error', reject);
59
+ res.on('error', reject);
60
+ }).on('error', reject);
61
+ }
62
+ get(url, 0);
63
+ });
64
+ }
65
+
66
+ // ── Main ─────────────────────────────────────────────────────────────────────
67
+ async function main() {
68
+ // Skip in CI environments where binaries are built fresh
69
+ if (process.env.SPHERE_SKIP_POSTINSTALL === '1') {
70
+ console.log('SPHERE_SKIP_POSTINSTALL=1 — skipping binary download.');
71
+ return;
72
+ }
73
+
74
+ const platform = getPlatformKey();
75
+ const tarball = `sphere-cli-${platform}.tar.gz`;
76
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${tarball}`;
77
+ const nativeDir = path.join(PKG_DIR, 'native');
78
+ const tmpTar = path.join(os.tmpdir(), `sphere-cli-install-${process.pid}.tar.gz`);
79
+
80
+ // Already installed (e.g. re-running postinstall manually)
81
+ const binaryPath = path.join(nativeDir, 'sphere-cli', 'sphere');
82
+ if (fs.existsSync(binaryPath)) {
83
+ console.log('✓ SPHERE CLI binary already present — skipping download.');
84
+ return;
85
+ }
86
+
87
+ console.log(`\nDownloading SPHERE CLI v${VERSION} for ${platform} …`);
88
+ console.log(` ${url}\n`);
89
+
90
+ try {
91
+ await download(url, tmpTar);
92
+ } catch (err) {
93
+ throw new Error(
94
+ `Failed to download SPHERE CLI binary: ${err.message}\n\n` +
95
+ 'Alternatives:\n' +
96
+ ` • curl installer: curl -fsSL https://github.com/${REPO}/releases/latest/download/install.sh | sh\n` +
97
+ ` • Manual download: ${url}`
98
+ );
99
+ }
100
+
101
+ fs.mkdirSync(nativeDir, { recursive: true });
102
+
103
+ try {
104
+ execFileSync('tar', ['-xzf', tmpTar, '-C', nativeDir]);
105
+ } finally {
106
+ try { fs.unlinkSync(tmpTar); } catch {}
107
+ }
108
+
109
+ // Ensure the binary is executable
110
+ fs.chmodSync(binaryPath, 0o755);
111
+
112
+ console.log('✓ SPHERE CLI installed.\n');
113
+ console.log(' Quick start:');
114
+ console.log(' sphere generate data.csv -o synth.csv');
115
+ console.log(' sphere evaluate real.csv synth.csv');
116
+ console.log(' sphere certify real.csv synth.csv -o report.html');
117
+ console.log('');
118
+ console.log(" Run 'sphere --help' for full options.\n");
119
+ }
120
+
121
+ main().catch(err => {
122
+ console.error('\n✗ SPHERE CLI postinstall failed:\n ' + err.message);
123
+ console.error('\nThe npm package was installed but the binary was not downloaded.');
124
+ console.error('Running `sphere` will show an error until you reinstall.\n');
125
+ // Exit 0 so npm install doesn't fail — user can fix later
126
+ process.exit(0);
127
+ });