@happy-nut/monacori 0.1.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happy-nut/monacori",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Validation control plane for AI-generated code changes.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -19,6 +19,7 @@
19
19
  "bin",
20
20
  "dist",
21
21
  "assets",
22
+ "scripts/patch-electron-name.mjs",
22
23
  "README.md",
23
24
  "LICENSE"
24
25
  ],
@@ -26,8 +27,9 @@
26
27
  "access": "public"
27
28
  },
28
29
  "scripts": {
29
- "build": "tsc -p tsconfig.json",
30
+ "build": "tsc -p tsconfig.json && node scripts/copy-viewer-assets.mjs",
30
31
  "icon": "node scripts/gen-icon.mjs",
32
+ "postinstall": "node scripts/patch-electron-name.mjs",
31
33
  "prepare": "npm run build",
32
34
  "smoke": "npm run build && node dist/cli.js --help"
33
35
  },
@@ -48,8 +50,12 @@
48
50
  "node": ">=20"
49
51
  },
50
52
  "dependencies": {
53
+ "@electron/rebuild": "^4.0.4",
54
+ "@xterm/addon-fit": "^0.11.0",
55
+ "@xterm/xterm": "^6.0.0",
51
56
  "diff2html": "^3.4.56",
52
57
  "electron": "^42.4.1",
53
- "highlight.js": "^11.11.1"
58
+ "highlight.js": "^11.11.1",
59
+ "node-pty": "^1.1.0"
54
60
  }
55
61
  }
@@ -0,0 +1,65 @@
1
+ import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { spawnSync } from "node:child_process";
3
+ import { createRequire } from "node:module";
4
+ import { dirname, join } from "node:path";
5
+
6
+ const APP_NAME = "monacori";
7
+
8
+ // Electron ships Electron.app with bundle name + executable "Electron", which is what macOS shows in
9
+ // the Dock / Cmd+Tab. The npm `mo` model spawns node_modules/electron's executable directly (not a
10
+ // packaged .app), and a directly-spawned GUI process takes its switcher/Dock name from the *executable*
11
+ // name — CFBundleName and app.setName() only affect the menu items, not the switcher. So we rename the
12
+ // executable to "monacori" (and repoint electron's path.txt) in addition to patching bundle metadata.
13
+ function electronRoot() {
14
+ if (process.platform !== "darwin") return null;
15
+ const require = createRequire(import.meta.url);
16
+ try {
17
+ return dirname(require.resolve("electron/package.json"));
18
+ } catch {
19
+ return null; // electron not installed
20
+ }
21
+ }
22
+
23
+ function main() {
24
+ const root = electronRoot();
25
+ if (!root) return; // not macOS, or electron missing — nothing to do
26
+ const appDir = join(root, "dist", "Electron.app");
27
+ const plistPath = join(appDir, "Contents", "Info.plist");
28
+ const macosDir = join(appDir, "Contents", "MacOS");
29
+ const oldExe = join(macosDir, "Electron");
30
+ const newExe = join(macosDir, APP_NAME);
31
+ const pathTxt = join(root, "path.txt");
32
+ if (!existsSync(plistPath)) return;
33
+
34
+ try {
35
+ // 1. Bundle metadata: name, display name, AND executable -> monacori.
36
+ const before = readFileSync(plistPath, "utf8");
37
+ const after = before
38
+ .replace(/(<key>CFBundleName<\/key>\s*<string>)[^<]*(<\/string>)/, "$1" + APP_NAME + "$2")
39
+ .replace(/(<key>CFBundleDisplayName<\/key>\s*<string>)[^<]*(<\/string>)/, "$1" + APP_NAME + "$2")
40
+ .replace(/(<key>CFBundleExecutable<\/key>\s*<string>)[^<]*(<\/string>)/, "$1" + APP_NAME + "$2");
41
+ if (after !== before) writeFileSync(plistPath, after);
42
+
43
+ // 2. Rename the executable so the directly-spawned process is "monacori" (idempotent).
44
+ if (existsSync(oldExe) && !existsSync(newExe)) renameSync(oldExe, newExe);
45
+
46
+ // 3. Repoint electron's path.txt at the renamed binary so require("electron") resolves it.
47
+ if (existsSync(pathTxt)) {
48
+ const pt = readFileSync(pathTxt, "utf8");
49
+ const fixed = pt.replace("MacOS/Electron", "MacOS/" + APP_NAME);
50
+ if (fixed !== pt) writeFileSync(pathTxt, fixed);
51
+ }
52
+ // Refresh LaunchServices so the Dock / Cmd+Tab show "monacori" instead of a cached "Electron".
53
+ // Without this, macOS keeps the previously-registered bundle name even after the plist is patched.
54
+ spawnSync(
55
+ "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister",
56
+ ["-f", appDir],
57
+ { stdio: "ignore" },
58
+ );
59
+ console.log('monacori: branded Electron app + executable as "' + APP_NAME + '"');
60
+ } catch {
61
+ // read-only / permission-denied environments — harmless, this is a convenience step
62
+ }
63
+ }
64
+
65
+ main();