arisa 2.3.31 → 2.3.32
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 +1 -1
- package/src/daemon/index.ts +2 -0
- package/src/daemon/lifecycle.ts +4 -0
- package/src/shared/ai-cli.ts +43 -11
package/package.json
CHANGED
package/src/daemon/index.ts
CHANGED
|
@@ -256,6 +256,8 @@ log.info(`Daemon push server listening on ${config.daemonSocket}`);
|
|
|
256
256
|
// --- Load Core in-process (single bun process, no child spawn) ---
|
|
257
257
|
log.info("Loading Core...");
|
|
258
258
|
await import("../core/index.ts");
|
|
259
|
+
const { setCoreState } = await import("./lifecycle");
|
|
260
|
+
setCoreState("up");
|
|
259
261
|
log.info("Core loaded");
|
|
260
262
|
|
|
261
263
|
// --- Auto-install missing CLIs (delayed to avoid peak memory) ---
|
package/src/daemon/lifecycle.ts
CHANGED
package/src/shared/ai-cli.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Claude CLI's non-root requirement.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { existsSync } from "fs";
|
|
8
|
+
import { existsSync, openSync, readSync, closeSync } from "fs";
|
|
9
9
|
import { delimiter, dirname, join } from "path";
|
|
10
10
|
|
|
11
11
|
export type AgentCliName = "claude" | "codex";
|
|
@@ -101,24 +101,56 @@ export interface AgentCliOptions {
|
|
|
101
101
|
skipPreload?: boolean;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Detect native executables (Mach-O, ELF) by reading magic bytes.
|
|
106
|
+
* Claude Code CLI v2+ ships as a native binary, not a JS script.
|
|
107
|
+
*/
|
|
108
|
+
function isNativeBinary(filePath: string): boolean {
|
|
109
|
+
try {
|
|
110
|
+
const fd = openSync(filePath, "r");
|
|
111
|
+
const buf = Buffer.alloc(4);
|
|
112
|
+
readSync(fd, buf, 0, 4, 0);
|
|
113
|
+
closeSync(fd);
|
|
114
|
+
const magic = buf.readUInt32BE(0);
|
|
115
|
+
return (
|
|
116
|
+
magic === 0xCFFAEDFE || // Mach-O 64-bit LE (macOS arm64/x86_64)
|
|
117
|
+
magic === 0xCEFAEDFE || // Mach-O 32-bit LE
|
|
118
|
+
magic === 0xFEEDFACF || // Mach-O 64-bit BE
|
|
119
|
+
magic === 0xFEEDFACE || // Mach-O 32-bit BE
|
|
120
|
+
magic === 0xCAFEBABE || // Mach-O Universal
|
|
121
|
+
magic === 0x7F454C46 // ELF (Linux)
|
|
122
|
+
);
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
104
128
|
export function buildBunWrappedAgentCliCommand(cli: AgentCliName, args: string[], options?: AgentCliOptions): string[] {
|
|
105
|
-
const
|
|
106
|
-
|
|
129
|
+
const cliPath = isRunningAsRoot()
|
|
130
|
+
? (resolveAgentCliPath(cli) || join(ROOT_BUN_BIN, cli))
|
|
131
|
+
: resolveAgentCliPath(cli);
|
|
132
|
+
|
|
133
|
+
if (!cliPath) {
|
|
134
|
+
throw new Error(`${cli} CLI not found`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Native binaries (Mach-O, ELF) must be executed directly — bun can't parse them as JS
|
|
138
|
+
const native = isNativeBinary(cliPath);
|
|
107
139
|
|
|
108
140
|
if (isRunningAsRoot()) {
|
|
109
141
|
// Run as arisa user — Claude CLI refuses to run as root.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
142
|
+
const inner = native
|
|
143
|
+
? [cliPath, ...args].map(shellEscape).join(" ")
|
|
144
|
+
: ["bun", "--bun", ...(!options?.skipPreload ? ["--preload", INK_SHIM] : []), cliPath, ...args].map(shellEscape).join(" ");
|
|
113
145
|
// su without "-" preserves parent env (tokens, keys); explicit HOME/PATH for arisa
|
|
114
146
|
return ["su", "arisa", "-s", "/bin/bash", "-c", `${ARISA_BUN_ENV} && ${buildEnvExports()}${inner}`];
|
|
115
147
|
}
|
|
116
148
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
throw new Error(`${cli} CLI not found`);
|
|
149
|
+
if (native) {
|
|
150
|
+
return [cliPath, ...args];
|
|
120
151
|
}
|
|
121
|
-
|
|
122
|
-
//
|
|
152
|
+
|
|
153
|
+
// JS/Node scripts: wrap with bun for performance + optional ink-shim preload
|
|
154
|
+
const preloadArgs = !options?.skipPreload ? ["--preload", INK_SHIM] : [];
|
|
123
155
|
return ["bun", "--bun", ...preloadArgs, cliPath, ...args];
|
|
124
156
|
}
|