finny 1.0.6 → 1.0.7

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/bin/opencode ADDED
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require("child_process")
4
+ const fs = require("fs")
5
+ const path = require("path")
6
+ const os = require("os")
7
+
8
+ function run(target) {
9
+ const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
+ stdio: "inherit",
11
+ })
12
+ if (result.error) {
13
+ console.error(result.error.message)
14
+ process.exit(1)
15
+ }
16
+ const code = typeof result.status === "number" ? result.status : 0
17
+ process.exit(code)
18
+ }
19
+
20
+ const envPath = process.env.OPENCODE_BIN_PATH
21
+ if (envPath) {
22
+ run(envPath)
23
+ }
24
+
25
+ const scriptPath = fs.realpathSync(__filename)
26
+ const scriptDir = path.dirname(scriptPath)
27
+
28
+ //
29
+ const cached = path.join(scriptDir, ".opencode")
30
+ if (fs.existsSync(cached)) {
31
+ run(cached)
32
+ }
33
+
34
+ const platformMap = {
35
+ darwin: "darwin",
36
+ linux: "linux",
37
+ win32: "windows",
38
+ }
39
+ const archMap = {
40
+ x64: "x64",
41
+ arm64: "arm64",
42
+ arm: "arm",
43
+ }
44
+
45
+ let platform = platformMap[os.platform()]
46
+ if (!platform) {
47
+ platform = os.platform()
48
+ }
49
+ let arch = archMap[os.arch()]
50
+ if (!arch) {
51
+ arch = os.arch()
52
+ }
53
+ const base = "finny-" + platform + "-" + arch
54
+ const binary = platform === "windows" ? "opencode.exe" : "opencode"
55
+
56
+ function supportsAvx2() {
57
+ if (arch !== "x64") return false
58
+
59
+ if (platform === "linux") {
60
+ try {
61
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
62
+ } catch {
63
+ return false
64
+ }
65
+ }
66
+
67
+ if (platform === "darwin") {
68
+ try {
69
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
70
+ encoding: "utf8",
71
+ timeout: 1500,
72
+ })
73
+ if (result.status !== 0) return false
74
+ return (result.stdout || "").trim() === "1"
75
+ } catch {
76
+ return false
77
+ }
78
+ }
79
+
80
+ if (platform === "windows") {
81
+ const cmd =
82
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
83
+
84
+ for (const exe of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
85
+ try {
86
+ const result = childProcess.spawnSync(exe, ["-NoProfile", "-NonInteractive", "-Command", cmd], {
87
+ encoding: "utf8",
88
+ timeout: 3000,
89
+ windowsHide: true,
90
+ })
91
+ if (result.status !== 0) continue
92
+ const out = (result.stdout || "").trim().toLowerCase()
93
+ if (out === "true" || out === "1") return true
94
+ if (out === "false" || out === "0") return false
95
+ } catch {
96
+ continue
97
+ }
98
+ }
99
+
100
+ return false
101
+ }
102
+
103
+ return false
104
+ }
105
+
106
+ const names = (() => {
107
+ const avx2 = supportsAvx2()
108
+ const baseline = arch === "x64" && !avx2
109
+
110
+ if (platform === "linux") {
111
+ const musl = (() => {
112
+ try {
113
+ if (fs.existsSync("/etc/alpine-release")) return true
114
+ } catch {
115
+ // ignore
116
+ }
117
+
118
+ try {
119
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
120
+ const text = ((result.stdout || "") + (result.stderr || "")).toLowerCase()
121
+ if (text.includes("musl")) return true
122
+ } catch {
123
+ // ignore
124
+ }
125
+
126
+ return false
127
+ })()
128
+
129
+ if (musl) {
130
+ if (arch === "x64") {
131
+ if (baseline) return [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
132
+ return [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
133
+ }
134
+ return [`${base}-musl`, base]
135
+ }
136
+
137
+ if (arch === "x64") {
138
+ if (baseline) return [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
139
+ return [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
140
+ }
141
+ return [base, `${base}-musl`]
142
+ }
143
+
144
+ if (arch === "x64") {
145
+ if (baseline) return [`${base}-baseline`, base]
146
+ return [base, `${base}-baseline`]
147
+ }
148
+ return [base]
149
+ })()
150
+
151
+ function findBinary(startDir) {
152
+ let current = startDir
153
+ for (;;) {
154
+ const modules = path.join(current, "node_modules")
155
+ if (fs.existsSync(modules)) {
156
+ for (const name of names) {
157
+ const candidate = path.join(modules, name, "bin", binary)
158
+ if (fs.existsSync(candidate)) return candidate
159
+ }
160
+ }
161
+ const parent = path.dirname(current)
162
+ if (parent === current) {
163
+ return
164
+ }
165
+ current = parent
166
+ }
167
+ }
168
+
169
+ const resolved = findBinary(scriptDir)
170
+ if (!resolved) {
171
+ console.error(
172
+ "It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing " +
173
+ names.map((n) => `\"${n}\"`).join(" or ") +
174
+ " package",
175
+ )
176
+ process.exit(1)
177
+ }
178
+
179
+ run(resolved)
package/package.json CHANGED
@@ -1,39 +1,25 @@
1
1
  {
2
2
  "name": "finny",
3
- "version": "1.0.6",
4
- "description": "AI-powered quantitative trading CLI with TUI interface",
5
- "keywords": [
6
- "trading",
7
- "quant",
8
- "cli",
9
- "tui",
10
- "ai",
11
- "algorithmic-trading"
12
- ],
13
- "author": "Finny",
14
- "license": "MIT",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/Jaiminp007/finny.git"
18
- },
19
- "homepage": "https://github.com/Jaiminp007/finny",
20
- "bugs": {
21
- "url": "https://github.com/Jaiminp007/finny/issues"
22
- },
23
3
  "bin": {
24
- "finny": "bin/finny"
4
+ "finny": "./bin/opencode"
25
5
  },
26
6
  "scripts": {
27
- "postinstall": "node scripts/postinstall.js"
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
28
8
  },
9
+ "version": "1.0.7",
10
+ "license": "MIT",
29
11
  "optionalDependencies": {
30
- "finny-darwin-arm64": "1.0.6",
31
- "finny-darwin-x64": "1.0.6",
32
- "finny-linux-arm64": "1.0.6",
33
- "finny-linux-x64": "1.0.6",
34
- "finny-windows-x64": "1.0.6"
35
- },
36
- "engines": {
37
- "node": ">=18"
12
+ "finny-darwin-arm64": "1.0.7",
13
+ "finny-darwin-x64": "1.0.7",
14
+ "finny-darwin-x64-baseline": "1.0.7",
15
+ "finny-linux-arm64": "1.0.7",
16
+ "finny-linux-arm64-musl": "1.0.7",
17
+ "finny-linux-x64": "1.0.7",
18
+ "finny-linux-x64-baseline": "1.0.7",
19
+ "finny-linux-x64-baseline-musl": "1.0.7",
20
+ "finny-linux-x64-musl": "1.0.7",
21
+ "finny-windows-arm64": "1.0.7",
22
+ "finny-windows-x64": "1.0.7",
23
+ "finny-windows-x64-baseline": "1.0.7"
38
24
  }
39
- }
25
+ }
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+
12
+ function detectPlatformAndArch() {
13
+ // Map platform names
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ // Map architecture names
31
+ let arch
32
+ switch (os.arch()) {
33
+ case "x64":
34
+ arch = "x64"
35
+ break
36
+ case "arm64":
37
+ arch = "arm64"
38
+ break
39
+ case "arm":
40
+ arch = "arm"
41
+ break
42
+ default:
43
+ arch = os.arch()
44
+ break
45
+ }
46
+
47
+ return { platform, arch }
48
+ }
49
+
50
+ function findBinary() {
51
+ const { platform, arch } = detectPlatformAndArch()
52
+ const packageName = `finny-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
54
+
55
+ try {
56
+ // Use require.resolve to find the package
57
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
+ const packageDir = path.dirname(packageJsonPath)
59
+ const binaryPath = path.join(packageDir, "bin", binaryName)
60
+
61
+ if (!fs.existsSync(binaryPath)) {
62
+ throw new Error(`Binary not found at ${binaryPath}`)
63
+ }
64
+
65
+ return { binaryPath, binaryName }
66
+ } catch (error) {
67
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
68
+ }
69
+ }
70
+
71
+ function prepareBinDirectory(binaryName) {
72
+ const binDir = path.join(__dirname, "bin")
73
+ const targetPath = path.join(binDir, binaryName)
74
+
75
+ // Ensure bin directory exists
76
+ if (!fs.existsSync(binDir)) {
77
+ fs.mkdirSync(binDir, { recursive: true })
78
+ }
79
+
80
+ // Remove existing binary/symlink if it exists
81
+ if (fs.existsSync(targetPath)) {
82
+ fs.unlinkSync(targetPath)
83
+ }
84
+
85
+ return { binDir, targetPath }
86
+ }
87
+
88
+ function symlinkBinary(sourcePath, binaryName) {
89
+ const { targetPath } = prepareBinDirectory(binaryName)
90
+
91
+ fs.symlinkSync(sourcePath, targetPath)
92
+ console.log(`opencode binary symlinked: ${targetPath} -> ${sourcePath}`)
93
+
94
+ // Verify the file exists after operation
95
+ if (!fs.existsSync(targetPath)) {
96
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
97
+ }
98
+ }
99
+
100
+ async function main() {
101
+ try {
102
+ if (os.platform() === "win32") {
103
+ // On Windows, the .exe is already included in the package and bin field points to it
104
+ // No postinstall setup needed
105
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
+ return
107
+ }
108
+
109
+ // On non-Windows platforms, just verify the binary package exists
110
+ // Don't replace the wrapper script - it handles binary execution
111
+ const { binaryPath } = findBinary()
112
+ const target = path.join(__dirname, "bin", ".opencode")
113
+ if (fs.existsSync(target)) fs.unlinkSync(target)
114
+ try {
115
+ fs.linkSync(binaryPath, target)
116
+ } catch {
117
+ fs.copyFileSync(binaryPath, target)
118
+ }
119
+ fs.chmodSync(target, 0o755)
120
+ } catch (error) {
121
+ console.error("Failed to setup opencode binary:", error.message)
122
+ process.exit(1)
123
+ }
124
+ }
125
+
126
+ try {
127
+ main()
128
+ } catch (error) {
129
+ console.error("Postinstall script error:", error.message)
130
+ process.exit(0)
131
+ }
package/bin/finny DELETED
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { execFileSync } = require("child_process");
4
- const path = require("path");
5
- const fs = require("fs");
6
-
7
- const PLATFORMS = {
8
- "darwin-arm64": "finny-darwin-arm64",
9
- "darwin-x64": "finny-darwin-x64",
10
- "linux-arm64": "finny-linux-arm64",
11
- "linux-x64": "finny-linux-x64",
12
- "win32-x64": "finny-windows-x64",
13
- };
14
-
15
- function getBinaryPath() {
16
- const platform = `${process.platform}-${process.arch}`;
17
- const packageName = PLATFORMS[platform];
18
-
19
- if (!packageName) {
20
- console.error(`Unsupported platform: ${platform}`);
21
- console.error(`Supported platforms: ${Object.keys(PLATFORMS).join(", ")}`);
22
- process.exit(1);
23
- }
24
-
25
- // Try to find the binary in node_modules
26
- const possiblePaths = [
27
- // Installed as dependency
28
- path.join(__dirname, "..", "node_modules", packageName, "bin", "finny"),
29
- // Installed globally or via npx
30
- path.join(__dirname, "..", "..", packageName, "bin", "finny"),
31
- // Direct sibling (monorepo)
32
- path.join(__dirname, "..", "..", "..", packageName, "bin", "finny"),
33
- ];
34
-
35
- // Add .exe for Windows
36
- if (process.platform === "win32") {
37
- possiblePaths.push(...possiblePaths.map(p => p + ".exe"));
38
- }
39
-
40
- for (const binaryPath of possiblePaths) {
41
- if (fs.existsSync(binaryPath)) {
42
- // Ensure binary has execute permissions (npm may strip them)
43
- try {
44
- fs.chmodSync(binaryPath, 0o755);
45
- } catch (_) {}
46
- return binaryPath;
47
- }
48
- }
49
-
50
- console.error(`Could not find finny binary for platform: ${platform}`);
51
- console.error(`Expected package: ${packageName}`);
52
- console.error(`Searched paths:`);
53
- possiblePaths.forEach(p => console.error(` - ${p}`));
54
- console.error(`\nTry reinstalling: npm install -g finny`);
55
- process.exit(1);
56
- }
57
-
58
- try {
59
- const binaryPath = getBinaryPath();
60
- const args = process.argv.slice(2);
61
-
62
- execFileSync(binaryPath, args, {
63
- stdio: "inherit",
64
- env: process.env,
65
- });
66
- } catch (error) {
67
- if (error.status !== undefined) {
68
- process.exit(error.status);
69
- }
70
- console.error(error.message);
71
- process.exit(1);
72
- }
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
-
6
- const PLATFORMS = {
7
- "darwin-arm64": "finny-darwin-arm64",
8
- "darwin-x64": "finny-darwin-x64",
9
- "linux-arm64": "finny-linux-arm64",
10
- "linux-x64": "finny-linux-x64",
11
- "win32-x64": "finny-windows-x64",
12
- };
13
-
14
- const platform = `${process.platform}-${process.arch}`;
15
- const packageName = PLATFORMS[platform];
16
-
17
- if (!packageName) {
18
- console.warn(`\n[finny] Warning: Unsupported platform ${platform}`);
19
- console.warn(`[finny] Supported: ${Object.keys(PLATFORMS).join(", ")}`);
20
- console.warn(`[finny] The CLI may not work on this platform.\n`);
21
- process.exit(0);
22
- }
23
-
24
- // Check if the platform package was installed
25
- const possiblePaths = [
26
- path.join(__dirname, "..", "node_modules", packageName),
27
- path.join(__dirname, "..", "..", packageName),
28
- path.join(__dirname, "..", "..", "..", packageName),
29
- ];
30
-
31
- const installed = possiblePaths.some(p => fs.existsSync(p));
32
-
33
- if (!installed) {
34
- console.warn(`\n[finny] Warning: Platform package ${packageName} not found`);
35
- console.warn(`[finny] This might happen if optional dependencies are disabled`);
36
- console.warn(`[finny] Try: npm install ${packageName}\n`);
37
- } else {
38
- // Make binary executable (fix for npm not preserving permissions)
39
- for (const basePath of possiblePaths) {
40
- const binaryPath = path.join(basePath, "bin", "finny");
41
- const binaryPathExe = path.join(basePath, "bin", "finny.exe");
42
-
43
- try {
44
- if (fs.existsSync(binaryPath)) {
45
- fs.chmodSync(binaryPath, 0o755);
46
- }
47
- if (fs.existsSync(binaryPathExe)) {
48
- fs.chmodSync(binaryPathExe, 0o755);
49
- }
50
- } catch (e) {
51
- // Ignore permission errors on Windows
52
- }
53
- }
54
- }