claudish 7.53.0 → 7.55.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 +1242 -548
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -729,7 +729,7 @@ var init_onepassword_config = __esm(() => {
|
|
|
729
729
|
});
|
|
730
730
|
|
|
731
731
|
// src/version.ts
|
|
732
|
-
var VERSION = "7.
|
|
732
|
+
var VERSION = "7.55.0";
|
|
733
733
|
|
|
734
734
|
// src/logger.ts
|
|
735
735
|
var exports_logger = {};
|
|
@@ -28161,6 +28161,26 @@ var init_provider_definitions = __esm(() => {
|
|
|
28161
28161
|
nativeModelPatterns: [{ pattern: /^x-ai\//i }, { pattern: /^grok-/i }],
|
|
28162
28162
|
isDirectApi: true
|
|
28163
28163
|
},
|
|
28164
|
+
{
|
|
28165
|
+
name: "grok-subscription",
|
|
28166
|
+
displayName: "Grok Build (subscription)",
|
|
28167
|
+
transport: "grok-subscription",
|
|
28168
|
+
tokenStrategy: "delta-aware",
|
|
28169
|
+
baseUrl: "https://cli-chat-proxy.grok.com",
|
|
28170
|
+
baseUrlEnvVars: ["GROK_PROXY_URL"],
|
|
28171
|
+
apiPath: "/v1/chat/completions",
|
|
28172
|
+
apiKeyEnvVar: "",
|
|
28173
|
+
apiKeyDescription: "Grok subscription OAuth (`claudish login grok`, or an existing `grok login`)",
|
|
28174
|
+
apiKeyUrl: "https://x.ai/cli",
|
|
28175
|
+
oauthLoginSlug: "grok",
|
|
28176
|
+
oauthFallback: "grok-oauth.json",
|
|
28177
|
+
shortcuts: ["gk", "grok-subscription"],
|
|
28178
|
+
shortestPrefix: "gk",
|
|
28179
|
+
legacyPrefixes: [{ prefix: "gk/", stripPrefix: true }],
|
|
28180
|
+
modelDiscovery: { path: "/v1/models", format: "openai-models-list" },
|
|
28181
|
+
isDirectApi: true,
|
|
28182
|
+
description: "Grok on your SuperGrok or X Premium+ plan (gk@)"
|
|
28183
|
+
},
|
|
28164
28184
|
{
|
|
28165
28185
|
name: "minimax",
|
|
28166
28186
|
displayName: "MiniMax",
|
|
@@ -28934,7 +28954,8 @@ var init_remote_provider_types = __esm(() => {
|
|
|
28934
28954
|
"qwen-cloud",
|
|
28935
28955
|
"devin",
|
|
28936
28956
|
"antigravity",
|
|
28937
|
-
"sakana-subscription"
|
|
28957
|
+
"sakana-subscription",
|
|
28958
|
+
"grok-subscription"
|
|
28938
28959
|
]);
|
|
28939
28960
|
PROVIDER_ALIAS = {
|
|
28940
28961
|
google: "gemini",
|
|
@@ -31663,14 +31684,613 @@ var init_devin_credential = __esm(() => {
|
|
|
31663
31684
|
init_devin_credentials();
|
|
31664
31685
|
});
|
|
31665
31686
|
|
|
31666
|
-
// src/auth/
|
|
31687
|
+
// src/auth/oauth-manager.ts
|
|
31667
31688
|
import { exec as exec2 } from "child_process";
|
|
31668
|
-
import { randomBytes as randomBytes2 } from "crypto";
|
|
31669
|
-
import {
|
|
31670
|
-
|
|
31689
|
+
import { createHash as createHash3, randomBytes as randomBytes2 } from "crypto";
|
|
31690
|
+
import {
|
|
31691
|
+
closeSync as closeSync3,
|
|
31692
|
+
existsSync as existsSync10,
|
|
31693
|
+
mkdirSync as mkdirSync7,
|
|
31694
|
+
openSync as openSync3,
|
|
31695
|
+
readFileSync as readFileSync9,
|
|
31696
|
+
unlinkSync as unlinkSync3,
|
|
31697
|
+
writeSync as writeSync3
|
|
31698
|
+
} from "fs";
|
|
31699
|
+
import { homedir as homedir13 } from "os";
|
|
31671
31700
|
import { join as join13 } from "path";
|
|
31672
31701
|
import { promisify as promisify2 } from "util";
|
|
31673
31702
|
|
|
31703
|
+
class OAuthManager {
|
|
31704
|
+
credentials = null;
|
|
31705
|
+
refreshPromise = null;
|
|
31706
|
+
tokenRefreshMargin = 5 * 60 * 1000;
|
|
31707
|
+
static ensureClaudishDir() {
|
|
31708
|
+
const dir = join13(homedir13(), ".claudish");
|
|
31709
|
+
if (!existsSync10(dir)) {
|
|
31710
|
+
mkdirSync7(dir, { recursive: true });
|
|
31711
|
+
}
|
|
31712
|
+
return dir;
|
|
31713
|
+
}
|
|
31714
|
+
getCredentialsPath() {
|
|
31715
|
+
return join13(homedir13(), ".claudish", this.credentialFile);
|
|
31716
|
+
}
|
|
31717
|
+
loadCredentials() {
|
|
31718
|
+
const credPath = this.getCredentialsPath();
|
|
31719
|
+
if (!existsSync10(credPath))
|
|
31720
|
+
return null;
|
|
31721
|
+
try {
|
|
31722
|
+
const data = JSON.parse(readFileSync9(credPath, "utf-8"));
|
|
31723
|
+
if (!this.validateCredentials(data)) {
|
|
31724
|
+
log(`[${this.providerName}] Invalid credentials file structure`);
|
|
31725
|
+
return null;
|
|
31726
|
+
}
|
|
31727
|
+
log(`[${this.providerName}] Loaded credentials from file`);
|
|
31728
|
+
return data;
|
|
31729
|
+
} catch (e) {
|
|
31730
|
+
log(`[${this.providerName}] Failed to load credentials: ${e.message}`);
|
|
31731
|
+
return null;
|
|
31732
|
+
}
|
|
31733
|
+
}
|
|
31734
|
+
saveCredentials(credentials2) {
|
|
31735
|
+
OAuthManager.ensureClaudishDir();
|
|
31736
|
+
const credPath = this.getCredentialsPath();
|
|
31737
|
+
const fd = openSync3(credPath, "w", 384);
|
|
31738
|
+
try {
|
|
31739
|
+
writeSync3(fd, JSON.stringify(credentials2, null, 2), 0, "utf-8");
|
|
31740
|
+
} finally {
|
|
31741
|
+
closeSync3(fd);
|
|
31742
|
+
}
|
|
31743
|
+
log(`[${this.providerName}] Credentials saved to ${credPath}`);
|
|
31744
|
+
}
|
|
31745
|
+
deleteCredentials() {
|
|
31746
|
+
const credPath = this.getCredentialsPath();
|
|
31747
|
+
if (existsSync10(credPath)) {
|
|
31748
|
+
unlinkSync3(credPath);
|
|
31749
|
+
log(`[${this.providerName}] Credentials deleted`);
|
|
31750
|
+
}
|
|
31751
|
+
}
|
|
31752
|
+
hasCredentials() {
|
|
31753
|
+
return this.credentials !== null && !!this.credentials.refresh_token;
|
|
31754
|
+
}
|
|
31755
|
+
async getAccessToken() {
|
|
31756
|
+
if (this.refreshPromise) {
|
|
31757
|
+
log(`[${this.providerName}] Waiting for in-progress refresh`);
|
|
31758
|
+
return this.refreshPromise;
|
|
31759
|
+
}
|
|
31760
|
+
if (!this.credentials) {
|
|
31761
|
+
throw new Error(`No ${this.providerName} credentials found. Please run \`${this.loginHint}\` first.`);
|
|
31762
|
+
}
|
|
31763
|
+
if (this.isTokenValid()) {
|
|
31764
|
+
return this.credentials.access_token;
|
|
31765
|
+
}
|
|
31766
|
+
this.refreshPromise = this.doRefreshToken().finally(() => {
|
|
31767
|
+
this.refreshPromise = null;
|
|
31768
|
+
});
|
|
31769
|
+
return this.refreshPromise;
|
|
31770
|
+
}
|
|
31771
|
+
async refreshToken() {
|
|
31772
|
+
if (!this.credentials) {
|
|
31773
|
+
throw new Error(`No ${this.providerName} credentials found. Please run \`${this.loginHint}\` first.`);
|
|
31774
|
+
}
|
|
31775
|
+
await this.doRefreshToken();
|
|
31776
|
+
}
|
|
31777
|
+
isTokenValid() {
|
|
31778
|
+
if (!this.credentials)
|
|
31779
|
+
return false;
|
|
31780
|
+
return Date.now() < this.credentials.expires_at - this.tokenRefreshMargin;
|
|
31781
|
+
}
|
|
31782
|
+
generateCodeVerifier() {
|
|
31783
|
+
return randomBytes2(64).toString("base64url");
|
|
31784
|
+
}
|
|
31785
|
+
generateCodeChallenge(verifier) {
|
|
31786
|
+
return createHash3("sha256").update(verifier).digest("base64url");
|
|
31787
|
+
}
|
|
31788
|
+
async openBrowser(url2, message) {
|
|
31789
|
+
try {
|
|
31790
|
+
if (process.platform === "darwin") {
|
|
31791
|
+
await execAsync2(`open "${url2}"`);
|
|
31792
|
+
} else if (process.platform === "win32") {
|
|
31793
|
+
await execAsync2(`start "${url2}"`);
|
|
31794
|
+
} else {
|
|
31795
|
+
await execAsync2(`xdg-open "${url2}"`);
|
|
31796
|
+
}
|
|
31797
|
+
if (message !== undefined) {
|
|
31798
|
+
console.log(message);
|
|
31799
|
+
} else {
|
|
31800
|
+
console.log(`
|
|
31801
|
+
Opening browser for authentication...`);
|
|
31802
|
+
console.log(`If the browser doesn't open, visit this URL:
|
|
31803
|
+
${url2}
|
|
31804
|
+
`);
|
|
31805
|
+
}
|
|
31806
|
+
} catch {
|
|
31807
|
+
console.log(`
|
|
31808
|
+
Please open this URL in your browser to authenticate:`);
|
|
31809
|
+
console.log(url2);
|
|
31810
|
+
console.log("");
|
|
31811
|
+
}
|
|
31812
|
+
}
|
|
31813
|
+
async copyToClipboard(text) {
|
|
31814
|
+
const commands = process.platform === "darwin" ? ["pbcopy"] : process.platform === "win32" ? ["clip"] : ["wl-copy", "xclip -selection clipboard", "xsel --clipboard --input"];
|
|
31815
|
+
for (const command of commands) {
|
|
31816
|
+
try {
|
|
31817
|
+
const child = (await import("child_process")).spawn(command, {
|
|
31818
|
+
shell: true,
|
|
31819
|
+
stdio: ["pipe", "ignore", "ignore"]
|
|
31820
|
+
});
|
|
31821
|
+
child.stdin.write(text);
|
|
31822
|
+
child.stdin.end();
|
|
31823
|
+
const ok = await new Promise((resolve) => {
|
|
31824
|
+
child.on("close", (code) => resolve(code === 0));
|
|
31825
|
+
child.on("error", () => resolve(false));
|
|
31826
|
+
});
|
|
31827
|
+
if (ok)
|
|
31828
|
+
return true;
|
|
31829
|
+
} catch {}
|
|
31830
|
+
}
|
|
31831
|
+
return false;
|
|
31832
|
+
}
|
|
31833
|
+
presentAuthUrl(url2) {
|
|
31834
|
+
const stdin = process.stdin;
|
|
31835
|
+
const interactive = Boolean(stdin.isTTY && typeof stdin.setRawMode === "function");
|
|
31836
|
+
if (!interactive) {
|
|
31837
|
+
console.log(` URL: ${url2}
|
|
31838
|
+
`);
|
|
31839
|
+
return () => {};
|
|
31840
|
+
}
|
|
31841
|
+
console.log(` URL: ${url2}`);
|
|
31842
|
+
console.log(` (press c to copy the URL, or open it manually)
|
|
31843
|
+
`);
|
|
31844
|
+
const onKey = (chunk) => {
|
|
31845
|
+
const key = chunk.toString();
|
|
31846
|
+
if (key === "\x03") {
|
|
31847
|
+
cleanup();
|
|
31848
|
+
process.exit(130);
|
|
31849
|
+
}
|
|
31850
|
+
if (key.toLowerCase() === "c") {
|
|
31851
|
+
this.copyToClipboard(url2).then((ok) => {
|
|
31852
|
+
console.log(ok ? " \u2713 URL copied to clipboard" : " \u2717 No clipboard tool available");
|
|
31853
|
+
});
|
|
31854
|
+
}
|
|
31855
|
+
};
|
|
31856
|
+
let disposed = false;
|
|
31857
|
+
const cleanup = () => {
|
|
31858
|
+
if (disposed)
|
|
31859
|
+
return;
|
|
31860
|
+
disposed = true;
|
|
31861
|
+
stdin.off("data", onKey);
|
|
31862
|
+
try {
|
|
31863
|
+
stdin.setRawMode(false);
|
|
31864
|
+
} catch {}
|
|
31865
|
+
stdin.pause();
|
|
31866
|
+
};
|
|
31867
|
+
stdin.setRawMode(true);
|
|
31868
|
+
stdin.resume();
|
|
31869
|
+
stdin.on("data", onKey);
|
|
31870
|
+
return cleanup;
|
|
31871
|
+
}
|
|
31872
|
+
async logout() {
|
|
31873
|
+
this.deleteCredentials();
|
|
31874
|
+
this.credentials = null;
|
|
31875
|
+
}
|
|
31876
|
+
}
|
|
31877
|
+
var execAsync2;
|
|
31878
|
+
var init_oauth_manager = __esm(() => {
|
|
31879
|
+
init_logger();
|
|
31880
|
+
execAsync2 = promisify2(exec2);
|
|
31881
|
+
});
|
|
31882
|
+
|
|
31883
|
+
// src/auth/grok-oauth.ts
|
|
31884
|
+
var GROK_ISSUER = "https://auth.x.ai", DEVICE_CODE_ENDPOINT, TOKEN_ENDPOINT, REVOKE_ENDPOINT, GROK_PUBLIC_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828", GROK_SCOPES, DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code", DEFAULT_POLL_INTERVAL_S = 5, GrokOAuth;
|
|
31885
|
+
var init_grok_oauth = __esm(() => {
|
|
31886
|
+
init_logger();
|
|
31887
|
+
init_oauth_manager();
|
|
31888
|
+
DEVICE_CODE_ENDPOINT = `${GROK_ISSUER}/oauth2/device/code`;
|
|
31889
|
+
TOKEN_ENDPOINT = `${GROK_ISSUER}/oauth2/token`;
|
|
31890
|
+
REVOKE_ENDPOINT = `${GROK_ISSUER}/oauth2/revoke`;
|
|
31891
|
+
GROK_SCOPES = [
|
|
31892
|
+
"openid",
|
|
31893
|
+
"profile",
|
|
31894
|
+
"email",
|
|
31895
|
+
"offline_access",
|
|
31896
|
+
"grok-cli:access",
|
|
31897
|
+
"api:access",
|
|
31898
|
+
"conversations:read",
|
|
31899
|
+
"conversations:write",
|
|
31900
|
+
"workspaces:read",
|
|
31901
|
+
"workspaces:write"
|
|
31902
|
+
].join(" ");
|
|
31903
|
+
GrokOAuth = class GrokOAuth extends OAuthManager {
|
|
31904
|
+
credentialFile = "grok-oauth.json";
|
|
31905
|
+
providerName = "GrokOAuth";
|
|
31906
|
+
loginHint = "claudish login grok";
|
|
31907
|
+
static instance = null;
|
|
31908
|
+
static getInstance() {
|
|
31909
|
+
if (!GrokOAuth.instance) {
|
|
31910
|
+
GrokOAuth.instance = new GrokOAuth;
|
|
31911
|
+
}
|
|
31912
|
+
return GrokOAuth.instance;
|
|
31913
|
+
}
|
|
31914
|
+
constructor() {
|
|
31915
|
+
super();
|
|
31916
|
+
this.credentials = this.loadCredentials();
|
|
31917
|
+
}
|
|
31918
|
+
validateCredentials(data) {
|
|
31919
|
+
if (!data || typeof data !== "object")
|
|
31920
|
+
return false;
|
|
31921
|
+
const d = data;
|
|
31922
|
+
return typeof d.access_token === "string" && typeof d.refresh_token === "string" && typeof d.expires_at === "number";
|
|
31923
|
+
}
|
|
31924
|
+
async getToken() {
|
|
31925
|
+
return this.getAccessToken();
|
|
31926
|
+
}
|
|
31927
|
+
async doRefreshToken() {
|
|
31928
|
+
const current = this.credentials;
|
|
31929
|
+
if (!current) {
|
|
31930
|
+
throw new Error(`No Grok credentials found. Please run \`${this.loginHint}\` first.`);
|
|
31931
|
+
}
|
|
31932
|
+
const body = new URLSearchParams({
|
|
31933
|
+
grant_type: "refresh_token",
|
|
31934
|
+
refresh_token: current.refresh_token,
|
|
31935
|
+
client_id: current.client_id || GROK_PUBLIC_CLIENT_ID
|
|
31936
|
+
});
|
|
31937
|
+
const response = await fetch(TOKEN_ENDPOINT, {
|
|
31938
|
+
method: "POST",
|
|
31939
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
31940
|
+
body
|
|
31941
|
+
});
|
|
31942
|
+
const parsed = await response.json().catch(() => ({}));
|
|
31943
|
+
if (!response.ok || !parsed.access_token) {
|
|
31944
|
+
const detail = parsed.error_description ?? parsed.error ?? `HTTP ${response.status}`;
|
|
31945
|
+
throw new Error(`Grok token refresh failed: ${detail}. Run \`${this.loginHint}\` to sign in.`);
|
|
31946
|
+
}
|
|
31947
|
+
const next = {
|
|
31948
|
+
access_token: parsed.access_token,
|
|
31949
|
+
refresh_token: parsed.refresh_token ?? current.refresh_token,
|
|
31950
|
+
expires_at: Date.now() + (parsed.expires_in ?? 6 * 60 * 60) * 1000,
|
|
31951
|
+
client_id: current.client_id || GROK_PUBLIC_CLIENT_ID,
|
|
31952
|
+
scope: parsed.scope ?? current.scope
|
|
31953
|
+
};
|
|
31954
|
+
this.credentials = next;
|
|
31955
|
+
this.saveCredentials(next);
|
|
31956
|
+
return next.access_token;
|
|
31957
|
+
}
|
|
31958
|
+
async login(clientId = GROK_PUBLIC_CLIENT_ID) {
|
|
31959
|
+
const auth = await this.requestDeviceCode(clientId);
|
|
31960
|
+
const url2 = auth.verification_uri_complete ?? auth.verification_uri;
|
|
31961
|
+
console.log(`
|
|
31962
|
+
Sign in to Grok (SuperGrok or X Premium+ subscription required).`);
|
|
31963
|
+
console.log(`
|
|
31964
|
+
Code: ${auth.user_code}`);
|
|
31965
|
+
const disposeUrlPrompt = this.presentAuthUrl(url2);
|
|
31966
|
+
await this.openBrowser(url2, "Opening your browser\u2026 (approve the request there)");
|
|
31967
|
+
try {
|
|
31968
|
+
const credentials2 = await this.pollForToken(auth, clientId);
|
|
31969
|
+
this.credentials = credentials2;
|
|
31970
|
+
this.saveCredentials(credentials2);
|
|
31971
|
+
} finally {
|
|
31972
|
+
disposeUrlPrompt();
|
|
31973
|
+
}
|
|
31974
|
+
console.log(`
|
|
31975
|
+
Signed in to Grok. Try it with: claudish --model gk@grok-4.6 "hello"
|
|
31976
|
+
`);
|
|
31977
|
+
}
|
|
31978
|
+
async requestDeviceCode(clientId) {
|
|
31979
|
+
const response = await fetch(DEVICE_CODE_ENDPOINT, {
|
|
31980
|
+
method: "POST",
|
|
31981
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
31982
|
+
body: new URLSearchParams({ client_id: clientId, scope: GROK_SCOPES })
|
|
31983
|
+
});
|
|
31984
|
+
const parsed = await response.json().catch(() => ({}));
|
|
31985
|
+
if (!response.ok || !parsed.device_code || !parsed.user_code) {
|
|
31986
|
+
const detail = parsed.error_description ?? parsed.error ?? `HTTP ${response.status}`;
|
|
31987
|
+
throw new Error(`Could not start Grok device authorization: ${detail}`);
|
|
31988
|
+
}
|
|
31989
|
+
return parsed;
|
|
31990
|
+
}
|
|
31991
|
+
async pollForToken(auth, clientId) {
|
|
31992
|
+
let intervalMs = (auth.interval ?? DEFAULT_POLL_INTERVAL_S) * 1000;
|
|
31993
|
+
const deadline = Date.now() + auth.expires_in * 1000;
|
|
31994
|
+
while (Date.now() < deadline) {
|
|
31995
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
31996
|
+
let parsed;
|
|
31997
|
+
try {
|
|
31998
|
+
const response = await fetch(TOKEN_ENDPOINT, {
|
|
31999
|
+
method: "POST",
|
|
32000
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
32001
|
+
body: new URLSearchParams({
|
|
32002
|
+
grant_type: DEVICE_CODE_GRANT,
|
|
32003
|
+
device_code: auth.device_code,
|
|
32004
|
+
client_id: clientId
|
|
32005
|
+
})
|
|
32006
|
+
});
|
|
32007
|
+
parsed = await response.json().catch(() => ({}));
|
|
32008
|
+
} catch (error46) {
|
|
32009
|
+
log(`[${this.providerName}] Poll failed, retrying: ${error46.message}`);
|
|
32010
|
+
continue;
|
|
32011
|
+
}
|
|
32012
|
+
if (parsed.access_token) {
|
|
32013
|
+
return {
|
|
32014
|
+
access_token: parsed.access_token,
|
|
32015
|
+
refresh_token: parsed.refresh_token ?? "",
|
|
32016
|
+
expires_at: Date.now() + (parsed.expires_in ?? 6 * 60 * 60) * 1000,
|
|
32017
|
+
client_id: clientId,
|
|
32018
|
+
scope: parsed.scope
|
|
32019
|
+
};
|
|
32020
|
+
}
|
|
32021
|
+
if (parsed.error === "authorization_pending")
|
|
32022
|
+
continue;
|
|
32023
|
+
if (parsed.error === "slow_down") {
|
|
32024
|
+
intervalMs += 5000;
|
|
32025
|
+
continue;
|
|
32026
|
+
}
|
|
32027
|
+
throw new Error(`Grok sign-in failed: ${parsed.error_description ?? parsed.error ?? "unknown error"}`);
|
|
32028
|
+
}
|
|
32029
|
+
throw new Error("Grok sign-in timed out \u2014 the device code expired. Please try again.");
|
|
32030
|
+
}
|
|
32031
|
+
async logout() {
|
|
32032
|
+
const current = this.credentials;
|
|
32033
|
+
if (current?.refresh_token) {
|
|
32034
|
+
try {
|
|
32035
|
+
await fetch(REVOKE_ENDPOINT, {
|
|
32036
|
+
method: "POST",
|
|
32037
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
32038
|
+
body: new URLSearchParams({
|
|
32039
|
+
token: current.refresh_token,
|
|
32040
|
+
token_type_hint: "refresh_token",
|
|
32041
|
+
client_id: current.client_id || GROK_PUBLIC_CLIENT_ID
|
|
32042
|
+
})
|
|
32043
|
+
});
|
|
32044
|
+
} catch (error46) {
|
|
32045
|
+
log(`[${this.providerName}] Revocation failed (deleting locally anyway): ${error46}`);
|
|
32046
|
+
}
|
|
32047
|
+
}
|
|
32048
|
+
await super.logout();
|
|
32049
|
+
}
|
|
32050
|
+
};
|
|
32051
|
+
});
|
|
32052
|
+
|
|
32053
|
+
// src/providers/grok/grok-credentials.ts
|
|
32054
|
+
import { existsSync as existsSync11, readFileSync as readFileSync10, renameSync, writeFileSync as writeFileSync7 } from "fs";
|
|
32055
|
+
import { homedir as homedir14 } from "os";
|
|
32056
|
+
import { join as join14 } from "path";
|
|
32057
|
+
function grokHome() {
|
|
32058
|
+
return grokHomeOverride ?? join14(homedir14(), ".grok");
|
|
32059
|
+
}
|
|
32060
|
+
function grokAuthPath() {
|
|
32061
|
+
return join14(grokHome(), "auth.json");
|
|
32062
|
+
}
|
|
32063
|
+
function str(value) {
|
|
32064
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
32065
|
+
}
|
|
32066
|
+
function readGrokCredential() {
|
|
32067
|
+
let parsed;
|
|
32068
|
+
try {
|
|
32069
|
+
parsed = JSON.parse(readFileSync10(grokAuthPath(), "utf8"));
|
|
32070
|
+
} catch {
|
|
32071
|
+
return;
|
|
32072
|
+
}
|
|
32073
|
+
if (!parsed || typeof parsed !== "object")
|
|
32074
|
+
return;
|
|
32075
|
+
const entries = Object.entries(parsed).filter(([, v]) => v && typeof v === "object" && str(v.key));
|
|
32076
|
+
if (entries.length === 0)
|
|
32077
|
+
return;
|
|
32078
|
+
const chosen = entries.find(([, v]) => str(v.auth_mode)?.toLowerCase() === "oidc") ?? entries.find(([scope2]) => scope2 === LEGACY_SCOPE) ?? entries[0];
|
|
32079
|
+
const [scope, raw] = chosen;
|
|
32080
|
+
const key = str(raw.key);
|
|
32081
|
+
if (!key)
|
|
32082
|
+
return;
|
|
32083
|
+
return {
|
|
32084
|
+
scope,
|
|
32085
|
+
key,
|
|
32086
|
+
refreshToken: str(raw.refresh_token),
|
|
32087
|
+
expiresAt: str(raw.expires_at),
|
|
32088
|
+
clientId: str(raw.oidc_client_id),
|
|
32089
|
+
issuer: str(raw.oidc_issuer),
|
|
32090
|
+
authMode: str(raw.auth_mode)
|
|
32091
|
+
};
|
|
32092
|
+
}
|
|
32093
|
+
function claudishGrokOAuthPath() {
|
|
32094
|
+
return claudishOAuthPathOverride ?? join14(homedir14(), ".claudish", "grok-oauth.json");
|
|
32095
|
+
}
|
|
32096
|
+
function hasClaudishGrokOAuth() {
|
|
32097
|
+
return existsSync11(claudishGrokOAuthPath());
|
|
32098
|
+
}
|
|
32099
|
+
function hasGrokCredentials() {
|
|
32100
|
+
return hasClaudishGrokOAuth() || readGrokCredential() !== undefined;
|
|
32101
|
+
}
|
|
32102
|
+
function isGrokCredentialExpired(cred, now = Date.now()) {
|
|
32103
|
+
if (!cred.expiresAt)
|
|
32104
|
+
return false;
|
|
32105
|
+
const expiry = Date.parse(cred.expiresAt);
|
|
32106
|
+
if (Number.isNaN(expiry))
|
|
32107
|
+
return false;
|
|
32108
|
+
return expiry - EXPIRY_SKEW_MS2 <= now;
|
|
32109
|
+
}
|
|
32110
|
+
function readGrokClientVersion() {
|
|
32111
|
+
return readLocalGrokVersion() ?? FALLBACK_GROK_CLIENT_VERSION;
|
|
32112
|
+
}
|
|
32113
|
+
function readLocalGrokVersion() {
|
|
32114
|
+
for (const [file2, field] of [
|
|
32115
|
+
["version.json", "version"],
|
|
32116
|
+
["models_cache.json", "grok_version"]
|
|
32117
|
+
]) {
|
|
32118
|
+
try {
|
|
32119
|
+
const parsed = JSON.parse(readFileSync10(join14(grokHome(), file2), "utf8"));
|
|
32120
|
+
const version2 = str(parsed[field]);
|
|
32121
|
+
if (version2)
|
|
32122
|
+
return version2;
|
|
32123
|
+
} catch {}
|
|
32124
|
+
}
|
|
32125
|
+
return;
|
|
32126
|
+
}
|
|
32127
|
+
async function resolveGrokClientVersion() {
|
|
32128
|
+
const local = readLocalGrokVersion();
|
|
32129
|
+
if (local)
|
|
32130
|
+
return local;
|
|
32131
|
+
if (liveClientVersion)
|
|
32132
|
+
return liveClientVersion;
|
|
32133
|
+
try {
|
|
32134
|
+
const response = await fetch(GROK_CHANNEL_URL, { signal: AbortSignal.timeout(5000) });
|
|
32135
|
+
if (response.ok) {
|
|
32136
|
+
const version2 = (await response.text()).trim().split(/\s+/)[0];
|
|
32137
|
+
if (/^\d+\.\d+\.\d+(-[A-Za-z0-9._]+)?$/.test(version2)) {
|
|
32138
|
+
liveClientVersion = version2;
|
|
32139
|
+
return version2;
|
|
32140
|
+
}
|
|
32141
|
+
}
|
|
32142
|
+
} catch {}
|
|
32143
|
+
return FALLBACK_GROK_CLIENT_VERSION;
|
|
32144
|
+
}
|
|
32145
|
+
function grokAuthHeaders(token, version2 = readGrokClientVersion()) {
|
|
32146
|
+
return {
|
|
32147
|
+
Authorization: `Bearer ${token}`,
|
|
32148
|
+
"x-grok-client-version": version2,
|
|
32149
|
+
"x-grok-client-identifier": GROK_CLIENT_IDENTIFIER
|
|
32150
|
+
};
|
|
32151
|
+
}
|
|
32152
|
+
function terminal(message) {
|
|
32153
|
+
const err = new Error(message);
|
|
32154
|
+
err.terminal = true;
|
|
32155
|
+
return err;
|
|
32156
|
+
}
|
|
32157
|
+
function persistRefreshedToken(scope, next) {
|
|
32158
|
+
const path = grokAuthPath();
|
|
32159
|
+
let parsed;
|
|
32160
|
+
try {
|
|
32161
|
+
parsed = JSON.parse(readFileSync10(path, "utf8"));
|
|
32162
|
+
} catch {
|
|
32163
|
+
return;
|
|
32164
|
+
}
|
|
32165
|
+
const entry = parsed[scope];
|
|
32166
|
+
if (!entry || typeof entry !== "object")
|
|
32167
|
+
return;
|
|
32168
|
+
entry.key = next.key;
|
|
32169
|
+
if (next.refreshToken)
|
|
32170
|
+
entry.refresh_token = next.refreshToken;
|
|
32171
|
+
if (next.expiresAt)
|
|
32172
|
+
entry.expires_at = next.expiresAt;
|
|
32173
|
+
const tmp = `${path}.claudish.tmp`;
|
|
32174
|
+
writeFileSync7(tmp, `${JSON.stringify(parsed, null, 2)}
|
|
32175
|
+
`, { mode: 384 });
|
|
32176
|
+
renameSync(tmp, path);
|
|
32177
|
+
}
|
|
32178
|
+
async function performRefresh(cred) {
|
|
32179
|
+
if (!cred.refreshToken || !cred.clientId) {
|
|
32180
|
+
throw terminal(`Grok credential is expired and cannot be refreshed. ${SIGN_IN_HINT}`);
|
|
32181
|
+
}
|
|
32182
|
+
const tokenEndpoint = `${(cred.issuer ?? "https://auth.x.ai").replace(/\/+$/, "")}/oauth2/token`;
|
|
32183
|
+
const body = new URLSearchParams({
|
|
32184
|
+
grant_type: "refresh_token",
|
|
32185
|
+
refresh_token: cred.refreshToken,
|
|
32186
|
+
client_id: cred.clientId
|
|
32187
|
+
});
|
|
32188
|
+
let response;
|
|
32189
|
+
try {
|
|
32190
|
+
response = await fetch(tokenEndpoint, {
|
|
32191
|
+
method: "POST",
|
|
32192
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
32193
|
+
body
|
|
32194
|
+
});
|
|
32195
|
+
} catch (error46) {
|
|
32196
|
+
throw new Error(`Could not reach ${tokenEndpoint} to refresh the Grok token: ${error46.message}`);
|
|
32197
|
+
}
|
|
32198
|
+
const text = await response.text();
|
|
32199
|
+
if (!response.ok) {
|
|
32200
|
+
let detail = text.slice(0, 300);
|
|
32201
|
+
try {
|
|
32202
|
+
const parsed2 = JSON.parse(text);
|
|
32203
|
+
detail = parsed2.error_description ?? parsed2.error ?? detail;
|
|
32204
|
+
} catch {}
|
|
32205
|
+
throw terminal(`Grok token refresh failed (${response.status}): ${detail}. ${SIGN_IN_HINT}`);
|
|
32206
|
+
}
|
|
32207
|
+
const parsed = JSON.parse(text);
|
|
32208
|
+
const accessToken = str(parsed.access_token);
|
|
32209
|
+
if (!accessToken) {
|
|
32210
|
+
throw terminal(`Grok token refresh returned no access_token. ${SIGN_IN_HINT}`);
|
|
32211
|
+
}
|
|
32212
|
+
const expiresAt = typeof parsed.expires_in === "number" ? new Date(Date.now() + parsed.expires_in * 1000).toISOString() : undefined;
|
|
32213
|
+
try {
|
|
32214
|
+
persistRefreshedToken(cred.scope, {
|
|
32215
|
+
key: accessToken,
|
|
32216
|
+
refreshToken: str(parsed.refresh_token),
|
|
32217
|
+
expiresAt
|
|
32218
|
+
});
|
|
32219
|
+
} catch {}
|
|
32220
|
+
return accessToken;
|
|
32221
|
+
}
|
|
32222
|
+
async function resolveGrokAccessToken() {
|
|
32223
|
+
if (hasClaudishGrokOAuth()) {
|
|
32224
|
+
try {
|
|
32225
|
+
return await GrokOAuth.getInstance().getToken();
|
|
32226
|
+
} catch (error46) {
|
|
32227
|
+
if (!readGrokCredential())
|
|
32228
|
+
throw terminal(`${error46.message}`);
|
|
32229
|
+
}
|
|
32230
|
+
}
|
|
32231
|
+
const cred = readGrokCredential();
|
|
32232
|
+
if (!cred)
|
|
32233
|
+
throw terminal(`No Grok subscription credential. ${SIGN_IN_HINT}`);
|
|
32234
|
+
if (!isGrokCredentialExpired(cred))
|
|
32235
|
+
return cred.key;
|
|
32236
|
+
return refreshShared(cred);
|
|
32237
|
+
}
|
|
32238
|
+
async function forceRefreshGrokAccessToken() {
|
|
32239
|
+
if (hasClaudishGrokOAuth()) {
|
|
32240
|
+
const oauth = GrokOAuth.getInstance();
|
|
32241
|
+
await oauth.refreshToken();
|
|
32242
|
+
return oauth.getToken();
|
|
32243
|
+
}
|
|
32244
|
+
const cred = readGrokCredential();
|
|
32245
|
+
if (!cred)
|
|
32246
|
+
throw terminal(`No Grok subscription credential. ${SIGN_IN_HINT}`);
|
|
32247
|
+
return refreshShared(cred);
|
|
32248
|
+
}
|
|
32249
|
+
function refreshShared(cred) {
|
|
32250
|
+
if (!refreshInFlight) {
|
|
32251
|
+
refreshInFlight = performRefresh(cred).finally(() => {
|
|
32252
|
+
refreshInFlight = null;
|
|
32253
|
+
});
|
|
32254
|
+
}
|
|
32255
|
+
return refreshInFlight;
|
|
32256
|
+
}
|
|
32257
|
+
var GROK_CLIENT_IDENTIFIER = "grok-shell", FALLBACK_GROK_CLIENT_VERSION = "1.0.4", LEGACY_SCOPE = "https://accounts.x.ai/sign-in", EXPIRY_SKEW_MS2, grokHomeOverride = null, claudishOAuthPathOverride = null, GROK_CHANNEL_URL = "https://x.ai/cli/stable", liveClientVersion = null, SIGN_IN_HINT, refreshInFlight = null;
|
|
32258
|
+
var init_grok_credentials = __esm(() => {
|
|
32259
|
+
init_grok_oauth();
|
|
32260
|
+
EXPIRY_SKEW_MS2 = 5 * 60 * 1000;
|
|
32261
|
+
SIGN_IN_HINT = "Run `claudish login grok` (no Grok CLI required \u2014 SuperGrok or X Premium+ subscription). " + "An existing `grok login` (~/.grok/auth.json) is also picked up automatically.";
|
|
32262
|
+
});
|
|
32263
|
+
|
|
32264
|
+
// src/auth/credentials/grok-credential.ts
|
|
32265
|
+
class GrokSubscriptionCredentialProvider {
|
|
32266
|
+
catalogName = "grok-subscription";
|
|
32267
|
+
async isAvailable() {
|
|
32268
|
+
try {
|
|
32269
|
+
return hasGrokCredentials();
|
|
32270
|
+
} catch {
|
|
32271
|
+
return false;
|
|
32272
|
+
}
|
|
32273
|
+
}
|
|
32274
|
+
async getRequestAuth() {
|
|
32275
|
+
const [token, version2] = await Promise.all([
|
|
32276
|
+
resolveGrokAccessToken(),
|
|
32277
|
+
resolveGrokClientVersion()
|
|
32278
|
+
]);
|
|
32279
|
+
return { headers: grokAuthHeaders(token, version2) };
|
|
32280
|
+
}
|
|
32281
|
+
}
|
|
32282
|
+
var init_grok_credential = __esm(() => {
|
|
32283
|
+
init_grok_credentials();
|
|
32284
|
+
});
|
|
32285
|
+
|
|
32286
|
+
// src/auth/kimi-oauth.ts
|
|
32287
|
+
import { exec as exec3 } from "child_process";
|
|
32288
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
32289
|
+
import { closeSync as closeSync4, existsSync as existsSync12, openSync as openSync4, readFileSync as readFileSync11, unlinkSync as unlinkSync4, writeSync as writeSync4 } from "fs";
|
|
32290
|
+
import { homedir as homedir15, hostname as hostname3, platform, release as release2 } from "os";
|
|
32291
|
+
import { join as join15 } from "path";
|
|
32292
|
+
import { promisify as promisify3 } from "util";
|
|
32293
|
+
|
|
31674
32294
|
class KimiOAuth {
|
|
31675
32295
|
static instance = null;
|
|
31676
32296
|
credentials = null;
|
|
@@ -31696,23 +32316,23 @@ class KimiOAuth {
|
|
|
31696
32316
|
return this.credentials !== null && !!this.credentials.refresh_token;
|
|
31697
32317
|
}
|
|
31698
32318
|
getCredentialsPath() {
|
|
31699
|
-
const claudishDir =
|
|
31700
|
-
return
|
|
32319
|
+
const claudishDir = join15(homedir15(), ".claudish");
|
|
32320
|
+
return join15(claudishDir, "kimi-oauth.json");
|
|
31701
32321
|
}
|
|
31702
32322
|
getDeviceIdPath() {
|
|
31703
|
-
const claudishDir =
|
|
31704
|
-
return
|
|
32323
|
+
const claudishDir = join15(homedir15(), ".claudish");
|
|
32324
|
+
return join15(claudishDir, "kimi-device-id");
|
|
31705
32325
|
}
|
|
31706
32326
|
loadOrCreateDeviceId() {
|
|
31707
32327
|
const deviceIdPath = this.getDeviceIdPath();
|
|
31708
|
-
const claudishDir =
|
|
31709
|
-
if (!
|
|
31710
|
-
const { mkdirSync:
|
|
31711
|
-
|
|
32328
|
+
const claudishDir = join15(homedir15(), ".claudish");
|
|
32329
|
+
if (!existsSync12(claudishDir)) {
|
|
32330
|
+
const { mkdirSync: mkdirSync8 } = __require("fs");
|
|
32331
|
+
mkdirSync8(claudishDir, { recursive: true });
|
|
31712
32332
|
}
|
|
31713
|
-
if (
|
|
32333
|
+
if (existsSync12(deviceIdPath)) {
|
|
31714
32334
|
try {
|
|
31715
|
-
const deviceId2 =
|
|
32335
|
+
const deviceId2 = readFileSync11(deviceIdPath, "utf-8").trim();
|
|
31716
32336
|
if (deviceId2) {
|
|
31717
32337
|
return deviceId2;
|
|
31718
32338
|
}
|
|
@@ -31720,13 +32340,13 @@ class KimiOAuth {
|
|
|
31720
32340
|
log(`[KimiOAuth] Failed to load device ID: ${e.message}`);
|
|
31721
32341
|
}
|
|
31722
32342
|
}
|
|
31723
|
-
const deviceId =
|
|
32343
|
+
const deviceId = randomBytes3(16).toString("hex").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
|
|
31724
32344
|
try {
|
|
31725
|
-
const fd =
|
|
32345
|
+
const fd = openSync4(deviceIdPath, "w", 384);
|
|
31726
32346
|
try {
|
|
31727
|
-
|
|
32347
|
+
writeSync4(fd, deviceId, 0, "utf-8");
|
|
31728
32348
|
} finally {
|
|
31729
|
-
|
|
32349
|
+
closeSync4(fd);
|
|
31730
32350
|
}
|
|
31731
32351
|
log(`[KimiOAuth] New device ID created: ${deviceId}`);
|
|
31732
32352
|
} catch (e) {
|
|
@@ -31871,11 +32491,11 @@ Waiting for authorization...`);
|
|
|
31871
32491
|
const currentPlatform = platform();
|
|
31872
32492
|
try {
|
|
31873
32493
|
if (currentPlatform === "darwin") {
|
|
31874
|
-
await
|
|
32494
|
+
await execAsync3(`open "${url2}"`);
|
|
31875
32495
|
} else if (currentPlatform === "win32") {
|
|
31876
|
-
await
|
|
32496
|
+
await execAsync3(`start "${url2}"`);
|
|
31877
32497
|
} else {
|
|
31878
|
-
await
|
|
32498
|
+
await execAsync3(`xdg-open "${url2}"`);
|
|
31879
32499
|
}
|
|
31880
32500
|
} catch (e) {
|
|
31881
32501
|
log(`[KimiOAuth] Failed to open browser: ${e.message}`);
|
|
@@ -31883,8 +32503,8 @@ Waiting for authorization...`);
|
|
|
31883
32503
|
}
|
|
31884
32504
|
async logout() {
|
|
31885
32505
|
const credPath = this.getCredentialsPath();
|
|
31886
|
-
if (
|
|
31887
|
-
|
|
32506
|
+
if (existsSync12(credPath)) {
|
|
32507
|
+
unlinkSync4(credPath);
|
|
31888
32508
|
log("[KimiOAuth] Credentials deleted");
|
|
31889
32509
|
}
|
|
31890
32510
|
this.credentials = null;
|
|
@@ -31950,8 +32570,8 @@ Waiting for authorization...`);
|
|
|
31950
32570
|
} catch (e) {
|
|
31951
32571
|
log(`[KimiOAuth] Refresh failed: ${e.message}`);
|
|
31952
32572
|
const credPath = this.getCredentialsPath();
|
|
31953
|
-
if (
|
|
31954
|
-
|
|
32573
|
+
if (existsSync12(credPath)) {
|
|
32574
|
+
unlinkSync4(credPath);
|
|
31955
32575
|
}
|
|
31956
32576
|
this.credentials = null;
|
|
31957
32577
|
if (process.env.MOONSHOT_API_KEY || process.env.KIMI_API_KEY) {
|
|
@@ -31967,11 +32587,11 @@ Details: ${e.message}`);
|
|
|
31967
32587
|
}
|
|
31968
32588
|
loadCredentials() {
|
|
31969
32589
|
const credPath = this.getCredentialsPath();
|
|
31970
|
-
if (!
|
|
32590
|
+
if (!existsSync12(credPath)) {
|
|
31971
32591
|
return null;
|
|
31972
32592
|
}
|
|
31973
32593
|
try {
|
|
31974
|
-
const data =
|
|
32594
|
+
const data = readFileSync11(credPath, "utf-8");
|
|
31975
32595
|
const credentials2 = JSON.parse(data);
|
|
31976
32596
|
if (!credentials2.access_token || !credentials2.refresh_token || !credentials2.expires_at || !credentials2.scope || !credentials2.token_type) {
|
|
31977
32597
|
log("[KimiOAuth] Invalid credentials file structure");
|
|
@@ -31986,17 +32606,17 @@ Details: ${e.message}`);
|
|
|
31986
32606
|
}
|
|
31987
32607
|
saveCredentials(credentials2) {
|
|
31988
32608
|
const credPath = this.getCredentialsPath();
|
|
31989
|
-
const claudishDir =
|
|
31990
|
-
if (!
|
|
31991
|
-
const { mkdirSync:
|
|
31992
|
-
|
|
32609
|
+
const claudishDir = join15(homedir15(), ".claudish");
|
|
32610
|
+
if (!existsSync12(claudishDir)) {
|
|
32611
|
+
const { mkdirSync: mkdirSync8 } = __require("fs");
|
|
32612
|
+
mkdirSync8(claudishDir, { recursive: true });
|
|
31993
32613
|
}
|
|
31994
|
-
const fd =
|
|
32614
|
+
const fd = openSync4(credPath, "w", 384);
|
|
31995
32615
|
try {
|
|
31996
32616
|
const data = JSON.stringify(credentials2, null, 2);
|
|
31997
|
-
|
|
32617
|
+
writeSync4(fd, data, 0, "utf-8");
|
|
31998
32618
|
} finally {
|
|
31999
|
-
|
|
32619
|
+
closeSync4(fd);
|
|
32000
32620
|
}
|
|
32001
32621
|
log(`[KimiOAuth] Credentials saved to ${credPath}`);
|
|
32002
32622
|
}
|
|
@@ -32004,10 +32624,10 @@ Details: ${e.message}`);
|
|
|
32004
32624
|
function getKimiOAuth() {
|
|
32005
32625
|
return KimiOAuth.getInstance();
|
|
32006
32626
|
}
|
|
32007
|
-
var
|
|
32627
|
+
var execAsync3, OAUTH_CONFIG2;
|
|
32008
32628
|
var init_kimi_oauth = __esm(() => {
|
|
32009
32629
|
init_logger();
|
|
32010
|
-
|
|
32630
|
+
execAsync3 = promisify3(exec3);
|
|
32011
32631
|
OAUTH_CONFIG2 = {
|
|
32012
32632
|
clientId: "17e5f671-d194-4dfb-9706-5516cb48c098",
|
|
32013
32633
|
authHost: "https://auth.kimi.com",
|
|
@@ -32017,18 +32637,18 @@ var init_kimi_oauth = __esm(() => {
|
|
|
32017
32637
|
});
|
|
32018
32638
|
|
|
32019
32639
|
// src/auth/oauth-registry.ts
|
|
32020
|
-
import { existsSync as
|
|
32021
|
-
import { homedir as
|
|
32022
|
-
import { join as
|
|
32640
|
+
import { existsSync as existsSync13, readFileSync as readFileSync12 } from "fs";
|
|
32641
|
+
import { homedir as homedir16 } from "os";
|
|
32642
|
+
import { join as join16 } from "path";
|
|
32023
32643
|
function hasValidOAuthCredentials(descriptor) {
|
|
32024
|
-
const credPath =
|
|
32025
|
-
if (!
|
|
32644
|
+
const credPath = join16(homedir16(), ".claudish", descriptor.credentialFile);
|
|
32645
|
+
if (!existsSync13(credPath))
|
|
32026
32646
|
return false;
|
|
32027
32647
|
if (descriptor.validationMode === "file-exists") {
|
|
32028
32648
|
return true;
|
|
32029
32649
|
}
|
|
32030
32650
|
try {
|
|
32031
|
-
const data = JSON.parse(
|
|
32651
|
+
const data = JSON.parse(readFileSync12(credPath, "utf-8"));
|
|
32032
32652
|
if (!data.access_token)
|
|
32033
32653
|
return false;
|
|
32034
32654
|
if (data.refresh_token)
|
|
@@ -32068,6 +32688,12 @@ var init_oauth_registry = __esm(() => {
|
|
|
32068
32688
|
validationMode: "check-expiry",
|
|
32069
32689
|
expiresAtField: "expires_at",
|
|
32070
32690
|
expiryBufferMs: 5 * 60 * 1000
|
|
32691
|
+
},
|
|
32692
|
+
"grok-subscription": {
|
|
32693
|
+
credentialFile: "grok-oauth.json",
|
|
32694
|
+
validationMode: "check-expiry",
|
|
32695
|
+
expiresAtField: "expires_at",
|
|
32696
|
+
expiryBufferMs: 5 * 60 * 1000
|
|
32071
32697
|
}
|
|
32072
32698
|
};
|
|
32073
32699
|
});
|
|
@@ -32216,11 +32842,11 @@ var init_native_anthropic_credential = __esm(() => {
|
|
|
32216
32842
|
});
|
|
32217
32843
|
|
|
32218
32844
|
// src/auth/vertex-auth.ts
|
|
32219
|
-
import { exec as
|
|
32220
|
-
import { existsSync as
|
|
32221
|
-
import { homedir as
|
|
32222
|
-
import { join as
|
|
32223
|
-
import { promisify as
|
|
32845
|
+
import { exec as exec4 } from "child_process";
|
|
32846
|
+
import { existsSync as existsSync14 } from "fs";
|
|
32847
|
+
import { homedir as homedir17 } from "os";
|
|
32848
|
+
import { join as join17 } from "path";
|
|
32849
|
+
import { promisify as promisify4 } from "util";
|
|
32224
32850
|
|
|
32225
32851
|
class VertexAuthManager {
|
|
32226
32852
|
cachedToken = null;
|
|
@@ -32274,12 +32900,12 @@ class VertexAuthManager {
|
|
|
32274
32900
|
}
|
|
32275
32901
|
async tryADC() {
|
|
32276
32902
|
try {
|
|
32277
|
-
const adcPath =
|
|
32278
|
-
if (!
|
|
32903
|
+
const adcPath = join17(homedir17(), ".config/gcloud/application_default_credentials.json");
|
|
32904
|
+
if (!existsSync14(adcPath)) {
|
|
32279
32905
|
log("[VertexAuth] ADC credentials file not found");
|
|
32280
32906
|
return null;
|
|
32281
32907
|
}
|
|
32282
|
-
const { stdout } = await
|
|
32908
|
+
const { stdout } = await execAsync4("gcloud auth application-default print-access-token", {
|
|
32283
32909
|
timeout: 1e4
|
|
32284
32910
|
});
|
|
32285
32911
|
const token = stdout.trim();
|
|
@@ -32299,13 +32925,13 @@ class VertexAuthManager {
|
|
|
32299
32925
|
if (!credPath) {
|
|
32300
32926
|
return null;
|
|
32301
32927
|
}
|
|
32302
|
-
if (!
|
|
32928
|
+
if (!existsSync14(credPath)) {
|
|
32303
32929
|
throw new Error(`Service account file not found: ${credPath}
|
|
32304
32930
|
|
|
32305
32931
|
Check GOOGLE_APPLICATION_CREDENTIALS path.`);
|
|
32306
32932
|
}
|
|
32307
32933
|
try {
|
|
32308
|
-
const { stdout } = await
|
|
32934
|
+
const { stdout } = await execAsync4(`gcloud auth print-access-token --credential-file-override="${credPath}"`, { timeout: 1e4 });
|
|
32309
32935
|
const token = stdout.trim();
|
|
32310
32936
|
if (!token) {
|
|
32311
32937
|
log("[VertexAuth] Service account returned empty token");
|
|
@@ -32338,8 +32964,8 @@ function validateVertexOAuthConfig() {
|
|
|
32338
32964
|
` + ` export VERTEX_PROJECT='your-gcp-project-id'
|
|
32339
32965
|
` + " export VERTEX_LOCATION='us-central1' # optional";
|
|
32340
32966
|
}
|
|
32341
|
-
const adcPath =
|
|
32342
|
-
const hasADC =
|
|
32967
|
+
const adcPath = join17(homedir17(), ".config/gcloud/application_default_credentials.json");
|
|
32968
|
+
const hasADC = existsSync14(adcPath);
|
|
32343
32969
|
const hasServiceAccount = !!process.env.GOOGLE_APPLICATION_CREDENTIALS;
|
|
32344
32970
|
if (!hasADC && !hasServiceAccount) {
|
|
32345
32971
|
return `No Vertex AI credentials found.
|
|
@@ -32368,10 +32994,10 @@ function getVertexAuthManager() {
|
|
|
32368
32994
|
}
|
|
32369
32995
|
return authManagerInstance;
|
|
32370
32996
|
}
|
|
32371
|
-
var
|
|
32997
|
+
var execAsync4, authManagerInstance = null;
|
|
32372
32998
|
var init_vertex_auth = __esm(() => {
|
|
32373
32999
|
init_logger();
|
|
32374
|
-
|
|
33000
|
+
execAsync4 = promisify4(exec4);
|
|
32375
33001
|
});
|
|
32376
33002
|
|
|
32377
33003
|
// src/auth/credentials/vertex-credential.ts
|
|
@@ -32459,6 +33085,7 @@ class CredentialAuthority {
|
|
|
32459
33085
|
authority.register(makeCodexCredential(), ["openai-codex"]);
|
|
32460
33086
|
authority.register(new AntigravityCredentialProvider, ["antigravity"]);
|
|
32461
33087
|
authority.register(new DevinCredentialProvider, ["devin"]);
|
|
33088
|
+
authority.register(new GrokSubscriptionCredentialProvider, ["grok-subscription"]);
|
|
32462
33089
|
authority.register(makeKimiCredential(), ["kimi"]);
|
|
32463
33090
|
authority.register(makeKimiCodingCredential(), ["kimi-coding"]);
|
|
32464
33091
|
authority.register(new VertexCredentialProvider, ["vertex"]);
|
|
@@ -32502,6 +33129,7 @@ var init_authority = __esm(() => {
|
|
|
32502
33129
|
init_api_key_credential();
|
|
32503
33130
|
init_codex_credential();
|
|
32504
33131
|
init_devin_credential();
|
|
33132
|
+
init_grok_credential();
|
|
32505
33133
|
init_kimi_credential();
|
|
32506
33134
|
init_local_credential();
|
|
32507
33135
|
init_native_anthropic_credential();
|
|
@@ -34640,39 +35268,17 @@ var init_xiaomi_model_dialect = __esm(() => {
|
|
|
34640
35268
|
// src/adapters/dialect-manager.ts
|
|
34641
35269
|
var exports_dialect_manager = {};
|
|
34642
35270
|
__export(exports_dialect_manager, {
|
|
34643
|
-
|
|
34644
|
-
AdapterManager: () => DialectManager
|
|
35271
|
+
resolveModelDialect: () => resolveModelDialect
|
|
34645
35272
|
});
|
|
34646
|
-
|
|
34647
|
-
|
|
34648
|
-
|
|
34649
|
-
|
|
34650
|
-
|
|
34651
|
-
this.adapters = [
|
|
34652
|
-
new GrokModelDialect(modelId, wireFormat),
|
|
34653
|
-
new GeminiAPIFormat(modelId, wireFormat),
|
|
34654
|
-
new CodexAPIFormat(modelId, wireFormat),
|
|
34655
|
-
new OpenAIAPIFormat(modelId, wireFormat),
|
|
34656
|
-
new QwenModelDialect(modelId, wireFormat),
|
|
34657
|
-
new MiniMaxModelDialect(modelId, wireFormat),
|
|
34658
|
-
new DeepSeekModelDialect(modelId, wireFormat),
|
|
34659
|
-
new GLMModelDialect(modelId, wireFormat),
|
|
34660
|
-
new XiaomiModelDialect(modelId, wireFormat)
|
|
34661
|
-
];
|
|
34662
|
-
this.defaultAdapter = new DefaultAPIFormat(modelId, wireFormat);
|
|
34663
|
-
}
|
|
34664
|
-
getAdapter() {
|
|
34665
|
-
for (const adapter of this.adapters) {
|
|
34666
|
-
if (adapter.shouldHandle(this.defaultAdapter.getModelId())) {
|
|
34667
|
-
return adapter;
|
|
34668
|
-
}
|
|
34669
|
-
}
|
|
34670
|
-
return this.defaultAdapter;
|
|
34671
|
-
}
|
|
34672
|
-
needsTransformation() {
|
|
34673
|
-
return this.getAdapter() !== this.defaultAdapter;
|
|
35273
|
+
function resolveModelDialect(modelId, wireFormat) {
|
|
35274
|
+
for (const make of DIALECT_FACTORIES) {
|
|
35275
|
+
const dialect = make(modelId, wireFormat);
|
|
35276
|
+
if (dialect.shouldHandle(modelId))
|
|
35277
|
+
return dialect;
|
|
34674
35278
|
}
|
|
35279
|
+
return new DefaultAPIFormat(modelId, wireFormat);
|
|
34675
35280
|
}
|
|
35281
|
+
var DIALECT_FACTORIES;
|
|
34676
35282
|
var init_dialect_manager = __esm(() => {
|
|
34677
35283
|
init_base_api_format();
|
|
34678
35284
|
init_codex_api_format();
|
|
@@ -34684,6 +35290,17 @@ var init_dialect_manager = __esm(() => {
|
|
|
34684
35290
|
init_openai_api_format();
|
|
34685
35291
|
init_qwen_model_dialect();
|
|
34686
35292
|
init_xiaomi_model_dialect();
|
|
35293
|
+
DIALECT_FACTORIES = [
|
|
35294
|
+
(m, w) => new GrokModelDialect(m, w),
|
|
35295
|
+
(m, w) => new GeminiAPIFormat(m, w),
|
|
35296
|
+
(m, w) => new CodexAPIFormat(m, w),
|
|
35297
|
+
(m, w) => new OpenAIAPIFormat(m, w),
|
|
35298
|
+
(m, w) => new QwenModelDialect(m, w),
|
|
35299
|
+
(m, w) => new MiniMaxModelDialect(m, w),
|
|
35300
|
+
(m, w) => new DeepSeekModelDialect(m, w),
|
|
35301
|
+
(m, w) => new GLMModelDialect(m, w),
|
|
35302
|
+
(m, w) => new XiaomiModelDialect(m, w)
|
|
35303
|
+
];
|
|
34687
35304
|
});
|
|
34688
35305
|
|
|
34689
35306
|
// src/auth/quota/types.ts
|
|
@@ -34819,9 +35436,9 @@ var init_antigravity2 = __esm(() => {
|
|
|
34819
35436
|
});
|
|
34820
35437
|
|
|
34821
35438
|
// src/auth/quota/sources/codex.ts
|
|
34822
|
-
import { existsSync as
|
|
34823
|
-
import { homedir as
|
|
34824
|
-
import { join as
|
|
35439
|
+
import { existsSync as existsSync15, readFileSync as readFileSync13 } from "fs";
|
|
35440
|
+
import { homedir as homedir18 } from "os";
|
|
35441
|
+
import { join as join18 } from "path";
|
|
34825
35442
|
function formatWindowMinutes(minutes) {
|
|
34826
35443
|
if (!Number.isFinite(minutes) || minutes <= 0)
|
|
34827
35444
|
return "";
|
|
@@ -34835,7 +35452,7 @@ function formatWindowMinutes(minutes) {
|
|
|
34835
35452
|
return `${hours}h${minutes % 60}m`;
|
|
34836
35453
|
}
|
|
34837
35454
|
function credentialsPath() {
|
|
34838
|
-
return
|
|
35455
|
+
return join18(homedir18(), ".claudish", "codex-oauth.json");
|
|
34839
35456
|
}
|
|
34840
35457
|
function planLabel(planType) {
|
|
34841
35458
|
if (!planType)
|
|
@@ -34887,10 +35504,10 @@ function scrapeCodexHeaders(headers) {
|
|
|
34887
35504
|
}
|
|
34888
35505
|
function resolveProbeModel() {
|
|
34889
35506
|
try {
|
|
34890
|
-
const cachePath =
|
|
34891
|
-
if (!
|
|
35507
|
+
const cachePath = join18(homedir18(), ".codex", "models_cache.json");
|
|
35508
|
+
if (!existsSync15(cachePath))
|
|
34892
35509
|
return;
|
|
34893
|
-
const cache2 = JSON.parse(
|
|
35510
|
+
const cache2 = JSON.parse(readFileSync13(cachePath, "utf-8"));
|
|
34894
35511
|
for (const m of cache2.models ?? []) {
|
|
34895
35512
|
const slug = m?.slug ?? m?.id;
|
|
34896
35513
|
if (typeof slug === "string" && slug.length > 0)
|
|
@@ -34902,9 +35519,9 @@ function resolveProbeModel() {
|
|
|
34902
35519
|
function readCodexCredentials() {
|
|
34903
35520
|
try {
|
|
34904
35521
|
const path = credentialsPath();
|
|
34905
|
-
if (!
|
|
35522
|
+
if (!existsSync15(path))
|
|
34906
35523
|
return;
|
|
34907
|
-
return JSON.parse(
|
|
35524
|
+
return JSON.parse(readFileSync13(path, "utf-8"));
|
|
34908
35525
|
} catch {
|
|
34909
35526
|
return;
|
|
34910
35527
|
}
|
|
@@ -34935,7 +35552,7 @@ var init_codex = __esm(() => {
|
|
|
34935
35552
|
},
|
|
34936
35553
|
isAvailable() {
|
|
34937
35554
|
try {
|
|
34938
|
-
return
|
|
35555
|
+
return existsSync15(credentialsPath());
|
|
34939
35556
|
} catch {
|
|
34940
35557
|
return false;
|
|
34941
35558
|
}
|
|
@@ -35316,8 +35933,8 @@ var init_harness = __esm(() => {
|
|
|
35316
35933
|
|
|
35317
35934
|
// src/behavior/journal.ts
|
|
35318
35935
|
import { appendFile as appendFile2, mkdir, readFile, rename, stat, writeFile } from "fs/promises";
|
|
35319
|
-
import { homedir as
|
|
35320
|
-
import { dirname as dirname6, join as
|
|
35936
|
+
import { homedir as homedir19 } from "os";
|
|
35937
|
+
import { dirname as dirname6, join as join19 } from "path";
|
|
35321
35938
|
function classifyPath(observed, expected) {
|
|
35322
35939
|
if (!observed)
|
|
35323
35940
|
return "not_applicable";
|
|
@@ -35329,7 +35946,7 @@ function classifyPath(observed, expected) {
|
|
|
35329
35946
|
return dirOf(observed) === dirOf(expected) ? "same_dir_wrong_name" : "outside_expected_dir";
|
|
35330
35947
|
}
|
|
35331
35948
|
function journalPath() {
|
|
35332
|
-
return
|
|
35949
|
+
return join19(homedir19(), ".claudish", "behavior-journal.jsonl");
|
|
35333
35950
|
}
|
|
35334
35951
|
async function prune(path) {
|
|
35335
35952
|
const content = await readFile(path, "utf8");
|
|
@@ -35388,10 +36005,10 @@ __export(exports_aggregate, {
|
|
|
35388
36005
|
contextBucket: () => contextBucket,
|
|
35389
36006
|
TELEMETRY_SCHEMA_VERSION: () => TELEMETRY_SCHEMA_VERSION
|
|
35390
36007
|
});
|
|
35391
|
-
import { createHash as
|
|
35392
|
-
import { appendFileSync as appendFileSync2, mkdirSync as
|
|
35393
|
-
import { homedir as
|
|
35394
|
-
import { dirname as dirname7, join as
|
|
36008
|
+
import { createHash as createHash4, randomBytes as randomBytes4 } from "crypto";
|
|
36009
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync8 } from "fs";
|
|
36010
|
+
import { homedir as homedir20 } from "os";
|
|
36011
|
+
import { dirname as dirname7, join as join20 } from "path";
|
|
35395
36012
|
function contextBucket(inputTokens) {
|
|
35396
36013
|
if (inputTokens < 50000)
|
|
35397
36014
|
return "0-50k";
|
|
@@ -35412,7 +36029,7 @@ function contextFillPct(peakTokens, window2 = enforcedContextWindow) {
|
|
|
35412
36029
|
return Math.min(100, Math.max(0, Math.round(peakTokens / window2 * 100)));
|
|
35413
36030
|
}
|
|
35414
36031
|
function hashSessionId(rawSessionId, model) {
|
|
35415
|
-
return
|
|
36032
|
+
return createHash4("sha256").update(`${SESSION_SALT}:${rawSessionId}:${model}`).digest("hex");
|
|
35416
36033
|
}
|
|
35417
36034
|
function setTelemetryConsent(value) {
|
|
35418
36035
|
consent = value;
|
|
@@ -35509,7 +36126,7 @@ function pendingReports() {
|
|
|
35509
36126
|
return [...sessions.values()].map(toReport);
|
|
35510
36127
|
}
|
|
35511
36128
|
function outboxPath() {
|
|
35512
|
-
return
|
|
36129
|
+
return join20(homedir20(), ".claudish", "behavior-outbox.jsonl");
|
|
35513
36130
|
}
|
|
35514
36131
|
function spoolPendingSync(path = outboxPath()) {
|
|
35515
36132
|
if (sessions.size === 0)
|
|
@@ -35519,7 +36136,7 @@ function spoolPendingSync(path = outboxPath()) {
|
|
|
35519
36136
|
if (reports.length === 0)
|
|
35520
36137
|
return 0;
|
|
35521
36138
|
try {
|
|
35522
|
-
|
|
36139
|
+
mkdirSync8(dirname7(path), { recursive: true });
|
|
35523
36140
|
appendFileSync2(path, `${reports.map((r) => JSON.stringify(r)).join(`
|
|
35524
36141
|
`)}
|
|
35525
36142
|
`);
|
|
@@ -35532,7 +36149,7 @@ function spoolPendingSync(path = outboxPath()) {
|
|
|
35532
36149
|
var TELEMETRY_SCHEMA_VERSION = 1, enforcedContextWindow = 0, SESSION_SALT, MAX_TRACKED_SESSIONS = 32, MAX_DECISION_KEYS = 200, sessions, consent = false;
|
|
35533
36150
|
var init_aggregate = __esm(() => {
|
|
35534
36151
|
init_logger();
|
|
35535
|
-
SESSION_SALT =
|
|
36152
|
+
SESSION_SALT = randomBytes4(32).toString("hex");
|
|
35536
36153
|
sessions = new Map;
|
|
35537
36154
|
process.on("exit", () => {
|
|
35538
36155
|
try {
|
|
@@ -35737,10 +36354,10 @@ __export(exports_live_log, {
|
|
|
35737
36354
|
recordLiveDivergence: () => recordLiveDivergence
|
|
35738
36355
|
});
|
|
35739
36356
|
import { appendFile as appendFile3 } from "fs/promises";
|
|
35740
|
-
import { homedir as
|
|
35741
|
-
import { join as
|
|
36357
|
+
import { homedir as homedir21 } from "os";
|
|
36358
|
+
import { join as join21 } from "path";
|
|
35742
36359
|
function defaultPath() {
|
|
35743
|
-
return
|
|
36360
|
+
return join21(homedir21(), ".claudish", "behavior-divergences.jsonl");
|
|
35744
36361
|
}
|
|
35745
36362
|
async function recordLiveDivergence(entry, path = defaultPath()) {
|
|
35746
36363
|
try {
|
|
@@ -36436,9 +37053,9 @@ var init_hooks = __esm(() => {
|
|
|
36436
37053
|
});
|
|
36437
37054
|
|
|
36438
37055
|
// src/behavior/observer/corpus.ts
|
|
36439
|
-
import { appendFileSync as appendFileSync3, readFileSync as
|
|
36440
|
-
import { homedir as
|
|
36441
|
-
import { join as
|
|
37056
|
+
import { appendFileSync as appendFileSync3, readFileSync as readFileSync14, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
37057
|
+
import { homedir as homedir22 } from "os";
|
|
37058
|
+
import { join as join22 } from "path";
|
|
36442
37059
|
function directoryOf2(filePath) {
|
|
36443
37060
|
const slash = filePath.lastIndexOf("/");
|
|
36444
37061
|
return slash > 0 ? filePath.slice(0, slash) : undefined;
|
|
@@ -36460,7 +37077,7 @@ function writeTargetsOf(row) {
|
|
|
36460
37077
|
function replayTranscript(file2) {
|
|
36461
37078
|
let text;
|
|
36462
37079
|
try {
|
|
36463
|
-
text =
|
|
37080
|
+
text = readFileSync14(file2, "utf8");
|
|
36464
37081
|
} catch {
|
|
36465
37082
|
return [];
|
|
36466
37083
|
}
|
|
@@ -36517,26 +37134,26 @@ function listTranscripts(root) {
|
|
|
36517
37134
|
return files;
|
|
36518
37135
|
}
|
|
36519
37136
|
for (const project of projects) {
|
|
36520
|
-
const dir =
|
|
37137
|
+
const dir = join22(root, project);
|
|
36521
37138
|
try {
|
|
36522
37139
|
if (!statSync2(dir).isDirectory())
|
|
36523
37140
|
continue;
|
|
36524
37141
|
for (const f of readdirSync2(dir)) {
|
|
36525
37142
|
if (f.endsWith(".jsonl"))
|
|
36526
|
-
files.push(
|
|
37143
|
+
files.push(join22(dir, f));
|
|
36527
37144
|
}
|
|
36528
37145
|
} catch {}
|
|
36529
37146
|
}
|
|
36530
37147
|
return files;
|
|
36531
37148
|
}
|
|
36532
37149
|
function buildCorpus(options = {}) {
|
|
36533
|
-
const root = options.projectsRoot ??
|
|
37150
|
+
const root = options.projectsRoot ?? join22(homedir22(), ".claude", "projects");
|
|
36534
37151
|
const files = listTranscripts(root);
|
|
36535
37152
|
const records = [];
|
|
36536
37153
|
for (const f of files)
|
|
36537
37154
|
records.push(...replayTranscript(f));
|
|
36538
37155
|
if (options.write && records.length > 0) {
|
|
36539
|
-
const outputPath = options.outputPath ??
|
|
37156
|
+
const outputPath = options.outputPath ?? join22(homedir22(), ".claudish", "behavior-divergences.jsonl");
|
|
36540
37157
|
try {
|
|
36541
37158
|
appendFileSync3(outputPath, `${records.map((r) => JSON.stringify(r)).join(`
|
|
36542
37159
|
`)}
|
|
@@ -36906,6 +37523,9 @@ class OpenAIProviderTransport {
|
|
|
36906
37523
|
}
|
|
36907
37524
|
return `${this.provider.baseUrl}${this.provider.apiPath}`;
|
|
36908
37525
|
}
|
|
37526
|
+
overrideStreamFormat() {
|
|
37527
|
+
return this.provider.streamFormatOverride;
|
|
37528
|
+
}
|
|
36909
37529
|
async getHeaders() {
|
|
36910
37530
|
const headers = {};
|
|
36911
37531
|
if (this.apiKey) {
|
|
@@ -37311,25 +37931,25 @@ var init_model_parser = __esm(() => {
|
|
|
37311
37931
|
|
|
37312
37932
|
// src/stats-buffer.ts
|
|
37313
37933
|
import {
|
|
37314
|
-
existsSync as
|
|
37315
|
-
mkdirSync as
|
|
37316
|
-
readFileSync as
|
|
37317
|
-
renameSync,
|
|
37318
|
-
unlinkSync as
|
|
37319
|
-
writeFileSync as
|
|
37934
|
+
existsSync as existsSync16,
|
|
37935
|
+
mkdirSync as mkdirSync9,
|
|
37936
|
+
readFileSync as readFileSync15,
|
|
37937
|
+
renameSync as renameSync2,
|
|
37938
|
+
unlinkSync as unlinkSync5,
|
|
37939
|
+
writeFileSync as writeFileSync8
|
|
37320
37940
|
} from "fs";
|
|
37321
|
-
import { homedir as
|
|
37322
|
-
import { join as
|
|
37941
|
+
import { homedir as homedir23 } from "os";
|
|
37942
|
+
import { join as join23 } from "path";
|
|
37323
37943
|
function ensureDir() {
|
|
37324
|
-
if (!
|
|
37325
|
-
|
|
37944
|
+
if (!existsSync16(CLAUDISH_DIR)) {
|
|
37945
|
+
mkdirSync9(CLAUDISH_DIR, { recursive: true });
|
|
37326
37946
|
}
|
|
37327
37947
|
}
|
|
37328
37948
|
function readFromDisk() {
|
|
37329
37949
|
try {
|
|
37330
|
-
if (!
|
|
37950
|
+
if (!existsSync16(BUFFER_FILE))
|
|
37331
37951
|
return [];
|
|
37332
|
-
const raw =
|
|
37952
|
+
const raw = readFileSync15(BUFFER_FILE, "utf-8");
|
|
37333
37953
|
const parsed = JSON.parse(raw);
|
|
37334
37954
|
if (!Array.isArray(parsed.events))
|
|
37335
37955
|
return [];
|
|
@@ -37354,9 +37974,9 @@ function writeToDisk(events) {
|
|
|
37354
37974
|
ensureDir();
|
|
37355
37975
|
const trimmed2 = enforceSizeCap([...events]);
|
|
37356
37976
|
const payload = { version: 1, events: trimmed2 };
|
|
37357
|
-
const tmpFile =
|
|
37358
|
-
|
|
37359
|
-
|
|
37977
|
+
const tmpFile = join23(CLAUDISH_DIR, `stats-buffer.tmp.${process.pid}.json`);
|
|
37978
|
+
writeFileSync8(tmpFile, JSON.stringify(payload, null, 2), "utf-8");
|
|
37979
|
+
renameSync2(tmpFile, BUFFER_FILE);
|
|
37360
37980
|
memoryCache = trimmed2;
|
|
37361
37981
|
} catch {}
|
|
37362
37982
|
}
|
|
@@ -37398,8 +38018,8 @@ function clearBuffer() {
|
|
|
37398
38018
|
try {
|
|
37399
38019
|
memoryCache = [];
|
|
37400
38020
|
eventsSinceLastFlush = 0;
|
|
37401
|
-
if (
|
|
37402
|
-
|
|
38021
|
+
if (existsSync16(BUFFER_FILE)) {
|
|
38022
|
+
unlinkSync5(BUFFER_FILE);
|
|
37403
38023
|
}
|
|
37404
38024
|
} catch {}
|
|
37405
38025
|
}
|
|
@@ -37427,8 +38047,8 @@ function syncFlushOnExit() {
|
|
|
37427
38047
|
var BUFFER_MAX_BYTES, CLAUDISH_DIR, BUFFER_FILE, memoryCache = null, eventsSinceLastFlush = 0, flushScheduled = false;
|
|
37428
38048
|
var init_stats_buffer = __esm(() => {
|
|
37429
38049
|
BUFFER_MAX_BYTES = 64 * 1024;
|
|
37430
|
-
CLAUDISH_DIR =
|
|
37431
|
-
BUFFER_FILE =
|
|
38050
|
+
CLAUDISH_DIR = join23(homedir23(), ".claudish");
|
|
38051
|
+
BUFFER_FILE = join23(CLAUDISH_DIR, "stats-buffer.json");
|
|
37432
38052
|
process.on("exit", syncFlushOnExit);
|
|
37433
38053
|
process.on("SIGTERM", () => {
|
|
37434
38054
|
try {
|
|
@@ -37565,7 +38185,7 @@ __export(exports_telemetry, {
|
|
|
37565
38185
|
classifyError: () => classifyError,
|
|
37566
38186
|
buildReport: () => buildReport
|
|
37567
38187
|
});
|
|
37568
|
-
import { randomBytes as
|
|
38188
|
+
import { randomBytes as randomBytes5 } from "crypto";
|
|
37569
38189
|
function getVersion() {
|
|
37570
38190
|
return VERSION;
|
|
37571
38191
|
}
|
|
@@ -37833,7 +38453,7 @@ function initTelemetry(_config) {
|
|
|
37833
38453
|
} catch {
|
|
37834
38454
|
consentEnabled = false;
|
|
37835
38455
|
}
|
|
37836
|
-
sessionId =
|
|
38456
|
+
sessionId = randomBytes5(8).toString("hex");
|
|
37837
38457
|
claudishVersion = getVersion();
|
|
37838
38458
|
installMethod = detectInstallMethod();
|
|
37839
38459
|
}
|
|
@@ -38356,6 +38976,8 @@ function extractProviderMessage(body) {
|
|
|
38356
38976
|
function isTerminalError(status, bodyText, terminal429) {
|
|
38357
38977
|
if (status === 401 || status === 403)
|
|
38358
38978
|
return true;
|
|
38979
|
+
if (status === 426)
|
|
38980
|
+
return true;
|
|
38359
38981
|
if (status === 429 && terminal429)
|
|
38360
38982
|
return true;
|
|
38361
38983
|
const lower = (bodyText || "").toLowerCase();
|
|
@@ -39237,6 +39859,44 @@ data: {"type":"ping"}
|
|
|
39237
39859
|
let insideThinkingBlock = false;
|
|
39238
39860
|
let thinkingBlocksSuppressed = 0;
|
|
39239
39861
|
let suppressedFrame = false;
|
|
39862
|
+
let highestSeenIndex = -1;
|
|
39863
|
+
const remappedBlocks = new Map;
|
|
39864
|
+
const trackIndex = (idx) => {
|
|
39865
|
+
if (idx > highestSeenIndex)
|
|
39866
|
+
highestSeenIndex = idx;
|
|
39867
|
+
};
|
|
39868
|
+
const emitIndexed = (controller2, data, line) => {
|
|
39869
|
+
if (typeof data.index !== "number") {
|
|
39870
|
+
enqueueData(controller2, data, line);
|
|
39871
|
+
return;
|
|
39872
|
+
}
|
|
39873
|
+
if (data.type === "content_block_start") {
|
|
39874
|
+
const expected = highestSeenIndex + 1;
|
|
39875
|
+
if (data.index !== expected) {
|
|
39876
|
+
log(`[AnthropicSSE] content_block_start index ${data.index} remapped to ${expected} (model=${opts.modelName})`);
|
|
39877
|
+
remappedBlocks.set(data.index, expected);
|
|
39878
|
+
const remapped2 = { ...data, index: expected };
|
|
39879
|
+
enqueueData(controller2, remapped2, `data: ${JSON.stringify(remapped2)}`);
|
|
39880
|
+
} else {
|
|
39881
|
+
enqueueData(controller2, data, line);
|
|
39882
|
+
}
|
|
39883
|
+
trackIndex(expected);
|
|
39884
|
+
return;
|
|
39885
|
+
}
|
|
39886
|
+
const remapped = remappedBlocks.get(data.index);
|
|
39887
|
+
if (data.type === "content_block_stop")
|
|
39888
|
+
remappedBlocks.delete(data.index);
|
|
39889
|
+
if (remapped !== undefined) {
|
|
39890
|
+
const modified = { ...data, index: remapped };
|
|
39891
|
+
enqueueData(controller2, modified, `data: ${JSON.stringify(modified)}`);
|
|
39892
|
+
} else if (data.index > highestSeenIndex) {
|
|
39893
|
+
log(`[AnthropicSSE] Dropping orphan ${data.type} at index ${data.index} (no open block \u2014 model=${opts.modelName})`);
|
|
39894
|
+
pendingEventLine = null;
|
|
39895
|
+
suppressedFrame = true;
|
|
39896
|
+
} else {
|
|
39897
|
+
enqueueData(controller2, data, line);
|
|
39898
|
+
}
|
|
39899
|
+
};
|
|
39240
39900
|
while (true) {
|
|
39241
39901
|
const { done, value } = await reader.read();
|
|
39242
39902
|
if (done)
|
|
@@ -39291,18 +39951,7 @@ data: ${JSON.stringify({
|
|
|
39291
39951
|
suppressedFrame = true;
|
|
39292
39952
|
continue;
|
|
39293
39953
|
}
|
|
39294
|
-
|
|
39295
|
-
const reindexed = data.index - thinkingBlocksSuppressed;
|
|
39296
|
-
const modifiedLine = `data: ${JSON.stringify({ ...data, index: reindexed })}`;
|
|
39297
|
-
if (!isClosed) {
|
|
39298
|
-
flushPendingEvent(controller);
|
|
39299
|
-
controller.enqueue(encoder.encode(`${modifiedLine}
|
|
39300
|
-
`));
|
|
39301
|
-
noteLifecycle(data, reindexed);
|
|
39302
|
-
}
|
|
39303
|
-
} else {
|
|
39304
|
-
enqueueData(controller, data, line);
|
|
39305
|
-
}
|
|
39954
|
+
emitIndexed(controller, data, line);
|
|
39306
39955
|
} catch {
|
|
39307
39956
|
if (!isClosed) {
|
|
39308
39957
|
flushPendingEvent(controller);
|
|
@@ -39334,47 +39983,44 @@ data: ${JSON.stringify({
|
|
|
39334
39983
|
}
|
|
39335
39984
|
return;
|
|
39336
39985
|
}
|
|
39337
|
-
|
|
39338
|
-
|
|
39339
|
-
|
|
39340
|
-
|
|
39341
|
-
|
|
39342
|
-
|
|
39343
|
-
|
|
39344
|
-
|
|
39345
|
-
|
|
39346
|
-
|
|
39347
|
-
|
|
39348
|
-
|
|
39349
|
-
|
|
39350
|
-
|
|
39351
|
-
|
|
39352
|
-
|
|
39353
|
-
|
|
39354
|
-
|
|
39355
|
-
|
|
39356
|
-
|
|
39357
|
-
|
|
39358
|
-
|
|
39359
|
-
|
|
39986
|
+
emitIndexed(controller, data, line);
|
|
39987
|
+
try {
|
|
39988
|
+
if (data.message?.usage) {
|
|
39989
|
+
inputTokens = data.message.usage.input_tokens || inputTokens;
|
|
39990
|
+
outputTokens = data.message.usage.output_tokens || outputTokens;
|
|
39991
|
+
}
|
|
39992
|
+
if (data.usage) {
|
|
39993
|
+
inputTokens = data.usage.input_tokens || inputTokens;
|
|
39994
|
+
outputTokens = data.usage.output_tokens || outputTokens;
|
|
39995
|
+
}
|
|
39996
|
+
if (data.type === "content_block_delta" && data.delta?.type === "text_delta") {
|
|
39997
|
+
const txt = data.delta.text || "";
|
|
39998
|
+
opts.onAssistantText?.(txt, "text");
|
|
39999
|
+
textChunks++;
|
|
40000
|
+
log(`[AnthropicSSE] Text chunk: "${txt.substring(0, 30).replace(/\n/g, "\\n")}" (${txt.length} chars)`);
|
|
40001
|
+
}
|
|
40002
|
+
if (data.type === "content_block_start" && data.content_block?.type === "tool_use") {
|
|
40003
|
+
toolUseBlocks++;
|
|
40004
|
+
opts.onToolCallObserved?.(data.content_block.name);
|
|
40005
|
+
log(`[AnthropicSSE] Tool use: ${data.content_block.name}`);
|
|
40006
|
+
}
|
|
40007
|
+
if (data.type === "message_delta" && data.delta?.stop_reason) {
|
|
40008
|
+
stopReason = data.delta.stop_reason;
|
|
40009
|
+
}
|
|
40010
|
+
} catch {}
|
|
39360
40011
|
} catch {
|
|
39361
40012
|
if (!isClosed) {
|
|
39362
40013
|
controller.enqueue(encoder.encode(`${line}
|
|
39363
40014
|
`));
|
|
39364
40015
|
}
|
|
39365
40016
|
}
|
|
39366
|
-
} else
|
|
40017
|
+
} else {
|
|
39367
40018
|
if (line.startsWith("event:")) {
|
|
39368
40019
|
pendingEventLine = line;
|
|
39369
40020
|
} else if (line.trim() === "" && suppressedFrame) {
|
|
39370
40021
|
suppressedFrame = false;
|
|
39371
40022
|
} else if (!isClosed) {
|
|
39372
40023
|
controller.enqueue(encoder.encode(`${line}
|
|
39373
|
-
`));
|
|
39374
|
-
}
|
|
39375
|
-
} else {
|
|
39376
|
-
if (!isClosed) {
|
|
39377
|
-
controller.enqueue(encoder.encode(`${line}
|
|
39378
40024
|
`));
|
|
39379
40025
|
}
|
|
39380
40026
|
}
|
|
@@ -40639,9 +41285,9 @@ var init_openai_responses_sse = __esm(() => {
|
|
|
40639
41285
|
});
|
|
40640
41286
|
|
|
40641
41287
|
// src/handlers/shared/token-tracker.ts
|
|
40642
|
-
import { mkdirSync as
|
|
40643
|
-
import { homedir as
|
|
40644
|
-
import { dirname as dirname8, join as
|
|
41288
|
+
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync9 } from "fs";
|
|
41289
|
+
import { homedir as homedir24 } from "os";
|
|
41290
|
+
import { dirname as dirname8, join as join24 } from "path";
|
|
40645
41291
|
function stripProviderPrefix(name) {
|
|
40646
41292
|
const at = name.indexOf("@");
|
|
40647
41293
|
return at === -1 ? name : name.slice(at + 1);
|
|
@@ -40829,9 +41475,9 @@ class TokenTracker {
|
|
|
40829
41475
|
};
|
|
40830
41476
|
}
|
|
40831
41477
|
const override = process.env.CLAUDISH_TOKEN_FILE;
|
|
40832
|
-
const outPath = override ||
|
|
40833
|
-
|
|
40834
|
-
|
|
41478
|
+
const outPath = override || join24(homedir24(), ".claudish", `tokens-${this.port}.json`);
|
|
41479
|
+
mkdirSync10(dirname8(outPath), { recursive: true });
|
|
41480
|
+
writeFileSync9(outPath, JSON.stringify(data), "utf-8");
|
|
40835
41481
|
} catch (e) {
|
|
40836
41482
|
log(`[TokenTracker] Error writing token file: ${e}`);
|
|
40837
41483
|
}
|
|
@@ -40854,7 +41500,7 @@ function extractAuthHeaders(c) {
|
|
|
40854
41500
|
|
|
40855
41501
|
class ComposedHandler {
|
|
40856
41502
|
provider;
|
|
40857
|
-
|
|
41503
|
+
resolvedDialect;
|
|
40858
41504
|
explicitAdapter;
|
|
40859
41505
|
modelAdapter;
|
|
40860
41506
|
middlewareManager;
|
|
@@ -40876,8 +41522,8 @@ class ComposedHandler {
|
|
|
40876
41522
|
this.options = options;
|
|
40877
41523
|
this.explicitAdapter = options.adapter;
|
|
40878
41524
|
this.isInteractive = options.isInteractive ?? false;
|
|
40879
|
-
this.
|
|
40880
|
-
const resolvedModelAdapter = this.
|
|
41525
|
+
this.resolvedDialect = resolveModelDialect(this.bareModelName, this.explicitAdapter?.getStreamFormat());
|
|
41526
|
+
const resolvedModelAdapter = this.resolvedDialect;
|
|
40881
41527
|
if (resolvedModelAdapter.getName() !== "DefaultAPIFormat") {
|
|
40882
41528
|
this.modelAdapter = resolvedModelAdapter;
|
|
40883
41529
|
}
|
|
@@ -40895,7 +41541,7 @@ class ComposedHandler {
|
|
|
40895
41541
|
});
|
|
40896
41542
|
}
|
|
40897
41543
|
getAdapter() {
|
|
40898
|
-
return this.explicitAdapter || this.
|
|
41544
|
+
return this.explicitAdapter || this.resolvedDialect;
|
|
40899
41545
|
}
|
|
40900
41546
|
getModelContextWindow() {
|
|
40901
41547
|
return this.modelAdapter?.getContextWindow() ?? this.getAdapter().getContextWindow();
|
|
@@ -42854,6 +43500,9 @@ class AnthropicProviderTransport {
|
|
|
42854
43500
|
getEndpoint() {
|
|
42855
43501
|
return `${this.provider.baseUrl}${this.provider.apiPath}`;
|
|
42856
43502
|
}
|
|
43503
|
+
overrideStreamFormat() {
|
|
43504
|
+
return this.provider.streamFormatOverride;
|
|
43505
|
+
}
|
|
42857
43506
|
async getHeaders() {
|
|
42858
43507
|
const headers = {
|
|
42859
43508
|
"anthropic-version": "2023-06-01"
|
|
@@ -43200,7 +43849,8 @@ function buildComplexHandler(ep, ctx, apiKey, baseUrl) {
|
|
|
43200
43849
|
apiKeyEnvVar: ctx.provider.apiKeyEnvVar,
|
|
43201
43850
|
prefixes: ctx.provider.prefixes ?? [],
|
|
43202
43851
|
headers: ep.headers,
|
|
43203
|
-
authScheme: ep.authScheme ?? "bearer"
|
|
43852
|
+
authScheme: ep.authScheme ?? "bearer",
|
|
43853
|
+
streamFormatOverride: ep.streamFormat
|
|
43204
43854
|
};
|
|
43205
43855
|
const transport = new OpenAIProviderTransport(remoteProvider, finalModel, apiKey);
|
|
43206
43856
|
const adapter = new OpenAIAPIFormat(finalModel);
|
|
@@ -43218,7 +43868,8 @@ function buildComplexHandler(ep, ctx, apiKey, baseUrl) {
|
|
|
43218
43868
|
apiKeyEnvVar: ctx.provider.apiKeyEnvVar,
|
|
43219
43869
|
prefixes: ctx.provider.prefixes ?? [],
|
|
43220
43870
|
headers: ep.headers,
|
|
43221
|
-
authScheme: ep.authScheme ?? "x-api-key"
|
|
43871
|
+
authScheme: ep.authScheme ?? "x-api-key",
|
|
43872
|
+
streamFormatOverride: ep.streamFormat
|
|
43222
43873
|
};
|
|
43223
43874
|
const transport = new AnthropicProviderTransport(remoteProvider, apiKey);
|
|
43224
43875
|
const adapter = new AnthropicAPIFormat(finalModel, ctx.provider.name);
|
|
@@ -44089,7 +44740,7 @@ var init_default_routing_rules = __esm(() => {
|
|
|
44089
44740
|
"o1-*": ["openai-codex", "openai", "openrouter"],
|
|
44090
44741
|
"o3-*": ["openai-codex", "openai", "openrouter"],
|
|
44091
44742
|
"gemini-*": ["antigravity", "google", "openrouter"],
|
|
44092
|
-
"grok-*": ["x-ai", "openrouter"],
|
|
44743
|
+
"grok-*": ["grok-subscription", "x-ai", "openrouter"],
|
|
44093
44744
|
"kimi-*": ["kimi-coding", "opencode-zen-go", "kimi", "openrouter"],
|
|
44094
44745
|
"k3*": ["kimi-coding", "opencode-zen-go", "kimi", "openrouter"],
|
|
44095
44746
|
"minimax-*": ["minimax-coding", "opencode-zen-go", "minimax", "openrouter"],
|
|
@@ -45012,9 +45663,9 @@ var CLAUDISH_BIN_ENV = "CLAUDISH_BIN";
|
|
|
45012
45663
|
// src/channel/session-manager.ts
|
|
45013
45664
|
import { spawn } from "child_process";
|
|
45014
45665
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
45015
|
-
import { createWriteStream, mkdirSync as
|
|
45016
|
-
import { homedir as
|
|
45017
|
-
import { join as
|
|
45666
|
+
import { createWriteStream, mkdirSync as mkdirSync11, writeFileSync as writeFileSync10 } from "fs";
|
|
45667
|
+
import { homedir as homedir25 } from "os";
|
|
45668
|
+
import { join as join25 } from "path";
|
|
45018
45669
|
|
|
45019
45670
|
class SessionManager {
|
|
45020
45671
|
sessions = new Map;
|
|
@@ -45026,7 +45677,7 @@ class SessionManager {
|
|
|
45026
45677
|
constructor(options) {
|
|
45027
45678
|
this.maxSessions = options?.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
|
45028
45679
|
this.scrollbackCapacity = options?.scrollbackCapacity ?? DEFAULT_SCROLLBACK;
|
|
45029
|
-
this.sessionsDir = options?.sessionsDir ?? process.env.CLAUDISH_SESSIONS_DIR ??
|
|
45680
|
+
this.sessionsDir = options?.sessionsDir ?? process.env.CLAUDISH_SESSIONS_DIR ?? join25(homedir25(), ".claudish", "sessions");
|
|
45030
45681
|
this.onStateChange = options?.onStateChange;
|
|
45031
45682
|
}
|
|
45032
45683
|
createSession(opts) {
|
|
@@ -45036,10 +45687,10 @@ class SessionManager {
|
|
|
45036
45687
|
const sessionId2 = randomUUID4().slice(0, 8);
|
|
45037
45688
|
const timeout = Math.min(opts.timeoutSeconds ?? DEFAULT_TIMEOUT, MAX_TIMEOUT);
|
|
45038
45689
|
const startedAt = new Date().toISOString();
|
|
45039
|
-
const sessionDir =
|
|
45040
|
-
|
|
45690
|
+
const sessionDir = join25(this.sessionsDir, sessionId2);
|
|
45691
|
+
mkdirSync11(sessionDir, { recursive: true });
|
|
45041
45692
|
if (opts.prompt) {
|
|
45042
|
-
|
|
45693
|
+
writeFileSync10(join25(sessionDir, "prompt.md"), opts.prompt, "utf-8");
|
|
45043
45694
|
}
|
|
45044
45695
|
const args = [
|
|
45045
45696
|
"--model",
|
|
@@ -45075,7 +45726,7 @@ class SessionManager {
|
|
|
45075
45726
|
});
|
|
45076
45727
|
}
|
|
45077
45728
|
});
|
|
45078
|
-
const outputLogStream = createWriteStream(
|
|
45729
|
+
const outputLogStream = createWriteStream(join25(sessionDir, "output.log"));
|
|
45079
45730
|
const entry = {
|
|
45080
45731
|
info: {
|
|
45081
45732
|
sessionId: sessionId2,
|
|
@@ -45122,9 +45773,9 @@ class SessionManager {
|
|
|
45122
45773
|
watcher.processExited(code);
|
|
45123
45774
|
outputLogStream.end();
|
|
45124
45775
|
if (entry.stderr) {
|
|
45125
|
-
|
|
45776
|
+
writeFileSync10(join25(sessionDir, "stderr.log"), entry.stderr, "utf-8");
|
|
45126
45777
|
}
|
|
45127
|
-
|
|
45778
|
+
writeFileSync10(join25(sessionDir, "meta.json"), JSON.stringify(entry.info, null, 2), "utf-8");
|
|
45128
45779
|
this.cleanupSigint();
|
|
45129
45780
|
});
|
|
45130
45781
|
proc.on("error", (err) => {
|
|
@@ -45434,9 +46085,9 @@ function compareByReleaseDateDesc(a, b) {
|
|
|
45434
46085
|
}
|
|
45435
46086
|
|
|
45436
46087
|
// src/model-loader.ts
|
|
45437
|
-
import { existsSync as
|
|
45438
|
-
import { homedir as
|
|
45439
|
-
import { join as
|
|
46088
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync12, readFileSync as readFileSync16, writeFileSync as writeFileSync11 } from "fs";
|
|
46089
|
+
import { homedir as homedir26 } from "os";
|
|
46090
|
+
import { join as join26 } from "path";
|
|
45440
46091
|
function groupRecommendedModels(entries) {
|
|
45441
46092
|
const byId = new Map;
|
|
45442
46093
|
const categoryOrder = new Map;
|
|
@@ -45546,9 +46197,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
45546
46197
|
if (!forceRefresh && _cachedRecommendedModels) {
|
|
45547
46198
|
return _cachedRecommendedModels;
|
|
45548
46199
|
}
|
|
45549
|
-
if (!forceRefresh &&
|
|
46200
|
+
if (!forceRefresh && existsSync17(RECOMMENDED_MODELS_CACHE_PATH)) {
|
|
45550
46201
|
try {
|
|
45551
|
-
const cacheData = JSON.parse(
|
|
46202
|
+
const cacheData = JSON.parse(readFileSync16(RECOMMENDED_MODELS_CACHE_PATH, "utf-8"));
|
|
45552
46203
|
if (cacheData.models && cacheData.models.length > 0 && isFreshEnough(cacheData)) {
|
|
45553
46204
|
_cachedRecommendedModels = cacheData;
|
|
45554
46205
|
return cacheData;
|
|
@@ -45564,9 +46215,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
45564
46215
|
if (data.models && data.models.length > 0) {
|
|
45565
46216
|
_cachedRecommendedModels = data;
|
|
45566
46217
|
try {
|
|
45567
|
-
const cacheDir =
|
|
45568
|
-
|
|
45569
|
-
|
|
46218
|
+
const cacheDir = join26(homedir26(), ".claudish");
|
|
46219
|
+
mkdirSync12(cacheDir, { recursive: true });
|
|
46220
|
+
writeFileSync11(RECOMMENDED_MODELS_CACHE_PATH, JSON.stringify(data), "utf-8");
|
|
45570
46221
|
} catch {}
|
|
45571
46222
|
return data;
|
|
45572
46223
|
}
|
|
@@ -45577,9 +46228,9 @@ async function getRecommendedModels(opts = {}) {
|
|
|
45577
46228
|
function getRecommendedModelsSync() {
|
|
45578
46229
|
if (_cachedRecommendedModels)
|
|
45579
46230
|
return _cachedRecommendedModels;
|
|
45580
|
-
if (
|
|
46231
|
+
if (existsSync17(RECOMMENDED_MODELS_CACHE_PATH)) {
|
|
45581
46232
|
try {
|
|
45582
|
-
const cacheData = JSON.parse(
|
|
46233
|
+
const cacheData = JSON.parse(readFileSync16(RECOMMENDED_MODELS_CACHE_PATH, "utf-8"));
|
|
45583
46234
|
if (cacheData.models && cacheData.models.length > 0 && isFreshEnough(cacheData)) {
|
|
45584
46235
|
_cachedRecommendedModels = cacheData;
|
|
45585
46236
|
return cacheData;
|
|
@@ -45703,7 +46354,7 @@ var _cachedModelInfo = null, _cachedModelIds = null, _cachedRecommendedModels =
|
|
|
45703
46354
|
var init_model_loader = __esm(() => {
|
|
45704
46355
|
init_cache_ttl();
|
|
45705
46356
|
FIREBASE_RECOMMENDED_URL = `${FIREBASE_BASE_URL}?catalog=recommended`;
|
|
45706
|
-
RECOMMENDED_MODELS_CACHE_PATH =
|
|
46357
|
+
RECOMMENDED_MODELS_CACHE_PATH = join26(homedir26(), ".claudish", "recommended-models-cache.json");
|
|
45707
46358
|
FIREBASE_SLUG_TO_PROVIDER_NAME = {
|
|
45708
46359
|
openai: "openai",
|
|
45709
46360
|
google: "google",
|
|
@@ -45922,11 +46573,11 @@ var splitPath = (path) => {
|
|
|
45922
46573
|
return patternCache[cacheKey];
|
|
45923
46574
|
}
|
|
45924
46575
|
return null;
|
|
45925
|
-
}, tryDecode = (
|
|
46576
|
+
}, tryDecode = (str2, decoder) => {
|
|
45926
46577
|
try {
|
|
45927
|
-
return decoder(
|
|
46578
|
+
return decoder(str2);
|
|
45928
46579
|
} catch {
|
|
45929
|
-
return
|
|
46580
|
+
return str2.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
45930
46581
|
try {
|
|
45931
46582
|
return decoder(match);
|
|
45932
46583
|
} catch {
|
|
@@ -45934,7 +46585,7 @@ var splitPath = (path) => {
|
|
|
45934
46585
|
}
|
|
45935
46586
|
});
|
|
45936
46587
|
}
|
|
45937
|
-
}, tryDecodeURI = (
|
|
46588
|
+
}, tryDecodeURI = (str2) => tryDecode(str2, decodeURI), getPath = (request) => {
|
|
45938
46589
|
const url2 = request.url;
|
|
45939
46590
|
const start = url2.indexOf("/", url2.indexOf(":") + 4);
|
|
45940
46591
|
let i = start;
|
|
@@ -46063,7 +46714,7 @@ var init_url = __esm(() => {
|
|
|
46063
46714
|
});
|
|
46064
46715
|
|
|
46065
46716
|
// ../../node_modules/.bun/hono@4.10.6/node_modules/hono/dist/request.js
|
|
46066
|
-
var tryDecodeURIComponent = (
|
|
46717
|
+
var tryDecodeURIComponent = (str2) => tryDecode(str2, decodeURIComponent_), HonoRequest;
|
|
46067
46718
|
var init_request = __esm(() => {
|
|
46068
46719
|
init_http_exception();
|
|
46069
46720
|
init_constants();
|
|
@@ -46185,25 +46836,25 @@ var HtmlEscapedCallbackPhase, raw = (value, callbacks) => {
|
|
|
46185
46836
|
escapedString.isEscaped = true;
|
|
46186
46837
|
escapedString.callbacks = callbacks;
|
|
46187
46838
|
return escapedString;
|
|
46188
|
-
}, resolveCallback = async (
|
|
46189
|
-
if (typeof
|
|
46190
|
-
if (!(
|
|
46191
|
-
|
|
46839
|
+
}, resolveCallback = async (str2, phase, preserveCallbacks, context, buffer) => {
|
|
46840
|
+
if (typeof str2 === "object" && !(str2 instanceof String)) {
|
|
46841
|
+
if (!(str2 instanceof Promise)) {
|
|
46842
|
+
str2 = str2.toString();
|
|
46192
46843
|
}
|
|
46193
|
-
if (
|
|
46194
|
-
|
|
46844
|
+
if (str2 instanceof Promise) {
|
|
46845
|
+
str2 = await str2;
|
|
46195
46846
|
}
|
|
46196
46847
|
}
|
|
46197
|
-
const callbacks =
|
|
46848
|
+
const callbacks = str2.callbacks;
|
|
46198
46849
|
if (!callbacks?.length) {
|
|
46199
|
-
return Promise.resolve(
|
|
46850
|
+
return Promise.resolve(str2);
|
|
46200
46851
|
}
|
|
46201
46852
|
if (buffer) {
|
|
46202
|
-
buffer[0] +=
|
|
46853
|
+
buffer[0] += str2;
|
|
46203
46854
|
} else {
|
|
46204
|
-
buffer = [
|
|
46855
|
+
buffer = [str2];
|
|
46205
46856
|
}
|
|
46206
|
-
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then((res) => Promise.all(res.filter(Boolean).map((
|
|
46857
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then((res) => Promise.all(res.filter(Boolean).map((str22) => resolveCallback(str22, phase, false, context, buffer))).then(() => buffer[0]));
|
|
46207
46858
|
if (preserveCallbacks) {
|
|
46208
46859
|
return raw(await resStr, callbacks);
|
|
46209
46860
|
} else {
|
|
@@ -47436,8 +48087,7 @@ var init_local_adapter = __esm(() => {
|
|
|
47436
48087
|
constructor(modelId, providerName) {
|
|
47437
48088
|
super(modelId);
|
|
47438
48089
|
this.providerName = providerName;
|
|
47439
|
-
|
|
47440
|
-
this.innerAdapter = manager.getAdapter();
|
|
48090
|
+
this.innerAdapter = resolveModelDialect(modelId);
|
|
47441
48091
|
}
|
|
47442
48092
|
processTextContent(textContent, accumulatedText) {
|
|
47443
48093
|
return this.innerAdapter.processTextContent(textContent, accumulatedText);
|
|
@@ -47605,8 +48255,7 @@ var init_openrouter_api_format = __esm(() => {
|
|
|
47605
48255
|
innerAdapter;
|
|
47606
48256
|
constructor(modelId) {
|
|
47607
48257
|
super(modelId);
|
|
47608
|
-
|
|
47609
|
-
this.innerAdapter = manager.getAdapter();
|
|
48258
|
+
this.innerAdapter = resolveModelDialect(modelId);
|
|
47610
48259
|
}
|
|
47611
48260
|
modelSupportsReasoning() {
|
|
47612
48261
|
const id = this.modelId.toLowerCase();
|
|
@@ -48868,11 +49517,11 @@ var init_ollama_api_format = __esm(() => {
|
|
|
48868
49517
|
});
|
|
48869
49518
|
|
|
48870
49519
|
// src/providers/api-key-provenance.ts
|
|
48871
|
-
import { existsSync as
|
|
48872
|
-
import { homedir as
|
|
48873
|
-
import { join as
|
|
49520
|
+
import { existsSync as existsSync18, readFileSync as readFileSync17 } from "fs";
|
|
49521
|
+
import { homedir as homedir27 } from "os";
|
|
49522
|
+
import { join as join27, resolve as resolve2 } from "path";
|
|
48874
49523
|
function activeConfigPath() {
|
|
48875
|
-
return activeGlobalConfigFile(
|
|
49524
|
+
return activeGlobalConfigFile(join27(homedir27(), ".claudish", "config.json"));
|
|
48876
49525
|
}
|
|
48877
49526
|
function configLayerLabel() {
|
|
48878
49527
|
return getConfigFileOverride() ? activeConfigPath() : "~/.claudish/config.json";
|
|
@@ -48949,9 +49598,9 @@ function formatProvenanceLog(p) {
|
|
|
48949
49598
|
function readDotenvKey(envVars) {
|
|
48950
49599
|
try {
|
|
48951
49600
|
const dotenvPath = resolve2(".env");
|
|
48952
|
-
if (!
|
|
49601
|
+
if (!existsSync18(dotenvPath))
|
|
48953
49602
|
return null;
|
|
48954
|
-
const parsed = import_dotenv.parse(
|
|
49603
|
+
const parsed = import_dotenv.parse(readFileSync17(dotenvPath, "utf-8"));
|
|
48955
49604
|
for (const v of envVars) {
|
|
48956
49605
|
if (parsed[v])
|
|
48957
49606
|
return parsed[v];
|
|
@@ -48964,9 +49613,9 @@ function readDotenvKey(envVars) {
|
|
|
48964
49613
|
function readConfigKey(envVar) {
|
|
48965
49614
|
try {
|
|
48966
49615
|
const configPath = activeConfigPath();
|
|
48967
|
-
if (!
|
|
49616
|
+
if (!existsSync18(configPath))
|
|
48968
49617
|
return null;
|
|
48969
|
-
const cfg = JSON.parse(
|
|
49618
|
+
const cfg = JSON.parse(readFileSync17(configPath, "utf-8"));
|
|
48970
49619
|
return cfg.apiKeys?.[envVar] || null;
|
|
48971
49620
|
} catch {
|
|
48972
49621
|
return null;
|
|
@@ -49152,6 +49801,29 @@ var init_gemini_apikey = __esm(() => {
|
|
|
49152
49801
|
init_gemini_queue();
|
|
49153
49802
|
});
|
|
49154
49803
|
|
|
49804
|
+
// src/providers/transport/grok-subscription.ts
|
|
49805
|
+
var GrokSubscriptionProviderTransport;
|
|
49806
|
+
var init_grok_subscription = __esm(() => {
|
|
49807
|
+
init_authority();
|
|
49808
|
+
init_grok_credentials();
|
|
49809
|
+
init_openai();
|
|
49810
|
+
GrokSubscriptionProviderTransport = class GrokSubscriptionProviderTransport extends OpenAIProviderTransport {
|
|
49811
|
+
async getHeaders() {
|
|
49812
|
+
const auth = await credentials.getRequestAuth("grok-subscription", {
|
|
49813
|
+
model: this.modelName
|
|
49814
|
+
});
|
|
49815
|
+
const headers = { ...auth.headers };
|
|
49816
|
+
if (this.provider.headers) {
|
|
49817
|
+
Object.assign(headers, this.provider.headers);
|
|
49818
|
+
}
|
|
49819
|
+
return headers;
|
|
49820
|
+
}
|
|
49821
|
+
async forceRefreshAuth() {
|
|
49822
|
+
await forceRefreshGrokAccessToken();
|
|
49823
|
+
}
|
|
49824
|
+
};
|
|
49825
|
+
});
|
|
49826
|
+
|
|
49155
49827
|
// src/providers/transport/ollamacloud.ts
|
|
49156
49828
|
class OllamaProviderTransport {
|
|
49157
49829
|
name = "ollamacloud";
|
|
@@ -49312,7 +49984,7 @@ function createHandlerForProvider(ctx) {
|
|
|
49312
49984
|
log(`[Proxy] Handler: provider=${ctx.provider.name}, model=${ctx.modelName}`);
|
|
49313
49985
|
return profile.createHandler(ctx);
|
|
49314
49986
|
}
|
|
49315
|
-
var geminiProfile, antigravityProfile, devinProfile, openaiProfile, openaiCodexProfile, anthropicCompatProfile, glmProfile, openCodeZenProfile, ollamaCloudProfile, litellmProfile, vertexProfile, PROVIDER_PROFILES;
|
|
49987
|
+
var geminiProfile, antigravityProfile, devinProfile, grokSubscriptionProfile, openaiProfile, openaiCodexProfile, anthropicCompatProfile, glmProfile, openCodeZenProfile, ollamaCloudProfile, litellmProfile, vertexProfile, PROVIDER_PROFILES;
|
|
49316
49988
|
var init_provider_profiles = __esm(() => {
|
|
49317
49989
|
init_anthropic_api_format();
|
|
49318
49990
|
init_base_api_format();
|
|
@@ -49332,6 +50004,7 @@ var init_provider_profiles = __esm(() => {
|
|
|
49332
50004
|
init_antigravity();
|
|
49333
50005
|
init_devin2();
|
|
49334
50006
|
init_gemini_apikey();
|
|
50007
|
+
init_grok_subscription();
|
|
49335
50008
|
init_litellm();
|
|
49336
50009
|
init_ollamacloud();
|
|
49337
50010
|
init_openai_codex();
|
|
@@ -49375,6 +50048,19 @@ var init_provider_profiles = __esm(() => {
|
|
|
49375
50048
|
return handler;
|
|
49376
50049
|
}
|
|
49377
50050
|
};
|
|
50051
|
+
grokSubscriptionProfile = {
|
|
50052
|
+
createHandler(ctx) {
|
|
50053
|
+
const transport = new GrokSubscriptionProviderTransport(ctx.provider, ctx.modelName, "");
|
|
50054
|
+
const adapter = new OpenAIAPIFormat(ctx.modelName);
|
|
50055
|
+
const handler = new ComposedHandler(transport, ctx.targetModel, ctx.modelName, ctx.port, {
|
|
50056
|
+
adapter,
|
|
50057
|
+
tokenStrategy: "delta-aware",
|
|
50058
|
+
...ctx.sharedOpts
|
|
50059
|
+
});
|
|
50060
|
+
log(`[Proxy] Created Grok subscription handler (composed): ${ctx.modelName}`);
|
|
50061
|
+
return handler;
|
|
50062
|
+
}
|
|
50063
|
+
};
|
|
49378
50064
|
openaiProfile = {
|
|
49379
50065
|
createHandler(ctx) {
|
|
49380
50066
|
if (requiresResponsesApi(ctx.modelName)) {
|
|
@@ -49547,6 +50233,7 @@ var init_provider_profiles = __esm(() => {
|
|
|
49547
50233
|
openai: openaiProfile,
|
|
49548
50234
|
"openai-codex": openaiCodexProfile,
|
|
49549
50235
|
"x-ai": openaiProfile,
|
|
50236
|
+
"grok-subscription": grokSubscriptionProfile,
|
|
49550
50237
|
qwen: openaiProfile,
|
|
49551
50238
|
minimax: anthropicCompatProfile,
|
|
49552
50239
|
"minimax-coding": anthropicCompatProfile,
|
|
@@ -50284,9 +50971,9 @@ var init_poe = __esm(() => {
|
|
|
50284
50971
|
});
|
|
50285
50972
|
|
|
50286
50973
|
// src/services/pricing-cache.ts
|
|
50287
|
-
import { existsSync as
|
|
50288
|
-
import { homedir as
|
|
50289
|
-
import { join as
|
|
50974
|
+
import { existsSync as existsSync19, readFileSync as readFileSync18, statSync as statSync4 } from "fs";
|
|
50975
|
+
import { homedir as homedir28 } from "os";
|
|
50976
|
+
import { join as join28 } from "path";
|
|
50290
50977
|
function prefixMatch(modelName) {
|
|
50291
50978
|
for (const [key, pricing] of pricingMap) {
|
|
50292
50979
|
if (modelName.startsWith(key))
|
|
@@ -50324,12 +51011,12 @@ async function warmPricingCache() {
|
|
|
50324
51011
|
}
|
|
50325
51012
|
function loadDiskCache() {
|
|
50326
51013
|
try {
|
|
50327
|
-
if (!
|
|
51014
|
+
if (!existsSync19(CACHE_FILE))
|
|
50328
51015
|
return false;
|
|
50329
51016
|
const stat2 = statSync4(CACHE_FILE);
|
|
50330
51017
|
const age = Date.now() - stat2.mtimeMs;
|
|
50331
51018
|
const isFresh = age < CACHE_TTL_MS3;
|
|
50332
|
-
const raw2 =
|
|
51019
|
+
const raw2 = readFileSync18(CACHE_FILE, "utf-8");
|
|
50333
51020
|
const data = JSON.parse(raw2);
|
|
50334
51021
|
for (const [key, pricing] of Object.entries(data)) {
|
|
50335
51022
|
pricingMap.set(key, pricing);
|
|
@@ -50345,8 +51032,8 @@ var init_pricing_cache = __esm(() => {
|
|
|
50345
51032
|
init_logger();
|
|
50346
51033
|
init_catalog_query();
|
|
50347
51034
|
pricingMap = new Map;
|
|
50348
|
-
CACHE_DIR =
|
|
50349
|
-
CACHE_FILE =
|
|
51035
|
+
CACHE_DIR = join28(homedir28(), ".claudish");
|
|
51036
|
+
CACHE_FILE = join28(CACHE_DIR, "pricing-cache.json");
|
|
50350
51037
|
CACHE_TTL_MS3 = 24 * 60 * 60 * 1000;
|
|
50351
51038
|
});
|
|
50352
51039
|
|
|
@@ -50871,20 +51558,20 @@ var init_redact = __esm(() => {
|
|
|
50871
51558
|
});
|
|
50872
51559
|
|
|
50873
51560
|
// src/team-stats.ts
|
|
50874
|
-
import { existsSync as
|
|
50875
|
-
import { join as
|
|
51561
|
+
import { existsSync as existsSync20, readFileSync as readFileSync19, writeFileSync as writeFileSync12 } from "fs";
|
|
51562
|
+
import { join as join29 } from "path";
|
|
50876
51563
|
function statsDir(sessionPath) {
|
|
50877
|
-
return
|
|
51564
|
+
return join29(sessionPath, "stats");
|
|
50878
51565
|
}
|
|
50879
51566
|
function tokenFileFor(sessionPath, anonId) {
|
|
50880
|
-
return
|
|
51567
|
+
return join29(statsDir(sessionPath), `${anonId}.json`);
|
|
50881
51568
|
}
|
|
50882
51569
|
function readTokenStats(sessionPath, anonId) {
|
|
50883
51570
|
const path = tokenFileFor(sessionPath, anonId);
|
|
50884
|
-
if (!
|
|
51571
|
+
if (!existsSync20(path))
|
|
50885
51572
|
return null;
|
|
50886
51573
|
try {
|
|
50887
|
-
return JSON.parse(
|
|
51574
|
+
return JSON.parse(readFileSync19(path, "utf-8"));
|
|
50888
51575
|
} catch {
|
|
50889
51576
|
return null;
|
|
50890
51577
|
}
|
|
@@ -51032,7 +51719,7 @@ ${segs.join(" \xB7 ")}`;
|
|
|
51032
51719
|
}
|
|
51033
51720
|
function writeStatusFile(sessionPath, manifest, status, opts) {
|
|
51034
51721
|
try {
|
|
51035
|
-
|
|
51722
|
+
writeFileSync12(join29(sessionPath, "status.txt"), `${renderTeamStats(sessionPath, manifest, status, opts)}
|
|
51036
51723
|
`, "utf-8");
|
|
51037
51724
|
} catch {}
|
|
51038
51725
|
}
|
|
@@ -51183,13 +51870,13 @@ __export(exports_team_orchestrator, {
|
|
|
51183
51870
|
import { spawn as spawn2 } from "child_process";
|
|
51184
51871
|
import {
|
|
51185
51872
|
createWriteStream as createWriteStream2,
|
|
51186
|
-
existsSync as
|
|
51187
|
-
mkdirSync as
|
|
51188
|
-
readFileSync as
|
|
51873
|
+
existsSync as existsSync21,
|
|
51874
|
+
mkdirSync as mkdirSync13,
|
|
51875
|
+
readFileSync as readFileSync20,
|
|
51189
51876
|
readdirSync as readdirSync3,
|
|
51190
|
-
writeFileSync as
|
|
51877
|
+
writeFileSync as writeFileSync13
|
|
51191
51878
|
} from "fs";
|
|
51192
|
-
import { join as
|
|
51879
|
+
import { join as join30, resolve as resolve3 } from "path";
|
|
51193
51880
|
function resolveCaptureMode(explicit, env = process.env) {
|
|
51194
51881
|
if (explicit)
|
|
51195
51882
|
return explicit;
|
|
@@ -51262,7 +51949,7 @@ function persistErrorLog(errorLogPath, header, stderr, stdoutTail) {
|
|
|
51262
51949
|
parts.push("--- stderr ---", stderr.trim() ? redactSecrets(stderr) : "(empty)", "");
|
|
51263
51950
|
parts.push("--- stdout (tail) ---", stdoutTail.trim() ? redactSecrets(stdoutTail) : "(empty)", "");
|
|
51264
51951
|
try {
|
|
51265
|
-
|
|
51952
|
+
writeFileSync13(errorLogPath, parts.join(`
|
|
51266
51953
|
`), "utf-8");
|
|
51267
51954
|
} catch {}
|
|
51268
51955
|
}
|
|
@@ -51286,18 +51973,18 @@ function setupSession(sessionPath, models, input) {
|
|
|
51286
51973
|
if (models.length === 0) {
|
|
51287
51974
|
throw new Error("At least one model is required");
|
|
51288
51975
|
}
|
|
51289
|
-
if (
|
|
51976
|
+
if (existsSync21(join30(sessionPath, "manifest.json"))) {
|
|
51290
51977
|
throw new Error(`Session already exists at ${sessionPath}. Use a new directory path or delete the existing session first.`);
|
|
51291
51978
|
}
|
|
51292
51979
|
const sentinels = models.filter(isSentinelModel);
|
|
51293
51980
|
if (sentinels.length > 0) {
|
|
51294
51981
|
throw new Error(`Invalid model(s) for team run: ${sentinels.join(", ")}. These are Claude Code agent selectors, not external model IDs. Use real external models (e.g., "gemini-2.0-flash", "gpt-4o", "or@deepseek/deepseek-r1"). For Claude models, use a Task agent instead of the team tool.`);
|
|
51295
51982
|
}
|
|
51296
|
-
|
|
51297
|
-
|
|
51983
|
+
mkdirSync13(join30(sessionPath, "work"), { recursive: true });
|
|
51984
|
+
mkdirSync13(join30(sessionPath, "errors"), { recursive: true });
|
|
51298
51985
|
if (input !== undefined) {
|
|
51299
|
-
|
|
51300
|
-
} else if (!
|
|
51986
|
+
writeFileSync13(join30(sessionPath, "input.md"), input, "utf-8");
|
|
51987
|
+
} else if (!existsSync21(join30(sessionPath, "input.md"))) {
|
|
51301
51988
|
throw new Error(`No input.md found at ${sessionPath} and no input provided`);
|
|
51302
51989
|
}
|
|
51303
51990
|
const ids = models.map((_, i) => String(i + 1).padStart(2, "0"));
|
|
@@ -51314,9 +52001,9 @@ function setupSession(sessionPath, models, input) {
|
|
|
51314
52001
|
model: models[i],
|
|
51315
52002
|
assignedAt: now
|
|
51316
52003
|
};
|
|
51317
|
-
|
|
52004
|
+
mkdirSync13(join30(sessionPath, "work", anonId), { recursive: true });
|
|
51318
52005
|
}
|
|
51319
|
-
|
|
52006
|
+
writeFileSync13(join30(sessionPath, "manifest.json"), JSON.stringify(manifest, null, 2), "utf-8");
|
|
51320
52007
|
const status = {
|
|
51321
52008
|
startedAt: now,
|
|
51322
52009
|
models: Object.fromEntries(Object.keys(manifest.models).map((id) => [
|
|
@@ -51330,7 +52017,7 @@ function setupSession(sessionPath, models, input) {
|
|
|
51330
52017
|
}
|
|
51331
52018
|
]))
|
|
51332
52019
|
};
|
|
51333
|
-
|
|
52020
|
+
writeFileSync13(join30(sessionPath, "status.json"), JSON.stringify(status, null, 2), "utf-8");
|
|
51334
52021
|
return manifest;
|
|
51335
52022
|
}
|
|
51336
52023
|
function assertValidRequirePattern(pattern) {
|
|
@@ -51347,7 +52034,7 @@ function readFullOutputIfNeeded(opts) {
|
|
|
51347
52034
|
if (crashed || !requirePattern || outputSize <= STDOUT_TAIL_LIMIT)
|
|
51348
52035
|
return;
|
|
51349
52036
|
try {
|
|
51350
|
-
return
|
|
52037
|
+
return readFileSync20(outputPath, "utf-8");
|
|
51351
52038
|
} catch {
|
|
51352
52039
|
return;
|
|
51353
52040
|
}
|
|
@@ -51355,15 +52042,15 @@ function readFullOutputIfNeeded(opts) {
|
|
|
51355
52042
|
async function runModels(sessionPath, opts = {}) {
|
|
51356
52043
|
const timeoutMs = (opts.timeout ?? 300) * 1000;
|
|
51357
52044
|
assertValidRequirePattern(opts.requirePattern);
|
|
51358
|
-
const manifest = JSON.parse(
|
|
51359
|
-
const statusPath =
|
|
51360
|
-
const inputPath =
|
|
51361
|
-
const inputContent =
|
|
52045
|
+
const manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
52046
|
+
const statusPath = join30(sessionPath, "status.json");
|
|
52047
|
+
const inputPath = join30(sessionPath, "input.md");
|
|
52048
|
+
const inputContent = readFileSync20(inputPath, "utf-8");
|
|
51362
52049
|
const spawnPlan = await (opts.spawnPlanner ?? prehydrateCredentialsForSpawn)(Object.values(manifest.models).map((m) => m.model));
|
|
51363
|
-
const statusCache = JSON.parse(
|
|
52050
|
+
const statusCache = JSON.parse(readFileSync20(statusPath, "utf-8"));
|
|
51364
52051
|
function updateModelStatus(id, update) {
|
|
51365
52052
|
statusCache.models[id] = { ...statusCache.models[id], ...update };
|
|
51366
|
-
|
|
52053
|
+
writeFileSync13(statusPath, JSON.stringify(statusCache, null, 2), "utf-8");
|
|
51367
52054
|
}
|
|
51368
52055
|
const minOutputBytes = opts.minOutputBytes ?? DEFAULT_MIN_OUTPUT_BYTES;
|
|
51369
52056
|
const requirePattern = opts.requirePattern;
|
|
@@ -51396,7 +52083,7 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51396
52083
|
persistErrorLog(rt.errorLogPath, `RECOVERED: ${note}`, stderr, stdoutTail);
|
|
51397
52084
|
opts.onStatusChange?.(id, statusCache.models[id]);
|
|
51398
52085
|
}
|
|
51399
|
-
|
|
52086
|
+
mkdirSync13(statsDir(sessionPath), { recursive: true });
|
|
51400
52087
|
const processes = new Map;
|
|
51401
52088
|
const runtimes = new Map;
|
|
51402
52089
|
const sigintHandler = () => {
|
|
@@ -51408,8 +52095,8 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51408
52095
|
process.on("SIGINT", sigintHandler);
|
|
51409
52096
|
const completionPromises = [];
|
|
51410
52097
|
for (const [anonId, entry] of Object.entries(manifest.models)) {
|
|
51411
|
-
const outputPath =
|
|
51412
|
-
const errorLogPath =
|
|
52098
|
+
const outputPath = join30(sessionPath, `response-${anonId}.md`);
|
|
52099
|
+
const errorLogPath = join30(sessionPath, "errors", `${anonId}.log`);
|
|
51413
52100
|
const spawnModel = spawnPlan.pinned.get(entry.model) ?? entry.model;
|
|
51414
52101
|
const args = [
|
|
51415
52102
|
"--model",
|
|
@@ -51548,7 +52235,7 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51548
52235
|
proc.on("exit", (code) => {
|
|
51549
52236
|
const timedOut = statusCache.models[anonId]?.state === "TIMEOUT";
|
|
51550
52237
|
if (!timedOut && meaningfulStderr(stderr)) {
|
|
51551
|
-
|
|
52238
|
+
writeFileSync13(errorLogPath, redactSecrets(stderr), "utf-8");
|
|
51552
52239
|
}
|
|
51553
52240
|
exitCode = code;
|
|
51554
52241
|
if (outputStream.destroyed) {
|
|
@@ -51635,7 +52322,7 @@ async function runModels(sessionPath, opts = {}) {
|
|
|
51635
52322
|
opts.onStatusChange?.(id, statusCache.models[id]);
|
|
51636
52323
|
const stopped = await terminateChildTree(proc);
|
|
51637
52324
|
if (!stopped) {
|
|
51638
|
-
persistErrorLog(rt?.errorLogPath ??
|
|
52325
|
+
persistErrorLog(rt?.errorLogPath ?? join30(sessionPath, "errors", `${id}.log`), "TIMEOUT: child survived SIGKILL \u2014 it may still be running and billing", stderr, stdoutTail);
|
|
51639
52326
|
}
|
|
51640
52327
|
};
|
|
51641
52328
|
const allDone = Promise.all(completionPromises);
|
|
@@ -51694,23 +52381,23 @@ async function judgeResponses(sessionPath, opts = {}) {
|
|
|
51694
52381
|
const responses = {};
|
|
51695
52382
|
for (const file2 of responseFiles) {
|
|
51696
52383
|
const id = file2.replace(/^response-/, "").replace(/\.md$/, "");
|
|
51697
|
-
responses[id] =
|
|
52384
|
+
responses[id] = readFileSync20(join30(sessionPath, file2), "utf-8");
|
|
51698
52385
|
}
|
|
51699
|
-
const input =
|
|
52386
|
+
const input = readFileSync20(join30(sessionPath, "input.md"), "utf-8");
|
|
51700
52387
|
const judgePrompt = buildJudgePrompt(input, responses);
|
|
51701
|
-
|
|
52388
|
+
writeFileSync13(join30(sessionPath, "judge-prompt.md"), judgePrompt, "utf-8");
|
|
51702
52389
|
const judgeModels = opts.judges ?? getDefaultJudgeModels(sessionPath);
|
|
51703
|
-
const judgePath =
|
|
51704
|
-
|
|
52390
|
+
const judgePath = join30(sessionPath, "judging");
|
|
52391
|
+
mkdirSync13(judgePath, { recursive: true });
|
|
51705
52392
|
setupSession(judgePath, judgeModels, judgePrompt);
|
|
51706
52393
|
await runModels(judgePath, { claudeFlags: opts.claudeFlags });
|
|
51707
52394
|
const votes = parseJudgeVotes(judgePath, Object.keys(responses));
|
|
51708
52395
|
const verdict = aggregateVerdict(votes, Object.keys(responses));
|
|
51709
|
-
|
|
52396
|
+
writeFileSync13(join30(sessionPath, "verdict.md"), formatVerdict(verdict, sessionPath), "utf-8");
|
|
51710
52397
|
return verdict;
|
|
51711
52398
|
}
|
|
51712
52399
|
function getStatus(sessionPath) {
|
|
51713
|
-
return JSON.parse(
|
|
52400
|
+
return JSON.parse(readFileSync20(join30(sessionPath, "status.json"), "utf-8"));
|
|
51714
52401
|
}
|
|
51715
52402
|
function fisherYatesShuffle(arr) {
|
|
51716
52403
|
for (let i = arr.length - 1;i > 0; i--) {
|
|
@@ -51720,7 +52407,7 @@ function fisherYatesShuffle(arr) {
|
|
|
51720
52407
|
return arr;
|
|
51721
52408
|
}
|
|
51722
52409
|
function getDefaultJudgeModels(sessionPath) {
|
|
51723
|
-
const manifest = JSON.parse(
|
|
52410
|
+
const manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
51724
52411
|
return Object.values(manifest.models).map((e) => e.model);
|
|
51725
52412
|
}
|
|
51726
52413
|
function buildJudgePrompt(input, responses) {
|
|
@@ -51783,7 +52470,7 @@ function parseJudgeVotes(judgePath, responseIds) {
|
|
|
51783
52470
|
const judgeId = file2.replace(/^response-/, "").replace(/\.md$/, "");
|
|
51784
52471
|
let content;
|
|
51785
52472
|
try {
|
|
51786
|
-
content =
|
|
52473
|
+
content = readFileSync20(join30(judgePath, file2), "utf-8");
|
|
51787
52474
|
} catch {
|
|
51788
52475
|
continue;
|
|
51789
52476
|
}
|
|
@@ -51835,7 +52522,7 @@ function aggregateVerdict(votes, responseIds) {
|
|
|
51835
52522
|
function formatVerdict(verdict, sessionPath) {
|
|
51836
52523
|
let manifest = null;
|
|
51837
52524
|
try {
|
|
51838
|
-
manifest = JSON.parse(
|
|
52525
|
+
manifest = JSON.parse(readFileSync20(join30(sessionPath, "manifest.json"), "utf-8"));
|
|
51839
52526
|
} catch {}
|
|
51840
52527
|
let output = `# Team Verdict
|
|
51841
52528
|
|
|
@@ -51896,14 +52583,14 @@ __export(exports_mcp_server, {
|
|
|
51896
52583
|
parseAnthropicSse: () => parseAnthropicSse,
|
|
51897
52584
|
formatTeamResult: () => formatTeamResult
|
|
51898
52585
|
});
|
|
51899
|
-
import { existsSync as
|
|
51900
|
-
import { homedir as
|
|
51901
|
-
import { dirname as dirname9, join as
|
|
52586
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync14, readFileSync as readFileSync21, readdirSync as readdirSync4, writeFileSync as writeFileSync14 } from "fs";
|
|
52587
|
+
import { homedir as homedir29 } from "os";
|
|
52588
|
+
import { dirname as dirname9, join as join31, resolve as resolve4 } from "path";
|
|
51902
52589
|
import { fileURLToPath } from "url";
|
|
51903
52590
|
async function loadAllModels(forceRefresh = false) {
|
|
51904
|
-
if (!forceRefresh &&
|
|
52591
|
+
if (!forceRefresh && existsSync22(ALL_MODELS_CACHE_PATH2)) {
|
|
51905
52592
|
try {
|
|
51906
|
-
const cacheData = JSON.parse(
|
|
52593
|
+
const cacheData = JSON.parse(readFileSync21(ALL_MODELS_CACHE_PATH2, "utf-8"));
|
|
51907
52594
|
const lastUpdated = new Date(cacheData.lastUpdated);
|
|
51908
52595
|
const ageInDays = (Date.now() - lastUpdated.getTime()) / (1000 * 60 * 60 * 24);
|
|
51909
52596
|
if (ageInDays <= CACHE_MAX_AGE_DAYS) {
|
|
@@ -51917,12 +52604,12 @@ async function loadAllModels(forceRefresh = false) {
|
|
|
51917
52604
|
throw new Error(`API returned ${response.status}`);
|
|
51918
52605
|
const data = await response.json();
|
|
51919
52606
|
const models = data.data || [];
|
|
51920
|
-
|
|
51921
|
-
|
|
52607
|
+
mkdirSync14(CLAUDISH_CACHE_DIR, { recursive: true });
|
|
52608
|
+
writeFileSync14(ALL_MODELS_CACHE_PATH2, JSON.stringify({ lastUpdated: new Date().toISOString(), models }), "utf-8");
|
|
51922
52609
|
return models;
|
|
51923
52610
|
} catch {
|
|
51924
|
-
if (
|
|
51925
|
-
const cacheData = JSON.parse(
|
|
52611
|
+
if (existsSync22(ALL_MODELS_CACHE_PATH2)) {
|
|
52612
|
+
const cacheData = JSON.parse(readFileSync21(ALL_MODELS_CACHE_PATH2, "utf-8"));
|
|
51926
52613
|
return cacheData.models || [];
|
|
51927
52614
|
}
|
|
51928
52615
|
return [];
|
|
@@ -52523,7 +53210,7 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52523
53210
|
let stderrFull = stderr_snippet || "";
|
|
52524
53211
|
if (error_log_path) {
|
|
52525
53212
|
try {
|
|
52526
|
-
stderrFull =
|
|
53213
|
+
stderrFull = readFileSync21(error_log_path, "utf-8");
|
|
52527
53214
|
} catch {}
|
|
52528
53215
|
}
|
|
52529
53216
|
const sessionData = {};
|
|
@@ -52531,16 +53218,16 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52531
53218
|
const sp = session_path;
|
|
52532
53219
|
for (const file2 of ["status.json", "manifest.json", "input.md"]) {
|
|
52533
53220
|
try {
|
|
52534
|
-
sessionData[file2] =
|
|
53221
|
+
sessionData[file2] = readFileSync21(join31(sp, file2), "utf-8");
|
|
52535
53222
|
} catch {}
|
|
52536
53223
|
}
|
|
52537
53224
|
try {
|
|
52538
|
-
const errorDir =
|
|
52539
|
-
if (
|
|
53225
|
+
const errorDir = join31(sp, "errors");
|
|
53226
|
+
if (existsSync22(errorDir)) {
|
|
52540
53227
|
for (const f of readdirSync4(errorDir)) {
|
|
52541
53228
|
if (f.endsWith(".log")) {
|
|
52542
53229
|
try {
|
|
52543
|
-
sessionData[`errors/${f}`] =
|
|
53230
|
+
sessionData[`errors/${f}`] = readFileSync21(join31(errorDir, f), "utf-8");
|
|
52544
53231
|
} catch {}
|
|
52545
53232
|
}
|
|
52546
53233
|
}
|
|
@@ -52550,7 +53237,7 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52550
53237
|
for (const f of readdirSync4(sp)) {
|
|
52551
53238
|
if (f.startsWith("response-") && f.endsWith(".md")) {
|
|
52552
53239
|
try {
|
|
52553
|
-
const content =
|
|
53240
|
+
const content = readFileSync21(join31(sp, f), "utf-8");
|
|
52554
53241
|
sessionData[f] = content.slice(0, 200) + (content.length > 200 ? "... (truncated)" : "");
|
|
52555
53242
|
} catch {}
|
|
52556
53243
|
}
|
|
@@ -52559,9 +53246,9 @@ Use with: run_prompt(model="${results[0].model.id}", prompt="your prompt")`;
|
|
|
52559
53246
|
}
|
|
52560
53247
|
let version2 = "unknown";
|
|
52561
53248
|
try {
|
|
52562
|
-
const pkgPath =
|
|
52563
|
-
if (
|
|
52564
|
-
version2 = JSON.parse(
|
|
53249
|
+
const pkgPath = join31(__dirname2, "../package.json");
|
|
53250
|
+
if (existsSync22(pkgPath)) {
|
|
53251
|
+
version2 = JSON.parse(readFileSync21(pkgPath, "utf-8")).version;
|
|
52565
53252
|
}
|
|
52566
53253
|
} catch {}
|
|
52567
53254
|
const report = {
|
|
@@ -52976,8 +53663,8 @@ var init_mcp_server = __esm(() => {
|
|
|
52976
53663
|
import_dotenv2.config({ quiet: true });
|
|
52977
53664
|
__filename2 = fileURLToPath(import.meta.url);
|
|
52978
53665
|
__dirname2 = dirname9(__filename2);
|
|
52979
|
-
CLAUDISH_CACHE_DIR =
|
|
52980
|
-
ALL_MODELS_CACHE_PATH2 =
|
|
53666
|
+
CLAUDISH_CACHE_DIR = join31(homedir29(), ".claudish");
|
|
53667
|
+
ALL_MODELS_CACHE_PATH2 = join31(CLAUDISH_CACHE_DIR, "all-models.json");
|
|
52981
53668
|
NEXT_STEP = {
|
|
52982
53669
|
nonzero_exit: "read the evidence log, then retry or drop the model",
|
|
52983
53670
|
timeout: "raise `timeout`, or pick a faster model",
|
|
@@ -53003,7 +53690,7 @@ var exports_serve_command = {};
|
|
|
53003
53690
|
__export(exports_serve_command, {
|
|
53004
53691
|
serveCommand: () => serveCommand
|
|
53005
53692
|
});
|
|
53006
|
-
import { existsSync as
|
|
53693
|
+
import { existsSync as existsSync23, readFileSync as readFileSync22 } from "fs";
|
|
53007
53694
|
function parseServeArgs(args) {
|
|
53008
53695
|
const out = {};
|
|
53009
53696
|
for (let i = 0;i < args.length; i++) {
|
|
@@ -53022,12 +53709,12 @@ function parseServeArgs(args) {
|
|
|
53022
53709
|
return out;
|
|
53023
53710
|
}
|
|
53024
53711
|
function loadModelMap(path) {
|
|
53025
|
-
if (!
|
|
53712
|
+
if (!existsSync23(path)) {
|
|
53026
53713
|
throw new Error(`--models file not found: ${path}`);
|
|
53027
53714
|
}
|
|
53028
53715
|
let raw2;
|
|
53029
53716
|
try {
|
|
53030
|
-
raw2 =
|
|
53717
|
+
raw2 = readFileSync22(path, "utf-8");
|
|
53031
53718
|
} catch (e) {
|
|
53032
53719
|
throw new Error(`failed to read --models file ${path}: ${e instanceof Error ? e.message : String(e)}`);
|
|
53033
53720
|
}
|
|
@@ -53106,7 +53793,7 @@ var exports_behavior_command = {};
|
|
|
53106
53793
|
__export(exports_behavior_command, {
|
|
53107
53794
|
behaviorCommand: () => behaviorCommand
|
|
53108
53795
|
});
|
|
53109
|
-
import { existsSync as
|
|
53796
|
+
import { existsSync as existsSync24, readFileSync as readFileSync23, writeFileSync as writeFileSync15 } from "fs";
|
|
53110
53797
|
function severityColor(sev) {
|
|
53111
53798
|
if (sev === "fix")
|
|
53112
53799
|
return green(sev);
|
|
@@ -53204,8 +53891,8 @@ function setTelemetryEnabled(value) {
|
|
|
53204
53891
|
const path = getConfigPath();
|
|
53205
53892
|
let cfg = {};
|
|
53206
53893
|
try {
|
|
53207
|
-
if (
|
|
53208
|
-
const parsed = JSON.parse(
|
|
53894
|
+
if (existsSync24(path)) {
|
|
53895
|
+
const parsed = JSON.parse(readFileSync23(path, "utf-8"));
|
|
53209
53896
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
53210
53897
|
cfg = parsed;
|
|
53211
53898
|
}
|
|
@@ -53214,7 +53901,7 @@ function setTelemetryEnabled(value) {
|
|
|
53214
53901
|
const behavior = cfg.behavior && typeof cfg.behavior === "object" && !Array.isArray(cfg.behavior) ? { ...cfg.behavior } : {};
|
|
53215
53902
|
behavior.telemetry = { enabled: value };
|
|
53216
53903
|
cfg.behavior = behavior;
|
|
53217
|
-
|
|
53904
|
+
writeFileSync15(path, `${JSON.stringify(cfg, null, 2)}
|
|
53218
53905
|
`, "utf-8");
|
|
53219
53906
|
}
|
|
53220
53907
|
function showTelemetry(action, json2) {
|
|
@@ -53226,8 +53913,8 @@ function showTelemetry(action, json2) {
|
|
|
53226
53913
|
let pending = 0;
|
|
53227
53914
|
try {
|
|
53228
53915
|
const path = outboxPath();
|
|
53229
|
-
if (
|
|
53230
|
-
pending =
|
|
53916
|
+
if (existsSync24(path)) {
|
|
53917
|
+
pending = readFileSync23(path, "utf8").split(`
|
|
53231
53918
|
`).filter(Boolean).length;
|
|
53232
53919
|
}
|
|
53233
53920
|
} catch {}
|
|
@@ -53299,9 +53986,9 @@ __export(exports_team_grid, {
|
|
|
53299
53986
|
});
|
|
53300
53987
|
import { spawn as spawn3 } from "child_process";
|
|
53301
53988
|
import { execSync } from "child_process";
|
|
53302
|
-
import { existsSync as
|
|
53989
|
+
import { existsSync as existsSync25, readFileSync as readFileSync24, writeFileSync as writeFileSync16 } from "fs";
|
|
53303
53990
|
import { connect as netConnect } from "net";
|
|
53304
|
-
import { dirname as dirname10, join as
|
|
53991
|
+
import { dirname as dirname10, join as join32 } from "path";
|
|
53305
53992
|
import { setTimeout as wait } from "timers/promises";
|
|
53306
53993
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
53307
53994
|
function resolveRouteInfo(modelId) {
|
|
@@ -53395,18 +54082,18 @@ function buildPaneHeader(model, prompt, bg) {
|
|
|
53395
54082
|
function findMagmuxBinary() {
|
|
53396
54083
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
53397
54084
|
const thisDir = dirname10(thisFile);
|
|
53398
|
-
const pkgRoot =
|
|
54085
|
+
const pkgRoot = join32(thisDir, "..");
|
|
53399
54086
|
const platform2 = process.platform;
|
|
53400
54087
|
const arch = process.arch;
|
|
53401
|
-
const bundledMagmux =
|
|
53402
|
-
if (
|
|
54088
|
+
const bundledMagmux = join32(pkgRoot, "native", `magmux-${platform2}-${arch}`);
|
|
54089
|
+
if (existsSync25(bundledMagmux))
|
|
53403
54090
|
return bundledMagmux;
|
|
53404
54091
|
try {
|
|
53405
54092
|
const pkgName = `@claudish/magmux-${platform2}-${arch}`;
|
|
53406
54093
|
let searchDir = pkgRoot;
|
|
53407
54094
|
for (let i = 0;i < 5; i++) {
|
|
53408
|
-
const candidate =
|
|
53409
|
-
if (
|
|
54095
|
+
const candidate = join32(searchDir, "node_modules", pkgName, "bin", "magmux");
|
|
54096
|
+
if (existsSync25(candidate))
|
|
53410
54097
|
return candidate;
|
|
53411
54098
|
const parent = dirname10(searchDir);
|
|
53412
54099
|
if (parent === searchDir)
|
|
@@ -53430,7 +54117,7 @@ function withoutControlPanes(evt) {
|
|
|
53430
54117
|
async function subscribeToMagmux(sockPath, onEvent) {
|
|
53431
54118
|
let client = null;
|
|
53432
54119
|
for (let attempt = 0;attempt < 40; attempt++) {
|
|
53433
|
-
if (
|
|
54120
|
+
if (existsSync25(sockPath)) {
|
|
53434
54121
|
try {
|
|
53435
54122
|
client = await new Promise((resolve5, reject) => {
|
|
53436
54123
|
const s = netConnect(sockPath);
|
|
@@ -53517,9 +54204,9 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
53517
54204
|
const keep = opts?.keep ?? false;
|
|
53518
54205
|
const manifest = setupSession(sessionPath, models, input);
|
|
53519
54206
|
const startedAt = new Date().toISOString();
|
|
53520
|
-
const gridfilePath =
|
|
53521
|
-
const prompt =
|
|
53522
|
-
const rawPrompt =
|
|
54207
|
+
const gridfilePath = join32(sessionPath, "gridfile.txt");
|
|
54208
|
+
const prompt = readFileSync24(join32(sessionPath, "input.md"), "utf-8").replace(/'/g, "'\\''").replace(/\n/g, " ");
|
|
54209
|
+
const rawPrompt = readFileSync24(join32(sessionPath, "input.md"), "utf-8");
|
|
53523
54210
|
const usedBannerColors = new Set;
|
|
53524
54211
|
const gridLines = Object.entries(manifest.models).map(([anonId]) => {
|
|
53525
54212
|
const model = manifest.models[anonId].model;
|
|
@@ -53530,7 +54217,7 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
53530
54217
|
const header = buildPaneHeader(model, rawPrompt, bg);
|
|
53531
54218
|
return `${header} claudish --model ${model} -y --quiet '${prompt}'`;
|
|
53532
54219
|
});
|
|
53533
|
-
|
|
54220
|
+
writeFileSync16(gridfilePath, `${gridLines.join(`
|
|
53534
54221
|
`)}
|
|
53535
54222
|
`, "utf-8");
|
|
53536
54223
|
const magmuxPath = findMagmuxBinary();
|
|
@@ -53550,8 +54237,8 @@ async function runWithGrid(sessionPath, models, input, opts) {
|
|
|
53550
54237
|
});
|
|
53551
54238
|
const [{ results }] = await Promise.all([subscription, procExit]);
|
|
53552
54239
|
const status = buildTeamStatus(manifest, startedAt, results?.panes ?? null);
|
|
53553
|
-
const statusPath =
|
|
53554
|
-
|
|
54240
|
+
const statusPath = join32(sessionPath, "status.json");
|
|
54241
|
+
writeFileSync16(statusPath, JSON.stringify(status, null, 2), "utf-8");
|
|
53555
54242
|
return status;
|
|
53556
54243
|
}
|
|
53557
54244
|
var BANNER_BG_COLORS;
|
|
@@ -53575,8 +54262,8 @@ var exports_team_cli = {};
|
|
|
53575
54262
|
__export(exports_team_cli, {
|
|
53576
54263
|
teamCommand: () => teamCommand
|
|
53577
54264
|
});
|
|
53578
|
-
import { readFileSync as
|
|
53579
|
-
import { join as
|
|
54265
|
+
import { readFileSync as readFileSync25 } from "fs";
|
|
54266
|
+
import { join as join33 } from "path";
|
|
53580
54267
|
function getFlag(args, flag) {
|
|
53581
54268
|
const idx = args.indexOf(flag);
|
|
53582
54269
|
if (idx === -1 || idx + 1 >= args.length)
|
|
@@ -53699,7 +54386,7 @@ async function teamCommand(args) {
|
|
|
53699
54386
|
}
|
|
53700
54387
|
case "judge": {
|
|
53701
54388
|
await judgeResponses(sessionPath, { judges });
|
|
53702
|
-
console.log(
|
|
54389
|
+
console.log(readFileSync25(join33(sessionPath, "verdict.md"), "utf-8"));
|
|
53703
54390
|
break;
|
|
53704
54391
|
}
|
|
53705
54392
|
case "run-and-judge": {
|
|
@@ -53717,7 +54404,7 @@ async function teamCommand(args) {
|
|
|
53717
54404
|
});
|
|
53718
54405
|
printStatus(status);
|
|
53719
54406
|
await judgeResponses(sessionPath, { judges });
|
|
53720
|
-
console.log(
|
|
54407
|
+
console.log(readFileSync25(join33(sessionPath, "verdict.md"), "utf-8"));
|
|
53721
54408
|
break;
|
|
53722
54409
|
}
|
|
53723
54410
|
case "status": {
|
|
@@ -54809,7 +55496,7 @@ function wrapAnsi(string5, columns, options) {
|
|
|
54809
55496
|
return String(string5).normalize().replaceAll(`\r
|
|
54810
55497
|
`, `
|
|
54811
55498
|
`).split(`
|
|
54812
|
-
`).map((line) =>
|
|
55499
|
+
`).map((line) => exec5(line, columns, options)).join(`
|
|
54813
55500
|
`);
|
|
54814
55501
|
}
|
|
54815
55502
|
var ESCAPES, END_CODE = 39, ANSI_ESCAPE_BELL = "\x07", ANSI_CSI = "[", ANSI_OSC = "]", ANSI_SGR_TERMINATOR = "m", ANSI_ESCAPE_LINK, wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`, wrapAnsiHyperlink = (url2) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url2}${ANSI_ESCAPE_BELL}`, wordLengths = (string5) => string5.split(" ").map((character) => stringWidth(character)), wrapWord = (rows, word, columns) => {
|
|
@@ -54863,7 +55550,7 @@ var ESCAPES, END_CODE = 39, ANSI_ESCAPE_BELL = "\x07", ANSI_CSI = "[", ANSI_OSC
|
|
|
54863
55550
|
return string5;
|
|
54864
55551
|
}
|
|
54865
55552
|
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
54866
|
-
},
|
|
55553
|
+
}, exec5 = (string5, columns, options = {}) => {
|
|
54867
55554
|
if (options.trim !== false && string5.trim() === "") {
|
|
54868
55555
|
return "";
|
|
54869
55556
|
}
|
|
@@ -54965,7 +55652,7 @@ var init_wrap_ansi = __esm(() => {
|
|
|
54965
55652
|
function breakLines(content, width) {
|
|
54966
55653
|
return content.split(`
|
|
54967
55654
|
`).flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true }).split(`
|
|
54968
|
-
`).map((
|
|
55655
|
+
`).map((str2) => str2.trimEnd())).join(`
|
|
54969
55656
|
`);
|
|
54970
55657
|
}
|
|
54971
55658
|
function readlineWidth() {
|
|
@@ -61511,12 +62198,12 @@ var require_bom_handling = __commonJS((exports) => {
|
|
|
61511
62198
|
this.encoder = encoder;
|
|
61512
62199
|
this.addBOM = true;
|
|
61513
62200
|
}
|
|
61514
|
-
PrependBOMWrapper.prototype.write = function(
|
|
62201
|
+
PrependBOMWrapper.prototype.write = function(str2) {
|
|
61515
62202
|
if (this.addBOM) {
|
|
61516
|
-
|
|
62203
|
+
str2 = BOMChar + str2;
|
|
61517
62204
|
this.addBOM = false;
|
|
61518
62205
|
}
|
|
61519
|
-
return this.encoder.write(
|
|
62206
|
+
return this.encoder.write(str2);
|
|
61520
62207
|
};
|
|
61521
62208
|
PrependBOMWrapper.prototype.end = function() {
|
|
61522
62209
|
return this.encoder.end();
|
|
@@ -61607,29 +62294,29 @@ var require_internal = __commonJS((exports, module) => {
|
|
|
61607
62294
|
function InternalEncoder(options, codec2) {
|
|
61608
62295
|
this.enc = codec2.enc;
|
|
61609
62296
|
}
|
|
61610
|
-
InternalEncoder.prototype.write = function(
|
|
61611
|
-
return Buffer2.from(
|
|
62297
|
+
InternalEncoder.prototype.write = function(str2) {
|
|
62298
|
+
return Buffer2.from(str2, this.enc);
|
|
61612
62299
|
};
|
|
61613
62300
|
InternalEncoder.prototype.end = function() {};
|
|
61614
62301
|
function InternalEncoderBase64(options, codec2) {
|
|
61615
62302
|
this.prevStr = "";
|
|
61616
62303
|
}
|
|
61617
|
-
InternalEncoderBase64.prototype.write = function(
|
|
61618
|
-
|
|
61619
|
-
var completeQuads =
|
|
61620
|
-
this.prevStr =
|
|
61621
|
-
|
|
61622
|
-
return Buffer2.from(
|
|
62304
|
+
InternalEncoderBase64.prototype.write = function(str2) {
|
|
62305
|
+
str2 = this.prevStr + str2;
|
|
62306
|
+
var completeQuads = str2.length - str2.length % 4;
|
|
62307
|
+
this.prevStr = str2.slice(completeQuads);
|
|
62308
|
+
str2 = str2.slice(0, completeQuads);
|
|
62309
|
+
return Buffer2.from(str2, "base64");
|
|
61623
62310
|
};
|
|
61624
62311
|
InternalEncoderBase64.prototype.end = function() {
|
|
61625
62312
|
return Buffer2.from(this.prevStr, "base64");
|
|
61626
62313
|
};
|
|
61627
62314
|
function InternalEncoderCesu8(options, codec2) {}
|
|
61628
|
-
InternalEncoderCesu8.prototype.write = function(
|
|
61629
|
-
var buf = Buffer2.alloc(
|
|
62315
|
+
InternalEncoderCesu8.prototype.write = function(str2) {
|
|
62316
|
+
var buf = Buffer2.alloc(str2.length * 3);
|
|
61630
62317
|
var bufIdx = 0;
|
|
61631
|
-
for (var i = 0;i <
|
|
61632
|
-
var charCode =
|
|
62318
|
+
for (var i = 0;i < str2.length; i++) {
|
|
62319
|
+
var charCode = str2.charCodeAt(i);
|
|
61633
62320
|
if (charCode < 128) {
|
|
61634
62321
|
buf[bufIdx++] = charCode;
|
|
61635
62322
|
} else if (charCode < 2048) {
|
|
@@ -61709,25 +62396,25 @@ var require_internal = __commonJS((exports, module) => {
|
|
|
61709
62396
|
function InternalEncoderUtf8(options, codec2) {
|
|
61710
62397
|
this.highSurrogate = "";
|
|
61711
62398
|
}
|
|
61712
|
-
InternalEncoderUtf8.prototype.write = function(
|
|
62399
|
+
InternalEncoderUtf8.prototype.write = function(str2) {
|
|
61713
62400
|
if (this.highSurrogate) {
|
|
61714
|
-
|
|
62401
|
+
str2 = this.highSurrogate + str2;
|
|
61715
62402
|
this.highSurrogate = "";
|
|
61716
62403
|
}
|
|
61717
|
-
if (
|
|
61718
|
-
var charCode =
|
|
62404
|
+
if (str2.length > 0) {
|
|
62405
|
+
var charCode = str2.charCodeAt(str2.length - 1);
|
|
61719
62406
|
if (charCode >= 55296 && charCode < 56320) {
|
|
61720
|
-
this.highSurrogate =
|
|
61721
|
-
|
|
62407
|
+
this.highSurrogate = str2[str2.length - 1];
|
|
62408
|
+
str2 = str2.slice(0, str2.length - 1);
|
|
61722
62409
|
}
|
|
61723
62410
|
}
|
|
61724
|
-
return Buffer2.from(
|
|
62411
|
+
return Buffer2.from(str2, this.enc);
|
|
61725
62412
|
};
|
|
61726
62413
|
InternalEncoderUtf8.prototype.end = function() {
|
|
61727
62414
|
if (this.highSurrogate) {
|
|
61728
|
-
var
|
|
62415
|
+
var str2 = this.highSurrogate;
|
|
61729
62416
|
this.highSurrogate = "";
|
|
61730
|
-
return Buffer2.from(
|
|
62417
|
+
return Buffer2.from(str2, this.enc);
|
|
61731
62418
|
}
|
|
61732
62419
|
};
|
|
61733
62420
|
});
|
|
@@ -61751,8 +62438,8 @@ var require_utf32 = __commonJS((exports) => {
|
|
|
61751
62438
|
this.isLE = codec2.isLE;
|
|
61752
62439
|
this.highSurrogate = 0;
|
|
61753
62440
|
}
|
|
61754
|
-
Utf32Encoder.prototype.write = function(
|
|
61755
|
-
var src = Buffer2.from(
|
|
62441
|
+
Utf32Encoder.prototype.write = function(str2) {
|
|
62442
|
+
var src = Buffer2.from(str2, "ucs2");
|
|
61756
62443
|
var dst = Buffer2.alloc(src.length * 2);
|
|
61757
62444
|
var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE;
|
|
61758
62445
|
var offset = 0;
|
|
@@ -61873,8 +62560,8 @@ var require_utf32 = __commonJS((exports) => {
|
|
|
61873
62560
|
}
|
|
61874
62561
|
this.encoder = codec2.iconv.getEncoder(options.defaultEncoding || "utf-32le", options);
|
|
61875
62562
|
}
|
|
61876
|
-
Utf32AutoEncoder.prototype.write = function(
|
|
61877
|
-
return this.encoder.write(
|
|
62563
|
+
Utf32AutoEncoder.prototype.write = function(str2) {
|
|
62564
|
+
return this.encoder.write(str2);
|
|
61878
62565
|
};
|
|
61879
62566
|
Utf32AutoEncoder.prototype.end = function() {
|
|
61880
62567
|
return this.encoder.end();
|
|
@@ -61975,8 +62662,8 @@ var require_utf16 = __commonJS((exports) => {
|
|
|
61975
62662
|
Utf16BECodec.prototype.decoder = Utf16BEDecoder;
|
|
61976
62663
|
Utf16BECodec.prototype.bomAware = true;
|
|
61977
62664
|
function Utf16BEEncoder() {}
|
|
61978
|
-
Utf16BEEncoder.prototype.write = function(
|
|
61979
|
-
var buf = Buffer2.from(
|
|
62665
|
+
Utf16BEEncoder.prototype.write = function(str2) {
|
|
62666
|
+
var buf = Buffer2.from(str2, "ucs2");
|
|
61980
62667
|
for (var i = 0;i < buf.length; i += 2) {
|
|
61981
62668
|
var tmp = buf[i];
|
|
61982
62669
|
buf[i] = buf[i + 1];
|
|
@@ -62024,8 +62711,8 @@ var require_utf16 = __commonJS((exports) => {
|
|
|
62024
62711
|
}
|
|
62025
62712
|
this.encoder = codec2.iconv.getEncoder("utf-16le", options);
|
|
62026
62713
|
}
|
|
62027
|
-
Utf16Encoder.prototype.write = function(
|
|
62028
|
-
return this.encoder.write(
|
|
62714
|
+
Utf16Encoder.prototype.write = function(str2) {
|
|
62715
|
+
return this.encoder.write(str2);
|
|
62029
62716
|
};
|
|
62030
62717
|
Utf16Encoder.prototype.end = function() {
|
|
62031
62718
|
return this.encoder.end();
|
|
@@ -62124,8 +62811,8 @@ var require_utf7 = __commonJS((exports) => {
|
|
|
62124
62811
|
function Utf7Encoder(options, codec2) {
|
|
62125
62812
|
this.iconv = codec2.iconv;
|
|
62126
62813
|
}
|
|
62127
|
-
Utf7Encoder.prototype.write = function(
|
|
62128
|
-
return Buffer2.from(
|
|
62814
|
+
Utf7Encoder.prototype.write = function(str2) {
|
|
62815
|
+
return Buffer2.from(str2.replace(nonDirectChars, function(chunk) {
|
|
62129
62816
|
return "+" + (chunk === "+" ? "" : this.iconv.encode(chunk, "utf16-be").toString("base64").replace(/=+$/, "")) + "-";
|
|
62130
62817
|
}.bind(this)));
|
|
62131
62818
|
};
|
|
@@ -62208,14 +62895,14 @@ var require_utf7 = __commonJS((exports) => {
|
|
|
62208
62895
|
this.base64Accum = Buffer2.alloc(6);
|
|
62209
62896
|
this.base64AccumIdx = 0;
|
|
62210
62897
|
}
|
|
62211
|
-
Utf7IMAPEncoder.prototype.write = function(
|
|
62898
|
+
Utf7IMAPEncoder.prototype.write = function(str2) {
|
|
62212
62899
|
var inBase64 = this.inBase64;
|
|
62213
62900
|
var base64Accum = this.base64Accum;
|
|
62214
62901
|
var base64AccumIdx = this.base64AccumIdx;
|
|
62215
|
-
var buf = Buffer2.alloc(
|
|
62902
|
+
var buf = Buffer2.alloc(str2.length * 5 + 10);
|
|
62216
62903
|
var bufIdx = 0;
|
|
62217
|
-
for (var i2 = 0;i2 <
|
|
62218
|
-
var uChar =
|
|
62904
|
+
for (var i2 = 0;i2 < str2.length; i2++) {
|
|
62905
|
+
var uChar = str2.charCodeAt(i2);
|
|
62219
62906
|
if (uChar >= 32 && uChar <= 126) {
|
|
62220
62907
|
if (inBase64) {
|
|
62221
62908
|
if (base64AccumIdx > 0) {
|
|
@@ -62353,10 +63040,10 @@ var require_sbcs_codec = __commonJS((exports) => {
|
|
|
62353
63040
|
function SBCSEncoder(options, codec2) {
|
|
62354
63041
|
this.encodeBuf = codec2.encodeBuf;
|
|
62355
63042
|
}
|
|
62356
|
-
SBCSEncoder.prototype.write = function(
|
|
62357
|
-
var buf = Buffer2.alloc(
|
|
62358
|
-
for (var i = 0;i <
|
|
62359
|
-
buf[i] = this.encodeBuf[
|
|
63043
|
+
SBCSEncoder.prototype.write = function(str2) {
|
|
63044
|
+
var buf = Buffer2.alloc(str2.length);
|
|
63045
|
+
for (var i = 0;i < str2.length; i++) {
|
|
63046
|
+
buf[i] = this.encodeBuf[str2.charCodeAt(i)];
|
|
62360
63047
|
}
|
|
62361
63048
|
return buf;
|
|
62362
63049
|
};
|
|
@@ -63225,8 +63912,8 @@ var require_dbcs_codec = __commonJS((exports) => {
|
|
|
63225
63912
|
this.defaultCharSingleByte = codec2.defCharSB;
|
|
63226
63913
|
this.gb18030 = codec2.gb18030;
|
|
63227
63914
|
}
|
|
63228
|
-
DBCSEncoder.prototype.write = function(
|
|
63229
|
-
var newBuf = Buffer2.alloc(
|
|
63915
|
+
DBCSEncoder.prototype.write = function(str2) {
|
|
63916
|
+
var newBuf = Buffer2.alloc(str2.length * (this.gb18030 ? 4 : 3));
|
|
63230
63917
|
var leadSurrogate = this.leadSurrogate;
|
|
63231
63918
|
var seqObj = this.seqObj;
|
|
63232
63919
|
var nextChar = -1;
|
|
@@ -63234,9 +63921,9 @@ var require_dbcs_codec = __commonJS((exports) => {
|
|
|
63234
63921
|
var j = 0;
|
|
63235
63922
|
while (true) {
|
|
63236
63923
|
if (nextChar === -1) {
|
|
63237
|
-
if (i2 ==
|
|
63924
|
+
if (i2 == str2.length)
|
|
63238
63925
|
break;
|
|
63239
|
-
var uCode =
|
|
63926
|
+
var uCode = str2.charCodeAt(i2++);
|
|
63240
63927
|
} else {
|
|
63241
63928
|
var uCode = nextChar;
|
|
63242
63929
|
nextChar = -1;
|
|
@@ -64975,10 +65662,10 @@ var require_lib3 = __commonJS((exports, module) => {
|
|
|
64975
65662
|
iconv.encodings = null;
|
|
64976
65663
|
iconv.defaultCharUnicode = "\uFFFD";
|
|
64977
65664
|
iconv.defaultCharSingleByte = "?";
|
|
64978
|
-
iconv.encode = function encode3(
|
|
64979
|
-
|
|
65665
|
+
iconv.encode = function encode3(str2, encoding, options) {
|
|
65666
|
+
str2 = "" + (str2 || "");
|
|
64980
65667
|
var encoder = iconv.getEncoder(encoding, options);
|
|
64981
|
-
var res = encoder.write(
|
|
65668
|
+
var res = encoder.write(str2);
|
|
64982
65669
|
var trail = encoder.end();
|
|
64983
65670
|
return trail && trail.length > 0 ? Buffer2.concat([res, trail]) : res;
|
|
64984
65671
|
};
|
|
@@ -65143,7 +65830,7 @@ var init_RemoveFileError = __esm(() => {
|
|
|
65143
65830
|
|
|
65144
65831
|
// ../../node_modules/.bun/@inquirer+external-editor@2.0.1+04f2146be16c61ef/node_modules/@inquirer/external-editor/dist/index.js
|
|
65145
65832
|
import { spawn as spawn4, spawnSync as spawnSync2 } from "child_process";
|
|
65146
|
-
import { readFileSync as
|
|
65833
|
+
import { readFileSync as readFileSync26, unlinkSync as unlinkSync6, writeFileSync as writeFileSync17 } from "fs";
|
|
65147
65834
|
import path from "path";
|
|
65148
65835
|
import os from "os";
|
|
65149
65836
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
@@ -65167,12 +65854,12 @@ function sanitizeAffix(affix) {
|
|
|
65167
65854
|
return "";
|
|
65168
65855
|
return affix.replace(/[^a-zA-Z0-9_.-]/g, "_");
|
|
65169
65856
|
}
|
|
65170
|
-
function splitStringBySpace(
|
|
65857
|
+
function splitStringBySpace(str2) {
|
|
65171
65858
|
const pieces = [];
|
|
65172
65859
|
let currentString = "";
|
|
65173
|
-
for (let strIndex = 0;strIndex <
|
|
65174
|
-
const currentLetter =
|
|
65175
|
-
if (strIndex > 0 && currentLetter === " " &&
|
|
65860
|
+
for (let strIndex = 0;strIndex < str2.length; strIndex++) {
|
|
65861
|
+
const currentLetter = str2.charAt(strIndex);
|
|
65862
|
+
if (strIndex > 0 && currentLetter === " " && str2[strIndex - 1] !== "\\" && currentString.length > 0) {
|
|
65176
65863
|
pieces.push(currentString);
|
|
65177
65864
|
currentString = "";
|
|
65178
65865
|
} else {
|
|
@@ -65252,14 +65939,14 @@ class ExternalEditor {
|
|
|
65252
65939
|
if (Object.prototype.hasOwnProperty.call(this.fileOptions, "mode")) {
|
|
65253
65940
|
opt.mode = this.fileOptions.mode;
|
|
65254
65941
|
}
|
|
65255
|
-
|
|
65942
|
+
writeFileSync17(this.tempFile, this.text, opt);
|
|
65256
65943
|
} catch (createFileError) {
|
|
65257
65944
|
throw new CreateFileError(createFileError);
|
|
65258
65945
|
}
|
|
65259
65946
|
}
|
|
65260
65947
|
readTemporaryFile() {
|
|
65261
65948
|
try {
|
|
65262
|
-
const tempFileBuffer =
|
|
65949
|
+
const tempFileBuffer = readFileSync26(this.tempFile);
|
|
65263
65950
|
if (tempFileBuffer.length === 0) {
|
|
65264
65951
|
this.text = "";
|
|
65265
65952
|
} else {
|
|
@@ -65275,7 +65962,7 @@ class ExternalEditor {
|
|
|
65275
65962
|
}
|
|
65276
65963
|
removeTemporaryFile() {
|
|
65277
65964
|
try {
|
|
65278
|
-
|
|
65965
|
+
unlinkSync6(this.tempFile);
|
|
65279
65966
|
} catch (removeFileError) {
|
|
65280
65967
|
throw new RemoveFileError(removeFileError);
|
|
65281
65968
|
}
|
|
@@ -66240,9 +66927,9 @@ var init_dist16 = __esm(() => {
|
|
|
66240
66927
|
|
|
66241
66928
|
// src/auth/antigravity-oauth.ts
|
|
66242
66929
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
66243
|
-
import { existsSync as
|
|
66244
|
-
import { homedir as
|
|
66245
|
-
import { join as
|
|
66930
|
+
import { existsSync as existsSync26, unlinkSync as unlinkSync7 } from "fs";
|
|
66931
|
+
import { homedir as homedir30 } from "os";
|
|
66932
|
+
import { join as join34 } from "path";
|
|
66246
66933
|
async function defaultSuggestModel() {
|
|
66247
66934
|
try {
|
|
66248
66935
|
const tok = readSharedAntigravityToken();
|
|
@@ -66363,9 +67050,9 @@ No session detected yet. Starting the Antigravity CLI interactively \u2014
|
|
|
66363
67050
|
async logout(deps) {
|
|
66364
67051
|
deleteSharedAntigravityToken(deps);
|
|
66365
67052
|
try {
|
|
66366
|
-
const tokenFile =
|
|
66367
|
-
if (
|
|
66368
|
-
|
|
67053
|
+
const tokenFile = join34(homedir30(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
67054
|
+
if (existsSync26(tokenFile))
|
|
67055
|
+
unlinkSync7(tokenFile);
|
|
66369
67056
|
} catch {}
|
|
66370
67057
|
log("[AntigravityOAuth] Antigravity session cleared (keychain + agy token file)");
|
|
66371
67058
|
}
|
|
@@ -66463,6 +67150,7 @@ var init_auth_commands = __esm(() => {
|
|
|
66463
67150
|
init_antigravity_oauth();
|
|
66464
67151
|
init_antigravity_token();
|
|
66465
67152
|
init_codex_oauth();
|
|
67153
|
+
init_grok_oauth();
|
|
66466
67154
|
init_kimi_oauth();
|
|
66467
67155
|
init_oauth_registry();
|
|
66468
67156
|
AUTH_PROVIDERS = [
|
|
@@ -66486,6 +67174,13 @@ var init_auth_commands = __esm(() => {
|
|
|
66486
67174
|
prefix: "cx@",
|
|
66487
67175
|
getInstance: () => CodexOAuth.getInstance(),
|
|
66488
67176
|
registryKeys: ["openai-codex"]
|
|
67177
|
+
},
|
|
67178
|
+
{
|
|
67179
|
+
name: "grok",
|
|
67180
|
+
displayName: "Grok Build (SuperGrok / X Premium+)",
|
|
67181
|
+
prefix: "gk@",
|
|
67182
|
+
getInstance: () => GrokOAuth.getInstance(),
|
|
67183
|
+
registryKeys: ["grok-subscription"]
|
|
66489
67184
|
}
|
|
66490
67185
|
];
|
|
66491
67186
|
});
|
|
@@ -68230,9 +68925,9 @@ function timelineBarCells(totalMs, maxTotalMs, barWidth) {
|
|
|
68230
68925
|
function splitStageCells(ttfbMs, ttftMs, totalMs, barCells) {
|
|
68231
68926
|
const net = Math.max(0, ttfbMs);
|
|
68232
68927
|
const srv = Math.max(0, ttftMs - ttfbMs);
|
|
68233
|
-
const
|
|
68234
|
-
const durations = [net, srv,
|
|
68235
|
-
const sum = net + srv +
|
|
68928
|
+
const str2 = Math.max(0, totalMs - ttftMs);
|
|
68929
|
+
const durations = [net, srv, str2];
|
|
68930
|
+
const sum = net + srv + str2;
|
|
68236
68931
|
if (barCells <= 0)
|
|
68237
68932
|
return { network: 0, server: 0, streaming: 0 };
|
|
68238
68933
|
if (sum <= 0) {
|
|
@@ -68841,11 +69536,11 @@ function renderCard(result, isLiveProbe, w, width, scales, directKeyVar) {
|
|
|
68841
69536
|
function renderLegend(w) {
|
|
68842
69537
|
const net = STAGE_BG_ANSI.network;
|
|
68843
69538
|
const srv = STAGE_BG_ANSI.server;
|
|
68844
|
-
const
|
|
69539
|
+
const str2 = STAGE_BG_ANSI.streaming;
|
|
68845
69540
|
const netFg = hexToAnsiFg(STAGE_FG.network);
|
|
68846
69541
|
const srvFg = hexToAnsiFg(STAGE_FG.server);
|
|
68847
69542
|
const strFg = hexToAnsiFg(STAGE_FG.streaming);
|
|
68848
|
-
w(` ${pc.dim}Stages:${pc.reset} ` + `${net} ${ANSI_RESET}${netFg} network${pc.reset} ` + `${srv} ${ANSI_RESET}${srvFg} server${pc.reset} ` + `${
|
|
69543
|
+
w(` ${pc.dim}Stages:${pc.reset} ` + `${net} ${ANSI_RESET}${netFg} network${pc.reset} ` + `${srv} ${ANSI_RESET}${srvFg} server${pc.reset} ` + `${str2} ${ANSI_RESET}${strFg} streaming${pc.reset} ` + `${pc.dim}\xB7\xB7 idle${pc.reset}
|
|
68849
69544
|
`);
|
|
68850
69545
|
w(` ${pc.dim}bar length = total time, shared scale (slowest = full bar) \xB7 ` + `tok/s scaled to fastest${pc.reset}
|
|
68851
69546
|
`);
|
|
@@ -70481,22 +71176,22 @@ __export(exports_cli, {
|
|
|
70481
71176
|
});
|
|
70482
71177
|
import {
|
|
70483
71178
|
copyFileSync as copyFileSync2,
|
|
70484
|
-
existsSync as
|
|
70485
|
-
mkdirSync as
|
|
70486
|
-
readFileSync as
|
|
71179
|
+
existsSync as existsSync27,
|
|
71180
|
+
mkdirSync as mkdirSync15,
|
|
71181
|
+
readFileSync as readFileSync27,
|
|
70487
71182
|
readdirSync as readdirSync5,
|
|
70488
|
-
unlinkSync as
|
|
70489
|
-
writeFileSync as
|
|
71183
|
+
unlinkSync as unlinkSync8,
|
|
71184
|
+
writeFileSync as writeFileSync18
|
|
70490
71185
|
} from "fs";
|
|
70491
|
-
import { homedir as
|
|
70492
|
-
import { dirname as dirname11, join as
|
|
71186
|
+
import { homedir as homedir31 } from "os";
|
|
71187
|
+
import { dirname as dirname11, join as join35 } from "path";
|
|
70493
71188
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
70494
71189
|
function getVersion3() {
|
|
70495
71190
|
return VERSION;
|
|
70496
71191
|
}
|
|
70497
71192
|
function clearAllModelCaches() {
|
|
70498
|
-
const cacheDir =
|
|
70499
|
-
if (!
|
|
71193
|
+
const cacheDir = join35(homedir31(), ".claudish");
|
|
71194
|
+
if (!existsSync27(cacheDir))
|
|
70500
71195
|
return;
|
|
70501
71196
|
const cachePatterns = ["pricing-cache.json", "recommended-models-cache.json"];
|
|
70502
71197
|
let cleared = 0;
|
|
@@ -70504,7 +71199,7 @@ function clearAllModelCaches() {
|
|
|
70504
71199
|
const files = readdirSync5(cacheDir);
|
|
70505
71200
|
for (const file2 of files) {
|
|
70506
71201
|
if (cachePatterns.includes(file2)) {
|
|
70507
|
-
|
|
71202
|
+
unlinkSync8(join35(cacheDir, file2));
|
|
70508
71203
|
cleared++;
|
|
70509
71204
|
}
|
|
70510
71205
|
}
|
|
@@ -70920,15 +71615,15 @@ Usage: claudish --models --provider <slug>`);
|
|
|
70920
71615
|
});
|
|
70921
71616
|
config3.resolvedDefaultProvider = resolved;
|
|
70922
71617
|
if (resolved.legacyAutoPromoted && !config3.quiet) {
|
|
70923
|
-
const markerFile =
|
|
70924
|
-
if (!
|
|
71618
|
+
const markerFile = join35(homedir31(), ".claudish", ".legacy-litellm-hint-shown");
|
|
71619
|
+
if (!existsSync27(markerFile)) {
|
|
70925
71620
|
const hint = buildLegacyHint(resolved);
|
|
70926
71621
|
if (hint) {
|
|
70927
71622
|
console.error(hint);
|
|
70928
71623
|
}
|
|
70929
71624
|
try {
|
|
70930
|
-
|
|
70931
|
-
|
|
71625
|
+
mkdirSync15(dirname11(markerFile), { recursive: true });
|
|
71626
|
+
writeFileSync18(markerFile, new Date().toISOString(), "utf-8");
|
|
70932
71627
|
} catch {}
|
|
70933
71628
|
}
|
|
70934
71629
|
}
|
|
@@ -71399,9 +72094,8 @@ async function probeModelRouting(models, jsonOutput, options = { live: true, tim
|
|
|
71399
72094
|
formatAdapterName = "OpenAIAPIFormat";
|
|
71400
72095
|
declaredStreamFormat = "openai-sse";
|
|
71401
72096
|
}
|
|
71402
|
-
const {
|
|
71403
|
-
const
|
|
71404
|
-
const modelTranslator = adapterManager.getAdapter();
|
|
72097
|
+
const { resolveModelDialect: resolveModelDialect2 } = await Promise.resolve().then(() => (init_dialect_manager(), exports_dialect_manager));
|
|
72098
|
+
const modelTranslator = resolveModelDialect2(modelName);
|
|
71405
72099
|
const modelTranslatorName = modelTranslator.getName();
|
|
71406
72100
|
const TRANSPORT_OVERRIDES = {
|
|
71407
72101
|
litellm: "openai-sse",
|
|
@@ -71998,8 +72692,8 @@ ${h("MORE INFO")}
|
|
|
71998
72692
|
}
|
|
71999
72693
|
function printAIAgentGuide() {
|
|
72000
72694
|
try {
|
|
72001
|
-
const guidePath =
|
|
72002
|
-
const guideContent =
|
|
72695
|
+
const guidePath = join35(__dirname3, "../AI_AGENT_GUIDE.md");
|
|
72696
|
+
const guideContent = readFileSync27(guidePath, "utf-8");
|
|
72003
72697
|
console.log(guideContent);
|
|
72004
72698
|
} catch (error46) {
|
|
72005
72699
|
console.error("Error reading AI Agent Guide:");
|
|
@@ -72015,19 +72709,19 @@ async function initializeClaudishSkill() {
|
|
|
72015
72709
|
console.log(`\uD83D\uDD27 Initializing Claudish skill in current project...
|
|
72016
72710
|
`);
|
|
72017
72711
|
const cwd = process.cwd();
|
|
72018
|
-
const claudeDir =
|
|
72019
|
-
const skillsDir =
|
|
72020
|
-
const claudishSkillDir =
|
|
72021
|
-
const skillFile =
|
|
72022
|
-
if (
|
|
72712
|
+
const claudeDir = join35(cwd, ".claude");
|
|
72713
|
+
const skillsDir = join35(claudeDir, "skills");
|
|
72714
|
+
const claudishSkillDir = join35(skillsDir, "claudish-usage");
|
|
72715
|
+
const skillFile = join35(claudishSkillDir, "SKILL.md");
|
|
72716
|
+
if (existsSync27(skillFile)) {
|
|
72023
72717
|
console.log("\u2705 Claudish skill already installed at:");
|
|
72024
72718
|
console.log(` ${skillFile}
|
|
72025
72719
|
`);
|
|
72026
72720
|
console.log("\uD83D\uDCA1 To reinstall, delete the file and run 'claudish --init' again.");
|
|
72027
72721
|
return;
|
|
72028
72722
|
}
|
|
72029
|
-
const sourceSkillPath =
|
|
72030
|
-
if (!
|
|
72723
|
+
const sourceSkillPath = join35(__dirname3, "../skills/claudish-usage/SKILL.md");
|
|
72724
|
+
if (!existsSync27(sourceSkillPath)) {
|
|
72031
72725
|
console.error("\u274C Error: Claudish skill file not found in installation.");
|
|
72032
72726
|
console.error(` Expected at: ${sourceSkillPath}`);
|
|
72033
72727
|
console.error(`
|
|
@@ -72036,16 +72730,16 @@ async function initializeClaudishSkill() {
|
|
|
72036
72730
|
process.exit(1);
|
|
72037
72731
|
}
|
|
72038
72732
|
try {
|
|
72039
|
-
if (!
|
|
72040
|
-
|
|
72733
|
+
if (!existsSync27(claudeDir)) {
|
|
72734
|
+
mkdirSync15(claudeDir, { recursive: true });
|
|
72041
72735
|
console.log("\uD83D\uDCC1 Created .claude/ directory");
|
|
72042
72736
|
}
|
|
72043
|
-
if (!
|
|
72044
|
-
|
|
72737
|
+
if (!existsSync27(skillsDir)) {
|
|
72738
|
+
mkdirSync15(skillsDir, { recursive: true });
|
|
72045
72739
|
console.log("\uD83D\uDCC1 Created .claude/skills/ directory");
|
|
72046
72740
|
}
|
|
72047
|
-
if (!
|
|
72048
|
-
|
|
72741
|
+
if (!existsSync27(claudishSkillDir)) {
|
|
72742
|
+
mkdirSync15(claudishSkillDir, { recursive: true });
|
|
72049
72743
|
console.log("\uD83D\uDCC1 Created .claude/skills/claudish-usage/ directory");
|
|
72050
72744
|
}
|
|
72051
72745
|
copyFileSync2(sourceSkillPath, skillFile);
|
|
@@ -72130,33 +72824,33 @@ __export(exports_update_checker, {
|
|
|
72130
72824
|
clearCache: () => clearCache,
|
|
72131
72825
|
checkForUpdates: () => checkForUpdates
|
|
72132
72826
|
});
|
|
72133
|
-
import { existsSync as
|
|
72134
|
-
import { homedir as
|
|
72135
|
-
import { join as
|
|
72827
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync16, readFileSync as readFileSync28, unlinkSync as unlinkSync9, writeFileSync as writeFileSync19 } from "fs";
|
|
72828
|
+
import { homedir as homedir32, platform as platform2, tmpdir } from "os";
|
|
72829
|
+
import { join as join36 } from "path";
|
|
72136
72830
|
function getCacheFilePath() {
|
|
72137
72831
|
let cacheDir;
|
|
72138
72832
|
if (isWindows) {
|
|
72139
|
-
const localAppData = process.env.LOCALAPPDATA ||
|
|
72140
|
-
cacheDir =
|
|
72833
|
+
const localAppData = process.env.LOCALAPPDATA || join36(homedir32(), "AppData", "Local");
|
|
72834
|
+
cacheDir = join36(localAppData, "claudish");
|
|
72141
72835
|
} else {
|
|
72142
|
-
cacheDir =
|
|
72836
|
+
cacheDir = join36(homedir32(), ".cache", "claudish");
|
|
72143
72837
|
}
|
|
72144
72838
|
try {
|
|
72145
|
-
if (!
|
|
72146
|
-
|
|
72839
|
+
if (!existsSync28(cacheDir)) {
|
|
72840
|
+
mkdirSync16(cacheDir, { recursive: true });
|
|
72147
72841
|
}
|
|
72148
|
-
return
|
|
72842
|
+
return join36(cacheDir, "update-check.json");
|
|
72149
72843
|
} catch {
|
|
72150
|
-
return
|
|
72844
|
+
return join36(tmpdir(), "claudish-update-check.json");
|
|
72151
72845
|
}
|
|
72152
72846
|
}
|
|
72153
72847
|
function readCache() {
|
|
72154
72848
|
try {
|
|
72155
72849
|
const cachePath = getCacheFilePath();
|
|
72156
|
-
if (!
|
|
72850
|
+
if (!existsSync28(cachePath)) {
|
|
72157
72851
|
return null;
|
|
72158
72852
|
}
|
|
72159
|
-
const data = JSON.parse(
|
|
72853
|
+
const data = JSON.parse(readFileSync28(cachePath, "utf-8"));
|
|
72160
72854
|
return data;
|
|
72161
72855
|
} catch {
|
|
72162
72856
|
return null;
|
|
@@ -72169,7 +72863,7 @@ function writeCache(latestVersion) {
|
|
|
72169
72863
|
lastCheck: Date.now(),
|
|
72170
72864
|
latestVersion
|
|
72171
72865
|
};
|
|
72172
|
-
|
|
72866
|
+
writeFileSync19(cachePath, JSON.stringify(data), "utf-8");
|
|
72173
72867
|
} catch {}
|
|
72174
72868
|
}
|
|
72175
72869
|
function isCacheValid(cache2) {
|
|
@@ -72179,8 +72873,8 @@ function isCacheValid(cache2) {
|
|
|
72179
72873
|
function clearCache() {
|
|
72180
72874
|
try {
|
|
72181
72875
|
const cachePath = getCacheFilePath();
|
|
72182
|
-
if (
|
|
72183
|
-
|
|
72876
|
+
if (existsSync28(cachePath)) {
|
|
72877
|
+
unlinkSync9(cachePath);
|
|
72184
72878
|
}
|
|
72185
72879
|
} catch {}
|
|
72186
72880
|
}
|
|
@@ -73064,15 +73758,15 @@ var init_local_liveness = __esm(() => {
|
|
|
73064
73758
|
});
|
|
73065
73759
|
|
|
73066
73760
|
// src/providers/probe-catalog.ts
|
|
73067
|
-
import { existsSync as
|
|
73068
|
-
import { homedir as
|
|
73069
|
-
import { dirname as dirname12, join as
|
|
73761
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync17, readFileSync as readFileSync29, writeFileSync as writeFileSync20 } from "fs";
|
|
73762
|
+
import { homedir as homedir33 } from "os";
|
|
73763
|
+
import { dirname as dirname12, join as join37 } from "path";
|
|
73070
73764
|
function readProbeModelsCache(path2 = PROBE_MODELS_CACHE_PATH) {
|
|
73071
|
-
if (!
|
|
73765
|
+
if (!existsSync29(path2))
|
|
73072
73766
|
return null;
|
|
73073
73767
|
let raw2;
|
|
73074
73768
|
try {
|
|
73075
|
-
raw2 = JSON.parse(
|
|
73769
|
+
raw2 = JSON.parse(readFileSync29(path2, "utf-8"));
|
|
73076
73770
|
} catch {
|
|
73077
73771
|
return null;
|
|
73078
73772
|
}
|
|
@@ -73081,8 +73775,8 @@ function readProbeModelsCache(path2 = PROBE_MODELS_CACHE_PATH) {
|
|
|
73081
73775
|
return raw2;
|
|
73082
73776
|
}
|
|
73083
73777
|
function writeProbeModelsCache(data, path2 = PROBE_MODELS_CACHE_PATH) {
|
|
73084
|
-
|
|
73085
|
-
|
|
73778
|
+
mkdirSync17(dirname12(path2), { recursive: true });
|
|
73779
|
+
writeFileSync20(path2, JSON.stringify(data), "utf-8");
|
|
73086
73780
|
}
|
|
73087
73781
|
function isCacheFresh(data, ttlMs = CACHE_TTL_MS4) {
|
|
73088
73782
|
if (!data?.generatedAt)
|
|
@@ -73201,7 +73895,7 @@ function isValidResponse(raw2) {
|
|
|
73201
73895
|
var PROBE_MODELS_URL = "https://us-central1-claudish-6da10.cloudfunctions.net/probeModels", CACHE_TTL_MS4, FETCH_TIMEOUT_MS3 = 15000, PROBE_MODELS_CACHE_PATH, _inFlight = null;
|
|
73202
73896
|
var init_probe_catalog = __esm(() => {
|
|
73203
73897
|
CACHE_TTL_MS4 = 60 * 60 * 1000;
|
|
73204
|
-
PROBE_MODELS_CACHE_PATH =
|
|
73898
|
+
PROBE_MODELS_CACHE_PATH = join37(homedir33(), ".claudish", "probe-models.json");
|
|
73205
73899
|
});
|
|
73206
73900
|
|
|
73207
73901
|
// src/tui/constants.ts
|
|
@@ -79554,18 +80248,18 @@ __export(exports_claude_runner, {
|
|
|
79554
80248
|
});
|
|
79555
80249
|
import { spawn as spawn5 } from "child_process";
|
|
79556
80250
|
import {
|
|
79557
|
-
closeSync as
|
|
79558
|
-
existsSync as
|
|
79559
|
-
mkdirSync as
|
|
79560
|
-
openSync as
|
|
79561
|
-
readFileSync as
|
|
80251
|
+
closeSync as closeSync5,
|
|
80252
|
+
existsSync as existsSync30,
|
|
80253
|
+
mkdirSync as mkdirSync18,
|
|
80254
|
+
openSync as openSync5,
|
|
80255
|
+
readFileSync as readFileSync30,
|
|
79562
80256
|
readdirSync as readdirSync6,
|
|
79563
80257
|
statSync as statSync5,
|
|
79564
|
-
unlinkSync as
|
|
79565
|
-
writeFileSync as
|
|
80258
|
+
unlinkSync as unlinkSync10,
|
|
80259
|
+
writeFileSync as writeFileSync21
|
|
79566
80260
|
} from "fs";
|
|
79567
|
-
import { homedir as
|
|
79568
|
-
import { dirname as dirname13, join as
|
|
80261
|
+
import { homedir as homedir34, tmpdir as tmpdir2 } from "os";
|
|
80262
|
+
import { dirname as dirname13, join as join38 } from "path";
|
|
79569
80263
|
import { isatty } from "tty";
|
|
79570
80264
|
function releaseTerminalIsolation() {
|
|
79571
80265
|
if (!restoreTerminal)
|
|
@@ -79600,14 +80294,14 @@ function isProxyAuthMode(config3) {
|
|
|
79600
80294
|
}
|
|
79601
80295
|
function managedSettingsPath() {
|
|
79602
80296
|
if (isWindows2()) {
|
|
79603
|
-
return
|
|
80297
|
+
return join38(process.env.PROGRAMDATA || "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
|
|
79604
80298
|
}
|
|
79605
80299
|
if (process.platform === "darwin") {
|
|
79606
80300
|
return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
79607
80301
|
}
|
|
79608
80302
|
return "/etc/claude-code/managed-settings.json";
|
|
79609
80303
|
}
|
|
79610
|
-
function managedSettingsForcesClaudeAi(readFile3 =
|
|
80304
|
+
function managedSettingsForcesClaudeAi(readFile3 = readFileSync30) {
|
|
79611
80305
|
try {
|
|
79612
80306
|
const raw2 = readFile3(managedSettingsPath(), "utf-8");
|
|
79613
80307
|
const parsed = JSON.parse(raw2);
|
|
@@ -79621,9 +80315,9 @@ function isWindows2() {
|
|
|
79621
80315
|
}
|
|
79622
80316
|
function createStatusLineScript(tokenFilePath) {
|
|
79623
80317
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
79624
|
-
const claudishDir =
|
|
80318
|
+
const claudishDir = join38(homeDir, ".claudish");
|
|
79625
80319
|
const timestamp = Date.now();
|
|
79626
|
-
const scriptPath =
|
|
80320
|
+
const scriptPath = join38(claudishDir, `status-${timestamp}.js`);
|
|
79627
80321
|
const escapedTokenPath = tokenFilePath.replace(/\\/g, "\\\\");
|
|
79628
80322
|
const script = `
|
|
79629
80323
|
const fs = require('fs');
|
|
@@ -79750,13 +80444,13 @@ process.stdin.on('end', () => {
|
|
|
79750
80444
|
}
|
|
79751
80445
|
});
|
|
79752
80446
|
`;
|
|
79753
|
-
|
|
80447
|
+
writeFileSync21(scriptPath, script, "utf-8");
|
|
79754
80448
|
return scriptPath;
|
|
79755
80449
|
}
|
|
79756
80450
|
function initializeTokenFile(tokenFilePath) {
|
|
79757
80451
|
try {
|
|
79758
|
-
|
|
79759
|
-
|
|
80452
|
+
mkdirSync18(dirname13(tokenFilePath), { recursive: true });
|
|
80453
|
+
writeFileSync21(tokenFilePath, JSON.stringify({
|
|
79760
80454
|
input_tokens: 0,
|
|
79761
80455
|
output_tokens: 0,
|
|
79762
80456
|
total_tokens: 0,
|
|
@@ -79787,11 +80481,11 @@ function cleanupStaleTokenFiles(dir, now = Date.now(), maxAgeMs = STALE_TOKEN_FI
|
|
|
79787
80481
|
if (!name.startsWith("tokens-") || !name.endsWith(".json"))
|
|
79788
80482
|
continue;
|
|
79789
80483
|
scanned++;
|
|
79790
|
-
const full =
|
|
80484
|
+
const full = join38(dir, name);
|
|
79791
80485
|
try {
|
|
79792
80486
|
if (statSync5(full).mtimeMs >= cutoff)
|
|
79793
80487
|
continue;
|
|
79794
|
-
|
|
80488
|
+
unlinkSync10(full);
|
|
79795
80489
|
removed++;
|
|
79796
80490
|
} catch {}
|
|
79797
80491
|
}
|
|
@@ -79804,7 +80498,7 @@ function parseSettingsArg(value) {
|
|
|
79804
80498
|
if (value.trimStart().startsWith("{")) {
|
|
79805
80499
|
return JSON.parse(value);
|
|
79806
80500
|
}
|
|
79807
|
-
return JSON.parse(
|
|
80501
|
+
return JSON.parse(readFileSync30(value, "utf-8"));
|
|
79808
80502
|
}
|
|
79809
80503
|
function parseSettingsArgSafe(value) {
|
|
79810
80504
|
try {
|
|
@@ -79816,13 +80510,13 @@ function parseSettingsArgSafe(value) {
|
|
|
79816
80510
|
}
|
|
79817
80511
|
function userSettingsFileCandidates(cwd) {
|
|
79818
80512
|
return [
|
|
79819
|
-
|
|
79820
|
-
|
|
79821
|
-
|
|
80513
|
+
join38(homedir34(), ".claude", "settings.json"),
|
|
80514
|
+
join38(cwd, ".claude", "settings.json"),
|
|
80515
|
+
join38(cwd, ".claude", "settings.local.json")
|
|
79822
80516
|
];
|
|
79823
80517
|
}
|
|
79824
80518
|
function discoverUserStatusLineCommand(claudeArgs = [], cwd = process.cwd()) {
|
|
79825
|
-
const sources = userSettingsFileCandidates(cwd).filter((file2) =>
|
|
80519
|
+
const sources = userSettingsFileCandidates(cwd).filter((file2) => existsSync30(file2));
|
|
79826
80520
|
const idx = claudeArgs.indexOf("--settings");
|
|
79827
80521
|
const settingsArg = idx === -1 ? undefined : claudeArgs[idx + 1];
|
|
79828
80522
|
if (settingsArg)
|
|
@@ -79859,13 +80553,13 @@ function buildChainedStatusCommand(userCommand, claudishBody, claudishSegment) {
|
|
|
79859
80553
|
}
|
|
79860
80554
|
function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLineCommand) {
|
|
79861
80555
|
const homeDir = process.env.HOME || process.env.USERPROFILE || tmpdir2();
|
|
79862
|
-
const claudishDir =
|
|
80556
|
+
const claudishDir = join38(homeDir, ".claudish");
|
|
79863
80557
|
try {
|
|
79864
|
-
|
|
80558
|
+
mkdirSync18(claudishDir, { recursive: true });
|
|
79865
80559
|
} catch {}
|
|
79866
80560
|
const timestamp = Date.now();
|
|
79867
|
-
const tempPath =
|
|
79868
|
-
const tokenFilePath =
|
|
80561
|
+
const tempPath = join38(claudishDir, `settings-${timestamp}.json`);
|
|
80562
|
+
const tokenFilePath = join38(claudishDir, `tokens-${port}.json`);
|
|
79869
80563
|
cleanupStaleTokenFiles(claudishDir);
|
|
79870
80564
|
initializeTokenFile(tokenFilePath);
|
|
79871
80565
|
let statusCommand;
|
|
@@ -79898,7 +80592,7 @@ function createTempSettingsFile(_modelDisplay, port, proxyAuthMode, userStatusLi
|
|
|
79898
80592
|
padding: 0
|
|
79899
80593
|
};
|
|
79900
80594
|
const settings = buildClaudishSettingsOverlay(statusLine, proxyAuthMode);
|
|
79901
|
-
|
|
80595
|
+
writeFileSync21(tempPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
79902
80596
|
return { path: tempPath, statusLine, tokenFilePath };
|
|
79903
80597
|
}
|
|
79904
80598
|
function buildClaudishSettingsOverlay(statusLine, proxyAuthMode) {
|
|
@@ -79923,7 +80617,7 @@ function mergeUserSettingsIfPresent(config3, tempSettingsPath, statusLine, proxy
|
|
|
79923
80617
|
if (proxyAuthMode && !("forceLoginMethod" in userSettings)) {
|
|
79924
80618
|
userSettings.forceLoginMethod = "console";
|
|
79925
80619
|
}
|
|
79926
|
-
|
|
80620
|
+
writeFileSync21(tempSettingsPath, JSON.stringify(userSettings, null, 2), "utf-8");
|
|
79927
80621
|
} catch {
|
|
79928
80622
|
if (!config3.quiet) {
|
|
79929
80623
|
console.warn(`[claudish] Warning: could not merge user settings: ${userSettingsValue}`);
|
|
@@ -80115,8 +80809,8 @@ async function runClaudeWithProxy(config3, proxyUrl, onCleanup) {
|
|
|
80115
80809
|
console.error("Install it from: https://claude.com/claude-code");
|
|
80116
80810
|
console.error(`
|
|
80117
80811
|
Or set CLAUDE_PATH to your custom installation:`);
|
|
80118
|
-
const home =
|
|
80119
|
-
const localPath = isWindows2() ?
|
|
80812
|
+
const home = homedir34();
|
|
80813
|
+
const localPath = isWindows2() ? join38(home, ".claude", "local", "claude.exe") : join38(home, ".claude", "local", "claude");
|
|
80120
80814
|
console.error(` export CLAUDE_PATH=${localPath}`);
|
|
80121
80815
|
process.exit(1);
|
|
80122
80816
|
}
|
|
@@ -80127,11 +80821,11 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
80127
80821
|
const childWantsTty = config3.interactive && !process.stdout.isTTY && Boolean(process.stdin.isTTY);
|
|
80128
80822
|
if (childWantsTty) {
|
|
80129
80823
|
try {
|
|
80130
|
-
const fd =
|
|
80824
|
+
const fd = openSync5("/dev/fd/0", "r+");
|
|
80131
80825
|
if (isatty(fd)) {
|
|
80132
80826
|
ttyFd = fd;
|
|
80133
80827
|
} else {
|
|
80134
|
-
|
|
80828
|
+
closeSync5(fd);
|
|
80135
80829
|
}
|
|
80136
80830
|
} catch {
|
|
80137
80831
|
ttyFd = undefined;
|
|
@@ -80154,7 +80848,7 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
80154
80848
|
const fdToClose = ttyFd;
|
|
80155
80849
|
proc.on("spawn", () => {
|
|
80156
80850
|
try {
|
|
80157
|
-
|
|
80851
|
+
closeSync5(fdToClose);
|
|
80158
80852
|
} catch {}
|
|
80159
80853
|
});
|
|
80160
80854
|
}
|
|
@@ -80167,7 +80861,7 @@ Or set CLAUDE_PATH to your custom installation:`);
|
|
|
80167
80861
|
});
|
|
80168
80862
|
releaseTerminalIsolation();
|
|
80169
80863
|
try {
|
|
80170
|
-
|
|
80864
|
+
unlinkSync10(tempSettingsPath);
|
|
80171
80865
|
} catch {}
|
|
80172
80866
|
return exitCode;
|
|
80173
80867
|
}
|
|
@@ -80187,7 +80881,7 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
|
|
|
80187
80881
|
} catch {}
|
|
80188
80882
|
}
|
|
80189
80883
|
try {
|
|
80190
|
-
|
|
80884
|
+
unlinkSync10(tempSettingsPath);
|
|
80191
80885
|
} catch {}
|
|
80192
80886
|
process.exit(0);
|
|
80193
80887
|
});
|
|
@@ -80196,23 +80890,23 @@ function setupSignalHandlers(proc, tempSettingsPath, quiet, onCleanup) {
|
|
|
80196
80890
|
async function findClaudeBinary() {
|
|
80197
80891
|
const isWindows3 = process.platform === "win32";
|
|
80198
80892
|
if (process.env.CLAUDE_PATH) {
|
|
80199
|
-
if (
|
|
80893
|
+
if (existsSync30(process.env.CLAUDE_PATH)) {
|
|
80200
80894
|
return process.env.CLAUDE_PATH;
|
|
80201
80895
|
}
|
|
80202
80896
|
}
|
|
80203
|
-
const home =
|
|
80204
|
-
const localPath = isWindows3 ?
|
|
80205
|
-
if (
|
|
80897
|
+
const home = homedir34();
|
|
80898
|
+
const localPath = isWindows3 ? join38(home, ".claude", "local", "claude.exe") : join38(home, ".claude", "local", "claude");
|
|
80899
|
+
if (existsSync30(localPath)) {
|
|
80206
80900
|
return localPath;
|
|
80207
80901
|
}
|
|
80208
80902
|
if (isWindows3) {
|
|
80209
80903
|
const windowsPaths = [
|
|
80210
|
-
|
|
80211
|
-
|
|
80212
|
-
|
|
80904
|
+
join38(home, "AppData", "Roaming", "npm", "claude.cmd"),
|
|
80905
|
+
join38(home, ".npm-global", "claude.cmd"),
|
|
80906
|
+
join38(home, "node_modules", ".bin", "claude.cmd")
|
|
80213
80907
|
];
|
|
80214
80908
|
for (const path2 of windowsPaths) {
|
|
80215
|
-
if (
|
|
80909
|
+
if (existsSync30(path2)) {
|
|
80216
80910
|
return path2;
|
|
80217
80911
|
}
|
|
80218
80912
|
}
|
|
@@ -80220,14 +80914,14 @@ async function findClaudeBinary() {
|
|
|
80220
80914
|
const commonPaths = [
|
|
80221
80915
|
"/usr/local/bin/claude",
|
|
80222
80916
|
"/opt/homebrew/bin/claude",
|
|
80223
|
-
|
|
80224
|
-
|
|
80225
|
-
|
|
80917
|
+
join38(home, ".npm-global/bin/claude"),
|
|
80918
|
+
join38(home, ".local/bin/claude"),
|
|
80919
|
+
join38(home, "node_modules/.bin/claude"),
|
|
80226
80920
|
"/data/data/com.termux/files/usr/bin/claude",
|
|
80227
|
-
|
|
80921
|
+
join38(home, "../usr/bin/claude")
|
|
80228
80922
|
];
|
|
80229
80923
|
for (const path2 of commonPaths) {
|
|
80230
|
-
if (
|
|
80924
|
+
if (existsSync30(path2)) {
|
|
80231
80925
|
return path2;
|
|
80232
80926
|
}
|
|
80233
80927
|
}
|
|
@@ -80286,18 +80980,18 @@ __export(exports_diag_output, {
|
|
|
80286
80980
|
NullDiagOutput: () => NullDiagOutput,
|
|
80287
80981
|
LogFileDiagOutput: () => LogFileDiagOutput
|
|
80288
80982
|
});
|
|
80289
|
-
import { createWriteStream as createWriteStream3, mkdirSync as
|
|
80290
|
-
import { homedir as
|
|
80291
|
-
import { join as
|
|
80983
|
+
import { createWriteStream as createWriteStream3, mkdirSync as mkdirSync19, unlinkSync as unlinkSync11, writeFileSync as writeFileSync22 } from "fs";
|
|
80984
|
+
import { homedir as homedir35 } from "os";
|
|
80985
|
+
import { join as join39 } from "path";
|
|
80292
80986
|
function getClaudishDir() {
|
|
80293
|
-
const dir =
|
|
80987
|
+
const dir = join39(homedir35(), ".claudish");
|
|
80294
80988
|
try {
|
|
80295
|
-
|
|
80989
|
+
mkdirSync19(dir, { recursive: true });
|
|
80296
80990
|
} catch {}
|
|
80297
80991
|
return dir;
|
|
80298
80992
|
}
|
|
80299
80993
|
function getDiagLogPath() {
|
|
80300
|
-
return
|
|
80994
|
+
return join39(getClaudishDir(), `diag-${process.pid}.log`);
|
|
80301
80995
|
}
|
|
80302
80996
|
|
|
80303
80997
|
class LogFileDiagOutput {
|
|
@@ -80306,7 +81000,7 @@ class LogFileDiagOutput {
|
|
|
80306
81000
|
constructor() {
|
|
80307
81001
|
this.logPath = getDiagLogPath();
|
|
80308
81002
|
try {
|
|
80309
|
-
|
|
81003
|
+
writeFileSync22(this.logPath, `--- claudish diag session ${new Date().toISOString()} ---
|
|
80310
81004
|
`);
|
|
80311
81005
|
} catch {}
|
|
80312
81006
|
this.stream = createWriteStream3(this.logPath, { flags: "a" });
|
|
@@ -80325,7 +81019,7 @@ class LogFileDiagOutput {
|
|
|
80325
81019
|
this.stream.end();
|
|
80326
81020
|
} catch {}
|
|
80327
81021
|
try {
|
|
80328
|
-
|
|
81022
|
+
unlinkSync11(this.logPath);
|
|
80329
81023
|
} catch {}
|
|
80330
81024
|
}
|
|
80331
81025
|
getLogPath() {
|
|
@@ -80893,9 +81587,9 @@ __export(exports_session_discovery, {
|
|
|
80893
81587
|
ACTIVE_WINDOW_MS: () => ACTIVE_WINDOW_MS
|
|
80894
81588
|
});
|
|
80895
81589
|
import { execFile, execFileSync as execFileSync2 } from "child_process";
|
|
80896
|
-
import { closeSync as
|
|
80897
|
-
import { homedir as
|
|
80898
|
-
import { basename, join as
|
|
81590
|
+
import { closeSync as closeSync6, openSync as openSync6, readSync, readdirSync as readdirSync7, statSync as statSync6 } from "fs";
|
|
81591
|
+
import { homedir as homedir36 } from "os";
|
|
81592
|
+
import { basename, join as join40 } from "path";
|
|
80899
81593
|
function slugForPath(absPath) {
|
|
80900
81594
|
return absPath.replace(/[/.]/g, "-");
|
|
80901
81595
|
}
|
|
@@ -80944,7 +81638,7 @@ function projectDirs() {
|
|
|
80944
81638
|
}
|
|
80945
81639
|
}
|
|
80946
81640
|
function sessionsIn(dirName) {
|
|
80947
|
-
const dir =
|
|
81641
|
+
const dir = join40(PROJECTS_DIR, dirName);
|
|
80948
81642
|
let names;
|
|
80949
81643
|
try {
|
|
80950
81644
|
names = readdirSync7(dir).filter((n) => n.endsWith(".jsonl"));
|
|
@@ -80953,7 +81647,7 @@ function sessionsIn(dirName) {
|
|
|
80953
81647
|
}
|
|
80954
81648
|
const rows = [];
|
|
80955
81649
|
for (const n of names) {
|
|
80956
|
-
const file2 =
|
|
81650
|
+
const file2 = join40(dir, n);
|
|
80957
81651
|
try {
|
|
80958
81652
|
const st = statSync6(file2);
|
|
80959
81653
|
if (st.size === 0)
|
|
@@ -81133,7 +81827,7 @@ function readChunk(file2, pos, len) {
|
|
|
81133
81827
|
return "";
|
|
81134
81828
|
let fd = null;
|
|
81135
81829
|
try {
|
|
81136
|
-
fd =
|
|
81830
|
+
fd = openSync6(file2, "r");
|
|
81137
81831
|
const buf = Buffer.allocUnsafe(len);
|
|
81138
81832
|
const n = readSync(fd, buf, 0, len, pos);
|
|
81139
81833
|
return buf.subarray(0, n).toString("utf-8");
|
|
@@ -81142,7 +81836,7 @@ function readChunk(file2, pos, len) {
|
|
|
81142
81836
|
} finally {
|
|
81143
81837
|
if (fd !== null) {
|
|
81144
81838
|
try {
|
|
81145
|
-
|
|
81839
|
+
closeSync6(fd);
|
|
81146
81840
|
} catch {}
|
|
81147
81841
|
}
|
|
81148
81842
|
}
|
|
@@ -81312,7 +82006,7 @@ function findLatestSessionId(cwd = process.cwd(), sinceMs = 0) {
|
|
|
81312
82006
|
}
|
|
81313
82007
|
var ENTRYPOINT_BYTES = 8192, PROJECTS_DIR, ACTIVE_WINDOW_MS = 120000, HEAD_BYTES, TAIL_BYTES, HARNESS_ENVELOPES, DEEP_TAIL_BYTES, RECENT_AI_TURNS = 5, RECENT_USER_TURNS = 1;
|
|
81314
82008
|
var init_session_discovery = __esm(() => {
|
|
81315
|
-
PROJECTS_DIR =
|
|
82009
|
+
PROJECTS_DIR = join40(homedir36(), ".claude", "projects");
|
|
81316
82010
|
HEAD_BYTES = 64 * 1024;
|
|
81317
82011
|
TAIL_BYTES = 128 * 1024;
|
|
81318
82012
|
HARNESS_ENVELOPES = [
|
|
@@ -81325,7 +82019,7 @@ var init_session_discovery = __esm(() => {
|
|
|
81325
82019
|
});
|
|
81326
82020
|
|
|
81327
82021
|
// src/session/conversation.ts
|
|
81328
|
-
import { closeSync as
|
|
82022
|
+
import { closeSync as closeSync7, openSync as openSync7, readSync as readSync2, statSync as statSync7 } from "fs";
|
|
81329
82023
|
import { StringDecoder } from "string_decoder";
|
|
81330
82024
|
function looksLikeTurn(line) {
|
|
81331
82025
|
const assistant = line.includes('"type":"assistant"');
|
|
@@ -81381,7 +82075,7 @@ function readConversation(file2, opts = {}) {
|
|
|
81381
82075
|
let fd = null;
|
|
81382
82076
|
try {
|
|
81383
82077
|
const size = statSync7(file2).size;
|
|
81384
|
-
fd =
|
|
82078
|
+
fd = openSync7(file2, "r");
|
|
81385
82079
|
const buf = Buffer.allocUnsafe(chunkBytes);
|
|
81386
82080
|
const decoder = new StringDecoder("utf-8");
|
|
81387
82081
|
let pending = "";
|
|
@@ -81437,7 +82131,7 @@ function readConversation(file2, opts = {}) {
|
|
|
81437
82131
|
} catch {} finally {
|
|
81438
82132
|
if (fd !== null) {
|
|
81439
82133
|
try {
|
|
81440
|
-
|
|
82134
|
+
closeSync7(fd);
|
|
81441
82135
|
} catch {}
|
|
81442
82136
|
}
|
|
81443
82137
|
}
|
|
@@ -83004,16 +83698,16 @@ __export(exports_session_stats, {
|
|
|
83004
83698
|
readSessionStats: () => readSessionStats,
|
|
83005
83699
|
computeSavings: () => computeSavings
|
|
83006
83700
|
});
|
|
83007
|
-
import { readFileSync as
|
|
83008
|
-
import { homedir as
|
|
83009
|
-
import { join as
|
|
83701
|
+
import { readFileSync as readFileSync31 } from "fs";
|
|
83702
|
+
import { homedir as homedir37 } from "os";
|
|
83703
|
+
import { join as join41 } from "path";
|
|
83010
83704
|
function tokenFilePath(port) {
|
|
83011
|
-
return process.env.CLAUDISH_TOKEN_FILE ||
|
|
83705
|
+
return process.env.CLAUDISH_TOKEN_FILE || join41(homedir37(), ".claudish", `tokens-${port}.json`);
|
|
83012
83706
|
}
|
|
83013
83707
|
function readSessionStats(port, opts) {
|
|
83014
83708
|
let raw2;
|
|
83015
83709
|
try {
|
|
83016
|
-
raw2 = JSON.parse(
|
|
83710
|
+
raw2 = JSON.parse(readFileSync31(tokenFilePath(port), "utf-8"));
|
|
83017
83711
|
} catch {
|
|
83018
83712
|
return null;
|
|
83019
83713
|
}
|
|
@@ -83353,8 +84047,8 @@ var init_session_summary = __esm(() => {
|
|
|
83353
84047
|
init_op_source();
|
|
83354
84048
|
init_startup_trace();
|
|
83355
84049
|
var import_dotenv3 = __toESM(require_main(), 1);
|
|
83356
|
-
import { existsSync as
|
|
83357
|
-
import { join as
|
|
84050
|
+
import { existsSync as existsSync31, readFileSync as readFileSync32 } from "fs";
|
|
84051
|
+
import { join as join42, resolve as resolve5 } from "path";
|
|
83358
84052
|
import_dotenv3.config({ quiet: true });
|
|
83359
84053
|
function classifyStartupKind() {
|
|
83360
84054
|
const argv = process.argv.slice(2);
|
|
@@ -83453,7 +84147,7 @@ async function applyConfigOverride() {
|
|
|
83453
84147
|
const { planConfigOverride: planConfigOverride2, setConfigFileOverride: setConfigFileOverride2 } = await Promise.resolve().then(() => exports_config_override);
|
|
83454
84148
|
const plan = planConfigOverride2(process.argv.slice(2), process.env, {
|
|
83455
84149
|
resolve: resolve5,
|
|
83456
|
-
exists:
|
|
84150
|
+
exists: existsSync31
|
|
83457
84151
|
});
|
|
83458
84152
|
if (plan.kind === "none")
|
|
83459
84153
|
return;
|
|
@@ -83608,14 +84302,14 @@ async function runCli() {
|
|
|
83608
84302
|
if (cliConfig.team && cliConfig.team.length > 0) {
|
|
83609
84303
|
let prompt = cliConfig.claudeArgs.join(" ");
|
|
83610
84304
|
if (cliConfig.inputFile) {
|
|
83611
|
-
prompt =
|
|
84305
|
+
prompt = readFileSync32(cliConfig.inputFile, "utf-8");
|
|
83612
84306
|
}
|
|
83613
84307
|
if (!prompt.trim()) {
|
|
83614
84308
|
console.error("Error: --team requires a prompt (positional args or -f <file>)");
|
|
83615
84309
|
process.exit(1);
|
|
83616
84310
|
}
|
|
83617
84311
|
const mode = cliConfig.teamMode ?? "default";
|
|
83618
|
-
const sessionPath =
|
|
84312
|
+
const sessionPath = join42(process.cwd(), `.claudish-team-${Date.now()}`);
|
|
83619
84313
|
if (mode === "json") {
|
|
83620
84314
|
const { setupSession: setupSession2, runModels: runModels2 } = await Promise.resolve().then(() => (init_team_orchestrator(), exports_team_orchestrator));
|
|
83621
84315
|
setupSession2(sessionPath, cliConfig.team, prompt);
|
|
@@ -83625,9 +84319,9 @@ async function runCli() {
|
|
|
83625
84319
|
});
|
|
83626
84320
|
const result = { ...status2, responses: {} };
|
|
83627
84321
|
for (const anonId of Object.keys(status2.models)) {
|
|
83628
|
-
const responsePath =
|
|
84322
|
+
const responsePath = join42(sessionPath, `response-${anonId}.md`);
|
|
83629
84323
|
try {
|
|
83630
|
-
const raw2 =
|
|
84324
|
+
const raw2 = readFileSync32(responsePath, "utf-8").trim();
|
|
83631
84325
|
try {
|
|
83632
84326
|
result.responses[anonId] = JSON.parse(raw2);
|
|
83633
84327
|
} catch {
|