fix statusLine not working

This commit is contained in:
musistudio
2025-10-02 07:55:17 +08:00
parent f04866207b
commit 73f9765980
3 changed files with 21 additions and 24 deletions

View File

@@ -26,6 +26,7 @@
"json5": "^2.2.3", "json5": "^2.2.3",
"openurl": "^1.1.1", "openurl": "^1.1.1",
"rotating-file-stream": "^3.2.7", "rotating-file-stream": "^3.2.7",
"shell-quote": "^1.8.3",
"tiktoken": "^1.0.21", "tiktoken": "^1.0.21",
"uuid": "^11.1.0" "uuid": "^11.1.0"
}, },

9
pnpm-lock.yaml generated
View File

@@ -29,6 +29,9 @@ importers:
rotating-file-stream: rotating-file-stream:
specifier: ^3.2.7 specifier: ^3.2.7
version: 3.2.7 version: 3.2.7
shell-quote:
specifier: ^1.8.3
version: 1.8.3
tiktoken: tiktoken:
specifier: ^1.0.21 specifier: ^1.0.21
version: 1.0.22 version: 1.0.22
@@ -840,6 +843,10 @@ packages:
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
engines: {node: '>=8'} engines: {node: '>=8'}
shell-quote@1.8.3:
resolution: {integrity: sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==}
engines: {node: '>= 0.4'}
shelljs@0.9.2: shelljs@0.9.2:
resolution: {integrity: sha512-S3I64fEiKgTZzKCC46zT/Ib9meqofLrQVbpSswtjFfAVDW+AZ54WTnAM/3/yENoxz/V1Cy6u3kiiEbQ4DNphvw==} resolution: {integrity: sha512-S3I64fEiKgTZzKCC46zT/Ib9meqofLrQVbpSswtjFfAVDW+AZ54WTnAM/3/yENoxz/V1Cy6u3kiiEbQ4DNphvw==}
engines: {node: '>=18'} engines: {node: '>=18'}
@@ -1739,6 +1746,8 @@ snapshots:
shebang-regex@3.0.0: {} shebang-regex@3.0.0: {}
shell-quote@1.8.3: {}
shelljs@0.9.2: shelljs@0.9.2:
dependencies: dependencies:
execa: 1.0.0 execa: 1.0.0

View File

@@ -5,15 +5,13 @@ import {
decrementReferenceCount, decrementReferenceCount,
incrementReferenceCount, incrementReferenceCount,
} from "./processCheck"; } from "./processCheck";
import {HOME_DIR} from "../constants"; import { quote } from 'shell-quote';
import {join} from "path";
export async function executeCodeCommand(args: string[] = []) { export async function executeCodeCommand(args: string[] = []) {
// Set environment variables // Set environment variables
const config = await readConfigFile(); const config = await readConfigFile();
const port = config.PORT || 3456; const port = config.PORT || 3456;
const env: Record<string, string> = { const env: Record<string, string> = {
...process.env,
ANTHROPIC_AUTH_TOKEN: config?.APIKEY || "test", ANTHROPIC_AUTH_TOKEN: config?.APIKEY || "test",
ANTHROPIC_API_KEY: '', ANTHROPIC_API_KEY: '',
ANTHROPIC_BASE_URL: `http://127.0.0.1:${port}`, ANTHROPIC_BASE_URL: `http://127.0.0.1:${port}`,
@@ -22,17 +20,17 @@ export async function executeCodeCommand(args: string[] = []) {
DISABLE_COST_WARNINGS: 'true', DISABLE_COST_WARNINGS: 'true',
API_TIMEOUT_MS: String(config.API_TIMEOUT_MS ?? 600000), // Default to 10 minutes if not set API_TIMEOUT_MS: String(config.API_TIMEOUT_MS ?? 600000), // Default to 10 minutes if not set
}; };
let settingsFlag: Record<string, any> | undefined; const settingsFlag = {
env
};
if (config?.StatusLine?.enabled) { if (config?.StatusLine?.enabled) {
settingsFlag = { settingsFlag.statusLine = {
statusLine: { type: "command",
type: "command", command: "ccr statusline",
command: "ccr statusline", padding: 0,
padding: 0,
}
} }
args.push(`--settings=${JSON.stringify(settingsFlag)}`);
} }
args.push('--settings', `${JSON.stringify(settingsFlag)}`);
// Non-interactive mode for automation environments // Non-interactive mode for automation environments
if (config.NON_INTERACTIVE_MODE) { if (config.NON_INTERACTIVE_MODE) {
@@ -47,25 +45,14 @@ export async function executeCodeCommand(args: string[] = []) {
env.ANTHROPIC_SMALL_FAST_MODEL = config.ANTHROPIC_SMALL_FAST_MODEL; env.ANTHROPIC_SMALL_FAST_MODEL = config.ANTHROPIC_SMALL_FAST_MODEL;
} }
// if (config?.APIKEY) {
// env.ANTHROPIC_API_KEY = config.APIKEY;
// delete env.ANTHROPIC_AUTH_TOKEN;
// }
// Increment reference count when command starts // Increment reference count when command starts
incrementReferenceCount(); incrementReferenceCount();
// Execute claude command // Execute claude command
const claudePath = config?.CLAUDE_PATH || process.env.CLAUDE_PATH || "claude"; const claudePath = config?.CLAUDE_PATH || process.env.CLAUDE_PATH || "claude";
// Properly join arguments to preserve spaces in quotes const joinedArgs = args.length > 0 ? quote(args) : "";
// Wrap each argument in double quotes to preserve single and double quotes inside arguments
const joinedArgs =
args.length > 0
? args.map((arg) => `"${arg.replace(/\"/g, '\\"')}"`).join(" ")
: "";
// 🔥 CONFIG-DRIVEN: stdio configuration based on environment
const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE
? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive ? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive
: "inherit"; // Default inherited behavior : "inherit"; // Default inherited behavior
@@ -73,7 +60,7 @@ export async function executeCodeCommand(args: string[] = []) {
claudePath + (joinedArgs ? ` ${joinedArgs}` : ""), claudePath + (joinedArgs ? ` ${joinedArgs}` : ""),
[], [],
{ {
env, env: process.env,
stdio: stdioConfig, stdio: stdioConfig,
shell: true, shell: true,
} }