claudish 3.3.10 → 3.4.0
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/dist/index.js +648 -450
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -56301,31 +56301,51 @@ var init_remote_provider_types = __esm(() => {
|
|
|
56301
56301
|
"gemini-3.0-flash": { inputCostPer1M: 0.1, outputCostPer1M: 0.4 },
|
|
56302
56302
|
"gemini-2.0-flash": { inputCostPer1M: 0.1, outputCostPer1M: 0.4 },
|
|
56303
56303
|
"gemini-2.0-flash-thinking": { inputCostPer1M: 0.1, outputCostPer1M: 0.4 },
|
|
56304
|
-
default: { inputCostPer1M: 0.5, outputCostPer1M: 2 }
|
|
56304
|
+
default: { inputCostPer1M: 0.5, outputCostPer1M: 2, isEstimate: true }
|
|
56305
56305
|
};
|
|
56306
56306
|
OPENAI_PRICING = {
|
|
56307
|
-
"gpt-5": { inputCostPer1M:
|
|
56308
|
-
"gpt-5.2": { inputCostPer1M:
|
|
56309
|
-
"gpt-5-
|
|
56310
|
-
"gpt-5.
|
|
56307
|
+
"gpt-5.2": { inputCostPer1M: 1.75, outputCostPer1M: 14 },
|
|
56308
|
+
"gpt-5.2-codex": { inputCostPer1M: 1.75, outputCostPer1M: 14 },
|
|
56309
|
+
"gpt-5.2-chat-latest": { inputCostPer1M: 1.75, outputCostPer1M: 14 },
|
|
56310
|
+
"gpt-5.2-pro": { inputCostPer1M: 21, outputCostPer1M: 168 },
|
|
56311
|
+
"gpt-5.1": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56312
|
+
"gpt-5.1-codex": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56313
|
+
"gpt-5.1-codex-max": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56314
|
+
"gpt-5.1-codex-mini": { inputCostPer1M: 0.25, outputCostPer1M: 2 },
|
|
56315
|
+
"gpt-5.1-chat-latest": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56316
|
+
"gpt-5": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56317
|
+
"gpt-5-codex": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56318
|
+
"gpt-5-chat-latest": { inputCostPer1M: 1.25, outputCostPer1M: 10 },
|
|
56319
|
+
"gpt-5-mini": { inputCostPer1M: 0.25, outputCostPer1M: 2 },
|
|
56320
|
+
"gpt-5-nano": { inputCostPer1M: 0.05, outputCostPer1M: 0.4 },
|
|
56321
|
+
"gpt-5-pro": { inputCostPer1M: 15, outputCostPer1M: 120 },
|
|
56322
|
+
"gpt-4.1": { inputCostPer1M: 2, outputCostPer1M: 8 },
|
|
56323
|
+
"gpt-4.1-mini": { inputCostPer1M: 0.4, outputCostPer1M: 1.6 },
|
|
56324
|
+
"gpt-4.1-nano": { inputCostPer1M: 0.1, outputCostPer1M: 0.4 },
|
|
56311
56325
|
"gpt-4o": { inputCostPer1M: 2.5, outputCostPer1M: 10 },
|
|
56326
|
+
"gpt-4o-2024-05-13": { inputCostPer1M: 5, outputCostPer1M: 15 },
|
|
56312
56327
|
"gpt-4o-mini": { inputCostPer1M: 0.15, outputCostPer1M: 0.6 },
|
|
56313
56328
|
"gpt-4o-audio": { inputCostPer1M: 2.5, outputCostPer1M: 10 },
|
|
56314
56329
|
o1: { inputCostPer1M: 15, outputCostPer1M: 60 },
|
|
56315
|
-
"o1-mini": { inputCostPer1M:
|
|
56316
|
-
"o1-
|
|
56317
|
-
o3: { inputCostPer1M:
|
|
56318
|
-
"o3-mini": { inputCostPer1M:
|
|
56330
|
+
"o1-mini": { inputCostPer1M: 1.1, outputCostPer1M: 4.4 },
|
|
56331
|
+
"o1-pro": { inputCostPer1M: 150, outputCostPer1M: 600 },
|
|
56332
|
+
o3: { inputCostPer1M: 2, outputCostPer1M: 8 },
|
|
56333
|
+
"o3-mini": { inputCostPer1M: 1.1, outputCostPer1M: 4.4 },
|
|
56334
|
+
"o3-pro": { inputCostPer1M: 20, outputCostPer1M: 80 },
|
|
56335
|
+
"o3-deep-research": { inputCostPer1M: 10, outputCostPer1M: 40 },
|
|
56336
|
+
"o4-mini": { inputCostPer1M: 1.1, outputCostPer1M: 4.4 },
|
|
56337
|
+
"o4-mini-deep-research": { inputCostPer1M: 2, outputCostPer1M: 8 },
|
|
56319
56338
|
"gpt-4-turbo": { inputCostPer1M: 10, outputCostPer1M: 30 },
|
|
56320
56339
|
"gpt-4-turbo-preview": { inputCostPer1M: 10, outputCostPer1M: 30 },
|
|
56321
56340
|
"gpt-4": { inputCostPer1M: 30, outputCostPer1M: 60 },
|
|
56322
56341
|
"gpt-3.5-turbo": { inputCostPer1M: 0.5, outputCostPer1M: 1.5 },
|
|
56323
|
-
|
|
56342
|
+
"codex-mini-latest": { inputCostPer1M: 1.5, outputCostPer1M: 6 },
|
|
56343
|
+
default: { inputCostPer1M: 2, outputCostPer1M: 8, isEstimate: true }
|
|
56324
56344
|
};
|
|
56325
56345
|
MINIMAX_PRICING = {
|
|
56326
56346
|
"minimax-m2.1": { inputCostPer1M: 0.12, outputCostPer1M: 0.48 },
|
|
56327
56347
|
"minimax-m2": { inputCostPer1M: 0.12, outputCostPer1M: 0.48 },
|
|
56328
|
-
default: { inputCostPer1M: 0.12, outputCostPer1M: 0.48 }
|
|
56348
|
+
default: { inputCostPer1M: 0.12, outputCostPer1M: 0.48, isEstimate: true }
|
|
56329
56349
|
};
|
|
56330
56350
|
KIMI_PRICING = {
|
|
56331
56351
|
"kimi-k2-thinking-turbo": { inputCostPer1M: 0.32, outputCostPer1M: 0.48 },
|
|
@@ -56333,13 +56353,13 @@ var init_remote_provider_types = __esm(() => {
|
|
|
56333
56353
|
"kimi-k2-turbo-preview": { inputCostPer1M: 0.2, outputCostPer1M: 0.4 },
|
|
56334
56354
|
"kimi-k2-0905-preview": { inputCostPer1M: 0.2, outputCostPer1M: 0.4 },
|
|
56335
56355
|
"kimi-k2": { inputCostPer1M: 0.2, outputCostPer1M: 0.4 },
|
|
56336
|
-
default: { inputCostPer1M: 0.32, outputCostPer1M: 0.48 }
|
|
56356
|
+
default: { inputCostPer1M: 0.32, outputCostPer1M: 0.48, isEstimate: true }
|
|
56337
56357
|
};
|
|
56338
56358
|
GLM_PRICING = {
|
|
56339
56359
|
"glm-4.7": { inputCostPer1M: 0.16, outputCostPer1M: 0.8 },
|
|
56340
56360
|
"glm-4": { inputCostPer1M: 0.16, outputCostPer1M: 0.8 },
|
|
56341
56361
|
"glm-4-plus": { inputCostPer1M: 0.5, outputCostPer1M: 2 },
|
|
56342
|
-
default: { inputCostPer1M: 0.16, outputCostPer1M: 0.8 }
|
|
56362
|
+
default: { inputCostPer1M: 0.16, outputCostPer1M: 0.8, isEstimate: true }
|
|
56343
56363
|
};
|
|
56344
56364
|
});
|
|
56345
56365
|
|
|
@@ -56980,7 +57000,7 @@ class OpenAIHandler {
|
|
|
56980
57000
|
}
|
|
56981
57001
|
return `${this.provider.baseUrl}${this.provider.apiPath}`;
|
|
56982
57002
|
}
|
|
56983
|
-
writeTokenFile(input, output) {
|
|
57003
|
+
writeTokenFile(input, output, isEstimate) {
|
|
56984
57004
|
try {
|
|
56985
57005
|
const total = input + output;
|
|
56986
57006
|
const leftPct = this.contextWindow > 0 ? Math.max(0, Math.min(100, Math.round((this.contextWindow - total) / this.contextWindow * 100))) : 100;
|
|
@@ -56993,6 +57013,9 @@ class OpenAIHandler {
|
|
|
56993
57013
|
context_left_percent: leftPct,
|
|
56994
57014
|
updated_at: Date.now()
|
|
56995
57015
|
};
|
|
57016
|
+
if (isEstimate) {
|
|
57017
|
+
data.cost_is_estimate = true;
|
|
57018
|
+
}
|
|
56996
57019
|
const claudishDir = join9(homedir5(), ".claudish");
|
|
56997
57020
|
mkdirSync6(claudishDir, { recursive: true });
|
|
56998
57021
|
writeFileSync8(join9(claudishDir, `tokens-${this.port}.json`), JSON.stringify(data), "utf-8");
|
|
@@ -57001,13 +57024,23 @@ class OpenAIHandler {
|
|
|
57001
57024
|
}
|
|
57002
57025
|
}
|
|
57003
57026
|
updateTokenTracking(inputTokens, outputTokens) {
|
|
57004
|
-
|
|
57005
|
-
this.sessionInputTokens
|
|
57027
|
+
let incrementalInputTokens;
|
|
57028
|
+
if (inputTokens >= this.sessionInputTokens) {
|
|
57029
|
+
incrementalInputTokens = inputTokens - this.sessionInputTokens;
|
|
57030
|
+
this.sessionInputTokens = inputTokens;
|
|
57031
|
+
} else if (inputTokens < this.sessionInputTokens * 0.5) {
|
|
57032
|
+
incrementalInputTokens = inputTokens;
|
|
57033
|
+
log(`[OpenAIHandler] Token tracking: detected concurrent conversation (${inputTokens} < ${this.sessionInputTokens}), charging full input`);
|
|
57034
|
+
} else {
|
|
57035
|
+
incrementalInputTokens = inputTokens;
|
|
57036
|
+
this.sessionInputTokens = inputTokens;
|
|
57037
|
+
log(`[OpenAIHandler] Token tracking: ambiguous token decrease (${inputTokens} vs ${this.sessionInputTokens}), charging full input`);
|
|
57038
|
+
}
|
|
57006
57039
|
this.sessionOutputTokens += outputTokens;
|
|
57007
57040
|
const pricing = this.getPricing();
|
|
57008
57041
|
const cost = incrementalInputTokens / 1e6 * pricing.inputCostPer1M + outputTokens / 1e6 * pricing.outputCostPer1M;
|
|
57009
57042
|
this.sessionTotalCost += cost;
|
|
57010
|
-
this.writeTokenFile(inputTokens, this.sessionOutputTokens);
|
|
57043
|
+
this.writeTokenFile(Math.max(inputTokens, this.sessionInputTokens), this.sessionOutputTokens, pricing.isEstimate);
|
|
57011
57044
|
}
|
|
57012
57045
|
convertMessages(claudeRequest) {
|
|
57013
57046
|
return convertMessagesToOpenAI(claudeRequest, `openai/${this.modelName}`, filterIdentity);
|
|
@@ -57158,7 +57191,7 @@ class OpenAIHandler {
|
|
|
57158
57191
|
payload.instructions = claudeRequest.system;
|
|
57159
57192
|
}
|
|
57160
57193
|
if (claudeRequest.max_tokens) {
|
|
57161
|
-
payload.max_output_tokens = claudeRequest.max_tokens;
|
|
57194
|
+
payload.max_output_tokens = Math.max(16, claudeRequest.max_tokens);
|
|
57162
57195
|
}
|
|
57163
57196
|
if (tools.length > 0) {
|
|
57164
57197
|
payload.tools = tools.map((tool) => {
|
|
@@ -57188,11 +57221,22 @@ class OpenAIHandler {
|
|
|
57188
57221
|
let outputTokens = 0;
|
|
57189
57222
|
let hasTextContent = false;
|
|
57190
57223
|
let hasToolUse = false;
|
|
57224
|
+
let lastActivity = Date.now();
|
|
57225
|
+
let pingInterval = null;
|
|
57226
|
+
let isClosed = false;
|
|
57191
57227
|
const functionCalls = new Map;
|
|
57192
57228
|
const stream = new ReadableStream({
|
|
57193
57229
|
start: async (controller) => {
|
|
57230
|
+
const send = (event, data) => {
|
|
57231
|
+
if (!isClosed) {
|
|
57232
|
+
controller.enqueue(encoder.encode(`event: ${event}
|
|
57233
|
+
data: ${JSON.stringify(data)}
|
|
57234
|
+
|
|
57235
|
+
`));
|
|
57236
|
+
}
|
|
57237
|
+
};
|
|
57194
57238
|
log(`[OpenAIHandler] Sending message_start with placeholder tokens`);
|
|
57195
|
-
|
|
57239
|
+
send("message_start", {
|
|
57196
57240
|
type: "message_start",
|
|
57197
57241
|
message: {
|
|
57198
57242
|
id: `msg_${Date.now()}`,
|
|
@@ -57204,20 +57248,19 @@ class OpenAIHandler {
|
|
|
57204
57248
|
stop_sequence: null,
|
|
57205
57249
|
usage: { input_tokens: 100, output_tokens: 1 }
|
|
57206
57250
|
}
|
|
57207
|
-
};
|
|
57208
|
-
|
|
57209
|
-
|
|
57210
|
-
|
|
57211
|
-
|
|
57212
|
-
|
|
57213
|
-
|
|
57214
|
-
|
|
57215
|
-
`));
|
|
57251
|
+
});
|
|
57252
|
+
send("ping", { type: "ping" });
|
|
57253
|
+
pingInterval = setInterval(() => {
|
|
57254
|
+
if (!isClosed && Date.now() - lastActivity > 1000) {
|
|
57255
|
+
send("ping", { type: "ping" });
|
|
57256
|
+
}
|
|
57257
|
+
}, 1000);
|
|
57216
57258
|
try {
|
|
57217
57259
|
while (true) {
|
|
57218
57260
|
const { done, value } = await reader.read();
|
|
57219
57261
|
if (done)
|
|
57220
57262
|
break;
|
|
57263
|
+
lastActivity = Date.now();
|
|
57221
57264
|
buffer += decoder.decode(value, { stream: true });
|
|
57222
57265
|
const lines = buffer.split(`
|
|
57223
57266
|
`);
|
|
@@ -57241,86 +57284,99 @@ data: {"type":"ping"}
|
|
|
57241
57284
|
}
|
|
57242
57285
|
if (event.type === "response.output_text.delta") {
|
|
57243
57286
|
if (!hasTextContent) {
|
|
57244
|
-
|
|
57287
|
+
send("content_block_start", {
|
|
57245
57288
|
type: "content_block_start",
|
|
57246
57289
|
index: blockIndex,
|
|
57247
57290
|
content_block: { type: "text", text: "" }
|
|
57248
|
-
};
|
|
57249
|
-
controller.enqueue(encoder.encode(`event: content_block_start
|
|
57250
|
-
data: ${JSON.stringify(blockStart)}
|
|
57251
|
-
|
|
57252
|
-
`));
|
|
57291
|
+
});
|
|
57253
57292
|
hasTextContent = true;
|
|
57254
57293
|
}
|
|
57255
|
-
|
|
57294
|
+
send("content_block_delta", {
|
|
57256
57295
|
type: "content_block_delta",
|
|
57257
57296
|
index: blockIndex,
|
|
57258
57297
|
delta: { type: "text_delta", text: event.delta || "" }
|
|
57259
|
-
};
|
|
57260
|
-
controller.enqueue(encoder.encode(`event: content_block_delta
|
|
57261
|
-
data: ${JSON.stringify(delta)}
|
|
57262
|
-
|
|
57263
|
-
`));
|
|
57298
|
+
});
|
|
57264
57299
|
} else if (event.type === "response.output_item.added") {
|
|
57300
|
+
if (getLogLevel() === "debug" && event.item?.type) {
|
|
57301
|
+
log(`[OpenAIHandler] Output item added: type=${event.item.type}, id=${event.item.id || event.item.call_id || "unknown"}`);
|
|
57302
|
+
}
|
|
57265
57303
|
if (event.item?.type === "function_call") {
|
|
57266
|
-
const
|
|
57304
|
+
const itemId = event.item.id;
|
|
57305
|
+
const openaiCallId = event.item.call_id || itemId;
|
|
57306
|
+
const callId = openaiCallId.startsWith("toolu_") ? openaiCallId : `toolu_${openaiCallId.replace(/^fc_/, "")}`;
|
|
57307
|
+
const fnName = event.item.name || "";
|
|
57267
57308
|
const fnIndex = blockIndex + functionCalls.size + (hasTextContent ? 1 : 0);
|
|
57268
|
-
|
|
57269
|
-
|
|
57309
|
+
log(`[OpenAIHandler] Function call: itemId=${itemId}, openaiCallId=${openaiCallId}, claudeId=${callId}, name=${fnName}, index=${fnIndex}`);
|
|
57310
|
+
const fnCallData = {
|
|
57311
|
+
name: fnName,
|
|
57270
57312
|
arguments: "",
|
|
57271
|
-
index: fnIndex
|
|
57272
|
-
|
|
57313
|
+
index: fnIndex,
|
|
57314
|
+
claudeId: callId
|
|
57315
|
+
};
|
|
57316
|
+
functionCalls.set(openaiCallId, fnCallData);
|
|
57317
|
+
if (itemId && itemId !== openaiCallId) {
|
|
57318
|
+
functionCalls.set(itemId, fnCallData);
|
|
57319
|
+
}
|
|
57273
57320
|
if (hasTextContent && !hasToolUse) {
|
|
57274
|
-
|
|
57275
|
-
controller.enqueue(encoder.encode(`event: content_block_stop
|
|
57276
|
-
data: ${JSON.stringify(blockStop)}
|
|
57277
|
-
|
|
57278
|
-
`));
|
|
57321
|
+
send("content_block_stop", { type: "content_block_stop", index: blockIndex });
|
|
57279
57322
|
blockIndex++;
|
|
57280
57323
|
}
|
|
57281
|
-
|
|
57324
|
+
send("content_block_start", {
|
|
57282
57325
|
type: "content_block_start",
|
|
57283
57326
|
index: fnIndex,
|
|
57284
57327
|
content_block: {
|
|
57285
57328
|
type: "tool_use",
|
|
57286
57329
|
id: callId,
|
|
57287
|
-
name:
|
|
57330
|
+
name: fnName,
|
|
57288
57331
|
input: {}
|
|
57289
57332
|
}
|
|
57290
|
-
};
|
|
57291
|
-
controller.enqueue(encoder.encode(`event: content_block_start
|
|
57292
|
-
data: ${JSON.stringify(toolStart)}
|
|
57293
|
-
|
|
57294
|
-
`));
|
|
57333
|
+
});
|
|
57295
57334
|
hasToolUse = true;
|
|
57335
|
+
} else if (event.item?.type === "reasoning") {
|
|
57336
|
+
log(`[OpenAIHandler] Reasoning block started`);
|
|
57337
|
+
}
|
|
57338
|
+
} else if (event.type === "response.reasoning_summary_text.delta") {
|
|
57339
|
+
if (!hasTextContent) {
|
|
57340
|
+
send("content_block_start", {
|
|
57341
|
+
type: "content_block_start",
|
|
57342
|
+
index: blockIndex,
|
|
57343
|
+
content_block: { type: "text", text: "" }
|
|
57344
|
+
});
|
|
57345
|
+
hasTextContent = true;
|
|
57296
57346
|
}
|
|
57347
|
+
send("content_block_delta", {
|
|
57348
|
+
type: "content_block_delta",
|
|
57349
|
+
index: blockIndex,
|
|
57350
|
+
delta: { type: "text_delta", text: event.delta || "" }
|
|
57351
|
+
});
|
|
57297
57352
|
} else if (event.type === "response.function_call_arguments.delta") {
|
|
57298
57353
|
const callId = event.call_id || event.item_id;
|
|
57354
|
+
if (getLogLevel() === "debug" && !functionCalls.has(callId)) {
|
|
57355
|
+
log(`[OpenAIHandler] Argument delta lookup failed: callId=${callId}, stored keys=[${Array.from(functionCalls.keys()).join(", ")}]`);
|
|
57356
|
+
}
|
|
57299
57357
|
const fnCall = functionCalls.get(callId);
|
|
57300
57358
|
if (fnCall) {
|
|
57301
57359
|
fnCall.arguments += event.delta || "";
|
|
57302
|
-
|
|
57360
|
+
send("content_block_delta", {
|
|
57303
57361
|
type: "content_block_delta",
|
|
57304
57362
|
index: fnCall.index,
|
|
57305
57363
|
delta: { type: "input_json_delta", partial_json: event.delta || "" }
|
|
57306
|
-
};
|
|
57307
|
-
controller.enqueue(encoder.encode(`event: content_block_delta
|
|
57308
|
-
data: ${JSON.stringify(delta)}
|
|
57309
|
-
|
|
57310
|
-
`));
|
|
57364
|
+
});
|
|
57311
57365
|
}
|
|
57312
57366
|
} else if (event.type === "response.output_item.done") {
|
|
57313
57367
|
if (event.item?.type === "function_call") {
|
|
57314
57368
|
const callId = event.item.call_id || event.item.id;
|
|
57315
|
-
const fnCall = functionCalls.get(callId);
|
|
57369
|
+
const fnCall = functionCalls.get(callId) || functionCalls.get(event.item.id);
|
|
57316
57370
|
if (fnCall) {
|
|
57317
|
-
|
|
57318
|
-
controller.enqueue(encoder.encode(`event: content_block_stop
|
|
57319
|
-
data: ${JSON.stringify(blockStop)}
|
|
57320
|
-
|
|
57321
|
-
`));
|
|
57371
|
+
send("content_block_stop", { type: "content_block_stop", index: fnCall.index });
|
|
57322
57372
|
}
|
|
57323
57373
|
}
|
|
57374
|
+
} else if (event.type === "response.incomplete") {
|
|
57375
|
+
log(`[OpenAIHandler] Response incomplete: ${event.reason || "unknown reason"}`);
|
|
57376
|
+
if (event.response?.usage) {
|
|
57377
|
+
inputTokens = event.response.usage.input_tokens || inputTokens;
|
|
57378
|
+
outputTokens = event.response.usage.output_tokens || outputTokens;
|
|
57379
|
+
}
|
|
57324
57380
|
} else if (event.type === "response.completed" || event.type === "response.done") {
|
|
57325
57381
|
if (event.response?.usage) {
|
|
57326
57382
|
inputTokens = event.response.usage.input_tokens || 0;
|
|
@@ -57337,31 +57393,29 @@ data: ${JSON.stringify(blockStop)}
|
|
|
57337
57393
|
}
|
|
57338
57394
|
}
|
|
57339
57395
|
}
|
|
57340
|
-
if (
|
|
57341
|
-
|
|
57342
|
-
|
|
57343
|
-
|
|
57344
|
-
|
|
57345
|
-
|
|
57396
|
+
if (pingInterval) {
|
|
57397
|
+
clearInterval(pingInterval);
|
|
57398
|
+
pingInterval = null;
|
|
57399
|
+
}
|
|
57400
|
+
if (hasTextContent) {
|
|
57401
|
+
send("content_block_stop", { type: "content_block_stop", index: blockIndex });
|
|
57346
57402
|
}
|
|
57347
57403
|
const stopReason = hasToolUse ? "tool_use" : "end_turn";
|
|
57348
|
-
|
|
57404
|
+
send("message_delta", {
|
|
57349
57405
|
type: "message_delta",
|
|
57350
57406
|
delta: { stop_reason: stopReason, stop_sequence: null },
|
|
57351
57407
|
usage: { input_tokens: inputTokens, output_tokens: outputTokens }
|
|
57352
|
-
};
|
|
57353
|
-
|
|
57354
|
-
|
|
57355
|
-
|
|
57356
|
-
`));
|
|
57357
|
-
const messageStop = { type: "message_stop" };
|
|
57358
|
-
controller.enqueue(encoder.encode(`event: message_stop
|
|
57359
|
-
data: ${JSON.stringify(messageStop)}
|
|
57360
|
-
|
|
57361
|
-
`));
|
|
57408
|
+
});
|
|
57409
|
+
send("message_stop", { type: "message_stop" });
|
|
57410
|
+
isClosed = true;
|
|
57362
57411
|
this.updateTokenTracking(inputTokens, outputTokens);
|
|
57363
57412
|
controller.close();
|
|
57364
57413
|
} catch (error46) {
|
|
57414
|
+
if (pingInterval) {
|
|
57415
|
+
clearInterval(pingInterval);
|
|
57416
|
+
pingInterval = null;
|
|
57417
|
+
}
|
|
57418
|
+
isClosed = true;
|
|
57365
57419
|
log(`[OpenAIHandler] Responses streaming error: ${error46}`);
|
|
57366
57420
|
controller.error(error46);
|
|
57367
57421
|
}
|
|
@@ -58122,310 +58176,96 @@ var init_dist11 = __esm(() => {
|
|
|
58122
58176
|
init_config();
|
|
58123
58177
|
});
|
|
58124
58178
|
|
|
58125
|
-
// src/
|
|
58126
|
-
|
|
58127
|
-
|
|
58128
|
-
|
|
58129
|
-
|
|
58130
|
-
|
|
58131
|
-
|
|
58132
|
-
|
|
58133
|
-
|
|
58134
|
-
|
|
58135
|
-
function isWindows() {
|
|
58136
|
-
return process.platform === "win32";
|
|
58137
|
-
}
|
|
58138
|
-
function createStatusLineScript(tokenFilePath) {
|
|
58139
|
-
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir();
|
|
58140
|
-
const claudishDir = join11(homeDir, ".claudish");
|
|
58141
|
-
const timestamp = Date.now();
|
|
58142
|
-
const scriptPath = join11(claudishDir, `status-${timestamp}.js`);
|
|
58143
|
-
const escapedTokenPath = tokenFilePath.replace(/\\/g, "\\\\");
|
|
58144
|
-
const script = `
|
|
58145
|
-
const fs = require('fs');
|
|
58146
|
-
const path = require('path');
|
|
58147
|
-
|
|
58148
|
-
const CYAN = "\\x1b[96m";
|
|
58149
|
-
const YELLOW = "\\x1b[93m";
|
|
58150
|
-
const GREEN = "\\x1b[92m";
|
|
58151
|
-
const MAGENTA = "\\x1b[95m";
|
|
58152
|
-
const DIM = "\\x1b[2m";
|
|
58153
|
-
const RESET = "\\x1b[0m";
|
|
58154
|
-
const BOLD = "\\x1b[1m";
|
|
58155
|
-
|
|
58156
|
-
let input = '';
|
|
58157
|
-
process.stdin.setEncoding('utf8');
|
|
58158
|
-
process.stdin.on('data', chunk => input += chunk);
|
|
58159
|
-
process.stdin.on('end', () => {
|
|
58160
|
-
try {
|
|
58161
|
-
let dir = path.basename(process.cwd());
|
|
58162
|
-
if (dir.length > 15) dir = dir.substring(0, 12) + '...';
|
|
58163
|
-
|
|
58164
|
-
let ctx = 100, cost = 0;
|
|
58165
|
-
const model = process.env.CLAUDISH_ACTIVE_MODEL_NAME || 'unknown';
|
|
58166
|
-
const isLocal = process.env.CLAUDISH_IS_LOCAL === 'true';
|
|
58167
|
-
|
|
58179
|
+
// src/model-loader.ts
|
|
58180
|
+
import { readFileSync as readFileSync5, existsSync as existsSync6 } from "node:fs";
|
|
58181
|
+
import { join as join11, dirname as dirname4 } from "node:path";
|
|
58182
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
58183
|
+
function loadModelInfo2() {
|
|
58184
|
+
if (_cachedModelInfo2) {
|
|
58185
|
+
return _cachedModelInfo2;
|
|
58186
|
+
}
|
|
58187
|
+
const jsonPath = join11(__dirname5, "../recommended-models.json");
|
|
58188
|
+
if (existsSync6(jsonPath)) {
|
|
58168
58189
|
try {
|
|
58169
|
-
const
|
|
58170
|
-
|
|
58171
|
-
|
|
58172
|
-
|
|
58173
|
-
|
|
58174
|
-
|
|
58175
|
-
|
|
58176
|
-
|
|
58190
|
+
const jsonContent = readFileSync5(jsonPath, "utf-8");
|
|
58191
|
+
const data = JSON.parse(jsonContent);
|
|
58192
|
+
const modelInfo = {};
|
|
58193
|
+
for (const model of data.models) {
|
|
58194
|
+
modelInfo[model.id] = {
|
|
58195
|
+
name: model.name,
|
|
58196
|
+
description: model.description,
|
|
58197
|
+
priority: model.priority,
|
|
58198
|
+
provider: model.provider
|
|
58199
|
+
};
|
|
58200
|
+
}
|
|
58201
|
+
modelInfo.custom = {
|
|
58202
|
+
name: "Custom Model",
|
|
58203
|
+
description: "Enter any OpenRouter model ID manually",
|
|
58204
|
+
priority: 999,
|
|
58205
|
+
provider: "Custom"
|
|
58206
|
+
};
|
|
58207
|
+
_cachedModelInfo2 = modelInfo;
|
|
58208
|
+
return modelInfo;
|
|
58209
|
+
} catch (error46) {
|
|
58210
|
+
console.error("❌ Failed to load recommended-models.json:", error46);
|
|
58211
|
+
throw new Error("Cannot load model information");
|
|
58177
58212
|
}
|
|
58178
|
-
|
|
58179
|
-
const costDisplay = isLocal ? 'LOCAL' : ('$' + cost.toFixed(3));
|
|
58180
|
-
console.log(\`\${CYAN}\${BOLD}\${dir}\${RESET} \${DIM}•\${RESET} \${YELLOW}\${model}\${RESET} \${DIM}•\${RESET} \${GREEN}\${costDisplay}\${RESET} \${DIM}•\${RESET} \${MAGENTA}\${ctx}%\${RESET}\`);
|
|
58181
|
-
} catch (e) {
|
|
58182
|
-
console.log('claudish');
|
|
58183
58213
|
}
|
|
58184
|
-
|
|
58185
|
-
`;
|
|
58186
|
-
writeFileSync10(scriptPath, script, "utf-8");
|
|
58187
|
-
return scriptPath;
|
|
58214
|
+
throw new Error("recommended-models.json not found");
|
|
58188
58215
|
}
|
|
58189
|
-
function
|
|
58190
|
-
|
|
58191
|
-
|
|
58192
|
-
try {
|
|
58193
|
-
mkdirSync8(claudishDir, { recursive: true });
|
|
58194
|
-
} catch {}
|
|
58195
|
-
const timestamp = Date.now();
|
|
58196
|
-
const tempPath = join11(claudishDir, `settings-${timestamp}.json`);
|
|
58197
|
-
const tokenFilePath = join11(claudishDir, `tokens-${port}.json`);
|
|
58198
|
-
let statusCommand;
|
|
58199
|
-
if (isWindows()) {
|
|
58200
|
-
const scriptPath = createStatusLineScript(tokenFilePath);
|
|
58201
|
-
statusCommand = `node "${scriptPath}"`;
|
|
58202
|
-
} else {
|
|
58203
|
-
const CYAN2 = "\\033[96m";
|
|
58204
|
-
const YELLOW2 = "\\033[93m";
|
|
58205
|
-
const GREEN2 = "\\033[92m";
|
|
58206
|
-
const MAGENTA = "\\033[95m";
|
|
58207
|
-
const DIM2 = "\\033[2m";
|
|
58208
|
-
const RESET2 = "\\033[0m";
|
|
58209
|
-
const BOLD2 = "\\033[1m";
|
|
58210
|
-
statusCommand = `JSON=$(cat) && DIR=$(basename "$(pwd)") && [ \${#DIR} -gt 15 ] && DIR="\${DIR:0:12}..." || true && CTX=100 && COST="0" && if [ -f "${tokenFilePath}" ]; then TOKENS=$(cat "${tokenFilePath}" 2>/dev/null) && REAL_CTX=$(echo "$TOKENS" | grep -o '"context_left_percent":[0-9]*' | grep -o '[0-9]*') && if [ ! -z "$REAL_CTX" ]; then CTX="$REAL_CTX"; fi; fi && COST=$(echo "$JSON" | grep -o '"total_cost_usd":[0-9.]*' | cut -d: -f2) && [ -z "$COST" ] && COST="0" || true && if [ "$CLAUDISH_IS_LOCAL" = "true" ]; then COST_DISPLAY="LOCAL"; else COST_DISPLAY=$(printf "\\$%.3f" "$COST"); fi && printf "${CYAN2}${BOLD2}%s${RESET2} ${DIM2}•${RESET2} ${YELLOW2}%s${RESET2} ${DIM2}•${RESET2} ${GREEN2}%s${RESET2} ${DIM2}•${RESET2} ${MAGENTA}%s%%${RESET2}\\n" "$DIR" "$CLAUDISH_ACTIVE_MODEL_NAME" "$COST_DISPLAY" "$CTX"`;
|
|
58216
|
+
function getAvailableModels() {
|
|
58217
|
+
if (_cachedModelIds) {
|
|
58218
|
+
return _cachedModelIds;
|
|
58211
58219
|
}
|
|
58212
|
-
const
|
|
58213
|
-
|
|
58214
|
-
|
|
58215
|
-
|
|
58216
|
-
|
|
58220
|
+
const jsonPath = join11(__dirname5, "../recommended-models.json");
|
|
58221
|
+
if (existsSync6(jsonPath)) {
|
|
58222
|
+
try {
|
|
58223
|
+
const jsonContent = readFileSync5(jsonPath, "utf-8");
|
|
58224
|
+
const data = JSON.parse(jsonContent);
|
|
58225
|
+
const modelIds = data.models.sort((a, b) => a.priority - b.priority).map((m) => m.id);
|
|
58226
|
+
const result = [...modelIds, "custom"];
|
|
58227
|
+
_cachedModelIds = result;
|
|
58228
|
+
return result;
|
|
58229
|
+
} catch (error46) {
|
|
58230
|
+
console.error("❌ Failed to load model list from JSON:", error46);
|
|
58231
|
+
throw new Error("Cannot load model list");
|
|
58217
58232
|
}
|
|
58218
|
-
}
|
|
58219
|
-
|
|
58220
|
-
return tempPath;
|
|
58233
|
+
}
|
|
58234
|
+
throw new Error("recommended-models.json not found");
|
|
58221
58235
|
}
|
|
58222
|
-
|
|
58223
|
-
|
|
58224
|
-
|
|
58225
|
-
|
|
58226
|
-
|
|
58227
|
-
|
|
58228
|
-
|
|
58229
|
-
|
|
58230
|
-
|
|
58231
|
-
|
|
58232
|
-
|
|
58233
|
-
|
|
58234
|
-
|
|
58235
|
-
|
|
58236
|
-
|
|
58237
|
-
|
|
58238
|
-
|
|
58239
|
-
|
|
58240
|
-
|
|
58241
|
-
|
|
58242
|
-
|
|
58243
|
-
|
|
58244
|
-
|
|
58245
|
-
|
|
58246
|
-
|
|
58247
|
-
if (
|
|
58248
|
-
|
|
58249
|
-
|
|
58250
|
-
|
|
58251
|
-
claudeArgs.push(...modifiedArgs);
|
|
58236
|
+
var __filename5, __dirname5, _cachedModelInfo2 = null, _cachedModelIds = null;
|
|
58237
|
+
var init_model_loader2 = __esm(() => {
|
|
58238
|
+
__filename5 = fileURLToPath4(import.meta.url);
|
|
58239
|
+
__dirname5 = dirname4(__filename5);
|
|
58240
|
+
});
|
|
58241
|
+
|
|
58242
|
+
// src/utils.ts
|
|
58243
|
+
function fuzzyScore2(text, query) {
|
|
58244
|
+
if (!text || !query)
|
|
58245
|
+
return 0;
|
|
58246
|
+
const t = text.toLowerCase();
|
|
58247
|
+
const q = query.toLowerCase();
|
|
58248
|
+
if (t === q)
|
|
58249
|
+
return 1;
|
|
58250
|
+
if (t.startsWith(q))
|
|
58251
|
+
return 0.9;
|
|
58252
|
+
if (t.includes(` ${q}`) || t.includes(`-${q}`) || t.includes(`/${q}`))
|
|
58253
|
+
return 0.8;
|
|
58254
|
+
if (t.includes(q))
|
|
58255
|
+
return 0.6;
|
|
58256
|
+
let score = 0;
|
|
58257
|
+
let tIdx = 0;
|
|
58258
|
+
let qIdx = 0;
|
|
58259
|
+
let consecutive = 0;
|
|
58260
|
+
while (tIdx < t.length && qIdx < q.length) {
|
|
58261
|
+
if (t[tIdx] === q[qIdx]) {
|
|
58262
|
+
score += 1 + consecutive * 0.5;
|
|
58263
|
+
consecutive++;
|
|
58264
|
+
qIdx++;
|
|
58252
58265
|
} else {
|
|
58253
|
-
|
|
58266
|
+
consecutive = 0;
|
|
58254
58267
|
}
|
|
58255
|
-
|
|
58256
|
-
const isLocalModel = modelId.startsWith("ollama/") || modelId.startsWith("ollama:") || modelId.startsWith("lmstudio/") || modelId.startsWith("lmstudio:") || modelId.startsWith("vllm/") || modelId.startsWith("vllm:") || modelId.startsWith("mlx/") || modelId.startsWith("mlx:") || modelId.startsWith("http://") || modelId.startsWith("https://");
|
|
58257
|
-
const env = {
|
|
58258
|
-
...process.env,
|
|
58259
|
-
ANTHROPIC_BASE_URL: proxyUrl,
|
|
58260
|
-
[ENV.CLAUDISH_ACTIVE_MODEL_NAME]: modelId,
|
|
58261
|
-
CLAUDISH_IS_LOCAL: isLocalModel ? "true" : "false",
|
|
58262
|
-
[ENV.ANTHROPIC_MODEL]: modelId,
|
|
58263
|
-
[ENV.ANTHROPIC_SMALL_FAST_MODEL]: modelId
|
|
58264
|
-
};
|
|
58265
|
-
if (config3.monitor) {
|
|
58266
|
-
delete env.ANTHROPIC_API_KEY;
|
|
58267
|
-
} else {
|
|
58268
|
-
env.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || "sk-ant-api03-placeholder-not-used-proxy-handles-auth-with-openrouter-key-xxxxxxxxxxxxxxxxxxxxx";
|
|
58269
|
-
}
|
|
58270
|
-
const log2 = (message) => {
|
|
58271
|
-
if (!config3.quiet) {
|
|
58272
|
-
console.log(message);
|
|
58273
|
-
}
|
|
58274
|
-
};
|
|
58275
|
-
if (config3.interactive) {
|
|
58276
|
-
log2(`
|
|
58277
|
-
[claudish] Model: ${modelId}
|
|
58278
|
-
`);
|
|
58279
|
-
} else {
|
|
58280
|
-
log2(`
|
|
58281
|
-
[claudish] Model: ${modelId}`);
|
|
58282
|
-
log2(`[claudish] Arguments: ${claudeArgs.join(" ")}
|
|
58283
|
-
`);
|
|
58284
|
-
}
|
|
58285
|
-
const proc = spawn("claude", claudeArgs, {
|
|
58286
|
-
env,
|
|
58287
|
-
stdio: "inherit",
|
|
58288
|
-
shell: isWindows()
|
|
58289
|
-
});
|
|
58290
|
-
setupSignalHandlers(proc, tempSettingsPath, config3.quiet);
|
|
58291
|
-
const exitCode = await new Promise((resolve) => {
|
|
58292
|
-
proc.on("exit", (code) => {
|
|
58293
|
-
resolve(code ?? 1);
|
|
58294
|
-
});
|
|
58295
|
-
});
|
|
58296
|
-
try {
|
|
58297
|
-
unlinkSync(tempSettingsPath);
|
|
58298
|
-
} catch (error46) {}
|
|
58299
|
-
return exitCode;
|
|
58300
|
-
}
|
|
58301
|
-
function setupSignalHandlers(proc, tempSettingsPath, quiet) {
|
|
58302
|
-
const signals2 = isWindows() ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
58303
|
-
for (const signal of signals2) {
|
|
58304
|
-
process.on(signal, () => {
|
|
58305
|
-
if (!quiet) {
|
|
58306
|
-
console.log(`
|
|
58307
|
-
[claudish] Received ${signal}, shutting down...`);
|
|
58308
|
-
}
|
|
58309
|
-
proc.kill();
|
|
58310
|
-
try {
|
|
58311
|
-
unlinkSync(tempSettingsPath);
|
|
58312
|
-
} catch {}
|
|
58313
|
-
process.exit(0);
|
|
58314
|
-
});
|
|
58315
|
-
}
|
|
58316
|
-
}
|
|
58317
|
-
async function checkClaudeInstalled() {
|
|
58318
|
-
try {
|
|
58319
|
-
const isWindows2 = process.platform === "win32";
|
|
58320
|
-
const command = isWindows2 ? "where" : "which";
|
|
58321
|
-
const proc = spawn(command, ["claude"], {
|
|
58322
|
-
stdio: "ignore",
|
|
58323
|
-
shell: isWindows2
|
|
58324
|
-
});
|
|
58325
|
-
const exitCode = await new Promise((resolve) => {
|
|
58326
|
-
proc.on("exit", (code) => {
|
|
58327
|
-
resolve(code ?? 1);
|
|
58328
|
-
});
|
|
58329
|
-
});
|
|
58330
|
-
return exitCode === 0;
|
|
58331
|
-
} catch {
|
|
58332
|
-
return false;
|
|
58333
|
-
}
|
|
58334
|
-
}
|
|
58335
|
-
var init_claude_runner = __esm(() => {
|
|
58336
|
-
init_dist11();
|
|
58337
|
-
});
|
|
58338
|
-
|
|
58339
|
-
// src/model-loader.ts
|
|
58340
|
-
import { readFileSync as readFileSync5, existsSync as existsSync6 } from "node:fs";
|
|
58341
|
-
import { join as join12, dirname as dirname4 } from "node:path";
|
|
58342
|
-
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
58343
|
-
function loadModelInfo2() {
|
|
58344
|
-
if (_cachedModelInfo2) {
|
|
58345
|
-
return _cachedModelInfo2;
|
|
58346
|
-
}
|
|
58347
|
-
const jsonPath = join12(__dirname5, "../recommended-models.json");
|
|
58348
|
-
if (existsSync6(jsonPath)) {
|
|
58349
|
-
try {
|
|
58350
|
-
const jsonContent = readFileSync5(jsonPath, "utf-8");
|
|
58351
|
-
const data = JSON.parse(jsonContent);
|
|
58352
|
-
const modelInfo = {};
|
|
58353
|
-
for (const model of data.models) {
|
|
58354
|
-
modelInfo[model.id] = {
|
|
58355
|
-
name: model.name,
|
|
58356
|
-
description: model.description,
|
|
58357
|
-
priority: model.priority,
|
|
58358
|
-
provider: model.provider
|
|
58359
|
-
};
|
|
58360
|
-
}
|
|
58361
|
-
modelInfo.custom = {
|
|
58362
|
-
name: "Custom Model",
|
|
58363
|
-
description: "Enter any OpenRouter model ID manually",
|
|
58364
|
-
priority: 999,
|
|
58365
|
-
provider: "Custom"
|
|
58366
|
-
};
|
|
58367
|
-
_cachedModelInfo2 = modelInfo;
|
|
58368
|
-
return modelInfo;
|
|
58369
|
-
} catch (error46) {
|
|
58370
|
-
console.error("❌ Failed to load recommended-models.json:", error46);
|
|
58371
|
-
throw new Error("Cannot load model information");
|
|
58372
|
-
}
|
|
58373
|
-
}
|
|
58374
|
-
throw new Error("recommended-models.json not found");
|
|
58375
|
-
}
|
|
58376
|
-
function getAvailableModels() {
|
|
58377
|
-
if (_cachedModelIds) {
|
|
58378
|
-
return _cachedModelIds;
|
|
58379
|
-
}
|
|
58380
|
-
const jsonPath = join12(__dirname5, "../recommended-models.json");
|
|
58381
|
-
if (existsSync6(jsonPath)) {
|
|
58382
|
-
try {
|
|
58383
|
-
const jsonContent = readFileSync5(jsonPath, "utf-8");
|
|
58384
|
-
const data = JSON.parse(jsonContent);
|
|
58385
|
-
const modelIds = data.models.sort((a, b) => a.priority - b.priority).map((m) => m.id);
|
|
58386
|
-
const result = [...modelIds, "custom"];
|
|
58387
|
-
_cachedModelIds = result;
|
|
58388
|
-
return result;
|
|
58389
|
-
} catch (error46) {
|
|
58390
|
-
console.error("❌ Failed to load model list from JSON:", error46);
|
|
58391
|
-
throw new Error("Cannot load model list");
|
|
58392
|
-
}
|
|
58393
|
-
}
|
|
58394
|
-
throw new Error("recommended-models.json not found");
|
|
58395
|
-
}
|
|
58396
|
-
var __filename5, __dirname5, _cachedModelInfo2 = null, _cachedModelIds = null;
|
|
58397
|
-
var init_model_loader2 = __esm(() => {
|
|
58398
|
-
__filename5 = fileURLToPath4(import.meta.url);
|
|
58399
|
-
__dirname5 = dirname4(__filename5);
|
|
58400
|
-
});
|
|
58401
|
-
|
|
58402
|
-
// src/utils.ts
|
|
58403
|
-
function fuzzyScore2(text, query) {
|
|
58404
|
-
if (!text || !query)
|
|
58405
|
-
return 0;
|
|
58406
|
-
const t = text.toLowerCase();
|
|
58407
|
-
const q = query.toLowerCase();
|
|
58408
|
-
if (t === q)
|
|
58409
|
-
return 1;
|
|
58410
|
-
if (t.startsWith(q))
|
|
58411
|
-
return 0.9;
|
|
58412
|
-
if (t.includes(` ${q}`) || t.includes(`-${q}`) || t.includes(`/${q}`))
|
|
58413
|
-
return 0.8;
|
|
58414
|
-
if (t.includes(q))
|
|
58415
|
-
return 0.6;
|
|
58416
|
-
let score = 0;
|
|
58417
|
-
let tIdx = 0;
|
|
58418
|
-
let qIdx = 0;
|
|
58419
|
-
let consecutive = 0;
|
|
58420
|
-
while (tIdx < t.length && qIdx < q.length) {
|
|
58421
|
-
if (t[tIdx] === q[qIdx]) {
|
|
58422
|
-
score += 1 + consecutive * 0.5;
|
|
58423
|
-
consecutive++;
|
|
58424
|
-
qIdx++;
|
|
58425
|
-
} else {
|
|
58426
|
-
consecutive = 0;
|
|
58427
|
-
}
|
|
58428
|
-
tIdx++;
|
|
58268
|
+
tIdx++;
|
|
58429
58269
|
}
|
|
58430
58270
|
if (qIdx === q.length) {
|
|
58431
58271
|
const compactness = q.length / (tIdx + 1);
|
|
@@ -58440,9 +58280,9 @@ __export(exports_cli, {
|
|
|
58440
58280
|
parseArgs: () => parseArgs,
|
|
58441
58281
|
getVersion: () => getVersion
|
|
58442
58282
|
});
|
|
58443
|
-
import { readFileSync as readFileSync6, writeFileSync as
|
|
58283
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync10, existsSync as existsSync7, mkdirSync as mkdirSync8, copyFileSync } from "node:fs";
|
|
58444
58284
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
58445
|
-
import { dirname as dirname5, join as
|
|
58285
|
+
import { dirname as dirname5, join as join12 } from "node:path";
|
|
58446
58286
|
function getVersion() {
|
|
58447
58287
|
return VERSION;
|
|
58448
58288
|
}
|
|
@@ -58734,7 +58574,7 @@ async function searchAndPrintModels(query, forceUpdate) {
|
|
|
58734
58574
|
throw new Error(`API returned ${response.status}`);
|
|
58735
58575
|
const data = await response.json();
|
|
58736
58576
|
models = data.data;
|
|
58737
|
-
|
|
58577
|
+
writeFileSync10(ALL_MODELS_JSON_PATH2, JSON.stringify({
|
|
58738
58578
|
lastUpdated: new Date().toISOString(),
|
|
58739
58579
|
models
|
|
58740
58580
|
}), "utf-8");
|
|
@@ -58835,7 +58675,7 @@ async function printAllModels(jsonOutput, forceUpdate) {
|
|
|
58835
58675
|
throw new Error(`API returned ${response.status}`);
|
|
58836
58676
|
const data = await response.json();
|
|
58837
58677
|
models = data.data;
|
|
58838
|
-
|
|
58678
|
+
writeFileSync10(ALL_MODELS_JSON_PATH2, JSON.stringify({
|
|
58839
58679
|
lastUpdated: new Date().toISOString(),
|
|
58840
58680
|
models
|
|
58841
58681
|
}), "utf-8");
|
|
@@ -59056,7 +58896,7 @@ async function updateModelsFromOpenRouter() {
|
|
|
59056
58896
|
source: "https://openrouter.ai/models?categories=programming&fmt=cards&order=top-weekly",
|
|
59057
58897
|
models: recommendations
|
|
59058
58898
|
};
|
|
59059
|
-
|
|
58899
|
+
writeFileSync10(MODELS_JSON_PATH, JSON.stringify(updatedData, null, 2), "utf-8");
|
|
59060
58900
|
console.error(`✅ Updated ${recommendations.length} models (last updated: ${updatedData.lastUpdated})`);
|
|
59061
58901
|
} catch (error46) {
|
|
59062
58902
|
console.error(`❌ Failed to update models: ${error46 instanceof Error ? error46.message : String(error46)}`);
|
|
@@ -59140,6 +58980,9 @@ PROFILE MANAGEMENT:
|
|
|
59140
58980
|
claudish profile show Show profile details (default profile or claudish profile show <name>)
|
|
59141
58981
|
claudish profile edit Edit a profile (interactive or claudish profile edit <name>)
|
|
59142
58982
|
|
|
58983
|
+
UPDATE:
|
|
58984
|
+
claudish update Check for updates and install latest version
|
|
58985
|
+
|
|
59143
58986
|
MODEL MAPPING (per-role override):
|
|
59144
58987
|
--model-opus <model> Model for Opus role (planning, complex tasks)
|
|
59145
58988
|
--model-sonnet <model> Model for Sonnet role (default coding)
|
|
@@ -59299,7 +59142,7 @@ MORE INFO:
|
|
|
59299
59142
|
}
|
|
59300
59143
|
function printAIAgentGuide() {
|
|
59301
59144
|
try {
|
|
59302
|
-
const guidePath =
|
|
59145
|
+
const guidePath = join12(__dirname6, "../AI_AGENT_GUIDE.md");
|
|
59303
59146
|
const guideContent = readFileSync6(guidePath, "utf-8");
|
|
59304
59147
|
console.log(guideContent);
|
|
59305
59148
|
} catch (error46) {
|
|
@@ -59316,10 +59159,10 @@ async function initializeClaudishSkill() {
|
|
|
59316
59159
|
console.log(`\uD83D\uDD27 Initializing Claudish skill in current project...
|
|
59317
59160
|
`);
|
|
59318
59161
|
const cwd = process.cwd();
|
|
59319
|
-
const claudeDir =
|
|
59320
|
-
const skillsDir =
|
|
59321
|
-
const claudishSkillDir =
|
|
59322
|
-
const skillFile =
|
|
59162
|
+
const claudeDir = join12(cwd, ".claude");
|
|
59163
|
+
const skillsDir = join12(claudeDir, "skills");
|
|
59164
|
+
const claudishSkillDir = join12(skillsDir, "claudish-usage");
|
|
59165
|
+
const skillFile = join12(claudishSkillDir, "SKILL.md");
|
|
59323
59166
|
if (existsSync7(skillFile)) {
|
|
59324
59167
|
console.log("✅ Claudish skill already installed at:");
|
|
59325
59168
|
console.log(` ${skillFile}
|
|
@@ -59327,7 +59170,7 @@ async function initializeClaudishSkill() {
|
|
|
59327
59170
|
console.log("\uD83D\uDCA1 To reinstall, delete the file and run 'claudish --init' again.");
|
|
59328
59171
|
return;
|
|
59329
59172
|
}
|
|
59330
|
-
const sourceSkillPath =
|
|
59173
|
+
const sourceSkillPath = join12(__dirname6, "../skills/claudish-usage/SKILL.md");
|
|
59331
59174
|
if (!existsSync7(sourceSkillPath)) {
|
|
59332
59175
|
console.error("❌ Error: Claudish skill file not found in installation.");
|
|
59333
59176
|
console.error(` Expected at: ${sourceSkillPath}`);
|
|
@@ -59338,15 +59181,15 @@ async function initializeClaudishSkill() {
|
|
|
59338
59181
|
}
|
|
59339
59182
|
try {
|
|
59340
59183
|
if (!existsSync7(claudeDir)) {
|
|
59341
|
-
|
|
59184
|
+
mkdirSync8(claudeDir, { recursive: true });
|
|
59342
59185
|
console.log("\uD83D\uDCC1 Created .claude/ directory");
|
|
59343
59186
|
}
|
|
59344
59187
|
if (!existsSync7(skillsDir)) {
|
|
59345
|
-
|
|
59188
|
+
mkdirSync8(skillsDir, { recursive: true });
|
|
59346
59189
|
console.log("\uD83D\uDCC1 Created .claude/skills/ directory");
|
|
59347
59190
|
}
|
|
59348
59191
|
if (!existsSync7(claudishSkillDir)) {
|
|
59349
|
-
|
|
59192
|
+
mkdirSync8(claudishSkillDir, { recursive: true });
|
|
59350
59193
|
console.log("\uD83D\uDCC1 Created .claude/skills/claudish-usage/ directory");
|
|
59351
59194
|
}
|
|
59352
59195
|
copyFileSync(sourceSkillPath, skillFile);
|
|
@@ -59440,7 +59283,7 @@ Force update: claudish --list-models --force-update
|
|
|
59440
59283
|
`);
|
|
59441
59284
|
}
|
|
59442
59285
|
function printAvailableModelsJSON() {
|
|
59443
|
-
const jsonPath =
|
|
59286
|
+
const jsonPath = join12(__dirname6, "../recommended-models.json");
|
|
59444
59287
|
try {
|
|
59445
59288
|
const jsonContent = readFileSync6(jsonPath, "utf-8");
|
|
59446
59289
|
const data = JSON.parse(jsonContent);
|
|
@@ -59474,72 +59317,41 @@ var init_cli = __esm(() => {
|
|
|
59474
59317
|
__filename6 = fileURLToPath5(import.meta.url);
|
|
59475
59318
|
__dirname6 = dirname5(__filename6);
|
|
59476
59319
|
try {
|
|
59477
|
-
const packageJson = JSON.parse(readFileSync6(
|
|
59320
|
+
const packageJson = JSON.parse(readFileSync6(join12(__dirname6, "../package.json"), "utf-8"));
|
|
59478
59321
|
VERSION = packageJson.version;
|
|
59479
59322
|
} catch {}
|
|
59480
|
-
MODELS_JSON_PATH =
|
|
59481
|
-
ALL_MODELS_JSON_PATH2 =
|
|
59482
|
-
});
|
|
59483
|
-
|
|
59484
|
-
// src/port-manager.ts
|
|
59485
|
-
var exports_port_manager = {};
|
|
59486
|
-
__export(exports_port_manager, {
|
|
59487
|
-
isPortAvailable: () => isPortAvailable,
|
|
59488
|
-
findAvailablePort: () => findAvailablePort
|
|
59323
|
+
MODELS_JSON_PATH = join12(__dirname6, "../recommended-models.json");
|
|
59324
|
+
ALL_MODELS_JSON_PATH2 = join12(__dirname6, "../all-models.json");
|
|
59489
59325
|
});
|
|
59490
|
-
import { createServer } from "node:net";
|
|
59491
|
-
async function findAvailablePort(startPort = 3000, endPort = 9000) {
|
|
59492
|
-
const randomPort = Math.floor(Math.random() * (endPort - startPort + 1)) + startPort;
|
|
59493
|
-
if (await isPortAvailable(randomPort)) {
|
|
59494
|
-
return randomPort;
|
|
59495
|
-
}
|
|
59496
|
-
for (let port = startPort;port <= endPort; port++) {
|
|
59497
|
-
if (await isPortAvailable(port)) {
|
|
59498
|
-
return port;
|
|
59499
|
-
}
|
|
59500
|
-
}
|
|
59501
|
-
throw new Error(`No available ports found in range ${startPort}-${endPort}`);
|
|
59502
|
-
}
|
|
59503
|
-
async function isPortAvailable(port) {
|
|
59504
|
-
return new Promise((resolve) => {
|
|
59505
|
-
const server = createServer();
|
|
59506
|
-
server.once("error", (err) => {
|
|
59507
|
-
resolve(err.code !== "EADDRINUSE");
|
|
59508
|
-
});
|
|
59509
|
-
server.once("listening", () => {
|
|
59510
|
-
server.close();
|
|
59511
|
-
resolve(true);
|
|
59512
|
-
});
|
|
59513
|
-
server.listen(port, "127.0.0.1");
|
|
59514
|
-
});
|
|
59515
|
-
}
|
|
59516
|
-
var init_port_manager = () => {};
|
|
59517
59326
|
|
|
59518
59327
|
// src/update-checker.ts
|
|
59519
59328
|
var exports_update_checker = {};
|
|
59520
59329
|
__export(exports_update_checker, {
|
|
59330
|
+
fetchLatestVersion: () => fetchLatestVersion,
|
|
59331
|
+
compareVersions: () => compareVersions,
|
|
59332
|
+
clearCache: () => clearCache,
|
|
59521
59333
|
checkForUpdates: () => checkForUpdates
|
|
59522
59334
|
});
|
|
59523
59335
|
import { execSync } from "node:child_process";
|
|
59336
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync9, readFileSync as readFileSync7, unlinkSync, writeFileSync as writeFileSync11 } from "node:fs";
|
|
59337
|
+
import { homedir as homedir7, platform, tmpdir } from "node:os";
|
|
59338
|
+
import { join as join13 } from "node:path";
|
|
59524
59339
|
import { createInterface as createInterface2 } from "node:readline";
|
|
59525
|
-
import { existsSync as existsSync8, readFileSync as readFileSync7, writeFileSync as writeFileSync12, mkdirSync as mkdirSync10, unlinkSync as unlinkSync2 } from "node:fs";
|
|
59526
|
-
import { join as join14 } from "node:path";
|
|
59527
|
-
import { tmpdir as tmpdir2, homedir as homedir7, platform } from "node:os";
|
|
59528
59340
|
function getCacheFilePath() {
|
|
59529
59341
|
let cacheDir;
|
|
59530
|
-
if (
|
|
59531
|
-
const localAppData = process.env.LOCALAPPDATA ||
|
|
59532
|
-
cacheDir =
|
|
59342
|
+
if (isWindows) {
|
|
59343
|
+
const localAppData = process.env.LOCALAPPDATA || join13(homedir7(), "AppData", "Local");
|
|
59344
|
+
cacheDir = join13(localAppData, "claudish");
|
|
59533
59345
|
} else {
|
|
59534
|
-
cacheDir =
|
|
59346
|
+
cacheDir = join13(homedir7(), ".cache", "claudish");
|
|
59535
59347
|
}
|
|
59536
59348
|
try {
|
|
59537
59349
|
if (!existsSync8(cacheDir)) {
|
|
59538
|
-
|
|
59350
|
+
mkdirSync9(cacheDir, { recursive: true });
|
|
59539
59351
|
}
|
|
59540
|
-
return
|
|
59352
|
+
return join13(cacheDir, "update-check.json");
|
|
59541
59353
|
} catch {
|
|
59542
|
-
return
|
|
59354
|
+
return join13(tmpdir(), "claudish-update-check.json");
|
|
59543
59355
|
}
|
|
59544
59356
|
}
|
|
59545
59357
|
function readCache() {
|
|
@@ -59561,7 +59373,7 @@ function writeCache(latestVersion) {
|
|
|
59561
59373
|
lastCheck: Date.now(),
|
|
59562
59374
|
latestVersion
|
|
59563
59375
|
};
|
|
59564
|
-
|
|
59376
|
+
writeFileSync11(cachePath, JSON.stringify(data), "utf-8");
|
|
59565
59377
|
} catch {}
|
|
59566
59378
|
}
|
|
59567
59379
|
function isCacheValid(cache) {
|
|
@@ -59572,7 +59384,7 @@ function clearCache() {
|
|
|
59572
59384
|
try {
|
|
59573
59385
|
const cachePath = getCacheFilePath();
|
|
59574
59386
|
if (existsSync8(cachePath)) {
|
|
59575
|
-
|
|
59387
|
+
unlinkSync(cachePath);
|
|
59576
59388
|
}
|
|
59577
59389
|
} catch {}
|
|
59578
59390
|
}
|
|
@@ -59625,10 +59437,9 @@ function runUpdate() {
|
|
|
59625
59437
|
console.error(`
|
|
59626
59438
|
[claudish] Updating...
|
|
59627
59439
|
`);
|
|
59628
|
-
|
|
59440
|
+
execSync("npm install -g claudish@latest", {
|
|
59629
59441
|
stdio: "inherit",
|
|
59630
|
-
|
|
59631
|
-
shell: true
|
|
59442
|
+
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
|
|
59632
59443
|
});
|
|
59633
59444
|
console.error(`
|
|
59634
59445
|
[claudish] Update complete! Please restart claudish.
|
|
@@ -59688,12 +59499,397 @@ async function checkForUpdates(currentVersion, options = {}) {
|
|
|
59688
59499
|
}
|
|
59689
59500
|
return false;
|
|
59690
59501
|
}
|
|
59691
|
-
var
|
|
59502
|
+
var isWindows, NPM_REGISTRY_URL = "https://registry.npmjs.org/claudish/latest", CACHE_MAX_AGE_MS;
|
|
59692
59503
|
var init_update_checker = __esm(() => {
|
|
59693
|
-
|
|
59504
|
+
isWindows = platform() === "win32";
|
|
59694
59505
|
CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
59695
59506
|
});
|
|
59696
59507
|
|
|
59508
|
+
// src/update-command.ts
|
|
59509
|
+
var exports_update_command = {};
|
|
59510
|
+
__export(exports_update_command, {
|
|
59511
|
+
updateCommand: () => updateCommand
|
|
59512
|
+
});
|
|
59513
|
+
import { execSync as execSync2 } from "node:child_process";
|
|
59514
|
+
import { createInterface as createInterface3 } from "node:readline";
|
|
59515
|
+
function detectInstallationMethod() {
|
|
59516
|
+
const scriptPath = process.argv[1] || "";
|
|
59517
|
+
if (scriptPath.includes("/opt/homebrew/") || scriptPath.includes("/usr/local/Cellar/")) {
|
|
59518
|
+
return { method: "brew", path: scriptPath };
|
|
59519
|
+
}
|
|
59520
|
+
if (scriptPath.includes("/.bun/")) {
|
|
59521
|
+
return { method: "bun", path: scriptPath };
|
|
59522
|
+
}
|
|
59523
|
+
if (scriptPath.includes("/node_modules/") || scriptPath.includes("/nvm/") || scriptPath.includes("/npm/")) {
|
|
59524
|
+
return { method: "npm", path: scriptPath };
|
|
59525
|
+
}
|
|
59526
|
+
return { method: "unknown", path: scriptPath };
|
|
59527
|
+
}
|
|
59528
|
+
function getUpdateCommand(method) {
|
|
59529
|
+
switch (method) {
|
|
59530
|
+
case "npm":
|
|
59531
|
+
return "npm install -g claudish@latest";
|
|
59532
|
+
case "bun":
|
|
59533
|
+
return "bun update -g claudish";
|
|
59534
|
+
case "brew":
|
|
59535
|
+
return "brew upgrade claudish";
|
|
59536
|
+
case "unknown":
|
|
59537
|
+
return "";
|
|
59538
|
+
}
|
|
59539
|
+
}
|
|
59540
|
+
function promptUser2(question) {
|
|
59541
|
+
return new Promise((resolve) => {
|
|
59542
|
+
const rl = createInterface3({
|
|
59543
|
+
input: process.stdin,
|
|
59544
|
+
output: process.stdout
|
|
59545
|
+
});
|
|
59546
|
+
rl.question(question, (answer) => {
|
|
59547
|
+
rl.close();
|
|
59548
|
+
const normalized = answer.toLowerCase().trim();
|
|
59549
|
+
resolve(normalized === "y" || normalized === "yes" || normalized === "");
|
|
59550
|
+
});
|
|
59551
|
+
});
|
|
59552
|
+
}
|
|
59553
|
+
async function executeUpdate(command) {
|
|
59554
|
+
try {
|
|
59555
|
+
console.log(`
|
|
59556
|
+
${BOLD2}Updating...${RESET2}
|
|
59557
|
+
`);
|
|
59558
|
+
execSync2(command, {
|
|
59559
|
+
stdio: "inherit",
|
|
59560
|
+
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
|
|
59561
|
+
});
|
|
59562
|
+
console.log(`
|
|
59563
|
+
${GREEN2}✓${RESET2} ${BOLD2}Update complete!${RESET2}`);
|
|
59564
|
+
console.log(`${CYAN2}Please restart any running claudish sessions.${RESET2}
|
|
59565
|
+
`);
|
|
59566
|
+
return true;
|
|
59567
|
+
} catch (error46) {
|
|
59568
|
+
console.error(`
|
|
59569
|
+
${RED}✗${RESET2} ${BOLD2}Update failed.${RESET2}`);
|
|
59570
|
+
console.error(`${YELLOW2}Try manually:${RESET2}`);
|
|
59571
|
+
console.error(` ${command}
|
|
59572
|
+
`);
|
|
59573
|
+
return false;
|
|
59574
|
+
}
|
|
59575
|
+
}
|
|
59576
|
+
function printManualInstructions() {
|
|
59577
|
+
console.log(`
|
|
59578
|
+
${BOLD2}Unable to detect installation method.${RESET2}`);
|
|
59579
|
+
console.log(`${YELLOW2}Please update manually:${RESET2}
|
|
59580
|
+
`);
|
|
59581
|
+
console.log(` ${CYAN2}npm:${RESET2} npm install -g claudish@latest`);
|
|
59582
|
+
console.log(` ${CYAN2}bun:${RESET2} bun install -g claudish@latest`);
|
|
59583
|
+
console.log(` ${CYAN2}brew:${RESET2} brew upgrade claudish ${RED}(not yet available)${RESET2}
|
|
59584
|
+
`);
|
|
59585
|
+
}
|
|
59586
|
+
async function updateCommand() {
|
|
59587
|
+
console.log(`
|
|
59588
|
+
${BOLD2}Checking for updates...${RESET2}
|
|
59589
|
+
`);
|
|
59590
|
+
const currentVersion = getVersion();
|
|
59591
|
+
const latestVersion = await fetchLatestVersion();
|
|
59592
|
+
if (!latestVersion) {
|
|
59593
|
+
console.error(`${RED}✗${RESET2} Unable to fetch latest version from npm registry.`);
|
|
59594
|
+
console.error(`${YELLOW2}Please check your internet connection and try again.${RESET2}
|
|
59595
|
+
`);
|
|
59596
|
+
process.exit(1);
|
|
59597
|
+
}
|
|
59598
|
+
const comparison = compareVersions(latestVersion, currentVersion);
|
|
59599
|
+
if (comparison <= 0) {
|
|
59600
|
+
console.log(`${GREEN2}✓${RESET2} ${BOLD2}Already up-to-date!${RESET2}`);
|
|
59601
|
+
console.log(`${CYAN2}Current version: ${currentVersion}${RESET2}
|
|
59602
|
+
`);
|
|
59603
|
+
process.exit(0);
|
|
59604
|
+
}
|
|
59605
|
+
console.log(`${BOLD2}Current version:${RESET2} ${YELLOW2}${currentVersion}${RESET2}`);
|
|
59606
|
+
console.log(`${BOLD2}Latest version:${RESET2} ${GREEN2}${latestVersion}${RESET2}
|
|
59607
|
+
`);
|
|
59608
|
+
const installInfo = detectInstallationMethod();
|
|
59609
|
+
if (installInfo.method === "unknown") {
|
|
59610
|
+
printManualInstructions();
|
|
59611
|
+
process.exit(1);
|
|
59612
|
+
}
|
|
59613
|
+
console.log(`${BOLD2}Detected installation method:${RESET2} ${CYAN2}${installInfo.method}${RESET2}`);
|
|
59614
|
+
const command = getUpdateCommand(installInfo.method);
|
|
59615
|
+
if (installInfo.method === "brew") {
|
|
59616
|
+
console.log(`${RED}Note: Homebrew formula not yet published.${RESET2}
|
|
59617
|
+
`);
|
|
59618
|
+
printManualInstructions();
|
|
59619
|
+
process.exit(1);
|
|
59620
|
+
}
|
|
59621
|
+
console.log(`${BOLD2}Update command:${RESET2} ${command}
|
|
59622
|
+
`);
|
|
59623
|
+
const shouldUpdate = await promptUser2(`${BOLD2}Proceed with update? [Y/n]${RESET2} `);
|
|
59624
|
+
if (!shouldUpdate) {
|
|
59625
|
+
console.log(`
|
|
59626
|
+
${YELLOW2}Update cancelled.${RESET2}`);
|
|
59627
|
+
console.log(`${CYAN2}Update later with: ${command}${RESET2}
|
|
59628
|
+
`);
|
|
59629
|
+
process.exit(0);
|
|
59630
|
+
}
|
|
59631
|
+
const success2 = await executeUpdate(command);
|
|
59632
|
+
if (success2) {
|
|
59633
|
+
clearCache();
|
|
59634
|
+
process.exit(0);
|
|
59635
|
+
} else {
|
|
59636
|
+
process.exit(1);
|
|
59637
|
+
}
|
|
59638
|
+
}
|
|
59639
|
+
var RESET2 = "\x1B[0m", BOLD2 = "\x1B[1m", GREEN2 = "\x1B[32m", YELLOW2 = "\x1B[33m", CYAN2 = "\x1B[36m", RED = "\x1B[31m";
|
|
59640
|
+
var init_update_command = __esm(() => {
|
|
59641
|
+
init_cli();
|
|
59642
|
+
init_update_checker();
|
|
59643
|
+
});
|
|
59644
|
+
|
|
59645
|
+
// src/claude-runner.ts
|
|
59646
|
+
var exports_claude_runner = {};
|
|
59647
|
+
__export(exports_claude_runner, {
|
|
59648
|
+
runClaudeWithProxy: () => runClaudeWithProxy,
|
|
59649
|
+
checkClaudeInstalled: () => checkClaudeInstalled
|
|
59650
|
+
});
|
|
59651
|
+
import { spawn } from "node:child_process";
|
|
59652
|
+
import { writeFileSync as writeFileSync12, unlinkSync as unlinkSync2, mkdirSync as mkdirSync10 } from "node:fs";
|
|
59653
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
59654
|
+
import { join as join14 } from "node:path";
|
|
59655
|
+
function isWindows2() {
|
|
59656
|
+
return process.platform === "win32";
|
|
59657
|
+
}
|
|
59658
|
+
function createStatusLineScript(tokenFilePath) {
|
|
59659
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
59660
|
+
const claudishDir = join14(homeDir, ".claudish");
|
|
59661
|
+
const timestamp = Date.now();
|
|
59662
|
+
const scriptPath = join14(claudishDir, `status-${timestamp}.js`);
|
|
59663
|
+
const escapedTokenPath = tokenFilePath.replace(/\\/g, "\\\\");
|
|
59664
|
+
const script = `
|
|
59665
|
+
const fs = require('fs');
|
|
59666
|
+
const path = require('path');
|
|
59667
|
+
|
|
59668
|
+
const CYAN = "\\x1b[96m";
|
|
59669
|
+
const YELLOW = "\\x1b[93m";
|
|
59670
|
+
const GREEN = "\\x1b[92m";
|
|
59671
|
+
const MAGENTA = "\\x1b[95m";
|
|
59672
|
+
const DIM = "\\x1b[2m";
|
|
59673
|
+
const RESET = "\\x1b[0m";
|
|
59674
|
+
const BOLD = "\\x1b[1m";
|
|
59675
|
+
|
|
59676
|
+
let input = '';
|
|
59677
|
+
process.stdin.setEncoding('utf8');
|
|
59678
|
+
process.stdin.on('data', chunk => input += chunk);
|
|
59679
|
+
process.stdin.on('end', () => {
|
|
59680
|
+
try {
|
|
59681
|
+
let dir = path.basename(process.cwd());
|
|
59682
|
+
if (dir.length > 15) dir = dir.substring(0, 12) + '...';
|
|
59683
|
+
|
|
59684
|
+
let ctx = 100, cost = 0;
|
|
59685
|
+
const model = process.env.CLAUDISH_ACTIVE_MODEL_NAME || 'unknown';
|
|
59686
|
+
const isLocal = process.env.CLAUDISH_IS_LOCAL === 'true';
|
|
59687
|
+
|
|
59688
|
+
try {
|
|
59689
|
+
const tokens = JSON.parse(fs.readFileSync('${escapedTokenPath}', 'utf-8'));
|
|
59690
|
+
cost = tokens.total_cost || 0;
|
|
59691
|
+
ctx = tokens.context_left_percent || 100;
|
|
59692
|
+
} catch (e) {
|
|
59693
|
+
try {
|
|
59694
|
+
const json = JSON.parse(input);
|
|
59695
|
+
cost = json.total_cost_usd || 0;
|
|
59696
|
+
} catch {}
|
|
59697
|
+
}
|
|
59698
|
+
|
|
59699
|
+
const costDisplay = isLocal ? 'LOCAL' : ('$' + cost.toFixed(3));
|
|
59700
|
+
console.log(\`\${CYAN}\${BOLD}\${dir}\${RESET} \${DIM}•\${RESET} \${YELLOW}\${model}\${RESET} \${DIM}•\${RESET} \${GREEN}\${costDisplay}\${RESET} \${DIM}•\${RESET} \${MAGENTA}\${ctx}%\${RESET}\`);
|
|
59701
|
+
} catch (e) {
|
|
59702
|
+
console.log('claudish');
|
|
59703
|
+
}
|
|
59704
|
+
});
|
|
59705
|
+
`;
|
|
59706
|
+
writeFileSync12(scriptPath, script, "utf-8");
|
|
59707
|
+
return scriptPath;
|
|
59708
|
+
}
|
|
59709
|
+
function createTempSettingsFile(modelDisplay, port) {
|
|
59710
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
59711
|
+
const claudishDir = join14(homeDir, ".claudish");
|
|
59712
|
+
try {
|
|
59713
|
+
mkdirSync10(claudishDir, { recursive: true });
|
|
59714
|
+
} catch {}
|
|
59715
|
+
const timestamp = Date.now();
|
|
59716
|
+
const tempPath = join14(claudishDir, `settings-${timestamp}.json`);
|
|
59717
|
+
const tokenFilePath = join14(claudishDir, `tokens-${port}.json`);
|
|
59718
|
+
let statusCommand;
|
|
59719
|
+
if (isWindows2()) {
|
|
59720
|
+
const scriptPath = createStatusLineScript(tokenFilePath);
|
|
59721
|
+
statusCommand = `node "${scriptPath}"`;
|
|
59722
|
+
} else {
|
|
59723
|
+
const CYAN3 = "\\033[96m";
|
|
59724
|
+
const YELLOW3 = "\\033[93m";
|
|
59725
|
+
const GREEN3 = "\\033[92m";
|
|
59726
|
+
const MAGENTA = "\\033[95m";
|
|
59727
|
+
const DIM2 = "\\033[2m";
|
|
59728
|
+
const RESET3 = "\\033[0m";
|
|
59729
|
+
const BOLD3 = "\\033[1m";
|
|
59730
|
+
statusCommand = `JSON=$(cat) && DIR=$(basename "$(pwd)") && [ \${#DIR} -gt 15 ] && DIR="\${DIR:0:12}..." || true && CTX=100 && COST="0" && if [ -f "${tokenFilePath}" ]; then TOKENS=$(cat "${tokenFilePath}" 2>/dev/null) && REAL_CTX=$(echo "$TOKENS" | grep -o '"context_left_percent":[0-9]*' | grep -o '[0-9]*') && if [ ! -z "$REAL_CTX" ]; then CTX="$REAL_CTX"; fi && REAL_COST=$(echo "$TOKENS" | grep -o '"total_cost":[0-9.]*' | cut -d: -f2) && if [ ! -z "$REAL_COST" ]; then COST="$REAL_COST"; fi; fi && if [ "$CLAUDISH_IS_LOCAL" = "true" ]; then COST_DISPLAY="LOCAL"; else COST_DISPLAY=$(printf "\\$%.3f" "$COST"); fi && printf "${CYAN3}${BOLD3}%s${RESET3} ${DIM2}•${RESET3} ${YELLOW3}%s${RESET3} ${DIM2}•${RESET3} ${GREEN3}%s${RESET3} ${DIM2}•${RESET3} ${MAGENTA}%s%%${RESET3}\\n" "$DIR" "$CLAUDISH_ACTIVE_MODEL_NAME" "$COST_DISPLAY" "$CTX"`;
|
|
59731
|
+
}
|
|
59732
|
+
const settings = {
|
|
59733
|
+
statusLine: {
|
|
59734
|
+
type: "command",
|
|
59735
|
+
command: statusCommand,
|
|
59736
|
+
padding: 0
|
|
59737
|
+
}
|
|
59738
|
+
};
|
|
59739
|
+
writeFileSync12(tempPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
59740
|
+
return tempPath;
|
|
59741
|
+
}
|
|
59742
|
+
async function runClaudeWithProxy(config3, proxyUrl) {
|
|
59743
|
+
const modelId = config3.model || "unknown";
|
|
59744
|
+
const portMatch = proxyUrl.match(/:(\d+)/);
|
|
59745
|
+
const port = portMatch ? portMatch[1] : "unknown";
|
|
59746
|
+
const tempSettingsPath = createTempSettingsFile(modelId, port);
|
|
59747
|
+
const claudeArgs = [];
|
|
59748
|
+
claudeArgs.push("--settings", tempSettingsPath);
|
|
59749
|
+
if (config3.interactive) {
|
|
59750
|
+
if (config3.autoApprove) {
|
|
59751
|
+
claudeArgs.push("--dangerously-skip-permissions");
|
|
59752
|
+
}
|
|
59753
|
+
if (config3.dangerous) {
|
|
59754
|
+
claudeArgs.push("--dangerouslyDisableSandbox");
|
|
59755
|
+
}
|
|
59756
|
+
} else {
|
|
59757
|
+
claudeArgs.push("-p");
|
|
59758
|
+
if (config3.autoApprove) {
|
|
59759
|
+
claudeArgs.push("--dangerously-skip-permissions");
|
|
59760
|
+
}
|
|
59761
|
+
if (config3.dangerous) {
|
|
59762
|
+
claudeArgs.push("--dangerouslyDisableSandbox");
|
|
59763
|
+
}
|
|
59764
|
+
if (config3.jsonOutput) {
|
|
59765
|
+
claudeArgs.push("--output-format", "json");
|
|
59766
|
+
}
|
|
59767
|
+
if (config3.agent && config3.claudeArgs.length > 0) {
|
|
59768
|
+
const modifiedArgs = [...config3.claudeArgs];
|
|
59769
|
+
const agentId = config3.agent.startsWith("@agent-") ? config3.agent : `@agent-${config3.agent}`;
|
|
59770
|
+
modifiedArgs[0] = `Use the ${agentId} agent to: ${modifiedArgs[0]}`;
|
|
59771
|
+
claudeArgs.push(...modifiedArgs);
|
|
59772
|
+
} else {
|
|
59773
|
+
claudeArgs.push(...config3.claudeArgs);
|
|
59774
|
+
}
|
|
59775
|
+
}
|
|
59776
|
+
const isLocalModel = modelId.startsWith("ollama/") || modelId.startsWith("ollama:") || modelId.startsWith("lmstudio/") || modelId.startsWith("lmstudio:") || modelId.startsWith("vllm/") || modelId.startsWith("vllm:") || modelId.startsWith("mlx/") || modelId.startsWith("mlx:") || modelId.startsWith("http://") || modelId.startsWith("https://");
|
|
59777
|
+
const env = {
|
|
59778
|
+
...process.env,
|
|
59779
|
+
ANTHROPIC_BASE_URL: proxyUrl,
|
|
59780
|
+
[ENV.CLAUDISH_ACTIVE_MODEL_NAME]: modelId,
|
|
59781
|
+
CLAUDISH_IS_LOCAL: isLocalModel ? "true" : "false",
|
|
59782
|
+
[ENV.ANTHROPIC_MODEL]: modelId,
|
|
59783
|
+
[ENV.ANTHROPIC_SMALL_FAST_MODEL]: modelId
|
|
59784
|
+
};
|
|
59785
|
+
if (config3.monitor) {
|
|
59786
|
+
delete env.ANTHROPIC_API_KEY;
|
|
59787
|
+
} else {
|
|
59788
|
+
env.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || "sk-ant-api03-placeholder-not-used-proxy-handles-auth-with-openrouter-key-xxxxxxxxxxxxxxxxxxxxx";
|
|
59789
|
+
}
|
|
59790
|
+
const log2 = (message) => {
|
|
59791
|
+
if (!config3.quiet) {
|
|
59792
|
+
console.log(message);
|
|
59793
|
+
}
|
|
59794
|
+
};
|
|
59795
|
+
if (config3.interactive) {
|
|
59796
|
+
log2(`
|
|
59797
|
+
[claudish] Model: ${modelId}
|
|
59798
|
+
`);
|
|
59799
|
+
} else {
|
|
59800
|
+
log2(`
|
|
59801
|
+
[claudish] Model: ${modelId}`);
|
|
59802
|
+
log2(`[claudish] Arguments: ${claudeArgs.join(" ")}
|
|
59803
|
+
`);
|
|
59804
|
+
}
|
|
59805
|
+
const proc = spawn("claude", claudeArgs, {
|
|
59806
|
+
env,
|
|
59807
|
+
stdio: "inherit",
|
|
59808
|
+
shell: isWindows2()
|
|
59809
|
+
});
|
|
59810
|
+
setupSignalHandlers(proc, tempSettingsPath, config3.quiet);
|
|
59811
|
+
const exitCode = await new Promise((resolve) => {
|
|
59812
|
+
proc.on("exit", (code) => {
|
|
59813
|
+
resolve(code ?? 1);
|
|
59814
|
+
});
|
|
59815
|
+
});
|
|
59816
|
+
try {
|
|
59817
|
+
unlinkSync2(tempSettingsPath);
|
|
59818
|
+
} catch (error46) {}
|
|
59819
|
+
return exitCode;
|
|
59820
|
+
}
|
|
59821
|
+
function setupSignalHandlers(proc, tempSettingsPath, quiet) {
|
|
59822
|
+
const signals2 = isWindows2() ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
59823
|
+
for (const signal of signals2) {
|
|
59824
|
+
process.on(signal, () => {
|
|
59825
|
+
if (!quiet) {
|
|
59826
|
+
console.log(`
|
|
59827
|
+
[claudish] Received ${signal}, shutting down...`);
|
|
59828
|
+
}
|
|
59829
|
+
proc.kill();
|
|
59830
|
+
try {
|
|
59831
|
+
unlinkSync2(tempSettingsPath);
|
|
59832
|
+
} catch {}
|
|
59833
|
+
process.exit(0);
|
|
59834
|
+
});
|
|
59835
|
+
}
|
|
59836
|
+
}
|
|
59837
|
+
async function checkClaudeInstalled() {
|
|
59838
|
+
try {
|
|
59839
|
+
const isWindows3 = process.platform === "win32";
|
|
59840
|
+
const command = isWindows3 ? "where" : "which";
|
|
59841
|
+
const proc = spawn(command, ["claude"], {
|
|
59842
|
+
stdio: "ignore",
|
|
59843
|
+
shell: isWindows3
|
|
59844
|
+
});
|
|
59845
|
+
const exitCode = await new Promise((resolve) => {
|
|
59846
|
+
proc.on("exit", (code) => {
|
|
59847
|
+
resolve(code ?? 1);
|
|
59848
|
+
});
|
|
59849
|
+
});
|
|
59850
|
+
return exitCode === 0;
|
|
59851
|
+
} catch {
|
|
59852
|
+
return false;
|
|
59853
|
+
}
|
|
59854
|
+
}
|
|
59855
|
+
var init_claude_runner = __esm(() => {
|
|
59856
|
+
init_dist11();
|
|
59857
|
+
});
|
|
59858
|
+
|
|
59859
|
+
// src/port-manager.ts
|
|
59860
|
+
var exports_port_manager = {};
|
|
59861
|
+
__export(exports_port_manager, {
|
|
59862
|
+
isPortAvailable: () => isPortAvailable,
|
|
59863
|
+
findAvailablePort: () => findAvailablePort
|
|
59864
|
+
});
|
|
59865
|
+
import { createServer } from "node:net";
|
|
59866
|
+
async function findAvailablePort(startPort = 3000, endPort = 9000) {
|
|
59867
|
+
const randomPort = Math.floor(Math.random() * (endPort - startPort + 1)) + startPort;
|
|
59868
|
+
if (await isPortAvailable(randomPort)) {
|
|
59869
|
+
return randomPort;
|
|
59870
|
+
}
|
|
59871
|
+
for (let port = startPort;port <= endPort; port++) {
|
|
59872
|
+
if (await isPortAvailable(port)) {
|
|
59873
|
+
return port;
|
|
59874
|
+
}
|
|
59875
|
+
}
|
|
59876
|
+
throw new Error(`No available ports found in range ${startPort}-${endPort}`);
|
|
59877
|
+
}
|
|
59878
|
+
async function isPortAvailable(port) {
|
|
59879
|
+
return new Promise((resolve) => {
|
|
59880
|
+
const server = createServer();
|
|
59881
|
+
server.once("error", (err) => {
|
|
59882
|
+
resolve(err.code !== "EADDRINUSE");
|
|
59883
|
+
});
|
|
59884
|
+
server.once("listening", () => {
|
|
59885
|
+
server.close();
|
|
59886
|
+
resolve(true);
|
|
59887
|
+
});
|
|
59888
|
+
server.listen(port, "127.0.0.1");
|
|
59889
|
+
});
|
|
59890
|
+
}
|
|
59891
|
+
var init_port_manager = () => {};
|
|
59892
|
+
|
|
59697
59893
|
// src/index.ts
|
|
59698
59894
|
var import_dotenv2 = __toESM(require_main(), 1);
|
|
59699
59895
|
import_dotenv2.config({ quiet: true });
|
|
@@ -59706,6 +59902,8 @@ if (isMcpMode) {
|
|
|
59706
59902
|
Promise.resolve().then(() => (init_profile_commands(), exports_profile_commands)).then((pc) => pc.initCommand());
|
|
59707
59903
|
} else if (firstArg === "profile") {
|
|
59708
59904
|
Promise.resolve().then(() => (init_profile_commands(), exports_profile_commands)).then((pc) => pc.profileCommand(args.slice(1)));
|
|
59905
|
+
} else if (firstArg === "update") {
|
|
59906
|
+
Promise.resolve().then(() => (init_update_command(), exports_update_command)).then((uc) => uc.updateCommand());
|
|
59709
59907
|
} else {
|
|
59710
59908
|
runCli();
|
|
59711
59909
|
}
|