lucentracode 0.2.0 → 0.2.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.
@@ -166,6 +166,33 @@ if (typeof resolved !== "string") {
166
166
  process.exit(1)
167
167
  }
168
168
 
169
+ // Make sure the binary is actually executable before trying to run it.
170
+ //
171
+ // It frequently is not. These packages are built and published from Windows, which has
172
+ // no POSIX permission bits, so npm records mode 0644 in the tar header and every macOS
173
+ // and Linux install extracts a binary it is not allowed to execute:
174
+ //
175
+ // spawnSync .../bin/lucentracode EACCES
176
+ //
177
+ // Fixing it at pack time would mean the release only ever being publishable from a
178
+ // POSIX machine -- a rule that holds until the day someone publishes from a laptop.
179
+ // Fixing it here makes the tar mode irrelevant, which is the property worth having.
180
+ function ensureExecutable(file) {
181
+ if (platform === "windows") return null
182
+ try {
183
+ const mode = fs.statSync(file).mode
184
+ if (mode & 0o111) return null
185
+ fs.chmodSync(file, (mode & 0o7777) | 0o755)
186
+ return null
187
+ } catch (err) {
188
+ // A read-only or root-owned install directory. Report it rather than failing with
189
+ // a bare EACCES, because the fix is one command and the user cannot guess it.
190
+ return err
191
+ }
192
+ }
193
+
194
+ const chmodError = ensureExecutable(resolved)
195
+
169
196
  // `stdio: "inherit"` hands the real terminal to the child, which the TUI requires: it
170
197
  // needs a genuine TTY for raw mode, resize events and colour. It also means the
171
198
  // terminal delivers Ctrl+C to the foreground process group, so the child sees the
@@ -173,7 +200,20 @@ if (typeof resolved !== "string") {
173
200
  const result = spawnSync(resolved, process.argv.slice(2), { stdio: "inherit", windowsHide: false })
174
201
 
175
202
  if (result.error) {
176
- process.stderr.write(`${PRODUCT}: could not start ${resolved}\n${result.error.message}\n`)
203
+ const lines = [`${PRODUCT}: could not start the binary.`, ` ${resolved}`, ``, `${result.error.message}`]
204
+ if (result.error.code === "EACCES") {
205
+ lines.push(
206
+ ``,
207
+ `The binary is not marked executable.` +
208
+ (chmodError ? ` Making it executable failed: ${chmodError.message}` : ``),
209
+ ``,
210
+ `Fix it with:`,
211
+ ` chmod +x ${resolved}`,
212
+ ``,
213
+ `If that is denied, reinstall somewhere you own, or use sudo for the chmod.`,
214
+ )
215
+ }
216
+ process.stderr.write(lines.join("\n") + "\n")
177
217
  process.exit(1)
178
218
  }
179
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucentracode",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "AI coding agent for the terminal, powered by the LucentraCode gateway.",
5
5
  "license": "MIT",
6
6
  "repository": {