@nubase/terminal 0.1.1 → 0.1.2
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/nubase.js +140 -7
- package/out/main/index.js +29 -3
- package/package.json +5 -3
- package/resources/icon.icns +0 -0
- package/resources/icon.png +0 -0
package/bin/nubase.js
CHANGED
|
@@ -1,11 +1,144 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import {
|
|
5
|
+
copyFileSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
renameSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
} from "node:fs";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { dirname, join, resolve } from "node:path";
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
16
|
import electron from "electron";
|
|
6
17
|
|
|
7
18
|
const appDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
const env = { ...process.env, NUBASE_LAUNCHED_FROM_CLI: "1" };
|
|
21
|
+
|
|
22
|
+
const run = (command, commandArgs) => {
|
|
23
|
+
const child = spawn(command, commandArgs, { stdio: "inherit", env });
|
|
24
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Electron from npm is a generic "Electron.app": pinned to the Dock it opens
|
|
29
|
+
* Electron's default page, and macOS shows its name and icon. So on macOS
|
|
30
|
+
* Nubase runs from its own bundle, ~/Applications/Nubase.app — a clone of
|
|
31
|
+
* Electron.app with Nubase's name and icon, whose app is a stub that loads
|
|
32
|
+
* this package. It is rebuilt whenever this package or Electron changes.
|
|
33
|
+
*/
|
|
34
|
+
const ensureMacBundle = () => {
|
|
35
|
+
const pkg = JSON.parse(readFileSync(join(appDir, "package.json"), "utf8"));
|
|
36
|
+
const electronApp = resolve(electron, "../../..");
|
|
37
|
+
const electronVersion = JSON.parse(
|
|
38
|
+
readFileSync(
|
|
39
|
+
join(
|
|
40
|
+
dirname(fileURLToPath(import.meta.resolve("electron"))),
|
|
41
|
+
"package.json",
|
|
42
|
+
),
|
|
43
|
+
"utf8",
|
|
44
|
+
),
|
|
45
|
+
).version;
|
|
46
|
+
const icon = join(appDir, "resources", "icon.icns");
|
|
47
|
+
const stamp = JSON.stringify({
|
|
48
|
+
appDir,
|
|
49
|
+
version: pkg.version,
|
|
50
|
+
electronVersion,
|
|
51
|
+
icon: existsSync(icon)
|
|
52
|
+
? createHash("sha1").update(readFileSync(icon)).digest("hex")
|
|
53
|
+
: "",
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const bundle = join(homedir(), "Applications", "Nubase.app");
|
|
57
|
+
const stampFile = join(bundle, "Contents", "Resources", "nubase-stamp.json");
|
|
58
|
+
const executable = join(bundle, "Contents", "MacOS", "Electron");
|
|
59
|
+
if (existsSync(stampFile) && readFileSync(stampFile, "utf8") === stamp) {
|
|
60
|
+
return executable;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Built next to the old bundle and swapped in, so a running copy keeps working.
|
|
64
|
+
const staging = `${bundle}.staging`;
|
|
65
|
+
rmSync(staging, { recursive: true, force: true });
|
|
66
|
+
mkdirSync(dirname(bundle), { recursive: true });
|
|
67
|
+
try {
|
|
68
|
+
// APFS clone: instant and takes no extra disk space.
|
|
69
|
+
execFileSync("cp", ["-cR", electronApp, staging], { stdio: "ignore" });
|
|
70
|
+
} catch {
|
|
71
|
+
rmSync(staging, { recursive: true, force: true });
|
|
72
|
+
execFileSync("cp", ["-R", electronApp, staging]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const contents = join(staging, "Contents");
|
|
76
|
+
const plist = join(contents, "Info.plist");
|
|
77
|
+
const setPlist = (key, value) =>
|
|
78
|
+
execFileSync("plutil", ["-replace", key, "-string", value, plist]);
|
|
79
|
+
setPlist("CFBundleName", "Nubase");
|
|
80
|
+
setPlist("CFBundleDisplayName", "Nubase");
|
|
81
|
+
setPlist("CFBundleIdentifier", "io.nubase.terminal");
|
|
82
|
+
if (existsSync(icon)) {
|
|
83
|
+
copyFileSync(icon, join(contents, "Resources", "nubase.icns"));
|
|
84
|
+
setPlist("CFBundleIconFile", "nubase.icns");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const stub = join(contents, "Resources", "app");
|
|
88
|
+
mkdirSync(stub, { recursive: true });
|
|
89
|
+
writeFileSync(
|
|
90
|
+
join(stub, "package.json"),
|
|
91
|
+
JSON.stringify(
|
|
92
|
+
{
|
|
93
|
+
name: pkg.name,
|
|
94
|
+
productName: pkg.productName,
|
|
95
|
+
version: pkg.version,
|
|
96
|
+
type: "module",
|
|
97
|
+
main: "main.js",
|
|
98
|
+
},
|
|
99
|
+
null,
|
|
100
|
+
2,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
writeFileSync(
|
|
104
|
+
join(stub, "main.js"),
|
|
105
|
+
`import ${JSON.stringify(pathToFileURL(join(appDir, pkg.main)).href)};\n`,
|
|
106
|
+
);
|
|
107
|
+
writeFileSync(join(contents, "Resources", "nubase-stamp.json"), stamp);
|
|
108
|
+
|
|
109
|
+
// Editing the bundle invalidates Electron's signature; Apple Silicon needs a valid one.
|
|
110
|
+
execFileSync("codesign", ["--force", "--deep", "--sign", "-", staging], {
|
|
111
|
+
stdio: "ignore",
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const old = `${bundle}.old`;
|
|
115
|
+
rmSync(old, { recursive: true, force: true });
|
|
116
|
+
if (existsSync(bundle)) renameSync(bundle, old);
|
|
117
|
+
renameSync(staging, bundle);
|
|
118
|
+
rmSync(old, { recursive: true, force: true });
|
|
119
|
+
|
|
120
|
+
// Makes Finder and the Dock pick up the new name and icon.
|
|
121
|
+
try {
|
|
122
|
+
execFileSync(
|
|
123
|
+
"/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister",
|
|
124
|
+
["-f", bundle],
|
|
125
|
+
{ stdio: "ignore" },
|
|
126
|
+
);
|
|
127
|
+
} catch {}
|
|
128
|
+
return executable;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (process.platform === "darwin") {
|
|
132
|
+
let executable;
|
|
133
|
+
try {
|
|
134
|
+
executable = ensureMacBundle();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error(
|
|
137
|
+
`Could not set up Nubase.app (${error.message}); running Electron directly.`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (executable) run(executable, args);
|
|
141
|
+
else run(electron, [appDir, ...args]);
|
|
142
|
+
} else {
|
|
143
|
+
run(electron, [appDir, ...args]);
|
|
144
|
+
}
|
package/out/main/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { accessSync, chmodSync, constants, createReadStream, existsSync, mkdirSync, statSync, watch } from "node:fs";
|
|
2
3
|
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
3
4
|
import { pathToFileURL } from "node:url";
|
|
4
5
|
import { BaseWindow, BrowserWindow, Menu, WebContentsView, app, dialog, ipcMain, nativeImage, net, protocol, safeStorage, shell } from "electron";
|
|
5
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
6
7
|
import { homedir } from "node:os";
|
|
7
|
-
import { accessSync, chmodSync, constants, createReadStream, existsSync, mkdirSync, statSync, watch } from "node:fs";
|
|
8
8
|
import { cp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
9
|
-
import { execFile } from "node:child_process";
|
|
9
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
10
10
|
import { promisify } from "node:util";
|
|
11
11
|
import { Readable } from "node:stream";
|
|
12
12
|
import * as sdkHost from "@nubase/sdk/host";
|
|
@@ -3125,7 +3125,31 @@ var WorkspaceManager = class {
|
|
|
3125
3125
|
}
|
|
3126
3126
|
};
|
|
3127
3127
|
//#endregion
|
|
3128
|
+
//#region src/main/shellEnv.ts
|
|
3129
|
+
var MARKER = "__NUBASE_PATH__";
|
|
3130
|
+
/**
|
|
3131
|
+
* Apps started from the Dock or Finder get launchd's bare PATH, so the agent
|
|
3132
|
+
* and terminal could not find git, node or Homebrew tools. Takes PATH from the
|
|
3133
|
+
* user's login shell instead, unless the `nubase` CLI already passed its own.
|
|
3134
|
+
*/
|
|
3135
|
+
var adoptLoginShellPath = () => {
|
|
3136
|
+
if (process.platform !== "darwin" || process.env.NUBASE_LAUNCHED_FROM_CLI) return;
|
|
3137
|
+
try {
|
|
3138
|
+
const path = execFileSync(process.env.SHELL ?? "/bin/zsh", ["-ilc", `printf '${MARKER}%s' "$PATH"`], {
|
|
3139
|
+
encoding: "utf8",
|
|
3140
|
+
timeout: 5e3,
|
|
3141
|
+
stdio: [
|
|
3142
|
+
"ignore",
|
|
3143
|
+
"pipe",
|
|
3144
|
+
"ignore"
|
|
3145
|
+
]
|
|
3146
|
+
}).split(MARKER).at(-1)?.trim();
|
|
3147
|
+
if (path) process.env.PATH = path;
|
|
3148
|
+
} catch {}
|
|
3149
|
+
};
|
|
3150
|
+
//#endregion
|
|
3128
3151
|
//#region src/main/index.ts
|
|
3152
|
+
adoptLoginShellPath();
|
|
3129
3153
|
var safeMode = process.argv.includes("--safe-mode");
|
|
3130
3154
|
protocol.registerSchemesAsPrivileged([{
|
|
3131
3155
|
scheme: EXTENSION_PROTOCOL,
|
|
@@ -3172,7 +3196,9 @@ var createWindow = () => {
|
|
|
3172
3196
|
};
|
|
3173
3197
|
var main = async () => {
|
|
3174
3198
|
await app.whenReady();
|
|
3175
|
-
const resourcesDir = join(
|
|
3199
|
+
const resourcesDir = join(import.meta.dirname, "../../resources");
|
|
3200
|
+
const iconPath = join(resourcesDir, "icon.png");
|
|
3201
|
+
if (process.platform === "darwin" && existsSync(iconPath)) app.dock?.setIcon(iconPath);
|
|
3176
3202
|
const rootSettings = new SettingsService(paths.settings);
|
|
3177
3203
|
await rootSettings.load();
|
|
3178
3204
|
await prepareExtensionsWorkspace(paths.extensions, resourcesDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubase/terminal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Nubase: an AI harness with a real, self-extending UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"test": "vitest run",
|
|
25
25
|
"typecheck": "tsc --noEmit",
|
|
26
26
|
"lint": "biome check .",
|
|
27
|
-
"lint:fix": "biome check . --write --unsafe"
|
|
27
|
+
"lint:fix": "biome check . --write --unsafe",
|
|
28
|
+
"icons": "./scripts/make-icns.sh"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@earendil-works/pi-coding-agent": "1.5.2",
|
|
@@ -64,5 +65,6 @@
|
|
|
64
65
|
"vite": "^8.1.0",
|
|
65
66
|
"vitest": "^4.1.9",
|
|
66
67
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
|
67
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"productName": "Nubase"
|
|
68
70
|
}
|
|
Binary file
|
|
Binary file
|