arisa 2.3.31 → 2.3.33

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": "arisa",
3
- "version": "2.3.31",
3
+ "version": "2.3.33",
4
4
  "description": "Arisa - dynamic agent runtime with daemon/core architecture that evolves through user interaction",
5
5
  "keywords": [
6
6
  "tinyclaw",
@@ -20,7 +20,10 @@ const AUTH_HINT_PATTERNS = [
20
20
  /please run \/login/i,
21
21
  /invalid.*api.?key/i,
22
22
  /authentication.*failed/i,
23
+ /failed to authenticat/i,
23
24
  /not authenticated/i,
25
+ /authentication_error/i,
26
+ /invalid.*bearer.*token/i,
24
27
  /ANTHROPIC_API_KEY/,
25
28
  /api key not found/i,
26
29
  /invalid x-api-key/i,
@@ -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) ---
@@ -61,6 +61,10 @@ export function getCoreState(): CoreState {
61
61
  return coreState;
62
62
  }
63
63
 
64
+ export function setCoreState(state: CoreState) {
65
+ coreState = state;
66
+ }
67
+
64
68
  export function getCoreError(): string | null {
65
69
  return lastError;
66
70
  }
@@ -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 usePreload = !options?.skipPreload;
106
- const preloadArgs = usePreload ? ["--preload", INK_SHIM] : [];
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
- // This path is used by Daemon fallback calls; Core runs as arisa directly.
111
- const cliPath = resolveAgentCliPath(cli) || join(ROOT_BUN_BIN, cli);
112
- const inner = ["bun", "--bun", ...preloadArgs, cliPath, ...args].map(shellEscape).join(" ");
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
- const cliPath = resolveAgentCliPath(cli);
118
- if (!cliPath) {
119
- throw new Error(`${cli} CLI not found`);
149
+ if (native) {
150
+ return [cliPath, ...args];
120
151
  }
121
- // Preload shim that patches process.stdin.setRawMode to prevent Ink crash
122
- // when running without a TTY (systemd, su -c, etc.)
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
  }