arisa 2.3.29 → 2.3.31

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.29",
3
+ "version": "2.3.31",
4
4
  "description": "Arisa - dynamic agent runtime with daemon/core architecture that evolves through user interaction",
5
5
  "keywords": [
6
6
  "tinyclaw",
@@ -131,7 +131,7 @@ async function runClaudeSetupToken(): Promise<void> {
131
131
 
132
132
  let proc: ReturnType<typeof Bun.spawn>;
133
133
  try {
134
- proc = Bun.spawn(buildBunWrappedAgentCliCommand("claude", ["setup-token"]), {
134
+ proc = Bun.spawn(buildBunWrappedAgentCliCommand("claude", ["setup-token"], { skipPreload: true }), {
135
135
  cwd: config.projectDir,
136
136
  stdin: "pipe",
137
137
  stdout: "pipe",
@@ -106,7 +106,7 @@ async function runCodexDeviceAuth(): Promise<void> {
106
106
 
107
107
  let proc: ReturnType<typeof Bun.spawn>;
108
108
  try {
109
- proc = Bun.spawn(buildBunWrappedAgentCliCommand("codex", ["login", "--device-auth"]), {
109
+ proc = Bun.spawn(buildBunWrappedAgentCliCommand("codex", ["login", "--device-auth"], { skipPreload: true }), {
110
110
  cwd: config.projectDir,
111
111
  stdin: "inherit",
112
112
  stdout: "pipe",
@@ -15,6 +15,25 @@ import { getAgentCliLabel, runWithCliFallback } from "./agent-cli";
15
15
 
16
16
  const log = createLogger("daemon");
17
17
 
18
+ /** Detect CLI output that is an error message, not a real response */
19
+ function looksLikeCliError(output: string): boolean {
20
+ const lower = output.toLowerCase();
21
+ const errorPatterns = [
22
+ "authentication_error",
23
+ "invalid bearer token",
24
+ "invalid api key",
25
+ "api error: 401",
26
+ "api error: 403",
27
+ "failed to authenticate",
28
+ "permission_error",
29
+ "rate_limit_error",
30
+ "overloaded_error",
31
+ "api error: 429",
32
+ "api error: 529",
33
+ ];
34
+ return errorPatterns.some(p => lower.includes(p));
35
+ }
36
+
18
37
  export async function fallbackClaude(message: string, coreError?: string): Promise<string> {
19
38
  const systemContext = coreError
20
39
  ? `[System: Core process is down. Error: ${coreError}. You are running in fallback mode from Daemon. The user's project is at ${config.projectDir}. Respond to the user normally. If they ask about the error, explain what you see.]\n\n`
@@ -37,6 +56,11 @@ export async function fallbackClaude(message: string, coreError?: string): Promi
37
56
  const cli = getAgentCliLabel(result.cli);
38
57
  if (result.partial) {
39
58
  log.warn(`Fallback ${cli} returned output but exited with code ${result.exitCode}`);
59
+ // Don't forward CLI error messages (auth failures, API errors) to the user
60
+ if (looksLikeCliError(result.output)) {
61
+ log.error(`Fallback ${cli} output is a CLI error, not forwarding to user: ${result.output.slice(0, 300)}`);
62
+ return `[Fallback mode] ${cli} CLI failed (exit ${result.exitCode}). Please check server logs.`;
63
+ }
40
64
  } else {
41
65
  log.warn(`Using fallback ${cli} CLI`);
42
66
  }
@@ -282,7 +282,7 @@ async function runInteractiveLogin(cli: AgentCliName, vars: Record<string, strin
282
282
  try {
283
283
  // For claude: capture stdout to extract OAuth token while still showing output
284
284
  if (cli === "claude") {
285
- const proc = Bun.spawn(buildBunWrappedAgentCliCommand(cli, args), {
285
+ const proc = Bun.spawn(buildBunWrappedAgentCliCommand(cli, args, { skipPreload: true }), {
286
286
  stdin: "inherit",
287
287
  stdout: "pipe",
288
288
  stderr: "inherit",
@@ -390,7 +390,7 @@ async function runInteractiveLogin(cli: AgentCliName, vars: Record<string, strin
390
390
  }
391
391
 
392
392
  // For codex and others: inherit all stdio
393
- const proc = Bun.spawn(buildBunWrappedAgentCliCommand(cli, args), {
393
+ const proc = Bun.spawn(buildBunWrappedAgentCliCommand(cli, args, { skipPreload: true }), {
394
394
  stdin: "inherit",
395
395
  stdout: "inherit",
396
396
  stderr: "inherit",
@@ -96,12 +96,20 @@ function buildEnvExports(): string {
96
96
  return exports.length > 0 ? exports.join(" && ") + " && " : "";
97
97
  }
98
98
 
99
- export function buildBunWrappedAgentCliCommand(cli: AgentCliName, args: string[]): string[] {
99
+ export interface AgentCliOptions {
100
+ /** Skip the ink-shim preload (useful for interactive login flows). Default: false */
101
+ skipPreload?: boolean;
102
+ }
103
+
104
+ export function buildBunWrappedAgentCliCommand(cli: AgentCliName, args: string[], options?: AgentCliOptions): string[] {
105
+ const usePreload = !options?.skipPreload;
106
+ const preloadArgs = usePreload ? ["--preload", INK_SHIM] : [];
107
+
100
108
  if (isRunningAsRoot()) {
101
109
  // Run as arisa user — Claude CLI refuses to run as root.
102
110
  // This path is used by Daemon fallback calls; Core runs as arisa directly.
103
111
  const cliPath = resolveAgentCliPath(cli) || join(ROOT_BUN_BIN, cli);
104
- const inner = ["bun", "--bun", "--preload", INK_SHIM, cliPath, ...args].map(shellEscape).join(" ");
112
+ const inner = ["bun", "--bun", ...preloadArgs, cliPath, ...args].map(shellEscape).join(" ");
105
113
  // su without "-" preserves parent env (tokens, keys); explicit HOME/PATH for arisa
106
114
  return ["su", "arisa", "-s", "/bin/bash", "-c", `${ARISA_BUN_ENV} && ${buildEnvExports()}${inner}`];
107
115
  }
@@ -112,5 +120,5 @@ export function buildBunWrappedAgentCliCommand(cli: AgentCliName, args: string[]
112
120
  }
113
121
  // Preload shim that patches process.stdin.setRawMode to prevent Ink crash
114
122
  // when running without a TTY (systemd, su -c, etc.)
115
- return ["bun", "--bun", "--preload", INK_SHIM, cliPath, ...args];
123
+ return ["bun", "--bun", ...preloadArgs, cliPath, ...args];
116
124
  }