hinacode 0.1.0-alpha.11 → 0.1.0-alpha.13
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/out/main/daemon.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { mkdirSync, readlinkSync, writeFileSync, readFileSync, rmSync } from "node:fs";
|
|
1
|
+
import { mkdirSync, existsSync, readlinkSync, writeFileSync, readFileSync, rmSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { homedir, hostname } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import {
|
|
4
|
+
import { dirname, delimiter, basename, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import QRCode from "qrcode";
|
|
7
|
+
import { S as Struct, e as effect, U as Updates, g as gen, u as unsupported, E as Events, t as tryPromise, d as decodeUnknownSync, m as make$1, s as suspend, r as repeat, a as spaced, f as forkScoped, T as Threads, W as Worktrees, b as Terminals, c as forEach, o as orElseSucceed, h as sync, i as isThreadBusy, j as String$1, v as void_, k as andThen, l as matchEffect, n as forkDetach, p as flatMap, q as UsageError, w as USAGE, x as parseCommand, y as serveConfig, z as hydratePath, A as make$2, B as makeAppLayer, C as autoUpdate, D as layer$1, F as provideMerge, G as mergeAll, H as layer$2, I as layer$3, J as provide, K as noKeyring, L as layer$4, M as succeed, N as MinimumLogLevel, O as Settings, R as RemoteAccess, P as pairingUrl, Q as isPortInUse, V as restartCommand } from "./chunks/shellPath-Ccnlw2g1.js";
|
|
8
|
+
import { execFile } from "node:child_process";
|
|
9
|
+
import { promisify } from "node:util";
|
|
6
10
|
import "node:crypto";
|
|
7
|
-
import "node:url";
|
|
8
11
|
import "node:stream";
|
|
9
12
|
import "node:readline";
|
|
10
|
-
import "node:child_process";
|
|
11
13
|
import "node:fs/promises";
|
|
12
14
|
import "@anthropic-ai/claude-agent-sdk";
|
|
13
|
-
import "node:util";
|
|
14
15
|
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
15
16
|
import "@modelcontextprotocol/sdk/types.js";
|
|
16
17
|
import "@muse-code/sdk";
|
|
@@ -22,13 +23,100 @@ import "node:zlib";
|
|
|
22
23
|
import "ws";
|
|
23
24
|
import "node:net";
|
|
24
25
|
import "node:tls";
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const execFileAsync = promisify(execFile);
|
|
27
|
+
const CHECK_INTERVAL = "4 hours";
|
|
28
|
+
const AUTO_INSTALL_INTERVAL = "1 minute";
|
|
29
|
+
const INSTALL_TIMEOUT_MS = 10 * 6e4;
|
|
30
|
+
const NpmRelease = Struct({ version: String$1 });
|
|
31
|
+
const globalPrefix = (packageRoot2) => {
|
|
32
|
+
const nodeModules = dirname(packageRoot2);
|
|
33
|
+
const lib = dirname(nodeModules);
|
|
34
|
+
const isGlobal = basename(packageRoot2) === "hinacode" && basename(nodeModules) === "node_modules";
|
|
35
|
+
return isGlobal && basename(lib) === "lib" ? dirname(lib) : void 0;
|
|
36
|
+
};
|
|
37
|
+
const isIdle = (cloud) => cloud.terminals.every((terminal) => terminal.status !== "running") && cloud.threads.every((thread) => !isThreadBusy(thread.status) && thread.queue.length === 0) && cloud.worktrees.every((worktree) => worktree.status !== "preparing");
|
|
38
|
+
const make = ({ current, packageRoot: packageRoot2, registry, restart, autoInstall }) => gen(function* () {
|
|
39
|
+
const prefix = globalPrefix(packageRoot2);
|
|
40
|
+
if (prefix === void 0 || process.platform === "win32") return unsupported(current);
|
|
41
|
+
const events = yield* Events;
|
|
42
|
+
let state = { type: "idle" };
|
|
43
|
+
const set = (next) => suspend(() => {
|
|
44
|
+
state = next;
|
|
45
|
+
return events.publish({ type: "update.changed" });
|
|
46
|
+
});
|
|
47
|
+
const latest = tryPromise(async () => {
|
|
48
|
+
const response = await fetch(`${registry.replace(/\/$/, "")}/hinacode/latest`, {
|
|
49
|
+
signal: AbortSignal.timeout(1e4)
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) throw new Error(`npm answered ${response.status}`);
|
|
52
|
+
return decodeUnknownSync(NpmRelease)(await response.json()).version;
|
|
53
|
+
});
|
|
54
|
+
const checkLock = yield* make$1(1);
|
|
55
|
+
const check = suspend(
|
|
56
|
+
() => state.type === "downloading" ? void_ : set({ type: "checking" }).pipe(
|
|
57
|
+
andThen(latest),
|
|
58
|
+
matchEffect({
|
|
59
|
+
onFailure: (error) => set({ type: "failed", message: `Could not check for updates: ${error.message}` }),
|
|
60
|
+
onSuccess: (version2) => set(version2 === current ? { type: "upToDate" } : { type: "ready", version: version2 })
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
).pipe(checkLock.withPermit);
|
|
64
|
+
const npmEnv = { ...process.env, PATH: [dirname(process.execPath), process.env["PATH"]].join(delimiter) };
|
|
65
|
+
const npmInstall = (version2) => tryPromise({
|
|
66
|
+
try: () => execFileAsync(
|
|
67
|
+
"npm",
|
|
68
|
+
[
|
|
69
|
+
"install",
|
|
70
|
+
"--global",
|
|
71
|
+
`--prefix=${prefix}`,
|
|
72
|
+
`--registry=${registry}`,
|
|
73
|
+
// npm 11 skips install scripts it was not told to run, and node-pty's picks its prebuilt binary.
|
|
74
|
+
"--allow-scripts=node-pty",
|
|
75
|
+
`hinacode@${version2}`
|
|
76
|
+
],
|
|
77
|
+
{ env: npmEnv, encoding: "utf8", timeout: INSTALL_TIMEOUT_MS }
|
|
78
|
+
),
|
|
79
|
+
catch: (cause) => new Error(cause.stderr?.trim().split("\n").slice(-3).join("\n") || String(cause))
|
|
80
|
+
});
|
|
81
|
+
const install = suspend(() => {
|
|
82
|
+
if (state.type !== "ready") return void_;
|
|
83
|
+
const { version: version2 } = state;
|
|
84
|
+
return set({ type: "downloading", version: version2 }).pipe(
|
|
85
|
+
andThen(
|
|
86
|
+
npmInstall(version2).pipe(
|
|
87
|
+
matchEffect({
|
|
88
|
+
onFailure: (error) => set({ type: "failed", message: error.message }),
|
|
89
|
+
onSuccess: () => sync(restart)
|
|
90
|
+
}),
|
|
91
|
+
// The caller's rpc returns now; the cloud restarts once npm finishes.
|
|
92
|
+
forkDetach
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
yield* repeat(check, spaced(CHECK_INTERVAL)).pipe(forkScoped);
|
|
98
|
+
const [threads, worktrees, terminals] = [yield* Threads, yield* Worktrees, yield* Terminals];
|
|
99
|
+
const idle = gen(function* () {
|
|
100
|
+
const list = yield* threads.list;
|
|
101
|
+
const sessions = yield* forEach(list, (thread) => terminals.list(thread.id));
|
|
102
|
+
return isIdle({ threads: list, worktrees: yield* worktrees.list, terminals: sessions.flat() });
|
|
103
|
+
}).pipe(orElseSucceed(() => false));
|
|
104
|
+
const installWhenIdle = suspend(
|
|
105
|
+
() => state.type === "ready" ? flatMap(idle, (yes) => yes ? install : void_) : void_
|
|
106
|
+
);
|
|
107
|
+
if (autoInstall)
|
|
108
|
+
yield* repeat(installWhenIdle, spaced(AUTO_INSTALL_INTERVAL)).pipe(forkScoped);
|
|
109
|
+
return Updates.of({
|
|
110
|
+
status: sync(() => ({ current, state })),
|
|
111
|
+
check,
|
|
112
|
+
install
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
const layer = (options) => effect(Updates, make(options));
|
|
29
116
|
const QUIT_TIMEOUT_MS = 5e3;
|
|
30
117
|
const LISTEN_TIMEOUT_MS = 5e3;
|
|
31
118
|
const { version } = createRequire(import.meta.url)("../../package.json");
|
|
119
|
+
const packageRoot = fileURLToPath(new URL("../..", import.meta.url));
|
|
32
120
|
const appData = () => process.platform === "darwin" ? join(homedir(), "Library", "Application Support") : process.platform === "win32" ? process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming") : process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config");
|
|
33
121
|
const isAlive = (pid) => {
|
|
34
122
|
try {
|
|
@@ -56,72 +144,126 @@ const lockDataDir = (dir) => {
|
|
|
56
144
|
} catch (error) {
|
|
57
145
|
if (error.code !== "EEXIST") throw error;
|
|
58
146
|
const pid = Number(readFileSync(path, "utf8"));
|
|
147
|
+
if (pid === process.pid) break;
|
|
59
148
|
if (isAlive(pid)) throw new Error(`another hinacode serve (pid ${pid}) uses ${dir}`, { cause: error });
|
|
60
149
|
rmSync(path, { force: true });
|
|
61
150
|
}
|
|
62
151
|
}
|
|
63
152
|
process.on("exit", () => rmSync(path, { force: true }));
|
|
64
153
|
};
|
|
65
|
-
const
|
|
154
|
+
const pairingText = async (userData, pairing) => {
|
|
155
|
+
const phoneUrl = pairingUrl(pairing);
|
|
156
|
+
const qr = await QRCode.toString(phoneUrl, { type: "terminal", small: true });
|
|
157
|
+
return [
|
|
158
|
+
`HinaCode cloud ${version}`,
|
|
159
|
+
`data: ${userData}`,
|
|
160
|
+
"",
|
|
161
|
+
"Pair a phone: scan this code in the HinaCode app, or paste the URL.",
|
|
162
|
+
` ${phoneUrl}`,
|
|
163
|
+
qr,
|
|
164
|
+
"Pair a desktop: Settings > Environments > Add environment, with one of:",
|
|
165
|
+
...pairing.hosts.map((host) => ` ${pairingUrl({ ...pairing, hosts: [host] })}`),
|
|
166
|
+
"Keep the token in these URLs private. Run `hinacode pair` to print them again.",
|
|
167
|
+
""
|
|
168
|
+
].join("\n");
|
|
169
|
+
};
|
|
170
|
+
const listening = async (runtime) => {
|
|
66
171
|
const deadline = Date.now() + LISTEN_TIMEOUT_MS;
|
|
67
172
|
for (; ; ) {
|
|
68
173
|
const status = await runtime.runPromise(RemoteAccess.use((remote) => remote.status));
|
|
69
174
|
if (status.listening) break;
|
|
70
|
-
if (status.listenError
|
|
175
|
+
if (status.listenError !== null && isPortInUse(status.listenError)) {
|
|
176
|
+
const { port } = (await runtime.runPromise(Settings.use((settings) => settings.get))).remote;
|
|
177
|
+
throw new Error(
|
|
178
|
+
`port ${port} is in use, perhaps by the HinaCode desktop's Remote or another cloud. Pick another with --port <n>.`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (status.listenError !== null) throw new Error(`remote listener failed: ${status.listenError}`);
|
|
71
182
|
if (Date.now() > deadline) throw new Error("remote listener did not start in time");
|
|
72
183
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
73
184
|
}
|
|
74
|
-
|
|
75
|
-
const lines = [
|
|
76
|
-
`HinaCode cloud ${version}`,
|
|
77
|
-
`data: ${userData}`,
|
|
78
|
-
"pair a phone with:",
|
|
79
|
-
` ${pairingUrl(pairing)}`,
|
|
80
|
-
"pair a desktop with one of:",
|
|
81
|
-
...pairing.hosts.map((host) => ` ${pairingUrl({ ...pairing, hosts: [host] })}`)
|
|
82
|
-
];
|
|
83
|
-
process.stdout.write(`${lines.join("\n")}
|
|
84
|
-
`);
|
|
185
|
+
return runtime.runPromise(RemoteAccess.use((remote) => remote.pairing));
|
|
85
186
|
};
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
if (command === "--version") return void process.stdout.write(`${version}
|
|
89
|
-
`);
|
|
90
|
-
if (command !== "serve") {
|
|
91
|
-
process.stderr.write(`${USAGE}
|
|
92
|
-
`);
|
|
93
|
-
return void (process.exitCode = command === "--help" || command === "-h" ? 0 : 1);
|
|
94
|
-
}
|
|
95
|
-
const serve = serveConfig(argv, process.env);
|
|
96
|
-
const userData = process.env["HINACODE_USER_DATA"] || join(homedir(), ".hinacode-cloud");
|
|
187
|
+
const serve = async (argv, userData) => {
|
|
188
|
+
const config = serveConfig(argv, process.env);
|
|
97
189
|
mkdirSync(userData, { recursive: true, mode: 448 });
|
|
98
190
|
lockDataDir(userData);
|
|
99
191
|
await hydratePath(process.env);
|
|
100
|
-
const runtime = make(
|
|
192
|
+
const runtime = make$2(
|
|
101
193
|
makeAppLayer({
|
|
102
194
|
userData,
|
|
103
195
|
sbxConfigPath: join(appData(), "sbx", "config.json"),
|
|
104
196
|
keyring: noKeyring,
|
|
105
|
-
updates:
|
|
197
|
+
updates: layer({
|
|
198
|
+
current: version,
|
|
199
|
+
packageRoot,
|
|
200
|
+
registry: process.env["npm_config_registry"] || "https://registry.npmjs.org",
|
|
201
|
+
autoInstall: autoUpdate(process.env),
|
|
202
|
+
restart: () => stop(() => {
|
|
203
|
+
const { file, args, env } = restartCommand(process);
|
|
204
|
+
process.execve(file, args, env);
|
|
205
|
+
})
|
|
206
|
+
}),
|
|
106
207
|
toWindows: () => {
|
|
107
208
|
},
|
|
108
|
-
serve
|
|
209
|
+
serve: config
|
|
109
210
|
})
|
|
110
211
|
);
|
|
111
212
|
let stopping = false;
|
|
112
|
-
const stop = () => {
|
|
213
|
+
const stop = (then) => {
|
|
113
214
|
if (stopping) return;
|
|
114
215
|
stopping = true;
|
|
115
216
|
const disposal = runtime.dispose().catch((cause) => console.error("runtime dispose failed", cause));
|
|
116
217
|
const timeout = new Promise((resolve) => setTimeout(resolve, QUIT_TIMEOUT_MS));
|
|
117
|
-
void Promise.race([disposal, timeout]).then(
|
|
218
|
+
void Promise.race([disposal, timeout]).then(then);
|
|
118
219
|
};
|
|
119
|
-
|
|
120
|
-
process.on("
|
|
220
|
+
const quit = () => stop(() => process.exit(0));
|
|
221
|
+
process.on("SIGINT", quit);
|
|
222
|
+
process.on("SIGTERM", quit);
|
|
121
223
|
await runtime.runPromise(void_);
|
|
122
|
-
await
|
|
224
|
+
process.stdout.write(await pairingText(userData, await listening(runtime)));
|
|
225
|
+
};
|
|
226
|
+
const pair = async (userData) => {
|
|
227
|
+
const database = join(userData, "hinacode.sqlite");
|
|
228
|
+
const noCloud = () => {
|
|
229
|
+
process.stderr.write(`No cloud in ${userData} yet. Start one with \`hinacode serve\`.
|
|
230
|
+
`);
|
|
231
|
+
process.exitCode = 1;
|
|
232
|
+
};
|
|
233
|
+
if (!existsSync(database)) return noCloud();
|
|
234
|
+
const runtime = make$2(
|
|
235
|
+
layer$1.pipe(
|
|
236
|
+
provideMerge(mergeAll(layer$3, layer$2)),
|
|
237
|
+
provide(mergeAll(layer$4(database), noKeyring)),
|
|
238
|
+
provide(succeed(MinimumLogLevel, "Warn"))
|
|
239
|
+
)
|
|
240
|
+
);
|
|
241
|
+
try {
|
|
242
|
+
const { remote } = await runtime.runPromise(Settings.use((settings) => settings.get));
|
|
243
|
+
if (!remote.enabled) return noCloud();
|
|
244
|
+
const pairing = await runtime.runPromise(RemoteAccess.use((access) => access.pairing));
|
|
245
|
+
process.stdout.write(await pairingText(userData, pairing));
|
|
246
|
+
} finally {
|
|
247
|
+
await runtime.dispose();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const main = async (argv) => {
|
|
251
|
+
const command = parseCommand(argv);
|
|
252
|
+
if (command === "help") return void process.stdout.write(`${USAGE}
|
|
253
|
+
`);
|
|
254
|
+
if (command === "version") return void process.stdout.write(`${version}
|
|
255
|
+
`);
|
|
256
|
+
const userData = process.env["HINACODE_USER_DATA"] || join(homedir(), ".hinacode-cloud");
|
|
257
|
+
return command === "serve" ? serve(argv, userData) : pair(userData);
|
|
123
258
|
};
|
|
124
259
|
main(process.argv.slice(2)).catch((error) => {
|
|
125
|
-
|
|
260
|
+
if (error instanceof UsageError) {
|
|
261
|
+
process.stderr.write(`hinacode: ${error.message}
|
|
262
|
+
|
|
263
|
+
${USAGE}
|
|
264
|
+
`);
|
|
265
|
+
} else {
|
|
266
|
+
console.error(`hinacode ${process.argv[2]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
267
|
+
}
|
|
126
268
|
process.exit(1);
|
|
127
269
|
});
|
package/out/main/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { existsSync, renameSync } from "node:fs";
|
|
2
2
|
import { join, delimiter } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { Notification, nativeImage, BrowserWindow, ipcMain, app, dialog, shell, protocol, safeStorage, Menu, net, session } from "electron";
|
|
5
|
-
import {
|
|
4
|
+
import { Notification, nativeImage, BrowserWindow, ipcMain, app, dialog, shell, protocol, safeStorage, powerMonitor, Menu, net, session } from "electron";
|
|
5
|
+
import { h as sync, X as catchDefect, Y as succeed, Z as callback, _ as timeoutOrElse, $ as seconds, a0 as TaggedError, j as String$1, a1 as promise, t as tryPromise, S as Struct, a2 as optional, a3 as RpcCall, a4 as decodeUnknownOption, a5 as EVENT_CHANNEL, a6 as RPC_CHANNEL, a7 as isTrustedSender, g as gen, a8 as getOrUndefined, a9 as dispatch, aa as Environments, p as flatMap, ab as catch_, ac as all$1, ad as map, ae as decodeUnknownEffect, af as RpcMethods, ag as inlineSource, u as unsupported, E as Events, ah as runFork, ai as logWarning, r as repeat, a as spaced, f as forkScoped, U as Updates, s as suspend, e as effect, v as void_, aj as ignore, z as hydratePath, ak as ATTACHMENT_PROTOCOL, al as GITHUB_ASSET_PROTOCOL, am as PROJECT_FILE_PROTOCOL, M as succeed$1, an as Keyring, A as make$1, B as makeAppLayer, ao as isInside, ap as githubAssetId, aq as GitHub, ar as externalUrl, as as projectFileRequest, at as Files, au as BROWSER_PARTITION, av as lockDownWebview, aw as isAllowedNavigation } from "./chunks/shellPath-Ccnlw2g1.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import { execFile, spawn } from "node:child_process";
|
|
8
8
|
import { access } from "node:fs/promises";
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
10
11
|
import updater from "electron-updater";
|
|
11
12
|
import { join as join$1 } from "path";
|
|
12
|
-
import "node:crypto";
|
|
13
13
|
import "node:stream";
|
|
14
14
|
import "node:readline";
|
|
15
15
|
import "@anthropic-ai/claude-agent-sdk";
|
|
@@ -47,15 +47,17 @@ const routes = {
|
|
|
47
47
|
"environments.list": client,
|
|
48
48
|
"environments.add": client,
|
|
49
49
|
"environments.remove": client,
|
|
50
|
-
"
|
|
51
|
-
"updates.
|
|
52
|
-
"updates.
|
|
50
|
+
"environments.reconnect": client,
|
|
51
|
+
"updates.status": named,
|
|
52
|
+
"updates.check": named,
|
|
53
|
+
"updates.install": named,
|
|
53
54
|
"agents.updates": client,
|
|
54
55
|
"agents.update": client,
|
|
55
56
|
"links.favicon": client,
|
|
56
57
|
"projects.list": all,
|
|
57
58
|
"threads.list": all,
|
|
58
59
|
"worktrees.list": all,
|
|
60
|
+
"worktrees.checkouts": all,
|
|
59
61
|
"pullRequests.all": all,
|
|
60
62
|
"limits.list": named,
|
|
61
63
|
"search.threads": all,
|
|
@@ -89,6 +91,7 @@ const routes = {
|
|
|
89
91
|
"projects.defaultBranch": project,
|
|
90
92
|
"projects.branches": project,
|
|
91
93
|
"projects.pullRequests": project,
|
|
94
|
+
"projects.searchPullRequests": project,
|
|
92
95
|
"projects.fetch": project,
|
|
93
96
|
"projects.icon": project,
|
|
94
97
|
"threads.create": owner("project", "projectId"),
|
|
@@ -138,6 +141,7 @@ const routes = {
|
|
|
138
141
|
"attachments.read": named,
|
|
139
142
|
"worktrees.remove": owner("worktree", "id"),
|
|
140
143
|
"worktrees.setupLog": owner("worktree", "id"),
|
|
144
|
+
"worktrees.stopSetup": owner("worktree", "id"),
|
|
141
145
|
"worktrees.pullRequest": owner("worktree", "id"),
|
|
142
146
|
"terminal.write": owner("terminal", "id"),
|
|
143
147
|
"terminal.resize": owner("terminal", "id"),
|
|
@@ -240,7 +244,8 @@ const launch = (location, path) => new Promise((resolve, reject) => {
|
|
|
240
244
|
execFile("open", ["-a", location, path], (error) => error ? reject(error) : resolve());
|
|
241
245
|
return;
|
|
242
246
|
}
|
|
243
|
-
const
|
|
247
|
+
const env = { ...process.env, HINACODE_INSTANCE: void 0 };
|
|
248
|
+
const child = process.platform === "win32" ? spawn(`"${location}"`, [`"${path}"`], { detached: true, stdio: "ignore", shell: true, env }) : spawn(location, [path], { detached: true, stdio: "ignore", env });
|
|
244
249
|
child.once("error", reject);
|
|
245
250
|
child.once("spawn", () => {
|
|
246
251
|
child.unref();
|
|
@@ -327,6 +332,18 @@ const registerIpc = (runtime, appUrl2) => {
|
|
|
327
332
|
const sendToWindows = (encoded) => {
|
|
328
333
|
for (const window of BrowserWindow.getAllWindows()) window.webContents.send(EVENT_CHANNEL, encoded);
|
|
329
334
|
};
|
|
335
|
+
const binary = join(import.meta.dirname, "../../tools/resource-monitor/bin/resource-monitor");
|
|
336
|
+
const startResourceMonitor = (userData) => {
|
|
337
|
+
if (!existsSync(binary)) return;
|
|
338
|
+
const instance = randomUUID();
|
|
339
|
+
process.env["HINACODE_INSTANCE"] = instance;
|
|
340
|
+
const log = join(userData, "resource-monitor", `${(/* @__PURE__ */ new Date()).toISOString().replaceAll(":", "-")}.ndjson`);
|
|
341
|
+
spawn(binary, ["watch", "-root", String(process.pid), "-instance", instance, "-out", log], {
|
|
342
|
+
detached: true,
|
|
343
|
+
stdio: ["ignore", "ignore", "inherit"]
|
|
344
|
+
}).on("error", (error) => console.error(`Resource monitor did not start: ${error.message}`)).unref();
|
|
345
|
+
console.log(`Resource monitor log: ${log}`);
|
|
346
|
+
};
|
|
330
347
|
const CHECK_INTERVAL = "4 hours";
|
|
331
348
|
const make = gen(function* () {
|
|
332
349
|
const current = app.getVersion();
|
|
@@ -369,6 +386,7 @@ if (!app.requestSingleInstanceLock()) {
|
|
|
369
386
|
console.error(`HinaCode is already running on ${app.getPath("userData")}. Set HINACODE_USER_DATA to run another.`);
|
|
370
387
|
app.exit(0);
|
|
371
388
|
}
|
|
389
|
+
if (!app.isPackaged) startResourceMonitor(app.getPath("userData"));
|
|
372
390
|
const pathHydrated = hydratePath(process.env);
|
|
373
391
|
protocol.registerSchemesAsPrivileged([
|
|
374
392
|
{ scheme: ATTACHMENT_PROTOCOL, privileges: { standard: true, secure: true } },
|
|
@@ -544,6 +562,10 @@ app.whenReady().then(async () => {
|
|
|
544
562
|
void Promise.race([disposal, timeout]).then(() => app.quit());
|
|
545
563
|
});
|
|
546
564
|
registerIpc(runtime, appUrl);
|
|
565
|
+
powerMonitor.on(
|
|
566
|
+
"resume",
|
|
567
|
+
() => runtime.runFork(flatMap(Environments, (environments) => environments.reconnectAll))
|
|
568
|
+
);
|
|
547
569
|
app.dock?.setIcon(icon);
|
|
548
570
|
if (process.platform === "darwin") setMacMenu();
|
|
549
571
|
serveAttachments(runtime, join(userData, "attachments"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hinacode",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.13",
|
|
4
4
|
"description": "Run coding agents on this machine and drive them from the HinaCode desktop or phone app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"main": "./out/main/index.js",
|
|
19
19
|
"scripts": {
|
|
20
|
-
"dev": "node scripts/dev-app-identity.mjs && electron-vite dev",
|
|
20
|
+
"dev": "node scripts/dev-app-identity.mjs && node scripts/build-resource-monitor.mjs && electron-vite dev",
|
|
21
21
|
"dev:markdown": "HINACODE_MOCK_CLAUDE=markdown HINACODE_USER_DATA=/tmp/kk-markdown pnpm dev",
|
|
22
22
|
"build": "electron-vite build",
|
|
23
23
|
"preview": "electron-vite preview",
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"typecheck": "pnpm paraglide && tsc --noEmit -p tsconfig.node.json && tsc --noEmit -p tsconfig.web.json && tsc --noEmit -p tsconfig.web-test.json && tsc --noEmit -p tsconfig.e2e.json",
|
|
29
29
|
"lint": "oxlint",
|
|
30
30
|
"check:specs": "node scripts/tlc.mjs",
|
|
31
|
+
"chart:thread": "node scripts/thread-chart.mjs",
|
|
32
|
+
"resource-monitor": "tools/resource-monitor/bin/resource-monitor",
|
|
31
33
|
"format": "oxfmt",
|
|
32
34
|
"test": "vitest run",
|
|
33
35
|
"test:unit": "vitest run --project unit",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"@vitejs/plugin-react": "5.2.0",
|
|
78
80
|
"@wterm/dom": "0.5.4",
|
|
79
81
|
"@wterm/ghostty": "0.5.4",
|
|
82
|
+
"babel-plugin-react-compiler": "1.0.0",
|
|
80
83
|
"class-variance-authority": "^0.7.1",
|
|
81
84
|
"cn": "^0.4.0",
|
|
82
85
|
"electron": "44.7.0",
|