@nipurn/xprompt-new 0.0.0-dev-202604112100

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/100xprompt ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+
3
+ import childProcess from "child_process"
4
+ import fs from "fs"
5
+ import path from "path"
6
+ import os from "os"
7
+ import { fileURLToPath } from "url"
8
+
9
+ const __filename = fileURLToPath(import.meta.url)
10
+
11
+ function run(target) {
12
+ const result = childProcess.spawnSync(target, process.argv.slice(2), {
13
+ stdio: "inherit",
14
+ })
15
+ if (result.error) {
16
+ console.error(result.error.message)
17
+ process.exit(1)
18
+ }
19
+ const code = typeof result.status === "number" ? result.status : 0
20
+ process.exit(code)
21
+ }
22
+
23
+ const envPath = process.env.HUNDREDXPROMPT_BIN_PATH
24
+ if (envPath) {
25
+ run(envPath)
26
+ }
27
+
28
+ const scriptPath = fs.realpathSync(__filename)
29
+ const scriptDir = path.dirname(scriptPath)
30
+
31
+ const platformMap = {
32
+ darwin: "darwin",
33
+ linux: "linux",
34
+ win32: "windows",
35
+ }
36
+ const archMap = {
37
+ x64: "x64",
38
+ arm64: "arm64",
39
+ arm: "arm",
40
+ }
41
+
42
+ let platform = platformMap[os.platform()]
43
+ if (!platform) {
44
+ platform = os.platform()
45
+ }
46
+ let arch = archMap[os.arch()]
47
+ if (!arch) {
48
+ arch = os.arch()
49
+ }
50
+ const base = "nipurn-xprompt-new-" + platform + "-" + arch
51
+ const binary = platform === "windows" ? "100xprompt.exe" : "100xprompt"
52
+
53
+ function findBinary(startDir) {
54
+ let current = startDir
55
+ for (;;) {
56
+ const modules = path.join(current, "node_modules")
57
+ if (fs.existsSync(modules)) {
58
+ const entries = fs.readdirSync(modules)
59
+ for (const entry of entries) {
60
+ if (!entry.startsWith(base)) {
61
+ continue
62
+ }
63
+ const candidate = path.join(modules, entry, "bin", binary)
64
+ if (fs.existsSync(candidate)) {
65
+ return candidate
66
+ }
67
+ }
68
+ }
69
+ const parent = path.dirname(current)
70
+ if (parent === current) {
71
+ return
72
+ }
73
+ current = parent
74
+ }
75
+ }
76
+
77
+ const resolved = findBinary(scriptDir)
78
+ if (!resolved) {
79
+ console.error(
80
+ 'It seems that your package manager failed to install the right version of the 100xprompt CLI for your platform. You can try manually installing the "' +
81
+ base +
82
+ '" package',
83
+ )
84
+ process.exit(1)
85
+ }
86
+
87
+ run(resolved)
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@nipurn/xprompt-new",
3
+ "bin": {
4
+ "100xprompt": "./bin/100xprompt"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "0.0.0-dev-202604112100",
10
+ "optionalDependencies": {
11
+ "nipurn-xprompt-new-linux-arm64": "0.0.0-dev-202604112100",
12
+ "nipurn-xprompt-new-linux-x64": "0.0.0-dev-202604112100",
13
+ "nipurn-xprompt-new-linux-x64-baseline": "0.0.0-dev-202604112100",
14
+ "nipurn-xprompt-new-linux-arm64-musl": "0.0.0-dev-202604112100",
15
+ "nipurn-xprompt-new-linux-x64-musl": "0.0.0-dev-202604112100",
16
+ "nipurn-xprompt-new-linux-x64-baseline-musl": "0.0.0-dev-202604112100",
17
+ "nipurn-xprompt-new-darwin-arm64": "0.0.0-dev-202604112100",
18
+ "nipurn-xprompt-new-darwin-x64": "0.0.0-dev-202604112100",
19
+ "nipurn-xprompt-new-darwin-x64-baseline": "0.0.0-dev-202604112100",
20
+ "nipurn-xprompt-new-windows-x64": "0.0.0-dev-202604112100",
21
+ "nipurn-xprompt-new-windows-x64-baseline": "0.0.0-dev-202604112100"
22
+ }
23
+ }
@@ -0,0 +1,236 @@
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 = `nipurn-xprompt-new-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "100xprompt.exe" : "100xprompt"
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(`100xprompt 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
+ function createConfig() {
101
+ const home = os.homedir()
102
+ // Primary: XDG config path (what the app reads via xdg-basedir)
103
+ const xdgConfigHome = process.env.XDG_CONFIG_HOME || path.join(home, ".config")
104
+ const configDir = path.join(xdgConfigHome, "100xprompt")
105
+ const configPath = path.join(configDir, "100xprompt.json")
106
+ // Legacy fallback: also check ~/.100xprompt
107
+ const legacyConfigDir = path.join(home, ".100xprompt")
108
+ const legacyConfigPath = path.join(legacyConfigDir, "100xprompt.json")
109
+
110
+ const defaultConfig = {
111
+ $schema: "https://opencode.ai/config.json",
112
+ compaction: {
113
+ auto: {
114
+ enabled: true,
115
+ // Note: The code automatically overrides this to 160k for Flash models
116
+ compactionThreshold: 80000,
117
+ tailPreserveTurns: 5,
118
+ },
119
+ micro: {
120
+ enabled: true,
121
+ hotTailCount: 5,
122
+ },
123
+ },
124
+ }
125
+
126
+ try {
127
+ // Determine which config path to use:
128
+ // If legacy path exists but XDG path doesn't, use legacy for validation/merge
129
+ // Otherwise prefer XDG path (the app reads from both)
130
+ let activeConfigDir = configDir
131
+ let activeConfigPath = configPath
132
+ if (fs.existsSync(legacyConfigPath) && !fs.existsSync(configPath)) {
133
+ activeConfigDir = legacyConfigDir
134
+ activeConfigPath = legacyConfigPath
135
+ }
136
+
137
+ if (!fs.existsSync(activeConfigDir)) {
138
+ fs.mkdirSync(activeConfigDir, { recursive: true })
139
+ }
140
+
141
+ if (fs.existsSync(activeConfigPath)) {
142
+ // Validate existing config and merge missing defaults
143
+ try {
144
+ const raw = fs.readFileSync(activeConfigPath, "utf-8")
145
+ const existing = JSON.parse(raw)
146
+
147
+ let needsUpdate = false
148
+
149
+ // Ensure compaction section exists with all required fields
150
+ if (!existing.compaction) {
151
+ existing.compaction = defaultConfig.compaction
152
+ needsUpdate = true
153
+ } else {
154
+ if (!existing.compaction.auto) {
155
+ existing.compaction.auto = defaultConfig.compaction.auto
156
+ needsUpdate = true
157
+ } else {
158
+ // Merge individual auto fields if missing
159
+ for (const [key, value] of Object.entries(defaultConfig.compaction.auto)) {
160
+ if (existing.compaction.auto[key] === undefined) {
161
+ existing.compaction.auto[key] = value
162
+ needsUpdate = true
163
+ }
164
+ }
165
+ }
166
+ if (!existing.compaction.micro) {
167
+ existing.compaction.micro = defaultConfig.compaction.micro
168
+ needsUpdate = true
169
+ }
170
+ }
171
+
172
+ if (!existing.$schema) {
173
+ existing.$schema = defaultConfig.$schema
174
+ needsUpdate = true
175
+ }
176
+
177
+ if (needsUpdate) {
178
+ fs.writeFileSync(activeConfigPath, JSON.stringify(existing, null, 2))
179
+ try {
180
+ fs.chmodSync(activeConfigPath, 0o644)
181
+ } catch {}
182
+ console.log(`Config updated with missing defaults at ${activeConfigPath}`)
183
+ } else {
184
+ console.log(`Config already exists and is valid at ${activeConfigPath}, skipping.`)
185
+ }
186
+ } catch (parseError) {
187
+ // Existing file is corrupt — back it up and recreate
188
+ const backupPath = activeConfigPath + ".bak"
189
+ console.warn(`Config at ${activeConfigPath} is corrupt, backing up to ${backupPath} and recreating.`)
190
+ try {
191
+ fs.copyFileSync(activeConfigPath, backupPath)
192
+ } catch {}
193
+ fs.writeFileSync(activeConfigPath, JSON.stringify(defaultConfig, null, 2))
194
+ try {
195
+ fs.chmodSync(activeConfigPath, 0o644)
196
+ } catch {}
197
+ console.log(`Default config recreated at ${activeConfigPath}`)
198
+ }
199
+ return
200
+ }
201
+
202
+ fs.writeFileSync(activeConfigPath, JSON.stringify(defaultConfig, null, 2))
203
+ try {
204
+ fs.chmodSync(activeConfigPath, 0o644)
205
+ } catch {}
206
+ console.log(`Default config created at ${activeConfigPath}`)
207
+ } catch (error) {
208
+ console.warn(`Failed to create default config: ${error.message}`)
209
+ // Don't fail postinstall just because config creation failed
210
+ }
211
+ }
212
+
213
+ async function main() {
214
+ try {
215
+ if (os.platform() === "win32") {
216
+ // On Windows, the .exe is already included in the package and bin field points to it
217
+ // No postinstall setup needed
218
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
219
+ return
220
+ }
221
+
222
+ const { binaryPath, binaryName } = findBinary()
223
+ symlinkBinary(binaryPath, binaryName)
224
+ createConfig()
225
+ } catch (error) {
226
+ console.error("Failed to setup 100xprompt binary:", error.message)
227
+ process.exit(1)
228
+ }
229
+ }
230
+
231
+ try {
232
+ main()
233
+ } catch (error) {
234
+ console.error("Postinstall script error:", error.message)
235
+ process.exit(0)
236
+ }