cortexcode 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/bin/cortexcode.mjs +19 -5
  2. package/package.json +1 -1
@@ -162,12 +162,21 @@ function writeIfChanged(path, text, mode = 0o644) {
162
162
  return true;
163
163
  }
164
164
 
165
- /** The starter's script: the newest ready version in APPS, started as this launcher starts it. */
165
+ /**
166
+ * The starter's script: the newest ready version in APPS, started exactly as this launcher starts it
167
+ * (its binary run directly, detached, output to the start log). Not through `open`: that hands the
168
+ * bundle to LaunchServices, which starts it differently from a terminal. When the app already runs,
169
+ * it brings the app's window forward instead (macOS).
170
+ */
166
171
  function starterScript() {
167
- const start =
172
+ const exe = process.platform === 'darwin' ? '$apps/$version/CortexCode.app/Contents/MacOS/CortexCode' : '$apps/$version/cortexcode/CortexCode';
173
+ // The window belongs to the frame's Electron child: opening that running bundle activates it.
174
+ const forward =
168
175
  process.platform === 'darwin'
169
- ? 'exec open "$apps/$version/CortexCode.app" --stdout "$log" --stderr "$log" --args "$@"'
170
- : 'exec "$apps/$version/cortexcode/CortexCode" "$@" >>"$log" 2>&1';
176
+ ? ` shell="$(ps -axo ppid=,comm= | awk -v p="$pid" '$1 == p && /\\.app\\/Contents\\/MacOS\\// { sub(/^ *[0-9]+ +/, ""); sub(/\\/Contents\\/MacOS\\/.*/, ""); print; exit }')"
177
+ [ -n "$shell" ] && open "$shell"
178
+ `
179
+ : '';
171
180
  const missing =
172
181
  process.platform === 'darwin'
173
182
  ? `osascript -e 'display alert "CortexCode is not installed" message "Run npx cortexcode in a terminal to install it."' >/dev/null 2>&1`
@@ -176,6 +185,10 @@ function starterScript() {
176
185
  # CortexCode starter, written by npx cortexcode: starts the newest app installed in the folder below.
177
186
  apps=${shq(APPS)}
178
187
  log=${shq(START_LOG)}
188
+ pid="$(sed -n 's/.*"pid": *\\([0-9][0-9]*\\).*/\\1/p' ${shq(join(HOME, 'run', 'frame.json'))} 2>/dev/null)"
189
+ if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
190
+ ${forward} exit 0
191
+ fi
179
192
  mkdir -p "$(dirname "$log")"
180
193
  version="$(ls "$apps" 2>/dev/null | grep -E '^[0-9]+\\.[0-9]+\\.[0-9]+$' | sort -t. -k1,1n -k2,2n -k3,3n |
181
194
  while read -r v; do [ -e "$apps/$v/${READY}" ] && echo "$v"; done | tail -n 1)"
@@ -183,7 +196,8 @@ if [ -z "$version" ]; then
183
196
  ${missing}
184
197
  exit 1
185
198
  fi
186
- ${start}
199
+ # Detached, so the starter ends at once and opening it again finds the running app.
200
+ nohup "${exe}" "$@" >>"$log" 2>&1 </dev/null &
187
201
  `;
188
202
  }
189
203
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortexcode",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "CortexCode, a local coding agent: npx cortexcode downloads the app for this machine from the official releases and starts it.",
5
5
  "type": "module",
6
6
  "bin": {